Enable tracing to file. Attempt to fix last position restoration on S^3.
authorAkos Polster <akos@pipacs.com>
Sun, 7 Nov 2010 20:25:03 +0000 (21:25 +0100)
committerAkos Polster <akos@pipacs.com>
Sun, 7 Nov 2010 20:25:03 +0000 (21:25 +0100)
13 files changed:
bookview.cpp
bookview.h
devtools.cpp
devtools.h
dorian.pro
main.cpp
pkg/changelog
platform.cpp
platform.h
trace.cpp
trace.h
widgets/translucentbutton.cpp
widgets/translucentbutton.h

index a00f4b0..387a767 100644 (file)
@@ -16,9 +16,9 @@
 #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;
 
@@ -48,8 +48,6 @@ BookView::BookView(QWidget *parent): QWebView(parent), contentIndex(-1), mBook(0
     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)
@@ -166,8 +164,9 @@ void BookView::setLastBookmark()
 {
     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);
@@ -236,6 +235,22 @@ void BookView::onLoadFinished(bool ok)
     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();
 }
@@ -278,7 +293,9 @@ void BookView::paintEvent(QPaintEvent *e)
     }
 
     // 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()) {
@@ -383,21 +400,6 @@ void BookView::addJavaScriptObjects()
     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)
@@ -421,6 +423,7 @@ void BookView::enterEvent(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();
@@ -431,6 +434,7 @@ void BookView::goToPosition(qreal position)
 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));
index bc2cf3f..e3d6597 100644 (file)
@@ -40,7 +40,10 @@ public:
     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. */
@@ -56,21 +59,24 @@ public slots:
     /** 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. */
@@ -112,7 +118,6 @@ protected:
     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)
index 12538bb..73ecb0d 100644 (file)
@@ -5,6 +5,7 @@
 #include "settings.h"
 #include "toolbuttonbox.h"
 #include "bookdb.h"
+#include "platform.h"
 
 DevTools::DevTools(QWidget *parent): Dyalog(parent, false)
 {
@@ -25,6 +26,13 @@ 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();
 }
 
@@ -41,7 +49,15 @@ void DevTools::onClear()
     }
 }
 
-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);
+}
index 650c612..d0439c8 100644 (file)
@@ -16,6 +16,7 @@ public:
 public slots:
     void onClear();
     void onLevelButtonClicked(int level);
+    void onTraceToFileToggled(bool enable);
 };
 
 #endif // DEVTOOLS_H
index 56489aa..9ae4fe7 100644 (file)
@@ -134,11 +134,12 @@ win32 {
 \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
index 3bd45d9..8cd02b2 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -28,24 +28,30 @@ static const QtMsgType DORIAN_DEFAULT_TRACE_LEVEL =
 
 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
index 60026e5..8344c86 100644 (file)
@@ -4,6 +4,8 @@ dorian (0.3.4-1) unstable; urgency=low
   * 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
 
index f72a073..24ceed9 100644 (file)
@@ -25,6 +25,8 @@ static const char *DORIAN_VERSION =
 #include "pkg/version.txt"
 ;
 
+#define DORIAN_LOG "dorian.txt"
+
 #ifdef Q_WS_MAEMO_5
 #   include <QtMaemo5/QMaemo5InformationBox>
 #else
@@ -100,3 +102,8 @@ void Platform::showBusy(QWidget *w, bool isBusy)
     Q_UNUSED(isBusy);
 #endif
 }
+
+QString Platform::traceFileName()
+{
+    return QDir::home().absoluteFilePath(DORIAN_LOG);
+}
index 6c8ddef..47ce0d1 100644 (file)
@@ -17,6 +17,7 @@ public:
     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
index d6d4992..d0b7a04 100644 (file)
--- a/trace.cpp
+++ b/trace.cpp
@@ -1,11 +1,11 @@
-#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"},
@@ -273,5 +273,22 @@ void Trace::messageHandler(QtMsgType type, const char *msg)
             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();
+}
diff --git a/trace.h b/trace.h
index bd5acfc..870bd87 100644 (file)
--- a/trace.h
+++ b/trace.h
@@ -6,6 +6,7 @@
 #include <QString>
 #include <QTime>
 #include <QEvent>
+#include <QFile>
 
 #ifdef Q_OS_SYMBIAN
 #   ifdef __PRETTY_FUNCTION__
@@ -26,6 +27,8 @@ public:
     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();
@@ -33,6 +36,7 @@ protected:
     static int indent;
     typedef struct {int type; const char *name;} EventName;
     static EventName eventTab[];
+    static QFile file;
 };
 
 #endif // TRACE_H
index f6cfb0c..7976dff 100644 (file)
@@ -10,9 +10,6 @@ TranslucentButton::TranslucentButton(const QString &name_, QWidget *parent):
     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);
 }
 
@@ -40,7 +37,7 @@ void TranslucentButton::flash(int duration)
     raise();
     transparent = false;
     update();
-    timer->start(duration);
+    QTimer::singleShot(duration, this, SLOT(stopFlash()));
 }
 
 void TranslucentButton::stopFlash()
index e1a1ca6..5e26707 100644 (file)
@@ -38,7 +38,6 @@ protected:
 private:
     QString name;
     bool transparent;
-    QTimer *timer;
     int elevatorTimer;
 };