Merge lp:~noskcaj/ubuntu/trusty/yelp/3.10.2 into lp:ubuntu/trusty/yelp
- Trusty (14.04)
- 3.10.2
- Merge into trusty
Proposed by
Jackson Doak
Status: | Merged |
---|---|
Merge reported by: | Sebastien Bacher |
Merged at revision: | not available |
Proposed branch: | lp:~noskcaj/ubuntu/trusty/yelp/3.10.2 |
Merge into: | lp:ubuntu/trusty/yelp |
Diff against target: |
7240 lines (+153/-6459) 21 files modified
.pc/07_disable_package_search.patch/libyelp/yelp-view.c (+4/-4) .pc/applied-patches (+0/-1) .pc/git_signal_handler.patch/libyelp/yelp-location-entry.c (+0/-1650) .pc/git_signal_handler.patch/libyelp/yelp-view.c (+0/-2220) .pc/git_signal_handler.patch/src/yelp-window.c (+0/-1402) NEWS (+7/-0) configure (+10/-10) configure.ac (+1/-1) debian/changelog (+7/-0) debian/patches/git_signal_handler.patch (+0/-93) debian/patches/series (+0/-1) docs/libyelp/html/YelpLocationEntry.html (+2/-2) docs/libyelp/html/YelpView.html (+2/-2) docs/libyelp/html/ch01.html (+3/-3) docs/libyelp/html/ch01s02.html (+1/-1) docs/libyelp/html/index.html (+2/-2) docs/libyelp/html/libyelp.devhelp (+1/-1) docs/libyelp/html/libyelp.devhelp2 (+1/-1) docs/libyelp/version.xml (+1/-1) po/kn.po (+45/-999) po/zh_CN.po (+66/-65) |
To merge this branch: | bzr merge lp:~noskcaj/ubuntu/trusty/yelp/3.10.2 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Sebastien Bacher | Approve | ||
Review via email: mp+210061@code.launchpad.net |
Commit message
Description of the change
New upstream bugfix release
To post a comment you must log in.
- 139. By Jackson Doak
-
target trusty
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file '.pc/07_disable_package_search.patch/libyelp/yelp-view.c' | |||
2 | --- .pc/07_disable_package_search.patch/libyelp/yelp-view.c 2013-12-17 10:40:39 +0000 | |||
3 | +++ .pc/07_disable_package_search.patch/libyelp/yelp-view.c 2014-03-08 22:22:39 +0000 | |||
4 | @@ -308,12 +308,12 @@ | |||
5 | 308 | view_clear_load (YELP_VIEW (object)); | 308 | view_clear_load (YELP_VIEW (object)); |
6 | 309 | 309 | ||
7 | 310 | if (priv->vadjuster > 0) { | 310 | if (priv->vadjuster > 0) { |
9 | 311 | g_source_remove (priv->vadjuster); | 311 | g_signal_handler_disconnect (priv->vadjustment, priv->vadjuster); |
10 | 312 | priv->vadjuster = 0; | 312 | priv->vadjuster = 0; |
11 | 313 | } | 313 | } |
12 | 314 | 314 | ||
13 | 315 | if (priv->hadjuster > 0) { | 315 | if (priv->hadjuster > 0) { |
15 | 316 | g_source_remove (priv->hadjuster); | 316 | g_signal_handler_disconnect (priv->hadjustment, priv->hadjuster); |
16 | 317 | priv->hadjuster = 0; | 317 | priv->hadjuster = 0; |
17 | 318 | } | 318 | } |
18 | 319 | 319 | ||
19 | @@ -885,7 +885,7 @@ | |||
20 | 885 | YelpViewPrivate *priv = GET_PRIV (view); | 885 | YelpViewPrivate *priv = GET_PRIV (view); |
21 | 886 | priv->hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (view)); | 886 | priv->hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (view)); |
22 | 887 | if (priv->hadjuster > 0) | 887 | if (priv->hadjuster > 0) |
24 | 888 | g_source_remove (priv->hadjuster); | 888 | g_signal_handler_disconnect (priv->hadjustment, priv->hadjuster); |
25 | 889 | priv->hadjuster = 0; | 889 | priv->hadjuster = 0; |
26 | 890 | if (priv->hadjustment) | 890 | if (priv->hadjustment) |
27 | 891 | priv->hadjuster = g_signal_connect (priv->hadjustment, "value-changed", | 891 | priv->hadjuster = g_signal_connect (priv->hadjustment, "value-changed", |
28 | @@ -900,7 +900,7 @@ | |||
29 | 900 | YelpViewPrivate *priv = GET_PRIV (view); | 900 | YelpViewPrivate *priv = GET_PRIV (view); |
30 | 901 | priv->vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (view)); | 901 | priv->vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (view)); |
31 | 902 | if (priv->vadjuster > 0) | 902 | if (priv->vadjuster > 0) |
33 | 903 | g_source_remove (priv->vadjuster); | 903 | g_signal_handler_disconnect (priv->vadjustment, priv->vadjuster); |
34 | 904 | priv->vadjuster = 0; | 904 | priv->vadjuster = 0; |
35 | 905 | if (priv->vadjustment) | 905 | if (priv->vadjustment) |
36 | 906 | priv->vadjuster = g_signal_connect (priv->vadjustment, "value-changed", | 906 | priv->vadjuster = g_signal_connect (priv->vadjustment, "value-changed", |
37 | 907 | 907 | ||
38 | === modified file '.pc/applied-patches' | |||
39 | --- .pc/applied-patches 2014-02-27 13:28:05 +0000 | |||
40 | +++ .pc/applied-patches 2014-03-08 22:22:39 +0000 | |||
41 | @@ -2,4 +2,3 @@ | |||
42 | 2 | 05_menu_tooltip.patch | 2 | 05_menu_tooltip.patch |
43 | 3 | 06_make_ubuntu_docs_default.patch | 3 | 06_make_ubuntu_docs_default.patch |
44 | 4 | 07_disable_package_search.patch | 4 | 07_disable_package_search.patch |
45 | 5 | git_signal_handler.patch | ||
46 | 6 | 5 | ||
47 | === removed directory '.pc/git_signal_handler.patch' | |||
48 | === removed directory '.pc/git_signal_handler.patch/libyelp' | |||
49 | === removed file '.pc/git_signal_handler.patch/libyelp/yelp-location-entry.c' | |||
50 | --- .pc/git_signal_handler.patch/libyelp/yelp-location-entry.c 2014-02-27 13:28:05 +0000 | |||
51 | +++ .pc/git_signal_handler.patch/libyelp/yelp-location-entry.c 1970-01-01 00:00:00 +0000 | |||
52 | @@ -1,1650 +0,0 @@ | |||
53 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||
54 | 2 | /* | ||
55 | 3 | * Copyright (C) 2009 Shaun McCance <shaunm@gnome.org> | ||
56 | 4 | * | ||
57 | 5 | * This program is free software; you can redistribute it and/or | ||
58 | 6 | * modify it under the terms of the GNU General Public License as | ||
59 | 7 | * published by the Free Software Foundation; either version 2 of the | ||
60 | 8 | * License, or (at your option) any later version. | ||
61 | 9 | * | ||
62 | 10 | * This program is distributed in the hope that it will be useful, | ||
63 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
64 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
65 | 13 | * General Public License for more details. | ||
66 | 14 | * | ||
67 | 15 | * You should have received a copy of the GNU General Public | ||
68 | 16 | * License along with this program; if not, write to the | ||
69 | 17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
70 | 18 | * Boston, MA 02111-1307, USA. | ||
71 | 19 | * | ||
72 | 20 | * Author: Shaun McCance <shaunm@gnome.org> | ||
73 | 21 | */ | ||
74 | 22 | |||
75 | 23 | #ifdef HAVE_CONFIG_H | ||
76 | 24 | #include <config.h> | ||
77 | 25 | #endif | ||
78 | 26 | |||
79 | 27 | #include <gdk/gdkkeysyms.h> | ||
80 | 28 | #include <gtk/gtk.h> | ||
81 | 29 | #include <glib/gi18n.h> | ||
82 | 30 | |||
83 | 31 | #include "yelp-location-entry.h" | ||
84 | 32 | #include "yelp-marshal.h" | ||
85 | 33 | #include "yelp-settings.h" | ||
86 | 34 | |||
87 | 35 | /** | ||
88 | 36 | * SECTION:yelp-location-entry | ||
89 | 37 | * @short_description: A location entry with history and search | ||
90 | 38 | * @include: yelp.h | ||
91 | 39 | * | ||
92 | 40 | * #YelpLocationEntry is a #GtkComboBox designed to show the current location, | ||
93 | 41 | * provide a drop-down menu of previous locations, and allow the user to perform | ||
94 | 42 | * searches. | ||
95 | 43 | * | ||
96 | 44 | * The #GtkTreeModel used by a #YelpLocationEntry is expected to have at least | ||
97 | 45 | * four columns: #GtkComboBox::entry-text-column contains the displayed name | ||
98 | 46 | * of the location, #YelpLocationEntry::desc-column contains a description | ||
99 | 47 | * for each entry, #YelpLocationEntry::icon-column contains an icon name for | ||
100 | 48 | * the location, and #YelpLocationEntry::flags-column contains a bit field | ||
101 | 49 | * of #YelpLocationEntryFlags. These columns are specified when creating a | ||
102 | 50 | * #YelpLocationEntry widget with yelp_location_entry_new_with_model(). | ||
103 | 51 | * | ||
104 | 52 | * Usually, a single row in the #GtkTreeModel corresponds to a location. When | ||
105 | 53 | * a user selects a row from the drop-down menu, the icon and text for that | ||
106 | 54 | * row will be placed in the embedded text entry, and the | ||
107 | 55 | * #YelpLocationEntry:location-selected signal will be emitted. | ||
108 | 56 | * | ||
109 | 57 | * If a row has the %YELP_LOCATION_ENTRY_IS_SEARCH flag set, selecting that | ||
110 | 58 | * row will not emit the #YelpLocationEntry::location-selected signal. Instead, | ||
111 | 59 | * the #YelpLocationEntry widget will be placed into search mode, as if by a | ||
112 | 60 | * call to yelp_location_entry_start_search(). | ||
113 | 61 | * | ||
114 | 62 | * When a row has the %YELP_LOCATION_ENTRY_CAN_BOOKMARK flag set, an icon | ||
115 | 63 | * will be displayed in the secondary icon position of the embedded text | ||
116 | 64 | * entry allowing the user to bookmark the location. Clicking this icon | ||
117 | 65 | * will cause the FIXME signal to be emitted. | ||
118 | 66 | **/ | ||
119 | 67 | |||
120 | 68 | static void location_entry_constructed (GObject *object); | ||
121 | 69 | static void location_entry_dispose (GObject *object); | ||
122 | 70 | static void location_entry_finalize (GObject *object); | ||
123 | 71 | static void location_entry_get_property (GObject *object, | ||
124 | 72 | guint prop_id, | ||
125 | 73 | GValue *value, | ||
126 | 74 | GParamSpec *pspec); | ||
127 | 75 | static void location_entry_set_property (GObject *object, | ||
128 | 76 | guint prop_id, | ||
129 | 77 | const GValue *value, | ||
130 | 78 | GParamSpec *pspec); | ||
131 | 79 | |||
132 | 80 | /* Signals */ | ||
133 | 81 | static void location_entry_location_selected (YelpLocationEntry *entry); | ||
134 | 82 | static void location_entry_search_activated (YelpLocationEntry *entry); | ||
135 | 83 | static void location_entry_bookmark_clicked (YelpLocationEntry *entry); | ||
136 | 84 | |||
137 | 85 | /* Utilities */ | ||
138 | 86 | static void location_entry_start_search (YelpLocationEntry *entry, | ||
139 | 87 | gboolean clear); | ||
140 | 88 | static void location_entry_cancel_search (YelpLocationEntry *entry); | ||
141 | 89 | static void location_entry_set_entry (YelpLocationEntry *entry, | ||
142 | 90 | gboolean emit); | ||
143 | 91 | static gboolean location_entry_start_pulse (gpointer data); | ||
144 | 92 | static gboolean location_entry_pulse (gpointer data); | ||
145 | 93 | static void location_entry_set_completion (YelpLocationEntry *entry, | ||
146 | 94 | GtkTreeModel *model); | ||
147 | 95 | |||
148 | 96 | |||
149 | 97 | /* GtkTreeModel callbacks */ | ||
150 | 98 | static void history_row_changed (GtkTreeModel *model, | ||
151 | 99 | GtkTreePath *path, | ||
152 | 100 | GtkTreeIter *iter, | ||
153 | 101 | gpointer user_data); | ||
154 | 102 | /* GtkComboBox callbacks */ | ||
155 | 103 | static void combo_box_changed_cb (GtkComboBox *widget, | ||
156 | 104 | gpointer user_data); | ||
157 | 105 | static gboolean combo_box_row_separator_func (GtkTreeModel *model, | ||
158 | 106 | GtkTreeIter *iter, | ||
159 | 107 | gpointer user_data); | ||
160 | 108 | /* GtkEntry callbacks */ | ||
161 | 109 | static gboolean entry_focus_in_cb (GtkWidget *widget, | ||
162 | 110 | GdkEventFocus *event, | ||
163 | 111 | gpointer user_data); | ||
164 | 112 | static gboolean entry_focus_out_cb (GtkWidget *widget, | ||
165 | 113 | GdkEventFocus *event, | ||
166 | 114 | gpointer user_data); | ||
167 | 115 | static void entry_activate_cb (GtkEntry *text_entry, | ||
168 | 116 | gpointer user_data); | ||
169 | 117 | static void entry_icon_press_cb (GtkEntry *gtkentry, | ||
170 | 118 | GtkEntryIconPosition icon_pos, | ||
171 | 119 | GdkEvent *event, | ||
172 | 120 | YelpLocationEntry *entry); | ||
173 | 121 | static gboolean entry_key_press_cb (GtkWidget *widget, | ||
174 | 122 | GdkEventKey *event, | ||
175 | 123 | YelpLocationEntry *entry); | ||
176 | 124 | /* GtkCellLayout callbacks */ | ||
177 | 125 | static void cell_set_text_cell (GtkCellLayout *layout, | ||
178 | 126 | GtkCellRenderer *cell, | ||
179 | 127 | GtkTreeModel *model, | ||
180 | 128 | GtkTreeIter *iter, | ||
181 | 129 | YelpLocationEntry *entry); | ||
182 | 130 | static void cell_set_bookmark_icon (GtkCellLayout *layout, | ||
183 | 131 | GtkCellRenderer *cell, | ||
184 | 132 | GtkTreeModel *model, | ||
185 | 133 | GtkTreeIter *iter, | ||
186 | 134 | YelpLocationEntry *entry); | ||
187 | 135 | /* GtkEntryCompletion callbacks */ | ||
188 | 136 | static void cell_set_completion_bookmark_icon (GtkCellLayout *layout, | ||
189 | 137 | GtkCellRenderer *cell, | ||
190 | 138 | GtkTreeModel *model, | ||
191 | 139 | GtkTreeIter *iter, | ||
192 | 140 | YelpLocationEntry *entry); | ||
193 | 141 | static void cell_set_completion_text_cell (GtkCellLayout *layout, | ||
194 | 142 | GtkCellRenderer *cell, | ||
195 | 143 | GtkTreeModel *model, | ||
196 | 144 | GtkTreeIter *iter, | ||
197 | 145 | YelpLocationEntry *entry); | ||
198 | 146 | static gboolean entry_match_func (GtkEntryCompletion *completion, | ||
199 | 147 | const gchar *key, | ||
200 | 148 | GtkTreeIter *iter, | ||
201 | 149 | YelpLocationEntry *entry); | ||
202 | 150 | static gint entry_completion_sort (GtkTreeModel *model, | ||
203 | 151 | GtkTreeIter *iter1, | ||
204 | 152 | GtkTreeIter *iter2, | ||
205 | 153 | gpointer user_data); | ||
206 | 154 | static gboolean entry_match_selected (GtkEntryCompletion *completion, | ||
207 | 155 | GtkTreeModel *model, | ||
208 | 156 | GtkTreeIter *iter, | ||
209 | 157 | YelpLocationEntry *entry); | ||
210 | 158 | /* YelpView callbacks */ | ||
211 | 159 | static void view_loaded (YelpView *view, | ||
212 | 160 | YelpLocationEntry *entry); | ||
213 | 161 | static void view_uri_selected (YelpView *view, | ||
214 | 162 | GParamSpec *pspec, | ||
215 | 163 | YelpLocationEntry *entry); | ||
216 | 164 | static void view_page_title (YelpView *view, | ||
217 | 165 | GParamSpec *pspec, | ||
218 | 166 | YelpLocationEntry *entry); | ||
219 | 167 | static void view_page_desc (YelpView *view, | ||
220 | 168 | GParamSpec *pspec, | ||
221 | 169 | YelpLocationEntry *entry); | ||
222 | 170 | static void view_page_icon (YelpView *view, | ||
223 | 171 | GParamSpec *pspec, | ||
224 | 172 | YelpLocationEntry *entry); | ||
225 | 173 | /* YelpBookmarks callbacks */ | ||
226 | 174 | static void bookmarks_changed (YelpBookmarks *bookmarks, | ||
227 | 175 | const gchar *doc_uri, | ||
228 | 176 | YelpLocationEntry *entry); | ||
229 | 177 | |||
230 | 178 | |||
231 | 179 | |||
232 | 180 | typedef struct _YelpLocationEntryPrivate YelpLocationEntryPrivate; | ||
233 | 181 | struct _YelpLocationEntryPrivate | ||
234 | 182 | { | ||
235 | 183 | YelpView *view; | ||
236 | 184 | YelpBookmarks *bookmarks; | ||
237 | 185 | GtkTreeRowReference *row; | ||
238 | 186 | gchar *completion_uri; | ||
239 | 187 | |||
240 | 188 | /* do not free below */ | ||
241 | 189 | GtkWidget *text_entry; | ||
242 | 190 | GtkCellRenderer *icon_cell; | ||
243 | 191 | GtkListStore *history; | ||
244 | 192 | GtkEntryCompletion *completion; | ||
245 | 193 | |||
246 | 194 | gboolean enable_search; | ||
247 | 195 | gboolean view_uri_selected; | ||
248 | 196 | gboolean search_mode; | ||
249 | 197 | guint pulse; | ||
250 | 198 | gulong bookmarks_changed; | ||
251 | 199 | |||
252 | 200 | gboolean icon_is_clear; | ||
253 | 201 | }; | ||
254 | 202 | |||
255 | 203 | enum { | ||
256 | 204 | LOCATION_ENTRY_IS_LOADING = 1 << 0, | ||
257 | 205 | LOCATION_ENTRY_IS_SEPARATOR = 1 << 1, | ||
258 | 206 | LOCATION_ENTRY_IS_SEARCH = 1 << 2 | ||
259 | 207 | }; | ||
260 | 208 | |||
261 | 209 | enum { | ||
262 | 210 | HISTORY_COL_TITLE, | ||
263 | 211 | HISTORY_COL_DESC, | ||
264 | 212 | HISTORY_COL_ICON, | ||
265 | 213 | HISTORY_COL_URI, | ||
266 | 214 | HISTORY_COL_DOC, | ||
267 | 215 | HISTORY_COL_PAGE, | ||
268 | 216 | HISTORY_COL_FLAGS, | ||
269 | 217 | HISTORY_COL_TERMS | ||
270 | 218 | }; | ||
271 | 219 | |||
272 | 220 | enum { | ||
273 | 221 | COMPLETION_COL_TITLE, | ||
274 | 222 | COMPLETION_COL_DESC, | ||
275 | 223 | COMPLETION_COL_ICON, | ||
276 | 224 | COMPLETION_COL_PAGE, | ||
277 | 225 | COMPLETION_COL_FLAGS | ||
278 | 226 | }; | ||
279 | 227 | |||
280 | 228 | enum { | ||
281 | 229 | COMPLETION_FLAG_ACTIVATE_SEARCH = 1<<0 | ||
282 | 230 | }; | ||
283 | 231 | |||
284 | 232 | enum { | ||
285 | 233 | LOCATION_SELECTED, | ||
286 | 234 | SEARCH_ACTIVATED, | ||
287 | 235 | BOOKMARK_CLICKED, | ||
288 | 236 | LAST_SIGNAL | ||
289 | 237 | }; | ||
290 | 238 | |||
291 | 239 | enum { | ||
292 | 240 | PROP_0, | ||
293 | 241 | PROP_VIEW, | ||
294 | 242 | PROP_BOOKMARKS, | ||
295 | 243 | PROP_ENABLE_SEARCH | ||
296 | 244 | }; | ||
297 | 245 | |||
298 | 246 | static GHashTable *completions; | ||
299 | 247 | |||
300 | 248 | static guint location_entry_signals[LAST_SIGNAL] = {0,}; | ||
301 | 249 | |||
302 | 250 | #define MAX_HISTORY 8 | ||
303 | 251 | |||
304 | 252 | G_DEFINE_TYPE (YelpLocationEntry, yelp_location_entry, GTK_TYPE_COMBO_BOX) | ||
305 | 253 | #define GET_PRIV(object) (G_TYPE_INSTANCE_GET_PRIVATE((object), YELP_TYPE_LOCATION_ENTRY, YelpLocationEntryPrivate)) | ||
306 | 254 | |||
307 | 255 | static void | ||
308 | 256 | yelp_location_entry_class_init (YelpLocationEntryClass *klass) | ||
309 | 257 | { | ||
310 | 258 | GObjectClass *object_class; | ||
311 | 259 | |||
312 | 260 | klass->location_selected = location_entry_location_selected; | ||
313 | 261 | klass->search_activated = location_entry_search_activated; | ||
314 | 262 | klass->bookmark_clicked = location_entry_bookmark_clicked; | ||
315 | 263 | |||
316 | 264 | object_class = G_OBJECT_CLASS (klass); | ||
317 | 265 | |||
318 | 266 | object_class->constructed = location_entry_constructed; | ||
319 | 267 | object_class->dispose = location_entry_dispose; | ||
320 | 268 | object_class->finalize = location_entry_finalize; | ||
321 | 269 | object_class->get_property = location_entry_get_property; | ||
322 | 270 | object_class->set_property = location_entry_set_property; | ||
323 | 271 | |||
324 | 272 | /** | ||
325 | 273 | * YelpLocationEntry::location-selected | ||
326 | 274 | * @widget: The #YelpLocationEntry for which the signal was emitted. | ||
327 | 275 | * @user_data: User data set when the handler was connected. | ||
328 | 276 | * | ||
329 | 277 | * This signal will be emitted whenever a user selects a normal row from the | ||
330 | 278 | * drop-down menu. Note that if a row has the flag %YELP_LOCATION_ENTRY_IS_SEARCH, | ||
331 | 279 | * clicking the row will cause @widget to enter search mode, and this signal | ||
332 | 280 | * will not be emitted. | ||
333 | 281 | **/ | ||
334 | 282 | location_entry_signals[LOCATION_SELECTED] = | ||
335 | 283 | g_signal_new ("location-selected", | ||
336 | 284 | G_OBJECT_CLASS_TYPE (klass), | ||
337 | 285 | G_SIGNAL_RUN_LAST, | ||
338 | 286 | G_STRUCT_OFFSET (YelpLocationEntryClass, location_selected), | ||
339 | 287 | NULL, NULL, | ||
340 | 288 | g_cclosure_marshal_VOID__VOID, | ||
341 | 289 | G_TYPE_NONE, 0); | ||
342 | 290 | |||
343 | 291 | /** | ||
344 | 292 | * YelpLocationEntry::search-activated | ||
345 | 293 | * @widget: The #YelpLocationEntry for which the signal was emitted. | ||
346 | 294 | * @text: The search text. | ||
347 | 295 | * @user_data: User data set when the handler was connected. | ||
348 | 296 | * | ||
349 | 297 | * This signal will be emitted whenever the user activates a search, generally | ||
350 | 298 | * by pressing <keycap>Enter</keycap> in the embedded text entry while @widget | ||
351 | 299 | * is in search mode. | ||
352 | 300 | **/ | ||
353 | 301 | location_entry_signals[SEARCH_ACTIVATED] = | ||
354 | 302 | g_signal_new ("search-activated", | ||
355 | 303 | G_OBJECT_CLASS_TYPE (klass), | ||
356 | 304 | G_SIGNAL_RUN_LAST, | ||
357 | 305 | G_STRUCT_OFFSET (YelpLocationEntryClass, search_activated), | ||
358 | 306 | NULL, NULL, | ||
359 | 307 | g_cclosure_marshal_VOID__STRING, | ||
360 | 308 | G_TYPE_NONE, 1, | ||
361 | 309 | G_TYPE_STRING); | ||
362 | 310 | |||
363 | 311 | /** | ||
364 | 312 | * YelpLocationEntry::bookmark-clicked | ||
365 | 313 | * @widget: The #YelpLocationEntry for which the signal was emitted. | ||
366 | 314 | * @user_data: User data set when the handler was connected. | ||
367 | 315 | * | ||
368 | 316 | * This signal will be emitted whenever a user clicks the bookmark icon | ||
369 | 317 | * embedded in the location entry. | ||
370 | 318 | **/ | ||
371 | 319 | location_entry_signals[BOOKMARK_CLICKED] = | ||
372 | 320 | g_signal_new ("bookmark-clicked", | ||
373 | 321 | G_OBJECT_CLASS_TYPE (klass), | ||
374 | 322 | G_SIGNAL_RUN_LAST, | ||
375 | 323 | G_STRUCT_OFFSET (YelpLocationEntryClass, bookmark_clicked), | ||
376 | 324 | NULL, NULL, | ||
377 | 325 | g_cclosure_marshal_VOID__VOID, | ||
378 | 326 | G_TYPE_NONE, 0); | ||
379 | 327 | |||
380 | 328 | /** | ||
381 | 329 | * YelpLocationEntry:view | ||
382 | 330 | * | ||
383 | 331 | * The YelpView instance that this location entry controls. | ||
384 | 332 | **/ | ||
385 | 333 | g_object_class_install_property (object_class, | ||
386 | 334 | PROP_VIEW, | ||
387 | 335 | g_param_spec_object ("view", | ||
388 | 336 | _("View"), | ||
389 | 337 | _("A YelpView instance to control"), | ||
390 | 338 | YELP_TYPE_VIEW, | ||
391 | 339 | G_PARAM_CONSTRUCT_ONLY | | ||
392 | 340 | G_PARAM_READWRITE | | ||
393 | 341 | G_PARAM_STATIC_STRINGS)); | ||
394 | 342 | |||
395 | 343 | /** | ||
396 | 344 | * YelpLocationEntry:bookmarks | ||
397 | 345 | * | ||
398 | 346 | * An instance of an implementation of YelpBookmarks to provide | ||
399 | 347 | * bookmark information for this location entry. | ||
400 | 348 | **/ | ||
401 | 349 | g_object_class_install_property (object_class, | ||
402 | 350 | PROP_BOOKMARKS, | ||
403 | 351 | g_param_spec_object ("bookmarks", | ||
404 | 352 | _("Bookmarks"), | ||
405 | 353 | _("A YelpBookmarks implementation instance"), | ||
406 | 354 | YELP_TYPE_BOOKMARKS, | ||
407 | 355 | G_PARAM_CONSTRUCT_ONLY | | ||
408 | 356 | G_PARAM_READWRITE | | ||
409 | 357 | G_PARAM_STATIC_STRINGS)); | ||
410 | 358 | |||
411 | 359 | /** | ||
412 | 360 | * YelpLocationEntry:enable-search | ||
413 | 361 | * | ||
414 | 362 | * Whether the location entry can act as a search entry. If search is not | ||
415 | 363 | * enabled, the user will not be able to initiate a search by clicking in | ||
416 | 364 | * the embedded text entry or selecting a search row in the drop-down menu. | ||
417 | 365 | **/ | ||
418 | 366 | g_object_class_install_property (object_class, | ||
419 | 367 | PROP_ENABLE_SEARCH, | ||
420 | 368 | g_param_spec_boolean ("enable-search", | ||
421 | 369 | N_("Enable Search"), | ||
422 | 370 | N_("Whether the location entry can be used as a search field"), | ||
423 | 371 | TRUE, | ||
424 | 372 | G_PARAM_CONSTRUCT | | ||
425 | 373 | G_PARAM_READWRITE | | ||
426 | 374 | G_PARAM_STATIC_STRINGS)); | ||
427 | 375 | |||
428 | 376 | g_type_class_add_private ((GObjectClass *) klass, | ||
429 | 377 | sizeof (YelpLocationEntryPrivate)); | ||
430 | 378 | |||
431 | 379 | completions = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); | ||
432 | 380 | } | ||
433 | 381 | |||
434 | 382 | static void | ||
435 | 383 | yelp_location_entry_init (YelpLocationEntry *entry) | ||
436 | 384 | { | ||
437 | 385 | YelpLocationEntryPrivate *priv = GET_PRIV (entry); | ||
438 | 386 | |||
439 | 387 | priv->search_mode = FALSE; | ||
440 | 388 | g_object_set (entry, "entry-text-column", HISTORY_COL_TITLE, NULL); | ||
441 | 389 | } | ||
442 | 390 | |||
443 | 391 | static void | ||
444 | 392 | location_entry_constructed (GObject *object) | ||
445 | 393 | { | ||
446 | 394 | GtkCellRenderer *bookmark_cell; | ||
447 | 395 | GList *cells; | ||
448 | 396 | GtkTreeIter iter; | ||
449 | 397 | YelpLocationEntryPrivate *priv = GET_PRIV (object); | ||
450 | 398 | |||
451 | 399 | /* Set up the text entry child */ | ||
452 | 400 | priv->text_entry = gtk_bin_get_child (GTK_BIN (object)); | ||
453 | 401 | gtk_entry_set_icon_from_icon_name (GTK_ENTRY (priv->text_entry), | ||
454 | 402 | GTK_ENTRY_ICON_PRIMARY, | ||
455 | 403 | "help-browser"); | ||
456 | 404 | gtk_entry_set_icon_activatable (GTK_ENTRY (priv->text_entry), | ||
457 | 405 | GTK_ENTRY_ICON_PRIMARY, | ||
458 | 406 | FALSE); | ||
459 | 407 | gtk_entry_set_icon_activatable (GTK_ENTRY (priv->text_entry), | ||
460 | 408 | GTK_ENTRY_ICON_SECONDARY, | ||
461 | 409 | TRUE); | ||
462 | 410 | gtk_editable_set_editable (GTK_EDITABLE (priv->text_entry), | ||
463 | 411 | priv->enable_search); | ||
464 | 412 | if (!priv->enable_search) { | ||
465 | 413 | priv->search_mode = FALSE; | ||
466 | 414 | location_entry_set_entry ((YelpLocationEntry *) object, FALSE); | ||
467 | 415 | } | ||
468 | 416 | |||
469 | 417 | /* Set up the history model */ | ||
470 | 418 | priv->history = gtk_list_store_new (8, | ||
471 | 419 | G_TYPE_STRING, /* title */ | ||
472 | 420 | G_TYPE_STRING, /* desc */ | ||
473 | 421 | G_TYPE_STRING, /* icon */ | ||
474 | 422 | G_TYPE_STRING, /* uri */ | ||
475 | 423 | G_TYPE_STRING, /* doc */ | ||
476 | 424 | G_TYPE_STRING, /* page */ | ||
477 | 425 | G_TYPE_INT, /* flags */ | ||
478 | 426 | G_TYPE_STRING /* search terms */ | ||
479 | 427 | ); | ||
480 | 428 | g_signal_connect (priv->history, "row-changed", | ||
481 | 429 | G_CALLBACK (history_row_changed), | ||
482 | 430 | object); | ||
483 | 431 | g_object_set (object, "model", priv->history, NULL); | ||
484 | 432 | if (priv->enable_search) { | ||
485 | 433 | gtk_list_store_append (priv->history, &iter); | ||
486 | 434 | gtk_list_store_set (priv->history, &iter, | ||
487 | 435 | HISTORY_COL_FLAGS, LOCATION_ENTRY_IS_SEPARATOR, | ||
488 | 436 | -1); | ||
489 | 437 | gtk_list_store_append (priv->history, &iter); | ||
490 | 438 | gtk_list_store_set (priv->history, &iter, | ||
491 | 439 | HISTORY_COL_ICON, "edit-find-symbolic", | ||
492 | 440 | HISTORY_COL_TITLE, _("Search..."), | ||
493 | 441 | HISTORY_COL_FLAGS, LOCATION_ENTRY_IS_SEARCH, | ||
494 | 442 | -1); | ||
495 | 443 | } | ||
496 | 444 | |||
497 | 445 | /* Set up the history drop-down */ | ||
498 | 446 | /* Trying to get the text to line up with the text in the GtkEntry. | ||
499 | 447 | * The text cell is the zeroeth cell right now, since we haven't | ||
500 | 448 | * yet called reorder. I realize using a guesstimate pixel value | ||
501 | 449 | * won't be perfect all the time, but 4 looks niceish. | ||
502 | 450 | */ | ||
503 | 451 | cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (object)); | ||
504 | 452 | g_object_set (cells->data, "xpad", 4, NULL); | ||
505 | 453 | gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (object), | ||
506 | 454 | GTK_CELL_RENDERER (cells->data), | ||
507 | 455 | (GtkCellLayoutDataFunc) cell_set_text_cell, | ||
508 | 456 | object, NULL); | ||
509 | 457 | g_object_set (cells->data, "ellipsize", PANGO_ELLIPSIZE_END, NULL); | ||
510 | 458 | g_list_free (cells); | ||
511 | 459 | |||
512 | 460 | priv->icon_cell = gtk_cell_renderer_pixbuf_new (); | ||
513 | 461 | gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (object), priv->icon_cell, FALSE); | ||
514 | 462 | g_object_set (priv->icon_cell, "yalign", 0.2, NULL); | ||
515 | 463 | gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (object), | ||
516 | 464 | priv->icon_cell, | ||
517 | 465 | "icon-name", | ||
518 | 466 | HISTORY_COL_ICON, | ||
519 | 467 | NULL); | ||
520 | 468 | gtk_cell_layout_reorder (GTK_CELL_LAYOUT (object), priv->icon_cell, 0); | ||
521 | 469 | |||
522 | 470 | if (priv->bookmarks) { | ||
523 | 471 | bookmark_cell = gtk_cell_renderer_pixbuf_new (); | ||
524 | 472 | gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (object), bookmark_cell, FALSE); | ||
525 | 473 | gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (object), | ||
526 | 474 | bookmark_cell, | ||
527 | 475 | (GtkCellLayoutDataFunc) cell_set_bookmark_icon, | ||
528 | 476 | object, NULL); | ||
529 | 477 | } | ||
530 | 478 | gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (object), | ||
531 | 479 | (GtkTreeViewRowSeparatorFunc) | ||
532 | 480 | combo_box_row_separator_func, | ||
533 | 481 | object, NULL); | ||
534 | 482 | /* Without this, you get a warning about the popup widget | ||
535 | 483 | * being NULL the firt time you click the arrow. | ||
536 | 484 | */ | ||
537 | 485 | gtk_widget_show_all (GTK_WIDGET (object)); | ||
538 | 486 | |||
539 | 487 | /* Connect signals */ | ||
540 | 488 | g_signal_connect (object, "changed", | ||
541 | 489 | G_CALLBACK (combo_box_changed_cb), NULL); | ||
542 | 490 | |||
543 | 491 | g_signal_connect (priv->text_entry, "focus-in-event", | ||
544 | 492 | G_CALLBACK (entry_focus_in_cb), object); | ||
545 | 493 | g_signal_connect (priv->text_entry, "focus-out-event", | ||
546 | 494 | G_CALLBACK (entry_focus_out_cb), object); | ||
547 | 495 | g_signal_connect (priv->text_entry, "icon-press", | ||
548 | 496 | G_CALLBACK (entry_icon_press_cb), object); | ||
549 | 497 | g_signal_connect (priv->text_entry, "key-press-event", | ||
550 | 498 | G_CALLBACK (entry_key_press_cb), object); | ||
551 | 499 | g_signal_connect (priv->text_entry, "activate", | ||
552 | 500 | G_CALLBACK (entry_activate_cb), object); | ||
553 | 501 | |||
554 | 502 | if (priv->bookmarks) | ||
555 | 503 | priv->bookmarks_changed = g_signal_connect (priv->bookmarks, | ||
556 | 504 | "bookmarks-changed", | ||
557 | 505 | G_CALLBACK (bookmarks_changed), | ||
558 | 506 | object); | ||
559 | 507 | |||
560 | 508 | g_signal_connect (priv->view, "loaded", G_CALLBACK (view_loaded), object); | ||
561 | 509 | g_signal_connect (priv->view, "notify::yelp-uri", G_CALLBACK (view_uri_selected), object); | ||
562 | 510 | g_signal_connect (priv->view, "notify::page-title", G_CALLBACK (view_page_title), object); | ||
563 | 511 | g_signal_connect (priv->view, "notify::page-desc", G_CALLBACK (view_page_desc), object); | ||
564 | 512 | g_signal_connect (priv->view, "notify::page-icon", G_CALLBACK (view_page_icon), object); | ||
565 | 513 | } | ||
566 | 514 | |||
567 | 515 | static void | ||
568 | 516 | location_entry_dispose (GObject *object) | ||
569 | 517 | { | ||
570 | 518 | YelpLocationEntryPrivate *priv = GET_PRIV (object); | ||
571 | 519 | |||
572 | 520 | if (priv->view) { | ||
573 | 521 | g_object_unref (priv->view); | ||
574 | 522 | priv->view = NULL; | ||
575 | 523 | } | ||
576 | 524 | |||
577 | 525 | if (priv->bookmarks) { | ||
578 | 526 | g_object_unref (priv->bookmarks); | ||
579 | 527 | priv->bookmarks = NULL; | ||
580 | 528 | } | ||
581 | 529 | |||
582 | 530 | if (priv->bookmarks_changed) { | ||
583 | 531 | g_source_remove (priv->bookmarks_changed); | ||
584 | 532 | priv->bookmarks_changed = 0; | ||
585 | 533 | } | ||
586 | 534 | |||
587 | 535 | if (priv->row) { | ||
588 | 536 | gtk_tree_row_reference_free (priv->row); | ||
589 | 537 | priv->row = NULL; | ||
590 | 538 | } | ||
591 | 539 | |||
592 | 540 | if (priv->pulse > 0) { | ||
593 | 541 | g_source_remove (priv->pulse); | ||
594 | 542 | priv->pulse = 0; | ||
595 | 543 | } | ||
596 | 544 | |||
597 | 545 | G_OBJECT_CLASS (yelp_location_entry_parent_class)->dispose (object); | ||
598 | 546 | } | ||
599 | 547 | |||
600 | 548 | static void | ||
601 | 549 | location_entry_finalize (GObject *object) | ||
602 | 550 | { | ||
603 | 551 | YelpLocationEntryPrivate *priv = GET_PRIV (object); | ||
604 | 552 | |||
605 | 553 | g_free (priv->completion_uri); | ||
606 | 554 | |||
607 | 555 | G_OBJECT_CLASS (yelp_location_entry_parent_class)->finalize (object); | ||
608 | 556 | } | ||
609 | 557 | |||
610 | 558 | static void | ||
611 | 559 | location_entry_get_property (GObject *object, | ||
612 | 560 | guint prop_id, | ||
613 | 561 | GValue *value, | ||
614 | 562 | GParamSpec *pspec) | ||
615 | 563 | { | ||
616 | 564 | YelpLocationEntryPrivate *priv = GET_PRIV (object); | ||
617 | 565 | |||
618 | 566 | switch (prop_id) { | ||
619 | 567 | case PROP_VIEW: | ||
620 | 568 | g_value_set_object (value, priv->view); | ||
621 | 569 | break; | ||
622 | 570 | case PROP_BOOKMARKS: | ||
623 | 571 | g_value_set_object (value, priv->bookmarks); | ||
624 | 572 | break; | ||
625 | 573 | case PROP_ENABLE_SEARCH: | ||
626 | 574 | g_value_set_boolean (value, priv->enable_search); | ||
627 | 575 | break; | ||
628 | 576 | default: | ||
629 | 577 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | ||
630 | 578 | break; | ||
631 | 579 | } | ||
632 | 580 | } | ||
633 | 581 | |||
634 | 582 | static void | ||
635 | 583 | location_entry_set_property (GObject *object, | ||
636 | 584 | guint prop_id, | ||
637 | 585 | const GValue *value, | ||
638 | 586 | GParamSpec *pspec) | ||
639 | 587 | { | ||
640 | 588 | YelpLocationEntryPrivate *priv = GET_PRIV (object); | ||
641 | 589 | |||
642 | 590 | switch (prop_id) { | ||
643 | 591 | case PROP_VIEW: | ||
644 | 592 | priv->view = g_value_dup_object (value); | ||
645 | 593 | break; | ||
646 | 594 | case PROP_BOOKMARKS: | ||
647 | 595 | priv->bookmarks = g_value_dup_object (value); | ||
648 | 596 | break; | ||
649 | 597 | case PROP_ENABLE_SEARCH: | ||
650 | 598 | priv->enable_search = g_value_get_boolean (value); | ||
651 | 599 | break; | ||
652 | 600 | default: | ||
653 | 601 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | ||
654 | 602 | break; | ||
655 | 603 | } | ||
656 | 604 | } | ||
657 | 605 | |||
658 | 606 | static void | ||
659 | 607 | location_entry_location_selected (YelpLocationEntry *entry) | ||
660 | 608 | { | ||
661 | 609 | GtkTreeIter iter; | ||
662 | 610 | YelpLocationEntryPrivate *priv = GET_PRIV (entry); | ||
663 | 611 | |||
664 | 612 | if (priv->view_uri_selected) | ||
665 | 613 | return; | ||
666 | 614 | |||
667 | 615 | if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (entry), &iter)) { | ||
668 | 616 | gchar *uri; | ||
669 | 617 | gtk_tree_model_get (GTK_TREE_MODEL (priv->history), &iter, | ||
670 | 618 | HISTORY_COL_URI, &uri, | ||
671 | 619 | -1); | ||
672 | 620 | yelp_view_load (priv->view, uri); | ||
673 | 621 | g_free (uri); | ||
674 | 622 | } | ||
675 | 623 | } | ||
676 | 624 | |||
677 | 625 | static void | ||
678 | 626 | location_entry_search_activated (YelpLocationEntry *entry) | ||
679 | 627 | { | ||
680 | 628 | YelpUri *base, *uri; | ||
681 | 629 | YelpLocationEntryPrivate *priv = GET_PRIV (entry); | ||
682 | 630 | |||
683 | 631 | g_object_get (priv->view, "yelp-uri", &base, NULL); | ||
684 | 632 | if (base == NULL) | ||
685 | 633 | return; | ||
686 | 634 | uri = yelp_uri_new_search (base, | ||
687 | 635 | gtk_entry_get_text (GTK_ENTRY (priv->text_entry))); | ||
688 | 636 | g_object_unref (base); | ||
689 | 637 | yelp_view_load_uri (priv->view, uri); | ||
690 | 638 | gtk_widget_grab_focus (GTK_WIDGET (priv->view)); | ||
691 | 639 | } | ||
692 | 640 | |||
693 | 641 | static void | ||
694 | 642 | location_entry_bookmark_clicked (YelpLocationEntry *entry) | ||
695 | 643 | { | ||
696 | 644 | YelpUri *uri; | ||
697 | 645 | gchar *doc_uri, *page_id; | ||
698 | 646 | YelpLocationEntryPrivate *priv = GET_PRIV (entry); | ||
699 | 647 | |||
700 | 648 | g_object_get (priv->view, | ||
701 | 649 | "yelp-uri", &uri, | ||
702 | 650 | "page-id", &page_id, | ||
703 | 651 | NULL); | ||
704 | 652 | doc_uri = yelp_uri_get_document_uri (uri); | ||
705 | 653 | if (priv->bookmarks && doc_uri && page_id) { | ||
706 | 654 | if (!yelp_bookmarks_is_bookmarked (priv->bookmarks, doc_uri, page_id)) { | ||
707 | 655 | gchar *icon, *title; | ||
708 | 656 | g_object_get (priv->view, | ||
709 | 657 | "page-icon", &icon, | ||
710 | 658 | "page-title", &title, | ||
711 | 659 | NULL); | ||
712 | 660 | yelp_bookmarks_add_bookmark (priv->bookmarks, doc_uri, page_id, icon, title); | ||
713 | 661 | g_free (icon); | ||
714 | 662 | g_free (title); | ||
715 | 663 | } | ||
716 | 664 | else { | ||
717 | 665 | yelp_bookmarks_remove_bookmark (priv->bookmarks, doc_uri, page_id); | ||
718 | 666 | } | ||
719 | 667 | } | ||
720 | 668 | g_free (doc_uri); | ||
721 | 669 | g_free (page_id); | ||
722 | 670 | g_object_unref (uri); | ||
723 | 671 | } | ||
724 | 672 | |||
725 | 673 | static void | ||
726 | 674 | location_entry_start_search (YelpLocationEntry *entry, | ||
727 | 675 | gboolean clear) | ||
728 | 676 | { | ||
729 | 677 | YelpLocationEntryPrivate *priv = GET_PRIV (entry); | ||
730 | 678 | |||
731 | 679 | if (!priv->enable_search) | ||
732 | 680 | return; | ||
733 | 681 | if (clear && !priv->search_mode) { | ||
734 | 682 | const gchar *icon = gtk_entry_get_icon_name (GTK_ENTRY (priv->text_entry), | ||
735 | 683 | GTK_ENTRY_ICON_PRIMARY); | ||
736 | 684 | if (!g_str_equal (icon, "folder-saved-search")) | ||
737 | 685 | gtk_entry_set_text (GTK_ENTRY (priv->text_entry), ""); | ||
738 | 686 | } | ||
739 | 687 | priv->search_mode = TRUE; | ||
740 | 688 | location_entry_set_entry (entry, FALSE); | ||
741 | 689 | gtk_widget_grab_focus (priv->text_entry); | ||
742 | 690 | } | ||
743 | 691 | |||
744 | 692 | static void | ||
745 | 693 | location_entry_cancel_search (YelpLocationEntry *entry) | ||
746 | 694 | { | ||
747 | 695 | gboolean ret; | ||
748 | 696 | YelpLocationEntryPrivate *priv = GET_PRIV (entry); | ||
749 | 697 | GdkEventFocus *event = g_new0 (GdkEventFocus, 1); | ||
750 | 698 | priv->search_mode = FALSE; | ||
751 | 699 | location_entry_set_entry (entry, FALSE); | ||
752 | 700 | event->type = GDK_FOCUS_CHANGE; | ||
753 | 701 | event->window = gtk_widget_get_window (GTK_WIDGET (entry)); | ||
754 | 702 | event->send_event = FALSE; | ||
755 | 703 | event->in = FALSE; | ||
756 | 704 | g_signal_emit_by_name (entry, "focus-out-event", event, &ret); | ||
757 | 705 | g_free (event); | ||
758 | 706 | /* Hack: This makes the popup disappear when you hit Esc. */ | ||
759 | 707 | if (priv->completion) { | ||
760 | 708 | g_object_ref (priv->completion); | ||
761 | 709 | gtk_entry_set_completion (GTK_ENTRY (priv->text_entry), NULL); | ||
762 | 710 | gtk_entry_set_completion (GTK_ENTRY (priv->text_entry), | ||
763 | 711 | priv->completion); | ||
764 | 712 | g_object_unref (priv->completion); | ||
765 | 713 | } | ||
766 | 714 | gtk_editable_select_region (GTK_EDITABLE (priv->text_entry), 0, 0); | ||
767 | 715 | } | ||
768 | 716 | |||
769 | 717 | static void | ||
770 | 718 | location_entry_set_completion (YelpLocationEntry *entry, | ||
771 | 719 | GtkTreeModel *model) | ||
772 | 720 | { | ||
773 | 721 | YelpLocationEntryPrivate *priv = GET_PRIV (entry); | ||
774 | 722 | GList *cells; | ||
775 | 723 | GtkCellRenderer *icon_cell, *bookmark_cell; | ||
776 | 724 | |||
777 | 725 | priv->completion = gtk_entry_completion_new (); | ||
778 | 726 | gtk_entry_completion_set_minimum_key_length (priv->completion, 3); | ||
779 | 727 | gtk_entry_completion_set_model (priv->completion, model); | ||
780 | 728 | gtk_entry_completion_set_text_column (priv->completion, COMPLETION_COL_TITLE); | ||
781 | 729 | gtk_entry_completion_set_match_func (priv->completion, | ||
782 | 730 | (GtkEntryCompletionMatchFunc) entry_match_func, | ||
783 | 731 | entry, NULL); | ||
784 | 732 | g_signal_connect (priv->completion, "match-selected", | ||
785 | 733 | G_CALLBACK (entry_match_selected), entry); | ||
786 | 734 | |||
787 | 735 | cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (priv->completion)); | ||
788 | 736 | g_object_set (cells->data, "xpad", 4, NULL); | ||
789 | 737 | gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (priv->completion), | ||
790 | 738 | GTK_CELL_RENDERER (cells->data), | ||
791 | 739 | (GtkCellLayoutDataFunc) cell_set_completion_text_cell, | ||
792 | 740 | entry, NULL); | ||
793 | 741 | g_object_set (cells->data, "ellipsize", PANGO_ELLIPSIZE_END, NULL); | ||
794 | 742 | g_list_free (cells); | ||
795 | 743 | |||
796 | 744 | icon_cell = gtk_cell_renderer_pixbuf_new (); | ||
797 | 745 | g_object_set (priv->icon_cell, "yalign", 0.2, NULL); | ||
798 | 746 | gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->completion), icon_cell, FALSE); | ||
799 | 747 | gtk_cell_layout_reorder (GTK_CELL_LAYOUT (priv->completion), icon_cell, 0); | ||
800 | 748 | gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (priv->completion), | ||
801 | 749 | icon_cell, | ||
802 | 750 | "icon-name", | ||
803 | 751 | COMPLETION_COL_ICON, | ||
804 | 752 | NULL); | ||
805 | 753 | if (priv->bookmarks) { | ||
806 | 754 | bookmark_cell = gtk_cell_renderer_pixbuf_new (); | ||
807 | 755 | gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (priv->completion), bookmark_cell, FALSE); | ||
808 | 756 | gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (priv->completion), | ||
809 | 757 | bookmark_cell, | ||
810 | 758 | (GtkCellLayoutDataFunc) cell_set_completion_bookmark_icon, | ||
811 | 759 | entry, NULL); | ||
812 | 760 | } | ||
813 | 761 | gtk_entry_set_completion (GTK_ENTRY (priv->text_entry), | ||
814 | 762 | priv->completion); | ||
815 | 763 | } | ||
816 | 764 | |||
817 | 765 | static void | ||
818 | 766 | location_entry_set_entry (YelpLocationEntry *entry, gboolean emit) | ||
819 | 767 | { | ||
820 | 768 | YelpLocationEntryPrivate *priv = GET_PRIV (entry); | ||
821 | 769 | GtkTreeModel *model = gtk_combo_box_get_model (GTK_COMBO_BOX (entry)); | ||
822 | 770 | GtkTreePath *path = NULL; | ||
823 | 771 | GtkTreeIter iter; | ||
824 | 772 | gchar *icon_name; | ||
825 | 773 | |||
826 | 774 | if (priv->search_mode) { | ||
827 | 775 | gtk_entry_set_icon_from_icon_name (GTK_ENTRY (priv->text_entry), | ||
828 | 776 | GTK_ENTRY_ICON_PRIMARY, | ||
829 | 777 | "edit-find-symbolic"); | ||
830 | 778 | gtk_entry_set_icon_from_icon_name (GTK_ENTRY (priv->text_entry), | ||
831 | 779 | GTK_ENTRY_ICON_SECONDARY, | ||
832 | 780 | "edit-clear-symbolic"); | ||
833 | 781 | gtk_entry_set_icon_tooltip_text (GTK_ENTRY (priv->text_entry), | ||
834 | 782 | GTK_ENTRY_ICON_SECONDARY, | ||
835 | 783 | _("Clear the search text")); | ||
836 | 784 | priv->icon_is_clear = TRUE; | ||
837 | 785 | return; | ||
838 | 786 | } | ||
839 | 787 | else { | ||
840 | 788 | priv->icon_is_clear = FALSE; | ||
841 | 789 | } | ||
842 | 790 | |||
843 | 791 | |||
844 | 792 | if (priv->row) | ||
845 | 793 | path = gtk_tree_row_reference_get_path (priv->row); | ||
846 | 794 | |||
847 | 795 | if (path) { | ||
848 | 796 | gchar *text, *doc_uri, *page_id; | ||
849 | 797 | gint flags; | ||
850 | 798 | gtk_tree_model_get_iter (model, &iter, path); | ||
851 | 799 | gtk_tree_model_get (model, &iter, | ||
852 | 800 | HISTORY_COL_TITLE, &text, | ||
853 | 801 | HISTORY_COL_ICON, &icon_name, | ||
854 | 802 | HISTORY_COL_FLAGS, &flags, | ||
855 | 803 | HISTORY_COL_DOC, &doc_uri, | ||
856 | 804 | HISTORY_COL_PAGE, &page_id, | ||
857 | 805 | -1); | ||
858 | 806 | if (flags & LOCATION_ENTRY_IS_LOADING) { | ||
859 | 807 | /* Would be nice to have a "loading" icon. I was using image-loading, | ||
860 | 808 | * but it look out of place with symbolic page icons. Plus, using | ||
861 | 809 | * image-loading-symbolic shows a broken image, because GtkEntry | ||
862 | 810 | * doesn't correctly use symbolic icons as of GNOME 3.0. | ||
863 | 811 | */ | ||
864 | 812 | gtk_entry_set_icon_from_icon_name (GTK_ENTRY (priv->text_entry), | ||
865 | 813 | GTK_ENTRY_ICON_PRIMARY, | ||
866 | 814 | "yelp-page-symbolic"); | ||
867 | 815 | if (priv->pulse == 0) | ||
868 | 816 | priv->pulse = g_timeout_add (500, location_entry_start_pulse, entry); | ||
869 | 817 | } | ||
870 | 818 | else { | ||
871 | 819 | gtk_entry_set_icon_from_icon_name (GTK_ENTRY (priv->text_entry), | ||
872 | 820 | GTK_ENTRY_ICON_PRIMARY, | ||
873 | 821 | icon_name); | ||
874 | 822 | } | ||
875 | 823 | if (priv->bookmarks && doc_uri && page_id) { | ||
876 | 824 | GdkPixbuf *pixbuf; | ||
877 | 825 | if (!yelp_bookmarks_is_bookmarked (priv->bookmarks, doc_uri, page_id)) { | ||
878 | 826 | gtk_entry_set_icon_from_icon_name (GTK_ENTRY (priv->text_entry), | ||
879 | 827 | GTK_ENTRY_ICON_SECONDARY, | ||
880 | 828 | "yelp-bookmark-add-symbolic"); | ||
881 | 829 | gtk_entry_set_icon_tooltip_text (GTK_ENTRY (priv->text_entry), | ||
882 | 830 | GTK_ENTRY_ICON_SECONDARY, | ||
883 | 831 | _("Bookmark this page")); | ||
884 | 832 | } | ||
885 | 833 | else { | ||
886 | 834 | gtk_entry_set_icon_from_icon_name (GTK_ENTRY (priv->text_entry), | ||
887 | 835 | GTK_ENTRY_ICON_SECONDARY, | ||
888 | 836 | "yelp-bookmark-remove-symbolic"); | ||
889 | 837 | gtk_entry_set_icon_tooltip_text (GTK_ENTRY (priv->text_entry), | ||
890 | 838 | GTK_ENTRY_ICON_SECONDARY, | ||
891 | 839 | _("Remove bookmark")); | ||
892 | 840 | } | ||
893 | 841 | } | ||
894 | 842 | else { | ||
895 | 843 | gtk_entry_set_icon_from_icon_name (GTK_ENTRY (priv->text_entry), | ||
896 | 844 | GTK_ENTRY_ICON_SECONDARY, | ||
897 | 845 | NULL); | ||
898 | 846 | } | ||
899 | 847 | g_free (doc_uri); | ||
900 | 848 | g_free (page_id); | ||
901 | 849 | gtk_entry_set_text (GTK_ENTRY (priv->text_entry), text); | ||
902 | 850 | if (emit) | ||
903 | 851 | g_signal_emit (entry, location_entry_signals[LOCATION_SELECTED], 0); | ||
904 | 852 | g_free (text); | ||
905 | 853 | gtk_tree_path_free (path); | ||
906 | 854 | } | ||
907 | 855 | else { | ||
908 | 856 | gtk_entry_set_icon_from_icon_name (GTK_ENTRY (priv->text_entry), | ||
909 | 857 | GTK_ENTRY_ICON_PRIMARY, | ||
910 | 858 | "help-browser"); | ||
911 | 859 | gtk_entry_set_icon_from_icon_name (GTK_ENTRY (priv->text_entry), | ||
912 | 860 | GTK_ENTRY_ICON_SECONDARY, | ||
913 | 861 | NULL); | ||
914 | 862 | } | ||
915 | 863 | } | ||
916 | 864 | |||
917 | 865 | static gboolean | ||
918 | 866 | location_entry_start_pulse (gpointer data) | ||
919 | 867 | { | ||
920 | 868 | YelpLocationEntryPrivate *priv = GET_PRIV (data); | ||
921 | 869 | priv->pulse = g_timeout_add (80, location_entry_pulse, data); | ||
922 | 870 | return FALSE; | ||
923 | 871 | } | ||
924 | 872 | |||
925 | 873 | static gboolean | ||
926 | 874 | location_entry_pulse (gpointer data) | ||
927 | 875 | { | ||
928 | 876 | YelpLocationEntryPrivate *priv = GET_PRIV (data); | ||
929 | 877 | GtkTreeModel *model; | ||
930 | 878 | GtkTreePath *path; | ||
931 | 879 | GtkTreeIter iter; | ||
932 | 880 | gint flags; | ||
933 | 881 | |||
934 | 882 | model = gtk_tree_row_reference_get_model (priv->row); | ||
935 | 883 | path = gtk_tree_row_reference_get_path (priv->row); | ||
936 | 884 | if (path) { | ||
937 | 885 | gtk_tree_model_get_iter (model, &iter, path); | ||
938 | 886 | gtk_tree_model_get (model, &iter, | ||
939 | 887 | HISTORY_COL_FLAGS, &flags, | ||
940 | 888 | -1); | ||
941 | 889 | gtk_tree_path_free (path); | ||
942 | 890 | } | ||
943 | 891 | |||
944 | 892 | if (flags & LOCATION_ENTRY_IS_LOADING && !priv->search_mode) { | ||
945 | 893 | gtk_entry_progress_pulse (GTK_ENTRY (priv->text_entry)); | ||
946 | 894 | } | ||
947 | 895 | else { | ||
948 | 896 | gtk_entry_set_progress_fraction (GTK_ENTRY (priv->text_entry), 0.0); | ||
949 | 897 | priv->pulse = 0; | ||
950 | 898 | } | ||
951 | 899 | |||
952 | 900 | return flags & LOCATION_ENTRY_IS_LOADING; | ||
953 | 901 | } | ||
954 | 902 | |||
955 | 903 | static void | ||
956 | 904 | combo_box_changed_cb (GtkComboBox *widget, | ||
957 | 905 | gpointer user_data) | ||
958 | 906 | { | ||
959 | 907 | YelpLocationEntryPrivate *priv = GET_PRIV (widget); | ||
960 | 908 | GtkTreeIter iter; | ||
961 | 909 | GtkTreeModel *model; | ||
962 | 910 | |||
963 | 911 | model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget)); | ||
964 | 912 | |||
965 | 913 | if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter)) { | ||
966 | 914 | gint flags; | ||
967 | 915 | gtk_tree_model_get (model, &iter, | ||
968 | 916 | HISTORY_COL_FLAGS, &flags, | ||
969 | 917 | -1); | ||
970 | 918 | if (flags & LOCATION_ENTRY_IS_SEARCH) { | ||
971 | 919 | location_entry_start_search ((YelpLocationEntry *) widget, TRUE); | ||
972 | 920 | } | ||
973 | 921 | else { | ||
974 | 922 | GtkTreePath *cur, *path; | ||
975 | 923 | path = gtk_tree_model_get_path (model, &iter); | ||
976 | 924 | if (priv->row) { | ||
977 | 925 | cur = gtk_tree_row_reference_get_path (priv->row); | ||
978 | 926 | if (gtk_tree_path_compare (cur, path) == 0) { | ||
979 | 927 | gtk_tree_path_free (cur); | ||
980 | 928 | gtk_tree_path_free (path); | ||
981 | 929 | return; | ||
982 | 930 | } | ||
983 | 931 | gtk_tree_path_free (cur); | ||
984 | 932 | gtk_tree_row_reference_free (priv->row); | ||
985 | 933 | } | ||
986 | 934 | priv->row = gtk_tree_row_reference_new (model, path); | ||
987 | 935 | gtk_tree_path_free (path); | ||
988 | 936 | priv->search_mode = FALSE; | ||
989 | 937 | location_entry_set_entry ((YelpLocationEntry *) widget, TRUE); | ||
990 | 938 | } | ||
991 | 939 | } | ||
992 | 940 | } | ||
993 | 941 | |||
994 | 942 | static gboolean | ||
995 | 943 | combo_box_row_separator_func (GtkTreeModel *model, | ||
996 | 944 | GtkTreeIter *iter, | ||
997 | 945 | gpointer user_data) | ||
998 | 946 | { | ||
999 | 947 | YelpLocationEntryPrivate *priv = GET_PRIV (user_data); | ||
1000 | 948 | gint flags; | ||
1001 | 949 | gtk_tree_model_get (model, iter, | ||
1002 | 950 | HISTORY_COL_FLAGS, &flags, | ||
1003 | 951 | -1); | ||
1004 | 952 | return (flags & LOCATION_ENTRY_IS_SEPARATOR); | ||
1005 | 953 | } | ||
1006 | 954 | |||
1007 | 955 | static void | ||
1008 | 956 | history_row_changed (GtkTreeModel *model, | ||
1009 | 957 | GtkTreePath *path, | ||
1010 | 958 | GtkTreeIter *iter, | ||
1011 | 959 | gpointer user_data) | ||
1012 | 960 | { | ||
1013 | 961 | /* FIXME: Should we bother checking path/iter against priv->row? | ||
1014 | 962 | It doesn't really make a difference, since set_entry is pretty much | ||
1015 | 963 | safe to call whenever. Does it make a performance impact? | ||
1016 | 964 | */ | ||
1017 | 965 | location_entry_set_entry (YELP_LOCATION_ENTRY (user_data), FALSE); | ||
1018 | 966 | } | ||
1019 | 967 | |||
1020 | 968 | static gboolean | ||
1021 | 969 | entry_focus_in_cb (GtkWidget *widget, | ||
1022 | 970 | GdkEventFocus *event, | ||
1023 | 971 | gpointer user_data) | ||
1024 | 972 | { | ||
1025 | 973 | GtkEntry *text_entry = GTK_ENTRY (widget); | ||
1026 | 974 | YelpLocationEntryPrivate *priv = GET_PRIV (user_data); | ||
1027 | 975 | |||
1028 | 976 | if (priv->enable_search && !priv->search_mode) | ||
1029 | 977 | location_entry_start_search ((YelpLocationEntry *) user_data, TRUE); | ||
1030 | 978 | |||
1031 | 979 | return FALSE; | ||
1032 | 980 | } | ||
1033 | 981 | |||
1034 | 982 | static gboolean | ||
1035 | 983 | entry_focus_out_cb (GtkWidget *widget, | ||
1036 | 984 | GdkEventFocus *event, | ||
1037 | 985 | gpointer user_data) | ||
1038 | 986 | { | ||
1039 | 987 | YelpLocationEntryPrivate *priv = GET_PRIV (user_data); | ||
1040 | 988 | |||
1041 | 989 | if (gtk_entry_get_text_length (GTK_ENTRY (widget)) == 0) { | ||
1042 | 990 | priv->search_mode = FALSE; | ||
1043 | 991 | location_entry_set_entry ((YelpLocationEntry *) user_data, FALSE); | ||
1044 | 992 | } | ||
1045 | 993 | |||
1046 | 994 | return FALSE; | ||
1047 | 995 | } | ||
1048 | 996 | |||
1049 | 997 | static void | ||
1050 | 998 | entry_activate_cb (GtkEntry *text_entry, | ||
1051 | 999 | gpointer user_data) | ||
1052 | 1000 | { | ||
1053 | 1001 | YelpLocationEntryPrivate *priv = GET_PRIV (user_data); | ||
1054 | 1002 | gchar *text = g_strdup (gtk_entry_get_text (text_entry)); | ||
1055 | 1003 | |||
1056 | 1004 | if (!priv->enable_search) | ||
1057 | 1005 | return; | ||
1058 | 1006 | |||
1059 | 1007 | if (!priv->search_mode || text == NULL || strlen(text) == 0) | ||
1060 | 1008 | return; | ||
1061 | 1009 | |||
1062 | 1010 | g_signal_emit (user_data, location_entry_signals[SEARCH_ACTIVATED], 0, text); | ||
1063 | 1011 | |||
1064 | 1012 | g_free (text); | ||
1065 | 1013 | } | ||
1066 | 1014 | |||
1067 | 1015 | static void | ||
1068 | 1016 | entry_icon_press_cb (GtkEntry *gtkentry, | ||
1069 | 1017 | GtkEntryIconPosition icon_pos, | ||
1070 | 1018 | GdkEvent *event, | ||
1071 | 1019 | YelpLocationEntry *entry) | ||
1072 | 1020 | { | ||
1073 | 1021 | YelpLocationEntryPrivate *priv = GET_PRIV (entry); | ||
1074 | 1022 | |||
1075 | 1023 | if (icon_pos == GTK_ENTRY_ICON_SECONDARY) { | ||
1076 | 1024 | if (priv->icon_is_clear) | ||
1077 | 1025 | location_entry_cancel_search (entry); | ||
1078 | 1026 | else | ||
1079 | 1027 | g_signal_emit (entry, location_entry_signals[BOOKMARK_CLICKED], 0); | ||
1080 | 1028 | } | ||
1081 | 1029 | } | ||
1082 | 1030 | |||
1083 | 1031 | static gboolean | ||
1084 | 1032 | entry_key_press_cb (GtkWidget *widget, | ||
1085 | 1033 | GdkEventKey *event, | ||
1086 | 1034 | YelpLocationEntry *entry) | ||
1087 | 1035 | { | ||
1088 | 1036 | YelpLocationEntryPrivate *priv = GET_PRIV (entry); | ||
1089 | 1037 | if (event->keyval == GDK_KEY_Escape) { | ||
1090 | 1038 | location_entry_cancel_search (entry); | ||
1091 | 1039 | return TRUE; | ||
1092 | 1040 | } | ||
1093 | 1041 | else if (!priv->search_mode) { | ||
1094 | 1042 | location_entry_start_search (entry, FALSE); | ||
1095 | 1043 | } | ||
1096 | 1044 | |||
1097 | 1045 | return FALSE; | ||
1098 | 1046 | } | ||
1099 | 1047 | |||
1100 | 1048 | static void | ||
1101 | 1049 | cell_set_text_cell (GtkCellLayout *layout, | ||
1102 | 1050 | GtkCellRenderer *cell, | ||
1103 | 1051 | GtkTreeModel *model, | ||
1104 | 1052 | GtkTreeIter *iter, | ||
1105 | 1053 | YelpLocationEntry *entry) | ||
1106 | 1054 | { | ||
1107 | 1055 | gchar *title, *desc, *color, *text; | ||
1108 | 1056 | YelpLocationEntryPrivate *priv = GET_PRIV (entry); | ||
1109 | 1057 | |||
1110 | 1058 | gtk_tree_model_get (model, iter, | ||
1111 | 1059 | HISTORY_COL_TITLE, &title, | ||
1112 | 1060 | HISTORY_COL_DESC, &desc, | ||
1113 | 1061 | -1); | ||
1114 | 1062 | if (desc) { | ||
1115 | 1063 | color = yelp_settings_get_color (yelp_settings_get_default (), | ||
1116 | 1064 | YELP_SETTINGS_COLOR_TEXT_LIGHT); | ||
1117 | 1065 | text = g_markup_printf_escaped ("<span size='larger'>%s</span>\n<span color='%s'>%s</span>", | ||
1118 | 1066 | title, color, desc); | ||
1119 | 1067 | g_free (color); | ||
1120 | 1068 | g_free (desc); | ||
1121 | 1069 | } | ||
1122 | 1070 | else { | ||
1123 | 1071 | text = g_markup_printf_escaped ("<span size='larger'>%s</span>", title); | ||
1124 | 1072 | } | ||
1125 | 1073 | |||
1126 | 1074 | g_object_set (cell, "markup", text, NULL); | ||
1127 | 1075 | g_free (text); | ||
1128 | 1076 | g_free (title); | ||
1129 | 1077 | } | ||
1130 | 1078 | |||
1131 | 1079 | static void | ||
1132 | 1080 | cell_set_bookmark_icon (GtkCellLayout *layout, | ||
1133 | 1081 | GtkCellRenderer *cell, | ||
1134 | 1082 | GtkTreeModel *model, | ||
1135 | 1083 | GtkTreeIter *iter, | ||
1136 | 1084 | YelpLocationEntry *entry) | ||
1137 | 1085 | { | ||
1138 | 1086 | gint flags; | ||
1139 | 1087 | gchar *doc_uri, *page_id; | ||
1140 | 1088 | YelpLocationEntryPrivate *priv = GET_PRIV (entry); | ||
1141 | 1089 | |||
1142 | 1090 | if (priv->bookmarks == NULL) { | ||
1143 | 1091 | g_object_set (cell, "icon-name", NULL, NULL); | ||
1144 | 1092 | return; | ||
1145 | 1093 | } | ||
1146 | 1094 | |||
1147 | 1095 | gtk_tree_model_get (model, iter, HISTORY_COL_FLAGS, &flags, -1); | ||
1148 | 1096 | if (flags & (LOCATION_ENTRY_IS_SEPARATOR | LOCATION_ENTRY_IS_SEARCH)) { | ||
1149 | 1097 | g_object_set (cell, "icon-name", NULL, NULL); | ||
1150 | 1098 | return; | ||
1151 | 1099 | } | ||
1152 | 1100 | |||
1153 | 1101 | gtk_tree_model_get (model, iter, | ||
1154 | 1102 | HISTORY_COL_DOC, &doc_uri, | ||
1155 | 1103 | HISTORY_COL_PAGE, &page_id, | ||
1156 | 1104 | -1); | ||
1157 | 1105 | if (doc_uri && page_id && | ||
1158 | 1106 | yelp_bookmarks_is_bookmarked (priv->bookmarks, doc_uri, page_id)) | ||
1159 | 1107 | g_object_set (cell, "icon-name", "yelp-bookmark-remove-symbolic", NULL); | ||
1160 | 1108 | else | ||
1161 | 1109 | g_object_set (cell, "icon-name", NULL, NULL); | ||
1162 | 1110 | |||
1163 | 1111 | g_free (doc_uri); | ||
1164 | 1112 | g_free (page_id); | ||
1165 | 1113 | } | ||
1166 | 1114 | |||
1167 | 1115 | static void | ||
1168 | 1116 | cell_set_completion_bookmark_icon (GtkCellLayout *layout, | ||
1169 | 1117 | GtkCellRenderer *cell, | ||
1170 | 1118 | GtkTreeModel *model, | ||
1171 | 1119 | GtkTreeIter *iter, | ||
1172 | 1120 | YelpLocationEntry *entry) | ||
1173 | 1121 | { | ||
1174 | 1122 | YelpLocationEntryPrivate *priv = GET_PRIV (entry); | ||
1175 | 1123 | |||
1176 | 1124 | if (priv->completion_uri) { | ||
1177 | 1125 | gchar *page_id = NULL; | ||
1178 | 1126 | gtk_tree_model_get (model, iter, | ||
1179 | 1127 | COMPLETION_COL_PAGE, &page_id, | ||
1180 | 1128 | -1); | ||
1181 | 1129 | |||
1182 | 1130 | if (page_id && yelp_bookmarks_is_bookmarked (priv->bookmarks, | ||
1183 | 1131 | priv->completion_uri, page_id)) | ||
1184 | 1132 | g_object_set (cell, "icon-name", "yelp-bookmark-remove-symbolic", NULL); | ||
1185 | 1133 | else | ||
1186 | 1134 | g_object_set (cell, "icon-name", NULL, NULL); | ||
1187 | 1135 | |||
1188 | 1136 | g_free (page_id); | ||
1189 | 1137 | } | ||
1190 | 1138 | } | ||
1191 | 1139 | |||
1192 | 1140 | static void | ||
1193 | 1141 | cell_set_completion_text_cell (GtkCellLayout *layout, | ||
1194 | 1142 | GtkCellRenderer *cell, | ||
1195 | 1143 | GtkTreeModel *model, | ||
1196 | 1144 | GtkTreeIter *iter, | ||
1197 | 1145 | YelpLocationEntry *entry) | ||
1198 | 1146 | { | ||
1199 | 1147 | gchar *title, *desc, *color, *text; | ||
1200 | 1148 | gint flags; | ||
1201 | 1149 | GList *cells, *cur; | ||
1202 | 1150 | YelpLocationEntryPrivate *priv = GET_PRIV (entry); | ||
1203 | 1151 | |||
1204 | 1152 | gtk_tree_model_get (model, iter, COMPLETION_COL_FLAGS, &flags, -1); | ||
1205 | 1153 | if (flags & COMPLETION_FLAG_ACTIVATE_SEARCH) { | ||
1206 | 1154 | title = g_strdup_printf (_("Search for “%s”"), | ||
1207 | 1155 | gtk_entry_get_text (GTK_ENTRY (priv->text_entry))); | ||
1208 | 1156 | text = g_markup_printf_escaped ("<span size='larger' font_weight='bold'>%s</span>", title); | ||
1209 | 1157 | g_object_set (cell, "markup", text, NULL); | ||
1210 | 1158 | g_free (text); | ||
1211 | 1159 | g_free (title); | ||
1212 | 1160 | |||
1213 | 1161 | color = yelp_settings_get_color (yelp_settings_get_default (), | ||
1214 | 1162 | YELP_SETTINGS_COLOR_YELLOW_BASE); | ||
1215 | 1163 | cells = gtk_cell_layout_get_cells (layout); | ||
1216 | 1164 | for (cur = cells; cur; cur = cur->next) { | ||
1217 | 1165 | g_object_set (cur->data, | ||
1218 | 1166 | "cell-background", color, | ||
1219 | 1167 | "cell-background-set", TRUE, | ||
1220 | 1168 | NULL); | ||
1221 | 1169 | } | ||
1222 | 1170 | g_list_free (cells); | ||
1223 | 1171 | g_free (color); | ||
1224 | 1172 | return; | ||
1225 | 1173 | } | ||
1226 | 1174 | |||
1227 | 1175 | gtk_tree_model_get (model, iter, | ||
1228 | 1176 | COMPLETION_COL_TITLE, &title, | ||
1229 | 1177 | COMPLETION_COL_DESC, &desc, | ||
1230 | 1178 | -1); | ||
1231 | 1179 | if (desc) { | ||
1232 | 1180 | color = yelp_settings_get_color (yelp_settings_get_default (), | ||
1233 | 1181 | YELP_SETTINGS_COLOR_TEXT_LIGHT); | ||
1234 | 1182 | text = g_markup_printf_escaped ("<span size='larger'>%s</span>\n<span color='%s'>%s</span>", | ||
1235 | 1183 | title, color, desc); | ||
1236 | 1184 | g_free (color); | ||
1237 | 1185 | g_free (desc); | ||
1238 | 1186 | } | ||
1239 | 1187 | else { | ||
1240 | 1188 | text = g_markup_printf_escaped ("<span size='larger'>%s</span>", title); | ||
1241 | 1189 | } | ||
1242 | 1190 | |||
1243 | 1191 | g_object_set (cell, "markup", text, NULL); | ||
1244 | 1192 | g_free (text); | ||
1245 | 1193 | g_free (title); | ||
1246 | 1194 | |||
1247 | 1195 | cells = gtk_cell_layout_get_cells (layout); | ||
1248 | 1196 | for (cur = cells; cur; cur = cur->next) | ||
1249 | 1197 | g_object_set (cur->data, "cell-background-set", FALSE, NULL); | ||
1250 | 1198 | g_list_free (cells); | ||
1251 | 1199 | } | ||
1252 | 1200 | |||
1253 | 1201 | static gboolean | ||
1254 | 1202 | entry_match_func (GtkEntryCompletion *completion, | ||
1255 | 1203 | const gchar *key, | ||
1256 | 1204 | GtkTreeIter *iter, | ||
1257 | 1205 | YelpLocationEntry *entry) | ||
1258 | 1206 | { | ||
1259 | 1207 | gint stri; | ||
1260 | 1208 | gchar *title, *desc, *titlecase = NULL, *desccase = NULL; | ||
1261 | 1209 | gboolean ret = FALSE; | ||
1262 | 1210 | gchar **strs; | ||
1263 | 1211 | gint flags; | ||
1264 | 1212 | GtkTreeModel *model = gtk_entry_completion_get_model (completion); | ||
1265 | 1213 | YelpLocationEntryPrivate *priv = GET_PRIV (entry); | ||
1266 | 1214 | static GRegex *nonword = NULL; | ||
1267 | 1215 | |||
1268 | 1216 | if (nonword == NULL) | ||
1269 | 1217 | nonword = g_regex_new ("\\W", 0, 0, NULL); | ||
1270 | 1218 | if (nonword == NULL) | ||
1271 | 1219 | return FALSE; | ||
1272 | 1220 | |||
1273 | 1221 | gtk_tree_model_get (model, iter, COMPLETION_COL_FLAGS, &flags, -1); | ||
1274 | 1222 | if (flags & COMPLETION_FLAG_ACTIVATE_SEARCH) | ||
1275 | 1223 | return TRUE; | ||
1276 | 1224 | |||
1277 | 1225 | gtk_tree_model_get (model, iter, | ||
1278 | 1226 | COMPLETION_COL_TITLE, &title, | ||
1279 | 1227 | COMPLETION_COL_DESC, &desc, | ||
1280 | 1228 | -1); | ||
1281 | 1229 | if (title) { | ||
1282 | 1230 | titlecase = g_utf8_casefold (title, -1); | ||
1283 | 1231 | g_free (title); | ||
1284 | 1232 | } | ||
1285 | 1233 | if (desc) { | ||
1286 | 1234 | desccase = g_utf8_casefold (desc, -1); | ||
1287 | 1235 | g_free (desc); | ||
1288 | 1236 | } | ||
1289 | 1237 | |||
1290 | 1238 | strs = g_regex_split (nonword, key, 0); | ||
1291 | 1239 | ret = TRUE; | ||
1292 | 1240 | for (stri = 0; strs[stri]; stri++) { | ||
1293 | 1241 | if (!titlecase || !strstr (titlecase, strs[stri])) { | ||
1294 | 1242 | if (!desccase || !strstr (desccase, strs[stri])) { | ||
1295 | 1243 | ret = FALSE; | ||
1296 | 1244 | break; | ||
1297 | 1245 | } | ||
1298 | 1246 | } | ||
1299 | 1247 | } | ||
1300 | 1248 | |||
1301 | 1249 | g_free (titlecase); | ||
1302 | 1250 | g_free (desccase); | ||
1303 | 1251 | g_strfreev (strs); | ||
1304 | 1252 | |||
1305 | 1253 | return ret; | ||
1306 | 1254 | } | ||
1307 | 1255 | |||
1308 | 1256 | static gint | ||
1309 | 1257 | entry_completion_sort (GtkTreeModel *model, | ||
1310 | 1258 | GtkTreeIter *iter1, | ||
1311 | 1259 | GtkTreeIter *iter2, | ||
1312 | 1260 | gpointer user_data) | ||
1313 | 1261 | { | ||
1314 | 1262 | gint ret = 0; | ||
1315 | 1263 | gint flags1, flags2; | ||
1316 | 1264 | gchar *key1, *key2; | ||
1317 | 1265 | |||
1318 | 1266 | gtk_tree_model_get (model, iter1, COMPLETION_COL_FLAGS, &flags1, -1); | ||
1319 | 1267 | gtk_tree_model_get (model, iter2, COMPLETION_COL_FLAGS, &flags2, -1); | ||
1320 | 1268 | if (flags1 & COMPLETION_FLAG_ACTIVATE_SEARCH) | ||
1321 | 1269 | return 1; | ||
1322 | 1270 | else if (flags2 & COMPLETION_FLAG_ACTIVATE_SEARCH) | ||
1323 | 1271 | return -1; | ||
1324 | 1272 | |||
1325 | 1273 | gtk_tree_model_get (model, iter1, COMPLETION_COL_ICON, &key1, -1); | ||
1326 | 1274 | gtk_tree_model_get (model, iter2, COMPLETION_COL_ICON, &key2, -1); | ||
1327 | 1275 | ret = yelp_settings_cmp_icons (key1, key2); | ||
1328 | 1276 | g_free (key1); | ||
1329 | 1277 | g_free (key2); | ||
1330 | 1278 | |||
1331 | 1279 | if (ret) | ||
1332 | 1280 | return ret; | ||
1333 | 1281 | |||
1334 | 1282 | gtk_tree_model_get (model, iter1, COMPLETION_COL_TITLE, &key1, -1); | ||
1335 | 1283 | gtk_tree_model_get (model, iter2, COMPLETION_COL_TITLE, &key2, -1); | ||
1336 | 1284 | if (key1 && key2) | ||
1337 | 1285 | ret = g_utf8_collate (key1, key2); | ||
1338 | 1286 | else if (key2 == NULL) | ||
1339 | 1287 | return -1; | ||
1340 | 1288 | else if (key1 == NULL) | ||
1341 | 1289 | return 1; | ||
1342 | 1290 | g_free (key1); | ||
1343 | 1291 | g_free (key2); | ||
1344 | 1292 | |||
1345 | 1293 | return ret; | ||
1346 | 1294 | } | ||
1347 | 1295 | |||
1348 | 1296 | static gboolean | ||
1349 | 1297 | entry_match_selected (GtkEntryCompletion *completion, | ||
1350 | 1298 | GtkTreeModel *model, | ||
1351 | 1299 | GtkTreeIter *iter, | ||
1352 | 1300 | YelpLocationEntry *entry) | ||
1353 | 1301 | { | ||
1354 | 1302 | YelpUri *base, *uri; | ||
1355 | 1303 | gchar *page, *xref; | ||
1356 | 1304 | gint flags; | ||
1357 | 1305 | YelpLocationEntryPrivate *priv = GET_PRIV (entry); | ||
1358 | 1306 | |||
1359 | 1307 | gtk_tree_model_get (model, iter, COMPLETION_COL_FLAGS, &flags, -1); | ||
1360 | 1308 | if (flags & COMPLETION_FLAG_ACTIVATE_SEARCH) { | ||
1361 | 1309 | entry_activate_cb (GTK_ENTRY (priv->text_entry), entry); | ||
1362 | 1310 | return TRUE; | ||
1363 | 1311 | } | ||
1364 | 1312 | |||
1365 | 1313 | g_object_get (priv->view, "yelp-uri", &base, NULL); | ||
1366 | 1314 | gtk_tree_model_get (model, iter, COMPLETION_COL_PAGE, &page, -1); | ||
1367 | 1315 | |||
1368 | 1316 | xref = g_strconcat ("xref:", page, NULL); | ||
1369 | 1317 | uri = yelp_uri_new_relative (base, xref); | ||
1370 | 1318 | |||
1371 | 1319 | yelp_view_load_uri (priv->view, uri); | ||
1372 | 1320 | |||
1373 | 1321 | g_free (page); | ||
1374 | 1322 | g_free (xref); | ||
1375 | 1323 | g_object_unref (uri); | ||
1376 | 1324 | g_object_unref (base); | ||
1377 | 1325 | |||
1378 | 1326 | gtk_widget_grab_focus (GTK_WIDGET (priv->view)); | ||
1379 | 1327 | return TRUE; | ||
1380 | 1328 | } | ||
1381 | 1329 | |||
1382 | 1330 | static void | ||
1383 | 1331 | view_loaded (YelpView *view, | ||
1384 | 1332 | YelpLocationEntry *entry) | ||
1385 | 1333 | { | ||
1386 | 1334 | gchar **ids; | ||
1387 | 1335 | gint i; | ||
1388 | 1336 | GtkTreeIter iter; | ||
1389 | 1337 | gint flags; | ||
1390 | 1338 | YelpUri *uri; | ||
1391 | 1339 | gchar *doc_uri, *page_id; | ||
1392 | 1340 | GtkTreeModel *completion; | ||
1393 | 1341 | YelpLocationEntryPrivate *priv = GET_PRIV (entry); | ||
1394 | 1342 | YelpDocument *document = yelp_view_get_document (view); | ||
1395 | 1343 | |||
1396 | 1344 | gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->history), &iter); | ||
1397 | 1345 | gtk_tree_model_get (GTK_TREE_MODEL (priv->history), &iter, | ||
1398 | 1346 | HISTORY_COL_FLAGS, &flags, | ||
1399 | 1347 | -1); | ||
1400 | 1348 | if (flags & LOCATION_ENTRY_IS_LOADING) { | ||
1401 | 1349 | flags = flags & ~LOCATION_ENTRY_IS_LOADING; | ||
1402 | 1350 | gtk_list_store_set (priv->history, &iter, HISTORY_COL_FLAGS, flags, -1); | ||
1403 | 1351 | } | ||
1404 | 1352 | |||
1405 | 1353 | g_object_get (view, | ||
1406 | 1354 | "yelp-uri", &uri, | ||
1407 | 1355 | "page-id", &page_id, | ||
1408 | 1356 | NULL); | ||
1409 | 1357 | doc_uri = yelp_uri_get_document_uri (uri); | ||
1410 | 1358 | gtk_list_store_set (priv->history, &iter, | ||
1411 | 1359 | HISTORY_COL_DOC, doc_uri, | ||
1412 | 1360 | HISTORY_COL_PAGE, page_id, | ||
1413 | 1361 | -1); | ||
1414 | 1362 | g_free (page_id); | ||
1415 | 1363 | |||
1416 | 1364 | if ((priv->completion_uri == NULL) || | ||
1417 | 1365 | !g_str_equal (doc_uri, priv->completion_uri)) { | ||
1418 | 1366 | completion = (GtkTreeModel *) g_hash_table_lookup (completions, doc_uri); | ||
1419 | 1367 | if (completion == NULL) { | ||
1420 | 1368 | GtkListStore *base = gtk_list_store_new (5, | ||
1421 | 1369 | G_TYPE_STRING, /* title */ | ||
1422 | 1370 | G_TYPE_STRING, /* desc */ | ||
1423 | 1371 | G_TYPE_STRING, /* icon */ | ||
1424 | 1372 | G_TYPE_STRING, /* uri */ | ||
1425 | 1373 | G_TYPE_INT /* flags */ | ||
1426 | 1374 | ); | ||
1427 | 1375 | completion = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (base)); | ||
1428 | 1376 | gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (completion), | ||
1429 | 1377 | entry_completion_sort, | ||
1430 | 1378 | NULL, NULL); | ||
1431 | 1379 | g_hash_table_insert (completions, g_strdup (doc_uri), completion); | ||
1432 | 1380 | if (document != NULL) { | ||
1433 | 1381 | GtkTreeIter iter; | ||
1434 | 1382 | ids = yelp_document_list_page_ids (document); | ||
1435 | 1383 | for (i = 0; ids[i]; i++) { | ||
1436 | 1384 | gchar *title, *desc, *icon; | ||
1437 | 1385 | gtk_list_store_insert (GTK_LIST_STORE (base), &iter, 0); | ||
1438 | 1386 | title = yelp_document_get_page_title (document, ids[i]); | ||
1439 | 1387 | desc = yelp_document_get_page_desc (document, ids[i]); | ||
1440 | 1388 | icon = yelp_document_get_page_icon (document, ids[i]); | ||
1441 | 1389 | gtk_list_store_set (base, &iter, | ||
1442 | 1390 | COMPLETION_COL_TITLE, title, | ||
1443 | 1391 | COMPLETION_COL_DESC, desc, | ||
1444 | 1392 | COMPLETION_COL_ICON, icon, | ||
1445 | 1393 | COMPLETION_COL_PAGE, ids[i], | ||
1446 | 1394 | -1); | ||
1447 | 1395 | g_free (icon); | ||
1448 | 1396 | g_free (desc); | ||
1449 | 1397 | g_free (title); | ||
1450 | 1398 | } | ||
1451 | 1399 | g_strfreev (ids); | ||
1452 | 1400 | gtk_list_store_insert (GTK_LIST_STORE (base), &iter, 0); | ||
1453 | 1401 | gtk_list_store_set (base, &iter, | ||
1454 | 1402 | COMPLETION_COL_ICON, "edit-find-symbolic", | ||
1455 | 1403 | COMPLETION_COL_FLAGS, COMPLETION_FLAG_ACTIVATE_SEARCH, | ||
1456 | 1404 | -1); | ||
1457 | 1405 | } | ||
1458 | 1406 | g_object_unref (base); | ||
1459 | 1407 | } | ||
1460 | 1408 | g_free (priv->completion_uri); | ||
1461 | 1409 | priv->completion_uri = doc_uri; | ||
1462 | 1410 | location_entry_set_completion (entry, completion); | ||
1463 | 1411 | } | ||
1464 | 1412 | |||
1465 | 1413 | g_object_unref (uri); | ||
1466 | 1414 | } | ||
1467 | 1415 | |||
1468 | 1416 | static void | ||
1469 | 1417 | view_uri_selected (YelpView *view, | ||
1470 | 1418 | GParamSpec *pspec, | ||
1471 | 1419 | YelpLocationEntry *entry) | ||
1472 | 1420 | { | ||
1473 | 1421 | GtkTreeIter iter; | ||
1474 | 1422 | gchar *iter_uri; | ||
1475 | 1423 | gboolean cont; | ||
1476 | 1424 | YelpUri *uri; | ||
1477 | 1425 | gchar *struri, *doc_uri; | ||
1478 | 1426 | YelpLocationEntryPrivate *priv = GET_PRIV (entry); | ||
1479 | 1427 | |||
1480 | 1428 | g_object_get (G_OBJECT (view), "yelp-uri", &uri, NULL); | ||
1481 | 1429 | if (uri == NULL) | ||
1482 | 1430 | return; | ||
1483 | 1431 | |||
1484 | 1432 | struri = yelp_uri_get_canonical_uri (uri); | ||
1485 | 1433 | |||
1486 | 1434 | cont = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->history), &iter); | ||
1487 | 1435 | while (cont) { | ||
1488 | 1436 | gtk_tree_model_get (GTK_TREE_MODEL (priv->history), &iter, | ||
1489 | 1437 | HISTORY_COL_URI, &iter_uri, | ||
1490 | 1438 | -1); | ||
1491 | 1439 | if (iter_uri && g_str_equal (struri, iter_uri)) { | ||
1492 | 1440 | g_free (iter_uri); | ||
1493 | 1441 | break; | ||
1494 | 1442 | } | ||
1495 | 1443 | else { | ||
1496 | 1444 | g_free (iter_uri); | ||
1497 | 1445 | cont = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->history), &iter); | ||
1498 | 1446 | } | ||
1499 | 1447 | } | ||
1500 | 1448 | if (cont) { | ||
1501 | 1449 | GtkTreeIter first; | ||
1502 | 1450 | gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->history), &first); | ||
1503 | 1451 | gtk_list_store_move_before (priv->history, &iter, &first); | ||
1504 | 1452 | } | ||
1505 | 1453 | else { | ||
1506 | 1454 | gint num; | ||
1507 | 1455 | GtkTreeIter last; | ||
1508 | 1456 | gtk_list_store_prepend (priv->history, &iter); | ||
1509 | 1457 | gtk_list_store_set (priv->history, &iter, | ||
1510 | 1458 | HISTORY_COL_TITLE, _("Loading"), | ||
1511 | 1459 | HISTORY_COL_ICON, "help-contents", | ||
1512 | 1460 | HISTORY_COL_URI, struri, | ||
1513 | 1461 | HISTORY_COL_FLAGS, LOCATION_ENTRY_IS_LOADING, | ||
1514 | 1462 | -1); | ||
1515 | 1463 | /* Limit to MAX_HISTORY entries. There are two extra for the search entry | ||
1516 | 1464 | * and the separator above it. | ||
1517 | 1465 | */ | ||
1518 | 1466 | num = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (priv->history), NULL); | ||
1519 | 1467 | if (num > MAX_HISTORY + 2) { | ||
1520 | 1468 | if (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (priv->history), | ||
1521 | 1469 | &last, NULL, | ||
1522 | 1470 | num - 3)) { | ||
1523 | 1471 | gtk_list_store_remove (priv->history, &last); | ||
1524 | 1472 | } | ||
1525 | 1473 | } | ||
1526 | 1474 | } | ||
1527 | 1475 | priv->view_uri_selected = TRUE; | ||
1528 | 1476 | gtk_combo_box_set_active_iter (GTK_COMBO_BOX (entry), &iter); | ||
1529 | 1477 | priv->view_uri_selected = FALSE; | ||
1530 | 1478 | |||
1531 | 1479 | g_free (struri); | ||
1532 | 1480 | g_object_unref (uri); | ||
1533 | 1481 | } | ||
1534 | 1482 | |||
1535 | 1483 | static void | ||
1536 | 1484 | view_page_title (YelpView *view, | ||
1537 | 1485 | GParamSpec *pspec, | ||
1538 | 1486 | YelpLocationEntry *entry) | ||
1539 | 1487 | { | ||
1540 | 1488 | GtkTreeIter first; | ||
1541 | 1489 | YelpLocationEntryPrivate *priv = GET_PRIV (entry); | ||
1542 | 1490 | |||
1543 | 1491 | if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->history), &first)) { | ||
1544 | 1492 | gchar *title, *frag = NULL; | ||
1545 | 1493 | YelpViewState state; | ||
1546 | 1494 | YelpUri *uri; | ||
1547 | 1495 | |||
1548 | 1496 | g_object_get (view, | ||
1549 | 1497 | "page-title", &title, | ||
1550 | 1498 | "state", &state, | ||
1551 | 1499 | NULL); | ||
1552 | 1500 | if (title == NULL) | ||
1553 | 1501 | return; | ||
1554 | 1502 | |||
1555 | 1503 | if (state != YELP_VIEW_STATE_ERROR) { | ||
1556 | 1504 | YelpUri *uri; | ||
1557 | 1505 | g_object_get (view, "yelp-uri", &uri, NULL); | ||
1558 | 1506 | frag = yelp_uri_get_frag_id (uri); | ||
1559 | 1507 | g_object_unref (uri); | ||
1560 | 1508 | } | ||
1561 | 1509 | |||
1562 | 1510 | if (frag) { | ||
1563 | 1511 | gchar *tmp = g_strdup_printf ("%s (#%s)", title, frag); | ||
1564 | 1512 | gtk_list_store_set (priv->history, &first, | ||
1565 | 1513 | HISTORY_COL_TITLE, tmp, | ||
1566 | 1514 | -1); | ||
1567 | 1515 | g_free (tmp); | ||
1568 | 1516 | g_free (frag); | ||
1569 | 1517 | } | ||
1570 | 1518 | else { | ||
1571 | 1519 | gtk_list_store_set (priv->history, &first, | ||
1572 | 1520 | HISTORY_COL_TITLE, title, | ||
1573 | 1521 | -1); | ||
1574 | 1522 | } | ||
1575 | 1523 | g_free (title); | ||
1576 | 1524 | } | ||
1577 | 1525 | } | ||
1578 | 1526 | |||
1579 | 1527 | static void | ||
1580 | 1528 | view_page_desc (YelpView *view, | ||
1581 | 1529 | GParamSpec *pspec, | ||
1582 | 1530 | YelpLocationEntry *entry) | ||
1583 | 1531 | { | ||
1584 | 1532 | GtkTreeIter first; | ||
1585 | 1533 | gchar *desc; | ||
1586 | 1534 | YelpLocationEntryPrivate *priv = GET_PRIV (entry); | ||
1587 | 1535 | |||
1588 | 1536 | g_object_get (view, "page-desc", &desc, NULL); | ||
1589 | 1537 | if (desc == NULL) | ||
1590 | 1538 | return; | ||
1591 | 1539 | |||
1592 | 1540 | if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->history), &first)) | ||
1593 | 1541 | gtk_list_store_set (priv->history, &first, | ||
1594 | 1542 | HISTORY_COL_DESC, desc, | ||
1595 | 1543 | -1); | ||
1596 | 1544 | g_free (desc); | ||
1597 | 1545 | } | ||
1598 | 1546 | |||
1599 | 1547 | static void | ||
1600 | 1548 | view_page_icon (YelpView *view, | ||
1601 | 1549 | GParamSpec *pspec, | ||
1602 | 1550 | YelpLocationEntry *entry) | ||
1603 | 1551 | { | ||
1604 | 1552 | GtkTreeIter first; | ||
1605 | 1553 | gchar *icon; | ||
1606 | 1554 | YelpLocationEntryPrivate *priv = GET_PRIV (entry); | ||
1607 | 1555 | |||
1608 | 1556 | g_object_get (view, "page-icon", &icon, NULL); | ||
1609 | 1557 | if (icon == NULL) | ||
1610 | 1558 | return; | ||
1611 | 1559 | |||
1612 | 1560 | if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->history), &first)) | ||
1613 | 1561 | gtk_list_store_set (priv->history, &first, | ||
1614 | 1562 | HISTORY_COL_ICON, icon, | ||
1615 | 1563 | -1); | ||
1616 | 1564 | g_free (icon); | ||
1617 | 1565 | } | ||
1618 | 1566 | |||
1619 | 1567 | static void | ||
1620 | 1568 | bookmarks_changed (YelpBookmarks *bookmarks, | ||
1621 | 1569 | const gchar *doc_uri, | ||
1622 | 1570 | YelpLocationEntry *entry) | ||
1623 | 1571 | { | ||
1624 | 1572 | GtkTreePath *path; | ||
1625 | 1573 | YelpLocationEntryPrivate *priv = GET_PRIV (entry); | ||
1626 | 1574 | |||
1627 | 1575 | if (priv->row) | ||
1628 | 1576 | path = gtk_tree_row_reference_get_path (priv->row); | ||
1629 | 1577 | |||
1630 | 1578 | if (path) { | ||
1631 | 1579 | GtkTreeIter iter; | ||
1632 | 1580 | gchar *this_uri, *page_id; | ||
1633 | 1581 | gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->history), &iter, path); | ||
1634 | 1582 | gtk_tree_model_get (GTK_TREE_MODEL (priv->history), &iter, | ||
1635 | 1583 | HISTORY_COL_DOC, &this_uri, | ||
1636 | 1584 | HISTORY_COL_PAGE, &page_id, | ||
1637 | 1585 | -1); | ||
1638 | 1586 | if (this_uri && g_str_equal (this_uri, doc_uri) && page_id) { | ||
1639 | 1587 | if (!yelp_bookmarks_is_bookmarked (priv->bookmarks, doc_uri, page_id)) { | ||
1640 | 1588 | gtk_entry_set_icon_from_icon_name (GTK_ENTRY (priv->text_entry), | ||
1641 | 1589 | GTK_ENTRY_ICON_SECONDARY, | ||
1642 | 1590 | "yelp-bookmark-add-symbolic"); | ||
1643 | 1591 | gtk_entry_set_icon_tooltip_text (GTK_ENTRY (priv->text_entry), | ||
1644 | 1592 | GTK_ENTRY_ICON_SECONDARY, | ||
1645 | 1593 | _("Bookmark this page")); | ||
1646 | 1594 | } | ||
1647 | 1595 | else { | ||
1648 | 1596 | gtk_entry_set_icon_from_icon_name (GTK_ENTRY (priv->text_entry), | ||
1649 | 1597 | GTK_ENTRY_ICON_SECONDARY, | ||
1650 | 1598 | "yelp-bookmark-remove-symbolic"); | ||
1651 | 1599 | gtk_entry_set_icon_tooltip_text (GTK_ENTRY (priv->text_entry), | ||
1652 | 1600 | GTK_ENTRY_ICON_SECONDARY, | ||
1653 | 1601 | _("Remove bookmark")); | ||
1654 | 1602 | } | ||
1655 | 1603 | } | ||
1656 | 1604 | else { | ||
1657 | 1605 | gtk_entry_set_icon_from_icon_name (GTK_ENTRY (priv->text_entry), | ||
1658 | 1606 | GTK_ENTRY_ICON_SECONDARY, | ||
1659 | 1607 | NULL); | ||
1660 | 1608 | } | ||
1661 | 1609 | g_free (this_uri); | ||
1662 | 1610 | g_free (page_id); | ||
1663 | 1611 | } | ||
1664 | 1612 | } | ||
1665 | 1613 | |||
1666 | 1614 | /** | ||
1667 | 1615 | * yelp_location_entry_new: | ||
1668 | 1616 | * @view: A #YelpView. | ||
1669 | 1617 | * | ||
1670 | 1618 | * Creates a new #YelpLocationEntry widget to control @view. | ||
1671 | 1619 | * | ||
1672 | 1620 | * Returns: A new #YelpLocationEntry. | ||
1673 | 1621 | **/ | ||
1674 | 1622 | GtkWidget* | ||
1675 | 1623 | yelp_location_entry_new (YelpView *view, | ||
1676 | 1624 | YelpBookmarks *bookmarks) | ||
1677 | 1625 | { | ||
1678 | 1626 | GtkWidget *ret; | ||
1679 | 1627 | g_return_val_if_fail (YELP_IS_VIEW (view), NULL); | ||
1680 | 1628 | |||
1681 | 1629 | ret = GTK_WIDGET (g_object_new (YELP_TYPE_LOCATION_ENTRY, | ||
1682 | 1630 | "has-entry", TRUE, | ||
1683 | 1631 | "view", view, | ||
1684 | 1632 | "bookmarks", bookmarks, | ||
1685 | 1633 | NULL)); | ||
1686 | 1634 | |||
1687 | 1635 | return ret; | ||
1688 | 1636 | } | ||
1689 | 1637 | |||
1690 | 1638 | /** | ||
1691 | 1639 | * yelp_location_entry_start_search: | ||
1692 | 1640 | * @entry: A #YelpLocationEntry. | ||
1693 | 1641 | * | ||
1694 | 1642 | * Puts @entry into search mode. This focuses the entry and clears its text | ||
1695 | 1643 | * contents. When the user activates the search, the | ||
1696 | 1644 | * #YelpLocationEntry::search-activated signal will be emitted. | ||
1697 | 1645 | **/ | ||
1698 | 1646 | void | ||
1699 | 1647 | yelp_location_entry_start_search (YelpLocationEntry *entry) | ||
1700 | 1648 | { | ||
1701 | 1649 | location_entry_start_search (entry, TRUE); | ||
1702 | 1650 | } | ||
1703 | 1651 | 0 | ||
1704 | === removed file '.pc/git_signal_handler.patch/libyelp/yelp-view.c' | |||
1705 | --- .pc/git_signal_handler.patch/libyelp/yelp-view.c 2014-02-27 13:28:05 +0000 | |||
1706 | +++ .pc/git_signal_handler.patch/libyelp/yelp-view.c 1970-01-01 00:00:00 +0000 | |||
1707 | @@ -1,2220 +0,0 @@ | |||
1708 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||
1709 | 2 | /* | ||
1710 | 3 | * Copyright (C) 2009 Shaun McCance <shaunm@gnome.org> | ||
1711 | 4 | * | ||
1712 | 5 | * This program is free software; you can redistribute it and/or | ||
1713 | 6 | * modify it under the terms of the GNU General Public License as | ||
1714 | 7 | * published by the Free Software Foundation; either version 2 of the | ||
1715 | 8 | * License, or (at your option) any later version. | ||
1716 | 9 | * | ||
1717 | 10 | * This program is distributed in the hope that it will be useful, | ||
1718 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1719 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1720 | 13 | * General Public License for more details. | ||
1721 | 14 | * | ||
1722 | 15 | * You should have received a copy of the GNU General Public | ||
1723 | 16 | * License along with this program; if not, write to the | ||
1724 | 17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
1725 | 18 | * Boston, MA 02111-1307, USA. | ||
1726 | 19 | * | ||
1727 | 20 | * Author: Shaun McCance <shaunm@gnome.org> | ||
1728 | 21 | */ | ||
1729 | 22 | |||
1730 | 23 | #ifdef HAVE_CONFIG_H | ||
1731 | 24 | #include <config.h> | ||
1732 | 25 | #endif | ||
1733 | 26 | |||
1734 | 27 | #include <glib/gi18n.h> | ||
1735 | 28 | #include <glib-object.h> | ||
1736 | 29 | #include <gio/gio.h> | ||
1737 | 30 | #include <gtk/gtk.h> | ||
1738 | 31 | #include <gdk/gdkx.h> | ||
1739 | 32 | #include <webkit/webkit.h> | ||
1740 | 33 | |||
1741 | 34 | #include "yelp-debug.h" | ||
1742 | 35 | #include "yelp-docbook-document.h" | ||
1743 | 36 | #include "yelp-error.h" | ||
1744 | 37 | #include "yelp-marshal.h" | ||
1745 | 38 | #include "yelp-settings.h" | ||
1746 | 39 | #include "yelp-types.h" | ||
1747 | 40 | #include "yelp-view.h" | ||
1748 | 41 | |||
1749 | 42 | #define BOGUS_URI "file:///bogus/" | ||
1750 | 43 | #define BOGUS_URI_LEN 14 | ||
1751 | 44 | |||
1752 | 45 | static void yelp_view_init (YelpView *view); | ||
1753 | 46 | static void yelp_view_class_init (YelpViewClass *klass); | ||
1754 | 47 | static void yelp_view_dispose (GObject *object); | ||
1755 | 48 | static void yelp_view_finalize (GObject *object); | ||
1756 | 49 | static void yelp_view_get_property (GObject *object, | ||
1757 | 50 | guint prop_id, | ||
1758 | 51 | GValue *value, | ||
1759 | 52 | GParamSpec *pspec); | ||
1760 | 53 | static void yelp_view_set_property (GObject *object, | ||
1761 | 54 | guint prop_id, | ||
1762 | 55 | const GValue *value, | ||
1763 | 56 | GParamSpec *pspec); | ||
1764 | 57 | |||
1765 | 58 | static gboolean view_external_uri (YelpView *view, | ||
1766 | 59 | YelpUri *uri); | ||
1767 | 60 | static void view_install_uri (YelpView *view, | ||
1768 | 61 | const gchar *uri); | ||
1769 | 62 | static void view_scrolled (GtkAdjustment *adjustment, | ||
1770 | 63 | YelpView *view); | ||
1771 | 64 | static void view_set_hadjustment (YelpView *view, | ||
1772 | 65 | GParamSpec *pspec, | ||
1773 | 66 | gpointer data); | ||
1774 | 67 | static void view_set_vadjustment (YelpView *view, | ||
1775 | 68 | GParamSpec *pspec, | ||
1776 | 69 | gpointer data); | ||
1777 | 70 | static void popup_open_link (GtkMenuItem *item, | ||
1778 | 71 | YelpView *view); | ||
1779 | 72 | static void popup_open_link_new (GtkMenuItem *item, | ||
1780 | 73 | YelpView *view); | ||
1781 | 74 | static void popup_copy_link (GtkMenuItem *item, | ||
1782 | 75 | YelpView *view); | ||
1783 | 76 | static void popup_save_image (GtkMenuItem *item, | ||
1784 | 77 | YelpView *view); | ||
1785 | 78 | static void popup_send_image (GtkMenuItem *item, | ||
1786 | 79 | YelpView *view); | ||
1787 | 80 | static void popup_copy_code (GtkMenuItem *item, | ||
1788 | 81 | YelpView *view); | ||
1789 | 82 | static void popup_save_code (GtkMenuItem *item, | ||
1790 | 83 | YelpView *view); | ||
1791 | 84 | static void view_populate_popup (YelpView *view, | ||
1792 | 85 | GtkMenu *menu, | ||
1793 | 86 | gpointer data); | ||
1794 | 87 | static void view_script_alert (YelpView *view, | ||
1795 | 88 | WebKitWebFrame *frame, | ||
1796 | 89 | gchar *message, | ||
1797 | 90 | gpointer data); | ||
1798 | 91 | static gboolean view_navigation_requested (WebKitWebView *view, | ||
1799 | 92 | WebKitWebFrame *frame, | ||
1800 | 93 | WebKitNetworkRequest *request, | ||
1801 | 94 | WebKitWebNavigationAction *action, | ||
1802 | 95 | WebKitWebPolicyDecision *decision, | ||
1803 | 96 | gpointer user_data); | ||
1804 | 97 | static void view_resource_request (WebKitWebView *view, | ||
1805 | 98 | WebKitWebFrame *frame, | ||
1806 | 99 | WebKitWebResource *resource, | ||
1807 | 100 | WebKitNetworkRequest *request, | ||
1808 | 101 | WebKitNetworkResponse *response, | ||
1809 | 102 | gpointer user_data); | ||
1810 | 103 | static void view_document_loaded (WebKitWebView *view, | ||
1811 | 104 | WebKitWebFrame *frame, | ||
1812 | 105 | gpointer user_data); | ||
1813 | 106 | |||
1814 | 107 | static void view_print (GtkAction *action, | ||
1815 | 108 | YelpView *view); | ||
1816 | 109 | static void view_history_action (GtkAction *action, | ||
1817 | 110 | YelpView *view); | ||
1818 | 111 | static void view_navigation_action (GtkAction *action, | ||
1819 | 112 | YelpView *view); | ||
1820 | 113 | |||
1821 | 114 | static void view_clear_load (YelpView *view); | ||
1822 | 115 | static void view_load_page (YelpView *view); | ||
1823 | 116 | static void view_show_error_page (YelpView *view, | ||
1824 | 117 | GError *error); | ||
1825 | 118 | |||
1826 | 119 | static void settings_set_fonts (YelpSettings *settings); | ||
1827 | 120 | static void settings_show_text_cursor (YelpSettings *settings); | ||
1828 | 121 | |||
1829 | 122 | static void uri_resolved (YelpUri *uri, | ||
1830 | 123 | YelpView *view); | ||
1831 | 124 | static void document_callback (YelpDocument *document, | ||
1832 | 125 | YelpDocumentSignal signal, | ||
1833 | 126 | YelpView *view, | ||
1834 | 127 | GError *error); | ||
1835 | 128 | |||
1836 | 129 | static const GtkActionEntry entries[] = { | ||
1837 | 130 | {"YelpViewPrint", GTK_STOCK_PRINT, | ||
1838 | 131 | N_("_Print..."), | ||
1839 | 132 | "<Control>P", | ||
1840 | 133 | NULL, | ||
1841 | 134 | G_CALLBACK (view_print) }, | ||
1842 | 135 | {"YelpViewGoBack", GTK_STOCK_GO_BACK, | ||
1843 | 136 | N_("_Back"), | ||
1844 | 137 | "<Alt>Left", | ||
1845 | 138 | NULL, | ||
1846 | 139 | G_CALLBACK (view_history_action) }, | ||
1847 | 140 | {"YelpViewGoForward", GTK_STOCK_GO_FORWARD, | ||
1848 | 141 | N_("_Forward"), | ||
1849 | 142 | "<Alt>Right", | ||
1850 | 143 | NULL, | ||
1851 | 144 | G_CALLBACK (view_history_action) }, | ||
1852 | 145 | {"YelpViewGoPrevious", NULL, | ||
1853 | 146 | N_("_Previous Page"), | ||
1854 | 147 | "<Control>Page_Up", | ||
1855 | 148 | NULL, | ||
1856 | 149 | G_CALLBACK (view_navigation_action) }, | ||
1857 | 150 | {"YelpViewGoNext", NULL, | ||
1858 | 151 | N_("_Next Page"), | ||
1859 | 152 | "<Control>Page_Down", | ||
1860 | 153 | NULL, | ||
1861 | 154 | G_CALLBACK (view_navigation_action) } | ||
1862 | 155 | }; | ||
1863 | 156 | |||
1864 | 157 | static gchar *nautilus_sendto = NULL; | ||
1865 | 158 | |||
1866 | 159 | enum { | ||
1867 | 160 | PROP_0, | ||
1868 | 161 | PROP_URI, | ||
1869 | 162 | PROP_STATE, | ||
1870 | 163 | PROP_PAGE_ID, | ||
1871 | 164 | PROP_ROOT_TITLE, | ||
1872 | 165 | PROP_PAGE_TITLE, | ||
1873 | 166 | PROP_PAGE_DESC, | ||
1874 | 167 | PROP_PAGE_ICON | ||
1875 | 168 | }; | ||
1876 | 169 | |||
1877 | 170 | enum { | ||
1878 | 171 | NEW_VIEW_REQUESTED, | ||
1879 | 172 | EXTERNAL_URI, | ||
1880 | 173 | LOADED, | ||
1881 | 174 | LAST_SIGNAL | ||
1882 | 175 | }; | ||
1883 | 176 | static gint signals[LAST_SIGNAL] = { 0 }; | ||
1884 | 177 | |||
1885 | 178 | G_DEFINE_TYPE (YelpView, yelp_view, WEBKIT_TYPE_WEB_VIEW); | ||
1886 | 179 | #define GET_PRIV(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), YELP_TYPE_VIEW, YelpViewPrivate)) | ||
1887 | 180 | |||
1888 | 181 | static WebKitWebSettings *websettings; | ||
1889 | 182 | |||
1890 | 183 | typedef struct _YelpActionEntry YelpActionEntry; | ||
1891 | 184 | struct _YelpActionEntry { | ||
1892 | 185 | GtkAction *action; | ||
1893 | 186 | YelpViewActionValidFunc func; | ||
1894 | 187 | gpointer data; | ||
1895 | 188 | }; | ||
1896 | 189 | static void | ||
1897 | 190 | action_entry_free (YelpActionEntry *entry) | ||
1898 | 191 | { | ||
1899 | 192 | if (entry == NULL) | ||
1900 | 193 | return; | ||
1901 | 194 | g_object_unref (entry->action); | ||
1902 | 195 | g_free (entry); | ||
1903 | 196 | } | ||
1904 | 197 | |||
1905 | 198 | typedef struct _YelpBackEntry YelpBackEntry; | ||
1906 | 199 | struct _YelpBackEntry { | ||
1907 | 200 | YelpUri *uri; | ||
1908 | 201 | gchar *title; | ||
1909 | 202 | gchar *desc; | ||
1910 | 203 | gdouble hadj; | ||
1911 | 204 | gdouble vadj; | ||
1912 | 205 | }; | ||
1913 | 206 | static void | ||
1914 | 207 | back_entry_free (YelpBackEntry *back) | ||
1915 | 208 | { | ||
1916 | 209 | if (back == NULL) | ||
1917 | 210 | return; | ||
1918 | 211 | g_object_unref (back->uri); | ||
1919 | 212 | g_free (back->title); | ||
1920 | 213 | g_free (back->desc); | ||
1921 | 214 | g_free (back); | ||
1922 | 215 | } | ||
1923 | 216 | |||
1924 | 217 | typedef struct _YelpViewPrivate YelpViewPrivate; | ||
1925 | 218 | struct _YelpViewPrivate { | ||
1926 | 219 | YelpUri *uri; | ||
1927 | 220 | YelpUri *resolve_uri; | ||
1928 | 221 | gulong uri_resolved; | ||
1929 | 222 | gchar *bogus_uri; | ||
1930 | 223 | YelpDocument *document; | ||
1931 | 224 | GCancellable *cancellable; | ||
1932 | 225 | GtkAdjustment *vadjustment; | ||
1933 | 226 | GtkAdjustment *hadjustment; | ||
1934 | 227 | gdouble vadjust; | ||
1935 | 228 | gdouble hadjust; | ||
1936 | 229 | gulong vadjuster; | ||
1937 | 230 | gulong hadjuster; | ||
1938 | 231 | |||
1939 | 232 | gchar *popup_link_uri; | ||
1940 | 233 | gchar *popup_link_text; | ||
1941 | 234 | gchar *popup_image_uri; | ||
1942 | 235 | WebKitDOMNode *popup_code_node; | ||
1943 | 236 | WebKitDOMNode *popup_code_title; | ||
1944 | 237 | gchar *popup_code_text; | ||
1945 | 238 | |||
1946 | 239 | YelpViewState state; | ||
1947 | 240 | YelpViewState prevstate; | ||
1948 | 241 | |||
1949 | 242 | gchar *page_id; | ||
1950 | 243 | gchar *root_title; | ||
1951 | 244 | gchar *page_title; | ||
1952 | 245 | gchar *page_desc; | ||
1953 | 246 | gchar *page_icon; | ||
1954 | 247 | |||
1955 | 248 | GList *back_list; | ||
1956 | 249 | GList *back_cur; | ||
1957 | 250 | gboolean back_load; | ||
1958 | 251 | |||
1959 | 252 | GtkActionGroup *action_group; | ||
1960 | 253 | |||
1961 | 254 | GSList *link_actions; | ||
1962 | 255 | |||
1963 | 256 | gint navigation_requested; | ||
1964 | 257 | }; | ||
1965 | 258 | |||
1966 | 259 | #define TARGET_TYPE_URI_LIST "text/uri-list" | ||
1967 | 260 | enum { | ||
1968 | 261 | TARGET_URI_LIST | ||
1969 | 262 | }; | ||
1970 | 263 | |||
1971 | 264 | static void | ||
1972 | 265 | yelp_view_init (YelpView *view) | ||
1973 | 266 | { | ||
1974 | 267 | GtkAction *action; | ||
1975 | 268 | YelpViewPrivate *priv = GET_PRIV (view); | ||
1976 | 269 | |||
1977 | 270 | g_object_set (view, "settings", websettings, NULL); | ||
1978 | 271 | |||
1979 | 272 | priv->cancellable = NULL; | ||
1980 | 273 | |||
1981 | 274 | priv->prevstate = priv->state = YELP_VIEW_STATE_BLANK; | ||
1982 | 275 | |||
1983 | 276 | priv->navigation_requested = | ||
1984 | 277 | g_signal_connect (view, "navigation-policy-decision-requested", | ||
1985 | 278 | G_CALLBACK (view_navigation_requested), NULL); | ||
1986 | 279 | g_signal_connect (view, "resource-request-starting", | ||
1987 | 280 | G_CALLBACK (view_resource_request), NULL); | ||
1988 | 281 | g_signal_connect (view, "document-load-finished", | ||
1989 | 282 | G_CALLBACK (view_document_loaded), NULL); | ||
1990 | 283 | g_signal_connect (view, "notify::hadjustment", | ||
1991 | 284 | G_CALLBACK (view_set_hadjustment), NULL); | ||
1992 | 285 | g_signal_connect (view, "notify::vadjustment", | ||
1993 | 286 | G_CALLBACK (view_set_vadjustment), NULL); | ||
1994 | 287 | g_signal_connect (view, "populate-popup", | ||
1995 | 288 | G_CALLBACK (view_populate_popup), NULL); | ||
1996 | 289 | g_signal_connect (view, "script-alert", | ||
1997 | 290 | G_CALLBACK (view_script_alert), NULL); | ||
1998 | 291 | |||
1999 | 292 | priv->action_group = gtk_action_group_new ("YelpView"); | ||
2000 | 293 | gtk_action_group_set_translation_domain (priv->action_group, GETTEXT_PACKAGE); | ||
2001 | 294 | gtk_action_group_add_actions (priv->action_group, | ||
2002 | 295 | entries, G_N_ELEMENTS (entries), | ||
2003 | 296 | view); | ||
2004 | 297 | action = gtk_action_group_get_action (priv->action_group, "YelpViewGoBack"); | ||
2005 | 298 | gtk_action_set_sensitive (action, FALSE); | ||
2006 | 299 | action = gtk_action_group_get_action (priv->action_group, "YelpViewGoForward"); | ||
2007 | 300 | gtk_action_set_sensitive (action, FALSE); | ||
2008 | 301 | } | ||
2009 | 302 | |||
2010 | 303 | static void | ||
2011 | 304 | yelp_view_dispose (GObject *object) | ||
2012 | 305 | { | ||
2013 | 306 | YelpViewPrivate *priv = GET_PRIV (object); | ||
2014 | 307 | |||
2015 | 308 | view_clear_load (YELP_VIEW (object)); | ||
2016 | 309 | |||
2017 | 310 | if (priv->vadjuster > 0) { | ||
2018 | 311 | g_source_remove (priv->vadjuster); | ||
2019 | 312 | priv->vadjuster = 0; | ||
2020 | 313 | } | ||
2021 | 314 | |||
2022 | 315 | if (priv->hadjuster > 0) { | ||
2023 | 316 | g_source_remove (priv->hadjuster); | ||
2024 | 317 | priv->hadjuster = 0; | ||
2025 | 318 | } | ||
2026 | 319 | |||
2027 | 320 | if (priv->action_group) { | ||
2028 | 321 | g_object_unref (priv->action_group); | ||
2029 | 322 | priv->action_group = NULL; | ||
2030 | 323 | } | ||
2031 | 324 | |||
2032 | 325 | if (priv->document) { | ||
2033 | 326 | g_object_unref (priv->document); | ||
2034 | 327 | priv->document = NULL; | ||
2035 | 328 | } | ||
2036 | 329 | |||
2037 | 330 | while (priv->link_actions) { | ||
2038 | 331 | action_entry_free (priv->link_actions->data); | ||
2039 | 332 | priv->link_actions = g_slist_delete_link (priv->link_actions, priv->link_actions); | ||
2040 | 333 | } | ||
2041 | 334 | |||
2042 | 335 | priv->back_cur = NULL; | ||
2043 | 336 | while (priv->back_list) { | ||
2044 | 337 | back_entry_free ((YelpBackEntry *) priv->back_list->data); | ||
2045 | 338 | priv->back_list = g_list_delete_link (priv->back_list, priv->back_list); | ||
2046 | 339 | } | ||
2047 | 340 | |||
2048 | 341 | G_OBJECT_CLASS (yelp_view_parent_class)->dispose (object); | ||
2049 | 342 | } | ||
2050 | 343 | |||
2051 | 344 | static void | ||
2052 | 345 | yelp_view_finalize (GObject *object) | ||
2053 | 346 | { | ||
2054 | 347 | YelpViewPrivate *priv = GET_PRIV (object); | ||
2055 | 348 | |||
2056 | 349 | g_free (priv->popup_link_uri); | ||
2057 | 350 | g_free (priv->popup_link_text); | ||
2058 | 351 | g_free (priv->popup_image_uri); | ||
2059 | 352 | g_free (priv->popup_code_text); | ||
2060 | 353 | |||
2061 | 354 | g_free (priv->page_id); | ||
2062 | 355 | g_free (priv->root_title); | ||
2063 | 356 | g_free (priv->page_title); | ||
2064 | 357 | g_free (priv->page_desc); | ||
2065 | 358 | g_free (priv->page_icon); | ||
2066 | 359 | |||
2067 | 360 | g_free (priv->bogus_uri); | ||
2068 | 361 | |||
2069 | 362 | G_OBJECT_CLASS (yelp_view_parent_class)->finalize (object); | ||
2070 | 363 | } | ||
2071 | 364 | |||
2072 | 365 | static void | ||
2073 | 366 | yelp_view_class_init (YelpViewClass *klass) | ||
2074 | 367 | { | ||
2075 | 368 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | ||
2076 | 369 | YelpSettings *settings = yelp_settings_get_default (); | ||
2077 | 370 | |||
2078 | 371 | nautilus_sendto = g_find_program_in_path ("nautilus-sendto"); | ||
2079 | 372 | |||
2080 | 373 | websettings = webkit_web_settings_new (); | ||
2081 | 374 | g_object_set (websettings, "enable-universal-access-from-file-uris", TRUE, NULL); | ||
2082 | 375 | g_signal_connect (settings, | ||
2083 | 376 | "fonts-changed", | ||
2084 | 377 | G_CALLBACK (settings_set_fonts), | ||
2085 | 378 | NULL); | ||
2086 | 379 | settings_set_fonts (settings); | ||
2087 | 380 | g_signal_connect (settings, | ||
2088 | 381 | "notify::show-text-cursor", | ||
2089 | 382 | G_CALLBACK (settings_show_text_cursor), | ||
2090 | 383 | NULL); | ||
2091 | 384 | settings_show_text_cursor (settings); | ||
2092 | 385 | |||
2093 | 386 | klass->external_uri = view_external_uri; | ||
2094 | 387 | |||
2095 | 388 | object_class->dispose = yelp_view_dispose; | ||
2096 | 389 | object_class->finalize = yelp_view_finalize; | ||
2097 | 390 | object_class->get_property = yelp_view_get_property; | ||
2098 | 391 | object_class->set_property = yelp_view_set_property; | ||
2099 | 392 | |||
2100 | 393 | signals[NEW_VIEW_REQUESTED] = | ||
2101 | 394 | g_signal_new ("new-view-requested", | ||
2102 | 395 | G_TYPE_FROM_CLASS (klass), | ||
2103 | 396 | G_SIGNAL_RUN_LAST, | ||
2104 | 397 | 0, NULL, NULL, | ||
2105 | 398 | g_cclosure_marshal_VOID__OBJECT, | ||
2106 | 399 | G_TYPE_NONE, 1, YELP_TYPE_URI); | ||
2107 | 400 | |||
2108 | 401 | signals[EXTERNAL_URI] = | ||
2109 | 402 | g_signal_new ("external-uri", | ||
2110 | 403 | G_TYPE_FROM_CLASS (klass), | ||
2111 | 404 | G_SIGNAL_RUN_LAST, | ||
2112 | 405 | G_STRUCT_OFFSET (YelpViewClass, external_uri), | ||
2113 | 406 | g_signal_accumulator_true_handled, NULL, | ||
2114 | 407 | yelp_marshal_BOOLEAN__OBJECT, | ||
2115 | 408 | G_TYPE_BOOLEAN, 1, YELP_TYPE_URI); | ||
2116 | 409 | |||
2117 | 410 | signals[LOADED] = | ||
2118 | 411 | g_signal_new ("loaded", | ||
2119 | 412 | G_TYPE_FROM_CLASS (klass), | ||
2120 | 413 | G_SIGNAL_RUN_LAST, | ||
2121 | 414 | 0, NULL, NULL, | ||
2122 | 415 | g_cclosure_marshal_VOID__VOID, | ||
2123 | 416 | G_TYPE_NONE, 0); | ||
2124 | 417 | |||
2125 | 418 | g_type_class_add_private (klass, sizeof (YelpViewPrivate)); | ||
2126 | 419 | |||
2127 | 420 | g_object_class_install_property (object_class, | ||
2128 | 421 | PROP_URI, | ||
2129 | 422 | g_param_spec_object ("yelp-uri", | ||
2130 | 423 | _("Yelp URI"), | ||
2131 | 424 | _("A YelpUri with the current location"), | ||
2132 | 425 | YELP_TYPE_URI, | ||
2133 | 426 | G_PARAM_READWRITE | G_PARAM_STATIC_NAME | | ||
2134 | 427 | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); | ||
2135 | 428 | |||
2136 | 429 | g_object_class_install_property (object_class, | ||
2137 | 430 | PROP_STATE, | ||
2138 | 431 | g_param_spec_enum ("state", | ||
2139 | 432 | N_("Loading State"), | ||
2140 | 433 | N_("The loading state of the view"), | ||
2141 | 434 | YELP_TYPE_VIEW_STATE, | ||
2142 | 435 | YELP_VIEW_STATE_BLANK, | ||
2143 | 436 | G_PARAM_READWRITE | G_PARAM_STATIC_NAME | | ||
2144 | 437 | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); | ||
2145 | 438 | |||
2146 | 439 | g_object_class_install_property (object_class, | ||
2147 | 440 | PROP_PAGE_ID, | ||
2148 | 441 | g_param_spec_string ("page-id", | ||
2149 | 442 | N_("Page ID"), | ||
2150 | 443 | N_("The ID of the root page of the page being viewed"), | ||
2151 | 444 | NULL, | ||
2152 | 445 | G_PARAM_READABLE | | ||
2153 | 446 | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); | ||
2154 | 447 | |||
2155 | 448 | g_object_class_install_property (object_class, | ||
2156 | 449 | PROP_ROOT_TITLE, | ||
2157 | 450 | g_param_spec_string ("root-title", | ||
2158 | 451 | N_("Root Title"), | ||
2159 | 452 | N_("The title of the root page of the page being viewed"), | ||
2160 | 453 | NULL, | ||
2161 | 454 | G_PARAM_READABLE | | ||
2162 | 455 | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); | ||
2163 | 456 | |||
2164 | 457 | g_object_class_install_property (object_class, | ||
2165 | 458 | PROP_PAGE_TITLE, | ||
2166 | 459 | g_param_spec_string ("page-title", | ||
2167 | 460 | N_("Page Title"), | ||
2168 | 461 | N_("The title of the page being viewed"), | ||
2169 | 462 | NULL, | ||
2170 | 463 | G_PARAM_READABLE | | ||
2171 | 464 | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); | ||
2172 | 465 | |||
2173 | 466 | g_object_class_install_property (object_class, | ||
2174 | 467 | PROP_PAGE_DESC, | ||
2175 | 468 | g_param_spec_string ("page-desc", | ||
2176 | 469 | N_("Page Description"), | ||
2177 | 470 | N_("The description of the page being viewed"), | ||
2178 | 471 | NULL, | ||
2179 | 472 | G_PARAM_READABLE | | ||
2180 | 473 | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); | ||
2181 | 474 | |||
2182 | 475 | g_object_class_install_property (object_class, | ||
2183 | 476 | PROP_PAGE_ICON, | ||
2184 | 477 | g_param_spec_string ("page-icon", | ||
2185 | 478 | N_("Page Icon"), | ||
2186 | 479 | N_("The icon of the page being viewed"), | ||
2187 | 480 | NULL, | ||
2188 | 481 | G_PARAM_READABLE | | ||
2189 | 482 | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); | ||
2190 | 483 | } | ||
2191 | 484 | |||
2192 | 485 | static void | ||
2193 | 486 | yelp_view_get_property (GObject *object, | ||
2194 | 487 | guint prop_id, | ||
2195 | 488 | GValue *value, | ||
2196 | 489 | GParamSpec *pspec) | ||
2197 | 490 | { | ||
2198 | 491 | YelpViewPrivate *priv = GET_PRIV (object); | ||
2199 | 492 | |||
2200 | 493 | switch (prop_id) | ||
2201 | 494 | { | ||
2202 | 495 | case PROP_URI: | ||
2203 | 496 | g_value_set_object (value, priv->uri); | ||
2204 | 497 | break; | ||
2205 | 498 | case PROP_PAGE_ID: | ||
2206 | 499 | g_value_set_string (value, priv->page_id); | ||
2207 | 500 | break; | ||
2208 | 501 | case PROP_ROOT_TITLE: | ||
2209 | 502 | g_value_set_string (value, priv->root_title); | ||
2210 | 503 | break; | ||
2211 | 504 | case PROP_PAGE_TITLE: | ||
2212 | 505 | g_value_set_string (value, priv->page_title); | ||
2213 | 506 | break; | ||
2214 | 507 | case PROP_PAGE_DESC: | ||
2215 | 508 | g_value_set_string (value, priv->page_desc); | ||
2216 | 509 | break; | ||
2217 | 510 | case PROP_PAGE_ICON: | ||
2218 | 511 | if (priv->page_icon) | ||
2219 | 512 | g_value_set_string (value, priv->page_icon); | ||
2220 | 513 | else | ||
2221 | 514 | g_value_set_string (value, "yelp-page-symbolic"); | ||
2222 | 515 | break; | ||
2223 | 516 | case PROP_STATE: | ||
2224 | 517 | g_value_set_enum (value, priv->state); | ||
2225 | 518 | break; | ||
2226 | 519 | default: | ||
2227 | 520 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | ||
2228 | 521 | break; | ||
2229 | 522 | } | ||
2230 | 523 | } | ||
2231 | 524 | |||
2232 | 525 | static void | ||
2233 | 526 | yelp_view_set_property (GObject *object, | ||
2234 | 527 | guint prop_id, | ||
2235 | 528 | const GValue *value, | ||
2236 | 529 | GParamSpec *pspec) | ||
2237 | 530 | { | ||
2238 | 531 | YelpUri *uri; | ||
2239 | 532 | YelpViewPrivate *priv = GET_PRIV (object); | ||
2240 | 533 | |||
2241 | 534 | switch (prop_id) | ||
2242 | 535 | { | ||
2243 | 536 | case PROP_URI: | ||
2244 | 537 | uri = g_value_get_object (value); | ||
2245 | 538 | yelp_view_load_uri (YELP_VIEW (object), uri); | ||
2246 | 539 | g_object_unref (uri); | ||
2247 | 540 | break; | ||
2248 | 541 | case PROP_STATE: | ||
2249 | 542 | priv->prevstate = priv->state; | ||
2250 | 543 | priv->state = g_value_get_enum (value); | ||
2251 | 544 | break; | ||
2252 | 545 | default: | ||
2253 | 546 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | ||
2254 | 547 | break; | ||
2255 | 548 | } | ||
2256 | 549 | } | ||
2257 | 550 | |||
2258 | 551 | /******************************************************************************/ | ||
2259 | 552 | |||
2260 | 553 | GtkWidget * | ||
2261 | 554 | yelp_view_new (void) | ||
2262 | 555 | { | ||
2263 | 556 | return (GtkWidget *) g_object_new (YELP_TYPE_VIEW, NULL); | ||
2264 | 557 | } | ||
2265 | 558 | |||
2266 | 559 | void | ||
2267 | 560 | yelp_view_load (YelpView *view, | ||
2268 | 561 | const gchar *uri) | ||
2269 | 562 | { | ||
2270 | 563 | YelpUri *yuri = yelp_uri_new (uri); | ||
2271 | 564 | yelp_view_load_uri (view, yuri); | ||
2272 | 565 | g_object_unref (yuri); | ||
2273 | 566 | } | ||
2274 | 567 | |||
2275 | 568 | void | ||
2276 | 569 | yelp_view_load_uri (YelpView *view, | ||
2277 | 570 | YelpUri *uri) | ||
2278 | 571 | { | ||
2279 | 572 | YelpViewPrivate *priv = GET_PRIV (view); | ||
2280 | 573 | |||
2281 | 574 | g_object_set (view, "state", YELP_VIEW_STATE_LOADING, NULL); | ||
2282 | 575 | |||
2283 | 576 | gtk_action_set_sensitive (gtk_action_group_get_action (priv->action_group, | ||
2284 | 577 | "YelpViewGoPrevious"), | ||
2285 | 578 | FALSE); | ||
2286 | 579 | gtk_action_set_sensitive (gtk_action_group_get_action (priv->action_group, | ||
2287 | 580 | "YelpViewGoNext"), | ||
2288 | 581 | FALSE); | ||
2289 | 582 | |||
2290 | 583 | if (!yelp_uri_is_resolved (uri)) { | ||
2291 | 584 | if (priv->resolve_uri != NULL) { | ||
2292 | 585 | if (priv->uri_resolved != 0) { | ||
2293 | 586 | g_signal_handler_disconnect (priv->resolve_uri, priv->uri_resolved); | ||
2294 | 587 | priv->uri_resolved = 0; | ||
2295 | 588 | } | ||
2296 | 589 | g_object_unref (priv->resolve_uri); | ||
2297 | 590 | } | ||
2298 | 591 | priv->resolve_uri = g_object_ref (uri); | ||
2299 | 592 | priv->uri_resolved = g_signal_connect (uri, "resolved", | ||
2300 | 593 | G_CALLBACK (uri_resolved), | ||
2301 | 594 | view); | ||
2302 | 595 | yelp_uri_resolve (uri); | ||
2303 | 596 | } | ||
2304 | 597 | else { | ||
2305 | 598 | uri_resolved (uri, view); | ||
2306 | 599 | } | ||
2307 | 600 | } | ||
2308 | 601 | |||
2309 | 602 | void | ||
2310 | 603 | yelp_view_load_document (YelpView *view, | ||
2311 | 604 | YelpUri *uri, | ||
2312 | 605 | YelpDocument *document) | ||
2313 | 606 | { | ||
2314 | 607 | GParamSpec *spec; | ||
2315 | 608 | YelpViewPrivate *priv = GET_PRIV (view); | ||
2316 | 609 | |||
2317 | 610 | g_return_if_fail (yelp_uri_is_resolved (uri)); | ||
2318 | 611 | |||
2319 | 612 | g_object_set (view, "state", YELP_VIEW_STATE_LOADING, NULL); | ||
2320 | 613 | |||
2321 | 614 | g_object_ref (uri); | ||
2322 | 615 | view_clear_load (view); | ||
2323 | 616 | priv->uri = uri; | ||
2324 | 617 | spec = g_object_class_find_property ((GObjectClass *) YELP_VIEW_GET_CLASS (view), | ||
2325 | 618 | "yelp-uri"); | ||
2326 | 619 | g_signal_emit_by_name (view, "notify::yelp-uri", spec); | ||
2327 | 620 | g_object_ref (document); | ||
2328 | 621 | if (priv->document) | ||
2329 | 622 | g_object_unref (document); | ||
2330 | 623 | priv->document = document; | ||
2331 | 624 | |||
2332 | 625 | view_load_page (view); | ||
2333 | 626 | } | ||
2334 | 627 | |||
2335 | 628 | YelpDocument * | ||
2336 | 629 | yelp_view_get_document (YelpView *view) | ||
2337 | 630 | { | ||
2338 | 631 | YelpViewPrivate *priv = GET_PRIV (view); | ||
2339 | 632 | return priv->document; | ||
2340 | 633 | } | ||
2341 | 634 | |||
2342 | 635 | GtkActionGroup * | ||
2343 | 636 | yelp_view_get_action_group (YelpView *view) | ||
2344 | 637 | { | ||
2345 | 638 | YelpViewPrivate *priv = GET_PRIV (view); | ||
2346 | 639 | return priv->action_group; | ||
2347 | 640 | } | ||
2348 | 641 | |||
2349 | 642 | /******************************************************************************/ | ||
2350 | 643 | |||
2351 | 644 | void | ||
2352 | 645 | yelp_view_add_link_action (YelpView *view, | ||
2353 | 646 | GtkAction *action, | ||
2354 | 647 | YelpViewActionValidFunc func, | ||
2355 | 648 | gpointer data) | ||
2356 | 649 | { | ||
2357 | 650 | YelpActionEntry *entry; | ||
2358 | 651 | YelpViewPrivate *priv = GET_PRIV (view); | ||
2359 | 652 | |||
2360 | 653 | entry = g_new0 (YelpActionEntry, 1); | ||
2361 | 654 | entry->action = g_object_ref (action); | ||
2362 | 655 | entry->func = func; | ||
2363 | 656 | entry->data = data; | ||
2364 | 657 | |||
2365 | 658 | priv->link_actions = g_slist_append (priv->link_actions, entry); | ||
2366 | 659 | } | ||
2367 | 660 | |||
2368 | 661 | YelpUri * | ||
2369 | 662 | yelp_view_get_active_link_uri (YelpView *view) | ||
2370 | 663 | { | ||
2371 | 664 | YelpViewPrivate *priv = GET_PRIV (view); | ||
2372 | 665 | YelpUri *uri; | ||
2373 | 666 | |||
2374 | 667 | if (g_str_has_prefix (priv->popup_link_uri, BOGUS_URI)) | ||
2375 | 668 | uri = yelp_uri_new_relative (priv->uri, priv->popup_link_uri + BOGUS_URI_LEN); | ||
2376 | 669 | else | ||
2377 | 670 | uri = yelp_uri_new_relative (priv->uri, priv->popup_link_uri); | ||
2378 | 671 | |||
2379 | 672 | return uri; | ||
2380 | 673 | } | ||
2381 | 674 | |||
2382 | 675 | gchar * | ||
2383 | 676 | yelp_view_get_active_link_text (YelpView *view) | ||
2384 | 677 | { | ||
2385 | 678 | YelpViewPrivate *priv = GET_PRIV (view); | ||
2386 | 679 | return g_strdup (priv->popup_link_text); | ||
2387 | 680 | } | ||
2388 | 681 | |||
2389 | 682 | /******************************************************************************/ | ||
2390 | 683 | |||
2391 | 684 | static gboolean | ||
2392 | 685 | view_external_uri (YelpView *view, | ||
2393 | 686 | YelpUri *uri) | ||
2394 | 687 | { | ||
2395 | 688 | gchar *struri = yelp_uri_get_canonical_uri (uri); | ||
2396 | 689 | g_app_info_launch_default_for_uri (struri, NULL, NULL); | ||
2397 | 690 | g_free (struri); | ||
2398 | 691 | return TRUE; | ||
2399 | 692 | } | ||
2400 | 693 | |||
2401 | 694 | typedef struct _YelpInstallInfo YelpInstallInfo; | ||
2402 | 695 | struct _YelpInstallInfo { | ||
2403 | 696 | YelpView *view; | ||
2404 | 697 | gchar *uri; | ||
2405 | 698 | }; | ||
2406 | 699 | |||
2407 | 700 | static void | ||
2408 | 701 | yelp_install_info_free (YelpInstallInfo *info) | ||
2409 | 702 | { | ||
2410 | 703 | g_object_unref (info->view); | ||
2411 | 704 | if (info->uri) | ||
2412 | 705 | g_free (info->uri); | ||
2413 | 706 | g_free (info); | ||
2414 | 707 | } | ||
2415 | 708 | |||
2416 | 709 | static void | ||
2417 | 710 | view_install_installed (GDBusConnection *connection, | ||
2418 | 711 | GAsyncResult *res, | ||
2419 | 712 | YelpInstallInfo *info) | ||
2420 | 713 | { | ||
2421 | 714 | GError *error = NULL; | ||
2422 | 715 | g_dbus_connection_call_finish (connection, res, &error); | ||
2423 | 716 | if (error) { | ||
2424 | 717 | const gchar *err = NULL; | ||
2425 | 718 | if (error->domain == G_DBUS_ERROR) { | ||
2426 | 719 | if (error->code == G_DBUS_ERROR_SERVICE_UNKNOWN) | ||
2427 | 720 | err = _("You do not have PackageKit. Package install links require PackageKit."); | ||
2428 | 721 | else | ||
2429 | 722 | err = error->message; | ||
2430 | 723 | } | ||
2431 | 724 | if (err != NULL) { | ||
2432 | 725 | GtkWidget *dialog = gtk_message_dialog_new (NULL, 0, | ||
2433 | 726 | GTK_MESSAGE_ERROR, | ||
2434 | 727 | GTK_BUTTONS_CLOSE, | ||
2435 | 728 | "%s", err); | ||
2436 | 729 | gtk_dialog_run ((GtkDialog *) dialog); | ||
2437 | 730 | gtk_widget_destroy (dialog); | ||
2438 | 731 | } | ||
2439 | 732 | g_error_free (error); | ||
2440 | 733 | } | ||
2441 | 734 | else if (info->uri) { | ||
2442 | 735 | gchar *struri, *docuri; | ||
2443 | 736 | YelpViewPrivate *priv = GET_PRIV (info->view); | ||
2444 | 737 | docuri = yelp_uri_get_document_uri (priv->uri); | ||
2445 | 738 | if (g_str_equal (docuri, info->uri)) { | ||
2446 | 739 | struri = yelp_uri_get_canonical_uri (priv->uri); | ||
2447 | 740 | yelp_view_load (info->view, struri); | ||
2448 | 741 | g_free (struri); | ||
2449 | 742 | } | ||
2450 | 743 | g_free (docuri); | ||
2451 | 744 | } | ||
2452 | 745 | |||
2453 | 746 | yelp_install_info_free (info); | ||
2454 | 747 | } | ||
2455 | 748 | |||
2456 | 749 | static void | ||
2457 | 750 | view_install_uri (YelpView *view, | ||
2458 | 751 | const gchar *uri) | ||
2459 | 752 | { | ||
2460 | 753 | GDBusConnection *connection; | ||
2461 | 754 | GError *error; | ||
2462 | 755 | gboolean help = FALSE, ghelp = FALSE; | ||
2463 | 756 | GVariantBuilder *strv; | ||
2464 | 757 | YelpInstallInfo *info; | ||
2465 | 758 | guint32 xid = 0; | ||
2466 | 759 | YelpViewPrivate *priv = GET_PRIV (view); | ||
2467 | 760 | GtkWidget *gtkwin; | ||
2468 | 761 | GdkWindow *gdkwin; | ||
2469 | 762 | /* do not free */ | ||
2470 | 763 | gchar *pkg, *confirm_search; | ||
2471 | 764 | |||
2472 | 765 | if (g_str_has_prefix (uri, "install-help:")) { | ||
2473 | 766 | help = TRUE; | ||
2474 | 767 | pkg = (gchar *) uri + 13; | ||
2475 | 768 | } | ||
2476 | 769 | else if (g_str_has_prefix (uri, "install-ghelp:")) { | ||
2477 | 770 | ghelp = TRUE; | ||
2478 | 771 | pkg = (gchar *) uri + 14; | ||
2479 | 772 | } | ||
2480 | 773 | else if (g_str_has_prefix (uri, "install:")) { | ||
2481 | 774 | pkg = (gchar *) uri + 8; | ||
2482 | 775 | } | ||
2483 | 776 | |||
2484 | 777 | connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); | ||
2485 | 778 | if (connection == NULL) { | ||
2486 | 779 | g_warning ("Unable to connect to dbus: %s", error->message); | ||
2487 | 780 | g_error_free (error); | ||
2488 | 781 | return; | ||
2489 | 782 | } | ||
2490 | 783 | |||
2491 | 784 | info = g_new0 (YelpInstallInfo, 1); | ||
2492 | 785 | info->view = g_object_ref (view); | ||
2493 | 786 | |||
2494 | 787 | gtkwin = gtk_widget_get_toplevel (GTK_WIDGET (view)); | ||
2495 | 788 | if (gtkwin != NULL && gtk_widget_is_toplevel (gtkwin)) { | ||
2496 | 789 | gdkwin = gtk_widget_get_window (gtkwin); | ||
2497 | 790 | if (gdkwin != NULL) | ||
2498 | 791 | xid = gdk_x11_window_get_xid (gdkwin); | ||
2499 | 792 | } | ||
2500 | 793 | |||
2501 | 794 | if (priv->state == YELP_VIEW_STATE_ERROR) | ||
2502 | 795 | confirm_search = "hide-confirm-search"; | ||
2503 | 796 | else | ||
2504 | 797 | confirm_search = ""; | ||
2505 | 798 | |||
2506 | 799 | if (help || ghelp) { | ||
2507 | 800 | const gchar * const *datadirs = g_get_system_data_dirs (); | ||
2508 | 801 | gint datadirs_i; | ||
2509 | 802 | gchar *docbook, *fname; | ||
2510 | 803 | docbook = g_strconcat (pkg, ".xml", NULL); | ||
2511 | 804 | strv = g_variant_builder_new (G_VARIANT_TYPE ("as")); | ||
2512 | 805 | for (datadirs_i = 0; datadirs[datadirs_i] != NULL; datadirs_i++) { | ||
2513 | 806 | if (ghelp) { | ||
2514 | 807 | fname = g_build_filename (datadirs[datadirs_i], "gnome", "help", | ||
2515 | 808 | pkg, "C", "index.page", NULL); | ||
2516 | 809 | g_variant_builder_add (strv, "s", fname); | ||
2517 | 810 | g_free (fname); | ||
2518 | 811 | fname = g_build_filename (datadirs[datadirs_i], "gnome", "help", | ||
2519 | 812 | pkg, "C", docbook, NULL); | ||
2520 | 813 | g_variant_builder_add (strv, "s", fname); | ||
2521 | 814 | g_free (fname); | ||
2522 | 815 | } | ||
2523 | 816 | else { | ||
2524 | 817 | fname = g_build_filename (datadirs[datadirs_i], "help", "C", | ||
2525 | 818 | pkg, "index.page", NULL); | ||
2526 | 819 | g_variant_builder_add (strv, "s", fname); | ||
2527 | 820 | g_free (fname); | ||
2528 | 821 | fname = g_build_filename (datadirs[datadirs_i], "help", "C", | ||
2529 | 822 | pkg, "index.docbook", NULL); | ||
2530 | 823 | g_variant_builder_add (strv, "s", fname); | ||
2531 | 824 | g_free (fname); | ||
2532 | 825 | } | ||
2533 | 826 | } | ||
2534 | 827 | g_free (docbook); | ||
2535 | 828 | info->uri = g_strconcat (ghelp ? "ghelp:" : "help:", pkg, NULL); | ||
2536 | 829 | g_dbus_connection_call (connection, | ||
2537 | 830 | "org.freedesktop.PackageKit", | ||
2538 | 831 | "/org/freedesktop/PackageKit", | ||
2539 | 832 | "org.freedesktop.PackageKit.Modify", | ||
2540 | 833 | "InstallProvideFiles", | ||
2541 | 834 | g_variant_new ("(uass)", xid, strv, confirm_search), | ||
2542 | 835 | NULL, | ||
2543 | 836 | G_DBUS_CALL_FLAGS_NONE, | ||
2544 | 837 | G_MAXINT, NULL, | ||
2545 | 838 | (GAsyncReadyCallback) view_install_installed, | ||
2546 | 839 | info); | ||
2547 | 840 | g_variant_builder_unref (strv); | ||
2548 | 841 | } | ||
2549 | 842 | else { | ||
2550 | 843 | gchar **pkgs; | ||
2551 | 844 | gint i; | ||
2552 | 845 | strv = g_variant_builder_new (G_VARIANT_TYPE ("as")); | ||
2553 | 846 | pkgs = g_strsplit (pkg, ",", 0); | ||
2554 | 847 | for (i = 0; pkgs[i]; i++) | ||
2555 | 848 | g_variant_builder_add (strv, "s", pkgs[i]); | ||
2556 | 849 | g_strfreev (pkgs); | ||
2557 | 850 | g_dbus_connection_call (connection, | ||
2558 | 851 | "org.freedesktop.PackageKit", | ||
2559 | 852 | "/org/freedesktop/PackageKit", | ||
2560 | 853 | "org.freedesktop.PackageKit.Modify", | ||
2561 | 854 | "InstallPackageNames", | ||
2562 | 855 | g_variant_new ("(uass)", xid, strv, confirm_search), | ||
2563 | 856 | NULL, | ||
2564 | 857 | G_DBUS_CALL_FLAGS_NONE, | ||
2565 | 858 | G_MAXINT, NULL, | ||
2566 | 859 | (GAsyncReadyCallback) view_install_installed, | ||
2567 | 860 | info); | ||
2568 | 861 | g_variant_builder_unref (strv); | ||
2569 | 862 | } | ||
2570 | 863 | |||
2571 | 864 | g_object_unref (connection); | ||
2572 | 865 | } | ||
2573 | 866 | |||
2574 | 867 | static void | ||
2575 | 868 | view_scrolled (GtkAdjustment *adjustment, | ||
2576 | 869 | YelpView *view) | ||
2577 | 870 | { | ||
2578 | 871 | YelpViewPrivate *priv = GET_PRIV (view); | ||
2579 | 872 | if (priv->back_cur == NULL || priv->back_cur->data == NULL) | ||
2580 | 873 | return; | ||
2581 | 874 | if (adjustment == priv->vadjustment) | ||
2582 | 875 | ((YelpBackEntry *) priv->back_cur->data)->vadj = gtk_adjustment_get_value (adjustment); | ||
2583 | 876 | else if (adjustment = priv->hadjustment) | ||
2584 | 877 | ((YelpBackEntry *) priv->back_cur->data)->hadj = gtk_adjustment_get_value (adjustment); | ||
2585 | 878 | } | ||
2586 | 879 | |||
2587 | 880 | static void | ||
2588 | 881 | view_set_hadjustment (YelpView *view, | ||
2589 | 882 | GParamSpec *pspec, | ||
2590 | 883 | gpointer data) | ||
2591 | 884 | { | ||
2592 | 885 | YelpViewPrivate *priv = GET_PRIV (view); | ||
2593 | 886 | priv->hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (view)); | ||
2594 | 887 | if (priv->hadjuster > 0) | ||
2595 | 888 | g_source_remove (priv->hadjuster); | ||
2596 | 889 | priv->hadjuster = 0; | ||
2597 | 890 | if (priv->hadjustment) | ||
2598 | 891 | priv->hadjuster = g_signal_connect (priv->hadjustment, "value-changed", | ||
2599 | 892 | G_CALLBACK (view_scrolled), view); | ||
2600 | 893 | } | ||
2601 | 894 | |||
2602 | 895 | static void | ||
2603 | 896 | view_set_vadjustment (YelpView *view, | ||
2604 | 897 | GParamSpec *pspec, | ||
2605 | 898 | gpointer data) | ||
2606 | 899 | { | ||
2607 | 900 | YelpViewPrivate *priv = GET_PRIV (view); | ||
2608 | 901 | priv->vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (view)); | ||
2609 | 902 | if (priv->vadjuster > 0) | ||
2610 | 903 | g_source_remove (priv->vadjuster); | ||
2611 | 904 | priv->vadjuster = 0; | ||
2612 | 905 | if (priv->vadjustment) | ||
2613 | 906 | priv->vadjuster = g_signal_connect (priv->vadjustment, "value-changed", | ||
2614 | 907 | G_CALLBACK (view_scrolled), view); | ||
2615 | 908 | } | ||
2616 | 909 | |||
2617 | 910 | static void | ||
2618 | 911 | popup_open_link (GtkMenuItem *item, | ||
2619 | 912 | YelpView *view) | ||
2620 | 913 | { | ||
2621 | 914 | YelpViewPrivate *priv = GET_PRIV (view); | ||
2622 | 915 | YelpUri *uri; | ||
2623 | 916 | |||
2624 | 917 | if (g_str_has_prefix (priv->popup_link_uri, BOGUS_URI)) | ||
2625 | 918 | uri = yelp_uri_new_relative (priv->uri, priv->popup_link_uri + BOGUS_URI_LEN); | ||
2626 | 919 | else | ||
2627 | 920 | uri = yelp_uri_new_relative (priv->uri, priv->popup_link_uri); | ||
2628 | 921 | |||
2629 | 922 | yelp_view_load_uri (view, uri); | ||
2630 | 923 | g_object_unref (uri); | ||
2631 | 924 | |||
2632 | 925 | g_free (priv->popup_link_uri); | ||
2633 | 926 | priv->popup_link_uri = NULL; | ||
2634 | 927 | |||
2635 | 928 | g_free (priv->popup_link_text); | ||
2636 | 929 | priv->popup_link_text = NULL; | ||
2637 | 930 | } | ||
2638 | 931 | |||
2639 | 932 | static void | ||
2640 | 933 | popup_open_link_new (GtkMenuItem *item, | ||
2641 | 934 | YelpView *view) | ||
2642 | 935 | { | ||
2643 | 936 | YelpViewPrivate *priv = GET_PRIV (view); | ||
2644 | 937 | YelpUri *uri; | ||
2645 | 938 | |||
2646 | 939 | if (g_str_has_prefix (priv->popup_link_uri, BOGUS_URI)) | ||
2647 | 940 | uri = yelp_uri_new_relative (priv->uri, priv->popup_link_uri + BOGUS_URI_LEN); | ||
2648 | 941 | else | ||
2649 | 942 | uri = yelp_uri_new_relative (priv->uri, priv->popup_link_uri); | ||
2650 | 943 | |||
2651 | 944 | g_free (priv->popup_link_uri); | ||
2652 | 945 | priv->popup_link_uri = NULL; | ||
2653 | 946 | |||
2654 | 947 | g_free (priv->popup_link_text); | ||
2655 | 948 | priv->popup_link_text = NULL; | ||
2656 | 949 | |||
2657 | 950 | g_signal_emit (view, signals[NEW_VIEW_REQUESTED], 0, uri); | ||
2658 | 951 | g_object_unref (uri); | ||
2659 | 952 | } | ||
2660 | 953 | |||
2661 | 954 | static void | ||
2662 | 955 | popup_copy_link (GtkMenuItem *item, | ||
2663 | 956 | YelpView *view) | ||
2664 | 957 | { | ||
2665 | 958 | YelpViewPrivate *priv = GET_PRIV (view); | ||
2666 | 959 | gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (view), GDK_SELECTION_CLIPBOARD), | ||
2667 | 960 | priv->popup_link_uri, | ||
2668 | 961 | -1); | ||
2669 | 962 | } | ||
2670 | 963 | |||
2671 | 964 | typedef struct _YelpSaveData YelpSaveData; | ||
2672 | 965 | struct _YelpSaveData { | ||
2673 | 966 | GFile *orig; | ||
2674 | 967 | GFile *dest; | ||
2675 | 968 | YelpView *view; | ||
2676 | 969 | GtkWindow *window; | ||
2677 | 970 | }; | ||
2678 | 971 | |||
2679 | 972 | static void | ||
2680 | 973 | file_copied (GFile *file, | ||
2681 | 974 | GAsyncResult *res, | ||
2682 | 975 | YelpSaveData *data) | ||
2683 | 976 | { | ||
2684 | 977 | GError *error = NULL; | ||
2685 | 978 | if (!g_file_copy_finish (file, res, &error)) { | ||
2686 | 979 | GtkWidget *dialog = gtk_message_dialog_new (gtk_widget_get_visible (GTK_WIDGET (data->window)) ? data->window : NULL, | ||
2687 | 980 | GTK_DIALOG_DESTROY_WITH_PARENT, | ||
2688 | 981 | GTK_MESSAGE_ERROR, | ||
2689 | 982 | GTK_BUTTONS_OK, | ||
2690 | 983 | "%s", error->message); | ||
2691 | 984 | gtk_dialog_run (GTK_DIALOG (dialog)); | ||
2692 | 985 | gtk_widget_destroy (dialog); | ||
2693 | 986 | } | ||
2694 | 987 | g_object_unref (data->orig); | ||
2695 | 988 | g_object_unref (data->dest); | ||
2696 | 989 | g_object_unref (data->view); | ||
2697 | 990 | g_object_unref (data->window); | ||
2698 | 991 | } | ||
2699 | 992 | |||
2700 | 993 | static void | ||
2701 | 994 | popup_save_image (GtkMenuItem *item, | ||
2702 | 995 | YelpView *view) | ||
2703 | 996 | { | ||
2704 | 997 | YelpSaveData *data; | ||
2705 | 998 | GtkWidget *dialog, *window; | ||
2706 | 999 | gchar *basename; | ||
2707 | 1000 | gint res; | ||
2708 | 1001 | YelpViewPrivate *priv = GET_PRIV (view); | ||
2709 | 1002 | |||
2710 | 1003 | for (window = gtk_widget_get_parent (GTK_WIDGET (view)); | ||
2711 | 1004 | window && !GTK_IS_WINDOW (window); | ||
2712 | 1005 | window = gtk_widget_get_parent (window)); | ||
2713 | 1006 | |||
2714 | 1007 | data = g_new0 (YelpSaveData, 1); | ||
2715 | 1008 | data->orig = g_file_new_for_uri (priv->popup_image_uri); | ||
2716 | 1009 | data->view = g_object_ref (view); | ||
2717 | 1010 | data->window = g_object_ref (window); | ||
2718 | 1011 | g_free (priv->popup_image_uri); | ||
2719 | 1012 | priv->popup_image_uri = NULL; | ||
2720 | 1013 | |||
2721 | 1014 | dialog = gtk_file_chooser_dialog_new (_("Save Image"), | ||
2722 | 1015 | GTK_WINDOW (window), | ||
2723 | 1016 | GTK_FILE_CHOOSER_ACTION_SAVE, | ||
2724 | 1017 | GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | ||
2725 | 1018 | GTK_STOCK_SAVE, GTK_RESPONSE_OK, | ||
2726 | 1019 | NULL); | ||
2727 | 1020 | gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE); | ||
2728 | 1021 | basename = g_file_get_basename (data->orig); | ||
2729 | 1022 | gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), basename); | ||
2730 | 1023 | g_free (basename); | ||
2731 | 1024 | gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), | ||
2732 | 1025 | g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP)); | ||
2733 | 1026 | |||
2734 | 1027 | res = gtk_dialog_run (GTK_DIALOG (dialog)); | ||
2735 | 1028 | |||
2736 | 1029 | if (res == GTK_RESPONSE_OK) { | ||
2737 | 1030 | data->dest = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog)); | ||
2738 | 1031 | g_file_copy_async (data->orig, data->dest, | ||
2739 | 1032 | G_FILE_COPY_OVERWRITE, | ||
2740 | 1033 | G_PRIORITY_DEFAULT, | ||
2741 | 1034 | NULL, NULL, NULL, | ||
2742 | 1035 | (GAsyncReadyCallback) file_copied, | ||
2743 | 1036 | data); | ||
2744 | 1037 | } | ||
2745 | 1038 | else { | ||
2746 | 1039 | g_object_unref (data->orig); | ||
2747 | 1040 | g_object_unref (data->view); | ||
2748 | 1041 | g_object_unref (data->window); | ||
2749 | 1042 | g_free (data); | ||
2750 | 1043 | } | ||
2751 | 1044 | |||
2752 | 1045 | gtk_widget_destroy (dialog); | ||
2753 | 1046 | } | ||
2754 | 1047 | |||
2755 | 1048 | static void | ||
2756 | 1049 | popup_send_image (GtkMenuItem *item, | ||
2757 | 1050 | YelpView *view) | ||
2758 | 1051 | { | ||
2759 | 1052 | gchar *command; | ||
2760 | 1053 | GAppInfo *app; | ||
2761 | 1054 | GAppLaunchContext *context; | ||
2762 | 1055 | GError *error = NULL; | ||
2763 | 1056 | YelpViewPrivate *priv = GET_PRIV (view); | ||
2764 | 1057 | |||
2765 | 1058 | command = g_strdup_printf ("%s %s", nautilus_sendto, priv->popup_image_uri); | ||
2766 | 1059 | context = (GAppLaunchContext *) gdk_display_get_app_launch_context (gtk_widget_get_display (GTK_WIDGET (item))); | ||
2767 | 1060 | |||
2768 | 1061 | app = g_app_info_create_from_commandline (command, NULL, 0, &error); | ||
2769 | 1062 | if (app) { | ||
2770 | 1063 | g_app_info_launch (app, NULL, context, &error); | ||
2771 | 1064 | g_object_unref (app); | ||
2772 | 1065 | } | ||
2773 | 1066 | |||
2774 | 1067 | if (error) { | ||
2775 | 1068 | g_debug ("Could not launch nautilus-sendto: %s", error->message); | ||
2776 | 1069 | g_error_free (error); | ||
2777 | 1070 | } | ||
2778 | 1071 | |||
2779 | 1072 | g_object_unref (context); | ||
2780 | 1073 | g_free (command); | ||
2781 | 1074 | g_free (priv->popup_image_uri); | ||
2782 | 1075 | priv->popup_image_uri = NULL; | ||
2783 | 1076 | } | ||
2784 | 1077 | |||
2785 | 1078 | static void | ||
2786 | 1079 | popup_copy_code (GtkMenuItem *item, | ||
2787 | 1080 | YelpView *view) | ||
2788 | 1081 | { | ||
2789 | 1082 | YelpViewPrivate *priv = GET_PRIV (view); | ||
2790 | 1083 | GtkClipboard *clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); | ||
2791 | 1084 | gchar *content = webkit_dom_node_get_text_content (priv->popup_code_node); | ||
2792 | 1085 | gtk_clipboard_set_text (clipboard, content, -1); | ||
2793 | 1086 | g_free (content); | ||
2794 | 1087 | } | ||
2795 | 1088 | |||
2796 | 1089 | static void | ||
2797 | 1090 | popup_save_code (GtkMenuItem *item, | ||
2798 | 1091 | YelpView *view) | ||
2799 | 1092 | { | ||
2800 | 1093 | YelpViewPrivate *priv = GET_PRIV (view); | ||
2801 | 1094 | GtkWidget *dialog, *window; | ||
2802 | 1095 | gint res; | ||
2803 | 1096 | |||
2804 | 1097 | g_free (priv->popup_code_text); | ||
2805 | 1098 | priv->popup_code_text = webkit_dom_node_get_text_content (priv->popup_code_node); | ||
2806 | 1099 | if (!g_str_has_suffix (priv->popup_code_text, "\n")) { | ||
2807 | 1100 | gchar *tmp = g_strconcat (priv->popup_code_text, "\n", NULL); | ||
2808 | 1101 | g_free (priv->popup_code_text); | ||
2809 | 1102 | priv->popup_code_text = tmp; | ||
2810 | 1103 | } | ||
2811 | 1104 | |||
2812 | 1105 | for (window = gtk_widget_get_parent (GTK_WIDGET (view)); | ||
2813 | 1106 | window && !GTK_IS_WINDOW (window); | ||
2814 | 1107 | window = gtk_widget_get_parent (window)); | ||
2815 | 1108 | |||
2816 | 1109 | dialog = gtk_file_chooser_dialog_new (_("Save Code"), | ||
2817 | 1110 | GTK_WINDOW (window), | ||
2818 | 1111 | GTK_FILE_CHOOSER_ACTION_SAVE, | ||
2819 | 1112 | GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | ||
2820 | 1113 | GTK_STOCK_SAVE, GTK_RESPONSE_OK, | ||
2821 | 1114 | NULL); | ||
2822 | 1115 | gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE); | ||
2823 | 1116 | if (priv->popup_code_title) { | ||
2824 | 1117 | gchar *filename = webkit_dom_node_get_text_content (priv->popup_code_title); | ||
2825 | 1118 | gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename); | ||
2826 | 1119 | g_free (filename); | ||
2827 | 1120 | } | ||
2828 | 1121 | gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), | ||
2829 | 1122 | g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS)); | ||
2830 | 1123 | |||
2831 | 1124 | res = gtk_dialog_run (GTK_DIALOG (dialog)); | ||
2832 | 1125 | |||
2833 | 1126 | if (res == GTK_RESPONSE_OK) { | ||
2834 | 1127 | GError *error = NULL; | ||
2835 | 1128 | GFile *file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog)); | ||
2836 | 1129 | GFileOutputStream *stream = g_file_replace (file, NULL, FALSE, | ||
2837 | 1130 | G_FILE_CREATE_NONE, | ||
2838 | 1131 | NULL, | ||
2839 | 1132 | &error); | ||
2840 | 1133 | if (stream == NULL) { | ||
2841 | 1134 | GtkWidget *dialog = gtk_message_dialog_new (gtk_widget_get_visible (window) ? GTK_WINDOW (window) : NULL, | ||
2842 | 1135 | GTK_DIALOG_DESTROY_WITH_PARENT, | ||
2843 | 1136 | GTK_MESSAGE_ERROR, | ||
2844 | 1137 | GTK_BUTTONS_OK, | ||
2845 | 1138 | "%s", error->message); | ||
2846 | 1139 | gtk_dialog_run (GTK_DIALOG (dialog)); | ||
2847 | 1140 | gtk_widget_destroy (dialog); | ||
2848 | 1141 | g_error_free (error); | ||
2849 | 1142 | } | ||
2850 | 1143 | else { | ||
2851 | 1144 | /* FIXME: we should do this async */ | ||
2852 | 1145 | GDataOutputStream *datastream = g_data_output_stream_new (G_OUTPUT_STREAM (stream)); | ||
2853 | 1146 | if (!g_data_output_stream_put_string (datastream, priv->popup_code_text, NULL, &error)) { | ||
2854 | 1147 | GtkWidget *dialog = gtk_message_dialog_new (gtk_widget_get_visible (window) ? GTK_WINDOW (window) : NULL, | ||
2855 | 1148 | GTK_DIALOG_DESTROY_WITH_PARENT, | ||
2856 | 1149 | GTK_MESSAGE_ERROR, | ||
2857 | 1150 | GTK_BUTTONS_OK, | ||
2858 | 1151 | "%s", error->message); | ||
2859 | 1152 | gtk_dialog_run (GTK_DIALOG (dialog)); | ||
2860 | 1153 | gtk_widget_destroy (dialog); | ||
2861 | 1154 | g_error_free (error); | ||
2862 | 1155 | } | ||
2863 | 1156 | g_object_unref (datastream); | ||
2864 | 1157 | } | ||
2865 | 1158 | g_object_unref (file); | ||
2866 | 1159 | } | ||
2867 | 1160 | |||
2868 | 1161 | priv->popup_code_node = NULL; | ||
2869 | 1162 | priv->popup_code_title = NULL; | ||
2870 | 1163 | g_free (priv->popup_code_text); | ||
2871 | 1164 | priv->popup_code_text = NULL; | ||
2872 | 1165 | |||
2873 | 1166 | gtk_widget_destroy (dialog); | ||
2874 | 1167 | } | ||
2875 | 1168 | |||
2876 | 1169 | static void | ||
2877 | 1170 | view_populate_popup (YelpView *view, | ||
2878 | 1171 | GtkMenu *menu, | ||
2879 | 1172 | gpointer data) | ||
2880 | 1173 | { | ||
2881 | 1174 | WebKitHitTestResult *result; | ||
2882 | 1175 | WebKitHitTestResultContext context; | ||
2883 | 1176 | GdkEvent *event; | ||
2884 | 1177 | YelpViewPrivate *priv = GET_PRIV (view); | ||
2885 | 1178 | GList *children; | ||
2886 | 1179 | GtkWidget *item; | ||
2887 | 1180 | WebKitDOMNode *node, *cur, *link_node = NULL, *code_node = NULL, *code_title_node = NULL; | ||
2888 | 1181 | |||
2889 | 1182 | children = gtk_container_get_children (GTK_CONTAINER (menu)); | ||
2890 | 1183 | while (children) { | ||
2891 | 1184 | gtk_container_remove (GTK_CONTAINER (menu), | ||
2892 | 1185 | GTK_WIDGET (children->data)); | ||
2893 | 1186 | children = children->next; | ||
2894 | 1187 | } | ||
2895 | 1188 | g_list_free (children); | ||
2896 | 1189 | |||
2897 | 1190 | event = gtk_get_current_event (); | ||
2898 | 1191 | |||
2899 | 1192 | result = webkit_web_view_get_hit_test_result (WEBKIT_WEB_VIEW (view), (GdkEventButton *) event); | ||
2900 | 1193 | g_object_get (result, | ||
2901 | 1194 | "context", &context, | ||
2902 | 1195 | "inner-node", &node, | ||
2903 | 1196 | NULL); | ||
2904 | 1197 | for (cur = node; cur != NULL; cur = webkit_dom_node_get_parent_node (cur)) { | ||
2905 | 1198 | if (WEBKIT_DOM_IS_ELEMENT (cur) && | ||
2906 | 1199 | webkit_dom_element_webkit_matches_selector ((WebKitDOMElement *) cur, | ||
2907 | 1200 | "a", NULL)) | ||
2908 | 1201 | link_node = cur; | ||
2909 | 1202 | |||
2910 | 1203 | if (WEBKIT_DOM_IS_ELEMENT (cur) && | ||
2911 | 1204 | webkit_dom_element_webkit_matches_selector ((WebKitDOMElement *) cur, | ||
2912 | 1205 | "div.code", NULL)) { | ||
2913 | 1206 | WebKitDOMNode *title; | ||
2914 | 1207 | code_node = (WebKitDOMNode *) | ||
2915 | 1208 | webkit_dom_element_query_selector ((WebKitDOMElement *) cur, | ||
2916 | 1209 | "pre.contents", NULL); | ||
2917 | 1210 | title = webkit_dom_node_get_parent_node (cur); | ||
2918 | 1211 | if (title != NULL && WEBKIT_DOM_IS_ELEMENT (title) && | ||
2919 | 1212 | webkit_dom_element_webkit_matches_selector ((WebKitDOMElement *) title, | ||
2920 | 1213 | "div.contents", NULL)) { | ||
2921 | 1214 | title = webkit_dom_node_get_previous_sibling (title); | ||
2922 | 1215 | if (title != NULL && WEBKIT_DOM_IS_ELEMENT (title) && | ||
2923 | 1216 | webkit_dom_element_webkit_matches_selector ((WebKitDOMElement *) title, | ||
2924 | 1217 | "div.title", NULL)) { | ||
2925 | 1218 | code_title_node = title; | ||
2926 | 1219 | } | ||
2927 | 1220 | } | ||
2928 | 1221 | } | ||
2929 | 1222 | } | ||
2930 | 1223 | |||
2931 | 1224 | if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK) { | ||
2932 | 1225 | gchar *uri; | ||
2933 | 1226 | g_object_get (result, "link-uri", &uri, NULL); | ||
2934 | 1227 | g_free (priv->popup_link_uri); | ||
2935 | 1228 | priv->popup_link_uri = uri; | ||
2936 | 1229 | |||
2937 | 1230 | g_free (priv->popup_link_text); | ||
2938 | 1231 | priv->popup_link_text = NULL; | ||
2939 | 1232 | if (link_node != NULL) { | ||
2940 | 1233 | WebKitDOMNode *child; | ||
2941 | 1234 | gchar *tmp; | ||
2942 | 1235 | gint i, tmpi; | ||
2943 | 1236 | gboolean ws; | ||
2944 | 1237 | |||
2945 | 1238 | child = (WebKitDOMNode *) | ||
2946 | 1239 | webkit_dom_element_query_selector (WEBKIT_DOM_ELEMENT (link_node), | ||
2947 | 1240 | "span.title", NULL); | ||
2948 | 1241 | if (child != NULL) | ||
2949 | 1242 | priv->popup_link_text = webkit_dom_node_get_text_content (child); | ||
2950 | 1243 | |||
2951 | 1244 | if (priv->popup_link_text == NULL) | ||
2952 | 1245 | priv->popup_link_text = webkit_dom_node_get_text_content (link_node); | ||
2953 | 1246 | |||
2954 | 1247 | tmp = g_new0 (gchar, strlen(priv->popup_link_text) + 1); | ||
2955 | 1248 | ws = FALSE; | ||
2956 | 1249 | for (i = 0, tmpi = 0; priv->popup_link_text[i] != '\0'; i++) { | ||
2957 | 1250 | if (priv->popup_link_text[i] == ' ' || priv->popup_link_text[i] == '\n') { | ||
2958 | 1251 | if (!ws) { | ||
2959 | 1252 | tmp[tmpi] = ' '; | ||
2960 | 1253 | tmpi++; | ||
2961 | 1254 | ws = TRUE; | ||
2962 | 1255 | } | ||
2963 | 1256 | } | ||
2964 | 1257 | else { | ||
2965 | 1258 | tmp[tmpi] = priv->popup_link_text[i]; | ||
2966 | 1259 | tmpi++; | ||
2967 | 1260 | ws = FALSE; | ||
2968 | 1261 | } | ||
2969 | 1262 | } | ||
2970 | 1263 | tmp[tmpi] = '\0'; | ||
2971 | 1264 | g_free (priv->popup_link_text); | ||
2972 | 1265 | priv->popup_link_text = tmp; | ||
2973 | 1266 | } | ||
2974 | 1267 | else { | ||
2975 | 1268 | priv->popup_link_text = g_strdup (uri); | ||
2976 | 1269 | } | ||
2977 | 1270 | |||
2978 | 1271 | if (g_str_has_prefix (priv->popup_link_uri, "mailto:")) { | ||
2979 | 1272 | gchar *label = g_strdup_printf (_("Send email to %s"), | ||
2980 | 1273 | priv->popup_link_uri + 7); | ||
2981 | 1274 | /* Not using a mnemonic because underscores are common in email | ||
2982 | 1275 | * addresses, and we'd have to escape them. There doesn't seem | ||
2983 | 1276 | * to be a quick GTK+ function for this. In practice, there will | ||
2984 | 1277 | * probably only be one menu item for mailto link popups anyway, | ||
2985 | 1278 | * so the mnemonic's not that big of a deal. | ||
2986 | 1279 | */ | ||
2987 | 1280 | item = gtk_menu_item_new_with_label (label); | ||
2988 | 1281 | g_signal_connect (item, "activate", | ||
2989 | 1282 | G_CALLBACK (popup_open_link), view); | ||
2990 | 1283 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); | ||
2991 | 1284 | g_free (label); | ||
2992 | 1285 | } | ||
2993 | 1286 | else if (g_str_has_prefix (priv->popup_link_uri, "install:")) { | ||
2994 | 1287 | item = gtk_menu_item_new_with_mnemonic (_("_Install Packages")); | ||
2995 | 1288 | g_signal_connect (item, "activate", | ||
2996 | 1289 | G_CALLBACK (popup_open_link), view); | ||
2997 | 1290 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); | ||
2998 | 1291 | } | ||
2999 | 1292 | else { | ||
3000 | 1293 | GSList *cur; | ||
3001 | 1294 | |||
3002 | 1295 | item = gtk_menu_item_new_with_mnemonic (_("_Open Link")); | ||
3003 | 1296 | g_signal_connect (item, "activate", | ||
3004 | 1297 | G_CALLBACK (popup_open_link), view); | ||
3005 | 1298 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); | ||
3006 | 1299 | |||
3007 | 1300 | if (g_str_has_prefix (priv->popup_link_uri, "http://") || | ||
3008 | 1301 | g_str_has_prefix (priv->popup_link_uri, "https://")) { | ||
3009 | 1302 | item = gtk_menu_item_new_with_mnemonic (_("_Copy Link Location")); | ||
3010 | 1303 | g_signal_connect (item, "activate", | ||
3011 | 1304 | G_CALLBACK (popup_copy_link), view); | ||
3012 | 1305 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); | ||
3013 | 1306 | } | ||
3014 | 1307 | else { | ||
3015 | 1308 | item = gtk_menu_item_new_with_mnemonic (_("Open Link in New _Window")); | ||
3016 | 1309 | g_signal_connect (item, "activate", | ||
3017 | 1310 | G_CALLBACK (popup_open_link_new), view); | ||
3018 | 1311 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); | ||
3019 | 1312 | } | ||
3020 | 1313 | |||
3021 | 1314 | for (cur = priv->link_actions; cur != NULL; cur = cur->next) { | ||
3022 | 1315 | gboolean add; | ||
3023 | 1316 | YelpActionEntry *entry = (YelpActionEntry *) cur->data; | ||
3024 | 1317 | if (entry->func == NULL) | ||
3025 | 1318 | add = TRUE; | ||
3026 | 1319 | else | ||
3027 | 1320 | add = (* entry->func) (view, entry->action, | ||
3028 | 1321 | priv->popup_link_uri, | ||
3029 | 1322 | entry->data); | ||
3030 | 1323 | if (add) { | ||
3031 | 1324 | item = gtk_action_create_menu_item (entry->action); | ||
3032 | 1325 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); | ||
3033 | 1326 | } | ||
3034 | 1327 | } | ||
3035 | 1328 | } | ||
3036 | 1329 | } | ||
3037 | 1330 | else { | ||
3038 | 1331 | item = gtk_action_create_menu_item (gtk_action_group_get_action (priv->action_group, | ||
3039 | 1332 | "YelpViewGoBack")); | ||
3040 | 1333 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); | ||
3041 | 1334 | item = gtk_action_create_menu_item (gtk_action_group_get_action (priv->action_group, | ||
3042 | 1335 | "YelpViewGoForward")); | ||
3043 | 1336 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); | ||
3044 | 1337 | } | ||
3045 | 1338 | |||
3046 | 1339 | if ((context & WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE) || | ||
3047 | 1340 | (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA)) { | ||
3048 | 1341 | /* This doesn't currently work for video with automatic controls, | ||
3049 | 1342 | * because WebKit puts the hit test on the div with the controls. | ||
3050 | 1343 | */ | ||
3051 | 1344 | gboolean image = context & WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE; | ||
3052 | 1345 | gchar *uri; | ||
3053 | 1346 | g_object_get (result, image ? "image-uri" : "media-uri", &uri, NULL); | ||
3054 | 1347 | g_free (priv->popup_image_uri); | ||
3055 | 1348 | if (g_str_has_prefix (uri, BOGUS_URI)) { | ||
3056 | 1349 | priv->popup_image_uri = yelp_uri_locate_file_uri (priv->uri, uri + BOGUS_URI_LEN); | ||
3057 | 1350 | g_free (uri); | ||
3058 | 1351 | } | ||
3059 | 1352 | else { | ||
3060 | 1353 | priv->popup_image_uri = uri; | ||
3061 | 1354 | } | ||
3062 | 1355 | |||
3063 | 1356 | item = gtk_separator_menu_item_new (); | ||
3064 | 1357 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); | ||
3065 | 1358 | |||
3066 | 1359 | if (image) | ||
3067 | 1360 | item = gtk_menu_item_new_with_mnemonic (_("_Save Image As...")); | ||
3068 | 1361 | else | ||
3069 | 1362 | item = gtk_menu_item_new_with_mnemonic (_("_Save Video As...")); | ||
3070 | 1363 | g_signal_connect (item, "activate", | ||
3071 | 1364 | G_CALLBACK (popup_save_image), view); | ||
3072 | 1365 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); | ||
3073 | 1366 | |||
3074 | 1367 | if (nautilus_sendto) { | ||
3075 | 1368 | if (image) | ||
3076 | 1369 | item = gtk_menu_item_new_with_mnemonic (_("S_end Image To...")); | ||
3077 | 1370 | else | ||
3078 | 1371 | item = gtk_menu_item_new_with_mnemonic (_("S_end Video To...")); | ||
3079 | 1372 | g_signal_connect (item, "activate", | ||
3080 | 1373 | G_CALLBACK (popup_send_image), view); | ||
3081 | 1374 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); | ||
3082 | 1375 | } | ||
3083 | 1376 | } | ||
3084 | 1377 | |||
3085 | 1378 | if (context & WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION) { | ||
3086 | 1379 | item = gtk_separator_menu_item_new (); | ||
3087 | 1380 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); | ||
3088 | 1381 | |||
3089 | 1382 | item = gtk_menu_item_new_with_mnemonic (_("_Copy Text")); | ||
3090 | 1383 | g_signal_connect_swapped (item, "activate", | ||
3091 | 1384 | G_CALLBACK (webkit_web_view_copy_clipboard), view); | ||
3092 | 1385 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); | ||
3093 | 1386 | } | ||
3094 | 1387 | |||
3095 | 1388 | if (code_node != NULL) { | ||
3096 | 1389 | item = gtk_separator_menu_item_new (); | ||
3097 | 1390 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); | ||
3098 | 1391 | |||
3099 | 1392 | priv->popup_code_node = code_node; | ||
3100 | 1393 | priv->popup_code_title = code_title_node; | ||
3101 | 1394 | |||
3102 | 1395 | item = gtk_menu_item_new_with_mnemonic (_("C_opy Code Block")); | ||
3103 | 1396 | g_signal_connect (item, "activate", | ||
3104 | 1397 | G_CALLBACK (popup_copy_code), view); | ||
3105 | 1398 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); | ||
3106 | 1399 | |||
3107 | 1400 | item = gtk_menu_item_new_with_mnemonic (_("Save Code _Block As...")); | ||
3108 | 1401 | g_signal_connect (item, "activate", | ||
3109 | 1402 | G_CALLBACK (popup_save_code), view); | ||
3110 | 1403 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); | ||
3111 | 1404 | } | ||
3112 | 1405 | |||
3113 | 1406 | g_object_unref (result); | ||
3114 | 1407 | gdk_event_free (event); | ||
3115 | 1408 | gtk_widget_show_all (GTK_WIDGET (menu)); | ||
3116 | 1409 | } | ||
3117 | 1410 | |||
3118 | 1411 | static void | ||
3119 | 1412 | view_script_alert (YelpView *view, | ||
3120 | 1413 | WebKitWebFrame *frame, | ||
3121 | 1414 | gchar *message, | ||
3122 | 1415 | gpointer data) | ||
3123 | 1416 | { | ||
3124 | 1417 | printf ("\n\n===ALERT===\n%s\n\n", message); | ||
3125 | 1418 | } | ||
3126 | 1419 | |||
3127 | 1420 | static gboolean | ||
3128 | 1421 | view_navigation_requested (WebKitWebView *view, | ||
3129 | 1422 | WebKitWebFrame *frame, | ||
3130 | 1423 | WebKitNetworkRequest *request, | ||
3131 | 1424 | WebKitWebNavigationAction *action, | ||
3132 | 1425 | WebKitWebPolicyDecision *decision, | ||
3133 | 1426 | gpointer user_data) | ||
3134 | 1427 | { | ||
3135 | 1428 | const gchar *requri = webkit_network_request_get_uri (request); | ||
3136 | 1429 | YelpViewPrivate *priv = GET_PRIV (view); | ||
3137 | 1430 | YelpUri *uri; | ||
3138 | 1431 | |||
3139 | 1432 | if (priv->bogus_uri && | ||
3140 | 1433 | g_str_has_prefix (requri, priv->bogus_uri) && | ||
3141 | 1434 | requri[strlen(priv->bogus_uri)] == '#') { | ||
3142 | 1435 | gchar *tmp = g_strconcat("xref:", requri + strlen(priv->bogus_uri), NULL); | ||
3143 | 1436 | uri = yelp_uri_new_relative (priv->uri, tmp); | ||
3144 | 1437 | g_free (tmp); | ||
3145 | 1438 | } | ||
3146 | 1439 | else if (g_str_has_prefix (requri, BOGUS_URI)) { | ||
3147 | 1440 | uri = yelp_uri_new_relative (priv->uri, requri + BOGUS_URI_LEN); | ||
3148 | 1441 | } | ||
3149 | 1442 | else | ||
3150 | 1443 | uri = yelp_uri_new_relative (priv->uri, requri); | ||
3151 | 1444 | |||
3152 | 1445 | webkit_web_policy_decision_ignore (decision); | ||
3153 | 1446 | |||
3154 | 1447 | yelp_view_load_uri ((YelpView *) view, uri); | ||
3155 | 1448 | g_object_unref (uri); | ||
3156 | 1449 | |||
3157 | 1450 | return TRUE; | ||
3158 | 1451 | } | ||
3159 | 1452 | |||
3160 | 1453 | static void | ||
3161 | 1454 | view_resource_request (WebKitWebView *view, | ||
3162 | 1455 | WebKitWebFrame *frame, | ||
3163 | 1456 | WebKitWebResource *resource, | ||
3164 | 1457 | WebKitNetworkRequest *request, | ||
3165 | 1458 | WebKitNetworkResponse *response, | ||
3166 | 1459 | gpointer user_data) | ||
3167 | 1460 | { | ||
3168 | 1461 | YelpViewPrivate *priv = GET_PRIV (view); | ||
3169 | 1462 | const gchar *requri = webkit_network_request_get_uri (request); | ||
3170 | 1463 | gchar last; | ||
3171 | 1464 | gchar *newpath; | ||
3172 | 1465 | |||
3173 | 1466 | if (!g_str_has_prefix (requri, BOGUS_URI)) | ||
3174 | 1467 | return; | ||
3175 | 1468 | |||
3176 | 1469 | /* We get this signal for the page itself. Ignore. */ | ||
3177 | 1470 | if (g_str_equal (requri, priv->bogus_uri)) | ||
3178 | 1471 | return; | ||
3179 | 1472 | |||
3180 | 1473 | newpath = yelp_uri_locate_file_uri (priv->uri, requri + BOGUS_URI_LEN); | ||
3181 | 1474 | if (newpath != NULL) { | ||
3182 | 1475 | webkit_network_request_set_uri (request, newpath); | ||
3183 | 1476 | g_free (newpath); | ||
3184 | 1477 | } | ||
3185 | 1478 | else { | ||
3186 | 1479 | webkit_network_request_set_uri (request, "about:blank"); | ||
3187 | 1480 | } | ||
3188 | 1481 | } | ||
3189 | 1482 | |||
3190 | 1483 | static void | ||
3191 | 1484 | view_document_loaded (WebKitWebView *view, | ||
3192 | 1485 | WebKitWebFrame *frame, | ||
3193 | 1486 | gpointer user_data) | ||
3194 | 1487 | { | ||
3195 | 1488 | YelpViewPrivate *priv = GET_PRIV (view); | ||
3196 | 1489 | gchar *search_terms; | ||
3197 | 1490 | |||
3198 | 1491 | search_terms = yelp_uri_get_query (priv->uri, "terms"); | ||
3199 | 1492 | |||
3200 | 1493 | if (search_terms) { | ||
3201 | 1494 | WebKitDOMDocument *doc; | ||
3202 | 1495 | WebKitDOMElement *body, *link; | ||
3203 | 1496 | doc = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view)); | ||
3204 | 1497 | body = webkit_dom_document_query_selector (doc, "div.body", NULL); | ||
3205 | 1498 | if (body) { | ||
3206 | 1499 | gchar *tmp, *uri, *txt; | ||
3207 | 1500 | link = webkit_dom_document_create_element (doc, "a", NULL); | ||
3208 | 1501 | webkit_dom_element_set_attribute (link, "class", "fullsearch", NULL); | ||
3209 | 1502 | tmp = g_uri_escape_string (search_terms, NULL, FALSE); | ||
3210 | 1503 | uri = g_strconcat ("xref:search=", tmp, NULL); | ||
3211 | 1504 | webkit_dom_element_set_attribute (link, "href", uri, NULL); | ||
3212 | 1505 | g_free (tmp); | ||
3213 | 1506 | g_free (uri); | ||
3214 | 1507 | txt = g_strdup_printf (_("See all search results for “%s”"), | ||
3215 | 1508 | search_terms); | ||
3216 | 1509 | webkit_dom_node_set_text_content (WEBKIT_DOM_NODE (link), txt, NULL); | ||
3217 | 1510 | g_free (txt); | ||
3218 | 1511 | webkit_dom_node_insert_before (WEBKIT_DOM_NODE (body), | ||
3219 | 1512 | WEBKIT_DOM_NODE (link), | ||
3220 | 1513 | webkit_dom_node_get_first_child (WEBKIT_DOM_NODE (body)), | ||
3221 | 1514 | NULL); | ||
3222 | 1515 | } | ||
3223 | 1516 | g_free (search_terms); | ||
3224 | 1517 | } | ||
3225 | 1518 | } | ||
3226 | 1519 | |||
3227 | 1520 | static void | ||
3228 | 1521 | view_print (GtkAction *action, YelpView *view) | ||
3229 | 1522 | { | ||
3230 | 1523 | webkit_web_frame_print (webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (view))); | ||
3231 | 1524 | } | ||
3232 | 1525 | |||
3233 | 1526 | static void | ||
3234 | 1527 | view_history_action (GtkAction *action, | ||
3235 | 1528 | YelpView *view) | ||
3236 | 1529 | { | ||
3237 | 1530 | GList *newcur; | ||
3238 | 1531 | YelpViewPrivate *priv = GET_PRIV (view); | ||
3239 | 1532 | |||
3240 | 1533 | if (priv->back_cur == NULL) | ||
3241 | 1534 | return; | ||
3242 | 1535 | |||
3243 | 1536 | if (g_str_equal (gtk_action_get_name (action), "YelpViewGoBack")) | ||
3244 | 1537 | newcur = priv->back_cur->next; | ||
3245 | 1538 | else | ||
3246 | 1539 | newcur = priv->back_cur->prev; | ||
3247 | 1540 | |||
3248 | 1541 | if (newcur == NULL) | ||
3249 | 1542 | return; | ||
3250 | 1543 | |||
3251 | 1544 | priv->back_cur = newcur; | ||
3252 | 1545 | |||
3253 | 1546 | if (priv->back_cur->data == NULL) | ||
3254 | 1547 | return; | ||
3255 | 1548 | |||
3256 | 1549 | priv->back_load = TRUE; | ||
3257 | 1550 | yelp_view_load_uri (view, ((YelpBackEntry *) priv->back_cur->data)->uri); | ||
3258 | 1551 | priv->vadjust = ((YelpBackEntry *) priv->back_cur->data)->vadj; | ||
3259 | 1552 | priv->hadjust = ((YelpBackEntry *) priv->back_cur->data)->hadj; | ||
3260 | 1553 | } | ||
3261 | 1554 | |||
3262 | 1555 | static void | ||
3263 | 1556 | view_navigation_action (GtkAction *action, | ||
3264 | 1557 | YelpView *view) | ||
3265 | 1558 | { | ||
3266 | 1559 | YelpViewPrivate *priv = GET_PRIV (view); | ||
3267 | 1560 | gchar *page_id, *new_id, *xref; | ||
3268 | 1561 | YelpUri *new_uri; | ||
3269 | 1562 | |||
3270 | 1563 | page_id = yelp_uri_get_page_id (priv->uri); | ||
3271 | 1564 | |||
3272 | 1565 | if (g_str_equal (gtk_action_get_name (action), "YelpViewGoPrevious")) | ||
3273 | 1566 | new_id = yelp_document_get_prev_id (priv->document, page_id); | ||
3274 | 1567 | else | ||
3275 | 1568 | new_id = yelp_document_get_next_id (priv->document, page_id); | ||
3276 | 1569 | |||
3277 | 1570 | /* Just in case we screwed up somewhere */ | ||
3278 | 1571 | if (new_id == NULL) { | ||
3279 | 1572 | gtk_action_set_sensitive (action, FALSE); | ||
3280 | 1573 | return; | ||
3281 | 1574 | } | ||
3282 | 1575 | |||
3283 | 1576 | xref = g_strconcat ("xref:", new_id, NULL); | ||
3284 | 1577 | new_uri = yelp_uri_new_relative (priv->uri, xref); | ||
3285 | 1578 | yelp_view_load_uri (view, new_uri); | ||
3286 | 1579 | |||
3287 | 1580 | g_free (xref); | ||
3288 | 1581 | g_free (new_id); | ||
3289 | 1582 | g_object_unref (new_uri); | ||
3290 | 1583 | } | ||
3291 | 1584 | |||
3292 | 1585 | static void | ||
3293 | 1586 | view_clear_load (YelpView *view) | ||
3294 | 1587 | { | ||
3295 | 1588 | YelpViewPrivate *priv = GET_PRIV (view); | ||
3296 | 1589 | |||
3297 | 1590 | if (priv->resolve_uri != NULL) { | ||
3298 | 1591 | if (priv->uri_resolved != 0) { | ||
3299 | 1592 | g_signal_handler_disconnect (priv->resolve_uri, priv->uri_resolved); | ||
3300 | 1593 | priv->uri_resolved = 0; | ||
3301 | 1594 | } | ||
3302 | 1595 | g_object_unref (priv->resolve_uri); | ||
3303 | 1596 | } | ||
3304 | 1597 | priv->resolve_uri = NULL; | ||
3305 | 1598 | |||
3306 | 1599 | if (priv->uri) { | ||
3307 | 1600 | g_object_unref (priv->uri); | ||
3308 | 1601 | priv->uri = NULL; | ||
3309 | 1602 | } | ||
3310 | 1603 | |||
3311 | 1604 | if (priv->cancellable) { | ||
3312 | 1605 | g_cancellable_cancel (priv->cancellable); | ||
3313 | 1606 | priv->cancellable = NULL; | ||
3314 | 1607 | } | ||
3315 | 1608 | } | ||
3316 | 1609 | |||
3317 | 1610 | static void | ||
3318 | 1611 | view_load_page (YelpView *view) | ||
3319 | 1612 | { | ||
3320 | 1613 | YelpViewPrivate *priv = GET_PRIV (view); | ||
3321 | 1614 | gchar *page_id; | ||
3322 | 1615 | |||
3323 | 1616 | debug_print (DB_FUNCTION, "entering\n"); | ||
3324 | 1617 | |||
3325 | 1618 | g_return_if_fail (priv->cancellable == NULL); | ||
3326 | 1619 | |||
3327 | 1620 | if (priv->document == NULL) { | ||
3328 | 1621 | GError *error; | ||
3329 | 1622 | gchar *docuri; | ||
3330 | 1623 | /* FIXME: and if priv->uri is NULL? */ | ||
3331 | 1624 | docuri = yelp_uri_get_document_uri (priv->uri); | ||
3332 | 1625 | /* FIXME: CANT_READ isn't right */ | ||
3333 | 1626 | if (docuri) { | ||
3334 | 1627 | error = g_error_new (YELP_ERROR, YELP_ERROR_CANT_READ, | ||
3335 | 1628 | _("Could not load a document for ‘%s’"), | ||
3336 | 1629 | docuri); | ||
3337 | 1630 | g_free (docuri); | ||
3338 | 1631 | } | ||
3339 | 1632 | else { | ||
3340 | 1633 | error = g_error_new (YELP_ERROR, YELP_ERROR_CANT_READ, | ||
3341 | 1634 | _("Could not load a document")); | ||
3342 | 1635 | } | ||
3343 | 1636 | view_show_error_page (view, error); | ||
3344 | 1637 | g_error_free (error); | ||
3345 | 1638 | return; | ||
3346 | 1639 | } | ||
3347 | 1640 | |||
3348 | 1641 | page_id = yelp_uri_get_page_id (priv->uri); | ||
3349 | 1642 | priv->cancellable = g_cancellable_new (); | ||
3350 | 1643 | yelp_document_request_page (priv->document, | ||
3351 | 1644 | page_id, | ||
3352 | 1645 | priv->cancellable, | ||
3353 | 1646 | (YelpDocumentCallback) document_callback, | ||
3354 | 1647 | view); | ||
3355 | 1648 | g_free (page_id); | ||
3356 | 1649 | } | ||
3357 | 1650 | |||
3358 | 1651 | static void | ||
3359 | 1652 | view_show_error_page (YelpView *view, | ||
3360 | 1653 | GError *error) | ||
3361 | 1654 | { | ||
3362 | 1655 | YelpViewPrivate *priv = GET_PRIV (view); | ||
3363 | 1656 | static const gchar *errorpage = | ||
3364 | 1657 | "<html><head>" | ||
3365 | 1658 | "<style type='text/css'>" | ||
3366 | 1659 | "body {" | ||
3367 | 1660 | " margin: 1em;" | ||
3368 | 1661 | " color: %s;" | ||
3369 | 1662 | " background-color: %s;" | ||
3370 | 1663 | " }\n" | ||
3371 | 1664 | "p { margin: 1em 0 0 0; }\n" | ||
3372 | 1665 | "div.note {" | ||
3373 | 1666 | " padding: 6px;" | ||
3374 | 1667 | " border-color: %s;" | ||
3375 | 1668 | " border-top: solid 1px;" | ||
3376 | 1669 | " border-bottom: solid 1px;" | ||
3377 | 1670 | " background-color: %s;" | ||
3378 | 1671 | " }\n" | ||
3379 | 1672 | "div.note div.inner {" | ||
3380 | 1673 | " margin: 0; padding: 0;" | ||
3381 | 1674 | " background-image: url(%s);" | ||
3382 | 1675 | " background-position: %s top;" | ||
3383 | 1676 | " background-repeat: no-repeat;" | ||
3384 | 1677 | " min-height: %ipx;" | ||
3385 | 1678 | " }\n" | ||
3386 | 1679 | "div.note div.contents {" | ||
3387 | 1680 | " margin-%s: %ipx;" | ||
3388 | 1681 | " }\n" | ||
3389 | 1682 | "div.note div.title {" | ||
3390 | 1683 | " margin-%s: %ipx;" | ||
3391 | 1684 | " margin-bottom: 0.2em;" | ||
3392 | 1685 | " font-weight: bold;" | ||
3393 | 1686 | " color: %s;" | ||
3394 | 1687 | " }\n" | ||
3395 | 1688 | "a { color: %s; text-decoration: none; }\n" | ||
3396 | 1689 | "</style>" | ||
3397 | 1690 | "</head><body>" | ||
3398 | 1691 | "<div class='note'><div class='inner'>" | ||
3399 | 1692 | "%s<div class='contents'>%s%s</div>" | ||
3400 | 1693 | "</div></div>" | ||
3401 | 1694 | "</body></html>"; | ||
3402 | 1695 | YelpSettings *settings = yelp_settings_get_default (); | ||
3403 | 1696 | gchar *page, *title = NULL, *link = NULL, *title_m, *content_beg, *content_end; | ||
3404 | 1697 | gchar *textcolor, *bgcolor, *noteborder, *notebg, *titlecolor, *noteicon, *linkcolor; | ||
3405 | 1698 | gint iconsize; | ||
3406 | 1699 | GParamSpec *spec; | ||
3407 | 1700 | gboolean doc404 = FALSE; | ||
3408 | 1701 | const gchar *left = (gtk_widget_get_direction((GtkWidget *) view) == GTK_TEXT_DIR_RTL) ? "right" : "left"; | ||
3409 | 1702 | |||
3410 | 1703 | if (priv->uri && yelp_uri_get_document_type (priv->uri) == YELP_URI_DOCUMENT_TYPE_NOT_FOUND) | ||
3411 | 1704 | doc404 = TRUE; | ||
3412 | 1705 | if (error->domain == YELP_ERROR) | ||
3413 | 1706 | switch (error->code) { | ||
3414 | 1707 | case YELP_ERROR_NOT_FOUND: | ||
3415 | 1708 | if (doc404) | ||
3416 | 1709 | title = _("Document Not Found"); | ||
3417 | 1710 | else | ||
3418 | 1711 | title = _("Page Not Found"); | ||
3419 | 1712 | break; | ||
3420 | 1713 | case YELP_ERROR_CANT_READ: | ||
3421 | 1714 | title = _("Cannot Read"); | ||
3422 | 1715 | break; | ||
3423 | 1716 | default: | ||
3424 | 1717 | break; | ||
3425 | 1718 | } | ||
3426 | 1719 | if (title == NULL) | ||
3427 | 1720 | title = _("Unknown Error"); | ||
3428 | 1721 | title_m = g_markup_printf_escaped ("<div class='title'>%s</div>", title); | ||
3429 | 1722 | |||
3430 | 1723 | content_beg = g_markup_printf_escaped ("<p>%s</p>", error->message); | ||
3431 | 1724 | content_end = NULL; | ||
3432 | 1725 | if (doc404) { | ||
3433 | 1726 | gchar *struri = yelp_uri_get_document_uri (priv->uri); | ||
3434 | 1727 | /* do not free */ | ||
3435 | 1728 | gchar *pkg = NULL, *scheme = NULL; | ||
3436 | 1729 | if (g_str_has_prefix (struri, "help:")) { | ||
3437 | 1730 | scheme = "help"; | ||
3438 | 1731 | pkg = struri + 5; | ||
3439 | 1732 | } | ||
3440 | 1733 | else if (g_str_has_prefix (struri, "ghelp:")) { | ||
3441 | 1734 | scheme = "ghelp"; | ||
3442 | 1735 | pkg = struri + 6; | ||
3443 | 1736 | } | ||
3444 | 1737 | g_free (struri); | ||
3445 | 1738 | } | ||
3446 | 1739 | |||
3447 | 1740 | textcolor = yelp_settings_get_color (settings, YELP_SETTINGS_COLOR_TEXT); | ||
3448 | 1741 | bgcolor = yelp_settings_get_color (settings, YELP_SETTINGS_COLOR_BASE); | ||
3449 | 1742 | noteborder = yelp_settings_get_color (settings, YELP_SETTINGS_COLOR_RED_BORDER); | ||
3450 | 1743 | notebg = yelp_settings_get_color (settings, YELP_SETTINGS_COLOR_YELLOW_BASE); | ||
3451 | 1744 | titlecolor = yelp_settings_get_color (settings, YELP_SETTINGS_COLOR_TEXT_LIGHT); | ||
3452 | 1745 | linkcolor = yelp_settings_get_color (settings, YELP_SETTINGS_COLOR_LINK); | ||
3453 | 1746 | noteicon = yelp_settings_get_icon (settings, YELP_SETTINGS_ICON_WARNING); | ||
3454 | 1747 | iconsize = yelp_settings_get_icon_size (settings) + 6; | ||
3455 | 1748 | |||
3456 | 1749 | page = g_strdup_printf (errorpage, | ||
3457 | 1750 | textcolor, bgcolor, noteborder, notebg, noteicon, | ||
3458 | 1751 | left, iconsize, left, iconsize, left, iconsize, | ||
3459 | 1752 | titlecolor, linkcolor, title_m, content_beg, | ||
3460 | 1753 | (content_end != NULL) ? content_end : ""); | ||
3461 | 1754 | |||
3462 | 1755 | g_object_set (view, "state", YELP_VIEW_STATE_ERROR, NULL); | ||
3463 | 1756 | |||
3464 | 1757 | if (doc404) { | ||
3465 | 1758 | g_free (priv->root_title); | ||
3466 | 1759 | priv->root_title = g_strdup (title); | ||
3467 | 1760 | spec = g_object_class_find_property ((GObjectClass *) YELP_VIEW_GET_CLASS (view), | ||
3468 | 1761 | "root-title"); | ||
3469 | 1762 | g_signal_emit_by_name (view, "notify::root-title", spec); | ||
3470 | 1763 | g_free (priv->page_id); | ||
3471 | 1764 | priv->page_id = g_strdup ("index"); | ||
3472 | 1765 | spec = g_object_class_find_property ((GObjectClass *) YELP_VIEW_GET_CLASS (view), | ||
3473 | 1766 | "page-id"); | ||
3474 | 1767 | g_signal_emit_by_name (view, "notify::page-id", spec); | ||
3475 | 1768 | } | ||
3476 | 1769 | |||
3477 | 1770 | g_free (priv->page_title); | ||
3478 | 1771 | priv->page_title = g_strdup (title); | ||
3479 | 1772 | spec = g_object_class_find_property ((GObjectClass *) YELP_VIEW_GET_CLASS (view), | ||
3480 | 1773 | "page-title"); | ||
3481 | 1774 | g_signal_emit_by_name (view, "notify::page-title", spec); | ||
3482 | 1775 | |||
3483 | 1776 | g_free (priv->page_desc); | ||
3484 | 1777 | priv->page_desc = NULL; | ||
3485 | 1778 | if (priv->uri) | ||
3486 | 1779 | priv->page_desc = yelp_uri_get_canonical_uri (priv->uri); | ||
3487 | 1780 | spec = g_object_class_find_property ((GObjectClass *) YELP_VIEW_GET_CLASS (view), | ||
3488 | 1781 | "page-desc"); | ||
3489 | 1782 | g_signal_emit_by_name (view, "notify::page-desc", spec); | ||
3490 | 1783 | |||
3491 | 1784 | g_free (priv->page_icon); | ||
3492 | 1785 | priv->page_icon = g_strdup ("dialog-warning"); | ||
3493 | 1786 | spec = g_object_class_find_property ((GObjectClass *) YELP_VIEW_GET_CLASS (view), | ||
3494 | 1787 | "page-icon"); | ||
3495 | 1788 | g_signal_emit_by_name (view, "notify::page-icon", spec); | ||
3496 | 1789 | |||
3497 | 1790 | g_signal_emit (view, signals[LOADED], 0); | ||
3498 | 1791 | g_signal_handler_block (view, priv->navigation_requested); | ||
3499 | 1792 | webkit_web_view_load_string (WEBKIT_WEB_VIEW (view), | ||
3500 | 1793 | page, | ||
3501 | 1794 | "text/html", | ||
3502 | 1795 | "UTF-8", | ||
3503 | 1796 | "file:///error/"); | ||
3504 | 1797 | g_signal_handler_unblock (view, priv->navigation_requested); | ||
3505 | 1798 | g_free (title_m); | ||
3506 | 1799 | g_free (content_beg); | ||
3507 | 1800 | if (content_end != NULL) | ||
3508 | 1801 | g_free (content_end); | ||
3509 | 1802 | g_free (page); | ||
3510 | 1803 | } | ||
3511 | 1804 | |||
3512 | 1805 | |||
3513 | 1806 | static void | ||
3514 | 1807 | settings_set_fonts (YelpSettings *settings) | ||
3515 | 1808 | { | ||
3516 | 1809 | gchar *family; | ||
3517 | 1810 | gint size; | ||
3518 | 1811 | |||
3519 | 1812 | g_object_set (websettings, | ||
3520 | 1813 | "default-encoding", "utf-8", | ||
3521 | 1814 | "enable-private-browsing", TRUE, | ||
3522 | 1815 | NULL); | ||
3523 | 1816 | |||
3524 | 1817 | family = yelp_settings_get_font_family (settings, | ||
3525 | 1818 | YELP_SETTINGS_FONT_VARIABLE); | ||
3526 | 1819 | size = yelp_settings_get_font_size (settings, | ||
3527 | 1820 | YELP_SETTINGS_FONT_VARIABLE); | ||
3528 | 1821 | g_object_set (websettings, | ||
3529 | 1822 | "default-font-family", family, | ||
3530 | 1823 | "sans-serif-font-family", family, | ||
3531 | 1824 | "default-font-size", size, | ||
3532 | 1825 | NULL); | ||
3533 | 1826 | g_free (family); | ||
3534 | 1827 | |||
3535 | 1828 | family = yelp_settings_get_font_family (settings, | ||
3536 | 1829 | YELP_SETTINGS_FONT_FIXED); | ||
3537 | 1830 | size = yelp_settings_get_font_size (settings, | ||
3538 | 1831 | YELP_SETTINGS_FONT_FIXED); | ||
3539 | 1832 | g_object_set (websettings, | ||
3540 | 1833 | "monospace-font-family", family, | ||
3541 | 1834 | "default-monospace-font-size", size, | ||
3542 | 1835 | NULL); | ||
3543 | 1836 | g_free (family); | ||
3544 | 1837 | } | ||
3545 | 1838 | |||
3546 | 1839 | static void | ||
3547 | 1840 | settings_show_text_cursor (YelpSettings *settings) | ||
3548 | 1841 | { | ||
3549 | 1842 | g_object_set (websettings, | ||
3550 | 1843 | "enable-caret-browsing", | ||
3551 | 1844 | yelp_settings_get_show_text_cursor (settings), | ||
3552 | 1845 | NULL); | ||
3553 | 1846 | } | ||
3554 | 1847 | |||
3555 | 1848 | /******************************************************************************/ | ||
3556 | 1849 | |||
3557 | 1850 | static void | ||
3558 | 1851 | uri_resolved (YelpUri *uri, | ||
3559 | 1852 | YelpView *view) | ||
3560 | 1853 | { | ||
3561 | 1854 | YelpViewPrivate *priv = GET_PRIV (view); | ||
3562 | 1855 | YelpDocument *document; | ||
3563 | 1856 | YelpBackEntry *back; | ||
3564 | 1857 | GtkAction *action; | ||
3565 | 1858 | GSList *proxies, *cur; | ||
3566 | 1859 | GError *error = NULL; | ||
3567 | 1860 | gchar *struri; | ||
3568 | 1861 | GParamSpec *spec; | ||
3569 | 1862 | |||
3570 | 1863 | if (yelp_uri_get_document_type (uri) != YELP_URI_DOCUMENT_TYPE_EXTERNAL) { | ||
3571 | 1864 | g_object_ref (uri); | ||
3572 | 1865 | view_clear_load (view); | ||
3573 | 1866 | priv->uri = uri; | ||
3574 | 1867 | } | ||
3575 | 1868 | |||
3576 | 1869 | switch (yelp_uri_get_document_type (uri)) { | ||
3577 | 1870 | case YELP_URI_DOCUMENT_TYPE_EXTERNAL: | ||
3578 | 1871 | g_object_set (view, "state", priv->prevstate, NULL); | ||
3579 | 1872 | struri = yelp_uri_get_canonical_uri (uri); | ||
3580 | 1873 | if (g_str_has_prefix (struri, "install:") || | ||
3581 | 1874 | g_str_has_prefix (struri, "install-ghelp:") || | ||
3582 | 1875 | g_str_has_prefix (struri, "install-help:")) { | ||
3583 | 1876 | view_install_uri (view, struri); | ||
3584 | 1877 | } | ||
3585 | 1878 | else { | ||
3586 | 1879 | gboolean result; | ||
3587 | 1880 | g_signal_emit (view, signals[EXTERNAL_URI], 0, uri, &result); | ||
3588 | 1881 | } | ||
3589 | 1882 | g_free (struri); | ||
3590 | 1883 | return; | ||
3591 | 1884 | case YELP_URI_DOCUMENT_TYPE_NOT_FOUND: | ||
3592 | 1885 | struri = yelp_uri_get_canonical_uri (uri); | ||
3593 | 1886 | if (struri != NULL) { | ||
3594 | 1887 | error = g_error_new (YELP_ERROR, YELP_ERROR_NOT_FOUND, | ||
3595 | 1888 | _("The URI ‘%s’ does not point to a valid page."), | ||
3596 | 1889 | struri); | ||
3597 | 1890 | g_free (struri); | ||
3598 | 1891 | } | ||
3599 | 1892 | else { | ||
3600 | 1893 | error = g_error_new (YELP_ERROR, YELP_ERROR_NOT_FOUND, | ||
3601 | 1894 | _("The URI does not point to a valid page.")); | ||
3602 | 1895 | } | ||
3603 | 1896 | break; | ||
3604 | 1897 | case YELP_URI_DOCUMENT_TYPE_ERROR: | ||
3605 | 1898 | struri = yelp_uri_get_canonical_uri (uri); | ||
3606 | 1899 | error = g_error_new (YELP_ERROR, YELP_ERROR_PROCESSING, | ||
3607 | 1900 | _("The URI ‘%s’ could not be parsed."), | ||
3608 | 1901 | struri); | ||
3609 | 1902 | g_free (struri); | ||
3610 | 1903 | break; | ||
3611 | 1904 | default: | ||
3612 | 1905 | break; | ||
3613 | 1906 | } | ||
3614 | 1907 | |||
3615 | 1908 | if (error == NULL) { | ||
3616 | 1909 | document = yelp_document_get_for_uri (uri); | ||
3617 | 1910 | if (priv->document) | ||
3618 | 1911 | g_object_unref (priv->document); | ||
3619 | 1912 | priv->document = document; | ||
3620 | 1913 | } | ||
3621 | 1914 | else { | ||
3622 | 1915 | if (priv->document != NULL) { | ||
3623 | 1916 | g_object_unref (priv->document); | ||
3624 | 1917 | priv->document = NULL; | ||
3625 | 1918 | } | ||
3626 | 1919 | } | ||
3627 | 1920 | |||
3628 | 1921 | if (!priv->back_load) { | ||
3629 | 1922 | back = g_new0 (YelpBackEntry, 1); | ||
3630 | 1923 | back->uri = g_object_ref (uri); | ||
3631 | 1924 | while (priv->back_list != priv->back_cur) { | ||
3632 | 1925 | back_entry_free ((YelpBackEntry *) priv->back_list->data); | ||
3633 | 1926 | priv->back_list = g_list_delete_link (priv->back_list, priv->back_list); | ||
3634 | 1927 | } | ||
3635 | 1928 | priv->back_list = g_list_prepend (priv->back_list, back); | ||
3636 | 1929 | priv->back_cur = priv->back_list; | ||
3637 | 1930 | } | ||
3638 | 1931 | priv->back_load = FALSE; | ||
3639 | 1932 | |||
3640 | 1933 | action = gtk_action_group_get_action (priv->action_group, "YelpViewGoBack"); | ||
3641 | 1934 | gtk_action_set_sensitive (action, FALSE); | ||
3642 | 1935 | proxies = gtk_action_get_proxies (action); | ||
3643 | 1936 | if (priv->back_cur->next && priv->back_cur->next->data) { | ||
3644 | 1937 | gchar *tooltip = ""; | ||
3645 | 1938 | back = priv->back_cur->next->data; | ||
3646 | 1939 | |||
3647 | 1940 | gtk_action_set_sensitive (action, TRUE); | ||
3648 | 1941 | if (back->title && back->desc) { | ||
3649 | 1942 | gchar *color; | ||
3650 | 1943 | color = yelp_settings_get_color (yelp_settings_get_default (), | ||
3651 | 1944 | YELP_SETTINGS_COLOR_TEXT_LIGHT); | ||
3652 | 1945 | tooltip = g_markup_printf_escaped ("<span size='larger'>%s</span>\n<span color='%s'>%s</span>", | ||
3653 | 1946 | back->title, color, back->desc); | ||
3654 | 1947 | g_free (color); | ||
3655 | 1948 | } | ||
3656 | 1949 | else if (back->title) | ||
3657 | 1950 | tooltip = g_markup_printf_escaped ("<span size='larger'>%s</span>", | ||
3658 | 1951 | back->title); | ||
3659 | 1952 | /* Can't seem to use markup on GtkAction tooltip */ | ||
3660 | 1953 | for (cur = proxies; cur != NULL; cur = cur->next) | ||
3661 | 1954 | gtk_widget_set_tooltip_markup (GTK_WIDGET (cur->data), tooltip); | ||
3662 | 1955 | } | ||
3663 | 1956 | else { | ||
3664 | 1957 | for (cur = proxies; cur != NULL; cur = cur->next) | ||
3665 | 1958 | gtk_widget_set_tooltip_text (GTK_WIDGET (cur->data), ""); | ||
3666 | 1959 | } | ||
3667 | 1960 | |||
3668 | 1961 | action = gtk_action_group_get_action (priv->action_group, "YelpViewGoForward"); | ||
3669 | 1962 | gtk_action_set_sensitive (action, FALSE); | ||
3670 | 1963 | proxies = gtk_action_get_proxies (action); | ||
3671 | 1964 | if (priv->back_cur->prev && priv->back_cur->prev->data) { | ||
3672 | 1965 | gchar *tooltip = ""; | ||
3673 | 1966 | back = priv->back_cur->prev->data; | ||
3674 | 1967 | |||
3675 | 1968 | gtk_action_set_sensitive (action, TRUE); | ||
3676 | 1969 | if (back->title && back->desc) { | ||
3677 | 1970 | gchar *color; | ||
3678 | 1971 | color = yelp_settings_get_color (yelp_settings_get_default (), | ||
3679 | 1972 | YELP_SETTINGS_COLOR_TEXT_LIGHT); | ||
3680 | 1973 | tooltip = g_markup_printf_escaped ("<span size='larger'>%s</span>\n<span color='%s'>%s</span>", | ||
3681 | 1974 | back->title, color, back->desc); | ||
3682 | 1975 | g_free (color); | ||
3683 | 1976 | } | ||
3684 | 1977 | else if (back->title) | ||
3685 | 1978 | tooltip = g_markup_printf_escaped ("<span size='larger'>%s</span>", | ||
3686 | 1979 | back->title); | ||
3687 | 1980 | /* Can't seem to use markup on GtkAction tooltip */ | ||
3688 | 1981 | for (cur = proxies; cur != NULL; cur = cur->next) | ||
3689 | 1982 | gtk_widget_set_tooltip_markup (GTK_WIDGET (cur->data), tooltip); | ||
3690 | 1983 | } | ||
3691 | 1984 | else { | ||
3692 | 1985 | for (cur = proxies; cur != NULL; cur = cur->next) | ||
3693 | 1986 | gtk_widget_set_tooltip_text (GTK_WIDGET (cur->data), ""); | ||
3694 | 1987 | } | ||
3695 | 1988 | |||
3696 | 1989 | spec = g_object_class_find_property ((GObjectClass *) YELP_VIEW_GET_CLASS (view), | ||
3697 | 1990 | "yelp-uri"); | ||
3698 | 1991 | g_signal_emit_by_name (view, "notify::yelp-uri", spec); | ||
3699 | 1992 | |||
3700 | 1993 | g_free (priv->page_id); | ||
3701 | 1994 | priv->page_id = NULL; | ||
3702 | 1995 | if (priv->uri != NULL) | ||
3703 | 1996 | priv->page_id = yelp_uri_get_page_id (priv->uri); | ||
3704 | 1997 | spec = g_object_class_find_property ((GObjectClass *) YELP_VIEW_GET_CLASS (view), | ||
3705 | 1998 | "page-id"); | ||
3706 | 1999 | g_signal_emit_by_name (view, "notify::page-id", spec); | ||
3707 | 2000 | |||
3708 | 2001 | g_free (priv->root_title); | ||
3709 | 2002 | g_free (priv->page_title); | ||
3710 | 2003 | g_free (priv->page_desc); | ||
3711 | 2004 | g_free (priv->page_icon); | ||
3712 | 2005 | priv->root_title = NULL; | ||
3713 | 2006 | priv->page_title = NULL; | ||
3714 | 2007 | priv->page_desc = NULL; | ||
3715 | 2008 | priv->page_icon = NULL; | ||
3716 | 2009 | |||
3717 | 2010 | spec = g_object_class_find_property ((GObjectClass *) YELP_VIEW_GET_CLASS (view), | ||
3718 | 2011 | "root-title"); | ||
3719 | 2012 | g_signal_emit_by_name (view, "notify::root-title", spec); | ||
3720 | 2013 | |||
3721 | 2014 | spec = g_object_class_find_property ((GObjectClass *) YELP_VIEW_GET_CLASS (view), | ||
3722 | 2015 | "page-title"); | ||
3723 | 2016 | g_signal_emit_by_name (view, "notify::page-title", spec); | ||
3724 | 2017 | |||
3725 | 2018 | spec = g_object_class_find_property ((GObjectClass *) YELP_VIEW_GET_CLASS (view), | ||
3726 | 2019 | "page-desc"); | ||
3727 | 2020 | g_signal_emit_by_name (view, "notify::page-desc", spec); | ||
3728 | 2021 | |||
3729 | 2022 | spec = g_object_class_find_property ((GObjectClass *) YELP_VIEW_GET_CLASS (view), | ||
3730 | 2023 | "page-icon"); | ||
3731 | 2024 | g_signal_emit_by_name (view, "notify::page-icon", spec); | ||
3732 | 2025 | |||
3733 | 2026 | if (error == NULL) | ||
3734 | 2027 | view_load_page (view); | ||
3735 | 2028 | else { | ||
3736 | 2029 | view_show_error_page (view, error); | ||
3737 | 2030 | g_error_free (error); | ||
3738 | 2031 | } | ||
3739 | 2032 | } | ||
3740 | 2033 | |||
3741 | 2034 | static void | ||
3742 | 2035 | document_callback (YelpDocument *document, | ||
3743 | 2036 | YelpDocumentSignal signal, | ||
3744 | 2037 | YelpView *view, | ||
3745 | 2038 | GError *error) | ||
3746 | 2039 | { | ||
3747 | 2040 | YelpViewPrivate *priv = GET_PRIV (view); | ||
3748 | 2041 | |||
3749 | 2042 | debug_print (DB_FUNCTION, "entering\n"); | ||
3750 | 2043 | |||
3751 | 2044 | if (signal == YELP_DOCUMENT_SIGNAL_INFO) { | ||
3752 | 2045 | gchar *prev_id, *next_id, *real_id; | ||
3753 | 2046 | GtkAction *action; | ||
3754 | 2047 | YelpBackEntry *back = NULL; | ||
3755 | 2048 | GParamSpec *spec; | ||
3756 | 2049 | |||
3757 | 2050 | real_id = yelp_document_get_page_id (document, priv->page_id); | ||
3758 | 2051 | if (priv->page_id && real_id && g_str_equal (real_id, priv->page_id)) { | ||
3759 | 2052 | g_free (real_id); | ||
3760 | 2053 | } | ||
3761 | 2054 | else { | ||
3762 | 2055 | GParamSpec *spec; | ||
3763 | 2056 | g_free (priv->page_id); | ||
3764 | 2057 | priv->page_id = real_id; | ||
3765 | 2058 | spec = g_object_class_find_property ((GObjectClass *) YELP_VIEW_GET_CLASS (view), | ||
3766 | 2059 | "page-id"); | ||
3767 | 2060 | g_signal_emit_by_name (view, "notify::page-id", spec); | ||
3768 | 2061 | } | ||
3769 | 2062 | |||
3770 | 2063 | g_free (priv->root_title); | ||
3771 | 2064 | g_free (priv->page_title); | ||
3772 | 2065 | g_free (priv->page_desc); | ||
3773 | 2066 | g_free (priv->page_icon); | ||
3774 | 2067 | |||
3775 | 2068 | priv->root_title = yelp_document_get_root_title (document, priv->page_id); | ||
3776 | 2069 | priv->page_title = yelp_document_get_page_title (document, priv->page_id); | ||
3777 | 2070 | priv->page_desc = yelp_document_get_page_desc (document, priv->page_id); | ||
3778 | 2071 | priv->page_icon = yelp_document_get_page_icon (document, priv->page_id); | ||
3779 | 2072 | |||
3780 | 2073 | if (priv->back_cur) | ||
3781 | 2074 | back = priv->back_cur->data; | ||
3782 | 2075 | if (back) { | ||
3783 | 2076 | g_free (back->title); | ||
3784 | 2077 | back->title = g_strdup (priv->page_title); | ||
3785 | 2078 | g_free (back->desc); | ||
3786 | 2079 | back->desc = g_strdup (priv->page_desc); | ||
3787 | 2080 | } | ||
3788 | 2081 | |||
3789 | 2082 | prev_id = yelp_document_get_prev_id (document, priv->page_id); | ||
3790 | 2083 | action = gtk_action_group_get_action (priv->action_group, "YelpViewGoPrevious"); | ||
3791 | 2084 | gtk_action_set_sensitive (action, prev_id != NULL); | ||
3792 | 2085 | g_free (prev_id); | ||
3793 | 2086 | |||
3794 | 2087 | next_id = yelp_document_get_next_id (document, priv->page_id); | ||
3795 | 2088 | action = gtk_action_group_get_action (priv->action_group, "YelpViewGoNext"); | ||
3796 | 2089 | gtk_action_set_sensitive (action, next_id != NULL); | ||
3797 | 2090 | g_free (next_id); | ||
3798 | 2091 | |||
3799 | 2092 | spec = g_object_class_find_property ((GObjectClass *) YELP_VIEW_GET_CLASS (view), | ||
3800 | 2093 | "root-title"); | ||
3801 | 2094 | g_signal_emit_by_name (view, "notify::root-title", spec); | ||
3802 | 2095 | |||
3803 | 2096 | spec = g_object_class_find_property ((GObjectClass *) YELP_VIEW_GET_CLASS (view), | ||
3804 | 2097 | "page-title"); | ||
3805 | 2098 | g_signal_emit_by_name (view, "notify::page-title", spec); | ||
3806 | 2099 | |||
3807 | 2100 | spec = g_object_class_find_property ((GObjectClass *) YELP_VIEW_GET_CLASS (view), | ||
3808 | 2101 | "page-desc"); | ||
3809 | 2102 | g_signal_emit_by_name (view, "notify::page-desc", spec); | ||
3810 | 2103 | |||
3811 | 2104 | spec = g_object_class_find_property ((GObjectClass *) YELP_VIEW_GET_CLASS (view), | ||
3812 | 2105 | "page-icon"); | ||
3813 | 2106 | g_signal_emit_by_name (view, "notify::page-icon", spec); | ||
3814 | 2107 | } | ||
3815 | 2108 | else if (signal == YELP_DOCUMENT_SIGNAL_CONTENTS) { | ||
3816 | 2109 | YelpUriDocumentType doctype; | ||
3817 | 2110 | const gchar *contents; | ||
3818 | 2111 | gchar *mime_type, *page_id, *frag_id, *full_uri; | ||
3819 | 2112 | page_id = yelp_uri_get_page_id (priv->uri); | ||
3820 | 2113 | debug_print (DB_ARG, " document.uri.page_id=\"%s\"\n", page_id); | ||
3821 | 2114 | mime_type = yelp_document_get_mime_type (document, page_id); | ||
3822 | 2115 | contents = yelp_document_read_contents (document, page_id); | ||
3823 | 2116 | frag_id = yelp_uri_get_frag_id (priv->uri); | ||
3824 | 2117 | g_free (priv->bogus_uri); | ||
3825 | 2118 | /* We don't have actual page and frag IDs for DocBook. We just map IDs | ||
3826 | 2119 | of block elements. The result is that we get xref:someid#someid. | ||
3827 | 2120 | If someid is really the page ID, we just drop the frag reference. | ||
3828 | 2121 | Otherwise, normal page views scroll past the link trail. | ||
3829 | 2122 | */ | ||
3830 | 2123 | if (frag_id != NULL) { | ||
3831 | 2124 | if (YELP_IS_DOCBOOK_DOCUMENT (document)) { | ||
3832 | 2125 | gchar *real_id = yelp_document_get_page_id (document, page_id); | ||
3833 | 2126 | if (g_str_equal (real_id, frag_id)) { | ||
3834 | 2127 | g_free (frag_id); | ||
3835 | 2128 | frag_id = NULL; | ||
3836 | 2129 | } | ||
3837 | 2130 | g_free (real_id); | ||
3838 | 2131 | } | ||
3839 | 2132 | } | ||
3840 | 2133 | /* We have to give WebKit a URI in a scheme it understands, otherwise we | ||
3841 | 2134 | won't get the resource-request-starting signal. So we can't use the | ||
3842 | 2135 | canonical URI, because it might be something like ghelp. We also have | ||
3843 | 2136 | to give it something unique, because WebKit ignores our load_string | ||
3844 | 2137 | call if the URI isn't different. We could try to construct something | ||
3845 | 2138 | based on actual file locations, but in fact it doesn't matter. So | ||
3846 | 2139 | we just make a bogus URI that's easy to process later. | ||
3847 | 2140 | */ | ||
3848 | 2141 | doctype = yelp_uri_get_document_type (priv->uri); | ||
3849 | 2142 | full_uri = yelp_uri_get_canonical_uri (priv->uri); | ||
3850 | 2143 | if (g_str_has_prefix (full_uri, "file:/") && | ||
3851 | 2144 | (doctype == YELP_URI_DOCUMENT_TYPE_TEXT || | ||
3852 | 2145 | doctype == YELP_URI_DOCUMENT_TYPE_HTML || | ||
3853 | 2146 | doctype == YELP_URI_DOCUMENT_TYPE_XHTML )) { | ||
3854 | 2147 | priv->bogus_uri = full_uri; | ||
3855 | 2148 | } | ||
3856 | 2149 | else { | ||
3857 | 2150 | g_free (full_uri); | ||
3858 | 2151 | if (frag_id != NULL) | ||
3859 | 2152 | priv->bogus_uri = g_strdup_printf ("%s%p#%s", BOGUS_URI, priv->uri, frag_id); | ||
3860 | 2153 | else | ||
3861 | 2154 | priv->bogus_uri = g_strdup_printf ("%s%p", BOGUS_URI, priv->uri); | ||
3862 | 2155 | } | ||
3863 | 2156 | g_signal_handler_block (view, priv->navigation_requested); | ||
3864 | 2157 | webkit_web_view_load_string (WEBKIT_WEB_VIEW (view), | ||
3865 | 2158 | contents, | ||
3866 | 2159 | mime_type, | ||
3867 | 2160 | "UTF-8", | ||
3868 | 2161 | priv->bogus_uri); | ||
3869 | 2162 | g_signal_handler_unblock (view, priv->navigation_requested); | ||
3870 | 2163 | g_object_set (view, "state", YELP_VIEW_STATE_LOADED, NULL); | ||
3871 | 2164 | |||
3872 | 2165 | /* If we need to set the GtkAdjustment or trigger the page title | ||
3873 | 2166 | * from what WebKit thinks it is (see comment below), we need to | ||
3874 | 2167 | * let the main loop run through. | ||
3875 | 2168 | */ | ||
3876 | 2169 | if (priv->vadjust > 0 || priv->hadjust > 0 || priv->page_title == NULL) | ||
3877 | 2170 | while (g_main_context_pending (NULL)) { | ||
3878 | 2171 | WebKitLoadStatus status; | ||
3879 | 2172 | status = webkit_web_view_get_load_status (WEBKIT_WEB_VIEW (view)); | ||
3880 | 2173 | g_main_context_iteration (NULL, FALSE); | ||
3881 | 2174 | /* Sometimes some runaway JavaScript causes there to always | ||
3882 | 2175 | * be pending sources. Break out if the document is loaded. | ||
3883 | 2176 | */ | ||
3884 | 2177 | if (status == WEBKIT_LOAD_FINISHED || | ||
3885 | 2178 | status == WEBKIT_LOAD_FAILED) | ||
3886 | 2179 | break; | ||
3887 | 2180 | } | ||
3888 | 2181 | |||
3889 | 2182 | /* Setting adjustments only work after the page is loaded. These | ||
3890 | 2183 | * are set by view_history_action, and they're reset to 0 after | ||
3891 | 2184 | * each load here. | ||
3892 | 2185 | */ | ||
3893 | 2186 | if (priv->vadjust > 0) { | ||
3894 | 2187 | if (priv->vadjustment) | ||
3895 | 2188 | gtk_adjustment_set_value (priv->vadjustment, priv->vadjust); | ||
3896 | 2189 | priv->vadjust = 0; | ||
3897 | 2190 | } | ||
3898 | 2191 | if (priv->hadjust > 0) { | ||
3899 | 2192 | if (priv->hadjustment) | ||
3900 | 2193 | gtk_adjustment_set_value (priv->hadjustment, priv->hadjust); | ||
3901 | 2194 | priv->hadjust = 0; | ||
3902 | 2195 | } | ||
3903 | 2196 | |||
3904 | 2197 | /* If the document didn't give us a page title, get it from WebKit. | ||
3905 | 2198 | * We let the main loop run through so that WebKit gets the title | ||
3906 | 2199 | * set so that we can send notify::page-title before loaded. It | ||
3907 | 2200 | * simplifies things if YelpView consumers can assume the title | ||
3908 | 2201 | * is set before loaded is triggered. | ||
3909 | 2202 | */ | ||
3910 | 2203 | if (priv->page_title == NULL) { | ||
3911 | 2204 | GParamSpec *spec; | ||
3912 | 2205 | priv->page_title = g_strdup (webkit_web_view_get_title (WEBKIT_WEB_VIEW (view))); | ||
3913 | 2206 | spec = g_object_class_find_property ((GObjectClass *) YELP_VIEW_GET_CLASS (view), | ||
3914 | 2207 | "page-title"); | ||
3915 | 2208 | g_signal_emit_by_name (view, "notify::page-title", spec); | ||
3916 | 2209 | } | ||
3917 | 2210 | |||
3918 | 2211 | g_free (frag_id); | ||
3919 | 2212 | g_free (page_id); | ||
3920 | 2213 | g_free (mime_type); | ||
3921 | 2214 | yelp_document_finish_read (document, contents); | ||
3922 | 2215 | g_signal_emit (view, signals[LOADED], 0); | ||
3923 | 2216 | } | ||
3924 | 2217 | else if (signal == YELP_DOCUMENT_SIGNAL_ERROR) { | ||
3925 | 2218 | view_show_error_page (view, error); | ||
3926 | 2219 | } | ||
3927 | 2220 | } | ||
3928 | 2221 | 0 | ||
3929 | === removed directory '.pc/git_signal_handler.patch/src' | |||
3930 | === removed file '.pc/git_signal_handler.patch/src/yelp-window.c' | |||
3931 | --- .pc/git_signal_handler.patch/src/yelp-window.c 2014-02-27 13:28:05 +0000 | |||
3932 | +++ .pc/git_signal_handler.patch/src/yelp-window.c 1970-01-01 00:00:00 +0000 | |||
3933 | @@ -1,1402 +0,0 @@ | |||
3934 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||
3935 | 2 | /* | ||
3936 | 3 | * Copyright (C) 2010 Shaun McCance <shaunm@gnome.org> | ||
3937 | 4 | * | ||
3938 | 5 | * This program is free software; you can redistribute it and/or | ||
3939 | 6 | * modify it under the terms of the GNU General Public License as | ||
3940 | 7 | * published by the Free Software Foundation; either version 2 of the | ||
3941 | 8 | * License, or (at your option) any later version. | ||
3942 | 9 | * | ||
3943 | 10 | * This program is distributed in the hope that it will be useful, | ||
3944 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3945 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
3946 | 13 | * General Public License for more details. | ||
3947 | 14 | * | ||
3948 | 15 | * You should have received a copy of the GNU General Public | ||
3949 | 16 | * License along with this program; if not, write to the | ||
3950 | 17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
3951 | 18 | * Boston, MA 02111-1307, USA. | ||
3952 | 19 | * | ||
3953 | 20 | * Author: Shaun McCance <shaunm@gnome.org> | ||
3954 | 21 | */ | ||
3955 | 22 | |||
3956 | 23 | #ifdef HAVE_CONFIG_H | ||
3957 | 24 | #include <config.h> | ||
3958 | 25 | #endif | ||
3959 | 26 | |||
3960 | 27 | #include <math.h> | ||
3961 | 28 | |||
3962 | 29 | #include <gdk/gdkkeysyms.h> | ||
3963 | 30 | #include <glib/gi18n.h> | ||
3964 | 31 | #include <gtk/gtk.h> | ||
3965 | 32 | |||
3966 | 33 | #include "yelp-location-entry.h" | ||
3967 | 34 | #include "yelp-settings.h" | ||
3968 | 35 | #include "yelp-uri.h" | ||
3969 | 36 | #include "yelp-view.h" | ||
3970 | 37 | |||
3971 | 38 | #include "yelp-application.h" | ||
3972 | 39 | #include "yelp-window.h" | ||
3973 | 40 | |||
3974 | 41 | static void yelp_window_init (YelpWindow *window); | ||
3975 | 42 | static void yelp_window_class_init (YelpWindowClass *klass); | ||
3976 | 43 | static void yelp_window_dispose (GObject *object); | ||
3977 | 44 | static void yelp_window_finalize (GObject *object); | ||
3978 | 45 | static void yelp_window_get_property (GObject *object, | ||
3979 | 46 | guint prop_id, | ||
3980 | 47 | GValue *value, | ||
3981 | 48 | GParamSpec *pspec); | ||
3982 | 49 | static void yelp_window_set_property (GObject *object, | ||
3983 | 50 | guint prop_id, | ||
3984 | 51 | const GValue *value, | ||
3985 | 52 | GParamSpec *pspec); | ||
3986 | 53 | |||
3987 | 54 | static void window_construct (YelpWindow *window); | ||
3988 | 55 | static void window_new (GtkAction *action, | ||
3989 | 56 | YelpWindow *window); | ||
3990 | 57 | static gboolean window_map_event (YelpWindow *window, | ||
3991 | 58 | GdkEvent *event, | ||
3992 | 59 | gpointer user_data); | ||
3993 | 60 | static gboolean window_configure_event (YelpWindow *window, | ||
3994 | 61 | GdkEventConfigure *event, | ||
3995 | 62 | gpointer user_data); | ||
3996 | 63 | static void window_drag_received (YelpWindow *window, | ||
3997 | 64 | GdkDragContext *context, | ||
3998 | 65 | gint x, | ||
3999 | 66 | gint y, | ||
4000 | 67 | GtkSelectionData *data, | ||
4001 | 68 | guint info, | ||
4002 | 69 | guint time, | ||
4003 | 70 | gpointer userdata); | ||
4004 | 71 | static gboolean window_resize_signal (YelpWindow *window); | ||
4005 | 72 | static void window_close (GtkAction *action, | ||
4006 | 73 | YelpWindow *window); | ||
4007 | 74 | static void window_go_all (GtkAction *action, | ||
4008 | 75 | YelpWindow *window); | ||
4009 | 76 | static void window_add_bookmark (GtkAction *action, | ||
4010 | 77 | YelpWindow *window); | ||
4011 | 78 | static void window_remove_bookmark (GtkAction *action, | ||
4012 | 79 | YelpWindow *window); | ||
4013 | 80 | static void window_load_bookmark (GtkAction *action, | ||
4014 | 81 | YelpWindow *window); | ||
4015 | 82 | static void window_find_in_page (GtkAction *action, | ||
4016 | 83 | YelpWindow *window); | ||
4017 | 84 | static void window_start_search (GtkAction *action, | ||
4018 | 85 | YelpWindow *window); | ||
4019 | 86 | static void window_open_location (GtkAction *action, | ||
4020 | 87 | YelpWindow *window); | ||
4021 | 88 | static void window_read_later (GtkAction *action, | ||
4022 | 89 | YelpWindow *window); | ||
4023 | 90 | static gboolean read_later_clicked (GtkLinkButton *button, | ||
4024 | 91 | YelpWindow *window); | ||
4025 | 92 | static void app_read_later_changed (YelpApplication *app, | ||
4026 | 93 | const gchar *doc_uri, | ||
4027 | 94 | YelpWindow *window); | ||
4028 | 95 | static void app_bookmarks_changed (YelpApplication *app, | ||
4029 | 96 | const gchar *doc_uri, | ||
4030 | 97 | YelpWindow *window); | ||
4031 | 98 | static void window_set_bookmarks (YelpWindow *window, | ||
4032 | 99 | const gchar *doc_uri); | ||
4033 | 100 | static void window_set_bookmark_action (YelpWindow *window); | ||
4034 | 101 | static gboolean find_entry_focus_out (GtkEntry *entry, | ||
4035 | 102 | GdkEventFocus *event, | ||
4036 | 103 | YelpWindow *window); | ||
4037 | 104 | static gboolean find_entry_key_press (GtkEntry *entry, | ||
4038 | 105 | GdkEventKey *event, | ||
4039 | 106 | YelpWindow *window); | ||
4040 | 107 | static void find_entry_changed (GtkEntry *entry, | ||
4041 | 108 | YelpWindow *window); | ||
4042 | 109 | |||
4043 | 110 | static gboolean entry_focus_in (GtkEntry *entry, | ||
4044 | 111 | GdkEventFocus *event, | ||
4045 | 112 | YelpWindow *window); | ||
4046 | 113 | static gboolean entry_focus_out (YelpLocationEntry *entry, | ||
4047 | 114 | GdkEventFocus *event, | ||
4048 | 115 | YelpWindow *window); | ||
4049 | 116 | |||
4050 | 117 | static void view_new_window (YelpView *view, | ||
4051 | 118 | YelpUri *uri, | ||
4052 | 119 | YelpWindow *window); | ||
4053 | 120 | static void view_loaded (YelpView *view, | ||
4054 | 121 | YelpWindow *window); | ||
4055 | 122 | static void view_uri_selected (YelpView *view, | ||
4056 | 123 | GParamSpec *pspec, | ||
4057 | 124 | YelpWindow *window); | ||
4058 | 125 | static void view_root_title (YelpView *view, | ||
4059 | 126 | GParamSpec *pspec, | ||
4060 | 127 | YelpWindow *window); | ||
4061 | 128 | static gboolean view_is_xref_uri (YelpView *view, | ||
4062 | 129 | GtkAction *action, | ||
4063 | 130 | const gchar *uri, | ||
4064 | 131 | YelpWindow *window); | ||
4065 | 132 | |||
4066 | 133 | static void hidden_entry_activate (GtkEntry *entry, | ||
4067 | 134 | YelpWindow *window); | ||
4068 | 135 | static void hidden_entry_hide (YelpWindow *window); | ||
4069 | 136 | static gboolean hidden_key_press (GtkWidget *widget, | ||
4070 | 137 | GdkEventKey *event, | ||
4071 | 138 | YelpWindow *window); | ||
4072 | 139 | |||
4073 | 140 | enum { | ||
4074 | 141 | PROP_0, | ||
4075 | 142 | PROP_APPLICATION | ||
4076 | 143 | }; | ||
4077 | 144 | |||
4078 | 145 | enum { | ||
4079 | 146 | RESIZE_EVENT, | ||
4080 | 147 | LAST_SIGNAL | ||
4081 | 148 | }; | ||
4082 | 149 | |||
4083 | 150 | static guint signals[LAST_SIGNAL] = { 0 }; | ||
4084 | 151 | |||
4085 | 152 | G_DEFINE_TYPE (YelpWindow, yelp_window, GTK_TYPE_WINDOW); | ||
4086 | 153 | #define GET_PRIV(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), YELP_TYPE_WINDOW, YelpWindowPrivate)) | ||
4087 | 154 | |||
4088 | 155 | static const gchar *YELP_UI = | ||
4089 | 156 | "<ui>" | ||
4090 | 157 | "<menubar>" | ||
4091 | 158 | "<menu action='PageMenu'>" | ||
4092 | 159 | "<menuitem action='NewWindow'/>" | ||
4093 | 160 | "<menuitem action='Find'/>" | ||
4094 | 161 | "<separator/>" | ||
4095 | 162 | "<menuitem action='YelpViewPrint'/>" | ||
4096 | 163 | "<separator/>" | ||
4097 | 164 | "<menuitem action='CloseWindow'/>" | ||
4098 | 165 | "</menu>" | ||
4099 | 166 | "<menu action='ViewMenu'>" | ||
4100 | 167 | "<menuitem action='LargerText'/>" | ||
4101 | 168 | "<menuitem action='SmallerText'/>" | ||
4102 | 169 | "<separator/>" | ||
4103 | 170 | "<menuitem action='ShowTextCursor'/>" | ||
4104 | 171 | "</menu>" | ||
4105 | 172 | "<menu action='GoMenu'>" | ||
4106 | 173 | "<menuitem action='YelpViewGoBack'/>" | ||
4107 | 174 | "<menuitem action='YelpViewGoForward'/>" | ||
4108 | 175 | "<separator/>" | ||
4109 | 176 | "<menuitem action='YelpViewGoPrevious'/>" | ||
4110 | 177 | "<menuitem action='YelpViewGoNext'/>" | ||
4111 | 178 | "<separator/>" | ||
4112 | 179 | "<menuitem action='GoAll'/>" | ||
4113 | 180 | "</menu>" | ||
4114 | 181 | "<menu action='BookmarksMenu'>" | ||
4115 | 182 | "<menuitem action='AddBookmark'/>" | ||
4116 | 183 | "<menuitem action='RemoveBookmark'/>" | ||
4117 | 184 | "<separator/>" | ||
4118 | 185 | "<placeholder name='Bookmarks'/>" | ||
4119 | 186 | "</menu>" | ||
4120 | 187 | "</menubar>" | ||
4121 | 188 | "<accelerator action='Find'/>" | ||
4122 | 189 | "<accelerator action='Search'/>" | ||
4123 | 190 | "<accelerator action='OpenLocation'/>" | ||
4124 | 191 | "</ui>"; | ||
4125 | 192 | |||
4126 | 193 | typedef struct _YelpWindowPrivate YelpWindowPrivate; | ||
4127 | 194 | struct _YelpWindowPrivate { | ||
4128 | 195 | GtkListStore *history; | ||
4129 | 196 | GtkUIManager *ui_manager; | ||
4130 | 197 | GtkActionGroup *action_group; | ||
4131 | 198 | YelpApplication *application; | ||
4132 | 199 | |||
4133 | 200 | gulong bookmarks_changed; | ||
4134 | 201 | gulong read_later_changed; | ||
4135 | 202 | |||
4136 | 203 | /* no refs on these, owned by containers */ | ||
4137 | 204 | YelpView *view; | ||
4138 | 205 | GtkWidget *vbox_view; | ||
4139 | 206 | GtkWidget *vbox_full; | ||
4140 | 207 | GtkWidget *hbox; | ||
4141 | 208 | YelpLocationEntry *entry; | ||
4142 | 209 | GtkWidget *hidden_entry; | ||
4143 | 210 | GtkWidget *find_entry; | ||
4144 | 211 | GtkWidget *find_label; | ||
4145 | 212 | GtkWidget *read_later_vbox; | ||
4146 | 213 | |||
4147 | 214 | /* refs because we dynamically add & remove */ | ||
4148 | 215 | GtkWidget *find_bar; | ||
4149 | 216 | GtkWidget *align_location; | ||
4150 | 217 | GtkWidget *align_hidden; | ||
4151 | 218 | GtkWidget *read_later; | ||
4152 | 219 | |||
4153 | 220 | gchar *doc_uri; | ||
4154 | 221 | |||
4155 | 222 | GtkActionGroup *bookmark_actions; | ||
4156 | 223 | guint bookmarks_merge_id; | ||
4157 | 224 | |||
4158 | 225 | guint resize_signal; | ||
4159 | 226 | gint width; | ||
4160 | 227 | gint height; | ||
4161 | 228 | |||
4162 | 229 | guint entry_color_animate; | ||
4163 | 230 | gfloat entry_color_step; | ||
4164 | 231 | |||
4165 | 232 | gboolean configured; | ||
4166 | 233 | }; | ||
4167 | 234 | |||
4168 | 235 | static const GtkActionEntry entries[] = { | ||
4169 | 236 | { "PageMenu", NULL, N_("_Page") }, | ||
4170 | 237 | { "ViewMenu", NULL, N_("_View") }, | ||
4171 | 238 | { "GoMenu", NULL, N_("_Go") }, | ||
4172 | 239 | { "BookmarksMenu", NULL, N_("_Bookmarks") }, | ||
4173 | 240 | |||
4174 | 241 | { "NewWindow", NULL, | ||
4175 | 242 | N_("_New Window"), | ||
4176 | 243 | "<Control>N", | ||
4177 | 244 | NULL, | ||
4178 | 245 | G_CALLBACK (window_new) }, | ||
4179 | 246 | { "CloseWindow", NULL, | ||
4180 | 247 | N_("_Close"), | ||
4181 | 248 | "<Control>W", | ||
4182 | 249 | NULL, | ||
4183 | 250 | G_CALLBACK (window_close) }, | ||
4184 | 251 | { "GoAll", NULL, | ||
4185 | 252 | N_("_All Documents"), | ||
4186 | 253 | NULL, NULL, | ||
4187 | 254 | G_CALLBACK (window_go_all) }, | ||
4188 | 255 | { "AddBookmark", NULL, | ||
4189 | 256 | N_("_Add Bookmark"), | ||
4190 | 257 | "<Control>D", | ||
4191 | 258 | NULL, | ||
4192 | 259 | G_CALLBACK (window_add_bookmark) }, | ||
4193 | 260 | { "RemoveBookmark", NULL, | ||
4194 | 261 | N_("_Remove Bookmark"), | ||
4195 | 262 | NULL, NULL, | ||
4196 | 263 | G_CALLBACK (window_remove_bookmark) }, | ||
4197 | 264 | { "Find", NULL, | ||
4198 | 265 | N_("Find in Page..."), | ||
4199 | 266 | "<Control>F", | ||
4200 | 267 | NULL, | ||
4201 | 268 | G_CALLBACK (window_find_in_page) }, | ||
4202 | 269 | { "Search", NULL, | ||
4203 | 270 | N_("Search..."), | ||
4204 | 271 | "<Control>S", | ||
4205 | 272 | NULL, | ||
4206 | 273 | G_CALLBACK (window_start_search) }, | ||
4207 | 274 | { "OpenLocation", NULL, | ||
4208 | 275 | N_("Open Location"), | ||
4209 | 276 | "<Control>L", | ||
4210 | 277 | NULL, | ||
4211 | 278 | G_CALLBACK (window_open_location) } | ||
4212 | 279 | }; | ||
4213 | 280 | |||
4214 | 281 | static void | ||
4215 | 282 | yelp_window_init (YelpWindow *window) | ||
4216 | 283 | { | ||
4217 | 284 | g_signal_connect (window, "configure-event", G_CALLBACK (window_configure_event), NULL); | ||
4218 | 285 | g_signal_connect (window, "map-event", G_CALLBACK (window_map_event), NULL); | ||
4219 | 286 | } | ||
4220 | 287 | |||
4221 | 288 | static void | ||
4222 | 289 | yelp_window_class_init (YelpWindowClass *klass) | ||
4223 | 290 | { | ||
4224 | 291 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | ||
4225 | 292 | |||
4226 | 293 | object_class->dispose = yelp_window_dispose; | ||
4227 | 294 | object_class->finalize = yelp_window_finalize; | ||
4228 | 295 | object_class->get_property = yelp_window_get_property; | ||
4229 | 296 | object_class->set_property = yelp_window_set_property; | ||
4230 | 297 | |||
4231 | 298 | g_object_class_install_property (object_class, | ||
4232 | 299 | PROP_APPLICATION, | ||
4233 | 300 | g_param_spec_object ("application", | ||
4234 | 301 | _("Application"), | ||
4235 | 302 | _("A YelpApplication instance that controls this window"), | ||
4236 | 303 | YELP_TYPE_APPLICATION, | ||
4237 | 304 | G_PARAM_CONSTRUCT_ONLY | | ||
4238 | 305 | G_PARAM_READWRITE | G_PARAM_STATIC_NAME | | ||
4239 | 306 | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); | ||
4240 | 307 | |||
4241 | 308 | signals[RESIZE_EVENT] = | ||
4242 | 309 | g_signal_new ("resized", | ||
4243 | 310 | G_OBJECT_CLASS_TYPE (klass), | ||
4244 | 311 | G_SIGNAL_RUN_LAST, | ||
4245 | 312 | 0, NULL, NULL, | ||
4246 | 313 | g_cclosure_marshal_VOID__VOID, | ||
4247 | 314 | G_TYPE_NONE, 0); | ||
4248 | 315 | |||
4249 | 316 | g_type_class_add_private (klass, sizeof (YelpWindowPrivate)); | ||
4250 | 317 | } | ||
4251 | 318 | |||
4252 | 319 | static void | ||
4253 | 320 | yelp_window_dispose (GObject *object) | ||
4254 | 321 | { | ||
4255 | 322 | YelpWindowPrivate *priv = GET_PRIV (object); | ||
4256 | 323 | |||
4257 | 324 | if (priv->history) { | ||
4258 | 325 | g_object_unref (priv->history); | ||
4259 | 326 | priv->history = NULL; | ||
4260 | 327 | } | ||
4261 | 328 | |||
4262 | 329 | if (priv->action_group) { | ||
4263 | 330 | g_object_unref (priv->action_group); | ||
4264 | 331 | priv->action_group = NULL; | ||
4265 | 332 | } | ||
4266 | 333 | |||
4267 | 334 | if (priv->bookmark_actions) { | ||
4268 | 335 | g_object_unref (priv->bookmark_actions); | ||
4269 | 336 | priv->bookmark_actions = NULL; | ||
4270 | 337 | } | ||
4271 | 338 | |||
4272 | 339 | if (priv->read_later_changed) { | ||
4273 | 340 | g_source_remove (priv->read_later_changed); | ||
4274 | 341 | priv->read_later_changed = 0; | ||
4275 | 342 | } | ||
4276 | 343 | |||
4277 | 344 | if (priv->bookmarks_changed) { | ||
4278 | 345 | g_source_remove (priv->bookmarks_changed); | ||
4279 | 346 | priv->bookmarks_changed = 0; | ||
4280 | 347 | } | ||
4281 | 348 | |||
4282 | 349 | if (priv->align_location) { | ||
4283 | 350 | g_object_unref (priv->align_location); | ||
4284 | 351 | priv->align_location = NULL; | ||
4285 | 352 | } | ||
4286 | 353 | |||
4287 | 354 | if (priv->align_hidden) { | ||
4288 | 355 | g_object_unref (priv->align_hidden); | ||
4289 | 356 | priv->align_hidden = NULL; | ||
4290 | 357 | } | ||
4291 | 358 | |||
4292 | 359 | if (priv->find_bar) { | ||
4293 | 360 | g_object_unref (priv->find_bar); | ||
4294 | 361 | priv->find_bar = NULL; | ||
4295 | 362 | } | ||
4296 | 363 | |||
4297 | 364 | if (priv->entry_color_animate != 0) { | ||
4298 | 365 | g_source_remove (priv->entry_color_animate); | ||
4299 | 366 | priv->entry_color_animate = 0; | ||
4300 | 367 | } | ||
4301 | 368 | |||
4302 | 369 | G_OBJECT_CLASS (yelp_window_parent_class)->dispose (object); | ||
4303 | 370 | } | ||
4304 | 371 | |||
4305 | 372 | static void | ||
4306 | 373 | yelp_window_finalize (GObject *object) | ||
4307 | 374 | { | ||
4308 | 375 | YelpWindowPrivate *priv = GET_PRIV (object); | ||
4309 | 376 | g_free (priv->doc_uri); | ||
4310 | 377 | G_OBJECT_CLASS (yelp_window_parent_class)->finalize (object); | ||
4311 | 378 | } | ||
4312 | 379 | |||
4313 | 380 | static void | ||
4314 | 381 | yelp_window_get_property (GObject *object, | ||
4315 | 382 | guint prop_id, | ||
4316 | 383 | GValue *value, | ||
4317 | 384 | GParamSpec *pspec) | ||
4318 | 385 | { | ||
4319 | 386 | YelpWindowPrivate *priv = GET_PRIV (object); | ||
4320 | 387 | switch (prop_id) { | ||
4321 | 388 | case PROP_APPLICATION: | ||
4322 | 389 | g_value_set_object (value, priv->application); | ||
4323 | 390 | break; | ||
4324 | 391 | default: | ||
4325 | 392 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | ||
4326 | 393 | break; | ||
4327 | 394 | } | ||
4328 | 395 | } | ||
4329 | 396 | |||
4330 | 397 | static void | ||
4331 | 398 | yelp_window_set_property (GObject *object, | ||
4332 | 399 | guint prop_id, | ||
4333 | 400 | const GValue *value, | ||
4334 | 401 | GParamSpec *pspec) | ||
4335 | 402 | { | ||
4336 | 403 | YelpWindowPrivate *priv = GET_PRIV (object); | ||
4337 | 404 | switch (prop_id) { | ||
4338 | 405 | case PROP_APPLICATION: | ||
4339 | 406 | priv->application = g_value_get_object (value); | ||
4340 | 407 | window_construct ((YelpWindow *) object); | ||
4341 | 408 | break; | ||
4342 | 409 | default: | ||
4343 | 410 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | ||
4344 | 411 | break; | ||
4345 | 412 | } | ||
4346 | 413 | } | ||
4347 | 414 | |||
4348 | 415 | static void | ||
4349 | 416 | window_construct (YelpWindow *window) | ||
4350 | 417 | { | ||
4351 | 418 | GtkWidget *scroll; | ||
4352 | 419 | GtkActionGroup *view_actions; | ||
4353 | 420 | GtkAction *action; | ||
4354 | 421 | GtkWidget *vbox, *button, *label; | ||
4355 | 422 | gchar *color, *text; | ||
4356 | 423 | YelpWindowPrivate *priv = GET_PRIV (window); | ||
4357 | 424 | |||
4358 | 425 | gtk_window_set_icon_name (GTK_WINDOW (window), "help-browser"); | ||
4359 | 426 | |||
4360 | 427 | priv->view = (YelpView *) yelp_view_new (); | ||
4361 | 428 | |||
4362 | 429 | action = gtk_action_new ("ReadLinkLater", _("Read Link _Later"), NULL, NULL); | ||
4363 | 430 | g_signal_connect (action, "activate", G_CALLBACK (window_read_later), window); | ||
4364 | 431 | yelp_view_add_link_action (priv->view, action, | ||
4365 | 432 | (YelpViewActionValidFunc) view_is_xref_uri, | ||
4366 | 433 | window); | ||
4367 | 434 | priv->read_later_changed = | ||
4368 | 435 | g_signal_connect (priv->application, "read-later-changed", | ||
4369 | 436 | G_CALLBACK (app_read_later_changed), window); | ||
4370 | 437 | |||
4371 | 438 | priv->vbox_full = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3); | ||
4372 | 439 | gtk_container_add (GTK_CONTAINER (window), priv->vbox_full); | ||
4373 | 440 | |||
4374 | 441 | priv->vbox_view = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); | ||
4375 | 442 | gtk_box_pack_start (GTK_BOX (priv->vbox_full), priv->vbox_view, TRUE, TRUE, 0); | ||
4376 | 443 | |||
4377 | 444 | priv->action_group = gtk_action_group_new ("YelpWindowActions"); | ||
4378 | 445 | gtk_action_group_set_translation_domain (priv->action_group, GETTEXT_PACKAGE); | ||
4379 | 446 | gtk_action_group_add_actions (priv->action_group, | ||
4380 | 447 | entries, G_N_ELEMENTS (entries), | ||
4381 | 448 | window); | ||
4382 | 449 | |||
4383 | 450 | priv->bookmark_actions = gtk_action_group_new ("BookmarkActions"); | ||
4384 | 451 | gtk_action_group_set_translate_func (priv->bookmark_actions, NULL, NULL, NULL); | ||
4385 | 452 | |||
4386 | 453 | priv->ui_manager = gtk_ui_manager_new (); | ||
4387 | 454 | gtk_ui_manager_insert_action_group (priv->ui_manager, priv->action_group, 0); | ||
4388 | 455 | gtk_ui_manager_insert_action_group (priv->ui_manager, priv->bookmark_actions, 1); | ||
4389 | 456 | gtk_ui_manager_insert_action_group (priv->ui_manager, | ||
4390 | 457 | yelp_application_get_action_group (priv->application), | ||
4391 | 458 | 2); | ||
4392 | 459 | view_actions = yelp_view_get_action_group (priv->view); | ||
4393 | 460 | gtk_ui_manager_insert_action_group (priv->ui_manager, view_actions, 3); | ||
4394 | 461 | gtk_window_add_accel_group (GTK_WINDOW (window), | ||
4395 | 462 | gtk_ui_manager_get_accel_group (priv->ui_manager)); | ||
4396 | 463 | gtk_ui_manager_add_ui_from_string (priv->ui_manager, YELP_UI, -1, NULL); | ||
4397 | 464 | gtk_box_pack_start (GTK_BOX (priv->vbox_view), | ||
4398 | 465 | gtk_ui_manager_get_widget (priv->ui_manager, "/ui/menubar"), | ||
4399 | 466 | FALSE, FALSE, 0); | ||
4400 | 467 | |||
4401 | 468 | priv->bookmarks_merge_id = gtk_ui_manager_new_merge_id (priv->ui_manager); | ||
4402 | 469 | priv->bookmarks_changed = | ||
4403 | 470 | g_signal_connect (priv->application, "bookmarks-changed", | ||
4404 | 471 | G_CALLBACK (app_bookmarks_changed), window); | ||
4405 | 472 | |||
4406 | 473 | priv->hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); | ||
4407 | 474 | g_object_set (priv->hbox, "border-width", 2, NULL); | ||
4408 | 475 | gtk_box_pack_start (GTK_BOX (priv->vbox_view), priv->hbox, FALSE, FALSE, 0); | ||
4409 | 476 | |||
4410 | 477 | action = gtk_action_group_get_action (view_actions, "YelpViewGoBack"); | ||
4411 | 478 | button = gtk_action_create_tool_item (action); | ||
4412 | 479 | gtk_box_pack_start (GTK_BOX (priv->hbox), | ||
4413 | 480 | button, | ||
4414 | 481 | FALSE, FALSE, 0); | ||
4415 | 482 | action = gtk_action_group_get_action (view_actions, "YelpViewGoForward"); | ||
4416 | 483 | button = gtk_action_create_tool_item (action); | ||
4417 | 484 | gtk_box_pack_start (GTK_BOX (priv->hbox), | ||
4418 | 485 | button, | ||
4419 | 486 | FALSE, FALSE, 0); | ||
4420 | 487 | |||
4421 | 488 | priv->entry = (YelpLocationEntry *) yelp_location_entry_new (priv->view, | ||
4422 | 489 | YELP_BOOKMARKS (priv->application)); | ||
4423 | 490 | g_signal_connect (gtk_bin_get_child (GTK_BIN (priv->entry)), "focus-in-event", | ||
4424 | 491 | G_CALLBACK (entry_focus_in), window); | ||
4425 | 492 | g_signal_connect (priv->entry, "focus-out-event", | ||
4426 | 493 | G_CALLBACK (entry_focus_out), window); | ||
4427 | 494 | |||
4428 | 495 | priv->align_location = g_object_ref_sink (gtk_alignment_new (0.0, 0.5, 1.0, 0.0)); | ||
4429 | 496 | gtk_box_pack_start (GTK_BOX (priv->hbox), | ||
4430 | 497 | GTK_WIDGET (priv->align_location), | ||
4431 | 498 | TRUE, TRUE, 0); | ||
4432 | 499 | gtk_container_add (GTK_CONTAINER (priv->align_location), GTK_WIDGET (priv->entry)); | ||
4433 | 500 | |||
4434 | 501 | priv->hidden_entry = gtk_entry_new (); | ||
4435 | 502 | priv->align_hidden = g_object_ref_sink (gtk_alignment_new (0.0, 0.5, 1.0, 0.0)); | ||
4436 | 503 | gtk_container_add (GTK_CONTAINER (priv->align_hidden), GTK_WIDGET (priv->hidden_entry)); | ||
4437 | 504 | |||
4438 | 505 | g_signal_connect (priv->hidden_entry, "activate", | ||
4439 | 506 | G_CALLBACK (hidden_entry_activate), window); | ||
4440 | 507 | g_signal_connect_swapped (priv->hidden_entry, "focus-out-event", | ||
4441 | 508 | G_CALLBACK (hidden_entry_hide), window); | ||
4442 | 509 | g_signal_connect (priv->hidden_entry, "key-press-event", | ||
4443 | 510 | G_CALLBACK (hidden_key_press), window); | ||
4444 | 511 | |||
4445 | 512 | scroll = gtk_scrolled_window_new (NULL, NULL); | ||
4446 | 513 | gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), | ||
4447 | 514 | GTK_POLICY_AUTOMATIC, | ||
4448 | 515 | GTK_POLICY_AUTOMATIC); | ||
4449 | 516 | gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), | ||
4450 | 517 | GTK_SHADOW_IN); | ||
4451 | 518 | gtk_box_pack_start (GTK_BOX (priv->vbox_view), scroll, TRUE, TRUE, 0); | ||
4452 | 519 | |||
4453 | 520 | priv->find_bar = g_object_ref_sink (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6)); | ||
4454 | 521 | g_object_set (priv->find_bar, | ||
4455 | 522 | "border-width", 2, | ||
4456 | 523 | "margin-right", 16, | ||
4457 | 524 | NULL); | ||
4458 | 525 | |||
4459 | 526 | label = gtk_label_new (_("Find:")); | ||
4460 | 527 | gtk_box_pack_start (GTK_BOX (priv->find_bar), label, FALSE, FALSE, 6); | ||
4461 | 528 | |||
4462 | 529 | priv->find_entry = gtk_entry_new (); | ||
4463 | 530 | g_signal_connect (priv->find_entry, "changed", | ||
4464 | 531 | G_CALLBACK (find_entry_changed), window); | ||
4465 | 532 | g_signal_connect (priv->find_entry, "key-press-event", | ||
4466 | 533 | G_CALLBACK (find_entry_key_press), window); | ||
4467 | 534 | g_signal_connect (priv->find_entry, "focus-out-event", | ||
4468 | 535 | G_CALLBACK (find_entry_focus_out), window); | ||
4469 | 536 | g_object_set (priv->find_entry, "width-request", 300, NULL); | ||
4470 | 537 | gtk_box_pack_start (GTK_BOX (priv->find_bar), priv->find_entry, FALSE, FALSE, 0); | ||
4471 | 538 | |||
4472 | 539 | priv->find_label = gtk_label_new (""); | ||
4473 | 540 | g_object_set (priv->find_label, "xalign", 0.0, NULL); | ||
4474 | 541 | gtk_box_pack_start (GTK_BOX (priv->find_bar), priv->find_label, FALSE, FALSE, 0); | ||
4475 | 542 | |||
4476 | 543 | priv->read_later = g_object_ref_sink (gtk_info_bar_new ()); | ||
4477 | 544 | vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); | ||
4478 | 545 | color = yelp_settings_get_color (yelp_settings_get_default (), | ||
4479 | 546 | YELP_SETTINGS_COLOR_TEXT_LIGHT); | ||
4480 | 547 | text = g_markup_printf_escaped ("<span weight='bold' color='%s'>%s</span>", | ||
4481 | 548 | color, _("Read Later")); | ||
4482 | 549 | button = gtk_label_new (text); | ||
4483 | 550 | g_object_set (button, "use-markup", TRUE, "xalign", 0.0, NULL); | ||
4484 | 551 | g_free (color); | ||
4485 | 552 | g_free (text); | ||
4486 | 553 | gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); | ||
4487 | 554 | gtk_box_pack_start (GTK_BOX (gtk_info_bar_get_content_area (GTK_INFO_BAR (priv->read_later))), | ||
4488 | 555 | vbox, | ||
4489 | 556 | FALSE, FALSE, 0); | ||
4490 | 557 | priv->read_later_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); | ||
4491 | 558 | gtk_box_pack_start (GTK_BOX (vbox), priv->read_later_vbox, FALSE, FALSE, 0); | ||
4492 | 559 | |||
4493 | 560 | g_signal_connect (priv->view, "new-view-requested", G_CALLBACK (view_new_window), window); | ||
4494 | 561 | g_signal_connect (priv->view, "loaded", G_CALLBACK (view_loaded), window); | ||
4495 | 562 | g_signal_connect (priv->view, "notify::yelp-uri", G_CALLBACK (view_uri_selected), window); | ||
4496 | 563 | g_signal_connect_swapped (priv->view, "notify::page-id", | ||
4497 | 564 | G_CALLBACK (window_set_bookmark_action), window); | ||
4498 | 565 | window_set_bookmark_action (window); | ||
4499 | 566 | g_signal_connect (priv->view, "notify::root-title", G_CALLBACK (view_root_title), window); | ||
4500 | 567 | gtk_container_add (GTK_CONTAINER (scroll), GTK_WIDGET (priv->view)); | ||
4501 | 568 | gtk_widget_grab_focus (GTK_WIDGET (priv->view)); | ||
4502 | 569 | |||
4503 | 570 | gtk_drag_dest_set (GTK_WIDGET (window), | ||
4504 | 571 | GTK_DEST_DEFAULT_ALL, | ||
4505 | 572 | NULL, 0, | ||
4506 | 573 | GDK_ACTION_COPY); | ||
4507 | 574 | gtk_drag_dest_add_uri_targets (GTK_WIDGET (window)); | ||
4508 | 575 | g_signal_connect (window, "drag-data-received", | ||
4509 | 576 | G_CALLBACK (window_drag_received), NULL); | ||
4510 | 577 | } | ||
4511 | 578 | |||
4512 | 579 | /******************************************************************************/ | ||
4513 | 580 | |||
4514 | 581 | YelpWindow * | ||
4515 | 582 | yelp_window_new (YelpApplication *app) | ||
4516 | 583 | { | ||
4517 | 584 | YelpWindow *window; | ||
4518 | 585 | |||
4519 | 586 | window = (YelpWindow *) g_object_new (YELP_TYPE_WINDOW, "application", app, NULL); | ||
4520 | 587 | |||
4521 | 588 | return window; | ||
4522 | 589 | } | ||
4523 | 590 | |||
4524 | 591 | void | ||
4525 | 592 | yelp_window_load_uri (YelpWindow *window, | ||
4526 | 593 | YelpUri *uri) | ||
4527 | 594 | { | ||
4528 | 595 | YelpWindowPrivate *priv = GET_PRIV (window); | ||
4529 | 596 | |||
4530 | 597 | yelp_view_load_uri (priv->view, uri); | ||
4531 | 598 | } | ||
4532 | 599 | |||
4533 | 600 | YelpUri * | ||
4534 | 601 | yelp_window_get_uri (YelpWindow *window) | ||
4535 | 602 | { | ||
4536 | 603 | YelpUri *uri; | ||
4537 | 604 | YelpWindowPrivate *priv = GET_PRIV (window); | ||
4538 | 605 | g_object_get (G_OBJECT (priv->view), "yelp-uri", &uri, NULL); | ||
4539 | 606 | return uri; | ||
4540 | 607 | } | ||
4541 | 608 | |||
4542 | 609 | void | ||
4543 | 610 | yelp_window_get_geometry (YelpWindow *window, | ||
4544 | 611 | gint *width, | ||
4545 | 612 | gint *height) | ||
4546 | 613 | { | ||
4547 | 614 | YelpWindowPrivate *priv = GET_PRIV (window); | ||
4548 | 615 | *width = priv->width; | ||
4549 | 616 | *height = priv->height; | ||
4550 | 617 | } | ||
4551 | 618 | |||
4552 | 619 | /******************************************************************************/ | ||
4553 | 620 | |||
4554 | 621 | static void | ||
4555 | 622 | window_new (GtkAction *action, YelpWindow *window) | ||
4556 | 623 | { | ||
4557 | 624 | YelpUri *yuri; | ||
4558 | 625 | gchar *uri = NULL; | ||
4559 | 626 | YelpWindowPrivate *priv = GET_PRIV (window); | ||
4560 | 627 | |||
4561 | 628 | g_object_get (priv->view, "yelp-uri", &yuri, NULL); | ||
4562 | 629 | uri = yelp_uri_get_document_uri (yuri); | ||
4563 | 630 | |||
4564 | 631 | yelp_application_new_window (priv->application, uri); | ||
4565 | 632 | |||
4566 | 633 | g_free (uri); | ||
4567 | 634 | g_object_unref (yuri); | ||
4568 | 635 | } | ||
4569 | 636 | |||
4570 | 637 | static void | ||
4571 | 638 | window_drag_received (YelpWindow *window, | ||
4572 | 639 | GdkDragContext *context, | ||
4573 | 640 | gint x, | ||
4574 | 641 | gint y, | ||
4575 | 642 | GtkSelectionData *data, | ||
4576 | 643 | guint info, | ||
4577 | 644 | guint time, | ||
4578 | 645 | gpointer userdata) | ||
4579 | 646 | { | ||
4580 | 647 | gchar **uris = gtk_selection_data_get_uris (data); | ||
4581 | 648 | if (uris && uris[0]) { | ||
4582 | 649 | YelpUri *uri = yelp_uri_new (uris[0]); | ||
4583 | 650 | yelp_window_load_uri (window, uri); | ||
4584 | 651 | g_object_unref (uri); | ||
4585 | 652 | g_strfreev (uris); | ||
4586 | 653 | gtk_drag_finish (context, TRUE, FALSE, time); | ||
4587 | 654 | } | ||
4588 | 655 | gtk_drag_finish (context, FALSE, FALSE, time); | ||
4589 | 656 | } | ||
4590 | 657 | |||
4591 | 658 | static gboolean | ||
4592 | 659 | window_map_event (YelpWindow *window, | ||
4593 | 660 | GdkEvent *event, | ||
4594 | 661 | gpointer user_data) | ||
4595 | 662 | { | ||
4596 | 663 | YelpWindowPrivate *priv = GET_PRIV (window); | ||
4597 | 664 | priv->configured = TRUE; | ||
4598 | 665 | return FALSE; | ||
4599 | 666 | } | ||
4600 | 667 | |||
4601 | 668 | static gboolean | ||
4602 | 669 | window_configure_event (YelpWindow *window, | ||
4603 | 670 | GdkEventConfigure *event, | ||
4604 | 671 | gpointer user_data) | ||
4605 | 672 | { | ||
4606 | 673 | YelpWindowPrivate *priv = GET_PRIV (window); | ||
4607 | 674 | gboolean skip = TRUE; | ||
4608 | 675 | if (priv->width != event->width) { | ||
4609 | 676 | skip = FALSE; | ||
4610 | 677 | priv->width = event->width; | ||
4611 | 678 | } | ||
4612 | 679 | if (priv->height != event->height) { | ||
4613 | 680 | skip = FALSE; | ||
4614 | 681 | priv->height = event->height; | ||
4615 | 682 | } | ||
4616 | 683 | /* Skip the configure-event signals that GTK+ sends as it's mapping | ||
4617 | 684 | * the window, and also skip if the event didn't change the size of | ||
4618 | 685 | * the window (i.e. it was just a move). | ||
4619 | 686 | */ | ||
4620 | 687 | if (!priv->configured || skip) | ||
4621 | 688 | return FALSE; | ||
4622 | 689 | |||
4623 | 690 | if (priv->resize_signal > 0) | ||
4624 | 691 | g_source_remove (priv->resize_signal); | ||
4625 | 692 | priv->resize_signal = g_timeout_add (200, | ||
4626 | 693 | (GSourceFunc) window_resize_signal, | ||
4627 | 694 | window); | ||
4628 | 695 | g_object_set (priv->find_entry, "width-request", 2 * priv->width / 3, NULL); | ||
4629 | 696 | return FALSE; | ||
4630 | 697 | } | ||
4631 | 698 | |||
4632 | 699 | static gboolean | ||
4633 | 700 | window_resize_signal (YelpWindow *window) | ||
4634 | 701 | { | ||
4635 | 702 | YelpWindowPrivate *priv = GET_PRIV (window); | ||
4636 | 703 | g_signal_emit (window, signals[RESIZE_EVENT], 0); | ||
4637 | 704 | priv->resize_signal = 0; | ||
4638 | 705 | return FALSE; | ||
4639 | 706 | } | ||
4640 | 707 | |||
4641 | 708 | static void | ||
4642 | 709 | window_close (GtkAction *action, YelpWindow *window) | ||
4643 | 710 | { | ||
4644 | 711 | gboolean ret; | ||
4645 | 712 | g_signal_emit_by_name (window, "delete-event", NULL, &ret); | ||
4646 | 713 | gtk_widget_destroy (GTK_WIDGET (window)); | ||
4647 | 714 | } | ||
4648 | 715 | |||
4649 | 716 | static void | ||
4650 | 717 | window_go_all (GtkAction *action, | ||
4651 | 718 | YelpWindow *window) | ||
4652 | 719 | { | ||
4653 | 720 | YelpWindowPrivate *priv = GET_PRIV (window); | ||
4654 | 721 | yelp_view_load (priv->view, "help-list:"); | ||
4655 | 722 | } | ||
4656 | 723 | |||
4657 | 724 | static void | ||
4658 | 725 | window_add_bookmark (GtkAction *action, | ||
4659 | 726 | YelpWindow *window) | ||
4660 | 727 | { | ||
4661 | 728 | YelpUri *uri; | ||
4662 | 729 | gchar *doc_uri, *page_id, *icon, *title; | ||
4663 | 730 | YelpWindowPrivate *priv = GET_PRIV (window); | ||
4664 | 731 | |||
4665 | 732 | g_object_get (priv->view, | ||
4666 | 733 | "yelp-uri", &uri, | ||
4667 | 734 | "page-id", &page_id, | ||
4668 | 735 | "page-icon", &icon, | ||
4669 | 736 | "page-title", &title, | ||
4670 | 737 | NULL); | ||
4671 | 738 | doc_uri = yelp_uri_get_document_uri (uri); | ||
4672 | 739 | yelp_application_add_bookmark (YELP_BOOKMARKS (priv->application), | ||
4673 | 740 | doc_uri, page_id, icon, title); | ||
4674 | 741 | g_free (doc_uri); | ||
4675 | 742 | g_free (page_id); | ||
4676 | 743 | g_free (icon); | ||
4677 | 744 | g_free (title); | ||
4678 | 745 | g_object_unref (uri); | ||
4679 | 746 | } | ||
4680 | 747 | |||
4681 | 748 | static void | ||
4682 | 749 | window_remove_bookmark (GtkAction *action, | ||
4683 | 750 | YelpWindow *window) | ||
4684 | 751 | { | ||
4685 | 752 | YelpUri *uri; | ||
4686 | 753 | gchar *doc_uri, *page_id; | ||
4687 | 754 | YelpWindowPrivate *priv = GET_PRIV (window); | ||
4688 | 755 | |||
4689 | 756 | g_object_get (priv->view, | ||
4690 | 757 | "yelp-uri", &uri, | ||
4691 | 758 | "page-id", &page_id, | ||
4692 | 759 | NULL); | ||
4693 | 760 | doc_uri = yelp_uri_get_document_uri (uri); | ||
4694 | 761 | yelp_application_remove_bookmark (YELP_BOOKMARKS (priv->application), | ||
4695 | 762 | doc_uri, page_id); | ||
4696 | 763 | g_free (doc_uri); | ||
4697 | 764 | g_free (page_id); | ||
4698 | 765 | g_object_unref (uri); | ||
4699 | 766 | } | ||
4700 | 767 | static void | ||
4701 | 768 | window_load_bookmark (GtkAction *action, | ||
4702 | 769 | YelpWindow *window) | ||
4703 | 770 | { | ||
4704 | 771 | YelpUri *base, *uri; | ||
4705 | 772 | gchar *xref; | ||
4706 | 773 | YelpWindowPrivate *priv = GET_PRIV (window); | ||
4707 | 774 | |||
4708 | 775 | /* Bookmark action names are prefixed with 'LoadBookmark-' */ | ||
4709 | 776 | xref = g_strconcat ("xref:", gtk_action_get_name (action) + 13, NULL); | ||
4710 | 777 | g_object_get (priv->view, "yelp-uri", &base, NULL); | ||
4711 | 778 | uri = yelp_uri_new_relative (base, xref); | ||
4712 | 779 | |||
4713 | 780 | yelp_view_load_uri (priv->view, uri); | ||
4714 | 781 | |||
4715 | 782 | g_object_unref (base); | ||
4716 | 783 | g_object_unref (uri); | ||
4717 | 784 | g_free (xref); | ||
4718 | 785 | } | ||
4719 | 786 | |||
4720 | 787 | static void | ||
4721 | 788 | app_bookmarks_changed (YelpApplication *app, | ||
4722 | 789 | const gchar *doc_uri, | ||
4723 | 790 | YelpWindow *window) | ||
4724 | 791 | { | ||
4725 | 792 | YelpUri *uri; | ||
4726 | 793 | gchar *this_doc_uri; | ||
4727 | 794 | YelpWindowPrivate *priv = GET_PRIV (window); | ||
4728 | 795 | |||
4729 | 796 | g_object_get (priv->view, "yelp-uri", &uri, NULL); | ||
4730 | 797 | this_doc_uri = yelp_uri_get_document_uri (uri); | ||
4731 | 798 | |||
4732 | 799 | if (g_str_equal (this_doc_uri, doc_uri)) { | ||
4733 | 800 | window_set_bookmarks (window, doc_uri); | ||
4734 | 801 | } | ||
4735 | 802 | |||
4736 | 803 | g_free (this_doc_uri); | ||
4737 | 804 | g_object_unref (uri); | ||
4738 | 805 | } | ||
4739 | 806 | |||
4740 | 807 | typedef struct _YelpMenuEntry YelpMenuEntry; | ||
4741 | 808 | struct _YelpMenuEntry { | ||
4742 | 809 | gchar *page_id; | ||
4743 | 810 | gchar *icon; | ||
4744 | 811 | gchar *title; | ||
4745 | 812 | }; | ||
4746 | 813 | |||
4747 | 814 | static gint | ||
4748 | 815 | entry_compare (YelpMenuEntry *a, YelpMenuEntry *b) | ||
4749 | 816 | { | ||
4750 | 817 | gint ret = yelp_settings_cmp_icons (a->icon, b->icon); | ||
4751 | 818 | if (ret != 0) | ||
4752 | 819 | return ret; | ||
4753 | 820 | |||
4754 | 821 | if (a->title && b->title) | ||
4755 | 822 | return g_utf8_collate (a->title, b->title); | ||
4756 | 823 | else if (b->title == NULL) | ||
4757 | 824 | return -1; | ||
4758 | 825 | else if (a->title == NULL) | ||
4759 | 826 | return 1; | ||
4760 | 827 | |||
4761 | 828 | return 0; | ||
4762 | 829 | } | ||
4763 | 830 | |||
4764 | 831 | static void | ||
4765 | 832 | window_set_bookmarks (YelpWindow *window, | ||
4766 | 833 | const gchar *doc_uri) | ||
4767 | 834 | { | ||
4768 | 835 | GVariant *value; | ||
4769 | 836 | GVariantIter *iter; | ||
4770 | 837 | gchar *page_id, *icon, *title; | ||
4771 | 838 | YelpWindowPrivate *priv = GET_PRIV (window); | ||
4772 | 839 | GSList *entries = NULL; | ||
4773 | 840 | |||
4774 | 841 | window_set_bookmark_action (window); | ||
4775 | 842 | |||
4776 | 843 | gtk_ui_manager_remove_ui (priv->ui_manager, priv->bookmarks_merge_id); | ||
4777 | 844 | |||
4778 | 845 | value = yelp_application_get_bookmarks (priv->application, doc_uri); | ||
4779 | 846 | g_variant_get (value, "a(sss)", &iter); | ||
4780 | 847 | while (g_variant_iter_loop (iter, "(&s&s&s)", &page_id, &icon, &title)) { | ||
4781 | 848 | YelpMenuEntry *entry = g_new0 (YelpMenuEntry, 1); | ||
4782 | 849 | entry->page_id = page_id; | ||
4783 | 850 | entry->icon = g_strdup (icon); | ||
4784 | 851 | entry->title = title; | ||
4785 | 852 | entries = g_slist_insert_sorted (entries, entry, (GCompareFunc) entry_compare); | ||
4786 | 853 | } | ||
4787 | 854 | for ( ; entries != NULL; entries = g_slist_delete_link (entries, entries)) { | ||
4788 | 855 | GSList *cur; | ||
4789 | 856 | GtkAction *bookmark; | ||
4790 | 857 | YelpMenuEntry *entry = (YelpMenuEntry *) entries->data; | ||
4791 | 858 | gchar *action_id = g_strconcat ("LoadBookmark-", entry->page_id, NULL); | ||
4792 | 859 | |||
4793 | 860 | bookmark = gtk_action_group_get_action (priv->bookmark_actions, action_id); | ||
4794 | 861 | if (bookmark) { | ||
4795 | 862 | /* The action might have been set by a different document using | ||
4796 | 863 | * the same page ID. We can just reuse the action, since it's | ||
4797 | 864 | * just a page ID relative to the current URI, but we need to | ||
4798 | 865 | * reset the title and icon. | ||
4799 | 866 | */ | ||
4800 | 867 | g_object_set (bookmark, | ||
4801 | 868 | "label", entry->title, | ||
4802 | 869 | "icon-name", entry->icon, | ||
4803 | 870 | NULL); | ||
4804 | 871 | } else { | ||
4805 | 872 | bookmark = gtk_action_new (action_id, entry->title, NULL, NULL); | ||
4806 | 873 | g_signal_connect (bookmark, "activate", | ||
4807 | 874 | G_CALLBACK (window_load_bookmark), window); | ||
4808 | 875 | gtk_action_set_icon_name (bookmark, entry->icon); | ||
4809 | 876 | gtk_action_group_add_action (priv->bookmark_actions, bookmark); | ||
4810 | 877 | } | ||
4811 | 878 | gtk_ui_manager_add_ui (priv->ui_manager, | ||
4812 | 879 | priv->bookmarks_merge_id, | ||
4813 | 880 | "ui/menubar/BookmarksMenu/Bookmarks", | ||
4814 | 881 | action_id, action_id, | ||
4815 | 882 | GTK_UI_MANAGER_MENUITEM, | ||
4816 | 883 | FALSE); | ||
4817 | 884 | gtk_ui_manager_ensure_update (priv->ui_manager); | ||
4818 | 885 | for (cur = gtk_action_get_proxies (bookmark); cur != NULL; cur = cur->next) { | ||
4819 | 886 | if (GTK_IS_IMAGE_MENU_ITEM (cur->data)) | ||
4820 | 887 | g_object_set (cur->data, "always-show-image", TRUE, NULL); | ||
4821 | 888 | } | ||
4822 | 889 | g_free (action_id); | ||
4823 | 890 | g_free (entry->icon); | ||
4824 | 891 | g_free (entry); | ||
4825 | 892 | } | ||
4826 | 893 | |||
4827 | 894 | g_variant_iter_free (iter); | ||
4828 | 895 | g_variant_unref (value); | ||
4829 | 896 | } | ||
4830 | 897 | |||
4831 | 898 | static void | ||
4832 | 899 | window_set_bookmark_action (YelpWindow *window) | ||
4833 | 900 | { | ||
4834 | 901 | YelpUri *uri = NULL; | ||
4835 | 902 | gchar *doc_uri = NULL, *page_id = NULL; | ||
4836 | 903 | GtkAction *action_add, *action_del; | ||
4837 | 904 | gboolean bookmarked; | ||
4838 | 905 | YelpWindowPrivate *priv = GET_PRIV (window); | ||
4839 | 906 | |||
4840 | 907 | action_add = gtk_action_group_get_action (priv->action_group, "AddBookmark"); | ||
4841 | 908 | action_del = gtk_action_group_get_action (priv->action_group, "RemoveBookmark"); | ||
4842 | 909 | |||
4843 | 910 | g_object_get (priv->view, | ||
4844 | 911 | "yelp-uri", &uri, | ||
4845 | 912 | "page-id", &page_id, | ||
4846 | 913 | NULL); | ||
4847 | 914 | if (page_id == NULL || uri == NULL) { | ||
4848 | 915 | gtk_action_set_sensitive (action_add, FALSE); | ||
4849 | 916 | gtk_action_set_sensitive (action_del, FALSE); | ||
4850 | 917 | goto done; | ||
4851 | 918 | } | ||
4852 | 919 | doc_uri = yelp_uri_get_document_uri (uri); | ||
4853 | 920 | bookmarked = yelp_application_is_bookmarked (YELP_BOOKMARKS (priv->application), | ||
4854 | 921 | doc_uri, page_id); | ||
4855 | 922 | gtk_action_set_sensitive (action_add, !bookmarked); | ||
4856 | 923 | gtk_action_set_sensitive (action_del, bookmarked); | ||
4857 | 924 | |||
4858 | 925 | done: | ||
4859 | 926 | g_free (page_id); | ||
4860 | 927 | g_free (doc_uri); | ||
4861 | 928 | if (uri) | ||
4862 | 929 | g_object_unref (uri); | ||
4863 | 930 | } | ||
4864 | 931 | |||
4865 | 932 | static void | ||
4866 | 933 | window_start_search (GtkAction *action, YelpWindow *window) | ||
4867 | 934 | { | ||
4868 | 935 | YelpWindowPrivate *priv = GET_PRIV (window); | ||
4869 | 936 | |||
4870 | 937 | yelp_location_entry_start_search (priv->entry); | ||
4871 | 938 | } | ||
4872 | 939 | |||
4873 | 940 | static void | ||
4874 | 941 | window_open_location (GtkAction *action, YelpWindow *window) | ||
4875 | 942 | { | ||
4876 | 943 | YelpUri *yuri = NULL; | ||
4877 | 944 | gchar *uri = NULL; | ||
4878 | 945 | GdkColor yellow; | ||
4879 | 946 | gchar *color; | ||
4880 | 947 | YelpWindowPrivate *priv = GET_PRIV (window); | ||
4881 | 948 | |||
4882 | 949 | gtk_container_remove (GTK_CONTAINER (priv->hbox), | ||
4883 | 950 | priv->align_location); | ||
4884 | 951 | gtk_box_pack_start (GTK_BOX (priv->hbox), | ||
4885 | 952 | priv->align_hidden, | ||
4886 | 953 | TRUE, TRUE, 0); | ||
4887 | 954 | |||
4888 | 955 | gtk_widget_show_all (priv->align_hidden); | ||
4889 | 956 | gtk_entry_set_text (GTK_ENTRY (priv->hidden_entry), ""); | ||
4890 | 957 | gtk_widget_grab_focus (priv->hidden_entry); | ||
4891 | 958 | |||
4892 | 959 | color = yelp_settings_get_color (yelp_settings_get_default (), | ||
4893 | 960 | YELP_SETTINGS_COLOR_YELLOW_BASE); | ||
4894 | 961 | if (gdk_color_parse (color, &yellow)) { | ||
4895 | 962 | gtk_widget_modify_base (priv->hidden_entry, | ||
4896 | 963 | GTK_STATE_NORMAL, | ||
4897 | 964 | &yellow); | ||
4898 | 965 | } | ||
4899 | 966 | g_free (color); | ||
4900 | 967 | |||
4901 | 968 | g_object_get (priv->view, "yelp-uri", &yuri, NULL); | ||
4902 | 969 | if (yuri) { | ||
4903 | 970 | uri = yelp_uri_get_canonical_uri (yuri); | ||
4904 | 971 | g_object_unref (yuri); | ||
4905 | 972 | } | ||
4906 | 973 | if (uri) { | ||
4907 | 974 | gchar *c; | ||
4908 | 975 | gtk_entry_set_text (GTK_ENTRY (priv->hidden_entry), uri); | ||
4909 | 976 | c = strchr (uri, ':'); | ||
4910 | 977 | if (c) | ||
4911 | 978 | gtk_editable_select_region (GTK_EDITABLE (priv->hidden_entry), c - uri + 1, -1); | ||
4912 | 979 | else | ||
4913 | 980 | gtk_editable_select_region (GTK_EDITABLE (priv->hidden_entry), 5, -1); | ||
4914 | 981 | g_free (uri); | ||
4915 | 982 | } | ||
4916 | 983 | } | ||
4917 | 984 | |||
4918 | 985 | static void | ||
4919 | 986 | read_later_resolved (YelpUri *uri, | ||
4920 | 987 | YelpWindow *window) | ||
4921 | 988 | { | ||
4922 | 989 | gchar *fulluri; | ||
4923 | 990 | const gchar *text = (const gchar *) g_object_get_data ((GObject *) uri, "link-text"); | ||
4924 | 991 | YelpWindowPrivate *priv = GET_PRIV (window); | ||
4925 | 992 | YelpUri *base; | ||
4926 | 993 | gchar *doc_uri; | ||
4927 | 994 | |||
4928 | 995 | g_object_get (priv->view, "yelp-uri", &base, NULL); | ||
4929 | 996 | doc_uri = yelp_uri_get_document_uri (uri); | ||
4930 | 997 | fulluri = yelp_uri_get_canonical_uri (uri); | ||
4931 | 998 | |||
4932 | 999 | yelp_application_add_read_later (priv->application, doc_uri, fulluri, text); | ||
4933 | 1000 | |||
4934 | 1001 | g_object_unref (base); | ||
4935 | 1002 | g_free (doc_uri); | ||
4936 | 1003 | g_free (fulluri); | ||
4937 | 1004 | } | ||
4938 | 1005 | |||
4939 | 1006 | static void | ||
4940 | 1007 | window_read_later (GtkAction *action, | ||
4941 | 1008 | YelpWindow *window) | ||
4942 | 1009 | { | ||
4943 | 1010 | YelpWindowPrivate *priv = GET_PRIV (window); | ||
4944 | 1011 | YelpUri *uri; | ||
4945 | 1012 | gchar *text; | ||
4946 | 1013 | |||
4947 | 1014 | uri = yelp_view_get_active_link_uri (priv->view); | ||
4948 | 1015 | text = yelp_view_get_active_link_text (priv->view); | ||
4949 | 1016 | |||
4950 | 1017 | g_object_set_data_full ((GObject *) uri, "link-text", text, g_free); | ||
4951 | 1018 | |||
4952 | 1019 | if (!yelp_uri_is_resolved (uri)) { | ||
4953 | 1020 | g_signal_connect (uri, "resolved", | ||
4954 | 1021 | G_CALLBACK (read_later_resolved), | ||
4955 | 1022 | window); | ||
4956 | 1023 | yelp_uri_resolve (uri); | ||
4957 | 1024 | } | ||
4958 | 1025 | else { | ||
4959 | 1026 | read_later_resolved (uri, window); | ||
4960 | 1027 | } | ||
4961 | 1028 | } | ||
4962 | 1029 | |||
4963 | 1030 | static gboolean | ||
4964 | 1031 | read_later_clicked (GtkLinkButton *button, | ||
4965 | 1032 | YelpWindow *window) | ||
4966 | 1033 | { | ||
4967 | 1034 | YelpWindowPrivate *priv = GET_PRIV (window); | ||
4968 | 1035 | YelpUri *base; | ||
4969 | 1036 | gchar *doc_uri; | ||
4970 | 1037 | gchar *fulluri; | ||
4971 | 1038 | |||
4972 | 1039 | fulluri = g_strdup (gtk_link_button_get_uri (button)); | ||
4973 | 1040 | |||
4974 | 1041 | g_object_get (priv->view, "yelp-uri", &base, NULL); | ||
4975 | 1042 | doc_uri = yelp_uri_get_document_uri (base); | ||
4976 | 1043 | |||
4977 | 1044 | yelp_application_remove_read_later (priv->application, doc_uri, fulluri); | ||
4978 | 1045 | |||
4979 | 1046 | g_object_unref (base); | ||
4980 | 1047 | g_free (doc_uri); | ||
4981 | 1048 | |||
4982 | 1049 | yelp_view_load (priv->view, fulluri); | ||
4983 | 1050 | |||
4984 | 1051 | g_free (fulluri); | ||
4985 | 1052 | return TRUE; | ||
4986 | 1053 | } | ||
4987 | 1054 | |||
4988 | 1055 | static void | ||
4989 | 1056 | app_read_later_changed (YelpApplication *app, | ||
4990 | 1057 | const gchar *doc_uri, | ||
4991 | 1058 | YelpWindow *window) | ||
4992 | 1059 | { | ||
4993 | 1060 | GVariant *value; | ||
4994 | 1061 | GVariantIter *viter; | ||
4995 | 1062 | gchar *uri, *title; /* do not free */ | ||
4996 | 1063 | GList *children; | ||
4997 | 1064 | gboolean has_children = FALSE; | ||
4998 | 1065 | YelpWindowPrivate *priv = GET_PRIV (window); | ||
4999 | 1066 | |||
5000 | 1067 | children = gtk_container_get_children (GTK_CONTAINER (priv->read_later_vbox)); |
The diff has been truncated for viewing.
Thanks, but please be careful with packaging Vcs (those are indicated in debian/control or by apt-get source), the location for this one is ~ubuntu- desktop/ yelp/ubuntu (debian dir only). I'm merging your changes by hand for this time but it would be nice if you could target the right vcs next time