~ubuntu-branches/ubuntu/precise/kactivities/precise-proposed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
 *   Copyright (C) 2010 Ivan Cukic <ivan.cukic(at)kde.org>
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License version 2,
 *   or (at your option) any later version, as published by the Free
 *   Software Foundation
 *
 *   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, write to the
 *   Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#ifndef ACTIVITY_MANAGER_P_H_
#define ACTIVITY_MANAGER_P_H_

#include <QSet>
#include <QString>
#include <QTimer>
#include <QDBusServiceWatcher>

#include <KConfig>
#include <KConfigGroup>
#include <KUrl>

#include "ActivityManager.h"
#include "Event.h"
#include "SharedInfo.h"
#include "config-features.h"

#ifdef HAVE_NEPOMUK
    #include <Nepomuk/ResourceManager>
    #include <Nepomuk/Resource>
#endif

#if !defined(HAVE_NEPOMUK) && !defined(Q_CC_MSVC)
    #warning "No Nepomuk, disabling some activity related features"
#endif

class QDBusInterface;

class ActivityManagerPrivate: public QObject {
    Q_OBJECT

public:
    ActivityManagerPrivate(ActivityManager * parent,
            QHash < WId, SharedInfo::WindowData > & _windows,
            QHash < KUrl, SharedInfo::ResourceData > & _resources
        );
    ~ActivityManagerPrivate();

    void addRunningActivity(const QString & id);
    void removeRunningActivity(const QString & id);

    void ensureCurrentActivityIsRunning();
    bool setCurrentActivity(const QString & id);

    void setActivityState(const QString & id, ActivityManager::State state);
    QHash < QString, ActivityManager::State > activities;

    // Current activity
    QString currentActivity;

    //opening/closing activity (ksmserver can only handle one at a time)
    QString transitioningActivity;

    // Configuration
    QTimer configSyncTimer;
    KConfig config;

    QHash < WId, SharedInfo::WindowData > & windows;
    QHash < KUrl, SharedInfo::ResourceData > & resources;

public:
    void initConifg();

    KConfigGroup activitiesConfig();
    KConfigGroup mainConfig();
    QString activityName(const QString & id);

public Q_SLOTS:
    void scheduleConfigSync();
    void configSync();
    void windowClosed(WId windowId);
    void activeWindowChanged(WId windowId);

    void startCompleted();
    void stopCompleted();
    void stopCancelled();

    //for avoiding dbus deadlocks
    void reallyStartActivity(const QString & id);
    void reallyStopActivity(const QString & id);

    void syncActivitiesWithNepomuk();
    void sessionServiceRegistered();

public Q_SLOTS:
    void nepomukOnline();
    void nepomukOffline();

#ifdef HAVE_NEPOMUK
public:
    Nepomuk::Resource activityResource(const QString & id);
    bool nepomukInitialized() const;

    mutable bool m_nepomukInitialized : 1;
    QDBusServiceWatcher * m_nepomukWatcher;
#endif // HAVE_NEPOMUK

private:
    ActivityManager * const q;
    QDBusInterface *ksmserverInterface; //just keeping it for the signals

};

#endif // ACTIVITY_MANAGER_P_H_