diff options
Diffstat (limited to 'kdelirc/kdelirc')
-rw-r--r-- | kdelirc/kdelirc/Makefile.am | 45 | ||||
-rw-r--r-- | kdelirc/kdelirc/arguments.cpp | 36 | ||||
-rw-r--r-- | kdelirc/kdelirc/arguments.h | 32 | ||||
-rw-r--r-- | kdelirc/kdelirc/iraction.cpp | 155 | ||||
-rw-r--r-- | kdelirc/kdelirc/iraction.h | 88 | ||||
-rw-r--r-- | kdelirc/kdelirc/iractions.cpp | 90 | ||||
-rw-r--r-- | kdelirc/kdelirc/iractions.h | 52 | ||||
-rw-r--r-- | kdelirc/kdelirc/mode.cpp | 51 | ||||
-rw-r--r-- | kdelirc/kdelirc/mode.h | 50 | ||||
-rw-r--r-- | kdelirc/kdelirc/modes.cpp | 128 | ||||
-rw-r--r-- | kdelirc/kdelirc/modes.h | 62 | ||||
-rw-r--r-- | kdelirc/kdelirc/profileserver.cpp | 159 | ||||
-rw-r--r-- | kdelirc/kdelirc/profileserver.h | 142 | ||||
-rw-r--r-- | kdelirc/kdelirc/prototype.cpp | 67 | ||||
-rw-r--r-- | kdelirc/kdelirc/prototype.h | 54 | ||||
-rw-r--r-- | kdelirc/kdelirc/remoteserver.cpp | 109 | ||||
-rw-r--r-- | kdelirc/kdelirc/remoteserver.h | 89 |
17 files changed, 1409 insertions, 0 deletions
diff --git a/kdelirc/kdelirc/Makefile.am b/kdelirc/kdelirc/Makefile.am new file mode 100644 index 0000000..ccbe9e4 --- /dev/null +++ b/kdelirc/kdelirc/Makefile.am @@ -0,0 +1,45 @@ +####### kdevelop will overwrite this part!!! (begin)########## +noinst_LTLIBRARIES = libkdelirc.la + +noinst_HEADERS = iraction.h arguments.h iractions.h prototype.h modes.h mode.h profileserver.h remoteserver.h + +libkdelirc_la_SOURCES = iraction.cpp arguments.cpp iractions.cpp prototype.cpp modes.cpp mode.cpp profileserver.cpp remoteserver.cpp +libkdelirc_la_LIBADD = $(LIB_QT) $(LIB_KDECORE) $(LIB_KDEUI) $(LIBSOCKET) + +####### kdevelop will overwrite this part!!! (end)############ +# These paths are KDE 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/KDE 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 KDE +INCLUDES = $(all_includes) + +METASOURCES = AUTO + +# the library search path. +libkdelirc_la_LDFLAGS = $(all_libraries) $(KDE_RPATH) + +# 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)/kdelirc.pot diff --git a/kdelirc/kdelirc/arguments.cpp b/kdelirc/kdelirc/arguments.cpp new file mode 100644 index 0000000..10fc69b --- /dev/null +++ b/kdelirc/kdelirc/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 <qstring.h> + +#include "arguments.h" + +Arguments::Arguments() +{ +} + +Arguments::~Arguments() +{ +} + +const QString Arguments::toString() const +{ + QString ret = ""; + for(Arguments::const_iterator i = begin(); i != end(); ++i) + { QString s = (*i).toString(); + if(s.isNull()) s = "..."; + if(i != begin()) ret += ", "; + ret += s; + } + return ret; +} + diff --git a/kdelirc/kdelirc/arguments.h b/kdelirc/kdelirc/arguments.h new file mode 100644 index 0000000..97448a5 --- /dev/null +++ b/kdelirc/kdelirc/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 <qvaluelist.h> +#include <qvariant.h> + +/** +@author Gav Wood +*/ + +class Arguments : public QValueList<QVariant> +{ +public: + const QString toString() const; + + Arguments(); + ~Arguments(); +}; + +#endif diff --git a/kdelirc/kdelirc/iraction.cpp b/kdelirc/kdelirc/iraction.cpp new file mode 100644 index 0000000..9081a2e --- /dev/null +++ b/kdelirc/kdelirc/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 <qvariant.h> + +#include <kconfig.h> +#include <klocale.h> + +#include "iraction.h" +#include "profileserver.h" +#include "remoteserver.h" + +IRAction::IRAction(const QString &newProgram, const QString &newObject, const QString &newMethod, const Arguments &newArguments, const QString &newRemote, const QString &newMode, const QString &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(KConfig &theConfig, int index) +{ + QString Binding = "Binding" + QString().setNum(index); + int numArguments = theConfig.readNumEntry(Binding + "Arguments"); + theArguments.clear(); + for(int j = 0; j < numArguments; j++) + { QVariant::Type theType = (QVariant::Type)theConfig.readNumEntry(Binding + "ArgumentType" + QString().setNum(j), QVariant::String); + theArguments += theConfig.readPropertyEntry(Binding + "Argument" + QString().setNum(j), theType == QVariant::CString ? QVariant::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(KConfig &theConfig, int index) const +{ + QString Binding = "Binding" + QString().setNum(index); + + theConfig.writeEntry(Binding + "Arguments", theArguments.count()); + for(unsigned j = 0; j < theArguments.count(); j++) + { QVariant arg = theArguments[j]; + QVariant::Type preType = arg.type(); + if(preType == QVariant::CString) arg.cast(QVariant::String); + theConfig.writeEntry(Binding + "Argument" + QString().setNum(j), arg); + theConfig.writeEntry(Binding + "ArgumentType" + QString().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 QString 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 QString IRAction::notes() const +{ + + if(isModeChange()) + return QString(theDoBefore ? i18n("Do actions before. ") : "") + + QString(theDoAfter ? i18n("Do actions after. ") : ""); + else if(isJustStart()) + return ""; + else + return QString(theAutoStart ? i18n("Auto-start. ") : "") + + QString(theRepeat ? i18n("Repeatable. ") : "") + + QString(!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 QString 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 QString IRAction::remoteName() const +{ + return RemoteServer::remoteServer()->getRemoteName(theRemote); +} + +const QString IRAction::buttonName() const +{ + return RemoteServer::remoteServer()->getButtonName(theRemote, theButton); +} + diff --git a/kdelirc/kdelirc/iraction.h b/kdelirc/kdelirc/iraction.h new file mode 100644 index 0000000..f7008ff --- /dev/null +++ b/kdelirc/kdelirc/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 <qstring.h> + +#include "prototype.h" +#include "arguments.h" +#include "profileserver.h" + +/** +@author Gav Wood +*/ + +class KConfig; + +class IRAction +{ + QString 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(KConfig &theConfig, int index); + void saveToConfig(KConfig &theConfig, int index) const; + + // may be changed to a profile-based representation in the future. + const QString function() const; + const QString application() const; + const QString buttonName() const; + const QString remoteName() const; + const QString notes() const; + + // bog standard raw DCOP stuff + const QString &program() const { return theProgram; } + const QString &object() const { return theObject; } + const Prototype &method() const { return theMethod; } + const QString &remote() const { return theRemote; } + const QString &mode() const { return theMode; } + const QString &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 QString &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 QString &newProgram) { theProgram = newProgram; } + void setObject(const QString &newObject) { theObject = newObject; } + void setMethod(const Prototype &newMethod) { theMethod = newMethod; } + void setRemote(const QString &newRemote) { theRemote = newRemote; } + void setMode(const QString &newMode) { theMode = newMode; } + void setButton(const QString &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 QString &a) { theObject = a; } + void setIfMulti(const IfMulti a) { theIfMulti = a; } + void setUnique(const bool a) { theUnique = a; } + + IRAction(const QString &newProgram, const QString &newObject, const QString &newMethod, const Arguments &newArguments, const QString &newRemote, const QString &newMode, const QString &newButton, const bool newRepeat, const bool newAutoStart, const bool newDoBefore, const bool newDoAfter, const bool newUnique, const IfMulti newIfMulti); + IRAction() { theProgram = QString::null; } +}; + +#endif diff --git a/kdelirc/kdelirc/iractions.cpp b/kdelirc/kdelirc/iractions.cpp new file mode 100644 index 0000000..9bc03e3 --- /dev/null +++ b/kdelirc/kdelirc/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 <kconfig.h> +#include <kdebug.h> + +#include "iractions.h" +#include "iraction.h" + +void IRActions::loadFromConfig(KConfig &theConfig) +{ + clear(); + int numBindings = theConfig.readNumEntry("Bindings"); + for(int i = 0; i < numBindings; i++) + addAction(IRAction().loadFromConfig(theConfig, i)); +} + +void IRActions::purgeAllBindings(KConfig &theConfig) +{ + int numBindings = theConfig.readNumEntry("Bindings"); + for(int i = 0; i < numBindings; i++) + { QString Binding = "Binding" + QString().setNum(i); + int numArguments = theConfig.readNumEntry(Binding + "Arguments"); + for(int j = 0; j < numArguments; j++) + { theConfig.deleteEntry(Binding + "Argument" + QString().setNum(j)); + theConfig.deleteEntry(Binding + "ArgumentType" + QString().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(KConfig &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 QString &remote, const QString &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 QString &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 QString &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/kdelirc/kdelirc/iractions.h b/kdelirc/kdelirc/iractions.h new file mode 100644 index 0000000..24174d9 --- /dev/null +++ b/kdelirc/kdelirc/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 <qvaluelist.h> +#include <qpair.h> +#include <qstring.h> +#include <qmap.h> + +#include "iraction.h" +#include "mode.h" + +/** +@author Gav Wood +*/ + +class KConfig; + +typedef QValueListIterator<IRAction> IRAIt; +typedef QValueList<IRAIt> IRAItList; + +class IRActions: protected QValueList<IRAction> +{ +private: + void purgeAllBindings(KConfig &theConfig); + +public: + IRAIt addAction(const IRAction &theAction); + IRAItList findByButton(const QString &remote, const QString &button); + IRAItList findByMode(const Mode &mode); + IRAItList findByModeButton(const Mode &mode, const QString &button); + + void erase(const IRAIt &action) { QValueList<IRAction>::erase(action); } + void renameMode(const Mode &mode, const QString &to); + + void loadFromConfig(KConfig &theConfig); + void saveToConfig(KConfig &theConfig); +}; + + +#endif diff --git a/kdelirc/kdelirc/mode.cpp b/kdelirc/kdelirc/mode.cpp new file mode 100644 index 0000000..1f4c34a --- /dev/null +++ b/kdelirc/kdelirc/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 <kconfig.h> + +#include "modes.h" +#include "mode.h" + +Mode::Mode() : theName(QString::null) +{ +} + +Mode::Mode(const QString &remote, const QString &name, const QString &iconFile) +{ + theRemote = remote; + theName = name; + theIconFile = iconFile; +} + +Mode::~Mode() +{ +} + +const Mode &Mode::loadFromConfig(KConfig &theConfig, int index) +{ + QString Prefix = "Mode" + QString().setNum(index); + theName = theConfig.readEntry(Prefix + "Name"); + theRemote = theConfig.readEntry(Prefix + "Remote"); + theIconFile = theConfig.readEntry(Prefix + "IconFile"); + if(theIconFile.isEmpty()) theIconFile = QString::null; + return *this; +} + +void Mode::saveToConfig(KConfig &theConfig, int index) +{ + QString Prefix = "Mode" + QString().setNum(index); + theConfig.writeEntry(Prefix + "Name", theName); + theConfig.writeEntry(Prefix + "Remote", theRemote); + theConfig.writeEntry(Prefix + "IconFile", theIconFile); +} + diff --git a/kdelirc/kdelirc/mode.h b/kdelirc/kdelirc/mode.h new file mode 100644 index 0000000..e52c042 --- /dev/null +++ b/kdelirc/kdelirc/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 <qstring.h> + +#include "remoteserver.h" + +/** +@author Gav Wood +*/ + +class KConfig; + +class Mode +{ + QString theName, theRemote, theIconFile; + +public: + void setName(const QString &a) { theName = a; } + void setRemote(const QString &a) { theRemote = a; } + void setIconFile(const QString &a) { theIconFile = a; } + + const QString &name() const { return theName; } + const QString &remote() const { return theRemote; } + const QString &iconFile() const { return theIconFile; } + const QString &remoteName() const { return RemoteServer::remoteServer()->getRemoteName(theRemote); } + + const Mode &loadFromConfig(KConfig &theConfig, int index); + void saveToConfig(KConfig &theConfig, int index); + + bool operator==(const Mode &mode) const { return mode.theName == theName && mode.theRemote == theRemote; } + + Mode(); + Mode(const QString &remote, const QString &name, const QString &iconFile = QString::null); + ~Mode(); +}; + +#endif diff --git a/kdelirc/kdelirc/modes.cpp b/kdelirc/kdelirc/modes.cpp new file mode 100644 index 0000000..1b60647 --- /dev/null +++ b/kdelirc/kdelirc/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 <kconfig.h> +#include <kdebug.h> + +#include "modes.h" +#include "mode.h" + +Modes::Modes() +{ +} + + +Modes::~Modes() +{ +} + +void Modes::loadFromConfig(KConfig &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 QStringList &theRemotes) +{ + for(QStringList::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 QString &remote) const +{ +// if(theDefaults[remote] == QString()) +// 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(KConfig &theConfig) +{ + int numModes = theConfig.readNumEntry("Modes"); + for(int i = 0; i < numModes; i++) + { QString Prefix = "Mode" + QString().setNum(i); + theConfig.deleteEntry(Prefix + "Name"); + theConfig.deleteEntry(Prefix + "Remote"); + } +} + +void Modes::saveToConfig(KConfig &theConfig) +{ + int index = 0; + purgeAllModes(theConfig); + for(iterator i = begin(); i != end(); ++i) + for(QMap<QString, 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()] == QString()) + theConfig.writeEntry("Default" + i.key(), ""); + else + theConfig.writeEntry("Default" + i.key(), theDefaults[i.key()]); +} + +const Mode &Modes::getMode(const QString &remote, const QString &mode) const +{ + return operator[](remote)[mode]; +} + +ModeList Modes::getModes(const QString &remote) const +{ + ModeList ret; + for(QMap<QString, 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 QString name) +{ + bool was = isDefault(mode); + erase(mode); + mode.setName(name); + if(was) setDefault(mode); + add(mode); +} + diff --git a/kdelirc/kdelirc/modes.h b/kdelirc/kdelirc/modes.h new file mode 100644 index 0000000..9eabd4b --- /dev/null +++ b/kdelirc/kdelirc/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 <qstring.h> +#include <qmap.h> +#include <qpair.h> +#include <qvaluelist.h> + +#include "mode.h" + +/** +@author Gav Wood +*/ + +class KConfig; + +typedef QValueList<Mode> ModeList; + +class Modes : protected QMap<QString, QMap<QString, Mode> > +{ + void purgeAllModes(KConfig &theConfig); + QMap<QString, QString> theDefaults; + +public: + void loadFromConfig(KConfig &theConfig); + void saveToConfig(KConfig &theConfig); + void generateNulls(const QStringList &theRemotes); + + const Mode &getMode(const QString &remote, const QString &mode) const; + ModeList getModes(const QString &remote) const; + const Mode getDefault(const QString &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 QString name); + + Modes(); + ~Modes(); +}; + +#endif diff --git a/kdelirc/kdelirc/profileserver.cpp b/kdelirc/kdelirc/profileserver.cpp new file mode 100644 index 0000000..484deac --- /dev/null +++ b/kdelirc/kdelirc/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 <qfile.h> +#include <qxml.h> + +#include <kglobal.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() +{ + QStringList theFiles = KGlobal::dirs()->findAllResources("data", "profiles/*.profile.xml"); + for(QStringList::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 QString &c) const +{ + for(QDictIterator<ProfileAction> i(theActions); i.current(); ++i) + if(i.current()->getClass() == c) return i; + return 0; +} + +void Profile::loadFromFile(const QString &fileName) +{ + charBuffer = ""; + curPA = 0; + curPAA = 0; + + QFile xmlFile(fileName); + QXmlInputSource source(&xmlFile); + QXmlSimpleReader reader; + reader.setContentHandler(this); + reader.parse(source); +} + +const ProfileAction *ProfileServer::getAction(const QString &appId, const QString &actionId) const +{ + if(theProfiles[appId]) + if(theProfiles[appId]->theActions[actionId]) + return theProfiles[appId]->theActions[actionId]; + return 0; +} + +const QString &ProfileServer::getServiceName(const QString &appId) const +{ + if(theProfiles[appId]) + return theProfiles[appId]->serviceName(); + return QString::null; +} + +const ProfileAction *ProfileServer::getAction(const QString &appId, const QString &objId, const QString &prototype) const +{ + return getAction(appId, objId + "::" + prototype); +} + +bool Profile::characters(const QString &data) +{ + charBuffer += data; + return true; +} + +bool Profile::startElement(const QString &, const QString &, const QString &name, const QXmlAttributes &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(qMakePair(attributes.value("min").toInt(), attributes.value("max").toInt())); + + charBuffer = ""; + return true; +} + +bool Profile::endElement(const QString &, const QString &, const QString &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/kdelirc/kdelirc/profileserver.h b/kdelirc/kdelirc/profileserver.h new file mode 100644 index 0000000..f906dd0 --- /dev/null +++ b/kdelirc/kdelirc/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 <qpair.h> +#include <qstring.h> +#include <qvaluelist.h> +#include <qmap.h> +#include <qxml.h> +#include <qdict.h> + +/** +@author Gav Wood +*/ + +enum IfMulti {IM_DONTSEND, IM_SENDTOALL, IM_SENDTOTOP, IM_SENDTOBOTTOM}; + +typedef QPair<int,int> Range; + +class ProfileAction; +class Profile; + +class ProfileActionArgument +{ + QString theComment, theType; + Range theRange; + QString theDefault; // should be QVariant? + const ProfileAction *parent; + + friend class Profile; +public: + const QString &comment() const { return theComment; } + void setComment(const QString &a) { theComment = a; } + const QString &type() const { return theType; } + void setType(const QString &a) { theType = a; } + const QString &getDefault() const { return theDefault; } + void setDefault(const QString &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 +{ + QString theObjId, thePrototype, theName, theComment, theClass; + float theMultiplier; + const Profile *parent; + bool theRepeat, theAutoStart; + QValueList<ProfileActionArgument> theArguments; + + friend class Profile; +public: + const QString &objId() const { return theObjId; } + void setObjId(const QString &a) { theObjId = a; } + const QString &prototype() const { return thePrototype; } + void setPrototype(const QString &a) { thePrototype = a; } + const QString &name() const { return theName; } + void setName(const QString &a) { theName = a; } + const QString &comment() const { return theComment; } + void setComment(const QString &a) { theComment = a; } + const QString &getClass() const { return theClass; } + void setClass(const QString &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 QValueList<ProfileActionArgument> &arguments() const { return theArguments; } + + const Profile *profile() const { return parent; } + void setProfile(const Profile *a) { parent = a; } +}; + +class Profile : public QXmlDefaultHandler +{ + QString theId, theName, theAuthor, theServiceName; + IfMulti theIfMulti; + bool theUnique; + QString charBuffer; + + ProfileAction *curPA; + ProfileActionArgument *curPAA; + QDict<ProfileAction> theActions; // objid+"::"+prototype => ProfileAction + + friend class ProfileServer; +public: + bool characters(const QString &data); + bool startElement(const QString &, const QString &, const QString &name, const QXmlAttributes &attributes); + bool endElement(const QString &, const QString &, const QString &name); + + const QString &id() const { return theId; } + void setId(const QString &a) { theId = a; } + const QString &name() const { return theName; } + void setName(const QString &a) { theName = a; } + const QString &author() const { return theAuthor; } + void setAuthor(const QString &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 QString &serviceName() const { if(theServiceName != QString::null) return theServiceName; return theName; } + void setServiceName(const QString &a) { theServiceName = a; } + const QDict<ProfileAction> &actions() const { return theActions; } + const ProfileAction *searchClass(const QString &c) const; + + void loadFromFile(const QString &fileName); + + Profile(); +}; + +class ProfileServer +{ + static ProfileServer *theInstance; + void loadProfiles(); + QDict<Profile> theProfiles; // id => Profile + +public: + static ProfileServer *profileServer() { if(!theInstance) theInstance = new ProfileServer(); return theInstance; } + const QDict<Profile> profiles() const { return theProfiles; } + const ProfileAction *getAction(const QString &appId, const QString &objId, const QString &prototype) const; + const ProfileAction *getAction(const QString &appId, const QString &actionId) const; + const QString &getServiceName(const QString &appId) const; + + ProfileServer(); + ~ProfileServer(); +}; + +#endif diff --git a/kdelirc/kdelirc/prototype.cpp b/kdelirc/kdelirc/prototype.cpp new file mode 100644 index 0000000..9b0a09b --- /dev/null +++ b/kdelirc/kdelirc/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 <qregexp.h> + +#include "prototype.h" + +Prototype::Prototype() +{ + original = ""; +} + +Prototype::Prototype(const QString &source) +{ + original = source; + parse(); +} + +Prototype::~Prototype() +{ +} + +const QString Prototype::argumentList() const +{ + QString ret = ""; + for(unsigned i = 0; i < theTypes.count(); i++) + ret += (i ? ", " : "") + theTypes[i] + " " + theNames[i]; + return ret; +} + +const QString Prototype::argumentListNN() const +{ + QString ret = ""; + for(unsigned i = 0; i < theTypes.count(); i++) + ret += (i ? ", " : "") + theTypes[i]; + return ret; +} + +void Prototype::parse() +{ + theNames.clear(); + theTypes.clear(); + + QRegExp main("^(.*) (\\w[\\d\\w]*)\\((.*)\\)"); + QRegExp parameters("^\\s*([^,\\s]+)(\\s+(\\w[\\d\\w]*))?(,(.*))?$"); + + if(main.search(original) == -1) return; + theReturn = main.cap(1); + theName = main.cap(2); + + QString args = main.cap(3); + while(parameters.search(args) != -1) + { theTypes += parameters.cap(1); + theNames += parameters.cap(3); + args = parameters.cap(5); + } +} + diff --git a/kdelirc/kdelirc/prototype.h b/kdelirc/kdelirc/prototype.h new file mode 100644 index 0000000..22c1123 --- /dev/null +++ b/kdelirc/kdelirc/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 <qstringlist.h> +#include <qpair.h> +#include <qstring.h> + +/** +@author Gav Wood +*/ + +class Prototype +{ + QString original, theName, theReturn; + QStringList theNames, theTypes; + + void parse(); + +public: + unsigned count() const{ return theTypes.count(); } + const QPair<QString, QString> operator[](int i) const { return qMakePair(theTypes[i], theNames[i]); } + const QString &name(int i) const { return theNames[i]; } + const QString &type(int i) const { return theTypes[i]; } + const QString &returnType() const { return theReturn; } + const QString &name() const { return theName; } + const QString &prototype() const { return original; } + const QString argumentList() const; + const QString argumentListNN() const; + const int argumentCount() { return theTypes.count(); } + const QString prototypeNR() const { return theName + "(" + argumentListNN() + ")"; } + + void setPrototype(const QString &source) { original = source; parse(); } + + Prototype &operator=(const QString &source) { setPrototype(source); return *this; } + + Prototype(const QString &source); + Prototype(); + ~Prototype(); + +}; + +#endif diff --git a/kdelirc/kdelirc/remoteserver.cpp b/kdelirc/kdelirc/remoteserver.cpp new file mode 100644 index 0000000..25d8f44 --- /dev/null +++ b/kdelirc/kdelirc/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 <qfile.h> +#include <qxml.h> + +#include <kglobal.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() +{ + QStringList theFiles = KGlobal::dirs()->findAllResources("data", "remotes/*.remote.xml"); + for(QStringList::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 QString &fileName) +{ + charBuffer = ""; + curRB = 0; + + QFile xmlFile(fileName); + QXmlInputSource source(&xmlFile); + QXmlSimpleReader reader; + reader.setContentHandler(this); + reader.parse(source); +} + +bool Remote::characters(const QString &data) +{ + charBuffer += data; + return true; +} + +bool Remote::startElement(const QString &, const QString &, const QString &name, const QXmlAttributes &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 QString &, const QString &, const QString &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/kdelirc/kdelirc/remoteserver.h b/kdelirc/kdelirc/remoteserver.h new file mode 100644 index 0000000..3700acd --- /dev/null +++ b/kdelirc/kdelirc/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 <qstring.h> +#include <qxml.h> +#include <qdict.h> + +/** +@author Gav Wood +*/ + + +class RemoteButton +{ + QString theName, theId, theClass, theParameter; + + friend class Remote; +public: + void setName(const QString &a) { theName = a; } + const QString &name(void) const { return theName; } + void setClass(const QString &a) { theClass = a; } + const QString &getClass(void) const { return theClass; } + void setParameter(const QString &a) { theParameter = a; } + const QString ¶meter(void) const { return theParameter; } + void setId(const QString &a) { theId = a; } + const QString &id(void) const { return theId; } +}; + +class Remote : public QXmlDefaultHandler +{ + QString theName, theId, theAuthor; + QDict<RemoteButton> theButtons; + + QString charBuffer; + RemoteButton *curRB; + + friend class RemoteServer; +public: + bool characters(const QString &data); + bool startElement(const QString &, const QString &, const QString &name, const QXmlAttributes &attributes); + bool endElement(const QString &, const QString &, const QString &name); + + void setName(const QString &a) { theName = a; } + const QString &name(void) const { return theName; } + void setId(const QString &a) { theId = a; } + const QString &id(void) const { return theId; } + void setAuthor(const QString &a) { theAuthor = a; } + const QString &author(void) const { return theAuthor; } + const QDict<RemoteButton> &buttons() const { return theButtons; } + + void loadFromFile(const QString &fileName); + + const QString &getButtonName(const QString &id) const { if(theButtons[id]) return theButtons[id]->name(); return id; } + + Remote(); + ~Remote(); +}; + +class RemoteServer +{ + static RemoteServer *theInstance; + void loadRemotes(); + QDict<Remote> theRemotes; + +public: + static RemoteServer *remoteServer() { if(!theInstance) theInstance = new RemoteServer(); return theInstance; } + + const QDict<Remote> &remotes() const { return theRemotes; } + + const QString &getRemoteName(const QString &id) const { if(theRemotes[id]) return theRemotes[id]->name(); return id; } + const QString &getButtonName(const QString &remote, const QString &button) const { if(theRemotes[remote]) return theRemotes[remote]->getButtonName(button); return button; } + + RemoteServer(); + ~RemoteServer(); +}; + +#endif |