summaryrefslogtreecommitdiffstats
path: root/kmilo/kmilo_kvaio/kcmkvaio/main.cpp
blob: 0624c1ec10136811e927685d5809bb73680eb61d (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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
 *  main.cpp
 *
 *  Copyright (C) 2003 Mirko Boehm (mirko@kde.org)
 *
 *  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 <tqlabel.h>
#include <tqlayout.h>
#include <tqcheckbox.h>
#include <tqtimer.h>
#include <tqslider.h>

#include <dcopclient.h>
#include <kgenericfactory.h>
#include <kaboutdata.h>
#include <kdebug.h>
#include <kconfig.h>
#include <kled.h>
#include <kprogress.h>

#include "kcmkvaio_general.h"

#include <dcopclient.h>

#include "main.h"
#include "main.moc"

typedef KGenericFactory<KVaioModule, TQWidget> KVaioModuleFactory;
K_EXPORT_COMPONENT_FACTORY( kcm_kvaio, KVaioModuleFactory("kcmkvaio"))

#define CONFIG_FILE "kmilodrc"


KVaioModule::KVaioModule(TQWidget *parent, const char *name, const TQStringList &)
    : KCModule(KVaioModuleFactory::instance(), parent, name)
{
    KAboutData *about =
        new KAboutData(I18N_NOOP("kcmkvaio"),
                       I18N_NOOP("KDE Control Module for Sony "
                                 "Vaio Laptop Hardware"),
                       0, 0, KAboutData::License_GPL,
                       "(c) 2003 Mirko Boehm");

    about->addAuthor("Mirko Boehm",
                     I18N_NOOP("Original author"),
                     "mirko@kde.org");
    setAboutData( about );

    TQVBoxLayout *tqlayout = new TQVBoxLayout(this);
    mKVaioGeneral = new KCMKVaioGeneral(this);
    tqlayout->addWidget( mKVaioGeneral );
    tqlayout->addStretch();

    mDriver = new KVaioDriverInterface(TQT_TQOBJECT(this));
    mDriverAvailable = mDriver->connectToDriver(false);
    mTimer = new TQTimer(this);
    mTimer->start(231);

    load();
    if (! mDriverAvailable)
    {
        mKVaioGeneral->tlOff->show();
        mKVaioGeneral->frameMain->setEnabled(false);
        setButtons(buttons() & ~Default);
    } else {
        mKVaioGeneral->tlOff->hide();
        // mKVaioGeneral->frameMain->setEnabled (true);
    }

    connect(mKVaioGeneral, TQT_SIGNAL(changed()),
            TQT_SLOT(changed()));
    connect(mTimer, TQT_SIGNAL(timeout()), TQT_SLOT(timeout()));
    connect(mDriver, TQT_SIGNAL (vaioEvent(int)), TQT_SLOT (vaioEvent(int) ) );
}

void KVaioModule::save()
{
    if (! mDriverAvailable) return;
    DCOPClient mClient;

    kdDebug() << "KVaioModule: saving." << endl;
    KConfig config(CONFIG_FILE);

    config.setGroup("KVaio");

    config.writeEntry("Report_Unknown_Events",
                      mKVaioGeneral->cbReportUnknownEvents->isChecked());
    config.writeEntry("PeriodicallyReportPowerStatus",
		      mKVaioGeneral->mCbPowerMsgs->isChecked() );
    config.writeEntry("PowerStatusOnBackButton",
		      mKVaioGeneral->mCbBackButtonMsg->isChecked() );
    config.sync();

    if(mClient.attach())
    {
        TQByteArray data, replyData;
        TQCString replyType;

        if (!mClient.call("kded", "kmilod", "reconfigure()",
                          data, replyType, replyData))
        {
            kdDebug() << "KVaio::showTextMsg: "
                      << "there was some error using DCOP." << endl;
        }
    } else {
        kdDebug() << "KVaioModule: cannot attach to DCOP server, "
                  << "no automatic config update." << endl;
    }
}

void KVaioModule::load()
{
	load( false );
}

void KVaioModule::load(bool useDefaults)
{
    kdDebug() << "KVaioModule: loading." << endl;
    KConfig config(CONFIG_FILE);

	 config.setReadDefaults( useDefaults );

    config.setGroup("KVaio");
    mKVaioGeneral->cbReportUnknownEvents->setChecked
        (config.readBoolEntry("Report_Unknown_Events", false));
    mKVaioGeneral->mCbPowerMsgs->setChecked
	(config.readBoolEntry("PeriodicallyReportPowerStatus", false) );
    mKVaioGeneral->mCbBackButtonMsg->setChecked
	(config.readBoolEntry("PowerStatusOnBackButton", true) );

	 emit changed( useDefaults );
}

void KVaioModule::defaults()
{
	load( true );
}

void KVaioModule::timeout()
{
    bool bat1Avail = false, bat2Avail = false, acConnected = false;
    int bat1Remaining = 0, bat1Max = 0, bat2Remaining = 0, bat2Max = 0;

    if(mDriver->getBatterytqStatus(bat1Avail, bat1Remaining, bat1Max,
                                 bat2Avail, bat2Remaining, bat2Max,
                                 acConnected) )
    {
    }
    int remaining = (int)(100.0*(bat1Remaining+bat2Remaining)
                          / (bat1Max+bat2Max));
    mKVaioGeneral->mKPBattery->setValue(remaining);
    mKVaioGeneral->kledBat1->setState(bat1Avail ? KLed::On : KLed::Off);
    mKVaioGeneral->kledBat2->setState(bat2Avail ? KLed::On : KLed::Off);
    mKVaioGeneral->kledAC->setState(acConnected ? KLed::On : KLed::Off);
}

void KVaioModule::vaioEvent (int e)
{
    kdDebug () << "KVaioModule::vaioEvent: event: " << e << endl;
}