aboutsummaryrefslogtreecommitdiffstats
path: root/embed
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2004-06-07 22:19:54 +0800
committerChristian Persch <chpe@src.gnome.org>2004-06-07 22:19:54 +0800
commit516de2813ef99889cf76c14dc00183fe3459298f (patch)
tree38fd1d44198d10b5b39b1e193035f69c58df2af2 /embed
parent934fa0b4b992c413ee5e8f654555b67d15f74ffd (diff)
downloadgsoc2013-epiphany-516de2813ef99889cf76c14dc00183fe3459298f.tar.gz
gsoc2013-epiphany-516de2813ef99889cf76c14dc00183fe3459298f.tar.zst
gsoc2013-epiphany-516de2813ef99889cf76c14dc00183fe3459298f.zip
Fix setting default filename in the !modeSave case.
2004-06-07 Christian Persch <chpe@cvs.gnome.org> * embed/mozilla/FilePicker.cpp: Fix setting default filename in the !modeSave case.
Diffstat (limited to 'embed')
-rw-r--r--embed/mozilla/FilePicker.cpp55
-rw-r--r--embed/mozilla/FilePicker.h2
2 files changed, 26 insertions, 31 deletions
diff --git a/embed/mozilla/FilePicker.cpp b/embed/mozilla/FilePicker.cpp
index 816eadee5..c129a29d3 100644
--- a/embed/mozilla/FilePicker.cpp
+++ b/embed/mozilla/FilePicker.cpp
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2001 Philip Langdale
- * Copyright (C) 2003 Christian Persch
+ * Copyright (C) 2003, 2004 Christian Persch
*
* 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
@@ -241,25 +241,11 @@ NS_IMETHODIMP GFilePicker::GetDefaultString(PRUnichar **aDefaultString)
LOG ("GFilePicker::GetDefaultString")
- char *filename, *converted;
- filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (mDialog));
- if (filename != NULL)
- {
- converted = g_filename_to_utf8(filename, -1, NULL, NULL, NULL);
-
- nsEmbedString defaultString;
#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1)
- NS_CStringToUTF16 (nsEmbedCString(converted),
- NS_CSTRING_ENCODING_UTF8, aDefaultString);
+ aDefaultString = mDefaultString;
#else
- NS_CStringToUTF16 (nsEmbedCString(converted),
- NS_CSTRING_ENCODING_UTF8, defaultString);
- *aDefaultString = NS_StringCloneData (defaultString);
+ *aDefaultString = NS_StringCloneData (mDefaultString);
#endif
-
- g_free (filename);
- g_free (converted);
- }
return NS_OK;
}
@@ -272,25 +258,18 @@ NS_IMETHODIMP GFilePicker::SetDefaultString(const PRUnichar *aDefaultString)
{
NS_ENSURE_TRUE (mDialog, NS_ERROR_FAILURE);
- if (mMode != nsIFilePicker::modeSave) return NS_ERROR_FAILURE;
+ mDefaultString.Assign (aDefaultString);
-#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1)
- if (aDefaultString.Length())
-#else
- if (aDefaultString)
-#endif
+ if (mMode == nsIFilePicker::modeSave)
{
nsEmbedCString defaultString;
-#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1)
- NS_UTF16ToCString (aDefaultString, NS_CSTRING_ENCODING_UTF8,
+ NS_UTF16ToCString (mDefaultString, NS_CSTRING_ENCODING_UTF8,
defaultString);
-#else
- NS_UTF16ToCString (nsEmbedString(aDefaultString),
- NS_CSTRING_ENCODING_UTF8, defaultString);
-#endif
LOG ("GFilePicker::SetDefaultString %s", defaultString.get())
+ if (!defaultString.Length()) return NS_ERROR_FAILURE;
+
/* set_current_name takes UTF-8, not a filename */
gtk_file_chooser_set_current_name
(GTK_FILE_CHOOSER (mDialog), defaultString.get());
@@ -367,8 +346,22 @@ NS_IMETHODIMP GFilePicker::SetDisplayDirectory(nsILocalFile *aDisplayDirectory)
LOG ("GFilePicker::SetDisplayDirectory to %s", dir.get())
- gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (mDialog),
- dir.get());
+ if (mDefaultString.Length() && mMode != nsIFilePicker::modeSave)
+ {
+ nsEmbedCString defaultString;
+ NS_UTF16ToCString (mDefaultString, NS_CSTRING_ENCODING_NATIVE_FILESYSTEM,
+ defaultString);
+
+ char *filename = g_build_filename (dir.get(), defaultString.get(), NULL);
+ LOG ("Setting filename to %s", filename);
+ gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (mDialog), filename);
+ g_free (filename);
+ }
+ else
+ {
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (mDialog),
+ dir.get());
+ }
return NS_OK;
}
diff --git a/embed/mozilla/FilePicker.h b/embed/mozilla/FilePicker.h
index cf6a7f68f..a0578a860 100644
--- a/embed/mozilla/FilePicker.h
+++ b/embed/mozilla/FilePicker.h
@@ -24,6 +24,7 @@
#include <nsIFilePicker.h>
#include <nsISupports.h>
+#include <nsEmbedString.h>
#include "ephy-file-chooser.h"
@@ -54,6 +55,7 @@ public:
private:
EphyFileChooser *mDialog;
PRInt16 mMode;
+ nsEmbedString mDefaultString;
};
#endif