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

« back to all changes in this revision

Viewing changes to window-stack-bridge/BamfWindowStack.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:
17
17
 */
18
18
 
19
19
#include <BamfWindowStack.h>
20
 
#include <Localisation.h>
 
20
#include <common/DBusTypes.h>
 
21
#include <common/Localisation.h>
21
22
 
22
23
#include <QFile>
23
24
#include <QFileInfo>
24
25
 
25
 
static const QString BAMF_DBUS_NAME("org.ayatana.bamf");
 
26
using namespace hud::common;
26
27
 
27
28
BamfWindow::BamfWindow(const QString &path, const QDBusConnection &connection) :
28
 
                m_window(BAMF_DBUS_NAME, path, connection), m_view(BAMF_DBUS_NAME, path,
29
 
                                connection), m_error(false), m_windowId(0) {
 
29
                m_window(DBusTypes::BAMF_DBUS_NAME, path, connection), m_view(
 
30
                                DBusTypes::BAMF_DBUS_NAME, path, connection), m_error(false), m_windowId(
 
31
                                0) {
30
32
 
31
33
        QDBusPendingReply<unsigned int> windowIdReply(m_window.GetXid());
32
34
        windowIdReply.waitForFinished();
52
54
        }
53
55
 
54
56
        if (!parents.empty()) {
55
 
                OrgAyatanaBamfApplicationInterface application(BAMF_DBUS_NAME,
56
 
                                parents.first(), m_window.connection());
 
57
                OrgAyatanaBamfApplicationInterface application(
 
58
                                DBusTypes::BAMF_DBUS_NAME, parents.first(),
 
59
                                m_window.connection());
57
60
                QDBusPendingReply<QString> desktopFileReply(application.DesktopFile());
58
61
                desktopFileReply.waitForFinished();
59
62
                if (desktopFileReply.isError()) {
60
 
                        qWarning() << _("Could not get desktop file for") << path;
 
63
                        qWarning() << _("Could not get desktop file for") << path
 
64
                                        << desktopFileReply.error();
61
65
                        m_error = true;
62
66
                        return;
63
67
                } else {
64
 
                        QFile desktopFile(desktopFileReply);
65
 
                        if (desktopFile.exists()) {
 
68
                        QString desktopFile(desktopFileReply);
 
69
                        if (!desktopFile.isEmpty()) {
66
70
                                m_applicationId = QFileInfo(desktopFile).baseName();
67
71
                        }
68
72
                }
119
123
 
120
124
BamfWindowStack::BamfWindowStack(const QDBusConnection &connection,
121
125
                QObject *parent) :
122
 
                AbstractWindowStack(connection, parent), m_matcher(BAMF_DBUS_NAME,
123
 
                                "/org/ayatana/bamf/matcher", connection) {
 
126
                AbstractWindowStack(connection, parent), m_matcher(
 
127
                                DBusTypes::BAMF_DBUS_NAME, DBusTypes::BAMF_MATCHER_DBUS_PATH,
 
128
                                connection) {
124
129
 
125
130
        QDBusConnectionInterface* interface = connection.interface();
126
 
        if (!interface->isServiceRegistered(BAMF_DBUS_NAME)) {
127
 
                QDBusReply<void> reply(interface->startService(BAMF_DBUS_NAME));
 
131
        if (!interface->isServiceRegistered(DBusTypes::BAMF_DBUS_NAME)) {
 
132
                QDBusReply<void> reply(
 
133
                                interface->startService(DBusTypes::BAMF_DBUS_NAME));
128
134
        }
129
135
 
130
136
        registerOnBus();
160
166
}
161
167
 
162
168
QString BamfWindowStack::GetAppIdFromPid(uint pid) {
 
169
        Q_UNUSED(pid);
163
170
        // FIXME Not implemented
164
171
        sendErrorReply(QDBusError::NotSupported,
165
172
                        "GetAppIdFromPid method not implemented");
166
173
        return QString();
167
174
}
168
175
 
169
 
QList<WindowInfo> BamfWindowStack::GetWindowStack() {
170
 
        QList<WindowInfo> results;
171
 
 
172
 
        QStringList stack(m_matcher.WindowStackForMonitor(-1));
 
176
WindowInfoList BamfWindowStack::GetWindowStack() {
 
177
        WindowInfoList results;
 
178
 
 
179
        QDBusPendingReply<QStringList> stackReply(
 
180
                        m_matcher.WindowStackForMonitor(-1));
 
181
        stackReply.waitForFinished();
 
182
        if (stackReply.isError()) {
 
183
                qWarning() << "Failed to get BAMF window stack" << stackReply.error();
 
184
                return results;
 
185
        }
 
186
 
 
187
        QStringList stack(stackReply);
173
188
        for (const QString &path : stack) {
174
 
                const auto window (m_windows[path]);
 
189
                const auto window(m_windows[path]);
175
190
                if (window) {
176
 
                        results << WindowInfo(window->windowId(),
177
 
                                              window->applicationId(),
178
 
                                              false);
 
191
                        results
 
192
                                        << WindowInfo(window->windowId(), window->applicationId(),
 
193
                                                        false);
179
194
                }
180
195
        }
181
196
 
182
 
        const auto window (m_windows[m_matcher.ActiveWindow()]);
 
197
        QDBusPendingReply<QString> activeWindowReply(m_matcher.ActiveWindow());
 
198
        activeWindowReply.waitForFinished();
 
199
        if (activeWindowReply.isError()) {
 
200
                qWarning() << "Failed to get BAMF active window"
 
201
                                << activeWindowReply.error();
 
202
                return results;
 
203
        }
 
204
 
 
205
        const auto window(m_windows[activeWindowReply]);
183
206
        if (window) {
184
207
                const uint windowId(window->windowId());
185
208
 
195
218
 
196
219
QStringList BamfWindowStack::GetWindowProperties(uint windowId,
197
220
                const QString &appId, const QStringList &names) {
 
221
        Q_UNUSED(appId);
198
222
        QStringList result;
199
223
        const auto window = m_windowsById[windowId];
200
224
 
215
239
 
216
240
void BamfWindowStack::ActiveWindowChanged(const QString &oldWindowPath,
217
241
                const QString &newWindowPath) {
 
242
        Q_UNUSED(oldWindowPath);
218
243
        if (!newWindowPath.isEmpty()) {
219
244
                const auto window(m_windows[newWindowPath]);
220
245
                if (window) {
221
 
                        FocusedWindowChanged(window->windowId(),
222
 
                                             window->applicationId(),
223
 
                                             WindowInfo::MAIN);
 
246
                        FocusedWindowChanged(window->windowId(), window->applicationId(),
 
247
                                        WindowInfo::MAIN);
224
248
                }
225
249
        }
226
250
}