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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
/***************************************************************************
* Copyright (C) 2004 by Hugo Parente Lima *
* [email protected] *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "configure.h"
#include "knetstats.h"
// TQt includes
#include <tqstringlist.h>
#include <tqlistbox.h>
#include <tqcheckbox.h>
#include <tqlabel.h>
#include <tqwidgetstack.h>
#include <tqpopupmenu.h>
// Kde includes
#include <tdeapplication.h>
#include <tdelocale.h>
#include <kiconloader.h>
#include <tdeconfig.h>
#include <tdefontrequester.h>
#include <knuminput.h>
#include <kcolorbutton.h>
#include <kcombobox.h>
#include <tdemessagebox.h>
#include <kpushbutton.h>
Configure::Configure(KNetStats* parent, const InterfaceMap& ifs) : ConfigureBase(parent) {
// Load configuration
TDEIconLoader* loader = kapp->iconLoader();
TQPixmap iconPCI = loader->loadIcon("icon_pci.png", TDEIcon::Small, 16);
// Clone the configuration.
for (InterfaceMap::ConstIterator it = ifs.begin(); it != ifs.end(); ++it) {
mInterfaces->insertItem(iconPCI, it.key());
mConfig[it.key()] = it.data()->options();
// parent->readInterfaceOptions(*it, &mConfig[*it]);
}
mInterfaces->setCurrentItem(0);
changeInterface(mInterfaces->selectedItem());
connect(mInterfaces, TQT_SIGNAL(selectionChanged(TQListBoxItem*)), this, TQT_SLOT(changeInterface(TQListBoxItem*)));
connect(mTheme, TQT_SIGNAL(activated(int)), this, TQT_SLOT(changeTheme(int)));
//connect(mInterfaces, TQT_SIGNAL(contextMenuRequested(TQListBoxItem*, const TQPoint&)), this, TQT_SLOT(showInterfaceContextMenu(TQListBoxItem*, const TQPoint&)));
}
void Configure::changeInterface(TQListBoxItem* item) {
TQString interface = item->text();
if (!mCurrentItem.isEmpty())
{
// Salvas as modificações passadas
KNetStatsView::Options& oldview = mConfig[mCurrentItem];
// general options
oldview.mMonitoring = mMonitoring->isChecked();
oldview.mUpdateInterval = mUpdateInterval->value();
oldview.mViewMode = (KNetStatsView::Mode) mViewMode->currentItem();
// txt view options
oldview.mTxtUplColor = mTxtUplColor->color();
oldview.mTxtDldColor = mTxtDldColor->color();
oldview.mTxtFont = mTxtFont->font();
// icon view
oldview.mTheme = mTheme->currentItem();
// chart view
oldview.mChartUplColor = mChartUplColor->color();
oldview.mChartDldColor = mChartDldColor->color();
oldview.mChartBgColor = mChartBgColor->color();
oldview.mChartTransparentBackground = mChartTransparentBackground->isChecked();
}
if (interface == mCurrentItem)
return;
// Carrega as opt. da nova interface
KNetStatsView::Options& view = mConfig[interface];
// general
mMonitoring->setChecked(view.mMonitoring);
mUpdateInterval->setValue(view.mUpdateInterval);
mViewMode->setCurrentItem(view.mViewMode);
mWdgStack->raiseWidget(view.mViewMode);
// txt options
mTxtUplColor->setColor(view.mTxtUplColor);
mTxtDldColor->setColor(view.mTxtDldColor);
mTxtFont->setFont( view.mTxtFont );
// icon options
mTheme->setCurrentItem(view.mTheme);
changeTheme(view.mTheme);
// chart options
mChartUplColor->setColor(view.mChartUplColor);
mChartDldColor->setColor(view.mChartDldColor);
mChartBgColor->setColor(view.mChartBgColor);
mChartTransparentBackground->setChecked(view.mChartTransparentBackground);
mCurrentItem = interface;
}
bool Configure::canSaveConfig()
{
// update the options
changeInterface(mInterfaces->item( mInterfaces->currentItem() ));
bool ok = false;
for(OptionsMap::ConstIterator i = mConfig.begin(); i != mConfig.end(); ++i)
if (i.data().mMonitoring) {
ok = true;
break;
}
if (!ok)
KMessageBox::error(this, i18n("You need to select at least one interface to monitor."));
return ok;
}
void Configure::changeTheme(int theme)
{
TDEIconLoader* loader = kapp->iconLoader();
mIconError->setPixmap(loader->loadIcon("theme"+TQString::number(theme)+"_error.png",
TDEIcon::Panel, ICONSIZE));
mIconNone->setPixmap(loader->loadIcon("theme"+TQString::number(theme)+"_none.png",
TDEIcon::Panel, ICONSIZE));
mIconTx->setPixmap(loader->loadIcon("theme"+TQString::number(theme)+"_tx.png",
TDEIcon::Panel, ICONSIZE));
mIconRx->setPixmap(loader->loadIcon("theme"+TQString::number(theme)+"_rx.png",
TDEIcon::Panel, ICONSIZE));
mIconBoth->setPixmap(loader->loadIcon("theme"+TQString::number(theme)+"_both.png",
TDEIcon::Panel, ICONSIZE));
}
/*
void Configure::showInterfaceContextMenu(TQListBoxItem* item, const TQPoint& point) {
if (!item && mConfig.size() == 1)
return;
TQPixmap icon = kapp->iconLoader()->loadIcon("edit-delete", TDEIcon::Small, 16);
TQPopupMenu* menu = new TQPopupMenu(this);
menu->insertItem(icon, i18n("Renomve Interface"), this, TQT_SLOT(removeInterface()));
menu->exec(point);
}
void Configure::removeInterface() {
mConfig.erase(mInterfaces->currentText());
mInterfaces->removeItem(mInterfaces->currentItem());
}
*/
#include "configure.moc"
|