vfs: Fix plugin decision in wizards, sanitize loading
authorChristian Kamm <mail@ckamm.de>
Tue, 13 Nov 2018 10:46:26 +0000 (11:46 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:23 +0000 (10:58 +0100)
21 files changed:
src/common/common.cmake
src/common/plugin.cpp [new file with mode: 0644]
src/common/plugin.h [new file with mode: 0644]
src/common/vfs.cpp
src/common/vfs.h
src/gui/accountsettings.cpp
src/gui/application.cpp
src/gui/folder.cpp
src/gui/folder.h
src/gui/folderman.cpp
src/gui/folderman.h
src/gui/folderwizard.cpp
src/gui/owncloudsetupwizard.cpp
src/gui/wizard/owncloudadvancedsetuppage.cpp
src/gui/wizard/owncloudwizard.cpp
src/libsync/CMakeLists.txt
src/libsync/logger.h
src/libsync/plugin.cpp [deleted file]
src/libsync/plugin.h [deleted file]
src/libsync/vfs/suffix/vfs_suffix.h
test/testsyncvirtualfiles.cpp

index 3caf829f71e9b46b8d0c9bc26dcfcd811ceb7c53..88c870933ff58861fa6711e92ae704dd77c886e4 100644 (file)
@@ -10,4 +10,5 @@ set(common_SOURCES
     ${CMAKE_CURRENT_LIST_DIR}/utility.cpp
     ${CMAKE_CURRENT_LIST_DIR}/remotepermissions.cpp
     ${CMAKE_CURRENT_LIST_DIR}/vfs.cpp
+    ${CMAKE_CURRENT_LIST_DIR}/plugin.cpp
 )
diff --git a/src/common/plugin.cpp b/src/common/plugin.cpp
new file mode 100644 (file)
index 0000000..59e5705
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) by Dominik Schmidt <dschmidt@owncloud.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "plugin.h"
+
+#include "config.h"
+
+#include <QPluginLoader>
+#include <QDir>
+#include <QLoggingCategory>
+
+Q_LOGGING_CATEGORY(lcPluginLoader, "pluginLoader", QtInfoMsg)
+
+namespace OCC {
+
+PluginFactory::~PluginFactory() = default;
+
+QString PluginLoader::pluginName(const QString &type, const QString &name)
+{
+    return QString(QLatin1String("%1sync_%2_%3"))
+            .arg(APPLICATION_EXECUTABLE)
+            .arg(type)
+            .arg(name);
+}
+
+bool PluginLoader::isAvailable(const QString &type, const QString &name)
+{
+    QPluginLoader loader(pluginName(type, name));
+    return loader.load();
+}
+
+QObject *PluginLoader::load(const QString &type, const QString &name)
+{
+    QString fileName = pluginName(type, name);
+    QPluginLoader pluginLoader(fileName);
+    if (pluginLoader.load()) {
+        qCInfo(lcPluginLoader) << "Loaded plugin" << fileName;
+    } else {
+        qCWarning(lcPluginLoader) << "Could not load plugin"
+                                  << fileName <<":"
+                                  << pluginLoader.errorString()
+                                  << "from" << QDir::currentPath();
+    }
+
+    return pluginLoader.instance();
+}
+
+QObject *PluginLoader::create(const QString &type, const QString &name, QObject *parent)
+{
+    auto factory = qobject_cast<PluginFactory *>(load(type, name));
+    if (!factory) {
+        return nullptr;
+    } else {
+        return factory->create(parent);
+    }
+}
+
+}
diff --git a/src/common/plugin.h b/src/common/plugin.h
new file mode 100644 (file)
index 0000000..b6471f8
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) by Dominik Schmidt <dschmidt@owncloud.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#pragma once
+
+#include "ocsynclib.h"
+#include <QObject>
+#include <QPluginLoader>
+
+namespace OCC {
+
+class OCSYNC_EXPORT PluginFactory
+{
+public:
+    ~PluginFactory();
+    virtual QObject* create(QObject* parent) = 0;
+};
+
+template<class PLUGIN_CLASS>
+class DefaultPluginFactory : public PluginFactory
+{
+public:
+    QObject* create(QObject *parent) override
+    {
+        return new PLUGIN_CLASS(parent);
+    }
+};
+
+class OCSYNC_EXPORT PluginLoader
+{
+public:
+    static QString pluginName(const QString &type, const QString &name);
+
+    bool isAvailable(const QString &type, const QString &name);
+    QObject *load(const QString &type, const QString &name);
+    QObject *create(const QString &type, const QString &name, QObject *parent = nullptr);
+};
+
+}
+
+Q_DECLARE_INTERFACE(OCC::PluginFactory, "org.owncloud.PluginFactory")
index b6f4646eb62a70f3d2baf552de92b075592f26f9..7cfb895e1689d1032101af350aafee95a40a83ec 100644 (file)
@@ -17,6 +17,7 @@
  */
 
 #include "vfs.h"
+#include "plugin.h"
 
 using namespace OCC;
 
@@ -56,3 +57,38 @@ bool Vfs::modeFromString(const QString &str, Mode *mode)
     }
     return false;
 }
+
+static QString modeToPluginName(Vfs::Mode mode)
+{
+    if (mode == Vfs::WithSuffix)
+        return "suffix";
+    if (mode == Vfs::WindowsCfApi)
+        return "win";
+    return QString();
+}
+
+bool OCC::isVfsPluginAvailable(Vfs::Mode mode)
+{
+    auto name = modeToPluginName(mode);
+    if (name.isEmpty())
+        return false;
+    return PluginLoader().load("vfs", name);
+}
+
+Vfs::Mode OCC::bestAvailableVfsMode()
+{
+    if (isVfsPluginAvailable(Vfs::WindowsCfApi)) {
+        return Vfs::WindowsCfApi;
+    } else if (isVfsPluginAvailable(Vfs::WithSuffix)) {
+        return Vfs::WithSuffix;
+    }
+    return Vfs::Off;
+}
+
+Vfs *OCC::createVfsFromPlugin(Vfs::Mode mode, QObject *parent)
+{
+    auto name = modeToPluginName(mode);
+    if (name.isEmpty())
+        return nullptr;
+    return qobject_cast<Vfs *>(PluginLoader().create("vfs", name, parent));
+}
index 511551c87b82e840a9649b1bd53dadd546c6d7ea..23e11a0c550431108af7ef56cdd7d645f766ac94 100644 (file)
@@ -94,4 +94,8 @@ signals:
     void doneHydrating();
 };
 
+bool isVfsPluginAvailable(Vfs::Mode mode) OCSYNC_EXPORT;
+Vfs::Mode bestAvailableVfsMode() OCSYNC_EXPORT;
+Vfs *createVfsFromPlugin(Vfs::Mode mode, QObject *parent) OCSYNC_EXPORT;
+
 } // namespace OCC
index 630a47f598a03f4e14c676d3aaf02ece38ccf1eb..e4dbe7256ed7045ad93f7ceaeb894e7273eff3f1 100644 (file)
@@ -537,8 +537,7 @@ void AccountSettings::slotFolderWizardAccepted()
         folderWizard->property("targetPath").toString());
 
     if (folderWizard->property("useVirtualFiles").toBool()) {
-        // ### Determine which vfs is available?
-        definition.virtualFilesMode = Vfs::WindowsCfApi;
+        definition.virtualFilesMode = bestAvailableVfsMode();
     }
 
     {
index 310f055c1e5cc2d8657d8a969b02bfd943c1ca01..e25f1c280b1d945fb09329aadeb9b6f422fcbe2e 100644 (file)
@@ -42,6 +42,7 @@
 #include "owncloudsetupwizard.h"
 #include "version.h"
 #include "csync_exclude.h"
+#include "common/vfs.h"
 
 #include "config.h"
 
@@ -268,6 +269,15 @@ Application::Application(int &argc, char **argv)
     if (!AbstractNetworkJob::httpTimeout)
         AbstractNetworkJob::httpTimeout = cfg.timeout();
 
+    // Check vfs plugins
+    if (Theme::instance()->showVirtualFilesOption() && bestAvailableVfsMode() == Vfs::Off) {
+        qCWarning(lcApplication) << "Theme wants to show vfs mode, but no vfs plugins are available";
+    }
+    if (isVfsPluginAvailable(Vfs::WindowsCfApi))
+        qCInfo(lcApplication) << "VFS windows plugin is available";
+    if (isVfsPluginAvailable(Vfs::WithSuffix))
+        qCInfo(lcApplication) << "VFS suffix plugin is available";
+
     _folderManager.reset(new FolderMan);
 
     connect(this, &SharedTools::QtSingleApplication::messageReceived, this, &Application::slotParseMessage);
index 3f284938c46d90e966cc5ec87c8002913f47a241..1d9bbc0f35a8d409633540a242dc2f936d996780 100644 (file)
@@ -33,7 +33,6 @@
 #include "localdiscoverytracker.h"
 #include "csync_exclude.h"
 #include "common/vfs.h"
-#include "plugin.h"
 #include "creds/abstractcredentials.h"
 
 #include <QTimer>
@@ -52,7 +51,7 @@ namespace OCC {
 Q_LOGGING_CATEGORY(lcFolder, "nextcloud.gui.folder", QtInfoMsg)
 
 Folder::Folder(const FolderDefinition &definition,
-    AccountState *accountState,
+    AccountState *accountState, Vfs *vfs,
     QObject *parent)
     : QObject(parent)
     , _accountState(accountState)
@@ -62,6 +61,7 @@ Folder::Folder(const FolderDefinition &definition,
     , _consecutiveFollowUpSyncs(0)
     , _journal(_definition.absoluteJournalPath())
     , _fileLog(new SyncRunFileLog)
+    , _vfs(vfs)
 {
     _timeSinceLastSyncStart.start();
     _timeSinceLastSyncDone.start();
@@ -118,32 +118,26 @@ Folder::Folder(const FolderDefinition &definition,
     connect(_engine.data(), &SyncEngine::itemCompleted,
         _localDiscoveryTracker.data(), &LocalDiscoveryTracker::slotItemCompleted);
 
-    // TODO cfapi: Move to function. Is this platform-universal?
-    PluginLoader pluginLoader;
-    if (_definition.virtualFilesMode == Vfs::WindowsCfApi) {
-        _vfs = pluginLoader.create<Vfs>("vfs", "win", this);
-    }
-    if (_definition.virtualFilesMode == Vfs::WithSuffix) {
-        _vfs = pluginLoader.create<Vfs>("vfs", "suffix", this);
-
-        // Attempt to switch to winvfs mode?
-        if (_vfs && _definition.upgradeVfsMode) {
-            if (auto winvfs = pluginLoader.create<Vfs>("vfs", "win", this)) {
-                // Set "suffix" vfs options and wipe the existing suffix files
-                SyncEngine::wipeVirtualFiles(path(), _journal, _vfs);
-
-                // Then switch to winvfs mode
-                _vfs = winvfs;
-                _definition.virtualFilesMode = Vfs::WindowsCfApi;
-                saveToSettings();
-            }
+    // Potentially upgrade suffix vfs to windows vfs
+    if (_definition.virtualFilesMode == Vfs::WithSuffix && _definition.upgradeVfsMode) {
+        if (auto winvfs = createVfsFromPlugin(Vfs::WindowsCfApi, this)) {
+            // Wipe the existing suffix files from fs and journal
+            SyncEngine::wipeVirtualFiles(path(), _journal, _vfs);
+
+            // Then switch to winvfs mode
+            delete _vfs;
+            _vfs = winvfs;
+            _definition.virtualFilesMode = Vfs::WindowsCfApi;
+            saveToSettings();
         }
     }
+
+    // Initialize the vfs plugin
     if (_definition.virtualFilesMode != Vfs::Off) {
-        if (!_vfs) {
-            // ### error handling; possibly earlier than in the ctor
-            qFatal("Could not load any vfs plugin.");
-        }
+        ENFORCE(_vfs);
+        ENFORCE(_vfs->mode() == _definition.virtualFilesMode);
+
+        _vfs->setParent(this);
 
         VfsSetupParams vfsParams;
         vfsParams.filesystemPath = path();
index b266ed402de7d836de4735922a429f47da51b03e..ed6e1a314659fdb8b2e5ef1938e8cd60cbde6254 100644 (file)
@@ -101,7 +101,11 @@ class Folder : public QObject
     Q_OBJECT
 
 public:
-    Folder(const FolderDefinition &definition, AccountState *accountState, QObject *parent = nullptr);
+    /** Create a new Folder
+     *
+     * The vfs instance will be parented to this.
+     */
+    Folder(const FolderDefinition &definition, AccountState *accountState, Vfs *vfs, QObject *parent = nullptr);
 
     ~Folder();
 
index 43ceae7876ff63989c788d0ae3fef952351b0823..501d5b7ec1ca3c099867814d883a443056acb640 100644 (file)
@@ -259,7 +259,12 @@ void FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account,
                     qCInfo(lcFolderMan) << "Successfully migrated syncjournal database.";
                 }
 
-                Folder *f = addFolderInternal(folderDefinition, account.data());
+                Vfs *vfs = createVfsFromPlugin(folderDefinition.virtualFilesMode, nullptr);
+                if (!vfs && folderDefinition.virtualFilesMode != Vfs::Off) {
+                    qCWarning(lcFolderMan) << "Could not load plugin for mode" << folderDefinition.virtualFilesMode;
+                }
+
+                Folder *f = addFolderInternal(folderDefinition, account.data(), vfs);
                 f->saveToSettings();
 
                 continue;
@@ -279,7 +284,13 @@ void FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account,
                 SyncJournalDb::maybeMigrateDb(folderDefinition.localPath, folderDefinition.absoluteJournalPath());
             }
 
-            Folder *f = addFolderInternal(std::move(folderDefinition), account.data());
+            Vfs *vfs = createVfsFromPlugin(folderDefinition.virtualFilesMode, nullptr);
+            if (!vfs && folderDefinition.virtualFilesMode != Vfs::Off) {
+                // TODO: Must do better error handling
+                qFatal("Could not load plugin");
+            }
+
+            Folder *f = addFolderInternal(std::move(folderDefinition), account.data(), vfs);
             if (f) {
                 // Migration: Mark folders that shall be saved in a backwards-compatible way
                 if (backwardsCompatible)
@@ -494,7 +505,8 @@ Folder *FolderMan::setupFolderFromOldConfigFile(const QString &file, AccountStat
     folderDefinition.paused = paused;
     folderDefinition.ignoreHiddenFiles = ignoreHiddenFiles();
 
-    folder = addFolderInternal(folderDefinition, accountState);
+    Vfs *vfs = nullptr;
+    folder = addFolderInternal(folderDefinition, accountState, vfs);
     if (folder) {
         QStringList blackList = settings.value(QLatin1String("blackList")).toStringList();
         if (!blackList.empty()) {
@@ -982,7 +994,13 @@ Folder *FolderMan::addFolder(AccountState *accountState, const FolderDefinition
         return nullptr;
     }
 
-    auto folder = addFolderInternal(definition, accountState);
+    Vfs *vfs = createVfsFromPlugin(folderDefinition.virtualFilesMode, nullptr);
+    if (!vfs && folderDefinition.virtualFilesMode != Vfs::Off) {
+        qCWarning(lcFolderMan) << "Could not load plugin for mode" << folderDefinition.virtualFilesMode;
+        return 0;
+    }
+
+    auto folder = addFolderInternal(definition, accountState, vfs);
 
     // Migration: The first account that's configured for a local folder shall
     // be saved in a backwards-compatible way.
@@ -994,6 +1012,7 @@ Folder *FolderMan::addFolder(AccountState *accountState, const FolderDefinition
     folder->setSaveBackwardsCompatible(oneAccountOnly);
 
     if (folder) {
+        folder->setSaveBackwardsCompatible(oneAccountOnly);
         folder->saveToSettings();
         emit folderSyncStateChange(folder);
         emit folderListChanged(_folderMap);
@@ -1003,8 +1022,10 @@ Folder *FolderMan::addFolder(AccountState *accountState, const FolderDefinition
     return folder;
 }
 
-Folder *FolderMan::addFolderInternal(FolderDefinition folderDefinition,
-    AccountState *accountState)
+Folder *FolderMan::addFolderInternal(
+    FolderDefinition folderDefinition,
+    AccountState *accountState,
+    Vfs *vfs)
 {
     auto alias = folderDefinition.alias;
     int count = 0;
@@ -1015,7 +1036,7 @@ Folder *FolderMan::addFolderInternal(FolderDefinition folderDefinition,
         folderDefinition.alias = alias + QString::number(++count);
     }
 
-    auto folder = new Folder(folderDefinition, accountState, this);
+    auto folder = new Folder(folderDefinition, accountState, vfs, this);
 
     if (_navigationPaneHelper.showInExplorerNavigationPane() && folderDefinition.navigationPaneClsid.isNull()) {
         folder->setNavigationPaneClsid(QUuid::createUuid());
index e083d158f4d1b778635900897fe99b9c431fd6c8..bc49167b00375f5bae48bdf9622fac544b567aed 100644 (file)
@@ -293,7 +293,7 @@ private:
      *  does not set an account on the new folder.
       */
     Folder *addFolderInternal(FolderDefinition folderDefinition,
-        AccountState *accountState);
+        AccountState *accountState, Vfs *vfs);
 
     /* unloads a folder object, does not delete it */
     void unloadFolder(Folder *);
index 47603ed5021786eff8894c503c212d0b1778dcf9..32cfc7b6198d07ea7b6b74b1549c225b6ff6cd42 100644 (file)
@@ -494,7 +494,7 @@ FolderWizardSelectiveSync::FolderWizardSelectiveSync(const AccountPtr &account)
     _selectiveSync = new SelectiveSyncWidget(account, this);
     layout->addWidget(_selectiveSync);
 
-    if (Theme::instance()->showVirtualFilesOption()) {
+    if (Theme::instance()->showVirtualFilesOption() && bestAvailableVfsMode() != Vfs::Off) {
         _virtualFilesCheckBox = new QCheckBox(tr("Use virtual files instead of downloading content immediately (experimental)"));
         connect(_virtualFilesCheckBox, &QCheckBox::clicked, this, &FolderWizardSelectiveSync::virtualFilesCheckboxClicked);
         connect(_virtualFilesCheckBox, &QCheckBox::stateChanged, this, [this](int state) {
index d57c7e1a11108a334ebcf790d4d865fd2367a495..eb6656c76062d6ad9076f56a659063ea6b358b89 100644 (file)
@@ -636,8 +636,7 @@ void OwncloudSetupWizard::slotAssistantFinished(int result)
             folderDefinition.targetPath = FolderDefinition::prepareTargetPath(_remoteFolder);
             folderDefinition.ignoreHiddenFiles = folderMan->ignoreHiddenFiles();
             if (_ocWizard->useVirtualFileSync()) {
-                // ### determine best vfs mode!
-                folderDefinition.virtualFilesMode = Vfs::WindowsCfApi;
+                folderDefinition.virtualFilesMode = bestAvailableVfsMode();
             }
             if (folderMan->navigationPaneHelper().showInExplorerNavigationPane())
                 folderDefinition.navigationPaneClsid = QUuid::createUuid();
index 09e3928836081ee4cf5a313b341830a9497d4f4b..dadbd0735363e69c59c7f98ecfdc8717cc7906dd 100644 (file)
@@ -102,7 +102,7 @@ void OwncloudAdvancedSetupPage::initializePage()
 {
     WizardCommon::initErrorLabel(_ui.errorLabel);
 
-    if (!Theme::instance()->showVirtualFilesOption()) {
+    if (!Theme::instance()->showVirtualFilesOption() || bestAvailableVfsMode() == Vfs::Off) {
         // If the layout were wrapped in a widget, the auto-grouping of the
         // radio buttons no longer works and there are surprising margins.
         // Just manually hide the button and remove the layout.
index 4c9f4e6c1f6035011418f647b64e9017a5eaeb16..7079f2fc1629e3952f60b4416461d3fe17712565 100644 (file)
@@ -31,6 +31,8 @@
 #include "wizard/webviewpage.h"
 #include "wizard/flow2authcredspage.h"
 
+#include "common/vfs.h"
+
 #include "QProgressIndicator.h"
 
 #include <QtCore>
@@ -328,16 +330,32 @@ void OwncloudWizard::bringToTop()
 
 void OwncloudWizard::askExperimentalVirtualFilesFeature(const std::function<void(bool enable)> &callback)
 {
-    auto msgBox = new QMessageBox(
-        QMessageBox::Warning,
-        tr("Enable experimental feature?"),
-        tr("When the \"virtual files\" mode is enabled no files will be downloaded initially. "
-           "Instead, a tiny \"%1\" file will be created for each file that exists on the server. "
-           "The contents can be downloaded by running these files or by using their context menu."
-           "\n\n"
-           "This is a new, experimental mode. If you decide to use it, please report any "
-           "issues that come up.")
-            .arg(APPLICATION_DOTVIRTUALFILE_SUFFIX));
+    auto bestVfsMode = bestAvailableVfsMode();
+    QMessageBox *msgBox = nullptr;
+    if (bestVfsMode == Vfs::WindowsCfApi) {
+        msgBox = new QMessageBox(
+            QMessageBox::Warning,
+            tr("Enable experimental feature?"),
+            tr("When the \"virtual files\" mode is enabled no files will be downloaded initially. "
+               "Instead a placeholder file will be created for each file that exists on the server. "
+               "When a file is opened its contents will be downloaded automatically. "
+               "Alternatively files can be downloaded manually by using their context menu."
+               "\n\n"
+               "This is a new, experimental mode. If you decide to use it, please report any "
+               "issues that come up."));
+    } else {
+        ASSERT(bestVfsMode == Vfs::WithSuffix);
+        msgBox = new QMessageBox(
+            QMessageBox::Warning,
+            tr("Enable experimental feature?"),
+            tr("When the \"virtual files\" mode is enabled no files will be downloaded initially. "
+               "Instead, a tiny \"%1\" file will be created for each file that exists on the server. "
+               "The contents can be downloaded by running these files or by using their context menu."
+               "\n\n"
+               "This is a new, experimental mode. If you decide to use it, please report any "
+               "issues that come up.")
+                .arg(APPLICATION_DOTVIRTUALFILE_SUFFIX));
+    }
     msgBox->addButton(tr("Enable experimental mode"), QMessageBox::AcceptRole);
     msgBox->addButton(tr("Stay safe"), QMessageBox::RejectRole);
     connect(msgBox, &QMessageBox::finished, msgBox, [callback, msgBox](int result) {
index bea212d103cfc418c344a073a0a4cc76f11159d6..353acf3d7b2a7553b8aeb6bd861d4e5a229a8565 100644 (file)
@@ -33,7 +33,6 @@ set(libsync_SRCS
     networkjobs.cpp
     owncloudpropagator.cpp
     nextcloudtheme.cpp
-    plugin.cpp
     progressdispatcher.cpp
     propagatorjobs.cpp
     propagatedownload.cpp
index 12973c71c1a4079cf0b61af75a94d256e4cff0be..c8ff3bce845b10502396194eade1eaff04cebc93 100644 (file)
@@ -23,7 +23,6 @@
 #include <qmutex.h>
 
 #include "common/utility.h"
-#include "logger.h"
 #include "owncloudlib.h"
 
 namespace OCC {
diff --git a/src/libsync/plugin.cpp b/src/libsync/plugin.cpp
deleted file mode 100644 (file)
index f3c4c85..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (C) by Dominik Schmidt <dschmidt@owncloud.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include "plugin.h"
-
-#include "config.h"
-#include "logger.h"
-
-#include <QPluginLoader>
-#include <QDir>
-
-Q_LOGGING_CATEGORY(lcPluginLoader, "pluginLoader", QtInfoMsg)
-
-namespace OCC {
-
-PluginFactory::~PluginFactory() = default;
-
-QObject *PluginLoader::createInternal(const QString& type, const QString &name, QObject* parent)
-{
-    auto factory = load<PluginFactory>(type, name);
-    if (!factory) {
-        return nullptr;
-    } else {
-        return factory->create(parent);
-    }
-}
-
-QString PluginLoader::pluginName(const QString &type, const QString &name)
-{
-    return QString(QLatin1String("%1sync_%2_%3"))
-            .arg(APPLICATION_EXECUTABLE)
-            .arg(type)
-            .arg(name);
-}
-
-QObject *PluginLoader::loadPluginInternal(const QString& type, const QString &name)
-{
-    QString fileName = pluginName(type, name);
-    QPluginLoader pluginLoader(fileName);
-    auto plugin = pluginLoader.load();
-    if(plugin) {
-        qCInfo(lcPluginLoader) << "Loaded plugin" << fileName;
-    } else {
-        qCWarning(lcPluginLoader) << "Could not load plugin"
-                                  << fileName <<":"
-                                  << pluginLoader.errorString()
-                                  << "from" << QDir::currentPath();
-    }
-
-    return pluginLoader.instance();
-}
-
-}
diff --git a/src/libsync/plugin.h b/src/libsync/plugin.h
deleted file mode 100644 (file)
index e8f8aec..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (C) by Dominik Schmidt <dschmidt@owncloud.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#pragma once
-
-#include "owncloudlib.h"
-#include <QObject>
-#include <QPluginLoader>
-
-namespace OCC {
-
-class OWNCLOUDSYNC_EXPORT PluginFactory
-{
-public:
-    ~PluginFactory();
-    virtual QObject* create(QObject* parent) = 0;
-};
-
-template<class PLUGIN_CLASS>
-class DefaultPluginFactory : public PluginFactory
-{
-public:
-    QObject* create(QObject* parent) override
-    {
-        return new PLUGIN_CLASS(parent);
-    }
-};
-
-class OWNCLOUDSYNC_EXPORT PluginLoader
-{
-public:
-    static QString pluginName(const QString &type, const QString &name);
-
-    template<class PLUGIN_CLASS, typename ... Args>
-    PLUGIN_CLASS *create(Args&& ... args)
-    {
-        return qobject_cast<PLUGIN_CLASS*>(createInternal(std::forward<Args>(args)...));
-    }
-
-private:
-    template<class FACTORY_CLASS, typename ... Args>
-    FACTORY_CLASS *load(Args&& ... args)
-    {
-        return qobject_cast<FACTORY_CLASS*>(loadPluginInternal(std::forward<Args>(args)...));
-    }
-
-    QObject *loadPluginInternal(const QString& type, const QString &name);
-    QObject *createInternal(const QString& type, const QString &name, QObject* parent = nullptr);
-};
-
-}
-
-Q_DECLARE_INTERFACE(OCC::PluginFactory, "org.owncloud.PluginFactory")
index d66f95a7f0291ea79f4dc1cfe69b44830f8607d8..0387832c96e0acdd592e29091a0ca3b62f56026f 100644 (file)
@@ -17,7 +17,7 @@
 #include <QScopedPointer>
 
 #include "common/vfs.h"
-#include "plugin.h"
+#include "common/plugin.h"
 
 namespace OCC {
 
index 5a271fd0f0e5c0075d45f676814eaf46fe1ec1da..a90f006c96fe15040a6e921a37f4fa0b55492785 100644 (file)
@@ -8,7 +8,6 @@
 #include <QtTest>
 #include "syncenginetestutils.h"
 #include "common/vfs.h"
-#include "plugin.h"
 #include <syncengine.h>
 
 using namespace OCC;
@@ -63,7 +62,7 @@ void markForDehydration(FakeFolder &folder, const QByteArray &path)
 SyncOptions vfsSyncOptions()
 {
     SyncOptions options;
-    options._vfs = PluginLoader().create<Vfs>("vfs", "suffix");
+    options._vfs = createVfsFromPlugin(Vfs::WithSuffix, nullptr);
     return options;
 }