2014-11-13 19:30:51 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2009 by Chani Armitage <chani@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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 Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "launch.h"
|
|
|
|
|
|
|
|
#include <KDebug>
|
|
|
|
#include <KIcon>
|
2024-04-04 14:11:44 +03:00
|
|
|
#include <KRun>
|
2014-11-13 19:30:51 +02:00
|
|
|
#include <Plasma/Containment>
|
|
|
|
|
|
|
|
AppLauncher::AppLauncher(QObject *parent, const QVariantList &args)
|
|
|
|
: Plasma::ContainmentActions(parent, args),
|
|
|
|
m_action(new QAction(this))
|
|
|
|
{
|
|
|
|
m_menu = new KMenu();
|
|
|
|
connect(m_menu, SIGNAL(triggered(QAction*)), this, SLOT(switchTo(QAction*)));
|
|
|
|
|
|
|
|
m_action->setMenu(m_menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
AppLauncher::~AppLauncher()
|
|
|
|
{
|
|
|
|
delete m_menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppLauncher::contextEvent(QEvent *event)
|
|
|
|
{
|
|
|
|
makeMenu();
|
|
|
|
m_menu->adjustSize();
|
|
|
|
m_menu->exec(popupPosition(m_menu->size(), event));
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<QAction*> AppLauncher::contextualActions()
|
|
|
|
{
|
|
|
|
makeMenu();
|
|
|
|
|
|
|
|
QList<QAction*> list;
|
|
|
|
list << m_action;
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppLauncher::makeMenu()
|
|
|
|
{
|
|
|
|
m_menu->clear();
|
|
|
|
|
2024-04-12 19:05:51 +03:00
|
|
|
// add the whole kmenu
|
2024-04-04 14:11:44 +03:00
|
|
|
KServiceGroup::Ptr group = KServiceGroup::root();
|
|
|
|
if (group && group->isValid()) {
|
2024-04-12 19:05:51 +03:00
|
|
|
m_menu->setTitle(group->caption());
|
|
|
|
m_menu->setIcon(KIcon(group->icon()));
|
2024-04-04 14:11:44 +03:00
|
|
|
addApp(m_menu, group);
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-04 14:11:44 +03:00
|
|
|
void AppLauncher::addApp(QMenu *menu, KServiceGroup::Ptr group)
|
2014-11-13 19:30:51 +02:00
|
|
|
{
|
2024-04-04 14:11:44 +03:00
|
|
|
const QString name = group->name();
|
|
|
|
if (group->noDisplay()) {
|
|
|
|
kDebug() << "hidden group" << name;
|
|
|
|
return;
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
|
|
|
|
2024-04-04 14:11:44 +03:00
|
|
|
foreach (const KServiceGroup::Ptr subGroup, group->groupEntries(KServiceGroup::NoOptions)) {
|
2024-04-19 03:43:37 +03:00
|
|
|
if (subGroup->noDisplay() || subGroup->childCount() < 1) {
|
|
|
|
continue;
|
|
|
|
}
|
2024-04-04 14:11:44 +03:00
|
|
|
QMenu *subMenu = menu->addMenu(KIcon(subGroup->icon()), subGroup->caption());
|
|
|
|
addApp(subMenu, subGroup);
|
|
|
|
if (subMenu->isEmpty()) {
|
|
|
|
delete subMenu;
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
2024-04-04 14:11:44 +03:00
|
|
|
}
|
2014-11-13 19:30:51 +02:00
|
|
|
|
2024-04-04 14:11:44 +03:00
|
|
|
foreach (const KService::Ptr app, group->serviceEntries(KServiceGroup::NoOptions)) {
|
|
|
|
if (app->noDisplay()) {
|
|
|
|
kDebug() << "hidden entry" << app->name();
|
|
|
|
continue;
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
2024-04-04 14:11:44 +03:00
|
|
|
QAction *action = menu->addAction(KIcon(app->icon()), app->name());
|
|
|
|
action->setData(app->entryPath());
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppLauncher::switchTo(QAction *action)
|
|
|
|
{
|
2024-04-04 14:11:44 +03:00
|
|
|
const QString entrypath = action->data().toString();
|
|
|
|
kDebug() << "running" << entrypath;
|
|
|
|
new KRun(KUrl(entrypath), nullptr);
|
2014-11-13 19:30:51 +02:00
|
|
|
}
|
|
|
|
|
2015-02-27 09:28:46 +00:00
|
|
|
#include "moc_launch.cpp"
|