192 |
g_assert(0); |
g_assert(0); |
193 |
} |
} |
194 |
|
|
195 |
static void relation_list_selected(relitem_context_t *context, |
static void relation_item_list_selected(relitem_context_t *context, |
196 |
gboolean selected) { |
gboolean selected) { |
197 |
|
|
198 |
if(context->but_remove) |
if(context->but_remove) |
199 |
gtk_widget_set_sensitive(context->but_remove, FALSE); |
gtk_widget_set_sensitive(context->but_remove, selected); |
200 |
if(context->but_edit) |
if(context->but_edit) |
201 |
gtk_widget_set_sensitive(context->but_edit, selected); |
gtk_widget_set_sensitive(context->but_edit, selected); |
202 |
} |
} |
203 |
|
|
204 |
static gboolean |
static gboolean |
205 |
relation_list_selection_func(GtkTreeSelection *selection, GtkTreeModel *model, |
relation_item_list_selection_func(GtkTreeSelection *selection, GtkTreeModel *model, |
206 |
GtkTreePath *path, gboolean path_currently_selected, |
GtkTreePath *path, gboolean path_currently_selected, |
207 |
gpointer userdata) { |
gpointer userdata) { |
208 |
relitem_context_t *context = (relitem_context_t*)userdata; |
relitem_context_t *context = (relitem_context_t*)userdata; |
210 |
|
|
211 |
if(gtk_tree_model_get_iter(model, &iter, path)) { |
if(gtk_tree_model_get_iter(model, &iter, path)) { |
212 |
g_assert(gtk_tree_path_get_depth(path) == 1); |
g_assert(gtk_tree_path_get_depth(path) == 1); |
213 |
relation_list_selected(context, TRUE); |
relation_item_list_selected(context, TRUE); |
214 |
} |
} |
215 |
|
|
216 |
return TRUE; /* allow selection state to change */ |
return TRUE; /* allow selection state to change */ |
217 |
} |
} |
218 |
|
|
219 |
static void on_relation_add(GtkWidget *but, relitem_context_t *context) { |
static void on_relation_item_add(GtkWidget *but, relitem_context_t *context) { |
220 |
/* create a new relation */ |
/* create a new relation */ |
221 |
|
|
222 |
relation_t *relation = osm_relation_new(); |
relation_t *relation = osm_relation_new(); |
266 |
return NULL; |
return NULL; |
267 |
} |
} |
268 |
|
|
269 |
static void on_relation_edit(GtkWidget *but, relitem_context_t *context) { |
static void on_relation_item_edit(GtkWidget *but, relitem_context_t *context) { |
270 |
relation_t *sel = get_selection(context); |
relation_t *sel = get_selection(context); |
271 |
if(!sel) return; |
if(!sel) return; |
272 |
|
|
275 |
info_dialog(context->dialog, context->appdata, sel); |
info_dialog(context->dialog, context->appdata, sel); |
276 |
} |
} |
277 |
|
|
278 |
static void on_relation_remove(GtkWidget *but, relitem_context_t *context) { |
/* remove the selected relation */ |
279 |
|
static void on_relation_item_remove(GtkWidget *but, relitem_context_t *context) { |
280 |
relation_t *sel = get_selection(context); |
relation_t *sel = get_selection(context); |
281 |
if(!sel) return; |
if(!sel) return; |
282 |
|
|
283 |
printf("remove relation #%ld\n", sel->id); |
printf("remove relation #%ld\n", sel->id); |
284 |
|
|
285 |
|
gint members = osm_relation_members_num(sel); |
286 |
|
|
287 |
|
if(members) |
288 |
|
if(!yes_no_f(context->dialog, NULL, 0, 0, |
289 |
|
_("Delete non-empty relation?"), |
290 |
|
_("This relation still has %d members. " |
291 |
|
"Delete it anyway?"), members)) |
292 |
|
return; |
293 |
|
|
294 |
|
/* first remove selected row from list */ |
295 |
|
GtkTreeIter iter; |
296 |
|
GtkTreeSelection *selection = |
297 |
|
gtk_tree_view_get_selection(GTK_TREE_VIEW(context->view)); |
298 |
|
if(gtk_tree_selection_get_selected(selection, NULL, &iter)) |
299 |
|
gtk_list_store_remove(context->store, &iter); |
300 |
|
|
301 |
|
/* then really delete it */ |
302 |
|
osm_relation_delete(context->appdata->osm, sel, FALSE); |
303 |
|
|
304 |
|
relation_item_list_selected(context, FALSE); |
305 |
} |
} |
306 |
|
|
307 |
static char *relitem_get_role_in_relation(relation_item_t *item, relation_t *relation) { |
static char *relitem_get_role_in_relation(relation_item_t *item, relation_t *relation) { |
329 |
|
|
330 |
static void |
static void |
331 |
relitem_toggled(GtkCellRendererToggle *cell, const gchar *path_str, |
relitem_toggled(GtkCellRendererToggle *cell, const gchar *path_str, |
332 |
relitem_context_t *context) { |
relitem_context_t *context) { |
333 |
GtkTreePath *path; |
GtkTreePath *path; |
334 |
GtkTreeIter iter; |
GtkTreeIter iter; |
335 |
|
|
386 |
return FALSE; |
return FALSE; |
387 |
} |
} |
388 |
|
|
389 |
static GtkWidget *relation_list(relitem_context_t *context) { |
static GtkWidget *relation_item_list_widget(relitem_context_t *context) { |
390 |
GtkWidget *vbox = gtk_vbox_new(FALSE,3); |
GtkWidget *vbox = gtk_vbox_new(FALSE,3); |
391 |
context->view = gtk_tree_view_new(); |
context->view = gtk_tree_view_new(); |
392 |
|
|
393 |
gtk_tree_selection_set_select_function( |
gtk_tree_selection_set_select_function( |
394 |
gtk_tree_view_get_selection(GTK_TREE_VIEW(context->view)), |
gtk_tree_view_get_selection(GTK_TREE_VIEW(context->view)), |
395 |
relation_list_selection_func, |
relation_item_list_selection_func, |
396 |
context, NULL); |
context, NULL); |
397 |
|
|
398 |
|
|
472 |
// gtk_widget_set_sensitive(context->but_add, FALSE); |
// gtk_widget_set_sensitive(context->but_add, FALSE); |
473 |
gtk_box_pack_start_defaults(GTK_BOX(hbox), context->but_add); |
gtk_box_pack_start_defaults(GTK_BOX(hbox), context->but_add); |
474 |
gtk_signal_connect(GTK_OBJECT(context->but_add), "clicked", |
gtk_signal_connect(GTK_OBJECT(context->but_add), "clicked", |
475 |
GTK_SIGNAL_FUNC(on_relation_add), context); |
GTK_SIGNAL_FUNC(on_relation_item_add), context); |
476 |
|
|
477 |
context->but_edit = gtk_button_new_with_label(_("Edit...")); |
context->but_edit = gtk_button_new_with_label(_("Edit...")); |
478 |
gtk_box_pack_start_defaults(GTK_BOX(hbox), context->but_edit); |
gtk_box_pack_start_defaults(GTK_BOX(hbox), context->but_edit); |
479 |
gtk_signal_connect(GTK_OBJECT(context->but_edit), "clicked", |
gtk_signal_connect(GTK_OBJECT(context->but_edit), "clicked", |
480 |
GTK_SIGNAL_FUNC(on_relation_edit), context); |
GTK_SIGNAL_FUNC(on_relation_item_edit), context); |
481 |
|
|
482 |
context->but_remove = gtk_button_new_with_label(_("Remove")); |
context->but_remove = gtk_button_new_with_label(_("Remove")); |
483 |
gtk_box_pack_start_defaults(GTK_BOX(hbox), context->but_remove); |
gtk_box_pack_start_defaults(GTK_BOX(hbox), context->but_remove); |
484 |
gtk_signal_connect(GTK_OBJECT(context->but_remove), "clicked", |
gtk_signal_connect(GTK_OBJECT(context->but_remove), "clicked", |
485 |
GTK_SIGNAL_FUNC(on_relation_remove), context); |
GTK_SIGNAL_FUNC(on_relation_item_remove), context); |
486 |
|
|
487 |
relation_list_selected(context, FALSE); |
relation_item_list_selected(context, FALSE); |
488 |
|
|
489 |
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
490 |
return vbox; |
return vbox; |
518 |
g_free(str); |
g_free(str); |
519 |
|
|
520 |
gtk_dialog_set_default_response(GTK_DIALOG(context->dialog), |
gtk_dialog_set_default_response(GTK_DIALOG(context->dialog), |
521 |
GTK_RESPONSE_ACCEPT); |
GTK_RESPONSE_CLOSE); |
522 |
|
|
523 |
|
/* making the dialog a little wider makes it less "crowded" */ |
524 |
|
#ifdef USE_HILDON |
525 |
|
gtk_window_set_default_size(GTK_WINDOW(context->dialog), 500, 300); |
526 |
|
#else |
527 |
|
gtk_window_set_default_size(GTK_WINDOW(context->dialog), 400, 200); |
528 |
|
#endif |
529 |
|
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(context->dialog)->vbox), |
530 |
|
relation_item_list_widget(context), TRUE, TRUE, 0); |
531 |
|
|
532 |
|
/* ----------------------------------- */ |
533 |
|
|
534 |
|
gtk_widget_show_all(context->dialog); |
535 |
|
gtk_dialog_run(GTK_DIALOG(context->dialog)); |
536 |
|
gtk_widget_destroy(context->dialog); |
537 |
|
|
538 |
|
g_free(context); |
539 |
|
} |
540 |
|
|
541 |
|
/* -------------------- global relation list ----------------- */ |
542 |
|
|
543 |
|
typedef struct { |
544 |
|
appdata_t *appdata; |
545 |
|
GtkWidget *dialog, *view; |
546 |
|
GtkWidget *but_members, *but_add, *but_edit, *but_remove; |
547 |
|
GtkListStore *store; |
548 |
|
} relation_context_t; |
549 |
|
|
550 |
|
enum { |
551 |
|
RELATION_COL_ID = 0, |
552 |
|
RELATION_COL_TYPE, |
553 |
|
RELATION_COL_NAME, |
554 |
|
RELATION_COL_MEMBERS, |
555 |
|
RELATION_COL_DATA, |
556 |
|
RELATION_NUM_COLS |
557 |
|
}; |
558 |
|
|
559 |
|
static relation_t *get_selected_relation(relation_context_t *context) { |
560 |
|
GtkTreeSelection *selection; |
561 |
|
GtkTreeModel *model; |
562 |
|
GtkTreeIter iter; |
563 |
|
|
564 |
|
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(context->view)); |
565 |
|
if(gtk_tree_selection_get_selected(selection, &model, &iter)) { |
566 |
|
relation_t *relation; |
567 |
|
gtk_tree_model_get(model, &iter, RELATION_COL_DATA, &relation, -1); |
568 |
|
return(relation); |
569 |
|
} |
570 |
|
return NULL; |
571 |
|
} |
572 |
|
|
573 |
|
static void relation_list_selected(relation_context_t *context, |
574 |
|
relation_t *selected) { |
575 |
|
|
576 |
|
if(context->but_members) |
577 |
|
gtk_widget_set_sensitive(context->but_members, |
578 |
|
(selected != NULL) && (selected->member != NULL)); |
579 |
|
|
580 |
|
if(context->but_remove) |
581 |
|
gtk_widget_set_sensitive(context->but_remove, selected != NULL); |
582 |
|
if(context->but_edit) |
583 |
|
gtk_widget_set_sensitive(context->but_edit, selected != NULL); |
584 |
|
} |
585 |
|
|
586 |
|
static gboolean |
587 |
|
relation_list_selection_func(GtkTreeSelection *selection, GtkTreeModel *model, |
588 |
|
GtkTreePath *path, gboolean path_currently_selected, |
589 |
|
gpointer userdata) { |
590 |
|
relation_context_t *context = (relation_context_t*)userdata; |
591 |
|
GtkTreeIter iter; |
592 |
|
|
593 |
|
if(gtk_tree_model_get_iter(model, &iter, path)) { |
594 |
|
g_assert(gtk_tree_path_get_depth(path) == 1); |
595 |
|
|
596 |
|
relation_t *relation = NULL; |
597 |
|
gtk_tree_model_get(model, &iter, RELATION_COL_DATA, &relation, -1); |
598 |
|
relation_list_selected(context, relation); |
599 |
|
} |
600 |
|
|
601 |
|
return TRUE; /* allow selection state to change */ |
602 |
|
} |
603 |
|
|
604 |
|
typedef struct { |
605 |
|
relation_t *relation; |
606 |
|
GtkWidget *dialog, *view; |
607 |
|
GtkListStore *store; |
608 |
|
} member_context_t; |
609 |
|
|
610 |
|
enum { |
611 |
|
MEMBER_COL_TYPE = 0, |
612 |
|
MEMBER_COL_ID, |
613 |
|
MEMBER_COL_NAME, |
614 |
|
MEMBER_COL_ROLE, |
615 |
|
MEMBER_COL_REF_ONLY, |
616 |
|
MEMBER_COL_DATA, |
617 |
|
MEMBER_NUM_COLS |
618 |
|
}; |
619 |
|
|
620 |
|
static gboolean |
621 |
|
member_list_selection_func(GtkTreeSelection *selection, GtkTreeModel *model, |
622 |
|
GtkTreePath *path, gboolean path_currently_selected, |
623 |
|
gpointer userdata) { |
624 |
|
GtkTreeIter iter; |
625 |
|
|
626 |
|
if(gtk_tree_model_get_iter(model, &iter, path)) { |
627 |
|
g_assert(gtk_tree_path_get_depth(path) == 1); |
628 |
|
|
629 |
|
member_t *member = NULL; |
630 |
|
gtk_tree_model_get(model, &iter, MEMBER_COL_DATA, &member, -1); |
631 |
|
if(member && member->type < NODE_ID) |
632 |
|
return TRUE; |
633 |
|
} |
634 |
|
|
635 |
|
return FALSE; |
636 |
|
} |
637 |
|
|
638 |
|
|
639 |
|
static GtkWidget *member_list_widget(member_context_t *context) { |
640 |
|
GtkWidget *vbox = gtk_vbox_new(FALSE,3); |
641 |
|
context->view = gtk_tree_view_new(); |
642 |
|
|
643 |
|
gtk_tree_selection_set_select_function( |
644 |
|
gtk_tree_view_get_selection(GTK_TREE_VIEW(context->view)), |
645 |
|
member_list_selection_func, |
646 |
|
context, NULL); |
647 |
|
|
648 |
|
/* --- "type" column --- */ |
649 |
|
GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); |
650 |
|
g_object_set(renderer, "foreground", "grey", NULL); |
651 |
|
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(context->view), |
652 |
|
-1, _("Type"), renderer, "text", MEMBER_COL_TYPE, |
653 |
|
"foreground-set", MEMBER_COL_REF_ONLY, NULL); |
654 |
|
|
655 |
|
|
656 |
|
/* --- "id" column --- */ |
657 |
|
renderer = gtk_cell_renderer_text_new(); |
658 |
|
g_object_set(renderer, "foreground", "grey", NULL); |
659 |
|
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(context->view), |
660 |
|
-1, _("Id"), renderer, "text", MEMBER_COL_ID, |
661 |
|
"foreground-set", MEMBER_COL_REF_ONLY, NULL); |
662 |
|
|
663 |
|
/* --- "Name" column --- */ |
664 |
|
renderer = gtk_cell_renderer_text_new(); |
665 |
|
g_object_set(renderer, "foreground", "grey", NULL); |
666 |
|
g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL); |
667 |
|
GtkTreeViewColumn *column = |
668 |
|
gtk_tree_view_column_new_with_attributes(_("Name"), renderer, |
669 |
|
"text", MEMBER_COL_NAME, |
670 |
|
"foreground-set", MEMBER_COL_REF_ONLY, NULL); |
671 |
|
gtk_tree_view_column_set_expand(column, TRUE); |
672 |
|
gtk_tree_view_insert_column(GTK_TREE_VIEW(context->view), column, -1); |
673 |
|
|
674 |
|
/* --- "role" column --- */ |
675 |
|
renderer = gtk_cell_renderer_text_new(); |
676 |
|
g_object_set(renderer, "foreground", "grey", NULL); |
677 |
|
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(context->view), |
678 |
|
-1, _("Role"), renderer, "text", MEMBER_COL_ROLE, |
679 |
|
"foreground-set", MEMBER_COL_REF_ONLY, NULL); |
680 |
|
|
681 |
|
/* build and fill the store */ |
682 |
|
context->store = gtk_list_store_new(MEMBER_NUM_COLS, |
683 |
|
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, |
684 |
|
G_TYPE_BOOLEAN, G_TYPE_POINTER); |
685 |
|
|
686 |
|
gtk_tree_view_set_model(GTK_TREE_VIEW(context->view), |
687 |
|
GTK_TREE_MODEL(context->store)); |
688 |
|
|
689 |
|
GtkTreeIter iter; |
690 |
|
member_t *member = context->relation->member; |
691 |
|
while(member) { |
692 |
|
tag_t *tags = osm_object_get_tags(member->type, member->ptr); |
693 |
|
char *id = osm_id_string(member->type, member->ptr); |
694 |
|
|
695 |
|
/* try to find something descriptive */ |
696 |
|
char *name = NULL; |
697 |
|
if(tags) |
698 |
|
name = osm_tag_get_by_key(tags, "name"); |
699 |
|
|
700 |
|
/* Append a row and fill in some data */ |
701 |
|
gtk_list_store_append(context->store, &iter); |
702 |
|
gtk_list_store_set(context->store, &iter, |
703 |
|
MEMBER_COL_TYPE, osm_type_string(member->type), |
704 |
|
MEMBER_COL_ID, id, |
705 |
|
MEMBER_COL_NAME, name, |
706 |
|
MEMBER_COL_ROLE, member->role, |
707 |
|
MEMBER_COL_REF_ONLY, member->type >= NODE_ID, |
708 |
|
MEMBER_COL_DATA, member, |
709 |
|
-1); |
710 |
|
|
711 |
|
g_free(id); |
712 |
|
member = member->next; |
713 |
|
} |
714 |
|
|
715 |
|
g_object_unref(context->store); |
716 |
|
|
717 |
|
/* put it into a scrolled window */ |
718 |
|
GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL); |
719 |
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), |
720 |
|
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); |
721 |
|
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_window), |
722 |
|
GTK_SHADOW_ETCHED_IN); |
723 |
|
gtk_container_add(GTK_CONTAINER(scrolled_window), context->view); |
724 |
|
|
725 |
|
gtk_box_pack_start_defaults(GTK_BOX(vbox), scrolled_window); |
726 |
|
|
727 |
|
return vbox; |
728 |
|
} |
729 |
|
|
730 |
|
/* user clicked "members..." button in relation list */ |
731 |
|
static void on_relation_members(GtkWidget *but, relation_context_t *context) { |
732 |
|
member_context_t *mcontext = g_new0(member_context_t, 1); |
733 |
|
|
734 |
|
/* display members list */ |
735 |
|
mcontext->relation = get_selected_relation(context); |
736 |
|
if(!mcontext->relation) return; |
737 |
|
|
738 |
|
char *str = osm_tag_get_by_key(mcontext->relation->tag, "name"); |
739 |
|
if(!str) str = osm_tag_get_by_key(mcontext->relation->tag, "ref"); |
740 |
|
if(!str) |
741 |
|
str = g_strdup_printf(_("Members of relation #%ld"), |
742 |
|
mcontext->relation->id); |
743 |
|
else |
744 |
|
str = g_strdup_printf(_("Members of relation \"%s\""), str); |
745 |
|
|
746 |
|
mcontext->dialog = |
747 |
|
gtk_dialog_new_with_buttons(str, |
748 |
|
GTK_WINDOW(context->dialog), GTK_DIALOG_MODAL, |
749 |
|
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, |
750 |
|
NULL); |
751 |
|
g_free(str); |
752 |
|
|
753 |
|
gtk_dialog_set_default_response(GTK_DIALOG(mcontext->dialog), |
754 |
|
GTK_RESPONSE_CLOSE); |
755 |
|
|
756 |
|
/* making the dialog a little wider makes it less "crowded" */ |
757 |
|
#ifdef USE_HILDON |
758 |
|
gtk_window_set_default_size(GTK_WINDOW(mcontext->dialog), 500, 300); |
759 |
|
#else |
760 |
|
gtk_window_set_default_size(GTK_WINDOW(mcontext->dialog), 400, 200); |
761 |
|
#endif |
762 |
|
|
763 |
|
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(mcontext->dialog)->vbox), |
764 |
|
member_list_widget(mcontext), TRUE, TRUE, 0); |
765 |
|
|
766 |
|
/* ----------------------------------- */ |
767 |
|
|
768 |
|
gtk_widget_show_all(mcontext->dialog); |
769 |
|
gtk_dialog_run(GTK_DIALOG(mcontext->dialog)); |
770 |
|
gtk_widget_destroy(mcontext->dialog); |
771 |
|
|
772 |
|
g_free(mcontext); |
773 |
|
} |
774 |
|
|
775 |
|
static void on_relation_add(GtkWidget *but, relation_context_t *context) { |
776 |
|
/* create a new relation */ |
777 |
|
|
778 |
|
relation_t *relation = osm_relation_new(); |
779 |
|
if(!info_dialog(context->dialog, context->appdata, relation)) { |
780 |
|
printf("tag edit cancelled\n"); |
781 |
|
osm_relation_free(relation); |
782 |
|
} else { |
783 |
|
osm_relation_attach(context->appdata->osm, relation); |
784 |
|
|
785 |
|
/* append a row for the new data */ |
786 |
|
/* try to find something descriptive */ |
787 |
|
|
788 |
|
char *id = g_strdup_printf("#%ld", relation->id); |
789 |
|
|
790 |
|
/* try to find something descriptive */ |
791 |
|
char *name = osm_tag_get_by_key(relation->tag, "name"); |
792 |
|
if(!name) name = osm_tag_get_by_key(relation->tag, "ref"); |
793 |
|
|
794 |
|
char *num = g_strdup_printf("%d", osm_relation_members_num(relation)); |
795 |
|
|
796 |
|
/* Append a row and fill in some data */ |
797 |
|
GtkTreeIter iter; |
798 |
|
gtk_list_store_append(context->store, &iter); |
799 |
|
gtk_list_store_set(context->store, &iter, |
800 |
|
RELATION_COL_ID, id, |
801 |
|
RELATION_COL_TYPE, |
802 |
|
osm_tag_get_by_key(relation->tag, "type"), |
803 |
|
RELATION_COL_NAME, name, |
804 |
|
RELATION_COL_MEMBERS, num, |
805 |
|
RELATION_COL_DATA, relation, |
806 |
|
-1); |
807 |
|
|
808 |
|
g_free(id); |
809 |
|
g_free(num); |
810 |
|
|
811 |
|
gtk_tree_selection_select_iter(gtk_tree_view_get_selection( |
812 |
|
GTK_TREE_VIEW(context->view)), &iter); |
813 |
|
|
814 |
|
/* scroll to end */ |
815 |
|
// GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment(); |
816 |
|
/* xyz */ |
817 |
|
} |
818 |
|
} |
819 |
|
|
820 |
|
/* user clicked "edit..." button in relation list */ |
821 |
|
static void on_relation_edit(GtkWidget *but, relation_context_t *context) { |
822 |
|
relation_t *sel = get_selected_relation(context); |
823 |
|
if(!sel) return; |
824 |
|
|
825 |
|
printf("edit relation #%ld\n", sel->id); |
826 |
|
|
827 |
|
info_dialog(context->dialog, context->appdata, sel); |
828 |
|
} |
829 |
|
|
830 |
|
/* remove the selected relation */ |
831 |
|
static void on_relation_remove(GtkWidget *but, relation_context_t *context) { |
832 |
|
relation_t *sel = get_selected_relation(context); |
833 |
|
if(!sel) return; |
834 |
|
|
835 |
|
printf("remove relation #%ld\n", sel->id); |
836 |
|
|
837 |
|
gint members = osm_relation_members_num(sel); |
838 |
|
|
839 |
|
if(members) |
840 |
|
if(!yes_no_f(context->dialog, NULL, 0, 0, |
841 |
|
_("Delete non-empty relation?"), |
842 |
|
_("This relation still has %d members. " |
843 |
|
"Delete it anyway?"), members)) |
844 |
|
return; |
845 |
|
|
846 |
|
/* first remove selected row from list */ |
847 |
|
GtkTreeIter iter; |
848 |
|
GtkTreeSelection *selection = |
849 |
|
gtk_tree_view_get_selection(GTK_TREE_VIEW(context->view)); |
850 |
|
if(gtk_tree_selection_get_selected(selection, NULL, &iter)) |
851 |
|
gtk_list_store_remove(context->store, &iter); |
852 |
|
|
853 |
|
/* then really delete it */ |
854 |
|
osm_relation_delete(context->appdata->osm, sel, FALSE); |
855 |
|
|
856 |
|
relation_list_selected(context, NULL); |
857 |
|
} |
858 |
|
|
859 |
|
static GtkWidget *relation_list_widget(relation_context_t *context) { |
860 |
|
GtkWidget *vbox = gtk_vbox_new(FALSE,3); |
861 |
|
context->view = gtk_tree_view_new(); |
862 |
|
|
863 |
|
gtk_tree_selection_set_select_function( |
864 |
|
gtk_tree_view_get_selection(GTK_TREE_VIEW(context->view)), |
865 |
|
relation_list_selection_func, |
866 |
|
context, NULL); |
867 |
|
|
868 |
|
/* --- "id" column --- */ |
869 |
|
GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); |
870 |
|
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(context->view), |
871 |
|
-1, _("Id"), renderer, "text", RELATION_COL_ID, NULL); |
872 |
|
|
873 |
|
/* --- "Type" column --- */ |
874 |
|
renderer = gtk_cell_renderer_text_new(); |
875 |
|
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(context->view), |
876 |
|
-1, _("Type"), renderer, "text", RELATION_COL_TYPE, NULL); |
877 |
|
|
878 |
|
/* --- "Name" column --- */ |
879 |
|
renderer = gtk_cell_renderer_text_new(); |
880 |
|
g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL); |
881 |
|
GtkTreeViewColumn *column = |
882 |
|
gtk_tree_view_column_new_with_attributes(_("Name"), renderer, |
883 |
|
"text", RELATION_COL_NAME, NULL); |
884 |
|
gtk_tree_view_column_set_expand(column, TRUE); |
885 |
|
gtk_tree_view_insert_column(GTK_TREE_VIEW(context->view), column, -1); |
886 |
|
|
887 |
|
/* --- "members" column --- */ |
888 |
|
renderer = gtk_cell_renderer_text_new(); |
889 |
|
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(context->view), |
890 |
|
-1, _("Members"), renderer, "text", RELATION_COL_MEMBERS, NULL); |
891 |
|
|
892 |
|
/* build and fill the store */ |
893 |
|
context->store = gtk_list_store_new(RELATION_NUM_COLS, |
894 |
|
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, |
895 |
|
G_TYPE_POINTER); |
896 |
|
|
897 |
|
gtk_tree_view_set_model(GTK_TREE_VIEW(context->view), |
898 |
|
GTK_TREE_MODEL(context->store)); |
899 |
|
|
900 |
|
GtkTreeIter iter; |
901 |
|
relation_t *relation = context->appdata->osm->relation; |
902 |
|
while(relation) { |
903 |
|
char *id = g_strdup_printf("#%ld", relation->id); |
904 |
|
|
905 |
|
/* try to find something descriptive */ |
906 |
|
char *name = osm_tag_get_by_key(relation->tag, "name"); |
907 |
|
if(!name) name = osm_tag_get_by_key(relation->tag, "ref"); |
908 |
|
|
909 |
|
char *num = g_strdup_printf("%d", osm_relation_members_num(relation)); |
910 |
|
|
911 |
|
/* Append a row and fill in some data */ |
912 |
|
gtk_list_store_append(context->store, &iter); |
913 |
|
gtk_list_store_set(context->store, &iter, |
914 |
|
RELATION_COL_ID, id, |
915 |
|
RELATION_COL_TYPE, |
916 |
|
osm_tag_get_by_key(relation->tag, "type"), |
917 |
|
RELATION_COL_NAME, name, |
918 |
|
RELATION_COL_MEMBERS, num, |
919 |
|
RELATION_COL_DATA, relation, |
920 |
|
-1); |
921 |
|
|
922 |
|
g_free(id); |
923 |
|
g_free(num); |
924 |
|
relation = relation->next; |
925 |
|
} |
926 |
|
|
927 |
|
g_object_unref(context->store); |
928 |
|
|
929 |
|
/* put it into a scrolled window */ |
930 |
|
GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL); |
931 |
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), |
932 |
|
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); |
933 |
|
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_window), |
934 |
|
GTK_SHADOW_ETCHED_IN); |
935 |
|
gtk_container_add(GTK_CONTAINER(scrolled_window), context->view); |
936 |
|
|
937 |
|
gtk_box_pack_start_defaults(GTK_BOX(vbox), scrolled_window); |
938 |
|
|
939 |
|
/* ------- button box ------------ */ |
940 |
|
|
941 |
|
GtkWidget *hbox = gtk_hbox_new(TRUE,3); |
942 |
|
|
943 |
|
context->but_add = gtk_button_new_with_label(_("Add...")); |
944 |
|
gtk_box_pack_start_defaults(GTK_BOX(hbox), context->but_add); |
945 |
|
gtk_signal_connect(GTK_OBJECT(context->but_add), "clicked", |
946 |
|
GTK_SIGNAL_FUNC(on_relation_add), context); |
947 |
|
|
948 |
|
context->but_edit = gtk_button_new_with_label(_("Edit...")); |
949 |
|
gtk_widget_set_sensitive(context->but_edit, FALSE); |
950 |
|
gtk_box_pack_start_defaults(GTK_BOX(hbox), context->but_edit); |
951 |
|
gtk_signal_connect(GTK_OBJECT(context->but_edit), "clicked", |
952 |
|
GTK_SIGNAL_FUNC(on_relation_edit), context); |
953 |
|
|
954 |
|
context->but_members = gtk_button_new_with_label(_("Members...")); |
955 |
|
gtk_box_pack_start_defaults(GTK_BOX(hbox), context->but_members); |
956 |
|
gtk_signal_connect(GTK_OBJECT(context->but_members), "clicked", |
957 |
|
GTK_SIGNAL_FUNC(on_relation_members), context); |
958 |
|
|
959 |
|
context->but_remove = gtk_button_new_with_label(_("Remove")); |
960 |
|
gtk_widget_set_sensitive(context->but_remove, FALSE); |
961 |
|
gtk_box_pack_start_defaults(GTK_BOX(hbox), context->but_remove); |
962 |
|
gtk_signal_connect(GTK_OBJECT(context->but_remove), "clicked", |
963 |
|
GTK_SIGNAL_FUNC(on_relation_remove), context); |
964 |
|
|
965 |
|
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
966 |
|
|
967 |
|
relation_list_selected(context, NULL); |
968 |
|
|
969 |
|
return vbox; |
970 |
|
} |
971 |
|
|
972 |
|
/* a global view on all relations */ |
973 |
|
void relation_list(appdata_t *appdata) { |
974 |
|
relation_context_t *context = g_new0(relation_context_t, 1); |
975 |
|
context->appdata = appdata; |
976 |
|
|
977 |
|
printf("relation list\n"); |
978 |
|
|
979 |
|
context->dialog = |
980 |
|
gtk_dialog_new_with_buttons(_("All relations"), |
981 |
|
GTK_WINDOW(appdata->window), GTK_DIALOG_MODAL, |
982 |
|
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, |
983 |
|
NULL); |
984 |
|
|
985 |
|
gtk_dialog_set_default_response(GTK_DIALOG(context->dialog), |
986 |
|
GTK_RESPONSE_CLOSE); |
987 |
|
|
988 |
/* making the dialog a little wider makes it less "crowded" */ |
/* making the dialog a little wider makes it less "crowded" */ |
989 |
#ifdef USE_HILDON |
#ifdef USE_HILDON |
992 |
gtk_window_set_default_size(GTK_WINDOW(context->dialog), 400, 200); |
gtk_window_set_default_size(GTK_WINDOW(context->dialog), 400, 200); |
993 |
#endif |
#endif |
994 |
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(context->dialog)->vbox), |
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(context->dialog)->vbox), |
995 |
relation_list(context), TRUE, TRUE, 0); |
relation_list_widget(context), TRUE, TRUE, 0); |
996 |
|
|
997 |
/* ----------------------------------- */ |
/* ----------------------------------- */ |
998 |
|
|