static void update_completion( GtkEntry* entry, GtkEntryCompletion* completion ) { char* new_dir, *fn; const char* old_dir; GtkListStore* list; const char *sep; sep = strrchr( gtk_entry_get_text(entry), '/' ); if( sep ) fn = (char*)sep + 1; else fn = (char*)gtk_entry_get_text(entry); g_object_set_data_full( G_OBJECT(completion), "fn", g_strdup(fn), (GDestroyNotify)g_free ); new_dir = path_entry_active_path(); old_dir = (const char*)g_object_get_data( (GObject*)completion, "cwd" ); if( old_dir && new_dir && 0 == g_ascii_strcasecmp( old_dir, new_dir ) ) { g_free( new_dir ); return; } g_object_set_data_full( (GObject*)completion, "cwd", new_dir, g_free ); list = (GtkListStore*)gtk_entry_completion_get_model( completion ); gtk_list_store_clear( list ); if( new_dir ) { GDir* dir; if( (dir = g_dir_open( new_dir, 0, NULL )) ) { const char* name; while( (name = g_dir_read_name( dir )) ) { char* full_path = g_build_filename( new_dir, name, NULL ); // printf("%d fn=%s\n",xxx++, full_path); if( g_file_test( full_path, G_FILE_TEST_IS_DIR ) ) { GtkTreeIter it; char* disp_name = g_filename_display_basename( full_path ); gtk_list_store_append( list, &it ); gtk_list_store_set( list, &it, COL_NAME, disp_name, COL_PATH, full_path, -1 ); g_free( disp_name ); } g_free( full_path ); } g_dir_close( dir ); gtk_entry_completion_set_match_func( completion, match_func, new_dir, NULL ); } else gtk_entry_completion_set_match_func( completion, NULL, NULL, NULL ); } }
/* * Create completion in entry */ static void dialog_entry_completion_new(const GtkWidget *container, GtkEntryCompletionMatchFunc completion_func, gpointer completion_data) { GtkListStore *list_store = NULL; GtkEntryCompletion *completion = NULL; /* Create a tree model and use it as the completion model */ list_store = gtk_list_store_new(1, G_TYPE_STRING); /* Create the completion object */ completion = gtk_entry_completion_new(); gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(list_store)); gtk_entry_completion_set_text_column(completion, 0); gtk_entry_completion_set_minimum_key_length(completion, AV_WIDGET_ENTRY_COMPLETION_KEY_LEN_MIN); gtk_entry_completion_set_popup_completion(completion, FALSE); gtk_entry_completion_set_inline_completion(completion, TRUE); gtk_entry_completion_set_match_func(completion, completion_func, completion_data, NULL); /* Assign the completion to the entry */ gtk_entry_set_completion(GTK_ENTRY(container), completion); g_object_unref (completion); }
/* exported interface documented in completion.h */ GtkEntryCompletion *nsgtk_url_entry_completion_new(struct nsgtk_scaffolding *gs) { GtkEntryCompletion *completion; completion = gtk_entry_completion_new(); gtk_entry_completion_set_match_func(completion, nsgtk_completion_match, NULL, NULL); gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(nsgtk_completion_list)); gtk_entry_completion_set_text_column(completion, 0); gtk_entry_completion_set_minimum_key_length(completion, 1); /* enable popup for completion */ gtk_entry_completion_set_popup_completion(completion, TRUE); /* when selected callback */ g_signal_connect(G_OBJECT(completion), "match-selected", G_CALLBACK(nsgtk_completion_match_select), gs); g_object_set(G_OBJECT(completion), "popup-set-width", TRUE, "popup-single-match", TRUE, NULL); return completion; }
static void ag_chart_edit_init(AgChartEdit *chart_edit) { GET_PRIV(chart_edit); gtk_widget_init_template(GTK_WIDGET(chart_edit)); g_object_set( priv->year_adjust, "lower", (gdouble)G_MININT, "upper", (gdouble)G_MAXINT, NULL ); gtk_entry_completion_set_model(priv->country_comp, country_list); gtk_entry_completion_set_text_column(priv->country_comp, AG_COUNTRY_NAME); gtk_entry_set_completion(GTK_ENTRY(priv->country), priv->country_comp); gtk_entry_completion_set_model(priv->city_comp, city_list); gtk_entry_completion_set_text_column(priv->city_comp, AG_CITY_NAME); gtk_entry_completion_set_minimum_key_length(priv->city_comp, 3); gtk_entry_set_completion(GTK_ENTRY(priv->city), priv->city_comp); gtk_entry_completion_set_match_func( priv->city_comp, (GtkEntryCompletionMatchFunc)ag_chart_edit_city_matches, chart_edit, NULL ); }
static void _glade_adaptor_chooser_widget_constructed (GObject *object) { _GladeAdaptorChooserWidget *chooser = GLADE_ADAPTOR_CHOOSER_WIDGET (object); _GladeAdaptorChooserWidgetPrivate *priv = GET_PRIVATE (chooser); /* Set cell data function: this save us from alocating name and icon name for each adaptor. */ gtk_tree_view_column_set_cell_data_func (priv->column_icon, priv->icon_cell, adaptor_icon_cell_data_func, NULL, NULL); gtk_tree_view_column_set_cell_data_func (priv->column_adaptor, priv->adaptor_cell, adaptor_text_cell_data_func, NULL, NULL); /* Set tree model filter function */ gtk_tree_model_filter_set_visible_func (priv->treemodelfilter, treemodelfilter_visible_func, chooser, NULL); /* Set completion match function */ gtk_entry_completion_set_match_func (priv->entrycompletion, entrycompletion_match_func, chooser, NULL); /* Enable Drag & Drop */ gtk_tree_view_enable_model_drag_source (priv->treeview, GDK_BUTTON1_MASK, _glade_dnd_get_target (), 1, 0); g_signal_connect_after (priv->treeview, "drag-begin", G_CALLBACK (glade_adaptor_chooser_widget_drag_begin), NULL); g_signal_connect (priv->treeview, "drag-data-get", G_CALLBACK (glade_adaptor_chooser_widget_drag_data_get), NULL); }
static void fm_path_entry_init(FmPathEntry *entry) { FmPathEntryPrivate *priv = FM_PATH_ENTRY_GET_PRIVATE(entry); GtkEntryCompletion* completion = gtk_entry_completion_new(); GtkCellRenderer* render; priv->model = NULL; priv->completion_model = NULL; priv->completion_len = 0; priv->in_change = FALSE; priv->completion = completion; priv->highlight_completion_match = TRUE; priv->common_suffix_append_idle_id = -1; priv->common_suffix[0] = 0; gtk_entry_completion_set_minimum_key_length(completion, 1); gtk_entry_completion_set_match_func(completion, fm_path_entry_match_func, NULL, NULL); g_signal_connect(G_OBJECT(completion), "match-selected", G_CALLBACK(fm_path_entry_match_selected), (gpointer)NULL); g_object_set(completion, "text-column", COL_FILE_NAME, NULL); render = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start( (GtkCellLayout*)completion, render, TRUE ); gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(completion), render, fm_path_entry_completion_render_func, entry, NULL); gtk_entry_completion_set_inline_completion(completion, TRUE); gtk_entry_completion_set_popup_set_width(completion, TRUE); g_signal_connect(G_OBJECT(entry), "key-press-event", G_CALLBACK(fm_path_entry_key_press), NULL); gtk_entry_set_completion(GTK_ENTRY(entry), completion); }
static VALUE rg_set_match_func(VALUE self) { VALUE func = rb_block_proc(); G_RELATIVE(self, func); gtk_entry_completion_set_match_func(_SELF(self), (GtkEntryCompletionMatchFunc)entryc_match_func, (gpointer)func, NULL); return self; }
static void hotssh_tab_init (HotSshTab *self) { HotSshTabPrivate *priv = hotssh_tab_get_instance_private (self); priv->settings = g_settings_new ("org.gnome.hotssh"); gtk_widget_init_template (GTK_WIDGET (self)); gtk_notebook_set_show_tabs ((GtkNotebook*)self, FALSE); g_signal_connect (priv->create_and_connect_button, "clicked", G_CALLBACK (on_create_and_connect), self); g_signal_connect (priv->add_new_connection_button, "clicked", G_CALLBACK (on_add_new_connection), self); g_signal_connect (priv->connect_cancel_button, "clicked", G_CALLBACK (on_connect_cancel), self); g_signal_connect (priv->error_disconnect, "clicked", G_CALLBACK (on_connect_cancel), self); g_signal_connect (priv->auth_cancel_button, "clicked", G_CALLBACK (on_connect_cancel), self); g_signal_connect (priv->approve_hostkey_button, "clicked", G_CALLBACK (on_approve_hostkey_clicked), self); g_signal_connect (priv->disapprove_hostkey_button, "clicked", G_CALLBACK (on_connect_cancel), self); g_signal_connect_swapped (priv->password_entry, "activate", G_CALLBACK (submit_password), self); g_signal_connect_swapped (priv->password_submit, "clicked", G_CALLBACK (submit_password), self); g_signal_connect (priv->connections_treeview, "row-activated", G_CALLBACK (on_connection_row_activated), self); priv->password_interaction = hotssh_password_interaction_new ((GtkEntry*)priv->password_entry); priv->terminal = vte_terminal_new (); g_signal_connect (priv->terminal, "realize", G_CALLBACK (on_vte_realize), self); vte_terminal_set_audible_bell ((VteTerminal*)priv->terminal, FALSE); /* Audible bell is a terrible idea */ g_signal_connect ((GObject*)priv->terminal, "size-allocate", G_CALLBACK (on_terminal_size_allocate), self); g_signal_connect ((GObject*)priv->terminal, "commit", G_CALLBACK (on_terminal_commit), self); gtk_box_pack_start ((GtkBox*)priv->terminal_box, priv->terminal, TRUE, TRUE, 0); gtk_range_set_adjustment ((GtkRange*)priv->terminal_vscrollbar, gtk_scrollable_get_vadjustment ((GtkScrollable*)priv->terminal)); gtk_widget_show_all (priv->terminal_box); g_queue_init (&priv->write_queue); { gs_unref_object HotSshHostDB *hostdb = hotssh_hostdb_get_instance (); gs_unref_object GtkTreeModel *hostdb_model = hotssh_hostdb_get_model (hostdb); priv->host_completion = gtk_entry_completion_new (); gtk_entry_completion_set_match_func (priv->host_completion, host_entry_match, self, NULL); gtk_entry_completion_set_model (priv->host_completion, hostdb_model); gtk_entry_completion_set_text_column (priv->host_completion, 0); gtk_entry_completion_set_inline_completion (priv->host_completion, TRUE); gtk_entry_set_completion ((GtkEntry*)priv->host_entry, priv->host_completion); } }
void completion_add(struct tab *t) { /* enable completion for tab */ t->completion = gtk_entry_completion_new(); gtk_entry_completion_set_text_column(t->completion, 0); gtk_entry_set_completion(GTK_ENTRY(t->uri_entry), t->completion); gtk_entry_completion_set_model(t->completion, GTK_TREE_MODEL(completion_model)); gtk_entry_completion_set_match_func(t->completion, completion_match, NULL, NULL); gtk_entry_completion_set_minimum_key_length(t->completion, 1); gtk_entry_completion_set_inline_selection(t->completion, TRUE); g_signal_connect(G_OBJECT (t->completion), "match-selected", G_CALLBACK(completion_select_cb), t); g_signal_connect(G_OBJECT (t->completion), "cursor-on-match", G_CALLBACK(completion_hover_cb), t); }
static void fm_path_entry_init(FmPathEntry *entry) { FmPathEntryPrivate *priv = FM_PATH_ENTRY_GET_PRIVATE(entry); GtkEntryCompletion* completion = gtk_entry_completion_new(); GtkCellRenderer* render; priv->model = fm_path_entry_model_new(entry); priv->completion = completion; priv->cancellable = g_cancellable_new(); priv->highlight_completion_match = TRUE; gtk_entry_completion_set_minimum_key_length(completion, 1); gtk_entry_completion_set_match_func(completion, fm_path_entry_match_func, NULL, NULL); g_object_set(completion, "text_column", COL_FULL_PATH, NULL); gtk_entry_completion_set_model(completion, priv->model); render = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start( (GtkCellLayout*)completion, render, TRUE ); gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(completion), render, fm_path_entry_completion_render_func, entry, NULL); /* NOTE: this is to avoid a bug of gtk+. * The inline selection provided by GtkEntry is buggy. * If we change the content of the entry, it still stores * the old prefix sometimes so things don't work as expected. * So, unfortunately, we're not able to use this nice feature. * * Please see gtk_entry_completion_key_press() of gtk/gtkentry.c * and look for completion->priv->completion_prefix. */ gtk_entry_completion_set_inline_selection(completion, FALSE); gtk_entry_completion_set_inline_completion(completion, TRUE); gtk_entry_completion_set_popup_set_width(completion, TRUE); /* gtk_entry_completion_set_popup_single_match(completion, FALSE); */ /* connect to these signals rather than overriding default handlers since * we want to invoke our handlers before the default ones provided by Gtk. */ g_signal_connect(entry, "key-press-event", G_CALLBACK(fm_path_entry_key_press), NULL); g_signal_connect(entry, "activate", G_CALLBACK(fm_path_entry_on_activate), NULL); g_signal_connect(entry, "populate-popup", G_CALLBACK(fm_path_entry_populate_popup), NULL); }
/** * This function initializes entry with an autocomplete table * specified by compl_list. To set the default darktable variables, * use dt_gtkentry_get_default_path_compl_list(). * * @param[in] entry GtkEntry * @param[in] compl_list A {NULL,NULL} terminated array containing * {variable,description} for each available * completion text. */ void dt_gtkentry_setup_completion(GtkEntry *entry, const dt_gtkentry_completion_spec *compl_list) { GtkEntryCompletion *completion = gtk_entry_completion_new(); GtkListStore *model = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); GtkTreeIter iter; gtk_entry_completion_set_text_column(completion, COMPL_DESCRIPTION); gtk_entry_set_completion(entry, completion); g_signal_connect(G_OBJECT(completion), "match-selected", G_CALLBACK(on_match_select), NULL); /* Populate the completion database. */ for(const dt_gtkentry_completion_spec *l = compl_list; l && l->varname; l++) { gtk_list_store_append(model, &iter); gtk_list_store_set(model, &iter, COMPL_VARNAME, l->varname, COMPL_DESCRIPTION, _(l->description), -1); } gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(model)); gtk_entry_completion_set_match_func(completion, on_match_func, NULL, NULL); g_object_unref(model); }
int clip_GTK_ENTRYCOMPLETIONSETMATCHFUNC(ClipMachine * ClipMachineMemory) { C_object *ccompletion = _fetch_co_arg(ClipMachineMemory); ClipVar *func = _clip_spar(ClipMachineMemory, 2); C_var *c = 0; CHECKCOBJ(ccompletion, GTK_IS_ENTRY_COMPLETION(ccompletion->object)); CHECKARG2(2, PCODE_type_of_ClipVarType, CCODE_type_of_ClipVarType); c->ClipMachineMemory = ClipMachineMemory; c->co = ccompletion; _clip_mclone(ClipMachineMemory, &c->cfunc, func); gtk_entry_completion_set_match_func(GTK_ENTRY_COMPLETION (ccompletion->object), (GtkEntryCompletionMatchFunc) _match_func, c, NULL); return 0; err: return 1; }
static gboolean _lib_tagging_tag_show(GtkAccelGroup *accel_group, GObject *acceleratable, guint keyval, GdkModifierType modifier, dt_lib_module_t *self) { int mouse_over_id = -1; int zoom = dt_conf_get_int("plugins/lighttable/images_in_row"); // the order is: // if(zoom == 1) => currently shown image // else if(selection not empty) => selected images // else if(cursor over image) => hovered image // else => return if(zoom == 1 || dt_collection_get_selected_count(darktable.collection) == 0) { mouse_over_id = dt_control_get_mouse_over_id(); if(mouse_over_id < 0) return TRUE; } dt_lib_tagging_t *d = (dt_lib_tagging_t *)self->data; d->floating_tag_imgid = mouse_over_id; gint x, y; gint px, py, w, h; GtkWidget *window = dt_ui_main_window(darktable.gui->ui); GtkWidget *center = dt_ui_center(darktable.gui->ui); gdk_window_get_origin(gtk_widget_get_window(center), &px, &py); w = gdk_window_get_width(gtk_widget_get_window(center)); h = gdk_window_get_height(gtk_widget_get_window(center)); x = px + 0.5 * (w - FLOATING_ENTRY_WIDTH); y = py + h - 50; /* put the floating box at the mouse pointer */ // gint pointerx, pointery; // GdkDevice *device = // gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gtk_widget_get_display(widget))); // gdk_window_get_device_position (gtk_widget_get_window (widget), device, &pointerx, &pointery, NULL); // x = px + pointerx + 1; // y = py + pointery + 1; d->floating_tag_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); /* stackoverflow.com/questions/1925568/how-to-give-keyboard-focus-to-a-pop-up-gtk-window */ gtk_widget_set_can_focus(d->floating_tag_window, TRUE); gtk_window_set_decorated(GTK_WINDOW(d->floating_tag_window), FALSE); gtk_window_set_type_hint(GTK_WINDOW(d->floating_tag_window), GDK_WINDOW_TYPE_HINT_POPUP_MENU); gtk_window_set_transient_for(GTK_WINDOW(d->floating_tag_window), GTK_WINDOW(window)); gtk_widget_set_opacity(d->floating_tag_window, 0.8); gtk_window_move(GTK_WINDOW(d->floating_tag_window), x, y); GtkWidget *entry = gtk_entry_new(); gtk_widget_set_size_request(entry, FLOATING_ENTRY_WIDTH, -1); gtk_widget_add_events(entry, GDK_FOCUS_CHANGE_MASK); GtkEntryCompletion *completion = gtk_entry_completion_new(); gtk_entry_completion_set_model(completion, gtk_tree_view_get_model(GTK_TREE_VIEW(d->related))); gtk_entry_completion_set_text_column(completion, 0); gtk_entry_completion_set_inline_completion(completion, TRUE); gtk_entry_completion_set_popup_set_width(completion, FALSE); gtk_entry_completion_set_match_func(completion, _completion_match_func, NULL, NULL); gtk_entry_set_completion(GTK_ENTRY(entry), completion); gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1); gtk_container_add(GTK_CONTAINER(d->floating_tag_window), entry); g_signal_connect(entry, "focus-out-event", G_CALLBACK(_lib_tagging_tag_destroy), d->floating_tag_window); g_signal_connect(entry, "key-press-event", G_CALLBACK(_lib_tagging_tag_key_press), self); gtk_widget_show_all(d->floating_tag_window); gtk_widget_grab_focus(entry); gtk_window_present(GTK_WINDOW(d->floating_tag_window)); return TRUE; }
GtkWidget * entry_create_widget (GtkWidget * dlg) { GtkWidget *c, *l = NULL, *w = NULL; #if !GTK_CHECK_VERSION(3,0,0) w = gtk_hbox_new (FALSE, 5); #else w = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5); #endif if (options.entry_data.entry_label) { l = gtk_label_new (NULL); if (options.data.no_markup) gtk_label_set_text_with_mnemonic (GTK_LABEL (l), options.entry_data.entry_label); else gtk_label_set_markup_with_mnemonic (GTK_LABEL (l), options.entry_data.entry_label); gtk_widget_set_name (l, "yad-entry-label"); gtk_box_pack_start (GTK_BOX (w), l, FALSE, FALSE, 1); } if (options.entry_data.numeric) { gdouble min, max, step, val; guint prec; min = 0.0; max = 65535.0; step = 1.0; prec = 0; val = 0.0; if (options.extra_data && options.extra_data[0]) { min = g_ascii_strtod (options.extra_data[0], NULL); if (options.extra_data[1]) max = g_ascii_strtod (options.extra_data[1], NULL); if (options.extra_data[2]) step = g_ascii_strtod (options.extra_data[2], NULL); if (options.extra_data[3]) { prec = (guint) g_ascii_strtoull (options.extra_data[3], NULL, 0); if (prec > 20) prec = 20; } } c = entry = gtk_spin_button_new_with_range (min, max, step); gtk_entry_set_alignment (GTK_ENTRY (c), 1.0); gtk_spin_button_set_digits (GTK_SPIN_BUTTON (c), prec); gtk_widget_set_name (entry, "yad-entry-spin"); if (options.entry_data.entry_text) { val = g_ascii_strtod (options.entry_data.entry_text, NULL); if (min >= max) { g_printerr (_("Maximum value must be greater than minimum value.\n")); min = 0.0; max = 65535.0; } if (val < min) { g_printerr (_("Initial value less than minimal.\n")); val = min; } else if (val > max) { g_printerr (_("Initial value greater than maximum.\n")); val = max; } } gtk_spin_button_set_value (GTK_SPIN_BUTTON (c), val); } else if (!options.entry_data.completion && options.extra_data && *options.extra_data) { gint active, i; if (options.common_data.editable || settings.combo_always_editable) { #if GTK_CHECK_VERSION(2,24,0) c = gtk_combo_box_text_new_with_entry (); #else c = gtk_combo_box_entry_new_text (); #endif gtk_widget_set_name (c, "yad-entry-edit-combo"); entry = gtk_bin_get_child (GTK_BIN (c)); if (options.entry_data.licon) { GdkPixbuf *pb = get_pixbuf (options.entry_data.licon, YAD_SMALL_ICON); if (pb) gtk_entry_set_icon_from_pixbuf (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, pb); } if (options.entry_data.ricon) { GdkPixbuf *pb = get_pixbuf (options.entry_data.ricon, YAD_SMALL_ICON); if (pb) gtk_entry_set_icon_from_pixbuf (GTK_ENTRY (entry), GTK_ENTRY_ICON_SECONDARY, pb); } } else { #if GTK_CHECK_VERSION(2,24,0) c = entry = gtk_combo_box_text_new (); #else c = entry = gtk_combo_box_new_text (); #endif gtk_widget_set_name (c, "yad-entry-combo"); is_combo = TRUE; } i = 0; active = -1; while (options.extra_data[i] != NULL) { if (options.entry_data.entry_text && g_ascii_strcasecmp (options.extra_data[i], options.entry_data.entry_text) == 0) active = i; #if GTK_CHECK_VERSION(2,24,0) gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (c), options.extra_data[i]); #else gtk_combo_box_append_text (GTK_COMBO_BOX (c), options.extra_data[i]); #endif i++; } if (options.entry_data.entry_text && active == -1) { #if GTK_CHECK_VERSION(2,24,0) gtk_combo_box_text_prepend_text (GTK_COMBO_BOX_TEXT (c), options.entry_data.entry_text); #else gtk_combo_box_prepend_text (GTK_COMBO_BOX (c), options.entry_data.entry_text); #endif } /* set first iter active */ if (!options.common_data.editable) gtk_combo_box_set_active (GTK_COMBO_BOX (c), (active != -1 ? active : 0)); } else { c = entry = gtk_entry_new (); gtk_widget_set_name (c, "yad-entry-widget"); gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE); if (options.entry_data.entry_text) gtk_entry_set_text (GTK_ENTRY (entry), options.entry_data.entry_text); if (options.entry_data.hide_text) g_object_set (G_OBJECT (entry), "visibility", FALSE, NULL); if (options.entry_data.completion) { GtkEntryCompletion *completion; GtkTreeModel *completion_model; completion = gtk_entry_completion_new (); gtk_entry_set_completion (GTK_ENTRY (entry), completion); completion_model = create_completion_model (); gtk_entry_completion_set_model (completion, completion_model); g_object_unref (completion_model); gtk_entry_completion_set_text_column (completion, 0); if (options.common_data.complete != YAD_COMPLETE_SIMPLE) gtk_entry_completion_set_match_func (completion, check_complete, NULL, NULL); g_object_unref (completion); } if (options.entry_data.licon) { GdkPixbuf *pb = get_pixbuf (options.entry_data.licon, YAD_SMALL_ICON); if (pb) gtk_entry_set_icon_from_pixbuf (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, pb); } if (options.entry_data.ricon) { GdkPixbuf *pb = get_pixbuf (options.entry_data.ricon, YAD_SMALL_ICON); if (pb) gtk_entry_set_icon_from_pixbuf (GTK_ENTRY (entry), GTK_ENTRY_ICON_SECONDARY, pb); } } if (l) gtk_label_set_mnemonic_widget (GTK_LABEL (l), entry); if (!is_combo) g_signal_connect (G_OBJECT (entry), "activate", G_CALLBACK (entry_activate_cb), dlg); else g_signal_connect (G_OBJECT (entry), "key-press-event", G_CALLBACK (combo_activate_cb), dlg); if (options.entry_data.licon || options.entry_data.ricon) g_signal_connect (G_OBJECT (entry), "icon-press", G_CALLBACK (icon_cb), NULL); gtk_box_pack_start (GTK_BOX (w), c, TRUE, TRUE, 1); return w; }
GtkWidget * totem_open_location_new (void) { TotemOpenLocation *open_location; char *clipboard_location; GtkEntryCompletion *completion; GtkTreeModel *model; GList *recent_items, *streams_recent_items = NULL; open_location = TOTEM_OPEN_LOCATION (g_object_new (TOTEM_TYPE_OPEN_LOCATION, NULL)); if (open_location->priv->uri_container == NULL) { g_object_unref (open_location); return NULL; } gtk_window_set_title (GTK_WINDOW (open_location), _("Open Location...")); gtk_dialog_add_buttons (GTK_DIALOG (open_location), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL); gtk_dialog_set_response_sensitive (GTK_DIALOG (open_location), GTK_RESPONSE_OK, FALSE); gtk_container_set_border_width (GTK_CONTAINER (open_location), 5); gtk_dialog_set_default_response (GTK_DIALOG (open_location), GTK_RESPONSE_OK); /* Get item from clipboard to fill GtkEntry */ clipboard_location = totem_open_location_set_from_clipboard (open_location); if (clipboard_location != NULL && strcmp (clipboard_location, "") != 0) gtk_entry_set_text (open_location->priv->uri_entry, clipboard_location); g_free (clipboard_location); /* Add items in Totem's GtkRecentManager to the URI GtkEntry's GtkEntryCompletion */ completion = gtk_entry_completion_new(); model = GTK_TREE_MODEL (gtk_list_store_new (1, G_TYPE_STRING)); gtk_entry_set_completion (open_location->priv->uri_entry, completion); recent_items = gtk_recent_manager_get_items (gtk_recent_manager_get_default ()); if (recent_items != NULL) { GList *p; GtkTreeIter iter; /* Filter out non-Totem items */ for (p = recent_items; p != NULL; p = p->next) { GtkRecentInfo *info = (GtkRecentInfo *) p->data; if (!gtk_recent_info_has_group (info, "TotemStreams")) { gtk_recent_info_unref (info); continue; } streams_recent_items = g_list_prepend (streams_recent_items, info); } streams_recent_items = g_list_sort (streams_recent_items, (GCompareFunc) totem_compare_recent_stream_items); /* Populate the list store for the combobox */ for (p = streams_recent_items; p != NULL; p = p->next) { GtkRecentInfo *info = (GtkRecentInfo *) p->data; gtk_list_store_append (GTK_LIST_STORE (model), &iter); gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, gtk_recent_info_get_uri (info), -1); gtk_recent_info_unref (info); } g_list_free (streams_recent_items); } g_list_free (recent_items); gtk_entry_completion_set_model (completion, model); gtk_entry_completion_set_text_column (completion, 0); gtk_entry_completion_set_match_func (completion, (GtkEntryCompletionMatchFunc) totem_open_location_match, model, NULL); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (open_location))), open_location->priv->uri_container, TRUE, /* expand */ TRUE, /* fill */ 0); /* padding */ gtk_widget_show_all (gtk_dialog_get_content_area (GTK_DIALOG (open_location))); return GTK_WIDGET (open_location); }
static void update_completion( GtkEntry* entry, GtkEntryCompletion* completion ) { GtkListStore* list; GtkTreeIter it; const char* text = gtk_entry_get_text( entry ); if ( text && ( text[0] == '$' || text[0] == '+' || text[0] == '&' || text[0] == '!' || text[0] == '%' || ( text[0] != '/' && strstr( text, ":/" ) ) || g_str_has_prefix( text, "//" ) ) ) { // command history GList* l; list = (GtkListStore*)gtk_entry_completion_get_model( completion ); gtk_list_store_clear( list ); for ( l = xset_cmd_history; l; l = l->next ) { gtk_list_store_append( list, &it ); gtk_list_store_set( list, &it, COL_NAME, (char*)l->data, COL_PATH, (char*)l->data, -1 ); } gtk_entry_completion_set_match_func( completion, match_func_cmd, NULL, NULL ); } else { // dir completion char* new_dir, *fn; const char* old_dir; const char *sep; sep = strrchr( text, '/' ); if( sep ) fn = (char*)sep + 1; else fn = (char*)text; g_object_set_data_full( G_OBJECT(completion), "fn", g_strdup(fn), (GDestroyNotify)g_free ); new_dir = get_cwd( entry ); old_dir = (const char*)g_object_get_data( (GObject*)completion, "cwd" ); if ( old_dir && new_dir && 0 == g_ascii_strcasecmp( old_dir, new_dir ) ) { g_free( new_dir ); return; } g_object_set_data_full( (GObject*)completion, "cwd", new_dir, g_free ); list = (GtkListStore*)gtk_entry_completion_get_model( completion ); gtk_list_store_clear( list ); if ( new_dir ) { GDir* dir; if( (dir = g_dir_open( new_dir, 0, NULL )) ) { // build list of dir names const char* name; GSList* name_list = NULL; while( (name = g_dir_read_name( dir )) ) { char* full_path = g_build_filename( new_dir, name, NULL ); if( g_file_test( full_path, G_FILE_TEST_IS_DIR ) ) name_list = g_slist_prepend( name_list, full_path ); } g_dir_close( dir ); // add sorted list to liststore GSList* l; char* disp_name; name_list = g_slist_sort( name_list, (GCompareFunc)g_strcmp0 ); for ( l = name_list; l; l = l->next ) { disp_name = g_filename_display_basename( (char*)l->data ); gtk_list_store_append( list, &it ); gtk_list_store_set( list, &it, COL_NAME, disp_name, COL_PATH, (char*)l->data, -1 ); g_free( disp_name ); g_free( (char*)l->data ); } g_slist_free( name_list ); gtk_entry_completion_set_match_func( completion, match_func, NULL, NULL ); } else gtk_entry_completion_set_match_func( completion, NULL, NULL, NULL ); } } }
/** * gva_main_init_search_completion: * @error: return location for a #GError, or %NULL * * Initializes autocompletion in the search entry. This must be done * <emphasis>after</emphasis> the game database is built and ROMs are * analyzed. If an error occurs, the function returns %FALSE and sets * @error. * * Returns: %TRUE if autocompletion was initialized successfully, * %FALSE if an error occurred **/ gboolean gva_main_init_search_completion (GError **error) { GtkEntryCompletion *completion; GtkCellRenderer *renderer; GtkListStore *store; GtkTreeIter iter; GtkEntry *entry; sqlite3_stmt *stmt; gint errcode; GList *list; if (!gva_db_prepare (SQL_COMPLETION_LIST, &stmt, error)) return FALSE; store = gtk_list_store_new ( 4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); while ((errcode = sqlite3_step (stmt)) == SQLITE_ROW) { GvaGameStoreColumn column_id; const gchar *column_name; const gchar *column_title; const gchar *search_text; gchar *collation_key; search_text = (const gchar *) sqlite3_column_text (stmt, 0); column_name = (const gchar *) sqlite3_column_text (stmt, 1); gva_columns_lookup_id (column_name, &column_id); column_title = gva_columns_lookup_title (column_id); if (search_text == NULL || *search_text == '\0') continue; gtk_list_store_append (store, &iter); collation_key = gva_search_collate_key (search_text); gtk_list_store_set ( store, &iter, COLUMN_NAME, column_name, COLUMN_TEXT, search_text, COLUMN_TYPE, column_title, COLUMN_CKEY, collation_key, -1); g_free (collation_key); } sqlite3_finalize (stmt); if (errcode != SQLITE_DONE) { gva_db_set_error (error, 0, NULL); g_object_unref (store); return FALSE; } completion = gtk_entry_completion_new (); gtk_entry_completion_set_match_func ( completion, (GtkEntryCompletionMatchFunc) main_entry_completion_match, NULL, NULL); gtk_entry_completion_set_minimum_key_length (completion, 3); gtk_entry_completion_set_model (completion, GTK_TREE_MODEL (store)); gtk_entry_completion_set_text_column (completion, COLUMN_TEXT); g_signal_connect ( completion, "match-selected", G_CALLBACK (main_entry_completion_match_selected_cb), NULL); list = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (completion)); g_object_set (list->data, "ellipsize", PANGO_ELLIPSIZE_END, NULL); g_list_free (list); renderer = gtk_cell_renderer_text_new (); g_object_set (renderer, "sensitive", FALSE, "xalign", 1.0, NULL); gtk_cell_layout_pack_start ( GTK_CELL_LAYOUT (completion), renderer, FALSE); gtk_cell_layout_add_attribute ( GTK_CELL_LAYOUT (completion), renderer, "text", COLUMN_TYPE); entry = GTK_ENTRY (GVA_WIDGET_MAIN_SEARCH_ENTRY); gtk_entry_set_completion (entry, completion); return TRUE; }
GtkWidget * file_open_location_dialog_new (Gimp *gimp) { GimpContext *context; GtkWidget *dialog; GtkWidget *hbox; GtkWidget *vbox; GtkWidget *image; GtkWidget *label; GtkWidget *entry; GtkEntryCompletion *completion; g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL); dialog = gimp_dialog_new (_("Open Location"), "gimp-file-open-location", NULL, 0, gimp_standard_help_func, GIMP_HELP_FILE_OPEN_LOCATION, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL); g_signal_connect (dialog, "response", G_CALLBACK (file_open_location_response), gimp); gtk_dialog_set_alternative_button_order (GTK_DIALOG(dialog), GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); gtk_container_set_border_width (GTK_CONTAINER (hbox), 12); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), hbox, FALSE, FALSE, 0); gtk_widget_show (hbox); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0); gtk_widget_show (vbox); image = gtk_image_new_from_icon_name (GIMP_STOCK_WEB, GTK_ICON_SIZE_BUTTON); gtk_box_pack_start (GTK_BOX (vbox), image, FALSE, FALSE, 0); gtk_widget_show (image); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0); gtk_widget_show (vbox); label = gtk_label_new (_("Enter location (URI):")); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 1.0); gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); gtk_widget_show (label); /* we don't want the context to affect the entry, so create * a scratch one instead of using e.g. the user context */ context = gimp_context_new (gimp, "file-open-location-dialog", NULL); entry = gimp_container_entry_new (gimp->documents, context, GIMP_VIEW_SIZE_SMALL, 0); g_object_unref (context); completion = gtk_entry_get_completion (GTK_ENTRY (entry)); gtk_entry_completion_set_match_func (completion, file_open_location_completion, NULL, NULL); gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE); gtk_widget_set_size_request (entry, 400, -1); gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0); gtk_widget_show (entry); g_object_set_data (G_OBJECT (dialog), "location-entry", entry); return dialog; }
static void empathy_contact_blocking_dialog_init (EmpathyContactBlockingDialog *self) { GtkBuilder *gui; char *filename; GtkWidget *contents; GtkWidget *account_hbox, *blocked_contacts_view, *blocked_contacts_sw, *remove_toolbar; GtkEntryCompletion *completion; TpAccountManager *am; GtkStyleContext *context; TpSimpleClientFactory *factory; self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EMPATHY_TYPE_CONTACT_BLOCKING_DIALOG, EmpathyContactBlockingDialogPrivate); gtk_window_set_title (GTK_WINDOW (self), _("Edit Blocked Contacts")); gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); filename = empathy_file_lookup ("empathy-contact-blocking-dialog.ui", "libempathy-gtk"); gui = empathy_builder_get_file (filename, "contents", &contents, "account-hbox", &account_hbox, "add-button", &self->priv->add_button, "add-contact-entry", &self->priv->add_contact_entry, "blocked-contacts", &self->priv->blocked_contacts, "blocked-contacts-sw", &blocked_contacts_sw, "blocked-contacts-view", &blocked_contacts_view, "remove-button", &self->priv->remove_button, "remove-toolbar", &remove_toolbar, NULL); empathy_builder_connect (gui, self, "add-button", "clicked", contact_blocking_dialog_add_contact, "add-contact-entry", "activate", contact_blocking_dialog_add_contact, "remove-button", "clicked", contact_blocking_dialog_remove_contacts, NULL); /* join the remove toolbar to the treeview */ context = gtk_widget_get_style_context (blocked_contacts_sw); gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM); context = gtk_widget_get_style_context (remove_toolbar); gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP); /* add the contents to the dialog */ gtk_container_add ( GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (self))), contents); gtk_widget_show (contents); /* set up the tree selection */ self->priv->selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW (blocked_contacts_view)); gtk_tree_selection_set_mode (self->priv->selection, GTK_SELECTION_MULTIPLE); g_signal_connect (self->priv->selection, "changed", G_CALLBACK (contact_blocking_dialog_view_selection_changed), self); /* build the contact entry */ self->priv->completion_contacts = gtk_list_store_new (N_COMPLETION_COLUMNS, G_TYPE_STRING, /* id */ G_TYPE_STRING, /* text */ TP_TYPE_CONTACT); /* contact */ completion = gtk_entry_completion_new (); gtk_entry_completion_set_model (completion, GTK_TREE_MODEL (self->priv->completion_contacts)); gtk_entry_completion_set_text_column (completion, COL_COMPLETION_TEXT); gtk_entry_completion_set_match_func (completion, contact_selector_dialog_match_func, NULL, NULL); g_signal_connect (completion, "match-selected", G_CALLBACK (contact_selector_dialog_match_selected_cb), self); gtk_entry_set_completion (GTK_ENTRY (self->priv->add_contact_entry), completion); g_object_unref (completion); g_object_unref (self->priv->completion_contacts); /* add the account chooser */ self->priv->account_chooser = empathy_account_chooser_new (); contact_blocking_dialog_refilter_account_chooser (self); g_signal_connect (self->priv->account_chooser, "changed", G_CALLBACK (contact_blocking_dialog_account_changed), self); gtk_box_pack_start (GTK_BOX (account_hbox), self->priv->account_chooser, TRUE, TRUE, 0); gtk_widget_show (self->priv->account_chooser); /* add an error warning info bar */ self->priv->info_bar = gtk_info_bar_new (); gtk_box_pack_start (GTK_BOX (contents), self->priv->info_bar, FALSE, TRUE, 0); gtk_info_bar_set_message_type (GTK_INFO_BAR (self->priv->info_bar), GTK_MESSAGE_ERROR); self->priv->info_bar_label = gtk_label_new (""); gtk_container_add (GTK_CONTAINER ( gtk_info_bar_get_content_area (GTK_INFO_BAR (self->priv->info_bar))), self->priv->info_bar_label); gtk_widget_show (self->priv->info_bar_label); /* prepare the account manager */ am = tp_account_manager_dup (); factory = tp_proxy_get_factory (am); tp_simple_client_factory_add_connection_features_varargs (factory, TP_CONNECTION_FEATURE_CONTACT_BLOCKING, NULL); tp_proxy_prepare_async (am, NULL, contact_blocking_dialog_am_prepared, self); g_object_unref (am); g_free (filename); g_object_unref (gui); }
int main (int argc, char *argv[]) { GtkWidget *vbox; GtkWidget *label; GtkWidget *entry; GtkEntryCompletion *completion; GtkTreeModel *completion_model; GtkCellRenderer *cell; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_container_set_border_width (GTK_CONTAINER (window), 5); g_signal_connect (window, "delete_event", gtk_main_quit, NULL); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2); gtk_container_add (GTK_CONTAINER (window), vbox); gtk_container_set_border_width (GTK_CONTAINER (vbox), 5); label = gtk_label_new (NULL); gtk_label_set_markup (GTK_LABEL (label), "Completion demo, try writing <b>total</b> or <b>gnome</b> for example."); gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); /* Create our first entry */ entry = gtk_entry_new (); /* Create the completion object */ completion = gtk_entry_completion_new (); gtk_entry_completion_set_inline_completion (completion, TRUE); /* Assign the completion to the entry */ gtk_entry_set_completion (GTK_ENTRY (entry), completion); g_object_unref (completion); add_with_prop_edit_button (vbox, entry, completion); /* Create a tree model and use it as the completion model */ completion_model = create_simple_completion_model (); gtk_entry_completion_set_model (completion, completion_model); g_object_unref (completion_model); /* Use model column 0 as the text column */ gtk_entry_completion_set_text_column (completion, 0); /* Create our second entry */ entry = gtk_entry_new (); /* Create the completion object */ completion = gtk_entry_completion_new (); /* Assign the completion to the entry */ gtk_entry_set_completion (GTK_ENTRY (entry), completion); g_object_unref (completion); add_with_prop_edit_button (vbox, entry, completion); /* Create a tree model and use it as the completion model */ completion_model = create_completion_model (); gtk_entry_completion_set_model (completion, completion_model); gtk_entry_completion_set_minimum_key_length (completion, 2); g_object_unref (completion_model); /* Use model column 1 as the text column */ cell = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (completion), cell, FALSE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (completion), cell, "pixbuf", 0, NULL); cell = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (completion), cell, FALSE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (completion), cell, "text", 1, NULL); gtk_entry_completion_set_match_func (completion, match_func, NULL, NULL); g_signal_connect (completion, "match-selected", G_CALLBACK (match_selected_cb), NULL); gtk_entry_completion_insert_action_text (completion, 100, "action!"); gtk_entry_completion_insert_action_text (completion, 101, "'nother action!"); g_signal_connect (completion, "action_activated", G_CALLBACK (activated_cb), NULL); /* Create our third entry */ entry = gtk_entry_new (); /* Create the completion object */ completion = gtk_entry_completion_new (); /* Assign the completion to the entry */ gtk_entry_set_completion (GTK_ENTRY (entry), completion); g_object_unref (completion); add_with_prop_edit_button (vbox, entry, completion); /* Create a tree model and use it as the completion model */ completion_model = GTK_TREE_MODEL (gtk_list_store_new (1, G_TYPE_STRING)); gtk_entry_completion_set_model (completion, completion_model); g_object_unref (completion_model); /* Use model column 0 as the text column */ gtk_entry_completion_set_text_column (completion, 0); /* Fill the completion dynamically */ gdk_threads_add_timeout (1000, (GSourceFunc) animation_timer, completion); /* Fourth entry */ gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new ("Model-less entry completion"), FALSE, FALSE, 0); entry = gtk_entry_new (); /* Create the completion object */ completion = gtk_entry_completion_new (); /* Assign the completion to the entry */ gtk_entry_set_completion (GTK_ENTRY (entry), completion); g_object_unref (completion); add_with_prop_edit_button (vbox, entry, completion); gtk_widget_show_all (window); gtk_main (); return 0; }
static void ring_main_window_init(RingMainWindow *win) { RingMainWindowPrivate *priv = RING_MAIN_WINDOW_GET_PRIVATE(win); gtk_widget_init_template(GTK_WIDGET(win)); /* set window icon */ GError *error = NULL; GdkPixbuf* icon = gdk_pixbuf_new_from_resource("/cx/ring/RingGnome/ring-symbol-blue", &error); if (icon == NULL) { g_debug("Could not load icon: %s", error->message); g_clear_error(&error); } else gtk_window_set_icon(GTK_WINDOW(win), icon); /* set menu icon */ GdkPixbuf* image_ring = gdk_pixbuf_new_from_resource_at_scale("/cx/ring/RingGnome/ring-symbol-blue", -1, 24, TRUE, &error); if (image_ring == NULL) { g_debug("Could not load icon: %s", error->message); g_clear_error(&error); } else gtk_image_set_from_pixbuf(GTK_IMAGE(priv->image_ring), image_ring); /* ring menu */ GtkBuilder *builder = gtk_builder_new_from_resource("/cx/ring/RingGnome/ringgearsmenu.ui"); GMenuModel *menu = G_MENU_MODEL(gtk_builder_get_object(builder, "menu")); gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(priv->ring_menu), menu); g_object_unref(builder); /* settings icon */ gtk_image_set_from_icon_name(GTK_IMAGE(priv->image_settings), "emblem-system-symbolic", GTK_ICON_SIZE_LARGE_TOOLBAR); /* connect settings button signal */ g_signal_connect(priv->ring_settings, "clicked", G_CALLBACK(settings_clicked), win); /* add the call view to the main stack */ gtk_stack_add_named(GTK_STACK(priv->stack_main_view), priv->vbox_call_view, CALL_VIEW_NAME); if (has_ring_account()) { /* user has ring account, so show the call view right away */ gtk_stack_set_visible_child(GTK_STACK(priv->stack_main_view), priv->vbox_call_view); } else { /* user has to create the ring account */ show_account_creation(win); } /* init the settings views */ priv->account_settings_view = account_view_new(); gtk_stack_add_named(GTK_STACK(priv->stack_main_view), priv->account_settings_view, ACCOUNT_SETTINGS_VIEW_NAME); priv->media_settings_view = media_settings_view_new(); gtk_stack_add_named(GTK_STACK(priv->stack_main_view), priv->media_settings_view, MEDIA_SETTINGS_VIEW_NAME); priv->general_settings_view = general_settings_view_new(); gtk_stack_add_named(GTK_STACK(priv->stack_main_view), priv->general_settings_view, GENERAL_SETTINGS_VIEW_NAME); /* make the setting we will show first the active one */ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->radiobutton_general_settings), TRUE); priv->last_settings_view = priv->general_settings_view; /* connect the settings button signals to switch settings views */ g_signal_connect(priv->radiobutton_media_settings, "toggled", G_CALLBACK(show_media_settings), win); g_signal_connect(priv->radiobutton_account_settings, "toggled", G_CALLBACK(show_account_settings), win); g_signal_connect(priv->radiobutton_general_settings, "toggled", G_CALLBACK(show_general_settings), win); /* populate the notebook */ auto smart_view = recent_contacts_view_new(); gtk_container_add(GTK_CONTAINER(priv->scrolled_window_smartview), smart_view); auto contacts_view = contacts_view_new(); gtk_container_add(GTK_CONTAINER(priv->scrolled_window_contacts), contacts_view); auto history_view = history_view_new(); gtk_container_add(GTK_CONTAINER(priv->scrolled_window_history), history_view); /* welcome/default view */ priv->welcome_view = ring_welcome_view_new(); g_object_ref(priv->welcome_view); // gtk_stack_add_named(GTK_STACK(priv->stack_call_view), welcome_view, DEFAULT_VIEW_NAME); gtk_container_add(GTK_CONTAINER(priv->frame_call), priv->welcome_view); gtk_widget_show(priv->welcome_view); /* call/chat selection */ QObject::connect( RecentModel::instance().selectionModel(), &QItemSelectionModel::currentChanged, [win](const QModelIndex current, G_GNUC_UNUSED const QModelIndex & previous) { if (auto call = RecentModel::instance().getActiveCall(current)) { /* if the call is on hold, we want to put it off hold automatically * when switching to it */ if (call->state() == Call::State::HOLD) call << Call::Action::HOLD; } selection_changed(current, win); } ); /* connect to dataChanged of the RecentModel to see if we need to change the view */ QObject::connect( &RecentModel::instance(), &RecentModel::dataChanged, [win](const QModelIndex & topLeft, G_GNUC_UNUSED const QModelIndex & bottomRight, G_GNUC_UNUSED const QVector<int> & roles) { /* it is possible for dataChanged to be emitted inside of a dataChanged handler or * some other signal; since the connection is via a lambda, Qt would cause the * handler to be called directly. This is not behaviour we usually want, so we call our * function via g_idle so that it gets called after the initial handler is done. */ if (topLeft == RecentModel::instance().selectionModel()->currentIndex()) g_idle_add((GSourceFunc)selected_item_changed, win); } ); g_signal_connect(priv->button_placecall, "clicked", G_CALLBACK(search_entry_placecall), win); g_signal_connect(priv->search_entry, "activate", G_CALLBACK(search_entry_placecall), win); /* autocompletion */ priv->q_completion_model = new NumberCompletionModel(); /* autocompletion renderers */ GtkCellArea *completion_area = gtk_cell_area_box_new(); /* photo renderer */ GtkCellRenderer *renderer = gtk_cell_renderer_pixbuf_new(); gtk_cell_area_box_pack_start(GTK_CELL_AREA_BOX(completion_area), renderer, TRUE, /* expand */ TRUE, /* align */ TRUE); /* fixed size */ gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(completion_area), renderer, (GtkCellLayoutDataFunc)autocompletion_photo_render, NULL, NULL); /* name renderer */ renderer = gtk_cell_renderer_text_new(); g_object_set(G_OBJECT(renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL); gtk_cell_area_box_pack_start(GTK_CELL_AREA_BOX(completion_area), renderer, TRUE, /* expand */ TRUE, /* align */ TRUE); /* fixed size */ gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(completion_area), renderer, (GtkCellLayoutDataFunc)autocompletion_name_render, NULL, NULL); /* number renderer */ renderer = gtk_cell_renderer_text_new(); g_object_set(G_OBJECT(renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL); gtk_cell_area_box_pack_start(GTK_CELL_AREA_BOX(completion_area), renderer, TRUE, /* expand */ TRUE, /* align */ TRUE); /* fixed size */ gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(completion_area), renderer, (GtkCellLayoutDataFunc)autocompletion_number_render, NULL, NULL); /* account renderer */ renderer = gtk_cell_renderer_text_new(); g_object_set(G_OBJECT(renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL); gtk_cell_area_box_pack_start(GTK_CELL_AREA_BOX(completion_area), renderer, TRUE, /* expand */ TRUE, /* align */ TRUE); /* fixed size */ gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(completion_area), renderer, (GtkCellLayoutDataFunc)autocompletion_account_render, NULL, NULL); GtkEntryCompletion *entry_completion = gtk_entry_completion_new_with_area(completion_area); GtkQTreeModel *completion_model = gtk_q_tree_model_new( (QAbstractItemModel *)priv->q_completion_model, 1, Qt::DisplayRole, G_TYPE_STRING); gtk_entry_completion_set_model(entry_completion, GTK_TREE_MODEL(completion_model)); gtk_entry_set_completion(GTK_ENTRY(priv->search_entry), entry_completion); gtk_entry_completion_set_match_func( entry_completion, (GtkEntryCompletionMatchFunc) completion_match_func, NULL, NULL); /* connect signal to when text is entered in the entry */ g_signal_connect(priv->search_entry, "changed", G_CALLBACK(search_entry_text_changed), win); g_signal_connect(entry_completion, "match-selected", G_CALLBACK(select_autocompletion), win); /* connect to incoming call and focus */ QObject::connect( &CallModel::instance(), &CallModel::incomingCall, [=](Call* call) { CallModel::instance().selectionModel()->setCurrentIndex( CallModel::instance().getIndex(call), QItemSelectionModel::ClearAndSelect); } ); /* react to digit key press events */ g_signal_connect(win, "key-press-event", G_CALLBACK(dtmf_pressed), NULL); /* set the search entry placeholder text */ gtk_entry_set_placeholder_text(GTK_ENTRY(priv->search_entry), C_("Please try to make the translation 50 chars or less so that it fits into the layout", "Search contacts or enter number")); }