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 #ifndef COLLECTIONRESOLVEJOB_H
0020 #define COLLECTIONRESOLVEJOB_H
0021 
0022 #include <Akonadi/Collection>
0023 #include <Akonadi/CollectionPathResolver>
0024 #include <Akonadi/Item>
0025 #include <KCompositeJob>
0026 
0027 class HackedCollectionPathResolver : public Akonadi::CollectionPathResolver
0028 {
0029     Q_OBJECT
0030 
0031 public:
0032     explicit HackedCollectionPathResolver(const QString &path, QObject *parent = nullptr);
0033     explicit HackedCollectionPathResolver(const Akonadi::Collection &col, QObject *parent = nullptr);
0034 
0035 protected:
0036     bool addSubjob(KJob *job) override;
0037 };
0038 
0039 class CollectionResolveJob : public KCompositeJob
0040 {
0041     Q_OBJECT
0042 
0043 public:
0044     explicit CollectionResolveJob(const QString &userInput, QObject *parent = nullptr);
0045     virtual ~CollectionResolveJob() = default;
0046 
0047     void start() override;
0048 
0049     bool hasUsableInput();
0050     bool hadSlash() const
0051     {
0052         return (mHadSlash);
0053     }
0054     Akonadi::Collection collection() const
0055     {
0056         return (mCollection);
0057     }
0058     QString formattedCollectionName() const;
0059 
0060     static Akonadi::Item parseItem(const QString &userInput, bool showError = false);
0061     static Akonadi::Collection parseCollection(const QString &userInput);
0062 
0063 protected Q_SLOTS:
0064     void slotResult(KJob *job) override;
0065 
0066 private:
0067     const QString mUserInput;
0068     Akonadi::Collection mCollection;
0069     bool mHadSlash;
0070 
0071 private:
0072     void fetchBase();
0073 };
0074 
0075 #endif                          // COLLECTIONRESOLVEJOB_H