static gboolean individual_drag_received (EmpathyPersonaView *self, GdkDragContext *context, GtkSelectionData *selection) { EmpathyIndividualManager *manager = NULL; FolksIndividual *individual; const gchar *individual_id; gboolean success = FALSE; individual_id = (const gchar *) gtk_selection_data_get_data (selection); manager = empathy_individual_manager_dup_singleton (); individual = empathy_individual_manager_lookup_member (manager, individual_id); if (individual == NULL) { DEBUG ("Failed to find drag event individual with ID '%s'", individual_id); g_object_unref (manager); return FALSE; } /* Emit a signal notifying of the drag. */ g_signal_emit (self, signals[DRAG_INDIVIDUAL_RECEIVED], 0, gdk_drag_context_get_selected_action (context), individual, &success); g_object_unref (manager); return success; }
/* Look for a FolksIndividual containing @contact as one of his persona * and create one if needed */ FolksIndividual * empathy_ensure_individual_from_tp_contact (TpContact *contact) { EmpathyIndividualManager *mgr; FolksIndividual *individual; mgr = empathy_individual_manager_dup_singleton (); individual = empathy_individual_manager_lookup_by_contact (mgr, contact); if (individual != NULL) g_object_ref (individual); else individual = empathy_create_individual_from_tp_contact (contact); g_object_unref (mgr); return individual; }
static void new_individual_response_cb (GtkDialog *dialog, gint response, GtkWidget *contact_widget) { EmpathyIndividualManager *individual_manager; EmpathyContact *contact; individual_manager = empathy_individual_manager_dup_singleton (); contact = empathy_contact_widget_get_contact (contact_widget); if (contact && response == GTK_RESPONSE_OK) empathy_individual_manager_add_from_contact (individual_manager, contact); new_individual_dialog = NULL; gtk_widget_destroy (GTK_WIDGET (dialog)); g_object_unref (individual_manager); }
static gboolean can_add_contact_to_account (TpAccount *account, gpointer user_data) { EmpathyIndividualManager *individual_manager; TpConnection *connection; gboolean result; connection = tp_account_get_connection (account); if (connection == NULL) return FALSE; individual_manager = empathy_individual_manager_dup_singleton (); result = empathy_connection_can_add_personas (connection); g_object_unref (individual_manager); return result; }
int main (int argc, char **argv) { GtkWidget *window, *view1, *view2, *box_horiz; EmpathyIndividualManager *mgr; EmpathyRosterModel *model; gtk_init (&argc, &argv); empathy_gtk_init (); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); empathy_set_css_provider (window); box_horiz = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8); mgr = empathy_individual_manager_dup_singleton (); model = EMPATHY_ROSTER_MODEL (empathy_roster_model_manager_new (mgr)); view1 = create_view_box (model, TRUE, TRUE); view2 = create_view_box (model, FALSE, FALSE); g_object_unref (model); g_object_unref (mgr); gtk_box_pack_start (GTK_BOX (box_horiz), view1, FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (box_horiz), view2, FALSE, TRUE, 0); gtk_container_add (GTK_CONTAINER (window), box_horiz); gtk_window_set_default_size (GTK_WINDOW (window), 600, 600); gtk_widget_show_all (window); g_signal_connect_swapped (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); gtk_main (); return 0; }
static void can_add_contact_to_account (TpAccount *account, EmpathyAccountChooserFilterResultCallback callback, gpointer callback_data, gpointer user_data) { EmpathyIndividualManager *individual_manager; TpConnection *connection; gboolean result; connection = tp_account_get_connection (account); if (connection == NULL) { callback (FALSE, callback_data); return; } individual_manager = empathy_individual_manager_dup_singleton (); result = empathy_connection_can_add_personas (connection); g_object_unref (individual_manager); callback (result, callback_data); }
static void set_up (EmpathyIndividualLinker *self) { EmpathyIndividualLinkerPriv *priv; EmpathyIndividualManager *individual_manager; GtkWidget *top_vbox; GtkPaned *paned; GtkWidget *label, *scrolled_window; GtkBox *vbox; EmpathyPersonaView *persona_view; gchar *tmp; GtkWidget *alignment; priv = GET_PRIV (self); top_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); /* Layout panes */ paned = GTK_PANED (gtk_paned_new (GTK_ORIENTATION_HORIZONTAL)); /* Left column heading */ alignment = gtk_alignment_new (0.5, 0.5, 1, 1); gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 0, 6); gtk_widget_show (alignment); vbox = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 6)); label = gtk_label_new (NULL); tmp = g_strdup_printf ("<b>%s</b>", _("Select contacts to link")); gtk_label_set_markup (GTK_LABEL (label), tmp); g_free (tmp); gtk_box_pack_start (vbox, label, FALSE, TRUE, 0); gtk_widget_show (label); /* Individual selector */ individual_manager = empathy_individual_manager_dup_singleton (); priv->individual_store = EMPATHY_INDIVIDUAL_STORE ( empathy_individual_store_manager_new (individual_manager)); g_object_unref (individual_manager); empathy_individual_store_set_show_protocols (priv->individual_store, FALSE); priv->individual_view = empathy_individual_view_new (priv->individual_store, EMPATHY_INDIVIDUAL_VIEW_FEATURE_INDIVIDUAL_DRAG | EMPATHY_INDIVIDUAL_VIEW_FEATURE_INDIVIDUAL_DROP | EMPATHY_INDIVIDUAL_VIEW_FEATURE_PERSONA_DROP, EMPATHY_INDIVIDUAL_FEATURE_NONE); empathy_individual_view_set_show_offline (priv->individual_view, TRUE); empathy_individual_view_set_show_untrusted (priv->individual_view, FALSE); g_signal_connect (priv->individual_view, "row-activated", (GCallback) row_activated_cb, self); g_signal_connect (priv->individual_view, "drag-motion", (GCallback) individual_view_drag_motion_cb, self); g_signal_connect (priv->individual_view, "drag-persona-received", (GCallback) individual_view_drag_persona_received_cb, self); /* Add a checkbox column to the selector */ priv->toggle_renderer = gtk_cell_renderer_toggle_new (); g_signal_connect (priv->toggle_renderer, "toggled", (GCallback) row_toggled_cb, self); priv->toggle_column = gtk_tree_view_column_new (); gtk_tree_view_column_pack_start (priv->toggle_column, priv->toggle_renderer, FALSE); gtk_tree_view_column_set_cell_data_func (priv->toggle_column, priv->toggle_renderer, (GtkTreeCellDataFunc) contact_toggle_cell_data_func, self, NULL); gtk_tree_view_insert_column (GTK_TREE_VIEW (priv->individual_view), priv->toggle_column, 0); scrolled_window = gtk_scrolled_window_new (NULL, NULL); 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_IN); gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (priv->individual_view)); gtk_widget_show (GTK_WIDGET (priv->individual_view)); gtk_box_pack_start (vbox, scrolled_window, TRUE, TRUE, 0); gtk_widget_show (scrolled_window); /* Live search */ priv->search_widget = empathy_live_search_new ( GTK_WIDGET (priv->individual_view)); empathy_individual_view_set_live_search (priv->individual_view, EMPATHY_LIVE_SEARCH (priv->search_widget)); gtk_box_pack_end (vbox, priv->search_widget, FALSE, TRUE, 0); gtk_container_add (GTK_CONTAINER (alignment), GTK_WIDGET (vbox)); gtk_paned_pack1 (paned, alignment, TRUE, FALSE); gtk_widget_show (GTK_WIDGET (vbox)); /* Right column heading */ alignment = gtk_alignment_new (0.5, 0.5, 1, 1); gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 6, 0); gtk_widget_show (alignment); vbox = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 6)); label = gtk_label_new (NULL); tmp = g_strdup_printf ("<b>%s</b>", _("New contact preview")); gtk_label_set_markup (GTK_LABEL (label), tmp); g_free (tmp); gtk_box_pack_start (vbox, label, FALSE, TRUE, 0); gtk_widget_show (label); /* New individual preview */ priv->preview_widget = empathy_individual_widget_new (priv->new_individual, EMPATHY_INDIVIDUAL_WIDGET_SHOW_DETAILS); gtk_box_pack_start (vbox, priv->preview_widget, FALSE, TRUE, 0); gtk_widget_show (priv->preview_widget); /* Persona list */ scrolled_window = gtk_scrolled_window_new (NULL, NULL); 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_IN); priv->persona_store = empathy_persona_store_new (priv->new_individual); empathy_persona_store_set_show_protocols (priv->persona_store, TRUE); persona_view = empathy_persona_view_new (priv->persona_store, EMPATHY_PERSONA_VIEW_FEATURE_ALL); empathy_persona_view_set_show_offline (persona_view, TRUE); g_signal_connect (persona_view, "drag-individual-received", (GCallback) persona_view_drag_individual_received_cb, self); gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (persona_view)); gtk_widget_show (GTK_WIDGET (persona_view)); gtk_box_pack_start (vbox, scrolled_window, TRUE, TRUE, 0); gtk_widget_show (scrolled_window); gtk_container_add (GTK_CONTAINER (alignment), GTK_WIDGET (vbox)); gtk_paned_pack2 (paned, alignment, TRUE, FALSE); gtk_widget_show (GTK_WIDGET (vbox)); gtk_widget_show (GTK_WIDGET (paned)); /* Footer label */ label = gtk_label_new (NULL); tmp = g_strdup_printf ("<i>%s</i>", _("Contacts selected in the list on the left will be linked together.")); gtk_label_set_markup (GTK_LABEL (label), tmp); g_free (tmp); gtk_widget_show (label); gtk_box_pack_start (GTK_BOX (top_vbox), GTK_WIDGET (paned), TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (top_vbox), label, FALSE, TRUE, 0); /* Add the main vbox to the bin */ gtk_box_pack_start (GTK_BOX (self), GTK_WIDGET (top_vbox), TRUE, TRUE, 0); gtk_widget_show (GTK_WIDGET (top_vbox)); }
int main (int argc, char **argv) { GtkWidget *window, *view, *scrolled, *box, *search; EmpathyIndividualManager *mgr; GError *error = NULL; GOptionContext *context; EmpathyRosterModel *model; gtk_init (&argc, &argv); empathy_gtk_init (); context = g_option_context_new ("- test tree model performance"); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_print ("option parsing failed: %s\n", error->message); return 1; } window = gtk_window_new (GTK_WINDOW_TOPLEVEL); empathy_set_css_provider (window); box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8); mgr = empathy_individual_manager_dup_singleton (); model = EMPATHY_ROSTER_MODEL (empathy_roster_model_manager_new (mgr)); view = empathy_roster_view_new (model); g_object_unref (model); g_signal_connect (view, "individual-activated", G_CALLBACK (individual_activated_cb), NULL); g_signal_connect (view, "popup-individual-menu", G_CALLBACK (popup_individual_menu_cb), NULL); g_signal_connect (view, "notify::empty", G_CALLBACK (empty_cb), NULL); g_signal_connect (view, "individual-tooltip", G_CALLBACK (individual_tooltip_cb), NULL); gtk_widget_set_has_tooltip (view, TRUE); empathy_roster_view_show_offline (EMPATHY_ROSTER_VIEW (view), show_offline); empathy_roster_view_show_groups (EMPATHY_ROSTER_VIEW (view), show_groups); g_object_unref (mgr); search = tpaw_live_search_new (view); empathy_roster_view_set_live_search (EMPATHY_ROSTER_VIEW (view), TPAW_LIVE_SEARCH (search)); scrolled = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); gtk_container_add (GTK_CONTAINER (scrolled), view); gtk_box_pack_start (GTK_BOX (box), search, FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (box), scrolled, TRUE, TRUE, 0); gtk_container_add (GTK_CONTAINER (window), box); gtk_window_set_default_size (GTK_WINDOW (window), 300, 600); gtk_widget_show_all (window); g_signal_connect_swapped (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); gtk_main (); return 0; }