From kde-commits Thu Jul 01 13:27:33 2010 From: Gary Cramblitt Date: Thu, 01 Jul 2010 13:27:33 +0000 To: kde-commits Subject: [Konversation] f72c995: Added /prefs irc command for setting Message-Id: <20100701132733.E349FBB5647 () projects ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=127800422529255 commit f72c995291742a1e39081c629833bdd13cb60820 Author: Gary Cramblitt Date: Sat Jun 19 20:18:58 2004 +0000 Added /prefs irc command for setting preferences without settings dialog. svn path=/trunk/kdeextragear-2/konversation/; revision=322019 diff --git a/konversation/outputfilter.cpp b/konversation/outputfilter.cpp index b3512db..f52101c 100644 --- a/konversation/outputfilter.cpp +++ b/konversation/outputfilter.cpp @@ -16,10 +16,14 @@ #include #include #include +#include +#include #include #include #include +#include +#include #include "outputfilter.h" #include "konversationapplication.h" @@ -164,6 +168,8 @@ QString& OutputFilter::parse(const QString& myNick,const QString& originalLine,c else if(line.startsWith("amsg ")) parseAmsg(parameter); else if(line.startsWith("server ")) parseServer(parameter); + + else if(line.startsWith("prefs ")) parsePrefs(parameter); else if(line=="join") parseJoin(QString::null); else if(line=="part") parsePart(QString::null); @@ -194,6 +200,8 @@ QString& OutputFilter::parse(const QString& myNick,const QString& originalLine,c else if(line == "server") parseServer(QString::null); + else if(line == "prefs") parsePrefs(QString::null); + // Forward unknown commands to server else toServer=inputLine.mid(1); } @@ -1024,4 +1032,89 @@ void OutputFilter::parseServer(const QString& parameter) output=QString::null; } +void OutputFilter::parsePrefs(const QString& parameter) +{ + bool showUsage = false; + if (parameter.isEmpty()) + showUsage = true; + else + { + KConfig* config=KApplication::kApplication()->config(); + + QStringList splitted = KShell::splitArgs(parameter); + if (splitted.count() > 0) + { + QString group = splitted[0]; + QStringList groupList(config->groupList()); + uint i; + if (group.lower() == "list") + { + // List available groups. + usage(i18n("Available Preference Groups: ") + groupList.join("|")); + } + else + { + // Validate group. + bool validGroup = false; + for (i = 0; i < groupList.count(); ++i) + { + if (group.lower() == groupList[i].lower()) + { + validGroup = true; + group = groupList[i]; + break; + } + } + if (validGroup and splitted.count() > 1) + { + QString option = splitted[1]; + QMap options = config->entryMap(group); + QValueList optionList = options.keys(); + QValueList optionValueList = options.values(); + if (option.lower() == "list") + { + // List available options in group. + output=i18n("Available Options in Group ") + group + ": "; + for (i = 0; i < optionList.count(); ++i) + { + output = output + optionList[i] + "(" + optionValueList[i] + ")|"; + } + usage(output); + } + else + { + // Validate option. + bool validOption = false; + for (i = 0; i < optionList.count(); ++i) + { + if (option.lower() == optionList[i].lower()) + { + validOption = true; + option = optionList[i]; + break; + } + } + if (validOption) + { + if (splitted.count() > 2) + { + // Set the desired option. + config->setGroup(group); + config->writeEntry(option, splitted[2]); + config->sync(); + // Reload preferences object. + dynamic_cast(kapp)->readOptions(); + } + // If no value given, just display current value. + else usage(group + "/" + option + " = " + options[option]); + } else showUsage = true; + } + } else showUsage = true; + } + } else showUsage = true; + } + if (showUsage) + usage(i18n("Usage: %1PREFS group option value or %2PREFS LIST to list groups or %3PREFS group LIST to list options in group. Quote parameters if they contain spaces.").arg(commandChar, commandChar, commandChar)); +} + #include "outputfilter.moc" diff --git a/konversation/outputfilter.h b/konversation/outputfilter.h index 9a2fc7c..bd3b315 100644 --- a/konversation/outputfilter.h +++ b/konversation/outputfilter.h @@ -129,6 +129,7 @@ class OutputFilter : public QObject void parseAaway(const QString& parameter); void parseAme(const QString& parameter); void parseAmsg(const QString& parameter); + void parsePrefs(const QString& parameter); void changeMode(const QString& parameter,char mode,char giveTake); bool isAChannel(const QString& check);