kwin/activities.h
Martin Gräßlin 0fb27fd12e Defines to create the boilerplate code for KWin's singleton classes
The define KWIN_SINGLETON adds to a class definition:

public:
    static Foo *create(QObject *parent = 0);
    static Foo *self() { return s_self; }
protected:
    explicit Foo(QObject *parent = 0);
private:
    static Foo *s_self;

There is an additional define KWIN_SINGLETON_VARIABLE to set a different
name than s_self.

The define KWIN_SINGLETON_FACTORY can be used to generate the create
method. It expands to:

Foo *Foo::s_self = 0;
Foo *Foo::create(QObject *parent)
{
    Q_ASSERT(!s_self);
    s_self = new Foo(parent);
    return s_self;
}

In addition there are defines to again set a different variable name and
to create an object of another inheriting class.

All the classes currently using this pattern are adjusted to use these
new defines. In a few places the name was adjusted. E.g. in Compositor
the factory method was called createCompositor instead of create.

REVIEW: 109865
2013-04-15 09:57:25 +02:00

130 lines
3.1 KiB
C++

/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2013 Martin Gräßlin <mgraesslin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef KWIN_ACTIVITIES_H
#define KWIN_ACTIVITIES_H
#include <kwinglobals.h>
#include <QObject>
#include <QStringList>
namespace KActivities {
class Controller;
}
namespace KWin
{
class Client;
class Activities : public QObject
{
Q_OBJECT
public:
~Activities();
bool stop(const QString &id);
bool start(const QString &id);
void update(bool running, bool updateCurrent, QObject *target = NULL, QString slot = QString());
void setCurrent(const QString &activity);
/**
* Adds/removes client \a c to/from \a activity.
*
* Takes care of transients as well.
*/
void toggleClientOnActivity(Client* c, const QString &activity, bool dont_activate);
const QStringList &running() const;
const QStringList &all() const;
const QString &current() const;
const QString &previous() const;
static QString nullUuid();
Q_SIGNALS:
/**
* This signal is emitted when the global
* activity is changed
* @param id id of the new current activity
*/
void currentChanged(const QString &id);
/**
* This signal is emitted when a new activity is added
* @param id id of the new activity
*/
void added(const QString &id);
/**
* This signal is emitted when the activity
* is removed
* @param id id of the removed activity
*/
void removed(const QString &id);
private Q_SLOTS:
void slotRemoved(const QString &activity);
void slotAdded(const QString &activity);
void slotCurrentChanged(const QString &newActivity);
void reallyStop(const QString &id); //dbus deadlocks suck
void handleReply();
private:
QStringList m_running;
QStringList m_all;
QString m_current;
QString m_previous;
KActivities::Controller *m_controller;
KWIN_SINGLETON(Activities)
};
inline
const QStringList &Activities::all() const
{
return m_all;
}
inline
const QString &Activities::current() const
{
return m_current;
}
inline
const QString &Activities::previous() const
{
return m_previous;
}
inline
const QStringList &Activities::running() const
{
return m_running;
}
inline
QString Activities::nullUuid()
{
// cloned from kactivities/src/lib/core/consumer.cpp
return QString("00000000-0000-0000-0000-000000000000");
}
}
#endif // KWIN_ACTIVITIES_H