File indexing completed on 2024-11-10 04:40:08

0001 /*
0002  * SPDX-FileCopyrightText: 2008 Igor Trindade Oliveira <igor_trindade@yahoo.com.br>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.1-or-later
0005  */
0006 
0007 #pragma once
0008 
0009 #include "servermanager.h"
0010 
0011 #include <QList>
0012 #include <QObject>
0013 #include <QPair>
0014 
0015 #include <memory>
0016 
0017 class KProcess;
0018 class KJob;
0019 
0020 class SetupTest : public QObject
0021 {
0022     Q_OBJECT
0023     Q_CLASSINFO("D-Bus Interface", "org.kde.Akonadi.Testrunner")
0024 
0025 public:
0026     SetupTest();
0027     ~SetupTest() override;
0028 
0029     /**
0030       Sets the instance identifier for the Akonadi session.
0031       Call this before using any other Akonadi API!
0032     */
0033     void setupInstanceId();
0034     bool startAkonadiDaemon();
0035     void stopAkonadiDaemon();
0036     QString basePath() const;
0037 
0038     /// Identifier used for the Akonadi session
0039     QString instanceId() const;
0040 
0041     /// set an environment variable
0042     void setEnvironmentVariable(const QByteArray &name, const QString &value);
0043 
0044     /// retrieve all modified environment variables, for writing the shell script
0045     using EnvVar = QPair<QByteArray, QByteArray>;
0046     QList<EnvVar> environmentVariables() const;
0047 
0048 public Q_SLOTS:
0049     Q_SCRIPTABLE void shutdown();
0050     Q_SCRIPTABLE void shutdownHarder();
0051     /** Synchronously restarts the server. */
0052     Q_SCRIPTABLE void restartAkonadiServer();
0053     Q_SCRIPTABLE void trackAkonadiProcess(bool track);
0054 
0055 Q_SIGNALS:
0056     void setupDone();
0057     void serverExited(int exitCode);
0058 
0059 private Q_SLOTS:
0060     void serverStateChanged(Akonadi::ServerManager::State state);
0061     void slotAkonadiDaemonProcessFinished(int exitCode);
0062     void agentCreationResult(KJob *job);
0063     void synchronizationResult(KJob *job);
0064 
0065 private:
0066     void setupAgents();
0067     void copyXdgDirectory(const QString &src, const QString &dst);
0068     void copyDirectory(const QString &src, const QString &dst);
0069     void createTempEnvironment();
0070     void cleanTempEnvironment() const;
0071     void setupFailed();
0072     void writeAkonadiserverrc(const QString &path);
0073     void checkSetupDone();
0074 
0075 private:
0076     std::unique_ptr<KProcess> mAkonadiDaemonProcess;
0077     bool mShuttingDown;
0078     bool mAgentsCreated;
0079     bool mTrackAkonadiProcess;
0080     int mSetupJobCount;
0081     int mExitCode;
0082     QList<EnvVar> mEnvVars;
0083 };