pluginmodel.h 4.66 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*!
 *    Copyright (C) 2018-2020 Savoir-faire Linux Inc.
 *   Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.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 General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
18 19 20 21 22 23 24 25 26 27 28 29 30
#pragma once

// std
#include <memory>
#include <string>
#include <vector>

// Qt
#include <qobject.h>

// LRC
#include "typedefs.h"

31 32 33 34 35 36 37 38 39
namespace lrc {

namespace api {

namespace plugin {
/**
 * This class describes current plugin Details
 */
struct PluginDetails
40
{
41 42 43 44 45
    QString name = "";
    QString path = "";
    QString iconPath = "";
    bool loaded = false;
};
46

47
struct MediaHandlerDetails
48
{
49 50 51 52 53 54
    QString id = "";
    QString name = "";
    QString iconPath = "";
    QString pluginId = "";
};
} // namespace plugin
55

56
class LIB_EXPORT PluginModel : public QObject
57 58 59 60 61 62 63 64 65 66
{
    Q_OBJECT
public:
    PluginModel();
    ~PluginModel();

    /**
     * Enable/disable plugins
     * @param if plugin enabled
     */
67
    Q_INVOKABLE void setPluginsEnabled(bool enable);
68 69 70 71 72

    /**
     * Get if plugins are enabled
     * @return plugins enabled
     */
73
    Q_INVOKABLE bool getPluginsEnabled() const;
74 75 76 77 78

    /**
     * Get list of installed plugins
     * @return plugins installed
     */
79
    Q_INVOKABLE VectorString listAvailablePlugins() const;
80 81 82 83 84

    /**
     * Get list of loaded plugins
     * @return plugins loaded
     */
85
    Q_INVOKABLE VectorString listLoadedPlugins() const;
86 87 88 89 90

    /**
     * Get details of installed plugin
     * @return plugin Details
     */
91
    Q_INVOKABLE plugin::PluginDetails getPluginDetails(const QString& path);
92 93 94

    /**
     * Install plugin
95
     * @return true if plugin was succesfully installed
96
     */
97
    Q_INVOKABLE bool installPlugin(const QString& jplPath, bool force);
98 99 100

    /**
     * Uninstall plugin
101
     * @return true if plugin was succesfully uninstalled
102
     */
103
    Q_INVOKABLE bool uninstallPlugin(const QString& rootPath);
104 105 106

    /**
     * Load plugin
107
     * @return true if plugin was succesfully loaded
108
     */
109
    Q_INVOKABLE bool loadPlugin(const QString& path);
110 111 112

    /**
     * Unload plugin
113
     * @return true if plugin was succesfully unloaded
114
     */
115
    Q_INVOKABLE bool unloadPlugin(const QString& path);
116 117

    /**
118 119
     * List all plugins Media Handlers
     * @return List of all plugins Media Handlers
120
     */
121
    Q_INVOKABLE VectorString listCallMediaHandlers() const;
122 123 124 125

    /**
     * Toggle media handler
     */
126
    Q_INVOKABLE void toggleCallMediaHandler(const QString& id);
127 128 129 130 131

    /**
     * Verify if there is an active plugin media handler
     * @return Map with name and status
     */
132
    Q_INVOKABLE MapStringString getCallMediaHandlerStatus();
133 134

    /**
135
     * Get details of installed plugins media handlers
136 137
     * @return Media Handler Details
     */
138
    Q_INVOKABLE plugin::MediaHandlerDetails getCallMediaHandlerDetails(const QString& id);
139 140 141 142 143 144 145 146 147 148 149

    /**
     * Get preferences map of installed plugin
     * @return Plugin preferences infos vector
     */
    Q_INVOKABLE VectorMapStringString getPluginPreferences(const QString& path);

    /**
     * Modify preference of installed plugin
     * @return true if preference was succesfully modified
     */
150 151 152
    Q_INVOKABLE bool setPluginPreference(const QString& path,
                                         const QString& key,
                                         const QString& value);
153 154 155 156 157 158 159 160

    /**
     * Get preferences values of installed plugin
     * @return Plugin preferences map
     */
    Q_INVOKABLE MapStringString getPluginPreferencesValues(const QString& path);

    /**
161
     * Reset preferences values of installed plugin to default values
162 163 164 165
     * @return true if preference was succesfully reset
     */
    Q_INVOKABLE bool resetPluginPreferencesValues(const QString& path);

166
    /**
167 168 169 170
     * Add a possible value to a preference that can be edited by the user
     * the only possibility at the moment is USERLIST option
     * @return if addition was successfull
     */
171 172 173
    Q_INVOKABLE bool addValueToPreference(const QString& pluginId,
                                          const QString& preferenceKey,
                                          const QString& value);
174 175 176 177
};

} // namespace api
} // namespace lrc