diff --git a/freespacenotifier/module.cpp b/freespacenotifier/module.cpp index 5dc4e9b14..cdfb76155 100644 --- a/freespacenotifier/module.cpp +++ b/freespacenotifier/module.cpp @@ -1,34 +1,31 @@ /* This file is part of the KDE Project Copyright (c) 2006 Lukas Tinkl Copyright (c) 2008 Lubos Lunak Copyright (c) 2009 Ivo Anjo 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. If not, see . */ #include "module.h" #include -K_PLUGIN_FACTORY_WITH_JSON(FreeSpaceNotifierModuleFactory, - "freespacenotifier.json", - registerPlugin(); - ) +K_PLUGIN_CLASS_WITH_JSON(FreeSpaceNotifierModule, "freespacenotifier.json") FreeSpaceNotifierModule::FreeSpaceNotifierModule(QObject* parent, const QList&) : KDEDModule(parent) { } #include "module.moc" diff --git a/kcms/translations/translations.cpp b/kcms/translations/translations.cpp index 866360626..093ee0995 100644 --- a/kcms/translations/translations.cpp +++ b/kcms/translations/translations.cpp @@ -1,144 +1,144 @@ /* * Copyright (C) 2014 John Layt * Copyright (C) 2018 Eike Hein * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "translations.h" #include "translationsmodel.h" #include "writeexports.h" #include #include #include #include -K_PLUGIN_FACTORY_WITH_JSON(TranslationsFactory, "kcm_translations.json", registerPlugin();) +K_PLUGIN_CLASS_WITH_JSON(Translations, "kcm_translations.json") Translations::Translations(QObject *parent, const QVariantList &args) : KQuickAddons::ConfigModule(parent, args) , m_translationsModel(new TranslationsModel(this)) , m_selectedTranslationsModel(new SelectedTranslationsModel(this)) , m_availableTranslationsModel(new AvailableTranslationsModel(this)) , m_everSaved(false) { KAboutData *about = new KAboutData(QStringLiteral("kcm_translations"), i18n("Configure Plasma translations"), QStringLiteral("2.0"), QString(), KAboutLicense::LGPL); setAboutData(about); setButtons(Apply | Default); m_config = KConfigGroup(KSharedConfig::openConfig(configFile), "Translations"); connect(m_selectedTranslationsModel, &SelectedTranslationsModel::selectedLanguagesChanged, this, &Translations::selectedLanguagesChanged); connect(m_selectedTranslationsModel, &SelectedTranslationsModel::missingLanguagesChanged, this, &Translations::missingLanguagesChanged); connect(m_selectedTranslationsModel, &SelectedTranslationsModel::selectedLanguagesChanged, m_availableTranslationsModel, &AvailableTranslationsModel::setSelectedLanguages); } Translations::~Translations() { } QAbstractItemModel* Translations::translationsModel() const { return m_translationsModel; } QAbstractItemModel* Translations::selectedTranslationsModel() const { return m_selectedTranslationsModel; } QAbstractItemModel* Translations::availableTranslationsModel() const { return m_availableTranslationsModel; } bool Translations::everSaved() const { return m_everSaved; } void Translations::load() { m_configuredLanguages = m_config.readEntry(lcLanguage, QString()).split(QLatin1Char(':'), QString::SkipEmptyParts); m_availableTranslationsModel->setSelectedLanguages(m_configuredLanguages); m_selectedTranslationsModel->setSelectedLanguages(m_configuredLanguages); } void Translations::save() { m_everSaved = true; emit everSavedChanged(); m_configuredLanguages = m_selectedTranslationsModel->selectedLanguages(); const auto missingLanguages = m_selectedTranslationsModel->missingLanguages(); for (const QString& lang : missingLanguages) { m_configuredLanguages.removeOne(lang); } m_config.writeEntry(lcLanguage, m_configuredLanguages.join(QStringLiteral(":")), KConfig::Persistent); m_config.sync(); writeExports(); m_selectedTranslationsModel->setSelectedLanguages(m_configuredLanguages); } void Translations::defaults() { KConfigGroup formatsConfig = KConfigGroup(KSharedConfig::openConfig(configFile), "Formats"); QString lang = formatsConfig.readEntry("LANG", QString()); if (lang.isEmpty() || !KLocalizedString::availableDomainTranslations("systemsettings").contains(lang)) { lang = QLocale::system().name(); } if (!KLocalizedString::availableDomainTranslations("systemsettings").contains(lang)) { lang = QStringLiteral("en_US"); } QStringList languages; languages << lang; m_selectedTranslationsModel->setSelectedLanguages(languages); } void Translations::selectedLanguagesChanged() { setNeedsSave(m_configuredLanguages != m_selectedTranslationsModel->selectedLanguages()); } void Translations::missingLanguagesChanged() { if (!m_selectedTranslationsModel->missingLanguages().isEmpty()) { setNeedsSave(true); } } #include "translations.moc" diff --git a/kioslave/desktop/desktopnotifier.cpp b/kioslave/desktop/desktopnotifier.cpp index aef4639b5..9f7fa1478 100644 --- a/kioslave/desktop/desktopnotifier.cpp +++ b/kioslave/desktop/desktopnotifier.cpp @@ -1,104 +1,102 @@ /* This file is part of the KDE Project Copyright (C) 2008, 2009 Fredrik Höglund This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "desktopnotifier.h" #include #include #include #include #include #include #include #include -K_PLUGIN_FACTORY_WITH_JSON(DesktopNotifierFactory, - "desktopnotifier.json", - registerPlugin();) +K_PLUGIN_CLASS_WITH_JSON(DesktopNotifier, "desktopnotifier.json") DesktopNotifier::DesktopNotifier(QObject *parent, const QList &) : KDEDModule(parent) { m_desktopLocation = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)); dirWatch = new KDirWatch(this); dirWatch->addDir(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)); dirWatch->addDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + '/' + "Trash/files"); dirWatch->addFile(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QStringLiteral("/user-dirs.dirs")); connect(dirWatch, &KDirWatch::created, this, &DesktopNotifier::created); connect(dirWatch, &KDirWatch::dirty, this, &DesktopNotifier::dirty); } void DesktopNotifier::watchDir(const QString &path) { dirWatch->addDir(path); } void DesktopNotifier::created(const QString &path) { if (path == QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QStringLiteral("/user-dirs.dirs")){ checkDesktopLocation(); } } void DesktopNotifier::dirty(const QString &path) { Q_UNUSED(path) if (path.startsWith(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + '/' + "Trash/files")) { QList trashUrls; // Check for any .desktop file linking to trash:/ to update its icon const auto desktopFiles = QDir(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)).entryInfoList({QStringLiteral("*.desktop")}); for (const auto &fi : desktopFiles) { KDesktopFile df(fi.absoluteFilePath()); if (df.hasLinkType() && df.readUrl() == QLatin1String("trash:/")) { trashUrls << QUrl(QStringLiteral("desktop:/") + fi.fileName()); } } if (!trashUrls.isEmpty()) { org::kde::KDirNotify::emitFilesChanged(trashUrls); } } else if (path == QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QStringLiteral("/user-dirs.dirs")){ checkDesktopLocation(); } else { // Emitting FilesAdded forces a re-read of the dir QUrl url; url.setScheme(QStringLiteral("desktop")); const auto relativePath = QDir(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)).relativeFilePath(path); url.setPath(QStringLiteral("%1/%2").arg(url.path(), relativePath)); url.setPath(QDir::cleanPath(url.path())); org::kde::KDirNotify::emitFilesAdded(url); } } void DesktopNotifier::checkDesktopLocation() { const QUrl ¤tLocation = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)); if (m_desktopLocation != currentLocation) { m_desktopLocation = currentLocation; org::kde::KDirNotify::emitFilesChanged(QList() << QUrl(QStringLiteral("desktop:/"))); } } #include diff --git a/ktimezoned/ktimezoned.cpp b/ktimezoned/ktimezoned.cpp index dac8a51c1..041d40534 100644 --- a/ktimezoned/ktimezoned.cpp +++ b/ktimezoned/ktimezoned.cpp @@ -1,190 +1,187 @@ /* This file is part of the KDE libraries Copyright (c) 2005-2010 David Jarvie Copyright (c) 2005 S.R.Haque Copyright (c) 2013 Martin Klapetek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ktimezoned.h" #include #include #include #include #include #include #include #include #include #include #include -K_PLUGIN_FACTORY_WITH_JSON(KTimeZonedFactory, - "ktimezoned.json", - registerPlugin(); - ) +K_PLUGIN_CLASS_WITH_JSON(KTimeZoned, "ktimezoned.json") const char LOCAL_ZONE[] = "LocalZone"; // name of local time zone const char ZONEINFO_DIR[] = "ZoneinfoDir"; // path to zoneinfo/ directory const char ZONE_TAB[] = "Zonetab"; // path & name of zone.tab KTimeZoned::KTimeZoned(QObject* parent, const QList& l) : KTimeZonedBase(parent, l) { init(false); } KTimeZoned::~KTimeZoned() { delete m_dirWatch; m_dirWatch = nullptr; delete m_zoneTabWatch; m_zoneTabWatch = nullptr; } void KTimeZoned::init(bool restart) { if (restart) { delete m_dirWatch; m_dirWatch = nullptr; delete m_zoneTabWatch; m_zoneTabWatch = nullptr; m_localZone = QString(); m_zoneinfoDir = QString(); m_zoneTab = QString(); } KConfig config(QStringLiteral("ktimezonedrc")); if (restart) config.reparseConfiguration(); KConfigGroup group(&config, "TimeZones"); m_localZone = group.readEntry(LOCAL_ZONE); m_zoneinfoDir = group.readEntry(ZONEINFO_DIR); m_zoneTab = group.readEntry(ZONE_TAB); updateLocalZone(); if (!m_dirWatch) { m_dirWatch = new KDirWatch(this); m_dirWatch->addFile(QStringLiteral("/etc/timezone")); m_dirWatch->addFile(QStringLiteral("/etc/localtime")); connect(m_dirWatch, &KDirWatch::dirty, this, &KTimeZoned::updateLocalZone); connect(m_dirWatch, &KDirWatch::deleted, this, &KTimeZoned::updateLocalZone); connect(m_dirWatch, &KDirWatch::created, this, &KTimeZoned::updateLocalZone); } if (!m_zoneTabWatch && findZoneTab(m_zoneTab)) { // cache the values so we don't look it up on next startup KConfig config(QStringLiteral("ktimezonedrc")); KConfigGroup group(&config, "TimeZones"); group.writeEntry(ZONEINFO_DIR, m_zoneinfoDir); group.writeEntry(ZONE_TAB, m_zoneTab); group.sync(); m_zoneTabWatch = new KDirWatch(this); m_zoneTabWatch->addDir(m_zoneinfoDir, KDirWatch::WatchFiles); connect(m_dirWatch, &KDirWatch::dirty, this, &KTimeZoned::updateLocalZone); connect(m_dirWatch, &KDirWatch::created, this, &KTimeZoned::updateLocalZone); connect(m_dirWatch, &KDirWatch::deleted, this, &KTimeZoned::updateLocalZone); } } // Check if the local zone has been updated, and if so, write the new // zone to the config file and notify interested parties. void KTimeZoned::updateLocalZone() { QString systemTimeZone = QTimeZone::systemTimeZoneId(); if (m_localZone != systemTimeZone) { qDebug() << "System timezone has been changed, new timezone is" << systemTimeZone; KConfig config(QStringLiteral("ktimezonedrc")); KConfigGroup group(&config, "TimeZones"); m_localZone = systemTimeZone; group.writeEntry(LOCAL_ZONE, m_localZone); group.sync(); QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/Daemon"), QStringLiteral("org.kde.KTimeZoned"), QStringLiteral("timeZoneChanged")); QDBusConnection::sessionBus().send(message); } } /* * Find the location of the zoneinfo files and store in m_zoneinfoDir. */ bool KTimeZoned::findZoneTab(const QString &pathFromConfig) { // First try the cached path if (QFileInfo::exists(pathFromConfig)) { return true; } const QString ZONE_TAB_FILE = QStringLiteral("/zone.tab"); const QString ZONE_INFO_DIR = QStringLiteral("/usr/share/zoneinfo"); // Find and open zone.tab - it's all easy except knowing where to look. // Try the LSB location first. QDir dir; QString zoneinfoDir = ZONE_INFO_DIR; QString zoneTab = ZONE_INFO_DIR + ZONE_TAB_FILE; // make a note if the dir exists; whether it contains zone.tab or not if (dir.exists(zoneinfoDir) && QFileInfo::exists(zoneTab)) { m_zoneinfoDir = zoneinfoDir; m_zoneTab = zoneTab; return true; } zoneinfoDir = QStringLiteral("/usr/lib/zoneinfo"); zoneTab = zoneinfoDir + ZONE_TAB_FILE; if (dir.exists(zoneinfoDir) && QFileInfo::exists(zoneTab)) { m_zoneinfoDir = zoneinfoDir; m_zoneTab = zoneTab; return true; } zoneinfoDir = ::getenv("TZDIR"); zoneTab = zoneinfoDir + ZONE_TAB_FILE; if (!zoneinfoDir.isEmpty() && dir.exists(zoneinfoDir) && QFileInfo::exists(zoneTab)) { m_zoneinfoDir = zoneinfoDir; m_zoneTab = zoneTab; return true; } zoneinfoDir = QLatin1String("/usr/share/lib/zoneinfo"); zoneTab = zoneinfoDir + ZONE_TAB_FILE; if (dir.exists(zoneinfoDir + QLatin1String("/src")) && QFileInfo::exists(zoneTab)) { m_zoneinfoDir = zoneinfoDir; m_zoneTab = zoneTab; return true; } return false; } void KTimeZoned::zonetabChanged() { QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/Daemon"), QStringLiteral("org.kde.KTimeZoned"), QStringLiteral("timeZoneDatabaseUpdated")); QDBusConnection::sessionBus().send(message); } #include "ktimezoned.moc" #include "moc_ktimezonedbase.cpp" diff --git a/ktimezoned/ktimezoned_win.cpp b/ktimezoned/ktimezoned_win.cpp index 311697edf..4728742b5 100644 --- a/ktimezoned/ktimezoned_win.cpp +++ b/ktimezoned/ktimezoned_win.cpp @@ -1,154 +1,151 @@ /* This file is part of the KDE libraries Copyright (c) 2009 Till Adam This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "ktimezoned_win.moc" #include "ktimezonedbase.moc" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef Q_OS_WIN #include #endif -K_PLUGIN_FACTORY_WITH_JSON(KTimeZonedFactory, - "ktimezoned.json", - registerPlugin(); -) +K_PLUGIN_CLASS_WITH_JSON(KTimeZoned, "ktimezoned.json") // Config file entry names const char LOCAL_ZONE[] = "LocalZone"; // name of local time zone static const TCHAR currentTimeZoneKey[] = TEXT("System\\CurrentControlSet\\Control\\TimeZoneInformation"); class RegistryWatcherThread : public QThread { public: RegistryWatcherThread(KTimeZoned* parent) :QThread(parent),q(parent) { } ~RegistryWatcherThread() { RegCloseKey(key); } void run() { //FIXME: the timezonechange needs to be handled diffrently #ifndef _WIN32 if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, currentTimeZoneKey, 0, KEY_READ, &key ) == ERROR_SUCCESS ) { while(true) { RegNotifyChangeKeyValue( key, true, REG_NOTIFY_CHANGE_LAST_SET, NULL, false /*async, we want it to block*/ ); q->updateLocalZone(); } } #endif } private: KTimeZoned* q; HKEY key; }; KTimeZoned::KTimeZoned(QObject* parent, const QList& l) : KTimeZonedBase(parent, l), mRegistryWatcherThread(0) { init(false); } KTimeZoned::~KTimeZoned() { if (mRegistryWatcherThread) { mRegistryWatcherThread->quit(); mRegistryWatcherThread->wait(100); } delete mRegistryWatcherThread; } void KTimeZoned::init(bool restart) { if (restart) { qDebug() << "KTimeZoned::init(restart)"; delete mRegistryWatcherThread; mRegistryWatcherThread = 0; } KConfig config(QLatin1String("ktimezonedrc")); if (restart) config.reparseConfiguration(); KConfigGroup group(&config, "TimeZones"); mConfigLocalZone = group.readEntry(LOCAL_ZONE); updateLocalZone(); if (!mRegistryWatcherThread) { mRegistryWatcherThread = new RegistryWatcherThread(this); mRegistryWatcherThread->start(); } } // Check if the local zone has been updated, and if so, write the new // zone to the config file and notify interested parties. void KTimeZoned::updateLocalZone() { // On Windows, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones // holds the time zone database. The TZI binary value is the TIME_ZONE_INFORMATION structure. TIME_ZONE_INFORMATION tzinfo; DWORD res = GetTimeZoneInformation(&tzinfo); if (res == TIME_ZONE_ID_INVALID) return; // hm mLocalZone = QString::fromUtf16( reinterpret_cast( tzinfo.StandardName ) ); if (mConfigLocalZone != mLocalZone) { qDebug() << "Local timezone is now: " << mLocalZone; KConfig config(QLatin1String("ktimezonedrc")); KConfigGroup group(&config, "TimeZones"); mConfigLocalZone = mLocalZone; group.writeEntry(LOCAL_ZONE, mConfigLocalZone); group.sync(); QDBusMessage message = QDBusMessage::createSignal("/Daemon", "org.kde.KTimeZoned", "timeZoneChanged"); QDBusConnection::sessionBus().send(message); } } diff --git a/libcolorcorrect/kded/locationupdater.cpp b/libcolorcorrect/kded/locationupdater.cpp index f66d537fe..06b02db14 100644 --- a/libcolorcorrect/kded/locationupdater.cpp +++ b/libcolorcorrect/kded/locationupdater.cpp @@ -1,57 +1,55 @@ /******************************************************************** Copyright 2017 Roman Gilg 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. If not, see . *********************************************************************/ #include "locationupdater.h" #include #include #include "../compositorcoloradaptor.h" #include "../geolocator.h" -K_PLUGIN_FACTORY_WITH_JSON(LocationUpdaterFactory, - "colorcorrectlocationupdater.json", - registerPlugin();) +K_PLUGIN_CLASS_WITH_JSON(LocationUpdater, "colorcorrectlocationupdater.json") LocationUpdater::LocationUpdater(QObject *parent, const QList &) : KDEDModule(parent) { m_adaptor = new ColorCorrect::CompositorAdaptor(this); connect(m_adaptor, &ColorCorrect::CompositorAdaptor::dataUpdated, this, &LocationUpdater::resetLocator); resetLocator(); } void LocationUpdater::resetLocator() { if (m_adaptor->running() && m_adaptor->mode() == 0) { if (!m_locator) { m_locator = new ColorCorrect::Geolocator(this); connect(m_locator, &ColorCorrect::Geolocator::locationChanged, this, &LocationUpdater::sendLocation); } } else { delete m_locator; m_locator = nullptr; } } void LocationUpdater::sendLocation(double latitude, double longitude) { m_adaptor->sendAutoLocationUpdate(latitude, longitude); } #include "locationupdater.moc" diff --git a/solidautoeject/solidautoeject.cpp b/solidautoeject/solidautoeject.cpp index b0766f0ed..7691f57b0 100644 --- a/solidautoeject/solidautoeject.cpp +++ b/solidautoeject/solidautoeject.cpp @@ -1,64 +1,62 @@ /* This file is part of the KDE Project Copyright (c) 2009 Kevin Ottens This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "solidautoeject.h" #include #include #include #include -K_PLUGIN_FACTORY_WITH_JSON(SolidAutoEjectFactory, - "solidautoeject.json", - registerPlugin();) +K_PLUGIN_CLASS_WITH_JSON(SolidAutoEject, "solidautoeject.json") SolidAutoEject::SolidAutoEject(QObject* parent, const QList&) : KDEDModule(parent) { const QList drives = Solid::Device::listFromType(Solid::DeviceInterface::OpticalDrive); foreach (const Solid::Device &drive, drives) { connectDevice(drive); } connect(Solid::DeviceNotifier::instance(), &Solid::DeviceNotifier::deviceAdded, this, &SolidAutoEject::onDeviceAdded); } SolidAutoEject::~SolidAutoEject() { } void SolidAutoEject::onDeviceAdded(const QString &udi) { connectDevice(Solid::Device(udi)); } void SolidAutoEject::onEjectPressed(const QString &udi) { Solid::Device dev(udi); dev.as()->eject(); } void SolidAutoEject::connectDevice(const Solid::Device &device) { connect(device.as(), &Solid::OpticalDrive::ejectPressed, this, &SolidAutoEject::onEjectPressed); } #include "solidautoeject.moc" diff --git a/soliduiserver/soliduiserver.cpp b/soliduiserver/soliduiserver.cpp index 850c6adf5..3ec09c066 100644 --- a/soliduiserver/soliduiserver.cpp +++ b/soliduiserver/soliduiserver.cpp @@ -1,238 +1,235 @@ /* This file is part of the KDE Project Copyright (c) 2005 Jean-Remy Falleri Copyright (c) 2005-2007 Kevin Ottens Copyright (c) 2007 Alexis Ménard Copyright (c) 2011, 2014 Lukas Tinkl This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "soliduiserver.h" #include "config-X11.h" #include #include #include #include #include #include #include #include #include #include #include #include "deviceactionsdialog.h" #include "deviceaction.h" #include "deviceserviceaction.h" #include "devicenothingaction.h" -K_PLUGIN_FACTORY_WITH_JSON(SolidUiServerFactory, - "soliduiserver.json", - registerPlugin(); - ) +K_PLUGIN_CLASS_WITH_JSON(SolidUiServer, "soliduiserver.json") SolidUiServer::SolidUiServer(QObject* parent, const QList&) : KDEDModule(parent) { } SolidUiServer::~SolidUiServer() { } void SolidUiServer::showActionsDialog(const QString &udi, const QStringList &desktopFiles) { if (m_udiToActionsDialog.contains(udi)) { DeviceActionsDialog *dialog = m_udiToActionsDialog[udi]; dialog->activateWindow(); return; } QList actions; foreach (const QString &desktop, desktopFiles) { const QString filePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "solid/actions/"+desktop); QList services = KDesktopFileActions::userDefinedServices(filePath, true); foreach (const KServiceAction &service, services) { DeviceServiceAction *action = new DeviceServiceAction(); action->setService(service); actions << action; } } // Only one action, execute directly if (actions.size()==1) { DeviceAction *action = actions.takeFirst(); Solid::Device device(udi); action->execute(device); delete action; return; } actions << new DeviceNothingAction(); DeviceActionsDialog *dialog = new DeviceActionsDialog(); dialog->setDevice(Solid::Device(udi)); dialog->setActions(actions); connect(dialog, &DeviceActionsDialog::finished, this, &SolidUiServer::onActionDialogFinished); m_udiToActionsDialog[udi] = dialog; // Update user activity timestamp, otherwise the notification dialog will be shown // in the background due to focus stealing prevention. Entering a new media can // be seen as a kind of user activity after all. It'd be better to update the timestamp // as soon as the media is entered, but it apparently takes some time to get here. KUserTimestamp::updateUserTimestamp(); dialog->show(); } void SolidUiServer::onActionDialogFinished() { DeviceActionsDialog *dialog = qobject_cast(sender()); if (dialog) { QString udi = dialog->device().udi(); m_udiToActionsDialog.remove(udi); } } void SolidUiServer::showPassphraseDialog(const QString &udi, const QString &returnService, const QString &returnObject, uint wId, const QString &appId) { if (m_idToPassphraseDialog.contains(returnService+':'+udi)) { KPasswordDialog *dialog = m_idToPassphraseDialog[returnService+':'+udi]; dialog->activateWindow(); return; } Solid::Device device(udi); KPasswordDialog *dialog = new KPasswordDialog(nullptr, KPasswordDialog::ShowKeepPassword); QString label = device.vendor(); if (!label.isEmpty()) label+=' '; label+= device.product(); dialog->setPrompt(i18n("'%1' needs a password to be accessed. Please enter a password.", label)); dialog->setPixmap(QIcon::fromTheme(device.icon()).pixmap(64, 64)); dialog->setProperty("soliduiserver.udi", udi); dialog->setProperty("soliduiserver.returnService", returnService); dialog->setProperty("soliduiserver.returnObject", returnObject); QString uuid; if (device.is()) uuid = device.as()->uuid(); // read the password from wallet and prefill it to the dialog if (!uuid.isEmpty()) { dialog->setProperty("soliduiserver.uuid", uuid); KWallet::Wallet * wallet = KWallet::Wallet::openWallet(KWallet::Wallet::LocalWallet(), (WId) wId); const QString folderName = QString::fromLatin1("SolidLuks"); if (wallet && wallet->hasFolder(folderName)) { wallet->setFolder(folderName); QString savedPassword; if (wallet->readPassword(uuid, savedPassword) == 0) { dialog->setKeepPassword(true); dialog->setPassword(savedPassword); } wallet->closeWallet(wallet->walletName(), false); } delete wallet; } connect(dialog, &KPasswordDialog::gotPassword, this, &SolidUiServer::onPassphraseDialogCompleted); connect(dialog, &KPasswordDialog::rejected, this, &SolidUiServer::onPassphraseDialogRejected); m_idToPassphraseDialog[returnService+':'+udi] = dialog; reparentDialog(dialog, (WId)wId, appId, true); dialog->show(); } void SolidUiServer::onPassphraseDialogCompleted(const QString &pass, bool keep) { KPasswordDialog *dialog = qobject_cast(sender()); if (dialog) { QString returnService = dialog->property("soliduiserver.returnService").toString(); QString returnObject = dialog->property("soliduiserver.returnObject").toString(); QDBusInterface returnIface(returnService, returnObject); QDBusReply reply = returnIface.call(QStringLiteral("passphraseReply"), pass); QString udi = dialog->property("soliduiserver.udi").toString(); m_idToPassphraseDialog.remove(returnService+':'+udi); if (!reply.isValid()) { qWarning() << "Impossible to send the passphrase to the application, D-Bus said: " << reply.error().name() << ", " << reply.error().message() << endl; return; // don't save into wallet if an error occurs } if (keep) { // save the password into the wallet KWallet::Wallet * wallet = KWallet::Wallet::openWallet(KWallet::Wallet::LocalWallet(), 0); if (wallet) { const QString folderName = QString::fromLatin1("SolidLuks"); const QString uuid = dialog->property("soliduiserver.uuid").toString(); if (!wallet->hasFolder(folderName)) wallet->createFolder(folderName); if (wallet->setFolder(folderName)) wallet->writePassword(uuid, pass); wallet->closeWallet(wallet->walletName(), false); delete wallet; } } } } void SolidUiServer::onPassphraseDialogRejected() { onPassphraseDialogCompleted(QString(), false); } void SolidUiServer::reparentDialog(QWidget *dialog, WId wId, const QString &appId, bool modal) { Q_UNUSED(appId); // Code borrowed from kwalletd KWindowSystem::setMainWindow(dialog, wId); // correct, set dialog parent #ifdef HAVE_X11 if (modal) { KWindowSystem::setState(dialog->winId(), NET::Modal); } else { KWindowSystem::clearState(dialog->winId(), NET::Modal); } #endif // allow dialog activation even if it interrupts, better than trying hacks // with keeping the dialog on top or on all desktops KUserTimestamp::updateUserTimestamp(); } #include "soliduiserver.moc" diff --git a/statusnotifierwatcher/statusnotifierwatcher.cpp b/statusnotifierwatcher/statusnotifierwatcher.cpp index 8995f4f3d..e9879b74b 100644 --- a/statusnotifierwatcher/statusnotifierwatcher.cpp +++ b/statusnotifierwatcher/statusnotifierwatcher.cpp @@ -1,137 +1,135 @@ /*************************************************************************** * Copyright 2009 by Marco Martin * * * * 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; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "statusnotifierwatcher.h" #include #include #include #include #include "statusnotifierwatcheradaptor.h" #include "statusnotifieritem_interface.h" -K_PLUGIN_FACTORY_WITH_JSON(StatusNotifierWatcherFactory, - "statusnotifierwatcher.json", - registerPlugin();) +K_PLUGIN_CLASS_WITH_JSON(StatusNotifierWatcher, "statusnotifierwatcher.json") StatusNotifierWatcher::StatusNotifierWatcher(QObject *parent, const QList&) : KDEDModule(parent) { setModuleName(QStringLiteral("StatusNotifierWatcher")); new StatusNotifierWatcherAdaptor(this); QDBusConnection dbus = QDBusConnection::sessionBus(); dbus.registerObject(QStringLiteral("/StatusNotifierWatcher"), this); dbus.registerService(QStringLiteral("org.kde.StatusNotifierWatcher")); m_serviceWatcher = new QDBusServiceWatcher(this); m_serviceWatcher->setConnection(dbus); m_serviceWatcher->setWatchMode(QDBusServiceWatcher::WatchForUnregistration); connect(m_serviceWatcher, &QDBusServiceWatcher::serviceUnregistered, this, &StatusNotifierWatcher::serviceUnregistered); } StatusNotifierWatcher::~StatusNotifierWatcher() { QDBusConnection dbus = QDBusConnection::sessionBus(); dbus.unregisterService(QStringLiteral("org.kde.StatusNotifierWatcher")); } void StatusNotifierWatcher::RegisterStatusNotifierItem(const QString &serviceOrPath) { QString service; QString path; if (serviceOrPath.startsWith(QLatin1Char('/'))) { service = message().service(); path = serviceOrPath; } else { service = serviceOrPath; path = QStringLiteral("/StatusNotifierItem"); } QString notifierItemId = service + path; if (QDBusConnection::sessionBus().interface()->isServiceRegistered(service).value() && !m_registeredServices.contains(notifierItemId)) { qDebug()<<"Registering" << notifierItemId << "to system tray"; //check if the service has registered a SystemTray object org::kde::StatusNotifierItem trayclient(service, path, QDBusConnection::sessionBus()); if (trayclient.isValid()) { m_registeredServices.append(notifierItemId); m_serviceWatcher->addWatchedService(service); emit StatusNotifierItemRegistered(notifierItemId); } } } QStringList StatusNotifierWatcher::RegisteredStatusNotifierItems() const { return m_registeredServices; } void StatusNotifierWatcher::serviceUnregistered(const QString& name) { qDebug()<<"Service "<< name << "unregistered"; m_serviceWatcher->removeWatchedService(name); QString match = name + QLatin1Char('/'); QStringList::Iterator it = m_registeredServices.begin(); while (it != m_registeredServices.end()) { if (it->startsWith(match)) { QString name = *it; it = m_registeredServices.erase(it); emit StatusNotifierItemUnregistered(name); } else { ++it; } } if (m_statusNotifierHostServices.contains(name)) { m_statusNotifierHostServices.remove(name); emit StatusNotifierHostUnregistered(); } } void StatusNotifierWatcher::RegisterStatusNotifierHost(const QString &service) { if (service.contains(QStringLiteral("org.kde.StatusNotifierHost-")) && QDBusConnection::sessionBus().interface()->isServiceRegistered(service).value() && !m_statusNotifierHostServices.contains(service)) { qDebug()<<"Registering"<addWatchedService(service); emit StatusNotifierHostRegistered(); } } bool StatusNotifierWatcher::IsStatusNotifierHostRegistered() const { return !m_statusNotifierHostServices.isEmpty(); } int StatusNotifierWatcher::ProtocolVersion() const { return 0; } #include "statusnotifierwatcher.moc" diff --git a/systemmonitor/kdedksysguard.cpp b/systemmonitor/kdedksysguard.cpp index 79a2808e2..10637cd62 100644 --- a/systemmonitor/kdedksysguard.cpp +++ b/systemmonitor/kdedksysguard.cpp @@ -1,79 +1,77 @@ /* * Copyright (C) 2014 Vishesh Handa * Copyright (C) 2006 Aaron Seigo * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License version 2 as * published by the Free Software Foundation * * 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 Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kdedksysguard.h" #include #include #include #include #include #include #include #include #include #include #include -K_PLUGIN_FACTORY_WITH_JSON(KSysGuardFactory, - "ksysguard.json", - registerPlugin();) +K_PLUGIN_CLASS_WITH_JSON(KDEDKSysGuard, "ksysguard.json") KDEDKSysGuard::KDEDKSysGuard(QObject* parent, const QVariantList&) : KDEDModule(parent) { QTimer::singleShot(0, this, &KDEDKSysGuard::init); } KDEDKSysGuard::~KDEDKSysGuard() { } void KDEDKSysGuard::init() { KActionCollection* actionCollection = new KActionCollection(this); QAction* action = actionCollection->addAction(QStringLiteral("Show System Activity")); action->setText(i18n("Show System Activity")); connect(action, &QAction::triggered, this, &KDEDKSysGuard::showTaskManager); KGlobalAccel::self()->setGlobalShortcut(action, QKeySequence(Qt::CTRL + Qt::Key_Escape)); } void KDEDKSysGuard::showTaskManager() { QDBusConnection con = QDBusConnection::sessionBus(); QDBusConnectionInterface* interface = con.interface(); if (interface->isServiceRegistered(QStringLiteral("org.kde.systemmonitor"))) { QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.systemmonitor"), QStringLiteral("/"), QStringLiteral("org.qtproject.Qt.QWidget"), QStringLiteral("close")); con.asyncCall(msg); } else { const QString exe = QStandardPaths::findExecutable(QStringLiteral("systemmonitor")); QProcess::startDetached(exe, QStringList()); } } #include "kdedksysguard.moc"