2
/* Ekiga -- A VoIP and Video-Conferencing application
3
* Copyright (C) 2000-2006 Damien Sandras
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.
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.
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.
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.
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.
43
#include <gdk/gdkkeysyms.h>
51
struct _GmWindowPrivate
55
gboolean hide_on_delete;
69
static GObjectClass *parent_class = NULL;
72
gm_window_delete_event (GtkWidget *w,
76
gm_window_show (GtkWidget *w,
80
gm_window_hide (GtkWidget *w,
84
gm_window_configure_event (GtkWidget *widget,
85
GdkEventConfigure *event);
92
gm_window_dispose (GObject *obj)
94
GmWindow *window = NULL;
96
window = GM_WINDOW (obj);
98
parent_class->dispose (obj);
103
gm_window_finalize (GObject *obj)
105
GmWindow *window = NULL;
107
window = GM_WINDOW (obj);
109
g_free ((gchar *) window->priv->key);
111
parent_class->finalize (obj);
116
gm_window_get_property (GObject *obj,
121
GmWindow *self = NULL;
123
self = GM_WINDOW (obj);
124
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GM_WINDOW_TYPE, GmWindowPrivate);
129
g_value_set_string (value, self->priv->key);
133
g_value_set_boolean (value, self->priv->hide_on_esc);
136
case GM_HIDE_ON_DELETE:
137
g_value_set_boolean (value, self->priv->hide_on_delete);
141
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, spec);
148
gm_window_set_property (GObject *obj,
153
GmWindow *self = NULL;
154
const gchar *str = NULL;
156
self = GM_WINDOW (obj);
157
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GM_WINDOW_TYPE, GmWindowPrivate);
162
g_free ((gchar *) self->priv->key);
163
str = g_value_get_string (value);
164
self->priv->key = g_strdup (str ? str : "");
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);
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));
176
case GM_HIDE_ON_DELETE:
177
self->priv->hide_on_delete = g_value_get_boolean (value);
181
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, spec);
188
gm_window_class_init (gpointer g_class,
189
G_GNUC_UNUSED gpointer class_data)
191
GObjectClass *gobject_class = NULL;
192
GParamSpec *spec = NULL;
194
parent_class = (GObjectClass *) g_type_class_peek_parent (g_class);
195
g_type_class_add_private (g_class, sizeof (GmWindowPrivate));
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;
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);
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);
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);
218
gm_window_init (GTypeInstance *instance,
221
GmWindow *self = NULL;
223
(void) g_class; /* -Wextra */
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;
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));
236
g_signal_connect (G_OBJECT (self), "delete_event",
237
G_CALLBACK (gm_window_delete_event), NULL);
239
g_signal_connect (G_OBJECT (self), "show",
240
G_CALLBACK (gm_window_show), self);
242
g_signal_connect (G_OBJECT (self), "hide",
243
G_CALLBACK (gm_window_hide), self);
245
g_signal_connect (G_OBJECT (self), "configure-event",
246
G_CALLBACK (gm_window_configure_event), self);
251
gm_window_get_type ()
253
static GType result = 0;
257
static const GTypeInfo info = {
258
sizeof (GmWindowClass),
261
gm_window_class_init,
270
result = g_type_register_static (GTK_TYPE_WINDOW,
272
&info, (GTypeFlags) 0);
284
gm_window_delete_event (GtkWidget *w,
285
G_GNUC_UNUSED gpointer data)
287
GmWindow* self = NULL;
289
self = GM_WINDOW (w);
291
if (self->priv->hide_on_delete) {
301
gm_window_show (GtkWidget *w,
302
G_GNUC_UNUSED gpointer data)
307
GmWindow *self = NULL;
309
gchar *conf_key_size = NULL;
310
gchar *conf_key_position = NULL;
312
gchar *position = NULL;
313
gchar **couple = NULL;
315
g_return_if_fail (w != NULL);
317
self = GM_WINDOW (w);
319
g_return_if_fail (strcmp (self->priv->key, ""));
322
g_strdup_printf ("%s/position", self->priv->key);
324
g_strdup_printf ("%s/size", self->priv->key);
326
if (gtk_window_get_resizable (GTK_WINDOW (w))) {
328
size = gm_conf_get_string (conf_key_size);
330
couple = g_strsplit (size, ",", 0);
332
if (couple && couple [0])
333
x = atoi (couple [0]);
334
if (couple && couple [1])
335
y = atoi (couple [1]);
337
if (x > 0 && y > 0) {
338
gtk_window_resize (GTK_WINDOW (w), x, y);
345
position = gm_conf_get_string (conf_key_position);
347
couple = g_strsplit (position, ",", 0);
349
if (couple && couple [0])
350
x = atoi (couple [0]);
351
if (couple && couple [1])
352
y = atoi (couple [1]);
354
if (x != 0 && y != 0)
355
gtk_window_move (GTK_WINDOW (w), x, y);
361
gtk_widget_realize (GTK_WIDGET (w));
363
g_free (conf_key_position);
364
g_free (conf_key_size);
369
gm_window_hide (GtkWidget *w,
370
G_GNUC_UNUSED gpointer data)
372
GmWindow *self = NULL;
374
gchar *conf_key_size = NULL;
375
gchar *conf_key_position = NULL;
377
gchar *position = NULL;
379
g_return_if_fail (w != NULL);
381
self = GM_WINDOW (w);
383
g_return_if_fail (strcmp (self->priv->key, ""));
386
g_strdup_printf ("%s/position", self->priv->key);
388
g_strdup_printf ("%s/size", self->priv->key);
390
position = g_strdup_printf ("%d,%d", self->priv->x, self->priv->y);
391
gm_conf_set_string (conf_key_position, position);
394
if (gtk_window_get_resizable (GTK_WINDOW (w))) {
396
size = g_strdup_printf ("%d,%d", self->priv->width, self->priv->height);
397
gm_conf_set_string (conf_key_size, size);
401
g_free (conf_key_position);
402
g_free (conf_key_size);
407
gm_window_configure_event (GtkWidget *widget,
408
GdkEventConfigure *event)
410
GM_WINDOW (widget)->priv->x = event->x;
411
GM_WINDOW (widget)->priv->y = event->y;
413
GM_WINDOW (widget)->priv->width = event->width;
414
GM_WINDOW (widget)->priv->height = event->height;
426
return GTK_WIDGET (g_object_new (GM_WINDOW_TYPE, NULL));
431
gm_window_new_with_key (const char *key)
433
GtkWidget *window = NULL;
435
g_return_val_if_fail (key != NULL, NULL);
437
window = gm_window_new ();
438
gm_window_set_key (GM_WINDOW (window), key);
445
gm_window_set_key (GmWindow *window,
448
g_return_if_fail (window != NULL);
449
g_return_if_fail (key != NULL);
451
g_object_set (GM_WINDOW (window), "key", key, NULL);
456
gm_window_get_size (GmWindow *self,
460
gchar *conf_key_size = NULL;
462
gchar **couple = NULL;
464
g_return_if_fail (self != NULL);
466
conf_key_size = g_strdup_printf ("%s/size", self->priv->key);
467
size = gm_conf_get_string (conf_key_size);
469
couple = g_strsplit (size, ",", 0);
471
if (x && couple && couple [0])
472
*x = atoi (couple [0]);
473
if (y && couple && couple [1])
474
*y = atoi (couple [1]);
476
g_free (conf_key_size);
482
gm_window_set_hide_on_delete (GmWindow *window,
483
gboolean hide_on_delete)
485
g_return_if_fail (window != NULL);
486
g_return_if_fail (IS_GM_WINDOW (window));
488
g_object_set (GM_WINDOW (window), "hide_on_delete", hide_on_delete, NULL);
492
gm_window_get_hide_on_delete (GmWindow *window)
494
g_return_val_if_fail (window != NULL, FALSE);
495
g_return_val_if_fail (IS_GM_WINDOW (window), FALSE);
497
return window->priv->hide_on_delete;