#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);
+}
class InfoWindow;
class SortedLibrary;
class SearchDialog;
+class QAction;
/** Manage library. */
class LibraryDialog: public ListWindow
void onAddFromFolderDone(int added);
void onSearch();
void showSearchResults();
+ void onSortByAuthor();
+ void onSortByTitle();
private:
- QString createItemText(const Book *book);
+ QString createItemText(Book *book);
void setSelected(const QModelIndex &index);
QModelIndex selected() const;
ListView *list;
SortedLibrary *sortedLibrary;
ProgressDialog *progress;
SearchDialog *searchDialog;
+ QAction *sortByAuthor;
+ QAction *sortByTitle;
};
#endif // LIBRARYDIALOG_H
view->show();
layout->addWidget(view);
- // Progress
+ // Dialogs
progress = new Progress(this);
- // Settings dialog
- settings = new QDialog(this);
-
// Tool bar actions
#ifdef Q_OS_SYMBIAN
{
QStringList excludedExtensions;
excludedExtensions << ".html" << ".xhtml" << ".xht" << ".htm" << ".gif"
- << ".png" << ".css";
+ << ".png" << ".css" << "*.ttf" << "mimetype";
return extract(excludedExtensions);
}
#include "sortedlibrary.h"
+#include "library.h"
#include "book.h"
#include "trace.h"
QSortFilterProxyModel(parent), mSortBy(SortByTitle)
{
setSourceModel(Library::instance());
+ setDynamicSortFilter(true);
sort(0);
}
-void SortedLibrary::sortBy(SortBy key)
+void SortedLibrary::setSortBy(SortBy key)
{
- mSortBy = key;
+ TRACE;
+ if (mSortBy != key) {
+ mSortBy = key;
+ invalidate();
+ sort(0);
+ }
+}
+
+SortedLibrary::SortBy SortedLibrary::sortBy()
+{
+ return mSortBy;
}
bool SortedLibrary::lessThan(const QModelIndex &left,
{
Book *leftBook = Library::instance()->book(left);
Book *rightBook = Library::instance()->book(right);
-
- QString leftString;
- QString rightString;
+ int ret = 0;
switch (mSortBy) {
- case SortByTitle:
- leftString = leftBook->shortName();
- rightString = rightBook->shortName();
+ case SortByAuthor:
+ ret = compareBy(SortByAuthor, leftBook, rightBook);
+ if (ret == 0) {
+ ret = compareBy(SortByTitle, leftBook, rightBook);
+ }
break;
default:
- leftString = leftBook->creators[0];
- rightString = rightBook->creators[0];
- break;
+ ret = compareBy(SortByTitle, leftBook, rightBook);
+ if (ret == 0) {
+ ret = compareBy(SortByAuthor, leftBook, rightBook);
+ }
}
- return QString::localeAwareCompare(leftString, rightString) < 0;
+ return ret < 0;
+}
+
+int SortedLibrary::compareBy(SortBy key, Book *left, Book *right) const
+{
+ Q_ASSERT(left);
+ Q_ASSERT(right);
+ switch (key) {
+ case SortByAuthor:
+ return QString::localeAwareCompare(left->creators.join(" "),
+ right->creators.join(" "));
+ default:
+ return QString::localeAwareCompare(left->shortName(), right->shortName());
+ }
}
#define SORTEDLIBRARY_H
#include <QSortFilterProxyModel>
-#include "library.h"
+
+class Book;
/** Sorted library model. */
class SortedLibrary: public QSortFilterProxyModel
enum SortBy {SortByTitle, SortByAuthor};
explicit SortedLibrary(QObject *parent = 0);
bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
- void sortBy(SortBy key);
+ void setSortBy(SortBy key);
+ SortBy sortBy();
signals:
public slots:
protected:
+ int compareBy(SortBy key, Book *left, Book *right) const;
+
+private:
SortBy mSortBy;
};
+dorian (0.3.7-1) unstable; urgency=low
+
+ * Sort library by title or author
+
+ -- Akos Polster <akos@pipacs.com> Sat, 13 Nov 2010 02:00:00 +0100
+
dorian (0.3.6-1) unstable; urgency=low
* Show Qt versions in Developer dialog box
* Delete temporary files
* Don't require Qt 4.7 on Symbian
- -- Akos Polster <akos@pipacs.com> Sun, 7 Nov 2010 02:00:00 +0100
+ -- Akos Polster <akos@pipacs.com> Fri, 12 Nov 2010 02:00:00 +0100
dorian (0.3.5-1) unstable; urgency=low
QWidget *parent):
Dyalog(parent), result(result_)
{
- setWindowTitle(tr("Download Book?"));
+ setWindowTitle(tr("Download book?"));
QLabel *title = new QLabel(result.title, this);
addWidget(title);
SearchResultsDialog::SearchResultsDialog(const QList<Search::Result> results_,
QWidget *parent): ListWindow(parent), results(results_)
{
- setWindowTitle(tr("Search Results"));
+ setWindowTitle(tr("Search results"));
foreach (Search::Result result, results) {
QString author;
this,
SLOT(onEndDownload(int, const Search::Result &, const QString &)));
- progress = new ProgressDialog(tr("Downloading Book"), this);
+ progress = new ProgressDialog(tr("Downloading book"), this);
}
void SearchResultsDialog::onItemActivated(const QModelIndex &index)
#endif // Q_WS_MAEMO_5
}
+QAction *ListWindow::addMenuAction(const QString &title, QObject *receiver,
+ const char *slot)
+{
+ TRACE;
+ QAction *action = 0;
+#if defined(Q_WS_MAEMO_5)
+ action = menuBar()->addAction(title);
+ connect(action, SIGNAL(triggered()), receiver, slot);
+#elif defined(Q_OS_SYMBIAN)
+ action = new QAction(title, this);
+ connect(action, SIGNAL(triggered()), receiver, slot);
+ action->setSoftKeyRole(QAction::PositiveSoftKey);
+ menuBar()->addAction(action);
+#else
+ Q_UNUSED(title);
+ Q_UNUSED(receiver);
+ Q_UNUSED(slot);
+ QAction = new QAction(this);
+#endif
+ action->setCheckable(true);
+ return action;
+}
+
#ifdef Q_WS_MAEMO_5
void ListWindow::closeEvent(QCloseEvent *event)
void addItemAction(const QString &title, QObject *receiver,
const char *slot);
+ /**
+ * Add an action to the menu.
+ */
+ QAction *addMenuAction(const QString &title, QObject *receiver,
+ const char *slot);
+
public slots:
#ifdef Q_OS_SYMBIAN
void show();