20#include "browserextension.h"
22#include <tqapplication.h>
23#include <tqclipboard.h>
25#include <tqobjectlist.h>
26#include <tqmetaobject.h>
29#include <tqstylesheet.h>
33#include <tdemessagebox.h>
34#include <kstaticdeleter.h>
35#include <kurifilter.h>
38using namespace KParts;
40const char *OpenURLEvent::s_strOpenURLEvent =
"KParts/BrowserExtension/OpenURLevent";
42class OpenURLEvent::OpenURLEventPrivate
48 ~OpenURLEventPrivate()
54:
Event( s_strOpenURLEvent ), m_part( part ), m_url( url ), m_args( args )
59OpenURLEvent::~OpenURLEvent()
71 redirectedRequest =
false;
74 forcesNewWindow =
false;
77 TQMap<TQString, TQString> metaData;
79 bool redirectedRequest;
97URLArgs::URLArgs(
bool _reload,
int _xOffset,
int _yOffset,
const TQString &_serviceType )
106URLArgs::URLArgs(
const URLArgs &args )
114 if (
this == &args)
return *
this;
128 d =
new URLArgsPrivate( * args.d );
142 d =
new URLArgsPrivate;
149 d =
new URLArgsPrivate;
150 d->redirectedRequest = redirected;
155 return d ? d->redirectedRequest :
false;
160 return d ? d->contentType : TQString::null;
166 d =
new URLArgsPrivate;
173 d =
new URLArgsPrivate;
179 return d ? d->doPost :
false;
185 d =
new URLArgsPrivate;
186 d->lockHistory = lock;
189bool URLArgs::lockHistory()
const
191 return d ? d->lockHistory :
false;
197 d =
new URLArgsPrivate;
201bool URLArgs::newTab()
const
203 return d ? d->newTab :
false;
209 d =
new URLArgsPrivate;
215 return d ? d->forcesNewWindow :
false;
221struct WindowArgsPrivate
227WindowArgs::WindowArgs()
229 x = y = width = height = -1;
231 menuBarVisible =
true;
232 toolBarsVisible =
true;
233 statusBarVisible =
true;
234 scrollBarsVisible =
true;
240WindowArgs::WindowArgs(
const WindowArgs &args )
246WindowArgs::~WindowArgs()
253 if (
this == &args )
return *
this;
260 height = args.height;
261 fullscreen = args.fullscreen;
262 menuBarVisible = args.menuBarVisible;
263 toolBarsVisible = args.toolBarsVisible;
264 statusBarVisible = args.statusBarVisible;
265 scrollBarsVisible = args.scrollBarsVisible;
266 resizable = args.resizable;
267 lowerWindow = args.lowerWindow;
279WindowArgs::WindowArgs(
const TQRect &_geometry,
bool _fullscreen,
bool _menuBarVisible,
280 bool _toolBarsVisible,
bool _statusBarVisible,
bool _resizable )
285 width = _geometry.width();
286 height = _geometry.height();
287 fullscreen = _fullscreen;
288 menuBarVisible = _menuBarVisible;
289 toolBarsVisible = _toolBarsVisible;
290 statusBarVisible = _statusBarVisible;
291 resizable = _resizable;
295WindowArgs::WindowArgs(
int _x,
int _y,
int _width,
int _height,
bool _fullscreen,
296 bool _menuBarVisible,
bool _toolBarsVisible,
297 bool _statusBarVisible,
bool _resizable )
304 fullscreen = _fullscreen;
305 menuBarVisible = _menuBarVisible;
306 toolBarsVisible = _toolBarsVisible;
307 statusBarVisible = _statusBarVisible;
308 resizable = _resizable;
320 KBitArray() { val = 0; }
321 bool operator [](
int index) {
return (val & (1 << index)) ? true :
false; }
322 void setBit(
int index,
bool value) {
323 if (value) val = val | (1 << index);
324 else val = val & ~(1 << index);
328class BrowserExtensionPrivate
331 BrowserExtensionPrivate()
333 m_browserInterface = 0;
335 ~BrowserExtensionPrivate()
339 struct DelayedRequest {
341 KParts::URLArgs m_delayedArgs;
343 TQValueList<DelayedRequest> m_requests;
344 bool m_urlDropHandlingEnabled;
345 KBitArray m_actionStatus;
346 TQMap<int, TQString> m_actionText;
347 BrowserInterface *m_browserInterface;
352BrowserExtension::ActionSlotMap * BrowserExtension::s_actionSlotMap = 0L;
353static KStaticDeleter<BrowserExtension::ActionSlotMap> actionSlotMapsd;
354BrowserExtension::ActionNumberMap * BrowserExtension::s_actionNumberMap = 0L;
355static KStaticDeleter<BrowserExtension::ActionNumberMap> actionNumberMapsd;
359: TQObject( parent, name), m_part( parent )
362 d =
new BrowserExtensionPrivate;
363 d->m_urlDropHandlingEnabled =
false;
365 if ( !s_actionSlotMap )
367 createActionSlotMap();
371 ActionSlotMap::ConstIterator it = s_actionSlotMap->begin();
372 ActionSlotMap::ConstIterator itEnd = s_actionSlotMap->end();
373 TQStrList slotNames = metaObject()->slotNames();
374 for (
int i=0 ; it != itEnd ; ++it, ++i )
377 d->m_actionStatus.setBit( i, slotNames.contains( it.key()+
"()" ) );
380 connect( m_part, TQ_SIGNAL( completed() ),
381 this, TQ_SLOT( slotCompleted() ) );
384 connect(
this, TQ_SIGNAL(
enableAction(
const char *,
bool ) ),
385 this, TQ_SLOT( slotEnableAction(
const char *,
bool ) ) );
386 connect(
this, TQ_SIGNAL(
setActionText(
const char *,
const TQString& ) ),
387 this, TQ_SLOT( slotSetActionText(
const char *,
const TQString& ) ) );
390BrowserExtension::~BrowserExtension()
418 stream << m_part->url() << (TQ_INT32)
xOffset() << (TQ_INT32)
yOffset();
425 stream >> u >> xOfs >> yOfs;
433 m_part->openURL( u );
438 return d->m_urlDropHandlingEnabled;
443 d->m_urlDropHandlingEnabled = enable;
446void BrowserExtension::slotCompleted()
454 TQCString plain(
"plain" );
455 TQString url = TQApplication::clipboard()->text(plain, TQClipboard::Selection).stripWhiteSpace();
457 url.remove(TQRegExp(
"[\\ ]*\\n+[\\ ]*"));
460 TQStringList filters = KURIFilter::self()->pluginNames();
461 filters.remove(
"kuriikwsfilter" );
462 filters.remove(
"localdomainurifilter" );
463 KURIFilterData filterData;
464 filterData.setData( url );
465 filterData.setCheckForExecutables(
false );
466 if ( KURIFilter::self()->filterURI( filterData, filters ) )
468 switch ( filterData.uriType() )
470 case KURIFilterData::LOCAL_FILE:
471 case KURIFilterData::LOCAL_DIR:
472 case KURIFilterData::NET_PROTOCOL:
475 case KURIFilterData::ERROR:
482 else if ( KURIFilter::self()->filterURI( filterData,
"kuriikwsfilter" ) && url.length() < 250 )
485 i18n(
"<qt>Do you want to search the Internet for <b>%1</b>?" ).arg( TQStyleSheet::escape(url) ),
486 i18n(
"Internet Search" ),
KGuiItem( i18n(
"&Search" ),
"edit-find"),
487 KStdGuiItem::cancel(),
"MiddleClickSearch" ) == KMessageBox::Yes)
495 BrowserExtensionPrivate::DelayedRequest req;
496 req.m_delayedURL = url;
497 req.m_delayedArgs = args;
498 d->m_requests.append( req );
499 TQTimer::singleShot( 0,
this, TQ_SLOT( slotEmitOpenURLRequestDelayed() ) );
502void BrowserExtension::slotEmitOpenURLRequestDelayed()
504 if (d->m_requests.isEmpty())
return;
505 BrowserExtensionPrivate::DelayedRequest req = d->m_requests.front();
506 d->m_requests.pop_front();
513 d->m_browserInterface = impl;
518 return d->m_browserInterface;
521void BrowserExtension::slotEnableAction(
const char * name,
bool enabled )
524 ActionNumberMap::ConstIterator it = s_actionNumberMap->find( name );
525 if ( it != s_actionNumberMap->end() )
527 d->m_actionStatus.setBit( it.data(), enabled );
531 kdWarning() <<
"BrowserExtension::slotEnableAction unknown action " <<
name <<
endl;
536 int actionNumber = (*s_actionNumberMap)[ name ];
537 return d->m_actionStatus[ actionNumber ];
540void BrowserExtension::slotSetActionText(
const char * name,
const TQString& text )
542 kdDebug() <<
"BrowserExtension::slotSetActionText " << name <<
" " << text <<
endl;
543 ActionNumberMap::ConstIterator it = s_actionNumberMap->find( name );
544 if ( it != s_actionNumberMap->end() )
546 d->m_actionText[ it.data() ] = text;
549 kdWarning() <<
"BrowserExtension::slotSetActionText unknown action " << name <<
endl;
554 int actionNumber = (*s_actionNumberMap)[ name ];
555 TQMap<int, TQString>::ConstIterator it = d->m_actionText.find( actionNumber );
556 if ( it != d->m_actionText.end() )
558 return TQString::null;
569 if (!s_actionSlotMap)
570 createActionSlotMap();
571 return s_actionSlotMap;
574void BrowserExtension::createActionSlotMap()
576 assert(!s_actionSlotMap);
577 s_actionSlotMap = actionSlotMapsd.setObject( s_actionSlotMap,
new ActionSlotMap );
579 s_actionSlotMap->insert(
"cut", TQ_SLOT( cut() ) );
580 s_actionSlotMap->insert(
"copy", TQ_SLOT( copy() ) );
581 s_actionSlotMap->insert(
"paste", TQ_SLOT( paste() ) );
582 s_actionSlotMap->insert(
"rename", TQ_SLOT( rename() ) );
583 s_actionSlotMap->insert(
"trash", TQ_SLOT( trash() ) );
584 s_actionSlotMap->insert(
"del", TQ_SLOT( del() ) );
585 s_actionSlotMap->insert(
"properties", TQ_SLOT( properties() ) );
586 s_actionSlotMap->insert(
"editMimeType", TQ_SLOT( editMimeType() ) );
587 s_actionSlotMap->insert(
"print", TQ_SLOT( print() ) );
595 assert(!s_actionNumberMap);
596 s_actionNumberMap = actionNumberMapsd.setObject( s_actionNumberMap,
new ActionNumberMap );
597 ActionSlotMap::ConstIterator it = s_actionSlotMap->begin();
598 ActionSlotMap::ConstIterator itEnd = s_actionSlotMap->end();
599 for (
int i=0 ; it != itEnd ; ++it, ++i )
602 s_actionNumberMap->insert( it.key(), i );
608 if ( !obj || obj->childrenListObject().isEmpty() )
613 const TQObjectList children = obj->childrenListObject();
614 TQObjectListIt it( children );
615 for (; it.current(); ++it )
616 if ( it.current()->inherits(
"KParts::BrowserExtension" ) )
625class BrowserHostExtension::BrowserHostExtensionPrivate
628 BrowserHostExtensionPrivate()
631 ~BrowserHostExtensionPrivate()
635 KParts::ReadOnlyPart *m_part;
640BrowserHostExtension::BrowserHostExtension( KParts::ReadOnlyPart *parent,
const char *name )
641 : TQObject( parent,
name )
643 d =
new BrowserHostExtensionPrivate;
647BrowserHostExtension::~BrowserHostExtension()
654 return TQStringList();
659 return TQPtrList<KParts::ReadOnlyPart>();
669 if ( !obj || obj->childrenListObject().isEmpty() )
674 const TQObjectList children = obj->childrenListObject();
675 TQObjectListIt it( children );
676 for (; it.current(); ++it )
677 if ( it.current()->inherits(
"KParts::BrowserHostExtension" ) )
683void BrowserExtension::virtual_hook(
int,
void* )
689 FindFrameParentParams param;
691 param.callingPart = callingPart;
693 virtual_hook(VIRTUAL_FIND_FRAME_PARENT, ¶m);
697void BrowserHostExtension::virtual_hook(
int,
void* )
700LiveConnectExtension::LiveConnectExtension(
KParts::ReadOnlyPart *parent,
const char *name ) : TQObject( parent, name) {}
718 if ( !obj || obj->childrenListObject().isEmpty() )
723 const TQObjectList children = obj->childrenListObject();
724 TQObjectListIt it( children );
725 for (; it.current(); ++it )
726 if ( it.current()->inherits(
"KParts::LiveConnectExtension" ) )
732#include "browserextension.moc"
static int questionYesNo(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const KGuiItem &buttonYes=KStdGuiItem::yes(), const KGuiItem &buttonNo=KStdGuiItem::no(), const TQString &dontAskAgainName=TQString::null, int options=Notify)
static void sorry(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, int options=Notify)
The Browser Extension is an extension (yes, no kidding) to KParts::ReadOnlyPart, which allows a bette...
void pasteRequest()
Asks the hosting browser to perform a paste (using openURLRequestDelayed).
virtual int xOffset()
Returns the current x offset.
URLArgs urlArgs() const
Retrieve the set of parameters to use for opening the URL (this must be called from openURL() in the ...
static ActionSlotMap * actionSlotMapPtr()
void enableAction(const char *name, bool enabled)
Enables or disable a standard action held by the browser.
virtual void setURLArgs(const URLArgs &args)
Set the parameters to use for opening the next URL.
BrowserExtension(KParts::ReadOnlyPart *parent, const char *name=0L)
Constructor.
bool isActionEnabled(const char *name) const
bool isURLDropHandlingEnabled() const
Returns whether url drop handling is enabled.
static BrowserExtension * childObject(TQObject *obj)
Queries obj for a child object which inherits from this BrowserExtension class.
static ActionSlotMap actionSlotMap()
Returns a map containing the action names as keys and corresponding TQ_SLOT()'ified method names as d...
virtual void restoreState(TQDataStream &stream)
Used by the browser to restore the view in the state it was when we left it.
virtual void saveState(TQDataStream &stream)
Used by the browser to save the current state of the view (in order to restore it if going back in na...
TQString actionText(const char *name) const
virtual int yOffset()
Returns the current y offset.
void openURLRequestDelayed(const KURL &url, const KParts::URLArgs &args=KParts::URLArgs())
This signal is emitted when openURLRequest is called, after a 0-seconds timer.
void openURLRequest(const KURL &url, const KParts::URLArgs &args=KParts::URLArgs())
Asks the host (browser) to open url.
void setURLDropHandlingEnabled(bool enable)
Enables or disables url drop handling.
void setActionText(const char *name, const TQString &text)
Change the text of a standard action held by the browser.
An extension class for container parts, i.e.
virtual bool openURLInFrame(const KURL &url, const KParts::URLArgs &urlArgs)
Opens the given url in a hosted child frame.
virtual const TQPtrList< KParts::ReadOnlyPart > frames() const
Returns a list of pointers to all hosted child objects.
virtual TQStringList frameNames() const
Returns a list of the names of all hosted child objects.
BrowserHostExtension * findFrameParent(KParts::ReadOnlyPart *callingPart, const TQString &frame)
Returns the part that contains frame and that may be accessed by callingPart.
static BrowserHostExtension * childObject(TQObject *obj)
Queries obj for a child object which inherits from this BrowserHostExtension class.
The purpose of this interface is to allow a direct communication between a KPart and the hosting brow...
Base class for all KParts events.
An extension class for LiveConnect, i.e. a call from JavaScript from a HTML page which embeds this pa...
virtual void unregister(const unsigned long objid)
notifies the part that there is no reference anymore to objid
virtual bool put(const unsigned long objid, const TQString &field, const TQString &value)
put a field value in objid, return true on success
virtual bool get(const unsigned long objid, const TQString &field, Type &type, unsigned long &retobjid, TQString &value)
get a field value from objid, return true on success
virtual bool call(const unsigned long objid, const TQString &func, const TQStringList &args, Type &type, unsigned long &retobjid, TQString &value)
calls a function of objid, return true on success
Base class for any "viewer" part.
kdbgstream kdWarning(int area=0)
kndbgstream & endl(kndbgstream &s)
kdbgstream kdDebug(int area=0)
TQString name(StdAccel id)
URLArgs is a set of arguments bundled into a structure, to allow specifying how a URL should be opene...
void setContentType(const TQString &contentType)
TDEHTML-specific field, header defining the type of the POST data.
TQStringList docState
This buffer can be used by the part to save and restore its contents.
TQString contentType() const
TDEHTML-specific field, header defining the type of the POST data.
void setNewTab(bool newTab)
Whether the URL should be opened in a new tab instead in a new window.
int xOffset
xOffset is the horizontal scrolling of the part's widget (in case it's a scrollview).
void setDoPost(bool enable)
TDEHTML-specific field, whether to do a POST instead of a GET, for the next openURL.
bool redirectedRequest() const
TQMap< TQString, TQString > & metaData()
Meta-data to associate with the next TDEIO operation.
TQString frameName
The frame in which to open the URL.
void setLockHistory(bool lock)
Whether to lock the history when opening the next URL.
bool reload
reload is set when the cache shouldn't be used (forced reload).
bool doPost() const
TDEHTML-specific field, whether to do a POST instead of a GET, for the next openURL.
void setRedirectedRequest(bool redirected)
Set the redirect flag to indicate URL is a result of either a META redirect or HTTP redirect.
int yOffset
yOffset vertical scrolling position, xOffset.
TQString serviceType
The servicetype (usually mimetype) to use when opening the next URL.
void setForcesNewWindow(bool forcesNewWindow)
Set 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.
TQByteArray postData
TDEHTML-specific field, contents of the HTTP POST data.
bool trustedSource
If true, the part who asks for a URL to be opened can be 'trusted' to execute applications.
The WindowArgs are used to specify arguments to the "create new window" call (see the createNewWindow...