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.files = db
|
||||||
database.path = /usr/share/$${TARGET}
|
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 \
|
INSTALLS += telegram 86.png 108.png 128.png 172.png 256.png \
|
||||||
fernschreiber.desktop gui images database
|
fernschreiber.desktop gui images database mapplauncher
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
src/appsettings.h \
|
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 QtQuick 2.6
|
||||||
import Sailfish.Silica 1.0
|
import Sailfish.Silica 1.0
|
||||||
|
import org.nemomobile.contacts 1.0
|
||||||
import "../components"
|
import "../components"
|
||||||
import "../js/twemoji.js" as Emoji
|
import "../js/twemoji.js" as Emoji
|
||||||
import "../js/functions.js" as Functions
|
import "../js/functions.js" as Functions
|
||||||
|
@ -29,6 +30,7 @@ Page {
|
||||||
|
|
||||||
property bool isLoading: true;
|
property bool isLoading: true;
|
||||||
property bool syncSupported: false;
|
property bool syncSupported: false;
|
||||||
|
property bool nemoSync: false;
|
||||||
|
|
||||||
function resetFocus() {
|
function resetFocus() {
|
||||||
contactsSearchField.focus = false;
|
contactsSearchField.focus = false;
|
||||||
|
@ -56,31 +58,50 @@ Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
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(".");
|
var sailfishOSVersion = fernschreiberUtils.getSailfishOSVersion().split(".");
|
||||||
if (parseInt(sailfishOSVersion[0]) < 4) {
|
if (parseInt(sailfishOSVersion[0]) < 4) {
|
||||||
Debug.log("Sailfish OS version 3.x - contact sync should still be possible...")
|
Debug.log("Sailfish OS version 3.x - contact sync should still be possible...")
|
||||||
newChatPage.syncSupported = true;
|
newChatPage.syncSupported = true;
|
||||||
} else {
|
} else {
|
||||||
Debug.log("Sailfish OS version 4.x - contact sync no longer supported...")
|
// With Sailfish OS 4 we can't get up-to-date contacts with the standard database anymore. We might need to enter Sailjail eventually...
|
||||||
newChatPage.syncSupported = false;
|
// 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 {
|
SilicaFlickable {
|
||||||
id: newChatContainer
|
id: newChatContainer
|
||||||
contentHeight: newChatPage.height
|
contentHeight: newChatPage.height
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
PullDownMenu {
|
PullDownMenu {
|
||||||
visible: contactsModel.canSynchronizeContacts() && newChatPage.syncSupported
|
|
||||||
MenuItem {
|
MenuItem {
|
||||||
onClicked: {
|
onClicked: {
|
||||||
newChatPage.isLoading = true;
|
newChatPage.isLoading = true;
|
||||||
if (!contactsModel.synchronizeContacts()) {
|
if (newChatPage.nemoSync) {
|
||||||
reloadContacts();
|
if (peopleModel.count === 0) {
|
||||||
appNotification.show(qsTr("Could not synchronize your contacts with Telegram."));
|
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)
|
// Success message is not fired before TDLib returned "Contacts imported" (see above)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ URL: http://werkwolf.eu/
|
||||||
Source0: %{name}-%{version}.tar.bz2
|
Source0: %{name}-%{version}.tar.bz2
|
||||||
Source100: harbour-fernschreiber.yaml
|
Source100: harbour-fernschreiber.yaml
|
||||||
Requires: sailfishsilica-qt5 >= 0.10.9
|
Requires: sailfishsilica-qt5 >= 0.10.9
|
||||||
|
Requires: nemo-qml-plugin-contacts-qt5
|
||||||
BuildRequires: pkgconfig(sailfishapp) >= 1.0.2
|
BuildRequires: pkgconfig(sailfishapp) >= 1.0.2
|
||||||
BuildRequires: pkgconfig(Qt5Core)
|
BuildRequires: pkgconfig(Qt5Core)
|
||||||
BuildRequires: pkgconfig(Qt5Qml)
|
BuildRequires: pkgconfig(Qt5Qml)
|
||||||
|
@ -70,5 +71,6 @@ desktop-file-install --delete-original \
|
||||||
%{_datadir}/%{name}
|
%{_datadir}/%{name}
|
||||||
%{_datadir}/applications/%{name}.desktop
|
%{_datadir}/applications/%{name}.desktop
|
||||||
%{_datadir}/icons/hicolor/*/apps/%{name}.png
|
%{_datadir}/icons/hicolor/*/apps/%{name}.png
|
||||||
|
%{_datadir}/mapplauncherd/privileges.d/harbour-fernschreiber.privileges
|
||||||
# >> files
|
# >> files
|
||||||
# << files
|
# << files
|
||||||
|
|
|
@ -36,6 +36,7 @@ PkgConfigBR:
|
||||||
# Runtime dependencies which are not automatically detected
|
# Runtime dependencies which are not automatically detected
|
||||||
Requires:
|
Requires:
|
||||||
- sailfishsilica-qt5 >= 0.10.9
|
- sailfishsilica-qt5 >= 0.10.9
|
||||||
|
- nemo-qml-plugin-contacts-qt5
|
||||||
|
|
||||||
# All installed files
|
# All installed files
|
||||||
Files:
|
Files:
|
||||||
|
@ -43,6 +44,7 @@ Files:
|
||||||
- '%{_datadir}/%{name}'
|
- '%{_datadir}/%{name}'
|
||||||
- '%{_datadir}/applications/%{name}.desktop'
|
- '%{_datadir}/applications/%{name}.desktop'
|
||||||
- '%{_datadir}/icons/hicolor/*/apps/%{name}.png'
|
- '%{_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
|
# For more information about yaml and what's supported in Sailfish OS
|
||||||
# build system, please see https://wiki.merproject.org/wiki/Spectacle
|
# build system, please see https://wiki.merproject.org/wiki/Spectacle
|
||||||
|
|
|
@ -153,7 +153,7 @@ void ContactsModel::hydrateContacts()
|
||||||
bool ContactsModel::synchronizeContacts()
|
bool ContactsModel::synchronizeContacts()
|
||||||
{
|
{
|
||||||
LOG("Synchronizing device contacts");
|
LOG("Synchronizing device contacts");
|
||||||
QVariantList deviceContacts;
|
deviceContacts.clear();
|
||||||
QSqlQuery databaseQuery(this->deviceContactsDatabase);
|
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 );");
|
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()) {
|
if (databaseQuery.exec()) {
|
||||||
|
@ -182,3 +182,32 @@ bool ContactsModel::canSynchronizeContacts()
|
||||||
{
|
{
|
||||||
return this->canUseDeviceContacts;
|
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 void hydrateContacts();
|
||||||
Q_INVOKABLE bool synchronizeContacts();
|
Q_INVOKABLE bool synchronizeContacts();
|
||||||
Q_INVOKABLE bool canSynchronizeContacts();
|
Q_INVOKABLE bool canSynchronizeContacts();
|
||||||
|
Q_INVOKABLE void startImportingContacts();
|
||||||
|
Q_INVOKABLE void stopImportingContacts();
|
||||||
|
Q_INVOKABLE void importContact(const QVariantMap &singlePerson);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void handleUsersReceived(const QString &extra, const QVariantList &userIds, int totalUsers);
|
void handleUsersReceived(const QString &extra, const QVariantList &userIds, int totalUsers);
|
||||||
|
@ -63,6 +66,7 @@ private:
|
||||||
QString filter;
|
QString filter;
|
||||||
QSqlDatabase deviceContactsDatabase;
|
QSqlDatabase deviceContactsDatabase;
|
||||||
bool canUseDeviceContacts;
|
bool canUseDeviceContacts;
|
||||||
|
QVariantList deviceContacts;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONTACTSMODEL_H
|
#endif // CONTACTSMODEL_H
|
||||||
|
|
Loading…
Reference in a new issue