File indexing completed on 2024-04-28 13:41:00
0001 /*************************************************************************** 0002 * Copyright (C) 2008-2011 by Daniel Nicoletti * 0003 * dantti12@gmail.com * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; see the file COPYING. If not, write to * 0017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0018 * Boston, MA 02110-1301, USA. * 0019 ***************************************************************************/ 0020 0021 #include "PkInterface.h" 0022 #include "packagekitadaptor.h" 0023 0024 #include <QtDBus/QDBusConnection> 0025 //#include <KWindowSystem> 0026 0027 #include "SessionTask.h" 0028 #include "PkInstallPackageNames.h" 0029 #include "PkInstallMimeTypes.h" 0030 #include "PkInstallGStreamerResources.h" 0031 #include "PkInstallFontconfigResources.h" 0032 #include "PkInstallPlasmaResources.h" 0033 #include "PkInstallPackageFiles.h" 0034 #include "PkInstallProvideFiles.h" 0035 #include "PkInstallCatalogs.h" 0036 #include "PkRemovePackageByFiles.h" 0037 #include "PkInstallPrinterDrivers.h" 0038 0039 #include "PkIsInstalled.h" 0040 #include "PkSearchFile.h" 0041 0042 #include <Daemon> 0043 0044 #include <QLoggingCategory> 0045 0046 Q_DECLARE_LOGGING_CATEGORY(APPER_SESSION) 0047 0048 using namespace PackageKit; 0049 0050 PkInterface::PkInterface(QObject *parent) : 0051 AbstractIsRunning(parent) 0052 { 0053 if (!Daemon::isRunning()) { 0054 QTimer timer; 0055 timer.setInterval(5000); 0056 QEventLoop loop; 0057 connect(Daemon::global(), &Daemon::isRunningChanged, &loop, &QEventLoop::quit); 0058 connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit); 0059 loop.exec(); 0060 if (!Daemon::isRunning()) { 0061 qCWarning(APPER_SESSION) << "Packagekit didn't start"; 0062 qApp->quit(); 0063 return; 0064 } 0065 } 0066 0067 qCDebug(APPER_SESSION) << "Creating Helper"; 0068 (void) new ModifyAdaptor(this); 0069 (void) new QueryAdaptor(this); 0070 if (!QDBusConnection::sessionBus().registerService(QLatin1String("org.freedesktop.PackageKit"))) { 0071 qCDebug(APPER_SESSION) << "unable to register service to dbus"; 0072 return; 0073 } 0074 0075 if (!QDBusConnection::sessionBus().registerObject(QLatin1String("/org/freedesktop/PackageKit"), this)) { 0076 qCDebug(APPER_SESSION) << "unable to register object to dbus"; 0077 return; 0078 } 0079 } 0080 0081 PkInterface::~PkInterface() 0082 { 0083 } 0084 0085 void PkInterface::InstallCatalogs(uint xid, const QStringList &files, const QString &interaction) 0086 { 0087 qCDebug(APPER_SESSION) << xid << files << interaction; 0088 show(new PkInstallCatalogs(xid, files, interaction, message())); 0089 } 0090 0091 void PkInterface::InstallFontconfigResources(uint xid, const QStringList &resources, const QString &interaction) 0092 { 0093 qCDebug(APPER_SESSION) << xid << resources << interaction; 0094 show(new PkInstallFontconfigResources(xid, resources, interaction, message())); 0095 } 0096 0097 void PkInterface::InstallGStreamerResources(uint xid, const QStringList &resources, const QString &interaction) 0098 { 0099 qCDebug(APPER_SESSION) << xid << resources << interaction; 0100 show(new PkInstallGStreamerResources(xid, resources, interaction, message())); 0101 } 0102 0103 void PkInterface::InstallMimeTypes(uint xid, const QStringList &mime_types, const QString &interaction) 0104 { 0105 qCDebug(APPER_SESSION) << xid << mime_types << interaction; 0106 show(new PkInstallMimeTypes(xid, mime_types, interaction, message())); 0107 } 0108 0109 void PkInterface::InstallPackageFiles(uint xid, const QStringList &files, const QString &interaction) 0110 { 0111 qCDebug(APPER_SESSION) << xid << files << interaction; 0112 show(new PkInstallPackageFiles(xid, files, interaction, message())); 0113 } 0114 0115 void PkInterface::InstallPackageNames(uint xid, const QStringList &packages, const QString &interaction) 0116 { 0117 qCDebug(APPER_SESSION) << xid << packages << interaction; 0118 show(new PkInstallPackageNames(xid, packages, interaction, message())); 0119 } 0120 0121 void PkInterface::InstallProvideFiles(uint xid, const QStringList &files, const QString &interaction) 0122 { 0123 qCDebug(APPER_SESSION) << xid << files << interaction; 0124 show(new PkInstallProvideFiles(xid, files, interaction, message())); 0125 } 0126 0127 void PkInterface::RemovePackageByFiles(uint xid, const QStringList &files, const QString &interaction) 0128 { 0129 qCDebug(APPER_SESSION) << xid << files << interaction; 0130 show(new PkRemovePackageByFiles(xid, files, interaction, message())); 0131 } 0132 0133 void PkInterface::InstallPrinterDrivers(uint xid, const QStringList &resources, const QString &interaction) 0134 { 0135 qCDebug(APPER_SESSION) << xid << resources << interaction; 0136 show(new PkInstallPrinterDrivers(xid, resources, interaction, message())); 0137 } 0138 0139 void PkInterface::InstallPlasmaResources(uint xid, const QStringList &resources, const QString &interaction) 0140 { 0141 qCDebug(APPER_SESSION) << xid << resources << interaction; 0142 show(new PkInstallPlasmaResources(xid, resources, interaction, message())); 0143 } 0144 0145 void PkInterface::InstallResources(uint xid, const QString &type, const QStringList &resources, const QString &interaction) 0146 { 0147 if (type == QLatin1String("codec")) { 0148 InstallGStreamerResources(xid, resources, interaction); 0149 } else if (type == QLatin1String("mimetype")) { 0150 InstallMimeTypes(xid, resources, interaction); 0151 } else if (type == QLatin1String("font")) { 0152 InstallFontconfigResources(xid, resources, interaction); 0153 } else if (type == QLatin1String("postscript-driver")) { 0154 InstallPrinterDrivers(xid, resources, interaction); 0155 } else if (type == QLatin1String("plasma-service")) { 0156 InstallPlasmaResources(xid, resources, interaction); 0157 } else { 0158 sendErrorReply(QStringLiteral("org.freedesktop.PackageKit.Failed"), QStringLiteral("Unsupported resource type")); 0159 } 0160 } 0161 0162 //Query 0163 bool PkInterface::IsInstalled(const QString &package_name, const QString &interaction) 0164 { 0165 show(new PkIsInstalled(package_name, interaction, message())); 0166 // This is discarted 0167 return false; 0168 } 0169 0170 bool PkInterface::SearchFile(const QString &file_name, const QString &interaction, QString &package_name) 0171 { 0172 Q_UNUSED(package_name) 0173 show(new PkSearchFile(file_name, interaction, message())); 0174 // This is discarted 0175 return false; 0176 } 0177 0178 void PkInterface::show(SessionTask *widget) 0179 { 0180 increaseRunning(); 0181 setDelayedReply(true); 0182 0183 connect(widget, &SessionTask::finished, this, &PkInterface::decreaseRunning); 0184 if (widget->parentWId()) { 0185 // Check before showing if the widget has 0186 // a parent, otherwise it should not be modal 0187 // to not lock the application 0188 widget->setWindowModality(Qt::WindowModal); 0189 } 0190 widget->show(); 0191 // KWindowSystem::forceActiveWindow(widget->winId()); 0192 // KWindowSystem::setMainWindow(widget, widget->parentWId()); 0193 } 0194 0195 #include "moc_PkInterface.cpp"