diff --git a/kparts/browserextension.cpp b/kparts/browserextension.cpp index 675ed3e5..d5c6b585 100644 --- a/kparts/browserextension.cpp +++ b/kparts/browserextension.cpp @@ -41,34 +41,32 @@ using namespace KParts; class OpenUrlEvent::OpenUrlEventPrivate { public: - OpenUrlEventPrivate( ReadOnlyPart *part, - const KUrl &url, - const OpenUrlArguments &args, - const BrowserArguments &browserArgs ) - : m_part( part ) - , m_url( url ) - , m_args(args) - , m_browserArgs(browserArgs) - { - } - ~OpenUrlEventPrivate() - { - } - static const char *s_strOpenUrlEvent; - ReadOnlyPart *m_part; - KUrl m_url; - OpenUrlArguments m_args; - BrowserArguments m_browserArgs; + OpenUrlEventPrivate(ReadOnlyPart *part, + const KUrl &url, + const OpenUrlArguments &args, + const BrowserArguments &browserArgs) + : m_part(part) + , m_url(url) + , m_args(args) + , m_browserArgs(browserArgs) + { + } + + static const char *s_strOpenUrlEvent; + ReadOnlyPart *m_part; + KUrl m_url; + OpenUrlArguments m_args; + BrowserArguments m_browserArgs; }; const char *OpenUrlEvent::OpenUrlEventPrivate::s_strOpenUrlEvent = - "KParts/BrowserExtension/OpenURLevent"; + "KParts/BrowserExtension/OpenURLevent"; -OpenUrlEvent::OpenUrlEvent( ReadOnlyPart *part, const KUrl &url, - const OpenUrlArguments &args, - const BrowserArguments &browserArgs ) - : Event( OpenUrlEventPrivate::s_strOpenUrlEvent ) - , d( new OpenUrlEventPrivate(part, url, args, browserArgs) ) +OpenUrlEvent::OpenUrlEvent(ReadOnlyPart *part, const KUrl &url, + const OpenUrlArguments &args, + const BrowserArguments &browserArgs) + : Event(OpenUrlEventPrivate::s_strOpenUrlEvent ) + , d(new OpenUrlEventPrivate(part, url, args, browserArgs)) { } @@ -97,9 +95,9 @@ BrowserArguments OpenUrlEvent::browserArguments() const return d->m_browserArgs; } -bool OpenUrlEvent::test( const QEvent *event ) +bool OpenUrlEvent::test(const QEvent *event) { - return Event::test( event, OpenUrlEventPrivate::s_strOpenUrlEvent ); + return Event::test(event, OpenUrlEventPrivate::s_strOpenUrlEvent); } namespace KParts @@ -107,13 +105,15 @@ namespace KParts struct BrowserArgumentsPrivate { - BrowserArgumentsPrivate() { - doPost = false; - redirectedRequest = false; - lockHistory = false; - newTab = false; - forcesNewWindow = false; + BrowserArgumentsPrivate() + { + doPost = false; + redirectedRequest = false; + lockHistory = false; + newTab = false; + forcesNewWindow = false; } + QString contentType; // for POST bool doPost; bool redirectedRequest; @@ -126,69 +126,76 @@ struct BrowserArgumentsPrivate BrowserArguments::BrowserArguments() { - softReload = false; - trustedSource = false; - d = 0; // Let's build it on demand for now + softReload = false; + trustedSource = false; + d = 0; // Let's build it on demand for now } -BrowserArguments::BrowserArguments( const BrowserArguments &args ) +BrowserArguments::BrowserArguments(const BrowserArguments &args) { - d = 0; - (*this) = args; + d = 0; + (*this) = args; } BrowserArguments &BrowserArguments::operator=(const BrowserArguments &args) { - if (this == &args) return *this; + if (this == &args) { + return *this; + } - delete d; d= 0; + delete d; + d = nullptr; - softReload = args.softReload; - postData = args.postData; - frameName = args.frameName; - docState = args.docState; - trustedSource = args.trustedSource; + softReload = args.softReload; + postData = args.postData; + frameName = args.frameName; + docState = args.docState; + trustedSource = args.trustedSource; - if ( args.d ) - d = new BrowserArgumentsPrivate( * args.d ); + if (args.d) { + d = new BrowserArgumentsPrivate(*args.d); + } - return *this; + return *this; } BrowserArguments::~BrowserArguments() { - delete d; - d = 0; + delete d; + d = nullptr; } -void BrowserArguments::setContentType( const QString & contentType ) +void BrowserArguments::setContentType(const QString &contentType) { - if (!d) - d = new BrowserArgumentsPrivate; - d->contentType = contentType; + if (!d) { + d = new BrowserArgumentsPrivate(); + } + d->contentType = contentType; } -void BrowserArguments::setRedirectedRequest( bool redirected ) +void BrowserArguments::setRedirectedRequest(bool redirected) { - if (!d) - d = new BrowserArgumentsPrivate; - d->redirectedRequest = redirected; + if (!d) { + d = new BrowserArgumentsPrivate(); + } + d->redirectedRequest = redirected; } -bool BrowserArguments::redirectedRequest () const +bool BrowserArguments::redirectedRequest() const { - return d ? d->redirectedRequest : false; + return d ? d->redirectedRequest : false; } QString BrowserArguments::contentType() const { - return d ? d->contentType : QString(); + return d ? d->contentType : QString(); } -void BrowserArguments::setDoPost( bool enable ) +void BrowserArguments::setDoPost(bool enable) { - if ( !d ) - d = new BrowserArgumentsPrivate; + if (!d) { + d = new BrowserArgumentsPrivate(); + } d->doPost = enable; } @@ -197,11 +204,12 @@ bool BrowserArguments::doPost() const return d ? d->doPost : false; } -void BrowserArguments::setLockHistory( bool lock ) +void BrowserArguments::setLockHistory(bool lock) { - if (!d) - d = new BrowserArgumentsPrivate; - d->lockHistory = lock; + if (!d) { + d = new BrowserArgumentsPrivate(); + } + d->lockHistory = lock; } bool BrowserArguments::lockHistory() const @@ -209,11 +217,12 @@ bool BrowserArguments::lockHistory() const return d ? d->lockHistory : false; } -void BrowserArguments::setNewTab( bool newTab ) +void BrowserArguments::setNewTab(bool newTab) { - if (!d) - d = new BrowserArgumentsPrivate; - d->newTab = newTab; + if (!d) { + d = new BrowserArgumentsPrivate(); + } + d->newTab = newTab; } bool BrowserArguments::newTab() const @@ -221,11 +230,12 @@ bool BrowserArguments::newTab() const return d ? d->newTab : false; } -void BrowserArguments::setForcesNewWindow( bool forcesNewWindow ) +void BrowserArguments::setForcesNewWindow(bool forcesNewWindow) { - if (!d) - d = new BrowserArgumentsPrivate; - d->forcesNewWindow = forcesNewWindow; + if (!d) { + d = new BrowserArgumentsPrivate(); + } + d->forcesNewWindow = forcesNewWindow; } bool BrowserArguments::forcesNewWindow() const @@ -239,25 +249,26 @@ namespace KParts class BrowserExtension::BrowserExtensionPrivate { public: - BrowserExtensionPrivate( KParts::ReadOnlyPart *parent ) - : m_urlDropHandlingEnabled(false), - m_part( parent ) - {} + BrowserExtensionPrivate(KParts::ReadOnlyPart *parent) + : m_urlDropHandlingEnabled(false), + m_part(parent) + { + } - struct DelayedRequest { - KUrl m_delayedURL; - KParts::OpenUrlArguments m_delayedArgs; - KParts::BrowserArguments m_delayedBrowserArgs; - }; + struct DelayedRequest { + KUrl m_delayedURL; + KParts::OpenUrlArguments m_delayedArgs; + KParts::BrowserArguments m_delayedBrowserArgs; + }; - QList m_requests; - bool m_urlDropHandlingEnabled; - QBitArray m_actionStatus; - QMap m_actionText; + QList m_requests; + bool m_urlDropHandlingEnabled; + QBitArray m_actionStatus; + QMap m_actionText; - static void createActionSlotMap(); + static void createActionSlotMap(); - KParts::ReadOnlyPart *m_part; + KParts::ReadOnlyPart *m_part; OpenUrlArguments m_args; BrowserArguments m_browserArgs; }; @@ -267,10 +278,10 @@ K_GLOBAL_STATIC(BrowserExtension::ActionNumberMap, s_actionNumberMap) void BrowserExtension::BrowserExtensionPrivate::createActionSlotMap() { - s_actionSlotMap->insert( "cut", SLOT(cut()) ); - s_actionSlotMap->insert( "copy", SLOT(copy()) ); - s_actionSlotMap->insert( "paste", SLOT(paste()) ); - s_actionSlotMap->insert( "print", SLOT(print()) ); + s_actionSlotMap->insert("cut", SLOT(cut())); + s_actionSlotMap->insert("copy", SLOT(copy())); + s_actionSlotMap->insert("paste", SLOT(paste())); + s_actionSlotMap->insert("print", SLOT(print())); // Tricky. Those aren't actions in fact, but simply methods that a browserextension // can have or not. No need to return them here. //s_actionSlotMap->insert( "reparseConfiguration", SLOT(reparseConfiguration()) ); @@ -279,8 +290,7 @@ void BrowserExtension::BrowserExtensionPrivate::createActionSlotMap() // Create the action-number map ActionSlotMap::ConstIterator it = s_actionSlotMap->constBegin(); ActionSlotMap::ConstIterator itEnd = s_actionSlotMap->constEnd(); - for ( int i=0 ; it != itEnd ; ++it, ++i ) - { + for (int i = 0 ; it != itEnd ; ++it, ++i) { // kDebug() << " action " << it.key() << " number " << i; s_actionNumberMap->insert( it.key(), i ); } @@ -288,84 +298,94 @@ void BrowserExtension::BrowserExtensionPrivate::createActionSlotMap() } -BrowserExtension::BrowserExtension( KParts::ReadOnlyPart *parent ) -: QObject( parent ), d( new BrowserExtensionPrivate(parent) ) +BrowserExtension::BrowserExtension(KParts::ReadOnlyPart *parent) + : QObject(parent), + d(new BrowserExtensionPrivate(parent)) { - //kDebug() << "BrowserExtension::BrowserExtension() " << this; + // kDebug() << "BrowserExtension::BrowserExtension() " << this; - if (s_actionSlotMap->isEmpty()) - // Create the action-slot map - BrowserExtensionPrivate::createActionSlotMap(); + if (s_actionSlotMap->isEmpty()) { + // Create the action-slot map + BrowserExtensionPrivate::createActionSlotMap(); + } - // Build list with this extension's slot names. - QList slotNames; - int methodCount = metaObject()->methodCount(); - int methodOffset = metaObject()->methodOffset(); - for ( int i=0 ; i < methodCount; ++i ) - { - QMetaMethod method = metaObject()->method( methodOffset + i ); - if ( method.methodType() == QMetaMethod::Slot ) - slotNames.append( method.signature() ); - } + // Build list with this extension's slot names. + QList slotNames; + int methodCount = metaObject()->methodCount(); + int methodOffset = metaObject()->methodOffset(); + for (int i= 0; i < methodCount; ++i) { + QMetaMethod method = metaObject()->method(methodOffset + i); + if (method.methodType() == QMetaMethod::Slot) { + slotNames.append(method.signature()); + } + } - // Set the initial status of the actions depending on whether - // they're supported or not - ActionSlotMap::ConstIterator it = s_actionSlotMap->constBegin(); - ActionSlotMap::ConstIterator itEnd = s_actionSlotMap->constEnd(); - for ( int i=0 ; it != itEnd ; ++it, ++i ) - { - // Does the extension have a slot with the name of this action ? - // ######### KDE4 TODO: use QMetaObject::indexOfMethod() ####### - d->m_actionStatus.setBit( i, slotNames.contains( it.key()+"()" ) ); - } + // Set the initial status of the actions depending on whether + // they're supported or not + ActionSlotMap::ConstIterator it = s_actionSlotMap->constBegin(); + ActionSlotMap::ConstIterator itEnd = s_actionSlotMap->constEnd(); + for (int i = 0 ; it != itEnd ; ++it, ++i) { + // Does the extension have a slot with the name of this action ? + // ######### KDE4 TODO: use QMetaObject::indexOfMethod() ####### + d->m_actionStatus.setBit(i, slotNames.contains(it.key()+"()")); + } - connect( d->m_part, SIGNAL(completed()), - this, SLOT(slotCompleted()) ); - connect( this, SIGNAL(openUrlRequest(KUrl,KParts::OpenUrlArguments,KParts::BrowserArguments)), - this, SLOT(slotOpenUrlRequest(KUrl,KParts::OpenUrlArguments,KParts::BrowserArguments)) ); - connect( this, SIGNAL(enableAction(const char*,bool)), - this, SLOT(slotEnableAction(const char*,bool)) ); - connect( this, SIGNAL(setActionText(const char*,QString)), - this, SLOT(slotSetActionText(const char*,QString)) ); + connect( + d->m_part, SIGNAL(completed()), + this, SLOT(slotCompleted()) + ); + connect( + this, SIGNAL(openUrlRequest(KUrl,KParts::OpenUrlArguments,KParts::BrowserArguments)), + this, SLOT(slotOpenUrlRequest(KUrl,KParts::OpenUrlArguments,KParts::BrowserArguments)) + ); + connect( + this, SIGNAL(enableAction(const char*,bool)), + this, SLOT(slotEnableAction(const char*,bool)) + ); + connect( + this, SIGNAL(setActionText(const char*,QString)), + this, SLOT(slotSetActionText(const char*,QString)) + ); } BrowserExtension::~BrowserExtension() { - //kDebug() << "BrowserExtension::~BrowserExtension() " << this; - delete d; + // kDebug() << "BrowserExtension::~BrowserExtension() " << this; + delete d; } void BrowserExtension::setBrowserArguments( const BrowserArguments &args ) { - d->m_browserArgs = args; + d->m_browserArgs = args; } BrowserArguments BrowserExtension::browserArguments() const { - return d->m_browserArgs; + return d->m_browserArgs; } int BrowserExtension::xOffset() { - return 0; + return 0; } int BrowserExtension::yOffset() { - return 0; + return 0; } -void BrowserExtension::saveState( QDataStream &stream ) +void BrowserExtension::saveState(QDataStream &stream) { // TODO add d->m_part->mimeType() - stream << d->m_part->url() << (qint32)xOffset() << (qint32)yOffset(); + stream << d->m_part->url() << (qint32)xOffset() << (qint32)yOffset(); } void BrowserExtension::restoreState( QDataStream &stream ) { - KUrl u; - qint32 xOfs, yOfs; - stream >> u >> xOfs >> yOfs; + KUrl u; + qint32 xOfs = 0; + qint32 yOfs = 0; + stream >> u >> xOfs >> yOfs; OpenUrlArguments args; args.setXOffset(xOfs); @@ -380,20 +400,20 @@ bool BrowserExtension::isURLDropHandlingEnabled() const return d->m_urlDropHandlingEnabled; } -void BrowserExtension::setURLDropHandlingEnabled( bool enable ) +void BrowserExtension::setURLDropHandlingEnabled(bool enable) { d->m_urlDropHandlingEnabled = enable; } void BrowserExtension::slotCompleted() { - //empty the argument stuff, to avoid bogus/invalid values when opening a new url - setBrowserArguments( BrowserArguments() ); + // empty the argument stuff, to avoid bogus/invalid values when opening a new url + setBrowserArguments(BrowserArguments()); } void BrowserExtension::pasteRequest() { - QString plain( "plain" ); + QString plain("plain"); QString url = QApplication::clipboard()->text(plain, QClipboard::Selection).trimmed(); // Remove linefeeds and any whitespace surrounding it. url.remove(QRegExp("[\\ ]*\\n+[\\ ]*")); @@ -404,92 +424,94 @@ void BrowserExtension::pasteRequest() filters.removeAll( "localdomainurifilter" ); KUriFilterData filterData; filterData.setData( url ); - filterData.setCheckForExecutables( false ); - if ( KUriFilter::self()->filterUri( filterData, filters ) ) + filterData.setCheckForExecutables(false); + if (KUriFilter::self()->filterUri(filterData, filters)) { + switch (filterData.uriType()) { + case KUriFilterData::LocalFile: + case KUriFilterData::LocalDir: + case KUriFilterData::NetProtocol: { + slotOpenUrlRequest(filterData.uri()); + break; + } + case KUriFilterData::Error: { + KMessageBox::sorry( d->m_part->widget(), filterData.errorMsg()); + break; + } + default: { + break; + } + } + } else if (KUriFilter::self()->filterUri(filterData, QStringList(QLatin1String("kuriikwsfilter"))) && + url.length() < 250 ) { - switch ( filterData.uriType() ) - { - case KUriFilterData::LocalFile: - case KUriFilterData::LocalDir: - case KUriFilterData::NetProtocol: - slotOpenUrlRequest( filterData.uri() ); - break; - case KUriFilterData::Error: - KMessageBox::sorry( d->m_part->widget(), filterData.errorMsg() ); - break; - default: - break; - } - } - else if ( KUriFilter::self()->filterUri( filterData, - QStringList( QLatin1String( "kuriikwsfilter" ) ) ) && - url.length() < 250 ) - { - if ( KMessageBox::questionYesNo( d->m_part->widget(), - i18n( "Do you want to search the Internet for %1?" , Qt::escape(url) ), - i18n( "Internet Search" ), KGuiItem( i18n( "&Search" ), "edit-find"), - KStandardGuiItem::cancel(), "MiddleClickSearch" ) == KMessageBox::Yes) - slotOpenUrlRequest( filterData.uri() ); + if (KMessageBox::questionYesNo(d->m_part->widget(), + i18n("Do you want to search the Internet for %1?", Qt::escape(url)), + i18n("Internet Search"), KGuiItem( i18n( "&Search" ), "edit-find"), + KStandardGuiItem::cancel(), "MiddleClickSearch") == KMessageBox::Yes) + slotOpenUrlRequest(filterData.uri()); } } -void BrowserExtension::slotOpenUrlRequest( const KUrl &url, const KParts::OpenUrlArguments& args, const KParts::BrowserArguments &browserArgs ) +void BrowserExtension::slotOpenUrlRequest(const KUrl &url, + const KParts::OpenUrlArguments &args, + const KParts::BrowserArguments &browserArgs) { - //kDebug() << this << " BrowserExtension::slotOpenURLRequest(): url=" << url.url(); + // kDebug() << this << " BrowserExtension::slotOpenURLRequest(): url=" << url.url(); BrowserExtensionPrivate::DelayedRequest req; req.m_delayedURL = url; req.m_delayedArgs = args; req.m_delayedBrowserArgs = browserArgs; - d->m_requests.append( req ); - QTimer::singleShot( 0, this, SLOT(slotEmitOpenUrlRequestDelayed()) ); + d->m_requests.append(req); + QTimer::singleShot(0, this, SLOT(slotEmitOpenUrlRequestDelayed())); } void BrowserExtension::slotEmitOpenUrlRequestDelayed() { - if (d->m_requests.isEmpty()) return; + if (d->m_requests.isEmpty()) { + return; + } BrowserExtensionPrivate::DelayedRequest req = d->m_requests.front(); d->m_requests.pop_front(); - emit openUrlRequestDelayed( req.m_delayedURL, req.m_delayedArgs, req.m_delayedBrowserArgs ); + emit openUrlRequestDelayed(req.m_delayedURL, req.m_delayedArgs, req.m_delayedBrowserArgs); // tricky: do not do anything here! (no access to member variables, etc.) } -void BrowserExtension::slotEnableAction( const char * name, bool enabled ) +void BrowserExtension::slotEnableAction(const char *name, bool enabled) { //kDebug() << "BrowserExtension::slotEnableAction " << name << " " << enabled; - ActionNumberMap::ConstIterator it = s_actionNumberMap->constFind( name ); - if ( it != s_actionNumberMap->constEnd() ) - { + ActionNumberMap::ConstIterator it = s_actionNumberMap->constFind(name); + if (it != s_actionNumberMap->constEnd()) { d->m_actionStatus.setBit( it.value(), enabled ); //kDebug() << "BrowserExtension::slotEnableAction setting bit " << it.data() << " to " << enabled; - } - else + } else { kWarning() << "BrowserExtension::slotEnableAction unknown action " << name; + } } -bool BrowserExtension::isActionEnabled( const char * name ) const +bool BrowserExtension::isActionEnabled(const char *name) const { - int actionNumber = (*s_actionNumberMap)[ name ]; - return d->m_actionStatus[ actionNumber ]; + int actionNumber = (*s_actionNumberMap)[name]; + return d->m_actionStatus[actionNumber]; } -void BrowserExtension::slotSetActionText( const char * name, const QString& text ) +void BrowserExtension::slotSetActionText(const char *name, const QString &text) { //kDebug() << "BrowserExtension::slotSetActionText " << name << " " << text; - ActionNumberMap::ConstIterator it = s_actionNumberMap->constFind( name ); - if ( it != s_actionNumberMap->constEnd() ) - { - d->m_actionText[ it.value() ] = text; + ActionNumberMap::ConstIterator it = s_actionNumberMap->constFind(name); + if (it != s_actionNumberMap->constEnd()) { + d->m_actionText[it.value()] = text; + } else { + kWarning() << "BrowserExtension::slotSetActionText unknown action" << name; } - else - kWarning() << "BrowserExtension::slotSetActionText unknown action " << name; } -QString BrowserExtension::actionText( const char * name ) const +QString BrowserExtension::actionText(const char *name) const { int actionNumber = (*s_actionNumberMap)[ name ]; - QMap::ConstIterator it = d->m_actionText.constFind( actionNumber ); - if ( it != d->m_actionText.constEnd() ) + QMap::ConstIterator it = d->m_actionText.constFind(actionNumber); + if (it != d->m_actionText.constEnd()) { return *it; + } return QString(); } @@ -499,16 +521,17 @@ BrowserExtension::ActionSlotMap BrowserExtension::actionSlotMap() return *actionSlotMapPtr(); } -BrowserExtension::ActionSlotMap * BrowserExtension::actionSlotMapPtr() +BrowserExtension::ActionSlotMap* BrowserExtension::actionSlotMapPtr() { - if (s_actionSlotMap->isEmpty()) + if (s_actionSlotMap->isEmpty()) { BrowserExtensionPrivate::createActionSlotMap(); + } return s_actionSlotMap; } -BrowserExtension *BrowserExtension::childObject( QObject *obj ) +BrowserExtension *BrowserExtension::childObject(QObject *obj) { - return KGlobal::findDirectChild(obj); + return KGlobal::findDirectChild(obj); } #include "moc_browserextension.cpp" diff --git a/kparts/browserextension.h b/kparts/browserextension.h index 4b61e7d8..4029c23b 100644 --- a/kparts/browserextension.h +++ b/kparts/browserextension.h @@ -58,123 +58,119 @@ struct BrowserArgumentsPrivate; */ struct KPARTS_EXPORT BrowserArguments { - BrowserArguments(); - BrowserArguments( const BrowserArguments &args ); - BrowserArguments &operator=( const BrowserArguments &args); + BrowserArguments(); + BrowserArguments(const BrowserArguments &args); + BrowserArguments &operator=(const BrowserArguments &args); - virtual ~BrowserArguments(); + virtual ~BrowserArguments(); - // KDE4: a struct has the problem that the stuff added after BC-freeze uses methods - // so it looks inconsistent with the member vars. -> better use methods for everything, - // even if they are inline. + /** + * This buffer can be used by the part to save and restore its contents. + * See KWebKitPart for instance. + */ + QStringList docState; + /** + * @p softReload is set when user just hits reload button. It's used + * currently for two different frameset reload strategies. In case of + * soft reload individual frames are reloaded instead of reloading whole + * frameset. + */ + bool softReload; - /** - * This buffer can be used by the part to save and restore its contents. - * See KWebKitPart for instance. - */ - QStringList docState; + /** + * KHTML-specific field, contents of the HTTP POST data. + */ + QByteArray postData; - /** - * @p softReload is set when user just hits reload button. It's used - * currently for two different frameset reload strategies. In case of - * soft reload individual frames are reloaded instead of reloading whole - * frameset. - */ - bool softReload; + /** + * KHTML-specific field, header defining the type of the POST data. + */ + void setContentType(const QString &contentType); + /** + * KHTML-specific field, header defining the type of the POST data. + */ + QString contentType() const; - /** - * KHTML-specific field, contents of the HTTP POST data. - */ - QByteArray postData; + /** + * KHTML-specific field, whether to do a POST instead of a GET, + * for the next openURL. + */ + void setDoPost(bool enable); - /** - * KHTML-specific field, header defining the type of the POST data. - */ - void setContentType( const QString & contentType ); - /** - * KHTML-specific field, header defining the type of the POST data. - */ - QString contentType() const; - /** - * KHTML-specific field, whether to do a POST instead of a GET, - * for the next openURL. - */ - void setDoPost( bool enable ); + /** + * KHTML-specific field, whether to do a POST instead of a GET, + * for the next openURL. + */ + bool doPost() const; - /** - * KHTML-specific field, whether to do a POST instead of a GET, - * for the next openURL. - */ - bool doPost() const; + /** + * Whether to lock the history when opening the next URL. + * This is used during e.g. a redirection, to avoid a new entry + * in the history. + */ + void setLockHistory(bool lock); + bool lockHistory() const; - /** - * Whether to lock the history when opening the next URL. - * This is used during e.g. a redirection, to avoid a new entry - * in the history. - */ - void setLockHistory( bool lock ); - bool lockHistory() const; + /** + * Whether the URL should be opened in a new tab instead in a new window. + */ + void setNewTab(bool newTab); + bool newTab() const; - /** - * Whether the URL should be opened in a new tab instead in a new window. - */ - void setNewTab( bool newTab ); - bool newTab() const; + /** + * The frame in which to open the URL. KHTML/Konqueror-specific. + */ + QString frameName; - /** - * The frame in which to open the URL. KHTML/Konqueror-specific. - */ - QString frameName; + /** + * If true, the part who asks for a URL to be opened can be 'trusted' + * to execute applications. For instance, the directory views can be + * 'trusted' whereas HTML pages are not trusted in that respect. + */ + bool trustedSource; - /** - * If true, the part who asks for a URL to be opened can be 'trusted' - * to execute applications. For instance, the directory views can be - * 'trusted' whereas HTML pages are not trusted in that respect. - */ - bool trustedSource; + /** + * @return true if the request was a result of a META refresh/redirect request or + * HTTP redirect. + */ + bool redirectedRequest() const; - /** - * @return true if the request was a result of a META refresh/redirect request or - * HTTP redirect. - */ - bool redirectedRequest () const; + /** + * Set the redirect flag to indicate URL is a result of either a META redirect + * or HTTP redirect. + * + * @param redirected + */ + void setRedirectedRequest(bool redirected); - /** - * Set the redirect flag to indicate URL is a result of either a META redirect - * or HTTP redirect. - * - * @param redirected - */ - void setRedirectedRequest(bool redirected); + /** + * Set whether the URL specifies to be opened in a new window. + * + * When openUrlRequest is emitted: + *
    + *
  • normally the url would be opened in the current view.
  • + *
  • setForcesNewWindow(true) specifies that a new window or tab should be used: + * setNewTab(true) requests a tab specifically, otherwise the user-preference is followed. + * This is typically used for target="_blank" in web browsers.
  • + *
+ * + * When createNewWindow is emitted: + *
    + *
  • if setNewTab(true) was called, a tab is created.
  • + *
  • otherwise, if setForcesNewWindow(true) was called, a window is created.
  • + *
  • otherwise the user preference is followed.
  • + *
+ */ + void setForcesNewWindow(bool forcesNewWindow); - /** - * Set whether the URL specifies to be opened in a new window. - * - * When openUrlRequest is emitted: - *
    - *
  • normally the url would be opened in the current view.
  • - *
  • setForcesNewWindow(true) specifies that a new window or tab should be used: - * setNewTab(true) requests a tab specifically, otherwise the user-preference is followed. - * This is typically used for target="_blank" in web browsers.
  • - *
- * - * When createNewWindow is emitted: - *
    - *
  • if setNewTab(true) was called, a tab is created.
  • - *
  • otherwise, if setForcesNewWindow(true) was called, a window is created.
  • - *
  • otherwise the user preference is followed.
  • - *
- */ - void setForcesNewWindow( bool forcesNewWindow ); - - /** - * Whether the URL specifies to be opened in a new window - */ - bool forcesNewWindow() const; + /** + * Whether the URL specifies to be opened in a new window + */ + bool forcesNewWindow() const; private: - BrowserArgumentsPrivate *d; + BrowserArgumentsPrivate *d; }; /** @@ -187,21 +183,21 @@ private: class KPARTS_EXPORT OpenUrlEvent : public Event { public: - OpenUrlEvent( ReadOnlyPart *part, const KUrl &url, - const OpenUrlArguments& args = OpenUrlArguments(), - const BrowserArguments& browserArgs = BrowserArguments() ); - virtual ~OpenUrlEvent(); + OpenUrlEvent(ReadOnlyPart *part, const KUrl &url, + const OpenUrlArguments& args = OpenUrlArguments(), + const BrowserArguments& browserArgs = BrowserArguments()); + virtual ~OpenUrlEvent(); - ReadOnlyPart *part() const; - KUrl url() const; - OpenUrlArguments arguments() const; - BrowserArguments browserArguments() const; + ReadOnlyPart *part() const; + KUrl url() const; + OpenUrlArguments arguments() const; + BrowserArguments browserArguments() const; - static bool test( const QEvent *event ); + static bool test(const QEvent *event); private: - class OpenUrlEventPrivate; - OpenUrlEventPrivate * const d; + class OpenUrlEventPrivate; + OpenUrlEventPrivate * const d; }; /** @@ -257,167 +253,165 @@ private: */ class KPARTS_EXPORT BrowserExtension : public QObject { - Q_OBJECT - Q_PROPERTY( bool urlDropHandling READ isURLDropHandlingEnabled WRITE setURLDropHandlingEnabled ) + Q_OBJECT + Q_PROPERTY(bool urlDropHandling READ isURLDropHandlingEnabled WRITE setURLDropHandlingEnabled) public: - /** - * Constructor - * - * @param parent The KParts::ReadOnlyPart that this extension ... "extends" :) - */ - explicit BrowserExtension( KParts::ReadOnlyPart *parent ); + /** + * Constructor + * + * @param parent The KParts::ReadOnlyPart that this extension ... "extends" :) + */ + explicit BrowserExtension(KParts::ReadOnlyPart *parent); + virtual ~BrowserExtension(); - virtual ~BrowserExtension(); + /** + * Set of flags passed via the popupMenu signal, to ask for some items in the popup menu. + */ + enum PopupFlag { + DefaultPopupItems = 0x0000, /**< default value, no additional menu item */ + ShowNavigationItems = 0x0001, /**< show "back" and "forward" (usually done when clicking the background of the view, but not an item) */ + ShowUp = 0x0002, /**< show "up" (same thing, but not over e.g. HTTP). Requires ShowNavigationItems. */ + ShowReload = 0x0004, /**< show "reload" (usually done when clicking the background of the view, but not an item) */ + ShowBookmark = 0x0008, /**< show "add to bookmarks" (usually not done on the local filesystem) */ + ShowCreateDirectory = 0x0010, /**< show "create directory" (usually only done on the background of the view, or + * in hierarchical views like directory trees, where the new dir would be visible) */ + ShowTextSelectionItems=0x0020, /**< set when selecting text, for a popup that only contains text-related items. */ + NoDeletion=0x0040, /**< deletion, trashing and renaming not allowed (e.g. parent dir not writeable). + * (this is only needed if the protocol itself supports deletion, unlike e.g. HTTP) */ + IsLink = 0x0080, /**< show "Bookmark This Link" and other link-related actions (linkactions merging group) */ + ShowUrlOperations = 0x0100, /**< show copy, paste, as well as cut if NoDeletion is not set. */ + ShowProperties = 0x200 /**< show "Properties" action (usually done by directory views) */ + }; + Q_DECLARE_FLAGS(PopupFlags, PopupFlag) - /** - * Set of flags passed via the popupMenu signal, to ask for some items in the popup menu. - */ - enum PopupFlag { - DefaultPopupItems=0x0000, /**< default value, no additional menu item */ - ShowNavigationItems=0x0001, /**< show "back" and "forward" (usually done when clicking the background of the view, but not an item) */ - ShowUp=0x0002, /**< show "up" (same thing, but not over e.g. HTTP). Requires ShowNavigationItems. */ - ShowReload=0x0004, /**< show "reload" (usually done when clicking the background of the view, but not an item) */ - ShowBookmark=0x0008, /**< show "add to bookmarks" (usually not done on the local filesystem) */ - ShowCreateDirectory=0x0010, /**< show "create directory" (usually only done on the background of the view, or - * in hierarchical views like directory trees, where the new dir would be visible) */ - ShowTextSelectionItems=0x0020, /**< set when selecting text, for a popup that only contains text-related items. */ - NoDeletion=0x0040, /**< deletion, trashing and renaming not allowed (e.g. parent dir not writeable). - * (this is only needed if the protocol itself supports deletion, unlike e.g. HTTP) */ - IsLink=0x0080, /**< show "Bookmark This Link" and other link-related actions (linkactions merging group) */ - ShowUrlOperations=0x0100, /**< show copy, paste, as well as cut if NoDeletion is not set. */ - ShowProperties=0x200 /**< show "Properties" action (usually done by directory views) */ - }; + /** + * Set the parameters to use for opening the next URL. + * This is called by the "hosting" application, to pass parameters to the part. + * @see BrowserArguments + */ + virtual void setBrowserArguments(const BrowserArguments &args); - Q_DECLARE_FLAGS( PopupFlags, PopupFlag ) + /** + * Retrieve the set of parameters to use for opening the URL + * (this must be called from openUrl() in the part). + * @see BrowserArguments + */ + BrowserArguments browserArguments() const; - /** - * Set the parameters to use for opening the next URL. - * This is called by the "hosting" application, to pass parameters to the part. - * @see BrowserArguments - */ - virtual void setBrowserArguments( const BrowserArguments &args ); + /** + * Returns the current x offset. + * + * For a scrollview, implement this using contentsX(). + */ + virtual int xOffset(); + /** + * Returns the current y offset. + * + * For a scrollview, implement this using contentsY(). + */ + virtual int yOffset(); - /** - * Retrieve the set of parameters to use for opening the URL - * (this must be called from openUrl() in the part). - * @see BrowserArguments - */ - BrowserArguments browserArguments() const; + /** + * Used by the browser to save the current state of the view + * (in order to restore it if going back in navigation). + * + * If you want to save additional properties, reimplement it + * but don't forget to call the parent method (probably first). + */ + virtual void saveState(QDataStream &stream); - /** - * Returns the current x offset. - * - * For a scrollview, implement this using contentsX(). - */ - virtual int xOffset(); - /** - * Returns the current y offset. - * - * For a scrollview, implement this using contentsY(). - */ - virtual int yOffset(); + /** + * Used by the browser to restore the view in the state + * it was when we left it. + * + * If you saved additional properties, reimplement it + * but don't forget to call the parent method (probably first). + */ + virtual void restoreState(QDataStream &stream); - /** - * Used by the browser to save the current state of the view - * (in order to restore it if going back in navigation). - * - * If you want to save additional properties, reimplement it - * but don't forget to call the parent method (probably first). - */ - virtual void saveState( QDataStream &stream ); + /** + * Returns whether url drop handling is enabled. + * See setURLDropHandlingEnabled for more information about this + * property. + */ + bool isURLDropHandlingEnabled() const; - /** - * Used by the browser to restore the view in the state - * it was when we left it. - * - * If you saved additional properties, reimplement it - * but don't forget to call the parent method (probably first). - */ - virtual void restoreState( QDataStream &stream ); + /** + * Enables or disables url drop handling. URL drop handling is a property + * describing whether the hosting shell component is allowed to install an + * event filter on the part's widget, to listen for URI drop events. + * Set it to true if you are exporting a BrowserExtension implementation and + * do not provide any special URI drop handling. If set to false you can be + * sure to receive all those URI drop events unfiltered. Also note that the + * implementation as of Konqueror installs the event filter only on the part's + * widget itself, not on child widgets. + */ + void setURLDropHandlingEnabled(bool enable); - /** - * Returns whether url drop handling is enabled. - * See setURLDropHandlingEnabled for more information about this - * property. - */ - bool isURLDropHandlingEnabled() const; + /** + * @return the status (enabled/disabled) of an action. + * When the enableAction signal is emitted, the browserextension + * stores the status of the action internally, so that it's possible + * to query later for the status of the action, using this method. + */ + bool isActionEnabled(const char *name) const; - /** - * Enables or disables url drop handling. URL drop handling is a property - * describing whether the hosting shell component is allowed to install an - * event filter on the part's widget, to listen for URI drop events. - * Set it to true if you are exporting a BrowserExtension implementation and - * do not provide any special URI drop handling. If set to false you can be - * sure to receive all those URI drop events unfiltered. Also note that the - * implementation as of Konqueror installs the event filter only on the part's - * widget itself, not on child widgets. - */ - void setURLDropHandlingEnabled( bool enable ); + /** + * @return the text of an action, if it was set explicitly by the part. + * When the setActionText signal is emitted, the browserextension + * stores the text of the action internally, so that it's possible + * to query later for the text of the action, using this method. + */ + QString actionText(const char *name) const; - /** - * @return the status (enabled/disabled) of an action. - * When the enableAction signal is emitted, the browserextension - * stores the status of the action internally, so that it's possible - * to query later for the status of the action, using this method. - */ - bool isActionEnabled( const char * name ) const; + typedef QMap ActionSlotMap; + /** + * Returns a map containing the action names as keys and corresponding + * SLOT()'ified method names as data entries. + * + * This is very useful for + * the host component, when connecting the own signals with the + * extension's slots. + * Basically you iterate over the map, check if the extension implements + * the slot and connect to the slot using the data value of your map + * iterator. + * Checking if the extension implements a certain slot can be done like this: + * + * \code + * extension->metaObject()->slotNames().contains( actionName + "()" ) + * \endcode + * + * (note that @p actionName is the iterator's key value if already + * iterating over the action slot map, returned by this method) + * + * Connecting to the slot can be done like this: + * + * \code + * connect( yourObject, SIGNAL( yourSignal() ), + * extension, mapIterator.data() ) + * \endcode + * + * (where "mapIterator" is your QMap iterator) + */ + static ActionSlotMap actionSlotMap(); - /** - * @return the text of an action, if it was set explicitly by the part. - * When the setActionText signal is emitted, the browserextension - * stores the text of the action internally, so that it's possible - * to query later for the text of the action, using this method. - */ - QString actionText( const char * name ) const; + /** + * @return a pointer to the static action-slot map. Preferred method to get it. + * The map is created if it doesn't exist yet + */ + static ActionSlotMap* actionSlotMapPtr(); - typedef QMap ActionSlotMap; - /** - * Returns a map containing the action names as keys and corresponding - * SLOT()'ified method names as data entries. - * - * This is very useful for - * the host component, when connecting the own signals with the - * extension's slots. - * Basically you iterate over the map, check if the extension implements - * the slot and connect to the slot using the data value of your map - * iterator. - * Checking if the extension implements a certain slot can be done like this: - * - * \code - * extension->metaObject()->slotNames().contains( actionName + "()" ) - * \endcode - * - * (note that @p actionName is the iterator's key value if already - * iterating over the action slot map, returned by this method) - * - * Connecting to the slot can be done like this: - * - * \code - * connect( yourObject, SIGNAL( yourSignal() ), - * extension, mapIterator.data() ) - * \endcode - * - * (where "mapIterator" is your QMap iterator) - */ - static ActionSlotMap actionSlotMap(); + /** + * Queries @p obj for a child object which inherits from this + * BrowserExtension class. Convenience method. + */ + static BrowserExtension* childObject(QObject *obj); - /** - * @return a pointer to the static action-slot map. Preferred method to get it. - * The map is created if it doesn't exist yet - */ - static ActionSlotMap * actionSlotMapPtr(); - - /** - * Queries @p obj for a child object which inherits from this - * BrowserExtension class. Convenience method. - */ - static BrowserExtension *childObject( QObject *obj ); - - /** - * Asks the hosting browser to perform a paste (using openUrlRequestDelayed()) - */ - void pasteRequest(); + /** + * Asks the hosting browser to perform a paste (using openUrlRequestDelayed()) + */ + void pasteRequest(); /** * Associates a list of actions with a predefined name known by the host's popupmenu: @@ -425,222 +419,221 @@ public: * "linkactions" for actions related to hyperlinks, * "partactions" for any other actions provided by the part */ - typedef QMap > ActionGroupMap; + typedef QMap> ActionGroupMap; Q_SIGNALS: #if !defined(Q_MOC_RUN) && !defined(DOXYGEN_SHOULD_SKIP_THIS) public: // yes, those signals are public; don't tell moc or doxygen :) #endif - /** - * Enables or disable a standard action held by the browser. - * - * See class documentation for the list of standard actions. - */ - void enableAction( const char * name, bool enabled ); + /** + * Enables or disable a standard action held by the browser. + * + * See class documentation for the list of standard actions. + */ + void enableAction(const char *name, bool enabled); - /** - * Change the text of a standard action held by the browser. - * This can be used to change "Paste" into "Paste Image" for instance. - * - * See class documentation for the list of standard actions. - */ - void setActionText( const char * name, const QString& text ); + /** + * Change the text of a standard action held by the browser. + * This can be used to change "Paste" into "Paste Image" for instance. + * + * See class documentation for the list of standard actions. + */ + void setActionText(const char *name, const QString &text); - /** - * Asks the host (browser) to open @p url. - * To set a reload, the x and y offsets, the service type etc., fill in the - * appropriate fields in the @p args structure. - * Hosts should not connect to this signal but to openUrlRequestDelayed(). - */ - void openUrlRequest( const KUrl &url, - const KParts::OpenUrlArguments& arguments = KParts::OpenUrlArguments(), - const KParts::BrowserArguments &browserArguments = KParts::BrowserArguments() ); + /** + * Asks the host (browser) to open @p url. + * To set a reload, the x and y offsets, the service type etc., fill in the + * appropriate fields in the @p args structure. + * Hosts should not connect to this signal but to openUrlRequestDelayed(). + */ + void openUrlRequest(const KUrl &url, + const KParts::OpenUrlArguments& arguments = KParts::OpenUrlArguments(), + const KParts::BrowserArguments &browserArguments = KParts::BrowserArguments()); - /** - * This signal is emitted when openUrlRequest() is called, after a 0-seconds timer. - * This allows the caller to terminate what it's doing first, before (usually) - * being destroyed. Parts should never use this signal, hosts should only connect - * to this signal. - */ - void openUrlRequestDelayed( const KUrl &url, - const KParts::OpenUrlArguments& arguments, - const KParts::BrowserArguments &browserArguments ); + /** + * This signal is emitted when openUrlRequest() is called, after a 0-seconds timer. + * This allows the caller to terminate what it's doing first, before (usually) + * being destroyed. Parts should never use this signal, hosts should only connect + * to this signal. + */ + void openUrlRequestDelayed(const KUrl &url, + const KParts::OpenUrlArguments &arguments, + const KParts::BrowserArguments &browserArguments); - /** - * Tells the hosting browser that the part opened a new URL (which can be - * queried via KParts::Part::url(). - * - * This helps the browser to update/create an entry in the history. - * The part may @em not emit this signal together with openUrlRequest(). - * Emit openUrlRequest() if you want the browser to handle a URL the user - * asked to open (from within your part/document). This signal however is - * useful if you want to handle URLs all yourself internally, while still - * telling the hosting browser about new opened URLs, in order to provide - * a proper history functionality to the user. - * An example of usage is a html rendering component which wants to emit - * this signal when a child frame document changed its URL. - * Conclusion: you probably want to use openUrlRequest() instead. - */ - void openUrlNotify(); + /** + * Tells the hosting browser that the part opened a new URL (which can be + * queried via KParts::Part::url(). + * + * This helps the browser to update/create an entry in the history. + * The part may @em not emit this signal together with openUrlRequest(). + * Emit openUrlRequest() if you want the browser to handle a URL the user + * asked to open (from within your part/document). This signal however is + * useful if you want to handle URLs all yourself internally, while still + * telling the hosting browser about new opened URLs, in order to provide + * a proper history functionality to the user. + * An example of usage is a html rendering component which wants to emit + * this signal when a child frame document changed its URL. + * Conclusion: you probably want to use openUrlRequest() instead. + */ + void openUrlNotify(); - /** - * Updates the URL shown in the browser's location bar to @p url. - */ - void setLocationBarUrl( const QString &url ); + /** + * Updates the URL shown in the browser's location bar to @p url. + */ + void setLocationBarUrl(const QString &url); - /** - * Sets the URL of an icon for the currently displayed page. - */ - void setIconUrl( const KUrl &url ); + /** + * Sets the URL of an icon for the currently displayed page. + */ + void setIconUrl(const KUrl &url); - /** - * Asks the hosting browser to open a new window for the given @p url - * and return a reference to the content part. - * - * @p arguments is optional additional information about how to open the url, - * @see KParts::OpenUrlArguments - * - * @p browserArguments is optional additional information for web browsers, - * @see KParts::BrowserArguments - * - * The request for a pointer to the part is only fulfilled/processed - * if the mimeType is set in the @p browserArguments. - * (otherwise the request cannot be processed synchronously). - */ - void createNewWindow( const KUrl &url, - const KParts::OpenUrlArguments& arguments = KParts::OpenUrlArguments(), - const KParts::BrowserArguments &browserArguments = KParts::BrowserArguments(), - KParts::ReadOnlyPart** part = 0 ); + /** + * Asks the hosting browser to open a new window for the given @p url + * and return a reference to the content part. + * + * @p arguments is optional additional information about how to open the url, + * @see KParts::OpenUrlArguments + * + * @p browserArguments is optional additional information for web browsers, + * @see KParts::BrowserArguments + * + * The request for a pointer to the part is only fulfilled/processed + * if the mimeType is set in the @p browserArguments. + * (otherwise the request cannot be processed synchronously). + */ + void createNewWindow(const KUrl &url, + const KParts::OpenUrlArguments &arguments = KParts::OpenUrlArguments(), + const KParts::BrowserArguments &browserArguments = KParts::BrowserArguments(), + KParts::ReadOnlyPart** part = nullptr); - /** - * Since the part emits the jobid in the started() signal, - * progress information is automatically displayed. - * - * However, if you don't use a KIO::Job in the part, - * you can use loadingProgress() and speedProgress() - * to display progress information. - */ - void loadingProgress( int percent ); - /** - * @see loadingProgress - */ - void speedProgress( int bytesPerSecond ); + /** + * Since the part emits the jobid in the started() signal, + * progress information is automatically displayed. + * + * However, if you don't use a KIO::Job in the part, + * you can use loadingProgress() and speedProgress() + * to display progress information. + */ + void loadingProgress(int percent); + /** + * @see loadingProgress + */ + void speedProgress(int bytesPerSecond); - void infoMessage( const QString & ); + void infoMessage(const QString &); - /** - * Emit this to make the browser show a standard popup menu for the files @p items. - * - * @param global global coordinates where the popup should be shown - * @param items list of file items which the popup applies to - * @param args OpenUrlArguments, mostly for metadata here - * @param browserArguments BrowserArguments, mostly for referrer - * @param flags enables/disables certain builtin actions in the popupmenu - * @param actionGroups named groups of actions which should be inserted into the popup, see ActionGroupMap - */ - void popupMenu( const QPoint &global, const KFileItemList &items, - const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(), - const KParts::BrowserArguments &browserArgs = KParts::BrowserArguments(), - KParts::BrowserExtension::PopupFlags flags = KParts::BrowserExtension::DefaultPopupItems, - const KParts::BrowserExtension::ActionGroupMap& actionGroups = ActionGroupMap() ); + /** + * Emit this to make the browser show a standard popup menu for the files @p items. + * + * @param global global coordinates where the popup should be shown + * @param items list of file items which the popup applies to + * @param args OpenUrlArguments, mostly for metadata here + * @param browserArguments BrowserArguments, mostly for referrer + * @param flags enables/disables certain builtin actions in the popupmenu + * @param actionGroups named groups of actions which should be inserted into the popup, see ActionGroupMap + */ + void popupMenu(const QPoint &global, const KFileItemList &items, + const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(), + const KParts::BrowserArguments &browserArgs = KParts::BrowserArguments(), + KParts::BrowserExtension::PopupFlags flags = KParts::BrowserExtension::DefaultPopupItems, + const KParts::BrowserExtension::ActionGroupMap &actionGroups = ActionGroupMap()); - /** - * Emit this to make the browser show a standard popup menu for the given @p url. - * - * Give as much information about this URL as possible, - * like @p args.mimeType and the file type @p mode - * - * @param global global coordinates where the popup should be shown - * @param url the URL this popup applies to - * @param mode the file type of the url (S_IFREG, S_IFDIR...) - * @param args OpenUrlArguments, set the mimetype of the URL using setMimeType() - * @param browserArguments BrowserArguments, mostly for referrer - * @param flags enables/disables certain builtin actions in the popupmenu - * @param actionGroups named groups of actions which should be inserted into the popup, see ActionGroupMap - */ - void popupMenu( const QPoint &global, const KUrl &url, - mode_t mode = static_cast(-1), - const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(), - const KParts::BrowserArguments &browserArgs = KParts::BrowserArguments(), - KParts::BrowserExtension::PopupFlags flags = KParts::BrowserExtension::DefaultPopupItems, - const KParts::BrowserExtension::ActionGroupMap& actionGroups = ActionGroupMap() ); + /** + * Emit this to make the browser show a standard popup menu for the given @p url. + * + * Give as much information about this URL as possible, + * like @p args.mimeType and the file type @p mode + * + * @param global global coordinates where the popup should be shown + * @param url the URL this popup applies to + * @param mode the file type of the url (S_IFREG, S_IFDIR...) + * @param args OpenUrlArguments, set the mimetype of the URL using setMimeType() + * @param browserArguments BrowserArguments, mostly for referrer + * @param flags enables/disables certain builtin actions in the popupmenu + * @param actionGroups named groups of actions which should be inserted into the popup, see ActionGroupMap + */ + void popupMenu(const QPoint &global, const KUrl &url, + mode_t mode = static_cast(-1), + const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(), + const KParts::BrowserArguments &browserArgs = KParts::BrowserArguments(), + KParts::BrowserExtension::PopupFlags flags = KParts::BrowserExtension::DefaultPopupItems, + const KParts::BrowserExtension::ActionGroupMap& actionGroups = ActionGroupMap()); - /** - * Inform the hosting application about the current selection. - * Used when a set of files/URLs is selected (with full information - * about those URLs, including size, permissions etc.) - */ - void selectionInfo( const KFileItemList& items ); - /** - * Inform the hosting application about the current selection. - * Used when some text is selected. - */ - void selectionInfo( const QString &text ); - /** - * Inform the hosting application about the current selection. - * Used when a set of URLs is selected. - */ - void selectionInfo( const KUrl::List &urls ); + /** + * Inform the hosting application about the current selection. + * Used when a set of files/URLs is selected (with full information + * about those URLs, including size, permissions etc.) + */ + void selectionInfo(const KFileItemList &items); + /** + * Inform the hosting application about the current selection. + * Used when some text is selected. + */ + void selectionInfo( const QString &text ); + /** + * Inform the hosting application about the current selection. + * Used when a set of URLs is selected. + */ + void selectionInfo( const KUrl::List &urls ); - /** - * Inform the hosting application that the user moved the mouse over an item. - * Used when the mouse is on an URL. - */ - void mouseOverInfo( const KFileItem& item ); + /** + * Inform the hosting application that the user moved the mouse over an item. + * Used when the mouse is on an URL. + */ + void mouseOverInfo(const KFileItem &item); - /** - * Ask the hosting application to add a new HTML (aka Mozilla/Netscape) - * SideBar entry. - */ - void addWebSideBar(const KUrl &url, const QString& name); + /** + * Ask the hosting application to add a new HTML (aka Mozilla/Netscape) + * SideBar entry. + */ + void addWebSideBar(const KUrl &url, const QString &name); - /** - * Ask the hosting application to move the top level widget. - */ - void moveTopLevelWidget( int x, int y ); + /** + * Ask the hosting application to move the top level widget. + */ + void moveTopLevelWidget(int x, int y); - /** - * Ask the hosting application to resize the top level widget. - */ - void resizeTopLevelWidget( int w, int h ); + /** + * Ask the hosting application to resize the top level widget. + */ + void resizeTopLevelWidget(int w, int h); - /** - * Ask the hosting application to focus @p part. - */ - void requestFocus(KParts::ReadOnlyPart *part); + /** + * Ask the hosting application to focus @p part. + */ + void requestFocus(KParts::ReadOnlyPart *part); - /** - * Tell the host (browser) about security state of current page - * enum PageSecurity { NotCrypted, Encrypted, Mixed }; - */ - void setPageSecurity( int ); + /** + * Tell the host (browser) about security state of current page + * enum PageSecurity { NotCrypted, Encrypted, Mixed }; + */ + void setPageSecurity(int); - /** - * Inform the host about items that have been removed. - */ - void itemsRemoved( const KFileItemList &items ); + /** + * Inform the host about items that have been removed. + */ + void itemsRemoved(const KFileItemList &items); private Q_SLOTS: - void slotCompleted(); - void slotOpenUrlRequest( const KUrl &url, - const KParts::OpenUrlArguments& arguments = KParts::OpenUrlArguments(), - const KParts::BrowserArguments &browserArguments = KParts::BrowserArguments() ); + void slotCompleted(); + void slotOpenUrlRequest(const KUrl &url, + const KParts::OpenUrlArguments &arguments = KParts::OpenUrlArguments(), + const KParts::BrowserArguments &browserArguments = KParts::BrowserArguments()); - void slotEmitOpenUrlRequestDelayed(); - void slotEnableAction( const char *, bool ); - void slotSetActionText( const char*, const QString& ); + void slotEmitOpenUrlRequestDelayed(); + void slotEnableAction(const char *, bool); + void slotSetActionText(const char*, const QString&); public: - typedef QMap ActionNumberMap; + typedef QMap ActionNumberMap; private: - class BrowserExtensionPrivate; - BrowserExtensionPrivate * const d; + class BrowserExtensionPrivate; + BrowserExtensionPrivate * const d; }; } -Q_DECLARE_OPERATORS_FOR_FLAGS( KParts::BrowserExtension::PopupFlags ) +Q_DECLARE_OPERATORS_FOR_FLAGS(KParts::BrowserExtension::PopupFlags) #endif - diff --git a/kparts/event.cpp b/kparts/event.cpp index 233af17a..95c7155a 100644 --- a/kparts/event.cpp +++ b/kparts/event.cpp @@ -27,16 +27,17 @@ using namespace KParts; class KParts::EventPrivate { public: - EventPrivate( const char *eventName ) : - m_eventName(eventName) + EventPrivate(const char *eventName) + : m_eventName(eventName) { } + const char* m_eventName; }; -Event::Event( const char *eventName ) - : QEvent( (QEvent::Type)(QEvent::User + KPARTS_EVENT_MAGIC) ) - , d( new EventPrivate(eventName) ) +Event::Event(const char *eventName) + : QEvent((QEvent::Type)(QEvent::User + KPARTS_EVENT_MAGIC)) + , d(new EventPrivate(eventName)) { } @@ -47,33 +48,32 @@ Event::~Event() const char *Event::eventName() const { - return d->m_eventName; + return d->m_eventName; } -bool Event::test( const QEvent *event ) +bool Event::test(const QEvent *event) { - if ( !event ) - return false; - - return ( event->type() == (QEvent::Type)(QEvent::User + KPARTS_EVENT_MAGIC ) ); + if (!event) { + return false; + } + return (event->type() == (QEvent::Type)(QEvent::User + KPARTS_EVENT_MAGIC)); } -bool Event::test( const QEvent *event, const char *name ) +bool Event::test(const QEvent *event, const char *name) { - if ( !test( event ) ) - return false; - - return ( strcmp( name, ((Event*)event)->eventName() ) == 0 ); + if (!test(event)) { + return false; + } + return (qstrcmp(name, ((Event*)event)->eventName()) == 0); } /////// GUIActivateEvent //////// - class KParts::GUIActivateEventPrivate { public: - GUIActivateEventPrivate( bool activated ) - : m_bActivated( activated ) + GUIActivateEventPrivate(bool activated) + : m_bActivated(activated) { } static const char *s_strGUIActivateEvent; @@ -82,9 +82,9 @@ public: const char *GUIActivateEventPrivate::s_strGUIActivateEvent = "KParts/GUIActivate"; -GUIActivateEvent::GUIActivateEvent( bool activated ) : - Event( GUIActivateEventPrivate::s_strGUIActivateEvent ), - d( new GUIActivateEventPrivate(activated) ) +GUIActivateEvent::GUIActivateEvent(bool activated) + : Event(GUIActivateEventPrivate::s_strGUIActivateEvent), + d(new GUIActivateEventPrivate(activated)) { } @@ -98,8 +98,7 @@ bool GUIActivateEvent::activated() const return d->m_bActivated; } -bool GUIActivateEvent::test( const QEvent *event ) +bool GUIActivateEvent::test(const QEvent *event) { - return Event::test( event, GUIActivateEventPrivate::s_strGUIActivateEvent ); + return Event::test(event, GUIActivateEventPrivate::s_strGUIActivateEvent); } - diff --git a/kparts/event.h b/kparts/event.h index 749a1e03..7e0899ce 100644 --- a/kparts/event.h +++ b/kparts/event.h @@ -37,15 +37,15 @@ class EventPrivate; class KPARTS_EXPORT Event : public QEvent { public: - Event( const char *eventName ); - ~Event(); - const char *eventName() const; + Event(const char *eventName); + ~Event(); + const char *eventName() const; - static bool test( const QEvent *event ); - static bool test( const QEvent *event, const char *name ); + static bool test(const QEvent *event); + static bool test(const QEvent *event, const char *name); private: - EventPrivate * const d; + EventPrivate * const d; }; class GUIActivateEventPrivate; @@ -58,15 +58,15 @@ class GUIActivateEventPrivate; class KPARTS_EXPORT GUIActivateEvent : public Event { public: - GUIActivateEvent( bool activated ); - ~GUIActivateEvent(); + GUIActivateEvent(bool activated); + ~GUIActivateEvent(); - bool activated() const; + bool activated() const; - static bool test( const QEvent *event ); + static bool test(const QEvent *event); private: - GUIActivateEventPrivate * const d; + GUIActivateEventPrivate * const d; }; } // namespace diff --git a/kparts/factory.cpp b/kparts/factory.cpp index 753bdf1a..3e0f392f 100644 --- a/kparts/factory.cpp +++ b/kparts/factory.cpp @@ -28,12 +28,10 @@ #include #include -#include - using namespace KParts; -Factory::Factory( QObject *parent ) -: KPluginFactory( 0, 0, parent ) +Factory::Factory(QObject *parent) + : KPluginFactory(0, 0, parent) { } @@ -41,11 +39,12 @@ Factory::~Factory() { } -Part *Factory::createPart( QWidget *parentWidget, QObject *parent, const char *classname, const QStringList &args ) +Part *Factory::createPart(QWidget *parentWidget, QObject *parent, const char *classname, const QStringList &args) { - Part* part = createPartObject( parentWidget, parent, classname, args ); - if ( part ) - emit objectCreated( part ); + Part* part = createPartObject(parentWidget, parent, classname, args); + if (part) { + emit objectCreated(part); + } return part; } @@ -54,28 +53,29 @@ KComponentData Factory::partComponentData() return KComponentData(); } -KComponentData Factory::partComponentDataFromLibrary( const QString &libraryName ) +KComponentData Factory::partComponentDataFromLibrary(const QString &libraryName) { - KPluginLoader loader( libraryName ); - + KPluginLoader loader(libraryName); KPluginFactory *factory = loader.factory(); - if ( !factory ) + if (!factory) { return KComponentData(); - KParts::Factory *pfactory = qobject_cast( factory ); - if ( !pfactory ) + } + KParts::Factory *pfactory = qobject_cast(factory); + if (!pfactory) { return KComponentData(); + } return pfactory->partComponentData(); } -Part *Factory::createPartObject( QWidget *, QObject *, const char *, const QStringList & ) +Part *Factory::createPartObject(QWidget *, QObject *, const char *, const QStringList &) { - return 0; + return nullptr; } -QObject *Factory::createObject( QObject *parent, const char *classname, const QStringList &args ) +QObject *Factory::createObject(QObject *parent, const char *classname, const QStringList &args) { - assert( !parent || parent->isWidgetType() ); - return createPart( static_cast( parent ), parent, classname, args ); + Q_ASSERT(!parent || parent->isWidgetType()); + return createPart(static_cast(parent), parent, classname, args); } #include "moc_factory.cpp" diff --git a/kparts/factory.h b/kparts/factory.h index ce203395..02d1f7c8 100644 --- a/kparts/factory.h +++ b/kparts/factory.h @@ -40,10 +40,10 @@ class Part; */ class KPARTS_EXPORT Factory : public KPluginFactory { - Q_OBJECT + Q_OBJECT public: - Factory( QObject *parent = 0 ); - virtual ~Factory(); + Factory(QObject *parent = nullptr); + virtual ~Factory(); /** * Creates a part. @@ -72,7 +72,8 @@ public: * important for reference counting, and allows unloading the * library automatically once all its objects have been destroyed. */ - Part *createPart( QWidget *parentWidget = 0, QObject *parent = 0, const char *classname = "KParts::Part", const QStringList &args = QStringList() ); + Part* createPart(QWidget *parentWidget = nullptr, QObject *parent = nullptr, + const char *classname = "KParts::Part", const QStringList &args = QStringList()); /** * If you have a part contained in a shared library you might want to query @@ -92,7 +93,6 @@ public: static KComponentData partComponentDataFromLibrary(const QString &libraryName); protected: - /** * Reimplement this method in your implementation to create the Part. * @@ -115,19 +115,16 @@ protected: * * @returns the newly created part. */ - virtual Part *createPartObject( QWidget *parentWidget = 0, QObject *parent = 0, const char *classname = "KParts::Part", const QStringList &args = QStringList() ) = 0; + virtual Part* createPartObject(QWidget *parentWidget = nullptr, QObject *parent = nullptr, + const char *classname = "KParts::Part", const QStringList &args = QStringList()) = 0; /** * Reimplemented from KPluginFactory. Calls createPart() */ - virtual QObject *createObject( QObject *parent = 0, const char *classname = "QObject", const QStringList &args = QStringList() ); - + virtual QObject* createObject(QObject *parent = nullptr, + const char *classname = "QObject", const QStringList &args = QStringList()); }; } -/* - * vim: et sw=4 - */ - #endif diff --git a/kparts/mainwindow.cpp b/kparts/mainwindow.cpp index cdb7116d..90fa9da2 100644 --- a/kparts/mainwindow.cpp +++ b/kparts/mainwindow.cpp @@ -42,12 +42,9 @@ class MainWindowPrivate { public: MainWindowPrivate() - : m_activePart(0), - m_bShellGUIActivated(false), - m_helpMenu(0) - { - } - ~MainWindowPrivate() + : m_activePart(nullptr), + m_bShellGUIActivated(false), + m_helpMenu(nullptr) { } @@ -57,18 +54,19 @@ public: }; } -MainWindow::MainWindow( QWidget* parent, Qt::WindowFlags f ) - : KXmlGuiWindow( parent, f ), d(new MainWindowPrivate()) +MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags f) + : KXmlGuiWindow(parent, f), + d(new MainWindowPrivate()) { } MainWindow::~MainWindow() { - delete d; + delete d; } -void MainWindow::createGUI( Part * part ) +void MainWindow::createGUI(Part *part) { #if 0 kDebug() << "part=" << part @@ -77,9 +75,9 @@ void MainWindow::createGUI( Part * part ) #endif KXMLGUIFactory *factory = guiFactory(); - assert( factory ); + assert(factory); - if ( d->m_activePart ) + if (d->m_activePart) { #if 0 kDebug() << "deactivating GUI for" << d->m_activePart diff --git a/kparts/mainwindow.h b/kparts/mainwindow.h index e4f9d7ce..5fa6f366 100644 --- a/kparts/mainwindow.h +++ b/kparts/mainwindow.h @@ -43,47 +43,46 @@ class MainWindowPrivate; */ class KPARTS_EXPORT MainWindow : public KXmlGuiWindow, virtual public PartBase { - Q_OBJECT - public: - /** - * Constructor, same signature as KMainWindow. - */ - explicit MainWindow( QWidget* parent = 0, Qt::WindowFlags f = 0 ); - /** - * Destructor. - */ - virtual ~MainWindow(); + Q_OBJECT +public: + /** + * Constructor, same signature as KMainWindow. + */ + explicit MainWindow(QWidget *parent = nullptr, Qt::WindowFlags f = 0); + /** + * Destructor. + */ + virtual ~MainWindow(); protected Q_SLOTS: + /** + * Create the GUI (by merging the host's and the active part's) + * You _must_ call this in order to see any GUI being created. + * + * @param part The active part (set to 0L if no part). + */ + void createGUI(KParts::Part *part); - /** - * Create the GUI (by merging the host's and the active part's) - * You _must_ call this in order to see any GUI being created. - * - * @param part The active part (set to 0L if no part). - */ - void createGUI( KParts::Part * part ); + /** + * Called when the active part wants to change the statusbar message + * Reimplement if your mainwindow has a complex statusbar + * (with several items) + */ + virtual void slotSetStatusBarText( const QString & ); - /** - * Called when the active part wants to change the statusbar message - * Reimplement if your mainwindow has a complex statusbar - * (with several items) - */ - virtual void slotSetStatusBarText( const QString & ); - - /** - * Rebuilds the GUI after KEditToolbar changed the toolbar layout. - * @see configureToolbars() - * KDE4: make this virtual. (For now we rely on the fact that it's called - * as a slot, so the metaobject finds it here). - */ - void saveNewToolbarConfig(); + /** + * Rebuilds the GUI after KEditToolbar changed the toolbar layout. + * @see configureToolbars() + * KDE4: make this virtual. (For now we rely on the fact that it's called + * as a slot, so the metaobject finds it here). + */ + void saveNewToolbarConfig(); protected: - virtual void createShellGUI( bool create = true ); + virtual void createShellGUI(bool create = true); private: - MainWindowPrivate* const d; + MainWindowPrivate* const d; }; }