summaryrefslogtreecommitdiffstats
path: root/examples/imapresource/imapserverproxy.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-07-07 22:23:49 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-07-07 22:23:49 +0200
commitda2b049e248c1ad7efeb53685158a205335e4e36 (patch)
tree1e7e5e940e9b760b2108081b1d2f3879cebdb0ff /examples/imapresource/imapserverproxy.cpp
parent9bcb822963fc96c94dbe7dcc4134dcd2dac454ff (diff)
downloadsink-da2b049e248c1ad7efeb53685158a205335e4e36.tar.gz
sink-da2b049e248c1ad7efeb53685158a205335e4e36.zip
A new debug system.
Instead of a single #define as debug area the new system allows for an identifier for each debug message with the structure component.area. The component is a dot separated identifier of the runtime component, such as the process or the plugin. The area is the code component, and can be as such defined at compiletime. The idea of this system is that it becomes possible to i.e. look at the output of all messages in the query subsystem of a specific resource (something that happens in the client process, but in the resource-specific subcomponent). The new macros are supposed to be less likely to clash with other names, hence the new names.
Diffstat (limited to 'examples/imapresource/imapserverproxy.cpp')
-rw-r--r--examples/imapresource/imapserverproxy.cpp40
1 files changed, 21 insertions, 19 deletions
diff --git a/examples/imapresource/imapserverproxy.cpp b/examples/imapresource/imapserverproxy.cpp
index 1b0a2ec..73ec654 100644
--- a/examples/imapresource/imapserverproxy.cpp
+++ b/examples/imapresource/imapserverproxy.cpp
@@ -37,6 +37,8 @@
37 37
38#include "log.h" 38#include "log.h"
39 39
40SINK_DEBUG_AREA("imapserverproxy")
41
40using namespace Imap; 42using namespace Imap;
41 43
42const char* Imap::Flags::Seen = "\\Seen"; 44const char* Imap::Flags::Seen = "\\Seen";
@@ -54,16 +56,16 @@ static KAsync::Job<T> runJob(KJob *job, const std::function<T(KJob*)> &f)
54{ 56{
55 return KAsync::start<T>([job, f](KAsync::Future<T> &future) { 57 return KAsync::start<T>([job, f](KAsync::Future<T> &future) {
56 QObject::connect(job, &KJob::result, [&future, f](KJob *job) { 58 QObject::connect(job, &KJob::result, [&future, f](KJob *job) {
57 Trace() << "Job done: " << job->metaObject()->className(); 59 SinkTrace() << "Job done: " << job->metaObject()->className();
58 if (job->error()) { 60 if (job->error()) {
59 Warning() << "Job failed: " << job->errorString(); 61 SinkWarning() << "Job failed: " << job->errorString();
60 future.setError(job->error(), job->errorString()); 62 future.setError(job->error(), job->errorString());
61 } else { 63 } else {
62 future.setValue(f(job)); 64 future.setValue(f(job));
63 future.setFinished(); 65 future.setFinished();
64 } 66 }
65 }); 67 });
66 Trace() << "Starting job: " << job->metaObject()->className(); 68 SinkTrace() << "Starting job: " << job->metaObject()->className();
67 job->start(); 69 job->start();
68 }); 70 });
69} 71}
@@ -72,15 +74,15 @@ static KAsync::Job<void> runJob(KJob *job)
72{ 74{
73 return KAsync::start<void>([job](KAsync::Future<void> &future) { 75 return KAsync::start<void>([job](KAsync::Future<void> &future) {
74 QObject::connect(job, &KJob::result, [&future](KJob *job) { 76 QObject::connect(job, &KJob::result, [&future](KJob *job) {
75 Trace() << "Job done: " << job->metaObject()->className(); 77 SinkTrace() << "Job done: " << job->metaObject()->className();
76 if (job->error()) { 78 if (job->error()) {
77 Warning() << "Job failed: " << job->errorString(); 79 SinkWarning() << "Job failed: " << job->errorString();
78 future.setError(job->error(), job->errorString()); 80 future.setError(job->error(), job->errorString());
79 } else { 81 } else {
80 future.setFinished(); 82 future.setFinished();
81 } 83 }
82 }); 84 });
83 Trace() << "Starting job: " << job->metaObject()->className(); 85 SinkTrace() << "Starting job: " << job->metaObject()->className();
84 job->start(); 86 job->start();
85 }); 87 });
86} 88}
@@ -117,11 +119,11 @@ KAsync::Job<void> ImapServerProxy::login(const QString &username, const QString
117 auto namespaceJob = new KIMAP::NamespaceJob(mSession); 119 auto namespaceJob = new KIMAP::NamespaceJob(mSession);
118 120
119 return runJob(loginJob).then(runJob(capabilitiesJob)).then<void>([this](){ 121 return runJob(loginJob).then(runJob(capabilitiesJob)).then<void>([this](){
120 Trace() << "Supported capabilities: " << mCapabilities; 122 SinkTrace() << "Supported capabilities: " << mCapabilities;
121 QStringList requiredExtensions = QStringList() << "UIDPLUS" << "NAMESPACE"; 123 QStringList requiredExtensions = QStringList() << "UIDPLUS" << "NAMESPACE";
122 for (const auto &requiredExtension : requiredExtensions) { 124 for (const auto &requiredExtension : requiredExtensions) {
123 if (!mCapabilities.contains(requiredExtension)) { 125 if (!mCapabilities.contains(requiredExtension)) {
124 Warning() << "Server doesn't support required capability: " << requiredExtension; 126 SinkWarning() << "Server doesn't support required capability: " << requiredExtension;
125 //TODO fail the job 127 //TODO fail the job
126 } 128 }
127 } 129 }
@@ -138,9 +140,9 @@ KAsync::Job<void> ImapServerProxy::login(const QString &username, const QString
138 mUserNamespaces << ns.name; 140 mUserNamespaces << ns.name;
139 mUserNamespaceSeparator = ns.separator; 141 mUserNamespaceSeparator = ns.separator;
140 } 142 }
141 Trace() << "Found personal namespaces: " << mPersonalNamespaces << mPersonalNamespaceSeparator; 143 SinkTrace() << "Found personal namespaces: " << mPersonalNamespaces << mPersonalNamespaceSeparator;
142 Trace() << "Found shared namespaces: " << mSharedNamespaces << mSharedNamespaceSeparator; 144 SinkTrace() << "Found shared namespaces: " << mSharedNamespaces << mSharedNamespaceSeparator;
143 Trace() << "Found user namespaces: " << mUserNamespaces << mUserNamespaceSeparator; 145 SinkTrace() << "Found user namespaces: " << mUserNamespaces << mUserNamespaceSeparator;
144 }); 146 });
145} 147}
146 148
@@ -291,8 +293,8 @@ KAsync::Job<QList<qint64>> ImapServerProxy::fetchHeaders(const QString &mailbox)
291 const QMap<qint64,KIMAP::MessageAttribute> &attrs, 293 const QMap<qint64,KIMAP::MessageAttribute> &attrs,
292 const QMap<qint64,KIMAP::MessageFlags> &flags, 294 const QMap<qint64,KIMAP::MessageFlags> &flags,
293 const QMap<qint64,KIMAP::MessagePtr> &messages) { 295 const QMap<qint64,KIMAP::MessagePtr> &messages) {
294 Trace() << "Received " << uids.size() << " headers from " << mailbox; 296 SinkTrace() << "Received " << uids.size() << " headers from " << mailbox;
295 Trace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size(); 297 SinkTrace() << uids.size() << sizes.size() << attrs.size() << flags.size() << messages.size();
296 298
297 //TODO based on the data available here, figure out which messages to actually fetch 299 //TODO based on the data available here, figure out which messages to actually fetch
298 //(we only fetched headers and structure so far) 300 //(we only fetched headers and structure so far)
@@ -344,7 +346,7 @@ KAsync::Job<QString> ImapServerProxy::createSubfolder(const QString &parentMailb
344 } else { 346 } else {
345 *folder = parentMailbox + mPersonalNamespaceSeparator + folderName; 347 *folder = parentMailbox + mPersonalNamespaceSeparator + folderName;
346 } 348 }
347 Trace() << "Creating subfolder: " << *folder; 349 SinkTrace() << "Creating subfolder: " << *folder;
348 return create(*folder); 350 return create(*folder);
349 }) 351 })
350 .then<QString>([=]() { 352 .then<QString>([=]() {
@@ -360,7 +362,7 @@ KAsync::Job<QString> ImapServerProxy::renameSubfolder(const QString &oldMailbox,
360 auto parts = oldMailbox.split(mPersonalNamespaceSeparator); 362 auto parts = oldMailbox.split(mPersonalNamespaceSeparator);
361 parts.removeLast(); 363 parts.removeLast();
362 *folder = parts.join(mPersonalNamespaceSeparator) + mPersonalNamespaceSeparator + newName; 364 *folder = parts.join(mPersonalNamespaceSeparator) + mPersonalNamespaceSeparator + newName;
363 Trace() << "Renaming subfolder: " << oldMailbox << *folder; 365 SinkTrace() << "Renaming subfolder: " << oldMailbox << *folder;
364 return rename(oldMailbox, *folder); 366 return rename(oldMailbox, *folder);
365 }) 367 })
366 .then<QString>([=]() { 368 .then<QString>([=]() {
@@ -370,14 +372,14 @@ KAsync::Job<QString> ImapServerProxy::renameSubfolder(const QString &oldMailbox,
370 372
371KAsync::Job<void> ImapServerProxy::fetchFolders(std::function<void(const QVector<Folder> &)> callback) 373KAsync::Job<void> ImapServerProxy::fetchFolders(std::function<void(const QVector<Folder> &)> callback)
372{ 374{
373 Trace() << "Fetching folders"; 375 SinkTrace() << "Fetching folders";
374 return list(KIMAP::ListJob::IncludeUnsubscribed, [callback](const QList<KIMAP::MailBoxDescriptor> &mailboxes, const QList<QList<QByteArray> > &flags){ 376 return list(KIMAP::ListJob::IncludeUnsubscribed, [callback](const QList<KIMAP::MailBoxDescriptor> &mailboxes, const QList<QList<QByteArray> > &flags){
375 QVector<Folder> list; 377 QVector<Folder> list;
376 for (int i = 0; i < mailboxes.size(); i++) { 378 for (int i = 0; i < mailboxes.size(); i++) {
377 const auto mailbox = mailboxes[i]; 379 const auto mailbox = mailboxes[i];
378 const auto mailboxFlags = flags[i]; 380 const auto mailboxFlags = flags[i];
379 bool noselect = mailboxFlags.contains(QByteArray(FolderFlags::Noselect).toLower()) || mailboxFlags.contains(QByteArray(FolderFlags::Noselect)); 381 bool noselect = mailboxFlags.contains(QByteArray(FolderFlags::Noselect).toLower()) || mailboxFlags.contains(QByteArray(FolderFlags::Noselect));
380 Log() << "Found mailbox: " << mailbox.name << mailboxFlags << FolderFlags::Noselect << noselect; 382 SinkLog() << "Found mailbox: " << mailbox.name << mailboxFlags << FolderFlags::Noselect << noselect;
381 list << Folder{mailbox.name.split(mailbox.separator), mailbox.name, mailbox.separator, noselect}; 383 list << Folder{mailbox.name.split(mailbox.separator), mailbox.name, mailbox.separator, noselect};
382 } 384 }
383 callback(list); 385 callback(list);
@@ -395,9 +397,9 @@ KAsync::Job<void> ImapServerProxy::fetchMessages(const Folder &folder, std::func
395 Q_ASSERT(!mPersonalNamespaceSeparator.isNull()); 397 Q_ASSERT(!mPersonalNamespaceSeparator.isNull());
396 return select(mailboxFromFolder(folder)).then<void, KAsync::Job<void>>([this, callback, folder]() -> KAsync::Job<void> { 398 return select(mailboxFromFolder(folder)).then<void, KAsync::Job<void>>([this, callback, folder]() -> KAsync::Job<void> {
397 return fetchHeaders(mailboxFromFolder(folder)).then<void, KAsync::Job<void>, QList<qint64>>([this, callback](const QList<qint64> &uidsToFetch){ 399 return fetchHeaders(mailboxFromFolder(folder)).then<void, KAsync::Job<void>, QList<qint64>>([this, callback](const QList<qint64> &uidsToFetch){
398 Trace() << "Uids to fetch: " << uidsToFetch; 400 SinkTrace() << "Uids to fetch: " << uidsToFetch;
399 if (uidsToFetch.isEmpty()) { 401 if (uidsToFetch.isEmpty()) {
400 Trace() << "Nothing to fetch"; 402 SinkTrace() << "Nothing to fetch";
401 callback(QVector<Message>()); 403 callback(QVector<Message>());
402 return KAsync::null<void>(); 404 return KAsync::null<void>();
403 } 405 }