comparison libpurple/protocols/msn/msn.c @ 15623:71af5b6209d5

uri-handler support for AIM/ICQ, Yahoo and MSN
author Daniel Atallah <daniel.atallah@gmail.com>
date Sun, 11 Feb 2007 21:58:50 +0000
parents 1d0d25848c5d
children 32c366eeeb99
comparison
equal deleted inserted replaced
15622:a2411e8dbe2d 15623:71af5b6209d5
33 #include "prefs.h" 33 #include "prefs.h"
34 #include "session.h" 34 #include "session.h"
35 #include "state.h" 35 #include "state.h"
36 #include "util.h" 36 #include "util.h"
37 #include "cmds.h" 37 #include "cmds.h"
38 #include "core.h"
38 #include "prpl.h" 39 #include "prpl.h"
39 #include "msn-utils.h" 40 #include "msn-utils.h"
40 #include "version.h" 41 #include "version.h"
41 42
42 #include "switchboard.h" 43 #include "switchboard.h"
1925 msn_switchboard_end(); 1926 msn_switchboard_end();
1926 msn_sync_end(); 1927 msn_sync_end();
1927 1928
1928 return TRUE; 1929 return TRUE;
1929 } 1930 }
1931
1932 static GaimAccount *find_acct(const char *prpl, const char *acct_id)
1933 {
1934 GaimAccount *acct = NULL;
1935
1936 /* If we have a specific acct, use it */
1937 if (acct_id) {
1938 acct = gaim_accounts_find(acct_id, prpl);
1939 if (acct && !gaim_account_is_connected(acct))
1940 acct = NULL;
1941 } else { /* Otherwise find an active account for the protocol */
1942 GList *l = gaim_accounts_get_all();
1943 while (l) {
1944 if (!strcmp(prpl, gaim_account_get_protocol_id(l->data))
1945 && gaim_account_is_connected(l->data)) {
1946 acct = l->data;
1947 break;
1948 }
1949 l = l->next;
1950 }
1951 }
1952
1953 return acct;
1954 }
1955
1956 static gboolean msn_uri_handler(const char *proto, const char *cmd, GHashTable *params)
1957 {
1958 char *acct_id = g_hash_table_lookup(params, "account");
1959 GaimAccount *acct;
1960
1961 if (g_ascii_strcasecmp(proto, "msnim"))
1962 return FALSE;
1963
1964 acct = find_acct("prpl-msn", acct_id);
1965
1966 if (!acct)
1967 return FALSE;
1968
1969 /* msnim:chat?contact=user@domain.tld */
1970 if (!g_ascii_strcasecmp(cmd, "Chat")) {
1971 char *sname = g_hash_table_lookup(params, "contact");
1972 if (sname) {
1973 GaimConversation *conv = gaim_find_conversation_with_account(
1974 GAIM_CONV_TYPE_IM, sname, acct);
1975 if (conv == NULL)
1976 conv = gaim_conversation_new(GAIM_CONV_TYPE_IM, acct, sname);
1977 gaim_conversation_present(conv);
1978 }
1979 /*else
1980 **If pidgindialogs_im() was in the core, we could use it here.
1981 * It is all gaim_request_* based, but I'm not sure it really belongs in the core
1982 pidgindialogs_im();*/
1983
1984 return TRUE;
1985 }
1986 /* msnim:add?contact=user@domain.tld */
1987 else if (!g_ascii_strcasecmp(cmd, "Add")) {
1988 char *name = g_hash_table_lookup(params, "contact");
1989 gaim_blist_request_add_buddy(acct, name, NULL, NULL);
1990 return TRUE;
1991 }
1992
1993 return FALSE;
1994 }
1995
1930 1996
1931 static GaimPluginProtocolInfo prpl_info = 1997 static GaimPluginProtocolInfo prpl_info =
1932 { 1998 {
1933 OPT_PROTO_MAIL_CHECK, 1999 OPT_PROTO_MAIL_CHECK,
1934 NULL, /* user_splits */ 2000 NULL, /* user_splits */
2053 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_PRPL_ONLY, 2119 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_PRPL_ONLY,
2054 "prpl-msn", msn_cmd_nudge, 2120 "prpl-msn", msn_cmd_nudge,
2055 _("nudge: nudge a user to get their attention"), NULL); 2121 _("nudge: nudge a user to get their attention"), NULL);
2056 2122
2057 gaim_prefs_remove("/plugins/prpl/msn"); 2123 gaim_prefs_remove("/plugins/prpl/msn");
2124
2125 gaim_signal_connect(gaim_get_core(), "uri-handler", plugin,
2126 GAIM_CALLBACK(msn_uri_handler), NULL);
2058 } 2127 }
2059 2128
2060 GAIM_INIT_PLUGIN(msn, init_plugin, info); 2129 GAIM_INIT_PLUGIN(msn, init_plugin, info);