summaryrefslogtreecommitdiffstats
path: root/src/systemcfg.cpp
blob: 97c2480f336bf7f88ebbe8fda4d26c718762c58f (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
125
126
127
/***************************************************************************
                          systemcfg.cpp  -  description
                             -------------------
    begin                : vie may 17 2002
    copyright            : (C) 2002 by Miguel Novas
    email                : [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.                                   *
 *                                                                         *
 ***************************************************************************/

#include <ntqlistbox.h>
#include <ntqspinbox.h>
#include <ntqpushbutton.h>
#include <ntqgroupbox.h>
#include <ntqcheckbox.h>
#include <ntqlayout.h>
#include <ntqtabwidget.h>
#include <tdelocale.h>
#include "systemcfg.h"

#include "infopanels.h"


SystemCfg::SystemCfg(LMSensors *lsensors, TQWidget *parent, const char *name): SystemCfgDesign(parent,name)
{
 sensors= lsensors;

 palPanelCfg= new PaletteCfg( boxPanelPalette );
 boxPanelPalette->setColumnLayout(0, TQt::Vertical );
 boxPanelPalette->layout()->setSpacing( 6 );
 boxPanelPalette->layout()->setMargin( 12 );
 TQGridLayout *boxPanelPaletteLayout = new TQGridLayout( boxPanelPalette->layout() );
 boxPanelPaletteLayout->setAlignment( TQt::AlignTop );
 boxPanelPaletteLayout->addWidget( palPanelCfg, 0, 0 );

 connect( TabWidget  ,TQ_SIGNAL(currentChanged(TQWidget*)), this, TQ_SLOT(slotTabWidgetChanged(TQWidget *)));
 //connect( buttonApply ,TQ_SIGNAL(clicked()),this, TQ_SLOT(slotApplyChanges()));

 listSensors->clear();
 listSensors->insertItem( i18n("CPU Speed"));
 listSensors->insertItem( i18n("CPU State"));
 listSensors->insertItem( i18n("RAM Used"));
 listSensors->insertItem( i18n("SWAP Used"));
 listSensors->insertItem( i18n("Up Time"));
 listSensors->setCurrentItem(0);
 readSensorInfo(0);

 connect( listSensors,TQ_SIGNAL(highlighted(int)),this,TQ_SLOT(slotCurrentSensorChanged(int)) );
}

SystemCfg::~SystemCfg(){
}

void SystemCfg::slotTabWidgetChanged(TQWidget *)
{
   switch(TabWidget->currentPageIndex())
  {
    case 0: readSensorInfo(listSensors->currentItem());  break;
    case 1: readPreferencesInfo();                       break;
  }
}

const char *SystemCfg::getPanelName(int index)
{
 switch(index) {
   case 0:  return "proc.CPUINFO";
   case 1:  return "proc.CPULOAD";
   case 2:  return "proc.RAMINFO";
   case 3:  return "proc.SWAPINFO";
   case 4:  return "proc.UPTIME";
 }
 return 0;
}

void SystemCfg::slotCurrentSensorChanged(int index)
{
 readSensorInfo(index);
}

void SystemCfg::readSensorInfo(int index)
{
const char *panelName= getPanelName(index);

 checkShow->setChecked( Panel::readShow(panelName) );
 palPanelCfg->readPalette(panelName);
}

void SystemCfg::readPreferencesInfo()
{
 SpinUpdateTime->setValue(InfoPanels::cfgReadUpdateInterval());
}


void SystemCfg::writeSensorInfo(int index)
{
const char *panelName= getPanelName(index);

 Panel::writeShow(panelName,checkShow->isChecked());
 palPanelCfg->savePalette();
 sensors->emitConfigChanged(panelName);
}

void SystemCfg::writePreferencesInfo()
{
 InfoPanels::cfgWriteUpdateInterval(SpinUpdateTime->value());
 sensors->emitConfigChanged("proc");
}

void SystemCfg::slotApplyChanges()
{
  if (!isVisible())
	  return;
  switch(TabWidget->currentPageIndex())
  {
    case 0: writeSensorInfo(listSensors->currentItem()); break;
    case 1: writePreferencesInfo();          break;
  }
}

#include "systemcfg.moc"