Navigate with volume keys.
[dorian] / librarydialog.cpp
index 32b4a04..f861d26 100644 (file)
 #include "book.h"
 #include "infodialog.h"
 #include "settings.h"
+#include "listwindow.h"
+#include "foldersdialog.h"
 
-LibraryDialog::LibraryDialog(QWidget *parent): QMainWindow(parent)
+LibraryDialog::LibraryDialog(QWidget *parent): ListWindow(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);
+    // Create and add list view
 
     list = new QListView(this);
     sortedLibrary = new SortedLibrary(this);
     list->setModel(sortedLibrary);
     list->setSelectionMode(QAbstractItemView::SingleSelection);
-    list->setUniformItemSizes(true);
-
+    list->setSpacing(1);
     Library *library = Library::instance();
     QModelIndex current = library->nowReading();
     setSelected(current);
-    horizontalLayout->addWidget(list);
+    addList(list);
+
+    // Add actions
 
 #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);
-    addButton = new QPushButton(tr("Add"), this);
-
-    buttonBox->addButton(detailsButton, QDialogButtonBox::ActionRole);
-    buttonBox->addButton(readButton, QDialogButtonBox::AcceptRole);
-    buttonBox->addButton(removeButton, QDialogButtonBox::ActionRole);
-    buttonBox->addButton(addButton, QDialogButtonBox::ActionRole);
-    horizontalLayout->addWidget(buttonBox);
-#else
-    QAction *addBookAction = menuBar()->addAction(tr("Add book"));
-#endif // Q_WS_MAEMO_5
+    addItemAction(tr("Details"), this, SLOT(onDetails()));
+    addItemAction(tr("Read"), this, SLOT(onRead()));
+    addItemAction(tr("Delete"), this, SLOT(onRemove()));
+#endif // ! Q_WS_MAEMO_5
+
+    addAction(tr("Add book"), this, SLOT(onAdd()));
+    addAction(tr("Manage folders"), this, SLOT(onShowFolders()));
 
     connect(Library::instance(), SIGNAL(nowReadingChanged()),
             this, SLOT(onCurrentBookChanged()));
@@ -62,21 +52,6 @@ LibraryDialog::LibraryDialog(QWidget *parent): QMainWindow(parent)
             SLOT(onBookAdded()));
     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()));
-    connect(list->selectionModel(),
-            SIGNAL(selectionChanged(const QItemSelection &,
-                                    const QItemSelection &)),
-            this, SLOT(onItemSelectionChanged()));
-    onItemSelectionChanged();
-#else
-    connect(addBookAction, SIGNAL(triggered()), this, SLOT(onAdd()));
-#endif // !Q_WS_MAEMO_5
 }
 
 void LibraryDialog::onAdd()
@@ -132,9 +107,10 @@ void LibraryDialog::onRemove()
         Book *currentBook = Library::instance()->book(current);
         QString title = currentBook->name();
         if (QMessageBox::Yes ==
-            QMessageBox::question(this, "Delete book",
-                                  "Delete book \"" + title + "\"?",
-                                  QMessageBox::Yes | QMessageBox::No)) {
+            QMessageBox::question(this, tr("Delete book"),
+                tr("Delete book \"%1\" from library?").
+                    arg(currentBook->shortName()),
+                QMessageBox::Yes | QMessageBox::No)) {
             Library::instance()->remove(current);
         }
     }
@@ -176,18 +152,6 @@ QString LibraryDialog::createItemText(const Book *book)
     return text;
 }
 
-#ifndef Q_WS_MAEMO_5
-
-void LibraryDialog::onItemSelectionChanged()
-{
-    bool enable = selected().isValid();
-    readButton->setEnabled(enable);
-    detailsButton->setEnabled(enable);
-    removeButton->setEnabled(enable);
-}
-
-#endif // Q_WS_MAEMO_5
-
 void LibraryDialog::onCurrentBookChanged()
 {
     close();
@@ -213,10 +177,8 @@ QModelIndex LibraryDialog::selected() const
     return QModelIndex();
 }
 
-void LibraryDialog::closeEvent(QCloseEvent *event)
+void LibraryDialog::onShowFolders()
 {
-#ifdef Q_WS_MAEMO_5
-    menuBar()->clear();
-#endif
-    event->accept();
+    FoldersDialog *folders = new FoldersDialog(this);
+    folders->show();
 }