File indexing completed on 2024-07-14 15:44:41

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2013 Martin Gräßlin <mgraesslin@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 #pragma once
0010 
0011 #include <kwinglobals.h>
0012 
0013 #include <QObject>
0014 #include <QStringList>
0015 
0016 #include <kactivities/controller.h>
0017 
0018 namespace KActivities
0019 {
0020 class Controller;
0021 }
0022 
0023 namespace KWin
0024 {
0025 class Window;
0026 
0027 class KWIN_EXPORT Activities : public QObject
0028 {
0029     Q_OBJECT
0030 
0031 public:
0032     explicit Activities();
0033 
0034     bool stop(const QString &id);
0035     bool start(const QString &id);
0036     void setCurrent(const QString &activity);
0037     /**
0038      * Adds/removes window \a window to/from \a activity.
0039      *
0040      * Takes care of transients as well.
0041      */
0042     void toggleWindowOnActivity(Window *window, const QString &activity, bool dont_activate);
0043 
0044     QStringList running() const;
0045     QStringList all() const;
0046     const QString &current() const;
0047     const QString &previous() const;
0048 
0049     static QString nullUuid();
0050 
0051     KActivities::Controller::ServiceStatus serviceStatus() const;
0052 
0053 Q_SIGNALS:
0054     /**
0055      * This signal is emitted when the global
0056      * activity is changed
0057      * @param id id of the new current activity
0058      */
0059     void currentChanged(const QString &id);
0060     /**
0061      * This signal is emitted when a new activity is added
0062      * @param id id of the new activity
0063      */
0064     void added(const QString &id);
0065     /**
0066      * This signal is emitted when the activity
0067      * is removed
0068      * @param id id of the removed activity
0069      */
0070     void removed(const QString &id);
0071 
0072 private Q_SLOTS:
0073     void slotServiceStatusChanged();
0074     void slotRemoved(const QString &activity);
0075     void slotCurrentChanged(const QString &newActivity);
0076     void reallyStop(const QString &id); // dbus deadlocks suck
0077 
0078 private:
0079     QString m_previous;
0080     QString m_current;
0081     KActivities::Controller *m_controller;
0082 };
0083 
0084 inline QStringList Activities::all() const
0085 {
0086     return m_controller->activities();
0087 }
0088 
0089 inline const QString &Activities::current() const
0090 {
0091     return m_current;
0092 }
0093 
0094 inline const QString &Activities::previous() const
0095 {
0096     return m_previous;
0097 }
0098 
0099 inline QStringList Activities::running() const
0100 {
0101     return m_controller->activities(KActivities::Info::Running);
0102 }
0103 
0104 inline QString Activities::nullUuid()
0105 {
0106     // cloned from kactivities/src/lib/core/consumer.cpp
0107     return QStringLiteral("00000000-0000-0000-0000-000000000000");
0108 }
0109 
0110 }