[gthumb] terminal: added preferences dialog to customize the command



commit 6b76a98fb05d5a4e87bdb004d276726d636affe2
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun Feb 23 10:27:42 2020 +0100

    terminal: added preferences dialog to customize the command

 extensions/terminal/data/meson.build               |   1 +
 extensions/terminal/data/ui/meson.build            |   4 +
 .../terminal/data/ui/terminal-preferences.ui       |  24 +++++
 extensions/terminal/dlg-terminal-preferences.c     | 117 +++++++++++++++++++++
 extensions/terminal/dlg-terminal-preferences.h     |  29 +++++
 extensions/terminal/main.c                         |   4 +-
 extensions/terminal/meson.build                    |   5 +
 7 files changed, 183 insertions(+), 1 deletion(-)
---
diff --git a/extensions/terminal/data/meson.build b/extensions/terminal/data/meson.build
new file mode 100644
index 00000000..36e5b291
--- /dev/null
+++ b/extensions/terminal/data/meson.build
@@ -0,0 +1 @@
+subdir('ui')
diff --git a/extensions/terminal/data/ui/meson.build b/extensions/terminal/data/ui/meson.build
new file mode 100644
index 00000000..9a9af9a6
--- /dev/null
+++ b/extensions/terminal/data/ui/meson.build
@@ -0,0 +1,4 @@
+ui_files = files(
+  'terminal-preferences.ui'
+)
+install_data(ui_files, install_dir : ui_install_dir)
diff --git a/extensions/terminal/data/ui/terminal-preferences.ui 
b/extensions/terminal/data/ui/terminal-preferences.ui
new file mode 100644
index 00000000..e1947e9f
--- /dev/null
+++ b/extensions/terminal/data/ui/terminal-preferences.ui
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.1 -->
+<interface>
+  <requires lib="gtk+" version="3.16"/>
+  <object class="GtkBox" id="dialog_content">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="border_width">15</property>
+    <property name="orientation">vertical</property>
+    <property name="spacing">15</property>
+    <child>
+      <object class="GtkEntry" id="command_entry">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="width_chars">50</property>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">0</property>
+      </packing>
+    </child>
+  </object>
+</interface>
diff --git a/extensions/terminal/dlg-terminal-preferences.c b/extensions/terminal/dlg-terminal-preferences.c
new file mode 100644
index 00000000..66feaa72
--- /dev/null
+++ b/extensions/terminal/dlg-terminal-preferences.c
@@ -0,0 +1,117 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2020 The Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <gtk/gtk.h>
+#include <gthumb.h>
+#include "dlg-terminal-preferences.h"
+#include "preferences.h"
+
+
+typedef struct {
+       GtkBuilder *builder;
+       GSettings  *settings;
+       GtkWidget  *dialog;
+} DialogData;
+
+
+static void
+update_settings (DialogData *data)
+{
+       const char *command;
+
+       command = gtk_entry_get_text (GTK_ENTRY (gtk_builder_get_object (data->builder, "command_entry")));
+       if (command != NULL)
+               g_settings_set_string (data->settings, PREF_TERMINAL_COMMAND, command);
+}
+
+
+static void
+destroy_cb (GtkWidget  *widget,
+           DialogData *data)
+{
+       g_object_unref (data->builder);
+       g_object_unref (data->settings);
+       g_free (data);
+}
+
+
+static void
+dialog_response_cb (GtkDialog *dialog,
+                   int        response_id,
+                   gpointer   user_data)
+{
+       DialogData *data = user_data;
+
+       if (response_id == GTK_RESPONSE_ACCEPT)
+               update_settings (data);
+       gtk_widget_destroy (data->dialog);
+}
+
+
+void
+dlg_terminal_preferences (GtkWindow *parent)
+{
+       DialogData *data;
+       char       *command;
+
+       data = g_new0 (DialogData, 1);
+       data->builder = _gtk_builder_new_from_file ("terminal-preferences.ui", "terminal");
+       data->settings = g_settings_new (GTHUMB_TERMINAL_SCHEMA);
+
+       /* Get the widgets. */
+
+       data->dialog = g_object_new (GTK_TYPE_DIALOG,
+                                    "title", _("Preferences"),
+                                    "transient-for", GTK_WINDOW (parent),
+                                    "modal", TRUE,
+                                    "destroy-with-parent", FALSE,
+                                    "use-header-bar", _gtk_settings_get_dialogs_use_header (),
+                                    NULL);
+       gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (data->dialog))),
+                          _gtk_builder_get_widget (data->builder, "dialog_content"));
+       gtk_dialog_add_buttons (GTK_DIALOG (data->dialog),
+                               _GTK_LABEL_CANCEL, GTK_RESPONSE_CANCEL,
+                               _GTK_LABEL_SAVE, GTK_RESPONSE_ACCEPT,
+                               NULL);
+       _gtk_dialog_add_class_to_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_ACCEPT, 
GTK_STYLE_CLASS_SUGGESTED_ACTION);
+
+       /* Set widgets data. */
+
+       command = g_settings_get_string (data->settings, PREF_TERMINAL_COMMAND);
+       gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (data->builder, "command_entry")), command);
+       g_free (command);
+
+       /* Set the signals handlers. */
+
+       g_signal_connect (G_OBJECT (data->dialog),
+                         "destroy",
+                         G_CALLBACK (destroy_cb),
+                         data);
+       g_signal_connect (data->dialog,
+                         "response",
+                         G_CALLBACK (dialog_response_cb),
+                         data);
+
+       /* run dialog. */
+
+       gtk_widget_show (data->dialog);
+}
diff --git a/extensions/terminal/dlg-terminal-preferences.h b/extensions/terminal/dlg-terminal-preferences.h
new file mode 100644
index 00000000..6edc46a5
--- /dev/null
+++ b/extensions/terminal/dlg-terminal-preferences.h
@@ -0,0 +1,29 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2020 The Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef DLG_TERMINAL_PREFERENCES_H
+#define DLG_TERMINAL_PREFERENCES_H
+
+#include <gthumb.h>
+
+void dlg_terminal_preferences (GtkWindow *parent);
+
+#endif /* DLG_TERMINAL_PREFERENCES_H */
diff --git a/extensions/terminal/main.c b/extensions/terminal/main.c
index 7bfacf1c..385e6d79 100644
--- a/extensions/terminal/main.c
+++ b/extensions/terminal/main.c
@@ -24,6 +24,7 @@
 #include <gtk/gtk.h>
 #include <gthumb.h>
 #include "callbacks.h"
+#include "dlg-terminal-preferences.h"
 
 
 G_MODULE_EXPORT void
@@ -43,11 +44,12 @@ gthumb_extension_deactivate (void)
 G_MODULE_EXPORT gboolean
 gthumb_extension_is_configurable (void)
 {
-       return FALSE;
+       return TRUE;
 }
 
 
 G_MODULE_EXPORT void
 gthumb_extension_configure (GtkWindow *parent)
 {
+       dlg_terminal_preferences (parent);
 }
diff --git a/extensions/terminal/meson.build b/extensions/terminal/meson.build
index 95224aa9..df2254c3 100644
--- a/extensions/terminal/meson.build
+++ b/extensions/terminal/meson.build
@@ -1,6 +1,7 @@
 source_files = files(
   'actions.c',
   'callbacks.c',
+  'dlg-terminal-preferences.c',
   'main.c'
 )
 
@@ -30,3 +31,7 @@ i18n.merge_file(
   install : true,
   install_dir : extensions_install_dir
 )
+
+# Subdirectories
+
+subdir('data')


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]