diff options
-rw-r--r-- | libempathy-gtk/empathy-chat-text-view.c | 6 | ||||
-rw-r--r-- | libempathy-gtk/empathy-chat.c | 134 | ||||
-rw-r--r-- | libempathy-gtk/empathy-spell.c | 31 | ||||
-rw-r--r-- | libempathy-gtk/empathy-spell.h | 2 | ||||
-rw-r--r-- | src/empathy-accounts.c | 12 | ||||
-rw-r--r-- | src/empathy-av.c | 41 | ||||
-rw-r--r-- | src/empathy-debugger.c | 7 | ||||
-rw-r--r-- | src/empathy.c | 18 |
8 files changed, 206 insertions, 45 deletions
diff --git a/libempathy-gtk/empathy-chat-text-view.c b/libempathy-gtk/empathy-chat-text-view.c index 5b6d5727b..07ad45dbd 100644 --- a/libempathy-gtk/empathy-chat-text-view.c +++ b/libempathy-gtk/empathy-chat-text-view.c @@ -344,7 +344,7 @@ chat_text_view_is_scrolled_down (EmpathyChatTextView *view) gdouble upper; gdouble page_size; - vadj = gtk_text_view_get_vadjustment (GTK_TEXT_VIEW (view)); + vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (view)); value = gtk_adjustment_get_value (vadj); upper = gtk_adjustment_get_upper (vadj); page_size = gtk_adjustment_get_page_size (vadj); @@ -495,7 +495,7 @@ chat_text_view_size_allocate (GtkWidget *widget, if (down) { GtkAdjustment *adj; - adj = gtk_text_view_get_vadjustment (GTK_TEXT_VIEW (widget)); + adj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (widget)); gtk_adjustment_set_value (adj, gtk_adjustment_get_upper (adj) - gtk_adjustment_get_page_size (adj)); @@ -683,7 +683,7 @@ chat_text_view_scroll_cb (EmpathyChatTextView *view) priv = GET_PRIV (view); - adj = gtk_text_view_get_vadjustment (GTK_TEXT_VIEW (view)); + adj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (view)); max_val = gtk_adjustment_get_upper (adj) - gtk_adjustment_get_page_size (adj); g_return_val_if_fail (priv->scroll_time != NULL, FALSE); diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c index fb8d538ef..d6b9cf788 100644 --- a/libempathy-gtk/empathy-chat.c +++ b/libempathy-gtk/empathy-chat.c @@ -172,6 +172,8 @@ static guint signals[LAST_SIGNAL] = { 0 }; G_DEFINE_TYPE (EmpathyChat, empathy_chat, GTK_TYPE_BIN); +static gboolean update_misspelled_words (gpointer data); + static void chat_get_property (GObject *object, guint param_id, @@ -1838,6 +1840,123 @@ chat_spelling_build_menu (EmpathyChatSpell *chat_spell) return menu; } +typedef struct { + EmpathyChat *chat; + gchar *word; + gchar *code; +} EmpathyChatWord; + +static EmpathyChatWord * +chat_word_new (EmpathyChat *chat, + const gchar *word, + const gchar *code) +{ + EmpathyChatWord *chat_word; + + chat_word = g_slice_new0 (EmpathyChatWord); + + chat_word->chat = g_object_ref (chat); + chat_word->word = g_strdup (word); + chat_word->code = g_strdup (code); + + return chat_word; +} + +static void +chat_word_free (EmpathyChatWord *chat_word) +{ + g_object_unref (chat_word->chat); + g_free (chat_word->word); + g_free (chat_word->code); + g_slice_free (EmpathyChatWord, chat_word); +} + +static void +chat_add_to_dictionary_activate_cb (GtkMenuItem *menu_item, + EmpathyChatWord *chat_word) +{ + EmpathyChatPriv *priv = GET_PRIV (chat_word->chat); + + empathy_spell_add_to_dictionary (chat_word->code, + chat_word->word); + priv->update_misspelled_words_id = + g_idle_add (update_misspelled_words, chat_word->chat); +} + +static GtkWidget * +chat_spelling_build_add_to_dictionary_item (EmpathyChatSpell *chat_spell) +{ + GtkWidget *menu, *item, *lang_item, *image; + GList *codes, *l; + gchar *label; + const gchar *code, *name; + EmpathyChatWord *chat_word; + + codes = empathy_spell_get_enabled_language_codes (); + g_assert (codes != NULL); + if (g_list_length (codes) > 1) { + /* translators: %s is the selected word */ + label = g_strdup_printf(_("Add '%s' to Dictionary"), + chat_spell->word); + item = gtk_image_menu_item_new_with_mnemonic (label); + g_free (label); + image = gtk_image_new_from_icon_name (GTK_STOCK_ADD, + GTK_ICON_SIZE_MENU); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), + image); + + menu = gtk_menu_new (); + + for (l = codes; l; l = l->next) { + code = l->data; + name = empathy_spell_get_language_name (code); + if (name == NULL) + continue; + + lang_item = gtk_image_menu_item_new_with_label (name); + + chat_word= chat_word_new (chat_spell->chat, + chat_spell->word, code); + g_object_set_data_full (G_OBJECT (lang_item), + "chat-word", chat_word, + (GDestroyNotify) chat_word_free); + + g_signal_connect (G_OBJECT (lang_item), "activate", + G_CALLBACK (chat_add_to_dictionary_activate_cb), + chat_word); + gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), lang_item); + } + gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), menu); + } else { + code = codes->data; + name = empathy_spell_get_language_name (code); + g_assert (name != NULL); + /* translators: first %s is the selected word, + * second %s is the language name of the target dictionary */ + label = g_strdup_printf(_("Add '%s' to %s Dictionary"), + chat_spell->word, name); + item = gtk_image_menu_item_new_with_mnemonic (label); + g_free (label); + image = gtk_image_new_from_icon_name (GTK_STOCK_ADD, + GTK_ICON_SIZE_MENU); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); + + chat_word = chat_word_new (chat_spell->chat, chat_spell->word, + code); + g_object_set_data_full (G_OBJECT (item), "chat-word", chat_word, + (GDestroyNotify) chat_word_free); + + g_signal_connect (G_OBJECT (item), "activate", + G_CALLBACK (chat_add_to_dictionary_activate_cb), + chat_word); + } + g_list_free (codes); + + gtk_widget_show_all (item); + + return item; +} + static void chat_text_send_cb (GtkMenuItem *menuitem, EmpathyChat *chat) @@ -1860,6 +1979,7 @@ chat_input_populate_popup_cb (GtkTextView *view, gchar *str = NULL; EmpathyChatSpell *chat_spell; GtkWidget *spell_menu; + GtkWidget *spell_item; EmpathySmileyManager *smiley_manager; GtkWidget *smiley_menu; GtkWidget *image; @@ -1917,13 +2037,14 @@ chat_input_populate_popup_cb (GtkTextView *view, if (!EMP_STR_EMPTY (str)) { chat_spell = chat_spell_new (chat, str, start, end); g_object_set_data_full (G_OBJECT (menu), - "chat_spell", chat_spell, + "chat-spell", chat_spell, (GDestroyNotify) chat_spell_free); item = gtk_separator_menu_item_new (); gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); + /* Spelling suggestions */ item = gtk_image_menu_item_new_with_mnemonic (_("_Spelling Suggestions")); image = gtk_image_new_from_icon_name (GTK_STOCK_SPELL_CHECK, GTK_ICON_SIZE_MENU); @@ -1932,6 +2053,17 @@ chat_input_populate_popup_cb (GtkTextView *view, spell_menu = chat_spelling_build_menu (chat_spell); gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), spell_menu); + + spell_item = gtk_separator_menu_item_new (); + gtk_menu_shell_append (GTK_MENU_SHELL (spell_menu), spell_item); + gtk_widget_show (spell_item); + + /* Add to dictionary */ + spell_item = chat_spelling_build_add_to_dictionary_item (chat_spell); + + gtk_menu_shell_append (GTK_MENU_SHELL (spell_menu), spell_item); + gtk_widget_show (spell_item); + gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); } diff --git a/libempathy-gtk/empathy-spell.c b/libempathy-gtk/empathy-spell.c index b9abcd5f7..dcbbaf8cd 100644 --- a/libempathy-gtk/empathy-spell.c +++ b/libempathy-gtk/empathy-spell.c @@ -359,7 +359,8 @@ empathy_spell_check (const gchar *word) } GList * -empathy_spell_get_suggestions (const gchar *code, const gchar *word) +empathy_spell_get_suggestions (const gchar *code, + const gchar *word) { gint len; GList *suggestion_list = NULL; @@ -409,6 +410,26 @@ empathy_spell_supported (void) return TRUE; } +void +empathy_spell_add_to_dictionary (const gchar *code, + const gchar *word) +{ + SpellLanguage *lang; + + g_return_if_fail (code != NULL); + g_return_if_fail (word != NULL); + + spell_setup_languages (); + if (languages == NULL) + return; + + lang = g_hash_table_lookup (languages, code); + if (lang == NULL) + return; + + enchant_dict_add_to_pwl (lang->speller, word, strlen (word)); +} + #else /* not HAVE_ENCHANT */ gboolean @@ -454,6 +475,14 @@ empathy_spell_free_language_codes (GList *codes) { } +void +empathy_spell_add_to_dictionary (const gchar *code, + const gchar *word) +{ + DEBUG ("Support disabled, could not expand the dictionary"); +} + + #endif /* HAVE_ENCHANT */ diff --git a/libempathy-gtk/empathy-spell.h b/libempathy-gtk/empathy-spell.h index aa2a3e51e..ebce1aef7 100644 --- a/libempathy-gtk/empathy-spell.h +++ b/libempathy-gtk/empathy-spell.h @@ -37,6 +37,8 @@ gboolean empathy_spell_check (const gchar *word); GList * empathy_spell_get_suggestions (const gchar *code, const gchar *word); void empathy_spell_free_suggestions (GList *suggestions); +void empathy_spell_add_to_dictionary (const gchar *code, + const gchar *word); G_END_DECLS diff --git a/src/empathy-accounts.c b/src/empathy-accounts.c index 4131100fb..e491ea160 100644 --- a/src/empathy-accounts.c +++ b/src/empathy-accounts.c @@ -135,7 +135,7 @@ account_manager_ready_for_accounts_cb (GObject *source_object, } static void -app_activated_cb (GtkApplication *app) +app_activate_cb (GApplication *app) { TpAccountManager *account_manager; @@ -199,17 +199,19 @@ main (int argc, char *argv[]) gtk_window_set_default_icon_name ("empathy"); textdomain (GETTEXT_PACKAGE); - app = gtk_application_new (EMPATHY_ACCOUNTS_DBUS_NAME, &argc, &argv); + app = gtk_application_new (EMPATHY_ACCOUNTS_DBUS_NAME, + G_APPLICATION_IS_SERVICE); account_manager = tp_account_manager_dup (); tp_account_manager_prepare_async (account_manager, NULL, account_manager_ready_for_accounts_cb, selected_account_name); - g_signal_connect (app, "activated", - G_CALLBACK (app_activated_cb), NULL); + g_signal_connect (app, "activate", G_CALLBACK (app_activate_cb), NULL); - gtk_application_run (app); + /* don't let this application exit automatically */ + g_application_hold (G_APPLICATION (app)); + g_application_run (G_APPLICATION (app), argc, argv); g_object_unref (account_manager); g_object_unref (app); diff --git a/src/empathy-av.c b/src/empathy-av.c index c937c2a44..84aba715b 100644 --- a/src/empathy-av.c +++ b/src/empathy-av.c @@ -43,43 +43,30 @@ #define EMPATHY_AV_DBUS_NAME "org.gnome.Empathy.AudioVideo" +static GtkApplication *app = NULL; +static gboolean app_held = FALSE; static guint nb_windows = 0; -static guint timeout_id = 0; static gboolean use_timer = TRUE; -static gboolean -timeout_cb (gpointer data) -{ - DEBUG ("Timing out; exiting"); - - gtk_main_quit (); - return FALSE; -} - static void start_timer (void) { if (!use_timer) return; - if (timeout_id != 0) - return; - DEBUG ("Start timer"); - timeout_id = g_timeout_add_seconds (TIMEOUT, timeout_cb, NULL); + if (app_held) + g_application_release (G_APPLICATION (app)); } static void stop_timer (void) { - if (timeout_id == 0) - return; - DEBUG ("Stop timer"); - g_source_remove (timeout_id); - timeout_id = 0; + g_application_hold (G_APPLICATION (app)); + app_held = TRUE; } static void @@ -128,7 +115,6 @@ main (int argc, #endif EmpathyCallFactory *call_factory; GError *error = NULL; - GtkApplication *app; /* Init */ g_thread_init (NULL); @@ -155,7 +141,7 @@ main (int argc, gtk_window_set_default_icon_name ("empathy"); textdomain (GETTEXT_PACKAGE); - app = gtk_application_new (EMPATHY_AV_DBUS_NAME, &argc, &argv); + app = gtk_application_new (EMPATHY_AV_DBUS_NAME, G_APPLICATION_IS_SERVICE); #ifdef ENABLE_DEBUG /* Set up debug sender */ @@ -182,9 +168,20 @@ main (int argc, use_timer = FALSE; } + /* the inactivity timeout can only be set while the application is held */ + g_application_hold (G_APPLICATION (app)); + g_application_set_inactivity_timeout (G_APPLICATION (app), TIMEOUT * 1000); + if (use_timer) + { + g_application_release (G_APPLICATION (app)); + app_held = FALSE; + } + else + app_held = TRUE; + start_timer (); - gtk_application_run (app); + g_application_run (G_APPLICATION (app), argc, argv); g_object_unref (app); g_object_unref (call_factory); diff --git a/src/empathy-debugger.c b/src/empathy-debugger.c index 2203041d1..2688bfd1e 100644 --- a/src/empathy-debugger.c +++ b/src/empathy-debugger.c @@ -39,7 +39,8 @@ main (int argc, g_thread_init (NULL); empathy_gtk_init (); - app = gtk_application_new (EMPATHY_DEBUGGER_DBUS_NAME, &argc, &argv); + app = gtk_application_new (EMPATHY_DEBUGGER_DBUS_NAME, + G_APPLICATION_IS_SERVICE); g_set_application_name (_("Empathy Debugger")); @@ -49,7 +50,9 @@ main (int argc, window = empathy_debug_window_new (NULL); g_signal_connect (window, "destroy", gtk_main_quit, NULL); - gtk_application_run (app); + /* don't let this application exit automatically */ + g_application_hold (G_APPLICATION (app)); + g_application_run (G_APPLICATION (app), argc, argv); g_object_unref (app); return EXIT_SUCCESS; diff --git a/src/empathy.c b/src/empathy.c index 314e4fb0f..aa4610622 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -190,13 +190,9 @@ empathy_app_new (guint argc, argv_variant = g_variant_new_bytestring_array (argv, argc); - self = g_initable_new (EMPATHY_TYPE_APP, - NULL, &error, + self = g_object_new (EMPATHY_TYPE_APP, "application-id", EMPATHY_DBUS_NAME, - "argv", argv_variant, - "register", TRUE, - "no-connect", no_connect, - "start-hidden", start_hidden, + "flags", G_APPLICATION_IS_SERVICE, NULL); if (self == NULL) @@ -231,8 +227,7 @@ empathy_app_set_property (GObject *object, } static void -empathy_app_activated (GtkApplication *app, - GVariant *args) +empathy_app_activate (GApplication *app) { EmpathyApp *self = (EmpathyApp *) app; @@ -254,7 +249,7 @@ static void empathy_app_class_init (EmpathyAppClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GtkApplicationClass *gtk_app_class = GTK_APPLICATION_CLASS (klass); + GApplicationClass *g_app_class = G_APPLICATION_CLASS (klass); GParamSpec *spec; gobject_class->set_property = empathy_app_set_property; @@ -262,7 +257,7 @@ empathy_app_class_init (EmpathyAppClass *klass) gobject_class->dispose = empathy_app_dispose; gobject_class->finalize = empathy_app_finalize; - gtk_app_class->activated = empathy_app_activated; + g_app_class->activate = empathy_app_activate; spec = g_param_spec_boolean ("no-connect", "no connect", "Don't connect on startup", @@ -696,7 +691,8 @@ main (int argc, char *argv[]) app = empathy_app_new (argc, (const gchar * const *) argv, no_connect, start_hidden); - gtk_application_run (GTK_APPLICATION (app)); + g_application_hold (G_APPLICATION (app)); + g_application_run (G_APPLICATION (app), argc, argv); notify_uninit (); xmlCleanupParser (); |