Skip to content

Commit

Permalink
Traymonitor icon show warning icon
Browse files Browse the repository at this point in the history
When there is a connection problem like
 - connection cannot be established
 - authentication fails
the icon of the traymonitor is changed to an exclamation mark

Signed-off-by: Marco van Wieringen <marco.van.wieringen@bareos.com>
  • Loading branch information
Oleg Livshyts authored and Marco van Wieringen committed Feb 17, 2015
1 parent f0f69a6 commit 8ec77d0
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 88 deletions.
Binary file added src/images/bareos_3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 0 additions & 2 deletions src/qt-tray-monitor/authenticate.cpp
Expand Up @@ -31,8 +31,6 @@
#include "jcr.h"
#include "monitoritemthread.h"

void senditf(const char *fmt, ...);
void sendit(const char *buf);

/* Commands sent to Director */
static char DIRhello[] = "Hello %s calling\n";
Expand Down
1 change: 1 addition & 0 deletions src/qt-tray-monitor/main.qrc
Expand Up @@ -4,5 +4,6 @@
<file>../images/W.png</file>
<file>../images/bareos_1.png</file>
<file>../images/bareos_2.png</file>
<file>../images/bareos_3.png</file>
</qresource>
</RCC>
23 changes: 23 additions & 0 deletions src/qt-tray-monitor/mainwindow.cpp
Expand Up @@ -60,6 +60,11 @@ MainWindow::MainWindow(QWidget *parent)
ui->tabWidget->removeTab(0);
}

bRefs = new bool[nTabs];
for(int i=0; i<nTabs; i++)
bRefs[i] = true;


// Now show the tray icon, but leave the MainWindow hidden.
systemTrayIcon->show();
}
Expand All @@ -68,6 +73,7 @@ MainWindow::~MainWindow()
{
delete ui;
delete monitorTabMap;
delete bRefs;
}

MainWindow* MainWindow::instance()
Expand All @@ -93,6 +99,9 @@ void MainWindow::destruct()

void MainWindow::addTabs(QStringList tabRefs)
{
tabs = tabRefs; //
nTabs = tabRefs.size();

for (int i = 0; i < tabRefs.count(); i++) {
MonitorTab* tab = new MonitorTab(tabRefs[i], this);
monitorTabMap->insert(tabRefs[i], tab); //tabRefs[i] used as reference
Expand Down Expand Up @@ -173,6 +182,8 @@ void MainWindow::onShowStatusbarMessage(QString message)

void MainWindow::onStatusChanged(const QString &tabRef, int state)
{
int n = tabs.indexOf(tabRef);

MonitorTab* tab = monitorTabMap->value(tabRef);

if (tab) {
Expand All @@ -182,12 +193,24 @@ void MainWindow::onStatusChanged(const QString &tabRef, int state)
}

switch(state) {

case MonitorItem::Error:

bRefs[n] = false;

systemTrayIcon->setNewIcon(2); // red Icon on Error
ui->tabWidget->setTabIcon(idx, QIcon(":images/W.png"));
break;

case MonitorItem::Running:

bRefs[n] = true;
if( bRefs[(n+1)%nTabs] && bRefs[(n+2)%nTabs]) // if all Tabs OK
systemTrayIcon->setNewIcon(0); // shows blue Icon

ui->tabWidget->setTabIcon(idx, QIcon());
break;

default:
break;
} /* switch(state) */
Expand Down
4 changes: 4 additions & 0 deletions src/qt-tray-monitor/mainwindow.h
Expand Up @@ -64,6 +64,10 @@ class MainWindow : public QMainWindow
QMap<QString,MonitorTab*>* monitorTabMap;
SystemTrayIcon* systemTrayIcon;

QStringList tabs;
int nTabs;
bool *bRefs;

public slots:
/* auto-connected slots to the UI */
void on_pushButton_Close_clicked();
Expand Down
130 changes: 56 additions & 74 deletions src/qt-tray-monitor/monitoritem.cpp
Expand Up @@ -57,79 +57,52 @@ bool MonitorItem::get_job_defaults(struct JobDefaults &job_defs)
int stat;
char *def;
BSOCK *dircomm;
bool rtn = false;
QString scmd = QString(".defaults job=\"%1\"").arg(job_defs.job_name);

if (job_defs.job_name == "") {
return rtn;
if (job_defs.job_name == "" || !doconnect()) {
return false;
}

if (!doconnect()) {
return rtn;
}
dircomm = d->DSock;
dircomm->fsend("%s", scmd.toUtf8().data());

while ((stat = dircomm->recv()) > 0) {

def = strchr(dircomm->msg, '=');
if (!def) {
continue;
}
/* Pointer to default value */
*def++ = 0;
strip_trailing_newline(def);

if (strcmp(dircomm->msg, "job") == 0) {
if (strcmp(def, job_defs.job_name.toUtf8().data()) != 0) {
goto bail_out;
if (def) {

/* Pointer to default value */
*def++ = 0;
strip_trailing_newline(def);

if (strcmp(dircomm->msg, "job") == 0) {

if (strcmp(def, job_defs.job_name.toUtf8().data()) != 0)
return false;
} else if (strcmp(dircomm->msg, "pool") == 0) {
job_defs.pool_name = def;
} else if (strcmp(dircomm->msg, "messages") == 0) {
job_defs.messages_name = def;
} else if (strcmp(dircomm->msg, "client") == 0) {
job_defs.client_name = def;
} else if (strcmp(dircomm->msg, "storage") == 0) {
job_defs.store_name = def;
} else if (strcmp(dircomm->msg, "where") == 0) {
job_defs.where = def;
} else if (strcmp(dircomm->msg, "level") == 0) {
job_defs.level = def;
} else if (strcmp(dircomm->msg, "type") == 0) {
job_defs.type = def;
} else if (strcmp(dircomm->msg, "fileset") == 0) {
job_defs.fileset_name = def;
} else if (strcmp(dircomm->msg, "catalog") == 0) {
job_defs.catalog_name = def;
job_defs.enabled = *def == '1' ? true : false;
}
continue;
}
if (strcmp(dircomm->msg, "pool") == 0) {
job_defs.pool_name = def;
continue;
}
if (strcmp(dircomm->msg, "messages") == 0) {
job_defs.messages_name = def;
continue;
}
if (strcmp(dircomm->msg, "client") == 0) {
job_defs.client_name = def;
continue;
}
if (strcmp(dircomm->msg, "storage") == 0) {
job_defs.store_name = def;
continue;
}
if (strcmp(dircomm->msg, "where") == 0) {
job_defs.where = def;
continue;
}
if (strcmp(dircomm->msg, "level") == 0) {
job_defs.level = def;
continue;
}
if (strcmp(dircomm->msg, "type") == 0) {
job_defs.type = def;
continue;
}
if (strcmp(dircomm->msg, "fileset") == 0) {
job_defs.fileset_name = def;
continue;
}
if (strcmp(dircomm->msg, "catalog") == 0) {
job_defs.catalog_name = def;
continue;
}
if (strcmp(dircomm->msg, "enabled") == 0) {
job_defs.enabled = *def == '1' ? true : false;
continue;
}
}
rtn = true;
/* Fall through wanted */
bail_out:
return rtn;
return true;
}

bool MonitorItem::doconnect()
Expand All @@ -148,6 +121,7 @@ bool MonitorItem::doconnect()
QString message;

switch (d->type) {

case R_DIRECTOR:
dird = static_cast<DIRRES*>(d->resource);
message = QString("Connecting to Director %1:%2").arg(dird->address).arg(dird->DIRport);
Expand All @@ -161,6 +135,7 @@ bool MonitorItem::doconnect()
jcr.dir_bsock = d->DSock;
}
break;

case R_CLIENT:
filed = static_cast<CLIENTRES*>(d->resource);
message = QString("Connecting to Client %1:%2").arg(filed->address).arg(filed->FDport);
Expand All @@ -174,6 +149,7 @@ bool MonitorItem::doconnect()
jcr.file_bsock = d->DSock;
}
break;

case R_STORAGE:
stored = static_cast<STORERES*>(d->resource);
message = QString("Connecting to Storage %1:%2").arg(stored->address).arg(stored->SDport);
Expand All @@ -187,27 +163,32 @@ bool MonitorItem::doconnect()
jcr.store_bsock = d->DSock;
}
break;

default:
printf("Error, currentitem is not a Client, a Storage or a Director..\n");
return false;
}

char *name = get_name();

if (d->DSock == NULL) {

emit showStatusbarMessage("Cannot connect to daemon.");
emit clearText(get_name());
emit appendText(get_name(), QString("Cannot connect to daemon."));
emit clearText(name);
emit appendText(name, QString("Cannot connect to daemon."));
d->state = MonitorItem::Error;
emit statusChanged(get_name(), d->state);
emit statusChanged(name, d->state);
return false;
}

if (!authenticate_daemon(this, &jcr)) {

d->state = MonitorItem::Error;
emit statusChanged(get_name(), d->state);
emit statusChanged(name, d->state);
message = QString("Authentication error : %1").arg(d->DSock->msg);
emit showStatusbarMessage(message);
emit clearText(get_name());
emit appendText(get_name(), QString("Authentication error : %1").arg(d->DSock->msg));
emit clearText(name);
emit appendText(name, QString("Authentication error : %1").arg(d->DSock->msg));
d->DSock->signal(BNET_TERMINATE); /* send EOF */
d->DSock->close();
delete d->DSock;
Expand All @@ -216,19 +197,23 @@ bool MonitorItem::doconnect()
}

switch (d->type) {

case R_DIRECTOR:
emit showStatusbarMessage("Opened connection with Director daemon.");
break;

case R_CLIENT:
emit showStatusbarMessage("Opened connection with File daemon.");
break;

case R_STORAGE:
emit showStatusbarMessage("Opened connection with Storage daemon.");
break;

default:
emit showStatusbarMessage("Error, currentitem is not a Client, a Storage or a Director..\n");
d->state = Error;
emit statusChanged(get_name(), d->state);
emit statusChanged(name, d->state);
return false;
}

Expand All @@ -237,7 +222,7 @@ bool MonitorItem::doconnect()
}

d->state = Running;
emit statusChanged(get_name(), d->state);
emit statusChanged(name, d->state);

return true;
}
Expand Down Expand Up @@ -282,15 +267,12 @@ bool MonitorItem::docmd(const char* command)
if (d->type == R_CLIENT)
emit jobIsRunning (jobRunning);
return true;
}
else if (d->DSock->msglen == BNET_SUB_PROMPT) {
} else if (d->DSock->msglen == BNET_SUB_PROMPT) {
// qDebug() << "<< PROMPT >>";
return false;
}
else if (d->DSock->msglen == BNET_HEARTBEAT) {
} else if (d->DSock->msglen == BNET_HEARTBEAT) {
bnet_sig(d->DSock, BNET_HB_RESPONSE);
}
else {
} else {
qDebug() << bnet_sig_to_ascii(d->DSock);
}
} else { /* BNET_HARDEOF || BNET_ERROR */
Expand Down
8 changes: 6 additions & 2 deletions src/qt-tray-monitor/monitoritemthread.cpp
Expand Up @@ -201,7 +201,9 @@ MONITORRES* MonitorItemThread::getMonitor() const
MonitorItem* MonitorItemThread::getDirector() const
{
// search for the first occurrence of a director
for (int i = 0; i < items.count(); i++) {

int count = items.count();
for (int i = 0; i < count; i++) {
if (items[i]->type() == R_DIRECTOR) {
return items[i];
}
Expand All @@ -215,7 +217,9 @@ MonitorItem* MonitorItemThread::getDirector() const
void MonitorItemThread::dotest()
{
const char *cmd;
for (int i = 0; i < items.count(); i++) {
int count = items.count();

for (int i = 0; i < count; i++) {
switch (items[i]->type()) {
case R_DIRECTOR:
cmd = ".jobs type=B";
Expand Down
24 changes: 14 additions & 10 deletions src/qt-tray-monitor/systemtrayicon.cpp
Expand Up @@ -21,7 +21,6 @@

#include "systemtrayicon.h"
#include "traymenu.h"

#include <QObject>
#include <QMainWindow>
#include <QTimer>
Expand All @@ -38,8 +37,7 @@ SystemTrayIcon::SystemTrayIcon(QMainWindow* mainWindow)
TrayMenu* menu = new TrayMenu(mainWindow);
setContextMenu(menu);

icons << ":/images/bareos_1.png" << ":/images/bareos_2.png" ;

icons << ":/images/bareos_1.png" << ":/images/bareos_2.png" << ":/images/W.png";
setIcon(QIcon(icons[iconIdx]));
setToolTip("Bareos Tray Monitor");

Expand All @@ -52,12 +50,16 @@ SystemTrayIcon::~SystemTrayIcon()
timer->stop();
}

void SystemTrayIcon::setIconInternal()
void SystemTrayIcon::setNewIcon(int icon){

iconIdx = icon;
setIcon(QIcon(icons[icon]));
}

void SystemTrayIcon::setIconInternal()
{
setIcon(QIcon(icons[iconIdx]));
if (++iconIdx == icons.count()) {
iconIdx = 0;
}
setIcon(QIcon(icons[iconIdx++]));
iconIdx %= 2; // 0 if 1 / 1 if 0
}

void SystemTrayIcon::animateIcon(bool on)
Expand All @@ -70,7 +72,9 @@ void SystemTrayIcon::animateIcon(bool on)
if (timer->isActive()) {
timer->stop();
}
iconIdx = 0;
setIconInternal();
if(iconIdx != 2){ // blink if there's no error
iconIdx = 0;
setIconInternal();
}
}
}

0 comments on commit 8ec77d0

Please sign in to comment.