Mercurial > gftp.yaz
annotate src/gtk/bookmarks.c @ 988:63555c9744c2
remote charset should be specified by each bookmark entry.
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Fri, 14 Aug 2009 07:54:55 +0900 |
parents | 19b6d55e2646 |
children |
rev | line source |
---|---|
1 | 1 /*****************************************************************************/ |
2 /* bookmarks.c - routines for the bookmarks */ | |
885 | 3 /* Copyright (C) 1998-2007 Brian Masney <masneyb@gftp.org> */ |
1 | 4 /* */ |
5 /* This program is free software; you can redistribute it and/or modify */ | |
6 /* it under the terms of the GNU General Public License as published by */ | |
7 /* the Free Software Foundation; either version 2 of the License, or */ | |
8 /* (at your option) any later version. */ | |
9 /* */ | |
10 /* This program is distributed in the hope that it will be useful, */ | |
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ | |
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ | |
13 /* GNU General Public License for more details. */ | |
14 /* */ | |
15 /* You should have received a copy of the GNU General Public License */ | |
16 /* along with this program; if not, write to the Free Software */ | |
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */ | |
18 /*****************************************************************************/ | |
19 | |
20 #include "gftp-gtk.h" | |
33 | 21 static const char cvsid[] = "$Id$"; |
1 | 22 |
544 | 23 static GtkWidget * bm_dialog = NULL, * edit_bookmarks_dialog = NULL; |
24 static GtkWidget * bm_hostedit, * bm_portedit, * bm_localdiredit, | |
988
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
25 * bm_remotediredit, * bm_useredit, * bm_passedit, * tree, |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
26 * bm_acctedit, * anon_chk, * bm_pathedit, * bm_protocol, |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
27 * bm_charsetedit; |
227 | 28 static GHashTable * new_bookmarks_htable = NULL; |
29 static gftp_bookmarks_var * new_bookmarks = NULL; | |
1 | 30 static GtkItemFactory * edit_factory; |
31 | |
32 | |
33 void | |
34 run_bookmark (gpointer data) | |
35 { | |
275 | 36 int refresh_local; |
37 | |
1 | 38 if (window1.request->stopable || window2.request->stopable) |
39 { | |
40 ftp_log (gftp_logging_misc, NULL, | |
41 _("%s: Please hit the stop button first to do anything else\n"), | |
42 _("Run Bookmark")); | |
43 return; | |
44 } | |
45 | |
285 | 46 if (GFTP_IS_CONNECTED (current_wdata->request)) |
380 | 47 gftpui_disconnect (current_wdata); |
285 | 48 |
243 | 49 if (gftp_parse_bookmark (current_wdata->request, other_wdata->request, |
275 | 50 (char *) data, &refresh_local) < 0) |
129 | 51 return; |
1 | 52 |
275 | 53 if (refresh_local) |
514 | 54 gftpui_refresh (other_wdata, 0); |
275 | 55 |
767 | 56 ftp_connect (current_wdata, current_wdata->request); |
1 | 57 } |
58 | |
59 | |
60 static void | |
19 | 61 doadd_bookmark (gpointer * data, gftp_dialog_data * ddata) |
1 | 62 { |
570 | 63 GtkItemFactoryEntry test = { NULL, NULL, run_bookmark, 0, MN_(NULL) }; |
1 | 64 const char *edttxt, *spos; |
129 | 65 gftp_bookmarks_var * tempentry; |
66 char *dpos, *proto; | |
1 | 67 |
19 | 68 edttxt = gtk_entry_get_text (GTK_ENTRY (ddata->edit)); |
1 | 69 if (*edttxt == '\0') |
70 { | |
71 ftp_log (gftp_logging_error, NULL, | |
72 _("Add Bookmark: You must enter a name for the bookmark\n")); | |
73 return; | |
74 } | |
75 | |
129 | 76 if (g_hash_table_lookup (gftp_bookmarks_htable, edttxt) != NULL) |
1 | 77 { |
78 ftp_log (gftp_logging_error, NULL, | |
79 _("Add Bookmark: Cannot add bookmark %s because that name already exists\n"), edttxt); | |
80 return; | |
81 } | |
82 | |
83 tempentry = g_malloc0 (sizeof (*tempentry)); | |
84 | |
941 | 85 dpos = tempentry->path = g_malloc0 ((gulong) strlen (edttxt) + 1); |
1 | 86 for (spos = edttxt; *spos != '\0';) |
87 { | |
88 *dpos++ = *spos++; | |
89 if (*spos == '/') | |
90 { | |
91 *dpos++ = '/'; | |
92 for (; *spos == '/'; spos++); | |
93 } | |
94 } | |
95 *dpos = '\0'; | |
96 | |
97 edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (hostedit)->entry)); | |
129 | 98 tempentry->hostname = g_strdup (edttxt); |
1 | 99 |
100 edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (portedit)->entry)); | |
101 tempentry->port = strtol (edttxt, NULL, 10); | |
102 | |
129 | 103 proto = gftp_protocols[current_wdata->request->protonum].name; |
104 tempentry->protocol = g_strdup (proto); | |
1 | 105 |
106 edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (other_wdata->combo)->entry)); | |
129 | 107 tempentry->local_dir = g_strdup (edttxt); |
1 | 108 |
109 edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (current_wdata->combo)->entry)); | |
129 | 110 tempentry->remote_dir = g_strdup (edttxt); |
1 | 111 |
7 | 112 if ((edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (useredit)->entry))) != NULL) |
1 | 113 { |
129 | 114 tempentry->user = g_strdup (edttxt); |
1 | 115 |
116 edttxt = gtk_entry_get_text (GTK_ENTRY (passedit)); | |
129 | 117 tempentry->pass = g_strdup (edttxt); |
19 | 118 tempentry->save_password = GTK_TOGGLE_BUTTON (ddata->checkbox)->active; |
1 | 119 } |
120 | |
129 | 121 gftp_add_bookmark (tempentry); |
1 | 122 |
7 | 123 test.path = g_strconcat ("/Bookmarks/", tempentry->path, NULL); |
1 | 124 gtk_item_factory_create_item (factory, &test, (gpointer) tempentry->path, |
125 1); | |
126 g_free (test.path); | |
26 | 127 gftp_write_bookmarks_file (); |
1 | 128 } |
129 | |
130 | |
131 void | |
48 | 132 add_bookmark (gpointer data) |
133 { | |
134 const char *edttxt; | |
135 | |
136 if (!check_status (_("Add Bookmark"), current_wdata, 0, 0, 0, 1)) | |
137 return; | |
138 | |
139 edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (hostedit)->entry)); | |
140 if (*edttxt == '\0') | |
141 { | |
142 ftp_log (gftp_logging_error, NULL, | |
143 _("Add Bookmark: You must enter a hostname\n")); | |
144 return; | |
145 } | |
146 | |
147 MakeEditDialog (_("Add Bookmark"), _("Enter the name of the bookmark you want to add\nYou can separate items by a / to put it into a submenu\n(ex: Linux Sites/Debian)"), NULL, 1, _("Remember password"), gftp_dialog_button_create, doadd_bookmark, data, NULL, NULL); | |
148 } | |
149 | |
150 | |
151 void | |
1 | 152 build_bookmarks_menu (void) |
153 { | |
570 | 154 GtkItemFactoryEntry test = { NULL, NULL, NULL, 0, MN_(NULL) }; |
129 | 155 gftp_bookmarks_var * tempentry; |
1 | 156 |
129 | 157 tempentry = gftp_bookmarks->children; |
1 | 158 while (tempentry != NULL) |
159 { | |
7 | 160 test.path = g_strconcat ("/Bookmarks/", tempentry->path, NULL); |
1 | 161 if (tempentry->isfolder) |
162 { | |
163 test.item_type = "<Branch>"; | |
164 test.callback = NULL; | |
165 } | |
166 else | |
167 { | |
168 test.item_type = ""; | |
169 test.callback = run_bookmark; | |
170 } | |
609 | 171 |
1 | 172 gtk_item_factory_create_item (factory, &test, |
173 (gpointer) tempentry->path, 1); | |
174 g_free (test.path); | |
175 if (tempentry->children != NULL) | |
176 { | |
177 tempentry = tempentry->children; | |
178 continue; | |
179 } | |
180 while (tempentry->next == NULL && tempentry->prev != NULL) | |
181 tempentry = tempentry->prev; | |
182 | |
183 tempentry = tempentry->next; | |
184 } | |
185 } | |
186 | |
187 | |
129 | 188 static gftp_bookmarks_var * |
189 copy_bookmarks (gftp_bookmarks_var * bookmarks) | |
1 | 190 { |
129 | 191 gftp_bookmarks_var * new_bm, * preventry, * tempentry, * sibling, * newentry, |
1 | 192 * tentry; |
193 | |
194 new_bm = g_malloc0 (sizeof (*new_bm)); | |
195 new_bm->path = g_malloc0 (1); | |
196 new_bm->isfolder = bookmarks->isfolder; | |
197 preventry = new_bm; | |
198 tempentry = bookmarks->children; | |
199 sibling = NULL; | |
200 while (tempentry != NULL) | |
201 { | |
202 newentry = g_malloc0 (sizeof (*newentry)); | |
203 newentry->isfolder = tempentry->isfolder; | |
204 newentry->save_password = tempentry->save_password; | |
205 newentry->cnode = tempentry->cnode; | |
206 if (tempentry->path) | |
129 | 207 newentry->path = g_strdup (tempentry->path); |
208 | |
1 | 209 if (tempentry->hostname) |
129 | 210 newentry->hostname = g_strdup (tempentry->hostname); |
211 | |
1 | 212 if (tempentry->protocol) |
129 | 213 newentry->protocol = g_strdup (tempentry->protocol); |
214 | |
1 | 215 if (tempentry->local_dir) |
129 | 216 newentry->local_dir = g_strdup (tempentry->local_dir); |
217 | |
1 | 218 if (tempentry->remote_dir) |
129 | 219 newentry->remote_dir = g_strdup (tempentry->remote_dir); |
220 | |
988
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
221 if (tempentry->remote_charset) |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
222 newentry->remote_charset = g_strdup (tempentry->remote_charset); |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
223 |
1 | 224 if (tempentry->user) |
129 | 225 newentry->user = g_strdup (tempentry->user); |
226 | |
1 | 227 if (tempentry->pass) |
129 | 228 newentry->pass = g_strdup (tempentry->pass); |
229 | |
1 | 230 if (tempentry->acct) |
129 | 231 newentry->acct = g_strdup (tempentry->acct); |
232 | |
1 | 233 newentry->port = tempentry->port; |
234 | |
229 | 235 gftp_copy_local_options (&newentry->local_options_vars, |
236 &newentry->local_options_hash, | |
429 | 237 &newentry->num_local_options_vars, |
229 | 238 tempentry->local_options_vars, |
239 tempentry->num_local_options_vars); | |
240 newentry->num_local_options_vars = tempentry->num_local_options_vars; | |
241 | |
1 | 242 if (sibling == NULL) |
243 { | |
244 if (preventry->children == NULL) | |
245 preventry->children = newentry; | |
246 else | |
247 { | |
248 tentry = preventry->children; | |
249 while (tentry->next != NULL) | |
250 tentry = tentry->next; | |
251 tentry->next = newentry; | |
252 } | |
253 } | |
254 else | |
255 sibling->next = newentry; | |
256 newentry->prev = preventry; | |
257 | |
258 if (tempentry->children != NULL) | |
259 { | |
260 preventry = newentry; | |
261 sibling = NULL; | |
262 tempentry = tempentry->children; | |
263 } | |
264 else | |
265 { | |
266 if (tempentry->next == NULL) | |
267 { | |
268 sibling = NULL; | |
269 while (tempentry->next == NULL && tempentry->prev != NULL) | |
270 { | |
271 tempentry = tempentry->prev; | |
272 preventry = preventry->prev; | |
273 } | |
274 tempentry = tempentry->next; | |
275 } | |
276 else | |
277 { | |
278 sibling = newentry; | |
279 tempentry = tempentry->next; | |
280 } | |
281 } | |
282 } | |
229 | 283 |
1 | 284 return (new_bm); |
285 } | |
286 | |
287 | |
288 static void | |
609 | 289 _free_menu_entry (gftp_bookmarks_var * entry) |
290 { | |
291 GtkWidget * tempwid; | |
292 char *tempstr; | |
293 | |
294 if (entry->oldpath != NULL) | |
295 tempstr = gftp_build_path (NULL, "/Bookmarks", entry->oldpath, NULL); | |
296 else | |
297 tempstr = gftp_build_path (NULL, "/Bookmarks", entry->path, NULL); | |
298 | |
299 tempwid = gtk_item_factory_get_item (factory, tempstr); | |
300 if (GTK_IS_WIDGET (tempwid)) | |
301 gtk_widget_destroy (tempwid); | |
302 | |
303 g_free (tempstr); | |
304 } | |
305 | |
306 | |
307 static void | |
48 | 308 bm_apply_changes (GtkWidget * widget, gpointer backup_data) |
309 { | |
129 | 310 gftp_bookmarks_var * tempentry, * delentry; |
48 | 311 |
603 | 312 if (bm_dialog != NULL) |
313 { | |
314 gtk_widget_grab_focus (bm_dialog); | |
315 return; | |
316 } | |
317 | |
570 | 318 if (gftp_bookmarks != NULL) |
48 | 319 { |
570 | 320 tempentry = gftp_bookmarks->children; |
321 while (tempentry != NULL) | |
322 { | |
323 if (tempentry->children != NULL) | |
324 tempentry = tempentry->children; | |
325 else | |
326 { | |
609 | 327 while (tempentry->next == NULL && tempentry->prev != NULL) |
570 | 328 { |
329 delentry = tempentry; | |
609 | 330 tempentry = tempentry->prev; |
331 _free_menu_entry (delentry); | |
332 gftp_free_bookmark (delentry, 1); | |
570 | 333 } |
609 | 334 |
335 delentry = tempentry; | |
336 tempentry = tempentry->next; | |
337 if (tempentry != NULL) | |
338 _free_menu_entry (delentry); | |
339 | |
340 gftp_free_bookmark (delentry, 1); | |
570 | 341 } |
342 } | |
609 | 343 |
570 | 344 g_hash_table_destroy (gftp_bookmarks_htable); |
48 | 345 } |
346 | |
347 if (backup_data) | |
348 { | |
570 | 349 gftp_bookmarks = copy_bookmarks (new_bookmarks); |
609 | 350 gftp_bookmarks_htable = build_bookmarks_hash_table (gftp_bookmarks); |
48 | 351 } |
352 else | |
353 { | |
570 | 354 gftp_bookmarks = new_bookmarks; |
355 gftp_bookmarks_htable = new_bookmarks_htable; | |
356 | |
48 | 357 new_bookmarks = NULL; |
358 new_bookmarks_htable = NULL; | |
359 } | |
570 | 360 |
48 | 361 build_bookmarks_menu (); |
362 gftp_write_bookmarks_file (); | |
363 } | |
364 | |
365 | |
366 static void | |
1 | 367 bm_close_dialog (GtkWidget * widget, GtkWidget * dialog) |
368 { | |
570 | 369 if (bm_dialog != NULL) |
603 | 370 return; |
570 | 371 |
201 | 372 if (new_bookmarks_htable != NULL) |
1 | 373 { |
201 | 374 g_hash_table_destroy (new_bookmarks_htable); |
375 new_bookmarks_htable = NULL; | |
1 | 376 } |
23 | 377 |
227 | 378 if (new_bookmarks != NULL) |
379 { | |
380 gftp_bookmarks_destroy (new_bookmarks); | |
381 new_bookmarks = NULL; | |
382 } | |
201 | 383 |
570 | 384 if (edit_bookmarks_dialog != NULL) |
385 { | |
386 gtk_widget_destroy (edit_bookmarks_dialog); | |
387 edit_bookmarks_dialog = NULL; | |
388 } | |
1 | 389 } |
390 | |
391 | |
48 | 392 #if GTK_MAJOR_VERSION > 1 |
1 | 393 static void |
48 | 394 editbm_action (GtkWidget * widget, gint response, gpointer user_data) |
1 | 395 { |
48 | 396 switch (response) |
1 | 397 { |
48 | 398 case GTK_RESPONSE_OK: |
399 bm_apply_changes (widget, NULL); | |
400 /* no break */ | |
401 default: | |
402 bm_close_dialog (NULL, widget); | |
1 | 403 } |
404 } | |
48 | 405 #endif |
1 | 406 |
407 | |
408 static void | |
19 | 409 do_make_new (gpointer data, gftp_dialog_data * ddata) |
1 | 410 { |
411 GdkPixmap * closedir_pixmap, * opendir_pixmap; | |
412 GdkBitmap * closedir_bitmap, * opendir_bitmap; | |
129 | 413 gftp_bookmarks_var * tempentry, * newentry; |
1 | 414 char *pos, *text[2]; |
415 const char *str; | |
416 | |
417 gftp_get_pixmap (tree, "open_dir.xpm", &opendir_pixmap, &opendir_bitmap); | |
418 gftp_get_pixmap (tree, "dir.xpm", &closedir_pixmap, &closedir_bitmap); | |
419 | |
19 | 420 str = gtk_entry_get_text (GTK_ENTRY (ddata->edit)); |
867 | 421 if (*str == '\0') |
422 { | |
423 ftp_log (gftp_logging_misc, NULL, | |
424 _("You must specify a name for the bookmark.")); | |
425 return; | |
426 } | |
1 | 427 |
428 newentry = g_malloc0 (sizeof (*newentry)); | |
45 | 429 #if GTK_MAJOR_VERSION == 1 |
430 newentry->path = g_strdup (str); | |
431 | |
1 | 432 while ((pos = strchr (str, '/')) != NULL) |
433 *pos++ = ' '; | |
45 | 434 #else |
844 | 435 newentry->path = g_strdup (str); |
436 while ((pos = g_utf8_strchr (newentry->path, -1, '/')) != NULL) | |
45 | 437 *pos++ = ' '; |
438 #endif | |
1 | 439 |
440 newentry->prev = new_bookmarks; | |
19 | 441 if (data) |
1 | 442 newentry->isfolder = 1; |
443 | |
444 if (new_bookmarks->children == NULL) | |
517 | 445 new_bookmarks->children = newentry; |
1 | 446 else |
447 { | |
448 tempentry = new_bookmarks->children; | |
449 while (tempentry->next != NULL) | |
450 tempentry = tempentry->next; | |
451 tempentry->next = newentry; | |
452 } | |
453 | |
454 text[0] = text[1] = newentry->path; | |
455 | |
456 if (newentry->isfolder) | |
457 newentry->cnode = gtk_ctree_insert_node (GTK_CTREE (tree), | |
458 new_bookmarks->cnode, NULL, | |
459 text, 5, closedir_pixmap, | |
460 closedir_bitmap, opendir_pixmap, | |
461 opendir_bitmap, FALSE, FALSE); | |
462 else | |
463 newentry->cnode = gtk_ctree_insert_node (GTK_CTREE (tree), | |
464 new_bookmarks->cnode, NULL, | |
465 text, 5, NULL, NULL, NULL, NULL, | |
609 | 466 TRUE, FALSE); |
1 | 467 |
468 gtk_ctree_node_set_row_data (GTK_CTREE (tree), newentry->cnode, newentry); | |
469 g_hash_table_insert (new_bookmarks_htable, newentry->path, newentry); | |
470 } | |
471 | |
472 | |
48 | 473 static void |
474 new_folder_entry (gpointer data) | |
475 { | |
476 MakeEditDialog (_("New Folder"), | |
477 _("Enter the name of the new folder to create"), NULL, 1, | |
478 NULL, gftp_dialog_button_create, | |
479 do_make_new, (gpointer) 0x1, NULL, NULL); | |
480 } | |
481 | |
482 | |
483 static void | |
484 new_item_entry (gpointer data) | |
485 { | |
754 | 486 MakeEditDialog (_("New Item"), |
48 | 487 _("Enter the name of the new item to create"), NULL, 1, |
488 NULL, gftp_dialog_button_create, | |
489 do_make_new, NULL, NULL, NULL); | |
490 } | |
491 | |
492 | |
493 static void | |
129 | 494 do_delete_entry (gftp_bookmarks_var * entry, gftp_dialog_data * ddata) |
48 | 495 { |
129 | 496 gftp_bookmarks_var * tempentry, * delentry; |
48 | 497 |
498 g_hash_table_remove (new_bookmarks_htable, entry->path); | |
499 gtk_ctree_remove_node (GTK_CTREE (tree), entry->cnode); | |
500 if (entry->prev->children == entry) | |
501 entry->prev->children = entry->prev->children->next; | |
502 else | |
503 { | |
504 tempentry = entry->prev->children; | |
505 while (tempentry->next != entry) | |
506 tempentry = tempentry->next; | |
507 tempentry->next = entry->next; | |
508 } | |
509 | |
510 entry->prev = NULL; | |
511 entry->next = NULL; | |
512 tempentry = entry; | |
513 while (tempentry != NULL) | |
514 { | |
609 | 515 gftp_free_bookmark (tempentry, 0); |
48 | 516 |
517 if (tempentry->children != NULL) | |
518 { | |
519 tempentry = tempentry->children; | |
520 continue; | |
521 } | |
522 else if (tempentry->next == NULL && tempentry->prev != NULL) | |
523 { | |
524 delentry = tempentry->prev; | |
525 g_free (tempentry); | |
526 tempentry = delentry->next; | |
527 if (delentry != entry) | |
528 g_free (delentry); | |
529 } | |
530 else | |
531 tempentry = tempentry->next; | |
532 } | |
533 g_free (entry); | |
534 } | |
535 | |
536 | |
537 static void | |
538 delete_entry (gpointer data) | |
539 { | |
129 | 540 gftp_bookmarks_var * entry; |
48 | 541 char *tempstr, *pos; |
542 | |
543 if (GTK_CLIST (tree)->selection == NULL) | |
544 return; | |
545 entry = | |
546 gtk_ctree_node_get_row_data (GTK_CTREE (tree), | |
547 GTK_CLIST (tree)->selection->data); | |
548 if (entry == NULL || entry->prev == NULL) | |
549 return; | |
550 | |
551 if (!entry->isfolder) | |
552 do_delete_entry (entry, NULL); | |
553 else | |
554 { | |
555 if ((pos = strrchr (entry->path, '/')) == NULL) | |
556 pos = entry->path; | |
557 else | |
558 pos++; | |
559 | |
742 | 560 tempstr = g_strdup_printf (_("Are you sure you want to erase the bookmark\n%s and all its children?"), pos); |
48 | 561 MakeYesNoDialog (_("Delete Bookmark"), tempstr, do_delete_entry, entry, |
562 NULL, NULL); | |
563 g_free (tempstr); | |
564 } | |
565 } | |
566 | |
567 | |
568 static void | |
569 set_userpass_visible (GtkWidget * checkbutton, GtkWidget * entry) | |
570 { | |
571 gtk_widget_set_sensitive (bm_useredit, !GTK_TOGGLE_BUTTON (anon_chk)->active); | |
572 gtk_widget_set_sensitive (bm_passedit, !GTK_TOGGLE_BUTTON (anon_chk)->active); | |
573 gtk_widget_set_sensitive (bm_acctedit, !GTK_TOGGLE_BUTTON (anon_chk)->active); | |
574 } | |
575 | |
576 | |
577 static void | |
612 | 578 _add_tree_node (gftp_bookmarks_var * entry, char *path, int isleaf, |
579 int expanded) | |
580 { | |
581 static GdkPixmap * closedir_pixmap = NULL, | |
582 * opendir_pixmap = NULL; | |
583 static GdkBitmap * closedir_bitmap = NULL, | |
584 * opendir_bitmap = NULL; | |
585 static int initialized = 0; | |
586 GtkCTreeNode * parent; | |
587 char *text[2], *pos; | |
588 | |
589 if (!initialized) | |
590 { | |
591 gftp_get_pixmap (tree, "open_dir.xpm", &opendir_pixmap, &opendir_bitmap); | |
592 gftp_get_pixmap (tree, "dir.xpm", &closedir_pixmap, &closedir_bitmap); | |
593 initialized = 1; | |
594 } | |
595 | |
596 if (path == NULL) | |
597 { | |
598 if ((pos = strrchr (entry->path, '/')) == NULL) | |
599 pos = entry->path; | |
600 else | |
601 pos++; | |
602 } | |
603 else | |
604 pos = path; | |
605 | |
606 text[0] = text[1] = pos; | |
607 | |
608 if (entry->prev == NULL) | |
609 parent = NULL; | |
610 else | |
611 parent = entry->prev->cnode; | |
612 | |
613 if (isleaf) | |
614 entry->cnode = gtk_ctree_insert_node (GTK_CTREE (tree), parent, NULL, text, | |
615 5, NULL, NULL, NULL, NULL, TRUE, | |
616 expanded); | |
617 else | |
618 entry->cnode = gtk_ctree_insert_node (GTK_CTREE (tree), parent, NULL, | |
619 text, 5, closedir_pixmap, | |
620 closedir_bitmap, opendir_pixmap, | |
621 opendir_bitmap, FALSE, expanded); | |
622 | |
623 gtk_ctree_node_set_row_data (GTK_CTREE (tree), entry->cnode, entry); | |
624 } | |
625 | |
626 | |
627 static void | |
48 | 628 build_bookmarks_tree (void) |
629 { | |
129 | 630 gftp_bookmarks_var * tempentry, * preventry; |
612 | 631 char *pos, *tempstr; |
48 | 632 |
612 | 633 _add_tree_node (new_bookmarks, _("Bookmarks"), 0, 1); |
48 | 634 |
635 tempentry = new_bookmarks->children; | |
636 while (tempentry != NULL) | |
637 { | |
638 tempentry->cnode = NULL; | |
612 | 639 |
48 | 640 if (tempentry->children != NULL) |
641 { | |
642 tempentry = tempentry->children; | |
643 continue; | |
644 } | |
612 | 645 else if (strchr (tempentry->path, '/') == NULL && tempentry->isfolder) |
646 _add_tree_node (tempentry, NULL, 0, 0); | |
48 | 647 else |
612 | 648 { |
649 pos = tempentry->path; | |
650 while ((pos = strchr (pos, '/')) != NULL) | |
603 | 651 { |
612 | 652 *pos = '\0'; |
653 tempstr = g_strdup (tempentry->path); | |
654 *pos++ = '/'; | |
655 | |
656 preventry = g_hash_table_lookup (new_bookmarks_htable, tempstr); | |
657 g_free (tempstr); | |
658 | |
659 if (preventry->cnode == NULL) | |
660 _add_tree_node (preventry, NULL, 0, 0); | |
603 | 661 } |
612 | 662 |
663 _add_tree_node (tempentry, NULL, TRUE, 0); | |
48 | 664 } |
665 | |
666 while (tempentry->next == NULL && tempentry->prev != NULL) | |
606 | 667 tempentry = tempentry->prev; |
48 | 668 tempentry = tempentry->next; |
669 } | |
670 } | |
671 | |
672 | |
673 static void | |
129 | 674 entry_apply_changes (GtkWidget * widget, gftp_bookmarks_var * entry) |
48 | 675 { |
613 | 676 gftp_bookmarks_var * tempentry, * nextentry, * bmentry; |
609 | 677 char *pos, *newpath, tempchar, *tempstr; |
48 | 678 GtkWidget * tempwid; |
518 | 679 size_t oldpathlen; |
48 | 680 const char *str; |
681 | |
593 | 682 tempstr = g_strdup (gtk_entry_get_text (GTK_ENTRY (bm_pathedit))); |
683 while ((pos = strchr (tempstr, '/')) != NULL) | |
684 *pos = ' '; | |
685 | |
48 | 686 oldpathlen = strlen (entry->path); |
613 | 687 if ((pos = strrchr (entry->path, '/')) != NULL) |
688 { | |
689 tempchar = *pos; | |
690 *pos = '\0'; | |
691 newpath = gftp_build_path (NULL, entry->path, tempstr, NULL); | |
692 *pos = tempchar; | |
693 g_free (tempstr); | |
694 } | |
695 else | |
696 newpath = tempstr; | |
593 | 697 |
48 | 698 str = gtk_entry_get_text (GTK_ENTRY (bm_hostedit)); |
570 | 699 if (entry->hostname != NULL) |
48 | 700 g_free (entry->hostname); |
129 | 701 entry->hostname = g_strdup (str); |
48 | 702 |
703 str = gtk_entry_get_text (GTK_ENTRY (bm_portedit)); | |
704 entry->port = strtol (str, NULL, 10); | |
705 | |
706 tempwid = gtk_menu_get_active (GTK_MENU (bm_protocol)); | |
707 str = gtk_object_get_user_data (GTK_OBJECT (tempwid)); | |
570 | 708 if (entry->protocol != NULL) |
48 | 709 g_free (entry->protocol); |
129 | 710 entry->protocol = g_strdup (str); |
48 | 711 |
712 str = gtk_entry_get_text (GTK_ENTRY (bm_remotediredit)); | |
570 | 713 if (entry->remote_dir != NULL) |
48 | 714 g_free (entry->remote_dir); |
129 | 715 entry->remote_dir = g_strdup (str); |
48 | 716 |
717 str = gtk_entry_get_text (GTK_ENTRY (bm_localdiredit)); | |
570 | 718 if (entry->local_dir != NULL) |
48 | 719 g_free (entry->local_dir); |
129 | 720 entry->local_dir = g_strdup (str); |
48 | 721 |
988
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
722 /* charset */ |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
723 str = gtk_entry_get_text (GTK_ENTRY (bm_charsetedit)); |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
724 if (entry->remote_charset != NULL) |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
725 g_free (entry->remote_charset); |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
726 entry->remote_charset = g_strdup (str); |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
727 |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
728 /* user */ |
48 | 729 if (GTK_TOGGLE_BUTTON (anon_chk)->active) |
570 | 730 str = GFTP_ANONYMOUS_USER; |
48 | 731 else |
732 str = gtk_entry_get_text (GTK_ENTRY (bm_useredit)); | |
570 | 733 |
734 if (entry->user != NULL) | |
48 | 735 g_free (entry->user); |
129 | 736 entry->user = g_strdup (str); |
48 | 737 |
570 | 738 if (strcasecmp (entry->user, GFTP_ANONYMOUS_USER) == 0) |
48 | 739 str = "@EMAIL@"; |
740 else | |
741 str = gtk_entry_get_text (GTK_ENTRY (bm_passedit)); | |
570 | 742 if (entry->pass != NULL) |
48 | 743 g_free (entry->pass); |
129 | 744 entry->pass = g_strdup (str); |
48 | 745 entry->save_password = *entry->pass != '\0'; |
746 | |
570 | 747 str = gtk_entry_get_text (GTK_ENTRY (bm_acctedit)); |
748 if (entry->acct != NULL) | |
48 | 749 g_free (entry->acct); |
129 | 750 entry->acct = g_strdup (str); |
48 | 751 |
767 | 752 gftp_gtk_save_bookmark_options (); |
229 | 753 |
48 | 754 if (strcmp (entry->path, newpath) != 0) |
755 { | |
756 tempentry = entry; | |
757 nextentry = entry->next; | |
758 entry->next = NULL; | |
613 | 759 |
48 | 760 while (tempentry != NULL) |
761 { | |
613 | 762 bmentry = g_hash_table_lookup (gftp_bookmarks_htable, |
763 tempentry->path); | |
772 | 764 if (bmentry == NULL) |
765 bmentry = g_hash_table_lookup (new_bookmarks_htable, | |
766 tempentry->path); | |
767 | |
768 g_hash_table_remove (new_bookmarks_htable, tempentry->path); | |
769 | |
613 | 770 if (bmentry->oldpath == NULL) |
771 bmentry->oldpath = tempentry->path; | |
422 | 772 else |
609 | 773 g_free (tempentry->path); |
422 | 774 |
609 | 775 if (*(tempentry->path + oldpathlen) == '\0') |
776 tempentry->path = g_strdup (newpath); | |
777 else | |
778 tempentry->path = gftp_build_path (NULL, newpath, | |
779 tempentry->path + oldpathlen, | |
780 NULL); | |
781 | |
48 | 782 g_hash_table_insert (new_bookmarks_htable, tempentry->path, |
570 | 783 tempentry); |
613 | 784 |
785 gtk_ctree_node_set_text (GTK_CTREE (tree), tempentry->cnode, 0, | |
786 tempentry->path); | |
787 | |
48 | 788 if (tempentry->children != NULL) |
613 | 789 tempentry = tempentry->children; |
790 else | |
791 { | |
792 while (tempentry->next == NULL && tempentry != entry && | |
793 tempentry->prev != NULL) | |
794 tempentry = tempentry->prev; | |
48 | 795 |
613 | 796 tempentry = tempentry->next; |
797 } | |
48 | 798 } |
570 | 799 |
48 | 800 entry->next = nextentry; |
801 } | |
802 | |
609 | 803 g_free (newpath); |
48 | 804 } |
805 | |
806 | |
422 | 807 #if GTK_MAJOR_VERSION == 1 |
808 | |
809 static void | |
810 entry_close_dialog (void * data) | |
811 { | |
812 gtk_widget_destroy (bm_dialog); | |
813 bm_dialog = NULL; | |
814 } | |
815 | |
816 | |
817 #else | |
818 | |
19 | 819 static void |
820 bmedit_action (GtkWidget * widget, gint response, gpointer user_data) | |
821 { | |
822 switch (response) | |
823 { | |
824 case GTK_RESPONSE_OK: | |
825 entry_apply_changes (widget, user_data); | |
826 /* no break */ | |
827 default: | |
828 gtk_widget_destroy (widget); | |
422 | 829 bm_dialog = NULL; |
19 | 830 } |
831 } | |
832 #endif | |
833 | |
834 | |
1 | 835 static void |
836 edit_entry (gpointer data) | |
837 { | |
422 | 838 GtkWidget * table, * tempwid, * menu, * notebook; |
988
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
839 volatile gftp_bookmarks_var * entry; |
767 | 840 unsigned int num, i; |
1 | 841 char *pos; |
842 | |
422 | 843 if (bm_dialog != NULL) |
844 { | |
845 gtk_widget_grab_focus (bm_dialog); | |
846 return; | |
847 } | |
848 | |
1 | 849 if (GTK_CLIST (tree)->selection == NULL) |
850 return; | |
851 | |
852 entry = gtk_ctree_node_get_row_data (GTK_CTREE (tree), | |
853 GTK_CLIST (tree)->selection->data); | |
854 | |
855 if (entry == NULL || entry == new_bookmarks) | |
856 return; | |
857 | |
45 | 858 #if GTK_MAJOR_VERSION == 1 |
422 | 859 bm_dialog = gtk_dialog_new (); |
860 gtk_window_set_title (GTK_WINDOW (bm_dialog), _("Edit Entry")); | |
861 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (bm_dialog)->action_area), 15); | |
19 | 862 #else |
422 | 863 bm_dialog = gtk_dialog_new_with_buttons (_("Edit Entry"), NULL, 0, |
866 | 864 GTK_STOCK_CANCEL, |
865 GTK_RESPONSE_CANCEL, | |
422 | 866 GTK_STOCK_SAVE, |
867 GTK_RESPONSE_OK, | |
868 NULL); | |
19 | 869 #endif |
422 | 870 gtk_window_set_wmclass (GTK_WINDOW (bm_dialog), "Edit Bookmark Entry", |
871 "gFTP"); | |
872 gtk_window_set_position (GTK_WINDOW (bm_dialog), GTK_WIN_POS_MOUSE); | |
873 gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (bm_dialog)->vbox), 10); | |
874 gtk_widget_realize (bm_dialog); | |
19 | 875 |
876 if (gftp_icon != NULL) | |
877 { | |
422 | 878 gdk_window_set_icon (bm_dialog->window, NULL, gftp_icon->pixmap, |
19 | 879 gftp_icon->bitmap); |
422 | 880 gdk_window_set_icon_name (bm_dialog->window, gftp_version); |
19 | 881 } |
1 | 882 |
227 | 883 notebook = gtk_notebook_new (); |
422 | 884 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (bm_dialog)->vbox), notebook, TRUE, |
1 | 885 TRUE, 0); |
227 | 886 gtk_widget_show (notebook); |
1 | 887 |
888 table = gtk_table_new (11, 2, FALSE); | |
889 gtk_container_border_width (GTK_CONTAINER (table), 5); | |
890 gtk_table_set_row_spacings (GTK_TABLE (table), 5); | |
891 gtk_table_set_col_spacings (GTK_TABLE (table), 5); | |
892 gtk_widget_show (table); | |
893 | |
227 | 894 tempwid = gtk_label_new (_("Bookmark")); |
895 gtk_widget_show (tempwid); | |
896 | |
897 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), table, tempwid); | |
898 | |
1 | 899 tempwid = gtk_label_new (_("Description:")); |
900 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5); | |
901 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 0, 1); | |
902 gtk_widget_show (tempwid); | |
903 | |
904 bm_pathedit = gtk_entry_new (); | |
905 gtk_table_attach_defaults (GTK_TABLE (table), bm_pathedit, 1, 2, 0, 1); | |
906 if ((pos = strrchr (entry->path, '/')) == NULL) | |
907 pos = entry->path; | |
908 else | |
909 pos++; | |
910 if (pos) | |
911 gtk_entry_set_text (GTK_ENTRY (bm_pathedit), pos); | |
912 gtk_widget_show (bm_pathedit); | |
913 | |
914 tempwid = gtk_label_new (_("Hostname:")); | |
915 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5); | |
916 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 1, 2); | |
917 gtk_widget_show (tempwid); | |
918 | |
919 bm_hostedit = gtk_entry_new (); | |
920 gtk_table_attach_defaults (GTK_TABLE (table), bm_hostedit, 1, 2, 1, 2); | |
921 if (entry->isfolder) | |
922 gtk_widget_set_sensitive (bm_hostedit, 0); | |
923 else if (entry->hostname) | |
924 gtk_entry_set_text (GTK_ENTRY (bm_hostedit), entry->hostname); | |
925 gtk_widget_show (bm_hostedit); | |
926 | |
927 tempwid = gtk_label_new (_("Port:")); | |
928 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5); | |
929 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 2, 3); | |
930 gtk_widget_show (tempwid); | |
931 | |
932 bm_portedit = gtk_entry_new (); | |
933 gtk_table_attach_defaults (GTK_TABLE (table), bm_portedit, 1, 2, 2, 3); | |
934 if (entry->isfolder) | |
935 gtk_widget_set_sensitive (bm_portedit, 0); | |
936 else if (entry->port) | |
937 { | |
938 pos = g_strdup_printf ("%d", entry->port); | |
939 gtk_entry_set_text (GTK_ENTRY (bm_portedit), pos); | |
940 g_free (pos); | |
941 } | |
942 gtk_widget_show (bm_portedit); | |
943 | |
944 tempwid = gtk_label_new (_("Protocol:")); | |
945 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5); | |
946 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 3, 4); | |
947 gtk_widget_show (tempwid); | |
948 | |
949 menu = gtk_option_menu_new (); | |
950 gtk_table_attach_defaults (GTK_TABLE (table), menu, 1, 2, 3, 4); | |
951 gtk_widget_show (menu); | |
952 | |
953 num = 0; | |
954 bm_protocol = gtk_menu_new (); | |
955 for (i = 0; gftp_protocols[i].name; i++) | |
956 { | |
957 tempwid = gtk_menu_item_new_with_label (gftp_protocols[i].name); | |
958 gtk_object_set_user_data (GTK_OBJECT (tempwid), gftp_protocols[i].name); | |
959 gtk_menu_append (GTK_MENU (bm_protocol), tempwid); | |
960 gtk_widget_show (tempwid); | |
961 if (entry->protocol && | |
962 strcmp (gftp_protocols[i].name, entry->protocol) == 0) | |
963 num = i; | |
964 } | |
965 gtk_option_menu_set_menu (GTK_OPTION_MENU (menu), bm_protocol); | |
966 gtk_option_menu_set_history (GTK_OPTION_MENU (menu), num); | |
967 | |
968 tempwid = gtk_label_new (_("Remote Directory:")); | |
969 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5); | |
970 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 4, 5); | |
971 gtk_widget_show (tempwid); | |
972 | |
973 bm_remotediredit = gtk_entry_new (); | |
974 gtk_table_attach_defaults (GTK_TABLE (table), bm_remotediredit, 1, 2, 4, 5); | |
975 if (entry->isfolder) | |
976 gtk_widget_set_sensitive (bm_remotediredit, 0); | |
977 else if (entry->remote_dir) | |
978 gtk_entry_set_text (GTK_ENTRY (bm_remotediredit), entry->remote_dir); | |
979 gtk_widget_show (bm_remotediredit); | |
980 | |
981 tempwid = gtk_label_new (_("Local Directory:")); | |
982 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5); | |
983 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 5, 6); | |
984 gtk_widget_show (tempwid); | |
985 | |
986 bm_localdiredit = gtk_entry_new (); | |
987 gtk_table_attach_defaults (GTK_TABLE (table), bm_localdiredit, 1, 2, 5, 6); | |
988 if (entry->isfolder) | |
989 gtk_widget_set_sensitive (bm_localdiredit, 0); | |
990 else if (entry->local_dir) | |
991 gtk_entry_set_text (GTK_ENTRY (bm_localdiredit), entry->local_dir); | |
992 gtk_widget_show (bm_localdiredit); | |
993 | |
988
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
994 /* remote charset */ |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
995 tempwid = gtk_label_new (_("Remote Charset:")); |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
996 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5); |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
997 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 6, 7); |
1 | 998 gtk_widget_show (tempwid); |
999 | |
988
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
1000 bm_charsetedit = gtk_entry_new (); |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
1001 gtk_table_attach_defaults (GTK_TABLE (table), bm_charsetedit, 1, 2, 6, 7); |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
1002 if (entry->isfolder) |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
1003 gtk_widget_set_sensitive (bm_charsetedit, 0); |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
1004 else if (entry->remote_charset) { |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
1005 gtk_entry_set_text (GTK_ENTRY (bm_charsetedit), entry->remote_charset); |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
1006 } |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
1007 gtk_widget_show (bm_charsetedit); |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
1008 |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
1009 /* separator line */ |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
1010 tempwid = gtk_hseparator_new (); |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
1011 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 2, 8, 9); |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
1012 gtk_widget_show (tempwid); |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
1013 |
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
1014 /* user name */ |
1 | 1015 tempwid = gtk_label_new (_("Username:")); |
1016 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5); | |
988
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
1017 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 9, 10); |
1 | 1018 gtk_widget_show (tempwid); |
1019 | |
1020 bm_useredit = gtk_entry_new (); | |
988
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
1021 gtk_table_attach_defaults (GTK_TABLE (table), bm_useredit, 1, 2, 9, 10); |
1 | 1022 if (entry->isfolder) |
1023 gtk_widget_set_sensitive (bm_useredit, 0); | |
1024 else if (entry->user) | |
1025 gtk_entry_set_text (GTK_ENTRY (bm_useredit), entry->user); | |
1026 gtk_widget_show (bm_useredit); | |
1027 | |
1028 tempwid = gtk_label_new (_("Password:")); | |
1029 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5); | |
988
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
1030 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 10, 11); |
1 | 1031 gtk_widget_show (tempwid); |
1032 | |
1033 bm_passedit = gtk_entry_new (); | |
988
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
1034 gtk_table_attach_defaults (GTK_TABLE (table), bm_passedit, 1, 2, 10, 11); |
1 | 1035 gtk_entry_set_visibility (GTK_ENTRY (bm_passedit), FALSE); |
1036 if (entry->isfolder) | |
1037 gtk_widget_set_sensitive (bm_passedit, 0); | |
1038 else if (entry->pass) | |
1039 gtk_entry_set_text (GTK_ENTRY (bm_passedit), entry->pass); | |
1040 gtk_widget_show (bm_passedit); | |
1041 | |
1042 tempwid = gtk_label_new (_("Account:")); | |
1043 gtk_misc_set_alignment (GTK_MISC (tempwid), 1, 0.5); | |
988
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
1044 gtk_table_attach_defaults (GTK_TABLE (table), tempwid, 0, 1, 11, 12); |
1 | 1045 gtk_widget_show (tempwid); |
1046 | |
1047 bm_acctedit = gtk_entry_new (); | |
988
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
1048 gtk_table_attach_defaults (GTK_TABLE (table), bm_acctedit, 1, 2, 11, 12); |
1 | 1049 gtk_entry_set_visibility (GTK_ENTRY (bm_acctedit), FALSE); |
1050 if (entry->isfolder) | |
1051 gtk_widget_set_sensitive (bm_acctedit, 0); | |
1052 else if (entry->acct) | |
1053 gtk_entry_set_text (GTK_ENTRY (bm_acctedit), entry->acct); | |
1054 gtk_widget_show (bm_acctedit); | |
1055 | |
1056 anon_chk = gtk_check_button_new_with_label (_("Log in as ANONYMOUS")); | |
988
63555c9744c2
remote charset should be specified by each bookmark entry.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
941
diff
changeset
|
1057 gtk_table_attach_defaults (GTK_TABLE (table), anon_chk, 0, 2, 12, 13); |
1 | 1058 if (entry->isfolder) |
1059 gtk_widget_set_sensitive (anon_chk, 0); | |
1060 else | |
1061 { | |
1062 gtk_signal_connect (GTK_OBJECT (anon_chk), "toggled", | |
1063 GTK_SIGNAL_FUNC (set_userpass_visible), NULL); | |
1064 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (anon_chk), entry->user | |
1065 && strcmp (entry->user, "anonymous") == 0); | |
1066 } | |
1067 gtk_widget_show (anon_chk); | |
1068 | |
45 | 1069 #if GTK_MAJOR_VERSION == 1 |
1 | 1070 tempwid = gtk_button_new_with_label (_("OK")); |
422 | 1071 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (bm_dialog)->action_area), tempwid, |
1 | 1072 TRUE, TRUE, 0); |
1073 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
1074 GTK_SIGNAL_FUNC (entry_apply_changes), | |
1075 (gpointer) entry); | |
1076 gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked", | |
422 | 1077 GTK_SIGNAL_FUNC (entry_close_dialog), NULL); |
1 | 1078 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT); |
1079 gtk_widget_show (tempwid); | |
1080 | |
1081 tempwid = gtk_button_new_with_label (_(" Cancel ")); | |
422 | 1082 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (bm_dialog)->action_area), tempwid, |
1 | 1083 TRUE, TRUE, 0); |
1084 gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked", | |
570 | 1085 GTK_SIGNAL_FUNC (entry_close_dialog), NULL); |
1 | 1086 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT); |
1087 gtk_widget_grab_focus (tempwid); | |
1088 gtk_widget_show (tempwid); | |
19 | 1089 #else |
422 | 1090 g_signal_connect (GTK_OBJECT (bm_dialog), "response", |
19 | 1091 G_CALLBACK (bmedit_action), (gpointer) entry); |
1092 #endif | |
1 | 1093 |
229 | 1094 gftp_gtk_setup_bookmark_options (notebook, entry); |
227 | 1095 |
422 | 1096 gtk_widget_show (bm_dialog); |
1 | 1097 } |
1098 | |
1099 | |
48 | 1100 static gint |
1101 bm_enter (GtkWidget * widget, GdkEventKey * event, gpointer data) | |
1 | 1102 { |
48 | 1103 if (event->type == GDK_KEY_PRESS) |
1 | 1104 { |
48 | 1105 if (event->keyval == GDK_Return || event->keyval == GDK_KP_Enter) |
1106 { | |
1107 edit_entry (NULL); | |
1108 return (FALSE); | |
1109 } | |
1110 else if (event->keyval == GDK_KP_Delete || event->keyval == GDK_Delete) | |
1111 { | |
1112 delete_entry (NULL); | |
1113 return (FALSE); | |
1114 } | |
1 | 1115 } |
48 | 1116 return (TRUE); |
1 | 1117 } |
1118 | |
1119 | |
366 | 1120 static inline gboolean |
1121 move_possible (GtkCTree *ctree, GtkCTreeNode *child, GtkCTreeNode *parent, | |
1122 GtkCTreeNode *sibling) | |
1123 { | |
1124 return (parent != NULL && sibling != NULL); | |
1125 } | |
1126 | |
1127 | |
1 | 1128 static void |
48 | 1129 after_move (GtkCTree * ctree, GtkCTreeNode * child, GtkCTreeNode * parent, |
1130 GtkCTreeNode * sibling, gpointer data) | |
1 | 1131 { |
48 | 1132 |
129 | 1133 gftp_bookmarks_var * childentry, * siblingentry, * parententry, * tempentry; |
48 | 1134 char *tempstr, *pos, *stpos; |
1135 | |
1136 childentry = gtk_ctree_node_get_row_data (ctree, child); | |
1137 parententry = gtk_ctree_node_get_row_data (ctree, parent); | |
1138 siblingentry = gtk_ctree_node_get_row_data (ctree, sibling); | |
1 | 1139 |
48 | 1140 tempentry = childentry->prev->children; |
1141 if (tempentry == childentry) | |
1142 childentry->prev->children = childentry->prev->children->next; | |
1143 else | |
1 | 1144 { |
48 | 1145 while (tempentry->next != childentry) |
1146 tempentry = tempentry->next; | |
1147 tempentry->next = childentry->next; | |
1148 } | |
1149 childentry->prev = parententry; | |
1150 if (!parententry->isfolder) | |
1151 { | |
1152 childentry->next = parententry->children; | |
1153 parententry->children = childentry; | |
1154 gtk_ctree_move (ctree, child, parententry->prev->cnode, | |
1155 parententry->cnode); | |
1 | 1156 } |
1157 else | |
1158 { | |
48 | 1159 if (siblingentry == NULL || parententry->children == siblingentry) |
1160 { | |
1161 childentry->next = parententry->children; | |
1162 parententry->children = childentry; | |
1163 } | |
1164 else | |
1165 { | |
1166 tempentry = parententry->children; | |
1167 while (tempentry->next != siblingentry) | |
1168 tempentry = tempentry->next; | |
1169 childentry->next = tempentry->next; | |
1170 tempentry->next = childentry; | |
1171 } | |
1 | 1172 |
48 | 1173 tempentry = childentry; |
1 | 1174 while (tempentry != NULL) |
1175 { | |
1176 g_hash_table_remove (new_bookmarks_htable, tempentry->path); | |
48 | 1177 if ((pos = strrchr (tempentry->path, '/')) == NULL) |
1178 pos = tempentry->path; | |
1179 else | |
1180 pos++; | |
1181 tempstr = g_strdup_printf ("%s/%s", tempentry->prev->path, pos); | |
1182 for (stpos = tempstr; *stpos == '/'; stpos++); | |
1 | 1183 g_free (tempentry->path); |
129 | 1184 tempentry->path = g_strdup (stpos); |
48 | 1185 g_free (tempstr); |
1 | 1186 g_hash_table_insert (new_bookmarks_htable, tempentry->path, |
1187 tempentry); | |
1188 if (tempentry->children != NULL) | |
48 | 1189 tempentry = tempentry->children; |
1190 else | |
1 | 1191 { |
48 | 1192 if (tempentry->next == NULL) |
1 | 1193 { |
48 | 1194 if (tempentry->prev == childentry) |
1195 break; | |
1 | 1196 else |
48 | 1197 { |
1198 while (tempentry->next == NULL | |
1199 && tempentry->prev != NULL) | |
1200 tempentry = tempentry->prev; | |
1201 } | |
1 | 1202 } |
48 | 1203 tempentry = tempentry->next; |
1 | 1204 } |
1205 } | |
1206 } | |
1207 } | |
1208 | |
1209 | |
48 | 1210 static gint |
1211 bm_dblclick (GtkWidget * widget, GdkEventButton * event, gpointer data) | |
1 | 1212 { |
48 | 1213 if (event->button == 3) |
1214 gtk_item_factory_popup (edit_factory, (guint) event->x_root, | |
1215 (guint) event->y_root, 1, 0); | |
1216 else if (event->type == GDK_2BUTTON_PRESS) | |
1 | 1217 { |
48 | 1218 edit_entry (NULL); |
1219 return (FALSE); | |
1 | 1220 } |
48 | 1221 return (TRUE); |
1 | 1222 } |
1223 | |
48 | 1224 |
1225 void | |
1226 edit_bookmarks (gpointer data) | |
1227 { | |
791 | 1228 GtkAccelGroup * accel_group; |
48 | 1229 GtkItemFactory * ifactory; |
452 | 1230 GtkWidget * scroll; |
48 | 1231 GtkItemFactoryEntry menu_items[] = { |
570 | 1232 {N_("/_File"), NULL, 0, 0, MN_("<Branch>")}, |
1233 {N_("/File/tearoff"), NULL, 0, 0, MN_("<Tearoff>")}, | |
791 | 1234 {N_("/File/New _Folder..."), NULL, new_folder_entry, 0, MN_(NULL)}, |
1235 {N_("/File/New _Item..."), NULL, new_item_entry, 0, MS_(GTK_STOCK_NEW)}, | |
1236 {N_("/File/_Delete"), NULL, delete_entry, 0, MS_(GTK_STOCK_DELETE)}, | |
1237 {N_("/File/_Properties..."), NULL, edit_entry, 0, MS_(GTK_STOCK_PROPERTIES)}, | |
570 | 1238 {N_("/File/sep"), NULL, 0, 0, MN_("<Separator>")}, |
791 | 1239 {N_("/File/_Close"), NULL, gtk_widget_destroy, 0, MS_(GTK_STOCK_CLOSE)} |
48 | 1240 }; |
1241 #if GTK_MAJOR_VERSION == 1 | |
1242 GtkWidget * tempwid; | |
1243 #endif | |
1244 | |
452 | 1245 if (edit_bookmarks_dialog != NULL) |
1246 { | |
1247 gtk_widget_grab_focus (edit_bookmarks_dialog); | |
1248 return; | |
1249 } | |
1250 | |
129 | 1251 new_bookmarks = copy_bookmarks (gftp_bookmarks); |
48 | 1252 new_bookmarks_htable = build_bookmarks_hash_table (new_bookmarks); |
1253 | |
1254 #if GTK_MAJOR_VERSION == 1 | |
452 | 1255 edit_bookmarks_dialog = gtk_dialog_new (); |
1256 gtk_window_set_title (GTK_WINDOW (edit_bookmarks_dialog), | |
1257 _("Edit Bookmarks")); | |
1258 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (edit_bookmarks_dialog)->action_area), 15); | |
48 | 1259 #else |
452 | 1260 edit_bookmarks_dialog = gtk_dialog_new_with_buttons (_("Edit Bookmarks"), |
866 | 1261 NULL, 0, |
452 | 1262 GTK_STOCK_CANCEL, |
1263 GTK_RESPONSE_CANCEL, | |
866 | 1264 GTK_STOCK_SAVE, |
1265 GTK_RESPONSE_OK, | |
452 | 1266 NULL); |
48 | 1267 #endif |
452 | 1268 gtk_window_set_wmclass (GTK_WINDOW(edit_bookmarks_dialog), "Edit Bookmarks", |
1269 "gFTP"); | |
1270 gtk_window_set_position (GTK_WINDOW (edit_bookmarks_dialog), | |
1271 GTK_WIN_POS_MOUSE); | |
1272 gtk_widget_realize (edit_bookmarks_dialog); | |
48 | 1273 |
1274 if (gftp_icon != NULL) | |
1275 { | |
452 | 1276 gdk_window_set_icon (edit_bookmarks_dialog->window, NULL, |
1277 gftp_icon->pixmap, gftp_icon->bitmap); | |
1278 gdk_window_set_icon_name (edit_bookmarks_dialog->window, gftp_version); | |
48 | 1279 } |
1280 | |
791 | 1281 accel_group = gtk_accel_group_new (); |
1282 ifactory = item_factory_new (GTK_TYPE_MENU_BAR, "<bookmarks>", accel_group, | |
1283 NULL); | |
48 | 1284 create_item_factory (ifactory, 7, menu_items, NULL); |
452 | 1285 create_item_factory (ifactory, 1, menu_items + 7, edit_bookmarks_dialog); |
1286 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (edit_bookmarks_dialog)->vbox), | |
1287 ifactory->widget, FALSE, FALSE, 0); | |
48 | 1288 gtk_widget_show (ifactory->widget); |
1289 | |
1290 scroll = gtk_scrolled_window_new (NULL, NULL); | |
1291 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), | |
1292 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
1293 gtk_widget_set_size_request (scroll, 150, 200); | |
1294 | |
452 | 1295 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (edit_bookmarks_dialog)->vbox), |
1296 scroll, TRUE, TRUE, 0); | |
48 | 1297 gtk_container_border_width (GTK_CONTAINER (scroll), 3); |
1298 gtk_widget_show (scroll); | |
1299 | |
1300 edit_factory = item_factory_new (GTK_TYPE_MENU, "<edit_bookmark>", NULL, "/File"); | |
1301 | |
452 | 1302 create_item_factory (edit_factory, 6, menu_items + 2, edit_bookmarks_dialog); |
48 | 1303 |
791 | 1304 gtk_window_add_accel_group (GTK_WINDOW (edit_bookmarks_dialog), accel_group); |
1305 | |
48 | 1306 tree = gtk_ctree_new (1, 0); |
1307 gtk_clist_set_selection_mode (GTK_CLIST (tree), GTK_SELECTION_BROWSE); | |
1308 gtk_clist_set_reorderable (GTK_CLIST (tree), 1); | |
1309 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scroll), tree); | |
1310 gtk_signal_connect_after (GTK_OBJECT (tree), "key_press_event", | |
1311 GTK_SIGNAL_FUNC (bm_enter), (gpointer) tree); | |
1312 gtk_signal_connect_after (GTK_OBJECT (tree), "tree_move", | |
1313 GTK_SIGNAL_FUNC (after_move), NULL); | |
1314 gtk_signal_connect_after (GTK_OBJECT (tree), "button_press_event", | |
1315 GTK_SIGNAL_FUNC (bm_dblclick), (gpointer) tree); | |
366 | 1316 gtk_ctree_set_drag_compare_func (GTK_CTREE(tree), &move_possible); |
48 | 1317 gtk_widget_show (tree); |
1318 | |
1319 #if GTK_MAJOR_VERSION == 1 | |
1320 tempwid = gtk_button_new_with_label (_("OK")); | |
452 | 1321 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (edit_bookmarks_dialog)->action_area), |
1322 tempwid, TRUE, TRUE, 0); | |
48 | 1323 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", |
1324 GTK_SIGNAL_FUNC (bm_apply_changes), NULL); | |
1325 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", | |
452 | 1326 GTK_SIGNAL_FUNC (bm_close_dialog), |
1327 (gpointer) edit_bookmarks_dialog); | |
48 | 1328 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT); |
1329 gtk_widget_show (tempwid); | |
1330 | |
1331 tempwid = gtk_button_new_with_label (_(" Cancel ")); | |
452 | 1332 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (edit_bookmarks_dialog)->action_area), |
1333 tempwid, TRUE, TRUE, 0); | |
48 | 1334 gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", |
452 | 1335 GTK_SIGNAL_FUNC (bm_close_dialog), |
1336 (gpointer) edit_bookmarks_dialog); | |
48 | 1337 GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT); |
1338 gtk_widget_grab_focus (tempwid); | |
1339 gtk_widget_show (tempwid); | |
1340 #else | |
452 | 1341 g_signal_connect (GTK_OBJECT (edit_bookmarks_dialog), "response", |
48 | 1342 G_CALLBACK (editbm_action), NULL); |
1343 #endif | |
1344 | |
452 | 1345 gtk_widget_show (edit_bookmarks_dialog); |
48 | 1346 |
1347 build_bookmarks_tree (); | |
1348 } | |
1349 |