restorePositionAfterLoad(false), positionAfterLoad(0), loaded(false),
contentsHeight(0)
{
- Trace t("BookView::BookView");
+ TRACE;
settings()->setAttribute(QWebSettings::AutoLoadImages, true);
settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
settings()->setAttribute(QWebSettings::JavaEnabled, false);
BookView::~BookView()
{
- Trace t("BookView::~BookView");
+ TRACE;
}
void BookView::loadContent(int index)
{
- Trace t("BookView::loadContent");
+ TRACE;
if (!mBook) {
return;
}
void BookView::setBook(Book *book)
{
- Trace t("BookView::setBook");
+ TRACE;
// Save position in current book
setLastBookmark();
void BookView::goPrevious()
{
- Trace t("BookView::goPrevious");
+ TRACE;
if (mBook && (contentIndex > 0)) {
mBook->setLastBookmark(contentIndex - 1, 0);
loadContent(contentIndex - 1);
void BookView::goNext()
{
- Trace t("BookView::goNext");
+ TRACE;
if (mBook && (contentIndex < (mBook->parts.size() - 1))) {
mBook->setLastBookmark(contentIndex + 1, 0);
loadContent(contentIndex + 1);
void BookView::setLastBookmark()
{
- Trace t("BookView::setLastBookmark");
+ TRACE;
if (mBook) {
int height = contentsHeight;
int pos = page()->mainFrame()->scrollPosition().y();
void BookView::restoreLastBookmark()
{
- Trace t("BookView::restoreLastBookmark");
+ TRACE;
if (mBook) {
goToBookmark(mBook->lastBookmark());
}
void BookView::goToBookmark(const Book::Bookmark &bookmark)
{
- Trace t("BookView::goToBookmark");
+ TRACE;
if (mBook) {
if (bookmark.part != contentIndex) {
qDebug () << "Loading new part" << bookmark.part;
void BookView::onLoadFinished(bool ok)
{
- Trace t("BookView::onLoadFinished");
+ TRACE;
if (!ok) {
qDebug() << "Not OK";
return;
void BookView::onSettingsChanged(const QString &key)
{
- Trace t("BookView::onSettingsChanged " + key);
+ TRACE;
if (key == "zoom") {
setZoomFactor(Settings::instance()->value(key).toFloat() / 100.);
}
void BookView::addBookmark(const QString ¬e)
{
- Trace t("BookView::addBookmark");
+ TRACE;
if (!mBook) {
return;
}
void BookView::leaveEvent(QEvent *e)
{
- Trace t("BookView::leaveEvent");
+ TRACE;
// Save current position, to be restored later
setLastBookmark();
QWebView::leaveEvent(e);
void BookView::enterEvent(QEvent *e)
{
- Trace t("BookView::enterEvent");
+ TRACE;
// Restore position saved at Leave event. This seems to be required,
// after temporarily switching from portrait to landscape and back
restoreLastBookmark();
void BookView::goNextPage()
{
- Trace t("BookView::goNextPage");
+ TRACE;
QWebFrame *frame = page()->mainFrame();
int pos = frame->scrollPosition().y();
frame->scroll(0, height());
void LibraryDialog::onRead()
{
- qDebug() << "LibraryDialog::onRead";
QModelIndex current = sortedLibrary->mapToSource(list->currentIndex());
if (current.isValid()) {
Library::instance()->setNowReading(current);
void LibraryDialog::onItemActivated(const QModelIndex &index)
{
- qDebug() << "LibraryDialog::onItemActivated";
+ TRACE;
QModelIndex libraryIndex = sortedLibrary->mapToSource(index);
Book *book = Library::instance()->book(libraryIndex);
(new InfoDialog(book, this))->exec();
void LibraryDialog::onAddFolder()
{
- Trace t("LibraryDialog::onAddFolder");
+ TRACE;
// Get folder name
Settings *settings = Settings::instance();
MainWindow::MainWindow(QWidget *parent):
AdopterWindow(parent), view(0), preventBlankingTimer(-1)
{
- Trace t("MainWindow::MainWindow");
+ TRACE;
#ifdef Q_WS_MAEMO_5
setAttribute(Qt::WA_Maemo5StackedWindow, true);
#endif
void MainWindow::showRegular()
{
- Trace t("MainWindow::showRegular");
+ TRACE;
// Re-parent children
fullScreenWindow->leaveChildren();
fullScreenWindow->hide();
show();
+#if defined(Q_OS_SYMBIAN)
activateWindow();
+#elif defined(Q_WS_MAEMO_5)
+ // FIXME: This is ugly.
+ view->restoreLastBookmark();
+#endif
progress->flash();
nextButton->flash(1500);
previousButton->flash(1500);
void MainWindow::showBig()
{
- Trace t("MainWindow::showBig");
+ TRACE;
// Re-parent children
leaveChildren();
previousButton->setGeometry(0, screen.height() - TranslucentButton::pixels,
TranslucentButton::pixels, TranslucentButton::pixels);
+#ifdef Q_OS_SYMBIAN
hide();
+#endif
fullScreenWindow->showFullScreen();
+#ifdef Q_OS_SYMBIAN
fullScreenWindow->activateWindow();
+#endif
progress->flash();
nextButton->flash(1500);
previousButton->flash(1500);
void MainWindow::closeEvent(QCloseEvent *event)
{
- Trace t("MainWindow::closeEvent");
+ TRACE;
view->setLastBookmark();
event->accept();
}
void MainWindow::onPartLoadStart()
{
- Trace t("MainWindow::onPartLoadStart");
+ TRACE;
#ifdef Q_WS_MAEMO_5
setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true);
#endif
void MainWindow::onPartLoadEnd(int index)
{
- Trace t("MainWindow::onPartLoadEnd");
+ TRACE;
bool enablePrevious = false;
bool enableNext = false;
Book *book = Library::instance()->book(mCurrent);
void MainWindow::onAddBookmark(const QString ¬e)
{
- Trace t("MainWindow:onAddBookmark");
+ TRACE;
view->addBookmark(note);
}
void MainWindow::onGoToBookmark(int index)
{
- Trace t("MainWindow::onGoToBookmark");
+ TRACE;
Book *book = Library::instance()->book(mCurrent);
view->goToBookmark(book->bookmarks()[index]);
}
void MainWindow::onGoToChapter(int index)
{
- Trace t("MainWindow::onGoToChapter");
+ TRACE;
Book *book = Library::instance()->book(mCurrent);
if (book) {
void MainWindow::resizeEvent(QResizeEvent *e)
{
- Trace t("MainWindow::resizeEvent");
+ TRACE;
progress->setGeometry(QRect(0, 0, e->size().width(), DORIAN_PROGRESS_HEIGHT));
#if defined(Q_WS_MAEMO_5)
previousButton->setGeometry(0,
bool Book::open()
{
- Trace t("Book::open");
+ TRACE;
qDebug() << path();
close();
clear();
void Book::peek()
{
- Trace t("Book::peek");
+ TRACE;
qDebug() << path();
close();
clear();
void Book::close()
{
- Trace t("Book::close");
+ TRACE;
content.clear();
parts.clear();
QDir::setCurrent(QDir::rootPath());
bool Book::extract(const QStringList &excludedExtensions)
{
- Trace t("Book::extract");
+ TRACE;
bool ret = false;
QString tmp = tmpDir();
qDebug() << "Extracting" << mPath << "to" << tmp;
bool Book::parse()
{
- Trace t("Book::parse");
+ TRACE;
// Parse OPS file
bool ret = false;
void Book::load()
{
- Trace t("Book::load");
+ TRACE;
qDebug() << "path" << path();
QVariantHash data = BookDb::instance()->load(path());
void Book::save()
{
- Trace t("Book::save");
+ TRACE;
QVariantHash data;
data["title"] = title;
void Book::setLastBookmark(int part, qreal position)
{
- Trace t("Book:setLastBookmark");
+ TRACE;
qDebug() << "part" << part << "position" << position;
mLastBookmark.part = part;
mLastBookmark.pos = position;
QString Book::opsPath()
{
- Trace t("Book::opsPath");
+ TRACE;
QString ret;
QFile container(tmpDir() + "/META-INF/container.xml");
void Book::upgrade()
{
- Trace t("Book::upgrade");
+ TRACE;
qDebug() << path();
void Book::remove()
{
- Trace t("Book::remove");
+ TRACE;
BookDb::instance()->remove(path());
}
BookDb::BookDb()
{
- Trace t("BookDb::BookDb");
+ TRACE;
bool shouldCreate = false;
QFileInfo info(Platform::dbPath());
if (!info.exists()) {
void BookDb::create()
{
- Trace t("BookDb::create");
+ TRACE;
QSqlQuery query;
if (!query.exec("create table book "
"(name text primary key, content blob)")) {
QVariantHash BookDb::load(const QString &book)
{
- Trace t("BookDb::load");
+ TRACE;
qDebug() << book;
QVariantHash ret;
QByteArray bytes;
in >> ret;
break;
}
- qDebug() << ret;
return ret;
}
void BookDb::save(const QString &book, const QVariantHash &data)
{
- Trace t("BookDb::save");
+ TRACE;
qDebug() << book;
- qDebug() << data;
QByteArray bytes;
QDataStream out(&bytes, QIODevice::WriteOnly);
out << data;
void BookDb::remove(const QString &book)
{
- Trace t("BookDb::remove");
+ TRACE;
qDebug() << book;
QSqlQuery query("delete from book where name = ?");
query.bindValue(0, book);
QStringList BookDb::books()
{
- Trace t("BookDb::books");
+ TRACE;
QStringList ret;
QSqlQuery query("select name from book");
query.setForwardOnly(true);
void BookFinder::find(const QString &path, const QStringList &books)
{
- Trace t("BookFinder::find");
+ TRACE;
QStringList booksFound;
int toAdd = 0;
int added = 0;
void Library::load()
{
- Trace t("Library::load");
+ TRACE;
clear();
QStringList books = BookDb::instance()->books();
void Library::save()
{
- Trace t("Library::save");
+ TRACE;
QSettings settings;
Book *currentBook = book(mNowReading);
settings.setValue("lib/nowreading",
bool Library::add(const QString &path)
{
- Trace t("Library::add " + path);
+ TRACE;
if (path == "") {
qCritical() << "Library::add: Empty path";
return false;
void Library::remove(const QModelIndex &index)
{
- Trace t("Library::remove");
+ TRACE;
Book *toRemove = book(index);
if (!toRemove) {
return;
void Library::onBookOpened(const QString &path)
{
- Trace t("Library::onBookOpened " + path);
+ TRACE;
QModelIndex index = find(path);
if (index.isValid()) {
emit dataChanged(index, index);
void Library::upgrade()
{
- Trace t("Library::upgrade");
+ TRACE;
QSettings settings;
QString oldVersion = settings.value("lib/version").toString();
if (/* true */ oldVersion.isEmpty()) {
void Search::start(const Query &query)
{
- Trace t("Search::start");
+ TRACE;
emit beginSearch();
void Search::download(const Search::Result &result, const QString &fileName)
{
- Trace t("Search::download");
+ TRACE;
downloadResult = result;
downloadFileName = fileName;
qDebug() << "UID" << result.id;
void Search::finished()
{
- Trace t("Search::finished");
+ TRACE;
if (!reply) {
return;
void Search::downloadFinished()
{
- Trace t("Search::downloadFinished");
+ TRACE;
if (!downloadReply) {
return;
Search::Query SearchDialog::query()
{
- Trace t("SearchDialog::query");
+ TRACE;
Search::Query ret;
ret.title = title->text();
ret.author = author->text();
void SearchResultsDialog::onItemActivated(const QModelIndex &index)
{
- Trace t("SearchResultsDialog::onItemActivated");
+ TRACE;
Search::Result result = results[index.row()];
qDebug() << "Book" << index.row() << ":" << result.title;
SearchResultInfoDialog *d = new SearchResultInfoDialog(result, this);
QString SearchResultsDialog::downloadName() const
{
- Trace t("SearchResultsDialog::downloadName");
+ TRACE;
QString dir = Platform::downloadDir();
QDir().mkpath(dir); // Not sure if this works. QDir API is quiet lame.
unsigned i = 0;
void SearchResultsDialog::onBeginDownload(int size)
{
Q_UNUSED(size);
- Trace t("SearchResultsDialog::onBeginDownload");
+ TRACE;
progress->showWait();
}
const QString &fileName)
{
Q_UNUSED(result);
- Trace t("SearchResultsDialog::onEndDownload");
+ TRACE;
progress->reset();
if (Search::Ok == status) {
Library::instance()->add(fileName);
#ifndef TRACE_H
#define TRACE_H
+#include <QtGlobal>
#include <QtDebug>
#include <QString>
#include <QTime>
#include <QEvent>
+#define TRACE Trace _(Q_FUNC_INFO)
+
/** Trace helper. */
class Trace
{
AdopterWindow::AdopterWindow(QWidget *parent):
QMainWindow(parent), grabbingZoomKeys(false), mainChild(0)
{
- Trace t("AdopterWindow::AdopterWindow");
+ TRACE;
#ifdef Q_WS_MAEMO_5
setAttribute(Qt::WA_Maemo5StackedWindow, true);
void AdopterWindow::takeChildren(QWidget *main, const QList<QWidget *> &others)
{
- Trace t("AdopterWindow::takeChildren");
+ TRACE;
leaveChildren();
if (main) {
mainChild = main;
void AdopterWindow::leaveChildren()
{
- Trace t("AdopterWindow::leaveChildren");
+ TRACE;
if (mainChild) {
centralWidget()->layout()->removeWidget(mainChild);
mainChild = 0;
void AdopterWindow::grabZoomKeys(bool grab)
{
- Trace t("AdopterWindow::grabZoomKeys");
+ TRACE;
grabbingZoomKeys = grab;
doGrabZoomKeys(grab);
}
void AdopterWindow::showEvent(QShowEvent *e)
{
- Trace t("AdopterWindow::showEvent");
+ TRACE;
doGrabZoomKeys(grabbingZoomKeys);
QMainWindow::showEvent(e);
}
void AdopterWindow::doGrabZoomKeys(bool grab)
{
- Trace t("AdopterWindow::doGrabZoomKeys");
+ TRACE;
#ifdef Q_WS_MAEMO_5
if (!isVisible()) {
qDebug() << "Not visible - skipping";
const QString &iconName,
const QString &text)
{
- Trace t("AdopterWindow::addToolBarAction");
+ TRACE;
qDebug() << "icon" << iconName << "text" << text;
#ifndef Q_OS_SYMBIAN
return toolBar->addAction(QIcon(Platform::icon(iconName)),
\r
QPoint ListView::scrollOffset() const\r
{\r
- Trace t("ListView::scrollOffset");\r
+ TRACE;\r
qDebug() << "0," << offset;\r
return QPoint(0, offset);\r
}\r
\r
void ListView::setScrollOffset(const QPoint &o)\r
{\r
- Trace t("ListView::setScrollOffset");\r
+ TRACE;\r
qDebug() << o;\r
offset = o.y();\r
QListView::scrollContentsBy(0, offset)\r
void ListWindow::addList(ListView *listView)
{
- Trace t("ListWindow::addList");
+ TRACE;
list = listView;
#if defined(Q_WS_MAEMO_5)
list->installEventFilter(this);
const char *slot, const QString &iconName,
QDialogButtonBox::ButtonRole role)
{
- Trace t("ListWindow::addAction");
+ TRACE;
#ifdef Q_WS_MAEMO_5
Q_UNUSED(role);
QPushButton *button =
void ListWindow::addItemAction(const QString &title, QObject *receiver,
const char *slot)
{
- Trace t("ListWindow::addItemAction");
+ TRACE;
#ifdef Q_WS_MAEMO_5
popup->addAction(title, receiver, slot);
#elif defined Q_OS_SYMBIAN
void ListWindow::onModelChanged()
{
- qDebug() << "ListWindow::onModelChanged";
list->setMinimumHeight(list->contentsHeight());
}
void Progress::setProgress(qreal p)
{
- Trace t("Progress::setProgress");
+ TRACE;
qDebug() << p;
if (progress != p) {
progress = p;
ProgressDialog::ProgressDialog(const QString &label, QWidget *parent):
QProgressDialog(label, "", 0, 0, parent)
{
- Trace t("ProgressDialog::ProgressDialog");
+ TRACE;
setMinimumDuration(0);
setWindowModality(Qt::WindowModal);
setCancelButton(0);
#include "translucentbutton.h"
#include "platform.h"
-#include "trace.h"
const int TranslucentButton::pixels = 95;