#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
-#include <canberra-gtk.h>
#include <libmissioncontrol/mc-profile.h>
#include <libempathy/empathy-utils.h>
#include <libempathy/empathy-dispatcher.h>
#include <libempathy/empathy-idle.h>
-#include <libempathy/empathy-tp-file.h>
+#include <libempathy/empathy-ft-factory.h>
#define SCHEMES "(https?|s?ftps?|nntp|news|javascript|about|ghelp|apt|telnet|"\
"file|webcal|mailto)"
}
const gchar *
-empathy_icon_name_from_account (McAccount *account)
+empathy_icon_name_from_account (EmpathyAccount *account)
{
McProfile *profile;
- profile = mc_account_get_profile (account);
+ profile = empathy_account_get_profile (account);
return mc_profile_get_icon_name (profile);
}
const gchar *
-empathy_icon_name_for_presence (McPresence presence)
+empathy_icon_name_for_presence (TpConnectionPresenceType presence)
{
switch (presence) {
- case MC_PRESENCE_AVAILABLE:
+ case TP_CONNECTION_PRESENCE_TYPE_AVAILABLE:
return EMPATHY_IMAGE_AVAILABLE;
- case MC_PRESENCE_DO_NOT_DISTURB:
+ case TP_CONNECTION_PRESENCE_TYPE_BUSY:
return EMPATHY_IMAGE_BUSY;
- case MC_PRESENCE_AWAY:
+ case TP_CONNECTION_PRESENCE_TYPE_AWAY:
return EMPATHY_IMAGE_AWAY;
- case MC_PRESENCE_EXTENDED_AWAY:
+ case TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY:
return EMPATHY_IMAGE_EXT_AWAY;
- case MC_PRESENCE_HIDDEN:
+ case TP_CONNECTION_PRESENCE_TYPE_HIDDEN:
return EMPATHY_IMAGE_HIDDEN;
- case MC_PRESENCE_OFFLINE:
- case MC_PRESENCE_UNSET:
+ case TP_CONNECTION_PRESENCE_TYPE_OFFLINE:
+ case TP_CONNECTION_PRESENCE_TYPE_ERROR:
+ case TP_CONNECTION_PRESENCE_TYPE_UNKNOWN:
return EMPATHY_IMAGE_OFFLINE;
- default:
- g_assert_not_reached ();
+ case TP_CONNECTION_PRESENCE_TYPE_UNSET:
+ return NULL;
}
return NULL;
const gchar *
empathy_icon_name_for_contact (EmpathyContact *contact)
{
- McPresence presence;
+ TpConnectionPresenceType presence;
g_return_val_if_fail (EMPATHY_IS_CONTACT (contact),
EMPATHY_IMAGE_OFFLINE);
return empathy_pixbuf_from_icon_name_sized (icon_name, size);
}
+gchar *
+empathy_filename_from_icon_name (const gchar *icon_name,
+ GtkIconSize icon_size)
+{
+ GtkIconTheme *icon_theme;
+ GtkIconInfo *icon_info;
+ gint w, h;
+ gint size = 48;
+ gchar *ret;
+
+ icon_theme = gtk_icon_theme_get_default ();
+
+ if (gtk_icon_size_lookup (icon_size, &w, &h)) {
+ size = (w + h) / 2;
+ }
+
+ icon_info = gtk_icon_theme_lookup_icon (icon_theme, icon_name, size, 0);
+ ret = g_strdup (gtk_icon_info_get_filename (icon_info));
+ gtk_icon_info_free (icon_info);
+
+ return ret;
+}
+
/* Stolen from GtkSourceView, hence the weird intendation. Please keep it like
* that to make it easier to apply changes from the original code.
*/
g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
- gdk_window = GTK_WIDGET (window)->window;
+ gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
if (!gdk_window) {
return FALSE;
}
GdkWindow *gdk_window;
gtk_status_icon_get_geometry (status_icon, NULL, &icon_location, NULL);
- gdk_window = GTK_WIDGET (window)->window;
+ gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
dpy = gdk_x11_drawable_get_xdisplay (gdk_window);
data[0] = icon_location.x;
}
timestamp = gtk_get_current_event_time ();
- gtk_window_set_skip_taskbar_hint (window, FALSE);
gtk_window_present_with_time (window, timestamp);
+ gtk_window_set_skip_taskbar_hint (window, FALSE);
/* FIXME: This shouldn't be required as gtk_window_present's doc says
* it deiconify automatically. */
gtk_window_deiconify (window);
static gchar *
fixup_url (const gchar *url)
{
+ g_return_val_if_fail (url != NULL, NULL);
+
if (g_str_has_prefix (url, "ghelp:") ||
g_str_has_prefix (url, "mailto:") ||
strstr (url, ":/")) {
gchar *real_url;
GError *error = NULL;
+ g_return_if_fail (parent == NULL || GTK_IS_WIDGET (parent));
+ g_return_if_fail (url != NULL);
+
real_url = fixup_url (url);
if (real_url) {
url = real_url;
}
- gtk_show_uri (gtk_widget_get_screen (parent), url,
+ gtk_show_uri (parent ? gtk_widget_get_screen (parent) : NULL, url,
gtk_get_current_event_time (), &error);
if (error) {
g_signal_handlers_unblock_by_func (widget, callback, user_data);
}
-/* Sending files with the file chooser */
-
-static void
-file_manager_send_file_request_cb (EmpathyDispatchOperation *operation,
- const GError *error, gpointer user_data)
-{
- GFile *file = (GFile *) user_data;
- EmpathyTpFile *tp_file;
-
- if (error != NULL) {
- DEBUG ("Couldn't request channel: %s", error->message);
- g_object_unref (file);
- return;
- }
-
- DEBUG ("Starting to send file");
-
- tp_file = EMPATHY_TP_FILE (
- empathy_dispatch_operation_get_channel_wrapper (operation));
-
- empathy_tp_file_offer (tp_file, file, NULL);
-
- g_object_unref (file);
-}
-
static void
file_manager_send_file_response_cb (GtkDialog *widget,
gint response_id,
EmpathyContact *contact)
{
- if (response_id == GTK_RESPONSE_OK) {
- GSList *list;
- GSList *l;
-
- list = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (widget));
-
- DEBUG ("File chooser selected files:");
-
- for (l = list; l; l = l->next) {
- gchar *uri;
- GFile *gfile;
- GFileInfo *info;
- GtkRecentManager *manager;
- gchar *filename;
- GTimeVal mtime;
- GError *error = NULL;
-
- uri = l->data;
- gfile = g_file_new_for_uri (uri);
- info = g_file_query_info (gfile,
- G_FILE_ATTRIBUTE_STANDARD_SIZE ","
- G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
- G_FILE_ATTRIBUTE_TIME_MODIFIED,
- 0, NULL, &error);
-
- if (error) {
- DEBUG ("Can't get info about the file: %s", error->message);
- g_clear_error (&error);
- g_object_unref (gfile);
- continue;
- }
+ EmpathyFTFactory *factory;
+ GFile *file;
+ gchar *uri;
+ GtkRecentManager *manager;
- DEBUG ("\t%s", uri);
- filename = g_file_get_basename (gfile);
- g_file_info_get_modification_time (info, &mtime);
+ if (response_id == GTK_RESPONSE_OK) {
+ file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (widget));
+ uri = g_file_get_uri (file);
- empathy_dispatcher_send_file_to_contact (contact,
- filename, g_file_info_get_size (info), mtime.tv_sec,
- g_file_info_get_content_type (info),
- file_manager_send_file_request_cb, gfile);
+ factory = empathy_ft_factory_dup_singleton ();
- g_free (filename);
- g_object_unref (info);
+ empathy_ft_factory_new_transfer_outgoing (factory, contact,
+ file);
- manager = gtk_recent_manager_get_default ();
- gtk_recent_manager_add_item (manager, uri);
+ manager = gtk_recent_manager_get_default ();
+ gtk_recent_manager_add_item (manager, uri);
- g_free (uri);
- }
- g_slist_free (list);
+ g_free (uri);
+ g_object_unref (factory);
+ g_object_unref (file);
}
gtk_widget_destroy (GTK_WIDGET (widget));
gtk_dialog_set_default_response (GTK_DIALOG (widget),
GTK_RESPONSE_OK);
+ gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (widget), FALSE);
+
g_signal_connect (widget, "response",
G_CALLBACK (file_manager_send_file_response_cb),
contact);
gtk_widget_show (widget);
}
-typedef struct {
- EmpathySound sound_id;
- const char * event_ca_id;
- const char * event_ca_description;
- const char * gconf_key;
-} EmpathySoundEntry;
-
-/* NOTE: these entries MUST be in the same order than EmpathySound enum */
-static EmpathySoundEntry sound_entries[LAST_EMPATHY_SOUND] = {
- { EMPATHY_SOUND_MESSAGE_INCOMING, "message-new-instant",
- N_("Received an instant message"), EMPATHY_PREFS_SOUNDS_INCOMING_MESSAGE } ,
- { EMPATHY_SOUND_MESSAGE_OUTGOING, "message-sent-instant",
- N_("Sent an instant message"), EMPATHY_PREFS_SOUNDS_OUTGOING_MESSAGE } ,
- { EMPATHY_SOUND_CONVERSATION_NEW, "message-new-instant",
- N_("Incoming chat request"), EMPATHY_PREFS_SOUNDS_NEW_CONVERSATION },
- { EMPATHY_SOUND_CONTACT_CONNECTED, "service-login",
- N_("Contact connected"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGIN },
- { EMPATHY_SOUND_CONTACT_DISCONNECTED, "service-logout",
- N_("Contact disconnected"), EMPATHY_PREFS_SOUNDS_CONTACT_LOGOUT },
- { EMPATHY_SOUND_ACCOUNT_CONNECTED, "service-login",
- N_("Connected to server"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGIN },
- { EMPATHY_SOUND_ACCOUNT_DISCONNECTED, "service-logout",
- N_("Disconnected from server"), EMPATHY_PREFS_SOUNDS_SERVICE_LOGOUT },
- { EMPATHY_SOUND_PHONE_INCOMING, "phone-incoming-call",
- N_("Incoming voice call"), NULL },
- { EMPATHY_SOUND_PHONE_OUTGOING, "phone-outgoing-calling",
- N_("Outgoing voice call"), NULL },
- { EMPATHY_SOUND_PHONE_HANGUP, "phone-hangup",
- N_("Voice call ended"), NULL },
-};
-
-
-static gboolean
-empathy_sound_pref_is_enabled (const char *key)
+static void
+file_manager_receive_file_response_cb (GtkDialog *dialog,
+ GtkResponseType response,
+ EmpathyFTHandler *handler)
{
- EmpathyConf *conf;
- gboolean res;
+ EmpathyFTFactory *factory;
+ GFile *file;
- conf = empathy_conf_get ();
- res = FALSE;
+ if (response == GTK_RESPONSE_OK) {
+ factory = empathy_ft_factory_dup_singleton ();
+ file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
- empathy_conf_get_bool (conf, EMPATHY_PREFS_SOUNDS_ENABLED, &res);
+ empathy_ft_factory_set_destination_for_incoming_handler
+ (factory, handler, file);
- if (!res) {
- return FALSE;
- }
-
- if (!empathy_check_available_state ()) {
- empathy_conf_get_bool (conf, EMPATHY_PREFS_SOUNDS_DISABLED_AWAY,
- &res);
- if (res) {
- return FALSE;
- }
+ g_object_unref (factory);
+ g_object_unref (file);
+ } else {
+ /* unref the handler, as we dismissed the file chooser,
+ * and refused the transfer.
+ */
+ g_object_unref (handler);
}
- empathy_conf_get_bool (conf, key, &res);
-
- return res;
+ gtk_widget_destroy (GTK_WIDGET (dialog));
}
void
-empathy_sound_stop (EmpathySound sound_id)
+empathy_receive_file_with_file_chooser (EmpathyFTHandler *handler)
{
- EmpathySoundEntry *entry;
-
- g_return_if_fail (sound_id < LAST_EMPATHY_SOUND);
-
- entry = &(sound_entries[sound_id]);
- g_return_if_fail (entry->sound_id == sound_id);
-
- ca_context_cancel (ca_gtk_context_get (), entry->sound_id);
-}
-
-
-gboolean
-empathy_sound_play_full (GtkWidget *widget, EmpathySound sound_id,
- ca_finish_callback_t callback, gpointer user_data)
-{
- EmpathySoundEntry *entry;
- gboolean should_play = TRUE;
- ca_proplist *p = NULL;
- ca_context *c;
-
- g_return_val_if_fail (sound_id < LAST_EMPATHY_SOUND, FALSE);
-
- entry = &(sound_entries[sound_id]);
- g_return_val_if_fail (entry->sound_id == sound_id, FALSE);
-
- if (entry->gconf_key != NULL) {
- should_play = empathy_sound_pref_is_enabled (entry->gconf_key);
- }
-
- if (!should_play)
- return FALSE;
+ GtkWidget *widget;
- c = ca_gtk_context_get ();
- ca_context_cancel (c, entry->sound_id);
-
- DEBUG ("Play sound \"%s\" (%s)",
- entry->event_ca_id,
- entry->event_ca_description);
-
- if (ca_proplist_create (&p) < 0)
- goto failed;
-
- if (ca_proplist_sets (p, CA_PROP_EVENT_ID, entry->event_ca_id) < 0)
- goto failed;
-
- if (ca_proplist_sets (p, CA_PROP_EVENT_DESCRIPTION,
- gettext (entry->event_ca_id)) < 0)
- goto failed;
-
- if (ca_gtk_proplist_set_for_widget (p, widget) < 0)
- goto failed;
-
- ca_context_play_full (ca_gtk_context_get (), entry->sound_id,
- p, callback, user_data);
-
- ca_proplist_destroy (p);
-
- return TRUE;
-
-failed:
- if (p != NULL)
- ca_proplist_destroy (p);
+ widget = gtk_file_chooser_dialog_new (_("Select a destination"),
+ NULL,
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE,
+ GTK_RESPONSE_OK,
+ NULL);
+ gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (widget),
+ empathy_ft_handler_get_filename (handler));
+ gtk_file_chooser_set_do_overwrite_confirmation
+ (GTK_FILE_CHOOSER (widget), TRUE);
- return FALSE;
-}
+ g_signal_connect (widget, "response",
+ G_CALLBACK (file_manager_receive_file_response_cb), handler);
-void
-empathy_sound_play (GtkWidget *widget, EmpathySound sound_id)
-{
- empathy_sound_play_full (widget, sound_id, NULL, NULL);
+ gtk_widget_show (widget);
}
-