glom r1461 - in trunk: . glom glom/libglom glom/libglom/document
- From: murrayc svn gnome org
- To: svn-commits-list gnome org
- Subject: glom r1461 - in trunk: . glom glom/libglom glom/libglom/document
- Date: Tue, 18 Mar 2008 14:11:41 +0000 (GMT)
Author: murrayc
Date: Tue Mar 18 14:11:40 2008
New Revision: 1461
URL: http://svn.gnome.org/viewvc/glom?rev=1461&view=rev
Log:
2008-03-18 Murray Cumming <murrayc murrayc com>
* configure.in: Depend on the new unstable bakery-2.6 API.
* glom/application.cc:
* glom/base_db.cc:
* glom/libglom/connectionpool.cc:
* glom/libglom/document/document_glom.cc:
* glom/main.cc:
* glom/xsl_utils.cc: Use giomm instead of Gnome::Vfs.
Modified:
trunk/ChangeLog
trunk/configure.in
trunk/glom/application.cc
trunk/glom/base_db.cc
trunk/glom/libglom/connectionpool.cc
trunk/glom/libglom/document/document_glom.cc
trunk/glom/main.cc
trunk/glom/xsl_utils.cc
Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in (original)
+++ trunk/configure.in Tue Mar 18 14:11:40 2008
@@ -86,7 +86,7 @@
fi
# Do not require, goocanvas and gtksourceviewmm in client only mode
-REQUIRED_LIBS="bakery-2.4 >= 2.4.2 gtkmm-2.4 >= 2.10 glibmm-2.4 >= 2.14.1 gthread-2.0 gnome-vfsmm-2.6 >= 2.11.1 libxslt >= 1.1.10 pygda-3.0 pygtk-2.0 >= 2.6.0 libgnome-2.0 >= 2.6.0 libgdamm-3.0 >= 2.9.81 libgda-3.0 >= 3.0.1 libgda-postgres-3.0 goocanvasmm-1.0 >= 0.2.0"
+REQUIRED_LIBS="bakery-2.6 >= 2.4.2 gtkmm-2.4 >= 2.10 gthread-2.0 gnome-vfsmm-2.6 >= 2.11.1 libxslt >= 1.1.10 pygda-3.0 pygtk-2.0 >= 2.6.0 libgnome-2.0 >= 2.6.0 libgdamm-3.0 >= 2.9.82 libgda-3.0 >= 3.0.1 libgda-postgres-3.0 goocanvasmm-1.0 >= 0.2.0"
if test $enable_client_only != yes; then
REQUIRED_LIBS="$REQUIRED_LIBS gtksourceviewmm-2.0"
fi
Modified: trunk/glom/application.cc
==============================================================================
--- trunk/glom/application.cc (original)
+++ trunk/glom/application.cc Tue Mar 18 14:11:40 2008
@@ -35,7 +35,7 @@
#include <cstdio>
#include <memory> //For std::auto_ptr<>
-#include <libgnomevfsmm.h>
+#include <giomm.h>
#include <sstream> //For stringstream.
#include <glibmm/i18n.h>
@@ -730,36 +730,46 @@
Bakery::App_WithDoc_Gtk::on_menu_file_close();
}
-static bool uri_is_writable(const Glib::RefPtr<const Gnome::Vfs::Uri>& uri)
+//Copied from bakery:
+static bool uri_is_writable(const Glib::RefPtr<const Gio::File>& uri)
{
if(!uri)
return false;
+ Glib::RefPtr<const Gio::FileInfo> file_info;
+
#ifdef GLIBMM_EXCEPTIONS_ENABLED
- // TODO: What if this throws?
- Glib::RefPtr<const Gnome::Vfs::FileInfo> file_info = uri->get_file_info(Gnome::Vfs::FILE_INFO_GET_ACCESS_RIGHTS);
+ try
+ {
+ file_info = uri->query_info(G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
+ }
+ catch(const Glib::Error& /* ex */)
+ {
+ return false;
+ }
#else
- std::auto_ptr<Gnome::Vfs::exception> error;
- Glib::RefPtr<const Gnome::Vfs::FileInfo> file_info = uri->get_file_info(Gnome::Vfs::FILE_INFO_GET_ACCESS_RIGHTS, error);
- if(error.get() != NULL) return false;
+ std::auto_ptr<Gio::Error> error;
+ file_info = uri->query_info(G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, Gio::FILE_QUERY_INFO_NONE, error);
+ if(error.get())
+ return false;
#endif
+
if(file_info)
{
- const Gnome::Vfs::FilePermissions permissions = file_info->get_permissions();
- return ((permissions & Gnome::Vfs::PERM_ACCESS_WRITABLE) == Gnome::Vfs::PERM_ACCESS_WRITABLE);
+ return file_info->get_attribute_boolean(G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
}
else
- return true; //Not every URI protocol supports FILE_INFO_GET_ACCESS_RIGHTS, so assume that it's writable and complain later.
+ return true; //Not every URI protocol supports access rights, so assume that it's writable and complain later.
}
Glib::ustring App_Glom::get_file_uri_without_extension(const Glib::ustring& uri)
{
- Glib::RefPtr<Gnome::Vfs::Uri> vfs_uri = Gnome::Vfs::Uri::create(uri);
- if(!vfs_uri)
+ Glib::RefPtr<Gio::File> file = Gio::File::create_for_uri(uri);
+ if(!file)
return uri; //Actually an error.
- const Glib::ustring filename_part = vfs_uri->extract_short_name();
+ const Glib::ustring filename_part = file->get_basename();
const Glib::ustring::size_type pos_dot = filename_part.rfind(".");
if(pos_dot == Glib::ustring::npos)
@@ -767,12 +777,12 @@
else
{
const Glib::ustring filename_part_without_ext = filename_part.substr(0, pos_dot);
- const Glib::ustring uri_parent = vfs_uri->extract_dirname();
- Glib::RefPtr<Gnome::Vfs::Uri> vfs_uri_parent = Gnome::Vfs::Uri::create(uri_parent);
- Glib::RefPtr<Gnome::Vfs::Uri> vfs_uri_without_extension = vfs_uri_parent->append_string(filename_part_without_ext);
+ //Use the Gio::File API to manipulate the URI:
+ Glib::RefPtr<Gio::File> parent = file->get_parent();
+ Glib::RefPtr<Gio::File> file_without_extension = parent->get_child(filename_part_without_ext);
- return vfs_uri_without_extension->to_string();
+ return file_without_extension->get_uri();
}
}
@@ -1925,26 +1935,11 @@
file_uri = document->get_file_uri_with_extension(file_uri);
bool bUseThisFileUri = true;
-
- //Check whether file exists already:
- {
- // Try to open the input file.
- Gnome::Vfs::Handle read_handle;
- try
- {
- read_handle.open(file_uri, Gnome::Vfs::OPEN_READ);
-
- //It does (there was no exception), so ask the user to confirm overwrite:
- const bool bOverwrite = true; //The FileChooser asked already. ui_ask_overwrite(file_uri);
-
- //Respond to button that was clicked:
- bUseThisFileUri = bOverwrite;
- }
- catch(const Gnome::Vfs::exception& ex)
- {
- bUseThisFileUri = true; //It does not exist.
- }
- }
+ //We previously checked whether the file existed,
+ //but The FileChooser checks that already,
+ //so Bakery doesn't bother checking anymore,
+ //and our old test always set bUseThisFileUri to true anyway. murryac.
+ //TODO: So remove this bool. murrayc.
//Save to this filepath:
if(bUseThisFileUri)
@@ -2158,11 +2153,15 @@
{
//Just start with the parent folder,
//instead of the whole name, to avoid overwriting:
- Glib::RefPtr<Gnome::Vfs::Uri> vfs_uri = Gnome::Vfs::Uri::create(old_file_uri);
- if(vfs_uri)
+ Glib::RefPtr<Gio::File> gio_file = Gio::File::create_for_uri(old_file_uri);
+ if(gio_file)
{
- Glib::ustring uri_parent = vfs_uri->extract_dirname();
- fileChooser_Save->set_uri(uri_parent);
+ Glib::RefPtr<Gio::File> parent = gio_file->get_parent();
+ if(parent)
+ {
+ const Glib::ustring uri_parent = parent->get_uri();
+ fileChooser_Save->set_uri(uri_parent);
+ }
}
}
@@ -2195,8 +2194,8 @@
const Glib::ustring uri = get_file_uri_without_extension(uri_chosen);
//Check whether the file exists, and that we have rights to it:
- Glib::RefPtr<Gnome::Vfs::Uri> vfs_uri = Gnome::Vfs::Uri::create(uri);
- if(!vfs_uri)
+ Glib::RefPtr<Gio::File> file = Gio::File::create_for_uri(uri);
+ if(!file)
return Glib::ustring(); //Failure.
@@ -2205,7 +2204,7 @@
{
//Check whether we have rights to the file to change it:
//Really, GtkFileChooser should do this for us.
- if(!uri_is_writable(vfs_uri))
+ if(!uri_is_writable(file))
{
//Warn the user:
ui_warning(gettext("Read-only File."), gettext("You may not overwrite the existing file, because you do not have sufficient access rights."));
@@ -2216,10 +2215,10 @@
//Check whether we have rights to the directory, to create a new file in it:
//Really, GtkFileChooser should do this for us.
- Glib::RefPtr<const Gnome::Vfs::Uri> vfs_uri_parent = vfs_uri->get_parent();
- if(vfs_uri_parent)
+ Glib::RefPtr<const Gio::File> parent = file->get_parent();
+ if(parent)
{
- if(!uri_is_writable(vfs_uri_parent))
+ if(!uri_is_writable(parent))
{
//Warn the user:
ui_warning(gettext("Read-only Directory."), gettext("You may not create a file in this directory, because you do not have sufficient access rights."));
@@ -2252,8 +2251,8 @@
//Check that the directory does not exist already.
//The GtkFileChooser could not check for that because it could not know that we would create a directory based on the filename:
//Note that uri has no extension at this point:
- Glib::RefPtr<Gnome::Vfs::Uri> vfsuri = Gnome::Vfs::Uri::create(uri);
- if(vfsuri->uri_exists())
+ Glib::RefPtr<Gio::File> dir = Gio::File::create_for_uri(uri);
+ if(dir->query_exists())
{
ui_warning(_("Directory Already Exists"), _("There is an existing directory with the same name as the directory that should be created for the new database files. You should specify a different filename to use a new directory instead."));
try_again = true; //Try again.
@@ -2265,20 +2264,21 @@
//The 0 prefix means that this is octal.
try
{
- Gnome::Vfs::Handle::make_directory(uri, 0770 /* leading zero means octal */);
+ //TODO: ensure that we use 0770? murrayc.
+ dir->make_directory();
}
- catch(const Gnome::Vfs::exception& ex)
+ catch(const Gio::Error& ex)
{
- std::cerr << "Error during make_directory(): " << ex.what() << std::endl;
+ std::cerr << "Error during Gio::File::make_directory(): " << ex.what() << std::endl;
}
//Add the filename (Note that the caller will add the extension if necessary, so we don't do it here.)
- Glib::RefPtr<Gnome::Vfs::Uri> uri_with_ext = Gnome::Vfs::Uri::create(uri_chosen);
- const Glib::ustring filename_part = uri_with_ext->extract_short_name();
+ Glib::RefPtr<Gio::File> file_with_ext = Gio::File::create_for_uri(uri_chosen);
+ const Glib::ustring filename_part = file_with_ext->get_basename();
//Add the filename part to the newly-created directory:
- Glib::RefPtr<Gnome::Vfs::Uri> uri_whole = vfs_uri->append_string(filename_part);
- return uri_whole->to_string();
+ Glib::RefPtr<Gio::File> file_whole = dir->get_child(filename_part);
+ return file_whole->get_uri();
}
#endif // !GLOM_ENABLE_CLIENT_ONLY
Modified: trunk/glom/base_db.cc
==============================================================================
--- trunk/glom/base_db.cc (original)
+++ trunk/glom/base_db.cc Tue Mar 18 14:11:40 2008
@@ -250,23 +250,40 @@
if(strQuery.compare(0, 6, "SELECT") == 0)
{
#ifdef GLIBMM_EXCEPTIONS_ENABLED
- result = gda_connection->execute_select_command(strQuery);
+ try
+ {
+ result = gda_connection->execute_select_command(strQuery);
+ }
+ catch(const Gnome::Gda::ConnectionError& ex)
+ {
+ std::cout << "debug: Base_DB::query_execute(): exception from execute_select_command(): " << ex.what() << std::endl;
+ }
#else
std::auto_ptr<Glib::Error> error;
result = gda_connection->execute_select_command(strQuery, error);
// Ignore error, empty datamodel is handled below
-#endif
+#endif //GLIBMM_EXCEPTIONS_ENABLED
}
else
{
- std::auto_ptr<Glib::Error> error;
+
#ifdef GLIBMM_EXCEPTIONS_ENABLED
- if(gda_connection->execute_non_select_command(strQuery) != -1)
+ int execute_result = -1;
+ try
+ {
+ execute_result = gda_connection->execute_non_select_command(strQuery);
+ }
+ catch(const Gnome::Gda::ConnectionError& ex)
+ {
+ std::cout << "debug: Base_DB::query_execute(): exception from execute_non_select_command(): " << ex.what() << std::endl;
+ }
#else
- if(gda_connection->execute_non_select_command(strQuery, error) != -1)
- if(error.get() == NULL)
-#endif
- result = Gnome::Gda::DataModelArray::create(1);
+ std::auto_ptr<Glib::Error> error;
+ execute_result = gda_connection->execute_non_select_command(strQuery, error);
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+
+ if(execute_result != -1)
+ result = Gnome::Gda::DataModelArray::create(1);
}
if(!result)
Modified: trunk/glom/libglom/connectionpool.cc
==============================================================================
--- trunk/glom/libglom/connectionpool.cc (original)
+++ trunk/glom/libglom/connectionpool.cc Tue Mar 18 14:11:40 2008
@@ -23,7 +23,7 @@
#include <glom/libglom/connectionpool.h>
#include <glom/libglom/document/document_glom.h>
#include <bakery/bakery.h>
-#include <libgnomevfsmm.h>
+#include <giomm.h>
#include <glib/gstdio.h> //For g_remove().
#include <glom/libglom/spawn_with_feedback.h>
#include <glom/libglom/utils.h>
@@ -769,8 +769,8 @@
bool ConnectionPool::directory_exists_uri(const std::string& uri)
{
- Glib::RefPtr<Gnome::Vfs::Uri> vfsuri = Gnome::Vfs::Uri::create(uri);
- return vfsuri->uri_exists();
+ Glib::RefPtr<Gio::File> file = Gio::File::create_for_uri(uri);
+ return file && file->query_exists();
}
#ifndef GLOM_ENABLE_CLIENT_ONLY
@@ -1002,9 +1002,11 @@
//Create these files: environment pg_hba.conf pg_ident.conf start.conf
const std::string dbdir_uri_config = dbdir_uri + "/config";
- create_text_file(dbdir_uri_config + "/pg_hba.conf", DEFAULT_CONFIG_PG_HBA);
+ const bool hba_conf_creation_succeeded = create_text_file(dbdir_uri_config + "/pg_hba.conf", DEFAULT_CONFIG_PG_HBA);
+ g_assert(hba_conf_creation_succeeded);
- create_text_file(dbdir_uri_config + "/pg_ident.conf", DEFAULT_CONFIG_PG_IDENT);
+ const bool ident_conf_creation_succeeded = create_text_file(dbdir_uri_config + "/pg_ident.conf", DEFAULT_CONFIG_PG_IDENT);
+ g_assert(ident_conf_creation_succeeded);
//Check that there is not an existing data directory:
const std::string dbdir_data = dbdir + "/data";
@@ -1020,8 +1022,12 @@
return false;
}
+ //Get file:// URI for the tmp/ directory:
const std::string temp_pwfile = Glib::build_filename(Glib::get_tmp_dir(), "glom_initdb_pwfile");
- create_text_file(temp_pwfile, get_password());
+ Glib::RefPtr<Gio::File> file = Gio::File::create_for_path(temp_pwfile);
+ const std::string temp_pwfile_uri = file->get_uri();
+ const bool pwfile_creation_succeeded = create_text_file(temp_pwfile_uri, get_password());
+ g_assert(pwfile_creation_succeeded);
const std::string command_initdb = Glib::shell_quote(get_path_to_postgres_executable("initdb")) + " -D \"" + dbdir_data + "\"" +
" -U " + username + " --pwfile=\"" + temp_pwfile + "\"";
@@ -1042,65 +1048,76 @@
bool ConnectionPool::create_text_file(const std::string& file_uri, const std::string& contents)
{
- Gnome::Vfs::Handle write_handle;
+ Glib::RefPtr<Gio::File> file = Gio::File::create_for_uri(file_uri);
+ Glib::RefPtr<Gio::FileOutputStream> stream;
+ //Create the file if it does not already exist:
#ifdef GLIBMM_EXCEPTIONS_ENABLED
try
-#else
- std::auto_ptr<Gnome::Vfs::exception> error;
-#endif
{
- //0660 means "this user and his group can read and write this non-executable file".
- //The 0 prefix means that this is octal.
-#ifdef GLIBMM_EXCEPTIONS_ENABLED
- write_handle.create(file_uri, Gnome::Vfs::OPEN_WRITE, false, 0660 /* leading zero means octal */);
-#else
- write_handle.create(file_uri, Gnome::Vfs::OPEN_WRITE, false, 0660 /* leading zero means octal */, error);
-#endif
+ if(file->query_exists())
+ {
+ stream = file->replace(); //Instead of append_to().
+ }
+ else
+ {
+ //By default files created are generally readable by everyone, but if we pass FILE_CREATE_PRIVATE in flags the file will be made readable only to the current user, to the level that is supported on the target filesystem.
+ //TODO: Do we want to specify 0660 exactly? (means "this user and his group can read and write this non-executable file".)
+ stream = file->create_file();
+ }
}
-#ifdef GLIBMM_EXCEPTIONS_ENABLED
- catch(const Gnome::Vfs::exception& ex)
+ catch(const Gio::Error& ex)
{
#else
+ std::auto_ptr<Gio::Error> error;
+ stream.create(error);
if(error.get() != NULL)
{
- const Gnome::Vfs::exception& ex = *error.get();
+ const Gio::Error& ex = *error.get();
#endif
- std::cerr << "ConnectionPool::create_text_file(): exception caught during file create: " << ex.what() << std::endl;
-
// If the operation was not successful, print the error and abort
+ std::cerr << "ConnectionPool::create_text_file(): exception while creating file." << std::endl
+ << " file uri:" << file_uri << std::endl
+ << " error:" << ex.what() << std::endl;
return false; // print_error(ex, output_uri_string);
}
+
+ if(!stream)
+ return false;
+
+
+ gsize bytes_written = 0;
+ const std::string::size_type contents_size = contents.size();
#ifdef GLIBMM_EXCEPTIONS_ENABLED
try
-#endif
{
//Write the data to the output uri
-#ifdef GLIBMM_EXCEPTIONS_ENABLED
- GnomeVFSFileSize bytes_written = write_handle.write(contents.data(), contents.size());
-#else
- GnomeVFSFileSize bytes_written = write_handle.write(contents.data(), contents.size(), error);
- if(error.get() != NULL)
-#endif
- if(bytes_written != contents.size())
- return false;
+ bytes_written = stream->write(contents.data(), contents_size);
}
-#ifdef GLIBMM_EXCEPTIONS_ENABLED
- catch(const Gnome::Vfs::exception& ex)
+ catch(const Gio::Error& ex)
{
#else
+ bytes_written = stream->write(contents.data(), contents_size, error);
if(error.get() != NULL)
{
- Gnome::Vfs::exception& ex = *error.get();
+ Gio::Error& ex = *error.get();
#endif
- std::cerr << "ConnectionPool::create_text_file(): exception caught during write: " << ex.what() << std::endl;
-
// If the operation was not successful, print the error and abort
+ std::cerr << "ConnectionPool::create_text_file(): exception while writing to file." << std::endl
+ << " file uri:" << file_uri << std::endl
+ << " error:" << ex.what() << std::endl;
return false; //print_error(ex, output_uri_string);
}
- return true; //Success. (At doing nothing, because nothing needed to be done.)
+ if(bytes_written != contents_size)
+ {
+ std::cerr << "ConnectionPool::create_text_file(): not all bytes written when writing to file." << std::endl
+ << " file uri:" << file_uri << std::endl;
+ return false;
+ }
+
+ return true; //Success.
}
#ifndef GLOM_ENABLE_CLIENT_ONLY
Modified: trunk/glom/libglom/document/document_glom.cc
==============================================================================
--- trunk/glom/libglom/document/document_glom.cc (original)
+++ trunk/glom/libglom/document/document_glom.cc Tue Mar 18 14:11:40 2008
@@ -31,7 +31,7 @@
#include <glom/libglom/data_structure/layout/layoutitem_image.h>
#include <glom/libglom/data_structure/layout/layoutitem_line.h>
#include <glom/libglom/standard_table_prefs_fields.h>
-#include <libgnomevfsmm/uri.h>
+#include <giomm.h>
#include <bakery/Utilities/BusyCursor.h>
#include <glom/libglom/connectionpool.h>
@@ -270,20 +270,20 @@
}
else
{
- Glib::RefPtr<Gnome::Vfs::Uri> vfsuri = Gnome::Vfs::Uri::create(uri_file);
+ //Use Gio::File API to construct the URI:
+ Glib::RefPtr<Gio::File> file = Gio::File::create_for_uri(uri_file);
- Glib::RefPtr<Gnome::Vfs::Uri> vfsuri_parent = vfsuri->get_parent();
- if(vfsuri_parent)
+ Glib::RefPtr<Gio::File> parent = file->get_parent();
+ if(parent)
{
- Glib::RefPtr<Gnome::Vfs::Uri> datadir = vfsuri_parent->append_string("glom_postgres_data");
- return datadir->to_string();
- }
- else
- {
- g_warning("Document_Glom::get_connection_self_hosted_directory_uri(): get_parent() returned empty.");
- return std::string();
+ Glib::RefPtr<Gio::File> datadir = parent->get_child("glom_postgres_data");
+ if(datadir)
+ return datadir->get_uri();
}
}
+
+ g_warning("Document_Glom::get_connection_self_hosted_directory_uri(): returning empty string.");
+ return std::string();
}
#endif // !GLOM_ENABLE_CLIENT_ONLY
Modified: trunk/glom/main.cc
==============================================================================
--- trunk/glom/main.cc (original)
+++ trunk/glom/main.cc Tue Mar 18 14:11:40 2008
@@ -28,7 +28,7 @@
#ifndef GLOM_ENABLE_MAEMO
#include <libgnome/gnome-init.h> // For gnome_program_init().
#endif
-#include <libgnomevfsmm/uri.h>
+#include <giomm.h>
#ifndef GLOM_ENABLE_CLIENT_ONLY
#include <gtksourceviewmm/init.h>
@@ -189,7 +189,7 @@
PySys_SetArgv(argc, argv);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
- try
+ //try
#endif
{
#ifndef GLOM_ENABLE_MAEMO
@@ -223,14 +223,16 @@
if(!input_uri.empty())
{
//Get a URI (file://something) from the filepath:
- input_uri = Gnome::Vfs::Uri::make_from_shell_arg(input_uri);
+ Glib::RefPtr<Gio::File> file = Gio::File::create_for_commandline_arg(input_uri);
+ if(file)
+ input_uri = file->get_uri();
//std::cout << "URI = " << input_uri << std::endl;
}
//debugging:
//input_uri = "file:///home/murrayc/cvs/gnome212/glom/examples/example_smallbusiness.glom";
- bool install_complete;
+ bool install_complete = false;
#ifndef GLOM_ENABLE_CLIENT_ONLY
//Check that PostgreSQL is really available:
install_complete = Glom::ConnectionPool::check_postgres_is_available_with_warning();
@@ -276,7 +278,7 @@
else
delete pApp_Glom;
}
-#ifdef GLIBMM_EXCEPTIONS_ENABLED
+#if 0 //#ifdef GLIBMM_EXCEPTIONS_ENABLED
catch(const Glib::Exception& ex)
{
//If this happens then comment out the try/catch, and let the debugger show the call stack.
Modified: trunk/glom/xsl_utils.cc
==============================================================================
--- trunk/glom/xsl_utils.cc (original)
+++ trunk/glom/xsl_utils.cc Tue Mar 18 14:11:40 2008
@@ -28,7 +28,7 @@
#include <libxml++/libxml++.h>
#include <libxslt/transform.h>
//#include <libexslt/exslt.h> //For exsltRegisterAll().
-#include <libgnomevfsmm.h>
+#include <giomm.h>
#include <glibmm/i18n.h>
#ifndef GLOM_ENABLE_MAEMO
@@ -60,41 +60,60 @@
const Glib::ustring temp_uri = "file:///tmp/glom_printout.html";
std::cout << "temp_uri=" << temp_uri << std::endl;
- Gnome::Vfs::Handle write_handle;
+ Glib::RefPtr<Gio::File> file = Gio::File::create_for_uri(temp_uri);
+ Glib::RefPtr<Gio::FileOutputStream> stream;
+ //Create the file if it does not already exist:
#ifdef GLIBMM_EXCEPTIONS_ENABLED
try
{
- //0660 means "this user and his group can read and write this non-executable file".
- //The 0 prefix means that this is octal.
- write_handle.create(temp_uri, Gnome::Vfs::OPEN_WRITE, false, 0660 /* leading zero means octal */);
+ if(file->query_exists())
+ {
+ stream = file->replace(); //Instead of append_to().
+ }
+ else
+ {
+ //By default files created are generally readable by everyone, but if we pass FILE_CREATE_PRIVATE in flags the file will be made readable only to the current user, to the level that is supported on the target filesystem.
+ //TODO: Do we want to specify 0660 exactly? (means "this user and his group can read and write this non-executable file".)
+ stream = file->create_file();
+ }
}
- catch(const Gnome::Vfs::exception& ex)
+ catch(const Gio::Error& ex)
{
- // If the operation was not successful, print the error and abort
- return; // print_error(ex, output_uri_string);
- }
#else
- std::auto_ptr<Gnome::Vfs::exception> error;
- write_handle.create(temp_uri, Gnome::Vfs::OPEN_WRITE, false, 0660 /* leading zero means octal */, error);
- if(error.get()) return;
+ std::auto_ptr<Gio::Error> error;
+ stream.create(error);
+ if(error.get() != NULL)
+ {
+ const Gio::Error& ex = *error.get();
#endif
+ // If the operation was not successful, print the error and abort
+ return; // false; // print_error(ex, output_uri_string);
+ }
+ //Write the data to the output uri
+ gsize bytes_written = 0;
+ const Glib::ustring::size_type result_bytes = result.bytes();
#ifdef GLIBMM_EXCEPTIONS_ENABLED
try
{
- //Write the data to the output uri
- /* GnomeVFSFileSize bytes_written = */ write_handle.write(result.data(), result.bytes());
+ bytes_written = stream->write(result.data(), result_bytes);
}
- catch(const Gnome::Vfs::exception& ex)
+ catch(const Gio::Error& ex)
{
- // If the operation was not successful, print the error and abort
- return; //print_error(ex, output_uri_string);
- }
#else
- write_handle.create(temp_uri, Gnome::Vfs::OPEN_WRITE, false, 0660 /* leading zero means octal */, error);
- if(error.get()) return;
+ bytes_written = stream->write(result.data(), result_bytes, error);
+ if(error.get() != NULL)
+ {
+ Gio::Error& ex = *error.get();
#endif
+ // If the operation was not successful, print the error and abort
+ return; // false; //print_error(ex, output_uri_string);
+ }
+
+ if(bytes_written != result_bytes)
+ return; //false
+
//Give the user a clue, in case the web browser opens in the background, for instance in a new tab:
if(parent_window)
@@ -106,8 +125,13 @@
// gnome_vfs_url_show()?
#else
//Use the GNOME browser:
- GError* gerror = 0; // TODO: This leaks memory if an error occurs. We can pass NULL as error if we are not interested in errors.
+ GError* gerror = 0;
gnome_url_show(temp_uri.c_str(), &gerror); //This is in libgnome.
+ if(gerror)
+ {
+ std::cerr << "Error while calling gnome_url_show(): " << gerror->message << std::endl;
+ g_clear_error(&gerror);
+ }
#endif
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]