release 0.6.6
[fapman] / package.h
1 /*
2         This file is part of Faster Application Manager.
3
4         Faster Application Manager is free software: you can redistribute it and/or modify
5         it under the terms of the GNU General Public License as published by
6         the Free Software Foundation, either version 3 of the License, or
7         (at your option) any later version.
8
9         Faster Application Manager is distributed in the hope that it will be useful,
10         but WITHOUT ANY WARRANTY; without even the implied warranty of
11         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12         GNU General Public License for more details.
13
14         You should have received a copy of the GNU General Public License
15         along with Faster Application Manager.  If not, see <http://www.gnu.org/licenses/>.
16
17         (C) Heikki Holstila 2010
18 */
19
20 #ifndef PACKAGE_H
21 #define PACKAGE_H
22
23 #include <QtCore>
24 #include "blacklistselect.h"
25
26 class AAptInterface;
27 class Repository;
28
29 class Package
30 {
31 public:
32         enum operation { PkgOpNone, PkgOpInstallUpgrade, PkgOpRemove };
33
34         // the order must match status filter strings
35         enum packageStatus { PkgStatUnknown, PkgStatNotInstalled, PkgStatUpgradeable, PkgStatInstalled };
36
37         Package(QByteArray name_, AAptInterface* apt_);
38         ~Package();
39         inline void setName(QByteArray n_) { iName=n_; }
40         inline void setMaemoDisplayName(QByteArray n_) { iMaemoDisplayName=n_; }
41         inline void setInstalled(bool i_) { iIsInstalled=i_; }
42         void setMarkedForOperation(operation op_);
43         inline void setVersion(QByteArray v_) { iVersion=v_; }
44         inline void setDescShort(QByteArray d_) { iDescriptionShort=d_; }
45         inline void appendDescLong(QByteArray d_) { iDescriptionLong.append(d_); }
46         inline void setSection(QByteArray s_) { iSection=s_; }
47         inline void setSize(int i_) { iSize=i_; }
48         inline void setInstalledSize(int i_) { iInstalledSize=i_; }
49         inline void appendIconData(QByteArray d_) { iIconData.append(d_); }
50         inline void addFullFileName(QString f_) { iFullFileNames.append(f_); }
51         void updateStatus();
52         inline void addRepository(Repository* r_) { iRepositories.append(r_); }
53         inline void setDate(QDateTime d_) { iDate=d_; }
54         inline void setBlacklisted(BlacklistSelect::blackList bl_) { iBlacklist=bl_; }
55         inline void appendDepends(QByteArray line_) { iDepends << line_.split(','); }
56         inline void appendConflicts(QByteArray line_) { iConflicts << line_.split(','); }
57         inline void appendPreDepends(QByteArray line_) { iPreDepends << line_.split(','); }
58         inline void appendProvides(QByteArray line_) { iProvides << line_.split(','); }
59         inline void appendReplaces(QByteArray line_) { iReplaces << line_.split(','); }
60         inline void appendBreaks(QByteArray line_) { iBreaks << line_.split(','); }
61         inline void appendRecommends(QByteArray line_) { iRecommends << line_.split(','); }
62         inline void appendSuggests(QByteArray line_) { iSuggests << line_.split(','); }
63         inline void appendUpgradeDescription(QByteArray d_) { iUpgradeDescription.append(d_); }
64         inline void setPinned(bool p_) { iPinned=p_; }
65         inline void setMaintainer(QByteArray m_) { iMaintainer = m_; }
66
67         void convertIcon();
68
69         inline QString name() { return iName; }
70         inline QString maemoDisplayName() { return QString::fromUtf8(iMaemoDisplayName); }
71         QString displayName();
72         inline bool isInstalled() { return iIsInstalled; }
73         inline bool isMarkedForOperation() { return iMarkedForOperation; }
74         inline operation markedOperation() { return iMarkedOperation; }
75         inline QString version() { return iVersion; }
76         inline QString descShort() { return QString::fromUtf8(iDescriptionShort); }
77         inline QString descLong() { return QString::fromUtf8(iDescriptionLong); }
78         inline QString section() { return iSection; }
79         inline int size() { return iSize; }
80         inline int installedSize() { return iInstalledSize; }
81         inline QPixmap* icon() { return iIcon; }
82         bool hasIconData();
83         bool isUpgradeable();
84         QString upgradeableVersion();
85         Package* availablePackage();
86         packageStatus status();
87         QString fileName();
88         inline QStringList fullFileNames() { return iFullFileNames; }
89         inline QDateTime date() { return iDate; }
90         inline QList<Repository*> repositories() { return iRepositories; }
91         inline BlacklistSelect::blackList blacklisted() { return iBlacklist; }
92         inline bool isBlacklisted() { if(iBlacklist==BlacklistSelect::BlacklistNone) return false; else return true; }
93         inline QString upgradeDescription() { return QString::fromUtf8(iUpgradeDescription); }
94         inline QList<QByteArray> depends() { return iDepends; }
95         inline QList<QByteArray> conflicts() { return iConflicts; }
96         inline QList<QByteArray> preDepends() { return iPreDepends; }
97         inline QList<QByteArray> provides() { return iProvides; }
98         inline QList<QByteArray> replaces() { return iReplaces; }
99         inline QList<QByteArray> breaks() { return iBreaks; }
100         inline QList<QByteArray> recommends() { return iRecommends; }
101         inline QList<QByteArray> suggests() { return iSuggests; }
102         inline bool isPinned() { return iPinned; }
103         QString maintainerRichText();
104
105         QStringList checkConflicts_RichText();
106
107         static bool versionCompare(QString isNewer, QString compare);
108         static QStringList toTrimmedRichTextList(QList<QByteArray> list_in);
109
110 private:
111
112         static bool versionConflicts(QString conflictVer, QString operVer);
113
114         AAptInterface* iAptInterface;
115
116         QByteArray iName;
117         QByteArray iMaemoDisplayName;
118         bool iIsInstalled;
119         bool iMarkedForOperation;
120         packageStatus iPkgStatus;
121         QByteArray iVersion;
122         QByteArray iDescriptionShort;
123         QByteArray iDescriptionLong;
124         QByteArray iSection;
125         int iSize;
126         int iInstalledSize;
127         operation iMarkedOperation;
128         QStringList iFullFileNames;
129         QDateTime iDate;
130         QList<Repository*> iRepositories;
131         BlacklistSelect::blackList iBlacklist;
132         QByteArray iUpgradeDescription;
133         QByteArray iMaintainer;
134
135         QByteArray iIconData;
136         QPixmap* iIcon;
137
138         QList<QByteArray> iDepends;
139         QList<QByteArray> iConflicts;
140         QList<QByteArray> iPreDepends;
141         QList<QByteArray> iProvides;
142         QList<QByteArray> iReplaces;
143         QList<QByteArray> iBreaks;
144         QList<QByteArray> iRecommends;
145         QList<QByteArray> iSuggests;
146
147         bool iPinned;
148 };
149
150 #endif // PACKAGE_H