summaryrefslogtreecommitdiffstats
path: root/src/infopanels.cpp
blob: a5f41323ad5161a4e61519858ad988f8de1f0c44 (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
/***************************************************************************
                          infopanels.cpp  -  description
                             -------------------
    begin                : vie may 10 2002
    copyright            : (C) 2002 by Miguel Novas
    email                : michaell@teleline.es
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 "infopanels.h"



InfoPanels::InfoPanels(TQWidget *panelsWidget, TQObject *parent, const char *name): PanelsGroup(widget,parent,name)
{
 widget= panelsWidget;
 timerPanelCount=0;
 timer = new TQTimer(this);
 configChanged("proc.CPUINFO");
 configChanged("proc.RAMINFO");
 configChanged("proc.SWAPINFO");
 configChanged("proc.CPULOAD");
 configChanged("proc.UPTIME");
}

InfoPanels::~InfoPanels(){
}

void InfoPanels::configChanged(const char *name)
{
  if(!strcmp(name,"proc")) readUpdateInterval();
  else {
     Panel *panel= (Panel *)widget->child(name);
     if( Panel::readShow(name)!= (bool)panel ) {
       if(panel) delete panel;
       else {
          if(!strcmp(name,"proc.CPUINFO" )) panel= new CpuPanel(widget,name);
          else
          if(!strcmp(name,"proc.RAMINFO" )) panel= new RamPanel(widget,name,RamPanel::memRAM);
          else
          if(!strcmp(name,"proc.SWAPINFO")) panel= new RamPanel(widget,name,RamPanel::memSWAP);
          else
          if(!strcmp(name,"proc.CPULOAD" )) panel= new CpuTimePanel(widget,name);
          else
          if(!strcmp(name,"proc.UPTIME"  )) panel= new UpTimePanel(widget,name);
          if(panel) timerConnect(panel);
       }
     }
  }
}

void InfoPanels::timerConnect(Panel *display)
{
 if(timerPanelCount==0) timer->start( cfgReadUpdateInterval()*1000 );
 connect( timer  , SIGNAL(timeout()  ), display, SLOT(updateInfo()) );
 connect( display, SIGNAL(destroyed()), this   , SLOT(infoPanelDestroyed()) );
 timerPanelCount++;
}

void InfoPanels::infoPanelDestroyed()
{
 if(--timerPanelCount<=0) timer->stop();
}

void InfoPanels::cfgWriteUpdateInterval(int interval)
{
 TDEGlobal::config()->setGroup("ShowWidget");
 TDEGlobal::config()->writeEntry("UpdateInterval" , interval );
}

int InfoPanels::cfgReadUpdateInterval()
{
 TDEGlobal::config()->setGroup("ShowWidget");
 return TDEGlobal::config()->readNumEntry("UpdateInterval" , 5 );
}

void InfoPanels::readUpdateInterval()
{
 timer->changeInterval(cfgReadUpdateInterval()*1000);
}

// ******************* Public static methods **********************