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 "kimap_debug.h"
13 #include <KLocalizedString>
14 
15 using namespace KIMAP;
16 
17 Job::Job(Session *session)
18  : KJob(session)
19  , d_ptr(new JobPrivate(session, i18n("Job")))
20 {
21 }
22 
23 Job::Job(JobPrivate &dd)
24  : KJob(dd.m_session)
25  , d_ptr(&dd)
26 {
27 }
28 
29 Job::~Job()
30 {
31  delete d_ptr;
32 }
33 
34 Session *Job::session() const
35 {
36  Q_D(const Job);
37  return d->m_session;
38 }
39 
40 void Job::start()
41 {
42  Q_D(Job);
43  d->sessionInternal()->addJob(this);
44 }
45 
46 void Job::handleResponse(const Response &response)
47 {
48  handleErrorReplies(response);
49 }
50 
51 void Job::connectionLost()
52 {
53  setError(KJob::UserDefinedError);
54  setErrorText(i18n("Connection to server lost."));
55  emitResult();
56 }
57 
58 Job::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, QLatin1String(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"
Q_SCRIPTABLE Q_NOREPLY void start()
QString i18n(const char *text, const TYPE &arg...)
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Dec 10 2023 03:48:59 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.