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), iPinned(false)
40 QString Package::displayName()
42 QString pkgname = name();
43 if( !iMaemoDisplayName.isEmpty() )
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 if( !iIcon->loadFromData(QByteArray::fromBase64(iIconData)) ) {
86 qDebug() << "Warning: Package" << iName << "has invalid icon data";
91 bool Package::isUpgradeable()
93 if( iSection=="user/hidden" )
98 QString newer = upgradeableVersion();
99 //qDebug() << newer << iVersion << versionCompare(newer,iVersion);
100 return versionCompare(newer,iVersion);
106 QString Package::upgradeableVersion()
109 if( isInstalled() ) {
110 Package* newer = iAptInterface->packagesAvailable()->value(iName,0);
112 ver = newer->version();
117 Package* Package::availablePackage()
122 Package* newer = iAptInterface->packagesAvailable()->value(iName,0);
127 void Package::updateStatus()
130 iPkgStatus = PkgStatInstalled;
131 if( isUpgradeable() )
132 iPkgStatus = PkgStatUpgradeable;
134 iPkgStatus = PkgStatNotInstalled;
138 Package::packageStatus Package::status()
140 updateStatus(); // just in case
144 bool Package::hasIconData()
146 if( iIconData.length()>0 )
152 bool Package::versionCompare(QString isNewer, QString compare)
155 int res = debVS.CmpVersion(isNewer.toStdString(), compare.toStdString());
156 //qDebug() << isNewer << compare << res;
164 QStringList Package::toTrimmedRichTextList(QList<QByteArray> list_in)
166 QStringList list_out;
168 for(int i=0; i<list_in.count(); i++)
170 QString s = list_in.at(i).trimmed();
171 s.replace('<',"<");
172 s.replace('>',">");
179 QStringList Package::checkConflicts_RichText()
183 if( iConflicts.count() == 0 )
186 for(int i=0; i<iConflicts.count(); i++)
188 QString s = iConflicts.at(i).trimmed();
191 int pos = s.indexOf('(');
194 name = s.left(pos).trimmed();
195 ver = s.mid(pos).trimmed();
197 Package* p_inst = iAptInterface->packagesInstalled()->value(name,0);
198 Package* p_avail = iAptInterface->packagesAvailable()->value(name,0);
200 if( p_inst && p_inst->isInstalled() ) {
201 confl = versionConflicts(ver, p_inst->version());
203 if( p_avail && p_avail->markedOperation()==Package::PkgOpInstallUpgrade ) {
205 confl = versionConflicts(ver, p_avail->version());
210 qDebug() << "package" << iName << "conflicts:" << name << ver;
211 s.replace('<',"<");
212 s.replace('>',">");
220 bool Package::versionConflicts(QString conflictVer, QString operVer)
222 if( conflictVer.isEmpty() )
226 conflictVer.remove('(');
227 conflictVer.remove(')');
229 if( conflictVer.startsWith("<<") ) {
230 conflictVer = conflictVer.mid(2).trimmed();
231 int res = debVS.CmpVersion(conflictVer.toStdString(), operVer.toStdString());
234 } else if( conflictVer.startsWith("<=") ) {
235 conflictVer = conflictVer.mid(2).trimmed();
236 int res = debVS.CmpVersion(conflictVer.toStdString(), operVer.toStdString());
239 } else if( conflictVer.startsWith("=") ) {
240 conflictVer = conflictVer.mid(1).trimmed();
241 int res = debVS.CmpVersion(conflictVer.toStdString(), operVer.toStdString());
244 } else if( conflictVer.startsWith(">=") ) {
245 conflictVer = conflictVer.mid(2).trimmed();
246 int res = debVS.CmpVersion(conflictVer.toStdString(), operVer.toStdString());
249 } else if( conflictVer.startsWith(">>") ) {
250 conflictVer = conflictVer.mid(2).trimmed();
251 int res = debVS.CmpVersion(conflictVer.toStdString(), operVer.toStdString());