KIMAP2

job.cpp
1/*
2 Copyright (c) 2009 Kevin Ottens <ervin@kde.org>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#include "job.h"
21#include "job_p.h"
22#include "message_p.h"
23#include "session_p.h"
24
25#include "kimap_debug.h"
26
27using namespace KIMAP2;
28
29void JobPrivate::sendCommand(const QByteArray &command, const QByteArray &args)
30{
31 tags << sessionInternal()->sendCommand(command, args);
32 m_currentCommand = command + "" + args;
33}
34
35Job::Job(Session *session)
36 : KJob(session), d_ptr(new JobPrivate(session, "Job"))
37{
38}
39
40Job::Job(JobPrivate &dd)
41 : KJob(dd.m_session), d_ptr(&dd)
42{
43}
44
45Job::~Job()
46{
47 delete d_ptr;
48}
49
50Session *Job::session() const
51{
52 Q_D(const Job);
53 return d->m_session;
54}
55
56void Job::start()
57{
58 Q_D(Job);
59 d->sessionInternal()->addJob(this);
60}
61
62void Job::handleResponse(const Message &response)
63{
64 handleErrorReplies(response);
65}
66
67void Job::connectionLost()
68{
69 Q_D(Job);
70 setError(ConnectionLost);
71 setErrorText("Connection to server lost: " + d->m_errorMessage);
72 emitResult();
73}
74
75void Job::setSocketError(QAbstractSocket::SocketError error)
76{
77 Q_D(Job);
78 d->m_socketError = error;
79}
80
81void Job::setErrorMessage(const QString &msg)
82{
83 Q_D(Job);
84 d->m_errorMessage = msg;
85}
86
87Job::HandlerResponse Job::handleErrorReplies(const Message &response)
88{
89 Q_D(Job);
90 // qCDebug(KIMAP2_LOG) << response.toString();
91
92 if (!response.content.isEmpty() &&
93 d->tags.contains(response.content.first().toString())) {
94 if (response.content.size() < 2) {
95 setErrorText(QString("%1 failed, malformed reply from the server.").arg(d->m_name));
96 } else if (response.content[1].toString() != "OK") {
97 setError(CommandFailed);
98 setErrorText(QString("%1 failed, server replied: %2.\n Sent command: %3").arg(d->m_name).arg(QLatin1String(response.toString().constData())).arg(QString(d->m_currentCommand)));
99 }
100 d->tags.removeAll(response.content.first().toString());
101 if (d->tags.isEmpty()) { // Only emit result when the last command returned
102 emitResult();
103 }
104 return Handled;
105 }
106
107 return NotHandled;
108}
void setErrorText(const QString &errorText)
void emitResult()
int error() const
void setError(int errorCode)
QString arg(Args &&... args) const const
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:21:18 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.