1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
#include <config.h>
#include <stdio.h>
#include <string.h>
#include <gtk/gtk.h>
#ifndef USE_STABLE_LIBGNOMEUI
#include <libgnomeui/gnome-icon-lookup.h>
#endif
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <math.h>
#include "egg-recent-util.h"
#ifdef G_OS_WIN32
#include <windows.h>
#endif
#define EGG_RECENT_UTIL_HOSTNAME_SIZE 512
/* ripped out of gedit2 */
gchar*
egg_recent_util_escape_underlines (const gchar* text)
{
GString *str;
gint length;
const gchar *p;
const gchar *end;
g_return_val_if_fail (text != NULL, NULL);
length = strlen (text);
str = g_string_new ("");
p = text;
end = text + length;
while (p != end)
{
const gchar *next;
next = g_utf8_next_char (p);
switch (*p)
{
case '_':
g_string_append (str, "__");
break;
default:
g_string_append_len (str, p, next - p);
break;
}
p = next;
}
return g_string_free (str, FALSE);
}
GdkPixbuf *
egg_recent_util_get_icon (GtkIconTheme *theme, const gchar *uri,
const gchar *mime_type, int size)
{
#ifndef USE_STABLE_LIBGNOMEUI
gchar *icon;
GdkPixbuf *pixbuf;
icon = gnome_icon_lookup (theme, NULL, uri, NULL, NULL,
mime_type, 0, NULL);
g_return_val_if_fail (icon != NULL, NULL);
pixbuf = gtk_icon_theme_load_icon (theme, icon, size, 0, NULL);
g_free (icon);
return pixbuf;
#endif
return NULL;
}
gchar *
egg_recent_util_get_unique_id (void)
{
char hostname[EGG_RECENT_UTIL_HOSTNAME_SIZE];
time_t the_time;
guint32 rand;
int pid;
#ifndef G_OS_WIN32
gethostname (hostname, EGG_RECENT_UTIL_HOSTNAME_SIZE);
#else
{
DWORD size = EGG_RECENT_UTIL_HOSTNAME_SIZE;
GetComputerName (hostname, &size);
}
#endif
time (&the_time);
rand = g_random_int ();
pid = getpid ();
return g_strdup_printf ("%s-%d-%d-%d", hostname, (int)time, (int)rand, (int)pid);
}
|