source: src-qt4/life-preserver/LPTray.cpp @ 04144d6

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

Get all the critical zfs messages parsed and added to the watcher/tray

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