#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()));
list->setSpacing(1);
Library *library = Library::instance();
QModelIndex current = library->nowReading();
- setSelected(current);
+ setSelected(sortedLibrary->mapFromSource(current));
addList(list);
progress = new ProgressDialog(tr("Adding books"), this);
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()
if (index.isValid()) {
Platform::instance()->information(
tr("This book is already in the library"), this);
- setSelected(index);
+ setSelected(sortedLibrary->mapFromSource(index));
}
else {
library->add(path);
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
(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++) {
{
progress->reset();
QList<Search::Result> results = Search::instance()->results();
- if (results.count() == 0) {
+ if (results.isEmpty()) {
QMessageBox::information(this, tr("Search results"),
tr("No books found"));
return;
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);
+}