1
/***************************************************************************
2
* Copyright © 2010 Jonathan Thomas <echidnaman@kubuntu.org> *
3
* Copyright © 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com> *
5
* This program is free software; you can redistribute it and/or *
6
* modify it under the terms of the GNU General Public License as *
7
* published by the Free Software Foundation; either version 2 of *
8
* the License or (at your option) version 3 or any later version *
9
* accepted by the membership of KDE e.V. (or its successor approved *
10
* by the membership of KDE e.V.), which shall act as a proxy *
11
* defined in Section 14 of version 3 of the license. *
13
* This program is distributed in the hope that it will be useful, *
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16
* GNU General Public License for more details. *
18
* You should have received a copy of the GNU General Public License *
19
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
20
***************************************************************************/
22
#include "LaunchListModel.h"
25
#include <QStringBuilder>
29
#include <KToolInvocation>
32
#include "Transaction/TransactionModel.h"
33
#include "resources/AbstractResource.h"
35
LaunchListModel::LaunchListModel(QObject* parent)
36
: QStandardItemModel(parent)
38
connect(TransactionModel::global(), SIGNAL(transactionAdded(Transaction*)),
39
this, SLOT(watchTransaction(Transaction*)));
42
void LaunchListModel::watchTransaction(Transaction *trans)
44
connect(trans, SIGNAL(statusChanged(Transaction::Status)),
45
this, SLOT(transactionStatusChanged(Transaction::Status)));
48
void LaunchListModel::transactionStatusChanged(Transaction::Status status)
50
Transaction *trans = qobject_cast<Transaction *>(sender());
52
if (status == Transaction::DoneStatus)
53
transactionFinished(trans);
56
void LaunchListModel::transactionFinished(Transaction* trans)
58
bool doneInstall = trans->status() == Transaction::DoneStatus &&
59
trans->role() == Transaction::InstallRole;
61
if(trans->resource()->canExecute() && doneInstall)
62
addApplication(trans->resource());
65
void LaunchListModel::addApplication(AbstractResource* app)
67
QList<QStandardItem*> items;
68
QStringList execs = app->executables();
70
for (const QString& exec : execs) {
71
KService::Ptr service = KService::serviceByStorageId(exec);
73
QString name = service->property("Name").toString();
74
if (!service->genericName().isEmpty())
75
name += QLatin1String(" - ") % service->genericName();
77
QStandardItem *item = new QStandardItem(name);
78
item->setIcon(QIcon::fromTheme(service->icon()));
79
item->setData(service->desktopEntryPath(), Qt::UserRole);
83
invisibleRootItem()->appendRows(items);
86
void LaunchListModel::invokeApplication(const QModelIndex &idx) const
88
KToolInvocation::startServiceByDesktopPath(idx.data(Qt::UserRole).toString());
91
void LaunchListModel::invokeApplication(int row) const
93
invokeApplication(index(row, 0));