Edric Milaret | 67007d1 | 2015-05-07 09:40:09 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
Edric Milaret | bab169d | 2016-01-07 15:13:33 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2016 by Savoir-faire Linux * |
Edric Milaret | 67007d1 | 2015-05-07 09:40:09 -0400 | [diff] [blame] | 3 | * 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 Milaret | 5f316da | 2015-09-28 11:57:42 -0400 | [diff] [blame] | 19 | #pragma once |
Edric Milaret | 67007d1 | 2015-05-07 09:40:09 -0400 | [diff] [blame] | 20 | |
| 21 | #include <QObject> |
| 22 | #include <QStandardPaths> |
| 23 | #include <QDir> |
| 24 | #include <QXmlStreamReader> |
| 25 | #include <QtConcurrent/QtConcurrent> |
Edric Milaret | db76aa8 | 2015-05-11 16:01:00 -0400 | [diff] [blame] | 26 | #include <QImage> |
Edric Milaret | 43f3c1e | 2015-07-16 17:52:47 -0400 | [diff] [blame] | 27 | #include <QFileSystemWatcher> |
Edric Milaret | 67007d1 | 2015-05-07 09:40:09 -0400 | [diff] [blame] | 28 | |
| 29 | #include "person.h" |
| 30 | #include "collectioninterface.h" |
| 31 | #include "contactmethod.h" |
| 32 | #include "phonedirectorymodel.h" |
| 33 | |
| 34 | class WindowsContactBackend : public CollectionInterface |
| 35 | { |
| 36 | public: |
| 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 | |
| 49 | private: |
| 50 | bool loadRun(); |
| 51 | private: |
| 52 | CollectionMediator<Person>* mediator_; |
Edric Milaret | db76aa8 | 2015-05-11 16:01:00 -0400 | [diff] [blame] | 53 | constexpr static int sizePhoto_ = 50; |
Edric Milaret | 43f3c1e | 2015-07-16 17:52:47 -0400 | [diff] [blame] | 54 | QFileSystemWatcher* watcher_; |
| 55 | |
| 56 | private: |
| 57 | bool getPersonFromContactFile(const QDir &contactDir, const QString& contactFileName); |
Edric Milaret | a13b48c | 2016-01-18 14:42:35 -0500 | [diff] [blame] | 58 | QImage getCirclePhoto(const QImage original); |
Edric Milaret | 67007d1 | 2015-05-07 09:40:09 -0400 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | class WindowsContactEditor : public CollectionEditor<Person> |
| 62 | { |
| 63 | public: |
| 64 | WindowsContactEditor(CollectionMediator<Person>* m, WindowsContactBackend* parent); |
| 65 | ~WindowsContactEditor(); |
| 66 | virtual bool save ( const Person* item ) override; |
| 67 | virtual bool remove ( const Person* item ) override; |
| 68 | virtual bool edit ( Person* item ) override; |
Edric Milaret | 16f997d | 2015-08-04 13:46:22 -0400 | [diff] [blame] | 69 | virtual bool addNew ( Person* item ) override; |
Edric Milaret | 67007d1 | 2015-05-07 09:40:09 -0400 | [diff] [blame] | 70 | virtual bool addExisting( const Person* item ) override; |
| 71 | |
| 72 | private: |
| 73 | virtual QVector<Person*> items() const override; |
| 74 | |
| 75 | QVector<Person*> items_; |
| 76 | WindowsContactBackend* collection_; |
| 77 | }; |
| 78 | |