summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLogan Rathbone <poprocks@gmail.com>2021-02-12 22:09:36 -0500
committerLogan Rathbone <poprocks@gmail.com>2021-02-12 22:09:36 -0500
commitcbc76d2217ece34bd8da7f1fd2aeb623c9f45f72 (patch)
treea5b6bf48d1d864ffa28262938f42202366155ba7 /src
parent5bcc3b18ca378e0ccf52a0890a7519505d8b5f08 (diff)
downloadzenity-cbc76d2217ece34bd8da7f1fd2aeb623c9f45f72.tar.gz
calendar: make it not crash and use GDateTime.
Diffstat (limited to 'src')
-rw-r--r--src/calendar.c38
-rw-r--r--src/entry.c8
-rw-r--r--src/fileselection.c13
-rw-r--r--src/main.c4
-rw-r--r--src/zenity.ui4
5 files changed, 47 insertions, 20 deletions
diff --git a/src/calendar.c b/src/calendar.c
index 0fb84ed..e8495d1 100644
--- a/src/calendar.c
+++ b/src/calendar.c
@@ -37,8 +37,10 @@ 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)
@@ -57,8 +59,8 @@ zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data)
return;
}
- dialog =
- GTK_WIDGET (gtk_builder_get_object (builder, "zenity_calendar_dialog"));
+ dialog = GTK_WIDGET (gtk_builder_get_object (builder,
+ "zenity_calendar_dialog"));
g_signal_connect (dialog, "response",
G_CALLBACK(zenity_calendar_dialog_response), data);
@@ -96,12 +98,17 @@ zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data)
if (cal_data->day > 0)
{
g_object_set (calendar,
- "day", cal_data->day,
+ "day", cal_data->day - 1,
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);
@@ -141,25 +148,28 @@ static void
zenity_calendar_dialog_output (void)
{
int day, month, year;
- char time_string[128];
- GDate *date = NULL;
+ char *time_string;
+ GDateTime *date;
g_object_get (calendar,
"day", &day,
"month", &month,
"year", &year,
NULL);
- date = g_date_new_dmy (year, month + 1, day);
- g_date_strftime (time_string, 127, zen_cal_data->date_format, date);
+
+ date = g_date_time_new_local (year, month + 1, day + 1,
+ 0, 0, 0);
+
+ time_string = g_date_time_format (date, zen_cal_data->date_format);
g_print ("%s\n", time_string);
- if (date != NULL)
- g_date_free (date);
+ g_date_time_unref (date);
+ g_free (time_string);
}
static void
-zenity_calendar_dialog_response (GtkWidget *widget,
- int response, gpointer data)
+zenity_calendar_dialog_response (GtkWidget *widget, int response,
+ gpointer data)
{
ZenityData *zen_data = data;
@@ -186,11 +196,13 @@ zenity_calendar_dialog_response (GtkWidget *widget,
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
break;
}
- zenity_util_gapp_quit (GTK_WINDOW(widget));
+ 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 (NULL, GTK_RESPONSE_OK, data);
+ zenity_calendar_dialog_response (GTK_WIDGET(cal), GTK_RESPONSE_OK, data);
}
+#endif
diff --git a/src/entry.c b/src/entry.c
index 6451e75..85323e7 100644
--- a/src/entry.c
+++ b/src/entry.c
@@ -33,16 +33,14 @@ static void zenity_entry_dialog_response (GtkWidget *widget,
int response, gpointer data);
static GtkWidget *entry;
-static gint n_entries = 0;
+static int n_entries = 0;
static void
zenity_entry_fill_entries (GSList **entries, const char **args)
{
- int i = 0;
-
- while (args[i] != NULL) {
+ for (int i = 0; args[i] != NULL; ++i)
+ {
*entries = g_slist_append (*entries, (char *)args[i]);
- i++;
}
}
diff --git a/src/fileselection.c b/src/fileselection.c
index 716005b..a44677e 100644
--- a/src/fileselection.c
+++ b/src/fileselection.c
@@ -161,7 +161,12 @@ zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
(GSourceFunc) zenity_util_timeout_handle,
dialog);
}
- zenity_util_gapp_main (GTK_WINDOW(dialog));
+
+ /* Since a native dialog is not a GtkWindow, we can't use our handy
+ * util function.
+ */
+ gtk_native_dialog_show (GTK_NATIVE_DIALOG(dialog));
+ g_application_hold (g_application_get_default ());
}
static void
@@ -218,5 +223,9 @@ zenity_fileselection_dialog_response (GtkDialog *dialog,
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
break;
}
- zenity_util_gapp_quit (GTK_WINDOW(dialog));
+
+ /* Since a native dialog is not a GtkWindow, we can't use our handy
+ * util function.
+ */
+ g_application_release (g_application_get_default ());
}
diff --git a/src/main.c b/src/main.c
index 7a37c05..8a9174b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -54,6 +54,10 @@ activate_cb (GtkApplication *app, gpointer user_data)
break;
case MODE_ENTRY:
+ /* allow for a series of tokens (or even a bash array!) to be
+ * passed as arguments so as to auto-populate the entry with
+ * a list of options as a combo-box.
+ */
results->entry_data->data = (const char **) args->argv + 1;
zenity_entry (results->data, results->entry_data);
break;
diff --git a/src/zenity.ui b/src/zenity.ui
index d7783f5..e682175 100644
--- a/src/zenity.ui
+++ b/src/zenity.ui
@@ -212,6 +212,10 @@
<property name="can_focus">0</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
+ <property name="margin-start">12</property>
+ <property name="margin-end">12</property>
+ <property name="margin-bottom">12</property>
+ <property name="margin-top">12</property>
<child>
<object class="GtkBox" id="vbox3">
<property name="can_focus">0</property>