[xchat-gnome] Bug 415345 - Should add the default Downloads folder to the filechoosers
- From: Ritesh Khadgaray <rkhadgaray src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [xchat-gnome] Bug 415345 - Should add the default Downloads folder to the filechoosers
- Date: Wed, 13 Jan 2010 20:57:48 +0000 (UTC)
commit 53a06edf9697cdbc504342c0674654e5545b24eb
Author: Ritesh Khadgaray <khadgaray gmail com>
Date: Thu Jan 14 02:26:35 2010 +0530
Bug 415345 - Should add the default Downloads folder to the filechoosers
src/common/cfgfiles.c | 4 ++-
src/common/util.c | 15 +++++++++++
src/common/util.h | 1 +
src/fe-gnome/preferences-page-dcc.c | 4 +++
src/fe-gnome/preferences.c | 47 ++++++----------------------------
5 files changed, 32 insertions(+), 39 deletions(-)
---
diff --git a/src/common/cfgfiles.c b/src/common/cfgfiles.c
index 2375d90..bca068f 100644
--- a/src/common/cfgfiles.c
+++ b/src/common/cfgfiles.c
@@ -24,6 +24,8 @@
#include <sys/types.h>
#include <sys/stat.h>
+#include <glib.h>
+
#include "xchat.h"
#include "cfgfiles.h"
#include "util.h"
@@ -706,7 +708,7 @@ load_config (void)
}
#else
snprintf (prefs.sounddir, sizeof (prefs.sounddir), "%s/sounds", get_xdir_utf8 ());
- snprintf (prefs.dccdir, sizeof (prefs.dccdir), "%s/downloads", get_xdir_utf8 ());
+ g_snprintf(prefs.dccdir, sizeof (prefs.dccdir), "%s", get_default_download_dir());
#endif
strcpy (prefs.doubleclickuser, "QUOTE WHOIS %s %s");
strcpy (prefs.awayreason, _("I'm busy"));
diff --git a/src/common/util.c b/src/common/util.c
index 34b36a8..f1734ad 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -43,6 +43,8 @@
#include "util.h"
#include "../../config.h"
+#include <glib.h>
+
#define WANTSOCKET
#include "inet.h"
@@ -1598,6 +1600,19 @@ move_file_utf8 (char *src_dir, char *dst_dir, char *fname, int dccpermissions)
g_free (src_fs);
}
+const char *
+get_default_download_dir(void)
+{
+ const gchar *ddir;
+
+ ddir = g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD);
+ if (!ddir)
+ ddir = g_get_user_special_dir( G_USER_DIRECTORY_DESKTOP );
+ if (!ddir)
+ ddir = g_get_home_dir ();
+ return ddir;
+}
+
int
mkdir_utf8 (char *dir)
{
diff --git a/src/common/util.h b/src/common/util.h
index b73c03e..a3c0d67 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -43,6 +43,7 @@ int strip_hidden_attribute (char *src, char *dst);
char *errorstring (int err);
int waitline (int sok, char *buf, int bufsize, int);
unsigned long make_ping_time (void);
+const char *get_default_download_dir (void);
void move_file_utf8 (char *src_dir, char *dst_dir, char *fname, int dccpermissions);
int mkdir_utf8 (char *dir);
int token_foreach (char *str, char sep, int (*callback) (char *str, void *ud), void *ud);
diff --git a/src/fe-gnome/preferences-page-dcc.c b/src/fe-gnome/preferences-page-dcc.c
index b5783c4..4e2de0a 100644
--- a/src/fe-gnome/preferences-page-dcc.c
+++ b/src/fe-gnome/preferences-page-dcc.c
@@ -25,6 +25,8 @@
#include "preferences-page-dcc.h"
#include "preferences-dialog.h"
#include "util.h"
+
+#include "../common/util.h"
#include "../common/xchat.h"
#include "../common/xchatc.h"
@@ -93,10 +95,12 @@ preferences_page_dcc_new (gpointer prefs_dialog, GtkBuilder *xml)
page->special_ip_address = special_ip_address;
+ gtk_file_chooser_add_shortcut_folder(GTK_FILE_CHOOSER (download_dir_button), get_default_download_dir(), NULL);
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (download_dir_button), prefs.dccdir);
if (strlen (prefs.dcc_completed_dir) == 0) {
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (completed_dir_button), prefs.dccdir);
} else {
+ gtk_file_chooser_add_shortcut_folder(GTK_FILE_CHOOSER (completed_dir_button), get_default_download_dir(), NULL);
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (completed_dir_button), prefs.dcc_completed_dir);
}
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (convert_spaces), prefs.dcc_send_fillspaces);
diff --git a/src/fe-gnome/preferences.c b/src/fe-gnome/preferences.c
index 2801b96..538b9b5 100644
--- a/src/fe-gnome/preferences.c
+++ b/src/fe-gnome/preferences.c
@@ -27,6 +27,7 @@
#include "palette.h"
#include "../common/xchat.h"
#include "../common/xchatc.h"
+#include "../common/util.h"
#include "gui.h"
static void nickname_changed (GConfClient *client, guint cnxn_id,
@@ -86,6 +87,7 @@ static void hook_preference (GConfClient *client, GConfEntry entry, gchar *path,
void
load_preferences (void)
{
+ gchar *ddir;
GConfClient *client = gconf_client_get_default ();
GConfEntry entry;
@@ -109,7 +111,9 @@ load_preferences (void)
g_object_unref (client);
- strncpy (prefs.dccdir, get_save_directory(), sizeof (prefs.dccdir));
+ ddir = get_save_directory ();
+ g_utf8_strncpy (prefs.dccdir, ddir, sizeof (prefs.dccdir));
+ g_free (ddir);
}
void set_version (void)
@@ -178,46 +182,13 @@ gchar *
get_save_directory(void)
{
char *dir;
- if (0 == strlen (prefs.dccdir)) {
- dir = NULL;
+ if ( !prefs.dccdir || 0 == strlen (prefs.dccdir) ||
+ (prefs.dccdir[0] == '~' && prefs.dccdir[1] == '/') ||
+ g_file_test (prefs.dccdir, G_FILE_TEST_IS_DIR) == FALSE ) {
+ dir = g_strdup (get_default_download_dir());
} else {
dir = g_strdup (prefs.dccdir);
}
- /* Starts with ~/ ? */
- if (dir != NULL && dir[0] == '~' && dir[1] == '/') {
- dir = g_build_filename (g_get_home_dir (),
- dir + 2, NULL);
- }
-
- /* Try ~/Desktop/Downloads */
- if (dir == NULL || strlen (dir) == 0 ||
- g_file_test (dir, G_FILE_TEST_IS_DIR) == FALSE) {
- const char *translated_folder;
- char *converted;
-
- g_free (dir);
- /* The name of the default downloads folder,
- * Needs to be the same as Epiphany's */
- translated_folder = _("Downloads");
-
- converted = g_filename_from_utf8 (translated_folder, -1, NULL,
- NULL, NULL);
- dir = g_build_filename (g_get_home_dir (), "Desktop",
- converted, NULL);
- g_free (converted);
- }
-
- /* Try ~/Desktop */
- if (g_file_test (dir, G_FILE_TEST_IS_DIR) == FALSE) {
- g_free (dir);
- dir = g_build_filename (g_get_home_dir (), "Desktop", NULL);
- }
-
- /* Try ~/ */
- if (g_file_test (dir, G_FILE_TEST_IS_DIR) == FALSE) {
- g_free (dir);
- dir = g_strdup (g_get_home_dir ());
- }
return dir;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]