Make selection handling work.
[dorian] / mainwindow.cpp
index 59550c5..34d56b5 100755 (executable)
@@ -34,7 +34,7 @@ const Qt::WindowFlags WIN_BIG_FLAGS =
 const int WIN_BIG_TIMER = 3000;
 
 MainWindow::MainWindow(QWidget *parent):
-        QMainWindow(parent), view(0), book(0), isFullscreen(false)
+        QMainWindow(parent), view(0), isFullscreen(false)
 {
 #ifdef Q_WS_MAEMO_5
     setAttribute(Qt::WA_Maemo5StackedWindow, true);
@@ -153,14 +153,10 @@ void MainWindow::showFullScreen()
 
 void MainWindow::setCurrentBook(const QModelIndex &current)
 {
-    if (current.isValid()) {
-        Book *book = Library::instance()->book(current);
-        view->setBook(book);
-        setWindowTitle(book->name());
-    } else {
-        view->setBook(0);
-        setWindowTitle("Dorian");
-    }
+    mCurrent = current;
+    Book *book = Library::instance()->book(current);
+    view->setBook(book);
+    setWindowTitle(book? book->name(): tr("Dorian"));
 }
 
 QAction *MainWindow::addToolBarAction(const QObject *receiver,
@@ -185,8 +181,9 @@ void MainWindow::showSettings()
 
 void MainWindow::showInfo()
 {
-    if (book) {
-        InfoDialog *info = new InfoDialog(book, this);
+    if (mCurrent.isValid()) {
+        InfoDialog *info =
+            new InfoDialog(Library::instance()->book(mCurrent), this);
         info->exec();
     }
 }
@@ -199,6 +196,7 @@ void MainWindow::showDevTools()
 
 void MainWindow::showBookmarks()
 {
+    Book *book = Library::instance()->book(mCurrent);
     if (book) {
         BookmarksDialog *bookmarks = new BookmarksDialog(book, this);
         int ret = bookmarks->exec();
@@ -264,6 +262,7 @@ void MainWindow::onChapterLoaded(int index)
 {
     bool enablePrevious = false;
     bool enableNext = false;
+    Book *book = Library::instance()->book(mCurrent);
     if (book) {
         if (index > 0) {
             enablePrevious = true;