Added button image data transmission from
[irreco.git] / irreco / src / core / irreco_input_dlg.c
blobc150ed3d7e653b7e918c41e6dac79ce4bc16eac0
1 /*
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_input_dlg.h"
22 /**
23 * @addtogroup IrrecoInputDlg
24 * @ingroup Irreco
26 * A simple dialog where the user can type input.
28 * @{
31 /**
32 * @file
33 * Source file of @ref IrrecoInputDlg.
38 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
39 /* Prototypes */
40 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
42 /**
43 * @name Construction & Destruction
44 * @{
47 G_DEFINE_TYPE(IrrecoInputDlg, irreco_input_dlg, IRRECO_TYPE_DLG)
49 static void irreco_input_dlg_finalize(GObject *object)
51 G_OBJECT_CLASS(irreco_input_dlg_parent_class)->finalize(object);
54 static void irreco_input_dlg_class_init(IrrecoInputDlgClass *klass)
56 GObjectClass *object_class = G_OBJECT_CLASS(klass);
57 object_class->finalize = irreco_input_dlg_finalize;
60 static void irreco_input_dlg_init(IrrecoInputDlg *self)
62 GtkWidget *padding;
63 IRRECO_ENTER
65 /* Construct dialog. */
66 gtk_window_set_title(GTK_WINDOW(self), _("Input dialog"));
67 gtk_window_set_modal(GTK_WINDOW(self), TRUE);
68 gtk_window_set_destroy_with_parent(GTK_WINDOW(self), TRUE);
69 gtk_dialog_set_has_separator(GTK_DIALOG(self), FALSE);
70 gtk_dialog_add_buttons(GTK_DIALOG(self),
71 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
72 GTK_STOCK_OK, GTK_RESPONSE_OK,
73 NULL);
75 /* Add widgets. */
76 self->hbox = gtk_hbox_new(FALSE, 0);
77 self->label = gtk_label_new(NULL);
78 self->entry = gtk_entry_new();
79 gtk_container_add(GTK_CONTAINER(self->hbox), self->label);
80 gtk_container_add(GTK_CONTAINER(self->hbox), self->entry);
81 padding = irreco_gtk_pad(self->hbox, 8, 8, 8, 8);
82 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(self)->vbox), padding);
83 IRRECO_RETURN
86 GtkWidget *irreco_input_dlg_new(GtkWindow *parent, const gchar *window_title)
88 IrrecoInputDlg *self;
89 IRRECO_ENTER
91 self = g_object_new(IRRECO_TYPE_INPUT_DLG, NULL);
92 irreco_dlg_set_parent(IRRECO_DLG(self), parent);
93 gtk_window_set_title(GTK_WINDOW(self), window_title);
94 IRRECO_RETURN_PTR(self);
97 /** @} */
101 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
102 /* Public Functions */
103 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
106 * @name Public Functions
107 * @{
110 void irreco_input_dlg_set_ok_button_text(IrrecoInputDlg *self,
111 const gchar *text)
113 GtkWidget *button;
114 IRRECO_ENTER
116 button = irreco_gtk_dialog_get_button(GTK_WIDGET(self), 1);
117 if (text == NULL) {
118 gtk_button_set_label(GTK_BUTTON(button), GTK_STOCK_OK);
119 } else {
120 gtk_button_set_label(GTK_BUTTON(button), text);
122 IRRECO_RETURN
125 void irreco_input_dlg_set_label(IrrecoInputDlg *self, const gchar *text)
127 IRRECO_ENTER
128 if (text == NULL) {
129 gtk_box_set_spacing(GTK_BOX(self->hbox), 0);
130 gtk_label_set_text(GTK_LABEL(self->label), NULL);
131 } else {
132 gtk_box_set_spacing(GTK_BOX(self->hbox), 8);
133 gtk_label_set_text(GTK_LABEL(self->label), text);
135 IRRECO_RETURN
138 void irreco_input_dlg_set_entry(IrrecoInputDlg *self, const gchar *text)
140 IRRECO_ENTER
141 gtk_entry_set_text(GTK_ENTRY(self->entry), text);
142 IRRECO_RETURN
145 const gchar *irreco_input_dlg_get_entry(IrrecoInputDlg *self)
147 IRRECO_ENTER
148 IRRECO_RETURN_CONST_STR(gtk_entry_get_text(GTK_ENTRY(self->entry)))
151 gboolean irreco_show_input_dlg(IrrecoInputDlg *self)
153 const gchar *input;
154 IRRECO_ENTER
156 gtk_widget_show_all(GTK_WIDGET(self));
157 while (gtk_dialog_run(GTK_DIALOG(self)) == GTK_RESPONSE_OK)
159 input = irreco_input_dlg_get_entry(IRRECO_INPUT_DLG(self));
160 if (g_utf8_strlen(input, -1) < 1) {
161 irreco_error_dlg(GTK_WINDOW(self),
162 _("Empty input is not valid. "
163 "Type something, or press cancel."));
164 } else {
165 IRRECO_RETURN_BOOL(TRUE);
168 IRRECO_RETURN_BOOL(FALSE);
171 /** @} */
173 /** @} */