/** * query_favorite_selector_new * * Returns: a new #GtkWidget */ GtkWidget * query_favorite_selector_new (TConnection *tcnc) { QueryFavoriteSelector *tsel; GdaTreeManager *manager; g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL); tsel = QUERY_FAVORITE_SELECTOR (g_object_new (QUERY_FAVORITE_SELECTOR_TYPE, NULL)); tsel->priv->tcnc = g_object_ref (tcnc); g_signal_connect (t_connection_get_favorites (tsel->priv->tcnc), "favorites-changed", G_CALLBACK (favorites_changed_cb), tsel); /* create tree managers */ tsel->priv->tree = gda_tree_new (); manager = mgr_favorites_new (tcnc, T_FAVORITES_QUERIES, ORDER_KEY_QUERIES); gda_tree_add_manager (tsel->priv->tree, manager); g_object_unref (manager); /* update the tree's contents */ if (! gda_tree_update_all (tsel->priv->tree, NULL)) { if (tsel->priv->idle_update_favorites == 0) tsel->priv->idle_update_favorites = g_idle_add ((GSourceFunc) idle_update_favorites, tsel); } /* header */ GtkWidget *label; gchar *str; str = g_strdup_printf ("<b>%s</b>", _("Favorites")); label = gdaui_bar_new (str); g_free (str); gdaui_bar_set_icon_from_resource (GDAUI_BAR (label), "/images/gda-browser-bookmark.png"); gtk_box_pack_start (GTK_BOX (tsel), label, FALSE, FALSE, 0); gtk_widget_show (label); /* tree model */ GtkTreeModel *model; GtkWidget *treeview; GtkCellRenderer *renderer; GtkTreeViewColumn *column; model = gdaui_tree_store_new (tsel->priv->tree, 7, G_TYPE_INT, MGR_FAVORITES_POSITION_ATT_NAME, G_TYPE_OBJECT, "icon", G_TYPE_STRING, MGR_FAVORITES_CONTENTS_ATT_NAME, G_TYPE_UINT, MGR_FAVORITES_TYPE_ATT_NAME, G_TYPE_INT, MGR_FAVORITES_ID_ATT_NAME, G_TYPE_STRING, MGR_FAVORITES_NAME_ATT_NAME, G_TYPE_STRING, "summary"); treeview = ui_make_tree_view (model); tsel->priv->treeview = treeview; g_object_unref (model); /* icon */ column = gtk_tree_view_column_new (); renderer = gtk_cell_renderer_pixbuf_new (); gtk_tree_view_column_pack_start (column, renderer, FALSE); gtk_tree_view_column_add_attribute (column, renderer, "pixbuf", COLUMN_ICON); g_object_set ((GObject*) renderer, "yalign", 0., NULL); /* text */ renderer = gtk_cell_renderer_text_new (); gtk_tree_view_column_pack_start (column, renderer, TRUE); gtk_tree_view_column_set_cell_data_func (column, renderer, (GtkTreeCellDataFunc) cell_data_func, NULL, NULL); gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column); gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED); /* scrolled window packing */ GtkWidget *sw; sw = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_ETCHED_IN); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); gtk_container_add (GTK_CONTAINER (sw), treeview); gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE); gtk_box_pack_start (GTK_BOX (tsel), sw, TRUE, TRUE, 0); gtk_widget_show_all (sw); g_signal_connect (G_OBJECT (treeview), "row-activated", G_CALLBACK (selection_changed_cb), tsel); g_signal_connect (G_OBJECT (treeview), "key-press-event", G_CALLBACK (key_press_event_cb), tsel); g_signal_connect (G_OBJECT (treeview), "popup-menu", G_CALLBACK (popup_menu_cb), tsel); g_signal_connect (G_OBJECT (treeview), "button-press-event", G_CALLBACK (button_press_event_cb), tsel); /* DnD */ gtk_tree_view_enable_model_drag_dest (GTK_TREE_VIEW (treeview), dbo_table, G_N_ELEMENTS (dbo_table), GDK_ACTION_COPY); gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (treeview), GDK_BUTTON1_MASK, dbo_table, G_N_ELEMENTS (dbo_table), GDK_ACTION_COPY | GDK_ACTION_MOVE); g_signal_connect (model, "drag-drop", G_CALLBACK (tree_store_drag_drop_cb), tsel); g_signal_connect (model, "drag-can-drag", G_CALLBACK (tree_store_drag_can_drag_cb), tsel); g_signal_connect (model, "drag-get", G_CALLBACK (tree_store_drag_get_cb), tsel); return (GtkWidget*) tsel; }
/** * table_preferences_new * * Returns: a new #GtkWidget */ GtkWidget * table_preferences_new (TableInfo *tinfo) { TablePreferences *tpref; g_return_val_if_fail (IS_TABLE_INFO (tinfo), NULL); tpref = TABLE_PREFERENCES (g_object_new (TABLE_PREFERENCES_TYPE, NULL)); tpref->priv->tinfo = tinfo; tpref->priv->tcnc = g_object_ref (table_info_get_connection (tinfo)); g_signal_connect (tpref->priv->tcnc, "meta-changed", G_CALLBACK (meta_changed_cb), tpref); g_signal_connect (tpref->priv->tcnc, "table-column-pref-changed", G_CALLBACK (table_column_pref_changed_cb), tpref); GtkWidget *grid; grid = gtk_grid_new (); gtk_box_pack_start (GTK_BOX (tpref), grid, TRUE, TRUE, 0); gtk_grid_set_row_spacing (GTK_GRID (grid), 6); gtk_grid_set_column_spacing (GTK_GRID (grid), 6); gtk_container_set_border_width (GTK_CONTAINER (grid), 6); /* left column */ GtkWidget *label; gchar *str; label = gtk_label_new (""); str = g_strdup_printf ("<b>%s:</b>", _("Table's fields")); gtk_label_set_markup (GTK_LABEL (label), str); g_free (str); gtk_widget_set_halign (label, GTK_ALIGN_START); gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1); GtkWidget *sw, *treeview; sw = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_ETCHED_IN); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); gtk_grid_attach (GTK_GRID (grid), sw, 0, 1, 1, 1); tpref->priv->columns_store = gtk_list_store_new (NUM_COLUMNS, G_TYPE_POINTER, G_TYPE_GTYPE, G_TYPE_STRING); treeview = ui_make_tree_view (GTK_TREE_MODEL (tpref->priv->columns_store)); tpref->priv->columns_treeview = GTK_TREE_VIEW (treeview); gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE); gtk_container_add (GTK_CONTAINER (sw), treeview); /* treeview's columns */ GtkTreeViewColumn *col; GtkCellRenderer *cell; cell = gtk_cell_renderer_text_new (); col = gtk_tree_view_column_new (); gtk_tree_view_column_pack_start (col, cell, TRUE); gtk_tree_view_column_set_cell_data_func (col, cell, (GtkTreeCellDataFunc) cell_name_data_func, NULL, NULL); gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), col); /* selection handling */ GtkTreeSelection *select; select = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); gtk_tree_selection_set_mode (select, GTK_SELECTION_SINGLE); g_signal_connect (G_OBJECT (select), "changed", G_CALLBACK (selection_changed_cb), tpref); /* right column */ label = gtk_label_new (""); str = g_strdup_printf ("<b>%s:</b>", _("Field's display preferences")); gtk_label_set_markup (GTK_LABEL (label), str); g_free (str); gtk_widget_set_halign (label, GTK_ALIGN_START); gtk_grid_attach (GTK_GRID (grid), label, 1, 0, 1, 1); tpref->priv->field_props = create_column_properties (tpref); gtk_grid_attach (GTK_GRID (grid), tpref->priv->field_props, 1, 1, 1, 1); /* show all */ gtk_widget_show_all (grid); /* * initial update */ GdaMetaStruct *mstruct; mstruct = t_connection_get_meta_struct (tpref->priv->tcnc); if (mstruct) meta_changed_cb (tpref->priv->tcnc, mstruct, tpref); selection_changed_cb (select, tpref); g_signal_connect (tpref->priv->columns_store, "row-changed", G_CALLBACK (columns_model_row_changed_cb), tpref); return (GtkWidget*) tpref; }