diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2012-02-08 21:52:10 +0800 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2012-02-08 22:13:34 +0800 |
commit | a71aa49346ee9a6ea4c7ceb14850d58824fb36de (patch) | |
tree | 58bff80950ed3b1d42490ecc9dec20350f2133b4 /libempathy-gtk | |
parent | 4bd4dca988dcd4680c9a381ebe7aed881006c556 (diff) | |
download | gsoc2013-empathy-a71aa49346ee9a6ea4c7ceb14850d58824fb36de.tar gsoc2013-empathy-a71aa49346ee9a6ea4c7ceb14850d58824fb36de.tar.gz gsoc2013-empathy-a71aa49346ee9a6ea4c7ceb14850d58824fb36de.tar.bz2 gsoc2013-empathy-a71aa49346ee9a6ea4c7ceb14850d58824fb36de.tar.lz gsoc2013-empathy-a71aa49346ee9a6ea4c7ceb14850d58824fb36de.tar.xz gsoc2013-empathy-a71aa49346ee9a6ea4c7ceb14850d58824fb36de.tar.zst gsoc2013-empathy-a71aa49346ee9a6ea4c7ceb14850d58824fb36de.zip |
remove linking UI
https://bugzilla.gnome.org/show_bug.cgi?id=669482
Diffstat (limited to 'libempathy-gtk')
-rw-r--r-- | libempathy-gtk/Makefile.am | 4 | ||||
-rw-r--r-- | libempathy-gtk/empathy-individual-linker.c | 779 | ||||
-rw-r--r-- | libempathy-gtk/empathy-individual-linker.h | 76 | ||||
-rw-r--r-- | libempathy-gtk/empathy-linking-dialog.c | 276 | ||||
-rw-r--r-- | libempathy-gtk/empathy-linking-dialog.h | 66 |
5 files changed, 0 insertions, 1201 deletions
diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am index 41cae1e5e..7643318d4 100644 --- a/libempathy-gtk/Makefile.am +++ b/libempathy-gtk/Makefile.am @@ -46,7 +46,6 @@ libempathy_gtk_handwritten_source = \ empathy-contact-dialogs.c \ empathy-contact-chooser.c \ empathy-contactinfo-utils.c \ - empathy-linking-dialog.c \ empathy-live-search.c \ empathy-contact-search-dialog.c \ empathy-contact-widget.c \ @@ -55,7 +54,6 @@ libempathy_gtk_handwritten_source = \ empathy-groups-widget.c \ empathy-individual-dialogs.c \ empathy-individual-edit-dialog.c \ - empathy-individual-linker.c \ empathy-individual-menu.c \ empathy-individual-store.c \ empathy-individual-store-channel.c \ @@ -113,7 +111,6 @@ libempathy_gtk_headers = \ empathy-contact-blocking-dialog.h \ empathy-contact-dialogs.h \ empathy-contact-chooser.h \ - empathy-linking-dialog.h \ empathy-live-search.h \ empathy-contact-search-dialog.h \ empathy-contact-widget.h \ @@ -124,7 +121,6 @@ libempathy_gtk_headers = \ empathy-images.h \ empathy-individual-dialogs.h \ empathy-individual-edit-dialog.h \ - empathy-individual-linker.h \ empathy-individual-menu.h \ empathy-individual-store.h \ empathy-individual-store-channel.h \ diff --git a/libempathy-gtk/empathy-individual-linker.c b/libempathy-gtk/empathy-individual-linker.c deleted file mode 100644 index 7de5e4add..000000000 --- a/libempathy-gtk/empathy-individual-linker.c +++ /dev/null @@ -1,779 +0,0 @@ -/* - * Copyright (C) 2010 Collabora Ltd. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301 USA - * - * Authors: Philip Withnall <philip.withnall@collabora.co.uk> - */ - -#include "config.h" - -#include <string.h> - -#include <glib/gi18n-lib.h> -#include <gtk/gtk.h> - -#include <telepathy-glib/util.h> - -#include <folks/folks.h> - -#include <libempathy/empathy-individual-manager.h> -#include <libempathy/empathy-utils.h> - -#include "empathy-individual-linker.h" -#include "empathy-individual-store.h" -#include "empathy-individual-store-manager.h" -#include "empathy-individual-view.h" -#include "empathy-individual-widget.h" -#include "empathy-persona-store.h" -#include "empathy-persona-view.h" - -/** - * SECTION:empathy-individual-linker - * @title:EmpathyIndividualLinker - * @short_description: A widget used to link together #FolksIndividual<!-- -->s - * @include: libempathy-gtk/empathy-individual-linker.h - * - * #EmpathyIndividualLinker is a widget which allows selection of several - * #FolksIndividual<!-- -->s to link together to form a single new individual. - * The widget provides a preview of the linked individual. - */ - -/** - * EmpathyIndividualLinker: - * @parent: parent object - * - * Widget which extends #GtkBin to provide a list of #FolksIndividual<!-- -->s - * to link together. - */ - -#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIndividualLinker) - -typedef struct { - EmpathyIndividualStore *individual_store; /* owned */ - EmpathyIndividualView *individual_view; /* child widget */ - GtkWidget *preview_widget; /* child widget */ - EmpathyPersonaStore *persona_store; /* owned */ - GtkTreeViewColumn *toggle_column; /* child widget */ - GtkCellRenderer *toggle_renderer; /* child widget */ - GtkWidget *search_widget; /* child widget */ - - FolksIndividual *start_individual; /* owned, allow-none */ - FolksIndividual *new_individual; /* owned, allow-none */ - - /* Stores the Individuals whose Personas have been added to the - * new_individual */ - /* unowned Individual (borrowed from EmpathyIndividualStore) -> bool */ - GHashTable *changed_individuals; -} EmpathyIndividualLinkerPriv; - -enum { - PROP_START_INDIVIDUAL = 1, - PROP_HAS_CHANGED, -}; - -G_DEFINE_TYPE (EmpathyIndividualLinker, empathy_individual_linker, - GTK_TYPE_BOX); - -static void -contact_toggle_cell_data_func (GtkTreeViewColumn *tree_column, - GtkCellRenderer *cell, - GtkTreeModel *tree_model, - GtkTreeIter *iter, - EmpathyIndividualLinker *self) -{ - EmpathyIndividualLinkerPriv *priv; - FolksIndividual *individual; - gboolean is_group, individual_added; - - priv = GET_PRIV (self); - - gtk_tree_model_get (tree_model, iter, - EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group, - EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, - -1); - - individual_added = GPOINTER_TO_UINT (g_hash_table_lookup ( - priv->changed_individuals, individual)); - - /* We don't want to show checkboxes next to the group rows. - * All checkboxes should be sensitive except the checkbox for the start - * individual, which should be permanently active and insensitive */ - g_object_set (cell, - "visible", !is_group, - "sensitive", individual != priv->start_individual, - "activatable", individual != priv->start_individual, - "active", individual_added || individual == priv->start_individual, - NULL); - - tp_clear_object (&individual); -} - -static void -update_toggle_renderers (EmpathyIndividualLinker *self) -{ - EmpathyIndividualLinkerPriv *priv = GET_PRIV (self); - - /* Re-setting the cell data func to the same function causes a refresh of the - * entire column, ensuring that each toggle button is correctly active or - * inactive. This is necessary because one Individual might appear multiple - * times in the list (in different groups), so toggling one instance of the - * Individual should toggle all of them. */ - gtk_tree_view_column_set_cell_data_func (priv->toggle_column, - priv->toggle_renderer, - (GtkTreeCellDataFunc) contact_toggle_cell_data_func, self, NULL); -} - -static void -link_individual (EmpathyIndividualLinker *self, - FolksIndividual *individual) -{ - EmpathyIndividualLinkerPriv *priv = GET_PRIV (self); - GeeSet *old_personas, *new_personas; - GeeHashSet *final_personas; - gboolean personas_changed; - - /* Add the individual to the link */ - g_hash_table_insert (priv->changed_individuals, individual, - GUINT_TO_POINTER (TRUE)); - - /* Add personas which are in @individual to priv->new_individual, adding them - * to the set of personas. */ - old_personas = folks_individual_get_personas (individual); - new_personas = folks_individual_get_personas (priv->new_individual); - final_personas = gee_hash_set_new (FOLKS_TYPE_PERSONA, g_object_ref, - g_object_unref, g_direct_hash, g_direct_equal); - gee_collection_add_all (GEE_COLLECTION (final_personas), - GEE_COLLECTION (old_personas)); - personas_changed = gee_collection_add_all (GEE_COLLECTION (final_personas), - GEE_COLLECTION (new_personas)); - - /* avoid updating all values in the Individual if the set of personas doesn't - * actually change */ - if (personas_changed) - { - folks_individual_set_personas (priv->new_individual, - GEE_SET (final_personas)); - } - - g_clear_object (&final_personas); - - /* Update the toggle renderers, so that if this Individual is listed in - * another group in the EmpathyIndividualView, the toggle button for that - * group is updated. */ - update_toggle_renderers (self); - - g_object_notify (G_OBJECT (self), "has-changed"); -} - -static void -unlink_individual (EmpathyIndividualLinker *self, - FolksIndividual *individual) -{ - EmpathyIndividualLinkerPriv *priv = GET_PRIV (self); - GeeSet *removed_personas, *old_personas; - GeeHashSet *final_personas; - gboolean personas_changed; - - /* Remove the individual from the link */ - g_hash_table_remove (priv->changed_individuals, individual); - - /* Remove personas which are in @individual from priv->new_individual. */ - old_personas = folks_individual_get_personas (priv->new_individual); - removed_personas = folks_individual_get_personas (individual); - - final_personas = gee_hash_set_new (FOLKS_TYPE_PERSONA, g_object_ref, - g_object_unref, g_direct_hash, g_direct_equal); - gee_collection_add_all (GEE_COLLECTION (final_personas), - GEE_COLLECTION (old_personas)); - personas_changed = gee_collection_remove_all (GEE_COLLECTION (final_personas), - GEE_COLLECTION (removed_personas)); - - if (personas_changed) - { - folks_individual_set_personas (priv->new_individual, - GEE_SET (final_personas)); - } - - g_clear_object (&final_personas); - - /* Update the toggle renderers, so that if this Individual is listed in - * another group in the EmpathyIndividualView, the toggle button for that - * group is updated. */ - update_toggle_renderers (self); - - g_object_notify (G_OBJECT (self), "has-changed"); -} - -static void -toggle_individual_row (EmpathyIndividualLinker *self, - GtkTreePath *path) -{ - EmpathyIndividualLinkerPriv *priv = GET_PRIV (self); - FolksIndividual *individual; - GtkTreeIter iter; - GtkTreeModel *tree_model; - gboolean individual_added; - - tree_model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->individual_view)); - - gtk_tree_model_get_iter (tree_model, &iter, path); - gtk_tree_model_get (tree_model, &iter, - EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, - -1); - - if (individual == NULL) - return; - - individual_added = GPOINTER_TO_UINT (g_hash_table_lookup ( - priv->changed_individuals, individual)); - - /* Toggle the Individual's linked status */ - if (individual_added) - unlink_individual (self, individual); - else - link_individual (self, individual); - - g_object_unref (individual); -} - -static void -row_activated_cb (EmpathyIndividualView *view, - GtkTreePath *path, - GtkTreeViewColumn *column, - EmpathyIndividualLinker *self) -{ - toggle_individual_row (self, path); -} - -static void -row_toggled_cb (GtkCellRendererToggle *cell_renderer, - const gchar *path, - EmpathyIndividualLinker *self) -{ - GtkTreePath *tree_path = gtk_tree_path_new_from_string (path); - toggle_individual_row (self, tree_path); - gtk_tree_path_free (tree_path); -} - -static gboolean -individual_view_drag_motion_cb (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time_) -{ - EmpathyIndividualView *view = EMPATHY_INDIVIDUAL_VIEW (widget); - GdkAtom target; - - target = gtk_drag_dest_find_target (GTK_WIDGET (view), context, NULL); - - if (target == gdk_atom_intern_static_string ("text/x-persona-id")) - { - GtkTreePath *path; - - /* FIXME: It doesn't make sense for us to highlight a specific row or - * position to drop a Persona in, so just highlight the entire widget. - * Since I can't find a way to do this, just highlight the first possible - * position in the tree. */ - gdk_drag_status (context, gdk_drag_context_get_suggested_action (context), - time_); - - path = gtk_tree_path_new_first (); - gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (view), path, - GTK_TREE_VIEW_DROP_BEFORE); - gtk_tree_path_free (path); - - return TRUE; - } - - /* Unknown or unhandled drag target */ - gdk_drag_status (context, GDK_ACTION_DEFAULT, time_); - gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (view), NULL, 0); - - return FALSE; -} - -static gboolean -individual_view_drag_persona_received_cb (EmpathyIndividualView *view, - GdkDragAction action, - FolksPersona *persona, - FolksIndividual *individual, - EmpathyIndividualLinker *self) -{ - EmpathyIndividualLinkerPriv *priv = GET_PRIV (self); - - /* A Persona has been dragged onto the EmpathyIndividualView (from the - * EmpathyPersonaView), so we try to remove the Individual which contains - * the Persona from the link. */ - if (individual != priv->start_individual) - { - unlink_individual (self, individual); - return TRUE; - } - - return FALSE; -} - -static gboolean -persona_view_drag_individual_received_cb (EmpathyPersonaView *view, - GdkDragAction action, - FolksIndividual *individual, - EmpathyIndividualLinker *self) -{ - /* An Individual has been dragged onto the EmpathyPersonaView (from the - * EmpathyIndividualView), so we try to add the Individual to the link. */ - link_individual (self, individual); - - return TRUE; -} - -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)); -} - -static void -empathy_individual_linker_init (EmpathyIndividualLinker *self) -{ - EmpathyIndividualLinkerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - EMPATHY_TYPE_INDIVIDUAL_LINKER, EmpathyIndividualLinkerPriv); - - self->priv = priv; - - priv->changed_individuals = g_hash_table_new (NULL, NULL); - - set_up (self); -} - -static void -get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - EmpathyIndividualLinkerPriv *priv; - - priv = GET_PRIV (object); - - switch (param_id) - { - case PROP_START_INDIVIDUAL: - g_value_set_object (value, priv->start_individual); - break; - case PROP_HAS_CHANGED: - g_value_set_boolean (value, empathy_individual_linker_get_has_changed ( - EMPATHY_INDIVIDUAL_LINKER (object))); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - -static void -set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - switch (param_id) - { - case PROP_START_INDIVIDUAL: - empathy_individual_linker_set_start_individual ( - EMPATHY_INDIVIDUAL_LINKER (object), g_value_get_object (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - -static void -dispose (GObject *object) -{ - EmpathyIndividualLinkerPriv *priv = GET_PRIV (object); - - tp_clear_object (&priv->individual_store); - tp_clear_object (&priv->persona_store); - tp_clear_object (&priv->start_individual); - tp_clear_object (&priv->new_individual); - - G_OBJECT_CLASS (empathy_individual_linker_parent_class)->dispose (object); -} - -static void -finalize (GObject *object) -{ - EmpathyIndividualLinkerPriv *priv = GET_PRIV (object); - - g_hash_table_unref (priv->changed_individuals); - - G_OBJECT_CLASS (empathy_individual_linker_parent_class)->finalize (object); -} - -static void -empathy_individual_linker_class_init (EmpathyIndividualLinkerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->get_property = get_property; - object_class->set_property = set_property; - object_class->dispose = dispose; - object_class->finalize = finalize; - - /** - * EmpathyIndividualLinker:start-individual: - * - * The #FolksIndividual to link other individuals to. This individual is - * selected by default in the list of individuals, and cannot be unselected. - * This ensures that empathy_individual_linker_get_linked_personas() will - * always return at least one persona to link. - */ - g_object_class_install_property (object_class, PROP_START_INDIVIDUAL, - g_param_spec_object ("start-individual", - "Start Individual", - "The #FolksIndividual to link other individuals to.", - FOLKS_TYPE_INDIVIDUAL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - /** - * EmpathyIndividualLinker:has-changed: - * - * Whether #FolksIndividual<!-- -->s have been added to or removed from - * the linked individual currently displayed in the widget. - * - * This will be %FALSE after the widget is initialised, and set to %TRUE when - * an individual is checked in the individual view on the left of the widget. - * If the individual is later unchecked, this will be reset to %FALSE, etc. - */ - g_object_class_install_property (object_class, PROP_HAS_CHANGED, - g_param_spec_boolean ("has-changed", - "Changed?", - "Whether individuals have been added to or removed from the linked " - "individual currently displayed in the widget.", - FALSE, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - - g_type_class_add_private (object_class, sizeof (EmpathyIndividualLinkerPriv)); -} - -/** - * empathy_individual_linker_new: - * @start_individual: (allow-none): the #FolksIndividual to link to, or %NULL - * - * Creates a new #EmpathyIndividualLinker. - * - * Return value: a new #EmpathyIndividualLinker - */ -GtkWidget * -empathy_individual_linker_new (FolksIndividual *start_individual) -{ - g_return_val_if_fail (start_individual == NULL || - FOLKS_IS_INDIVIDUAL (start_individual), NULL); - - return g_object_new (EMPATHY_TYPE_INDIVIDUAL_LINKER, - "start-individual", start_individual, - NULL); -} - -/** - * empathy_individual_linker_get_start_individual: - * @self: an #EmpathyIndividualLinker - * - * Get the value of #EmpathyIndividualLinker:start-individual. - * - * Return value: (transfer none): the start individual for linking, or %NULL - */ -FolksIndividual * -empathy_individual_linker_get_start_individual (EmpathyIndividualLinker *self) -{ - g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_LINKER (self), NULL); - - return GET_PRIV (self)->start_individual; -} - -/** - * empathy_individual_linker_set_start_individual: - * @self: an #EmpathyIndividualLinker - * @individual: (allow-none): the start individual, or %NULL - * - * Set the value of #EmpathyIndividualLinker:start-individual to @individual. - */ -void -empathy_individual_linker_set_start_individual (EmpathyIndividualLinker *self, - FolksIndividual *individual) -{ - EmpathyIndividualLinkerPriv *priv; - - g_return_if_fail (EMPATHY_IS_INDIVIDUAL_LINKER (self)); - g_return_if_fail (individual == NULL || FOLKS_IS_INDIVIDUAL (individual)); - - priv = GET_PRIV (self); - - tp_clear_object (&priv->start_individual); - tp_clear_object (&priv->new_individual); - g_hash_table_remove_all (priv->changed_individuals); - - if (individual != NULL) - { - priv->start_individual = g_object_ref (individual); - priv->new_individual = folks_individual_new ( - folks_individual_get_personas (individual)); - empathy_individual_view_set_store (priv->individual_view, - priv->individual_store); - } - else - { - priv->start_individual = NULL; - priv->new_individual = NULL; - - /* We only display Individuals in the individual view if we have a - * new_individual to link them into */ - empathy_individual_view_set_store (priv->individual_view, NULL); - } - - empathy_individual_widget_set_individual ( - EMPATHY_INDIVIDUAL_WIDGET (priv->preview_widget), priv->new_individual); - empathy_persona_store_set_individual (priv->persona_store, - priv->new_individual); - - g_object_freeze_notify (G_OBJECT (self)); - g_object_notify (G_OBJECT (self), "start-individual"); - g_object_notify (G_OBJECT (self), "has-changed"); - g_object_thaw_notify (G_OBJECT (self)); -} - -/** - * empathy_individual_linker_get_linked_personas: - * @self: an #EmpathyIndividualLinker - * - * Return a list of the #FolksPersona<!-- -->s which comprise the linked - * individual currently displayed in the widget. - * - * The return value is guaranteed to contain at least one element. - * - * Return value: (transfer none) (element-type Folks.Persona): a set of - * #FolksPersona<!-- -->s to link together - */ -GeeSet * -empathy_individual_linker_get_linked_personas (EmpathyIndividualLinker *self) -{ - EmpathyIndividualLinkerPriv *priv; - GeeSet *personas; - - g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_LINKER (self), NULL); - - priv = GET_PRIV (self); - - if (priv->new_individual == NULL) - return NULL; - - personas = folks_individual_get_personas (priv->new_individual); - g_assert (personas != NULL); - return personas; -} - -/** - * empathy_individual_linker_get_has_changed: - * @self: an #EmpathyIndividualLinker - * - * Return whether #FolksIndividual<!-- -->s have been added to or removed from - * the linked individual currently displayed in the widget. - * - * This will be %FALSE after the widget is initialised, and set to %TRUE when - * an individual is checked in the individual view on the left of the widget. - * If the individual is later unchecked, this will be reset to %FALSE, etc. - * - * Return value: %TRUE if the linked individual has been changed, %FALSE - * otherwise - */ -gboolean -empathy_individual_linker_get_has_changed (EmpathyIndividualLinker *self) -{ - EmpathyIndividualLinkerPriv *priv; - - g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_LINKER (self), FALSE); - - priv = GET_PRIV (self); - - return (g_hash_table_size (priv->changed_individuals) > 0) ? TRUE : FALSE; -} - -void -empathy_individual_linker_set_search_text (EmpathyIndividualLinker *self, - const gchar *search_text) -{ - g_return_if_fail (EMPATHY_IS_INDIVIDUAL_LINKER (self)); - - empathy_live_search_set_text ( - EMPATHY_LIVE_SEARCH (GET_PRIV (self)->search_widget), search_text); -} diff --git a/libempathy-gtk/empathy-individual-linker.h b/libempathy-gtk/empathy-individual-linker.h deleted file mode 100644 index 3079fa091..000000000 --- a/libempathy-gtk/empathy-individual-linker.h +++ /dev/null @@ -1,76 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2010 Collabora Ltd. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301 USA - * - * Authors: Philip Withnall <philip.withnall@collabora.co.uk> - */ - -#ifndef __EMPATHY_INDIVIDUAL_LINKER_H__ -#define __EMPATHY_INDIVIDUAL_LINKER_H__ - -#include <gtk/gtk.h> - -#include <folks/folks.h> - -G_BEGIN_DECLS - -#define EMPATHY_TYPE_INDIVIDUAL_LINKER (empathy_individual_linker_get_type ()) -#define EMPATHY_INDIVIDUAL_LINKER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), \ - EMPATHY_TYPE_INDIVIDUAL_LINKER, EmpathyIndividualLinker)) -#define EMPATHY_INDIVIDUAL_LINKER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), \ - EMPATHY_TYPE_INDIVIDUAL_LINKER, EmpathyIndividualLinkerClass)) -#define EMPATHY_IS_INDIVIDUAL_LINKER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), \ - EMPATHY_TYPE_INDIVIDUAL_LINKER)) -#define EMPATHY_IS_INDIVIDUAL_LINKER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), \ - EMPATHY_TYPE_INDIVIDUAL_LINKER)) -#define EMPATHY_INDIVIDUAL_LINKER_GET_CLASS(o) ( \ - G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_INDIVIDUAL_LINKER, \ - EmpathyIndividualLinkerClass)) - -typedef struct { - GtkBox parent; - - /*<private>*/ - gpointer priv; -} EmpathyIndividualLinker; - -typedef struct { - GtkBoxClass parent_class; -} EmpathyIndividualLinkerClass; - -GType empathy_individual_linker_get_type (void) G_GNUC_CONST; -GtkWidget * empathy_individual_linker_new (FolksIndividual *start_individual); - -FolksIndividual * empathy_individual_linker_get_start_individual ( - EmpathyIndividualLinker *self); -void empathy_individual_linker_set_start_individual ( - EmpathyIndividualLinker *self, - FolksIndividual *individual); - -GeeSet * empathy_individual_linker_get_linked_personas ( - EmpathyIndividualLinker *self); - -gboolean empathy_individual_linker_get_has_changed ( - EmpathyIndividualLinker *self); - -void empathy_individual_linker_set_search_text (EmpathyIndividualLinker *self, - const gchar *search_text); - -G_END_DECLS - -#endif /* __EMPATHY_INDIVIDUAL_LINKER_H__ */ diff --git a/libempathy-gtk/empathy-linking-dialog.c b/libempathy-gtk/empathy-linking-dialog.c deleted file mode 100644 index 350bfdc22..000000000 --- a/libempathy-gtk/empathy-linking-dialog.c +++ /dev/null @@ -1,276 +0,0 @@ -/* - * Copyright (C) 2010 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authors: Philip Withnall <philip.withnall@collabora.co.uk> - */ - -#include <config.h> - -#include <string.h> -#include <stdlib.h> - -#include <gtk/gtk.h> -#include <glib/gi18n-lib.h> - -#include <folks/folks.h> -#include <folks/folks-telepathy.h> - -#include <libempathy/empathy-individual-manager.h> -#include <libempathy/empathy-utils.h> - -#include "empathy-linking-dialog.h" -#include "empathy-individual-linker.h" -#include "empathy-ui-utils.h" - -/** - * SECTION:empathy-individual-widget - * @title:EmpathyLinkingDialog - * @short_description: A dialog used to link individuals together - * @include: libempathy-empathy-linking-dialog.h - * - * #EmpathyLinkingDialog is a dialog which allows selection of individuals to - * link together, and preview of the newly linked individual. When submitted, it - * pushes the new links to backing storage. - */ - -/** - * EmpathyLinkingDialog: - * @parent: parent object - * - * Widget which displays appropriate widgets with details about an individual, - * also allowing changing these details, if desired. - * - * Currently, it's just a thin wrapper around #EmpathyContactWidget, and - * displays the details of the first eligible persona found in the individual. - */ - -static GtkWidget *linking_dialog = NULL; - -/* Fairly arbitrary response ID for the "Unlink" button */ -#define RESPONSE_UNLINK 5 - -#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyLinkingDialog) - -typedef struct { - EmpathyIndividualLinker *linker; /* child widget */ - GtkWidget *link_button; /* child widget */ -} EmpathyLinkingDialogPriv; - -G_DEFINE_TYPE (EmpathyLinkingDialog, empathy_linking_dialog, - GTK_TYPE_DIALOG); - -static void -linker_notify_has_changed_cb (EmpathyIndividualLinker *linker, - GParamSpec *pspec, - EmpathyLinkingDialog *self) -{ - EmpathyLinkingDialogPriv *priv = GET_PRIV (self); - - /* Only make the "Link" button sensitive if the linked Individual has been - * changed. */ - gtk_widget_set_sensitive (priv->link_button, - empathy_individual_linker_get_has_changed (linker)); -} - -static void -empathy_linking_dialog_class_init (EmpathyLinkingDialogClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - g_type_class_add_private (object_class, sizeof (EmpathyLinkingDialogPriv)); -} - -static void -empathy_linking_dialog_init (EmpathyLinkingDialog *self) -{ - EmpathyLinkingDialogPriv *priv; - GtkDialog *dialog; - GtkWidget *button; - GtkBox *content_area; - - priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - EMPATHY_TYPE_LINKING_DIALOG, EmpathyLinkingDialogPriv); - self->priv = priv; - - dialog = GTK_DIALOG (self); - - /* Set up dialog */ - gtk_window_set_resizable (GTK_WINDOW (self), TRUE); - /* Translators: this is the title of the linking dialogue (reached by - * right-clicking on a contact and selecting "Link…"). "Link" in this title - * is a verb. */ - gtk_window_set_title (GTK_WINDOW (self), _("Link Contacts")); - gtk_widget_set_size_request (GTK_WIDGET (self), 600, 500); - - /* Unlink button */ - button = gtk_button_new_with_mnemonic ( - C_("Unlink individual (button)", "_Unlink…")); - gtk_widget_set_tooltip_text (button, _("Completely split the displayed " - "linked contacts into the separate contacts.")); - gtk_dialog_add_action_widget (dialog, button, RESPONSE_UNLINK); - gtk_widget_show (button); - - /* Cancel button */ - button = gtk_button_new_with_label (GTK_STOCK_CANCEL); - gtk_button_set_use_stock (GTK_BUTTON (button), TRUE); - gtk_dialog_add_action_widget (dialog, button, GTK_RESPONSE_CANCEL); - gtk_widget_show (button); - - /* Add button */ - /* Translators: this is an action button in the linking dialogue. "Link" is - * used here as a verb meaning "to connect two contacts to form a - * meta-contact". */ - priv->link_button = gtk_button_new_with_mnemonic (_("_Link")); - gtk_dialog_add_action_widget (dialog, priv->link_button, GTK_RESPONSE_OK); - gtk_widget_show (priv->link_button); - - /* Linker widget */ - priv->linker = - EMPATHY_INDIVIDUAL_LINKER (empathy_individual_linker_new (NULL)); - g_signal_connect (priv->linker, "notify::has-changed", - (GCallback) linker_notify_has_changed_cb, self); - - gtk_container_set_border_width (GTK_CONTAINER (priv->linker), 8); - content_area = GTK_BOX (gtk_dialog_get_content_area (dialog)); - gtk_box_pack_start (content_area, GTK_WIDGET (priv->linker), TRUE, TRUE, 0); - gtk_widget_show (GTK_WIDGET (priv->linker)); -} - -static void -linking_response_cb (EmpathyLinkingDialog *self, - gint response, - gpointer user_data) -{ - EmpathyLinkingDialogPriv *priv = GET_PRIV (self); - - if (response == GTK_RESPONSE_OK) - { - EmpathyIndividualManager *manager; - GeeSet *personas; - - manager = empathy_individual_manager_dup_singleton (); - - personas = empathy_individual_linker_get_linked_personas (priv->linker); - empathy_individual_manager_link_personas (manager, personas); - - g_object_unref (manager); - } - else if (response == RESPONSE_UNLINK) - { - EmpathyIndividualManager *manager; - FolksIndividual *individual; - GtkWidget *dialog; - - individual = - empathy_individual_linker_get_start_individual (priv->linker); - - /* Show a confirmation dialogue first */ - dialog = gtk_message_dialog_new (GTK_WINDOW (self), GTK_DIALOG_MODAL, - GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE, - _("Unlink linked contacts '%s'?"), - folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual))); - gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), - _("Are you sure you want to unlink these linked contacts? This will " - "completely split the linked contacts into separate contacts.")); - gtk_dialog_add_buttons (GTK_DIALOG (dialog), - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - C_("Unlink individual (button)", "_Unlink"), GTK_RESPONSE_OK, - NULL); - - if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK) - { - gtk_widget_destroy (dialog); - return; - } - - gtk_widget_destroy (dialog); - - manager = empathy_individual_manager_dup_singleton (); - empathy_individual_manager_unlink_individual (manager, individual); - g_object_unref (manager); - } - - linking_dialog = NULL; - gtk_widget_destroy (GTK_WIDGET (self)); -} - -/** - * empathy_linking_dialog_show: - * @individual: the #FolksIndividual to start linking against - * @parent: a parent window for the dialogue, or %NULL - * - * Create and show the linking dialogue, with @individual selected as the - * individual to link to. If the dialogue is already being shown, raise it and - * reset it so the start individual is @individual. - * - * Return value: the linking dialog - */ -GtkWidget * -empathy_linking_dialog_show (FolksIndividual *individual, - GtkWindow *parent) -{ - EmpathyLinkingDialogPriv *priv; - GeeSet *personas; - GeeIterator *iter; - guint num_personas = 0; - - /* Create the dialogue if it doesn't exist */ - if (linking_dialog == NULL) - { - linking_dialog = GTK_WIDGET (g_object_new (EMPATHY_TYPE_LINKING_DIALOG, - NULL)); - - g_signal_connect (linking_dialog, "response", - (GCallback) linking_response_cb, NULL); - } - - priv = GET_PRIV (linking_dialog); - - if (parent != NULL) - gtk_window_set_transient_for (GTK_WINDOW (linking_dialog), parent); - - empathy_individual_linker_set_start_individual (priv->linker, individual); - - /* Count how many Telepathy personas we have, to see whether we can - * unlink */ - personas = folks_individual_get_personas (individual); - iter = gee_iterable_iterator (GEE_ITERABLE (personas)); - while (gee_iterator_next (iter)) - { - FolksPersona *persona = gee_iterator_get (iter); - if (empathy_folks_persona_is_interesting (persona)) - num_personas++; - - g_clear_object (&persona); - } - g_clear_object (&iter); - - /* Only make the "Unlink" button sensitive if we have enough personas */ - gtk_dialog_set_response_sensitive (GTK_DIALOG (linking_dialog), - RESPONSE_UNLINK, (num_personas > 1) ? TRUE : FALSE); - - gtk_window_present (GTK_WINDOW (linking_dialog)); - - return linking_dialog; -} - -EmpathyIndividualLinker * -empathy_linking_dialog_get_individual_linker (EmpathyLinkingDialog *self) -{ - g_return_val_if_fail (EMPATHY_IS_LINKING_DIALOG (self), NULL); - - return GET_PRIV (self)->linker; -} diff --git a/libempathy-gtk/empathy-linking-dialog.h b/libempathy-gtk/empathy-linking-dialog.h deleted file mode 100644 index fb47641ca..000000000 --- a/libempathy-gtk/empathy-linking-dialog.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2010 Collabora Ltd. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Authors: Philip Withnall <philip.withnall@collabora.co.uk> - */ - -#ifndef __EMPATHY_LINKING_DIALOG_H__ -#define __EMPATHY_LINKING_DIALOG_H__ - -#include <gtk/gtk.h> - -#include <folks/folks.h> - -#include "empathy-individual-linker.h" - -G_BEGIN_DECLS - -#define EMPATHY_TYPE_LINKING_DIALOG (empathy_linking_dialog_get_type ()) -#define EMPATHY_LINKING_DIALOG(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), \ - EMPATHY_TYPE_LINKING_DIALOG, EmpathyLinkingDialog)) -#define EMPATHY_LINKING_DIALOG_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), \ - EMPATHY_TYPE_LINKING_DIALOG, EmpathyLinkingDialogClass)) -#define EMPATHY_IS_LINKING_DIALOG(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), \ - EMPATHY_TYPE_LINKING_DIALOG)) -#define EMPATHY_IS_LINKING_DIALOG_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), \ - EMPATHY_TYPE_LINKING_DIALOG)) -#define EMPATHY_LINKING_DIALOG_GET_CLASS(o) ( \ - G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_LINKING_DIALOG, \ - EmpathyLinkingDialogClass)) - -typedef struct { - GtkDialog parent; - - /*<private>*/ - gpointer priv; -} EmpathyLinkingDialog; - -typedef struct { - GtkDialogClass parent_class; -} EmpathyLinkingDialogClass; - -GType empathy_linking_dialog_get_type (void) G_GNUC_CONST; - -GtkWidget * empathy_linking_dialog_show (FolksIndividual *individual, - GtkWindow *parent); - -EmpathyIndividualLinker * empathy_linking_dialog_get_individual_linker ( - EmpathyLinkingDialog *self); - -G_END_DECLS - -#endif /* __EMPATHY_LINKING_DIALOG_H__ */ |