Permalink
Browse files

Fixed a history in the razor-runner.

  • Loading branch information...
1 parent c7bacad commit 0efb12742745546ea7144ebaec72a19089790908 @SokoloffA SokoloffA committed May 5, 2012
Showing with 38 additions and 31 deletions.
  1. +1 −0 razorqt-runner/commanditemmodel.cpp
  2. +2 −13 razorqt-runner/dialog.cpp
  3. +21 −14 razorqt-runner/providers.cpp
  4. +14 −4 razorqt-runner/providers.h
@@ -191,6 +191,7 @@ CommandSourceItemModel::CommandSourceItemModel(QObject *parent) :
mHistoryProvider = new HistoryProvider();
mProviders.append(mHistoryProvider);
+ mCustomCommandProvider->setHistoryProvider(mHistoryProvider);
mProviders.append(new AppLinkProvider());
#ifdef MATH_ENABLED
@@ -38,7 +38,7 @@
#include <razorqt/powermanager.h>
#include <razorqt/screensaver.h>
-
+#include <iostream>
#include <QtCore/QDebug>
#include <QtGui/QCloseEvent>
#include <QtGui/QDesktopWidget>
@@ -308,7 +308,7 @@ void Dialog::applySettings()
if (mGlobalShortcut->shortcut() != shortcut)
{
mGlobalShortcut->setShortcut(shortcut);
- qDebug() << tr("Press \"%1\" to see dialog.").arg(shortcut.toString());
+ std::cout << tr("Press \"%1\" to see dialog.").arg(shortcut.toString()).toLocal8Bit().constData() << std::endl;
}
mShowOnTop = mSettings->value("dialog/show_on_top", true).toBool();
@@ -357,18 +357,7 @@ void Dialog::runCommand()
const CommandProviderItem *command = mCommandItemModel->command(ui->commandList->currentIndex());
if (command)
- {
res = command->run();
- }
- else
- {
- QString command = ui->commandEd->text();
- res = QProcess::startDetached(command);
- if (res)
- {
- mCommandItemModel->addHistoryCommand(command);
- }
- }
if (res)
{
@@ -92,8 +92,10 @@ AppLinkItem::AppLinkItem(const QDomElement &element):
mTitle = element.attribute("title");
mComment = element.attribute("genericName");
mToolTip = element.attribute("comment");
- mCommand = QFileInfo(element.attribute("exec")).baseName().section(" ", 0, 0);
+ mCommand = element.attribute("exec");
+ mProgram = QFileInfo(element.attribute("exec")).baseName().section(" ", 0, 0);
mDesktopFile = element.attribute("desktopFile");
+ QMetaObject::invokeMethod(this, "updateIcon", Qt::QueuedConnection);
}
@@ -117,6 +119,7 @@ void AppLinkItem::operator=(const AppLinkItem &other)
mToolTip = other.toolTip();
mCommand = other.mCommand;
+ mProgram = other.mProgram;
mDesktopFile = other.mDesktopFile;
mIconName = other.mIconName;
@@ -129,7 +132,7 @@ void AppLinkItem::operator=(const AppLinkItem &other)
************************************************/
unsigned int AppLinkItem::rank(const QString &pattern) const
{
- return qMax(stringRank(mCommand, pattern),
+ return qMax(stringRank(mProgram, pattern),
stringRank(mTitle, pattern)
);
}
@@ -156,7 +159,7 @@ bool AppLinkItem::compare(const QRegExp &regExp) const
QRegExp re(regExp);
re.setCaseSensitivity(Qt::CaseInsensitive);
- return mCommand.contains(re) ||
+ return mProgram.contains(re) ||
mTitle.contains(re) ;
}
@@ -204,6 +207,7 @@ void doUpdate(const QDomElement &xml, QHash<QString, AppLinkItem*> &items)
else if (e.tagName() == "AppLink")
{
AppLinkItem *item = new AppLinkItem(e);
+ delete items[item->command()]; // delete previous item;
items.insert(item->command(), item);
}
}
@@ -218,7 +222,6 @@ void AppLinkProvider::update()
emit aboutToBeChanged();
QHash<QString, AppLinkItem*> newItems;
doUpdate(mXdgMenu->xml().documentElement(), newItems);
-
{
QMutableListIterator<CommandProviderItem*> i(*this);
while (i.hasNext()) {
@@ -227,7 +230,6 @@ void AppLinkProvider::update()
if (newItem)
{
*(item) = *newItem; // Copy by value, not pointer!
- item->updateIcon();
delete newItem;
}
else
@@ -240,10 +242,9 @@ void AppLinkProvider::update()
{
QHashIterator<QString, AppLinkItem*> i(newItems);
- while (i.hasNext()) {
- AppLinkItem *item = i.next().value();
- append(item);
- item->updateIcon();
+ while (i.hasNext())
+ {
+ append(i.next().value());
}
}
@@ -351,8 +352,9 @@ void HistoryProvider::clearHistory()
/************************************************
************************************************/
-CustomCommandItem::CustomCommandItem():
- CommandProviderItem()
+CustomCommandItem::CustomCommandItem(CustomCommandProvider *provider):
+ CommandProviderItem(),
+ mProvider(provider)
{
mIcon = XdgIcon::fromTheme("utilities-terminal");
}
@@ -438,7 +440,11 @@ bool CustomCommandItem::run() const
if (program.isEmpty())
return false;
- return QProcess::startDetached(program, args);
+ bool ret = QProcess::startDetached(program, args);
+ if (ret && mProvider->historyProvider())
+ mProvider->historyProvider()->AddCommand(mCommand);
+
+ return ret;
}
@@ -464,9 +470,10 @@ unsigned int CustomCommandItem::rank(const QString &pattern) const
************************************************/
CustomCommandProvider::CustomCommandProvider():
- CommandProvider()
+ CommandProvider(),
+ mHistoryProvider(0)
{
- mItem = new CustomCommandItem();
+ mItem = new CustomCommandItem(this);
append(mItem);
}
@@ -41,10 +41,11 @@
/*! The CommandProviderItem class provides an item for use with CommandProvider.
Items usually contain title, comment, toolTip and icon.
*/
-class CommandProviderItem
+class CommandProviderItem: public QObject
{
+ Q_OBJECT
public:
- CommandProviderItem() {}
+ CommandProviderItem(): QObject() {}
virtual ~CommandProviderItem() {}
virtual bool run() const = 0;
@@ -105,21 +106,24 @@ class CommandProvider: public QObject, public QList<CommandProviderItem*>
class AppLinkItem: public CommandProviderItem
{
+ Q_OBJECT
public:
AppLinkItem(const QDomElement &element);
bool run() const;
bool compare(const QRegExp &regExp) const;
- void updateIcon();
QString command() const { return mCommand; }
void operator=(const AppLinkItem &other);
virtual unsigned int rank(const QString &pattern) const;
+private slots:
+ void updateIcon();
private:
QString mDesktopFile;
QString mIconName;
QString mCommand;
+ QString mProgram;
};
@@ -179,11 +183,12 @@ class HistoryProvider: public CommandProvider
/************************************************
* Custom command
************************************************/
+class CustomCommandProvider;
class CustomCommandItem: public CommandProviderItem
{
public:
- CustomCommandItem();
+ CustomCommandItem(CustomCommandProvider *provider);
bool run() const;
bool compare(const QRegExp &regExp) const;
@@ -194,6 +199,7 @@ class CustomCommandItem: public CommandProviderItem
virtual unsigned int rank(const QString &pattern) const;
private:
QString mCommand;
+ CustomCommandProvider *mProvider;
};
@@ -207,8 +213,12 @@ class CustomCommandProvider: public CommandProvider
QString command() const { return mItem->command(); }
void setCommand(const QString &command) { mItem->setCommand(command); }
+ HistoryProvider* historyProvider() const { return mHistoryProvider; }
+ void setHistoryProvider(HistoryProvider *historyProvider) { mHistoryProvider = historyProvider; }
+
private:
CustomCommandItem *mItem;
+ HistoryProvider *mHistoryProvider;
};

0 comments on commit 0efb127

Please sign in to comment.