File: PkInterface.cpp

package info (click to toggle)
apper 1.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 9,868 kB
  • sloc: cpp: 14,381; xml: 941; makefile: 15; sh: 4
file content (195 lines) | stat: -rw-r--r-- 7,597 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/***************************************************************************
 *   Copyright (C) 2008-2011 by Daniel Nicoletti                           *
 *   dantti12@gmail.com                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, 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 General Public License     *
 *   along with this program; see the file COPYING. If not, write to       *
 *   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,  *
 *   Boston, MA 02110-1301, USA.                                           *
 ***************************************************************************/

#include "PkInterface.h"
#include "packagekitadaptor.h"

#include <QtDBus/QDBusConnection>
//#include <KWindowSystem>

#include "SessionTask.h"
#include "PkInstallPackageNames.h"
#include "PkInstallMimeTypes.h"
#include "PkInstallGStreamerResources.h"
#include "PkInstallFontconfigResources.h"
#include "PkInstallPlasmaResources.h"
#include "PkInstallPackageFiles.h"
#include "PkInstallProvideFiles.h"
#include "PkInstallCatalogs.h"
#include "PkRemovePackageByFiles.h"
#include "PkInstallPrinterDrivers.h"

#include "PkIsInstalled.h"
#include "PkSearchFile.h"

#include <Daemon>

#include <QLoggingCategory>

Q_DECLARE_LOGGING_CATEGORY(APPER_SESSION)

using namespace PackageKit;

PkInterface::PkInterface(QObject *parent) :
    AbstractIsRunning(parent)
{
    if (!Daemon::isRunning()) {
        QTimer timer;
        timer.setInterval(5000);
        QEventLoop loop;
        connect(Daemon::global(), &Daemon::isRunningChanged, &loop, &QEventLoop::quit);
        connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
        loop.exec();
        if (!Daemon::isRunning()) {
            qCWarning(APPER_SESSION) << "Packagekit didn't start";
            qApp->quit();
            return;
        }
    }

    qCDebug(APPER_SESSION) << "Creating Helper";
    (void) new ModifyAdaptor(this);
    (void) new QueryAdaptor(this);
    if (!QDBusConnection::sessionBus().registerService(QLatin1String("org.freedesktop.PackageKit"))) {
        qCDebug(APPER_SESSION) << "unable to register service to dbus";
        return;
    }

    if (!QDBusConnection::sessionBus().registerObject(QLatin1String("/org/freedesktop/PackageKit"), this)) {
        qCDebug(APPER_SESSION) << "unable to register object to dbus";
        return;
    }
}

PkInterface::~PkInterface()
{
}

void PkInterface::InstallCatalogs(uint xid, const QStringList &files, const QString &interaction)
{
    qCDebug(APPER_SESSION) << xid << files << interaction;
    show(new PkInstallCatalogs(xid, files, interaction, message()));
}

void PkInterface::InstallFontconfigResources(uint xid, const QStringList &resources, const QString &interaction)
{
    qCDebug(APPER_SESSION) << xid << resources << interaction;
    show(new PkInstallFontconfigResources(xid, resources, interaction, message()));
}

void PkInterface::InstallGStreamerResources(uint xid, const QStringList &resources, const QString &interaction)
{
    qCDebug(APPER_SESSION) << xid << resources << interaction;
    show(new PkInstallGStreamerResources(xid, resources, interaction, message()));
}

void PkInterface::InstallMimeTypes(uint xid, const QStringList &mime_types, const QString &interaction)
{
    qCDebug(APPER_SESSION) << xid << mime_types << interaction;
    show(new PkInstallMimeTypes(xid, mime_types, interaction, message()));
}

void PkInterface::InstallPackageFiles(uint xid, const QStringList &files, const QString &interaction)
{
    qCDebug(APPER_SESSION) << xid << files << interaction;
    show(new PkInstallPackageFiles(xid, files, interaction, message()));
}

void PkInterface::InstallPackageNames(uint xid, const QStringList &packages, const QString &interaction)
{
    qCDebug(APPER_SESSION) << xid << packages << interaction;
    show(new PkInstallPackageNames(xid, packages, interaction, message()));
}

void PkInterface::InstallProvideFiles(uint xid, const QStringList &files, const QString &interaction)
{
    qCDebug(APPER_SESSION) << xid << files << interaction;
    show(new PkInstallProvideFiles(xid, files, interaction, message()));
}

void PkInterface::RemovePackageByFiles(uint xid, const QStringList &files, const QString &interaction)
{
    qCDebug(APPER_SESSION) << xid << files << interaction;
    show(new PkRemovePackageByFiles(xid, files, interaction, message()));
}

void PkInterface::InstallPrinterDrivers(uint xid, const QStringList &resources, const QString &interaction)
{
    qCDebug(APPER_SESSION) << xid << resources << interaction;
    show(new PkInstallPrinterDrivers(xid, resources, interaction, message()));
}

void PkInterface::InstallPlasmaResources(uint xid, const QStringList &resources, const QString &interaction)
{
    qCDebug(APPER_SESSION) << xid << resources << interaction;
    show(new PkInstallPlasmaResources(xid, resources, interaction, message()));
}

void PkInterface::InstallResources(uint xid, const QString &type, const QStringList &resources, const QString &interaction)
{
    if (type == QLatin1String("codec")) {
        InstallGStreamerResources(xid, resources, interaction);
    } else if (type == QLatin1String("mimetype")) {
        InstallMimeTypes(xid, resources, interaction);
    } else if (type == QLatin1String("font")) {
        InstallFontconfigResources(xid, resources, interaction);
    } else if (type == QLatin1String("postscript-driver")) {
        InstallPrinterDrivers(xid, resources, interaction);
    } else if (type == QLatin1String("plasma-service")) {
        InstallPlasmaResources(xid, resources, interaction);
    } else {
        sendErrorReply(QStringLiteral("org.freedesktop.PackageKit.Failed"), QStringLiteral("Unsupported resource type"));
    }
}

//Query
bool PkInterface::IsInstalled(const QString &package_name, const QString &interaction)
{
    show(new PkIsInstalled(package_name, interaction, message()));
    // This is discarted
    return false;
}

bool PkInterface::SearchFile(const QString &file_name, const QString &interaction, QString &package_name)
{
    Q_UNUSED(package_name)
    show(new PkSearchFile(file_name, interaction, message()));
    // This is discarted
    return false;
}

void PkInterface::show(SessionTask *widget)
{
    increaseRunning();
    setDelayedReply(true);

    connect(widget, &SessionTask::finished, this, &PkInterface::decreaseRunning);
    if (widget->parentWId()) {
        // Check before showing if the widget has
        // a parent, otherwise it should not be modal
        // to not lock the application
        widget->setWindowModality(Qt::WindowModal);
    }
    widget->show();
//    KWindowSystem::forceActiveWindow(widget->winId());
//    KWindowSystem::setMainWindow(widget, widget->parentWId());
}

#include "moc_PkInterface.cpp"