示例#1
0
static void
account_chooser_ready_cb (EmpathyAccountChooser *chooser,
			EmpathyLogWindow *window)
{
	gtk_notebook_set_current_page (GTK_NOTEBOOK (window->notebook), 1);
	log_window_chats_set_selected (window, window->selected_account,
				       window->selected_chat_id, window->selected_is_chatroom);
}
示例#2
0
GtkWidget *
empathy_log_window_show (EmpathyAccount   *account,
			const gchar *chat_id,
			gboolean     is_chatroom,
			GtkWindow   *parent)
{
	static EmpathyLogWindow *window = NULL;
	EmpathyAccountChooser   *account_chooser;
	EmpathyAccountManager  *account_manager;
	gint                    account_num;
	GtkBuilder             *gui;
	gchar                  *filename;

	if (window) {
		gtk_window_present (GTK_WINDOW (window->window));

		if (account && chat_id) {
			gtk_notebook_set_current_page (GTK_NOTEBOOK (window->notebook), 1);
			log_window_chats_set_selected (window, account,
						       chat_id, is_chatroom);
		}

		return window->window;
	}

	window = g_new0 (EmpathyLogWindow, 1);
	window->log_manager = empathy_log_manager_dup_singleton ();

	filename = empathy_file_lookup ("empathy-log-window.ui",
					"libempathy-gtk");
	gui = empathy_builder_get_file (filename,
				       "log_window", &window->window,
				       "notebook", &window->notebook,
				       "entry_find", &window->entry_find,
				       "button_find", &window->button_find,
				       "treeview_find", &window->treeview_find,
				       "scrolledwindow_find", &window->scrolledwindow_find,
				       "button_previous", &window->button_previous,
				       "button_next", &window->button_next,
				       "entry_chats", &window->entry_chats,
				       "calendar_chats", &window->calendar_chats,
				       "vbox_chats", &window->vbox_chats,
				       "treeview_chats", &window->treeview_chats,
				       "scrolledwindow_chats", &window->scrolledwindow_chats,
				       NULL);
	g_free (filename);

	empathy_builder_connect (gui, window,
			      "log_window", "destroy", log_window_destroy_cb,
			      "entry_find", "changed", log_window_entry_find_changed_cb,
			      "button_previous", "clicked", log_window_button_previous_clicked_cb,
			      "button_next", "clicked", log_window_button_next_clicked_cb,
			      "button_find", "clicked", log_window_button_find_clicked_cb,
			      "entry_chats", "changed", log_window_entry_chats_changed_cb,
			      "entry_chats", "activate", log_window_entry_chats_activate_cb,
			      NULL);

	g_object_unref (gui);

	g_object_add_weak_pointer (G_OBJECT (window->window),
				   (gpointer) &window);

	/* We set this up here so we can block it when needed. */
	g_signal_connect (window->calendar_chats, "day-selected",
			  G_CALLBACK (log_window_calendar_chats_day_selected_cb),
			  window);
	g_signal_connect (window->calendar_chats, "month-changed",
			  G_CALLBACK (log_window_calendar_chats_month_changed_cb),
			  window);

	/* Configure Search EmpathyChatView */
	window->chatview_find = empathy_theme_manager_create_view (empathy_theme_manager_get ());
	gtk_container_add (GTK_CONTAINER (window->scrolledwindow_find),
			   GTK_WIDGET (window->chatview_find));
	gtk_widget_show (GTK_WIDGET (window->chatview_find));

	/* Configure Contacts EmpathyChatView */
	window->chatview_chats = empathy_theme_manager_create_view (empathy_theme_manager_get ());
	gtk_container_add (GTK_CONTAINER (window->scrolledwindow_chats),
			   GTK_WIDGET (window->chatview_chats));
	gtk_widget_show (GTK_WIDGET (window->chatview_chats));

	/* Account chooser for chats */
	window->account_chooser_chats = empathy_account_chooser_new ();
	account_chooser = EMPATHY_ACCOUNT_CHOOSER (window->account_chooser_chats);

	gtk_box_pack_start (GTK_BOX (window->vbox_chats),
			    window->account_chooser_chats,
			    FALSE, TRUE, 0);

	g_signal_connect (window->account_chooser_chats, "changed",
			  G_CALLBACK (log_window_chats_accounts_changed_cb),
			  window);

	/* Populate */
	account_manager = empathy_account_manager_dup_singleton ();
	account_num = empathy_account_manager_get_count (account_manager);
	g_object_unref (account_manager);

	if (account_num > 1) {
		gtk_widget_show (window->vbox_chats);
		gtk_widget_show (window->account_chooser_chats);
	} else {
		gtk_widget_hide (window->vbox_chats);
		gtk_widget_hide (window->account_chooser_chats);
	}

	/* Search List */
	log_window_find_setup (window);

	/* Contacts */
	log_window_chats_setup (window);
	log_window_chats_populate (window);

	/* Select chat */
	if (account && chat_id) {
		gtk_notebook_set_current_page (GTK_NOTEBOOK (window->notebook), 1);
		log_window_chats_set_selected (window, account,
					       chat_id, is_chatroom);
	}

	if (parent) {
		gtk_window_set_transient_for (GTK_WINDOW (window->window),
					      GTK_WINDOW (parent));
	}

	gtk_widget_show (window->window);

	return window->window;
}
static void
log_manager_got_chats_cb (GObject *manager,
                       GAsyncResult *result,
                       gpointer user_data)
{
	EmpathyLogWindow      *window = user_data;
	GList                 *chats;
	GList                 *l;
	GtkTreeView           *view;
	GtkTreeModel          *model;
	GtkTreeSelection      *selection;
	GtkListStore          *store;
	GtkTreeIter            iter;
	GError                *error = NULL;
	gboolean               select_account = FALSE;

	if (log_window == NULL)
		return;

	if (!tpl_log_manager_get_chats_finish (TPL_LOG_MANAGER (manager),
		result, &chats, &error)) {
			DEBUG ("%s. Aborting", error->message);
			g_error_free (error);
			return;
	}

	view = GTK_TREE_VIEW (window->treeview_chats);
	model = gtk_tree_view_get_model (view);
	selection = gtk_tree_view_get_selection (view);
	store = GTK_LIST_STORE (model);

	for (l = chats; l; l = l->next) {
			TplLogSearchHit *hit;

			hit = l->data;

			if (hit->account == NULL)
				continue;

			gtk_list_store_append (store, &iter);
			gtk_list_store_set (store, &iter,
					COL_CHAT_ICON, "empathy-available", /* FIXME */
					COL_CHAT_NAME, hit->chat_id,
					COL_CHAT_ACCOUNT, hit->account,
					COL_CHAT_ID, hit->chat_id,
					COL_CHAT_IS_CHATROOM, hit->is_chatroom,
					-1);

			if (window->selected_account != NULL &&
			    !tp_strdiff (tp_proxy_get_object_path (hit->account),
			    tp_proxy_get_object_path (window->selected_account)))
				select_account = TRUE;

			/* FIXME: Update COL_CHAT_ICON/NAME */
			if (hit->is_chatroom) {
			} else {
			}
	}
	tpl_log_manager_search_free (chats);

	/* Unblock signals */
	g_signal_handlers_unblock_by_func (selection,
			log_window_chats_changed_cb,
			window);

	/* We display the selected account if we populate the model with chats from
	 * this account. */
	if (select_account)
		log_window_chats_set_selected (window);
}