Re: final account rework
Xavier Claessens <[email protected]> Sun, 01 Oct 2006 21:59:38 +0200
| Newsgroups | gmane.comp.gnome.gossip.devel |
|---|---|
| Message-ID | <1159732778.5791.29.camel@zdra-desktop> |
Le dimanche 01 octobre 2006 à 18:46 +0200, Xavier Claessens a écrit : > Hi, > > I'm working on protocol specific UI for creating and editing accounts > [1]. This work is made for HEAD and will be very useful for telepathy. > > One of the goal of this is removing the deprecated > gossip_account_[get,set]_*() API and use instead the new API > gossip_account_param_set(). I'm surprised there is not many places where > the deprecated API is used, most of it is in my new > gossip-account-jabber.[ch] module, that's why I'm thinking about > removing this API completely now. > > For that I need one think: the protocol should create new accounts with > default values for all parameters. Something like > GossipAccount *gossip_protocol_create_account (GossipProtocol*); > With telepathy it is already the protocol that creates new accounts and > it already sets all parameters with default values (Eitan correct me if > I miss understood the code). In telepathy we directly call > gossip_telepathy_cmgr_new_account_from_protocol > from protocol/telepathy/ which violate the libgossip abstraction. > > Is that a good idea if I implement all that in my next big account > rework ? Maybe it's better to make many little patches than one big ? > > btw, new_account_window_get_account_info() has changed in last commit in > the THELEPATHY branch and don't have the telepathy specific code > anymore ! what happened ? > > Xavier Claessens. > > [1] http://bugzilla.gnome.org/show_bug.cgi?id=358099 Here is a patch. Like that we can create a new account with all default values for a particular protocol using: gossip_session_new_account (session, GOSSIP_ACCOUNT_TYPE_JABBER); It still needs a little work to not use properties in g_object_new but uses gossip_account_param_set_full() instead, like that we can set a flag for each parameter, this flag can be used in the UI to sort optional parameters that can be hidden in a "advanced" tab/dialog/expander or whatever will be the nicer way. Like always this is not very useful for HEAD but will be very cool for telepathy. The patch is for HEAD since it doesn't depend directly on telepathy. What do you think about ? Xavier. _______________________________________________ Gossip-dev mailing list [email protected] http://lists.imendio.com/mailman/listinfo/gossip-dev
gossip-new-account.patch
(text/x-patch, 8.4 KB)
Index: libgossip/gossip-protocol.c
===================================================================
RCS file: /cvs/gnome/gossip/libgossip/gossip-protocol.c,v
retrieving revision 1.29
diff -u -p -r1.29 gossip-protocol.c
--- libgossip/gossip-protocol.c 29 Sep 2006 23:25:02 -0000 1.29
+++ libgossip/gossip-protocol.c 1 Oct 2006 19:51:35 -0000
@@ -87,6 +87,7 @@ gossip_protocol_class_init (GossipProtoc
klass->get_vcard = NULL;
klass->get_version = NULL;
klass->register_account = NULL;
+ klass->new_account = NULL;
signals[LOGGED_IN] =
g_signal_new ("logged-in",
@@ -681,6 +682,21 @@ gossip_protocol_register_cancel (GossipP
if (klass->register_cancel) {
klass->register_cancel (protocol);
}
+}
+
+GossipAccount *
+gossip_protocol_new_account (GossipProtocol *protocol)
+{
+ GossipProtocolClass *klass;
+
+ g_return_val_if_fail (GOSSIP_IS_PROTOCOL (protocol), NULL);
+
+ klass = GOSSIP_PROTOCOL_GET_CLASS (protocol);
+ if (klass->new_account) {
+ return klass->new_account (protocol);
+ }
+
+ return NULL;
}
const gchar *
Index: libgossip/gossip-protocol.h
===================================================================
RCS file: /cvs/gnome/gossip/libgossip/gossip-protocol.h,v
retrieving revision 1.21
diff -u -p -r1.21 gossip-protocol.h
--- libgossip/gossip-protocol.h 29 Sep 2006 23:25:00 -0000 1.21
+++ libgossip/gossip-protocol.h 1 Oct 2006 19:51:36 -0000
@@ -129,6 +129,7 @@ struct _GossipProtocolClass {
GossipRegisterCallback callback,
gpointer user_data);
void (*register_cancel) (GossipProtocol *protocol);
+ GossipAccount * (*new_account) (GossipProtocol *protocol);
};
GType gossip_protocol_get_type (void) G_GNUC_CONST;
@@ -202,6 +203,7 @@ void gossip_protocol_register
GossipRegisterCallback callback,
gpointer user_data);
void gossip_protocol_register_cancel (GossipProtocol *protocol);
+GossipAccount * gossip_protocol_new_account (GossipProtocol *protocol);
const gchar * gossip_protocol_error_to_string (GossipProtocolError error);
#endif /* __GOSSIP_PROTOCOL_H__ */
Index: libgossip/gossip-session.c
===================================================================
RCS file: /cvs/gnome/gossip/libgossip/gossip-session.c,v
retrieving revision 1.74
diff -u -p -r1.74 gossip-session.c
--- libgossip/gossip-session.c 29 Sep 2006 23:25:00 -0000 1.74
+++ libgossip/gossip-session.c 1 Oct 2006 19:51:37 -0000
@@ -826,6 +826,36 @@ gossip_session_count_accounts (GossipSes
}
}
+GossipAccount *
+gossip_session_new_account (GossipSession *session,
+ GossipAccountType type)
+{
+ GossipSessionPriv *priv;
+ GossipProtocol *protocol;
+ GossipAccount *account;
+
+ g_return_val_if_fail (GOSSIP_IS_SESSION (session), NULL);
+
+ priv = GET_PRIV (session);
+
+ protocol = gossip_protocol_new_from_account_type (type);
+ g_return_val_if_fail (GOSSIP_IS_PROTOCOL (protocol), NULL);
+
+ account = gossip_protocol_new_account (protocol);
+ priv->protocols = g_list_append (priv->protocols,
+ g_object_ref (protocol));
+
+ g_hash_table_insert (priv->accounts,
+ g_object_ref (account),
+ g_object_ref (protocol));
+
+ session_protocol_signals_setup (session, protocol);
+
+ g_object_unref (protocol);
+
+ return account;
+}
+
gboolean
gossip_session_add_account (GossipSession *session,
GossipAccount *account)
Index: libgossip/gossip-session.h
===================================================================
RCS file: /cvs/gnome/gossip/libgossip/gossip-session.h,v
retrieving revision 1.32
diff -u -p -r1.32 gossip-session.h
--- libgossip/gossip-session.h 29 Sep 2006 23:25:00 -0000 1.32
+++ libgossip/gossip-session.h 1 Oct 2006 19:51:37 -0000
@@ -83,7 +83,8 @@ void gossip_session_count_acc
guint *connected,
guint *connecting,
guint *disconnected);
-
+GossipAccount * gossip_session_new_account (GossipSession *session,
+ GossipAccountType type);
gboolean gossip_session_add_account (GossipSession *session,
GossipAccount *account);
gboolean gossip_session_remove_account (GossipSession *session,
Index: protocols/jabber/gossip-jabber.c
===================================================================
RCS file: /cvs/gnome/gossip/protocols/jabber/gossip-jabber.c,v
retrieving revision 1.108
diff -u -p -r1.108 gossip-jabber.c
--- protocols/jabber/gossip-jabber.c 29 Sep 2006 23:24:52 -0000 1.108
+++ protocols/jabber/gossip-jabber.c 1 Oct 2006 19:51:40 -0000
@@ -165,6 +165,7 @@ static void jabber_register_
GossipRegisterCallback callback,
gpointer user_data);
static void jabber_register_cancel (GossipProtocol *protocol);
+static GossipAccount * jabber_new_account (GossipProtocol *protocol);
static void jabber_register_connection_open_cb (LmConnection *connection,
gboolean result,
RegisterData *ra);
@@ -374,6 +375,7 @@ gossip_jabber_class_init (GossipJabberCl
protocol_class->get_version = jabber_get_version;
protocol_class->register_account = jabber_register_account;
protocol_class->register_cancel = jabber_register_cancel;
+ protocol_class->new_account = jabber_new_account;
g_type_class_add_private (object_class, sizeof (GossipJabberPriv));
}
@@ -1094,6 +1096,39 @@ jabber_register_cancel (GossipProtocol *
priv->register_cancel = TRUE;
jabber_logout (protocol);
+}
+
+static GossipAccount *
+jabber_new_account (GossipProtocol *protocol)
+{
+ GossipAccount *account;
+ const gchar *id;
+ const gchar *server;
+ gboolean ssl;
+ guint16 port;
+
+ g_return_val_if_fail (GOSSIP_IS_JABBER (protocol), NULL);
+
+ id = jabber_get_example_username (protocol);
+ server = jabber_get_default_server (protocol, id);
+ ssl = jabber_is_ssl_supported (protocol);
+ port = jabber_get_default_port (protocol, ssl);
+
+ /* Set a default value for each account parameter */
+ /* FIXME: this should be set using gossip_account_param_set_full() */
+ account = g_object_new (GOSSIP_TYPE_ACCOUNT,
+ "type", GOSSIP_ACCOUNT_TYPE_JABBER,
+ "name", _("new account"),
+ "id", id,
+ "password", "",
+ "resource", _("Home"),
+ "server", server,
+ "port", port,
+ "auto_connect", TRUE,
+ "use_ssl", ssl,
+ "use_proxy", FALSE,
+ NULL);
+ return account;
}
static void
Index: src/gossip-new-account-window.c
===================================================================
RCS file: /cvs/gnome/gossip/src/gossip-new-account-window.c,v
retrieving revision 1.13
diff -u -p -r1.13 gossip-new-account-window.c
--- src/gossip-new-account-window.c 29 Sep 2006 23:17:28 -0000 1.13
+++ src/gossip-new-account-window.c 1 Oct 2006 19:51:42 -0000
@@ -299,7 +299,6 @@ new_account_window_get_account_info (Gos
resource = gtk_entry_get_text (GTK_ENTRY (window->four_resource_entry));
server = gtk_entry_get_text (GTK_ENTRY (window->four_server_entry));
port = gtk_entry_get_text (GTK_ENTRY (window->four_port_entry));
-
name = gtk_entry_get_text (GTK_ENTRY (window->five_name_entry));
toggle = GTK_TOGGLE_BUTTON (window->four_ssl_checkbutton);
@@ -312,19 +311,22 @@ new_account_window_get_account_info (Gos
name = _("Home");
}
- /* create account */
port_int = atoi (port);
- *account = g_object_new (GOSSIP_TYPE_ACCOUNT,
- "name", name,
- "id", username,
- "resource", resource,
- "server", server,
- "password", password,
- "port", port_int,
- "use_ssl", use_ssl,
- "use_proxy", use_proxy,
- NULL);
+ /* create account */
+ *account = gossip_session_new_account (gossip_app_get_session (),
+ GOSSIP_ACCOUNT_TYPE_JABBER);
+
+ g_object_set (*account,
+ "name", name,
+ "id", username,
+ "resource", resource,
+ "server", server,
+ "password", password,
+ "port", port_int,
+ "use_ssl", use_ssl,
+ "use_proxy", use_proxy,
+ NULL);
return has_account;
}
signature.asc
(application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (GNU/Linux) iD8DBQBFIB4q6dEBUn2qPAMRAnJwAJ480Aliy7g4A14srj3gBnHk5i5SxgCghadV ZsvU5FkvVnDnUEL+lLWndpw= =iWl6 -----END PGP SIGNATURE-----