blob: 5f9916882ff0b4fc8d17085a88ec8b8887bcdb6d [file] [log] [blame]
Edric Milaret67007d12015-05-07 09:40:09 -04001/***************************************************************************
Anthony LĂ©onard2fde81d2017-04-17 10:06:55 -04002 * Copyright (C) 2015-2017 by Savoir-faire Linux *
Edric Milaret67007d12015-05-07 09:40:09 -04003 * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program 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
Edric Milaret5f316da2015-09-28 11:57:42 -040019#pragma once
Edric Milaret67007d12015-05-07 09:40:09 -040020
21#include <QObject>
22#include <QStandardPaths>
23#include <QDir>
24#include <QXmlStreamReader>
25#include <QtConcurrent/QtConcurrent>
Edric Milaretdb76aa82015-05-11 16:01:00 -040026#include <QImage>
Edric Milaret43f3c1e2015-07-16 17:52:47 -040027#include <QFileSystemWatcher>
Edric Milaret67007d12015-05-07 09:40:09 -040028
29#include "person.h"
30#include "collectioninterface.h"
31#include "contactmethod.h"
32#include "phonedirectorymodel.h"
33
34class WindowsContactBackend : public CollectionInterface
35{
36public:
37 explicit WindowsContactBackend(CollectionMediator<Person>* mediator, CollectionInterface* parent = nullptr);
38 virtual ~WindowsContactBackend();
39
40 virtual bool load() override;
41 virtual bool reload() override;
42 virtual bool clear() override;
43 virtual QString name () const override;
44 virtual QString category () const override;
45 virtual bool isEnabled() const override;
46 virtual QByteArray id () const override;
47 virtual FlagPack<CollectionInterface::SupportedFeatures> supportedFeatures() const override;
48
49private:
50 bool loadRun();
51private:
52 CollectionMediator<Person>* mediator_;
Edric Milaretdb76aa82015-05-11 16:01:00 -040053 constexpr static int sizePhoto_ = 50;
Edric Milaret43f3c1e2015-07-16 17:52:47 -040054 QFileSystemWatcher* watcher_;
55
56private:
57 bool getPersonFromContactFile(const QDir &contactDir, const QString& contactFileName);
Edric Milaret67007d12015-05-07 09:40:09 -040058};
59
60class WindowsContactEditor : public CollectionEditor<Person>
61{
62public:
63 WindowsContactEditor(CollectionMediator<Person>* m, WindowsContactBackend* parent);
64 ~WindowsContactEditor();
65 virtual bool save ( const Person* item ) override;
66 virtual bool remove ( const Person* item ) override;
67 virtual bool edit ( Person* item ) override;
Edric Milaret16f997d2015-08-04 13:46:22 -040068 virtual bool addNew ( Person* item ) override;
Edric Milaret67007d12015-05-07 09:40:09 -040069 virtual bool addExisting( const Person* item ) override;
70
71private:
72 virtual QVector<Person*> items() const override;
73
74 QVector<Person*> items_;
75 WindowsContactBackend* collection_;
76};
77