Make library full screen on Maemo. Show busy indicator while loading
authorAkos Polster <polster@nolove.pipacs.com>
Tue, 20 Jul 2010 14:56:58 +0000 (16:56 +0200)
committerAkos Polster <polster@nolove.pipacs.com>
Tue, 20 Jul 2010 14:56:58 +0000 (16:56 +0200)
book.

bookview.cpp
bookview.h
infodialog.cpp
librarydialog.cpp
librarydialog.h
mainwindow.cpp
mainwindow.h

index 933bb4f..d960e26 100644 (file)
@@ -79,6 +79,7 @@ void BookView::loadContent(int index)
     }
     else {
         loadFinished = false;
+        emit chapterLoadStart(index);
         load(QUrl(contentFile));
     }
     contentIndex = index;
@@ -147,7 +148,7 @@ void BookView::onLoadFinished(bool ok)
     loadFinished = true;
     addNavigationBar();
     onSettingsChanged("scheme");
-    emit chapterLoaded(contentIndex);
+    emit chapterLoadEnd(contentIndex);
     if (restore) {
         restore = false;
         if (ok && mBook) {
index fc42344..b333228 100644 (file)
@@ -26,7 +26,8 @@ public:
     void setLastBookmark();
 
 signals:
-    void chapterLoaded(int index);
+    void chapterLoadStart(int index);
+    void chapterLoadEnd(int index);
 
 public slots:
     void goPrevious();
index 6bd9e01..7deb3c5 100644 (file)
@@ -34,16 +34,11 @@ void InfoDialog::onReadBook()
 
 void InfoDialog::onRemoveBook()
 {
-    QString title = book->name();
     if (QMessageBox::Yes ==
         QMessageBox::question(this,
-                              "Delete book",
-                              "Delete book \"" + title + "\"",
-                              QMessageBox::Yes
-#ifndef Q_WS_MAEMO_5
-                              , QMessageBox::No
-#endif
-                              )) {
+                              tr("Delete book"),
+                              "Delete book \"" + book->name() + "\"?",
+                              QMessageBox::Yes | QMessageBox::No)) {
         Library::instance()->remove(Library::instance()->find(book));
         close();
     }
index fd7777b..32b4a04 100644 (file)
 #include "infodialog.h"
 #include "settings.h"
 
-LibraryDialog::LibraryDialog(QWidget *parent):
-        QDialog(parent, Qt::Dialog | Qt::WindowTitleHint |
-                Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint)
+LibraryDialog::LibraryDialog(QWidget *parent): QMainWindow(parent)
 {
+#ifdef Q_WS_MAEMO_5
+    setAttribute(Qt::WA_Maemo5StackedWindow, true);
+#endif
     setWindowTitle(tr("Library"));
+
+    QFrame *frame = new QFrame(this);
+    setCentralWidget(frame);
+    QHBoxLayout *horizontalLayout = new QHBoxLayout(this);
+    frame->setLayout(horizontalLayout);
+
     list = new QListView(this);
     sortedLibrary = new SortedLibrary(this);
     list->setModel(sortedLibrary);
     list->setSelectionMode(QAbstractItemView::SingleSelection);
     list->setUniformItemSizes(true);
-#ifndef Q_WS_MAEMO_5
-    setSizeGripEnabled(true);
-#endif
 
     Library *library = Library::instance();
     QModelIndex current = library->nowReading();
     setSelected(current);
-
-    QHBoxLayout *horizontalLayout = new QHBoxLayout(this);
     horizontalLayout->addWidget(list);
 
-    QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
 #ifndef Q_WS_MAEMO_5
+    QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
     detailsButton = new QPushButton(tr("Details"), this);
     readButton = new QPushButton(tr("Read"), this);
     removeButton = new QPushButton(tr("Delete"), this);
-#endif // Q_WS_MAEMO_5
     addButton = new QPushButton(tr("Add"), this);
 
-#ifndef Q_WS_MAEMO_5
     buttonBox->addButton(detailsButton, QDialogButtonBox::ActionRole);
     buttonBox->addButton(readButton, QDialogButtonBox::AcceptRole);
     buttonBox->addButton(removeButton, QDialogButtonBox::ActionRole);
-#endif // Q_WS_MAEMO_5
     buttonBox->addButton(addButton, QDialogButtonBox::ActionRole);
-
     horizontalLayout->addWidget(buttonBox);
+#else
+    QAction *addBookAction = menuBar()->addAction(tr("Add book"));
+#endif // Q_WS_MAEMO_5
 
     connect(Library::instance(), SIGNAL(nowReadingChanged()),
             this, SLOT(onCurrentBookChanged()));
@@ -59,12 +60,12 @@ LibraryDialog::LibraryDialog(QWidget *parent):
             SIGNAL(rowsInserted(const QModelIndex &, int, int)),
             this,
             SLOT(onBookAdded()));
-    connect(addButton, SIGNAL(clicked()), this, SLOT(onAdd()));
     connect(list, SIGNAL(activated(const QModelIndex &)),
             this, SLOT(onItemActivated(const QModelIndex &)));
 #ifndef Q_WS_MAEMO_5
     connect(list, SIGNAL(itemSelectionChanged()),
             this, SLOT(onItemSelectionChanged()));
+    connect(addButton, SIGNAL(clicked()), this, SLOT(onAdd()));
     connect(detailsButton, SIGNAL(clicked()), this, SLOT(onDetails()));
     connect(readButton, SIGNAL(clicked()), this, SLOT(onRead()));
     connect(removeButton, SIGNAL(clicked()), this, SLOT(onRemove()));
@@ -73,6 +74,8 @@ LibraryDialog::LibraryDialog(QWidget *parent):
                                     const QItemSelection &)),
             this, SLOT(onItemSelectionChanged()));
     onItemSelectionChanged();
+#else
+    connect(addBookAction, SIGNAL(triggered()), this, SLOT(onAdd()));
 #endif // !Q_WS_MAEMO_5
 }
 
@@ -124,7 +127,6 @@ void LibraryDialog::onBookAdded()
 
 void LibraryDialog::onRemove()
 {
-    qDebug() << "LibraryDialog::onRemove";
     QModelIndex current = sortedLibrary->mapToSource(list->currentIndex());
     if (current.isValid()) {
         Book *currentBook = Library::instance()->book(current);
@@ -132,7 +134,7 @@ void LibraryDialog::onRemove()
         if (QMessageBox::Yes ==
             QMessageBox::question(this, "Delete book",
                                   "Delete book \"" + title + "\"?",
-                                  QMessageBox::Yes, QMessageBox::No)) {
+                                  QMessageBox::Yes | QMessageBox::No)) {
             Library::instance()->remove(current);
         }
     }
@@ -179,13 +181,9 @@ QString LibraryDialog::createItemText(const Book *book)
 void LibraryDialog::onItemSelectionChanged()
 {
     bool enable = selected().isValid();
-    qDebug() << "LibraryDialog::onItemSelectionChanged" << enable;
     readButton->setEnabled(enable);
-    qDebug() << " readButton";
     detailsButton->setEnabled(enable);
-    qDebug() << " detailsButton";
     removeButton->setEnabled(enable);
-    qDebug() << " removeButton";
 }
 
 #endif // Q_WS_MAEMO_5
@@ -214,3 +212,11 @@ QModelIndex LibraryDialog::selected() const
     }
     return QModelIndex();
 }
+
+void LibraryDialog::closeEvent(QCloseEvent *event)
+{
+#ifdef Q_WS_MAEMO_5
+    menuBar()->clear();
+#endif
+    event->accept();
+}
index 1424ead..bef71fc 100644 (file)
@@ -4,16 +4,17 @@
 #include <QDialog>
 #include <QString>
 #include <QModelIndexList>
+#include <QMainWindow>
 
-class QMainWindow;
 class QListView;
 class QPushButton;
 class QModelIndex;
+class QCloseEvent;
 class Book;
 class InfoWindow;
 class SortedLibrary;
 
-class LibraryDialog: public QDialog
+class LibraryDialog: public QMainWindow
 {
     Q_OBJECT
 
@@ -32,6 +33,9 @@ public slots:
     void onItemActivated(const QModelIndex &index);
     void onCurrentBookChanged();
 
+protected:
+    void closeEvent(QCloseEvent *event);
+
 private:
     QString createItemText(const Book *book);
     void setSelected(const QModelIndex &index);
index 34d56b5..ca97ee2 100755 (executable)
@@ -116,7 +116,10 @@ MainWindow::MainWindow(QWidget *parent):
                                    Settings::instance()->value("orientation"));
 
     // Handle loading chapters
-    connect(view, SIGNAL(chapterLoaded(int)), this, SLOT(onChapterLoaded(int)));
+    connect(view, SIGNAL(chapterLoadStart(int)),
+            this, SLOT(onChapterLoadStart()));
+    connect(view, SIGNAL(chapterLoadEnd(int)),
+            this, SLOT(onChapterLoadEnd(int)));
 
 #ifdef DORIAN_TEST_MODEL
     (void)new ModelTest(Library::instance(), this);
@@ -169,8 +172,8 @@ QAction *MainWindow::addToolBarAction(const QObject *receiver,
 
 void MainWindow::showLibrary()
 {
-    LibraryDialog *dialog = new LibraryDialog();
-    dialog->exec();
+    LibraryDialog *dialog = new LibraryDialog(this);
+    dialog->show();
 }
 
 void MainWindow::showSettings()
@@ -258,7 +261,14 @@ void MainWindow::onSettingsChanged(const QString &key)
 #endif // Q_WS_MAEMO_5
 }
 
-void MainWindow::onChapterLoaded(int index)
+void MainWindow::onChapterLoadStart()
+{
+#ifdef Q_WS_MAEMO_5
+    setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
+#endif
+}
+
+void MainWindow::onChapterLoadEnd(int index)
 {
     bool enablePrevious = false;
     bool enableNext = false;
@@ -272,6 +282,7 @@ void MainWindow::onChapterLoaded(int index)
         }
     }
 #ifdef Q_WS_MAEMO_5
+    setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false);
     previousAction->setIcon(QIcon(enablePrevious?
         ":/icons/previous.png" : ":/icons/previous-disabled.png"));
     nextAction->setIcon(QIcon(enableNext?
index 1959965..628fd18 100755 (executable)
@@ -28,7 +28,8 @@ public slots:
     void showNormal();
     void showFullScreen();
     void onSettingsChanged(const QString &key);
-    void onChapterLoaded(int index);
+    void onChapterLoadStart();
+    void onChapterLoadEnd(int index);
 
 protected:
 #ifdef Q_WS_MAEMO5