File indexing completed on 2024-06-23 05:21:15
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 #include "OfflineConnectionTask.h" 0024 #include <QTimer> 0025 #include "Common/ConnectionId.h" 0026 #include "Imap/Model/ItemRoles.h" 0027 #include "Imap/Model/TaskPresentationModel.h" 0028 #include "Streams/FakeSocket.h" 0029 0030 namespace Imap 0031 { 0032 namespace Mailbox 0033 { 0034 0035 OfflineConnectionTask::OfflineConnectionTask(Model *model) : ImapTask(model) 0036 { 0037 parser = new Parser(model, new Streams::FakeSocket(CONN_STATE_CONNECTED_PRETLS_PRECAPS), Common::ConnectionId::next()); 0038 ParserState parserState(parser); 0039 parserState.connState = CONN_STATE_LOGOUT; 0040 model->m_parsers[parser] = parserState; 0041 model->m_taskModel->slotParserCreated(parser); 0042 markAsActiveTask(); 0043 QTimer::singleShot(0, this, SLOT(slotPerform())); 0044 } 0045 0046 /** @short A decorator for slottifying the perform() method */ 0047 void OfflineConnectionTask::slotPerform() 0048 { 0049 perform(); 0050 } 0051 0052 void OfflineConnectionTask::perform() 0053 { 0054 model->runReadyTasks(); 0055 _failed(tr("We're offline")); 0056 QTimer::singleShot(0, this, SLOT(slotDie())); 0057 } 0058 0059 /** @short A slot for the die() */ 0060 void OfflineConnectionTask::slotDie() 0061 { 0062 die(tr("Offline")); 0063 deleteLater(); 0064 model->killParser(parser, Model::PARSER_KILL_EXPECTED); 0065 model->m_parsers.remove(parser); 0066 model->m_taskModel->slotParserDeleted(parser); 0067 } 0068 0069 /** @short This is an internal task */ 0070 QVariant OfflineConnectionTask::taskData(const int role) const 0071 { 0072 Q_UNUSED(role); 0073 return QVariant(); 0074 } 0075 0076 0077 } 0078 }