~renatofilho/address-book-service/create-source

« back to all changes in this revision

Viewing changes to lib/dirtycontact-notify.cpp

  • Committer: Renato Araujo Oliveira Filho
  • Date: 2014-03-18 15:01:59 UTC
  • Revision ID: renato.filho@canonical.com-20140318150159-mj7rwmsargsiv38q
Moved DirtyContactsNotify class to a individual file and make it a QObject.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2014 Canonical Ltd.
 
3
 *
 
4
 * This file is part of contact-service-app.
 
5
 *
 
6
 * contact-service-app is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; version 3.
 
9
 *
 
10
 * contact-service-app is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
 
 
20
//this timeout represents how long the server will wait for changes on the contact before notify the client
 
21
#define NOTIFY_CONTACTS_TIMEOUT 500
 
22
 
 
23
#include "dirtycontact-notify.h"
 
24
#include "addressbook-adaptor.h"
 
25
 
 
26
namespace galera {
 
27
 
 
28
DirtyContactsNotify::DirtyContactsNotify(AddressBookAdaptor *adaptor, QObject *parent)
 
29
    : QObject(parent),
 
30
      m_adaptor(adaptor)
 
31
{
 
32
    m_timer.setInterval(NOTIFY_CONTACTS_TIMEOUT);
 
33
    m_timer.setSingleShot(true);
 
34
    connect(&m_timer, SIGNAL(timeout()), SLOT(onTimeout()));
 
35
}
 
36
 
 
37
void DirtyContactsNotify::append(QSet<QString> ids)
 
38
{
 
39
    m_ids += ids;
 
40
    m_timer.start();
 
41
}
 
42
 
 
43
void DirtyContactsNotify::onTimeout()
 
44
{
 
45
    Q_EMIT m_adaptor->contactsUpdated(m_ids.toList());
 
46
    m_ids.clear();
 
47
}
 
48
 
 
49
} //namespace