KNemo – network interfaces monitor for systray
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1200 lines
45 KiB

  1. /* This file is part of KNemo
  2. Copyright (C) 2004, 2006 Percy Leonhardt <percy@eris23.de>
  3. KNemo is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU Library General Public License as
  5. published by the Free Software Foundation; either version 2 of
  6. the License, or (at your option) any later version.
  7. KNemo is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this library; see the file COPYING.LIB. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. Boston, MA 02110-1301, USA.
  15. */
  16. #include <tqfile.h>
  17. #include <tqdict.h>
  18. #include <tqlabel.h>
  19. #include <tqlayout.h>
  20. #include <tqcstring.h>
  21. #include <tqlistbox.h>
  22. #include <tqcheckbox.h>
  23. #include <tqlineedit.h>
  24. #include <tqcombobox.h>
  25. #include <tqgroupbox.h>
  26. #include <tqwhatsthis.h>
  27. #include <tqtabwidget.h>
  28. #include <tqpushbutton.h>
  29. #include <tqstringlist.h>
  30. #include <tqdatastream.h>
  31. #include <kglobal.h>
  32. #include <kconfig.h>
  33. #include <klocale.h>
  34. #include <knuminput.h>
  35. #include <dcopclient.h>
  36. #include <kiconloader.h>
  37. #include <kfiledialog.h>
  38. #include <kdesktopfile.h>
  39. #include <kcolorbutton.h>
  40. #include <kinputdialog.h>
  41. #include <kapplication.h>
  42. #include <knotifydialog.h>
  43. #include <kstandarddirs.h>
  44. #include <kgenericfactory.h>
  45. #include <kdirselectdialog.h>
  46. #include "configdlg.h"
  47. #include "kcmregistry.h"
  48. #include "configdialog.h"
  49. const TQString ConfigDialog::ICON_DISCONNECTED = "network_disconnected";
  50. const TQString ConfigDialog::ICON_CONNECTED = "network_connected";
  51. const TQString ConfigDialog::ICON_INCOMING = "network_incoming";
  52. const TQString ConfigDialog::ICON_OUTGOING = "network_outgoing";
  53. const TQString ConfigDialog::ICON_TRAFFIC = "network_traffic";
  54. const TQString ConfigDialog::SUFFIX_PPP = "_ppp";
  55. const TQString ConfigDialog::SUFFIX_LAN = "_lan";
  56. const TQString ConfigDialog::SUFFIX_WLAN = "_wlan";
  57. typedef KGenericFactory<ConfigDialog, TQWidget> KNemoFactory;
  58. K_EXPORT_COMPONENT_FACTORY( kcm_knemo, KNemoFactory("kcm_knemo") )
  59. ConfigDialog::ConfigDialog( TQWidget *parent, const char *name, const TQStringList& )
  60. : KCModule( KNemoFactory::instance(), parent, name ),
  61. mLock( false ),
  62. mDlg( new ConfigDlg( this ) ),
  63. mColorVLines( 0x04FB1D ),
  64. mColorHLines( 0x04FB1D ),
  65. mColorIncoming( 0x1889FF ),
  66. mColorOutgoing( 0xFF7F08 ),
  67. mColorBackground( 0x313031 )
  68. {
  69. KGlobal::locale()->insertCatalogue("kcm_knemo");
  70. setupToolTipArray();
  71. // fill the backends combobox
  72. for ( int i = 0; KCMRegistry[i].name != TQString(); i++ )
  73. {
  74. mDlg->comboBoxBackends->insertItem( KCMRegistry[i].name );
  75. }
  76. load();
  77. TQVBoxLayout* top = new TQVBoxLayout(this);
  78. mDlg->pushButtonNew->setPixmap( SmallIcon( "filenew" ) );
  79. mDlg->pushButtonDelete->setPixmap( SmallIcon( "editdelete" ) );
  80. mDlg->pushButtonAddCommand->setPixmap( SmallIcon( "filenew" ) );
  81. mDlg->pushButtonRemoveCommand->setPixmap( SmallIcon( "editdelete" ) );
  82. mDlg->pushButtonUp->setPixmap( SmallIcon( "1uparrow" ) );
  83. mDlg->pushButtonDown->setPixmap( SmallIcon( "1downarrow" ) );
  84. mDlg->pushButtonAddToolTip->setPixmap( SmallIcon( "1rightarrow" ) );
  85. mDlg->pushButtonRemoveToolTip->setPixmap( SmallIcon( "1leftarrow" ) );
  86. mDlg->listViewCommands->setSorting( -1 );
  87. TQWhatsThis::add( mDlg->listViewCommands,
  88. i18n("<p>In this area you can add the custom entries " \
  89. "for your context menu: <ol><li>check <b>Display " \
  90. "custom entries in context menu</b>;</li>" \
  91. "<li>push on the <b>Add</b> button to add a new " \
  92. "entry in the list;</li><li>edit the entry by " \
  93. "double clicking in column <b>Menu text</b> and " \
  94. "<b>Command</b>;</li><li>start from step 2 for " \
  95. "every new entry</li>.</ol>If you need to execute " \
  96. "the command as root user check the corresponding " \
  97. "<b>Root</b> CheckBox.") );
  98. mSettingsDict.setAutoDelete( true );
  99. setButtons( KCModule::Default | KCModule::Apply );
  100. connect( mDlg->pushButtonNew, TQT_SIGNAL( clicked() ),
  101. this, TQT_SLOT( buttonNewSelected() ) );
  102. connect( mDlg->pushButtonDelete, TQT_SIGNAL( clicked() ),
  103. this, TQT_SLOT( buttonDeleteSelected() ) );
  104. connect( mDlg->pushButtonAddCommand, TQT_SIGNAL( clicked() ),
  105. this, TQT_SLOT( buttonAddCommandSelected() ) );
  106. connect( mDlg->pushButtonRemoveCommand, TQT_SIGNAL( clicked() ),
  107. this, TQT_SLOT( buttonRemoveCommandSelected() ) );
  108. connect( mDlg->pushButtonUp, TQT_SIGNAL( clicked() ),
  109. this, TQT_SLOT( buttonCommandUpSelected() ) );
  110. connect( mDlg->pushButtonDown, TQT_SIGNAL( clicked() ),
  111. this, TQT_SLOT( buttonCommandDownSelected() ) );
  112. connect( mDlg->pushButtonAddToolTip, TQT_SIGNAL( clicked() ),
  113. this, TQT_SLOT( buttonAddToolTipSelected() ) );
  114. connect( mDlg->pushButtonRemoveToolTip, TQT_SIGNAL( clicked() ),
  115. this, TQT_SLOT( buttonRemoveToolTipSelected() ) );
  116. connect( mDlg->pushButtonNotifications, TQT_SIGNAL( clicked() ),
  117. this, TQT_SLOT( buttonNotificationsSelected() ) );
  118. connect( mDlg->pushButtonStatisticsDir, TQT_SIGNAL( clicked() ),
  119. this, TQT_SLOT( buttonStatisticsDirSelected() ) );
  120. connect( mDlg->lineEditAlias, TQT_SIGNAL( textChanged( const TQString& ) ),
  121. this, TQT_SLOT( aliasChanged( const TQString& ) ) );
  122. connect( mDlg->comboBoxIconSet, TQT_SIGNAL( activated( int ) ),
  123. this, TQT_SLOT( iconSetChanged( int ) ) );
  124. connect( mDlg->comboBoxBackends, TQT_SIGNAL( activated( int ) ),
  125. this, TQT_SLOT( backendChanged( int ) ) );
  126. connect( mDlg->checkBoxNotConnected, TQT_SIGNAL( toggled( bool ) ),
  127. this, TQT_SLOT( checkBoxNotConnectedToggled ( bool ) ) );
  128. connect( mDlg->checkBoxNotExisting, TQT_SIGNAL( toggled( bool ) ),
  129. this, TQT_SLOT( checkBoxNotExistingToggled ( bool ) ) );
  130. connect( mDlg->checkBoxStatistics, TQT_SIGNAL( toggled( bool ) ),
  131. this, TQT_SLOT( checkBoxStatisticsToggled ( bool ) ) );
  132. connect( mDlg->checkBoxStartKNemo, TQT_SIGNAL( toggled( bool ) ),
  133. this, TQT_SLOT( checkBoxStartKNemoToggled( bool ) ) );
  134. connect( mDlg->spinBoxTrafficThreshold, TQT_SIGNAL( valueChanged( int ) ),
  135. this, TQT_SLOT( spinBoxTrafficValueChanged ( int ) ) );
  136. connect( mDlg->checkBoxCustom, TQT_SIGNAL( toggled( bool ) ),
  137. this, TQT_SLOT( checkBoxCustomToggled ( bool ) ) );
  138. connect( mDlg->listBoxInterfaces, TQT_SIGNAL( highlighted( const TQString& ) ),
  139. this, TQT_SLOT( interfaceSelected( const TQString& ) ) );
  140. connect( mDlg->listViewCommands, TQT_SIGNAL( selectionChanged() ),
  141. this, TQT_SLOT( listViewCommandsSelectionChanged() ) );
  142. connect( mDlg->listViewCommands, TQT_SIGNAL( itemRenamed( TQListViewItem*, int, const TQString& ) ),
  143. this, TQT_SLOT( listViewCommandsRenamed( TQListViewItem*, int, const TQString& ) ) );
  144. // connect the plotter widgets
  145. connect( mDlg->checkBoxTopBar, TQT_SIGNAL( toggled( bool ) ),
  146. this, TQT_SLOT( checkBoxToggled( bool ) ) );
  147. connect( mDlg->checkBoxLabels, TQT_SIGNAL( toggled( bool ) ),
  148. this, TQT_SLOT( checkBoxToggled( bool ) ) );
  149. connect( mDlg->checkBoxVLines, TQT_SIGNAL( toggled( bool ) ),
  150. this, TQT_SLOT( checkBoxToggled( bool ) ) );
  151. connect( mDlg->checkBoxHLines, TQT_SIGNAL( toggled( bool ) ),
  152. this, TQT_SLOT( checkBoxToggled( bool ) ) );
  153. connect( mDlg->checkBoxIncoming, TQT_SIGNAL( toggled( bool ) ),
  154. this, TQT_SLOT( checkBoxToggled( bool ) ) );
  155. connect( mDlg->checkBoxOutgoing, TQT_SIGNAL( toggled( bool ) ),
  156. this, TQT_SLOT( checkBoxToggled( bool ) ) );
  157. connect( mDlg->checkBoxVLinesScroll, TQT_SIGNAL( toggled( bool ) ),
  158. this, TQT_SLOT( checkBoxToggled( bool ) ) );
  159. connect( mDlg->checkBoxAutoDetection, TQT_SIGNAL( toggled( bool ) ),
  160. this, TQT_SLOT( checkBoxToggled( bool ) ) );
  161. connect( mDlg->spinBoxCount, TQT_SIGNAL( valueChanged( int ) ),
  162. this, TQT_SLOT( spinBoxValueChanged( int ) ) );
  163. connect( mDlg->spinBoxPixel, TQT_SIGNAL( valueChanged( int ) ),
  164. this, TQT_SLOT( spinBoxValueChanged( int ) ) );
  165. connect( mDlg->spinBoxDistance, TQT_SIGNAL( valueChanged( int ) ),
  166. this, TQT_SLOT( spinBoxValueChanged( int ) ) );
  167. connect( mDlg->spinBoxFontSize, TQT_SIGNAL( valueChanged( int ) ),
  168. this, TQT_SLOT( spinBoxValueChanged( int ) ) );
  169. connect( mDlg->spinBoxMinValue, TQT_SIGNAL( valueChanged( int ) ),
  170. this, TQT_SLOT( spinBoxValueChanged( int ) ) );
  171. connect( mDlg->spinBoxMaxValue, TQT_SIGNAL( valueChanged( int ) ),
  172. this, TQT_SLOT( spinBoxValueChanged( int ) ) );
  173. connect( mDlg->numInputPollInterval, TQT_SIGNAL( valueChanged( int ) ),
  174. this, TQT_SLOT( spinBoxValueChanged( int ) ) );
  175. connect( mDlg->numInputSaveInterval, TQT_SIGNAL( valueChanged( int ) ),
  176. this, TQT_SLOT( spinBoxValueChanged( int ) ) );
  177. connect( mDlg->kColorButtonVLines, TQT_SIGNAL( changed( const TQColor& ) ),
  178. this, TQT_SLOT( kColorButtonChanged( const TQColor& ) ) );
  179. connect( mDlg->kColorButtonHLines, TQT_SIGNAL( changed( const TQColor& ) ),
  180. this, TQT_SLOT( kColorButtonChanged( const TQColor& ) ) );
  181. connect( mDlg->kColorButtonIncoming, TQT_SIGNAL( changed( const TQColor& ) ),
  182. this, TQT_SLOT( kColorButtonChanged( const TQColor& ) ) );
  183. connect( mDlg->kColorButtonOutgoing, TQT_SIGNAL( changed( const TQColor& ) ),
  184. this, TQT_SLOT( kColorButtonChanged( const TQColor& ) ) );
  185. connect( mDlg->kColorButtonBackground, TQT_SIGNAL( changed( const TQColor& ) ),
  186. this, TQT_SLOT( kColorButtonChanged( const TQColor& ) ) );
  187. // No dcop call if KNemo is not activated by the user. Otherwise
  188. // load-on-demand will start KNemo.
  189. if ( mDlg->checkBoxStartKNemo->isChecked() )
  190. {
  191. // In case the user opened the control center via the context menu
  192. // this call to the daemon will deliver the interface the menu
  193. // belongs to. This way we can preselect the appropriate entry in the list.
  194. TQCString replyType;
  195. TQByteArray replyData, arg;
  196. TQString selectedInterface = TQString();
  197. if ( kapp->dcopClient()->call( "kded", "knemod", "getSelectedInterface()", arg, replyType, replyData ) )
  198. {
  199. TQDataStream reply( replyData, IO_ReadOnly );
  200. reply >> selectedInterface;
  201. }
  202. if ( selectedInterface != TQString() )
  203. {
  204. // Try to preselect the interface.
  205. unsigned int i;
  206. for ( i = 0; i < mDlg->listBoxInterfaces->count(); i++ )
  207. {
  208. TQListBoxItem* item = mDlg->listBoxInterfaces->item( i );
  209. if ( item->text() == selectedInterface )
  210. {
  211. // Found it.
  212. mDlg->listBoxInterfaces->setSelected( i, true );
  213. break;
  214. }
  215. }
  216. if ( i == mDlg->listBoxInterfaces->count() )
  217. // Not found. Select first entry in list.
  218. mDlg->listBoxInterfaces->setSelected( 0, true );
  219. }
  220. else
  221. // No interface from daemon. Select first entry in list.
  222. mDlg->listBoxInterfaces->setSelected( 0, true );
  223. }
  224. else
  225. {
  226. // Started from control center. Select first entry in list.
  227. mDlg->listBoxInterfaces->setSelected( 0, true );
  228. }
  229. top->add( mDlg );
  230. }
  231. ConfigDialog::~ConfigDialog()
  232. {
  233. delete mDlg;
  234. }
  235. void ConfigDialog::load()
  236. {
  237. mSettingsDict.clear();
  238. mDlg->listBoxInterfaces->clear();
  239. KConfig* config = new KConfig( "knemorc", true );
  240. config->setGroup( "General" );
  241. bool startKNemo = config->readBoolEntry( "StartKNemo", false );
  242. mDlg->checkBoxStartKNemo->setChecked( startKNemo );
  243. mDlg->tabWidgetConfiguration->setEnabled( startKNemo );
  244. mDlg->numInputPollInterval->setValue( config->readNumEntry( "PollInterval", 1 ) );
  245. mDlg->numInputSaveInterval->setValue( config->readNumEntry( "SaveInterval", 60 ) );
  246. mDlg->lineEditStatisticsDir->setText( config->readEntry( "StatisticsDir", KGlobal::dirs()->saveLocation( "data", "knemo/" ) ) );
  247. mToolTipContent = config->readNumEntry( "ToolTipContent", 2 );
  248. // select the backend from the config file
  249. bool foundBackend = false;
  250. TQString backend = config->readEntry( "Backend", "Nettools" );
  251. int i;
  252. for ( i = 0; KCMRegistry[i].name != TQString(); i++ )
  253. {
  254. if ( KCMRegistry[i].name == backend )
  255. {
  256. foundBackend = true;
  257. break;
  258. }
  259. }
  260. if ( !foundBackend )
  261. {
  262. i = 0; // use the first backend (Nettools)
  263. }
  264. mDlg->comboBoxBackends->setCurrentItem( i );
  265. mDlg->textLabelBackendDescription->setText( KCMRegistry[i].description );
  266. TQStrList list;
  267. int numEntries = config->readListEntry( "Interfaces", list );
  268. if ( numEntries == 0 )
  269. return;
  270. char* interface;
  271. for ( interface = list.first(); interface; interface = list.next() )
  272. {
  273. TQString group( "Interface_" );
  274. group += interface;
  275. InterfaceSettings* settings = new InterfaceSettings();
  276. if ( config->hasGroup( group ) )
  277. {
  278. config->setGroup( group );
  279. settings->alias = config->readEntry( "Alias" );
  280. settings->iconSet = config->readNumEntry( "IconSet", 0 );
  281. settings->customCommands = config->readBoolEntry( "CustomCommands" );
  282. settings->hideWhenNotAvailable = config->readBoolEntry( "HideWhenNotAvailable" );
  283. settings->hideWhenNotExisting = config->readBoolEntry( "HideWhenNotExisting" );
  284. settings->activateStatistics = config->readBoolEntry( "ActivateStatistics" );
  285. settings->trafficThreshold = config->readNumEntry( "TrafficThreshold", 0 );
  286. int numCommands = config->readNumEntry( "NumCommands" );
  287. for ( int i = 0; i < numCommands; i++ )
  288. {
  289. TQString entry;
  290. InterfaceCommand cmd;
  291. entry = TQString( "RunAsRoot%1" ).tqarg( i + 1 );
  292. cmd.runAsRoot = config->readBoolEntry( entry );
  293. entry = TQString( "Command%1" ).tqarg( i + 1 );
  294. cmd.command = config->readEntry( entry );
  295. entry = TQString( "MenuText%1" ).tqarg( i + 1 );
  296. cmd.menuText = config->readEntry( entry );
  297. settings->commands.append( cmd );
  298. }
  299. }
  300. mSettingsDict.insert( interface, settings );
  301. mDlg->listBoxInterfaces->insertItem( interface );
  302. }
  303. // enable or disable statistics entries
  304. updateStatisticsEntries();
  305. // Set the plotter widgets
  306. config->setGroup( "PlotterSettings" );
  307. mDlg->spinBoxPixel->setValue( config->readNumEntry( "Pixel", 1 ) );
  308. mDlg->spinBoxCount->setValue( config->readNumEntry( "Count", 5 ) );
  309. mDlg->spinBoxDistance->setValue( config->readNumEntry( "Distance", 30 ) );
  310. mDlg->spinBoxFontSize->setValue( config->readNumEntry( "FontSize", 8 ) );
  311. mDlg->spinBoxMinValue->setValue( config->readNumEntry( "MinimumValue", 0 ) );
  312. mDlg->spinBoxMaxValue->setValue( config->readNumEntry( "MaximumValue", 1 ) );
  313. mDlg->checkBoxLabels->setChecked( config->readBoolEntry( "Labels", true ) );
  314. mDlg->checkBoxTopBar->setChecked( config->readBoolEntry( "TopBar", false ) );
  315. mDlg->checkBoxVLines->setChecked( config->readBoolEntry( "VerticalLines", true ) );
  316. mDlg->checkBoxHLines->setChecked( config->readBoolEntry( "HorizontalLines", true ) );
  317. mDlg->checkBoxIncoming->setChecked( config->readBoolEntry( "ShowIncoming", true ) );
  318. mDlg->checkBoxOutgoing->setChecked( config->readBoolEntry( "ShowOutgoing", true ) );
  319. mDlg->checkBoxAutoDetection->setChecked( config->readBoolEntry( "AutomaticDetection", true ) );
  320. mDlg->checkBoxVLinesScroll->setChecked( config->readBoolEntry( "VerticalLinesScroll", true ) );
  321. mDlg->kColorButtonVLines->setColor( config->readColorEntry( "ColorVLines", &mColorVLines ) );
  322. mDlg->kColorButtonHLines->setColor( config->readColorEntry( "ColorHLines", &mColorHLines ) );
  323. mDlg->kColorButtonIncoming->setColor( config->readColorEntry( "ColorIncoming", &mColorIncoming ) );
  324. mDlg->kColorButtonOutgoing->setColor( config->readColorEntry( "ColorOutgoing", &mColorOutgoing ) );
  325. mDlg->kColorButtonBackground->setColor( config->readColorEntry( "ColorBackground", &mColorBackground ) );
  326. delete config;
  327. // These things need to be here so that 'Reset' from the control
  328. // center is handled correctly.
  329. setupToolTipTab();
  330. }
  331. void ConfigDialog::save()
  332. {
  333. KConfig* config = new KConfig( "knemorc", false );
  334. TQStringList list;
  335. TQDictIterator<InterfaceSettings> it( mSettingsDict );
  336. for ( ; it.current(); ++it )
  337. {
  338. list.append( it.currentKey() );
  339. InterfaceSettings* settings = it.current();
  340. config->setGroup( "Interface_" + it.currentKey() );
  341. if ( settings->alias.isEmpty() )
  342. config->deleteEntry( "Alias" );
  343. else
  344. config->writeEntry( "Alias", settings->alias );
  345. config->writeEntry( "IconSet", settings->iconSet );
  346. config->writeEntry( "CustomCommands", settings->customCommands );
  347. config->writeEntry( "HideWhenNotAvailable", settings->hideWhenNotAvailable );
  348. config->writeEntry( "HideWhenNotExisting", settings->hideWhenNotExisting );
  349. config->writeEntry( "ActivateStatistics", settings->activateStatistics );
  350. config->writeEntry( "TrafficThreshold", settings->trafficThreshold );
  351. config->writeEntry( "NumCommands", settings->commands.size() );
  352. for ( uint i = 0; i < settings->commands.size(); i++ )
  353. {
  354. TQString entry;
  355. entry = TQString( "RunAsRoot%1" ).tqarg( i + 1 );
  356. config->writeEntry( entry, settings->commands[i].runAsRoot );
  357. entry = TQString( "Command%1" ).tqarg( i + 1 );
  358. config->writeEntry( entry, settings->commands[i].command );
  359. entry = TQString( "MenuText%1" ).tqarg( i + 1 );
  360. config->writeEntry( entry, settings->commands[i].menuText );
  361. }
  362. }
  363. config->setGroup( "General" );
  364. config->writeEntry( "StartKNemo", mDlg->checkBoxStartKNemo->isChecked() );
  365. config->writeEntry( "PollInterval", mDlg->numInputPollInterval->value() );
  366. config->writeEntry( "SaveInterval", mDlg->numInputSaveInterval->value() );
  367. config->writeEntry( "StatisticsDir", mDlg->lineEditStatisticsDir->text() );
  368. config->writeEntry( "Backend", mDlg->comboBoxBackends->text( mDlg->comboBoxBackends->currentItem() ) );
  369. config->writeEntry( "ToolTipContent", mToolTipContent );
  370. config->writeEntry( "Interfaces", list );
  371. config->setGroup( "PlotterSettings" );
  372. config->writeEntry( "Pixel", mDlg->spinBoxPixel->value() );
  373. config->writeEntry( "Count", mDlg->spinBoxCount->value() );
  374. config->writeEntry( "Distance", mDlg->spinBoxDistance->value() );
  375. config->writeEntry( "FontSize", mDlg->spinBoxFontSize->value() );
  376. config->writeEntry( "MinimumValue", mDlg->spinBoxMinValue->value() );
  377. config->writeEntry( "MaximumValue", mDlg->spinBoxMaxValue->value() );
  378. config->writeEntry( "Labels", mDlg->checkBoxLabels->isChecked() );
  379. config->writeEntry( "TopBar", mDlg->checkBoxTopBar->isChecked() );
  380. config->writeEntry( "VerticalLines", mDlg->checkBoxVLines->isChecked() );
  381. config->writeEntry( "HorizontalLines", mDlg->checkBoxHLines->isChecked() );
  382. config->writeEntry( "ShowIncoming", mDlg->checkBoxIncoming->isChecked() );
  383. config->writeEntry( "ShowOutgoing", mDlg->checkBoxOutgoing->isChecked() );
  384. config->writeEntry( "AutomaticDetection", mDlg->checkBoxAutoDetection->isChecked() );
  385. config->writeEntry( "VerticalLinesScroll", mDlg->checkBoxVLinesScroll->isChecked() );
  386. config->writeEntry( "ColorVLines", mDlg->kColorButtonVLines->color() );
  387. config->writeEntry( "ColorHLines", mDlg->kColorButtonHLines->color() );
  388. config->writeEntry( "ColorIncoming", mDlg->kColorButtonIncoming->color() );
  389. config->writeEntry( "ColorOutgoing", mDlg->kColorButtonOutgoing->color() );
  390. config->writeEntry( "ColorBackground", mDlg->kColorButtonBackground->color() );
  391. config->sync();
  392. delete config;
  393. KDesktopFile* desktop = new KDesktopFile( "kded/knemod.desktop", false, "services" );
  394. if ( mDlg->checkBoxStartKNemo->isChecked() )
  395. {
  396. // This call will implicitly start KNemo if it is not yet running.
  397. kapp->dcopClient()->send( "kded", "knemod", "reparseConfiguration()", TQString("") );
  398. desktop->writeEntry( "X-KDE-Kded-autoload", true );
  399. }
  400. else
  401. {
  402. TQByteArray data;
  403. TQDataStream arg(data, IO_WriteOnly);
  404. arg << "knemod";
  405. kapp->dcopClient()->send("kded", "kded", "unloadModule(TQCString)", data);
  406. desktop->deleteEntry( "X-KDE-Kded-autoload" );
  407. }
  408. desktop->sync();
  409. delete desktop;
  410. }
  411. void ConfigDialog::defaults()
  412. {
  413. // Default interfaces
  414. TQFile proc( "/proc/net/dev" );
  415. if ( proc.open( IO_ReadOnly ) )
  416. {
  417. mSettingsDict.clear();
  418. mDlg->listBoxInterfaces->clear();
  419. TQString file = proc.readAll();
  420. TQStringList content = TQStringList::split( "\n", file );
  421. if ( content.count() > 2 )
  422. {
  423. for ( unsigned int i = 2; i < content.count(); i++ )
  424. {
  425. TQString interface = content[i].simplifyWhiteSpace();
  426. interface = interface.left( interface.find( ':' ) );
  427. if ( interface == "lo" )
  428. continue;
  429. InterfaceSettings* settings = new InterfaceSettings();
  430. settings->customCommands = false;
  431. settings->hideWhenNotAvailable = false;
  432. settings->hideWhenNotExisting = false;
  433. settings->activateStatistics = false;
  434. mSettingsDict.insert( interface, settings );
  435. mDlg->listBoxInterfaces->insertItem( interface );
  436. }
  437. if ( mDlg->listBoxInterfaces->count() > 0 )
  438. {
  439. mDlg->listBoxInterfaces->setSelected( 0, true );
  440. }
  441. else
  442. {
  443. mDlg->lineEditAlias->setText( TQString() );
  444. mDlg->comboBoxIconSet->setCurrentItem( 0 );
  445. mDlg->checkBoxNotConnected->setChecked( false );
  446. mDlg->checkBoxNotExisting->setChecked( false );
  447. mDlg->checkBoxStatistics->setChecked( false );
  448. mDlg->checkBoxCustom->setChecked( false );
  449. }
  450. }
  451. proc.close();
  452. }
  453. // Default misc settings
  454. mDlg->numInputPollInterval->setValue( 1 );
  455. mDlg->numInputSaveInterval->setValue( 60 );
  456. mDlg->lineEditStatisticsDir->setText( KGlobal::dirs()->saveLocation( "data", "knemo/" ) );
  457. mDlg->comboBoxBackends->setCurrentItem( 0 );
  458. mDlg->textLabelBackendDescription->setText( KCMRegistry[0].description );
  459. // Default tool tips
  460. mToolTipContent = 2;
  461. setupToolTipTab();
  462. // Default plotter settings
  463. mDlg->spinBoxPixel->setValue( 1 );
  464. mDlg->spinBoxCount->setValue( 5 );
  465. mDlg->spinBoxDistance->setValue( 30 );
  466. mDlg->spinBoxFontSize->setValue( 8 );
  467. mDlg->spinBoxMinValue->setValue( 0 );
  468. mDlg->spinBoxMaxValue->setValue( 1 );
  469. mDlg->checkBoxLabels->setChecked( true );
  470. mDlg->checkBoxTopBar->setChecked( false );
  471. mDlg->checkBoxVLines->setChecked( true );
  472. mDlg->checkBoxHLines->setChecked( true );
  473. mDlg->checkBoxIncoming->setChecked( true );
  474. mDlg->checkBoxOutgoing->setChecked( true );
  475. mDlg->checkBoxAutoDetection->setChecked( true );
  476. mDlg->checkBoxVLinesScroll->setChecked( true );
  477. mDlg->kColorButtonVLines->setColor( mColorVLines );
  478. mDlg->kColorButtonHLines->setColor( mColorHLines );
  479. mDlg->kColorButtonIncoming->setColor( mColorIncoming );
  480. mDlg->kColorButtonOutgoing->setColor( mColorOutgoing );
  481. mDlg->kColorButtonBackground->setColor( mColorBackground );
  482. changed( true );
  483. }
  484. void ConfigDialog::buttonNewSelected()
  485. {
  486. bool ok = false;
  487. TQString ifname = KInputDialog::getText( i18n( "Add new interface" ),
  488. i18n( "Please enter the name of the interface to be monitored.\nIt should be something like 'eth1', 'wlan2' or 'ppp0'." ),
  489. TQString(),
  490. &ok );
  491. if ( ok )
  492. {
  493. mDlg->listBoxInterfaces->insertItem( ifname );
  494. mSettingsDict.insert( ifname, new InterfaceSettings() );
  495. mDlg->listBoxInterfaces->setSelected( mDlg->listBoxInterfaces->count() - 1, true );
  496. changed( true );
  497. }
  498. }
  499. void ConfigDialog::buttonDeleteSelected()
  500. {
  501. TQListBoxItem* selected = mDlg->listBoxInterfaces->selectedItem();
  502. if ( selected == 0 )
  503. return;
  504. // TODO: find a better way than blocking signals
  505. mSettingsDict.remove( selected->text() );
  506. mDlg->lineEditAlias->blockSignals( true );
  507. mDlg->lineEditAlias->setText( TQString() );
  508. mDlg->lineEditAlias->blockSignals( false );
  509. mDlg->comboBoxIconSet->blockSignals( true );
  510. mDlg->comboBoxIconSet->setCurrentItem( 0 );
  511. mDlg->comboBoxIconSet->blockSignals( false );
  512. mDlg->checkBoxNotConnected->blockSignals( true );
  513. mDlg->checkBoxNotConnected->setChecked( false );
  514. mDlg->checkBoxNotConnected->blockSignals( false );
  515. mDlg->checkBoxNotExisting->blockSignals( true );
  516. mDlg->checkBoxNotExisting->setChecked( false );
  517. mDlg->checkBoxNotExisting->blockSignals( false );
  518. mDlg->checkBoxStatistics->blockSignals( true );
  519. mDlg->checkBoxStatistics->setChecked( false );
  520. mDlg->checkBoxStatistics->blockSignals( false );
  521. mDlg->checkBoxCustom->blockSignals( true );
  522. mDlg->checkBoxCustom->setChecked( false );
  523. mDlg->checkBoxCustom->blockSignals( false );
  524. mDlg->listBoxInterfaces->removeItem( mDlg->listBoxInterfaces->index( selected ) );
  525. changed( true );
  526. }
  527. void ConfigDialog::buttonAddCommandSelected()
  528. {
  529. TQListBoxItem* selected = mDlg->listBoxInterfaces->selectedItem();
  530. if ( selected == 0 )
  531. return;
  532. KNemoCheckListItem* item = new KNemoCheckListItem( mDlg->listViewCommands );
  533. item->setRenameEnabled( 1, true );
  534. item->setRenameEnabled( 2, true );
  535. connect( item, TQT_SIGNAL( stateChanged( KNemoCheckListItem*, bool ) ),
  536. this, TQT_SLOT( listViewCommandsCheckListItemChanged( KNemoCheckListItem*, bool ) ) );
  537. InterfaceSettings* settings = mSettingsDict[selected->text()];
  538. TQValueVector<InterfaceCommand> cmds;
  539. TQListViewItem* i = mDlg->listViewCommands->firstChild();
  540. for ( ; i != 0; i = i->nextSibling() )
  541. {
  542. InterfaceCommand cmd;
  543. cmd.runAsRoot = static_cast<KNemoCheckListItem*>( i )->isOn();
  544. cmd.menuText = i->text( 1 );
  545. cmd.command = i->text( 2 );
  546. cmds.append( cmd );
  547. }
  548. settings->commands = cmds;
  549. if (!mLock) changed( true );
  550. }
  551. void ConfigDialog::buttonRemoveCommandSelected()
  552. {
  553. TQListBoxItem* selected = mDlg->listBoxInterfaces->selectedItem();
  554. if ( selected == 0 )
  555. return;
  556. delete mDlg->listViewCommands->selectedItem();
  557. InterfaceSettings* settings = mSettingsDict[selected->text()];
  558. TQValueVector<InterfaceCommand> cmds;
  559. TQListViewItem* i = mDlg->listViewCommands->firstChild();
  560. for ( ; i != 0; i = i->nextSibling() )
  561. {
  562. InterfaceCommand cmd;
  563. cmd.runAsRoot = static_cast<KNemoCheckListItem*>( i )->isOn();
  564. cmd.menuText = i->text( 1 );
  565. cmd.command = i->text( 2 );
  566. cmds.append( cmd );
  567. }
  568. settings->commands = cmds;
  569. if (!mLock) changed( true );
  570. }
  571. void ConfigDialog::buttonCommandUpSelected()
  572. {
  573. TQListBoxItem* selected = mDlg->listBoxInterfaces->selectedItem();
  574. if ( selected == 0 )
  575. return;
  576. TQListViewItem* item = mDlg->listViewCommands->selectedItem();
  577. if ( item )
  578. {
  579. TQListViewItem* previous = item->itemAbove();
  580. if ( previous )
  581. {
  582. // We can move one up.
  583. previous = previous->itemAbove();
  584. if ( previous )
  585. item->moveItem( previous );
  586. else
  587. {
  588. mDlg->listViewCommands->takeItem( item );
  589. mDlg->listViewCommands->insertItem( item );
  590. mDlg->listViewCommands->setSelected( item, true );
  591. }
  592. }
  593. }
  594. InterfaceSettings* settings = mSettingsDict[selected->text()];
  595. TQValueVector<InterfaceCommand> cmds;
  596. TQListViewItem* i = mDlg->listViewCommands->firstChild();
  597. for ( ; i != 0; i = i->nextSibling() )
  598. {
  599. InterfaceCommand cmd;
  600. cmd.runAsRoot = static_cast<KNemoCheckListItem*>( i )->isOn();
  601. cmd.menuText = i->text( 1 );
  602. cmd.command = i->text( 2 );
  603. cmds.append( cmd );
  604. }
  605. settings->commands = cmds;
  606. if (!mLock) changed( true );
  607. }
  608. void ConfigDialog::buttonCommandDownSelected()
  609. {
  610. TQListBoxItem* selected = mDlg->listBoxInterfaces->selectedItem();
  611. if ( selected == 0 )
  612. return;
  613. TQListViewItem* item = mDlg->listViewCommands->selectedItem();
  614. if ( item )
  615. {
  616. TQListViewItem* next = item->itemBelow();
  617. if ( next )
  618. {
  619. // We can move one down.
  620. item->moveItem( next );
  621. }
  622. }
  623. InterfaceSettings* settings = mSettingsDict[selected->text()];
  624. TQValueVector<InterfaceCommand> cmds;
  625. TQListViewItem* i = mDlg->listViewCommands->firstChild();
  626. for ( ; i != 0; i = i->nextSibling() )
  627. {
  628. InterfaceCommand cmd;
  629. cmd.runAsRoot = static_cast<KNemoCheckListItem*>( i )->isOn();
  630. cmd.menuText = i->text( 1 );
  631. cmd.command = i->text( 2 );
  632. cmds.append( cmd );
  633. }
  634. settings->commands = cmds;
  635. if (!mLock) changed( true );
  636. }
  637. void ConfigDialog::buttonAddToolTipSelected()
  638. {
  639. // Support extended selection
  640. for ( int k = mDlg->listBoxAvailable->count() - 1; k >= 0; k-- )
  641. {
  642. if ( !mDlg->listBoxAvailable->isSelected( k ) )
  643. continue;
  644. TQListBoxItem* selected = mDlg->listBoxAvailable->item( k );
  645. if ( selected == 0 )
  646. continue;
  647. // Find the index of the selected item in the tooltip array.
  648. int itemIndex = 0;
  649. for ( int i = 0; mToolTips[i].first != TQString(); i++ )
  650. {
  651. if ( mToolTips[i].first == selected->text() )
  652. {
  653. itemIndex = i;
  654. break;
  655. }
  656. }
  657. // Find the first item in the display list which has a larger
  658. // index in the tooltip array. We have to insert the selected
  659. // item just before this one.
  660. int newIndex = -1;
  661. for ( unsigned int i = 0; i < mDlg->listBoxDisplay->count(); i++ )
  662. {
  663. // For every item in the display list find its index in
  664. // the tooltip array.
  665. int siblingIndex = 0;
  666. TQListBoxItem* item = mDlg->listBoxDisplay->item( i );
  667. for ( int j = 0; mToolTips[j].first != TQString(); j++ )
  668. {
  669. if ( mToolTips[j].first == item->text() )
  670. {
  671. siblingIndex = j;
  672. break;
  673. }
  674. }
  675. // Check if the index of this item is larger than the index
  676. // of the selected item.
  677. if ( siblingIndex > itemIndex )
  678. {
  679. // Insert the selected item at position newIndex placing it
  680. // directly in front of the sibling.
  681. newIndex = i;
  682. break;
  683. }
  684. }
  685. mDlg->listBoxAvailable->setSelected( selected, false );
  686. mDlg->listBoxAvailable->takeItem( selected );
  687. mDlg->listBoxDisplay->insertItem( selected, newIndex );
  688. if ( mDlg->listBoxAvailable->count() == 0 )
  689. mDlg->pushButtonAddToolTip->setEnabled( false );
  690. if ( mDlg->listBoxDisplay->count() == 1 )
  691. mDlg->pushButtonRemoveToolTip->setEnabled( true );
  692. mToolTipContent += mToolTips[itemIndex].second;
  693. changed( true );
  694. }
  695. }
  696. void ConfigDialog::buttonRemoveToolTipSelected()
  697. {
  698. // Support extended selection
  699. for ( int k = mDlg->listBoxDisplay->count() - 1; k >= 0; k-- )
  700. {
  701. if ( !mDlg->listBoxDisplay->isSelected( k ) )
  702. continue;
  703. TQListBoxItem* selected = mDlg->listBoxDisplay->item( k );
  704. if ( selected == 0 )
  705. continue;
  706. // Find the index of the selected item in the tooltip array.
  707. int itemIndex = 0;
  708. for ( int i = 0; mToolTips[i].first != TQString(); i++ )
  709. {
  710. if ( mToolTips[i].first == selected->text() )
  711. {
  712. itemIndex = i;
  713. break;
  714. }
  715. }
  716. // Find the first item in the available list which has a larger
  717. // index in the tooltip array. We have to insert the selected
  718. // item just before this one.
  719. int newIndex = -1;
  720. for ( unsigned int i = 0; i < mDlg->listBoxAvailable->count(); i++ )
  721. {
  722. // For every item in the available list find its index in
  723. // the tooltip array.
  724. int siblingIndex = 0;
  725. TQListBoxItem* item = mDlg->listBoxAvailable->item( i );
  726. for ( int j = 0; mToolTips[j].first != TQString(); j++ )
  727. {
  728. if ( mToolTips[j].first == item->text() )
  729. {
  730. siblingIndex = j;
  731. break;
  732. }
  733. }
  734. // Check if the index of this item is larger than the index
  735. // of the selected item.
  736. if ( siblingIndex > itemIndex )
  737. {
  738. // Insert the selected item at position newIndex placing it
  739. // directly in front of the sibling.
  740. newIndex = i;
  741. break;
  742. }
  743. }
  744. mDlg->listBoxDisplay->setSelected( selected, false );
  745. mDlg->listBoxDisplay->takeItem( selected );
  746. mDlg->listBoxAvailable->insertItem( selected, newIndex );
  747. if ( mDlg->listBoxDisplay->count() == 0 )
  748. mDlg->pushButtonRemoveToolTip->setEnabled( false );
  749. if ( mDlg->listBoxAvailable->count() == 1 )
  750. mDlg->pushButtonAddToolTip->setEnabled( true );
  751. mToolTipContent -= mToolTips[itemIndex].second;
  752. changed( true );
  753. }
  754. }
  755. void ConfigDialog::buttonNotificationsSelected()
  756. {
  757. KNotifyDialog dialog( this );
  758. dialog.addApplicationEvents( "knemo" );
  759. dialog.exec();
  760. }
  761. void ConfigDialog:: buttonStatisticsDirSelected()
  762. {
  763. KURL url = KDirSelectDialog::selectDirectory();
  764. if ( url.path() != TQString() )
  765. {
  766. mDlg->lineEditStatisticsDir->setText( url.path() );
  767. changed( true );
  768. }
  769. }
  770. void ConfigDialog::interfaceSelected( const TQString& interface )
  771. {
  772. InterfaceSettings* settings = mSettingsDict[interface];
  773. mLock = true;
  774. mDlg->lineEditAlias->setText( settings->alias );
  775. mDlg->comboBoxIconSet->setCurrentItem( settings->iconSet );
  776. mDlg->checkBoxCustom->setChecked( settings->customCommands );
  777. mDlg->checkBoxNotConnected->setChecked( settings->hideWhenNotAvailable );
  778. mDlg->checkBoxNotExisting->setChecked( settings->hideWhenNotExisting );
  779. mDlg->checkBoxStatistics->setChecked( settings->activateStatistics );
  780. mDlg->spinBoxTrafficThreshold->setValue( settings->trafficThreshold );
  781. mDlg->listViewCommands->clear();
  782. for ( int i = settings->commands.size() - 1; i >= 0; i-- )
  783. {
  784. KNemoCheckListItem* item = new KNemoCheckListItem( mDlg->listViewCommands );
  785. item->setOn( settings->commands[i].runAsRoot );
  786. item->setText( 1, settings->commands[i].menuText );
  787. item->setRenameEnabled( 1, true );
  788. item->setText( 2, settings->commands[i].command );
  789. item->setRenameEnabled( 2, true );
  790. connect( item, TQT_SIGNAL( stateChanged( KNemoCheckListItem*, bool ) ),
  791. this, TQT_SLOT( listViewCommandsCheckListItemChanged( KNemoCheckListItem*, bool ) ) );
  792. }
  793. iconSetChanged( settings->iconSet ); // to update iconset preview
  794. mLock = false;
  795. }
  796. void ConfigDialog::aliasChanged( const TQString& text )
  797. {
  798. TQListBoxItem* selected = mDlg->listBoxInterfaces->selectedItem();
  799. if ( selected == 0 )
  800. return;
  801. InterfaceSettings* settings = mSettingsDict[selected->text()];
  802. settings->alias = text;
  803. if (!mLock) changed( true );
  804. }
  805. void ConfigDialog::iconSetChanged( int set )
  806. {
  807. TQListBoxItem* selected = mDlg->listBoxInterfaces->selectedItem();
  808. if ( selected == 0 )
  809. return;
  810. InterfaceSettings* settings = mSettingsDict[selected->text()];
  811. settings->iconSet = set;
  812. // Update the preview of the iconset.
  813. TQString suffix;
  814. switch ( set )
  815. {
  816. case NETWORK:
  817. suffix = SUFFIX_LAN;
  818. break;
  819. case WIRELESS:
  820. suffix = SUFFIX_WLAN;
  821. break;
  822. case MODEM:
  823. suffix = SUFFIX_PPP;
  824. break;
  825. default:
  826. suffix = ""; // use standard icons
  827. }
  828. mDlg->pixmapDisconnected->setPixmap( SmallIcon( ICON_DISCONNECTED + suffix ) );
  829. mDlg->pixmapConnected->setPixmap( SmallIcon( ICON_CONNECTED + suffix ) );
  830. mDlg->pixmapIncoming->setPixmap( SmallIcon( ICON_INCOMING + suffix ) );
  831. mDlg->pixmapOutgoing->setPixmap( SmallIcon( ICON_OUTGOING + suffix ) );
  832. mDlg->pixmapTraffic->setPixmap( SmallIcon( ICON_TRAFFIC + suffix ) );
  833. if (!mLock) changed( true );
  834. }
  835. void ConfigDialog::backendChanged( int backend )
  836. {
  837. mDlg->textLabelBackendDescription->setText( KCMRegistry[backend].description );
  838. if (!mLock) changed( true );
  839. }
  840. void ConfigDialog::checkBoxNotConnectedToggled( bool on )
  841. {
  842. TQListBoxItem* selected = mDlg->listBoxInterfaces->selectedItem();
  843. if ( selected == 0 )
  844. return;
  845. InterfaceSettings* settings = mSettingsDict[selected->text()];
  846. settings->hideWhenNotAvailable = on;
  847. if (!mLock) changed( true );
  848. }
  849. void ConfigDialog::checkBoxNotExistingToggled( bool on )
  850. {
  851. TQListBoxItem* selected = mDlg->listBoxInterfaces->selectedItem();
  852. if ( selected == 0 )
  853. return;
  854. InterfaceSettings* settings = mSettingsDict[selected->text()];
  855. settings->hideWhenNotExisting = on;
  856. if (!mLock) changed( true );
  857. }
  858. void ConfigDialog::checkBoxStatisticsToggled( bool on )
  859. {
  860. TQListBoxItem* selected = mDlg->listBoxInterfaces->selectedItem();
  861. if ( selected == 0 )
  862. return;
  863. InterfaceSettings* settings = mSettingsDict[selected->text()];
  864. settings->activateStatistics = on;
  865. if (!mLock) changed( true );
  866. // enable or disable statistics entries
  867. updateStatisticsEntries();
  868. }
  869. void ConfigDialog::checkBoxStartKNemoToggled( bool on )
  870. {
  871. if ( on )
  872. {
  873. KConfig* config = new KConfig( "knemorc", false );
  874. config->setGroup( "General" );
  875. if ( config->readBoolEntry( "FirstStart", true ) )
  876. {
  877. config->writeEntry( "FirstStart", false );
  878. config->sync();
  879. delete config;
  880. // Populate the dialog with some default values if the user starts
  881. // KNemo for the very first time.
  882. defaults();
  883. }
  884. }
  885. if (!mLock) changed( true );
  886. }
  887. void ConfigDialog::spinBoxTrafficValueChanged( int value )
  888. {
  889. TQListBoxItem* selected = mDlg->listBoxInterfaces->selectedItem();
  890. if ( selected == 0 )
  891. return;
  892. InterfaceSettings* settings = mSettingsDict[selected->text()];
  893. settings->trafficThreshold = value;
  894. if (!mLock) changed( true );
  895. }
  896. void ConfigDialog::checkBoxCustomToggled( bool on )
  897. {
  898. TQListBoxItem* selected = mDlg->listBoxInterfaces->selectedItem();
  899. if ( selected == 0 )
  900. return;
  901. InterfaceSettings* settings = mSettingsDict[selected->text()];
  902. settings->customCommands = on;
  903. if ( on )
  904. if ( mDlg->listViewCommands->selectedItem() )
  905. mDlg->pushButtonRemoveCommand->setEnabled( true );
  906. else
  907. mDlg->pushButtonRemoveCommand->setEnabled( false );
  908. if (!mLock) changed( true );
  909. }
  910. void ConfigDialog::setupToolTipTab()
  911. {
  912. mDlg->listBoxDisplay->clear();
  913. mDlg->listBoxAvailable->clear();
  914. for ( int i = 0; mToolTips[i].first != TQString(); i++ )
  915. {
  916. if ( mToolTipContent & mToolTips[i].second )
  917. mDlg->listBoxDisplay->insertItem( mToolTips[i].first );
  918. else
  919. mDlg->listBoxAvailable->insertItem( mToolTips[i].first );
  920. }
  921. if ( mDlg->listBoxDisplay->count() > 0 )
  922. {
  923. mDlg->listBoxDisplay->setSelected( 0, true );
  924. mDlg->pushButtonRemoveToolTip->setEnabled( true );
  925. }
  926. else
  927. mDlg->pushButtonRemoveToolTip->setEnabled( false );
  928. if ( mDlg->listBoxAvailable->count() > 0 )
  929. {
  930. mDlg->listBoxAvailable->setSelected( 0, true );
  931. mDlg->pushButtonAddToolTip->setEnabled( true );
  932. }
  933. else
  934. mDlg->pushButtonAddToolTip->setEnabled( false );
  935. }
  936. void ConfigDialog::setupToolTipArray()
  937. {
  938. // Cannot make this data static as the i18n macro doesn't seem
  939. // to work when called to early i.e. before setting the catalogue.
  940. mToolTips[0] = TQPair<TQString, int>( i18n( "Interface" ), INTERFACE );
  941. mToolTips[1] = TQPair<TQString, int>( i18n( "Alias" ), ALIAS );
  942. mToolTips[2] = TQPair<TQString, int>( i18n( "Status" ), STATUS );
  943. mToolTips[3] = TQPair<TQString, int>( i18n( "Uptime" ), UPTIME );
  944. mToolTips[4] = TQPair<TQString, int>( i18n( "IP-Address" ), IP_ADDRESS );
  945. mToolTips[5] = TQPair<TQString, int>( i18n( "Subnet Mask" ), SUBNET_MASK );
  946. mToolTips[6] = TQPair<TQString, int>( i18n( "HW-Address" ), HW_ADDRESS );
  947. mToolTips[7] = TQPair<TQString, int>( i18n( "Broadcast Address" ), BCAST_ADDRESS );
  948. mToolTips[8] = TQPair<TQString, int>( i18n( "Default Gateway" ), GATEWAY );
  949. mToolTips[9] = TQPair<TQString, int>( i18n( "PtP-Address" ), PTP_ADDRESS );
  950. mToolTips[10] = TQPair<TQString, int>( i18n( "Packets Received" ), RX_PACKETS );
  951. mToolTips[11] = TQPair<TQString, int>( i18n( "Packets Sent" ), TX_PACKETS );
  952. mToolTips[12] = TQPair<TQString, int>( i18n( "Bytes Received" ), RX_BYTES );
  953. mToolTips[13] = TQPair<TQString, int>( i18n( "Bytes Sent" ), TX_BYTES );
  954. mToolTips[14] = TQPair<TQString, int>( i18n( "Download Speed" ), DOWNLOAD_SPEED );
  955. mToolTips[15] = TQPair<TQString, int>( i18n( "Upload Speed" ), UPLOAD_SPEED );
  956. mToolTips[16] = TQPair<TQString, int>( i18n( "ESSID" ), ESSID );
  957. mToolTips[17] = TQPair<TQString, int>( i18n( "Mode" ), MODE );
  958. mToolTips[18] = TQPair<TQString, int>( i18n( "Frequency" ), FREQUENCY );
  959. mToolTips[19] = TQPair<TQString, int>( i18n( "Bit Rate" ), BIT_RATE );
  960. mToolTips[20] = TQPair<TQString, int>( i18n( "Access Point" ), ACCESS_POINT );
  961. mToolTips[21] = TQPair<TQString, int>( i18n( "Link Quality" ), LINK_TQUALITY );
  962. mToolTips[22] = TQPair<TQString, int>( i18n( "Nickname" ), NICK_NAME );
  963. mToolTips[23] = TQPair<TQString, int>( i18n( "Encryption" ), ENCRYPTION );
  964. mToolTips[24] = TQPair<TQString, int>();
  965. }
  966. void ConfigDialog::updateStatisticsEntries( void )
  967. {
  968. bool statisticsActive = false;
  969. TQDictIterator<InterfaceSettings> it( mSettingsDict );
  970. for ( ; it.current(); ++it )
  971. {
  972. if ( it.current()->activateStatistics )
  973. {
  974. statisticsActive = true;
  975. break;
  976. }
  977. }
  978. mDlg->groupBoxStatistics->setEnabled( statisticsActive );
  979. mDlg->groupBoxUpdateInterval->setEnabled( statisticsActive );
  980. }
  981. void ConfigDialog::checkBoxToggled( bool )
  982. {
  983. changed( true );
  984. }
  985. void ConfigDialog::spinBoxValueChanged( int )
  986. {
  987. changed( true );
  988. }
  989. void ConfigDialog::kColorButtonChanged( const TQColor& )
  990. {
  991. changed( true );
  992. }
  993. void ConfigDialog::listViewCommandsSelectionChanged()
  994. {
  995. TQListViewItem* item = mDlg->listViewCommands->selectedItem();
  996. if ( item )
  997. mDlg->pushButtonRemoveCommand->setEnabled( true );
  998. else
  999. mDlg->pushButtonRemoveCommand->setEnabled( false );
  1000. }
  1001. void ConfigDialog::listViewCommandsCheckListItemChanged( KNemoCheckListItem* item, bool state )
  1002. {
  1003. TQListBoxItem* selected = mDlg->listBoxInterfaces->selectedItem();
  1004. if ( selected == 0 )
  1005. return;
  1006. // Find the row of the item.
  1007. int row = 0;
  1008. bool foundItem = false;
  1009. TQListViewItem* i = mDlg->listViewCommands->firstChild();
  1010. for ( ; i != 0; i = i->nextSibling() )
  1011. {
  1012. if ( i == item )
  1013. {
  1014. foundItem = true;
  1015. break;
  1016. }
  1017. row++;
  1018. }
  1019. if ( foundItem )
  1020. {
  1021. InterfaceSettings* settings = mSettingsDict[selected->text()];
  1022. InterfaceCommand& cmd = settings->commands[row];
  1023. cmd.runAsRoot = state;
  1024. if (!mLock) changed( true );
  1025. }
  1026. }
  1027. void ConfigDialog::listViewCommandsRenamed( TQListViewItem* item, int col, const TQString & text )
  1028. {
  1029. TQListBoxItem* selected = mDlg->listBoxInterfaces->selectedItem();
  1030. if ( selected == 0 )
  1031. return;
  1032. // Find the row of the item.
  1033. int row = 0;
  1034. bool foundItem = false;
  1035. TQListViewItem* i = mDlg->listViewCommands->firstChild();
  1036. for ( ; i != 0; i = i->nextSibling() )
  1037. {
  1038. if ( i == item )
  1039. {
  1040. foundItem = true;
  1041. break;
  1042. }
  1043. row++;
  1044. }
  1045. if ( foundItem )
  1046. {
  1047. InterfaceSettings* settings = mSettingsDict[selected->text()];
  1048. InterfaceCommand& cmd = settings->commands[row];
  1049. if ( col == 1 )
  1050. cmd.menuText = text;
  1051. else if ( col == 2 )
  1052. cmd.command = text;
  1053. if (!mLock) changed( true );
  1054. }
  1055. }
  1056. #include "configdialog.moc"