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);
}
}
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;
{
Trace t("BookView::onLoadFinished");
if (!ok) {
- t.trace("Not OK");
+ qDebug() << "Not OK";
return;
}
loaded = true;
}
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();
}
{
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());
}
}
contentsHeight = size.height();
if (decorated) {
if (restorePositionAfterLoad) {
- Trace::trace("BookView::onContentSizeChanged: Time to restore");
+ qDebug() << "BookView::onContentSizeChanged: Time to restore";
restorePositionAfterLoad = false;
goToPosition(positionAfterLoad);
}
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()
#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();
}
#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. */
void goToChapter(int index);
public slots:
- void onItemActivated(QListWidgetItem *);
+ void onItemActivated(const QModelIndex &index);
protected:
- QListWidget *list;
+ ListView *list;
+ QStringList data;
};
#endif // CHAPTERSDIALOG_H
widgets/toolbuttonbox.cpp \
model/bookfinder.cpp \
widgets/listwindow.cpp \
- foldersdialog.cpp \
widgets/progress.cpp \
widgets/bookwindow.cpp
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
iconscalable.path = $$DATADIR/icons/hicolor/scalable/hildon
iconscalable.files += pkg/maemo/icon-scalable/dorian.png
}
+macx {
+ CONFIG += x86
+}
<file>icons/previous-disabled.png</file>
<file>icons/chapters.png</file>
<file>icons/mac/chapters.png</file>
+ <file>icons/library.png</file>
</qresource>
</RCC>
+++ /dev/null
-#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);
-}
+++ /dev/null
-#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
#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);
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()));
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);
}
#include "listwindow.h"
-class QListView;
+class ListView;
class QPushButton;
class QModelIndex;
class QCloseEvent;
+class QProgressDialog;
class Book;
class InfoWindow;
class SortedLibrary;
public slots:
void onAdd();
- void onShowFolders();
+ void onAddFolder();
#ifndef Q_WS_MAEMO_5
void onRemove();
void onDetails();
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
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 &)),
MainWindow::~MainWindow()
{
- bookFinderThread.quit();
- bookFinderThread.wait();
- delete bookFinder;
}
void MainWindow::onCurrentBookChanged()
#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);
}
} 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);
}
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";
}
}
#include <QtGui>
#include "bookwindow.h"
-#include "bookfinder.h"
class QString;
class QModelIndex;
QModelIndex mCurrent;
FullScreenWindow *fullScreenWindow;
int preventBlankingTimer;
- BookFinder *bookFinder;
- BookFinderThread bookFinderThread;
Progress *progress;
};
bool Book::open()
{
Trace t("Book::open");
- t.trace(path());
+ qDebug() << path();
close();
clear();
if (path().isEmpty()) {
void Book::peek()
{
Trace t("Book::peek");
- t.trace(path());
+ qDebug() << path();
close();
clear();
if (path().isEmpty()) {
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)) {
// 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);
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;
}
// 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);
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();
"/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));
}
}
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);
// 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",
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();
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;
}
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);
{
}
-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);
}
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
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();
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;
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;
* 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
#include <stdio.h>
#include <stdlib.h>
-
#include <QEvent>
#include "trace.h"
{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);
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;
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;
--- /dev/null
+#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
#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,
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);
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();
}
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
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
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
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
#else
QDialogButtonBox *buttonBox;
QList<QPushButton *> itemButtons;
-#endif
- QHBoxLayout *frameLayout;
- QListView *list;
+#endif // Q_WS_MAEMO_5
+ QBoxLayout *contentLayout;
+ ListView *list;
};
#endif // LISTWINDOW_H