~nikwen/account-polld/directly-poll-with-new-account-data-fix

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 Copyright 2014 Canonical Ltd.
 Authors: Sergio Schvezov <sergio.schvezov@canonical.com>

 This program is free software: you can redistribute it and/or modify it
 under the terms of the GNU General Public License version 3, as published
 by the Free Software Foundation.

 This program is distributed in the hope that it will be useful, but
 WITHOUT ANY WARRANTY; without even the implied warranties of
 MERCHANTABILITY, SATISFACTORY QUALITY, 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 this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <QContactManager>
#include <QContactFilter>
#include <QContactEmailAddress>
#include <QContactDetailFilter>
#include <QContactManager>
#include <QContactAvatar>
#include <QCoreApplication>
#include <QScopedPointer>
#include <QTimer>
#include <thread>

#include "qtcontacts.h"
#include "qtcontacts.hpp"
#include "qtcontacts.moc"

#ifdef __cplusplus
extern "C" {
#include "_cgo_export.h"
}
#endif

QTCONTACTS_USE_NAMESPACE

int mainloopStart() {
    static char empty[1] = {0};
    static char *argv[] = {empty, empty, empty};
    static int argc = 1;

    QCoreApplication mApp(argc, argv);
    return mApp.exec();
}

void getAvatar(char *email) {
    QScopedPointer<Avatar> avatar(new Avatar());
    avatar->retrieveThumbnail(QString(email));
}

void Avatar::retrieveThumbnail(const QString& email) {
    QString avatar;

    QContactManager manager ("galera");
    QContactDetailFilter filter(QContactEmailAddress::match(email));
    QList<QContact> contacts = manager.contacts(filter);
    if(contacts.size() > 0) {
        avatar = contacts[0].detail<QContactAvatar>().imageUrl().path();
    }

    QByteArray byteArray = avatar.toUtf8();
    char* cString = byteArray.data();

    callback(cString);
}