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
27 #include <QDBusConnection>
28 #include <QDBusInterface>
29 #include <phonon/AudioOutput>
30 #include <phonon/MediaObject>
38 #include "mainwindow.h"
40 #include "ui_mainwindow.h"
41 #include "aaptinterface.h"
42 #include "packageview.h"
43 #include "confirmdialog.h"
49 #include "rotatingbackground.h"
50 #include "dpkginterface.h"
53 MainWindow::MainWindow(QWidget *parent) :
55 ui(new Ui::MainWindow)
59 iAptInterface = new AAptInterface(this);
60 iWinPackageView = new PackageView(this);
61 iWinPackageView->setAptInterface(iAptInterface);
62 iWinRepoView = new RepoView(this);
63 iWinRepoView->setAptInterface(iAptInterface);
64 iSettings = new Settings(this);
65 iSettings->setAptInterface(iAptInterface);
66 iSettings->setPackageView(iWinPackageView);
67 iWinPackageView->setSettings(iSettings);
68 iAptInterface->setSettings(iSettings);
69 iDpkgInterface = new DpkgInterface(this);
71 iWinPackageView->setSortOrder( (PackageView::sortOrder)iSettings->qsettings()->value("default_sort_order",0).toInt() );
73 iWinPackageView->setSearchOptions( iSettings->qsettings()->value("search_pkgnames",true).toBool(),
74 iSettings->qsettings()->value("search_displaynames",true).toBool(),
75 iSettings->qsettings()->value("search_descshort",true).toBool(),
76 iSettings->qsettings()->value("search_desclong",false).toBool() );
79 this->setAttribute(Qt::WA_Maemo5StackedWindow);
80 if( !iSettings->qsettings()->value("disable_autorotation",false).toBool() ) {
81 this->setAttribute(Qt::WA_Maemo5AutoOrientation);
83 this->setAttribute(Qt::WA_Maemo5LandscapeOrientation);
87 iDimmer = new dimmer(this);
89 iReposAutoUpdating = false;
90 iUpgradeAutoUpdate = true;
91 iNextOperation = OpNone;
93 connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(orientationChanged()));
95 ui->centralWidget->loadWallpaper();
98 QString stylesheet_mainscreen =
100 "border-radius: 16px;"
102 "border-color: palette(light);"
103 "border-style: outset;"
104 "padding-right: 10px;"
105 "padding-left: 10px;"
106 "color: palette(buttontext);"
107 "background: rgba(255,255,255,80);"
109 "QPushButton:pressed {"
110 "border-style: inset;"
111 "background-color: rgba(255,255,255,150);"
115 if( ((QApplication*)QApplication::instance())->styleSheet().isEmpty() )
117 QString stylesheet_file;
118 QFile f("/root/.fapman/style.css");
119 if( f.open(QIODevice::ReadOnly | QIODevice::Text ) )
122 stylesheet_file += f.readLine().trimmed();
127 if( stylesheet_file.isEmpty() ) {
128 //ui->centralWidget->setStyleSheet(stylesheet_mainscreen);
130 ((QApplication*)QApplication::instance())->setStyleSheet(stylesheet_file);
138 QDBusConnection conn = QDBusConnection::connectToBus(QDBusConnection::SystemBus, "faster_application_manager");
140 QString service = "com.nokia.icd";
141 QString path = "/com/nokia/icd";
142 QString method = "connect";
144 QDBusInterface net(service, path, service, conn, this);
145 net.call(method,"[ANY]",0);
148 iMediaObject = new Phonon::MediaObject(this);
149 Phonon::AudioOutput* aout = new Phonon::AudioOutput(Phonon::NotificationCategory, this);
150 Phonon::createPath(iMediaObject, aout);
155 MainWindow::~MainWindow()
157 // save "need repo refresh" status
158 iSettings->qsettings()->setValue("need_repo_refresh", iAptInterface->needRepoRefresh());
160 delete iWinPackageView;
162 delete iAptInterface;
163 delete iDpkgInterface;
169 void MainWindow::changeEvent(QEvent *e)
171 QMainWindow::changeEvent(e);
173 case QEvent::LanguageChange:
174 ui->retranslateUi(this);
181 void MainWindow::on_btnRepos_clicked()
183 iWinRepoView->openWin();
186 void MainWindow::on_btnUpdate_clicked()
190 busyDialog(true, tr("Operation in progress"), tr("Updating catalogs"));
192 iAptInterface->addQueuedOperation(AAptInterface::ModeAptGetUpdate);
193 iAptInterface->run(iDimmer);
197 int MainWindow::top_application()
206 void MainWindow::dateFetchAsk()
208 if( !iSettings->qsettings()->value("firstrun_asked_fetch_dates",false).toBool() &&
209 !iSettings->qsettings()->value("fetch_dates",false).toBool() )
211 iSettings->qsettings()->setValue("firstrun_asked_fetch_dates", true);
212 ConfirmDialog d(true, this);
213 d.setText("Fetch date information?","Enable date information fetching for packages? You have to enable it in order to be "
214 "able to sort packages by date. The first fetch can be slow but the dates are cached for later use. You can later "
215 "change this selection from the options menu.");
217 iSettings->qsettings()->setValue("fetch_dates", true);
219 if( iSettings->qsettings()->value("fetch_dates",false).toBool() )
221 iSettings->qsettings()->setValue("firstrun_asked_fetch_dates", true); // don't ask if the option has already been enabled
222 if( !iAptInterface->dateCacheExists() )
224 ConfirmDialog d(false, this);
225 d.setText("Notice","Date information will be fetched only for packages from maemo.org and only for user categories.");
228 iAptInterface->addQueuedOperation(AAptInterface::ModeFetchDates);
232 void MainWindow::on_btnListInstallable_clicked()
238 if( iAptInterface->lastListUpdate() < QDateTime::currentDateTime().addSecs(-KListExpireTime) )
240 if( iAptInterface->lastDpkgUpdate() < QDateTime::currentDateTime().addSecs(-KListExpireTime) )
242 iAptInterface->setNeedRefresh(-1,listupd,dpkgupd,listupd);
244 iWinPackageView->setStatFilter( Package::PkgStatNotInstalled );
246 if( iAptInterface->needRepoRefresh() && !iSettings->qsettings()->value("no_catalogs_autoupdate",false).toBool() )
247 iAptInterface->addQueuedOperation(AAptInterface::ModeAptGetUpdate);
249 busyDialog(true, tr("Operation in progress"), tr("Reading package lists"));
251 iNextOperation = OpOpenPkgView;
252 iAptInterface->addQueuedOperation(AAptInterface::ModeReadPackages);
256 iAptInterface->run(iDimmer);
259 void MainWindow::on_btnUpgrade_clicked()
265 if( iAptInterface->lastListUpdate() < QDateTime::currentDateTime().addSecs(-KListExpireTime) )
267 if( iAptInterface->lastDpkgUpdate() < QDateTime::currentDateTime().addSecs(-KListExpireTime) )
269 iAptInterface->setNeedRefresh(-1,listupd,dpkgupd,listupd);
271 iWinPackageView->setStatFilter( Package::PkgStatUpgradeable );
273 if( iAptInterface->needRepoRefresh() && !iSettings->qsettings()->value("no_catalogs_autoupdate",false).toBool() )
274 iAptInterface->addQueuedOperation(AAptInterface::ModeAptGetUpdate);
276 busyDialog(true, tr("Operation in progress"), tr("Reading package lists"));
278 iNextOperation = OpOpenPkgView;
279 iAptInterface->addQueuedOperation(AAptInterface::ModeReadPackages);
283 iAptInterface->run(iDimmer);
286 void MainWindow::on_btnListInstalled_clicked()
290 if( !iSettings->qsettings()->value("remove_readfull",false).toBool() )
291 iAptInterface->setSkipListAndDates();
294 if( iAptInterface->lastDpkgUpdate() < QDateTime::currentDateTime().addSecs(-KListExpireTime) )
296 iAptInterface->setNeedRefresh(-1,-1,dpkgupd,-1);
298 iWinPackageView->setStatFilter( Package::PkgStatInstalled );
300 busyDialog(true, tr("Operation in progress"), tr("Reading package lists"));
302 iNextOperation = OpOpenPkgView;
303 iAptInterface->addQueuedOperation(AAptInterface::ModeReadPackages);
307 iAptInterface->run(iDimmer);
310 void MainWindow::operationQueueFinished(QList<AAptInterface::interfaceMode> lastModes, bool success, QString title, QStringList msgs)
312 if( lastModes.contains(AAptInterface::ModeAptGetSimulate) && success ) {
313 iNextOperation = OpPromptSimulated;
315 if( lastModes.contains(AAptInterface::ModeAptGetInstall) && success ) {
316 iWinPackageView->clearSelections();
318 iWinPackageView->close();
319 iNextOperation = OpNone;
321 GdkEventIconThemeReload();
324 QWidget* dialogParent = this;
325 if( iWinPackageView->isVisible() )
326 dialogParent = iWinPackageView;
328 if( iNextOperation == OpOpenPkgView && success )
330 iWinPackageView->openWin();
332 iNextOperation = OpNone;
333 } else if( iNextOperation == OpPromptSimulated && success )
335 QStringList inst,remv,instver,remvver;
336 QStringList all = iAptInterface->processPackages();
337 QStringList vers = iAptInterface->processPackageVersions();
338 for(int zyx=0; zyx<all.count(); zyx++)
340 if( all.at(zyx).endsWith('-') )
342 remv.append( all.at(zyx).left( all.at(zyx).size()-1 ) );
343 if( vers.count()>zyx )
344 remvver.append( vers.at(zyx) );
346 inst.append( all.at(zyx) );
347 if( vers.count()>zyx )
348 instver.append( vers.at(zyx) );
352 int total_dl_size = 0;
353 for( int i=0; i<inst.count(); i++ ) {
354 Package* pkg = iAptInterface->packagesAvailable()->value(inst.at(i),0);
356 total_dl_size += pkg->size()/1024;
361 pkglist = QString("<b>The following operations will be performed:</b><br>"
362 "%1 to install/upgrade, %2 to remove<br>").arg(inst.count()).arg(remv.count());
364 pkglist += QString("Total download size: %L1 kB<br>").arg(total_dl_size);
365 bool mismatch = false;
366 bool warn_system_package_remove = false;
367 bool warn_system_package_install = false;
369 if( remv.count()>0 ) {
370 pkglist += "<br><b><u>REMOVE:</u></b><br><font size=\"-1\">";
371 for( int i=0; i<remv.count(); i++ ) {
372 pkglist += "<b>" + remv.at(i) + "</b>";
373 Package* pkg = iAptInterface->packagesInstalled()->value(remv.at(i),0);
375 qDebug() << "Warning: unknown package" << remv.at(i);
376 pkglist += "<font color=\"red\">***UNKNOWN***</font>";
380 if( pkg && pkg->maemoDisplayName()=="Maemo 5" ) {
381 warn_system_package_remove = true;
384 if( remvver.count()>i ) {
385 pkglist += " " + remvver.at(i);
386 if( pkg && remvver.at(i) != pkg->version() ) {
387 qDebug() << "Version mismatch, database version is" << pkg->version() << "but removing" << remvver.at(i);
389 pkglist += " <font color=\"red\">***TRYING TO REMOVE " + pkg->version() + "***</font> ";
392 if( pkg && pkg->installedSize()>0 )
393 pkglist += QString(" (%L1 kB)").arg(pkg->installedSize());
397 pkglist += "</font>";
399 bool installing_blacklisted = false;
400 if( inst.count()>0 ) {
401 pkglist += "<br><b><u>INSTALL/UPGRADE:</u></b><br><font size=\"-1\">";
402 for( int i=0; i<inst.count(); i++ ) {
403 pkglist += "<b>" + inst.at(i) + "</b>";
404 Package* pkg = iAptInterface->packagesAvailable()->value(inst.at(i),0);
406 qDebug() << "Warning: unknown package" << inst.at(i);
407 pkglist += "<font color=\"red\">***NEW/UNKNOWN***</font>";
410 if( pkg && pkg->isBlacklisted() ) {
411 qDebug() << "Warning: installing blacklisted package" << inst.at(i);
412 pkglist += "<font color=\"red\">***BLACKLISTED***</font>";
413 installing_blacklisted = true;
416 if( pkg && pkg->maemoDisplayName()=="Maemo 5" ) {
417 warn_system_package_install = true;
420 if( instver.count()>i ) {
421 pkglist += " " + instver.at(i);
422 if( pkg && instver.at(i) != pkg->version() ) {
423 qDebug() << "Version mismatch, database version is" << pkg->version() << "but installing" << instver.at(i);
425 pkglist += " <font color=\"red\">***TRYING TO INSTALL " + pkg->version() + "***</font> ";
428 if( pkg && pkg->size()>0 ) {
429 pkglist += QString(" (%L1 kB)").arg(pkg->size()/1024);
434 pkglist += "</font>";
437 ConfirmDialog m(false, dialogParent);
438 m.setText("Warning", "There is a version mismatch between your original package selections and some of the packages being installed " \
439 "from the repositories. This could be due to your application catalogs being out of date.");
442 if( installing_blacklisted ) {
443 ConfirmDialog b(false, dialogParent);
444 b.setText("Warning","Blacklisted package(s) will be installed");
447 if( warn_system_package_remove ) {
448 ConfirmDialog s(false, dialogParent);
449 s.setText("Warning","You are about to remove a critical system package.");
452 if( warn_system_package_install ) {
453 ConfirmDialog s(false, dialogParent);
454 s.setText("Warning","You are trying to perform an install/upgrade operation on a critical system package. Doing a system upgrade with " \
455 "Faster Application Manager has not been tested and it could result in a horrible failure. You have been warned.");
460 ConfirmDialog d(true, dialogParent);
461 if( inst.count()==0 && remv.count()==0 )
463 pkglist = "None of the packages can be installed";
466 d.setText("Confirmation",pkglist);
468 iAptInterface->addQueuedOperation(AAptInterface::ModeAptGetInstall);
470 if( iSettings->qsettings()->value("enable_autoclean",true).toBool() && inst.count()>0 )
471 iAptInterface->addQueuedOperation(AAptInterface::ModeAptGetClean);
474 if( remv.count() > 0 )
475 busytext += QString("Remove %1 package(s)<br>").arg(remv.count());
476 if( inst.count() > 0 )
477 busytext += QString("Install %1 package(s)<br>").arg(inst.count());
478 busytext += "Preparing...";
479 busyDialog(true, "Operation in progress", busytext);
481 // "run" really does nothing here since the previous item should still be running
482 if( iWinPackageView->isVisible() ) {
483 iAptInterface->run(iWinPackageView->mydimmer());
485 iAptInterface->run(iDimmer);
488 iNextOperation = OpNone;
492 iNextOperation = OpNone;
494 if( iSettings->qsettings()->value("sound_notify",false).toBool() )
496 qDebug() << "playing sound";
497 iMediaObject->setCurrentSource( Phonon::MediaSource(iSettings->qsettings()->value("sound_file","/usr/share/sounds/ui-operation_ready.wav").toString()) );
498 iMediaObject->play();
501 QString text = "<br><b><u>Faster Application Manager</u></b><br>"
502 "<b>"+title+"</b><br>" + msgs.join("<br>") + "<br>";
504 QRect r = QApplication::desktop()->rect();
505 if(r.width() < r.height()) {
506 ConfirmDialog d(false, dialogParent);
507 d.setText(title,msgs.join("<br>"));
511 QMaemo5InformationBox::information(0, text, QMaemo5InformationBox::NoTimeout);
513 ConfirmDialog d(false, dialogParent);
514 d.setText(title,msgs.join("<br>"));
524 void MainWindow::busyDialog(bool show_, QString title, QString text)
527 iDimmer->setProgress(-1);
528 ui->menuMenu->setEnabled(false);
529 ui->centralWidget->setEnabled(false);
530 iWinPackageView->disableMenu();
531 iDimmer->resizeEvent(0);
532 iDimmer->dim(title, text);
533 iWinPackageView->mydimmer()->resizeEvent(0);
534 iWinPackageView->mydimmer()->dim(title, text);
537 iWinPackageView->mydimmer()->undim();
538 ui->menuMenu->setEnabled(true);
539 ui->centralWidget->setEnabled(true);
540 iWinPackageView->enableMenu();
544 void MainWindow::on_actionAbout_triggered()
546 ConfirmDialog d(false, this);
547 d.setText("About","Faster Application Manager<br>"
548 "<font size=\"-1\">Version " + PROGRAM_VERSION + "</font><br><br>"
549 "(C) Heikki Holstila 2010<br>Donate using "
550 "<a href=\"https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=6ZKRY5QFHL42A&lc=FI&item_name=Faster%20Application%20Manager"
551 "%20for%20Maemo5¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted\">PayPal</a>");
555 void MainWindow::on_actionClean_triggered()
557 //if( iOperation != OpNone ) return;
558 //iOperation = OpClean;
559 iAptInterface->addQueuedOperation(AAptInterface::ModeAptGetClean);
560 iAptInterface->run(iDimmer);
563 void MainWindow::closeEvent(QCloseEvent *event)
565 if( iDimmer->busy() ) {
566 iAptInterface->cancel();
573 void MainWindow::on_actionView_log_triggered()
575 QByteArray log = iAptInterface->readLogFile();
576 LogView l(log, this);
580 void MainWindow::on_actionOptions_triggered()
582 iSettings->openWin();
585 void MainWindow::notifyDialog(QString title, QString msg)
587 QWidget* dialogParent = this;
588 if( iWinPackageView->isVisible() )
589 dialogParent = iWinPackageView;
591 ConfirmDialog d(false, dialogParent);
592 d.setText(title, msg);
596 bool MainWindow::confirmDialog(QString title, QString msg)
598 QWidget* dialogParent = this;
599 if( iWinPackageView->isVisible() )
600 dialogParent = iWinPackageView;
602 ConfirmDialog d(true, dialogParent);
603 d.setText(title, msg);
607 void MainWindow::GdkEventIconThemeReload()
609 // DOES NOT EVEN WORK (at least not reliably) - disabled from the project file
611 #ifdef MYDEF_GTK_EXISTS
612 qDebug() << "Sending GDK icon theme reload event";
614 gdk_init((int*)QApplication::argc(),(gchar***)QApplication::argv());
616 // taken from hildon application manager
618 ev.type = GDK_CLIENT_EVENT;
620 ev.send_event = TRUE;
621 ev.message_type = gdk_atom_intern_static_string("_GTK_LOAD_ICONTHEMES");
623 gdk_event_send_clientmessage_toall((GdkEvent*)&ev);
625 while(gdk_events_pending()) {
626 g_main_context_iteration(NULL, true);
632 void MainWindow::on_actionLoad_file_triggered()
634 QStringList files = QFileDialog::getOpenFileNames(this, "Open files", "/", "Files (*.deb *.install)");
635 if( files.count() > 0 ) {
636 QStringList debs = files.filter(QRegExp(".*\\.deb$"));
637 QStringList installs = files.filter(QRegExp(".*\\.install$"));
638 if( debs.count()>0 && installs.count()>0 ) {
639 ConfirmDialog d(false, this);
640 d.setText("Error", "You can't mix different file types in your selection");
645 iDpkgInterface->loadDebFiles(debs);
646 else if( installs.count()>0 )
647 iAptInterface->loadInstallFiles(installs);
651 void MainWindow::orientationChanged()
653 //ui->centralWidget->adjustSize();
654 //ui->listWidget->adjustSize();
658 void MainWindow::showFreeSpace()
660 quint64 warn_limit_root = 5120;
661 quint64 warn_limit_opt = 51200;
662 struct statfs root_stat;
663 struct statfs opt_stat;
664 statfs("/",&root_stat);
665 statfs("/opt",&opt_stat);
666 quint64 free_root = root_stat.f_bavail * root_stat.f_bsize / 1024;
667 quint64 free_opt = opt_stat.f_bavail * opt_stat.f_bsize / 1024;
668 quint64 total_root = root_stat.f_blocks * root_stat.f_bsize / 1024;
669 quint64 total_opt = opt_stat.f_blocks * opt_stat.f_bsize / 1024;
670 qDebug() << "rootfs" << free_root << "/" << total_root << "kB free";
671 qDebug() << "opt fs" << free_opt << "/" << total_opt << "kB free";
673 QString rootstr = QString("rootfs: %L1 / %L2 MB free").arg(free_root/1024).arg(total_root/1024);
674 QString optstr = QString("opt: %L1 / %L2 MB free").arg(free_opt/1024).arg(total_opt/1024);
676 ui->label->setText("<font size=\"-1\">" + rootstr + "<br>" + optstr + "</font>");
679 ui->progressBarRoot->setFormat(rootstr);
680 ui->progressBarRoot->setMaximum(total_root/1024);
681 ui->progressBarRoot->setValue(free_root/1024);
682 ui->progressBarOpt->setFormat(optstr);
683 ui->progressBarOpt->setMaximum(total_opt/1024);
684 ui->progressBarOpt->setValue(free_opt/1024);
687 if( free_root < warn_limit_root || free_opt < warn_limit_opt )
689 ConfirmDialog d(false, this);
691 if( free_root < warn_limit_root )
692 t += QString("Root filesystem has %L1 kB available<br>").arg(free_root);
693 if( free_opt < warn_limit_opt )
694 t += QString("Opt (home) filesystem has %L1 kB available<br>").arg(free_opt);
695 t += "<br>You may proceed, but consider freeing up space to prevent problems in the future";
696 d.setText("Warning: Low disk space",t);
701 void MainWindow::on_listWidget_itemClicked(QListWidgetItem* item)
703 if( item->text() == "Manage repositories" ) {
704 on_btnRepos_clicked();
706 else if( item->text() == "Update catalogs" ) {
707 on_btnUpdate_clicked();
709 else if( item->text() == "Install applications" ) {
710 on_btnListInstallable_clicked();
712 else if( item->text() == "Remove applications" ) {
713 on_btnListInstalled_clicked();
715 else if( item->text() == "Upgrade applications" ) {
716 on_btnUpgrade_clicked();
719 qDebug() << "Warning: Unhandled main menu item";
721 item->setSelected(false);