{
return mRootPath;
}
+
+QString Book::name() const
+{
+ if (title != "") {
+ return title;
+ } else {
+ return path();
+ }
+}
/** List bookmarks. */
QList<Bookmark> bookmarks() const;
+ /**
+ * Get friendly name.
+ * @return @see title or path name if title is not available yet.
+ */
+ QString name() const;
+
QString title; //< Book title from EPUB.
QStringList toc; //< Table of contents from EPUB.
QHash<QString, ContentItem> content; //< Content items from EPUB.
styles/day.js
DEFINES += \
- USE_FILE32API
+ USE_FILE32API \
+ DORIAN_TEST_MODEL
+
+include(modeltest/modeltest.pri)
unix {
LIBS += -lz
- include(modeltest/modeltest.pri)
}
windows {
# FIXME: Build zlib, too
int Library::rowCount(const QModelIndex &parent) const
{
- Q_UNUSED(parent);
- return mBooks.size();
+ if (parent.isValid()) {
+ return 0;
+ } else {
+ return mBooks.size();
+ }
}
QVariant Library::data(const QModelIndex &index, int role) const
{
+ qDebug() << "Library::data, row" << index.row() << "role" << role;
+
+ if (!index.isValid()) {
+ return QVariant();
+ }
+
switch (role) {
case Qt::DisplayRole:
- return mBooks[index.row()]->title;
+ return mBooks[index.row()]->name();
case BookRole:
return QVariant::fromValue<Book>(*mBooks[index.row()]);
default:
}
int size = mBooks.size();
Book *book = new Book(path);
- beginInsertRows(QModelIndex(), size - 1, size);
+ beginInsertRows(QModelIndex(), size, size);
mBooks.append(book);
save();
endInsertRows();
void Library::remove(const QModelIndex &index)
{
+ if (!index.isValid()) {
+ return;
+ }
int row = index.row();
if ((row < 0) || (row >= mBooks.size())) {
return;
}
- beginRemoveRows(QModelIndex(), row, row + 1);
+ beginRemoveRows(QModelIndex(), row, row);
Book *book = mBooks[row];
mBooks.removeAt(row);
save();
if (current.isValid()) {
Book currentBook =
Library::instance()->data(current, Library::BookRole).value<Book>();
- QString title = currentBook.title;
+ QString title = currentBook.name();
if (QMessageBox::Yes ==
QMessageBox::question(this, "Delete book",
"Delete book \"" + title + "\"?",
#include "bookmarksdialog.h"
#include "settings.h"
+#ifdef DORIAN_TEST_MODEL
+#include "modeltest.h"
+#endif
+
#ifdef Q_WS_MAC
# define ICON_PREFIX ":/icons/mac/"
#else
// Handle loading chapters
connect(view, SIGNAL(chapterLoaded(int)), this, SLOT(onChapterLoaded(int)));
+
+#ifdef DORIAN_TEST_MODEL
+ (void)new ModelTest(Library::instance(), this);
+#endif
}
void MainWindow::onCurrentBookChanged()
+++ /dev/null
-include(modeltest.pri)
-
-OTHER_FILES += \
- README