~ubuntu-branches/ubuntu/vivid/muon/vivid-proposed

« back to all changes in this revision

Viewing changes to installer/ApplicationWindow.cpp

Tags: upstream-1.3.65
ImportĀ upstreamĀ versionĀ 1.3.65

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include <KAction>
33
33
#include <KActionCollection>
34
34
#include <KIcon>
 
35
#include <KMessageWidget>
 
36
#include <KPixmapSequence>
 
37
#include <KPixmapSequenceOverlayPainter>
35
38
#include <KService>
36
39
#include <KToolInvocation>
37
 
#include "kmessagewidget.h"
38
40
 
39
41
// LibQApt includes
40
42
#include <LibQApt/Backend>
41
43
 
 
44
// Libmuon includes
 
45
#include <Application.h>
 
46
#include <ApplicationBackend.h>
 
47
#include <HistoryView/HistoryView.h>
 
48
 
42
49
// Own includes
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"
51
56
 
52
57
ApplicationWindow::ApplicationWindow()
53
58
    : MuonMainWindow()
54
 
    , m_launcherMessage(0)
55
 
    , m_appLauncher(0)
 
59
    , m_launcherMessage(nullptr)
 
60
    , m_appLauncher(nullptr)
 
61
    , m_progressItem(nullptr)
56
62
{
57
63
    initGUI();
58
64
    QTimer::singleShot(10, this, SLOT(initObject()));
85
91
    m_viewStack = new QStackedWidget(leftWidget);
86
92
    m_viewStack->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
87
93
 
 
94
    // Busy widget
 
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);
 
99
    busyWidget->start();
 
100
 
 
101
    m_viewStack->addWidget(m_busyWidget);
 
102
    m_viewStack->setCurrentWidget(m_busyWidget);
 
103
 
88
104
    m_mainWidget->addWidget(leftWidget);
89
105
    loadSplitterSizes();
90
106
 
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()));
115
131
 
116
132
    MuonMainWindow::initObject();
117
133
    // Our modified ApplicationBackend provides us events in a way that
253
269
    m_viewHash[installedItem->index()] = 0;
254
270
 
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;
376
393
        case AppView: {
377
394
            QString originFilter = index.data(OriginFilterRole).toString();
378
395
            QApt::Package::State stateFilter = (QApt::Package::State)index.data(StateFilterRole).toInt();
 
396
 
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);
 
403
 
 
404
            if (originFilter != QLatin1String("Ubuntu") && originFilter != QLatin1String("Debian"))
386
405
                appView->setShouldShowTechnical(true);
387
 
            }
388
406
        }
389
407
        break;
390
408
        case CatView: {
392
410
 
393
411
            AvailableView *availableView = static_cast<AvailableView *>(view);
394
412
            availableView->setBackend(m_backend);
395
 
            m_viewStack->addWidget(view);
396
413
        }
397
414
            break;
398
415
        case History:
399
416
            view = new HistoryView(this);
400
 
            m_viewStack->addWidget(view);
 
417
            break;
 
418
        case Progress: {
 
419
            view = new ProgressView(this, m_appBackend);
 
420
            ProgressView *pView = (ProgressView *)view;
 
421
            connect(pView, SIGNAL(lastTransactionCancelled()), this, SLOT(removeProgressItem()));
 
422
        }
401
423
        case InvalidView:
402
424
        default:
403
425
            break;
404
426
        }
 
427
 
 
428
        m_viewStack->addWidget(view);
405
429
    }
406
430
 
 
431
    m_viewStack->addWidget(view);
407
432
    m_viewStack->setCurrentWidget(view);
 
433
    m_viewStack->removeWidget(m_busyWidget);
 
434
 
 
435
    delete m_busyWidget;
 
436
    m_busyWidget = nullptr;
408
437
 
409
438
    m_viewHash[index] = view;
410
439
}
425
454
void ApplicationWindow::sourcesEditorFinished(int reload)
426
455
{
427
456
    m_appBackend->reload();
 
457
    clearViews();
 
458
    populateViews();
428
459
    MuonMainWindow::sourcesEditorFinished(reload);
429
460
}
430
461
 
436
467
void ApplicationWindow::showLauncherMessage()
437
468
{
438
469
    clearMessageActions();
439
 
    QApt::PackageList packages;
440
470
 
441
 
    foreach (const QString &package, m_appBackend->launchList()) {
442
 
        QApt::Package *pkg = m_backend->package(package);
443
 
        if (pkg) {
444
 
            packages << pkg;
 
471
    QVector<KService::Ptr> apps;
 
472
    foreach (Application *app, m_appBackend->launchList()) {
 
473
        app->clearPackage();
 
474
        app->package(); // Regenerate package
 
475
        if (!app->isInstalled()) {
 
476
            continue;
445
477
        }
 
478
        apps << app->executables();
446
479
    }
447
480
 
448
481
    m_appBackend->clearLaunchList();
449
 
 
450
 
    QVector<KService *> apps;
451
 
    foreach (QApt::Package *package, packages) {
452
 
        if (!package->isInstalled()) {
453
 
            continue;
454
 
        }
455
 
 
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())
464
 
            {
465
 
                apps << service;
466
 
            }
467
 
        }
468
 
    }
469
482
    m_launchableApps = apps;
470
483
 
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()
500
513
{
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)),
522
535
    }
523
536
}
524
537
 
 
538
void ApplicationWindow::addProgressItem()
 
539
{
 
540
    QStandardItem *parentItem = m_viewModel->invisibleRootItem();
 
541
 
 
542
    if (m_progressItem)
 
543
        return;
 
544
 
 
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);
 
551
 
 
552
    m_viewHash[m_progressItem->index()] = 0;
 
553
}
 
554
 
 
555
void ApplicationWindow::removeProgressItem()
 
556
{
 
557
    if (!m_progressItem)
 
558
        return;
 
559
 
 
560
    QObject *progressView = m_viewHash[m_progressItem->index()];
 
561
    if (progressView)
 
562
            progressView->deleteLater();
 
563
 
 
564
    m_viewHash.remove(m_progressItem->index());
 
565
    m_viewModel->removeRow(m_viewModel->indexFromItem(m_progressItem).row());
 
566
    m_progressItem = nullptr;
 
567
}
 
568
 
525
569
#include "ApplicationWindow.moc"