1/* This file is part of the KDE project
2 Copyright (C) 1999 Simon Hausmann <hausmann@kde.org>
3 David Faure <faure@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#ifndef __kparts_browserextension_h__
22#define __kparts_browserextension_h__
23
24#include <sys/types.h>
25
26#include <kparts/part.h>
27#include <kparts/event.h>
28
29#include <QtCore/QSharedDataPointer>
30
31template <class T1, class T2> struct QPair;
32template<typename T> class Q3PtrList;
33template <class Key, class T> class QMap;
34template<typename T> class QList;
35
36class KFileItem;
37class KFileItemList;
38class QDataStream;
39class QPoint;
40class QString;
41class QStringList;
42
43namespace KParts {
44
45class BrowserInterface;
46
47struct BrowserArgumentsPrivate;
48
49/**
50 * BrowserArguments is a set of web-browsing-specific arguments,
51 * which allow specifying how a URL should be opened by openUrl()
52 * (as a complement to KParts::OpenUrlArguments which are the non-web-specific arguments)
53 *
54 * The arguments remain stored in the browser extension after that,
55 * and can be used for instance to jump to the xOffset/yOffset position
56 * once the url has finished loading.
57 *
58 * The parts (with a browser extension) who care about urlargs will
59 * use those arguments, others will ignore them.
60 *
61 * This can also be used the other way round, when a part asks
62 * for a URL to be opened (with openUrlRequest or createNewWindow).
63 */
64struct KPARTS_EXPORT BrowserArguments
65{
66 BrowserArguments();
67 BrowserArguments( const BrowserArguments &args );
68 BrowserArguments &operator=( const BrowserArguments &args);
69
70 virtual ~BrowserArguments();
71
72 // KDE4: a struct has the problem that the stuff added after BC-freeze uses methods
73 // so it looks inconsistent with the member vars. -> better use methods for everything,
74 // even if they are inline.
75
76
77 /**
78 * This buffer can be used by the part to save and restore its contents.
79 * See KHTMLPart for instance.
80 */
81 QStringList docState;
82
83 /**
84 * @p softReload is set when user just hits reload button. It's used
85 * currently for two different frameset reload strategies. In case of
86 * soft reload individual frames are reloaded instead of reloading whole
87 * frameset.
88 */
89 bool softReload;
90
91 /**
92 * KHTML-specific field, contents of the HTTP POST data.
93 */
94 QByteArray postData;
95
96 /**
97 * KHTML-specific field, header defining the type of the POST data.
98 */
99 void setContentType( const QString & contentType );
100 /**
101 * KHTML-specific field, header defining the type of the POST data.
102 */
103 QString contentType() const;
104 /**
105 * KHTML-specific field, whether to do a POST instead of a GET,
106 * for the next openURL.
107 */
108 void setDoPost( bool enable );
109
110 /**
111 * KHTML-specific field, whether to do a POST instead of a GET,
112 * for the next openURL.
113 */
114 bool doPost() const;
115
116 /**
117 * Whether to lock the history when opening the next URL.
118 * This is used during e.g. a redirection, to avoid a new entry
119 * in the history.
120 */
121 void setLockHistory( bool lock );
122 bool lockHistory() const;
123
124 /**
125 * Whether the URL should be opened in a new tab instead in a new window.
126 */
127 void setNewTab( bool newTab );
128 bool newTab() const;
129
130 /**
131 * The frame in which to open the URL. KHTML/Konqueror-specific.
132 */
133 QString frameName;
134
135 /**
136 * If true, the part who asks for a URL to be opened can be 'trusted'
137 * to execute applications. For instance, the directory views can be
138 * 'trusted' whereas HTML pages are not trusted in that respect.
139 */
140 bool trustedSource;
141
142 /**
143 * @return true if the request was a result of a META refresh/redirect request or
144 * HTTP redirect.
145 */
146 bool redirectedRequest () const;
147
148 /**
149 * Set the redirect flag to indicate URL is a result of either a META redirect
150 * or HTTP redirect.
151 *
152 * @param redirected
153 */
154 void setRedirectedRequest(bool redirected);
155
156 /**
157 * Set whether the URL specifies to be opened in a new window.
158 *
159 * When openUrlRequest is emitted:
160 * <ul>
161 * <li>normally the url would be opened in the current view.</li>
162 * <li>setForcesNewWindow(true) specifies that a new window or tab should be used:
163 * setNewTab(true) requests a tab specifically, otherwise the user-preference is followed.
164 * This is typically used for target="_blank" in web browsers.</li>
165 * </ul>
166 *
167 * When createNewWindow is emitted:
168 * <ul>
169 * <li>if setNewTab(true) was called, a tab is created.</li>
170 * <li>otherwise, if setForcesNewWindow(true) was called, a window is created.</li>
171 * <li>otherwise the user preference is followed.</li>
172 * </ul>
173 */
174 void setForcesNewWindow( bool forcesNewWindow );
175
176 /**
177 * Whether the URL specifies to be opened in a new window
178 */
179 bool forcesNewWindow() const;
180
181private:
182 BrowserArgumentsPrivate *d;
183};
184
185class WindowArgsPrivate;
186
187/**
188 * The WindowArgs are used to specify arguments to the "create new window"
189 * call (see the createNewWindow variant that uses WindowArgs).
190 * The primary reason for this is the javascript window.open function.
191 */
192class KPARTS_EXPORT WindowArgs
193{
194public:
195 WindowArgs();
196 ~WindowArgs();
197 WindowArgs( const WindowArgs &args );
198 WindowArgs &operator=( const WindowArgs &args );
199 WindowArgs( const QRect &_geometry, bool _fullscreen, bool _menuBarVisible,
200 bool _toolBarsVisible, bool _statusBarVisible, bool _resizable );
201 WindowArgs( int _x, int _y, int _width, int _height, bool _fullscreen,
202 bool _menuBarVisible, bool _toolBarsVisible,
203 bool _statusBarVisible, bool _resizable );
204
205 void setX(int x);
206 int x() const;
207
208 void setY(int y);
209 int y() const;
210
211 void setWidth(int w);
212 int width() const;
213
214 void setHeight(int h);
215 int height() const;
216
217 void setFullScreen(bool fs);
218 bool isFullScreen() const;
219
220 void setMenuBarVisible(bool visible);
221 bool isMenuBarVisible() const;
222
223 void setToolBarsVisible(bool visible);
224 bool toolBarsVisible() const;
225
226 void setStatusBarVisible(bool visible);
227 bool isStatusBarVisible() const;
228
229 void setResizable(bool resizable);
230 bool isResizable() const;
231
232 void setLowerWindow(bool lower);
233 bool lowerWindow() const;
234
235 void setScrollBarsVisible(bool visible);
236 bool scrollBarsVisible() const;
237
238private:
239 QSharedDataPointer<WindowArgsPrivate> d;
240};
241
242/**
243 * The KParts::OpenUrlEvent event informs that a given part has opened a given URL.
244 * Applications can use this event to send this information to interested plugins.
245 *
246 * The event should be sent before opening the URL in the part, so that the plugins
247 * can use part()->url() to get the old URL.
248 */
249class KPARTS_EXPORT OpenUrlEvent : public Event
250{
251public:
252 OpenUrlEvent( ReadOnlyPart *part, const KUrl &url,
253 const OpenUrlArguments& args = OpenUrlArguments(),
254 const BrowserArguments& browserArgs = BrowserArguments() );
255 virtual ~OpenUrlEvent();
256
257 ReadOnlyPart *part() const;
258 KUrl url() const;
259 OpenUrlArguments arguments() const;
260 BrowserArguments browserArguments() const;
261
262 static bool test( const QEvent *event );
263
264private:
265 class OpenUrlEventPrivate;
266 OpenUrlEventPrivate * const d;
267};
268
269 /**
270 * The Browser Extension is an extension (yes, no kidding) to
271 * KParts::ReadOnlyPart, which allows a better integration of parts
272 * with browsers (in particular Konqueror).
273 * Remember that ReadOnlyPart only has openUrl(KUrl) and a few arguments() but not much more.
274 * For full-fledged browsing, we need much more than that, including
275 * enabling/disabling of standard actions (print, copy, paste...),
276 * allowing parts to save and restore their data into the back/forward history,
277 * allowing parts to control the location bar URL, to requests URLs
278 * to be opened by the hosting browser, etc.
279 *
280 * The part developer needs to define its own class derived from BrowserExtension,
281 * to implement the virtual methods [and the standard-actions slots, see below].
282 *
283 * The way to associate the BrowserExtension with the part is to simply
284 * create the BrowserExtension as a child of the part (in QObject's terms).
285 * The hosting application will look for it automatically.
286 *
287 * Another aspect of the browser integration is that a set of standard
288 * actions are provided by the browser, but implemented by the part
289 * (for the actions it supports).
290 *
291 * The following standard actions are defined by the host of the view:
292 *
293 * [selection-dependent actions]
294 * @li @p cut : Copy selected items to clipboard and store 'not cut' in clipboard.
295 * @li @p copy : Copy selected items to clipboard and store 'cut' in clipboard.
296 * @li @p paste : Paste clipboard into view URL.
297 * @li @p pasteTo(const KUrl &) : Paste clipboard into given URL.
298 * @li @p searchProvider : Lookup selected text at default search provider
299 *
300 * [normal actions]
301 * @li None anymore.
302 *
303 *
304 * The view defines a slot with the name of the action in order to implement the action.
305 * The browser will detect the slot automatically and connect its action to it when
306 * appropriate (i.e. when the view is active).
307 *
308 *
309 * The selection-dependent actions are disabled by default and the view should
310 * enable them when the selection changes, emitting enableAction().
311 *
312 * The normal actions do not depend on the selection.
313 *
314 * A special case is the configuration slots, not connected to any action directly.
315 *
316 * [configuration slot]
317 * @li @p reparseConfiguration : Re-read configuration and apply it.
318 * @li @p disableScrolling: no scrollbars
319 */
320class KPARTS_EXPORT BrowserExtension : public QObject
321{
322 Q_OBJECT
323 Q_PROPERTY( bool urlDropHandling READ isURLDropHandlingEnabled WRITE setURLDropHandlingEnabled )
324public:
325 /**
326 * Constructor
327 *
328 * @param parent The KParts::ReadOnlyPart that this extension ... "extends" :)
329 */
330 explicit BrowserExtension( KParts::ReadOnlyPart *parent );
331
332
333 virtual ~BrowserExtension();
334
335 /**
336 * Set of flags passed via the popupMenu signal, to ask for some items in the popup menu.
337 */
338 enum PopupFlag {
339 DefaultPopupItems=0x0000, /**< default value, no additional menu item */
340 ShowNavigationItems=0x0001, /**< show "back" and "forward" (usually done when clicking the background of the view, but not an item) */
341 ShowUp=0x0002, /**< show "up" (same thing, but not over e.g. HTTP). Requires ShowNavigationItems. */
342 ShowReload=0x0004, /**< show "reload" (usually done when clicking the background of the view, but not an item) */
343 ShowBookmark=0x0008, /**< show "add to bookmarks" (usually not done on the local filesystem) */
344 ShowCreateDirectory=0x0010, /**< show "create directory" (usually only done on the background of the view, or
345 * in hierarchical views like directory trees, where the new dir would be visible) */
346 ShowTextSelectionItems=0x0020, /**< set when selecting text, for a popup that only contains text-related items. */
347 NoDeletion=0x0040, /**< deletion, trashing and renaming not allowed (e.g. parent dir not writeable).
348 * (this is only needed if the protocol itself supports deletion, unlike e.g. HTTP) */
349 IsLink=0x0080, /**< show "Bookmark This Link" and other link-related actions (linkactions merging group) */
350 ShowUrlOperations=0x0100, /**< show copy, paste, as well as cut if NoDeletion is not set. */
351 ShowProperties=0x200 /**< show "Properties" action (usually done by directory views) */
352 };
353
354 Q_DECLARE_FLAGS( PopupFlags, PopupFlag )
355
356 /**
357 * Set the parameters to use for opening the next URL.
358 * This is called by the "hosting" application, to pass parameters to the part.
359 * @see BrowserArguments
360 */
361 virtual void setBrowserArguments( const BrowserArguments &args );
362
363 /**
364 * Retrieve the set of parameters to use for opening the URL
365 * (this must be called from openUrl() in the part).
366 * @see BrowserArguments
367 */
368 BrowserArguments browserArguments() const;
369
370 /**
371 * Returns the current x offset.
372 *
373 * For a scrollview, implement this using contentsX().
374 */
375 virtual int xOffset();
376 /**
377 * Returns the current y offset.
378 *
379 * For a scrollview, implement this using contentsY().
380 */
381 virtual int yOffset();
382
383 /**
384 * Used by the browser to save the current state of the view
385 * (in order to restore it if going back in navigation).
386 *
387 * If you want to save additional properties, reimplement it
388 * but don't forget to call the parent method (probably first).
389 */
390 virtual void saveState( QDataStream &stream );
391
392 /**
393 * Used by the browser to restore the view in the state
394 * it was when we left it.
395 *
396 * If you saved additional properties, reimplement it
397 * but don't forget to call the parent method (probably first).
398 */
399 virtual void restoreState( QDataStream &stream );
400
401 /**
402 * Returns whether url drop handling is enabled.
403 * See setURLDropHandlingEnabled for more information about this
404 * property.
405 */
406 bool isURLDropHandlingEnabled() const;
407
408 /**
409 * Enables or disables url drop handling. URL drop handling is a property
410 * describing whether the hosting shell component is allowed to install an
411 * event filter on the part's widget, to listen for URI drop events.
412 * Set it to true if you are exporting a BrowserExtension implementation and
413 * do not provide any special URI drop handling. If set to false you can be
414 * sure to receive all those URI drop events unfiltered. Also note that the
415 * implementation as of Konqueror installs the event filter only on the part's
416 * widget itself, not on child widgets.
417 */
418 void setURLDropHandlingEnabled( bool enable );
419
420 void setBrowserInterface( BrowserInterface *impl );
421 BrowserInterface *browserInterface() const;
422
423 /**
424 * @return the status (enabled/disabled) of an action.
425 * When the enableAction signal is emitted, the browserextension
426 * stores the status of the action internally, so that it's possible
427 * to query later for the status of the action, using this method.
428 */
429 bool isActionEnabled( const char * name ) const;
430
431 /**
432 * @return the text of an action, if it was set explicitly by the part.
433 * When the setActionText signal is emitted, the browserextension
434 * stores the text of the action internally, so that it's possible
435 * to query later for the text of the action, using this method.
436 */
437 QString actionText( const char * name ) const;
438
439 typedef QMap<QByteArray,QByteArray> ActionSlotMap;
440 /**
441 * Returns a map containing the action names as keys and corresponding
442 * SLOT()'ified method names as data entries.
443 *
444 * This is very useful for
445 * the host component, when connecting the own signals with the
446 * extension's slots.
447 * Basically you iterate over the map, check if the extension implements
448 * the slot and connect to the slot using the data value of your map
449 * iterator.
450 * Checking if the extension implements a certain slot can be done like this:
451 *
452 * \code
453 * extension->metaObject()->slotNames().contains( actionName + "()" )
454 * \endcode
455 *
456 * (note that @p actionName is the iterator's key value if already
457 * iterating over the action slot map, returned by this method)
458 *
459 * Connecting to the slot can be done like this:
460 *
461 * \code
462 * connect( yourObject, SIGNAL( yourSignal() ),
463 * extension, mapIterator.data() )
464 * \endcode
465 *
466 * (where "mapIterator" is your QMap<QCString,QCString> iterator)
467 */
468 static ActionSlotMap actionSlotMap();
469
470 /**
471 * @return a pointer to the static action-slot map. Preferred method to get it.
472 * The map is created if it doesn't exist yet
473 */
474 static ActionSlotMap * actionSlotMapPtr();
475
476 /**
477 * Queries @p obj for a child object which inherits from this
478 * BrowserExtension class. Convenience method.
479 */
480 static BrowserExtension *childObject( QObject *obj );
481
482 /**
483 * Asks the hosting browser to perform a paste (using openUrlRequestDelayed())
484 */
485 void pasteRequest();
486
487 /**
488 * Associates a list of actions with a predefined name known by the host's popupmenu:
489 * "editactions" for actions related text editing,
490 * "linkactions" for actions related to hyperlinks,
491 * "partactions" for any other actions provided by the part
492 */
493 typedef QMap<QString, QList<QAction *> > ActionGroupMap;
494
495Q_SIGNALS:
496#if !defined(Q_MOC_RUN) && !defined(DOXYGEN_SHOULD_SKIP_THIS) && !defined(IN_IDE_PARSER)
497public: // yes, those signals are public; don't tell moc, doxygen or kdevelop :)
498#endif
499 /**
500 * Enables or disable a standard action held by the browser.
501 *
502 * See class documentation for the list of standard actions.
503 */
504 void enableAction( const char * name, bool enabled );
505
506 /**
507 * Change the text of a standard action held by the browser.
508 * This can be used to change "Paste" into "Paste Image" for instance.
509 *
510 * See class documentation for the list of standard actions.
511 */
512 void setActionText( const char * name, const QString& text );
513
514 /**
515 * Asks the host (browser) to open @p url.
516 * To set a reload, the x and y offsets, the service type etc., fill in the
517 * appropriate fields in the @p args structure.
518 * Hosts should not connect to this signal but to openUrlRequestDelayed().
519 */
520 void openUrlRequest( const KUrl &url,
521 const KParts::OpenUrlArguments& arguments = KParts::OpenUrlArguments(),
522 const KParts::BrowserArguments &browserArguments = KParts::BrowserArguments() );
523
524 /**
525 * This signal is emitted when openUrlRequest() is called, after a 0-seconds timer.
526 * This allows the caller to terminate what it's doing first, before (usually)
527 * being destroyed. Parts should never use this signal, hosts should only connect
528 * to this signal.
529 */
530 void openUrlRequestDelayed( const KUrl &url,
531 const KParts::OpenUrlArguments& arguments,
532 const KParts::BrowserArguments &browserArguments );
533
534 /**
535 * Tells the hosting browser that the part opened a new URL (which can be
536 * queried via KParts::Part::url().
537 *
538 * This helps the browser to update/create an entry in the history.
539 * The part may @em not emit this signal together with openUrlRequest().
540 * Emit openUrlRequest() if you want the browser to handle a URL the user
541 * asked to open (from within your part/document). This signal however is
542 * useful if you want to handle URLs all yourself internally, while still
543 * telling the hosting browser about new opened URLs, in order to provide
544 * a proper history functionality to the user.
545 * An example of usage is a html rendering component which wants to emit
546 * this signal when a child frame document changed its URL.
547 * Conclusion: you probably want to use openUrlRequest() instead.
548 */
549 void openUrlNotify();
550
551 /**
552 * Updates the URL shown in the browser's location bar to @p url.
553 */
554 void setLocationBarUrl( const QString &url );
555
556 /**
557 * Sets the URL of an icon for the currently displayed page.
558 */
559 void setIconUrl( const KUrl &url );
560
561 /**
562 * Asks the hosting browser to open a new window for the given @p url
563 * and return a reference to the content part.
564 *
565 * @p arguments is optional additional information about how to open the url,
566 * @see KParts::OpenUrlArguments
567 *
568 * @p browserArguments is optional additional information for web browsers,
569 * @see KParts::BrowserArguments
570 *
571 * The request for a pointer to the part is only fulfilled/processed
572 * if the mimeType is set in the @p browserArguments.
573 * (otherwise the request cannot be processed synchronously).
574 */
575 void createNewWindow( const KUrl &url,
576 const KParts::OpenUrlArguments& arguments = KParts::OpenUrlArguments(),
577 const KParts::BrowserArguments &browserArguments = KParts::BrowserArguments(),
578 const KParts::WindowArgs &windowArgs = KParts::WindowArgs(),
579 KParts::ReadOnlyPart** part = 0 ); // TODO consider moving to BrowserHostExtension?
580
581 /**
582 * Since the part emits the jobid in the started() signal,
583 * progress information is automatically displayed.
584 *
585 * However, if you don't use a KIO::Job in the part,
586 * you can use loadingProgress() and speedProgress()
587 * to display progress information.
588 */
589 void loadingProgress( int percent );
590 /**
591 * @see loadingProgress
592 */
593 void speedProgress( int bytesPerSecond );
594
595 void infoMessage( const QString & );
596
597 /**
598 * Emit this to make the browser show a standard popup menu for the files @p items.
599 *
600 * @param global global coordinates where the popup should be shown
601 * @param items list of file items which the popup applies to
602 * @param args OpenUrlArguments, mostly for metadata here
603 * @param browserArguments BrowserArguments, mostly for referrer
604 * @param flags enables/disables certain builtin actions in the popupmenu
605 * @param actionGroups named groups of actions which should be inserted into the popup, see ActionGroupMap
606 */
607 void popupMenu( const QPoint &global, const KFileItemList &items,
608 const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(),
609 const KParts::BrowserArguments &browserArgs = KParts::BrowserArguments(),
610 KParts::BrowserExtension::PopupFlags flags = KParts::BrowserExtension::DefaultPopupItems,
611 const KParts::BrowserExtension::ActionGroupMap& actionGroups = ActionGroupMap() );
612
613 /**
614 * Emit this to make the browser show a standard popup menu for the given @p url.
615 *
616 * Give as much information about this URL as possible,
617 * like @p args.mimeType and the file type @p mode
618 *
619 * @param global global coordinates where the popup should be shown
620 * @param url the URL this popup applies to
621 * @param mode the file type of the url (S_IFREG, S_IFDIR...)
622 * @param args OpenUrlArguments, set the mimetype of the URL using setMimeType()
623 * @param browserArguments BrowserArguments, mostly for referrer
624 * @param flags enables/disables certain builtin actions in the popupmenu
625 * @param actionGroups named groups of actions which should be inserted into the popup, see ActionGroupMap
626 */
627 void popupMenu( const QPoint &global, const KUrl &url,
628 mode_t mode = static_cast<mode_t>(-1),
629 const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(),
630 const KParts::BrowserArguments &browserArgs = KParts::BrowserArguments(),
631 KParts::BrowserExtension::PopupFlags flags = KParts::BrowserExtension::DefaultPopupItems,
632 const KParts::BrowserExtension::ActionGroupMap& actionGroups = ActionGroupMap() );
633
634 /**
635 * Inform the hosting application about the current selection.
636 * Used when a set of files/URLs is selected (with full information
637 * about those URLs, including size, permissions etc.)
638 */
639 void selectionInfo( const KFileItemList& items );
640 /**
641 * Inform the hosting application about the current selection.
642 * Used when some text is selected.
643 */
644 void selectionInfo( const QString &text );
645 /**
646 * Inform the hosting application about the current selection.
647 * Used when a set of URLs is selected.
648 */
649 void selectionInfo( const KUrl::List &urls );
650
651 /**
652 * Inform the hosting application that the user moved the mouse over an item.
653 * Used when the mouse is on an URL.
654 */
655 void mouseOverInfo( const KFileItem& item );
656
657 /**
658 * Ask the hosting application to add a new HTML (aka Mozilla/Netscape)
659 * SideBar entry.
660 */
661 void addWebSideBar(const KUrl &url, const QString& name);
662
663 /**
664 * Ask the hosting application to move the top level widget.
665 */
666 void moveTopLevelWidget( int x, int y );
667
668 /**
669 * Ask the hosting application to resize the top level widget.
670 */
671 void resizeTopLevelWidget( int w, int h );
672
673 /**
674 * Ask the hosting application to focus @p part.
675 */
676 void requestFocus(KParts::ReadOnlyPart *part);
677
678 /**
679 * Tell the host (browser) about security state of current page
680 * enum PageSecurity { NotCrypted, Encrypted, Mixed };
681 */
682 void setPageSecurity( int );
683
684 /**
685 * Inform the host about items that have been removed.
686 */
687 void itemsRemoved( const KFileItemList &items );
688
689private Q_SLOTS:
690 void slotCompleted();
691 void slotOpenUrlRequest( const KUrl &url,
692 const KParts::OpenUrlArguments& arguments = KParts::OpenUrlArguments(),
693 const KParts::BrowserArguments &browserArguments = KParts::BrowserArguments() );
694
695 void slotEmitOpenUrlRequestDelayed();
696 void slotEnableAction( const char *, bool );
697 void slotSetActionText( const char*, const QString& );
698
699public:
700 typedef QMap<QByteArray,int> ActionNumberMap;
701
702private:
703 class BrowserExtensionPrivate;
704 BrowserExtensionPrivate * const d;
705};
706
707/**
708 * An extension class for container parts, i.e. parts that contain
709 * other parts.
710 * For instance a KHTMLPart hosts one part per frame.
711 */
712class KPARTS_EXPORT BrowserHostExtension : public QObject
713{
714 Q_OBJECT
715public:
716 BrowserHostExtension( KParts::ReadOnlyPart *parent );
717
718 virtual ~BrowserHostExtension();
719
720 /**
721 * Returns a list of the names of all hosted child objects.
722 *
723 * Note that this method does not query the child objects recursively.
724 */
725 virtual QStringList frameNames() const;
726
727 /**
728 * Returns a list of pointers to all hosted child objects.
729 *
730 * Note that this method does not query the child objects recursively.
731 */
732 virtual const QList<KParts::ReadOnlyPart*> frames() const;
733
734 /**
735 * Returns the part that contains @p frame and that may be accessed
736 * by @p callingPart
737 */
738 virtual BrowserHostExtension *findFrameParent(KParts::ReadOnlyPart *callingPart, const QString &frame);
739
740 /**
741 * Opens the given url in a hosted child frame. The frame name is specified in the
742 * frameName variable in the @p browserArguments parameter (see KParts::BrowserArguments ) .
743 */
744 virtual bool openUrlInFrame( const KUrl &url,
745 const KParts::OpenUrlArguments& arguments,
746 const KParts::BrowserArguments &browserArguments );
747
748 /**
749 * Queries @p obj for a child object which inherits from this
750 * BrowserHostExtension class. Convenience method.
751 */
752 static BrowserHostExtension *childObject( QObject *obj );
753
754private:
755 class BrowserHostExtensionPrivate;
756 BrowserHostExtensionPrivate * const d;
757};
758
759/**
760 * An extension class for LiveConnect, i.e. a call from JavaScript
761 * from a HTML page which embeds this part.
762 * A part can have an object hierarchy by using objid as a reference
763 * to an object.
764 */
765class KPARTS_EXPORT LiveConnectExtension : public QObject
766{
767 Q_OBJECT
768public:
769 enum Type {
770 TypeVoid=0, TypeBool, TypeFunction, TypeNumber, TypeObject, TypeString
771 };
772 typedef QList<QPair<Type, QString> > ArgList;
773
774 LiveConnectExtension( KParts::ReadOnlyPart *parent );
775
776 virtual ~LiveConnectExtension();
777 /**
778 * get a field value from objid, return true on success
779 */
780 virtual bool get( const unsigned long objid, const QString & field, Type & type, unsigned long & retobjid, QString & value );
781 /**
782 * put a field value in objid, return true on success
783 */
784 virtual bool put( const unsigned long objid, const QString & field, const QString & value );
785 /**
786 * calls a function of objid, return true on success
787 */
788 virtual bool call( const unsigned long objid, const QString & func, const QStringList & args, Type & type, unsigned long & retobjid, QString & value );
789 /**
790 * notifies the part that there is no reference anymore to objid
791 */
792 virtual void unregister( const unsigned long objid );
793
794 static LiveConnectExtension *childObject( QObject *obj );
795Q_SIGNALS:
796#if !defined(Q_MOC_RUN) && !defined(DOXYGEN_SHOULD_SKIP_THIS) && !defined(IN_IDE_PARSER)
797public: // yes, those signals are public; don't tell moc, doxygen or kdevelop :)
798#endif
799 /**
800 * notify a event from the part of object objid
801 */
802 void partEvent( const unsigned long objid, const QString & event, const KParts::LiveConnectExtension::ArgList & args );
803
804private:
805 class LiveConnectExtensionPrivate;
806 LiveConnectExtensionPrivate * const d;
807};
808
809}
810
811Q_DECLARE_OPERATORS_FOR_FLAGS( KParts::BrowserExtension::PopupFlags )
812
813#endif
814
815