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>
36 #include "mainwindow.h"
38 #include "ui_mainwindow.h"
39 #include "aaptinterface.h"
40 #include "packageview.h"
41 #include "confirmdialog.h"
47 #include "rotatingbackground.h"
48 #include "dpkginterface.h"
51 MainWindow::MainWindow(QWidget *parent) :
53 ui(new Ui::MainWindow)
57 iAptInterface = new AAptInterface(this);
58 iWinPackageView = new PackageView(this);
59 iWinPackageView->setAptInterface(iAptInterface);
60 iWinRepoView = new RepoView(this);
61 iWinRepoView->setAptInterface(iAptInterface);
62 iSettings = new Settings(this);
63 iSettings->setAptInterface(iAptInterface);
64 iSettings->setPackageView(iWinPackageView);
65 iWinPackageView->setSettings(iSettings);
66 iAptInterface->setSettings(iSettings);
67 iDpkgInterface = new DpkgInterface(this);
69 iWinPackageView->setSortOrder( (PackageView::sortOrder)iSettings->qsettings()->value("default_sort_order",0).toInt() );
71 iWinPackageView->setSearchOptions( iSettings->qsettings()->value("search_pkgnames",true).toBool(),
72 iSettings->qsettings()->value("search_displaynames",true).toBool(),
73 iSettings->qsettings()->value("search_descshort",true).toBool(),
74 iSettings->qsettings()->value("search_desclong",false).toBool() );
77 this->setAttribute(Qt::WA_Maemo5StackedWindow);
78 if( !iSettings->qsettings()->value("disable_autorotation",false).toBool() ) {
79 this->setAttribute(Qt::WA_Maemo5AutoOrientation);
81 this->setAttribute(Qt::WA_Maemo5LandscapeOrientation);
85 iDimmer = new dimmer(this);
87 iReposAutoUpdating = false;
88 iUpgradeAutoUpdate = true;
89 iNextOperation = OpNone;
91 ui->centralWidget->loadWallpaper();
93 QString stylesheet_mainscreen =
95 "border-radius: 16px;"
97 "border-color: palette(light);"
98 "border-style: outset;"
99 "padding-right: 10px;"
100 "padding-left: 10px;"
101 "color: palette(buttontext);"
102 "background: rgba(255,255,255,80);"
104 "QPushButton:pressed {"
105 "border-style: inset;"
106 "background-color: rgba(255,255,255,150);"
109 if( ((QApplication*)QApplication::instance())->styleSheet().isEmpty() )
111 QString stylesheet_file;
112 QFile f("/root/.fapman/style.css");
113 if( f.open(QIODevice::ReadOnly | QIODevice::Text ) )
116 stylesheet_file += f.readLine().trimmed();
121 if( stylesheet_file.isEmpty() ) {
122 ui->centralWidget->setStyleSheet(stylesheet_mainscreen);
124 ((QApplication*)QApplication::instance())->setStyleSheet(stylesheet_file);
132 QDBusConnection conn = QDBusConnection::connectToBus(QDBusConnection::SystemBus, "faster_application_manager");
134 QString service = "com.nokia.icd";
135 QString path = "/com/nokia/icd";
136 QString method = "connect";
138 QDBusInterface net(service, path, service, conn, this);
139 net.call(method,"[ANY]",0);
142 iMediaObject = new Phonon::MediaObject(this);
143 Phonon::AudioOutput* aout = new Phonon::AudioOutput(Phonon::NotificationCategory, this);
144 Phonon::createPath(iMediaObject, aout);
149 MainWindow::~MainWindow()
151 // save "need repo refresh" status
152 iSettings->qsettings()->setValue("need_repo_refresh", iAptInterface->needRepoRefresh());
154 delete iWinPackageView;
156 delete iAptInterface;
157 delete iDpkgInterface;
163 void MainWindow::changeEvent(QEvent *e)
165 QMainWindow::changeEvent(e);
167 case QEvent::LanguageChange:
168 ui->retranslateUi(this);
175 void MainWindow::on_btnRepos_clicked()
177 iWinRepoView->openWin();
180 void MainWindow::on_btnUpdate_clicked()
184 busyDialog(true, tr("Operation in progress"), tr("Updating catalogs"));
186 iAptInterface->addQueuedOperation(AAptInterface::ModeAptGetUpdate);
187 iAptInterface->run(iDimmer);
191 int MainWindow::top_application()
200 void MainWindow::dateFetchAsk()
202 if( !iSettings->qsettings()->value("firstrun_asked_fetch_dates",false).toBool() &&
203 !iSettings->qsettings()->value("fetch_dates",false).toBool() )
205 iSettings->qsettings()->setValue("firstrun_asked_fetch_dates", true);
206 ConfirmDialog d(true, this);
207 d.setText("Fetch date information?","Enable date information fetching for packages? You have to enable it in order to be "
208 "able to sort packages by date. The first fetch can be slow but the dates are cached for later use. You can later "
209 "change this selection from the options menu.");
211 iSettings->qsettings()->setValue("fetch_dates", true);
213 if( iSettings->qsettings()->value("fetch_dates",false).toBool() )
215 iSettings->qsettings()->setValue("firstrun_asked_fetch_dates", true); // don't ask if the option has already been enabled
216 if( !iAptInterface->dateCacheExists() )
218 ConfirmDialog d(false, this);
219 d.setText("Notice","Date information will be fetched only for packages from maemo.org and only for user categories.");
222 iAptInterface->addQueuedOperation(AAptInterface::ModeFetchDates);
226 void MainWindow::on_btnListInstallable_clicked()
230 if( iIdlingSince < QDateTime::currentDateTime().addSecs(-30*60) )
231 iAptInterface->setNeedRefresh(-1,1,1,1);
233 iWinPackageView->setStatFilter( Package::PkgStatNotInstalled );
235 if( iAptInterface->needRepoRefresh() )
236 iAptInterface->addQueuedOperation(AAptInterface::ModeAptGetUpdate);
238 busyDialog(true, tr("Operation in progress"), tr("Reading package lists"));
240 iNextOperation = OpOpenPkgView;
241 iAptInterface->addQueuedOperation(AAptInterface::ModeReadPackages);
245 iAptInterface->run(iDimmer);
248 void MainWindow::on_btnUpgrade_clicked()
252 if( iIdlingSince < QDateTime::currentDateTime().addSecs(-30*60) )
253 iAptInterface->setNeedRefresh(-1,1,1,1);
255 iWinPackageView->setStatFilter( Package::PkgStatUpgradeable );
257 if( iAptInterface->needRepoRefresh() )
258 iAptInterface->addQueuedOperation(AAptInterface::ModeAptGetUpdate);
260 busyDialog(true, tr("Operation in progress"), tr("Reading package lists"));
262 iNextOperation = OpOpenPkgView;
263 iAptInterface->addQueuedOperation(AAptInterface::ModeReadPackages);
267 iAptInterface->run(iDimmer);
270 void MainWindow::on_btnListInstalled_clicked()
274 if( !iSettings->qsettings()->value("remove_readfull",false).toBool() )
275 iAptInterface->setSkipListAndDates();
277 if( iIdlingSince < QDateTime::currentDateTime().addSecs(-30*60) )
278 iAptInterface->setNeedRefresh(-1,-1,1,-1);
280 iWinPackageView->setStatFilter( Package::PkgStatInstalled );
282 busyDialog(true, tr("Operation in progress"), tr("Reading package lists"));
284 iNextOperation = OpOpenPkgView;
285 iAptInterface->addQueuedOperation(AAptInterface::ModeReadPackages);
289 iAptInterface->run(iDimmer);
292 void MainWindow::operationQueueFinished(QList<AAptInterface::interfaceMode> lastModes, bool success, QString title, QStringList msgs)
294 if( lastModes.contains(AAptInterface::ModeAptGetSimulate) && success ) {
295 iNextOperation = OpPromptSimulated;
297 if( lastModes.contains(AAptInterface::ModeAptGetInstall) && success ) {
298 iWinPackageView->clearSelections();
300 iWinPackageView->close();
301 iNextOperation = OpNone;
303 GdkEventIconThemeReload();
306 if( iNextOperation == OpOpenPkgView && success )
308 iWinPackageView->openWin();
310 iNextOperation = OpNone;
311 } else if( iNextOperation == OpPromptSimulated && success )
313 QStringList inst,remv,instver,remvver;
314 QStringList all = iAptInterface->processPackages();
315 QStringList vers = iAptInterface->processPackageVersions();
316 for(int zyx=0; zyx<all.count(); zyx++)
318 if( all.at(zyx).endsWith('-') )
320 remv.append( all.at(zyx).left( all.at(zyx).size()-1 ) );
321 if( vers.count()>zyx )
322 remvver.append( vers.at(zyx) );
324 inst.append( all.at(zyx) );
325 if( vers.count()>zyx )
326 instver.append( vers.at(zyx) );
330 int total_dl_size = 0;
331 for( int i=0; i<inst.count(); i++ ) {
332 Package* pkg = iAptInterface->packagesAvailable()->value(inst.at(i),0);
334 total_dl_size += pkg->size()/1024;
339 pkglist = QString("<b>The following operations will be performed:</b><br>"
340 "%1 to install/upgrade, %2 to remove<br>").arg(inst.count()).arg(remv.count());
342 pkglist += QString("Total download size: %L1 kB<br>").arg(total_dl_size);
343 bool mismatch = false;
345 if( remv.count()>0 ) {
346 pkglist += "<br><b><u>REMOVE:</u></b><br><font size=\"-1\">";
347 for( int i=0; i<remv.count(); i++ ) {
348 pkglist += "<b>" + remv.at(i) + "</b>";
349 Package* pkg = iAptInterface->packagesInstalled()->value(remv.at(i),0);
351 qDebug() << "Warning: unknown package" << remv.at(i);
352 pkglist += "<font color=\"red\">***UNKNOWN***</font>";
355 if( remvver.count()>i ) {
356 pkglist += " " + remvver.at(i);
357 if( pkg && remvver.at(i) != pkg->version() ) {
358 qDebug() << "Version mismatch, database version is" << pkg->version() << "but removing" << remvver.at(i);
360 pkglist += " <font color=\"red\">***TRYING TO REMOVE " + pkg->version() + "***</font> ";
363 if( pkg && pkg->installedSize()>0 )
364 pkglist += QString(" (%L1 kB)").arg(pkg->installedSize());
368 pkglist += "</font>";
370 bool installing_blacklisted = false;
371 if( inst.count()>0 ) {
372 pkglist += "<br><b><u>INSTALL/UPGRADE:</u></b><br><font size=\"-1\">";
373 for( int i=0; i<inst.count(); i++ ) {
374 pkglist += "<b>" + inst.at(i) + "</b>";
375 Package* pkg = iAptInterface->packagesAvailable()->value(inst.at(i),0);
377 qDebug() << "Warning: unknown package" << inst.at(i);
378 pkglist += "<font color=\"red\">***NEW/UNKNOWN***</font>";
381 if( pkg && pkg->isBlacklisted() ) {
382 qDebug() << "Warning: installing blacklisted package" << inst.at(i);
383 pkglist += "<font color=\"red\">***BLACKLISTED***</font>";
384 installing_blacklisted = true;
386 if( instver.count()>i ) {
387 pkglist += " " + instver.at(i);
388 if( pkg && instver.at(i) != pkg->version() ) {
389 qDebug() << "Version mismatch, database version is" << pkg->version() << "but installing" << instver.at(i);
391 pkglist += " <font color=\"red\">***TRYING TO INSTALL " + pkg->version() + "***</font> ";
394 if( pkg && pkg->size()>0 ) {
395 pkglist += QString(" (%L1 kB)").arg(pkg->size()/1024);
400 pkglist += "</font>";
403 ConfirmDialog m(false, this);
404 m.setText("Warning", "There is a version mismatch between your original package selections and some of the packages being installed " \
405 "from the repositories. This could be due to your application catalogs being out of date.");
408 if( installing_blacklisted ) {
409 ConfirmDialog b(false, this);
410 b.setText("Warning","Blacklisted package(s) will be installed");
415 ConfirmDialog d(true, this);
416 d.setText("Confirmation",pkglist);
418 iAptInterface->addQueuedOperation(AAptInterface::ModeAptGetInstall);
420 if( iSettings->qsettings()->value("enable_autoclean",true).toBool() && inst.count()>0 )
421 iAptInterface->addQueuedOperation(AAptInterface::ModeAptGetClean);
424 if( remv.count() > 0 )
425 busytext += QString("Remove %1 package(s)<br>").arg(remv.count());
426 if( inst.count() > 0 )
427 busytext += QString("Install %1 package(s)<br>").arg(inst.count());
428 busytext += "Preparing...";
429 busyDialog(true, "Operation in progress", busytext);
431 // "run" really does nothing here since the previous item should still be running
432 if( iWinPackageView->isVisible() ) {
433 iAptInterface->run(iWinPackageView->mydimmer());
435 iAptInterface->run(iDimmer);
438 iNextOperation = OpNone;
442 iNextOperation = OpNone;
444 if( iSettings->qsettings()->value("sound_notify",false).toBool() )
446 qDebug() << "playing sound";
447 iMediaObject->setCurrentSource( Phonon::MediaSource(iSettings->qsettings()->value("sound_file","/usr/share/sounds/ui-operation_ready.wav").toString()) );
448 iMediaObject->play();
451 QString text = "<br><b><u>Faster Application Manager</u></b><br>"
452 "<b>"+title+"</b><br>" + msgs.join("<br>") + "<br>";
455 QMaemo5InformationBox::information(0, text, QMaemo5InformationBox::NoTimeout);
461 void MainWindow::busyDialog(bool show_, QString title, QString text)
464 iDimmer->setProgress(-1);
465 ui->menuMenu->setEnabled(false);
466 ui->centralWidget->setEnabled(false);
467 iWinPackageView->disableMenu();
468 iDimmer->resizeEvent(0);
469 iDimmer->dim(title, text);
470 iWinPackageView->mydimmer()->resizeEvent(0);
471 iWinPackageView->mydimmer()->dim(title, text);
474 iWinPackageView->mydimmer()->undim();
475 ui->menuMenu->setEnabled(true);
476 ui->centralWidget->setEnabled(true);
477 iWinPackageView->enableMenu();
481 void MainWindow::on_actionAbout_triggered()
483 ConfirmDialog d(false, this);
484 d.setText("About","Faster Application Manager<br>"
485 "<font size=\"-1\">Version " + PROGRAM_VERSION + "</font><br><br>"
486 "(C) Heikki Holstila 2010<br>Donate using "
487 "<a href=\"https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=6ZKRY5QFHL42A&lc=FI&item_name=Faster%20Application%20Manager"
488 "%20for%20Maemo5¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted\">PayPal</a>");
492 void MainWindow::on_actionClean_triggered()
494 //if( iOperation != OpNone ) return;
495 //iOperation = OpClean;
496 iAptInterface->addQueuedOperation(AAptInterface::ModeAptGetClean);
497 iAptInterface->run(iDimmer);
500 void MainWindow::closeEvent(QCloseEvent *event)
502 if( iDimmer->busy() ) {
503 iAptInterface->cancel();
510 void MainWindow::on_actionView_log_triggered()
512 QByteArray log = iAptInterface->readLogFile();
513 LogView l(log, this);
517 void MainWindow::on_actionOptions_triggered()
519 iSettings->openWin();
522 void MainWindow::notifyDialog(QString title, QString msg)
524 ConfirmDialog d(false, this);
525 d.setText(title, msg);
529 bool MainWindow::confirmDialog(QString title, QString msg)
531 ConfirmDialog d(true, this);
532 d.setText(title, msg);
536 void MainWindow::GdkEventIconThemeReload()
538 // DOES NOT EVEN WORK (at least not reliably) - disabled from the project file
540 #ifdef MYDEF_GTK_EXISTS
541 qDebug() << "Sending GDK icon theme reload event";
543 gdk_init((int*)QApplication::argc(),(gchar***)QApplication::argv());
545 // taken from hildon application manager
547 ev.type = GDK_CLIENT_EVENT;
549 ev.send_event = TRUE;
550 ev.message_type = gdk_atom_intern_static_string("_GTK_LOAD_ICONTHEMES");
552 gdk_event_send_clientmessage_toall((GdkEvent*)&ev);
554 while(gdk_events_pending()) {
555 g_main_context_iteration(NULL, true);
561 void MainWindow::on_actionLoad_file_triggered()
563 QStringList files = QFileDialog::getOpenFileNames(this, "Open files", "/", "Files (*.deb *.install)");
564 if( files.count() > 0 ) {
565 QStringList debs = files.filter(QRegExp(".*\\.deb$"));
566 QStringList installs = files.filter(QRegExp(".*\\.install$"));
567 if( debs.count()>0 && installs.count()>0 ) {
568 ConfirmDialog d(false, this);
569 d.setText("Error", "You can't mix different file types in your selection");
574 iDpkgInterface->loadDebFiles(debs);
575 else if( installs.count()>0 )
576 iAptInterface->loadInstallFiles(installs);