You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
546 lines
22 KiB
546 lines
22 KiB
15 years ago
|
/***************************************************************************
|
||
|
* Copyright (C) 2003 by Gav Wood *
|
||
|
* gav@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. *
|
||
|
***************************************************************************/
|
||
|
|
||
14 years ago
|
#include <tqcheckbox.h>
|
||
|
#include <tqlabel.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
14 years ago
|
#include <tqlineedit.h>
|
||
|
#include <tqradiobutton.h>
|
||
|
#include <tqcombobox.h>
|
||
|
#include <tqevent.h>
|
||
|
#include <tqlistview.h>
|
||
15 years ago
|
|
||
|
#include <kpushbutton.h>
|
||
12 years ago
|
#include <tdeapplication.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
|
#include <tdeglobal.h>
|
||
12 years ago
|
#include <tdeconfig.h>
|
||
15 years ago
|
#include <kicondialog.h>
|
||
|
#include <kiconloader.h>
|
||
|
#include <kdebug.h>
|
||
|
#include <ksimpleconfig.h>
|
||
|
#include <kgenericfactory.h>
|
||
12 years ago
|
#include <tdelistview.h>
|
||
12 years ago
|
#include <tdemessagebox.h>
|
||
15 years ago
|
#include <kpushbutton.h>
|
||
|
|
||
|
#include <dcopclient.h>
|
||
|
#include <dcopref.h>
|
||
|
|
||
|
#include <irkick_stub.h>
|
||
|
|
||
|
#include "addaction.h"
|
||
|
#include "newmode.h"
|
||
|
#include "profileserver.h"
|
||
|
#include "remoteserver.h"
|
||
|
#include "kcmlirc.h"
|
||
|
#include "editaction.h"
|
||
|
#include "editmode.h"
|
||
|
#include "modeslist.h"
|
||
|
#include "selectprofile.h"
|
||
|
|
||
14 years ago
|
typedef KGenericFactory<KCMLirc, TQWidget> theFactory;
|
||
15 years ago
|
K_EXPORT_COMPONENT_FACTORY(kcmlirc, theFactory("kcmlirc"))
|
||
|
|
||
12 years ago
|
KCMLirc::KCMLirc(TQWidget *parent, const char *name, TQStringList /*args*/) : DCOPObject("KCMLirc"), TDECModule(parent, name)
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEGlobal::locale()->insertCatalogue( "kcmlirc" );
|
||
12 years ago
|
setAboutData(new TDEAboutData("kcmlirc", I18N_NOOP("TDE Lirc"), VERSION, I18N_NOOP("The TDE IR Remote Control System"), TDEAboutData::License_GPL_V2, "Copyright (c)2003 Gav Wood", I18N_NOOP("Use this to configure TDE's infrared remote control system in order to control any TDE application with your infrared remote control."), "http://www.kde.org"));
|
||
12 years ago
|
setButtons(TDECModule::Help);
|
||
13 years ago
|
setQuickHelp(i18n("<h1>Remote Controls</h1><p>This module allows you to configure bindings between your remote controls and TDE applications. Simply select your remote control and click Add under the Actions/Buttons list. If you want TDE 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>"));
|
||
15 years ago
|
bool ok;
|
||
12 years ago
|
TDEApplication::kApplication()->dcopClient()->remoteInterfaces("irkick", "IRKick", &ok);
|
||
15 years ago
|
if(!ok)
|
||
|
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)
|
||
12 years ago
|
{ kdDebug() << "S" << TDEApplication::startServiceByDesktopName("irkick") << endl;
|
||
15 years ago
|
KSimpleConfig theConfig("irkickrc");
|
||
|
theConfig.setGroup("General");
|
||
|
if(theConfig.readBoolEntry("AutoStart", true) == false)
|
||
13 years ago
|
if(KMessageBox::questionYesNo(this, i18n("Would you like the infrared remote control software to start automatically when you begin TDE?"), i18n("Automatically Start?"), i18n("Start Automatically"), i18n("Do Not Start")) == KMessageBox::Yes)
|
||
15 years ago
|
theConfig.writeEntry("AutoStart", true);
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEApplication::kApplication()->dcopClient()->remoteInterfaces("irkick", "IRKick", &ok);
|
||
15 years ago
|
kdDebug() << "OK" << ok << endl;
|
||
|
|
||
|
|
||
14 years ago
|
(new TQHBoxLayout(this))->setAutoAdd(true);
|
||
15 years ago
|
theKCMLircBase = new KCMLircBase(this);
|
||
14 years ago
|
connect(theKCMLircBase->theModes, TQT_SIGNAL( selectionChanged(TQListViewItem *) ), this, TQT_SLOT( updateActions() ));
|
||
13 years ago
|
connect(theKCMLircBase->theModes, TQT_SIGNAL( selectionChanged(TQListViewItem *) ), this, TQT_SLOT( updateModesStatus(TQListViewItem *) ));
|
||
|
connect(theKCMLircBase->theActions, TQT_SIGNAL( currentChanged(TQListViewItem *) ), this, TQT_SLOT( updateActionsStatus(TQListViewItem *) ));
|
||
14 years ago
|
connect(theKCMLircBase->theExtensions, TQT_SIGNAL( selectionChanged(TQListViewItem *) ), this, TQT_SLOT( updateInformation() ));
|
||
|
connect(theKCMLircBase->theModes, TQT_SIGNAL( itemRenamed(TQListViewItem *) ), this, TQT_SLOT( slotRenamed(TQListViewItem *) ));
|
||
12 years ago
|
connect(theKCMLircBase->theModes, TQT_SIGNAL(dropped(TDEListView*, TQDropEvent*, TQListViewItem*, TQListViewItem*)), this, TQT_SLOT(slotDrop(TDEListView*, TQDropEvent*, TQListViewItem*, TQListViewItem*)));
|
||
14 years ago
|
connect((TQObject *)(theKCMLircBase->theAddActions), TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotAddActions() ));
|
||
|
connect((TQObject *)(theKCMLircBase->theAddAction), TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotAddAction() ));
|
||
|
connect((TQObject *)(theKCMLircBase->theEditAction), TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotEditAction() ));
|
||
|
connect((TQObject *)(theKCMLircBase->theActions), TQT_SIGNAL( doubleClicked(TQListViewItem *) ), this, TQT_SLOT( slotEditAction() ));
|
||
|
connect((TQObject *)(theKCMLircBase->theRemoveAction), TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotRemoveAction() ));
|
||
|
connect((TQObject *)(theKCMLircBase->theAddMode), TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotAddMode() ));
|
||
|
connect((TQObject *)(theKCMLircBase->theEditMode), TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotEditMode() ));
|
||
|
connect((TQObject *)(theKCMLircBase->theRemoveMode), TQT_SIGNAL( clicked() ), this, TQT_SLOT( slotRemoveMode() ));
|
||
15 years ago
|
load();
|
||
|
}
|
||
|
|
||
|
KCMLirc::~KCMLirc()
|
||
|
{
|
||
|
}
|
||
|
|
||
13 years ago
|
void KCMLirc::updateModesStatus(TQListViewItem *item)
|
||
15 years ago
|
{
|
||
13 years ago
|
theKCMLircBase->theModes->setItemsRenameable(item && item->parent());
|
||
15 years ago
|
theKCMLircBase->theAddActions->setEnabled(ProfileServer::profileServer()->profiles().count() && theKCMLircBase->theModes->selectedItem() && RemoteServer::remoteServer()->remotes()[modeMap[theKCMLircBase->theModes->selectedItem()].remote()]);
|
||
|
theKCMLircBase->theAddAction->setEnabled(item);
|
||
|
theKCMLircBase->theAddMode->setEnabled(item);
|
||
13 years ago
|
theKCMLircBase->theRemoveMode->setEnabled(item && item->parent());
|
||
15 years ago
|
theKCMLircBase->theEditMode->setEnabled(item);
|
||
|
}
|
||
|
|
||
13 years ago
|
void KCMLirc::updateActionsStatus(TQListViewItem *item)
|
||
15 years ago
|
{
|
||
|
theKCMLircBase->theRemoveAction->setEnabled(item);
|
||
|
theKCMLircBase->theEditAction->setEnabled(item);
|
||
|
}
|
||
|
|
||
14 years ago
|
void KCMLirc::slotRenamed(TQListViewItem *item)
|
||
15 years ago
|
{
|
||
|
if(!item) return;
|
||
|
|
||
13 years ago
|
if(item->parent() && item->text(0) != modeMap[item].name())
|
||
15 years ago
|
{ allActions.renameMode(modeMap[item], item->text(0));
|
||
|
allModes.rename(modeMap[item], item->text(0));
|
||
|
emit changed(true);
|
||
|
updateModes();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KCMLirc::slotEditAction()
|
||
|
{
|
||
|
if(!theKCMLircBase->theActions->currentItem()) return;
|
||
|
|
||
|
EditAction theDialog(actionMap[theKCMLircBase->theActions->currentItem()], this);
|
||
14 years ago
|
TQListViewItem *item = theKCMLircBase->theModes->currentItem();
|
||
13 years ago
|
if(item->parent()) item = item->parent();
|
||
15 years ago
|
theDialog.theModes->insertItem(i18n("[Exit current mode]"));
|
||
|
for(item = item->firstChild(); item; item = item->nextSibling())
|
||
|
theDialog.theModes->insertItem(item->text(0));
|
||
|
theDialog.readFrom();
|
||
14 years ago
|
if(theDialog.exec() == TQDialog::Accepted) { theDialog.writeBack(); emit changed(true); updateActions(); }
|
||
15 years ago
|
}
|
||
|
|
||
|
void KCMLirc::slotAddActions()
|
||
|
{
|
||
|
if(!theKCMLircBase->theModes->selectedItem()) return;
|
||
|
Mode m = modeMap[theKCMLircBase->theModes->selectedItem()];
|
||
|
if(!RemoteServer::remoteServer()->remotes()[m.remote()]) return;
|
||
|
|
||
|
SelectProfile theDialog(this, 0);
|
||
|
|
||
14 years ago
|
TQMap<TQListViewItem *, Profile *> profileMap;
|
||
|
TQDict<Profile> dict = ProfileServer::profileServer()->profiles();
|
||
|
for(TQDictIterator<Profile> i(dict); i.current(); ++i) profileMap[new TQListViewItem(theDialog.theProfiles, i.current()->name())] = i.current();
|
||
15 years ago
|
|
||
14 years ago
|
if(theDialog.exec() == TQDialog::Accepted && theDialog.theProfiles->currentItem())
|
||
15 years ago
|
{ autoPopulate(*(profileMap[theDialog.theProfiles->currentItem()]), *(RemoteServer::remoteServer()->remotes()[m.remote()]), m.name());
|
||
|
updateActions();
|
||
|
emit changed(true);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KCMLirc::slotAddAction()
|
||
|
{
|
||
|
kdDebug() << k_funcinfo << endl;
|
||
|
if(!theKCMLircBase->theModes->selectedItem()) return;
|
||
|
Mode m = modeMap[theKCMLircBase->theModes->selectedItem()];
|
||
|
|
||
|
AddAction theDialog(this, 0, m);
|
||
14 years ago
|
connect(this, TQT_SIGNAL(haveButton(const TQString &, const TQString &)), &theDialog, TQT_SLOT(updateButton(const TQString &, const TQString &)));
|
||
15 years ago
|
|
||
|
// populate the modes list box
|
||
14 years ago
|
TQListViewItem *item = theKCMLircBase->theModes->selectedItem();
|
||
13 years ago
|
if(item->parent()) item = item->parent();
|
||
15 years ago
|
theDialog.theModes->setEnabled(item->firstChild());
|
||
|
theDialog.theSwitchMode->setEnabled(item->firstChild());
|
||
|
for(item = item->firstChild(); item; item = item->nextSibling())
|
||
12 years ago
|
{ TDEListViewItem *a = new TDEListViewItem(theDialog.theModes, item->text(0));
|
||
15 years ago
|
if(item->isSelected()) { a->setSelected(true); theDialog.theModes->setCurrentItem(a); }
|
||
|
}
|
||
|
|
||
14 years ago
|
if(theDialog.exec() == TQDialog::Accepted && theDialog.theButtons->selectedItem())
|
||
15 years ago
|
{ IRAction a;
|
||
|
a.setRemote(m.remote());
|
||
|
a.setMode(m.name());
|
||
|
a.setButton(theDialog.buttonMap[theDialog.theButtons->selectedItem()]);
|
||
|
a.setRepeat(theDialog.theRepeat->isChecked());
|
||
|
a.setAutoStart(theDialog.theAutoStart->isChecked());
|
||
|
a.setDoBefore(theDialog.theDoBefore->isChecked());
|
||
|
a.setDoAfter(theDialog.theDoAfter->isChecked());
|
||
|
a.setUnique(theDialog.isUnique);
|
||
|
a.setIfMulti(theDialog.theDontSend->isChecked() ? IM_DONTSEND : theDialog.theSendToTop->isChecked() ? IM_SENDTOTOP : theDialog.theSendToBottom->isChecked() ? IM_SENDTOBOTTOM : IM_SENDTOALL);
|
||
|
// change mode?
|
||
|
if(theDialog.theChangeMode->isChecked())
|
||
|
{
|
||
|
if(theDialog.theSwitchMode->isChecked() && theDialog.theModes->selectedItem())
|
||
|
{
|
||
|
a.setProgram("");
|
||
|
a.setObject(theDialog.theModes->selectedItem()->text(0));
|
||
|
}
|
||
|
else if(theDialog.theExitMode->isChecked())
|
||
|
{
|
||
|
a.setProgram("");
|
||
|
a.setObject("");
|
||
|
}
|
||
|
a.setAutoStart(false);
|
||
|
a.setRepeat(false);
|
||
|
}
|
||
|
// DCOP?
|
||
13 years ago
|
else if(theDialog.theUseDCOP->isChecked() && theDialog.theObjects->selectedItem() && theDialog.theObjects->selectedItem()->parent() && theDialog.theFunctions->selectedItem())
|
||
15 years ago
|
{
|
||
|
a.setProgram(theDialog.program);
|
||
|
a.setObject(theDialog.theObjects->selectedItem()->text(0));
|
||
|
a.setMethod(theDialog.theFunctions->selectedItem()->text(2));
|
||
|
theDialog.theParameters->setSorting(3);
|
||
|
a.setArguments(theDialog.theArguments);
|
||
|
}
|
||
|
// profile?
|
||
|
else if(theDialog.theUseProfile->isChecked() && theDialog.theProfiles->selectedItem() && (theDialog.theProfileFunctions->selectedItem() || theDialog.theJustStart->isChecked()))
|
||
|
{
|
||
|
ProfileServer *theServer = ProfileServer::profileServer();
|
||
|
|
||
|
if(theDialog.theNotJustStart->isChecked())
|
||
|
{ const ProfileAction *theAction = theServer->getAction(theDialog.profileMap[theDialog.theProfiles->selectedItem()], theDialog.profileFunctionMap[theDialog.theProfileFunctions->selectedItem()]);
|
||
|
a.setProgram(theAction->profile()->id());
|
||
|
a.setObject(theAction->objId());
|
||
|
a.setMethod(theAction->prototype());
|
||
|
theDialog.theParameters->setSorting(3);
|
||
|
a.setArguments(theDialog.theArguments);
|
||
|
}
|
||
|
else
|
||
|
{ a.setProgram(theServer->profiles()[theDialog.profileMap[theDialog.theProfiles->selectedItem()]]->id());
|
||
|
a.setObject("");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// save our new action
|
||
|
allActions.addAction(a);
|
||
|
updateActions();
|
||
|
emit changed(true);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KCMLirc::slotRemoveAction()
|
||
|
{
|
||
|
if(!theKCMLircBase->theActions->currentItem()) return;
|
||
|
|
||
|
IRAIt i = actionMap[theKCMLircBase->theActions->currentItem()];
|
||
|
allActions.erase(i);
|
||
|
updateActions();
|
||
|
emit changed(true);
|
||
|
}
|
||
|
|
||
14 years ago
|
void KCMLirc::autoPopulate(const Profile &profile, const Remote &remote, const TQString &mode)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQDict<RemoteButton> d = remote.buttons();
|
||
|
for(TQDictIterator<RemoteButton> i(d); i.current(); ++i)
|
||
15 years ago
|
{ const ProfileAction *pa = profile.searchClass(i.current()->getClass());
|
||
|
if(pa)
|
||
|
{
|
||
|
IRAction a;
|
||
|
a.setRemote(remote.id());
|
||
|
a.setMode(mode);
|
||
|
a.setButton(i.current()->id());
|
||
|
a.setRepeat(pa->repeat());
|
||
|
a.setAutoStart(pa->autoStart());
|
||
|
a.setProgram(pa->profile()->id());
|
||
|
a.setObject(pa->objId());
|
||
|
a.setMethod(pa->prototype());
|
||
|
a.setUnique(pa->profile()->unique());
|
||
|
a.setIfMulti(pa->profile()->ifMulti());
|
||
|
Arguments l;
|
||
|
// argument count should be either 0 or 1. undefined if > 1.
|
||
|
if(Prototype(pa->prototype()).argumentCount() == 1)
|
||
13 years ago
|
{
|
||
|
l.append(TQString(TQString().setNum(i.current()->parameter().toFloat() * pa->multiplier())));
|
||
14 years ago
|
l.back().cast(TQVariant::nameToType(Prototype(pa->prototype()).type(0).utf8()));
|
||
15 years ago
|
}
|
||
|
a.setArguments(l);
|
||
|
allActions.addAction(a);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KCMLirc::slotAddMode()
|
||
|
{
|
||
|
if(!theKCMLircBase->theModes->selectedItem()) return;
|
||
|
|
||
|
NewMode theDialog(this, 0);
|
||
14 years ago
|
TQMap<TQListViewItem *, TQString> remoteMap;
|
||
|
TQListViewItem *tr = theKCMLircBase->theModes->selectedItem();
|
||
13 years ago
|
if(tr) if(tr->parent()) tr = tr->parent();
|
||
14 years ago
|
for(TQListViewItem *i = theKCMLircBase->theModes->firstChild(); i; i = i->nextSibling())
|
||
12 years ago
|
{ TDEListViewItem *a = new TDEListViewItem(theDialog.theRemotes, i->text(0));
|
||
15 years ago
|
remoteMap[a] = modeMap[i].remote();
|
||
|
if(i == tr) { a->setSelected(true); theDialog.theRemotes->setCurrentItem(a); }
|
||
|
}
|
||
14 years ago
|
if(theDialog.exec() == TQDialog::Accepted && theDialog.theRemotes->selectedItem() && !theDialog.theName->text().isEmpty())
|
||
15 years ago
|
{
|
||
|
allModes.add(Mode(remoteMap[theDialog.theRemotes->selectedItem()], theDialog.theName->text()));
|
||
|
updateModes();
|
||
|
emit changed(true);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KCMLirc::slotEditMode()
|
||
|
{
|
||
|
if(!theKCMLircBase->theModes->selectedItem()) return;
|
||
|
|
||
|
EditMode theDialog(this, 0);
|
||
|
|
||
|
Mode &mode = modeMap[theKCMLircBase->theModes->selectedItem()];
|
||
13 years ago
|
theDialog.theName->setEnabled(theKCMLircBase->theModes->selectedItem()->parent());
|
||
15 years ago
|
theDialog.theName->setText(mode.name().isEmpty() ? mode.remoteName() : mode.name());
|
||
|
if(!mode.iconFile().isNull())
|
||
|
theDialog.theIcon->setIcon(mode.iconFile());
|
||
|
else
|
||
|
theDialog.theIcon->resetIcon();
|
||
|
theDialog.theDefault->setChecked(allModes.isDefault(mode));
|
||
|
theDialog.theDefault->setEnabled(!allModes.isDefault(mode));
|
||
|
|
||
14 years ago
|
if(theDialog.exec() == TQDialog::Accepted)
|
||
15 years ago
|
{ kdDebug() << "Setting icon : " << theDialog.theIcon->icon() << endl;
|
||
13 years ago
|
mode.setIconFile(theDialog.theIcon->icon().isEmpty() ? TQString() : theDialog.theIcon->icon());
|
||
15 years ago
|
allModes.updateMode(mode);
|
||
|
if(!mode.name().isEmpty())
|
||
|
{ allActions.renameMode(mode, theDialog.theName->text());
|
||
|
allModes.rename(mode, theDialog.theName->text());
|
||
|
}
|
||
|
if(theDialog.theDefault->isChecked()) allModes.setDefault(mode);
|
||
|
emit changed(true);
|
||
|
updateModes();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KCMLirc::slotRemoveMode()
|
||
|
{
|
||
|
if(!theKCMLircBase->theModes->selectedItem()) return;
|
||
13 years ago
|
if(!theKCMLircBase->theModes->selectedItem()->parent()) return;
|
||
15 years ago
|
|
||
13 years ago
|
if(KMessageBox::warningContinueCancel(this, i18n("Are you sure you want to remove %1 and all its actions?").arg(theKCMLircBase->theModes->selectedItem()->text(0)), i18n("Erase Actions?")) == KMessageBox::Continue)
|
||
15 years ago
|
{
|
||
|
allModes.erase(modeMap[theKCMLircBase->theModes->selectedItem()]);
|
||
|
updateModes();
|
||
|
emit changed(true);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KCMLirc::slotSetDefaultMode()
|
||
|
{
|
||
|
if(!theKCMLircBase->theModes->selectedItem()) return;
|
||
|
allModes.setDefault(modeMap[theKCMLircBase->theModes->selectedItem()]);
|
||
|
updateModes();
|
||
|
emit changed(true);
|
||
|
}
|
||
|
|
||
12 years ago
|
void KCMLirc::slotDrop(TDEListView *, TQDropEvent *, TQListViewItem *, TQListViewItem *after)
|
||
15 years ago
|
{
|
||
|
Mode m = modeMap[after];
|
||
|
|
||
|
if(modeMap[theKCMLircBase->theModes->selectedItem()].remote() != m.remote())
|
||
|
{
|
||
|
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"));
|
||
|
return;
|
||
|
}
|
||
14 years ago
|
for(TQListViewItem *i = theKCMLircBase->theActions->firstChild(); i; i = i->nextSibling())
|
||
15 years ago
|
if(i->isSelected())
|
||
|
(*(actionMap[i])).setMode(m.name());
|
||
|
|
||
|
updateActions();
|
||
|
emit changed(true);
|
||
|
}
|
||
|
|
||
|
void KCMLirc::updateActions()
|
||
|
{
|
||
|
IRAIt oldCurrent;
|
||
|
if(theKCMLircBase->theActions->selectedItem()) oldCurrent = actionMap[theKCMLircBase->theActions->selectedItem()];
|
||
|
|
||
|
theKCMLircBase->theActions->clear();
|
||
|
actionMap.clear();
|
||
|
|
||
13 years ago
|
if(!theKCMLircBase->theModes->selectedItem()) { updateActionsStatus(0); return; }
|
||
15 years ago
|
|
||
|
Mode m = modeMap[theKCMLircBase->theModes->selectedItem()];
|
||
13 years ago
|
theKCMLircBase->theModeLabel->setText(m.remoteName() + ": " + (m.name().isEmpty() ? i18n("Actions <i>always</i> available") : i18n("Actions available only in mode <b>%1</b>").arg(m.name())));
|
||
15 years ago
|
IRAItList l = allActions.findByMode(m);
|
||
|
for(IRAItList::iterator i = l.begin(); i != l.end(); ++i)
|
||
12 years ago
|
{ TQListViewItem *b = new TDEListViewItem(theKCMLircBase->theActions, (**i).buttonName(), (**i).application(), (**i).function(), (**i).arguments().toString(), (**i).notes());
|
||
15 years ago
|
actionMap[b] = *i;
|
||
|
if(*i == oldCurrent) { b->setSelected(true); theKCMLircBase->theActions->setCurrentItem(b); }
|
||
|
}
|
||
|
|
||
|
if(theKCMLircBase->theActions->currentItem())
|
||
|
theKCMLircBase->theActions->currentItem()->setSelected(true);
|
||
13 years ago
|
updateActionsStatus(theKCMLircBase->theActions->currentItem());
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
void KCMLirc::gotButton(TQString remote, TQString button)
|
||
15 years ago
|
{
|
||
|
emit haveButton(remote, button);
|
||
|
}
|
||
|
|
||
|
void KCMLirc::updateModes()
|
||
|
{
|
||
|
Mode oldCurrent;
|
||
|
if(theKCMLircBase->theModes->selectedItem()) oldCurrent = modeMap[theKCMLircBase->theModes->selectedItem()];
|
||
|
|
||
|
theKCMLircBase->theModes->clear();
|
||
|
modeMap.clear();
|
||
|
|
||
|
IRKick_stub IRKick("irkick", "IRKick");
|
||
14 years ago
|
TQStringList remotes = IRKick.remotes();
|
||
15 years ago
|
if(remotes.begin() == remotes.end())
|
||
|
theKCMLircBase->theMainLabel->setMaximumSize(32767, 32767);
|
||
|
else
|
||
|
theKCMLircBase->theMainLabel->setMaximumSize(0, 0);
|
||
14 years ago
|
for(TQStringList::iterator i = remotes.begin(); i != remotes.end(); ++i)
|
||
15 years ago
|
{ Mode mode = allModes.getMode(*i, "");
|
||
12 years ago
|
TQListViewItem *a = new TDEListViewItem(theKCMLircBase->theModes, RemoteServer::remoteServer()->getRemoteName(*i), allModes.isDefault(mode) ? "Default" : "", mode.iconFile().isNull() ? "" : "");
|
||
15 years ago
|
if(!mode.iconFile().isNull())
|
||
12 years ago
|
a->setPixmap(2, TDEIconLoader().loadIcon(mode.iconFile(), TDEIcon::Panel));
|
||
15 years ago
|
modeMap[a] = mode; // the null mode
|
||
|
if(modeMap[a] == oldCurrent) { a->setSelected(true); theKCMLircBase->theModes->setCurrentItem(a); }
|
||
|
a->setOpen(true);
|
||
|
ModeList l = allModes.getModes(*i);
|
||
|
for(ModeList::iterator j = l.begin(); j != l.end(); ++j)
|
||
|
if(!(*j).name().isEmpty())
|
||
12 years ago
|
{ TQListViewItem *b = new TDEListViewItem(a, (*j).name(), allModes.isDefault(*j) ? i18n("Default") : "", (*j).iconFile().isNull() ? "" : "");
|
||
15 years ago
|
if(!(*j).iconFile().isNull())
|
||
12 years ago
|
b->setPixmap(2, TDEIconLoader().loadIcon((*j).iconFile(), TDEIcon::Panel));
|
||
15 years ago
|
modeMap[b] = *j;
|
||
|
if(*j == oldCurrent) { b->setSelected(true); theKCMLircBase->theModes->setCurrentItem(b); }
|
||
|
}
|
||
|
}
|
||
|
if(theKCMLircBase->theModes->currentItem())
|
||
|
theKCMLircBase->theModes->currentItem()->setSelected(true);
|
||
13 years ago
|
updateModesStatus(theKCMLircBase->theModes->currentItem());
|
||
15 years ago
|
updateActions();
|
||
|
}
|
||
|
|
||
|
void KCMLirc::updateExtensions()
|
||
|
{
|
||
|
theKCMLircBase->theExtensions->clear();
|
||
|
|
||
|
{ ProfileServer *theServer = ProfileServer::profileServer();
|
||
14 years ago
|
TQListViewItem *a = new TQListViewItem(theKCMLircBase->theExtensions, i18n("Applications"));
|
||
15 years ago
|
a->setOpen(true);
|
||
|
profileMap.clear();
|
||
14 years ago
|
TQDict<Profile> dict = theServer->profiles();
|
||
|
TQDictIterator<Profile> i(dict);
|
||
15 years ago
|
for(; i.current(); ++i)
|
||
14 years ago
|
profileMap[new TQListViewItem(a, i.current()->name())] = i.currentKey();
|
||
15 years ago
|
}
|
||
|
{ RemoteServer *theServer = RemoteServer::remoteServer();
|
||
14 years ago
|
TQListViewItem *a = new TQListViewItem(theKCMLircBase->theExtensions, i18n("Remote Controls"));
|
||
15 years ago
|
a->setOpen(true);
|
||
|
remoteMap.clear();
|
||
14 years ago
|
TQDict<Remote> dict = theServer->remotes();
|
||
|
TQDictIterator<Remote> i(dict);
|
||
15 years ago
|
for(; i.current(); ++i)
|
||
14 years ago
|
remoteMap[new TQListViewItem(a, i.current()->name())] = i.currentKey();
|
||
15 years ago
|
}
|
||
|
updateInformation();
|
||
|
}
|
||
|
|
||
|
void KCMLirc::updateInformation()
|
||
|
{
|
||
|
theKCMLircBase->theInformation->clear();
|
||
|
theKCMLircBase->theInformationLabel->setText("");
|
||
|
|
||
|
if(!theKCMLircBase->theExtensions->selectedItem()) return;
|
||
|
|
||
13 years ago
|
if(!theKCMLircBase->theExtensions->selectedItem()->parent())
|
||
15 years ago
|
{
|
||
13 years ago
|
theKCMLircBase->theInformationLabel->setText(i18n("Information on <b>%1</b>:").arg(theKCMLircBase->theExtensions->selectedItem()->text(0)));
|
||
15 years ago
|
if(theKCMLircBase->theExtensions->selectedItem()->text(0) == i18n("Applications"))
|
||
14 years ago
|
new TQListViewItem(theKCMLircBase->theInformation, i18n("Number of Applications"), TQString().setNum(theKCMLircBase->theExtensions->selectedItem()->childCount()));
|
||
15 years ago
|
else if(theKCMLircBase->theExtensions->selectedItem()->text(0) == i18n("Remote Controls"))
|
||
14 years ago
|
new TQListViewItem(theKCMLircBase->theInformation, i18n("Number of Remote Controls"), TQString().setNum(theKCMLircBase->theExtensions->selectedItem()->childCount()));
|
||
15 years ago
|
}
|
||
13 years ago
|
else if(theKCMLircBase->theExtensions->selectedItem()->parent()->text(0) == i18n("Applications"))
|
||
15 years ago
|
{
|
||
|
ProfileServer *theServer = ProfileServer::profileServer();
|
||
|
const Profile *p = theServer->profiles()[profileMap[theKCMLircBase->theExtensions->selectedItem()]];
|
||
14 years ago
|
new TQListViewItem(theKCMLircBase->theInformation, i18n("Extension Name"), p->name());
|
||
|
new TQListViewItem(theKCMLircBase->theInformation, i18n("Extension Author"), p->author());
|
||
|
new TQListViewItem(theKCMLircBase->theInformation, i18n("Application Identifier"), p->id());
|
||
|
new TQListViewItem(theKCMLircBase->theInformation, i18n("Number of Actions"), TQString().setNum(p->actions().count()));
|
||
13 years ago
|
theKCMLircBase->theInformationLabel->setText(i18n("Information on <b>%1</b>:").arg(p->name()));
|
||
15 years ago
|
}
|
||
13 years ago
|
else if(theKCMLircBase->theExtensions->selectedItem()->parent()->text(0) == i18n("Remote Controls"))
|
||
15 years ago
|
{
|
||
|
RemoteServer *theServer = RemoteServer::remoteServer();
|
||
|
const Remote *p = theServer->remotes()[remoteMap[theKCMLircBase->theExtensions->selectedItem()]];
|
||
14 years ago
|
new TQListViewItem(theKCMLircBase->theInformation, i18n("Extension Name"), p->name());
|
||
|
new TQListViewItem(theKCMLircBase->theInformation, i18n("Extension Author"), p->author());
|
||
|
new TQListViewItem(theKCMLircBase->theInformation, i18n("Remote Control Identifier"), p->id());
|
||
|
new TQListViewItem(theKCMLircBase->theInformation, i18n("Number of Buttons"), TQString().setNum(p->buttons().count()));
|
||
13 years ago
|
theKCMLircBase->theInformationLabel->setText(i18n("Information on <b>%1</b>:").arg(p->name()));
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
void KCMLirc::load()
|
||
|
{
|
||
|
KSimpleConfig theConfig("irkickrc");
|
||
|
allActions.loadFromConfig(theConfig);
|
||
|
allModes.loadFromConfig(theConfig);
|
||
|
allModes.generateNulls(IRKick_stub("irkick", "IRKick").remotes());
|
||
|
|
||
|
updateExtensions();
|
||
|
updateModes();
|
||
|
updateActions();
|
||
|
}
|
||
|
|
||
|
void KCMLirc::defaults()
|
||
|
{
|
||
|
// insert your default settings code here...
|
||
|
emit changed(true);
|
||
|
}
|
||
|
|
||
|
void KCMLirc::save()
|
||
|
{
|
||
|
KSimpleConfig theConfig("irkickrc");
|
||
|
allActions.saveToConfig(theConfig);
|
||
|
allModes.saveToConfig(theConfig);
|
||
|
|
||
|
theConfig.sync();
|
||
|
IRKick_stub("irkick", "IRKick").reloadConfiguration();
|
||
|
|
||
|
emit changed(true);
|
||
|
}
|
||
|
|
||
|
void KCMLirc::configChanged()
|
||
|
{
|
||
|
// insert your saving code here...
|
||
|
emit changed(true);
|
||
|
}
|
||
|
|
||
|
// TODO: Take this out when I know how
|
||
|
extern "C"
|
||
|
{
|
||
12 years ago
|
KDE_EXPORT TDECModule *create_kcmlirc(TQWidget *parent, const char *)
|
||
12 years ago
|
{ TDEGlobal::locale()->insertCatalogue("kcmlirc");
|
||
13 years ago
|
return new KCMLirc(parent, "KCMLirc");
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
#include <irkick_stub.cpp>
|
||
|
|
||
|
#include "kcmlirc.moc"
|