~canonical-dx-team/unity/unity.fix-ql-losing-focus

« back to all changes in this revision

Viewing changes to services/panel-main.c

  • Committer: Neil Jagdish Patel
  • Date: 2010-11-11 18:51:08 UTC
  • mfrom: (572.1.58 unity-3.0)
  • Revision ID: neil.patel@canonical.com-20101111185108-71923a90txzvxbit
[merge] Unity 3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2010 Canonical Ltd
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License version 3 as
 
6
 * published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
 
17
 */
 
18
 
 
19
#include <glib.h>
 
20
#include <gio/gio.h>
 
21
#include <gtk/gtk.h>
 
22
 
 
23
#include "panel-service.h"
 
24
 
 
25
static GDBusNodeInfo *introspection_data = NULL;
 
26
 
 
27
/*
 
28
 * typedef struct {
 
29
 *   gchar *indicator_id
 
30
 *   gchar *entry_id;
 
31
 *   gchar *label;
 
32
 *   bool   label_sensitive;
 
33
 *   bool   label_visible;
 
34
 *   uint32 icon_hint;
 
35
 *   gchar *icon_data;
 
36
 *   bool   icon_sensitive;
 
37
 *   bool   icon_visible;
 
38
 *
 
39
 * } EntryInfo;
 
40
 */
 
41
 
 
42
static const gchar introspection_xml[] =
 
43
  "<node>"
 
44
  "  <interface name='com.canonical.Unity.Panel.Service'>"
 
45
  ""
 
46
  "    <method name='Sync'>"
 
47
  "      <arg type='a(sssbbusbb)' name='state' direction='out'/>"
 
48
  "    </method>"
 
49
  ""
 
50
  "    <method name='SyncOne'>"
 
51
  "      <arg type='s' name='indicator_id' direction='in'/>"
 
52
  "      <arg type='a(sssbbusbb)' name='state' direction='out'/>"
 
53
  "    </method>"
 
54
  ""
 
55
  "    <method name='ShowEntry'>"
 
56
  "      <arg type='s' name='entry_id' direction='in'/>"
 
57
  "      <arg type='u' name='timestamp' direction='in'/>"
 
58
  "      <arg type='i' name='x' direction='in'/>"
 
59
  "      <arg type='i' name='y' direction='in'/>"
 
60
  "      <arg type='i' name='button' direction='in'/>"
 
61
  "    </method>"
 
62
  ""
 
63
  "    <signal name='EntryActivated'>"
 
64
  "     <arg type='s' name='entry_id' />"
 
65
  "    </signal>"
 
66
  ""
 
67
  "    <signal name='ReSync'>"
 
68
  "     <arg type='s' name='indicator_id' />"
 
69
  "    </signal>"
 
70
  ""
 
71
  "    <signal name='ActiveMenuPointerMotion'>"
 
72
  "     <arg type='i' name='x' />"
 
73
  "     <arg type='i' name='y' />"
 
74
  "    </signal>"
 
75
  ""
 
76
  "  </interface>"
 
77
  "</node>";
 
78
 
 
79
#define S_NAME  "com.canonical.Unity.Panel.Service"
 
80
#define S_PATH  "/com/canonical/Unity/Panel/Service"
 
81
#define S_IFACE "com.canonical.Unity.Panel.Service"
 
82
 
 
83
/* Forwards */
 
84
static void
 
85
handle_method_call (GDBusConnection       *connection,
 
86
                    const gchar           *sender,
 
87
                    const gchar           *object_path,
 
88
                    const gchar           *interface_name,
 
89
                    const gchar           *method_name,
 
90
                    GVariant              *parameters,
 
91
                    GDBusMethodInvocation *invocation,
 
92
                    gpointer               user_data);
 
93
 
 
94
 
 
95
static const GDBusInterfaceVTable interface_vtable =
 
96
{
 
97
  handle_method_call,
 
98
  NULL,
 
99
  NULL
 
100
};
 
101
 
 
102
 
 
103
/* Methods */
 
104
 
 
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
  PanelService *service = PANEL_SERVICE (user_data);
 
116
 
 
117
  if (g_strcmp0 (method_name, "Sync") == 0)
 
118
    {
 
119
      g_dbus_method_invocation_return_value (invocation,
 
120
                                             panel_service_sync (service));
 
121
    }
 
122
  else if (g_strcmp0 (method_name, "SyncOne") == 0)
 
123
    {
 
124
      gchar *id;
 
125
      g_variant_get (parameters, "(s)", &id, NULL);
 
126
      g_dbus_method_invocation_return_value (invocation,
 
127
                                             panel_service_sync_one (service,
 
128
                                                                     id));
 
129
      g_free (id);
 
130
    }
 
131
  else if (g_strcmp0 (method_name, "ShowEntry") == 0)
 
132
    {
 
133
      gchar  *entry_id;
 
134
      guint32 timestamp;
 
135
      gint32  x;
 
136
      gint32  y;
 
137
      gint32  button;
 
138
      g_variant_get (parameters, "(suiii)", &entry_id, &timestamp, &x, &y, &button, NULL);
 
139
 
 
140
      g_debug ("button: %u", button);
 
141
 
 
142
      panel_service_show_entry (service, entry_id, timestamp, x, y, button);
 
143
 
 
144
      g_dbus_method_invocation_return_value (invocation, NULL);
 
145
      g_free (entry_id);
 
146
    }
 
147
}
 
148
 
 
149
static void
 
150
on_service_resync (PanelService *service, const gchar *indicator_id, GDBusConnection *connection)
 
151
{
 
152
  GError *error = NULL;
 
153
  g_dbus_connection_emit_signal (connection,
 
154
                                 S_NAME,
 
155
                                 S_PATH,
 
156
                                 S_IFACE,
 
157
                                 "ReSync",
 
158
                                 g_variant_new ("(s)", indicator_id),
 
159
                                 &error);
 
160
 
 
161
  if (error)
 
162
    {
 
163
      g_warning ("Unable to emit ReSync signal: %s", error->message);
 
164
      g_error_free (error);
 
165
    }
 
166
}
 
167
 
 
168
static void
 
169
on_service_entry_activated (PanelService    *service,
 
170
                            const gchar     *entry_id,
 
171
                            GDBusConnection *connection)
 
172
{
 
173
  GError *error = NULL;
 
174
  g_dbus_connection_emit_signal (connection,
 
175
                                 S_NAME,
 
176
                                 S_PATH,
 
177
                                 S_IFACE,
 
178
                                 "EntryActivated",
 
179
                                 g_variant_new ("(s)", entry_id),
 
180
                                 &error);
 
181
 
 
182
  if (error)
 
183
    {
 
184
      g_warning ("Unable to emit EntryActivated signal: %s", error->message);
 
185
      g_error_free (error);
 
186
    }
 
187
}
 
188
 
 
189
static void
 
190
on_service_active_menu_pointer_motion (PanelService    *service,
 
191
                                       GDBusConnection *connection)
 
192
{
 
193
  GError *error = NULL;
 
194
  gint    x=0, y=0;
 
195
 
 
196
  panel_service_get_last_xy (service, &x, &y);
 
197
 
 
198
  g_dbus_connection_emit_signal (connection,
 
199
                                 S_NAME,
 
200
                                 S_PATH,
 
201
                                 S_IFACE,
 
202
                                 "ActiveMenuPointerMotion",
 
203
                                 g_variant_new ("(ii)", x, y),
 
204
                                 &error);
 
205
 
 
206
  if (error)
 
207
    {
 
208
      g_warning ("Unable to emit ActiveMenuPointerMotionsignal: %s", error->message);
 
209
      g_error_free (error);
 
210
    }
 
211
}
 
212
 
 
213
static void
 
214
on_bus_acquired (GDBusConnection *connection,
 
215
                 const gchar     *name,
 
216
                 gpointer         user_data)
 
217
{
 
218
  PanelService *service = PANEL_SERVICE (user_data);
 
219
  guint         reg_id;
 
220
 
 
221
  reg_id = g_dbus_connection_register_object (connection,
 
222
                                              S_PATH,
 
223
                                              introspection_data->interfaces[0],
 
224
                                              &interface_vtable,
 
225
                                              service,
 
226
                                              NULL,
 
227
                                              NULL);
 
228
  g_signal_connect (service, "re-sync",
 
229
                    G_CALLBACK (on_service_resync), connection);
 
230
  g_signal_connect (service, "entry-activated",
 
231
                    G_CALLBACK (on_service_entry_activated), connection);
 
232
  g_signal_connect (service, "active-menu-pointer-motion",
 
233
                    G_CALLBACK (on_service_active_menu_pointer_motion), connection);
 
234
 
 
235
  g_debug ("%s", G_STRFUNC);
 
236
  g_assert (reg_id > 0);
 
237
}
 
238
 
 
239
static void
 
240
on_name_acquired (GDBusConnection *connection,
 
241
                  const gchar     *name,
 
242
                  gpointer         user_data)
 
243
{
 
244
  g_debug ("Name Acquired");
 
245
}
 
246
 
 
247
static void
 
248
on_name_lost (GDBusConnection *connection,
 
249
              const gchar     *name,
 
250
              gpointer         user_data)
 
251
{
 
252
  g_debug ("%s", G_STRFUNC);
 
253
  gtk_main_quit ();
 
254
}
 
255
 
 
256
gint
 
257
main (gint argc, gchar **argv)
 
258
{
 
259
  PanelService *service;
 
260
  guint         owner_id;
 
261
 
 
262
  gtk_init (&argc, &argv);
 
263
        gtk_icon_theme_append_search_path (gtk_icon_theme_get_default(),
 
264
                                           INDICATORICONDIR);
 
265
 
 
266
  introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
 
267
  g_assert (introspection_data != NULL);
 
268
 
 
269
  service = panel_service_get_default ();
 
270
  
 
271
  owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
 
272
                             S_NAME,
 
273
                             G_BUS_NAME_OWNER_FLAGS_NONE,
 
274
                             on_bus_acquired,
 
275
                             on_name_acquired,
 
276
                             on_name_lost,
 
277
                             service,
 
278
                             NULL);
 
279
  gtk_main ();
 
280
 
 
281
  g_bus_unown_name (owner_id);
 
282
  g_dbus_node_info_unref (introspection_data);
 
283
  g_object_unref (service);
 
284
 
 
285
  return 0;
 
286
}