File indexing completed on 2024-04-21 04:58:10

0001 /*
0002     SPDX-FileCopyrightText: 2009 David Faure <faure@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #ifndef MODULE_MANAGER_H
0008 #define MODULE_MANAGER_H
0009 
0010 #include <KPluginMetaData>
0011 
0012 #include <QStringList>
0013 
0014 class KConfigGroup;
0015 
0016 /**
0017  * The module manager is responsible for discovering the modules (i.e. tabs,
0018  * i.e. plugins, i.e. desktop files) to use in the sidebar, and for updating them.
0019  * This class contains no GUI code, so that it can be unit-tested.
0020  */
0021 class ModuleManager
0022 {
0023 public:
0024     ModuleManager(KConfigGroup *config);
0025 
0026     /// Returns the filenames of the modules that should be shown in the GUI
0027     /// Example: "home.desktop" (default module), "dirtree1.desktop" (added by user)...
0028     QStringList modules() const;
0029 
0030     /// Returns the names of the available plugin libraries
0031     /// Example: konqsidebar_tree, konqsidebar_web
0032     QVector<KPluginMetaData> availablePlugins() const;
0033 
0034     /// Returns the paths of all modules that match a given filter, like websidebarplugin*.desktop
0035     QStringList localModulePaths(const QString &filter) const;
0036 
0037     /// Returns the relative path in the "data" resource, for a given module
0038     QString moduleDataPath(const QString &fileName) const;
0039     /// Returns the relative path of the entries directory in the "data" resource
0040     QString relativeDataPath() const
0041     {
0042         return QStringLiteral("konqsidebartng/entries/");
0043     }
0044     /// Returns the full path for a given module. TEMP HACK, TO BE REMOVED
0045     QString moduleFullPath(const QString &fileName) const;
0046 
0047     void saveOpenViews(const QStringList &fileName);
0048     void restoreDeletedButtons();
0049     void rollbackToDefault();
0050 
0051     void setModuleName(const QString &fileName, const QString &moduleName);
0052     void setModuleUrl(const QString &fileName, const QUrl &url);
0053     void setModuleIcon(const QString &fileName, const QString &icon);
0054     void setShowHiddenFolders(const QString &fileName, const bool &newState);
0055     int getMaxKDEWeight();
0056     int getNextAvailableKDEWeight();
0057 
0058     /// Find a unique filename for a new module, based on a template name
0059     /// like "dirtree%1.desktop".
0060     /// @return the full path. templ is modified to contain the filename only.
0061     QString addModuleFromTemplate(QString &templ);
0062 
0063     /// Called when a module was added
0064     void moduleAdded(const QString &fileName);
0065 
0066     /// Remove a module (deletes the local .desktop file)
0067     void removeModule(const QString &fileName);
0068 
0069     /**
0070      * @brief The relative directory where to look for plugins
0071      *
0072      * The returned value is suitable to pass as first argument to KPluginMetaData::findPluginById()
0073      * and KPluginMetaData::findPlugins().
0074      * @return the relative directory where plugins are stored
0075      */
0076     static QString pluginDirectory() {return QStringLiteral("konqueror/sidebar");}
0077 
0078 private:
0079     void sortGlobalEntries(QStringList &fileNames) const;
0080 
0081     KConfigGroup *m_config; // owned by SidebarWidget
0082     QString m_localPath; // local path
0083 };
0084 
0085 #endif