again.
{
QString title = book->name();
if (QMessageBox::Yes ==
- QMessageBox::question(this, "Delete book", "Delete book " + title,
+ QMessageBox::question(this,
+ "Delete book",
+ "Delete book \"" + title + "\"",
QMessageBox::Yes
#ifndef Q_WS_MAEMO_5
, QMessageBox::No
QVariant Library::data(const QModelIndex &index, int role) const
{
- qDebug() << "Library::data, row" << index.row() << "role" << role;
-
if (!index.isValid()) {
return QVariant();
}
Book *Library::book(const QModelIndex &index)
{
- if (index.isValid()) {
+ if (index.isValid() &&
+ (index.row() >= 0) &&
+ (index.row() < mBooks.size())) {
return mBooks[index.row()];
} else {
return 0;
void Library::remove(const QModelIndex &index)
{
- if (!index.isValid()) {
+ Book *toRemove = book(index);
+ if (!toRemove) {
return;
}
int row = index.row();
- if ((row < 0) || (row >= mBooks.size())) {
- return;
- }
beginRemoveRows(QModelIndex(), row, row);
- Book *book = mBooks[row];
mBooks.removeAt(row);
save();
endRemoveRows();
- if (book == mNowReading) {
+ if (toRemove == mNowReading) {
mNowReading = 0;
emit nowReadingChanged();
}
- delete book;
+ delete toRemove;
}
QModelIndex Library::nowReading() const
void Library::setNowReading(const QModelIndex index)
{
- if (index.isValid()) {
- int row = index.row();
- if ((row >= 0) && (row < mBooks.size())) {
- mNowReading = mBooks[row];
- }
- } else {
- mNowReading = 0;
- }
+ mNowReading = book(index);
save();
emit nowReadingChanged();
}
#include "sortedlibrary.h"
#include "book.h"
#include "infodialog.h"
+#include "settings.h"
LibraryDialog::LibraryDialog(QWidget *parent):
QDialog(parent, Qt::Dialog | Qt::WindowTitleHint |
horizontalLayout->addWidget(buttonBox);
- connect(Library::instance(), SIGNAL(currentBookChanged()),
+ connect(Library::instance(), SIGNAL(nowReadingChanged()),
this, SLOT(onCurrentBookChanged()));
#ifndef Q_WS_MAEMO_5
connect(list, SIGNAL(itemSelectionChanged()),
Library *library = Library::instance();
// Figure out directory to show
- if (lastDir == "") {
- if (library->rowCount()) {
- QModelIndex lastIndex = library->index(library->rowCount() - 1);
- Book *lastBook = library->book(lastIndex);
- QFileInfo info(lastBook->path());
- lastDir = info.absolutePath();
- }
- }
+ QString lastDir = Settings::instance()->value("lastdir").toString();
if (lastDir == "") {
lastDir = QDir::homePath();
}
// Get book file name
QString path = QFileDialog::getOpenFileName(this, tr("Add Book"),
lastDir, "Books (*.epub)");
- qDebug() << "LibraryDialog::onAdd" << path;
if (path == "") {
return;
}
+ // Save directory selected
+ Settings::instance()->setValue("lastdir", QFileInfo(path).absolutePath());
+
// Add book to library
- lastDir = QFileInfo(path).absolutePath();
if (library->find(path).isValid()) {
#ifdef Q_WS_MAEMO_5
QMaemo5InformationBox::information(this,
tr("This book is already in the library"),
QMaemo5InformationBox::DefaultTimeout);
-#endif
+#else
+ (void)QMessageBox::information(this, tr("Dorian"),
+ tr("This book is already in the library"), QMessageBox::Ok);
+#endif // Q_WS_MAEMO_5
// FIXME: Select existing book
}
else {
QPushButton *readButton;
#endif // Q_WS_MAEMO_5
QPushButton *addButton;
- QString lastDir;
public slots:
void onAdd();
const int WIN_BIG_TIMER = 3000;
MainWindow::MainWindow(QWidget *parent):
- QMainWindow(parent), view(0), book(0), isFullscreen(false)
+ QMainWindow(parent), view(0), isFullscreen(false)
{
#ifdef Q_WS_MAEMO_5
setAttribute(Qt::WA_Maemo5StackedWindow, true);
void MainWindow::setCurrentBook(const QModelIndex ¤t)
{
+ mCurrent = current;
if (current.isValid()) {
Book *book = Library::instance()->book(current);
view->setBook(book);
void MainWindow::showInfo()
{
- if (book) {
- InfoDialog *info = new InfoDialog(book, this);
+ if (mCurrent.isValid()) {
+ InfoDialog *info =
+ new InfoDialog(Library::instance()->book(mCurrent), this);
info->exec();
}
}
void MainWindow::showBookmarks()
{
+ Book *book = Library::instance()->book(mCurrent);
if (book) {
BookmarksDialog *bookmarks = new BookmarksDialog(book, this);
int ret = bookmarks->exec();
{
bool enablePrevious = false;
bool enableNext = false;
+ Book *book = Library::instance()->book(mCurrent);
if (book) {
if (index > 0) {
enablePrevious = true;
QToolBar *toolBar;
QDialog *settings;
DevTools *devTools;
- Book *book;
+ QModelIndex mCurrent;
Qt::WindowFlags normalFlags;
TranslucentButton *restoreButton;
bool isFullscreen;
dorian (0.0.10-1) unstable; urgency=low
* Turn library into proper model
+ * Show message if selected book is already in the library
-- Akos Polster <akos@pipacs.com> Fri, 16 Jul 2010 20:00:00 +0200