Rework zenity_util_set_window_icon* to not use stock images
This commit is contained in:
parent
1a43253ac5
commit
fba4f05582
@ -120,20 +120,20 @@ 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_stock (dialog, data->window_icon, GTK_STOCK_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_stock (dialog, data->window_icon, GTK_STOCK_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_ERROR:
|
case ZENITY_MSG_ERROR:
|
||||||
zenity_util_set_window_icon_from_stock (dialog, data->window_icon, GTK_STOCK_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_stock (dialog, data->window_icon, GTK_STOCK_DIALOG_INFO);
|
zenity_util_set_window_icon_from_icon_name (dialog, data->window_icon, "dialog-information");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
59
src/util.c
59
src/util.c
@ -178,32 +178,36 @@ zenity_util_fill_file_buffer (GtkTextBuffer *buffer, const gchar *filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const gchar *
|
const gchar *
|
||||||
zenity_util_stock_from_filename (const gchar *filename)
|
zenity_util_icon_name_from_filename (const gchar *filename)
|
||||||
{
|
{
|
||||||
if (!filename || !filename[0])
|
if (!filename || !filename[0])
|
||||||
return GTK_STOCK_DIALOG_WARNING; /* default */
|
return "dialog-warning"; /* default */
|
||||||
|
|
||||||
if (!g_ascii_strcasecmp (filename, "warning"))
|
if (!g_ascii_strcasecmp (filename, "warning"))
|
||||||
return GTK_STOCK_DIALOG_WARNING;
|
return "dialog-warning";
|
||||||
if (!g_ascii_strcasecmp (filename, "info"))
|
if (!g_ascii_strcasecmp (filename, "info"))
|
||||||
return GTK_STOCK_DIALOG_INFO;
|
return "dialog-information";
|
||||||
if (!g_ascii_strcasecmp (filename, "question"))
|
if (!g_ascii_strcasecmp (filename, "question"))
|
||||||
return GTK_STOCK_DIALOG_QUESTION;
|
return "dialog-question";
|
||||||
if (!g_ascii_strcasecmp (filename, "error"))
|
if (!g_ascii_strcasecmp (filename, "error"))
|
||||||
return GTK_STOCK_DIALOG_ERROR;
|
return "dialog-error";
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
GdkPixbuf *
|
void
|
||||||
zenity_util_pixbuf_new_from_file (GtkWidget *widget, const gchar *filename)
|
zenity_util_set_window_icon_from_file (GtkWidget *widget, const gchar *filename)
|
||||||
{
|
{
|
||||||
const gchar *stock;
|
GdkPixbuf *pixbuf;
|
||||||
|
const gchar *icon_name;
|
||||||
|
|
||||||
stock = zenity_util_stock_from_filename (filename);
|
icon_name = zenity_util_icon_name_from_filename (filename);
|
||||||
if (stock)
|
if (icon_name) {
|
||||||
return gtk_widget_render_icon (widget, stock, GTK_ICON_SIZE_BUTTON, NULL);
|
gtk_window_set_icon_name (GTK_WINDOW (widget), icon_name);
|
||||||
|
} else {
|
||||||
return gdk_pixbuf_new_from_file (filename, NULL);
|
pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
|
||||||
|
gtk_window_set_icon (GTK_WINDOW (widget), pixbuf);
|
||||||
|
g_object_unref (pixbuf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -211,33 +215,24 @@ zenity_util_set_window_icon (GtkWidget *widget, const gchar *filename, const gch
|
|||||||
{
|
{
|
||||||
GdkPixbuf *pixbuf;
|
GdkPixbuf *pixbuf;
|
||||||
|
|
||||||
if (filename != NULL)
|
if (filename != NULL) {
|
||||||
pixbuf = zenity_util_pixbuf_new_from_file (widget, (gchar *) filename);
|
zenity_util_set_window_icon_from_file (widget, filename);
|
||||||
else
|
} else {
|
||||||
pixbuf = gdk_pixbuf_new_from_file (default_file, NULL);
|
pixbuf = gdk_pixbuf_new_from_file (default_file, NULL);
|
||||||
|
|
||||||
if (pixbuf != NULL) {
|
if (pixbuf != NULL) {
|
||||||
gtk_window_set_icon (GTK_WINDOW (widget), pixbuf);
|
gtk_window_set_icon (GTK_WINDOW (widget), pixbuf);
|
||||||
g_object_unref (pixbuf);
|
g_object_unref (pixbuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
zenity_util_set_window_icon_from_stock (GtkWidget *widget, const gchar *filename, const gchar *default_stock_id)
|
zenity_util_set_window_icon_from_icon_name (GtkWidget *widget, const gchar *filename, const gchar *default_icon_name)
|
||||||
{
|
{
|
||||||
GdkPixbuf *pixbuf;
|
if (filename != NULL)
|
||||||
|
zenity_util_set_window_icon_from_file (widget, filename);
|
||||||
if (filename != NULL) {
|
else
|
||||||
pixbuf = zenity_util_pixbuf_new_from_file (widget, (gchar *) filename);
|
gtk_window_set_icon_name (GTK_WINDOW (widget), default_icon_name);
|
||||||
}
|
|
||||||
else {
|
|
||||||
pixbuf = gtk_widget_render_icon (widget, default_stock_id, GTK_ICON_SIZE_BUTTON, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pixbuf != NULL) {
|
|
||||||
gtk_window_set_icon (GTK_WINDOW (widget), pixbuf);
|
|
||||||
g_object_unref (pixbuf);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -19,14 +19,14 @@ GtkBuilder* zenity_util_load_ui_file (const gchar *widge
|
|||||||
gchar * zenity_util_strip_newline (gchar *string);
|
gchar * zenity_util_strip_newline (gchar *string);
|
||||||
gboolean zenity_util_fill_file_buffer (GtkTextBuffer *buffer,
|
gboolean zenity_util_fill_file_buffer (GtkTextBuffer *buffer,
|
||||||
const gchar *filename);
|
const gchar *filename);
|
||||||
const gchar * zenity_util_stock_from_filename (const gchar *filename);
|
const gchar * zenity_util_icon_name_from_filename (const gchar *filename);
|
||||||
void zenity_util_set_window_icon (GtkWidget *widget,
|
void zenity_util_set_window_icon (GtkWidget *widget,
|
||||||
const gchar *filename,
|
const gchar *filename,
|
||||||
const gchar *default_file);
|
const gchar *default_file);
|
||||||
void zenity_util_set_window_icon_from_stock (GtkWidget *widget,
|
void zenity_util_set_window_icon_from_icon_name(GtkWidget *widget,
|
||||||
const gchar *filename,
|
const gchar *filename,
|
||||||
const gchar *default_stock_id);
|
const gchar *default_icon_name);
|
||||||
GdkPixbuf * zenity_util_pixbuf_new_from_file (GtkWidget *widget,
|
void zenity_util_set_window_icon_from_file (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);
|
||||||
|
Reference in New Issue
Block a user