[WebKit-devel] KParts::TextExtension

David Faure faure at kde.org
Fri Sep 24 21:40:26 CEST 2010


I just committed a KParts::TextExtension, so that kparts plugins (babelfish, 
kttsplugin etc.) or web browsers themselves can get information such as:
bool hasSelection(), QString selectedText(Format format), QString 
completeText(Format format) and signal selectionChanged(),
in a web-browser-engine independent way.

The api is below for post-commit review :-)
Now is a good time to ask for more virtual methods in there.

The reason I'm posting this here, is to let other kpart authors know about it.
For instance if katepart provides this extension then babelfish and text-to-
speech would also work with it (e.g. in konqueror).

I'll commit http://www.davidfaure.fr/2010/kttsplugin.diff (kdebase) on Monday, 
it leads to a pretty nice cleanup of that code.

Question: when can I commit extragear/base/konq-plugins/babelfish, i.e. when 
can it depend on kdelibs trunk?

Question for webkit-devel: when can I commit the use of TextExtension to 
extragear/base/kwebkitpart? 
http://www.davidfaure.fr/2010/webkit_textextension.diff

===============

/**
 * @short an extension for KParts that allows to retrieve text from the part.
 *
 * For instance, the text-to-speech plugin uses this to speak the whole text
 * from the part or the selected text. The translation plugin uses it for
 * translating the selected text, and so on.
 *
 * @since 4.6
 */
class KPARTS_EXPORT TextExtension : public QObject
{
    Q_OBJECT
public:
    TextExtension(KParts::ReadOnlyPart* parent);
    ~TextExtension();

    /**
     * Queries @p obj for a child object which inherits from this
     * TextExtension class.
     */
    static TextExtension *childObject( QObject *obj );

    enum Format { PlainText, HTML };

    /**
     * Returns true if the user selected text in the part.
     */
    virtual bool hasSelection() const;
    /**
     * Returns the selected text, in the requested format.
     * If the format is not supported, the part must return an empty string.
     */
    virtual QString selectedText(Format format) const;
    /**
     * Returns the complete text shown in the part, in the requested format.
     * If the format is not supported, the part must return an empty string.
     */
    virtual QString completeText(Format format) const;

    // future extensions can be made via slots

Q_SIGNALS:
    /**
     * This signal is emitted when the selection changes.
     */
    void selectionChanged();

private:
    // for future extensions
    TextExtensionPrivate* const d;
};


-- 
David Faure, faure at kde.org, http://www.davidfaure.fr
Sponsored by Nokia to work on KDE, incl. Konqueror (http://www.konqueror.org).


More information about the WebKit-devel mailing list