~ubuntu-branches/ubuntu/precise/empathy/precise-proposed-201205180810

« back to all changes in this revision

Viewing changes to src/empathy.c

  • Committer: Bazaar Package Importer
  • Author(s): Brian Curtis, Brian Curtis, Ken VanDine
  • Date: 2011-06-01 10:35:24 UTC
  • mfrom: (1.1.70 upstream) (6.3.44 experimental)
  • Revision ID: james.westby@ubuntu.com-20110601103524-wx3wgp71394730jt
Tags: 3.1.1-1ubuntu1
[ Brian Curtis ]
* Merge with Debian experimental, remaining Ubuntu changes:
* debian/control:
  - Drop geoclue/mapping build-depends (they are in Universe)
  - Add Vcz-Bzr link
  - Add Suggests on telepathy-idle
  - Bump telepathy-butterfly, telepathy-haze to recommends
  - Don't recommend the freedesktop sound theme we have an ubuntu one
  - Add build depend for libunity-dev
* debian/rules:
  - Use autoreconf.mk
  - Disable map and location
* debian/empathy.install:
  - Install message indicator configuration
* debian/indicators/empathy:
  - Message indicator configuration
* debian/patches/01_lpi.patch:
  - Add Launchpad integration
* debian/patches/10_use_notify_osd_icons.patch:
  - Use the notify-osd image for new messages
* debian/patches/34_start_raised_execpt_in_session.patch
  - If not started with the session, we should always raise
* debian/patches/36_chat_window_default_size.patch:
  - Make the default chat window size larger
* debian/patches/37_facebook_default.patch:
  - Make facebook the default chat account type
* debian/patches/38_lp_569289.patch
  - Set freenode as default IRC network for new IRC accounts 
* debian/patches/41_unity_launcher_progress.patch
  - Display file transfer progress in the unity launcher

[ Ken VanDine ]
* debian/control
  - build depend on libgcr-3-dev instead of libgcr-dev
  - dropped build depends for libindicate, we will use telepathy-indicator
  - Depend on dconf-gsettings-backend | gsettings-backend
  - Added a Recommends for telepathy-indicator
* +debian/empathy.gsettings-override
  - Added an override for notifications-focus
* debian/patches/series
  - commented out 23_idomessagedialog_for_voip_and_ft.patch, until ido has 
    been ported to gtk3

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include <glib/gi18n.h>
31
31
#include <gtk/gtk.h>
32
32
#include <gdk/gdkx.h>
33
 
#include <unique/unique.h>
34
33
 
35
34
#ifdef HAVE_LIBCHAMPLAIN
36
35
#include <clutter-gtk/clutter-gtk.h>
45
44
#include <telepathy-glib/connection-manager.h>
46
45
#include <telepathy-glib/interfaces.h>
47
46
 
48
 
#include <telepathy-yell/telepathy-yell.h>
49
 
 
50
47
#include <telepathy-logger/log-manager.h>
51
48
 
52
 
#include <libempathy/empathy-idle.h>
 
49
#include <libempathy/empathy-presence-manager.h>
53
50
#include <libempathy/empathy-utils.h>
54
51
#include <libempathy/empathy-chatroom-manager.h>
55
52
#include <libempathy/empathy-account-settings.h>
56
53
#include <libempathy/empathy-connectivity.h>
57
54
#include <libempathy/empathy-connection-managers.h>
58
 
#include <libempathy/empathy-dispatcher.h>
 
55
#include <libempathy/empathy-request-util.h>
59
56
#include <libempathy/empathy-ft-factory.h>
60
57
#include <libempathy/empathy-gsettings.h>
61
58
#include <libempathy/empathy-tp-chat.h>
62
59
 
63
60
#include <libempathy-gtk/empathy-ui-utils.h>
64
61
#include <libempathy-gtk/empathy-location-manager.h>
65
 
#include <libempathy-gtk/empathy-theme-manager.h>
66
62
 
67
63
#include "empathy-main-window.h"
68
64
#include "empathy-accounts-common.h"
69
65
#include "empathy-accounts-dialog.h"
70
 
#include "empathy-chat-manager.h"
71
66
#include "empathy-status-icon.h"
72
67
#include "empathy-ft-manager.h"
 
68
#include "empathy-notifications-approver.h"
73
69
 
74
70
#include "extensions/extensions.h"
75
71
 
76
72
#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
77
73
#include <libempathy/empathy-debug.h>
78
74
 
79
 
static gboolean start_hidden = FALSE;
80
 
static gboolean no_connect = FALSE;
 
75
#define EMPATHY_DBUS_NAME "org.gnome.Empathy"
 
76
 
 
77
#define EMPATHY_TYPE_APP (empathy_app_get_type ())
 
78
#define EMPATHY_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EMPATHY_TYPE_APP, EmpathyApp))
 
79
#define EMPATHY_APP_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), EMPATHY_TYPE_APP, EmpathyAppClass))
 
80
#define EMPATHY_IS_EMPATHY_APP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EMPATHY_TYPE_APP))
 
81
#define EMPATHY_IS_EMPATHY_APP_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), EMPATHY_TYPE_APP))
 
82
#define EMPATHY_APP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_APP, EmpathyAppClass))
 
83
 
 
84
typedef struct _EmpathyApp EmpathyApp;
 
85
typedef struct _EmpathyAppClass EmpathyAppClass;
 
86
 
 
87
enum
 
88
{
 
89
  PROP_NO_CONNECT = 1,
 
90
  PROP_START_HIDDEN
 
91
};
 
92
 
 
93
GType empathy_app_get_type (void);
 
94
 
 
95
struct _EmpathyAppClass
 
96
{
 
97
  GtkApplicationClass parent_class;
 
98
};
 
99
 
 
100
struct _EmpathyApp
 
101
{
 
102
  GtkApplication parent;
 
103
 
 
104
  /* Properties */
 
105
  gboolean no_connect;
 
106
  gboolean start_hidden;
 
107
 
 
108
  gboolean activated;
 
109
 
 
110
  GtkWidget *window;
 
111
  EmpathyStatusIcon *icon;
 
112
  TpAccountManager *account_manager;
 
113
  TplLogManager *log_manager;
 
114
  EmpathyChatroomManager *chatroom_manager;
 
115
  EmpathyFTFactory  *ft_factory;
 
116
  EmpathyPresenceManager *presence_mgr;
 
117
  EmpathyConnectivity *connectivity;
 
118
  GSettings *gsettings;
 
119
  EmpathyNotificationsApprover *notifications_approver;
 
120
#ifdef HAVE_GEOCLUE
 
121
  EmpathyLocationManager *location_manager;
 
122
#endif
 
123
#ifdef ENABLE_DEBUG
 
124
  TpDebugSender *debug_sender;
 
125
#endif
 
126
};
 
127
 
 
128
 
 
129
G_DEFINE_TYPE(EmpathyApp, empathy_app, GTK_TYPE_APPLICATION)
 
130
 
 
131
static void
 
132
empathy_app_dispose (GObject *object)
 
133
{
 
134
  EmpathyApp *self = EMPATHY_APP (object);
 
135
  void (*dispose) (GObject *) =
 
136
    G_OBJECT_CLASS (empathy_app_parent_class)->dispose;
 
137
 
 
138
  if (self->presence_mgr != NULL)
 
139
    {
 
140
      empathy_presence_manager_set_state (self->presence_mgr,
 
141
          TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
 
142
    }
 
143
 
 
144
#ifdef ENABLE_DEBUG
 
145
  tp_clear_object (&self->debug_sender);
 
146
#endif
 
147
 
 
148
  tp_clear_object (&self->presence_mgr);
 
149
  tp_clear_object (&self->connectivity);
 
150
  tp_clear_object (&self->icon);
 
151
  tp_clear_object (&self->account_manager);
 
152
  tp_clear_object (&self->log_manager);
 
153
  tp_clear_object (&self->chatroom_manager);
 
154
#ifdef HAVE_GEOCLUE
 
155
  tp_clear_object (&self->location_manager);
 
156
#endif
 
157
  tp_clear_object (&self->ft_factory);
 
158
  tp_clear_object (&self->gsettings);
 
159
  tp_clear_object (&self->notifications_approver);
 
160
 
 
161
  if (dispose != NULL)
 
162
    dispose (object);
 
163
}
 
164
 
 
165
static void
 
166
empathy_app_finalize (GObject *object)
 
167
{
 
168
  EmpathyApp *self = EMPATHY_APP (object);
 
169
  void (*finalize) (GObject *) =
 
170
    G_OBJECT_CLASS (empathy_app_parent_class)->finalize;
 
171
 
 
172
  if (self->window != NULL)
 
173
    gtk_widget_destroy (self->window);
 
174
 
 
175
  if (finalize != NULL)
 
176
    finalize (object);
 
177
}
81
178
 
82
179
static void account_manager_ready_cb (GObject *source_object,
83
180
    GAsyncResult *result,
84
181
    gpointer user_data);
85
182
 
86
183
static void
 
184
empathy_app_set_property (GObject *object,
 
185
    guint prop_id,
 
186
    const GValue *value,
 
187
    GParamSpec *pspec)
 
188
{
 
189
  EmpathyApp *self = EMPATHY_APP (object);
 
190
 
 
191
  switch (prop_id)
 
192
    {
 
193
      case PROP_NO_CONNECT:
 
194
        self->no_connect = g_value_get_boolean (value);
 
195
        break;
 
196
      case PROP_START_HIDDEN:
 
197
        self->start_hidden = g_value_get_boolean (value);
 
198
        break;
 
199
      default:
 
200
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
201
        break;
 
202
    }
 
203
}
 
204
 
 
205
static void
 
206
new_incoming_transfer_cb (EmpathyFTFactory *factory,
 
207
    EmpathyFTHandler *handler,
 
208
    GError *error,
 
209
    gpointer user_data)
 
210
{
 
211
  if (error)
 
212
    empathy_ft_manager_display_error (handler, error);
 
213
  else
 
214
    empathy_receive_file_with_file_chooser (handler);
 
215
}
 
216
 
 
217
static void
 
218
new_ft_handler_cb (EmpathyFTFactory *factory,
 
219
    EmpathyFTHandler *handler,
 
220
    GError *error,
 
221
    gpointer user_data)
 
222
{
 
223
  if (error)
 
224
    empathy_ft_manager_display_error (handler, error);
 
225
  else
 
226
    empathy_ft_manager_add_handler (handler);
 
227
 
 
228
  g_object_unref (handler);
 
229
}
 
230
 
 
231
static int
 
232
empathy_app_command_line (GApplication *app,
 
233
    GApplicationCommandLine *cmdline)
 
234
{
 
235
  EmpathyApp *self = (EmpathyApp *) app;
 
236
 
 
237
  if (!self->activated)
 
238
    {
 
239
      GError *error = NULL;
 
240
 
 
241
      /* Create the FT factory */
 
242
      self->ft_factory = empathy_ft_factory_dup_singleton ();
 
243
      g_signal_connect (self->ft_factory, "new-ft-handler",
 
244
          G_CALLBACK (new_ft_handler_cb), NULL);
 
245
      g_signal_connect (self->ft_factory, "new-incoming-transfer",
 
246
          G_CALLBACK (new_incoming_transfer_cb), NULL);
 
247
 
 
248
      if (!empathy_ft_factory_register (self->ft_factory, &error))
 
249
        {
 
250
          g_warning ("Failed to register FileTransfer handler: %s",
 
251
              error->message);
 
252
          g_error_free (error);
 
253
        }
 
254
 
 
255
      g_application_hold (G_APPLICATION (app));
 
256
      self->activated = TRUE;
 
257
 
 
258
      /* Setting up UI */
 
259
      self->window = empathy_main_window_dup ();
 
260
      gtk_widget_show (self->window);
 
261
      self->icon = empathy_status_icon_new (GTK_WINDOW (self->window),
 
262
          self->start_hidden);
 
263
 
 
264
      self->notifications_approver =
 
265
        empathy_notifications_approver_dup_singleton ();
 
266
    }
 
267
  else
 
268
    {
 
269
      /* We're requested to show stuff again, disable the start hidden global in
 
270
       * case the accounts wizard wants to pop up.
 
271
       */
 
272
      self->start_hidden = FALSE;
 
273
    }
 
274
 
 
275
  if (!self->start_hidden)
 
276
    empathy_window_present (GTK_WINDOW (self->window));
 
277
 
 
278
  /* Display the accounts dialog if needed */
 
279
  tp_account_manager_prepare_async (self->account_manager, NULL,
 
280
      account_manager_ready_cb, self);
 
281
 
 
282
  return 0;
 
283
}
 
284
 
 
285
static gboolean
 
286
show_version_cb (const char *option_name,
 
287
    const char *value,
 
288
    gpointer data,
 
289
    GError **error);
 
290
 
 
291
static gboolean
 
292
empathy_app_local_command_line (GApplication *app,
 
293
    gchar ***arguments,
 
294
    gint *exit_status)
 
295
{
 
296
  EmpathyApp *self = (EmpathyApp *) app;
 
297
  gint i;
 
298
  gchar **argv;
 
299
  gint argc = 0;
 
300
  gboolean retval = FALSE;
 
301
  GError *error = NULL;
 
302
  gboolean no_connect = FALSE, start_hidden = FALSE;
 
303
 
 
304
  GOptionContext *optcontext;
 
305
  GOptionEntry options[] = {
 
306
      { "no-connect", 'n',
 
307
        0, G_OPTION_ARG_NONE, &no_connect,
 
308
        N_("Don't connect on startup"),
 
309
        NULL },
 
310
      { "start-hidden", 'h',
 
311
        0, G_OPTION_ARG_NONE, &start_hidden,
 
312
        N_("Don't display the contact list or any other dialogs on startup"),
 
313
        NULL },
 
314
      { "version", 'v',
 
315
        G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, show_version_cb,
 
316
        NULL, NULL },
 
317
      { NULL }
 
318
  };
 
319
 
 
320
  optcontext = g_option_context_new (N_("- Empathy IM Client"));
 
321
  g_option_context_add_group (optcontext, gtk_get_option_group (TRUE));
 
322
  g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE);
 
323
 
 
324
  argv = *arguments;
 
325
  for (i = 0; argv[i] != NULL; i++)
 
326
    argc++;
 
327
 
 
328
  if (!g_option_context_parse (optcontext, &argc, &argv, &error))
 
329
    {
 
330
      g_print ("%s\nRun '%s --help' to see a full list of available command "
 
331
          "line options.\n",
 
332
          error->message, argv[0]);
 
333
      g_warning ("Error in empathy init: %s", error->message);
 
334
 
 
335
      *exit_status = EXIT_FAILURE;
 
336
      retval = TRUE;
 
337
    }
 
338
 
 
339
  g_option_context_free (optcontext);
 
340
 
 
341
  self->no_connect = no_connect;
 
342
  self->start_hidden = start_hidden;
 
343
 
 
344
  return retval;
 
345
}
 
346
 
 
347
static void empathy_app_constructed (GObject *object);
 
348
 
 
349
static void
 
350
empathy_app_class_init (EmpathyAppClass *klass)
 
351
{
 
352
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
353
  GApplicationClass *g_app_class = G_APPLICATION_CLASS (klass);
 
354
  GParamSpec *spec;
 
355
 
 
356
  gobject_class->set_property = empathy_app_set_property;
 
357
  gobject_class->constructed = empathy_app_constructed;
 
358
  gobject_class->dispose = empathy_app_dispose;
 
359
  gobject_class->finalize = empathy_app_finalize;
 
360
 
 
361
  g_app_class->command_line = empathy_app_command_line;
 
362
  g_app_class->local_command_line = empathy_app_local_command_line;
 
363
 
 
364
  spec = g_param_spec_boolean ("no-connect", "no connect",
 
365
      "Don't connect on startup",
 
366
      FALSE,
 
367
      G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
 
368
  g_object_class_install_property (gobject_class, PROP_NO_CONNECT, spec);
 
369
 
 
370
  spec = g_param_spec_boolean ("start-hidden", "start hidden",
 
371
      "Don't display the contact list or any other dialogs on startup",
 
372
      FALSE,
 
373
      G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
 
374
  g_object_class_install_property (gobject_class, PROP_START_HIDDEN, spec);
 
375
}
 
376
 
 
377
static void
 
378
empathy_app_init (EmpathyApp *self)
 
379
{
 
380
}
 
381
 
 
382
static void
87
383
use_conn_notify_cb (GSettings *gsettings,
88
384
    const gchar *key,
89
385
    gpointer     user_data)
163
459
}
164
460
 
165
461
static void
166
 
show_accounts_ui (GdkScreen *screen,
 
462
show_accounts_ui (EmpathyApp *self,
 
463
    GdkScreen *screen,
167
464
    gboolean if_needed)
168
465
{
169
466
  empathy_accounts_dialog_show_application (screen,
170
 
      NULL, if_needed, start_hidden);
171
 
}
172
 
 
173
 
static UniqueResponse
174
 
unique_app_message_cb (UniqueApp *unique_app,
175
 
    gint command,
176
 
    UniqueMessageData *data,
177
 
    guint timestamp,
178
 
    gpointer user_data)
179
 
{
180
 
  GtkWindow *window = user_data;
181
 
  TpAccountManager *account_manager;
182
 
 
183
 
  DEBUG ("Other instance launched, presenting the main window. "
184
 
      "Command=%d, timestamp %u", command, timestamp);
185
 
 
186
 
  /* XXX: the standalone app somewhat breaks this case, since
187
 
   * communicating it would be a pain */
188
 
 
189
 
  /* We're requested to show stuff again, disable the start hidden global
190
 
   * in case the accounts wizard wants to pop up.
191
 
   */
192
 
  start_hidden = FALSE;
193
 
 
194
 
  gtk_window_set_screen (GTK_WINDOW (window),
195
 
      unique_message_data_get_screen (data));
196
 
  gtk_window_set_startup_id (GTK_WINDOW (window),
197
 
      unique_message_data_get_startup_id (data));
198
 
  gtk_window_present_with_time (GTK_WINDOW (window), timestamp);
199
 
  gtk_window_set_skip_taskbar_hint (window, FALSE);
200
 
 
201
 
  account_manager = tp_account_manager_dup ();
202
 
  tp_account_manager_prepare_async (account_manager, NULL,
203
 
      account_manager_ready_cb, NULL);
204
 
  g_object_unref (account_manager);
205
 
 
206
 
  return UNIQUE_RESPONSE_OK;
207
 
}
208
 
 
209
 
static gboolean show_version_cb (const char *option_name,
210
 
    const char *value,
211
 
    gpointer data,
212
 
    GError **error) G_GNUC_NORETURN;
 
467
      NULL, if_needed, self->start_hidden);
 
468
}
213
469
 
214
470
static gboolean
215
471
show_version_cb (const char *option_name,
223
479
}
224
480
 
225
481
static void
226
 
new_incoming_transfer_cb (EmpathyFTFactory *factory,
227
 
    EmpathyFTHandler *handler,
228
 
    GError *error,
229
 
    gpointer user_data)
230
 
{
231
 
  if (error)
232
 
    empathy_ft_manager_display_error (handler, error);
233
 
  else
234
 
    empathy_receive_file_with_file_chooser (handler);
235
 
}
236
 
 
237
 
static void
238
 
new_ft_handler_cb (EmpathyFTFactory *factory,
239
 
    EmpathyFTHandler *handler,
240
 
    GError *error,
241
 
    gpointer user_data)
242
 
{
243
 
  if (error)
244
 
    empathy_ft_manager_display_error (handler, error);
245
 
  else
246
 
    empathy_ft_manager_add_handler (handler);
247
 
 
248
 
  g_object_unref (handler);
249
 
}
250
 
 
251
 
static void
252
482
account_manager_ready_cb (GObject *source_object,
253
483
    GAsyncResult *result,
254
484
    gpointer user_data)
255
485
{
256
486
  TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
 
487
  EmpathyApp *self = user_data;
257
488
  GError *error = NULL;
258
 
  EmpathyIdle *idle;
259
 
  EmpathyConnectivity *connectivity;
260
489
  TpConnectionPresenceType presence;
261
 
  GSettings *gsettings = g_settings_new (EMPATHY_PREFS_SCHEMA);
262
490
 
263
491
  if (!tp_account_manager_prepare_finish (manager, result, &error))
264
492
    {
 
493
      GtkWidget *dialog;
 
494
 
265
495
      DEBUG ("Failed to prepare account manager: %s", error->message);
 
496
 
 
497
      dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
 
498
          GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
 
499
          _("Error contacting the Account Manager"));
 
500
      gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
 
501
          _("There was an error while trying to connect to the Telepathy "
 
502
            "Account Manager. The error was:\n\n%s"),
 
503
          error->message);
 
504
 
 
505
      gtk_dialog_run (GTK_DIALOG (dialog));
 
506
      gtk_widget_destroy (dialog);
 
507
 
266
508
      g_error_free (error);
267
509
      return;
268
510
    }
269
511
 
270
512
  /* Autoconnect */
271
 
  idle = empathy_idle_dup_singleton ();
272
 
  connectivity = empathy_connectivity_dup_singleton ();
273
 
 
274
513
  presence = tp_account_manager_get_most_available_presence (manager, NULL,
275
514
      NULL);
276
515
 
277
 
  if (g_settings_get_boolean (gsettings, EMPATHY_PREFS_AUTOCONNECT) &&
278
 
      !no_connect &&
 
516
  if (g_settings_get_boolean (self->gsettings, EMPATHY_PREFS_AUTOCONNECT) &&
 
517
      !self->no_connect &&
279
518
      tp_connection_presence_type_cmp_availability
280
519
          (presence, TP_CONNECTION_PRESENCE_TYPE_OFFLINE)
281
520
            <= 0)
282
521
      /* if current state is Offline, then put it online */
283
 
      empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE);
 
522
      empathy_presence_manager_set_state (self->presence_mgr,
 
523
          TP_CONNECTION_PRESENCE_TYPE_AVAILABLE);
284
524
 
285
525
  /* Pop up the accounts dialog if we don't have any account */
286
526
  if (!empathy_accounts_has_accounts (manager))
287
 
    show_accounts_ui (gdk_screen_get_default (), TRUE);
288
 
 
289
 
  g_object_unref (idle);
290
 
  g_object_unref (connectivity);
291
 
  g_object_unref (gsettings);
 
527
    show_accounts_ui (self, gdk_screen_get_default (), TRUE);
292
528
}
293
529
 
294
530
static void
316
552
      if (!empathy_chatroom_get_auto_connect (room))
317
553
        continue;
318
554
 
319
 
      empathy_dispatcher_join_muc (account,
320
 
        empathy_chatroom_get_room (room), TP_USER_ACTION_TIME_NOT_USER_ACTION);
 
555
      empathy_join_muc (account, empathy_chatroom_get_room (room),
 
556
        TP_USER_ACTION_TIME_NOT_USER_ACTION);
321
557
    }
322
558
  g_list_free (chatrooms);
323
559
}
331
567
    GHashTable *details,
332
568
    EmpathyChatroomManager *manager)
333
569
{
334
 
  if (new_status != TP_CONNECTION_STATUS_CONNECTED)
335
 
    return;
336
 
 
337
570
  account_join_chatrooms (account, manager);
338
571
}
339
572
 
382
615
}
383
616
 
384
617
static void
385
 
empathy_idle_set_auto_away_cb (GSettings *gsettings,
 
618
empathy_presence_manager_set_auto_away_cb (GSettings *gsettings,
386
619
                                const gchar *key,
387
620
                                gpointer user_data)
388
621
{
389
 
        EmpathyIdle *idle = user_data;
 
622
        EmpathyPresenceManager *presence_mgr = user_data;
390
623
 
391
 
        empathy_idle_set_auto_away (idle,
 
624
        empathy_presence_manager_set_auto_away (presence_mgr,
392
625
      g_settings_get_boolean (gsettings, key));
393
626
}
394
627
 
395
 
int
396
 
main (int argc, char *argv[])
 
628
static void
 
629
empathy_app_constructed (GObject *object)
397
630
{
398
 
#ifdef HAVE_GEOCLUE
399
 
  EmpathyLocationManager *location_manager = NULL;
400
 
#endif
401
 
  EmpathyStatusIcon *icon;
402
 
  EmpathyDispatcher *dispatcher;
403
 
  TpAccountManager *account_manager;
404
 
  TplLogManager *log_manager;
405
 
  EmpathyChatroomManager *chatroom_manager;
406
 
  EmpathyFTFactory  *ft_factory;
407
 
  GtkWidget *window;
408
 
  EmpathyIdle *idle;
409
 
  EmpathyConnectivity *connectivity;
410
 
  EmpathyChatManager *chat_manager;
411
 
  GError *error = NULL;
412
 
  UniqueApp *unique_app;
 
631
  EmpathyApp *self = (EmpathyApp *) object;
413
632
  gboolean chatroom_manager_ready;
414
 
  gboolean autoaway = TRUE;
415
 
#ifdef ENABLE_DEBUG
416
 
  TpDebugSender *debug_sender;
417
 
#endif
418
 
  GSettings *gsettings;
419
 
  EmpathyThemeManager *theme_mgr;
420
 
 
421
 
  GOptionContext *optcontext;
422
 
  GOptionEntry options[] = {
423
 
      { "no-connect", 'n',
424
 
        0, G_OPTION_ARG_NONE, &no_connect,
425
 
        N_("Don't connect on startup"),
426
 
        NULL },
427
 
      { "start-hidden", 'h',
428
 
        0, G_OPTION_ARG_NONE, &start_hidden,
429
 
        N_("Don't display the contact list or any other dialogs on startup"),
430
 
        NULL },
431
 
      { "version", 'v',
432
 
        G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, show_version_cb,
433
 
        NULL, NULL },
434
 
      { NULL }
435
 
  };
436
 
 
437
 
  /* Init */
438
 
  g_thread_init (NULL);
439
 
 
440
 
#ifdef HAVE_LIBCHAMPLAIN
441
 
  gtk_clutter_init (&argc, &argv);
442
 
#endif
443
 
 
444
 
  g_type_init ();
445
 
  tpy_cli_init ();
446
 
  empathy_init ();
447
 
 
448
 
  optcontext = g_option_context_new (N_("- Empathy IM Client"));
449
 
  g_option_context_add_group (optcontext, gtk_get_option_group (TRUE));
450
 
  g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE);
451
 
 
452
 
  if (!g_option_context_parse (optcontext, &argc, &argv, &error)) {
453
 
    g_print ("%s\nRun '%s --help' to see a full list of available command line options.\n",
454
 
        error->message, argv[0]);
455
 
    g_warning ("Error in empathy init: %s", error->message);
456
 
    return EXIT_FAILURE;
457
 
  }
458
 
 
459
 
  g_option_context_free (optcontext);
460
 
 
461
 
  empathy_gtk_init ();
 
633
  gboolean autoaway;
 
634
 
462
635
  g_set_application_name (_(PACKAGE_NAME));
463
636
 
464
637
  gtk_window_set_default_icon_name ("empathy");
466
639
 
467
640
#ifdef ENABLE_DEBUG
468
641
  /* Set up debug sender */
469
 
  debug_sender = tp_debug_sender_dup ();
 
642
  self->debug_sender = tp_debug_sender_dup ();
470
643
  g_log_set_default_handler (tp_debug_sender_log_handler, G_LOG_DOMAIN);
471
644
#endif
472
645
 
473
 
  unique_app = unique_app_new ("org.gnome."PACKAGE_NAME, NULL);
474
 
 
475
 
  if (unique_app_is_running (unique_app))
476
 
    {
477
 
      if (unique_app_send_message (unique_app, UNIQUE_ACTIVATE, NULL) ==
478
 
          UNIQUE_RESPONSE_OK)
479
 
        {
480
 
          g_object_unref (unique_app);
481
 
          return EXIT_SUCCESS;
482
 
        }
483
 
    }
484
 
 
485
646
  notify_init (_(PACKAGE_NAME));
486
647
 
487
648
  /* Setting up Idle */
488
 
  idle = empathy_idle_dup_singleton ();
489
 
 
490
 
  gsettings = g_settings_new (EMPATHY_PREFS_SCHEMA);
491
 
  autoaway = g_settings_get_boolean (gsettings, EMPATHY_PREFS_AUTOAWAY);
492
 
 
493
 
  g_signal_connect (gsettings,
 
649
  self->presence_mgr = empathy_presence_manager_dup_singleton ();
 
650
 
 
651
  self->gsettings = g_settings_new (EMPATHY_PREFS_SCHEMA);
 
652
  autoaway = g_settings_get_boolean (self->gsettings, EMPATHY_PREFS_AUTOAWAY);
 
653
 
 
654
  g_signal_connect (self->gsettings,
494
655
      "changed::" EMPATHY_PREFS_AUTOAWAY,
495
 
      G_CALLBACK (empathy_idle_set_auto_away_cb), idle);
 
656
      G_CALLBACK (empathy_presence_manager_set_auto_away_cb),
 
657
      self->presence_mgr);
496
658
 
497
 
  empathy_idle_set_auto_away (idle, autoaway);
 
659
  empathy_presence_manager_set_auto_away (self->presence_mgr, autoaway);
498
660
 
499
661
  /* Setting up Connectivity */
500
 
  connectivity = empathy_connectivity_dup_singleton ();
501
 
  use_conn_notify_cb (gsettings, EMPATHY_PREFS_USE_CONN,
502
 
      connectivity);
503
 
  g_signal_connect (gsettings,
 
662
  self->connectivity = empathy_connectivity_dup_singleton ();
 
663
  use_conn_notify_cb (self->gsettings, EMPATHY_PREFS_USE_CONN,
 
664
      self->connectivity);
 
665
  g_signal_connect (self->gsettings,
504
666
      "changed::" EMPATHY_PREFS_USE_CONN,
505
 
      G_CALLBACK (use_conn_notify_cb), connectivity);
 
667
      G_CALLBACK (use_conn_notify_cb), self->connectivity);
506
668
 
507
669
  /* account management */
508
 
  account_manager = tp_account_manager_dup ();
509
 
  tp_account_manager_prepare_async (account_manager, NULL,
510
 
      account_manager_ready_cb, NULL);
511
 
 
512
 
  /* The EmpathyDispatcher doesn't dispatch anything any more but we have to
513
 
   * keep it around as we still use it to request channels */
514
 
  dispatcher = empathy_dispatcher_dup_singleton ();
 
670
  self->account_manager = tp_account_manager_dup ();
 
671
  tp_account_manager_prepare_async (self->account_manager, NULL,
 
672
      account_manager_ready_cb, self);
515
673
 
516
674
  migrate_config_to_xdg_dir ();
517
675
 
518
 
  /* Setting up UI */
519
 
  window = empathy_main_window_dup ();
520
 
  gtk_widget_show (window);
521
 
  icon = empathy_status_icon_new (GTK_WINDOW (window), start_hidden);
522
 
 
523
 
  /* Chat manager */
524
 
  chat_manager = empathy_chat_manager_dup_singleton ();
525
 
 
526
 
  g_signal_connect (unique_app, "message-received",
527
 
      G_CALLBACK (unique_app_message_cb), window);
528
 
 
529
676
  /* Logging */
530
 
  log_manager = tpl_log_manager_dup_singleton ();
531
 
 
532
 
  chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
533
 
 
534
 
  g_object_get (chatroom_manager, "ready", &chatroom_manager_ready, NULL);
 
677
  self->log_manager = tpl_log_manager_dup_singleton ();
 
678
 
 
679
  self->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
 
680
 
 
681
  g_object_get (self->chatroom_manager, "ready", &chatroom_manager_ready, NULL);
535
682
  if (!chatroom_manager_ready)
536
683
    {
537
 
      g_signal_connect (G_OBJECT (chatroom_manager), "notify::ready",
538
 
          G_CALLBACK (chatroom_manager_ready_cb), account_manager);
 
684
      g_signal_connect (G_OBJECT (self->chatroom_manager), "notify::ready",
 
685
          G_CALLBACK (chatroom_manager_ready_cb), self->account_manager);
539
686
    }
540
687
  else
541
688
    {
542
 
      chatroom_manager_ready_cb (chatroom_manager, NULL, account_manager);
543
 
    }
544
 
 
545
 
  /* Create the FT factory */
546
 
  ft_factory = empathy_ft_factory_dup_singleton ();
547
 
  g_signal_connect (ft_factory, "new-ft-handler",
548
 
      G_CALLBACK (new_ft_handler_cb), NULL);
549
 
  g_signal_connect (ft_factory, "new-incoming-transfer",
550
 
      G_CALLBACK (new_incoming_transfer_cb), NULL);
551
 
 
552
 
  if (!empathy_ft_factory_register (ft_factory, &error))
553
 
    {
554
 
      g_warning ("Failed to register FileTransfer handler: %s", error->message);
555
 
      g_error_free (error);
 
689
      chatroom_manager_ready_cb (self->chatroom_manager, NULL,
 
690
          self->account_manager);
556
691
    }
557
692
 
558
693
  /* Location mananger */
559
694
#ifdef HAVE_GEOCLUE
560
 
  location_manager = empathy_location_manager_dup_singleton ();
561
 
#endif
562
 
 
563
 
  /* Keep the theme manager alive as it does some caching */
564
 
  theme_mgr = empathy_theme_manager_dup_singleton ();
565
 
 
566
 
  gtk_main ();
567
 
 
568
 
  empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
569
 
 
570
 
#ifdef ENABLE_DEBUG
571
 
  g_object_unref (debug_sender);
572
 
#endif
573
 
 
574
 
  g_object_unref (chat_manager);
575
 
  g_object_unref (idle);
576
 
  g_object_unref (connectivity);
577
 
  g_object_unref (icon);
578
 
  g_object_unref (account_manager);
579
 
  g_object_unref (log_manager);
580
 
  g_object_unref (dispatcher);
581
 
  g_object_unref (chatroom_manager);
582
 
#ifdef HAVE_GEOCLUE
583
 
  g_object_unref (location_manager);
584
 
#endif
585
 
  g_object_unref (ft_factory);
586
 
  g_object_unref (unique_app);
587
 
  g_object_unref (gsettings);
588
 
  g_object_unref (theme_mgr);
589
 
  gtk_widget_destroy (window);
 
695
  self->location_manager = empathy_location_manager_dup_singleton ();
 
696
#endif
 
697
 
 
698
  self->activated = FALSE;
 
699
  self->ft_factory = NULL;
 
700
  self->window = NULL;
 
701
}
 
702
 
 
703
int
 
704
main (int argc, char *argv[])
 
705
{
 
706
  EmpathyApp *app;
 
707
  gint retval;
 
708
 
 
709
  g_thread_init (NULL);
 
710
  g_type_init ();
 
711
 
 
712
#ifdef HAVE_LIBCHAMPLAIN
 
713
  gtk_clutter_init (&argc, &argv);
 
714
#endif
 
715
 
 
716
  empathy_init ();
 
717
  gtk_init (&argc, &argv);
 
718
  empathy_gtk_init ();
 
719
 
 
720
  app = g_object_new (EMPATHY_TYPE_APP,
 
721
      "application-id", EMPATHY_DBUS_NAME,
 
722
      "flags", G_APPLICATION_HANDLES_COMMAND_LINE,
 
723
      NULL);
 
724
 
 
725
  retval = g_application_run (G_APPLICATION (app), argc, argv);
590
726
 
591
727
  notify_uninit ();
592
728
  xmlCleanupParser ();
593
729
 
594
 
  return EXIT_SUCCESS;
 
730
  g_object_unref (app);
 
731
 
 
732
  return retval;
595
733
}