1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2006-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 GLOBALCONFIG_H |
24 | #define GLOBALCONFIG_H |
25 | |
26 | #include "hash.h" |
27 | #include "site.h" |
28 | #include "package.h" |
29 | |
30 | #include <QDateTime> |
31 | #include <QFileInfo> |
32 | |
33 | class Downloader; |
34 | |
35 | class GlobalConfig { |
36 | public: |
37 | class Mirror { |
38 | public: |
39 | QString url; |
40 | QString location; |
41 | friend QDebug operator <<(QDebug ,const GlobalConfig::Mirror &); |
42 | }; |
43 | |
44 | GlobalConfig(); |
45 | ~GlobalConfig(); |
46 | /// fetch local or remote config files |
47 | QStringList fetch(const QString &baseURL); |
48 | /// parse list of config files |
49 | bool parse(const QStringList &configFiles); |
50 | |
51 | /// return list of site definitions |
52 | QList<Site*> *sites() { return &m_sites; } |
53 | |
54 | /// return list of package definitions |
55 | QList<Package*> *packages() { return &m_packages; } |
56 | |
57 | /// return list of mirrors |
58 | QList<Mirror*> *mirrors() { return &m_mirrors; } |
59 | |
60 | /// return category notes |
61 | QHash <QString,QString> &categoryNotes() { return m_categoryNotes; } |
62 | |
63 | /// return category packages relations |
64 | QHash <QString,QStringList> &categoryPackages() { return m_categoryPackages; } |
65 | |
66 | /// return meta packages relations |
67 | QHash <QString,QStringList> &metaPackages() { return m_metaPackages; } |
68 | |
69 | /// return package orientated news |
70 | QHash<QString, QString> *news() { return &m_news; } |
71 | |
72 | /// return category displayed in enduser mode |
73 | QStringList &endUserCategories() { return m_endUserCategories; } |
74 | |
75 | /// returns the category for a specific package |
76 | QString packageCategory(const QString &package); |
77 | |
78 | QDateTime &timeStamp() { return m_timestamp; } |
79 | void clear(); |
80 | /// return version of required installer |
81 | const QByteArray &minimalInstallerVersion() { return m_minimalInstallerVersion; } |
82 | void setBaseURL(const QUrl &url) { m_baseURL = url.toString(); } |
83 | |
84 | /// check if a config-remote.txt is located in download directory |
85 | static bool isRemoteConfigAvailable(); |
86 | /// return path of remote config file |
87 | static const QFileInfo remoteConfigFile(); |
88 | |
89 | Hash &hashType() { return m_hashType; } |
90 | |
91 | protected: |
92 | bool parseFromFile(const QString &fileName); |
93 | bool parseFromByteArray(const QByteArray &ba); |
94 | bool parse(QIODevice *ioDev); |
95 | |
96 | private: |
97 | QList <Site*> m_sites; |
98 | QList <Package*> m_packages; |
99 | // package news <key,value> where key = <name>-<version> |
100 | QHash <QString,QString> m_news; |
101 | QHash <QString,QString> m_categoryNotes; |
102 | QHash <QString,QStringList> m_categoryPackages; |
103 | QHash <QString,QStringList> m_metaPackages; |
104 | QList <Mirror*> m_mirrors; |
105 | QString m_baseURL; |
106 | QDateTime m_timestamp; |
107 | QByteArray m_minimalInstallerVersion; |
108 | QStringList m_endUserCategories; |
109 | Hash m_hashType; |
110 | |
111 | Q_DISABLE_COPY(GlobalConfig) |
112 | |
113 | friend QDebug operator<<(QDebug, const GlobalConfig &); |
114 | }; |
115 | |
116 | #endif |
117 | |