File: openwidgetassistant.cpp

package info (click to toggle)
plasma-workspace 4%3A5.27.5-2%2Bdeb12u2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 102,040 kB
  • sloc: cpp: 121,800; xml: 3,238; python: 645; perl: 586; sh: 254; javascript: 113; ruby: 62; makefile: 15; ansic: 13
file content (69 lines) | stat: -rw-r--r-- 2,081 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
    SPDX-FileCopyrightText: 2008 Aaron Seigo <aseigo@kde.org>

    SPDX-License-Identifier: LGPL-2.0-or-later
*/

#include "openwidgetassistant_p.h"

#include <QLabel>
#include <QListWidget>
#include <QVBoxLayout>

#include <KFileWidget>
#include <KLocalizedString>
#include <KMessageBox>
#include <QDebug>
#include <QUrl>

#include <KPackage/PackageLoader>
#include <KPackage/PackageStructure>

namespace Plasma
{
OpenWidgetAssistant::OpenWidgetAssistant(QWidget *parent)
    : KAssistantDialog(parent)
    , m_fileWidget(nullptr)
    , m_filePageWidget(new QWidget(this))
{
    QVBoxLayout *layout = new QVBoxLayout(m_filePageWidget);
    m_fileWidget = new KFileWidget(QUrl(), m_filePageWidget);
    m_fileWidget->setOperationMode(KFileWidget::Opening);
    m_fileWidget->setMode(KFile::File | KFile::ExistingOnly);
    connect(this, SIGNAL(user1Clicked()), m_fileWidget, SLOT(slotOk()));
    connect(m_fileWidget, SIGNAL(accepted()), this, SLOT(finished()));
    layout->addWidget(m_fileWidget);

    m_fileWidget->setFilter(QString());
    const QStringList mimes{QStringLiteral("application/x-plasma")};
    m_fileWidget->setMimeFilter(mimes);

    m_filePage = new KPageWidgetItem(m_filePageWidget, i18n("Select Plasmoid File"));
    addPage(m_filePage);

    resize(QSize(560, 400).expandedTo(minimumSizeHint()));
}

void OpenWidgetAssistant::slotHelpClicked()
{
    // enable it when doc will created
}

void OpenWidgetAssistant::finished()
{
    m_fileWidget->accept(); // how interesting .. accept() must be called before the state is set
    const QString packageFilePath = m_fileWidget->selectedFile();
    if (packageFilePath.isEmpty()) {
        // TODO: user visible error handling
        qDebug() << "hm. no file path?";
        return;
    }

    KPackage::Package installer = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/Applet"));

    if (!installer.install(packageFilePath)) {
        KMessageBox::error(this, i18n("Installing the package %1 failed.", packageFilePath), i18n("Installation Failure"));
    }
}

} // Plasma namespace