File: bamf-tab.c

package info (click to toggle)
bamf 0.5.3-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,732 kB
  • sloc: ansic: 14,574; sh: 4,238; makefile: 423; xml: 249; python: 46
file content (269 lines) | stat: -rw-r--r-- 7,269 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/*
 * Copyright (C) 2012 Canonical Ltd
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authored by:
 *              Robert Carr <racarr@canonical.com>
 *
 */
/**
 * SECTION:bamf-tab
 * @short_description: The base class for browser tabs
 *
 * #BamfTab is the base class that all tabs need to derive from.
 */

#include "bamf-tab.h"

#define BAMF_TAB_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE(obj, \
BAMF_TYPE_TAB, BamfTabPrivate))

static void bamf_tab_dbus_iface_init (BamfDBusItemTabIface *iface);
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (BamfTab, bamf_tab, BAMF_TYPE_VIEW,
                                  G_IMPLEMENT_INTERFACE (BAMF_DBUS_ITEM_TYPE_TAB,
                                                         bamf_tab_dbus_iface_init));

enum
{
  PROP_0,
  PROP_LOCATION,
  PROP_XID,
  PROP_DESKTOP_ID,
  PROP_IS_FOREGROUND_TAB
};

struct _BamfTabPrivate
{
  BamfDBusItemTab *dbus_iface;
};

static const gchar *
bamf_tab_get_view_type (BamfView *view)
{
  return "tab";
}

static char *
bamf_tab_get_stable_bus_name (BamfView *view)
{
  return g_strdup_printf ("tab/%u", GPOINTER_TO_UINT (view));
}

static void
bamf_tab_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
  BamfTab *self;

  self = BAMF_TAB (object);

  switch (property_id)
    {
    case PROP_LOCATION:
      g_value_set_string (value, bamf_tab_get_location (self));
      break;
    case PROP_XID:
      g_value_set_uint64  (value, bamf_tab_get_xid (self));
      break;
    case PROP_DESKTOP_ID:
      g_value_set_string (value, bamf_tab_get_desktop_id (self));
      break;
    case PROP_IS_FOREGROUND_TAB:
      g_value_set_boolean (value, bamf_tab_get_is_foreground_tab (self));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    }
}

static void
bamf_tab_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
  BamfTab *self;

  self = BAMF_TAB (object);

  switch (property_id)
    {
    case PROP_LOCATION:
      _bamf_dbus_item_tab_set_location (self->priv->dbus_iface, g_value_get_string (value));
      break;
    case PROP_DESKTOP_ID:
      _bamf_dbus_item_tab_set_desktop_id (self->priv->dbus_iface, g_value_get_string (value));
      break;
    case PROP_XID:
      _bamf_dbus_item_tab_set_xid (self->priv->dbus_iface, g_value_get_uint64 (value));
      break;
    case PROP_IS_FOREGROUND_TAB:
      _bamf_dbus_item_tab_set_is_foreground_tab (self->priv->dbus_iface, g_value_get_boolean (value));
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
    }
}

static void
bamf_tab_finalize (GObject *object)
{
  BamfTab *self = BAMF_TAB (object);

  g_object_unref (self->priv->dbus_iface);

  G_OBJECT_CLASS (bamf_tab_parent_class)->finalize (object);
}


static gboolean
on_dbus_handle_raise (BamfDBusItemView *interface,
                      GDBusMethodInvocation *invocation,
                      BamfTab *self)
{
  g_dbus_method_invocation_return_value (invocation, NULL);
  bamf_tab_raise (self);

  return TRUE;
}

static gboolean
on_dbus_handle_close (BamfDBusItemView *interface,
                      GDBusMethodInvocation *invocation,
                      BamfTab *self)
{
  g_dbus_method_invocation_return_value (invocation, NULL);
  bamf_tab_close (self);

  return TRUE;
}

static void
bamf_tab_preview_ready (BamfTab *self,
                        const gchar *preview_data,
                        gpointer user_data)
{
  GDBusMethodInvocation *invocation;

  invocation = (GDBusMethodInvocation *)user_data;

  g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", preview_data));
}

static gboolean
on_dbus_handle_request_preview (BamfDBusItemView *interface,
                                GDBusMethodInvocation *invocation,
                                BamfTab *self)
{
  bamf_tab_request_preview (self, bamf_tab_preview_ready, invocation);

  return TRUE;
}

static void
bamf_tab_init (BamfTab *self)
{
  self->priv = BAMF_TAB_GET_PRIVATE (self);

  self->priv->dbus_iface = _bamf_dbus_item_tab_skeleton_new ();

  g_signal_connect (self->priv->dbus_iface, "handle-raise",
                    G_CALLBACK (on_dbus_handle_raise), self);
  g_signal_connect (self->priv->dbus_iface, "handle-close",
                    G_CALLBACK (on_dbus_handle_close), self);
  g_signal_connect (self->priv->dbus_iface, "handle-request-preview",
                    G_CALLBACK (on_dbus_handle_request_preview), self);

  _bamf_dbus_item_object_skeleton_set_tab (BAMF_DBUS_ITEM_OBJECT_SKELETON (self),
                                           self->priv->dbus_iface);
}


static void
bamf_tab_dbus_iface_init (BamfDBusItemTabIface *iface)
{
}

static void
bamf_tab_class_init (BamfTabClass * klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  BamfViewClass *view_class = BAMF_VIEW_CLASS (klass);

  object_class->get_property = bamf_tab_get_property;
  object_class->set_property = bamf_tab_set_property;
  object_class->finalize = bamf_tab_finalize;
  view_class->view_type = bamf_tab_get_view_type;
  view_class->stable_bus_name = bamf_tab_get_stable_bus_name;

  g_object_class_override_property (object_class, PROP_LOCATION, "location");
  g_object_class_override_property (object_class, PROP_DESKTOP_ID, "desktop-id");
  g_object_class_override_property (object_class, PROP_XID, "xid");
  g_object_class_override_property (object_class, PROP_IS_FOREGROUND_TAB, "is-foreground-tab");

  g_type_class_add_private (klass, sizeof (BamfTabPrivate));
}


const gchar *
bamf_tab_get_location (BamfTab *self)
{
  g_return_val_if_fail (BAMF_IS_TAB (self), NULL);

  return _bamf_dbus_item_tab_get_location (self->priv->dbus_iface);
}

const gchar *
bamf_tab_get_desktop_id (BamfTab *self)
{
  g_return_val_if_fail (BAMF_IS_TAB (self), NULL);

  return _bamf_dbus_item_tab_get_desktop_id (self->priv->dbus_iface);
}

guint64
bamf_tab_get_xid (BamfTab *self)
{
  g_return_val_if_fail (BAMF_IS_TAB (self), 0);

  return _bamf_dbus_item_tab_get_xid (self->priv->dbus_iface);
}

gboolean
bamf_tab_get_is_foreground_tab (BamfTab *self)
{
  g_return_val_if_fail (BAMF_IS_TAB (self), 0);

  return _bamf_dbus_item_tab_get_is_foreground_tab (self->priv->dbus_iface);
}

void
bamf_tab_raise (BamfTab *self)
{
  g_return_if_fail (BAMF_IS_TAB (self));

  BAMF_TAB_GET_CLASS (self)->raise (self);
}

void
bamf_tab_close (BamfTab *self)
{
  g_return_if_fail (BAMF_IS_TAB (self));

  BAMF_TAB_GET_CLASS (self)->close (self);
}

void
bamf_tab_request_preview (BamfTab *self, BamfTabPreviewReadyCallback callback, gpointer user_data)
{
  g_return_if_fail (BAMF_IS_TAB (self));

  BAMF_TAB_GET_CLASS (self)->request_preview (self, callback, user_data);
}