summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cba014f)
raw | patch | inline | side by side (parent: cba014f)
author | albinsunnanbo <albinsunnanbo@users.sourceforge.net> | |
Thu, 13 Mar 2008 14:24:00 +0000 (14:24 +0000) | ||
committer | albinsunnanbo <albinsunnanbo@users.sourceforge.net> | |
Thu, 13 Mar 2008 14:24:00 +0000 (14:24 +0000) |
index 381b02b084cef9e5a20f246100f1495cec58b8c3..da60c8821c6d21aea20884a3c920d4717d62a2e2 100644 (file)
_tempfd(0)
{
try {
- _tempfd = Glib::file_open_tmp(_filename, "ink_ext_XXXXXX.svg");
+ _tempfd = Inkscape::IO::file_open_tmp(_filename, "ink_ext_XXXXXX.svg");
} catch (...) {
/// \todo Popup dialog here
return;
std::string tempfilename_out;
int tempfd_out = 0;
try {
- tempfd_out = Glib::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX");
+ tempfd_out = Inkscape::IO::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX");
} catch (...) {
/// \todo Popup dialog here
return NULL;
std::string tempfilename_in;
int tempfd_in = 0;
try {
- tempfd_in = Glib::file_open_tmp(tempfilename_in, "ink_ext_XXXXXX");
+ tempfd_in = Inkscape::IO::file_open_tmp(tempfilename_in, "ink_ext_XXXXXX");
} catch (...) {
/// \todo Popup dialog here
return;
std::string tempfilename_out;
int tempfd_out = 0;
try {
- tempfd_out = Glib::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX.svg");
+ tempfd_out = Inkscape::IO::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX.svg");
} catch (...) {
/// \todo Popup dialog here
return;
index fb7d6a6f91bbcb1fa8f9f296f309e28498df9118..8b0ba97a86021037c6b8b504ebd5a3f343ad628b 100644 (file)
@@ -195,7 +195,7 @@ XSLT::save(Inkscape::Extension::Output */*module*/, SPDocument *doc, gchar const
std::string tempfilename_out;
int tempfd_out = 0;
try {
- tempfd_out = Glib::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX");
+ tempfd_out = Inkscape::IO::file_open_tmp(tempfilename_out, "ink_ext_XXXXXX");
} catch (...) {
/// \todo Popup dialog here
return;
diff --git a/src/io/sys.cpp b/src/io/sys.cpp
index a1e693a24d978f9cd9a6e8cdcf4234189ac1c661..b184988fd7a21be408dd65e6ad53af2570df8fde 100644 (file)
--- a/src/io/sys.cpp
+++ b/src/io/sys.cpp
return retval;
}
+/*
+ * Wrapper around Glib::file_open_tmp()
+ * Returns a handle to the temp file
+ * name_used contains the actual name used
+ *
+ * Returns:
+ * A file handle (as from open()) to the file opened for reading and writing.
+ * The file is opened in binary mode on platforms where there is a difference.
+ * The file handle should be closed with close().
+ *
+ * Note:
+ * On Windows Vista Glib::file_open_tmp fails with the current version of glibmm
+ * A special case is implemented for WIN32. This can be removed if the issue is fixed
+ * in future versions of glibmm
+ * */
+int Inkscape::IO::file_open_tmp(std::string& name_used, const std::string& prefix)
+{
+#ifndef WIN32
+ return Glib::file_open_tmp(name_used, prefix);
+#else
+ /* Special case for WIN32 due to a bug in glibmm
+ * (only needed for Windows Vista, but since there is only one windows build all builds get the workaround)
+ * The workaround can be removed if the bug is fixed in glibmm
+ *
+ * The code is mostly identical to the implementation in glibmm
+ * http://svn.gnome.org/svn/glibmm/branches/glibmm-2-12/glib/src/fileutils.ccg
+ * */
+
+ std::string basename_template (prefix);
+ basename_template += "XXXXXX"; // this sillyness shouldn't be in the interface
+
+ GError* error = 0;
+ gchar *buf_name_used;
+
+ gint fileno = g_file_open_tmp(basename_template.c_str(), &buf_name_used, &error);
+
+ if(error)
+ Glib::Error::throw_exception(error);
+
+ name_used = g_strdup(buf_name_used);
+ g_free(buf_name_used);
+ return fileno;
+#endif
+}
+
bool Inkscape::IO::file_test( char const *utf8name, GFileTest test )
{
bool exists = false;
diff --git a/src/io/sys.h b/src/io/sys.h
index fd39c630b9ea7df2b2a22d3da32e3e85a8180080..b31602d9129bc5df57fe4135bbc4474f54052359 100644 (file)
--- a/src/io/sys.h
+++ b/src/io/sys.h
#include <glib/gtypes.h>
#include <glib/gdir.h>
#include <glib/gfileutils.h>
+#include <string>
/*#####################
## U T I L I T Y
int mkdir_utf8name( char const *utf8name );
+int file_open_tmp( std::string& name_used, const std::string& prefix );
+
bool file_test( char const *utf8name, GFileTest test );
GDir *dir_open(gchar const *utf8name, guint flags, GError **error);
index e9ef6344369ec8910b73402a0d1a02a27576c372..19b739061d9c14b716f791857e0f1f70871f1cd0 100644 (file)
#include "interface.h"
#include "gc-core.h"
#include <dialogs/dialog-events.h>
+#include "io/sys.h"
namespace Inkscape
{
// create file path
const std::string tmptemplate = "ocal-";
std::string tmpname;
- int fd = Glib::file_open_tmp(tmpname, tmptemplate);
+ int fd = Inkscape::IO::file_open_tmp(tmpname, tmptemplate);
if (fd<0) {
g_warning("Error creating temp file");
return;
index 3deb4204ad470a9aa3c8a29659b92ae69fb6cd74..52ff07ee6d5d2d409454fb9c202a91af58414269 100644 (file)
--- a/src/ui/dialog/print.cpp
+++ b/src/ui/dialog/print.cpp
#include "unit-constants.h"
#include "helper/png-write.h"
#include "svg/svg-color.h"
+#include "io/sys.h"
static void
std::string tmp_base = "inkscape-print-png-XXXXXX";
int tmp_fd;
- if ( (tmp_fd = Glib::file_open_tmp (tmp_png, tmp_base)) >= 0) {
+ if ( (tmp_fd = Inkscape::IO::file_open_tmp (tmp_png, tmp_base)) >= 0) {
close(tmp_fd);
guint32 bgcolor = 0x00000000;