static gboolean contact_list_store_contact_active_cb (ShowActiveData *data) { EmpathyContactListStorePriv *priv; priv = GET_PRIV (data->store); if (data->remove && !priv->show_offline && !empathy_contact_is_online (data->contact)) { DEBUG ("Contact:'%s' active timeout, removing item", empathy_contact_get_name (data->contact)); contact_list_store_remove_contact (data->store, data->contact); } DEBUG ("Contact:'%s' no longer active", empathy_contact_get_name (data->contact)); contact_list_store_contact_set_active (data->store, data->contact, FALSE, TRUE); contact_list_store_contact_active_free (data); return FALSE; }
static void contact_widget_name_notify_cb (EmpathyContactWidget *information) { if (GTK_IS_ENTRY (information->widget_alias)) gtk_entry_set_text (GTK_ENTRY (information->widget_alias), empathy_contact_get_name (information->contact)); else gtk_label_set_label (GTK_LABEL (information->widget_alias), empathy_contact_get_name (information->contact)); }
static void contact_list_view_remove_activate_cb (GtkMenuItem *menuitem, EmpathyContactListView *view) { EmpathyContactListViewPriv *priv = GET_PRIV (view); EmpathyContact *contact; contact = empathy_contact_list_view_get_selected (view); if (contact) { gchar *text; GtkWindow *parent; parent = empathy_get_toplevel_window (GTK_WIDGET (view)); text = g_strdup_printf (_("Do you really want to remove the contact '%s'?"), empathy_contact_get_name (contact)); if (contact_list_view_remove_dialog_show (parent, _("Removing contact"), text)) { EmpathyContactList *list; list = empathy_contact_list_store_get_list_iface (priv->store); empathy_contact_list_remove (list, contact, _("Sorry, I don't want you in my contact list anymore.")); } g_free (text); g_object_unref (contact); } }
static void ft_manager_stop (EmpathyFTManager *manager) { GtkTreeSelection *selection; GtkTreeIter iter; GtkTreeModel *model; EmpathyFTHandler *handler; EmpathyFTManagerPriv *priv; priv = GET_PRIV (manager); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)); if (!gtk_tree_selection_get_selected (selection, &model, &iter)) return; gtk_tree_model_get (model, &iter, COL_FT_OBJECT, &handler, -1); g_return_if_fail (handler != NULL); DEBUG ("Stopping file transfer: contact=%s, filename=%s", empathy_contact_get_name (empathy_ft_handler_get_contact (handler)), empathy_ft_handler_get_filename (handler)); empathy_ft_handler_cancel_transfer (handler); g_object_unref (handler); }
static void theme_boxes_append_message (EmpathyChatTextView *view, EmpathyMessage *message) { EmpathyContact *sender; theme_boxes_maybe_append_header (EMPATHY_THEME_BOXES (view), message); sender = empathy_message_get_sender (message); if (empathy_message_get_tptype (message) == TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION) { gchar *body; body = g_strdup_printf (" * %s %s", empathy_contact_get_name (sender), empathy_message_get_body (message)); empathy_chat_text_view_append_body (EMPATHY_CHAT_TEXT_VIEW (view), body, EMPATHY_CHAT_TEXT_VIEW_TAG_ACTION); } else { empathy_chat_text_view_append_body (EMPATHY_CHAT_TEXT_VIEW (view), empathy_message_get_body (message), EMPATHY_CHAT_TEXT_VIEW_TAG_BODY); } }
void empathy_contact_information_dialog_show (EmpathyContact *contact, GtkWindow *parent) { GtkWidget *dialog; GtkWidget *button; GtkWidget *contact_widget; GList *l; g_return_if_fail (EMPATHY_IS_CONTACT (contact)); l = g_list_find_custom (information_dialogs, contact, (GCompareFunc) contact_dialogs_find); if (l) { gtk_window_present (GTK_WINDOW (l->data)); return; } /* Create dialog */ dialog = gtk_dialog_new (); gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); gtk_window_set_title (GTK_WINDOW (dialog), empathy_contact_get_name (contact)); /* Close button */ button = gtk_button_new_with_label (GTK_STOCK_CLOSE); gtk_button_set_use_stock (GTK_BUTTON (button), TRUE); gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, GTK_RESPONSE_CLOSE); GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); gtk_window_set_default (GTK_WINDOW (dialog), button); gtk_widget_show (button); /* Contact info widget */ contact_widget = empathy_contact_widget_new (contact, EMPATHY_CONTACT_WIDGET_SHOW_LOCATION | EMPATHY_CONTACT_WIDGET_EDIT_NONE); gtk_container_set_border_width (GTK_CONTAINER (contact_widget), 8); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), contact_widget, TRUE, TRUE, 0); gtk_widget_show (contact_widget); g_object_set_data (G_OBJECT (dialog), "contact_widget", contact_widget); information_dialogs = g_list_prepend (information_dialogs, dialog); g_signal_connect (dialog, "response", G_CALLBACK (contact_dialogs_response_cb), &information_dialogs); if (parent) { gtk_window_set_transient_for (GTK_WINDOW (dialog), parent); } gtk_widget_show (dialog); }
static void contact_list_store_contact_updated_cb (EmpathyContact *contact, GParamSpec *param, EmpathyContactListStore *store) { DEBUG ("Contact:'%s' updated, checking roster is in sync...", empathy_contact_get_name (contact)); contact_list_store_contact_update (store, contact); }
static void contact_monitor_name_changed_cb (EmpathyContact *contact, GParamSpec *pspec, EmpathyContactMonitor *self) { const char *name; name = empathy_contact_get_name (contact); g_signal_emit (self, signals[CONTACT_NAME_CHANGED], 0, contact, name); }
static void do_real_transfer_done (EmpathyFTManager *manager, EmpathyFTHandler *handler) { const char *contact_name; const char *filename; char *first_line, *second_line, *message; char *uri; gboolean incoming; GtkTreeRowReference *row_ref; GtkRecentManager *recent_manager; GFile *file; row_ref = ft_manager_get_row_from_handler (manager, handler); g_return_if_fail (row_ref != NULL); incoming = empathy_ft_handler_is_incoming (handler); contact_name = empathy_contact_get_name (empathy_ft_handler_get_contact (handler)); filename = empathy_ft_handler_get_filename (handler); if (incoming) /* translators: first %s is filename, second %s * is the contact name */ first_line = g_strdup_printf (_("\"%s\" received from %s"), filename, contact_name); else /* translators: first %s is filename, second %s * is the contact name */ first_line = g_strdup_printf (_("\"%s\" sent to %s"), filename, contact_name); second_line = g_strdup (_("File transfer completed")); message = g_strdup_printf ("%s\n%s", first_line, second_line); ft_manager_update_handler_message (manager, row_ref, message); ft_manager_clear_handler_time (manager, row_ref); /* update buttons */ ft_manager_update_buttons (manager); g_free (message); g_free (first_line); g_free (second_line); recent_manager = gtk_recent_manager_get_default (); file = empathy_ft_handler_get_gfile (handler); uri = g_file_get_uri (file); gtk_recent_manager_add_item (recent_manager, uri); g_free (uri); }
static const gchar * chat_window_get_chat_name (EmpathyChat *chat) { EmpathyContact *remote_contact = NULL; const gchar *name = NULL; name = empathy_chat_get_name (chat); if (!name) { remote_contact = empathy_chat_get_remote_contact (chat); if (remote_contact) { name = empathy_contact_get_name (remote_contact); } } return name ? name : _("Conversation"); }
static void ft_manager_remove_file_from_model (EmpathyFTManager *manager, EmpathyFTHandler *handler) { GtkTreeRowReference *row_ref; GtkTreeSelection *selection; GtkTreePath *path = NULL; GtkTreeIter iter; gboolean update_selection; EmpathyFTManagerPriv *priv = GET_PRIV (manager); row_ref = ft_manager_get_row_from_handler (manager, handler); g_return_if_fail (row_ref); DEBUG ("Removing file transfer from window: contact=%s, filename=%s", empathy_contact_get_name (empathy_ft_handler_get_contact (handler)), empathy_ft_handler_get_filename (handler)); /* Get the iter from the row_ref */ path = gtk_tree_row_reference_get_path (row_ref); gtk_tree_model_get_iter (priv->model, &iter, path); gtk_tree_path_free (path); /* We have to update the selection only if we are removing the selected row */ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)); update_selection = gtk_tree_selection_iter_is_selected (selection, &iter); /* Remove tp_file's row. After that iter points to the next row */ if (!gtk_list_store_remove (GTK_LIST_STORE (priv->model), &iter)) { gint n_row; /* There is no next row, set iter to the last row */ n_row = gtk_tree_model_iter_n_children (priv->model, NULL); if (n_row > 0) gtk_tree_model_iter_nth_child (priv->model, &iter, NULL, n_row - 1); else update_selection = FALSE; } if (update_selection) gtk_tree_selection_select_iter (selection, &iter); }
static ShowActiveData * contact_list_store_contact_active_new (EmpathyContactListStore *store, EmpathyContact *contact, gboolean remove) { ShowActiveData *data; DEBUG ("Contact:'%s' now active, and %s be removed", empathy_contact_get_name (contact), remove ? "WILL" : "WILL NOT"); data = g_slice_new0 (ShowActiveData); data->store = g_object_ref (store); data->contact = g_object_ref (contact); data->remove = remove; return data; }
static gchar * ft_manager_format_error_message (EmpathyFTHandler *handler, const GError *error) { const char *contact_name, *filename; EmpathyContact *contact; char *first_line, *message; gboolean incoming; contact_name = NULL; incoming = empathy_ft_handler_is_incoming (handler); contact = empathy_ft_handler_get_contact (handler); if (contact) contact_name = empathy_contact_get_name (contact); filename = empathy_ft_handler_get_filename (handler); if (incoming) /* filename/contact_name here are either both NULL or both valid */ if (filename && contact_name) /* translators: first %s is filename, second %s * is the contact name */ first_line = g_strdup_printf (_("Error receiving \"%s\" from %s"), filename, contact_name); else first_line = g_strdup (_("Error receiving a file")); else /* translators: first %s is filename, second %s * is the contact name */ if (filename && contact_name) first_line = g_strdup_printf (_("Error sending \"%s\" to %s"), filename, contact_name); else first_line = g_strdup (_("Error sending a file")); message = g_strdup_printf ("%s\n%s", first_line, error->message); g_free (first_line); return message; }
static void tp_chat_state_changed_got_contact_cb (EmpathyTpContactFactory *factory, EmpathyContact *contact, const GError *error, gpointer user_data, GObject *chat) { TpChannelChatState state; if (error) { DEBUG ("Error: %s", error->message); return; } state = GPOINTER_TO_UINT (user_data); DEBUG ("Chat state changed for %s (%d): %d", empathy_contact_get_name (contact), empathy_contact_get_handle (contact), state); g_signal_emit (chat, signals[CHAT_STATE_CHANGED], 0, contact, state); }
static void megaphone_applet_update_contact (MegaphoneApplet *applet) { MegaphoneAppletPriv *priv = GET_PRIV (applet); const gchar *name; const gchar *status; gchar *tip; const gchar *avatar_token = NULL; if (priv->contact) { EmpathyAvatar *avatar; avatar = empathy_contact_get_avatar (priv->contact); if (avatar) { avatar_token = avatar->token; } } if (avatar_token) { panel_applet_gconf_set_string (PANEL_APPLET (applet), "avatar_token", avatar_token, NULL); } megaphone_applet_update_icon (applet); if (priv->contact ) { name = empathy_contact_get_name (priv->contact); status = empathy_contact_get_status (priv->contact); tip = g_strdup_printf ("<b>%s</b>: %s", name, status); gtk_widget_set_tooltip_markup (GTK_WIDGET (applet), tip); g_free (tip); } else { gtk_widget_set_tooltip_markup (GTK_WIDGET (applet), _("Please configure a contact.")); } }
static gchar * ft_manager_format_contact_info (EmpathyFTHandler *handler) { gboolean incoming; const char *filename, *contact_name, *first_line_format; char *retval; incoming = empathy_ft_handler_is_incoming (handler); contact_name = empathy_contact_get_name (empathy_ft_handler_get_contact (handler)); filename = empathy_ft_handler_get_filename (handler); if (incoming) /* translators: first %s is filename, second %s is the contact name */ first_line_format = _("Receiving \"%s\" from %s"); else /* translators: first %s is filename, second %s is the contact name */ first_line_format = _("Sending \"%s\" to %s"); retval = g_strdup_printf (first_line_format, filename, contact_name); return retval; }
static void contact_list_store_add_contact (EmpathyContactListStore *store, EmpathyContact *contact) { EmpathyContactListStorePriv *priv; GtkTreeIter iter; GList *groups = NULL, *l; TpConnection *connection; EmpathyContactListFlags flags = 0; priv = GET_PRIV (store); if (EMP_STR_EMPTY (empathy_contact_get_name (contact)) || (!priv->show_offline && !empathy_contact_is_online (contact))) { return; } if (priv->show_groups) { groups = empathy_contact_list_get_groups (priv->list, contact); } connection = empathy_contact_get_connection (contact); if (EMPATHY_IS_CONTACT_MANAGER (priv->list)) { flags = empathy_contact_manager_get_flags_for_connection ( EMPATHY_CONTACT_MANAGER (priv->list), connection); } /* If no groups just add it at the top level. */ if (!groups) { GtkTreeModel *model = GTK_TREE_MODEL (store); if (gtk_tree_model_get_iter_first (model, &iter)) do { EmpathyContact *c; gtk_tree_model_get (model, &iter, EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &c, -1); if (c == contact) { g_object_unref (c); return; } if (c != NULL) g_object_unref (c); } while (gtk_tree_model_iter_next (model, &iter)); gtk_tree_store_append (GTK_TREE_STORE (store), &iter, NULL); gtk_tree_store_set (GTK_TREE_STORE (store), &iter, EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact), EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, contact, EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE, EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE, EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL, empathy_contact_get_capabilities (contact) & EMPATHY_CAPABILITIES_AUDIO, EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL, empathy_contact_get_capabilities (contact) & EMPATHY_CAPABILITIES_VIDEO, EMPATHY_CONTACT_LIST_STORE_COL_FLAGS, flags, -1); } /* Else add to each group. */ for (l = groups; l; l = l->next) { GtkTreeIter iter_group; contact_list_store_get_group (store, l->data, &iter_group, NULL, NULL); gtk_tree_store_insert_after (GTK_TREE_STORE (store), &iter, &iter_group, NULL); gtk_tree_store_set (GTK_TREE_STORE (store), &iter, EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact), EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, contact, EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE, EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE, EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL, empathy_contact_get_capabilities (contact) & EMPATHY_CAPABILITIES_AUDIO, EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL, empathy_contact_get_capabilities (contact) & EMPATHY_CAPABILITIES_VIDEO, EMPATHY_CONTACT_LIST_STORE_COL_FLAGS, flags, -1); g_free (l->data); } g_list_free (groups); contact_list_store_contact_update (store, contact); }
static void contact_widget_location_update (EmpathyContactWidget *information) { GHashTable *location; GValue *value; gdouble lat = 0.0, lon = 0.0; gboolean has_position = TRUE; GtkWidget *label; guint row = 0; GHashTableIter iter; gpointer key, pvalue; if (!(information->flags & EMPATHY_CONTACT_WIDGET_SHOW_LOCATION)) { gtk_widget_hide (information->vbox_location); return; } location = empathy_contact_get_location (information->contact); if (location == NULL || g_hash_table_size (location) == 0) { gtk_widget_hide (information->vbox_location); return; } value = g_hash_table_lookup (location, EMPATHY_LOCATION_LAT); if (value == NULL) has_position = FALSE; else lat = g_value_get_double (value); value = g_hash_table_lookup (location, EMPATHY_LOCATION_LON); if (value == NULL) has_position = FALSE; else lon = g_value_get_double (value); value = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP); if (value == NULL) gtk_label_set_markup (GTK_LABEL (information->label_location), _("<b>Location</b>")); else { gchar *user_date; gchar *text; gint64 stamp; time_t time; stamp = g_value_get_int64 (value); time = stamp; user_date = empathy_time_to_string_relative (time); text = g_strconcat ( _("<b>Location</b>, "), user_date, NULL); gtk_label_set_markup (GTK_LABEL (information->label_location), text); g_free (text); } /* Prepare the location information table */ if (information->table_location != NULL) { gtk_widget_destroy (information->table_location); } information->table_location = gtk_table_new (1, 2, FALSE); gtk_box_pack_start (GTK_BOX (information->subvbox_location), information->table_location, FALSE, FALSE, 5); g_hash_table_iter_init (&iter, location); while (g_hash_table_iter_next (&iter, &key, &pvalue)) { const gchar *skey; const gchar* user_label; GValue *gvalue; char *svalue = NULL; skey = (const gchar *) key; user_label = location_key_to_label (skey); gvalue = (GValue *) pvalue; label = gtk_label_new (user_label); gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); gtk_table_attach (GTK_TABLE (information->table_location), label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 10, 0); gtk_widget_show (label); if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE) { gdouble dvalue; dvalue = g_value_get_double (gvalue); svalue = g_strdup_printf ("%f", dvalue); } else if (G_VALUE_TYPE (gvalue) == G_TYPE_STRING) { svalue = g_value_dup_string (gvalue); } else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64) { time_t time; time = g_value_get_int64 (value); svalue = empathy_time_to_string_utc (time, _("%B %e, %Y at %R UTC")); } if (svalue != NULL) { label = gtk_label_new (svalue); gtk_table_attach_defaults (GTK_TABLE (information->table_location), label, 1, 2, row, row + 1); gtk_misc_set_alignment (GTK_MISC (label), 0, 0); gtk_widget_show (label); } g_free (svalue); row++; } gtk_widget_show (information->table_location); #if HAVE_LIBCHAMPLAIN /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such * windows */ if (has_position && !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) { ClutterActor *marker; ChamplainLayer *layer; information->map_view_embed = gtk_champlain_embed_new (); information->map_view = gtk_champlain_embed_get_view ( GTK_CHAMPLAIN_EMBED (information->map_view_embed)); gtk_container_add (GTK_CONTAINER (information->viewport_map), information->map_view_embed); g_object_set (G_OBJECT (information->map_view), "show-license", FALSE, "scroll-mode", CHAMPLAIN_SCROLL_MODE_KINETIC, NULL); layer = champlain_layer_new (); champlain_view_add_layer (information->map_view, layer); marker = champlain_marker_new_with_text ( empathy_contact_get_name (information->contact), NULL, NULL, NULL); champlain_base_marker_set_position (CHAMPLAIN_BASE_MARKER (marker), lat, lon); clutter_container_add (CLUTTER_CONTAINER (layer), marker, NULL); champlain_view_center_on (information->map_view, lat, lon); gtk_widget_show_all (information->viewport_map); } #endif gtk_widget_show (information->vbox_location); }
static void theme_boxes_maybe_append_header (EmpathyThemeBoxes *theme, EmpathyMessage *msg) { EmpathyChatTextView *view = EMPATHY_CHAT_TEXT_VIEW (theme); EmpathyThemeBoxesPriv*priv = GET_PRIV (theme); EmpathyContact *contact; EmpathyContact *last_contact; GdkPixbuf *avatar = NULL; GtkTextBuffer *buffer; const gchar *name; GtkTextIter iter; GtkWidget *label1, *label2; GtkTextChildAnchor *anchor; GtkWidget *box; gchar *str; time_t time_; gchar *tmp; GtkTextIter start; gboolean color_set; GtkTextTagTable *table; GtkTextTag *tag; GString *str_obj; contact = empathy_message_get_sender (msg); name = empathy_contact_get_name (contact); last_contact = empathy_chat_text_view_get_last_contact (view); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (theme)); DEBUG ("Maybe add fancy header"); /* Only insert a header if the previously inserted block is not the same * as this one. */ if (empathy_contact_equal (last_contact, contact)) { return; } empathy_chat_text_view_append_spacing (view); /* Insert header line */ gtk_text_buffer_get_end_iter (buffer, &iter); gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "\n", -1, EMPATHY_THEME_BOXES_TAG_HEADER_LINE, NULL); gtk_text_buffer_get_end_iter (buffer, &iter); anchor = gtk_text_buffer_create_child_anchor (buffer, &iter); /* Create a hbox for the header and resize it when the view allocation * changes */ box = gtk_hbox_new (FALSE, 0); g_signal_connect_object (view, "size-allocate", G_CALLBACK (table_size_allocate_cb), box, 0); /* Add avatar to the box if needed */ if (priv->show_avatars) { avatar = theme_boxes_get_avatar_pixbuf_with_cache (contact); if (avatar) { GtkWidget *image; image = gtk_image_new_from_pixbuf (avatar); gtk_box_pack_start (GTK_BOX (box), image, FALSE, TRUE, 2); } } /* Add contact alias */ str = g_markup_printf_escaped ("<b>%s</b>", name); label1 = g_object_new (GTK_TYPE_LABEL, "label", str, "use-markup", TRUE, "xalign", 0.0, NULL); g_free (str); /* Add the message receive time */ time_ = empathy_message_get_timestamp (msg); tmp = empathy_time_to_string_local (time_, EMPATHY_TIME_FORMAT_DISPLAY_SHORT); str = g_strdup_printf ("<i>%s</i>", tmp); label2 = g_object_new (GTK_TYPE_LABEL, "label", str, "use-markup", TRUE, "xalign", 1.0, NULL); str_obj = g_string_new ("\n- "); g_string_append (str_obj, name); g_string_append (str_obj, ", "); g_string_append (str_obj, tmp); g_string_append (str_obj, " -"); g_free (tmp); g_free (str); /* Set foreground color of labels to the same color than the header tag. */ table = gtk_text_buffer_get_tag_table (buffer); tag = gtk_text_tag_table_lookup (table, EMPATHY_THEME_BOXES_TAG_HEADER); g_object_get (tag, "foreground-set", &color_set, NULL); if (color_set) { GdkColor *color; g_object_get (tag, "foreground-gdk", &color, NULL); gtk_widget_modify_fg (label1, GTK_STATE_NORMAL, color); gtk_widget_modify_fg (label2, GTK_STATE_NORMAL, color); gdk_color_free (color); } /* Pack labels into the box */ gtk_misc_set_alignment (GTK_MISC (label1), 0.0, 0.5); gtk_misc_set_alignment (GTK_MISC (label2), 1.0, 0.5); gtk_box_pack_start (GTK_BOX (box), label1, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (box), label2, TRUE, TRUE, 0); /* Add the header box to the text view */ g_object_set_data_full (G_OBJECT (box), "str_obj", g_string_free (str_obj, FALSE), g_free); gtk_text_view_add_child_at_anchor (GTK_TEXT_VIEW (view), box, anchor); gtk_widget_show_all (box); /* Insert a header line */ gtk_text_buffer_get_end_iter (buffer, &iter); start = iter; gtk_text_iter_backward_char (&start); gtk_text_buffer_apply_tag_by_name (buffer, EMPATHY_THEME_BOXES_TAG_HEADER, &start, &iter); gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "\n", -1, EMPATHY_THEME_BOXES_TAG_HEADER, NULL); gtk_text_buffer_get_end_iter (buffer, &iter); gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "\n", -1, EMPATHY_THEME_BOXES_TAG_HEADER_LINE, NULL); }
void empathy_log_manager_add_message (EmpathyLogManager *manager, const gchar *chat_id, gboolean chatroom, EmpathyMessage *message) { FILE *file; McAccount *account; EmpathyContact *sender; const gchar *body_str; const gchar *str; EmpathyAvatar *avatar; gchar *avatar_token = NULL; gchar *filename; gchar *basedir; gchar *body; gchar *timestamp; gchar *contact_name; gchar *contact_id; TpChannelTextMessageType msg_type; g_return_if_fail (EMPATHY_IS_LOG_MANAGER (manager)); g_return_if_fail (chat_id != NULL); g_return_if_fail (EMPATHY_IS_MESSAGE (message)); sender = empathy_message_get_sender (message); account = empathy_contact_get_account (sender); body_str = empathy_message_get_body (message); msg_type = empathy_message_get_tptype (message); if (EMP_STR_EMPTY (body_str)) { return; } filename = log_manager_get_filename (manager, account, chat_id, chatroom); basedir = g_path_get_dirname (filename); if (!g_file_test (basedir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { DEBUG ("Creating directory:'%s'", basedir); g_mkdir_with_parents (basedir, LOG_DIR_CREATE_MODE); } g_free (basedir); DEBUG ("Adding message: '%s' to file: '%s'", body_str, filename); if (!g_file_test (filename, G_FILE_TEST_EXISTS)) { file = g_fopen (filename, "w+"); if (file) { g_fprintf (file, LOG_HEADER); } g_chmod (filename, LOG_FILE_CREATE_MODE); } else { file = g_fopen (filename, "r+"); if (file) { fseek (file, - strlen (LOG_FOOTER), SEEK_END); } } body = g_markup_escape_text (body_str, -1); timestamp = log_manager_get_timestamp_from_message (message); str = empathy_contact_get_name (sender); contact_name = g_markup_escape_text (str, -1); str = empathy_contact_get_id (sender); contact_id = g_markup_escape_text (str, -1); avatar = empathy_contact_get_avatar (sender); if (avatar) { avatar_token = g_markup_escape_text (avatar->token, -1); } g_fprintf (file, "<message time='%s' id='%s' name='%s' token='%s' isuser='******' type='%s'>%s</message>\n" LOG_FOOTER, timestamp, contact_id, contact_name, avatar_token ? avatar_token : "", empathy_contact_is_user (sender) ? "true" : "false", empathy_message_type_to_str (msg_type), body); fclose (file); g_free (filename); g_free (contact_id); g_free (contact_name); g_free (timestamp); g_free (body); g_free (avatar_token); }
static void contact_widget_location_update (EmpathyContactWidget *information) { GHashTable *location; GValue *value; gdouble lat = 0.0, lon = 0.0; gboolean has_position = TRUE; GtkWidget *label; guint row = 0; static const gchar* ordered_geolocation_keys[] = { EMPATHY_LOCATION_TEXT, EMPATHY_LOCATION_URI, EMPATHY_LOCATION_DESCRIPTION, EMPATHY_LOCATION_BUILDING, EMPATHY_LOCATION_FLOOR, EMPATHY_LOCATION_ROOM, EMPATHY_LOCATION_STREET, EMPATHY_LOCATION_AREA, EMPATHY_LOCATION_LOCALITY, EMPATHY_LOCATION_REGION, EMPATHY_LOCATION_COUNTRY, NULL }; int i; const gchar *skey; gboolean display_map = FALSE; if (!(information->flags & EMPATHY_CONTACT_WIDGET_SHOW_LOCATION)) { gtk_widget_hide (information->vbox_location); return; } location = empathy_contact_get_location (information->contact); if (location == NULL || g_hash_table_size (location) == 0) { gtk_widget_hide (information->vbox_location); return; } value = g_hash_table_lookup (location, EMPATHY_LOCATION_LAT); if (value == NULL) has_position = FALSE; else lat = g_value_get_double (value); value = g_hash_table_lookup (location, EMPATHY_LOCATION_LON); if (value == NULL) has_position = FALSE; else lon = g_value_get_double (value); value = g_hash_table_lookup (location, EMPATHY_LOCATION_TIMESTAMP); if (value == NULL) { gchar *loc = g_strdup_printf ("<b>%s</b>", _("Location")); gtk_label_set_markup (GTK_LABEL (information->label_location), loc); g_free (loc); } else { gchar *user_date; gchar *text; gint64 stamp; time_t time_; stamp = g_value_get_int64 (value); time_ = stamp; user_date = empathy_time_to_string_relative (time_); text = g_strconcat ( _("<b>Location</b>, "), user_date, NULL); gtk_label_set_markup (GTK_LABEL (information->label_location), text); g_free (text); } /* Prepare the location information table */ if (information->table_location != NULL) { gtk_widget_destroy (information->table_location); } information->table_location = gtk_table_new (1, 2, FALSE); gtk_box_pack_start (GTK_BOX (information->subvbox_location), information->table_location, FALSE, FALSE, 5); for (i = 0; (skey = ordered_geolocation_keys[i]); i++) { const gchar* user_label; GValue *gvalue; char *svalue = NULL; gvalue = g_hash_table_lookup (location, (gpointer) skey); if (gvalue == NULL) continue; user_label = location_key_to_label (skey); label = gtk_label_new (user_label); gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); gtk_table_attach (GTK_TABLE (information->table_location), label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 10, 0); gtk_widget_show (label); if (G_VALUE_TYPE (gvalue) == G_TYPE_DOUBLE) { gdouble dvalue; dvalue = g_value_get_double (gvalue); svalue = g_strdup_printf ("%f", dvalue); } else if (G_VALUE_TYPE (gvalue) == G_TYPE_STRING) { svalue = g_value_dup_string (gvalue); } else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64) { time_t time_; time_ = g_value_get_int64 (value); svalue = empathy_time_to_string_utc (time_, _("%B %e, %Y at %R UTC")); } if (svalue != NULL) { label = gtk_label_new (svalue); gtk_table_attach_defaults (GTK_TABLE (information->table_location), label, 1, 2, row, row + 1); gtk_misc_set_alignment (GTK_MISC (label), 0, 0); gtk_widget_show (label); if (!(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) gtk_label_set_selectable (GTK_LABEL (label), TRUE); } g_free (svalue); row++; } #if HAVE_LIBCHAMPLAIN if (has_position && !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP)) { /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such * windows */ display_map = TRUE; } #endif if (row > 0) { /* We can display some fields */ gtk_widget_show (information->table_location); } else if (!display_map) { /* Can't display either fields or map */ gtk_widget_hide (information->vbox_location); return; } #if HAVE_LIBCHAMPLAIN if (display_map) { ClutterActor *marker; ChamplainLayer *layer; information->map_view_embed = gtk_champlain_embed_new (); information->map_view = gtk_champlain_embed_get_view ( GTK_CHAMPLAIN_EMBED (information->map_view_embed)); gtk_container_add (GTK_CONTAINER (information->viewport_map), information->map_view_embed); g_object_set (G_OBJECT (information->map_view), "show-license", TRUE, "scroll-mode", CHAMPLAIN_SCROLL_MODE_KINETIC, "zoom-level", 10, NULL); layer = champlain_layer_new (); champlain_view_add_layer (information->map_view, layer); marker = champlain_marker_new_with_text ( empathy_contact_get_name (information->contact), NULL, NULL, NULL); champlain_base_marker_set_position (CHAMPLAIN_BASE_MARKER (marker), lat, lon); clutter_container_add (CLUTTER_CONTAINER (layer), marker, NULL); champlain_view_center_on (information->map_view, lat, lon); gtk_widget_show_all (information->viewport_map); } #endif gtk_widget_show (information->vbox_location); }
static void contact_list_store_contact_update (EmpathyContactListStore *store, EmpathyContact *contact) { EmpathyContactListStorePriv *priv; ShowActiveData *data; GtkTreeModel *model; GList *iters, *l; gboolean in_list; gboolean should_be_in_list; gboolean was_online = TRUE; gboolean now_online = FALSE; gboolean set_model = FALSE; gboolean do_remove = FALSE; gboolean do_set_active = FALSE; gboolean do_set_refresh = FALSE; gboolean show_avatar = FALSE; GdkPixbuf *pixbuf_avatar; priv = GET_PRIV (store); model = GTK_TREE_MODEL (store); iters = contact_list_store_find_contact (store, contact); if (!iters) { in_list = FALSE; } else { in_list = TRUE; } /* Get online state now. */ now_online = empathy_contact_is_online (contact); if (priv->show_offline || now_online) { should_be_in_list = TRUE; } else { should_be_in_list = FALSE; } if (!in_list && !should_be_in_list) { /* Nothing to do. */ DEBUG ("Contact:'%s' in list:NO, should be:NO", empathy_contact_get_name (contact)); g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL); g_list_free (iters); return; } else if (in_list && !should_be_in_list) { DEBUG ("Contact:'%s' in list:YES, should be:NO", empathy_contact_get_name (contact)); if (priv->show_active) { do_remove = TRUE; do_set_active = TRUE; do_set_refresh = TRUE; set_model = TRUE; DEBUG ("Remove item (after timeout)"); } else { DEBUG ("Remove item (now)!"); contact_list_store_remove_contact (store, contact); } } else if (!in_list && should_be_in_list) { DEBUG ("Contact:'%s' in list:NO, should be:YES", empathy_contact_get_name (contact)); contact_list_store_add_contact (store, contact); if (priv->show_active) { do_set_active = TRUE; DEBUG ("Set active (contact added)"); } } else { DEBUG ("Contact:'%s' in list:YES, should be:YES", empathy_contact_get_name (contact)); /* Get online state before. */ if (iters && g_list_length (iters) > 0) { gtk_tree_model_get (model, iters->data, EMPATHY_CONTACT_LIST_STORE_COL_IS_ONLINE, &was_online, -1); } /* Is this really an update or an online/offline. */ if (priv->show_active) { if (was_online != now_online) { do_set_active = TRUE; do_set_refresh = TRUE; DEBUG ("Set active (contact updated %s)", was_online ? "online -> offline" : "offline -> online"); } else { /* Was TRUE for presence updates. */ /* do_set_active = FALSE; */ do_set_refresh = TRUE; DEBUG ("Set active (contact updated)"); } } set_model = TRUE; } if (priv->show_avatars && !priv->is_compact) { show_avatar = TRUE; } pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact, 32, 32); for (l = iters; l && set_model; l = l->next) { gtk_tree_store_set (GTK_TREE_STORE (store), l->data, EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, empathy_icon_name_for_contact (contact), EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR, pixbuf_avatar, EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar, EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact), EMPATHY_CONTACT_LIST_STORE_COL_STATUS, empathy_contact_get_status (contact), EMPATHY_CONTACT_LIST_STORE_COL_STATUS_VISIBLE, !priv->is_compact, EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE, EMPATHY_CONTACT_LIST_STORE_COL_IS_ONLINE, now_online, EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE, EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL, empathy_contact_get_capabilities (contact) & EMPATHY_CAPABILITIES_AUDIO, EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL, empathy_contact_get_capabilities (contact) & EMPATHY_CAPABILITIES_VIDEO, -1); } if (pixbuf_avatar) { g_object_unref (pixbuf_avatar); } if (priv->show_active && do_set_active) { contact_list_store_contact_set_active (store, contact, do_set_active, do_set_refresh); if (do_set_active) { data = contact_list_store_contact_active_new (store, contact, do_remove); g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME, (GSourceFunc) contact_list_store_contact_active_cb, data); } } /* FIXME: when someone goes online then offline quickly, the * first timeout sets the user to be inactive and the second * timeout removes the user from the contact list, really we * should remove the first timeout. */ g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL); g_list_free (iters); }
static void contact_list_store_add_contact (EmpathyContactListStore *store, EmpathyContact *contact) { EmpathyContactListStorePriv *priv; GtkTreeIter iter; GList *groups = NULL, *l; priv = GET_PRIV (store); if (EMP_STR_EMPTY (empathy_contact_get_name (contact)) || (!priv->show_offline && !empathy_contact_is_online (contact))) { return; } if (priv->show_groups) { groups = empathy_contact_list_get_groups (priv->list, contact); } /* If no groups just add it at the top level. */ if (!groups) { gtk_tree_store_append (GTK_TREE_STORE (store), &iter, NULL); gtk_tree_store_set (GTK_TREE_STORE (store), &iter, EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact), EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, contact, EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE, EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE, EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL, empathy_contact_get_capabilities (contact) & EMPATHY_CAPABILITIES_AUDIO, EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL, empathy_contact_get_capabilities (contact) & EMPATHY_CAPABILITIES_VIDEO, -1); } /* Else add to each group. */ for (l = groups; l; l = l->next) { GtkTreeIter iter_group; contact_list_store_get_group (store, l->data, &iter_group, NULL, NULL); gtk_tree_store_insert_after (GTK_TREE_STORE (store), &iter, &iter_group, NULL); gtk_tree_store_set (GTK_TREE_STORE (store), &iter, EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact), EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, contact, EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE, EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE, EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL, empathy_contact_get_capabilities (contact) & EMPATHY_CAPABILITIES_AUDIO, EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL, empathy_contact_get_capabilities (contact) & EMPATHY_CAPABILITIES_VIDEO, -1); g_free (l->data); } g_list_free (groups); contact_list_store_contact_update (store, contact); }