diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ set(ACCOUNTSGLIB_DEP_VERSION "1.21") find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Core Widgets) -find_package(KF5 ${KF5_MIN_VERSION} REQUIRED KCMUtils I18n CoreAddons DBusAddons Declarative) +find_package(KF5 ${KF5_MIN_VERSION} REQUIRED KCMUtils I18n CoreAddons DBusAddons Declarative Wallet KIO) find_package(AccountsQt5 ${ACCOUNTSQT_DEP_VERSION} CONFIG) set_package_properties(AccountsQt5 PROPERTIES DESCRIPTION "Accounts management library for Qt applications" diff --git a/src/daemon/CMakeLists.txt b/src/daemon/CMakeLists.txt --- a/src/daemon/CMakeLists.txt +++ b/src/daemon/CMakeLists.txt @@ -17,3 +17,5 @@ set_target_properties(kded_accounts PROPERTIES OUTPUT_NAME accounts) install(TARGETS kded_accounts DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/kded) + +add_subdirectory(kio-webdav) diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -21,6 +21,8 @@ #include #include +#include +#include #include #include @@ -36,50 +38,34 @@ AccountsDaemon::AccountsDaemon(QObject *parent, const QList&) : KDEDModule(parent) { + QMetaObject::invokeMethod(this, "startDaemon", Qt::QueuedConnection); connect(KAccounts::accountsManager(), &Accounts::Manager::accountCreated, this, &AccountsDaemon::accountCreated); connect(KAccounts::accountsManager(), &Accounts::Manager::accountRemoved, this, &AccountsDaemon::accountRemoved); - QStringList pluginPaths; - - const QStringList paths = QCoreApplication::libraryPaths(); - for (const QString &libraryPath : paths) { - QString path(libraryPath + QStringLiteral("/kaccounts/daemonplugins")); - QDir dir(path); + const QVector data = KPluginLoader::findPlugins(QStringLiteral("kaccounts/daemonplugins")); + for (const KPluginMetaData& metadata : data) { - if (!dir.exists()) { + if (!metadata.isValid()) { + qDebug() << "Invalid metadata" << metadata.name(); continue; } - const QStringList dirEntries = dir.entryList(QDir::Files | QDir::NoDotAndDotDot); + KPluginLoader loader(metadata.fileName()); + KPluginFactory* factory = loader.factory(); - for (const QString &file : dirEntries) { - pluginPaths.append(path + '/' + file); + if (!factory) { + qDebug() << "KPluginFactory could not load the plugin:" << metadata.pluginId() << loader.errorString(); + continue; } - } - - for (const QString &pluginPath : qAsConst(pluginPaths)) { - QPluginLoader loader(pluginPath); - if (!loader.load()) { - qWarning() << "Could not create KAccounts daemon plugin: " << pluginPath; - qWarning() << loader.errorString(); + KAccountsDPlugin* plugin = factory->create(this, {}); + if (!plugin) { + qDebug() << "Error loading plugin" << metadata.name() << loader.errorString(); continue; } - QObject *obj = loader.instance(); - if (obj) { - KAccountsDPlugin *plugin = qobject_cast(obj); - if (!plugin) { - qDebug() << "Plugin could not be converted to an KAccountsDPlugin"; - qDebug() << pluginPath; - continue; - } - qDebug() << "Loaded KAccounts plugin" << pluginPath; - m_plugins << plugin; - } else { - qDebug() << "Plugin could not creaate instance" << pluginPath; - } + m_plugins << plugin; } } diff --git a/src/daemon/kio-webdav/CMakeLists.txt b/src/daemon/kio-webdav/CMakeLists.txt --- a/src/daemon/kio-webdav/CMakeLists.txt +++ b/src/daemon/kio-webdav/CMakeLists.txt @@ -6,23 +6,24 @@ createkioservice.cpp removekioservice.cpp) -add_library(kaccounts_kio_webdav_plugin MODULE ${kio-webdav_SRCS}) + +kcoreaddons_add_plugin(kaccounts_kio_webdav_plugin + SOURCES ${kio-webdav_SRCS} + JSON "kio-webdav.json" + INSTALL_NAMESPACE "kaccounts/daemonplugins" + ) target_link_libraries(kaccounts_kio_webdav_plugin Qt5::Core # Qt5::Xml -# Qt5::Widgets -# KF5::CoreAddons -# KF5::ConfigCore -# KF5::Wallet -# KF5::KIOCore -# KF5::I18n + Qt5::Widgets + KF5::CoreAddons + KF5::ConfigCore + KF5::Wallet + KF5::KIOCore + KF5::I18n KF5::DBusAddons kaccounts ${ACCOUNTSQT_LIBRARIES} ${SIGNONQT_LIBRARIES} ) - -install (TARGETS kaccounts_carddav_plugin - DESTINATION ${PLUGIN_INSTALL_DIR}/kaccounts/daemonplugins -) diff --git a/src/daemon/kio-webdav/createkioservice.cpp b/src/daemon/kio-webdav/createkioservice.cpp --- a/src/daemon/kio-webdav/createkioservice.cpp +++ b/src/daemon/kio-webdav/createkioservice.cpp @@ -66,14 +66,15 @@ Accounts::Service service = m_manager->service(m_serviceName); QString host = m_account->value("dav/host").toString(); + QString path = m_account->value("dav/storagePath").toString(); m_account->selectService(service); QString username = data["UserName"].toString(); CreateNetAttachJob *netJob = new CreateNetAttachJob(this); connect(netJob, &CreateNetAttachJob::finished, this, &CreateKioService::netAttachCreated); netJob->setHost(host); - netJob->setPath(m_account->value("dav/path").toString()); + netJob->setPath(path); netJob->setUsername(username); netJob->setPassword(data["Secret"].toString()); netJob->setIcon(service.iconName()); diff --git a/src/daemon/kio-webdav/createnetattachjob.cpp b/src/daemon/kio-webdav/createnetattachjob.cpp --- a/src/daemon/kio-webdav/createnetattachjob.cpp +++ b/src/daemon/kio-webdav/createnetattachjob.cpp @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/daemon/kio-webdav/kio-webdav.json b/src/daemon/kio-webdav/kio-webdav.json new file mode 100644 --- /dev/null +++ b/src/daemon/kio-webdav/kio-webdav.json @@ -0,0 +1,11 @@ +{ + "KPlugin": { + "Description": "Mount WebDAV shares with KIO", + "EnabledByDefault": true, + "Icon": "system-file-manager", + "Id": "kaccounts_kio_webdav", + "License": "GPL", + "Name": "KIO WebDAV", + "Version": "0.1" + } +} diff --git a/src/daemon/kio-webdav/kioservices.h b/src/daemon/kio-webdav/kioservices.h --- a/src/daemon/kio-webdav/kioservices.h +++ b/src/daemon/kio-webdav/kioservices.h @@ -40,7 +40,8 @@ Q_OBJECT public: - explicit KIOServices(QObject* parent =nullptr); + KIOServices(QObject* parent, const QVariantList &args); + ~KIOServices() override; public Q_SLOTS: void onAccountCreated(const Accounts::AccountId accId, const Accounts::ServiceList &serviceList); diff --git a/src/daemon/kio-webdav/kioservices.cpp b/src/daemon/kio-webdav/kioservices.cpp --- a/src/daemon/kio-webdav/kioservices.cpp +++ b/src/daemon/kio-webdav/kioservices.cpp @@ -26,11 +26,17 @@ #include #include -KIOServices::KIOServices(QObject *parent) - : KAccountsDPlugin(parent) +#include + +K_PLUGIN_CLASS_WITH_JSON(KIOServices, "kio-webdav.json") + +KIOServices::KIOServices(QObject *parent, const QVariantList &args) + : KAccountsDPlugin(parent, args) { } +KIOServices::~KIOServices() = default; + void KIOServices::onAccountCreated(const Accounts::AccountId accId, const Accounts::ServiceList &serviceList) { qDebug(); @@ -126,3 +132,5 @@ return QFile::exists(path); } + +#include "kioservices.moc" diff --git a/src/daemon/kio-webdav/removekioservice.cpp b/src/daemon/kio-webdav/removekioservice.cpp --- a/src/daemon/kio-webdav/removekioservice.cpp +++ b/src/daemon/kio-webdav/removekioservice.cpp @@ -22,8 +22,6 @@ #include #include -#include - RemoveKioService::RemoveKioService(QObject *parent) : KJob(parent) { diff --git a/src/lib/kaccountsdplugin.h b/src/lib/kaccountsdplugin.h --- a/src/lib/kaccountsdplugin.h +++ b/src/lib/kaccountsdplugin.h @@ -54,7 +54,7 @@ Q_OBJECT public: - KAccountsDPlugin(QObject *parent = nullptr); + KAccountsDPlugin(QObject *parent, const QVariantList& args); virtual ~KAccountsDPlugin(); public Q_SLOTS: @@ -90,6 +90,4 @@ virtual void onServiceDisabled(const Accounts::AccountId accountId, const Accounts::Service &service) = 0; }; -Q_DECLARE_INTERFACE(KAccountsDPlugin, "org.kde.kaccounts.DPlugin") - #endif // KACCOUNTSDPLUGIN_H diff --git a/src/lib/kaccountsdplugin.cpp b/src/lib/kaccountsdplugin.cpp --- a/src/lib/kaccountsdplugin.cpp +++ b/src/lib/kaccountsdplugin.cpp @@ -21,7 +21,7 @@ #include "kaccountsdplugin.h" -KAccountsDPlugin::KAccountsDPlugin(QObject *parent) +KAccountsDPlugin::KAccountsDPlugin(QObject *parent, const QVariantList& args) : QObject(parent) { }