2 * irreco - Ir Remote Control
3 * Copyright (C) 2007 Arto Karppinen (arto.karppinen@iki.fi)
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (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 Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "irreco_backend_err_dlg.h"
21 #include "gtk/gtkmessagedialog.h"
24 * @typedef IrrecoBackendErrDlg
26 * For displaying error messages from backends.
31 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
33 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
34 static gboolean
irreco_backend_err_dlg_configure_event(GtkWidget
*self
,
35 GdkEventConfigure
*event
,
40 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
41 /* Construction & Destruction */
42 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
43 G_DEFINE_TYPE(IrrecoBackendErrDlg
, irreco_backend_err_dlg
, IRRECO_TYPE_DLG
)
45 static void irreco_backend_err_dlg_finalize(GObject
*object
)
47 G_OBJECT_CLASS(irreco_backend_err_dlg_parent_class
)->finalize (object
);
50 static void irreco_backend_err_dlg_class_init(IrrecoBackendErrDlgClass
*klass
)
52 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
53 object_class
->finalize
= irreco_backend_err_dlg_finalize
;
56 static GtkWidget
* irreco_backend_err_dlg_create_label(const gchar
* text
)
61 label
= gtk_label_new(text
);
62 gtk_label_set_line_wrap(GTK_LABEL(label
), TRUE
);
63 gtk_label_set_selectable(GTK_LABEL(label
), TRUE
);
64 gtk_misc_set_alignment(GTK_MISC(label
), 0.0, 0.0);
65 IRRECO_RETURN_PTR(label
);
68 static void irreco_backend_err_dlg_init(IrrecoBackendErrDlg
*self
)
70 GtkWidget
*hbox
, *vbox
, *image
, *table
;
73 /* Construct dialog. */
74 gtk_window_set_title(GTK_WINDOW(self
), _("Irreco Backend Error"));
75 gtk_window_set_modal(GTK_WINDOW(self
), TRUE
);
76 gtk_window_set_destroy_with_parent(GTK_WINDOW(self
), TRUE
);
77 gtk_dialog_set_has_separator(GTK_DIALOG(self
), FALSE
);
78 gtk_dialog_add_buttons(GTK_DIALOG(self
),
79 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
83 hbox
= gtk_hbox_new(FALSE
, 12);
84 vbox
= gtk_vbox_new(FALSE
, 12);
85 table
= gtk_table_new(4, 2, 0);
86 gtk_table_set_col_spacings(GTK_TABLE(table
), 8);
87 gtk_table_set_row_spacings(GTK_TABLE(table
), 5);
89 image
= gtk_image_new_from_stock(NULL
, GTK_ICON_SIZE_DIALOG
);
90 gtk_image_set_from_stock(GTK_IMAGE(image
), GTK_STOCK_DIALOG_ERROR
,
91 GTK_ICON_SIZE_DIALOG
);
92 gtk_misc_set_alignment(GTK_MISC(image
), 0.5, 0.0);
94 self
->backend
= irreco_backend_err_dlg_create_label(NULL
);
95 self
->instace
= irreco_backend_err_dlg_create_label(NULL
);
96 self
->code
= irreco_backend_err_dlg_create_label(NULL
);
97 self
->message
= irreco_backend_err_dlg_create_label(NULL
);
100 gtk_table_attach_defaults(GTK_TABLE(table
),
101 irreco_backend_err_dlg_create_label(_("Backend:")), 0, 1, 0, 1);
102 gtk_table_attach_defaults(GTK_TABLE(table
), self
->backend
, 1, 2, 0, 1);
104 gtk_table_attach_defaults(GTK_TABLE(table
),
105 irreco_backend_err_dlg_create_label(_("Instance:")), 0, 1, 1, 2);
106 gtk_table_attach_defaults(GTK_TABLE(table
), self
->instace
, 1, 2, 1, 2);
108 gtk_table_attach_defaults(GTK_TABLE(table
),
109 irreco_backend_err_dlg_create_label(_("Code:")), 0, 1, 2, 3);
110 gtk_table_attach_defaults(GTK_TABLE(table
), self
->code
, 1, 2, 2, 3);
112 gtk_table_attach_defaults(GTK_TABLE(table
),
113 irreco_backend_err_dlg_create_label(_("Message:")), 0, 1, 3, 4);
114 gtk_table_attach_defaults(GTK_TABLE(table
), self
->message
, 1, 2, 3, 4);
116 gtk_box_pack_start(GTK_BOX(vbox
), table
,
119 gtk_box_pack_start(GTK_BOX(hbox
), image
,
122 gtk_box_pack_start(GTK_BOX(hbox
), vbox
,
125 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(self
)->vbox
), hbox
,
128 gtk_container_set_border_width(GTK_CONTAINER(self
), 5);
129 gtk_container_set_border_width(GTK_CONTAINER(hbox
), 5);
130 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(self
)->vbox
), 14); /* 14 + 2 * 5 = 24 */
131 gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(self
)->action_area
), 5);
132 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(self
)->action_area
), 6);
134 /* Signal handlers. */
135 g_signal_connect(G_OBJECT(self
), "configure-event",
136 G_CALLBACK(irreco_backend_err_dlg_configure_event
),
141 GtkWidget
* irreco_backend_err_dlg_new(GtkWindow
*parent
,
142 const gchar
*backend
,
143 const gchar
*instace
,
145 const gchar
*message
)
147 IrrecoBackendErrDlg
*self
;
150 self
= g_object_new(IRRECO_TYPE_BACKEND_ERR_DLG
, NULL
);
151 irreco_dlg_set_parent(IRRECO_DLG(self
), parent
);
153 gtk_label_set_text(GTK_LABEL(self
->backend
), backend
);
154 gtk_label_set_text(GTK_LABEL(self
->instace
), instace
);
155 gtk_label_set_text(GTK_LABEL(self
->code
), code
);
156 gtk_label_set_text(GTK_LABEL(self
->message
), message
);
157 IRRECO_RETURN_PTR(self
);
162 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
164 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
166 void irreco_show_backend_err_dlg(GtkWindow
*parent
,
167 const gchar
*backend
,
168 const gchar
*instace
,
170 const gchar
*message
)
175 self
= irreco_backend_err_dlg_new(parent
, backend
, instace
,
177 gtk_widget_show_all(GTK_WIDGET(self
));
178 gtk_dialog_run(GTK_DIALOG(self
));
179 gtk_widget_destroy(self
);
185 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
186 /* Signal handlers */
187 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
189 static gboolean
irreco_backend_err_dlg_configure_event(GtkWidget
*self
,
190 GdkEventConfigure
*event
,
196 IRRECO_PRINTF("Dialog size w%i h%i\n", event
->width
, event
->height
);
198 x
= (800 - event
->width
) / 2;
199 y
= (480 - event
->height
) / 2;
201 if (x
!= event
->x
|| y
!= event
->y
) {
202 IRRECO_PRINTF("Moving dialog from x%i y%i to x%i y%i\n",
203 event
->x
, event
->y
, x
, y
);
204 gtk_window_move(GTK_WINDOW(self
), x
, y
);
206 IRRECO_PRINTF("Dialog position x%i y%i\n", x
, y
);
209 IRRECO_RETURN_BOOL(FALSE
);