KIMAP

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

KDE's Doxygen guidelines are available online.