4
* Created by: Axel von Bertoldi
5
* Last Modified: January 2008
6
* Last Modified by: Axel von Bertoldi
7
* (C) 2005-2008 Axel von Bertoldi
9
* This program is free software; you can redistribute it and/or modify it
10
* under the terms of the GNU General Public License as published by the Free
11
* Software Foundation; either version 2 of the License, or (at your option)
14
* This program is distributed in the hope that it will be useful, but WITHOUT
15
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19
* You should have received a copy of the GNU General Public License along with
20
* this program; if not, write to:
21
* The Free Software Foundation, Inc.,
22
* 51 Franklin Street, Fifth Floor
23
* Boston, MA 02110-1301, USA.
26
#include <glib/gprintf.h>
29
/******************************************************************************/
31
utils_check_gerror (GError **error)
35
if (DEBUG) g_printf ("error: %s\n", (*error)->message);
36
utils_show_dialog ("Application Error",
39
g_error_free (*error);
45
/******************************************************************************/
47
utils_show_dialog (gchar *title, gchar *message, GtkMessageType type)
49
GtkWidget *dialog = gtk_message_dialog_new (NULL,
54
gtk_window_set_title (GTK_WINDOW (dialog), title);
56
g_signal_connect (G_OBJECT (dialog), "destroy",
57
G_CALLBACK (gtk_widget_destroy), dialog);
58
g_signal_connect (G_OBJECT (dialog), "delete_event",
59
G_CALLBACK (gtk_widget_destroy), dialog);
60
g_signal_connect_swapped (G_OBJECT (dialog),
62
G_CALLBACK (gtk_widget_destroy),
64
gtk_widget_show_all (dialog);
68
/******************************************************************************/
70
utils_get_scaled_image_from_file (gchar *file_name, int size) {
71
GdkPixbuf *orig = gdk_pixbuf_new_from_file (file_name, NULL);
72
if (orig == NULL) return NULL;
74
GdkPixbuf *scaled = gdk_pixbuf_scale_simple (orig,
78
GtkWidget *icon = gtk_image_new_from_pixbuf (scaled);
79
g_object_unref (orig);
80
g_object_unref (scaled);
83
/******************************************************************************/
85
g_slist_swap_data (GSList *list, guint index) {
87
GSList *first = g_slist_nth (list, index);
88
GSList *second = first->next;
91
first->data = second->data;
95
/******************************************************************************/
97
utils_sort_alpha (const gchar **s1,
99
return g_utf8_collate ((gchar *)*s1, (gchar *)*s2);
101
/******************************************************************************/
103
utils_clamp_file_name (const gchar *file_name, int length, gboolean *clamped) {
104
/* clamped is true if the string is actually clamped */
107
if (strlen (file_name) > length) {
108
tmp = g_strndup (file_name, length - 3);
109
ret = g_strdup_printf ("%s...", tmp);
111
if (clamped != NULL) *clamped = TRUE;
115
if (clamped != NULL) *clamped = FALSE;
116
return g_strdup (file_name);
119
/******************************************************************************/