From 078a5091837c9b6a7e9221d1c718720120f29b36 Mon Sep 17 00:00:00 2001 From: Sebastian Wolf Date: Wed, 1 Sep 2021 00:37:15 +0200 Subject: [PATCH] Contact synchronization also via settings --- harbour-fernschreiber.pro | 1 + qml/components/ContactSync.qml | 45 ++++++++++++++++ .../settingsPage/SettingsUserProfile.qml | 53 +++++++++++++++++++ qml/pages/NewChatPage.qml | 39 +++++++------- translations/harbour-fernschreiber-de.ts | 15 ++++++ translations/harbour-fernschreiber-en.ts | 15 ++++++ translations/harbour-fernschreiber-es.ts | 15 ++++++ translations/harbour-fernschreiber-fi.ts | 15 ++++++ translations/harbour-fernschreiber-hu.ts | 15 ++++++ translations/harbour-fernschreiber-it.ts | 15 ++++++ translations/harbour-fernschreiber-pl.ts | 15 ++++++ translations/harbour-fernschreiber-ru.ts | 15 ++++++ translations/harbour-fernschreiber-sk.ts | 15 ++++++ translations/harbour-fernschreiber-sv.ts | 15 ++++++ translations/harbour-fernschreiber-zh_CN.ts | 15 ++++++ translations/harbour-fernschreiber.ts | 15 ++++++ 16 files changed, 298 insertions(+), 20 deletions(-) create mode 100644 qml/components/ContactSync.qml diff --git a/harbour-fernschreiber.pro b/harbour-fernschreiber.pro index 8af8d3d..3e92ced 100644 --- a/harbour-fernschreiber.pro +++ b/harbour-fernschreiber.pro @@ -44,6 +44,7 @@ DISTFILES += qml/harbour-fernschreiber.qml \ qml/components/AudioPreview.qml \ qml/components/BackgroundImage.qml \ qml/components/ChatListViewItem.qml \ + qml/components/ContactSync.qml \ qml/components/DocumentPreview.qml \ qml/components/GamePreview.qml \ qml/components/ImagePreview.qml \ diff --git a/qml/components/ContactSync.qml b/qml/components/ContactSync.qml new file mode 100644 index 0000000..8a60c00 --- /dev/null +++ b/qml/components/ContactSync.qml @@ -0,0 +1,45 @@ +/* + Copyright (C) 2021 Sebastian J. Wolf and other contributors + + This file is part of Fernschreiber. + + Fernschreiber is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Fernschreiber is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Fernschreiber. If not, see . +*/ +import QtQuick 2.0 +import org.nemomobile.contacts 1.0 + +Item { + + signal syncError(); + + function synchronize() { + if (peopleModel.count === 0) { + appNotification.show(qsTr("Could not synchronize your contacts with Telegram.")); + syncError(); + } else { + contactsModel.startImportingContacts(); + for (var i = 0; i < peopleModel.count; i++ ) { + contactsModel.importContact(peopleModel.get(i)); + } + contactsModel.stopImportingContacts(); + } + } + + PeopleModel { + id: peopleModel + filterType: PeopleModel.FilterAll + requiredProperty: PeopleModel.PhoneNumberRequired + } + +} diff --git a/qml/components/settingsPage/SettingsUserProfile.qml b/qml/components/settingsPage/SettingsUserProfile.qml index 0b6f901..004e9aa 100644 --- a/qml/components/settingsPage/SettingsUserProfile.qml +++ b/qml/components/settingsPage/SettingsUserProfile.qml @@ -34,6 +34,7 @@ AccordionItem { readonly property var userInformation: tdLibWrapper.getUserInformation() property bool uploadInProgress: false + property bool contactSyncEnabled: false Component.onCompleted: { tdLibWrapper.getUserProfilePhotos(userInformation.id, 100, 0); @@ -152,6 +153,49 @@ AccordionItem { } + Column { + id: contactSyncItem + width: parent.width + height: syncInProgress ? ( syncContactsBusyIndicator.height + Theme.paddingMedium ) : ( syncContactsButton.height + Theme.paddingMedium ) + visible: accordionContent.contactSyncEnabled + + property bool syncInProgress: false + + Connections { + target: contactSyncLoader.item + onSyncError: { + contactSyncItem.syncInProgress = false; + } + } + + Connections { + target: tdLibWrapper + onContactsImported: { + appNotification.show(qsTr("Contacts successfully synchronized with Telegram.")); + } + } + + Button { + id: syncContactsButton + text: qsTr("Synchronize Contacts with Telegram") + visible: !contactSyncItem.syncInProgress + anchors { + horizontalCenter: parent.horizontalCenter + } + onClicked: { + contactSyncLoader.item.synchronize(); + } + } + + BusyIndicator { + id: syncContactsBusyIndicator + anchors.horizontalCenter: parent.horizontalCenter + running: contactSyncItem.syncInProgress + size: BusyIndicatorSize.Small + visible: running + } + } + SectionHeader { horizontalAlignment: Text.AlignLeft text: qsTr("Profile Pictures") @@ -246,6 +290,15 @@ AccordionItem { } + Loader { + id: contactSyncLoader + source: "../ContactSync.qml" + active: true + onLoaded: { + accordionContent.contactSyncEnabled = true; + } + } + Component { id: imagePickerPage ImagePickerPage { diff --git a/qml/pages/NewChatPage.qml b/qml/pages/NewChatPage.qml index 54e3f19..8bf40ef 100644 --- a/qml/pages/NewChatPage.qml +++ b/qml/pages/NewChatPage.qml @@ -18,7 +18,6 @@ */ import QtQuick 2.6 import Sailfish.Silica 1.0 -import org.nemomobile.contacts 1.0 import "../components" import "../js/twemoji.js" as Emoji import "../js/functions.js" as Functions @@ -59,21 +58,29 @@ Page { Component.onCompleted: { var sailfishOSVersion = fernschreiberUtils.getSailfishOSVersion().split("."); + // With Sailfish OS 4 we can't get up-to-date contacts with the standard database anymore. We might need to enter Sailjail eventually... + // Details see https://forum.sailfishos.org/t/4-0-1-45-non-jailed-contacts-sqlite-database-no-longer-updated/4724 + // We try it with the inofficial Nemo Contact API via a loader... if (parseInt(sailfishOSVersion[0]) < 4) { Debug.log("Sailfish OS version 3.x - contact sync should still be possible...") newChatPage.syncSupported = true; - } else { - // With Sailfish OS 4 we can't get up-to-date contacts with the standard database anymore. We might need to enter Sailjail eventually... - // Details see https://forum.sailfishos.org/t/4-0-1-45-non-jailed-contacts-sqlite-database-no-longer-updated/4724 - // We try it with the inofficial Nemo Contact API... - newChatPage.nemoSync = true; } } - PeopleModel { - id: peopleModel - filterType: PeopleModel.FilterAll - requiredProperty: PeopleModel.PhoneNumberRequired + Connections { + target: contactSyncLoader.item + onSyncError: { + newChatPage.isLoading = false; + } + } + + Loader { + id: contactSyncLoader + source: "../components/ContactSync.qml" + active: true + onLoaded: { + newChatPage.nemoSync = true; + } } SilicaFlickable { @@ -82,20 +89,12 @@ Page { anchors.fill: parent PullDownMenu { + enabled: newChatPage.syncSupported || newChatPage.nemoSync MenuItem { onClicked: { newChatPage.isLoading = true; if (newChatPage.nemoSync) { - if (peopleModel.count === 0) { - appNotification.show(qsTr("Could not synchronize your contacts with Telegram.")); - newChatPage.isLoading = false; - } else { - contactsModel.startImportingContacts(); - for (var i = 0; i < peopleModel.count; i++ ) { - contactsModel.importContact(peopleModel.get(i)); - } - contactsModel.stopImportingContacts(); - } + contactSyncLoader.item.synchronize(); } if (newChatPage.syncSupported) { if (!contactsModel.synchronizeContacts()) { diff --git a/translations/harbour-fernschreiber-de.ts b/translations/harbour-fernschreiber-de.ts index 70ced0b..b426242 100644 --- a/translations/harbour-fernschreiber-de.ts +++ b/translations/harbour-fernschreiber-de.ts @@ -534,6 +534,13 @@ Sie haben noch keine Chats. + + ContactSync + + Could not synchronize your contacts with Telegram. + Konnte Ihre Kontakte nicht mit Telegram synchronisieren. + + CoverPage @@ -1756,6 +1763,14 @@ Uploading... Lade hoch... + + Synchronize Contacts with Telegram + Kontakte mit Telegram synchronisieren + + + Contacts successfully synchronized with Telegram. + Die Kontakte wurden erfolgreich mit Telegram synchronisiert. + StickerPicker diff --git a/translations/harbour-fernschreiber-en.ts b/translations/harbour-fernschreiber-en.ts index aca08b4..311d885 100644 --- a/translations/harbour-fernschreiber-en.ts +++ b/translations/harbour-fernschreiber-en.ts @@ -534,6 +534,13 @@ You don't have any chats yet. + + ContactSync + + Could not synchronize your contacts with Telegram. + Could not synchronize your contacts with Telegram. + + CoverPage @@ -1758,6 +1765,14 @@ messages Uploading... Uploading... + + Synchronize Contacts with Telegram + Synchronize Contacts with Telegram + + + Contacts successfully synchronized with Telegram. + Contacts successfully synchronized with Telegram. + StickerPicker diff --git a/translations/harbour-fernschreiber-es.ts b/translations/harbour-fernschreiber-es.ts index fe7de69..c3c212a 100644 --- a/translations/harbour-fernschreiber-es.ts +++ b/translations/harbour-fernschreiber-es.ts @@ -534,6 +534,13 @@ No hay todavía conversaciones. + + ContactSync + + Could not synchronize your contacts with Telegram. + No se pudieron sincronizar los contactos con Telegram. + + CoverPage @@ -1756,6 +1763,14 @@ Uploading... Subiendo... + + Synchronize Contacts with Telegram + Sincronizar con Telegram + + + Contacts successfully synchronized with Telegram. + Contactos sincronizados con éxito con Telegram. + StickerPicker diff --git a/translations/harbour-fernschreiber-fi.ts b/translations/harbour-fernschreiber-fi.ts index eb6c5cf..0304ea0 100644 --- a/translations/harbour-fernschreiber-fi.ts +++ b/translations/harbour-fernschreiber-fi.ts @@ -534,6 +534,13 @@ Sinulla ei ole vielä keskusteluja. + + ContactSync + + Could not synchronize your contacts with Telegram. + Yhteystietojasi ei voitu synkronoida Telegramin kanssa. + + CoverPage @@ -1757,6 +1764,14 @@ Uploading... Lähetetään... + + Synchronize Contacts with Telegram + Synkronoi yhteystiedot Telegramin kanssa + + + Contacts successfully synchronized with Telegram. + Yhteystietojen synkronointi Telegramin kanssa onnistui. + StickerPicker diff --git a/translations/harbour-fernschreiber-hu.ts b/translations/harbour-fernschreiber-hu.ts index b217643..a42fd6d 100644 --- a/translations/harbour-fernschreiber-hu.ts +++ b/translations/harbour-fernschreiber-hu.ts @@ -524,6 +524,13 @@ + + ContactSync + + Could not synchronize your contacts with Telegram. + + + CoverPage @@ -1729,6 +1736,14 @@ Uploading... + + Synchronize Contacts with Telegram + + + + Contacts successfully synchronized with Telegram. + + StickerPicker diff --git a/translations/harbour-fernschreiber-it.ts b/translations/harbour-fernschreiber-it.ts index cf3d994..3dd388c 100644 --- a/translations/harbour-fernschreiber-it.ts +++ b/translations/harbour-fernschreiber-it.ts @@ -534,6 +534,13 @@ Nessuna chat presente + + ContactSync + + Could not synchronize your contacts with Telegram. + Sincronizzazione contatti con Telegram non riuscita + + CoverPage @@ -1756,6 +1763,14 @@ Uploading... Carica... + + Synchronize Contacts with Telegram + Sincronizza contatti con Telegram + + + Contacts successfully synchronized with Telegram. + Sincronizzazione contatti con Telegram completata + StickerPicker diff --git a/translations/harbour-fernschreiber-pl.ts b/translations/harbour-fernschreiber-pl.ts index bfbb223..feb5b0c 100644 --- a/translations/harbour-fernschreiber-pl.ts +++ b/translations/harbour-fernschreiber-pl.ts @@ -544,6 +544,13 @@ Nie masz jeszcze żadnych czatów. + + ContactSync + + Could not synchronize your contacts with Telegram. + Nie można zsynchonizaować kontaktów z Telegramem. + + CoverPage @@ -1783,6 +1790,14 @@ Uploading... Przesyłanie... + + Synchronize Contacts with Telegram + Synchronizuj kontakty z Telegramem + + + Contacts successfully synchronized with Telegram. + Synchronizacja kontaktów z Telegramem zakończona sukcesem. + StickerPicker diff --git a/translations/harbour-fernschreiber-ru.ts b/translations/harbour-fernschreiber-ru.ts index 6549fee..63aed91 100644 --- a/translations/harbour-fernschreiber-ru.ts +++ b/translations/harbour-fernschreiber-ru.ts @@ -544,6 +544,13 @@ Тут пока ничего нет + + ContactSync + + Could not synchronize your contacts with Telegram. + Невозможно синхронизировать ваши контакты с Телеграм. + + CoverPage @@ -1786,6 +1793,14 @@ Uploading... Отправка... + + Synchronize Contacts with Telegram + Синхронизировать с Телеграм + + + Contacts successfully synchronized with Telegram. + Контакты успешно синхронизированы с Телеграм. + StickerPicker diff --git a/translations/harbour-fernschreiber-sk.ts b/translations/harbour-fernschreiber-sk.ts index 4342e73..3d1c4f8 100644 --- a/translations/harbour-fernschreiber-sk.ts +++ b/translations/harbour-fernschreiber-sk.ts @@ -544,6 +544,13 @@ Nemáte žiadne čety. + + ContactSync + + Could not synchronize your contacts with Telegram. + Nemožno synchonizovať kontakty s Telegramom. + + CoverPage @@ -1783,6 +1790,14 @@ Uploading... Zapisovanie... + + Synchronize Contacts with Telegram + Synchronizovať kontakty s Telegramom + + + Contacts successfully synchronized with Telegram. + Kontakty boli úspešne synchronizované s Telegramom. + StickerPicker diff --git a/translations/harbour-fernschreiber-sv.ts b/translations/harbour-fernschreiber-sv.ts index 20c7557..24acbd4 100644 --- a/translations/harbour-fernschreiber-sv.ts +++ b/translations/harbour-fernschreiber-sv.ts @@ -534,6 +534,13 @@ Du har inga chattar än. + + ContactSync + + Could not synchronize your contacts with Telegram. + Kunde inte synkronisera dina kontakter med Telegram. + + CoverPage @@ -1756,6 +1763,14 @@ Uploading... Ladda upp... + + Synchronize Contacts with Telegram + Synkronisera kontakter med Telegram + + + Contacts successfully synchronized with Telegram. + Kontakter synkroniserade med Telegram. + StickerPicker diff --git a/translations/harbour-fernschreiber-zh_CN.ts b/translations/harbour-fernschreiber-zh_CN.ts index 9500bb7..abe429c 100644 --- a/translations/harbour-fernschreiber-zh_CN.ts +++ b/translations/harbour-fernschreiber-zh_CN.ts @@ -524,6 +524,13 @@ 你还没有任何对话。 + + ContactSync + + Could not synchronize your contacts with Telegram. + 无法同步你的云端 Telegram 联系人。 + + CoverPage @@ -1730,6 +1737,14 @@ Uploading... 正在上传… + + Synchronize Contacts with Telegram + 同步 Telegram 联系人 + + + Contacts successfully synchronized with Telegram. + 已成功同步 Telegram 联系人。 + StickerPicker diff --git a/translations/harbour-fernschreiber.ts b/translations/harbour-fernschreiber.ts index 6b751c7..b898004 100644 --- a/translations/harbour-fernschreiber.ts +++ b/translations/harbour-fernschreiber.ts @@ -534,6 +534,13 @@ You don't have any chats yet. + + ContactSync + + Could not synchronize your contacts with Telegram. + + + CoverPage @@ -1756,6 +1763,14 @@ Uploading... Uploading... + + Synchronize Contacts with Telegram + + + + Contacts successfully synchronized with Telegram. + + StickerPicker