changeset 6179:16e384bb7fbf

[gaim-migrate @ 6664] Core/UI split the core initialization and shutdown. I think I got all the bugs worked out. It's looking nice and stable here, but if it causes CVS to go to hell for everyone.. er, try to fix it or let me know :) I don't have this in patch form. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Thu, 17 Jul 2003 10:35:43 +0000
parents 06e28a7b72c3
children 4fb902212769
files ChangeLog plugins/docklet/docklet.c plugins/filectl.c plugins/gaim-remote/remote.c src/Makefile.am src/core.c src/core.h src/gaim.h src/gtkaccount.c src/gtkprefs.c src/main.c src/protocols/irc/irc.c src/session.c
diffstat 13 files changed, 281 insertions(+), 133 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Jul 17 06:55:29 2003 +0000
+++ b/ChangeLog	Thu Jul 17 10:35:43 2003 +0000
@@ -7,6 +7,7 @@
 	* The Remote Control plugin no longer adds duplicate groups to your
 	  buddy list.
 	* Servers and ports are now imported correctly in MSN.
+	* Core/UI split the core initialization and shutdown.
 
 version 0.65 (07/16/2003):
 	* French translation updated (Eric (Zongo) Boumaour)
--- a/plugins/docklet/docklet.c	Thu Jul 17 06:55:29 2003 +0000
+++ b/plugins/docklet/docklet.c	Thu Jul 17 10:35:43 2003 +0000
@@ -30,6 +30,7 @@
 /* includes */
 #include "internal.h"
 
+#include "core.h"
 #include "debug.h"
 #include "prefs.h"
 #include "sound.h"
@@ -180,7 +181,7 @@
 			break;
 	}
 
-	gaim_new_item_from_stock(menu, _("Quit"), GTK_STOCK_QUIT, G_CALLBACK(do_quit), NULL, 0, 0, 0);
+	gaim_new_item_from_stock(menu, _("Quit"), GTK_STOCK_QUIT, G_CALLBACK(gaim_core_quit), NULL, 0, 0, 0);
 
 	gtk_widget_show_all(menu);
 	gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time());
--- a/plugins/filectl.c	Thu Jul 17 06:55:29 2003 +0000
+++ b/plugins/filectl.c	Thu Jul 17 10:35:43 2003 +0000
@@ -16,8 +16,6 @@
 static void init_file();
 static void check_file();
 
-extern void do_quit();
-
 /* parse char * as if were word array */
 char *getarg(char *, int, int);
 
@@ -95,7 +93,7 @@
 		} else if (!strncasecmp(command, "back", 4)) {
 			do_im_back();
 		} else if (!strncasecmp(command, "quit", 4)) {
-			do_quit();
+			gaim_core_quit();
 		}
 		free(command);
 	}
--- a/plugins/gaim-remote/remote.c	Thu Jul 17 06:55:29 2003 +0000
+++ b/plugins/gaim-remote/remote.c	Thu Jul 17 10:35:43 2003 +0000
@@ -31,6 +31,7 @@
 #include <getopt.h>
 
 #include "conversation.h"
+#include "core.h"
 #include "debug.h"
 #include "prpl.h"
 
@@ -311,7 +312,7 @@
 			g_source_remove(ui->inpa);
 			g_free(ui);
 		}
-		do_quit();
+		gaim_core_quit();
 		break;
 	case CUI_META_DETACH:
 		uis = g_slist_remove(uis, ui);
--- a/src/Makefile.am	Thu Jul 17 06:55:29 2003 +0000
+++ b/src/Makefile.am	Thu Jul 17 10:35:43 2003 +0000
@@ -16,6 +16,7 @@
 	connection.h \
 	conversation.c \
 	conversation.h \
+	core.c \
 	core.h \
 	debug.c \
 	debug.h \
--- a/src/core.c	Thu Jul 17 06:55:29 2003 +0000
+++ b/src/core.c	Thu Jul 17 10:35:43 2003 +0000
@@ -1,6 +1,10 @@
-/*
+/**
+ * @file core.c Gaim Core API
+ * @ingroup core
+ *
  * gaim
  *
+ * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org>
  *
  * 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
@@ -15,7 +19,131 @@
  * 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 "connection.h"
+#include "conversation.h"
+#include "core.h"
+#include "debug.h"
+#include "plugin.h"
+#include "pounce.h"
+#include "prefs.h"
+#include "proxy.h"
+#include "sound.h"
 
-/* DONE! */
+struct GaimCore
+{
+	char *ui;
+
+	void *reserved;
+};
+
+static GaimCoreUiOps *_ops  = NULL;
+static GaimCore      *_core = NULL;
+
+STATIC_PROTO_INIT
+
+gboolean
+gaim_core_init(const char *ui)
+{
+	GaimCoreUiOps *ops;
+	GaimCore *core;
+
+	g_return_val_if_fail(ui != NULL, FALSE);
+	g_return_val_if_fail(gaim_get_core() == NULL, FALSE);
+
+	_core = core = g_new0(GaimCore, 1);
+	core->ui = g_strdup(ui);
+	core->reserved = NULL;
+
+	ops = gaim_get_core_ui_ops();
+
+	/* Initialize all static protocols. */
+	static_proto_init();
+
+	printf("gaim_prefs_init\n");
+	gaim_prefs_init();
+
+	if (ops != NULL) {
+		if (ops->ui_prefs_init != NULL)
+			ops->ui_prefs_init();
+
+		if (ops->debug_ui_init != NULL)
+			ops->debug_ui_init();
+	}
+
+	printf("conversation_init\n");
+	gaim_conversation_init();
+	gaim_proxy_init();
+	gaim_sound_init();
+	gaim_pounces_init();
+
+	if (ops != NULL && ops->ui_init != NULL)
+		ops->ui_init();
+
+	return TRUE;
+}
+
+void
+gaim_core_quit(void)
+{
+	GaimCoreUiOps *ops;
+	GaimCore *core = gaim_get_core();
+
+	g_return_if_fail(core != NULL);
+
+	ops = gaim_get_core_ui_ops();
+
+	if (ops != NULL && ops->quit != NULL)
+		ops->quit();
+
+	/* The self destruct sequence has been initiated */
+	gaim_event_broadcast(event_quit);
+
+	/* Transmission ends */
+	gaim_connections_disconnect_all();
+
+	/* Record what we have before we blow it away... */
+	gaim_prefs_sync();
+	gaim_accounts_sync();
+
+	gaim_debug(GAIM_DEBUG_INFO, "main", "Unloading all plugins\n");
+	gaim_plugins_destroy_all();
+
+	if (core->ui != NULL) {
+		g_free(core->ui);
+		core->ui = NULL;
+	}
+
+	g_free(core);
+
+	_core = NULL;
+}
+
+const char *
+gaim_core_get_ui(void)
+{
+	GaimCore *core = gaim_get_core();
+
+	g_return_val_if_fail(core != NULL, NULL);
+
+	return core->ui;
+}
+
+GaimCore *
+gaim_get_core(void)
+{
+	return _core;
+}
+
+void
+gaim_set_core_ui_ops(GaimCoreUiOps *ops)
+{
+	_ops = ops;
+}
+
+GaimCoreUiOps *
+gaim_get_core_ui_ops(void)
+{
+	return _ops;
+}
--- a/src/core.h	Thu Jul 17 06:55:29 2003 +0000
+++ b/src/core.h	Thu Jul 17 10:35:43 2003 +0000
@@ -1,10 +1,10 @@
 /**
- * @file core.h Gaim Core
+ * @file core.h Gaim Core API
  * @defgroup core Gaim Core
  *
  * gaim
  *
- * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
+ * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org>
  * 
  * 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
@@ -20,11 +20,67 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+#ifndef _GAIM_CORE_H_
+#define _GAIM_CORE_H_
 
-#ifndef _CORE_H_
-#define _CORE_H_
+typedef struct GaimCore GaimCore;
+
+typedef struct
+{
+	void (*ui_prefs_init)(void);
+	void (*debug_ui_init)(void); /* Unfortunate necessity. */
+	void (*ui_init)(void);
+	void (*quit)(void);
+
+} GaimCoreUiOps;
+
+/**
+ * Initializes the core of gaim.
+ *
+ * This will setup preferences for all the core subsystems.
+ *
+ * @param ui The ID of the UI using the core. This should be a
+ *           unique ID, registered with the gaim team.
+ *
+ * @return @c TRUE if successful, or @c FALSE otherwise.
+ */
+gboolean gaim_core_init(const char *ui);
+
+/**
+ * Quits the core of gaim, which, depending on the UI, may quit the
+ * application using the gaim core.
+ */
+void gaim_core_quit(void);
 
-#endif /* _CORE_H_ */
+/**
+ * Returns the ID of the UI that is using the core.
+ *
+ * @return The ID of the UI that is currently using the core.
+ */
+const char *gaim_core_get_ui(void);
+
+/**
+ * Returns a handle to the gaim core.
+ *
+ * This is used for such things as signals.
+ */
+GaimCore *gaim_get_core(void);
+
+/**
+ * Sets the UI ops for the core.
+ *
+ * @param A UI ops structure for the core.
+ */
+void gaim_set_core_ui_ops(GaimCoreUiOps *ops);
+
+/**
+ * Returns the UI ops for the core.
+ *
+ * @return The core's UI ops structure.
+ */
+GaimCoreUiOps *gaim_get_core_ui_ops(void);
+
+#endif /* _GAIM_CORE_H_ */
 
 /*
 
@@ -36,9 +92,9 @@
   .'        /       |   \\         /"   "\    /' /        \   /'
  /  ____  /         |    \`\.__/-""  D O   \_/'  /          \/'
 /-'"    """""---__  |     "-/"   O G     R   /'        _--"`
-                  \_|      /   R    __--_    ),   __--""
-                    '""--_/  T   _-"_>--<_\the'-" \
-                   {\__--_/}    / \\__>--<__\   B  \
+                  \_|      /   R    __--_  t ),   __--""
+                    '""--_/  T   _-"_>--<_\ h '-" \
+                   {\__--_/}    / \\__>--<__\ e B  \
                    /'   (_/  _-"  | |__>--<__|   U  |
                   |   _/) )-"     | |__>--<__|  R   |
                   / /" ,_/       / /__>---<__/ N    |
--- a/src/gaim.h	Thu Jul 17 06:55:29 2003 +0000
+++ b/src/gaim.h	Thu Jul 17 10:35:43 2003 +0000
@@ -36,9 +36,6 @@
 extern GSList *unread_message_queue;
 extern GSList *away_time_queue;
 
-/* Functions in main.c */
-extern void do_quit();
-
 /* Functions in dialogs.c */
 extern void g_show_info_text(GaimConnection *, const char *, int, const char *, ...);
 extern void show_change_passwd(GaimConnection *);
--- a/src/gtkaccount.c	Thu Jul 17 06:55:29 2003 +0000
+++ b/src/gtkaccount.c	Thu Jul 17 10:35:43 2003 +0000
@@ -39,9 +39,6 @@
 
 #include "ui.h"
 
-/* XXX for do_quit() */
-#include "gaim.h"
-
 enum
 {
 	COLUMN_ICON,
@@ -1827,6 +1824,6 @@
 	if (GAIM_GTK_BLIST(gaim_get_blist())->window == NULL &&
 		mainwindow == NULL && gaim_connections_get_all() == NULL) {
 
-		do_quit();
+		gaim_core_quit();
 	}
 }
--- a/src/gtkprefs.c	Thu Jul 17 06:55:29 2003 +0000
+++ b/src/gtkprefs.c	Thu Jul 17 10:35:43 2003 +0000
@@ -1481,7 +1481,7 @@
 		gpointer data)
 {
 	GtkWidget *hbox = data;
-	gboolean enabled = value;
+	gboolean enabled = (gboolean)value;
 
 	gtk_widget_set_sensitive(hbox, enabled);
 }
--- a/src/main.c	Thu Jul 17 06:55:29 2003 +0000
+++ b/src/main.c	Thu Jul 17 10:35:43 2003 +0000
@@ -23,6 +23,7 @@
 
 #include "account.h"
 #include "conversation.h"
+#include "core.h"
 #include "debug.h"
 #include "ft.h"
 #include "log.h"
@@ -34,8 +35,6 @@
 #include "status.h"
 #include "util.h"
 
-//#include "gaim.h"
-
 #include "gtkaccount.h"
 #include "gtkblist.h"
 #include "gtkconn.h"
@@ -59,57 +58,6 @@
 #include "locale.h"
 #include <getopt.h>
 
-#if 0
-#ifdef GAIM_PLUGINS
-# ifndef _WIN32
-#  include <dlfcn.h>
-# endif
-#endif /* GAIM_PLUGINS */
-
-#include <gtk/gtk.h>
-#ifndef _WIN32
-#include <gdk/gdkx.h>
-#include <unistd.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/un.h>
-#include <sys/wait.h>
-#endif /* !_WIN32 */
-#include <gdk/gdk.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include "prpl.h"
-#include "sound.h"
-#include "gtksound.h"
-#include "gaim.h"
-#include "account.h"
-#include "prefs.h"
-#include "notify.h"
-#include "gtkaccount.h"
-#include "gtkblist.h"
-#include "gtkconn.h"
-#include "gtkdebug.h"
-#include "gtknotify.h"
-#include "gtkrequest.h"
-#include "gtksound.h"
-#if HAVE_SIGNAL_H
-#include <signal.h>
-#endif
-#include "locale.h"
-#include <getopt.h>
-
-#ifdef _WIN32
-#include "win32dep.h"
-#endif
-#endif
-
 extern void load_prefs();
 extern void load_pounces();
 
@@ -154,44 +102,6 @@
 };
 #endif
 
-STATIC_PROTO_INIT
-
-void do_quit()
-{
-	/* captain's log, stardate... */
-	system_log(log_quit, NULL, NULL, OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON);
-
-	/* the self destruct sequence has been initiated */
-	gaim_event_broadcast(event_quit);
-
-	/* transmission ends */
-	gaim_connections_disconnect_all();
-
-	/* record what we have before we blow it away... */
-	gaim_prefs_sync();
-	gaim_accounts_sync();
-
-	gaim_debug(GAIM_DEBUG_INFO, "main", "Unloading all plugins\n");
-	gaim_plugins_destroy_all();
-
-	/* XXX */
-#if 0
-#ifdef USE_PERL
-	/* yup, perl too */
-	perl_end();
-#endif
-#endif
-
-#ifdef USE_SM
-	/* unplug */
-	session_end();
-#endif
-
-	/* and end it all... */
-	gtk_main_quit();
-}
-
-
 static guint snd_tmout = 0;
 static gboolean sound_timeout(gpointer data)
 {
@@ -339,7 +249,7 @@
 #endif
 		gtk_widget_hide(mainwindow);
 	} else
-		do_quit();
+		gaim_core_quit();
 }
 
 void show_login()
@@ -577,6 +487,63 @@
 }
 #endif /* _WIN32 */
 
+static void
+debug_init(void)
+{
+	gaim_set_debug_ui_ops(gaim_get_gtk_debug_ui_ops());
+	gaim_gtk_debug_init();
+}
+
+static void
+gaim_gtk_ui_init(void)
+{
+	/* Set the UI operation structures. */
+	gaim_set_win_ui_ops(gaim_get_gtk_window_ui_ops());
+	gaim_set_xfer_ui_ops(gaim_get_gtk_xfer_ui_ops());
+	gaim_set_blist_ui_ops(gaim_get_gtk_blist_ui_ops());
+	gaim_set_notify_ui_ops(gaim_get_gtk_notify_ui_ops());
+	gaim_set_request_ui_ops(gaim_get_gtk_request_ui_ops());
+	gaim_set_sound_ui_ops(gaim_get_gtk_sound_ui_ops());
+	gaim_set_connection_ui_ops(gaim_get_gtk_connection_ui_ops());
+
+	gaim_gtk_prefs_init();
+	gaim_gtk_blist_init();
+	gaim_gtk_conversation_init();
+	gaim_gtk_pounces_init();
+	gaim_gtk_xfer_init();
+}
+
+static void
+gaim_gtk_quit(void)
+{
+	/* XXX? */
+
+	/* captain's log, stardate... */
+	system_log(log_quit, NULL, NULL, OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON);
+
+#ifdef USE_SM
+	/* unplug */
+	session_end();
+#endif
+
+	/* and end it all... */
+	gtk_main_quit();
+}
+
+static GaimCoreUiOps core_ops =
+{
+	gaim_gtk_prefs_init,
+	debug_init,
+	gaim_gtk_ui_init,
+	gaim_gtk_quit
+};
+
+static GaimCoreUiOps *
+gaim_get_gtk_core_ui_ops(void)
+{
+	return &core_ops;
+}
+
 /* FUCKING GET ME A TOWEL! */
 #ifdef _WIN32
 int gaim_main(int argc, char *argv[])
@@ -833,36 +800,39 @@
 		return 0;
 	}
 
+	gaim_gtk_stock_init();
+
+	gaim_set_core_ui_ops(gaim_get_gtk_core_ui_ops());
+
+	if (!gaim_core_init(GAIM_GTK_UI)) {
+		fprintf(stderr,
+				"Initialization of the Gaim core failed. Dumping core.\n"
+				"Please report this!\n");
+		abort();
+	}
+
+#if 0
 	/* This has to be done before the debug stuff. */
 	gaim_gtk_stock_init();
-	
+
 	static_proto_init();
 
 	gaim_prefs_init();
-	gaim_gtk_prefs_init();
 
 	/* This kind of has to be here.. sucks, but it's important. */
-	gaim_set_debug_ui_ops(gaim_get_gtk_debug_ui_ops());
 	gaim_gtk_debug_init();
 
-	/* Set the UI operation structures. */
-	gaim_set_win_ui_ops(gaim_get_gtk_window_ui_ops());
-	gaim_set_xfer_ui_ops(gaim_get_gtk_xfer_ui_ops());
-	gaim_set_blist_ui_ops(gaim_get_gtk_blist_ui_ops());
-	gaim_set_notify_ui_ops(gaim_get_gtk_notify_ui_ops());
-	gaim_set_request_ui_ops(gaim_get_gtk_request_ui_ops());
-	gaim_set_sound_ui_ops(gaim_get_gtk_sound_ui_ops());
-	gaim_set_connection_ui_ops(gaim_get_gtk_connection_ui_ops());
-
 	gaim_conversation_init();
 	gaim_proxy_init();
 	gaim_sound_init();
 	gaim_pounces_init();
 
+	gaim_gtk_prefs_init();
 	gaim_gtk_blist_init();
 	gaim_gtk_conversation_init();
 	gaim_gtk_pounces_init();
 	gaim_gtk_xfer_init();
+#endif
 
 	plugin_search_paths[0] = LIBDIR;
 	plugin_search_paths[1] = gaim_user_dir();
--- a/src/protocols/irc/irc.c	Thu Jul 17 06:55:29 2003 +0000
+++ b/src/protocols/irc/irc.c	Thu Jul 17 10:35:43 2003 +0000
@@ -27,6 +27,7 @@
 #include "account.h"
 #include "accountopt.h"
 #include "conversation.h"
+#include "core.h"
 #include "debug.h"
 #include "ft.h"
 #include "multi.h"
@@ -2311,7 +2312,7 @@
 	} else if (!g_ascii_strcasecmp(pdibuf, "QUIT")) {
 		char *reason = word_eol[2];
 		id->str = g_string_insert(id->str, 0, reason);
-		do_quit();
+		gaim_core_quit();
 	} else if (!g_ascii_strcasecmp(pdibuf, "VERSION")) {
 		g_snprintf(buf, sizeof(buf), "VERSION\r\n");
 		irc_write(id->fd, buf, strlen(buf));
--- a/src/session.c	Thu Jul 17 06:55:29 2003 +0000
+++ b/src/session.c	Thu Jul 17 10:35:43 2003 +0000
@@ -26,9 +26,6 @@
 
 #include "debug.h"
 
-/* XXX */
-extern void do_quit();
-
 extern char *opt_rcfile_arg;
 
 #ifdef USE_SM
@@ -199,7 +196,7 @@
 void session_die(SmcConn conn, SmPointer data) {
 	gaim_debug(GAIM_DEBUG_INFO, "Session Management",
 			   "Received die\n");
-	do_quit();
+	gaim_core_quit();
 }
 
 void session_save_complete(SmcConn conn, SmPointer data) {