summaryrefslogtreecommitdiffstats
path: root/src/ui/dialog/export.cpp
diff options
context:
space:
mode:
authorDenis Declara <declara91@gmail.com>2012-04-15 12:29:45 +0000
committerDenis Declara <declara91@gmail.com>2012-04-15 12:29:45 +0000
commit6b5ff661a46ea1779c86f6947006c5ed32926117 (patch)
treea5b170f0830854e99ad065055ee2a3996933e614 /src/ui/dialog/export.cpp
parentImproved User interface. (diff)
parenti18n. Fix for Bug #980518 (Please use c-format). (diff)
downloadinkscape-6b5ff661a46ea1779c86f6947006c5ed32926117.tar.gz
inkscape-6b5ff661a46ea1779c86f6947006c5ed32926117.zip
Trunk merge
(bzr r11073.1.15)
Diffstat (limited to 'src/ui/dialog/export.cpp')
-rw-r--r--src/ui/dialog/export.cpp128
1 files changed, 60 insertions, 68 deletions
diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp
index 150abd66b..060a10f63 100644
--- a/src/ui/dialog/export.cpp
+++ b/src/ui/dialog/export.cpp
@@ -8,8 +8,9 @@
* Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
* Jon A. Cruz <jon@joncruz.org>
* Abhishek Sharma
+ * Kris De Gussem <Kris.DeGussem@gmail.com>
*
- * Copyright (C) 1999-2007 Authors
+ * Copyright (C) 1999-2007, 2012 Authors
* Copyright (C) 2001-2002 Ximian, Inc.
*
* Released under GNU GPL, read the file 'COPYING' for more information
@@ -350,7 +351,7 @@ void Export::setTargetDesktop(SPDesktop *desktop)
subselChangedConn = desktop->connectToolSubselectionChanged(sigc::hide(sigc::mem_fun(*this, &Export::onSelectionChanged)));
//// Must check flags, so can't call widget_setup() directly.
- selectModifiedConn = desktop->selection->connectModified(sigc::hide<0>(sigc::mem_fun(*this, &Export::onSelectioModified)));
+ selectModifiedConn = desktop->selection->connectModified(sigc::hide<0>(sigc::mem_fun(*this, &Export::onSelectionModified)));
}
//widget_setup();
}
@@ -428,7 +429,7 @@ void Export::set_default_filename () {
* @param sensitive Whether the spin button is sensitive or not
* @param cb Callback for when this spin button is changed (optional)
*/
-Gtk::Adjustment * Export::createSpinbutton( gchar const *key, float val, float min, float max,
+Gtk::Adjustment * Export::createSpinbutton( gchar const * /*key*/, float val, float min, float max,
float step, float page, GtkWidget *us,
GtkWidget *t, int x, int y,
const gchar *ll, const gchar *lr,
@@ -606,7 +607,7 @@ void Export::onSelectionChanged()
updateCheckbuttons ();
}
-void Export::onSelectioModified ( guint flags )
+void Export::onSelectionModified ( guint /*flags*/ )
{
switch (current_key) {
case SELECTION_DRAWING:
@@ -784,7 +785,7 @@ void Export::onAreaToggled ()
/// Called when dialog is deleted
-gint Export::onProgressDelete ( GtkWidget *widget, GdkEvent *event, GObject *base )
+gint Export::onProgressDelete ( GtkWidget * /*widget*/, GdkEvent * /*event*/, GObject *base )
{
g_object_set_data (base, "cancel", (gpointer) 1);
return TRUE;
@@ -792,7 +793,7 @@ gint Export::onProgressDelete ( GtkWidget *widget, GdkEvent *event, GObject *bas
/// Called when progress is cancelled
-void Export::onProgressCancel ( GtkWidget *widget, GObject *base )
+void Export::onProgressCancel ( GtkWidget * /*widget*/, GObject *base )
{
g_object_set_data (base, "cancel", (gpointer) 1);
} // end of sp_export_progress_cancel()
@@ -822,8 +823,7 @@ unsigned int Export::onProgressCallback (float value, void *data)
} // end of sp_export_progress_callback()
-GtkWidget * Export::create_progress_dialog (gchar *progress_text) {
-
+GtkWidget * Export::create_progress_dialog (Glib::ustring progress_text) {
GtkWidget *dlg, *prg, *btn; /* progressbar dlg widgets */
dlg = gtk_dialog_new ();
@@ -836,7 +836,7 @@ GtkWidget * Export::create_progress_dialog (gchar *progress_text) {
gtk_window_set_resizable (GTK_WINDOW (dlg), FALSE);
g_object_set_data ((GObject *) base, "progress", prg);
- gtk_progress_bar_set_text ((GtkProgressBar *) prg, progress_text);
+ gtk_progress_bar_set_text ((GtkProgressBar *) prg, progress_text.c_str());
gtk_progress_bar_set_orientation ( (GtkProgressBar *) prg,
GTK_PROGRESS_LEFT_TO_RIGHT);
@@ -857,26 +857,26 @@ GtkWidget * Export::create_progress_dialog (gchar *progress_text) {
}
// FIXME: Some lib function should be available to do this ...
-gchar * Export::filename_add_extension (const gchar *filename, const gchar *extension)
+Glib::ustring Export::filename_add_extension (Glib::ustring filename, Glib::ustring extension)
{
- const gchar *dot;
-
- dot = strrchr (filename, '.');
- if ( !dot )
- return g_strconcat (filename, ".", extension, NULL);
- {
- if (dot[1] == '\0')
- return g_strconcat (filename, extension, NULL);
+ Glib::ustring::size_type dot;
+
+ dot = filename.find_last_of(".");
+ if ( !dot )
+ {
+ return filename = filename + "." + extension;
+ }
else
{
- if (g_ascii_strcasecmp (dot + 1, extension) == 0)
- return g_strdup (filename);
- else
- {
- return g_strconcat (filename, ".", extension, NULL);
- }
- }
- }
+ if (dot==filename.find_last_of(Glib::ustring::compose(".", extension)))
+ {
+ return filename;
+ }
+ else
+ {
+ return filename = filename + "." + extension;
+ }
+ }
}
gchar *Export::absolutize_path_from_document_location (SPDocument *doc, const gchar *filename)
@@ -908,24 +908,22 @@ void Export::onExport ()
if (batch_export.get_active ()) {
// Batch export of selected objects
- gint num = g_slist_length((GSList *) sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList());
+ gint num = g_slist_length(const_cast<GSList *>(sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList()));
gint n = 0;
if (num < 1)
return;
- gchar *progress_text = g_strdup_printf (_("Exporting %d files"), num);
- GtkWidget *prog_dlg = create_progress_dialog (progress_text);
- g_free (progress_text);
+ GtkWidget *prog_dlg = create_progress_dialog (Glib::ustring::compose(_("Exporting %1 files"),num));
- for (GSList *i = (GSList *) sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList();
+ for (GSList *i = const_cast<GSList *>(sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList());
i != NULL;
i = i->next) {
SPItem *item = reinterpret_cast<SPItem *>(i->data);
// retrieve export filename hint
const gchar *filename = item->getRepr()->attribute("inkscape:export-filename");
- gchar *path = 0;
+ gchar *path = NULL;
if (!filename) {
path = create_filepath_from_id(item->getId(), NULL);
} else {
@@ -953,7 +951,7 @@ void Export::onExport ()
*area, width, height, dpi, dpi,
nv->pagecolor,
NULL, NULL, TRUE, // overwrite without asking
- hide ? (GSList *) sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList() : NULL
+ hide ? const_cast<GSList *>(sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList()) : NULL
)) {
gchar * error;
gchar * safeFile = Inkscape::IO::sanitizeString(path);
@@ -974,8 +972,13 @@ void Export::onExport ()
} else {
- gchar const *filename = g_strdup(filename_entry.get_text().c_str());
+ 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);
@@ -985,22 +988,15 @@ void Export::onExport ()
unsigned long int const width = int(getValue(bmwidth_adj) + 0.5);
unsigned long int const height = int(getValue(bmheight_adj) + 0.5);
- if (filename == NULL || *filename == '\0') {
- sp_ui_error_dialog(_("You have to enter a filename"));
- return;
- }
-
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:
- gchar * filename_ext = filename_add_extension(filename, "png");
- //gtk_entry_set_text(GTK_ENTRY(filename_entry), filename_ext);
+ 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);
+ gchar *path = absolutize_path_from_document_location(doc, filename_ext.c_str());
gchar *dirname = g_path_get_dirname(path);
if ( dirname == NULL
@@ -1019,18 +1015,16 @@ void Export::onExport ()
g_free(dirname);
gchar *fn = g_path_get_basename (path);
- gchar *progress_text = g_strdup_printf (_("Exporting %s (%lu x %lu)"), fn, width, height);
+ GtkWidget *prog_dlg = create_progress_dialog (Glib::ustring::compose(_("Exporting %1 (%2 x %3)"), fn, width, height));
g_free (fn);
- GtkWidget *prog_dlg = create_progress_dialog (progress_text);
- g_free (progress_text);
/* 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 ? (GSList *) sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList() : NULL
+ hide ? const_cast<GSList *>(sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList()) : NULL
)) {
gchar * error;
gchar * safeFile = Inkscape::IO::sanitizeString(path);
@@ -1043,12 +1037,13 @@ void Export::onExport ()
/* Reset the filename so that it can be changed again by changing
selections and all that */
g_free(original_name);
- original_name = g_strdup(filename_ext);
+ original_name = const_cast<gchar*>(filename_ext.c_str());
filename_modified = false;
gtk_widget_destroy (prog_dlg);
//g_object_set_data (G_OBJECT (base), "cancel", (gpointer) 0);
+
/* Setup the values in the document */
switch (current_key) {
case SELECTION_PAGE:
@@ -1061,8 +1056,8 @@ void Export::onExport ()
DocumentUndo::setUndoSensitive(doc, false);
gchar const *temp_string = repr->attribute("inkscape:export-filename");
- if (temp_string == NULL || strcmp(temp_string, filename_ext)) {
- repr->setAttribute("inkscape:export-filename", filename_ext);
+ 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");
@@ -1071,7 +1066,7 @@ void Export::onExport ()
modified = true;
}
temp_string = repr->attribute("inkscape:export-ydpi");
- if (temp_string == NULL || xdpi != atof(temp_string)) {
+ if (temp_string == NULL || ydpi != atof(temp_string)) {
sp_repr_set_svg_double(repr, "inkscape:export-ydpi", ydpi);
modified = true;
}
@@ -1092,18 +1087,22 @@ void Export::onExport ()
reprlst = sp_desktop_selection(SP_ACTIVE_DESKTOP)->reprList();
for(; reprlst != NULL; reprlst = reprlst->next) {
- Inkscape::XML::Node * repr = (Inkscape::XML::Node *)reprlst->data;
+ Inkscape::XML::Node * repr = static_cast<Inkscape::XML::Node *>(reprlst->data);
const gchar * temp_string;
- gchar *dir = g_path_get_dirname(filename);
- gchar *docdir = g_path_get_dirname(SP_ACTIVE_DOCUMENT->getURI());
-
+ 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 ||
- !(g_strrstr(filename_ext, repr->attribute("id")) != NULL &&
- ( !SP_ACTIVE_DOCUMENT->getURI() ||
- strcmp(dir, docdir) == 0))) {
+ !(filename_ext.find_last_of(repr->attribute("id")) &&
+ ( !docURI ||
+ (dir == docdir)))) {
temp_string = repr->attribute("inkscape:export-filename");
- if (temp_string == NULL || strcmp(temp_string, filename_ext)) {
- repr->setAttribute("inkscape:export-filename", filename_ext);
+ if (temp_string == NULL || (filename_ext != temp_string)) {
+ repr->setAttribute("inkscape:export-filename", filename_ext.c_str());
modified = true;
}
}
@@ -1113,12 +1112,10 @@ void Export::onExport ()
modified = true;
}
temp_string = repr->attribute("inkscape:export-ydpi");
- if (temp_string == NULL || xdpi != atof(temp_string)) {
+ if (temp_string == NULL || ydpi != atof(temp_string)) {
sp_repr_set_svg_double(repr, "inkscape:export-ydpi", ydpi);
modified = true;
}
- g_free(dir);
- g_free(docdir);
}
DocumentUndo::setUndoSensitive(doc, saved);
@@ -1130,10 +1127,7 @@ void Export::onExport ()
default:
break;
}
-
- g_free (filename_ext);
g_free (path);
-
}
} // end of sp_export_export_clicked()
@@ -1800,10 +1794,8 @@ void Export::onFilenameModified()
{
if (strcmp(original_name, filename_entry.get_text().c_str())==0) {
filename_modified = false;
-// g_message("Modified: FALSE\n");
} else {
filename_modified = true;
-// g_message("Modified: TRUE\n");
}
return;