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"
23 * @addtogroup IrrecoInputDlg
26 * A simple dialog where the user can type input.
33 * Source file of @ref IrrecoInputDlg.
38 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
40 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
43 * @name Construction & Destruction
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
)
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
,
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
);
86 GtkWidget
*irreco_input_dlg_new(GtkWindow
*parent
, const gchar
*window_title
)
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
);
101 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
102 /* Public Functions */
103 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
106 * @name Public Functions
110 void irreco_input_dlg_set_ok_button_text(IrrecoInputDlg
*self
,
116 button
= irreco_gtk_dialog_get_button(GTK_WIDGET(self
), 1);
118 gtk_button_set_label(GTK_BUTTON(button
), GTK_STOCK_OK
);
120 gtk_button_set_label(GTK_BUTTON(button
), text
);
125 void irreco_input_dlg_set_label(IrrecoInputDlg
*self
, const gchar
*text
)
129 gtk_box_set_spacing(GTK_BOX(self
->hbox
), 0);
130 gtk_label_set_text(GTK_LABEL(self
->label
), NULL
);
132 gtk_box_set_spacing(GTK_BOX(self
->hbox
), 8);
133 gtk_label_set_text(GTK_LABEL(self
->label
), text
);
138 void irreco_input_dlg_set_entry(IrrecoInputDlg
*self
, const gchar
*text
)
141 gtk_entry_set_text(GTK_ENTRY(self
->entry
), text
);
145 const gchar
*irreco_input_dlg_get_entry(IrrecoInputDlg
*self
)
148 IRRECO_RETURN_CONST_STR(gtk_entry_get_text(GTK_ENTRY(self
->entry
)))
151 gboolean
irreco_show_input_dlg(IrrecoInputDlg
*self
)
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."));
165 IRRECO_RETURN_BOOL(TRUE
);
168 IRRECO_RETURN_BOOL(FALSE
);