From fcdae90264249396e6583fb88a8d069ea0726348 Mon Sep 17 00:00:00 2001 From: coderus Date: Wed, 1 Mar 2017 11:24:12 +0300 Subject: [PATCH 01/20] Fixed background daemon mode * Fixed relation between dbus and systemd services * Combined keepRunning and autostart options * Get rid of yaml --- .../dbus/org.harbour.sailorgram.service | 3 +- harbour-sailorgram/harbour-sailorgram.pro | 1 - harbour-sailorgram/qml/model/Context.qml | 11 +++- .../qml/pages/settings/DaemonSettingsPage.qml | 13 +--- .../qml/pages/settings/SettingsPage.qml | 5 +- .../rpm/harbour-sailorgram.spec | 33 ---------- .../rpm/harbour-sailorgram.yaml | 63 ------------------- .../dbus/interface/sailorgraminterface.cpp | 6 +- harbour-sailorgram/src/harbour-sailorgram.cpp | 15 +++-- harbour-sailorgram/src/sailorgram.cpp | 51 +++++++++++---- harbour-sailorgram/src/sailorgram.h | 10 ++- .../translations/harbour-sailorgram.ts | 10 +-- 12 files changed, 76 insertions(+), 145 deletions(-) delete mode 100644 harbour-sailorgram/rpm/harbour-sailorgram.yaml diff --git a/harbour-sailorgram/dbus/org.harbour.sailorgram.service b/harbour-sailorgram/dbus/org.harbour.sailorgram.service index 16915511..898d8770 100644 --- a/harbour-sailorgram/dbus/org.harbour.sailorgram.service +++ b/harbour-sailorgram/dbus/org.harbour.sailorgram.service @@ -1,4 +1,5 @@ [D-BUS Service] Name=org.harbour.sailorgram +Interface=org.harbour.sailorgram Exec=/usr/bin/invoker --type=generic /usr/bin/harbour-sailorgram -SystemdService=org.harbour.sailorgram +SystemdService=harbour-sailorgram-notifications.service diff --git a/harbour-sailorgram/harbour-sailorgram.pro b/harbour-sailorgram/harbour-sailorgram.pro index fcb8f197..9409cf4b 100644 --- a/harbour-sailorgram/harbour-sailorgram.pro +++ b/harbour-sailorgram/harbour-sailorgram.pro @@ -168,7 +168,6 @@ SAILFISHAPP_ICONS = \ OTHER_FILES += \ rpm/harbour-sailorgram.changes \ rpm/harbour-sailorgram.spec \ - rpm/harbour-sailorgram.yaml \ harbour-sailorgram.desktop \ qml/cover/*.png diff --git a/harbour-sailorgram/qml/model/Context.qml b/harbour-sailorgram/qml/model/Context.qml index 2e92f28e..6f9b1389 100644 --- a/harbour-sailorgram/qml/model/Context.qml +++ b/harbour-sailorgram/qml/model/Context.qml @@ -84,8 +84,18 @@ Item property SailorGram sailorgram: SailorGram { telegram: context.telegram + view: quickView + + onWakeUpRequested: { + if (Qt.application.state !== Qt.ApplicationActive) + mainwindow.activate(); + } onOpenDialogRequested: { + if (!quickView.active) { + quickView.show() + } + var dialog = context.dialogs.getDialog(dialogid); if(!dialog) @@ -142,7 +152,6 @@ Item context.angledbubbles = parseInt(Settings.transactionGet(tx, "angledbubbles")); context.showsearchfield = parseInt(Settings.transactionGet(tx, "showsearchfield")); context.defaultemojiset = parseInt(Settings.transactionGet(tx, "defaultemojiset")); - context.sailorgram.keepRunning = parseInt(Settings.transactionGet(tx, "keeprunning")); var opacity = Settings.transactionGet(tx, "bubblesopacity"); context.bubblesopacity = (opacity === false) ? 100 : parseInt(opacity); diff --git a/harbour-sailorgram/qml/pages/settings/DaemonSettingsPage.qml b/harbour-sailorgram/qml/pages/settings/DaemonSettingsPage.qml index 1870cbc3..2d0c16a7 100644 --- a/harbour-sailorgram/qml/pages/settings/DaemonSettingsPage.qml +++ b/harbour-sailorgram/qml/pages/settings/DaemonSettingsPage.qml @@ -12,9 +12,7 @@ Dialog acceptDestinationAction: PageStackAction.Pop onAccepted: { - context.sailorgram.keepRunning = tskeeprunning.checked; context.sailorgram.autostart = tsdaemonenabled.checked; - Settings.set("keeprunning", tskeeprunning.checked); } SilicaFlickable @@ -29,21 +27,12 @@ Dialog DialogHeader { acceptText: qsTr("Save") } - TextSwitch - { - id: tskeeprunning - anchors { left: parent.left; right: parent.right; leftMargin: Theme.paddingSmall; rightMargin: Theme.paddingSmall } - text: qsTr("Keep running") - description: qsTr("SailorGram keeps running in background even when closed") - checked: context.sailorgram.keepRunning - } - TextSwitch { id: tsdaemonenabled anchors { left: parent.left; right: parent.right; leftMargin: Theme.paddingSmall; rightMargin: Theme.paddingSmall } text: qsTr("Autostart") - description: qsTr("SailorGram starts automatically") + description: qsTr("SailorGram starts automatically and will continue working in background after closing") checked: context.sailorgram.autostart } } diff --git a/harbour-sailorgram/qml/pages/settings/SettingsPage.qml b/harbour-sailorgram/qml/pages/settings/SettingsPage.qml index 830d20d0..ddba4aa1 100644 --- a/harbour-sailorgram/qml/pages/settings/SettingsPage.qml +++ b/harbour-sailorgram/qml/pages/settings/SettingsPage.qml @@ -42,9 +42,8 @@ Page width: parent.width height: Theme.itemSizeSmall icon: "qrc:///res/daemon.png" - text: qsTr("Daemon") + " (Disabled)" - enabled: false - //onActionRequested: pageStack.push(Qt.resolvedUrl("DaemonSettingsPage.qml"), { "context": settingspage.context }) + text: qsTr("Daemon") + onActionRequested: pageStack.push(Qt.resolvedUrl("DaemonSettingsPage.qml"), { "context": settingspage.context }) } /* diff --git a/harbour-sailorgram/rpm/harbour-sailorgram.spec b/harbour-sailorgram/rpm/harbour-sailorgram.spec index 10d15fcf..9095d1a4 100644 --- a/harbour-sailorgram/rpm/harbour-sailorgram.spec +++ b/harbour-sailorgram/rpm/harbour-sailorgram.spec @@ -1,14 +1,7 @@ -# -# Do NOT Edit the Auto-generated Part! -# Generated by: spectacle version 0.27 -# - Name: harbour-sailorgram -# >> macros %define __provides_exclude_from ^%{_datadir}/.*$ %define __requires_exclude ^libqtelegram|.*$ -# << macros %{!?qtc_qmake:%define qtc_qmake %qmake} %{!?qtc_qmake5:%define qtc_qmake5 %qmake5} @@ -44,64 +37,41 @@ An unofficial Telegram Client for SailfishOS %prep %setup -q -n %{name}-%{version} -# >> setup -# << setup - %build -# >> build pre -# << build pre %qtc_qmake5 %qtc_make %{?_smp_mflags} -# >> build post -# << build post - %install rm -rf %{buildroot} -# >> install pre -# << install pre %qmake5_install -# >> install post -mkdir -p %{buildroot}/usr/lib/systemd/user/post-user-session.target.wants -ln -s ../harbour-sailorgram-notifications.service %{buildroot}/usr/lib/systemd/user/post-user-session.target.wants/harbour-sailorgram-notifications.service - ln -s /usr/share/%{name}/lib/libQTelegram.so %{buildroot}/usr/share/%{name}/lib/libQTelegram.so.1 ln -s /usr/share/%{name}/lib/libQTelegram.so %{buildroot}/usr/share/%{name}/lib/libQTelegram.so.1.0 ln -s /usr/share/%{name}/lib/libQTelegram.so %{buildroot}/usr/share/%{name}/lib/libQTelegram.so.1.0.0 -# << install post - desktop-file-install --delete-original \ --dir %{buildroot}%{_datadir}/applications \ %{buildroot}%{_datadir}/applications/*.desktop %pre -# >> pre systemctl-user stop harbour-sailorgram-notifications.service if /sbin/pidof harbour-sailorgram > /dev/null; then killall harbour-sailorgram || true fi -# << pre %preun -# >> preun systemctl-user stop harbour-sailorgram-notifications.service if /sbin/pidof harbour-sailorgram > /dev/null; then killall harbour-sailorgram || true fi -# << preun - %post -# >> post systemctl-user restart mce.service systemctl-user restart ngfd.service -systemctl-user restart harbour-sailorgram-notifications.service # Reset settings #rm -rf /home/nemo/.cache/%{name} @@ -118,9 +88,6 @@ systemctl-user restart harbour-sailorgram-notifications.service %{_datadir}/ngfd/events.d/*.ini %{_datadir}/dbus-1/services/*.service %{_libdir}/systemd/user/harbour-sailorgram-notifications.service -%{_libdir}/systemd/user/post-user-session.target.wants/harbour-sailorgram-notifications.service %{_sysconfdir}/mce/10sailorgram-led.ini %exclude %{_libdir}/cmake/* %exclude %{_libdir}/debug/* -# >> files -# << files diff --git a/harbour-sailorgram/rpm/harbour-sailorgram.yaml b/harbour-sailorgram/rpm/harbour-sailorgram.yaml deleted file mode 100644 index b2e5943c..00000000 --- a/harbour-sailorgram/rpm/harbour-sailorgram.yaml +++ /dev/null @@ -1,63 +0,0 @@ -Name: harbour-sailorgram -Summary: SailorGram -Version: 0.89 -Release: 13 -# 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 -Group: Qt/Qt -URL: https://github.com/QtGram/harbour-sailorgram/ -License: GPL3 -# This must be generated before uploading a package to a remote build service. -# Usually this line does not need to be modified. -Sources: -- '%{name}-%{version}.tar.bz2' -Description: | - An unofficial Telegram Client for SailfishOS -Configure: none -# The qtc5 builder inserts macros to allow QtCreator to have fine -# control over qmake/make execution -Builder: qtc5 - -# This section specifies build dependencies that are resolved using pkgconfig. -# This is the preferred way of specifying build dependencies for your package. -PkgConfigBR: - - sailfishapp >= 1.0.2 - - Qt5Core - - Qt5Qml - - Qt5Xml - - Qt5Quick - - Qt5DBus - - Qt5Multimedia - - Qt5Concurrent - - Qt5Location - - Qt5Positioning - - openssl -# Build dependencies without a pkgconfig setup can be listed here -# PkgBR: -# - openssl-devel - -# Runtime dependencies which are not automatically detected -Requires: - - sailfishsilica-qt5 >= 0.10.9 - -RpmLintIgnore: - - arch-dependent-file-in-usr-share - - filename-too-long-for-joliet -# All installed files -Files: - - '%{_bindir}/%{name}' - - '%{_datadir}/%{name}' - - '%{_datadir}/applications/%{name}.desktop' - - '%{_datadir}/icons/hicolor/*/apps/%{name}.png' - - '%{_datadir}/lipstick/notificationcategories/*.conf' - - '%{_datadir}/ngfd/events.d/*.ini' - - '%{_datadir}/dbus-1/services/*.service' - - '%{_libdir}/systemd/user/harbour-sailorgram-notifications.service' - - '%{_libdir}/systemd/user/post-user-session.target.wants/harbour-sailorgram-notifications.service' - - '%{_sysconfdir}/mce/10sailorgram-led.ini' - - '%exclude %{_libdir}/cmake/*' - - '%exclude %{_libdir}/debug/*' - -# For more information about yaml and what's supported in Sailfish OS -# build system, please see https://wiki.merproject.org/wiki/Spectacle - diff --git a/harbour-sailorgram/src/dbus/interface/sailorgraminterface.cpp b/harbour-sailorgram/src/dbus/interface/sailorgraminterface.cpp index c3d44d50..ba2595b4 100644 --- a/harbour-sailorgram/src/dbus/interface/sailorgraminterface.cpp +++ b/harbour-sailorgram/src/dbus/interface/sailorgraminterface.cpp @@ -14,14 +14,14 @@ SailorgramInterface::SailorgramInterface(QObject *parent) : QObject(parent) return; } + if(!connection.registerObject("/", this)) + qWarning() << connection.lastError().message(); + if(!connection.registerService(SailorgramInterface::INTERFACE_NAME)) { qWarning() << connection.lastError().message(); return; } - - if(!connection.registerObject("/", this)) - qWarning() << connection.lastError().message(); } void SailorgramInterface::sendWakeUp() diff --git a/harbour-sailorgram/src/harbour-sailorgram.cpp b/harbour-sailorgram/src/harbour-sailorgram.cpp index 5de4e05a..92bd900e 100644 --- a/harbour-sailorgram/src/harbour-sailorgram.cpp +++ b/harbour-sailorgram/src/harbour-sailorgram.cpp @@ -13,13 +13,14 @@ int main(int argc, char *argv[]) QScopedPointer application(SailfishApp::application(argc, argv)); application->setApplicationName("harbour-sailorgram"); application->setApplicationVersion("0.9"); - application->addLibraryPath(QString("%1/../share/%2/lib").arg(qApp->applicationDirPath(), qApp->applicationName())); +// application->addLibraryPath(QString("%1/../share/%2/lib").arg(qApp->applicationDirPath(), qApp->applicationName())); QStringList args = application->arguments(); bool daemonized = args.contains("-daemon"); - if(daemonized && !SailorGram::hasDaemonFile()) - return 0; +// if(daemonized && !SailorGram::hasDaemonFile()) { // segfault on using SailorGram::hasDaemonFile +// return 0; +// } QDBusConnection sessionbus = QDBusConnection::sessionBus(); @@ -47,13 +48,15 @@ int main(int argc, char *argv[]) QQmlEngine* engine = view->engine(); QObject::connect(engine, SIGNAL(quit()), application.data(), SLOT(quit())); engine->addImageProvider(QStringLiteral("thumbnail"), new ThumbnailProvider); + view->rootContext()->setContextProperty("quickView", view.data()); view->setSource(SailfishApp::pathTo("qml/harbour-sailorgram.qml")); - if(daemonized) - application->setQuitOnLastWindowClosed(false); - else + if(daemonized) { + view->create(); + } else { view->show(); + } return application->exec(); } diff --git a/harbour-sailorgram/src/sailorgram.cpp b/harbour-sailorgram/src/sailorgram.cpp index 6ee06928..15a1ef39 100644 --- a/harbour-sailorgram/src/sailorgram.cpp +++ b/harbour-sailorgram/src/sailorgram.cpp @@ -6,12 +6,16 @@ const QString SailorGram::DAEMON_FILE = "daemon"; const QString SailorGram::PUBLIC_KEY_FILE = "public.key"; const QString SailorGram::EMOJI_FOLDER = "emoji"; const QString SailorGram::APPLICATION_PRETTY_NAME = "SailorGram"; +const QString SailorGram::SYSTEMD_SERVICE = "/usr/lib/systemd/user/harbour-sailorgram-notifications.service"; +const QString SailorGram::SYSTEMD_ENABLER_DIR = QStringLiteral("%1/.config/systemd/user/post-user-session.target.wants").arg(QDir::homePath()); +const QString SailorGram::SYSTEMD_ENABLER = QStringLiteral("%1/harbour-sailorgram-notifications.service").arg(SailorGram::SYSTEMD_ENABLER_DIR); -SailorGram::SailorGram(QObject *parent): QObject(parent), _telegram(NULL), _daemonized(false) +SailorGram::SailorGram(QObject *parent): QObject(parent), _telegram(NULL), _daemonized(false), _view(NULL) { this->_interface = new SailorgramInterface(this); this->_notifications = new TelegramNotifications(this); - //this->_autostart = !SailorGram::hasDaemonFile(); + + qApp->setQuitOnLastWindowClosed(!autostart()); connect(qApp, &QGuiApplication::applicationStateChanged, this, &SailorGram::onApplicationStateChanged); connect(this->_notifications, &TelegramNotifications::newMessage, this, &SailorGram::notify); @@ -26,7 +30,7 @@ Telegram *SailorGram::telegram() const bool SailorGram::autostart() const { - return this->_autostart; + return QFile::exists(SailorGram::SYSTEMD_ENABLER); } bool SailorGram::keepRunning() const @@ -118,6 +122,11 @@ QList SailorGram::translations() const return trlist; } +QQuickView *SailorGram::view() const +{ + return this->_view; +} + void SailorGram::setTelegram(Telegram *telegram) { if(this->_telegram == telegram) @@ -139,25 +148,35 @@ void SailorGram::setKeepRunning(bool keep) void SailorGram::setAutostart(bool autostart) { - if(this->_autostart == autostart) + if (this->autostart() == autostart) { return; + } - this->_autostart = autostart; - - QDir dir(TelegramConfig_storagePath); + qApp->setQuitOnLastWindowClosed(!autostart); if(autostart) { - QFile file(dir.absoluteFilePath(SailorGram::DAEMON_FILE)); - file.open(QFile::WriteOnly); - file.close(); + if (!QDir(SailorGram::SYSTEMD_ENABLER_DIR).exists()) { + QDir::home().mkpath(SailorGram::SYSTEMD_ENABLER_DIR); + } + QFile::link(SailorGram::SYSTEMD_SERVICE, SailorGram::SYSTEMD_ENABLER); + } + else { + QFile::remove(SailorGram::SYSTEMD_ENABLER); } - else - QFile::remove(dir.absoluteFilePath(SailorGram::DAEMON_FILE)); emit autostartChanged(); } +void SailorGram::setView(QQuickView *view) +{ + if(this->_view == view) + return; + + this->_view = view; + emit viewChanged(); +} + bool SailorGram::hasDaemonFile() { QDir dir(TelegramConfig_storagePath); @@ -257,5 +276,13 @@ void SailorGram::onWakeUpRequested() emit daemonizedChanged(); } + if(this->_view) { + if (this->_view->isActive()) { + this->_view->raise(); + } else { + this->_view->show(); + } + } + emit wakeUpRequested(); } diff --git a/harbour-sailorgram/src/sailorgram.h b/harbour-sailorgram/src/sailorgram.h index f9221d35..4d2ad895 100644 --- a/harbour-sailorgram/src/sailorgram.h +++ b/harbour-sailorgram/src/sailorgram.h @@ -2,6 +2,7 @@ #define SAILORGRAM_H #include +#include #include #include #include "dbus/interface/sailorgraminterface.h" @@ -25,6 +26,7 @@ class SailorGram : public QObject Q_PROPERTY(QString voiceRecordPath READ voiceRecordPath CONSTANT FINAL) Q_PROPERTY(TelegramNotifications* notifications READ notifications CONSTANT FINAL) Q_PROPERTY(QList translations READ translations CONSTANT FINAL) + Q_PROPERTY(QQuickView* view READ view WRITE setView NOTIFY viewChanged) public: explicit SailorGram(QObject *parent = 0); @@ -41,9 +43,11 @@ class SailorGram : public QObject QString voiceRecordPath() const; TelegramNotifications* notifications() const; QList translations() const; + QQuickView* view() const; void setTelegram(Telegram* telegram); void setKeepRunning(bool keep); void setAutostart(bool autostart); + void setView(QQuickView* view); public: static bool hasDaemonFile(); @@ -63,6 +67,7 @@ class SailorGram : public QObject void autostartChanged(); void keepRunningChanged(); void daemonizedChanged(); + void viewChanged(); void wakeUpRequested(); void openDialogRequested(TLInt dialogid); @@ -72,13 +77,16 @@ class SailorGram : public QObject SailorgramInterface* _interface; Telegram* _telegram; bool _daemonized; - bool _autostart; + QQuickView* _view; private: static const QString DAEMON_FILE; static const QString PUBLIC_KEY_FILE; static const QString EMOJI_FOLDER; static const QString APPLICATION_PRETTY_NAME; + static const QString SYSTEMD_SERVICE; + static const QString SYSTEMD_ENABLER_DIR; + static const QString SYSTEMD_ENABLER; }; #endif // SAILORGRAM_H diff --git a/harbour-sailorgram/translations/harbour-sailorgram.ts b/harbour-sailorgram/translations/harbour-sailorgram.ts index f95f1950..c917b68e 100644 --- a/harbour-sailorgram/translations/harbour-sailorgram.ts +++ b/harbour-sailorgram/translations/harbour-sailorgram.ts @@ -139,20 +139,12 @@ message(s) Save - - Keep running - - - - SailorGram keeps running in background even when closed - - Autostart - SailorGram starts automatically + SailorGram starts automatically and will continue working in background after closing From ff9393a08d2faeb23f4e3a7be0a17a1a2d99a51a Mon Sep 17 00:00:00 2001 From: coderus Date: Wed, 1 Mar 2017 11:24:46 +0300 Subject: [PATCH 02/20] Updated LibQTelegram submodule --- LibQTelegram | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LibQTelegram b/LibQTelegram index 127368a9..14309f75 160000 --- a/LibQTelegram +++ b/LibQTelegram @@ -1 +1 @@ -Subproject commit 127368a962ad0cdc27e7b61f331783eb9e7506e0 +Subproject commit 14309f75c15f339f4ae5d71a0a43c869b406f855 From adc8b5a5da606724a16f40e54662bd02e5353244 Mon Sep 17 00:00:00 2001 From: coderus Date: Wed, 1 Mar 2017 13:47:04 +0300 Subject: [PATCH 03/20] GET RID OF YAML! --- harbour-sailorgram/rpm/harbour-sailorgram.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/harbour-sailorgram/rpm/harbour-sailorgram.spec b/harbour-sailorgram/rpm/harbour-sailorgram.spec index 9095d1a4..4de34dfd 100644 --- a/harbour-sailorgram/rpm/harbour-sailorgram.spec +++ b/harbour-sailorgram/rpm/harbour-sailorgram.spec @@ -7,6 +7,7 @@ Name: harbour-sailorgram %{!?qtc_qmake5:%define qtc_qmake5 %qmake5} %{!?qtc_make:%define qtc_make make} %{?qtc_builddir:%define _builddir %qtc_builddir} + Summary: SailorGram Version: 0.89 Release: 13 @@ -14,7 +15,6 @@ Group: Qt/Qt License: GPL3 URL: https://github.com/QtGram/harbour-sailorgram/ Source0: %{name}-%{version}.tar.bz2 -Source100: harbour-sailorgram.yaml Source101: harbour-sailorgram-rpmlintrc Requires: sailfishsilica-qt5 >= 0.10.9 BuildRequires: pkgconfig(sailfishapp) >= 1.0.2 From 92dc10bde94c939c0d32a10f41bba552cb52b325 Mon Sep 17 00:00:00 2001 From: coderus Date: Wed, 1 Mar 2017 17:29:53 +0300 Subject: [PATCH 04/20] Dont dbus, only systemd --- harbour-sailorgram/dbus/org.harbour.sailorgram.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/harbour-sailorgram/dbus/org.harbour.sailorgram.service b/harbour-sailorgram/dbus/org.harbour.sailorgram.service index 898d8770..4b2a5b1d 100644 --- a/harbour-sailorgram/dbus/org.harbour.sailorgram.service +++ b/harbour-sailorgram/dbus/org.harbour.sailorgram.service @@ -1,5 +1,5 @@ [D-BUS Service] Name=org.harbour.sailorgram Interface=org.harbour.sailorgram -Exec=/usr/bin/invoker --type=generic /usr/bin/harbour-sailorgram +Exec=/bin/false SystemdService=harbour-sailorgram-notifications.service From 55c20df2dbe1973f09cd9517ec44172bb2dfbf61 Mon Sep 17 00:00:00 2001 From: coderus Date: Wed, 1 Mar 2017 17:30:18 +0300 Subject: [PATCH 05/20] Open dialog at last unread message Fixes #2 --- .../qml/components/message/MessagesList.qml | 17 +++++++++++++++-- .../qml/pages/dialog/DialogPage.qml | 4 ++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/harbour-sailorgram/qml/components/message/MessagesList.qml b/harbour-sailorgram/qml/components/message/MessagesList.qml index 1b5b8efe..05c786a4 100644 --- a/harbour-sailorgram/qml/components/message/MessagesList.qml +++ b/harbour-sailorgram/qml/components/message/MessagesList.qml @@ -27,6 +27,21 @@ SilicaListView return selectionlist; } + onCountChanged: { + if (model.newMessageIndex >= 0 && model.newMessageIndex < count) { + positionViewAtIndex(model.newMessageIndex, ListView.Center); + } + } + + Connections { + target: model + onNewMessageIndexChanged: { + if (model.newMessageIndex >= 0 && model.newMessageIndex < count) { + positionViewAtIndex(model.newMessageIndex, ListView.Center); + } + } + } + Connections { target: dialogpage.context.positionSource @@ -47,8 +62,6 @@ SilicaListView verticalLayoutDirection: ListView.BottomToTop currentIndex: -1 - Component.onCompleted: messageslist.positionViewAtIndex(model.newMessageIndex, ListView.Center); - onSelectionModeChanged: { if(selectionMode) { selectedMessages = new Object; diff --git a/harbour-sailorgram/qml/pages/dialog/DialogPage.qml b/harbour-sailorgram/qml/pages/dialog/DialogPage.qml index 0228dccc..c7c7eb8e 100644 --- a/harbour-sailorgram/qml/pages/dialog/DialogPage.qml +++ b/harbour-sailorgram/qml/pages/dialog/DialogPage.qml @@ -24,6 +24,10 @@ Page messagesmodel.dialog = dialog; firstLoad = false; + + if (status == PageStatus.Active && messageslist.model.newMessageIndex >= 0 && messageslist.model.newMessageIndex < messageslist.count) { + messageslist.positionViewAtIndex(messageslist.model.newMessageIndex, ListView.Center); + } } MessagesModel From 95358eb5709e4447057c9ad9c14621fb958e2204 Mon Sep 17 00:00:00 2001 From: coderus Date: Thu, 2 Mar 2017 11:38:09 +0300 Subject: [PATCH 06/20] Move LibQTelegram to fork --- .gitmodules | 2 +- LibQTelegram | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 46d7bf02..641bd77b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "LibQTelegram"] path = LibQTelegram - url = https://github.com/QtGram/LibQTelegram + url = https://github.com/CODeRUS/LibQTelegram.git diff --git a/LibQTelegram b/LibQTelegram index 14309f75..fb854a5a 160000 --- a/LibQTelegram +++ b/LibQTelegram @@ -1 +1 @@ -Subproject commit 14309f75c15f339f4ae5d71a0a43c869b406f855 +Subproject commit fb854a5a49292c2ccc634ce60cf81440b5769a9c From 12511b523d2754eab06cc3914ffdd8f54b5bee9a Mon Sep 17 00:00:00 2001 From: coderus Date: Thu, 2 Mar 2017 11:38:40 +0300 Subject: [PATCH 07/20] Fix position to first unread only on loading --- .../qml/components/message/MessagesList.qml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/harbour-sailorgram/qml/components/message/MessagesList.qml b/harbour-sailorgram/qml/components/message/MessagesList.qml index 05c786a4..fed4befc 100644 --- a/harbour-sailorgram/qml/components/message/MessagesList.qml +++ b/harbour-sailorgram/qml/components/message/MessagesList.qml @@ -27,10 +27,17 @@ SilicaListView return selectionlist; } + property int lastCount + + Component.onCompleted: { + lastCount = count + } + onCountChanged: { - if (model.newMessageIndex >= 0 && model.newMessageIndex < count) { + if (lastCount == 0 && model.newMessageIndex >= 0 && model.newMessageIndex < count) { positionViewAtIndex(model.newMessageIndex, ListView.Center); } + lastCount = count } Connections { From b1a96b72714415c45ff32bb7b417834a887936a8 Mon Sep 17 00:00:00 2001 From: coderus Date: Thu, 2 Mar 2017 14:36:49 +0300 Subject: [PATCH 08/20] Update LibQTelegram submodule --- LibQTelegram | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LibQTelegram b/LibQTelegram index fb854a5a..69337d6f 160000 --- a/LibQTelegram +++ b/LibQTelegram @@ -1 +1 @@ -Subproject commit fb854a5a49292c2ccc634ce60cf81440b5769a9c +Subproject commit 69337d6f9ccddf88f725b7cbebd9e999068ce69e From 187e7a14cfa16002b10bf37b1109d85b81f6336a Mon Sep 17 00:00:00 2001 From: coderus Date: Thu, 2 Mar 2017 14:37:05 +0300 Subject: [PATCH 09/20] Use real application version --- harbour-sailorgram/harbour-sailorgram.pro | 2 ++ harbour-sailorgram/qml/model/Context.qml | 4 ++-- harbour-sailorgram/rpm/harbour-sailorgram.spec | 2 +- harbour-sailorgram/src/harbour-sailorgram.cpp | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/harbour-sailorgram/harbour-sailorgram.pro b/harbour-sailorgram/harbour-sailorgram.pro index 9409cf4b..284b2476 100644 --- a/harbour-sailorgram/harbour-sailorgram.pro +++ b/harbour-sailorgram/harbour-sailorgram.pro @@ -14,6 +14,8 @@ TARGET = harbour-sailorgram include($$PWD/../config.pri) +DEFINES += APP_VERSION=\\\"$$VERSION\\\" + CONFIG += sailfishapp QT += sql dbus multimedia diff --git a/harbour-sailorgram/qml/model/Context.qml b/harbour-sailorgram/qml/model/Context.qml index 6f9b1389..913f9705 100644 --- a/harbour-sailorgram/qml/model/Context.qml +++ b/harbour-sailorgram/qml/model/Context.qml @@ -11,9 +11,9 @@ Item readonly property string apiHash: "5ce096f34c8afab871edce728e6d64c9" readonly property string hereAppId: "MqR7KyY6dZpTbKiFwc3h" readonly property string hereAppCode: "zfYp6V9Ou_wDQn4NVqMofA" - readonly property string version: "0.89" + readonly property string version: Qt.application.version readonly property bool beta: true - readonly property int betanum: 4 + readonly property int betanum: 999 readonly property bool reconnecting: reconnectTimer.running diff --git a/harbour-sailorgram/rpm/harbour-sailorgram.spec b/harbour-sailorgram/rpm/harbour-sailorgram.spec index 4de34dfd..9c49c12a 100644 --- a/harbour-sailorgram/rpm/harbour-sailorgram.spec +++ b/harbour-sailorgram/rpm/harbour-sailorgram.spec @@ -39,7 +39,7 @@ An unofficial Telegram Client for SailfishOS %build -%qtc_qmake5 +%qtc_qmake5 VERSION=%{version} %qtc_make %{?_smp_mflags} diff --git a/harbour-sailorgram/src/harbour-sailorgram.cpp b/harbour-sailorgram/src/harbour-sailorgram.cpp index 92bd900e..da26c30c 100644 --- a/harbour-sailorgram/src/harbour-sailorgram.cpp +++ b/harbour-sailorgram/src/harbour-sailorgram.cpp @@ -12,7 +12,7 @@ int main(int argc, char *argv[]) { QScopedPointer application(SailfishApp::application(argc, argv)); application->setApplicationName("harbour-sailorgram"); - application->setApplicationVersion("0.9"); + application->setApplicationVersion(QString(APP_VERSION)); // application->addLibraryPath(QString("%1/../share/%2/lib").arg(qApp->applicationDirPath(), qApp->applicationName())); QStringList args = application->arguments(); From 4119ba75d6c8ac3f01f93a4ee1cbb343995f3bb4 Mon Sep 17 00:00:00 2001 From: coderus Date: Thu, 2 Mar 2017 14:37:27 +0300 Subject: [PATCH 10/20] Set proper delegate width --- harbour-sailorgram/qml/components/message/MessagesList.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/harbour-sailorgram/qml/components/message/MessagesList.qml b/harbour-sailorgram/qml/components/message/MessagesList.qml index fed4befc..55da83f8 100644 --- a/harbour-sailorgram/qml/components/message/MessagesList.qml +++ b/harbour-sailorgram/qml/components/message/MessagesList.qml @@ -83,7 +83,7 @@ SilicaListView } delegate: Column { - width: parent.width + width: ListView.view.width spacing: Theme.paddingSmall NewMessage { id: newmessage; visible: model.isMessageNew } From f92af73281ad595c4232a0cda2a9d4d646675d51 Mon Sep 17 00:00:00 2001 From: coderus Date: Thu, 2 Mar 2017 17:03:36 +0300 Subject: [PATCH 11/20] Update LibQTelegram submodule --- LibQTelegram | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LibQTelegram b/LibQTelegram index 69337d6f..cc9d32de 160000 --- a/LibQTelegram +++ b/LibQTelegram @@ -1 +1 @@ -Subproject commit 69337d6f9ccddf88f725b7cbebd9e999068ce69e +Subproject commit cc9d32dedd8589b89a75e9b9cb03e0b87ede2bb5 From c19b29f579bc011b0db9fdf1aa85dd65744b6698 Mon Sep 17 00:00:00 2001 From: coderus Date: Thu, 2 Mar 2017 18:02:25 +0300 Subject: [PATCH 12/20] Fix version number --- harbour-sailorgram/harbour-sailorgram.pro | 2 +- harbour-sailorgram/rpm/harbour-sailorgram.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/harbour-sailorgram/harbour-sailorgram.pro b/harbour-sailorgram/harbour-sailorgram.pro index 284b2476..9f949b3a 100644 --- a/harbour-sailorgram/harbour-sailorgram.pro +++ b/harbour-sailorgram/harbour-sailorgram.pro @@ -14,7 +14,7 @@ TARGET = harbour-sailorgram include($$PWD/../config.pri) -DEFINES += APP_VERSION=\\\"$$VERSION\\\" +DEFINES += APP_VERSION=\\\"$$APP_VERSION\\\" CONFIG += sailfishapp QT += sql dbus multimedia diff --git a/harbour-sailorgram/rpm/harbour-sailorgram.spec b/harbour-sailorgram/rpm/harbour-sailorgram.spec index 9c49c12a..748f2bb0 100644 --- a/harbour-sailorgram/rpm/harbour-sailorgram.spec +++ b/harbour-sailorgram/rpm/harbour-sailorgram.spec @@ -39,7 +39,7 @@ An unofficial Telegram Client for SailfishOS %build -%qtc_qmake5 VERSION=%{version} +%qtc_qmake5 APP_VERSION=%{version} %qtc_make %{?_smp_mflags} From 2a518a7fd6f9a2869ee615713674981198a1c39e Mon Sep 17 00:00:00 2001 From: coderus Date: Fri, 3 Mar 2017 10:47:09 +0300 Subject: [PATCH 13/20] Restart daemon on crashes --- .../systemd/harbour-sailorgram-notifications.service | 2 ++ 1 file changed, 2 insertions(+) diff --git a/harbour-sailorgram/systemd/harbour-sailorgram-notifications.service b/harbour-sailorgram/systemd/harbour-sailorgram-notifications.service index 21b0588f..fa27d54d 100644 --- a/harbour-sailorgram/systemd/harbour-sailorgram-notifications.service +++ b/harbour-sailorgram/systemd/harbour-sailorgram-notifications.service @@ -7,6 +7,8 @@ After=lipstick.service Type=dbus ExecStart=/usr/bin/invoker --type=generic /usr/bin/harbour-sailorgram -daemon BusName=org.harbour.sailorgram +Restart=on-failure +RestartSec=5 [Install] WantedBy=post-user-session.target From 97a263f50a1d4d8786f1e98527adc0e062cbad42 Mon Sep 17 00:00:00 2001 From: coderus Date: Fri, 3 Mar 2017 10:47:23 +0300 Subject: [PATCH 14/20] Update LibQTelegram submodule --- LibQTelegram | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LibQTelegram b/LibQTelegram index cc9d32de..f8ec9045 160000 --- a/LibQTelegram +++ b/LibQTelegram @@ -1 +1 @@ -Subproject commit cc9d32dedd8589b89a75e9b9cb03e0b87ede2bb5 +Subproject commit f8ec9045e034d7c43d8a44c840cb9162bf8cc5a4 From fefa92765888e1721d483af3f93201d234c4c828 Mon Sep 17 00:00:00 2001 From: coderus Date: Fri, 3 Mar 2017 10:47:42 +0300 Subject: [PATCH 15/20] Dismiss notification on read dialogs --- harbour-sailorgram/src/sailorgram.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/harbour-sailorgram/src/sailorgram.cpp b/harbour-sailorgram/src/sailorgram.cpp index 15a1ef39..5f499159 100644 --- a/harbour-sailorgram/src/sailorgram.cpp +++ b/harbour-sailorgram/src/sailorgram.cpp @@ -19,6 +19,7 @@ SailorGram::SailorGram(QObject *parent): QObject(parent), _telegram(NULL), _daem connect(qApp, &QGuiApplication::applicationStateChanged, this, &SailorGram::onApplicationStateChanged); connect(this->_notifications, &TelegramNotifications::newMessage, this, &SailorGram::notify); + connect(this->_notifications, &TelegramNotifications::dismissNotification, this, &SailorGram::closeNotification); connect(this->_interface, &SailorgramInterface::wakeUpRequested, this, &SailorGram::onWakeUpRequested); connect(this->_interface, &SailorgramInterface::openDialogRequested, this, &SailorGram::openDialogRequested); } From c762eae7a39fea635ea7eb4a7f7f75db5de612d8 Mon Sep 17 00:00:00 2001 From: coderus Date: Fri, 3 Mar 2017 12:08:26 +0300 Subject: [PATCH 16/20] Fix opening application from background mode --- harbour-sailorgram/harbour-sailorgram.desktop | 1 + 1 file changed, 1 insertion(+) diff --git a/harbour-sailorgram/harbour-sailorgram.desktop b/harbour-sailorgram/harbour-sailorgram.desktop index bc012411..4652b496 100644 --- a/harbour-sailorgram/harbour-sailorgram.desktop +++ b/harbour-sailorgram/harbour-sailorgram.desktop @@ -1,6 +1,7 @@ [Desktop Entry] Type=Application X-Nemo-Application-Type=silica-qt5 +X-Nemo-Single-Instance=no Icon=harbour-sailorgram Exec=harbour-sailorgram %U Name=SailorGram From e85c12b1701b889919cb09f4e95da5561aa60c02 Mon Sep 17 00:00:00 2001 From: coderus Date: Fri, 3 Mar 2017 12:58:55 +0300 Subject: [PATCH 17/20] Make hidden header option to work as expected --- harbour-sailorgram/qml/components/dialog/DialogTopHeader.qml | 2 +- harbour-sailorgram/qml/pages/dialog/DialogPage.qml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/harbour-sailorgram/qml/components/dialog/DialogTopHeader.qml b/harbour-sailorgram/qml/components/dialog/DialogTopHeader.qml index c12a489e..a87a2814 100644 --- a/harbour-sailorgram/qml/components/dialog/DialogTopHeader.qml +++ b/harbour-sailorgram/qml/components/dialog/DialogTopHeader.qml @@ -12,7 +12,7 @@ BackgroundRectangle id: dialogtopheader width: parent.width - height: Theme.itemSizeSmall + (Theme.paddingSmall * 2) + implicitHeight: Theme.itemSizeSmall + (Theme.paddingSmall * 2) Column { diff --git a/harbour-sailorgram/qml/pages/dialog/DialogPage.qml b/harbour-sailorgram/qml/pages/dialog/DialogPage.qml index c7c7eb8e..500c1da5 100644 --- a/harbour-sailorgram/qml/pages/dialog/DialogPage.qml +++ b/harbour-sailorgram/qml/pages/dialog/DialogPage.qml @@ -104,6 +104,7 @@ Page statusText: messagesmodel.statusText peer: dialogpage.dialog visible: !context.chatheaderhidden && dialogpage.isPortrait + height: visible ? implicitHeight : 0 } MessagesList From f0bf07dfc3237c27c7477fd34d350e9afc29a7fd Mon Sep 17 00:00:00 2001 From: coderus Date: Fri, 3 Mar 2017 17:24:51 +0300 Subject: [PATCH 18/20] Update LibQTelegram submodule --- LibQTelegram | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LibQTelegram b/LibQTelegram index f8ec9045..1e5df07c 160000 --- a/LibQTelegram +++ b/LibQTelegram @@ -1 +1 @@ -Subproject commit f8ec9045e034d7c43d8a44c840cb9162bf8cc5a4 +Subproject commit 1e5df07c856372e69e766a56d1863d54a8b9f230 From c281c2f6d4092938aedfc23e8fd54e3d2108d2d4 Mon Sep 17 00:00:00 2001 From: coderus Date: Tue, 14 Mar 2017 14:02:07 +0300 Subject: [PATCH 19/20] Update LibQTelegram submodule --- LibQTelegram | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LibQTelegram b/LibQTelegram index 1e5df07c..8078eac8 160000 --- a/LibQTelegram +++ b/LibQTelegram @@ -1 +1 @@ -Subproject commit 1e5df07c856372e69e766a56d1863d54a8b9f230 +Subproject commit 8078eac80310215b0cdab2f766fca2899d25b473 From bf9025edd87d422012307e205a6b4248a3950ab9 Mon Sep 17 00:00:00 2001 From: coderus Date: Tue, 14 Mar 2017 14:05:39 +0300 Subject: [PATCH 20/20] Back to upstream submodule please commit final LibQTelegram revision after merge --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 641bd77b..46d7bf02 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "LibQTelegram"] path = LibQTelegram - url = https://github.com/CODeRUS/LibQTelegram.git + url = https://github.com/QtGram/LibQTelegram