aboutsummaryrefslogtreecommitdiffstats
path: root/wpa_supplicant/wpa_gui-qt4/eventhistory.cpp
blob: a36085d21a6ca86dc1c711e1b7a345ff3ebf1ada (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
 * wpa_gui - EventHistory class
 * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
 *
 * This software may be distributed under the terms of the BSD license.
 * See README for more details.
 */

#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:
			return QString(tr("Timestamp"));
		case 1:
			return QString(tr("Message"));
		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();
}


EventHistory::EventHistory(QWidget *parent, const char *, bool, Qt::WFlags)
	: QDialog(parent)
{
	setupUi(this);

	connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));

	eventListView->setItemsExpandable(FALSE);
	eventListView->setRootIsDecorated(FALSE);
	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();
}