eventhistory.cpp
Go to the documentation of this file.
00001 /*
00002  * wpa_gui - EventHistory class
00003  * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 2 as
00007  * published by the Free Software Foundation.
00008  *
00009  * Alternatively, this software may be distributed under the terms of BSD
00010  * license.
00011  *
00012  * See README and COPYING for more details.
00013  */
00014 
00015 #include <QHeaderView>
00016 #include <QScrollBar>
00017 
00018 #include "eventhistory.h"
00019 
00020 
00021 int EventListModel::rowCount(const QModelIndex &) const
00022 {
00023         return msgList.count();
00024 }
00025 
00026 
00027 int EventListModel::columnCount(const QModelIndex &) const
00028 {
00029         return 2;
00030 }
00031 
00032 
00033 QVariant EventListModel::data(const QModelIndex &index, int role) const
00034 {
00035         if (!index.isValid())
00036                 return QVariant();
00037 
00038         if (role == Qt::DisplayRole)
00039                 if (index.column() == 0) {
00040                         if (index.row() >= timeList.size())
00041                                 return QVariant();
00042                         return timeList.at(index.row());
00043                 } else {
00044                         if (index.row() >= msgList.size())
00045                                 return QVariant();
00046                         return msgList.at(index.row());
00047                 }
00048         else
00049                 return QVariant();
00050 }
00051 
00052 
00053 QVariant EventListModel::headerData(int section, Qt::Orientation orientation,
00054                                     int role) const
00055 {
00056         if (role != Qt::DisplayRole)
00057                 return QVariant();
00058 
00059         if (orientation == Qt::Horizontal) {
00060                 switch (section) {
00061                 case 0:
00062                         return QString(tr("Timestamp"));
00063                 case 1:
00064                         return QString(tr("Message"));
00065                 default:
00066                         return QVariant();
00067                 }
00068         } else
00069                 return QString("%1").arg(section);
00070 }
00071 
00072 
00073 void EventListModel::addEvent(QString time, QString msg)
00074 {
00075         beginInsertRows(QModelIndex(), msgList.size(), msgList.size() + 1);
00076         timeList << time;
00077         msgList << msg;
00078         endInsertRows();
00079 }
00080 
00081 
00082 EventHistory::EventHistory(QWidget *parent, const char *, bool, Qt::WFlags)
00083         : QDialog(parent)
00084 {
00085         setupUi(this);
00086 
00087         connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
00088 
00089         eventListView->setItemsExpandable(FALSE);
00090         eventListView->setRootIsDecorated(FALSE);
00091         elm = new EventListModel(parent);
00092         eventListView->setModel(elm);
00093 }
00094 
00095 
00096 EventHistory::~EventHistory()
00097 {
00098         destroy();
00099         delete elm;
00100 }
00101 
00102 
00103 void EventHistory::languageChange()
00104 {
00105         retranslateUi(this);
00106 }
00107 
00108 
00109 void EventHistory::addEvents(WpaMsgList msgs)
00110 {
00111         WpaMsgList::iterator it;
00112         for (it = msgs.begin(); it != msgs.end(); it++)
00113                 addEvent(*it);
00114 }
00115 
00116 
00117 void EventHistory::addEvent(WpaMsg msg)
00118 {
00119         bool scroll = true;
00120 
00121         if (eventListView->verticalScrollBar()->value() <
00122             eventListView->verticalScrollBar()->maximum())
00123                 scroll = false;
00124 
00125         elm->addEvent(msg.getTimestamp().toString("yyyy-MM-dd hh:mm:ss.zzz"),
00126                       msg.getMsg());
00127 
00128         if (scroll)
00129                 eventListView->scrollToBottom();
00130 }


wpa_supplicant_node
Author(s): Package maintained by Blaise Gassend
autogenerated on Thu Apr 24 2014 15:33:20