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 "updateusersjob.h" 0010 0011 #include "useridrequestjob.h" 0012 #include "users.h" 0013 #include "usersrequestjob.h" 0014 0015 using namespace OXA; 0016 0017 UpdateUsersJob::UpdateUsersJob(QObject *parent) 0018 : KJob(parent) 0019 { 0020 } 0021 0022 void UpdateUsersJob::start() 0023 { 0024 auto userIdJob = new UserIdRequestJob(this); 0025 connect(userIdJob, &UserIdRequestJob::result, this, &UpdateUsersJob::userIdRequestJobFinished); 0026 0027 auto usersJob = new UsersRequestJob(this); 0028 connect(usersJob, &UsersRequestJob::result, this, &UpdateUsersJob::usersRequestJobFinished); 0029 0030 userIdJob->start(); 0031 usersJob->start(); 0032 } 0033 0034 void UpdateUsersJob::userIdRequestJobFinished(KJob *job) 0035 { 0036 if (job->error()) { 0037 setError(job->error()); 0038 setErrorText(job->errorText()); 0039 } else { 0040 mUserIdRequestFinished = true; 0041 0042 auto requestJob = qobject_cast<UserIdRequestJob *>(job); 0043 mUserId = requestJob->userId(); 0044 0045 finish(); 0046 } 0047 } 0048 0049 void UpdateUsersJob::usersRequestJobFinished(KJob *job) 0050 { 0051 if (job->error()) { 0052 setError(job->error()); 0053 setErrorText(job->errorText()); 0054 } else { 0055 mUsersRequestFinished = true; 0056 0057 auto requestJob = qobject_cast<UsersRequestJob *>(job); 0058 mUsers = requestJob->users(); 0059 0060 finish(); 0061 } 0062 } 0063 0064 void UpdateUsersJob::finish() 0065 { 0066 // check if both sub-jobs have finished 0067 if (!(mUserIdRequestFinished && mUsersRequestFinished)) { 0068 return; 0069 } 0070 0071 if (error()) { 0072 emitResult(); 0073 return; 0074 } 0075 0076 Users::self()->setCurrentUserId(mUserId); 0077 Users::self()->setUsers(mUsers); 0078 0079 emitResult(); 0080 } 0081 0082 #include "moc_updateusersjob.cpp"