static bool HasSomethingToPaste (kpMainWindow *mw)
{
#if DEBUG_KP_MAIN_WINDOW
    kdDebug () << "kpMainWindow(" << mw->name () << "):HasSomethingToPaste()" << endl;
    QTime timer;
    timer.start ();
#else
    (void) mw;
#endif

    bool hasSomething = false;

    QMimeSource *ms = QApplication::clipboard ()->data (QClipboard::Clipboard);
    if (ms)
    {
        // It's faster to test for QTextDrag::canDecode() first due to the
        // lazy evaluation of the '||' operator.
        hasSomething = (QTextDrag::canDecode (ms) ||
                        kpSelectionDrag::canDecode (ms));
    #if DEBUG_KP_MAIN_WINDOW
        kdDebug () << "\t" << mw->name () << "***canDecode=" << timer.restart () << endl;
        for (int i = 0; ; i++)
        {
            const char *fmt = ms->format (i);
            if (!fmt)
                break;

            kdDebug () << "\t'" << fmt << "'" << endl;
        }
    #endif
    }

    return hasSomething;
}
Exemple #2
0
KIO_EXPORT QString KIO::pasteActionText()
{
    QMimeSource *data = QApplication::clipboard()->data();
    KURL::List urls;
    if(KURLDrag::canDecode(data) && KURLDrag::decode(data, urls))
    {
        if(urls.isEmpty())
            return QString::null; // nothing to paste
        else if(urls.first().isLocalFile())
            return i18n("&Paste File", "&Paste %n Files", urls.count());
        else
            return i18n("&Paste URL", "&Paste %n URLs", urls.count());
    }
    else if(data->format(0) != 0)
    {
        return i18n("&Paste Clipboard Contents");
    }
    else
    {
        return QString::null;
    }
}
// public slot
void kpMainWindow::slotPaste ()
{
#if DEBUG_KP_MAIN_WINDOW && 1
    kdDebug () << "kpMainWindow::slotPaste() CALLED" << endl;
#endif

    // sync: restoreOverrideCursor() in all exit paths
    QApplication::setOverrideCursor (Qt::waitCursor);

    if (toolHasBegunShape ())
        tool ()->endShapeInternal ();


    if (!::HasSomethingToPasteWithDialogIfNot (this))
    {
        QApplication::restoreOverrideCursor ();
        return;
    }


    //
    // Acquire the pixmap
    //

    QMimeSource *ms = QApplication::clipboard ()->data (QClipboard::Clipboard);
    if (!ms)
    {
        kdError () << "kpMainWindow::slotPaste() without mimeSource" << endl;
        QApplication::restoreOverrideCursor ();
        return;
    }

    kpSelection sel;
    QString text;
    if (kpSelectionDrag::decode (ms, sel/*ref*/, pasteWarnAboutLossInfo ()))
    {
        sel.setTransparency (selectionTransparency ());
        paste (sel);
    }
    else if (QTextDrag::decode (ms, text/*ref*/))
    {
        pasteText (text);
    }
    else
    {
        QApplication::restoreOverrideCursor ();

        kdDebug () << "kpMainWindow::slotPaste() could not decode selection" << endl;
        kdDebug () << "\tFormats supported:" << endl;
        for (int i = 0; ms->format (i); i++)
        {
            kdDebug () << "\t\t" << i << ":" << ms->format (i) << endl;
        }

        // TODO: fix Klipper
        KMessageBox::sorry (this,
            i18n ("<qt><p>KolourPaint cannot paste the contents of"
                  " the clipboard as the data unexpectedly disappeared.</p>"

                  "<p>This usually occurs if the application which was"
                  " responsible"
                  " for the clipboard contents has been closed.</p></qt>"),
            i18n ("Cannot Paste"));

        // TODO: PROPAGATE: interprocess
        if (KMainWindow::memberList)
        {
        #if DEBUG_KP_MAIN_WINDOW
            kdDebug () << "\thave memberList" << endl;
        #endif

            for (QPtrList <KMainWindow>::const_iterator it = KMainWindow::memberList->begin ();
                 it != KMainWindow::memberList->end ();
                 it++)
            {
                kpMainWindow *mw = dynamic_cast <kpMainWindow *> (*it);

                if (!mw)
                {
                    kdError () << "kpMainWindow::slotPaste() given fake kpMainWindow: " << (*it) << endl;
                    continue;
                }
            #if DEBUG_KP_MAIN_WINDOW
                kdDebug () << "\t\tmw=" << mw << endl;
            #endif

                mw->slotEnablePaste ();
            }
        }

        return;
    }

    QApplication::restoreOverrideCursor ();
}