2
* Copyright (C) 2013 Canonical, Ltd.
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.
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.
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/>.
16
* Author: Pete Woods <pete.woods@canonical.com>
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>
31
#include <QDBusConnection>
32
#include <QDBusServiceWatcher>
34
using namespace hud::common;
35
using namespace hud::service;
38
m_sessionBus(QDBusConnection::sessionBus()), m_queryCounter(0) {
39
DBusTypes::registerMetaTypes();
40
LibUnityVoice::UnityVoice::registerMetaTypes();
46
void Factory::setSessionBus(const QDBusConnection &sessionBus) {
47
m_sessionBus = sessionBus;
50
HudService::Ptr Factory::singletonHudService() {
51
if (m_hudService.isNull()) {
53
new HudServiceImpl(*this, singletonApplicationList(),
59
QSharedPointer<ComCanonicalUnityWindowStackInterface> Factory::singletonWindowStack() {
60
if (m_windowStack.isNull()) {
62
new ComCanonicalUnityWindowStackInterface(
63
DBusTypes::WINDOW_STACK_DBUS_NAME,
64
DBusTypes::WINDOW_STACK_DBUS_PATH, sessionBus()));
69
QSharedPointer<QDBusServiceWatcher> Factory::windowStackWatcher() {
70
return QSharedPointer<QDBusServiceWatcher>(
71
new QDBusServiceWatcher(DBusTypes::WINDOW_STACK_DBUS_NAME,
72
sessionBus(), QDBusServiceWatcher::WatchForUnregistration));
75
QSharedPointer<ComCanonicalAppMenuRegistrarInterface> Factory::singletonAppmenu() {
76
if (m_appmenu.isNull()) {
78
new ComCanonicalAppMenuRegistrarInterface(
79
DBusTypes::APPMENU_REGISTRAR_DBUS_NAME,
80
DBusTypes::APPMENU_REGISTRAR_DBUS_PATH, sessionBus()));
85
QDBusConnection Factory::sessionBus() {
89
Query::Ptr Factory::newQuery(const QString &query, const QString &sender) {
91
new QueryImpl(m_queryCounter++, query, sender,
92
*singletonHudService(), singletonApplicationList(),
93
singletonVoice(), sessionBus()));
96
ApplicationList::Ptr Factory::singletonApplicationList() {
97
if (m_applicationList.isNull()) {
98
m_applicationList.reset(
99
new ApplicationListImpl(*this, singletonWindowStack(),
100
windowStackWatcher()));
102
return m_applicationList;
105
UsageTracker::Ptr Factory::singletonUsageTracker() {
106
if (m_usageTracker.isNull()) {
107
m_usageTracker.reset(new SqliteUsageTracker());
109
return m_usageTracker;
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));
123
Application::Ptr Factory::newApplication(const QString &applicationId) {
124
return Application::Ptr(
125
new ApplicationImpl(applicationId, *this, sessionBus()));
128
ItemStore::Ptr Factory::newItemStore(const QString &applicationId) {
129
return ItemStore::Ptr(new ItemStore(applicationId, singletonUsageTracker()));
132
Window::Ptr Factory::newWindow(unsigned int windowId,
133
const QString &applicationId, WindowContext::Ptr allwindowsContext) {
135
new WindowImpl(windowId, applicationId, allwindowsContext, *this));
138
WindowToken::Ptr Factory::newWindowToken(const QString &applicationId,
139
QList<CollectorToken::Ptr> tokens) {
140
return WindowToken::Ptr(new WindowTokenImpl(tokens, newItemStore(applicationId)));
143
WindowContext::Ptr Factory::newWindowContext() {
144
return WindowContext::Ptr(new WindowContextImpl(*this));
147
Collector::Ptr Factory::newDBusMenuCollector(unsigned int windowId,
148
const QString &applicationId) {
149
Q_UNUSED(applicationId);
150
return Collector::Ptr(new DBusMenuCollector(windowId, singletonAppmenu()));
153
Collector::Ptr Factory::newGMenuCollector(const QString &name,
154
const QDBusObjectPath &actionPath, const QDBusObjectPath &menuPath) {
155
return Collector::Ptr(new GMenuCollector(name, actionPath, menuPath));
158
Collector::Ptr Factory::newGMenuWindowCollector(unsigned int windowId,
159
const QString &applicationId) {
160
return Collector::Ptr(
161
new GMenuWindowCollector(windowId, applicationId,
162
singletonWindowStack(), *this));