kmilo
main.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <QLabel>
00023 #include <QLayout>
00024 #include <QCheckBox>
00025 #include <QTimer>
00026 #include <qslider.h>
00027
00028 #include <QVBoxLayout>
00029 #include <QDBusInterface>
00030 #include <QDBusReply>
00031
00032 #include <kgenericfactory.h>
00033 #include <kaboutdata.h>
00034 #include <kdebug.h>
00035 #include <kconfig.h>
00036 #include <kconfiggroup.h>
00037 #include <kled.h>
00038
00039 #include "kcmkvaio_general.h"
00040
00041 #include "main.h"
00042 #include "main.moc"
00043
00044 typedef KGenericFactory<KVaioModule, QWidget> KVaioModuleFactory;
00045 K_EXPORT_COMPONENT_FACTORY( kcm_kvaio, KVaioModuleFactory("kcmkvaio"))
00046
00047 #define CONFIG_FILE "kmilodrc"
00048
00049
00050 KVaioModule::KVaioModule(QWidget *parent, const QStringList &)
00051 : KCModule(KVaioModuleFactory::componentData(), parent)
00052 {
00053 KAboutData *about =
00054 new KAboutData(I18N_NOOP("kcmkvaio"), 0,
00055 ki18n("KDE Control Module for Sony "
00056 "Vaio Laptop Hardware"),
00057 0, KLocalizedString(), KAboutData::License_GPL,
00058 ki18n("(c) 2003 Mirko Boehm"));
00059
00060 about->addAuthor(ki18n("Mirko Boehm"),
00061 ki18n("Original author"),
00062 "mirko@kde.org");
00063 setAboutData( about );
00064
00065 QVBoxLayout *layout = new QVBoxLayout(this);
00066 mKVaioGeneral = new KCMKVaioGeneral(this);
00067 layout->addWidget( mKVaioGeneral );
00068 layout->addStretch();
00069
00070 mDriver = new KVaioDriverInterface(this);
00071 mDriverAvailable = mDriver->connectToDriver(false);
00072 mTimer = new QTimer(this);
00073 mTimer->start(231);
00074
00075 load();
00076 if (! mDriverAvailable)
00077 {
00078 mKVaioGeneral->tlOff->show();
00079 mKVaioGeneral->frameMain->setEnabled(false);
00080 setButtons(buttons() & ~Default);
00081 } else {
00082 mKVaioGeneral->tlOff->hide();
00083
00084 }
00085
00086 connect(mKVaioGeneral, SIGNAL(changed()),
00087 SLOT(changed()));
00088 connect(mTimer, SIGNAL(timeout()), SLOT(timeout()));
00089 connect(mDriver, SIGNAL (vaioEvent(int)), SLOT (vaioEvent(int) ) );
00090 }
00091
00092 void KVaioModule::save()
00093 {
00094 if (! mDriverAvailable) return;
00095
00096 kDebug() << "KVaioModule: saving." ;
00097 KConfig config(CONFIG_FILE);
00098
00099 KConfigGroup cg(&config, "KVaio");
00100
00101 cg.writeEntry("Report_Unknown_Events",
00102 mKVaioGeneral->cbReportUnknownEvents->isChecked());
00103 cg.writeEntry("PeriodicallyReportPowerStatus",
00104 mKVaioGeneral->mCbPowerMsgs->isChecked() );
00105 cg.writeEntry("PowerStatusOnBackButton",
00106 mKVaioGeneral->mCbBackButtonMsg->isChecked() );
00107 config.sync();
00108
00109 QDBusInterface kmilod("org.kde.kded", "/modules/kmilod", "org.kde.kmilod");
00110 QDBusReply<void> reply = kmilod.call("reconfigure");
00111 if( !reply.isValid() )
00112 kDebug() << "KVaio::showTextMsg: "
00113 << "there was an error using D-Bus on kmilod::reconfigure()." << endl;
00114 }
00115
00116 void KVaioModule::load()
00117 {
00118 kDebug() << "KVaioModule: loading." ;
00119 KConfig config(CONFIG_FILE);
00120
00121 KConfigGroup cg(&config, "KVaio");
00122 mKVaioGeneral->cbReportUnknownEvents->setChecked
00123 (cg.readEntry("Report_Unknown_Events", false));
00124 mKVaioGeneral->mCbPowerMsgs->setChecked
00125 (cg.readEntry("PeriodicallyReportPowerStatus", false) );
00126 mKVaioGeneral->mCbBackButtonMsg->setChecked
00127 (cg.readEntry("PowerStatusOnBackButton", true) );
00128 }
00129
00130 void KVaioModule::defaults()
00131 {
00132 mKVaioGeneral->cbReportUnknownEvents->setChecked( true );
00133 mKVaioGeneral->mCbPowerMsgs->setChecked( true );
00134 mKVaioGeneral->mCbBackButtonMsg->setChecked( true );
00135
00136 }
00137
00138 void KVaioModule::timeout()
00139 {
00140 bool bat1Avail = false, bat2Avail = false, acConnected = false;
00141 int bat1Remaining = 0, bat1Max = 0, bat2Remaining = 0, bat2Max = 0;
00142
00143 if(mDriver->getBatteryStatus(bat1Avail, bat1Remaining, bat1Max,
00144 bat2Avail, bat2Remaining, bat2Max,
00145 acConnected) )
00146 {
00147 }
00148 int remaining = (int)(100.0*(bat1Remaining+bat2Remaining)
00149 / (bat1Max+bat2Max));
00150 mKVaioGeneral->mKPBattery->setProgress(remaining);
00151 mKVaioGeneral->kledBat1->setState(bat1Avail ? KLed::On : KLed::Off);
00152 mKVaioGeneral->kledBat2->setState(bat2Avail ? KLed::On : KLed::Off);
00153 mKVaioGeneral->kledAC->setState(acConnected ? KLed::On : KLed::Off);
00154 }
00155
00156 void KVaioModule::vaioEvent (int e)
00157 {
00158 kDebug () << "KVaioModule::vaioEvent: event: " << e ;
00159 }
00160