1 | /* |
2 | ** |
3 | ** Copyright (C) 2005-2010 Ralf Habacker. All rights reserved. |
4 | ** |
5 | ** This file is part of the KDE installer for windows |
6 | ** |
7 | ** This library is free software; you can redistribute it and/or |
8 | ** modify it under the terms of the GNU Library General Public |
9 | ** License version 2 as published by the Free Software Foundation. |
10 | ** |
11 | ** This library 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 GNU |
14 | ** Library General Public License for more details. |
15 | ** |
16 | ** You should have received a copy of the GNU Library General Public License |
17 | ** along with this library; see the file COPYING.LIB. If not, write to |
18 | ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 | ** Boston, MA 02110-1301, USA. |
20 | ** |
21 | ****************************************************************************/ |
22 | |
23 | #ifndef INSTALLERENGINE_H |
24 | #define INSTALLERENGINE_H |
25 | |
26 | #include <QString> |
27 | #include <QProcess> |
28 | |
29 | #include "settings.h" |
30 | #include "globalconfig.h" |
31 | #include "packagecategorycache.h" |
32 | #include "packagestates.h" |
33 | #include "database.h" |
34 | #include "typehelper.h" |
35 | |
36 | class PackageList; |
37 | class Downloader; |
38 | class Installer; |
39 | class GlobalConfig; |
40 | class Settings; |
41 | class Package; |
42 | class InstallWizard; |
43 | class Database; |
44 | |
45 | /** |
46 | The class InstallerEngine contains all relevant informations and actions to |
47 | download, remove, install or update packages. |
48 | */ |
49 | class InstallerEngine : public QObject |
50 | { |
51 | Q_OBJECT |
52 | public: |
53 | InstallerEngine(QObject *parent=0); |
54 | virtual ~InstallerEngine(); |
55 | |
56 | void setConfigURL(const QUrl &url); |
57 | |
58 | QString root() { return m_root; } |
59 | |
60 | /** |
61 | set installation root |
62 | Calling this method will reload the installed package into the internal database |
63 | @param root installation root |
64 | */ |
65 | void setRoot(const QString &root); |
66 | |
67 | // read in global config |
68 | bool initGlobalConfig(); |
69 | |
70 | // add packages from global config or sites (requires proxy settings) |
71 | bool initPackages(); |
72 | |
73 | // check installer version |
74 | bool isInstallerVersionOutdated(); |
75 | |
76 | /// check if any package is installed in the recent installation root |
77 | bool isAnyPackageInstalled(); |
78 | |
79 | /// check if any kde process is running from the installation root |
80 | bool isAnyKDEProcessRunning(); |
81 | |
82 | /// kill all kde processes running from the installation root |
83 | bool killAllKDEApps(); |
84 | |
85 | |
86 | void stop(); |
87 | |
88 | Package *getPackageByName(const QString &name,const QString &version=QString()); |
89 | |
90 | Installer *installer() |
91 | { |
92 | return m_installer; |
93 | } |
94 | |
95 | GlobalConfig *globalConfig() { return m_globalConfig; } |
96 | /// download url |
97 | static QString defaultConfigURL; |
98 | static QString fallBackURL; |
99 | Database *database() { return m_database; } |
100 | PackageList* packageResources() { return m_packageResources; } |
101 | QUrl &usedDownloadSource() { return m_usedConfigURL; } |
102 | |
103 | /// number of installed packages |
104 | int installedPackages() { return m_installedPackages; } |
105 | |
106 | /// number of installed packages |
107 | int removedPackages() { return m_removedPackages; } |
108 | /// number of really downloaded packages |
109 | int downloadedPackages() { return m_downloadedPackages; } |
110 | |
111 | QString ; |
112 | |
113 | typedef enum { cancel, retry, ignore } ErrorAction; |
114 | void setErrorAction(ErrorAction action) { m_errorAction = action; } |
115 | |
116 | typedef enum { onlineInstall, localInstall, downloadOnly } InstallMode; |
117 | static void setInstallMode(InstallMode mode) { m_installMode = mode; } |
118 | |
119 | static InstallMode installMode() { return m_installMode; } |
120 | |
121 | void checkUpdateDependencies(QList<Package*> &deps); |
122 | |
123 | bool setDependencyState(Package *package, QList<Package*>&deps); |
124 | |
125 | /// check if a package should be included in the list of displayed packages |
126 | bool includePackage(CompilerTypes::Type compilerType, const QString &name, const QString &categoryName=QString()); |
127 | |
128 | /// check if a category should be included in the list of displayed categories |
129 | bool includeCategory(CompilerTypes::Type compilerType, const QString &categoryName); |
130 | |
131 | /// return version of kde start menu generator in the form 0x00aabbcc as converted from 'aa.bb.cc' |
132 | int (); |
133 | |
134 | /// return version identifed by "key" from executable "appname", see \ref toVersionInt for the output format |
135 | int getAppVersion(const QString &appname, const QString &key=QString()); |
136 | QString getAppVersionString(const QString &appname, const QString &key=QString()); |
137 | |
138 | void setCurrentCompiler(CompilerTypes::Type type) { m_currentCompiler = type; } |
139 | CompilerTypes::Type currentCompiler() { return m_currentCompiler; } |
140 | |
141 | /// return process environment for running tools |
142 | QProcessEnvironment processEnvironment(); |
143 | |
144 | /// run process detached |
145 | bool runProcessDetached(const QString &executable, const QStringList &args = QStringList()); |
146 | |
147 | /// run process |
148 | bool runProcess(QProcess &p, const QString &cmd, const QStringList &args = QStringList(), bool waitFinished = false); |
149 | |
150 | // check if helper applications could be started (used for running installer on linux) |
151 | bool canRunHelperApplications(); |
152 | |
153 | Q_SIGNALS: |
154 | void error ( const QString &error ); |
155 | |
156 | protected slots: |
157 | //@ TODO using this slots make thing much complicater as necessary |
158 | //void installDirChanged(const QString &newdir); |
159 | void slotError ( const QString &error ); |
160 | |
161 | protected: |
162 | PackageList* m_packageResources; |
163 | Installer *m_installer; // currently used installer |
164 | GlobalConfig *m_globalConfig; |
165 | Database *m_database; |
166 | bool m_initFinished; |
167 | bool m_globalConfigReaded; |
168 | bool m_addedPackages; |
169 | bool m_canceled; |
170 | QString m_root; |
171 | QUrl m_configURL; |
172 | QUrl m_usedConfigURL; |
173 | int m_installedPackages; |
174 | int m_downloadedPackages; |
175 | int m_removedPackages; |
176 | static InstallMode m_installMode; |
177 | ErrorAction m_errorAction; // action required after errors |
178 | CompilerTypes::Type m_currentCompiler; ///< current compiler |
179 | |
180 | /// init all package definitions |
181 | virtual bool init(); |
182 | /// reload all package definition |
183 | virtual void reload(); |
184 | |
185 | /** |
186 | fetch configuration from local (file procotol), http or ftp mirrors |
187 | The precedence is |
188 | */ |
189 | bool readGlobalConfig(); |
190 | |
191 | /// adds packages defined directly in GlobalConfig |
192 | bool addPackagesFromGlobalConfig(); |
193 | |
194 | /// add packages collected from site definition |
195 | bool addPackagesFromSites(); |
196 | |
197 | /// add meta packages collected from site definition |
198 | bool addMetaPackages(); |
199 | |
200 | /// add installed packages for which no package is available |
201 | bool addInstalledPackages(); |
202 | |
203 | bool (); |
204 | |
205 | /** |
206 | in case that dependencies are updated, this method |
207 | can be used to find which additional packages has to be installed |
208 | */ |
209 | bool checkInstalledDependencies(); |
210 | |
211 | friend QDebug &operator<<(QDebug &, const InstallerEngine &); |
212 | }; |
213 | |
214 | /// holds the package selection and icon states |
215 | extern PackageStates packageStates; |
216 | |
217 | /// holds the package dependency state |
218 | extern PackageStates dependencyStates; |
219 | |
220 | #endif |
221 | |