Improve traces. Simplify folder management.
authorAkos Polster <polster@marzipan.pipacs.com>
Sun, 29 Aug 2010 00:48:23 +0000 (02:48 +0200)
committerAkos Polster <polster@marzipan.pipacs.com>
Sun, 29 Aug 2010 00:48:23 +0000 (02:48 +0200)
24 files changed:
bookview.cpp
chaptersdialog.cpp
chaptersdialog.h
dorian.pro
dorian.qrc
foldersdialog.cpp [deleted file]
foldersdialog.h [deleted file]
librarydialog.cpp
librarydialog.h
mainwindow.cpp
mainwindow.h
model/book.cpp
model/bookfinder.cpp
model/bookfinder.h
model/library.cpp
model/ncxhandler.h
model/opshandler.h
pkg/changelog
trace.cpp
trace.h
widgets/bookwindow.cpp
widgets/listview.h [new file with mode: 0644]
widgets/listwindow.cpp
widgets/listwindow.h

index c0a0353..3003165 100644 (file)
@@ -169,8 +169,8 @@ void BookView::setLastBookmark()
     if (mBook) {
         int height = contentsHeight;
         int pos = page()->mainFrame()->scrollPosition().y();
-        t.trace(QString("At %1 (%2%, height %3)").
-                arg(pos).arg((qreal)pos / (qreal)height * 100).arg(height));
+        qDebug() << QString("At %1 (%2%, height %3)").
+                arg(pos).arg((qreal)pos / (qreal)height * 100).arg(height);
         mBook->setLastBookmark(contentIndex, (qreal)pos / (qreal)height);
     }
 }
@@ -188,7 +188,7 @@ void BookView::goToBookmark(const Book::Bookmark &bookmark)
     Trace t("BookView::goToBookmark");
     if (mBook) {
         if (bookmark.part != contentIndex) {
-            t.trace(QString("Loading new part %1").arg(bookmark.part));
+            qDebug () << "Loading new part" << bookmark.part;
             mBook->setLastBookmark(bookmark.part, bookmark.pos);
             restorePositionAfterLoad = true;
             positionAfterLoad = bookmark.pos;
@@ -203,7 +203,7 @@ void BookView::onLoadFinished(bool ok)
 {
     Trace t("BookView::onLoadFinished");
     if (!ok) {
-        t.trace("Not OK");
+        qDebug() << "Not OK";
         return;
     }
     loaded = true;
@@ -292,7 +292,7 @@ void BookView::addBookmark()
     }
     int y = page()->mainFrame()->scrollPosition().y();
     int height = page()->mainFrame()->contentsSize().height();
-    t.trace(QString().setNum((qreal)y / (qreal)height));
+    qDebug() << ((qreal)y / (qreal)height);
     mBook->addBookmark(contentIndex, (qreal)y / (qreal)height);
     update();
 }
@@ -362,11 +362,10 @@ bool BookView::eventFilter(QObject *o, QEvent *e)
 {
     if (e->type() != QEvent::Paint && e->type() != QEvent::MouseMove) {
         if (e->type() == QEvent::Resize) {
-            Trace::trace(QString("BookView::eventFilter QEvent::Resize to %1").
-                         arg(page()->mainFrame()->contentsSize().height()));
+            qDebug() << "BookView::eventFilter QEvent::Resize to"
+                    << page()->mainFrame()->contentsSize().height();
         } else {
-            Trace::trace(QString("BookView::eventFilter %1").
-                         arg(Trace::event(e->type())));
+            qDebug() << "BookView::eventFilter" << Trace::event(e->type());
         }
     }
 
@@ -404,7 +403,7 @@ void BookView::onContentsSizeChanged(const QSize &size)
     contentsHeight = size.height();
     if (decorated) {
         if (restorePositionAfterLoad) {
-            Trace::trace("BookView::onContentSizeChanged: Time to restore");
+            qDebug() << "BookView::onContentSizeChanged: Time to restore";
             restorePositionAfterLoad = false;
             goToPosition(positionAfterLoad);
         }
@@ -433,8 +432,8 @@ void BookView::goToPosition(qreal position)
     int scrollPos = (qreal)contentsHeight * position;
     page()->mainFrame()->setScrollPosition(QPoint(0, scrollPos));
     // FIXME: update();
-    Trace::trace(QString("BookView::goToPosition: To %1 (%2%, height %3)").
-            arg(scrollPos).arg(position * 100).arg(contentsHeight));
+    qDebug() << "BookView::goToPosition: To" << scrollPos << "("
+            << (position * 100) << "%, height" << contentsHeight << ")";
 }
 
 void BookView::showProgress()
index 0b972d7..2f279e0 100644 (file)
@@ -2,30 +2,34 @@
 
 #include "chaptersdialog.h"
 #include "book.h"
+#include "listview.h"
 
 ChaptersDialog::ChaptersDialog(Book *book, QWidget *parent): ListWindow(parent)
 {
     setWindowTitle(tr("Chapters"));
 
-    list = new QListWidget(this);
-    list->setSelectionMode(QAbstractItemView::SingleSelection);
     if (book) {
         foreach (QString id, book->chapters) {
             QString contentTitle = book->content[id].name;
-            (void)new QListWidgetItem(contentTitle, list);
+            data.append(contentTitle);
         }
     }
+    QStringListModel *model = new QStringListModel(data, this);
+    list = new ListView;
+    list->setSelectionMode(QAbstractItemView::SingleSelection);
+    list->setModel(model);
+    list->setUniformItemSizes(true);
     addList(list);
-    connect(list, SIGNAL(itemActivated(QListWidgetItem*)),
-            this, SLOT(onItemActivated(QListWidgetItem*)));
+    connect(list, SIGNAL(activated(const QModelIndex &)),
+            this, SLOT(onItemActivated(const QModelIndex &)));
 
 #ifndef Q_WS_MAEMO_5
     addAction(tr("Close"), this, SLOT(close()), QDialogButtonBox::RejectRole);
 #endif // Q_WS_MAEMO_5
 }
 
-void ChaptersDialog::onItemActivated(QListWidgetItem *item)
+void ChaptersDialog::onItemActivated(const QModelIndex &index)
 {
-    emit goToChapter(list->row(item));
+    emit goToChapter(index.row());
     close();
 }
index 03d18ff..7ec300c 100644 (file)
@@ -1,11 +1,13 @@
 #ifndef CHAPTERSDIALOG_H
 #define CHAPTERSDIALOG_H
 
+#include <QStringList>
+
 #include "listwindow.h"
 
 class QWidget;
-class QListWidget;
-class QListWidgetItem;
+class QModelIndex;
+class ListView;
 class Book;
 
 /** Display book chapters. */
@@ -20,10 +22,11 @@ signals:
     void goToChapter(int index);
 
 public slots:
-    void onItemActivated(QListWidgetItem *);
+    void onItemActivated(const QModelIndex &index);
 
 protected:
-    QListWidget *list;
+    ListView *list;
+    QStringList data;
 };
 
 #endif // CHAPTERSDIALOG_H
index 24c75f2..1656cd8 100644 (file)
@@ -29,7 +29,6 @@ SOURCES += \
     widgets/toolbuttonbox.cpp \
     model/bookfinder.cpp \
     widgets/listwindow.cpp \
-    foldersdialog.cpp \
     widgets/progress.cpp \
     widgets/bookwindow.cpp
 
@@ -61,9 +60,9 @@ HEADERS += \
     widgets/toolbuttonbox.h \
     model/bookfinder.h \
     widgets/listwindow.h \
-    foldersdialog.h \
     widgets/progress.h \
-    widgets/bookwindow.h
+    widgets/bookwindow.h \
+    widgets/listview.h
 
 RESOURCES += \
     dorian.qrc
@@ -127,3 +126,6 @@ maemo5 {
     iconscalable.path = $$DATADIR/icons/hicolor/scalable/hildon
     iconscalable.files += pkg/maemo/icon-scalable/dorian.png
 }
+macx {
+    CONFIG += x86
+}
index 7a73617..39744a0 100644 (file)
@@ -37,5 +37,6 @@
         <file>icons/previous-disabled.png</file>
         <file>icons/chapters.png</file>
         <file>icons/mac/chapters.png</file>
+        <file>icons/library.png</file>
     </qresource>
 </RCC>
diff --git a/foldersdialog.cpp b/foldersdialog.cpp
deleted file mode 100644 (file)
index 33666ef..0000000
+++ /dev/null
@@ -1,161 +0,0 @@
-#include <QtGui>
-#include <QStringListModel>
-#include <QFileInfo>
-
-#ifdef Q_WS_MAEMO_5
-#include <QtMaemo5/QMaemo5InformationBox>
-#endif
-
-#include "foldersdialog.h"
-#include "library.h"
-#include "settings.h"
-#include "trace.h"
-#include "bookfinder.h"
-
-FoldersDialog::FoldersDialog(QWidget *parent): ListWindow(parent)
-{
-    setWindowTitle(tr("Folders"));
-    model = new QStringListModel(Library::instance()->folders(), this);
-    QListView *list = new QListView(this);
-    list->setModel(model);
-    list->setEditTriggers(QAbstractItemView::NoEditTriggers);
-    list->setUniformItemSizes(true);
-    addList(list);
-    addAction(tr("Add folder"), this, SLOT(onAdd()));
-    addItemAction(tr("Re-scan"), this, SLOT(onRefresh()));
-    addItemAction(tr("Remove"), this, SLOT(onRemove()));
-    addAction(tr("Re-scan all folders"), this, SLOT(onRefreshAll()));
-    progress = new QProgressDialog(tr("Scanning for books"), "", 0, 0, this);
-    progress->reset();
-    progress->setMinimumDuration(0);
-    progress->setWindowModality(Qt::WindowModal);
-    progress->setCancelButton(0);
-}
-
-void FoldersDialog::onAdd()
-{
-    Trace t("FoldersDialog::onAdd");
-
-    // Get folder name
-    Settings *settings = Settings::instance();
-    QString last =
-            settings->value("lastfolderadded", QDir::homePath()).toString();
-    QString path =
-            QFileDialog::getExistingDirectory(this, tr("Add Folder"), last);
-    if (path == "") {
-        return;
-    }
-    settings->setValue("lastfolderadded", QFileInfo(path).absolutePath());
-    t.trace(path);
-
-    // Add folder to model
-    if (Library::instance()->addFolder(path)) {
-        int rows = model->rowCount();
-        model->insertRows(rows, 1);
-        model->setData(model->index(rows), path);
-        refresh(QStringList(path));
-    } else {
-#ifdef Q_WS_MAEMO_5
-        QMaemo5InformationBox::information(this,
-            tr("This folder is already in the library"));
-#else
-        (void)QMessageBox::information(this, tr("Dorian"),
-            tr("This folder is already in the library"), QMessageBox::Ok);
-#endif // Q_WS_MAEMO_5
-    }
-}
-
-void FoldersDialog::onRemove()
-{
-    Trace t("FoldersDialog::onRemove");
-
-    QModelIndexList selection = list->selectionModel()->selectedIndexes();
-    if (selection.size() != 1) {
-        return;
-    }
-
-    QModelIndex selected = selection[0];
-    QString path = list->model()->data(selected).toString();
-    t.trace(path);
-
-    if (QMessageBox::Yes ==
-        QMessageBox::question(this, tr("Remove folder"),
-            tr("Remove folder \"%1\" from library?").arg(path),
-            QMessageBox::Yes | QMessageBox::No)) {
-        if (Library::instance()->removeFolder(path)) {
-            model->removeRow(selected.row());
-        }
-    }
-}
-
-void FoldersDialog::refresh(const QStringList &dirs)
-{
-    Trace t("FoldersDialog::refresh");
-
-    progress->setWindowTitle((dirs.length() > 1)?
-                             tr("Scanning all folders"): tr("Scanning folder"));
-    BookFinder *bookFinder = new BookFinder(this);
-    Library *library = Library::instance();
-    connect(bookFinder, SIGNAL(beginAdd(int)), progress, SLOT(setMaximum(int)));
-    connect(bookFinder, SIGNAL(add(const QString &)),
-            this, SLOT(onAddBook(const QString &)));
-    connect(bookFinder, SIGNAL(add(const QString &)),
-            library, SLOT(add(const QString &)));
-    connect(bookFinder, SIGNAL(remove(const QString &)),
-            library, SLOT(remove(const QString &)));
-    connect(bookFinder, SIGNAL(done(int,int)),
-            this, SLOT(onRefreshDone(int, int)));
-    bookFinder->find(dirs, library->bookPaths());
-}
-
-void FoldersDialog::onRefresh()
-{
-    Trace t("FoldersDialog::onRefresh");
-
-    QModelIndexList selection = list->selectionModel()->selectedIndexes();
-    if (selection.size() != 1) {
-        return;
-    }
-    QModelIndex selected = selection[0];
-    QString path = list->model()->data(selected).toString();
-    refresh(QStringList(path));
-}
-
-void FoldersDialog::onRefreshAll()
-{
-    refresh(model->stringList());
-}
-
-void FoldersDialog::onRefreshDone(int added, int removed)
-{
-    QString addedMsg;
-    QString removedMsg;
-
-    switch (added) {
-    case 0: addedMsg = tr("No books added"); break;
-    case 1: addedMsg = tr("%1 book added").arg(1); break;
-    default: addedMsg = tr("%1 books added").arg(added);
-    }
-
-    switch (removed) {
-    case 0: removedMsg = tr("no books removed"); break;
-    case 1: removedMsg = tr("%1 book removed").arg(1); break;
-    default: removedMsg = tr("%1 books removed").arg(removed);
-    }
-
-    progress->reset();
-    QString msg(tr("Scanning complete\n\n%1, %2.").
-                arg(addedMsg).arg(removedMsg));
-    Trace::trace(QString("FoldersDialog::onRefreshDone: " + msg));
-#ifdef Q_WS_MAEMO_5
-    QMaemo5InformationBox::information(this, msg);
-#else
-    // FIXME
-#endif
-}
-
-void FoldersDialog::onAddBook(const QString &path)
-{
-    progress->setLabelText(QFileInfo(path).fileName());
-    progress->setValue(progress->value() + 1);
-}
diff --git a/foldersdialog.h b/foldersdialog.h
deleted file mode 100644 (file)
index a655bbc..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-#ifndef FOLDERSDIALOG_H
-#define FOLDERSDIALOG_H
-
-class QStringListModel;
-class QWidget;
-class QProgressDialog;
-
-#include "listwindow.h"
-
-/** Dialog to manage folders monitored by the library. */
-class FoldersDialog: public ListWindow
-{
-    Q_OBJECT
-
-public:
-    explicit FoldersDialog(QWidget *parent = 0);
-
-public slots:
-    void onAdd();
-    void onRemove();
-    void onRefresh();
-    void onRefreshAll();
-    void onRefreshDone(int added, int removed);
-    void onAddBook(const QString &path);
-
-protected:
-    void refresh(const QStringList &folders);
-    QStringListModel *model;
-    QProgressDialog *progress;
-};
-
-#endif // FOLDERSDIALOG_H
index f861d26..4386e7d 100644 (file)
 #include "infodialog.h"
 #include "settings.h"
 #include "listwindow.h"
-#include "foldersdialog.h"
+#include "listview.h"
+#include "trace.h"
+#include "bookfinder.h"
 
 LibraryDialog::LibraryDialog(QWidget *parent): ListWindow(parent)
 {
     setWindowTitle(tr("Library"));
 
-    // Create and add list view
+    // Add actions
+
+#ifndef Q_WS_MAEMO_5
+    addItemAction(tr("Details"), this, SLOT(onDetails()));
+    addItemAction(tr("Read"), this, SLOT(onRead()));
+    addItemAction(tr("Delete"), this, SLOT(onRemove()));
+#endif // ! Q_WS_MAEMO_5
+
+    addAction(tr("Add book"), this, SLOT(onAdd()));
+    addAction(tr("Add books from folder"), this, SLOT(onAddFolder()));
 
-    list = new QListView(this);
+    // Create and add list view
+    list = new ListView(this);
     sortedLibrary = new SortedLibrary(this);
     list->setModel(sortedLibrary);
     list->setSelectionMode(QAbstractItemView::SingleSelection);
@@ -33,16 +45,11 @@ LibraryDialog::LibraryDialog(QWidget *parent): ListWindow(parent)
     setSelected(current);
     addList(list);
 
-    // Add actions
-
-#ifndef Q_WS_MAEMO_5
-    addItemAction(tr("Details"), this, SLOT(onDetails()));
-    addItemAction(tr("Read"), this, SLOT(onRead()));
-    addItemAction(tr("Delete"), this, SLOT(onRemove()));
-#endif // ! Q_WS_MAEMO_5
-
-    addAction(tr("Add book"), this, SLOT(onAdd()));
-    addAction(tr("Manage folders"), this, SLOT(onShowFolders()));
+    progress = new QProgressDialog(tr("Adding books"), "", 0, 0, this);
+    progress->reset();
+    progress->setMinimumDuration(0);
+    progress->setWindowModality(Qt::WindowModal);
+    progress->setCancelButton(0);
 
     connect(Library::instance(), SIGNAL(nowReadingChanged()),
             this, SLOT(onCurrentBookChanged()));
@@ -177,8 +184,57 @@ QModelIndex LibraryDialog::selected() const
     return QModelIndex();
 }
 
-void LibraryDialog::onShowFolders()
+void LibraryDialog::onAddFolder()
+{
+    Trace t("LibraryDialog::onAddFolder");
+
+    // Get folder name
+    Settings *settings = Settings::instance();
+    QString last =
+            settings->value("lastfolderadded", QDir::homePath()).toString();
+    QString path =
+            QFileDialog::getExistingDirectory(this, tr("Select folder"), last);
+    if (path == "") {
+        return;
+    }
+    settings->setValue("lastfolderadded", QFileInfo(path).absolutePath());
+    qDebug() << path;
+
+    // Add books from folder
+    progress->setWindowTitle(tr("Adding books"));
+    BookFinder *bookFinder = new BookFinder(this);
+    Library *library = Library::instance();
+    connect(bookFinder, SIGNAL(begin(int)), progress, SLOT(setMaximum(int)));
+    connect(bookFinder, SIGNAL(add(const QString &)),
+            this, SLOT(onAddFromFolder(const QString &)));
+    connect(bookFinder, SIGNAL(add(const QString &)),
+            library, SLOT(add(const QString &)));
+    connect(bookFinder, SIGNAL(done(int)),
+            this, SLOT(onAddFromFolderDone(int)));
+    bookFinder->find(path, Library::instance()->bookPaths());
+}
+
+void LibraryDialog::onAddFromFolderDone(int added)
+{
+    QString msg;
+
+    switch (added) {
+    case 0: msg = tr("No new books found"); break;
+    case 1: msg = tr("One new book added"); break;
+    default: msg = tr("%1 new books added").arg(added);
+    }
+
+    progress->reset();
+    qDebug() << "LibraryDialog::onRefreshDone:" << msg;
+#ifdef Q_WS_MAEMO_5
+    QMaemo5InformationBox::information(this, msg);
+#else
+    // FIXME
+#endif
+}
+
+void LibraryDialog::onAddFromFolder(const QString &path)
 {
-    FoldersDialog *folders = new FoldersDialog(this);
-    folders->show();
+    progress->setLabelText(QFileInfo(path).fileName());
+    progress->setValue(progress->value() + 1);
 }
index ed8c66b..ca0e452 100644 (file)
@@ -7,10 +7,11 @@
 
 #include "listwindow.h"
 
-class QListView;
+class ListView;
 class QPushButton;
 class QModelIndex;
 class QCloseEvent;
+class QProgressDialog;
 class Book;
 class InfoWindow;
 class SortedLibrary;
@@ -24,7 +25,7 @@ public:
 
 public slots:
     void onAdd();
-    void onShowFolders();
+    void onAddFolder();
 #ifndef Q_WS_MAEMO_5
     void onRemove();
     void onDetails();
@@ -33,13 +34,15 @@ public slots:
     void onBookAdded();
     void onItemActivated(const QModelIndex &index);
     void onCurrentBookChanged();
-
+    void onAddFromFolder(const QString &path);
+    void onAddFromFolderDone(int added);
 private:
     QString createItemText(const Book *book);
     void setSelected(const QModelIndex &index);
     QModelIndex selected() const;
-    QListView *list;
+    ListView *list;
     SortedLibrary *sortedLibrary;
+    QProgressDialog *progress;
 };
 
 #endif // LIBRARYDIALOG_H
index 95a47d9..3182b08 100755 (executable)
@@ -153,15 +153,6 @@ MainWindow::MainWindow(QWidget *parent):
     fullScreenWindow = new FullScreenWindow(this);
     connect(fullScreenWindow, SIGNAL(restore()), this, SLOT(showRegular()));
 
-    // Create thread for finding books in directories
-    bookFinder = new BookFinder();
-    connect(bookFinder, SIGNAL(add(const QString &)),
-            library, SLOT(add(const QString &)));
-    connect(bookFinder, SIGNAL(remove(const QString &)),
-            library, SLOT(remove(const QString &)));
-    bookFinder->moveToThread(&bookFinderThread);
-    bookFinderThread.start();
-
     // Handle settings changes
     Settings *settings = Settings::instance();
     connect(settings, SIGNAL(valueChanged(const QString &)),
@@ -177,9 +168,6 @@ MainWindow::MainWindow(QWidget *parent):
 
 MainWindow::~MainWindow()
 {
-    bookFinderThread.quit();
-    bookFinderThread.wait();
-    delete bookFinder;
 }
 
 void MainWindow::onCurrentBookChanged()
@@ -275,8 +263,7 @@ void MainWindow::onSettingsChanged(const QString &key)
 #ifdef Q_WS_MAEMO_5
     if (key == "orientation") {
         QString value = Settings::instance()->value(key).toString();
-        Trace::trace(QString("MainWindow::onSettingsChanged: orientation %1").
-                     arg(value));
+        qDebug() << "MainWindow::onSettingsChanged: orientation" << value;
         if (value == "portrait") {
             setAttribute(Qt::WA_Maemo5LandscapeOrientation, false);
             setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
@@ -287,16 +274,14 @@ void MainWindow::onSettingsChanged(const QString &key)
         }
     } else if (key == "lightson") {
         bool enable = Settings::instance()->value(key, false).toBool();
-        Trace::trace(QString("MainWindow::onSettingsChanged: lightson: %1").
-                     arg(enable));
+        qDebug() << "MainWindow::onSettingsChanged: lightson:" << enable;
         killTimer(preventBlankingTimer);
         if (enable) {
             preventBlankingTimer = startTimer(29 * 1000);
         }
     } else if (key == "usevolumekeys") {
         bool value = Settings::instance()->value(key).toBool();
-        Trace::trace(QString("MainWindow::onSettingsChanged: usevolumekeys %1").
-                     arg(value));
+        qDebug() << "MainWindow::onSettingsChanged: usevolumekeys" << value;
         grabZoomKeys(value);
         fullScreenWindow->grabZoomKeys(value);
     }
@@ -384,7 +369,7 @@ void MainWindow::timerEvent(QTimerEvent *event)
                            MCE_REQUEST_IF, QDBusConnection::systemBus());
         mce.call(MCE_PREVENT_BLANK_REQ);
 #endif // Q_WS_MAEMO_5
-        Trace::trace("MainWindow::timerEvent: Prevent display blanking");
+        qDebug() << "MainWindow::timerEvent: Prevent display blanking";
     }
 }
 
index 1834f1a..4c4af45 100755 (executable)
@@ -4,7 +4,6 @@
 #include <QtGui>
 
 #include "bookwindow.h"
-#include "bookfinder.h"
 
 class QString;
 class QModelIndex;
@@ -67,8 +66,6 @@ private:
     QModelIndex mCurrent;
     FullScreenWindow *fullScreenWindow;
     int preventBlankingTimer;
-    BookFinder *bookFinder;
-    BookFinderThread bookFinderThread;
     Progress *progress;
 };
 
index bf29f3a..e3d1838 100644 (file)
@@ -47,7 +47,7 @@ QString Book::path() const
 bool Book::open()
 {
     Trace t("Book::open");
-    t.trace(path());
+    qDebug() << path();
     close();
     clear();
     if (path().isEmpty()) {
@@ -68,7 +68,7 @@ bool Book::open()
 void Book::peek()
 {
     Trace t("Book::peek");
-    t.trace(path());
+    qDebug() << path();
     close();
     clear();
     if (path().isEmpty()) {
@@ -105,7 +105,7 @@ bool Book::extract()
     Trace t("Book::extract");
     bool ret = false;
     QString tmp = tmpDir();
-    t.trace("Extracting " + mPath + " to " + tmp);
+    qDebug() << "Extracting" << mPath << "to" << tmp;
 
     QDir::setCurrent(QDir::rootPath());
     if (!clearDir(tmp)) {
@@ -151,7 +151,7 @@ bool Book::parse()
     // Parse OPS file
     bool ret = false;
     QString opsFileName = opsPath();
-    t.trace("Parsing OPS file" + opsFileName);
+    qDebug() << "Parsing OPS file" << opsFileName;
     QFile opsFile(opsFileName);
     QXmlSimpleReader reader;
     QXmlInputSource *source = new QXmlInputSource(&opsFile);
@@ -173,7 +173,7 @@ bool Book::parse()
     coverKeys << "cover-image" << "img-cover-jpeg" << "cover";
     foreach (QString key, coverKeys) {
         if (content.contains(key)) {
-            t.trace("Loading cover image from " + content[key].href);
+            qDebug() << "Loading cover image from" << content[key].href;
             cover = makeCover(content[key].href);
             break;
         }
@@ -183,7 +183,7 @@ bool Book::parse()
     // contents
     if (content.contains("ncx")) {
         QString ncxFileName = content["ncx"].href;
-        t.trace("Parsing NCX file " + ncxFileName);
+        qDebug() << "Parsing NCX file" << ncxFileName;
         QFile ncxFile(ncxFileName);
         source = new QXmlInputSource(&ncxFile);
         NcxHandler *ncxHandler = new NcxHandler(*this);
@@ -253,14 +253,14 @@ void Book::clear()
 void Book::load()
 {
     Trace t("Book::load");
-    t.trace("path: " + path());
+    qDebug() << "path" << path();
     QSettings settings;
     QString key = "book/" + path() + "/";
-    t.trace("key: " + key);
+    qDebug() << "key" << key;
 
     // Load book info
     title = settings.value(key + "title").toString();
-    t.trace(title);
+    qDebug() << title;
     creators = settings.value(key + "creators").toStringList();
     date = settings.value(key + "date").toString();
     publisher = settings.value(key + "publisher").toString();
@@ -283,8 +283,8 @@ void Book::load()
                                      "/part").toInt();
         qreal pos = settings.value(key + "bookmark" + QString::number(i) +
                                    "/pos").toReal();
-        t.trace(QString("Bookmark %1 at part %2, %3").
-                arg(i).arg(part).arg(pos));
+        qDebug() << QString("Bookmark %1 at part %2, %3").
+                arg(i).arg(part).arg(pos);
         mBookmarks.append(Bookmark(part, pos));
     }
 }
@@ -294,11 +294,11 @@ void Book::save()
     Trace t("Book::save");
     QSettings settings;
     QString key = "book/" + path() + "/";
-    t.trace("key: " + key);
+    qDebug() << "key" << key;
 
     // Save book info
     settings.setValue(key + "title", title);
-    t.trace("title: " + title);
+    qDebug() << "title" << title;
     settings.setValue(key + "creators", creators);
     settings.setValue(key + "date", date);
     settings.setValue(key + "publisher", publisher);
@@ -313,8 +313,8 @@ void Book::save()
     // Save bookmarks
     settings.setValue(key + "bookmarks", mBookmarks.size());
     for (int i = 0; i < mBookmarks.size(); i++) {
-        t.trace(QString("Bookmark %1 at %2, %3").
-                arg(i).arg(mBookmarks[i].part).arg(mBookmarks[i].pos));
+        qDebug() << QString("Bookmark %1 at %2, %3").
+                arg(i).arg(mBookmarks[i].part).arg(mBookmarks[i].pos);
         settings.setValue(key + "bookmark" + QString::number(i) + "/part",
                           mBookmarks[i].part);
         settings.setValue(key + "bookmark" + QString::number(i) + "/pos",
@@ -358,7 +358,7 @@ QString Book::opsPath()
     QString ret;
 
     QFile container(tmpDir() + "/META-INF/container.xml");
-    t.trace(container.fileName());
+    qDebug() << container.fileName();
     QXmlSimpleReader reader;
     QXmlInputSource *source = new QXmlInputSource(&container);
     ContainerHandler *containerHandler = new ContainerHandler();
@@ -368,8 +368,7 @@ QString Book::opsPath()
     if (reader.parse(source)) {
         ret = tmpDir() + "/" + containerHandler->rootFile;
         mRootPath = QFileInfo(ret).absoluteDir().absolutePath();
-        t.trace("OSP path: " + ret);
-        t.trace("Root dir: " + mRootPath);
+        qDebug() << "OSP path" << ret << "\nRoot dir" << mRootPath;
     }
     delete errorHandler;
     delete containerHandler;
@@ -450,12 +449,12 @@ int Book::partFromChapter(int index)
         }
         if (content[contentKey].href == baseRef) {
             found = true;
-            t.trace(QString("Key for %1 is %2").arg(baseRef).arg(contentKey));
+            qDebug() << QString("Key for %1 is %2").arg(baseRef).arg(contentKey);
             break;
         }
     }
     if (!found) {
-        t.trace("Could not find key for " + baseRef);
+        qDebug() << "Could not find key for" << baseRef;
         return -1;
     }
     int partIndex = parts.indexOf(contentKey);
index f02045f..e33024b 100644 (file)
@@ -9,54 +9,32 @@ BookFinder::BookFinder(QObject *parent): QObject(parent)
 {
 }
 
-void BookFinder::find(const QStringList &directories, const QStringList &books)
+void BookFinder::find(const QString &path, const QStringList &books)
 {
     Trace t("BookFinder::find");
     QStringList booksFound;
+    int toAdd = 0;
     int added = 0;
-    int removed = 0;
 
-    foreach (QString path, directories) {
-        QStringList filters(QString("*.epub"));
-        QFileInfoList entries =
-                QDir(path).entryInfoList(filters, QDir::Files | QDir::Readable);
-        foreach (QFileInfo entry, entries) {
-            booksFound.append(entry.absoluteFilePath());
-        }
+    QStringList filters(QString("*.epub"));
+    QFileInfoList entries =
+            QDir(path).entryInfoList(filters, QDir::Files | QDir::Readable);
+    foreach (QFileInfo entry, entries) {
+        booksFound.append(entry.absoluteFilePath());
     }
 
-    int toAdd = 0;
     foreach (QString found, booksFound) {
         if (!books.contains(found)) {
             toAdd++;
         }
     }
-    emit beginAdd(toAdd);
-
+    emit begin(toAdd);
     foreach (QString found, booksFound) {
         if (!books.contains(found)) {
-            t.trace(QString("New book ") + found);
+            qDebug() << "New book" << found;
             emit add(found);
             added++;
         }
     }
-
-    foreach (QString book, books) {
-        QFileInfo bookInfo = QFileInfo(book);
-        QString bookDir = bookInfo.absolutePath();
-        QString bookPath = bookInfo.absoluteFilePath();
-        foreach (QString dirName, directories) {
-            t.trace(bookDir + " vs. " + QDir(dirName).absolutePath());
-            if (bookDir == QDir(dirName).absolutePath()) {
-                if (!booksFound.contains(bookPath)) {
-                    t.trace(QString("Deleted book ") + bookPath);
-                    removed++;
-                    emit remove(bookPath);
-                }
-                break;
-            }
-        }
-    }
-
-    emit done(added, removed);
+    emit done(added);
 }
index a3d5d91..86ff898 100644 (file)
@@ -15,23 +15,12 @@ public:
     explicit BookFinder(QObject *parent = 0);
 
 public slots:
-    void find(const QStringList &directories, const QStringList &books);
+    void find(const QString &directory, const QStringList &books);
 
 signals:
-    void beginAdd(int count);
-    void add(const QString &book);
-    void remove(const QString &book);
-    void done(int added, int removed);
-
-public slots:
-};
-
-class BookFinderThread: public QThread
-{
-public:
-   void run () {
-       exec();
-   }
+    void begin(int count);
+    void add(const QString &bookPath);
+    void done(int count);
 };
 
 #endif // BOOKFINDER_H
index c210555..5c4a41e 100644 (file)
@@ -110,7 +110,7 @@ bool Library::add(const QString &path)
         return false;
     }
     if (find(path).isValid()) {
-        t.trace("Book already exists in library");
+        qDebug() << "Book already exists in library";
         return false;
     }
     int size = mBooks.size();
index 211252b..170c8ab 100644 (file)
@@ -37,9 +37,8 @@ public:
         if (name == "text") {
             contentTitle = currentText;
         } else if (name == "navPoint") {
-            t.trace(QString("url: ") + contentUrl);
-            t.trace(QString("title: ") + contentTitle);
-            t.trace(QString("id:") + contentId);
+            qDebug() << "url" << contentUrl << "\ntitl" << contentTitle
+                    << "\nid" << contentId;
             Book::ContentItem item;
             item.href = book.rootPath() + "/" + contentUrl;
             item.name = contentTitle;
index 92d9943..b13c17d 100644 (file)
@@ -65,11 +65,10 @@ public:
             QString key = attrs.value("id");
             book.content[key] = item;
             partCount++;
-            t.trace(QString("name: ") + item.name);
-            t.trace(QString("href: ") + attrs.value("href"));
-            t.trace(QString("id: ") + key);
+            qDebug() << "name:"<< item.name << "\nhref:" << attrs.value("href")
+                    << "id:" << key;
         } else if (name == "itemref") {
-            t.trace(QString("id: ") + attrs.value("idref"));
+            qDebug() << "id:" << attrs.value("idref");
             book.parts.append(attrs.value("idref"));
         }
         return true;
index cae5105..40fb3a8 100644 (file)
@@ -2,6 +2,7 @@ dorian (0.1.5-1) unstable; urgency=low
 
   * Show better bookmark descriptions
   * Fix part navigation on desktops
+  * Remove complicated folder management
 
  -- Akos Polster <akos@pipacs.com>  Sun, 22 Aug 2010 02:00:00 +0200
 
index dd1acd1..f3a2bef 100644 (file)
--- a/trace.cpp
+++ b/trace.cpp
@@ -1,6 +1,5 @@
 #include <stdio.h>
 #include <stdlib.h>
-
 #include <QEvent>
 
 #include "trace.h"
@@ -229,12 +228,46 @@ Trace::EventName Trace::eventTab[] = {
     {0, 0}
 };
 
+Trace::Trace(const QString &s): name(s)
+{
+    messageHandler(QtDebugMsg, QString(">%1").arg(name).toAscii().constData());
+    indent++;
+}
+
+Trace::~Trace()
+{
+    if (--indent < 0) {
+        indent = 0;
+    }
+    messageHandler(QtDebugMsg, QString("<%1").arg(name).toAscii().constData());
+}
+
+QString Trace::event(QEvent::Type t)
+{
+    for (int i = 0; eventTab[i].name; i++) {
+        if (eventTab[i].type == t) {
+            return eventTab[i].name;
+        }
+    }
+    if (t >= QEvent::User) {
+        return QString("QEvent::User+%1").arg(t - QEvent::User);
+    } else {
+        return QString("Unknown event %1").arg(t);
+    }
+}
+
+const char *Trace::prefix()
+{
+    return (QTime::currentTime().toString("hh:mm:ss.zzz ") +
+        QString(" ").repeated(indent)).toAscii().constData();
+}
+
 void Trace::messageHandler(QtMsgType type, const char *msg)
 {
     if (type >= Trace::level) {
         switch (type) {
         case QtDebugMsg:
-            fprintf(stderr, "%s\n", msg);
+            fprintf(stderr, "%s%s\n", prefix(), msg);
             break;
         case QtWarningMsg:
             fprintf(stderr, "Warning: %s\n", msg);
diff --git a/trace.h b/trace.h
index 9c2fd2e..3fe1458 100644 (file)
--- a/trace.h
+++ b/trace.h
@@ -9,44 +9,14 @@
 class Trace
 {
 public:
-    Trace(const QString &s): name(s) {
-        qDebug() << prefix() + ">" + name;
-        indent++;
-    }
-
-    ~Trace() {
-        if (--indent < 0) {
-            indent = 0;
-        }
-        qDebug() << prefix() + "<" + name;
-    }
-
-    static void trace(const QString &s) {
-        qDebug() << prefix() + s;
-    }
-
-    static QString event(QEvent::Type t) {
-        for (int i = 0; eventTab[i].name; i++) {
-            if (eventTab[i].type == t) {
-                return eventTab[i].name;
-            }
-        }
-        if (t >= QEvent::User) {
-            return QString("QEvent::User+%1").arg(t - QEvent::User);
-        } else {
-            return QString("Unknown event %1").arg(t);
-        }
-    }
-
+    Trace(const QString &s);
+    ~Trace();
+    static QString event(QEvent::Type t);
     static void messageHandler(QtMsgType type, const char *msg);
-
     static QtMsgType level;
 
 protected:
-    static QString prefix() {
-        return QTime::currentTime().toString("hh:mm:ss.zzz ") +
-            QString(" ").repeated(indent);
-    }
+    static const char *prefix();
     QString name;
     static int indent;
     typedef struct {int type; const char *name;} EventName;
index 0ad9eca..f87b54b 100644 (file)
@@ -68,10 +68,10 @@ void BookWindow::doGrabZoomKeys(bool grab)
     Trace t("BookWindow::doGrabZoomKeys");
 #ifdef Q_WS_MAEMO_5
     if (!isVisible()) {
-        t.trace("Not visible - skipping");
+        qDebug() << "Not visible - skipping";
     }
     if (!winId()) {
-        t.trace("Could not get window ID - skipping");
+        qDebug() << "Could not get window ID - skipping";
         return;
     }
     unsigned long val = grab? 1: 0;
diff --git a/widgets/listview.h b/widgets/listview.h
new file mode 100644 (file)
index 0000000..1812b95
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef LISTVIEW_H
+#define LISTVIEW_H
+
+#include <QListView>
+
+class ListView: public QListView
+{
+    Q_OBJECT
+public:
+    explicit ListView(QWidget *parent = 0): QListView(parent) {
+        setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+        setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    }
+    int contentsHeight() const {return QListView::contentsSize().height() + 10;}
+};
+
+#endif // LISTVIEW_H
index 55ce10f..c15fa30 100644 (file)
@@ -2,33 +2,57 @@
 
 #include "listwindow.h"
 #include "trace.h"
+#include "listview.h"
 
 ListWindow::ListWindow(QWidget *parent): QMainWindow(parent), list(0)
 {
 #ifdef Q_WS_MAEMO_5
     setAttribute(Qt::WA_Maemo5StackedWindow, true);
-#endif
+    popup = new QMenu(this);
 
+    QScrollArea *scroller = new QScrollArea(this);
+    setCentralWidget(scroller);
+    scroller->setProperty("FingerScrollable", true);
+    scroller->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    scroller->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    scroller->setFrameStyle(QFrame::NoFrame);
+    scroller->show();
+
+    QWidget *content = new QWidget(scroller);
+    contentLayout = new QVBoxLayout(content);
+    contentLayout->setMargin(0);
+    content->setLayout(contentLayout);
+    content->show();
+
+    scroller->setWidget(content);
+    scroller->setWidgetResizable(true);
+#else
     QFrame *frame = new QFrame(this);
     setCentralWidget(frame);
-    frameLayout = new QHBoxLayout();
-    frame->setLayout(frameLayout);
-
-#ifdef Q_WS_MAEMO_5
-    popup = new QMenu(this);
-#else
+    contentLayout = new QHBoxLayout();
+    frame->setLayout(contentLayout);
     buttonBox = new QDialogButtonBox(Qt::Vertical, this);
-    frameLayout->addWidget(buttonBox);
+    contentLayout->addWidget(buttonBox);
 #endif
 }
 
-void ListWindow::addList(QListView *listView)
+void ListWindow::addList(ListView *listView)
 {
+    Trace t("ListWindow::addList");
     list = listView;
 #ifdef Q_WS_MAEMO_5
     list->installEventFilter(this);
+    list->setMinimumHeight(list->contentsHeight());
+    contentLayout->addWidget(list);
+    connect(list->model(),
+            SIGNAL(rowsInserted(const QModelIndex &, int, int)),
+            this, SLOT(onModelChanged()));
+    connect(list->model(),
+            SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
+            this, SLOT(onModelChanged()));
+#else
+    contentLayout->insertWidget(0, list);
 #endif
-    frameLayout->insertWidget(0, list);
     connect(list->selectionModel(),
       SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
       this,
@@ -38,19 +62,24 @@ void ListWindow::addList(QListView *listView)
 void ListWindow::addAction(const QString &title, QObject *receiver,
                            const char *slot, QDialogButtonBox::ButtonRole role)
 {
+    Trace t("ListWindow::addAction");
 #ifndef Q_WS_MAEMO_5
     QPushButton *button = buttonBox->addButton(title, role);
     connect(button, SIGNAL(clicked()), receiver, slot);
 #else
     Q_UNUSED(role);
-    QAction *action = menuBar()->addAction(title);
-    connect(action, SIGNAL(triggered()), receiver, slot);
+    // QAction *action = menuBar()->addAction(title);
+    // connect(action, SIGNAL(triggered()), receiver, slot);
+    QPushButton *button = new QPushButton(title, this);
+    contentLayout->addWidget(button);
+    connect(button, SIGNAL(clicked()), receiver, slot);
 #endif // ! Q_WS_MAEMO_5
 }
 
 void ListWindow::addItemAction(const QString &title, QObject *receiver,
                                const char *slot)
 {
+    Trace t("ListWindow::addItemAction");
 #ifndef Q_WS_MAEMO_5
     QPushButton *button =
             buttonBox->addButton(title, QDialogButtonBox::ActionRole);
@@ -103,7 +132,7 @@ void ListWindow::activateItemButtons()
 bool ListWindow::eventFilter(QObject *obj, QEvent *event)
 {
     if (event->type() == QEvent::ContextMenu) {
-        Trace::trace("ListWindow::eventFiler: Received QEvent::ContextMenu");
+        qDebug() << "ListWindow::eventFiler: Received QEvent::ContextMenu";
         if (popup->actions().size()) {
             QMouseEvent *mouseEvent = static_cast<QMouseEvent*> (event);
             QPoint pos = mouseEvent->globalPos();
@@ -115,9 +144,14 @@ bool ListWindow::eventFilter(QObject *obj, QEvent *event)
         }
         return true;
     } else {
-        Trace::trace("ListWindow::eventFilter");
         return QObject::eventFilter(obj, event);
     }
 }
 
+void ListWindow::onModelChanged()
+{
+    qDebug() << "ListWindow::onModelChanged";
+    list->setMinimumHeight(list->contentsHeight());
+}
+
 #endif // Q_WS_MAEMO_5
index 7b7d585..3b689f6 100644 (file)
@@ -7,11 +7,12 @@
 
 class QListView;
 class QString;
-class QHBoxLayout;
+class QBoxLayout;
 class QPushButton;
 class QModelIndex;
 class QItemSelection;
 class QEvent;
+class ListView;
 
 /** A window with a list and menu actions (Maemo) or buttons (non-Maemo). */
 class ListWindow: public QMainWindow
@@ -22,7 +23,7 @@ public:
     explicit ListWindow(QWidget *parent = 0);
 
     /** Add a list view to the window. */
-    void addList(QListView *list);
+    void addList(ListView *list);
 
     /**
      * Add an action to the window: either a button, or, on Maemo, a top
@@ -44,7 +45,9 @@ public:
 protected slots:
     void onSelectionChanged(const QItemSelection &selected,
                             const QItemSelection &deselected);
-#ifndef Q_WS_MAEMO_5
+#ifdef Q_WS_MAEMO_5
+    void onModelChanged();
+#else
     void activateItemButtons();
 #endif
 
@@ -56,9 +59,9 @@ protected:
 #else
     QDialogButtonBox *buttonBox;
     QList<QPushButton *> itemButtons;
-#endif
-    QHBoxLayout *frameLayout;
-    QListView *list;
+#endif // Q_WS_MAEMO_5
+    QBoxLayout *contentLayout;
+    ListView *list;
 };
 
 #endif // LISTWINDOW_H