File indexing completed on 2024-06-23 05:21:13
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 IMAP_TASK_IDLELAUNCHER_H 0024 #define IMAP_TASK_IDLELAUNCHER_H 0025 0026 #include <QPointer> 0027 0028 class QTimer; 0029 0030 namespace Imap 0031 { 0032 0033 namespace Mailbox 0034 { 0035 0036 class KeepMailboxOpenTask; 0037 0038 /** @short Automatically launch and maintain the IDLE command 0039 0040 This class servers as a helper for the KeepMailboxOpenTask task. Its responsibility 0041 is to watch the parser for being "idle" (ie. no commands flowing from upper layers) 0042 and automatically launching the IDLE command, watching for its interruption (perhaps 0043 by other commands) and restarting it when the parser is idling again. 0044 */ 0045 class IdleLauncher: public QObject 0046 { 0047 Q_OBJECT 0048 public: 0049 /** @short Create the IdleLauncher 0050 0051 This function should only be called when the KeepMailboxOpenTask has selected the 0052 target mailbox and all member variables are set up. 0053 */ 0054 explicit IdleLauncher(KeepMailboxOpenTask *parent); 0055 0056 /** @short Register the interest in launching the IDLE command after a delay */ 0057 void enterIdleLater(); 0058 0059 /** @short Prevent any further idling */ 0060 void die(); 0061 0062 /** @short Break the IDLE command */ 0063 void finishIdle(); 0064 0065 /** @short Are we in the middle of an IDLE now? 0066 0067 This function returns true iff slotEnterIdleNow() has been called and finishIdle() 0068 hasn't been called yet. It doesn't depend on command completion tracking on upper layers, 0069 though. 0070 */ 0071 bool idling() const; 0072 0073 /** @short Are we waiting for the "OK idle done"? */ 0074 bool waitingForIdleTaggedTermination() const; 0075 0076 /** @short Informs the IdleLauncher that the server OKed the end of the IDLE mode 0077 0078 We will automatically resume IDLE later. 0079 */ 0080 void idleCommandCompleted(); 0081 0082 /** @short Informs the IdleLauncher that the IDLE command failed */ 0083 void idleCommandFailed(); 0084 public slots: 0085 /** @short Immediately send the IDLE command to the parser */ 0086 void slotEnterIdleNow(); 0087 /** @short Abort the IDLE command because it's been running for too long */ 0088 void slotTerminateLongIdle(); 0089 private: 0090 KeepMailboxOpenTask *task; 0091 QTimer *delayedEnter; 0092 QTimer *renewal; 0093 /** @short Are we between queueing the IDLE and DONE statements? */ 0094 bool m_idling; 0095 /** @short Are we between queueing the IDLE and receiving the <tag> OK? */ 0096 bool m_idleCommandRunning; 0097 0098 IdleLauncher(const Imap::Mailbox::IdleLauncher &); // don't implement 0099 IdleLauncher &operator=(const Imap::Mailbox::IdleLauncher &); // don't implement 0100 }; 0101 0102 } 0103 0104 } 0105 0106 #endif /* IMAP_TASK_IDLELAUNCHER_H */