Changeset 4bf9740 in nscp for helpers


Ignore:
Timestamp:
09/17/08 21:10:18 (5 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2, stable
Children:
08f0346
Parents:
7e74e2c
Message:

2008-09-17 MickeM - 0.3.4 RC-6

  • Fixed issue on all filters so == takes the "usual" 2 equalsigns (old still works).
  • Added so tray icon can get "propper" name from core for "description".

2008-09-16 MickeM - 0.3.4 RC-5

  • Fixed an issue with the session launcher
Location:
helpers/systray_helper
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • helpers/systray_helper/TrayWidget.cpp

    ra34b229 r4bf9740  
    5050typedef BOOL (WINAPI *LPFN_CHANGEWINDOWMESSAGEFILTER) (UINT, DWORD); 
    5151LPFN_CHANGEWINDOWMESSAGEFILTER fnChangeWindowMessageFilter = NULL; 
    52 BOOL ChangeWindowMessageFilter(UINT message, DWORD what) 
     52BOOL ChangeWindowMessageFilter_(UINT message, DWORD what) 
    5353{ 
    5454  if (fnChangeWindowMessageFilter == NULL) { 
     
    8585  LOG_MESSAGE_TRAY(_T("Attempting to launch system tray module for ") + channel_id_); 
    8686  gTrayInstance = this; 
    87   try { 
    88     shared_client_.reset(new nsclient_session::shared_client_session(channel_id_, this)); 
    89     if (shared_client_.get() != NULL) 
    90       shared_client_->attach_to_session(channel_id_); 
    91   } catch (nsclient_session::session_exception e) { 
    92     LOG_ERROR_TRAY(_T("Failed to attach to shared session: ") + e.what()); 
    93   } 
    9487} 
    9588TrayWidget::~TrayWidget() { 
     
    111104  try { 
    112105    shared_client_.reset(new nsclient_session::shared_client_session(channel_id_, this)); 
    113     if (shared_client_.get() != NULL) 
     106    if (shared_client_.get() != NULL) { 
    114107      shared_client_->attach_to_session(channel_id_); 
     108      TrayIcon::addIcon(hDlgWnd); 
     109    } 
    115110  } catch (nsclient_session::session_exception e) { 
    116111    LOG_ERROR_TRAY(_T("Failed to attach to shared session: ") + e.what()); 
     
    124119  return shared_client_->inject(command, arguments, splitter, escape, msg, perf); 
    125120} 
     121std::pair<std::wstring,std::wstring> TrayWidget::get_client_name() { 
     122  if (shared_client_.get() == NULL) { 
     123    LOG_ERROR_TRAY(_T("No active shared instance!")); 
     124    return std::pair<std::wstring,std::wstring>(_T("NSClient++ system tray offline"), _T("")); 
     125  } 
     126  return shared_client_->get_client_name(); 
     127} 
    126128 
    127129 
     
    131133  LOG_MESSAGE_TRAY(_T("Creating dialog...")); 
    132134  ghInstance = hInstance; 
    133   //hDlgWnd = ::CreateDialog(hInstance,MAKEINTRESOURCE(IDD_NSTRAYDLG),NULL,TrayIcon::DialogProc); 
    134   //if ((hDlgWnd == NULL)||!IsWindow(hDlgWnd)) { 
    135 //    LOG_ERROR_TRAY(_T("Failed to create windows: ") + error::lookup::last_error()); 
    136 //  } 
    137135 
    138136  WNDCLASSEX wndclass; 
     
    149147  wndclass.lpszClassName=_T("NSClient_pp_TrayClass"); 
    150148  wndclass.style=0; 
    151   // register task bar restore event after crash 
    152   //WM_TASKBARCREATED=RegisterWindowMessage(TEXT("TaskbarCreated")); 
    153   //MyChangeWindowMessageFilter(WM_TASKBARCREATED, MSGFLT_ADD);  
    154149 
    155150  UINT UDM_TASKBARCREATED = RegisterWindowMessage(_T("TaskbarCreated")); 
     
    157152    LOG_ERROR_TRAY(_T("Failed to register 'TaskbarCreated': ") + error::lookup::last_error()); 
    158153  } 
    159   if (!ChangeWindowMessageFilter(UDM_TASKBARCREATED, MSGFLT_ADD)) { 
     154  if (!ChangeWindowMessageFilter_(UDM_TASKBARCREATED, MSGFLT_ADD)) { 
    160155    LOG_ERROR_TRAY(_T("Failed to cchange window filter: ") + error::lookup::last_error()); 
    161156  } 
     
    185180  } 
    186181  return; 
    187    
    188   /* 
    189   MSG Msg; 
    190   BOOL bRet; 
    191   while((bRet = ::GetMessage(&Msg, NULL, 0, 0)) != 0) 
    192   { 
    193     if (Msg.message == WM_MY_CLOSE) { 
    194       ::DestroyWindow(hDlgWnd); 
    195     } else if (Msg.message == UDM_TASKBARCREATED) { 
    196       LOG_MESSAGE_TRAY(_T("Recreating systray icon...")); 
    197       TrayIcon::addIcon(Msg.hwnd); 
    198     } else if (bRet == -1) { 
    199       // handle the error and possibly exit 
    200       LOG_ERROR_TRAY(_T("Wonder what this is... please let me know...")); 
    201       return; 
    202     } else { 
    203     //} else if (!::IsWindow(hDlgWnd) || !::IsDialogMessage(hDlgWnd, &Msg)) { 
    204       ::TranslateMessage(&Msg);  
    205       ::DispatchMessage(&Msg);  
    206     }  
    207   } 
    208   */ 
    209182} 
    210183 
    211184void TrayWidget::session_error(std::wstring file, unsigned int line, std::wstring msg) { 
    212185  log(_T("error"), file.c_str(), line, msg); 
     186} 
     187void TrayWidget::session_info(std::wstring file, unsigned int line, std::wstring msg) { 
     188  log(_T("info"), file.c_str(), line, msg); 
    213189} 
    214190 
     
    353329      SetDlgItemText(hWnd, IDC_MSG, msg.c_str()); 
    354330      SetDlgItemText(hWnd, IDC_PERF, perf.c_str()); 
     331    } else if (cmd == _T("connect-service")) { 
     332      gTrayInstance->connectService(); 
    355333    } 
    356334    return 0; 
     
    364342  } 
    365343 
     344  static void connectService() { 
     345    Thread<worker_thread> *pThread = new Thread<worker_thread>(_T("tray-worker-thread")); 
     346    pThread->createThread(worker_thread::init(_T("connect-service"), NULL)); 
     347  } 
    366348  static void updateServiceStatus(HMENU hMenu) { 
    367349    Thread<worker_thread> *pThread = new Thread<worker_thread>(_T("tray-worker-thread")); 
     
    586568  if (uMsg == UDM_TASKBARCREATED) { 
    587569    addIcon(hwndDlg); 
    588     LOG_MESSAGE_TO_TRAY(_T("UDM_TASKBARCREATED")); 
    589570  } 
    590571 
     
    600581  case WM_CREATE: 
    601582  case WM_INITDIALOG: 
    602     LOG_MESSAGE_TO_TRAY(_T("WM_INITDIALOG")); 
    603  
    604  
    605583    UDM_TASKBARCREATED = RegisterWindowMessage(_T("TaskbarCreated")); 
    606584    if (UDM_TASKBARCREATED == 0) { 
    607585      LOG_MESSAGE_TO_TRAY(_T("Failed to register 'TaskbarCreated': ") + error::lookup::last_error()); 
    608586    } 
    609     if (!ChangeWindowMessageFilter(UDM_TASKBARCREATED, MSGFLT_ADD)) { 
     587    if (!ChangeWindowMessageFilter_(UDM_TASKBARCREATED, MSGFLT_ADD)) { 
    610588      LOG_MESSAGE_TO_TRAY(_T("Failed to cchange window filter: ") + error::lookup::last_error()); 
    611589    } 
    612590 
    613591    addIcon(hwndDlg); 
     592    worker_thread::connectService(); 
    614593    break; 
    615594 
     
    619598      { 
    620599      case ID_POPUP_CONNECT: 
    621         gTrayInstance->connectService(); 
     600        worker_thread::connectService(); 
    622601        break; 
    623602      case ID_POPUP_CLOSE: 
     
    680659  ndata.uCallbackMessage=WM_ICON_NOTIFY; 
    681660  ndata.hIcon=::LoadIcon(ghInstance,MAKEINTRESOURCE(IDI_NSCP)); 
    682   std::wstring title = _T("NSClient++ SystemTray (TODO)"); //NSCModuleHelper::getApplicationName() + _T(" - ") + NSCModuleHelper::getApplicationVersionString(); 
     661  std::pair<std::wstring,std::wstring> version = gTrayInstance->get_client_name(); 
     662  std::wstring title = version.first + _T(" - ") + version.second; 
    683663  wcsncpy_s(ndata.szTip, 64, title.c_str(), min(64, title.size())); 
    684664  Shell_NotifyIcon(NIM_ADD,&ndata); 
  • helpers/systray_helper/TrayWidget.h

    ra34b229 r4bf9740  
    6060  void log(std::wstring category, const TCHAR* file, const int line, std::wstring message); 
    6161  void session_error(std::wstring file, unsigned int line, std::wstring msg); 
     62  void session_info(std::wstring file, unsigned int line, std::wstring msg); 
    6263  void session_log_message(int msgType, const TCHAR* file, const int line, std::wstring message); 
    6364  int session_inject(std::wstring command, std::wstring arguments, TCHAR splitter, bool escape, std::wstring &msg, std::wstring & perf) { 
    6465    return -1; 
     66  } 
     67  std::pair<std::wstring,std::wstring> session_get_name() { 
     68    return std::pair<std::wstring,std::wstring>(_T("NSClient++ systray"),_T("")); 
    6569  } 
    6670 
     
    6973  HWND getLogWindow() const { return hLogWnd; } 
    7074  int inject(std::wstring command, std::wstring arguments, TCHAR splitter, bool escape, std::wstring &msg, std::wstring & perf); 
     75  std::pair<std::wstring,std::wstring> get_client_name(); 
    7176 
    7277 
Note: See TracChangeset for help on using the changeset viewer.