Debian Codegraph @

extensions/terminal/dlg-terminal-preferences.c

raw symbols SCIP
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /*
4 * GThumb
5 *
6 * Copyright (C) 2020 The Free Software Foundation, Inc.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include <config.h>
23 #include <gtk/gtk.h>
24 #include <gthumb.h>
25 #include "dlg-terminal-preferences.h"
26 #include "preferences.h"
27
28
29 typedef struct {
30 GtkBuilder *builder;
31 GSettings *settings;
32 GtkWidget *dialog;
33 } DialogData;
34
35
36 static void
37 update_settings (DialogData *data)
38 {
39 const char *command;
40
41 command = gtk_entry_get_text (GTK_ENTRY (gtk_builder_get_object (data->builder, "command_entry")));
42 if (command != NULL)
43 g_settings_set_string (data->settings, PREF_TERMINAL_COMMAND, command);
44 }
45
46
47 static void
48 destroy_cb (GtkWidget *widget,
49 DialogData *data)
50 {
51 g_object_unref (data->builder);
52 g_object_unref (data->settings);
53 g_free (data);
54 }
55
56
57 static void
58 dialog_response_cb (GtkDialog *dialog,
59 int response_id,
60 gpointer user_data)
61 {
62 DialogData *data = user_data;
63
64 if (response_id == GTK_RESPONSE_ACCEPT)
65 update_settings (data);
66 gtk_widget_destroy (data->dialog);
67 }
68
69
70 void
71 dlg_terminal_preferences (GtkWindow *parent)
72 {
73 DialogData *data;
74 char *command;
75
76 data = g_new0 (DialogData, 1);
77 data->builder = _gtk_builder_new_from_file ("terminal-preferences.ui", "terminal");
78 data->settings = g_settings_new (GTHUMB_TERMINAL_SCHEMA);
79
80 /* Get the widgets. */
81
82 data->dialog = g_object_new (GTK_TYPE_DIALOG,
83 "title", _("Preferences"),
84 "transient-for", GTK_WINDOW (parent),
85 "modal", TRUE,
86 "destroy-with-parent", FALSE,
87 "use-header-bar", _gtk_settings_get_dialogs_use_header (),
88 NULL);
89 gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (data->dialog))),
90 _gtk_builder_get_widget (data->builder, "dialog_content"));
91 gtk_dialog_add_buttons (GTK_DIALOG (data->dialog),
92 _GTK_LABEL_CANCEL, GTK_RESPONSE_CANCEL,
93 _GTK_LABEL_SAVE, GTK_RESPONSE_ACCEPT,
94 NULL);
95 _gtk_dialog_add_class_to_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_ACCEPT, GTK_STYLE_CLASS_SUGGESTED_ACTION);
96
97 /* Set widgets data. */
98
99 command = g_settings_get_string (data->settings, PREF_TERMINAL_COMMAND);
100 gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (data->builder, "command_entry")), command);
101 g_free (command);
102
103 /* Set the signals handlers. */
104
105 g_signal_connect (G_OBJECT (data->dialog),
106 "destroy",
107 G_CALLBACK (destroy_cb),
108 data);
109 g_signal_connect (data->dialog,
110 "response",
111 G_CALLBACK (dialog_response_cb),
112 data);
113
114 /* run dialog. */
115
116 gtk_widget_show (data->dialog);
117 }