~ubuntu-branches/ubuntu/maverick/ekiga/maverick

« back to all changes in this revision

Viewing changes to lib/gui/gmwindow.c

  • Committer: Bazaar Package Importer
  • Author(s): Eugen Dedu, Eugen Dedu, Loic Minier
  • Date: 2008-09-27 10:00:00 UTC
  • mfrom: (1.1.8 upstream)
  • mto: (1.4.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 38.
  • Revision ID: james.westby@ubuntu.com-20080927100000-l5k5werb6czr5b3h
Tags: 3.0.1-1
[ Eugen Dedu ]
* New version.  (Closes: #500089).
* Add our own changelog file in /usr/share/doc.
* Remove gnomemeeting transitional package.
* Discover new interfaces.  (Closes: #488199).
* Compile with dbus support.  (Closes: #467212).
* Numeric keypad inserts digits at correct position.  (Closes: #440159).
* Use libnotify upon call.  (Closes: #412604).
* Symlink identical GNOME help files, to reduce size.  (Closes: #505536).
* Explicitely build-depends on a few dev packages, even if they were
  pulled out anyway by the other dependencies.

[ Loic Minier ]
* Use clean:: instead of clean: in rules.
* Don't disable Uploaders: generation for control.in -> control generation
  in rules.
* Fix some tabs which were size 4 anyway.
* Generate a PO template during build by calling intltool-update -p in
  install; thanks Ubuntu and Martin Pitt; closes: #505535.
* Also let the -dbg depend on ${misc:Depends}.
* Cleanup rules; in particular, use dpkg-parsechangelog and honor
  distclean/clean failures, remove old clean rules, commented out stuff,
  gtk-only stuff.
* Pass -s to dh_* in binary-arch.
* Use debian/*.links and debian/*.manpages instead of symlink manually or
  passing files to dh_installman.
* Use ftp.gnome.org in copyright.
* Switch to quilt and fix target deps in the process; build-dep on quilt
  instead of dpatch; rename news.dpatch to 00_news.patch and refresh;
  replace 00list with series.
* Install autotools-dev config.guess and .sub after patching.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/* Ekiga -- A VoIP and Video-Conferencing application
 
3
 * Copyright (C) 2000-2006 Damien Sandras
 
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 as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software Foundation,
 
17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 
18
 *
 
19
 *
 
20
 * Ekiga is licensed under the GPL license and as a special exception,
 
21
 * you have permission to link or otherwise combine this program with the
 
22
 * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
 
23
 * without applying the requirements of the GNU GPL to the OPAL, OpenH323
 
24
 * and PWLIB programs, as long as you do follow the requirements of the
 
25
 * GNU GPL for all the rest of the software thus combined.
 
26
 */
 
27
 
 
28
 
 
29
/*
 
30
 *                         gmwindow.c -  description
 
31
 *                         -------------------------
 
32
 *   begin                : 16 August 2007 
 
33
 *   copyright            : (c) 2007 by Damien Sandras 
 
34
 *   description          : Implementation of a GtkWindow able to restore
 
35
 *                          its position and size in a GmConf key.
 
36
 *
 
37
 */
 
38
 
 
39
#include "gmwindow.h"
 
40
 
 
41
#include "gmconf.h"
 
42
 
 
43
#include <gdk/gdkkeysyms.h>
 
44
#include <string.h>
 
45
#include <stdlib.h>
 
46
 
 
47
 
 
48
/*
 
49
 * The GmWindow
 
50
 */
 
51
struct _GmWindowPrivate
 
52
{
 
53
  GtkAccelGroup *accel;
 
54
  gboolean hide_on_esc;
 
55
  gboolean hide_on_delete;
 
56
  const gchar *key;
 
57
  int x;
 
58
  int y;
 
59
  int width;
 
60
  int height;
 
61
};
 
62
 
 
63
enum {
 
64
  GM_WINDOW_KEY = 1,
 
65
  GM_HIDE_ON_ESC = 2,
 
66
  GM_HIDE_ON_DELETE = 3
 
67
};
 
68
 
 
69
static GObjectClass *parent_class = NULL;
 
70
 
 
71
static gboolean
 
72
gm_window_delete_event (GtkWidget *w,
 
73
                        gpointer data);
 
74
 
 
75
static void
 
76
gm_window_show (GtkWidget *w,
 
77
                gpointer data);
 
78
 
 
79
static void
 
80
gm_window_hide (GtkWidget *w,
 
81
                gpointer data);
 
82
 
 
83
static gboolean 
 
84
gm_window_configure_event (GtkWidget *widget,
 
85
                           GdkEventConfigure *event);
 
86
 
 
87
 
 
88
/* 
 
89
 * GObject stuff
 
90
 */
 
91
static void
 
92
gm_window_dispose (GObject *obj)
 
93
{
 
94
  GmWindow *window = NULL;
 
95
 
 
96
  window = GM_WINDOW (obj);
 
97
 
 
98
  parent_class->dispose (obj);
 
99
}
 
100
 
 
101
 
 
102
static void
 
103
gm_window_finalize (GObject *obj)
 
104
{
 
105
  GmWindow *window = NULL;
 
106
 
 
107
  window = GM_WINDOW (obj);
 
108
 
 
109
  g_free ((gchar *) window->priv->key);
 
110
 
 
111
  parent_class->finalize (obj);
 
112
}
 
113
 
 
114
 
 
115
static void
 
116
gm_window_get_property (GObject *obj,
 
117
                        guint prop_id,
 
118
                        GValue *value,
 
119
                        GParamSpec *spec)
 
120
{
 
121
  GmWindow *self = NULL;
 
122
 
 
123
  self = GM_WINDOW (obj);
 
124
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GM_WINDOW_TYPE, GmWindowPrivate);
 
125
 
 
126
  switch (prop_id) {
 
127
 
 
128
  case GM_WINDOW_KEY:
 
129
    g_value_set_string (value, self->priv->key);
 
130
    break;
 
131
 
 
132
  case GM_HIDE_ON_ESC:
 
133
    g_value_set_boolean (value, self->priv->hide_on_esc);
 
134
    break;
 
135
 
 
136
  case GM_HIDE_ON_DELETE:
 
137
    g_value_set_boolean (value, self->priv->hide_on_delete);
 
138
    break;
 
139
 
 
140
  default:
 
141
    G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, spec);
 
142
    break;
 
143
  }
 
144
}
 
145
 
 
146
 
 
147
static void
 
148
gm_window_set_property (GObject *obj,
 
149
                        guint prop_id,
 
150
                        const GValue *value,
 
151
                        GParamSpec *spec)
 
152
{
 
153
  GmWindow *self = NULL;
 
154
  const gchar *str = NULL;
 
155
 
 
156
  self = GM_WINDOW (obj);
 
157
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GM_WINDOW_TYPE, GmWindowPrivate);
 
158
 
 
159
  switch (prop_id) {
 
160
 
 
161
  case GM_WINDOW_KEY:
 
162
    g_free ((gchar *) self->priv->key);
 
163
    str = g_value_get_string (value);
 
164
    self->priv->key = g_strdup (str ? str : "");
 
165
    break;
 
166
 
 
167
  case GM_HIDE_ON_ESC:
 
168
    self->priv->hide_on_esc = g_value_get_boolean (value);
 
169
    if (!self->priv->hide_on_esc)
 
170
      gtk_accel_group_disconnect_key (self->priv->accel, GDK_Escape, (GdkModifierType) 0);
 
171
    else
 
172
      gtk_accel_group_connect (self->priv->accel, GDK_Escape, (GdkModifierType) 0, GTK_ACCEL_LOCKED,
 
173
                               g_cclosure_new_swap (G_CALLBACK (gtk_widget_hide), (gpointer) self, NULL));
 
174
    break;
 
175
 
 
176
  case GM_HIDE_ON_DELETE:
 
177
    self->priv->hide_on_delete = g_value_get_boolean (value);
 
178
    break;
 
179
 
 
180
  default:
 
181
    G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, spec);
 
182
    break;
 
183
  }
 
184
}
 
185
 
 
186
 
 
187
static void
 
188
gm_window_class_init (gpointer g_class,
 
189
                      G_GNUC_UNUSED gpointer class_data)
 
190
{
 
191
  GObjectClass *gobject_class = NULL;
 
192
  GParamSpec *spec = NULL;
 
193
 
 
194
  parent_class = (GObjectClass *) g_type_class_peek_parent (g_class);
 
195
  g_type_class_add_private (g_class, sizeof (GmWindowPrivate));
 
196
 
 
197
  gobject_class = (GObjectClass *) g_class;
 
198
  gobject_class->dispose = gm_window_dispose;
 
199
  gobject_class->finalize = gm_window_finalize;
 
200
  gobject_class->get_property = gm_window_get_property;
 
201
  gobject_class->set_property = gm_window_set_property;
 
202
 
 
203
  spec = g_param_spec_string ("key", "Key", "Key", 
 
204
                              NULL, (GParamFlags) G_PARAM_READWRITE);
 
205
  g_object_class_install_property (gobject_class, GM_WINDOW_KEY, spec); 
 
206
 
 
207
  spec = g_param_spec_boolean ("hide_on_esc", "Hide on Escape", "Hide on Escape", 
 
208
                               TRUE, (GParamFlags) G_PARAM_READWRITE);
 
209
  g_object_class_install_property (gobject_class, GM_HIDE_ON_ESC, spec); 
 
210
 
 
211
  spec = g_param_spec_boolean ("hide_on_delete", "Hide on delete-event", "Hide on delete-event (or just relay the event)",
 
212
                               TRUE, (GParamFlags) G_PARAM_READWRITE);
 
213
  g_object_class_install_property (gobject_class, GM_HIDE_ON_DELETE, spec);
 
214
}
 
215
 
 
216
 
 
217
static void
 
218
gm_window_init (GTypeInstance *instance,
 
219
                gpointer g_class)
 
220
{
 
221
  GmWindow *self = NULL;
 
222
 
 
223
  (void) g_class; /* -Wextra */
 
224
 
 
225
  self = GM_WINDOW (instance);
 
226
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GM_WINDOW_TYPE, GmWindowPrivate);
 
227
  self->priv->key = g_strdup ("");
 
228
  self->priv->hide_on_esc = TRUE;
 
229
  self->priv->hide_on_delete = TRUE;
 
230
 
 
231
  self->priv->accel = gtk_accel_group_new ();
 
232
  gtk_window_add_accel_group (GTK_WINDOW (self), self->priv->accel);
 
233
  gtk_accel_group_connect (self->priv->accel, GDK_Escape, (GdkModifierType) 0, GTK_ACCEL_LOCKED,
 
234
                           g_cclosure_new_swap (G_CALLBACK (gtk_widget_hide), (gpointer) self, NULL));
 
235
 
 
236
  g_signal_connect (G_OBJECT (self), "delete_event",
 
237
                    G_CALLBACK (gm_window_delete_event), NULL);
 
238
 
 
239
  g_signal_connect (G_OBJECT (self), "show",
 
240
                    G_CALLBACK (gm_window_show), self);
 
241
 
 
242
  g_signal_connect (G_OBJECT (self), "hide",
 
243
                    G_CALLBACK (gm_window_hide), self);
 
244
 
 
245
  g_signal_connect (G_OBJECT (self), "configure-event",
 
246
                    G_CALLBACK (gm_window_configure_event), self);
 
247
}
 
248
 
 
249
 
 
250
GType
 
251
gm_window_get_type ()
 
252
{
 
253
  static GType result = 0;
 
254
 
 
255
  if (result == 0) {
 
256
 
 
257
    static const GTypeInfo info = {
 
258
      sizeof (GmWindowClass),
 
259
      NULL,
 
260
      NULL,
 
261
      gm_window_class_init,
 
262
      NULL,
 
263
      NULL,
 
264
      sizeof (GmWindow),
 
265
      0,
 
266
      gm_window_init,
 
267
      NULL
 
268
    };
 
269
 
 
270
    result = g_type_register_static (GTK_TYPE_WINDOW,
 
271
                                     "GmWindowType",
 
272
                                     &info, (GTypeFlags) 0);
 
273
  }
 
274
 
 
275
  return result;
 
276
}
 
277
 
 
278
 
 
279
/* 
 
280
 * Our own stuff
 
281
 */
 
282
 
 
283
static gboolean
 
284
gm_window_delete_event (GtkWidget *w,
 
285
                        G_GNUC_UNUSED gpointer data)
 
286
{
 
287
  GmWindow* self = NULL;
 
288
 
 
289
  self = GM_WINDOW (w);
 
290
 
 
291
  if (self->priv->hide_on_delete) {
 
292
    gtk_widget_hide (w);
 
293
    return TRUE;
 
294
  } else {
 
295
    return FALSE;
 
296
  }
 
297
}
 
298
 
 
299
 
 
300
static void
 
301
gm_window_show (GtkWidget *w,
 
302
                G_GNUC_UNUSED gpointer data)
 
303
{
 
304
  int x = 0;
 
305
  int y = 0;
 
306
 
 
307
  GmWindow *self = NULL;
 
308
 
 
309
  gchar *conf_key_size = NULL;
 
310
  gchar *conf_key_position = NULL;
 
311
  gchar *size = NULL;
 
312
  gchar *position = NULL;
 
313
  gchar **couple = NULL;
 
314
 
 
315
  g_return_if_fail (w != NULL);
 
316
  
 
317
  self = GM_WINDOW (w);
 
318
 
 
319
  g_return_if_fail (strcmp (self->priv->key, ""));
 
320
 
 
321
  conf_key_position =
 
322
    g_strdup_printf ("%s/position", self->priv->key);
 
323
  conf_key_size =
 
324
    g_strdup_printf ("%s/size", self->priv->key);
 
325
 
 
326
  if (gtk_window_get_resizable (GTK_WINDOW (w))) {
 
327
 
 
328
    size = gm_conf_get_string (conf_key_size);
 
329
    if (size)
 
330
      couple = g_strsplit (size, ",", 0);
 
331
 
 
332
    if (couple && couple [0])
 
333
      x = atoi (couple [0]);
 
334
    if (couple && couple [1])
 
335
      y = atoi (couple [1]);
 
336
 
 
337
    if (x > 0 && y > 0) {
 
338
      gtk_window_resize (GTK_WINDOW (w), x, y);
 
339
    }
 
340
 
 
341
    g_strfreev (couple);
 
342
    g_free (size);
 
343
  }
 
344
 
 
345
  position = gm_conf_get_string (conf_key_position);
 
346
  if (position)
 
347
    couple = g_strsplit (position, ",", 0);
 
348
 
 
349
  if (couple && couple [0])
 
350
    x = atoi (couple [0]);
 
351
  if (couple && couple [1])
 
352
    y = atoi (couple [1]);
 
353
 
 
354
  if (x != 0 && y != 0)
 
355
    gtk_window_move (GTK_WINDOW (w), x, y);
 
356
 
 
357
  g_strfreev (couple);
 
358
  couple = NULL;
 
359
  g_free (position);
 
360
 
 
361
  gtk_widget_realize (GTK_WIDGET (w));
 
362
 
 
363
  g_free (conf_key_position);
 
364
  g_free (conf_key_size);
 
365
}
 
366
 
 
367
 
 
368
static void
 
369
gm_window_hide (GtkWidget *w,
 
370
                G_GNUC_UNUSED gpointer data)
 
371
{
 
372
  GmWindow *self = NULL;
 
373
 
 
374
  gchar *conf_key_size = NULL;
 
375
  gchar *conf_key_position = NULL;
 
376
  gchar *size = NULL;
 
377
  gchar *position = NULL;
 
378
  
 
379
  g_return_if_fail (w != NULL);
 
380
  
 
381
  self = GM_WINDOW (w);
 
382
 
 
383
  g_return_if_fail (strcmp (self->priv->key, ""));
 
384
 
 
385
  conf_key_position =
 
386
    g_strdup_printf ("%s/position", self->priv->key);
 
387
  conf_key_size =
 
388
    g_strdup_printf ("%s/size", self->priv->key);
 
389
 
 
390
  position = g_strdup_printf ("%d,%d", self->priv->x, self->priv->y);
 
391
  gm_conf_set_string (conf_key_position, position);
 
392
  g_free (position);
 
393
 
 
394
  if (gtk_window_get_resizable (GTK_WINDOW (w))) {
 
395
 
 
396
    size = g_strdup_printf ("%d,%d", self->priv->width, self->priv->height);
 
397
    gm_conf_set_string (conf_key_size, size);
 
398
    g_free (size);
 
399
  }
 
400
  
 
401
  g_free (conf_key_position);
 
402
  g_free (conf_key_size);
 
403
}
 
404
 
 
405
 
 
406
static gboolean 
 
407
gm_window_configure_event (GtkWidget *widget,
 
408
                           GdkEventConfigure *event)
 
409
{
 
410
  GM_WINDOW (widget)->priv->x = event->x;
 
411
  GM_WINDOW (widget)->priv->y = event->y;
 
412
 
 
413
  GM_WINDOW (widget)->priv->width = event->width;
 
414
  GM_WINDOW (widget)->priv->height = event->height;
 
415
 
 
416
  return FALSE;
 
417
}
 
418
 
 
419
 
 
420
/* 
 
421
 * Public API
 
422
 */
 
423
GtkWidget *
 
424
gm_window_new ()
 
425
{
 
426
  return GTK_WIDGET (g_object_new (GM_WINDOW_TYPE, NULL));
 
427
}
 
428
 
 
429
 
 
430
GtkWidget *
 
431
gm_window_new_with_key (const char *key)
 
432
{
 
433
  GtkWidget *window = NULL;
 
434
 
 
435
  g_return_val_if_fail (key != NULL, NULL);
 
436
 
 
437
  window = gm_window_new ();
 
438
  gm_window_set_key (GM_WINDOW (window), key);
 
439
 
 
440
  return window;
 
441
}
 
442
 
 
443
 
 
444
void
 
445
gm_window_set_key (GmWindow *window,
 
446
                   const char *key)
 
447
{
 
448
  g_return_if_fail (window != NULL);
 
449
  g_return_if_fail (key != NULL);
 
450
 
 
451
  g_object_set (GM_WINDOW (window), "key", key, NULL);
 
452
}
 
453
 
 
454
 
 
455
void 
 
456
gm_window_get_size (GmWindow *self,
 
457
                    int *x,
 
458
                    int *y)
 
459
{
 
460
  gchar *conf_key_size = NULL;
 
461
  gchar *size = NULL;
 
462
  gchar **couple = NULL;
 
463
 
 
464
  g_return_if_fail (self != NULL);
 
465
 
 
466
  conf_key_size = g_strdup_printf ("%s/size", self->priv->key);
 
467
  size = gm_conf_get_string (conf_key_size);
 
468
  if (size)
 
469
    couple = g_strsplit (size, ",", 0);
 
470
 
 
471
  if (x && couple && couple [0])
 
472
    *x = atoi (couple [0]);
 
473
  if (y && couple && couple [1])
 
474
    *y = atoi (couple [1]);
 
475
 
 
476
  g_free (conf_key_size);
 
477
  g_free (size);
 
478
  g_strfreev (couple);
 
479
}
 
480
 
 
481
void
 
482
gm_window_set_hide_on_delete (GmWindow *window,
 
483
                              gboolean hide_on_delete)
 
484
{
 
485
  g_return_if_fail (window != NULL);
 
486
  g_return_if_fail (IS_GM_WINDOW (window));
 
487
 
 
488
  g_object_set (GM_WINDOW (window), "hide_on_delete", hide_on_delete, NULL);
 
489
}
 
490
 
 
491
gboolean
 
492
gm_window_get_hide_on_delete (GmWindow *window)
 
493
{
 
494
  g_return_val_if_fail (window != NULL, FALSE);
 
495
  g_return_val_if_fail (IS_GM_WINDOW (window), FALSE);
 
496
 
 
497
  return window->priv->hide_on_delete;
 
498
}
 
499