X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=librarydialog.cpp;h=a3a94f51c4735fcacf0cd208e56d4a397641da43;hb=678671f16bae6bf6276d9a56bf9f4bd17119c239;hp=767667ae3d0f8d8588f13d55f47f22ae20e30f70;hpb=a0350a125756f86873ddd67bda42dd22759fd1e8;p=dorian diff --git a/librarydialog.cpp b/librarydialog.cpp index 767667a..a3a94f5 100644 --- a/librarydialog.cpp +++ b/librarydialog.cpp @@ -1,12 +1,5 @@ -#include -#include -#include #include -#include - -#ifdef Q_WS_MAEMO_5 -#include -#endif +#include #include "librarydialog.h" #include "library.h" @@ -18,22 +11,33 @@ #include "listview.h" #include "trace.h" #include "bookfinder.h" +#include "searchdialog.h" +#include "platform.h" +#include "searchresultsdialog.h" +#include "progressdialog.h" +#include "settings.h" LibraryDialog::LibraryDialog(QWidget *parent): ListWindow(parent) { + TRACE; setWindowTitle(tr("Library")); + setAttribute(Qt::WA_DeleteOnClose, true); // Add actions + sortByTitle = addMenuAction(tr("Sort by title"), this, SLOT(onSortByTitle())); + 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()), ":/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); @@ -43,14 +47,10 @@ LibraryDialog::LibraryDialog(QWidget *parent): ListWindow(parent) list->setSpacing(1); Library *library = Library::instance(); QModelIndex current = library->nowReading(); - setSelected(current); + setSelected(sortedLibrary->mapFromSource(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,20 @@ 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())); + + // Retrieve default sort criteria + switch (Settings::instance()->value("lib/sortby").toInt()) { + case SortedLibrary::SortByAuthor: + onSortByAuthor(); + break; + default: + onSortByTitle(); + } } void LibraryDialog::onAdd() @@ -85,15 +99,9 @@ void LibraryDialog::onAdd() // Add book to library QModelIndex index = library->find(path); if (index.isValid()) { -#ifdef Q_WS_MAEMO_5 - QMaemo5InformationBox::information(this, - tr("This book is already in the library"), - QMaemo5InformationBox::DefaultTimeout); -#else - (void)QMessageBox::information(this, tr("Dorian"), - tr("This book is already in the library"), QMessageBox::Ok); -#endif // Q_WS_MAEMO_5 - setSelected(index); + Platform::instance()->information( + tr("This book is already in the library"), this); + setSelected(sortedLibrary->mapFromSource(index)); } else { library->add(path); @@ -103,7 +111,8 @@ void LibraryDialog::onAdd() void LibraryDialog::onBookAdded() { Library *library = Library::instance(); - setSelected(library->index(library->rowCount() - 1)); + setSelected(sortedLibrary-> + mapFromSource(library->index(library->rowCount() - 1))); } #ifndef Q_WS_MAEMO_5 @@ -126,7 +135,6 @@ void LibraryDialog::onRemove() void LibraryDialog::onRead() { - qDebug() << "LibraryDialog::onRead"; QModelIndex current = sortedLibrary->mapToSource(list->currentIndex()); if (current.isValid()) { Library::instance()->setNowReading(current); @@ -142,15 +150,16 @@ 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(); } -QString LibraryDialog::createItemText(const Book *book) +QString LibraryDialog::createItemText(Book *book) { - QString text = book->title + "\n"; + Q_ASSERT(book); + QString text = book->shortName() + "\n"; if (book->creators.size()) { text += book->creators[0]; for (int i = 1; i < book->creators.size(); i++) { @@ -187,7 +196,7 @@ QModelIndex LibraryDialog::selected() const void LibraryDialog::onAddFolder() { - Trace t("LibraryDialog::onAddFolder"); + TRACE; // Get folder name Settings *settings = Settings::instance(); @@ -221,17 +230,13 @@ 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(); qDebug() << "LibraryDialog::onRefreshDone:" << msg; -#ifdef Q_WS_MAEMO_5 - QMaemo5InformationBox::information(this, msg); -#else - // FIXME -#endif + Platform::instance()->information(msg, this); } void LibraryDialog::onAddFromFolder(const QString &path) @@ -239,3 +244,48 @@ 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 results = Search::instance()->results(); + if (results.isEmpty()) { + 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(); +} + +void LibraryDialog::onSortByAuthor() +{ + TRACE; + sortedLibrary->setSortBy(SortedLibrary::SortByAuthor); + Settings::instance()->setValue("lib/sortby", SortedLibrary::SortByAuthor); + sortByAuthor->setChecked(true); + sortByTitle->setChecked(false); +} + +void LibraryDialog::onSortByTitle() +{ + TRACE; + sortedLibrary->setSortBy(SortedLibrary::SortByTitle); + Settings::instance()->setValue("lib/sortby", SortedLibrary::SortByTitle); + sortByAuthor->setChecked(false); + sortByTitle->setChecked(true); +}