File indexing completed on 2024-05-12 05:12:42

0001 /*
0002  * Copyright (C) 2014  Bhaskar Kandiyal <bkandiyal@gmail.com>
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 
0020 #ifndef IMPORTCOMMAND_H
0021 #define IMPORTCOMMAND_H
0022 
0023 #include "abstractcommand.h"
0024 
0025 #include <Akonadi/Collection>
0026 #include <Akonadi/Item>
0027 
0028 namespace Akonadi
0029 {
0030 class XmlDocument;
0031 };
0032 
0033 class QFile;
0034 class KJob;
0035 
0036 class ImportCommand : public AbstractCommand
0037 {
0038     Q_OBJECT
0039 
0040 public:
0041     explicit ImportCommand(QObject *parent = nullptr);
0042     virtual ~ImportCommand();
0043 
0044     QString name() const override;
0045 
0046 public Q_SLOTS:
0047     void start() override;
0048 
0049 protected:
0050     int initCommand(QCommandLineParser *parser) override;
0051     void setupCommandOptions(QCommandLineParser *parser) override;
0052 
0053 private:
0054     Akonadi::Collection mParentCollection;
0055     Akonadi::Collection mCurrentCollection;
0056     QVector<Akonadi::Item> mItemQueue;
0057     QVector<Akonadi::Collection> mCollections;
0058     QMap<QString, Akonadi::Collection> mCollectionMap;
0059     Akonadi::XmlDocument *mDocument;
0060 
0061 private Q_SLOTS:
0062     void onCollectionCreated(KJob *job);
0063     void onCollectionFetched(KJob *job);
0064     void onChildrenFetched(KJob *job);
0065     void onItemCreated(KJob *job);
0066     void onParentFetched(KJob *job);
0067     void processNextCollectionFromMap();
0068     void processNextCollection();
0069     void processNextItemFromQueue();
0070 };
0071 
0072 #endif // IMPORTCOMMAND_H