summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/cfgfiles.c60
-rw-r--r--src/common/chanopt.c5
-rw-r--r--src/common/ctcp.c12
-rw-r--r--src/common/dcc.c8
-rw-r--r--src/common/dirent-win32.c199
-rw-r--r--src/common/dirent-win32.h28
-rw-r--r--src/common/ignore.c5
-rw-r--r--src/common/inbound.c5
-rw-r--r--src/common/inet.h4
-rw-r--r--src/common/makefile.mak44
-rw-r--r--src/common/msproxy.c5
-rw-r--r--src/common/network.c5
-rw-r--r--src/common/notify.c5
-rw-r--r--src/common/outbound.c22
-rw-r--r--src/common/plugin.c191
-rw-r--r--src/common/plugin.h11
-rw-r--r--src/common/proto-irc.c5
-rw-r--r--src/common/server.c40
-rw-r--r--src/common/servlist.c3
-rw-r--r--src/common/ssl.c2
-rw-r--r--src/common/text.c48
-rw-r--r--src/common/thread.c33
-rw-r--r--src/common/thread.h10
-rw-r--r--src/common/util.c193
-rw-r--r--src/common/util.h9
-rw-r--r--src/common/xchat-plugin.h33
-rw-r--r--src/common/xchat.c33
-rw-r--r--src/common/xchat.h19
-rw-r--r--src/fe-gtk/Makefile.am9
-rw-r--r--src/fe-gtk/about.c55
-rw-r--r--src/fe-gtk/banlist.c10
-rw-r--r--src/fe-gtk/chanlist.c5
-rw-r--r--src/fe-gtk/chanview-tabs.c8
-rw-r--r--src/fe-gtk/editlist.c6
-rw-r--r--src/fe-gtk/fe-gtk.c95
-rw-r--r--src/fe-gtk/fe-gtk.h9
-rw-r--r--src/fe-gtk/fkeys.c7
-rw-r--r--src/fe-gtk/gtkutil.c252
-rw-r--r--src/fe-gtk/joind.c5
-rw-r--r--src/fe-gtk/maingui.c89
-rw-r--r--src/fe-gtk/makefile.mak62
-rw-r--r--src/fe-gtk/menu.c41
-rw-r--r--src/fe-gtk/palette.c8
-rw-r--r--src/fe-gtk/palette.h1
-rw-r--r--src/fe-gtk/plugin-tray.c50
-rw-r--r--src/fe-gtk/plugingui.c9
-rw-r--r--src/fe-gtk/rawlog.c5
-rw-r--r--src/fe-gtk/search.c2
-rw-r--r--src/fe-gtk/setup.c87
-rw-r--r--src/fe-gtk/sexy-iso-codes.c305
-rw-r--r--src/fe-gtk/sexy-iso-codes.h37
-rw-r--r--src/fe-gtk/sexy-marshal.c129
-rw-r--r--src/fe-gtk/sexy-marshal.h28
-rw-r--r--src/fe-gtk/sexy-spell-entry.c108
-rw-r--r--src/fe-gtk/typedef.h11
-rw-r--r--src/fe-gtk/xchat.exe.manifest22
-rw-r--r--src/fe-gtk/xchat.rc28
-rw-r--r--src/fe-gtk/xtext.c41
-rw-r--r--src/fe-gtk/xtext.h1
-rw-r--r--src/fe-text/fe-text.c473
-rw-r--r--src/fe-text/fe-text.h30
-rw-r--r--src/fe-text/makefile.mak20
-rw-r--r--src/gtk2-prefs/callbacks.cpp224
-rw-r--r--src/gtk2-prefs/callbacks.h71
-rw-r--r--src/gtk2-prefs/config.h59
-rw-r--r--src/gtk2-prefs/interface.cpp836
-rw-r--r--src/gtk2-prefs/interface.h5
-rw-r--r--src/gtk2-prefs/main.cpp616
-rw-r--r--src/gtk2-prefs/main.h32
-rw-r--r--src/gtk2-prefs/makefile.mak24
-rw-r--r--src/gtk2-prefs/support.cpp146
-rw-r--r--src/gtk2-prefs/support.h44
-rw-r--r--src/gtk2-prefs/sys_win32.h28
-rw-r--r--src/gtk2-prefs/win32util.cpp80
-rw-r--r--src/gtk2-prefs/win32util.h26
-rw-r--r--src/makefile.mak23
-rw-r--r--src/makeinc.skel.mak45
-rw-r--r--src/pixmaps/makefile.mak18
-rw-r--r--src/version-script4
79 files changed, 4843 insertions, 523 deletions
diff --git a/src/common/cfgfiles.c b/src/common/cfgfiles.c
index 8bb2a61b..130ad9d9 100644
--- a/src/common/cfgfiles.c
+++ b/src/common/cfgfiles.c
@@ -17,7 +17,6 @@
  */
 
 #include <fcntl.h>
-#include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
@@ -31,11 +30,11 @@
 #include "text.h"
 #include "xchatc.h"
 
-#ifdef WIN32
-#define XCHAT_DIR "X-Chat 2"
-#else
+#ifndef WIN32
+#include <unistd.h>
 #define XCHAT_DIR ".xchat2"
 #endif
+
 #define DEF_FONT "Monospace 9"
 
 void
@@ -166,9 +165,13 @@ list_delentry (GSList ** list, char *name)
 char *
 cfg_get_str (char *cfg, char *var, char *dest, int dest_len)
 {
+	char buffer[128];	/* should be plenty for a variable name */
+
+	sprintf (buffer, "%s ", var);	/* add one space, this way it works against var - var2 checks too */
+
 	while (1)
 	{
-		if (!strncasecmp (var, cfg, strlen (var)))
+		if (!strncasecmp (buffer, cfg, strlen (var) + 1))
 		{
 			char *value, t;
 			cfg += strlen (var);
@@ -308,12 +311,19 @@ get_xdir_fs (void)
 {
 	if (!xdir_fs)
 	{
-		char out[256];
+		if (portable_mode ())
+		{
+			xdir_fs = ".\\config";
+		}
+		else
+		{
+			char out[256];
 
-		if (!get_reg_str ("Software\\Microsoft\\Windows\\CurrentVersion\\"
-				"Explorer\\Shell Folders", "AppData", out, sizeof (out)))
-			return "./config";
-		xdir_fs = g_strdup_printf ("%s\\" XCHAT_DIR, out);
+			if (!get_reg_str ("Software\\Microsoft\\Windows\\CurrentVersion\\"
+					"Explorer\\Shell Folders", "AppData", out, sizeof (out)))
+				return "./config";
+			xdir_fs = g_strdup_printf ("%s\\" "X-Chat 2", out);
+		}
 	}
 	return xdir_fs;
 }
@@ -393,7 +403,9 @@ const struct prefs vars[] = {
 	{"dcc_blocksize", P_OFFINT (dcc_blocksize), TYPE_INT},
 	{"dcc_completed_dir", P_OFFSET (dcc_completed_dir), TYPE_STR},
 	{"dcc_dir", P_OFFSET (dccdir), TYPE_STR},
+#ifndef WIN32
 	{"dcc_fast_send", P_OFFINT (fastdccsend), TYPE_BOOL},
+#endif
 	{"dcc_global_max_get_cps", P_OFFINT (dcc_global_max_get_cps), TYPE_INT},
 	{"dcc_global_max_send_cps", P_OFFINT (dcc_global_max_send_cps), TYPE_INT},
 	{"dcc_ip", P_OFFSET (dcc_ip_str), TYPE_STR},
@@ -429,7 +441,11 @@ const struct prefs vars[] = {
 	{"gui_input_style", P_OFFINT (style_inputbox), TYPE_BOOL},
 	{"gui_join_dialog", P_OFFINT (gui_join_dialog), TYPE_BOOL},
 	{"gui_lagometer", P_OFFINT (lagometer), TYPE_INT},
+	{"gui_license", P_OFFSET (gui_license), TYPE_STR},
 	{"gui_mode_buttons", P_OFFINT (chanmodebuttons), TYPE_BOOL},
+#ifdef WIN32
+	{"gui_one_instance", P_OFFINT (gui_one_instance), TYPE_BOOL},
+#endif
 	{"gui_pane_left_size", P_OFFINT (gui_pane_left_size), TYPE_INT},
 	{"gui_pane_right_size", P_OFFINT (gui_pane_right_size), TYPE_INT},
 	{"gui_quit_dialog", P_OFFINT (gui_quit_dialog), TYPE_BOOL},
@@ -536,6 +552,9 @@ const struct prefs vars[] = {
 
 	{"tab_chans", P_OFFINT (tabchannels), TYPE_BOOL},
 	{"tab_dialogs", P_OFFINT (privmsgtab), TYPE_BOOL},
+#ifdef WIN32
+	{"tab_icons", P_OFFINT (tab_icons), TYPE_BOOL},
+#endif
 	{"tab_layout", P_OFFINT (tab_layout), TYPE_INT},
 	{"tab_new_to_front", P_OFFINT (newtabstofront), TYPE_INT},
 	{"tab_notices", P_OFFINT (notices_tabs), TYPE_BOOL},
@@ -546,9 +565,18 @@ const struct prefs vars[] = {
 	{"tab_sort", P_OFFINT (tab_sort), TYPE_BOOL},
 	{"tab_trunc", P_OFFINT (truncchans), TYPE_INT},
 	{"tab_utils", P_OFFINT (windows_as_tabs), TYPE_BOOL},
+#ifdef WIN32
+	{"tab_xp", P_OFFINT (tab_xp), TYPE_BOOL},
+#endif
 
+	{"text_auto_copy_color", P_OFFINT (autocopy_color), TYPE_BOOL},	
+	{"text_auto_copy_stamp", P_OFFINT (autocopy_stamp), TYPE_BOOL},
+	{"text_auto_copy_text", P_OFFINT (autocopy_text), TYPE_BOOL},
 	{"text_background", P_OFFSET (background), TYPE_STR},
 	{"text_color_nicks", P_OFFINT (colorednicks), TYPE_BOOL},
+#ifdef WIN32
+	{"text_emoticons", P_OFFINT (emoticons), TYPE_BOOL},
+#endif
 	{"text_font", P_OFFSET (font_normal), TYPE_STR},
 	{"text_indent", P_OFFINT (indent_nicks), TYPE_BOOL},
 	{"text_max_indent", P_OFFINT (max_auto_indent), TYPE_INT},
@@ -556,6 +584,7 @@ const struct prefs vars[] = {
 	{"text_replay", P_OFFINT (text_replay), TYPE_BOOL},
 	{"text_show_marker", P_OFFINT (show_marker), TYPE_BOOL},
 	{"text_show_sep", P_OFFINT (show_separator), TYPE_BOOL},
+	{"text_spell_langs", P_OFFSET (spell_langs), TYPE_STR},
 	{"text_stripcolor", P_OFFINT (stripcolor), TYPE_BOOL},
 	{"text_thin_sep", P_OFFINT (thin_separator), TYPE_BOOL},
 	{"text_tint_blue", P_OFFINT (tint_blue), TYPE_INT},
@@ -624,13 +653,16 @@ load_config (void)
 	prefs.indent_nicks = 1;
 	prefs.thin_separator = 1;
 	prefs._tabs_position = 2; /* 2 = left */
+#ifndef WIN32
 	prefs.fastdccsend = 1;
+#endif
 	prefs.wordwrap = 1;
 	prefs.autosave = 1;
 	prefs.autodialog = 1;
 	prefs.gui_input_spell = 1;
 	prefs.autoreconnect = 1;
 	prefs.recon_delay = 10;
+	prefs.autocopy_text = 1;
 	prefs.text_replay = 1;
 	prefs.tabchannels = 1;
 	prefs.tab_layout = 2;	/* 0=Tabs 1=Reserved 2=Tree */
@@ -683,6 +715,8 @@ load_config (void)
 #ifdef WIN32
 	prefs.identd = 1;
 #endif
+	strcpy (prefs.gui_license, "");
+	strcpy (prefs.spell_langs, g_getenv ("LC_ALL") ? g_getenv ("LC_ALL") : "en_US");
 	strcpy (prefs.stamp_format, "[%H:%M] ");
 	strcpy (prefs.timestamp_log_format, "%b %d %H:%M:%S ");
 	strcpy (prefs.logmask, "%n-%c.log");
@@ -1067,7 +1101,13 @@ cmd_set (struct session *sess, char *tbuf, char *word[], char *word_eol[])
 	while (vars[i].name);
 
 	if (!finds && !quiet)
+	{
 		PrintText (sess, "No such variable.\n");
+	}
+	else if (prefs.autosave && !save_config ())
+	{
+		PrintText (sess, "Error saving changes to disk.\n");
+	}
 
 	return TRUE;
 }
diff --git a/src/common/chanopt.c b/src/common/chanopt.c
index a4fd8faa..f8e16e8b 100644
--- a/src/common/chanopt.c
+++ b/src/common/chanopt.c
@@ -3,12 +3,15 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <errno.h>
 
+#ifndef WIN32
+#include <unistd.h>
+#endif
+
 #include "xchat.h"
 
 #include "cfgfiles.h"
diff --git a/src/common/ctcp.c b/src/common/ctcp.c
index 574cda79..2bb75746 100644
--- a/src/common/ctcp.c
+++ b/src/common/ctcp.c
@@ -18,9 +18,12 @@
 
 #include <stdio.h>
 #include <string.h>
-#include <unistd.h>
 #include <stdlib.h>
 
+#ifndef WIN32
+#include <unistd.h>
+#endif
+
 #include "xchat.h"
 #include "cfgfiles.h"
 #include "util.h"
@@ -134,8 +137,13 @@ ctcp_handle (session *sess, char *to, char *nick, char *ip,
 
 	if (!strcasecmp (msg, "VERSION") && !prefs.hidever)
 	{
-		snprintf (outbuf, sizeof (outbuf), "VERSION xchat "PACKAGE_VERSION" %s",
+#ifdef WIN32
+		snprintf (outbuf, sizeof (outbuf), "VERSION XChat-WDK "PACKAGE_VERSION" [x%d] / %s",
+					 get_cpu_arch (), get_cpu_str ());
+#else
+		snprintf (outbuf, sizeof (outbuf), "VERSION XChat-WDK "PACKAGE_VERSION" %s",
 					 get_cpu_str ());
+#endif
 		serv->p_nctcp (serv, nick, outbuf);
 	}
 
diff --git a/src/common/dcc.c b/src/common/dcc.c
index 8f289342..d91b7e8e 100644
--- a/src/common/dcc.c
+++ b/src/common/dcc.c
@@ -31,7 +31,6 @@
 #include <time.h>
 #include <errno.h>
 #include <sys/stat.h>
-#include <unistd.h>
 #include <fcntl.h>
 
 #define WANTSOCKET
@@ -41,6 +40,8 @@
 
 #ifdef WIN32
 #include <windows.h>
+#else
+#include <unistd.h>
 #endif
 
 #include "xchat.h"
@@ -57,6 +58,9 @@
 
 #ifdef USE_DCC64
 #define BIG_STR_TO_INT(x) strtoull(x,NULL,10)
+#ifdef WIN32
+#define stat _stat64
+#endif
 #else
 #define BIG_STR_TO_INT(x) strtoul(x,NULL,10)
 #endif
@@ -1984,7 +1988,7 @@ is_same_file (struct DCC *dcc, struct DCC *new_dcc)
 
 	/* now handle case-insensitive Filesystems: HFS+, FAT */
 #ifdef WIN32
-#warning no win32 implementation - behaviour may be unreliable
+	/* warning no win32 implementation - behaviour may be unreliable */
 #else
 	/* this fstat() shouldn't really fail */
 	if ((dcc->fp == -1 ? stat (dcc->destfile_fs, &st_a) : fstat (dcc->fp, &st_a)) == -1)
diff --git a/src/common/dirent-win32.c b/src/common/dirent-win32.c
new file mode 100644
index 00000000..273c6732
--- /dev/null
+++ b/src/common/dirent-win32.c
@@ -0,0 +1,199 @@
+/*****************************************************************************
+ * dirent.h - dirent API for Microsoft Visual Studio
+ *
+ * Copyright (C) 2006 Toni Ronkko
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * ``Software''), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL TONI RONKKO BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Dec 15, 2009, John Cunningham
+ * Added rewinddir member function
+ *
+ * Jan 18, 2008, Toni Ronkko
+ * Using FindFirstFileA and WIN32_FIND_DATAA to avoid converting string
+ * between multi-byte and unicode representations.  This makes the
+ * code simpler and also allows the code to be compiled under MingW.  Thanks
+ * to Azriel Fasten for the suggestion.
+ *
+ * Mar 4, 2007, Toni Ronkko
+ * Bug fix: due to the strncpy_s() function this file only compiled in
+ * Visual Studio 2005.  Using the new string functions only when the
+ * compiler version allows.
+ *
+ * Nov  2, 2006, Toni Ronkko
+ * Major update: removed support for Watcom C, MS-DOS and Turbo C to
+ * simplify the file, updated the code to compile cleanly on Visual
+ * Studio 2005 with both unicode and multi-byte character strings,
+ * removed rewinddir() as it had a bug.
+ *
+ * Aug 20, 2006, Toni Ronkko
+ * Removed all remarks about MSVC 1.0, which is antiqued now.  Simplified
+ * comments by removing SGML tags.
+ *
+ * May 14 2002, Toni Ronkko
+ * Embedded the function definitions directly to the header so that no
+ * source modules need to be included in the Visual Studio project.  Removed
+ * all the dependencies to other projects so that this very header can be
+ * used independently.
+ *
+ * May 28 1998, Toni Ronkko
+ * First version.
+ *****************************************************************************/
+
+#include "dirent-win32.h"
+
+/* Use the new safe string functions introduced in Visual Studio 2005 */
+#if defined(_MSC_VER) && _MSC_VER >= 1400
+# define STRNCPY(dest,src,size) strncpy_s((dest),(size),(src),_TRUNCATE)
+#else
+# define STRNCPY(dest,src,size) strncpy((dest),(src),(size))
+#endif
+
+
+/*****************************************************************************
+ * Open directory stream DIRNAME for read and return a pointer to the
+ * internal working area that is used to retrieve individual directory
+ * entries.
+ */
+DIR *opendir(const char *dirname)
+{
+   DIR *dirp;
+   assert (dirname != NULL);
+   assert (strlen (dirname) < MAX_PATH);
+
+   /* construct new DIR structure */
+   dirp = (DIR*) malloc (sizeof (struct DIR));
+   if (dirp != NULL) {
+      char *p;
+
+      /* take directory name... */
+      STRNCPY (dirp->patt, dirname, sizeof(dirp->patt));
+      dirp->patt[MAX_PATH] = '\0';
+
+      /* ... and append search pattern to it */
+      p = strchr (dirp->patt, '\0');
+      if (dirp->patt < p  &&  *(p-1) != '\\'  &&  *(p-1) != ':') {
+         *p++ = '\\';
+      }
+      *p++ = '*';
+      *p = '\0';
+
+      /* open stream and retrieve first file */
+      dirp->search_handle = FindFirstFileA (dirp->patt, &dirp->current.data);
+      if (dirp->search_handle == INVALID_HANDLE_VALUE) {
+         /* invalid search pattern? */
+         free (dirp);
+         return NULL;
+      }
+
+      /* there is an un-processed directory entry in memory now */
+      dirp->cached = 1;
+   }
+
+   return dirp;
+}
+
+
+/*****************************************************************************
+ * Read a directory entry, and return a pointer to a dirent structure
+ * containing the name of the entry in d_name field.  Individual directory
+ * entries returned by this very function include regular files,
+ * sub-directories, pseudo-directories "." and "..", but also volume labels,
+ * hidden files and system files may be returned.
+ */
+struct dirent *readdir(DIR *dirp)
+{
+   assert (dirp != NULL);
+
+   if (dirp->search_handle == INVALID_HANDLE_VALUE) {
+      /* directory stream was opened/rewound incorrectly or ended normally */
+      return NULL;
+   }
+
+   /* get next directory entry */
+   if (dirp->cached != 0) {
+      /* a valid directory entry already in memory */
+      dirp->cached = 0;
+   } else {
+      /* read next directory entry from disk */
+      if (FindNextFileA (dirp->search_handle, &dirp->current.data) == FALSE) {
+         /* the very last file has been processed or an error occured */
+         FindClose (dirp->search_handle);
+         dirp->search_handle = INVALID_HANDLE_VALUE;
+         return NULL;
+      }
+   }
+
+   /* copy as a multibyte character string */
+   STRNCPY ( dirp->current.d_name,
+             dirp->current.data.cFileName,
+             sizeof(dirp->current.d_name) );
+   dirp->current.d_name[MAX_PATH] = '\0';
+
+   return &dirp->current;
+}
+
+
+/*****************************************************************************
+ * Close directory stream opened by opendir() function.  Close of the
+ * directory stream invalidates the DIR structure as well as any previously
+ * read directory entry.
+ */
+int closedir(DIR *dirp)
+{
+   assert (dirp != NULL);
+
+   /* release search handle */
+   if (dirp->search_handle != INVALID_HANDLE_VALUE) {
+      FindClose (dirp->search_handle);
+      dirp->search_handle = INVALID_HANDLE_VALUE;
+   }
+
+   /* release directory handle */
+   free (dirp);
+   return 0;
+}
+
+
+/*****************************************************************************
+ * Resets the position of the directory stream to which dirp refers to the
+ * beginning of the directory. It also causes the directory stream to refer
+ * to the current state of the corresponding directory, as a call to opendir()
+ * would have done. If dirp does not refer to a directory stream, the effect
+ * is undefined.
+ */
+void rewinddir(DIR* dirp)
+{
+   /* release search handle */
+   if (dirp->search_handle != INVALID_HANDLE_VALUE) {
+      FindClose (dirp->search_handle);
+      dirp->search_handle = INVALID_HANDLE_VALUE;
+   }
+
+   /* open new search handle and retrieve first file */
+   dirp->search_handle = FindFirstFileA (dirp->patt, &dirp->current.data);
+   if (dirp->search_handle == INVALID_HANDLE_VALUE) {
+      /* invalid search pattern? */
+      free (dirp);
+      return;
+   }
+
+   /* there is an un-processed directory entry in memory now */
+   dirp->cached = 1;
+}
diff --git a/src/common/dirent-win32.h b/src/common/dirent-win32.h
new file mode 100644
index 00000000..cbb753e6
--- /dev/null
+++ b/src/common/dirent-win32.h
@@ -0,0 +1,28 @@
+#ifndef DIRENT_H
+#define DIRENT_H
+
+#include <windows.h>
+#include <string.h>
+#include <assert.h>
+
+typedef struct dirent
+{
+   char d_name[MAX_PATH + 1]; /* current dir entry (multi-byte char string) */
+   WIN32_FIND_DATAA data;     /* file attributes */
+}  dirent;
+
+typedef struct DIR
+{
+   dirent current;            /* Current directory entry */
+   int    cached;             /* Indicates un-processed entry in memory */
+   HANDLE search_handle;      /* File search handle */
+   char   patt[MAX_PATH + 3]; /* search pattern (3 = pattern + "\\*\0") */
+} DIR;
+
+/* Forward declarations */
+DIR *opendir (const char *dirname);
+struct dirent *readdir (DIR *dirp);
+int closedir (DIR *dirp);
+void rewinddir(DIR* dirp);
+
+#endif /*DIRENT_H*/
diff --git a/src/common/ignore.c b/src/common/ignore.c
index c3544f30..0ed23daa 100644
--- a/src/common/ignore.c
+++ b/src/common/ignore.c
@@ -19,11 +19,14 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 
+#ifndef WIN32
+#include <unistd.h>
+#endif
+
 #include "xchat.h"
 #include "ignore.h"
 #include "cfgfiles.h"
diff --git a/src/common/inbound.c b/src/common/inbound.c
index 41f5cff3..bd7252c5 100644
--- a/src/common/inbound.c
+++ b/src/common/inbound.c
@@ -21,9 +21,12 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <sys/types.h>
-#include <unistd.h>
 #include <time.h>
 
+#ifndef WIN32
+#include <unistd.h>
+#endif
+
 #define WANTARPA
 #define WANTDNS
 #include "inet.h"
diff --git a/src/common/inet.h b/src/common/inet.h
index b420c9c6..8995569c 100644
--- a/src/common/inet.h
+++ b/src/common/inet.h
@@ -21,12 +21,12 @@
 
 #else
 
+#include "../../config.h"
 #ifdef USE_IPV6
 #include <winsock2.h>
 #include <ws2tcpip.h>
-#include <tpipv6.h>
 #else
-#include <winsock.h>
+#include <winsock2.h>
 #endif
 
 #define set_blocking(sok)	{ \
diff --git a/src/common/makefile.mak b/src/common/makefile.mak
new file mode 100644
index 00000000..f78a6d8d
--- /dev/null
+++ b/src/common/makefile.mak
@@ -0,0 +1,44 @@
+include "..\makeinc.mak"
+
+COMMON_OBJECTS = \
+cfgfiles.obj \
+chanopt.obj \
+ctcp.obj \
+dcc.obj \
+dirent-win32.obj \
+history.obj \
+ignore.obj \
+inbound.obj \
+modes.obj \
+network.obj \
+notify.obj \
+outbound.obj \
+plugin.obj \
+plugin-timer.obj \
+proto-irc.obj \
+server.obj \
+servlist.obj \
+ssl.obj \
+text.obj \
+thread.obj \
+tree.obj \
+url.obj \
+userlist.obj \
+util.obj \
+xchat.obj
+
+all: $(COMMON_OBJECTS) xchatcommon.lib dirent-win32.lib
+
+xchatcommon.lib: $(COMMON_OBJECTS)
+	lib /nologo /out:xchatcommon.lib $(COMMON_OBJECTS)
+
+dirent-win32.lib: dirent-win32.obj
+	lib /nologo /out:dirent-win32.lib dirent-win32.obj
+
+.c.obj::
+	$(CC) $(CFLAGS) $(GLIB) $<
+
+clean:
+	@del *.obj
+	@del xchatcommon.lib
+	@del dirent-win32.lib
diff --git a/src/common/msproxy.c b/src/common/msproxy.c
index 9c85394d..5103233a 100644
--- a/src/common/msproxy.c
+++ b/src/common/msproxy.c
@@ -26,9 +26,12 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <fcntl.h>
 
+#ifndef WIN32
+#include <unistd.h>
+#endif
+
 #define WANTSOCKET
 #define WANTARPA
 #include "inet.h"
diff --git a/src/common/network.c b/src/common/network.c
index 0c409506..eba24b05 100644
--- a/src/common/network.c
+++ b/src/common/network.c
@@ -21,9 +21,12 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
-#include <unistd.h>
 #include <glib.h>
 
+#ifndef WIN32
+#include <unistd.h>
+#endif
+
 #include "../../config.h"				  /* grab USE_IPV6 and LOOKUPD defines */
 
 #define WANTSOCKET
diff --git a/src/common/notify.c b/src/common/notify.c
index 04795849..9c6e54de 100644
--- a/src/common/notify.c
+++ b/src/common/notify.c
@@ -22,9 +22,12 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <unistd.h>
 #include <time.h>
 
+#ifndef WIN32
+#include <unistd.h>
+#endif
+
 #include "xchat.h"
 #include "notify.h"
 #include "cfgfiles.h"
diff --git a/src/common/outbound.c b/src/common/outbound.c
index c1270e96..a09fdce4 100644
--- a/src/common/outbound.c
+++ b/src/common/outbound.c
@@ -30,9 +30,9 @@
 
 #ifndef WIN32
 #include <sys/wait.h>
+#include <unistd.h>
 #endif
 
-#include <unistd.h>
 #include <time.h>
 #include <signal.h>
 #include <sys/stat.h>
@@ -2881,6 +2881,23 @@ cmd_recv (struct session *sess, char *tbuf, char *word[], char *word_eol[])
 	return FALSE;
 }
 
+#if 0 /* manual command for flushing prefs to disk, but we use an autosave-upon-set approach instead */
+static int
+cmd_saveconf (struct session *sess, char *tbuf, char *word[], char *word_eol[])
+{
+	if (save_config ())
+	{
+		PrintText (sess, "Settings have been saved successfully.\n");
+	}
+	else
+	{
+		PrintText (sess, "Error saving settings.\n");
+	}
+
+	return TRUE;
+}
+#endif
+
 static int
 cmd_say (struct session *sess, char *tbuf, char *word[], char *word_eol[])
 {
@@ -3633,6 +3650,9 @@ const struct commands xc_cmds[] = {
 #endif
 	{"RECV", cmd_recv, 1, 0, 1, N_("RECV <text>, send raw data to xchat, as if it was received from the irc server")},
 
+#if 0
+	{"SAVECONF", cmd_saveconf, 0, 0, 1, N_("SAVECONF, saves the current settings to disk")},
+#endif
 	{"SAY", cmd_say, 0, 0, 1,
 	 N_("SAY <text>, sends the text to the object in the current window")},
 	{"SEND", cmd_send, 0, 0, 1, N_("SEND <nick> [<file>]")},
diff --git a/src/common/plugin.c b/src/common/plugin.c
index ada4d3be..5ed20b87 100644
--- a/src/common/plugin.c
+++ b/src/common/plugin.c
@@ -20,6 +20,14 @@
 #include <string.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+
+#ifdef WIN32
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
 
 #include "xchat.h"
 #include "fe.h"
@@ -262,6 +270,10 @@ plugin_add (session *sess, char *filename, void *handle, void *init_func,
 		pl->xchat_send_modes = xchat_send_modes;
 		pl->xchat_strip = xchat_strip;
 		pl->xchat_free = xchat_free;
+		pl->xchat_set_pluginpref_str = xchat_set_pluginpref_str;
+		pl->xchat_get_pluginpref_str = xchat_get_pluginpref_str;
+		pl->xchat_set_pluginpref_int = xchat_set_pluginpref_int;
+		pl->xchat_get_pluginpref_int = xchat_get_pluginpref_int;
 
 		/* incase new plugins are loaded on older xchat */
 		pl->xchat_dummy4 = xchat_dummy;
@@ -996,13 +1008,20 @@ xchat_get_info (xchat_plugin *ph, const char *id)
 		return XCHATLIBDIR;
 
 	case 0x14f51cd8: /* version */
+#ifdef WIN32
+		return XCHAT_RELEASE;
+#else
 		return PACKAGE_VERSION;
+#endif
 
 	case 0xdd9b1abd:	/* xchatdir */
 		return get_xdir_utf8 ();
 
 	case 0xe33f6c4a:	/* xchatdirfs */
 		return get_xdir_fs ();
+
+	case 0x3d1e70d7:	/* wdk_version */
+		return PACKAGE_VERSION;
 	}
 
 	sess = ph->context;
@@ -1567,3 +1586,175 @@ xchat_free (xchat_plugin *ph, void *ptr)
 {
 	g_free (ptr);
 }
+
+int
+xchat_set_pluginpref_str (xchat_plugin *pl, const char *var, const char *value)
+{
+	FILE *fpIn;
+	int fhOut;
+	int prevConfig;
+	char confname[64];
+	char confname_tmp[69];
+	char buffer[512];		/* the same as in cfg_put_str */
+	char buffer_tmp[512];
+	char *canon;
+
+	canon = g_strdup (pl->name);
+	canonalize_key (canon);
+	sprintf (confname, "plugin_%s.conf", canon);
+	g_free (canon);
+	sprintf (confname_tmp, "%s.new", confname);
+
+	fhOut = xchat_open_file (confname_tmp, O_TRUNC | O_WRONLY | O_CREAT, 0600, XOF_DOMODE);
+	fpIn = xchat_fopen_file (confname, "r", 0);
+
+	if (fhOut == -1)		/* unable to save, abort */
+	{
+		return 0;
+	}
+	else if (fpIn == NULL)	/* no previous config, no parsing */
+	{
+		sprintf (buffer, "%s = %s\n", var, value);
+		write (fhOut, buffer, strlen (buffer));
+		close (fhOut);
+
+		sprintf (buffer, "%s/%s", get_xdir_fs (), confname);
+		sprintf (buffer_tmp, "%s/%s", get_xdir_fs (), confname_tmp);
+
+#ifdef WIN32
+		unlink (buffer);
+#endif
+
+		if (rename (buffer_tmp, buffer) == 0)
+		{
+			return 1;
+		}
+		else
+		{
+			return 0;
+		}
+	}
+	else					/* existing config, preserve settings and find & replace current var value if any */
+	{
+		prevConfig = 0;
+
+		while (fscanf (fpIn, " %[^\n]", &buffer) != EOF)	/* read whole lines including whitespaces */
+		{
+			sprintf (buffer_tmp, "%s ", var);				/* add one space, this way it works against var - var2 checks too */
+
+			if (strncmp (buffer_tmp, buffer, strlen (var) + 1) == 0)	/* given setting already exists */
+			{
+				sprintf (buffer, "%s = %s\n", var, value);
+				prevConfig = 1;
+			}
+			else
+			{
+				strcat (buffer, "\n");
+			}
+
+			write (fhOut, buffer, strlen (buffer));
+		}
+
+		fclose (fpIn);
+
+		if (!prevConfig)	/* var doesn't exist currently, append */
+		{
+			sprintf (buffer, "%s = %s\n", var, value);
+			write (fhOut, buffer, strlen (buffer));
+		}
+
+		close (fhOut);
+
+		sprintf (buffer, "%s/%s", get_xdir_fs (), confname);
+		sprintf (buffer_tmp, "%s/%s", get_xdir_fs (), confname_tmp);
+
+#ifdef WIN32
+		unlink (buffer);
+#endif
+
+		if (rename (buffer_tmp, buffer) == 0)
+		{
+			return 1;
+		}
+		else
+		{
+			return 0;
+		}
+	}
+}
+
+int
+xchat_get_pluginpref_str (xchat_plugin *pl, const char *var, char *dest)
+{
+	int fh;
+	int l;
+	char confname[64];
+	char *canon;
+	char *cfg;
+	struct stat st;
+
+	canon = g_strdup (pl->name);
+	canonalize_key (canon);
+	sprintf (confname, "plugin_%s.conf", canon);
+	g_free (canon);
+
+	/* partly borrowed from palette.c */
+	fh = xchat_open_file (confname, O_RDONLY, 0, 0);
+
+	if (fh == -1)
+	{
+		return 0;
+	}
+
+	fstat (fh, &st);
+	cfg = malloc (st.st_size + 1);
+
+	if (!cfg)
+	{
+		close (fh);
+		return 0;
+	}
+
+	cfg[0] = '\0';
+	l = read (fh, cfg, st.st_size);
+
+	if (l >= 0)
+	{
+		cfg[l] = '\0';
+	}
+
+	if (!cfg_get_str (cfg, var, dest, 512)) /* dest_len is the same as buffer size in set */
+	{
+		free (cfg);
+		close (fh);
+		return 0;
+	}
+
+	free (cfg);
+	close (fh);
+	return 1;
+}
+
+int
+xchat_set_pluginpref_int (xchat_plugin *pl, const char *var, int value)
+{
+	char buffer[12];
+
+	sprintf (buffer, "%d", value);
+	return xchat_set_pluginpref_str (pl, var, buffer);
+}
+
+int
+xchat_get_pluginpref_int (xchat_plugin *pl, const char *var)
+{
+	char buffer[12];
+
+	if (xchat_get_pluginpref_str (pl, var, buffer))
+	{
+		return atoi (buffer);
+	}
+	else
+	{
+		return -1;
+	}
+}
diff --git a/src/common/plugin.h b/src/common/plugin.h
index b0c89d1b..cddb86fb 100644
--- a/src/common/plugin.h
+++ b/src/common/plugin.h
@@ -98,6 +98,17 @@ struct _xchat_plugin
 	     int flags);
 	void (*xchat_free) (xchat_plugin *ph,
 	    void *ptr);
+	int (*xchat_set_pluginpref_str) (xchat_plugin *ph,
+		const char *var,
+		const char *value);
+	int (*xchat_get_pluginpref_str) (xchat_plugin *ph,
+		const char *var,
+		char *dest);
+	int (*xchat_set_pluginpref_int) (xchat_plugin *ph,
+		const char *var,
+		int value);
+	int (*xchat_get_pluginpref_int) (xchat_plugin *ph,
+		const char *var);
 	void *(*xchat_dummy4) (xchat_plugin *ph);
 	void *(*xchat_dummy3) (xchat_plugin *ph);
 	void *(*xchat_dummy2) (xchat_plugin *ph);
diff --git a/src/common/proto-irc.c b/src/common/proto-irc.c
index f1df6ccd..91a57abe 100644
--- a/src/common/proto-irc.c
+++ b/src/common/proto-irc.c
@@ -18,13 +18,16 @@
 
 /* IRC RFC1459(+commonly used extensions) protocol implementation */
 
-#include <unistd.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>
 #include <stdarg.h>
 
+#ifndef WIN32
+#include <unistd.h>
+#endif
+
 #include "xchat.h"
 #include "ctcp.h"
 #include "fe.h"
diff --git a/src/common/server.c b/src/common/server.c
index 99894687..cdd67cda 100644
--- a/src/common/server.c
+++ b/src/common/server.c
@@ -26,7 +26,6 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <errno.h>
 #include <fcntl.h>
 
@@ -37,6 +36,7 @@
 #ifndef WIN32
 #include <signal.h>
 #include <sys/wait.h>
+#include <unistd.h>
 #else
 #include <winbase.h>
 #endif
@@ -845,33 +845,6 @@ server_flush_queue (server *serv)
 	fe_set_throttle (serv);
 }
 
-#ifdef WIN32
-
-static int
-waitline2 (GIOChannel *source, char *buf, int bufsize)
-{
-	int i = 0;
-	int len;
-
-	while (1)
-	{
-		if (g_io_channel_read (source, &buf[i], 1, &len) != G_IO_ERROR_NONE)
-			return -1;
-		if (buf[i] == '\n' || bufsize == i + 1)
-		{
-			buf[i] = 0;
-			return i;
-		}
-		i++;
-	}
-}
-
-#else
-
-#define waitline2(source,buf,size) waitline(serv->childread,buf,size,0)
-
-#endif
-
 /* connect() successed */
 
 static void
@@ -1395,12 +1368,7 @@ base64_encode (char *to, char *from, unsigned int len)
 static int
 http_read_line (int print_fd, int sok, char *buf, int len)
 {
-#ifdef WIN32
-	/* make sure waitline() uses recv() or it'll fail on win32 */
-	len = waitline (sok, buf, len, FALSE);
-#else
 	len = waitline (sok, buf, len, TRUE);
-#endif
 	if (len >= 1)
 	{
 		/* print the message out (send it to the parent process) */
@@ -1526,7 +1494,7 @@ server_child (server * serv)
 		if (FALSE)
 			;
 #ifdef USE_LIBPROXY
-		else if (prefs.proxy_type == 5)
+		} else if (prefs.proxy_type == 5)
 		{
 			char **proxy_list;
 			char *url, *proxy;
@@ -1796,7 +1764,11 @@ server_connect (server *serv, char *hostname, int port, int no_login)
 	}
 #endif
 	serv->childpid = pid;
+#ifdef WIN32
+	serv->iotag = fe_input_add (serv->childread, FIA_READ|FIA_FD, server_read_child,
+#else
 	serv->iotag = fe_input_add (serv->childread, FIA_READ, server_read_child,
+#endif
 										 serv);
 }
 
diff --git a/src/common/servlist.c b/src/common/servlist.c
index 66bc8115..c9d4b6a8 100644
--- a/src/common/servlist.c
+++ b/src/common/servlist.c
@@ -21,7 +21,10 @@
 #include <string.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+
+#ifndef WIN32
 #include <unistd.h>
+#endif
 
 #include "xchat.h"
 #include <glib.h>
diff --git a/src/common/ssl.c b/src/common/ssl.c
index a18ad47c..daa7416b 100644
--- a/src/common/ssl.c
+++ b/src/common/ssl.c
@@ -17,12 +17,12 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#include "inet.h"				  /* make it first to avoid macro redefinitions */
 #include <openssl/ssl.h>		  /* SSL_() */
 #include <openssl/err.h>		  /* ERR_() */
 #include <time.h>					  /* asctime() */
 #include <string.h>				  /* strncpy() */
 #include "ssl.h"					  /* struct cert_info */
-#include "inet.h"
 #include "../../config.h"		  /* HAVE_SNPRINTF */
 
 #ifndef HAVE_SNPRINTF
diff --git a/src/common/text.c b/src/common/text.c
index 6b111742..9aa1bc85 100644
--- a/src/common/text.c
+++ b/src/common/text.c
@@ -19,13 +19,16 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include <unistd.h>
 #include <ctype.h>
 #include <time.h>
 #include <sys/types.h>
 #include <fcntl.h>
 #include <sys/stat.h>
+
+#ifndef WIN32
+#include <unistd.h>
 #include <sys/mman.h>
+#endif
 
 #include "xchat.h"
 #include <glib.h>
@@ -271,9 +274,12 @@ scrollback_load (session *sess)
 	char *text;
 	time_t stamp;
 	int lines;
+
+#ifndef WIN32
 	char *map, *end_map;
 	struct stat statbuf;
 	const char *begin, *eol;
+#endif
 
 	if (sess->text_scrollback == SET_DEFAULT)
 	{
@@ -293,6 +299,7 @@ scrollback_load (session *sess)
 	if (fh == -1)
 		return;
 
+#ifndef WIN32
 	if (fstat (fh, &statbuf) < 0)
 		return;
 
@@ -301,7 +308,7 @@ scrollback_load (session *sess)
 		return;
 
 	end_map = map + statbuf.st_size;
-	
+
 	lines = 0;
 	begin = map;
 	while (begin < end_map)
@@ -314,11 +321,11 @@ scrollback_load (session *sess)
 			eol = end_map;
 
 		n_bytes = MIN (eol - begin, sizeof (buf) - 1);
-		
+
 		strncpy (buf, begin, n_bytes);
 
 		buf[n_bytes] = 0;
-		
+
 		if (buf[0] == 'T')
 		{
 			if (sizeof (time_t) == 4)
@@ -350,6 +357,39 @@ scrollback_load (session *sess)
 	}
 
 	munmap (map, statbuf.st_size);
+#else
+	lines = 0;
+	while (waitline (fh, buf, sizeof buf, FALSE) != -1)
+	{
+		if (buf[0] == 'T')
+		{
+			if (sizeof (time_t) == 4)
+				stamp = strtoul (buf + 2, NULL, 10);
+			else
+				stamp = strtoull (buf + 2, NULL, 10); /* just incase time_t is 64 bits */
+			text = strchr (buf + 3, ' ');
+			if (text)
+			{
+				text = strip_color (text + 1, -1, STRIP_COLOR);
+				fe_print_text (sess, text, stamp);
+				g_free (text);
+			}
+			lines++;
+		}
+	}
+
+	sess->scrollwritten = lines;
+
+	if (lines)
+	{
+		text = ctime (&stamp);
+		text[24] = 0;	/* get rid of the \n */
+		snprintf (buf, sizeof (buf), "\n*\t%s %s\n\n", _("Loaded log from"), text);
+		fe_print_text (sess, buf, 0);
+		/*EMIT_SIGNAL (XP_TE_GENMSG, sess, "*", buf, NULL, NULL, NULL, 0);*/
+	}
+#endif
+
 	close (fh);
 }
 
diff --git a/src/common/thread.c b/src/common/thread.c
new file mode 100644
index 00000000..02b17cfb
--- /dev/null
+++ b/src/common/thread.c
@@ -0,0 +1,33 @@
+#include <fcntl.h>
+#include "thread.h"
+
+thread *
+thread_new (void)
+{
+	thread *th;
+
+	th = calloc (1, sizeof (*th));
+	if (!th)
+	{
+		return NULL;
+	}
+
+	if (_pipe (th->pipe_fd, 4096, _O_BINARY) == -1)
+	{
+		free (th);
+		return NULL;
+	}
+
+	return th;
+}
+
+int
+thread_start (thread *th, void *(*start_routine)(void *), void *arg)
+{
+	DWORD id;
+
+	CloseHandle (CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE)start_routine, arg, 0, (DWORD *)&id));
+	th->threadid = id;
+
+	return 1;
+}
diff --git a/src/common/thread.h b/src/common/thread.h
new file mode 100644
index 00000000..7ca0f937
--- /dev/null
+++ b/src/common/thread.h
@@ -0,0 +1,10 @@
+#include <windows.h>
+
+typedef struct
+{
+	DWORD threadid;
+	int pipe_fd[2];
+} thread;
+
+thread *thread_new (void);
+int thread_start (thread *th, void *(*start_routine)(void *), void *arg);
diff --git a/src/common/util.c b/src/common/util.c
index 5a0ab6c5..9d9c2cff 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -16,26 +16,32 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#define WANTSOCKET
+#include "inet.h"				/* make it first to avoid macro redefinitions */
+
 #define __APPLE_API_STRICT_CONFORMANCE
 
 #define _FILE_OFFSET_BITS 64
 #include <stdio.h>
-#include <unistd.h>
 #include <string.h>
 #include <stdlib.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+
 #ifdef WIN32
 #include <sys/timeb.h>
 #include <process.h>
+#include <io.h>
+#include "dirent-win32.h"
 #else
-#include <sys/types.h>
+#include <unistd.h>
 #include <pwd.h>
 #include <sys/time.h>
 #include <sys/utsname.h>
+#include <dirent.h>
 #endif
+
 #include <fcntl.h>
-#include <dirent.h>
 #include <errno.h>
 #include "xchat.h"
 #include "xchatc.h"
@@ -44,9 +50,6 @@
 #include "util.h"
 #include "../../config.h"
 
-#define WANTSOCKET
-#include "inet.h"
-
 #if defined (USING_FREEBSD) || defined (__APPLE__)
 #include <sys/sysctl.h>
 #endif
@@ -54,9 +57,11 @@
 #include <socks.h>
 #endif
 
+#ifndef ENABLE_NLS
 #ifndef HAVE_SNPRINTF
 #define snprintf g_snprintf
 #endif
+#endif
 
 #ifdef USE_DEBUG
 
@@ -383,6 +388,28 @@ waitline (int sok, char *buf, int bufsize, int use_recv)
 	}
 }
 
+#ifdef WIN32
+/* waitline2 using win32 file descriptor and glib instead of _read. win32 can't _read() sok! */
+int
+waitline2 (GIOChannel *source, char *buf, int bufsize)
+{
+	int i = 0;
+	int len;
+
+	while (1)
+	{
+		if (g_io_channel_read (source, &buf[i], 1, &len) != G_IO_ERROR_NONE)
+			return -1;
+		if (buf[i] == '\n' || bufsize == i + 1)
+		{
+			buf[i] = 0;
+			return i;
+		}
+		i++;
+	}
+}
+#endif
+
 /* checks for "~" in a file and expands */
 
 char *
@@ -624,30 +651,110 @@ get_mhz (void)
 	return 0;	/* fails on Win9x */
 }
 
+int
+get_cpu_arch (void)
+{
+	SYSTEM_INFO si;
+
+	GetSystemInfo (&si);
+
+	if (si.wProcessorArchitecture == 9)
+	{
+		return 64;
+	}
+	else
+	{
+		return 86;
+	}
+}
+
 char *
 get_cpu_str (void)
 {
 	static char verbuf[64];
-	OSVERSIONINFO osvi;
-	SYSTEM_INFO si;
+	static char winver[20];
+	OSVERSIONINFOEX osvi;
 	double mhz;
 
-	osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
+	osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
 	GetVersionEx (&osvi);
-	GetSystemInfo (&si);
+
+	switch (osvi.dwMajorVersion)
+	{
+		case 5:
+			switch (osvi.dwMinorVersion)
+			{
+				case 1:
+					strcpy (winver, "XP");
+					break;
+				case 2:
+					if (osvi.wProductType == VER_NT_WORKSTATION)
+					{
+						strcpy (winver, "XP x64 Edition");
+					}
+					else
+					{
+						if (GetSystemMetrics(SM_SERVERR2) == 0)
+						{
+							strcpy (winver, "Server 2003");
+						}
+						else
+						{
+							strcpy (winver, "Server 2003 R2");
+						}
+					}
+					break;
+			}
+			break;
+		case 6:
+			switch (osvi.dwMinorVersion)
+			{
+				case 0:
+					if (osvi.wProductType == VER_NT_WORKSTATION)
+					{
+						strcpy (winver, "Vista");
+					}
+					else
+					{
+						strcpy (winver, "Server 2008");
+					}
+					break;
+				case 1:
+					if (osvi.wProductType == VER_NT_WORKSTATION)
+					{
+						strcpy (winver, "7");
+					}
+					else
+					{
+						strcpy (winver, "Server 2008 R2");
+					}
+					break;
+				case 2:
+					if (osvi.wProductType == VER_NT_WORKSTATION)
+					{
+						strcpy (winver, "8");
+					}
+					else
+					{
+						strcpy (winver, "8 Server");
+					}
+					break;
+			}
+			break;
+	}
 
 	mhz = get_mhz ();
 	if (mhz)
 	{
 		double cpuspeed = ( mhz > 1000 ) ? mhz / 1000 : mhz;
 		const char *cpuspeedstr = ( mhz > 1000 ) ? "GHz" : "MHz";
-		sprintf (verbuf, "Windows %ld.%ld [i%d86/%.2f%s]",
-					osvi.dwMajorVersion, osvi.dwMinorVersion, si.wProcessorLevel, 
-					cpuspeed, cpuspeedstr);
-	} else
-		sprintf (verbuf, "Windows %ld.%ld [i%d86]",
-			osvi.dwMajorVersion, osvi.dwMinorVersion, si.wProcessorLevel);
-
+		sprintf (verbuf, "Windows %s [%.2f%s]",	winver, cpuspeed, cpuspeedstr);
+	}
+	else
+	{
+		sprintf (verbuf, "Windows %s", winver);
+	}
+	
 	return verbuf;
 }
 
@@ -1727,3 +1834,55 @@ safe_strcpy (char *dest, const char *src, int bytes_left)
 		}
 	}
 }
+
+void
+canonalize_key (char *key)
+{
+	char *pos, token;
+
+	for (pos = key; (token = *pos) != 0; pos++)
+	{
+		if (token != '_' && (token < '0' || token > '9') && (token < 'A' || token > 'Z') && (token < 'a' || token > 'z'))
+		{
+			*pos = '_';
+		}
+		else
+		{
+			*pos = tolower(token);
+		}
+	}
+}
+
+int
+portable_mode ()
+{
+#ifdef WIN32
+	if ((_access( "portable-mode", 0 )) != -1)
+	{
+		return 1;
+	}
+	else
+	{
+		return 0;
+	}
+#else
+	return 0;
+#endif
+}
+
+int
+xtray_mode ()
+{
+#ifdef WIN32
+	if ((_access( "plugins/xtray.dll", 0 )) != -1)
+	{
+		return 1;
+	}
+	else
+	{
+		return 0;
+	}
+#else
+	return 0;
+#endif
+}
diff --git a/src/common/util.h b/src/common/util.h
index fce45def..82d74366 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -43,6 +43,12 @@ int strip_color2 (const char *src, int len, char *dst, int flags);
 int strip_hidden_attribute (char *src, char *dst);
 char *errorstring (int err);
 int waitline (int sok, char *buf, int bufsize, int);
+#ifdef WIN32
+int waitline2 (GIOChannel *source, char *buf, int bufsize);
+int get_cpu_arch (void);
+#else
+#define waitline2(source,buf,size) waitline(serv->childread,buf,size,0)
+#endif
 unsigned long make_ping_time (void);
 void move_file_utf8 (char *src_dir, char *dst_dir, char *fname, int dccpermissions);
 int mkdir_utf8 (char *dir);
@@ -50,5 +56,8 @@ int token_foreach (char *str, char sep, int (*callback) (char *str, void *ud), v
 guint32 str_hash (const char *key);
 guint32 str_ihash (const unsigned char *key);
 void safe_strcpy (char *dest, const char *src, int bytes_left);
+void canonalize_key (char *key);
+int portable_mode ();
+int xtray_mode ();
 
 #endif
diff --git a/src/common/xchat-plugin.h b/src/common/xchat-plugin.h
index 30b19295..15799424 100644
--- a/src/common/xchat-plugin.h
+++ b/src/common/xchat-plugin.h
@@ -137,6 +137,17 @@ struct _xchat_plugin
 	     int flags);
 	void (*xchat_free) (xchat_plugin *ph,
 	    void *ptr);
+	int (*xchat_set_pluginpref_str) (xchat_plugin *ph,
+		const char *var,
+		const char *value);
+	int (*xchat_get_pluginpref_str) (xchat_plugin *ph,
+		const char *var,
+		char *dest);
+	int (*xchat_set_pluginpref_int) (xchat_plugin *ph,
+		const char *var,
+		int value);
+	int (*xchat_get_pluginpref_int) (xchat_plugin *ph,
+		const char *var);
 };
 #endif
 
@@ -292,6 +303,24 @@ void
 xchat_free (xchat_plugin *ph,
 	    void *ptr);
 
+int
+xchat_set_pluginpref_str (xchat_plugin *ph,
+		const char *var,
+		const char *value);
+
+int
+xchat_get_pluginpref_str (xchat_plugin *ph,
+		const char *var,
+		char *dest);
+
+int
+xchat_set_pluginpref_int (xchat_plugin *ph,
+		const char *var,
+		int value);
+int
+xchat_get_pluginpref_int (xchat_plugin *ph,
+		const char *var);
+
 #if !defined(PLUGIN_C) && defined(WIN32)
 #ifndef XCHAT_PLUGIN_HANDLE
 #define XCHAT_PLUGIN_HANDLE (ph)
@@ -326,6 +355,10 @@ xchat_free (xchat_plugin *ph,
 #define xchat_send_modes ((XCHAT_PLUGIN_HANDLE)->xchat_send_modes)
 #define xchat_strip ((XCHAT_PLUGIN_HANDLE)->xchat_strip)
 #define xchat_free ((XCHAT_PLUGIN_HANDLE)->xchat_free)
+#define xchat_set_pluginpref_str ((XCHAT_PLUGIN_HANDLE)->xchat_set_pluginpref_str)
+#define xchat_get_pluginpref_str ((XCHAT_PLUGIN_HANDLE)->xchat_get_pluginpref_str)
+#define xchat_set_pluginpref_int ((XCHAT_PLUGIN_HANDLE)->xchat_set_pluginpref_int)
+#define xchat_get_pluginpref_int ((XCHAT_PLUGIN_HANDLE)->xchat_get_pluginpref_int)
 #endif
 
 #ifdef __cplusplus
diff --git a/src/common/xchat.c b/src/common/xchat.c
index afac9a0e..22c4eddb 100644
--- a/src/common/xchat.c
+++ b/src/common/xchat.c
@@ -22,14 +22,16 @@
 #include <time.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <unistd.h>
 
 #define WANTSOCKET
 #include "inet.h"
 
-#ifndef WIN32
+#ifdef WIN32
+#include <windows.h>
+#else
 #include <sys/wait.h>
 #include <signal.h>
+#include <unistd.h>
 #endif
 
 #include "xchat.h"
@@ -590,6 +592,7 @@ static char defaultconf_commands[] =
 	"NAME DMSG\n"			"CMD msg =%2 &3\n\n"\
 	"NAME EXIT\n"			"CMD quit\n\n"\
 	"NAME GREP\n"			"CMD lastlog -r &2\n\n"\
+	"NAME IGNALL\n"			"CMD ignore %2!*@* ALL\n\n"\
 	"NAME J\n"				"CMD join &2\n\n"\
 	"NAME KILL\n"			"CMD quote KILL %2 :&3\n\n"\
 	"NAME LEAVE\n"			"CMD part &2\n\n"\
@@ -903,7 +906,11 @@ int
 main (int argc, char *argv[])
 {
 	int ret;
-	
+
+#ifdef WIN32
+	HANDLE mutex;
+#endif
+
 	srand (time (0));	/* CL: do this only once! */
 
 #ifdef SOCKS
@@ -920,6 +927,21 @@ main (int argc, char *argv[])
 
 	load_config ();
 
+#ifdef WIN32
+	if (prefs.gui_one_instance && !portable_mode ())
+	{
+		DWORD error;
+
+		mutex = CreateMutex (NULL, TRUE, "Local\xchat");
+		error = GetLastError ();
+
+		if (error == ERROR_ALREADY_EXISTS || mutex == NULL)
+		{
+			return 1;
+		}
+	}
+#endif
+
 #ifdef USE_LIBPROXY
 	libproxy_factory = px_proxy_factory_new();
 #endif
@@ -945,6 +967,11 @@ main (int argc, char *argv[])
 
 #ifdef WIN32
 	WSACleanup ();
+
+	if (prefs.gui_one_instance && !portable_mode ())
+	{
+		CloseHandle (mutex);
+	}
 #endif
 
 	return 0;
diff --git a/src/common/xchat.h b/src/common/xchat.h
index 10f1067e..6815cc39 100644
--- a/src/common/xchat.h
+++ b/src/common/xchat.h
@@ -8,12 +8,14 @@
 
 #include "history.h"
 
+#ifndef ENABLE_NLS
 #ifndef HAVE_SNPRINTF
 #define snprintf g_snprintf
 #endif
 
 #ifndef HAVE_VSNPRINTF
-#define vsnprintf g_vsnprintf
+#define vsnprintf _vsnprintf
+#endif
 #endif
 
 #ifdef USE_DEBUG
@@ -54,7 +56,7 @@ void *xchat_realloc (char *old, int len, char *file, int line);
 
 #ifdef WIN32						/* for win32 */
 #define OFLAGS O_BINARY
-#define sleep(t) _sleep(t*1000)
+#define sleep(t) Sleep(t*1000)
 #include <direct.h>
 #define	F_OK	0
 #define	X_OK	1
@@ -115,6 +117,8 @@ struct xchatprefs
 	char partreason[256];
 	char font_normal[FONTNAMELEN + 1];
 	char doubleclickuser[256];
+	char gui_license[64];
+	char spell_langs[64];
 	char sounddir[PATHLEN + 1];
 	char soundcmd[PATHLEN + 1];
 	char background[PATHLEN + 1];
@@ -178,6 +182,9 @@ struct xchatprefs
 	int gui_usermenu;
 	int gui_join_dialog;
 	int gui_quit_dialog;
+#ifdef WIN32
+	int gui_one_instance;
+#endif
 	int dialog_left;
 	int dialog_top;
 	int dialog_width;
@@ -205,6 +212,9 @@ struct xchatprefs
 	unsigned int wallops;
 	unsigned int skipmotd;
 	unsigned int autorejoin;
+	unsigned int autocopy_text;
+	unsigned int autocopy_stamp;
+	unsigned int autocopy_color;
 	unsigned int colorednicks;
 	unsigned int chanmodebuttons;
 	unsigned int userlistbuttons;
@@ -292,7 +302,12 @@ struct xchatprefs
 	unsigned int wait_on_exit;
 	unsigned int confmode;
 	unsigned int utf8_locale;
+#ifdef WIN32
 	unsigned int identd;
+	unsigned int emoticons;
+	unsigned int tab_icons;
+	unsigned int tab_xp;
+#endif
 
 	unsigned int ctcp_number_limit;	/*flood */
 	unsigned int ctcp_time_limit;	/*seconds of floods */
diff --git a/src/fe-gtk/Makefile.am b/src/fe-gtk/Makefile.am
index 7db38096..da36ed57 100644
--- a/src/fe-gtk/Makefile.am
+++ b/src/fe-gtk/Makefile.am
@@ -10,8 +10,8 @@ EXTRA_DIST = \
 	about.h ascii.h banlist.h chanlist.h chanview.h chanview-tabs.c \
 	chanview-tree.c custom-list.h editlist.h fe-gtk.h fkeys.h gtkutil.h joind.h \
 	maingui.h menu.h mmx_cmod.S mmx_cmod.h notifygui.h palette.h pixmaps.h \
-	plugin-tray.h plugingui.c plugingui.h rawlog.h search.h sexy-spell-entry.h \
-   textgui.h urlgrab.h userlistgui.h xtext.h
+	plugin-tray.h plugingui.c plugingui.h rawlog.h search.h sexy-iso-codes.h \
+	sexy-spell-entry.h sexy-marshal.h textgui.h urlgrab.h userlistgui.h xtext.h
 
 if USE_MMX
 mmx_cmod_S = mmx_cmod.S
@@ -22,11 +22,12 @@ plugingui_c = plugingui.c
 endif
 
 if USE_LIBSEXY
-sexy_spell_entry_c = sexy-spell-entry.c
+sexy_spell = \
+	sexy-iso-codes.c sexy-marshal.c sexy-spell-entry.c
 endif
 
 xchat_SOURCES = about.c ascii.c banlist.c chanlist.c chanview.c custom-list.c \
 	dccgui.c editlist.c fe-gtk.c fkeys.c gtkutil.c ignoregui.c joind.c menu.c \
 	maingui.c $(mmx_cmod_S) notifygui.c palette.c pixmaps.c plugin-tray.c $(plugingui_c) \
-	rawlog.c search.c servlistgui.c setup.c $(sexy_spell_entry_c) textgui.c \
+	rawlog.c search.c servlistgui.c setup.c $(sexy_spell) textgui.c \
 	urlgrab.c userlistgui.c xtext.c
diff --git a/src/fe-gtk/about.c b/src/fe-gtk/about.c
index 60700aec..dc1cbf08 100644
--- a/src/fe-gtk/about.c
+++ b/src/fe-gtk/about.c
@@ -39,6 +39,7 @@
 
 #include "../common/xchat.h"
 #include "../common/util.h"
+#include "../common/xchatc.h"
 #include "palette.h"
 #include "pixmaps.h"
 #include "gtkutil.h"
@@ -69,7 +70,7 @@ menu_about (GtkWidget * wid, gpointer sess)
 							"(C) 1998-2005 Peter Zelezny", author, buf, 0));
 }
 
-#else
+#endif
 
 static GtkWidget *about = 0;
 
@@ -95,7 +96,7 @@ menu_about (GtkWidget * wid, gpointer sess)
 	}
 
 	about = gtk_dialog_new ();
-	gtk_window_set_position (GTK_WINDOW (about), GTK_WIN_POS_CENTER);
+	gtk_window_set_position (GTK_WINDOW (about), GTK_WIN_POS_CENTER_ON_PARENT);
 	gtk_window_set_resizable (GTK_WINDOW (about), FALSE);
 	gtk_window_set_title (GTK_WINDOW (about), _("About "DISPLAY_NAME));
 	if (parent_window)
@@ -113,36 +114,47 @@ menu_about (GtkWidget * wid, gpointer sess)
 	gtk_container_add (GTK_CONTAINER (vbox), label);
 	g_get_charset (&locale);
 	(snprintf) (buf, sizeof (buf),
-				"<span size=\"x-large\"><b>"DISPLAY_NAME" "PACKAGE_VERSION"</b></span>\n\n"
-				"%s\n\n"
+				"<span size=\"x-large\"><b>"DISPLAY_NAME" "PACKAGE_VERSION"</b></span>\n"
 #ifdef WIN32
-				/* leave this message to avoid time wasting bug reports! */
-				"This version is unofficial and comes with no support.\n\n"
-#endif
-				"%s\n"
+				"%s%s%s"
+				"\n<b>XChat Release</b>: "XCHAT_RELEASE"\n\n"
+				"<b>OS</b>: %s\n"
 				"<b>Charset</b>: %s "
-#ifdef WIN32 
 				"<b>GTK+</b>: %i.%i.%i\n"
+				"<b>Compiled</b>: "__DATE__"\n"
+				"<b>Portable Mode</b>: %s\n"
+				"<b>Build Type</b>: x%d\n\n"
+				"<small>This version is unofficial and comes with no support.\n"
+				"\302\251 1998-2010 Peter \305\275elezn\303\275 &lt;zed@xchat.org>"
+				/* "\n<a href=\"http://code.google.com/p/xchat-wdk/\">http://code.google.com/p/xchat-wdk/</a>" this is broken in gtk ATM */
+				"</small>",
+				(strcmp (prefs.gui_license, "") ? "<span size=\"x-large\">" : ""),
+				(strcmp (prefs.gui_license, "") ? prefs.gui_license : ""),
+				(strcmp (prefs.gui_license, "") ? "</span>\n" : ""),
+				get_cpu_str (),
+				locale,
+				gtk_major_version,
+				gtk_minor_version,
+				gtk_micro_version,
+				(portable_mode () ? "Yes" : "No"),
+				get_cpu_arch ()
 #else
+				"\n%s\n\n"
+				"%s\n"
+				"<b>Charset</b>: %s "
 				"<b>Renderer</b>: %s\n"
-#endif
 				"<b>Compiled</b>: "__DATE__"\n\n"
 				"<small>\302\251 1998-2010 Peter \305\275elezn\303\275 &lt;zed@xchat.org></small>",
-					_("A multiplatform IRC Client"),
-					get_cpu_str(),
-					locale,
-#ifdef WIN32
-					gtk_major_version,
-					gtk_minor_version,
-					gtk_micro_version
-#else
+				_("A multiplatform IRC Client"),
+				get_cpu_str (),
+				locale,
 #ifdef USE_XFT
-					"Xft"
+				"Xft"
 #else
-					"Pango"
+				"Pango"
 #endif
 #endif
-					);
+				);
 	gtk_label_set_markup (GTK_LABEL (label), buf);
 	gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
 
@@ -158,4 +170,3 @@ menu_about (GtkWidget * wid, gpointer sess)
 
 	gtk_widget_show_all (about);
 }
-#endif
diff --git a/src/fe-gtk/banlist.c b/src/fe-gtk/banlist.c
index afaa7eb4..fecb62a5 100644
--- a/src/fe-gtk/banlist.c
+++ b/src/fe-gtk/banlist.c
@@ -19,10 +19,13 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <fcntl.h>
 #include <time.h>
 
+#ifndef WIN32
+#include <unistd.h>
+#endif
+
 #include "fe-gtk.h"
 
 #include <gtk/gtkhbox.h>
@@ -134,11 +137,8 @@ banlist_do_refresh (struct session *sess)
 		gtk_list_store_clear (store);
 
 		handle_command (sess, "ban", FALSE);
-#ifdef WIN32
-		if (0)
-#else
+
 		if (supports_exempt (sess->server))
-#endif
 		{
 			snprintf (tbuf, sizeof (tbuf), "quote mode %s +e", sess->channel);
 			handle_command (sess, tbuf, FALSE);
diff --git a/src/fe-gtk/chanlist.c b/src/fe-gtk/chanlist.c
index 2f65b518..4dca935b 100644
--- a/src/fe-gtk/chanlist.c
+++ b/src/fe-gtk/chanlist.c
@@ -19,10 +19,13 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <fcntl.h>
 #include <time.h>
 
+#ifndef WIN32
+#include <unistd.h>
+#endif
+
 #include "fe-gtk.h"
 
 #include <gtk/gtkalignment.h>
diff --git a/src/fe-gtk/chanview-tabs.c b/src/fe-gtk/chanview-tabs.c
index 8e3da8e6..f99e61f1 100644
--- a/src/fe-gtk/chanview-tabs.c
+++ b/src/fe-gtk/chanview-tabs.c
@@ -144,8 +144,8 @@ tab_scroll_left_up_clicked (GtkWidget *widget, chanview *cv)
 		for (i = adj->value; ((i > new_value) && (tab_left_is_moving)); i -= 0.1)
 		{
 			gtk_adjustment_set_value (adj, i);
-			while (g_main_pending ())
-				g_main_iteration (TRUE);
+			while (g_main_context_pending (NULL))
+				g_main_context_iteration (NULL, TRUE);
 		}
 
 		gtk_adjustment_set_value (adj, new_value);
@@ -191,8 +191,8 @@ tab_scroll_right_down_clicked (GtkWidget *widget, chanview *cv)
 		for (i = adj->value; ((i < new_value) && (tab_right_is_moving)); i += 0.1)
 		{
 			gtk_adjustment_set_value (adj, i);
-			while (g_main_pending ())
-				g_main_iteration (TRUE);
+			while (g_main_context_pending (NULL))
+				g_main_context_iteration (NULL, TRUE);
 		}
 
 		gtk_adjustment_set_value (adj, new_value);
diff --git a/src/fe-gtk/editlist.c b/src/fe-gtk/editlist.c
index 5af67e32..d374d064 100644
--- a/src/fe-gtk/editlist.c
+++ b/src/fe-gtk/editlist.c
@@ -19,10 +19,14 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+
+#ifndef WIN32
+#include <unistd.h>
+#endif
+
 #include "fe-gtk.h"
 
 #include <gtk/gtkstock.h>
diff --git a/src/fe-gtk/fe-gtk.c b/src/fe-gtk/fe-gtk.c
index 5efcaeec..88a1138c 100644
--- a/src/fe-gtk/fe-gtk.c
+++ b/src/fe-gtk/fe-gtk.c
@@ -19,7 +19,6 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
-#include <unistd.h>
 
 #include "fe-gtk.h"
 
@@ -32,6 +31,12 @@
 #include <gtk/gtkmessagedialog.h>
 #include <gtk/gtkversion.h>
 
+#ifdef WIN32
+#include <gdk/gdkwin32.h>
+#else
+#include <unistd.h>
+#endif
+
 #include "../common/xchat.h"
 #include "../common/fe.h"
 #include "../common/util.h"
@@ -39,6 +44,7 @@
 #include "../common/cfgfiles.h"
 #include "../common/xchatc.h"
 #include "../common/plugin.h"
+#include "../common/server.h"
 #include "gtkutil.h"
 #include "maingui.h"
 #include "pixmaps.h"
@@ -136,11 +142,26 @@ static const GOptionEntry gopt_entries[] =
  {NULL}
 };
 
+#ifdef WIN32
+static void
+create_msg_dialog (gchar *title, gchar *message)
+{
+	GtkWidget *dialog;
+	dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, message);
+	gtk_window_set_title (GTK_WINDOW (dialog), title);
+	gtk_dialog_run (GTK_DIALOG (dialog));
+	gtk_widget_destroy (dialog);
+}
+#endif
+
 int
 fe_args (int argc, char *argv[])
 {
 	GError *error = NULL;
 	GOptionContext *context;
+#ifdef WIN32
+	char *buffer[2048];
+#endif
 
 #ifdef ENABLE_NLS
 	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
@@ -149,22 +170,67 @@ fe_args (int argc, char *argv[])
 #endif
 
 	context = g_option_context_new (NULL);
+#ifdef WIN32
+	g_option_context_set_help_enabled (context, FALSE);	/* disable stdout help as stdout is unavailable for subsystem:windows */
+#endif
 	g_option_context_add_main_entries (context, gopt_entries, GETTEXT_PACKAGE);
 	g_option_context_add_group (context, gtk_get_option_group (FALSE));
 	g_option_context_parse (context, &argc, &argv, &error);
 
+#ifdef WIN32
+	if (error)											/* workaround for argv not being available when using subsystem:windows */
+	{
+		if (error->message)								/* the error message contains argv so search for patterns in that */
+		{
+			if (strstr (error->message, "--help-all") != NULL)
+			{
+				if (snprintf (buffer, 2048, g_option_context_get_help (context, FALSE, NULL)))
+				{
+					gtk_init (&argc, &argv);
+					create_msg_dialog ("Long Help", buffer);
+				}
+				return 0;
+			} else if (strstr (error->message, "--help") != NULL || strstr (error->message, "-?") != NULL)
+			{
+				if (snprintf (buffer, 2048, g_option_context_get_help (context, TRUE, NULL)))
+				{
+					gtk_init (&argc, &argv);
+					create_msg_dialog ("Help", buffer);
+				}
+				return 0;
+			} else 
+			{
+				if (snprintf (buffer, 2048, "%s\n", error->message))
+				{
+					gtk_init (&argc, &argv);
+					create_msg_dialog ("Error", buffer);
+				}
+				return 1;
+			}
+		}
+	}
+#else
 	if (error)
 	{
 		if (error->message)
 			printf ("%s\n", error->message);
 		return 1;
 	}
+#endif
 
 	g_option_context_free (context);
 
 	if (arg_show_version)
 	{
+#ifdef WIN32
+		if (snprintf (buffer, 2048, DISPLAY_NAME" "PACKAGE_VERSION"\n"))
+		{
+			gtk_init (&argc, &argv);
+			create_msg_dialog ("Version Information", buffer);
+		}
+#else
 		printf (PACKAGE_TARNAME" "PACKAGE_VERSION"\n");
+#endif
 		return 0;
 	}
 
@@ -177,7 +243,18 @@ fe_args (int argc, char *argv[])
 		if (sl)
 		{
 			*sl = 0;
-			printf ("%s\\plugins\n", exe);
+			if (snprintf (buffer, 2048, "%s\\plugins\n", exe))
+			{
+				gtk_init (&argc, &argv);
+				create_msg_dialog ("Plugin Auto-load Directory", buffer);
+			}
+		} else
+		{
+			if (snprintf (buffer, 2048, ".\\plugins\n"))
+			{
+				gtk_init (&argc, &argv);
+				create_msg_dialog ("Plugin Auto-load Directory", buffer);
+			}
 		}
 #else
 		printf ("%s\n", XCHATLIBDIR"/plugins");
@@ -187,7 +264,15 @@ fe_args (int argc, char *argv[])
 
 	if (arg_show_config)
 	{
+#ifdef WIN32
+		if (snprintf (buffer, 2048, "%s\n", get_xdir_fs ()))
+		{
+			gtk_init (&argc, &argv);
+			create_msg_dialog ("User Config Directory", buffer);
+		}
+#else
 		printf ("%s\n", get_xdir_fs ());
+#endif
 		return 0;
 	}
 
@@ -330,7 +415,7 @@ log_handler (const gchar   *log_domain,
 {
 	session *sess;
 
-	if (getenv ("XCHAT_WARNING_IGNORE"))
+	/* if (getenv ("XCHAT_WARNING_IGNORE")) this gets ignored sometimes, so simply just disable all warnings */
 		return;
 
 	sess = find_dialog (serv_list->data, "(warnings)");
@@ -845,7 +930,11 @@ fe_gui_info_ptr (session *sess, int info_type)
 	{
 	case 0:	/* native window pointer (for plugins) */
 #ifdef WIN32
+#if GTK_CHECK_VERSION(2,24,8)
+		return gdk_win32_window_get_impl_hwnd (sess->gui->window->window);
+#else
 		return GDK_WINDOW_HWND (sess->gui->window->window);
+#endif
 #else
 		return sess->gui->window;
 #endif
diff --git a/src/fe-gtk/fe-gtk.h b/src/fe-gtk/fe-gtk.h
index 12516259..8fffb3cc 100644
--- a/src/fe-gtk/fe-gtk.h
+++ b/src/fe-gtk/fe-gtk.h
@@ -1,13 +1,6 @@
 #include "../../config.h"
 
-#ifdef WIN32
-/* If you're compiling this for Windows, your release is un-official
- * and not condoned. Please don't use the XChat name. Make up your
- * own name! */
-#define DISPLAY_NAME "XChat-Unofficial"
-#else
-#define DISPLAY_NAME "XChat"
-#endif
+#define DISPLAY_NAME "XChat-WDK"
 
 #ifndef WIN32
 #include <sys/types.h>
diff --git a/src/fe-gtk/fkeys.c b/src/fe-gtk/fkeys.c
index 014b5cc3..b9690731 100644
--- a/src/fe-gtk/fkeys.c
+++ b/src/fe-gtk/fkeys.c
@@ -20,11 +20,14 @@
 #include <stdlib.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <unistd.h>
 #include <string.h>
 #include <fcntl.h>
 #include <ctype.h>
 
+#ifndef WIN32
+#include <unistd.h>
+#endif
+
 #include "fe-gtk.h"
 
 #include <gtk/gtklabel.h>
@@ -315,7 +318,7 @@ key_handle_key_press (GtkWidget *wid, GdkEventKey *evt, session *sess)
 		key_action_tab_clean ();
 		break;
 
-#if defined(USE_GTKSPELL) && !defined(WIN32)
+#if defined(USE_GTKSPELL)/* && !defined(WIN32) */
 	/* gtktextview has no 'activate' event, so we trap ENTER here */
 	case GDK_Return:
 	case GDK_KP_Enter:
diff --git a/src/fe-gtk/gtkutil.c b/src/fe-gtk/gtkutil.c
index 63ab491b..fe4e1737 100644
--- a/src/fe-gtk/gtkutil.c
+++ b/src/fe-gtk/gtkutil.c
@@ -22,8 +22,8 @@
 #include <stdarg.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <unistd.h>
 #include <fcntl.h>
+
 #include "fe-gtk.h"
 
 #include <gtk/gtkbutton.h>
@@ -52,6 +52,13 @@
 #include "gtkutil.h"
 #include "pixmaps.h"
 
+#ifdef WIN32
+#include "../common/fe.h"
+#include "../common/thread.h"
+#else
+#include <unistd.h>
+#endif
+
 /* gtkutil.c, just some gtk wrappers */
 
 extern void path_part (char *file, char *path, int pathlen);
@@ -63,6 +70,13 @@ struct file_req
 	void *userdata;
 	filereqcallback callback;
 	int flags;		/* FRF_* flags */
+
+#ifdef WIN32
+	int multiple;
+	thread *th;
+	char *title;	/* native locale */
+	char *filter;
+#endif
 };
 
 static char last_dir[256] = "";
@@ -164,6 +178,190 @@ gtkutil_file_req_response (GtkWidget *dialog, gint res, struct file_req *freq)
 	}
 }
 
+#ifdef WIN32
+static int
+win32_openfile (char *file_buf, int file_buf_len, char *title_text, char *filter,
+			   int multiple)
+{
+	OPENFILENAME o;
+
+	memset (&o, 0, sizeof (o));
+
+	o.lStructSize = sizeof (o);
+	o.lpstrFilter = filter;
+	o.lpstrFile = file_buf;
+	o.nMaxFile = file_buf_len;
+	o.lpstrTitle = title_text;
+	o.Flags = 0x02000000 | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY |
+				OFN_NOCHANGEDIR | OFN_EXPLORER | OFN_LONGNAMES | OFN_NONETWORKBUTTON;
+	if (multiple)
+	{
+		o.Flags |= OFN_ALLOWMULTISELECT;
+	}
+
+	return GetOpenFileName (&o);
+}
+
+static int
+win32_savefile (char *file_buf, int file_buf_len, char *title_text, char *filter,
+               int multiple)
+{
+	/* we need the filter to get the default filename. it is from fe-gtk.c (fe_confirm);
+	 * but that filter is actually the whole filename, so apply an empty filter and all good.
+	 * in win32_thread2 we copy the filter ( = the filename) after the last dir into our
+	 * LPTSTR file buffer to make it actually work. the docs for this amazingly retard api:
+	 *
+	 * http://msdn.microsoft.com/en-us/library/ms646839%28VS.85%29.aspx
+	 */
+
+	OPENFILENAME o;
+
+	memset (&o, 0, sizeof (o));
+
+	o.lStructSize = sizeof (o);
+	o.lpstrFilter = "All files\0*.*\0\0";
+	o.lpstrFile = file_buf;
+	o.nMaxFile = file_buf_len;
+	o.lpstrTitle = title_text;
+	o.Flags = 0x02000000 | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY |
+				OFN_NOCHANGEDIR | OFN_EXPLORER | OFN_LONGNAMES | OFN_NONETWORKBUTTON;
+	if (multiple)
+	{
+		o.Flags |= OFN_ALLOWMULTISELECT;
+	}
+
+	return GetSaveFileName (&o);
+}
+
+static void *
+win32_thread (struct file_req *freq)
+{
+	char buf[1024 + 32];
+	char file[1024];
+
+	memset (file, 0, sizeof (file));
+	safe_strcpy (file, last_dir, sizeof (file));
+
+	if (win32_openfile (file, sizeof (file), freq->title, freq->filter, freq->multiple))
+	{
+		if (freq->multiple)
+		{
+			char *f = file;
+
+			if (f[strlen (f) + 1] == 0)	/* only selected one file */
+			{
+				snprintf (buf, sizeof (buf), "1\n%s\n", file);
+				write (freq->th->pipe_fd[1], buf, strlen (buf));
+			} else
+			{
+				f += strlen (f) + 1; /* skip first, it's only the dir */
+				while (f[0])
+				{
+					snprintf (buf, sizeof (buf), "1\n%s\\%s\n", /*dir!*/file, f);
+					write (freq->th->pipe_fd[1], buf, strlen (buf));
+					f += strlen (f) + 1;
+				}
+			}
+
+		} else
+		{
+			snprintf (buf, sizeof (buf), "1\n%s\n", file);
+			write (freq->th->pipe_fd[1], buf, strlen (buf));
+		}
+	}
+
+	write (freq->th->pipe_fd[1], "0\n", 2);
+	Sleep (2000);
+
+	return NULL;
+}
+
+static void *
+win32_thread2 (struct file_req *freq)
+{
+	char buf[1024 + 32];
+	char file[1024];
+
+	memset (file, 0, sizeof (file));
+	safe_strcpy (file, last_dir, sizeof (file));
+	safe_strcpy (file, freq->filter, sizeof (file));
+
+	if (win32_savefile (file, sizeof (file), freq->title, NULL, freq->multiple))
+	{
+		if (freq->multiple)
+		{
+			char *f = file;
+
+			if (f[strlen (f) + 1] == 0)    /* only selected one file */
+			{
+				snprintf (buf, sizeof (buf), "1\n%s\n", file);
+				write (freq->th->pipe_fd[1], buf, strlen (buf));
+			} else
+			{
+				f += strlen (f) + 1; /* skip first, it's only the dir */
+				while (f[0])
+				{
+					snprintf (buf, sizeof (buf), "1\n%s\\%s\n", /*dir!*/file, f);
+					write (freq->th->pipe_fd[1], buf, strlen (buf));
+					f += strlen (f) + 1;
+				}
+			}
+
+		} else
+		{
+			snprintf (buf, sizeof (buf), "1\n%s\n", file);
+			write (freq->th->pipe_fd[1], buf, strlen (buf));
+		}
+	}
+
+	write (freq->th->pipe_fd[1], "0\n", 2);
+	Sleep (2000);
+
+	return NULL;
+}
+
+static gboolean
+win32_close_pipe (int fd)
+{
+	close (fd);
+	return 0;
+}
+
+static gboolean
+win32_read_thread (GIOChannel *source, GIOCondition cond, struct file_req *freq)
+{
+	char buf[512];
+	char *file;
+
+	waitline2 (source, buf, sizeof buf);
+
+	switch (buf[0])
+	{
+	case '0':	/* filedialog has closed */
+		freq->callback (freq->userdata, NULL);
+		break;
+
+	case '1':	/* got a filename! */
+		waitline2 (source, buf, sizeof buf);
+		file = g_filename_to_utf8 (buf, -1, 0, 0, 0);
+		freq->callback (freq->userdata, file);
+		g_free (file);
+		return TRUE;
+	}
+
+	/* it doesn't work to close them here, because of the weird
+		way giowin32 works. We must _return_ before closing them */
+	g_timeout_add(3000, (GSourceFunc)win32_close_pipe, freq->th->pipe_fd[0]);
+	g_timeout_add(2000, (GSourceFunc)win32_close_pipe, freq->th->pipe_fd[1]);
+
+	g_free (freq->title);
+	free (freq->th);
+	free (freq);
+
+	return FALSE;
+}
+#endif
+
 void
 gtkutil_file_req (const char *title, void *callback, void *userdata, char *filter,
 						int flags)
@@ -172,6 +370,58 @@ gtkutil_file_req (const char *title, void *callback, void *userdata, char *filte
 	GtkWidget *dialog;
 	extern char *get_xdir_fs (void);
 
+#ifdef WIN32
+	if (!(flags & FRF_WRITE))
+	{
+		freq = malloc (sizeof (struct file_req));
+		freq->th = thread_new ();
+		freq->flags = 0;
+		freq->multiple = (flags & FRF_MULTIPLE);
+		freq->callback = callback;
+		freq->userdata = userdata;
+		freq->title = g_locale_from_utf8 (title, -1, 0, 0, 0);
+		if (!filter)
+		{
+			freq->filter =	"All files\0*.*\0"
+							"Executables\0*.exe\0"
+							"ZIP files\0*.zip\0\0";
+		}
+		else
+		{
+			freq->filter = filter;
+		}
+
+		thread_start (freq->th, win32_thread, freq);
+		fe_input_add (freq->th->pipe_fd[0], FIA_FD|FIA_READ, win32_read_thread, freq);
+
+		return;
+
+	}
+	
+	else {
+		freq = malloc (sizeof (struct file_req));
+		freq->th = thread_new ();
+		freq->flags = 0;
+		freq->multiple = (flags & FRF_MULTIPLE);
+		freq->callback = callback;
+		freq->userdata = userdata;
+		freq->title = g_locale_from_utf8 (title, -1, 0, 0, 0);
+		if (!filter)
+		{
+			freq->filter = "All files\0*.*\0\0";
+		}
+		else
+		{
+			freq->filter = filter;
+		}
+
+		thread_start (freq->th, win32_thread2, freq);
+		fe_input_add (freq->th->pipe_fd[0], FIA_FD|FIA_READ, win32_read_thread, freq);
+
+	return;
+	}
+#endif
+
 	if (flags & FRF_WRITE)
 	{
 		dialog = gtk_file_chooser_dialog_new (title, NULL,
diff --git a/src/fe-gtk/joind.c b/src/fe-gtk/joind.c
index ee5c56d1..e645f0bc 100644
--- a/src/fe-gtk/joind.c
+++ b/src/fe-gtk/joind.c
@@ -9,10 +9,13 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <unistd.h>
 #include <string.h>
 #include <stdio.h>
 
+#ifndef WIN32
+#include <unistd.h>
+#endif
+
 #include <gtk/gtkbbox.h>
 #include <gtk/gtkbutton.h>
 #include <gtk/gtkdialog.h>
diff --git a/src/fe-gtk/maingui.c b/src/fe-gtk/maingui.c
index ef269f95..28cf46a9 100644
--- a/src/fe-gtk/maingui.c
+++ b/src/fe-gtk/maingui.c
@@ -53,6 +53,8 @@
 #include "../common/plugin.h"
 #include "../common/modes.h"
 #include "../common/url.h"
+#include "../common/util.h"
+
 #include "fe-gtk.h"
 #include "banlist.h"
 #include "gtkutil.h"
@@ -214,60 +216,10 @@ mg_create_tab_colors (void)
 	away_list = mg_attr_list_create (&colors[COL_AWAY], FALSE);
 }
 
-#ifdef WIN32
-#define WINVER 0x0501	/* needed for vc6? */
-#include <windows.h>
-#include <gdk/gdkwin32.h>
-
-/* Flash the taskbar button on Windows when there's a highlight event. */
-
-static void
-flash_window (GtkWidget *win)
-{
-	FLASHWINFO fi;
-	static HMODULE user = NULL;
-	static BOOL (*flash) (PFLASHWINFO) = NULL;
-
-	if (!user)
-	{
-		user = GetModuleHandleA ("USER32");
-		if (!user)
-			return;	/* this should never fail */
-	}
-
-	if (!flash)
-	{
-		flash = (void *)GetProcAddress (user, "FlashWindowEx");
-		if (!flash)
-			return;	/* this fails on NT4.0 and Win95 */
-	}
-
-	fi.cbSize = sizeof (fi);
-	fi.hwnd = GDK_WINDOW_HWND (win->window);
-	fi.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG;
-	fi.uCount = 0;
-	fi.dwTimeout = 500;
-	flash (&fi);
-	/*FlashWindowEx (&fi);*/
-}
-#else
-
-#ifdef USE_XLIB
-#include <gdk/gdkx.h>
-
 static void
 set_window_urgency (GtkWidget *win, gboolean set)
 {
-	XWMHints *hints;
-
-	hints = XGetWMHints(GDK_WINDOW_XDISPLAY(win->window), GDK_WINDOW_XWINDOW(win->window));
-	if (set)
-		hints->flags |= XUrgencyHint;
-	else
-		hints->flags &= ~XUrgencyHint;
-	XSetWMHints(GDK_WINDOW_XDISPLAY(win->window),
-	            GDK_WINDOW_XWINDOW(win->window), hints);
-	XFree(hints);
+	gtk_window_set_urgency_hint (GTK_WINDOW (win), set);
 }
 
 static void
@@ -281,18 +233,14 @@ unflash_window (GtkWidget *win)
 {
 	set_window_urgency (win, FALSE);
 }
-#endif
-#endif
 
 /* flash the taskbar button */
 
 void
 fe_flash_window (session *sess)
 {
-#if defined(WIN32) || defined(USE_XLIB)
 	if (fe_gui_info (sess, 0) != 1)	/* only do it if not focused */
 		flash_window (sess->gui->window);
-#endif
 }
 
 /* set a tab plain, red, light-red, or blue */
@@ -529,10 +477,22 @@ fe_set_title (session *sess)
 		break;
 	default:
 	def:
-		gtk_window_set_title (GTK_WINDOW (sess->gui->window), DISPLAY_NAME);
+		snprintf (tbuf, sizeof (tbuf), DISPLAY_NAME);
+		if (strcmp (prefs.gui_license, ""))		/* zero means gui_license is empty */
+		{
+			strcat (tbuf, " - ");
+			strcat (tbuf, prefs.gui_license);
+		}
+		gtk_window_set_title (GTK_WINDOW (sess->gui->window), tbuf);
 		return;
 	}
 
+	if (strcmp (prefs.gui_license, ""))			/* zero means gui_license is empty */
+	{
+		strcat (tbuf, " - ");
+		strcat (tbuf, prefs.gui_license);
+	}
+
 	gtk_window_set_title (GTK_WINDOW (sess->gui->window), tbuf);
 }
 
@@ -1334,7 +1294,7 @@ mg_open_quit_dialog (gboolean minimize_button)
 	gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1),
 										GTK_BUTTONBOX_END);
 
-	if (minimize_button)
+	if (minimize_button && !xtray_mode ())
 	{
 		button = gtk_button_new_with_mnemonic (_("_Minimize to Tray"));
 		gtk_widget_show (button);
@@ -1632,7 +1592,12 @@ mg_create_alertmenu (session *sess, GtkWidget *menu)
 	submenu = menu_quick_sub (_("_Extra Alerts"), menu, NULL, XCMENU_MNEMONIC, -1);
 
 	mg_perchan_menu_item (_("Beep on _Message"), submenu, &sess->alert_beep, prefs.input_beep_chans);
-	mg_perchan_menu_item (_("Blink Tray _Icon"), submenu, &sess->alert_tray, prefs.input_tray_chans);
+
+	if (!xtray_mode ())		/*disable this context menu item when xtray is loaded */
+	{
+		mg_perchan_menu_item (_("Blink Tray _Icon"), submenu, &sess->alert_tray, prefs.input_tray_chans);
+	}
+
 	mg_perchan_menu_item (_("Blink Task _Bar"), submenu, &sess->alert_taskbar, prefs.input_flash_chans);
 }
 
@@ -2972,11 +2937,7 @@ mg_tabwin_focus_cb (GtkWindow * win, GdkEventFocus *event, gpointer userdata)
 		gtk_xtext_check_marker_visibility (GTK_XTEXT (current_sess->gui->xtext));
 		plugin_emit_dummy_print (current_sess, "Focus Window");
 	}
-#ifndef WIN32
-#ifdef USE_XLIB
 	unflash_window (GTK_WIDGET (win));
-#endif
-#endif
 	return FALSE;
 }
 
@@ -2987,11 +2948,7 @@ mg_topwin_focus_cb (GtkWindow * win, GdkEventFocus *event, session *sess)
 	if (!sess->server->server_session)
 		sess->server->server_session = sess;
 	gtk_xtext_check_marker_visibility(GTK_XTEXT (current_sess->gui->xtext));
-#ifndef WIN32
-#ifdef USE_XLIB
 	unflash_window (GTK_WIDGET (win));
-#endif
-#endif
 	plugin_emit_dummy_print (sess, "Focus Window");
 	return FALSE;
 }
diff --git a/src/fe-gtk/makefile.mak b/src/fe-gtk/makefile.mak
new file mode 100644
index 00000000..27922405
--- /dev/null
+++ b/src/fe-gtk/makefile.mak
@@ -0,0 +1,62 @@
+include "..\makeinc.mak"
+
+FEGTK_OBJECTS = \
+about.obj \
+ascii.obj \
+banlist.obj \
+chanlist.obj \
+chanview.obj \
+custom-list.obj \
+dccgui.obj \
+editlist.obj \
+fe-gtk.obj \
+fkeys.obj \
+gtkutil.obj \
+ignoregui.obj \
+joind.obj \
+maingui.obj \
+menu.obj \
+notifygui.obj \
+palette.obj \
+pixmaps.obj \
+plugingui.obj \
+plugin-tray.obj \
+rawlog.obj \
+search.obj \
+servlistgui.obj \
+setup.obj \
+sexy-iso-codes.obj \
+sexy-marshal.obj \
+sexy-spell-entry.obj \
+textgui.obj \
+urlgrab.obj \
+userlistgui.obj \
+xtext.obj
+
+!ifdef X64
+MACHINE_FLAG = /MACHINE:X64
+!else
+MACHINE_FLAG = /MACHINE:X86
+!endif
+
+COMLIB = ..\common\xchatcommon.lib
+PROG = xchat.exe
+
+all: $(PROG)
+
+.c.obj::
+	$(CC) $(CFLAGS) -I..\..\plugins $(GLIB) $(GTK) $<
+
+$(PROG): $(FEGTK_OBJECTS) $(COMLIB) xchat-icon.obj
+	$(LINK) /out:$(PROG) /entry:mainCRTStartup $(LDFLAGS) $(LIBS) $(FEGTK_OBJECTS) $(COMLIB) xchat-icon.obj
+
+xchat.res: xchat.rc ../../xchat.ico
+	rc /nologo /r xchat.rc
+
+xchat-icon.obj: xchat.res
+	cvtres /nologo $(MACHINE_FLAG) /OUT:xchat-icon.obj xchat.res
+
+clean:
+	@del *.obj
+	@del $(PROG)
+	@del xchat.res
diff --git a/src/fe-gtk/menu.c b/src/fe-gtk/menu.c
index d04be222..e6a5eca0 100644
--- a/src/fe-gtk/menu.c
+++ b/src/fe-gtk/menu.c
@@ -20,10 +20,11 @@
 #include <stdlib.h>
 #include <fcntl.h>
 #include <string.h>
-#include <unistd.h>
 
 #ifdef WIN32
 #include <windows.h>
+#else
+#include <unistd.h>
 #endif
 
 #include "fe-gtk.h"
@@ -1122,6 +1123,23 @@ usermenu_update (void)
 	}
 }
 
+#if 0
+static void
+menu_saveconf (void)
+{
+	session *sess = current_sess;
+
+	if (save_config ())
+	{
+		PrintText (sess, "Settings have been saved successfully.\n");
+	}
+	else
+	{
+		PrintText (sess, "Error saving settings.\n");
+	}
+}
+#endif
+
 static void
 menu_newserver_window (GtkWidget * wid, gpointer none)
 {
@@ -1204,6 +1222,12 @@ menu_resetmarker (GtkWidget * wid, gpointer none)
 }
 
 static void
+menu_copy_selection (GtkWidget * wid, gpointer none)
+{
+	gtk_xtext_copy_selection (GTK_XTEXT (current_sess->gui->xtext));
+}
+
+static void
 menu_flushbuffer (GtkWidget * wid, gpointer none)
 {
 	fe_text_clear (current_sess, 0);
@@ -1580,7 +1604,7 @@ static struct mymenu mymenu[] = {
 #endif
 	{0, 0, 0, M_SEP, 0, 0, 0},	/* 11 */
 #define DETACH_OFFSET (12)
-	{0, menu_detach, GTK_STOCK_REDO, M_MENUSTOCK, 0, 0, 1, GDK_I},	/* 12 */
+	{0, menu_detach, GTK_STOCK_REDO, M_MENUSTOCK, 0, 0, 1, GDK_i},	/* 12 */
 #define CLOSE_OFFSET (13)
 	{0, menu_close, GTK_STOCK_CLOSE, M_MENUSTOCK, 0, 0, 1, GDK_w},
 	{0, 0, 0, M_SEP, 0, 0, 0},
@@ -1633,6 +1657,10 @@ static struct mymenu mymenu[] = {
 		{N_("Userlist Popup..."), menu_ulpopup, 0, M_MENUITEM, 0, 0, 1},
 		{0, 0, 0, M_END, 0, 0, 0},		/* 53 */
 
+#if 0
+	{N_("Save Settings to Disk"), menu_saveconf, GTK_STOCK_SAVE, M_MENUSTOCK, 0, 0, 1}, /* don't use this, a /set auto-save approach will be added instead */
+#endif
+
 	{N_("_Window"), 0, 0, M_NEWMENU, 0, 0, 1},
 	{N_("Ban List..."), menu_banlist, 0, M_MENUITEM, 0, 0, 1},
 	{N_("Character Chart..."), ascii_open, 0, M_MENUITEM, 0, 0, 1},
@@ -1645,12 +1673,13 @@ static struct mymenu mymenu[] = {
 	{N_("URL Grabber..."), url_opengui, 0, M_MENUITEM, 0, 0, 1},
 	{0, 0, 0, M_SEP, 0, 0, 0},
 	{N_("Reset Marker Line"), menu_resetmarker, 0, M_MENUITEM, 0, 0, 1, GDK_m},
+	{N_("_Copy Selection"), menu_copy_selection, 0, M_MENUITEM, 0, 0, 1, GDK_C},
 	{N_("C_lear Text"), menu_flushbuffer, GTK_STOCK_CLEAR, M_MENUSTOCK, 0, 0, 1, GDK_l},
-#define SEARCH_OFFSET 67
+#define SEARCH_OFFSET 68
 	{N_("Search Text..."), menu_search, GTK_STOCK_FIND, M_MENUSTOCK, 0, 0, 1, GDK_f},
 	{N_("Save Text..."), menu_savebuffer, GTK_STOCK_SAVE, M_MENUSTOCK, 0, 0, 1},
 
-	{N_("_Help"), 0, 0, M_NEWMENU, 0, 0, 1},	/* 69 */
+	{N_("_Help"), 0, 0, M_NEWMENU, 0, 0, 1},	/* 70 */
 	{N_("_Contents"), menu_docs, GTK_STOCK_HELP, M_MENUSTOCK, 0, 0, 1, GDK_F1},
 #if 0
 	{N_("Check for updates"), menu_update, 0, M_MENUITEM, 0, 1},
@@ -2188,7 +2217,9 @@ normalitem:
 										mymenu[i].key,
 										mymenu[i].key == GDK_F1 ? 0 :
 										mymenu[i].key == GDK_w ? close_mask :
-										GDK_CONTROL_MASK,
+										(g_ascii_isupper (mymenu[i].key)) ?
+											GDK_SHIFT_MASK | GDK_CONTROL_MASK :
+											GDK_CONTROL_MASK,
 										GTK_ACCEL_VISIBLE);
 			if (mymenu[i].callback)
 				g_signal_connect (G_OBJECT (item), "activate",
diff --git a/src/fe-gtk/palette.c b/src/fe-gtk/palette.c
index ebae92ff..104700c2 100644
--- a/src/fe-gtk/palette.c
+++ b/src/fe-gtk/palette.c
@@ -18,11 +18,14 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 
+#ifndef WIN32
+#include <unistd.h>
+#endif
+
 #include "fe-gtk.h"
 #include "palette.h"
 
@@ -78,8 +81,9 @@ GdkColor colors[] = {
 	{0, 0x0000, 0x0000, 0xffff}, /* 38 tab Nick Mentioned (blue) */
 	{0, 0xffff, 0x0000, 0x0000}, /* 39 tab New Message (red) */
 	{0, 0x9595, 0x9595, 0x9595}, /* 40 away user (grey) */
+	{0, 0xffff, 0x0000, 0x0000}, /* 41 spell checker color (red) */
 };
-#define MAX_COL 40
+#define MAX_COL 41
 
 
 void
diff --git a/src/fe-gtk/palette.h b/src/fe-gtk/palette.h
index c97693bb..627c6963 100644
--- a/src/fe-gtk/palette.h
+++ b/src/fe-gtk/palette.h
@@ -9,6 +9,7 @@ extern GdkColor colors[];
 #define COL_HILIGHT 38
 #define COL_NEW_MSG 39
 #define COL_AWAY 40
+#define COL_SPELL 41
 
 void palette_alloc (GtkWidget * widget);
 void palette_load (void);
diff --git a/src/fe-gtk/plugin-tray.c b/src/fe-gtk/plugin-tray.c
index e46d9570..b9f60f8d 100644
--- a/src/fe-gtk/plugin-tray.c
+++ b/src/fe-gtk/plugin-tray.c
@@ -1,7 +1,6 @@
 /* Copyright (C) 2006-2007 Peter Zelezny. */
 
 #include <string.h>
-#include <unistd.h>
 #include "../common/xchat-plugin.h"
 #include "../common/xchat.h"
 #include "../common/xchatc.h"
@@ -15,6 +14,10 @@
 #include "menu.h"
 #include <gtk/gtk.h>
 
+#ifndef WIN32
+#include <unistd.h>
+#endif
+
 #ifdef USE_LIBNOTIFY
 #include <libnotify/notify.h>
 #ifndef NOTIFY_CHECK_VERSION
@@ -217,10 +220,10 @@ tray_stop_flash (void)
 		nets = tray_count_networks ();
 		chans = tray_count_channels ();
 		if (nets)
-			tray_set_tipf (_("XChat: Connected to %u networks and %u channels"),
+			tray_set_tipf (_("XChat-WDK: Connected to %u networks and %u channels"),
 								nets, chans);
 		else
-			tray_set_tipf ("XChat: %s", _("Not connected."));
+			tray_set_tipf ("XChat-WDK: %s", _("Not connected."));
 	}
 
 	if (custom_icon1)
@@ -370,7 +373,7 @@ tray_toggle_visibility (gboolean force_hide)
 	/* ph may have an invalid context now */
 	xchat_set_context (ph, xchat_find_context (ph, NULL, NULL));
 
-	win = (GtkWindow *)xchat_get_info (ph, "win_ptr");
+	win = xchat_get_info (ph, "gtkwin_ptr");
 
 	tray_stop_flash ();
 	tray_reset_counts ();
@@ -505,11 +508,12 @@ tray_menu_cb (GtkWidget *widget, guint button, guint time, gpointer userdata)
 	/*gtk_menu_set_screen (GTK_MENU (menu), gtk_widget_get_screen (widget));*/
 
 	if (tray_get_window_status () == WS_HIDDEN)
-		tray_make_item (menu, _("_Restore"), tray_menu_restore_cb, NULL);
+		tray_make_item (menu, _("_Restore Window"), tray_menu_restore_cb, NULL);
 	else
-		tray_make_item (menu, _("_Hide"), tray_menu_restore_cb, NULL);
+		tray_make_item (menu, _("_Hide Window"), tray_menu_restore_cb, NULL);
 	tray_make_item (menu, NULL, tray_menu_quit_cb, NULL);
 
+#ifndef WIN32 /* somehow this is broken on win32 */
 	submenu = mg_submenu (menu, _("_Blink on"));
 	blink_item (&prefs.input_tray_chans, submenu, _("Channel Message"));
 	blink_item (&prefs.input_tray_priv, submenu, _("Private Message"));
@@ -526,6 +530,8 @@ tray_menu_cb (GtkWidget *widget, guint button, guint time, gpointer userdata)
 		gtk_widget_set_sensitive (item, FALSE);
 
 	tray_make_item (menu, NULL, tray_menu_quit_cb, NULL);
+#endif
+
 	mg_create_icon_item (_("_Quit"), GTK_STOCK_QUIT, menu, tray_menu_quit_cb, NULL);
 
 	menu_add_plugin_items (menu, "\x5$TRAY", NULL);
@@ -551,8 +557,12 @@ tray_init (void)
 	sticon = gtk_status_icon_new_from_pixbuf (ICON_NORMAL);
 	if (!sticon)
 		return;
+
+#ifndef WIN32
 	g_signal_connect (G_OBJECT (sticon), "popup-menu",
 							G_CALLBACK (tray_menu_cb), sticon);
+#endif
+
 	g_signal_connect (G_OBJECT (sticon), "activate",
 							G_CALLBACK (tray_menu_restore_cb), NULL);
 }
@@ -570,15 +580,15 @@ tray_hilight_cb (char *word[], void *userdata)
 		/* FIXME: hides any previous private messages */
 		tray_hilight_count++;
 		if (tray_hilight_count == 1)
-			tray_set_tipf (_("XChat: Highlighted message from: %s (%s)"),
+			tray_set_tipf (_("XChat-WDK: Highlighted message from: %s (%s)"),
 								word[1], xchat_get_info (ph, "channel"));
 		else
-			tray_set_tipf (_("XChat: %u highlighted messages, latest from: %s (%s)"),
+			tray_set_tipf (_("XChat-WDK: %u highlighted messages, latest from: %s (%s)"),
 								tray_hilight_count, word[1], xchat_get_info (ph, "channel"));
 	}
 
 	if (prefs.input_balloon_hilight)
-		tray_set_balloonf (word[2], _("XChat: Highlighted message from: %s (%s)"),
+		tray_set_balloonf (word[2], _("XChat-WDK: Highlighted message from: %s (%s)"),
 								 word[1], xchat_get_info (ph, "channel"));
 
 	return XCHAT_EAT_NONE;
@@ -596,14 +606,14 @@ tray_message_cb (char *word[], void *userdata)
 
 		tray_pub_count++;
 		if (tray_pub_count == 1)
-			tray_set_tipf (_("XChat: New public message from: %s (%s)"),
+			tray_set_tipf (_("XChat-WDK: New public message from: %s (%s)"),
 								word[1], xchat_get_info (ph, "channel"));
 		else
-			tray_set_tipf (_("XChat: %u new public messages."), tray_pub_count);
+			tray_set_tipf (_("XChat-WDK: %u new public messages."), tray_pub_count);
 	}
 
 	if (prefs.input_balloon_chans)
-		tray_set_balloonf (word[2], _("XChat: New public message from: %s (%s)"),
+		tray_set_balloonf (word[2], _("XChat-WDK: New public message from: %s (%s)"),
 								 word[1], xchat_get_info (ph, "channel"));
 
 	return XCHAT_EAT_NONE;
@@ -625,14 +635,14 @@ tray_priv (char *from, char *text)
 
 	tray_priv_count++;
 	if (tray_priv_count == 1)
-		tray_set_tipf (_("XChat: Private message from: %s (%s)"),
+		tray_set_tipf (_("XChat-WDK: Private message from: %s (%s)"),
 							from, network);
 	else
-		tray_set_tipf (_("XChat: %u private messages, latest from: %s (%s)"),
+		tray_set_tipf (_("XChat-WDK: %u private messages, latest from: %s (%s)"),
 							tray_priv_count, from, network);
 
 	if (prefs.input_balloon_priv)
-		tray_set_balloonf (text, _("XChat: Private message from: %s (%s)"),
+		tray_set_balloonf (text, _("XChat-WDK: Private message from: %s (%s)"),
 								 from, network);
 }
 
@@ -678,15 +688,15 @@ tray_dcc_cb (char *word[], void *userdata)
 
 		tray_file_count++;
 		if (tray_file_count == 1)
-			tray_set_tipf (_("XChat: File offer from: %s (%s)"),
+			tray_set_tipf (_("XChat-WDK: File offer from: %s (%s)"),
 								word[1], network);
 		else
-			tray_set_tipf (_("XChat: %u file offers, latest from: %s (%s)"),
+			tray_set_tipf (_("XChat-WDK: %u file offers, latest from: %s (%s)"),
 								tray_file_count, word[1], network);
 	}
 
 	if (prefs.input_balloon_priv)
-		tray_set_balloonf ("", _("XChat: File offer from: %s (%s)"),
+		tray_set_balloonf ("", _("XChat-WDK: File offer from: %s (%s)"),
 								word[1], network);
 
 	return XCHAT_EAT_NONE;
@@ -722,7 +732,7 @@ tray_apply_setup (void)
 	}
 	else
 	{
-		if (prefs.gui_tray)
+		if (prefs.gui_tray && !xtray_mode ())
 			tray_init ();
 	}
 }
@@ -754,7 +764,7 @@ tray_plugin_init (xchat_plugin *plugin_handle, char **plugin_name,
 
 	xchat_hook_print (ph, "Focus Window", -1, tray_focus_cb, NULL);
 
-	if (prefs.gui_tray)
+	if (prefs.gui_tray && !xtray_mode ())
 		tray_init ();
 
 	return 1;       /* return 1 for success */
diff --git a/src/fe-gtk/plugingui.c b/src/fe-gtk/plugingui.c
index de59e649..71d2f02e 100644
--- a/src/fe-gtk/plugingui.c
+++ b/src/fe-gtk/plugingui.c
@@ -146,8 +146,13 @@ plugingui_load_cb (session *sess, char *file)
 void
 plugingui_load (void)
 {
-	gtkutil_file_req (_("Select a Plugin or Script to load"), plugingui_load_cb,
-							current_sess, NULL, FRF_ADDFOLDER);
+	gtkutil_file_req (_("Select a Plugin or Script to load"), plugingui_load_cb, current_sess,
+#ifdef WIN32
+							"Plugins and Scripts\0*.dll;*.lua;*.pl;*.py;*.tcl\0"
+							"All files\0*.*\0\0", 0);
+#else
+							NULL, FRF_ADDFOLDER);
+#endif
 }
 
 static void
diff --git a/src/fe-gtk/rawlog.c b/src/fe-gtk/rawlog.c
index 56ca0510..593468c1 100644
--- a/src/fe-gtk/rawlog.c
+++ b/src/fe-gtk/rawlog.c
@@ -19,9 +19,12 @@
 #include <stdio.h>
 #include <string.h>
 #include <fcntl.h>
-#include <unistd.h>
 #include <stdlib.h>
 
+#ifndef WIN32
+#include <unistd.h>
+#endif
+
 #include "fe-gtk.h"
 
 #include <gtk/gtkbutton.h>
diff --git a/src/fe-gtk/search.c b/src/fe-gtk/search.c
index d62e79c7..bbde9c5c 100644
--- a/src/fe-gtk/search.c
+++ b/src/fe-gtk/search.c
@@ -153,7 +153,7 @@ search_open (session * sess)
 								_("_Find"));
 	g_object_set_data (G_OBJECT (wid), "e", entry);
 
-	g_signal_connect (G_OBJECT (win), "key-press-event", G_CALLBACK (search_key_cb), win);
+	g_signal_connect (G_OBJECT (win), "key_press_event", G_CALLBACK (search_key_cb), win);
 
 	gtk_widget_show (win);
 }
diff --git a/src/fe-gtk/setup.c b/src/fe-gtk/setup.c
index 517e0944..cce85d30 100644
--- a/src/fe-gtk/setup.c
+++ b/src/fe-gtk/setup.c
@@ -122,6 +122,19 @@ static const setting textbox_settings[] =
 	{ST_ENTRY,  N_("Time stamp format:"), P_OFFSETNL(stamp_format),
 					N_("See strftime manpage for details."),0,sizeof prefs.stamp_format},
 
+	{ST_HEADER,	N_("Auto-Copy Behavior"),0,0,0},
+	{ST_TOGGLE, N_("Automatically copy selected text"), P_OFFINTNL(autocopy_text),
+					N_("Copy selected text to clipboard when left mouse button is released. "
+						"Otherwise, CONTROL-SHIFT-C will copy the "
+						"selected text to the clipboard."), 0, 0},
+	{ST_TOGGLE, N_("Automatically include time stamps"), P_OFFINTNL(autocopy_stamp),
+					N_("Automatically include time stamps in copied lines of text. Otherwise, "
+						"include time stamps if the SHIFT key is held down while selecting."), 0, 0},
+	{ST_TOGGLE, N_("Automatically include color information"), P_OFFINTNL(autocopy_color),
+					N_("Automatically include color information in copied lines of text.  "
+						"Otherwise, include color information if the CONTROL key is held down "
+						"while selecting."), 0, 0},
+
 	{ST_END, 0, 0, 0, 0, 0}
 };
 
@@ -138,6 +151,12 @@ static const setting inputbox_settings[] =
 	{ST_TOGGLE, N_("Use the Text box font and colors"), P_OFFINTNL(style_inputbox),0,0,0},
 #if defined(USE_GTKSPELL) || defined(USE_LIBSEXY)
 	{ST_TOGGLE, N_("Spell checking"), P_OFFINTNL(gui_input_spell),0,0,0},
+	{ST_ENTRY,	N_("Dictionaries to use:"), P_OFFSETNL(spell_langs),0,0,sizeof prefs.spell_langs},
+#ifdef WIN32
+	{ST_LABEL,	N_("Use language codes (as in \"share\\myspell\\dicts\").\nSeparate multiple entries with commas.")},
+#else
+	{ST_LABEL,	N_("Use language codes. Separate multiple entries with commas.")},
+#endif
 #endif
 
 	{ST_HEADER, N_("Nick Completion"),0,0,0},
@@ -348,6 +367,24 @@ static const setting alert_settings[] =
 	{ST_END, 0, 0, 0, 0, 0}
 };
 
+static const setting alert_settings_xtray[] =
+{
+	{ST_HEADER,	N_("Alerts"),0,0,0},
+
+	{ST_ALERTHEAD},
+	{ST_3OGGLE, N_("Blink task bar on:"), 0, 0, (void *)taskbarlist, 0},
+	{ST_3OGGLE, N_("Make a beep sound on:"), 0, 0, (void *)beeplist, 0},
+
+	{ST_HEADER,	N_("Highlighted Messages"),0,0,0},
+	{ST_LABEL,	N_("Highlighted messages are ones where your nickname is mentioned, but also:"), 0, 0, 0, 1},
+
+	{ST_ENTRY,	N_("Extra words to highlight:"), P_OFFSETNL(irc_extra_hilight), 0, 0, sizeof prefs.irc_extra_hilight},
+	{ST_ENTRY,	N_("Nick names not to highlight:"), P_OFFSETNL(irc_no_hilight), 0, 0, sizeof prefs.irc_no_hilight},
+	{ST_ENTRY,	N_("Nick names to always highlight:"), P_OFFSETNL(irc_nick_hilight), 0, 0, sizeof prefs.irc_nick_hilight},
+	{ST_LABEL,	N_("Separate multiple words with commas.\nWildcards are accepted.")},
+	{ST_END, 0, 0, 0, 0, 0}
+};
+
 static const setting general_settings[] =
 {
 	{ST_HEADER,	N_("Default Messages"),0,0,0},
@@ -363,7 +400,6 @@ static const setting general_settings[] =
 	{ST_END, 0, 0, 0, 0, 0}
 };
 
-#if 0
 static const setting advanced_settings[] =
 {
 	{ST_HEADER,	N_("Advanced Settings"),0,0,0},
@@ -371,6 +407,25 @@ static const setting advanced_settings[] =
 	{ST_TOGGLE,	N_("Display MODEs in raw form"), P_OFFINTNL(raw_modes), 0, 0, 0},
 	{ST_TOGGLE,	N_("Whois on notify"), P_OFFINTNL(whois_on_notifyonline), N_("Sends a /WHOIS when a user comes online in your notify list"), 0, 0},
 	{ST_TOGGLE,	N_("Hide join and part messages"), P_OFFINTNL(confmode), N_("Hide channel join/part messages by default"), 0, 0},
+	{ST_ENTRY,	N_("License Text:"), P_OFFSETNL(gui_license), 0, 0, sizeof prefs.gui_license},
+	{ST_HEADER,	N_("Auto Open DCC Windows"),0,0,0},
+	{ST_TOGGLE, N_("Send window"), P_OFFINTNL(autoopendccsendwindow), 0, 0, 0},
+	{ST_TOGGLE, N_("Receive window"), P_OFFINTNL(autoopendccrecvwindow), 0, 0, 0},
+	{ST_TOGGLE, N_("Chat window"), P_OFFINTNL(autoopendccchatwindow), 0, 0, 0},
+
+	{ST_END, 0, 0, 0, 0, 0}
+};
+
+#ifdef WIN32
+static const setting advanced_settings_oneinstance[] =
+{
+	{ST_HEADER,	N_("Advanced Settings"),0,0,0},
+	{ST_NUMBER,	N_("Auto reconnect delay:"), P_OFFINTNL(recon_delay), 0, 0, 9999},
+	{ST_TOGGLE,	N_("Display MODEs in raw form"), P_OFFINTNL(raw_modes), 0, 0, 0},
+	{ST_TOGGLE,	N_("Whois on notify"), P_OFFINTNL(whois_on_notifyonline), N_("Sends a /WHOIS when a user comes online in your notify list"), 0, 0},
+	{ST_TOGGLE,	N_("Hide join and part messages"), P_OFFINTNL(confmode), N_("Hide channel join/part messages by default"), 0, 0},
+	{ST_TOGGLE,	N_("Allow only one instance of XChat to run"), P_OFFINTNL(gui_one_instance), 0, 0, 0},
+	{ST_ENTRY,	N_("License Text:"), P_OFFSETNL(gui_license), 0, 0, sizeof prefs.gui_license},
 	{ST_HEADER,	N_("Auto Open DCC Windows"),0,0,0},
 	{ST_TOGGLE, N_("Send window"), P_OFFINTNL(autoopendccsendwindow), 0, 0, 0},
 	{ST_TOGGLE, N_("Receive window"), P_OFFINTNL(autoopendccrecvwindow), 0, 0, 0},
@@ -1328,6 +1383,9 @@ setup_create_color_page (void)
 	setup_create_other_color (_("New message:"), COL_NEW_MSG, 10, tab);
 	setup_create_other_colorR (_("Away user:"), COL_AWAY, 10, tab);
 	setup_create_other_color (_("Highlight:"), COL_HILIGHT, 11, tab);
+#if defined(USE_GTKSPELL) || defined(USE_LIBSEXY)
+	setup_create_other_colorR (_("Spell checker:"), COL_SPELL, 11, tab);
+#endif
 
 	return box;
 }
@@ -1711,7 +1769,7 @@ static const char *const cata[] =
 		N_("General"),
 		N_("Logging"),
 		N_("Sound"),
-/*		N_("Advanced"),*/
+		N_("Advanced"),
 		NULL,
 	N_("Network"),
 		N_("Network setup"),
@@ -1732,10 +1790,33 @@ setup_create_pages (GtkWidget *box)
 	setup_add_page (cata[3], book, setup_create_page (userlist_settings));
 	setup_add_page (cata[4], book, setup_create_page (tabs_settings));
 	setup_add_page (cata[5], book, setup_create_color_page ());
-	setup_add_page (cata[8], book, setup_create_page (alert_settings));
+
+	if (xtray_mode ())
+	{
+		setup_add_page (cata[8], book, setup_create_page (alert_settings_xtray));
+	}
+	else
+	{
+		setup_add_page (cata[8], book, setup_create_page (alert_settings));
+	}
+
 	setup_add_page (cata[9], book, setup_create_page (general_settings));
 	setup_add_page (cata[10], book, setup_create_page (logging_settings));
 	setup_add_page (cata[11], book, setup_create_sound_page ());
+
+#ifdef WIN32
+	if (portable_mode ())
+	{
+		setup_add_page (cata[12], book, setup_create_page (advanced_settings));
+	}
+	else
+	{
+		setup_add_page (cata[12], book, setup_create_page (advanced_settings_oneinstance));
+	}
+#else
+	setup_add_page (cata[12], book, setup_create_page (advanced_settings));
+#endif
+
 	setup_add_page (cata[14], book, setup_create_page (network_settings));
 	setup_add_page (cata[15], book, setup_create_page (filexfer_settings));
 
diff --git a/src/fe-gtk/sexy-iso-codes.c b/src/fe-gtk/sexy-iso-codes.c
new file mode 100644
index 00000000..4b637c9f
--- /dev/null
+++ b/src/fe-gtk/sexy-iso-codes.c
@@ -0,0 +1,305 @@
+/*
+ *  Copyright (C) 2005 Nathan Fredrickson
+ *  Borrowed from Galeon, renamed, and simplified to only use iso-codes with no
+ *  fallback method.
+ *
+ *  Copyright (C) 2004 Christian Persch
+ *  Copyright (C) 2004 Crispin Flowerday
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA  02111-1307, USA.
+ *
+ */
+
+#include "../../config.h"
+
+#include "sexy-iso-codes.h"
+
+#include <glib/gi18n.h>
+
+#include <string.h>
+
+#include <libxml/xmlreader.h>
+
+static GHashTable *iso_639_table = NULL;
+static GHashTable *iso_3166_table = NULL;
+
+#define ISO_639_DOMAIN	"iso_639"
+#define ISO_3166_DOMAIN	"iso_3166"
+
+#ifdef HAVE_ISO_CODES
+
+#define ISOCODESLOCALEDIR "/share/locale"
+
+static void
+read_iso_639_entry (xmlTextReaderPtr reader,
+		    GHashTable *table)
+{
+	xmlChar *code, *name;
+
+	code = xmlTextReaderGetAttribute (reader, (const xmlChar *) "iso_639_1_code");
+	name = xmlTextReaderGetAttribute (reader, (const xmlChar *) "name");
+
+	/* Get iso-639-2 code */
+	if (code == NULL || code[0] == '\0')
+	{
+		xmlFree (code);
+		/* FIXME: use the 2T or 2B code? */
+		code = xmlTextReaderGetAttribute (reader, (const xmlChar *) "iso_639_2T_code");
+	}
+
+	if (code != NULL && code[0] != '\0' && name != NULL && name[0] != '\0')
+	{
+		g_hash_table_insert (table, code, name);
+	}
+	else
+	{
+		xmlFree (code);
+		xmlFree (name);
+	}
+}
+
+static void
+read_iso_3166_entry (xmlTextReaderPtr reader,
+		     GHashTable *table)
+{
+	xmlChar *code, *name;
+
+	code = xmlTextReaderGetAttribute (reader, (const xmlChar *) "alpha_2_code");
+	name = xmlTextReaderGetAttribute (reader, (const xmlChar *) "name");
+
+	if (code != NULL && code[0] != '\0' && name != NULL && name[0] != '\0')
+	{
+		char *lcode;
+
+		lcode = g_ascii_strdown ((char *) code, -1);
+		xmlFree (code);
+
+		g_hash_table_insert (table, lcode, name);
+	}
+	else
+	{
+		xmlFree (code);
+		xmlFree (name);
+	}
+
+}
+
+typedef enum
+{
+	STATE_START,
+	STATE_STOP,
+	STATE_ENTRIES,
+} ParserState;
+
+static gboolean
+load_iso_entries (int iso,
+		  GFunc read_entry_func,
+		  gpointer user_data)
+{
+	xmlTextReaderPtr reader;
+	ParserState state = STATE_START;
+	xmlChar iso_entries[32], iso_entry[32];
+	char *filename;
+	int ret = -1;
+
+#ifdef WIN32
+	filename = g_strdup_printf (".\\share\\xml\\iso-codes\\iso_%d.xml", iso);
+#else
+	filename = g_strdup_printf ("/usr/share/xml/iso-codes/iso_%d.xml", iso);
+#endif
+	reader = xmlNewTextReaderFilename (filename);
+	if (reader == NULL) goto out;
+
+	xmlStrPrintf (iso_entries, sizeof (iso_entries),
+				  (xmlChar *)"iso_%d_entries", iso);
+	xmlStrPrintf (iso_entry, sizeof (iso_entry),
+				  (xmlChar *)"iso_%d_entry", iso);
+
+	ret = xmlTextReaderRead (reader);
+
+	while (ret == 1)
+	{
+		const xmlChar *tag;
+		xmlReaderTypes type;
+
+		tag = xmlTextReaderConstName (reader);
+		type = xmlTextReaderNodeType (reader);
+
+		if (state == STATE_ENTRIES &&
+		    type == XML_READER_TYPE_ELEMENT &&
+		    xmlStrEqual (tag, iso_entry))
+		{
+			read_entry_func (reader, user_data);
+		}
+		else if (state == STATE_START &&
+			 type == XML_READER_TYPE_ELEMENT &&
+			 xmlStrEqual (tag, iso_entries))
+		{
+			state = STATE_ENTRIES;
+		}
+		else if (state == STATE_ENTRIES &&
+			 type == XML_READER_TYPE_END_ELEMENT &&
+			 xmlStrEqual (tag, iso_entries))
+		{
+			state = STATE_STOP;
+		}
+		else if (type == XML_READER_TYPE_SIGNIFICANT_WHITESPACE ||
+			 type == XML_READER_TYPE_WHITESPACE ||
+			 type == XML_READER_TYPE_TEXT ||
+			 type == XML_READER_TYPE_COMMENT)
+		{
+			/* eat it */
+		}
+		else
+		{
+			/* ignore it */
+		}
+
+		ret = xmlTextReaderRead (reader);
+	}
+
+	xmlFreeTextReader (reader);
+
+out:
+	if (ret < 0 || state != STATE_STOP)
+	{
+		/* This is not critical, we will fallback to our own code */
+		g_free (filename);
+		return FALSE;
+	}
+
+	g_free (filename);
+
+	return TRUE;
+}
+
+#endif /* HAVE_ISO_CODES */
+
+
+static void
+ensure_iso_codes_initialised (void)
+{
+	static gboolean initialised = FALSE;
+
+	if (initialised == TRUE)
+	{
+		return;
+	}
+	initialised = TRUE;
+
+#if defined (ENABLE_NLS) && defined (HAVE_ISO_CODES)
+	bindtextdomain (ISO_639_DOMAIN, ISOCODESLOCALEDIR);
+	bind_textdomain_codeset (ISO_639_DOMAIN, "UTF-8");
+
+	bindtextdomain(ISO_3166_DOMAIN, ISOCODESLOCALEDIR);
+	bind_textdomain_codeset (ISO_3166_DOMAIN, "UTF-8");
+#endif
+
+	iso_639_table = g_hash_table_new_full (g_str_hash, g_str_equal,
+					       (GDestroyNotify) xmlFree,
+					       (GDestroyNotify) xmlFree);
+
+	iso_3166_table = g_hash_table_new_full (g_str_hash, g_str_equal,
+						(GDestroyNotify) g_free,
+						(GDestroyNotify) xmlFree);
+	
+#ifdef HAVE_ISO_CODES
+	load_iso_entries (639, (GFunc) read_iso_639_entry, iso_639_table);
+	load_iso_entries (3166, (GFunc) read_iso_3166_entry, iso_3166_table);
+#endif
+}
+
+
+static char *
+get_iso_name_for_lang_code (const char *code)
+{
+	char **str;
+	char *name = NULL;
+	const char *langname, *localename;
+	int len;
+
+	str = g_strsplit (code, "_", -1);
+
+	/* count the entries */
+	for (len = 0; str[len]; len++ ) /* empty */;
+
+	g_return_val_if_fail (len != 0, NULL);
+
+	langname = (const char *) g_hash_table_lookup (iso_639_table, str[0]);
+
+	if (len == 1 && langname != NULL)
+	{
+		name = g_strdup (dgettext (ISO_639_DOMAIN, langname));
+	}
+	else if (len == 2 && langname != NULL)
+	{
+		localename = (const char *) g_hash_table_lookup (iso_3166_table, str[1]);
+
+		if (localename != NULL)
+		{
+			/* translators: the first %s is the language name, and the
+			 * second %s is the locale name. Example:
+			 * "French (France)
+			 *
+			 * Also: The text before the "|" is context to help you decide on
+                         * the correct translation. You MUST OMIT it in the translated string.
+			 */
+			name = g_strdup_printf (Q_("language|%s (%s)"),
+						dgettext (ISO_639_DOMAIN, langname),
+						dgettext (ISO_3166_DOMAIN, localename));
+		}
+		else
+		{
+			name = g_strdup_printf (Q_("language|%s (%s)"),
+						dgettext (ISO_639_DOMAIN, langname), str[1]);
+		}
+	}
+
+	g_strfreev (str);
+
+	return name;
+}
+
+/**
+ * gtkspell_iso_codes_lookup_name_for_code:
+ * @code: A language code, e.g. en_CA
+ *
+ * Looks up a name to display to the user for a language code,
+ * this might use the iso-codes package if support was compiled
+ * in, and it is available
+ *
+ * Returns: the UTF-8 string to display to the user, or NULL if 
+ * a name for the code could not be found
+ */
+char *
+gtkspell_iso_codes_lookup_name_for_code (const char *code)
+{
+	char * lcode;
+	char * ret;
+
+	g_return_val_if_fail (code != NULL, NULL);
+
+	ensure_iso_codes_initialised ();
+
+	lcode = g_ascii_strdown (code, -1);
+
+	ret = get_iso_name_for_lang_code (lcode);
+
+	g_free (lcode);
+
+	return ret;
+}
+
diff --git a/src/fe-gtk/sexy-iso-codes.h b/src/fe-gtk/sexy-iso-codes.h
new file mode 100644
index 00000000..e5f37162
--- /dev/null
+++ b/src/fe-gtk/sexy-iso-codes.h
@@ -0,0 +1,37 @@
+/*
+ *  Copyright (C) 2005 Nathan Fredrickson
+ *  Borrowed from Galeon, renamed, and simplified to only use iso-codes with no
+ *  fallback method.
+ *
+ *  Copyright (C) 2004 Christian Persch
+ *  Copyright (C) 2004 Crispin Flowerday
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA  02111-1307, USA.
+ *
+ */
+
+#ifndef GTKSPELL_ISO_CODES_H
+#define GTKSPELL_ISO_CODES_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+char *  gtkspell_iso_codes_lookup_name_for_code (const char *code);
+
+G_END_DECLS
+
+#endif
diff --git a/src/fe-gtk/sexy-marshal.c b/src/fe-gtk/sexy-marshal.c
new file mode 100644
index 00000000..10a629f2
--- /dev/null
+++ b/src/fe-gtk/sexy-marshal.c
@@ -0,0 +1,129 @@
+
+#include	<glib-object.h>
+
+
+#ifdef G_ENABLE_DEBUG
+#define g_marshal_value_peek_boolean(v)  g_value_get_boolean (v)
+#define g_marshal_value_peek_char(v)     g_value_get_char (v)
+#define g_marshal_value_peek_uchar(v)    g_value_get_uchar (v)
+#define g_marshal_value_peek_int(v)      g_value_get_int (v)
+#define g_marshal_value_peek_uint(v)     g_value_get_uint (v)
+#define g_marshal_value_peek_long(v)     g_value_get_long (v)
+#define g_marshal_value_peek_ulong(v)    g_value_get_ulong (v)
+#define g_marshal_value_peek_int64(v)    g_value_get_int64 (v)
+#define g_marshal_value_peek_uint64(v)   g_value_get_uint64 (v)
+#define g_marshal_value_peek_enum(v)     g_value_get_enum (v)
+#define g_marshal_value_peek_flags(v)    g_value_get_flags (v)
+#define g_marshal_value_peek_float(v)    g_value_get_float (v)
+#define g_marshal_value_peek_double(v)   g_value_get_double (v)
+#define g_marshal_value_peek_string(v)   (char*) g_value_get_string (v)
+#define g_marshal_value_peek_param(v)    g_value_get_param (v)
+#define g_marshal_value_peek_boxed(v)    g_value_get_boxed (v)
+#define g_marshal_value_peek_pointer(v)  g_value_get_pointer (v)
+#define g_marshal_value_peek_object(v)   g_value_get_object (v)
+#else /* !G_ENABLE_DEBUG */
+/* WARNING: This code accesses GValues directly, which is UNSUPPORTED API.
+ *          Do not access GValues directly in your code. Instead, use the
+ *          g_value_get_*() functions
+ */
+#define g_marshal_value_peek_boolean(v)  (v)->data[0].v_int
+#define g_marshal_value_peek_char(v)     (v)->data[0].v_int
+#define g_marshal_value_peek_uchar(v)    (v)->data[0].v_uint
+#define g_marshal_value_peek_int(v)      (v)->data[0].v_int
+#define g_marshal_value_peek_uint(v)     (v)->data[0].v_uint
+#define g_marshal_value_peek_long(v)     (v)->data[0].v_long
+#define g_marshal_value_peek_ulong(v)    (v)->data[0].v_ulong
+#define g_marshal_value_peek_int64(v)    (v)->data[0].v_int64
+#define g_marshal_value_peek_uint64(v)   (v)->data[0].v_uint64
+#define g_marshal_value_peek_enum(v)     (v)->data[0].v_long
+#define g_marshal_value_peek_flags(v)    (v)->data[0].v_ulong
+#define g_marshal_value_peek_float(v)    (v)->data[0].v_float
+#define g_marshal_value_peek_double(v)   (v)->data[0].v_double
+#define g_marshal_value_peek_string(v)   (v)->data[0].v_pointer
+#define g_marshal_value_peek_param(v)    (v)->data[0].v_pointer
+#define g_marshal_value_peek_boxed(v)    (v)->data[0].v_pointer
+#define g_marshal_value_peek_pointer(v)  (v)->data[0].v_pointer
+#define g_marshal_value_peek_object(v)   (v)->data[0].v_pointer
+#endif /* !G_ENABLE_DEBUG */
+
+
+/* BOOLEAN:STRING (./marshal.list:1) */
+void
+sexy_marshal_BOOLEAN__STRING (GClosure     *closure,
+                              GValue       *return_value,
+                              guint         n_param_values,
+                              const GValue *param_values,
+                              gpointer      invocation_hint,
+                              gpointer      marshal_data)
+{
+  typedef gboolean (*GMarshalFunc_BOOLEAN__STRING) (gpointer     data1,
+                                                    gpointer     arg_1,
+                                                    gpointer     data2);
+  register GMarshalFunc_BOOLEAN__STRING callback;
+  register GCClosure *cc = (GCClosure*) closure;
+  register gpointer data1, data2;
+  gboolean v_return;
+
+  g_return_if_fail (return_value != NULL);
+  g_return_if_fail (n_param_values == 2);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = g_value_peek_pointer (param_values + 0);
+    }
+  else
+    {
+      data1 = g_value_peek_pointer (param_values + 0);
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_BOOLEAN__STRING) (marshal_data ? marshal_data : cc->callback);
+
+  v_return = callback (data1,
+                       g_marshal_value_peek_string (param_values + 1),
+                       data2);
+
+  g_value_set_boolean (return_value, v_return);
+}
+
+/* OBJECT:OBJECT,OBJECT (./marshal.list:2) */
+void
+sexy_marshal_OBJECT__OBJECT_OBJECT (GClosure     *closure,
+                                    GValue       *return_value,
+                                    guint         n_param_values,
+                                    const GValue *param_values,
+                                    gpointer      invocation_hint,
+                                    gpointer      marshal_data)
+{
+  typedef GObject* (*GMarshalFunc_OBJECT__OBJECT_OBJECT) (gpointer     data1,
+                                                          gpointer     arg_1,
+                                                          gpointer     arg_2,
+                                                          gpointer     data2);
+  register GMarshalFunc_OBJECT__OBJECT_OBJECT callback;
+  register GCClosure *cc = (GCClosure*) closure;
+  register gpointer data1, data2;
+  GObject* v_return;
+
+  g_return_if_fail (return_value != NULL);
+  g_return_if_fail (n_param_values == 3);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = g_value_peek_pointer (param_values + 0);
+    }
+  else
+    {
+      data1 = g_value_peek_pointer (param_values + 0);
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_OBJECT__OBJECT_OBJECT) (marshal_data ? marshal_data : cc->callback);
+
+  v_return = callback (data1,
+                       g_marshal_value_peek_object (param_values + 1),
+                       g_marshal_value_peek_object (param_values + 2),
+                       data2);
+
+  g_value_take_object (return_value, v_return);
+}
+
diff --git a/src/fe-gtk/sexy-marshal.h b/src/fe-gtk/sexy-marshal.h
new file mode 100644
index 00000000..f41eccbe
--- /dev/null
+++ b/src/fe-gtk/sexy-marshal.h
@@ -0,0 +1,28 @@
+
+#ifndef __sexy_marshal_MARSHAL_H__
+#define __sexy_marshal_MARSHAL_H__
+
+#include	<glib-object.h>
+
+G_BEGIN_DECLS
+
+/* BOOLEAN:STRING (./marshal.list:1) */
+extern void sexy_marshal_BOOLEAN__STRING (GClosure     *closure,
+                                          GValue       *return_value,
+                                          guint         n_param_values,
+                                          const GValue *param_values,
+                                          gpointer      invocation_hint,
+                                          gpointer      marshal_data);
+
+/* OBJECT:OBJECT,OBJECT (./marshal.list:2) */
+extern void sexy_marshal_OBJECT__OBJECT_OBJECT (GClosure     *closure,
+                                                GValue       *return_value,
+                                                guint         n_param_values,
+                                                const GValue *param_values,
+                                                gpointer      invocation_hint,
+                                                gpointer      marshal_data);
+
+G_END_DECLS
+
+#endif /* __sexy_marshal_MARSHAL_H__ */
+
diff --git a/src/fe-gtk/sexy-spell-entry.c b/src/fe-gtk/sexy-spell-entry.c
index d67ffe2d..9483f04b 100644
--- a/src/fe-gtk/sexy-spell-entry.c
+++ b/src/fe-gtk/sexy-spell-entry.c
@@ -26,10 +26,19 @@
 #include <gtk/gtk.h>
 #include "sexy-spell-entry.h"
 #include <string.h>
+#include <fcntl.h>
 #include <glib/gi18n.h>
 #include <sys/types.h>
-/*#include "gtkspell-iso-codes.h"
-#include "sexy-marshal.h"*/
+#include <sys/stat.h>
+#include "sexy-iso-codes.h"
+#include "sexy-marshal.h"
+
+#ifdef WIN32
+#include "typedef.h"
+#endif
+
+#include "../common/cfgfiles.h"
+#include "../common/xchatc.h"
 
 /*
  * Bunch of poop to make enchant into a runtime dependency rather than a
@@ -134,12 +143,19 @@ initialize_enchant ()
 	GModule *enchant;
 	gpointer funcptr;
 
+#ifdef WIN32
+	enchant = g_module_open("libenchant.dll", 0);
+#else
 	enchant = g_module_open("libenchant", 0);
+#endif
 	if (enchant == NULL)
 	{
+#ifndef WIN32
 		enchant = g_module_open("libenchant.so.1", 0);
-		if (enchant == NULL)
-			return;
+				if (enchant == NULL)
+					return;
+#endif
+		return;
 	}
 
 	have_enchant = TRUE;
@@ -207,14 +223,14 @@ sexy_spell_entry_class_init(SexySpellEntryClass *klass)
 	 * Returns: %FALSE to indicate that the word should be marked as
 	 * correct.
 	 */
-/*	signals[WORD_CHECK] = g_signal_new("word_check",
+	signals[WORD_CHECK] = g_signal_new("word_check",
 					   G_TYPE_FROM_CLASS(object_class),
 					   G_SIGNAL_RUN_LAST,
 					   G_STRUCT_OFFSET(SexySpellEntryClass, word_check),
 					   (GSignalAccumulator) spell_accumulator, NULL,
 					   sexy_marshal_BOOLEAN__STRING,
 					   G_TYPE_BOOLEAN,
-					   1, G_TYPE_STRING);*/
+					   1, G_TYPE_STRING);
 }
 
 static void
@@ -260,8 +276,42 @@ gtk_entry_find_position (GtkEntry *entry, gint x)
 static void
 insert_underline(SexySpellEntry *entry, guint start, guint end)
 {
-	PangoAttribute *ucolor = pango_attr_underline_color_new (65535, 0, 0);
-	PangoAttribute *unline = pango_attr_underline_new (PANGO_UNDERLINE_ERROR);
+	int fh, l;
+	int red, green, blue;
+	struct stat st;
+	char *cfg;
+	PangoAttribute *ucolor;
+	PangoAttribute *unline;
+
+	fh = xchat_open_file ("colors.conf", O_RDONLY, 0, 0);
+
+	if (fh != -1)
+	{
+		fstat (fh, &st);
+		cfg = malloc (st.st_size + 1);
+
+		if (cfg)
+		{
+			cfg[0] = '\0';
+			l = read (fh, cfg, st.st_size);
+			if (l >= 0)
+			{
+				cfg[l] = '\0';
+			}
+
+			cfg_get_color (cfg, "color_265", &red, &green, &blue);
+			free (cfg);
+		}
+
+		close (fh);
+	} else
+	{
+		red = 65535;
+		green = blue = 0;
+	}
+
+	ucolor = pango_attr_underline_color_new (red, green, blue);
+	unline = pango_attr_underline_new (PANGO_UNDERLINE_ERROR);
 
 	ucolor->start_index = start;
 	unline->start_index = start;
@@ -457,10 +507,6 @@ build_spelling_menu(SexySpellEntry *entry, const gchar *word)
 	if (entry->priv->dict_list == NULL)
 		return topmenu;
 
-#if 1
-	dict = (struct EnchantDict *) entry->priv->dict_list->data;
-	build_suggestion_menu(entry, topmenu, dict, word);
-#else
 	/* Suggestions */
 	if (g_slist_length(entry->priv->dict_list) == 1) {
 		dict = (struct EnchantDict *) entry->priv->dict_list->data;
@@ -489,7 +535,6 @@ build_spelling_menu(SexySpellEntry *entry, const gchar *word)
 			build_suggestion_menu(entry, menu, dict, word);
 		}
 	}
-#endif
 
 	/* Separator */
 	mi = gtk_separator_menu_item_new ();
@@ -503,11 +548,6 @@ build_spelling_menu(SexySpellEntry *entry, const gchar *word)
 
 	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi), gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
 
-#if 1
-	dict = (struct EnchantDict *) entry->priv->dict_list->data;
-	g_object_set_data(G_OBJECT(mi), "enchant-dict", dict);
-	g_signal_connect(G_OBJECT(mi), "activate", G_CALLBACK(add_to_dictionary), entry);
-#else
 	if (g_slist_length(entry->priv->dict_list) == 1) {
 		dict = (struct EnchantDict *) entry->priv->dict_list->data;
 		g_object_set_data(G_OBJECT(mi), "enchant-dict", dict);
@@ -539,7 +579,6 @@ build_spelling_menu(SexySpellEntry *entry, const gchar *word)
 			gtk_menu_shell_append(GTK_MENU_SHELL(menu), submi);
 		}
 	}
-#endif
 
 	gtk_widget_show_all(mi);
 	gtk_menu_shell_append(GTK_MENU_SHELL(topmenu), mi);
@@ -721,11 +760,7 @@ word_misspelled(SexySpellEntry *entry, int start, int end)
 
 	g_strlcpy(word, text + start, end - start + 1);
 
-#if 0
 	g_signal_emit(entry, signals[WORD_CHECK], 0, word, &ret);
-#else
-	ret = default_word_check (entry, word);
-#endif
 
 	g_free(word);
 	return ret;
@@ -921,10 +956,10 @@ void
 sexy_spell_entry_activate_default_languages(SexySpellEntry *entry)
 {
 #if GLIB_CHECK_VERSION (2, 6, 0)
-	const gchar* const *langs;
+	/*const gchar* const *langs;
 	int i;
-	gchar *lastprefix = NULL;
-	GSList *enchant_langs;
+	gchar *lastprefix = NULL;*/
+	GSList *enchant_langs, *i;
 
 	if (!have_enchant)
 		return;
@@ -933,14 +968,14 @@ sexy_spell_entry_activate_default_languages(SexySpellEntry *entry)
 		entry->priv->broker = enchant_broker_init();
 
 
-	langs = g_get_language_names ();
+	/*langs = g_get_language_names ();
 
 	if (langs == NULL)
-		return;
+		return;*/
 
 	enchant_langs = sexy_spell_entry_get_languages(entry);
 
-	for (i = 0; langs[i]; i++) {
+	/*for (i = 0; langs[i]; i++) {
 		if ((g_strncasecmp(langs[i], "C", 1) != 0) &&
 		    (strlen(langs[i]) >= 2) &&
 		    enchant_has_lang(langs[i], enchant_langs)) {
@@ -952,10 +987,19 @@ sexy_spell_entry_activate_default_languages(SexySpellEntry *entry)
 		}
 	}
 	if (lastprefix != NULL)
-		g_free(lastprefix);
+		g_free(lastprefix);*/
+
+	for (i = enchant_langs; i; i = g_slist_next (i))
+	{
+		if (strstr (prefs.spell_langs, i->data) != NULL)
+		{
+			sexy_spell_entry_activate_language_internal (entry, i->data, NULL);
+		}
+	}
 
 	g_slist_foreach(enchant_langs, (GFunc) g_free, NULL);
 	g_slist_free(enchant_langs);
+	g_slist_free (i);
 
 	/* If we don't have any languages activated, use "en" */
 	if (entry->priv->dict_list == NULL)
@@ -1083,8 +1127,8 @@ gchar *
 sexy_spell_entry_get_language_name(const SexySpellEntry *entry,
 								   const gchar *lang)
 {
-	/*if (have_enchant)
-		return gtkspell_iso_codes_lookup_name_for_code(lang);*/
+	if (have_enchant)
+		return gtkspell_iso_codes_lookup_name_for_code(lang);
 	return NULL;
 }
 
diff --git a/src/fe-gtk/typedef.h b/src/fe-gtk/typedef.h
new file mode 100644
index 00000000..b20612ea
--- /dev/null
+++ b/src/fe-gtk/typedef.h
@@ -0,0 +1,11 @@
+#ifndef SSIZE_T_DEFINED
+#ifdef ssize_t
+#undef ssize_t
+#endif
+#ifdef _WIN64
+typedef __int64          ssize_t;
+#else
+typedef _W64 int         ssize_t;
+#endif
+#define SSIZE_T_DEFINED
+#endif
diff --git a/src/fe-gtk/xchat.exe.manifest b/src/fe-gtk/xchat.exe.manifest
new file mode 100644
index 00000000..13685d98
--- /dev/null
+++ b/src/fe-gtk/xchat.exe.manifest
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+  <assemblyIdentity
+    name="XChat"
+    processorArchitecture="*"
+    version="1.0.0.0"
+    type="win32"
+  />
+  <description>XChat IRC client</description>
+  <dependency>
+    <dependentAssembly>
+      <assemblyIdentity
+        type="win32"
+        name="Microsoft.Windows.Common-Controls"
+        version="6.0.0.0"
+        processorArchitecture="*"
+        publicKeyToken="6595b64144ccf1df"
+        language="*"
+      />
+    </dependentAssembly>
+  </dependency>
+</assembly>
diff --git a/src/fe-gtk/xchat.rc b/src/fe-gtk/xchat.rc
new file mode 100644
index 00000000..28676b83
--- /dev/null
+++ b/src/fe-gtk/xchat.rc
@@ -0,0 +1,28 @@
+#include <winver.h>

+#include "../../config.h"

+#include "../../resource.h"

+

+1 24 "xchat.exe.manifest"

+

+XC_ICON ICON "../../xchat.ico" 

+

+VS_VERSION_INFO VERSIONINFO

+	FILEVERSION    COMMA_VERSION

+	PRODUCTVERSION COMMA_VERSION

+	BEGIN

+		BLOCK "StringFileInfo"

+		BEGIN

+			BLOCK "040904B0"

+			BEGIN

+				

+				VALUE "FileDescription", "XChat-WDK IRC Client"

+				VALUE "ProductName", "XChat-WDK" 

+				VALUE "ProductVersion", PACKAGE_VERSION

+				VALUE "FileVersion", PACKAGE_VERSION

+			END

+		END

+		BLOCK "VarFileInfo"

+		BEGIN

+			VALUE "Translation", 0x0409, 0x04B0

+		END

+	END

diff --git a/src/fe-gtk/xtext.c b/src/fe-gtk/xtext.c
index fa9803c7..3bc9b6a8 100644
--- a/src/fe-gtk/xtext.c
+++ b/src/fe-gtk/xtext.c
@@ -42,7 +42,6 @@
 #include <ctype.h>
 #include <stdlib.h>
 #include <time.h>
-#include <unistd.h>
 #include <gtk/gtkmain.h>
 #include <gtk/gtksignal.h>
 #include <gtk/gtkselection.h>
@@ -67,12 +66,16 @@
 #endif
 
 #include "xtext.h"
+#include "../common/xchat.h"
+#include "../common/xchatc.h"
 
 #define charlen(str) g_utf8_skip[*(guchar *)(str)]
 
 #ifdef WIN32
 #include <windows.h>
 #include <gdk/gdkwin32.h>
+#else
+#include <unistd.h>
 #endif
 
 /* is delimiter */
@@ -998,7 +1001,11 @@ gtk_xtext_realize (GtkWidget * widget)
 
 	gdk_window_set_user_data (widget->window, widget);
 
+#if GTK_CHECK_VERSION(2,24,0)
+	xtext->depth = gdk_window_get_visual (widget->window)->depth;
+#else
 	xtext->depth = gdk_drawable_get_visual (widget->window)->depth;
+#endif
 
 	val.subwindow_mode = GDK_INCLUDE_INFERIORS;
 	val.graphics_exposures = 0;
@@ -1941,7 +1948,7 @@ gtk_xtext_check_mark_stamp (GtkXText *xtext, GdkModifierType mask)
 {
 	gboolean redraw = FALSE;
 
-	if ((mask & GDK_SHIFT_MASK))
+	if (mask & GDK_SHIFT_MASK || prefs.autocopy_stamp)
 	{
 		if (!xtext->mark_stamp)
 		{
@@ -2106,7 +2113,16 @@ gtk_xtext_set_clip_owner (GtkWidget * xtext, GdkEventButton * event)
 		free (str);
 	}
 
-	gtk_selection_owner_set (xtext, GDK_SELECTION_PRIMARY, event->time);
+	if (event)
+	{
+		gtk_selection_owner_set (xtext, GDK_SELECTION_PRIMARY, event->time);
+	}
+}
+
+void
+gtk_xtext_copy_selection (GtkXText *xtext)
+{
+	gtk_xtext_set_clip_owner (xtext, NULL);
 }
 
 static void
@@ -2182,9 +2198,12 @@ gtk_xtext_button_release (GtkWidget * widget, GdkEventButton * event)
 		if (xtext->buffer->last_ent_start)
 		{
 			xtext->color_paste = FALSE;
-			if (event->state & GDK_CONTROL_MASK)
+			if (event->state & GDK_CONTROL_MASK || prefs.autocopy_color)
 				xtext->color_paste = TRUE;
-			gtk_xtext_set_clip_owner (GTK_WIDGET (xtext), event);
+			if (prefs.autocopy_text)
+			{
+				gtk_xtext_set_clip_owner (GTK_WIDGET (xtext), event);
+			}
 		}
 
 		if (xtext->select_start_x == event->x &&
@@ -2249,7 +2268,10 @@ gtk_xtext_button_press (GtkWidget * widget, GdkEventButton * event)
 			ent->mark_end = offset + len;
 			gtk_xtext_selection_render (xtext, ent, offset, ent, offset + len);
 			xtext->word_or_line_select = TRUE;
-			gtk_xtext_set_clip_owner (GTK_WIDGET (xtext), event);
+			if (prefs.autocopy_text)
+			{
+				gtk_xtext_set_clip_owner (GTK_WIDGET (xtext), event);
+			}
 		}
 
 		return FALSE;
@@ -2265,7 +2287,10 @@ gtk_xtext_button_press (GtkWidget * widget, GdkEventButton * event)
 			ent->mark_end = ent->str_len;
 			gtk_xtext_selection_render (xtext, ent, 0, ent, ent->str_len);
 			xtext->word_or_line_select = TRUE;
-			gtk_xtext_set_clip_owner (GTK_WIDGET (xtext), event);
+			if (prefs.autocopy_text)
+			{
+				gtk_xtext_set_clip_owner (GTK_WIDGET (xtext), event);
+			}
 		}
 
 		return FALSE;
@@ -3836,7 +3861,7 @@ gtk_xtext_load_trans (GtkXText * xtext)
 	PaintDesktop (hdc);
 	ReleaseDC (hwnd, hdc);
 
-	gdk_window_get_size (GTK_WIDGET (xtext)->window, &width, &height);
+	gdk_drawable_get_size (GTK_WIDGET (xtext)->window, &width, &height);
 	img = gdk_image_get (GTK_WIDGET (xtext)->window, 0, 0, width+128, height);
 	xtext->pixmap = win32_tint (xtext, img, img->width, img->height);
 
diff --git a/src/fe-gtk/xtext.h b/src/fe-gtk/xtext.h
index a37ddc32..90fa1bca 100644
--- a/src/fe-gtk/xtext.h
+++ b/src/fe-gtk/xtext.h
@@ -270,6 +270,7 @@ void gtk_xtext_set_wordwrap (GtkXText *xtext, gboolean word_wrap);
 xtext_buffer *gtk_xtext_buffer_new (GtkXText *xtext);
 void gtk_xtext_buffer_free (xtext_buffer *buf);
 void gtk_xtext_buffer_show (GtkXText *xtext, xtext_buffer *buf, int render);
+void gtk_xtext_copy_selection (GtkXText *xtext);
 GType gtk_xtext_get_type (void);
 
 #endif
diff --git a/src/fe-text/fe-text.c b/src/fe-text/fe-text.c
index 2bc2e649..f3c1ff05 100644
--- a/src/fe-text/fe-text.c
+++ b/src/fe-text/fe-text.c
@@ -22,60 +22,51 @@
 #ifdef HAVE_STRINGS_H
 #include <strings.h>
 #endif
+#ifdef WIN32
+#define STDIN_FILENO 0
+#define STDOUT_FILENO 1
+#else
+#include <unistd.h>
 #include <sys/time.h>
+#endif
 #include <sys/types.h>
-#include <unistd.h>
 #include <ctype.h>
+#include <glib.h>
 #include "../common/xchat.h"
 #include "../common/xchatc.h"
+#include "../common/cfgfiles.h"
 #include "../common/outbound.h"
 #include "../common/util.h"
 #include "../common/fe.h"
 #include "fe-text.h"
 
 
-static GSList *tmr_list;		  /* timer list */
-static int tmr_list_count;
-static GSList *se_list;			  /* socket event list */
-static int se_list_count;
 static int done = FALSE;		  /* finished ? */
 
 
 static void
 send_command (char *cmd)
 {
-	handle_multiline (sess_list->data, cmd, TRUE, FALSE);
+	handle_multiline (current_tab, cmd, TRUE, FALSE);
 }
 
-static void
-read_stdin (void)
+static gboolean
+handle_line (GIOChannel *channel, GIOCondition cond, gpointer data)
 {
-	int len, i = 0;
-	static int pos = 0;
-	static char inbuf[1024];
-	char tmpbuf[512];
-
-	len = read (STDIN_FILENO, tmpbuf, sizeof tmpbuf - 1);
-
-	while (i < len)
-	{
-		switch (tmpbuf[i])
-		{
-		case '\r':
-			break;
 
-		case '\n':
-			inbuf[pos] = 0;
-			pos = 0;
-			send_command (inbuf);
-			break;
+	gchar *str_return;
+	gsize length, terminator_pos;
+	GError *error = NULL;
+	GIOStatus result;
 
-		default:
-			inbuf[pos] = tmpbuf[i];
-			if (pos < (sizeof inbuf - 2))
-				pos++;
-		}
-		i++;
+	result = g_io_channel_read_line(channel, &str_return, &length, &terminator_pos, &error);
+	if (result == G_IO_STATUS_ERROR) {
+		return FALSE;
+	}
+	else {
+		send_command(str_return);
+		g_free(str_return);
+		return TRUE;
 	}
 }
 
@@ -87,12 +78,13 @@ fe_new_window (struct session *sess, int focus)
 	char buf[512];
 
 	sess->gui = malloc (4);
+	current_sess = sess;
 
 	if (!sess->server->front_session)
 		sess->server->front_session = sess;
 	if (!sess->server->server_session)
 		sess->server->server_session = sess;
-	if (!current_tab)
+	if (!current_tab || focus)
 		current_tab = sess;
 
 	if (done_intro)
@@ -101,7 +93,7 @@ fe_new_window (struct session *sess, int focus)
 
 	snprintf (buf, sizeof (buf),
 				"\n"
-				" \017xchat \00310"PACKAGE_VERSION"\n"
+				" \017XChat-Text \00310"PACKAGE_VERSION"\n"
 				" \017Running on \00310%s \017glib \00310%d.%d.%d\n"
 				" \017This binary compiled \00310"__DATE__"\017\n",
 				get_cpu_str(),
@@ -133,15 +125,21 @@ get_stamp_str (time_t tim, char *dest, int size)
 }
 
 static int
-timecat (char *buf)
+timecat (char *buf, time_t stamp)
 {
 	char stampbuf[64];
 
-	get_stamp_str (time (0), stampbuf, sizeof (stampbuf));
+	/* set the stamp to the current time if not provided */
+	if (!stamp)
+		stamp = time (0);
+
+	get_stamp_str (stamp, stampbuf, sizeof (stampbuf));
 	strcat (buf, stampbuf);
 	return strlen (stampbuf);
 }
 
+/* Windows doesn't handle ANSI codes in cmd.exe, need to not display them */
+#ifndef WIN32
 /*                       0  1  2  3  4  5  6  7   8   9   10 11  12  13  14 15 */
 static const short colconv[] = { 0, 7, 4, 2, 1, 3, 5, 11, 13, 12, 6, 16, 14, 15, 10, 7 };
 
@@ -157,7 +155,7 @@ fe_print_text (struct session *sess, char *text, time_t stamp)
 	if (prefs.timestamp)
 	{
 		newtext[0] = 0;
-		j += timecat (newtext);
+		j += timecat (newtext, stamp);
 	}
 	while (i < len)
 	{
@@ -165,7 +163,7 @@ fe_print_text (struct session *sess, char *text, time_t stamp)
 		{
 			dotime = FALSE;
 			newtext[j] = 0;
-			j += timecat (newtext);
+			j += timecat (newtext, stamp);
 		}
 		switch (text[i])
 		{
@@ -179,8 +177,7 @@ fe_print_text (struct session *sess, char *text, time_t stamp)
 				j++;
 				newtext[j] = 'm';
 				j++;
-				i--;
-				goto jump2;
+				goto endloop;
 			}
 			k = 0;
 			comma = FALSE;
@@ -226,13 +223,16 @@ fe_print_text (struct session *sess, char *text, time_t stamp)
 						comma = TRUE;
 						break;
 					default:
-						goto jump;
+						goto endloop;
 					}
 					k = 0;
 				}
 				i++;
 			}
 			break;
+		/* don't actually want hidden text */
+		case '\010':				  /* hidden */
+			break;
 		case '\026':				  /* REVERSE */
 			if (reverse)
 			{
@@ -296,120 +296,246 @@ fe_print_text (struct session *sess, char *text, time_t stamp)
 			newtext[j] = text[i];
 			j++;
 		}
-	 jump2:
 		i++;
-	 jump:
-		i += 0;
+		endloop:
+			;
 	}
+
+	/* make sure last character is a new line */
+	if (text[i-1] != '\n')
+		newtext[j++] = '\n';
+
 	newtext[j] = 0;
 	write (STDOUT_FILENO, newtext, j);
 	free (newtext);
 }
-
+#else
+/* The win32 version for cmd.exe */
 void
-fe_timeout_remove (int tag)
+fe_print_text (struct session *sess, char *text, time_t stamp)
 {
-	timerevent *te;
-	GSList *list;
+	int dotime = FALSE;
+	int comma, k, i = 0, j = 0, len = strlen (text);
+
+	unsigned char *newtext = malloc (len + 1024);
 
-	list = tmr_list;
-	while (list)
+	if (prefs.timestamp)
 	{
-		te = (timerevent *) list->data;
-		if (te->tag == tag)
+		newtext[0] = 0;
+		j += timecat (newtext, stamp);
+	}
+	while (i < len)
+	{
+		if (dotime && text[i] != 0)
 		{
-			tmr_list = g_slist_remove (tmr_list, te);
-			free (te);
-			return;
+			dotime = FALSE;
+			newtext[j] = 0;
+			j += timecat (newtext, stamp);
 		}
-		list = list->next;
+		switch (text[i])
+		{
+		case 3:
+			i++;
+			if (!isdigit (text[i]))
+			{
+				goto endloop;
+			}
+			k = 0;
+			comma = FALSE;
+			while (i < len)
+			{
+				if (text[i] >= '0' && text[i] <= '9' && k < 2)
+				{
+					k++;
+				} else
+				{
+					switch (text[i])
+					{
+					case ',':
+						comma = TRUE;
+						break;
+					default:
+						goto endloop;
+					}
+					k = 0;
+
+				}
+				i++;
+			}
+			break;
+		/* don't actually want hidden text */
+		case '\010':				  /* hidden */
+		case '\026':				  /* REVERSE */
+		case '\037':				  /* underline */
+		case '\002':				  /* bold */
+		case '\017':				  /* reset all */
+			break;
+		case '\007':
+			if (!prefs.filterbeep)
+			{
+				newtext[j] = text[i];
+				j++;
+			}
+			break;
+		case '\t':
+			newtext[j] = ' ';
+			j++;
+			break;
+		case '\n':
+			newtext[j] = '\r';
+			j++;
+			if (prefs.timestamp)
+				dotime = TRUE;
+		default:
+			newtext[j] = text[i];
+			j++;
+		}
+		i++;
+		endloop:
+			;
 	}
+
+	/* make sure last character is a new line */
+	if (text[i-1] != '\n')
+		newtext[j++] = '\n';
+
+	newtext[j] = 0;
+	write (STDOUT_FILENO, newtext, j);
+	free (newtext);
+}
+#endif
+
+void
+fe_timeout_remove (int tag)
+{
+	g_source_remove (tag);
 }
 
 int
 fe_timeout_add (int interval, void *callback, void *userdata)
 {
-	struct timeval now;
-	timerevent *te = malloc (sizeof (timerevent));
-
-	tmr_list_count++;				  /* this overflows at 2.2Billion, who cares!! */
-
-	te->tag = tmr_list_count;
-	te->interval = interval;
-	te->callback = callback;
-	te->userdata = userdata;
-
-	gettimeofday (&now, NULL);
-	te->next_call = now.tv_sec * 1000 + (now.tv_usec / 1000) + te->interval;
-
-	tmr_list = g_slist_prepend (tmr_list, te);
-
-	return te->tag;
+	return g_timeout_add (interval, (GSourceFunc) callback, userdata);
 }
 
 void
 fe_input_remove (int tag)
 {
-	socketevent *se;
-	GSList *list;
-
-	list = se_list;
-	while (list)
-	{
-		se = (socketevent *) list->data;
-		if (se->tag == tag)
-		{
-			se_list = g_slist_remove (se_list, se);
-			free (se);
-			return;
-		}
-		list = list->next;
-	}
+	g_source_remove (tag);
 }
 
 int
 fe_input_add (int sok, int flags, void *func, void *data)
 {
-	socketevent *se = malloc (sizeof (socketevent));
+	int tag, type = 0;
+	GIOChannel *channel;
 
-	se_list_count++;				  /* this overflows at 2.2Billion, who cares!! */
+	channel = g_io_channel_unix_new (sok);
 
-	se->tag = se_list_count;
-	se->sok = sok;
-	se->rread = flags & FIA_READ;
-	se->wwrite = flags & FIA_WRITE;
-	se->eexcept = flags & FIA_EX;
-	se->callback = func;
-	se->userdata = data;
-	se_list = g_slist_prepend (se_list, se);
+	if (flags & FIA_READ)
+		type |= G_IO_IN | G_IO_HUP | G_IO_ERR;
+	if (flags & FIA_WRITE)
+		type |= G_IO_OUT | G_IO_ERR;
+	if (flags & FIA_EX)
+		type |= G_IO_PRI;
 
-	return se->tag;
+	tag = g_io_add_watch (channel, type, (GIOFunc) func, data);
+	g_io_channel_unref (channel);
+
+	return tag;
 }
 
+/* === command-line parameter parsing : requires glib 2.6 === */
+
+static char *arg_cfgdir = NULL;
+static gint arg_show_autoload = 0;
+static gint arg_show_config = 0;
+static gint arg_show_version = 0;
+
+static const GOptionEntry gopt_entries[] = 
+{
+ {"no-auto",	'a', 0, G_OPTION_ARG_NONE,	&arg_dont_autoconnect, N_("Don't auto connect to servers"), NULL},
+ {"cfgdir",	'd', 0, G_OPTION_ARG_STRING,	&arg_cfgdir, N_("Use a different config directory"), "PATH"},
+ {"no-plugins",	'n', 0, G_OPTION_ARG_NONE,	&arg_skip_plugins, N_("Don't auto load any plugins"), NULL},
+ {"plugindir",	'p', 0, G_OPTION_ARG_NONE,	&arg_show_autoload, N_("Show plugin auto-load directory"), NULL},
+ {"configdir",	'u', 0, G_OPTION_ARG_NONE,	&arg_show_config, N_("Show user config directory"), NULL},
+ {"url",	 0,  0, G_OPTION_ARG_STRING,	&arg_url, N_("Open an irc://server:port/channel URL"), "URL"},
+ {"version",	'v', 0, G_OPTION_ARG_NONE,	&arg_show_version, N_("Show version information"), NULL},
+ {NULL}
+};
+
 int
 fe_args (int argc, char *argv[])
 {
-	if (argc > 1)
+	GError *error = NULL;
+	GOptionContext *context;
+
+#ifdef ENABLE_NLS
+	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+#endif
+
+	context = g_option_context_new (NULL);
+	g_option_context_add_main_entries (context, gopt_entries, GETTEXT_PACKAGE);
+	g_option_context_parse (context, &argc, &argv, &error);
+
+	if (error)
+	{
+		if (error->message)
+			printf ("%s\n", error->message);
+		return 1;
+	}
+
+	g_option_context_free (context);
+
+	if (arg_show_version)
+	{
+		printf (PACKAGE_TARNAME" "PACKAGE_VERSION"\n");
+		return 0;
+	}
+
+	if (arg_show_autoload)
 	{
-		if (!strcasecmp (argv[1], "--version") || !strcasecmp (argv[1], "-v"))
+#ifdef WIN32
+		/* see the chdir() below */
+		char *sl, *exe = strdup (argv[0]);
+		sl = strrchr (exe, '\\');
+		if (sl)
 		{
-			puts (PACKAGE_VERSION);
-			return 0;
+			*sl = 0;
+			printf ("%s\\plugins\n", exe);
 		}
+#else
+		printf ("%s\n", XCHATLIBDIR"/plugins");
+#endif
+		return 0;
 	}
+
+	if (arg_show_config)
+	{
+		printf ("%s\n", get_xdir_fs ());
+		return 0;
+	}
+
+	if (arg_cfgdir)	/* we want filesystem encoding */
+	{
+		xdir_fs = strdup (arg_cfgdir);
+		if (xdir_fs[strlen (xdir_fs) - 1] == '/')
+			xdir_fs[strlen (xdir_fs) - 1] = 0;
+		g_free (arg_cfgdir);
+	}
+
 	return -1;
 }
 
 void
 fe_init (void)
 {
-	se_list = 0;
-	se_list_count = 0;
-	tmr_list = 0;
-	tmr_list_count = 0;
+	/* the following should be default generated, not enfoced in binary */
 	prefs.autosave = 0;
 	prefs.use_server_tab = 0;
 	prefs.autodialog = 0;
+	/* except for these, there is no lag meter, there is no server list */
 	prefs.lagometer = 0;
 	prefs.slist_skip = 1;
 }
@@ -417,129 +543,29 @@ fe_init (void)
 void
 fe_main (void)
 {
-	struct timeval timeout, now;
-	socketevent *se;
-	timerevent *te;
-	fd_set rd, wd, ex;
-	GSList *list;
-	guint64 shortest, delay;
+	GIOChannel *keyboard_input;
 
-	if (!sess_list)
-		new_ircwindow (NULL, NULL, SESS_SERVER, 0);
+	main_loop = g_main_loop_new(NULL, FALSE);
 
-#ifdef ENABLE_NLS
-	bindtextdomain (GETTEXT_PACKAGE, PREFIX"/share/locale");
-	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
-	textdomain (GETTEXT_PACKAGE);
+	/* Keyboard Entry Setup */
+#ifdef G_OS_WIN32
+	keyboard_input = g_io_channel_win32_new_fd(STDIN_FILENO);
+#else
+	keyboard_input = g_io_channel_unix_new(STDIN_FILENO);
 #endif
 
-	while (!done)
-	{
-		FD_ZERO (&rd);
-		FD_ZERO (&wd);
-		FD_ZERO (&ex);
-
-		list = se_list;
-		while (list)
-		{
-			se = (socketevent *) list->data;
-			if (se->rread)
-				FD_SET (se->sok, &rd);
-			if (se->wwrite)
-				FD_SET (se->sok, &wd);
-			if (se->eexcept)
-				FD_SET (se->sok, &ex);
-			list = list->next;
-		}
-
-		FD_SET (STDIN_FILENO, &rd);	/* for reading keyboard */
-
-		/* find the shortest timeout event */
-		shortest = 0;
-		list = tmr_list;
-		while (list)
-		{
-			te = (timerevent *) list->data;
-			if (te->next_call < shortest || shortest == 0)
-				shortest = te->next_call;
-			list = list->next;
-		}
-		gettimeofday (&now, NULL);
-		delay = shortest - ((now.tv_sec * 1000) + (now.tv_usec / 1000));
-		timeout.tv_sec = delay / 1000;
-		timeout.tv_usec = (delay % 1000) * 1000;
-
-		select (FD_SETSIZE, &rd, &wd, &ex, &timeout);
-
-		if (FD_ISSET (STDIN_FILENO, &rd))
-			read_stdin ();
-
-		/* set all checked flags to false */
-		list = se_list;
-		while (list)
-		{
-			se = (socketevent *) list->data;
-			se->checked = 0;
-			list = list->next;
-		}
-
-		/* check all the socket callbacks */
-		list = se_list;
-		while (list)
-		{
-			se = (socketevent *) list->data;
-			se->checked = 1;
-			if (se->rread && FD_ISSET (se->sok, &rd))
-			{
-				se->callback (NULL, 1, se->userdata);
-			} else if (se->wwrite && FD_ISSET (se->sok, &wd))
-			{
-				se->callback (NULL, 2, se->userdata);
-			} else if (se->eexcept && FD_ISSET (se->sok, &ex))
-			{
-				se->callback (NULL, 4, se->userdata);
-			}
-			list = se_list;
-			if (list)
-			{
-				se = (socketevent *) list->data;
-				while (se->checked)
-				{
-					list = list->next;
-					if (!list)
-						break;
-					se = (socketevent *) list->data;
-				}
-			}
-		}
+	g_io_add_watch(keyboard_input, G_IO_IN, handle_line, NULL);
 
-		/* now check our list of timeout events, some might need to be called! */
-		gettimeofday (&now, NULL);
-		list = tmr_list;
-		while (list)
-		{
-			te = (timerevent *) list->data;
-			list = list->next;
-			if (now.tv_sec * 1000 + (now.tv_usec / 1000) >= te->next_call)
-			{
-				/* if the callback returns 0, it must be removed */
-				if (te->callback (te->userdata) == 0)
-				{
-					fe_timeout_remove (te->tag);
-				} else
-				{
-					te->next_call = now.tv_sec * 1000 + (now.tv_usec / 1000) + te->interval;
-				}
-			}
-		}
+	g_main_loop_run(main_loop);
 
-	}
+	return;
 }
 
 void
 fe_exit (void)
 {
 	done = TRUE;
+	g_main_loop_quit(main_loop);
 }
 
 void
@@ -793,10 +819,23 @@ fe_get_int (char *prompt, int def, void *callback, void *ud)
 void
 fe_idle_add (void *func, void *data)
 {
+	g_idle_add (func, data);
 }
 void
 fe_ctrl_gui (session *sess, fe_gui_action action, int arg)
 {
+	/* only one action type handled for now, but could add more */
+	switch (action)
+	{
+	/* gui focus is really the only case xchat-text needs to wory about */
+	case FE_GUI_FOCUS:
+		current_sess = sess;
+		current_tab = sess;
+		sess->server->front_session = sess;
+		break;
+	default:
+		break;
+	}
 }
 int
 fe_gui_info (session *sess, int info_type)
diff --git a/src/fe-text/fe-text.h b/src/fe-text/fe-text.h
index b8afa284..e4f6f6c0 100644
--- a/src/fe-text/fe-text.h
+++ b/src/fe-text/fe-text.h
@@ -1,29 +1 @@
-
-typedef int (*socket_callback) (void *source, int condition, void *user_data);
-typedef int (*timer_callback) (void *user_data);
-
-struct socketeventRec
-{
-	socket_callback callback;
-	void *userdata;
-	int sok;
-	int tag;
-	int rread:1;
-	int wwrite:1;
-	int eexcept:1;
-	int checked:1;
-};
-
-typedef struct socketeventRec socketevent;
-
-
-struct timerRec
-{
-	timer_callback callback;
-	void *userdata;
-	int interval;
-	int tag;
-	guint64 next_call;	/* miliseconds */
-};
-
-typedef struct timerRec timerevent;
+GMainLoop *main_loop;
diff --git a/src/fe-text/makefile.mak b/src/fe-text/makefile.mak
new file mode 100644
index 00000000..59d277d3
--- /dev/null
+++ b/src/fe-text/makefile.mak
@@ -0,0 +1,20 @@
+include "..\makeinc.mak"

+

+COMLIB = ..\common\xchatcommon.lib

+PROG = xchat-text.exe

+

+!ifdef X64

+PLATOBJ = msvcrt_win2003.obj

+!else

+PLATOBJ = msvcrt_winxp.obj

+!endif

+

+all: fe-text.obj

+	link /out:$(PROG) /subsystem:console /nologo $(PLATOBJ) $(LIBS) $(COMLIB) fe-text.obj

+

+fe-text.obj: fe-text.c makefile.mak

+	cl $(CFLAGS) $(GLIB) fe-text.c

+

+clean:

+	@del *.obj

+	@del $(PROG)

diff --git a/src/gtk2-prefs/callbacks.cpp b/src/gtk2-prefs/callbacks.cpp
new file mode 100644
index 00000000..9cc5c928
--- /dev/null
+++ b/src/gtk2-prefs/callbacks.cpp
@@ -0,0 +1,224 @@
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <gtk/gtk.h>
+#include <iostream>
+
+#include "callbacks.h"
+#include "interface.h"
+#include "support.h"
+
+#include "main.h"
+
+
+
+extern GtkWidget* g_main_window;
+
+void
+on_main_showpreviewtoggle_toggled               (GtkToggleButton *togglebutton,
+                                        gpointer         user_data)
+{
+	if (gtk_toggle_button_get_active (togglebutton)) {
+		gtk_widget_show(lookup_widget(g_main_window, "main_previewhbox"));
+		gtk_button_set_label(GTK_BUTTON(togglebutton), "Hide preview <<");
+		gtk_window_resize(GTK_WINDOW(g_main_window), 700, 330);
+	} else {
+		gtk_widget_hide(lookup_widget(g_main_window, "main_previewhbox"));
+		gtk_button_set_label(GTK_BUTTON(togglebutton), "Show preview >>");
+		gtk_window_resize(GTK_WINDOW(g_main_window), 300, 330);
+	}
+
+}
+
+
+/*
+extern GtkWidget* g_fontsel_dialog;
+
+
+void
+on_fontsel_dialog_response             (GtkDialog       *dialog,
+                                        gint             id,
+                                        gpointer         user_data)
+{
+
+	switch(id) {
+		case GTK_RESPONSE_OK:
+		{
+			const char* font = gtk_font_selection_dialog_get_font_name (GTK_FONT_SELECTION_DIALOG(dialog));
+			std::string f = (font ? font : "");
+			set_theme(get_selected_theme(), f);
+			break;
+		}
+//		case GTK_RESPONSE_CANCEL:
+//			gtk_widget_destroy(g_fontsel_dialog);
+//			g_fontsel_dialog = 0;
+//			return;
+
+	}
+	gtk_widget_destroy(g_fontsel_dialog);
+	g_fontsel_dialog = 0;
+
+}
+
+
+gboolean
+on_fontsel_dialog_delete_event         (GtkWidget       *widget,
+                                        GdkEvent        *event,
+                                        gpointer         user_data)
+{
+	gtk_widget_destroy(g_fontsel_dialog);
+	g_fontsel_dialog = 0;
+
+	return FALSE;
+}
+
+
+void
+on_main_fontselectbutton_clicked       (GtkButton       *button,
+                                        gpointer         user_data)
+{
+	g_fontsel_dialog = create_fontsel_dialog();
+	gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(g_fontsel_dialog), get_current_font().c_str());
+	gtk_widget_show(g_fontsel_dialog);
+}
+*/
+
+
+
+
+
+void
+on_main_ok_button_clicked              (GtkButton       *button,
+                                        gpointer         user_data)
+{
+	if (save_current_theme())
+		gtk_main_quit();
+}
+
+
+void
+on_main_cancel_button_clicked          (GtkButton       *button,
+                                        gpointer         user_data)
+{
+	gtk_main_quit();
+}
+
+
+void
+on_main_reset_button_clicked           (GtkButton       *button,
+                                        gpointer         user_data)
+{
+	set_theme(get_orig_theme(), get_orig_font());
+}
+
+
+gboolean
+on_main_window_delete_event            (GtkWidget       *widget,
+                                        GdkEvent        *event,
+                                        gpointer         user_data)
+{
+	program_shutdown();
+	return true;
+}
+
+
+void
+on_main_use_default_font_radio_toggled (GtkToggleButton *togglebutton,
+                                        gpointer         user_data)
+{
+	bool default_font = gtk_toggle_button_get_active(togglebutton);
+
+	gtk_widget_set_sensitive(lookup_widget(g_main_window, "main_font_selector_button"), !default_font);
+
+	apply_theme(get_selected_theme(), get_selected_font());
+}
+
+
+void
+on_main_font_selector_button_font_set  (GtkFontButton   *fontbutton,
+                                        gpointer         user_data)
+{
+	apply_theme(get_selected_theme(), get_selected_font());
+}
+
+
+void
+on_new2_activate                       (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+
+}
+
+
+void
+on_open2_activate                      (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+
+}
+
+
+void
+on_save2_activate                      (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+
+}
+
+
+void
+on_save_as2_activate                   (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+
+}
+
+
+void
+on_quit2_activate                      (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+
+}
+
+
+void
+on_cut2_activate                       (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+
+}
+
+
+void
+on_copy2_activate                      (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+
+}
+
+
+void
+on_paste2_activate                     (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+
+}
+
+
+void
+on_delete2_activate                    (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+
+}
+
+
+void
+on_about2_activate                     (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+
+}
+
diff --git a/src/gtk2-prefs/callbacks.h b/src/gtk2-prefs/callbacks.h
new file mode 100644
index 00000000..5759aebc
--- /dev/null
+++ b/src/gtk2-prefs/callbacks.h
@@ -0,0 +1,71 @@
+#include <gtk/gtk.h>
+
+
+void
+on_main_showpreviewtoggle_toggled               (GtkToggleButton *togglebutton,
+                                        gpointer         user_data);
+
+void
+on_main_ok_button_clicked              (GtkButton       *button,
+                                        gpointer         user_data);
+
+void
+on_main_cancel_button_clicked          (GtkButton       *button,
+                                        gpointer         user_data);
+
+void
+on_main_reset_button_clicked           (GtkButton       *button,
+                                        gpointer         user_data);
+
+gboolean
+on_main_window_delete_event            (GtkWidget       *widget,
+                                        GdkEvent        *event,
+                                        gpointer         user_data);
+
+void
+on_main_use_default_font_radio_toggled (GtkToggleButton *togglebutton,
+                                        gpointer         user_data);
+
+void
+on_main_font_selector_button_font_set  (GtkFontButton   *fontbutton,
+                                        gpointer         user_data);
+
+void
+on_new2_activate                       (GtkMenuItem     *menuitem,
+                                        gpointer         user_data);
+
+void
+on_open2_activate                      (GtkMenuItem     *menuitem,
+                                        gpointer         user_data);
+
+void
+on_save2_activate                      (GtkMenuItem     *menuitem,
+                                        gpointer         user_data);
+
+void
+on_save_as2_activate                   (GtkMenuItem     *menuitem,
+                                        gpointer         user_data);
+
+void
+on_quit2_activate                      (GtkMenuItem     *menuitem,
+                                        gpointer         user_data);
+
+void
+on_cut2_activate                       (GtkMenuItem     *menuitem,
+                                        gpointer         user_data);
+
+void
+on_copy2_activate                      (GtkMenuItem     *menuitem,
+                                        gpointer         user_data);
+
+void
+on_paste2_activate                     (GtkMenuItem     *menuitem,
+                                        gpointer         user_data);
+
+void
+on_delete2_activate                    (GtkMenuItem     *menuitem,
+                                        gpointer         user_data);
+
+void
+on_about2_activate                     (GtkMenuItem     *menuitem,
+                                        gpointer         user_data);
diff --git a/src/gtk2-prefs/config.h b/src/gtk2-prefs/config.h
new file mode 100644
index 00000000..4501a33b
--- /dev/null
+++ b/src/gtk2-prefs/config.h
@@ -0,0 +1,59 @@
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#undef HAVE_DLFCN_H
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#undef HAVE_INTTYPES_H
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#undef HAVE_STDINT_H
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#undef HAVE_STDLIB_H
+
+/* Define to 1 if you have the <strings.h> header file. */
+#undef HAVE_STRINGS_H
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#undef HAVE_UNISTD_H
+
+/* For gmessages.h error message */
+#define G_HAVE_ISO_VARARGS
+
+/* For mkdir */
+#define HAVE_DIRECT_H 1
+
+/* Name of package */
+#define PACKAGE gtk2-prefs
+
+/* Define to the address where bug reports for this package should be sent. */
+#undef PACKAGE_BUGREPORT
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME gtk2-prefs
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING gtk2-prefs 0.4.1
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME gtk2-prefs
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION 0.4.1
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Version number of package */
+#define VERSION 0.4.1
diff --git a/src/gtk2-prefs/interface.cpp b/src/gtk2-prefs/interface.cpp
new file mode 100644
index 00000000..7c1cc53c
--- /dev/null
+++ b/src/gtk2-prefs/interface.cpp
@@ -0,0 +1,836 @@
+/*
+ * DO NOT EDIT THIS FILE - it is generated by Glade.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <string.h>
+#include <stdio.h>
+
+#include <gdk/gdkkeysyms.h>
+#include <gtk/gtk.h>
+
+#include "callbacks.h"
+#include "interface.h"
+#include "support.h"
+
+#define GLADE_HOOKUP_OBJECT(component,widget,name) \
+  g_object_set_data_full (G_OBJECT (component), name, \
+    gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref)
+
+#define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \
+  g_object_set_data (G_OBJECT (component), name, widget)
+
+GtkWidget*
+create_main_window (void)
+{
+  GtkWidget *main_window;
+  GtkWidget *main_hbox;
+  GtkWidget *vbox1;
+  GtkWidget *hbox1;
+  GtkWidget *frame2;
+  GtkWidget *alignment3;
+  GtkWidget *scrolledwindow3;
+  GtkWidget *main_themelist;
+  GtkWidget *label1234;
+  GtkWidget *frame3;
+  GtkWidget *alignment4;
+  GtkWidget *vbox7;
+  GtkWidget *hbox8;
+  GtkWidget *vbox9;
+  GtkWidget *main_use_default_font_radio;
+  GSList *main_use_default_font_radio_group = NULL;
+  GtkWidget *main_use_custom_font_radio;
+  GtkWidget *alignment5;
+  GtkWidget *vbox10;
+  GtkWidget *hbox9;
+  GtkWidget *vbox11;
+  GtkWidget *main_font_selector_button;
+  GtkWidget *label669;
+  GtkWidget *vbox13;
+  GtkWidget *hbox6666;
+  GtkWidget *main_use_system_config_checkbutton;
+  GtkWidget *main_showpreviewtoggle;
+  GtkWidget *hbuttonbox1;
+  GtkWidget *hbox7;
+  GtkWidget *hbox6665;
+  GtkWidget *image2;
+  GtkWidget *label2;
+  GtkWidget *vbox6;
+  GtkWidget *hbox5;
+  GtkWidget *main_ok_button;
+  GtkWidget *main_cancel_button;
+  GtkWidget *main_reset_button;
+  GtkWidget *alignment2;
+  GtkWidget *hbox6;
+  GtkWidget *image1;
+  GtkWidget *label667;
+  GtkWidget *main_previewhbox;
+  GtkWidget *vseparator2;
+  GtkWidget *frame4;
+  GtkWidget *alignment6;
+  GtkWidget *vbox12;
+  GtkWidget *main_previewbook;
+  GtkWidget *table1;
+  GtkWidget *vbox2;
+  GtkWidget *checkbutton1;
+  GtkWidget *checkbutton2;
+  GtkWidget *button4;
+  GtkWidget *togglebutton1;
+  GtkObject *spinbutton1_adj;
+  GtkWidget *spinbutton1;
+  GtkWidget *vbox4;
+  GtkWidget *menubar2;
+  GtkWidget *menuitem5;
+  GtkWidget *menuitem5_menu;
+  GtkWidget *new2;
+  GtkWidget *open2;
+  GtkWidget *save2;
+  GtkWidget *save_as2;
+  GtkWidget *separatormenuitem2;
+  GtkWidget *quit2;
+  GtkWidget *menuitem6;
+  GtkWidget *menuitem6_menu;
+  GtkWidget *cut2;
+  GtkWidget *copy2;
+  GtkWidget *paste2;
+  GtkWidget *delete2;
+  GtkWidget *menuitem8;
+  GtkWidget *menuitem8_menu;
+  GtkWidget *about2;
+  GtkWidget *combobox1;
+  GtkWidget *comboboxentry1;
+  GtkWidget *hscale1;
+  GtkWidget *scrolledwindow1;
+  GtkWidget *preview_treeview;
+  GtkWidget *statusbar1;
+  GtkWidget *progressbar1;
+  GtkWidget *vseparator1;
+  GtkWidget *frame1;
+  GtkWidget *vbox3;
+  GtkWidget *radiobutton1;
+  GSList *radiobutton1_group = NULL;
+  GtkWidget *radiobutton2;
+  GtkWidget *radiobutton3;
+  GtkWidget *label6;
+  GtkWidget *label4;
+  GtkWidget *scrolledwindow2;
+  GtkWidget *textview1;
+  GtkWidget *label5;
+  GtkWidget *vbox5;
+  GtkWidget *hbox4;
+  GtkWidget *about_label;
+  GtkWidget *label666;
+  GtkWidget *label670;
+  GtkAccelGroup *accel_group;
+  GtkTooltips *tooltips;
+
+  tooltips = gtk_tooltips_new ();
+
+  accel_group = gtk_accel_group_new ();
+
+  main_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+  gtk_widget_set_name (main_window, "main_window");
+  gtk_window_set_title (GTK_WINDOW (main_window), "GTK+ Preference Tool");
+
+  main_hbox = gtk_hbox_new (FALSE, 0);
+  gtk_widget_set_name (main_hbox, "main_hbox");
+  gtk_widget_show (main_hbox);
+  gtk_container_add (GTK_CONTAINER (main_window), main_hbox);
+  gtk_widget_set_size_request (main_hbox, 310, 320);
+
+  vbox1 = gtk_vbox_new (FALSE, 0);
+  gtk_widget_set_name (vbox1, "vbox1");
+  gtk_widget_show (vbox1);
+  gtk_box_pack_start (GTK_BOX (main_hbox), vbox1, TRUE, TRUE, 0);
+  gtk_container_set_border_width (GTK_CONTAINER (vbox1), 3);
+
+  hbox1 = gtk_hbox_new (FALSE, 0);
+  gtk_widget_set_name (hbox1, "hbox1");
+  gtk_widget_show (hbox1);
+  gtk_box_pack_start (GTK_BOX (vbox1), hbox1, TRUE, TRUE, 0);
+
+  frame2 = gtk_frame_new (NULL);
+  gtk_widget_set_name (frame2, "frame2");
+  gtk_widget_show (frame2);
+  gtk_box_pack_start (GTK_BOX (hbox1), frame2, TRUE, TRUE, 0);
+  gtk_frame_set_shadow_type (GTK_FRAME (frame2), GTK_SHADOW_NONE);
+
+  alignment3 = gtk_alignment_new (0.5, 0.5, 1, 1);
+  gtk_widget_set_name (alignment3, "alignment3");
+  gtk_widget_show (alignment3);
+  gtk_container_add (GTK_CONTAINER (frame2), alignment3);
+  gtk_alignment_set_padding (GTK_ALIGNMENT (alignment3), 0, 0, 12, 0);
+
+  scrolledwindow3 = gtk_scrolled_window_new (NULL, NULL);
+  gtk_widget_set_name (scrolledwindow3, "scrolledwindow3");
+  gtk_widget_show (scrolledwindow3);
+  gtk_container_add (GTK_CONTAINER (alignment3), scrolledwindow3);
+  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow3), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow3), GTK_SHADOW_IN);
+
+  main_themelist = gtk_tree_view_new ();
+  gtk_widget_set_name (main_themelist, "main_themelist");
+  gtk_widget_show (main_themelist);
+  gtk_container_add (GTK_CONTAINER (scrolledwindow3), main_themelist);
+  GTK_WIDGET_SET_FLAGS (main_themelist, GTK_CAN_DEFAULT);
+  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (main_themelist), FALSE);
+
+  label1234 = gtk_label_new ("<b>Theme</b>");
+  gtk_widget_set_name (label1234, "label1234");
+  gtk_widget_show (label1234);
+  gtk_frame_set_label_widget (GTK_FRAME (frame2), label1234);
+  gtk_label_set_use_markup (GTK_LABEL (label1234), TRUE);
+
+  frame3 = gtk_frame_new (NULL);
+  gtk_widget_set_name (frame3, "frame3");
+  gtk_widget_show (frame3);
+  gtk_box_pack_start (GTK_BOX (vbox1), frame3, FALSE, FALSE, 9);
+  gtk_frame_set_shadow_type (GTK_FRAME (frame3), GTK_SHADOW_NONE);
+
+  alignment4 = gtk_alignment_new (0.5, 0.5, 1, 1);
+  gtk_widget_set_name (alignment4, "alignment4");
+  gtk_widget_show (alignment4);
+  gtk_container_add (GTK_CONTAINER (frame3), alignment4);
+  gtk_alignment_set_padding (GTK_ALIGNMENT (alignment4), 0, 0, 12, 0);
+
+  vbox7 = gtk_vbox_new (FALSE, 0);
+  gtk_widget_set_name (vbox7, "vbox7");
+  gtk_widget_show (vbox7);
+  gtk_container_add (GTK_CONTAINER (alignment4), vbox7);
+
+  hbox8 = gtk_hbox_new (FALSE, 0);
+  gtk_widget_set_name (hbox8, "hbox8");
+  gtk_widget_show (hbox8);
+  gtk_box_pack_start (GTK_BOX (vbox7), hbox8, FALSE, FALSE, 0);
+
+  vbox9 = gtk_vbox_new (FALSE, 0);
+  gtk_widget_set_name (vbox9, "vbox9");
+  gtk_widget_show (vbox9);
+  gtk_box_pack_start (GTK_BOX (hbox8), vbox9, TRUE, TRUE, 0);
+
+  main_use_default_font_radio = gtk_radio_button_new_with_mnemonic (NULL, "Use theme default font");
+  gtk_widget_set_name (main_use_default_font_radio, "main_use_default_font_radio");
+  gtk_widget_show (main_use_default_font_radio);
+  gtk_box_pack_start (GTK_BOX (vbox9), main_use_default_font_radio, FALSE, FALSE, 0);
+  gtk_radio_button_set_group (GTK_RADIO_BUTTON (main_use_default_font_radio), main_use_default_font_radio_group);
+  main_use_default_font_radio_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (main_use_default_font_radio));
+
+  main_use_custom_font_radio = gtk_radio_button_new_with_mnemonic (NULL, "Use custom font:");
+  gtk_widget_set_name (main_use_custom_font_radio, "main_use_custom_font_radio");
+  gtk_widget_show (main_use_custom_font_radio);
+  gtk_box_pack_start (GTK_BOX (vbox9), main_use_custom_font_radio, FALSE, FALSE, 0);
+  gtk_radio_button_set_group (GTK_RADIO_BUTTON (main_use_custom_font_radio), main_use_default_font_radio_group);
+  main_use_default_font_radio_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (main_use_custom_font_radio));
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (main_use_custom_font_radio), TRUE);
+
+  alignment5 = gtk_alignment_new (0.5, 0.5, 1, 1);
+  gtk_widget_set_name (alignment5, "alignment5");
+  gtk_widget_show (alignment5);
+  gtk_box_pack_start (GTK_BOX (vbox9), alignment5, TRUE, TRUE, 0);
+  gtk_alignment_set_padding (GTK_ALIGNMENT (alignment5), 0, 0, 12, 0);
+
+  vbox10 = gtk_vbox_new (FALSE, 0);
+  gtk_widget_set_name (vbox10, "vbox10");
+  gtk_widget_show (vbox10);
+  gtk_container_add (GTK_CONTAINER (alignment5), vbox10);
+
+  hbox9 = gtk_hbox_new (FALSE, 0);
+  gtk_widget_set_name (hbox9, "hbox9");
+  gtk_widget_show (hbox9);
+  gtk_box_pack_start (GTK_BOX (vbox10), hbox9, FALSE, FALSE, 0);
+
+  vbox11 = gtk_vbox_new (FALSE, 0);
+  gtk_widget_set_name (vbox11, "vbox11");
+  gtk_widget_show (vbox11);
+  gtk_box_pack_start (GTK_BOX (hbox9), vbox11, TRUE, TRUE, 0);
+
+  main_font_selector_button = gtk_font_button_new ();
+  gtk_widget_set_name (main_font_selector_button, "main_font_selector_button");
+  gtk_widget_show (main_font_selector_button);
+  gtk_box_pack_start (GTK_BOX (vbox11), main_font_selector_button, FALSE, FALSE, 0);
+
+  label669 = gtk_label_new ("<b>Font</b>");
+  gtk_widget_set_name (label669, "label669");
+  gtk_widget_show (label669);
+  gtk_frame_set_label_widget (GTK_FRAME (frame3), label669);
+  gtk_label_set_use_markup (GTK_LABEL (label669), TRUE);
+
+  vbox13 = gtk_vbox_new (FALSE, 0);
+  gtk_widget_set_name (vbox13, "vbox13");
+  gtk_widget_show (vbox13);
+  gtk_box_pack_start (GTK_BOX (vbox1), vbox13, FALSE, FALSE, 0);
+
+  hbox6666 = gtk_hbox_new (FALSE, 0);
+  gtk_widget_set_name (hbox6666, "hbox6666");
+  gtk_widget_show (hbox6666);
+  gtk_box_pack_start (GTK_BOX (vbox13), hbox6666, TRUE, TRUE, 0);
+
+  /* main_use_system_config_checkbutton = gtk_check_button_new_with_mnemonic ("Apply for all users");
+  gtk_widget_set_name (main_use_system_config_checkbutton, "main_use_system_config_checkbutton");
+  gtk_widget_show (main_use_system_config_checkbutton);
+  gtk_box_pack_start (GTK_BOX (hbox6666), main_use_system_config_checkbutton, FALSE, FALSE, 12);
+  gtk_tooltips_set_tip (tooltips, main_use_system_config_checkbutton, "If this is enabled, the program will update the system-wide configuration file. NOT RECOMMENDED!", NULL); */
+
+  main_showpreviewtoggle = gtk_toggle_button_new_with_mnemonic ("Show preview >>");
+  gtk_widget_set_name (main_showpreviewtoggle, "main_showpreviewtoggle");
+  gtk_widget_show (main_showpreviewtoggle);
+  gtk_box_pack_end (GTK_BOX (hbox6666), main_showpreviewtoggle, FALSE, FALSE, 2);
+
+  hbuttonbox1 = gtk_hbutton_box_new ();
+  gtk_widget_set_name (hbuttonbox1, "hbuttonbox1");
+  gtk_widget_show (hbuttonbox1);
+  gtk_box_pack_start (GTK_BOX (vbox1), hbuttonbox1, FALSE, FALSE, 0);
+
+  hbox7 = gtk_hbox_new (FALSE, 0);
+  gtk_widget_set_name (hbox7, "hbox7");
+  gtk_widget_show (hbox7);
+  gtk_box_pack_start (GTK_BOX (vbox1), hbox7, FALSE, TRUE, 6);
+
+  hbox6665 = gtk_hbox_new (FALSE, 0);
+  gtk_widget_set_name (hbox6665, "hbox6665");
+  gtk_widget_show (hbox6665);
+  gtk_box_pack_start (GTK_BOX (hbox7), hbox6665, TRUE, FALSE, 0);
+
+  image2 = gtk_image_new_from_stock ("gtk-dialog-info", GTK_ICON_SIZE_LARGE_TOOLBAR);
+  gtk_widget_set_name (image2, "image2");
+  gtk_widget_show (image2);
+  gtk_box_pack_start (GTK_BOX (hbox6665), image2, FALSE, FALSE, 0);
+
+  label2 = gtk_label_new ("You should restart XChat-WDK\nfor this change to take effect.");
+  gtk_widget_set_name (label2, "label2");
+  gtk_widget_show (label2);
+  gtk_box_pack_start (GTK_BOX (hbox6665), label2, FALSE, FALSE, 0);
+  gtk_label_set_line_wrap (GTK_LABEL (label2), TRUE);
+  gtk_misc_set_alignment (GTK_MISC (label2), 0, 0.5);
+
+  vbox6 = gtk_vbox_new (FALSE, 0);
+  gtk_widget_set_name (vbox6, "vbox6");
+  gtk_widget_show (vbox6);
+  gtk_box_pack_start (GTK_BOX (vbox1), vbox6, FALSE, FALSE, 0);
+
+  hbox5 = gtk_hbox_new (TRUE, 0);
+  gtk_widget_set_name (hbox5, "hbox5");
+  gtk_widget_show (hbox5);
+  gtk_box_pack_start (GTK_BOX (vbox6), hbox5, FALSE, FALSE, 0);
+  gtk_container_set_border_width (GTK_CONTAINER (hbox5), 4);
+
+  main_ok_button = gtk_button_new_from_stock ("gtk-ok");
+  gtk_widget_set_name (main_ok_button, "main_ok_button");
+  gtk_widget_show (main_ok_button);
+  gtk_box_pack_end (GTK_BOX (hbox5), main_ok_button, TRUE, TRUE, 4);
+  GTK_WIDGET_SET_FLAGS (main_ok_button, GTK_CAN_DEFAULT);
+
+  main_cancel_button = gtk_button_new_from_stock ("gtk-cancel");
+  gtk_widget_set_name (main_cancel_button, "main_cancel_button");
+  gtk_widget_show (main_cancel_button);
+  gtk_box_pack_end (GTK_BOX (hbox5), main_cancel_button, TRUE, TRUE, 4);
+  GTK_WIDGET_SET_FLAGS (main_cancel_button, GTK_CAN_DEFAULT);
+
+  main_reset_button = gtk_button_new ();
+  gtk_widget_set_name (main_reset_button, "main_reset_button");
+  gtk_widget_show (main_reset_button);
+  gtk_box_pack_end (GTK_BOX (hbox5), main_reset_button, TRUE, TRUE, 4);
+
+  alignment2 = gtk_alignment_new (0.5, 0.5, 0, 0);
+  gtk_widget_set_name (alignment2, "alignment2");
+  gtk_widget_show (alignment2);
+  gtk_container_add (GTK_CONTAINER (main_reset_button), alignment2);
+
+  hbox6 = gtk_hbox_new (FALSE, 2);
+  gtk_widget_set_name (hbox6, "hbox6");
+  gtk_widget_show (hbox6);
+  gtk_container_add (GTK_CONTAINER (alignment2), hbox6);
+
+  image1 = gtk_image_new_from_stock ("gtk-revert-to-saved", GTK_ICON_SIZE_BUTTON);
+  gtk_widget_set_name (image1, "image1");
+  gtk_widget_show (image1);
+  gtk_box_pack_start (GTK_BOX (hbox6), image1, FALSE, FALSE, 0);
+
+  label667 = gtk_label_new_with_mnemonic ("_Reset");
+  gtk_widget_set_name (label667, "label667");
+  gtk_widget_show (label667);
+  gtk_box_pack_start (GTK_BOX (hbox6), label667, FALSE, FALSE, 0);
+
+  main_previewhbox = gtk_hbox_new (FALSE, 0);
+  gtk_widget_set_name (main_previewhbox, "main_previewhbox");
+  gtk_box_pack_start (GTK_BOX (main_hbox), main_previewhbox, TRUE, TRUE, 0);
+
+  vseparator2 = gtk_vseparator_new ();
+  gtk_widget_set_name (vseparator2, "vseparator2");
+  gtk_widget_show (vseparator2);
+  gtk_box_pack_start (GTK_BOX (main_previewhbox), vseparator2, FALSE, TRUE, 4);
+
+  frame4 = gtk_frame_new (NULL);
+  gtk_widget_set_name (frame4, "frame4");
+  gtk_widget_show (frame4);
+  gtk_box_pack_start (GTK_BOX (main_previewhbox), frame4, TRUE, TRUE, 0);
+  gtk_container_set_border_width (GTK_CONTAINER (frame4), 3);
+  gtk_frame_set_shadow_type (GTK_FRAME (frame4), GTK_SHADOW_NONE);
+
+  alignment6 = gtk_alignment_new (0.5, 0.5, 1, 1);
+  gtk_widget_set_name (alignment6, "alignment6");
+  gtk_widget_show (alignment6);
+  gtk_container_add (GTK_CONTAINER (frame4), alignment6);
+
+  vbox12 = gtk_vbox_new (FALSE, 0);
+  gtk_widget_set_name (vbox12, "vbox12");
+  gtk_widget_show (vbox12);
+  gtk_container_add (GTK_CONTAINER (alignment6), vbox12);
+
+  main_previewbook = gtk_notebook_new ();
+  gtk_widget_set_name (main_previewbook, "main_previewbook");
+  gtk_widget_show (main_previewbook);
+  gtk_box_pack_start (GTK_BOX (vbox12), main_previewbook, TRUE, TRUE, 0);
+
+  table1 = gtk_table_new (3, 3, FALSE);
+  gtk_widget_set_name (table1, "table1");
+  gtk_widget_show (table1);
+  gtk_container_add (GTK_CONTAINER (main_previewbook), table1);
+  gtk_container_set_border_width (GTK_CONTAINER (table1), 5);
+
+  vbox2 = gtk_vbox_new (FALSE, 4);
+  gtk_widget_set_name (vbox2, "vbox2");
+  gtk_widget_show (vbox2);
+  gtk_table_attach (GTK_TABLE (table1), vbox2, 0, 1, 0, 1,
+                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
+                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);
+
+  checkbutton1 = gtk_check_button_new_with_mnemonic ("check button 1");
+  gtk_widget_set_name (checkbutton1, "checkbutton1");
+  gtk_widget_show (checkbutton1);
+  gtk_box_pack_start (GTK_BOX (vbox2), checkbutton1, FALSE, FALSE, 0);
+
+  checkbutton2 = gtk_check_button_new_with_mnemonic ("check button 2");
+  gtk_widget_set_name (checkbutton2, "checkbutton2");
+  gtk_widget_show (checkbutton2);
+  gtk_box_pack_start (GTK_BOX (vbox2), checkbutton2, FALSE, FALSE, 0);
+
+  button4 = gtk_button_new_with_mnemonic ("button");
+  gtk_widget_set_name (button4, "button4");
+  gtk_widget_show (button4);
+  gtk_box_pack_start (GTK_BOX (vbox2), button4, FALSE, FALSE, 0);
+
+  togglebutton1 = gtk_toggle_button_new_with_mnemonic ("toggle button");
+  gtk_widget_set_name (togglebutton1, "togglebutton1");
+  gtk_widget_show (togglebutton1);
+  gtk_box_pack_start (GTK_BOX (vbox2), togglebutton1, FALSE, FALSE, 0);
+
+  spinbutton1_adj = gtk_adjustment_new (0, 0, 100, 1, 10, 10);
+  spinbutton1 = gtk_spin_button_new (GTK_ADJUSTMENT (spinbutton1_adj), 1, 0);
+  gtk_widget_set_name (spinbutton1, "spinbutton1");
+  gtk_widget_show (spinbutton1);
+  gtk_box_pack_start (GTK_BOX (vbox2), spinbutton1, FALSE, FALSE, 0);
+
+  vbox4 = gtk_vbox_new (FALSE, 4);
+  gtk_widget_set_name (vbox4, "vbox4");
+  gtk_widget_show (vbox4);
+  gtk_table_attach (GTK_TABLE (table1), vbox4, 2, 3, 0, 1,
+                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
+                    (GtkAttachOptions) (GTK_FILL), 0, 0);
+
+  menubar2 = gtk_menu_bar_new ();
+  gtk_widget_set_name (menubar2, "menubar2");
+  gtk_widget_show (menubar2);
+  gtk_box_pack_start (GTK_BOX (vbox4), menubar2, FALSE, FALSE, 0);
+
+  menuitem5 = gtk_menu_item_new_with_mnemonic ("_File");
+  gtk_widget_set_name (menuitem5, "menuitem5");
+  gtk_widget_show (menuitem5);
+  gtk_container_add (GTK_CONTAINER (menubar2), menuitem5);
+
+  menuitem5_menu = gtk_menu_new ();
+  gtk_widget_set_name (menuitem5_menu, "menuitem5_menu");
+  gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem5), menuitem5_menu);
+
+  new2 = gtk_image_menu_item_new_from_stock ("gtk-new", accel_group);
+  gtk_widget_set_name (new2, "new2");
+  gtk_widget_show (new2);
+  gtk_container_add (GTK_CONTAINER (menuitem5_menu), new2);
+
+  open2 = gtk_image_menu_item_new_from_stock ("gtk-open", accel_group);
+  gtk_widget_set_name (open2, "open2");
+  gtk_widget_show (open2);
+  gtk_container_add (GTK_CONTAINER (menuitem5_menu), open2);
+
+  save2 = gtk_image_menu_item_new_from_stock ("gtk-save", accel_group);
+  gtk_widget_set_name (save2, "save2");
+  gtk_widget_show (save2);
+  gtk_container_add (GTK_CONTAINER (menuitem5_menu), save2);
+
+  save_as2 = gtk_image_menu_item_new_from_stock ("gtk-save-as", accel_group);
+  gtk_widget_set_name (save_as2, "save_as2");
+  gtk_widget_show (save_as2);
+  gtk_container_add (GTK_CONTAINER (menuitem5_menu), save_as2);
+
+  separatormenuitem2 = gtk_separator_menu_item_new ();
+  gtk_widget_set_name (separatormenuitem2, "separatormenuitem2");
+  gtk_widget_show (separatormenuitem2);
+  gtk_container_add (GTK_CONTAINER (menuitem5_menu), separatormenuitem2);
+  gtk_widget_set_sensitive (separatormenuitem2, FALSE);
+
+  quit2 = gtk_image_menu_item_new_from_stock ("gtk-quit", accel_group);
+  gtk_widget_set_name (quit2, "quit2");
+  gtk_widget_show (quit2);
+  gtk_container_add (GTK_CONTAINER (menuitem5_menu), quit2);
+
+  menuitem6 = gtk_menu_item_new_with_mnemonic ("_Edit");
+  gtk_widget_set_name (menuitem6, "menuitem6");
+  gtk_widget_show (menuitem6);
+  gtk_container_add (GTK_CONTAINER (menubar2), menuitem6);
+
+  menuitem6_menu = gtk_menu_new ();
+  gtk_widget_set_name (menuitem6_menu, "menuitem6_menu");
+  gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem6), menuitem6_menu);
+
+  cut2 = gtk_image_menu_item_new_from_stock ("gtk-cut", accel_group);
+  gtk_widget_set_name (cut2, "cut2");
+  gtk_widget_show (cut2);
+  gtk_container_add (GTK_CONTAINER (menuitem6_menu), cut2);
+
+  copy2 = gtk_image_menu_item_new_from_stock ("gtk-copy", accel_group);
+  gtk_widget_set_name (copy2, "copy2");
+  gtk_widget_show (copy2);
+  gtk_container_add (GTK_CONTAINER (menuitem6_menu), copy2);
+
+  paste2 = gtk_image_menu_item_new_from_stock ("gtk-paste", accel_group);
+  gtk_widget_set_name (paste2, "paste2");
+  gtk_widget_show (paste2);
+  gtk_container_add (GTK_CONTAINER (menuitem6_menu), paste2);
+
+  delete2 = gtk_image_menu_item_new_from_stock ("gtk-delete", accel_group);
+  gtk_widget_set_name (delete2, "delete2");
+  gtk_widget_show (delete2);
+  gtk_container_add (GTK_CONTAINER (menuitem6_menu), delete2);
+
+  menuitem8 = gtk_menu_item_new_with_mnemonic ("_Help");
+  gtk_widget_set_name (menuitem8, "menuitem8");
+  gtk_widget_show (menuitem8);
+  gtk_container_add (GTK_CONTAINER (menubar2), menuitem8);
+
+  menuitem8_menu = gtk_menu_new ();
+  gtk_widget_set_name (menuitem8_menu, "menuitem8_menu");
+  gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem8), menuitem8_menu);
+
+  about2 = gtk_menu_item_new_with_mnemonic ("_About");
+  gtk_widget_set_name (about2, "about2");
+  gtk_widget_show (about2);
+  gtk_container_add (GTK_CONTAINER (menuitem8_menu), about2);
+
+  combobox1 = gtk_combo_box_new_text ();
+  gtk_widget_set_name (combobox1, "combobox1");
+  gtk_widget_show (combobox1);
+  gtk_box_pack_start (GTK_BOX (vbox4), combobox1, FALSE, FALSE, 0);
+  gtk_combo_box_append_text (GTK_COMBO_BOX (combobox1), "item 1");
+  gtk_combo_box_append_text (GTK_COMBO_BOX (combobox1), "item 2");
+  gtk_combo_box_append_text (GTK_COMBO_BOX (combobox1), "item 3");
+
+  comboboxentry1 = gtk_combo_box_entry_new_text ();
+  gtk_widget_set_name (comboboxentry1, "comboboxentry1");
+  gtk_widget_show (comboboxentry1);
+  gtk_box_pack_start (GTK_BOX (vbox4), comboboxentry1, FALSE, FALSE, 0);
+  gtk_widget_set_size_request (comboboxentry1, 80, 25);
+  gtk_combo_box_append_text (GTK_COMBO_BOX (comboboxentry1), "item 1");
+  gtk_combo_box_append_text (GTK_COMBO_BOX (comboboxentry1), "item 2");
+  gtk_combo_box_append_text (GTK_COMBO_BOX (comboboxentry1), "item 3");
+
+  hscale1 = gtk_hscale_new (GTK_ADJUSTMENT (gtk_adjustment_new (15, 0, 50, 1, 0, 0)));
+  gtk_widget_set_name (hscale1, "hscale1");
+  gtk_widget_show (hscale1);
+  gtk_box_pack_start (GTK_BOX (vbox4), hscale1, TRUE, TRUE, 0);
+  gtk_scale_set_digits (GTK_SCALE (hscale1), 0);
+
+  scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
+  gtk_widget_set_name (scrolledwindow1, "scrolledwindow1");
+  gtk_widget_show (scrolledwindow1);
+  gtk_table_attach (GTK_TABLE (table1), scrolledwindow1, 2, 3, 1, 2,
+                    (GtkAttachOptions) (GTK_FILL),
+                    (GtkAttachOptions) (GTK_FILL), 0, 0);
+
+  preview_treeview = gtk_tree_view_new ();
+  gtk_widget_set_name (preview_treeview, "preview_treeview");
+  gtk_widget_show (preview_treeview);
+  gtk_container_add (GTK_CONTAINER (scrolledwindow1), preview_treeview);
+  gtk_tree_view_set_reorderable (GTK_TREE_VIEW (preview_treeview), TRUE);
+
+  statusbar1 = gtk_statusbar_new ();
+  gtk_widget_set_name (statusbar1, "statusbar1");
+  gtk_widget_show (statusbar1);
+  gtk_table_attach (GTK_TABLE (table1), statusbar1, 1, 3, 2, 3,
+                    (GtkAttachOptions) (GTK_FILL),
+                    (GtkAttachOptions) (0), 0, 0);
+  gtk_widget_set_size_request (statusbar1, 6, 20);
+
+  progressbar1 = gtk_progress_bar_new ();
+  gtk_widget_set_name (progressbar1, "progressbar1");
+  gtk_widget_show (progressbar1);
+  gtk_table_attach (GTK_TABLE (table1), progressbar1, 0, 1, 2, 3,
+                    (GtkAttachOptions) (GTK_FILL),
+                    (GtkAttachOptions) (0), 0, 0);
+  gtk_widget_set_size_request (progressbar1, 80, 20);
+  gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progressbar1), 0.56);
+  gtk_progress_bar_set_text (GTK_PROGRESS_BAR (progressbar1), "56%");
+
+  vseparator1 = gtk_vseparator_new ();
+  gtk_widget_set_name (vseparator1, "vseparator1");
+  gtk_widget_show (vseparator1);
+  gtk_table_attach (GTK_TABLE (table1), vseparator1, 1, 2, 0, 2,
+                    (GtkAttachOptions) (GTK_FILL),
+                    (GtkAttachOptions) (GTK_FILL), 5, 0);
+
+  frame1 = gtk_frame_new (NULL);
+  gtk_widget_set_name (frame1, "frame1");
+  gtk_widget_show (frame1);
+  gtk_table_attach (GTK_TABLE (table1), frame1, 0, 1, 1, 2,
+                    (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
+                    (GtkAttachOptions) (GTK_EXPAND), 0, 0);
+  gtk_frame_set_label_align (GTK_FRAME (frame1), 0.5, 0.5);
+
+  vbox3 = gtk_vbox_new (FALSE, 0);
+  gtk_widget_set_name (vbox3, "vbox3");
+  gtk_widget_show (vbox3);
+  gtk_container_add (GTK_CONTAINER (frame1), vbox3);
+  gtk_container_set_border_width (GTK_CONTAINER (vbox3), 5);
+
+  radiobutton1 = gtk_radio_button_new_with_mnemonic (NULL, "radio 1");
+  gtk_widget_set_name (radiobutton1, "radiobutton1");
+  gtk_widget_show (radiobutton1);
+  gtk_box_pack_start (GTK_BOX (vbox3), radiobutton1, FALSE, FALSE, 0);
+  gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobutton1), radiobutton1_group);
+  radiobutton1_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton1));
+
+  radiobutton2 = gtk_radio_button_new_with_mnemonic (NULL, "radio 2");
+  gtk_widget_set_name (radiobutton2, "radiobutton2");
+  gtk_widget_show (radiobutton2);
+  gtk_box_pack_start (GTK_BOX (vbox3), radiobutton2, FALSE, FALSE, 0);
+  gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobutton2), radiobutton1_group);
+  radiobutton1_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton2));
+
+  radiobutton3 = gtk_radio_button_new_with_mnemonic (NULL, "radio 3");
+  gtk_widget_set_name (radiobutton3, "radiobutton3");
+  gtk_widget_show (radiobutton3);
+  gtk_box_pack_start (GTK_BOX (vbox3), radiobutton3, FALSE, FALSE, 0);
+  gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobutton3), radiobutton1_group);
+  radiobutton1_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton3));
+
+  label6 = gtk_label_new ("frame");
+  gtk_widget_set_name (label6, "label6");
+  gtk_widget_show (label6);
+  gtk_frame_set_label_widget (GTK_FRAME (frame1), label6);
+  gtk_misc_set_padding (GTK_MISC (label6), 1, 0);
+
+  label4 = gtk_label_new ("Common widgets");
+  gtk_widget_set_name (label4, "label4");
+  gtk_widget_show (label4);
+  gtk_notebook_set_tab_label (GTK_NOTEBOOK (main_previewbook), gtk_notebook_get_nth_page (GTK_NOTEBOOK (main_previewbook), 0), label4);
+
+  scrolledwindow2 = gtk_scrolled_window_new (NULL, NULL);
+  gtk_widget_set_name (scrolledwindow2, "scrolledwindow2");
+  gtk_widget_show (scrolledwindow2);
+  gtk_container_add (GTK_CONTAINER (main_previewbook), scrolledwindow2);
+
+  textview1 = gtk_text_view_new ();
+  gtk_widget_set_name (textview1, "textview1");
+  gtk_widget_show (textview1);
+  gtk_container_add (GTK_CONTAINER (scrolledwindow2), textview1);
+  gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (textview1), GTK_WRAP_WORD);
+  gtk_text_view_set_left_margin (GTK_TEXT_VIEW (textview1), 8);
+  gtk_text_view_set_right_margin (GTK_TEXT_VIEW (textview1), 8);
+  gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview1)), "You can type some text here.\nYou can also click the right mouse button for a popup menu.", -1);
+
+  label5 = gtk_label_new ("Text area");
+  gtk_widget_set_name (label5, "label5");
+  gtk_widget_show (label5);
+  gtk_notebook_set_tab_label (GTK_NOTEBOOK (main_previewbook), gtk_notebook_get_nth_page (GTK_NOTEBOOK (main_previewbook), 1), label5);
+
+  vbox5 = gtk_vbox_new (FALSE, 0);
+  gtk_widget_set_name (vbox5, "vbox5");
+  gtk_widget_show (vbox5);
+  gtk_container_add (GTK_CONTAINER (main_previewbook), vbox5);
+
+  hbox4 = gtk_hbox_new (FALSE, 0);
+  gtk_widget_set_name (hbox4, "hbox4");
+  gtk_widget_show (hbox4);
+  gtk_box_pack_start (GTK_BOX (vbox5), hbox4, TRUE, TRUE, 0);
+  gtk_container_set_border_width (GTK_CONTAINER (hbox4), 7);
+
+  about_label = gtk_label_new ("");
+  gtk_widget_set_name (about_label, "about_label");
+  gtk_widget_show (about_label);
+  gtk_box_pack_start (GTK_BOX (hbox4), about_label, FALSE, FALSE, 0);
+  gtk_label_set_line_wrap (GTK_LABEL (about_label), TRUE);
+
+  label666 = gtk_label_new ("About");
+  gtk_widget_set_name (label666, "label666");
+  gtk_widget_show (label666);
+  gtk_notebook_set_tab_label (GTK_NOTEBOOK (main_previewbook), gtk_notebook_get_nth_page (GTK_NOTEBOOK (main_previewbook), 2), label666);
+
+  label670 = gtk_label_new ("<b>Preview</b>");
+  gtk_widget_set_name (label670, "label670");
+  gtk_widget_show (label670);
+  gtk_frame_set_label_widget (GTK_FRAME (frame4), label670);
+  gtk_label_set_use_markup (GTK_LABEL (label670), TRUE);
+
+  g_signal_connect ((gpointer) main_window, "delete_event",
+                    G_CALLBACK (on_main_window_delete_event),
+                    NULL);
+  g_signal_connect ((gpointer) main_use_default_font_radio, "toggled",
+                    G_CALLBACK (on_main_use_default_font_radio_toggled),
+                    NULL);
+  g_signal_connect ((gpointer) main_font_selector_button, "font_set",
+                    G_CALLBACK (on_main_font_selector_button_font_set),
+                    NULL);
+  g_signal_connect ((gpointer) main_showpreviewtoggle, "toggled",
+                    G_CALLBACK (on_main_showpreviewtoggle_toggled),
+                    NULL);
+  g_signal_connect ((gpointer) main_ok_button, "clicked",
+                    G_CALLBACK (on_main_ok_button_clicked),
+                    NULL);
+  g_signal_connect ((gpointer) main_cancel_button, "clicked",
+                    G_CALLBACK (on_main_cancel_button_clicked),
+                    NULL);
+  g_signal_connect ((gpointer) main_reset_button, "clicked",
+                    G_CALLBACK (on_main_reset_button_clicked),
+                    NULL);
+  g_signal_connect ((gpointer) new2, "activate",
+                    G_CALLBACK (on_new2_activate),
+                    NULL);
+  g_signal_connect ((gpointer) open2, "activate",
+                    G_CALLBACK (on_open2_activate),
+                    NULL);
+  g_signal_connect ((gpointer) save2, "activate",
+                    G_CALLBACK (on_save2_activate),
+                    NULL);
+  g_signal_connect ((gpointer) save_as2, "activate",
+                    G_CALLBACK (on_save_as2_activate),
+                    NULL);
+  g_signal_connect ((gpointer) quit2, "activate",
+                    G_CALLBACK (on_quit2_activate),
+                    NULL);
+  g_signal_connect ((gpointer) cut2, "activate",
+                    G_CALLBACK (on_cut2_activate),
+                    NULL);
+  g_signal_connect ((gpointer) copy2, "activate",
+                    G_CALLBACK (on_copy2_activate),
+                    NULL);
+  g_signal_connect ((gpointer) paste2, "activate",
+                    G_CALLBACK (on_paste2_activate),
+                    NULL);
+  g_signal_connect ((gpointer) delete2, "activate",
+                    G_CALLBACK (on_delete2_activate),
+                    NULL);
+  g_signal_connect ((gpointer) about2, "activate",
+                    G_CALLBACK (on_about2_activate),
+                    NULL);
+
+  /* Store pointers to all widgets, for use by lookup_widget(). */
+  GLADE_HOOKUP_OBJECT_NO_REF (main_window, main_window, "main_window");
+  GLADE_HOOKUP_OBJECT (main_window, main_hbox, "main_hbox");
+  GLADE_HOOKUP_OBJECT (main_window, vbox1, "vbox1");
+  GLADE_HOOKUP_OBJECT (main_window, hbox1, "hbox1");
+  GLADE_HOOKUP_OBJECT (main_window, frame2, "frame2");
+  GLADE_HOOKUP_OBJECT (main_window, alignment3, "alignment3");
+  GLADE_HOOKUP_OBJECT (main_window, scrolledwindow3, "scrolledwindow3");
+  GLADE_HOOKUP_OBJECT (main_window, main_themelist, "main_themelist");
+  GLADE_HOOKUP_OBJECT (main_window, label1234, "label1234");
+  GLADE_HOOKUP_OBJECT (main_window, frame3, "frame3");
+  GLADE_HOOKUP_OBJECT (main_window, alignment4, "alignment4");
+  GLADE_HOOKUP_OBJECT (main_window, vbox7, "vbox7");
+  GLADE_HOOKUP_OBJECT (main_window, hbox8, "hbox8");
+  GLADE_HOOKUP_OBJECT (main_window, vbox9, "vbox9");
+  GLADE_HOOKUP_OBJECT (main_window, main_use_default_font_radio, "main_use_default_font_radio");
+  GLADE_HOOKUP_OBJECT (main_window, main_use_custom_font_radio, "main_use_custom_font_radio");
+  GLADE_HOOKUP_OBJECT (main_window, alignment5, "alignment5");
+  GLADE_HOOKUP_OBJECT (main_window, vbox10, "vbox10");
+  GLADE_HOOKUP_OBJECT (main_window, hbox9, "hbox9");
+  GLADE_HOOKUP_OBJECT (main_window, vbox11, "vbox11");
+  GLADE_HOOKUP_OBJECT (main_window, main_font_selector_button, "main_font_selector_button");
+  GLADE_HOOKUP_OBJECT (main_window, label669, "label669");
+  GLADE_HOOKUP_OBJECT (main_window, vbox13, "vbox13");
+  GLADE_HOOKUP_OBJECT (main_window, hbox6666, "hbox6666");
+  /* GLADE_HOOKUP_OBJECT (main_window, main_use_system_config_checkbutton, "main_use_system_config_checkbutton"); */
+  GLADE_HOOKUP_OBJECT (main_window, main_showpreviewtoggle, "main_showpreviewtoggle");
+  GLADE_HOOKUP_OBJECT (main_window, hbuttonbox1, "hbuttonbox1");
+  GLADE_HOOKUP_OBJECT (main_window, hbox7, "hbox7");
+  GLADE_HOOKUP_OBJECT (main_window, hbox6665, "hbox6665");
+  GLADE_HOOKUP_OBJECT (main_window, image2, "image2");
+  GLADE_HOOKUP_OBJECT (main_window, label2, "label2");
+  GLADE_HOOKUP_OBJECT (main_window, vbox6, "vbox6");
+  GLADE_HOOKUP_OBJECT (main_window, hbox5, "hbox5");
+  GLADE_HOOKUP_OBJECT (main_window, main_ok_button, "main_ok_button");
+  GLADE_HOOKUP_OBJECT (main_window, main_cancel_button, "main_cancel_button");
+  GLADE_HOOKUP_OBJECT (main_window, main_reset_button, "main_reset_button");
+  GLADE_HOOKUP_OBJECT (main_window, alignment2, "alignment2");
+  GLADE_HOOKUP_OBJECT (main_window, hbox6, "hbox6");
+  GLADE_HOOKUP_OBJECT (main_window, image1, "image1");
+  GLADE_HOOKUP_OBJECT (main_window, label667, "label667");
+  GLADE_HOOKUP_OBJECT (main_window, main_previewhbox, "main_previewhbox");
+  GLADE_HOOKUP_OBJECT (main_window, vseparator2, "vseparator2");
+  GLADE_HOOKUP_OBJECT (main_window, frame4, "frame4");
+  GLADE_HOOKUP_OBJECT (main_window, alignment6, "alignment6");
+  GLADE_HOOKUP_OBJECT (main_window, vbox12, "vbox12");
+  GLADE_HOOKUP_OBJECT (main_window, main_previewbook, "main_previewbook");
+  GLADE_HOOKUP_OBJECT (main_window, table1, "table1");
+  GLADE_HOOKUP_OBJECT (main_window, vbox2, "vbox2");
+  GLADE_HOOKUP_OBJECT (main_window, checkbutton1, "checkbutton1");
+  GLADE_HOOKUP_OBJECT (main_window, checkbutton2, "checkbutton2");
+  GLADE_HOOKUP_OBJECT (main_window, button4, "button4");
+  GLADE_HOOKUP_OBJECT (main_window, togglebutton1, "togglebutton1");
+  GLADE_HOOKUP_OBJECT (main_window, spinbutton1, "spinbutton1");
+  GLADE_HOOKUP_OBJECT (main_window, vbox4, "vbox4");
+  GLADE_HOOKUP_OBJECT (main_window, menubar2, "menubar2");
+  GLADE_HOOKUP_OBJECT (main_window, menuitem5, "menuitem5");
+  GLADE_HOOKUP_OBJECT (main_window, menuitem5_menu, "menuitem5_menu");
+  GLADE_HOOKUP_OBJECT (main_window, new2, "new2");
+  GLADE_HOOKUP_OBJECT (main_window, open2, "open2");
+  GLADE_HOOKUP_OBJECT (main_window, save2, "save2");
+  GLADE_HOOKUP_OBJECT (main_window, save_as2, "save_as2");
+  GLADE_HOOKUP_OBJECT (main_window, separatormenuitem2, "separatormenuitem2");
+  GLADE_HOOKUP_OBJECT (main_window, quit2, "quit2");
+  GLADE_HOOKUP_OBJECT (main_window, menuitem6, "menuitem6");
+  GLADE_HOOKUP_OBJECT (main_window, menuitem6_menu, "menuitem6_menu");
+  GLADE_HOOKUP_OBJECT (main_window, cut2, "cut2");
+  GLADE_HOOKUP_OBJECT (main_window, copy2, "copy2");
+  GLADE_HOOKUP_OBJECT (main_window, paste2, "paste2");
+  GLADE_HOOKUP_OBJECT (main_window, delete2, "delete2");
+  GLADE_HOOKUP_OBJECT (main_window, menuitem8, "menuitem8");
+  GLADE_HOOKUP_OBJECT (main_window, menuitem8_menu, "menuitem8_menu");
+  GLADE_HOOKUP_OBJECT (main_window, about2, "about2");
+  GLADE_HOOKUP_OBJECT (main_window, combobox1, "combobox1");
+  GLADE_HOOKUP_OBJECT (main_window, comboboxentry1, "comboboxentry1");
+  GLADE_HOOKUP_OBJECT (main_window, hscale1, "hscale1");
+  GLADE_HOOKUP_OBJECT (main_window, scrolledwindow1, "scrolledwindow1");
+  GLADE_HOOKUP_OBJECT (main_window, preview_treeview, "preview_treeview");
+  GLADE_HOOKUP_OBJECT (main_window, statusbar1, "statusbar1");
+  GLADE_HOOKUP_OBJECT (main_window, progressbar1, "progressbar1");
+  GLADE_HOOKUP_OBJECT (main_window, vseparator1, "vseparator1");
+  GLADE_HOOKUP_OBJECT (main_window, frame1, "frame1");
+  GLADE_HOOKUP_OBJECT (main_window, vbox3, "vbox3");
+  GLADE_HOOKUP_OBJECT (main_window, radiobutton1, "radiobutton1");
+  GLADE_HOOKUP_OBJECT (main_window, radiobutton2, "radiobutton2");
+  GLADE_HOOKUP_OBJECT (main_window, radiobutton3, "radiobutton3");
+  GLADE_HOOKUP_OBJECT (main_window, label6, "label6");
+  GLADE_HOOKUP_OBJECT (main_window, label4, "label4");
+  GLADE_HOOKUP_OBJECT (main_window, scrolledwindow2, "scrolledwindow2");
+  GLADE_HOOKUP_OBJECT (main_window, textview1, "textview1");
+  GLADE_HOOKUP_OBJECT (main_window, label5, "label5");
+  GLADE_HOOKUP_OBJECT (main_window, vbox5, "vbox5");
+  GLADE_HOOKUP_OBJECT (main_window, hbox4, "hbox4");
+  GLADE_HOOKUP_OBJECT (main_window, about_label, "about_label");
+  GLADE_HOOKUP_OBJECT (main_window, label666, "label666");
+  GLADE_HOOKUP_OBJECT (main_window, label670, "label670");
+  GLADE_HOOKUP_OBJECT_NO_REF (main_window, tooltips, "tooltips");
+
+  gtk_widget_grab_default (main_themelist);
+  gtk_window_add_accel_group (GTK_WINDOW (main_window), accel_group);
+
+  return main_window;
+}
+
diff --git a/src/gtk2-prefs/interface.h b/src/gtk2-prefs/interface.h
new file mode 100644
index 00000000..11c79152
--- /dev/null
+++ b/src/gtk2-prefs/interface.h
@@ -0,0 +1,5 @@
+/*
+ * DO NOT EDIT THIS FILE - it is generated by Glade.
+ */
+
+GtkWidget* create_main_window (void);
diff --git a/src/gtk2-prefs/main.cpp b/src/gtk2-prefs/main.cpp
new file mode 100644
index 00000000..42e425c2
--- /dev/null
+++ b/src/gtk2-prefs/main.cpp
@@ -0,0 +1,616 @@
+/***************************************************************************
+                          main.cpp  -  description
+                             -------------------
+    begin                : Wed Jan  1 19:06:46 GMT+4 2003
+    copyright            : (C) 2003 - 2005 by Alex Shaduri
+    email                : ashaduri '@' gmail.com
+ ***************************************************************************/
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <iostream>
+#include <fstream>
+#include <stdlib.h>
+#include <sstream>
+#include <gtk/gtk.h>
+
+#ifdef _WIN32
+#include "win32util.h"
+#include <io.h>
+#else
+#include <sys/stat.h>
+#endif
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include "interface.h"
+#include "callbacks.h"
+#include "support.h"
+
+#include "main.h"
+
+
+// ------------------------------------------------------
+
+
+
+GtkWidget* g_main_window = 0;
+// GtkWidget* g_fontsel_dialog = 0;
+
+
+static std::string s_tmp_file;
+
+
+
+// ------------------------------------------------------
+
+
+
+static std::string gchar_to_string(gchar* gstr)
+{
+	std::string str = (gstr ? gstr : "");
+	g_free(gstr);
+	return str;
+}
+
+
+
+std::string get_home_dir()
+{
+	std::string dir;
+
+	if (g_get_home_dir())
+		dir = g_get_home_dir();
+
+#ifdef _WIN32
+	if (dir == "") {
+		dir = win32_get_registry_value_string(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "Personal");
+	}
+	if (dir == "") {
+		dir = win32_get_registry_value_string(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "User");
+	}
+#endif
+
+	return dir;
+
+}
+
+
+
+
+// ------------------------------------------------------
+
+
+static std::string s_orig_theme;
+static std::string s_orig_font;
+
+std::string& get_orig_theme()
+{
+	return s_orig_theme;
+}
+
+
+std::string& get_orig_font()
+{
+	return s_orig_font;
+}
+
+
+// ------------------------------------------------------
+
+
+std::string get_current_theme()
+{
+
+	GtkSettings* settings = gtk_settings_get_default();
+	gchar* theme;
+	g_object_get(settings, "gtk-theme-name", &theme, NULL);
+
+	return gchar_to_string(theme);
+}
+
+
+
+
+std::string get_current_font()
+{
+	return gchar_to_string(pango_font_description_to_string(gtk_rc_get_style(g_main_window)->font_desc));
+}
+
+
+
+// ------------------------------------------------------
+
+
+
+std::string get_selected_theme()
+{
+	GtkTreeView* treeview = GTK_TREE_VIEW(lookup_widget(g_main_window, "main_themelist"));
+	GtkTreeModel* model = gtk_tree_view_get_model(treeview);
+	GtkTreeSelection* selection = gtk_tree_view_get_selection(treeview);
+
+	GtkTreeIter iter;
+	gtk_tree_selection_get_selected(selection, 0, &iter);
+
+	gchar* theme_name;
+	gtk_tree_model_get(model, &iter, 0, &theme_name, -1);
+// 	std::cout << theme_name << "\n";
+	return gchar_to_string(theme_name);
+}
+
+
+
+std::string get_selected_font()
+{
+// 	GtkWidget* fontentry = lookup_widget(g_main_window, "main_fontentry");
+// 	return gtk_entry_get_text(GTK_ENTRY(fontentry));
+
+	bool default_font = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(g_main_window, "main_use_default_font_radio")));
+
+	if (default_font)
+		return "";
+
+	GtkWidget* fontbutton = lookup_widget(g_main_window, "main_font_selector_button");
+	return gtk_font_button_get_font_name(GTK_FONT_BUTTON(fontbutton));
+}
+
+
+// ------------------------------------------------------
+
+
+
+static void themelist_selection_changed_cb(GtkTreeSelection* selection, gpointer data)
+{
+	if (gtk_tree_selection_get_selected (selection, 0, 0))
+		apply_theme(get_selected_theme(), get_current_font());
+}
+
+
+
+// ------------------------------------------------------
+
+
+
+static void populate_with_themes(GtkWidget* w)
+{
+
+	std::string search_path = gchar_to_string(gtk_rc_get_theme_dir());
+	//std::string search_path = gchar_to_string(g_build_filename("lib", "gtk-2.0", "2.10.0", "engines", NULL));
+
+	if (search_path.size() && search_path[search_path.size() -1] != G_DIR_SEPARATOR)
+		search_path += G_DIR_SEPARATOR_S;
+
+	GDir* gdir = g_dir_open(search_path.c_str(), 0, NULL);
+	if (gdir == NULL)
+		return;
+
+
+	char* name;
+	GList* glist = 0;
+
+	while ( (name = const_cast<char*>(g_dir_read_name(gdir))) != NULL ) {
+		std::string filename = name;
+
+//		if (g_ascii_strup(fname.c_str(), -1) == "Default")
+//			continue;
+
+		std::string fullname = search_path + filename;
+		std::string rc = fullname; rc += G_DIR_SEPARATOR_S; rc += "gtk-2.0"; rc += G_DIR_SEPARATOR_S; rc += "gtkrc";
+
+		bool is_dir = 0;
+		if (g_file_test(fullname.c_str(), G_FILE_TEST_IS_DIR))
+			is_dir = 1;
+
+		if (is_dir && g_file_test(rc.c_str(), G_FILE_TEST_IS_REGULAR)) {
+			glist = g_list_insert_sorted(glist, g_strdup(filename.c_str()), (GCompareFunc)strcmp);
+		}
+	}
+
+	g_dir_close(gdir);
+
+
+
+
+	// ---------------- tree
+
+
+	GtkTreeView* treeview = GTK_TREE_VIEW(w);
+	GtkListStore *store = gtk_list_store_new (1, G_TYPE_STRING);
+	gtk_tree_view_set_model(treeview, GTK_TREE_MODEL(store));
+
+	GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes (
+												"Theme", gtk_cell_renderer_text_new(),
+												"text", 0,
+												NULL);
+	gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
+	gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
+
+
+	GtkTreeIter   iter;
+
+	int i =0, curr=0;
+	while (char* theme = (char*)g_list_nth_data(glist, i)) {
+		gtk_list_store_append (store, &iter);
+		gtk_list_store_set (store, &iter, 0, theme, -1);
+
+		if (strcmp(theme, get_current_theme().c_str()) == 0) {
+			curr = i;
+		}
+
+		++i;
+	}
+
+
+	GtkTreeSelection* selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+
+	// set the default theme
+
+	// THIS IS IMPORTANT!!!
+	gtk_widget_grab_focus(w);
+
+	std::stringstream str;
+	str << curr;
+	GtkTreePath* selpath = gtk_tree_path_new_from_string (str.str().c_str());
+	if (selpath) {
+		gtk_tree_selection_select_path(selection, selpath);
+		gtk_tree_view_scroll_to_cell(treeview, selpath, NULL, true, 0.5, 0.0);
+		gtk_tree_path_free(selpath);
+	}
+
+	g_signal_connect (G_OBJECT (selection), "changed",
+                  G_CALLBACK (themelist_selection_changed_cb), NULL);
+
+	g_object_unref (G_OBJECT (store));
+
+
+	// ---------------- font
+
+// 	GtkWidget* fontentry = lookup_widget(g_main_window, "main_fontentry");
+// 	gtk_entry_set_text(GTK_ENTRY(fontentry), get_current_font().c_str());
+
+	GtkWidget* fontbutton = lookup_widget(g_main_window, "main_font_selector_button");
+	gtk_font_button_set_font_name(GTK_FONT_BUTTON(fontbutton), get_current_font().c_str());
+
+
+}
+
+
+
+
+// ------------------------------------------------------
+
+#ifdef _WIN32
+static void redirect_to_file (const gchar* log_domain, GLogLevelFlags log_level,
+									const gchar* message, gpointer user_data)
+{
+	/* only write logs if running in portable mode, otherwise
+	   we would get a permission error in program files */
+	if ((_access( "portable-mode", 0 )) != -1)
+	{
+		std::fstream f;
+		f.open("gtk2-prefs.log", std::ios::app);
+		f << message << "\n";
+		f.close();
+	}
+}
+#endif
+
+// ------------------------------------------------------
+
+
+
+
+int main(int argc, char *argv[])
+{
+
+	// work around pango weirdness
+#ifdef _WIN32
+	// no longer needed as of pango 1.2.5, but won't do any harm
+// 	putenv("PANGO_WIN32_NO_UNISCRIBE=1");
+#endif
+
+
+
+
+	std::string user = g_get_user_name();
+	std::string tmp = g_get_tmp_dir();
+	std::string tmp_file = tmp + G_DIR_SEPARATOR_S + "gtk_prefs_tmprc_" + user;
+	s_tmp_file = tmp_file;
+	gtk_rc_add_default_file(tmp_file.c_str());
+
+
+
+	gtk_init (&argc, &argv);
+
+	// redirect gtk warnings to file when in win32
+#if defined _WIN32 && !defined DEBUG
+	g_log_set_handler ("GLib", GLogLevelFlags(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
+                     | G_LOG_FLAG_RECURSION), redirect_to_file, NULL);
+	g_log_set_handler ("GModule", GLogLevelFlags(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
+                     | G_LOG_FLAG_RECURSION), redirect_to_file, NULL);
+	g_log_set_handler ("GLib-GObject", GLogLevelFlags(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
+                     | G_LOG_FLAG_RECURSION), redirect_to_file, NULL);
+	g_log_set_handler ("GThread", GLogLevelFlags(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
+                     | G_LOG_FLAG_RECURSION), redirect_to_file, NULL);
+	g_log_set_handler ("Gtk", GLogLevelFlags(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
+                     | G_LOG_FLAG_RECURSION), redirect_to_file, NULL);
+	g_log_set_handler ("Gdk", GLogLevelFlags(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
+                     | G_LOG_FLAG_RECURSION), redirect_to_file, NULL);
+	g_log_set_handler ("GdkPixbuf", GLogLevelFlags(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL
+                     | G_LOG_FLAG_RECURSION), redirect_to_file, NULL);
+#endif
+
+
+	add_pixmap_directory(".");
+
+	g_main_window = create_main_window();
+
+
+	populate_with_themes(lookup_widget(g_main_window, "main_themelist"));
+
+
+	std::string about_text = std::string("GTK+ Preference Tool") + "\n\
+\n\
+by Alex Shaduri <ashaduri@gmail.com>\n\
+\n\
+  The authors make NO WARRANTY or representation, either express or implied, with respect to this software, its quality, accuracy, merchantability, or fitness for a particular purpose.  This software is provided \"AS IS\", and you, its user, assume the entire risk as to its quality and accuracy.\n\
+\n\
+  This is free software, and you are welcome to redistribute it under terms of GNU General Public License v2.";
+
+
+	gtk_label_set_text(GTK_LABEL(lookup_widget(g_main_window, "about_label")), about_text.c_str());
+
+
+	GtkTreeView* treeview = GTK_TREE_VIEW(lookup_widget(g_main_window, "preview_treeview"));
+	GtkTreeStore *store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_INT);
+	gtk_tree_view_set_model(treeview, GTK_TREE_MODEL(store));
+
+
+	GtkTreeViewColumn* column1 = gtk_tree_view_column_new_with_attributes ("Text", gtk_cell_renderer_text_new(), "text", 0, NULL);
+	gtk_tree_view_column_set_sizing(column1, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
+	gtk_tree_view_column_set_resizable(column1, true);
+	gtk_tree_view_column_set_reorderable (column1, true);
+	gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column1);
+
+	GtkTreeViewColumn* column2 = gtk_tree_view_column_new_with_attributes ("Number", gtk_cell_renderer_text_new(), "text", 1, NULL);
+	gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column2);
+
+
+	GtkTreeIter   iter1, iter2;
+
+	gtk_tree_store_append (store, &iter1, NULL);
+	gtk_tree_store_set (store, &iter1, 0, "Parent 2", 1, 66, -1);
+
+	gtk_tree_store_append (store, &iter1, NULL);
+	gtk_tree_store_set (store, &iter1, 0, "Parent 1", 1, 65, -1);
+
+	gtk_tree_store_append (store, &iter2, &iter1);
+	gtk_tree_store_set (store, &iter2, 0, "Child 1", 1, 67, -1);
+
+	gtk_tree_view_column_set_sort_column_id(column1, 0);
+	gtk_tree_view_column_set_sort_order (column1, GTK_SORT_ASCENDING);
+	gtk_tree_view_column_set_sort_indicator(column1, true);
+	gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), 0, GTK_SORT_ASCENDING);
+
+	g_object_unref (G_OBJECT (store));
+
+
+	get_orig_theme() = get_current_theme();
+	get_orig_font() = get_current_font();
+
+
+	gtk_widget_show (g_main_window);
+
+
+	gtk_main();
+
+	return EXIT_SUCCESS;
+
+}
+
+
+
+// -------------------------------
+
+
+
+void set_theme(const std::string& theme_name, const std::string& font)
+{
+	// set widgets accordingly
+
+	// tree
+	GtkTreeView* treeview = GTK_TREE_VIEW(lookup_widget(g_main_window, "main_themelist"));
+	GtkTreeModel* model = gtk_tree_view_get_model(treeview);
+	GtkTreeSelection* selection = gtk_tree_view_get_selection(treeview);
+
+	GtkTreeIter iter;
+	gtk_tree_model_get_iter_first(model, &iter);
+
+	while(gtk_tree_model_iter_next(model, &iter)) {
+
+		gchar* text;
+		gtk_tree_model_get (model, &iter, 0, &text, -1);
+		std::string theme = gchar_to_string(text);
+
+		if (theme_name == theme) {
+			gtk_tree_selection_select_iter(selection, &iter);
+			break;
+		}
+
+	}
+
+
+	// font
+// 	GtkWidget* fontentry = lookup_widget(g_main_window, "main_fontentry");
+// 	gtk_entry_set_text(GTK_ENTRY(fontentry), font.c_str());
+
+	if (font != "") {
+		GtkWidget* fontbutton = lookup_widget(g_main_window, "main_font_selector_button");
+		gtk_font_button_set_font_name(GTK_FONT_BUTTON(fontbutton), get_current_font().c_str());
+	}
+
+
+	apply_theme(get_selected_theme(), get_selected_font());
+
+}
+
+
+
+
+void apply_theme(const std::string& theme_name, const std::string& font)
+{
+
+	std::stringstream strstr;
+	strstr << "gtk-theme-name = \"" << theme_name << "\"\n";
+
+	if (font != "")
+		strstr << "style \"user-font\"\n{\nfont_name=\"" << font << "\"\n}\nwidget_class \"*\" style \"user-font\"";
+
+// 	std::cout << strstr.str() << "\n\n\n";
+	std::fstream f;
+	f.open(s_tmp_file.c_str(), std::ios::out);
+		f << strstr.str();
+	f.close();
+
+
+	GtkSettings* settings = gtk_settings_get_default();
+
+  	gtk_rc_reparse_all_for_settings (settings, true);
+// 	gtk_rc_parse_string(strstr.str().c_str());
+//  	gtk_rc_parse("/root/.gtk-tmp");
+//  	gtk_rc_reset_styles(settings);
+
+	unlink(s_tmp_file.c_str());
+
+	while (gtk_events_pending())
+		gtk_main_iteration();
+
+
+}
+
+
+
+
+#ifdef _WIN32
+#ifdef HAVE_DIRECT_H
+#include <direct.h>
+#define mkdir(a) _mkdir(a)
+#else
+#define mkdir(a, b) mkdir(a)
+#endif
+#endif
+
+
+bool save_current_theme()
+{
+
+	std::string conf_file = "";
+
+	if ((_access( "portable-mode", 0 )) != -1) {
+
+		char* themes_dir_c = gtk_rc_get_theme_dir();
+		char* conf_file_c = g_build_filename("etc", "gtk-2.0", "gtkrc", NULL);
+
+		conf_file = (conf_file_c ? conf_file_c : "");
+
+		// file doesn't exist, try to get it from gtk.
+		if (!g_file_test(conf_file.c_str(), G_FILE_TEST_EXISTS)) {
+
+			gchar** rc_files = gtk_rc_get_default_files();
+			if (rc_files[0] != 0) {
+				conf_file = rc_files[0];
+			}
+
+		}
+
+
+		g_free(themes_dir_c);
+		g_free(conf_file_c);
+
+
+		// mkdir a directory, only one level deep
+		char* etc = g_path_get_dirname(conf_file.c_str());
+		if (!g_file_test(etc, G_FILE_TEST_IS_DIR)) {
+			mkdir(etc, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
+		}
+		g_free(etc);
+
+
+	} else {
+
+		conf_file = get_home_dir();
+
+		if (conf_file[conf_file.length()-1] != G_DIR_SEPARATOR)
+			conf_file += G_DIR_SEPARATOR_S;
+
+		conf_file += ".gtkrc-2.0";
+
+	}
+
+
+
+	// ask
+
+	GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+	GtkWidget* dialog = gtk_dialog_new_with_buttons ("Query", GTK_WINDOW(window),
+											GtkDialogFlags(GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL),
+											GTK_STOCK_NO, GTK_RESPONSE_REJECT,
+											GTK_STOCK_YES, GTK_RESPONSE_ACCEPT,
+											NULL);
+	gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_MOUSE);
+	GtkWidget* hbox = gtk_hbox_new(1, 1);
+	gtk_container_set_border_width(GTK_CONTAINER(hbox), 10);
+
+	gtk_container_add (GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox);
+	gtk_container_add (GTK_CONTAINER(hbox),
+			gtk_label_new((std::string("\n\nThe file \"") + conf_file +  "\" will be overwritten.\nAre you sure?\n\n").c_str()));
+
+	gtk_widget_show_all (dialog);
+
+	bool ret = 0;
+	gint result = gtk_dialog_run (GTK_DIALOG (dialog));
+	switch (result) {
+		case GTK_RESPONSE_ACCEPT:
+			ret = 1;
+			break;
+	}
+	gtk_widget_destroy(dialog);
+	gtk_widget_destroy(window);
+
+	if (!ret)  // the user pressed "No".
+		return false;
+
+
+	std::string font = get_selected_font();
+
+	std::fstream f;
+	f.open(conf_file.c_str(), std::ios::out);
+		f << "# Auto-written by gtk2_prefs. Do not edit.\n\n";
+		f << "gtk-theme-name = \"" << get_selected_theme() << "\"\n";
+
+		if (font != "")
+			f << "style \"user-font\"\n{\n\tfont_name=\"" << font << "\"\n}\nwidget_class \"*\" style \"user-font\"";
+	f.close();
+
+
+	return true;
+
+}
+
+
+
+
+void program_shutdown()
+{
+	gtk_main_quit();
+}
+
+
+
+
+
diff --git a/src/gtk2-prefs/main.h b/src/gtk2-prefs/main.h
new file mode 100644
index 00000000..ab4e5cbd
--- /dev/null
+++ b/src/gtk2-prefs/main.h
@@ -0,0 +1,32 @@
+/***************************************************************************
+                          main.cpp  -  description
+                             -------------------
+    begin                : Wed Jan  1 2003
+    copyright            : (C) 2003 - 2005 by Alex Shaduri
+    email                : ashaduri '@' gmail.com
+ ***************************************************************************/
+
+#ifndef _MAIN_H_
+#define _MAIN_H_
+
+
+#include <string>
+
+
+std::string& get_orig_theme();
+std::string& get_orig_font();
+
+std::string get_current_theme();
+std::string get_current_font();
+
+std::string get_selected_theme();
+std::string get_selected_font();
+
+void set_theme(const std::string& theme_name, const std::string& font);
+void apply_theme(const std::string& theme_name, const std::string& font);
+bool save_current_theme();
+
+void program_shutdown();
+
+
+#endif
diff --git a/src/gtk2-prefs/makefile.mak b/src/gtk2-prefs/makefile.mak
new file mode 100644
index 00000000..1eeeb565
--- /dev/null
+++ b/src/gtk2-prefs/makefile.mak
@@ -0,0 +1,24 @@
+include "..\makeinc.mak"
+
+TARGET = gtk2-prefs.exe
+
+PREF_OBJECTS = \
+callbacks.obj \
+interface.obj \
+support.obj \
+win32util.obj \
+main.obj
+
+CPPFLAGS = $(CPPFLAGS) /D_STL70_ /D_STATIC_CPPLIB /EHsc /DHAVE_CONFIG_H
+
+all: $(PREF_OBJECTS) $(TARGET)
+
+.cpp.obj:
+	$(CC) $(CPPFLAGS) $(GLIB) $(GTK) /I. /c $<
+	
+$(TARGET): $(PREF_OBJECTS)
+	$(LINK) /out:$(TARGET) /entry:mainCRTStartup $(LDFLAGS) $(PREF_OBJECTS) ntstc_msvcrt.lib $(LIBS)
+
+clean:
+	del $(TARGET)
+	del *.obj
diff --git a/src/gtk2-prefs/support.cpp b/src/gtk2-prefs/support.cpp
new file mode 100644
index 00000000..bb19f284
--- /dev/null
+++ b/src/gtk2-prefs/support.cpp
@@ -0,0 +1,146 @@
+/*
+ * DO NOT EDIT THIS FILE - it is generated by Glade.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <string.h>
+#include <stdio.h>
+
+#include <gtk/gtk.h>
+
+#include "support.h"
+
+GtkWidget*
+lookup_widget                          (GtkWidget       *widget,
+                                        const gchar     *widget_name)
+{
+  GtkWidget *parent, *found_widget;
+
+  for (;;)
+    {
+      if (GTK_IS_MENU (widget))
+        parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
+      else
+        parent = widget->parent;
+      if (!parent)
+        parent = (GtkWidget*)g_object_get_data (G_OBJECT (widget), "GladeParentKey");
+      if (parent == NULL)
+        break;
+      widget = parent;
+    }
+
+  found_widget = (GtkWidget*) g_object_get_data (G_OBJECT (widget),
+                                                 widget_name);
+  if (!found_widget)
+    g_warning ("Widget not found: %s", widget_name);
+  return found_widget;
+}
+
+static GList *pixmaps_directories = NULL;
+
+/* Use this function to set the directory containing installed pixmaps. */
+void
+add_pixmap_directory                   (const gchar     *directory)
+{
+  pixmaps_directories = g_list_prepend (pixmaps_directories,
+                                        g_strdup (directory));
+}
+
+/* This is an internally used function to find pixmap files. */
+static gchar*
+find_pixmap_file                       (const gchar     *filename)
+{
+  GList *elem;
+
+  /* We step through each of the pixmaps directory to find it. */
+  elem = pixmaps_directories;
+  while (elem)
+    {
+      gchar *pathname = g_strdup_printf ("%s%s%s", (gchar*)elem->data,
+                                         G_DIR_SEPARATOR_S, filename);
+      if (g_file_test (pathname, G_FILE_TEST_EXISTS))
+        return pathname;
+      g_free (pathname);
+      elem = elem->next;
+    }
+  return NULL;
+}
+
+/* This is an internally used function to create pixmaps. */
+GtkWidget*
+create_pixmap                          (GtkWidget       *widget,
+                                        const gchar     *filename)
+{
+  gchar *pathname = NULL;
+  GtkWidget *pixmap;
+
+  if (!filename || !filename[0])
+      return gtk_image_new ();
+
+  pathname = find_pixmap_file (filename);
+
+  if (!pathname)
+    {
+      g_warning ("Couldn't find pixmap file: %s", filename);
+      return gtk_image_new ();
+    }
+
+  pixmap = gtk_image_new_from_file (pathname);
+  g_free (pathname);
+  return pixmap;
+}
+
+/* This is an internally used function to create pixmaps. */
+GdkPixbuf*
+create_pixbuf                          (const gchar     *filename)
+{
+  gchar *pathname = NULL;
+  GdkPixbuf *pixbuf;
+  GError *error = NULL;
+
+  if (!filename || !filename[0])
+      return NULL;
+
+  pathname = find_pixmap_file (filename);
+
+  if (!pathname)
+    {
+      g_warning ("Couldn't find pixmap file: %s", filename);
+      return NULL;
+    }
+
+  pixbuf = gdk_pixbuf_new_from_file (pathname, &error);
+  if (!pixbuf)
+    {
+      fprintf (stderr, "Failed to load pixbuf file: %s: %s\n",
+               pathname, error->message);
+      g_error_free (error);
+    }
+  g_free (pathname);
+  return pixbuf;
+}
+
+/* This is used to set ATK action descriptions. */
+void
+glade_set_atk_action_description       (AtkAction       *action,
+                                        const gchar     *action_name,
+                                        const gchar     *description)
+{
+  gint n_actions, i;
+
+  n_actions = atk_action_get_n_actions (action);
+  for (i = 0; i < n_actions; i++)
+    {
+      if (!strcmp (atk_action_get_name (action, i), action_name))
+        atk_action_set_description (action, i, description);
+    }
+}
+
diff --git a/src/gtk2-prefs/support.h b/src/gtk2-prefs/support.h
new file mode 100644
index 00000000..2dea079c
--- /dev/null
+++ b/src/gtk2-prefs/support.h
@@ -0,0 +1,44 @@
+/*
+ * DO NOT EDIT THIS FILE - it is generated by Glade.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <gtk/gtk.h>
+
+/*
+ * Public Functions.
+ */
+
+/*
+ * This function returns a widget in a component created by Glade.
+ * Call it with the toplevel widget in the component (i.e. a window/dialog),
+ * or alternatively any widget in the component, and the name of the widget
+ * you want returned.
+ */
+GtkWidget*  lookup_widget              (GtkWidget       *widget,
+                                        const gchar     *widget_name);
+
+
+/* Use this function to set the directory containing installed pixmaps. */
+void        add_pixmap_directory       (const gchar     *directory);
+
+
+/*
+ * Private Functions.
+ */
+
+/* This is used to create the pixmaps used in the interface. */
+GtkWidget*  create_pixmap              (GtkWidget       *widget,
+                                        const gchar     *filename);
+
+/* This is used to create the pixbufs used in the interface. */
+GdkPixbuf*  create_pixbuf              (const gchar     *filename);
+
+/* This is used to set ATK action descriptions. */
+void        glade_set_atk_action_description (AtkAction       *action,
+                                              const gchar     *action_name,
+                                              const gchar     *description);
+
diff --git a/src/gtk2-prefs/sys_win32.h b/src/gtk2-prefs/sys_win32.h
new file mode 100644
index 00000000..0a106690
--- /dev/null
+++ b/src/gtk2-prefs/sys_win32.h
@@ -0,0 +1,28 @@
+/***************************************************************************
+                          sys_win32.h  -  description
+                             -------------------
+    begin                : Wed Oct 22 2003
+    copyright            : (C) 2003 by Alex Shaduri, Irakli A. Elizbarashvili
+    email                : alex_sh@land.ru
+ ***************************************************************************/
+#ifndef SYS_WIN32_H
+#define SYS_WIN32_H
+
+
+
+
+
+#ifdef _WIN32
+
+#	define WIN32_LEAN_AND_MEAN
+#	include <windows.h>
+
+#endif
+
+
+
+
+
+
+
+#endif
diff --git a/src/gtk2-prefs/win32util.cpp b/src/gtk2-prefs/win32util.cpp
new file mode 100644
index 00000000..79cab17d
--- /dev/null
+++ b/src/gtk2-prefs/win32util.cpp
@@ -0,0 +1,80 @@
+/***************************************************************************
+                          win32util.cpp  -  description
+                             -------------------
+    begin                : Tue Jan 14 2003
+    copyright            : (C) 2003 by Alex Shaduri
+    email                : alex_sh@land.ru
+ ***************************************************************************/
+
+#ifdef _WIN32
+
+#include <string>
+#include "sys_win32.h"
+#include "win32util.h"
+
+
+
+
+
+std::string win32_get_registry_value_string(HKEY base, const std::string& keydir, const std::string& key)
+{
+
+	HKEY reg_key = NULL;
+	DWORD type;
+	DWORD nbytes;
+	char* result = NULL;
+//HKEY_CURRENT_USER
+	nbytes = 0;
+	if ( RegOpenKeyEx ( base, keydir.c_str(), 0, KEY_QUERY_VALUE, &reg_key) == ERROR_SUCCESS
+			&& RegQueryValueEx (reg_key, key.c_str(), 0, &type, NULL, &nbytes) == ERROR_SUCCESS ) {
+		result = (char*)malloc(nbytes + 1);
+		RegQueryValueEx (reg_key,  key.c_str(), 0, &type, (BYTE*)result, &nbytes);
+		result[nbytes] = '\0';
+	}
+
+	if (reg_key != NULL)
+		RegCloseKey (reg_key);
+
+	std::string ret = "";
+
+	if (result) {
+		ret = result;
+	}
+
+	return ret;
+
+}
+
+
+
+
+void win32_set_registry_value_string(HKEY base, const std::string& keydir, const std::string& key, const std::string& value)
+{
+
+	HKEY reg_key = NULL;
+	DWORD nbytes;
+
+	nbytes = value.length() + 1;
+
+	if ( RegOpenKeyEx ( base, keydir.c_str(), 0, KEY_QUERY_VALUE, &reg_key) == ERROR_SUCCESS) {
+		RegSetValueEx (reg_key,  key.c_str(), 0, REG_SZ, (const BYTE*)(value.c_str()), nbytes);
+	}
+
+	if (reg_key != NULL)
+		RegCloseKey (reg_key);
+
+}
+
+
+
+
+
+
+
+#endif
+
+
+
+
+
+
diff --git a/src/gtk2-prefs/win32util.h b/src/gtk2-prefs/win32util.h
new file mode 100644
index 00000000..8c194a19
--- /dev/null
+++ b/src/gtk2-prefs/win32util.h
@@ -0,0 +1,26 @@
+/***************************************************************************
+                          win32util.h  -  description
+                             -------------------
+    begin                : Tue Jan 14 2003
+    copyright            : (C) 2003 by Alex Shaduri
+    email                : alex_sh@land.ru
+ ***************************************************************************/
+#ifndef WIN32UTIL_H
+#define WIN32UTIL_H
+
+#ifdef _WIN32
+
+#include <string>
+#include "sys_win32.h"
+
+
+
+std::string win32_get_registry_value_string(HKEY base, const std::string& keydir, const std::string& key);
+void win32_set_registry_value_string(HKEY base, const std::string& keydir, const std::string& key, const std::string& value);
+
+
+
+
+#endif //_WIN32
+
+#endif // WIN32UTIL_H
diff --git a/src/makefile.mak b/src/makefile.mak
new file mode 100644
index 00000000..cd73b879
--- /dev/null
+++ b/src/makefile.mak
@@ -0,0 +1,23 @@
+all:
+	@cd pixmaps
+	@-$(MAKE) /nologo /s /f makefile.mak $@
+	@cd ..\common
+	@-$(MAKE) /nologo /s /f makefile.mak $@
+	@cd ..\fe-gtk
+	@-$(MAKE) /nologo /s /f makefile.mak $@
+	@cd ..\fe-text
+	@-$(MAKE) /nologo /s /f makefile.mak $@
+	@cd ..\gtk2-prefs
+	@-$(MAKE) /nologo /s /f makefile.mak $@
+
+clean:
+	@cd pixmaps
+	@-$(MAKE) /nologo /s /f makefile.mak clean $@
+	@cd ..\common
+	@-$(MAKE) /nologo /s /f makefile.mak clean $@
+	@cd ..\fe-gtk
+	@-$(MAKE) /nologo /s /f makefile.mak clean $@
+	@cd ..\fe-text
+	@-$(MAKE) /nologo /s /f makefile.mak clean $@
+	@cd ..\gtk2-prefs
+	@-$(MAKE) /nologo /s /f makefile.mak clean $@
diff --git a/src/makeinc.skel.mak b/src/makeinc.skel.mak
new file mode 100644
index 00000000..552b6a6e
--- /dev/null
+++ b/src/makeinc.skel.mak
@@ -0,0 +1,45 @@
+CC = cl
+LINK = link
+CFLAGS = $(CFLAGS) /Ox /c /MD /MP /W0 /nologo
+CFLAGS = $(CFLAGS) /DWIN32 /DG_DISABLE_CAST_CHECKS /DG_DISABLE_DEPRECATED /DGDK_PIXBUF_DISABLE_DEPRECATED /DGDK_DISABLE_DEPRECATED /DHAVE_STRTOULL /Dstrtoull=_strtoui64 /Dstrcasecmp=stricmp /Dstrncasecmp=strnicmp
+CFLAGS = $(CFLAGS) /I$(DEV)\include
+CPPFLAGS = /c /MD /W0 /nologo /DWIN32
+LDFLAGS = /subsystem:windows /nologo
+LIBS = $(LIBS) gdi32.lib shell32.lib user32.lib advapi32.lib imm32.lib ole32.lib winmm.lib ws2_32.lib wininet.lib comdlg32.lib libeay32.lib ssleay32.lib
+
+GLIB = /I$(DEV)\include\glib-2.0 /I$(DEV)\lib\glib-2.0\include /I$(DEV)\include\libxml2
+GTK = /I$(DEV)\include\gtk-2.0 /I$(DEV)\lib\gtk-2.0\include /I$(DEV)\include\atk-1.0 /I$(DEV)\include\cairo /I$(DEV)\include\pango-1.0 /I$(DEV)\include\gdk-pixbuf-2.0
+LIBS = $(LIBS) /libpath:$(DEV)\lib gtk-win32-2.0.lib gdk-win32-2.0.lib atk-1.0.lib gio-2.0.lib gdk_pixbuf-2.0.lib pangowin32-1.0.lib pangocairo-1.0.lib pango-1.0.lib cairo.lib gobject-2.0.lib gmodule-2.0.lib glib-2.0.lib intl.lib libxml2.lib
+#obs LIBS = $(LIBS) /libpath:$(DEV)\lib libgtk-win32-2.0-0.lib libgdk-win32-2.0-0.lib libatk-1.0-0.lib libgio-2.0-0.lib libgdk_pixbuf-2.0-0.lib libpangowin32-1.0-0.lib libpangocairo-1.0-0.lib libpango-1.0-0.lib libcairo-2.lib libgobject-2.0-0.lib libgmodule-2.0-0.lib libglib-2.0-0.lib libintl-8.lib libxml2-2.lib
+
+LUALIB = lua51
+LUAOUTPUT = xclua.dll
+
+PERL512LIB = perl512
+PERL512OUTPUT = xcperl-512.dll
+PERL514LIB = perl514
+PERL514OUTPUT = xcperl-514.dll
+
+PYTHONLIB = python27
+PYTHONOUTPUT = xcpython.dll
+
+TCLLIB = tcl85
+TCLOUTPUT = xctcl.dll
+
+!ifdef X64
+CFLAGS = $(CFLAGS) /favor:AMD64 /D_WIN64
+CPPFLAGS = $(CPPFLAGS) /favor:AMD64 /D_WIN64
+LDFLAGS = $(LDFLAGS) msvcrt_win2003.obj
+
+PERL512PATH = c:\mozilla-build\perl-5.12-x64
+PERL514PATH = c:\mozilla-build\perl-5.14-x64
+PYTHONPATH = c:\mozilla-build\python-2.7-x64
+TCLPATH = c:\mozilla-build\tcl-8.5-x64
+!else
+LDFLAGS = $(LDFLAGS) msvcrt_winxp.obj
+
+PERL512PATH = c:\mozilla-build\perl-5.12-x86
+PERL514PATH = c:\mozilla-build\perl-5.14-x86
+PYTHONPATH = c:\mozilla-build\python-2.7-x86
+TCLPATH = c:\mozilla-build\tcl-8.5-x86
+!endif
diff --git a/src/pixmaps/makefile.mak b/src/pixmaps/makefile.mak
new file mode 100644
index 00000000..f9535dbe
--- /dev/null
+++ b/src/pixmaps/makefile.mak
@@ -0,0 +1,18 @@
+CONV = gdk-pixbuf-csource
+
+LIST =	bookpng book.png \
+			hoppng hop.png \
+			oppng op.png \
+			purplepng purple.png \
+			redpng red.png \
+			trayfilepng fileoffer.png \
+			trayhilightpng highlight.png \
+			traymsgpng message.png \
+			voicepng voice.png \
+			xchatpng ..\..\xchat.png
+
+all: 
+	@$(CONV) --build-list $(LIST) > inline_pngs.h
+
+clean:
+	@del *.h
diff --git a/src/version-script b/src/version-script
index 048c1f55..e76f4fe9 100644
--- a/src/version-script
+++ b/src/version-script
@@ -30,5 +30,9 @@ EXPORTED {
 		xchat_send_modes;
 		xchat_strip;
 		xchat_free;
+		xchat_set_pluginpref_str;
+		xchat_get_pluginpref_str;
+		xchat_set_pluginpref_int;
+		xchat_get_pluginpref_int;
 	local: *;
 };