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

0001 /*
0002     Copyright (C) 2013  Jonathan Marten <jjm@keelhaul.me.uk>
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 GROUPCOMMAND_H
0020 #define GROUPCOMMAND_H
0021 
0022 #include "abstractcommand.h"
0023 
0024 #include <Akonadi/Item>
0025 #include <KContacts/ContactGroup>
0026 
0027 class KJob;
0028 
0029 class GroupCommand : public AbstractCommand
0030 {
0031     Q_OBJECT
0032 
0033 public:
0034     explicit GroupCommand(QObject *parent = nullptr);
0035     virtual ~GroupCommand();
0036 
0037     QString name() const override;
0038 
0039 public Q_SLOTS:
0040     void start() override;
0041 
0042 protected:
0043     void setupCommandOptions(QCommandLineParser *parser) override;
0044     int initCommand(QCommandLineParser *parser) override;
0045 
0046 private:
0047     enum Mode {
0048         ModeExpand,
0049         ModeAdd,
0050         ModeDelete,
0051         ModeClean
0052     };
0053 
0054     Akonadi::Item *mGroupItem;
0055 
0056     QString mGroupArg;
0057     QString mNameArg;
0058     QStringList mItemArgs;
0059     bool mBriefMode;
0060     GroupCommand::Mode mOperationMode;
0061 
0062 private:
0063     void fetchItems();
0064 
0065     void displayContactData(const KContacts::ContactGroup::Data &data);
0066     void displayContactReference(Akonadi::Item::Id id);
0067     void displayContactReference(const Akonadi::Item &item, const QString &email = QString());
0068     void displayReferenceError(Akonadi::Item::Id id);
0069 
0070     bool removeDataByEmail(KContacts::ContactGroup &group, const QString &email, bool verbose = false);
0071     bool removeReferenceById(KContacts::ContactGroup &group, const QString &id, bool verbose = false);
0072 
0073     AbstractCommand::Errors showExpandedGroup(const KContacts::ContactGroup &group);
0074     AbstractCommand::Errors addGroupItems(KContacts::ContactGroup &group);
0075     AbstractCommand::Errors deleteGroupItems(KContacts::ContactGroup &group);
0076     AbstractCommand::Errors cleanGroupItems(KContacts::ContactGroup &group);
0077 
0078 private Q_SLOTS:
0079     void onItemsFetched(KJob *job);
0080 };
0081 
0082 #endif                          // GROUPCOMMAND_H