summaryrefslogtreecommitdiff
path: root/resourceqt-client/client.cpp
diff options
context:
space:
mode:
authorWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-12-01 16:27:21 +0200
committerWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-12-01 16:27:21 +0200
commit78db2c0b916d68a0c4056d4be7228a606b2f9dac (patch)
treefb5c624c88b413d82c790c7f488d3e3efd862742 /resourceqt-client/client.cpp
parentc8917f1cbbf96a1c5c655d9adbd45a46833e70db (diff)
parentef6d735381083c0e90b122f6a22771c13337b8c1 (diff)
downloadlibresourceqt-78db2c0b916d68a0c4056d4be7228a606b2f9dac.tar.gz
Merge remote branch 'origin/master'
Diffstat (limited to 'resourceqt-client/client.cpp')
-rw-r--r--resourceqt-client/client.cpp152
1 files changed, 97 insertions, 55 deletions
diff --git a/resourceqt-client/client.cpp b/resourceqt-client/client.cpp
index 4cd372a..fcfe36c 100644
--- a/resourceqt-client/client.cpp
+++ b/resourceqt-client/client.cpp
@@ -60,9 +60,8 @@ Client::Client()
commandList["free"] = CommandListArgs("", "destroy and free the resources");
commandList["acquire"] = CommandListArgs("", "acquire required resources");
commandList["release"] = CommandListArgs("", "release resources");
- commandList["update"] = CommandListArgs("", "update modified resource set after add or remove command");
- commandList["add"] = CommandListArgs("reslist [-o]", "add resource list, if -o provided, set as optional");
- commandList["remove"] = CommandListArgs("reslist [-o]", "remove resource list, if -o provided, removed only optional flag");
+ commandList["update"] = CommandListArgs("update <all>[:opt] where 'all' and 'opt' are comma separated resources",
+ "update the resource set by specifying the new set");
commandList["audio"] = CommandListArgs("pid <pid> | group <audio group> | tag <name> <value>", "set audio properties");
commandList["addaudio"] = CommandListArgs("<audio group> <pid> <tag name> <tag value>", "Add an audio resource and set the properties");
commandList["show"] = CommandListArgs("", "show resources");
@@ -137,13 +136,18 @@ bool Client::initialize(const CommandLineParser &parser)
if (!connect(&stdInNotifier, SIGNAL(activated(int)), this, SLOT(readLine(int)))) {
return false;
}
+ if (!connect(resourceSet , SIGNAL(connectedToManager()), this, SLOT(stopConnectTimerHandler()))) {
+ return false;
+ }
if (!connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()),
this, SLOT(doExit()))) {
return false;
}
+
+ startTimer();
+ resourceSet->initAndConnect();
OUTPUT << "accepting input" << endl;
showPrompt();
-
return true;
}
@@ -153,6 +157,73 @@ void Client::doExit()
resourceSet->release();
}
+
+void Client::modifyResources(const QString &resString)
+{
+ //resString example: [mand_resources:opt_resources] res1,res2,res3:res1,res3
+ if ( resString.isEmpty() || resString.isNull()){
+ qDebug("Client::modifyResources(): no resources in string.");
+ return;
+ }
+ QStringList newAllAndOpt = resString.split(":");
+
+ if (newAllAndOpt.size()==1)
+ qDebug("There are only mandatory resources.");
+
+ //Every optional res. is also in allSet
+ QSet<ResourcePolicy::ResourceType> newAllSet;
+ QSet<ResourcePolicy::ResourceType> newOptSet;
+
+ if ( !CommandLineParser::parseResourceList(newAllAndOpt.at(0), newAllSet) ) {
+ qDebug("Client::modifyResources(): could not parse all resources.");
+ return;
+ }
+
+ if (newAllAndOpt.size()>1) {
+ if ( !CommandLineParser::parseResourceList(newAllAndOpt.at(1), newOptSet) ){
+ qDebug("Client::modifyResources(): could not parse optional resources.");
+ return;
+ }
+ bool optNotInAll = false;
+ //If the user forgot to add resource to all when specifying optional -> add to all.
+ foreach(ResourceType newOptRes, newOptSet){
+ if ( !newAllSet.contains(newOptRes) ){
+ optNotInAll = true;
+ newAllSet.insert(newOptRes);
+ }
+ }
+ if (optNotInAll)
+ qDebug("Client::modifyResources(): optional resources should be added to all as well.");
+ }
+
+ //Check if new resources are in current resource set.
+ foreach ( ResourceType newRes, newAllSet) {
+ if ( resourceSet->contains(newRes) ){
+ if ( resourceSet->resource(newRes)->isOptional() && !newOptSet.contains(newRes) ) {
+ //New mandatory is in set, but is not optional in the new set.
+ resourceSet->resource(newRes)->setOptional(false);
+ }
+ else if ( !resourceSet->resource(newRes)->isOptional() && newOptSet.contains(newRes) ){
+ //New mandatory is in set, but is optional.
+ resourceSet->resource(newRes)->setOptional(true);
+ }
+ }
+ else { //Add new resource.
+ resourceSet->addResource(newRes);
+
+ if ( newOptSet.contains(newRes) )
+ resourceSet->resource(newRes)->setOptional(true);
+ }
+ }
+ QList<Resource*> resList = resourceSet->resources();
+ //Check if there are current resources not in the new set (i.e. removed).
+ foreach(Resource* resource, resList)
+ if ( !newAllSet.contains(resource->type()) )
+ resourceSet->deleteResource(resource->type());
+
+}
+
+
const char * resourceTypeToString(ResourceType type)
{
switch (type) {
@@ -208,6 +279,11 @@ void Client::showResources(const QList<Resource*> &resList)
}
}
+void Client::stopConnectTimerHandler()
+{
+ stopTimer();
+}
+
void Client::resourceAcquiredHandler(const QList<ResourceType>&)
{
stopTimer();
@@ -333,60 +409,26 @@ void Client::readLine(int)
qCritical("%s failed!", qPrintable(command));
}
}
- else if (command == "add") {
- QString resourceList, flag;
- input >> resourceList >> flag;
- if (!resourceSet) {
- qCritical("%s%s failed!", qPrintable(prefix), qPrintable(command));
- }
- else if (resourceList.isEmpty() || resourceList.isNull()) {
- OUTPUT << "List of desired resources is missing. Use help.";
- }
- else {
- bool optional = false;
- QSet<ResourcePolicy::ResourceType> resToAdd;
- CommandLineParser::parseResourceList(resourceList, resToAdd);
- if (flag == "-o") {
- optional = true;
- }
- foreach(ResourcePolicy::ResourceType resource, resToAdd) {
- if (!resourceSet->contains(resource)) {
- resourceSet->addResource(resource);
- }
- if (optional) {
- resourceSet->resource(resource)->setOptional();
- }
- }
- }
- }
- else if (command == "remove") {
- QString resourceList, flag;
- input >> resourceList >> flag;
- if (!resourceSet) {
- qCritical("%s%s failed!", qPrintable(prefix), qPrintable(command));
- }
- else if (resourceList.isEmpty() || resourceList.isNull()) {
- OUTPUT << "List of desired resources is missing. Use help.";
+ else if (command == "update") {
+
+ QString resourceList;
+ input >> resourceList;
+
+ if (!resourceSet)
+ qCritical("%s failed!", qPrintable(command));
+
+ if (resourceList.isEmpty() || resourceList.isNull()) {
+ qCritical("%s failed! List of desired resources is missing. Use help.",
+ qPrintable(command));
}
else {
- QSet<ResourcePolicy::ResourceType> resToRemove;
- CommandLineParser::parseResourceList(resourceList, resToRemove);
- if (flag == "-o") {
- foreach(ResourcePolicy::ResourceType resource, resToRemove) {
- resourceSet->resource(resource)->setOptional(false);
- }
- }
- else {
- foreach(ResourcePolicy::ResourceType resource, resToRemove) {
- resourceSet->deleteResource(resource);
- }
- }
- }
- }
- else if (command == "update") {
- if (!resourceSet || !resourceSet->update()) {
- qCritical("%s%s failed!", qPrintable(prefix), qPrintable(command));
+ startTimer();
+ modifyResources(resourceList);
+
+ if (!resourceSet->update())
+ qCritical("%s failed!", qPrintable(command));
}
+
}
else if (command == "audio") {
QString what, group, tagName, tagValue;