Logo Search packages:      
Sourcecode: inkscape version File versions

bool sp_file_export_to_ocal_dialog ( Gtk::Window &  parentWindow  ) 

Display an Export dialog, export as the selected type if OK pressed

Definition at line 1266 of file file.cpp.

References Inkscape::Extension::db, file_save(), Inkscape::Preferences::get(), Inkscape::UI::Dialog::FileExportToOCALDialog::getFilename(), Inkscape::UI::Dialog::FileExportToOCALPasswordDialog::getPassword(), Inkscape::Preferences::getString(), Inkscape::UI::Dialog::FileExportToOCALPasswordDialog::getUsername(), SPDocument::isModifiedSinceSave(), Inkscape::UI::Dialog::FileExportToOCALPasswordDialog::show(), Inkscape::UI::Dialog::FileExportToOCALDialog::show(), and SPDocument::uri.

Referenced by sp_file_export_to_ocal().

{

   if (!SP_ACTIVE_DOCUMENT)
        return false;

    SPDocument *doc = SP_ACTIVE_DOCUMENT;

    Glib::ustring export_path;
    Glib::ustring export_loc;
    Glib::ustring fileName;
    Inkscape::Extension::Extension *selectionType;

    bool success = false;

    static bool gotSuccess = false;

    Inkscape::XML::Node *repr = sp_document_repr_root(doc);
    (void)repr;

    if (!doc->uri && !doc->isModifiedSinceSave())
        return false;

    //  Get the default extension name
    Glib::ustring default_extension = "org.inkscape.output.svg.inkscape";
    char formatBuf[256];

    Glib::ustring filename_extension = ".svg";
    selectionType = Inkscape::Extension::db.get(default_extension.c_str());

    export_path = Glib::get_tmp_dir ();

    export_loc = export_path;
    export_loc.append(G_DIR_SEPARATOR_S);
    snprintf(formatBuf, 255, _("drawing%s"), filename_extension.c_str());
    export_loc.append(formatBuf);

    // convert save_loc from utf-8 to locale
    // is this needed any more, now that everything is handled in
    // Inkscape::IO?
    Glib::ustring export_path_local = Glib::filename_from_utf8(export_path);
    if ( export_path_local.size() > 0)
        export_path = export_path_local;

    // Show the Export To OCAL dialog
    Inkscape::UI::Dialog::FileExportToOCALDialog *exportDialogInstance =
        new Inkscape::UI::Dialog::FileExportToOCALDialog(
                parentWindow,
                Inkscape::UI::Dialog::EXPORT_TYPES,
                (char const *) _("Select file to export to")
                );

    success = exportDialogInstance->show();
    if (!success) {
        delete exportDialogInstance;
        return success;
    }

    fileName = exportDialogInstance->getFilename();

    delete exportDialogInstance;
    exportDialogInstance = NULL;;

    fileName.append(filename_extension.c_str());
    if (fileName.size() > 0) {
        Glib::ustring newFileName = Glib::filename_to_utf8(fileName);

        if ( newFileName.size()>0 )
            fileName = newFileName;
        else
            g_warning( "Error converting save filename to UTF-8." );
    }
    Glib::ustring filePath = export_path;
    filePath.append(G_DIR_SEPARATOR_S);
    filePath.append(Glib::path_get_basename(fileName));

    fileName = filePath;

    success = file_save(parentWindow, doc, filePath, selectionType, FALSE, FALSE);

    if (!success){
        gchar *text = g_strdup_printf(_("Error saving a temporary copy"));
        sp_ui_error_dialog(text);

        return success;
    }

    // Start now the submition

    // Create the uri
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
    Glib::ustring uri = "dav://";
    Glib::ustring username = prefs->getString("/options/ocalusername/str");
    Glib::ustring password = prefs->getString("/options/ocalpassword/str");
    if (username.empty() || password.empty())
    {
        Inkscape::UI::Dialog::FileExportToOCALPasswordDialog *exportPasswordDialogInstance = NULL;
        if(!gotSuccess)
        {
            exportPasswordDialogInstance = new Inkscape::UI::Dialog::FileExportToOCALPasswordDialog(
                    parentWindow,
                    (char const *) _("Open Clip Art Login"));
            success = exportPasswordDialogInstance->show();
            if (!success) {
                delete exportPasswordDialogInstance;
                return success;
            }
        }
        username = exportPasswordDialogInstance->getUsername();
        password = exportPasswordDialogInstance->getPassword();

        delete exportPasswordDialogInstance;
        exportPasswordDialogInstance = NULL;
    }
    uri.append(username);
    uri.append(":");
    uri.append(password);
    uri.append("@");
    uri.append(prefs->getString("/options/ocalurl/str"));
    uri.append("/dav.php/");
    uri.append(Glib::path_get_basename(fileName));

    // Save as a remote file using the dav protocol.
    success = file_save_remote(doc, uri, selectionType, FALSE, FALSE);
    remove(fileName.c_str());
    if (!success)
    {
        gchar *text = g_strdup_printf(_("Error exporting the document. Verify if the server name, username and password are correct, if the server has support for webdav and verify if you didn't forget to choose a license."));
        sp_ui_error_dialog(text);
    }
    else
        gotSuccess = true;

    return success;
}


Generated by  Doxygen 1.6.0   Back to index