313 |
|
|
314 |
typedef struct { |
typedef struct { |
315 |
project_t *project; |
project_t *project; |
316 |
GtkWidget *dialog, *view; |
GtkWidget *dialog, *list; |
|
GtkWidget *but_new, *but_edit, *but_remove; |
|
317 |
settings_t *settings; |
settings_t *settings; |
318 |
#ifdef USE_HILDON |
#ifdef USE_HILDON |
319 |
dbus_mm_pos_t *mmpos; |
dbus_mm_pos_t *mmpos; |
330 |
}; |
}; |
331 |
|
|
332 |
static void view_selected(select_context_t *context, project_t *project) { |
static void view_selected(select_context_t *context, project_t *project) { |
333 |
gtk_widget_set_sensitive(context->but_remove, project != NULL); |
list_button_enable(context->list, LIST_BUTTON_REMOVE, project != NULL); |
334 |
gtk_widget_set_sensitive(context->but_edit, project != NULL); |
list_button_enable(context->list, LIST_BUTTON_EDIT, project != NULL); |
335 |
|
|
336 |
/* check if the selected project also has a valid osm file */ |
/* check if the selected project also has a valid osm file */ |
337 |
gtk_dialog_set_response_sensitive(GTK_DIALOG(context->dialog), |
gtk_dialog_set_response_sensitive(GTK_DIALOG(context->dialog), |
358 |
} |
} |
359 |
|
|
360 |
/* get the currently selected project in the list, NULL if none */ |
/* get the currently selected project in the list, NULL if none */ |
361 |
static project_t *project_get_selected(GtkWidget *view) { |
static project_t *project_get_selected(GtkWidget *list) { |
362 |
project_t *project = NULL; |
project_t *project = NULL; |
363 |
GtkTreeModel *model; |
GtkTreeModel *model; |
364 |
GtkTreeIter iter; |
GtkTreeIter iter; |
365 |
|
|
366 |
GtkTreeSelection *selection = |
GtkTreeSelection *selection = list_get_selection(list); |
|
gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); |
|
367 |
g_assert(gtk_tree_selection_get_selected(selection, &model, &iter)); |
g_assert(gtk_tree_selection_get_selected(selection, &model, &iter)); |
368 |
gtk_tree_model_get(model, &iter, PROJECT_COL_DATA, &project, -1); |
gtk_tree_model_get(model, &iter, PROJECT_COL_DATA, &project, -1); |
369 |
|
|
433 |
|
|
434 |
/* remove from view */ |
/* remove from view */ |
435 |
GtkTreeIter iter; |
GtkTreeIter iter; |
436 |
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(context->view)); |
GtkTreeModel *model = list_get_model(context->list); |
437 |
gboolean deleted = FALSE; |
gboolean deleted = FALSE; |
438 |
if(gtk_tree_model_get_iter_first(model, &iter)) { |
if(gtk_tree_model_get_iter_first(model, &iter)) { |
439 |
do { |
do { |
552 |
*project = project_new(context); |
*project = project_new(context); |
553 |
if(*project) { |
if(*project) { |
554 |
|
|
555 |
GtkTreeModel *model = |
GtkTreeModel *model = list_get_model(context->list); |
|
gtk_tree_view_get_model(GTK_TREE_VIEW(context->view)); |
|
556 |
|
|
557 |
GtkTreeIter iter; |
GtkTreeIter iter; |
558 |
gchar *status_stock_id = NULL; |
gchar *status_stock_id = NULL; |
565 |
PROJECT_COL_DATA, *project, |
PROJECT_COL_DATA, *project, |
566 |
-1); |
-1); |
567 |
|
|
568 |
GtkTreeSelection *selection = |
GtkTreeSelection *selection = list_get_selection(context->list); |
|
gtk_tree_view_get_selection(GTK_TREE_VIEW(context->view)); |
|
569 |
gtk_tree_selection_select_iter(selection, &iter); |
gtk_tree_selection_select_iter(selection, &iter); |
570 |
} |
} |
571 |
} |
} |
572 |
|
|
573 |
static void on_project_delete(GtkButton *button, gpointer data) { |
static void on_project_delete(GtkButton *button, gpointer data) { |
574 |
select_context_t *context = (select_context_t*)data; |
select_context_t *context = (select_context_t*)data; |
575 |
project_t *project = project_get_selected(context->view); |
project_t *project = project_get_selected(context->list); |
576 |
|
|
577 |
char *str = g_strdup_printf(_("Do you really want to delete the " |
char *str = g_strdup_printf(_("Do you really want to delete the " |
578 |
"project \"%s\"?"), project->name); |
"project \"%s\"?"), project->name); |
598 |
|
|
599 |
static void on_project_edit(GtkButton *button, gpointer data) { |
static void on_project_edit(GtkButton *button, gpointer data) { |
600 |
select_context_t *context = (select_context_t*)data; |
select_context_t *context = (select_context_t*)data; |
601 |
project_t *project = project_get_selected(context->view); |
project_t *project = project_get_selected(context->list); |
602 |
g_assert(project); |
g_assert(project); |
603 |
#ifdef USE_HILDON |
#ifdef USE_HILDON |
604 |
if(project_edit(context->dialog, project, |
if(project_edit(context->dialog, project, |
611 |
GtkTreeIter iter; |
GtkTreeIter iter; |
612 |
|
|
613 |
/* description etc. may have changed, so update list */ |
/* description etc. may have changed, so update list */ |
614 |
GtkTreeSelection *selection = |
GtkTreeSelection *selection = list_get_selection(context->list); |
|
gtk_tree_view_get_selection(GTK_TREE_VIEW(context->view)); |
|
615 |
g_assert(gtk_tree_selection_get_selected(selection, &model, &iter)); |
g_assert(gtk_tree_selection_get_selected(selection, &model, &iter)); |
616 |
|
|
617 |
// gtk_tree_model_get(model, &iter, PROJECT_COL_DATA, &project, -1); |
// gtk_tree_model_get(model, &iter, PROJECT_COL_DATA, &project, -1); |
646 |
} |
} |
647 |
|
|
648 |
static GtkWidget *project_list_widget(select_context_t *context) { |
static GtkWidget *project_list_widget(select_context_t *context) { |
649 |
GtkWidget *vbox = gtk_vbox_new(FALSE,3); |
context->list = list_new(); |
|
context->view = gtk_tree_view_new(); |
|
650 |
|
|
651 |
gtk_tree_selection_set_select_function( |
list_set_selection_function(context->list, view_selection_func, context); |
652 |
gtk_tree_view_get_selection(GTK_TREE_VIEW(context->view)), |
|
653 |
view_selection_func, |
list_set_columns(context->list, |
654 |
context, NULL); |
_("Name"), PROJECT_COL_NAME, 0, |
655 |
|
_("State"), PROJECT_COL_STATUS, LIST_FLAG_STOCK_ICON, |
656 |
/* --- "Name" column --- */ |
_("Description"), PROJECT_COL_DESCRIPTION, LIST_FLAG_EXPAND, |
657 |
GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); |
NULL); |
658 |
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(context->view), |
|
|
-1, _("Name"), renderer, "text", PROJECT_COL_NAME, NULL); |
|
|
|
|
|
/* --- State flags column --- */ |
|
|
GtkCellRenderer *pixbuf_renderer = gtk_cell_renderer_pixbuf_new(); |
|
|
GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes(_("State"), |
|
|
pixbuf_renderer, "stock_id", PROJECT_COL_STATUS, |
|
|
NULL); |
|
|
//gtk_tree_view_column_pack_start(column, renderer2, FALSE); |
|
|
//gtk_tree_view_column_add_attribute(column, renderer2, "stock_id", PROJECT_COL_FLAG_DIFF_PRESENT); |
|
|
gtk_tree_view_column_set_expand(column, FALSE); |
|
|
gtk_tree_view_insert_column(GTK_TREE_VIEW(context->view), column, -1); |
|
|
|
|
|
/* --- "Description" column --- */ |
|
|
renderer = gtk_cell_renderer_text_new(); |
|
|
g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL ); |
|
|
column = gtk_tree_view_column_new_with_attributes( |
|
|
_("Description"), renderer, "text", PROJECT_COL_DESCRIPTION, NULL); |
|
|
gtk_tree_view_column_set_expand(column, TRUE); |
|
|
gtk_tree_view_insert_column(GTK_TREE_VIEW(context->view), column, -1); |
|
659 |
|
|
660 |
/* build the store */ |
/* build the store */ |
661 |
GtkListStore *store = gtk_list_store_new(PROJECT_NUM_COLS, |
GtkListStore *store = gtk_list_store_new(PROJECT_NUM_COLS, |
680 |
project = project->next; |
project = project->next; |
681 |
} |
} |
682 |
|
|
683 |
gtk_tree_view_set_model(GTK_TREE_VIEW(context->view), GTK_TREE_MODEL(store)); |
list_set_store(context->list, store); |
684 |
g_object_unref(store); |
g_object_unref(store); |
685 |
|
|
686 |
/* put it into a scrolled window */ |
list_set_static_buttons(context->list, G_CALLBACK(on_project_new), |
687 |
GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL); |
G_CALLBACK(on_project_edit), G_CALLBACK(on_project_delete), context); |
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), |
|
|
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); |
|
|
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_window), |
|
|
GTK_SHADOW_ETCHED_IN); |
|
|
gtk_container_add(GTK_CONTAINER(scrolled_window), context->view); |
|
|
gtk_box_pack_start_defaults(GTK_BOX(vbox), scrolled_window); |
|
|
|
|
|
/* ------- button box ------------ */ |
|
|
|
|
|
GtkWidget *hbox = gtk_hbox_new(TRUE,3); |
|
|
context->but_new = gtk_button_new_with_label(_("New...")); |
|
|
gtk_box_pack_start_defaults(GTK_BOX(hbox), context->but_new); |
|
|
gtk_signal_connect(GTK_OBJECT(context->but_new), "clicked", |
|
|
GTK_SIGNAL_FUNC(on_project_new), context); |
|
|
|
|
|
context->but_edit = gtk_button_new_with_label(_("Edit...")); |
|
|
gtk_widget_set_sensitive(context->but_edit, FALSE); |
|
|
gtk_box_pack_start_defaults(GTK_BOX(hbox), context->but_edit); |
|
|
gtk_signal_connect(GTK_OBJECT(context->but_edit), "clicked", |
|
|
GTK_SIGNAL_FUNC(on_project_edit), context); |
|
|
|
|
|
context->but_remove = gtk_button_new_with_label(_("Remove")); |
|
|
gtk_widget_set_sensitive(context->but_remove, FALSE); |
|
|
gtk_box_pack_start_defaults(GTK_BOX(hbox), context->but_remove); |
|
|
gtk_signal_connect(GTK_OBJECT(context->but_remove), "clicked", |
|
|
GTK_SIGNAL_FUNC(on_project_delete), context); |
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
|
688 |
|
|
689 |
return vbox; |
return context->list; |
690 |
} |
} |
691 |
|
|
692 |
char *project_select(appdata_t *appdata) { |
char *project_select(appdata_t *appdata) { |
722 |
|
|
723 |
gtk_widget_show_all(context->dialog); |
gtk_widget_show_all(context->dialog); |
724 |
if(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(context->dialog))) |
if(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(context->dialog))) |
725 |
name = g_strdup(project_get_selected(context->view)->name); |
name = g_strdup(project_get_selected(context->list)->name); |
726 |
|
|
727 |
gtk_widget_destroy(context->dialog); |
gtk_widget_destroy(context->dialog); |
728 |
|
|