.
[dorian] / librarydialog.cpp
index 767667a..bcedcf4 100644 (file)
@@ -18,6 +18,9 @@
 #include "listview.h"
 #include "trace.h"
 #include "bookfinder.h"
+#include "searchdialog.h"
+#include "platform.h"
+#include "searchresultsdialog.h"
 
 LibraryDialog::LibraryDialog(QWidget *parent): ListWindow(parent)
 {
@@ -31,9 +34,9 @@ LibraryDialog::LibraryDialog(QWidget *parent): ListWindow(parent)
     addItemAction(tr("Delete"), this, SLOT(onRemove()));
 #endif // ! Q_WS_MAEMO_5
 
-    addAction(tr("Add book"), this, SLOT(onAdd()), ":/icons/add.png");
-    addAction(tr("Add books from folder"), this, SLOT(onAddFolder()),
-              ":/icons/folder.png");
+    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");
 
     // Create and add list view
     list = new ListView(this);
@@ -51,6 +54,10 @@ LibraryDialog::LibraryDialog(QWidget *parent): ListWindow(parent)
     progress->setMinimumDuration(0);
     progress->setWindowModality(Qt::WindowModal);
     progress->setCancelButton(0);
+#ifdef Q_WS_S60
+    progress->setFixedWidth(
+            QApplication::desktop()->availableGeometry().width());
+#endif
 
     connect(Library::instance(), SIGNAL(nowReadingChanged()),
             this, SLOT(onCurrentBookChanged()));
@@ -60,6 +67,11 @@ LibraryDialog::LibraryDialog(QWidget *parent): ListWindow(parent)
             SLOT(onBookAdded()));
     connect(list, SIGNAL(activated(const QModelIndex &)),
             this, SLOT(onItemActivated(const QModelIndex &)));
+
+    // Create search dialog
+    searchDialog = new SearchDialog(this);
+    connect(Search::instance(), SIGNAL(endSearch()),
+            this, SLOT(showSearchResults()));
 }
 
 void LibraryDialog::onAdd()
@@ -221,8 +233,8 @@ void LibraryDialog::onAddFromFolderDone(int added)
 
     switch (added) {
     case 0: msg = tr("No new books found"); break;
-    case 1: msg = tr("One new book added"); break;
-    default: msg = tr("%1 new books added").arg(added);
+    case 1: msg = tr("One book added"); break;
+    default: msg = tr("%1 books added").arg(added);
     }
 
     progress->reset();
@@ -239,3 +251,26 @@ void LibraryDialog::onAddFromFolder(const QString &path)
     progress->setLabelText(QFileInfo(path).fileName());
     progress->setValue(progress->value() + 1);
 }
+
+void LibraryDialog::onSearch()
+{
+    int ret = searchDialog->exec();
+    if (ret != QDialog::Accepted) {
+        return;
+    }
+    Search::instance()->start(searchDialog->query());
+}
+
+void LibraryDialog::showSearchResults()
+{
+    QList<Search::Result> results = Search::instance()->results();
+    if (results.count() == 0) {
+        QMessageBox::information(this, tr("Search results"), tr("No books found"));
+        return;
+    }
+
+    SearchResultsDialog *dialog = new SearchResultsDialog(results, this);
+    connect(dialog, SIGNAL(add(const Search::Result &)),
+            this, SLOT(onAddSearchResult(const Search::Result &)));
+    dialog->show();
+}