Skip to content
This repository has been archived by the owner on Dec 17, 2017. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Razor-runner program
  • Loading branch information
SokoloffA committed Jul 19, 2011
1 parent b5440b3 commit bfebf90
Show file tree
Hide file tree
Showing 21 changed files with 1,870 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -35,7 +35,7 @@ add_subdirectory( razorqt-appswitcher )
add_subdirectory( razorqt-resources )
#add_subdirectory( razorqt-su )
add_subdirectory( razorqt-x11info )

add_subdirectory( razorqt-runner )


########### Add uninstall target ###############
Expand Down
87 changes: 87 additions & 0 deletions razorqt-runner/CMakeLists.txt
@@ -0,0 +1,87 @@
set(PROJECT razor-runner)

set(H_FILES
dialog.h
commanditemmodel.h
widgets.h
configuredialog/configuredialog.h
)

set(MOC_FILES
dialog.h
commanditemmodel.h
widgets.h
configuredialog/configuredialog.h
)

set(CPP_FILES
main.cpp
dialog.cpp
commanditemmodel.cpp
widgets.cpp
configuredialog/configuredialog.cpp
)

set(UI_FILES
dialog.ui
configuredialog/configuredialog.ui
)

set(QRC_FILES

)

set(LIBRARIES
razorqt
razorqxt
)

set(QT_USE_QTXML 1)

set(THEMES
resources/themes
)
# Translations **********************************
file(GLOB TS_FILES
translations/*.ts
)
#************************************************
cmake_minimum_required( VERSION 2.6 )

include_directories(
.
${CMAKE_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/librazorqt/
)


if(NOT CMAKE_BUILD_TYPE)
set( CMAKE_BUILD_TYPE Release )
endif (NOT CMAKE_BUILD_TYPE)

add_definitions(-Wall)
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})


set(RAZOR_SHARE_DIR ${CMAKE_INSTALL_PREFIX}/share/razor)
set(APP_SHARE_DIR ${RAZOR_SHARE_DIR}/${PROJECT})
add_definitions(-DTRANSLATIONS_DIR=\"${APP_SHARE_DIR}\")

#************************************************


qt4_wrap_cpp(MOC_SOURCES ${MOC_FILES})
qt4_wrap_ui(UI_HEADERS ${UI_FILES})
qt4_add_resources(QRC_SOURCES ${QRC_FILES})
qt4_add_translation(QM_FILES ${TS_FILES})

add_executable(${PROJECT} ${CPP_FILES} ${UI_FILES} ${RESOURCES} ${QRC_SOURCES} ${QM_FILES} ${MOC_SOURCES})
add_dependencies(${PROJECT} razorqt)
target_link_libraries(${PROJECT} ${LIBRARIES} ${QT_LIBRARIES})

install(TARGETS ${PROJECT} RUNTIME DESTINATION bin)
install(FILES ${QM_FILES} DESTINATION ${APP_SHARE_DIR})
install(FILES ${CONFIG_FILES} DESTINATION ${APP_SHARE_DIR})
install(DIRECTORY ${THEMES} DESTINATION ${RAZOR_SHARE_DIR})
300 changes: 300 additions & 0 deletions razorqt-runner/commanditemmodel.cpp
@@ -0,0 +1,300 @@
/* BEGIN_COMMON_COPYRIGHT_HEADER
*
* Razor - a lightweight, Qt based, desktop toolset
* https://sourceforge.net/projects/razor-qt/
*
* Copyright: 2010-2011 Razor team
* Authors:
* Alexander Sokoloff <sokoloff.a@gmail.ru>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; only version 2 of
* the License is valid for this program.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* END_COMMON_COPYRIGHT_HEADER */

#include "commanditemmodel.h"

#include <razorqt/xdgmenu.h>
#include <razorqt/xdgdesktopfile.h>
#include <razorqt/domhelper.h>
#include <razorqt/xdgicon.h>

#include <QtGui/QStandardItemModel>
#include <QtCore/QFileInfo>
#include <QtCore/QProcess>
#include <QtCore/QSettings>


/************************************************
************************************************/
CommandItem::CommandItem():
QStandardItem()
{
}


/************************************************
************************************************/
CommandItem::~CommandItem()
{
}


/************************************************
************************************************/
void CommandItem::setText(const QString &title, const QString &comment)
{
QString s = QString("<b>%1</b><br>\n%2\n").arg(title, comment);
setData(s, Qt::DisplayRole);
}


/************************************************
************************************************/
DesktopItem::DesktopItem(const QDomElement &element):
CommandItem()
{
setData(XdgIcon::fromTheme(element.attribute("icon")), Qt::DecorationRole);
setText(element.attribute("title"), element.attribute("genericName"));
setData(QVariant(element.attribute("comment")), Qt::ToolTipRole);

QString command = QFileInfo(element.attribute("exec")).baseName().section(" ", 0, 0);
mSearchText = element.attribute("title") + " " + command;
mDesktopFile = element.attribute("desktopFile");

}


/************************************************
************************************************/
bool DesktopItem::run() const
{

XdgDesktopFile *desktop = XdgDesktopFileCache::getFile(mDesktopFile);
return desktop->startDetached();
}


/************************************************
************************************************/
bool DesktopItem::compare(const QRegExp &regExp) const
{
QRegExp re(regExp);

re.setCaseSensitivity(Qt::CaseInsensitive);
return mSearchText.contains(re);
}



/************************************************
************************************************/
HistoryItem::HistoryItem(const QString &command):
CommandItem()
{
setData(XdgIcon::defaultApplicationIcon(), Qt::DecorationRole);
setText(command, QObject::tr("History"));
mCommand = command;
}


/************************************************
************************************************/
bool HistoryItem::run() const
{
return QProcess::startDetached(mCommand);
}


/************************************************
************************************************/
bool HistoryItem::compare(const QRegExp &regExp) const
{
QRegExp re(regExp);

re.setCaseSensitivity(Qt::CaseSensitive);
return mCommand.contains(re);
}


/************************************************
************************************************/
CommandItemModel::CommandItemModel(QObject *parent) :
QSortFilterProxyModel(parent),
mSourceModel(new QStandardItemModel(this)),
mXdgMenu(new XdgMenu())
{
setSourceModel(mSourceModel);
// rebuild();
}


/************************************************
************************************************/
CommandItemModel::~CommandItemModel()
{
}


/************************************************
************************************************/
bool CommandItemModel::isOutDated() const
{
return mXdgMenu->isOutDated();
}


/************************************************
************************************************/
void CommandItemModel::rebuild()
{
if (mXdgMenu->isOutDated())
{
mXdgMenu->read(XdgMenu::getMenuFileName());

// Remove old DesktopItems. If anyone knows a better solution tell me.
for (int i = mSourceModel->rowCount()-1; i>-1; --i)
{
DesktopItem *item = dynamic_cast<DesktopItem*>(mSourceModel->item(i, 0));
if (item)
mSourceModel->removeRow(i, QModelIndex());
}


rebuildMainMenu(mXdgMenu->xml().documentElement());
}
}


/************************************************
************************************************/
void CommandItemModel::rebuildMainMenu(const QDomElement &xml)
{
DomElementIterator it(xml, "");
while(it.hasNext())
{
QDomElement e = it.next();

// Build submenu ........................
if (e.tagName() == "Menu")
rebuildMainMenu(e);

//Build application link ................
else if (e.tagName() == "AppLink")
{
DesktopItem *item = new DesktopItem(e);
mSourceModel->appendRow(item);
}

}

}


/************************************************
************************************************/
bool CommandItemModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
QRegExp re(filterRegExp());

if (re.isEmpty())
return false;

CommandItem *item = dynamic_cast<CommandItem*>(mSourceModel->item(sourceRow, 0));

if (!item)
return false;

return item->compare(re);
}


/************************************************
************************************************/
const CommandItem *CommandItemModel::command(const QModelIndex &index) const
{
if (!index.isValid())
return 0;

QModelIndex ind = mapToSource(index);
if (!ind.isValid())
return 0;

CommandItem *item = dynamic_cast<CommandItem*>(mSourceModel->item(ind.row(), 0));
return item;
}


/************************************************
************************************************/
void CommandItemModel::addHistoryCommand(const QString &command)
{
HistoryItem *item = new HistoryItem(command);
mSourceModel->appendRow(item);
}



/************************************************
************************************************/
void CommandItemModel::loadHistory(const QSettings *settings)
{
int n=0;
while (true)
{
n++;
QString command = settings->value(QString("history/command%1").arg(n)).toString();
if (command.isEmpty())
break;

HistoryItem *item = new HistoryItem(command);
mSourceModel->appendRow(item);
}
}


/************************************************
************************************************/
void CommandItemModel::saveHistory(QSettings *settings)
{
int n=0;
for (int i=0; i<mSourceModel->rowCount(); ++i)
{
HistoryItem *item = dynamic_cast<HistoryItem*>(mSourceModel->item(i, 0));
if (item)
{
n++;
settings->setValue(QString("history/command%1").arg(n), item->command());
}
}
}

4 comments on commit bfebf90

@diegoxter
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just asking, razor-runner can be configured to put itself on any place on the desktop? or it is hardcoded on the top of the screen?

@SokoloffA
Copy link
Member Author

@SokoloffA SokoloffA commented on bfebf90 Jul 20, 2011 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diegoxter
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you didn't tell me that a settings dialog existed, I couldn't have guessed (but well, that's just the stupid me)
A floating mode ? Well, i can't speak for other people, but if the runner can be on either bottom of the screen or a corner, that's it for me, maybe somewhere somebody do need floating mode on this app, but particularly, not interested on that.

@SokoloffA
Copy link
Member Author

@SokoloffA SokoloffA commented on bfebf90 Jul 20, 2011 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.