Add confirmation after download on Symbian.
[dorian] / mainwindow.cpp
index 9ca9fb5..31c952c 100755 (executable)
@@ -1,14 +1,6 @@
 #include <QtGui>
-#include <QtDebug>
-#include <QDir>
-#include <QApplication>
-#include <QFileInfo>
-#include <QStringList>
-#include <QWebView>
-#include <QWebFrame>
 
 #ifdef Q_WS_MAEMO_5
-#   include <QtMaemo5/QMaemo5InformationBox>
 #   include <QtDBus>
 #   include <QtGui/QX11Info>
 #   include <X11/Xlib.h>
@@ -46,7 +38,7 @@ const int DORIAN_PROGRESS_HEIGHT = 17;
 MainWindow::MainWindow(QWidget *parent):
     AdopterWindow(parent), view(0), preventBlankingTimer(-1)
 {
-    Trace t("MainWindow::MainWindow");
+    TRACE;
 #ifdef Q_WS_MAEMO_5
     setAttribute(Qt::WA_Maemo5StackedWindow, true);
 #endif
@@ -106,6 +98,8 @@ MainWindow::MainWindow(QWidget *parent):
     addToolBarSpace();
     fullScreenAction = addToolBarAction(this, SLOT(showBig()),
                                         "view-fullscreen", tr("Full screen"));
+#else
+    (void)addToolBarAction(this, SLOT(close()), "", tr("Exit"));
 #endif
 
     // Buttons on top of the book view
@@ -189,7 +183,7 @@ void MainWindow::onCurrentBookChanged()
 
 void MainWindow::showRegular()
 {
-    Trace t("MainWindow::showRegular");
+    TRACE;
 
     // Re-parent children
     fullScreenWindow->leaveChildren();
@@ -222,15 +216,20 @@ void MainWindow::showRegular()
 
     fullScreenWindow->hide();
     show();
+#if defined(Q_OS_SYMBIAN)
     activateWindow();
+#elif defined(Q_WS_MAEMO_5)
+    // FIXME: This is ugly.
+    view->restoreLastBookmark();
+#endif
     progress->flash();
-    nextButton->flash(1500);
-    previousButton->flash(1500);
+    nextButton->flash();
+    previousButton->flash();
 }
 
 void MainWindow::showBig()
 {
-    Trace t("MainWindow::showBig");
+    TRACE;
 
     // Re-parent children
     leaveChildren();
@@ -251,12 +250,16 @@ void MainWindow::showBig()
     previousButton->setGeometry(0, screen.height() - TranslucentButton::pixels,
         TranslucentButton::pixels, TranslucentButton::pixels);
 
+#ifdef Q_OS_SYMBIAN
     hide();
+#endif
     fullScreenWindow->showFullScreen();
+#ifdef Q_OS_SYMBIAN
     fullScreenWindow->activateWindow();
+#endif
     progress->flash();
-    nextButton->flash(1500);
-    previousButton->flash(1500);
+    nextButton->flash();
+    previousButton->flash();
 }
 
 void MainWindow::setCurrentBook(const QModelIndex &current)
@@ -306,14 +309,14 @@ void MainWindow::showBookmarks()
 
 void MainWindow::closeEvent(QCloseEvent *event)
 {
-    Trace t("MainWindow::closeEvent");
+    TRACE;
     view->setLastBookmark();
     event->accept();
 }
 
 void MainWindow::onSettingsChanged(const QString &key)
 {
-#ifdef Q_WS_MAEMO_5
+#if defined(Q_WS_MAEMO_5)
     if (key == "orientation") {
         QString value = Settings::instance()->value(key).toString();
         qDebug() << "MainWindow::onSettingsChanged: orientation" << value;
@@ -344,7 +347,7 @@ void MainWindow::onSettingsChanged(const QString &key)
 
 void MainWindow::onPartLoadStart()
 {
-    Trace t("MainWindow::onPartLoadStart");
+    TRACE;
 #ifdef Q_WS_MAEMO_5
     setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
 #endif
@@ -352,7 +355,7 @@ void MainWindow::onPartLoadStart()
 
 void MainWindow::onPartLoadEnd(int index)
 {
-    Trace t("MainWindow::onPartLoadEnd");
+    TRACE;
     bool enablePrevious = false;
     bool enableNext = false;
     Book *book = Library::instance()->book(mCurrent);
@@ -371,13 +374,14 @@ void MainWindow::onPartLoadEnd(int index)
 
 void MainWindow::onAddBookmark(const QString &note)
 {
-    Trace t("MainWindow:onAddBookmark");
+    TRACE;
     view->addBookmark(note);
+    Platform::information(tr("Bookmarked current position"), this);
 }
 
 void MainWindow::onGoToBookmark(int index)
 {
-    Trace t("MainWindow::onGoToBookmark");
+    TRACE;
     Book *book = Library::instance()->book(mCurrent);
     view->goToBookmark(book->bookmarks()[index]);
 }
@@ -396,13 +400,14 @@ void MainWindow::showChapters()
 
 void MainWindow::onGoToChapter(int index)
 {
-    Trace t("MainWindow::onGoToChapter");
+    TRACE;
 
     Book *book = Library::instance()->book(mCurrent);
     if (book) {
-        int partIndex = book->partFromChapter(index);
+        QString fragment;
+        int partIndex = book->partFromChapter(index, fragment);
         if (partIndex != -1) {
-            view->goToBookmark(Book::Bookmark(partIndex, 0));
+            view->goToPart(partIndex, fragment);
         }
     }
 }
@@ -422,7 +427,7 @@ void MainWindow::timerEvent(QTimerEvent *event)
 
 void MainWindow::resizeEvent(QResizeEvent *e)
 {
-    Trace t("MainWindow::resizeEvent");
+    TRACE;
     progress->setGeometry(QRect(0, 0, e->size().width(), DORIAN_PROGRESS_HEIGHT));
 #if defined(Q_WS_MAEMO_5)
     previousButton->setGeometry(0,
@@ -442,8 +447,8 @@ void MainWindow::resizeEvent(QResizeEvent *e)
         toolBar->height(), TranslucentButton::pixels, TranslucentButton::pixels);
 #endif // Q_WS_MAEMO_5
     qDebug() << "previousButton geometry" << previousButton->geometry();
-    previousButton->flash(1500);
-    nextButton->flash(1500);
+    previousButton->flash();
+    nextButton->flash();
     QMainWindow::resizeEvent(e);
 }
 
@@ -458,7 +463,7 @@ void MainWindow::about()
     label->setText(tr("<b>Dorian %1</b><br><br>Copyright &copy; 2010 "
         "Akos Polster &lt;akos@pipacs.com&gt;<br>"
         "Licensed under GNU General Public License, Version 3<br>"
-        "Source code: <a href='https://garage.maemo.org/projects/dorian/'>"
+        "Source code:<br><a href='https://garage.maemo.org/projects/dorian/'>"
         "garage.maemo.org/projects/dorian</a>").arg(Platform::version()));
     aboutDialog->addWidget(label);
     aboutDialog->addStretch();
@@ -468,15 +473,15 @@ void MainWindow::about()
 
 void MainWindow::goToNextPage()
 {
-    nextButton->flash(1500);
-    previousButton->flash(1500);
+    nextButton->flash();
+    previousButton->flash();
     view->goNextPage();
 }
 
 void MainWindow::goToPreviousPage()
 {
-    nextButton->flash(1500);
-    previousButton->flash(1500);
+    nextButton->flash();
+    previousButton->flash();
     view->goPreviousPage();
 }