~mial/ubuntu/oneiric/unity/bug-791810

« back to all changes in this revision

Viewing changes to services/panel-main.c

Import the work done so far with Compiz

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- Mode: C; tab-width:2; indent-tabs-mode: t; c-basic-offset: 2 -*-
2
 
/*
3
 
 * Copyright (C) 2010 Canonical Ltd
4
 
 *
5
 
 * This program is free software: you can redistribute it and/or modify
6
 
 * it under the terms of the GNU General Public License version 3 as
7
 
 * published by the Free Software Foundation.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 * GNU General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU General Public License
15
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 
 *
17
 
 * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
18
 
 *              Rodrigo Moya <rodrigo.moya@canonical.com>
19
 
 */
20
 
 
21
 
#include <glib.h>
22
 
#include <gio/gio.h>
23
 
#include <gtk/gtk.h>
24
 
 
25
 
#include "panel-a11y.h"
26
 
#include "panel-service.h"
27
 
 
28
 
static GDBusNodeInfo *introspection_data = NULL;
29
 
 
30
 
/*
31
 
 * typedef struct {
32
 
 *   gchar *indicator_id
33
 
 *   gchar *entry_id;
34
 
 *   gchar *label;
35
 
 *   bool   label_sensitive;
36
 
 *   bool   label_visible;
37
 
 *   uint32 icon_hint;
38
 
 *   gchar *icon_data;
39
 
 *   bool   icon_sensitive;
40
 
 *   bool   icon_visible;
41
 
 *
42
 
 * } EntryInfo;
43
 
 */
44
 
 
45
 
static const gchar introspection_xml[] =
46
 
  "<node>"
47
 
  "  <interface name='com.canonical.Unity.Panel.Service'>"
48
 
  ""
49
 
  "    <method name='Sync'>"
50
 
  "      <arg type='a(ssssbbusbbi)' name='state' direction='out'/>"
51
 
  "    </method>"
52
 
  ""
53
 
  "    <method name='SyncOne'>"
54
 
  "      <arg type='s' name='indicator_id' direction='in'/>"
55
 
  "      <arg type='a(ssssbbusbbi)' name='state' direction='out'/>"
56
 
  "    </method>"
57
 
  ""
58
 
  "    <method name='SyncGeometries'>"
59
 
  "      <arg type='a(ssiiii)' name='geometries' direction='in'/>"
60
 
  "    </method>"
61
 
        ""
62
 
  "    <method name='ShowEntry'>"
63
 
  "      <arg type='s' name='entry_id' direction='in'/>"
64
 
  "      <arg type='u' name='timestamp' direction='in'/>"
65
 
  "      <arg type='i' name='x' direction='in'/>"
66
 
  "      <arg type='i' name='y' direction='in'/>"
67
 
  "      <arg type='i' name='button' direction='in'/>"
68
 
  "    </method>"
69
 
  ""
70
 
  "    <method name='SecondaryActivateEntry'>"
71
 
  "      <arg type='s' name='entry_id' direction='in'/>"
72
 
  "      <arg type='u' name='timestamp' direction='in'/>"
73
 
  "    </method>"
74
 
  ""
75
 
  "    <method name='ScrollEntry'>"
76
 
  "      <arg type='s' name='entry_id' direction='in'/>"
77
 
  "      <arg type='i' name='delta' direction='in'/>"
78
 
  "    </method>"
79
 
  ""
80
 
  "    <signal name='EntryActivated'>"
81
 
  "     <arg type='s' name='entry_id' />"
82
 
  "    </signal>"
83
 
  ""
84
 
  "    <signal name='ReSync'>"
85
 
  "     <arg type='s' name='indicator_id' />"
86
 
  "    </signal>"
87
 
  ""
88
 
  "    <signal name='EntryActivateRequest'>"
89
 
  "     <arg type='s' name='entry_id' />"
90
 
  "    </signal>"
91
 
  ""
92
 
  "    <signal name='EntryShowNowChanged'>"
93
 
  "     <arg type='s' name='entry_id' />"
94
 
  "     <arg type='b' name='show_now_state' />"
95
 
  "    </signal>"
96
 
  ""
97
 
  "  </interface>"
98
 
  "</node>";
99
 
 
100
 
#define S_NAME  "com.canonical.Unity.Panel.Service"
101
 
#define S_PATH  "/com/canonical/Unity/Panel/Service"
102
 
#define S_IFACE "com.canonical.Unity.Panel.Service"
103
 
 
104
 
/* Forwards */
105
 
static void
106
 
handle_method_call (GDBusConnection       *connection,
107
 
                    const gchar           *sender,
108
 
                    const gchar           *object_path,
109
 
                    const gchar           *interface_name,
110
 
                    const gchar           *method_name,
111
 
                    GVariant              *parameters,
112
 
                    GDBusMethodInvocation *invocation,
113
 
                    gpointer               user_data);
114
 
 
115
 
 
116
 
static const GDBusInterfaceVTable interface_vtable =
117
 
{
118
 
  handle_method_call,
119
 
  NULL,
120
 
  NULL
121
 
};
122
 
 
123
 
 
124
 
/* Methods */
125
 
 
126
 
static void
127
 
handle_method_call (GDBusConnection       *connection,
128
 
                    const gchar           *sender,
129
 
                    const gchar           *object_path,
130
 
                    const gchar           *interface_name,
131
 
                    const gchar           *method_name,
132
 
                    GVariant              *parameters,
133
 
                    GDBusMethodInvocation *invocation,
134
 
                    gpointer               user_data)
135
 
{
136
 
  PanelService *service = PANEL_SERVICE (user_data);
137
 
 
138
 
  if (g_strcmp0 (method_name, "Sync") == 0)
139
 
    {
140
 
      g_dbus_method_invocation_return_value (invocation,
141
 
                                             panel_service_sync (service));
142
 
    }
143
 
  else if (g_strcmp0 (method_name, "SyncOne") == 0)
144
 
    {
145
 
      gchar *id;
146
 
      g_variant_get (parameters, "(s)", &id, NULL);
147
 
      g_dbus_method_invocation_return_value (invocation,
148
 
                                             panel_service_sync_one (service,
149
 
                                                                     id));
150
 
      g_free (id);
151
 
    }
152
 
  else if (g_strcmp0 (method_name, "SyncGeometries") == 0)
153
 
    {
154
 
      GVariantIter *iter;
155
 
      gchar *indicator_id, *entry_id;
156
 
      gint x, y, width, height;
157
 
 
158
 
      g_variant_get (parameters, "(a(ssiiii))", &iter);
159
 
      while (iter && g_variant_iter_loop (iter, "(ssiiii)",
160
 
                                  &indicator_id,
161
 
                                  &entry_id,
162
 
                                  &x,
163
 
                                  &y,
164
 
                                  &width,
165
 
                                  &height))
166
 
        {
167
 
          panel_service_sync_geometry (service, indicator_id,
168
 
                                       entry_id, x, y, width, height);
169
 
        }
170
 
 
171
 
      if (iter) g_variant_iter_free (iter);
172
 
 
173
 
      g_dbus_method_invocation_return_value (invocation, NULL);
174
 
    }
175
 
  else if (g_strcmp0 (method_name, "ShowEntry") == 0)
176
 
    {
177
 
      gchar  *entry_id;
178
 
      guint32 timestamp;
179
 
      gint32  x;
180
 
      gint32  y;
181
 
      gint32  button;
182
 
      g_variant_get (parameters, "(suiii)", &entry_id, &timestamp, &x, &y, &button, NULL);
183
 
 
184
 
      panel_service_show_entry (service, entry_id, timestamp, x, y, button);
185
 
 
186
 
      g_dbus_method_invocation_return_value (invocation, NULL);
187
 
      g_free (entry_id);
188
 
    }
189
 
  else if (g_strcmp0 (method_name, "SecondaryActivateEntry") == 0)
190
 
    {
191
 
      gchar  *entry_id;
192
 
      guint32 timestamp;
193
 
      g_variant_get (parameters, "(su)", &entry_id, &timestamp, NULL);
194
 
 
195
 
      panel_service_secondary_activate_entry (service, entry_id, timestamp);
196
 
 
197
 
      g_dbus_method_invocation_return_value (invocation, NULL);
198
 
      g_free (entry_id);
199
 
    }
200
 
  else if (g_strcmp0 (method_name, "ScrollEntry") == 0)
201
 
    {
202
 
      gchar *entry_id;
203
 
      gint32 delta;
204
 
      g_variant_get (parameters, "(si)", &entry_id, &delta, NULL);
205
 
      panel_service_scroll_entry (service, entry_id, delta);
206
 
      g_dbus_method_invocation_return_value (invocation, NULL);
207
 
      g_free(entry_id);
208
 
    }
209
 
}
210
 
 
211
 
static void
212
 
on_service_resync (PanelService *service, const gchar *indicator_id, GDBusConnection *connection)
213
 
{
214
 
  GError *error = NULL;
215
 
  g_dbus_connection_emit_signal (connection,
216
 
                                 S_NAME,
217
 
                                 S_PATH,
218
 
                                 S_IFACE,
219
 
                                 "ReSync",
220
 
                                 g_variant_new ("(s)", indicator_id),
221
 
                                 &error);
222
 
  if (error)
223
 
    {
224
 
      g_warning ("Unable to emit ReSync signal: %s", error->message);
225
 
      g_error_free (error);
226
 
    }
227
 
}
228
 
 
229
 
static void
230
 
on_service_entry_activated (PanelService    *service,
231
 
                            const gchar     *entry_id,
232
 
                            GDBusConnection *connection)
233
 
{
234
 
  GError *error = NULL;
235
 
  g_dbus_connection_emit_signal (connection,
236
 
                                 S_NAME,
237
 
                                 S_PATH,
238
 
                                 S_IFACE,
239
 
                                 "EntryActivated",
240
 
                                 g_variant_new ("(s)", entry_id),
241
 
                                 &error);
242
 
 
243
 
  if (error)
244
 
    {
245
 
      g_warning ("Unable to emit EntryActivated signal: %s", error->message);
246
 
      g_error_free (error);
247
 
    }
248
 
}
249
 
 
250
 
static void
251
 
on_service_entry_activate_request (PanelService    *service,
252
 
                                   const gchar     *entry_id,
253
 
                                   GDBusConnection *connection)
254
 
{
255
 
  GError *error = NULL;
256
 
  g_dbus_connection_emit_signal (connection,
257
 
                                 S_NAME,
258
 
                                 S_PATH,
259
 
                                 S_IFACE,
260
 
                                 "EntryActivateRequest",
261
 
                                 g_variant_new ("(s)", entry_id),
262
 
                                 &error);
263
 
 
264
 
  if (error)
265
 
    {
266
 
      g_warning ("Unable to emit EntryActivateRequest signal: %s", error->message);
267
 
      g_error_free (error);
268
 
    }
269
 
}
270
 
 
271
 
static void
272
 
on_service_entry_show_now_changed (PanelService    *service,
273
 
                                   const gchar     *entry_id,
274
 
                                   gboolean         show_now_state,
275
 
                                   GDBusConnection *connection)
276
 
{
277
 
  GError *error = NULL;
278
 
  g_dbus_connection_emit_signal (connection,
279
 
                                 S_NAME,
280
 
                                 S_PATH,
281
 
                                 S_IFACE,
282
 
                                 "EntryShowNowChanged",
283
 
                                 g_variant_new ("(sb)", entry_id, show_now_state),
284
 
                                 &error);
285
 
 
286
 
  if (error)
287
 
    {
288
 
      g_warning ("Unable to emit EntryShowNowChanged signal: %s", error->message);
289
 
      g_error_free (error);
290
 
    }
291
 
}
292
 
 
293
 
static void
294
 
on_bus_acquired (GDBusConnection *connection,
295
 
                 const gchar     *name,
296
 
                 gpointer         user_data)
297
 
{
298
 
  PanelService *service = PANEL_SERVICE (user_data);
299
 
  guint         reg_id;
300
 
 
301
 
  reg_id = g_dbus_connection_register_object (connection,
302
 
                                              S_PATH,
303
 
                                              introspection_data->interfaces[0],
304
 
                                              &interface_vtable,
305
 
                                              service,
306
 
                                              NULL,
307
 
                                              NULL);
308
 
  g_signal_connect (service, "re-sync",
309
 
                    G_CALLBACK (on_service_resync), connection);
310
 
  g_signal_connect (service, "entry-activated",
311
 
                    G_CALLBACK (on_service_entry_activated), connection);
312
 
  g_signal_connect (service, "entry-activate-request",
313
 
                    G_CALLBACK (on_service_entry_activate_request), connection);
314
 
  g_signal_connect (service, "entry-show-now-changed",
315
 
                    G_CALLBACK (on_service_entry_show_now_changed), connection);
316
 
 
317
 
  g_debug ("%s", G_STRFUNC);
318
 
  g_assert (reg_id > 0);
319
 
}
320
 
 
321
 
static void
322
 
on_name_acquired (GDBusConnection *connection,
323
 
                  const gchar     *name,
324
 
                  gpointer         user_data)
325
 
{
326
 
  g_debug ("Name Acquired");
327
 
}
328
 
 
329
 
static void
330
 
on_name_lost (GDBusConnection *connection,
331
 
              const gchar     *name,
332
 
              gpointer         user_data)
333
 
{
334
 
  PanelService *service = PANEL_SERVICE (user_data);
335
 
                
336
 
  g_debug ("%s", G_STRFUNC);
337
 
  if (service != NULL)
338
 
  {
339
 
    g_signal_handlers_disconnect_by_func (service, on_service_resync, connection);
340
 
    g_signal_handlers_disconnect_by_func (service, on_service_entry_activated, connection);
341
 
    g_signal_handlers_disconnect_by_func (service, on_service_entry_activate_request, connection);
342
 
    g_signal_handlers_disconnect_by_func (service, on_service_entry_show_now_changed, connection);
343
 
  }
344
 
  gtk_main_quit ();
345
 
}
346
 
 
347
 
static void
348
 
on_indicators_cleared (PanelService *service)
349
 
{
350
 
  gtk_main_quit ();
351
 
}
352
 
 
353
 
static void
354
 
on_signal (int sig)
355
 
{
356
 
  PanelService *service = panel_service_get_default ();
357
 
  panel_service_clear_indicators (service);
358
 
  g_signal_connect (service, "indicators-cleared",
359
 
                    G_CALLBACK (on_indicators_cleared), NULL);
360
 
}
361
 
 
362
 
gint
363
 
main (gint argc, gchar **argv)
364
 
{
365
 
  PanelService *service;
366
 
  guint         owner_id;
367
 
 
368
 
  g_unsetenv("UBUNTU_MENUPROXY");
369
 
  g_setenv ("NO_AT_BRIDGE", "1", TRUE);
370
 
  g_unsetenv ("NO_GAIL");
371
 
 
372
 
  gtk_init (&argc, &argv);
373
 
  gtk_icon_theme_append_search_path (gtk_icon_theme_get_default(),
374
 
                                     INDICATORICONDIR);
375
 
 
376
 
  introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
377
 
  g_assert (introspection_data != NULL);
378
 
 
379
 
  panel_a11y_init ();
380
 
 
381
 
  service = panel_service_get_default ();
382
 
 
383
 
  owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
384
 
                             S_NAME,
385
 
                             G_BUS_NAME_OWNER_FLAGS_NONE,
386
 
                             on_bus_acquired,
387
 
                             on_name_acquired,
388
 
                             on_name_lost,
389
 
                             service,
390
 
                             NULL);
391
 
 
392
 
  signal (SIGINT, on_signal);
393
 
  signal (SIGTERM, on_signal);
394
 
 
395
 
  gtk_main ();
396
 
 
397
 
  g_bus_unown_name (owner_id);
398
 
  g_dbus_node_info_unref (introspection_data);
399
 
  g_object_unref (service);
400
 
 
401
 
  return 0;
402
 
}