Synchronize contacts with Nemomobile QML API
This commit is contained in:
parent
dce28370b5
commit
3b387afa01
7 changed files with 72 additions and 10 deletions
|
@ -201,8 +201,11 @@ fernschreiber.desktop.files = harbour-fernschreiber.desktop
|
|||
database.files = db
|
||||
database.path = /usr/share/$${TARGET}
|
||||
|
||||
mapplauncher.path = /usr/share/mapplauncherd/privileges.d
|
||||
mapplauncher.files = privileges/harbour-fernschreiber.privileges
|
||||
|
||||
INSTALLS += telegram 86.png 108.png 128.png 172.png 256.png \
|
||||
fernschreiber.desktop gui images database
|
||||
fernschreiber.desktop gui images database mapplauncher
|
||||
|
||||
HEADERS += \
|
||||
src/appsettings.h \
|
||||
|
|
1
privileges/harbour-fernschreiber.privileges
Normal file
1
privileges/harbour-fernschreiber.privileges
Normal file
|
@ -0,0 +1 @@
|
|||
/usr/bin/harbour-fernschreiber,p
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
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
|
||||
|
@ -29,6 +30,7 @@ Page {
|
|||
|
||||
property bool isLoading: true;
|
||||
property bool syncSupported: false;
|
||||
property bool nemoSync: false;
|
||||
|
||||
function resetFocus() {
|
||||
contactsSearchField.focus = false;
|
||||
|
@ -56,32 +58,51 @@ Page {
|
|||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
// With Sailfish OS 4 we can't get up-to-date contacts andmore. 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
|
||||
var sailfishOSVersion = fernschreiberUtils.getSailfishOSVersion().split(".");
|
||||
if (parseInt(sailfishOSVersion[0]) < 4) {
|
||||
Debug.log("Sailfish OS version 3.x - contact sync should still be possible...")
|
||||
newChatPage.syncSupported = true;
|
||||
} else {
|
||||
Debug.log("Sailfish OS version 4.x - contact sync no longer supported...")
|
||||
newChatPage.syncSupported = false;
|
||||
// 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
|
||||
}
|
||||
|
||||
SilicaFlickable {
|
||||
id: newChatContainer
|
||||
contentHeight: newChatPage.height
|
||||
anchors.fill: parent
|
||||
|
||||
PullDownMenu {
|
||||
visible: contactsModel.canSynchronizeContacts() && newChatPage.syncSupported
|
||||
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();
|
||||
}
|
||||
}
|
||||
if (newChatPage.syncSupported) {
|
||||
if (!contactsModel.synchronizeContacts()) {
|
||||
reloadContacts();
|
||||
appNotification.show(qsTr("Could not synchronize your contacts with Telegram."));
|
||||
}
|
||||
}
|
||||
// Success message is not fired before TDLib returned "Contacts imported" (see above)
|
||||
}
|
||||
text: qsTr("Synchronize Contacts with Telegram")
|
||||
|
|
|
@ -19,6 +19,7 @@ URL: http://werkwolf.eu/
|
|||
Source0: %{name}-%{version}.tar.bz2
|
||||
Source100: harbour-fernschreiber.yaml
|
||||
Requires: sailfishsilica-qt5 >= 0.10.9
|
||||
Requires: nemo-qml-plugin-contacts-qt5
|
||||
BuildRequires: pkgconfig(sailfishapp) >= 1.0.2
|
||||
BuildRequires: pkgconfig(Qt5Core)
|
||||
BuildRequires: pkgconfig(Qt5Qml)
|
||||
|
@ -70,5 +71,6 @@ desktop-file-install --delete-original \
|
|||
%{_datadir}/%{name}
|
||||
%{_datadir}/applications/%{name}.desktop
|
||||
%{_datadir}/icons/hicolor/*/apps/%{name}.png
|
||||
%{_datadir}/mapplauncherd/privileges.d/harbour-fernschreiber.privileges
|
||||
# >> files
|
||||
# << files
|
||||
|
|
|
@ -36,6 +36,7 @@ PkgConfigBR:
|
|||
# Runtime dependencies which are not automatically detected
|
||||
Requires:
|
||||
- sailfishsilica-qt5 >= 0.10.9
|
||||
- nemo-qml-plugin-contacts-qt5
|
||||
|
||||
# All installed files
|
||||
Files:
|
||||
|
@ -43,6 +44,7 @@ Files:
|
|||
- '%{_datadir}/%{name}'
|
||||
- '%{_datadir}/applications/%{name}.desktop'
|
||||
- '%{_datadir}/icons/hicolor/*/apps/%{name}.png'
|
||||
- '%{_datadir}/mapplauncherd/privileges.d/harbour-fernschreiber.privileges'
|
||||
|
||||
# For more information about yaml and what's supported in Sailfish OS
|
||||
# build system, please see https://wiki.merproject.org/wiki/Spectacle
|
||||
|
|
|
@ -153,7 +153,7 @@ void ContactsModel::hydrateContacts()
|
|||
bool ContactsModel::synchronizeContacts()
|
||||
{
|
||||
LOG("Synchronizing device contacts");
|
||||
QVariantList deviceContacts;
|
||||
deviceContacts.clear();
|
||||
QSqlQuery databaseQuery(this->deviceContactsDatabase);
|
||||
databaseQuery.prepare("select distinct c.contactId, c.firstName, c.lastName, n.phoneNumber from Contacts as c inner join PhoneNumbers as n on c.contactId = n.contactId where n.phoneNumber is not null and ( c.firstName is not null or c.lastName is not null );");
|
||||
if (databaseQuery.exec()) {
|
||||
|
@ -182,3 +182,32 @@ bool ContactsModel::canSynchronizeContacts()
|
|||
{
|
||||
return this->canUseDeviceContacts;
|
||||
}
|
||||
|
||||
void ContactsModel::startImportingContacts()
|
||||
{
|
||||
this->deviceContacts.clear();
|
||||
}
|
||||
|
||||
void ContactsModel::stopImportingContacts()
|
||||
{
|
||||
if (!deviceContacts.isEmpty()) {
|
||||
LOG("Importing found contacts" << deviceContacts.size());
|
||||
this->tdLibWrapper->importContacts(deviceContacts);
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsModel::importContact(const QVariantMap &singlePerson)
|
||||
{
|
||||
QString firstName = singlePerson.value("firstName").toString();
|
||||
QVariantList phoneNumbers = singlePerson.value("phoneNumbers").toList();
|
||||
if (!firstName.isEmpty() && !phoneNumbers.isEmpty()) {
|
||||
for (QVariant phoneNumber : phoneNumbers) {
|
||||
QVariantMap singleContact;
|
||||
singleContact.insert("first_name", firstName);
|
||||
singleContact.insert("last_name", singlePerson.value("lastName").toString());
|
||||
singleContact.insert("phone_number", phoneNumber.toString());
|
||||
deviceContacts.append(singleContact);
|
||||
LOG("Found contact" << singleContact.value("first_name").toString() << singleContact.value("last_name").toString() << singleContact.value("phone_number").toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,6 +52,9 @@ public:
|
|||
Q_INVOKABLE void hydrateContacts();
|
||||
Q_INVOKABLE bool synchronizeContacts();
|
||||
Q_INVOKABLE bool canSynchronizeContacts();
|
||||
Q_INVOKABLE void startImportingContacts();
|
||||
Q_INVOKABLE void stopImportingContacts();
|
||||
Q_INVOKABLE void importContact(const QVariantMap &singlePerson);
|
||||
|
||||
public slots:
|
||||
void handleUsersReceived(const QString &extra, const QVariantList &userIds, int totalUsers);
|
||||
|
@ -63,6 +66,7 @@ private:
|
|||
QString filter;
|
||||
QSqlDatabase deviceContactsDatabase;
|
||||
bool canUseDeviceContacts;
|
||||
QVariantList deviceContacts;
|
||||
};
|
||||
|
||||
#endif // CONTACTSMODEL_H
|
||||
|
|
Loading…
Reference in a new issue