kparts: format and indent

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-08-31 01:59:18 +03:00
parent f8f34a1825
commit f43675b01d
8 changed files with 759 additions and 750 deletions

View file

@ -41,34 +41,32 @@ using namespace KParts;
class OpenUrlEvent::OpenUrlEventPrivate class OpenUrlEvent::OpenUrlEventPrivate
{ {
public: public:
OpenUrlEventPrivate( ReadOnlyPart *part, OpenUrlEventPrivate(ReadOnlyPart *part,
const KUrl &url, const KUrl &url,
const OpenUrlArguments &args, const OpenUrlArguments &args,
const BrowserArguments &browserArgs ) const BrowserArguments &browserArgs)
: m_part( part ) : m_part(part)
, m_url( url ) , m_url(url)
, m_args(args) , m_args(args)
, m_browserArgs(browserArgs) , m_browserArgs(browserArgs)
{ {
} }
~OpenUrlEventPrivate()
{ static const char *s_strOpenUrlEvent;
} ReadOnlyPart *m_part;
static const char *s_strOpenUrlEvent; KUrl m_url;
ReadOnlyPart *m_part; OpenUrlArguments m_args;
KUrl m_url; BrowserArguments m_browserArgs;
OpenUrlArguments m_args;
BrowserArguments m_browserArgs;
}; };
const char *OpenUrlEvent::OpenUrlEventPrivate::s_strOpenUrlEvent = const char *OpenUrlEvent::OpenUrlEventPrivate::s_strOpenUrlEvent =
"KParts/BrowserExtension/OpenURLevent"; "KParts/BrowserExtension/OpenURLevent";
OpenUrlEvent::OpenUrlEvent( ReadOnlyPart *part, const KUrl &url, OpenUrlEvent::OpenUrlEvent(ReadOnlyPart *part, const KUrl &url,
const OpenUrlArguments &args, const OpenUrlArguments &args,
const BrowserArguments &browserArgs ) const BrowserArguments &browserArgs)
: Event( OpenUrlEventPrivate::s_strOpenUrlEvent ) : Event(OpenUrlEventPrivate::s_strOpenUrlEvent )
, d( new OpenUrlEventPrivate(part, url, args, browserArgs) ) , d(new OpenUrlEventPrivate(part, url, args, browserArgs))
{ {
} }
@ -97,9 +95,9 @@ BrowserArguments OpenUrlEvent::browserArguments() const
return d->m_browserArgs; 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 namespace KParts
@ -107,13 +105,15 @@ namespace KParts
struct BrowserArgumentsPrivate struct BrowserArgumentsPrivate
{ {
BrowserArgumentsPrivate() { BrowserArgumentsPrivate()
doPost = false; {
redirectedRequest = false; doPost = false;
lockHistory = false; redirectedRequest = false;
newTab = false; lockHistory = false;
forcesNewWindow = false; newTab = false;
forcesNewWindow = false;
} }
QString contentType; // for POST QString contentType; // for POST
bool doPost; bool doPost;
bool redirectedRequest; bool redirectedRequest;
@ -126,69 +126,76 @@ struct BrowserArgumentsPrivate
BrowserArguments::BrowserArguments() BrowserArguments::BrowserArguments()
{ {
softReload = false; softReload = false;
trustedSource = false; trustedSource = false;
d = 0; // Let's build it on demand for now d = 0; // Let's build it on demand for now
} }
BrowserArguments::BrowserArguments( const BrowserArguments &args ) BrowserArguments::BrowserArguments(const BrowserArguments &args)
{ {
d = 0; d = 0;
(*this) = args; (*this) = args;
} }
BrowserArguments &BrowserArguments::operator=(const BrowserArguments &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; softReload = args.softReload;
postData = args.postData; postData = args.postData;
frameName = args.frameName; frameName = args.frameName;
docState = args.docState; docState = args.docState;
trustedSource = args.trustedSource; trustedSource = args.trustedSource;
if ( args.d ) if (args.d) {
d = new BrowserArgumentsPrivate( * args.d ); d = new BrowserArgumentsPrivate(*args.d);
}
return *this; return *this;
} }
BrowserArguments::~BrowserArguments() BrowserArguments::~BrowserArguments()
{ {
delete d; delete d;
d = 0; d = nullptr;
} }
void BrowserArguments::setContentType( const QString & contentType ) void BrowserArguments::setContentType(const QString &contentType)
{ {
if (!d) if (!d) {
d = new BrowserArgumentsPrivate; d = new BrowserArgumentsPrivate();
d->contentType = contentType; }
d->contentType = contentType;
} }
void BrowserArguments::setRedirectedRequest( bool redirected ) void BrowserArguments::setRedirectedRequest(bool redirected)
{ {
if (!d) if (!d) {
d = new BrowserArgumentsPrivate; d = new BrowserArgumentsPrivate();
d->redirectedRequest = redirected; }
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 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 ) if (!d) {
d = new BrowserArgumentsPrivate; d = new BrowserArgumentsPrivate();
}
d->doPost = enable; d->doPost = enable;
} }
@ -197,11 +204,12 @@ bool BrowserArguments::doPost() const
return d ? d->doPost : false; return d ? d->doPost : false;
} }
void BrowserArguments::setLockHistory( bool lock ) void BrowserArguments::setLockHistory(bool lock)
{ {
if (!d) if (!d) {
d = new BrowserArgumentsPrivate; d = new BrowserArgumentsPrivate();
d->lockHistory = lock; }
d->lockHistory = lock;
} }
bool BrowserArguments::lockHistory() const bool BrowserArguments::lockHistory() const
@ -209,11 +217,12 @@ bool BrowserArguments::lockHistory() const
return d ? d->lockHistory : false; return d ? d->lockHistory : false;
} }
void BrowserArguments::setNewTab( bool newTab ) void BrowserArguments::setNewTab(bool newTab)
{ {
if (!d) if (!d) {
d = new BrowserArgumentsPrivate; d = new BrowserArgumentsPrivate();
d->newTab = newTab; }
d->newTab = newTab;
} }
bool BrowserArguments::newTab() const bool BrowserArguments::newTab() const
@ -221,11 +230,12 @@ bool BrowserArguments::newTab() const
return d ? d->newTab : false; return d ? d->newTab : false;
} }
void BrowserArguments::setForcesNewWindow( bool forcesNewWindow ) void BrowserArguments::setForcesNewWindow(bool forcesNewWindow)
{ {
if (!d) if (!d) {
d = new BrowserArgumentsPrivate; d = new BrowserArgumentsPrivate();
d->forcesNewWindow = forcesNewWindow; }
d->forcesNewWindow = forcesNewWindow;
} }
bool BrowserArguments::forcesNewWindow() const bool BrowserArguments::forcesNewWindow() const
@ -239,25 +249,26 @@ namespace KParts
class BrowserExtension::BrowserExtensionPrivate class BrowserExtension::BrowserExtensionPrivate
{ {
public: public:
BrowserExtensionPrivate( KParts::ReadOnlyPart *parent ) BrowserExtensionPrivate(KParts::ReadOnlyPart *parent)
: m_urlDropHandlingEnabled(false), : m_urlDropHandlingEnabled(false),
m_part( parent ) m_part(parent)
{} {
}
struct DelayedRequest { struct DelayedRequest {
KUrl m_delayedURL; KUrl m_delayedURL;
KParts::OpenUrlArguments m_delayedArgs; KParts::OpenUrlArguments m_delayedArgs;
KParts::BrowserArguments m_delayedBrowserArgs; KParts::BrowserArguments m_delayedBrowserArgs;
}; };
QList<DelayedRequest> m_requests; QList<DelayedRequest> m_requests;
bool m_urlDropHandlingEnabled; bool m_urlDropHandlingEnabled;
QBitArray m_actionStatus; QBitArray m_actionStatus;
QMap<int, QString> m_actionText; QMap<int, QString> m_actionText;
static void createActionSlotMap(); static void createActionSlotMap();
KParts::ReadOnlyPart *m_part; KParts::ReadOnlyPart *m_part;
OpenUrlArguments m_args; OpenUrlArguments m_args;
BrowserArguments m_browserArgs; BrowserArguments m_browserArgs;
}; };
@ -267,10 +278,10 @@ K_GLOBAL_STATIC(BrowserExtension::ActionNumberMap, s_actionNumberMap)
void BrowserExtension::BrowserExtensionPrivate::createActionSlotMap() void BrowserExtension::BrowserExtensionPrivate::createActionSlotMap()
{ {
s_actionSlotMap->insert( "cut", SLOT(cut()) ); s_actionSlotMap->insert("cut", SLOT(cut()));
s_actionSlotMap->insert( "copy", SLOT(copy()) ); s_actionSlotMap->insert("copy", SLOT(copy()));
s_actionSlotMap->insert( "paste", SLOT(paste()) ); s_actionSlotMap->insert("paste", SLOT(paste()));
s_actionSlotMap->insert( "print", SLOT(print()) ); s_actionSlotMap->insert("print", SLOT(print()));
// Tricky. Those aren't actions in fact, but simply methods that a browserextension // Tricky. Those aren't actions in fact, but simply methods that a browserextension
// can have or not. No need to return them here. // can have or not. No need to return them here.
//s_actionSlotMap->insert( "reparseConfiguration", SLOT(reparseConfiguration()) ); //s_actionSlotMap->insert( "reparseConfiguration", SLOT(reparseConfiguration()) );
@ -279,8 +290,7 @@ void BrowserExtension::BrowserExtensionPrivate::createActionSlotMap()
// Create the action-number map // Create the action-number map
ActionSlotMap::ConstIterator it = s_actionSlotMap->constBegin(); ActionSlotMap::ConstIterator it = s_actionSlotMap->constBegin();
ActionSlotMap::ConstIterator itEnd = s_actionSlotMap->constEnd(); 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; // kDebug() << " action " << it.key() << " number " << i;
s_actionNumberMap->insert( it.key(), i ); s_actionNumberMap->insert( it.key(), i );
} }
@ -288,84 +298,94 @@ void BrowserExtension::BrowserExtensionPrivate::createActionSlotMap()
} }
BrowserExtension::BrowserExtension( KParts::ReadOnlyPart *parent ) BrowserExtension::BrowserExtension(KParts::ReadOnlyPart *parent)
: QObject( parent ), d( new BrowserExtensionPrivate(parent) ) : QObject(parent),
d(new BrowserExtensionPrivate(parent))
{ {
//kDebug() << "BrowserExtension::BrowserExtension() " << this; // kDebug() << "BrowserExtension::BrowserExtension() " << this;
if (s_actionSlotMap->isEmpty()) if (s_actionSlotMap->isEmpty()) {
// Create the action-slot map // Create the action-slot map
BrowserExtensionPrivate::createActionSlotMap(); BrowserExtensionPrivate::createActionSlotMap();
}
// Build list with this extension's slot names. // Build list with this extension's slot names.
QList<QByteArray> slotNames; QList<QByteArray> slotNames;
int methodCount = metaObject()->methodCount(); int methodCount = metaObject()->methodCount();
int methodOffset = metaObject()->methodOffset(); int methodOffset = metaObject()->methodOffset();
for ( int i=0 ; i < methodCount; ++i ) for (int i= 0; i < methodCount; ++i) {
{ QMetaMethod method = metaObject()->method(methodOffset + i);
QMetaMethod method = metaObject()->method( methodOffset + i ); if (method.methodType() == QMetaMethod::Slot) {
if ( method.methodType() == QMetaMethod::Slot ) slotNames.append(method.signature());
slotNames.append( method.signature() ); }
} }
// Set the initial status of the actions depending on whether // Set the initial status of the actions depending on whether
// they're supported or not // they're supported or not
ActionSlotMap::ConstIterator it = s_actionSlotMap->constBegin(); ActionSlotMap::ConstIterator it = s_actionSlotMap->constBegin();
ActionSlotMap::ConstIterator itEnd = s_actionSlotMap->constEnd(); ActionSlotMap::ConstIterator itEnd = s_actionSlotMap->constEnd();
for ( int i=0 ; it != itEnd ; ++it, ++i ) for (int i = 0 ; it != itEnd ; ++it, ++i) {
{ // Does the extension have a slot with the name of this action ?
// Does the extension have a slot with the name of this action ? // ######### KDE4 TODO: use QMetaObject::indexOfMethod() #######
// ######### KDE4 TODO: use QMetaObject::indexOfMethod() ####### d->m_actionStatus.setBit(i, slotNames.contains(it.key()+"()"));
d->m_actionStatus.setBit( i, slotNames.contains( it.key()+"()" ) ); }
}
connect( d->m_part, SIGNAL(completed()), connect(
this, SLOT(slotCompleted()) ); d->m_part, SIGNAL(completed()),
connect( this, SIGNAL(openUrlRequest(KUrl,KParts::OpenUrlArguments,KParts::BrowserArguments)), this, SLOT(slotCompleted())
this, SLOT(slotOpenUrlRequest(KUrl,KParts::OpenUrlArguments,KParts::BrowserArguments)) ); );
connect( this, SIGNAL(enableAction(const char*,bool)), connect(
this, SLOT(slotEnableAction(const char*,bool)) ); this, SIGNAL(openUrlRequest(KUrl,KParts::OpenUrlArguments,KParts::BrowserArguments)),
connect( this, SIGNAL(setActionText(const char*,QString)), this, SLOT(slotOpenUrlRequest(KUrl,KParts::OpenUrlArguments,KParts::BrowserArguments))
this, SLOT(slotSetActionText(const char*,QString)) ); );
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() BrowserExtension::~BrowserExtension()
{ {
//kDebug() << "BrowserExtension::~BrowserExtension() " << this; // kDebug() << "BrowserExtension::~BrowserExtension() " << this;
delete d; delete d;
} }
void BrowserExtension::setBrowserArguments( const BrowserArguments &args ) void BrowserExtension::setBrowserArguments( const BrowserArguments &args )
{ {
d->m_browserArgs = args; d->m_browserArgs = args;
} }
BrowserArguments BrowserExtension::browserArguments() const BrowserArguments BrowserExtension::browserArguments() const
{ {
return d->m_browserArgs; return d->m_browserArgs;
} }
int BrowserExtension::xOffset() int BrowserExtension::xOffset()
{ {
return 0; return 0;
} }
int BrowserExtension::yOffset() int BrowserExtension::yOffset()
{ {
return 0; return 0;
} }
void BrowserExtension::saveState( QDataStream &stream ) void BrowserExtension::saveState(QDataStream &stream)
{ {
// TODO add d->m_part->mimeType() // 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 ) void BrowserExtension::restoreState( QDataStream &stream )
{ {
KUrl u; KUrl u;
qint32 xOfs, yOfs; qint32 xOfs = 0;
stream >> u >> xOfs >> yOfs; qint32 yOfs = 0;
stream >> u >> xOfs >> yOfs;
OpenUrlArguments args; OpenUrlArguments args;
args.setXOffset(xOfs); args.setXOffset(xOfs);
@ -380,20 +400,20 @@ bool BrowserExtension::isURLDropHandlingEnabled() const
return d->m_urlDropHandlingEnabled; return d->m_urlDropHandlingEnabled;
} }
void BrowserExtension::setURLDropHandlingEnabled( bool enable ) void BrowserExtension::setURLDropHandlingEnabled(bool enable)
{ {
d->m_urlDropHandlingEnabled = enable; d->m_urlDropHandlingEnabled = enable;
} }
void BrowserExtension::slotCompleted() void BrowserExtension::slotCompleted()
{ {
//empty the argument stuff, to avoid bogus/invalid values when opening a new url // empty the argument stuff, to avoid bogus/invalid values when opening a new url
setBrowserArguments( BrowserArguments() ); setBrowserArguments(BrowserArguments());
} }
void BrowserExtension::pasteRequest() void BrowserExtension::pasteRequest()
{ {
QString plain( "plain" ); QString plain("plain");
QString url = QApplication::clipboard()->text(plain, QClipboard::Selection).trimmed(); QString url = QApplication::clipboard()->text(plain, QClipboard::Selection).trimmed();
// Remove linefeeds and any whitespace surrounding it. // Remove linefeeds and any whitespace surrounding it.
url.remove(QRegExp("[\\ ]*\\n+[\\ ]*")); url.remove(QRegExp("[\\ ]*\\n+[\\ ]*"));
@ -404,92 +424,94 @@ void BrowserExtension::pasteRequest()
filters.removeAll( "localdomainurifilter" ); filters.removeAll( "localdomainurifilter" );
KUriFilterData filterData; KUriFilterData filterData;
filterData.setData( url ); filterData.setData( url );
filterData.setCheckForExecutables( false ); filterData.setCheckForExecutables(false);
if ( KUriFilter::self()->filterUri( filterData, filters ) ) 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() ) if (KMessageBox::questionYesNo(d->m_part->widget(),
{ i18n("<qt>Do you want to search the Internet for <b>%1</b>?</qt>", Qt::escape(url)),
case KUriFilterData::LocalFile: i18n("Internet Search"), KGuiItem( i18n( "&Search" ), "edit-find"),
case KUriFilterData::LocalDir: KStandardGuiItem::cancel(), "MiddleClickSearch") == KMessageBox::Yes)
case KUriFilterData::NetProtocol: slotOpenUrlRequest(filterData.uri());
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( "<qt>Do you want to search the Internet for <b>%1</b>?</qt>" , 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; BrowserExtensionPrivate::DelayedRequest req;
req.m_delayedURL = url; req.m_delayedURL = url;
req.m_delayedArgs = args; req.m_delayedArgs = args;
req.m_delayedBrowserArgs = browserArgs; req.m_delayedBrowserArgs = browserArgs;
d->m_requests.append( req ); d->m_requests.append(req);
QTimer::singleShot( 0, this, SLOT(slotEmitOpenUrlRequestDelayed()) ); QTimer::singleShot(0, this, SLOT(slotEmitOpenUrlRequestDelayed()));
} }
void BrowserExtension::slotEmitOpenUrlRequestDelayed() void BrowserExtension::slotEmitOpenUrlRequestDelayed()
{ {
if (d->m_requests.isEmpty()) return; if (d->m_requests.isEmpty()) {
return;
}
BrowserExtensionPrivate::DelayedRequest req = d->m_requests.front(); BrowserExtensionPrivate::DelayedRequest req = d->m_requests.front();
d->m_requests.pop_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.) // 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; //kDebug() << "BrowserExtension::slotEnableAction " << name << " " << enabled;
ActionNumberMap::ConstIterator it = s_actionNumberMap->constFind( name ); ActionNumberMap::ConstIterator it = s_actionNumberMap->constFind(name);
if ( it != s_actionNumberMap->constEnd() ) if (it != s_actionNumberMap->constEnd()) {
{
d->m_actionStatus.setBit( it.value(), enabled ); d->m_actionStatus.setBit( it.value(), enabled );
//kDebug() << "BrowserExtension::slotEnableAction setting bit " << it.data() << " to " << enabled; //kDebug() << "BrowserExtension::slotEnableAction setting bit " << it.data() << " to " << enabled;
} } else {
else
kWarning() << "BrowserExtension::slotEnableAction unknown action " << name; 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 ]; int actionNumber = (*s_actionNumberMap)[name];
return d->m_actionStatus[ actionNumber ]; 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; //kDebug() << "BrowserExtension::slotSetActionText " << name << " " << text;
ActionNumberMap::ConstIterator it = s_actionNumberMap->constFind( name ); ActionNumberMap::ConstIterator it = s_actionNumberMap->constFind(name);
if ( it != s_actionNumberMap->constEnd() ) if (it != s_actionNumberMap->constEnd()) {
{ d->m_actionText[it.value()] = text;
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 ]; int actionNumber = (*s_actionNumberMap)[ name ];
QMap<int, QString>::ConstIterator it = d->m_actionText.constFind( actionNumber ); QMap<int, QString>::ConstIterator it = d->m_actionText.constFind(actionNumber);
if ( it != d->m_actionText.constEnd() ) if (it != d->m_actionText.constEnd()) {
return *it; return *it;
}
return QString(); return QString();
} }
@ -499,16 +521,17 @@ BrowserExtension::ActionSlotMap BrowserExtension::actionSlotMap()
return *actionSlotMapPtr(); return *actionSlotMapPtr();
} }
BrowserExtension::ActionSlotMap * BrowserExtension::actionSlotMapPtr() BrowserExtension::ActionSlotMap* BrowserExtension::actionSlotMapPtr()
{ {
if (s_actionSlotMap->isEmpty()) if (s_actionSlotMap->isEmpty()) {
BrowserExtensionPrivate::createActionSlotMap(); BrowserExtensionPrivate::createActionSlotMap();
}
return s_actionSlotMap; return s_actionSlotMap;
} }
BrowserExtension *BrowserExtension::childObject( QObject *obj ) BrowserExtension *BrowserExtension::childObject(QObject *obj)
{ {
return KGlobal::findDirectChild<KParts::BrowserExtension *>(obj); return KGlobal::findDirectChild<KParts::BrowserExtension*>(obj);
} }
#include "moc_browserextension.cpp" #include "moc_browserextension.cpp"

View file

@ -58,123 +58,119 @@ struct BrowserArgumentsPrivate;
*/ */
struct KPARTS_EXPORT BrowserArguments struct KPARTS_EXPORT BrowserArguments
{ {
BrowserArguments(); BrowserArguments();
BrowserArguments( const BrowserArguments &args ); BrowserArguments(const BrowserArguments &args);
BrowserArguments &operator=( 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, * This buffer can be used by the part to save and restore its contents.
// even if they are inline. * 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. * KHTML-specific field, contents of the HTTP POST data.
* See KWebKitPart for instance. */
*/ QByteArray postData;
QStringList docState;
/** /**
* @p softReload is set when user just hits reload button. It's used * KHTML-specific field, header defining the type of the POST data.
* currently for two different frameset reload strategies. In case of */
* soft reload individual frames are reloaded instead of reloading whole void setContentType(const QString &contentType);
* frameset. /**
*/ * KHTML-specific field, header defining the type of the POST data.
bool softReload; */
QString contentType() const;
/** /**
* KHTML-specific field, contents of the HTTP POST data. * KHTML-specific field, whether to do a POST instead of a GET,
*/ * for the next openURL.
QByteArray postData; */
void setDoPost(bool enable);
/** /**
* KHTML-specific field, header defining the type of the POST data. * KHTML-specific field, whether to do a POST instead of a GET,
*/ * for the next openURL.
void setContentType( const QString & contentType ); */
/** bool doPost() const;
* 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, * Whether to lock the history when opening the next URL.
* for the next openURL. * This is used during e.g. a redirection, to avoid a new entry
*/ * in the history.
bool doPost() const; */
void setLockHistory(bool lock);
bool lockHistory() const;
/** /**
* Whether to lock the history when opening the next URL. * Whether the URL should be opened in a new tab instead in a new window.
* This is used during e.g. a redirection, to avoid a new entry */
* in the history. void setNewTab(bool newTab);
*/ bool newTab() const;
void setLockHistory( bool lock );
bool lockHistory() const;
/** /**
* Whether the URL should be opened in a new tab instead in a new window. * The frame in which to open the URL. KHTML/Konqueror-specific.
*/ */
void setNewTab( bool newTab ); QString frameName;
bool newTab() const;
/** /**
* The frame in which to open the URL. KHTML/Konqueror-specific. * 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
QString frameName; * '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' * @return true if the request was a result of a META refresh/redirect request or
* to execute applications. For instance, the directory views can be * HTTP redirect.
* 'trusted' whereas HTML pages are not trusted in that respect. */
*/ bool redirectedRequest() const;
bool trustedSource;
/** /**
* @return true if the request was a result of a META refresh/redirect request or * Set the redirect flag to indicate URL is a result of either a META redirect
* HTTP redirect. * or HTTP redirect.
*/ *
bool redirectedRequest () const; * @param redirected
*/
void setRedirectedRequest(bool redirected);
/** /**
* Set the redirect flag to indicate URL is a result of either a META redirect * Set whether the URL specifies to be opened in a new window.
* or HTTP redirect. *
* * When openUrlRequest is emitted:
* @param redirected * <ul>
*/ * <li>normally the url would be opened in the current view.</li>
void setRedirectedRequest(bool redirected); * <li>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.</li>
* </ul>
*
* When createNewWindow is emitted:
* <ul>
* <li>if setNewTab(true) was called, a tab is created.</li>
* <li>otherwise, if setForcesNewWindow(true) was called, a window is created.</li>
* <li>otherwise the user preference is followed.</li>
* </ul>
*/
void setForcesNewWindow(bool forcesNewWindow);
/** /**
* Set whether the URL specifies to be opened in a new window. * Whether the URL specifies to be opened in a new window
* */
* When openUrlRequest is emitted: bool forcesNewWindow() const;
* <ul>
* <li>normally the url would be opened in the current view.</li>
* <li>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.</li>
* </ul>
*
* When createNewWindow is emitted:
* <ul>
* <li>if setNewTab(true) was called, a tab is created.</li>
* <li>otherwise, if setForcesNewWindow(true) was called, a window is created.</li>
* <li>otherwise the user preference is followed.</li>
* </ul>
*/
void setForcesNewWindow( bool forcesNewWindow );
/**
* Whether the URL specifies to be opened in a new window
*/
bool forcesNewWindow() const;
private: private:
BrowserArgumentsPrivate *d; BrowserArgumentsPrivate *d;
}; };
/** /**
@ -187,21 +183,21 @@ private:
class KPARTS_EXPORT OpenUrlEvent : public Event class KPARTS_EXPORT OpenUrlEvent : public Event
{ {
public: public:
OpenUrlEvent( ReadOnlyPart *part, const KUrl &url, OpenUrlEvent(ReadOnlyPart *part, const KUrl &url,
const OpenUrlArguments& args = OpenUrlArguments(), const OpenUrlArguments& args = OpenUrlArguments(),
const BrowserArguments& browserArgs = BrowserArguments() ); const BrowserArguments& browserArgs = BrowserArguments());
virtual ~OpenUrlEvent(); virtual ~OpenUrlEvent();
ReadOnlyPart *part() const; ReadOnlyPart *part() const;
KUrl url() const; KUrl url() const;
OpenUrlArguments arguments() const; OpenUrlArguments arguments() const;
BrowserArguments browserArguments() const; BrowserArguments browserArguments() const;
static bool test( const QEvent *event ); static bool test(const QEvent *event);
private: private:
class OpenUrlEventPrivate; class OpenUrlEventPrivate;
OpenUrlEventPrivate * const d; OpenUrlEventPrivate * const d;
}; };
/** /**
@ -257,167 +253,165 @@ private:
*/ */
class KPARTS_EXPORT BrowserExtension : public QObject class KPARTS_EXPORT BrowserExtension : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY( bool urlDropHandling READ isURLDropHandlingEnabled WRITE setURLDropHandlingEnabled ) Q_PROPERTY(bool urlDropHandling READ isURLDropHandlingEnabled WRITE setURLDropHandlingEnabled)
public: public:
/** /**
* Constructor * Constructor
* *
* @param parent The KParts::ReadOnlyPart that this extension ... "extends" :) * @param parent The KParts::ReadOnlyPart that this extension ... "extends" :)
*/ */
explicit BrowserExtension( KParts::ReadOnlyPart *parent ); 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. * Set the parameters to use for opening the next URL.
*/ * This is called by the "hosting" application, to pass parameters to the part.
enum PopupFlag { * @see BrowserArguments
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) */ virtual void setBrowserArguments(const BrowserArguments &args);
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 ) /**
* 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. * Returns the current x offset.
* This is called by the "hosting" application, to pass parameters to the part. *
* @see BrowserArguments * For a scrollview, implement this using contentsX().
*/ */
virtual void setBrowserArguments( const BrowserArguments &args ); 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 * Used by the browser to save the current state of the view
* (this must be called from openUrl() in the part). * (in order to restore it if going back in navigation).
* @see BrowserArguments *
*/ * If you want to save additional properties, reimplement it
BrowserArguments browserArguments() const; * but don't forget to call the parent method (probably first).
*/
virtual void saveState(QDataStream &stream);
/** /**
* Returns the current x offset. * Used by the browser to restore the view in the state
* * it was when we left it.
* For a scrollview, implement this using contentsX(). *
*/ * If you saved additional properties, reimplement it
virtual int xOffset(); * but don't forget to call the parent method (probably first).
/** */
* Returns the current y offset. virtual void restoreState(QDataStream &stream);
*
* For a scrollview, implement this using contentsY().
*/
virtual int yOffset();
/** /**
* Used by the browser to save the current state of the view * Returns whether url drop handling is enabled.
* (in order to restore it if going back in navigation). * See setURLDropHandlingEnabled for more information about this
* * property.
* If you want to save additional properties, reimplement it */
* but don't forget to call the parent method (probably first). bool isURLDropHandlingEnabled() const;
*/
virtual void saveState( QDataStream &stream );
/** /**
* Used by the browser to restore the view in the state * Enables or disables url drop handling. URL drop handling is a property
* it was when we left it. * describing whether the hosting shell component is allowed to install an
* * event filter on the part's widget, to listen for URI drop events.
* If you saved additional properties, reimplement it * Set it to true if you are exporting a BrowserExtension implementation and
* but don't forget to call the parent method (probably first). * 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
virtual void restoreState( QDataStream &stream ); * 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. * @return the status (enabled/disabled) of an action.
* See setURLDropHandlingEnabled for more information about this * When the enableAction signal is emitted, the browserextension
* property. * 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 isURLDropHandlingEnabled() const; */
bool isActionEnabled(const char *name) const;
/** /**
* Enables or disables url drop handling. URL drop handling is a property * @return the text of an action, if it was set explicitly by the part.
* describing whether the hosting shell component is allowed to install an * When the setActionText signal is emitted, the browserextension
* event filter on the part's widget, to listen for URI drop events. * stores the text of the action internally, so that it's possible
* Set it to true if you are exporting a BrowserExtension implementation and * to query later for the text of the action, using this method.
* 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 QString actionText(const char *name) const;
* implementation as of Konqueror installs the event filter only on the part's
* widget itself, not on child widgets.
*/
void setURLDropHandlingEnabled( bool enable );
/** typedef QMap<QByteArray,QByteArray> ActionSlotMap;
* @return the status (enabled/disabled) of an action. /**
* When the enableAction signal is emitted, the browserextension * Returns a map containing the action names as keys and corresponding
* stores the status of the action internally, so that it's possible * SLOT()'ified method names as data entries.
* to query later for the status of the action, using this method. *
*/ * This is very useful for
bool isActionEnabled( const char * name ) const; * 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<QCString,QCString> iterator)
*/
static ActionSlotMap actionSlotMap();
/** /**
* @return the text of an action, if it was set explicitly by the part. * @return a pointer to the static action-slot map. Preferred method to get it.
* When the setActionText signal is emitted, the browserextension * The map is created if it doesn't exist yet
* stores the text of the action internally, so that it's possible */
* to query later for the text of the action, using this method. static ActionSlotMap* actionSlotMapPtr();
*/
QString actionText( const char * name ) const;
typedef QMap<QByteArray,QByteArray> ActionSlotMap; /**
/** * Queries @p obj for a child object which inherits from this
* Returns a map containing the action names as keys and corresponding * BrowserExtension class. Convenience method.
* SLOT()'ified method names as data entries. */
* static BrowserExtension* childObject(QObject *obj);
* 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<QCString,QCString> iterator)
*/
static ActionSlotMap actionSlotMap();
/** /**
* @return a pointer to the static action-slot map. Preferred method to get it. * Asks the hosting browser to perform a paste (using openUrlRequestDelayed())
* The map is created if it doesn't exist yet */
*/ void pasteRequest();
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();
/** /**
* Associates a list of actions with a predefined name known by the host's popupmenu: * 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, * "linkactions" for actions related to hyperlinks,
* "partactions" for any other actions provided by the part * "partactions" for any other actions provided by the part
*/ */
typedef QMap<QString, QList<QAction *> > ActionGroupMap; typedef QMap<QString, QList<QAction*>> ActionGroupMap;
Q_SIGNALS: Q_SIGNALS:
#if !defined(Q_MOC_RUN) && !defined(DOXYGEN_SHOULD_SKIP_THIS) #if !defined(Q_MOC_RUN) && !defined(DOXYGEN_SHOULD_SKIP_THIS)
public: // yes, those signals are public; don't tell moc or doxygen :) public: // yes, those signals are public; don't tell moc or doxygen :)
#endif #endif
/** /**
* Enables or disable a standard action held by the browser. * Enables or disable a standard action held by the browser.
* *
* See class documentation for the list of standard actions. * See class documentation for the list of standard actions.
*/ */
void enableAction( const char * name, bool enabled ); void enableAction(const char *name, bool enabled);
/** /**
* Change the text of a standard action held by the browser. * Change the text of a standard action held by the browser.
* This can be used to change "Paste" into "Paste Image" for instance. * This can be used to change "Paste" into "Paste Image" for instance.
* *
* See class documentation for the list of standard actions. * See class documentation for the list of standard actions.
*/ */
void setActionText( const char * name, const QString& text ); void setActionText(const char *name, const QString &text);
/** /**
* Asks the host (browser) to open @p url. * Asks the host (browser) to open @p url.
* To set a reload, the x and y offsets, the service type etc., fill in the * To set a reload, the x and y offsets, the service type etc., fill in the
* appropriate fields in the @p args structure. * appropriate fields in the @p args structure.
* Hosts should not connect to this signal but to openUrlRequestDelayed(). * Hosts should not connect to this signal but to openUrlRequestDelayed().
*/ */
void openUrlRequest( const KUrl &url, void openUrlRequest(const KUrl &url,
const KParts::OpenUrlArguments& arguments = KParts::OpenUrlArguments(), const KParts::OpenUrlArguments& arguments = KParts::OpenUrlArguments(),
const KParts::BrowserArguments &browserArguments = KParts::BrowserArguments() ); const KParts::BrowserArguments &browserArguments = KParts::BrowserArguments());
/** /**
* This signal is emitted when openUrlRequest() is called, after a 0-seconds timer. * 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) * 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 * being destroyed. Parts should never use this signal, hosts should only connect
* to this signal. * to this signal.
*/ */
void openUrlRequestDelayed( const KUrl &url, void openUrlRequestDelayed(const KUrl &url,
const KParts::OpenUrlArguments& arguments, const KParts::OpenUrlArguments &arguments,
const KParts::BrowserArguments &browserArguments ); const KParts::BrowserArguments &browserArguments);
/** /**
* Tells the hosting browser that the part opened a new URL (which can be * Tells the hosting browser that the part opened a new URL (which can be
* queried via KParts::Part::url(). * queried via KParts::Part::url().
* *
* This helps the browser to update/create an entry in the history. * This helps the browser to update/create an entry in the history.
* The part may @em not emit this signal together with openUrlRequest(). * The part may @em not emit this signal together with openUrlRequest().
* Emit openUrlRequest() if you want the browser to handle a URL the user * 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 * asked to open (from within your part/document). This signal however is
* useful if you want to handle URLs all yourself internally, while still * useful if you want to handle URLs all yourself internally, while still
* telling the hosting browser about new opened URLs, in order to provide * telling the hosting browser about new opened URLs, in order to provide
* a proper history functionality to the user. * a proper history functionality to the user.
* An example of usage is a html rendering component which wants to emit * An example of usage is a html rendering component which wants to emit
* this signal when a child frame document changed its URL. * this signal when a child frame document changed its URL.
* Conclusion: you probably want to use openUrlRequest() instead. * Conclusion: you probably want to use openUrlRequest() instead.
*/ */
void openUrlNotify(); void openUrlNotify();
/** /**
* Updates the URL shown in the browser's location bar to @p url. * Updates the URL shown in the browser's location bar to @p url.
*/ */
void setLocationBarUrl( const QString &url ); void setLocationBarUrl(const QString &url);
/** /**
* Sets the URL of an icon for the currently displayed page. * Sets the URL of an icon for the currently displayed page.
*/ */
void setIconUrl( const KUrl &url ); void setIconUrl(const KUrl &url);
/** /**
* Asks the hosting browser to open a new window for the given @p url * Asks the hosting browser to open a new window for the given @p url
* and return a reference to the content part. * and return a reference to the content part.
* *
* @p arguments is optional additional information about how to open the url, * @p arguments is optional additional information about how to open the url,
* @see KParts::OpenUrlArguments * @see KParts::OpenUrlArguments
* *
* @p browserArguments is optional additional information for web browsers, * @p browserArguments is optional additional information for web browsers,
* @see KParts::BrowserArguments * @see KParts::BrowserArguments
* *
* The request for a pointer to the part is only fulfilled/processed * The request for a pointer to the part is only fulfilled/processed
* if the mimeType is set in the @p browserArguments. * if the mimeType is set in the @p browserArguments.
* (otherwise the request cannot be processed synchronously). * (otherwise the request cannot be processed synchronously).
*/ */
void createNewWindow( const KUrl &url, void createNewWindow(const KUrl &url,
const KParts::OpenUrlArguments& arguments = KParts::OpenUrlArguments(), const KParts::OpenUrlArguments &arguments = KParts::OpenUrlArguments(),
const KParts::BrowserArguments &browserArguments = KParts::BrowserArguments(), const KParts::BrowserArguments &browserArguments = KParts::BrowserArguments(),
KParts::ReadOnlyPart** part = 0 ); KParts::ReadOnlyPart** part = nullptr);
/** /**
* Since the part emits the jobid in the started() signal, * Since the part emits the jobid in the started() signal,
* progress information is automatically displayed. * progress information is automatically displayed.
* *
* However, if you don't use a KIO::Job in the part, * However, if you don't use a KIO::Job in the part,
* you can use loadingProgress() and speedProgress() * you can use loadingProgress() and speedProgress()
* to display progress information. * to display progress information.
*/ */
void loadingProgress( int percent ); void loadingProgress(int percent);
/** /**
* @see loadingProgress * @see loadingProgress
*/ */
void speedProgress( int bytesPerSecond ); 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. * 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 global global coordinates where the popup should be shown
* @param items list of file items which the popup applies to * @param items list of file items which the popup applies to
* @param args OpenUrlArguments, mostly for metadata here * @param args OpenUrlArguments, mostly for metadata here
* @param browserArguments BrowserArguments, mostly for referrer * @param browserArguments BrowserArguments, mostly for referrer
* @param flags enables/disables certain builtin actions in the popupmenu * @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 * @param actionGroups named groups of actions which should be inserted into the popup, see ActionGroupMap
*/ */
void popupMenu( const QPoint &global, const KFileItemList &items, void popupMenu(const QPoint &global, const KFileItemList &items,
const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(), const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(),
const KParts::BrowserArguments &browserArgs = KParts::BrowserArguments(), const KParts::BrowserArguments &browserArgs = KParts::BrowserArguments(),
KParts::BrowserExtension::PopupFlags flags = KParts::BrowserExtension::DefaultPopupItems, KParts::BrowserExtension::PopupFlags flags = KParts::BrowserExtension::DefaultPopupItems,
const KParts::BrowserExtension::ActionGroupMap& actionGroups = ActionGroupMap() ); const KParts::BrowserExtension::ActionGroupMap &actionGroups = ActionGroupMap());
/** /**
* Emit this to make the browser show a standard popup menu for the given @p url. * 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, * Give as much information about this URL as possible,
* like @p args.mimeType and the file type @p mode * like @p args.mimeType and the file type @p mode
* *
* @param global global coordinates where the popup should be shown * @param global global coordinates where the popup should be shown
* @param url the URL this popup applies to * @param url the URL this popup applies to
* @param mode the file type of the url (S_IFREG, S_IFDIR...) * @param mode the file type of the url (S_IFREG, S_IFDIR...)
* @param args OpenUrlArguments, set the mimetype of the URL using setMimeType() * @param args OpenUrlArguments, set the mimetype of the URL using setMimeType()
* @param browserArguments BrowserArguments, mostly for referrer * @param browserArguments BrowserArguments, mostly for referrer
* @param flags enables/disables certain builtin actions in the popupmenu * @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 * @param actionGroups named groups of actions which should be inserted into the popup, see ActionGroupMap
*/ */
void popupMenu( const QPoint &global, const KUrl &url, void popupMenu(const QPoint &global, const KUrl &url,
mode_t mode = static_cast<mode_t>(-1), mode_t mode = static_cast<mode_t>(-1),
const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(), const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(),
const KParts::BrowserArguments &browserArgs = KParts::BrowserArguments(), const KParts::BrowserArguments &browserArgs = KParts::BrowserArguments(),
KParts::BrowserExtension::PopupFlags flags = KParts::BrowserExtension::DefaultPopupItems, KParts::BrowserExtension::PopupFlags flags = KParts::BrowserExtension::DefaultPopupItems,
const KParts::BrowserExtension::ActionGroupMap& actionGroups = ActionGroupMap() ); const KParts::BrowserExtension::ActionGroupMap& actionGroups = ActionGroupMap());
/** /**
* Inform the hosting application about the current selection. * Inform the hosting application about the current selection.
* Used when a set of files/URLs is selected (with full information * Used when a set of files/URLs is selected (with full information
* about those URLs, including size, permissions etc.) * about those URLs, including size, permissions etc.)
*/ */
void selectionInfo( const KFileItemList& items ); void selectionInfo(const KFileItemList &items);
/** /**
* Inform the hosting application about the current selection. * Inform the hosting application about the current selection.
* Used when some text is selected. * Used when some text is selected.
*/ */
void selectionInfo( const QString &text ); void selectionInfo( const QString &text );
/** /**
* Inform the hosting application about the current selection. * Inform the hosting application about the current selection.
* Used when a set of URLs is selected. * Used when a set of URLs is selected.
*/ */
void selectionInfo( const KUrl::List &urls ); void selectionInfo( const KUrl::List &urls );
/** /**
* Inform the hosting application that the user moved the mouse over an item. * Inform the hosting application that the user moved the mouse over an item.
* Used when the mouse is on an URL. * Used when the mouse is on an URL.
*/ */
void mouseOverInfo( const KFileItem& item ); void mouseOverInfo(const KFileItem &item);
/** /**
* Ask the hosting application to add a new HTML (aka Mozilla/Netscape) * Ask the hosting application to add a new HTML (aka Mozilla/Netscape)
* SideBar entry. * SideBar entry.
*/ */
void addWebSideBar(const KUrl &url, const QString& name); void addWebSideBar(const KUrl &url, const QString &name);
/** /**
* Ask the hosting application to move the top level widget. * Ask the hosting application to move the top level widget.
*/ */
void moveTopLevelWidget( int x, int y ); void moveTopLevelWidget(int x, int y);
/** /**
* Ask the hosting application to resize the top level widget. * Ask the hosting application to resize the top level widget.
*/ */
void resizeTopLevelWidget( int w, int h ); void resizeTopLevelWidget(int w, int h);
/** /**
* Ask the hosting application to focus @p part. * Ask the hosting application to focus @p part.
*/ */
void requestFocus(KParts::ReadOnlyPart *part); void requestFocus(KParts::ReadOnlyPart *part);
/** /**
* Tell the host (browser) about security state of current page * Tell the host (browser) about security state of current page
* enum PageSecurity { NotCrypted, Encrypted, Mixed }; * enum PageSecurity { NotCrypted, Encrypted, Mixed };
*/ */
void setPageSecurity( int ); void setPageSecurity(int);
/** /**
* Inform the host about items that have been removed. * Inform the host about items that have been removed.
*/ */
void itemsRemoved( const KFileItemList &items ); void itemsRemoved(const KFileItemList &items);
private Q_SLOTS: private Q_SLOTS:
void slotCompleted(); void slotCompleted();
void slotOpenUrlRequest( const KUrl &url, void slotOpenUrlRequest(const KUrl &url,
const KParts::OpenUrlArguments& arguments = KParts::OpenUrlArguments(), const KParts::OpenUrlArguments &arguments = KParts::OpenUrlArguments(),
const KParts::BrowserArguments &browserArguments = KParts::BrowserArguments() ); const KParts::BrowserArguments &browserArguments = KParts::BrowserArguments());
void slotEmitOpenUrlRequestDelayed(); void slotEmitOpenUrlRequestDelayed();
void slotEnableAction( const char *, bool ); void slotEnableAction(const char *, bool);
void slotSetActionText( const char*, const QString& ); void slotSetActionText(const char*, const QString&);
public: public:
typedef QMap<QByteArray,int> ActionNumberMap; typedef QMap<QByteArray,int> ActionNumberMap;
private: private:
class BrowserExtensionPrivate; class BrowserExtensionPrivate;
BrowserExtensionPrivate * const d; BrowserExtensionPrivate * const d;
}; };
} }
Q_DECLARE_OPERATORS_FOR_FLAGS( KParts::BrowserExtension::PopupFlags ) Q_DECLARE_OPERATORS_FOR_FLAGS(KParts::BrowserExtension::PopupFlags)
#endif #endif

View file

@ -27,16 +27,17 @@ using namespace KParts;
class KParts::EventPrivate class KParts::EventPrivate
{ {
public: public:
EventPrivate( const char *eventName ) : EventPrivate(const char *eventName)
m_eventName(eventName) : m_eventName(eventName)
{ {
} }
const char* m_eventName; const char* m_eventName;
}; };
Event::Event( const char *eventName ) Event::Event(const char *eventName)
: QEvent( (QEvent::Type)(QEvent::User + KPARTS_EVENT_MAGIC) ) : QEvent((QEvent::Type)(QEvent::User + KPARTS_EVENT_MAGIC))
, d( new EventPrivate(eventName) ) , d(new EventPrivate(eventName))
{ {
} }
@ -47,33 +48,32 @@ Event::~Event()
const char *Event::eventName() const 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 ) if (!event) {
return false; return false;
}
return ( event->type() == (QEvent::Type)(QEvent::User + KPARTS_EVENT_MAGIC ) ); 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 ) ) if (!test(event)) {
return false; return false;
}
return ( strcmp( name, ((Event*)event)->eventName() ) == 0 ); return (qstrcmp(name, ((Event*)event)->eventName()) == 0);
} }
/////// GUIActivateEvent //////// /////// GUIActivateEvent ////////
class KParts::GUIActivateEventPrivate class KParts::GUIActivateEventPrivate
{ {
public: public:
GUIActivateEventPrivate( bool activated ) GUIActivateEventPrivate(bool activated)
: m_bActivated( activated ) : m_bActivated(activated)
{ {
} }
static const char *s_strGUIActivateEvent; static const char *s_strGUIActivateEvent;
@ -82,9 +82,9 @@ public:
const char *GUIActivateEventPrivate::s_strGUIActivateEvent = "KParts/GUIActivate"; const char *GUIActivateEventPrivate::s_strGUIActivateEvent = "KParts/GUIActivate";
GUIActivateEvent::GUIActivateEvent( bool activated ) : GUIActivateEvent::GUIActivateEvent(bool activated)
Event( GUIActivateEventPrivate::s_strGUIActivateEvent ), : Event(GUIActivateEventPrivate::s_strGUIActivateEvent),
d( new GUIActivateEventPrivate(activated) ) d(new GUIActivateEventPrivate(activated))
{ {
} }
@ -98,8 +98,7 @@ bool GUIActivateEvent::activated() const
return d->m_bActivated; 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);
} }

View file

@ -37,15 +37,15 @@ class EventPrivate;
class KPARTS_EXPORT Event : public QEvent class KPARTS_EXPORT Event : public QEvent
{ {
public: public:
Event( const char *eventName ); Event(const char *eventName);
~Event(); ~Event();
const char *eventName() const; const char *eventName() const;
static bool test( const QEvent *event ); static bool test(const QEvent *event);
static bool test( const QEvent *event, const char *name ); static bool test(const QEvent *event, const char *name);
private: private:
EventPrivate * const d; EventPrivate * const d;
}; };
class GUIActivateEventPrivate; class GUIActivateEventPrivate;
@ -58,15 +58,15 @@ class GUIActivateEventPrivate;
class KPARTS_EXPORT GUIActivateEvent : public Event class KPARTS_EXPORT GUIActivateEvent : public Event
{ {
public: public:
GUIActivateEvent( bool activated ); GUIActivateEvent(bool activated);
~GUIActivateEvent(); ~GUIActivateEvent();
bool activated() const; bool activated() const;
static bool test( const QEvent *event ); static bool test(const QEvent *event);
private: private:
GUIActivateEventPrivate * const d; GUIActivateEventPrivate * const d;
}; };
} // namespace } // namespace

View file

@ -28,12 +28,10 @@
#include <kglobal.h> #include <kglobal.h>
#include <kcomponentdata.h> #include <kcomponentdata.h>
#include <assert.h>
using namespace KParts; using namespace KParts;
Factory::Factory( QObject *parent ) Factory::Factory(QObject *parent)
: KPluginFactory( 0, 0, 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 ); Part* part = createPartObject(parentWidget, parent, classname, args);
if ( part ) if (part) {
emit objectCreated( part ); emit objectCreated(part);
}
return part; return part;
} }
@ -54,28 +53,29 @@ KComponentData Factory::partComponentData()
return KComponentData(); return KComponentData();
} }
KComponentData Factory::partComponentDataFromLibrary( const QString &libraryName ) KComponentData Factory::partComponentDataFromLibrary(const QString &libraryName)
{ {
KPluginLoader loader( libraryName ); KPluginLoader loader(libraryName);
KPluginFactory *factory = loader.factory(); KPluginFactory *factory = loader.factory();
if ( !factory ) if (!factory) {
return KComponentData(); return KComponentData();
KParts::Factory *pfactory = qobject_cast<KParts::Factory *>( factory ); }
if ( !pfactory ) KParts::Factory *pfactory = qobject_cast<KParts::Factory*>(factory);
if (!pfactory) {
return KComponentData(); return KComponentData();
}
return pfactory->partComponentData(); 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() ); Q_ASSERT(!parent || parent->isWidgetType());
return createPart( static_cast<QWidget *>( parent ), parent, classname, args ); return createPart(static_cast<QWidget*>(parent), parent, classname, args);
} }
#include "moc_factory.cpp" #include "moc_factory.cpp"

View file

@ -40,10 +40,10 @@ class Part;
*/ */
class KPARTS_EXPORT Factory : public KPluginFactory class KPARTS_EXPORT Factory : public KPluginFactory
{ {
Q_OBJECT Q_OBJECT
public: public:
Factory( QObject *parent = 0 ); Factory(QObject *parent = nullptr);
virtual ~Factory(); virtual ~Factory();
/** /**
* Creates a part. * Creates a part.
@ -72,7 +72,8 @@ public:
* important for reference counting, and allows unloading the * important for reference counting, and allows unloading the
* library automatically once all its objects have been destroyed. * 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 * 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); static KComponentData partComponentDataFromLibrary(const QString &libraryName);
protected: protected:
/** /**
* Reimplement this method in your implementation to create the Part. * Reimplement this method in your implementation to create the Part.
* *
@ -115,19 +115,16 @@ protected:
* *
* @returns the newly created part. * @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() * 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 #endif

View file

@ -42,12 +42,9 @@ class MainWindowPrivate
{ {
public: public:
MainWindowPrivate() MainWindowPrivate()
: m_activePart(0), : m_activePart(nullptr),
m_bShellGUIActivated(false), m_bShellGUIActivated(false),
m_helpMenu(0) m_helpMenu(nullptr)
{
}
~MainWindowPrivate()
{ {
} }
@ -57,18 +54,19 @@ public:
}; };
} }
MainWindow::MainWindow( QWidget* parent, Qt::WindowFlags f ) MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags f)
: KXmlGuiWindow( parent, f ), d(new MainWindowPrivate()) : KXmlGuiWindow(parent, f),
d(new MainWindowPrivate())
{ {
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
delete d; delete d;
} }
void MainWindow::createGUI( Part * part ) void MainWindow::createGUI(Part *part)
{ {
#if 0 #if 0
kDebug() << "part=" << part kDebug() << "part=" << part
@ -77,9 +75,9 @@ void MainWindow::createGUI( Part * part )
#endif #endif
KXMLGUIFactory *factory = guiFactory(); KXMLGUIFactory *factory = guiFactory();
assert( factory ); assert(factory);
if ( d->m_activePart ) if (d->m_activePart)
{ {
#if 0 #if 0
kDebug() << "deactivating GUI for" << d->m_activePart kDebug() << "deactivating GUI for" << d->m_activePart

View file

@ -43,47 +43,46 @@ class MainWindowPrivate;
*/ */
class KPARTS_EXPORT MainWindow : public KXmlGuiWindow, virtual public PartBase class KPARTS_EXPORT MainWindow : public KXmlGuiWindow, virtual public PartBase
{ {
Q_OBJECT Q_OBJECT
public: public:
/** /**
* Constructor, same signature as KMainWindow. * Constructor, same signature as KMainWindow.
*/ */
explicit MainWindow( QWidget* parent = 0, Qt::WindowFlags f = 0 ); explicit MainWindow(QWidget *parent = nullptr, Qt::WindowFlags f = 0);
/** /**
* Destructor. * Destructor.
*/ */
virtual ~MainWindow(); virtual ~MainWindow();
protected Q_SLOTS: 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) * Called when the active part wants to change the statusbar message
* You _must_ call this in order to see any GUI being created. * Reimplement if your mainwindow has a complex statusbar
* * (with several items)
* @param part The active part (set to 0L if no part). */
*/ virtual void slotSetStatusBarText( const QString & );
void createGUI( KParts::Part * part );
/** /**
* Called when the active part wants to change the statusbar message * Rebuilds the GUI after KEditToolbar changed the toolbar layout.
* Reimplement if your mainwindow has a complex statusbar * @see configureToolbars()
* (with several items) * KDE4: make this virtual. (For now we rely on the fact that it's called
*/ * as a slot, so the metaobject finds it here).
virtual void slotSetStatusBarText( const QString & ); */
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: protected:
virtual void createShellGUI( bool create = true ); virtual void createShellGUI(bool create = true);
private: private:
MainWindowPrivate* const d; MainWindowPrivate* const d;
}; };
} }