2008-02-28 02:34:43 +01:00
|
|
|
/*
|
|
|
|
* wpa_gui - EventHistory class
|
|
|
|
* Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
|
|
|
|
*
|
2012-02-11 15:46:35 +01:00
|
|
|
* This software may be distributed under the terms of the BSD license.
|
|
|
|
* See README for more details.
|
2008-02-28 02:34:43 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QHeaderView>
|
|
|
|
#include <QScrollBar>
|
|
|
|
|
|
|
|
#include "eventhistory.h"
|
|
|
|
|
|
|
|
|
|
|
|
int EventListModel::rowCount(const QModelIndex &) const
|
|
|
|
{
|
|
|
|
return msgList.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int EventListModel::columnCount(const QModelIndex &) const
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QVariant EventListModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
if (!index.isValid())
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
if (role == Qt::DisplayRole)
|
|
|
|
if (index.column() == 0) {
|
|
|
|
if (index.row() >= timeList.size())
|
|
|
|
return QVariant();
|
|
|
|
return timeList.at(index.row());
|
|
|
|
} else {
|
|
|
|
if (index.row() >= msgList.size())
|
|
|
|
return QVariant();
|
|
|
|
return msgList.at(index.row());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QVariant EventListModel::headerData(int section, Qt::Orientation orientation,
|
|
|
|
int role) const
|
|
|
|
{
|
|
|
|
if (role != Qt::DisplayRole)
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
if (orientation == Qt::Horizontal) {
|
|
|
|
switch (section) {
|
|
|
|
case 0:
|
2010-04-11 21:35:02 +02:00
|
|
|
return QString(tr("Timestamp"));
|
2008-02-28 02:34:43 +01:00
|
|
|
case 1:
|
2010-04-11 21:35:02 +02:00
|
|
|
return QString(tr("Message"));
|
2008-02-28 02:34:43 +01:00
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
return QString("%1").arg(section);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EventListModel::addEvent(QString time, QString msg)
|
|
|
|
{
|
|
|
|
beginInsertRows(QModelIndex(), msgList.size(), msgList.size() + 1);
|
|
|
|
timeList << time;
|
|
|
|
msgList << msg;
|
|
|
|
endInsertRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-08 23:01:01 +02:00
|
|
|
EventHistory::EventHistory(QWidget *parent, const char *, bool, Qt::WindowFlags)
|
2008-02-28 02:34:43 +01:00
|
|
|
: QDialog(parent)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
|
|
|
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
|
|
|
|
|
2015-05-08 23:01:01 +02:00
|
|
|
eventListView->setItemsExpandable(false);
|
|
|
|
eventListView->setRootIsDecorated(false);
|
2008-02-28 02:34:43 +01:00
|
|
|
elm = new EventListModel(parent);
|
|
|
|
eventListView->setModel(elm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EventHistory::~EventHistory()
|
|
|
|
{
|
|
|
|
destroy();
|
|
|
|
delete elm;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EventHistory::languageChange()
|
|
|
|
{
|
|
|
|
retranslateUi(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EventHistory::addEvents(WpaMsgList msgs)
|
|
|
|
{
|
|
|
|
WpaMsgList::iterator it;
|
|
|
|
for (it = msgs.begin(); it != msgs.end(); it++)
|
|
|
|
addEvent(*it);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EventHistory::addEvent(WpaMsg msg)
|
|
|
|
{
|
|
|
|
bool scroll = true;
|
|
|
|
|
|
|
|
if (eventListView->verticalScrollBar()->value() <
|
|
|
|
eventListView->verticalScrollBar()->maximum())
|
|
|
|
scroll = false;
|
|
|
|
|
|
|
|
elm->addEvent(msg.getTimestamp().toString("yyyy-MM-dd hh:mm:ss.zzz"),
|
|
|
|
msg.getMsg());
|
|
|
|
|
|
|
|
if (scroll)
|
|
|
|
eventListView->scrollToBottom();
|
|
|
|
}
|