File indexing completed on 2024-11-24 04:44:30

0001 /*
0002     This file is part of oxaccess.
0003 
0004     SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #include "useridrequestjob.h"
0010 
0011 #include "davmanager.h"
0012 #include "foldersrequestjob.h"
0013 
0014 using namespace OXA;
0015 
0016 UserIdRequestJob::UserIdRequestJob(QObject *parent)
0017     : KJob(parent)
0018     , mUserId(-1)
0019 {
0020 }
0021 
0022 void UserIdRequestJob::start()
0023 {
0024     auto job = new FoldersRequestJob(0, FoldersRequestJob::Modified, this);
0025     connect(job, &FoldersRequestJob::result, this, &UserIdRequestJob::davJobFinished);
0026 
0027     job->start();
0028 }
0029 
0030 qlonglong UserIdRequestJob::userId() const
0031 {
0032     return mUserId;
0033 }
0034 
0035 void UserIdRequestJob::davJobFinished(KJob *job)
0036 {
0037     if (job->error()) {
0038         setError(job->error());
0039         setErrorText(job->errorText());
0040         emitResult();
0041         return;
0042     }
0043 
0044     auto requestJob = qobject_cast<FoldersRequestJob *>(job);
0045     Q_ASSERT(requestJob);
0046 
0047     const Folder::List folders = requestJob->folders();
0048     for (const Folder &folder : folders) {
0049         if (folder.folderId() == 1) {
0050             // Found folder with 'Private Folders' as parent, so the owner must
0051             // be the user that is currently logged in.
0052             mUserId = folder.owner();
0053             break;
0054         }
0055     }
0056 
0057     if (mUserId == -1) {
0058         setError(UserDefinedError);
0059         setErrorText(QStringLiteral("No private folder found"));
0060     }
0061 
0062     emitResult();
0063 }
0064 
0065 #include "moc_useridrequestjob.cpp"