source: src-qt4/life-preserver/LPTray.cpp @ 8c6a630

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

Completely finish cleaning up the replication functionality in the tray watcher it works great now.

  • Property mode set to 100644
File size: 4.1 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] == "FINISHED"){
73      this->showMessage( info[1], info[2], QSystemTrayIcon::Information, 5000);
74    }else if(info[0] == "ERROR"){
75      this->showMessage( info[1], info[2], QSystemTrayIcon::Warning, 10000);
76    }
77   
78  }else if(type=="critical"){
79    info << "time" << "message" << "device";
80    info = watcher->getMessages(type,info);
81    if(!info.isEmpty()){
82      QString msg = QString(tr("Time: %1")).arg(info[0]);
83      //message/device information can have more than one listed
84      QStringList devs = info[2].split(":::");     
85      QStringList msgs = info[1].split(":::");
86      for(int i=0; i<devs.length(); i++){
87        msg.append("\n"+QString(tr("%1: %2")).arg(devs[i],msgs[i]) );
88      }
89      QString title = tr("System Alert");
90      QMessageBox::warning(0, title ,msg);
91    }
92  }else if(type=="mirror"){
93         
94  }else if(type=="scrub" || type =="resilver"){
95    info << "id" << "time" << "message";
96    info = watcher->getMessages(type, info);
97    if(!info.isEmpty()){
98      if(info[0]=="ERROR"){ 
99        this->showMessage(info[1], info[2], QSystemTrayIcon::Warning, 5000);
100      }else{ 
101        this->showMessage(info[1], info[2], QSystemTrayIcon::Information, 5000); 
102      }
103    }
104  }
105  //Update the tray icon
106  updateTrayIcon();
107  //Update the tooltip
108  updateToolTip();
109}
110
111void LPTray::slotTrayClicked(QSystemTrayIcon::ActivationReason reason){
112  if(reason == QSystemTrayIcon::Trigger){ 
113    if(GUI->isVisible()){ GUI->hide(); }
114    else{ startGUI(); }
115  }else if( reason == QSystemTrayIcon::Context){
116    this->contextMenu()->popup(QCursor::pos());
117  }
118}
119
120void LPTray::slotClose(){
121  exit(0);
122}
123
124void LPTray::slotSingleInstance(){
125  this->show();
126  if(!GUI->isVisible()){ startGUI(); }
127  else{ 
128    GUI->raise(); 
129    GUI->show();
130  }
131}
132
133void LPTray::startGUI(){
134  //Start up the GUI
135    GUI->setupUI();
136    GUI->raise();
137    GUI->show();
138}
Note: See TracBrowser for help on using the repository browser.