2 This file is part of Faster Application Manager.
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.
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.
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/>.
17 (C) Heikki Holstila 2010
22 #include "repository.h"
23 #include "aaptinterface.h"
24 #include "blacklistselect.h"
26 #include "apt-src/debversion.h"
29 Package::Package(QByteArray name_, AAptInterface *apt_):
30 iAptInterface(apt_), iName(name_), iIsInstalled(false), iMarkedForOperation(false),
31 iPkgStatus(PkgStatUnknown), iSize(0), iInstalledSize(0), iMarkedOperation(PkgOpNone),
32 iBlacklist(BlacklistSelect::BlacklistNone), iIcon(0), iPinned(false)
44 QString Package::displayName() const
46 QString pkgname = name();
47 if( !iMaemoDisplayName.isEmpty() )
48 pkgname = maemoDisplayName();
49 QString n( pkgname.at(0) );
51 pkgname.replace(0,1,n);
55 QString Package::fileName() const
57 if( iFullFileNames.count()>0 ) {
58 return iFullFileNames.at(0).mid( iFullFileNames.at(0).lastIndexOf('/')+1 );
60 qDebug() << "Warning: package has no file name information";
61 return "unknown_filename";
65 void Package::setMarkedForOperation(operation op_)
67 if( iMarkedOperation != op_ ) {
68 if( op_==PkgOpNone ) {
70 iAptInterface->setNumSelectedPackages( iAptInterface->numSelectedPackages()-1 );
71 } else if( iMarkedOperation==PkgOpNone ) {
73 iAptInterface->setNumSelectedPackages( iAptInterface->numSelectedPackages()+1 );
77 iMarkedOperation = op_;
79 if( op_ == PkgOpNone )
80 iMarkedForOperation = false;
82 iMarkedForOperation = true;
85 void Package::convertIcon()
87 if( iIconData.length() > 0 && iIcon == 0 ) {
88 iIcon = new QPixmap();
89 if( !iIcon->loadFromData(QByteArray::fromBase64(iIconData)) ) {
90 qDebug() << "Warning: Package" << iName << "has invalid icon data";
95 bool Package::isUpgradeable() const
97 if( iSection=="user/hidden" || iPinned )
102 QString newer = upgradeableVersion();
103 //qDebug() << newer << iVersion << versionCompare(newer,iVersion);
104 return versionCompare(newer,iVersion);
110 QString Package::upgradeableVersion() const
113 if( isInstalled() ) {
114 Package* newer = iAptInterface->packagesAvailable()->value(iName,0);
116 ver = newer->version();
121 Package* Package::availablePackage() const
126 Package* newer = iAptInterface->packagesAvailable()->value(iName,0);
131 void Package::updateStatus()
134 iPkgStatus = PkgStatInstalled;
135 if( isUpgradeable() )
136 iPkgStatus = PkgStatUpgradeable;
138 iPkgStatus = PkgStatNotInstalled;
142 Package::packageStatus Package::status()
144 updateStatus(); // just in case
148 bool Package::hasIconData() const
150 if( iIconData.length()>0 )
156 bool Package::versionCompare(QString isNewer, QString compare)
159 int res = debVS.CmpVersion(isNewer.toStdString(), compare.toStdString());
160 //qDebug() << isNewer << compare << res;
168 QStringList Package::toTrimmedRichTextList(QList<QByteArray> list_in)
170 QStringList list_out;
172 for(int i=0; i<list_in.count(); i++)
174 QString s = list_in.at(i).trimmed();
175 s.replace('<',"<");
176 s.replace('>',">");
183 QStringList Package::checkConflicts_RichText() const
187 if( iConflicts.count() == 0 )
190 for(int i=0; i<iConflicts.count(); i++)
192 QString s = iConflicts.at(i).trimmed();
195 int pos = s.indexOf('(');
198 name = s.left(pos).trimmed();
199 ver = s.mid(pos).trimmed();
201 Package* p_inst = iAptInterface->packagesInstalled()->value(name,0);
202 Package* p_avail = iAptInterface->packagesAvailable()->value(name,0);
204 if( p_inst && p_inst->isInstalled() ) {
205 confl = versionConflicts(ver, p_inst->version());
207 if( p_avail && p_avail->markedOperation()==Package::PkgOpInstallUpgrade ) {
209 confl = versionConflicts(ver, p_avail->version());
214 qDebug() << "package" << iName << "conflicts:" << name << ver;
215 s.replace('<',"<");
216 s.replace('>',">");
224 bool Package::versionConflicts(QString conflictVer, QString operVer)
226 if( conflictVer.isEmpty() )
230 conflictVer.remove('(');
231 conflictVer.remove(')');
233 if( conflictVer.startsWith("<<") ) {
234 conflictVer = conflictVer.mid(2).trimmed();
235 int res = debVS.CmpVersion(conflictVer.toStdString(), operVer.toStdString());
238 } else if( conflictVer.startsWith("<=") ) {
239 conflictVer = conflictVer.mid(2).trimmed();
240 int res = debVS.CmpVersion(conflictVer.toStdString(), operVer.toStdString());
243 } else if( conflictVer.startsWith("=") ) {
244 conflictVer = conflictVer.mid(1).trimmed();
245 int res = debVS.CmpVersion(conflictVer.toStdString(), operVer.toStdString());
248 } else if( conflictVer.startsWith(">=") ) {
249 conflictVer = conflictVer.mid(2).trimmed();
250 int res = debVS.CmpVersion(conflictVer.toStdString(), operVer.toStdString());
253 } else if( conflictVer.startsWith(">>") ) {
254 conflictVer = conflictVer.mid(2).trimmed();
255 int res = debVS.CmpVersion(conflictVer.toStdString(), operVer.toStdString());
263 QString Package::maintainerRichText() const
265 QString m = iMaintainer;
266 m.replace('<',"<");
267 m.replace('>',">");