1 /**
2  * UGENE - Integrated Bioinformatics Tools.
3  * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru>
4  * http://ugene.net
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301, USA.
20  */
21 
22 #ifndef _U2_PLUGINDESCRIPTOR_H_
23 #define _U2_PLUGINDESCRIPTOR_H_
24 
25 #include <QObject>
26 
27 #include <U2Core/GUrl.h>
28 #include <U2Core/Version.h>
29 #include <U2Core/global.h>
30 
31 namespace U2 {
32 
33 #define PLUGIN_FILE_EXT "plugin"
34 
35 enum PlatformName {
36     PlatformName_Unknown,
37     PlatformName_Win,
38     PlatformName_UnixNotMac,
39     PlatformName_Mac
40 };
41 
42 enum PlatformArch {
43     PlatformArch_Unknown,
44     PlatformArch_32,
45     PlatformArch_64
46 };
47 
48 enum PluginModeFlag {
49     PluginMode_Malformed = 1,
50     PluginMode_Console = 1 << 1,
51     PluginMode_UI = 1 << 2
52 };
53 
54 typedef QFlags<PluginModeFlag> PluginMode;
55 
56 class PlatformInfo {
57 public:
PlatformInfo()58     PlatformInfo()
59         : name(PlatformName_Unknown), arch(PlatformArch_Unknown) {
60     }
61 
62     PlatformName name;
63     PlatformArch arch;
64     bool operator==(const PlatformInfo &p) const {
65         return name == p.name && arch == p.arch;
66     }
67 };
68 
69 class DependsInfo {
70 public:
71     QString id;
72     Version version;
73 };
74 
75 class PluginDesc {
76 public:
77     PluginDesc();
78 
79     QString id;
80     QString name;
81     Version pluginVersion;
82     Version ugeneVersion;
83     Version qtVersion;
84     QString pluginVendor;
85     GUrl descriptorUrl;
86     GUrl libraryUrl;
87     GUrl licenseUrl;
88     PlatformInfo platform;
89     PluginMode mode;
90     QList<DependsInfo> dependsList;
91 
isValid()92     bool isValid() const {
93         return !id.isEmpty() && !pluginVersion.text.isEmpty() && !ugeneVersion.text.isEmpty() && !libraryUrl.isEmpty();
94     }
95 
96     bool operator==(const PluginDesc &pd) const;
97 };
98 
99 class U2PRIVATE_EXPORT PluginDescriptorHelper : public QObject {
100     Q_OBJECT
101 private:
PluginDescriptorHelper()102     PluginDescriptorHelper() {
103     }
104 
105 public:
106     static PluginDesc readPluginDescriptor(const QString &url, QString &error);
107 
108     // orders plugins by loading order
109     static QList<PluginDesc> orderPlugins(const QList<PluginDesc> &unordered, QString &err);
110 };
111 
112 }  // namespace U2
113 
114 #endif
115