File indexing completed on 2025-01-26 05:00:55

0001 /*
0002  *   SPDX-FileCopyrightText: 2011, 2012, 2013, 2014, 2015 Ivan Cukic <ivan.cukic(at)kde.org>
0003  *
0004  *   SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #pragma once
0008 
0009 // Qt
0010 #include <QObject>
0011 
0012 // STL
0013 #include <memory>
0014 
0015 // Local
0016 #include <Plugin.h>
0017 
0018 class QSqlQuery;
0019 
0020 /**
0021  * Communication with the outer world.
0022  *
0023  * - Handles configuration
0024  * - Filters the events based on the user's configuration.
0025  */
0026 class ResourceLinking : public QObject
0027 {
0028     Q_OBJECT
0029     Q_CLASSINFO("D-Bus Interface", "org.kde.ActivityManager.Resources.Linking")
0030 
0031 public:
0032     explicit ResourceLinking(QObject *parent);
0033 
0034     void init();
0035 
0036 public Q_SLOTS:
0037     /**
0038      * Links the resource to the activity
0039      * @param initiatingAgent application that requests the linking. Leave
0040      *     empty if the resource should be linked to the activity regardless
0041      *     of which application asks for it.
0042      * @param targettedResource resource to link to the activity. Can be a file
0043      *     or any other kind of URI. If it is not a globally recognizable URI,
0044      *     you should set the initiatingAgent to a specific application.
0045      * @param usedActivity Activity to link to. Leave empty to link to all
0046      *     activities.
0047      */
0048     void LinkResourceToActivity(QString initiatingAgent, QString targettedResource, QString usedActivity = QString());
0049     void UnlinkResourceFromActivity(QString initiatingAgent, QString targettedResource, QString usedActivity = QString());
0050     bool IsResourceLinkedToActivity(QString initiatingAgent, QString targettedResource, QString usedActivity = QString());
0051 
0052 Q_SIGNALS:
0053     void ResourceLinkedToActivity(const QString &initiatingAgent, const QString &targettedResource, const QString &usedActivity);
0054     void ResourceUnlinkedFromActivity(const QString &initiatingAgent, const QString &targettedResource, const QString &usedActivity);
0055 
0056 private Q_SLOTS:
0057     void onActivityAdded(const QString &activity);
0058     void onActivityRemoved(const QString &activity);
0059     void onCurrentActivityChanged(const QString &activity);
0060 
0061 private:
0062     bool validateArguments(QString &initiatingAgent, QString &targettedResource, QString &usedActivity, bool checkFilesExist = true);
0063 
0064     QString currentActivity() const;
0065 
0066     std::unique_ptr<QSqlQuery> linkResourceToActivityQuery;
0067     std::unique_ptr<QSqlQuery> unlinkResourceFromAllActivitiesQuery;
0068     std::unique_ptr<QSqlQuery> unlinkResourceFromActivityQuery;
0069     std::unique_ptr<QSqlQuery> isResourceLinkedToActivityQuery;
0070 };