Initial changes for sailfish port
authorLuciano Montanaro <mikelima@cirulla.net>
Sun, 29 Sep 2013 21:17:45 +0000 (23:17 +0200)
committerLuciano Montanaro <mikelima@cirulla.net>
Sun, 29 Sep 2013 21:17:45 +0000 (23:17 +0200)
application/dataprovider.cpp
application/main.cpp
application/settings.cpp
application/stationlistmodel.cpp
application/stationlistmodel.h
application/stationlistproxymodel.cpp
application/stationlistproxymodel.h
application/view.cpp
application/view.h

index 8d19c13..44e4844 100644 (file)
@@ -28,9 +28,11 @@ Boston, MA 02110-1301, USA.
 #include <QNetworkReply>
 #include <QNetworkRequest>
 #include <QSharedPointer>
+#if 0
 #include <QWebElement>
 #include <QWebFrame>
 #include <QWebPage>
+#endif
 
 // Constants
 static const int RECENT_STATIONS_MAX_COUNT = 10;
index 29a4fdf..d26db6f 100644 (file)
@@ -19,12 +19,17 @@ Boston, MA 02110-1301, USA.
 
 */
 
+#ifdef TARGET_PLATFORM_FREMANTLE
 #include "app.h"
-#ifndef TARGET_PLATFORM_FREMANTLE
+#else
 #include "view.h"
 #endif
 
+#ifdef TARGET_PLATFORM_SAILFISH
+#include <QtGui/QGuiApplication>
+#else
 #include <QtGui/QApplication>
+#endif
 #include <QDir>
 #include <QDebug>
 #include <QLocale>
@@ -40,7 +45,9 @@ Boston, MA 02110-1301, USA.
 
 Q_DECL_EXPORT int main(int argc, char *argv[])
 {
-#ifdef TARGET_PLATFORM_HARMATTAN
+#ifdef TARGET_PLATFORM_SAILFISH
+    QScopedPointer< QGuiApplication > a(new QGuiApplication(argc, argv));
+#elif TARGET_PLATFORM_HARMATTAN
     QScopedPointer< QApplication > a(MDeclarativeCache::qApplication(argc, argv));
 #else
     QScopedPointer< QApplication > a(new QApplication(argc, argv));
index 654dcaa..2c59793 100644 (file)
@@ -21,7 +21,7 @@ Boston, MA 02110-1301, USA.
 
 #include "settings.h"
 
-#include <QApplication>
+#include <QCoreApplication>
 #include <QDebug>
 #include <QSettings>
 #include <QStringList>
index 36cec14..335e004 100644 (file)
@@ -25,20 +25,30 @@ Boston, MA 02110-1301, USA.
 #include <QFileInfo>
 #include <QDebug>
 #include <QStandardItem>
+#ifndef TARGET_PLATFORM_SAILFISH
 #include <QGeoCoordinate>
+#endif
 
+#ifndef TARGET_PLATFORM_SAILFISH
 QTM_USE_NAMESPACE
 Q_DECLARE_METATYPE(QGeoCoordinate)
+#endif
+
+static QHash<int, QByteArray> roles;
 
 StationListModel::StationListModel(QObject *parent) :
     QStandardItemModel(parent)
 {
     setRowCount(0);
+#ifndef TARGET_PLATFORM_SAILFISH
     QHash<int, QByteArray> roles;
+#endif
     roles[Qt::DisplayRole] = "name";
     roles[StationListModel::PositionRole] = "position";
     roles[StationListModel::StationCodeRole] = "code";
+#ifndef TARGET_PLATFORM_SAILFISH
     setRoleNames(roles);
+#endif
 }
 
 bool StationListModel::load(const QString &filename)
@@ -81,6 +91,11 @@ bool StationListModel::load(const QString &filename)
     return true;
 }
 
+QHash<int, QByteArray> StationListModel::roleNames() const
+{
+    return roles;
+}
+
 void StationListModel::readStationsElement()
 {
     m_reader.readNext();
@@ -128,8 +143,10 @@ void StationListModel::readStationElement()
 void StationListModel::readPosElement(QStandardItem *item)
 {
     QStringList coordinates = m_reader.readElementText().split(",");
+#ifndef TARGET_PLATFORM_SAILFISH
     QGeoCoordinate pos = QGeoCoordinate(coordinates[0].toDouble(), coordinates[1].toDouble());
     item->setData(QVariant::fromValue(pos), PositionRole);
+#endif
     m_reader.readElementText();
     if (m_reader.isEndElement()) {
         m_reader.readNext();
index b497fb5..7913e06 100644 (file)
@@ -43,6 +43,8 @@ public:
 
     bool load(const QString &filename);
 
+    QHash<int, QByteArray> roleNames() const;
+
 signals:
 
 public slots:
index 3a693cd..fe613c2 100644 (file)
@@ -25,16 +25,20 @@ Boston, MA 02110-1301, USA.
 #include "stationlistmodel.h"
 
 #include <QDebug>
+#ifndef TARGET_PLATFORM_SAILFISH
 #include <QGeoCoordinate>
 
 QTM_USE_NAMESPACE
 
 Q_DECLARE_METATYPE(QGeoCoordinate)
+#endif
 
 StationListProxyModel::StationListProxyModel(QObject *parent) :
     QSortFilterProxyModel(parent),
+#ifndef TARGET_PLATFORM_SAILFISH
     positionInfoSource(QGeoPositionInfoSource::createDefaultSource(this)),
     m_here(44.5, 9.0),
+#endif
     m_filterRecentOnly(false)
 {
     Settings *settings = Settings::instance();
@@ -42,6 +46,7 @@ StationListProxyModel::StationListProxyModel(QObject *parent) :
     setFilterCaseSensitivity(Qt::CaseInsensitive);
     setSortCaseSensitivity(Qt::CaseInsensitive);
     setDynamicSortFilter(true);
+#ifndef TARGET_PLATFORM_SAILFISH
     if (positionInfoSource) {
         qDebug() << "position info source available";
         connect(positionInfoSource, SIGNAL(positionUpdated(QGeoPositionInfo)),
@@ -50,6 +55,7 @@ StationListProxyModel::StationListProxyModel(QObject *parent) :
     } else {
         qDebug() << "No position info source available";
     }
+#endif
     connect(settings, SIGNAL(recentStationsChanged()),
             this, SLOT(updateRecentStations()));
     updateRecentStations();
@@ -61,9 +67,13 @@ bool StationListProxyModel::lessThan(const QModelIndex &left,
     int role = sortRole();
 
     if (role == StationListModel::PositionRole) {
+#ifdef TARGET_PLATFORM_SAILFISH
+        return 0;
+#else
         QGeoCoordinate first = left.data(role).value<QGeoCoordinate>();
         QGeoCoordinate second = right.data(role).value<QGeoCoordinate>();
        return first.distanceTo(m_here) < second.distanceTo(m_here);
+#endif
     } else {
         return QString::compare(left.data(role).toString(),
                                 right.data(role).toString(),
@@ -71,6 +81,8 @@ bool StationListProxyModel::lessThan(const QModelIndex &left,
     }
 }
 
+
+#ifndef TARGET_PLATFORM_SAILFISH
 void StationListProxyModel::setUserPosition(const QtMobility::QGeoCoordinate &pos)
 {
     qDebug() << "Position is now" << pos;
@@ -79,6 +91,7 @@ void StationListProxyModel::setUserPosition(const QtMobility::QGeoCoordinate &po
         invalidate();
     }
 }
+#endif
 
 void StationListProxyModel::setRecentStations(const QStringList &stations)
 {
@@ -162,15 +175,18 @@ void StationListProxyModel::forceSortingMode(SortingMode mode)
     default:
         break;
     }
+#ifndef TARGET_PLATFORM_SAILFISH
     if (mode == StationListProxyModel::DistanceSorting) {
         positionInfoSource->startUpdates();
     } else {
         positionInfoSource->stopUpdates();
     }
+#endif
     invalidate();
     sort(0);
 }
 
+#ifndef TARGET_PLATFORM_SAILFISH
 void StationListProxyModel::updatePosition(const QtMobility::QGeoPositionInfo &update)
 {
     qDebug() << "Position update received" << update;
@@ -183,3 +199,4 @@ void StationListProxyModel::updatePosition(const QtMobility::QGeoPositionInfo &u
         }
     }
 }
+#endif
index 45644a4..cb818c8 100644 (file)
@@ -23,12 +23,16 @@ Boston, MA 02110-1301, USA.
 */
 
 #include <QSortFilterProxyModel>
+#ifndef TARGET_PLATFORM_SAILFISH
 #include <QGeoCoordinate>
 #include <QGeoPositionInfoSource>
+#endif
 #include <QMetaType>
 #include <QStringList>
 
+#ifndef TARGET_PLATFORM_SAILFISH
 QTM_USE_NAMESPACE
+#endif
 
 class StationListProxyModel : public QSortFilterProxyModel
 {
@@ -52,7 +56,9 @@ public:
     SortingMode sortingMode();
     void setSortingMode(SortingMode mode);
 
+#ifndef TARGET_PLATFORM_SAILFISH
     Q_INVOKABLE void setUserPosition(const QGeoCoordinate &pos);
+#endif
     Q_INVOKABLE void setRecentStations(const QStringList &stations);
     Q_INVOKABLE void setRecentOnlyFilter(bool);
 
@@ -68,12 +74,16 @@ private:
     void forceSortingMode(SortingMode mode);
 
 private slots:
+#ifndef TARGET_PLATFORM_SAILFISH
     void updatePosition(const QGeoPositionInfo &update);
+#endif
     void updateRecentStations(void);
 private:
     QString m_searchPattern;
+#ifndef TARGET_PLATFORM_SAILFISH
     QGeoPositionInfoSource *positionInfoSource;
     QGeoCoordinate m_here;
+#endif
     QStringList m_stations;
     SortingMode m_sortingMode;
     bool m_filterRecentOnly;
index 3e57d80..d922d68 100644 (file)
@@ -31,7 +31,11 @@ Boston, MA 02110-1301, USA.
 #include <QFile>
 #include <QModelIndex>
 #include <QtConcurrentRun>
+#ifdef TARGET_PLATFORM_SAILFISH
+#include <QtQuick>
+#else
 #include <QtDeclarative>
+#endif
 
 // search Paths seem to be broken in Harmattan?
 
@@ -60,8 +64,13 @@ static QString trueFilePath(const QString &path)
 #endif
 }
 
+#ifdef TARGET_PLATFORM_SAILFISH
+View::View(QWindow *parent) :
+    QQuickView(parent),
+#else
 View::View(QWidget *parent) :
     QDeclarativeView(parent),
+#endif
     stationListModel(new StationListModel(this)),
     stationListProxyModel(new StationListProxyModel(this))
 {
@@ -79,7 +88,11 @@ View::View(QWidget *parent) :
     qmlRegisterType<StationScheduleModel>(
                 "net.cirulla.quandoparte", 1, 0, "StationScheduleModel");
 
+#ifdef TARGET_PLATFORM_SAILFISH
+    QQmlContext *context = this->rootContext();
+#else
     QDeclarativeContext *context = this->rootContext();
+#endif
     /* objects to be made accessible to QML */
     context->setContextProperty("settings", Settings::instance());
     context->setContextProperty("stationList", stationListModel);
index a91ce6e..8170f3e 100644 (file)
@@ -23,16 +23,30 @@ Boston, MA 02110-1301, USA.
 */
 
 #include <QFuture>
+#ifdef TARGET_PLATFORM_SAILFISH
+#include <QQuickView>
+#else
 #include <QDeclarativeView>
+#endif
 
 class StationListModel;
 class StationListProxyModel;
 
-class View : public QDeclarativeView
+class View :
+#ifdef TARGET_PLATFORM_SAILFISH
+        public QQuickView
+#else
+        public QDeclarativeView
+#endif
 {
     Q_OBJECT
 public:
+#ifdef TARGET_PLATFORM_SAILFISH
+    explicit View(QWindow *parent = 0);
+#else
     explicit View(QWidget *parent = 0);
+#endif
+
     ~View();
 
 signals: