~ubuntu-branches/ubuntu/karmic/file-browser-applet/karmic

« back to all changes in this revision

Viewing changes to src/utils.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Starr-Bochicchio
  • Date: 2008-11-04 13:34:36 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20081104133436-7kgxv6psv6mjnxh0
Tags: 0.6.0-0ubuntu1
* New upstream release.
 - Added context menu with a few actions (open-with, new folder here, 
   delete file/folder, create/extract archive, create CD/DVD from 
   file/folder, compile a tex file).
 - Added configuration option to make text vertical/horizontal when 
   the panel is vertical.
 - Added tooltips to configuration dialog.
 - Fixed bugs #21, #30, #34, #37, #39.
 - Plugged some memory leaks (thanks Silvio Ricardo Cordeiro).
 - Lots of code cleanup. 
* debian/control:
 - Add suggests on file-roller, brasero, and rubber 
   for new features.
 - Add Vcs-Bzr field.
 - Add versionized Build-Depend on libgtk2.0-dev (>= 2.14)

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include "utils.h"
30
30
 
31
31
/******************************************************************************/
 
32
void
 
33
garbage_init (Garbage *garabage) {
 
34
        GPtrArray **_garbage = (GPtrArray**)garabage;
 
35
        *_garbage = g_ptr_array_new();
 
36
}
 
37
/******************************************************************************/
 
38
void
 
39
garbage_empty (Garbage *garabage, gboolean reuse) {
 
40
        GPtrArray **_garbage = (GPtrArray**)garabage;
 
41
 
 
42
        g_ptr_array_foreach (*_garbage, (GFunc)g_free, NULL);
 
43
        g_ptr_array_free (*_garbage, TRUE);
 
44
        *_garbage = reuse ? g_ptr_array_new() : NULL;
 
45
}
 
46
/******************************************************************************/
 
47
void
 
48
garbage_add_item (Garbage garabage, gpointer item) {
 
49
        GPtrArray *_garbage = (GPtrArray*)garabage;
 
50
        g_ptr_array_add (_garbage, item);
 
51
}
 
52
/******************************************************************************/
32
53
gboolean
33
 
utils_check_gerror (GError **error) {
 
54
utils_gerror_ok (GError **error, gboolean show_error) {
34
55
        if (DEBUG) g_printf ("In %s\n", __FUNCTION__);
35
56
 
36
57
        if (*error) {
37
58
                if (DEBUG) g_printf ("error: %s\n", (*error)->message);
38
 
                utils_show_dialog ("Application Error",
39
 
                                                   (*error)->message,
40
 
                                                   GTK_MESSAGE_ERROR);
 
59
 
 
60
                if (show_error)
 
61
                        utils_show_dialog ("Error", (*error)->message, GTK_MESSAGE_ERROR);
 
62
 
41
63
                g_error_free (*error);
42
64
                *error = NULL;
43
 
                return TRUE;
 
65
                return FALSE;
44
66
        }
45
 
        return FALSE;
 
67
        return TRUE;
46
68
}
47
69
/******************************************************************************/
48
70
void
53
75
                                                                                                0,
54
76
                                                                                                type,
55
77
                                                                                                GTK_BUTTONS_CLOSE,
 
78
                                                                                                "%s",
56
79
                                                                                                message);
57
80
        gtk_window_set_title (GTK_WINDOW (dialog), title);
58
81
 
59
 
        g_signal_connect (G_OBJECT (dialog), "destroy",
60
 
                                          G_CALLBACK (gtk_widget_destroy), dialog);
61
 
    g_signal_connect (G_OBJECT (dialog), "delete_event",
62
 
                      G_CALLBACK (gtk_widget_destroy), dialog);
63
 
        g_signal_connect_swapped (G_OBJECT (dialog),
64
 
                                                          "response",
65
 
                                                          G_CALLBACK (gtk_widget_destroy),
66
 
                                                          dialog);
 
82
        g_signal_connect (G_OBJECT (dialog), "destroy", G_CALLBACK (gtk_widget_destroy), dialog);
 
83
    g_signal_connect (G_OBJECT (dialog), "delete_event", G_CALLBACK (gtk_widget_destroy), dialog);
 
84
        g_signal_connect_swapped (G_OBJECT (dialog), "response", G_CALLBACK (gtk_widget_destroy), dialog);
67
85
        gtk_widget_show_all (dialog);
68
86
 
69
87
        return;
70
88
}
71
89
/******************************************************************************/
72
90
GtkWidget*
73
 
utils_get_scaled_image_from_file (gchar *file_name, int size) {
 
91
utils_get_scaled_image_from_file (const gchar *file_name, int size) {
74
92
        if (DEBUG) g_printf ("In %s\n", __FUNCTION__);
75
93
 
76
 
                GdkPixbuf *pixbuf   = gdk_pixbuf_new_from_file_at_size (file_name,
77
 
                                                                                                                           size,
78
 
                                                                                                                           size,
79
 
                                                                                                                           NULL);
 
94
        GdkPixbuf *pixbuf   = gdk_pixbuf_new_from_file_at_size (file_name,
 
95
                                                                                                                        size,
 
96
                                                                                                                        size,
 
97
                                                                                                                        NULL);
80
98
                if (pixbuf == NULL) return NULL;
81
99
 
82
100
                GtkWidget *icon = gtk_image_new_from_pixbuf (pixbuf);
98
116
        return list;
99
117
}
100
118
/******************************************************************************/
101
 
gint
102
 
utils_sort_alpha (const gchar **s1,
103
 
                                  const gchar **s2) {
104
 
        if (DEBUG) g_printf ("In %s\n", __FUNCTION__);
105
 
 
106
 
        return g_utf8_collate ((gchar *)*s1, (gchar *)*s2);
107
 
}
108
 
/******************************************************************************/
109
 
gchar *
110
 
utils_clamp_file_name (const gchar *file_name, int length, gboolean *clamped) {
111
 
        if (DEBUG) g_printf ("In %s\n", __FUNCTION__);
112
 
 
113
 
/* clamped is true if the string is actually clamped */
114
 
        gchar *tmp, *ret;
115
 
 
116
 
        if (strlen (file_name) > length) {
117
 
                tmp = g_strndup (file_name, length - 3);
118
 
                ret = g_strdup_printf ("%s...", tmp);
119
 
                g_free (tmp);
120
 
                if (clamped != NULL) *clamped = TRUE;
121
 
                return ret;
122
 
        }
123
 
        else {
124
 
                if (clamped != NULL) *clamped = FALSE;
125
 
                return g_strdup (file_name);
126
 
        }
127
 
}
128
 
/******************************************************************************/