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 "apt-src/debversion.h"
25 #include "blacklistselect.h"
27 Package::Package(QByteArray name_, AAptInterface *apt_):
28 iAptInterface(apt_), iName(name_), iIsInstalled(false), iMarkedForOperation(false),
29 iPkgStatus(PkgStatUnknown), iSize(0), iInstalledSize(0), iMarkedOperation(PkgOpNone),
30 iBlacklist(BlacklistSelect::BlacklistNone), iIcon(0)
40 QString Package::displayName()
42 QString pkgname = name();
43 if( iMaemoDisplayName!="" )
44 pkgname = maemoDisplayName();
45 QString n( pkgname.at(0) );
47 pkgname.replace(0,1,n);
51 QString Package::fileName()
53 if( iFullFileNames.count()>0 ) {
54 return iFullFileNames.at(0).mid( iFullFileNames.at(0).lastIndexOf('/')+1 );
56 qDebug() << "Warning: package has no file name information";
57 return "unknown_filename";
61 void Package::setMarkedForOperation(operation op_)
63 if( iMarkedOperation != op_ ) {
64 if( op_==PkgOpNone ) {
66 iAptInterface->setNumSelectedPackages( iAptInterface->numSelectedPackages()-1 );
67 } else if( iMarkedOperation==PkgOpNone ) {
69 iAptInterface->setNumSelectedPackages( iAptInterface->numSelectedPackages()+1 );
73 iMarkedOperation = op_;
75 if( op_ == PkgOpNone )
76 iMarkedForOperation = false;
78 iMarkedForOperation = true;
81 void Package::convertIcon()
83 if( iIconData.length() > 0 && iIcon == 0 ) {
84 iIcon = new QPixmap();
85 iIconData = QByteArray::fromBase64( iIconData );
86 if( !iIcon->loadFromData( iIconData ) ) {
87 qDebug() << "Warning: Package" << iName << "has invalid icon data";
93 bool Package::isUpgradeable()
95 if( iSection=="user/hidden" )
100 QString newer = upgradeableVersion();
101 //qDebug() << newer << iVersion << versionCompare(newer,iVersion);
102 return versionCompare(newer,iVersion);
108 QString Package::upgradeableVersion()
111 if( isInstalled() ) {
112 Package* newer = iAptInterface->packagesAvailable()->value(iName,0);
114 ver = newer->version();
119 Package* Package::availablePackage()
124 Package* newer = iAptInterface->packagesAvailable()->value(iName,0);
129 void Package::updateStatus()
132 iPkgStatus = PkgStatInstalled;
133 if( isUpgradeable() )
134 iPkgStatus = PkgStatUpgradeable;
136 iPkgStatus = PkgStatNotInstalled;
140 Package::packageStatus Package::status()
142 updateStatus(); // not optimal, but it's here just in case
146 bool Package::hasIconData()
148 if( iIconData.length()>0 )
154 bool Package::versionCompare(QString isNewer, QString compare)
157 int res = debVS.CmpVersion(isNewer.toStdString(), compare.toStdString());
158 //qDebug() << isNewer << compare << res;
166 QStringList Package::toTrimmedRichTextList(QList<QByteArray> list_in)
168 QStringList list_out;
170 for(int i=0; i<list_in.count(); i++)
172 QString s = list_in.at(i).trimmed();
173 s.replace('<',"<");
174 s.replace('>',">");
181 QStringList Package::checkConflicts_RichText()
185 if( iConflicts.count() == 0 )
188 for(int i=0; i<iConflicts.count(); i++)
190 QString s = iConflicts.at(i).trimmed();
193 int pos = s.indexOf('(');
196 name = s.left(pos).trimmed();
197 ver = s.mid(pos).trimmed();
199 Package* p_inst = iAptInterface->packagesInstalled()->value(name,0);
200 Package* p_avail = iAptInterface->packagesAvailable()->value(name,0);
202 if( p_inst && p_inst->isInstalled() ) {
203 confl = versionConflicts(ver, p_inst->version());
205 if( p_avail && p_avail->markedOperation()==Package::PkgOpInstallUpgrade ) {
207 confl = versionConflicts(ver, p_avail->version());
212 qDebug() << "package" << iName << "conflicts:" << name << ver;
213 s.replace('<',"<");
214 s.replace('>',">");
222 bool Package::versionConflicts(QString conflictVer, QString operVer)
224 if( conflictVer=="" )
228 conflictVer.remove('(');
229 conflictVer.remove(')');
231 if( conflictVer.startsWith("<<") ) {
232 conflictVer = conflictVer.mid(2).trimmed();
233 int res = debVS.CmpVersion(conflictVer.toStdString(), operVer.toStdString());
236 } else if( conflictVer.startsWith("<=") ) {
237 conflictVer = conflictVer.mid(2).trimmed();
238 int res = debVS.CmpVersion(conflictVer.toStdString(), operVer.toStdString());
241 } else if( conflictVer.startsWith("=") ) {
242 conflictVer = conflictVer.mid(1).trimmed();
243 int res = debVS.CmpVersion(conflictVer.toStdString(), operVer.toStdString());
246 } else if( conflictVer.startsWith(">=") ) {
247 conflictVer = conflictVer.mid(2).trimmed();
248 int res = debVS.CmpVersion(conflictVer.toStdString(), operVer.toStdString());
251 } else if( conflictVer.startsWith(">>") ) {
252 conflictVer = conflictVer.mid(2).trimmed();
253 int res = debVS.CmpVersion(conflictVer.toStdString(), operVer.toStdString());