source: src-qt4/life-preserver/lp-tray/LPMessages.cpp @ 6a2483b

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

Remove the old life-preserver from the src-qt4/life-preserver dir, and replace it with src-qt4/life-preserver/lp-tray and src-qt4/life-preserver/lp-gui.

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