filedialogimpl-gtkmm.cpp revision 52cad88e59adf0342e9294b9249b96bffe8fbe9e
1568N/A/**
830N/A * @file
830N/A * Implementation of the file dialog interfaces defined in filedialogimpl.h.
919N/A */
919N/A/* Authors:
919N/A * Bob Jamison
919N/A * Joel Holdsworth
919N/A * Bruno Dilly
830N/A * Other dudes from The Inkscape Organization
919N/A * Abhishek Sharma
919N/A *
919N/A * Copyright (C) 2004-2007 Bob Jamison
830N/A * Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
919N/A * Copyright (C) 2007-2008 Joel Holdsworth
919N/A * Copyright (C) 2004-2007 The Inkscape Organization
919N/A *
919N/A * Released under GNU GPL, read the file 'COPYING' for more information
919N/A */
919N/A
919N/A#ifdef HAVE_CONFIG_H
830N/A#include <config.h>
830N/A#endif
830N/A
830N/A#include "filedialogimpl-gtkmm.h"
830N/A#include "dialogs/dialog-events.h"
830N/A#include "interface.h"
830N/A#include "io/sys.h"
830N/A#include "path-prefix.h"
830N/A#include "preferences.h"
830N/A
830N/A#ifdef WITH_GNOME_VFS
830N/A#include <libgnomevfs/gnome-vfs.h>
830N/A#endif
830N/A
830N/A#include <gtkmm/expander.h>
830N/A#include <gtkmm/stock.h>
830N/A
830N/A#include <glibmm/convert.h>
830N/A#include <glibmm/fileutils.h>
830N/A#include <glibmm/i18n.h>
830N/A#include <glibmm/miscutils.h>
830N/A
830N/A#include "extension/input.h"
830N/A#include "extension/output.h"
830N/A#include "extension/db.h"
830N/A#include "svg-view-widget.h"
830N/A#include "inkscape.h"
830N/A
830N/A// Routines from file.cpp
830N/A#undef INK_DUMP_FILENAME_CONV
830N/A
830N/A#ifdef INK_DUMP_FILENAME_CONV
830N/Avoid dump_str(const gchar *str, const gchar *prefix);
830N/Avoid dump_ustr(const Glib::ustring &ustr);
830N/A#endif
830N/A
830N/A
830N/A
830N/Anamespace Inkscape {
830N/Anamespace UI {
830N/Anamespace Dialog {
830N/A
830N/A
830N/A
830N/A//########################################################################
830N/A//### U T I L I T Y
830N/A//########################################################################
830N/A
830N/Avoid fileDialogExtensionToPattern(Glib::ustring &pattern, Glib::ustring &extension)
830N/A{
830N/A for (unsigned int i = 0; i < extension.length(); ++i) {
830N/A Glib::ustring::value_type ch = extension[i];
830N/A if (Glib::Unicode::isalpha(ch)) {
830N/A pattern += '[';
830N/A pattern += Glib::Unicode::toupper(ch);
830N/A pattern += Glib::Unicode::tolower(ch);
830N/A pattern += ']';
830N/A } else {
830N/A pattern += ch;
830N/A }
830N/A }
830N/A}
830N/A
830N/A
830N/Avoid findEntryWidgets(Gtk::Container *parent, std::vector<Gtk::Entry *> &result)
830N/A{
830N/A if (!parent) {
830N/A return;
830N/A }
830N/A std::vector<Gtk::Widget *> children = parent->get_children();
830N/A for (unsigned int i = 0; i < children.size(); ++i) {
830N/A Gtk::Widget *child = children[i];
830N/A GtkWidget *wid = child->gobj();
830N/A if (GTK_IS_ENTRY(wid))
830N/A result.push_back(dynamic_cast<Gtk::Entry *>(child));
830N/A else if (GTK_IS_CONTAINER(wid))
830N/A findEntryWidgets(dynamic_cast<Gtk::Container *>(child), result);
830N/A }
830N/A}
830N/A
830N/Avoid findExpanderWidgets(Gtk::Container *parent, std::vector<Gtk::Expander *> &result)
830N/A{
830N/A if (!parent)
830N/A return;
830N/A std::vector<Gtk::Widget *> children = parent->get_children();
830N/A for (unsigned int i = 0; i < children.size(); ++i) {
830N/A Gtk::Widget *child = children[i];
830N/A GtkWidget *wid = child->gobj();
830N/A if (GTK_IS_EXPANDER(wid))
830N/A result.push_back(dynamic_cast<Gtk::Expander *>(child));
830N/A else if (GTK_IS_CONTAINER(wid))
830N/A findExpanderWidgets(dynamic_cast<Gtk::Container *>(child), result);
830N/A }
830N/A}
830N/A
830N/A
830N/A/*#########################################################################
830N/A### SVG Preview Widget
830N/A#########################################################################*/
830N/A
830N/Abool SVGPreview::setDocument(SPDocument *doc)
830N/A{
830N/A if (document)
830N/A document->doUnref();
830N/A
830N/A doc->doRef();
830N/A document = doc;
830N/A
830N/A // This should remove it from the box, and free resources
830N/A if (viewerGtk)
830N/A Gtk::Container::remove(*viewerGtk);
830N/A
830N/A viewerGtk = Glib::wrap(sp_svg_view_widget_new(doc));
830N/A Gtk::VBox *vbox = Glib::wrap(gobj());
830N/A vbox->pack_start(*viewerGtk, TRUE, TRUE, 0);
830N/A viewerGtk->show();
830N/A return true;
830N/A}
830N/A
830N/A
830N/Abool SVGPreview::setFileName(Glib::ustring &theFileName)
830N/A{
830N/A Glib::ustring fileName = theFileName;
830N/A
830N/A fileName = Glib::filename_to_utf8(fileName);
830N/A
830N/A /**
830N/A * I don't know why passing false to keepalive is bad. But it
830N/A * prevents the display of an svg with a non-ascii filename
830N/A */
830N/A SPDocument *doc = SPDocument::createNewDoc(fileName.c_str(), true);
830N/A if (!doc) {
830N/A g_warning("SVGView: error loading document '%s'\n", fileName.c_str());
830N/A return false;
830N/A }
830N/A
830N/A setDocument(doc);
830N/A
830N/A doc->doUnref();
830N/A
830N/A return true;
830N/A}
830N/A
830N/A
830N/A
830N/Abool SVGPreview::setFromMem(char const *xmlBuffer)
830N/A{
830N/A if (!xmlBuffer)
830N/A return false;
830N/A
830N/A gint len = (gint)strlen(xmlBuffer);
830N/A SPDocument *doc = SPDocument::createNewDocFromMem(xmlBuffer, len, 0);
830N/A if (!doc) {
830N/A g_warning("SVGView: error loading buffer '%s'\n", xmlBuffer);
830N/A return false;
830N/A }
830N/A
830N/A setDocument(doc);
830N/A
830N/A doc->doUnref();
830N/A
830N/A Inkscape::GC::request_early_collection();
830N/A
830N/A return true;
830N/A}
830N/A
830N/A
830N/A
830N/Avoid SVGPreview::showImage(Glib::ustring &theFileName)
830N/A{
830N/A Glib::ustring fileName = theFileName;
830N/A
830N/A
830N/A /*#####################################
830N/A # LET'S HAVE SOME FUN WITH SVG!
830N/A # Instead of just loading an image, why
830N/A # don't we make a lovely little svg and
830N/A # display it nicely?
830N/A #####################################*/
830N/A
830N/A // Arbitrary size of svg doc -- rather 'portrait' shaped
830N/A gint previewWidth = 400;
830N/A gint previewHeight = 600;
830N/A
830N/A // Get some image info. Smart pointer does not need to be deleted
830N/A Glib::RefPtr<Gdk::Pixbuf> img(NULL);
830N/A try
830N/A {
830N/A img = Gdk::Pixbuf::create_from_file(fileName);
830N/A }
830N/A catch (const Glib::FileError &e)
830N/A {
830N/A g_message("caught Glib::FileError in SVGPreview::showImage");
830N/A return;
830N/A }
830N/A catch (const Gdk::PixbufError &e)
830N/A {
830N/A g_message("Gdk::PixbufError in SVGPreview::showImage");
830N/A return;
830N/A }
830N/A catch (...)
830N/A {
830N/A g_message("Caught ... in SVGPreview::showImage");
830N/A return;
830N/A }
830N/A
830N/A gint imgWidth = img->get_width();
830N/A gint imgHeight = img->get_height();
830N/A
830N/A // Find the minimum scale to fit the image inside the preview area
830N/A double scaleFactorX = (0.9 * (double)previewWidth) / ((double)imgWidth);
830N/A double scaleFactorY = (0.9 * (double)previewHeight) / ((double)imgHeight);
830N/A double scaleFactor = scaleFactorX;
830N/A if (scaleFactorX > scaleFactorY)
830N/A scaleFactor = scaleFactorY;
830N/A
830N/A // Now get the resized values
830N/A gint scaledImgWidth = (int)(scaleFactor * (double)imgWidth);
830N/A gint scaledImgHeight = (int)(scaleFactor * (double)imgHeight);
830N/A
830N/A // center the image on the area
830N/A gint imgX = (previewWidth - scaledImgWidth) / 2;
830N/A gint imgY = (previewHeight - scaledImgHeight) / 2;
830N/A
830N/A // wrap a rectangle around the image
830N/A gint rectX = imgX - 1;
830N/A gint rectY = imgY - 1;
830N/A gint rectWidth = scaledImgWidth + 2;
830N/A gint rectHeight = scaledImgHeight + 2;
830N/A
830N/A // Our template. Modify to taste
830N/A gchar const *xformat = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
830N/A "<svg\n"
830N/A "xmlns=\"http://www.w3.org/2000/svg\"\n"
830N/A "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
830N/A "width=\"%d\" height=\"%d\">\n" //# VALUES HERE
830N/A "<rect\n"
830N/A " style=\"fill:#eeeeee;stroke:none\"\n"
830N/A " x=\"-100\" y=\"-100\" width=\"4000\" height=\"4000\"/>\n"
830N/A "<image x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\"\n"
830N/A "xlink:href=\"%s\"/>\n"
830N/A "<rect\n"
830N/A " style=\"fill:none;"
830N/A " stroke:#000000;stroke-width:1.0;"
830N/A " stroke-linejoin:miter;stroke-opacity:1.0000000;"
830N/A " stroke-miterlimit:4.0000000;stroke-dasharray:none\"\n"
830N/A " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\"/>\n"
830N/A "<text\n"
830N/A " style=\"font-size:24.000000;font-style:normal;font-weight:normal;"
830N/A " fill:#000000;fill-opacity:1.0000000;stroke:none;"
830N/A " font-family:Sans\"\n"
830N/A " x=\"10\" y=\"26\">%d x %d</text>\n" //# VALUES HERE
830N/A "</svg>\n\n";
830N/A
830N/A // if (!Glib::get_charset()) //If we are not utf8
830N/A fileName = Glib::filename_to_utf8(fileName);
830N/A
830N/A // Fill in the template
830N/A /* FIXME: Do proper XML quoting for fileName. */
830N/A gchar *xmlBuffer =
830N/A g_strdup_printf(xformat, previewWidth, previewHeight, imgX, imgY, scaledImgWidth, scaledImgHeight,
830N/A fileName.c_str(), rectX, rectY, rectWidth, rectHeight, imgWidth, imgHeight);
830N/A
830N/A // g_message("%s\n", xmlBuffer);
830N/A
830N/A // now show it!
830N/A setFromMem(xmlBuffer);
830N/A g_free(xmlBuffer);
830N/A}
830N/A
830N/A
830N/A
830N/Avoid SVGPreview::showNoPreview()
830N/A{
830N/A // Are we already showing it?
830N/A if (showingNoPreview)
830N/A return;
830N/A
830N/A // Arbitrary size of svg doc -- rather 'portrait' shaped
830N/A gint previewWidth = 300;
830N/A gint previewHeight = 600;
830N/A
830N/A // Our template. Modify to taste
830N/A gchar const *xformat =
830N/A "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
830N/A "<svg\n"
830N/A "xmlns=\"http://www.w3.org/2000/svg\"\n"
830N/A "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
830N/A "width=\"%d\" height=\"%d\">\n" //# VALUES HERE
830N/A "<g transform=\"translate(-190,24.27184)\" style=\"opacity:0.12\">\n"
830N/A "<path\n"
830N/A "style=\"font-size:12;fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:0.936193pt\"\n"
830N/A "d=\"M 397.64309 320.25301 L 280.39197 282.517 L 250.74227 124.83447 L 345.08225 "
830N/A "29.146783 L 393.59996 46.667064 L 483.89679 135.61619 L 397.64309 320.25301 z \"\n"
830N/A "id=\"whiteSpace\" />\n"
830N/A "<path\n"
830N/A "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
830N/A "d=\"M 476.95792 339.17168 C 495.78197 342.93607 499.54842 356.11361 495.78197 359.87802 "
830N/A "C 492.01856 363.6434 482.6065 367.40781 475.07663 361.76014 C 467.54478 "
830N/A "356.11361 467.54478 342.93607 476.95792 339.17168 z \"\n"
830N/A "id=\"droplet01\" />\n"
830N/A "<path\n"
830N/A "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
830N/A "d=\"M 286.46194 340.42914 C 284.6277 340.91835 269.30405 327.71337 257.16909 333.8338 "
830N/A "C 245.03722 339.95336 236.89276 353.65666 248.22676 359.27982 C 259.56184 364.90298 "
830N/A "267.66433 358.41867 277.60113 351.44119 C 287.53903 344.46477 "
830N/A "287.18046 343.1206 286.46194 340.42914 z \"\n"
830N/A "id=\"droplet02\" />\n"
830N/A "<path\n"
830N/A "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
830N/A "d=\"M 510.35756 306.92856 C 520.59494 304.36879 544.24333 306.92856 540.47688 321.98634 "
830N/A "C 536.71354 337.04806 504.71297 331.39827 484.00371 323.87156 C 482.12141 "
830N/A "308.81083 505.53237 308.13423 510.35756 306.92856 z \"\n"
830N/A "id=\"droplet03\" />\n"
830N/A "<path\n"
830N/A "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
830N/A "d=\"M 359.2403 21.362537 C 347.92693 21.362537 336.6347 25.683095 327.96556 34.35223 "
830N/A "L 173.87387 188.41466 C 165.37697 196.9114 161.1116 207.95813 160.94269 219.04577 "
830N/A "L 160.88418 219.04577 C 160.88418 219.08524 160.94076 219.12322 160.94269 219.16279 "
830N/A "C 160.94033 219.34888 160.88418 219.53256 160.88418 219.71865 L 161.14748 219.71865 "
830N/A "C 164.0966 230.93917 240.29699 245.24198 248.79866 253.74346 C 261.63771 266.58263 "
830N/A "199.5652 276.01151 212.4041 288.85074 C 225.24316 301.68979 289.99433 313.6933 302.8346 "
830N/A "326.53254 C 315.67368 339.37161 276.5961 353.04289 289.43532 365.88196 C 302.27439 "
830N/A "378.72118 345.40201 362.67257 337.5908 396.16198 C 354.92909 413.50026 391.10302 "
830N/A "405.2208 415.32417 387.88252 C 428.16323 375.04345 390.6948 376.17577 403.53397 "
830N/A "363.33668 C 416.37304 350.49745 448.78128 350.4282 476.08902 319.71589 C 465.09739 "
830N/A "302.62116 429.10801 295.34136 441.94719 282.50217 C 454.78625 269.66311 479.74708 "
830N/A "276.18423 533.60644 251.72479 C 559.89837 239.78398 557.72636 230.71459 557.62567 "
830N/A "219.71865 C 557.62356 219.48727 557.62567 219.27892 557.62567 219.04577 L 557.56716 "
830N/A "219.04577 C 557.3983 207.95812 553.10345 196.9114 544.60673 188.41466 L 390.54428 "
830N/A "34.35223 C 381.87515 25.683095 370.55366 21.362537 359.2403 21.362537 z M 357.92378 "
830N/A "41.402939 C 362.95327 41.533963 367.01541 45.368018 374.98006 50.530832 L 447.76915 "
830N/A "104.50827 C 448.56596 105.02498 449.32484 105.564 450.02187 106.11735 C 450.7189 106.67062 "
830N/A "451.3556 107.25745 451.95277 107.84347 C 452.54997 108.42842 453.09281 109.01553 453.59111 "
830N/A "109.62808 C 454.08837 110.24052 454.53956 110.86661 454.93688 111.50048 C 455.33532 112.13538 "
830N/A "455.69164 112.78029 455.9901 113.43137 C 456.28877 114.08363 456.52291 114.75639 456.7215 "
830N/A "115.42078 C 456.92126 116.08419 457.08982 116.73973 457.18961 117.41019 C 457.28949 "
830N/A "118.08184 457.33588 118.75535 457.33588 119.42886 L 414.21245 98.598549 L 409.9118 "
830N/A "131.16055 L 386.18512 120.04324 L 349.55654 144.50131 L 335.54288 96.1703 L 317.4919 "
830N/A "138.4453 L 267.08369 143.47735 L 267.63956 121.03795 C 267.63956 115.64823 296.69685 "
830N/A "77.915899 314.39075 68.932902 L 346.77721 45.674327 C 351.55594 42.576634 354.90608 "
830N/A "41.324327 357.92378 41.402939 z M 290.92738 261.61333 C 313.87149 267.56365 339.40299 "
830N/A "275.37038 359.88393 275.50997 L 360.76161 284.72563 C 343.2235 282.91785 306.11346 "
830N/A "274.45012 297.36372 269.98057 L 290.92738 261.61333 z \"\n"
830N/A "id=\"mountainDroplet\" />\n"
830N/A "</g> <g transform=\"translate(-20,0)\">\n"
830N/A "<text xml:space=\"preserve\"\n"
830N/A "style=\"font-size:32.000000;font-style:normal;font-variant:normal;font-weight:bold;"
830N/A "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
830N/A "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
830N/A "font-family:Sans;text-anchor:middle;writing-mode:lr\"\n"
830N/A "x=\"190\" y=\"240\">%s</text></g>\n" //# VALUE HERE
830N/A "</svg>\n\n";
830N/A
830N/A // Fill in the template
830N/A gchar *xmlBuffer = g_strdup_printf(xformat, previewWidth, previewHeight, _("No preview"));
830N/A
830N/A // g_message("%s\n", xmlBuffer);
830N/A
830N/A // now show it!
830N/A setFromMem(xmlBuffer);
830N/A g_free(xmlBuffer);
830N/A showingNoPreview = true;
830N/A}
830N/A
830N/A
830N/A/**
830N/A * Inform the user that the svg file is too large to be displayed.
830N/A * This does not check for sizes of embedded images (yet)
830N/A */
830N/Avoid SVGPreview::showTooLarge(long fileLength)
830N/A{
1568N/A
830N/A // Arbitrary size of svg doc -- rather 'portrait' shaped
830N/A gint previewWidth = 300;
830N/A gint previewHeight = 600;
830N/A
830N/A // Our template. Modify to taste
830N/A gchar const *xformat =
830N/A "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
830N/A "<svg\n"
830N/A "xmlns=\"http://www.w3.org/2000/svg\"\n"
830N/A "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
830N/A "width=\"%d\" height=\"%d\">\n" //# VALUES HERE
830N/A "<g transform=\"translate(-170,24.27184)\" style=\"opacity:0.12\">\n"
830N/A "<path\n"
830N/A "style=\"font-size:12;fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:0.936193pt\"\n"
830N/A "d=\"M 397.64309 320.25301 L 280.39197 282.517 L 250.74227 124.83447 L 345.08225 "
830N/A "29.146783 L 393.59996 46.667064 L 483.89679 135.61619 L 397.64309 320.25301 z \"\n"
830N/A "id=\"whiteSpace\" />\n"
830N/A "<path\n"
830N/A "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
830N/A "d=\"M 476.95792 339.17168 C 495.78197 342.93607 499.54842 356.11361 495.78197 359.87802 "
830N/A "C 492.01856 363.6434 482.6065 367.40781 475.07663 361.76014 C 467.54478 "
830N/A "356.11361 467.54478 342.93607 476.95792 339.17168 z \"\n"
830N/A "id=\"droplet01\" />\n"
830N/A "<path\n"
830N/A "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
830N/A "d=\"M 286.46194 340.42914 C 284.6277 340.91835 269.30405 327.71337 257.16909 333.8338 "
830N/A "C 245.03722 339.95336 236.89276 353.65666 248.22676 359.27982 C 259.56184 364.90298 "
830N/A "267.66433 358.41867 277.60113 351.44119 C 287.53903 344.46477 "
830N/A "287.18046 343.1206 286.46194 340.42914 z \"\n"
830N/A "id=\"droplet02\" />\n"
830N/A "<path\n"
830N/A "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
830N/A "d=\"M 510.35756 306.92856 C 520.59494 304.36879 544.24333 306.92856 540.47688 321.98634 "
830N/A "C 536.71354 337.04806 504.71297 331.39827 484.00371 323.87156 C 482.12141 "
830N/A "308.81083 505.53237 308.13423 510.35756 306.92856 z \"\n"
830N/A "id=\"droplet03\" />\n"
830N/A "<path\n"
830N/A "style=\"font-size:12;fill-rule:evenodd;stroke-width:1pt;fill:#000000;fill-opacity:1\"\n"
830N/A "d=\"M 359.2403 21.362537 C 347.92693 21.362537 336.6347 25.683095 327.96556 34.35223 "
830N/A "L 173.87387 188.41466 C 165.37697 196.9114 161.1116 207.95813 160.94269 219.04577 "
830N/A "L 160.88418 219.04577 C 160.88418 219.08524 160.94076 219.12322 160.94269 219.16279 "
830N/A "C 160.94033 219.34888 160.88418 219.53256 160.88418 219.71865 L 161.14748 219.71865 "
830N/A "C 164.0966 230.93917 240.29699 245.24198 248.79866 253.74346 C 261.63771 266.58263 "
830N/A "199.5652 276.01151 212.4041 288.85074 C 225.24316 301.68979 289.99433 313.6933 302.8346 "
830N/A "326.53254 C 315.67368 339.37161 276.5961 353.04289 289.43532 365.88196 C 302.27439 "
830N/A "378.72118 345.40201 362.67257 337.5908 396.16198 C 354.92909 413.50026 391.10302 "
830N/A "405.2208 415.32417 387.88252 C 428.16323 375.04345 390.6948 376.17577 403.53397 "
830N/A "363.33668 C 416.37304 350.49745 448.78128 350.4282 476.08902 319.71589 C 465.09739 "
830N/A "302.62116 429.10801 295.34136 441.94719 282.50217 C 454.78625 269.66311 479.74708 "
830N/A "276.18423 533.60644 251.72479 C 559.89837 239.78398 557.72636 230.71459 557.62567 "
830N/A "219.71865 C 557.62356 219.48727 557.62567 219.27892 557.62567 219.04577 L 557.56716 "
830N/A "219.04577 C 557.3983 207.95812 553.10345 196.9114 544.60673 188.41466 L 390.54428 "
830N/A "34.35223 C 381.87515 25.683095 370.55366 21.362537 359.2403 21.362537 z M 357.92378 "
830N/A "41.402939 C 362.95327 41.533963 367.01541 45.368018 374.98006 50.530832 L 447.76915 "
830N/A "104.50827 C 448.56596 105.02498 449.32484 105.564 450.02187 106.11735 C 450.7189 106.67062 "
830N/A "451.3556 107.25745 451.95277 107.84347 C 452.54997 108.42842 453.09281 109.01553 453.59111 "
830N/A "109.62808 C 454.08837 110.24052 454.53956 110.86661 454.93688 111.50048 C 455.33532 112.13538 "
830N/A "455.69164 112.78029 455.9901 113.43137 C 456.28877 114.08363 456.52291 114.75639 456.7215 "
830N/A "115.42078 C 456.92126 116.08419 457.08982 116.73973 457.18961 117.41019 C 457.28949 "
830N/A "118.08184 457.33588 118.75535 457.33588 119.42886 L 414.21245 98.598549 L 409.9118 "
830N/A "131.16055 L 386.18512 120.04324 L 349.55654 144.50131 L 335.54288 96.1703 L 317.4919 "
830N/A "138.4453 L 267.08369 143.47735 L 267.63956 121.03795 C 267.63956 115.64823 296.69685 "
830N/A "77.915899 314.39075 68.932902 L 346.77721 45.674327 C 351.55594 42.576634 354.90608 "
830N/A "41.324327 357.92378 41.402939 z M 290.92738 261.61333 C 313.87149 267.56365 339.40299 "
830N/A "275.37038 359.88393 275.50997 L 360.76161 284.72563 C 343.2235 282.91785 306.11346 "
830N/A "274.45012 297.36372 269.98057 L 290.92738 261.61333 z \"\n"
830N/A "id=\"mountainDroplet\" />\n"
830N/A "</g>\n"
830N/A "<text xml:space=\"preserve\"\n"
830N/A "style=\"font-size:32.000000;font-style:normal;font-variant:normal;font-weight:bold;"
830N/A "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
830N/A "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
830N/A "font-family:Sans;text-anchor:middle;writing-mode:lr\"\n"
830N/A "x=\"170\" y=\"215\">%5.1f MB</text>\n" //# VALUE HERE
830N/A "<text xml:space=\"preserve\"\n"
830N/A "style=\"font-size:24.000000;font-style:normal;font-variant:normal;font-weight:bold;"
830N/A "font-stretch:normal;fill:#000000;fill-opacity:1.0000000;stroke:none;stroke-width:1.0000000pt;"
830N/A "stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;"
830N/A "font-family:Sans;text-anchor:middle;writing-mode:lr\"\n"
830N/A "x=\"180\" y=\"245\">%s</text>\n" //# VALUE HERE
830N/A "</svg>\n\n";
830N/A
830N/A // Fill in the template
830N/A double floatFileLength = ((double)fileLength) / 1048576.0;
830N/A // printf("%ld %f\n", fileLength, floatFileLength);
830N/A gchar *xmlBuffer =
830N/A g_strdup_printf(xformat, previewWidth, previewHeight, floatFileLength, _("too large for preview"));
830N/A
830N/A // g_message("%s\n", xmlBuffer);
830N/A
830N/A // now show it!
830N/A setFromMem(xmlBuffer);
830N/A g_free(xmlBuffer);
830N/A}
830N/A
830N/Abool SVGPreview::set(Glib::ustring &fileName, int dialogType)
830N/A{
830N/A
830N/A if (!Glib::file_test(fileName, Glib::FILE_TEST_EXISTS)) {
830N/A showNoPreview();
830N/A return false;
830N/A }
830N/A
830N/A
830N/A if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
1568N/A showNoPreview();
830N/A return false;
830N/A }
830N/A
830N/A if (Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)) {
830N/A Glib::ustring fileNameUtf8 = Glib::filename_to_utf8(fileName);
830N/A gchar *fName = const_cast<gchar *>(
830N/A fileNameUtf8.c_str()); // const-cast probably not necessary? (not necessary on Windows version of stat())
830N/A struct stat info;
830N/A if (g_stat(fName, &info)) // stat returns 0 upon success
830N/A {
830N/A g_warning("SVGPreview::set() : %s : %s", fName, strerror(errno));
830N/A return false;
830N/A }
830N/A if (info.st_size > 0xA00000L) {
830N/A showingNoPreview = false;
830N/A showTooLarge(info.st_size);
830N/A return false;
830N/A }
830N/A }
830N/A
830N/A Glib::ustring svg = ".svg";
830N/A Glib::ustring svgz = ".svgz";
830N/A
1568N/A if ((dialogType == SVG_TYPES || dialogType == IMPORT_TYPES) &&
1568N/A (hasSuffix(fileName, svg) || hasSuffix(fileName, svgz))) {
1568N/A bool retval = setFileName(fileName);
1568N/A showingNoPreview = false;
830N/A return retval;
830N/A } else if (isValidImageFile(fileName)) {
830N/A showImage(fileName);
830N/A showingNoPreview = false;
830N/A return true;
830N/A } else {
830N/A showNoPreview();
830N/A return false;
830N/A }
830N/A}
830N/A
830N/A
830N/ASVGPreview::SVGPreview()
830N/A{
830N/A if (!INKSCAPE)
830N/A Inkscape::Application::init("", false);
830N/A document = NULL;
830N/A viewerGtk = NULL;
830N/A set_size_request(150, 150);
830N/A showingNoPreview = false;
830N/A}
830N/A
830N/ASVGPreview::~SVGPreview()
830N/A{
830N/A}
830N/A
830N/A
830N/A/*#########################################################################
830N/A### F I L E D I A L O G B A S E C L A S S
830N/A#########################################################################*/
830N/A
830N/Avoid FileDialogBaseGtk::internalSetup()
830N/A{
830N/A // Open executable file dialogs don't need the preview panel
830N/A if (_dialogType != EXE_TYPES) {
830N/A Inkscape::Preferences *prefs = Inkscape::Preferences::get();
830N/A bool enablePreview = prefs->getBool(preferenceBase + "/enable_preview", true);
830N/A
830N/A previewCheckbox.set_label(Glib::ustring(_("Enable preview")));
830N/A previewCheckbox.set_active(enablePreview);
830N/A
830N/A previewCheckbox.signal_toggled().connect(sigc::mem_fun(*this, &FileDialogBaseGtk::_previewEnabledCB));
830N/A
830N/A // Catch selection-changed events, so we can adjust the text widget
830N/A signal_update_preview().connect(sigc::mem_fun(*this, &FileDialogBaseGtk::_updatePreviewCallback));
830N/A
830N/A //###### Add a preview widget
830N/A set_preview_widget(svgPreview);
830N/A set_preview_widget_active(enablePreview);
830N/A set_use_preview_label(false);
830N/A }
830N/A}
830N/A
830N/A
830N/Avoid FileDialogBaseGtk::cleanup(bool showConfirmed)
830N/A{
830N/A if (_dialogType != EXE_TYPES) {
830N/A Inkscape::Preferences *prefs = Inkscape::Preferences::get();
830N/A if (showConfirmed) {
830N/A prefs->setBool(preferenceBase + "/enable_preview", previewCheckbox.get_active());
830N/A }
830N/A }
830N/A}
830N/A
830N/A
830N/Avoid FileDialogBaseGtk::_previewEnabledCB()
830N/A{
830N/A bool enabled = previewCheckbox.get_active();
830N/A set_preview_widget_active(enabled);
830N/A if (enabled) {
830N/A _updatePreviewCallback();
830N/A } else {
830N/A // Clears out any current preview image.
830N/A svgPreview.showNoPreview();
830N/A }
830N/A}
830N/A
830N/A
830N/A
830N/A/**
830N/A * Callback for checking if the preview needs to be redrawn
830N/A */
830N/Avoid FileDialogBaseGtk::_updatePreviewCallback()
830N/A{
830N/A Glib::ustring fileName = get_preview_filename();
830N/A bool enabled = previewCheckbox.get_active();
830N/A
830N/A#ifdef WITH_GNOME_VFS
830N/A if (fileName.empty() && gnome_vfs_initialized()) {
830N/A fileName = get_preview_uri();
830N/A }
830N/A#endif
830N/A
830N/A if (enabled && !fileName.empty()) {
830N/A svgPreview.set(fileName, _dialogType);
830N/A } else {
830N/A svgPreview.showNoPreview();
830N/A }
830N/A}
830N/A
830N/A
830N/A/*#########################################################################
830N/A### F I L E O P E N
830N/A#########################################################################*/
830N/A
830N/A/**
830N/A * Constructor. Not called directly. Use the factory.
830N/A */
830N/AFileOpenDialogImplGtk::FileOpenDialogImplGtk(Gtk::Window &parentWindow, const Glib::ustring &dir,
830N/A FileDialogType fileTypes, const Glib::ustring &title)
830N/A : FileDialogBaseGtk(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_OPEN, fileTypes, "/dialogs/open")
830N/A{
830N/A
830N/A
830N/A if (_dialogType == EXE_TYPES) {
830N/A /* One file at a time */
830N/A set_select_multiple(false);
830N/A } else {
830N/A /* And also Multiple Files */
830N/A set_select_multiple(true);
830N/A }
830N/A
830N/A#ifdef WITH_GNOME_VFS
830N/A if (gnome_vfs_initialized()) {
830N/A set_local_only(false);
830N/A }
830N/A#endif
830N/A
830N/A /* Initalize to Autodetect */
830N/A extension = NULL;
830N/A /* No filename to start out with */
830N/A myFilename = "";
830N/A
830N/A /* Set our dialog type (open, import, etc...)*/
830N/A _dialogType = fileTypes;
830N/A
830N/A
830N/A /* Set the pwd and/or the filename */
830N/A if (dir.size() > 0) {
830N/A Glib::ustring udir(dir);
830N/A Glib::ustring::size_type len = udir.length();
830N/A // leaving a trailing backslash on the directory name leads to the infamous
830N/A // double-directory bug on win32
830N/A if (len != 0 && udir[len - 1] == '\\')
830N/A udir.erase(len - 1);
830N/A if (_dialogType == EXE_TYPES) {
830N/A set_filename(udir.c_str());
830N/A } else {
830N/A set_current_folder(udir.c_str());
830N/A }
830N/A }
830N/A
830N/A if (_dialogType != EXE_TYPES) {
830N/A set_extra_widget(previewCheckbox);
830N/A }
830N/A
830N/A //###### Add the file types menu
830N/A createFilterMenu();
830N/A
830N/A add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
830N/A set_default(*add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK));
830N/A
830N/A //###### Allow easy access to our examples folder
830N/A if (Inkscape::IO::file_test(INKSCAPE_EXAMPLESDIR, G_FILE_TEST_EXISTS) &&
830N/A Inkscape::IO::file_test(INKSCAPE_EXAMPLESDIR, G_FILE_TEST_IS_DIR) && g_path_is_absolute(INKSCAPE_EXAMPLESDIR)) {
830N/A add_shortcut_folder(INKSCAPE_EXAMPLESDIR);
830N/A }
830N/A}
830N/A
830N/A/**
830N/A * Destructor
830N/A */
830N/AFileOpenDialogImplGtk::~FileOpenDialogImplGtk()
830N/A{
830N/A}
830N/A
830N/Avoid FileOpenDialogImplGtk::addFilterMenu(Glib::ustring name, Glib::ustring pattern)
830N/A{
830N/A
830N/A#if WITH_GTKMM_3_0
830N/A Glib::RefPtr<Gtk::FileFilter> allFilter = Gtk::FileFilter::create();
830N/A allFilter->set_name(_(name.c_str()));
830N/A allFilter->add_pattern(pattern);
830N/A#else
830N/A Gtk::FileFilter allFilter;
830N/A allFilter.set_name(_(name.c_str()));
830N/A allFilter.add_pattern(pattern);
830N/A#endif
830N/A extensionMap[Glib::ustring(_("All Files"))] = NULL;
830N/A add_filter(allFilter);
830N/A}
830N/A
830N/Avoid FileOpenDialogImplGtk::createFilterMenu()
830N/A{
830N/A if (_dialogType == CUSTOM_TYPE) {
830N/A return;
830N/A }
830N/A
830N/A if (_dialogType == EXE_TYPES) {
830N/A#if WITH_GTKMM_3_0
830N/A Glib::RefPtr<Gtk::FileFilter> allFilter = Gtk::FileFilter::create();
830N/A allFilter->set_name(_("All Files"));
830N/A allFilter->add_pattern("*");
830N/A#else
830N/A Gtk::FileFilter allFilter;
830N/A allFilter.set_name(_("All Files"));
830N/A allFilter.add_pattern("*");
830N/A#endif
830N/A extensionMap[Glib::ustring(_("All Files"))] = NULL;
830N/A add_filter(allFilter);
830N/A } else {
830N/A#if WITH_GTKMM_3_0
830N/A Glib::RefPtr<Gtk::FileFilter> allInkscapeFilter = Gtk::FileFilter::create();
830N/A allInkscapeFilter->set_name(_("All Inkscape Files"));
830N/A
830N/A Glib::RefPtr<Gtk::FileFilter> allFilter = Gtk::FileFilter::create();
830N/A allFilter->set_name(_("All Files"));
830N/A allFilter->add_pattern("*");
830N/A
830N/A Glib::RefPtr<Gtk::FileFilter> allImageFilter = Gtk::FileFilter::create();
830N/A allImageFilter->set_name(_("All Images"));
830N/A
830N/A Glib::RefPtr<Gtk::FileFilter> allVectorFilter = Gtk::FileFilter::create();
830N/A allVectorFilter->set_name(_("All Vectors"));
830N/A
830N/A Glib::RefPtr<Gtk::FileFilter> allBitmapFilter = Gtk::FileFilter::create();
830N/A allBitmapFilter->set_name(_("All Bitmaps"));
830N/A#else
830N/A Gtk::FileFilter allInkscapeFilter;
830N/A allInkscapeFilter.set_name(_("All Inkscape Files"));
830N/A
830N/A Gtk::FileFilter allFilter;
830N/A allFilter.set_name(_("All Files"));
830N/A allFilter.add_pattern("*");
830N/A
830N/A Gtk::FileFilter allImageFilter;
830N/A allImageFilter.set_name(_("All Images"));
830N/A
830N/A Gtk::FileFilter allVectorFilter;
830N/A allVectorFilter.set_name(_("All Vectors"));
830N/A
830N/A Gtk::FileFilter allBitmapFilter;
830N/A allBitmapFilter.set_name(_("All Bitmaps"));
830N/A#endif
830N/A extensionMap[Glib::ustring(_("All Inkscape Files"))] = NULL;
830N/A add_filter(allInkscapeFilter);
830N/A
830N/A extensionMap[Glib::ustring(_("All Files"))] = NULL;
830N/A add_filter(allFilter);
830N/A
830N/A extensionMap[Glib::ustring(_("All Images"))] = NULL;
830N/A add_filter(allImageFilter);
830N/A
830N/A extensionMap[Glib::ustring(_("All Vectors"))] = NULL;
830N/A add_filter(allVectorFilter);
830N/A
830N/A extensionMap[Glib::ustring(_("All Bitmaps"))] = NULL;
830N/A add_filter(allBitmapFilter);
830N/A
830N/A // patterns added dynamically below
830N/A Inkscape::Extension::DB::InputList extension_list;
830N/A Inkscape::Extension::db.get_input_list(extension_list);
830N/A
830N/A for (Inkscape::Extension::DB::InputList::iterator current_item = extension_list.begin();
830N/A current_item != extension_list.end(); ++current_item)
830N/A {
830N/A Inkscape::Extension::Input *imod = *current_item;
830N/A
830N/A // FIXME: would be nice to grey them out instead of not listing them
830N/A if (imod->deactivated())
830N/A continue;
830N/A
830N/A Glib::ustring upattern("*");
830N/A Glib::ustring extension = imod->get_extension();
830N/A fileDialogExtensionToPattern(upattern, extension);
830N/A
830N/A Glib::ustring uname(_(imod->get_filetypename()));
830N/A
830N/A#if WITH_GTKMM_3_0
830N/A Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
830N/A filter->set_name(uname);
830N/A filter->add_pattern(upattern);
830N/A#else
830N/A Gtk::FileFilter filter;
830N/A filter.set_name(uname);
830N/A filter.add_pattern(upattern);
830N/A#endif
830N/A
830N/A add_filter(filter);
830N/A extensionMap[uname] = imod;
830N/A
830N/A// g_message("ext %s:%s '%s'\n", ioext->name, ioext->mimetype, upattern.c_str());
830N/A#if WITH_GTKMM_3_0
830N/A allInkscapeFilter->add_pattern(upattern);
830N/A if (strncmp("image", imod->get_mimetype(), 5) == 0)
830N/A allImageFilter->add_pattern(upattern);
830N/A#else
830N/A allInkscapeFilter.add_pattern(upattern);
830N/A if (strncmp("image", imod->get_mimetype(), 5) == 0)
830N/A allImageFilter.add_pattern(upattern);
830N/A#endif
830N/A
830N/A // uncomment this to find out all mime types supported by Inkscape import/open
830N/A // g_print ("%s\n", imod->get_mimetype());
830N/A
830N/A // I don't know of any other way to define "bitmap" formats other than by listing them
830N/A if (strncmp("image/png", imod->get_mimetype(), 9) == 0 ||
830N/A strncmp("image/jpeg", imod->get_mimetype(), 10) == 0 ||
830N/A strncmp("image/gif", imod->get_mimetype(), 9) == 0 ||
830N/A strncmp("image/x-icon", imod->get_mimetype(), 12) == 0 ||
830N/A strncmp("image/x-navi-animation", imod->get_mimetype(), 22) == 0 ||
830N/A strncmp("image/x-cmu-raster", imod->get_mimetype(), 18) == 0 ||
830N/A strncmp("image/x-xpixmap", imod->get_mimetype(), 15) == 0 ||
830N/A strncmp("image/bmp", imod->get_mimetype(), 9) == 0 ||
830N/A strncmp("image/vnd.wap.wbmp", imod->get_mimetype(), 18) == 0 ||
830N/A strncmp("image/tiff", imod->get_mimetype(), 10) == 0 ||
830N/A strncmp("image/x-xbitmap", imod->get_mimetype(), 15) == 0 ||
830N/A strncmp("image/x-tga", imod->get_mimetype(), 11) == 0 ||
830N/A strncmp("image/x-pcx", imod->get_mimetype(), 11) == 0)
830N/A {
830N/A#if WITH_GTKMM_3_0
830N/A allBitmapFilter->add_pattern(upattern);
830N/A#else
830N/A allBitmapFilter.add_pattern(upattern);
830N/A#endif
830N/A } else {
830N/A#if WITH_GTKMM_3_0
830N/A allVectorFilter->add_pattern(upattern);
830N/A#else
830N/A allVectorFilter.add_pattern(upattern);
830N/A#endif
830N/A }
830N/A }
830N/A }
830N/A return;
830N/A}
830N/A
830N/A/**
830N/A * Show this dialog modally. Return true if user hits [OK]
830N/A */
830N/Abool FileOpenDialogImplGtk::show()
830N/A{
830N/A set_modal(TRUE); // Window
830N/A sp_transientize(GTK_WIDGET(gobj())); // Make transient
830N/A gint b = run(); // Dialog
830N/A svgPreview.showNoPreview();
830N/A hide();
830N/A
830N/A if (b == Gtk::RESPONSE_OK) {
830N/A // This is a hack, to avoid the warning messages that
830N/A // Gtk::FileChooser::get_filter() returns
830N/A // should be: Gtk::FileFilter *filter = get_filter();
830N/A GtkFileChooser *gtkFileChooser = Gtk::FileChooser::gobj();
830N/A GtkFileFilter *filter = gtk_file_chooser_get_filter(gtkFileChooser);
830N/A if (filter) {
830N/A // Get which extension was chosen, if any
830N/A extension = extensionMap[gtk_file_filter_get_name(filter)];
830N/A }
830N/A myFilename = get_filename();
830N/A#ifdef WITH_GNOME_VFS
830N/A if (myFilename.empty() && gnome_vfs_initialized())
830N/A myFilename = get_uri();
830N/A#endif
830N/A cleanup(true);
830N/A return true;
830N/A } else {
830N/A cleanup(false);
830N/A return false;
830N/A }
830N/A}
830N/A
830N/A
830N/A
830N/A/**
830N/A * Get the file extension type that was selected by the user. Valid after an [OK]
830N/A */
830N/AInkscape::Extension::Extension *FileOpenDialogImplGtk::getSelectionType()
830N/A{
830N/A return extension;
830N/A}
830N/A
830N/A
830N/A/**
830N/A * Get the file name chosen by the user. Valid after an [OK]
830N/A */
830N/AGlib::ustring FileOpenDialogImplGtk::getFilename(void)
830N/A{
830N/A return myFilename;
830N/A}
830N/A
830N/A
830N/A/**
830N/A * To Get Multiple filenames selected at-once.
830N/A */
830N/Astd::vector<Glib::ustring> FileOpenDialogImplGtk::getFilenames()
830N/A{
830N/A#if WITH_GTKMM_3_0
830N/A std::vector<std::string> result_tmp = get_filenames();
830N/A
830N/A // Copy filenames to a vector of type Glib::ustring
830N/A std::vector<Glib::ustring> result;
830N/A
830N/A for (std::vector<std::string>::iterator it = result_tmp.begin(); it != result_tmp.end(); ++it)
830N/A result.push_back(*it);
830N/A
830N/A#else
830N/A std::vector<Glib::ustring> result = get_filenames();
830N/A#endif
830N/A
830N/A#ifdef WITH_GNOME_VFS
830N/A if (result.empty() && gnome_vfs_initialized())
830N/A result = get_uris();
830N/A#endif
830N/A return result;
830N/A}
830N/A
830N/AGlib::ustring FileOpenDialogImplGtk::getCurrentDirectory()
830N/A{
830N/A return get_current_folder();
830N/A}
830N/A
830N/A
830N/A
830N/A//########################################################################
830N/A//# F I L E S A V E
830N/A//########################################################################
830N/A
830N/A/**
830N/A * Constructor
830N/A */
830N/AFileSaveDialogImplGtk::FileSaveDialogImplGtk(Gtk::Window &parentWindow, const Glib::ustring &dir,
830N/A FileDialogType fileTypes, const Glib::ustring &title,
830N/A const Glib::ustring & /*default_key*/, const gchar *docTitle,
830N/A const Inkscape::Extension::FileSaveMethod save_method)
830N/A : FileDialogBaseGtk(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes,
830N/A (save_method == Inkscape::Extension::FILE_SAVE_METHOD_SAVE_COPY) ? "/dialogs/save_copy"
830N/A : "/dialogs/save_as")
830N/A , save_method(save_method)
830N/A{
830N/A FileSaveDialog::myDocTitle = docTitle;
830N/A
830N/A /* One file at a time */
830N/A set_select_multiple(false);
830N/A
830N/A#ifdef WITH_GNOME_VFS
830N/A if (gnome_vfs_initialized()) {
830N/A set_local_only(false);
830N/A }
830N/A#endif
830N/A
830N/A /* Initalize to Autodetect */
830N/A extension = NULL;
830N/A /* No filename to start out with */
830N/A myFilename = "";
830N/A
830N/A /* Set our dialog type (save, export, etc...)*/
830N/A _dialogType = fileTypes;
830N/A
830N/A /* Set the pwd and/or the filename */
830N/A if (dir.size() > 0) {
830N/A Glib::ustring udir(dir);
830N/A Glib::ustring::size_type len = udir.length();
830N/A // leaving a trailing backslash on the directory name leads to the infamous
830N/A // double-directory bug on win32
830N/A if ((len != 0) && (udir[len - 1] == '\\')) {
830N/A udir.erase(len - 1);
830N/A }
830N/A myFilename = udir;
830N/A }
830N/A
830N/A //###### Add the file types menu
830N/A // createFilterMenu();
830N/A
830N/A //###### Do we want the .xxx extension automatically added?
830N/A Inkscape::Preferences *prefs = Inkscape::Preferences::get();
830N/A fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically")));
830N/A if (save_method == Inkscape::Extension::FILE_SAVE_METHOD_SAVE_COPY) {
830N/A fileTypeCheckbox.set_active(prefs->getBool("/dialogs/save_copy/append_extension", true));
830N/A } else {
830N/A fileTypeCheckbox.set_active(prefs->getBool("/dialogs/save_as/append_extension", true));
830N/A }
830N/A
830N/A if (_dialogType != CUSTOM_TYPE)
830N/A createFileTypeMenu();
830N/A
830N/A fileTypeComboBox.set_size_request(200, 40);
830N/A fileTypeComboBox.signal_changed().connect(sigc::mem_fun(*this, &FileSaveDialogImplGtk::fileTypeChangedCallback));
830N/A
830N/A
830N/A childBox.pack_start(checksBox);
830N/A childBox.pack_end(fileTypeComboBox);
830N/A checksBox.pack_start(fileTypeCheckbox);
830N/A checksBox.pack_start(previewCheckbox);
830N/A
830N/A set_extra_widget(childBox);
830N/A
830N/A // Let's do some customization
830N/A fileNameEntry = NULL;
830N/A Gtk::Container *cont = get_toplevel();
830N/A std::vector<Gtk::Entry *> entries;
830N/A findEntryWidgets(cont, entries);
830N/A // g_message("Found %d entry widgets\n", entries.size());
830N/A if (!entries.empty()) {
830N/A // Catch when user hits [return] on the text field
830N/A fileNameEntry = entries[0];
830N/A fileNameEntry->signal_activate().connect(
830N/A sigc::mem_fun(*this, &FileSaveDialogImplGtk::fileNameEntryChangedCallback));
830N/A }
830N/A
830N/A // Let's do more customization
830N/A std::vector<Gtk::Expander *> expanders;
830N/A findExpanderWidgets(cont, expanders);
830N/A // g_message("Found %d expander widgets\n", expanders.size());
830N/A if (!expanders.empty()) {
830N/A // Always show the file list
830N/A Gtk::Expander *expander = expanders[0];
830N/A expander->set_expanded(true);
830N/A }
830N/A
830N/A // allow easy access to the user's own templates folder
830N/A gchar *templates = INKSCAPE->profile_path("templates");
830N/A if (Inkscape::IO::file_test(templates, G_FILE_TEST_EXISTS) &&
830N/A Inkscape::IO::file_test(templates, G_FILE_TEST_IS_DIR) && g_path_is_absolute(templates)) {
830N/A add_shortcut_folder(templates);
830N/A }
830N/A g_free(templates);
830N/A
830N/A
830N/A // if (extension == NULL)
830N/A // checkbox.set_sensitive(FALSE);
830N/A
830N/A add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
830N/A set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK));
830N/A
830N/A show_all_children();
830N/A}
830N/A
830N/A/**
830N/A * Destructor
830N/A */
830N/AFileSaveDialogImplGtk::~FileSaveDialogImplGtk()
830N/A{
830N/A}
830N/A
830N/A/**
830N/A * Callback for fileNameEntry widget
830N/A */
830N/Avoid FileSaveDialogImplGtk::fileNameEntryChangedCallback()
830N/A{
830N/A if (!fileNameEntry)
830N/A return;
830N/A
830N/A Glib::ustring fileName = fileNameEntry->get_text();
830N/A if (!Glib::get_charset()) // If we are not utf8
830N/A fileName = Glib::filename_to_utf8(fileName);
830N/A
830N/A // g_message("User hit return. Text is '%s'\n", fileName.c_str());
830N/A
830N/A if (!Glib::path_is_absolute(fileName)) {
830N/A // try appending to the current path
830N/A // not this way: fileName = get_current_folder() + "/" + fileName;
830N/A std::vector<Glib::ustring> pathSegments;
830N/A pathSegments.push_back(get_current_folder());
830N/A pathSegments.push_back(fileName);
830N/A fileName = Glib::build_filename(pathSegments);
830N/A }
830N/A
830N/A // g_message("path:'%s'\n", fileName.c_str());
830N/A
830N/A if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
830N/A set_current_folder(fileName);
830N/A } else if (/*Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)*/ 1) {
830N/A // dialog with either (1) select a regular file or (2) cd to dir
830N/A // simulate an 'OK'
830N/A set_filename(fileName);
830N/A response(Gtk::RESPONSE_OK);
830N/A }
830N/A}
830N/A
830N/A
830N/A
830N/A/**
830N/A * Callback for fileNameEntry widget
830N/A */
830N/Avoid FileSaveDialogImplGtk::fileTypeChangedCallback()
830N/A{
830N/A int sel = fileTypeComboBox.get_active_row_number();
830N/A if ((sel < 0) || (sel >= (int)fileTypes.size()))
830N/A return;
830N/A
830N/A FileType type = fileTypes[sel];
830N/A // g_message("selected: %s\n", type.name.c_str());
830N/A
830N/A extension = type.extension;
830N/A#if WITH_GTKMM_3_0
830N/A Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
830N/A filter->add_pattern(type.pattern);
830N/A#else
830N/A Gtk::FileFilter filter;
830N/A filter.add_pattern(type.pattern);
830N/A#endif
830N/A set_filter(filter);
830N/A
830N/A updateNameAndExtension();
830N/A}
830N/A
830N/Avoid FileSaveDialogImplGtk::addFileType(Glib::ustring name, Glib::ustring pattern)
830N/A{
830N/A //#Let user choose
830N/A FileType guessType;
830N/A guessType.name = name;
830N/A guessType.pattern = pattern;
830N/A guessType.extension = NULL;
830N/A fileTypeComboBox.append(guessType.name);
830N/A fileTypes.push_back(guessType);
830N/A
830N/A
830N/A fileTypeComboBox.set_active(0);
830N/A fileTypeChangedCallback(); // call at least once to set the filter
830N/A}
830N/A
830N/Avoid FileSaveDialogImplGtk::createFileTypeMenu()
830N/A{
830N/A Inkscape::Extension::DB::OutputList extension_list;
830N/A Inkscape::Extension::db.get_output_list(extension_list);
830N/A knownExtensions.clear();
830N/A
830N/A for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();
830N/A current_item != extension_list.end(); ++current_item) {
830N/A Inkscape::Extension::Output *omod = *current_item;
830N/A
830N/A // FIXME: would be nice to grey them out instead of not listing them
830N/A if (omod->deactivated())
830N/A continue;
830N/A
830N/A FileType type;
830N/A type.name = (_(omod->get_filetypename()));
830N/A type.pattern = "*";
830N/A Glib::ustring extension = omod->get_extension();
830N/A knownExtensions.insert(extension.casefold());
830N/A fileDialogExtensionToPattern(type.pattern, extension);
830N/A type.extension = omod;
830N/A fileTypeComboBox.append(type.name);
830N/A fileTypes.push_back(type);
830N/A }
830N/A
830N/A //#Let user choose
830N/A FileType guessType;
830N/A guessType.name = _("Guess from extension");
830N/A guessType.pattern = "*";
830N/A guessType.extension = NULL;
830N/A fileTypeComboBox.append(guessType.name);
830N/A fileTypes.push_back(guessType);
830N/A
830N/A
830N/A fileTypeComboBox.set_active(0);
830N/A fileTypeChangedCallback(); // call at least once to set the filter
830N/A}
830N/A
830N/A
830N/A
830N/A/**
830N/A * Show this dialog modally. Return true if user hits [OK]
830N/A */
830N/Abool FileSaveDialogImplGtk::show()
830N/A{
830N/A change_path(myFilename);
830N/A set_modal(TRUE); // Window
830N/A sp_transientize(GTK_WIDGET(gobj())); // Make transient
830N/A gint b = run(); // Dialog
830N/A svgPreview.showNoPreview();
830N/A set_preview_widget_active(false);
830N/A hide();
830N/A
830N/A if (b == Gtk::RESPONSE_OK) {
830N/A updateNameAndExtension();
830N/A Inkscape::Preferences *prefs = Inkscape::Preferences::get();
830N/A
830N/A // Store changes of the "Append filename automatically" checkbox back to preferences.
830N/A if (save_method == Inkscape::Extension::FILE_SAVE_METHOD_SAVE_COPY) {
830N/A prefs->setBool("/dialogs/save_copy/append_extension", fileTypeCheckbox.get_active());
830N/A } else {
830N/A prefs->setBool("/dialogs/save_as/append_extension", fileTypeCheckbox.get_active());
830N/A }
830N/A
830N/A Inkscape::Extension::store_file_extension_in_prefs((extension != NULL ? extension->get_id() : ""), save_method);
830N/A
830N/A cleanup(true);
830N/A
830N/A return true;
830N/A } else {
830N/A cleanup(false);
830N/A return false;
830N/A }
830N/A}
830N/A
830N/A
830N/A/**
830N/A * Get the file extension type that was selected by the user. Valid after an [OK]
830N/A */
830N/AInkscape::Extension::Extension *FileSaveDialogImplGtk::getSelectionType()
830N/A{
830N/A return extension;
830N/A}
830N/A
830N/Avoid FileSaveDialogImplGtk::setSelectionType(Inkscape::Extension::Extension *key)
830N/A{
830N/A // If no pointer to extension is passed in, look up based on filename extension.
830N/A if (!key) {
830N/A // Not quite UTF-8 here.
830N/A gchar *filenameLower = g_ascii_strdown(myFilename.c_str(), -1);
830N/A for (int i = 0; !key && (i < (int)fileTypes.size()); i++) {
830N/A Inkscape::Extension::Output *ext = dynamic_cast<Inkscape::Extension::Output *>(fileTypes[i].extension);
830N/A if (ext && ext->get_extension()) {
830N/A gchar *extensionLower = g_ascii_strdown(ext->get_extension(), -1);
830N/A if (g_str_has_suffix(filenameLower, extensionLower)) {
830N/A key = fileTypes[i].extension;
830N/A }
830N/A g_free(extensionLower);
830N/A }
830N/A }
830N/A g_free(filenameLower);
830N/A }
830N/A
830N/A // Ensure the proper entry in the combo box is selected.
830N/A if (key) {
830N/A extension = key;
830N/A gchar const *extensionID = extension->get_id();
830N/A if (extensionID) {
830N/A for (int i = 0; i < (int)fileTypes.size(); i++) {
830N/A Inkscape::Extension::Extension *ext = fileTypes[i].extension;
830N/A if (ext) {
830N/A gchar const *id = ext->get_id();
830N/A if (id && (strcmp(extensionID, id) == 0)) {
830N/A int oldSel = fileTypeComboBox.get_active_row_number();
830N/A if (i != oldSel) {
830N/A fileTypeComboBox.set_active(i);
830N/A }
830N/A break;
830N/A }
830N/A }
830N/A }
830N/A }
830N/A }
830N/A}
830N/A
830N/AGlib::ustring FileSaveDialogImplGtk::getCurrentDirectory()
830N/A{
830N/A return get_current_folder();
830N/A}
830N/A
830N/A
830N/A/*void
830N/AFileSaveDialogImplGtk::change_title(const Glib::ustring& title)
830N/A{
830N/A set_title(title);
830N/A}*/
830N/A
830N/A/**
830N/A * Change the default save path location.
830N/A */
830N/Avoid FileSaveDialogImplGtk::change_path(const Glib::ustring &path)
830N/A{
830N/A myFilename = path;
830N/A
830N/A if (Glib::file_test(myFilename, Glib::FILE_TEST_IS_DIR)) {
830N/A // fprintf(stderr,"set_current_folder(%s)\n",myFilename.c_str());
830N/A set_current_folder(myFilename);
830N/A } else {
830N/A // fprintf(stderr,"set_filename(%s)\n",myFilename.c_str());
830N/A if (Glib::file_test(myFilename, Glib::FILE_TEST_EXISTS)) {
830N/A set_filename(myFilename);
830N/A } else {
830N/A std::string dirName = Glib::path_get_dirname(myFilename);
830N/A if (dirName != get_current_folder()) {
830N/A set_current_folder(dirName);
830N/A }
830N/A }
830N/A Glib::ustring basename = Glib::path_get_basename(myFilename);
830N/A // fprintf(stderr,"set_current_name(%s)\n",basename.c_str());
830N/A try
830N/A {
830N/A set_current_name(Glib::filename_to_utf8(basename));
830N/A }
830N/A catch (Glib::ConvertError &e)
830N/A {
830N/A g_warning("Error converting save filename to UTF-8.");
830N/A // try a fallback.
830N/A set_current_name(basename);
830N/A }
830N/A }
830N/A}
830N/A
830N/Avoid FileSaveDialogImplGtk::updateNameAndExtension()
830N/A{
830N/A // Pick up any changes the user has typed in.
830N/A Glib::ustring tmp = get_filename();
830N/A#ifdef WITH_GNOME_VFS
830N/A if (tmp.empty() && gnome_vfs_initialized()) {
830N/A tmp = get_uri();
830N/A }
830N/A#endif
830N/A if (!tmp.empty()) {
830N/A myFilename = tmp;
830N/A }
830N/A
830N/A Inkscape::Extension::Output *newOut = extension ? dynamic_cast<Inkscape::Extension::Output *>(extension) : 0;
830N/A if (fileTypeCheckbox.get_active() && newOut) {
830N/A // Append the file extension if it's not already present and display it in the file name entry field
830N/A appendExtension(myFilename, newOut);
830N/A change_path(myFilename);
830N/A }
830N/A}
830N/A
830N/A
830N/A#ifdef NEW_EXPORT_DIALOG
830N/A
830N/A//########################################################################
830N/A//# F I L E E X P O R T
830N/A//########################################################################
830N/A
830N/A/**
830N/A * Callback for fileNameEntry widget
830N/A */
830N/Avoid FileExportDialogImpl::fileNameEntryChangedCallback()
830N/A{
830N/A if (!fileNameEntry)
830N/A return;
830N/A
830N/A Glib::ustring fileName = fileNameEntry->get_text();
830N/A if (!Glib::get_charset()) // If we are not utf8
830N/A fileName = Glib::filename_to_utf8(fileName);
830N/A
830N/A // g_message("User hit return. Text is '%s'\n", fileName.c_str());
830N/A
830N/A if (!Glib::path_is_absolute(fileName)) {
830N/A // try appending to the current path
830N/A // not this way: fileName = get_current_folder() + "/" + fileName;
830N/A std::vector<Glib::ustring> pathSegments;
830N/A pathSegments.push_back(get_current_folder());
830N/A pathSegments.push_back(fileName);
830N/A fileName = Glib::build_filename(pathSegments);
830N/A }
830N/A
830N/A // g_message("path:'%s'\n", fileName.c_str());
830N/A
830N/A if (Glib::file_test(fileName, Glib::FILE_TEST_IS_DIR)) {
830N/A set_current_folder(fileName);
830N/A } else if (/*Glib::file_test(fileName, Glib::FILE_TEST_IS_REGULAR)*/ 1) {
830N/A // dialog with either (1) select a regular file or (2) cd to dir
830N/A // simulate an 'OK'
830N/A set_filename(fileName);
830N/A response(Gtk::RESPONSE_OK);
830N/A }
830N/A}
830N/A
830N/A
830N/A
830N/A/**
830N/A * Callback for fileNameEntry widget
830N/A */
830N/Avoid FileExportDialogImpl::fileTypeChangedCallback()
830N/A{
830N/A int sel = fileTypeComboBox.get_active_row_number();
830N/A if ((sel < 0) || (sel >= (int)fileTypes.size()))
830N/A return;
830N/A
830N/A FileType type = fileTypes[sel];
830N/A // g_message("selected: %s\n", type.name.c_str());
830N/A Gtk::FileFilter filter;
830N/A filter.add_pattern(type.pattern);
830N/A set_filter(filter);
830N/A}
830N/A
830N/A
830N/A
830N/Avoid FileExportDialogImpl::createFileTypeMenu()
830N/A{
830N/A Inkscape::Extension::DB::OutputList extension_list;
830N/A Inkscape::Extension::db.get_output_list(extension_list);
830N/A
830N/A for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin();
830N/A current_item != extension_list.end(); ++current_item) {
830N/A Inkscape::Extension::Output *omod = *current_item;
830N/A
830N/A // FIXME: would be nice to grey them out instead of not listing them
830N/A if (omod->deactivated())
830N/A continue;
830N/A
830N/A FileType type;
830N/A type.name = (_(omod->get_filetypename()));
830N/A type.pattern = "*";
830N/A Glib::ustring extension = omod->get_extension();
830N/A fileDialogExtensionToPattern(type.pattern, extension);
830N/A type.extension = omod;
830N/A fileTypeComboBox.append_text(type.name);
830N/A fileTypes.push_back(type);
830N/A }
830N/A
830N/A //#Let user choose
830N/A FileType guessType;
830N/A guessType.name = _("Guess from extension");
830N/A guessType.pattern = "*";
830N/A guessType.extension = NULL;
830N/A fileTypeComboBox.append_text(guessType.name);
830N/A fileTypes.push_back(guessType);
830N/A
830N/A
830N/A fileTypeComboBox.set_active(0);
830N/A fileTypeChangedCallback(); // call at least once to set the filter
830N/A}
830N/A
830N/A
830N/A/**
830N/A * Constructor
830N/A */
830N/AFileExportDialogImpl::FileExportDialogImpl(Gtk::Window &parentWindow, const Glib::ustring &dir,
830N/A FileDialogType fileTypes, const Glib::ustring &title,
830N/A const Glib::ustring & /*default_key*/)
830N/A : FileDialogBaseGtk(parentWindow, title, Gtk::FILE_CHOOSER_ACTION_SAVE, fileTypes, "/dialogs/export")
830N/A , sourceX0Spinner("X0", _("Left edge of source"))
830N/A , sourceY0Spinner("Y0", _("Top edge of source"))
830N/A , sourceX1Spinner("X1", _("Right edge of source"))
830N/A , sourceY1Spinner("Y1", _("Bottom edge of source"))
830N/A , sourceWidthSpinner("Width", _("Source width"))
830N/A , sourceHeightSpinner("Height", _("Source height"))
830N/A , destWidthSpinner("Width", _("Destination width"))
830N/A , destHeightSpinner("Height", _("Destination height"))
830N/A , destDPISpinner("DPI", _("Resolution (dots per inch)"))
830N/A{
830N/A Inkscape::Preferences *prefs = Inkscape::Preferences::get();
830N/A append_extension = prefs->getBool("/dialogs/save_export/append_extension", true);
830N/A
830N/A /* One file at a time */
830N/A set_select_multiple(false);
830N/A
830N/A#ifdef WITH_GNOME_VFS
830N/A if (gnome_vfs_initialized()) {
830N/A set_local_only(false);
830N/A }
830N/A#endif
830N/A
830N/A /* Initalize to Autodetect */
830N/A extension = NULL;
830N/A /* No filename to start out with */
830N/A myFilename = "";
830N/A
830N/A /* Set our dialog type (save, export, etc...)*/
830N/A _dialogType = fileTypes;
830N/A
830N/A /* Set the pwd and/or the filename */
830N/A if (dir.size() > 0) {
830N/A Glib::ustring udir(dir);
830N/A Glib::ustring::size_type len = udir.length();
830N/A // leaving a trailing backslash on the directory name leads to the infamous
830N/A // double-directory bug on win32
830N/A if ((len != 0) && (udir[len - 1] == '\\'))
830N/A udir.erase(len - 1);
830N/A set_current_folder(udir.c_str());
830N/A }
830N/A
830N/A //#########################################
830N/A //## EXTRA WIDGET -- SOURCE SIDE
830N/A //#########################################
830N/A
830N/A //##### Export options buttons/spinners, etc
830N/A documentButton.set_label(_("Document"));
830N/A scopeBox.pack_start(documentButton);
830N/A scopeGroup = documentButton.get_group();
830N/A
830N/A pageButton.set_label(_("Page"));
830N/A pageButton.set_group(scopeGroup);
830N/A scopeBox.pack_start(pageButton);
830N/A
830N/A selectionButton.set_label(_("Selection"));
830N/A selectionButton.set_group(scopeGroup);
830N/A scopeBox.pack_start(selectionButton);
830N/A
830N/A customButton.set_label(C_("Export dialog", "Custom"));
830N/A customButton.set_group(scopeGroup);
830N/A scopeBox.pack_start(customButton);
830N/A
830N/A sourceBox.pack_start(scopeBox);
830N/A
830N/A
830N/A
830N/A // dimension buttons
830N/A sourceTable.resize(3, 3);
830N/A sourceTable.attach(sourceX0Spinner, 0, 1, 0, 1);
830N/A sourceTable.attach(sourceY0Spinner, 1, 2, 0, 1);
830N/A sourceUnitsSpinner.setUnitType(UNIT_TYPE_LINEAR);
830N/A sourceTable.attach(sourceUnitsSpinner, 2, 3, 0, 1);
830N/A sourceTable.attach(sourceX1Spinner, 0, 1, 1, 2);
830N/A sourceTable.attach(sourceY1Spinner, 1, 2, 1, 2);
830N/A sourceTable.attach(sourceWidthSpinner, 0, 1, 2, 3);
830N/A sourceTable.attach(sourceHeightSpinner, 1, 2, 2, 3);
830N/A
830N/A sourceBox.pack_start(sourceTable);
830N/A sourceFrame.set_label(_("Source"));
830N/A sourceFrame.add(sourceBox);
830N/A exportOptionsBox.pack_start(sourceFrame);
830N/A
830N/A
830N/A //#########################################
830N/A //## EXTRA WIDGET -- SOURCE SIDE
830N/A //#########################################
830N/A
830N/A
830N/A destTable.resize(3, 3);
830N/A destTable.attach(destWidthSpinner, 0, 1, 0, 1);
830N/A destTable.attach(destHeightSpinner, 1, 2, 0, 1);
830N/A destUnitsSpinner.setUnitType(UNIT_TYPE_LINEAR);
830N/A destTable.attach(destUnitsSpinner, 2, 3, 0, 1);
830N/A destTable.attach(destDPISpinner, 0, 1, 1, 2);
830N/A
830N/A destBox.pack_start(destTable);
830N/A
830N/A
830N/A cairoButton.set_label(_("Cairo"));
830N/A otherOptionBox.pack_start(cairoButton);
830N/A
830N/A antiAliasButton.set_label(_("Antialias"));
830N/A otherOptionBox.pack_start(antiAliasButton);
830N/A
830N/A backgroundButton.set_label(_("Background"));
830N/A otherOptionBox.pack_start(backgroundButton);
830N/A
830N/A destBox.pack_start(otherOptionBox);
830N/A
830N/A
830N/A
830N/A //###### File options
830N/A //###### Do we want the .xxx extension automatically added?
830N/A fileTypeCheckbox.set_label(Glib::ustring(_("Append filename extension automatically")));
830N/A fileTypeCheckbox.set_active(append_extension);
830N/A destBox.pack_start(fileTypeCheckbox);
830N/A
830N/A //###### File type menu
830N/A createFileTypeMenu();
830N/A fileTypeComboBox.set_size_request(200, 40);
830N/A fileTypeComboBox.signal_changed().connect(sigc::mem_fun(*this, &FileExportDialogImpl::fileTypeChangedCallback));
830N/A
830N/A destBox.pack_start(fileTypeComboBox);
830N/A
830N/A destFrame.set_label(_("Destination"));
830N/A destFrame.add(destBox);
830N/A exportOptionsBox.pack_start(destFrame);
830N/A
830N/A //##### Put the two boxes and their parent onto the dialog
830N/A exportOptionsBox.pack_start(sourceFrame);
830N/A exportOptionsBox.pack_start(destFrame);
830N/A
830N/A set_extra_widget(exportOptionsBox);
830N/A
830N/A
830N/A
830N/A // Let's do some customization
830N/A fileNameEntry = NULL;
830N/A Gtk::Container *cont = get_toplevel();
830N/A std::vector<Gtk::Entry *> entries;
830N/A findEntryWidgets(cont, entries);
830N/A // g_message("Found %d entry widgets\n", entries.size());
830N/A if (!entries.empty()) {
830N/A // Catch when user hits [return] on the text field
830N/A fileNameEntry = entries[0];
830N/A fileNameEntry->signal_activate().connect(
830N/A sigc::mem_fun(*this, &FileExportDialogImpl::fileNameEntryChangedCallback));
830N/A }
830N/A
830N/A // Let's do more customization
830N/A std::vector<Gtk::Expander *> expanders;
830N/A findExpanderWidgets(cont, expanders);
830N/A // g_message("Found %d expander widgets\n", expanders.size());
830N/A if (!expanders.empty()) {
830N/A // Always show the file list
830N/A Gtk::Expander *expander = expanders[0];
830N/A expander->set_expanded(true);
830N/A }
830N/A
830N/A
830N/A // if (extension == NULL)
830N/A // checkbox.set_sensitive(FALSE);
830N/A
830N/A add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
830N/A set_default(*add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK));
830N/A
830N/A show_all_children();
830N/A}
830N/A
830N/A/**
830N/A * Destructor
830N/A */
830N/AFileExportDialogImpl::~FileExportDialogImpl()
830N/A{
830N/A}
830N/A
830N/A
830N/A
830N/A/**
830N/A * Show this dialog modally. Return true if user hits [OK]
830N/A */
830N/Abool FileExportDialogImpl::show()
830N/A{
830N/A Glib::ustring s = Glib::filename_to_utf8(get_current_folder());
830N/A if (s.length() == 0) {
830N/A s = getcwd(NULL, 0);
830N/A }
830N/A set_current_folder(Glib::filename_from_utf8(s)); // hack to force initial dir listing
830N/A set_modal(TRUE); // Window
830N/A sp_transientize(GTK_WIDGET(gobj())); // Make transient
830N/A gint b = run(); // Dialog
830N/A svgPreview.showNoPreview();
830N/A hide();
830N/A
830N/A if (b == Gtk::RESPONSE_OK) {
830N/A int sel = fileTypeComboBox.get_active_row_number();
830N/A if (sel >= 0 && sel < (int)fileTypes.size()) {
830N/A FileType &type = fileTypes[sel];
830N/A extension = type.extension;
830N/A }
830N/A myFilename = get_filename();
830N/A#ifdef WITH_GNOME_VFS
830N/A if (myFilename.empty() && gnome_vfs_initialized()) {
830N/A myFilename = get_uri();
830N/A }
830N/A#endif
830N/A
830N/A /*
830N/A
830N/A // FIXME: Why do we have more code
830N/A
830N/A append_extension = checkbox.get_active();
830N/A Inkscape::Preferences *prefs = Inkscape::Preferences::get();
830N/A prefs->setBool("/dialogs/save_export/append_extension", append_extension);
830N/A prefs->setBool("/dialogs/save_export/default", ( extension != NULL ? extension->get_id() : "" ));
830N/A */
830N/A return true;
830N/A } else {
830N/A return false;
830N/A }
830N/A}
830N/A
830N/A
830N/A/**
830N/A * Get the file extension type that was selected by the user. Valid after an [OK]
830N/A */
830N/AInkscape::Extension::Extension *FileExportDialogImpl::getSelectionType()
830N/A{
830N/A return extension;
830N/A}
830N/A
830N/A
830N/A/**
830N/A * Get the file name chosen by the user. Valid after an [OK]
830N/A */
830N/AGlib::ustring FileExportDialogImpl::getFilename()
830N/A{
830N/A return myFilename;
830N/A}
830N/A
830N/A#endif // NEW_EXPORT_DIALOG
830N/A
830N/A
830N/A} // namespace Dialog
830N/A} // namespace UI
830N/A} // namespace Inkscape
830N/A
830N/A/*
830N/A Local Variables:
830N/A mode:c++
830N/A c-file-style:"stroustrup"
830N/A c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
830N/A indent-tabs-mode:nil
830N/A fill-column:99
830N/A End:
830N/A*/
830N/A// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
830N/A