~ubuntu-branches/ubuntu/trusty/hud/trusty-updates

« back to all changes in this revision

Viewing changes to service/Factory.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-01-20 19:43:59 UTC
  • mfrom: (1.1.26)
  • Revision ID: package-import@ubuntu.com-20140120194359-jxxxqtd4ql9elvpf
Tags: 13.10.1+14.04.20140120-0ubuntu1
* New rebuild forced
* Automatic snapshot from revision 362

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU General Public License version 3, as published
 
6
 * by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY{} without even the implied warranties of
 
10
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
11
 * PURPOSE.  See the GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License along
 
14
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Author: Pete Woods <pete.woods@canonical.com>
 
17
 */
 
18
 
 
19
#include <service/Factory.h>
 
20
#include <service/ApplicationImpl.h>
 
21
#include <service/ApplicationListImpl.h>
 
22
#include <service/AppmenuRegistrarInterface.h>
 
23
#include <service/HudServiceImpl.h>
 
24
#include <service/WindowImpl.h>
 
25
#include <service/QueryImpl.h>
 
26
#include <service/SqliteUsageTracker.h>
 
27
#include <service/VoiceImpl.h>
 
28
#include <service/WindowImpl.h>
 
29
#include <common/DBusTypes.h>
 
30
 
 
31
#include <QDBusConnection>
 
32
#include <QDBusServiceWatcher>
 
33
 
 
34
using namespace hud::common;
 
35
using namespace hud::service;
 
36
 
 
37
Factory::Factory() :
 
38
                m_sessionBus(QDBusConnection::sessionBus()), m_queryCounter(0) {
 
39
        DBusTypes::registerMetaTypes();
 
40
        LibUnityVoice::UnityVoice::registerMetaTypes();
 
41
}
 
42
 
 
43
Factory::~Factory() {
 
44
}
 
45
 
 
46
void Factory::setSessionBus(const QDBusConnection &sessionBus) {
 
47
        m_sessionBus = sessionBus;
 
48
}
 
49
 
 
50
HudService::Ptr Factory::singletonHudService() {
 
51
        if (m_hudService.isNull()) {
 
52
                m_hudService.reset(
 
53
                                new HudServiceImpl(*this, singletonApplicationList(),
 
54
                                                sessionBus()));
 
55
        }
 
56
        return m_hudService;
 
57
}
 
58
 
 
59
QSharedPointer<ComCanonicalUnityWindowStackInterface> Factory::singletonWindowStack() {
 
60
        if (m_windowStack.isNull()) {
 
61
                m_windowStack.reset(
 
62
                                new ComCanonicalUnityWindowStackInterface(
 
63
                                                DBusTypes::WINDOW_STACK_DBUS_NAME,
 
64
                                                DBusTypes::WINDOW_STACK_DBUS_PATH, sessionBus()));
 
65
        }
 
66
        return m_windowStack;
 
67
}
 
68
 
 
69
QSharedPointer<QDBusServiceWatcher> Factory::windowStackWatcher() {
 
70
        return QSharedPointer<QDBusServiceWatcher>(
 
71
                        new QDBusServiceWatcher(DBusTypes::WINDOW_STACK_DBUS_NAME,
 
72
                                        sessionBus(), QDBusServiceWatcher::WatchForUnregistration));
 
73
}
 
74
 
 
75
QSharedPointer<ComCanonicalAppMenuRegistrarInterface> Factory::singletonAppmenu() {
 
76
        if (m_appmenu.isNull()) {
 
77
                m_appmenu.reset(
 
78
                                new ComCanonicalAppMenuRegistrarInterface(
 
79
                                                DBusTypes::APPMENU_REGISTRAR_DBUS_NAME,
 
80
                                                DBusTypes::APPMENU_REGISTRAR_DBUS_PATH, sessionBus()));
 
81
        }
 
82
        return m_appmenu;
 
83
}
 
84
 
 
85
QDBusConnection Factory::sessionBus() {
 
86
        return m_sessionBus;
 
87
}
 
88
 
 
89
Query::Ptr Factory::newQuery(const QString &query, const QString &sender) {
 
90
        return Query::Ptr(
 
91
                        new QueryImpl(m_queryCounter++, query, sender,
 
92
                                        *singletonHudService(), singletonApplicationList(),
 
93
                                        singletonVoice(), sessionBus()));
 
94
}
 
95
 
 
96
ApplicationList::Ptr Factory::singletonApplicationList() {
 
97
        if (m_applicationList.isNull()) {
 
98
                m_applicationList.reset(
 
99
                                new ApplicationListImpl(*this, singletonWindowStack(),
 
100
                                                windowStackWatcher()));
 
101
        }
 
102
        return m_applicationList;
 
103
}
 
104
 
 
105
UsageTracker::Ptr Factory::singletonUsageTracker() {
 
106
        if (m_usageTracker.isNull()) {
 
107
                m_usageTracker.reset(new SqliteUsageTracker());
 
108
        }
 
109
        return m_usageTracker;
 
110
}
 
111
 
 
112
Voice::Ptr Factory::singletonVoice() {
 
113
        if (m_voice.isNull()) {
 
114
                QSharedPointer<ComCanonicalUnityVoiceInterface> voiceInterface(
 
115
                                new ComCanonicalUnityVoiceInterface(
 
116
                                                DBusTypes::UNITY_VOICE_DBUS_NAME,
 
117
                                                DBusTypes::UNITY_VOICE_DBUS_PATH, sessionBus()));
 
118
                m_voice.reset(new VoiceImpl(voiceInterface));
 
119
        }
 
120
        return m_voice;
 
121
}
 
122
 
 
123
Application::Ptr Factory::newApplication(const QString &applicationId) {
 
124
        return Application::Ptr(
 
125
                        new ApplicationImpl(applicationId, *this, sessionBus()));
 
126
}
 
127
 
 
128
ItemStore::Ptr Factory::newItemStore(const QString &applicationId) {
 
129
        return ItemStore::Ptr(new ItemStore(applicationId, singletonUsageTracker()));
 
130
}
 
131
 
 
132
Window::Ptr Factory::newWindow(unsigned int windowId,
 
133
                const QString &applicationId, WindowContext::Ptr allwindowsContext) {
 
134
        return Window::Ptr(
 
135
                        new WindowImpl(windowId, applicationId, allwindowsContext, *this));
 
136
}
 
137
 
 
138
WindowToken::Ptr Factory::newWindowToken(const QString &applicationId,
 
139
                QList<CollectorToken::Ptr> tokens) {
 
140
        return WindowToken::Ptr(new WindowTokenImpl(tokens, newItemStore(applicationId)));
 
141
}
 
142
 
 
143
WindowContext::Ptr Factory::newWindowContext() {
 
144
        return WindowContext::Ptr(new WindowContextImpl(*this));
 
145
}
 
146
 
 
147
Collector::Ptr Factory::newDBusMenuCollector(unsigned int windowId,
 
148
                const QString &applicationId) {
 
149
        Q_UNUSED(applicationId);
 
150
        return Collector::Ptr(new DBusMenuCollector(windowId, singletonAppmenu()));
 
151
}
 
152
 
 
153
Collector::Ptr Factory::newGMenuCollector(const QString &name,
 
154
                const QDBusObjectPath &actionPath, const QDBusObjectPath &menuPath) {
 
155
        return Collector::Ptr(new GMenuCollector(name, actionPath, menuPath));
 
156
}
 
157
 
 
158
Collector::Ptr Factory::newGMenuWindowCollector(unsigned int windowId,
 
159
                const QString &applicationId) {
 
160
        return Collector::Ptr(
 
161
                        new GMenuWindowCollector(windowId, applicationId,
 
162
                                        singletonWindowStack(), *this));
 
163
}