From: <ev...@us...> - 2006-08-19 01:30:35
|
Revision: 16858 Author: evands Date: 2006-08-18 18:29:53 -0700 (Fri, 18 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16858&view=rev Log Message: ----------- ** Part 4 of a 4 part commit ** Restructured the tree and the build files for the core/UI split. libgaim is now built as a library against which gtkgaim and gntgaim link and can be built separately from them by configuring with them disable d (--disable-gtkgaim and --disable-gntgaim). Each of the three source trees (gtk, console, and core) has its own plugins folder. This works nicely on my system; hopefully it won't cause too much chaos for others. If you have local changes, an easy way to merge them to the new layout should be along the lines of svn diff -r version_before_move > myChanges.diff patch -p1 < myChanges.diff where svn diff is done from the gaim checkout root but patch is done from gtk or core (or both). This changeset combines work by Sadrul Chowdhury, Gary Kramlich (grim), and me. Known issues: * On my system, at least, something's not quite right with the gtkgaim build process; it imports gtkgaim.h (as can be seen by adding a #warning) but <gtk/gtk.h> doesn't seem to be used. The GTK_STOCK_XXX defines claim to be undeclared. I was going to make this work before committing, but I strongly suspect someone with more autotools experience will be able to fix it easily whereas I've already glared at it for an hour. * The gnt console UI depends on libgnt, which is not yet automatically built. Either autogen.sh && make && make install libgnt (in console/libgnt) or configure with --disable-gnt for now. * The Windows build process has not been touched yet so still needs updating. * There's an stray "rm: core: is a directory" warning after autogen.sh is compl te. I'm not sure where that's coming from. Modified Paths: -------------- trunk/Makefile.am trunk/configure.ac Added Paths: ----------- trunk/gtk/win32/ Removed Paths: ------------- trunk/src/account.c trunk/src/account.h trunk/src/accountopt.c trunk/src/accountopt.h trunk/src/blist.c trunk/src/blist.h trunk/src/buddyicon.c trunk/src/buddyicon.h trunk/src/cipher.c trunk/src/cipher.h trunk/src/circbuffer.c trunk/src/circbuffer.h trunk/src/cmds.c trunk/src/cmds.h trunk/src/connection.c trunk/src/connection.h trunk/src/conversation.c trunk/src/conversation.h trunk/src/core.c trunk/src/core.h trunk/src/dbus-analyze-functions.py trunk/src/dbus-analyze-types.py trunk/src/dbus-bindings.h trunk/src/dbus-define-api.h trunk/src/dbus-gaim.h trunk/src/dbus-gaim.service trunk/src/dbus-maybe.h trunk/src/dbus-server.c trunk/src/dbus-server.h trunk/src/dbus-useful.c trunk/src/dbus-useful.h trunk/src/debug.c trunk/src/debug.h trunk/src/desktopitem.c trunk/src/desktopitem.h trunk/src/dnsquery.c trunk/src/dnsquery.h trunk/src/dnssrv.c trunk/src/dnssrv.h trunk/src/eventloop.c trunk/src/eventloop.h trunk/src/ft.c trunk/src/ft.h trunk/src/gaim-client-example.c trunk/src/gaim-client.c trunk/src/gaim-client.h trunk/src/gaim-notifications-example trunk/src/gaim-remote trunk/src/gaim-send trunk/src/gaim-send-async trunk/src/gaim.h trunk/src/getopt.c trunk/src/getopt.h trunk/src/getopt1.c trunk/src/gtkaccount.c trunk/src/gtkaccount.h trunk/src/gtkblist.c trunk/src/gtkblist.h trunk/src/gtkcelllayout.c trunk/src/gtkcelllayout.h trunk/src/gtkcellrendererprogress.c trunk/src/gtkcellrendererprogress.h trunk/src/gtkcellview.c trunk/src/gtkcellview.h trunk/src/gtkcellviewmenuitem.c trunk/src/gtkcellviewmenuitem.h trunk/src/gtkcombobox.c trunk/src/gtkcombobox.h trunk/src/gtkconn.c trunk/src/gtkconn.h trunk/src/gtkconv.c trunk/src/gtkconv.h trunk/src/gtkconvwin.h trunk/src/gtkdebug.c trunk/src/gtkdebug.h trunk/src/gtkdialogs.c trunk/src/gtkdialogs.h trunk/src/gtkdnd-hints.c trunk/src/gtkdnd-hints.h trunk/src/gtkeventloop.c trunk/src/gtkeventloop.h trunk/src/gtkexpander.c trunk/src/gtkexpander.h trunk/src/gtkft.c trunk/src/gtkft.h trunk/src/gtkgaim.h trunk/src/gtkidle.c trunk/src/gtkidle.h trunk/src/gtkimhtml.c trunk/src/gtkimhtml.h trunk/src/gtkimhtmltoolbar.c trunk/src/gtkimhtmltoolbar.h trunk/src/gtklog.c trunk/src/gtklog.h trunk/src/gtkmain.c trunk/src/gtkmenutray.c trunk/src/gtkmenutray.h trunk/src/gtknickcolors.h trunk/src/gtknotify.c trunk/src/gtknotify.h trunk/src/gtkplugin.c trunk/src/gtkplugin.h trunk/src/gtkpluginpref.c trunk/src/gtkpluginpref.h trunk/src/gtkpounce.c trunk/src/gtkpounce.h trunk/src/gtkprefs.c trunk/src/gtkprefs.h trunk/src/gtkprivacy.c trunk/src/gtkprivacy.h trunk/src/gtkrequest.c trunk/src/gtkrequest.h trunk/src/gtkroomlist.c trunk/src/gtkroomlist.h trunk/src/gtksavedstatuses.c trunk/src/gtksavedstatuses.h trunk/src/gtksession.c trunk/src/gtksession.h trunk/src/gtksound.c trunk/src/gtksound.h trunk/src/gtksourceiter.c trunk/src/gtksourceiter.h trunk/src/gtkstatusbox.c trunk/src/gtkstatusbox.h trunk/src/gtkstock.c trunk/src/gtkstock.h trunk/src/gtkthemes.c trunk/src/gtkthemes.h trunk/src/gtkutils.c trunk/src/gtkutils.h trunk/src/gtkwhiteboard.c trunk/src/gtkwhiteboard.h trunk/src/idle.c trunk/src/idle.h trunk/src/imgstore.c trunk/src/imgstore.h trunk/src/internal.h trunk/src/log.c trunk/src/log.h trunk/src/mime.c trunk/src/mime.h trunk/src/network.c trunk/src/network.h trunk/src/notify.c trunk/src/notify.h trunk/src/ntlm.c trunk/src/ntlm.h trunk/src/plugin.c trunk/src/plugin.h trunk/src/pluginpref.c trunk/src/pluginpref.h trunk/src/pounce.c trunk/src/pounce.h trunk/src/prefix.c trunk/src/prefix.h trunk/src/prefs.c trunk/src/prefs.h trunk/src/privacy.c trunk/src/privacy.h trunk/src/protocols/ trunk/src/proxy.c trunk/src/proxy.h trunk/src/prpl.c trunk/src/prpl.h trunk/src/request.c trunk/src/request.h trunk/src/roomlist.c trunk/src/roomlist.h trunk/src/savedstatuses.c trunk/src/savedstatuses.h trunk/src/server.c trunk/src/server.h trunk/src/signals.c trunk/src/signals.h trunk/src/sound.c trunk/src/sound.h trunk/src/sslconn.c trunk/src/sslconn.h trunk/src/status.c trunk/src/status.h trunk/src/stringref.c trunk/src/stringref.h trunk/src/stun.c trunk/src/stun.h trunk/src/upnp.c trunk/src/upnp.h trunk/src/util.c trunk/src/util.h trunk/src/value.c trunk/src/value.h trunk/src/version.h trunk/src/whiteboard.c trunk/src/whiteboard.h trunk/src/win32/ trunk/src/win_gaim.c trunk/src/xmlnode.c trunk/src/xmlnode.h Modified: trunk/Makefile.am =================================================================== --- trunk/Makefile.am 2006-08-19 01:19:33 UTC (rev 16857) +++ trunk/Makefile.am 2006-08-19 01:29:53 UTC (rev 16858) @@ -48,8 +48,16 @@ apps_DATA = $(apps_in_files:.desktop.in=.desktop) @INTLTOOL_DESKTOP_RULE@ -SUBDIRS = doc m4macros pixmaps plugins po sounds src +if ENABLE_GTK +GTK_DIR=gtk +endif +if ENABLE_GNT +GNT_DIR=console +endif + +SUBDIRS = core doc $(GNT_DIR) $(GTK_DIR) m4macros po + docs: Doxyfile if HAVE_DOXYGEN @echo "Running doxygen..." Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2006-08-19 01:19:33 UTC (rev 16857) +++ trunk/configure.ac 2006-08-19 01:29:53 UTC (rev 16858) @@ -527,6 +527,8 @@ AC_ARG_WITH(tkconfig, [ --with-tkconfig=DIR directory containing tkConfig.sh]) AC_ARG_ENABLE(gtkspell, [ --disable-gtkspell compile without GtkSpell automatic spell checking],,enable_gtkspell=yes) AC_ARG_ENABLE(debug, [ --enable-debug compile with debugging support],,enable_debug=no) +AC_ARG_ENABLE(gtkgaim, [ --disable-gtkgaim compile without GtkGaim client],,enable_gtk=yes) +AC_ARG_ENABLE(gntgaim, [ --disable-gntgaim compile without GntGaim console client],,enable_gnt=yes) AC_ARG_ENABLE(fatal-asserts, [ --enable-fatal-asserts make assertions fatal (useful for debugging)],,enable_fatal_asserts=no) dnl We know Gaim won't compile with deprecated APIs disabled. dnl We have no desire to support two different versions of the @@ -633,19 +635,37 @@ fi AC_SUBST(CFLAGS) -AM_PATH_GLIB_2_0(2.0.0,,AC_MSG_ERROR([ +PKG_CHECK_MODULES(GLIB, [glib-2.0 >= 2.0.0 gobject-2.0 gmodule-2.0 gthread-2.0], + [ + AC_SUBST(GLIB_CFLAGS) + AC_SUBST(GLIB_LIBS) + ], + [ + AC_MSG_ERROR([ *** GLib 2.0 is required to build Gaim; please make sure you have the GLib *** development headers installed. The latest version of GLib is -*** always available at http://www.gtk.org/.]),gthread) -AM_PATH_GTK_2_0(2.0.0,,AC_MSG_ERROR([ -*** GTK+ 2.0 is required to build Gaim; please make sure you have the GTK+ -*** development headers installed. The latest version of GTK+ is -*** always available at http://www.gtk.org/.])) +*** always available at http://www.gtk.org/.]) + ]) AC_PATH_PROG(gaimpath, gaim) -AC_SUBST(GTK_CFLAGS) -AC_SUBST(GLIB_CFLAGS) +if test "$enable_gtk" = yes ; then + PKG_CHECK_MODULES(GTK, [gtk+-2.0 >= 2.0.0], + [ + AC_SUBST(GTK_CFLAGS) + AC_SUBST(GTK_LIBS) + ], + [ + AC_MSG_ERROR([ +*** GTK+ 2.0 is required to build Gaim. please make sure you have the GTK+ +*** development headers installed. The latest version of GTK+ is +*** always available at http://www.gtk.org/. +*** +*** If you wish to build just gntgaim or libgaim, +*** configure with --disable-gtkgaim]) + ]) +fi + AC_PATH_XTRA # We can't assume that $x_libraries will be set, because autoconf does not # set it in the case when the X libraries are in a standard place. @@ -784,6 +804,33 @@ AM_CONDITIONAL(ENABLE_DBUS, test "x$enable_dbus" = "xyes") dnl ####################################################################### +dnl # GNT Gaim +dnl ####################################################################### +AM_CONDITIONAL(ENABLE_GNT, test "x$enable_gnt" = "xyes") + +dnl ####################################################################### +dnl # Look for startup-notification, evolution integration, X-libraries, +dnl # XScreenSaver, X session management, GtkSpell only if GTK+ was found +dnl ####################################################################### + +if test "x$enable_gtk" = "xyes"; then + +AC_PATH_XTRA +# We can't assume that $x_libraries will be set, because autoconf does not +# set it in the case when the X libraries are in a standard place. +# Ditto for $x_includes +if test X"$x_libraries" = X"" || test X"$x_libraries" = XNONE; then + x_libpath_add= +else + x_libpath_add="-L$x_libraries" +fi +if test X"$x_includes" = X"" || test X"$x_includes" = XNONE; then + x_incpath_add= +else + x_incpath_add="-I$x_includes" +fi + +dnl ####################################################################### dnl # Check for startup notification dnl ####################################################################### AC_ARG_ENABLE(startup-notification, [AC_HELP_STRING([--disable-startup-notification], [compile without startup notification support])], , enable_startup_notification=yes) @@ -803,7 +850,6 @@ AC_SUBST(STARTUP_NOTIFICATION_LIBS) fi - dnl ####################################################################### dnl # Check for stuff needed by the evolution integration plugin. dnl ####################################################################### @@ -834,8 +880,6 @@ AC_SUBST(EVOLUTION_ADDRESSBOOK_LIBS) fi -AM_CONDITIONAL(BUILD_GEVOLUTION, test "x$build_gevo" = "xyes") - dnl ####################################################################### dnl # Check for XScreenSaver dnl ####################################################################### @@ -889,7 +933,6 @@ AC_DEFINE(USE_SM, 1, [Define if we're using X Session Management.]) fi - AC_DEFUN([GC_TM_GMTOFF], [AC_REQUIRE([AC_STRUCT_TM])dnl AC_CACHE_CHECK([for tm_gmtoff in struct tm], ac_cv_struct_tm_gmtoff, @@ -901,6 +944,30 @@ fi ]) +dnl Thanks, Evan. +if test "$enable_gtkspell" = yes ; then + PKG_CHECK_MODULES(GTKSPELL, gtkspell-2.0 >= 2.0.2, [], [ + AC_MSG_RESULT(no) + enable_gtkspell=no + ]) + if test "$enable_gtkspell" = "yes" ; then + AC_SUBST(GTKSPELL_CFLAGS) + AC_SUBST(GTKSPELL_LIBS) + AC_DEFINE(USE_GTKSPELL,,[do we have gtkspell?]) + fi +fi +else # GTK + enable_gevolution=no + enable_sm=no + enable_xss=no + enable_startup_notification=no + enable_gtkspell=no +fi # GTK + +AM_CONDITIONAL(ENABLE_GTK, test "x$enable_gtk" = "xyes") + +AM_CONDITIONAL(BUILD_GEVOLUTION, test "x$build_gevo" = "xyes") + GC_TM_GMTOFF dnl ####################################################################### @@ -943,6 +1010,7 @@ AC_SUBST(MONO_LIBS) AM_CONDITIONAL(USE_MONO, test x"$enable_mono" = x"yes") +if test "x$enable_gtk" = "xyes"; then # This is for now, since perl still requires GTK+ dnl ####################################################################### dnl # Check for Perl support dnl ####################################################################### @@ -950,6 +1018,10 @@ enable_perl=no fi +else # GTK + enable_perl=no +fi # GTK + if test "$enable_perl" = yes ; then AC_PATH_PROG(perlpath, perl) AC_MSG_CHECKING(for Perl compile flags) @@ -1566,19 +1638,6 @@ AM_CONDITIONAL(USE_TK, false) fi -dnl Thanks, Evan. -if test "$enable_gtkspell" = yes ; then - PKG_CHECK_MODULES(GTKSPELL, gtkspell-2.0 >= 2.0.2, [], [ - AC_MSG_RESULT(no) - enable_gtkspell=no - ]) - if test "$enable_gtkspell" = "yes" ; then - AC_SUBST(GTKSPELL_CFLAGS) - AC_SUBST(GTKSPELL_LIBS) - AC_DEFINE(USE_GTKSPELL,,[do we have gtkspell?]) - fi -fi - if test "$ac_cv_cygwin" = yes ; then LDADD="$LDADD -static" AC_DEFINE(DEBUG, 1, [Define if debugging is enabled.]) @@ -1748,43 +1807,47 @@ doc/gaim.1 doc/gntgaim.1 m4macros/Makefile - pixmaps/Makefile - pixmaps/smileys/Makefile - pixmaps/smileys/default/Makefile - pixmaps/smileys/none/Makefile - pixmaps/status/Makefile - pixmaps/status/default/Makefile - plugins/Makefile - plugins/docklet/Makefile - plugins/gevolution/Makefile - plugins/gestures/Makefile - plugins/mono/Makefile - plugins/mono/api/Makefile - plugins/mono/loader/Makefile - plugins/musicmessaging/Makefile - plugins/perl/Makefile - plugins/perl/common/Makefile.PL - plugins/ssl/Makefile - plugins/tcl/Makefile - plugins/ticker/Makefile + gtk/Makefile + gtk/pixmaps/Makefile + gtk/pixmaps/smileys/Makefile + gtk/pixmaps/smileys/default/Makefile + gtk/pixmaps/smileys/none/Makefile + gtk/pixmaps/status/Makefile + gtk/pixmaps/status/default/Makefile + gtk/plugins/Makefile + gtk/plugins/docklet/Makefile + gtk/plugins/gevolution/Makefile + gtk/plugins/gestures/Makefile + gtk/plugins/musicmessaging/Makefile + gtk/sounds/Makefile + gtk/plugins/ticker/Makefile + core/plugins/Makefile + core/plugins/mono/Makefile + core/plugins/mono/api/Makefile + core/plugins/mono/loader/Makefile + core/plugins/perl/Makefile + core/plugins/perl/common/Makefile.PL + core/plugins/ssl/Makefile + core/plugins/tcl/Makefile + core/Makefile + core/protocols/Makefile + core/protocols/bonjour/Makefile + core/protocols/gg/Makefile + core/protocols/irc/Makefile + core/protocols/jabber/Makefile + core/protocols/msn/Makefile + core/protocols/novell/Makefile + core/protocols/oscar/Makefile + core/protocols/qq/Makefile + core/protocols/sametime/Makefile + core/protocols/silc/Makefile + core/protocols/simple/Makefile + core/protocols/toc/Makefile + core/protocols/yahoo/Makefile + core/protocols/zephyr/Makefile + console/Makefile + console/plugins/Makefile po/Makefile.in - sounds/Makefile - src/Makefile - src/protocols/Makefile - src/protocols/bonjour/Makefile - src/protocols/gg/Makefile - src/protocols/irc/Makefile - src/protocols/jabber/Makefile - src/protocols/msn/Makefile - src/protocols/novell/Makefile - src/protocols/oscar/Makefile - src/protocols/qq/Makefile - src/protocols/sametime/Makefile - src/protocols/silc/Makefile - src/protocols/simple/Makefile - src/protocols/toc/Makefile - src/protocols/yahoo/Makefile - src/protocols/zephyr/Makefile gaim.pc gaim.spec ]) @@ -1797,7 +1860,12 @@ echo Protocols to link statically.. : $STATIC_PRPLS echo Protocols to build dynamically : $DYNAMIC_PRPLS echo -echo UI Library.................... : GTK+ 2.x +if test "x$enable_gtk" = "xyes" ; then +echo GTK UI Library................ : GTK+ 2.x +else +echo GTK UI Library................ : None +fi +echo Build with GNT Console UI..... : $enable_gnt echo SSL Library/Libraries......... : $msg_ssl echo echo Build with GStreamer support.. : $enable_gst @@ -1808,7 +1876,7 @@ echo Build with Tk support......... : $enable_tk echo Build with GtkSpell support... : $enable_gtkspell echo Build with DBUS support....... : $enable_dbus -if test x$enable_dbus = xyes ; then +if test "x$enable_dbus" = "xyes" ; then eval echo DBUS servies directory........ : $DBUS_SERVICES_DIR fi echo Build with Cyrus SASL support. : $enable_cyrus_sasl Copied: trunk/gtk/win32 (from rev 16857, trunk/src/win32) Deleted: trunk/src/account.c =================================================================== --- trunk/src/account.c 2006-08-19 01:19:33 UTC (rev 16857) +++ trunk/src/account.c 2006-08-19 01:29:53 UTC (rev 16858) @@ -1,2364 +0,0 @@ -/** - * @file account.c Account API - * @ingroup core - * - * gaim - * - * Gaim is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * 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 - */ -#include "internal.h" -#include "account.h" -#include "core.h" -#include "dbus-maybe.h" -#include "debug.h" -#include "notify.h" -#include "pounce.h" -#include "prefs.h" -#include "privacy.h" -#include "prpl.h" -#include "request.h" -#include "server.h" -#include "signals.h" -#include "status.h" -#include "util.h" -#include "xmlnode.h" - -/* TODO: Should use GaimValue instead of this? What about "ui"? */ -typedef struct -{ - GaimPrefType type; - - char *ui; - - union - { - int integer; - char *string; - gboolean bool; - - } value; - -} GaimAccountSetting; - - -static GaimAccountUiOps *account_ui_ops = NULL; - -static GList *accounts = NULL; -static guint save_timer = 0; -static gboolean accounts_loaded = FALSE; - - -/********************************************************************* - * Writing to disk * - *********************************************************************/ - -static void -setting_to_xmlnode(gpointer key, gpointer value, gpointer user_data) -{ - const char *name; - GaimAccountSetting *setting; - xmlnode *node, *child; - char buf[20]; - - name = (const char *)key; - setting = (GaimAccountSetting *)value; - node = (xmlnode *)user_data; - - child = xmlnode_new_child(node, "setting"); - xmlnode_set_attrib(child, "name", name); - - if (setting->type == GAIM_PREF_INT) { - xmlnode_set_attrib(child, "type", "int"); - snprintf(buf, sizeof(buf), "%d", setting->value.integer); - xmlnode_insert_data(child, buf, -1); - } - else if (setting->type == GAIM_PREF_STRING && setting->value.string != NULL) { - xmlnode_set_attrib(child, "type", "string"); - xmlnode_insert_data(child, setting->value.string, -1); - } - else if (setting->type == GAIM_PREF_BOOLEAN) { - xmlnode_set_attrib(child, "type", "bool"); - snprintf(buf, sizeof(buf), "%d", setting->value.bool); - xmlnode_insert_data(child, buf, -1); - } -} - -static void -ui_setting_to_xmlnode(gpointer key, gpointer value, gpointer user_data) -{ - const char *ui; - GHashTable *table; - xmlnode *node, *child; - - ui = (const char *)key; - table = (GHashTable *)value; - node = (xmlnode *)user_data; - - if (g_hash_table_size(table) > 0) - { - child = xmlnode_new_child(node, "settings"); - xmlnode_set_attrib(child, "ui", ui); - g_hash_table_foreach(table, setting_to_xmlnode, child); - } -} - -static xmlnode * -status_attr_to_xmlnode(const GaimStatus *status, const GaimStatusType *type, const GaimStatusAttr *attr) -{ - xmlnode *node; - const char *id; - char *value = NULL; - GaimStatusAttr *default_attr; - GaimValue *default_value; - GaimType attr_type; - GaimValue *attr_value; - - id = gaim_status_attr_get_id(attr); - g_return_val_if_fail(id, NULL); - - attr_value = gaim_status_get_attr_value(status, id); - g_return_val_if_fail(attr_value, NULL); - attr_type = gaim_value_get_type(attr_value); - - /* - * If attr_value is a different type than it should be - * then don't write it to the file. - */ - default_attr = gaim_status_type_get_attr(type, id); - default_value = gaim_status_attr_get_value(default_attr); - if (attr_type != gaim_value_get_type(default_value)) - return NULL; - - /* - * If attr_value is the same as the default for this status - * then there is no need to write it to the file. - */ - if (attr_type == GAIM_TYPE_STRING) - { - const char *string_value = gaim_value_get_string(attr_value); - const char *default_string_value = gaim_value_get_string(default_value); - if (((string_value == NULL) && (default_string_value == NULL)) || - ((string_value != NULL) && (default_string_value != NULL) && - !strcmp(string_value, default_string_value))) - return NULL; - value = g_strdup(gaim_value_get_string(attr_value)); - } - else if (attr_type == GAIM_TYPE_INT) - { - int int_value = gaim_value_get_int(attr_value); - if (int_value == gaim_value_get_int(default_value)) - return NULL; - value = g_strdup_printf("%d", int_value); - } - else if (attr_type == GAIM_TYPE_BOOLEAN) - { - gboolean boolean_value = gaim_value_get_boolean(attr_value); - if (boolean_value == gaim_value_get_boolean(default_value)) - return NULL; - value = g_strdup(boolean_value ? - "true" : "false"); - } - else - { - return NULL; - } - - g_return_val_if_fail(value, NULL); - - node = xmlnode_new("attribute"); - - xmlnode_set_attrib(node, "id", id); - xmlnode_set_attrib(node, "value", value); - - g_free(value); - - return node; -} - -static xmlnode * -status_attrs_to_xmlnode(const GaimStatus *status) -{ - GaimStatusType *type = gaim_status_get_type(status); - xmlnode *node, *child; - const GList *attrs, *attr; - - node = xmlnode_new("attributes"); - - attrs = gaim_status_type_get_attrs(type); - for (attr = attrs; attr != NULL; attr = attr->next) - { - child = status_attr_to_xmlnode(status, type, (const GaimStatusAttr *)attr->data); - if (child) - xmlnode_insert_child(node, child); - } - - return node; -} - -static xmlnode * -status_to_xmlnode(const GaimStatus *status) -{ - xmlnode *node, *child; - - node = xmlnode_new("status"); - xmlnode_set_attrib(node, "type", gaim_status_get_id(status)); - if (gaim_status_get_name(status) != NULL) - xmlnode_set_attrib(node, "name", gaim_status_get_name(status)); - xmlnode_set_attrib(node, "active", gaim_status_is_active(status) ? "true" : "false"); - - child = status_attrs_to_xmlnode(status); - xmlnode_insert_child(node, child); - - return node; -} - -static xmlnode * -statuses_to_xmlnode(const GaimPresence *presence) -{ - xmlnode *node, *child; - const GList *statuses, *status; - - node = xmlnode_new("statuses"); - - statuses = gaim_presence_get_statuses(presence); - for (status = statuses; status != NULL; status = status->next) - { - child = status_to_xmlnode((GaimStatus *)status->data); - xmlnode_insert_child(node, child); - } - - return node; -} - -static xmlnode * -proxy_settings_to_xmlnode(GaimProxyInfo *proxy_info) -{ - xmlnode *node, *child; - GaimProxyType proxy_type; - const char *value; - int int_value; - char buf[20]; - - proxy_type = gaim_proxy_info_get_type(proxy_info); - - node = xmlnode_new("proxy"); - - child = xmlnode_new_child(node, "type"); - xmlnode_insert_data(child, - (proxy_type == GAIM_PROXY_USE_GLOBAL ? "global" : - proxy_type == GAIM_PROXY_NONE ? "none" : - proxy_type == GAIM_PROXY_HTTP ? "http" : - proxy_type == GAIM_PROXY_SOCKS4 ? "socks4" : - proxy_type == GAIM_PROXY_SOCKS5 ? "socks5" : - proxy_type == GAIM_PROXY_USE_ENVVAR ? "envvar" : "unknown"), -1); - - if (proxy_type != GAIM_PROXY_USE_GLOBAL && - proxy_type != GAIM_PROXY_NONE && - proxy_type != GAIM_PROXY_USE_ENVVAR) - { - if ((value = gaim_proxy_info_get_host(proxy_info)) != NULL) - { - child = xmlnode_new_child(node, "host"); - xmlnode_insert_data(child, value, -1); - } - - if ((int_value = gaim_proxy_info_get_port(proxy_info)) != 0) - { - snprintf(buf, sizeof(buf), "%d", int_value); - child = xmlnode_new_child(node, "port"); - xmlnode_insert_data(child, buf, -1); - } - - if ((value = gaim_proxy_info_get_username(proxy_info)) != NULL) - { - child = xmlnode_new_child(node, "username"); - xmlnode_insert_data(child, value, -1); - } - - if ((value = gaim_proxy_info_get_password(proxy_info)) != NULL) - { - child = xmlnode_new_child(node, "password"); - xmlnode_insert_data(child, value, -1); - } - } - - return node; -} - -static xmlnode * -account_to_xmlnode(GaimAccount *account) -{ - xmlnode *node, *child; - const char *tmp; - GaimPresence *presence; - GaimProxyInfo *proxy_info; - - node = xmlnode_new("account"); - - child = xmlnode_new_child(node, "protocol"); - xmlnode_insert_data(child, gaim_account_get_protocol_id(account), -1); - - child = xmlnode_new_child(node, "name"); - xmlnode_insert_data(child, gaim_account_get_username(account), -1); - - if (gaim_account_get_remember_password(account) && - ((tmp = gaim_account_get_password(account)) != NULL)) - { - child = xmlnode_new_child(node, "password"); - xmlnode_insert_data(child, tmp, -1); - } - - if ((tmp = gaim_account_get_alias(account)) != NULL) - { - child = xmlnode_new_child(node, "alias"); - xmlnode_insert_data(child, tmp, -1); - } - - if ((presence = gaim_account_get_presence(account)) != NULL) - { - child = statuses_to_xmlnode(presence); - xmlnode_insert_child(node, child); - } - - if ((tmp = gaim_account_get_user_info(account)) != NULL) - { - /* TODO: Do we need to call gaim_str_strip_char(tmp, '\r') here? */ - child = xmlnode_new_child(node, "userinfo"); - xmlnode_insert_data(child, tmp, -1); - } - - if ((tmp = gaim_account_get_buddy_icon(account)) != NULL) - { - child = xmlnode_new_child(node, "buddyicon"); - xmlnode_insert_data(child, tmp, -1); - } - - if (g_hash_table_size(account->settings) > 0) - { - child = xmlnode_new_child(node, "settings"); - g_hash_table_foreach(account->settings, setting_to_xmlnode, child); - } - - if (g_hash_table_size(account->ui_settings) > 0) - { - g_hash_table_foreach(account->ui_settings, ui_setting_to_xmlnode, node); - } - - if ((proxy_info = gaim_account_get_proxy_info(account)) != NULL) - { - child = proxy_settings_to_xmlnode(proxy_info); - xmlnode_insert_child(node, child); - } - - return node; -} - -static xmlnode * -accounts_to_xmlnode(void) -{ - xmlnode *node, *child; - GList *cur; - - node = xmlnode_new("account"); - xmlnode_set_attrib(node, "version", "1.0"); - - for (cur = gaim_accounts_get_all(); cur != NULL; cur = cur->next) - { - child = account_to_xmlnode(cur->data); - xmlnode_insert_child(node, child); - } - - return node; -} - -static void -sync_accounts(void) -{ - xmlnode *node; - char *data; - - if (!accounts_loaded) - { - gaim_debug_error("account", "Attempted to save accounts before " - "they were read!\n"); - return; - } - - node = accounts_to_xmlnode(); - data = xmlnode_to_formatted_str(node, NULL); - gaim_util_write_data_to_file("accounts.xml", data, -1); - g_free(data); - xmlnode_free(node); -} - -static gboolean -save_cb(gpointer data) -{ - sync_accounts(); - save_timer = 0; - return FALSE; -} - -static void -schedule_accounts_save() -{ - if (save_timer == 0) - save_timer = gaim_timeout_add(5000, save_cb, NULL); -} - - -/********************************************************************* - * Reading from disk * - *********************************************************************/ - -static void -parse_settings(xmlnode *node, GaimAccount *account) -{ - const char *ui; - xmlnode *child; - - /* Get the UI string, if these are UI settings */ - ui = xmlnode_get_attrib(node, "ui"); - - /* Read settings, one by one */ - for (child = xmlnode_get_child(node, "setting"); child != NULL; - child = xmlnode_get_next_twin(child)) - { - const char *name, *str_type; - GaimPrefType type; - char *data; - - name = xmlnode_get_attrib(child, "name"); - if (name == NULL) - /* Ignore this setting */ - continue; - - str_type = xmlnode_get_attrib(child, "type"); - if (str_type == NULL) - /* Ignore this setting */ - continue; - - if (!strcmp(str_type, "string")) - type = GAIM_PREF_STRING; - else if (!strcmp(str_type, "int")) - type = GAIM_PREF_INT; - else if (!strcmp(str_type, "bool")) - type = GAIM_PREF_BOOLEAN; - else - /* Ignore this setting */ - continue; - - data = xmlnode_get_data(child); - if (data == NULL) - /* Ignore this setting */ - continue; - - if (ui == NULL) - { - if (type == GAIM_PREF_STRING) - gaim_account_set_string(account, name, data); - else if (type == GAIM_PREF_INT) - gaim_account_set_int(account, name, atoi(data)); - else if (type == GAIM_PREF_BOOLEAN) - gaim_account_set_bool(account, name, - (*data == '0' ? FALSE : TRUE)); - } else { - if (type == GAIM_PREF_STRING) - gaim_account_set_ui_string(account, ui, name, data); - else if (type == GAIM_PREF_INT) - gaim_account_set_ui_int(account, ui, name, atoi(data)); - else if (type == GAIM_PREF_BOOLEAN) - gaim_account_set_ui_bool(account, ui, name, - (*data == '0' ? FALSE : TRUE)); - } - - g_free(data); - } -} - -static GList * -parse_status_attrs(xmlnode *node, GaimStatus *status) -{ - GList *list = NULL; - xmlnode *child; - GaimValue *attr_value; - - for (child = xmlnode_get_child(node, "attribute"); child != NULL; - child = xmlnode_get_next_twin(child)) - { - const char *id = xmlnode_get_attrib(child, "id"); - const char *value = xmlnode_get_attrib(child, "value"); - - if (!id || !*id || !value || !*value) - continue; - - attr_value = gaim_status_get_attr_value(status, id); - if (!attr_value) - continue; - - list = g_list_append(list, (char *)id); - - switch (gaim_value_get_type(attr_value)) - { - case GAIM_TYPE_STRING: - list = g_list_append(list, (char *)value); - break; - case GAIM_TYPE_INT: - case GAIM_TYPE_BOOLEAN: - { - int v; - if (sscanf(value, "%d", &v) == 1) - list = g_list_append(list, GINT_TO_POINTER(v)); - else - list = g_list_remove(list, id); - break; - } - default: - break; - } - } - - return list; -} - -static void -parse_status(xmlnode *node, GaimAccount *account) -{ - gboolean active = FALSE; - const char *data; - const char *type; - xmlnode *child; - GList *attrs = NULL; - - /* Get the active/inactive state */ - data = xmlnode_get_attrib(node, "active"); - if (data == NULL) - return; - if (strcasecmp(data, "true") == 0) - active = TRUE; - else if (strcasecmp(data, "false") == 0) - active = FALSE; - else - return; - - /* Get the type of the status */ - type = xmlnode_get_attrib(node, "type"); - if (type == NULL) - return; - - /* Read attributes into a GList */ - child = xmlnode_get_child(node, "attributes"); - if (child != NULL) - { - attrs = parse_status_attrs(child, - gaim_account_get_status(account, type)); - } - - gaim_account_set_status_list(account, type, active, attrs); - - g_list_free(attrs); -} - -static void -parse_statuses(xmlnode *node, GaimAccount *account) -{ - xmlnode *child; - - for (child = xmlnode_get_child(node, "status"); child != NULL; - child = xmlnode_get_next_twin(child)) - { - parse_status(child, account); - } -} - -static void -parse_proxy_info(xmlnode *node, GaimAccount *account) -{ - GaimProxyInfo *proxy_info; - xmlnode *child; - char *data; - - proxy_info = gaim_proxy_info_new(); - - /* Use the global proxy settings, by default */ - gaim_proxy_info_set_type(proxy_info, GAIM_PROXY_USE_GLOBAL); - - /* Read proxy type */ - child = xmlnode_get_child(node, "type"); - if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL)) - { - if (!strcmp(data, "global")) - gaim_proxy_info_set_type(proxy_info, GAIM_PROXY_USE_GLOBAL); - else if (!strcmp(data, "none")) - gaim_proxy_info_set_type(proxy_info, GAIM_PROXY_NONE); - else if (!strcmp(data, "http")) - gaim_proxy_info_set_type(proxy_info, GAIM_PROXY_HTTP); - else if (!strcmp(data, "socks4")) - gaim_proxy_info_set_type(proxy_info, GAIM_PROXY_SOCKS4); - else if (!strcmp(data, "socks5")) - gaim_proxy_info_set_type(proxy_info, GAIM_PROXY_SOCKS5); - else if (!strcmp(data, "envvar")) - gaim_proxy_info_set_type(proxy_info, GAIM_PROXY_USE_ENVVAR); - else - { - gaim_debug_error("account", "Invalid proxy type found when " - "loading account information for %s\n", - gaim_account_get_username(account)); - } - g_free(data); - } - - /* Read proxy host */ - child = xmlnode_get_child(node, "host"); - if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL)) - { - gaim_proxy_info_set_host(proxy_info, data); - g_free(data); - } - - /* Read proxy port */ - child = xmlnode_get_child(node, "port"); - if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL)) - { - gaim_proxy_info_set_port(proxy_info, atoi(data)); - g_free(data); - } - - /* Read proxy username */ - child = xmlnode_get_child(node, "username"); - if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL)) - { - gaim_proxy_info_set_username(proxy_info, data); - g_free(data); - } - - /* Read proxy password */ - child = xmlnode_get_child(node, "password"); - if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL)) - { - gaim_proxy_info_set_password(proxy_info, data); - g_free(data); - } - - /* If there are no values set then proxy_infourn NULL */ - if ((gaim_proxy_info_get_type(proxy_info) == GAIM_PROXY_USE_GLOBAL) && - (gaim_proxy_info_get_host(proxy_info) == NULL) && - (gaim_proxy_info_get_port(proxy_info) == 0) && - (gaim_proxy_info_get_username(proxy_info) == NULL) && - (gaim_proxy_info_get_password(proxy_info) == NULL)) - { - gaim_proxy_info_destroy(proxy_info); - return; - } - - gaim_account_set_proxy_info(account, proxy_info); -} - -static GaimAccount * -parse_account(xmlnode *node) -{ - GaimAccount *ret; - xmlnode *child; - char *protocol_id = NULL; - char *name = NULL; - char *data; - - child = xmlnode_get_child(node, "protocol"); - if (child != NULL) - protocol_id = xmlnode_get_data(child); - - child = xmlnode_get_child(node, "name"); - if (child != NULL) - name = xmlnode_get_data(child); - if (name == NULL) - { - /* Do we really need to do this? */ - child = xmlnode_get_child(node, "username"); - if (child != NULL) - name = xmlnode_get_data(child); - } - - if ((protocol_id == NULL) || (name == NULL)) - { - g_free(protocol_id); - g_free(name); - return NULL; - } - - ret = gaim_account_new(name, protocol_id); - g_free(name); - g_free(protocol_id); - - /* Read the password */ - child = xmlnode_get_child(node, "password"); - if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL)) - { - gaim_account_set_remember_password(ret, TRUE); - gaim_account_set_password(ret, data); - g_free(data); - } - - /* Read the alias */ - child = xmlnode_get_child(node, "alias"); - if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL)) - { - if (*data != '\0') - gaim_account_set_alias(ret, data); - g_free(data); - } - - /* Read the statuses */ - child = xmlnode_get_child(node, "statuses"); - if (child != NULL) - { - parse_statuses(child, ret); - } - - /* Read the userinfo */ - child = xmlnode_get_child(node, "userinfo"); - if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL)) - { - gaim_account_set_user_info(ret, data); - g_free(data); - } - - /* Read the buddyicon */ - child = xmlnode_get_child(node, "buddyicon"); - if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL)) - { - gaim_account_set_buddy_icon(ret, data); - g_free(data); - } - - /* Read settings (both core and UI) */ - for (child = xmlnode_get_child(node, "settings"); child != NULL; - child = xmlnode_get_next_twin(child)) - { - parse_settings(child, ret); - } - - /* Read proxy */ - child = xmlnode_get_child(node, "proxy"); - if (child != NULL) - { - parse_proxy_info(child, ret); - } - - return ret; -} - -static void -load_accounts(void) -{ - xmlnode *node, *child; - - accounts_loaded = TRUE; - - node = gaim_util_read_xml_from_file("accounts.xml", _("accounts")); - - if (node == NULL) - return; - - for (child = xmlnode_get_child(node, "account"); child != NULL; - child = xmlnode_get_next_twin(child)) - { - GaimAccount *new_acct; - new_acct = parse_account(child); - gaim_accounts_add(new_acct); - } - - xmlnode_free(node); -} - - -static void -delete_setting(void *data) -{ - GaimAccountSetting *setting = (GaimAccountSetting *)data; - - g_free(setting->ui); - - if (setting->type == GAIM_PREF_STRING) - g_free(setting->value.string); - - g_free(setting); -} - -GaimAccount * -gaim_account_new(const char *username, const char *protocol_id) -{ - GaimAccount *account = NULL; - GaimPlugin *prpl = NULL; - GaimPluginProtocolInfo *prpl_info = NULL; - GaimStatusType *status_type; - - g_return_val_if_fail(username != NULL, NULL); - g_return_val_if_fail(protocol_id != NULL, NULL); - - account = gaim_accounts_find(username, protocol_id); - - if (account != NULL) - return account; - - account = g_new0(GaimAccount, 1); - GAIM_DBUS_REGISTER_POINTER(account, GaimAccount); - - gaim_account_set_username(account, username); - - gaim_account_set_protocol_id(account, protocol_id); - - account->settings = g_hash_table_new_full(g_str_hash, g_str_equal, - g_free, delete_setting); - account->ui_settings = g_hash_table_new_full(g_str_hash, g_str_equal, - g_free, (GDestroyNotify)g_hash_table_destroy); - account->system_log = NULL; - /* 0 is not a valid privacy setting */ - account->perm_deny = GAIM_PRIVACY_ALLOW_ALL; - - account->presence = gaim_presence_new_for_account(account); - - prpl = gaim_find_prpl(protocol_id); - - if (prpl == NULL) - return account; - - prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); - if (prpl_info != NULL && prpl_info->status_types != NULL) - gaim_account_set_status_types(account, prpl_info->status_types(account)); - - status_type = gaim_account_get_status_type_with_primitive(account, GAIM_STATUS_AVAILABLE); - if (status_type != NULL) - gaim_presence_set_status_active(account->presence, - gaim_status_type_get_id(status_type), - TRUE); - else - gaim_presence_set_status_active(account->presence, - "offline", - TRUE); - - return account; -} - -void -gaim_account_destroy(GaimAccount *account) -{ - GList *l; - - g_return_if_fail(account != NULL); - - gaim_debug_info("account", "Destroying account %p\n", account); - - for (l = gaim_get_conversations(); l != NULL; l = l->next) - { - GaimConversation *conv = (GaimConversation *)l->data; - - if (gaim_conversation_get_account(conv) == account) - gaim_conversation_set_account(conv, NULL); - } - - g_free(account->username); - g_free(account->alias); - g_free(account->password); - g_free(account->user_info); - g_free(account->protocol_id); - - g_hash_table_destroy(account->settings); - g_hash_table_destroy(account->ui_settings); - - gaim_account_set_status_types(account, NULL); - - gaim_presence_destroy(account->presence); - - if(account->system_log) - gaim_log_free(account->system_log); - - GAIM_DBUS_UNREGISTER_POINTER(account); - g_free(account); -} - -void -gaim_account_register(GaimAccount *account) -{ - g_return_if_fail(account != NULL); - - gaim_debug_info("account", "Registering account %s\n", - gaim_account_get_username(account)); - - gaim_connection_new(account, TRUE, NULL); -} - -static void -request_password_ok_cb(GaimAccount *account, GaimRequestFields *fields) -{ - const char *entry; - gboolean remember; - - entry = gaim_request_fields_get_string(fields, "password"); - remember = gaim_request_fields_get_bool(fields, "remember"); - - if (!entry || !*entry) - { - gaim_notify_error(account, NULL, _("Password is required to sign on."), NULL); - return; - } - - if(remember) - gaim_account_set_remember_password(account, TRUE); - - gaim_account_set_password(account, entry); - - gaim_connection_new(account, FALSE, entry); -} - -static void -request_password(GaimAccount *account) -{ - gchar *primary; - const gchar *username; - GaimRequestFieldGroup *group; - GaimRequestField *field; - GaimRequestFields *fields; - - /* Close any previous password request windows */ - gaim_request_close_with_handle(account); - - username = gaim_account_get_username(account); - primary = g_strdup_printf(_("Enter password for %s (%s)"), username, - gaim_account_get_protocol_name(account)); - - fields = gaim_request_fields_new(); - group = gaim_request_field_group_new(NULL); - gaim_request_fields_add_group(fields, group); - - field = gaim_request_field_string_new("password", _("Enter Password"), NULL, FALSE); - gaim_request_field_string_set_masked(field, TRUE); - gaim_request_field_set_required(field, TRUE); - gaim_request_field_group_add_field(group, field); - - field = gaim_request_field_bool_new("remember", _("Save password"), FALSE); - gaim_request_field_group_add_field(group, field); - - gaim_request_fields(account, - NULL, - primary, - NULL, - fields, - _("OK"), G_CALLBACK(request_password_ok_cb), - _("Cancel"), NULL, - account); - g_free(primary); -} - -void -gaim_account_connect(GaimAccount *account) -{ - GaimPlugin *prpl; - GaimPluginProtocolInfo *prpl_info; - const char *password; - - g_return_if_fail(account != NULL); - - gaim_debug_info("account", "Connecting to account %s\n", - gaim_account_get_username(account)); - - if (!gaim_account_get_enabled(account, gaim_core_get_ui())) - return; - - prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); - if (prpl == NULL) - { - gchar *message; - - message = g_strdup_printf(_("Missing protocol plugin for %s"), - gaim_account_get_username(account)); - gaim_notify_error(account, _("Connection Error"), message, NULL); - g_free(message); - return; - } - - prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); - password = gaim_account_get_password(account); - if ((password == NULL) && - !(prpl_info->options & OPT_PROTO_NO_PASSWORD) && - !(prpl_info->options & OPT_PROTO_PASSWORD_OPTIONAL)) - request_password(account); - else - gaim_connection_new(account, FALSE, password); -} - -void -gaim_account_disconnect(GaimAccount *account) -{ - GaimConnection *gc; - - g_return_if_fail(account != NULL); - g_return_if_fail(!gaim_account_is_disconnected(account)); - - gaim_debug_info("account", "Disconnecting account %p\n", account); - - account->disconnecting = TRUE; - - gc = gaim_account_get_connection(account); - gaim_connection_destroy(gc); - if (!gaim_account_get_remember_password(account)) - gaim_account_set_password(account, NULL); - gaim_account_set_connection(account, NULL); - - account->disconnecting = FALSE; -} - -void -gaim_account_notify_added(GaimAccount *account, const char *remote_user, - const char *id, const char *alias, - const char *message) -{ - GaimAccountUiOps *ui_ops; - - g_return_if_fail(account != NULL); - g_return_if_fail(remote_user != NULL); - - ui_ops = gaim_accounts_get_ui_ops(); - - if (ui_ops != NULL && ui_ops->notify_added != NULL) - ui_ops->notify_added(account, remote_user, id, alias, message); -} - -void -gaim_account_request_add(GaimAccount *account, const char *remote_user, - const char *id, const char *alias, - const char *message) -{ - GaimAccountUiOps *ui_ops; - - g_return_if_fail(account != NULL); - g_return_if_fail(remote_user != NULL); - - ui_ops = gaim_accounts_get_ui_ops(); - - if (ui_ops != NULL && ui_ops->request_add != NULL) - ui_ops->request_add(account, remote_user, id, alias, message); -} - -static void -change_password_cb(GaimAccount *account, GaimRequestFields *fields) -{ - const char *orig_pass, *new_pass_1, *new_pass_2; - - orig_pass = gaim_request_fields_get_string(fields, "password"); - new_pass_1 = gaim_request_fields_get_string(fields, "new_password_1"); - new_pass_2 = gaim_request_fields_get_string(fields, "new_password_2"); - - if (g_utf8_collate(new_pass_1, new_pass_2)) - { - gaim_notify_error(account, NULL, - _("New passwords do not match."), NULL); - - return; - } - - if (orig_pass == NULL || new_pass_1 == NULL || new_pass_2 == NULL || - *orig_pass == '\0' || *new_pass_1 == '\0' || *new_pass_2 == '\0') - { - gaim_notify_error(account, NULL, - _("Fill out all fields completely."), NULL); - return; - } - - gaim_account_change_password(account, orig_pass, new_pass_1); -} - -void -gaim_account_request_change_password(GaimAccount *account) -{ - GaimRequestFields *fields; - GaimRequestFieldGroup *group; - GaimRequestField *field; - char primary[256]; - - g_return_if_fail(account != NULL); - g_return_if_fail(gaim_account_is_connected(account)); - - fields = gaim_request_fields_new(); - - group = gaim_request_field_group_new(NULL); - gaim_request_fields_add_group(fields, group); - - field = gaim_request_field_string_new("password", _("Original password"), - NULL, FALSE); - gaim_request_field_string_set_masked(field, TRUE); - gaim_request_field_set_required(field, TRUE); - gaim_request_field_group_add_field(group, field); - - field = gaim_request_field_string_new("new_password_1", - _("New password"), - NULL, FALSE); - gaim_request_field_string_set_masked(field, TRUE); - gaim_request_field_set_required(field, TRUE); - gaim_request_field_group_add_field(group, field); - - field = gaim_request_field_string_new("new_password_2", - _("New password (again)"), - NULL, FALSE); - gaim_request_field_string_set_masked(field, TRUE); - gaim_request_field_set_required(field, TRUE); - gaim_request_field_group_add_field(group, field); - - g_snprintf(primary, sizeof(primary), _("Change password for %s"), - gaim_account_get_username(account)); - - /* I'm sticking this somewhere in the code: bologna */ - - gaim_request_fields(gaim_account_get_connection(account), - NULL, - primary, - _("Please enter your current password and your " - "new password."), - fields, - _("OK"), G_CALLBACK(change_password_cb), - _("Cancel"), NULL, - account); -} - -static void -set_user_info_cb(GaimAccount *account, const char *user_info) -{ - GaimConnection *gc; - - gaim_account_set_user_info(account, user_info); - - gc = gaim_account_get_connection(account); - - if (gc != NULL) - serv_set_info(gc, user_info); -} - -void -gaim_account_request_change_user_info(GaimAccount *account) -{ - GaimConnection *gc; - char primary[256]; - - g_return_if_fail(account != NULL); - g_return_if_fail(gaim_account_is_connected(account)); - - gc = gaim_account_get_connection(account); - - g_snprintf(primary, sizeof(primary), - _("Change user information for %s"), - gaim_account_get_username(account)); - - gaim_request_input(gc, _("Set User Info"), primary, NULL, - gaim_account_get_user_info(account), - TRUE, FALSE, ((gc != NULL) && - (gc->flags & GAIM_CONNECTION_HTML) ? "html" : NULL), - _("Save"), G_CALLBACK(set_user_info_cb), - _("Cancel"), NULL, account); -} - -void -gaim_account_set_username(GaimAccount *account, const char *username) -{ - g_return_if_fail(account != NULL); - - g_free(account->username); - account->username = g_strdup(username); - - schedule_accounts_save(); -} - -void -gaim_account_set_password(GaimAccount *account, const char *password) -{ - g_return_if_fail(account != NULL); - - g_free(account->password); - account->password = g_strdup(password); - - schedule_accounts_save(); -} - -void -gaim_account_set_alias(GaimAccount *account, const char *alias) -{ - g_return_if_fail(account != NULL); - - /* - * Do nothing if alias and account->alias are both NULL. Or if - * they're the exact same string. - */ - if (alias == account->alias) - return; - - if ((!alias && account->alias) || (alias && !account->alias) || - g_utf8_collate(account->alias, alias)) - { - char *old = account->alias; - - account->alias = g_strdup(alias); - gaim_signal_emit(gaim_accounts_get_handle(), "account-alias-changed", - account, old); - g_free(old); - - schedule_accounts_save(); - } -} - -void -gaim_account_set_user_info(GaimAccount *account, const char *user_info) -{ - g_return_if_fail(account != NULL); - - g_free(account->user_info); - account->user_info = g_strdup(user_info); - - schedule_accounts_save(); -} - -void -gaim_account_set_buddy_icon(GaimAccount *account, const char *icon) -{ - g_return_if_fail(account != NULL); - - /* Delete an existing icon from the cache. */ - if (account->buddy_icon != NULL && (icon == NULL || strcmp(account->buddy_icon, icon))) - { - const char *dirname = gaim_buddy_icons_get_cache_dir(); - struct stat st; - - if (g_stat(account->buddy_icon, &st) == 0) - { - /* The file exists. This is a full path. */ - - /* XXX: This is a hack so we only delete the file if it's - * in the cache dir. Otherwise, people who upgrade (who - * may have buddy icon filenames set outside of the cache - * dir) could lose files. */ - if (!strncmp(dirname, account->buddy_icon, strlen(dirname))) - g_unlink(account->buddy_icon); - } - else - { - char *filename = g_build_filename(dirname, account->buddy_icon, NULL); - g_unlink(filename); - g_free(filename); - } - } - - g_free(account->buddy_icon); - account->buddy_icon = g_strdup(icon); - if (gaim_account_is_connected(account)) - { - char *filename = gaim_buddy_icons_get_full_path(icon); - serv_set_buddyicon(gaim_account_get_connection(account), filename); - g_free(filename); - } - - schedule_accounts_save(); -} - -void -gaim_account_set_protocol_id(GaimAccount *account, const char *protocol_id) -{ - g_return_if_fail(account != NULL); - g_return_if_fail(protocol_id != NULL); - - g_free(account->protocol_id); - account->protocol_id = g_strdup(protocol_id); - - schedule_accounts_save(); -} - -void -gaim_account_set_connection(GaimAccount *account, GaimConnection *gc) -{ - g_return_if_fail(account != NULL); - - account->gc = gc; -} - -void -gaim_account_set_remember_password(GaimAccount *account, gboolean value) -{ - g_return_if_fail(account != NULL); - - account->remember_pass = value; - - schedule_accounts_save(); -} - -void -gaim_account_set_check_mail(GaimAccount *account, gboolean value) -{ - g_return_if_fail(account != NULL); - - gaim_account_set_bool(account, "check-mail", value); -} - -void -gaim_account_set_enabled(GaimAccount *account, const char *ui, - gboolean value) -{ - GaimConnection *gc; - gboolean was_enabled = FALSE; - - g_return_if_fail(account != NULL); - g_return_if_fail(ui != NULL); - - was_enabled = gaim_account_get_enabled(account, ui); - - gaim_account_set_ui_bool(account, ui, "auto-login", value); - gc = gaim_account_get_connection(account); - - if(was_enabled && !value) - gaim_signal_emit(gaim_accounts_get_handle(), "account-disabled", account); - else if(!was_enabled && value) - gaim_signal_emit(gaim_accounts_get_handle(), "account-enabled", account); - - if ((gc != NULL) && (gc->wants_to_die == TRUE)) - return; - - if (value && gaim_presence_is_online(account->presence)) - gaim_account_connect(account); - else if (!value && !gaim_account_is_disconnected(account)) - gaim_account_disconnect(account); -} - -void -gaim_account_set_proxy_info(GaimAccount *account, GaimProxyInfo *info) -{ - g_return_if_fail(account != NULL); - - if (account->proxy_info != NULL) - gaim_proxy_info_destroy(account->proxy_info); - - account->proxy_info = info; - - schedule_accounts_save(); -} - -void -gaim_account_set_status_types(GaimAccount *account, GList *status_types) -{ - g_return_if_fail(account != NULL); - - /* Old with the old... */ - if (account->status_types != NULL) - { - g_list_foreach(account->status_types, (GFunc)gaim_status_type_destroy, NULL); - g_list_free(account->status_types); - } - - /* In with the new... */ - account->status_types = status_types; -} - -void -gaim_account_set_status(GaimAccount *account, const char *status_id, - gboolean active, ...) -{ - va_list args; - - va_start(args, active); - gaim_account_set_status_vargs(account, status_id, active, args); - va_end(args); -} - -void -gaim_account_set_status_vargs(GaimAccount *account, const char *status_id, - gboolean active, va_list args) -{ - GList *attrs = NULL; - const gchar *id; - gpointer data; - - if (args != NULL) - { - while ((id = va_arg(args, const char *)) != NULL) - { - attrs = g_list_append(attrs, (char *)id); - data = va_arg(args, void *); - attrs = g_list_append(attrs, data); - } - } - gaim_account_set_status_list(account, status_id, active, attrs); - g_list_free(attrs); -} - -void -gaim_account_set_status_list(GaimAccount *account, const char *status_id, - gboolean active, GList *attrs) -{ - GaimStatus *status; - - g_return_if_fail(account != NULL); - g_return_if_fail(status_id != NULL); - - status = gaim_account_get_status(account, status_id); - if (status == NULL) - { - gaim_debug_error("account", - "Invalid status ID %s for account %s (%s)\n", - status_id, gaim_account_get_username(account), - gaim_account_get_protocol_id(account)); - return; - } - - if (active || gaim_status_is_independent(status)) - gaim_status_set_active_with_attrs_list(status, active, attrs); - - /* - * Our current statuses are saved to accounts.xml (so that when we - * reconnect, we go back to the previous status). - */ - schedule_accounts_save(); -} - -void -gaim_account_clear_settings(GaimAccount *account) -{ - g_return_if_fail(account != NULL); - - g_hash_table_destroy(account->settings); - - account->settings = g_hash_table_new_full(g_str_hash, g_str_equal, - g_free, delete_setting); -} - -void -gaim_account_set_int(GaimAccount *account, const char *name, int value) -{ - GaimAccountSetting *setting; - - g_return_if_fail(account != NULL); - g_return_if_fail(name != NULL); - - setting = g_new0(GaimAccountSetting, 1); - - setting->type = GAIM_PREF_INT; - setting->value.integer = value; - - g_hash_table_insert(account->settings, g_strdup(name), setting); - - schedule_accounts_save(); -} - -void -gaim_account_set_string(GaimAccount *account, const char *name, - const char *value) -{ - GaimAccountSetting *setting; - - g_return_if_fail(account != NULL); - g_return_if_fail(name != NULL); - - setting = g_new0(GaimAccountSetting, 1); - - setting->type = GAIM_PREF_STRING; - setting->value.string = g_strdup(value); - - g_hash_table_insert(account->settings, g_strdup(name), setting); - - schedule_accounts_save(); -} - -void -gaim_account_set_bool(GaimAccount *account, const char *name, gboolean value) -{ - GaimAccountSetting *setting; - - g_return_if_fail(account != NULL); - g_return_if_fail(name != NULL); - - setting = g_new0(GaimAccountSetting, 1); - - setting->type = GAIM_PREF_BOOLEAN; - setting->value.bool = value; - - g_hash_table_insert(account->settings, g_strdup(name), setting); - - schedule_accounts_save(); -} - -static GHashTable * -get_ui_settings_table(GaimAccount *account, const char *ui) -{ - GHashTable *table; - - table = g_hash_table_lookup(account->ui_settings, ui); - - if (table == NULL) { - table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, - delete_setting); - g_hash_table_insert(account->ui_settings, g_strdup(ui), table); - } - - return table; -} - -void -gaim_account_set_ui_int(GaimAccount *account, const char *ui, - const char *name, int value) -{ - GaimAccountSetting *setting; - GHashTable *table; - - g_return_if_fail(account != NULL); - g_return_if_fail(ui != NULL); - g_return_if_fail(name != NULL); - - setting = g_new0(GaimAccountSetting, 1); - - setting->type = GAIM_PREF_INT; - setting->ui = g_strdup(ui); - setting->value.integer = value; - - table = get_ui_settings_table(account, ui); - - g_hash_table_insert(table, g_strdup(name), setting); - - schedule_accounts_save(); -} - -void -gaim_account_set_ui_string(GaimAccount *account, const char *ui, - const char *name, const char *value) -{ - GaimAccountSetting *setting; - GHashTable *table; - - g_return_if_fail(account != NULL); - g_return_if_fail(ui != NULL); - g_return_if_fail(name != NULL); - - setting = g_new0(GaimAccountSetting, 1); - - setting->type = GAIM_PREF_STRING; - setting->ui = g_strdup(ui); - setting->value.string = g_strdup(value); - - table = get_ui_settings_table(account, ui); - - g_hash_table_insert(table, g_strdup(name), setting); - - schedule_accounts_save(); -} - -void -gaim_account_set_ui_bool(GaimAccount *account, const char *ui, - const char *name, gboolean value) -{ - GaimAccountSetting *setting; - GHashTable *table; - - g_return_if_fail(account != NULL); - g_return_if_fail(ui != NULL); - g_return_if_fail(name != NULL); - - setting = g_new0(GaimAccountSetting, 1); - - setting->type = GAIM_PREF_BOOLEAN; - setting->ui = g_strdup(ui); - setting->value.bool = value; - - table = get_ui_settings_table(account, ui); - - g_hash_table_insert(table, g_strdup(name), setting); - - schedule_accounts_save(); -} - -static GaimConnectionState -gaim_account_get_state(const GaimAccount *account) -{ - GaimConnection *gc; - - g_return_val_if_fail(account != NULL, GAIM_DISCONNECTED); - - gc = gaim_account_get_connection(account); - if (!gc) - return GAIM_DISCONNECTED; - - return gaim_connection_get_state(gc); -} - -gboolean -gaim_account_is_connected(const GaimAccount *account) -{ - return (gaim_account_get_state(account) == GAIM_CONNECTED); -} - -gboolean -gaim_account_is_connecting(const GaimAccount *account) -{ - return (gaim_account_get_state(account) == GAIM_CONNECTING); -} - -gboolean -gaim_account_is_disconnected(const GaimAccount *account) -{ - return (gaim_account_get_state(account) == GAIM_DISCONNECTED); -} - -const char * -gaim_account_get_username(const GaimAccount *account) -{ - g_return_val_if_fail(account != NULL, NULL); - - return account->username; -} - -const char * -gaim_account_get_password(const GaimAccount *account) -{ - g_return_val_if_fail(account != NULL, NULL); - - return account->password; -} - -const char * -gaim_account_get_alias(const GaimAccount *account) -{ - g_return_val_if_fail(account != NULL, NULL); - - return account->alias; -} - -const char * -gaim_account_get_user_info(const GaimAccount *account) -{ - g_return_val_if_fail(account != NULL, NULL); - - return account->user_info; -} - -const char * -gaim_account_get_buddy_icon(const GaimAccount *account) -{ - g_return_val_if_fail(account != NULL, NULL); - - return account->buddy_icon; -} - -const char * -gaim_account_get_protocol_id(const GaimAccount *account) -{ - g_return_val_if_fail(accoun... [truncated message content] |