From: Herman B. <her...@us...> - 2003-08-08 01:05:06
|
Update of /cvsroot/gaim/gaim/plugins/win32/winprefs In directory sc8-pr-cvs1:/tmp/cvs-serv13713 Modified Files: Makefile.mingw winprefs.c Log Message: Blist can now be docked, using Windows appbar features Index: Makefile.mingw =================================================================== RCS file: /cvsroot/gaim/gaim/plugins/win32/winprefs/Makefile.mingw,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Makefile.mingw 21 Jun 2003 00:59:23 -0000 1.2 +++ Makefile.mingw 8 Aug 2003 01:05:03 -0000 1.3 @@ -56,7 +56,8 @@ ## SOURCES, OBJECTS ## -C_SRC = winprefs.c +C_SRC = winprefs.c \ + gtkappbar.c OBJECTS = $(C_SRC:%.c=%.o) Index: winprefs.c =================================================================== RCS file: /cvsroot/gaim/gaim/plugins/win32/winprefs/winprefs.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- winprefs.c 8 Jul 2003 06:11:48 -0000 1.9 +++ winprefs.c 8 Aug 2003 01:05:03 -0000 1.10 @@ -1,7 +1,11 @@ /* - * winprefs.c + * gaim - WinGaim Options Plugin * - * copyright (c) 1998-2002, Herman Bloggs <her...@ya...> + * File: winprefs.c + * Date: December 12, 2002 + * Description: Gaim Plugin interface + * + * copyright (c) 2002-2003, Herman Bloggs <her...@ya...> * * this program is free software; you can redistribute it and/or modify * it under the terms of the gnu general public license as published by @@ -21,43 +25,110 @@ #include <windows.h> #include <winreg.h> #include <winerror.h> +#include <gdk/gdkwin32.h> #include "internal.h" +#include "gtkinternal.h" #include "prefs.h" #include "debug.h" #include "gtkplugin.h" #include "gtkutils.h" +#include "gtkblist.h" +#include "gtkappbar.h" /* * MACROS & DEFINES */ #define WINPREFS_PLUGIN_ID "gtk-win-prefs" -#define WINPREFS_VERSION 1 /* * LOCALS */ -static const char *OPT_WINPREFS_AUTOSTART="/plugins/gtk/win32/winprefs/auto_start"; +static const char *OPT_WINPREFS_DBLIST_DOCKABLE = "/plugins/gtk/win32/winprefs/dblist_dockable"; +static const char *OPT_WINPREFS_DBLIST_DOCKED = "/plugins/gtk/win32/winprefs/dblist_docked"; +static const char *OPT_WINPREFS_DBLIST_HEIGHT = "/plugins/gtk/win32/winprefs/dblist_height"; +static const char *OPT_WINPREFS_DBLIST_SIDE = "/plugins/gtk/win32/winprefs/dblist_side"; +static GaimPlugin *plugin_id = NULL; +static GtkAppBar *blist_ab = NULL; +static GtkWidget *blist = NULL; /* * PROTOS */ +static void blist_create_cb(); /* * CODE */ -static GtkWidget *wgaim_button(const char *text, const char *pref, GtkWidget *page) { +/* UTIL */ + +static GtkWidget *wgaim_button(const char *text, GtkWidget *page) { GtkWidget *button; button = gtk_check_button_new_with_mnemonic(text); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), gaim_prefs_get_bool(pref)); gtk_box_pack_start(GTK_BOX(page), button, FALSE, FALSE, 0); gtk_widget_show(button); return button; } +/* BLIST DOCKING */ + +static void blist_save_state() { + if(blist_ab && gaim_prefs_get_bool(OPT_WINPREFS_DBLIST_DOCKABLE)) { + if(blist_ab->docked) { + gaim_prefs_set_int(OPT_WINPREFS_DBLIST_HEIGHT, blist_ab->undocked_height); + gaim_prefs_set_int(OPT_WINPREFS_DBLIST_SIDE, blist_ab->side); + } + gaim_prefs_set_bool(OPT_WINPREFS_DBLIST_DOCKED, blist_ab->docked); + } + else + gaim_prefs_set_bool(OPT_WINPREFS_DBLIST_DOCKED, FALSE); +} + +static void blist_set_dockable(gboolean val) { + if(val) { + if(!blist_ab && blist) + blist_ab = gtk_appbar_add(blist); + } + else { + gtk_appbar_remove(blist_ab); + blist_ab = NULL; + } +} + +static void gaim_quit_cb() { + gaim_debug(GAIM_DEBUG_INFO, WINPREFS_PLUGIN_ID, "gaim_quit_cb: removing appbar\n"); + blist_save_state(); + blist_set_dockable(FALSE); +} + +static gboolean blist_create_cb_remove(gpointer data) { + gaim_signal_disconnect(plugin_id, event_signon, blist_create_cb); + return FALSE; +} + +static void blist_create_cb() { + gaim_debug(GAIM_DEBUG_INFO, WINPREFS_PLUGIN_ID, "event_signon\n"); + + blist = GAIM_GTK_BLIST(gaim_get_blist())->window; + if(gaim_prefs_get_bool(OPT_WINPREFS_DBLIST_DOCKABLE)) { + blist_set_dockable(TRUE); + if(gaim_prefs_get_bool(OPT_WINPREFS_DBLIST_DOCKED)) { + blist_ab->undocked_height = gaim_prefs_get_int(OPT_WINPREFS_DBLIST_HEIGHT); + gtk_appbar_dock(blist_ab, + gaim_prefs_get_int(OPT_WINPREFS_DBLIST_SIDE)); + } + } + /* removing here will cause a crash when going to next cb + in the gaim signal cb loop.. so process delayed. */ + g_idle_add(blist_create_cb_remove, NULL); +} + + +/* AUTOSTART */ + static int open_run_key(PHKEY phKey, REGSAM samDesired) { /* First try current user key (for WinNT & Win2k +), fall back to local machine */ if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, @@ -73,44 +144,72 @@ return 1; } -static void set_winprefs_option(GtkWidget *w, const char *key) { - gaim_prefs_set_bool(key, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))); - if(key == OPT_WINPREFS_AUTOSTART) { - HKEY hKey; +/* WIN PREFS GENERAL */ - if(!open_run_key(&hKey, KEY_SET_VALUE)) - return; - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) { - char buffer[1024]; - DWORD size; +static void winprefs_set_autostart(GtkWidget *w) { + HKEY hKey; - if((size = GetModuleFileName(wgaim_hinstance(), - (LPBYTE)buffer, - sizeof(buffer)))==0) { - gaim_debug(GAIM_DEBUG_ERROR, WINPREFS_PLUGIN_ID, "GetModuleFileName Error.. Could not set Gaim autostart.\n"); - RegCloseKey(hKey); - return; - } - /* Now set value of new key */ - if(ERROR_SUCCESS != RegSetValueEx(hKey, - "Gaim", - 0, - REG_SZ, - buffer, - size)) - gaim_debug(GAIM_DEBUG_ERROR, WINPREFS_PLUGIN_ID, "Could not set registry key value\n"); - } - else { - if(ERROR_SUCCESS != RegDeleteValue(hKey, "Gaim")) - gaim_debug(GAIM_DEBUG_ERROR, WINPREFS_PLUGIN_ID, "Could not delete registry key value\n"); - } - RegCloseKey(hKey); - } + if(!open_run_key(&hKey, KEY_SET_VALUE)) + return; + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) { + char buffer[1024]; + DWORD size; + + if((size = GetModuleFileName(wgaim_hinstance(), + (LPBYTE)buffer, + sizeof(buffer)))==0) { + gaim_debug(GAIM_DEBUG_ERROR, WINPREFS_PLUGIN_ID, "GetModuleFileName Error.. Could not set Gaim autostart.\n"); + RegCloseKey(hKey); + return; + } + /* Now set value of new key */ + if(ERROR_SUCCESS != RegSetValueEx(hKey, + "Gaim", + 0, + REG_SZ, + buffer, + size)) + gaim_debug(GAIM_DEBUG_ERROR, WINPREFS_PLUGIN_ID, "Could not set registry key value\n"); + } + else { + if(ERROR_SUCCESS != RegDeleteValue(hKey, "Gaim")) + gaim_debug(GAIM_DEBUG_ERROR, WINPREFS_PLUGIN_ID, "Could not delete registry key value\n"); + } + RegCloseKey(hKey); +} + +static void winprefs_set_blist_dockable(GtkWidget *w) { + gaim_prefs_set_bool(OPT_WINPREFS_DBLIST_DOCKABLE, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))); + gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)) ? blist_set_dockable(TRUE) : blist_set_dockable(FALSE); } + /* * EXPORTED FUNCTIONS */ + +gboolean plugin_load(GaimPlugin *plugin) { + plugin_id = plugin; + + /* blist docking init */ + if(!blist && gaim_get_blist() && GAIM_GTK_BLIST(gaim_get_blist())) { + blist = GAIM_GTK_BLIST(gaim_get_blist())->window; + if(gaim_prefs_get_bool(OPT_WINPREFS_DBLIST_DOCKABLE)) + blist_set_dockable(TRUE); + } + else + gaim_signal_connect(plugin, event_signon, blist_create_cb, NULL); + + gaim_signal_connect(plugin, event_quit, gaim_quit_cb, NULL); + + return TRUE; +} + +gboolean plugin_unload(GaimPlugin *plugin) { + blist_set_dockable(FALSE); + return TRUE; +} + static GtkWidget* get_config_frame(GaimPlugin *plugin) { GtkWidget *ret; GtkWidget *button; @@ -120,16 +219,21 @@ ret = gtk_vbox_new(FALSE, 18); gtk_container_set_border_width (GTK_CONTAINER (ret), 12); - /* IM Convo trans options */ vbox = gaim_gtk_make_frame (ret, _("Startup")); - button = wgaim_button(_("_Start Gaim on Windows startup"), OPT_WINPREFS_AUTOSTART, vbox); - /* Set initial value */ + + /* Autostart */ + button = wgaim_button(_("_Start Gaim on Windows startup"), vbox); if(open_run_key(&hKey, KEY_QUERY_VALUE)) { if(ERROR_SUCCESS == RegQueryValueEx(hKey, "Gaim", 0, NULL, NULL, NULL)) { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); } } - gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(set_winprefs_option), (void *)OPT_WINPREFS_AUTOSTART); + gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(winprefs_set_autostart), NULL); + + /* Dockable Blist */ + button = wgaim_button(_("_Dockable Buddy List"), vbox); + gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(winprefs_set_blist_dockable), NULL); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), gaim_prefs_get_bool(OPT_WINPREFS_DBLIST_DOCKABLE)); gtk_widget_show_all(ret); return ret; @@ -154,9 +258,9 @@ N_("Options specific to Windows Gaim."), N_("Options specific to Windows Gaim."), "Herman Bloggs <her...@ya...>", - WEBSITE, - NULL, - NULL, + GAIM_WEBSITE, + plugin_load, + plugin_unload, NULL, &ui_info, NULL @@ -165,9 +269,12 @@ static void init_plugin(GaimPlugin *plugin) { - gaim_prefs_add_none("/plugins/gtk/win32"); - gaim_prefs_add_none("/plugins/gtk/win32/winprefs"); - gaim_prefs_add_bool("/plugins/gtk/win32/winprefs/auto_start", FALSE); + gaim_prefs_add_none("/plugins/gtk/win32"); + gaim_prefs_add_none("/plugins/gtk/win32/winprefs"); + gaim_prefs_add_bool(OPT_WINPREFS_DBLIST_DOCKABLE, FALSE); + gaim_prefs_add_bool(OPT_WINPREFS_DBLIST_DOCKED, FALSE); + gaim_prefs_add_int(OPT_WINPREFS_DBLIST_HEIGHT, 0); + gaim_prefs_add_int(OPT_WINPREFS_DBLIST_SIDE, 0); } GAIM_INIT_PLUGIN(winprefs, init_plugin, info) |