diff --git a/companion.desktop b/harbour-companion.desktop similarity index 86% rename from companion.desktop rename to harbour-companion.desktop index 51f34f8..f4dd68f 100644 --- a/companion.desktop +++ b/harbour-companion.desktop @@ -1,8 +1,8 @@ [Desktop Entry] Type=Application X-Nemo-Application-Type=silica-qt5 -Icon=companion -Exec=companion +Icon=harbour-companion +Exec=harbour-companion Name=companion # translation example: # your app name in German locale (de) diff --git a/companion.pro b/harbour-companion.pro similarity index 76% rename from companion.pro rename to harbour-companion.pro index 5c037d3..29b8a10 100644 --- a/companion.pro +++ b/harbour-companion.pro @@ -10,22 +10,18 @@ # - translation filenames have to be changed # The name of your application -TARGET = companion +TARGET = harbour-companion QT += qml CONFIG += sailfishapp SOURCES += src/companion.cpp \ - src/schedule.cpp \ - src/memory.cpp + src/loader.cpp OTHER_FILES += qml/companion.qml \ qml/cover/CoverPage.qml \ - rpm/companion.spec \ - rpm/companion.yaml \ - translations/*.ts \ - companion.desktop + translations/*.ts SAILFISHAPP_ICONS = 86x86 108x108 128x128 256x256 @@ -37,18 +33,21 @@ CONFIG += sailfishapp_i18n # planning to localize your app, remember to comment out the # following TRANSLATIONS line. And also do not forget to # modify the localized app name in the the .desktop file. -TRANSLATIONS += translations/companion-de.ts +TRANSLATIONS += translations/harbour-companion-de.ts HEADERS += \ - src/schedule.h \ - src/memory.h + src/loader.h DISTFILES += \ - qml/pages/MainView.qml \ - qml/pages/DateView.qml \ qml/js/Global.js \ - qml/pages/SubDateView.qml \ - rpm/companion.changes + qml/pages/DateView.qml \ + qml/pages/SelectConferenceView.qml \ + qml/pages/ConferenceView.qml \ + qml/pages/EventView.qml \ + rpm/harbour-companion.changes \ + rpm/harbour-companion.spec \ + rpm/harbour-companion.yaml \ + harbour-companion.desktop desktop.files = $${TARGET}.desktop desktop.path = /usr/share/applications diff --git a/icons/108x108/companion.png b/icons/108x108/harbour-companion.png similarity index 100% rename from icons/108x108/companion.png rename to icons/108x108/harbour-companion.png diff --git a/icons/128x128/companion.png b/icons/128x128/harbour-companion.png similarity index 100% rename from icons/128x128/companion.png rename to icons/128x128/harbour-companion.png diff --git a/icons/256x256/companion.png b/icons/256x256/harbour-companion.png similarity index 100% rename from icons/256x256/companion.png rename to icons/256x256/harbour-companion.png diff --git a/icons/86x86/companion.png b/icons/86x86/harbour-companion.png similarity index 100% rename from icons/86x86/companion.png rename to icons/86x86/harbour-companion.png diff --git a/qml/companion.qml b/qml/companion.qml index 05ce49e..8e87d4e 100644 --- a/qml/companion.qml +++ b/qml/companion.qml @@ -36,15 +36,11 @@ import "js/Global.js" as Global ApplicationWindow { - initialPage: Component { MainView { } } + initialPage: Component { ConferenceView { } } cover: Qt.resolvedUrl("cover/CoverPage.qml") allowedOrientations: defaultAllowedOrientations id: root property int date - - Schedule { - id: schedule - } } diff --git a/qml/js/Global.js b/qml/js/Global.js index c1e49ec..9017618 100644 --- a/qml/js/Global.js +++ b/qml/js/Global.js @@ -3,3 +3,90 @@ function padLeft(nr, n, str){ return Array(n-String(nr).length+1).join(str||'0')+nr; } + +// Objects are grouped by place => regroup by time +function groupByTime(objects){ + var newData = [] + var groupedByTime = {} + for(var room in objects){ + for(var elem in objects[room]){ + var tmp = objects[room][elem] + if(!groupedByTime[tmp.start]){ + groupedByTime[tmp.start] = [] + } + + groupedByTime[tmp.start].push(tmp); + } + } + for(var time in groupedByTime){ + for(var elem1 in groupedByTime[time]){ + var tmp1 = groupedByTime[time][elem1] + var start = tmp1.start + + var startHours = parseInt(start[0]+start[1]) + var durationHours = parseInt(tmp1.duration[0]+tmp1.duration[1]) + var startMinute = parseInt(start[3]+start[4]) + var durationMinute = parseInt(tmp1.duration[3]+tmp1.duration[4]) + + var endTime = (startHours*60)+startMinute+(durationHours*60)+durationMinute + var end = padLeft(Math.floor(endTime/60),2)+":"+padLeft(endTime%60,2) + tmp1["end"] = end; + + newData.push(tmp1); + } + } + return newData +} + +function compareTime(aTime, aPlace, bTime, bPlace){ + //Sort by time + if(aTime > bTime) + return 1; + if(aTime < bTime) + return -1; + + //Same time => Sort by room name + if(aPlace > bPlace) + return 1; + if(aPlace < bPlace) + return -1; + + //Whatever + return 0; +} + +function comparePlace(aTime, aPlace, bTime, bPlace){ + //Sort by room name + if(aPlace > bPlace) + return 1; + if(aPlace < bPlace) + return -1; + + //Sort by time + if(aTime > bTime) + return 1; + if(aTime < bTime) + return -1; + + //Whatever + return 0; +} + +function orderBy(objects, byPlace){ + objects = objects.sort(function(a,b){ + //Late night events are on the wrong date in the fahrplan sheet + var aStart = parseInt(a.start[0]+a.start[1]); + var bStart = parseInt(b.start[0]+b.start[1]); + if(aStart < 7){ + aStart += 30; + } + if(bStart < 7){ + bStart += 30; + } + + if(byPlace) + return comparePlace(aStart, a.room, bStart, b.room); + return compareTime(aStart, a.room, bStart, b.room); + }); + return objects; +} diff --git a/qml/pages/MainView.qml b/qml/pages/ConferenceView.qml similarity index 64% rename from qml/pages/MainView.qml rename to qml/pages/ConferenceView.qml index 4eedd7c..6c8f61b 100644 --- a/qml/pages/MainView.qml +++ b/qml/pages/ConferenceView.qml @@ -38,24 +38,39 @@ import "../js/Global.js" as Global Page { id: page + Loader{ + id: loader + } + // The effective value will be restricted by ApplicationWindow.allowedOrientations allowedOrientations: Orientation.All // To enable PullDownMenu, place our content in a SilicaFlickable SilicaFlickable { + leftMargin: Theme.paddingMedium + rightMargin: Theme.paddingMedium anchors.fill: parent // Tell SilicaFlickable the height of its content. contentHeight: column.height PullDownMenu { + + MenuItem { + text: qsTr("Select conference") + onClicked: { + pageStack.push(Qt.resolvedUrl("SelectConferenceView.qml"), {loader:loader}); + } + + } + MenuItem { text: "Update schedule" onClicked: { update.execute("Updating schedule",function(){ - schedule.loadFromNetwork(); + loader.loadFromNetwork(); }) - } + } } } @@ -71,16 +86,16 @@ Page { width: page.width spacing: Theme.paddingSmall PageHeader { - title: qsTr("GPN Companion") + title: qsTr("Chaos Companion") } Label { text: "Updating..." - visible: schedule.updating + visible: loader.loading } ColumnView{ - model:JSON.parse(schedule.schedule).schedule.conference.days + model:JSON.parse(loader.schedule).schedule.conference.days width: parent.width itemHeight: Theme.itemSizeSmall delegate: BackgroundItem { @@ -91,41 +106,9 @@ Page { } onClicked: { - var base = JSON.parse(schedule.schedule).schedule.conference.days[model.index]; + var base = JSON.parse(loader.schedule).schedule.conference.days[model.index]; var data = base.rooms; - var newData = [] - var timed = {} - for(var keys in data){ - for(var elem in data[keys]){ - var tmp = data[keys][elem] - if(!timed[tmp.start]){ - timed[tmp.start] = [] - } - - timed[tmp.start].push(tmp); - } - } - for(var time in timed){ - for(var elem1 in timed[time]){ - var tmp1 = timed[time][elem1] - var start = tmp1.start - - var hours = parseInt(start[0]+start[1]) - var dhours = parseInt(tmp1.duration[0]+tmp1.duration[1]) - var minute = parseInt(start[3]+start[4]) - var dminute = parseInt(tmp1.duration[3]+tmp1.duration[4]) - - var endTime = (hours*60)+minute+(dhours*60)+dminute - var end = Global.padLeft(Math.floor(endTime/60),2)+":"+Global.padLeft(endTime%60,2) - tmp1["end"] = end; - - newData.push(tmp1) - } - } - - Memory.set("model", newData) - Memory.set("title", base.date) - pageStack.push(Qt.resolvedUrl("DateView.qml")); + pageStack.push(Qt.resolvedUrl("DateView.qml"), {model:base.rooms, title:base.date}); } } } diff --git a/qml/pages/DateView.qml b/qml/pages/DateView.qml index 3e20f0b..2cdefd5 100644 --- a/qml/pages/DateView.qml +++ b/qml/pages/DateView.qml @@ -31,27 +31,43 @@ import QtQuick 2.0 import Sailfish.Silica 1.0 import harbour.companion 1.0 +import "../js/Global.js" as Global Page { id: page + property var model + property string title + property bool order: false // The effective value will be restricted by ApplicationWindow.allowedOrientations allowedOrientations: Orientation.All SilicaListView { + + PullDownMenu { + + MenuItem { + text: page.order ? qsTr("Sort by time") : qsTr("Sort by place") + onClicked: { + page.order = !page.order + page.model = Global.orderBy(page.model, page.order); + } + } + } + id: listView x: Theme.paddingMedium width: parent.width - 2*Theme.paddingMedium - model: Memory.get("model") + model: page.model anchors.fill: parent header: PageHeader { - title: Memory.get("title") + title: page.title } delegate: ListItem { id: delegate - height: title.height + times.height + height: title.contentHeight + times.height Label { id: title @@ -82,12 +98,15 @@ Page { } onClicked: { - Memory.set("subdata",modelData); - pageStack.push(Qt.resolvedUrl("SubDateView.qml")); + pageStack.push(Qt.resolvedUrl("EventView.qml"), {event:modelData}); } } VerticalScrollDecorator {} + + Component.onCompleted: { + page.model = Global.orderBy(Global.groupByTime(page.model), page.order); + } } } diff --git a/qml/pages/SubDateView.qml b/qml/pages/EventView.qml similarity index 86% rename from qml/pages/SubDateView.qml rename to qml/pages/EventView.qml index 1b2034d..1296541 100644 --- a/qml/pages/SubDateView.qml +++ b/qml/pages/EventView.qml @@ -35,6 +35,8 @@ import harbour.companion 1.0 Page { id: page + property var event + // The effective value will be restricted by ApplicationWindow.allowedOrientations allowedOrientations: Orientation.All @@ -65,7 +67,7 @@ Page { PageHeader { id: header - title: Memory.get("subdata").title + title: page.event.title } Label { @@ -74,7 +76,7 @@ Page { } Label { - text: Memory.get("subdata").title + text: page.event.title wrapMode: Text.Wrap color: Theme.highlightColor width: parent.width @@ -83,13 +85,15 @@ Page { Label { text:"Subtitle:" color: Theme.primaryColor + visible: page.event.subtitle ? Theme.fontSizeLarge : 0 } Label { - text: Memory.get("subdata").subtitle + text: page.event.subtitle wrapMode: Text.Wrap color: Theme.highlightColor width: parent.width + height: page.event.subtitle ? Theme.fontSizeLarge : 0 } Label { @@ -98,7 +102,7 @@ Page { } Label { - text: Memory.get("subdata").room + text: page.event.room wrapMode: Text.Wrap color: Theme.highlightColor width: parent.width @@ -110,7 +114,7 @@ Page { } Label { - text: Memory.get("subdata").start+" - "+Memory.get("subdata").end + text: page.event.start+" - "+page.event.end wrapMode: Text.Wrap color: Theme.highlightColor width: parent.width @@ -122,7 +126,8 @@ Page { } Label { - text: Memory.get("subdata").type + text: page.event.type + font.capitalization: Font.Capitalize wrapMode: Text.Wrap color: Theme.highlightColor width: parent.width @@ -134,7 +139,7 @@ Page { } Label { - text: (Memory.get("subdata").do_not_record) ? "Do not record" : "-" + text: (page.event.do_not_record) ? "Do NOT record!" : "You may record" wrapMode: Text.Wrap color: Theme.highlightColor width: parent.width @@ -149,10 +154,11 @@ Page { Label { text:"Abstract:" color: Theme.primaryColor + visible: page.event.abstract ? true: false } Label { - text: Memory.get("subdata").abstract + text: page.event.abstract wrapMode: Text.Wrap color: Theme.highlightColor width: parent.width @@ -161,10 +167,12 @@ Page { Label { text:"Description:" color: Theme.primaryColor + visible: page.event.description ? true: false + } Label { - text: Memory.get("subdata").description + text: page.event.description wrapMode: Text.Wrap color: Theme.highlightColor width: parent.width diff --git a/qml/pages/SelectConferenceView.qml b/qml/pages/SelectConferenceView.qml new file mode 100644 index 0000000..5e863dc --- /dev/null +++ b/qml/pages/SelectConferenceView.qml @@ -0,0 +1,68 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 +import harbour.companion 1.0 + +Page { + id: page + + property var loader + + // The effective value will be restricted by ApplicationWindow.allowedOrientations + allowedOrientations: Orientation.All + + ListModel { + id: eventModel + ListElement { + name: qsTr("34. Chaos Communication Congress") + cachename: "%0c3" + iteration: 2017 + url: "https://fahrplan.events.ccc.de/congress/%0/Fahrplan/schedule.json" + } + ListElement { + name: qsTr("17. Gulasch Programmier Nacht") + cachename: "gpn%0" + iteration:17 + url: "https://entropia.de/GPN%0:Fahrplan:JSON?action=raw" + } + ListElement { + name: qsTr("MRMCD 17") + cachename: "mrmcd%0" + iteration: 2017 + url: "https://%0.mrmcd.net/fahrplan/schedule.json" + } + } + + SilicaListView { + id: listView + + x: Theme.paddingMedium + width: parent.width - 2*Theme.paddingMedium + + model: eventModel + anchors.fill: parent + header: PageHeader { + title: qsTr("Choose event") + } + delegate: ListItem { + id: delegate + + Label { + id: title + + x: Theme.paddingMedium + text: model.name + wrapMode: Text.Wrap + color: Theme.highlightColor + width: parent.width-2*Theme.paddingMedium + } + + onClicked: { + page.loader.setCurrent(model.cachename, model.url, model.iteration); + pageStack.pop(); + } + + } + + VerticalScrollDecorator {} + } +} diff --git a/rpm/companion.changes b/rpm/companion.changes deleted file mode 100644 index affdc30..0000000 --- a/rpm/companion.changes +++ /dev/null @@ -1,6 +0,0 @@ -* Thu May 18 2017 Niels bernlöhr 0.2.0-1 -- Rebrand for GPN - - -* Sat Dec 24 2016 Niels bernlöhr 0.0.1-1 -- Initial Release diff --git a/rpm/harbour-companion.changes b/rpm/harbour-companion.changes new file mode 100644 index 0000000..7756391 --- /dev/null +++ b/rpm/harbour-companion.changes @@ -0,0 +1,9 @@ +* Thu Dec 14 2017 Niels Bernlöhr 0.3.0-1 +- Rebrand for 34c3 + gpn + mrmcd + +* Thu May 18 2017 Niels Bernlöhr 0.2.0-1 +- Rebrand for GPN + + +* Sat Dec 24 2016 Niels Bernlöhr 0.0.1-1 +- Initial Release diff --git a/rpm/companion.changes.in b/rpm/harbour-companion.changes.in similarity index 100% rename from rpm/companion.changes.in rename to rpm/harbour-companion.changes.in diff --git a/rpm/companion.spec b/rpm/harbour-companion.spec similarity index 94% rename from rpm/companion.spec rename to rpm/harbour-companion.spec index 3e3fd03..843bed4 100644 --- a/rpm/companion.spec +++ b/rpm/harbour-companion.spec @@ -3,7 +3,7 @@ # Generated by: spectacle version 0.27 # -Name: companion +Name: harbour-companion # >> macros # << macros @@ -13,13 +13,13 @@ Name: companion %{!?qtc_make:%define qtc_make make} %{?qtc_builddir:%define _builddir %qtc_builddir} Summary: Chaos Companion -Version: 0.2 +Version: 0.3 Release: 1 Group: Qt/Qt License: LICENSE URL: https://github.com/k0rmarun/33c3-companion-jolla Source0: %{name}-%{version}.tar.bz2 -Source100: companion.yaml +Source100: harbour-companion.yaml Requires: sailfishsilica-qt5 >= 0.10.9 BuildRequires: pkgconfig(sailfishapp) >= 1.0.2 BuildRequires: pkgconfig(Qt5Core) diff --git a/rpm/companion.yaml b/rpm/harbour-companion.yaml similarity index 97% rename from rpm/companion.yaml rename to rpm/harbour-companion.yaml index 4c7a4b8..ef19aa4 100644 --- a/rpm/companion.yaml +++ b/rpm/harbour-companion.yaml @@ -1,6 +1,6 @@ -Name: companion +Name: harbour-companion Summary: Chaos Companion -Version: 0.2 +Version: 0.3 Release: 1 # The contents of the Group field should be one of the groups listed here: # http://gitorious.org/meego-developer-tools/spectacle/blobs/master/data/GROUPS diff --git a/src/companion.cpp b/src/companion.cpp index 4958982..5f60a17 100644 --- a/src/companion.cpp +++ b/src/companion.cpp @@ -34,18 +34,7 @@ #include #include -#include "schedule.h" -#include "memory.h" - -// Second, define the singleton type provider function (callback). -static QObject *example_qobject_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine) -{ - Q_UNUSED(engine) - Q_UNUSED(scriptEngine) - - Memory *example = new Memory(); - return example; -} +#include "loader.h" int main(int argc, char *argv[]) { @@ -67,8 +56,7 @@ int main(int argc, char *argv[]) // // For details see: // https://harbour.jolla.com/faq#1.5.0 - qmlRegisterType("harbour.companion", 1, 0, "Schedule"); - qmlRegisterSingletonType("harbour.companion", 1, 0, "Memory", example_qobject_singletontype_provider); + qmlRegisterType("harbour.companion", 1, 0, "Loader"); // Start the application. v->setSource(SailfishApp::pathTo("qml/companion.qml")); diff --git a/src/loader.cpp b/src/loader.cpp new file mode 100644 index 0000000..6140bfc --- /dev/null +++ b/src/loader.cpp @@ -0,0 +1,98 @@ +#include "loader.h" +#include +#include +#include + +Loader::Loader(QObject *parent) : QObject(parent) +{ + mBaseDir = QStandardPaths::writableLocation(QStandardPaths::DataLocation); + mFilename = mBaseDir+"/cache.json"; + mURLFilename = mBaseDir+"/url"; + mCacheFilename = mFilename; + qDebug() << "filename" << mFilename; + + nam = new QNetworkAccessManager(this); + mLoading = false; + emit loadingChanged(mLoading); + setCurrent("cache.json", "", 0); +} + +bool Loader::loadFromDisk(){ + mSchedule = read(mFilename); + if(!mSchedule.isEmpty()){ + emit scheduleChanged(mSchedule); + qDebug() << "LOAD FROM DISK SUCCEEDED"; + return true; + } else { + qDebug() << "LOAD FROM DISK FAILED"; + return false; + } +} + +void Loader::loadFromNetwork(){ + mLoading = true; + emit loadingChanged(mLoading); + + connect(nam, &QNetworkAccessManager::finished, + this, &Loader::RequestFinished); + nam->get(QNetworkRequest(mURL)); +} + +void Loader::setCurrent(const QString& cacheTitle, const QString &url, int iteration) { + mFilename = mBaseDir + "/" + cacheTitle.arg(iteration); + if(url.isEmpty()){ + mURL = read(mURLFilename); + }else { + mURL = url.arg(iteration); + } + if(!loadFromDisk()){ + loadFromNetwork(); + return; + } +} + +void Loader::RequestFinished(QNetworkReply *reply){ + if(reply->error() == QNetworkReply::NoError){ + QString tmp = QString(reply->readAll()); + if(mSchedule != tmp && !tmp.isEmpty()){ + mSchedule = tmp; + emit scheduleChanged(mSchedule); + write(mFilename, mSchedule); + write(mCacheFilename, mSchedule); + write(mURLFilename, mURL); + qDebug() << "LOAD FROM NETWORK SUCCEEDED"; + } else { + qDebug() << "NOTHING CHANGED"; + } + } else { + emit loadFromNetworkFailed(); + qDebug() << "LOAD FROM NETWORK FAILED"; + } + + mLoading = false; + emit loadingChanged(mLoading); +} + +void Loader::write(const QString& filename, const QString &data){ + QFile file(filename); + if(!file.exists()){ + QDir dir = QDir::home(); + dir.mkpath(mBaseDir); + } + if(file.open(QIODevice::WriteOnly|QIODevice::Truncate)){ + file.write(data.toUtf8()); + file.close(); + } +} + +QString Loader::read(const QString& filename){ + QString ret; + QFile file(filename); + if(file.exists()){ + file.open(QIODevice::ReadOnly); + ret = QString(file.readAll()); + file.close(); + } + return ret; +} + diff --git a/src/loader.h b/src/loader.h new file mode 100644 index 0000000..099923a --- /dev/null +++ b/src/loader.h @@ -0,0 +1,48 @@ +#ifndef LOADER_H +#define LOADER_H + +#include +#include +#include + +class Loader: public QObject +{ + Q_OBJECT + + Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged) + Q_PROPERTY(QString schedule READ schedule NOTIFY scheduleChanged) + + bool loadFromDisk(); + bool loadURLFromDisk(); + void write(const QString& filename, const QString& data); + QString read(const QString& filename); + + QString mBaseDir; + QString mFilename; + QString mCacheFilename; + QString mURLFilename; + QString mURL; + QNetworkAccessManager* nam; + bool mLoading; + + QString mSchedule; + +public: + explicit Loader(QObject *parent = 0); + QString schedule() { return mSchedule; } + bool loading(){return mLoading; } + + Q_INVOKABLE void loadFromNetwork(); + Q_INVOKABLE void setCurrent(const QString& cacheTitle, const QString &url, int iteration); + +private slots: + void RequestFinished(QNetworkReply* reply); + +signals: + void loadFromDiskFailed(); + void loadFromNetworkFailed(); + void scheduleChanged(const QString& source); + void loadingChanged(bool updating); +}; + +#endif // LOADER_H diff --git a/src/memory.cpp b/src/memory.cpp deleted file mode 100644 index 3739653..0000000 --- a/src/memory.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "memory.h" - -Memory::Memory(QObject *parent) : QObject(parent) -{ - -} - -void Memory::set(QString key, QVariant value){ - data[key] = value; -} - -QVariant Memory::get(QString key){ - return data[key]; -} diff --git a/src/memory.h b/src/memory.h deleted file mode 100644 index 05170d1..0000000 --- a/src/memory.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef MEMORY_H -#define MEMORY_H - -#include -#include -#include -#include - -class Memory : public QObject -{ - Q_OBJECT - QVariantMap data; -public: - explicit Memory(QObject *parent = 0); - - Q_INVOKABLE void set(QString key, QVariant value); - Q_INVOKABLE QVariant get(QString key); - -signals: - -public slots: -}; - -#endif // MEMORY_H diff --git a/src/schedule.cpp b/src/schedule.cpp deleted file mode 100644 index 3c6ed06..0000000 --- a/src/schedule.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#include "schedule.h" -#include -#include -#include - -Schedule::Schedule(QObject *parent) : QObject(parent) -{ - mDirname = QStandardPaths::writableLocation(QStandardPaths::DataLocation); - mFilename = mDirname+"/cache.json"; - qDebug() << "filename" << mFilename; - nam = new QNetworkAccessManager(this); - mUpdating = false; - emit updatingChanged(mUpdating); - if(!loadFromDisk()){ - loadFromNetwork(); - } -} - -bool Schedule::loadFromDisk(){ - QFile file(mFilename); - if(file.open(QIODevice::ReadOnly)){ - mSchedule = QString(file.readAll()); - file.close(); - if(!mSchedule.isEmpty()){ - emit scheduleChanged(mSchedule); - qDebug() << "LOAD FROM DISK SUCCEEDED"; - return true; - } else { - qDebug() << "LOAD FROM DISK FAILED"; - return false; - } - } else { - emit loadFromDiskFailed(); - qDebug() << "LOAD FROM DISK FAILED"; - return false; - } -} - -void Schedule::loadFromNetwork(){ - QUrl url("https://entropia.de/GPN17:Fahrplan:JSON?action=raw"); - - mUpdating = true; - emit updatingChanged(mUpdating); - - connect(nam, &QNetworkAccessManager::finished, - this, &Schedule::RequestFinished); - nam->get(QNetworkRequest(url)); -} - -void Schedule::RequestFinished(QNetworkReply *reply){ - if(reply->error() == QNetworkReply::NoError){ - QString tmp = QString(reply->readAll()); - if(mSchedule != tmp && !tmp.isEmpty()){ - mSchedule = tmp; - emit scheduleChanged(mSchedule); - write(mSchedule); - qDebug() << "LOAD FROM NETWORK SUCCEEDED"; - } else { - qDebug() << "NOTHING CHANGED"; - } - } else { - emit loadFromNetworkFailed(); - qDebug() << "LOAD FROM NETWORK FAILED"; - } - - mUpdating = false; - emit updatingChanged(mUpdating); -} - -void Schedule::write(const QString &data){ - QFile file(mFilename); - if(!file.exists()){ - QDir dir = QDir::home(); - dir.mkpath(mDirname); - } - if(file.open(QIODevice::WriteOnly|QIODevice::Truncate)){ - file.write(data.toUtf8()); - file.close(); - } -} - - diff --git a/src/schedule.h b/src/schedule.h deleted file mode 100644 index 18cd936..0000000 --- a/src/schedule.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef SCHEDULE_H -#define SCHEDULE_H - -#include -#include -#include - -class Schedule : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString schedule - READ schedule - NOTIFY scheduleChanged) - Q_PROPERTY(bool updating READ updating NOTIFY updatingChanged) - bool loadFromDisk(); - void write(const QString& data); - -public: - explicit Schedule(QObject *parent = 0); - QString schedule() { return mSchedule; } - bool updating(){return mUpdating; } - - Q_INVOKABLE void loadFromNetwork(); - -private slots: - void RequestFinished(QNetworkReply* reply); - -signals: - void loadFromDiskFailed(); - void loadFromNetworkFailed(); - void scheduleChanged(const QString& source); - void updatingChanged(bool updating); -private: - QString mSchedule; - QString mFilename; - QString mDirname; - QNetworkAccessManager* nam; - bool mUpdating; -}; - -#endif // SCHEDULE_H diff --git a/translations/companion-de.ts b/translations/companion-de.ts deleted file mode 100644 index 03a4c1e..0000000 --- a/translations/companion-de.ts +++ /dev/null @@ -1,19 +0,0 @@ - - - - - CoverPage - - Nothing to -see yet - - - - - MainView - - GPN Companion - - - - diff --git a/translations/companion.ts b/translations/companion.ts deleted file mode 100644 index 03a4c1e..0000000 --- a/translations/companion.ts +++ /dev/null @@ -1,19 +0,0 @@ - - - - - CoverPage - - Nothing to -see yet - - - - - MainView - - GPN Companion - - - - diff --git a/translations/harbour-companion-de.ts b/translations/harbour-companion-de.ts new file mode 100644 index 0000000..e029c5c --- /dev/null +++ b/translations/harbour-companion-de.ts @@ -0,0 +1,53 @@ + + + + + ConferenceView + + Select conference + + + + Chaos Companion + + + + + CoverPage + + Nothing to +see yet + + + + + DateView + + Sort by time + + + + Sort by place + + + + + SelectConferenceView + + 34. Chaos Communication Congress + + + + 17. Gulasch Programmier Nacht + + + + MRMCD 17 + + + + Choose event + + + + diff --git a/translations/harbour-companion.ts b/translations/harbour-companion.ts new file mode 100644 index 0000000..e029c5c --- /dev/null +++ b/translations/harbour-companion.ts @@ -0,0 +1,53 @@ + + + + + ConferenceView + + Select conference + + + + Chaos Companion + + + + + CoverPage + + Nothing to +see yet + + + + + DateView + + Sort by time + + + + Sort by place + + + + + SelectConferenceView + + 34. Chaos Communication Congress + + + + 17. Gulasch Programmier Nacht + + + + MRMCD 17 + + + + Choose event + + + +