*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
* Authors: Martyn Russell <martyn@imendio.com>
* Xavier Claessens <xclaesse@gmail.com>
*/
#include <gtk/gtk.h>
#include <glib.h>
#include <glib/gi18n.h>
-
-#include <libmissioncontrol/mission-control.h>
-#include <libmissioncontrol/mc-account.h>
-#include <libmissioncontrol/mc-profile.h>
+#include <glib/gprintf.h>
#include <libempathy/empathy-tp-roomlist.h>
#include <libempathy/empathy-chatroom.h>
GtkWidget *treeview;
GtkTreeModel *model;
GtkWidget *button_join;
- GtkWidget *button_close;
+ GtkWidget *label_error_message;
+ GtkWidget *viewport_error;
} EmpathyNewChatroomDialog;
enum {
COL_NAME,
COL_ROOM,
COL_MEMBERS,
- COL_TOOL_TIP,
+ COL_MEMBERS_INT,
+ COL_TOOLTIP,
COL_COUNT
};
static void new_chatroom_dialog_listing_cb (EmpathyTpRoomlist *room_list,
gpointer unused,
EmpathyNewChatroomDialog *dialog);
+static void start_listing_error_cb (EmpathyTpRoomlist *room_list,
+ GError *error,
+ EmpathyNewChatroomDialog *dialog);
+static void stop_listing_error_cb (EmpathyTpRoomlist *room_list,
+ GError *error,
+ EmpathyNewChatroomDialog *dialog);
static void new_chatroom_dialog_model_clear (EmpathyNewChatroomDialog *dialog);
static void new_chatroom_dialog_model_row_activated_cb (GtkTreeView *tree_view,
GtkTreePath *path,
static gboolean new_chatroom_dialog_entry_server_focus_out_cb (GtkWidget *widget,
GdkEventFocus *event,
EmpathyNewChatroomDialog *dialog);
+static void new_chatroom_dialog_button_close_error_clicked_cb (GtkButton *button,
+ EmpathyNewChatroomDialog *dialog);
static EmpathyNewChatroomDialog *dialog_p = NULL;
"treeview", &dialog->treeview,
"button_join", &dialog->button_join,
"expander_browse", &dialog->expander_browse,
+ "label_error_message", &dialog->label_error_message,
+ "viewport_error", &dialog->viewport_error,
NULL);
g_free (filename);
"entry_server", "focus-out-event", new_chatroom_dialog_entry_server_focus_out_cb,
"entry_room", "changed", new_chatroom_dialog_entry_changed_cb,
"expander_browse", "activate", new_chatroom_dialog_expander_browse_activate_cb,
+ "button_close_error", "clicked", new_chatroom_dialog_button_close_error_clicked_cb,
NULL);
g_object_unref (gui);
if (dialog->room_list) {
g_object_unref (dialog->room_list);
}
- g_object_unref (dialog->model);
+ g_object_unref (dialog->model);
g_free (dialog);
}
G_TYPE_STRING, /* Name */
G_TYPE_STRING, /* Room */
G_TYPE_STRING, /* Member count */
+ G_TYPE_INT, /* Member count int */
G_TYPE_STRING); /* Tool tip */
dialog->model = GTK_TREE_MODEL (store);
gtk_tree_view_set_model (view, dialog->model);
- gtk_tree_view_set_tooltip_column (view, COL_TOOL_TIP);
+ gtk_tree_view_set_tooltip_column (view, COL_TOOLTIP);
gtk_tree_view_set_search_column (view, COL_NAME);
/* Selection */
GtkTreeView *view;
GtkTreeViewColumn *column;
GtkCellRenderer *cell;
- gint width, height;
+ gint width, height;
gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height);
"height", height,
"stock-size", GTK_ICON_SIZE_MENU,
NULL);
- column = gtk_tree_view_column_new_with_attributes (_(" "),
+ column = gtk_tree_view_column_new_with_attributes (NULL,
cell,
"stock-id", COL_INVITE_ONLY,
NULL);
+
+ gtk_tree_view_column_set_sort_column_id (column, COL_INVITE_ONLY);
gtk_tree_view_append_column (view, column);
- column = gtk_tree_view_column_new_with_attributes (_(" "),
+ column = gtk_tree_view_column_new_with_attributes (NULL,
cell,
"stock-id", COL_NEED_PASSWORD,
NULL);
+
+ gtk_tree_view_column_set_sort_column_id (column, COL_NEED_PASSWORD);
gtk_tree_view_append_column (view, column);
cell = gtk_cell_renderer_text_new ();
"text", COL_NAME,
NULL);
+ gtk_tree_view_column_set_sort_column_id (column, COL_NAME);
gtk_tree_view_column_set_expand (column, TRUE);
gtk_tree_view_append_column (view, column);
cell,
"text", COL_MEMBERS,
NULL);
+
+ gtk_tree_view_column_set_sort_column_id (column, COL_MEMBERS_INT);
gtk_tree_view_append_column (view, column);
}
new_chatroom_dialog_update_widgets (EmpathyNewChatroomDialog *dialog)
{
EmpathyAccountChooser *account_chooser;
- McAccount *account;
- McProfile *profile;
+ EmpathyAccount *account;
const gchar *protocol;
const gchar *room;
-
+
account_chooser = EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser);
- account = empathy_account_chooser_get_account (account_chooser);
- profile = mc_account_get_profile (account);
- protocol = mc_profile_get_protocol_name (profile);
+ account = empathy_account_chooser_dup_account (account_chooser);
+ protocol = empathy_account_get_protocol (account);
gtk_entry_set_text (GTK_ENTRY (dialog->entry_server), "");
gtk_widget_grab_focus (dialog->entry_room);
g_object_unref (account);
- g_object_unref (profile);
}
static void
EmpathyNewChatroomDialog *dialog)
{
EmpathyAccountChooser *account_chooser;
- McAccount *account;
+ EmpathyAccount *account;
gboolean listing = FALSE;
+ gboolean expanded = FALSE;
if (dialog->room_list) {
g_object_unref (dialog->room_list);
+ dialog->room_list = NULL;
}
ephy_spinner_stop (EPHY_SPINNER (dialog->throbber));
new_chatroom_dialog_model_clear (dialog);
account_chooser = EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser);
- account = empathy_account_chooser_get_account (account_chooser);
+ account = empathy_account_chooser_dup_account (account_chooser);
+ if (account == NULL)
+ goto out;
+
dialog->room_list = empathy_tp_roomlist_new (account);
if (dialog->room_list) {
g_signal_connect (dialog->room_list, "notify::is-listing",
G_CALLBACK (new_chatroom_dialog_listing_cb),
dialog);
+ g_signal_connect (dialog->room_list, "error::start",
+ G_CALLBACK (start_listing_error_cb),
+ dialog);
+ g_signal_connect (dialog->room_list, "error::stop",
+ G_CALLBACK (stop_listing_error_cb),
+ dialog);
+
+ expanded = gtk_expander_get_expanded (GTK_EXPANDER (dialog->expander_browse));
+ if (expanded) {
+ gtk_widget_hide (dialog->viewport_error);
+ gtk_widget_set_sensitive (dialog->treeview, TRUE);
+ new_chatroom_dialog_browse_start (dialog);
+ }
listing = empathy_tp_roomlist_is_listing (dialog->room_list);
if (listing) {
}
}
+ g_object_unref (account);
+
+out:
new_chatroom_dialog_update_widgets (dialog);
}
+static void
+new_chatroom_dialog_button_close_error_clicked_cb (GtkButton *button,
+ EmpathyNewChatroomDialog *dialog)
+{
+ gtk_widget_hide (dialog->viewport_error);
+}
+
static void
new_chatroom_dialog_roomlist_destroy_cb (EmpathyTpRoomlist *room_list,
EmpathyNewChatroomDialog *dialog)
GtkTreeIter iter;
gchar *members;
gchar *tooltip;
+ const gchar *need_password;
+ const gchar *invite_only;
DEBUG ("New chatroom listed: %s (%s)",
empathy_chatroom_get_name (chatroom),
selection = gtk_tree_view_get_selection (view);
store = GTK_LIST_STORE (dialog->model);
members = g_strdup_printf ("%d", empathy_chatroom_get_members_count (chatroom));
- tooltip = g_strdup_printf ("<b>%s</b>\nInvite required: %s\nPassword required: %s\nMembers: %s",
- empathy_chatroom_get_name (chatroom),
- empathy_chatroom_get_invite_only (chatroom) ? _("Yes") : _("No"),
- empathy_chatroom_get_need_password (chatroom) ? _("Yes") : _("No"),
- members);
+ tooltip = g_strdup_printf (C_("Room/Join's roomlist tooltip. Parameters"
+ "are a channel name, yes/no, yes/no and a number.",
+ "<b>%s</b>\nInvite required: %s\nPassword required: %s\nMembers: %s"),
+ empathy_chatroom_get_name (chatroom),
+ empathy_chatroom_get_invite_only (chatroom) ? _("Yes") : _("No"),
+ empathy_chatroom_get_need_password (chatroom) ? _("Yes") : _("No"),
+ members);
+ invite_only = (empathy_chatroom_get_invite_only (chatroom) ?
+ GTK_STOCK_INDEX : NULL);
+ need_password = (empathy_chatroom_get_need_password (chatroom) ?
+ GTK_STOCK_DIALOG_AUTHENTICATION : NULL);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
- COL_NEED_PASSWORD, (empathy_chatroom_get_need_password (chatroom) ? GTK_STOCK_DIALOG_AUTHENTICATION : NULL),
- COL_INVITE_ONLY, (empathy_chatroom_get_invite_only (chatroom) ? GTK_STOCK_INDEX : NULL),
+ COL_NEED_PASSWORD, need_password,
+ COL_INVITE_ONLY, invite_only,
COL_NAME, empathy_chatroom_get_name (chatroom),
COL_ROOM, empathy_chatroom_get_room (chatroom),
COL_MEMBERS, members,
- COL_TOOL_TIP, tooltip,
+ COL_MEMBERS_INT, empathy_chatroom_get_members_count (chatroom),
+ COL_TOOLTIP, tooltip,
-1);
g_free (members);
g_free (tooltip);
}
+static void
+start_listing_error_cb (EmpathyTpRoomlist *room_list,
+ GError *error,
+ EmpathyNewChatroomDialog *dialog)
+{
+ gtk_label_set_text (GTK_LABEL (dialog->label_error_message), _("Could not start room listing"));
+ gtk_widget_show_all (dialog->viewport_error);
+ gtk_widget_set_sensitive (dialog->treeview, FALSE);
+}
+
+static void
+stop_listing_error_cb (EmpathyTpRoomlist *room_list,
+ GError *error,
+ EmpathyNewChatroomDialog *dialog)
+{
+ gtk_label_set_text (GTK_LABEL (dialog->label_error_message), _("Could not stop room listing"));
+ gtk_widget_show_all (dialog->viewport_error);
+ gtk_widget_set_sensitive (dialog->treeview, FALSE);
+}
+
static void
new_chatroom_dialog_listing_cb (EmpathyTpRoomlist *room_list,
gpointer unused,
/* Update the throbber */
if (listing) {
- ephy_spinner_start (EPHY_SPINNER (dialog->throbber));
+ ephy_spinner_start (EPHY_SPINNER (dialog->throbber));
} else {
ephy_spinner_stop (EPHY_SPINNER (dialog->throbber));
}
static void
new_chatroom_dialog_model_selection_changed (GtkTreeSelection *selection,
EmpathyNewChatroomDialog *dialog)
-{
+{
GtkTreeModel *model;
GtkTreeIter iter;
gchar *room = NULL;
new_chatroom_dialog_join (EmpathyNewChatroomDialog *dialog)
{
EmpathyAccountChooser *account_chooser;
- McAccount *account;
+ TpConnection *connection;
const gchar *room;
const gchar *server = NULL;
gchar *room_name = NULL;
server = gtk_entry_get_text (GTK_ENTRY (dialog->entry_server));
account_chooser = EMPATHY_ACCOUNT_CHOOSER (dialog->account_chooser);
- account = empathy_account_chooser_get_account (account_chooser);
+ connection = empathy_account_chooser_get_connection (account_chooser);
if (!EMP_STR_EMPTY (server)) {
room_name = g_strconcat (room, "@", server, NULL);
}
DEBUG ("Requesting channel for '%s'", room_name);
- empathy_dispatcher_join_muc (account, room_name, NULL, NULL);
+ empathy_dispatcher_join_muc (connection, room_name, NULL, NULL);
g_free (room_name);
}
new_chatroom_dialog_browse_stop (dialog);
gtk_window_set_resizable (GTK_WINDOW (dialog->window), FALSE);
} else {
+ gtk_widget_hide (dialog->viewport_error);
+ gtk_widget_set_sensitive (dialog->treeview, TRUE);
new_chatroom_dialog_browse_start (dialog);
gtk_window_set_resizable (GTK_WINDOW (dialog->window), TRUE);
}