KIMAP

job.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Kevin Ottens <ervin@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "job.h"
8#include "job_p.h"
9#include "response_p.h"
10#include "session_p.h"
11
12#include "kimap_debug.h"
13#include <KLocalizedString>
14
15using namespace KIMAP;
16
17Job::Job(Session *session)
18 : KJob(session)
19 , d_ptr(new JobPrivate(session, i18n("Job")))
20{
21}
22
23Job::Job(JobPrivate &dd)
24 : KJob(dd.m_session)
25 , d_ptr(&dd)
26{
27}
28
29Job::~Job()
30{
31 delete d_ptr;
32}
33
34Session *Job::session() const
35{
36 Q_D(const Job);
37 return d->m_session;
38}
39
40void Job::start()
41{
42 Q_D(Job);
43 d->sessionInternal()->addJob(this);
44}
45
46void Job::handleResponse(const Response &response)
47{
48 handleErrorReplies(response);
49}
50
51void Job::connectionLost()
52{
53 setError(KJob::UserDefinedError);
54 setErrorText(i18n("Connection to server lost."));
55 emitResult();
56}
57
58Job::HandlerResponse Job::handleErrorReplies(const Response &response)
59{
60 Q_D(Job);
61 // qCDebug(KIMAP_LOG) << response.toString();
62
63 if (!response.content.isEmpty() && d->tags.contains(response.content.first().toString())) {
64 if (response.content.size() < 2) {
65 setErrorText(i18n("%1 failed, malformed reply from the server.", d->m_name));
66 } else if (response.content[1].toString() != "OK") {
67 setError(UserDefinedError);
68 setErrorText(i18n("%1 failed, server replied: %2", d->m_name, QLatin1StringView(response.toString().constData())));
69 }
70 d->tags.removeAll(response.content.first().toString());
71 if (d->tags.isEmpty()) { // Only emit result when the last command returned
72 emitResult();
73 }
74 return Handled;
75 }
76
77 return NotHandled;
78}
79
80#include "moc_job.cpp"
void setErrorText(const QString &errorText)
void emitResult()
void setError(int errorCode)
QString i18n(const char *text, const TYPE &arg...)
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:12:10 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.