added app list backup, helper shell scripts
[fapman] / packageselector.cpp
index a8561ed..fcade78 100644 (file)
 #include "repository.h"
 #include "blacklistselect.h"
 #include "aaptinterface.h"
+#include "settings.h"
 
-PackageSelector::PackageSelector(Package* pkg, AAptInterface* apt, QWidget *parent) :
+PackageSelector::PackageSelector(Package* pkg, AAptInterface* apt, Settings* set, QWidget *parent) :
     QDialog(parent),
     ui(new Ui::PackageSelector)
 {
     ui->setupUi(this); 
        iPkg = pkg;
        iAptInterface = apt;
+       iSettings = set;
        iNetworkAccessManager = 0;
        iChangelogFetched = false;
+       iFetchInProgress = false;
        iChangelog = "";
 
        ui->pushButton_website->setIcon(QPixmap("/usr/share/icons/hicolor/48x48/hildon/general_web.png"));
-       if( getMaemoOrgUrl(pkg)=="" && getMaemoOrgUrl(pkg->availablePackage())=="" ) {
+       if( getMaemoOrgUrl(pkg).isEmpty() && getMaemoOrgUrl(pkg->availablePackage()).isEmpty() ) {
                ui->pushButton_website->setEnabled(false);
        }
        if( pkg->isMarkedForOperation() )
                ui->pushButton_blacklist->setEnabled(false);
 
        if( pkg->icon() && !pkg->icon()->isNull() ) {
-               ui->label_appicon->setPixmap( *pkg->icon() );
+               QPixmap aicon( *pkg->icon() );
+               ui->label_appicon->setPixmap( aicon.scaled(48,48) );
        } else {
                ui->label_appicon->setPixmap( QPixmap(":/icons/icons/appdefault.png") );
        }
@@ -73,7 +77,7 @@ PackageSelector::PackageSelector(Package* pkg, AAptInterface* apt, QWidget *pare
        Package* upg_pkg = iPkg->availablePackage();
        if( !upg_pkg )
                upg_pkg = iPkg;
-       if( (!pkg->isUpgradeable() || (upg_pkg && upg_pkg->upgradeDescription()=="")) && (getMaemoOrgUrl(upg_pkg)=="") )
+       if( (!pkg->isUpgradeable() || (upg_pkg && upg_pkg->upgradeDescription().isEmpty())) && (getMaemoOrgUrl(upg_pkg).isEmpty()) )
                ui->radioTabChanges->hide();
 
        if( pkg->isUpgradeable() )
@@ -101,12 +105,20 @@ PackageSelector::PackageSelector(Package* pkg, AAptInterface* apt, QWidget *pare
                ui->label_statusicon->setPixmap(QPixmap(":/icons/icons/pkg_remove.png"));
                ui->radioRemove->setChecked(true);
        }
+
+       if( !getMaemoOrgUrl(upg_pkg).isEmpty() && !iChangelogFetched && !iFetchInProgress &&
+               iSettings->qsettings()->value("always_fetch_changes",false).toBool() )
+       {
+               queryChangelog();
+       }
 }
 
 PackageSelector::~PackageSelector()
 {
-       delete iNetworkAccessManager;
-       iNetworkAccessManager = 0;
+       if( iNetworkAccessManager ) {
+               delete iNetworkAccessManager;
+               iNetworkAccessManager = 0;
+       }
     delete ui;
 }
 
@@ -374,6 +386,10 @@ void PackageSelector::on_radioTabBasic_clicked()
                }
        }
 
+       if( !iPkg->maintainerRichText().isEmpty() ) {
+               longtext +="Maintainer: " + iPkg->maintainerRichText() + "<br>";
+       }
+
        longtext += "<br>" + iPkg->descShort();
        QString descLong = iPkg->descLong();
        if( descLong.length()>0 ) {
@@ -395,7 +411,7 @@ void PackageSelector::on_radioTabChanges_clicked()
        if( !upg_pkg )
                upg_pkg = iPkg;
 
-       if( iPkg->isUpgradeable() && upg_pkg && upg_pkg->upgradeDescription()!="" )
+       if( iPkg->isUpgradeable() && upg_pkg && !upg_pkg->upgradeDescription().isEmpty() )
        {
                text += "<u><b>Upgrade description:</b></u>";
                text += "<font size=\"-1\"><br>";
@@ -405,12 +421,14 @@ void PackageSelector::on_radioTabChanges_clicked()
        }
 
        QString changelog;
-       if( getMaemoOrgUrl(upg_pkg)!="" && !iChangelogFetched ) {
+       if( !getMaemoOrgUrl(upg_pkg).isEmpty() && !iChangelogFetched && !iFetchInProgress ) {
                queryChangelog();
                changelog = "Fetching changelog...";
        } else {
                changelog = iChangelog;
-               if( changelog == "" )
+               if( iFetchInProgress )
+                       changelog = "Fetching changelog...";
+               else if( changelog == "" )
                        changelog = "Not available";
        }
 
@@ -427,14 +445,14 @@ void PackageSelector::on_radioTabDepends_clicked()
        ui->label_header2->setText("");
        ui->label_text->setText("");
 
-       QStringList deps = iPkg->dependsRichText();
-       QStringList confl = iPkg->conflictsRichText();
-       QStringList predeps = iPkg->preDependsRichText();
-       QStringList repl = iPkg->replacesRichText();
-       QStringList prov = iPkg->providesRichText();
-       QStringList brks = iPkg->breaksRichText();
-       QStringList recs = iPkg->recommendsRichText();
-       QStringList sugs = iPkg->suggestsRichText();
+       QStringList deps = Package::toTrimmedRichTextList( iPkg->depends() );
+       QStringList confl = Package::toTrimmedRichTextList( iPkg->conflicts() );
+       QStringList predeps = Package::toTrimmedRichTextList( iPkg->preDepends() );
+       QStringList repl = Package::toTrimmedRichTextList( iPkg->replaces() );
+       QStringList prov = Package::toTrimmedRichTextList( iPkg->provides() );
+       QStringList brks = Package::toTrimmedRichTextList( iPkg->breaks() );
+       QStringList recs = Package::toTrimmedRichTextList( iPkg->recommends() );
+       QStringList sugs = Package::toTrimmedRichTextList( iPkg->suggests() );
 
        QString text;
 
@@ -505,10 +523,11 @@ void PackageSelector::on_radioTabDepends_clicked()
 
 void PackageSelector::queryChangelog()
 {
-       if( iChangelogFetched )
+       if( iChangelogFetched || iFetchInProgress )
                return;
 
        iChangelogFetched = false;
+       iFetchInProgress = true;
        iChangelog = "";
 
        Package* pkg = iPkg->availablePackage();
@@ -523,6 +542,12 @@ void PackageSelector::queryChangelog()
        if( !iNetworkAccessManager ) {
                iNetworkAccessManager = new QNetworkAccessManager(this);
                connect(iNetworkAccessManager,SIGNAL(finished(QNetworkReply*)),this,SLOT(changelogFetchNetworkReply(QNetworkReply*)));
+
+               if( iSettings->qsettings()->value("use_proxies").toBool() && !iSettings->qsettings()->value("http_proxy").toString().isEmpty() )
+               {
+                        QNetworkProxy proxy = Settings::createProxyFromString( iSettings->qsettings()->value("http_proxy").toString() );
+                        iNetworkAccessManager->setProxy(proxy);
+               }
        }
 
        QUrl url( getMaemoOrgUrl(pkg) );
@@ -542,18 +567,20 @@ void PackageSelector::changelogFetchNetworkReply(QNetworkReply* reply)
                int pos2 = data.indexOf("</div>", pos);
 
                if( pos!=-1 && pos2!=-1 ) {
-                       iChangelog = parseChangeTable( data.mid(pos,pos2-pos+6) );
+                       iChangelog = parseChangeTable( QString::fromUtf8( data.mid(pos,pos2-pos+6) ) );
                } else {
                        iChangelog = "";
                }
 
-               iChangelogFetched = true;
                qDebug() << "changelog fetched";
        } else {
+               iChangelog = "Not available (Network error)";
                qDebug() << "changelog fetch error:" << reply->error() << reply->errorString();
        }
 
        reply->deleteLater();
+       iFetchInProgress = false;
+       iChangelogFetched = true;
 
        if( this->isVisible() && ui->radioTabChanges->isChecked() )
                on_radioTabChanges_clicked();