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
21 #include <QDBusConnection>
22 #include <QDBusInterface>
24 #include "packageselector.h"
25 #include "ui_packageselector.h"
27 #include "packageview.h"
28 #include "repository.h"
29 #include "blacklistselect.h"
30 #include "aaptinterface.h"
32 #include "mainwindow.h"
34 PackageSelector::PackageSelector(Package* pkg, AAptInterface* apt, Settings* set, MainWindow* mw, QWidget *parent) :
36 ui(new Ui::PackageSelector), iNetworkAccessManager(0), iChangelogFetched(false), iFetchInProgress(false)
45 ui->pushButton_website->setIcon(QPixmap("/usr/share/icons/hicolor/48x48/hildon/general_web.png"));
46 if( getMaemoOrgUrl(pkg).isEmpty() && getMaemoOrgUrl(pkg->availablePackage()).isEmpty() ) {
47 ui->pushButton_website->setEnabled(false);
49 if( pkg->isMarkedForOperation() )
50 ui->pushButton_blacklist->setEnabled(false);
52 if( pkg->icon() && !pkg->icon()->isNull() ) {
53 QPixmap aicon( *pkg->icon() );
54 ui->label_appicon->setPixmap( aicon.scaled(48,48) );
56 ui->label_appicon->setPixmap( QPixmap(":/icons/icons/appdefault.png") );
58 this->setWindowTitle( pkg->name() );
60 if( pkg->maemoDisplayName() != "" )
61 ui->label_header->setText("<b>" + pkg->maemoDisplayName() + "</b>");
63 ui->label_header->setText("<b>" + pkg->name() + "</b>");
65 ui->radioTabBasic->setChecked(true);
68 // switch to shorter button labels for portait mode
69 if( QApplication::desktop()->width() < QApplication::desktop()->height() )
71 ui->radioTabBasic->setText("Info");
72 ui->radioTabChanges->setText("Chgs");
73 ui->radioTabDepends->setText("Deps");
74 ui->scrollAreaWidgetContents->setMaximumWidth( QApplication::desktop()->width() - 15 );
77 Package* upg_pkg = iPkg->availablePackage();
80 if( (!pkg->isUpgradeable() || (upg_pkg && upg_pkg->upgradeDescription().isEmpty())) && (getMaemoOrgUrl(upg_pkg).isEmpty()) )
81 ui->radioTabChanges->hide();
83 if( pkg->isUpgradeable() )
84 ui->radioInstall->setText("Upgrade");
86 ui->radioInstall->setText("Install");
88 if( pkg->markedOperation() == Package::PkgOpNone )
90 if( pkg->isInstalled() && pkg->isUpgradeable() )
91 ui->label_statusicon->setPixmap(QPixmap(":/icons/icons/pkg_nop_instupgr.png"));
92 else if( pkg->isInstalled() )
93 ui->label_statusicon->setPixmap(QPixmap(":/icons/icons/pkg_nop_installed.png"));
94 else if( !pkg->isInstalled() )
95 ui->label_statusicon->setPixmap(QPixmap(":/icons/icons/pkg_nop_notinstalled.png"));
97 ui->radioNothing->setChecked(true);
98 } else if( pkg->markedOperation() == Package::PkgOpInstallUpgrade ) {
99 if( pkg->isUpgradeable() )
100 ui->label_statusicon->setPixmap(QPixmap(":/icons/icons/pkg_upgrade.png"));
102 ui->label_statusicon->setPixmap(QPixmap(":/icons/icons/pkg_install.png"));
103 ui->radioInstall->setChecked(true);
104 } else if( pkg->markedOperation() == Package::PkgOpRemove ) {
105 ui->label_statusicon->setPixmap(QPixmap(":/icons/icons/pkg_remove.png"));
106 ui->radioRemove->setChecked(true);
109 if( !getMaemoOrgUrl(upg_pkg).isEmpty() && !iChangelogFetched && !iFetchInProgress &&
110 iSettings->qsettings()->value("always_fetch_changes",false).toBool() )
116 PackageSelector::~PackageSelector()
118 if( iNetworkAccessManager ) {
119 delete iNetworkAccessManager;
120 iNetworkAccessManager = 0;
125 void PackageSelector::changeEvent(QEvent *e)
127 QDialog::changeEvent(e);
129 case QEvent::LanguageChange:
130 ui->retranslateUi(this);
137 Package::operation PackageSelector::selectedOperation()
139 if( ui->radioInstall->isChecked() )
140 return Package::PkgOpInstallUpgrade;
141 if( ui->radioRemove->isChecked() )
142 return Package::PkgOpRemove;
144 return Package::PkgOpNone;
147 void PackageSelector::on_pushButton_blacklist_clicked()
150 /*if( iPkg->isUpgradeable() && iPkg->availablePackage() )
151 pkg = iPkg->availablePackage();*/
153 if( pkg->isInstalled() && pkg->isUpgradeable() )
155 Package* upg = pkg->availablePackage();
160 BlacklistSelect s(pkg, this);
161 BlacklistSelect::blackList old = pkg->blacklisted();
163 if( old != pkg->blacklisted() ) {
164 Package* p1 = iAptInterface->packagesInstalled()->value(pkg->name(),0);
165 Package* p2 = iAptInterface->packagesAvailable()->value(pkg->name(),0);
167 iAptInterface->removeFromBlacklist(p1,old);
168 if( pkg->blacklisted()==BlacklistSelect::BlacklistAll || pkg->blacklisted()==BlacklistSelect::BlacklistNone )
169 p1->setBlacklisted( pkg->blacklisted() );
170 else if( pkg->blacklisted()==BlacklistSelect::BlacklistThis && pkg->version()==p1->version() )
171 p1->setBlacklisted( pkg->blacklisted() );
173 p1->setBlacklisted( BlacklistSelect::BlacklistNone );
176 iAptInterface->removeFromBlacklist(p2,old);
177 if( pkg->blacklisted()==BlacklistSelect::BlacklistAll || pkg->blacklisted()==BlacklistSelect::BlacklistNone )
178 p2->setBlacklisted( pkg->blacklisted() );
179 else if( pkg->blacklisted()==BlacklistSelect::BlacklistThis && pkg->version()==p2->version() )
180 p2->setBlacklisted( pkg->blacklisted() );
182 p2->setBlacklisted( BlacklistSelect::BlacklistNone );
184 iAptInterface->writeBlacklist();
190 QString PackageSelector::getMaemoOrgUrl(Package* pkg)
197 if( pkg->repositories().count() == 0 )
200 for( int i=0; i<pkg->repositories().count(); i++ )
202 if( pkg->repositories().at(i) && pkg->repositories().at(i)->url().startsWith("http://repository.maemo.org") )
203 url = "http://maemo.org/packages/view/" + pkg->name() + "/";
208 void PackageSelector::updateInfo()
210 if( ui->radioTabBasic->isChecked() )
211 on_radioTabBasic_clicked();
212 else if( ui->radioTabChanges->isChecked() )
213 on_radioTabChanges_clicked();
214 else if( ui->radioTabDepends->isChecked() )
215 on_radioTabDepends_clicked();
217 ui->radioInstall->setEnabled(true);
218 ui->radioRemove->setEnabled(true);
219 ui->radioInstall->show();
220 ui->radioRemove->show();
222 Package* upg_pkg = iPkg->availablePackage();
224 if( iPkg->isInstalled() && !iPkg->isUpgradeable() )
226 ui->radioInstall->setEnabled(false);
227 ui->radioInstall->hide();
228 } else if( !iPkg->isInstalled() ) {
229 ui->radioRemove->setEnabled(false);
230 ui->radioRemove->hide();
233 if( iPkg->isBlacklisted() ) {
234 ui->radioInstall->setEnabled(false);
235 //ui->radioRemove->setEnabled(false);
237 if( iPkg->isInstalled() && upg_pkg && upg_pkg->isBlacklisted() ) {
238 ui->radioInstall->setEnabled(false);
242 void PackageSelector::on_pushButton_website_clicked()
244 QString url = getMaemoOrgUrl(iPkg);
246 url = getMaemoOrgUrl(iPkg->availablePackage());
251 QDBusConnection conn = QDBusConnection::connectToBus(QDBusConnection::SessionBus, "faster_application_manager");
253 QString service = "com.nokia.osso_browser";
254 QString path = "/com/nokia/osso_browser/request";
255 QString method = "open_new_window";
257 QDBusInterface browser(service, path, service, conn, this);
258 browser.call(method, url);
261 void PackageSelector::on_radioTabBasic_clicked()
263 ui->label_header2->show();
266 Package* upg_pkg = iPkg->availablePackage();
268 if( iPkg->isInstalled() ) {
269 header2 += "Installed, version <b>" + iPkg->version() + "</b>";
271 header2 += "Not installed";
275 if( iPkg->markedOperation() == Package::PkgOpInstallUpgrade )
277 if( iPkg->isUpgradeable() )
278 header2 += "Marked for <b>upgrade</b><br>";
280 header2 += "Marked for <b>installation</b><br>";
281 } else if(iPkg->markedOperation() == Package::PkgOpRemove)
283 header2 += "Marked for <b>removal</b><br>";
286 if( iPkg->isBlacklisted() && !iPkg->isUpgradeable() ) {
287 header2 += "BLACKLISTED";
288 if( iPkg->blacklisted() == BlacklistSelect::BlacklistAll )
290 else if( iPkg->blacklisted() == BlacklistSelect::BlacklistThis )
291 header2 += " (this)";
292 iPkg->setMarkedForOperation(Package::PkgOpNone);
294 } else if( upg_pkg && upg_pkg->isBlacklisted() ) {
295 header2 += "BLACKLISTED";
296 if( upg_pkg->blacklisted() == BlacklistSelect::BlacklistAll )
298 else if( upg_pkg->blacklisted() == BlacklistSelect::BlacklistThis )
299 header2 += " (" + upg_pkg->version() + ")";
300 iPkg->setMarkedForOperation(Package::PkgOpNone);
301 upg_pkg->setMarkedForOperation(Package::PkgOpNone);
305 ui->label_header2->setText(header2);
309 longtext += "Category: " + iPkg->section() + "<br>";
311 if( iPkg->isInstalled() ) {
312 longtext += "Installation date: ";
313 if( iPkg->date().isValid() )
314 longtext += iPkg->date().toString("yyyy-MM-dd hh:mm");
316 longtext += "Unknown";
320 if( iPkg->isInstalled() && iPkg->installedSize() > 0 )
321 longtext += QString("Size: %L1 kB<br>").arg(iPkg->installedSize() );
324 if( !iPkg->isInstalled() ){
325 longtext += "Available version <b>" + iPkg->version() + "</b>";
326 if( iPkg->size() > 0 )
327 longtext += QString(" (%L1 kB)").arg(iPkg->size()/1024 );
330 else if( iPkg->isUpgradeable() ){
331 longtext += "Available version <b>" + iPkg->upgradeableVersion() + "</b>";
332 if( iPkg->size() > 0 )
333 longtext += QString(" (%L1 kB)").arg(iPkg->size()/1024 );
337 if( !iPkg->isInstalled() ) {
338 longtext += "Available package date: ";
339 if( iPkg->date().isValid() )
340 longtext += iPkg->date().toString("yyyy-MM-dd hh:mm");
342 longtext += "Unknown";
344 } else if( iPkg->isUpgradeable() ) {
345 longtext += "Available package date: ";
346 if( iPkg->availablePackage() && iPkg->availablePackage()->date().isValid() )
347 longtext += iPkg->availablePackage()->date().toString("yyyy-MM-dd hh:mm");
349 longtext += "Unknown";
353 if( !iPkg->isInstalled() )
355 longtext += "Repositories: ";
356 if( iPkg->repositories().count()>0 ) {
357 for(int i=0; i<iPkg->repositories().count(); i++ ) {
358 if( iPkg->repositories().at(i) )
359 longtext += iPkg->repositories().at(i)->name();
361 longtext += "unknown";
362 if( i<iPkg->repositories().count()-1 )
367 longtext += "unknown<br>";
371 if( iPkg->isUpgradeable() )
373 longtext += "Repositories: ";
374 if( upg_pkg && upg_pkg->repositories().count()>0 ) {
375 for(int i=0; i<upg_pkg->repositories().count(); i++ ) {
376 if( upg_pkg->repositories().at(i) )
377 longtext += upg_pkg->repositories().at(i)->name();
379 longtext += "unknown";
380 if( i<upg_pkg->repositories().count()-1 )
385 longtext += "unknown<br>";
389 if( !iPkg->maintainerRichText().isEmpty() ) {
390 longtext +="Maintainer: " + iPkg->maintainerRichText() + "<br>";
393 longtext += "<br>" + iPkg->descShort();
394 QString descLong = iPkg->descLong();
395 if( descLong.length()>0 ) {
396 descLong.replace('\n',"<br>");
397 longtext += "<font size=\"-1\"><br><br>" + descLong + "</font>";
400 ui->label_text->setText( longtext );
403 void PackageSelector::on_radioTabChanges_clicked()
405 ui->label_header2->hide();
406 ui->label_header2->setText("");
410 Package* upg_pkg = iPkg->availablePackage();
414 if( iPkg->isUpgradeable() && upg_pkg && !upg_pkg->upgradeDescription().isEmpty() )
416 text += "<u><b>Upgrade description:</b></u>";
417 text += "<font size=\"-1\"><br>";
418 text += upg_pkg->upgradeDescription();
419 text += "</font><br>";
420 text.replace('\n',"<br>");
424 if( !getMaemoOrgUrl(upg_pkg).isEmpty() && !iChangelogFetched && !iFetchInProgress ) {
426 changelog = "Fetching changelog...";
428 changelog = iChangelog;
429 if( iFetchInProgress )
430 changelog = "Fetching changelog...";
431 else if( changelog == "" )
432 changelog = "Not available";
435 text += "<u><b>Debian changelog:</b></u><font size=\"-1\"><br>";
439 ui->label_text->setText(text);
442 void PackageSelector::on_radioTabDepends_clicked()
444 ui->label_header2->hide();
445 ui->label_header2->setText("");
446 ui->label_text->setText("");
448 QStringList deps = Package::toTrimmedRichTextList( iPkg->depends() );
449 QStringList confl = Package::toTrimmedRichTextList( iPkg->conflicts() );
450 QStringList predeps = Package::toTrimmedRichTextList( iPkg->preDepends() );
451 QStringList repl = Package::toTrimmedRichTextList( iPkg->replaces() );
452 QStringList prov = Package::toTrimmedRichTextList( iPkg->provides() );
453 QStringList brks = Package::toTrimmedRichTextList( iPkg->breaks() );
454 QStringList recs = Package::toTrimmedRichTextList( iPkg->recommends() );
455 QStringList sugs = Package::toTrimmedRichTextList( iPkg->suggests() );
461 text += "<b><u>Depends:</u></b><br><font size=\"-1\">";
462 text += deps.join(", ");
463 text += "</font><br>";
466 if( predeps.count()>0 )
468 text += "<b><u>Pre-Depends:</u></b><br><font size=\"-1\">";
469 text += predeps.join(", ");
470 text += "</font><br>";
473 if( confl.count()>0 )
475 text += "<b><u>Conflicts:</u></b><br><font size=\"-1\">";
476 text += confl.join(", ");
477 text += "</font><br>";
482 text += "<b><u>Provides:</u></b><br><font size=\"-1\">";
483 text += prov.join(", ");
484 text += "</font><br>";
489 text += "<b><u>Replaces:</u></b><br><font size=\"-1\">";
490 text += repl.join(", ");
491 text += "</font><br>";
496 text += "<b><u>Breaks:</u></b><br><font size=\"-1\">";
497 text += brks.join(", ");
498 text += "</font><br>";
503 text += "<b><u>Recommends:</u></b><br><font size=\"-1\">";
504 text += recs.join(", ");
505 text += "</font><br>";
510 text += "<b><u>Suggests:</u></b><br><font size=\"-1\">";
511 text += sugs.join(", ");
512 text += "</font><br>";
515 if( deps.count()==0 && predeps.count()==0 && confl.count()==0 && prov.count()==0 &&
516 repl.count()==0 && brks.count()==0 && recs.count()==0 && sugs.count()==0 )
518 text = "Package has no dependencies listed";
521 ui->label_text->setText(text);
524 void PackageSelector::queryChangelog()
526 if( iChangelogFetched || iFetchInProgress )
530 iMainWindow->openNetworkConnection();
532 iChangelogFetched = false;
533 iFetchInProgress = true;
536 Package* pkg = iPkg->availablePackage();
540 if( getMaemoOrgUrl(pkg) == "" ) {
541 iChangelogFetched = true;
545 if( !iNetworkAccessManager ) {
546 iNetworkAccessManager = new QNetworkAccessManager(this);
547 connect(iNetworkAccessManager,SIGNAL(finished(QNetworkReply*)),this,SLOT(changelogFetchNetworkReply(QNetworkReply*)));
549 if( iSettings->qsettings()->value("use_proxies").toBool() && !iSettings->qsettings()->value("http_proxy").toString().isEmpty() )
551 QNetworkProxy proxy = Settings::createProxyFromString( iSettings->qsettings()->value("http_proxy").toString() );
552 iNetworkAccessManager->setProxy(proxy);
556 QUrl url( getMaemoOrgUrl(pkg) );
557 QNetworkRequest req(url);
559 qDebug() << "fetching changelog";
561 iNetworkAccessManager->get(req);
564 void PackageSelector::changelogFetchNetworkReply(QNetworkReply* reply)
566 if( reply->error() == QNetworkReply::NoError ) {
567 QByteArray data = reply->readAll();
569 int pos = data.indexOf("<div class=\"changelog\">");
570 int pos2 = data.indexOf("</div>", pos);
572 if( pos!=-1 && pos2!=-1 ) {
573 iChangelog = parseChangeTable( QString::fromUtf8( data.mid(pos,pos2-pos+6) ) );
578 qDebug() << "changelog fetched";
580 iChangelog = "Not available ( error)";
581 qDebug() << "changelog fetch error:" << reply->error() << reply->errorString();
584 reply->deleteLater();
585 iFetchInProgress = false;
586 iChangelogFetched = true;
588 if( this->isVisible() && ui->radioTabChanges->isChecked() )
589 on_radioTabChanges_clicked();
592 QString PackageSelector::parseChangeTable(QString tabledata)
594 tabledata.remove("<strong>");
595 tabledata.remove("</strong>");
596 tabledata.remove('\n');
598 //qDebug() << tabledata;
600 QString newdata = "<table><tbody>";
602 int pos = tabledata.indexOf("<tr>", tabledata.indexOf("<tbody>") );
604 int pos2 = tabledata.indexOf("</td>",pos);
605 pos2 = tabledata.indexOf("</td>",pos2+5);
608 newdata += tabledata.mid(pos, pos2-pos+5) + "</tr>";
610 pos = tabledata.indexOf("<tr>",pos+4);
613 newdata += "</tbody></table>";
615 //qDebug() << newdata;