File indexing completed on 2024-06-16 05:01:23

0001 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net>
0002 
0003    This file is part of the Trojita Qt IMAP e-mail client,
0004    http://trojita.flaska.net/
0005 
0006    This program is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU General Public License as
0008    published by the Free Software Foundation; either version 2 of
0009    the License or (at your option) version 3 or any later version
0010    accepted by the membership of KDE e.V. (or its successor approved
0011    by the membership of KDE e.V.), which shall act as a proxy
0012    defined in Section 14 of version 3 of the license.
0013 
0014    This program is distributed in the hope that it will be useful,
0015    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017    GNU General Public License for more details.
0018 
0019    You should have received a copy of the GNU General Public License
0020    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021 */
0022 
0023 #ifndef SENDERIDENTITIESMODEL_H
0024 #define SENDERIDENTITIESMODEL_H
0025 
0026 #include <QAbstractTableModel>
0027 
0028 class QSettings;
0029 
0030 namespace Composer
0031 {
0032 
0033 class ItemSenderIdentity
0034 {
0035 public:
0036     ItemSenderIdentity(const QString &realName, const QString &emailAddress,
0037                        const QString &organisation, const QString &signature);
0038     ItemSenderIdentity();
0039 
0040     QString realName;
0041     QString emailAddress;
0042     QString organisation;
0043     QString signature;
0044 };
0045 
0046 /** @short Model for a list of available sender identities */
0047 class SenderIdentitiesModel : public QAbstractTableModel
0048 {
0049     Q_OBJECT
0050 public:
0051     enum { COLUMN_NAME, COLUMN_EMAIL, COLUMN_ORGANIZATION, COLUMN_SIGNATURE, COLUMN_LAST };
0052 
0053     explicit SenderIdentitiesModel(QObject *parent = 0);
0054     virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
0055     virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
0056     virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
0057     virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
0058     /** @short Reimplemented from QAbstractTableModel; required for QDataWidgetMapper. */
0059     virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
0060 
0061     void appendIdentity(const ItemSenderIdentity &item);
0062     void removeIdentityAt(const int position);
0063     void moveIdentity(const int from, const int to);
0064 
0065     /** @short Replace the contents of this model by data read from a QSettings instance */
0066     void loadFromSettings(QSettings &s);
0067     /** @short Save the data into a QSettings instance */
0068     void saveToSettings(QSettings &s) const;
0069 
0070 private:
0071     QList<ItemSenderIdentity> m_identities;
0072 };
0073 
0074 }
0075 
0076 #endif // SENDERIDENTITIESMODEL_H