Debian Codegraph @

storagechangenotifierplugins/hcontacts/ContactsChangeNotifierPlugin.cpp

raw
1 /*
2 * This file is part of buteo-sync-plugins package
3 *
4 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
5 * Copyright (C) 2013 - 2021 Jolla Ltd.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * version 2.1 as published by the Free Software Foundation.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22 #include "ContactsChangeNotifierPlugin.h"
23 #include "ContactsChangeNotifier.h"
24 #include "LogMacros.h"
25 #include <QTimer>
26
27 using namespace Buteo;
28
29 Buteo::StorageChangeNotifierPlugin* ContactsChangeNotifierPluginLoader::createPlugin(const QString& aStorageName)
30 {
31 return new ContactsChangeNotifierPlugin(aStorageName);
32 }
33
34
35 ContactsChangeNotifierPlugin::ContactsChangeNotifierPlugin(const QString& aStorageName) :
36 StorageChangeNotifierPlugin(aStorageName),
37 ihasChanges(false),
38 iDisableLater(false)
39 {
40 FUNCTION_CALL_TRACE(lcSyncMLContactChangeTrace);
41 icontactsChangeNotifier = new ContactsChangeNotifier;
42 QObject::connect(icontactsChangeNotifier, SIGNAL(change()),
43 this, SLOT(onChange()));
44 }
45
46 ContactsChangeNotifierPlugin::~ContactsChangeNotifierPlugin()
47 {
48 FUNCTION_CALL_TRACE(lcSyncMLContactChangeTrace);
49 delete icontactsChangeNotifier;
50 }
51
52 QString ContactsChangeNotifierPlugin::name() const
53 {
54 FUNCTION_CALL_TRACE(lcSyncMLContactChangeTrace);
55 return iStorageName;
56 }
57
58 bool ContactsChangeNotifierPlugin::hasChanges() const
59 {
60 FUNCTION_CALL_TRACE(lcSyncMLContactChangeTrace);
61 return ihasChanges;
62 }
63
64 void ContactsChangeNotifierPlugin::changesReceived()
65 {
66 FUNCTION_CALL_TRACE(lcSyncMLContactChangeTrace);
67 ihasChanges = false;
68 }
69
70 void ContactsChangeNotifierPlugin::onChange()
71 {
72 FUNCTION_CALL_TRACE(lcSyncMLContactChangeTrace);
73 qCDebug(lcSyncMLContactChange) << "Change in contacts detected";
74 ihasChanges = true;
75 if(iDisableLater)
76 {
77 icontactsChangeNotifier->disable();
78 }
79 else
80 {
81 emit storageChange();
82 }
83 }
84
85 void ContactsChangeNotifierPlugin::enable()
86 {
87 FUNCTION_CALL_TRACE(lcSyncMLContactChangeTrace);
88 icontactsChangeNotifier->enable();
89 iDisableLater = false;
90 }
91
92 void ContactsChangeNotifierPlugin::disable(bool disableAfterNextChange)
93 {
94 FUNCTION_CALL_TRACE(lcSyncMLContactChangeTrace);
95 if(disableAfterNextChange)
96 {
97 iDisableLater = true;
98 }
99 else
100 {
101 icontactsChangeNotifier->disable();
102 }
103 }