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
20 #ifdef MYDEF_GTK_EXISTS
30 #include <QDBusConnection>
31 #include <QDBusInterface>
32 #include <phonon/AudioOutput>
33 #include <phonon/MediaObject>
44 #include "mainwindow.h"
46 #include "ui_mainwindow.h"
47 #include "aaptinterface.h"
48 #include "packageview.h"
49 #include "confirmdialog.h"
55 #include "rotatingbackground.h"
56 #include "dpkginterface.h"
59 MainWindow::MainWindow(QWidget *parent) :
61 ui(new Ui::MainWindow)
65 iAptInterface = new AAptInterface(this);
66 iWinPackageView = new PackageView(this);
67 iWinPackageView->setAptInterface(iAptInterface);
68 iWinRepoView = new RepoView(this);
69 iWinRepoView->setAptInterface(iAptInterface);
70 iSettings = new Settings(this);
71 iSettings->setAptInterface(iAptInterface);
72 iSettings->setPackageView(iWinPackageView);
73 iWinPackageView->setSettings(iSettings);
74 iAptInterface->setSettings(iSettings);
75 iDpkgInterface = new DpkgInterface(this);
77 iWinPackageView->setSortOrder( (PackageView::sortOrder)iSettings->qsettings()->value("default_sort_order",0).toInt() );
79 iWinPackageView->setSearchOptions( iSettings->qsettings()->value("search_pkgnames",true).toBool(),
80 iSettings->qsettings()->value("search_displaynames",true).toBool(),
81 iSettings->qsettings()->value("search_descshort",true).toBool(),
82 iSettings->qsettings()->value("search_desclong",false).toBool() );
85 if( !iSettings->qsettings()->value("disable_autorotation",false).toBool() ) {
86 this->setAttribute(Qt::WA_Maemo5AutoOrientation);
88 this->setAttribute(Qt::WA_Maemo5LandscapeOrientation);
90 this->setAttribute(Qt::WA_Maemo5StackedWindow);
93 iDimmer = new dimmer(this);
95 iReposAutoUpdating = false;
96 iUpgradeAutoUpdate = true;
97 iNextOperation = OpNone;
99 connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(orientationChanged()));
101 ui->centralWidget->loadWallpaper();
104 QString stylesheet_mainscreen =
106 "border-radius: 16px;"
108 "border-color: palette(light);"
109 "border-style: outset;"
110 "padding-right: 10px;"
111 "padding-left: 10px;"
112 "color: palette(buttontext);"
113 "background: rgba(255,255,255,80);"
115 "QPushButton:pressed {"
116 "border-style: inset;"
117 "background-color: rgba(255,255,255,150);"
121 if( ((QApplication*)QApplication::instance())->styleSheet().isEmpty() )
123 QString stylesheet_file;
124 QFile f("/root/.fapman/style.css");
125 if( f.open(QIODevice::ReadOnly | QIODevice::Text ) )
128 stylesheet_file += f.readLine().trimmed();
133 if( stylesheet_file.isEmpty() ) {
134 //ui->centralWidget->setStyleSheet(stylesheet_mainscreen);
136 ((QApplication*)QApplication::instance())->setStyleSheet(stylesheet_file);
144 QDBusConnection conn = QDBusConnection::connectToBus(QDBusConnection::SystemBus, "faster_application_manager");
146 QString service = "com.nokia.icd";
147 QString path = "/com/nokia/icd";
148 QString method = "connect";
150 QDBusInterface net(service, path, service, conn, this);
151 net.call(method,"[ANY]",0);
154 iMediaObject = new Phonon::MediaObject(this);
155 Phonon::AudioOutput* aout = new Phonon::AudioOutput(Phonon::NotificationCategory, this);
156 Phonon::createPath(iMediaObject, aout);
161 orientationChanged();
164 MainWindow::~MainWindow()
166 // save "need repo refresh" status
167 iSettings->qsettings()->setValue("need_repo_refresh", iAptInterface->needRepoRefresh());
169 delete iWinPackageView; iWinPackageView=0;
170 delete iWinRepoView; iWinRepoView=0;
171 delete iAptInterface; iAptInterface=0;
172 delete iDpkgInterface; iDpkgInterface=0;
173 delete iDimmer; iDimmer=0;
174 delete iSettings; iSettings=0;
176 //iMediaObject and aout automatically deleted by their parent
179 void MainWindow::changeEvent(QEvent *e)
181 QMainWindow::changeEvent(e);
183 case QEvent::LanguageChange:
184 ui->retranslateUi(this);
191 void MainWindow::on_btnRepos_clicked()
193 iWinRepoView->openWin();
196 void MainWindow::on_btnUpdate_clicked()
200 busyDialog(true, tr("Operation in progress"), tr("Updating catalogs"));
202 iAptInterface->addQueuedOperation(AAptInterface::ModeAptGetUpdate);
203 iAptInterface->run(iDimmer);
207 int MainWindow::top_application()
216 void MainWindow::dateFetchAsk()
218 if( !iSettings->qsettings()->value("firstrun_asked_fetch_dates",false).toBool() &&
219 !iSettings->qsettings()->value("fetch_dates",false).toBool() )
221 iSettings->qsettings()->setValue("firstrun_asked_fetch_dates", true);
222 ConfirmDialog d(true, this);
223 d.setText("Fetch date information?","Enable date information fetching for packages? You have to enable it in order to be "
224 "able to sort packages by date. The first fetch can be slow but the dates are cached for later use. You can later "
225 "change this selection from the options menu.");
227 iSettings->qsettings()->setValue("fetch_dates", true);
229 if( iSettings->qsettings()->value("fetch_dates",false).toBool() )
231 iSettings->qsettings()->setValue("firstrun_asked_fetch_dates", true); // don't ask if the option has already been enabled
232 if( !iAptInterface->dateCacheExists() )
234 ConfirmDialog d(false, this);
235 d.setText("Notice","Date information will be fetched only for packages from maemo.org and only for user categories.");
238 iAptInterface->addQueuedOperation(AAptInterface::ModeFetchDates);
242 void MainWindow::on_btnListInstallable_clicked()
248 if( iAptInterface->lastListUpdate() < QDateTime::currentDateTime().addSecs(-KListExpireTime) )
250 if( iAptInterface->lastDpkgUpdate() < QDateTime::currentDateTime().addSecs(-KListExpireTime) )
252 iAptInterface->setNeedRefresh(-1,listupd,dpkgupd,listupd);
254 iWinPackageView->setStatFilter( Package::PkgStatNotInstalled );
256 if( iAptInterface->needRepoRefresh() && !iSettings->qsettings()->value("no_catalogs_autoupdate",false).toBool() )
257 iAptInterface->addQueuedOperation(AAptInterface::ModeAptGetUpdate);
259 busyDialog(true, tr("Operation in progress"), tr("Reading package lists"));
261 iNextOperation = OpOpenPkgView;
262 iAptInterface->addQueuedOperation(AAptInterface::ModeReadPackages);
266 iAptInterface->run(iDimmer);
269 void MainWindow::on_btnUpgrade_clicked()
275 if( iAptInterface->lastListUpdate() < QDateTime::currentDateTime().addSecs(-KListExpireTime) )
277 if( iAptInterface->lastDpkgUpdate() < QDateTime::currentDateTime().addSecs(-KListExpireTime) )
279 iAptInterface->setNeedRefresh(-1,listupd,dpkgupd,listupd);
281 iWinPackageView->setStatFilter( Package::PkgStatUpgradeable );
283 if( iAptInterface->needRepoRefresh() && !iSettings->qsettings()->value("no_catalogs_autoupdate",false).toBool() )
284 iAptInterface->addQueuedOperation(AAptInterface::ModeAptGetUpdate);
286 busyDialog(true, tr("Operation in progress"), tr("Reading package lists"));
288 iNextOperation = OpOpenPkgView;
289 iAptInterface->addQueuedOperation(AAptInterface::ModeReadPackages);
293 iAptInterface->run(iDimmer);
296 void MainWindow::on_btnListInstalled_clicked()
300 if( !iSettings->qsettings()->value("remove_readfull",false).toBool() )
301 iAptInterface->setSkipListAndDates();
304 if( iAptInterface->lastDpkgUpdate() < QDateTime::currentDateTime().addSecs(-KListExpireTime) )
306 iAptInterface->setNeedRefresh(-1,-1,dpkgupd,-1);
308 iWinPackageView->setStatFilter( Package::PkgStatInstalled );
310 busyDialog(true, tr("Operation in progress"), tr("Reading package lists"));
312 iNextOperation = OpOpenPkgView;
313 iAptInterface->addQueuedOperation(AAptInterface::ModeReadPackages);
317 iAptInterface->run(iDimmer);
320 void MainWindow::operationQueueFinished(QList<AAptInterface::interfaceMode> lastModes, bool success, QString title, QStringList msgs)
322 if( lastModes.contains(AAptInterface::ModeAptGetSimulate) && success ) {
323 iNextOperation = OpPromptSimulated;
325 if( lastModes.contains(AAptInterface::ModeAptGetInstall) && success ) {
326 iWinPackageView->clearSelections();
328 iWinPackageView->close();
329 iNextOperation = OpNone;
331 GdkEventIconThemeReload();
334 QWidget* dialogParent = this;
335 if( iWinPackageView->isVisible() )
336 dialogParent = iWinPackageView;
338 if( iNextOperation == OpOpenPkgView && success )
340 iWinPackageView->openWin();
342 iNextOperation = OpNone;
343 } else if( iNextOperation == OpPromptSimulated && success )
345 QStringList inst,remv,instver,remvver;
346 QStringList all = iAptInterface->processPackages();
347 QStringList vers = iAptInterface->processPackageVersions();
348 for(int zyx=0; zyx<all.count(); zyx++)
350 if( all.at(zyx).endsWith('-') )
352 remv.append( all.at(zyx).left( all.at(zyx).size()-1 ) );
353 if( vers.count()>zyx )
354 remvver.append( vers.at(zyx) );
356 inst.append( all.at(zyx) );
357 if( vers.count()>zyx )
358 instver.append( vers.at(zyx) );
362 int total_dl_size = 0;
363 for( int i=0; i<inst.count(); i++ ) {
364 Package* pkg = iAptInterface->packagesAvailable()->value(inst.at(i),0);
366 total_dl_size += pkg->size()/1024;
371 pkglist = QString("<b>The following operations will be performed:</b><br>"
372 "%1 to install/upgrade, %2 to remove<br>").arg(inst.count()).arg(remv.count());
374 pkglist += QString("Total download size: %L1 kB<br>").arg(total_dl_size);
375 bool mismatch = false;
376 bool warn_system_package_remove = false;
377 bool warn_system_package_install = false;
379 if( remv.count()>0 ) {
380 pkglist += "<br><b><u>REMOVE:</u></b><br><font size=\"-1\">";
381 for( int i=0; i<remv.count(); i++ ) {
382 pkglist += "<b>" + remv.at(i) + "</b>";
383 Package* pkg = iAptInterface->packagesInstalled()->value(remv.at(i),0);
385 qDebug() << "Warning: unknown package" << remv.at(i);
386 pkglist += "<font color=\"red\">***UNKNOWN***</font>";
390 if( pkg && pkg->maemoDisplayName()=="Maemo 5" ) {
391 warn_system_package_remove = true;
394 if( remvver.count()>i ) {
395 pkglist += " " + remvver.at(i);
396 if( pkg && remvver.at(i) != pkg->version() ) {
397 qDebug() << "Version mismatch, database version is" << pkg->version() << "but removing" << remvver.at(i);
399 pkglist += " <font color=\"red\">***TRYING TO REMOVE " + pkg->version() + "***</font> ";
402 if( pkg && pkg->installedSize()>0 )
403 pkglist += QString(" (%L1 kB)").arg(pkg->installedSize());
407 pkglist += "</font>";
409 bool installing_blacklisted = false;
410 if( inst.count()>0 ) {
411 pkglist += "<br><b><u>INSTALL/UPGRADE:</u></b><br><font size=\"-1\">";
412 for( int i=0; i<inst.count(); i++ ) {
413 pkglist += "<b>" + inst.at(i) + "</b>";
414 Package* pkg = iAptInterface->packagesAvailable()->value(inst.at(i),0);
416 qDebug() << "Warning: unknown package" << inst.at(i);
417 pkglist += "<font color=\"red\">***NEW/UNKNOWN***</font>";
420 if( pkg && pkg->isBlacklisted() ) {
421 qDebug() << "Warning: installing blacklisted package" << inst.at(i);
422 pkglist += "<font color=\"red\">***BLACKLISTED***</font>";
423 installing_blacklisted = true;
426 if( pkg && pkg->maemoDisplayName()=="Maemo 5" ) { // unreliable?
427 warn_system_package_install = true;
430 if( instver.count()>i ) {
431 pkglist += " " + instver.at(i);
432 if( pkg && instver.at(i) != pkg->version() ) {
433 qDebug() << "Version mismatch, database version is" << pkg->version() << "but installing" << instver.at(i);
435 pkglist += " <font color=\"red\">***TRYING TO INSTALL " + pkg->version() + "***</font> ";
438 if( pkg && pkg->size()>0 ) {
439 pkglist += QString(" (%L1 kB)").arg(pkg->size()/1024);
444 pkglist += "</font>";
447 ConfirmDialog m(false, dialogParent);
448 m.setText("Warning", "There is a version mismatch between your original package selections and some of the packages being installed " \
449 "from the repositories. This could be due to your application catalogs being out of date.");
452 if( installing_blacklisted ) {
453 ConfirmDialog b(false, dialogParent);
454 b.setText("Warning","Blacklisted package(s) will be installed");
457 if( warn_system_package_remove ) {
458 ConfirmDialog s(false, dialogParent);
459 s.setText("Warning","You are about to remove a critical system package.");
462 if( warn_system_package_install ) {
463 ConfirmDialog s(false, dialogParent);
464 s.setText("Warning","You are trying to perform an install/upgrade operation on a critical system package. Doing a system upgrade with " \
465 "Faster Application Manager has not been tested and it could result in a horrible failure. You have been warned.");
470 ConfirmDialog d(true, dialogParent);
471 if( inst.count()==0 && remv.count()==0 )
473 pkglist = "None of the packages can be installed";
476 d.setText("Confirmation",pkglist);
478 iAptInterface->addQueuedOperation(AAptInterface::ModeAptGetInstall);
480 if( iSettings->qsettings()->value("enable_autoclean",true).toBool() && inst.count()>0 )
481 iAptInterface->addQueuedOperation(AAptInterface::ModeAptGetClean);
484 if( remv.count() > 0 )
485 busytext += QString("Remove %1 package(s)<br>").arg(remv.count());
486 if( inst.count() > 0 )
487 busytext += QString("Install %1 package(s)<br>").arg(inst.count());
488 busytext += "Preparing...";
489 busyDialog(true, "Operation in progress", busytext);
491 // "run" really does nothing here since the previous item should still be running
492 if( iWinPackageView->isVisible() ) {
493 iAptInterface->run(iWinPackageView->mydimmer());
495 iAptInterface->run(iDimmer);
498 iNextOperation = OpNone;
502 iNextOperation = OpNone;
504 if( iSettings->qsettings()->value("sound_notify",false).toBool() )
506 qDebug() << "playing sound";
507 iMediaObject->setCurrentSource( Phonon::MediaSource(iSettings->qsettings()->value("sound_file","/usr/share/sounds/ui-operation_ready.wav").toString()) );
508 iMediaObject->play();
511 QString text = "<br><b><u>Faster Application Manager</u></b><br>"
512 "<b>"+title+"</b><br>" + msgs.join("<br>") + "<br>";
514 QRect r = QApplication::desktop()->rect();
515 if(r.width() < r.height()) {
516 ConfirmDialog d(false, dialogParent);
517 d.setText(title,msgs.join("<br>"));
521 QMaemo5InformationBox::information(0, text, QMaemo5InformationBox::NoTimeout);
523 ConfirmDialog d(false, dialogParent);
524 d.setText(title,msgs.join("<br>"));
534 void MainWindow::busyDialog(bool show_, QString title, QString text)
537 iDimmer->setProgress(-1);
538 ui->menuMenu->setEnabled(false);
539 ui->centralWidget->setEnabled(false);
540 iWinPackageView->disableMenu();
541 iDimmer->resizeEvent(0);
542 iDimmer->dim(title, text);
543 iWinPackageView->mydimmer()->resizeEvent(0);
544 iWinPackageView->mydimmer()->dim(title, text);
547 iWinPackageView->mydimmer()->undim();
548 ui->menuMenu->setEnabled(true);
549 ui->centralWidget->setEnabled(true);
550 iWinPackageView->enableMenu();
554 void MainWindow::on_actionAbout_triggered()
556 ConfirmDialog d(false, this);
557 d.setText("About","Faster Application Manager<br>"
558 "<font size=\"-1\">Version " + PROGRAM_VERSION + "</font><br><br>"
559 "(C) Heikki Holstila 2010<br>Donate using "
560 "<a href=\"https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=6ZKRY5QFHL42A&lc=FI&item_name=Faster%20Application%20Manager"
561 "%20for%20Maemo5¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted\">PayPal</a>");
565 void MainWindow::on_actionClean_triggered()
567 //if( iOperation != OpNone ) return;
568 //iOperation = OpClean;
569 iAptInterface->addQueuedOperation(AAptInterface::ModeAptGetClean);
570 iAptInterface->run(iDimmer);
573 void MainWindow::closeEvent(QCloseEvent *event)
575 if( iDimmer->busy() ) {
576 iAptInterface->cancel();
583 void MainWindow::on_actionView_log_triggered()
585 QByteArray log = iAptInterface->readLogFile();
586 LogView l(log, this);
590 void MainWindow::on_actionOptions_triggered()
592 iSettings->openWin();
595 void MainWindow::notifyDialog(QString title, QString msg)
597 QWidget* dialogParent = this;
598 if( iWinPackageView->isVisible() )
599 dialogParent = iWinPackageView;
601 ConfirmDialog d(false, dialogParent);
602 d.setText(title, msg);
606 bool MainWindow::confirmDialog(QString title, QString msg)
608 QWidget* dialogParent = this;
609 if( iWinPackageView->isVisible() )
610 dialogParent = iWinPackageView;
612 ConfirmDialog d(true, dialogParent);
613 d.setText(title, msg);
617 void MainWindow::GdkEventIconThemeReload()
619 // DOES NOT EVEN WORK (at least not reliably) - disabled from the project file
621 #ifdef MYDEF_GTK_EXISTS
622 qDebug() << "Sending GDK icon theme reload event";
624 gdk_init((int*)QApplication::argc(),(gchar***)QApplication::argv());
626 // taken from hildon application manager
628 ev.type = GDK_CLIENT_EVENT;
630 ev.send_event = TRUE;
631 ev.message_type = gdk_atom_intern_static_string("_GTK_LOAD_ICONTHEMES");
633 gdk_event_send_clientmessage_toall((GdkEvent*)&ev);
635 while(gdk_events_pending()) {
636 g_main_context_iteration(NULL, true);
642 void MainWindow::on_actionLoad_file_triggered()
644 QStringList files = QFileDialog::getOpenFileNames(this, "Open files", "/", "Files (*.deb *.install)");
645 if( files.count() > 0 ) {
646 QStringList debs = files.filter(QRegExp(".*\\.deb$"));
647 QStringList installs = files.filter(QRegExp(".*\\.install$"));
648 if( debs.count()>0 && installs.count()>0 ) {
649 ConfirmDialog d(false, this);
650 d.setText("Error", "You can't mix different file types in your selection");
655 iDpkgInterface->loadDebFiles(debs);
656 else if( installs.count()>0 )
657 iAptInterface->loadInstallFiles(installs);
661 void MainWindow::resizeEvent(QResizeEvent* event)
663 QRect sg = ui->listWidget->rect();
665 if( sg.width() > sg.height() ) {
666 ui->listWidget->setGridSize( QSize((sg.width()-12)/5, (sg.height()-12)/2) );
668 ui->listWidget->setGridSize( QSize((sg.width()-12)/3, (sg.height()-12)/3) );
672 iDimmer->resize( this->size() );
675 QMainWindow::resizeEvent(event);
678 void MainWindow::orientationChanged()
683 void MainWindow::showFreeSpace()
685 quint64 warn_limit_root = 5120;
686 quint64 warn_limit_opt = 51200;
687 struct statfs root_stat;
688 struct statfs opt_stat;
689 statfs("/",&root_stat);
690 statfs("/opt",&opt_stat);
691 quint64 free_root = static_cast<quint64>(root_stat.f_bavail) * static_cast<quint64>(root_stat.f_bsize) / 1024;
692 quint64 free_opt = static_cast<quint64>(opt_stat.f_bavail) * static_cast<quint64>(opt_stat.f_bsize) / 1024;
693 quint64 total_root = static_cast<quint64>(root_stat.f_blocks) * static_cast<quint64>(root_stat.f_bsize) / 1024;
694 quint64 total_opt = static_cast<quint64>(opt_stat.f_blocks) * static_cast<quint64>(opt_stat.f_bsize) / 1024;
695 qDebug() << "rootfs" << free_root << "/" << total_root << "kB free";
696 qDebug() << "opt fs" << free_opt << "/" << total_opt << "kB free";
698 QString rootstr = QString("rootfs: %L1 / %L2 MB free").arg(free_root/1024).arg(total_root/1024);
699 QString optstr = QString("opt: %L1 / %L2 MB free").arg(free_opt/1024).arg(total_opt/1024);
701 ui->label->setText("<font size=\"-1\">" + rootstr + "<br>" + optstr + "</font>");
704 ui->progressBarRoot->setFormat(rootstr);
705 ui->progressBarRoot->setMaximum(total_root/1024);
706 ui->progressBarRoot->setValue(free_root/1024);
707 ui->progressBarOpt->setFormat(optstr);
708 ui->progressBarOpt->setMaximum(total_opt/1024);
709 ui->progressBarOpt->setValue(free_opt/1024);
712 if( free_root < warn_limit_root || free_opt < warn_limit_opt )
714 ConfirmDialog d(false, this);
716 if( free_root < warn_limit_root )
717 t += QString("Root filesystem has %L1 kB available<br>").arg(free_root);
718 if( free_opt < warn_limit_opt )
719 t += QString("Opt (home) filesystem has %L1 kB available<br>").arg(free_opt);
720 t += "<br>You may proceed, but consider freeing up space to prevent problems in the future";
721 d.setText("Warning: Low disk space",t);
726 void MainWindow::on_listWidget_itemClicked(QListWidgetItem* item)
728 qDebug() << "main menu:" << item->statusTip();
730 if( item->statusTip() == "manage_repos" ) {
731 on_btnRepos_clicked();
733 else if( item->statusTip() == "update_catalogs" ) {
734 on_btnUpdate_clicked();
736 else if( item->statusTip() == "install_apps" ) {
737 on_btnListInstallable_clicked();
739 else if( item->statusTip() == "remove_apps" ) {
740 on_btnListInstalled_clicked();
742 else if( item->statusTip() == "upgrade_apps" ) {
743 on_btnUpgrade_clicked();
746 qDebug() << "Warning: Unhandled main menu item";
748 item->setSelected(false);