#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)
{
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);
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()));
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()
void LibraryDialog::onRead()
{
- qDebug() << "LibraryDialog::onRead";
QModelIndex current = sortedLibrary->mapToSource(list->currentIndex());
if (current.isValid()) {
Library::instance()->setNowReading(current);
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();
void LibraryDialog::onAddFolder()
{
- Trace t("LibraryDialog::onAddFolder");
+ TRACE;
// Get folder name
Settings *settings = Settings::instance();
#ifdef Q_WS_MAEMO_5
QMaemo5InformationBox::information(this, msg);
#else
- // FIXME
+ QMessageBox::information(this, tr("Done adding books"), msg);
#endif
}
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();
+}