33
33
#include <KActionCollection>
35
#include <KMessageWidget>
36
#include <KPixmapSequence>
37
#include <KPixmapSequenceOverlayPainter>
35
38
#include <KService>
36
39
#include <KToolInvocation>
37
#include "kmessagewidget.h"
39
41
// LibQApt includes
40
42
#include <LibQApt/Backend>
45
#include <Application.h>
46
#include <ApplicationBackend.h>
47
#include <HistoryView/HistoryView.h>
43
#include "../libmuon/HistoryView/HistoryView.h"
44
#include "ApplicationBackend.h"
45
#include "Application.h"
46
50
#include "ApplicationLauncher.h"
51
#include "ApplicationView/ApplicationListView.h"
47
52
#include "AvailableView.h"
53
#include "ProgressView.h"
48
54
#include "ViewSwitcher.h"
49
#include "ApplicationModel/ApplicationListView.h"
50
55
#include "MuonInstallerSettings.h"
52
57
ApplicationWindow::ApplicationWindow()
54
, m_launcherMessage(0)
59
, m_launcherMessage(nullptr)
60
, m_appLauncher(nullptr)
61
, m_progressItem(nullptr)
58
64
QTimer::singleShot(10, this, SLOT(initObject()));
85
91
m_viewStack = new QStackedWidget(leftWidget);
86
92
m_viewStack->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
95
m_busyWidget = new QWidget(m_viewStack);
96
KPixmapSequenceOverlayPainter *busyWidget = new KPixmapSequenceOverlayPainter(m_busyWidget);
97
busyWidget->setSequence(KPixmapSequence("process-working", KIconLoader::SizeSmallMedium));
98
busyWidget->setWidget(m_busyWidget);
101
m_viewStack->addWidget(m_busyWidget);
102
m_viewStack->setCurrentWidget(m_busyWidget);
88
104
m_mainWidget->addWidget(leftWidget);
89
105
loadSplitterSizes();
107
123
connect(m_appBackend, SIGNAL(appBackendReady()),
108
124
this, SLOT(populateViews()));
109
125
connect(m_appBackend, SIGNAL(reloadStarted()),
110
this, SLOT(clearViews()));
111
connect(m_appBackend, SIGNAL(reloadFinished()),
112
this, SLOT(populateViews()));
126
this, SLOT(removeProgressItem()));
113
127
connect(m_appBackend, SIGNAL(reloadFinished()),
114
128
this, SLOT(showLauncherMessage()));
129
connect(m_appBackend, SIGNAL(startingFirstTransaction()),
130
this, SLOT(addProgressItem()));
116
132
MuonMainWindow::initObject();
117
133
// Our modified ApplicationBackend provides us events in a way that
253
269
m_viewHash[installedItem->index()] = 0;
255
271
parentItem = availableItem;
272
kDebug() << originNames.size();
256
273
foreach(const QString &originName, originNames) {
257
274
QString originLabel = m_backend->originLabel(originName);
258
275
QStandardItem *viewItem = new QStandardItem;
377
394
QString originFilter = index.data(OriginFilterRole).toString();
378
395
QApt::Package::State stateFilter = (QApt::Package::State)index.data(StateFilterRole).toInt();
379
397
view = new ApplicationListView(this, m_appBackend, index);
380
398
ApplicationListView *appView = static_cast<ApplicationListView *>(view);
381
m_viewStack->addWidget(view);
382
399
appView->setBackend(m_backend);
383
400
appView->setStateFilter(stateFilter);
384
401
appView->setOriginFilter(originFilter);
385
if (originFilter.contains(QLatin1String("LP-PPA"))) {
402
appView->setCanShowTechnical(true);
404
if (originFilter != QLatin1String("Ubuntu") && originFilter != QLatin1String("Debian"))
386
405
appView->setShouldShowTechnical(true);
393
411
AvailableView *availableView = static_cast<AvailableView *>(view);
394
412
availableView->setBackend(m_backend);
395
m_viewStack->addWidget(view);
399
416
view = new HistoryView(this);
400
m_viewStack->addWidget(view);
419
view = new ProgressView(this, m_appBackend);
420
ProgressView *pView = (ProgressView *)view;
421
connect(pView, SIGNAL(lastTransactionCancelled()), this, SLOT(removeProgressItem()));
401
423
case InvalidView:
428
m_viewStack->addWidget(view);
431
m_viewStack->addWidget(view);
407
432
m_viewStack->setCurrentWidget(view);
433
m_viewStack->removeWidget(m_busyWidget);
436
m_busyWidget = nullptr;
409
438
m_viewHash[index] = view;
436
467
void ApplicationWindow::showLauncherMessage()
438
469
clearMessageActions();
439
QApt::PackageList packages;
441
foreach (const QString &package, m_appBackend->launchList()) {
442
QApt::Package *pkg = m_backend->package(package);
471
QVector<KService::Ptr> apps;
472
foreach (Application *app, m_appBackend->launchList()) {
474
app->package(); // Regenerate package
475
if (!app->isInstalled()) {
478
apps << app->executables();
448
481
m_appBackend->clearLaunchList();
450
QVector<KService *> apps;
451
foreach (QApt::Package *package, packages) {
452
if (!package->isInstalled()) {
456
// TODO: move to Application (perhaps call it Application::executables())
457
foreach (const QString &desktop, package->installedFilesList().filter(".desktop")) {
458
// we create a new KService because findByDestopPath
459
// might fail because the Sycoca database is not up to date yet.
460
KService *service = new KService(desktop);
461
if (service->isApplication() &&
462
!service->noDisplay() &&
463
!service->exec().isEmpty())
469
482
m_launchableApps = apps;
471
484
if (apps.size() == 1) {
472
KService *service = apps.first();
485
KService::Ptr service = apps.first();
473
486
QString name = service->genericName().isEmpty() ?
474
487
service->property("Name").toString() :
475
488
service->property("Name").toString() % QLatin1Literal(" - ") % service->genericName();
499
512
void ApplicationWindow::showAppLauncher()
501
514
if (!m_appLauncher && !m_launchableApps.isEmpty()) {
502
m_appLauncher = new ApplicationLauncher(m_launchableApps);
515
m_appLauncher = new ApplicationLauncher(m_appBackend);
503
516
connect(m_appLauncher, SIGNAL(destroyed(QObject*)),
504
517
this, SLOT(onAppLauncherClosed()));
505
518
connect(m_appLauncher, SIGNAL(finished(int)),
538
void ApplicationWindow::addProgressItem()
540
QStandardItem *parentItem = m_viewModel->invisibleRootItem();
545
m_progressItem = new QStandardItem;
546
m_progressItem->setEditable(false);
547
m_progressItem->setIcon(KIcon("download").pixmap(32,32));
548
m_progressItem->setText(i18nc("@item:inlistbox Item for showing the progress view", "In Progress"));
549
m_progressItem->setData(Progress, ViewTypeRole);
550
parentItem->appendRow(m_progressItem);
552
m_viewHash[m_progressItem->index()] = 0;
555
void ApplicationWindow::removeProgressItem()
560
QObject *progressView = m_viewHash[m_progressItem->index()];
562
progressView->deleteLater();
564
m_viewHash.remove(m_progressItem->index());
565
m_viewModel->removeRow(m_viewModel->indexFromItem(m_progressItem).row());
566
m_progressItem = nullptr;
525
569
#include "ApplicationWindow.moc"