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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
#include <config.h>
#include <libnautilus/libnautilus.h>
#include <gnome.h>
#include "hyperbola-filefmt.h"
#include <gtk/gtk.h>
#include <string.h>
#include <limits.h>
#include <parser.h>
#include <dirent.h>
#include <ctype.h>
typedef struct {
NautilusView *view_frame;
GtkWidget *clist, *ent;
gint8 notify_count;
} HyperbolaNavigationSearch;
static void
hyperbola_navigation_search_ent_changed(GtkWidget *ent, HyperbolaNavigationSearch *hns)
{
}
static void
hyperbola_navigation_search_ent_activate(GtkWidget *ent, HyperbolaNavigationSearch *hns)
{
GString *query;
FILE *fh;
char *dir;
char *ctmp, *line;
query = g_string_new(NULL);
gtk_clist_freeze(GTK_CLIST(hns->clist));
gtk_clist_clear(GTK_CLIST(hns->clist));
dir = gnome_datadir_file("gnome/help");
g_string_sprintf(query, "sgrep -l '");
line = gtk_entry_get_text(GTK_ENTRY(hns->ent));
while((ctmp = strtok(line, " \t")))
{
g_string_sprintfa(query, "%sword(\"%s\")", line?"":" and ", ctmp);
line = NULL;
}
g_string_sprintfa(query, "' %s/*/*/*.sgml", dir);
g_free(dir);
fh = popen(query->str, "r");
g_string_free(query, TRUE);
if(fh)
{
char aline[LINE_MAX];
char uri[512], *uriptr;
GHashTable *uri_hash;
uri_hash = g_hash_table_new(g_str_hash, g_str_equal);
while(fgets(aline, sizeof(aline), fh))
{
char *filename, *ctmp;
int len, rownum;
if(strncmp(aline, "---", 3) != 0) /* Skip non match-info lines */
continue;
g_strstrip(aline);
filename = strtok(aline, " \t");
if(!filename)
continue;
filename = strtok(NULL, " \t");
if(!filename)
continue;
filename = strtok(NULL, " \t");
if(!filename)
continue;
len = strlen(filename);
if(filename[len-1] == ':')
filename[len-1] = '\0';
/* XXX lame! Should use gnome_file_locate eventually to figure out all possible prefixes. */
ctmp = strstr(filename, "/help/");
if(ctmp)
{
char **pieces;
ctmp += strlen("/help/");
pieces = g_strsplit(ctmp, "/", -1);
if(!pieces || !pieces[0] || !pieces[1] || !pieces[2] || pieces[3])
ctmp = NULL;
else
{
ctmp = strrchr(pieces[2], '.');
if(ctmp && !strcmp(ctmp, ".sgml"))
*ctmp = '\0';
g_snprintf(uri, sizeof(uri), "help:%s/%s", pieces[0], pieces[2]);
}
g_strfreev(pieces);
}
if(!ctmp)
g_snprintf(uri, sizeof(uri), "file://%s", filename);
uriptr = g_hash_table_lookup(uri_hash, uri);
if(uriptr)
continue;
uriptr = uri;
rownum = gtk_clist_append(GTK_CLIST(hns->clist), &uriptr);
if(gtk_clist_get_text(GTK_CLIST(hns->clist), rownum, 0, &uriptr))
g_hash_table_insert(uri_hash, uriptr, uriptr);
}
pclose(fh);
g_hash_table_destroy(uri_hash);
}
gtk_clist_thaw(GTK_CLIST(hns->clist));
}
static void
hyperbola_navigation_search_select_row(GtkWidget *clist, gint row, gint column, GdkEvent *event, HyperbolaNavigationSearch *hns)
{
Nautilus_NavigationRequestInfo loc;
char *uri;
if(!event || event->type != GDK_2BUTTON_PRESS) /* we only care if the user has double-clicked on an item...? */
return;
if(gtk_clist_get_text(GTK_CLIST(clist), row, 0, &uri))
return;
memset(&loc, 0, sizeof(loc));
loc.requested_uri = uri;
loc.new_window_requested = FALSE;
nautilus_view_request_location_change(NAUTILUS_VIEW(hns->view_frame), &loc);
}
BonoboObject *hyperbola_navigation_search_new(void)
{
HyperbolaNavigationSearch *hns;
GtkWidget *wtmp, *vbox;
hns = g_new0(HyperbolaNavigationSearch, 1);
vbox = gtk_vbox_new(FALSE, GNOME_PAD);
hns->ent = gtk_entry_new();
gtk_signal_connect(GTK_OBJECT(hns->ent), "changed", hyperbola_navigation_search_ent_changed, hns);
gtk_signal_connect(GTK_OBJECT(hns->ent), "activate", hyperbola_navigation_search_ent_activate, hns);
gtk_container_add(GTK_CONTAINER(vbox), hns->ent);
hns->clist = gtk_clist_new(1);
gtk_clist_freeze(GTK_CLIST(hns->clist));
gtk_clist_set_selection_mode(GTK_CLIST(hns->clist), GTK_SELECTION_BROWSE);
gtk_clist_set_column_widget(GTK_CLIST(hns->clist), 0, hns->ent);
gtk_signal_connect(GTK_OBJECT(hns->clist), "select_row", hyperbola_navigation_search_select_row, hns);
wtmp = gtk_scrolled_window_new(gtk_clist_get_hadjustment(GTK_CLIST(hns->clist)),
gtk_clist_get_vadjustment(GTK_CLIST(hns->clist)));
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(wtmp), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add(GTK_CONTAINER(wtmp), hns->clist);
gtk_container_add(GTK_CONTAINER(vbox), wtmp);
gtk_clist_columns_autosize(GTK_CLIST(hns->clist));
gtk_clist_thaw(GTK_CLIST(hns->clist));
gtk_widget_show_all(vbox);
hns->view_frame = NAUTILUS_VIEW (nautilus_meta_view_new (vbox));
return BONOBO_OBJECT (hns->view_frame);
}
|