# HG changeset patch # User Daniel Atallah # Date 1110251737 0 # Node ID 179b0245a2f760f6533d21d5adc466cddc2855c3 # Parent 0925c898b73c20b3d0e3ab3d9a22e5b1e6453987 [gaim-migrate @ 12213] This is patches 1115963 and 1115968 from rlaager, implementation of wgaim_get_special_folder() and using it to specify a sane default for the file chooser. committer: Tailor Script diff -r 0925c898b73c -r 179b0245a2f7 src/gtkrequest.c --- a/src/gtkrequest.c Tue Mar 08 02:37:07 2005 +0000 +++ b/src/gtkrequest.c Tue Mar 08 03:15:37 2005 +0000 @@ -1654,6 +1654,9 @@ GaimGtkRequestData *data; GtkWidget *filesel; const gchar *current_folder; +#if GTK_CHECK_VERSION(2,4,0) + gboolean folder_set = FALSE; +#endif data = g_new0(GaimGtkRequestData, 1); data->type = GAIM_REQUEST_FILE; @@ -1683,17 +1686,32 @@ } else { current_folder = gaim_prefs_get_string("/gaim/gtk/filelocations/last_open_folder"); } + if (filename != NULL) gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(filesel), filename); - if ((current_folder != NULL) && (*current_folder != '\0')) - gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(filesel), current_folder); + if ((current_folder != NULL) && (*current_folder != '\0')) { + folder_set = gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(filesel), current_folder); + } + +#ifdef _WIN32 + if (!folder_set) { + char *my_documents = wgaim_get_special_folder(CSIDL_PERSONAL); + if (my_documents != NULL) { + gtk_file_chooser_set_current_folder( + GTK_FILE_CHOOSER(filesel), my_documents); + + g_free(my_documents); + } + } + +#endif g_signal_connect(G_OBJECT(GTK_FILE_CHOOSER(filesel)), "response", G_CALLBACK(file_ok_check_if_exists_cb), data); #else /* FILECHOOSER */ - filesel = gtk_file_selection_new(title ? title - : (savedialog ? _("Save File...") - : _("Open File..."))); + filesel = gtk_file_selection_new( + title ? title : (savedialog ? _("Save File...") + : _("Open File..."))); if (savedialog) { current_folder = gaim_prefs_get_string("/gaim/gtk/filelocations/last_save_folder"); } else { diff -r 0925c898b73c -r 179b0245a2f7 src/win32/win32dep.c --- a/src/win32/win32dep.c Tue Mar 08 02:37:07 2005 +0000 +++ b/src/win32/win32dep.c Tue Mar 08 03:15:37 2005 +0000 @@ -27,7 +27,6 @@ #include #include #include -#include #include #include @@ -53,6 +52,8 @@ #include +#include "win32dep.h" + /* * DEFINES & MACROS */ @@ -83,7 +84,7 @@ /* * LOCALS */ -static char app_data_dir[MAX_PATH + 1] = "C:"; +static char *app_data_dir; static char install_dir[MAXPATHLEN]; static char lib_dir[MAXPATHLEN]; static char locale_dir[MAXPATHLEN]; @@ -99,8 +100,6 @@ * PROTOS */ LPFNFLASHWINDOWEX MyFlashWindowEx = NULL; -LPFNSHGETFOLDERPATHA MySHGetFolderPathA = NULL; -LPFNSHGETFOLDERPATHW MySHGetFolderPathW = NULL; FARPROC wgaim_find_and_loadproc(char*, char*); extern void wgaim_gtkspell_init(); @@ -233,6 +232,50 @@ /* Determine Gaim Paths during Runtime */ +/* Get paths to special Windows folders. */ +char *wgaim_get_special_folder(int folder_type) { + static LPFNSHGETFOLDERPATHA MySHGetFolderPathA = NULL; + char *retval = NULL; +#if GLIB_CHECK_VERSION(2,6,0) + static LPFNSHGETFOLDERPATHW MySHGetFolderPathW = NULL; + + if (!MySHGetFolderPathW) { + MySHGetFolderPathW = (LPFNSHGETFOLDERPATHW) + wgaim_find_and_loadproc("shfolder.dll", "SHGetFolderPathW"); + } + + if (MySHGetFolderPathW) { + wchar_t utf_16_dir[MAX_PATH + 1]; + + if (SUCCEEDED(MySHGetFolderPathW(NULL, folder_type, NULL, + SHGFP_TYPE_CURRENT, utf_16_dir))) { + retval = g_utf16_to_utf8(utf_16_dir, -1, NULL, NULL, NULL); + } + } +#endif + + if (!retval) { + if (!MySHGetFolderPathA) { + MySHGetFolderPathA = (LPFNSHGETFOLDERPATHA) + wgaim_find_and_loadproc("shfolder.dll", "SHGetFolderPathA"); + } + if (MySHGetFolderPathA) { + char locale_dir[MAX_PATH + 1]; + + if (SUCCEEDED(MySHGetFolderPathA(NULL, folder_type, NULL, + SHGFP_TYPE_CURRENT, locale_dir))) { +#if GLIB_CHECK_VERSION(2,6,0) + retval = g_locale_to_utf8(locale_dir, -1, NULL, NULL, NULL); +#else + retval = g_strdup(locale_dir); +#endif + } + } + } + + return retval; +} + char* wgaim_install_dir(void) { HMODULE hmod; char* buf; @@ -270,7 +313,7 @@ } char* wgaim_data_dir(void) { - return (char*)&app_data_dir; + return app_data_dir; } /* Miscellaneous */ @@ -452,40 +495,17 @@ g_free(newenv); /* Set app data dir, used by gaim_home_dir */ - newenv = (char*)g_getenv("GAIMHOME"); - if(!newenv) { -#if GLIB_CHECK_VERSION(2,6,0) - if ((MySHGetFolderPathW = (LPFNSHGETFOLDERPATHW) wgaim_find_and_loadproc("shfolder.dll", "SHGetFolderPathW"))) { - wchar_t utf_16_dir[MAX_PATH +1]; - char *temp; - MySHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, - SHGFP_TYPE_CURRENT, utf_16_dir); - temp = g_utf16_to_utf8(utf_16_dir, -1, NULL, NULL, NULL); - g_strlcpy(app_data_dir, temp, sizeof(app_data_dir)); - g_free(temp); - } else if ((MySHGetFolderPathA = (LPFNSHGETFOLDERPATHA) wgaim_find_and_loadproc("shfolder.dll", "SHGetFolderPathA"))) { - char locale_dir[MAX_PATH + 1]; - char *temp; - MySHGetFolderPathA(NULL, CSIDL_APPDATA, NULL, - SHGFP_TYPE_CURRENT, locale_dir); - temp = g_locale_to_utf8(locale_dir, -1, NULL, NULL, NULL); - g_strlcpy(app_data_dir, temp, sizeof(app_data_dir)); - g_free(temp); - } -#else - if ((MySHGetFolderPathA = (LPFNSHGETFOLDERPATHA) wgaim_find_and_loadproc("shfolder.dll", "SHGetFolderPathA"))) { - MySHGetFolderPathA(NULL, CSIDL_APPDATA, NULL, - SHGFP_TYPE_CURRENT, app_data_dir); - } -#endif - else { - strcpy(app_data_dir, "C:"); + newenv = (char*) g_getenv("GAIMHOME"); + if (newenv) { + app_data_dir = g_strdup(newenv); + } else { + app_data_dir = wgaim_get_special_folder(CSIDL_APPDATA); + if (!app_data_dir) { + app_data_dir = g_strdup("C:"); } } - else { - g_strlcpy(app_data_dir, newenv, sizeof(app_data_dir)); - } - gaim_debug(GAIM_DEBUG_INFO, "wgaim", "Gaim settings dir: %s\n", app_data_dir); + + gaim_debug(GAIM_DEBUG_INFO, "wgaim", "Gaim settings dir: %s\n", app_data_dir); /* IdleTracker Initialization */ if(!wgaim_set_idlehooks()) @@ -505,6 +525,8 @@ /* Idle tracker cleanup */ wgaim_remove_idlehooks(); + + g_free(app_data_dir); } /* DLL initializer */ diff -r 0925c898b73c -r 179b0245a2f7 src/win32/win32dep.h --- a/src/win32/win32dep.h Tue Mar 08 02:37:07 2005 +0000 +++ b/src/win32/win32dep.h Tue Mar 08 03:15:37 2005 +0000 @@ -22,6 +22,7 @@ */ #ifndef _WIN32DEP_H_ #define _WIN32DEP_H_ +#include #include #include #include @@ -42,6 +43,7 @@ extern gboolean wgaim_read_reg_string(HKEY key, char* sub_key, char* val_name, LPBYTE data, LPDWORD data_len); extern char* wgaim_escape_dirsep(char*); /* Determine Gaim paths */ +extern char* wgaim_get_special_folder(int folder_type); /* needs to be g_free'd */ extern char* wgaim_install_dir(void); extern char* wgaim_lib_dir(void); extern char* wgaim_locale_dir(void);