| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#ifndef CLIENTSERVICEACTION_H |
| 19 |
#define CLIENTSERVICEACTION_H |
| 20 |
|
| 21 |
#include <QObject> |
| 22 |
#include <QPointer> |
| 23 |
#include <qmailserviceaction.h> |
| 24 |
#include <qmailmessage.h> |
| 25 |
#include <QUuid> |
| 26 |
|
| 27 |
class ClientServiceAction : public QObject |
| 28 |
{ |
| 29 |
Q_OBJECT |
| 30 |
Q_PROPERTY(QString description READ description CONSTANT) |
| 31 |
public: |
| 32 |
explicit ClientServiceAction(QObject *parent = 0) : QObject(parent) |
| 33 |
{ |
| 34 |
m_uid = QUuid::createUuid().toByteArray(); |
| 35 |
} |
| 36 |
|
| 37 |
enum ActionType { |
| 38 |
|
| 39 |
Immediate = 1, |
| 40 |
Undoable, |
| 41 |
Silent |
| 42 |
}; |
| 43 |
|
| 44 |
enum ServiceAction { |
| 45 |
CopyAction, |
| 46 |
MoveAction, |
| 47 |
DeleteAction, |
| 48 |
FlagAction, |
| 49 |
RetrieveAction, |
| 50 |
RetrievePartAction, |
| 51 |
SearchAction, |
| 52 |
SendAction, |
| 53 |
StandardFoldersAction, |
| 54 |
StorageAction, |
| 55 |
TransmitAction, |
| 56 |
ExportAction, |
| 57 |
OutboxAction, |
| 58 |
SyncAccountAction, |
| 59 |
SyncFolderAction, |
| 60 |
CreateStandardFolders |
| 61 |
}; |
| 62 |
|
| 63 |
virtual void process() = 0; |
| 64 |
QMailServiceAction *action() const { return m_serviceAction; } |
| 65 |
ActionType actionType() const { return m_actionType; } |
| 66 |
ServiceAction serviceActionType() const { return m_serviceActionType; } |
| 67 |
QString description() const { return m_description; } |
| 68 |
bool isRunning() const { return m_serviceAction ? m_serviceAction->isRunning() : false; } |
| 69 |
QByteArray uid() const { return m_uid; } |
| 70 |
virtual QString location() { |
| 71 |
|
| 72 |
Q_ASSERT(false); |
| 73 |
return QString(); |
| 74 |
} |
| 75 |
|
| 76 |
virtual QMailAccountId accountId() { |
| 77 |
Q_ASSERT(false); |
| 78 |
return QMailAccountId(); |
| 79 |
} |
| 80 |
|
| 81 |
virtual quint64 messageId() { |
| 82 |
|
| 83 |
Q_ASSERT(false); |
| 84 |
return 0; |
| 85 |
} |
| 86 |
|
| 87 |
virtual QMailMessageIdList messageIds() { |
| 88 |
Q_ASSERT(false); |
| 89 |
return QMailMessageIdList(); |
| 90 |
} |
| 91 |
|
| 92 |
virtual QMailFolderIdList folderIds() { |
| 93 |
Q_ASSERT(false); |
| 94 |
return QMailFolderIdList(); |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
bool operator < (const ClientServiceAction *r) const { |
| 99 |
return m_actionType < r->actionType(); |
| 100 |
} |
| 101 |
|
| 102 |
bool operator == (const ClientServiceAction *r) const { |
| 103 |
return m_uid == r->uid(); |
| 104 |
} |
| 105 |
|
| 106 |
signals: |
| 107 |
void activityChanged(QMailServiceAction::Activity activity); |
| 108 |
|
| 109 |
protected: |
| 110 |
ActionType m_actionType; |
| 111 |
ServiceAction m_serviceActionType; |
| 112 |
QString m_description; |
| 113 |
QPointer<QMailServiceAction> m_serviceAction; |
| 114 |
QByteArray m_uid; |
| 115 |
|
| 116 |
QMailRetrievalAction *createRetrievalAction() { |
| 117 |
m_serviceAction = new QMailRetrievalAction(this); |
| 118 |
connect(m_serviceAction, &QMailServiceAction::activityChanged, this, &ClientServiceAction::activityChanged); |
| 119 |
qDebug() << "Retrieval action created"; |
| 120 |
return static_cast<QMailRetrievalAction *>(m_serviceAction.data()); |
| 121 |
} |
| 122 |
|
| 123 |
QMailStorageAction *createStorageAction(){ |
| 124 |
m_serviceAction = new QMailStorageAction(this); |
| 125 |
connect(m_serviceAction, &QMailServiceAction::activityChanged, this, &ClientServiceAction::activityChanged); |
| 126 |
return static_cast<QMailStorageAction *>(m_serviceAction.data()); |
| 127 |
} |
| 128 |
|
| 129 |
QMailTransmitAction *createTransmitAction(){ |
| 130 |
m_serviceAction = new QMailTransmitAction(this); |
| 131 |
connect(m_serviceAction, &QMailServiceAction::activityChanged, this, &ClientServiceAction::activityChanged); |
| 132 |
return static_cast<QMailTransmitAction *>(m_serviceAction.data()); |
| 133 |
} |
| 134 |
}; |
| 135 |
|
| 136 |
class UndoableAction : public ClientServiceAction |
| 137 |
{ |
| 138 |
Q_OBJECT |
| 139 |
public: |
| 140 |
explicit UndoableAction(QObject *parent = 0) : ClientServiceAction(parent) |
| 141 |
{ |
| 142 |
m_actionType = ActionType::Undoable; |
| 143 |
} |
| 144 |
|
| 145 |
enum ItemType { Folder, Message }; |
| 146 |
|
| 147 |
virtual int itemCount() = 0; |
| 148 |
virtual QMailAccountIdList accountIds() = 0; |
| 149 |
ItemType itemType() const { return m_itemType; } |
| 150 |
|
| 151 |
protected: |
| 152 |
ItemType m_itemType; |
| 153 |
}; |
| 154 |
|
| 155 |
class DeleteMessagesAction : public UndoableAction |
| 156 |
{ |
| 157 |
Q_OBJECT |
| 158 |
QMailMessageIdList m_ids; |
| 159 |
public: |
| 160 |
DeleteMessagesAction(QObject *parent, const QMailMessageIdList &msgIds); |
| 161 |
|
| 162 |
void process(); |
| 163 |
int itemCount(); |
| 164 |
QMailAccountIdList accountIds(); |
| 165 |
}; |
| 166 |
|
| 167 |
class MoveToFolderAction : public UndoableAction |
| 168 |
{ |
| 169 |
Q_OBJECT |
| 170 |
QMailMessageIdList m_ids; |
| 171 |
QMailFolderId m_destination; |
| 172 |
public: |
| 173 |
MoveToFolderAction(QObject *parent, const QMailMessageIdList &msgIds, const QMailFolderId &destination); |
| 174 |
void process(); |
| 175 |
int itemCount(); |
| 176 |
QMailAccountIdList accountIds(); |
| 177 |
}; |
| 178 |
|
| 179 |
class MoveToStandardFolderAction : public UndoableAction |
| 180 |
{ |
| 181 |
Q_OBJECT |
| 182 |
QMailMessageIdList m_ids; |
| 183 |
QMailFolder::StandardFolder m_standard; |
| 184 |
public: |
| 185 |
MoveToStandardFolderAction(QObject *parent, const QMailMessageIdList &msgIds, const QMailFolder::StandardFolder &folder); |
| 186 |
void process(); |
| 187 |
int itemCount(); |
| 188 |
QMailAccountIdList accountIds(); |
| 189 |
}; |
| 190 |
|
| 191 |
class CreateStandardFoldersAction : public ClientServiceAction |
| 192 |
{ |
| 193 |
Q_OBJECT |
| 194 |
QMailAccountId m_id; |
| 195 |
public: |
| 196 |
CreateStandardFoldersAction(QObject *parent, const QMailAccountId &id); |
| 197 |
void process(); |
| 198 |
QMailAccountId accountId() { return m_id; } |
| 199 |
}; |
| 200 |
|
| 201 |
class EmptyTrashAction : public ClientServiceAction |
| 202 |
{ |
| 203 |
Q_OBJECT |
| 204 |
QMailAccountId m_id; |
| 205 |
public: |
| 206 |
EmptyTrashAction(QObject *parent, const QMailAccountId &id); |
| 207 |
void process(); |
| 208 |
QMailAccountId accountId() { return m_id; } |
| 209 |
}; |
| 210 |
|
| 211 |
class ExportUpdatesAction : public ClientServiceAction |
| 212 |
{ |
| 213 |
Q_OBJECT |
| 214 |
QMailAccountId m_accountId; |
| 215 |
public: |
| 216 |
ExportUpdatesAction(QObject *parent, const QMailAccountId &id); |
| 217 |
void process(); |
| 218 |
QMailAccountId accountId() { return m_accountId; } |
| 219 |
}; |
| 220 |
|
| 221 |
class FlagsAction : public ClientServiceAction |
| 222 |
{ |
| 223 |
Q_OBJECT |
| 224 |
|
| 225 |
public: |
| 226 |
|
| 227 |
enum FlagType { |
| 228 |
FlagStarred, |
| 229 |
FlagRead, |
| 230 |
FlagTodo |
| 231 |
}; |
| 232 |
enum State { |
| 233 |
Apply, |
| 234 |
Remove |
| 235 |
}; |
| 236 |
|
| 237 |
FlagsAction(QObject *parent, const QMailMessageIdList &msgs, |
| 238 |
const FlagsAction::FlagType &flag, const FlagsAction::State &state); |
| 239 |
|
| 240 |
void process(); |
| 241 |
QMailAccountIdList accountIds(); |
| 242 |
|
| 243 |
private: |
| 244 |
QMailMessageIdList m_idList; |
| 245 |
FlagType m_flag; |
| 246 |
State m_state; |
| 247 |
}; |
| 248 |
|
| 249 |
class FetchMessagePartAction : public ClientServiceAction |
| 250 |
{ |
| 251 |
Q_OBJECT |
| 252 |
public: |
| 253 |
FetchMessagePartAction(QObject *parent, const QMailMessageId &id, const QString &location); |
| 254 |
void process(); |
| 255 |
public slots: |
| 256 |
QString location() { return m_location; } |
| 257 |
quint64 messageId() { return m_id; } |
| 258 |
private: |
| 259 |
quint64 m_id; |
| 260 |
QString m_location; |
| 261 |
}; |
| 262 |
|
| 263 |
class FetchMessagesAction : public ClientServiceAction |
| 264 |
{ |
| 265 |
Q_OBJECT |
| 266 |
public: |
| 267 |
FetchMessagesAction(QObject *parent, const QMailMessageIdList &list); |
| 268 |
void process(); |
| 269 |
public slots: |
| 270 |
QMailMessageIdList messageIds() { return m_list; } |
| 271 |
private: |
| 272 |
QMailMessageIdList m_list; |
| 273 |
}; |
| 274 |
|
| 275 |
class OutboxAction : public ClientServiceAction |
| 276 |
{ |
| 277 |
Q_OBJECT |
| 278 |
public: |
| 279 |
OutboxAction(QObject *parent, const QMailMessage &msg); |
| 280 |
|
| 281 |
void process(); |
| 282 |
|
| 283 |
private: |
| 284 |
QMailMessage m_msg; |
| 285 |
}; |
| 286 |
|
| 287 |
class SendPendingMessagesAction : public ClientServiceAction |
| 288 |
{ |
| 289 |
Q_OBJECT |
| 290 |
public: |
| 291 |
SendPendingMessagesAction(QObject *parent, const QMailAccountId &id); |
| 292 |
|
| 293 |
QMailAccountId accountId() const { return m_id; } |
| 294 |
void process(); |
| 295 |
|
| 296 |
signals: |
| 297 |
void messagesSent(const QMailMessageIdList &ids); |
| 298 |
void messageSendingFailed(const QMailMessageIdList &ids, QMailServiceAction::Status::ErrorCode error); |
| 299 |
private: |
| 300 |
QMailAccountId m_id; |
| 301 |
}; |
| 302 |
|
| 303 |
class AccountSyncAction : public ClientServiceAction |
| 304 |
{ |
| 305 |
Q_OBJECT |
| 306 |
public: |
| 307 |
AccountSyncAction(QObject *parent, const QMailAccountId &id); |
| 308 |
|
| 309 |
QMailAccountId accountId() { return m_id; } |
| 310 |
void process(); |
| 311 |
|
| 312 |
private: |
| 313 |
QMailAccountId m_id; |
| 314 |
}; |
| 315 |
|
| 316 |
class FolderSyncAction : public ClientServiceAction |
| 317 |
{ |
| 318 |
Q_OBJECT |
| 319 |
QMailAccountId m_id; |
| 320 |
QMailFolderIdList m_list; |
| 321 |
public: |
| 322 |
FolderSyncAction(QObject *parent, const QMailAccountId &id, const QMailFolderIdList &folders); |
| 323 |
QMailAccountId accountId() { return m_id; } |
| 324 |
void process(); |
| 325 |
}; |
| 326 |
|
| 327 |
#endif |