From: Danielle Madeley Date: Fri, 14 Oct 2011 04:42:36 +0000 (+1100) Subject: Merge remote-tracking branch 'pochu/upgrade-software' X-Git-Url: https://git.0d.be/?p=empathy.git;a=commitdiff_plain;h=f8148be971e1b51e43374473ab33e5ac8fd14a40;hp=-c Merge remote-tracking branch 'pochu/upgrade-software' --- f8148be971e1b51e43374473ab33e5ac8fd14a40 diff --combined libempathy/empathy-utils.c index 66add2f7,a1047334..9eec82e7 --- a/libempathy/empathy-utils.c +++ b/libempathy/empathy-utils.c @@@ -80,16 -80,6 +80,16 @@@ static struct { NULL, }, }; +static gboolean +properties_contains (gchar **list, + gint length, + const gchar *property); + +static gboolean +check_writeable_property (TpConnection *connection, + FolksIndividual *individual, + gchar *property); + void empathy_init (void) { @@@ -368,6 -358,8 +368,8 @@@ create_errors_to_message_hash (void _("The length of the server certificate, or the depth of the " "server certificate chain, exceed the limits imposed by the " "cryptography library")); + g_hash_table_insert (errors, TP_ERROR_STR_SOFTWARE_UPGRADE_REQUIRED, + _("Your software is too old")); return errors; } @@@ -735,12 -727,6 +737,12 @@@ empathy_contact_dup_from_folks_individu } g_clear_object (&iter); + if (contact == NULL) + { + DEBUG ("Can't create an EmpathyContact for Individual %s", + folks_individual_get_id (individual)); + } + return contact; } @@@ -812,10 -798,10 +814,10 @@@ empathy_connection_can_add_personas (Tp } gboolean -empathy_connection_can_alias_personas (TpConnection *connection) +empathy_connection_can_alias_personas (TpConnection *connection, + FolksIndividual *individual) { gboolean retval; - FolksPersonaStore *persona_store; g_return_val_if_fail (TP_IS_CONNECTION (connection), FALSE); @@@ -823,16 -809,22 +825,16 @@@ TP_CONNECTION_STATUS_CONNECTED) return FALSE; - persona_store = FOLKS_PERSONA_STORE ( - empathy_dup_persona_store_for_connection (connection)); - - retval = (folks_persona_store_get_can_alias_personas (persona_store) == - FOLKS_MAYBE_BOOL_TRUE); - - g_clear_object (&persona_store); + retval = check_writeable_property (connection, individual, "alias"); return retval; } gboolean -empathy_connection_can_group_personas (TpConnection *connection) +empathy_connection_can_group_personas (TpConnection *connection, + FolksIndividual *individual) { gboolean retval; - FolksPersonaStore *persona_store; g_return_val_if_fail (TP_IS_CONNECTION (connection), FALSE); @@@ -840,7 -832,13 +842,7 @@@ TP_CONNECTION_STATUS_CONNECTED) return FALSE; - persona_store = FOLKS_PERSONA_STORE ( - empathy_dup_persona_store_for_connection (connection)); - - retval = (folks_persona_store_get_can_group_personas (persona_store) == - FOLKS_MAYBE_BOOL_TRUE); - - g_clear_object (&persona_store); + retval = check_writeable_property (connection, individual, "groups"); return retval; } @@@ -990,101 -988,3 +992,101 @@@ empathy_account_has_uri_scheme_tel (TpA return FALSE; } + +/* Return the TpContact on @conn associated with @individual, if any */ +TpContact * +empathy_get_tp_contact_for_individual (FolksIndividual *individual, + TpConnection *conn) +{ + TpContact *contact = NULL; + GeeSet *personas; + GeeIterator *iter; + + personas = folks_individual_get_personas (individual); + iter = gee_iterable_iterator (GEE_ITERABLE (personas)); + while (contact == NULL && gee_iterator_next (iter)) + { + TpfPersona *persona = gee_iterator_get (iter); + TpConnection *contact_conn; + TpContact *contact_cur = NULL; + + if (TPF_IS_PERSONA (persona)) + { + contact_cur = tpf_persona_get_contact (persona); + if (contact_cur != NULL) + { + contact_conn = tp_contact_get_connection (contact_cur); + + if (!tp_strdiff (tp_proxy_get_object_path (contact_conn), + tp_proxy_get_object_path (conn))) + contact = contact_cur; + } + } + + g_clear_object (&persona); + } + g_clear_object (&iter); + + return contact; +} + +static gboolean +properties_contains (gchar **list, + gint length, + const gchar *property) +{ + gint i; + + for (i = 0; i < length; i++) + { + if (!tp_strdiff (list[i], property)) + return TRUE; + } + + return FALSE; +} + +static gboolean +check_writeable_property (TpConnection *connection, + FolksIndividual *individual, + gchar *property) +{ + gchar **properties; + gint prop_len; + gboolean retval = FALSE; + GeeSet *personas; + GeeIterator *iter; + FolksPersonaStore *persona_store; + + persona_store = FOLKS_PERSONA_STORE ( + empathy_dup_persona_store_for_connection (connection)); + + properties = + folks_persona_store_get_always_writeable_properties (persona_store, + &prop_len); + retval = properties_contains (properties, prop_len, property); + if (retval == TRUE) + goto out; + + /* Lets see if the Individual contains a Persona with the given property */ + personas = folks_individual_get_personas (individual); + iter = gee_iterable_iterator (GEE_ITERABLE (personas)); + while (!retval && gee_iterator_next (iter)) + { + FolksPersona *persona = gee_iterator_get (iter); + + properties = + folks_persona_get_writeable_properties (persona, &prop_len); + retval = properties_contains (properties, prop_len, property); + + g_clear_object (&persona); + + if (retval == TRUE) + break; + } + g_clear_object (&iter); + +out: + g_clear_object (&persona_store); + return retval; +} diff --combined src/empathy-main-window.c index fda8a960,28198b03..c5f13dfa --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@@ -76,6 -76,7 +76,6 @@@ #include "empathy-chatrooms-window.h" #include "empathy-event-manager.h" #include "empathy-ft-manager.h" -#include "empathy-migrate-butterfly-logs.h" #define DEBUG_FLAG EMPATHY_DEBUG_OTHER #include @@@ -97,11 -98,6 +97,11 @@@ enum PAGE_NO_MATCH }; +enum { + PROP_0, + PROP_SHELL_RUNNING +}; + G_DEFINE_TYPE (EmpathyMainWindow, empathy_main_window, GTK_TYPE_WINDOW); #define GET_PRIV(self) ((EmpathyMainWindowPriv *)((EmpathyMainWindow *) self)->priv) @@@ -168,7 -164,8 +168,7 @@@ struct _EmpathyMainWindowPriv /* Actions that are enabled when there are connected accounts */ GList *actions_connected; - /* The idle event source to migrate butterfly's logs */ - guint butterfly_log_migration_members_changed_id; + gboolean shell_running; }; static void @@@ -555,23 -552,6 +555,23 @@@ main_window_event_removed_cb (EmpathyEv &data); } +static gboolean +main_window_load_events_idle_cb (gpointer user_data) +{ + EmpathyMainWindow *window = user_data; + EmpathyMainWindowPriv *priv = GET_PRIV (window); + GSList *l; + + l = empathy_event_manager_get_events (priv->event_manager); + while (l) { + main_window_event_added_cb (priv->event_manager, l->data, + window); + l = l->next; + } + + return FALSE; +} + static void main_window_row_activated_cb (EmpathyContactListView *view, GtkTreePath *path, @@@ -666,12 -646,6 +666,12 @@@ main_window_row_inserted_cb (GtkTreeMod gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), PAGE_CONTACT_LIST); gtk_widget_grab_focus (GTK_WIDGET (priv->individual_view)); + + /* The store is being filled, it will be done after an idle cb. + * So we can then get events. If we do that too soon, event's + * contact is not yet in the store and it won't get marked as + * having events. */ + g_idle_add (main_window_load_events_idle_cb, window); } } @@@ -734,6 -708,134 +734,134 @@@ main_window_error_close_clicked_cb (Gtk main_window_remove_error (window, account); } + static void + main_window_error_upgrade_sw_clicked_cb (GtkButton *button, + EmpathyMainWindow *window) + { + TpAccount *account; + GtkWidget *dialog; + + account = g_object_get_data (G_OBJECT (button), "account"); + main_window_remove_error (window, account); + + dialog = gtk_message_dialog_new (GTK_WINDOW (window), + GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + _("Sorry, %s accounts can’t be used until your %s software is updated."), + tp_account_get_protocol (account), + tp_account_get_protocol (account)); + + g_signal_connect_swapped (dialog, "response", + G_CALLBACK (gtk_widget_destroy), + dialog); + + gtk_widget_show (dialog); + } + + static void + main_window_upgrade_software_error (EmpathyMainWindow *window, + TpAccount *account) + { + EmpathyMainWindowPriv *priv = GET_PRIV (window); + GtkWidget *info_bar; + GtkWidget *content_area; + GtkWidget *label; + GtkWidget *image; + GtkWidget *upgrade_button; + GtkWidget *close_button; + GtkWidget *action_area; + GtkWidget *action_table; + gchar *str; + const gchar *icon_name; + const gchar *error_message; + gboolean user_requested; + + error_message = + empathy_account_get_error_message (account, &user_requested); + + if (user_requested) { + return; + } + + str = g_markup_printf_escaped ("%s\n%s", + tp_account_get_display_name (account), + error_message); + + /* If there are other errors, remove them */ + main_window_remove_error (window, account); + + info_bar = gtk_info_bar_new (); + gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_ERROR); + + gtk_widget_set_no_show_all (info_bar, TRUE); + gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar, FALSE, TRUE, 0); + gtk_widget_show (info_bar); + + icon_name = tp_account_get_icon_name (account); + image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR); + gtk_widget_show (image); + + label = gtk_label_new (str); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END); + gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); + gtk_widget_show (label); + g_free (str); + + content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar)); + gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0); + + image = gtk_image_new_from_stock (GTK_STOCK_REFRESH, GTK_ICON_SIZE_BUTTON); + upgrade_button = gtk_button_new (); + gtk_button_set_image (GTK_BUTTON (upgrade_button), image); + gtk_widget_set_tooltip_text (upgrade_button, _("Update software...")); + gtk_widget_show (upgrade_button); + + image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON); + close_button = gtk_button_new (); + gtk_button_set_image (GTK_BUTTON (close_button), image); + gtk_widget_set_tooltip_text (close_button, _("Close")); + gtk_widget_show (close_button); + + action_table = gtk_table_new (1, 2, FALSE); + gtk_table_set_col_spacings (GTK_TABLE (action_table), 2); + gtk_widget_show (action_table); + + action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (info_bar)); + gtk_box_pack_start (GTK_BOX (action_area), action_table, FALSE, FALSE, 0); + + gtk_table_attach (GTK_TABLE (action_table), upgrade_button, 0, 1, 0, 1, + (GtkAttachOptions) (GTK_SHRINK), + (GtkAttachOptions) (GTK_SHRINK), 0, 0); + gtk_table_attach (GTK_TABLE (action_table), close_button, 1, 2, 0, 1, + (GtkAttachOptions) (GTK_SHRINK), + (GtkAttachOptions) (GTK_SHRINK), 0, 0); + + g_object_set_data (G_OBJECT (info_bar), "label", label); + g_object_set_data_full (G_OBJECT (info_bar), + "account", g_object_ref (account), + g_object_unref); + g_object_set_data_full (G_OBJECT (upgrade_button), + "account", g_object_ref (account), + g_object_unref); + g_object_set_data_full (G_OBJECT (close_button), + "account", g_object_ref (account), + g_object_unref); + + g_signal_connect (upgrade_button, "clicked", + G_CALLBACK (main_window_error_upgrade_sw_clicked_cb), + window); + g_signal_connect (close_button, "clicked", + G_CALLBACK (main_window_error_close_clicked_cb), + window); + + gtk_widget_set_tooltip_text (priv->errors_vbox, error_message); + gtk_widget_show (priv->errors_vbox); + + g_hash_table_insert (priv->errors, g_object_ref (account), info_bar); + } + static void main_window_error_display (EmpathyMainWindow *window, TpAccount *account) @@@ -753,6 -855,12 +881,12 @@@ const gchar *error_message; gboolean user_requested; + if (!tp_strdiff (TP_ERROR_STR_SOFTWARE_UPGRADE_REQUIRED, + tp_account_get_detailed_error (account, NULL))) { + main_window_upgrade_software_error (window, account); + return; + } + error_message = empathy_account_get_error_message (account, &user_requested); @@@ -1880,8 -1988,7 +2014,8 @@@ empathy_main_window_show_preferences (E EmpathyMainWindowPriv *priv = GET_PRIV (window); if (priv->preferences == NULL) { - priv->preferences = empathy_preferences_new (GTK_WINDOW (window)); + priv->preferences = empathy_preferences_new (GTK_WINDOW (window), + priv->shell_running); g_object_add_weak_pointer (G_OBJECT (priv->preferences), (gpointer) &priv->preferences); @@@ -2011,11 -2118,9 +2145,11 @@@ main_window_connection_items_setup (Emp "room_join_favorites", "chat_new_message", "chat_new_call", + "chat_search_contacts", "chat_add_contact", "edit_personal_information", - "edit_blocked_contacts" + "edit_blocked_contacts", + "edit_search_contacts" }; for (i = 0, list = NULL; i < G_N_ELEMENTS (actions_connected); i++) { @@@ -2037,7 -2142,7 +2171,7 @@@ account_manager_prepared_cb (GObjec EmpathyMainWindowPriv *priv = GET_PRIV (window); GError *error = NULL; - if (!tp_account_manager_prepare_finish (manager, result, &error)) { + if (!tp_proxy_prepare_finish (manager, result, &error)) { DEBUG ("Failed to prepare account manager: %s", error->message); g_error_free (error); return; @@@ -2070,17 -2175,25 +2204,17 @@@ g_list_free (accounts); } -static void -main_window_members_changed_cb (EmpathyContactList *list, - EmpathyContact *contact, - EmpathyContact *actor, - guint reason, - gchar *message, - gboolean is_member, - EmpathyMainWindow *window) +void +empathy_main_window_set_shell_running (EmpathyMainWindow *window, + gboolean shell_running) { EmpathyMainWindowPriv *priv = GET_PRIV (window); - if (!is_member) + if (priv->shell_running == shell_running) return; - if (!empathy_migrate_butterfly_logs (contact)) { - g_signal_handler_disconnect (list, - priv->butterfly_log_migration_members_changed_id); - priv->butterfly_log_migration_members_changed_id = 0; - } + priv->shell_running = shell_running; + g_object_notify (G_OBJECT (window), "shell-running"); } static GObject * @@@ -2101,65 -2214,14 +2235,65 @@@ empathy_main_window_constructor (GType return window; } +static void +empathy_main_window_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + EmpathyMainWindow *self = EMPATHY_MAIN_WINDOW (object); + EmpathyMainWindowPriv *priv = GET_PRIV (self); + + switch (property_id) + { + case PROP_SHELL_RUNNING: + priv->shell_running = g_value_get_boolean (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +empathy_main_window_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + EmpathyMainWindow *self = EMPATHY_MAIN_WINDOW (object); + EmpathyMainWindowPriv *priv = GET_PRIV (self); + + switch (property_id) + { + case PROP_SHELL_RUNNING: + g_value_set_boolean (value, priv->shell_running); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + static void empathy_main_window_class_init (EmpathyMainWindowClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + GParamSpec *pspec; object_class->finalize = empathy_main_window_finalize; object_class->constructor = empathy_main_window_constructor; + object_class->set_property = empathy_main_window_set_property; + object_class->get_property = empathy_main_window_get_property; + + pspec = g_param_spec_boolean ("shell-running", + "Shell running", + "Whether the Shell is running or not", + FALSE, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (object_class, PROP_SHELL_RUNNING, pspec); + g_type_class_add_private (object_class, sizeof (EmpathyMainWindowPriv)); } @@@ -2175,6 -2237,7 +2309,6 @@@ empathy_main_window_init (EmpathyMainWi GtkToolItem *item; gboolean show_offline; gchar *filename; - GSList *l; GtkTreeModel *model; GtkWidget *search_vbox; GtkWidget *menubar; @@@ -2191,10 -2254,6 +2325,10 @@@ gtk_window_set_role (GTK_WINDOW (window), "contact_list"); gtk_window_set_default_size (GTK_WINDOW (window), 225, 325); + /* don't finalize the widget on delete-event, just hide it */ + g_signal_connect (window, "delete-event", + G_CALLBACK (gtk_widget_hide_on_delete), NULL); + /* Set up interface */ filename = empathy_file_lookup ("empathy-main-window.ui", "src"); gui = empathy_builder_get_file (filename, @@@ -2281,7 -2340,7 +2415,7 @@@ priv->account_manager = tp_account_manager_dup (); - tp_account_manager_prepare_async (priv->account_manager, NULL, + tp_proxy_prepare_async (priv->account_manager, NULL, account_manager_prepared_cb, window); priv->errors = g_hash_table_new_full (g_direct_hash, @@@ -2355,6 -2414,10 +2489,6 @@@ EMPATHY_INDIVIDUAL_VIEW_FEATURE_ALL ^ EMPATHY_INDIVIDUAL_VIEW_FEATURE_PERSONA_DROP, EMPATHY_INDIVIDUAL_FEATURE_ALL); - priv->butterfly_log_migration_members_changed_id = g_signal_connect ( - priv->contact_manager, "members-changed", - G_CALLBACK (main_window_members_changed_cb), window); - gtk_widget_show (GTK_WIDGET (priv->individual_view)); gtk_container_add (GTK_CONTAINER (sw), GTK_WIDGET (priv->individual_view)); @@@ -2415,6 -2478,13 +2549,6 @@@ G_CALLBACK (main_window_account_disabled_cb), window); - l = empathy_event_manager_get_events (priv->event_manager); - while (l) { - main_window_event_added_cb (priv->event_manager, l->data, - window); - l = l->next; - } - /* Show offline ? */ show_offline = g_settings_get_boolean (priv->gsettings_ui, EMPATHY_PREFS_UI_SHOW_OFFLINE);