• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • kdeutils
  • Sitemap
  • Contact Us
 

kmilo

main.cpp

Go to the documentation of this file.
00001 /*
00002  *  main.cpp
00003  *
00004  *  Copyright (C) 2003 Mirko Boehm (mirko@kde.org)
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019  *
00020  */
00021 
00022 #include <QLabel>
00023 #include <QLayout>
00024 #include <QCheckBox>
00025 #include <QTimer>
00026 #include <qslider.h>
00027 //Added by qt3to4:
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         // mKVaioGeneral->frameMain->setEnabled (true);
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 

kmilo

Skip menu "kmilo"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdeutils

Skip menu "kdeutils"
  • ark
  • kcalc
  • kcharselect
  • kdelirc
  • kdessh
  • kdf
  • kfloppy
  • kgpg
  • kjots
  • klaptopdaemon
  • kmilo
  • ksim
  • ktimer
  • kwallet
  • superkaramba
Generated for kdeutils by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal