diff --git a/browser.cpp b/browser.cpp index 1ccf2ad4ab5f0b6a1d534ca660e3eab081871577..336a0633f1b441df0792106f074e013a6fc92b7e 100644 --- a/browser.cpp +++ b/browser.cpp @@ -307,6 +307,14 @@ QString BrowserTree::LookForTreeColor(QTreeWidgetItem* item) return treecol; /* "" */ } +bool BrowserTree::ReplacePlaceholders( QString &cmd) { + if(cmd.contains("{HOME}")) { + cmd.replace("{HOME}", QDir::homePath()); + return true; + } + return false; +} + int BrowserTree::LookForFontSize(QTreeWidgetItem *item) { int size = defaultFontSize; @@ -351,7 +359,7 @@ void BrowserTree::ContextMenu(const QPoint& p) int column = currentColumn(); EApplicationLauncher *app = NULL, *master_app = NULL; int state; - QString appstatus, appaction, appname, master_appname, execstring; + QString appstatus, appaction, appname, master_appname; QDomNode node; QAction *action = NULL, *dummyaction = NULL, *collapse = NULL, *collapse_all = NULL; @@ -396,13 +404,16 @@ void BrowserTree::ContextMenu(const QPoint& p) if(node.isElement() ) { elem = node.toElement(); - execstring = elem.attribute("exename"); + const QString &execstring = elem.attribute("exename"); if(i == 0) /* application itself */ { launch_icon = QIcon(":icons/launch.png"); maximize_icon = QIcon(":icons/maximize.png"); - QString cmdline = LookForEnvPath(currentItem() ) + execstring; + QString cmdline(execstring); + bool placeh = ReplacePlaceholders(cmdline); + if(!placeh) + cmdline = LookForEnvPath(currentItem() ) + execstring; QString exename; QStringList args; getExeAndArgs(cmdline, exename, args); @@ -437,7 +448,10 @@ void BrowserTree::ContextMenu(const QPoint& p) { // qDebug() << "Element name: " << elem.tagName() << ", executes: " << execstring << ", the so called " << // appname; - QString cmdline = LookForEnvPath(currentItem() ) + execstring; + QString cmdline(execstring); + bool placeh = ReplacePlaceholders(cmdline); + if(!placeh) + cmdline = LookForEnvPath(currentItem() ) + execstring; QString exename; QStringList args; getExeAndArgs(cmdline, exename, args); @@ -517,6 +531,7 @@ void BrowserTree::ContextMenu(const QPoint& p) /* The last option is stop/kill, in a submenu, available on the executable and running items */ /* We must get the app once again, reading it ftom the currentItem() */ + const QString &execstring = elem.attribute("exename"); if(elem.hasAttribute("executable") && elem.attribute("executable") == "yes" && execstring != "") /* exec string is not empty */ { @@ -588,8 +603,11 @@ void BrowserTree::executeRaiseOrStartAction() bf = new BackupAppFinder(0); bf->exec(exename, envpath); exename = bf->exename(); - if(!exename.isEmpty()) - AddApplicationToList(bf->exe_path() + exename + " " + arguments.join(" "), item); + if(!exename.isEmpty()) { + QString cmd = bf->exe_path() + exename + " " + arguments.join(" "); + ReplacePlaceholders(cmd); + AddApplicationToList(cmd, item); + } } /* calls Rise() on launcher. Since QTango 4.2, Rise() uses dbus to raise() the application, * if the application is registered with DBus sessioin bus. @@ -641,7 +659,6 @@ void BrowserTree::collapse_all() void BrowserTree::ExecuteElement(QTreeWidgetItem *item, int column) { - QString commandLine; QDomElement elem = domElementForItem[item]; qDebug() << __FUNCTION__ << elem.attribute("exename"); if(elem.hasAttribute("exename") && elem.attribute("exename") == "" ) @@ -663,7 +680,10 @@ void BrowserTree::ExecuteElement(QTreeWidgetItem *item, int column) { QString exename; QStringList args; - commandLine = LookForEnvPath(item) + elem.attribute("exename"); + QString commandLine(elem.attribute("exename")); + bool placeh = ReplacePlaceholders(commandLine); // {HOME} + if(!placeh) + commandLine = LookForEnvPath(item) + elem.attribute("exename"); getExeAndArgs(commandLine, exename, args); EApplicationLauncher *launcher = GetAppByExeAndArgs(exename, args); if(launcher != NULL && launcher->XUtils()->X11Status() == EXISTING) @@ -691,8 +711,10 @@ void BrowserTree::ExecuteElement(QTreeWidgetItem *item, int column) QString exename; QStringList args; EApplicationLauncher *launcher; - - commandLine = LookForEnvPath(item) + elem.attribute("exename"); + QString commandLine(elem.attribute("exename")); + bool placeh = ReplacePlaceholders(commandLine); + if(!placeh) + commandLine = LookForEnvPath(item) + elem.attribute("exename"); item->setIcon(3, QIcon(":icons/starting.png") ); getExeAndArgs(commandLine, exename, args); @@ -1047,11 +1069,14 @@ void BrowserTree::parseFolderElement(const QDomElement &element, && element.hasAttribute("exename") && element.attribute("exename") != "" ) { /* An executable icon has a folder icon with a gear */ - command = LookForEnvPath(item) + element.attribute("exename"); + command = element.attribute("exename"); + bool placeh = ReplacePlaceholders(command); + if(!placeh) // {HOME} --> home path + command = LookForEnvPath(item) + element.attribute("exename"); // no envpath if placeholders /* AddApplicationToList adds the couple Application/item to the pair list */ launcher = AddApplicationToList(command, item); - item->setText(2, element.attribute("exename") ); - item->setTextColor(2, Qt::gray); + item->setText(2, placeh ? command : element.attribute("exename") ); + item->setForeground(2, Qt::gray); if(adopt && launcher->XUtils()->QueryX11Status(command) > 0) { folderIcon.addPixmap(QPixmap(":icons/folder_exec_open_running.png"), QIcon::Normal, QIcon::On ); @@ -1122,7 +1147,11 @@ void BrowserTree::parseFolderElement(const QDomElement &element, { if(child.attribute("exename") != "") { - command = LookForEnvPath(childItem) + child.attribute("exename"); + command = child.attribute("exename"); + bool placeh = ReplacePlaceholders(command); + if(!placeh) // {HOME} --> home path + command = LookForEnvPath(childItem) + child.attribute("exename"); + // env path prepended if no placeholders are used launcher = AddApplicationToList(command, childItem ); bool is_cumbia = false; if(launcher) // launcher null for duplicated entries @@ -1155,7 +1184,7 @@ void BrowserTree::parseFolderElement(const QDomElement &element, } childItem->setTextColor(3, Qt::gray); item->setTextColor(2, Qt::gray); - childItem->setText(2, child.attribute("exename") ); + childItem->setText(2, placeh ? command : child.attribute("exename") ); childItem->setTextColor(3, Qt::gray); } else diff --git a/browser.h b/browser.h index 9246df122c5fe296a98a382b7a22430b227d85df..e8e45d3127162b43e4014eb13332eb841a5a3bbc 100644 --- a/browser.h +++ b/browser.h @@ -133,6 +133,7 @@ private: QString LookForEnvPath(QTreeWidgetItem* item); QString LookForTreeColor(QTreeWidgetItem* item); + bool ReplacePlaceholders(QString &cmd); void applyColor(QTreeWidgetItem *, QString); void parseFolderElement(const QDomElement &element,