Logo Search packages:      
Sourcecode: inkscape version File versions  Download package

bool Inkscape::UI::ClipboardManagerImpl::_pasteImage (  ) [private]

Retrieve a bitmap image from the clipboard and paste it into the active document.

Todo:
Check whether the encoding is correct here

Definition at line 866 of file clipboard.cpp.

References _clipboard, file_import(), Inkscape::Preferences::get(), and Inkscape::Preferences::getString().

Referenced by paste().

{
    SPDocument *doc = SP_ACTIVE_DOCUMENT;
    if ( doc == NULL ) return false;

    // retrieve image data
    Glib::RefPtr<Gdk::Pixbuf> img = _clipboard->wait_for_image();
    if (!img) return false;

    // Very stupid hack: Write into a file, then import the file into the document.
    // To avoid using tmpfile and POSIX file handles, make the filename based on current time.
    // This wasn't my idea, I just copied this from selection-chemistry.cpp
    // and just can't think of something saner at the moment. Pasting more than
    // one image per second will overwrite the image.
    // However, I don't think anyone is able to copy a _different_ image into inkscape
    // in 1 second.
    time_t rawtime;
    char image_filename[128];

    time(&rawtime);
    strftime(image_filename, 128, "inkscape_pasted_image_%Y%m%d_%H%M%S.png", localtime( &rawtime ));
    /// @todo Check whether the encoding is correct here
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
    std::string save_folder = Glib::filename_from_utf8(prefs->getString("/dialogs/save_as/path"));

    gchar *image_path = g_build_filename(save_folder.data(), image_filename, NULL);
    img->save(image_path, "png");
    file_import(doc, image_path, NULL);
    g_free(image_path);

    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index