Make it build on Windows. Fix traces on Windows. Abstract out platform specific actio...
authorAkos Polster <akos@pipacs.com>
Sun, 5 Sep 2010 11:20:33 +0000 (13:20 +0200)
committerAkos Polster <akos@pipacs.com>
Sun, 5 Sep 2010 11:20:33 +0000 (13:20 +0200)
dorian.pro
main.cpp
mainwindow.cpp
mainwindow.h
pkg/changelog
pkg/version.txt
pkg/win32/zlibstat.lib [new file with mode: 0644]
trace.cpp
trace.h
widgets/adopterwindow.cpp
widgets/adopterwindow.h

index afb5290..40de241 100644 (file)
@@ -102,15 +102,17 @@ unix {
         LIBS += -lz
     }
 }
-windows {
-    # FIXME: Build zlib, too
+win32 {
+    DEFINES += ZLIB_WINAPI
+    INCLUDEPATH += $$PWD/model/zlib
+    LIBS += pkg/win32/zlibstat.lib
 }
 symbian {
     # ICON = ...
     TARGET.UID3 = 0xEA633557
     # TARGET.CAPABILITY = ...
     # FIXME: Add OpenC ZLIB?
-    INCLUDE += C:\NokiaQtSDK\Symbian\SDK\src\3rdparty\zlib
+    INCLUDEPATH += C:\NokiaQtSDK\Symbian\SDK\src\3rdparty\zlib
 }
 maemo5 {
     QT += maemo5 dbus
index 57d7dc2..c1c710d 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -1,4 +1,4 @@
-#ifdef Q_OS_UNIX
+#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
 #include <unistd.h>
 #endif
 
@@ -8,24 +8,32 @@
 #include "trace.h"
 #include "settings.h"
 
+static const char *DORIAN_VERSION =
+#include "pkg/version.txt"
+;
+
 int main(int argc, char *argv[])
 {
     QApplication a(argc, argv);
-    a.setApplicationName("Dorian");
-    a.setApplicationVersion("0.0.1");
-    a.setOrganizationDomain("pipacs.com");
-    a.setOrganizationName("Pipacs");
 
     Trace::level = (QtMsgType)Settings::instance()->
         value("tracelevel", (int)QtWarningMsg).toInt();
     qInstallMsgHandler(Trace::messageHandler);
 
+    a.setApplicationName("Dorian");
+    a.setApplicationVersion(DORIAN_VERSION);
+    a.setOrganizationDomain("pipacs.com");
+    a.setOrganizationName("Pipacs");
+
+#ifdef Q_OS_SYMBIAN
+    // Remove context menu from all widgets
+    foreach (QWidget *w, QApplication::allWidgets()) {
+        w->setContextMenuPolicy(Qt::NoContextMenu);
+    }
+#endif // Q_OS_SYMBIAN
+
     MainWindow w;
-#ifdef Q_WS_S60
-    w.showMaximized();
-#else
     w.show();
-#endif
 
     int ret = a.exec();
     if (ret == 1000) {
index b049ab7..a872f28 100755 (executable)
@@ -44,7 +44,7 @@
 #endif
 
 const int PROGRESS_HEIGHT = 17;
-const char *DORIAN_VERSION =
+static const char *DORIAN_VERSION =
 #include "pkg/version.txt"
 ;
 
@@ -73,22 +73,19 @@ MainWindow::MainWindow(QWidget *parent):
     // Progress
     progress = new Progress(central);
 
-    // Tool bar
-
-    setUnifiedTitleAndToolBarOnMac(true);
+    // Settings dialog
     settings = new QDialog(this);
-    toolBar = addToolBar("controls");
-    toolBar->setMovable(false);
-    toolBar->setFloatable(false);
-    toolBar->toggleViewAction()->setVisible(false);
-#if defined(Q_WS_X11) && !defined(Q_WS_MAEMO_5)
-    toolBar->setIconSize(QSize(42, 42));
-#endif
 
-    chaptersAction = addToolBarAction(this, SLOT(showChapters()), "chapters");
-    bookmarksAction = addToolBarAction(this, SLOT(showBookmarks()), "bookmarks");
-    infoAction = addToolBarAction(this, SLOT(showInfo()), "info");
-    libraryAction = addToolBarAction(this, SLOT(showLibrary()), "library");
+    // Tool bar actions
+
+    chaptersAction = addToolBarAction(this, SLOT(showChapters()),
+                                      "chapters", tr("Chapters"));
+    bookmarksAction = addToolBarAction(this, SLOT(showBookmarks()),
+                                       "bookmarks", tr("Bookmarks"));
+    infoAction = addToolBarAction(this, SLOT(showInfo()),
+                                  "info", tr("Book info"));
+    libraryAction = addToolBarAction(this, SLOT(showLibrary()),
+                                     "library", tr("Library"));
 
 #ifdef Q_WS_MAEMO_5
     settingsAction = menuBar()->addAction(tr("Settings"));
@@ -99,9 +96,10 @@ MainWindow::MainWindow(QWidget *parent):
     connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
 #else
     settingsAction = addToolBarAction(this, SLOT(showSettings()),
-                                      "preferences-system");
-    devToolsAction = addToolBarAction(this, SLOT(showDevTools()), "developer");
-    addToolBarAction(this, SLOT(about()), "about");
+                                      "preferences-system", tr("Settings"));
+    devToolsAction = addToolBarAction(this, SLOT(showDevTools()),
+                                      "developer", tr("Developer"));
+    addToolBarAction(this, SLOT(about()), "about", tr("About"));
 #endif // Q_WS_MAEMO_5
 
     QFrame *frame = new QFrame(toolBar);
@@ -109,7 +107,7 @@ MainWindow::MainWindow(QWidget *parent):
     toolBar->addWidget(frame);
 
     fullScreenAction = addToolBarAction(this, SLOT(showBig()),
-                                        "view-fullscreen");
+                                        "view-fullscreen", tr("Full screen"));
 
     // Buttons on top of the book view
     previousButton = new TranslucentButton("back", this);
@@ -239,14 +237,6 @@ void MainWindow::setCurrentBook(const QModelIndex &current)
     setWindowTitle(book? book->shortName(): tr("Dorian"));
 }
 
-QAction *MainWindow::addToolBarAction(const QObject *receiver,
-                                      const char *member,
-                                      const QString &name)
-{
-    return toolBar->
-        addAction(QIcon(ICON_PREFIX + name + ".png"), "", receiver, member);
-}
-
 void MainWindow::showLibrary()
 {
     (new LibraryDialog(this))->show();
index 5995075..dc75edf 100755 (executable)
@@ -49,8 +49,6 @@ protected:
 
 private:
     void setCurrentBook(const QModelIndex &current);
-    QAction *addToolBarAction(const QObject *receiver, const char *member,
-                              const QString &name);
     BookView *view;
     QAction *settingsAction;
     QAction *libraryAction;
@@ -61,7 +59,6 @@ private:
     QAction *forwardAction;
     QAction *backwardAction;
     QAction *chaptersAction;
-    QToolBar *toolBar;
     QDialog *settings;
     DevTools *devTools;
     QModelIndex mCurrent;
index 4bd622b..8577696 100644 (file)
@@ -1,10 +1,18 @@
+dorian (0.2.0-1) unstable; urgency=low
+
+  * Add support for Windows
+  * Add support for Symbian
+  * Fix tracing on Windows
+
+ -- Akos Polster <akos@pipacs.com>  Sun,  5 Sep 2010 02:00:00 +0200
+
 dorian (0.1.7-1) unstable; urgency=low
 
   * Navigate through pages instead of book parts
   * Move some menu items to the toolbar
   * Don't show buttons in current book's information dialog
 
- -- Akos Polster <akos@pipacs.com>  Wed,  1 Aug 2010 02:00:00 +0200
+ -- Akos Polster <akos@pipacs.com>  Wed,  1 Sep 2010 02:00:00 +0200
 
 dorian (0.1.6-1) unstable; urgency=low
 
index 964e6ec..0a25d5a 100644 (file)
@@ -1 +1 @@
-"0.1.7"
+"0.2.0"
diff --git a/pkg/win32/zlibstat.lib b/pkg/win32/zlibstat.lib
new file mode 100644 (file)
index 0000000..88e3958
Binary files /dev/null and b/pkg/win32/zlibstat.lib differ
index f3a2bef..f762b19 100644 (file)
--- a/trace.cpp
+++ b/trace.cpp
@@ -256,28 +256,23 @@ QString Trace::event(QEvent::Type t)
     }
 }
 
-const char *Trace::prefix()
+QString Trace::prefix()
 {
-    return (QTime::currentTime().toString("hh:mm:ss.zzz ") +
-        QString(" ").repeated(indent)).toAscii().constData();
+    return QTime::currentTime().toString("hh:mm:ss.zzz ") +
+            QString(" ").repeated(indent);
 }
 
 void Trace::messageHandler(QtMsgType type, const char *msg)
 {
     if (type >= Trace::level) {
+        QtMsgHandler oldHandler = qInstallMsgHandler(0);
         switch (type) {
         case QtDebugMsg:
-            fprintf(stderr, "%s%s\n", prefix(), msg);
+            qt_message_output(QtDebugMsg, (prefix()+msg).toUtf8().constData());
             break;
-        case QtWarningMsg:
-            fprintf(stderr, "Warning: %s\n", msg);
-            break;
-        case QtCriticalMsg:
-            fprintf(stderr, "Critical: %s\n", msg);
-            break;
-        case QtFatalMsg:
-            fprintf(stderr, "Fatal: %s\n", msg);
-            abort();
+        default:
+            qt_message_output(type, msg);
         }
+        qInstallMsgHandler(oldHandler);
     }
 }
diff --git a/trace.h b/trace.h
index 232e2f3..843be64 100644 (file)
--- a/trace.h
+++ b/trace.h
@@ -17,7 +17,7 @@ public:
     static QtMsgType level;
 
 protected:
-    static const char *prefix();
+    static QString prefix();
     QString name;
     static int indent;
     typedef struct {int type; const char *name;} EventName;
index 3aa4827..844ebf0 100644 (file)
@@ -9,6 +9,12 @@
 #include "adopterwindow.h"
 #include "trace.h"
 
+#ifdef Q_WS_MAC
+#   define ICON_PREFIX ":/icons/mac/"
+#else
+#   define ICON_PREFIX ":/icons/"
+#endif
+
 AdopterWindow::AdopterWindow(QWidget *parent):
         QMainWindow(parent), grabbingZoomKeys(false), mainChild(0)
 {
@@ -21,6 +27,18 @@ AdopterWindow::AdopterWindow(QWidget *parent):
     layout->setMargin(0);
     frame->setLayout(layout);
     setCentralWidget(frame);
+
+#ifndef Q_OS_SYMBIAN
+    // Tool bar
+    setUnifiedTitleAndToolBarOnMac(true);
+    toolBar = addToolBar("controls");
+    toolBar->setMovable(false);
+    toolBar->setFloatable(false);
+    toolBar->toggleViewAction()->setVisible(false);
+#if defined(Q_WS_X11) && !defined(Q_WS_MAEMO_5)
+    toolBar->setIconSize(QSize(42, 42));
+#endif
+#endif // Q_OS_SYMBIAN
 }
 
 void AdopterWindow::takeChildren(QWidget *main, const QList<QWidget *> &others)
@@ -92,3 +110,29 @@ void AdopterWindow::doGrabZoomKeys(bool grab)
     Q_UNUSED(grab);
 #endif // Q_WS_MAEMO_5
 }
+
+void AdopterWindow::show()
+{
+#ifdef Q_OS_SYMBIAN
+    showMaximized();
+#else
+    QMainWindow::show();
+#endif
+}
+
+QAction *AdopterWindow::addToolBarAction(QObject *receiver,
+                                         const char *member,
+                                         const QString &iconName,
+                                         const QString &text)
+{
+#ifndef Q_OS_SYMBIAN
+    return toolBar->addAction(QIcon(ICON_PREFIX + iconName + ".png"), text,
+                              receiver, member);
+#else
+    Q_UNUSED(iconName);
+    QAction *action = new QAction(text, this);
+    menuBar()->addAction(action);
+    connect(action, SIGNAL(triggered()), receiver, member);
+    return action;
+#endif
+}
index 9818acf..55a4011 100644 (file)
@@ -5,6 +5,8 @@
 #include <QList>
 
 class QWidget;
+class QToolBar;
+class QAction;
 
 /**
   * A main window that can adopt other windows' children, and grabs the
@@ -19,6 +21,23 @@ public:
     void takeChildren(QWidget *main, const QList<QWidget *> &others);
     void leaveChildren();
 
+    /**
+     * Add action that is visible on the tool bar (except on Symbian, where
+     * it is visible on the Options menu.
+     */
+    QAction *addToolBarAction(QObject *receiver, const char *slot,
+                              const QString &iconName, const QString &text);
+
+    /** Add space. */
+    void addToolBarSpace();
+
+    /** Add action that is visible on the menu. */
+    QAction *addAction(QObject *receiver, const char *slot,
+                       const QString &text);
+
+    /** Show window. */
+    void show();
+
 signals:
 
 public slots:
@@ -28,6 +47,7 @@ protected:
     void doGrabZoomKeys(bool grab);
     bool grabbingZoomKeys;
     QWidget *mainChild;
+    QToolBar *toolBar;
 };
 
 #endif // ADOPTERWINDOW_H