Compare commits

..

No commits in common. "master" and "dc72103c6a4a895785a725c21e0a66c3fb930671" have entirely different histories.

12 changed files with 271 additions and 662 deletions

View File

@ -13,26 +13,24 @@ add_definitions(-D_GNU_SOURCE)
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 11)
# locale.h
include(CheckIncludeFile)
CHECK_INCLUDE_FILE("locale.h" HAVE_LOCALE_H)
if(HAVE_LOCALE_H)
add_definitions(-DHAVE_LOCALE_H)
endif()
# GTK+
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED IMPORTED_TARGET "gtk+-3.0>=3.16.0")
pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET "glib-2.0>=2.43.4")
link_libraries(PkgConfig::GTK3 PkgConfig::GLIB)
# X11
find_package(X11 REQUIRED)
link_libraries(${X11_LIBRARIES})
# Build
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/.gresource.c"
add_custom_command(
OUTPUT ".gresource.c"
COMMAND glib-compile-resources
ARGS "--target" "${CMAKE_CURRENT_BINARY_DIR}/.gresource.c" "--generate-source" "--sourcedir" "${CMAKE_CURRENT_SOURCE_DIR}/src" "${CMAKE_CURRENT_SOURCE_DIR}/src/.gresource.xml"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/.gresource.xml" "${CMAKE_CURRENT_SOURCE_DIR}/src/zenity.ui"
ARGS "--target" "${CMAKE_BINARY_DIR}/.gresource.c" "--generate-source" "--sourcedir" "${CMAKE_SOURCE_DIR}/src" "${CMAKE_SOURCE_DIR}/src/.gresource.xml"
DEPENDS "src/.gresource.xml" "src/zenity.ui"
)
add_executable(zenity src/entry.c src/tree.c src/option.c src/text.c src/util.c src/main.c "${CMAKE_CURRENT_BINARY_DIR}/.gresource.c")
add_executable(zenity src/entry.c src/tree.c src/option.c src/util.c src/main.c "${CMAKE_BINARY_DIR}/.gresource.c")
target_compile_definitions(zenity PRIVATE "-DG_LOG_DOMAIN=\"Zenity\"")
# Install

113
meson.build Normal file
View File

@ -0,0 +1,113 @@
project('zenity', 'c',
version: '3.41.0',
meson_version: '>=0.53.0',
license: 'LGPL-2.1-or-later'
)
version_arr = meson.project_version().split('.')
zenity_version_major = version_arr[0].to_int()
zenity_version_minor = version_arr[1]
zenity_version_micro = version_arr[2].to_int()
zenity_prefix = get_option('prefix')
zenity_bindir = join_paths(zenity_prefix, get_option('bindir'))
zenity_libdir = join_paths(zenity_prefix, get_option('libdir'))
zenity_datadir = join_paths(zenity_prefix, get_option('datadir'), 'zenity')
zenity_localedir = join_paths(zenity_prefix, get_option('localedir'))
zenity_root_dir = include_directories('.')
zenity_po_dir = join_paths(meson.source_root(), 'po')
gnome = import('gnome')
i18n = import('i18n')
cc = meson.get_compiler('c')
zenity_conf = configuration_data()
zenity_conf.set_quoted('ZENITY_NAME', meson.project_name())
zenity_conf.set_quoted('ZENITY_VERSION', meson.project_version())
zenity_conf.set_quoted('ZENITY_STRING',
'@0@ @1@'.format(meson.project_name(), meson.project_version()))
zenity_conf.set_quoted('ZENITY_DATADIR', zenity_datadir)
zenity_conf.set_quoted('ZENITY_LIBDIR', zenity_libdir)
zenity_conf.set_quoted('ZENITY_LOCALE_DIR', zenity_localedir)
zenity_conf.set('VERSION', 'ZENITY_VERSION')
zenity_conf.set('GETTEXT_PACKAGE', 'ZENITY_NAME')
zenity_conf.set('LOCALEDIR', 'ZENITY_LOCALE_DIR')
zenity_conf.set('DEBUG', get_option('debug'))
check_headers = [
'sys/types.h',
'unistd.h',
'langinfo.h',
'locale.h'
]
foreach h : check_headers
cc.has_header(h, required: true)
endforeach
gtk_dep = dependency('gtk+-3.0', version: '>= 3.16.0')
# this is the minimum required glib according to the above-mentioned version of gtk
# it's really just being documented here for ease of reference.
glib_dep = dependency('glib-2.0', version: '>= 2.43.4')
# Optional dependencies
opt_missing_str = '''
Requested optional @0@ support but library not found.
Please ensure you have any required development libraries installed.'''
libnotify = dependency('libnotify', version: '>= 0.6.1', required: false)
if get_option('libnotify')
if libnotify.found()
zenity_conf.set('HAVE_LIBNOTIFY', true)
else
error(opt_missing_str.format('libnotify'))
endif
endif
webkitgtk = dependency('webkit2gtk-4.0', version: '>= 2.8.1', required: false)
if get_option('webkitgtk')
if webkitgtk.found()
zenity_conf.set('HAVE_WEBKITGTK', true)
else
error(opt_missing_str.format('webkitgtk'))
endif
endif
# link Xlib if we have it. This will likely be removed after gtk4 migration.
x11 = dependency('x11', required: false)
perl = find_program('perl', required: false)
if perl.found()
zenity_conf.set('PERL', perl.path())
endif
configure_file(
output: 'config.h',
configuration: zenity_conf
)
# Print a summary of options at the end.
summary({'prefix': zenity_prefix,
'libdir': zenity_libdir,
'datadir': zenity_datadir,
'localedir': zenity_localedir,
}, section: 'Directories')
summary({'libnotify': get_option('libnotify'),
'webkitgtk': get_option('webkitgtk'),
'gdialog script': perl.found(),
}, section: 'Configuration')
subdir('src')
subdir('data')
subdir('po')
subdir('help')
meson.add_install_script('meson_post_install.py')

View File

@ -21,8 +21,6 @@
* Authors: Glynn Foster <glynn.foster@sun.com>
*/
#include <ctype.h>
#include "util.h"
#include "zenity.h"
@ -47,22 +45,6 @@ zenity_entry_combo_activate_default (GtkEntry *entry, gpointer window) {
gtk_window_activate_default (GTK_WINDOW (window));
}
static void
zenity_entry_insert_text_event (GtkEditable *editable, const gchar *text,
gint length, gint *position, gpointer data) {
int i = 0;
if (gtk_editable_get_position (editable) == 0 && text[0] == '-' &&
gtk_entry_get_text (GTK_ENTRY (editable))[0] != '-') {
i++;
}
for (; i < length; i++) {
if (!isdigit (text[i])) {
g_signal_stop_emission_by_name (G_OBJECT (editable), "insert-text");
return;
}
}
}
void
zenity_entry (ZenityData *data, ZenityEntryData *entry_data) {
GtkBuilder *builder = NULL;
@ -103,9 +85,8 @@ zenity_entry (ZenityData *data, ZenityEntryData *entry_data) {
if (data->extra_label) {
gint i = 0;
while (data->extra_label[i] != NULL) {
gtk_dialog_add_button (GTK_DIALOG (dialog),
data->extra_label[i],
i + ZENITY_EXIT_CODE_LAST);
gtk_dialog_add_button (
GTK_DIALOG (dialog), data->extra_label[i], i);
i++;
}
}
@ -125,7 +106,7 @@ zenity_entry (ZenityData *data, ZenityEntryData *entry_data) {
text = gtk_builder_get_object (builder, "zenity_entry_text");
if (entry_data->dialog_text)
gtk_label_set_markup (
gtk_label_set_text_with_mnemonic (
GTK_LABEL (text), g_strcompress (entry_data->dialog_text));
vbox = gtk_builder_get_object (builder, "vbox4");
@ -152,12 +133,6 @@ zenity_entry (ZenityData *data, ZenityEntryData *entry_data) {
"activate",
G_CALLBACK (zenity_entry_combo_activate_default),
GTK_WINDOW (dialog));
if (entry_data->only_numerical)
g_signal_connect (G_OBJECT (gtk_bin_get_child (GTK_BIN (entry))),
"insert-text",
G_CALLBACK (zenity_entry_insert_text_event),
NULL);
} else {
entry = gtk_entry_new ();
@ -168,12 +143,6 @@ zenity_entry (ZenityData *data, ZenityEntryData *entry_data) {
if (entry_data->hide_text)
g_object_set (G_OBJECT (entry), "visibility", FALSE, NULL);
if (entry_data->only_numerical)
g_signal_connect (G_OBJECT (entry),
"insert-text",
G_CALLBACK (zenity_entry_insert_text_event),
NULL);
}
gtk_widget_show (entry);
@ -184,7 +153,7 @@ zenity_entry (ZenityData *data, ZenityEntryData *entry_data) {
g_object_unref (builder);
zenity_util_show_dialog (dialog);
zenity_util_show_dialog (dialog, data->attach);
if (data->timeout_delay > 0) {
g_timeout_add_seconds (data->timeout_delay,
@ -228,10 +197,8 @@ zenity_entry_dialog_response (GtkWidget *widget, int response, gpointer data) {
default:
if (zen_data->extra_label &&
(response - ZENITY_EXIT_CODE_LAST) <
g_strv_length (zen_data->extra_label))
printf ("%s\n",
zen_data->extra_label[response - ZENITY_EXIT_CODE_LAST]);
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);
break;
}

View File

@ -54,9 +54,6 @@ main (gint argc, gchar **argv) {
results->tree_data->data = (const gchar **) argv + 1;
zenity_tree (results->data, results->tree_data);
break;
case MODE_TEXTINFO:
zenity_text (results->data, results->text_data);
break;
case MODE_LAST:
g_printerr ("You must specify a dialog type. See 'zenity "
"--help' for details\n");

View File

@ -29,6 +29,7 @@
/* General Options */
static gchar *zenity_general_dialog_title;
static gchar *zenity_general_window_icon;
static int zenity_general_width;
static int zenity_general_height;
static gchar *zenity_general_dialog_text;
@ -43,12 +44,12 @@ static gchar *zenity_general_ok_button;
static gchar *zenity_general_cancel_button;
static gchar **zenity_general_extra_buttons;
static gboolean zenity_general_modal;
static guintptr zenity_general_attach;
/* Entry Dialog Options */
static gboolean zenity_entry_active;
static gchar *zenity_entry_entry_text;
static gboolean zenity_entry_hide_text;
static gboolean zenity_entry_only_numerical;
/* List Dialog Options */
static gboolean zenity_list_active;
@ -61,11 +62,6 @@ static gboolean zenity_list_hide_header;
static gboolean zenity_list_imagelist;
static gboolean zenity_list_mid_search;
/* Text Dialog Options */
static gboolean zenity_text_active;
static gchar *zenity_text_font;
static gchar *zenity_text_save_filename;
static GOptionEntry general_options[] = {{"title",
'\0',
0,
@ -73,6 +69,13 @@ static GOptionEntry general_options[] = {{"title",
&zenity_general_dialog_title,
"Set the dialog title",
"TITLE"},
{"window-icon",
'\0',
0,
G_OPTION_ARG_FILENAME,
&zenity_general_window_icon,
"Set the window icon",
"ICONPATH"},
{"width",
'\0',
0,
@ -123,6 +126,13 @@ static GOptionEntry general_options[] = {{"title",
&zenity_general_modal,
"Set the modal hint",
NULL},
{"attach",
'\0',
G_OPTION_FLAG_NOALIAS,
G_OPTION_ARG_INT,
&zenity_general_attach,
"Set the parent window to attach to",
"WINDOW"},
{NULL}};
static GOptionEntry entry_options[] = {{"entry",
@ -153,13 +163,6 @@ static GOptionEntry entry_options[] = {{"entry",
&zenity_entry_hide_text,
"Hide the entry text",
NULL},
{"only-numerical",
'\0',
0,
G_OPTION_ARG_NONE,
&zenity_entry_only_numerical,
"Only allow numerical input",
NULL},
{NULL}};
static GOptionEntry list_options[] = {{"list",
@ -258,50 +261,6 @@ static GOptionEntry list_options[] = {{"list",
NULL},
{NULL}};
static GOptionEntry text_options[] = {{"text-info",
'\0',
G_OPTION_FLAG_IN_MAIN,
G_OPTION_ARG_NONE,
&zenity_text_active,
"Display text information dialog",
NULL},
{"text",
'\0',
G_OPTION_FLAG_NOALIAS,
G_OPTION_ARG_STRING,
&zenity_general_dialog_text,
"Set the dialog text",
"TEXT"},
{"filename",
'\0',
G_OPTION_FLAG_NOALIAS,
G_OPTION_ARG_FILENAME,
&zenity_general_uri,
"Open file",
"FILENAME"},
{"font",
'\0',
0,
G_OPTION_ARG_STRING,
&zenity_text_font,
"Set the text font",
"TEXT"},
{"no-wrap",
'\0',
G_OPTION_FLAG_NOALIAS,
G_OPTION_ARG_NONE,
&zenity_general_dialog_no_wrap,
"Do not enable text wrapping",
NULL},
{"save-filename",
'\0',
0,
G_OPTION_ARG_STRING,
&zenity_text_save_filename,
"Set the initial filename for text save dialog",
"TEXT"},
{NULL}};
static ZenityParsingOptions *results;
static GOptionContext *ctx;
@ -314,7 +273,6 @@ zenity_option_init (void) {
results->mode = MODE_LAST;
results->data = g_new0 (ZenityData, 1);
results->entry_data = g_new0 (ZenityEntryData, 1);
results->text_data = g_new0 (ZenityTextData, 1);
results->tree_data = g_new0 (ZenityTreeData, 1);
}
@ -322,6 +280,8 @@ void
zenity_option_free (void) {
if (zenity_general_dialog_title)
g_free (zenity_general_dialog_title);
if (zenity_general_window_icon)
g_free (zenity_general_window_icon);
if (zenity_general_dialog_text)
g_free (zenity_general_dialog_text);
if (zenity_general_uri)
@ -344,11 +304,6 @@ zenity_option_free (void) {
if (zenity_list_hide_column)
g_free (zenity_list_hide_column);
if (zenity_text_font)
g_free (zenity_text_font);
if (zenity_text_save_filename)
g_free (zenity_text_save_filename);
g_option_context_free (ctx);
}
@ -386,6 +341,7 @@ static gboolean
zenity_general_pre_callback (GOptionContext *context, GOptionGroup *group,
gpointer data, GError **error) {
zenity_general_dialog_title = NULL;
zenity_general_window_icon = NULL;
zenity_general_width = -1;
zenity_general_height = -1;
zenity_general_dialog_text = NULL;
@ -400,6 +356,7 @@ zenity_general_pre_callback (GOptionContext *context, GOptionGroup *group,
zenity_general_dialog_no_markup = FALSE;
zenity_general_timeout_delay = -1;
zenity_general_modal = FALSE;
zenity_general_attach = 0;
return TRUE;
}
@ -410,7 +367,6 @@ zenity_entry_pre_callback (GOptionContext *context, GOptionGroup *group,
zenity_entry_active = FALSE;
zenity_entry_entry_text = NULL;
zenity_entry_hide_text = FALSE;
zenity_entry_only_numerical = FALSE;
return TRUE;
}
@ -431,15 +387,6 @@ zenity_list_pre_callback (GOptionContext *context, GOptionGroup *group,
return TRUE;
}
static gboolean
zenity_text_pre_callback (GOptionContext *context, GOptionGroup *group,
gpointer data, GError **error) {
zenity_text_active = FALSE;
zenity_text_font = NULL;
zenity_text_save_filename = NULL;
return TRUE;
}
/* Post parse callbacks assign the option values to
parsing result and makes some post condition tests */
@ -447,6 +394,7 @@ static gboolean
zenity_general_post_callback (GOptionContext *context, GOptionGroup *group,
gpointer data, GError **error) {
results->data->dialog_title = zenity_general_dialog_title;
results->data->window_icon = zenity_general_window_icon;
results->data->width = zenity_general_width;
results->data->height = zenity_general_height;
results->data->timeout_delay = zenity_general_timeout_delay;
@ -454,6 +402,7 @@ zenity_general_post_callback (GOptionContext *context, GOptionGroup *group,
results->data->cancel_label = zenity_general_cancel_button;
results->data->extra_label = zenity_general_extra_buttons;
results->data->modal = zenity_general_modal;
results->data->attach = zenity_general_attach;
return TRUE;
}
@ -467,7 +416,6 @@ zenity_entry_post_callback (GOptionContext *context, GOptionGroup *group,
results->entry_data->dialog_text = zenity_general_dialog_text;
results->entry_data->entry_text = zenity_entry_entry_text;
results->entry_data->hide_text = zenity_entry_hide_text;
results->entry_data->only_numerical = zenity_entry_only_numerical;
} else {
if (zenity_entry_entry_text)
zenity_option_error (zenity_option_get_name (
@ -478,11 +426,6 @@ zenity_entry_post_callback (GOptionContext *context, GOptionGroup *group,
zenity_option_error (
zenity_option_get_name (entry_options, &zenity_entry_hide_text),
ERROR_SUPPORT);
if (zenity_entry_only_numerical)
zenity_option_error (zenity_option_get_name (entry_options,
&zenity_entry_only_numerical),
ERROR_SUPPORT);
}
return TRUE;
@ -562,26 +505,6 @@ zenity_list_post_callback (GOptionContext *context, GOptionGroup *group,
return TRUE;
}
static gboolean
zenity_text_post_callback (GOptionContext *context, GOptionGroup *group,
gpointer data, GError **error) {
zenity_option_set_dialog_mode (zenity_text_active, MODE_TEXTINFO);
if (results->mode == MODE_TEXTINFO) {
results->text_data->dialog_text = zenity_general_dialog_text;
results->text_data->uri = zenity_general_uri;
results->text_data->no_wrap = zenity_general_dialog_no_wrap;
results->text_data->font = zenity_text_font;
results->text_data->save_filename = zenity_text_save_filename;
} else {
if (zenity_text_font)
zenity_option_error (
zenity_option_get_name (text_options, &zenity_text_font),
ERROR_SUPPORT);
}
return TRUE;
}
static GOptionContext *
zenity_create_context (void) {
GOptionContext *tmp_ctx;
@ -616,18 +539,6 @@ zenity_create_context (void) {
g_option_group_set_error_hook (a_group, zenity_option_error_callback);
g_option_context_add_group (tmp_ctx, a_group);
/* Adds text option entries */
a_group = g_option_group_new ("text-info",
"Text information options",
"Show text information options",
NULL,
NULL);
g_option_group_add_entries (a_group, text_options);
g_option_group_set_parse_hooks (
a_group, zenity_text_pre_callback, zenity_text_post_callback);
g_option_group_set_error_hook (a_group, zenity_option_error_callback);
g_option_context_add_group (tmp_ctx, a_group);
/* Adds gtk option entries */
a_group = gtk_get_option_group (TRUE);
g_option_context_add_group (tmp_ctx, a_group);

View File

@ -30,12 +30,7 @@
#include <locale.h>
#endif
typedef enum {
MODE_ENTRY,
MODE_LIST,
MODE_TEXTINFO,
MODE_LAST
} ZenityDialogMode;
typedef enum { MODE_ENTRY, MODE_LIST, MODE_LAST } ZenityDialogMode;
typedef enum {
ERROR_SYNTAX,
@ -49,7 +44,6 @@ typedef struct {
ZenityData *data;
ZenityEntryData *entry_data;
ZenityTextData *text_data;
ZenityTreeData *tree_data;
} ZenityParsingOptions;

View File

@ -1,303 +0,0 @@
/*
* text.c
*
* Copyright (C) 2002 Sun Microsystems, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* Authors: Glynn Foster <glynn.foster@sun.com>
*/
#include "util.h"
#include "zenity.h"
#include <gio/gio.h>
static ZenityTextData *zen_text_data;
static void zenity_text_dialog_response (
GtkWidget *widget, int response, gpointer data);
static gboolean
zenity_text_scroll_to_end (gpointer user_data) {
GtkTextIter iter;
gtk_text_buffer_get_end_iter (
gtk_text_view_get_buffer (GTK_TEXT_VIEW (user_data)), &iter);
gtk_text_view_scroll_to_iter (
GTK_TEXT_VIEW (user_data), &iter, 0.0, FALSE, 0, 0);
return G_SOURCE_REMOVE;
}
static gboolean
zenity_text_handle_stdin (
GIOChannel *channel, GIOCondition condition, gpointer data) {
static GtkTextBuffer *buffer;
static GtkTextView *text_view;
gchar buf[1024];
gsize len;
text_view = GTK_TEXT_VIEW (data);
buffer = gtk_text_view_get_buffer (text_view);
if ((condition & G_IO_IN) || (condition & (G_IO_IN | G_IO_HUP))) {
GError *error = NULL;
gint status;
while (channel->is_readable != TRUE)
;
do {
status = g_io_channel_read_chars (channel, buf, 1024, &len, &error);
while (gtk_events_pending ())
gtk_main_iteration ();
} while (status == G_IO_STATUS_AGAIN);
if (status != G_IO_STATUS_NORMAL) {
if (error) {
g_warning ("zenity_text_handle_stdin () : %s", error->message);
g_error_free (error);
error = NULL;
}
return FALSE;
}
if (len > 0) {
GtkTextIter end;
gchar *utftext;
gsize localelen;
gsize utflen;
gtk_text_buffer_get_end_iter (buffer, &end);
if (!g_utf8_validate (buf, len, 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);
g_free (utftext);
} else {
gtk_text_buffer_insert (buffer, &end, buf, len);
}
zenity_text_scroll_to_end (text_view);
}
}
return TRUE;
}
static void
zenity_text_fill_entries_from_stdin (GtkTextView *text_view) {
GIOChannel *channel;
channel = g_io_channel_unix_new (0);
g_io_channel_set_encoding (channel, "UTF-8", 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);
}
void
zenity_text (ZenityData *data, ZenityTextData *text_data) {
GtkBuilder *builder;
GtkWidget *dialog;
GtkWidget *ok_button;
GObject *text_view;
GtkTextBuffer *text_buffer;
GObject *text_label;
zen_text_data = text_data;
builder =
zenity_util_load_ui_file ("zenity_text_dialog", "textbuffer1", NULL);
if (builder == NULL) {
data->exit_code = zenity_util_return_exit_code (ZENITY_ERROR);
return;
}
gtk_builder_connect_signals (builder, NULL);
dialog =
GTK_WIDGET (gtk_builder_get_object (builder, "zenity_text_dialog"));
ok_button = GTK_WIDGET (
gtk_builder_get_object (builder, "zenity_text_close_button"));
g_signal_connect (G_OBJECT (dialog),
"response",
G_CALLBACK (zenity_text_dialog_response),
data);
if (data->dialog_title)
gtk_window_set_title (GTK_WINDOW (dialog), data->dialog_title);
text_buffer = gtk_text_buffer_new (NULL);
text_view = gtk_builder_get_object (builder, "zenity_text_view");
gtk_text_view_set_buffer (GTK_TEXT_VIEW (text_view), text_buffer);
if (text_data->no_wrap)
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), GTK_WRAP_NONE);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
if (text_data->font) {
PangoFontDescription *fontDesc =
pango_font_description_from_string (text_data->font);
gtk_widget_override_font (GTK_WIDGET (text_view), fontDesc);
}
G_GNUC_END_IGNORE_DEPRECATIONS
if (text_data->uri) {
zenity_util_fill_file_buffer (text_buffer, text_data->uri);
g_idle_add (zenity_text_scroll_to_end, text_view);
} else
zenity_text_fill_entries_from_stdin (GTK_TEXT_VIEW (text_view));
zen_text_data->buffer = text_buffer;
if (data->extra_label) {
gint i = 0;
while (data->extra_label[i] != NULL) {
gtk_dialog_add_button (GTK_DIALOG (dialog),
data->extra_label[i],
i + ZENITY_EXIT_CODE_LAST);
i++;
}
}
if (data->ok_label) {
gtk_button_set_label (GTK_BUTTON (ok_button), data->ok_label);
}
if (data->width > -1 || data->height > -1)
gtk_window_set_default_size (
GTK_WINDOW (dialog), data->width, data->height);
else
gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 400);
if (data->modal)
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
text_label = gtk_builder_get_object (builder, "zenity_text_label");
if (text_data->dialog_text)
gtk_label_set_markup (
GTK_LABEL (text_label), g_strcompress (text_data->dialog_text));
zenity_util_show_dialog (dialog);
g_object_unref (builder);
if (data->timeout_delay > 0) {
g_timeout_add_seconds (data->timeout_delay,
(GSourceFunc) zenity_util_timeout_handle,
dialog);
}
gtk_main ();
}
static void
zenity_save (GtkWidget *widget, GtkWindow *parent_window) {
GtkFileChooserNative *dialog;
GtkFileChooser *chooser;
GtkFileFilter *filter;
gint res;
dialog = gtk_file_chooser_native_new ("Save File",
parent_window,
GTK_FILE_CHOOSER_ACTION_SAVE,
"Save",
"Cancel");
chooser = GTK_FILE_CHOOSER (dialog);
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, "Log Files");
gtk_file_filter_add_pattern (filter, "*.log");
gtk_file_chooser_add_filter (chooser, filter);
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, "All Files");
gtk_file_filter_add_pattern (filter, "*");
gtk_file_chooser_add_filter (chooser, filter);
gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
if (zen_text_data->save_filename) {
gtk_file_chooser_set_current_name (
chooser, zen_text_data->save_filename);
}
res = gtk_native_dialog_run (GTK_NATIVE_DIALOG (dialog));
if (res == GTK_RESPONSE_ACCEPT) {
char *filename;
GtkTextBuffer *buffer;
GtkTextIter start;
GtkTextIter end;
char *text;
filename = gtk_file_chooser_get_filename (chooser);
buffer = zen_text_data->buffer;
gtk_text_buffer_get_start_iter (buffer, &start);
gtk_text_buffer_get_end_iter (buffer, &end);
text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
gtk_text_buffer_set_modified (buffer, FALSE);
g_file_set_contents (filename, text, -1, NULL);
g_free (filename);
}
g_object_unref (dialog);
}
static void
zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data) {
gboolean should_exit = TRUE;
ZenityData *zen_data = data;
switch (response) {
case GTK_RESPONSE_CLOSE:
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_OK);
break;
case ZENITY_TIMEOUT:
zen_data->exit_code = zenity_util_return_exit_code (ZENITY_TIMEOUT);
break;
case ZENITY_SAVE_BUTTON:
zenity_save (widget, GTK_WINDOW (gtk_widget_get_toplevel (widget)));
should_exit = FALSE;
break;
default:
if (zen_data->extra_label &&
(response - ZENITY_EXIT_CODE_LAST) <
g_strv_length (zen_data->extra_label))
printf ("%s\n",
zen_data->extra_label[response - ZENITY_EXIT_CODE_LAST]);
zenity_util_exit_code_with_data (ZENITY_ESC, zen_data);
break;
}
if (should_exit) {
gtk_main_quit ();
}
}

View File

@ -61,15 +61,12 @@ zenity_tree_dialog_untoggle (
}
static void
check_or_radio_label_activated_cb (
GtkCellRendererToggle *cell, gchar *path_string, gpointer data) {
GtkTreeModel *model;
check_or_radio_label_activated_cb (GtkTreeView *tree_view, GtkTreePath *path,
GtkTreeViewColumn *column, gpointer user_data) {
GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
GtkTreeIter iter;
GtkTreePath *path;
gboolean value;
model = GTK_TREE_MODEL (data);
/* Because this is a radio list, we should untoggle the previous toggle so
* that
* we only have one selection at any given time
@ -78,7 +75,6 @@ check_or_radio_label_activated_cb (
gtk_tree_model_foreach (model, zenity_tree_dialog_untoggle, NULL);
}
path = gtk_tree_path_new_from_string (path_string);
gtk_tree_model_get_iter (model, &iter, path);
gtk_tree_model_get (model, &iter, 0, &value, -1);
@ -415,9 +411,8 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) {
if (data->extra_label) {
gint i = 0;
while (data->extra_label[i] != NULL) {
gtk_dialog_add_button (GTK_DIALOG (dialog),
data->extra_label[i],
i + ZENITY_EXIT_CODE_LAST);
gtk_dialog_add_button (
GTK_DIALOG (dialog), data->extra_label[i], i);
i++;
}
}
@ -446,7 +441,15 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) {
tree_view = gtk_builder_get_object (builder, "zenity_tree_view");
if (!tree_data->radiobox && !tree_data->checkbox) {
if (tree_data->radiobox || tree_data->checkbox) {
gtk_tree_view_set_activate_on_single_click (
GTK_TREE_VIEW (tree_view), TRUE);
g_signal_connect (tree_view,
"row-activated",
G_CALLBACK (check_or_radio_label_activated_cb),
data);
} else {
g_signal_connect (tree_view,
"row-activated",
G_CALLBACK (zenity_tree_row_activated),
@ -483,7 +486,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) {
if (tree_data->radiobox || tree_data->checkbox) {
gtk_tree_selection_set_mode (
gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
GTK_SELECTION_NONE);
GTK_SELECTION_SINGLE);
} else {
if (tree_data->multi)
gtk_tree_selection_set_mode (
@ -511,11 +514,6 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) {
G_OBJECT (model), "radio", GINT_TO_POINTER (1));
}
g_signal_connect (cell_renderer,
"toggled",
G_CALLBACK (check_or_radio_label_activated_cb),
model);
column = gtk_tree_view_column_new_with_attributes (
tmp->data, cell_renderer, "active", column_index, NULL);
} else if (tree_data->imagebox) {
@ -637,7 +635,7 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data) {
gtk_tree_view_set_search_column (GTK_TREE_VIEW (tree_view), 1);
}
zenity_util_show_dialog (dialog);
zenity_util_show_dialog (dialog, data->attach);
if (tree_data->mid_search)
gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (tree_view),
@ -786,10 +784,8 @@ zenity_tree_dialog_response (GtkWidget *widget, int response, gpointer data) {
default:
if (zen_data->extra_label &&
(response - ZENITY_EXIT_CODE_LAST) <
g_strv_length (zen_data->extra_label))
printf ("%s\n",
zen_data->extra_label[response - ZENITY_EXIT_CODE_LAST]);
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);
break;
}

View File

@ -36,6 +36,10 @@
#include <stdlib.h>
#include <string.h>
#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
#endif
#define ZENITY_OK_DEFAULT 0
#define ZENITY_CANCEL_DEFAULT 1
#define ZENITY_ESC_DEFAULT 1
@ -240,9 +244,93 @@ zenity_util_exit_code_with_data (ZenityExitCode value, ZenityData *zen_data) {
zen_data->exit_code = zenity_util_return_exit_code (value);
}
#ifdef GDK_WINDOWING_X11
static Window
transient_get_xterm (void) {
const char *wid_str = g_getenv ("WINDOWID");
if (wid_str) {
char *wid_str_end;
int ret;
Window wid = strtoul (wid_str, &wid_str_end, 10);
if (*wid_str != '\0' && *wid_str_end == '\0' && wid != 0) {
XWindowAttributes attrs;
GdkDisplay *display;
display = gdk_display_get_default ();
gdk_x11_display_error_trap_push (display);
ret = XGetWindowAttributes (
GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), wid, &attrs);
if (gdk_x11_display_error_trap_pop (display) != 0 || ret == 0) {
return None;
}
return wid;
}
}
return None;
}
static void
transient_x_free (void *ptr) {
if (ptr)
XFree (ptr);
}
static gboolean
transient_is_toplevel (Window wid) {
XTextProperty prop;
Display *dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
if (!XGetWMName (dpy, wid, &prop))
return FALSE;
transient_x_free (prop.value);
return !!prop.value;
}
/*
* GNOME Terminal doesn't give us its toplevel window, but the WM needs a
* toplevel XID for proper stacking. Other terminals work fine without this
* magic. We can't use GDK here since "xterm" is a foreign window.
*/
static Window
transient_get_xterm_toplevel (void) {
Window xterm = transient_get_xterm ();
Display *dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
while (xterm != None && !transient_is_toplevel (xterm)) {
Window root, parent, *children;
unsigned nchildren;
XQueryTree (dpy, xterm, &root, &parent, &children, &nchildren);
transient_x_free (children);
if (parent == root)
xterm = None;
else
xterm = parent;
}
return xterm;
}
static void
zenity_util_make_transient (GdkWindow *window, Window parent) {
Window parent_window = parent;
if (parent_window == 0)
parent_window = transient_get_xterm_toplevel ();
if (parent_window != None) {
XSetTransientForHint (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
GDK_WINDOW_XID (window),
parent_window);
}
}
#endif /* GDK_WINDOWING_X11 */
void
zenity_util_show_dialog (GtkWidget *dialog) {
zenity_util_show_dialog (GtkWidget *dialog, guintptr parent) {
gtk_widget_realize (dialog);
#ifdef GDK_WINDOWING_X11
if (GDK_IS_X11_DISPLAY (gdk_display_get_default ())) {
g_assert (gtk_widget_get_window (dialog));
zenity_util_make_transient (gtk_widget_get_window (dialog), parent);
}
#endif
gtk_widget_show (dialog);
}

View File

@ -17,7 +17,7 @@ gboolean zenity_util_fill_file_buffer (
void zenity_util_show_help (GError **error);
gint zenity_util_return_exit_code (ZenityExitCode value);
void zenity_util_exit_code_with_data (ZenityExitCode value, ZenityData *data);
void zenity_util_show_dialog (GtkWidget *widget);
void zenity_util_show_dialog (GtkWidget *widget, guintptr parent);
gboolean zenity_util_timeout_handle (gpointer data);

View File

@ -7,6 +7,7 @@ G_BEGIN_DECLS
typedef struct {
gchar *dialog_title;
gchar *window_icon;
gchar *ok_label;
gchar *cancel_label;
gchar **extra_label;
@ -15,36 +16,25 @@ typedef struct {
gint exit_code;
gint timeout_delay;
gboolean modal;
guintptr attach;
} ZenityData;
typedef enum {
ZENITY_OK = 0,
ZENITY_OK,
ZENITY_CANCEL,
ZENITY_ESC,
ZENITY_ERROR,
ZENITY_EXTRA,
ZENITY_TIMEOUT,
ZENITY_SAVE_BUTTON,
ZENITY_EXIT_CODE_LAST
ZENITY_TIMEOUT
} ZenityExitCode;
typedef struct {
gchar *dialog_text;
gchar *entry_text;
gboolean hide_text;
gboolean only_numerical;
const gchar **data;
} ZenityEntryData;
typedef struct {
gchar *dialog_text;
gchar *uri;
gboolean no_wrap;
gchar *font;
gchar *save_filename;
GtkTextBuffer *buffer;
} ZenityTextData;
typedef struct {
gchar *dialog_text;
GSList *columns;
@ -62,7 +52,6 @@ typedef struct {
} ZenityTreeData;
void zenity_entry (ZenityData *data, ZenityEntryData *entry_data);
void zenity_text (ZenityData *data, ZenityTextData *text_data);
void zenity_tree (ZenityData *data, ZenityTreeData *tree_data);
G_END_DECLS

View File

@ -5,7 +5,7 @@
<object class="GtkDialog" id="zenity_entry_dialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title">Add a new entry</property>
<property name="title" translatable="yes">Add a new entry</property>
<property name="window_position">center</property>
<property name="type_hint">dialog</property>
<signal name="destroy" handler="gtk_main_quit" swapped="no"/>
@ -22,7 +22,7 @@
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="zenity_entry_cancel_button">
<property name="label">Cancel</property>
<property name="label" translatable="yes">Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
@ -36,7 +36,7 @@
</child>
<child>
<object class="GtkButton" id="zenity_entry_ok_button">
<property name="label">OK</property>
<property name="label" translatable="yes">OK</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
@ -72,7 +72,7 @@
<object class="GtkLabel" id="zenity_entry_text">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label">Enter new text:</property>
<property name="label" translatable="yes">_Enter new text:</property>
<property name="use_underline">True</property>
<property name="xalign">0</property>
</object>
@ -109,7 +109,7 @@
<object class="GtkDialog" id="zenity_tree_dialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title">Select items from the list</property>
<property name="title" translatable="yes">Select items from the list</property>
<property name="window_position">center</property>
<property name="default_width">300</property>
<property name="default_height">196</property>
@ -126,7 +126,7 @@
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="zenity_tree_cancel_button">
<property name="label">Cancel</property>
<property name="label" translatable="yes">Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
@ -140,7 +140,7 @@
</child>
<child>
<object class="GtkButton" id="zenity_tree_ok_button">
<property name="label">OK</property>
<property name="label" translatable="yes">OK</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
@ -171,7 +171,7 @@
<object class="GtkLabel" id="zenity_tree_text">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label">Select items from the list below.</property>
<property name="label" translatable="yes">Select items from the list below.</property>
<property name="xalign">0</property>
</object>
<packing>
@ -217,145 +217,4 @@
<action-widget response="-5">zenity_tree_ok_button</action-widget>
</action-widgets>
</object>
<object class="GtkTextBuffer" id="textbuffer1"/>
<object class="GtkDialog" id="zenity_text_dialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title">Text View</property>
<property name="window_position">center</property>
<property name="default_width">300</property>
<property name="default_height">200</property>
<property name="type_hint">dialog</property>
<signal name="destroy" handler="gtk_main_quit" swapped="no"/>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="zenity_text_save_button">
<property name="label">Save</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="image_position">right</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="zenity_text_close_button">
<property name="label">OK</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="image_position">right</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox" id="vbox30">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">6</property>
<child>
<object class="GtkBox" id="vbox40">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="zenity_text_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label">Text information:</property>
<property name="use_underline">True</property>
<property name="wrap">True</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
<child>
<object class="GtkBox" id="vbox5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkScrolledWindow" id="zenity_text_scrolled_window">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">etched-in</property>
<child>
<object class="GtkTextView" id="zenity_text_view">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="pixels_above_lines">2</property>
<property name="pixels_below_lines">2</property>
<property name="editable">False</property>
<property name="wrap_mode">word</property>
<property name="left_margin">2</property>
<property name="right_margin">2</property>
<property name="buffer">textbuffer1</property>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-7">zenity_text_close_button</action-widget>
<action-widget response="6">zenity_text_save_button</action-widget>
</action-widgets>
</object>
</interface>