#include "infodialog.h"
#include "settings.h"
#include "listwindow.h"
-#include "listview.h"
#include "trace.h"
#include "bookfinder.h"
#include "searchdialog.h"
#include "progressdialog.h"
#include "settings.h"
-LibraryDialog::LibraryDialog(QWidget *parent): ListWindow(parent)
+LibraryDialog::LibraryDialog(QWidget *parent): ListWindow(tr("(No books)"), parent)
{
TRACE;
setWindowTitle(tr("Library"));
// Set selected item
Library *library = Library::instance();
QModelIndex current = library->nowReading();
- // FIXME: setSelected(sortedLibrary->mapFromSource(current));
+ setCurrentItem(sortedLibrary->mapFromSource(current));
+ // Search dialog box
+ searchDialog = new SearchDialog(this);
+ connect(Search::instance(), SIGNAL(endSearch()),
+ this, SLOT(showSearchResults()));
+
+ // Progress bar
progress = new ProgressDialog(tr("Adding books"), this);
- connect(Library::instance(),
- SIGNAL(rowsInserted(const QModelIndex &, int, int)),
- this,
- SLOT(onBookAdded()));
+ connect(library, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
+ this, SLOT(onBookAdded()));
connect(this, 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:
void LibraryDialog::onItemActivated(const QModelIndex &index)
{
TRACE;
+
QModelIndex libraryIndex = sortedLibrary->mapToSource(index);
Book *book = Library::instance()->book(libraryIndex);
int ret = (new InfoDialog(book, this))->exec();
switch (ret) {
case InfoDialog::Read:
- {
- QModelIndex current = sortedLibrary->mapToSource(list->currentIndex());
- Q_ASSERT(current.isValid());
- Library::instance()->setNowReading(current);
- close();
- }
+ Library::instance()->setNowReading(libraryIndex);
+ close();
break;
case InfoDialog::Delete:
- {
- QModelIndex current = sortedLibrary->mapToSource(list->currentIndex());
- Library::instance()->remove(current);
- }
+ Library::instance()->remove(libraryIndex);
break;
default:
;
void LibraryDialog::setSelected(const QModelIndex &libraryIndex)
{
QModelIndex sortedIndex = sortedLibrary->mapFromSource(libraryIndex);
- list->selectionModel()->clearSelection();
if (sortedIndex.isValid()) {
- list->selectionModel()->select(sortedIndex,
- QItemSelectionModel::Select);
- list->setCurrentIndex(sortedIndex);
- }
-}
-
-QModelIndex LibraryDialog::selected() const
-{
- QModelIndexList selectedItems = list->selectionModel()->selectedIndexes();
- if (selectedItems.size()) {
- return sortedLibrary->mapToSource(selectedItems[0]);
+ setCurrentItem(sortedIndex);
}
- return QModelIndex();
}
void LibraryDialog::onAddFolder()
void LibraryDialog::onSearch()
{
+ TRACE;
int ret = searchDialog->exec();
+ qDebug() << "Search dialog returned" << ret;
if (ret != QDialog::Accepted) {
return;
}