source: src-qt4/life-preserver/LPMessages.cpp @ e0c368d

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

Create a new "LPMessages" dialog class and integrate it into the tray application. This will show the full messages that are available, as well as display the contents of any known log/error files that the watcher is aware of.

  • Property mode set to 100644
File size: 2.8 KB
Line 
1#include "LPMessages.h"
2#include "ui_LPMessages.h"
3
4LPMessages::LPMessages(QWidget *parent) : QDialog(parent), ui(new Ui::LPMessages){
5  ui->setupUi(this);
6  logsAvailable=false;
7  connect(ui->push_close, SIGNAL(clicked()), this, SLOT(closeDialog()) );
8  connect(ui->combo_logs, SIGNAL(currentIndexChanged(int)), this, SLOT(slotChangeLog()) );
9}
10
11LPMessages::~LPMessages(){
12  //no special cleanup
13}
14
15// ------------------------------
16// PUBLIC FUNCTIONS
17// ------------------------------
18void LPMessages::setMessages(QString msg){
19  if(msg.isEmpty()){ msg = tr("No recent messages"); }
20  ui->label_messages->setText(msg);
21  //Make sure that the messages tab is visible
22  ui->tabWidget->setCurrentWidget(ui->tab_messages);
23}
24
25void LPMessages::setErrors(QString err){
26  ui->label_errors->setText(err);
27  ui->label_errors->setVisible( !err.isEmpty() );
28}
29
30void LPMessages::setLogFiles(QStringList logs){
31  ui->combo_logs->clear();
32  logsAvailable = !logs.isEmpty();
33  if(!logsAvailable){ logs << tr("No Log Files Available"); }
34  ui->combo_logs->addItems(logs);
35  ui->text_log->setVisible(logsAvailable);
36  ui->combo_logs->setCurrentIndex(0);
37}
38
39// -------------------------------
40// PRIVATE FUNCTIONS
41// -------------------------------
42void LPMessages::displayLogFile(QString logFile){
43  QString msg = tr("(Life Preserver) No file contents to display");
44  //Read the log file if it exists
45  QStringList contents;
46  QFile file(logFile);
47  if(!file.exists()){ contents << QString(tr("(Life Preserver) File does not exist: %1")).arg(logFile); }
48  else{
49    if(file.open(QIODevice::ReadOnly | QIODevice::Text)){ 
50      QTextStream in(&file);
51      while(!in.atEnd()){
52        contents << QString( in.readLine() );
53      }
54      file.close();
55    }else{
56      contents << QString(tr("(Life Preserver) File could not be opened: %1")).arg(logFile);
57    }
58  }
59  //Now put the contents into a single message
60  if(!contents.isEmpty()){ msg = contents.join("\n"); }
61  //display the contents of the file
62  ui->text_log->setText(msg);
63}
64
65// -----------------------
66// PRIVATE SLOTS
67// -----------------------
68void LPMessages::slotChangeLog(){
69  qDebug() << "Change Visible Log File";
70  if(!logsAvailable){ return; }
71  //Get the logfile path from the text
72  QString logfile = ui->combo_logs->currentText().section("<",1,1,QString::SectionSkipEmpty).section(">",0,0);
73  //Now run the function to display the file's contents
74  displayLogFile(logfile);
75}
76
77void LPMessages::closeDialog(){
78  qDebug() << "Closing down the message dialog";
79  //no cleanup necessary for this dialog
80  this->close();
81}
82
83// ------------------
84// PROTECTED
85// ------------------
86void LPMessages::closeEvent(QCloseEvent *event){
87  //Make sure this window only gets hidden rather than closed
88  // this prevents the entire tray application from closing down as well
89  event->ignore();
90  this->hide(); 
91}
Note: See TracBrowser for help on using the repository browser.