summaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
authorKris De Gussem <kris.degussem@gmail.com>2012-04-16 13:38:39 +0000
committerKris <Kris.De.Gussem@hotmail.com>2012-04-16 13:38:39 +0000
commit3272764893e96cf7c33c65e6ff7e7b2a3cadd049 (patch)
tree6cb0423cb3baa10be2c3973cca5b03b6ffe51966 /src/ui
parentLoop index type cleanup (diff)
downloadinkscape-3272764893e96cf7c33c65e6ff7e7b2a3cadd049.tar.gz
inkscape-3272764893e96cf7c33c65e6ff7e7b2a3cadd049.zip
some more string class usage as opposed to c-strings to prevent issues
(bzr r11259)
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/dialog/export.cpp366
-rw-r--r--src/ui/dialog/export.h8
2 files changed, 177 insertions, 197 deletions
diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp
index 060a10f63..3d81b4d33 100644
--- a/src/ui/dialog/export.cpp
+++ b/src/ui/dialog/export.cpp
@@ -94,8 +94,8 @@ namespace Dialog {
Export::Export (void) :
UI::Widget::Panel ("", "/dialogs/export/", SP_VERB_DIALOG_EXPORT),
current_key(SELECTION_PAGE),
- original_name(NULL),
- doc_export_name(NULL),
+ original_name(),
+ doc_export_name(),
filename_modified(false),
was_empty(true),
update(false),
@@ -262,7 +262,7 @@ Export::Export (void) :
file_box.add(filename_box);
- original_name = g_strdup(filename_entry.get_text().c_str());
+ original_name = filename_entry.get_text();
// focus is in the filename initially:
filename_entry.grab_focus();
@@ -317,10 +317,6 @@ Export::Export (void) :
Export::~Export (void)
{
- g_free(original_name);
- original_name = NULL;
- g_free(doc_export_name);
- doc_export_name = NULL;
was_empty = TRUE;
selectModifiedConn.disconnect();
@@ -406,7 +402,7 @@ void Export::set_default_filename () {
g_free(name);
}
- doc_export_name = g_strdup(filename_entry.get_text().c_str());
+ doc_export_name = filename_entry.get_text();
}
}
@@ -487,40 +483,36 @@ Gtk::Adjustment * Export::createSpinbutton( gchar const * /*key*/, float val, fl
} // end of createSpinbutton()
-gchar* Export::create_filepath_from_id (const gchar *id, const gchar *file_entry_text) {
+Glib::ustring Export::create_filepath_from_id (Glib::ustring id, const Glib::ustring &file_entry_text) {
- if (id == NULL) /* This should never happen */
+ if (id.empty())
+ { /* This should never happen */
id = "bitmap";
+ }
- gchar *directory = NULL;
+ Glib::ustring directory;
- if (directory == NULL && file_entry_text != NULL && file_entry_text[0] != '\0') {
- // std::cout << "Directory from dialog" << std::endl;
- directory = g_path_get_dirname(file_entry_text);
+ if (!file_entry_text.empty()) {
+ directory = Glib::path_get_dirname(file_entry_text);
}
- if (directory == NULL) {
+ if (directory.empty()) {
/* Grab document directory */
- if ( SP_ACTIVE_DOCUMENT->getURI() ) {
- // std::cout << "Directory from document" << std::endl;
- directory = g_path_get_dirname( SP_ACTIVE_DOCUMENT->getURI() );
+ const gchar* docURI = SP_ACTIVE_DOCUMENT->getURI();
+ if (docURI) {
+ directory = Glib::path_get_dirname(docURI);
}
}
- if (directory == NULL) {
- // std::cout << "Home Directory" << std::endl;
+ if (directory.empty()) {
directory = homedir_path(NULL);
}
- gchar * id_ext = g_strconcat(id, ".png", NULL);
- gchar *filename = g_build_filename(directory, id_ext, NULL);
- g_free(directory);
- g_free(id_ext);
+ Glib::ustring filename = Glib::build_filename(directory, id+".png");
return filename;
}
-void
-Export::onBatchClicked ()
+void Export::onBatchClicked ()
{
if (batch_export.get_active()) {
singleexport_box.set_sensitive(false);
@@ -717,20 +709,18 @@ void Export::onAreaToggled ()
if (SP_ACTIVE_DESKTOP && !filename_modified) {
- const gchar * filename = NULL;
+ Glib::ustring filename;
float xdpi = 0.0, ydpi = 0.0;
switch (key) {
case SELECTION_PAGE:
case SELECTION_DRAWING: {
SPDocument * doc = SP_ACTIVE_DOCUMENT;
- sp_document_get_export_hints (doc, &filename, &xdpi, &ydpi);
+ sp_document_get_export_hints (doc, filename, &xdpi, &ydpi);
- if (filename == NULL) {
- if (doc_export_name != NULL) {
- filename = g_strdup(doc_export_name);
- } else {
- filename = g_strdup("");
+ if (filename.empty()) {
+ if (!doc_export_name.empty()) {
+ filename = doc_export_name;
}
}
break;
@@ -738,11 +728,11 @@ void Export::onAreaToggled ()
case SELECTION_SELECTION:
if ((sp_desktop_selection(SP_ACTIVE_DESKTOP))->isEmpty() == false) {
- sp_selection_get_export_hints (sp_desktop_selection(SP_ACTIVE_DESKTOP), &filename, &xdpi, &ydpi);
+ sp_selection_get_export_hints (sp_desktop_selection(SP_ACTIVE_DESKTOP), filename, &xdpi, &ydpi);
/* If we still don't have a filename -- let's build
one that's nice */
- if (filename == NULL) {
+ if (filename.empty()) {
const gchar * id = NULL;
const GSList * reprlst = sp_desktop_selection(SP_ACTIVE_DESKTOP)->reprList();
for(; reprlst != NULL; reprlst = reprlst->next) {
@@ -753,7 +743,7 @@ void Export::onAreaToggled ()
}
}
- filename = create_filepath_from_id (id, filename_entry.get_text().c_str());
+ filename = create_filepath_from_id (id, filename_entry.get_text());
}
}
break;
@@ -762,9 +752,8 @@ void Export::onAreaToggled ()
break;
}
- if (filename != NULL) {
- g_free(original_name);
- original_name = g_strdup(filename);
+ if (!filename.empty()) {
+ original_name = filename;
filename_entry.set_text(filename);
}
@@ -879,19 +868,18 @@ Glib::ustring Export::filename_add_extension (Glib::ustring filename, Glib::ustr
}
}
-gchar *Export::absolutize_path_from_document_location (SPDocument *doc, const gchar *filename)
+Glib::ustring Export::absolutize_path_from_document_location (SPDocument *doc, const Glib::ustring &filename)
{
- gchar *path = 0;
+ Glib::ustring path;
//Make relative paths go from the document location, if possible:
- if (!g_path_is_absolute(filename) && doc->getURI()) {
- gchar *dirname = g_path_get_dirname(doc->getURI());
- if (dirname) {
- path = g_build_filename(dirname, filename, NULL);
- g_free(dirname);
+ if (!Glib::path_is_absolute(filename) && doc->getURI()) {
+ Glib::ustring dirname = Glib::path_get_dirname(doc->getURI());
+ if (!dirname.empty()) {
+ path = Glib::build_filename(dirname, filename);
}
}
- if (!path) {
- path = g_strdup(filename);
+ if (path.empty()) {
+ path = filename;
}
return path;
}
@@ -923,9 +911,10 @@ void Export::onExport ()
// retrieve export filename hint
const gchar *filename = item->getRepr()->attribute("inkscape:export-filename");
- gchar *path = NULL;
+ Glib::ustring path;
if (!filename) {
- path = create_filepath_from_id(item->getId(), NULL);
+ Glib::ustring tmp;
+ path = create_filepath_from_id(item->getId(), tmp);
} else {
path = absolutize_path_from_document_location(doc, filename);
}
@@ -947,14 +936,14 @@ void Export::onExport ()
if (width > 1 && height > 1) {
/* Do export */
- if (!sp_export_png_file (doc, path,
+ if (!sp_export_png_file (doc, path.c_str(),
*area, width, height, dpi, dpi,
nv->pagecolor,
NULL, NULL, TRUE, // overwrite without asking
hide ? const_cast<GSList *>(sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList()) : NULL
)) {
gchar * error;
- gchar * safeFile = Inkscape::IO::sanitizeString(path);
+ gchar * safeFile = Inkscape::IO::sanitizeString(path.c_str());
error = g_strdup_printf(_("Could not export to filename %s.\n"), safeFile);
sp_ui_error_dialog(error);
g_free(safeFile);
@@ -963,7 +952,6 @@ void Export::onExport ()
}
}
n++;
- g_free(path);
onProgressCallback((float)n/num, prog_dlg);
}
@@ -971,140 +959,86 @@ void Export::onExport ()
//g_object_set_data (G_OBJECT (base), "cancel", (gpointer) 0);
} else {
+ Glib::ustring filename = filename_entry.get_text();
- Glib::ustring filename = filename_entry.get_text();
+ if (filename.empty()){
+ sp_ui_error_dialog(_("You have to enter a filename"));
+ return;
+ }
+
+ float const x0 = getValuePx(x0_adj);
+ float const y0 = getValuePx(y0_adj);
+ float const x1 = getValuePx(x1_adj);
+ float const y1 = getValuePx(y1_adj);
+ float const xdpi = getValue(xdpi_adj);
+ float const ydpi = getValue(ydpi_adj);
+ unsigned long int const width = int(getValue(bmwidth_adj) + 0.5);
+ unsigned long int const height = int(getValue(bmheight_adj) + 0.5);
+
+ if (!((x1 > x0) && (y1 > y0) && (width > 0) && (height > 0))) {
+ sp_ui_error_dialog (_("The chosen area to be exported is invalid"));
+ return;
+ }
- if (filename.empty()){
- sp_ui_error_dialog(_("You have to enter a filename"));
- return;
- }
-
- float const x0 = getValuePx(x0_adj);
- float const y0 = getValuePx(y0_adj);
- float const x1 = getValuePx(x1_adj);
- float const y1 = getValuePx(y1_adj);
- float const xdpi = getValue(xdpi_adj);
- float const ydpi = getValue(ydpi_adj);
- unsigned long int const width = int(getValue(bmwidth_adj) + 0.5);
- unsigned long int const height = int(getValue(bmheight_adj) + 0.5);
-
- if (!((x1 > x0) && (y1 > y0) && (width > 0) && (height > 0))) {
- sp_ui_error_dialog (_("The chosen area to be exported is invalid"));
- return;
- }
+ // make sure that .png is the extension of the file:
+ Glib::ustring const filename_ext = filename_add_extension(filename, "png");
+ filename_entry.set_text(filename_ext);
+ Glib::ustring path = absolutize_path_from_document_location(doc, filename_ext);
- // make sure that .png is the extension of the file:
- Glib::ustring const filename_ext = filename_add_extension(filename, "png");
- filename_entry.set_text(filename_ext);
- gchar *path = absolutize_path_from_document_location(doc, filename_ext.c_str());
+ Glib::ustring dirname = Glib::path_get_dirname(path);
+ if ( dirname.empty()
+ || !Inkscape::IO::file_test(dirname.c_str(), (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) )
+ {
+ gchar *safeDir = Inkscape::IO::sanitizeString(dirname.c_str());
+ gchar *error = g_strdup_printf(_("Directory %s does not exist or is not a directory.\n"),
+ safeDir);
+ sp_ui_error_dialog(error);
+ g_free(safeDir);
+ g_free(error);
+ return;
+ }
- gchar *dirname = g_path_get_dirname(path);
- if ( dirname == NULL
- || !Inkscape::IO::file_test(dirname, (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) )
- {
- gchar *safeDir = Inkscape::IO::sanitizeString(dirname);
- gchar *error = g_strdup_printf(_("Directory %s does not exist or is not a directory.\n"),
- safeDir);
- sp_ui_error_dialog(error);
- g_free(safeDir);
- g_free(error);
- g_free(dirname);
- g_free(path);
- return;
- }
- g_free(dirname);
-
- gchar *fn = g_path_get_basename (path);
- GtkWidget *prog_dlg = create_progress_dialog (Glib::ustring::compose(_("Exporting %1 (%2 x %3)"), fn, width, height));
- g_free (fn);
-
-
- /* Do export */
- if (!sp_export_png_file (sp_desktop_document (SP_ACTIVE_DESKTOP), path,
- Geom::Rect(Geom::Point(x0, y0), Geom::Point(x1, y1)), width, height, xdpi, ydpi,
- nv->pagecolor,
- onProgressCallback, prog_dlg, FALSE,
- hide ? const_cast<GSList *>(sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList()) : NULL
- )) {
- gchar * error;
- gchar * safeFile = Inkscape::IO::sanitizeString(path);
- error = g_strdup_printf(_("Could not export to filename %s.\n"), safeFile);
- sp_ui_error_dialog(error);
- g_free(safeFile);
- g_free(error);
- }
+ Glib::ustring fn = path_get_basename (path);
+ GtkWidget *prog_dlg = create_progress_dialog (Glib::ustring::compose(_("Exporting %1 (%2 x %3)"), fn, width, height));
+
+
+ /* Do export */
+ if (!sp_export_png_file (sp_desktop_document (SP_ACTIVE_DESKTOP), path.c_str(),
+ Geom::Rect(Geom::Point(x0, y0), Geom::Point(x1, y1)), width, height, xdpi, ydpi,
+ nv->pagecolor,
+ onProgressCallback, prog_dlg, FALSE,
+ hide ? const_cast<GSList *>(sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList()) : NULL
+ )) {
+ gchar * error;
+ gchar * safeFile = Inkscape::IO::sanitizeString(path.c_str());
+ error = g_strdup_printf(_("Could not export to filename %s.\n"), safeFile);
+ sp_ui_error_dialog(error);
+ g_free(safeFile);
+ g_free(error);
+ }
- /* Reset the filename so that it can be changed again by changing
- selections and all that */
- g_free(original_name);
- original_name = const_cast<gchar*>(filename_ext.c_str());
- filename_modified = false;
+ /* Reset the filename so that it can be changed again by changing
+ selections and all that */
+ original_name = filename_ext;
+ filename_modified = false;
- gtk_widget_destroy (prog_dlg);
- //g_object_set_data (G_OBJECT (base), "cancel", (gpointer) 0);
+ gtk_widget_destroy (prog_dlg);
+ /* Setup the values in the document */
+ switch (current_key) {
+ case SELECTION_PAGE:
+ case SELECTION_DRAWING: {
+ SPDocument * doc = SP_ACTIVE_DOCUMENT;
+ Inkscape::XML::Node * repr = doc->getReprRoot();
+ bool modified = false;
- /* Setup the values in the document */
- switch (current_key) {
- case SELECTION_PAGE:
- case SELECTION_DRAWING: {
- SPDocument * doc = SP_ACTIVE_DOCUMENT;
- Inkscape::XML::Node * repr = doc->getReprRoot();
- bool modified = false;
-
- bool saved = DocumentUndo::getUndoSensitive(doc);
- DocumentUndo::setUndoSensitive(doc, false);
-
- gchar const *temp_string = repr->attribute("inkscape:export-filename");
- if (temp_string == NULL || (filename_ext != temp_string)) {
- repr->setAttribute("inkscape:export-filename", filename_ext.c_str());
- modified = true;
- }
- temp_string = repr->attribute("inkscape:export-xdpi");
- if (temp_string == NULL || xdpi != atof(temp_string)) {
- sp_repr_set_svg_double(repr, "inkscape:export-xdpi", xdpi);
- modified = true;
- }
- temp_string = repr->attribute("inkscape:export-ydpi");
- if (temp_string == NULL || ydpi != atof(temp_string)) {
- sp_repr_set_svg_double(repr, "inkscape:export-ydpi", ydpi);
- modified = true;
- }
- DocumentUndo::setUndoSensitive(doc, saved);
+ bool saved = DocumentUndo::getUndoSensitive(doc);
+ DocumentUndo::setUndoSensitive(doc, false);
- if (modified) {
- doc->setModifiedSinceSave();
- }
- break;
- }
- case SELECTION_SELECTION: {
- const GSList * reprlst;
- SPDocument * doc = SP_ACTIVE_DOCUMENT;
- bool modified = false;
-
- bool saved = DocumentUndo::getUndoSensitive(doc);
- DocumentUndo::setUndoSensitive(doc, false);
- reprlst = sp_desktop_selection(SP_ACTIVE_DESKTOP)->reprList();
-
- for(; reprlst != NULL; reprlst = reprlst->next) {
- Inkscape::XML::Node * repr = static_cast<Inkscape::XML::Node *>(reprlst->data);
- const gchar * temp_string;
- Glib::ustring dir = Glib::path_get_dirname(filename.c_str());
- const gchar* docURI=SP_ACTIVE_DOCUMENT->getURI();
- Glib::ustring docdir;
- if (docURI)
- {
- docdir = Glib::path_get_dirname(docURI);
- }
- if (repr->attribute("id") == NULL ||
- !(filename_ext.find_last_of(repr->attribute("id")) &&
- ( !docURI ||
- (dir == docdir)))) {
- temp_string = repr->attribute("inkscape:export-filename");
- if (temp_string == NULL || (filename_ext != temp_string)) {
- repr->setAttribute("inkscape:export-filename", filename_ext.c_str());
- modified = true;
- }
+ gchar const *temp_string = repr->attribute("inkscape:export-filename");
+ if (temp_string == NULL || (filename_ext != temp_string)) {
+ repr->setAttribute("inkscape:export-filename", filename_ext.c_str());
+ modified = true;
}
temp_string = repr->attribute("inkscape:export-xdpi");
if (temp_string == NULL || xdpi != atof(temp_string)) {
@@ -1116,18 +1050,63 @@ void Export::onExport ()
sp_repr_set_svg_double(repr, "inkscape:export-ydpi", ydpi);
modified = true;
}
+ DocumentUndo::setUndoSensitive(doc, saved);
+
+ if (modified) {
+ doc->setModifiedSinceSave();
+ }
+ break;
}
- DocumentUndo::setUndoSensitive(doc, saved);
+ case SELECTION_SELECTION: {
+ const GSList * reprlst;
+ SPDocument * doc = SP_ACTIVE_DOCUMENT;
+ bool modified = false;
+
+ bool saved = DocumentUndo::getUndoSensitive(doc);
+ DocumentUndo::setUndoSensitive(doc, false);
+ reprlst = sp_desktop_selection(SP_ACTIVE_DESKTOP)->reprList();
+
+ for(; reprlst != NULL; reprlst = reprlst->next) {
+ Inkscape::XML::Node * repr = static_cast<Inkscape::XML::Node *>(reprlst->data);
+ const gchar * temp_string;
+ Glib::ustring dir = Glib::path_get_dirname(filename.c_str());
+ const gchar* docURI=SP_ACTIVE_DOCUMENT->getURI();
+ Glib::ustring docdir;
+ if (docURI)
+ {
+ docdir = Glib::path_get_dirname(docURI);
+ }
+ if (repr->attribute("id") == NULL ||
+ !(filename_ext.find_last_of(repr->attribute("id")) &&
+ ( !docURI ||
+ (dir == docdir)))) {
+ temp_string = repr->attribute("inkscape:export-filename");
+ if (temp_string == NULL || (filename_ext != temp_string)) {
+ repr->setAttribute("inkscape:export-filename", filename_ext.c_str());
+ modified = true;
+ }
+ }
+ temp_string = repr->attribute("inkscape:export-xdpi");
+ if (temp_string == NULL || xdpi != atof(temp_string)) {
+ sp_repr_set_svg_double(repr, "inkscape:export-xdpi", xdpi);
+ modified = true;
+ }
+ temp_string = repr->attribute("inkscape:export-ydpi");
+ if (temp_string == NULL || ydpi != atof(temp_string)) {
+ sp_repr_set_svg_double(repr, "inkscape:export-ydpi", ydpi);
+ modified = true;
+ }
+ }
+ DocumentUndo::setUndoSensitive(doc, saved);
- if (modified) {
- doc->setModifiedSinceSave();
+ if (modified) {
+ doc->setModifiedSinceSave();
+ }
+ break;
}
- break;
+ default:
+ break;
}
- default:
- break;
- }
- g_free (path);
}
} // end of sp_export_export_clicked()
@@ -1137,7 +1116,7 @@ void Export::onExport ()
void Export::onBrowse ()
{
GtkWidget *fs;
- const gchar *filename;
+ Glib::ustring filename;
fs = gtk_file_chooser_dialog_new (_("Select a filename for exporting"),
(GtkWindow*)desktop->getToplevel(),
@@ -1156,13 +1135,14 @@ void Export::onBrowse ()
gtk_window_set_modal(GTK_WINDOW (fs), true);
- filename = filename_entry.get_text().c_str();
+ filename = filename_entry.get_text();
- if (*filename == '\0') {
- filename = create_filepath_from_id(NULL, NULL);
+ if (filename.empty()) {
+ Glib::ustring tmp;
+ filename = create_filepath_from_id(tmp, tmp);
}
- gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (fs), filename);
+ gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (fs), filename.c_str());
#ifdef WIN32
// code in this section is borrowed from ui/dialogs/filedialogimpl-win32.cpp
@@ -1177,7 +1157,7 @@ void Export::onBrowse ()
// Copy the selected file name, converting from UTF-8 to UTF-16
WCHAR _filename[_MAX_PATH + 1];
memset(_filename, 0, sizeof(_filename));
- gunichar2* utf16_path_string = g_utf8_to_utf16(filename, -1, NULL, NULL, NULL);
+ gunichar2* utf16_path_string = g_utf8_to_utf16(filename.c_str(), -1, NULL, NULL, NULL);
wcsncpy(_filename, (wchar_t*)utf16_path_string, _MAX_PATH);
g_free(utf16_path_string);
@@ -1792,7 +1772,7 @@ float Export::getValuePx( Gtk::Adjustment *adj )
*/
void Export::onFilenameModified()
{
- if (strcmp(original_name, filename_entry.get_text().c_str())==0) {
+ if (original_name == filename_entry.get_text()) {
filename_modified = false;
} else {
filename_modified = true;
diff --git a/src/ui/dialog/export.h b/src/ui/dialog/export.h
index 51b969b5e..86a7d7924 100644
--- a/src/ui/dialog/export.h
+++ b/src/ui/dialog/export.h
@@ -199,9 +199,9 @@ private:
* Utlitiy filename and path functions
*/
void set_default_filename ();
- gchar* create_filepath_from_id (const gchar *id, const gchar *file_entry_text);
+ Glib::ustring create_filepath_from_id (Glib::ustring id, const Glib::ustring &file_entry_text);
Glib::ustring filename_add_extension (Glib::ustring filename, Glib::ustring extension);
- gchar *absolutize_path_from_document_location (SPDocument *doc, const gchar *filename);
+ Glib::ustring absolutize_path_from_document_location (SPDocument *doc, const Glib::ustring &filename);
/*
* Currently selected export area type
@@ -210,8 +210,8 @@ private:
/*
* Original name for the export object
*/
- gchar * original_name;
- gchar * doc_export_name;
+ Glib::ustring original_name;
+ Glib::ustring doc_export_name;
/*
* Was the Original name modified
*/