* Authors: Xavier Claessens <xclaesse@gmail.com>
*/
-#include <config.h>
+#include "config.h"
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-
-#include <glib.h>
#include <glib/gstdio.h>
#include <glib/gi18n.h>
-#include <gtk/gtk.h>
-#include <gdk/gdkx.h>
+#include <libnotify/notify.h>
+#include <tp-account-widgets/tpaw-utils.h>
#ifdef HAVE_LIBCHAMPLAIN
#include <clutter-gtk/clutter-gtk.h>
#endif
-#include <libnotify/notify.h>
-
-#include <telepathy-glib/account-manager.h>
-#include <telepathy-glib/dbus.h>
-#include <telepathy-glib/debug-sender.h>
-#include <telepathy-glib/util.h>
-#include <telepathy-glib/connection-manager.h>
-#include <telepathy-glib/interfaces.h>
-
-#include <telepathy-logger/telepathy-logger.h>
-
-#include <libempathy/empathy-client-factory.h>
-#include <libempathy/empathy-connection-aggregator.h>
-#include <libempathy/empathy-presence-manager.h>
-#include <libempathy/empathy-utils.h>
-#include <libempathy/empathy-chatroom-manager.h>
-#include <libempathy/empathy-account-settings.h>
-#include <libempathy/empathy-connectivity.h>
-#include <libempathy/empathy-connection-managers.h>
-#include <libempathy/empathy-request-util.h>
-#include <libempathy/empathy-ft-factory.h>
-#include <libempathy/empathy-gsettings.h>
-#include <libempathy/empathy-tp-chat.h>
-
-#include <libempathy-gtk/empathy-ui-utils.h>
-#include <libempathy-gtk/empathy-location-manager.h>
-#include <libempathy-gtk/empathy-notify-manager.h>
-
-#include "empathy-roster-window.h"
#include "empathy-accounts-common.h"
#include "empathy-accounts-dialog.h"
-#include "empathy-status-icon.h"
+#include "empathy-bus-names.h"
+#include "empathy-chatroom-manager.h"
+#include "empathy-client-factory.h"
+#include "empathy-connection-aggregator.h"
+#include "empathy-ft-factory.h"
#include "empathy-ft-manager.h"
+#include "empathy-gsettings.h"
+#include "empathy-location-manager.h"
#include "empathy-notifications-approver.h"
-
-#include "extensions/extensions.h"
+#include "empathy-presence-manager.h"
+#include "empathy-request-util.h"
+#include "empathy-roster-window.h"
+#include "empathy-status-icon.h"
+#include "empathy-ui-utils.h"
+#include "empathy-utils.h"
#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
-#include <libempathy/empathy-debug.h>
-
-#define EMPATHY_DBUS_NAME "org.gnome.Empathy"
+#include "empathy-debug.h"
#define EMPATHY_TYPE_APP (empathy_app_get_type ())
#define EMPATHY_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMPATHY_TYPE_APP, EmpathyApp))
EmpathyChatroomManager *chatroom_manager;
EmpathyFTFactory *ft_factory;
EmpathyPresenceManager *presence_mgr;
- EmpathyConnectivity *connectivity;
GSettings *gsettings;
EmpathyNotificationsApprover *notifications_approver;
EmpathyConnectionAggregator *conn_aggregator;
#endif
tp_clear_object (&self->presence_mgr);
- tp_clear_object (&self->connectivity);
tp_clear_object (&self->icon);
tp_clear_object (&self->account_manager);
tp_clear_object (&self->log_manager);
g_object_unref (handler);
}
-static gboolean
-empathy_app_local_command_line (GApplication *app,
- gchar ***arguments,
- gint *exit_status);
-
static void
empathy_presence_manager_set_auto_away_cb (GSettings *gsettings,
const gchar *key,
}
}
-static int
-empathy_app_command_line (GApplication *app,
- GApplicationCommandLine *cmdline)
+static void
+empathy_app_activate (GApplication *app)
{
EmpathyApp *self = (EmpathyApp *) app;
- gchar **args, **argv;
- gint argc, exit_status, i;
-
- args = g_application_command_line_get_arguments (cmdline, &argc);
- /* We have to make an extra copy of the array, since g_option_context_parse()
- * assumes that it can remove strings from the array without freeing them. */
- argv = g_new (gchar*, argc + 1);
- for (i = 0; i <= argc; i++)
- argv[i] = args[i];
-
- if (empathy_app_local_command_line (app, &argv, &exit_status))
- DEBUG ("failed to parse command line!");
-
- g_free (argv);
- g_strfreev (args);
if (!self->activated)
{
GError *error = NULL;
TpDBusDaemon *dbus;
+ empathy_gtk_init ();
+
/* Create the FT factory */
self->ft_factory = empathy_ft_factory_dup_singleton ();
g_signal_connect (self->ft_factory, "new-ft-handler",
self->activated = TRUE;
/* Setting up UI */
- self->window = empathy_roster_window_dup ();
+ self->window = empathy_roster_window_new (GTK_APPLICATION (app));
+ gtk_application_set_app_menu (GTK_APPLICATION (self),
+ empathy_roster_window_get_menu_model (
+ EMPATHY_ROSTER_WINDOW (self->window)));
gtk_application_add_window (GTK_APPLICATION (app),
GTK_WINDOW (self->window));
+ gtk_application_add_accelerator (GTK_APPLICATION (app),
+ "<Primary>h",
+ "win." EMPATHY_PREFS_UI_SHOW_OFFLINE,
+ NULL);
/* check if Shell is running */
dbus = tp_dbus_daemon_dup (&error);
self->notifications_approver =
empathy_notifications_approver_dup_singleton ();
}
- else
- {
- /* We're requested to show stuff again, disable the start hidden global in
- * case the accounts wizard wants to pop up.
- */
- self->start_hidden = FALSE;
- }
if (self->show_preferences)
- empathy_roster_window_show_preferences (
- EMPATHY_ROSTER_WINDOW (self->window), self->preferences_tab);
+ {
+ empathy_roster_window_show_preferences (
+ EMPATHY_ROSTER_WINDOW (self->window),
+ tp_str_empty (self->preferences_tab) ? NULL : self->preferences_tab);
- if (!self->start_hidden)
- empathy_window_present (GTK_WINDOW (self->window));
+ self->show_preferences = FALSE;
+ }
+ else
+ {
+ if (!self->start_hidden)
+ tpaw_window_present (GTK_WINDOW (self->window));
+ }
/* Display the accounts dialog if needed */
tp_proxy_prepare_async (self->account_manager, NULL,
account_manager_ready_cb, self);
-
- return 0;
}
static gboolean
gpointer data,
GError **error);
+static void
+open_preference_action_cb (GAction *action,
+ GVariant *parameter,
+ gpointer data)
+{
+ EmpathyApp *self = EMPATHY_APP (data);
+
+ self->show_preferences = TRUE;
+
+ g_free (self->preferences_tab);
+ self->preferences_tab = g_variant_dup_string (parameter, NULL);
+}
+
static gboolean
empathy_app_local_command_line (GApplication *app,
gchar ***arguments,
gint *exit_status)
{
EmpathyApp *self = (EmpathyApp *) app;
+ GSimpleAction *action;
gint i;
gchar **argv;
gint argc = 0;
- gboolean retval = FALSE;
+ gboolean retval = TRUE;
GError *error = NULL;
gboolean no_connect = FALSE, start_hidden = FALSE;
{ NULL }
};
+ if (!g_application_register (app, NULL, &error))
+ {
+ g_warning ("Impossible to register empathy: %s", error->message);
+ g_clear_error (&error);
+ *exit_status = EXIT_FAILURE;
+ return retval;
+ }
+
+ action = g_simple_action_new ("open-preferences", G_VARIANT_TYPE_STRING);
+ g_signal_connect (action, "activate", G_CALLBACK (open_preference_action_cb), app);
+ g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (action));
+ g_object_unref (action);
+
/* We create a group so that GOptionArgFuncs get the user data */
group = g_option_group_new ("empathy", NULL, NULL, app, NULL);
+ g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
g_option_group_add_entries (group, options);
optcontext = g_option_context_new (N_("- Empathy IM Client"));
- g_option_context_add_group (optcontext, gtk_get_option_group (TRUE));
+ g_option_context_add_group (optcontext, gtk_get_option_group (FALSE));
g_option_context_set_main_group (optcontext, group);
g_option_context_set_translation_domain (optcontext, GETTEXT_PACKAGE);
"line options.\n",
error->message, argv[0]);
g_warning ("Error in empathy init: %s", error->message);
+ g_clear_error (&error);
*exit_status = EXIT_FAILURE;
- retval = TRUE;
}
+ else
+ {
+ self->no_connect = no_connect;
+ self->start_hidden = start_hidden;
- g_free (argv);
+ if (self->show_preferences)
+ {
+ GVariant *parameter;
+ parameter = g_variant_new_string (self->preferences_tab ? self->preferences_tab : "");
+ g_action_group_activate_action (G_ACTION_GROUP (app), "open-preferences", parameter);
+ }
- g_option_context_free (optcontext);
+ g_application_activate (app);
+ }
- self->no_connect = no_connect;
- self->start_hidden = start_hidden;
+ g_free (argv);
+ g_option_context_free (optcontext);
return retval;
}
gobject_class->dispose = empathy_app_dispose;
gobject_class->finalize = empathy_app_finalize;
- g_app_class->command_line = empathy_app_command_line;
g_app_class->local_command_line = empathy_app_local_command_line;
+ g_app_class->activate = empathy_app_activate;
spec = g_param_spec_boolean ("no-connect", "no connect",
"Don't connect on startup",
{
}
-static void
-use_conn_notify_cb (GSettings *gsettings,
- const gchar *key,
- gpointer user_data)
-{
- EmpathyConnectivity *connectivity = user_data;
-
- empathy_connectivity_set_use_conn (connectivity,
- g_settings_get_boolean (gsettings, key));
-}
-
static void
migrate_config_to_xdg_dir (void)
{
return;
}
- accounts = tp_account_manager_get_valid_accounts (account_manager);
+ accounts = tp_account_manager_dup_valid_accounts (account_manager);
for (l = accounts; l != NULL; l = g_list_next (l))
{
tp_g_signal_connect_object (account, "notify::connection",
G_CALLBACK (account_connection_changed_cb), chatroom_manager, 0);
}
- g_list_free (accounts);
+ g_list_free_full (accounts, g_object_unref);
}
static void
EmpathyApp *self = (EmpathyApp *) object;
gboolean chatroom_manager_ready;
+ textdomain (GETTEXT_PACKAGE);
g_set_application_name (_(PACKAGE_NAME));
gtk_window_set_default_icon_name ("empathy");
- textdomain (GETTEXT_PACKAGE);
#ifdef ENABLE_DEBUG
/* Set up debug sender */
self->gsettings = g_settings_new (EMPATHY_PREFS_SCHEMA);
- /* Setting up Connectivity */
- self->connectivity = empathy_connectivity_dup_singleton ();
- use_conn_notify_cb (self->gsettings, EMPATHY_PREFS_USE_CONN,
- self->connectivity);
- g_signal_connect (self->gsettings,
- "changed::" EMPATHY_PREFS_USE_CONN,
- G_CALLBACK (use_conn_notify_cb), self->connectivity);
-
/* account management */
self->account_manager = tp_account_manager_dup ();
tp_proxy_prepare_async (self->account_manager, NULL,
account_manager_ready_cb, self);
+ tp_account_manager_enable_restart (self->account_manager);
+
migrate_config_to_xdg_dir ();
/* Logging */
EmpathyApp *app;
gint retval;
- g_thread_init (NULL);
g_type_init ();
#ifdef HAVE_LIBCHAMPLAIN
g_type_init ();
empathy_init ();
- gtk_init (&argc, &argv);
- empathy_gtk_init ();
add_empathy_features ();
app = g_object_new (EMPATHY_TYPE_APP,
- "application-id", EMPATHY_DBUS_NAME,
- "flags", G_APPLICATION_HANDLES_COMMAND_LINE,
+ "application-id", EMPATHY_BUS_NAME,
NULL);
retval = g_application_run (G_APPLICATION (app), argc, argv);