Skip to content
This repository has been archived by the owner on Dec 4, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:pcbsd/pcbsd
Browse files Browse the repository at this point in the history
  • Loading branch information
Kris Moore committed Sep 27, 2013
2 parents 393790b + eb70a80 commit 5119a91
Show file tree
Hide file tree
Showing 7 changed files with 329 additions and 8 deletions.
91 changes: 91 additions & 0 deletions src-qt4/life-preserver/LPMessages.cpp
@@ -0,0 +1,91 @@
#include "LPMessages.h"
#include "ui_LPMessages.h"

LPMessages::LPMessages(QWidget *parent) : QDialog(parent), ui(new Ui::LPMessages){
ui->setupUi(this);
logsAvailable=false;
connect(ui->push_close, SIGNAL(clicked()), this, SLOT(closeDialog()) );
connect(ui->combo_logs, SIGNAL(currentIndexChanged(int)), this, SLOT(slotChangeLog()) );
}

LPMessages::~LPMessages(){
//no special cleanup
}

// ------------------------------
// PUBLIC FUNCTIONS
// ------------------------------
void LPMessages::setMessages(QString msg){
if(msg.isEmpty()){ msg = tr("No recent messages"); }
ui->label_messages->setText(msg);
//Make sure that the messages tab is visible
ui->tabWidget->setCurrentWidget(ui->tab_messages);
}

void LPMessages::setErrors(QString err){
ui->label_errors->setText(err);
ui->label_errors->setVisible( !err.isEmpty() );
}

void LPMessages::setLogFiles(QStringList logs){
ui->combo_logs->clear();
logsAvailable = !logs.isEmpty();
if(!logsAvailable){ logs << tr("No Log Files Available"); }
ui->combo_logs->addItems(logs);
ui->text_log->setVisible(logsAvailable);
ui->combo_logs->setCurrentIndex(0);
}

// -------------------------------
// PRIVATE FUNCTIONS
// -------------------------------
void LPMessages::displayLogFile(QString logFile){
QString msg = tr("(Life Preserver) No file contents to display");
//Read the log file if it exists
QStringList contents;
QFile file(logFile);
if(!file.exists()){ contents << QString(tr("(Life Preserver) File does not exist: %1")).arg(logFile); }
else{
if(file.open(QIODevice::ReadOnly | QIODevice::Text)){
QTextStream in(&file);
while(!in.atEnd()){
contents << QString( in.readLine() );
}
file.close();
}else{
contents << QString(tr("(Life Preserver) File could not be opened: %1")).arg(logFile);
}
}
//Now put the contents into a single message
if(!contents.isEmpty()){ msg = contents.join("\n"); }
//display the contents of the file
ui->text_log->setText(msg);
}

// -----------------------
// PRIVATE SLOTS
// -----------------------
void LPMessages::slotChangeLog(){
qDebug() << "Change Visible Log File";
if(!logsAvailable){ return; }
//Get the logfile path from the text
QString logfile = ui->combo_logs->currentText().section("<",1,1,QString::SectionSkipEmpty).section(">",0,0);
//Now run the function to display the file's contents
displayLogFile(logfile);
}

void LPMessages::closeDialog(){
qDebug() << "Closing down the message dialog";
//no cleanup necessary for this dialog
this->close();
}

// ------------------
// PROTECTED
// ------------------
void LPMessages::closeEvent(QCloseEvent *event){
//Make sure this window only gets hidden rather than closed
// this prevents the entire tray application from closing down as well
event->ignore();
this->hide();
}
39 changes: 39 additions & 0 deletions src-qt4/life-preserver/LPMessages.h
@@ -0,0 +1,39 @@
#ifndef _LP_MESSAGES_H
#define _LP_MESSAGES_H

#include <QDialog>
#include <QStringList>
#include <QString>
#include <QFile>
#include <QTextStream>
#include <QDebug>
#include <QCloseEvent>

namespace Ui{
class LPMessages;
};

class LPMessages : public QDialog{
Q_OBJECT
public:
LPMessages(QWidget *parent=0);
~LPMessages();

void setMessages(QString msg);
void setErrors(QString err);
void setLogFiles(QStringList logs);

private:
Ui::LPMessages *ui;
bool logsAvailable;
void displayLogFile(QString logfile);

private slots:
void slotChangeLog();
void closeDialog();

protected:
void closeEvent(QCloseEvent*);

};
#endif
150 changes: 150 additions & 0 deletions src-qt4/life-preserver/LPMessages.ui
@@ -0,0 +1,150 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LPMessages</class>
<widget class="QDialog" name="LPMessages">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>464</width>
<height>207</height>
</rect>
</property>
<property name="windowTitle">
<string>Life Preserver Messages</string>
</property>
<property name="windowIcon">
<iconset resource="lPreserve.qrc">
<normaloff>:/images/tray-icon-error.png</normaloff>:/images/tray-icon-error.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab_messages">
<attribute name="icon">
<iconset resource="lPreserve.qrc">
<normaloff>:/images/view.png</normaloff>:/images/view.png</iconset>
</attribute>
<attribute name="title">
<string>Messages</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QLabel" name="label_messages">
<property name="text">
<string notr="true">Normal Messages</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_errors">
<property name="styleSheet">
<string notr="true">background-color: rgba(220,10,10,70); border-radius: 5px;</string>
</property>
<property name="text">
<string notr="true">Error Messages</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_files">
<attribute name="icon">
<iconset resource="lPreserve.qrc">
<normaloff>:/images/copy.png</normaloff>:/images/copy.png</iconset>
</attribute>
<attribute name="title">
<string>Log Files</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QComboBox" name="combo_logs">
<property name="frame">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QTextEdit" name="text_log">
<property name="lineWrapMode">
<enum>QTextEdit::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="push_close">
<property name="text">
<string>Close</string>
</property>
<property name="icon">
<iconset resource="lPreserve.qrc">
<normaloff>:/images/application-exit.png</normaloff>:/images/application-exit.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="lPreserve.qrc"/>
</resources>
<connections/>
</ui>
35 changes: 33 additions & 2 deletions src-qt4/life-preserver/LPTray.cpp
Expand Up @@ -8,13 +8,16 @@ LPTray::LPTray() : QSystemTrayIcon(){
connect(watcher,SIGNAL(StatusUpdated()),this,SLOT(watcherMessage()) );
//Setup the context menu
menu = new QMenu;
menu->addAction(new QAction(QIcon(":/images/application-exit.png"),tr("Close Life Preserver Tray"),this) );
connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(slotClose()) );
menu->addAction(QIcon(":/images/backup-failed.png"),tr("View Messages"),this,SLOT(startMessageDialog()) );
menu->addAction(QIcon(":/images/tray-icon-idle.png"),tr("Start Application UI"),this,SLOT(startGUI()) );
menu->addSeparator();
menu->addAction(QIcon(":/images/application-exit.png"),tr("Close Life Preserver Tray"),this,SLOT(slotClose()) );
this->setContextMenu(menu);
//Setup initial icon for the tray
this->setIcon( QIcon(":/images/tray-icon-idle.png") );
//Create the configuration GUI
GUI = new mainUI();
msgdlg = new LPMessages();
//connect other signals/slots
connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(slotTrayClicked(QSystemTrayIcon::ActivationReason)) );
//Start up the watcher
Expand All @@ -26,6 +29,8 @@ LPTray::LPTray() : QSystemTrayIcon(){
LPTray::~LPTray(){
watcher->stop();
delete watcher;
delete GUI;
delete msgdlg;
}

// ===============
Expand Down Expand Up @@ -136,3 +141,29 @@ void LPTray::startGUI(){
GUI->raise();
GUI->show();
}

void LPTray::startMessageDialog(){
//Get all the available messages from the watcher
QStringList msgs, errs, logs; //message variables to fill
//Cycle through the watcher types and get any messages
QStringList types; types << "message" << "replication" << "critical" << "mirror" << "resilver" << "scrub";
QStringList infoL; infoL << "id" << "timestamp" << "device" << "message" << "files";
for(int i=0; i<types.length(); i++){
QStringList info = watcher->getMessages(types[i], infoL);
if(info.isEmpty()){continue;}
if(info[0] == "ERROR"){
errs << info[1] + " (" + info[2] + "): " + info[3];
}else if(!info[0].isEmpty()){
msgs << info[1] + " (" + info[2] + "): " + info[3];
}
if(!info[4].isEmpty()){
logs << info[4]; // In format: "example logfile </var/logs/example.log>"
}
}
//Now start up the dialog
msgdlg->setMessages( msgs.join("\n") );
msgdlg->setErrors( errs.join("\n") );
msgdlg->setLogFiles(logs);
msgdlg->raise();
msgdlg->show();
}
4 changes: 3 additions & 1 deletion src-qt4/life-preserver/LPTray.h
Expand Up @@ -8,6 +8,7 @@

#include "mainUI.h"
#include "LPWatcher.h"
#include "LPMessages.h"

class LPTray : public QSystemTrayIcon{
Q_OBJECT
Expand All @@ -17,10 +18,10 @@ class LPTray : public QSystemTrayIcon{

private:
LPWatcher *watcher;
LPMessages *msgdlg;
QMenu *menu;
mainUI *GUI;


void updateTrayIcon();
void updateToolTip();

Expand All @@ -31,6 +32,7 @@ private slots:
void slotClose();
void slotSingleInstance();
void startGUI();
void startMessageDialog();

};

Expand Down

0 comments on commit 5119a91

Please sign in to comment.