| 1 |
/* Copyright (C) 2016 - 2017 Dan Chapman <[email protected]> |
| 2 |
|
| 3 |
This file is part of Dekko email client for Ubuntu devices |
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or |
| 6 |
modify it under the terms of the GNU General Public License as |
| 7 |
published by the Free Software Foundation; either version 2 of |
| 8 |
the License or (at your option) version 3 |
| 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 |
pragma Singleton |
| 19 |
import QtQuick 2.4 |
| 20 |
import QuickFlux 1.0 |
| 21 |
import Dekko.Mail.Accounts 1.0 |
| 22 |
import Dekko.Mail 1.0 |
| 23 |
import Dekko.Mail.API 1.0 |
| 24 |
import Dekko.Mail.Stores.Accounts 1.0 |
| 25 |
import Dekko.Utils 1.0 as QtCoreAPI |
| 26 |
|
| 27 |
AppListener { |
| 28 |
|
| 29 |
readonly property bool showCC: d.ccVisible |
| 30 |
readonly property bool showBCC: d.bccVisible |
| 31 |
readonly property bool sendInProgress: d.sendInProgress |
| 32 |
readonly property bool hasValidIdentity: d.identitiesValid |
| 33 |
readonly property bool sidePanelOpen: builder.attachments.count || d.openContacts |
| 34 |
readonly property string currentSignature: hasValidIdentity ? identities.selectedAccount.identity.signature : "" |
| 35 |
readonly property QtObject identity: priv_identity |
| 36 |
readonly property QtObject recipients: priv_recipients |
| 37 |
readonly property QtObject attachments: builder.attachments |
| 38 |
readonly property QtObject __builder: builder |
| 39 |
|
| 40 |
property alias _private: d |
| 41 |
|
| 42 |
property ComposerStoreActions actions: ComposerStoreActions{} |
| 43 |
///////////// |
| 44 |
// Builder // |
| 45 |
///////////// |
| 46 |
property alias builder: builder |
| 47 |
// bind the subject fields text document to messagebuilder |
| 48 |
property alias subjectDocument: builder.subject |
| 49 |
// bind the body fields text document to messagebuilder |
| 50 |
property alias bodyDocument: builder.body |
| 51 |
//////////////// |
| 52 |
// identities // |
| 53 |
//////////////// |
| 54 |
property alias identities: identities |
| 55 |
property alias identitiesModel: identities.model |
| 56 |
property alias identityIndex: identities.selectedIndex |
| 57 |
//////////////// |
| 58 |
// Submission // |
| 59 |
//////////////// |
| 60 |
property alias submission: submissionManager |
| 61 |
|
| 62 |
SenderIdentities { |
| 63 |
id: identities |
| 64 |
accountsModel: AccountStore.sendAccountsModel |
| 65 |
accountIdentities: AccountStore.identities |
| 66 |
} |
| 67 |
|
| 68 |
MessageBuilder { |
| 69 |
id: builder |
| 70 |
identities: identities |
| 71 |
} |
| 72 |
|
| 73 |
SubmissionManager { |
| 74 |
id: submissionManager |
| 75 |
builder: builder |
| 76 |
onError: { |
| 77 |
switch(error) { |
| 78 |
case SubmissionManager.NoBuilder: |
| 79 |
Log.logError("ComposerStore::SubmissionManager::NoBuilder", "No message builder set. Cannot compose without one") |
| 80 |
break |
| 81 |
case SubmissionManager.InvalidMessage: |
| 82 |
Log.logError("ComposerStore::SubmissionManager::InvalidMessage", "Invalid message, missing 'To' recipients or Subject") |
| 83 |
break |
| 84 |
case SubmissionManager.NoIdentities: |
| 85 |
Log.logError("ComposerStore::SubmissionManager::NoIdentities", "No identities available for MessageBuilder. Cannot proceed...") |
| 86 |
PopupActions.showNotice(PopupKeys.popupComposer, qsTr("Please select a sender. Otherwise no drafts will be saved automatically. Consider setting a default identity.")) |
| 87 |
break |
| 88 |
case SubmissionManager.InvalidIdentity: |
| 89 |
Log.logError("ComposerStore::SubmissionManager::InvalidIdentity", "Invalid identity for MessageBuilder. Cannot proceed...") |
| 90 |
PopupActions.showNotice(PopupKeys.popupComposer, qsTr("Somethings fishy with your Identity. Please select a valid sender.")) |
| 91 |
break |
| 92 |
} |
| 93 |
} |
| 94 |
onMessageQueued: { |
| 95 |
Log.logInfo("ComposerStore::SubmissionManager::messageQueued", "Message queued resetting composer") |
| 96 |
ComposerActions.resetComposer() |
| 97 |
ViewActions.closeComposer() |
| 98 |
d.sendInProgress = false |
| 99 |
ViewActions.orderSimpleToast(ViewKeys.toastMainWindow, qsTr("Message queued.")) |
| 100 |
} |
| 101 |
onDraftSaved: { |
| 102 |
Log.logInfo("ComposerStore::SubmissionManager::draftSaved", "Draft message was saved"); |
| 103 |
ViewActions.orderSimpleToast(ViewKeys.toastMainWindow, qsTr("Draft saved.")) |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
QtObject { |
| 108 |
id: priv_identity |
| 109 |
readonly property string name: hasValidIdentity ? identities.selectedAccount.identity.name : "" |
| 110 |
readonly property string initials: hasValidIdentity ? identities.selectedAccount.identity.initials : "" |
| 111 |
readonly property string email: hasValidIdentity ? identities.selectedAccount.identity.email : "" |
| 112 |
} |
| 113 |
|
| 114 |
QtObject { |
| 115 |
id: priv_recipients |
| 116 |
property alias to: builder.to |
| 117 |
property alias cc: builder.cc |
| 118 |
property alias bcc: builder.bcc |
| 119 |
} |
| 120 |
|
| 121 |
QtObject { |
| 122 |
id: d |
| 123 |
property bool sendInProgress: false |
| 124 |
property bool ccVisible: false |
| 125 |
property bool bccVisible: false |
| 126 |
property bool identitiesValid: identities.selectedIndex >= 0 |
| 127 |
property bool openContacts: false |
| 128 |
property Timer delayDiscard: Timer { |
| 129 |
interval: 10 |
| 130 |
onTriggered: ComposerActions.discardMessage() |
| 131 |
} |
| 132 |
property Timer sendTimer: Timer { |
| 133 |
interval: 50 |
| 134 |
onTriggered: submissionManager.send() |
| 135 |
} |
| 136 |
} |
| 137 |
} |
| 138 |
|