Added WirelessManager, a port of wpa_supplicant.
[AROS.git] / workbench / network / WirelessManager / wpa_supplicant / wpa_gui-qt4 / eventhistory.cpp
blob1eb0b7b143869933f01c46ea116f9484bce52195
1 /*
2 * wpa_gui - EventHistory class
3 * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
10 * license.
12 * See README and COPYING for more details.
15 #include <QHeaderView>
16 #include <QScrollBar>
18 #include "eventhistory.h"
21 int EventListModel::rowCount(const QModelIndex &) const
23 return msgList.count();
27 int EventListModel::columnCount(const QModelIndex &) const
29 return 2;
33 QVariant EventListModel::data(const QModelIndex &index, int role) const
35 if (!index.isValid())
36 return QVariant();
38 if (role == Qt::DisplayRole)
39 if (index.column() == 0) {
40 if (index.row() >= timeList.size())
41 return QVariant();
42 return timeList.at(index.row());
43 } else {
44 if (index.row() >= msgList.size())
45 return QVariant();
46 return msgList.at(index.row());
48 else
49 return QVariant();
53 QVariant EventListModel::headerData(int section, Qt::Orientation orientation,
54 int role) const
56 if (role != Qt::DisplayRole)
57 return QVariant();
59 if (orientation == Qt::Horizontal) {
60 switch (section) {
61 case 0:
62 return QString(tr("Timestamp"));
63 case 1:
64 return QString(tr("Message"));
65 default:
66 return QVariant();
68 } else
69 return QString("%1").arg(section);
73 void EventListModel::addEvent(QString time, QString msg)
75 beginInsertRows(QModelIndex(), msgList.size(), msgList.size() + 1);
76 timeList << time;
77 msgList << msg;
78 endInsertRows();
82 EventHistory::EventHistory(QWidget *parent, const char *, bool, Qt::WFlags)
83 : QDialog(parent)
85 setupUi(this);
87 connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
89 eventListView->setItemsExpandable(FALSE);
90 eventListView->setRootIsDecorated(FALSE);
91 elm = new EventListModel(parent);
92 eventListView->setModel(elm);
96 EventHistory::~EventHistory()
98 destroy();
99 delete elm;
103 void EventHistory::languageChange()
105 retranslateUi(this);
109 void EventHistory::addEvents(WpaMsgList msgs)
111 WpaMsgList::iterator it;
112 for (it = msgs.begin(); it != msgs.end(); it++)
113 addEvent(*it);
117 void EventHistory::addEvent(WpaMsg msg)
119 bool scroll = true;
121 if (eventListView->verticalScrollBar()->value() <
122 eventListView->verticalScrollBar()->maximum())
123 scroll = false;
125 elm->addEvent(msg.getTimestamp().toString("yyyy-MM-dd hh:mm:ss.zzz"),
126 msg.getMsg());
128 if (scroll)
129 eventListView->scrollToBottom();