Really delete current book. Don't close library when deleting current
authorAkos Polster <akos@pipacs.com>
Wed, 17 Nov 2010 22:58:40 +0000 (23:58 +0100)
committerAkos Polster <akos@pipacs.com>
Wed, 17 Nov 2010 22:58:40 +0000 (23:58 +0100)
book.

infodialog.cpp
infodialog.h
librarydialog.cpp
librarydialog.h
mainwindow.cpp
model/book.cpp
model/library.cpp
pkg/changelog
pkg/version.txt
widgets/dyalog.cpp

index d6dee93..4f88539 100644 (file)
@@ -54,8 +54,7 @@ InfoDialog::InfoDialog(Book *b, QWidget *parent, bool showButtons):
 
 void InfoDialog::onReadBook()
 {
-    Library::instance()->setNowReading(Library::instance()->find(book));
-    close();
+    done(InfoDialog::Read);
 }
 
 void InfoDialog::onRemoveBook()
@@ -64,7 +63,6 @@ void InfoDialog::onRemoveBook()
         QMessageBox::question(this, tr("Delete book"),
             tr("Delete book \"%1\" from library?").arg(book->shortName()),
             QMessageBox::Yes | QMessageBox::No)) {
-        Library::instance()->remove(Library::instance()->find(book));
-        close();
+        done(InfoDialog::Delete);
     }
 }
index c326bf9..260eca4 100644 (file)
@@ -12,6 +12,7 @@ class InfoDialog: public Dyalog
     Q_OBJECT
 
 public:
+    enum {Close, Read, Delete}; //< Dialog result codes.
     explicit InfoDialog(Book *book, QWidget *parent, bool showButtons = true);
 
 public slots:
index a3a94f5..4312cd4 100644 (file)
@@ -29,12 +29,6 @@ LibraryDialog::LibraryDialog(QWidget *parent): ListWindow(parent)
     sortByAuthor =
             addMenuAction(tr("Sort by author"), this, SLOT(onSortByAuthor()));
 
-#ifndef 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()), "add");
     addAction(tr("Add books from folder"), this, SLOT(onAddFolder()), "folder");
     addAction(tr("Search the Web"), this, SLOT(onSearch()), "search");
@@ -52,8 +46,6 @@ LibraryDialog::LibraryDialog(QWidget *parent): ListWindow(parent)
 
     progress = new ProgressDialog(tr("Adding books"), this);
 
-    connect(Library::instance(), SIGNAL(nowReadingChanged()),
-            this, SLOT(onCurrentBookChanged()));
     connect(Library::instance(),
             SIGNAL(rowsInserted(const QModelIndex &, int, int)),
             this,
@@ -115,45 +107,31 @@ void LibraryDialog::onBookAdded()
                 mapFromSource(library->index(library->rowCount() - 1)));
 }
 
-#ifndef Q_WS_MAEMO_5
-
-void LibraryDialog::onRemove()
-{
-    QModelIndex current = sortedLibrary->mapToSource(list->currentIndex());
-    if (current.isValid()) {
-        Book *currentBook = Library::instance()->book(current);
-        QString title = currentBook->name();
-        if (QMessageBox::Yes ==
-            QMessageBox::question(this, tr("Delete book"),
-                tr("Delete book \"%1\" from library?").
-                    arg(currentBook->shortName()),
-                QMessageBox::Yes | QMessageBox::No)) {
-            Library::instance()->remove(current);
-        }
-    }
-}
-
-void LibraryDialog::onRead()
-{
-    QModelIndex current = sortedLibrary->mapToSource(list->currentIndex());
-    if (current.isValid()) {
-        Library::instance()->setNowReading(current);
-    }
-}
-
-void LibraryDialog::onDetails()
-{
-    onItemActivated(list->currentIndex());
-}
-
-#endif // Q_WS_MAEMO_5
-
 void LibraryDialog::onItemActivated(const QModelIndex &index)
 {
     TRACE;
     QModelIndex libraryIndex = sortedLibrary->mapToSource(index);
     Book *book = Library::instance()->book(libraryIndex);
-    (new InfoDialog(book, this))->exec();
+    int ret = (new InfoDialog(book, this))->exec();
+
+    switch (ret) {
+    case InfoDialog::Read:
+        {
+            QModelIndex current = sortedLibrary->mapToSource(list->currentIndex());
+            Q_ASSERT(current.isValid());
+            Library::instance()->setNowReading(current);
+            close();
+        }
+        break;
+    case InfoDialog::Delete:
+        {
+            QModelIndex current = sortedLibrary->mapToSource(list->currentIndex());
+            Library::instance()->remove(current);
+        }
+        break;
+    default:
+        ;
+    }
 }
 
 QString LibraryDialog::createItemText(Book *book)
@@ -169,11 +147,6 @@ QString LibraryDialog::createItemText(Book *book)
     return text;
 }
 
-void LibraryDialog::onCurrentBookChanged()
-{
-    close();
-}
-
 void LibraryDialog::setSelected(const QModelIndex &libraryIndex)
 {
     QModelIndex sortedIndex = sortedLibrary->mapFromSource(libraryIndex);
index 7b368a4..480a66d 100644 (file)
@@ -29,14 +29,8 @@ public:
 public slots:
     void onAdd();
     void onAddFolder();
-#ifndef Q_WS_MAEMO_5
-    void onRemove();
-    void onDetails();
-    void onRead();
-#endif // Q_WS_MAEMO_5
     void onBookAdded();
     void onItemActivated(const QModelIndex &index);
-    void onCurrentBookChanged();
     void onAddFromFolder(const QString &path);
     void onAddFromFolderDone(int added);
     void onSearch();
index 9712cef..4c635cd 100755 (executable)
@@ -29,6 +29,7 @@
 #include "translucentbutton.h"
 #include "platform.h"
 #include "progressdialog.h"
+#include "sortedlibrary.h"
 
 #ifdef DORIAN_TEST_MODEL
 #   include "modeltest.h"
@@ -166,7 +167,8 @@ void MainWindow::initialize()
             if (!library->rowCount()) {
                 library->add(":/books/2BR02B.epub");
             }
-            library->setNowReading(library->index(0));
+            SortedLibrary sorted;
+            library->setNowReading(sorted.mapToSource(sorted.index(0, 0)));
         }
     }
 }
index 3cced2a..b24130b 100644 (file)
@@ -552,6 +552,6 @@ void Book::upgrade()
 void Book::remove()
 {
     TRACE;
-    load();
+    close();
     BookDb::instance()->remove(path());
 }
index a14a6f9..c3e16e9 100644 (file)
@@ -129,16 +129,16 @@ void Library::remove(const QModelIndex &index)
     if (!toRemove) {
         return;
     }
+    if (index == mNowReading) {
+        mNowReading = QModelIndex();
+        emit nowReadingChanged();
+    }
     toRemove->remove();
     int row = index.row();
     beginRemoveRows(QModelIndex(), row, row);
     mBooks.removeAt(row);
     save();
     endRemoveRows();
-    if (index == mNowReading) {
-        mNowReading = QModelIndex();
-        emit nowReadingChanged();
-    }
     delete toRemove;
 }
 
index 588092e..c4e41ed 100644 (file)
@@ -1,3 +1,10 @@
+dorian (0.3.9-1) unstable; urgency=low
+
+  * Don't close library dialog when deleting current book
+  * Really delete current book [#6614]
+
+ -- Akos Polster <akos@pipacs.com>  Mon, 15 Nov 2010 02:00:00 +0100
+
 dorian (0.3.8-1) unstable; urgency=low
 
   * Move progress bar to the bottom
index 3a5ff99..143fcc7 100644 (file)
@@ -1 +1 @@
-"0.3.8"
+"0.3.9"
index db75c88..2b8fc1b 100644 (file)
@@ -12,6 +12,8 @@ Dyalog::Dyalog(QWidget *parent, bool showButtons_):
                     Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint),
     showButtons(showButtons_)
 {
+    setAttribute(Qt::WA_DeleteOnClose);
+
     scroller = new QScrollArea(this);
 
 #if defined(Q_WS_MAEMO_5)