File indexing completed on 2024-11-24 04:53:24
0001 /* Copyright (C) 2012 Thomas Lübking <thomas.luebking@gmail.com> 0002 Copyright (C) 2013 Caspar Schutijser <caspar@schutijser.com> 0003 Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net> 0004 Copyright (C) 2013 - 2014 Pali Rohár <pali.rohar@gmail.com> 0005 0006 This file is part of the Trojita Qt IMAP e-mail client, 0007 http://trojita.flaska.net/ 0008 0009 This program is free software; you can redistribute it and/or 0010 modify it under the terms of the GNU General Public License as 0011 published by the Free Software Foundation; either version 2 of 0012 the License or (at your option) version 3 or any later version 0013 accepted by the membership of KDE e.V. (or its successor approved 0014 by the membership of KDE e.V.), which shall act as a proxy 0015 defined in Section 14 of version 3 of the license. 0016 0017 This program is distributed in the hope that it will be useful, 0018 but WITHOUT ANY WARRANTY; without even the implied warranty of 0019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0020 GNU General Public License for more details. 0021 0022 You should have received a copy of the GNU General Public License 0023 along with this program. If not, see <http://www.gnu.org/licenses/>. 0024 */ 0025 0026 #ifndef ABOOK_ADDRESSBOOK 0027 #define ABOOK_ADDRESSBOOK 0028 0029 #include <QObject> 0030 #include <QPair> 0031 0032 #include "Plugins/AddressbookPlugin.h" 0033 #include "Plugins/PluginInterface.h" 0034 0035 class QFileSystemWatcher; 0036 class QStandardItemModel; 0037 class QTimer; 0038 0039 using namespace Plugins; 0040 0041 /** @short A generic local adressbook interface*/ 0042 class AbookAddressbook : public AddressbookPlugin { 0043 Q_OBJECT 0044 public: 0045 AbookAddressbook(QObject *parent); 0046 virtual ~AbookAddressbook(); 0047 0048 virtual AddressbookPlugin::Features features() const; 0049 0050 enum Type { Name = Qt::DisplayRole, Mail = Qt::UserRole + 1, 0051 Address, Address2, City, State, ZIP, Country, 0052 Phone, Workphone, Fax, Mobile, 0053 Nick, URL, Notes, Anniversary, Photo, 0054 UnknownKeys, Dirty }; 0055 0056 NameEmailList complete(const QString &string, const QStringList &ignores, int max = -1) const; 0057 QStringList prettyNamesForAddress(const QString &mail) const; 0058 0059 QStandardItemModel *model() const; 0060 0061 public slots: 0062 virtual AddressbookCompletionJob *requestCompletion(const QString &input, const QStringList &ignores = QStringList(), int max = -1); 0063 virtual AddressbookNamesJob *requestPrettyNamesForAddress(const QString &email); 0064 virtual void openAddressbookWindow(); 0065 virtual void openContactWindow(const QString &email, const QString &displayName); 0066 0067 void saveContacts(); 0068 void readAbook(bool update = false); 0069 void updateAbook(); 0070 0071 private slots: 0072 void scheduleAbookUpdate(); 0073 0074 private: 0075 void ensureAbookPath(); 0076 void remonitorAdressbook(); 0077 0078 QFileSystemWatcher *m_filesystemWatcher; 0079 QTimer *m_updateTimer; 0080 QStandardItemModel *m_contacts; 0081 0082 QList<QPair<Type,QString> > m_fields; 0083 }; 0084 0085 class trojita_plugin_AbookAddressbookPlugin : public QObject, public AddressbookPluginInterface 0086 { 0087 Q_OBJECT 0088 Q_INTERFACES(Plugins::AddressbookPluginInterface) 0089 Q_PLUGIN_METADATA(IID "net.flaska.trojita.plugins.addressbook.abookaddressbook") 0090 0091 public: 0092 QString name() const override; 0093 QString description() const override; 0094 AddressbookPlugin *create(QObject *parent, QSettings *settings) override; 0095 }; 0096 0097 #endif // ABOOK_ADDRESSBOOK