File indexing completed on 2024-05-19 05:11:17

0001 /**
0002   This file is part of the akonadi-calendar library.
0003 
0004   SPDX-FileCopyrightText: 2013 Sérgio Martins <iamsergio@gmail.com>
0005 
0006   SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #pragma once
0010 
0011 #include "akonadi-calendar_export.h"
0012 
0013 #include <Akonadi/Collection>
0014 
0015 #include <QObject>
0016 #include <QString>
0017 
0018 #include <memory>
0019 
0020 /**
0021  * A class to import ical calendar files into akonadi.
0022  *
0023  * @since 4.12
0024  */
0025 namespace Akonadi
0026 {
0027 class IncidenceChanger;
0028 class ICalImporterPrivate;
0029 
0030 class AKONADI_CALENDAR_EXPORT ICalImporter : public QObject
0031 {
0032     Q_OBJECT
0033 public:
0034     /**
0035      * Constructs a new ICalImporter object. Use a different ICalImporter instance for each file you want to import.
0036      *
0037      * @param changer An existing IncidenceChanger, if 0, an internal one will be created.
0038      *                If you pass an existing one, you will be able to undo/redo import operations.
0039      * @param parent  Parent QObject.
0040      */
0041     explicit ICalImporter(Akonadi::IncidenceChanger *changer = nullptr, QObject *parent = nullptr);
0042     ~ICalImporter() override;
0043 
0044     /**
0045      * Translated error message.
0046      * This is set when either importIntoExistingFinished() or importIntoNewResource() return false
0047      * or when the corresponding signals are have success=false.
0048      */
0049     [[nodiscard]] QString errorMessage() const;
0050 
0051 Q_SIGNALS:
0052     /**
0053      * Emitted after calling importIntoExistingResource()
0054      * @param success Success of the operation.
0055      * @param total Number of incidences included in the ical file.
0056      *
0057      * @see importIntoExistingResource(), errorMessage().
0058      */
0059     void importIntoExistingFinished(bool success, int total);
0060 
0061     /**
0062      * Emitted after calling importIntoNewResource().
0063      * If success is false, check errorMessage().
0064      */
0065     void importIntoNewFinished(bool success);
0066 
0067 public Q_SLOTS:
0068 
0069     /**
0070      * Creates a new akonadi_ical_resource and configures it to use @p filename.
0071      * @param filename ical absolute file path
0072      * @return True if the job was started, in this case you should wait for the corresponding signal.
0073      */
0074     bool importIntoNewResource(const QString &filename);
0075 
0076     /**
0077      * Imports an ical file into an existing resource.
0078      * @param url Path of a local or remote file to import.
0079      * @param collectionId The destination collection. If null, the user will be prompted for a destination.
0080      *
0081      * @return false if some basic validation happened, like insufficient permissions. Use errorMessage() to see
0082      *         what happened. The importIntoExistingFinished() signal won't be emitted in this case.
0083      *
0084      *         true if the import job was started. importIntoExistingFinished() signal will be emitted in this case.
0085      */
0086     bool importIntoExistingResource(const QUrl &url, Akonadi::Collection collection);
0087 
0088 private:
0089     std::unique_ptr<ICalImporterPrivate> const d;
0090 };
0091 }