Fix forward navigation control on Linux.
[dorian] / platform.cpp
index ee7f5d9..1681638 100644 (file)
@@ -6,7 +6,15 @@
 #   include <unistd.h>
 #endif
 
+#ifdef Q_OS_SYMBIAN
+#   include <eikenv.h>
+#   include <eikappui.h>
+#   include <aknenv.h>
+#   include <aknappui.h>
+#endif
+
 #include "platform.h"
+#include "trace.h"
 
 #if defined(Q_OS_WIN32) || defined(Q_OS_SYMBIAN)
 #   define DORIAN_BASE "dorian"
@@ -18,6 +26,8 @@
 #   define DORIAN_ICON_PREFIX ":/icons/mac/"
 #elif defined(Q_OS_SYMBIAN)
 #   define DORIAN_ICON_PREFIX ":/icons/symbian/"
+#elif defined(Q_WS_MAEMO_5)
+#   define DORIAN_ICON_PREFIX ":/icons/maemo/"
 #else
 #   define DORIAN_ICON_PREFIX ":/icons/"
 #endif
@@ -56,13 +66,13 @@ QString Platform::dbPath()
     return QDir(base).absoluteFilePath("books.db");
 }
 
-QString Platform::icon(const QString &name)
+QString Platform::icon(const QString &name, const QString &extension)
 {
-    QString iconName = QString(DORIAN_ICON_PREFIX) + name + ".png";
+    QString iconName = QString(DORIAN_ICON_PREFIX) + name + extension;
     if (QFile(iconName).exists()) {
         return iconName;
     } else {
-        return QString(":/icons/") + name + ".png";
+        return QString(":/icons/") + name + extension;
     }
 }
 
@@ -145,3 +155,75 @@ QString Platform::defaultOrientation()
     return QString("landscape");
 #endif
 }
+
+void Platform::setOrientation(QWidget *widget, const QString &orientation)
+{
+    TRACE;
+    qDebug() << "To" << orientation;
+
+    Q_UNUSED(widget);
+
+#if defined(Q_OS_SYMBIAN)
+    CAknAppUi *appUi = dynamic_cast<CAknAppUi *>(CEikonEnv::Static()->AppUi());
+    if (!appUi) {
+        qCritical() << "Platform::setOrientation: Couldn't get AppUi pointer";
+        return;
+    }
+#endif
+
+    if (orientation == "portrait") {
+#if defined(Q_WS_MAEMO_5)
+        widget->setAttribute(Qt::WA_Maemo5LandscapeOrientation, false);
+        widget->setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
+#elif defined(Q_OS_SYMBIAN)
+        TRAPD(error,
+              appUi->SetOrientationL(CAknAppUi::EAppUiOrientationPortrait););
+#endif
+    } else {
+#if defined(Q_WS_MAEMO_5)
+        widget->setAttribute(Qt::WA_Maemo5PortraitOrientation, false);
+        widget->setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
+#elif defined(Q_OS_SYMBIAN)
+        TRAPD(error,
+              appUi->SetOrientationL(CAknAppUi::EAppUiOrientationLandscape););
+#endif
+    }
+}
+
+int Platform::softKeyHeight()
+{
+#if defined(Q_OS_SYMBIAN)
+    return 62;
+#else
+    return 0;
+#endif
+}
+
+int Platform::toolBarIconHeight()
+{
+#if defined(Q_OS_SYMBIAN)
+    return 60;
+#elif defined(Q_WS_X11)  && !defined(Q_WS_MAEMO_5)
+    return 40;
+#else
+    return 0;
+#endif
+}
+
+QSize Platform::size()
+{
+    return QApplication::desktop()->geometry().size();
+}
+
+QSize Platform::availableSize()
+{
+    QSize s = QApplication::desktop()->availableGeometry().size();
+#if defined(Q_OS_SYMBIAN)
+    // Work around a Qt bug on Symbian which sometimes forgets to reduce the
+    // available height by the soft key area height
+    if (s.height() == 548) {
+        s.setHeight(s.height() - softKeyHeight());
+    }
+#endif
+    return s;
+}