Commit 3907b37e authored by Giacomo Strangolino's avatar Giacomo Strangolino
Browse files

merged with master

parents f204eced 105c38d7
......@@ -10,8 +10,6 @@ DEFINES -= QT_NO_DEBUG_OUTPUT
TEMPLATE = app
CONFIG += warn_on debug qt app_bundle
QT += sql
QT += multimedia
......
......@@ -8,23 +8,11 @@
#include <QApplication>
#include <QCoreApplication>
#include <cumacros.h>
#include <cudata.h>
#include <qustring.h>
AlarmHistoryTree::AlarmHistoryTree(QWidget *parent) : QTreeView(parent)
{
db = QSqlDatabase::addDatabase("QMYSQL");
QStringList args = qApp->arguments();
QString dbHost = "fcslog-replica-01";
if(args.contains("--dbh") && args.size() > args.indexOf("--dbh")) {
dbHost = args.at(args.indexOf("--dbh") + 1);
}
db.setHostName(dbHost);
db.setDatabaseName("hdbpp");
db.setUserName("hdbppro");
db.setPassword("hdbppro");
if (!db.open()) {
QString sqlErr = db.lastError().text();
QMessageBox::critical(0, "Error", QString("Can't establish connection with db \"alarm\" on host log:\n%1").arg(sqlErr));
}
AlarmHistoryTree::AlarmHistoryTree(QWidget *parent) : QTreeView(parent) {
m_sql_model = new MySqlModel();
m_sql_model->setHeaderData(0, Qt::Horizontal, "Timestamp");
setModel(m_sql_model);
......@@ -50,7 +38,7 @@ void AlarmHistoryTree::applyFilter(AlarmFilter f)
printf("AlarmHistoryTree.applyFilter: status %s row status %s\n", qstoc(f.status), qstoc(rowEls[STATUS].toString()));
if(rowEls.size() > STATUS && rowEls[STATUS] != f.status && !isRowHidden(i, root))
setRowHidden(i, root, true);
}
}
}
_filter_enabled = true;
......@@ -72,8 +60,37 @@ QAbstractItemModel *AlarmHistoryTree::model() const {
void AlarmHistoryTree::onFilterNameChanged(const QString &f) {
for(int i = 0; i < m_sql_model->rowCount(); i++) {
setRowHidden(i, QModelIndex(), !f.isEmpty() && !m_sql_model->data(m_sql_model->index(i, NAME), Qt::DisplayRole).toString().contains(f));
setRowHidden(i, QModelIndex(), !f.isEmpty() && !m_sql_model->data(m_sql_model->index(i, NAME), Qt::DisplayRole).toString().contains(f));
}
}
void AlarmHistoryTree::onDbParamsReady(const CuData &p) {
QString m;
bool err = p.B("err");
if(err) {
m = QuString(p, "msg");
printf("AlarmHistoryTree::onDbParamsReady error ? %s\n", datos(p));
}
else {
db = QSqlDatabase::addDatabase("QMYSQL");
std::vector<std::string> pa = p["value"].toStringVector();
if(pa.size() != 5)
m = QString("HistoryDB property: expected 4 parameters (host, user, password, database, port), found %1").arg(pa.size());
else {
db.setHostName(pa[0].c_str());
db.setUserName(pa[1].c_str());
db.setPassword(pa[2].c_str());
db.setDatabaseName(pa[3].c_str());
db.setPort(QuString(pa[4]).toInt());
if (!db.open())
m = QString("Can't establish connection with db with params %s:\n%1").arg(p["value"].toString().c_str()).arg(db.lastError().text());
else
printf("AlarmHistoryTree::onDbParamsReady: successfully opened db\n");
}
}
if(!m.isEmpty())
QMessageBox::critical(0, "Error", m);
}
void AlarmHistoryTree::executeQuery(QString &q) {
......
......@@ -8,6 +8,7 @@
#include <QSqlDatabase>
class MySqlModel;
class CuData;
class AlarmHistoryTree : public QTreeView
{
......@@ -22,6 +23,7 @@ class AlarmHistoryTree : public QTreeView
public slots:
void onFilterNameChanged(const QString& f);
void onDbParamsReady(const CuData& p);
protected:
......
......@@ -37,92 +37,11 @@ AlarmTreeWidget::AlarmTreeWidget(QWidget *parent) : QTreeWidget(parent)
connect(this, SIGNAL(itemEntered(QTreeWidgetItem*,int)), this, SLOT(slotItemEntered(QTreeWidgetItem*,int)));
}
void AlarmTreeWidget::applyFilter(AlarmFilter f)
{
QList<QTreeWidgetItem *> items;
int i;
if(_filter_enabled)
removeFilter();
items = findItems("*", Qt::MatchWildcard);
if(f.ack_enable) {
QString sack = f.ack ? "ACK" : "NACK";
for(i = 0; i < items.size(); i++)
if(items[i]->text(ACK) != sack)
items[i]->setHidden(true);
headerItem()->setIcon(ACK, QIcon(ICON_PATH + "filter.png"));
}
else
headerItem()->setIcon(ACK, QIcon(ICON_PATH + ""));
if(f.lev) {
for(i = 0; i < items.size(); i++) {
/* must not have been hidden previously */
if(!items[i]->isHidden()) {
if(items[i]->text(LEVEL) != f.level)
items[i]->setHidden(true);
}
}
headerItem()->setIcon(LEVEL, QIcon(ICON_PATH + "filter.png"));
}
else
headerItem()->setIcon(LEVEL, QIcon(ICON_PATH + ""));
if(f.stat) {
for(i = 0; i < items.size(); i++) {
/* must not have been hidden previously */
if(!items[i]->isHidden()) {
if(items[i]->text(STATUS) != f.status)
items[i]->setHidden(true);
}
}
headerItem()->setIcon(STATUS, QIcon(ICON_PATH + "filter.png"));
}
else
headerItem()->setIcon(STATUS, QIcon(ICON_PATH + ""));
if(f.grp) {
for(i = 0; i < items.size(); i++) {
/* must not have been hidden previously */
if(!items[i]->isHidden())
{
for(int j = 0; j < f.groups.size(); j++) {
if(!items[i]->text(DEVICE).contains(f.groups[j])) {
items[i]->setHidden(true);
break;
}
}
}
}
headerItem()->setIcon(DEVICE, QIcon(ICON_PATH + "filter.png"));
}
else
headerItem()->setIcon(DEVICE, QIcon(ICON_PATH + ""));
_filter_enabled = true;
}
void AlarmTreeWidget::setType(AlarmTreeWidget::Type t) {
m_type = t;
}
void AlarmTreeWidget::removeFilter()
{
QList<QTreeWidgetItem *> items;
int i;
items = findItems("*", Qt::MatchWildcard);
for(i = 0; i < items.size(); i++)
if(items[i]->isHidden())
items[i]->setHidden(false);
_filter_enabled = false;
headerItem()->setIcon(ACK, QIcon(ICON_PATH + ""));
headerItem()->setIcon(LEVEL, QIcon(ICON_PATH + ""));
headerItem()->setIcon(STATUS, QIcon(ICON_PATH + ""));
headerItem()->setIcon(DEVICE, QIcon(ICON_PATH + ""));
}
void AlarmTreeWidget::refresh(const CuData &v) {
double d = static_cast<int>(v["timestamp_us"].toDouble());
QString ts = QDateTime::fromSecsSinceEpoch(d).toString("HH:mm:ss");
......@@ -133,20 +52,18 @@ void AlarmTreeWidget::refresh(const CuData &v) {
QString dev = src.section('/', 0, src.count('/') - 1);
bool empty = QuString(v, "msg").contains(QRegularExpression("cannot\\s+extract"));
bool err = v["err"].toBool() && !empty;
if(empty)
printf("\e[1;34mAlarmTreeWidget::refresh: attribute %s is empty <<<<<<<<<<<<<<<< \e[0m\n", qstoc(src));
QStringList data;
setToolTip(QuString(v, "msg"));
// error: err flag is true and message is not of type "cannot extract data..."
// only AlarmType adds an entry for each error
if (err && m_type == AlarmType) {
if(!m_src_err_map.contains(src))
m_src_err_map.insert(src, SrvErrNew|SrvErrUnack); // true: new
data << m_gen_error_item(v);
perr("%s: %s\n", qstoc(src), qstoc(toolTip()));
m_src_err.insert(src);
}
else {
if(m_src_err.contains(src)) {
m_src_err.remove(src);
if(m_src_err_map.contains(src)) {
m_src_err_map.remove(src);
src_fixed = src;
}
data = QuStringList(v, "value");
......@@ -191,9 +108,6 @@ void AlarmTreeWidget::refresh(const CuData &v) {
if(!item) /* create a new item */ {
index = findPos(fields[0].toUInt(), fields[AlarmTreeWidgetItem::Level], fields[AlarmTreeWidgetItem::Status]);
m_insert_item(src, fields, index);
// printf("\e[1;33m%s \e[1;34m%s - number of tabs %d -- index %d\e[0m\n",
// qstoc(QDateTime::fromTime_t(fields.first().toUInt()).toString()),
// qstoc(data[i]), data[i].count("\t"), index);
}
else /* update fields of existing items */
item->update(fields);
......@@ -205,6 +119,7 @@ void AlarmTreeWidget::refresh(const CuData &v) {
alsrcset.insert(alanam); // alsrcset is a reference
// notify new alarm detected. connected to Alarm::beep
qDebug() << __PRETTY_FUNCTION__ << fields;
if(fields.size() > 5 && (fields[3] == "ALARM" || fields[3] == "ERROR") && fields.last() == "NEW")
emit newAlarmDetected();
}
......@@ -219,7 +134,7 @@ int AlarmTreeWidget::findPos(time_t ts, const QString &pri, const QString& statu
int i = 0, prio = m_pri_to_int(pri), stat = m_status_to_int(status);
// printf("findPos called with ts %ld, pri %d\n", ts, prio);
while(i < topLevelItemCount() && topLevelItem(i)->data(AlarmTreeWidgetItem::Status, Qt::UserRole).toInt() > stat) {
// printf("1st pri %d pri %d --> i %d\n", prio, topLevelItem(i)->data(AlarmTreeWidgetItem::Level, Qt::UserRole).toInt(), i);
// printf("1st pri %d pri %d --> i %d\nok cont", prio, topLevelItem(i)->data(AlarmTreeWidgetItem::Level, Qt::UserRole).toInt(), i);
i++;
}
......@@ -253,18 +168,25 @@ int AlarmTreeWidget::countAlarmed() const {
return cnt;
}
void AlarmTreeWidget::setServerErrNotNew(const QString &errdev) {
if(m_src_err_map.contains(errdev))
m_src_err_map[errdev] &= ~SrvErrNew;
}
void AlarmTreeWidget::setServerErrAck(const QString &n) {
if(m_src_err_map.contains(n))
m_src_err_map[n] &= ~SrvErrUnack;
}
void AlarmTreeWidget::contextMenuEvent(QContextMenuEvent *e)
{
bool silenceAvail = true;
bool enable = true;
QList<QTreeWidgetItem *>items = this->selectedItems();
foreach(QTreeWidgetItem *it, items)
{
foreach(QTreeWidgetItem *it, items) {
int sil = it->text(AlarmTreeWidgetItem::SilencedMin).toInt();
if(sil < 0)
{
silenceAvail = false;
break;
}
silenceAvail &= (sil == 0);
enable &= (sil > 0);
}
if(items.size()) {
QMenu *menu = new QMenu(this);
......@@ -278,6 +200,11 @@ void AlarmTreeWidget::contextMenuEvent(QContextMenuEvent *e)
wikiAction->setProperty("url", it->text(MESSAGE).split(" ").last());
connect(wikiAction, SIGNAL(triggered()), this, SLOT(openUrl()));
}
// enable
if(m_type == AlarmType && enable)
menu->addAction("Enable", this, SIGNAL(enable()));
menu->exec(QCursor::pos());
delete menu;
}
......@@ -304,10 +231,11 @@ void AlarmTreeWidget::m_insert_item(const QString& src, const QStringList &list,
item->setData(AlarmTreeWidgetItem::DateTime, Qt::UserRole, list.at(AlarmTreeWidgetItem::DateTime).toUInt());
item->setData(AlarmTreeWidgetItem::Status, Qt::UserRole, m_status_to_int(list.at(AlarmTreeWidgetItem::Status)));
QString s = src.section('/', 0, src.count('/') - 1);
QRegularExpression re("[tango://]*(.*):\\d+/(.*)");
QRegularExpression re("(?:tango://)*(.*):\\d+/(.*)");
QRegularExpressionMatch ma = re.match(s);
if(ma.capturedTexts().size() > 2) {
s = "[" + ma.capturedTexts().at(1).section('.', 0, 0) + "] " + ma.capturedTexts()[2];
QString s = ma.capturedTexts().at(1);
s.contains('.') ? s = "[" + s.section('.', 0, 0) + "] " + ma.capturedTexts()[2] : s = s;
}
item->setData(AlarmTreeWidgetItem::Device, Qt::UserRole, src.section('/', 0, src.count('/') - 1));
item->setText(AlarmTreeWidgetItem::Device, s);
......@@ -321,10 +249,14 @@ void AlarmTreeWidget::m_insert_item(const QString& src, const QStringList &list,
QString AlarmTreeWidget::m_gen_error_item(const CuData &da) const {
QStringList l;
QDateTime dt = QDateTime::currentDateTime();
QString dev = QuString(da, "src"), msg = QuString(da, "msg");
dev = dev.section('/', 0, dev.count('/') - 1);
l << QString::number(dt.toSecsSinceEpoch()) << "-" << dev << "ERROR" << "NACK" << "high" << "-1" << "gr_handler"
<< msg.replace("\n", " ") << "NEW";
QString dev, src = QuString(da, "src"), msg = QuString(da, "msg");
dev = src.section('/', 0, dev.count('/') - 1);
qDebug() << __PRETTY_FUNCTION__ << m_src_err_map;
bool _new = ((m_src_err_map[src] & (SrvErrNew | SrvErrUnack)) == (SrvErrNew | SrvErrUnack));
printf("\e[1;36mAlarmTreeWidget::m_gen_error_item %d & %d\e[0m\n", m_src_err_map[src] , (SrvErrNew | SrvErrUnack));
l << QString::number(dt.toSecsSinceEpoch()) << "-" << src << "ERROR" << (m_src_err_map[src] & SrvErrUnack ? "UNACK" : "ACK") << "high" << "-1" << "gr_handler"
<< "Alarm server error: " + msg.replace("\n", " ") << (_new ? "NEW" : " ");
qDebug() << __PRETTY_FUNCTION__ << l;
return l.join("\t");
}
......
#ifndef ALARM_TREE_WIDGET_H
#ifndef ALARM_TREE_WIDGET_H
#define ALARM_TREE_WIDGET_H
#include "filter.h"
......@@ -17,14 +17,15 @@ class AlarmTreeWidget : public QTreeWidget
public:
enum Type {AlarmType, DisabledAlarmType };
enum Columns { DATET, MICROSEC, ALARM, STATUS, ACK, LEVEL, SILENCED, DEVICE, MESSAGE, COLUMN_COUNT };
enum SrvErrState { SrvErrNew = 0x1, SrvErrUnack = 0x2 };
AlarmTreeWidget(QWidget *parent);
void applyFilter(AlarmFilter f);
void setType(Type t);
void removeFilter();
int findPos(time_t ts, const QString& pri, const QString &status);
int countAll() const;
int countAlarmed() const;
void setServerErrNotNew(const QString& errdev);
void setServerErrAck(const QString& n);
public slots:
void refresh(const CuData &v);
......@@ -40,6 +41,7 @@ signals:
void mouseOverItem(bool);
void silence();
void ack();
void enable();
protected:
void mouseMoveEvent(QMouseEvent *event);
......@@ -56,7 +58,7 @@ private:
bool _filter_enabled;
QHash<QString, AlarmTreeWidgetItem*> mItemHash;
QHash<QString, QSet<QString> >mSrcAlarmHash;
QSet<QString> m_src_err;
QMap<QString, int> m_src_err_map;
QString m_make_key(const QString& alarm, const QString& handler) const;
Type m_type;
......
......@@ -124,7 +124,7 @@ void AlarmTreeWidgetItem::update(const QStringList &fields)
setBackground(SilencedMin, c);
mHasMutedIcon = true;
}
else if(mHasMutedIcon && silenced < 0)
else if(mHasMutedIcon && silenced <= 0)
{
mHasMutedIcon = false;
setIcon(SilencedMin, mNullIcon);
......
......@@ -23,7 +23,8 @@ Sound::~Sound()
void Sound::play()
{
mSound->play();
if(mSound->isFinished())
mSound->play();
}
void Sound::stop()
......
......@@ -5,50 +5,85 @@
#include <AlarmTreeWidget.h>
#include <AlarmTreeWidgetItem.h>
#include <quwriter.h>
#include <QtDebug>
Acmd::Acmd() {
}
void Acmd::ack(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool& fpoo) {
// ack alarms
// if a selected element represents a server error (not a true alarm), then do not operate on it
// and store the name into errdevs
void Acmd::ack(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool& fpoo, QStringList &errdevs) {
QMultiMap<QString, QString> map = m_getDevAlarmMap(tw, all);
foreach(const QString& dev, map.uniqueKeys()) {
QuWriter *w = new QuWriter(nullptr, cup, fpoo);
const QStringList &alarms = map.values(dev);
w->setAutoDestroy(true);
w->setTarget(QString("%1->Ack").arg(dev));
printf("AckCmd.ack: executing %s (%s)\n", qstoc(w->target()), qstoc(alarms.join(",")));
w->execute(alarms);
if(alarms.size() != 1 || alarms[0].count('/') == 0) { // exclude "Alarm server error"
w->setAutoDestroy(true);
w->setTarget(QString("%1->Ack").arg(dev));
w->execute(alarms);
/* stop new */
QuWriter *stopNewWriter = new QuWriter(nullptr, cup, fpoo);
stopNewWriter->setAutoDestroy(true);
stopNewWriter->setTarget(dev + "->StopNew");
stopNewWriter->execute();
/* stop new */
QuWriter *stopNewWriter = new QuWriter(nullptr, cup, fpoo);
stopNewWriter->setAutoDestroy(true);
stopNewWriter->setTarget(dev + "->StopNew");
stopNewWriter->execute();
}
else
errdevs << alarms[0];
}
}
void Acmd::silence(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool &fpoo) {
// silence alarms
// if a selected element represents a server error (not a true alarm), then do not operate on it
// and store the name into errdevs
void Acmd::silence(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool &fpoo, QStringList &errdevs) {
QMultiMap<QString, QString> map = m_getDevAlarmMap(tw, all);
foreach(const QString& dev, map.uniqueKeys()) {
QuWriter *w = new QuWriter(nullptr, cup, fpoo);
const QStringList &alarms = map.values(dev);
w->setAutoDestroy(true);
w->setTarget(dev + "->Silence");
printf("AckCmd.ack: executing %s (%s)\n", qstoc(w->target()), qstoc(alarms.join(",")));
w->execute(alarms);
if(alarms.size() != 1 || alarms[0].count('/') == 0) { // exclude "Alarm server error"
w->setAutoDestroy(true);
w->setTarget(dev + "->Silence");
w->execute(alarms);
}
else
errdevs << alarms[0];
}
}
void Acmd::stop_new(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool &fpoo) {
QMultiMap<QString, QString> map = m_getDevAlarmMap(tw, all);
// enable selected alarms
//
void Acmd::enable(const QTreeWidget *tw, CumbiaPool *cup, const CuControlsFactoryPool &fpoo) {
QMultiMap<QString, QString> map = m_getDevAlarmMap(tw, false);
foreach(const QString& dev, map.uniqueKeys()) {
QuWriter *w = new QuWriter(nullptr, cup, fpoo);
const QStringList &alarms = map.values(dev);
w->setAutoDestroy(true);
w->setTarget(dev + "->StopNew");
printf("AckCmd.stop_new: executing %s\n", qstoc(w->target()));
w->execute(alarms);
if(alarms.size() != 1 || alarms[0].count('/') == 0) { // exclude "Alarm server error"
w->setAutoDestroy(true);
w->setTarget(dev + "->Enable");
w->execute(alarms);
}
}
}
// stop new alarms
// if a selected element represents a server error (not a true alarm), then do not operate on it
// and store the name into errdevs
void Acmd::stop_new(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool &fpoo,
QStringList &errdevs) {
QMultiMap<QString, QString> map = m_getDevAlarmMap(tw, all);
foreach(const QString& dev, map.uniqueKeys()) { // exclude "Alarm server error"
QuWriter *w = new QuWriter(nullptr, cup, fpoo);
const QStringList &alarms = map.values(dev);
if(alarms.size() != 1 || alarms[0].count('/') == 0) {
w->setAutoDestroy(true);
w->setTarget(dev + "->StopNew");
w->execute(alarms);
}
else
errdevs << alarms[0];
}
}
......
......@@ -11,10 +11,10 @@ class Acmd
{
public:
Acmd();
void ack(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool &fpoo);
void silence(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool &fpoo);
void stop_new(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool &fpoo);
void ack(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool &fpoo, QStringList& errdevs);
void silence(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool &fpoo, QStringList &errdevs);
void stop_new(const QTreeWidget *tw, bool all, CumbiaPool *cup, const CuControlsFactoryPool &fpoo, QStringList &errdevs);
void enable(const QTreeWidget *tw, CumbiaPool *cup, const CuControlsFactoryPool &fpoo);
private:
QMultiMap<QString, QString> m_getDevAlarmMap(const QTreeWidget *tw, bool all) const;
};
......
......@@ -69,6 +69,9 @@ Alarm::Alarm(CumbiaPool *cu_p, QWidget *parent) : QWidget(parent)
connect(ui->treeWidgetAlarms, SIGNAL(silence()), this, SLOT(stopSound()));
/* ack. Also uses QTWriter to impart StopNew command */
connect(ui->treeWidgetAlarms, SIGNAL(ack()), this, SLOT(ack()));
/* enable */
connect(ui->treeWidgetAlarms, SIGNAL(enable()), this, SLOT(enable()));
connect(ui->pBStopSound, SIGNAL(clicked()), this, SLOT(stopSound()));
connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
......@@ -88,6 +91,14 @@ Alarm::Alarm(CumbiaPool *cu_p, QWidget *parent) : QWidget(parent)
connect(db_dlist_w, SIGNAL(newData(CuData)), this, SLOT(onDevList(CuData)));
db_dlist_w->setSource(QString("tango://#AlarmHandler#%1").arg(devlist_prop));
// db params
QuWatcher *db_conn_p = new QuWatcher(this, cu_pool, m_ctrl_factory_pool); // device prop watcher
db_conn_p->setObjectName("db_conn_p");
db_conn_p->setSingleShot(true);
db_conn_p->setAutoDestroy(true);
connect(db_conn_p, SIGNAL(newData(CuData)), ui->twHistory, SLOT(onDbParamsReady(CuData)));
db_conn_p->setSource(QString("tango://#AlarmHandler#HistoryDb"));
// groups
QuWatcher *grpW = new QuWatcher(this, cu_pool, m_ctrl_factory_pool);
grpW->setObjectName("group_w");
......@@ -119,9 +130,6 @@ Alarm::Alarm(CumbiaPool *cu_p, QWidget *parent) : QWidget(parent)
sound = new Sound(soundFileName);
connect( ui->pBTestSoundOn,SIGNAL(clicked()), sound, SLOT(play()));
connect( ui->pBTestSoundOff,SIGNAL(clicked()), sound, SLOT(stop()));
ui->groupBoxFilter->setHidden(true);
connect(ui->pBFilter, SIGNAL(toggled(bool)), ui->groupBoxFilter, SLOT(setVisible(bool)));
connect(ui->cBStatus, SIGNAL(toggled(bool)), ui->comboStatus, SLOT(setEnabled(bool)));
ui->pbInfo->setEnabled(false);
......@@ -141,6 +149,8 @@ Alarm::Alarm(CumbiaPool *cu_p, QWidget *parent) : QWidget(parent)
/* sound: beep on new alarm */
connect(ui->treeWidgetAlarms, SIGNAL(newAlarmDetected()), this, SLOT(beep()));
ui->tabWidget->setCurrentIndex(0);
// database
ui->dateStart->setDate(QDate::currentDate());
ui->dateStop->setDate(QDate::currentDate());
......@@ -151,6 +161,7 @@ Alarm::Alarm(CumbiaPool *cu_p, QWidget *parent) : QWidget(parent)
connect(ui->leFilterName, SIGNAL(textChanged(QString)), this, SLOT(onFilterNameChanged(QString)));
connect(ui->comboStatus, SIGNAL(currentTextChanged(QString)), this, SLOT(onFilterStatusChanged(QString)));
connect(ui->cBStatus, SIGNAL(toggled(bool)), this, SLOT(onFilterStatusEnabled(bool)));
connect(ui->pbClearFilter, SIGNAL(clicked()), ui->leFilterName, SLOT(clear()));
m_filter = new AlarmFilter(ui->twHistory);
}
......@@ -160,6 +171,7 @@ Alarm::~Alarm() {
sound->stop();
delete sound;
}
delete m_filter;
}
void Alarm::refresh(const CuData &da) {
......@@ -169,6 +181,8 @@ void Alarm::refresh(const CuData &da) {
QString tn = "%1 [%2]";
if(att == "alarm") ui->tabWidget->setTabText(0, tn.arg("Alarm").arg(tw->countAlarmed()));
else ui->tabWidget->setTabText(1, tn.arg("Disabled Alarms").arg(tw->countAll()));
// filter
m_filter->filter();
}
void Alarm::onDevList(const CuData &da) {
......@@ -212,7 +226,16 @@ QList<QTreeWidgetItem *> Alarm::mGetSelectedItems()
void Alarm::silence()
{
Acmd acmd;
acmd.silence(ui->treeWidgetAlarms, false, cu_pool, m_ctrl_factory_pool);
QStringList errdevs; // list of "server error" devs
acmd.silence(ui->treeWidgetAlarms, false, cu_pool, m_ctrl_factory_pool, errdevs);
foreach(const QString& ed, errdevs)
ui->treeWidgetAlarms->setServerErrNotNew(ed);
sound->stop();
}
void Alarm::enable() {
Acmd acmd;
acmd.enable(ui->treeWidgetAlarms, cu_pool, m_ctrl_factory_pool);
}
void Alarm::testSound() {
......@@ -230,18 +253,31 @@ void Alarm::openUrl(const QString &u) const {
void Alarm::stopSound() {
Acmd acmd;
acmd.stop_new(ui->treeWidgetAlarms, true, cu_pool, m_ctrl_factory_pool);
QString