source: src-qt4/life-preserver/LPTray.cpp @ 108626c

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2
Last change on this file since 108626c was 108626c, checked in by Ken Moore <ken@…>, 10 months ago

Clean up the tray icons for life-preserver so they are easier to see, and fix the constant resilvering messages when a reilver is finished.

  • Property mode set to 100644
File size: 4.2 KB
Line 
1#include "LPTray.h"
2
3//PUBLIC
4LPTray::LPTray() : QSystemTrayIcon(){
5  //Start up the log file watcher and connect the signals/slots
6  watcher = new LPWatcher();
7        connect(watcher,SIGNAL(MessageAvailable(QString)),this,SLOT(watcherMessage(QString)) );
8        connect(watcher,SIGNAL(StatusUpdated()),this,SLOT(watcherMessage()) );
9  //Setup the context menu
10  menu = new QMenu;
11        menu->addAction(new QAction(QIcon(":/images/application-exit.png"),tr("Close Life Preserver Tray"),this) );
12        connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(slotClose()) );
13  this->setContextMenu(menu);
14  //Setup initial icon for the tray
15  this->setIcon( QIcon(":/images/tray-icon-idle.png") );
16  //Create the configuration GUI
17  GUI = new mainUI();
18  //connect other signals/slots
19  connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(slotTrayClicked(QSystemTrayIcon::ActivationReason)) );
20  //Start up the watcher
21  watcher->start();
22  updateTrayIcon();
23  updateToolTip();
24}
25
26LPTray::~LPTray(){
27  watcher->stop();
28  delete watcher;
29}
30
31// ===============
32//  PRIVATE FUNCTIONS
33// ===============
34void LPTray::updateTrayIcon(){
35  if( watcher->hasError() ){
36    //Errors - show that attention is required
37    this->setIcon( QIcon(":/images/tray-icon-error.png") );
38  }else if( watcher->isRunning() ){
39    //Show the working icon
40    this->setIcon( QIcon(":/images/tray-icon-working.png") );
41  }else{
42    //Show the idle icon
43    this->setIcon( QIcon(":/images/tray-icon-idle.png") );
44  }
45 
46}
47
48void LPTray::updateToolTip(){
49  QStringList info = watcher->getAllCurrentMessages();
50  this->setToolTip( info.join("\n") ); 
51}
52
53// ===============
54//     PRIVATE SLOTS
55// ===============
56void LPTray::watcherMessage(QString type){
57  qDebug() << "New Watcher Message:" << type;
58  QStringList info;
59  if(type=="message"){
60    //Show the message pop-up
61    info << "time" << "message";
62    info = watcher->getMessages(type,info);
63    if(!info.isEmpty()){
64      this->showMessage( info[0], info[1], QSystemTrayIcon::Information, 5000);
65    }
66  }else if(type=="replication"){
67    info << "id" << "time" << "message";
68    info = watcher->getMessages(type,info);
69    if(info.isEmpty()){ return; }
70    if(info[0] == "STARTED"){
71      this->showMessage( info[1], info[2], QSystemTrayIcon::Information, 5000);
72    }else if(info[0] == "RUNNING"){
73      //don't show anything here - just let the tooltip update
74    }else if(info[0] == "FINISHED"){
75      this->showMessage( info[1], info[2], QSystemTrayIcon::Information, 5000);
76    }else if(info[0] == "ERROR"){
77      this->showMessage( info[1], info[2], QSystemTrayIcon::Warning, 5000);
78    }
79   
80  }else if(type=="critical"){
81    info << "time" << "message" << "device";
82    info = watcher->getMessages(type,info);
83    if(!info.isEmpty()){
84      QString msg = QString(tr("Time: %1")).arg(info[0]);
85      //message/device information can have more than one listed
86      QStringList devs = info[2].split(":::");     
87      QStringList msgs = info[1].split(":::");
88      for(int i=0; i<devs.length(); i++){
89        msg.append("\n"+QString(tr("%1: %2")).arg(devs[i],msgs[i]) );
90      }
91      QString title = tr("System Alert");
92      QMessageBox::warning(0, title ,msg);
93    }
94  }else if(type=="mirror"){
95         
96  }else if(type=="scrub" || type =="resilver"){
97    info << "id" << "time" << "message";
98    info = watcher->getMessages(type, info);
99    if(!info.isEmpty()){
100      if(info[0]=="ERROR"){ 
101        this->showMessage(info[1], info[2], QSystemTrayIcon::Warning, 5000);
102      }else{ 
103        this->showMessage(info[1], info[2], QSystemTrayIcon::Information, 5000); 
104      }
105    }
106  }
107  //Update the tray icon
108  updateTrayIcon();
109  //Update the tooltip
110  updateToolTip();
111}
112
113void LPTray::slotTrayClicked(QSystemTrayIcon::ActivationReason reason){
114  if(reason == QSystemTrayIcon::Trigger){ 
115    if(GUI->isVisible()){ GUI->hide(); }
116    else{ startGUI(); }
117  }else if( reason == QSystemTrayIcon::Context){
118    this->contextMenu()->popup(QCursor::pos());
119  }
120}
121
122void LPTray::slotClose(){
123  exit(0);
124}
125
126void LPTray::slotSingleInstance(){
127  this->show();
128  if(!GUI->isVisible()){ startGUI(); }
129  else{ 
130    GUI->raise(); 
131    GUI->show();
132  }
133}
134
135void LPTray::startGUI(){
136  //Start up the GUI
137    GUI->setupUI();
138    GUI->raise();
139    GUI->show();
140}
Note: See TracBrowser for help on using the repository browser.