File indexing completed on 2024-05-12 05:12:40
0001 /* 0002 Copyright (C) 2012 Kevin Krammer <krammer@kde.org> 0003 0004 This program is free software; you can redistribute it and/or modify 0005 it under the terms of the GNU General Public License as published by 0006 the Free Software Foundation; either version 2 of the License, or 0007 (at your option) any later version. 0008 0009 This program is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 GNU General Public License for more details. 0013 0014 You should have received a copy of the GNU General Public License along 0015 with this program; if not, write to the Free Software Foundation, Inc., 0016 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 0017 */ 0018 0019 #include "collectionpathjob.h" 0020 #include "collectionresolvejob.h" 0021 0022 #include <KLocalizedString> 0023 0024 #include <Akonadi/CollectionFetchJob> 0025 0026 using namespace Akonadi; 0027 0028 CollectionPathJob::CollectionPathJob(const Akonadi::Collection &collection, QObject *parent) 0029 : KCompositeJob(parent), 0030 mCollection(collection) 0031 { 0032 setAutoDelete(false); 0033 } 0034 0035 void CollectionPathJob::start() 0036 { 0037 if (!mCollection.isValid()) { 0038 emitResult(); 0039 return; 0040 } 0041 0042 CollectionPathResolver *resolver = new HackedCollectionPathResolver(mCollection, this); 0043 addSubjob(resolver); 0044 resolver->start(); 0045 } 0046 0047 void CollectionPathJob::slotResult(KJob *job) 0048 { 0049 if (job->error() == 0) { 0050 CollectionPathResolver *resolver = qobject_cast<CollectionPathResolver *>(job); 0051 Q_ASSERT(resolver != nullptr); 0052 mPath = resolver->path(); 0053 } 0054 0055 bool willEmitResult = (job->error() && !error()); 0056 KCompositeJob::slotResult(job); 0057 0058 if (!hasSubjobs() && !willEmitResult) { 0059 emitResult(); 0060 } 0061 } 0062 0063 QString CollectionPathJob::collectionPath() const 0064 { 0065 return (mPath); 0066 } 0067 0068 QString CollectionPathJob::formattedCollectionPath() const 0069 { 0070 return (i18nc("@info:shell 1=collection ID, 2=collection path", 0071 "%1 (\"/%2\")", QString::number(mCollection.id()), mPath)); 0072 }