#include "progressdialog.h"
#include "platform.h"
-BookView::BookView(QWidget *parent): QWebView(parent), contentIndex(-1), mBook(0),
- restorePositionAfterLoad(false), positionAfterLoad(0), loaded(false),
- contentsHeight(0), grabbingVolumeKeys(false)
+BookView::BookView(QWidget *parent): QWebView(parent), contentIndex(-1),
+ mBook(0), restorePositionAfterLoad(false), positionAfterLoad(0),
+ loaded(false), grabbingVolumeKeys(false)
{
TRACE;
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool)));
connect(frame, SIGNAL(javaScriptWindowObjectCleared()),
this, SLOT(addJavaScriptObjects()));
- connect(frame, SIGNAL(contentsSizeChanged(const QSize &)),
- this, SLOT(onContentsSizeChanged(const QSize &)));
// Suppress unwanted text selections on Maemo and Symbian
#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
{
TRACE;
if (mBook) {
- int height = contentsHeight;
- int pos = page()->mainFrame()->scrollPosition().y();
+ QWebFrame *frame = page()->mainFrame();
+ int height = frame->contentsSize().height();
+ int pos = frame->scrollPosition().y();
qDebug() << QString("At %1 (%2%, height %3)").
arg(pos).arg((qreal)pos / (qreal)height * 100).arg(height);
mBook->setLastBookmark(contentIndex, (qreal)pos / (qreal)height);
onSettingsChanged("scheme");
onSettingsChanged("zoom");
onSettingsChanged("font");
+
+ QTimer::singleShot(210, this, SLOT(restoreAfterLoad()));
+}
+
+void BookView::restoreAfterLoad()
+{
+ if (restoreFragmentAfterLoad) {
+ qDebug() << "Restorint to fragment" << fragmentAfterLoad;
+ goToFragment(fragmentAfterLoad);
+ restoreFragmentAfterLoad = false;
+ } else if (restorePositionAfterLoad) {
+ qDebug() << "Restoring to position" << positionAfterLoad;
+ goToPosition(positionAfterLoad);
+ restorePositionAfterLoad = false;
+ }
+
emit partLoadEnd(contentIndex);
showProgress();
}
}
// Paint bookmarks
- QPoint scrollPos = page()->mainFrame()->scrollPosition();
+ QWebFrame *frame = page()->mainFrame();
+ int contentsHeight = frame->contentsSize().height();
+ QPoint scrollPos = frame->scrollPosition();
QPixmap bookmarkPixmap = QPixmap::fromImage(bookmarkImage);
QPainter painter(this);
foreach (Book::Bookmark b, mBook->bookmarks()) {
page()->mainFrame()->addToJavaScriptWindowObject("bv", this);
}
-void BookView::onContentsSizeChanged(const QSize &size)
-{
- TRACE;
- contentsHeight = size.height();
- if (restoreFragmentAfterLoad) {
- qDebug() << "Restorint to fragment" << fragmentAfterLoad;
- goToFragment(fragmentAfterLoad);
- } else if (restorePositionAfterLoad) {
- qDebug() << "Restoring to position";
- goToPosition(positionAfterLoad);
- }
- restorePositionAfterLoad = false;
- restoreFragmentAfterLoad = false;
-}
-
#ifdef Q_WS_MAEMO_5
void BookView::leaveEvent(QEvent *e)
void BookView::goToPosition(qreal position)
{
+ int contentsHeight = page()->mainFrame()->contentsSize().height();
int scrollPos = (int)((qreal)contentsHeight * position);
page()->mainFrame()->setScrollPosition(QPoint(0, scrollPos));
// FIXME: update();
void BookView::showProgress()
{
if (mBook) {
+ int contentsHeight = page()->mainFrame()->contentsSize().height();
qreal pos = (qreal)(page()->mainFrame()->scrollPosition().y()) /
(qreal)contentsHeight;
emit progress(mBook->getProgress(contentIndex, pos));
void grabVolumeKeys(bool grab);
signals:
+ /** Part loading started. */
void partLoadStart(int index);
+
+ /** Part loading finished. */
void partLoadEnd(int index);
/** Signal button press, when the real event has been suppressed. */
/** Go to previous part. */
void goNext();
+ /** Actions to perform after URL loading finished. */
void onLoadFinished(bool ok);
+
+ /** Handle settings changes. */
void onSettingsChanged(const QString &key);
/** Add QObjects to the main frame. */
void addJavaScriptObjects();
- /** Handle main frame contents size changes. */
- void onContentsSizeChanged(const QSize &size);
-
/** Go to previous page. */
void goPreviousPage();
/** Go to next page. */
void goNextPage();
+ /** Restore saved position after URL loading finished. */
+ void restoreAfterLoad();
+
protected slots:
#ifdef Q_OS_SYMBIAN
/** Observe media keys. */
QImage bookmarkImage; /**< Bookmark icon pre-loaded. */
bool loaded; /**< True, if content has been loaded. */
bool mousePressed; /**< Event filter's mouse button state. */
- int contentsHeight; /**< Last know height of the frame. */
bool grabbingVolumeKeys;/**< True, if volume keys should be grabbed. */
#if defined(Q_WS_MAEMO_5) || defined(Q_OS_SYMBIAN)
#include "settings.h"
#include "toolbuttonbox.h"
#include "bookdb.h"
+#include "platform.h"
DevTools::DevTools(QWidget *parent): Dyalog(parent, false)
{
box->toggle(Trace::level);
connect(box, SIGNAL(buttonClicked(int)),
this, SLOT(onLevelButtonClicked(int)));
+
+ QCheckBox *traceToFile = new QCheckBox(tr("Trace to file"), this);
+ addWidget(traceToFile);
+ traceToFile->setChecked(!Trace::fileName().isEmpty());
+ connect(traceToFile, SIGNAL(toggled(bool)),
+ this, SLOT(onTraceToFileToggled(bool)));
+
addStretch();
}
}
}
-void DevTools::onLevelButtonClicked(int level) {
+void DevTools::onLevelButtonClicked(int level)
+{
Trace::level = (QtMsgType)level;
Settings::instance()->setValue("tracelevel", level);
}
+
+void DevTools::onTraceToFileToggled(bool enable)
+{
+ QString name = enable? Platform::traceFileName(): QString();
+ Trace::setFileName(name);
+ Settings::instance()->setValue("tracefilename", name);
+}
public slots:
void onClear();
void onLevelButtonClicked(int level);
+ void onTraceToFileToggled(bool enable);
};
#endif // DEVTOOLS_H
\r
symbian {\r
TARGET = Dorian\r
- TARGET.UID3 = 0xEA633557\r
- TARGET.CAPABILITY = UserEnvironment NetworkServices ReadUserData WriteUserData SwEvent\r
+ TARGET.UID3 = 0xA89FC85B\r
+ TARGET.CAPABILITY = UserEnvironment NetworkServices ReadUserData \\r
+ WriteUserData SwEvent\r
TARGET.EPOCHEAPSIZE = 0x080000 0x4000000\r
ICON = $$PWD/pkg/symbian/book.svg\r
- packageheader = "$${LITERAL_HASH}{\"Dorian\"}, (0xEA633557), 0, 3, 4"\r
+ packageheader = "$${LITERAL_HASH}{\"Dorian\"}, (0xA89FC85B), 0, 3, 4"\r
vendorinfo = \\r
"%{\"Nokia Betalabs \"}" \\r
":\"Nokia Betalabs \""\r
int main(int argc, char *argv[])
{
- QApplication a(argc, argv);
int ret;
+ // Set up application
+ QApplication a(argc, argv);
a.setApplicationName("Dorian");
a.setApplicationVersion(DORIAN_VERSION);
a.setOrganizationDomain("pipacs.com");
a.setOrganizationName("Pipacs");
- Trace::level = (QtMsgType)Settings::instance()->
+ // Initialize tracing
+ Settings *settings = Settings::instance();
+ Trace::level = (QtMsgType)settings->
value("tracelevel", (int)DORIAN_DEFAULT_TRACE_LEVEL).toInt();
+ Trace::setFileName(settings->value("tracefilename").toString());
qInstallMsgHandler(Trace::messageHandler);
#ifdef Q_OS_SYMBIAN
+ // Show splash screen
Splash *splash = new Splash();
splash->showFullScreen();
a.processEvents();
#endif
+ // Create main window, run event loop
{
MainWindow w;
#ifdef Q_OS_SYMBIAN
* Navigate with volume keys on Symbian, too
* Speed up startup, load books on demand
* Show splash screen on Symbian
+ * Fix restoring last position on Symbian
+ * Use proper UID on Symbian
-- Akos Polster <akos@pipacs.com> Fri, 5 Nov 2010 02:00:00 +0100
#include "pkg/version.txt"
;
+#define DORIAN_LOG "dorian.txt"
+
#ifdef Q_WS_MAEMO_5
# include <QtMaemo5/QMaemo5InformationBox>
#else
Q_UNUSED(isBusy);
#endif
}
+
+QString Platform::traceFileName()
+{
+ return QDir::home().absoluteFilePath(DORIAN_LOG);
+}
static QString defaultFont();
static void information(const QString &label, QWidget *parent = 0);
static void showBusy(QWidget *w, bool isBusy);
+ static QString traceFileName();
};
#endif // PLATFORM_H
-#include <stdio.h>
-#include <stdlib.h>
#include <QEvent>
+#include <QFile>
#include "trace.h"
int Trace::indent;
QtMsgType Trace::level = QtDebugMsg;
+QFile Trace::file;
Trace::EventName Trace::eventTab[] = {
{QEvent::None, "QEvent::None"},
qt_message_output(type, msg);
}
qInstallMsgHandler(oldHandler);
+ if (Trace::file.isOpen()) {
+ Trace::file.write((prefix() + msg).toUtf8());
+ }
+ }
+}
+
+void Trace::setFileName(const QString &fileName)
+{
+ Trace::file.close();
+ Trace::file.setFileName(fileName);
+ if (!fileName.isEmpty()) {
+ (void)Trace::file.open(QIODevice::WriteOnly);
}
}
+
+QString Trace::fileName()
+{
+ return Trace::file.fileName();
+}
#include <QString>
#include <QTime>
#include <QEvent>
+#include <QFile>
#ifdef Q_OS_SYMBIAN
# ifdef __PRETTY_FUNCTION__
static QString event(QEvent::Type t);
static void messageHandler(QtMsgType type, const char *msg);
static QtMsgType level;
+ static void setFileName(const QString &fileName);
+ static QString fileName();
protected:
static QString prefix();
static int indent;
typedef struct {int type; const char *name;} EventName;
static EventName eventTab[];
+ static QFile file;
};
#endif // TRACE_H
QLabel(parent), name(name_), transparent(true)
{
setGeometry(0, 0, pixels, pixels);
- timer = new QTimer(this);
- timer->setSingleShot(true);
- connect(timer, SIGNAL(timeout()), this, SLOT(stopFlash()));
elevatorTimer = startTimer(elevatorInterval);
}
raise();
transparent = false;
update();
- timer->start(duration);
+ QTimer::singleShot(duration, this, SLOT(stopFlash()));
}
void TranslucentButton::stopFlash()
private:
QString name;
bool transparent;
- QTimer *timer;
int elevatorTimer;
};