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

kdelirc

kcmlirc.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2003 by Gav Wood                                        *
00003  *   gav@kde.org                                                 *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  ***************************************************************************/
00010 
00011 #include <QCheckBox>
00012 #include <QLabel>
00013 #include <QLayout>
00014 #include <QLineEdit>
00015 #include <qradiobutton.h>
00016 #include <QComboBox>
00017 #include <qevent.h>
00018 #include <q3listview.h>
00019 //Added by qt3to4:
00020 #include <QHBoxLayout>
00021 #include <QDropEvent>
00022 
00023 #include <kpushbutton.h>
00024 #include <kapplication.h>
00025 #include <klocale.h>
00026 #include <kglobal.h>
00027 #include <kconfig.h>
00028 #include <kicondialog.h>
00029 #include <kiconloader.h>
00030 #include <kdebug.h>
00031 #include <ksimpleconfig.h>
00032 #include <kgenericfactory.h>
00033 #include <k3listview.h>
00034 #include <kmessagebox.h>
00035 #include <kpushbutton.h>
00036 #include <ktoolinvocation.h>
00037 #include <dcopclient.h>
00038 #include <dcopref.h>
00039 
00040 #include <irkick_stub.h>
00041 
00042 #include "addaction.h"
00043 #include "newmodedialog.h"
00044 #include "profileserver.h"
00045 #include "remoteserver.h"
00046 #include "kcmlirc.h"
00047 #include "editaction.h"
00048 #include "editmode.h"
00049 #include "modeslist.h"
00050 #include "selectprofile.h"
00051 
00052 typedef KGenericFactory<KCMLirc, QWidget> theFactory;
00053 K_EXPORT_COMPONENT_FACTORY(kcmlirc, theFactory("kcmlirc"))
00054 
00055 KCMLirc::KCMLirc(QWidget *parent, const QStringList &/*args*/)
00056     : DCOPObject("KCMLirc"), KCModule(theFactory::componentData(),parent)
00057 {
00058     KGlobal::locale()->insertCatalog( "kcmlirc" );
00059     setAboutData(new KAboutData("kcmlirc", 0, ki18n("KDE Lirc"), VERSION, ki18n("The KDE IR Remote Control System"), KAboutData::License_GPL_V2, ki18n("Copyright (c)2003 Gav Wood"), ki18n("Use this to configure KDE's infrared remote control system in order to control any KDE application with your infrared remote control."), "http://www.kde.org"));
00060     setButtons(KCModule::Help);
00061     setQuickHelp(i18n("<h1>Remote Controls</h1><p>This module allows you to configure bindings between your remote controls and KDE applications. Simply select your remote control and click Add under the Actions/Buttons list. If you want KDE to attempt to automatically assign buttons to a supported application's actions, try clicking the Auto-Populate button.</p><p>To view the recognised applications and remote controls, simply select the <em>Loaded Extensions</em> tab.</p>"));
00062     bool ok;
00063     KApplication::kApplication()->dcopClient()->remoteInterfaces("irkick", "IRKick", &ok);
00064     if(!ok)
00065         if(KMessageBox::questionYesNo(this, i18n("The Infrared Remote Control software is not currently running. This configuration module will not work properly without it. Would you like to start it now?"), i18n("Software Not Running"), i18n("Start"), i18n("Do Not Start")) == KMessageBox::Yes)
00066         {   kDebug() << "S" << KToolInvocation::startServiceByDesktopName("irkick") ;
00067             KSimpleConfig theConfig("irkickrc");
00068             theConfig.setGroup("General");
00069             if(theConfig.readBoolEntry("AutoStart", true) == false)
00070                 if(KMessageBox::questionYesNo(this, i18n("Would you like the infrared remote control software to start automatically when you begin KDE?"), i18n("Automatically Start?"), i18n("Start Automatically"), i18n("Do Not Start")) == KMessageBox::Yes)
00071                     theConfig.writeEntry("AutoStart", true);
00072         }
00073 
00074     KApplication::kApplication()->dcopClient()->remoteInterfaces("irkick", "IRKick", &ok);
00075     kDebug() << "OK" << ok ;
00076 
00077 
00078     (new QHBoxLayout(this))->setAutoAdd(true);
00079     theKCMLircBase = new KCMLircBase(this);
00080     connect(theKCMLircBase->theModes, SIGNAL( selectionChanged(Q3ListViewItem *) ), this, SLOT( updateActions() ));
00081     connect(theKCMLircBase->theModes, SIGNAL( selectionChanged(Q3ListViewItem *) ), this, SLOT( updateModesStatus(Q3ListViewItem *) ));
00082     connect(theKCMLircBase->theActions, SIGNAL( currentChanged(Q3ListViewItem *) ), this, SLOT( updateActionsStatus(Q3ListViewItem *) ));
00083     connect(theKCMLircBase->theExtensions, SIGNAL( selectionChanged(Q3ListViewItem *) ), this, SLOT( updateInformation() ));
00084     connect(theKCMLircBase->theModes, SIGNAL( itemRenamed(Q3ListViewItem *) ), this, SLOT( slotRenamed(Q3ListViewItem *) ));
00085     connect(theKCMLircBase->theModes, SIGNAL(dropped(K3ListView*, QDropEvent*, Q3ListViewItem*, Q3ListViewItem*)), this, SLOT(slotDrop(K3ListView*, QDropEvent*, Q3ListViewItem*, Q3ListViewItem*)));
00086     connect((QObject *)(theKCMLircBase->theAddActions), SIGNAL( clicked() ), this, SLOT( slotAddActions() ));
00087     connect((QObject *)(theKCMLircBase->theAddAction), SIGNAL( clicked() ), this, SLOT( slotAddAction() ));
00088     connect((QObject *)(theKCMLircBase->theEditAction), SIGNAL( clicked() ), this, SLOT( slotEditAction() ));
00089     connect((QObject *)(theKCMLircBase->theActions), SIGNAL( doubleClicked(Q3ListViewItem *) ), this, SLOT( slotEditAction() ));
00090     connect((QObject *)(theKCMLircBase->theRemoveAction), SIGNAL( clicked() ), this, SLOT( slotRemoveAction() ));
00091     connect((QObject *)(theKCMLircBase->theAddMode), SIGNAL( clicked() ), this, SLOT( slotAddMode() ));
00092     connect((QObject *)(theKCMLircBase->theEditMode), SIGNAL( clicked() ), this, SLOT( slotEditMode() ));
00093     connect((QObject *)(theKCMLircBase->theRemoveMode), SIGNAL( clicked() ), this, SLOT( slotRemoveMode() ));
00094     load();
00095 }
00096 
00097 KCMLirc::~KCMLirc()
00098 {
00099 }
00100 
00101 void KCMLirc::updateModesStatus(Q3ListViewItem *item)
00102 {
00103     theKCMLircBase->theModes->setItemsRenameable(item && item->parent());
00104     theKCMLircBase->theAddActions->setEnabled(ProfileServer::profileServer()->profiles().count() && theKCMLircBase->theModes->selectedItem() && RemoteServer::remoteServer()->remotes()[modeMap[theKCMLircBase->theModes->selectedItem()].remote()]);
00105     theKCMLircBase->theAddAction->setEnabled(item);
00106     theKCMLircBase->theAddMode->setEnabled(item);
00107     theKCMLircBase->theRemoveMode->setEnabled(item && item->parent());
00108     theKCMLircBase->theEditMode->setEnabled(item);
00109 }
00110 
00111 void KCMLirc::updateActionsStatus(Q3ListViewItem *item)
00112 {
00113     theKCMLircBase->theRemoveAction->setEnabled(item);
00114     theKCMLircBase->theEditAction->setEnabled(item);
00115 }
00116 
00117 void KCMLirc::slotRenamed(Q3ListViewItem *item)
00118 {
00119     if(!item) return;
00120 
00121     if(item->parent() && item->text(0) != modeMap[item].name())
00122     {   allActions.renameMode(modeMap[item], item->text(0));
00123         allModes.rename(modeMap[item], item->text(0));
00124         emit changed(true);
00125         updateModes();
00126     }
00127 }
00128 
00129 void KCMLirc::slotEditAction()
00130 {
00131     if(!theKCMLircBase->theActions->currentItem()) return;
00132 
00133     EditAction theDialog(actionMap[theKCMLircBase->theActions->currentItem()], this);
00134     Q3ListViewItem *item = theKCMLircBase->theModes->currentItem();
00135     if(item->parent()) item = item->parent();
00136     theDialog.theModes->insertItem(i18n("[Exit current mode]"));
00137     for(item = item->firstChild(); item; item = item->nextSibling())
00138         theDialog.theModes->insertItem(item->text(0));
00139     theDialog.readFrom();
00140     if(theDialog.exec() == QDialog::Accepted) { theDialog.writeBack(); emit changed(true); updateActions(); }
00141 }
00142 
00143 void KCMLirc::slotAddActions()
00144 {
00145     if(!theKCMLircBase->theModes->selectedItem()) return;
00146     Mode m = modeMap[theKCMLircBase->theModes->selectedItem()];
00147     if(!RemoteServer::remoteServer()->remotes()[m.remote()]) return;
00148 
00149     SelectProfile theDialog(this, 0);
00150 
00151     QMap<Q3ListViewItem *, Profile *> profileMap;
00152     Q3Dict<Profile> dict = ProfileServer::profileServer()->profiles();
00153     for(Q3DictIterator<Profile> i(dict); i.current(); ++i) profileMap[new Q3ListViewItem(theDialog.theProfiles, i.current()->name())] = i.current();
00154 
00155     if(theDialog.exec() == QDialog::Accepted && theDialog.theProfiles->currentItem())
00156     {   autoPopulate(*(profileMap[theDialog.theProfiles->currentItem()]), *(RemoteServer::remoteServer()->remotes()[m.remote()]), m.name());
00157         updateActions();
00158         emit changed(true);
00159     }
00160 }
00161 
00162 void KCMLirc::slotAddAction()
00163 {
00164     kDebug() ;
00165     if(!theKCMLircBase->theModes->selectedItem()) return;
00166     Mode m = modeMap[theKCMLircBase->theModes->selectedItem()];
00167 
00168     AddAction theDialog(this, 0, m);
00169     connect(this, SIGNAL(haveButton(const QString &, const QString &)), &theDialog, SLOT(updateButton(const QString &, const QString &)));
00170 
00171     // populate the modes list box
00172     Q3ListViewItem *item = theKCMLircBase->theModes->selectedItem();
00173     if(item->parent()) item = item->parent();
00174     theDialog.theModes->setEnabled(item->firstChild());
00175     theDialog.theSwitchMode->setEnabled(item->firstChild());
00176     for(item = item->firstChild(); item; item = item->nextSibling())
00177     {   K3ListViewItem *a = new K3ListViewItem(theDialog.theModes, item->text(0));
00178         if(item->isSelected()) { a->setSelected(true); theDialog.theModes->setCurrentItem(a); }
00179     }
00180 
00181     if(theDialog.exec() == QDialog::Accepted && theDialog.theButtons->selectedItem())
00182     {   IRAction a;
00183         a.setRemote(m.remote());
00184         a.setMode(m.name());
00185         a.setButton(theDialog.buttonMap[theDialog.theButtons->selectedItem()]);
00186         a.setRepeat(theDialog.theRepeat->isChecked());
00187         a.setAutoStart(theDialog.theAutoStart->isChecked());
00188         a.setDoBefore(theDialog.theDoBefore->isChecked());
00189         a.setDoAfter(theDialog.theDoAfter->isChecked());
00190         a.setUnique(theDialog.isUnique);
00191         a.setIfMulti(theDialog.theDontSend->isChecked() ? IM_DONTSEND : theDialog.theSendToTop->isChecked() ? IM_SENDTOTOP : theDialog.theSendToBottom->isChecked() ? IM_SENDTOBOTTOM : IM_SENDTOALL);
00192         // change mode?
00193         if(theDialog.theChangeMode->isChecked())
00194         {
00195             if(theDialog.theSwitchMode->isChecked() && theDialog.theModes->selectedItem())
00196             {
00197                 a.setProgram("");
00198                 a.setObject(theDialog.theModes->selectedItem()->text(0));
00199             }
00200             else if(theDialog.theExitMode->isChecked())
00201             {
00202                 a.setProgram("");
00203                 a.setObject("");
00204             }
00205             a.setAutoStart(false);
00206             a.setRepeat(false);
00207         }
00208         // DCOP?
00209         else if(theDialog.theUseDCOP->isChecked() && theDialog.theObjects->selectedItem() && theDialog.theObjects->selectedItem()->parent() && theDialog.theFunctions->selectedItem())
00210         {
00211             a.setProgram(theDialog.program);
00212             a.setObject(theDialog.theObjects->selectedItem()->text(0));
00213             a.setMethod(theDialog.theFunctions->selectedItem()->text(2));
00214             theDialog.theParameters->setSorting(3);
00215             a.setArguments(theDialog.theArguments);
00216         }
00217         // profile?
00218         else if(theDialog.theUseProfile->isChecked() && theDialog.theProfiles->selectedItem() && (theDialog.theProfileFunctions->selectedItem() || theDialog.theJustStart->isChecked()))
00219         {
00220             ProfileServer *theServer = ProfileServer::profileServer();
00221 
00222             if(theDialog.theNotJustStart->isChecked())
00223             {   const ProfileAction *theAction = theServer->getAction(theDialog.profileMap[theDialog.theProfiles->selectedItem()], theDialog.profileFunctionMap[theDialog.theProfileFunctions->selectedItem()]);
00224                 a.setProgram(theAction->profile()->id());
00225                 a.setObject(theAction->objId());
00226                 a.setMethod(theAction->prototype());
00227                 theDialog.theParameters->setSorting(3);
00228                 a.setArguments(theDialog.theArguments);
00229             }
00230             else
00231             {   a.setProgram(theServer->profiles()[theDialog.profileMap[theDialog.theProfiles->selectedItem()]]->id());
00232                 a.setObject("");
00233             }
00234         }
00235 
00236         // save our new action
00237         allActions.addAction(a);
00238         updateActions();
00239         emit changed(true);
00240     }
00241 }
00242 
00243 void KCMLirc::slotRemoveAction()
00244 {
00245     if(!theKCMLircBase->theActions->currentItem()) return;
00246 
00247     IRAIt i = actionMap[theKCMLircBase->theActions->currentItem()];
00248     allActions.erase(i);
00249     updateActions();
00250     emit changed(true);
00251 }
00252 
00253 void KCMLirc::autoPopulate(const Profile &profile, const Remote &remote, const QString &mode)
00254 {
00255     Q3Dict<RemoteButton> d = remote.buttons();
00256     for(Q3DictIterator<RemoteButton> i(d); i.current(); ++i)
00257     {   const ProfileAction *pa = profile.searchClass(i.current()->getClass());
00258         if(pa)
00259         {
00260             IRAction a;
00261             a.setRemote(remote.id());
00262             a.setMode(mode);
00263             a.setButton(i.current()->id());
00264             a.setRepeat(pa->repeat());
00265             a.setAutoStart(pa->autoStart());
00266             a.setProgram(pa->profile()->id());
00267             a.setObject(pa->objId());
00268             a.setMethod(pa->prototype());
00269             a.setUnique(pa->profile()->unique());
00270             a.setIfMulti(pa->profile()->ifMulti());
00271             Arguments l;
00272             // argument count should be either 0 or 1. undefined if > 1.
00273             if(Prototype(pa->prototype()).argumentCount() == 1)
00274             {   l.append(QString().setNum(i.current()->parameter().toFloat() * pa->multiplier()));
00275                 l.back().cast(QVariant::nameToType(Prototype(pa->prototype()).type(0).utf8()));
00276             }
00277             a.setArguments(l);
00278             allActions.addAction(a);
00279         }
00280     }
00281 }
00282 
00283 void KCMLirc::slotAddMode()
00284 {
00285     if(!theKCMLircBase->theModes->selectedItem()) return;
00286 
00287     NewModeDialog theDialog(this);
00288     QMap<Q3ListViewItem *, QString> remoteMap;
00289     Q3ListViewItem *tr = theKCMLircBase->theModes->selectedItem();
00290     if(tr) if(tr->parent()) tr = tr->parent();
00291     for(Q3ListViewItem *i = theKCMLircBase->theModes->firstChild(); i; i = i->nextSibling())
00292     {   K3ListViewItem *a = new K3ListViewItem(theDialog.theRemotes, i->text(0));
00293         remoteMap[a] = modeMap[i].remote();
00294         if(i == tr) { a->setSelected(true); theDialog.theRemotes->setCurrentItem(a); }
00295     }
00296     if(theDialog.exec() == QDialog::Accepted && theDialog.theRemotes->selectedItem() && !theDialog.theName->text().isEmpty())
00297     {
00298         allModes.add(Mode(remoteMap[theDialog.theRemotes->selectedItem()], theDialog.theName->text()));
00299         updateModes();
00300         emit changed(true);
00301     }
00302 }
00303 
00304 void KCMLirc::slotEditMode()
00305 {
00306     if(!theKCMLircBase->theModes->selectedItem()) return;
00307 
00308     EditMode theDialog(this, 0);
00309 
00310     Mode &mode = modeMap[theKCMLircBase->theModes->selectedItem()];
00311     theDialog.theName->setEnabled(theKCMLircBase->theModes->selectedItem()->parent());
00312     theDialog.theName->setText(mode.name().isEmpty() ? mode.remoteName() : mode.name());
00313     if(!mode.iconFile().isNull())
00314         theDialog.theIcon->setIcon(mode.iconFile());
00315     else
00316         theDialog.theIcon->resetIcon();
00317     theDialog.theDefault->setChecked(allModes.isDefault(mode));
00318     theDialog.theDefault->setEnabled(!allModes.isDefault(mode));
00319 
00320     if(theDialog.exec() == QDialog::Accepted)
00321     {   kDebug() << "Setting icon : " << theDialog.theIcon->icon() ;
00322         mode.setIconFile(theDialog.theIcon->icon().isEmpty() ? QString::null : theDialog.theIcon->icon());  //krazy:exclude=nullstrassign for old broken gcc
00323         allModes.updateMode(mode);
00324         if(!mode.name().isEmpty())
00325         {   allActions.renameMode(mode, theDialog.theName->text());
00326             allModes.rename(mode, theDialog.theName->text());
00327         }
00328         if(theDialog.theDefault->isChecked()) allModes.setDefault(mode);
00329         emit changed(true);
00330         updateModes();
00331     }
00332 }
00333 
00334 void KCMLirc::slotRemoveMode()
00335 {
00336     if(!theKCMLircBase->theModes->selectedItem()) return;
00337     if(!theKCMLircBase->theModes->selectedItem()->parent()) return;
00338 
00339     if(KMessageBox::warningContinueCancel(this, i18n("Are you sure you want to remove %1 and all its actions?", theKCMLircBase->theModes->selectedItem()->text(0)), i18n("Erase Actions?")) == KMessageBox::Continue)
00340     {
00341         allModes.erase(modeMap[theKCMLircBase->theModes->selectedItem()]);
00342         updateModes();
00343         emit changed(true);
00344     }
00345 }
00346 
00347 void KCMLirc::slotSetDefaultMode()
00348 {
00349     if(!theKCMLircBase->theModes->selectedItem()) return;
00350     allModes.setDefault(modeMap[theKCMLircBase->theModes->selectedItem()]);
00351     updateModes();
00352     emit changed(true);
00353 }
00354 
00355 void KCMLirc::slotDrop(K3ListView *, QDropEvent *, Q3ListViewItem *, Q3ListViewItem *after)
00356 {
00357     Mode m = modeMap[after];
00358 
00359     if(modeMap[theKCMLircBase->theModes->selectedItem()].remote() != m.remote())
00360     {
00361         KMessageBox::error(this, i18n("You may only drag the selected items onto a mode of the same remote control"), i18n("You May Not Drag Here"));
00362         return;
00363     }
00364     for(Q3ListViewItem *i = theKCMLircBase->theActions->firstChild(); i; i = i->nextSibling())
00365         if(i->isSelected())
00366             (*(actionMap[i])).setMode(m.name());
00367 
00368     updateActions();
00369     emit changed(true);
00370 }
00371 
00372 void KCMLirc::updateActions()
00373 {
00374     IRAIt oldCurrent;
00375     if(theKCMLircBase->theActions->selectedItem()) oldCurrent = actionMap[theKCMLircBase->theActions->selectedItem()];
00376 
00377     theKCMLircBase->theActions->clear();
00378     actionMap.clear();
00379 
00380     if(!theKCMLircBase->theModes->selectedItem()) { updateActionsStatus(0); return; }
00381 
00382     Mode m = modeMap[theKCMLircBase->theModes->selectedItem()];
00383     theKCMLircBase->theModeLabel->setText(m.remoteName() + ": " + (m.name().isEmpty() ? i18n("Actions <i>always</i> available") : i18n("Actions available only in mode <b>%1</b>", m.name())));
00384     IRAItList l = allActions.findByMode(m);
00385     for(IRAItList::iterator i = l.begin(); i != l.end(); ++i)
00386     {   Q3ListViewItem *b = new K3ListViewItem(theKCMLircBase->theActions, (**i).buttonName(), (**i).application(), (**i).function(), (**i).arguments().toString(), (**i).notes());
00387         actionMap[b] = *i;
00388         if(*i == oldCurrent) { b->setSelected(true); theKCMLircBase->theActions->setCurrentItem(b); }
00389     }
00390 
00391     if(theKCMLircBase->theActions->currentItem())
00392         theKCMLircBase->theActions->currentItem()->setSelected(true);
00393     updateActionsStatus(theKCMLircBase->theActions->currentItem());
00394 }
00395 
00396 void KCMLirc::gotButton(QString remote, QString button)
00397 {
00398     emit haveButton(remote, button);
00399 }
00400 
00401 void KCMLirc::updateModes()
00402 {
00403     Mode oldCurrent;
00404     if(theKCMLircBase->theModes->selectedItem()) oldCurrent = modeMap[theKCMLircBase->theModes->selectedItem()];
00405 
00406     theKCMLircBase->theModes->clear();
00407     modeMap.clear();
00408 
00409     IRKick_stub IRKick("irkick", "IRKick");
00410     QStringList remotes = IRKick.remotes();
00411     if(remotes.begin() == remotes.end())
00412         theKCMLircBase->theMainLabel->setMaximumSize(32767, 32767);
00413     else
00414         theKCMLircBase->theMainLabel->setMaximumSize(0, 0);
00415     for(QStringList::iterator i = remotes.begin(); i != remotes.end(); ++i)
00416     {   Mode mode = allModes.getMode(*i, "");
00417         Q3ListViewItem *a = new K3ListViewItem(theKCMLircBase->theModes, RemoteServer::remoteServer()->getRemoteName(*i), allModes.isDefault(mode) ? "Default" : "", mode.iconFile().isNull() ? "" : "");
00418         if(!mode.iconFile().isNull())
00419             a->setPixmap(2, KIconLoader().loadIcon(mode.iconFile(), KIconLoader::Panel));
00420         modeMap[a] = mode;  // the null mode
00421         if(modeMap[a] == oldCurrent) { a->setSelected(true); theKCMLircBase->theModes->setCurrentItem(a); }
00422         a->setOpen(true);
00423         ModeList l = allModes.getModes(*i);
00424         for(ModeList::iterator j = l.begin(); j != l.end(); ++j)
00425             if(!(*j).name().isEmpty())
00426             {   Q3ListViewItem *b = new K3ListViewItem(a, (*j).name(), allModes.isDefault(*j) ? i18n("Default") : "", (*j).iconFile().isNull() ? "" : "");
00427                 if(!(*j).iconFile().isNull())
00428                     b->setPixmap(2, KIconLoader().loadIcon((*j).iconFile(), KIconLoader::Panel));
00429                 modeMap[b] = *j;
00430                 if(*j == oldCurrent) { b->setSelected(true); theKCMLircBase->theModes->setCurrentItem(b); }
00431             }
00432     }
00433     if(theKCMLircBase->theModes->currentItem())
00434         theKCMLircBase->theModes->currentItem()->setSelected(true);
00435     updateModesStatus(theKCMLircBase->theModes->currentItem());
00436     updateActions();
00437 }
00438 
00439 void KCMLirc::updateExtensions()
00440 {
00441     theKCMLircBase->theExtensions->clear();
00442 
00443     {   ProfileServer *theServer = ProfileServer::profileServer();
00444         Q3ListViewItem *a = new Q3ListViewItem(theKCMLircBase->theExtensions, i18n("Applications"));
00445         a->setOpen(true);
00446         profileMap.clear();
00447         Q3Dict<Profile> dict = theServer->profiles();
00448         Q3DictIterator<Profile> i(dict);
00449         for(; i.current(); ++i)
00450             profileMap[new Q3ListViewItem(a, i.current()->name())] = i.currentKey();
00451     }
00452     {   RemoteServer *theServer = RemoteServer::remoteServer();
00453         Q3ListViewItem *a = new Q3ListViewItem(theKCMLircBase->theExtensions, i18n("Remote Controls"));
00454         a->setOpen(true);
00455         remoteMap.clear();
00456         Q3Dict<Remote> dict = theServer->remotes();
00457         Q3DictIterator<Remote> i(dict);
00458         for(; i.current(); ++i)
00459             remoteMap[new Q3ListViewItem(a, i.current()->name())] = i.currentKey();
00460     }
00461     updateInformation();
00462 }
00463 
00464 void KCMLirc::updateInformation()
00465 {
00466     theKCMLircBase->theInformation->clear();
00467     theKCMLircBase->theInformationLabel->setText("");
00468 
00469     if(!theKCMLircBase->theExtensions->selectedItem()) return;
00470 
00471     if(!theKCMLircBase->theExtensions->selectedItem()->parent())
00472     {
00473         theKCMLircBase->theInformationLabel->setText(i18n("Information on <b>%1</b>:", theKCMLircBase->theExtensions->selectedItem()->text(0)));
00474         if(theKCMLircBase->theExtensions->selectedItem()->text(0) == i18n("Applications"))
00475             new Q3ListViewItem(theKCMLircBase->theInformation, i18n("Number of Applications"), QString().setNum(theKCMLircBase->theExtensions->selectedItem()->childCount()));
00476         else if(theKCMLircBase->theExtensions->selectedItem()->text(0) == i18n("Remote Controls"))
00477             new Q3ListViewItem(theKCMLircBase->theInformation, i18n("Number of Remote Controls"), QString().setNum(theKCMLircBase->theExtensions->selectedItem()->childCount()));
00478     }
00479     else if(theKCMLircBase->theExtensions->selectedItem()->parent()->text(0) == i18n("Applications"))
00480     {
00481         ProfileServer *theServer = ProfileServer::profileServer();
00482         const Profile *p = theServer->profiles()[profileMap[theKCMLircBase->theExtensions->selectedItem()]];
00483         new Q3ListViewItem(theKCMLircBase->theInformation, i18n("Extension Name"), p->name());
00484         new Q3ListViewItem(theKCMLircBase->theInformation, i18n("Extension Author"), p->author());
00485         new Q3ListViewItem(theKCMLircBase->theInformation, i18n("Application Identifier"), p->id());
00486         new Q3ListViewItem(theKCMLircBase->theInformation, i18n("Number of Actions"), QString().setNum(p->actions().count()));
00487         theKCMLircBase->theInformationLabel->setText(i18n("Information on <b>%1</b>:", p->name()));
00488     }
00489     else if(theKCMLircBase->theExtensions->selectedItem()->parent()->text(0) == i18n("Remote Controls"))
00490     {
00491         RemoteServer *theServer = RemoteServer::remoteServer();
00492         const Remote *p = theServer->remotes()[remoteMap[theKCMLircBase->theExtensions->selectedItem()]];
00493         new Q3ListViewItem(theKCMLircBase->theInformation, i18n("Extension Name"), p->name());
00494         new Q3ListViewItem(theKCMLircBase->theInformation, i18n("Extension Author"), p->author());
00495         new Q3ListViewItem(theKCMLircBase->theInformation, i18n("Remote Control Identifier"), p->id());
00496         new Q3ListViewItem(theKCMLircBase->theInformation, i18n("Number of Buttons"), QString().setNum(p->buttons().count()));
00497         theKCMLircBase->theInformationLabel->setText(i18n("Information on <b>%1</b>:", p->name()));
00498     }
00499 }
00500 
00501 void KCMLirc::load()
00502 {
00503     KSimpleConfig theConfig("irkickrc");
00504     allActions.loadFromConfig(theConfig);
00505     allModes.loadFromConfig(theConfig);
00506     allModes.generateNulls(IRKick_stub("irkick", "IRKick").remotes());
00507 
00508     updateExtensions();
00509     updateModes();
00510     updateActions();
00511 }
00512 
00513 void KCMLirc::defaults()
00514 {
00515     // insert your default settings code here...
00516     emit changed(true);
00517 }
00518 
00519 void KCMLirc::save()
00520 {
00521     KSimpleConfig theConfig("irkickrc");
00522     allActions.saveToConfig(theConfig);
00523     allModes.saveToConfig(theConfig);
00524 
00525     theConfig.sync();
00526     IRKick_stub("irkick", "IRKick").reloadConfiguration();
00527 
00528     emit changed(true);
00529 }
00530 
00531 void KCMLirc::configChanged()
00532 {
00533  // insert your saving code here...
00534     emit changed(true);
00535 }
00536 
00537 // TODO: Take this out when I know how
00538 extern "C"
00539 {
00540     KDE_EXPORT KCModule *create_kcmlirc(QWidget *parent, const char *)
00541     {   KGlobal::locale()->insertCatalog("kcmlirc");
00542         return new KCMLirc(parent);
00543     }
00544 }
00545 
00546 #include <ktoolinvocation.h>
00547 
00548 #include "kcmlirc.moc"

kdelirc

Skip menu "kdelirc"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • 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