Simplify in/out traces.
[dorian] / librarydialog.cpp
index c08c4ae..6ca466a 100644 (file)
 #include "listview.h"
 #include "trace.h"
 #include "bookfinder.h"
+#include "searchdialog.h"
+#include "platform.h"
+#include "searchresultsdialog.h"
+#include "progressdialog.h"
 
 LibraryDialog::LibraryDialog(QWidget *parent): ListWindow(parent)
 {
@@ -31,9 +35,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);
@@ -46,11 +50,7 @@ LibraryDialog::LibraryDialog(QWidget *parent): ListWindow(parent)
     setSelected(current);
     addList(list);
 
-    progress = new QProgressDialog(tr("Adding books"), "", 0, 0, this);
-    progress->reset();
-    progress->setMinimumDuration(0);
-    progress->setWindowModality(Qt::WindowModal);
-    progress->setCancelButton(0);
+    progress = new ProgressDialog(tr("Adding books"), this);
 
     connect(Library::instance(), SIGNAL(nowReadingChanged()),
             this, SLOT(onCurrentBookChanged()));
@@ -60,6 +60,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()
@@ -126,7 +131,6 @@ void LibraryDialog::onRemove()
 
 void LibraryDialog::onRead()
 {
-    qDebug() << "LibraryDialog::onRead";
     QModelIndex current = sortedLibrary->mapToSource(list->currentIndex());
     if (current.isValid()) {
         Library::instance()->setNowReading(current);
@@ -142,7 +146,7 @@ void LibraryDialog::onDetails()
 
 void LibraryDialog::onItemActivated(const QModelIndex &index)
 {
-    qDebug() << "LibraryDialog::onItemActivated";
+    TRACE;
     QModelIndex libraryIndex = sortedLibrary->mapToSource(index);
     Book *book = Library::instance()->book(libraryIndex);
     (new InfoDialog(book, this))->exec();
@@ -187,7 +191,7 @@ QModelIndex LibraryDialog::selected() const
 
 void LibraryDialog::onAddFolder()
 {
-    Trace t("LibraryDialog::onAddFolder");
+    TRACE;
 
     // Get folder name
     Settings *settings = Settings::instance();
@@ -230,7 +234,7 @@ void LibraryDialog::onAddFromFolderDone(int added)
 #ifdef Q_WS_MAEMO_5
     QMaemo5InformationBox::information(this, msg);
 #else
-    // FIXME
+    QMessageBox::information(this, tr("Done adding books"), msg);
 #endif
 }
 
@@ -239,3 +243,30 @@ 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;
+    }
+    progress->setLabelText(tr("Searching Project Gutenberg"));
+    progress->showWait();
+    Search::instance()->start(searchDialog->query());
+}
+
+void LibraryDialog::showSearchResults()
+{
+    progress->reset();
+    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();
+}