summaryrefslogtreecommitdiffstats
path: root/tdelirc/tdelirc
diff options
context:
space:
mode:
Diffstat (limited to 'tdelirc/tdelirc')
-rw-r--r--tdelirc/tdelirc/CMakeLists.txt32
-rw-r--r--tdelirc/tdelirc/Makefile.am45
-rw-r--r--tdelirc/tdelirc/arguments.cpp36
-rw-r--r--tdelirc/tdelirc/arguments.h32
-rw-r--r--tdelirc/tdelirc/iraction.cpp155
-rw-r--r--tdelirc/tdelirc/iraction.h88
-rw-r--r--tdelirc/tdelirc/iractions.cpp90
-rw-r--r--tdelirc/tdelirc/iractions.h52
-rw-r--r--tdelirc/tdelirc/mode.cpp51
-rw-r--r--tdelirc/tdelirc/mode.h50
-rw-r--r--tdelirc/tdelirc/modes.cpp128
-rw-r--r--tdelirc/tdelirc/modes.h62
-rw-r--r--tdelirc/tdelirc/profileserver.cpp159
-rw-r--r--tdelirc/tdelirc/profileserver.h142
-rw-r--r--tdelirc/tdelirc/prototype.cpp67
-rw-r--r--tdelirc/tdelirc/prototype.h54
-rw-r--r--tdelirc/tdelirc/remoteserver.cpp109
-rw-r--r--tdelirc/tdelirc/remoteserver.h89
18 files changed, 1441 insertions, 0 deletions
diff --git a/tdelirc/tdelirc/CMakeLists.txt b/tdelirc/tdelirc/CMakeLists.txt
new file mode 100644
index 0000000..2893472
--- /dev/null
+++ b/tdelirc/tdelirc/CMakeLists.txt
@@ -0,0 +1,32 @@
+#################################################
+#
+# (C) 2012 Golubev Alexander
+# fatzer2 (AT) gmail.com
+#
+# Improvements and feedback are welcome
+#
+# This file is released under GPL >= 2
+#
+#################################################
+
+include_directories(
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${TDE_INCLUDE_DIR}
+ ${TQT_INCLUDE_DIRS}
+)
+
+link_directories(
+ ${TQT_LIBRARY_DIRS}
+)
+
+
+##### tdelirc (static) ##########################
+
+tde_add_library( tdelirc STATIC_PIC
+ SOURCES iraction.cpp arguments.cpp
+ iractions.cpp prototype.cpp modes.cpp
+ mode.cpp profileserver.cpp remoteserver.cpp
+)
+
diff --git a/tdelirc/tdelirc/Makefile.am b/tdelirc/tdelirc/Makefile.am
new file mode 100644
index 0000000..e488f85
--- /dev/null
+++ b/tdelirc/tdelirc/Makefile.am
@@ -0,0 +1,45 @@
+####### tdevelop will overwrite this part!!! (begin)##########
+noinst_LTLIBRARIES = libtdelirc.la
+
+noinst_HEADERS = iraction.h arguments.h iractions.h prototype.h modes.h mode.h profileserver.h remoteserver.h
+
+libtdelirc_la_SOURCES = iraction.cpp arguments.cpp iractions.cpp prototype.cpp modes.cpp mode.cpp profileserver.cpp remoteserver.cpp
+libtdelirc_la_LIBADD = $(LIB_QT) $(LIB_TDECORE) $(LIB_TDEUI) $(LIBSOCKET)
+
+####### tdevelop will overwrite this part!!! (end)############
+# These paths are TDE specific. Use them:
+# kde_appsdir Where your application's menu entry (.desktop) should go to.
+# kde_icondir Where your icon should go to - better use KDE_ICON.
+# kde_sounddir Where your sounds should go to.
+# kde_htmldir Where your docs should go to. (contains lang subdirs)
+# kde_datadir Where you install application data. (Use a subdir)
+# kde_locale Where translation files should go to. (contains lang subdirs)
+# kde_cgidir Where cgi-bin executables should go to.
+# kde_confdir Where config files should go to (system-wide ones with default values).
+# kde_mimedir Where mimetypes .desktop files should go to.
+# kde_servicesdir Where services .desktop files should go to.
+# kde_servicetypesdir Where servicetypes .desktop files should go to.
+# kde_toolbardir Where general toolbar icons should go to (deprecated, use KDE_ICON).
+# kde_wallpaperdir Where general wallpapers should go to.
+# kde_irkicksdir Where irkicks for the "New" menu (Konqueror/KDesktop) should go to.
+# kde_bindir Where executables should go to. Use bin_PROGRAMS or bin_SCRIPTS.
+# kde_libdir Where shared libraries should go to. Use lib_LTLIBRARIES.
+# kde_moduledir Where modules (e.g. parts) should go to. Use kde_module_LTLIBRARIES.
+# kde_styledir Where Qt/TDE widget styles should go to (new in KDE 3).
+# kde_designerdir Where Qt Designer plugins should go to (new in KDE 3).
+
+# set the include path for X, qt and TDE
+INCLUDES = $(all_includes)
+
+METASOURCES = AUTO
+
+# the library search path.
+libtdelirc_la_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_KIO) -ltdetexteditor
+
+# Uncomment the following two lines if you add a ui.rc file for your application to make use of
+# KDE´s XML GUI builing
+#rcdir = $(kde_datadir)/irkick
+#rc_DATA = irkickui.rc
+
+messages:
+ $(XGETTEXT) *.cpp *.h -o $(podir)/tdelirc.pot
diff --git a/tdelirc/tdelirc/arguments.cpp b/tdelirc/tdelirc/arguments.cpp
new file mode 100644
index 0000000..fc678ce
--- /dev/null
+++ b/tdelirc/tdelirc/arguments.cpp
@@ -0,0 +1,36 @@
+//
+//
+// C++ Implementation: $MODULE$
+//
+// Description:
+//
+//
+// Author: Gav Wood <gav@kde.org>, (C) 2003
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#include <tqstring.h>
+
+#include "arguments.h"
+
+Arguments::Arguments()
+{
+}
+
+Arguments::~Arguments()
+{
+}
+
+const TQString Arguments::toString() const
+{
+ TQString ret = "";
+ for(Arguments::const_iterator i = begin(); i != end(); ++i)
+ { TQString s = (*i).toString();
+ if(s.isNull()) s = "...";
+ if(i != begin()) ret += ", ";
+ ret += s;
+ }
+ return ret;
+}
+
diff --git a/tdelirc/tdelirc/arguments.h b/tdelirc/tdelirc/arguments.h
new file mode 100644
index 0000000..dae1f5c
--- /dev/null
+++ b/tdelirc/tdelirc/arguments.h
@@ -0,0 +1,32 @@
+//
+//
+// C++ Interface: $MODULE$
+//
+// Description:
+//
+//
+// Author: Gav Wood <gav@kde.org>, (C) 2003
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef ARGUMENTS_H
+#define ARGUMENTS_H
+
+#include <tqvaluelist.h>
+#include <tqvariant.h>
+
+/**
+@author Gav Wood
+*/
+
+class Arguments : public TQValueList<TQVariant>
+{
+public:
+ const TQString toString() const;
+
+ Arguments();
+ ~Arguments();
+};
+
+#endif
diff --git a/tdelirc/tdelirc/iraction.cpp b/tdelirc/tdelirc/iraction.cpp
new file mode 100644
index 0000000..46b581f
--- /dev/null
+++ b/tdelirc/tdelirc/iraction.cpp
@@ -0,0 +1,155 @@
+//
+//
+// C++ Implementation: $MODULE$
+//
+// Description:
+//
+//
+// Author: Gav Wood <gav@kde.org>, (C) 2003
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include <tqvariant.h>
+
+#include <tdeconfig.h>
+#include <tdelocale.h>
+
+#include "iraction.h"
+#include "profileserver.h"
+#include "remoteserver.h"
+
+IRAction::IRAction(const TQString &newProgram, const TQString &newObject, const TQString &newMethod, const Arguments &newArguments, const TQString &newRemote, const TQString &newMode, const TQString &newButton, const bool newRepeat, const bool newAutoStart, const bool newDoBefore, const bool newDoAfter, const bool newUnique, const IfMulti newIfMulti)
+{
+ theProgram = newProgram;
+ theObject = newObject;
+ theMethod = newMethod;
+ theArguments = newArguments;
+ theRemote = newRemote;
+ theMode = newMode;
+ theButton = newButton;
+ theRepeat = newRepeat;
+ theDoAfter = newDoAfter;
+ theDoBefore = newDoBefore;
+ theAutoStart = newAutoStart;
+ theUnique = newUnique;
+ theIfMulti = newIfMulti;
+}
+
+const IRAction &IRAction::loadFromConfig(TDEConfig &theConfig, int index)
+{
+ TQString Binding = "Binding" + TQString().setNum(index);
+ int numArguments = theConfig.readNumEntry(Binding + "Arguments");
+ theArguments.clear();
+ for(int j = 0; j < numArguments; j++)
+ { TQVariant::Type theType = (TQVariant::Type)theConfig.readNumEntry(Binding + "ArgumentType" + TQString().setNum(j), TQVariant::String);
+ theArguments += theConfig.readPropertyEntry(Binding + "Argument" + TQString().setNum(j), theType == TQVariant::CString ? TQVariant::String : theType);
+ theArguments.last().cast(theType);
+ }
+
+ theProgram = theConfig.readEntry(Binding + "Program");
+ theObject = theConfig.readEntry(Binding + "Object");
+ theMethod.setPrototype(theConfig.readEntry(Binding + "Method"));
+ theRemote = theConfig.readEntry(Binding + "Remote");
+ theMode = theConfig.readEntry(Binding + "Mode");
+ theButton = theConfig.readEntry(Binding + "Button");
+ theRepeat = theConfig.readBoolEntry(Binding + "Repeat");
+ theDoBefore = theConfig.readBoolEntry(Binding + "DoBefore");
+ theDoAfter = theConfig.readBoolEntry(Binding + "DoAfter");
+ theAutoStart = theConfig.readBoolEntry(Binding + "AutoStart");
+ theUnique = theConfig.readBoolEntry(Binding + "Unique", true);
+ theIfMulti = (IfMulti)theConfig.readNumEntry(Binding + "IfMulti", IM_DONTSEND);
+
+ return *this;
+}
+
+void IRAction::saveToConfig(TDEConfig &theConfig, int index) const
+{
+ TQString Binding = "Binding" + TQString().setNum(index);
+
+ theConfig.writeEntry(Binding + "Arguments", theArguments.count());
+ for(unsigned j = 0; j < theArguments.count(); j++)
+ { TQVariant arg = theArguments[j];
+ TQVariant::Type preType = arg.type();
+ if(preType == TQVariant::CString) arg.cast(TQVariant::String);
+ theConfig.writeEntry(Binding + "Argument" + TQString().setNum(j), arg);
+ theConfig.writeEntry(Binding + "ArgumentType" + TQString().setNum(j), preType);
+ }
+ theConfig.writeEntry(Binding + "Program", theProgram);
+ theConfig.writeEntry(Binding + "Object", theObject);
+ theConfig.writeEntry(Binding + "Method", theMethod.prototype());
+ theConfig.writeEntry(Binding + "Remote", theRemote);
+ theConfig.writeEntry(Binding + "Mode", theMode);
+ theConfig.writeEntry(Binding + "Button", theButton);
+ theConfig.writeEntry(Binding + "Repeat", theRepeat);
+ theConfig.writeEntry(Binding + "DoBefore", theDoBefore);
+ theConfig.writeEntry(Binding + "DoAfter", theDoAfter);
+ theConfig.writeEntry(Binding + "AutoStart", theAutoStart);
+ theConfig.writeEntry(Binding + "Unique", theUnique);
+ theConfig.writeEntry(Binding + "IfMulti", theIfMulti);
+}
+
+const TQString IRAction::function() const
+{
+ ProfileServer *theServer = ProfileServer::profileServer();
+ if(theProgram.isEmpty())
+ if(theObject.isEmpty())
+ return i18n("Exit mode");
+ else
+ return i18n("Switch to %1").arg(theObject);
+ else
+ if(theObject.isEmpty())
+ return i18n("Just start");
+ else
+ {
+ const ProfileAction *a = theServer->getAction(theProgram, theObject, theMethod.prototype());
+ if(a)
+ return a->name();
+ else
+ return theObject + "::" + theMethod.name();
+ }
+}
+
+const TQString IRAction::notes() const
+{
+
+ if(isModeChange())
+ return TQString(theDoBefore ? i18n("Do actions before. ") : "") +
+ TQString(theDoAfter ? i18n("Do actions after. ") : "");
+ else if(isJustStart())
+ return "";
+ else
+ return TQString(theAutoStart ? i18n("Auto-start. ") : "")
+ + TQString(theRepeat ? i18n("Repeatable. ") : "")
+ + TQString(!theUnique ? (theIfMulti == IM_DONTSEND ? i18n("Do nothing if many instances. ")
+ : theIfMulti == IM_SENDTOTOP ? i18n("Send to top instance. ")
+ : theIfMulti == IM_SENDTOBOTTOM ? i18n("Send to bottom instance. ") : i18n("Send to all instances. "))
+ : "");
+}
+
+const TQString IRAction::application() const
+{
+ ProfileServer *theServer = ProfileServer::profileServer();
+ if(theProgram.isEmpty())
+ return "";
+ else
+ {
+ const Profile *a = theServer->profiles()[theProgram];
+ if(a)
+ return a->name();
+ else
+ return theProgram;
+ }
+}
+
+const TQString IRAction::remoteName() const
+{
+ return RemoteServer::remoteServer()->getRemoteName(theRemote);
+}
+
+const TQString IRAction::buttonName() const
+{
+ return RemoteServer::remoteServer()->getButtonName(theRemote, theButton);
+}
+
diff --git a/tdelirc/tdelirc/iraction.h b/tdelirc/tdelirc/iraction.h
new file mode 100644
index 0000000..14d0354
--- /dev/null
+++ b/tdelirc/tdelirc/iraction.h
@@ -0,0 +1,88 @@
+//
+//
+// C++ Interface: $MODULE$
+//
+// Description:
+//
+//
+// Author: Gav Wood <gav@kde.org>, (C) 2003
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef IRACTION_H
+#define IRACTION_H
+
+#include <tqstring.h>
+
+#include "prototype.h"
+#include "arguments.h"
+#include "profileserver.h"
+
+/**
+@author Gav Wood
+*/
+
+class TDEConfig;
+
+class IRAction
+{
+ TQString theProgram, theObject, theRemote, theButton, theMode;
+ Prototype theMethod;
+ Arguments theArguments;
+ bool theRepeat, theAutoStart, theDoBefore, theDoAfter;
+ IfMulti theIfMulti;
+ bool theUnique;
+
+public:
+ // load/save convenience functions
+ const IRAction &loadFromConfig(TDEConfig &theConfig, int index);
+ void saveToConfig(TDEConfig &theConfig, int index) const;
+
+ // may be changed to a profile-based representation in the future.
+ const TQString function() const;
+ const TQString application() const;
+ const TQString buttonName() const;
+ const TQString remoteName() const;
+ const TQString notes() const;
+
+ // bog standard raw DCOP stuff
+ const TQString &program() const { return theProgram; }
+ const TQString &object() const { return theObject; }
+ const Prototype &method() const { return theMethod; }
+ const TQString &remote() const { return theRemote; }
+ const TQString &mode() const { return theMode; }
+ const TQString &button() const { return theButton; }
+ const Arguments arguments() const { if(theProgram != "" && theObject != "") return theArguments; return Arguments(); }
+ const bool repeat() const { return theRepeat; }
+ const bool autoStart() const { return theAutoStart; }
+ const IfMulti ifMulti() const { return theIfMulti; }
+ const bool unique() const { return theUnique; }
+
+ const TQString &modeChange() const { return theObject; }
+ const bool doBefore() const { return theDoBefore; }
+ const bool doAfter() const { return theDoAfter; }
+
+ bool isModeChange() const { return theProgram == ""; }
+ bool isJustStart() const { return theProgram != "" && theObject == ""; }
+
+ void setProgram(const TQString &newProgram) { theProgram = newProgram; }
+ void setObject(const TQString &newObject) { theObject = newObject; }
+ void setMethod(const Prototype &newMethod) { theMethod = newMethod; }
+ void setRemote(const TQString &newRemote) { theRemote = newRemote; }
+ void setMode(const TQString &newMode) { theMode = newMode; }
+ void setButton(const TQString &newButton) { theButton = newButton; }
+ void setArguments(const Arguments &newArguments) { theArguments = newArguments; }
+ void setRepeat(bool newRepeat) { theRepeat = newRepeat; }
+ void setDoBefore(bool a) { theDoBefore = a; }
+ void setDoAfter(bool a) { theDoAfter = a; }
+ void setAutoStart(bool newAutoStart) { theAutoStart = newAutoStart; }
+ void setModeChange(const TQString &a) { theObject = a; }
+ void setIfMulti(const IfMulti a) { theIfMulti = a; }
+ void setUnique(const bool a) { theUnique = a; }
+
+ IRAction(const TQString &newProgram, const TQString &newObject, const TQString &newMethod, const Arguments &newArguments, const TQString &newRemote, const TQString &newMode, const TQString &newButton, const bool newRepeat, const bool newAutoStart, const bool newDoBefore, const bool newDoAfter, const bool newUnique, const IfMulti newIfMulti);
+ IRAction() { theProgram = TQString(); }
+};
+
+#endif
diff --git a/tdelirc/tdelirc/iractions.cpp b/tdelirc/tdelirc/iractions.cpp
new file mode 100644
index 0000000..85d144e
--- /dev/null
+++ b/tdelirc/tdelirc/iractions.cpp
@@ -0,0 +1,90 @@
+//
+//
+// C++ Implementation: $MODULE$
+//
+// Description:
+//
+//
+// Author: Gav Wood <gav@kde.org>, (C) 2003
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#include <tdeconfig.h>
+#include <kdebug.h>
+
+#include "iractions.h"
+#include "iraction.h"
+
+void IRActions::loadFromConfig(TDEConfig &theConfig)
+{
+ clear();
+ int numBindings = theConfig.readNumEntry("Bindings");
+ for(int i = 0; i < numBindings; i++)
+ addAction(IRAction().loadFromConfig(theConfig, i));
+}
+
+void IRActions::purgeAllBindings(TDEConfig &theConfig)
+{
+ int numBindings = theConfig.readNumEntry("Bindings");
+ for(int i = 0; i < numBindings; i++)
+ { TQString Binding = "Binding" + TQString().setNum(i);
+ int numArguments = theConfig.readNumEntry(Binding + "Arguments");
+ for(int j = 0; j < numArguments; j++)
+ { theConfig.deleteEntry(Binding + "Argument" + TQString().setNum(j));
+ theConfig.deleteEntry(Binding + "ArgumentType" + TQString().setNum(j));
+ }
+ theConfig.deleteEntry(Binding + "Arguments"); theConfig.deleteEntry(Binding + "Program");
+ theConfig.deleteEntry(Binding + "Object"); theConfig.deleteEntry(Binding + "Method");
+ theConfig.deleteEntry(Binding + "Remote"); theConfig.deleteEntry(Binding + "Button");
+ theConfig.deleteEntry(Binding + "Repeat"); theConfig.deleteEntry(Binding + "Mode");
+ }
+}
+
+void IRActions::saveToConfig(TDEConfig &theConfig)
+{
+ int index = 0;
+ purgeAllBindings(theConfig);
+ for(iterator i = begin(); i != end(); ++i,index++)
+ (*i).saveToConfig(theConfig, index);
+ theConfig.writeEntry("Bindings", index);
+}
+
+IRAIt IRActions::addAction(const IRAction &theAction)
+{
+ return append(theAction);
+}
+
+IRAItList IRActions::findByButton(const TQString &remote, const TQString &button)
+{
+ IRAItList ret;
+ for(iterator i = begin(); i != end(); ++i)
+ if((*i).remote() == remote && (*i).button() == button)
+ ret += i;
+ return ret;
+}
+
+void IRActions::renameMode(const Mode &mode, const TQString &to)
+{
+ for(iterator i = begin(); i != end(); ++i)
+ { if((*i).remote() == mode.remote() && (*i).mode() == mode.name()) (*i).setMode(to);
+ if((*i).isModeChange() && (*i).modeChange() == mode.name()) (*i).setModeChange(to);
+ }
+}
+
+IRAItList IRActions::findByMode(const Mode &mode)
+{
+ IRAItList ret;
+ for(iterator i = begin(); i != end(); ++i)
+ if((*i).remote() == mode.remote() && (*i).mode() == mode.name()) ret += i;
+ return ret;
+}
+
+IRAItList IRActions::findByModeButton(const Mode &mode, const TQString &button)
+{
+ IRAItList ret;
+ for(iterator i = begin(); i != end(); ++i)
+ if((*i).remote() == mode.remote() && (*i).mode() == mode.name() && (*i).button() == button)
+ ret += i;
+ return ret;
+}
diff --git a/tdelirc/tdelirc/iractions.h b/tdelirc/tdelirc/iractions.h
new file mode 100644
index 0000000..4c44c46
--- /dev/null
+++ b/tdelirc/tdelirc/iractions.h
@@ -0,0 +1,52 @@
+//
+//
+// C++ Interface: $MODULE$
+//
+// Description:
+//
+//
+// Author: Gav Wood <gav@kde.org>, (C) 2003
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef IRACTIONS_H
+#define IRACTIONS_H
+
+#include <tqvaluelist.h>
+#include <tqpair.h>
+#include <tqstring.h>
+#include <tqmap.h>
+
+#include "iraction.h"
+#include "mode.h"
+
+/**
+@author Gav Wood
+*/
+
+class TDEConfig;
+
+typedef TQValueListIterator<IRAction> IRAIt;
+typedef TQValueList<IRAIt> IRAItList;
+
+class IRActions: protected TQValueList<IRAction>
+{
+private:
+ void purgeAllBindings(TDEConfig &theConfig);
+
+public:
+ IRAIt addAction(const IRAction &theAction);
+ IRAItList findByButton(const TQString &remote, const TQString &button);
+ IRAItList findByMode(const Mode &mode);
+ IRAItList findByModeButton(const Mode &mode, const TQString &button);
+
+ void erase(const IRAIt &action) { TQValueList<IRAction>::erase(action); }
+ void renameMode(const Mode &mode, const TQString &to);
+
+ void loadFromConfig(TDEConfig &theConfig);
+ void saveToConfig(TDEConfig &theConfig);
+};
+
+
+#endif
diff --git a/tdelirc/tdelirc/mode.cpp b/tdelirc/tdelirc/mode.cpp
new file mode 100644
index 0000000..9402573
--- /dev/null
+++ b/tdelirc/tdelirc/mode.cpp
@@ -0,0 +1,51 @@
+//
+//
+// C++ Implementation: $MODULE$
+//
+// Description:
+//
+//
+// Author: Gav Wood <gav@kde.org>, (C) 2003
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include <tdeconfig.h>
+
+#include "modes.h"
+#include "mode.h"
+
+Mode::Mode() : theName(TQString())
+{
+}
+
+Mode::Mode(const TQString &remote, const TQString &name, const TQString &iconFile)
+{
+ theRemote = remote;
+ theName = name;
+ theIconFile = iconFile;
+}
+
+Mode::~Mode()
+{
+}
+
+const Mode &Mode::loadFromConfig(TDEConfig &theConfig, int index)
+{
+ TQString Prefix = "Mode" + TQString().setNum(index);
+ theName = theConfig.readEntry(Prefix + "Name");
+ theRemote = theConfig.readEntry(Prefix + "Remote");
+ theIconFile = theConfig.readEntry(Prefix + "IconFile");
+ if(theIconFile.isEmpty()) theIconFile = TQString();
+ return *this;
+}
+
+void Mode::saveToConfig(TDEConfig &theConfig, int index)
+{
+ TQString Prefix = "Mode" + TQString().setNum(index);
+ theConfig.writeEntry(Prefix + "Name", theName);
+ theConfig.writeEntry(Prefix + "Remote", theRemote);
+ theConfig.writeEntry(Prefix + "IconFile", theIconFile);
+}
+
diff --git a/tdelirc/tdelirc/mode.h b/tdelirc/tdelirc/mode.h
new file mode 100644
index 0000000..55b7b0a
--- /dev/null
+++ b/tdelirc/tdelirc/mode.h
@@ -0,0 +1,50 @@
+//
+//
+// C++ Interface: $MODULE$
+//
+// Description:
+//
+//
+// Author: Gav Wood <gav@kde.org>, (C) 2003
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef MODE_H
+#define MODE_H
+
+#include <tqstring.h>
+
+#include "remoteserver.h"
+
+/**
+@author Gav Wood
+*/
+
+class TDEConfig;
+
+class Mode
+{
+ TQString theName, theRemote, theIconFile;
+
+public:
+ void setName(const TQString &a) { theName = a; }
+ void setRemote(const TQString &a) { theRemote = a; }
+ void setIconFile(const TQString &a) { theIconFile = a; }
+
+ const TQString &name() const { return theName; }
+ const TQString &remote() const { return theRemote; }
+ const TQString &iconFile() const { return theIconFile; }
+ const TQString &remoteName() const { return RemoteServer::remoteServer()->getRemoteName(theRemote); }
+
+ const Mode &loadFromConfig(TDEConfig &theConfig, int index);
+ void saveToConfig(TDEConfig &theConfig, int index);
+
+ bool operator==(const Mode &mode) const { return mode.theName == theName && mode.theRemote == theRemote; }
+
+ Mode();
+ Mode(const TQString &remote, const TQString &name, const TQString &iconFile = TQString());
+ ~Mode();
+};
+
+#endif
diff --git a/tdelirc/tdelirc/modes.cpp b/tdelirc/tdelirc/modes.cpp
new file mode 100644
index 0000000..8eedce0
--- /dev/null
+++ b/tdelirc/tdelirc/modes.cpp
@@ -0,0 +1,128 @@
+//
+//
+// C++ Implementation: $MODULE$
+//
+// Description:
+//
+//
+// Author: Gav Wood <gav@kde.org>, (C) 2003
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#include <tdeconfig.h>
+#include <kdebug.h>
+
+#include "modes.h"
+#include "mode.h"
+
+Modes::Modes()
+{
+}
+
+
+Modes::~Modes()
+{
+}
+
+void Modes::loadFromConfig(TDEConfig &theConfig)
+{
+ clear();
+ int numModes = theConfig.readNumEntry("Modes");
+ for(int i = 0; i < numModes; i++)
+ {
+ add(Mode().loadFromConfig(theConfig, i));
+ }
+
+ for(iterator i = begin(); i != end(); ++i)
+ theDefaults[i.key()] = theConfig.readEntry("Default" + i.key());
+}
+
+void Modes::generateNulls(const TQStringList &theRemotes)
+{
+ for(TQStringList::const_iterator i = theRemotes.begin(); i != theRemotes.end(); ++i)
+ { if(!contains(*i) || !operator[](*i).contains("")) operator[](*i)[""] = Mode(*i, "");
+ if(!theDefaults.contains(*i)) theDefaults[*i].isEmpty();
+ }
+}
+
+bool Modes::isDefault(const Mode &mode) const
+{
+ if(theDefaults[mode.remote()] == mode.name())
+ return true;
+// if(theDefaults[mode.remote()].isEmpty() || theDefaults[mode.remote()].isNull())
+// return mode.name().isEmpty();
+ return false;
+}
+
+const Mode Modes::getDefault(const TQString &remote) const
+{
+// if(theDefaults[remote] == TQString())
+// return Mode(remote, "");
+ if(contains(remote))
+ if(operator[](remote).contains(theDefaults[remote]))
+ return operator[](remote)[theDefaults[remote]];
+ else return Mode(remote, "");
+ else return Mode(remote, "");
+
+}
+
+void Modes::purgeAllModes(TDEConfig &theConfig)
+{
+ int numModes = theConfig.readNumEntry("Modes");
+ for(int i = 0; i < numModes; i++)
+ { TQString Prefix = "Mode" + TQString().setNum(i);
+ theConfig.deleteEntry(Prefix + "Name");
+ theConfig.deleteEntry(Prefix + "Remote");
+ }
+}
+
+void Modes::saveToConfig(TDEConfig &theConfig)
+{
+ int index = 0;
+ purgeAllModes(theConfig);
+ for(iterator i = begin(); i != end(); ++i)
+ for(TQMap<TQString, Mode>::iterator j = (*i).begin(); j != (*i).end(); ++j,index++)
+ (*j).saveToConfig(theConfig, index);
+ theConfig.writeEntry("Modes", index);
+
+ for(iterator i = begin(); i != end(); ++i)
+ if(theDefaults[i.key()] == TQString())
+ theConfig.writeEntry("Default" + i.key(), "");
+ else
+ theConfig.writeEntry("Default" + i.key(), theDefaults[i.key()]);
+}
+
+const Mode &Modes::getMode(const TQString &remote, const TQString &mode) const
+{
+ return operator[](remote)[mode];
+}
+
+ModeList Modes::getModes(const TQString &remote) const
+{
+ ModeList ret;
+ for(TQMap<TQString, Mode>::const_iterator i = operator[](remote).begin(); i != operator[](remote).end(); ++i)
+ ret += *i;
+ return ret;
+}
+
+void Modes::erase(const Mode &mode)
+{
+ operator[](mode.remote()).erase(mode.name());
+}
+
+void Modes::add(const Mode &mode)
+{
+ kdDebug() << "adding a mode " << mode.name() << " to remote " << mode.remote() << endl;
+ operator[](mode.remote())[mode.name()] = mode;
+}
+
+void Modes::rename(Mode &mode, const TQString name)
+{
+ bool was = isDefault(mode);
+ erase(mode);
+ mode.setName(name);
+ if(was) setDefault(mode);
+ add(mode);
+}
+
diff --git a/tdelirc/tdelirc/modes.h b/tdelirc/tdelirc/modes.h
new file mode 100644
index 0000000..d0de17a
--- /dev/null
+++ b/tdelirc/tdelirc/modes.h
@@ -0,0 +1,62 @@
+//
+//
+// C++ Interface: $MODULE$
+//
+// Description:
+//
+//
+// Author: Gav Wood <gav@kde.org>, (C) 2003
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef MODES_H
+#define MODES_H
+
+#include <tqstring.h>
+#include <tqmap.h>
+#include <tqpair.h>
+#include <tqvaluelist.h>
+
+#include "mode.h"
+
+/**
+@author Gav Wood
+*/
+
+class TDEConfig;
+
+typedef TQValueList<Mode> ModeList;
+
+class Modes : protected TQMap<TQString, TQMap<TQString, Mode> >
+{
+ void purgeAllModes(TDEConfig &theConfig);
+ TQMap<TQString, TQString> theDefaults;
+
+public:
+ void loadFromConfig(TDEConfig &theConfig);
+ void saveToConfig(TDEConfig &theConfig);
+ void generateNulls(const TQStringList &theRemotes);
+
+ const Mode &getMode(const TQString &remote, const TQString &mode) const;
+ ModeList getModes(const TQString &remote) const;
+ const Mode getDefault(const TQString &remote) const;
+ bool isDefault(const Mode &mode) const;
+
+ /**
+ * Call when you've changed a previously getMode'd mode and you want the changes
+ * to be recorded
+ **/
+ void updateMode(const Mode &mode) { operator[](mode.remote())[mode.name()] = mode; }
+ void setDefault(const Mode &mode) { theDefaults[mode.remote()] = mode.name(); }
+ void erase(const Mode &mode);
+ void add(const Mode &mode);
+
+ // dont use this without renaming all the modes in the actions!!!
+ void rename(Mode &mode, const TQString name);
+
+ Modes();
+ ~Modes();
+};
+
+#endif
diff --git a/tdelirc/tdelirc/profileserver.cpp b/tdelirc/tdelirc/profileserver.cpp
new file mode 100644
index 0000000..ba39442
--- /dev/null
+++ b/tdelirc/tdelirc/profileserver.cpp
@@ -0,0 +1,159 @@
+//
+//
+// C++ Implementation: $MODULE$
+//
+// Description:
+//
+//
+// Author: Gav Wood <gav@kde.org>, (C) 2003
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include <tqfile.h>
+#include <tqxml.h>
+
+#include <tdeglobal.h>
+#include <kstandarddirs.h>
+#include <kdebug.h>
+
+#include "profileserver.h"
+
+ProfileServer *ProfileServer::theInstance = 0;
+
+ProfileServer::ProfileServer()
+{
+ theProfiles.setAutoDelete(true);
+ loadProfiles();
+}
+
+ProfileServer::~ProfileServer()
+{
+}
+
+void ProfileServer::loadProfiles()
+{
+ TQStringList theFiles = TDEGlobal::dirs()->findAllResources("data", "profiles/*.profile.xml");
+ for(TQStringList::iterator i = theFiles.begin(); i != theFiles.end(); ++i)
+ { kdDebug() << "Found data file: " << *i << endl;
+ Profile *p = new Profile();
+ p->loadFromFile(*i);
+ theProfiles.insert(p->id(), p);
+ }
+}
+
+Profile::Profile()
+{
+ // set up defaults
+ theUnique = true;
+ theIfMulti = IM_DONTSEND;
+
+ theActions.setAutoDelete(true);
+}
+
+const ProfileAction *Profile::searchClass(const TQString &c) const
+{
+ for(TQDictIterator<ProfileAction> i(theActions); i.current(); ++i)
+ if(i.current()->getClass() == c) return i;
+ return 0;
+}
+
+void Profile::loadFromFile(const TQString &fileName)
+{
+ charBuffer = "";
+ curPA = 0;
+ curPAA = 0;
+
+ TQFile xmlFile(fileName);
+ TQXmlInputSource source(TQT_TQIODEVICE(&xmlFile));
+ TQXmlSimpleReader reader;
+ reader.setContentHandler(this);
+ reader.parse(source);
+}
+
+const ProfileAction *ProfileServer::getAction(const TQString &appId, const TQString &actionId) const
+{
+ if(theProfiles[appId])
+ if(theProfiles[appId]->theActions[actionId])
+ return theProfiles[appId]->theActions[actionId];
+ return 0;
+}
+
+const TQString &ProfileServer::getServiceName(const TQString &appId) const
+{
+ if(theProfiles[appId])
+ return theProfiles[appId]->serviceName();
+ return TQString();
+}
+
+const ProfileAction *ProfileServer::getAction(const TQString &appId, const TQString &objId, const TQString &prototype) const
+{
+ return getAction(appId, objId + "::" + prototype);
+}
+
+bool Profile::characters(const TQString &data)
+{
+ charBuffer += data;
+ return true;
+}
+
+bool Profile::startElement(const TQString &, const TQString &, const TQString &name, const TQXmlAttributes &attributes)
+{
+ if(name == "profile")
+ { theId = attributes.value("id");
+ theServiceName = attributes.value("servicename");
+ }
+ else if(name == "action")
+ { curPA = new ProfileAction;
+ curPA->setObjId(attributes.value("objid"));
+ curPA->setPrototype(attributes.value("prototype"));
+ curPA->setClass(attributes.value("class"));
+ curPA->setMultiplier(attributes.value("multiplier").isEmpty() ? 1.0 : attributes.value("multiplier").toFloat());
+ curPA->setRepeat(attributes.value("repeat") == "1");
+ curPA->setAutoStart(attributes.value("autostart") == "1");
+ }
+ else if(name == "instances")
+ { theUnique = attributes.value("unique") == "1";
+ theIfMulti = attributes.value("ifmulti") == "sendtotop" ? IM_SENDTOTOP : attributes.value("ifmulti") == "sendtobottom" ? IM_SENDTOBOTTOM : attributes.value("ifmulti") == "sendtoall" ? IM_SENDTOALL : IM_DONTSEND;
+ }
+ else if(name == "argument")
+ { curPA->theArguments.append(ProfileActionArgument());
+ curPAA = &(curPA->theArguments.last());
+ curPAA->setAction(curPA);
+ curPAA->setType(attributes.value("type"));
+ }
+ else if(name == "range" && curPAA)
+ curPAA->setRange(tqMakePair(attributes.value("min").toInt(), attributes.value("max").toInt()));
+
+ charBuffer = "";
+ return true;
+}
+
+bool Profile::endElement(const TQString &, const TQString &, const TQString &name)
+{
+ if(name == "name")
+ if(curPA)
+ curPA->setName(charBuffer);
+ else
+ theName = charBuffer;
+ else if(name == "author")
+ theAuthor = charBuffer;
+ else if(name == "comment" && curPA && !curPAA)
+ curPA->setComment(charBuffer);
+ else if(name == "default" && curPA && curPAA)
+ curPAA->setDefault(charBuffer);
+ else if(name == "comment" && curPA && curPAA)
+ curPAA->setComment(charBuffer);
+ else if(name == "action")
+ {
+ curPA->setProfile(this);
+ theActions.insert(curPA->objId() + "::" + curPA->prototype(), curPA);
+ curPA = 0;
+ }
+ else if(name == "argument")
+ curPAA = 0;
+
+ charBuffer = "";
+ return true;
+}
diff --git a/tdelirc/tdelirc/profileserver.h b/tdelirc/tdelirc/profileserver.h
new file mode 100644
index 0000000..0d9bc59
--- /dev/null
+++ b/tdelirc/tdelirc/profileserver.h
@@ -0,0 +1,142 @@
+//
+//
+// C++ Interface: $MODULE$
+//
+// Description:
+//
+//
+// Author: Gav Wood <gav@kde.org>, (C) 2003
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef PROFILESERVER_H
+#define PROFILESERVER_H
+
+#include <tqpair.h>
+#include <tqstring.h>
+#include <tqvaluelist.h>
+#include <tqmap.h>
+#include <tqxml.h>
+#include <tqdict.h>
+
+/**
+@author Gav Wood
+*/
+
+enum IfMulti {IM_DONTSEND, IM_SENDTOALL, IM_SENDTOTOP, IM_SENDTOBOTTOM};
+
+typedef TQPair<int,int> Range;
+
+class ProfileAction;
+class Profile;
+
+class ProfileActionArgument
+{
+ TQString theComment, theType;
+ Range theRange;
+ TQString theDefault; // should be TQVariant?
+ const ProfileAction *parent;
+
+ friend class Profile;
+public:
+ const TQString &comment() const { return theComment; }
+ void setComment(const TQString &a) { theComment = a; }
+ const TQString &type() const { return theType; }
+ void setType(const TQString &a) { theType = a; }
+ const TQString &getDefault() const { return theDefault; }
+ void setDefault(const TQString &a) { theDefault = a; }
+ const Range &range() const { return theRange; }
+ void setRange(const Range &a) { theRange = a; }
+
+ const ProfileAction *action() const { return parent; }
+ void setAction(const ProfileAction *a) { parent = a; }
+};
+
+class ProfileAction
+{
+ TQString theObjId, thePrototype, theName, theComment, theClass;
+ float theMultiplier;
+ const Profile *parent;
+ bool theRepeat, theAutoStart;
+ TQValueList<ProfileActionArgument> theArguments;
+
+ friend class Profile;
+public:
+ const TQString &objId() const { return theObjId; }
+ void setObjId(const TQString &a) { theObjId = a; }
+ const TQString &prototype() const { return thePrototype; }
+ void setPrototype(const TQString &a) { thePrototype = a; }
+ const TQString &name() const { return theName; }
+ void setName(const TQString &a) { theName = a; }
+ const TQString &comment() const { return theComment; }
+ void setComment(const TQString &a) { theComment = a; }
+ const TQString &getClass() const { return theClass; }
+ void setClass(const TQString &a) { theClass = a; }
+ const float multiplier() const { return theMultiplier; }
+ void setMultiplier(const float a) { theMultiplier = a; }
+ bool repeat() const { return theRepeat; }
+ void setRepeat(bool a) { theRepeat = a; }
+ bool autoStart() const { return theAutoStart; }
+ void setAutoStart(bool a) { theAutoStart = a; }
+ const TQValueList<ProfileActionArgument> &arguments() const { return theArguments; }
+
+ const Profile *profile() const { return parent; }
+ void setProfile(const Profile *a) { parent = a; }
+};
+
+class Profile : public TQXmlDefaultHandler
+{
+ TQString theId, theName, theAuthor, theServiceName;
+ IfMulti theIfMulti;
+ bool theUnique;
+ TQString charBuffer;
+
+ ProfileAction *curPA;
+ ProfileActionArgument *curPAA;
+ TQDict<ProfileAction> theActions; // objid+"::"+prototype => ProfileAction
+
+ friend class ProfileServer;
+public:
+ bool characters(const TQString &data);
+ bool startElement(const TQString &, const TQString &, const TQString &name, const TQXmlAttributes &attributes);
+ bool endElement(const TQString &, const TQString &, const TQString &name);
+
+ const TQString &id() const { return theId; }
+ void setId(const TQString &a) { theId = a; }
+ const TQString &name() const { return theName; }
+ void setName(const TQString &a) { theName = a; }
+ const TQString &author() const { return theAuthor; }
+ void setAuthor(const TQString &a) { theAuthor = a; }
+ const bool unique() const { return theUnique; }
+ void setUnique(const bool a) { theUnique = a; }
+ const IfMulti ifMulti() const { return theIfMulti; }
+ void setIfMulti(const IfMulti a) { theIfMulti = a; }
+ const TQString &serviceName() const { if(theServiceName != TQString()) return theServiceName; return theName; }
+ void setServiceName(const TQString &a) { theServiceName = a; }
+ const TQDict<ProfileAction> &actions() const { return theActions; }
+ const ProfileAction *searchClass(const TQString &c) const;
+
+ void loadFromFile(const TQString &fileName);
+
+ Profile();
+};
+
+class ProfileServer
+{
+ static ProfileServer *theInstance;
+ void loadProfiles();
+ TQDict<Profile> theProfiles; // id => Profile
+
+public:
+ static ProfileServer *profileServer() { if(!theInstance) theInstance = new ProfileServer(); return theInstance; }
+ const TQDict<Profile> profiles() const { return theProfiles; }
+ const ProfileAction *getAction(const TQString &appId, const TQString &objId, const TQString &prototype) const;
+ const ProfileAction *getAction(const TQString &appId, const TQString &actionId) const;
+ const TQString &getServiceName(const TQString &appId) const;
+
+ ProfileServer();
+ ~ProfileServer();
+};
+
+#endif
diff --git a/tdelirc/tdelirc/prototype.cpp b/tdelirc/tdelirc/prototype.cpp
new file mode 100644
index 0000000..8e2eedf
--- /dev/null
+++ b/tdelirc/tdelirc/prototype.cpp
@@ -0,0 +1,67 @@
+//
+//
+// C++ Implementation: $MODULE$
+//
+// Description:
+//
+//
+// Author: Gav Wood <gav@kde.org>, (C) 2003
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#include <tqregexp.h>
+
+#include "prototype.h"
+
+Prototype::Prototype()
+{
+ original = "";
+}
+
+Prototype::Prototype(const TQString &source)
+{
+ original = source;
+ parse();
+}
+
+Prototype::~Prototype()
+{
+}
+
+const TQString Prototype::argumentList() const
+{
+ TQString ret = "";
+ for(unsigned i = 0; i < theTypes.count(); i++)
+ ret += (i ? ", " : "") + theTypes[i] + " " + theNames[i];
+ return ret;
+}
+
+const TQString Prototype::argumentListNN() const
+{
+ TQString ret = "";
+ for(unsigned i = 0; i < theTypes.count(); i++)
+ ret += (i ? ", " : "") + theTypes[i];
+ return ret;
+}
+
+void Prototype::parse()
+{
+ theNames.clear();
+ theTypes.clear();
+
+ TQRegExp main("^(.*) (\\w[\\d\\w]*)\\((.*)\\)");
+ TQRegExp parameters("^\\s*([^,\\s]+)(\\s+(\\w[\\d\\w]*))?(,(.*))?$");
+
+ if(main.search(original) == -1) return;
+ theReturn = main.cap(1);
+ theName = main.cap(2);
+
+ TQString args = main.cap(3);
+ while(parameters.search(args) != -1)
+ { theTypes += parameters.cap(1);
+ theNames += parameters.cap(3);
+ args = parameters.cap(5);
+ }
+}
+
diff --git a/tdelirc/tdelirc/prototype.h b/tdelirc/tdelirc/prototype.h
new file mode 100644
index 0000000..fa101b7
--- /dev/null
+++ b/tdelirc/tdelirc/prototype.h
@@ -0,0 +1,54 @@
+//
+//
+// C++ Interface: $MODULE$
+//
+// Description:
+//
+//
+// Author: Gav Wood <gav@kde.org>, (C) 2003
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef PROTOTYPE_H
+#define PROTOTYPE_H
+
+#include <tqstringlist.h>
+#include <tqpair.h>
+#include <tqstring.h>
+
+/**
+@author Gav Wood
+*/
+
+class Prototype
+{
+ TQString original, theName, theReturn;
+ TQStringList theNames, theTypes;
+
+ void parse();
+
+public:
+ unsigned count() const{ return theTypes.count(); }
+ const TQPair<TQString, TQString> operator[](int i) const { return tqMakePair(theTypes[i], theNames[i]); }
+ const TQString &name(int i) const { return theNames[i]; }
+ const TQString &type(int i) const { return theTypes[i]; }
+ const TQString &returnType() const { return theReturn; }
+ const TQString &name() const { return theName; }
+ const TQString &prototype() const { return original; }
+ const TQString argumentList() const;
+ const TQString argumentListNN() const;
+ const int argumentCount() { return theTypes.count(); }
+ const TQString prototypeNR() const { return theName + "(" + argumentListNN() + ")"; }
+
+ void setPrototype(const TQString &source) { original = source; parse(); }
+
+ Prototype &operator=(const TQString &source) { setPrototype(source); return *this; }
+
+ Prototype(const TQString &source);
+ Prototype();
+ ~Prototype();
+
+};
+
+#endif
diff --git a/tdelirc/tdelirc/remoteserver.cpp b/tdelirc/tdelirc/remoteserver.cpp
new file mode 100644
index 0000000..dafa67d
--- /dev/null
+++ b/tdelirc/tdelirc/remoteserver.cpp
@@ -0,0 +1,109 @@
+//
+//
+// C++ Implementation: $MODULE$
+//
+// Description:
+//
+//
+// Author: Gav Wood <gav@kde.org>, (C) 2003
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include <tqfile.h>
+#include <tqxml.h>
+
+#include <tdeglobal.h>
+#include <kstandarddirs.h>
+#include <kdebug.h>
+
+#include "remoteserver.h"
+
+RemoteServer *RemoteServer::theInstance = 0;
+
+RemoteServer::RemoteServer()
+{
+ theRemotes.setAutoDelete(true);
+ loadRemotes();
+}
+
+RemoteServer::~RemoteServer()
+{
+}
+
+void RemoteServer::loadRemotes()
+{
+ TQStringList theFiles = TDEGlobal::dirs()->findAllResources("data", "remotes/*.remote.xml");
+ for(TQStringList::iterator i = theFiles.begin(); i != theFiles.end(); ++i)
+ { kdDebug() << "Found data file: " << *i << endl;
+ Remote *p = new Remote();
+ p->loadFromFile(*i);
+ theRemotes.insert(p->id(), p);
+ }
+}
+
+Remote::Remote()
+{
+ theButtons.setAutoDelete(true);
+}
+
+Remote::~Remote()
+{
+}
+
+void Remote::loadFromFile(const TQString &fileName)
+{
+ charBuffer = "";
+ curRB = 0;
+
+ TQFile xmlFile(fileName);
+ TQXmlInputSource source(TQT_TQIODEVICE(&xmlFile));
+ TQXmlSimpleReader reader;
+ reader.setContentHandler(this);
+ reader.parse(source);
+}
+
+bool Remote::characters(const TQString &data)
+{
+ charBuffer += data;
+ return true;
+}
+
+bool Remote::startElement(const TQString &, const TQString &, const TQString &name, const TQXmlAttributes &attributes)
+{
+ if(name == "remote")
+ theId = theName = attributes.value("id");
+ else if(name == "button")
+ {
+ curRB = new RemoteButton();
+ curRB->setId(attributes.value("id"));
+ curRB->setClass(attributes.value("id"));
+ if(attributes.index("class") > -1)
+ curRB->setClass(attributes.value("class"));
+ curRB->setParameter(attributes.value("parameter"));
+ curRB->setName(attributes.value("id"));
+ }
+
+ charBuffer = "";
+ return true;
+}
+
+bool Remote::endElement(const TQString &, const TQString &, const TQString &name)
+{
+ if(name == "name")
+ if(curRB)
+ curRB->setName(charBuffer);
+ else
+ theName = charBuffer;
+ else if(name == "author")
+ theAuthor = charBuffer;
+ else if(name == "button")
+ {
+ theButtons.insert(curRB->id(), curRB);
+ curRB = 0;
+ }
+
+ charBuffer = "";
+ return true;
+}
diff --git a/tdelirc/tdelirc/remoteserver.h b/tdelirc/tdelirc/remoteserver.h
new file mode 100644
index 0000000..80891ba
--- /dev/null
+++ b/tdelirc/tdelirc/remoteserver.h
@@ -0,0 +1,89 @@
+//
+//
+// C++ Interface: $MODULE$
+//
+// Description:
+//
+//
+// Author: Gav Wood <gav@kde.org>, (C) 2003
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef REMOTESERVER_H
+#define REMOTESERVER_H
+
+#include <tqstring.h>
+#include <tqxml.h>
+#include <tqdict.h>
+
+/**
+@author Gav Wood
+*/
+
+
+class RemoteButton
+{
+ TQString theName, theId, theClass, theParameter;
+
+ friend class Remote;
+public:
+ void setName(const TQString &a) { theName = a; }
+ const TQString &name(void) const { return theName; }
+ void setClass(const TQString &a) { theClass = a; }
+ const TQString &getClass(void) const { return theClass; }
+ void setParameter(const TQString &a) { theParameter = a; }
+ const TQString &parameter(void) const { return theParameter; }
+ void setId(const TQString &a) { theId = a; }
+ const TQString &id(void) const { return theId; }
+};
+
+class Remote : public TQXmlDefaultHandler
+{
+ TQString theName, theId, theAuthor;
+ TQDict<RemoteButton> theButtons;
+
+ TQString charBuffer;
+ RemoteButton *curRB;
+
+ friend class RemoteServer;
+public:
+ bool characters(const TQString &data);
+ bool startElement(const TQString &, const TQString &, const TQString &name, const TQXmlAttributes &attributes);
+ bool endElement(const TQString &, const TQString &, const TQString &name);
+
+ void setName(const TQString &a) { theName = a; }
+ const TQString &name(void) const { return theName; }
+ void setId(const TQString &a) { theId = a; }
+ const TQString &id(void) const { return theId; }
+ void setAuthor(const TQString &a) { theAuthor = a; }
+ const TQString &author(void) const { return theAuthor; }
+ const TQDict<RemoteButton> &buttons() const { return theButtons; }
+
+ void loadFromFile(const TQString &fileName);
+
+ const TQString &getButtonName(const TQString &id) const { if(theButtons[id]) return theButtons[id]->name(); return id; }
+
+ Remote();
+ ~Remote();
+};
+
+class RemoteServer
+{
+ static RemoteServer *theInstance;
+ void loadRemotes();
+ TQDict<Remote> theRemotes;
+
+public:
+ static RemoteServer *remoteServer() { if(!theInstance) theInstance = new RemoteServer(); return theInstance; }
+
+ const TQDict<Remote> &remotes() const { return theRemotes; }
+
+ const TQString &getRemoteName(const TQString &id) const { if(theRemotes[id]) return theRemotes[id]->name(); return id; }
+ const TQString &getButtonName(const TQString &remote, const TQString &button) const { if(theRemotes[remote]) return theRemotes[remote]->getButtonName(button); return button; }
+
+ RemoteServer();
+ ~RemoteServer();
+};
+
+#endif