Fix style
Fixing style in all zenity code, removing useless spaces, empty lines, all code in 80 columns, etc.
This commit is contained in:
parent
8c5e60de83
commit
4eddb202ca
91
src/about.c
91
src/about.c
@ -25,10 +25,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "zenity.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include <string.h>
|
#include "zenity.h"
|
||||||
#include <gdk/gdkkeysyms.h>
|
#include <gdk/gdkkeysyms.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#define GTK_RESPONSE_CREDITS 0
|
#define GTK_RESPONSE_CREDITS 0
|
||||||
#define ZENITY_HELP_PATH ZENITY_DATADIR "/help/"
|
#define ZENITY_HELP_PATH ZENITY_DATADIR "/help/"
|
||||||
@ -39,39 +39,38 @@
|
|||||||
|
|
||||||
static GtkWidget *dialog;
|
static GtkWidget *dialog;
|
||||||
|
|
||||||
static void zenity_about_dialog_response (GtkWidget *widget, int response, gpointer data);
|
static void zenity_about_dialog_response (
|
||||||
|
GtkWidget *widget, int response, gpointer data);
|
||||||
|
|
||||||
/* Sync with the people in the THANKS file */
|
/* Sync with the people in the THANKS file */
|
||||||
static const gchar *const authors[] = {
|
static const gchar *const authors[] = {"Glynn Foster <glynn foster sun com>",
|
||||||
"Glynn Foster <glynn foster sun com>",
|
|
||||||
"Lucas Rocha <lucasr gnome org>",
|
"Lucas Rocha <lucasr gnome org>",
|
||||||
"Mike Newman <mikegtn gnome org>",
|
"Mike Newman <mikegtn gnome org>",
|
||||||
NULL
|
NULL};
|
||||||
};
|
|
||||||
|
|
||||||
static const char *documenters[] = {
|
static const char *documenters[] = {"Glynn Foster <glynn.foster@sun.com>",
|
||||||
"Glynn Foster <glynn.foster@sun.com>",
|
|
||||||
"Lucas Rocha <lucasr@gnome.org>",
|
"Lucas Rocha <lucasr@gnome.org>",
|
||||||
"Java Desktop System Documentation Team",
|
"Java Desktop System Documentation Team",
|
||||||
"GNOME Documentation Project",
|
"GNOME Documentation Project",
|
||||||
NULL
|
NULL};
|
||||||
};
|
|
||||||
|
|
||||||
static gchar *translators;
|
static gchar *translators;
|
||||||
|
|
||||||
static const char *license[] = {
|
static const char *license[] = {
|
||||||
N_("This program is free software; you can redistribute it and/or modify "
|
N_ ("This program is free software; you can redistribute it and/or modify "
|
||||||
"it under the terms of the GNU Lesser General Public License as published by "
|
"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 "
|
"the Free Software Foundation; either version 2 of the License, or "
|
||||||
"(at your option) any later version.\n"),
|
"(at your option) any later version.\n"),
|
||||||
N_("This program is distributed in the hope that it will be useful, "
|
N_ ("This program is distributed in the hope that it will be useful, "
|
||||||
"but WITHOUT ANY WARRANTY; without even the implied warranty of "
|
"but WITHOUT ANY WARRANTY; without even the implied warranty of "
|
||||||
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
|
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
|
||||||
"GNU Lesser General Public License for more details.\n"),
|
"GNU Lesser General Public License for more details.\n"),
|
||||||
N_("You should have received a copy of the GNU Lesser General Public License "
|
N_ ("You should have received a copy of the GNU Lesser General Public "
|
||||||
|
"License "
|
||||||
"along with this program; if not, write to the Free Software "
|
"along with this program; if not, write to the Free Software "
|
||||||
"Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.")
|
"Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA "
|
||||||
};
|
"02110-1301, USA.")};
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
static gint
|
static gint
|
||||||
@ -254,40 +253,53 @@ zenity_zen_wisdom (GtkDialog *dialog, GdkEventKey *event, gpointer user_data)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
zenity_about (ZenityData *data)
|
zenity_about (ZenityData *data) {
|
||||||
{
|
|
||||||
GdkPixbuf *logo;
|
GdkPixbuf *logo;
|
||||||
char *license_trans;
|
char *license_trans;
|
||||||
|
|
||||||
|
translators = _ ("translator-credits");
|
||||||
|
logo =
|
||||||
|
gdk_pixbuf_new_from_file (ZENITY_IMAGE_FULLPATH ("zenity.png"), NULL);
|
||||||
|
|
||||||
translators = _("translator-credits");
|
license_trans = g_strconcat (
|
||||||
logo = gdk_pixbuf_new_from_file (ZENITY_IMAGE_FULLPATH ("zenity.png"), NULL);
|
_ (license[0]), "\n", _ (license[1]), "\n", _ (license[2]), "\n", NULL);
|
||||||
|
|
||||||
license_trans = g_strconcat (_(license[0]), "\n", _(license[1]), "\n",
|
|
||||||
_(license[2]), "\n", NULL);
|
|
||||||
|
|
||||||
dialog = gtk_about_dialog_new ();
|
dialog = gtk_about_dialog_new ();
|
||||||
|
|
||||||
g_object_set (G_OBJECT (dialog),
|
g_object_set (G_OBJECT (dialog),
|
||||||
"name", "Zenity",
|
"name",
|
||||||
"version", VERSION,
|
"Zenity",
|
||||||
"copyright", "Copyright \xc2\xa9 2003 Sun Microsystems",
|
"version",
|
||||||
"comments", _("Display dialog boxes from shell scripts"),
|
VERSION,
|
||||||
"authors", authors,
|
"copyright",
|
||||||
"documenters", documenters,
|
"Copyright \xc2\xa9 2003 Sun Microsystems",
|
||||||
"translator-credits", translators,
|
"comments",
|
||||||
"website", "http://live.gnome.org/Zenity",
|
_ ("Display dialog boxes from shell scripts"),
|
||||||
"logo", logo,
|
"authors",
|
||||||
"wrap-license", TRUE,
|
authors,
|
||||||
"license", license_trans,
|
"documenters",
|
||||||
|
documenters,
|
||||||
|
"translator-credits",
|
||||||
|
translators,
|
||||||
|
"website",
|
||||||
|
"http://live.gnome.org/Zenity",
|
||||||
|
"logo",
|
||||||
|
logo,
|
||||||
|
"wrap-license",
|
||||||
|
TRUE,
|
||||||
|
"license",
|
||||||
|
license_trans,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
g_free (license_trans);
|
g_free (license_trans);
|
||||||
|
|
||||||
zenity_util_set_window_icon (dialog, NULL, ZENITY_IMAGE_FULLPATH ("zenity.png"));
|
zenity_util_set_window_icon (
|
||||||
|
dialog, NULL, ZENITY_IMAGE_FULLPATH ("zenity.png"));
|
||||||
|
|
||||||
g_signal_connect (G_OBJECT (dialog), "response",
|
g_signal_connect (G_OBJECT (dialog),
|
||||||
G_CALLBACK (zenity_about_dialog_response), data);
|
"response",
|
||||||
|
G_CALLBACK (zenity_about_dialog_response),
|
||||||
|
data);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
g_signal_connect (G_OBJECT (dialog), "key_press_event",
|
g_signal_connect (G_OBJECT (dialog), "key_press_event",
|
||||||
@ -299,8 +311,7 @@ zenity_about (ZenityData *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_about_dialog_response (GtkWidget *widget, int response, gpointer data)
|
zenity_about_dialog_response (GtkWidget *widget, int response, gpointer data) {
|
||||||
{
|
|
||||||
ZenityData *zen_data = data;
|
ZenityData *zen_data = data;
|
||||||
|
|
||||||
switch (response) {
|
switch (response) {
|
||||||
|
@ -23,20 +23,19 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <time.h>
|
|
||||||
#include "zenity.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "zenity.h"
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
static GtkWidget *calendar;
|
static GtkWidget *calendar;
|
||||||
static ZenityCalendarData *zen_cal_data;
|
static ZenityCalendarData *zen_cal_data;
|
||||||
|
|
||||||
static void zenity_calendar_dialog_response (GtkWidget *widget, int response, gpointer data);
|
static void zenity_calendar_dialog_response (
|
||||||
|
GtkWidget *widget, int response, gpointer data);
|
||||||
static void zenity_calendar_double_click (GtkCalendar *calendar, gpointer data);
|
static void zenity_calendar_double_click (GtkCalendar *calendar, gpointer data);
|
||||||
|
|
||||||
void
|
void
|
||||||
zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data)
|
zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data) {
|
||||||
{
|
|
||||||
GtkBuilder *builder;
|
GtkBuilder *builder;
|
||||||
GtkWidget *dialog;
|
GtkWidget *dialog;
|
||||||
GtkWidget *button;
|
GtkWidget *button;
|
||||||
@ -53,19 +52,24 @@ zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data)
|
|||||||
|
|
||||||
gtk_builder_connect_signals (builder, NULL);
|
gtk_builder_connect_signals (builder, NULL);
|
||||||
|
|
||||||
dialog = GTK_WIDGET (gtk_builder_get_object (builder,
|
dialog =
|
||||||
"zenity_calendar_dialog"));
|
GTK_WIDGET (gtk_builder_get_object (builder, "zenity_calendar_dialog"));
|
||||||
|
|
||||||
g_signal_connect (G_OBJECT (dialog), "response",
|
g_signal_connect (G_OBJECT (dialog),
|
||||||
G_CALLBACK (zenity_calendar_dialog_response), data);
|
"response",
|
||||||
|
G_CALLBACK (zenity_calendar_dialog_response),
|
||||||
|
data);
|
||||||
|
|
||||||
if (data->dialog_title)
|
if (data->dialog_title)
|
||||||
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
|
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
|
||||||
|
|
||||||
zenity_util_set_window_icon (dialog, data->window_icon, ZENITY_IMAGE_FULLPATH ("zenity-calendar.png"));
|
zenity_util_set_window_icon (dialog,
|
||||||
|
data->window_icon,
|
||||||
|
ZENITY_IMAGE_FULLPATH ("zenity-calendar.png"));
|
||||||
|
|
||||||
if (data->width > -1 || data->height > -1)
|
if (data->width > -1 || data->height > -1)
|
||||||
gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height);
|
gtk_window_set_default_size (
|
||||||
|
GTK_WINDOW (dialog), data->width, data->height);
|
||||||
|
|
||||||
if (data->modal)
|
if (data->modal)
|
||||||
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
||||||
@ -73,40 +77,49 @@ zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data)
|
|||||||
text = gtk_builder_get_object (builder, "zenity_calendar_text");
|
text = gtk_builder_get_object (builder, "zenity_calendar_text");
|
||||||
|
|
||||||
if (cal_data->dialog_text)
|
if (cal_data->dialog_text)
|
||||||
gtk_label_set_markup (GTK_LABEL (text), g_strcompress (cal_data->dialog_text));
|
gtk_label_set_markup (
|
||||||
|
GTK_LABEL (text), g_strcompress (cal_data->dialog_text));
|
||||||
|
|
||||||
calendar = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_calendar"));
|
calendar = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_calendar"));
|
||||||
|
|
||||||
if (cal_data->month > 0 || cal_data->year > 0)
|
if (cal_data->month > 0 || cal_data->year > 0)
|
||||||
gtk_calendar_select_month (GTK_CALENDAR (calendar), cal_data->month - 1, cal_data->year);
|
gtk_calendar_select_month (
|
||||||
|
GTK_CALENDAR (calendar), cal_data->month - 1, cal_data->year);
|
||||||
if (cal_data->day > 0)
|
if (cal_data->day > 0)
|
||||||
gtk_calendar_select_day (GTK_CALENDAR (calendar), cal_data->day);
|
gtk_calendar_select_day (GTK_CALENDAR (calendar), cal_data->day);
|
||||||
|
|
||||||
g_signal_connect (calendar, "day-selected-double-click",
|
g_signal_connect (calendar,
|
||||||
G_CALLBACK (zenity_calendar_double_click), data);
|
"day-selected-double-click",
|
||||||
|
G_CALLBACK (zenity_calendar_double_click),
|
||||||
|
data);
|
||||||
|
|
||||||
gtk_label_set_mnemonic_widget (GTK_LABEL (text), calendar);
|
gtk_label_set_mnemonic_widget (GTK_LABEL (text), calendar);
|
||||||
zenity_util_show_dialog (dialog, data->attach);
|
zenity_util_show_dialog (dialog, data->attach);
|
||||||
|
|
||||||
if (data->timeout_delay > 0) {
|
if (data->timeout_delay > 0) {
|
||||||
g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, dialog);
|
g_timeout_add_seconds (data->timeout_delay,
|
||||||
|
(GSourceFunc) zenity_util_timeout_handle,
|
||||||
|
dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->extra_label) {
|
if (data->extra_label) {
|
||||||
gint i=0;
|
gint i = 0;
|
||||||
while(data->extra_label[i]!=NULL){
|
while (data->extra_label[i] != NULL) {
|
||||||
gtk_dialog_add_button (GTK_DIALOG (dialog), data->extra_label[i], i);
|
gtk_dialog_add_button (
|
||||||
|
GTK_DIALOG (dialog), data->extra_label[i], i);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->ok_label) {
|
if (data->ok_label) {
|
||||||
button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_calendar_ok_button"));
|
button = GTK_WIDGET (
|
||||||
|
gtk_builder_get_object (builder, "zenity_calendar_ok_button"));
|
||||||
gtk_button_set_label (GTK_BUTTON (button), data->ok_label);
|
gtk_button_set_label (GTK_BUTTON (button), data->ok_label);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->cancel_label) {
|
if (data->cancel_label) {
|
||||||
button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_calendar_cancel_button"));
|
button = GTK_WIDGET (
|
||||||
|
gtk_builder_get_object (builder, "zenity_calendar_cancel_button"));
|
||||||
gtk_button_set_label (GTK_BUTTON (button), data->cancel_label);
|
gtk_button_set_label (GTK_BUTTON (button), data->cancel_label);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,8 +128,7 @@ zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data)
|
|||||||
gtk_main ();
|
gtk_main ();
|
||||||
}
|
}
|
||||||
static void
|
static void
|
||||||
zenity_calendar_dialog_output (void)
|
zenity_calendar_dialog_output (void) {
|
||||||
{
|
|
||||||
guint day, month, year;
|
guint day, month, year;
|
||||||
gchar time_string[128];
|
gchar time_string[128];
|
||||||
GDate *date = NULL;
|
GDate *date = NULL;
|
||||||
@ -131,8 +143,8 @@ zenity_calendar_dialog_output (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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;
|
ZenityData *zen_data;
|
||||||
|
|
||||||
zen_data = data;
|
zen_data = data;
|
||||||
@ -153,8 +165,9 @@ zenity_calendar_dialog_response (GtkWidget *widget, int response, gpointer data)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (zen_data->extra_label && response < g_strv_length(zen_data->extra_label))
|
if (zen_data->extra_label &&
|
||||||
printf("%s\n",zen_data->extra_label[response]);
|
response < g_strv_length (zen_data->extra_label))
|
||||||
|
printf ("%s\n", zen_data->extra_label[response]);
|
||||||
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -162,7 +175,6 @@ zenity_calendar_dialog_response (GtkWidget *widget, int response, gpointer data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_calendar_double_click (GtkCalendar *cal, gpointer data)
|
zenity_calendar_double_click (GtkCalendar *cal, gpointer data) {
|
||||||
{
|
|
||||||
zenity_calendar_dialog_response (NULL, GTK_RESPONSE_OK, data);
|
zenity_calendar_dialog_response (NULL, GTK_RESPONSE_OK, data);
|
||||||
}
|
}
|
||||||
|
34
src/color.c
34
src/color.c
@ -23,16 +23,17 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include "zenity.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "zenity.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
static ZenityData *zen_data;
|
static ZenityData *zen_data;
|
||||||
|
|
||||||
static void zenity_colorselection_dialog_response (GtkWidget *widget, int response, gpointer data);
|
static void zenity_colorselection_dialog_response (
|
||||||
|
GtkWidget *widget, int response, gpointer data);
|
||||||
|
|
||||||
void zenity_colorselection (ZenityData *data, ZenityColorData *color_data)
|
void
|
||||||
{
|
zenity_colorselection (ZenityData *data, ZenityColorData *color_data) {
|
||||||
GtkWidget *dialog;
|
GtkWidget *dialog;
|
||||||
GtkWidget *button;
|
GtkWidget *button;
|
||||||
GdkRGBA color;
|
GdkRGBA color;
|
||||||
@ -41,7 +42,8 @@ void zenity_colorselection (ZenityData *data, ZenityColorData *color_data)
|
|||||||
|
|
||||||
dialog = gtk_color_chooser_dialog_new (data->dialog_title, NULL);
|
dialog = gtk_color_chooser_dialog_new (data->dialog_title, NULL);
|
||||||
|
|
||||||
g_signal_connect (G_OBJECT (dialog), "response",
|
g_signal_connect (G_OBJECT (dialog),
|
||||||
|
"response",
|
||||||
G_CALLBACK (zenity_colorselection_dialog_response),
|
G_CALLBACK (zenity_colorselection_dialog_response),
|
||||||
color_data);
|
color_data);
|
||||||
|
|
||||||
@ -52,9 +54,10 @@ void zenity_colorselection (ZenityData *data, ZenityColorData *color_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data->extra_label) {
|
if (data->extra_label) {
|
||||||
gint i=0;
|
gint i = 0;
|
||||||
while(data->extra_label[i]!=NULL){
|
while (data->extra_label[i] != NULL) {
|
||||||
gtk_dialog_add_button (GTK_DIALOG (dialog), data->extra_label[i], i);
|
gtk_dialog_add_button (
|
||||||
|
GTK_DIALOG (dialog), data->extra_label[i], i);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,17 +87,17 @@ void zenity_colorselection (ZenityData *data, ZenityColorData *color_data)
|
|||||||
dialog);
|
dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_main();
|
gtk_main ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_colorselection_dialog_response (GtkWidget *widget, int response, gpointer data)
|
zenity_colorselection_dialog_response (
|
||||||
{
|
GtkWidget *widget, int response, gpointer data) {
|
||||||
GdkRGBA color;
|
GdkRGBA color;
|
||||||
|
|
||||||
switch (response) {
|
switch (response) {
|
||||||
case GTK_RESPONSE_OK:
|
case GTK_RESPONSE_OK:
|
||||||
zenity_util_exit_code_with_data(ZENITY_OK, zen_data);
|
zenity_util_exit_code_with_data (ZENITY_OK, zen_data);
|
||||||
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (widget), &color);
|
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (widget), &color);
|
||||||
g_print ("%s\n", gdk_rgba_to_string (&color));
|
g_print ("%s\n", gdk_rgba_to_string (&color));
|
||||||
break;
|
break;
|
||||||
@ -104,8 +107,9 @@ zenity_colorselection_dialog_response (GtkWidget *widget, int response, gpointer
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (zen_data->extra_label && response < g_strv_length(zen_data->extra_label))
|
if (zen_data->extra_label &&
|
||||||
printf("%s\n",zen_data->extra_label[response]);
|
response < g_strv_length (zen_data->extra_label))
|
||||||
|
printf ("%s\n", zen_data->extra_label[response]);
|
||||||
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
78
src/entry.c
78
src/entry.c
@ -23,17 +23,17 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "zenity.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "zenity.h"
|
||||||
|
|
||||||
static void zenity_entry_dialog_response (GtkWidget *widget, int response, gpointer data);
|
static void zenity_entry_dialog_response (
|
||||||
|
GtkWidget *widget, int response, gpointer data);
|
||||||
|
|
||||||
static GtkWidget *entry;
|
static GtkWidget *entry;
|
||||||
static gint n_entries = 0;
|
static gint n_entries = 0;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_entry_fill_entries (GSList **entries, const gchar **args)
|
zenity_entry_fill_entries (GSList **entries, const gchar **args) {
|
||||||
{
|
|
||||||
gint i = 0;
|
gint i = 0;
|
||||||
|
|
||||||
while (args[i] != NULL) {
|
while (args[i] != NULL) {
|
||||||
@ -43,14 +43,12 @@ zenity_entry_fill_entries (GSList **entries, const gchar **args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_entry_combo_activate_default (GtkEntry *entry, gpointer window)
|
zenity_entry_combo_activate_default (GtkEntry *entry, gpointer window) {
|
||||||
{
|
|
||||||
gtk_window_activate_default (GTK_WINDOW (window));
|
gtk_window_activate_default (GTK_WINDOW (window));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
zenity_entry (ZenityData *data, ZenityEntryData *entry_data)
|
zenity_entry (ZenityData *data, ZenityEntryData *entry_data) {
|
||||||
{
|
|
||||||
GtkBuilder *builder = NULL;
|
GtkBuilder *builder = NULL;
|
||||||
GtkWidget *dialog;
|
GtkWidget *dialog;
|
||||||
GtkWidget *button;
|
GtkWidget *button;
|
||||||
@ -68,48 +66,57 @@ zenity_entry (ZenityData *data, ZenityEntryData *entry_data)
|
|||||||
|
|
||||||
gtk_builder_connect_signals (builder, NULL);
|
gtk_builder_connect_signals (builder, NULL);
|
||||||
|
|
||||||
dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_entry_dialog"));
|
dialog =
|
||||||
|
GTK_WIDGET (gtk_builder_get_object (builder, "zenity_entry_dialog"));
|
||||||
|
|
||||||
g_signal_connect (G_OBJECT (dialog), "response",
|
g_signal_connect (G_OBJECT (dialog),
|
||||||
G_CALLBACK (zenity_entry_dialog_response), data);
|
"response",
|
||||||
|
G_CALLBACK (zenity_entry_dialog_response),
|
||||||
|
data);
|
||||||
|
|
||||||
if (data->dialog_title)
|
if (data->dialog_title)
|
||||||
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
|
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
|
||||||
|
|
||||||
zenity_util_set_window_icon (dialog, data->window_icon, ZENITY_IMAGE_FULLPATH ("zenity-entry.png"));
|
zenity_util_set_window_icon (
|
||||||
|
dialog, data->window_icon, ZENITY_IMAGE_FULLPATH ("zenity-entry.png"));
|
||||||
|
|
||||||
if (data->width > -1 || data->height > -1)
|
if (data->width > -1 || data->height > -1)
|
||||||
gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height);
|
gtk_window_set_default_size (
|
||||||
|
GTK_WINDOW (dialog), data->width, data->height);
|
||||||
|
|
||||||
if (data->modal)
|
if (data->modal)
|
||||||
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
||||||
|
|
||||||
if (data->extra_label) {
|
if (data->extra_label) {
|
||||||
gint i=0;
|
gint i = 0;
|
||||||
while(data->extra_label[i]!=NULL){
|
while (data->extra_label[i] != NULL) {
|
||||||
gtk_dialog_add_button (GTK_DIALOG (dialog), data->extra_label[i], i);
|
gtk_dialog_add_button (
|
||||||
|
GTK_DIALOG (dialog), data->extra_label[i], i);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->ok_label) {
|
if (data->ok_label) {
|
||||||
button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_entry_ok_button"));
|
button = GTK_WIDGET (
|
||||||
|
gtk_builder_get_object (builder, "zenity_entry_ok_button"));
|
||||||
gtk_button_set_label (GTK_BUTTON (button), data->ok_label);
|
gtk_button_set_label (GTK_BUTTON (button), data->ok_label);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->cancel_label) {
|
if (data->cancel_label) {
|
||||||
button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_entry_cancel_button"));
|
button = GTK_WIDGET (
|
||||||
|
gtk_builder_get_object (builder, "zenity_entry_cancel_button"));
|
||||||
gtk_button_set_label (GTK_BUTTON (button), data->cancel_label);
|
gtk_button_set_label (GTK_BUTTON (button), data->cancel_label);
|
||||||
}
|
}
|
||||||
|
|
||||||
text = gtk_builder_get_object (builder, "zenity_entry_text");
|
text = gtk_builder_get_object (builder, "zenity_entry_text");
|
||||||
|
|
||||||
if (entry_data->dialog_text)
|
if (entry_data->dialog_text)
|
||||||
gtk_label_set_text_with_mnemonic (GTK_LABEL (text), g_strcompress (entry_data->dialog_text));
|
gtk_label_set_text_with_mnemonic (
|
||||||
|
GTK_LABEL (text), g_strcompress (entry_data->dialog_text));
|
||||||
|
|
||||||
vbox = gtk_builder_get_object (builder, "vbox4");
|
vbox = gtk_builder_get_object (builder, "vbox4");
|
||||||
|
|
||||||
zenity_entry_fill_entries(&entries, entry_data->data);
|
zenity_entry_fill_entries (&entries, entry_data->data);
|
||||||
|
|
||||||
n_entries = g_slist_length (entries);
|
n_entries = g_slist_length (entries);
|
||||||
|
|
||||||
@ -117,19 +124,22 @@ zenity_entry (ZenityData *data, ZenityEntryData *entry_data)
|
|||||||
entry = gtk_combo_box_text_new_with_entry ();
|
entry = gtk_combo_box_text_new_with_entry ();
|
||||||
|
|
||||||
for (tmp = entries; tmp; tmp = tmp->next) {
|
for (tmp = entries; tmp; tmp = tmp->next) {
|
||||||
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (entry), tmp->data);
|
gtk_combo_box_text_append_text (
|
||||||
|
GTK_COMBO_BOX_TEXT (entry), tmp->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entry_data->entry_text) {
|
if (entry_data->entry_text) {
|
||||||
gtk_combo_box_text_prepend_text (GTK_COMBO_BOX_TEXT (entry), entry_data->entry_text);
|
gtk_combo_box_text_prepend_text (
|
||||||
|
GTK_COMBO_BOX_TEXT (entry), entry_data->entry_text);
|
||||||
gtk_combo_box_set_active (GTK_COMBO_BOX (entry), 0);
|
gtk_combo_box_set_active (GTK_COMBO_BOX (entry), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_signal_connect (gtk_bin_get_child (GTK_BIN (entry)), "activate",
|
g_signal_connect (gtk_bin_get_child (GTK_BIN (entry)),
|
||||||
|
"activate",
|
||||||
G_CALLBACK (zenity_entry_combo_activate_default),
|
G_CALLBACK (zenity_entry_combo_activate_default),
|
||||||
GTK_WINDOW (dialog));
|
GTK_WINDOW (dialog));
|
||||||
} else {
|
} else {
|
||||||
entry = gtk_entry_new();
|
entry = gtk_entry_new ();
|
||||||
|
|
||||||
gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
|
gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
|
||||||
|
|
||||||
@ -150,16 +160,17 @@ zenity_entry (ZenityData *data, ZenityEntryData *entry_data)
|
|||||||
|
|
||||||
zenity_util_show_dialog (dialog, data->attach);
|
zenity_util_show_dialog (dialog, data->attach);
|
||||||
|
|
||||||
if(data->timeout_delay > 0) {
|
if (data->timeout_delay > 0) {
|
||||||
g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, dialog);
|
g_timeout_add_seconds (data->timeout_delay,
|
||||||
|
(GSourceFunc) zenity_util_timeout_handle,
|
||||||
|
dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_main ();
|
gtk_main ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_entry_dialog_output (void)
|
zenity_entry_dialog_output (void) {
|
||||||
{
|
|
||||||
const gchar *text;
|
const gchar *text;
|
||||||
if (n_entries > 1)
|
if (n_entries > 1)
|
||||||
text = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (entry));
|
text = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (entry));
|
||||||
@ -168,18 +179,16 @@ zenity_entry_dialog_output (void)
|
|||||||
|
|
||||||
if (text != NULL)
|
if (text != NULL)
|
||||||
g_print ("%s\n", text);
|
g_print ("%s\n", text);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_entry_dialog_response (GtkWidget *widget, int response, gpointer data)
|
zenity_entry_dialog_response (GtkWidget *widget, int response, gpointer data) {
|
||||||
{
|
|
||||||
ZenityData *zen_data = data;
|
ZenityData *zen_data = data;
|
||||||
|
|
||||||
switch (response) {
|
switch (response) {
|
||||||
case GTK_RESPONSE_OK:
|
case GTK_RESPONSE_OK:
|
||||||
zenity_entry_dialog_output ();
|
zenity_entry_dialog_output ();
|
||||||
zenity_util_exit_code_with_data(ZENITY_OK, zen_data);
|
zenity_util_exit_code_with_data (ZENITY_OK, zen_data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GTK_RESPONSE_CANCEL:
|
case GTK_RESPONSE_CANCEL:
|
||||||
@ -192,8 +201,9 @@ zenity_entry_dialog_response (GtkWidget *widget, int response, gpointer data)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (zen_data->extra_label && response < g_strv_length(zen_data->extra_label))
|
if (zen_data->extra_label &&
|
||||||
printf("%s\n",zen_data->extra_label[response]);
|
response < g_strv_length (zen_data->extra_label))
|
||||||
|
printf ("%s\n", zen_data->extra_label[response]);
|
||||||
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -23,16 +23,17 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include "zenity.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "zenity.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
static ZenityData *zen_data;
|
static ZenityData *zen_data;
|
||||||
|
|
||||||
static void zenity_fileselection_dialog_response (GtkWidget *widget, int response, gpointer data);
|
static void zenity_fileselection_dialog_response (
|
||||||
|
GtkWidget *widget, int response, gpointer data);
|
||||||
|
|
||||||
void zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
|
void
|
||||||
{
|
zenity_fileselection (ZenityData *data, ZenityFileData *file_data) {
|
||||||
GtkWidget *dialog;
|
GtkWidget *dialog;
|
||||||
gchar *dir;
|
gchar *dir;
|
||||||
gchar *basename;
|
gchar *basename;
|
||||||
@ -50,22 +51,28 @@ void zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
|
|||||||
action = GTK_FILE_CHOOSER_ACTION_SAVE;
|
action = GTK_FILE_CHOOSER_ACTION_SAVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
dialog = gtk_file_chooser_dialog_new (NULL, NULL,
|
dialog = gtk_file_chooser_dialog_new (NULL,
|
||||||
|
NULL,
|
||||||
action,
|
action,
|
||||||
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
_ ("_Cancel"),
|
||||||
_("_OK"), GTK_RESPONSE_OK,
|
GTK_RESPONSE_CANCEL,
|
||||||
|
_ ("_OK"),
|
||||||
|
GTK_RESPONSE_OK,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
|
gtk_file_chooser_set_do_overwrite_confirmation (
|
||||||
file_data->confirm_overwrite);
|
GTK_FILE_CHOOSER (dialog), file_data->confirm_overwrite);
|
||||||
|
|
||||||
g_signal_connect (G_OBJECT (dialog), "response",
|
g_signal_connect (G_OBJECT (dialog),
|
||||||
G_CALLBACK (zenity_fileselection_dialog_response), file_data);
|
"response",
|
||||||
|
G_CALLBACK (zenity_fileselection_dialog_response),
|
||||||
|
file_data);
|
||||||
|
|
||||||
if (data->extra_label) {
|
if (data->extra_label) {
|
||||||
gint i=0;
|
gint i = 0;
|
||||||
while(data->extra_label[i]!=NULL){
|
while (data->extra_label[i] != NULL) {
|
||||||
gtk_dialog_add_button (GTK_DIALOG (dialog), data->extra_label[i], i);
|
gtk_dialog_add_button (
|
||||||
|
GTK_DIALOG (dialog), data->extra_label[i], i);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,7 +80,8 @@ void zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
|
|||||||
if (data->dialog_title)
|
if (data->dialog_title)
|
||||||
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
|
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
|
||||||
|
|
||||||
zenity_util_set_window_icon (dialog, data->window_icon, ZENITY_IMAGE_FULLPATH ("zenity-file.png"));
|
zenity_util_set_window_icon (
|
||||||
|
dialog, data->window_icon, ZENITY_IMAGE_FULLPATH ("zenity-file.png"));
|
||||||
|
|
||||||
if (data->modal)
|
if (data->modal)
|
||||||
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
||||||
@ -82,14 +90,17 @@ void zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
|
|||||||
dir = g_path_get_dirname (file_data->uri);
|
dir = g_path_get_dirname (file_data->uri);
|
||||||
|
|
||||||
if (g_path_is_absolute (file_data->uri) == TRUE)
|
if (g_path_is_absolute (file_data->uri) == TRUE)
|
||||||
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), dir);
|
gtk_file_chooser_set_current_folder (
|
||||||
|
GTK_FILE_CHOOSER (dialog), dir);
|
||||||
|
|
||||||
if (file_data->uri[strlen (file_data->uri) - 1] != '/') {
|
if (file_data->uri[strlen (file_data->uri) - 1] != '/') {
|
||||||
basename = g_path_get_basename (file_data->uri);
|
basename = g_path_get_basename (file_data->uri);
|
||||||
if (file_data->save)
|
if (file_data->save)
|
||||||
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), basename);
|
gtk_file_chooser_set_current_name (
|
||||||
|
GTK_FILE_CHOOSER (dialog), basename);
|
||||||
else
|
else
|
||||||
(void) gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), file_data->uri);
|
(void) gtk_file_chooser_set_filename (
|
||||||
|
GTK_FILE_CHOOSER (dialog), file_data->uri);
|
||||||
g_free (basename);
|
g_free (basename);
|
||||||
}
|
}
|
||||||
g_free (dir);
|
g_free (dir);
|
||||||
@ -102,9 +113,9 @@ void zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
|
|||||||
/* Filter format: Executables | *.exe *.bat *.com */
|
/* Filter format: Executables | *.exe *.bat *.com */
|
||||||
gint filter_i;
|
gint filter_i;
|
||||||
|
|
||||||
for (filter_i = 0; file_data->filter [filter_i]; filter_i++) {
|
for (filter_i = 0; file_data->filter[filter_i]; filter_i++) {
|
||||||
GtkFileFilter *filter = gtk_file_filter_new();
|
GtkFileFilter *filter = gtk_file_filter_new ();
|
||||||
gchar *filter_str = file_data->filter [filter_i];
|
gchar *filter_str = file_data->filter[filter_i];
|
||||||
gchar **pattern, **patterns;
|
gchar **pattern, **patterns;
|
||||||
gchar *name = NULL;
|
gchar *name = NULL;
|
||||||
gint i;
|
gint i;
|
||||||
@ -123,7 +134,8 @@ void zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
|
|||||||
gtk_file_filter_set_name (filter, name);
|
gtk_file_filter_set_name (filter, name);
|
||||||
|
|
||||||
/* Point i to the right position for split */
|
/* Point i to the right position for split */
|
||||||
for (++i; filter_str[i] == ' '; i++);
|
for (++i; filter_str[i] == ' '; i++)
|
||||||
|
;
|
||||||
} else {
|
} else {
|
||||||
gtk_file_filter_set_name (filter, filter_str);
|
gtk_file_filter_set_name (filter, filter_str);
|
||||||
i = 0;
|
i = 0;
|
||||||
@ -146,37 +158,40 @@ void zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
|
|||||||
|
|
||||||
zenity_util_show_dialog (dialog, data->attach);
|
zenity_util_show_dialog (dialog, data->attach);
|
||||||
|
|
||||||
if(data->timeout_delay > 0) {
|
if (data->timeout_delay > 0) {
|
||||||
g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, dialog);
|
g_timeout_add_seconds (data->timeout_delay,
|
||||||
|
(GSourceFunc) zenity_util_timeout_handle,
|
||||||
|
dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_main ();
|
gtk_main ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_fileselection_dialog_output (GtkWidget *widget, ZenityFileData *file_data)
|
zenity_fileselection_dialog_output (
|
||||||
{
|
GtkWidget *widget, ZenityFileData *file_data) {
|
||||||
GSList *selections, *iter;
|
GSList *selections, *iter;
|
||||||
selections = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER (widget));
|
selections = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER (widget));
|
||||||
for (iter = selections;iter != NULL; iter = iter->next) {
|
for (iter = selections; iter != NULL; iter = iter->next) {
|
||||||
g_print ("%s", g_filename_to_utf8 ((gchar*)iter->data, -1, NULL, NULL, NULL));
|
g_print ("%s",
|
||||||
|
g_filename_to_utf8 ((gchar *) iter->data, -1, NULL, NULL, NULL));
|
||||||
g_free (iter->data);
|
g_free (iter->data);
|
||||||
if (iter->next != NULL)
|
if (iter->next != NULL)
|
||||||
g_print ("%s",file_data->separator);
|
g_print ("%s", file_data->separator);
|
||||||
}
|
}
|
||||||
g_print("\n");
|
g_print ("\n");
|
||||||
g_slist_free(selections);
|
g_slist_free (selections);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_fileselection_dialog_response (GtkWidget *widget, int response, gpointer data)
|
zenity_fileselection_dialog_response (
|
||||||
{
|
GtkWidget *widget, int response, gpointer data) {
|
||||||
ZenityFileData *file_data = data;
|
ZenityFileData *file_data = data;
|
||||||
|
|
||||||
switch (response) {
|
switch (response) {
|
||||||
case GTK_RESPONSE_OK:
|
case GTK_RESPONSE_OK:
|
||||||
zenity_fileselection_dialog_output (widget, file_data);
|
zenity_fileselection_dialog_output (widget, file_data);
|
||||||
zenity_util_exit_code_with_data(ZENITY_OK, zen_data);
|
zenity_util_exit_code_with_data (ZENITY_OK, zen_data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GTK_RESPONSE_CANCEL:
|
case GTK_RESPONSE_CANCEL:
|
||||||
@ -189,8 +204,9 @@ zenity_fileselection_dialog_response (GtkWidget *widget, int response, gpointer
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (zen_data->extra_label && response < g_strv_length(zen_data->extra_label))
|
if (zen_data->extra_label &&
|
||||||
printf("%s\n",zen_data->extra_label[response]);
|
response < g_strv_length (zen_data->extra_label))
|
||||||
|
printf ("%s\n", zen_data->extra_label[response]);
|
||||||
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
182
src/forms.c
182
src/forms.c
@ -22,19 +22,23 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <string.h>
|
|
||||||
#include "zenity.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "zenity.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
static ZenityData *zen_data;
|
static ZenityData *zen_data;
|
||||||
static GSList *selected;
|
static GSList *selected;
|
||||||
static void zenity_forms_dialog_response (GtkWidget *widget, int response, gpointer data);
|
static void zenity_forms_dialog_response (
|
||||||
|
GtkWidget *widget, int response, gpointer data);
|
||||||
|
|
||||||
static void zenity_forms_dialog_get_selected (GtkTreeModel *model, GtkTreePath *path_buf, GtkTreeIter *iter, GtkTreeView *tree_view)
|
static void
|
||||||
{
|
zenity_forms_dialog_get_selected (GtkTreeModel *model, GtkTreePath *path_buf,
|
||||||
|
GtkTreeIter *iter, GtkTreeView *tree_view) {
|
||||||
gint n_columns = 0;
|
gint n_columns = 0;
|
||||||
gint i = 0;
|
gint i = 0;
|
||||||
GValue value = {0, };
|
GValue value = {
|
||||||
|
0,
|
||||||
|
};
|
||||||
|
|
||||||
n_columns = gtk_tree_model_get_n_columns (model);
|
n_columns = gtk_tree_model_get_n_columns (model);
|
||||||
for (i = 0; i < n_columns; i++) {
|
for (i = 0; i < n_columns; i++) {
|
||||||
@ -45,8 +49,8 @@ static void zenity_forms_dialog_get_selected (GtkTreeModel *model, GtkTreePath *
|
|||||||
}
|
}
|
||||||
|
|
||||||
static GtkWidget *
|
static GtkWidget *
|
||||||
zenity_forms_create_and_fill_combo (ZenityFormsData *forms_data, int combo_number)
|
zenity_forms_create_and_fill_combo (
|
||||||
{
|
ZenityFormsData *forms_data, int combo_number) {
|
||||||
GtkListStore *list_store;
|
GtkListStore *list_store;
|
||||||
GtkWidget *combo_box;
|
GtkWidget *combo_box;
|
||||||
GtkCellRenderer *renderer;
|
GtkCellRenderer *renderer;
|
||||||
@ -55,7 +59,8 @@ zenity_forms_create_and_fill_combo (ZenityFormsData *forms_data, int combo_numbe
|
|||||||
list_store = gtk_list_store_new (1, G_TYPE_STRING);
|
list_store = gtk_list_store_new (1, G_TYPE_STRING);
|
||||||
|
|
||||||
if (forms_data->combo_values) {
|
if (forms_data->combo_values) {
|
||||||
combo_values = g_slist_nth_data (forms_data->combo_values, combo_number);
|
combo_values =
|
||||||
|
g_slist_nth_data (forms_data->combo_values, combo_number);
|
||||||
if (combo_values) {
|
if (combo_values) {
|
||||||
gchar **row_values = g_strsplit_set (combo_values, "|", -1);
|
gchar **row_values = g_strsplit_set (combo_values, "|", -1);
|
||||||
if (row_values) {
|
if (row_values) {
|
||||||
@ -79,15 +84,15 @@ zenity_forms_create_and_fill_combo (ZenityFormsData *forms_data, int combo_numbe
|
|||||||
|
|
||||||
renderer = gtk_cell_renderer_text_new ();
|
renderer = gtk_cell_renderer_text_new ();
|
||||||
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, TRUE);
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, TRUE);
|
||||||
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer, "text", 0, NULL);
|
gtk_cell_layout_set_attributes (
|
||||||
|
GTK_CELL_LAYOUT (combo_box), renderer, "text", 0, NULL);
|
||||||
|
|
||||||
return combo_box;
|
return combo_box;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GtkWidget *
|
static GtkWidget *
|
||||||
zenity_forms_create_and_fill_list (ZenityFormsData *forms_data,
|
zenity_forms_create_and_fill_list (
|
||||||
int list_number, gchar *header)
|
ZenityFormsData *forms_data, int list_number, gchar *header) {
|
||||||
{
|
|
||||||
GtkListStore *list_store;
|
GtkListStore *list_store;
|
||||||
GtkWidget *tree_view;
|
GtkWidget *tree_view;
|
||||||
GtkWidget *scrolled_window;
|
GtkWidget *scrolled_window;
|
||||||
@ -105,7 +110,8 @@ zenity_forms_create_and_fill_list (ZenityFormsData *forms_data,
|
|||||||
tree_view = gtk_tree_view_new ();
|
tree_view = gtk_tree_view_new ();
|
||||||
|
|
||||||
if (forms_data->column_values) {
|
if (forms_data->column_values) {
|
||||||
column_values = g_slist_nth_data (forms_data->column_values, list_number);
|
column_values =
|
||||||
|
g_slist_nth_data (forms_data->column_values, list_number);
|
||||||
if (column_values) {
|
if (column_values) {
|
||||||
gchar **values = g_strsplit_set (column_values, "|", -1);
|
gchar **values = g_strsplit_set (column_values, "|", -1);
|
||||||
if (values) {
|
if (values) {
|
||||||
@ -117,11 +123,10 @@ zenity_forms_create_and_fill_list (ZenityFormsData *forms_data,
|
|||||||
for (i = 0; i < n_columns; i++) {
|
for (i = 0; i < n_columns; i++) {
|
||||||
gchar *column_name = values[i];
|
gchar *column_name = values[i];
|
||||||
renderer = gtk_cell_renderer_text_new ();
|
renderer = gtk_cell_renderer_text_new ();
|
||||||
column = gtk_tree_view_column_new_with_attributes (column_name,
|
column = gtk_tree_view_column_new_with_attributes (
|
||||||
renderer,
|
column_name, renderer, "text", column_index, NULL);
|
||||||
"text", column_index,
|
gtk_tree_view_append_column (
|
||||||
NULL);
|
GTK_TREE_VIEW (tree_view), column);
|
||||||
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
|
|
||||||
column_index++;
|
column_index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -157,20 +162,23 @@ zenity_forms_create_and_fill_list (ZenityFormsData *forms_data,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL (list_store));
|
gtk_tree_view_set_model (
|
||||||
|
GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL (list_store));
|
||||||
g_object_unref (list_store);
|
g_object_unref (list_store);
|
||||||
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
||||||
//gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window),
|
// gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW
|
||||||
|
// (scrolled_window),
|
||||||
// GTK_WIDGET (tree_view));
|
// GTK_WIDGET (tree_view));
|
||||||
gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (tree_view));
|
gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (tree_view));
|
||||||
gtk_widget_set_size_request (GTK_WIDGET (scrolled_window), -1, 100);
|
gtk_widget_set_size_request (GTK_WIDGET (scrolled_window), -1, 100);
|
||||||
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), forms_data->show_header);
|
gtk_tree_view_set_headers_visible (
|
||||||
|
GTK_TREE_VIEW (tree_view), forms_data->show_header);
|
||||||
|
|
||||||
return scrolled_window;
|
return scrolled_window;
|
||||||
}
|
}
|
||||||
|
|
||||||
void zenity_forms_dialog (ZenityData *data, ZenityFormsData *forms_data)
|
void
|
||||||
{
|
zenity_forms_dialog (ZenityData *data, ZenityFormsData *forms_data) {
|
||||||
GtkBuilder *builder = NULL;
|
GtkBuilder *builder = NULL;
|
||||||
GtkWidget *dialog;
|
GtkWidget *dialog;
|
||||||
GtkWidget *grid;
|
GtkWidget *grid;
|
||||||
@ -185,48 +193,56 @@ void zenity_forms_dialog (ZenityData *data, ZenityFormsData *forms_data)
|
|||||||
|
|
||||||
zen_data = data;
|
zen_data = data;
|
||||||
|
|
||||||
builder = zenity_util_load_ui_file("zenity_forms_dialog", NULL);
|
builder = zenity_util_load_ui_file ("zenity_forms_dialog", NULL);
|
||||||
|
|
||||||
if (builder == NULL) {
|
if (builder == NULL) {
|
||||||
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
|
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_builder_connect_signals(builder, NULL);
|
gtk_builder_connect_signals (builder, NULL);
|
||||||
|
|
||||||
dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_forms_dialog"));
|
dialog =
|
||||||
|
GTK_WIDGET (gtk_builder_get_object (builder, "zenity_forms_dialog"));
|
||||||
|
|
||||||
g_signal_connect (G_OBJECT(dialog), "response",
|
g_signal_connect (G_OBJECT (dialog),
|
||||||
G_CALLBACK (zenity_forms_dialog_response), forms_data);
|
"response",
|
||||||
|
G_CALLBACK (zenity_forms_dialog_response),
|
||||||
|
forms_data);
|
||||||
|
|
||||||
if (data->dialog_title)
|
if (data->dialog_title)
|
||||||
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
|
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
|
||||||
|
|
||||||
if (data->width > -1 || data->height > -1)
|
if (data->width > -1 || data->height > -1)
|
||||||
gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height);
|
gtk_window_set_default_size (
|
||||||
|
GTK_WINDOW (dialog), data->width, data->height);
|
||||||
|
|
||||||
if (data->extra_label) {
|
if (data->extra_label) {
|
||||||
gint i=0;
|
gint i = 0;
|
||||||
while(data->extra_label[i]!=NULL){
|
while (data->extra_label[i] != NULL) {
|
||||||
gtk_dialog_add_button (GTK_DIALOG (dialog), data->extra_label[i], i);
|
gtk_dialog_add_button (
|
||||||
|
GTK_DIALOG (dialog), data->extra_label[i], i);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->ok_label) {
|
if (data->ok_label) {
|
||||||
button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_forms_ok_button"));
|
button = GTK_WIDGET (
|
||||||
|
gtk_builder_get_object (builder, "zenity_forms_ok_button"));
|
||||||
gtk_button_set_label (GTK_BUTTON (button), data->ok_label);
|
gtk_button_set_label (GTK_BUTTON (button), data->ok_label);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->cancel_label) {
|
if (data->cancel_label) {
|
||||||
button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_forms_cancel_button"));
|
button = GTK_WIDGET (
|
||||||
|
gtk_builder_get_object (builder, "zenity_forms_cancel_button"));
|
||||||
gtk_button_set_label (GTK_BUTTON (button), data->cancel_label);
|
gtk_button_set_label (GTK_BUTTON (button), data->cancel_label);
|
||||||
}
|
}
|
||||||
|
|
||||||
text = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_forms_text"));
|
text = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_forms_text"));
|
||||||
|
|
||||||
if (forms_data->dialog_text)
|
if (forms_data->dialog_text)
|
||||||
gtk_label_set_markup (GTK_LABEL (text), g_strcompress (forms_data->dialog_text));
|
gtk_label_set_markup (
|
||||||
|
GTK_LABEL (text), g_strcompress (forms_data->dialog_text));
|
||||||
|
|
||||||
grid = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_forms_grid"));
|
grid = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_forms_grid"));
|
||||||
|
|
||||||
@ -234,37 +250,35 @@ void zenity_forms_dialog (ZenityData *data, ZenityFormsData *forms_data)
|
|||||||
ZenityFormsValue *zenity_value = (ZenityFormsValue *) tmp->data;
|
ZenityFormsValue *zenity_value = (ZenityFormsValue *) tmp->data;
|
||||||
GtkWidget *label;
|
GtkWidget *label;
|
||||||
|
|
||||||
label = gtk_label_new(zenity_value->option_value);
|
label = gtk_label_new (zenity_value->option_value);
|
||||||
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
||||||
gtk_grid_attach (GTK_GRID (grid),
|
gtk_grid_attach (GTK_GRID (grid), label, 0, i, 1, 1);
|
||||||
label,
|
|
||||||
0, i,
|
|
||||||
1, 1);
|
|
||||||
|
|
||||||
switch(zenity_value->type)
|
switch (zenity_value->type) {
|
||||||
{
|
|
||||||
case ZENITY_FORMS_ENTRY:
|
case ZENITY_FORMS_ENTRY:
|
||||||
zenity_value->forms_widget = gtk_entry_new();
|
zenity_value->forms_widget = gtk_entry_new ();
|
||||||
break;
|
break;
|
||||||
case ZENITY_FORMS_PASSWORD:
|
case ZENITY_FORMS_PASSWORD:
|
||||||
zenity_value->forms_widget = gtk_entry_new();
|
zenity_value->forms_widget = gtk_entry_new ();
|
||||||
gtk_entry_set_visibility(GTK_ENTRY(zenity_value->forms_widget),
|
gtk_entry_set_visibility (
|
||||||
FALSE);
|
GTK_ENTRY (zenity_value->forms_widget), FALSE);
|
||||||
break;
|
break;
|
||||||
case ZENITY_FORMS_CALENDAR:
|
case ZENITY_FORMS_CALENDAR:
|
||||||
zenity_value->forms_widget = gtk_calendar_new();
|
zenity_value->forms_widget = gtk_calendar_new ();
|
||||||
break;
|
break;
|
||||||
case ZENITY_FORMS_LIST:
|
case ZENITY_FORMS_LIST:
|
||||||
zenity_value->forms_widget = zenity_forms_create_and_fill_list (forms_data, list_count,
|
zenity_value->forms_widget = zenity_forms_create_and_fill_list (
|
||||||
zenity_value->option_value);
|
forms_data, list_count, zenity_value->option_value);
|
||||||
list_count++;
|
list_count++;
|
||||||
break;
|
break;
|
||||||
case ZENITY_FORMS_COMBO:
|
case ZENITY_FORMS_COMBO:
|
||||||
zenity_value->forms_widget = zenity_forms_create_and_fill_combo (forms_data, combo_count);
|
zenity_value->forms_widget =
|
||||||
|
zenity_forms_create_and_fill_combo (
|
||||||
|
forms_data, combo_count);
|
||||||
combo_count++;
|
combo_count++;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
zenity_value->forms_widget = gtk_entry_new();
|
zenity_value->forms_widget = gtk_entry_new ();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,7 +286,8 @@ void zenity_forms_dialog (ZenityData *data, ZenityFormsData *forms_data)
|
|||||||
GTK_WIDGET (zenity_value->forms_widget),
|
GTK_WIDGET (zenity_value->forms_widget),
|
||||||
label,
|
label,
|
||||||
GTK_POS_RIGHT,
|
GTK_POS_RIGHT,
|
||||||
1, 1);
|
1,
|
||||||
|
1);
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@ -282,15 +297,16 @@ void zenity_forms_dialog (ZenityData *data, ZenityFormsData *forms_data)
|
|||||||
g_object_unref (builder);
|
g_object_unref (builder);
|
||||||
|
|
||||||
if (data->timeout_delay > 0) {
|
if (data->timeout_delay > 0) {
|
||||||
g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, dialog);
|
g_timeout_add_seconds (data->timeout_delay,
|
||||||
|
(GSourceFunc) zenity_util_timeout_handle,
|
||||||
|
dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_main();
|
gtk_main ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_forms_dialog_output (ZenityFormsData *forms_data)
|
zenity_forms_dialog_output (ZenityFormsData *forms_data) {
|
||||||
{
|
|
||||||
GSList *tmp, *tmp2;
|
GSList *tmp, *tmp2;
|
||||||
guint day, year, month;
|
guint day, year, month;
|
||||||
GDate *date = NULL;
|
GDate *date = NULL;
|
||||||
@ -305,19 +321,23 @@ zenity_forms_dialog_output (ZenityFormsData *forms_data)
|
|||||||
switch (zenity_value->type) {
|
switch (zenity_value->type) {
|
||||||
case ZENITY_FORMS_PASSWORD:
|
case ZENITY_FORMS_PASSWORD:
|
||||||
case ZENITY_FORMS_ENTRY:
|
case ZENITY_FORMS_ENTRY:
|
||||||
g_print("%s", gtk_entry_get_text (GTK_ENTRY (zenity_value->forms_widget)));
|
g_print ("%s",
|
||||||
|
gtk_entry_get_text (
|
||||||
|
GTK_ENTRY (zenity_value->forms_widget)));
|
||||||
break;
|
break;
|
||||||
case ZENITY_FORMS_LIST:
|
case ZENITY_FORMS_LIST:
|
||||||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_bin_get_child (GTK_BIN (zenity_value->forms_widget))));
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (
|
||||||
|
gtk_bin_get_child (GTK_BIN (zenity_value->forms_widget))));
|
||||||
gtk_tree_selection_selected_foreach (selection,
|
gtk_tree_selection_selected_foreach (selection,
|
||||||
(GtkTreeSelectionForeachFunc) zenity_forms_dialog_get_selected,
|
(GtkTreeSelectionForeachFunc)
|
||||||
GTK_TREE_VIEW (gtk_bin_get_child (GTK_BIN (zenity_value->forms_widget))));
|
zenity_forms_dialog_get_selected,
|
||||||
|
GTK_TREE_VIEW (gtk_bin_get_child (
|
||||||
|
GTK_BIN (zenity_value->forms_widget))));
|
||||||
|
|
||||||
for (tmp2 = selected; tmp2; tmp2 = tmp2->next) {
|
for (tmp2 = selected; tmp2; tmp2 = tmp2->next) {
|
||||||
if (tmp->next != NULL) {
|
if (tmp->next != NULL) {
|
||||||
g_print ("%s,", (gchar *) tmp2->data);
|
g_print ("%s,", (gchar *) tmp2->data);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
g_print ("%s", (gchar *) tmp2->data);
|
g_print ("%s", (gchar *) tmp2->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,15 +346,26 @@ zenity_forms_dialog_output (ZenityFormsData *forms_data)
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case ZENITY_FORMS_CALENDAR:
|
case ZENITY_FORMS_CALENDAR:
|
||||||
gtk_calendar_get_date (GTK_CALENDAR (zenity_value->forms_widget), &day, &month, &year);
|
gtk_calendar_get_date (
|
||||||
|
GTK_CALENDAR (zenity_value->forms_widget),
|
||||||
|
&day,
|
||||||
|
&month,
|
||||||
|
&year);
|
||||||
date = g_date_new_dmy (year, month + 1, day);
|
date = g_date_new_dmy (year, month + 1, day);
|
||||||
g_date_strftime (time_string, 127, forms_data->date_format, date);
|
g_date_strftime (
|
||||||
|
time_string, 127, forms_data->date_format, date);
|
||||||
g_print ("%s", time_string);
|
g_print ("%s", time_string);
|
||||||
break;
|
break;
|
||||||
case ZENITY_FORMS_COMBO:
|
case ZENITY_FORMS_COMBO:
|
||||||
if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (zenity_value->forms_widget), &iter)) {
|
if (gtk_combo_box_get_active_iter (
|
||||||
list_store = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (zenity_value->forms_widget)));
|
GTK_COMBO_BOX (zenity_value->forms_widget), &iter)) {
|
||||||
gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter, 0, &combo_value, -1);
|
list_store = GTK_LIST_STORE (gtk_combo_box_get_model (
|
||||||
|
GTK_COMBO_BOX (zenity_value->forms_widget)));
|
||||||
|
gtk_tree_model_get (GTK_TREE_MODEL (list_store),
|
||||||
|
&iter,
|
||||||
|
0,
|
||||||
|
&combo_value,
|
||||||
|
-1);
|
||||||
g_object_unref (G_OBJECT (list_store));
|
g_object_unref (G_OBJECT (list_store));
|
||||||
|
|
||||||
g_print ("%s", combo_value);
|
g_print ("%s", combo_value);
|
||||||
@ -342,23 +373,21 @@ zenity_forms_dialog_output (ZenityFormsData *forms_data)
|
|||||||
} else
|
} else
|
||||||
g_print (" ");
|
g_print (" ");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
if (tmp->next != NULL)
|
if (tmp->next != NULL)
|
||||||
g_print("%s", forms_data->separator);
|
g_print ("%s", forms_data->separator);
|
||||||
}
|
}
|
||||||
g_print("\n");
|
g_print ("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_forms_dialog_response (GtkWidget *widget, int response, gpointer data)
|
zenity_forms_dialog_response (GtkWidget *widget, int response, gpointer data) {
|
||||||
{
|
|
||||||
ZenityFormsData *forms_data = (ZenityFormsData *) data;
|
ZenityFormsData *forms_data = (ZenityFormsData *) data;
|
||||||
|
|
||||||
switch (response) {
|
switch (response) {
|
||||||
case GTK_RESPONSE_OK:
|
case GTK_RESPONSE_OK:
|
||||||
zenity_forms_dialog_output (forms_data);
|
zenity_forms_dialog_output (forms_data);
|
||||||
zenity_util_exit_code_with_data(ZENITY_OK, zen_data);
|
zenity_util_exit_code_with_data (ZENITY_OK, zen_data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GTK_RESPONSE_CANCEL:
|
case GTK_RESPONSE_CANCEL:
|
||||||
@ -371,8 +400,9 @@ zenity_forms_dialog_response (GtkWidget *widget, int response, gpointer data)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (zen_data->extra_label && response < g_strv_length(zen_data->extra_label))
|
if (zen_data->extra_label &&
|
||||||
printf("%s\n",zen_data->extra_label[response]);
|
response < g_strv_length (zen_data->extra_label))
|
||||||
|
printf ("%s\n", zen_data->extra_label[response]);
|
||||||
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
15
src/main.c
15
src/main.c
@ -23,13 +23,13 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include "zenity.h"
|
|
||||||
#include "option.h"
|
#include "option.h"
|
||||||
|
#include "zenity.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <langinfo.h>
|
#include <langinfo.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#ifdef HAVE_LOCALE_H
|
#ifdef HAVE_LOCALE_H
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#endif
|
#endif
|
||||||
@ -40,12 +40,12 @@ main (gint argc, gchar **argv) {
|
|||||||
gint retval;
|
gint retval;
|
||||||
|
|
||||||
#ifdef HAVE_LOCALE_H
|
#ifdef HAVE_LOCALE_H
|
||||||
setlocale(LC_ALL,"");
|
setlocale (LC_ALL, "");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bindtextdomain(GETTEXT_PACKAGE, GNOMELOCALEDIR);
|
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
|
||||||
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
|
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
||||||
textdomain(GETTEXT_PACKAGE);
|
textdomain (GETTEXT_PACKAGE);
|
||||||
|
|
||||||
gtk_init (&argc, &argv);
|
gtk_init (&argc, &argv);
|
||||||
|
|
||||||
@ -102,7 +102,8 @@ main (gint argc, gchar **argv) {
|
|||||||
g_print ("%s\n", VERSION);
|
g_print ("%s\n", VERSION);
|
||||||
break;
|
break;
|
||||||
case MODE_LAST:
|
case MODE_LAST:
|
||||||
g_printerr (_("You must specify a dialog type. See 'zenity --help' for details\n"));
|
g_printerr (_ ("You must specify a dialog type. See 'zenity "
|
||||||
|
"--help' for details\n"));
|
||||||
zenity_option_free ();
|
zenity_option_free ();
|
||||||
exit (-1);
|
exit (-1);
|
||||||
default:
|
default:
|
||||||
|
113
src/msg.c
113
src/msg.c
@ -23,21 +23,24 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "zenity.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "zenity.h"
|
||||||
|
|
||||||
static void zenity_msg_dialog_response (GtkWidget *widget, int response, gpointer data);
|
static void zenity_msg_dialog_response (
|
||||||
|
GtkWidget *widget, int response, gpointer data);
|
||||||
static void
|
static void
|
||||||
zenity_msg_construct_question_dialog (GtkWidget *dialog, ZenityMsgData *msg_data, ZenityData *data)
|
zenity_msg_construct_question_dialog (
|
||||||
{
|
GtkWidget *dialog, ZenityMsgData *msg_data, ZenityData *data) {
|
||||||
|
|
||||||
|
|
||||||
GtkWidget *cancel_button, *ok_button;
|
GtkWidget *cancel_button, *ok_button;
|
||||||
|
|
||||||
cancel_button = gtk_dialog_add_button (GTK_DIALOG (dialog), _("_No"), GTK_RESPONSE_CANCEL);
|
cancel_button = gtk_dialog_add_button (
|
||||||
ok_button = gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Yes"), GTK_RESPONSE_OK);
|
GTK_DIALOG (dialog), _ ("_No"), GTK_RESPONSE_CANCEL);
|
||||||
|
ok_button = gtk_dialog_add_button (
|
||||||
|
GTK_DIALOG (dialog), _ ("_Yes"), GTK_RESPONSE_OK);
|
||||||
|
|
||||||
gtk_widget_grab_focus (msg_data->default_cancel ? cancel_button : ok_button);
|
gtk_widget_grab_focus (
|
||||||
|
msg_data->default_cancel ? cancel_button : ok_button);
|
||||||
|
|
||||||
if (data->cancel_label) {
|
if (data->cancel_label) {
|
||||||
gtk_button_set_label (GTK_BUTTON (cancel_button), data->cancel_label);
|
gtk_button_set_label (GTK_BUTTON (cancel_button), data->cancel_label);
|
||||||
@ -46,13 +49,10 @@ zenity_msg_construct_question_dialog (GtkWidget *dialog, ZenityMsgData *msg_data
|
|||||||
if (data->ok_label) {
|
if (data->ok_label) {
|
||||||
gtk_button_set_label (GTK_BUTTON (ok_button), data->ok_label);
|
gtk_button_set_label (GTK_BUTTON (ok_button), data->ok_label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_label_widget_clipboard_selection(GtkWidget *widget)
|
zenity_label_widget_clipboard_selection (GtkWidget *widget) {
|
||||||
{
|
|
||||||
/* Workaround hotfix for suspected toolkit issue:
|
/* Workaround hotfix for suspected toolkit issue:
|
||||||
since focus change of the dialog's focussed widget (text)
|
since focus change of the dialog's focussed widget (text)
|
||||||
somehow currently chooses to destroy
|
somehow currently chooses to destroy
|
||||||
@ -69,15 +69,14 @@ zenity_label_widget_clipboard_selection(GtkWidget *widget)
|
|||||||
<property name="selectable">True</property>
|
<property name="selectable">True</property>
|
||||||
.
|
.
|
||||||
*/
|
*/
|
||||||
g_object_set(gtk_widget_get_settings (widget),
|
g_object_set (gtk_widget_get_settings (widget),
|
||||||
"gtk-label-select-on-focus",
|
"gtk-label-select-on-focus",
|
||||||
FALSE,
|
FALSE,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
|
zenity_msg (ZenityData *data, ZenityMsgData *msg_data) {
|
||||||
{
|
|
||||||
GtkBuilder *builder;
|
GtkBuilder *builder;
|
||||||
GtkWidget *dialog;
|
GtkWidget *dialog;
|
||||||
GtkWidget *ok_button;
|
GtkWidget *ok_button;
|
||||||
@ -87,16 +86,19 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
|
|||||||
switch (msg_data->mode) {
|
switch (msg_data->mode) {
|
||||||
case ZENITY_MSG_WARNING:
|
case ZENITY_MSG_WARNING:
|
||||||
builder = zenity_util_load_ui_file ("zenity_warning_dialog", NULL);
|
builder = zenity_util_load_ui_file ("zenity_warning_dialog", NULL);
|
||||||
dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_warning_dialog"));
|
dialog = GTK_WIDGET (
|
||||||
|
gtk_builder_get_object (builder, "zenity_warning_dialog"));
|
||||||
text = gtk_builder_get_object (builder, "zenity_warning_text");
|
text = gtk_builder_get_object (builder, "zenity_warning_text");
|
||||||
image = gtk_builder_get_object (builder, "zenity_warning_image");
|
image = gtk_builder_get_object (builder, "zenity_warning_image");
|
||||||
ok_button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_warning_ok_button"));
|
ok_button = GTK_WIDGET (
|
||||||
|
gtk_builder_get_object (builder, "zenity_warning_ok_button"));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ZENITY_MSG_QUESTION:
|
case ZENITY_MSG_QUESTION:
|
||||||
case ZENITY_MSG_SWITCH:
|
case ZENITY_MSG_SWITCH:
|
||||||
builder = zenity_util_load_ui_file ("zenity_question_dialog", NULL);
|
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");
|
text = gtk_builder_get_object (builder, "zenity_question_text");
|
||||||
image = gtk_builder_get_object (builder, "zenity_question_image");
|
image = gtk_builder_get_object (builder, "zenity_question_image");
|
||||||
ok_button = NULL;
|
ok_button = NULL;
|
||||||
@ -104,18 +106,22 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
|
|||||||
|
|
||||||
case ZENITY_MSG_ERROR:
|
case ZENITY_MSG_ERROR:
|
||||||
builder = zenity_util_load_ui_file ("zenity_error_dialog", NULL);
|
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");
|
text = gtk_builder_get_object (builder, "zenity_error_text");
|
||||||
image = gtk_builder_get_object (builder, "zenity_error_image");
|
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;
|
break;
|
||||||
|
|
||||||
case ZENITY_MSG_INFO:
|
case ZENITY_MSG_INFO:
|
||||||
builder = zenity_util_load_ui_file ("zenity_info_dialog", NULL);
|
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");
|
text = gtk_builder_get_object (builder, "zenity_info_text");
|
||||||
image = gtk_builder_get_object (builder, "zenity_info_image");
|
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;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -129,9 +135,10 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data->extra_label) {
|
if (data->extra_label) {
|
||||||
gint i=0;
|
gint i = 0;
|
||||||
while(data->extra_label[i]!=NULL){
|
while (data->extra_label[i] != NULL) {
|
||||||
gtk_dialog_add_button (GTK_DIALOG (dialog), data->extra_label[i], i);
|
gtk_dialog_add_button (
|
||||||
|
GTK_DIALOG (dialog), data->extra_label[i], i);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -141,8 +148,10 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_signal_connect (G_OBJECT (dialog), "response",
|
g_signal_connect (G_OBJECT (dialog),
|
||||||
G_CALLBACK (zenity_msg_dialog_response), data);
|
"response",
|
||||||
|
G_CALLBACK (zenity_msg_dialog_response),
|
||||||
|
data);
|
||||||
|
|
||||||
gtk_builder_connect_signals (builder, NULL);
|
gtk_builder_connect_signals (builder, NULL);
|
||||||
|
|
||||||
@ -157,24 +166,29 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
|
|||||||
|
|
||||||
switch (msg_data->mode) {
|
switch (msg_data->mode) {
|
||||||
case ZENITY_MSG_WARNING:
|
case ZENITY_MSG_WARNING:
|
||||||
zenity_util_set_window_icon_from_icon_name (dialog, data->window_icon, "dialog-warning");
|
zenity_util_set_window_icon_from_icon_name (
|
||||||
|
dialog, data->window_icon, "dialog-warning");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ZENITY_MSG_QUESTION:
|
case ZENITY_MSG_QUESTION:
|
||||||
zenity_util_set_window_icon_from_icon_name (dialog, data->window_icon, "dialog-question");
|
zenity_util_set_window_icon_from_icon_name (
|
||||||
|
dialog, data->window_icon, "dialog-question");
|
||||||
zenity_msg_construct_question_dialog (dialog, msg_data, data);
|
zenity_msg_construct_question_dialog (dialog, msg_data, data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ZENITY_MSG_SWITCH:
|
case ZENITY_MSG_SWITCH:
|
||||||
zenity_util_set_window_icon_from_icon_name (dialog, data->window_icon, "dialog-question");
|
zenity_util_set_window_icon_from_icon_name (
|
||||||
|
dialog, data->window_icon, "dialog-question");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ZENITY_MSG_ERROR:
|
case ZENITY_MSG_ERROR:
|
||||||
zenity_util_set_window_icon_from_icon_name (dialog, data->window_icon, "dialog-error");
|
zenity_util_set_window_icon_from_icon_name (
|
||||||
|
dialog, data->window_icon, "dialog-error");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ZENITY_MSG_INFO:
|
case ZENITY_MSG_INFO:
|
||||||
zenity_util_set_window_icon_from_icon_name (dialog, data->window_icon, "dialog-information");
|
zenity_util_set_window_icon_from_icon_name (
|
||||||
|
dialog, data->window_icon, "dialog-information");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -182,14 +196,15 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data->width > -1 || data->height > -1)
|
if (data->width > -1 || data->height > -1)
|
||||||
gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height);
|
gtk_window_set_default_size (
|
||||||
|
GTK_WINDOW (dialog), data->width, data->height);
|
||||||
|
|
||||||
if (data->width > -1)
|
if (data->width > -1)
|
||||||
gtk_widget_set_size_request (GTK_WIDGET (text), data->width, -1);
|
gtk_widget_set_size_request (GTK_WIDGET (text), data->width, -1);
|
||||||
else
|
else if (!msg_data->ellipsize && !msg_data->no_wrap) {
|
||||||
if (!msg_data->ellipsize && !msg_data->no_wrap) {
|
|
||||||
// the magic number 60 is picked from gtk+/gtk/ui/gtkmessagedialog.ui
|
// the magic number 60 is picked from gtk+/gtk/ui/gtkmessagedialog.ui
|
||||||
// however, 60 would increase the distance between the icon and the text,
|
// however, 60 would increase the distance between the icon and the
|
||||||
|
// text,
|
||||||
// decreasing to 10 fix it.
|
// decreasing to 10 fix it.
|
||||||
gtk_label_set_width_chars (text, 10);
|
gtk_label_set_width_chars (text, 10);
|
||||||
gtk_label_set_max_width_chars (text, 10);
|
gtk_label_set_max_width_chars (text, 10);
|
||||||
@ -202,23 +217,27 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
|
|||||||
if (msg_data->no_markup)
|
if (msg_data->no_markup)
|
||||||
gtk_label_set_text (GTK_LABEL (text), msg_data->dialog_text);
|
gtk_label_set_text (GTK_LABEL (text), msg_data->dialog_text);
|
||||||
else
|
else
|
||||||
gtk_label_set_markup (GTK_LABEL (text), g_strcompress (msg_data->dialog_text));
|
gtk_label_set_markup (
|
||||||
zenity_label_widget_clipboard_selection(GTK_WIDGET (text));
|
GTK_LABEL (text), g_strcompress (msg_data->dialog_text));
|
||||||
|
zenity_label_widget_clipboard_selection (GTK_WIDGET (text));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg_data->ellipsize)
|
if (msg_data->ellipsize)
|
||||||
gtk_label_set_ellipsize (GTK_LABEL(text), PANGO_ALIGN_RIGHT);
|
gtk_label_set_ellipsize (GTK_LABEL (text), PANGO_ALIGN_RIGHT);
|
||||||
|
|
||||||
if (msg_data->dialog_icon)
|
if (msg_data->dialog_icon)
|
||||||
gtk_image_set_from_icon_name (GTK_IMAGE (image), msg_data->dialog_icon, GTK_ICON_SIZE_DIALOG);
|
gtk_image_set_from_icon_name (
|
||||||
|
GTK_IMAGE (image), msg_data->dialog_icon, GTK_ICON_SIZE_DIALOG);
|
||||||
|
|
||||||
if (msg_data->no_wrap)
|
if (msg_data->no_wrap)
|
||||||
gtk_label_set_line_wrap (GTK_LABEL (text), FALSE);
|
gtk_label_set_line_wrap (GTK_LABEL (text), FALSE);
|
||||||
|
|
||||||
zenity_util_show_dialog (dialog, data->attach);
|
zenity_util_show_dialog (dialog, data->attach);
|
||||||
|
|
||||||
if(data->timeout_delay > 0) {
|
if (data->timeout_delay > 0) {
|
||||||
g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, NULL);
|
g_timeout_add_seconds (data->timeout_delay,
|
||||||
|
(GSourceFunc) zenity_util_timeout_handle,
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_object_unref (builder);
|
g_object_unref (builder);
|
||||||
@ -227,13 +246,12 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_msg_dialog_response (GtkWidget *widget, int response, gpointer data)
|
zenity_msg_dialog_response (GtkWidget *widget, int response, gpointer data) {
|
||||||
{
|
|
||||||
ZenityData *zen_data = data;
|
ZenityData *zen_data = data;
|
||||||
|
|
||||||
switch (response) {
|
switch (response) {
|
||||||
case GTK_RESPONSE_OK:
|
case GTK_RESPONSE_OK:
|
||||||
zenity_util_exit_code_with_data(ZENITY_OK, zen_data);
|
zenity_util_exit_code_with_data (ZENITY_OK, zen_data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GTK_RESPONSE_CANCEL:
|
case GTK_RESPONSE_CANCEL:
|
||||||
@ -241,8 +259,9 @@ zenity_msg_dialog_response (GtkWidget *widget, int response, gpointer data)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (zen_data->extra_label && response < g_strv_length(zen_data->extra_label))
|
if (zen_data->extra_label &&
|
||||||
printf("%s\n",zen_data->extra_label[response]);
|
response < g_strv_length (zen_data->extra_label))
|
||||||
|
printf ("%s\n", zen_data->extra_label[response]);
|
||||||
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -24,16 +24,16 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <time.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
#ifdef HAVE_LIBNOTIFY
|
#ifdef HAVE_LIBNOTIFY
|
||||||
#include <libnotify/notify.h>
|
#include <libnotify/notify.h>
|
||||||
|
|
||||||
#include "zenity.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "zenity.h"
|
||||||
|
|
||||||
#define MAX_HINTS 16
|
#define MAX_HINTS 16
|
||||||
|
|
||||||
@ -41,14 +41,13 @@ static char *icon_file;
|
|||||||
static GHashTable *notification_hints;
|
static GHashTable *notification_hints;
|
||||||
|
|
||||||
static NotifyNotification *
|
static NotifyNotification *
|
||||||
zenity_notification_new(gchar *message, gchar *icon_file)
|
zenity_notification_new (gchar *message, gchar *icon_file) {
|
||||||
{
|
|
||||||
NotifyNotification *notif;
|
NotifyNotification *notif;
|
||||||
gchar **text;
|
gchar **text;
|
||||||
|
|
||||||
text = g_strsplit (g_strcompress (message), "\n", 2);
|
text = g_strsplit (g_strcompress (message), "\n", 2);
|
||||||
if (*text == NULL) {
|
if (*text == NULL) {
|
||||||
g_printerr (_("Could not parse message\n"));
|
g_printerr (_ ("Could not parse message\n"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,13 +59,11 @@ zenity_notification_new(gchar *message, gchar *icon_file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_notification_default_action (NotifyNotification *n,
|
on_notification_default_action (
|
||||||
const char *action,
|
NotifyNotification *n, const char *action, void *user_data) {
|
||||||
void *user_data)
|
|
||||||
{
|
|
||||||
ZenityData *zen_data;
|
ZenityData *zen_data;
|
||||||
|
|
||||||
zen_data = (ZenityData *)user_data;
|
zen_data = (ZenityData *) user_data;
|
||||||
notify_notification_close (n, NULL);
|
notify_notification_close (n, NULL);
|
||||||
|
|
||||||
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
|
||||||
@ -75,18 +72,14 @@ on_notification_default_action (NotifyNotification *n,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static GHashTable *
|
static GHashTable *
|
||||||
zenity_notification_parse_hints_array (gchar **hints)
|
zenity_notification_parse_hints_array (gchar **hints) {
|
||||||
{
|
|
||||||
GHashTable *result;
|
GHashTable *result;
|
||||||
gchar** pair;
|
gchar **pair;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
result = g_hash_table_new_full (g_str_hash,
|
result = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
|
||||||
g_str_equal,
|
|
||||||
g_free,
|
|
||||||
g_free);
|
|
||||||
|
|
||||||
for(i = 0; i < g_strv_length (hints); i++) {
|
for (i = 0; i < g_strv_length (hints); i++) {
|
||||||
pair = g_strsplit (hints[i], ":", 2);
|
pair = g_strsplit (hints[i], ":", 2);
|
||||||
g_hash_table_replace (result, g_strdup (pair[0]), g_strdup (pair[1]));
|
g_hash_table_replace (result, g_strdup (pair[0]), g_strdup (pair[1]));
|
||||||
g_strfreev (pair);
|
g_strfreev (pair);
|
||||||
@ -100,10 +93,9 @@ zenity_notification_parse_hints_array (gchar **hints)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static GHashTable *
|
static GHashTable *
|
||||||
zenity_notification_parse_hints (gchar *hints)
|
zenity_notification_parse_hints (gchar *hints) {
|
||||||
{
|
|
||||||
GHashTable *result;
|
GHashTable *result;
|
||||||
gchar** hint_array;
|
gchar **hint_array;
|
||||||
|
|
||||||
hint_array = g_strsplit (g_strcompress (hints), "\n", MAX_HINTS);
|
hint_array = g_strsplit (g_strcompress (hints), "\n", MAX_HINTS);
|
||||||
result = zenity_notification_parse_hints_array (hint_array);
|
result = zenity_notification_parse_hints_array (hint_array);
|
||||||
@ -112,8 +104,8 @@ zenity_notification_parse_hints (gchar *hints)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_notification_set_hint(gpointer key, gpointer value, gpointer user_data)
|
zenity_notification_set_hint (
|
||||||
{
|
gpointer key, gpointer value, gpointer user_data) {
|
||||||
NotifyNotification *notification;
|
NotifyNotification *notification;
|
||||||
gchar *hint_name;
|
gchar *hint_name;
|
||||||
GVariant *hint_value;
|
GVariant *hint_value;
|
||||||
@ -127,36 +119,37 @@ zenity_notification_set_hint(gpointer key, gpointer value, gpointer user_data)
|
|||||||
string_value = (gchar *) value;
|
string_value = (gchar *) value;
|
||||||
notification = (NotifyNotification *) user_data;
|
notification = (NotifyNotification *) user_data;
|
||||||
|
|
||||||
if ((g_ascii_strcasecmp ("action-icons", hint_name) == 0)
|
if ((g_ascii_strcasecmp ("action-icons", hint_name) == 0) ||
|
||||||
|| (g_ascii_strcasecmp ("resident", hint_name) == 0)
|
(g_ascii_strcasecmp ("resident", hint_name) == 0) ||
|
||||||
|| (g_ascii_strcasecmp ("suppress-sound", hint_name) == 0)
|
(g_ascii_strcasecmp ("suppress-sound", hint_name) == 0) ||
|
||||||
|| (g_ascii_strcasecmp ("transient", hint_name) == 0)) {
|
(g_ascii_strcasecmp ("transient", hint_name) == 0)) {
|
||||||
/* boolean hints */
|
/* boolean hints */
|
||||||
if (g_ascii_strcasecmp ("true", string_value) == 0) {
|
if (g_ascii_strcasecmp ("true", string_value) == 0) {
|
||||||
boolean_value = TRUE;
|
boolean_value = TRUE;
|
||||||
} else if (g_ascii_strcasecmp ("false", string_value) == 0) {
|
} else if (g_ascii_strcasecmp ("false", string_value) == 0) {
|
||||||
boolean_value = FALSE;
|
boolean_value = FALSE;
|
||||||
} else {
|
} else {
|
||||||
g_printerr (_("Invalid value for a boolean typed hint.\nSupported values are 'true' or 'false'.\n"));
|
g_printerr (_ ("Invalid value for a boolean typed hint.\nSupported "
|
||||||
|
"values are 'true' or 'false'.\n"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
hint_value = g_variant_new_boolean (boolean_value);
|
hint_value = g_variant_new_boolean (boolean_value);
|
||||||
} else if ((g_ascii_strcasecmp ("category", hint_name) == 0)
|
} else if ((g_ascii_strcasecmp ("category", hint_name) == 0) ||
|
||||||
|| (g_ascii_strcasecmp ("desktop-entry", hint_name) == 0)
|
(g_ascii_strcasecmp ("desktop-entry", hint_name) == 0) ||
|
||||||
|| (g_ascii_strcasecmp ("image-path", hint_name) == 0)
|
(g_ascii_strcasecmp ("image-path", hint_name) == 0) ||
|
||||||
|| (g_ascii_strcasecmp ("image_path", hint_name) == 0)
|
(g_ascii_strcasecmp ("image_path", hint_name) == 0) ||
|
||||||
|| (g_ascii_strcasecmp ("sound-file", hint_name) == 0)
|
(g_ascii_strcasecmp ("sound-file", hint_name) == 0) ||
|
||||||
|| (g_ascii_strcasecmp ("sound-name", hint_name) == 0)) {
|
(g_ascii_strcasecmp ("sound-name", hint_name) == 0)) {
|
||||||
/* string hints */
|
/* string hints */
|
||||||
hint_value = g_variant_new_string (string_value);
|
hint_value = g_variant_new_string (string_value);
|
||||||
} else if ((g_ascii_strcasecmp ("image-data", hint_name) == 0)
|
} else if ((g_ascii_strcasecmp ("image-data", hint_name) == 0) ||
|
||||||
|| (g_ascii_strcasecmp ("image_data", hint_name) == 0)
|
(g_ascii_strcasecmp ("image_data", hint_name) == 0) ||
|
||||||
|| (g_ascii_strcasecmp ("icon-data", hint_name) == 0)) {
|
(g_ascii_strcasecmp ("icon-data", hint_name) == 0)) {
|
||||||
/* (iibiiay) */
|
/* (iibiiay) */
|
||||||
g_printerr (_("Unsupported hint. Skipping.\n"));
|
g_printerr (_ ("Unsupported hint. Skipping.\n"));
|
||||||
return;
|
return;
|
||||||
} else if ((g_ascii_strcasecmp ("x", hint_name) == 0)
|
} else if ((g_ascii_strcasecmp ("x", hint_name) == 0) ||
|
||||||
|| (g_ascii_strcasecmp ("y", hint_name) == 0)) {
|
(g_ascii_strcasecmp ("y", hint_name) == 0)) {
|
||||||
/* int hints */
|
/* int hints */
|
||||||
if (string_value == NULL)
|
if (string_value == NULL)
|
||||||
string_value = "";
|
string_value = "";
|
||||||
@ -170,18 +163,16 @@ zenity_notification_set_hint(gpointer key, gpointer value, gpointer user_data)
|
|||||||
hint_value = g_variant_new_byte (byte_value);
|
hint_value = g_variant_new_byte (byte_value);
|
||||||
} else {
|
} else {
|
||||||
/* unknown hints */
|
/* unknown hints */
|
||||||
g_printerr (_("Unknown hint name. Skipping.\n"));
|
g_printerr (_ ("Unknown hint name. Skipping.\n"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
notify_notification_set_hint (notification,
|
notify_notification_set_hint (notification, hint_name, hint_value);
|
||||||
hint_name,
|
|
||||||
hint_value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_notification_set_hints (NotifyNotification *notification, GHashTable *hints)
|
zenity_notification_set_hints (
|
||||||
{
|
NotifyNotification *notification, GHashTable *hints) {
|
||||||
if (hints == NULL) {
|
if (hints == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -190,10 +181,8 @@ zenity_notification_set_hints (NotifyNotification *notification, GHashTable *hin
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
zenity_notification_handle_stdin (GIOChannel *channel,
|
zenity_notification_handle_stdin (
|
||||||
GIOCondition condition,
|
GIOChannel *channel, GIOCondition condition, gpointer user_data) {
|
||||||
gpointer user_data)
|
|
||||||
{
|
|
||||||
if ((condition & G_IO_IN) != 0) {
|
if ((condition & G_IO_IN) != 0) {
|
||||||
GString *string;
|
GString *string;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
@ -206,7 +195,8 @@ zenity_notification_handle_stdin (GIOChannel *channel,
|
|||||||
gchar *command, *value, *colon;
|
gchar *command, *value, *colon;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
status = g_io_channel_read_line_string (channel, string, NULL, &error);
|
status = g_io_channel_read_line_string (
|
||||||
|
channel, string, NULL, &error);
|
||||||
while (gdk_events_pending ())
|
while (gdk_events_pending ())
|
||||||
gtk_main_iteration ();
|
gtk_main_iteration ();
|
||||||
|
|
||||||
@ -223,16 +213,17 @@ zenity_notification_handle_stdin (GIOChannel *channel,
|
|||||||
}
|
}
|
||||||
|
|
||||||
zenity_util_strip_newline (string->str);
|
zenity_util_strip_newline (string->str);
|
||||||
colon = strchr(string->str, ':');
|
colon = strchr (string->str, ':');
|
||||||
if (colon == NULL) {
|
if (colon == NULL) {
|
||||||
g_printerr (_("Could not parse command from stdin\n"));
|
g_printerr (_ ("Could not parse command from stdin\n"));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* split off the command and value */
|
/* split off the command and value */
|
||||||
command = g_strstrip (g_strndup (string->str, colon - string->str));
|
command = g_strstrip (g_strndup (string->str, colon - string->str));
|
||||||
|
|
||||||
value = colon + 1;
|
value = colon + 1;
|
||||||
while (*value && g_ascii_isspace (*value)) value++;
|
while (*value && g_ascii_isspace (*value))
|
||||||
|
value++;
|
||||||
|
|
||||||
if (!g_ascii_strcasecmp (command, "icon")) {
|
if (!g_ascii_strcasecmp (command, "icon")) {
|
||||||
g_free (icon_file);
|
g_free (icon_file);
|
||||||
@ -258,7 +249,8 @@ zenity_notification_handle_stdin (GIOChannel *channel,
|
|||||||
|
|
||||||
notify_notification_show (notif, &error);
|
notify_notification_show (notif, &error);
|
||||||
if (error) {
|
if (error) {
|
||||||
g_warning ("Error showing notification: %s", error->message);
|
g_warning (
|
||||||
|
"Error showing notification: %s", error->message);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
error = NULL;
|
error = NULL;
|
||||||
}
|
}
|
||||||
@ -278,7 +270,8 @@ zenity_notification_handle_stdin (GIOChannel *channel,
|
|||||||
|
|
||||||
notify_notification_show (notif, &error);
|
notify_notification_show (notif, &error);
|
||||||
if (error) {
|
if (error) {
|
||||||
g_warning ("Error showing notification: %s", error->message);
|
g_warning (
|
||||||
|
"Error showing notification: %s", error->message);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
error = NULL;
|
error = NULL;
|
||||||
}
|
}
|
||||||
@ -303,39 +296,38 @@ zenity_notification_handle_stdin (GIOChannel *channel,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_notification_listen_on_stdin (ZenityData *data)
|
zenity_notification_listen_on_stdin (ZenityData *data) {
|
||||||
{
|
|
||||||
GIOChannel *channel;
|
GIOChannel *channel;
|
||||||
|
|
||||||
channel = g_io_channel_unix_new (0);
|
channel = g_io_channel_unix_new (0);
|
||||||
g_io_channel_set_encoding (channel, NULL, NULL);
|
g_io_channel_set_encoding (channel, NULL, NULL);
|
||||||
g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL);
|
g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL);
|
||||||
g_io_add_watch (channel, G_IO_IN | G_IO_HUP,
|
g_io_add_watch (
|
||||||
zenity_notification_handle_stdin, data);
|
channel, G_IO_IN | G_IO_HUP, zenity_notification_handle_stdin, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
zenity_notification (ZenityData *data, ZenityNotificationData *notification_data)
|
zenity_notification (
|
||||||
{
|
ZenityData *data, ZenityNotificationData *notification_data) {
|
||||||
GError *error;
|
GError *error;
|
||||||
NotifyNotification *notification;
|
NotifyNotification *notification;
|
||||||
GHashTable *notification_hints;
|
GHashTable *notification_hints;
|
||||||
|
|
||||||
/* create the notification widget */
|
/* create the notification widget */
|
||||||
if (!notify_is_initted ()) {
|
if (!notify_is_initted ()) {
|
||||||
notify_init (_("Zenity notification"));
|
notify_init (_ ("Zenity notification"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notification_data->listen) {
|
if (notification_data->listen) {
|
||||||
zenity_notification_listen_on_stdin (data);
|
zenity_notification_listen_on_stdin (data);
|
||||||
gtk_main();
|
gtk_main ();
|
||||||
} else {
|
} else {
|
||||||
if (notification_data->notification_text == NULL) {
|
if (notification_data->notification_text == NULL) {
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
notification = zenity_notification_new (notification_data->notification_text,
|
notification = zenity_notification_new (
|
||||||
data->window_icon);
|
notification_data->notification_text, data->window_icon);
|
||||||
|
|
||||||
if (notification == NULL) {
|
if (notification == NULL) {
|
||||||
exit (1);
|
exit (1);
|
||||||
@ -351,8 +343,9 @@ zenity_notification (ZenityData *data, ZenityNotificationData *notification_data
|
|||||||
|
|
||||||
/* set the notification hints for the displayed notification */
|
/* set the notification hints for the displayed notification */
|
||||||
if (notification_data->notification_hints != NULL) {
|
if (notification_data->notification_hints != NULL) {
|
||||||
notification_hints = zenity_notification_parse_hints_array (notification_data->notification_hints);
|
notification_hints = zenity_notification_parse_hints_array (
|
||||||
zenity_notification_set_hints(notification, notification_hints);
|
notification_data->notification_hints);
|
||||||
|
zenity_notification_set_hints (notification, notification_hints);
|
||||||
g_hash_table_unref (notification_hints);
|
g_hash_table_unref (notification_hints);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,12 +358,13 @@ zenity_notification (ZenityData *data, ZenityNotificationData *notification_data
|
|||||||
}
|
}
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->timeout_delay > 0) {
|
if (data->timeout_delay > 0) {
|
||||||
g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, NULL);
|
g_timeout_add_seconds (data->timeout_delay,
|
||||||
gtk_main();
|
(GSourceFunc) zenity_util_timeout_handle,
|
||||||
|
NULL);
|
||||||
|
gtk_main ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1782
src/option.c
1782
src/option.c
File diff suppressed because it is too large
Load Diff
@ -80,11 +80,9 @@ typedef struct {
|
|||||||
ZenityFormsData *forms_data;
|
ZenityFormsData *forms_data;
|
||||||
} ZenityParsingOptions;
|
} ZenityParsingOptions;
|
||||||
|
|
||||||
void zenity_option_error (gchar *string,
|
void zenity_option_error (gchar *string, ZenityError error);
|
||||||
ZenityError error);
|
|
||||||
|
|
||||||
ZenityParsingOptions * zenity_option_parse (gint argc,
|
ZenityParsingOptions *zenity_option_parse (gint argc, gchar **argv);
|
||||||
gchar **argv);
|
|
||||||
|
|
||||||
void zenity_option_free (void);
|
void zenity_option_free (void);
|
||||||
|
|
||||||
|
146
src/password.c
146
src/password.c
@ -22,16 +22,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <string.h>
|
|
||||||
#include "zenity.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "zenity.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
static ZenityData *zen_data;
|
static ZenityData *zen_data;
|
||||||
|
|
||||||
static void zenity_password_dialog_response (GtkWidget *widget, int response, gpointer data);
|
static void zenity_password_dialog_response (
|
||||||
|
GtkWidget *widget, int response, gpointer data);
|
||||||
|
|
||||||
void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data)
|
void
|
||||||
{
|
zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data) {
|
||||||
GtkWidget *dialog;
|
GtkWidget *dialog;
|
||||||
GtkWidget *image;
|
GtkWidget *image;
|
||||||
GtkWidget *hbox;
|
GtkWidget *hbox;
|
||||||
@ -44,102 +45,76 @@ void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data
|
|||||||
dialog = gtk_dialog_new ();
|
dialog = gtk_dialog_new ();
|
||||||
|
|
||||||
if (data->extra_label) {
|
if (data->extra_label) {
|
||||||
gint i=0;
|
gint i = 0;
|
||||||
while(data->extra_label[i]!=NULL){
|
while (data->extra_label[i] != NULL) {
|
||||||
gtk_dialog_add_button (GTK_DIALOG (dialog), data->extra_label[i], i);
|
gtk_dialog_add_button (
|
||||||
|
GTK_DIALOG (dialog), data->extra_label[i], i);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_dialog_add_button(GTK_DIALOG(dialog),
|
gtk_dialog_add_button (GTK_DIALOG (dialog),
|
||||||
data->cancel_label != NULL ? data->cancel_label : _("_Cancel"),
|
data->cancel_label != NULL ? data->cancel_label : _ ("_Cancel"),
|
||||||
GTK_RESPONSE_CANCEL);
|
GTK_RESPONSE_CANCEL);
|
||||||
gtk_dialog_add_button(GTK_DIALOG(dialog),
|
gtk_dialog_add_button (GTK_DIALOG (dialog),
|
||||||
data->ok_label != NULL ? data->ok_label : _("_OK"),
|
data->ok_label != NULL ? data->ok_label : _ ("_OK"),
|
||||||
GTK_RESPONSE_OK);
|
GTK_RESPONSE_OK);
|
||||||
|
|
||||||
image = gtk_image_new_from_icon_name("dialog-password",
|
image =
|
||||||
GTK_ICON_SIZE_DIALOG);
|
gtk_image_new_from_icon_name ("dialog-password", GTK_ICON_SIZE_DIALOG);
|
||||||
gtk_dialog_set_default_response(GTK_DIALOG(dialog),
|
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
|
||||||
GTK_RESPONSE_OK);
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
|
||||||
hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
|
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 12);
|
||||||
gtk_box_pack_start(GTK_BOX(hbox),
|
|
||||||
image,
|
|
||||||
FALSE,
|
|
||||||
FALSE,
|
|
||||||
12);
|
|
||||||
|
|
||||||
/* Checks if username has been passed as a parameter */
|
/* Checks if username has been passed as a parameter */
|
||||||
gchar *title_text = N_("Type your password");
|
gchar *title_text = N_ ("Type your password");
|
||||||
|
|
||||||
if(password_data->username)
|
if (password_data->username)
|
||||||
title_text = N_("Type your username and password");
|
title_text = N_ ("Type your username and password");
|
||||||
|
|
||||||
label = gtk_label_new(title_text);
|
label = gtk_label_new (title_text);
|
||||||
|
|
||||||
gtk_box_pack_start(GTK_BOX(hbox),
|
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 12);
|
||||||
label,
|
gtk_box_pack_start (
|
||||||
FALSE,
|
GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
|
||||||
FALSE,
|
|
||||||
12);
|
|
||||||
gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),
|
|
||||||
hbox,
|
hbox,
|
||||||
FALSE,
|
FALSE,
|
||||||
TRUE,
|
TRUE,
|
||||||
5);
|
5);
|
||||||
|
|
||||||
vbox_labels = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
|
vbox_labels = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
|
||||||
vbox_entries = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
|
vbox_entries = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
|
||||||
|
|
||||||
hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
|
||||||
gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),
|
gtk_box_pack_start (
|
||||||
|
GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
|
||||||
hbox,
|
hbox,
|
||||||
FALSE,
|
FALSE,
|
||||||
TRUE,
|
TRUE,
|
||||||
5);
|
5);
|
||||||
|
|
||||||
gtk_box_pack_start(GTK_BOX(hbox),
|
gtk_box_pack_start (GTK_BOX (hbox), vbox_labels, FALSE, TRUE, 12);
|
||||||
vbox_labels,
|
gtk_box_pack_start (GTK_BOX (hbox), vbox_entries, TRUE, TRUE, 12);
|
||||||
FALSE,
|
|
||||||
TRUE,
|
|
||||||
12);
|
|
||||||
gtk_box_pack_start(GTK_BOX(hbox),
|
|
||||||
vbox_entries,
|
|
||||||
TRUE,
|
|
||||||
TRUE,
|
|
||||||
12);
|
|
||||||
|
|
||||||
if(password_data->username) {
|
if (password_data->username) {
|
||||||
label = gtk_label_new(_("Username:"));
|
label = gtk_label_new (_ ("Username:"));
|
||||||
gtk_box_pack_start(GTK_BOX(vbox_labels),
|
gtk_box_pack_start (GTK_BOX (vbox_labels), label, TRUE, FALSE, 12);
|
||||||
label,
|
password_data->entry_username = gtk_entry_new ();
|
||||||
TRUE,
|
gtk_box_pack_start (GTK_BOX (vbox_entries),
|
||||||
FALSE,
|
|
||||||
12);
|
|
||||||
password_data->entry_username = gtk_entry_new();
|
|
||||||
gtk_box_pack_start(GTK_BOX(vbox_entries),
|
|
||||||
password_data->entry_username,
|
password_data->entry_username,
|
||||||
TRUE,
|
TRUE,
|
||||||
TRUE,
|
TRUE,
|
||||||
12);
|
12);
|
||||||
}
|
}
|
||||||
|
|
||||||
label = gtk_label_new(_("Password:"));
|
label = gtk_label_new (_ ("Password:"));
|
||||||
gtk_box_pack_start(GTK_BOX(vbox_labels),
|
gtk_box_pack_start (GTK_BOX (vbox_labels), label, TRUE, FALSE, 12);
|
||||||
label,
|
password_data->entry_password = gtk_entry_new ();
|
||||||
TRUE,
|
gtk_entry_set_visibility (GTK_ENTRY (password_data->entry_password), FALSE);
|
||||||
FALSE,
|
gtk_entry_set_activates_default (
|
||||||
12);
|
GTK_ENTRY (password_data->entry_password), TRUE);
|
||||||
password_data->entry_password = gtk_entry_new();
|
gtk_box_pack_start (
|
||||||
gtk_entry_set_visibility(GTK_ENTRY(password_data->entry_password),
|
GTK_BOX (vbox_entries), password_data->entry_password, TRUE, TRUE, 12);
|
||||||
FALSE);
|
|
||||||
gtk_entry_set_activates_default (GTK_ENTRY(password_data->entry_password),
|
|
||||||
TRUE);
|
|
||||||
gtk_box_pack_start(GTK_BOX(vbox_entries),
|
|
||||||
password_data->entry_password,
|
|
||||||
TRUE,
|
|
||||||
TRUE,
|
|
||||||
12);
|
|
||||||
|
|
||||||
if (data->dialog_title)
|
if (data->dialog_title)
|
||||||
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
|
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
|
||||||
@ -147,10 +122,12 @@ void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data
|
|||||||
if (data->modal)
|
if (data->modal)
|
||||||
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
||||||
|
|
||||||
g_signal_connect (G_OBJECT (dialog), "response",
|
g_signal_connect (G_OBJECT (dialog),
|
||||||
|
"response",
|
||||||
G_CALLBACK (zenity_password_dialog_response),
|
G_CALLBACK (zenity_password_dialog_response),
|
||||||
password_data);
|
password_data);
|
||||||
gtk_widget_show_all(GTK_WIDGET(gtk_dialog_get_content_area(GTK_DIALOG(dialog))));
|
gtk_widget_show_all (
|
||||||
|
GTK_WIDGET (gtk_dialog_get_content_area (GTK_DIALOG (dialog))));
|
||||||
zenity_util_show_dialog (dialog, data->attach);
|
zenity_util_show_dialog (dialog, data->attach);
|
||||||
|
|
||||||
if (data->timeout_delay > 0) {
|
if (data->timeout_delay > 0) {
|
||||||
@ -158,20 +135,26 @@ void zenity_password_dialog (ZenityData *data, ZenityPasswordData *password_data
|
|||||||
(GSourceFunc) zenity_util_timeout_handle,
|
(GSourceFunc) zenity_util_timeout_handle,
|
||||||
dialog);
|
dialog);
|
||||||
}
|
}
|
||||||
gtk_main();
|
gtk_main ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_password_dialog_response (GtkWidget *widget, int response, gpointer data)
|
zenity_password_dialog_response (
|
||||||
{
|
GtkWidget *widget, int response, gpointer data) {
|
||||||
ZenityPasswordData *password_data = (ZenityPasswordData *) data;
|
ZenityPasswordData *password_data = (ZenityPasswordData *) data;
|
||||||
switch (response) {
|
switch (response) {
|
||||||
case GTK_RESPONSE_OK:
|
case GTK_RESPONSE_OK:
|
||||||
zenity_util_exit_code_with_data(ZENITY_OK, zen_data);
|
zenity_util_exit_code_with_data (ZENITY_OK, zen_data);
|
||||||
if (password_data->username)
|
if (password_data->username)
|
||||||
g_print("%s|%s\n", gtk_entry_get_text (GTK_ENTRY(password_data->entry_username)), gtk_entry_get_text (GTK_ENTRY(password_data->entry_password)));
|
g_print ("%s|%s\n",
|
||||||
|
gtk_entry_get_text (
|
||||||
|
GTK_ENTRY (password_data->entry_username)),
|
||||||
|
gtk_entry_get_text (
|
||||||
|
GTK_ENTRY (password_data->entry_password)));
|
||||||
else
|
else
|
||||||
g_print ("%s\n", gtk_entry_get_text (GTK_ENTRY(password_data->entry_password)));
|
g_print ("%s\n",
|
||||||
|
gtk_entry_get_text (
|
||||||
|
GTK_ENTRY (password_data->entry_password)));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GTK_RESPONSE_CANCEL:
|
case GTK_RESPONSE_CANCEL:
|
||||||
@ -179,8 +162,9 @@ zenity_password_dialog_response (GtkWidget *widget, int response, gpointer data)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (zen_data->extra_label && response < g_strv_length(zen_data->extra_label))
|
if (zen_data->extra_label &&
|
||||||
printf("%s\n",zen_data->extra_label[response]);
|
response < g_strv_length (zen_data->extra_label))
|
||||||
|
printf ("%s\n", zen_data->extra_label[response]);
|
||||||
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
219
src/progress.c
219
src/progress.c
@ -23,15 +23,15 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include "zenity.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "zenity.h"
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
static GtkBuilder *builder;
|
static GtkBuilder *builder;
|
||||||
static ZenityData *zen_data;
|
static ZenityData *zen_data;
|
||||||
@ -45,18 +45,17 @@ static gboolean auto_close;
|
|||||||
gint zenity_progress_timeout (gpointer data);
|
gint zenity_progress_timeout (gpointer data);
|
||||||
gint zenity_progress_pulsate_timeout (gpointer data);
|
gint zenity_progress_pulsate_timeout (gpointer data);
|
||||||
|
|
||||||
static void zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data);
|
static void zenity_progress_dialog_response (
|
||||||
|
GtkWidget *widget, int response, gpointer data);
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
zenity_progress_pulsate_progress_bar (gpointer user_data)
|
zenity_progress_pulsate_progress_bar (gpointer user_data) {
|
||||||
{
|
|
||||||
gtk_progress_bar_pulse (GTK_PROGRESS_BAR (user_data));
|
gtk_progress_bar_pulse (GTK_PROGRESS_BAR (user_data));
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_progress_pulsate_stop (void)
|
zenity_progress_pulsate_stop (void) {
|
||||||
{
|
|
||||||
if (pulsate_timeout > 0) {
|
if (pulsate_timeout > 0) {
|
||||||
g_source_remove (pulsate_timeout);
|
g_source_remove (pulsate_timeout);
|
||||||
pulsate_timeout = -1;
|
pulsate_timeout = -1;
|
||||||
@ -64,53 +63,51 @@ zenity_progress_pulsate_stop (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_progress_pulsate_start (GObject *progress_bar)
|
zenity_progress_pulsate_start (GObject *progress_bar) {
|
||||||
{
|
|
||||||
if (pulsate_timeout == -1) {
|
if (pulsate_timeout == -1) {
|
||||||
pulsate_timeout = g_timeout_add (100,
|
pulsate_timeout = g_timeout_add (
|
||||||
zenity_progress_pulsate_progress_bar,
|
100, zenity_progress_pulsate_progress_bar, progress_bar);
|
||||||
progress_bar);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_progress_update_time_remaining (ZenityProgressData *progress_data)
|
zenity_progress_update_time_remaining (ZenityProgressData *progress_data) {
|
||||||
{
|
|
||||||
static GObject *progress_time = NULL;
|
static GObject *progress_time = NULL;
|
||||||
static time_t start_time = (time_t)(-1);
|
static time_t start_time = (time_t) (-1);
|
||||||
float percentage = progress_data->percentage;
|
float percentage = progress_data->percentage;
|
||||||
|
|
||||||
if (progress_time == NULL)
|
if (progress_time == NULL)
|
||||||
progress_time = gtk_builder_get_object (builder, "zenity_progress_time");
|
progress_time =
|
||||||
if (start_time == (time_t)(-1) || percentage <= 0.0 || percentage >= 100.0) {
|
gtk_builder_get_object (builder, "zenity_progress_time");
|
||||||
start_time = time(NULL);
|
if (start_time == (time_t) (-1) || percentage <= 0.0 ||
|
||||||
|
percentage >= 100.0) {
|
||||||
|
start_time = time (NULL);
|
||||||
gtk_label_set_text (GTK_LABEL (progress_time), "");
|
gtk_label_set_text (GTK_LABEL (progress_time), "");
|
||||||
} else {
|
} else {
|
||||||
time_t current_time = time (NULL);
|
time_t current_time = time (NULL);
|
||||||
time_t elapsed_time = current_time - start_time;
|
time_t elapsed_time = current_time - start_time;
|
||||||
time_t total_time = (time_t) (100.0*elapsed_time/progress_data->percentage);
|
time_t total_time =
|
||||||
|
(time_t) (100.0 * elapsed_time / progress_data->percentage);
|
||||||
time_t remaining_time = total_time - elapsed_time;
|
time_t remaining_time = total_time - elapsed_time;
|
||||||
gulong hours, minutes, seconds;
|
gulong hours, minutes, seconds;
|
||||||
gchar *remaining_message;
|
gchar *remaining_message;
|
||||||
|
|
||||||
seconds = (gulong) (remaining_time%60);
|
seconds = (gulong) (remaining_time % 60);
|
||||||
remaining_time /= 60;
|
remaining_time /= 60;
|
||||||
minutes = (gulong) (remaining_time%60);
|
minutes = (gulong) (remaining_time % 60);
|
||||||
remaining_time /= 60;
|
remaining_time /= 60;
|
||||||
hours = (gulong) remaining_time;
|
hours = (gulong) remaining_time;
|
||||||
|
|
||||||
remaining_message = g_strdup_printf (_("Time remaining: %lu:%02lu:%02lu"),
|
remaining_message = g_strdup_printf (
|
||||||
hours, minutes, seconds);
|
_ ("Time remaining: %lu:%02lu:%02lu"), hours, minutes, seconds);
|
||||||
gtk_label_set_text (GTK_LABEL (progress_time), remaining_message);
|
gtk_label_set_text (GTK_LABEL (progress_time), remaining_message);
|
||||||
g_free (remaining_message);
|
g_free (remaining_message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
zenity_progress_handle_stdin (GIOChannel *channel,
|
zenity_progress_handle_stdin (
|
||||||
GIOCondition condition,
|
GIOChannel *channel, GIOCondition condition, gpointer data) {
|
||||||
gpointer data)
|
|
||||||
{
|
|
||||||
static ZenityProgressData *progress_data;
|
static ZenityProgressData *progress_data;
|
||||||
static GObject *progress_bar;
|
static GObject *progress_bar;
|
||||||
static GObject *progress_label;
|
static GObject *progress_label;
|
||||||
@ -131,7 +128,8 @@ zenity_progress_handle_stdin (GIOChannel *channel,
|
|||||||
;
|
;
|
||||||
do {
|
do {
|
||||||
do {
|
do {
|
||||||
status = g_io_channel_read_line_string (channel, string, NULL, &error);
|
status = g_io_channel_read_line_string (
|
||||||
|
channel, string, NULL, &error);
|
||||||
|
|
||||||
while (gtk_events_pending ())
|
while (gtk_events_pending ())
|
||||||
gtk_main_iteration ();
|
gtk_main_iteration ();
|
||||||
@ -140,7 +138,8 @@ zenity_progress_handle_stdin (GIOChannel *channel,
|
|||||||
|
|
||||||
if (status != G_IO_STATUS_NORMAL) {
|
if (status != G_IO_STATUS_NORMAL) {
|
||||||
if (error) {
|
if (error) {
|
||||||
g_warning ("zenity_progress_handle_stdin () : %s", error->message);
|
g_warning (
|
||||||
|
"zenity_progress_handle_stdin () : %s", error->message);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
error = NULL;
|
error = NULL;
|
||||||
}
|
}
|
||||||
@ -153,28 +152,32 @@ zenity_progress_handle_stdin (GIOChannel *channel,
|
|||||||
/* We have a comment, so let's try to change the label */
|
/* We have a comment, so let's try to change the label */
|
||||||
match = g_strstr_len (string->str, strlen (string->str), "#");
|
match = g_strstr_len (string->str, strlen (string->str), "#");
|
||||||
match++;
|
match++;
|
||||||
gtk_label_set_text (GTK_LABEL (progress_label), g_strcompress(g_strchomp (g_strchug (match))));
|
gtk_label_set_text (GTK_LABEL (progress_label),
|
||||||
|
g_strcompress (g_strchomp (g_strchug (match))));
|
||||||
|
|
||||||
} else if (g_str_has_prefix (string->str, "pulsate")) {
|
} else if (g_str_has_prefix (string->str, "pulsate")) {
|
||||||
gchar *colon, *command, *value;
|
gchar *colon, *command, *value;
|
||||||
|
|
||||||
zenity_util_strip_newline (string->str);
|
zenity_util_strip_newline (string->str);
|
||||||
|
|
||||||
colon = strchr(string->str, ':');
|
colon = strchr (string->str, ':');
|
||||||
if (colon == NULL) {
|
if (colon == NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* split off the command and value */
|
/* split off the command and value */
|
||||||
command = g_strstrip (g_strndup (string->str, colon - string->str));
|
command =
|
||||||
|
g_strstrip (g_strndup (string->str, colon - string->str));
|
||||||
|
|
||||||
value = colon + 1;
|
value = colon + 1;
|
||||||
while (*value && g_ascii_isspace (*value)) value++;
|
while (*value && g_ascii_isspace (*value))
|
||||||
|
value++;
|
||||||
|
|
||||||
if (!g_ascii_strcasecmp (value, "false")) {
|
if (!g_ascii_strcasecmp (value, "false")) {
|
||||||
zenity_progress_pulsate_stop ();
|
zenity_progress_pulsate_stop ();
|
||||||
|
|
||||||
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar),
|
gtk_progress_bar_set_fraction (
|
||||||
|
GTK_PROGRESS_BAR (progress_bar),
|
||||||
progress_data->percentage / 100.0);
|
progress_data->percentage / 100.0);
|
||||||
} else {
|
} else {
|
||||||
zenity_progress_pulsate_start (progress_bar);
|
zenity_progress_pulsate_start (progress_bar);
|
||||||
@ -187,10 +190,10 @@ zenity_progress_handle_stdin (GIOChannel *channel,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Now try to convert the thing to a number */
|
/* Now try to convert the thing to a number */
|
||||||
percentage = CLAMP(atoi (string->str), 0, 100);
|
percentage = CLAMP (atoi (string->str), 0, 100);
|
||||||
|
|
||||||
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar),
|
gtk_progress_bar_set_fraction (
|
||||||
percentage / 100.0);
|
GTK_PROGRESS_BAR (progress_bar), percentage / 100.0);
|
||||||
|
|
||||||
progress_data->percentage = percentage;
|
progress_data->percentage = percentage;
|
||||||
|
|
||||||
@ -200,32 +203,37 @@ zenity_progress_handle_stdin (GIOChannel *channel,
|
|||||||
if (percentage == 100) {
|
if (percentage == 100) {
|
||||||
GObject *button;
|
GObject *button;
|
||||||
|
|
||||||
button = gtk_builder_get_object(builder, "zenity_progress_ok_button");
|
button = gtk_builder_get_object (
|
||||||
gtk_widget_set_sensitive(GTK_WIDGET (button), TRUE);
|
builder, "zenity_progress_ok_button");
|
||||||
gtk_widget_grab_focus(GTK_WIDGET (button));
|
gtk_widget_set_sensitive (GTK_WIDGET (button), TRUE);
|
||||||
|
gtk_widget_grab_focus (GTK_WIDGET (button));
|
||||||
|
|
||||||
if (progress_data->autoclose) {
|
if (progress_data->autoclose) {
|
||||||
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
|
zen_data->exit_code =
|
||||||
gtk_main_quit();
|
zenity_util_return_exit_code (ZENITY_OK);
|
||||||
|
gtk_main_quit ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} while ((g_io_channel_get_buffer_condition (channel) & G_IO_IN) == G_IO_IN && status != G_IO_STATUS_EOF);
|
} while ((g_io_channel_get_buffer_condition (channel) & G_IO_IN) ==
|
||||||
|
G_IO_IN &&
|
||||||
|
status != G_IO_STATUS_EOF);
|
||||||
g_string_free (string, TRUE);
|
g_string_free (string, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((condition & G_IO_IN) != G_IO_IN || status == G_IO_STATUS_EOF) {
|
if ((condition & G_IO_IN) != G_IO_IN || status == G_IO_STATUS_EOF) {
|
||||||
/* We assume that we are done, so stop the pulsating and de-sensitize the buttons */
|
/* We assume that we are done, so stop the pulsating and de-sensitize
|
||||||
|
* the buttons */
|
||||||
GtkWidget *button;
|
GtkWidget *button;
|
||||||
|
|
||||||
button = GTK_WIDGET (gtk_builder_get_object (builder,
|
button = GTK_WIDGET (
|
||||||
"zenity_progress_ok_button"));
|
gtk_builder_get_object (builder, "zenity_progress_ok_button"));
|
||||||
gtk_widget_set_sensitive (button, TRUE);
|
gtk_widget_set_sensitive (button, TRUE);
|
||||||
gtk_widget_grab_focus (button);
|
gtk_widget_grab_focus (button);
|
||||||
|
|
||||||
button = GTK_WIDGET (gtk_builder_get_object (builder,
|
button = GTK_WIDGET (
|
||||||
"zenity_progress_cancel_button"));
|
gtk_builder_get_object (builder, "zenity_progress_cancel_button"));
|
||||||
|
|
||||||
gtk_widget_set_sensitive (button, FALSE);
|
gtk_widget_set_sensitive (button, FALSE);
|
||||||
|
|
||||||
@ -237,7 +245,7 @@ zenity_progress_handle_stdin (GIOChannel *channel,
|
|||||||
|
|
||||||
if (progress_data->autoclose) {
|
if (progress_data->autoclose) {
|
||||||
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
|
||||||
gtk_main_quit();
|
gtk_main_quit ();
|
||||||
}
|
}
|
||||||
|
|
||||||
g_io_channel_shutdown (channel, TRUE, NULL);
|
g_io_channel_shutdown (channel, TRUE, NULL);
|
||||||
@ -247,35 +255,37 @@ zenity_progress_handle_stdin (GIOChannel *channel,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_progress_read_info (ZenityProgressData *progress_data)
|
zenity_progress_read_info (ZenityProgressData *progress_data) {
|
||||||
{
|
|
||||||
channel = g_io_channel_unix_new (0);
|
channel = g_io_channel_unix_new (0);
|
||||||
g_io_channel_set_encoding (channel, NULL, NULL);
|
g_io_channel_set_encoding (channel, NULL, NULL);
|
||||||
g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL);
|
g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL);
|
||||||
g_io_add_watch (channel, G_IO_IN | G_IO_HUP, zenity_progress_handle_stdin, progress_data);
|
g_io_add_watch (channel,
|
||||||
|
G_IO_IN | G_IO_HUP,
|
||||||
|
zenity_progress_handle_stdin,
|
||||||
|
progress_data);
|
||||||
/* We need to check the pulsate state here, because, the g_io_add_watch
|
/* We need to check the pulsate state here, because, the g_io_add_watch
|
||||||
doesn't call the zenity_progress_handle_stdin function if there's no
|
doesn't call the zenity_progress_handle_stdin function if there's no
|
||||||
input. This fix the Bug 567663 */
|
input. This fix the Bug 567663 */
|
||||||
if (progress_data->pulsate) {
|
if (progress_data->pulsate) {
|
||||||
GObject *progress_bar = gtk_builder_get_object (builder, "zenity_progress_bar");
|
GObject *progress_bar =
|
||||||
|
gtk_builder_get_object (builder, "zenity_progress_bar");
|
||||||
zenity_progress_pulsate_start (progress_bar);
|
zenity_progress_pulsate_start (progress_bar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_text_size_allocate (GtkWidget *widget, GtkAllocation *allocation, gpointer data)
|
zenity_text_size_allocate (
|
||||||
{
|
GtkWidget *widget, GtkAllocation *allocation, gpointer data) {
|
||||||
gtk_widget_set_size_request (widget, allocation->width/2, -1);
|
gtk_widget_set_size_request (widget, allocation->width / 2, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
zenity_progress (ZenityData *data, ZenityProgressData *progress_data)
|
zenity_progress (ZenityData *data, ZenityProgressData *progress_data) {
|
||||||
{
|
|
||||||
GtkWidget *dialog;
|
GtkWidget *dialog;
|
||||||
GtkWidget *button;
|
GtkWidget *button;
|
||||||
GObject *text;
|
GObject *text;
|
||||||
GObject *progress_bar;
|
GObject *progress_bar;
|
||||||
GObject *cancel_button,*ok_button;
|
GObject *cancel_button, *ok_button;
|
||||||
|
|
||||||
zen_data = data;
|
zen_data = data;
|
||||||
builder = zenity_util_load_ui_file ("zenity_progress_dialog", NULL);
|
builder = zenity_util_load_ui_file ("zenity_progress_dialog", NULL);
|
||||||
@ -289,59 +299,71 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data)
|
|||||||
|
|
||||||
text = gtk_builder_get_object (builder, "zenity_progress_text");
|
text = gtk_builder_get_object (builder, "zenity_progress_text");
|
||||||
|
|
||||||
dialog = GTK_WIDGET (gtk_builder_get_object (builder,
|
dialog =
|
||||||
"zenity_progress_dialog"));
|
GTK_WIDGET (gtk_builder_get_object (builder, "zenity_progress_dialog"));
|
||||||
|
|
||||||
progress_bar = gtk_builder_get_object (builder, "zenity_progress_bar");
|
progress_bar = gtk_builder_get_object (builder, "zenity_progress_bar");
|
||||||
|
|
||||||
g_signal_connect (G_OBJECT (dialog), "response",
|
g_signal_connect (G_OBJECT (dialog),
|
||||||
G_CALLBACK (zenity_progress_dialog_response), data);
|
"response",
|
||||||
|
G_CALLBACK (zenity_progress_dialog_response),
|
||||||
|
data);
|
||||||
|
|
||||||
if (data->dialog_title)
|
if (data->dialog_title)
|
||||||
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
|
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
|
||||||
|
|
||||||
zenity_util_set_window_icon (dialog, data->window_icon, ZENITY_IMAGE_FULLPATH ("zenity-progress.png"));
|
zenity_util_set_window_icon (dialog,
|
||||||
|
data->window_icon,
|
||||||
|
ZENITY_IMAGE_FULLPATH ("zenity-progress.png"));
|
||||||
|
|
||||||
if (data->width > -1 || data->height > -1)
|
if (data->width > -1 || data->height > -1)
|
||||||
gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height);
|
gtk_window_set_default_size (
|
||||||
|
GTK_WINDOW (dialog), data->width, data->height);
|
||||||
|
|
||||||
if (data->width > -1) {
|
if (data->width > -1) {
|
||||||
gtk_widget_set_size_request (GTK_WIDGET (text), data->width, -1);
|
gtk_widget_set_size_request (GTK_WIDGET (text), data->width, -1);
|
||||||
}
|
} else {
|
||||||
else {
|
g_signal_connect_after (G_OBJECT (text),
|
||||||
g_signal_connect_after (G_OBJECT (text), "size-allocate",
|
"size-allocate",
|
||||||
G_CALLBACK (zenity_text_size_allocate), data);
|
G_CALLBACK (zenity_text_size_allocate),
|
||||||
g_signal_connect_after (G_OBJECT (progress_bar), "size-allocate",
|
data);
|
||||||
G_CALLBACK (zenity_text_size_allocate), data);
|
g_signal_connect_after (G_OBJECT (progress_bar),
|
||||||
|
"size-allocate",
|
||||||
|
G_CALLBACK (zenity_text_size_allocate),
|
||||||
|
data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->modal)
|
if (data->modal)
|
||||||
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
||||||
|
|
||||||
if (data->extra_label) {
|
if (data->extra_label) {
|
||||||
gint i=0;
|
gint i = 0;
|
||||||
while(data->extra_label[i]!=NULL){
|
while (data->extra_label[i] != NULL) {
|
||||||
gtk_dialog_add_button (GTK_DIALOG (dialog), data->extra_label[i], i);
|
gtk_dialog_add_button (
|
||||||
|
GTK_DIALOG (dialog), data->extra_label[i], i);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->ok_label) {
|
if (data->ok_label) {
|
||||||
button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_progress_ok_button"));
|
button = GTK_WIDGET (
|
||||||
|
gtk_builder_get_object (builder, "zenity_progress_ok_button"));
|
||||||
gtk_button_set_label (GTK_BUTTON (button), data->ok_label);
|
gtk_button_set_label (GTK_BUTTON (button), data->ok_label);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->cancel_label) {
|
if (data->cancel_label) {
|
||||||
button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_progress_cancel_button"));
|
button = GTK_WIDGET (
|
||||||
|
gtk_builder_get_object (builder, "zenity_progress_cancel_button"));
|
||||||
gtk_button_set_label (GTK_BUTTON (button), data->cancel_label);
|
gtk_button_set_label (GTK_BUTTON (button), data->cancel_label);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (progress_data->dialog_text)
|
if (progress_data->dialog_text)
|
||||||
gtk_label_set_markup (GTK_LABEL (text), g_strcompress (progress_data->dialog_text));
|
gtk_label_set_markup (
|
||||||
|
GTK_LABEL (text), g_strcompress (progress_data->dialog_text));
|
||||||
|
|
||||||
if (progress_data->percentage > -1)
|
if (progress_data->percentage > -1)
|
||||||
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar),
|
gtk_progress_bar_set_fraction (
|
||||||
progress_data->percentage/100.0);
|
GTK_PROGRESS_BAR (progress_bar), progress_data->percentage / 100.0);
|
||||||
|
|
||||||
autokill = progress_data->autokill;
|
autokill = progress_data->autokill;
|
||||||
|
|
||||||
@ -349,36 +371,40 @@ zenity_progress (ZenityData *data, ZenityProgressData *progress_data)
|
|||||||
ok_button = gtk_builder_get_object (builder, "zenity_progress_ok_button");
|
ok_button = gtk_builder_get_object (builder, "zenity_progress_ok_button");
|
||||||
|
|
||||||
no_cancel = progress_data->no_cancel;
|
no_cancel = progress_data->no_cancel;
|
||||||
cancel_button = gtk_builder_get_object (builder, "zenity_progress_cancel_button");
|
cancel_button =
|
||||||
|
gtk_builder_get_object (builder, "zenity_progress_cancel_button");
|
||||||
|
|
||||||
if (no_cancel) {
|
if (no_cancel) {
|
||||||
gtk_widget_hide (GTK_WIDGET(cancel_button));
|
gtk_widget_hide (GTK_WIDGET (cancel_button));
|
||||||
gtk_window_set_deletable (GTK_WINDOW (dialog), FALSE);
|
gtk_window_set_deletable (GTK_WINDOW (dialog), FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (no_cancel && auto_close)
|
if (no_cancel && auto_close)
|
||||||
gtk_widget_hide(GTK_WIDGET(ok_button));
|
gtk_widget_hide (GTK_WIDGET (ok_button));
|
||||||
|
|
||||||
zenity_util_show_dialog (dialog, data->attach);
|
zenity_util_show_dialog (dialog, data->attach);
|
||||||
zenity_progress_read_info (progress_data);
|
zenity_progress_read_info (progress_data);
|
||||||
|
|
||||||
if(data->timeout_delay > 0) {
|
if (data->timeout_delay > 0) {
|
||||||
g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, NULL);
|
g_timeout_add_seconds (data->timeout_delay,
|
||||||
|
(GSourceFunc) zenity_util_timeout_handle,
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_main ();
|
gtk_main ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data)
|
zenity_progress_dialog_response (
|
||||||
{
|
GtkWidget *widget, int response, gpointer data) {
|
||||||
switch (response) {
|
switch (response) {
|
||||||
case GTK_RESPONSE_OK:
|
case GTK_RESPONSE_OK:
|
||||||
zenity_util_exit_code_with_data(ZENITY_OK, zen_data);
|
zenity_util_exit_code_with_data (ZENITY_OK, zen_data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GTK_RESPONSE_CANCEL:
|
case GTK_RESPONSE_CANCEL:
|
||||||
/* We do not want to kill the parent process, in order to give the user
|
/* We do not want to kill the parent process, in order to give the
|
||||||
|
user
|
||||||
the ability to choose the action to be taken. See bug #310824.
|
the ability to choose the action to be taken. See bug #310824.
|
||||||
But we want to give people the option to choose this behavior.
|
But we want to give people the option to choose this behavior.
|
||||||
-- Monday 27, March 2006
|
-- Monday 27, March 2006
|
||||||
@ -393,8 +419,9 @@ zenity_progress_dialog_response (GtkWidget *widget, int response, gpointer data)
|
|||||||
zenity_util_exit_code_with_data (ZENITY_TIMEOUT, zen_data);
|
zenity_util_exit_code_with_data (ZENITY_TIMEOUT, zen_data);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (zen_data->extra_label && response < g_strv_length(zen_data->extra_label))
|
if (zen_data->extra_label &&
|
||||||
printf("%s\n",zen_data->extra_label[response]);
|
response < g_strv_length (zen_data->extra_label))
|
||||||
|
printf ("%s\n", zen_data->extra_label[response]);
|
||||||
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
77
src/scale.c
77
src/scale.c
@ -23,45 +23,50 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "zenity.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "zenity.h"
|
||||||
|
|
||||||
static GtkWidget *scale;
|
static GtkWidget *scale;
|
||||||
|
|
||||||
static void zenity_scale_value_changed (GtkWidget *widget, gpointer data);
|
static void zenity_scale_value_changed (GtkWidget *widget, gpointer data);
|
||||||
static void zenity_scale_dialog_response (GtkWidget *widget, int response, gpointer data);
|
static void zenity_scale_dialog_response (
|
||||||
|
GtkWidget *widget, int response, gpointer data);
|
||||||
|
|
||||||
void
|
void
|
||||||
zenity_scale (ZenityData *data, ZenityScaleData *scale_data)
|
zenity_scale (ZenityData *data, ZenityScaleData *scale_data) {
|
||||||
{
|
|
||||||
GtkBuilder *builder;
|
GtkBuilder *builder;
|
||||||
GtkWidget *dialog;
|
GtkWidget *dialog;
|
||||||
GtkWidget *button;
|
GtkWidget *button;
|
||||||
GObject *text;
|
GObject *text;
|
||||||
|
|
||||||
builder = zenity_util_load_ui_file ("zenity_scale_dialog", "adjustment1", NULL);
|
builder =
|
||||||
|
zenity_util_load_ui_file ("zenity_scale_dialog", "adjustment1", NULL);
|
||||||
|
|
||||||
if (builder == NULL) {
|
if (builder == NULL) {
|
||||||
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
|
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_scale_dialog"));
|
dialog =
|
||||||
scale = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_scale_hscale"));
|
GTK_WIDGET (gtk_builder_get_object (builder, "zenity_scale_dialog"));
|
||||||
|
scale =
|
||||||
|
GTK_WIDGET (gtk_builder_get_object (builder, "zenity_scale_hscale"));
|
||||||
text = gtk_builder_get_object (builder, "zenity_scale_text");
|
text = gtk_builder_get_object (builder, "zenity_scale_text");
|
||||||
|
|
||||||
g_signal_connect (G_OBJECT (dialog), "response",
|
g_signal_connect (G_OBJECT (dialog),
|
||||||
G_CALLBACK (zenity_scale_dialog_response), data);
|
"response",
|
||||||
|
G_CALLBACK (zenity_scale_dialog_response),
|
||||||
|
data);
|
||||||
|
|
||||||
if (scale_data->min_value >= scale_data->max_value) {
|
if (scale_data->min_value >= scale_data->max_value) {
|
||||||
g_printerr (_("Maximum value must be greater than minimum value.\n"));
|
g_printerr (_ ("Maximum value must be greater than minimum value.\n"));
|
||||||
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
|
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scale_data->value < scale_data->min_value ||
|
if (scale_data->value < scale_data->min_value ||
|
||||||
scale_data->value > scale_data->max_value) {
|
scale_data->value > scale_data->max_value) {
|
||||||
g_printerr (_("Value out of range.\n"));
|
g_printerr (_ ("Value out of range.\n"));
|
||||||
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
|
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -71,50 +76,61 @@ zenity_scale (ZenityData *data, ZenityScaleData *scale_data)
|
|||||||
if (data->dialog_title)
|
if (data->dialog_title)
|
||||||
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
|
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
|
||||||
|
|
||||||
zenity_util_set_window_icon (dialog, data->window_icon, ZENITY_IMAGE_FULLPATH ("zenity-scale.png"));
|
zenity_util_set_window_icon (
|
||||||
|
dialog, data->window_icon, ZENITY_IMAGE_FULLPATH ("zenity-scale.png"));
|
||||||
|
|
||||||
if (data->width > -1 || data->height > -1)
|
if (data->width > -1 || data->height > -1)
|
||||||
gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height);
|
gtk_window_set_default_size (
|
||||||
|
GTK_WINDOW (dialog), data->width, data->height);
|
||||||
|
|
||||||
if (data->modal)
|
if (data->modal)
|
||||||
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
||||||
|
|
||||||
if (data->extra_label) {
|
if (data->extra_label) {
|
||||||
gint i=0;
|
gint i = 0;
|
||||||
while(data->extra_label[i]!=NULL){
|
while (data->extra_label[i] != NULL) {
|
||||||
gtk_dialog_add_button (GTK_DIALOG (dialog), data->extra_label[i], i);
|
gtk_dialog_add_button (
|
||||||
|
GTK_DIALOG (dialog), data->extra_label[i], i);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->ok_label) {
|
if (data->ok_label) {
|
||||||
button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_scale_ok_button"));
|
button = GTK_WIDGET (
|
||||||
|
gtk_builder_get_object (builder, "zenity_scale_ok_button"));
|
||||||
gtk_button_set_label (GTK_BUTTON (button), data->ok_label);
|
gtk_button_set_label (GTK_BUTTON (button), data->ok_label);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->cancel_label) {
|
if (data->cancel_label) {
|
||||||
button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_scale_cancel_button"));
|
button = GTK_WIDGET (
|
||||||
|
gtk_builder_get_object (builder, "zenity_scale_cancel_button"));
|
||||||
gtk_button_set_label (GTK_BUTTON (button), data->cancel_label);
|
gtk_button_set_label (GTK_BUTTON (button), data->cancel_label);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scale_data->dialog_text)
|
if (scale_data->dialog_text)
|
||||||
gtk_label_set_markup (GTK_LABEL (text), g_strcompress (scale_data->dialog_text));
|
gtk_label_set_markup (
|
||||||
|
GTK_LABEL (text), g_strcompress (scale_data->dialog_text));
|
||||||
|
|
||||||
gtk_range_set_range (GTK_RANGE (scale), scale_data->min_value, scale_data->max_value);
|
gtk_range_set_range (
|
||||||
|
GTK_RANGE (scale), scale_data->min_value, scale_data->max_value);
|
||||||
gtk_range_set_value (GTK_RANGE (scale), scale_data->value);
|
gtk_range_set_value (GTK_RANGE (scale), scale_data->value);
|
||||||
gtk_range_set_increments (GTK_RANGE (scale), scale_data->step, 0);
|
gtk_range_set_increments (GTK_RANGE (scale), scale_data->step, 0);
|
||||||
|
|
||||||
if (scale_data->print_partial)
|
if (scale_data->print_partial)
|
||||||
g_signal_connect (G_OBJECT (scale), "value-changed",
|
g_signal_connect (G_OBJECT (scale),
|
||||||
G_CALLBACK (zenity_scale_value_changed), data);
|
"value-changed",
|
||||||
|
G_CALLBACK (zenity_scale_value_changed),
|
||||||
|
data);
|
||||||
|
|
||||||
if (scale_data->hide_value)
|
if (scale_data->hide_value)
|
||||||
gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
|
gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
|
||||||
|
|
||||||
zenity_util_show_dialog (dialog, data->attach);
|
zenity_util_show_dialog (dialog, data->attach);
|
||||||
|
|
||||||
if(data->timeout_delay > 0) {
|
if (data->timeout_delay > 0) {
|
||||||
g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, dialog);
|
g_timeout_add_seconds (data->timeout_delay,
|
||||||
|
(GSourceFunc) zenity_util_timeout_handle,
|
||||||
|
dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_object_unref (builder);
|
g_object_unref (builder);
|
||||||
@ -123,19 +139,17 @@ zenity_scale (ZenityData *data, ZenityScaleData *scale_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_scale_value_changed (GtkWidget *widget, gpointer data)
|
zenity_scale_value_changed (GtkWidget *widget, gpointer data) {
|
||||||
{
|
|
||||||
g_print ("%.0f\n", gtk_range_get_value (GTK_RANGE (widget)));
|
g_print ("%.0f\n", gtk_range_get_value (GTK_RANGE (widget)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_scale_dialog_response (GtkWidget *widget, int response, gpointer data)
|
zenity_scale_dialog_response (GtkWidget *widget, int response, gpointer data) {
|
||||||
{
|
|
||||||
ZenityData *zen_data = data;
|
ZenityData *zen_data = data;
|
||||||
|
|
||||||
switch (response) {
|
switch (response) {
|
||||||
case GTK_RESPONSE_OK:
|
case GTK_RESPONSE_OK:
|
||||||
zenity_util_exit_code_with_data(ZENITY_OK, zen_data);
|
zenity_util_exit_code_with_data (ZENITY_OK, zen_data);
|
||||||
g_print ("%.0f\n", gtk_range_get_value (GTK_RANGE (scale)));
|
g_print ("%.0f\n", gtk_range_get_value (GTK_RANGE (scale)));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -149,8 +163,9 @@ zenity_scale_dialog_response (GtkWidget *widget, int response, gpointer data)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (zen_data->extra_label && response < g_strv_length(zen_data->extra_label))
|
if (zen_data->extra_label &&
|
||||||
printf("%s\n",zen_data->extra_label[response]);
|
response < g_strv_length (zen_data->extra_label))
|
||||||
|
printf ("%s\n", zen_data->extra_label[response]);
|
||||||
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
281
src/text.c
281
src/text.c
@ -23,9 +23,9 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <gio/gio.h>
|
|
||||||
#include "zenity.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "zenity.h"
|
||||||
|
#include <gio/gio.h>
|
||||||
|
|
||||||
#ifdef HAVE_WEBKITGTK
|
#ifdef HAVE_WEBKITGTK
|
||||||
#include <webkit2/webkit2.h>
|
#include <webkit2/webkit2.h>
|
||||||
@ -33,98 +33,124 @@
|
|||||||
|
|
||||||
static ZenityTextData *zen_text_data;
|
static ZenityTextData *zen_text_data;
|
||||||
|
|
||||||
static void zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data);
|
static void zenity_text_dialog_response (
|
||||||
|
GtkWidget *widget, int response, gpointer data);
|
||||||
static void zenity_text_toggle_button (GtkToggleButton *button, gpointer data);
|
static void zenity_text_toggle_button (GtkToggleButton *button, gpointer data);
|
||||||
|
|
||||||
#ifdef HAVE_WEBKITGTK
|
#ifdef HAVE_WEBKITGTK
|
||||||
static void
|
static void
|
||||||
zenity_configure_webkit (WebKitWebView *web_view)
|
zenity_configure_webkit (WebKitWebView *web_view) {
|
||||||
{
|
|
||||||
WebKitSettings *settings;
|
WebKitSettings *settings;
|
||||||
settings = webkit_web_view_get_settings(web_view);
|
settings = webkit_web_view_get_settings (web_view);
|
||||||
g_object_set(G_OBJECT(settings), "auto-load-images", TRUE, NULL);
|
g_object_set (G_OBJECT (settings), "auto-load-images", TRUE, NULL);
|
||||||
/*
|
/*
|
||||||
Stick to the defaults
|
Stick to the defaults
|
||||||
"cursive-font-family" gchar* : Read / Write / Construct
|
"cursive-font-family" gchar* : Read / Write /
|
||||||
"default-encoding" gchar* : Read / Write / Construct
|
Construct
|
||||||
"default-font-family" gchar* : Read / Write / Construct
|
"default-encoding" gchar* : Read / Write /
|
||||||
"default-font-size" gint : Read / Write / Construct
|
Construct
|
||||||
"default-monospace-font-size" gint : Read / Write / Construct
|
"default-font-family" gchar* : Read / Write /
|
||||||
"editing-behavior" WebKitEditingBehavior : Read / Write / Construct
|
Construct
|
||||||
|
"default-font-size" gint : Read / Write /
|
||||||
|
Construct
|
||||||
|
"default-monospace-font-size" gint : Read / Write /
|
||||||
|
Construct
|
||||||
|
"editing-behavior" WebKitEditingBehavior : Read / Write /
|
||||||
|
Construct
|
||||||
*/
|
*/
|
||||||
g_object_set(G_OBJECT(settings), "enable-caret-browsing", FALSE, NULL);
|
g_object_set (G_OBJECT (settings), "enable-caret-browsing", FALSE, NULL);
|
||||||
g_object_set(G_OBJECT(settings), "enable-developer-extras", FALSE, NULL);
|
g_object_set (G_OBJECT (settings), "enable-developer-extras", FALSE, NULL);
|
||||||
g_object_set(G_OBJECT(settings), "enable-fullscreen", FALSE, NULL);
|
g_object_set (G_OBJECT (settings), "enable-fullscreen", FALSE, NULL);
|
||||||
g_object_set(G_OBJECT(settings), "enable-html5-database", FALSE, NULL);
|
g_object_set (G_OBJECT (settings), "enable-html5-database", FALSE, NULL);
|
||||||
g_object_set(G_OBJECT(settings), "enable-html5-local-storage", FALSE, NULL);
|
g_object_set (
|
||||||
g_object_set(G_OBJECT(settings), "enable-java", FALSE, NULL);
|
G_OBJECT (settings), "enable-html5-local-storage", FALSE, NULL);
|
||||||
g_object_set(G_OBJECT(settings), "enable-javascript", FALSE, NULL);
|
g_object_set (G_OBJECT (settings), "enable-java", FALSE, NULL);
|
||||||
g_object_set(G_OBJECT(settings), "enable-offline-web-application-cache", FALSE, NULL);
|
g_object_set (G_OBJECT (settings), "enable-javascript", FALSE, NULL);
|
||||||
g_object_set(G_OBJECT(settings), "enable-page-cache", FALSE, NULL);
|
g_object_set (G_OBJECT (settings),
|
||||||
g_object_set(G_OBJECT(settings), "enable-plugins", FALSE, NULL);
|
"enable-offline-web-application-cache",
|
||||||
g_object_set(G_OBJECT(settings), "enable-private-browsing", TRUE, NULL);
|
FALSE,
|
||||||
|
NULL);
|
||||||
|
g_object_set (G_OBJECT (settings), "enable-page-cache", FALSE, NULL);
|
||||||
|
g_object_set (G_OBJECT (settings), "enable-plugins", FALSE, NULL);
|
||||||
|
g_object_set (G_OBJECT (settings), "enable-private-browsing", TRUE, NULL);
|
||||||
/*
|
/*
|
||||||
Stick to defaults
|
Stick to defaults
|
||||||
"enforce-96-dpi" gboolean : Read / Write / Construct
|
"enforce-96-dpi" gboolean : Read / Write /
|
||||||
"fantasy-font-family" gchar* : Read / Write / Construct
|
Construct
|
||||||
|
"fantasy-font-family" gchar* : Read / Write /
|
||||||
|
Construct
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
Stick to defaults
|
Stick to defaults
|
||||||
"minimum-font-size" gint : Read / Write / Construct
|
"minimum-font-size" gint : Read / Write /
|
||||||
"minimum-logical-font-size" gint : Read / Write / Construct
|
Construct
|
||||||
"monospace-font-family" gchar* : Read / Write / Construct
|
"minimum-logical-font-size" gint : Read / Write /
|
||||||
"print-backgrounds" gboolean : Read / Write / Construct
|
Construct
|
||||||
"resizable-text-areas" gboolean : Read / Write / Construct
|
"monospace-font-family" gchar* : Read / Write /
|
||||||
"sans-serif-font-family" gchar* : Read / Write / Construct
|
Construct
|
||||||
"serif-font-family" gchar* : Read / Write / Construct
|
"print-backgrounds" gboolean : Read / Write /
|
||||||
"spell-checking-languages" gchar* : Read / Write / Construct
|
Construct
|
||||||
|
"resizable-text-areas" gboolean : Read / Write /
|
||||||
|
Construct
|
||||||
|
"sans-serif-font-family" gchar* : Read / Write /
|
||||||
|
Construct
|
||||||
|
"serif-font-family" gchar* : Read / Write /
|
||||||
|
Construct
|
||||||
|
"spell-checking-languages" gchar* : Read / Write /
|
||||||
|
Construct
|
||||||
*/
|
*/
|
||||||
g_object_set(G_OBJECT(settings), "enable-tabs-to-links", FALSE, NULL);
|
g_object_set (G_OBJECT (settings), "enable-tabs-to-links", FALSE, NULL);
|
||||||
g_object_set(G_OBJECT(settings), "user-agent",
|
g_object_set (G_OBJECT (settings),
|
||||||
"Zenity with WebKit (KHTML, like Gecko) support", NULL);
|
"user-agent",
|
||||||
|
"Zenity with WebKit (KHTML, like Gecko) support",
|
||||||
|
NULL);
|
||||||
/*
|
/*
|
||||||
Stick to defaults
|
Stick to defaults
|
||||||
"user-stylesheet-uri" gchar* : Read / Write / Construct
|
"user-stylesheet-uri" gchar* : Read / Write /
|
||||||
"zoom-step" gfloat : Read / Write / Construct
|
Construct
|
||||||
|
"zoom-step" gfloat : Read / Write /
|
||||||
|
Construct
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
zenity_text_webview_decision_request (WebKitWebView *web_view,
|
zenity_text_webview_decision_request (WebKitWebView *web_view,
|
||||||
WebKitPolicyDecision *decision,
|
WebKitPolicyDecision *decision, WebKitPolicyDecisionType type) {
|
||||||
WebKitPolicyDecisionType type)
|
|
||||||
{
|
|
||||||
if (type == WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION) {
|
if (type == WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION) {
|
||||||
WebKitNavigationPolicyDecision *navigation_decision = WEBKIT_NAVIGATION_POLICY_DECISION (decision);
|
WebKitNavigationPolicyDecision *navigation_decision =
|
||||||
WebKitNavigationAction *navigation_action = webkit_navigation_policy_decision_get_navigation_action(navigation_decision);
|
WEBKIT_NAVIGATION_POLICY_DECISION (decision);
|
||||||
|
WebKitNavigationAction *navigation_action =
|
||||||
|
webkit_navigation_policy_decision_get_navigation_action (
|
||||||
|
navigation_decision);
|
||||||
webkit_policy_decision_ignore (decision);
|
webkit_policy_decision_ignore (decision);
|
||||||
if (!zen_text_data->no_interaction &&
|
if (!zen_text_data->no_interaction &&
|
||||||
webkit_navigation_action_get_navigation_type (navigation_action) == WEBKIT_NAVIGATION_TYPE_LINK_CLICKED) {
|
webkit_navigation_action_get_navigation_type (navigation_action) ==
|
||||||
WebKitURIRequest *request = webkit_navigation_action_get_request(navigation_action);
|
WEBKIT_NAVIGATION_TYPE_LINK_CLICKED) {
|
||||||
g_app_info_launch_default_for_uri (webkit_uri_request_get_uri(request), NULL, NULL);
|
WebKitURIRequest *request =
|
||||||
|
webkit_navigation_action_get_request (navigation_action);
|
||||||
|
g_app_info_launch_default_for_uri (
|
||||||
|
webkit_uri_request_get_uri (request), NULL, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_text_webview_load_changed (WebKitWebView *webkitwebview,
|
zenity_text_webview_load_changed (
|
||||||
WebKitLoadEvent event,
|
WebKitWebView *webkitwebview, WebKitLoadEvent event, gpointer user_data) {
|
||||||
gpointer user_data)
|
|
||||||
{
|
|
||||||
if (event == WEBKIT_LOAD_FINISHED) {
|
if (event == WEBKIT_LOAD_FINISHED) {
|
||||||
g_signal_connect (G_OBJECT (webkitwebview), "decide-policy",
|
g_signal_connect (G_OBJECT (webkitwebview),
|
||||||
G_CALLBACK (zenity_text_webview_decision_request), NULL);
|
"decide-policy",
|
||||||
|
G_CALLBACK (zenity_text_webview_decision_request),
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
zenity_text_handle_stdin (GIOChannel *channel,
|
zenity_text_handle_stdin (
|
||||||
GIOCondition condition,
|
GIOChannel *channel, GIOCondition condition, gpointer data) {
|
||||||
gpointer data)
|
|
||||||
{
|
|
||||||
static GtkTextBuffer *buffer;
|
static GtkTextBuffer *buffer;
|
||||||
static GtkTextView *text_view;
|
static GtkTextView *text_view;
|
||||||
gchar buf[1024];
|
gchar buf[1024];
|
||||||
@ -167,7 +193,14 @@ zenity_text_handle_stdin (GIOChannel *channel,
|
|||||||
gtk_text_buffer_get_end_iter (buffer, &end);
|
gtk_text_buffer_get_end_iter (buffer, &end);
|
||||||
|
|
||||||
if (!g_utf8_validate (buf, len, NULL)) {
|
if (!g_utf8_validate (buf, len, NULL)) {
|
||||||
utftext = g_convert_with_fallback (buf, len, "UTF-8", "ISO-8859-1", NULL, &localelen, &utflen, NULL);
|
utftext = g_convert_with_fallback (buf,
|
||||||
|
len,
|
||||||
|
"UTF-8",
|
||||||
|
"ISO-8859-1",
|
||||||
|
NULL,
|
||||||
|
&localelen,
|
||||||
|
&utflen,
|
||||||
|
NULL);
|
||||||
gtk_text_buffer_insert (buffer, &end, utftext, utflen);
|
gtk_text_buffer_insert (buffer, &end, utftext, utflen);
|
||||||
g_free (utftext);
|
g_free (utftext);
|
||||||
} else {
|
} else {
|
||||||
@ -177,7 +210,8 @@ zenity_text_handle_stdin (GIOChannel *channel,
|
|||||||
GtkTextMark *mark = NULL;
|
GtkTextMark *mark = NULL;
|
||||||
mark = gtk_text_buffer_get_insert (buffer);
|
mark = gtk_text_buffer_get_insert (buffer);
|
||||||
if (mark != NULL)
|
if (mark != NULL)
|
||||||
gtk_text_view_scroll_to_mark (text_view, mark, 0.0, FALSE, 0, 0);
|
gtk_text_view_scroll_to_mark (
|
||||||
|
text_view, mark, 0.0, FALSE, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -186,19 +220,18 @@ zenity_text_handle_stdin (GIOChannel *channel,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_text_fill_entries_from_stdin (GtkTextView *text_view)
|
zenity_text_fill_entries_from_stdin (GtkTextView *text_view) {
|
||||||
{
|
|
||||||
GIOChannel *channel;
|
GIOChannel *channel;
|
||||||
|
|
||||||
channel = g_io_channel_unix_new (0);
|
channel = g_io_channel_unix_new (0);
|
||||||
g_io_channel_set_encoding (channel, "UTF-8", NULL);
|
g_io_channel_set_encoding (channel, "UTF-8", NULL);
|
||||||
g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL);
|
g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL);
|
||||||
g_io_add_watch (channel, G_IO_IN | G_IO_HUP, zenity_text_handle_stdin, text_view);
|
g_io_add_watch (
|
||||||
|
channel, G_IO_IN | G_IO_HUP, zenity_text_handle_stdin, text_view);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
zenity_text (ZenityData *data, ZenityTextData *text_data)
|
zenity_text (ZenityData *data, ZenityTextData *text_data) {
|
||||||
{
|
|
||||||
GtkBuilder *builder;
|
GtkBuilder *builder;
|
||||||
GtkWidget *dialog;
|
GtkWidget *dialog;
|
||||||
GtkWidget *ok_button;
|
GtkWidget *ok_button;
|
||||||
@ -215,8 +248,8 @@ zenity_text (ZenityData *data, ZenityTextData *text_data)
|
|||||||
gchar *content;
|
gchar *content;
|
||||||
#endif
|
#endif
|
||||||
zen_text_data = text_data;
|
zen_text_data = text_data;
|
||||||
builder = zenity_util_load_ui_file ("zenity_text_dialog",
|
builder =
|
||||||
"textbuffer1", NULL);
|
zenity_util_load_ui_file ("zenity_text_dialog", "textbuffer1", NULL);
|
||||||
|
|
||||||
if (builder == NULL) {
|
if (builder == NULL) {
|
||||||
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
|
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
|
||||||
@ -225,47 +258,56 @@ zenity_text (ZenityData *data, ZenityTextData *text_data)
|
|||||||
|
|
||||||
gtk_builder_connect_signals (builder, NULL);
|
gtk_builder_connect_signals (builder, NULL);
|
||||||
|
|
||||||
dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_text_dialog"));
|
dialog =
|
||||||
|
GTK_WIDGET (gtk_builder_get_object (builder, "zenity_text_dialog"));
|
||||||
|
|
||||||
ok_button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_text_close_button"));
|
ok_button = GTK_WIDGET (
|
||||||
cancel_button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_text_cancel_button"));
|
gtk_builder_get_object (builder, "zenity_text_close_button"));
|
||||||
checkbox = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_text_checkbox"));
|
cancel_button = GTK_WIDGET (
|
||||||
|
gtk_builder_get_object (builder, "zenity_text_cancel_button"));
|
||||||
|
checkbox =
|
||||||
|
GTK_WIDGET (gtk_builder_get_object (builder, "zenity_text_checkbox"));
|
||||||
|
|
||||||
g_signal_connect (G_OBJECT (dialog), "response",
|
g_signal_connect (G_OBJECT (dialog),
|
||||||
G_CALLBACK (zenity_text_dialog_response), data);
|
"response",
|
||||||
|
G_CALLBACK (zenity_text_dialog_response),
|
||||||
|
data);
|
||||||
|
|
||||||
if (data->dialog_title)
|
if (data->dialog_title)
|
||||||
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
|
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
|
||||||
|
|
||||||
zenity_util_set_window_icon (dialog, data->window_icon, ZENITY_IMAGE_FULLPATH ("zenity-text.png"));
|
zenity_util_set_window_icon (
|
||||||
|
dialog, data->window_icon, ZENITY_IMAGE_FULLPATH ("zenity-text.png"));
|
||||||
|
|
||||||
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE);
|
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE);
|
||||||
|
|
||||||
text_buffer = gtk_text_buffer_new (NULL);
|
text_buffer = gtk_text_buffer_new (NULL);
|
||||||
text_view = gtk_builder_get_object (builder, "zenity_text_view");
|
text_view = gtk_builder_get_object (builder, "zenity_text_view");
|
||||||
gtk_text_view_set_buffer (GTK_TEXT_VIEW (text_view), text_buffer);
|
gtk_text_view_set_buffer (GTK_TEXT_VIEW (text_view), text_buffer);
|
||||||
gtk_text_view_set_editable (GTK_TEXT_VIEW(text_view), text_data->editable);
|
gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), text_data->editable);
|
||||||
|
|
||||||
if (text_data->no_wrap)
|
if (text_data->no_wrap)
|
||||||
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW(text_view), GTK_WRAP_NONE);
|
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), GTK_WRAP_NONE);
|
||||||
|
|
||||||
if (text_data->font) {
|
if (text_data->font) {
|
||||||
PangoFontDescription *fontDesc = pango_font_description_from_string (text_data->font);
|
PangoFontDescription *fontDesc =
|
||||||
gtk_widget_override_font (GTK_WIDGET(text_view), fontDesc);
|
pango_font_description_from_string (text_data->font);
|
||||||
|
gtk_widget_override_font (GTK_WIDGET (text_view), fontDesc);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (text_data->uri)
|
if (text_data->uri)
|
||||||
zenity_util_fill_file_buffer (text_buffer, text_data->uri);
|
zenity_util_fill_file_buffer (text_buffer, text_data->uri);
|
||||||
else
|
else
|
||||||
zenity_text_fill_entries_from_stdin (GTK_TEXT_VIEW(text_view));
|
zenity_text_fill_entries_from_stdin (GTK_TEXT_VIEW (text_view));
|
||||||
|
|
||||||
if (text_data->editable)
|
if (text_data->editable)
|
||||||
zen_text_data->buffer = text_buffer;
|
zen_text_data->buffer = text_buffer;
|
||||||
|
|
||||||
if (data->extra_label) {
|
if (data->extra_label) {
|
||||||
gint i=0;
|
gint i = 0;
|
||||||
while(data->extra_label[i]!=NULL){
|
while (data->extra_label[i] != NULL) {
|
||||||
gtk_dialog_add_button (GTK_DIALOG (dialog), data->extra_label[i], i);
|
gtk_dialog_add_button (
|
||||||
|
GTK_DIALOG (dialog), data->extra_label[i], i);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -283,12 +325,15 @@ zenity_text (ZenityData *data, ZenityTextData *text_data)
|
|||||||
gtk_widget_set_sensitive (GTK_WIDGET (ok_button), FALSE);
|
gtk_widget_set_sensitive (GTK_WIDGET (ok_button), FALSE);
|
||||||
gtk_button_set_label (GTK_BUTTON (checkbox), text_data->checkbox);
|
gtk_button_set_label (GTK_BUTTON (checkbox), text_data->checkbox);
|
||||||
|
|
||||||
g_signal_connect (G_OBJECT (checkbox), "toggled",
|
g_signal_connect (G_OBJECT (checkbox),
|
||||||
G_CALLBACK (zenity_text_toggle_button), ok_button);
|
"toggled",
|
||||||
|
G_CALLBACK (zenity_text_toggle_button),
|
||||||
|
ok_button);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->width > -1 || data->height > -1)
|
if (data->width > -1 || data->height > -1)
|
||||||
gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height);
|
gtk_window_set_default_size (
|
||||||
|
GTK_WINDOW (dialog), data->width, data->height);
|
||||||
else
|
else
|
||||||
gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 400);
|
gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 400);
|
||||||
|
|
||||||
@ -296,34 +341,36 @@ zenity_text (ZenityData *data, ZenityTextData *text_data)
|
|||||||
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
||||||
|
|
||||||
#ifdef HAVE_WEBKITGTK
|
#ifdef HAVE_WEBKITGTK
|
||||||
if(text_data->html) {
|
if (text_data->html) {
|
||||||
web_kit = webkit_web_view_new();
|
web_kit = webkit_web_view_new ();
|
||||||
scrolled_window = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_text_scrolled_window"));
|
scrolled_window = GTK_WIDGET (
|
||||||
|
gtk_builder_get_object (builder, "zenity_text_scrolled_window"));
|
||||||
|
|
||||||
zenity_configure_webkit (WEBKIT_WEB_VIEW (web_kit));
|
zenity_configure_webkit (WEBKIT_WEB_VIEW (web_kit));
|
||||||
|
|
||||||
if (text_data->url)
|
if (text_data->url) {
|
||||||
{
|
if (!(g_str_has_prefix (text_data->url, "http://") ||
|
||||||
if (!(g_str_has_prefix (text_data->url, "http://") || g_str_has_prefix (text_data->url, "https://")))
|
g_str_has_prefix (text_data->url, "https://")))
|
||||||
text_data->url = g_strdup_printf ("http://%s", text_data->url);
|
text_data->url = g_strdup_printf ("http://%s", text_data->url);
|
||||||
|
|
||||||
|
webkit_web_view_load_uri (
|
||||||
webkit_web_view_load_uri (WEBKIT_WEB_VIEW (web_kit), text_data->url);
|
WEBKIT_WEB_VIEW (web_kit), text_data->url);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
gchar *cwd;
|
gchar *cwd;
|
||||||
gchar *dirname;
|
gchar *dirname;
|
||||||
gchar *dirname_uri;
|
gchar *dirname_uri;
|
||||||
dirname = text_data->uri ? g_path_get_dirname (text_data->uri) : g_strdup ("/");
|
dirname = text_data->uri ? g_path_get_dirname (text_data->uri)
|
||||||
|
: g_strdup ("/");
|
||||||
cwd = g_get_current_dir ();
|
cwd = g_get_current_dir ();
|
||||||
dirname_uri = g_strconcat ("file://", cwd, "/", dirname, "/", NULL);
|
dirname_uri = g_strconcat ("file://", cwd, "/", dirname, "/", NULL);
|
||||||
g_free (cwd);
|
g_free (cwd);
|
||||||
g_free (dirname);
|
g_free (dirname);
|
||||||
gtk_text_buffer_get_start_iter (text_buffer, &start_iter);
|
gtk_text_buffer_get_start_iter (text_buffer, &start_iter);
|
||||||
gtk_text_buffer_get_end_iter (text_buffer, &end_iter);
|
gtk_text_buffer_get_end_iter (text_buffer, &end_iter);
|
||||||
content = gtk_text_buffer_get_text (text_buffer, &start_iter, &end_iter, TRUE);
|
content = gtk_text_buffer_get_text (
|
||||||
webkit_web_view_load_html (WEBKIT_WEB_VIEW(web_kit), content, dirname_uri);
|
text_buffer, &start_iter, &end_iter, TRUE);
|
||||||
|
webkit_web_view_load_html (
|
||||||
|
WEBKIT_WEB_VIEW (web_kit), content, dirname_uri);
|
||||||
g_free (dirname_uri);
|
g_free (dirname_uri);
|
||||||
g_free (content);
|
g_free (content);
|
||||||
}
|
}
|
||||||
@ -331,11 +378,13 @@ zenity_text (ZenityData *data, ZenityTextData *text_data)
|
|||||||
// We don't want user to click on links and navigate to another page.
|
// We don't want user to click on links and navigate to another page.
|
||||||
// So, when the page finishes loading, we take handle of the requests.
|
// So, when the page finishes loading, we take handle of the requests.
|
||||||
|
|
||||||
g_signal_connect (G_OBJECT (web_kit), "load-changed",
|
g_signal_connect (G_OBJECT (web_kit),
|
||||||
G_CALLBACK (zenity_text_webview_load_changed), NULL);
|
"load-changed",
|
||||||
|
G_CALLBACK (zenity_text_webview_load_changed),
|
||||||
|
NULL);
|
||||||
|
|
||||||
gtk_widget_destroy (GTK_WIDGET (text_view));
|
gtk_widget_destroy (GTK_WIDGET (text_view));
|
||||||
gtk_container_add (GTK_CONTAINER(scrolled_window), web_kit);
|
gtk_container_add (GTK_CONTAINER (scrolled_window), web_kit);
|
||||||
gtk_widget_show (GTK_WIDGET (web_kit));
|
gtk_widget_show (GTK_WIDGET (web_kit));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -344,36 +393,37 @@ zenity_text (ZenityData *data, ZenityTextData *text_data)
|
|||||||
|
|
||||||
g_object_unref (builder);
|
g_object_unref (builder);
|
||||||
|
|
||||||
if(data->timeout_delay > 0) {
|
if (data->timeout_delay > 0) {
|
||||||
g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, dialog);
|
g_timeout_add_seconds (data->timeout_delay,
|
||||||
|
(GSourceFunc) zenity_util_timeout_handle,
|
||||||
|
dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_main ();
|
gtk_main ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_text_toggle_button (GtkToggleButton *button, gpointer data)
|
zenity_text_toggle_button (GtkToggleButton *button, gpointer data) {
|
||||||
{
|
GtkWidget *ok_button = (GtkWidget *) data;
|
||||||
GtkWidget *ok_button = (GtkWidget *)data;
|
gtk_widget_set_sensitive (
|
||||||
gtk_widget_set_sensitive (GTK_WIDGET(ok_button), gtk_toggle_button_get_active(button));
|
GTK_WIDGET (ok_button), gtk_toggle_button_get_active (button));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_text_dialog_output (ZenityData *zen_data)
|
zenity_text_dialog_output (ZenityData *zen_data) {
|
||||||
{
|
|
||||||
if (zen_text_data->editable) {
|
if (zen_text_data->editable) {
|
||||||
GtkTextIter start, end;
|
GtkTextIter start, end;
|
||||||
gchar *text;
|
gchar *text;
|
||||||
gtk_text_buffer_get_bounds (zen_text_data->buffer, &start, &end);
|
gtk_text_buffer_get_bounds (zen_text_data->buffer, &start, &end);
|
||||||
text = gtk_text_buffer_get_text (zen_text_data->buffer, &start, &end, 0);
|
text =
|
||||||
|
gtk_text_buffer_get_text (zen_text_data->buffer, &start, &end, 0);
|
||||||
g_print ("%s", text);
|
g_print ("%s", text);
|
||||||
g_free (text);
|
g_free (text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data)
|
zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data) {
|
||||||
{
|
|
||||||
ZenityData *zen_data = data;
|
ZenityData *zen_data = data;
|
||||||
|
|
||||||
switch (response) {
|
switch (response) {
|
||||||
@ -388,9 +438,10 @@ zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (zen_data->extra_label && response < g_strv_length(zen_data->extra_label))
|
if (zen_data->extra_label &&
|
||||||
printf("%s\n",zen_data->extra_label[response]);
|
response < g_strv_length (zen_data->extra_label))
|
||||||
zenity_util_exit_code_with_data(ZENITY_ESC, zen_data);
|
printf ("%s\n", zen_data->extra_label[response]);
|
||||||
|
zenity_util_exit_code_with_data (ZENITY_ESC, zen_data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
gtk_main_quit ();
|
gtk_main_quit ();
|
||||||
|
436
src/tree.c
436
src/tree.c
@ -25,10 +25,10 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "zenity.h"
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "zenity.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#define MAX_ELEMENTS_BEFORE_SCROLLING 5
|
#define MAX_ELEMENTS_BEFORE_SCROLLING 5
|
||||||
#define PRINT_HIDE_COLUMN_SEPARATOR ","
|
#define PRINT_HIDE_COLUMN_SEPARATOR ","
|
||||||
@ -43,14 +43,17 @@ static GIOChannel *channel;
|
|||||||
|
|
||||||
static int *zenity_tree_extract_column_indexes (char *indexes, gint n_columns);
|
static int *zenity_tree_extract_column_indexes (char *indexes, gint n_columns);
|
||||||
static gboolean zenity_tree_column_is_hidden (gint column_index);
|
static gboolean zenity_tree_column_is_hidden (gint column_index);
|
||||||
static void zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data);
|
static void zenity_tree_dialog_response (
|
||||||
static void zenity_tree_row_activated (GtkTreeView *tree_view, GtkTreePath *tree_path,
|
GtkWidget *widget, int response, gpointer data);
|
||||||
GtkTreeViewColumn *tree_col, gpointer data);
|
static void zenity_tree_row_activated (GtkTreeView *tree_view,
|
||||||
|
GtkTreePath *tree_path, GtkTreeViewColumn *tree_col, gpointer data);
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
zenity_tree_dialog_untoggle (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
|
zenity_tree_dialog_untoggle (
|
||||||
{
|
GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) {
|
||||||
GValue toggle_value = {0, };
|
GValue toggle_value = {
|
||||||
|
0,
|
||||||
|
};
|
||||||
|
|
||||||
gtk_tree_model_get_value (model, iter, 0, &toggle_value);
|
gtk_tree_model_get_value (model, iter, 0, &toggle_value);
|
||||||
|
|
||||||
@ -60,8 +63,8 @@ zenity_tree_dialog_untoggle (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_tree_toggled_callback (GtkCellRendererToggle *cell, gchar *path_string, gpointer data)
|
zenity_tree_toggled_callback (
|
||||||
{
|
GtkCellRendererToggle *cell, gchar *path_string, gpointer data) {
|
||||||
GtkTreeModel *model;
|
GtkTreeModel *model;
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
GtkTreePath *path;
|
GtkTreePath *path;
|
||||||
@ -69,7 +72,8 @@ zenity_tree_toggled_callback (GtkCellRendererToggle *cell, gchar *path_string, g
|
|||||||
|
|
||||||
model = GTK_TREE_MODEL (data);
|
model = GTK_TREE_MODEL (data);
|
||||||
|
|
||||||
/* Because this is a radio list, we should untoggle the previous toggle so that
|
/* Because this is a radio list, we should untoggle the previous toggle so
|
||||||
|
* that
|
||||||
* we only have one selection at any given time
|
* we only have one selection at any given time
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -88,12 +92,8 @@ zenity_tree_toggled_callback (GtkCellRendererToggle *cell, gchar *path_string, g
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_load_pixbuf (GtkTreeViewColumn *tree_column,
|
zenity_load_pixbuf (GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
|
||||||
GtkCellRenderer *cell,
|
GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) {
|
||||||
GtkTreeModel *tree_model,
|
|
||||||
GtkTreeIter *iter,
|
|
||||||
gpointer data)
|
|
||||||
{
|
|
||||||
static GHashTable *pixbuf_cache = NULL;
|
static GHashTable *pixbuf_cache = NULL;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
GdkPixbuf *pixbuf;
|
GdkPixbuf *pixbuf;
|
||||||
@ -106,7 +106,7 @@ zenity_load_pixbuf (GtkTreeViewColumn *tree_column,
|
|||||||
|
|
||||||
if (!pixbuf_cache) {
|
if (!pixbuf_cache) {
|
||||||
pixbuf_cache = g_hash_table_new (g_str_hash, g_str_equal);
|
pixbuf_cache = g_hash_table_new (g_str_hash, g_str_equal);
|
||||||
g_assert(pixbuf_cache);
|
g_assert (pixbuf_cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
pixbuf = g_hash_table_lookup (pixbuf_cache, str);
|
pixbuf = g_hash_table_lookup (pixbuf_cache, str);
|
||||||
@ -126,10 +126,8 @@ zenity_load_pixbuf (GtkTreeViewColumn *tree_column,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
zenity_tree_handle_stdin (GIOChannel *channel,
|
zenity_tree_handle_stdin (
|
||||||
GIOCondition condition,
|
GIOChannel *channel, GIOCondition condition, gpointer data) {
|
||||||
gpointer data)
|
|
||||||
{
|
|
||||||
static GtkTreeView *tree_view;
|
static GtkTreeView *tree_view;
|
||||||
GtkTreeModel *model;
|
GtkTreeModel *model;
|
||||||
static GtkTreeIter iter;
|
static GtkTreeIter iter;
|
||||||
@ -142,9 +140,12 @@ zenity_tree_handle_stdin (GIOChannel *channel,
|
|||||||
GIOStatus status = G_IO_STATUS_NORMAL;
|
GIOStatus status = G_IO_STATUS_NORMAL;
|
||||||
|
|
||||||
tree_view = GTK_TREE_VIEW (data);
|
tree_view = GTK_TREE_VIEW (data);
|
||||||
n_columns = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "n_columns"));
|
n_columns =
|
||||||
editable = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "editable"));
|
GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "n_columns"));
|
||||||
toggles = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "toggles"));
|
editable =
|
||||||
|
GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "editable"));
|
||||||
|
toggles =
|
||||||
|
GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "toggles"));
|
||||||
|
|
||||||
model = gtk_tree_view_get_model (tree_view);
|
model = gtk_tree_view_get_model (tree_view);
|
||||||
|
|
||||||
@ -159,12 +160,14 @@ zenity_tree_handle_stdin (GIOChannel *channel,
|
|||||||
|
|
||||||
string = g_string_new (NULL);
|
string = g_string_new (NULL);
|
||||||
|
|
||||||
while ((g_io_channel_get_flags(channel) & G_IO_FLAG_IS_READABLE) != G_IO_FLAG_IS_READABLE)
|
while ((g_io_channel_get_flags (channel) & G_IO_FLAG_IS_READABLE) !=
|
||||||
|
G_IO_FLAG_IS_READABLE)
|
||||||
;
|
;
|
||||||
do {
|
do {
|
||||||
do {
|
do {
|
||||||
if (g_io_channel_get_flags(channel) & G_IO_FLAG_IS_READABLE)
|
if (g_io_channel_get_flags (channel) & G_IO_FLAG_IS_READABLE)
|
||||||
status = g_io_channel_read_line_string (channel, string, NULL, &error);
|
status = g_io_channel_read_line_string (
|
||||||
|
channel, string, NULL, &error);
|
||||||
else
|
else
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
@ -172,13 +175,14 @@ zenity_tree_handle_stdin (GIOChannel *channel,
|
|||||||
gtk_main_iteration ();
|
gtk_main_iteration ();
|
||||||
|
|
||||||
// TODO: Find a better way to avoid 100% cpu utilization
|
// TODO: Find a better way to avoid 100% cpu utilization
|
||||||
g_usleep(10000);
|
g_usleep (10000);
|
||||||
|
|
||||||
} while (status == G_IO_STATUS_AGAIN);
|
} while (status == G_IO_STATUS_AGAIN);
|
||||||
|
|
||||||
if (status != G_IO_STATUS_NORMAL) {
|
if (status != G_IO_STATUS_NORMAL) {
|
||||||
if (error) {
|
if (error) {
|
||||||
g_warning ("zenity_tree_handle_stdin () : %s", error->message);
|
g_warning (
|
||||||
|
"zenity_tree_handle_stdin () : %s", error->message);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
error = NULL;
|
error = NULL;
|
||||||
}
|
}
|
||||||
@ -193,34 +197,48 @@ zenity_tree_handle_stdin (GIOChannel *channel,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (toggles && column_count == 0) {
|
if (toggles && column_count == 0) {
|
||||||
if (strcmp (g_ascii_strdown (zenity_util_strip_newline (string->str), -1), "true") == 0)
|
if (strcmp (g_ascii_strdown (
|
||||||
gtk_list_store_set (GTK_LIST_STORE (model), &iter, column_count, TRUE, -1);
|
zenity_util_strip_newline (string->str), -1),
|
||||||
|
"true") == 0)
|
||||||
|
gtk_list_store_set (
|
||||||
|
GTK_LIST_STORE (model), &iter, column_count, TRUE, -1);
|
||||||
else
|
else
|
||||||
gtk_list_store_set (GTK_LIST_STORE (model), &iter, column_count, FALSE, -1);
|
gtk_list_store_set (
|
||||||
}
|
GTK_LIST_STORE (model), &iter, column_count, FALSE, -1);
|
||||||
else {
|
} else {
|
||||||
gtk_list_store_set (GTK_LIST_STORE (model), &iter, column_count, zenity_util_strip_newline (string->str), -1);
|
gtk_list_store_set (GTK_LIST_STORE (model),
|
||||||
|
&iter,
|
||||||
|
column_count,
|
||||||
|
zenity_util_strip_newline (string->str),
|
||||||
|
-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (editable) {
|
if (editable) {
|
||||||
gtk_list_store_set (GTK_LIST_STORE (model), &iter, n_columns, TRUE, -1);
|
gtk_list_store_set (
|
||||||
|
GTK_LIST_STORE (model), &iter, n_columns, TRUE, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (row_count == MAX_ELEMENTS_BEFORE_SCROLLING) {
|
if (row_count == MAX_ELEMENTS_BEFORE_SCROLLING) {
|
||||||
GtkWidget *scrolled_window;
|
GtkWidget *scrolled_window;
|
||||||
GtkRequisition rectangle;
|
GtkRequisition rectangle;
|
||||||
|
|
||||||
gtk_widget_get_preferred_size (GTK_WIDGET (tree_view), &rectangle, NULL);
|
gtk_widget_get_preferred_size (
|
||||||
scrolled_window = GTK_WIDGET (gtk_builder_get_object (builder,
|
GTK_WIDGET (tree_view), &rectangle, NULL);
|
||||||
"zenity_tree_window"));
|
scrolled_window = GTK_WIDGET (
|
||||||
gtk_widget_set_size_request (scrolled_window, -1, rectangle.height);
|
gtk_builder_get_object (builder, "zenity_tree_window"));
|
||||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
gtk_widget_set_size_request (
|
||||||
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
scrolled_window, -1, rectangle.height);
|
||||||
|
gtk_scrolled_window_set_policy (
|
||||||
|
GTK_SCROLLED_WINDOW (scrolled_window),
|
||||||
|
GTK_POLICY_AUTOMATIC,
|
||||||
|
GTK_POLICY_AUTOMATIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
column_count++;
|
column_count++;
|
||||||
|
|
||||||
} while ((g_io_channel_get_buffer_condition (channel) & G_IO_IN) == G_IO_IN && status != G_IO_STATUS_EOF);
|
} while ((g_io_channel_get_buffer_condition (channel) & G_IO_IN) ==
|
||||||
|
G_IO_IN &&
|
||||||
|
status != G_IO_STATUS_EOF);
|
||||||
g_string_free (string, TRUE);
|
g_string_free (string, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,35 +250,33 @@ zenity_tree_handle_stdin (GIOChannel *channel,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_tree_fill_entries_from_stdin (GtkTreeView *tree_view,
|
zenity_tree_fill_entries_from_stdin (GtkTreeView *tree_view, gint n_columns,
|
||||||
gint n_columns,
|
gboolean toggles, gboolean editable) {
|
||||||
gboolean toggles,
|
g_object_set_data (
|
||||||
gboolean editable)
|
G_OBJECT (tree_view), "n_columns", GINT_TO_POINTER (n_columns));
|
||||||
{
|
g_object_set_data (
|
||||||
g_object_set_data (G_OBJECT (tree_view), "n_columns", GINT_TO_POINTER (n_columns));
|
G_OBJECT (tree_view), "toggles", GINT_TO_POINTER (toggles));
|
||||||
g_object_set_data (G_OBJECT (tree_view), "toggles", GINT_TO_POINTER (toggles));
|
g_object_set_data (
|
||||||
g_object_set_data (G_OBJECT (tree_view), "editable", GINT_TO_POINTER (editable));
|
G_OBJECT (tree_view), "editable", GINT_TO_POINTER (editable));
|
||||||
|
|
||||||
channel = g_io_channel_unix_new (0);
|
channel = g_io_channel_unix_new (0);
|
||||||
g_io_channel_set_encoding (channel, NULL, NULL);
|
g_io_channel_set_encoding (channel, NULL, NULL);
|
||||||
g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL);
|
g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL);
|
||||||
g_io_add_watch (channel, G_IO_IN | G_IO_HUP, zenity_tree_handle_stdin, tree_view);
|
g_io_add_watch (
|
||||||
|
channel, G_IO_IN | G_IO_HUP, zenity_tree_handle_stdin, tree_view);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_tree_fill_entries (GtkTreeView *tree_view,
|
zenity_tree_fill_entries (GtkTreeView *tree_view, const gchar **args,
|
||||||
const gchar **args,
|
gint n_columns, gboolean toggles, gboolean editable) {
|
||||||
gint n_columns,
|
|
||||||
gboolean toggles,
|
|
||||||
gboolean editable)
|
|
||||||
{
|
|
||||||
GtkTreeModel *model;
|
GtkTreeModel *model;
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
gint i = 0;
|
gint i = 0;
|
||||||
|
|
||||||
model = gtk_tree_view_get_model (tree_view);
|
model = gtk_tree_view_get_model (tree_view);
|
||||||
|
|
||||||
g_object_set_data (G_OBJECT (tree_view), "n_columns", GINT_TO_POINTER (n_columns));
|
g_object_set_data (
|
||||||
|
G_OBJECT (tree_view), "n_columns", GINT_TO_POINTER (n_columns));
|
||||||
|
|
||||||
while (args[i] != NULL) {
|
while (args[i] != NULL) {
|
||||||
gint j;
|
gint j;
|
||||||
@ -270,28 +286,35 @@ zenity_tree_fill_entries (GtkTreeView *tree_view,
|
|||||||
for (j = 0; j < n_columns; j++) {
|
for (j = 0; j < n_columns; j++) {
|
||||||
|
|
||||||
if (toggles && j == 0) {
|
if (toggles && j == 0) {
|
||||||
if (strcmp (g_ascii_strdown ((gchar *) args[i+j], -1), "true") == 0)
|
if (strcmp (g_ascii_strdown ((gchar *) args[i + j], -1),
|
||||||
gtk_list_store_set (GTK_LIST_STORE (model), &iter, j, TRUE, -1);
|
"true") == 0)
|
||||||
|
gtk_list_store_set (
|
||||||
|
GTK_LIST_STORE (model), &iter, j, TRUE, -1);
|
||||||
else
|
else
|
||||||
gtk_list_store_set (GTK_LIST_STORE (model), &iter, j, FALSE, -1);
|
gtk_list_store_set (
|
||||||
}
|
GTK_LIST_STORE (model), &iter, j, FALSE, -1);
|
||||||
else
|
} else
|
||||||
gtk_list_store_set (GTK_LIST_STORE (model), &iter, j, args[i+j], -1);
|
gtk_list_store_set (
|
||||||
|
GTK_LIST_STORE (model), &iter, j, args[i + j], -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (editable)
|
if (editable)
|
||||||
gtk_list_store_set (GTK_LIST_STORE (model), &iter, n_columns, TRUE, -1);
|
gtk_list_store_set (
|
||||||
|
GTK_LIST_STORE (model), &iter, n_columns, TRUE, -1);
|
||||||
|
|
||||||
if (i == MAX_ELEMENTS_BEFORE_SCROLLING) {
|
if (i == MAX_ELEMENTS_BEFORE_SCROLLING) {
|
||||||
GtkWidget *scrolled_window;
|
GtkWidget *scrolled_window;
|
||||||
GtkRequisition rectangle;
|
GtkRequisition rectangle;
|
||||||
|
|
||||||
gtk_widget_get_preferred_size (GTK_WIDGET (tree_view), &rectangle, NULL);
|
gtk_widget_get_preferred_size (
|
||||||
scrolled_window = GTK_WIDGET (gtk_builder_get_object (builder,
|
GTK_WIDGET (tree_view), &rectangle, NULL);
|
||||||
"zenity_tree_window"));
|
scrolled_window = GTK_WIDGET (
|
||||||
|
gtk_builder_get_object (builder, "zenity_tree_window"));
|
||||||
gtk_widget_set_size_request (scrolled_window, -1, rectangle.height);
|
gtk_widget_set_size_request (scrolled_window, -1, rectangle.height);
|
||||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
gtk_scrolled_window_set_policy (
|
||||||
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
GTK_SCROLLED_WINDOW (scrolled_window),
|
||||||
|
GTK_POLICY_AUTOMATIC,
|
||||||
|
GTK_POLICY_AUTOMATIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
i += n_columns;
|
i += n_columns;
|
||||||
@ -299,23 +322,17 @@ zenity_tree_fill_entries (GtkTreeView *tree_view,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
zenity_mid_search_func (GtkTreeModel *model, gint column,
|
zenity_mid_search_func (GtkTreeModel *model, gint column, const gchar *key,
|
||||||
const gchar *key, GtkTreeIter *iter,
|
GtkTreeIter *iter, gpointer search_data) {
|
||||||
gpointer search_data)
|
|
||||||
{
|
|
||||||
gchar *iter_string = NULL;
|
gchar *iter_string = NULL;
|
||||||
gtk_tree_model_get (model, iter, column, &iter_string, -1);
|
gtk_tree_model_get (model, iter, column, &iter_string, -1);
|
||||||
return ! (g_strrstr (g_utf8_strdown(iter_string, -1),
|
return !(g_strrstr (g_utf8_strdown (iter_string, -1),
|
||||||
g_utf8_strdown(key, -1)) != NULL);
|
g_utf8_strdown (key, -1)) != NULL);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_cell_edited_callback (GtkCellRendererText *cell,
|
zenity_cell_edited_callback (GtkCellRendererText *cell,
|
||||||
const gchar *path_string,
|
const gchar *path_string, const gchar *new_text, gpointer data) {
|
||||||
const gchar *new_text,
|
|
||||||
gpointer data)
|
|
||||||
{
|
|
||||||
GtkTreeModel *model;
|
GtkTreeModel *model;
|
||||||
GtkTreePath *path;
|
GtkTreePath *path;
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
@ -333,8 +350,7 @@ zenity_cell_edited_callback (GtkCellRendererText *cell,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
|
zenity_tree (ZenityData *data, ZenityTreeData *tree_data) {
|
||||||
{
|
|
||||||
GtkWidget *dialog;
|
GtkWidget *dialog;
|
||||||
GtkWidget *button;
|
GtkWidget *button;
|
||||||
GObject *tree_view;
|
GObject *tree_view;
|
||||||
@ -361,35 +377,39 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
|
|||||||
if (strcmp (g_ascii_strdown (tree_data->print_column, -1), "all") == 0)
|
if (strcmp (g_ascii_strdown (tree_data->print_column, -1), "all") == 0)
|
||||||
print_all_columns = TRUE;
|
print_all_columns = TRUE;
|
||||||
else
|
else
|
||||||
print_columns = zenity_tree_extract_column_indexes (tree_data->print_column, n_columns);
|
print_columns = zenity_tree_extract_column_indexes (
|
||||||
}
|
tree_data->print_column, n_columns);
|
||||||
else {
|
} else {
|
||||||
print_columns = g_new (gint, 2);
|
print_columns = g_new (gint, 2);
|
||||||
print_columns[0] = (tree_data->radiobox || tree_data->checkbox ? 2 : 1);
|
print_columns[0] = (tree_data->radiobox || tree_data->checkbox ? 2 : 1);
|
||||||
print_columns[1] = 0;
|
print_columns[1] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tree_data->hide_column)
|
if (tree_data->hide_column)
|
||||||
hide_columns = zenity_tree_extract_column_indexes (tree_data->hide_column, n_columns);
|
hide_columns = zenity_tree_extract_column_indexes (
|
||||||
|
tree_data->hide_column, n_columns);
|
||||||
|
|
||||||
if (n_columns == 0) {
|
if (n_columns == 0) {
|
||||||
g_printerr (_("No column titles specified for List dialog.\n"));
|
g_printerr (_ ("No column titles specified for List dialog.\n"));
|
||||||
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
|
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tree_data->checkbox + tree_data->radiobox + tree_data->imagebox > 1) {
|
if (tree_data->checkbox + tree_data->radiobox + tree_data->imagebox > 1) {
|
||||||
g_printerr (_("You should use only one List dialog type.\n"));
|
g_printerr (_ ("You should use only one List dialog type.\n"));
|
||||||
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
|
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_builder_connect_signals (builder, NULL);
|
gtk_builder_connect_signals (builder, NULL);
|
||||||
|
|
||||||
dialog = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_tree_dialog"));
|
dialog =
|
||||||
|
GTK_WIDGET (gtk_builder_get_object (builder, "zenity_tree_dialog"));
|
||||||
|
|
||||||
g_signal_connect (G_OBJECT (dialog), "response",
|
g_signal_connect (G_OBJECT (dialog),
|
||||||
G_CALLBACK (zenity_tree_dialog_response), data);
|
"response",
|
||||||
|
G_CALLBACK (zenity_tree_dialog_response),
|
||||||
|
data);
|
||||||
|
|
||||||
if (data->dialog_title)
|
if (data->dialog_title)
|
||||||
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
|
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
|
||||||
@ -398,38 +418,46 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
|
|||||||
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
||||||
|
|
||||||
if (data->extra_label) {
|
if (data->extra_label) {
|
||||||
gint i=0;
|
gint i = 0;
|
||||||
while(data->extra_label[i]!=NULL){
|
while (data->extra_label[i] != NULL) {
|
||||||
gtk_dialog_add_button (GTK_DIALOG (dialog), data->extra_label[i], i);
|
gtk_dialog_add_button (
|
||||||
|
GTK_DIALOG (dialog), data->extra_label[i], i);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->ok_label) {
|
if (data->ok_label) {
|
||||||
button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_tree_ok_button"));
|
button = GTK_WIDGET (
|
||||||
|
gtk_builder_get_object (builder, "zenity_tree_ok_button"));
|
||||||
gtk_button_set_label (GTK_BUTTON (button), data->ok_label);
|
gtk_button_set_label (GTK_BUTTON (button), data->ok_label);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->cancel_label) {
|
if (data->cancel_label) {
|
||||||
button = GTK_WIDGET (gtk_builder_get_object (builder, "zenity_tree_cancel_button"));
|
button = GTK_WIDGET (
|
||||||
|
gtk_builder_get_object (builder, "zenity_tree_cancel_button"));
|
||||||
gtk_button_set_label (GTK_BUTTON (button), data->cancel_label);
|
gtk_button_set_label (GTK_BUTTON (button), data->cancel_label);
|
||||||
}
|
}
|
||||||
|
|
||||||
text = gtk_builder_get_object (builder, "zenity_tree_text");
|
text = gtk_builder_get_object (builder, "zenity_tree_text");
|
||||||
|
|
||||||
if (tree_data->dialog_text)
|
if (tree_data->dialog_text)
|
||||||
gtk_label_set_markup (GTK_LABEL (text), g_strcompress (tree_data->dialog_text));
|
gtk_label_set_markup (
|
||||||
|
GTK_LABEL (text), g_strcompress (tree_data->dialog_text));
|
||||||
|
|
||||||
zenity_util_set_window_icon (dialog, data->window_icon, ZENITY_IMAGE_FULLPATH ("zenity-list.png"));
|
zenity_util_set_window_icon (
|
||||||
|
dialog, data->window_icon, ZENITY_IMAGE_FULLPATH ("zenity-list.png"));
|
||||||
|
|
||||||
if (data->width > -1 || data->height > -1)
|
if (data->width > -1 || data->height > -1)
|
||||||
gtk_window_set_default_size (GTK_WINDOW (dialog), data->width, data->height);
|
gtk_window_set_default_size (
|
||||||
|
GTK_WINDOW (dialog), data->width, data->height);
|
||||||
|
|
||||||
tree_view = gtk_builder_get_object (builder, "zenity_tree_view");
|
tree_view = gtk_builder_get_object (builder, "zenity_tree_view");
|
||||||
|
|
||||||
if (!(tree_data->radiobox || tree_data->checkbox))
|
if (!(tree_data->radiobox || tree_data->checkbox))
|
||||||
g_signal_connect (tree_view, "row-activated",
|
g_signal_connect (tree_view,
|
||||||
G_CALLBACK (zenity_tree_row_activated), data);
|
"row-activated",
|
||||||
|
G_CALLBACK (zenity_tree_row_activated),
|
||||||
|
data);
|
||||||
|
|
||||||
/* Create an empty list store */
|
/* Create an empty list store */
|
||||||
model = g_object_new (GTK_TYPE_LIST_STORE, NULL);
|
model = g_object_new (GTK_TYPE_LIST_STORE, NULL);
|
||||||
@ -440,7 +468,8 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
|
|||||||
column_types = g_new (GType, n_columns);
|
column_types = g_new (GType, n_columns);
|
||||||
|
|
||||||
for (i = 0; i < n_columns; i++) {
|
for (i = 0; i < n_columns; i++) {
|
||||||
/* Have the limitation that the radioboxes and checkboxes are in the first column */
|
/* Have the limitation that the radioboxes and checkboxes are in the
|
||||||
|
* first column */
|
||||||
if (i == 0 && (tree_data->checkbox || tree_data->radiobox))
|
if (i == 0 && (tree_data->checkbox || tree_data->radiobox))
|
||||||
column_types[i] = G_TYPE_BOOLEAN;
|
column_types[i] = G_TYPE_BOOLEAN;
|
||||||
else
|
else
|
||||||
@ -459,14 +488,16 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
|
|||||||
|
|
||||||
if (!(tree_data->radiobox || tree_data->checkbox)) {
|
if (!(tree_data->radiobox || tree_data->checkbox)) {
|
||||||
if (tree_data->multi)
|
if (tree_data->multi)
|
||||||
gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
gtk_tree_selection_set_mode (
|
||||||
|
gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
||||||
GTK_SELECTION_MULTIPLE);
|
GTK_SELECTION_MULTIPLE);
|
||||||
else
|
else
|
||||||
gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
gtk_tree_selection_set_mode (
|
||||||
|
gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
||||||
GTK_SELECTION_SINGLE);
|
GTK_SELECTION_SINGLE);
|
||||||
}
|
} else
|
||||||
else
|
gtk_tree_selection_set_mode (
|
||||||
gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
||||||
GTK_SELECTION_NONE);
|
GTK_SELECTION_NONE);
|
||||||
|
|
||||||
column_index = 0;
|
column_index = 0;
|
||||||
@ -479,43 +510,53 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
|
|||||||
cell_renderer = gtk_cell_renderer_toggle_new ();
|
cell_renderer = gtk_cell_renderer_toggle_new ();
|
||||||
|
|
||||||
if (tree_data->radiobox) {
|
if (tree_data->radiobox) {
|
||||||
g_object_set (G_OBJECT (cell_renderer), "radio", TRUE, NULL);
|
g_object_set (
|
||||||
g_object_set_data (G_OBJECT (model), "radio", GINT_TO_POINTER (1));
|
G_OBJECT (cell_renderer), "radio", TRUE, NULL);
|
||||||
|
g_object_set_data (
|
||||||
|
G_OBJECT (model), "radio", GINT_TO_POINTER (1));
|
||||||
}
|
}
|
||||||
|
|
||||||
g_signal_connect (cell_renderer, "toggled",
|
g_signal_connect (cell_renderer,
|
||||||
G_CALLBACK (zenity_tree_toggled_callback), model);
|
"toggled",
|
||||||
|
G_CALLBACK (zenity_tree_toggled_callback),
|
||||||
|
model);
|
||||||
|
|
||||||
column = gtk_tree_view_column_new_with_attributes (tmp->data,
|
column = gtk_tree_view_column_new_with_attributes (
|
||||||
cell_renderer,
|
tmp->data, cell_renderer, "active", column_index, NULL);
|
||||||
"active", column_index, NULL);
|
|
||||||
} else if (tree_data->imagebox) {
|
} else if (tree_data->imagebox) {
|
||||||
GtkCellRenderer *cell_renderer = gtk_cell_renderer_pixbuf_new ();
|
GtkCellRenderer *cell_renderer =
|
||||||
column = gtk_tree_view_column_new_with_attributes (tmp->data,
|
gtk_cell_renderer_pixbuf_new ();
|
||||||
cell_renderer, NULL);
|
column = gtk_tree_view_column_new_with_attributes (
|
||||||
gtk_tree_view_column_set_cell_data_func (column, cell_renderer,
|
tmp->data, cell_renderer, NULL);
|
||||||
zenity_load_pixbuf, NULL, NULL);
|
gtk_tree_view_column_set_cell_data_func (
|
||||||
}
|
column, cell_renderer, zenity_load_pixbuf, NULL, NULL);
|
||||||
else {
|
} else {
|
||||||
if (tree_data->editable) {
|
if (tree_data->editable) {
|
||||||
GtkCellRenderer *cell_renderer;
|
GtkCellRenderer *cell_renderer;
|
||||||
|
|
||||||
cell_renderer = gtk_cell_renderer_text_new ();
|
cell_renderer = gtk_cell_renderer_text_new ();
|
||||||
g_signal_connect (G_OBJECT (cell_renderer), "edited",
|
g_signal_connect (G_OBJECT (cell_renderer),
|
||||||
|
"edited",
|
||||||
G_CALLBACK (zenity_cell_edited_callback),
|
G_CALLBACK (zenity_cell_edited_callback),
|
||||||
gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)));
|
gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)));
|
||||||
g_object_set_data (G_OBJECT (cell_renderer), "column", GINT_TO_POINTER (column_index));
|
g_object_set_data (G_OBJECT (cell_renderer),
|
||||||
|
"column",
|
||||||
|
GINT_TO_POINTER (column_index));
|
||||||
|
|
||||||
column = gtk_tree_view_column_new_with_attributes (tmp->data,
|
column =
|
||||||
|
gtk_tree_view_column_new_with_attributes (tmp->data,
|
||||||
cell_renderer,
|
cell_renderer,
|
||||||
"text", column_index,
|
"text",
|
||||||
"editable", n_columns,
|
column_index,
|
||||||
|
"editable",
|
||||||
|
n_columns,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
} else {
|
||||||
else {
|
column =
|
||||||
column = gtk_tree_view_column_new_with_attributes (tmp->data,
|
gtk_tree_view_column_new_with_attributes (tmp->data,
|
||||||
gtk_cell_renderer_text_new (),
|
gtk_cell_renderer_text_new (),
|
||||||
"text", column_index,
|
"text",
|
||||||
|
column_index,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -526,27 +567,32 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
|
|||||||
gtk_tree_view_column_set_visible (column, FALSE);
|
gtk_tree_view_column_set_visible (column, FALSE);
|
||||||
|
|
||||||
first_column = TRUE;
|
first_column = TRUE;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (tree_data->editable) {
|
if (tree_data->editable) {
|
||||||
GtkCellRenderer *cell_renderer;
|
GtkCellRenderer *cell_renderer;
|
||||||
|
|
||||||
cell_renderer = gtk_cell_renderer_text_new ();
|
cell_renderer = gtk_cell_renderer_text_new ();
|
||||||
g_signal_connect (G_OBJECT (cell_renderer), "edited",
|
g_signal_connect (G_OBJECT (cell_renderer),
|
||||||
|
"edited",
|
||||||
G_CALLBACK (zenity_cell_edited_callback),
|
G_CALLBACK (zenity_cell_edited_callback),
|
||||||
gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)));
|
gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)));
|
||||||
g_object_set_data (G_OBJECT (cell_renderer), "column", GINT_TO_POINTER (column_index));
|
g_object_set_data (G_OBJECT (cell_renderer),
|
||||||
|
"column",
|
||||||
|
GINT_TO_POINTER (column_index));
|
||||||
|
|
||||||
column = gtk_tree_view_column_new_with_attributes (tmp->data,
|
column = gtk_tree_view_column_new_with_attributes (tmp->data,
|
||||||
cell_renderer,
|
cell_renderer,
|
||||||
"text", column_index,
|
"text",
|
||||||
"editable", n_columns,
|
column_index,
|
||||||
|
"editable",
|
||||||
|
n_columns,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
column = gtk_tree_view_column_new_with_attributes (tmp->data,
|
column = gtk_tree_view_column_new_with_attributes (tmp->data,
|
||||||
gtk_cell_renderer_text_new (),
|
gtk_cell_renderer_text_new (),
|
||||||
"text", column_index, NULL);
|
"text",
|
||||||
|
column_index,
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_tree_view_column_set_sort_column_id (column, column_index);
|
gtk_tree_view_column_set_sort_column_id (column, column_index);
|
||||||
@ -565,24 +611,42 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
|
|||||||
|
|
||||||
if (tree_data->radiobox || tree_data->checkbox) {
|
if (tree_data->radiobox || tree_data->checkbox) {
|
||||||
if (tree_data->data && *tree_data->data)
|
if (tree_data->data && *tree_data->data)
|
||||||
zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), tree_data->data, n_columns, TRUE, tree_data->editable);
|
zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view),
|
||||||
|
tree_data->data,
|
||||||
|
n_columns,
|
||||||
|
TRUE,
|
||||||
|
tree_data->editable);
|
||||||
else
|
else
|
||||||
zenity_tree_fill_entries_from_stdin (GTK_TREE_VIEW (tree_view), n_columns, TRUE, tree_data->editable);
|
zenity_tree_fill_entries_from_stdin (GTK_TREE_VIEW (tree_view),
|
||||||
}
|
n_columns,
|
||||||
else {
|
TRUE,
|
||||||
|
tree_data->editable);
|
||||||
|
} else {
|
||||||
if (tree_data->data && *tree_data->data)
|
if (tree_data->data && *tree_data->data)
|
||||||
zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view), tree_data->data, n_columns, FALSE, tree_data->editable);
|
zenity_tree_fill_entries (GTK_TREE_VIEW (tree_view),
|
||||||
|
tree_data->data,
|
||||||
|
n_columns,
|
||||||
|
FALSE,
|
||||||
|
tree_data->editable);
|
||||||
else
|
else
|
||||||
zenity_tree_fill_entries_from_stdin (GTK_TREE_VIEW (tree_view), n_columns, FALSE, tree_data->editable);
|
zenity_tree_fill_entries_from_stdin (GTK_TREE_VIEW (tree_view),
|
||||||
|
n_columns,
|
||||||
|
FALSE,
|
||||||
|
tree_data->editable);
|
||||||
}
|
}
|
||||||
|
|
||||||
zenity_util_show_dialog (dialog, data->attach);
|
zenity_util_show_dialog (dialog, data->attach);
|
||||||
|
|
||||||
if (tree_data->mid_search)
|
if (tree_data->mid_search)
|
||||||
gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(tree_view), (GtkTreeViewSearchEqualFunc) zenity_mid_search_func, model, NULL);
|
gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (tree_view),
|
||||||
|
(GtkTreeViewSearchEqualFunc) zenity_mid_search_func,
|
||||||
|
model,
|
||||||
|
NULL);
|
||||||
|
|
||||||
if(data->timeout_delay > 0) {
|
if (data->timeout_delay > 0) {
|
||||||
g_timeout_add_seconds (data->timeout_delay, (GSourceFunc) zenity_util_timeout_handle, dialog);
|
g_timeout_add_seconds (data->timeout_delay,
|
||||||
|
(GSourceFunc) zenity_util_timeout_handle,
|
||||||
|
dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_main ();
|
gtk_main ();
|
||||||
@ -591,12 +655,15 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_tree_dialog_get_selected (GtkTreeModel *model, GtkTreePath *path_buf, GtkTreeIter *iter, GtkTreeView *tree_view)
|
zenity_tree_dialog_get_selected (GtkTreeModel *model, GtkTreePath *path_buf,
|
||||||
{
|
GtkTreeIter *iter, GtkTreeView *tree_view) {
|
||||||
GValue value = {0, };
|
GValue value = {
|
||||||
|
0,
|
||||||
|
};
|
||||||
gint n_columns, i;
|
gint n_columns, i;
|
||||||
|
|
||||||
n_columns = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "n_columns"));
|
n_columns =
|
||||||
|
GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "n_columns"));
|
||||||
|
|
||||||
if (print_all_columns) {
|
if (print_all_columns) {
|
||||||
for (i = 0; i < n_columns; i++) {
|
for (i = 0; i < n_columns; i++) {
|
||||||
@ -617,23 +684,29 @@ zenity_tree_dialog_get_selected (GtkTreeModel *model, GtkTreePath *path_buf, Gtk
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
zenity_tree_dialog_toggle_get_selected (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, GtkTreeView *tree_view)
|
zenity_tree_dialog_toggle_get_selected (GtkTreeModel *model, GtkTreePath *path,
|
||||||
{
|
GtkTreeIter *iter, GtkTreeView *tree_view) {
|
||||||
GValue toggle_value = {0, };
|
GValue toggle_value = {
|
||||||
|
0,
|
||||||
|
};
|
||||||
gint n_columns, i;
|
gint n_columns, i;
|
||||||
|
|
||||||
n_columns = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "n_columns"));
|
n_columns =
|
||||||
|
GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_view), "n_columns"));
|
||||||
|
|
||||||
gtk_tree_model_get_value (model, iter, 0, &toggle_value);
|
gtk_tree_model_get_value (model, iter, 0, &toggle_value);
|
||||||
|
|
||||||
if (g_value_get_boolean (&toggle_value)) {
|
if (g_value_get_boolean (&toggle_value)) {
|
||||||
GValue value = {0, };
|
GValue value = {
|
||||||
|
0,
|
||||||
|
};
|
||||||
|
|
||||||
if (print_all_columns) {
|
if (print_all_columns) {
|
||||||
for (i = 1; i < n_columns; i++) {
|
for (i = 1; i < n_columns; i++) {
|
||||||
gtk_tree_model_get_value (model, iter, i, &value);
|
gtk_tree_model_get_value (model, iter, i, &value);
|
||||||
|
|
||||||
selected = g_slist_append (selected, g_value_dup_string (&value));
|
selected =
|
||||||
|
g_slist_append (selected, g_value_dup_string (&value));
|
||||||
g_value_unset (&value);
|
g_value_unset (&value);
|
||||||
}
|
}
|
||||||
g_value_unset (&toggle_value);
|
g_value_unset (&toggle_value);
|
||||||
@ -641,7 +714,8 @@ zenity_tree_dialog_toggle_get_selected (GtkTreeModel *model, GtkTreePath *path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; print_columns[i] != 0; i++) {
|
for (i = 0; print_columns[i] != 0; i++) {
|
||||||
gtk_tree_model_get_value (model, iter, print_columns[i] - 1, &value);
|
gtk_tree_model_get_value (
|
||||||
|
model, iter, print_columns[i] - 1, &value);
|
||||||
|
|
||||||
selected = g_slist_append (selected, g_value_dup_string (&value));
|
selected = g_slist_append (selected, g_value_dup_string (&value));
|
||||||
g_value_unset (&value);
|
g_value_unset (&value);
|
||||||
@ -654,9 +728,8 @@ zenity_tree_dialog_toggle_get_selected (GtkTreeModel *model, GtkTreePath *path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_tree_dialog_output (void)
|
zenity_tree_dialog_output (void) {
|
||||||
{
|
GObject *tree_view;
|
||||||
GObject *tree_view;
|
|
||||||
GtkTreeSelection *selection;
|
GtkTreeSelection *selection;
|
||||||
GtkTreeModel *model;
|
GtkTreeModel *model;
|
||||||
|
|
||||||
@ -664,7 +737,8 @@ GObject *tree_view;
|
|||||||
model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
|
model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
|
||||||
|
|
||||||
if (gtk_tree_model_get_column_type (model, 0) == G_TYPE_BOOLEAN)
|
if (gtk_tree_model_get_column_type (model, 0) == G_TYPE_BOOLEAN)
|
||||||
gtk_tree_model_foreach (model, (GtkTreeModelForeachFunc) zenity_tree_dialog_toggle_get_selected,
|
gtk_tree_model_foreach (model,
|
||||||
|
(GtkTreeModelForeachFunc) zenity_tree_dialog_toggle_get_selected,
|
||||||
GTK_TREE_VIEW (tree_view));
|
GTK_TREE_VIEW (tree_view));
|
||||||
else {
|
else {
|
||||||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
|
||||||
@ -678,8 +752,7 @@ GObject *tree_view;
|
|||||||
for (tmp = selected; tmp; tmp = tmp->next) {
|
for (tmp = selected; tmp; tmp = tmp->next) {
|
||||||
if (tmp->next != NULL) {
|
if (tmp->next != NULL) {
|
||||||
g_print ("%s%s", (gchar *) tmp->data, separator);
|
g_print ("%s%s", (gchar *) tmp->data, separator);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
g_print ("%s\n", (gchar *) tmp->data);
|
g_print ("%s\n", (gchar *) tmp->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -691,14 +764,13 @@ GObject *tree_view;
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data)
|
zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data) {
|
||||||
{
|
|
||||||
ZenityData *zen_data = data;
|
ZenityData *zen_data = data;
|
||||||
|
|
||||||
switch (response) {
|
switch (response) {
|
||||||
case GTK_RESPONSE_OK:
|
case GTK_RESPONSE_OK:
|
||||||
zenity_tree_dialog_output ();
|
zenity_tree_dialog_output ();
|
||||||
zenity_util_exit_code_with_data(ZENITY_OK, zen_data);
|
zenity_util_exit_code_with_data (ZENITY_OK, zen_data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GTK_RESPONSE_CANCEL:
|
case GTK_RESPONSE_CANCEL:
|
||||||
@ -711,12 +783,14 @@ zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (zen_data->extra_label && response < g_strv_length(zen_data->extra_label))
|
if (zen_data->extra_label &&
|
||||||
printf("%s\n",zen_data->extra_label[response]);
|
response < g_strv_length (zen_data->extra_label))
|
||||||
|
printf ("%s\n", zen_data->extra_label[response]);
|
||||||
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_ESC);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (channel != NULL && g_io_channel_get_flags (channel) & G_IO_FLAG_IS_READABLE)
|
if (channel != NULL &&
|
||||||
|
g_io_channel_get_flags (channel) & G_IO_FLAG_IS_READABLE)
|
||||||
g_io_channel_shutdown (channel, TRUE, NULL);
|
g_io_channel_shutdown (channel, TRUE, NULL);
|
||||||
|
|
||||||
gtk_main_quit ();
|
gtk_main_quit ();
|
||||||
@ -724,8 +798,7 @@ zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data)
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_tree_row_activated (GtkTreeView *tree_view, GtkTreePath *tree_path,
|
zenity_tree_row_activated (GtkTreeView *tree_view, GtkTreePath *tree_path,
|
||||||
GtkTreeViewColumn *tree_col, gpointer data)
|
GtkTreeViewColumn *tree_col, gpointer data) {
|
||||||
{
|
|
||||||
ZenityData *zen_data = data;
|
ZenityData *zen_data = data;
|
||||||
|
|
||||||
zenity_tree_dialog_output ();
|
zenity_tree_dialog_output ();
|
||||||
@ -734,8 +807,7 @@ zenity_tree_row_activated (GtkTreeView *tree_view, GtkTreePath *tree_path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
zenity_tree_column_is_hidden (gint column_index)
|
zenity_tree_column_is_hidden (gint column_index) {
|
||||||
{
|
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
if (hide_columns != NULL)
|
if (hide_columns != NULL)
|
||||||
@ -747,14 +819,12 @@ zenity_tree_column_is_hidden (gint column_index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gint *
|
static gint *
|
||||||
zenity_tree_extract_column_indexes (char *indexes, int n_columns)
|
zenity_tree_extract_column_indexes (char *indexes, int n_columns) {
|
||||||
{
|
|
||||||
char **tmp;
|
char **tmp;
|
||||||
gint *result;
|
gint *result;
|
||||||
gint i, j, index;
|
gint i, j, index;
|
||||||
|
|
||||||
tmp = g_strsplit (indexes,
|
tmp = g_strsplit (indexes, PRINT_HIDE_COLUMN_SEPARATOR, 0);
|
||||||
PRINT_HIDE_COLUMN_SEPARATOR, 0);
|
|
||||||
|
|
||||||
result = g_new (gint, 1);
|
result = g_new (gint, 1);
|
||||||
|
|
||||||
|
176
src/util.c
176
src/util.c
@ -29,15 +29,15 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <locale.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "zenity.h"
|
#include "zenity.h"
|
||||||
|
#include <errno.h>
|
||||||
|
#include <locale.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#ifdef GDK_WINDOWING_X11
|
#ifdef GDK_WINDOWING_X11
|
||||||
#include <gdk/gdkx.h>
|
#include <gdk/gdkx.h>
|
||||||
@ -49,9 +49,8 @@
|
|||||||
#define ZENITY_ERROR_DEFAULT -1
|
#define ZENITY_ERROR_DEFAULT -1
|
||||||
#define ZENITY_EXTRA_DEFAULT 127
|
#define ZENITY_EXTRA_DEFAULT 127
|
||||||
|
|
||||||
GtkBuilder*
|
GtkBuilder *
|
||||||
zenity_util_load_ui_file (const gchar *root_widget, ...)
|
zenity_util_load_ui_file (const gchar *root_widget, ...) {
|
||||||
{
|
|
||||||
va_list args;
|
va_list args;
|
||||||
gchar *arg = NULL;
|
gchar *arg = NULL;
|
||||||
GPtrArray *ptrarray;
|
GPtrArray *ptrarray;
|
||||||
@ -69,34 +68,33 @@ zenity_util_load_ui_file (const gchar *root_widget, ...)
|
|||||||
|
|
||||||
va_start (args, root_widget);
|
va_start (args, root_widget);
|
||||||
|
|
||||||
arg = va_arg (args, gchar*);
|
arg = va_arg (args, gchar *);
|
||||||
|
|
||||||
while (arg) {
|
while (arg) {
|
||||||
g_ptr_array_add (ptrarray, g_strdup (arg));
|
g_ptr_array_add (ptrarray, g_strdup (arg));
|
||||||
arg = va_arg (args, gchar*);
|
arg = va_arg (args, gchar *);
|
||||||
}
|
}
|
||||||
va_end (args);
|
va_end (args);
|
||||||
|
|
||||||
/* Enforce terminating NULL */
|
/* Enforce terminating NULL */
|
||||||
g_ptr_array_add (ptrarray, NULL);
|
g_ptr_array_add (ptrarray, NULL);
|
||||||
objects = (gchar**) g_ptr_array_free (ptrarray, FALSE);
|
objects = (gchar **) g_ptr_array_free (ptrarray, FALSE);
|
||||||
|
|
||||||
if (g_file_test (ZENITY_UI_FILE_RELATIVEPATH, G_FILE_TEST_EXISTS)) {
|
if (g_file_test (ZENITY_UI_FILE_RELATIVEPATH, G_FILE_TEST_EXISTS)) {
|
||||||
/* Try current dir, for debugging */
|
/* Try current dir, for debugging */
|
||||||
result = gtk_builder_add_objects_from_file (builder,
|
result = gtk_builder_add_objects_from_file (
|
||||||
ZENITY_UI_FILE_RELATIVEPATH,
|
builder, ZENITY_UI_FILE_RELATIVEPATH, objects, NULL);
|
||||||
objects, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == 0)
|
if (result == 0)
|
||||||
result = gtk_builder_add_objects_from_file (builder,
|
result = gtk_builder_add_objects_from_file (
|
||||||
ZENITY_UI_FILE_FULLPATH,
|
builder, ZENITY_UI_FILE_FULLPATH, objects, &error);
|
||||||
objects, &error);
|
|
||||||
|
|
||||||
g_strfreev (objects);
|
g_strfreev (objects);
|
||||||
|
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
g_warning ("Could not load ui file %s: %s", ZENITY_UI_FILE_FULLPATH,
|
g_warning ("Could not load ui file %s: %s",
|
||||||
|
ZENITY_UI_FILE_FULLPATH,
|
||||||
error->message);
|
error->message);
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
g_object_unref (builder);
|
g_object_unref (builder);
|
||||||
@ -105,16 +103,14 @@ zenity_util_load_ui_file (const gchar *root_widget, ...)
|
|||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
gchar*
|
gchar *
|
||||||
zenity_util_strip_newline (gchar *string)
|
zenity_util_strip_newline (gchar *string) {
|
||||||
{
|
|
||||||
gsize len;
|
gsize len;
|
||||||
|
|
||||||
g_return_val_if_fail (string != NULL, NULL);
|
g_return_val_if_fail (string != NULL, NULL);
|
||||||
|
|
||||||
len = strlen (string);
|
len = strlen (string);
|
||||||
while (len--)
|
while (len--) {
|
||||||
{
|
|
||||||
if (string[len] == '\n')
|
if (string[len] == '\n')
|
||||||
string[len] = '\0';
|
string[len] = '\0';
|
||||||
else
|
else
|
||||||
@ -125,8 +121,7 @@ zenity_util_strip_newline (gchar *string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
zenity_util_fill_file_buffer (GtkTextBuffer *buffer, const gchar *filename)
|
zenity_util_fill_file_buffer (GtkTextBuffer *buffer, const gchar *filename) {
|
||||||
{
|
|
||||||
GtkTextIter iter, end;
|
GtkTextIter iter, end;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
gchar buf[2048];
|
gchar buf[2048];
|
||||||
@ -165,7 +160,8 @@ zenity_util_fill_file_buffer (GtkTextBuffer *buffer, const gchar *filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (remaining) {
|
if (remaining) {
|
||||||
g_warning ("Invalid UTF-8 data encountered reading file '%s'", filename);
|
g_warning (
|
||||||
|
"Invalid UTF-8 data encountered reading file '%s'", filename);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,8 +178,7 @@ zenity_util_fill_file_buffer (GtkTextBuffer *buffer, const gchar *filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const gchar *
|
const gchar *
|
||||||
zenity_util_icon_name_from_filename (const gchar *filename)
|
zenity_util_icon_name_from_filename (const gchar *filename) {
|
||||||
{
|
|
||||||
if (!filename || !filename[0])
|
if (!filename || !filename[0])
|
||||||
return "dialog-warning"; /* default */
|
return "dialog-warning"; /* default */
|
||||||
|
|
||||||
@ -199,8 +194,8 @@ zenity_util_icon_name_from_filename (const gchar *filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
zenity_util_set_window_icon_from_file (GtkWidget *widget, const gchar *filename)
|
zenity_util_set_window_icon_from_file (
|
||||||
{
|
GtkWidget *widget, const gchar *filename) {
|
||||||
GdkPixbuf *pixbuf;
|
GdkPixbuf *pixbuf;
|
||||||
const gchar *icon_name;
|
const gchar *icon_name;
|
||||||
|
|
||||||
@ -215,8 +210,8 @@ zenity_util_set_window_icon_from_file (GtkWidget *widget, const gchar *filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
zenity_util_set_window_icon (GtkWidget *widget, const gchar *filename, const gchar *default_file)
|
zenity_util_set_window_icon (
|
||||||
{
|
GtkWidget *widget, const gchar *filename, const gchar *default_file) {
|
||||||
GdkPixbuf *pixbuf;
|
GdkPixbuf *pixbuf;
|
||||||
|
|
||||||
if (filename != NULL) {
|
if (filename != NULL) {
|
||||||
@ -231,8 +226,8 @@ zenity_util_set_window_icon (GtkWidget *widget, const gchar *filename, const gch
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
zenity_util_set_window_icon_from_icon_name (GtkWidget *widget, const gchar *filename, const gchar *default_icon_name)
|
zenity_util_set_window_icon_from_icon_name (
|
||||||
{
|
GtkWidget *widget, const gchar *filename, const gchar *default_icon_name) {
|
||||||
if (filename != NULL)
|
if (filename != NULL)
|
||||||
zenity_util_set_window_icon_from_file (widget, filename);
|
zenity_util_set_window_icon_from_file (widget, filename);
|
||||||
else
|
else
|
||||||
@ -240,8 +235,7 @@ zenity_util_set_window_icon_from_icon_name (GtkWidget *widget, const gchar *file
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
zenity_util_show_help (GError **error)
|
zenity_util_show_help (GError **error) {
|
||||||
{
|
|
||||||
gchar *tmp;
|
gchar *tmp;
|
||||||
tmp = g_find_program_in_path ("yelp");
|
tmp = g_find_program_in_path ("yelp");
|
||||||
|
|
||||||
@ -252,8 +246,7 @@ zenity_util_show_help (GError **error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
gint
|
gint
|
||||||
zenity_util_return_exit_code ( ZenityExitCode value )
|
zenity_util_return_exit_code (ZenityExitCode value) {
|
||||||
{
|
|
||||||
|
|
||||||
const gchar *env_var = NULL;
|
const gchar *env_var = NULL;
|
||||||
gint retval;
|
gint retval;
|
||||||
@ -261,50 +254,50 @@ zenity_util_return_exit_code ( ZenityExitCode value )
|
|||||||
switch (value) {
|
switch (value) {
|
||||||
|
|
||||||
case ZENITY_OK:
|
case ZENITY_OK:
|
||||||
env_var = g_getenv("ZENITY_OK");
|
env_var = g_getenv ("ZENITY_OK");
|
||||||
if (! env_var)
|
if (!env_var)
|
||||||
env_var = g_getenv("DIALOG_OK");
|
env_var = g_getenv ("DIALOG_OK");
|
||||||
if (! env_var)
|
if (!env_var)
|
||||||
retval = ZENITY_OK_DEFAULT;
|
retval = ZENITY_OK_DEFAULT;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ZENITY_CANCEL:
|
case ZENITY_CANCEL:
|
||||||
env_var = g_getenv("ZENITY_CANCEL");
|
env_var = g_getenv ("ZENITY_CANCEL");
|
||||||
if (! env_var)
|
if (!env_var)
|
||||||
env_var = g_getenv("DIALOG_CANCEL");
|
env_var = g_getenv ("DIALOG_CANCEL");
|
||||||
if (! env_var)
|
if (!env_var)
|
||||||
retval = ZENITY_CANCEL_DEFAULT;
|
retval = ZENITY_CANCEL_DEFAULT;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ZENITY_ESC:
|
case ZENITY_ESC:
|
||||||
env_var = g_getenv("ZENITY_ESC");
|
env_var = g_getenv ("ZENITY_ESC");
|
||||||
if (! env_var)
|
if (!env_var)
|
||||||
env_var = g_getenv("DIALOG_ESC");
|
env_var = g_getenv ("DIALOG_ESC");
|
||||||
if (! env_var)
|
if (!env_var)
|
||||||
retval = ZENITY_ESC_DEFAULT;
|
retval = ZENITY_ESC_DEFAULT;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ZENITY_EXTRA:
|
case ZENITY_EXTRA:
|
||||||
env_var = g_getenv("ZENITY_EXTRA");
|
env_var = g_getenv ("ZENITY_EXTRA");
|
||||||
if (! env_var)
|
if (!env_var)
|
||||||
env_var = g_getenv("DIALOG_EXTRA");
|
env_var = g_getenv ("DIALOG_EXTRA");
|
||||||
if (! env_var)
|
if (!env_var)
|
||||||
retval = ZENITY_EXTRA_DEFAULT;
|
retval = ZENITY_EXTRA_DEFAULT;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ZENITY_ERROR:
|
case ZENITY_ERROR:
|
||||||
env_var = g_getenv("ZENITY_ERROR");
|
env_var = g_getenv ("ZENITY_ERROR");
|
||||||
if (! env_var)
|
if (!env_var)
|
||||||
env_var = g_getenv("DIALOG_ERROR");
|
env_var = g_getenv ("DIALOG_ERROR");
|
||||||
if (! env_var)
|
if (!env_var)
|
||||||
retval = ZENITY_ERROR_DEFAULT;
|
retval = ZENITY_ERROR_DEFAULT;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ZENITY_TIMEOUT:
|
case ZENITY_TIMEOUT:
|
||||||
env_var = g_getenv("ZENITY_TIMEOUT");
|
env_var = g_getenv ("ZENITY_TIMEOUT");
|
||||||
if (! env_var)
|
if (!env_var)
|
||||||
env_var = g_getenv("DIALOG_TIMEOUT");
|
env_var = g_getenv ("DIALOG_TIMEOUT");
|
||||||
if (! env_var)
|
if (!env_var)
|
||||||
retval = ZENITY_TIMEOUT;
|
retval = ZENITY_TIMEOUT;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -318,16 +311,14 @@ zenity_util_return_exit_code ( ZenityExitCode value )
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
zenity_util_exit_code_with_data(ZenityExitCode value, ZenityData *zen_data)
|
zenity_util_exit_code_with_data (ZenityExitCode value, ZenityData *zen_data) {
|
||||||
{
|
|
||||||
zen_data->exit_code = zenity_util_return_exit_code (value);
|
zen_data->exit_code = zenity_util_return_exit_code (value);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef GDK_WINDOWING_X11
|
#ifdef GDK_WINDOWING_X11
|
||||||
|
|
||||||
static Window
|
static Window
|
||||||
transient_get_xterm (void)
|
transient_get_xterm (void) {
|
||||||
{
|
|
||||||
const char *wid_str = g_getenv ("WINDOWID");
|
const char *wid_str = g_getenv ("WINDOWID");
|
||||||
if (wid_str) {
|
if (wid_str) {
|
||||||
char *wid_str_end;
|
char *wid_str_end;
|
||||||
@ -336,8 +327,9 @@ transient_get_xterm (void)
|
|||||||
if (*wid_str != '\0' && *wid_str_end == '\0' && wid != 0) {
|
if (*wid_str != '\0' && *wid_str_end == '\0' && wid != 0) {
|
||||||
XWindowAttributes attrs;
|
XWindowAttributes attrs;
|
||||||
gdk_error_trap_push ();
|
gdk_error_trap_push ();
|
||||||
ret = XGetWindowAttributes (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), wid, &attrs);
|
ret = XGetWindowAttributes (
|
||||||
gdk_flush();
|
GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), wid, &attrs);
|
||||||
|
gdk_flush ();
|
||||||
if (gdk_error_trap_pop () != 0 || ret == 0) {
|
if (gdk_error_trap_pop () != 0 || ret == 0) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
@ -348,15 +340,13 @@ transient_get_xterm (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
transient_x_free (void *ptr)
|
transient_x_free (void *ptr) {
|
||||||
{
|
|
||||||
if (ptr)
|
if (ptr)
|
||||||
XFree (ptr);
|
XFree (ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
transient_is_toplevel (Window wid)
|
transient_is_toplevel (Window wid) {
|
||||||
{
|
|
||||||
XTextProperty prop;
|
XTextProperty prop;
|
||||||
Display *dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
|
Display *dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
|
||||||
if (!XGetWMName (dpy, wid, &prop))
|
if (!XGetWMName (dpy, wid, &prop))
|
||||||
@ -372,17 +362,13 @@ transient_is_toplevel (Window wid)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static Window
|
static Window
|
||||||
transient_get_xterm_toplevel (void)
|
transient_get_xterm_toplevel (void) {
|
||||||
{
|
|
||||||
Window xterm = transient_get_xterm ();
|
Window xterm = transient_get_xterm ();
|
||||||
Display *dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
|
Display *dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
|
||||||
while (xterm != None && !transient_is_toplevel (xterm))
|
while (xterm != None && !transient_is_toplevel (xterm)) {
|
||||||
{
|
|
||||||
Window root, parent, *children;
|
Window root, parent, *children;
|
||||||
unsigned nchildren;
|
unsigned nchildren;
|
||||||
XQueryTree (dpy, xterm,
|
XQueryTree (dpy, xterm, &root, &parent, &children, &nchildren);
|
||||||
&root, &parent,
|
|
||||||
&children, &nchildren);
|
|
||||||
transient_x_free (children);
|
transient_x_free (children);
|
||||||
if (parent == root)
|
if (parent == root)
|
||||||
xterm = None;
|
xterm = None;
|
||||||
@ -393,41 +379,39 @@ transient_get_xterm_toplevel (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
zenity_util_make_transient (GdkWindow *window, Window parent)
|
zenity_util_make_transient (GdkWindow *window, Window parent) {
|
||||||
{
|
|
||||||
Window parent_window = parent;
|
Window parent_window = parent;
|
||||||
if (parent_window == 0)
|
if (parent_window == 0)
|
||||||
parent_window = transient_get_xterm_toplevel ();
|
parent_window = transient_get_xterm_toplevel ();
|
||||||
if (parent_window != None) {
|
if (parent_window != None) {
|
||||||
XSetTransientForHint (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), GDK_WINDOW_XID(window), parent_window);
|
XSetTransientForHint (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
|
||||||
|
GDK_WINDOW_XID (window),
|
||||||
|
parent_window);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* GDK_WINDOWING_X11 */
|
#endif /* GDK_WINDOWING_X11 */
|
||||||
|
|
||||||
void
|
void
|
||||||
zenity_util_show_dialog (GtkWidget *dialog, guintptr parent)
|
zenity_util_show_dialog (GtkWidget *dialog, guintptr parent) {
|
||||||
{
|
|
||||||
gtk_widget_realize (dialog);
|
gtk_widget_realize (dialog);
|
||||||
#ifdef GDK_WINDOWING_X11
|
#ifdef GDK_WINDOWING_X11
|
||||||
if (GDK_IS_X11_DISPLAY (gdk_display_get_default ()))
|
if (GDK_IS_X11_DISPLAY (gdk_display_get_default ())) {
|
||||||
{
|
g_assert (gtk_widget_get_window (dialog));
|
||||||
g_assert (gtk_widget_get_window(dialog));
|
zenity_util_make_transient (gtk_widget_get_window (dialog), parent);
|
||||||
zenity_util_make_transient (gtk_widget_get_window(dialog), parent);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
gtk_widget_show (dialog);
|
gtk_widget_show (dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
zenity_util_timeout_handle (gpointer data)
|
zenity_util_timeout_handle (gpointer data) {
|
||||||
{
|
GtkDialog *dialog = GTK_DIALOG (data);
|
||||||
GtkDialog *dialog = GTK_DIALOG(data);
|
if (dialog != NULL)
|
||||||
if(dialog != NULL)
|
gtk_dialog_response (dialog, ZENITY_TIMEOUT);
|
||||||
gtk_dialog_response(dialog, ZENITY_TIMEOUT);
|
|
||||||
else {
|
else {
|
||||||
gtk_main_quit();
|
gtk_main_quit ();
|
||||||
exit(ZENITY_TIMEOUT);
|
exit (ZENITY_TIMEOUT);
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
31
src/util.h
31
src/util.h
@ -1,9 +1,8 @@
|
|||||||
#ifndef UTIL_H
|
#ifndef UTIL_H
|
||||||
#define UTIL_H
|
#define UTIL_H
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
|
||||||
#include "zenity.h"
|
#include "zenity.h"
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
@ -12,23 +11,21 @@ G_BEGIN_DECLS
|
|||||||
|
|
||||||
#define ZENITY_IMAGE_FULLPATH(filename) (ZENITY_DATADIR "/" filename)
|
#define ZENITY_IMAGE_FULLPATH(filename) (ZENITY_DATADIR "/" filename)
|
||||||
|
|
||||||
GtkBuilder* zenity_util_load_ui_file (const gchar *widget_root, ...) G_GNUC_NULL_TERMINATED;
|
GtkBuilder *zenity_util_load_ui_file (
|
||||||
gchar * zenity_util_strip_newline (gchar *string);
|
const gchar *widget_root, ...) G_GNUC_NULL_TERMINATED;
|
||||||
gboolean zenity_util_fill_file_buffer (GtkTextBuffer *buffer,
|
gchar *zenity_util_strip_newline (gchar *string);
|
||||||
const gchar *filename);
|
gboolean zenity_util_fill_file_buffer (
|
||||||
const gchar * zenity_util_icon_name_from_filename (const gchar *filename);
|
GtkTextBuffer *buffer, const gchar *filename);
|
||||||
void zenity_util_set_window_icon (GtkWidget *widget,
|
const gchar *zenity_util_icon_name_from_filename (const gchar *filename);
|
||||||
const gchar *filename,
|
void zenity_util_set_window_icon (
|
||||||
const gchar *default_file);
|
GtkWidget *widget, const gchar *filename, const gchar *default_file);
|
||||||
void zenity_util_set_window_icon_from_icon_name(GtkWidget *widget,
|
void zenity_util_set_window_icon_from_icon_name (
|
||||||
const gchar *filename,
|
GtkWidget *widget, const gchar *filename, const gchar *default_icon_name);
|
||||||
const gchar *default_icon_name);
|
void zenity_util_set_window_icon_from_file (
|
||||||
void zenity_util_set_window_icon_from_file (GtkWidget *widget,
|
GtkWidget *widget, const gchar *filename);
|
||||||
const gchar *filename);
|
|
||||||
void zenity_util_show_help (GError **error);
|
void zenity_util_show_help (GError **error);
|
||||||
gint zenity_util_return_exit_code (ZenityExitCode value);
|
gint zenity_util_return_exit_code (ZenityExitCode value);
|
||||||
void zenity_util_exit_code_with_data (ZenityExitCode value,
|
void zenity_util_exit_code_with_data (ZenityExitCode value, ZenityData *data);
|
||||||
ZenityData *data);
|
|
||||||
void zenity_util_show_dialog (GtkWidget *widget, guintptr parent);
|
void zenity_util_show_dialog (GtkWidget *widget, guintptr parent);
|
||||||
|
|
||||||
gboolean zenity_util_timeout_handle (gpointer data);
|
gboolean zenity_util_timeout_handle (gpointer data);
|
||||||
|
51
src/zenity.h
51
src/zenity.h
@ -7,9 +7,9 @@ G_BEGIN_DECLS
|
|||||||
|
|
||||||
#ifdef ENABLE_NLS
|
#ifdef ENABLE_NLS
|
||||||
#include <libintl.h>
|
#include <libintl.h>
|
||||||
#define _(String) dgettext(GETTEXT_PACKAGE,String)
|
#define _(String) dgettext (GETTEXT_PACKAGE, String)
|
||||||
#ifdef gettext_noop
|
#ifdef gettext_noop
|
||||||
#define N_(String) gettext_noop(String)
|
#define N_(String) gettext_noop (String)
|
||||||
#else
|
#else
|
||||||
#define N_(String) (String)
|
#define N_(String) (String)
|
||||||
#endif
|
#endif
|
||||||
@ -18,9 +18,9 @@ G_BEGIN_DECLS
|
|||||||
#define N_(String) (String)
|
#define N_(String) (String)
|
||||||
#define textdomain(String) (String)
|
#define textdomain(String) (String)
|
||||||
#define gettext(String) (String)
|
#define gettext(String) (String)
|
||||||
#define dgettext(Domain,String) (String)
|
#define dgettext(Domain, String) (String)
|
||||||
#define dcgettext(Domain,String,Type) (String)
|
#define dcgettext(Domain, String, Type) (String)
|
||||||
#define bindtextdomain(Domain,Directory) (Domain)
|
#define bindtextdomain(Domain, Directory) (Domain)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -163,7 +163,7 @@ typedef struct {
|
|||||||
gchar *dialog_text;
|
gchar *dialog_text;
|
||||||
gchar *separator;
|
gchar *separator;
|
||||||
gchar *date_format;
|
gchar *date_format;
|
||||||
// gchar *hide_column;
|
// gchar *hide_column;
|
||||||
gboolean show_header;
|
gboolean show_header;
|
||||||
} ZenityFormsData;
|
} ZenityFormsData;
|
||||||
|
|
||||||
@ -188,35 +188,26 @@ typedef struct {
|
|||||||
GtkWidget *entry_password;
|
GtkWidget *entry_password;
|
||||||
} ZenityPasswordData;
|
} ZenityPasswordData;
|
||||||
|
|
||||||
void zenity_calendar (ZenityData *data,
|
void zenity_calendar (ZenityData *data, ZenityCalendarData *calendar_data);
|
||||||
ZenityCalendarData *calendar_data);
|
void zenity_msg (ZenityData *data, ZenityMsgData *msg_data);
|
||||||
void zenity_msg (ZenityData *data,
|
void zenity_fileselection (ZenityData *data, ZenityFileData *file_data);
|
||||||
ZenityMsgData *msg_data);
|
void zenity_entry (ZenityData *data, ZenityEntryData *entry_data);
|
||||||
void zenity_fileselection (ZenityData *data,
|
void zenity_progress (ZenityData *data, ZenityProgressData *progress_data);
|
||||||
ZenityFileData *file_data);
|
void zenity_text (ZenityData *data, ZenityTextData *text_data);
|
||||||
void zenity_entry (ZenityData *data,
|
void zenity_tree (ZenityData *data, ZenityTreeData *tree_data);
|
||||||
ZenityEntryData *entry_data);
|
|
||||||
void zenity_progress (ZenityData *data,
|
|
||||||
ZenityProgressData *progress_data);
|
|
||||||
void zenity_text (ZenityData *data,
|
|
||||||
ZenityTextData *text_data);
|
|
||||||
void zenity_tree (ZenityData *data,
|
|
||||||
ZenityTreeData *tree_data);
|
|
||||||
#ifdef HAVE_LIBNOTIFY
|
#ifdef HAVE_LIBNOTIFY
|
||||||
void zenity_notification (ZenityData *data,
|
void zenity_notification (
|
||||||
ZenityNotificationData *notification_data);
|
ZenityData *data, ZenityNotificationData *notification_data);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void zenity_colorselection (ZenityData *data,
|
void zenity_colorselection (
|
||||||
ZenityColorData *notification_data);
|
ZenityData *data, ZenityColorData *notification_data);
|
||||||
void zenity_scale (ZenityData *data,
|
void zenity_scale (ZenityData *data, ZenityScaleData *scale_data);
|
||||||
ZenityScaleData *scale_data);
|
|
||||||
void zenity_about (ZenityData *data);
|
void zenity_about (ZenityData *data);
|
||||||
|
|
||||||
void zenity_password_dialog (ZenityData *data,
|
void zenity_password_dialog (
|
||||||
ZenityPasswordData *password_data);
|
ZenityData *data, ZenityPasswordData *password_data);
|
||||||
void zenity_forms_dialog (ZenityData *data,
|
void zenity_forms_dialog (ZenityData *data, ZenityFormsData *forms_data);
|
||||||
ZenityFormsData *forms_data);
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* ZENITY_H */
|
#endif /* ZENITY_H */
|
||||||
|
Reference in New Issue
Block a user