diff options
-rw-r--r-- | src/empathy-debug-window.c | 335 |
1 files changed, 193 insertions, 142 deletions
diff --git a/src/empathy-debug-window.c b/src/empathy-debug-window.c index 69db2a6ce..affb25974 100644 --- a/src/empathy-debug-window.c +++ b/src/empathy-debug-window.c @@ -46,6 +46,12 @@ G_DEFINE_TYPE (EmpathyDebugWindow, empathy_debug_window, GTK_TYPE_WINDOW) +typedef enum +{ + SERVICE_TYPE_CM = 0, + SERVICE_TYPE_CLIENT, +} ServiceType; + enum { COL_DEBUG_TIMESTAMP = 0, @@ -59,10 +65,10 @@ enum enum { - COL_CM_NAME = 0, - COL_CM_UNIQUE_NAME, - COL_CM_GONE, - NUM_COLS_CM + COL_NAME = 0, + COL_UNIQUE_NAME, + COL_GONE, + NUM_COLS }; enum @@ -76,7 +82,7 @@ enum typedef struct { /* Toolbar items */ - GtkWidget *cm_chooser; + GtkWidget *chooser; GtkToolItem *save_button; GtkToolItem *copy_button; GtkToolItem *clear_button; @@ -85,7 +91,7 @@ typedef struct GtkWidget *level_filter; /* Cache */ - GHashTable *all_cms; + GHashTable *cache; /* TreeView */ GtkListStore *store; @@ -105,8 +111,8 @@ typedef struct /* Whether NewDebugMessage will be fired */ gboolean paused; - /* CM chooser store */ - GtkListStore *cms; + /* Service (CM, Client) chooser store */ + GtkListStore *service_store; /* Misc. */ gboolean dispose_run; @@ -185,17 +191,17 @@ debug_message_list_free (gpointer data) } static gchar * -get_active_cm_name (EmpathyDebugWindow *self) +get_active_service_name (EmpathyDebugWindow *self) { EmpathyDebugWindowPriv *priv = GET_PRIV (self); GtkTreeIter iter; gchar *name; - if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->cm_chooser), &iter)) + if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->chooser), &iter)) return NULL; - gtk_tree_model_get (GTK_TREE_MODEL (priv->cms), &iter, - COL_CM_NAME, &name, -1); + gtk_tree_model_get (GTK_TREE_MODEL (priv->service_store), &iter, + COL_NAME, &name, -1); return name; } @@ -212,13 +218,13 @@ debug_window_cache_new_message (EmpathyDebugWindow *debug_window, DebugMessage *dm; char *name; - name = get_active_cm_name (debug_window); - messages = g_hash_table_lookup (priv->all_cms, name); + name = get_active_service_name (debug_window); + messages = g_hash_table_lookup (priv->cache, name); dm = debug_message_new (timestamp, domain, level, message); messages = g_list_append (messages, dm); - g_hash_table_insert (priv->all_cms, name, messages); + g_hash_table_insert (priv->cache, name, messages); } static void @@ -356,8 +362,8 @@ debug_window_get_messages_cb (TpProxy *proxy, debug_window_set_toolbar_sensitivity (debug_window, TRUE); - name = get_active_cm_name (debug_window); - old_messages = g_hash_table_lookup (priv->all_cms, name); + name = get_active_service_name (debug_window); + old_messages = g_hash_table_lookup (priv->cache, name); /* we call get_messages either when a new CM is added or * when a CM that we've already seen re-appears; in both cases @@ -365,7 +371,7 @@ debug_window_get_messages_cb (TpProxy *proxy, */ if (old_messages != NULL) { - g_hash_table_remove (priv->all_cms, name); + g_hash_table_remove (priv->cache, name); debug_message_list_free (old_messages); } @@ -399,7 +405,7 @@ debug_window_add_log_messages_from_cache (EmpathyDebugWindow *debug_window, DEBUG ("Adding logs from cache for CM %s", name); - messages = g_hash_table_lookup (priv->all_cms, name); + messages = g_hash_table_lookup (priv->cache, name); if (messages == NULL) return; @@ -427,7 +433,7 @@ proxy_invalidated_cb (TpProxy *proxy, } static void -debug_window_cm_chooser_changed_cb (GtkComboBox *cm_chooser, +debug_window_service_chooser_changed_cb (GtkComboBox *chooser, EmpathyDebugWindow *debug_window) { EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window); @@ -436,25 +442,25 @@ debug_window_cm_chooser_changed_cb (GtkComboBox *cm_chooser, gchar *bus_name, *name = NULL; TpProxy *proxy; GtkTreeIter iter; - gboolean cm_gone; + gboolean gone; - if (!gtk_combo_box_get_active_iter (cm_chooser, &iter)) + if (!gtk_combo_box_get_active_iter (chooser, &iter)) { DEBUG ("No CM is selected"); if (gtk_tree_model_iter_n_children ( - GTK_TREE_MODEL (priv->cms), NULL) > 0) + GTK_TREE_MODEL (priv->service_store), NULL) > 0) { - gtk_combo_box_set_active (cm_chooser, 0); + gtk_combo_box_set_active (chooser, 0); } return; } gtk_list_store_clear (priv->store); - gtk_tree_model_get (GTK_TREE_MODEL (priv->cms), &iter, - COL_CM_NAME, &name, COL_CM_GONE, &cm_gone, -1); + gtk_tree_model_get (GTK_TREE_MODEL (priv->service_store), &iter, + COL_NAME, &name, COL_GONE, &gone, -1); - if (cm_gone) + if (gone) { debug_window_add_log_messages_from_cache (debug_window, name); g_free (name); @@ -470,8 +476,8 @@ debug_window_cm_chooser_changed_cb (GtkComboBox *cm_chooser, DEBUG ("Failed at duping the dbus daemon: %s", error->message); } - gtk_tree_model_get (GTK_TREE_MODEL (priv->cms), &iter, - COL_CM_UNIQUE_NAME, &bus_name, -1); + gtk_tree_model_get (GTK_TREE_MODEL (priv->service_store), &iter, + COL_UNIQUE_NAME, &bus_name, -1); proxy = g_object_new (TP_TYPE_PROXY, "bus-name", bus_name, "dbus-daemon", dbus, @@ -518,7 +524,7 @@ typedef struct } CmInModelForeachData; static gboolean -debug_window_cms_foreach (GtkTreeModel *model, +debug_window_service_foreach (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer user_data) @@ -527,7 +533,7 @@ debug_window_cms_foreach (GtkTreeModel *model, gchar *store_name; gtk_tree_model_get (model, iter, - (data->use_name ? COL_CM_NAME : COL_CM_UNIQUE_NAME), + (data->use_name ? COL_NAME : COL_UNIQUE_NAME), &store_name, -1); @@ -545,7 +551,7 @@ debug_window_cms_foreach (GtkTreeModel *model, } static gboolean -debug_window_cm_is_in_model (EmpathyDebugWindow *debug_window, +debug_window_service_is_in_model (EmpathyDebugWindow *debug_window, const gchar *name, GtkTreeIter **iter, gboolean use_name) @@ -560,8 +566,8 @@ debug_window_cm_is_in_model (EmpathyDebugWindow *debug_window, data->found_iter = iter; data->use_name = use_name; - gtk_tree_model_foreach (GTK_TREE_MODEL (priv->cms), - debug_window_cms_foreach, data); + gtk_tree_model_foreach (GTK_TREE_MODEL (priv->service_store), + debug_window_service_foreach, data); found = data->found; @@ -629,8 +635,29 @@ get_cm_display_name (EmpathyDebugWindow *self, typedef struct { EmpathyDebugWindow *debug_window; - gchar *cm_name; -} FillCmChooserData; + gchar *name; + ServiceType type; +} FillServiceChooserData; + +static FillServiceChooserData * +fill_service_chooser_data_new (EmpathyDebugWindow *window, + const gchar *name, + ServiceType type) +{ + FillServiceChooserData * data = g_slice_new (FillServiceChooserData); + + data->debug_window = window; + data->name = g_strdup (name); + data->type = SERVICE_TYPE_CM; + return data; +} + +static void +fill_service_chooser_data_free (FillServiceChooserData *data) +{ + g_free (data->name); + g_slice_free (FillServiceChooserData, data); +} static void debug_window_get_name_owner_cb (TpDBusDaemon *proxy, @@ -639,7 +666,7 @@ debug_window_get_name_owner_cb (TpDBusDaemon *proxy, gpointer user_data, GObject *weak_object) { - FillCmChooserData *data = (FillCmChooserData *) user_data; + FillServiceChooserData *data = (FillServiceChooserData *) user_data; EmpathyDebugWindow *self = EMPATHY_DEBUG_WINDOW (data->debug_window); EmpathyDebugWindowPriv *priv = GET_PRIV (data->debug_window); @@ -649,28 +676,31 @@ debug_window_get_name_owner_cb (TpDBusDaemon *proxy, goto OUT; } - if (!debug_window_cm_is_in_model (data->debug_window, out, NULL, FALSE)) + if (!debug_window_service_is_in_model (data->debug_window, out, NULL, FALSE)) { GtkTreeIter iter; char *name; - DEBUG ("Adding CM to list: %s at unique name: %s", - data->cm_name, out); + DEBUG ("Adding %s to list: %s at unique name: %s", + data->type == SERVICE_TYPE_CM? "CM": "Client", + data->name, out); - name = get_cm_display_name (self, data->cm_name); + if (data->type == SERVICE_TYPE_CM) + name = get_cm_display_name (self, data->name); + else + name = g_strdup (data->name); - gtk_list_store_append (priv->cms, &iter); - gtk_list_store_set (priv->cms, &iter, - COL_CM_NAME, name, - COL_CM_UNIQUE_NAME, out, + gtk_list_store_append (priv->service_store, &iter); + gtk_list_store_set (priv->service_store, &iter, + COL_NAME, name, + COL_UNIQUE_NAME, out, -1); g_free (name); } OUT: - g_free (data->cm_name); - g_slice_free (FillCmChooserData, data); + fill_service_chooser_data_free (data); } static void @@ -704,11 +734,8 @@ debug_window_list_connection_names_cb (const gchar * const *names, for (i = 0; cms[i] != NULL; i++) { - FillCmChooserData *data; - - data = g_slice_new0 (FillCmChooserData); - data->debug_window = debug_window; - data->cm_name = g_strdup (cms[i]); + FillServiceChooserData *data = fill_service_chooser_data_new ( + debug_window, cms[i], SERVICE_TYPE_CM); tp_cli_dbus_daemon_call_get_name_owner (dbus, -1, names[i], debug_window_get_name_owner_cb, @@ -718,9 +745,6 @@ debug_window_list_connection_names_cb (const gchar * const *names, g_object_unref (dbus); } -#define CM_WELL_KNOWN_NAME_PREFIX \ - "org.freedesktop.Telepathy.ConnectionManager." - static void debug_window_name_owner_changed_cb (TpDBusDaemon *proxy, const gchar *arg0, @@ -731,88 +755,131 @@ debug_window_name_owner_changed_cb (TpDBusDaemon *proxy, { EmpathyDebugWindow *self = EMPATHY_DEBUG_WINDOW (user_data); EmpathyDebugWindowPriv *priv = GET_PRIV (user_data); + ServiceType type; + const gchar *name; - /* Wow, I hate all of this code... */ - if (!g_str_has_prefix (arg0, CM_WELL_KNOWN_NAME_PREFIX)) - return; + if (g_str_has_prefix (arg0, TP_CM_BUS_NAME_BASE)) + { + type = SERVICE_TYPE_CM; + name = arg0 + strlen (TP_CM_BUS_NAME_BASE); + } + else if (g_str_has_prefix (arg0, TP_CLIENT_BUS_NAME_BASE)) + { + type = SERVICE_TYPE_CLIENT; + name = arg0 + strlen (TP_CLIENT_BUS_NAME_BASE); + } + else + { + return; + } if (EMP_STR_EMPTY (arg1) && !EMP_STR_EMPTY (arg2)) { - /* A connection manager joined -- because it's guaranteed - * that the CM just joined (because o.fd.Tp.CM.foo - * just joined), we don't need to check whether the unique - * name is in the CM model. Hooray. - */ - const gchar *name = arg0 + strlen (CM_WELL_KNOWN_NAME_PREFIX); - - if (!g_hash_table_lookup (priv->all_cms, name)) + gchar *display_name; + + if (type == SERVICE_TYPE_CM) + display_name = get_cm_display_name (self, name); + else + display_name = g_strdup (name); + + /* A service joined */ + if (!g_hash_table_lookup (priv->cache, name)) { GtkTreeIter iter; - char *str; - - DEBUG ("Adding new CM '%s' at %s.", name, arg2); - str = get_cm_display_name (self, name); + DEBUG ("Adding new service '%s' at %s.", name, arg2); - gtk_list_store_append (priv->cms, &iter); - gtk_list_store_set (priv->cms, &iter, - COL_CM_NAME, str, - COL_CM_UNIQUE_NAME, arg2, + gtk_list_store_append (priv->service_store, &iter); + gtk_list_store_set (priv->service_store, &iter, + COL_NAME, display_name, + COL_UNIQUE_NAME, arg2, -1); - - g_free (str); } else { - /* a CM with the same name is already in the hash table, + /* a service with the same name is already in the hash table, * update it and set it as re-enabled in the model. */ GtkTreeIter *iter = NULL; - if (debug_window_cm_is_in_model (user_data, name, &iter, TRUE)) + if (debug_window_service_is_in_model (user_data, name, &iter, TRUE)) { - char *str; - DEBUG ("Refreshing CM '%s' at '%s'.", name, arg2); - str = get_cm_display_name (self, name); - - gtk_list_store_set (priv->cms, iter, - COL_CM_NAME, str, - COL_CM_UNIQUE_NAME, arg2, - COL_CM_GONE, FALSE, + gtk_list_store_set (priv->service_store, iter, + COL_NAME, display_name, + COL_UNIQUE_NAME, arg2, + COL_GONE, FALSE, -1); gtk_tree_iter_free (iter); - g_free (str); - debug_window_cm_chooser_changed_cb - (GTK_COMBO_BOX (priv->cm_chooser), user_data); + debug_window_service_chooser_changed_cb + (GTK_COMBO_BOX (priv->chooser), user_data); } } + + g_free (display_name); } else if (!EMP_STR_EMPTY (arg1) && EMP_STR_EMPTY (arg2)) { - /* A connection manager died -- because it's guaranteed - * that the CM itself just died (because o.fd.Tp.CM.foo - * just died), we don't need to check that it was already - * in the model. - */ + /* A service died */ GtkTreeIter *iter = NULL; - DEBUG ("Setting CM disabled from %s.", arg1); + DEBUG ("Setting service disabled from %s.", arg1); - /* set the CM as disabled in the model */ - if (debug_window_cm_is_in_model (user_data, arg1, &iter, FALSE)) - { - gtk_list_store_set (priv->cms, - iter, COL_CM_GONE, TRUE, -1); + /* set the service as disabled in the model */ + if (debug_window_service_is_in_model (user_data, arg1, &iter, FALSE)) + { + gtk_list_store_set (priv->service_store, + iter, COL_GONE, TRUE, -1); gtk_tree_iter_free (iter); } } } static void -debug_window_fill_cm_chooser (EmpathyDebugWindow *debug_window) +add_client (EmpathyDebugWindow *self, + const gchar *name) +{ + EmpathyDebugWindowPriv *priv = GET_PRIV (self); + const gchar *suffix; + FillServiceChooserData *data; + + suffix = name + strlen (TP_CLIENT_BUS_NAME_BASE); + + data = fill_service_chooser_data_new (self, suffix, SERVICE_TYPE_CLIENT); + + tp_cli_dbus_daemon_call_get_name_owner (priv->dbus, -1, + name, debug_window_get_name_owner_cb, data, NULL, NULL); +} + +static void +list_names_cb (TpDBusDaemon *bus_daemon, + const gchar * const *names, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + EmpathyDebugWindow *self = EMPATHY_DEBUG_WINDOW (weak_object); + guint i; + + if (error != NULL) + { + DEBUG ("Failed to list names: %s", error->message); + return; + } + + for (i = 0; names[i] != NULL; i++) + { + if (g_str_has_prefix (names[i], TP_CLIENT_BUS_NAME_BASE)) + { + add_client (self, names[i]); + } + } +} + +static void +debug_window_fill_service_chooser (EmpathyDebugWindow *debug_window) { EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window); GError *error = NULL; @@ -827,38 +894,22 @@ debug_window_fill_cm_chooser (EmpathyDebugWindow *debug_window) return; } - /* Add empathy */ - gtk_list_store_append (priv->cms, &iter); - gtk_list_store_set (priv->cms, &iter, - COL_CM_NAME, _(PACKAGE_NAME), - COL_CM_UNIQUE_NAME, "org.gnome."PACKAGE_NAME, - -1); - gtk_combo_box_set_active (GTK_COMBO_BOX (priv->cm_chooser), 0); - /* Add CMs to list */ tp_list_connection_names (priv->dbus, debug_window_list_connection_names_cb, debug_window, NULL, NULL); /* add Mission Control */ - gtk_list_store_append (priv->cms, &iter); - gtk_list_store_set (priv->cms, &iter, - COL_CM_NAME, "misson-control", - COL_CM_UNIQUE_NAME, "org.freedesktop.Telepathy.MissionControl5", + gtk_list_store_append (priv->service_store, &iter); + gtk_list_store_set (priv->service_store, &iter, + COL_NAME, "misson-control", + COL_UNIQUE_NAME, "org.freedesktop.Telepathy.MissionControl5", -1); - /* add the logger */ - gtk_list_store_append (priv->cms, &iter); - gtk_list_store_set (priv->cms, &iter, - COL_CM_NAME, "logger", - COL_CM_UNIQUE_NAME, "org.freedesktop.Telepathy.Client.Logger", - -1); + gtk_combo_box_set_active (GTK_COMBO_BOX (priv->chooser), 0); - /* add Empathy audio/video client */ - gtk_list_store_append (priv->cms, &iter); - gtk_list_store_set (priv->cms, &iter, - COL_CM_NAME, "Audio/Video", - COL_CM_UNIQUE_NAME, "org.freedesktop.Telepathy.Client.Empathy.AudioVideo", - -1); + /* add clients */ + tp_dbus_daemon_list_names (priv->dbus, 2000, + list_names_cb, NULL, NULL, G_OBJECT (debug_window)); priv->name_owner_changed_signal = tp_cli_dbus_daemon_connect_to_name_owner_changed (priv->dbus, @@ -1178,7 +1229,7 @@ debug_window_save_clicked_cb (GtkToolButton *tool_button, gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (file_chooser), g_get_tmp_dir ()); - name = get_active_cm_name (debug_window); + name = get_active_service_name (debug_window); t = time (NULL); tm_s = localtime (&t); @@ -1362,20 +1413,20 @@ am_prepared_cb (GObject *am, gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0); /* CM */ - priv->cm_chooser = gtk_combo_box_new_text (); - priv->cms = gtk_list_store_new (NUM_COLS_CM, G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_BOOLEAN); - gtk_combo_box_set_model (GTK_COMBO_BOX (priv->cm_chooser), - GTK_TREE_MODEL (priv->cms)); - gtk_widget_show (priv->cm_chooser); + priv->chooser = gtk_combo_box_new_text (); + priv->service_store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING, + G_TYPE_STRING, G_TYPE_BOOLEAN); + gtk_combo_box_set_model (GTK_COMBO_BOX (priv->chooser), + GTK_TREE_MODEL (priv->service_store)); + gtk_widget_show (priv->chooser); item = gtk_tool_item_new (); gtk_widget_show (GTK_WIDGET (item)); - gtk_container_add (GTK_CONTAINER (item), priv->cm_chooser); + gtk_container_add (GTK_CONTAINER (item), priv->chooser); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); - g_signal_connect (priv->cm_chooser, "changed", - G_CALLBACK (debug_window_cm_chooser_changed_cb), object); - gtk_widget_show (GTK_WIDGET (priv->cm_chooser)); + g_signal_connect (priv->chooser, "changed", + G_CALLBACK (debug_window_service_chooser_changed_cb), object); + gtk_widget_show (GTK_WIDGET (priv->chooser)); item = gtk_separator_tool_item_new (); gtk_widget_show (GTK_WIDGET (item)); @@ -1555,7 +1606,7 @@ am_prepared_cb (GObject *am, priv->view_visible = FALSE; debug_window_set_toolbar_sensitivity (EMPATHY_DEBUG_WINDOW (object), FALSE); - debug_window_fill_cm_chooser (EMPATHY_DEBUG_WINDOW (object)); + debug_window_fill_service_chooser (EMPATHY_DEBUG_WINDOW (object)); gtk_widget_show (GTK_WIDGET (object)); } @@ -1578,7 +1629,7 @@ empathy_debug_window_init (EmpathyDebugWindow *empathy_debug_window) empathy_debug_window->priv = priv; priv->dispose_run = FALSE; - priv->all_cms = g_hash_table_new_full (g_str_hash, g_str_equal, + priv->cache = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); } @@ -1618,7 +1669,7 @@ debug_window_finalize (GObject *object) char *key; GList *values; - g_hash_table_iter_init (&iter, priv->all_cms); + g_hash_table_iter_init (&iter, priv->cache); while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &values)) @@ -1626,7 +1677,7 @@ debug_window_finalize (GObject *object) debug_message_list_free (values); } - g_hash_table_destroy (priv->all_cms); + g_hash_table_destroy (priv->cache); (G_OBJECT_CLASS (empathy_debug_window_parent_class)->finalize) (object); } @@ -1658,8 +1709,8 @@ debug_window_dispose (GObject *object) if (priv->new_debug_message_signal != NULL) tp_proxy_signal_connection_disconnect (priv->new_debug_message_signal); - if (priv->cms != NULL) - g_object_unref (priv->cms); + if (priv->service_store != NULL) + g_object_unref (priv->service_store); if (priv->dbus != NULL) g_object_unref (priv->dbus); |