summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLogan Rathbone <poprocks@gmail.com>2021-02-13 19:53:09 -0500
committerLogan Rathbone <poprocks@gmail.com>2021-02-13 19:53:09 -0500
commit6b6ef217972a2776b46406ad421f4ade432c1574 (patch)
tree20b53445e390f979e9814d3fdd1377eb1f831274 /src
parentcbc76d2217ece34bd8da7f1fd2aeb623c9f45f72 (diff)
downloadzenity-6b6ef217972a2776b46406ad421f4ade432c1574.tar.gz
.ui: use resource; cleanup before commencing meson conversion.
Diffstat (limited to 'src')
-rw-r--r--src/about.c2
-rw-r--r--src/calendar.c20
-rw-r--r--src/fileselection.c9
-rw-r--r--src/main.c5
-rw-r--r--src/msg.c21
-rw-r--r--src/notification.c14
-rw-r--r--src/util.c59
-rw-r--r--src/util.h5
-rw-r--r--src/zenity.gresource.xml28
-rw-r--r--src/zenity.ui4
10 files changed, 96 insertions, 71 deletions
diff --git a/src/about.c b/src/about.c
index e01e0af..338cca3 100644
--- a/src/about.c
+++ b/src/about.c
@@ -35,8 +35,6 @@
#include <config.h>
#define GTK_RESPONSE_CREDITS 0
-#define ZENITY_HELP_PATH ZENITY_DATADIR "/help/"
-#define ZENITY_CLOTHES_PATH ZENITY_DATADIR "/clothes/"
#define ZENITY_CANVAS_X 400.0
#define ZENITY_CANVAS_Y 280.0
diff --git a/src/calendar.c b/src/calendar.c
index e8495d1..f674e4c 100644
--- a/src/calendar.c
+++ b/src/calendar.c
@@ -37,10 +37,6 @@ static ZenityCalendarData *zen_cal_data;
static void zenity_calendar_dialog_response (GtkWidget *widget,
int response, gpointer data);
-#if 0
-static void zenity_calendar_day_selected (GtkCalendar *calendar,
- gpointer data);
-#endif
void
zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data)
@@ -102,14 +98,6 @@ zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data)
NULL);
}
- /* day-selected-double-click is gone in gtk4, and having this emit upon
- * single-click violates POLA more than just disabling the behaviour,
- * IMO. */
-#if 0
- g_signal_connect (calendar, "day-selected",
- G_CALLBACK(zenity_calendar_day_selected), data);
-#endif
-
gtk_label_set_mnemonic_widget (GTK_LABEL (text), calendar);
zenity_util_show_dialog (dialog);
@@ -198,11 +186,3 @@ zenity_calendar_dialog_response (GtkWidget *widget, int response,
}
zenity_util_gapp_quit (GTK_WINDOW(gtk_widget_get_native (widget)));
}
-
-#if 0
-static void
-zenity_calendar_day_selected (GtkCalendar *cal, gpointer data)
-{
- zenity_calendar_dialog_response (GTK_WIDGET(cal), GTK_RESPONSE_OK, data);
-}
-#endif
diff --git a/src/fileselection.c b/src/fileselection.c
index a44677e..0020b23 100644
--- a/src/fileselection.c
+++ b/src/fileselection.c
@@ -166,7 +166,8 @@ zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
* util function.
*/
gtk_native_dialog_show (GTK_NATIVE_DIALOG(dialog));
- g_application_hold (g_application_get_default ());
+
+ zenity_util_gapp_main (NULL);
}
static void
@@ -223,9 +224,5 @@ zenity_fileselection_dialog_response (GtkDialog *dialog,
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
break;
}
-
- /* Since a native dialog is not a GtkWindow, we can't use our handy
- * util function.
- */
- g_application_release (g_application_get_default ());
+ zenity_util_gapp_quit (NULL);
}
diff --git a/src/main.c b/src/main.c
index 8a9174b..3649ad5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -133,8 +133,9 @@ activate_cb (GtkApplication *app, gpointer user_data)
zenity_option_free ();
g_free (args);
- // FIXME - pass retval to gapplication properly.
-// exit (retval);
+ /* FIXME - pass retval to gapplication properly.
+ * exit (retval);
+ */
}
int
diff --git a/src/msg.c b/src/msg.c
index 983fd6a..e7af4f7 100644
--- a/src/msg.c
+++ b/src/msg.c
@@ -55,6 +55,7 @@ zenity_msg_construct_question_dialog (GtkWidget *dialog,
}
}
+/* FIXME - Is this still necessary with gtk4? */
static void
zenity_label_widget_clipboard_selection (GtkWidget *widget)
{
@@ -104,8 +105,8 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
case ZENITY_MSG_QUESTION:
case ZENITY_MSG_SWITCH:
builder = zenity_util_load_ui_file ("zenity_question_dialog", NULL);
- dialog = GTK_WIDGET (
- gtk_builder_get_object (builder, "zenity_question_dialog"));
+ dialog = GTK_WIDGET (gtk_builder_get_object (builder,
+ "zenity_question_dialog"));
text = gtk_builder_get_object (builder, "zenity_question_text");
image = gtk_builder_get_object (builder, "zenity_question_image");
ok_button = NULL;
@@ -113,22 +114,22 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
case ZENITY_MSG_ERROR:
builder = zenity_util_load_ui_file ("zenity_error_dialog", NULL);
- dialog = GTK_WIDGET (
- gtk_builder_get_object (builder, "zenity_error_dialog"));
+ dialog = GTK_WIDGET (gtk_builder_get_object (builder,
+ "zenity_error_dialog"));
text = gtk_builder_get_object (builder, "zenity_error_text");
image = gtk_builder_get_object (builder, "zenity_error_image");
- ok_button = GTK_WIDGET (
- gtk_builder_get_object (builder, "zenity_error_ok_button"));
+ ok_button = GTK_WIDGET (gtk_builder_get_object (builder,
+ "zenity_error_ok_button"));
break;
case ZENITY_MSG_INFO:
builder = zenity_util_load_ui_file ("zenity_info_dialog", NULL);
- dialog = GTK_WIDGET (
- gtk_builder_get_object (builder, "zenity_info_dialog"));
+ dialog = GTK_WIDGET (gtk_builder_get_object (builder,
+ "zenity_info_dialog"));
text = gtk_builder_get_object (builder, "zenity_info_text");
image = gtk_builder_get_object (builder, "zenity_info_image");
- ok_button = GTK_WIDGET (
- gtk_builder_get_object (builder, "zenity_info_ok_button"));
+ ok_button = GTK_WIDGET (gtk_builder_get_object (builder,
+ "zenity_info_ok_button"));
break;
default:
diff --git a/src/notification.c b/src/notification.c
index 928a9ab..20a47f7 100644
--- a/src/notification.c
+++ b/src/notification.c
@@ -377,8 +377,11 @@ zenity_notification (ZenityData *data,
if (notification_data->listen)
{
zenity_notification_listen_on_stdin (data);
- // FIXME - not sure what to replace this with atm.
-// gtk_main ();
+
+ /* FIXME - gtk_main () was here. Possibly replace this with the
+ * zenity_util_gapp_main function and a corresponding _quit in
+ * place of the exit calls.
+ */
}
else
{
@@ -427,8 +430,11 @@ zenity_notification (ZenityData *data,
g_timeout_add_seconds (data->timeout_delay,
(GSourceFunc) zenity_util_timeout_handle,
NULL);
- // FIXME - not sure what to replace this with here.
-// gtk_main ();
+
+ /* FIXME - gtk_main () was here. Possibly replace this with the
+ * zenity_util_gapp_main function and a corresponding _quit in
+ * place of the exit calls.
+ */
}
}
diff --git a/src/util.c b/src/util.c
index 8ec7e29..4a92149 100644
--- a/src/util.c
+++ b/src/util.c
@@ -57,7 +57,7 @@ zenity_util_load_ui_file (const char *root_widget, ...)
GtkBuilder *builder = gtk_builder_new ();
GError *error = NULL;
char **objects;
- guint result = 0;
+ gboolean result = FALSE;
gtk_builder_set_translation_domain (builder, GETTEXT_PACKAGE);
@@ -80,25 +80,25 @@ zenity_util_load_ui_file (const char *root_widget, ...)
g_ptr_array_add (ptrarray, NULL);
objects = (char **)g_ptr_array_free (ptrarray, FALSE);
- if (g_file_test (ZENITY_UI_FILE_RELATIVEPATH, G_FILE_TEST_EXISTS)) {
- /* Try current dir, for debugging */
- result = gtk_builder_add_objects_from_file (builder,
- ZENITY_UI_FILE_RELATIVEPATH, (const char **)objects, NULL);
- }
-
- if (result == 0)
- result = gtk_builder_add_objects_from_file (builder,
- ZENITY_UI_FILE_FULLPATH, (const char **)objects, &error);
+ result = gtk_builder_add_objects_from_resource (builder,
+ ZENITY_UI_RESOURCE_PATH,
+ (const char **)objects,
+ &error);
g_strfreev (objects);
- if (result == 0) {
- g_warning ("Could not load ui file %s: %s",
- ZENITY_UI_FILE_FULLPATH,
- error->message);
+ if (! result) {
+ g_error ("Could not load ui resource %s: %s",
+ ZENITY_UI_RESOURCE_PATH,
+ error->message);
+ }
+
+ /* This should never happen, but if an unexpected error is logged, print
+ * it for debugging purposes. */
+ if (error) {
+ g_debug ("%s: Error generated: %s",
+ __func__, error->message);
g_error_free (error);
- g_object_unref (builder);
- return NULL;
}
return builder;
@@ -544,18 +544,31 @@ zenity_util_timeout_handle (gpointer data)
void
zenity_util_gapp_main (GtkWindow *window)
{
- GtkApplication *app;
+ GApplication *app = g_application_get_default ();
- g_assert (GTK_IS_WINDOW (window));
+ if (window)
+ {
+ /* As this behaves quite differently if a window is provided vs. not,
+ * let's ensure any window passed is valid.
+ */
+ g_assert (GTK_IS_WINDOW (window));
- app = GTK_APPLICATION(g_application_get_default ());
- gtk_application_add_window (app, window);
+ gtk_application_add_window (GTK_APPLICATION(app), window);
+ }
+ else {
+ g_application_hold (g_application_get_default ());
+ }
}
void
zenity_util_gapp_quit (GtkWindow *window)
{
- g_assert (GTK_IS_WINDOW (window));
-
- gtk_window_set_application (window, NULL);
+ if (window)
+ {
+ g_assert (GTK_IS_WINDOW (window));
+ gtk_window_set_application (window, NULL);
+ }
+ else {
+ g_application_release (g_application_get_default ());
+ }
}
diff --git a/src/util.h b/src/util.h
index 78f3567..fdb1085 100644
--- a/src/util.h
+++ b/src/util.h
@@ -41,10 +41,9 @@
G_BEGIN_DECLS
-#define ZENITY_UI_FILE_FULLPATH ZENITY_DATADIR "/zenity.ui"
-#define ZENITY_UI_FILE_RELATIVEPATH "./zenity.ui"
+#define ZENITY_UI_RESOURCE_PATH "/org/gnome/Zenity/zenity.ui"
-#define ZENITY_IMAGE_FULLPATH(filename) (ZENITY_DATADIR "/" filename)
+#define ZENITY_IMAGE_FULLPATH(filename) (PACKAGE_DATADIR "/" filename)
GtkBuilder *zenity_util_load_ui_file (const char *widget_root,
...) G_GNUC_NULL_TERMINATED;
diff --git a/src/zenity.gresource.xml b/src/zenity.gresource.xml
new file mode 100644
index 0000000..68efa13
--- /dev/null
+++ b/src/zenity.gresource.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- vim:ts=4 sw=4
+-->
+<!--
+ Copyright © 2021 Logan Rathbone <poprocks@gmail.com>
+
+ Zenity is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ Zenity 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with Zenity; see the file COPYING.
+ If not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+-->
+
+<gresources>
+ <gresource prefix="/org/gnome/Zenity">
+ <file preprocess="xml-stripblanks" compressed="true">zenity.ui</file>
+ </gresource>
+</gresources>
diff --git a/src/zenity.ui b/src/zenity.ui
index e682175..82513a4 100644
--- a/src/zenity.ui
+++ b/src/zenity.ui
@@ -1,6 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
<!-- vim: ts=2 sw=2
-->
-<?xml version="1.0" encoding="UTF-8"?>
+
<interface>
<requires lib="gtk" version="4.0"/>
<object class="GtkAdjustment" id="adjustment1">