2 This file is part of the KDE project
3 Copyright (C) 1998, 1999 Simon Hausmann <hausmann@kde.org>
4 Copyright (C) 2000-2004 David Faure <faure@kde.org>
5 Copyright (C) 2007 Eduardo Robles Elvira <edulix@gmail.com>
6 Copyright (C) 2007 Daniel GarcĂa Moreno <danigm@gmail.com>
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
24 #ifndef KONQMAINWINDOW_H
25 #define KONQMAINWINDOW_H
27 #include "konqprivate_export.h"
29 #include <QtCore/QMap>
30 #include <QtCore/QPointer>
31 #include <QtCore/QList>
33 #include <kfileitem.h>
35 #include "konqopenurlrequest.h"
36 #include <kparts/mainwindow.h>
37 #include <kglobalsettings.h>
39 #include "konqcombo.h"
40 #include "konqframe.h"
41 #include "konqframecontainer.h"
45 class KLocalizedString
;
46 class KToggleFullScreenAction
;
47 class KonqUndoManager
;
52 class KActionCollection
;
56 class KBookmarkActionMenu
;
60 class KonqBidiHistoryAction
;
63 class KonqFrameContainerBase
;
64 class KonqFrameContainer
;
65 class KToolBarPopupAction
;
66 class KAnimatedButton
;
67 class KonqViewManager
;
68 class ToggleViewGUIClient
;
69 class KonqMainWindowIface
;
74 class KBookmarkManager
;
78 class BrowserExtension
;
79 class BrowserHostExtension
;
81 class OpenUrlArguments
;
82 struct BrowserArguments
;
85 class KonqExtendedBookmarkOwner
;
88 class KONQ_TESTS_EXPORT KonqMainWindow
: public KParts::MainWindow
, public KonqFrameContainerBase
91 Q_PROPERTY( int viewCount READ viewCount
)
92 Q_PROPERTY( int activeViewsCount READ activeViewsCount
)
93 Q_PROPERTY( int linkableViewsCount READ linkableViewsCount
)
94 Q_PROPERTY( QString locationBarURL READ locationBarURL
)
95 Q_PROPERTY( bool fullScreenMode READ fullScreenMode
)
96 Q_PROPERTY( QString currentTitle READ currentTitle
)
97 Q_PROPERTY( QString currentURL READ currentURL
)
98 Q_PROPERTY( bool isHTMLAllowed READ isHTMLAllowed
)
99 Q_PROPERTY( QString currentProfile READ currentProfile
)
101 enum ComboAction
{ ComboClear
, ComboAdd
, ComboRemove
};
102 enum PageSecurity
{ NotCrypted
, Encrypted
, Mixed
};
104 // TODO remove xmluiFile argument, this solution can't work for session management,
105 // see readProperties.
107 explicit KonqMainWindow(const KUrl
&initialURL
= KUrl(),
108 const QString
& xmluiFile
= "konqueror.rc");
112 * Filters the URL and calls the main openUrl method.
114 void openFilteredUrl(const QString
& url
, const KonqOpenURLRequest
& req
);
117 * Convenience overload for openFilteredUrl(url, req)
119 void openFilteredUrl(const QString
& url
, bool inNewTab
= false, bool tempFile
= false);
123 * The main openUrl method.
125 void openUrl(KonqView
* view
, const KUrl
& url
,
126 const QString
&serviceType
= QString(),
127 const KonqOpenURLRequest
& req
= KonqOpenURLRequest::null
,
128 bool trustedSource
= false); // trustedSource should be part of KonqOpenURLRequest, probably
132 * Called by openUrl when it knows the mime type (either directly,
134 * \param mimeType the mimetype of the URL to open. Always set.
135 * \param url the URL to open.
136 * \param childView the view in which to open the URL. Can be 0, in which
137 * case a new tab (or the very first view) will be created.
139 bool openView(QString mimeType
, const KUrl
& url
, KonqView
*childView
,
140 const KonqOpenURLRequest
& req
= KonqOpenURLRequest::null
);
145 void openMultiURL( const KUrl::List
& url
);
147 /// Returns the view manager for this window.
148 KonqViewManager
*viewManager() const { return m_pViewManager
; }
150 /// KXMLGUIBuilder methods, reimplemented for delayed bookmark-toolbar initialization
151 virtual QWidget
*createContainer( QWidget
*parent
, int index
, const QDomElement
&element
, QAction
* &containerAction
);
152 virtual void removeContainer( QWidget
*container
, QWidget
*parent
, QDomElement
&element
, QAction
* containerAction
);
154 /// KMainWindow methods, for session management
155 virtual void saveProperties( KConfigGroup
& config
);
156 virtual void readProperties( const KConfigGroup
& config
);
158 void setInitialFrameName( const QString
&name
);
160 void reparseConfiguration();
162 /// Called by KonqViewManager
163 void insertChildView(KonqView
*childView
);
164 /// Called by KonqViewManager
165 void removeChildView(KonqView
*childView
);
167 KonqView
*childView( KParts::ReadOnlyPart
*view
);
168 KonqView
*childView( KParts::ReadOnlyPart
*callingPart
, const QString
&name
, KParts::BrowserHostExtension
*&hostExtension
, KParts::ReadOnlyPart
**part
);
170 // Total number of views
171 int viewCount() const { return m_mapViews
.count(); }
173 // Number of views not in "passive" mode
174 int activeViewsCount() const;
176 // Number of views not in "passive" mode and not locked
177 int activeViewsNotLockedCount() const;
179 // Number of views that can be linked, i.e. not with "follow active view" behavior
180 int linkableViewsCount() const;
182 // Number of main views (non-toggle non-passive views)
183 int mainViewsCount() const;
185 // Return true if we are showing a view that supports this mimeType.
186 bool hasViewWithMimeType(const QString
& mimeType
) const;
188 typedef QMap
<KParts::ReadOnlyPart
*, KonqView
*> MapViews
;
190 const MapViews
& viewMap() const { return m_mapViews
; }
192 KonqView
*currentView() const;
194 /** URL of current part, or URLs of selected items for directory views */
195 KUrl::List
currentURLs() const;
197 // Only valid if there are one or two views
198 KonqView
* otherView( KonqView
* view
) const;
200 /// Overloaded of KMainWindow
201 virtual void setCaption( const QString
&caption
);
202 /// Overloaded of KMainWindow -- should never be called, or if it is, we ignore "modified" anyway
203 virtual void setCaption( const QString
&caption
, bool modified
) {
205 return setCaption(caption
);
209 * Change URL displayed in the location bar
211 void setLocationBarURL( const QString
&url
);
213 * Overload for convenience
215 void setLocationBarURL( const KUrl
&url
);
217 * Return URL displayed in the location bar - for KonqViewManager
219 QString
locationBarURL() const;
220 void focusLocationBar();
223 * Set page security related to current view
225 void setPageSecurity( PageSecurity
);
227 void enableAllActions( bool enable
);
229 void disableActionsNoView();
231 void updateToolBarActions( bool pendingActions
= false );
232 void updateOpenWithActions();
233 void updateViewActions();
235 bool sidebarVisible() const;
237 void setShowHTML( bool b
);
239 void showHTML( KonqView
* view
, bool b
, bool _activateView
);
241 bool fullScreenMode() const;
244 * @return the "link view" action, for checking/unchecking from KonqView
246 KToggleAction
* linkViewAction()const { return m_paLinkView
; }
248 void enableAction( const char * name
, bool enabled
);
249 void setActionText( const char * name
, const QString
& text
);
252 * The default settings "allow HTML" - the one used when creating a new view
253 * Might not match the current view !
255 bool isHTMLAllowed() const { return m_bHTMLAllowed
; }
257 static QList
<KonqMainWindow
*> *mainWindowList() { return s_lstViews
; }
259 // public for konq_guiclients
260 void viewCountChanged();
263 * For the view manager: we are loading the profile from this config file,
264 * so we should save mainwindow settings into that file from now on
266 void setProfileConfig(const KConfigGroup
& cfg
);
267 void currentProfileChanged();
269 // operates on all combos of all mainwindows of this instance
270 // up to now adds an entry or clears all entries
271 static void comboAction( int action
, const QString
& url
,
272 const QString
& senderId
);
278 // KonqFrameContainerBase implementation BEGIN
280 virtual bool accept( KonqFrameVisitor
* visitor
);
283 * Insert a new frame as the mainwindow's child
285 virtual void insertChildFrame(KonqFrameBase
* frame
, int index
= -1 );
287 * Call this before deleting one of our children.
289 virtual void childFrameRemoved( KonqFrameBase
* frame
);
291 void saveConfig( KConfigGroup
& config
, const QString
&prefix
, const KonqFrameBase::Options
&options
, KonqFrameBase
* docContainer
, int id
= 0, int depth
= 0 );
293 void copyHistory( KonqFrameBase
*other
);
295 void setTitle( const QString
&title
, QWidget
* sender
);
296 void setTabIcon( const KUrl
&url
, QWidget
* sender
);
298 QWidget
* asQWidget();
300 KonqFrameBase::FrameType
frameType() const;
302 KonqFrameBase
* childFrame()const;
304 void setActiveChild( KonqFrameBase
* activeChild
);
306 // KonqFrameContainerBase implementation END
308 KonqFrameBase
* workingTab()const { return m_pWorkingTab
; }
309 void setWorkingTab( KonqFrameBase
* tab
) { m_pWorkingTab
= tab
; }
311 static bool isMimeTypeAssociatedWithSelf( const QString
&mimeType
);
312 static bool isMimeTypeAssociatedWithSelf( const QString
&mimeType
, const KService::Ptr
&offer
);
314 bool refuseExecutingKonqueror(const QString
& mimeType
);
318 // TODO: move to a KonqPreloadHandler class
319 static void setPreloadedFlag( bool preloaded
);
320 static bool isPreloaded() { return s_preloaded
; }
321 static void setPreloadedWindow( KonqMainWindow
* );
322 static KonqMainWindow
* preloadedWindow() { return s_preloadedWindow
; }
324 QString
currentTitle() const;
325 // Not used by konqueror itself; only exists for the Q_PROPERTY,
326 // which I guess is used by scripts and plugins...
327 QString
currentURL() const;
328 QString
currentProfile() const;
329 void applyWindowSizeFromProfile(const KConfigGroup
& profileGroup
);
331 void updateHistoryActions();
333 // Public for unit tests
334 void prepareForPopupMenu(const KFileItemList
&items
, const KParts::OpenUrlArguments
&args
, const KParts::BrowserArguments
& browserArgs
);
337 void viewAdded( KonqView
*view
);
338 void viewRemoved( KonqView
*view
);
339 void popupItemsDisturbed();
342 void updateViewModeActions();
344 void slotInternalViewModeChanged();
346 void slotCtrlTabPressed();
348 void slotPopupMenu( const QPoint
&global
, const KFileItemList
&items
, const KParts::OpenUrlArguments
&args
, const KParts::BrowserArguments
& browserArgs
, KParts::BrowserExtension::PopupFlags flags
, const KParts::BrowserExtension::ActionGroupMap
& );
349 void slotPopupMenu( const QPoint
&global
, const KUrl
&url
, mode_t mode
, const KParts::OpenUrlArguments
&args
, const KParts::BrowserArguments
& browserArgs
, KParts::BrowserExtension::PopupFlags f
, const KParts::BrowserExtension::ActionGroupMap
& );
352 * __NEEEEVER__ call this method directly. It relies on sender() (the part)
354 void slotOpenURLRequest( const KUrl
&url
, const KParts::OpenUrlArguments
& args
, const KParts::BrowserArguments
&browserArgs
);
356 void openUrlRequestHelper( KonqView
*childView
, const KUrl
&url
, const KParts::OpenUrlArguments
& args
, const KParts::BrowserArguments
&browserArgs
);
358 void slotCreateNewWindow( const KUrl
&url
, const KParts::OpenUrlArguments
& args
, const KParts::BrowserArguments
&browserArgs
,
359 const KParts::WindowArgs
&windowArgs
= KParts::WindowArgs(),
360 KParts::ReadOnlyPart
**part
= 0 );
362 void slotNewWindow();
363 void slotDuplicateWindow();
366 void slotCopyFiles();
367 void slotMoveFiles();
368 void slotOpenLocation();
372 void slotViewModeTriggered(QAction
* action
);
376 void slotReload( KonqView
* view
= 0L, bool softReload
= true );
377 void slotForceReload();
382 void slotUp(Qt::MouseButtons buttons
, Qt::KeyboardModifiers modifiers
);
383 void slotUpDelayed();
385 void slotBack(Qt::MouseButtons buttons
, Qt::KeyboardModifiers modifiers
);
387 void slotForward(Qt::MouseButtons buttons
, Qt::KeyboardModifiers modifiers
);
389 void slotHome(Qt::MouseButtons buttons
, Qt::KeyboardModifiers modifiers
);
390 void slotGoHistory();
392 void slotAddClosedUrl(KonqFrameBase
*tab
);
394 void slotConfigure();
395 void slotConfigureDone();
396 void slotConfigureToolbars();
397 void slotConfigureExtensions();
398 void slotConfigureSpellChecking();
399 void slotNewToolbarConfig();
401 void slotUndoAvailable( bool avail
);
403 void slotPartChanged( KonqView
*childView
, KParts::ReadOnlyPart
*oldPart
, KParts::ReadOnlyPart
*newPart
);
405 void slotRunFinished();
406 void slotClearLocationBar();
408 // reimplement from KParts::MainWindow
409 virtual void slotSetStatusBarText( const QString
&text
);
411 // public for KonqViewManager
412 void slotPartActivated( KParts::Part
*part
);
414 void slotGoHistoryActivated( int steps
);
415 void slotGoHistoryActivated( int steps
, Qt::MouseButtons buttons
, Qt::KeyboardModifiers modifiers
);
418 void slotSplitViewHorizontal();
419 void slotSplitViewVertical();
420 void slotRemoveOtherTabs();
421 void slotRemoveOtherTabsPopupDelayed();
424 void slotViewCompleted( KonqView
* view
);
426 void slotURLEntered(const QString
&text
, Qt::KeyboardModifiers
);
428 void slotLocationLabelActivated();
430 void slotDuplicateTab();
431 void slotDuplicateTabPopup();
433 void slotBreakOffTab();
434 void slotBreakOffTabPopup();
435 void slotBreakOffTabPopupDelayed();
437 void slotPopupNewWindow();
438 void slotPopupThisWindow();
439 void slotPopupNewTab();
440 void slotPopupPasteTo();
441 void slotRemoveView();
443 void slotRemoveOtherTabsPopup();
445 void slotReloadPopup();
446 void slotReloadAllTabs();
447 void slotRemoveTab();
448 void slotRemoveTabPopup();
449 void slotRemoveTabPopupDelayed();
451 void slotActivateNextTab();
452 void slotActivatePrevTab();
453 void slotActivateTab();
455 void slotDumpDebugInfo();
457 void slotSaveViewProfile();
459 void slotOpenEmbedded(KService::Ptr
);
461 // Connected to KSycoca
462 void slotDatabaseChanged();
465 void slotReconfigure();
467 void slotForceSaveMainWindowSettings();
472 void slotGoMenuAboutToShow();
474 void slotUpAboutToShow();
475 void slotBackAboutToShow();
476 void slotForwardAboutToShow();
478 void slotClosedItemsListAboutToShow();
479 void updateClosedItemsAction();
482 void slotSessionsListAboutToShow();
483 void saveCurrentSession();
484 void manageSessions();
485 void slotSessionActivated(QAction
* action
);
487 void slotUpActivated(QAction
* action
);
488 void slotBackActivated(QAction
* action
);
489 void slotForwardActivated(QAction
* action
);
490 void slotGoHistoryDelayed();
492 void slotCompletionModeChanged( KGlobalSettings::Completion
);
493 void slotMakeCompletion( const QString
& );
494 void slotSubstringcompletion( const QString
& );
495 void slotRotation( KCompletionBase::KeyBindingType
);
496 void slotMatch( const QString
& );
497 void slotClearHistory();
498 void slotClearComboHistory();
500 void slotClipboardDataChanged();
501 void slotCheckComboSelection();
503 void slotShowMenuBar();
505 void slotOpenURL( const KUrl
& );
509 void slotFindOpen( KonqDirPart
* dirPart
);
510 void slotFindClosed( KonqDirPart
* dirPart
);
513 void slotIconsChanged();
515 virtual bool event( QEvent
* );
517 void slotMoveTabLeft();
518 void slotMoveTabRight();
520 void slotAddWebSideBar(const KUrl
& url
, const QString
& name
);
522 void slotUpdateFullScreen( bool set
); // do not call directly
525 virtual bool eventFilter(QObject
*obj
,QEvent
*ev
);
528 * Reimplemented for internal reasons. The API is not affected.
530 virtual void showEvent(QShowEvent
*event
);
532 bool makeViewsFollow( const KUrl
& url
,
533 const KParts::OpenUrlArguments
& args
,
534 const KParts::BrowserArguments
&browserArgs
, const QString
& serviceType
,
535 KonqView
* senderView
);
537 void applyKonqMainWindowSettings();
541 void updateLocalPropsActions();
543 virtual void closeEvent( QCloseEvent
* );
544 virtual bool queryExit();
546 bool askForTarget(const KLocalizedString
& text
, KUrl
& url
);
549 void slotUndoTextChanged(const QString
& newText
);
551 void slotRequesterClicked( KUrlRequester
* );
553 void slotItemsRemoved(const KFileItemList
&);
555 * Loads the url displayed currently in the lineedit of the locationbar, by
556 * emulating a enter key press event.
560 void bookmarksIntoCompletion();
562 void initBookmarkBar();
564 void showPageSecurity();
567 void updateWindowIcon();
569 QString
detectNameFilter( KUrl
& url
);
572 * takes care of hiding the bookmarkbar and calling setChecked( false ) on the
573 * corresponding action
575 void updateBookmarkBar();
578 * Adds all children of @p group to the static completion object
580 static void bookmarksIntoCompletion( const KBookmarkGroup
& group
);
583 * Returns all matches of the url-history for @p s. If there are no direct
584 * matches, it will try completing with http:// prepended, and if there's
585 * still no match, then http://www. Due to that, this is only usable for
586 * popupcompletion and not for manual or auto-completion.
588 static QStringList
historyPopupCompletionItems( const QString
& s
= QString());
590 void startAnimation();
591 void stopAnimation();
593 void setUpEnabled( const KUrl
&url
);
595 void checkDisableClearButton();
599 void popupNewTab(bool infront
, bool openAfterCurrentPage
);
600 void addClosedWindowToUndoList();
602 * Tries to find a index.html (.kde.html) file in the specified directory
604 static QString
findIndexFile( const QString
&directory
);
606 void connectExtension( KParts::BrowserExtension
*ext
);
607 void disconnectExtension( KParts::BrowserExtension
*ext
);
609 void plugViewModeActions();
610 void unplugViewModeActions();
612 bool stayPreloaded();
613 bool checkPreloadResourceUsage();
616 * Manage how many instances of this class are out there.
618 void incInstancesCount();
619 void decInstancesCount();
621 QObject
* lastFrame( KonqView
*view
);
623 // Maximum height of the animated logo qtoolbutton (m_paAnimatedLogo)
624 int maxThrobberHeight();
625 void setAnimatedLogoSize();
628 KonqUndoManager
* m_pUndoManager
;
630 KNewMenu
* m_pMenuNew
;
634 KBookmarkActionMenu
*m_pamBookmarks
;
636 KToolBarPopupAction
*m_paUp
;
637 KToolBarPopupAction
*m_paBack
;
638 KToolBarPopupAction
*m_paForward
;
639 /// Action for the trash that contains closed tabs/windows
640 KToolBarPopupAction
*m_paClosedItems
;
641 KActionMenu
*m_paSessions
;
644 KAction
*m_paSaveViewProfile
;
646 KAction
*m_paSplitViewHor
;
647 KAction
*m_paSplitViewVer
;
649 KAction
*m_paDuplicateTab
;
650 KAction
*m_paBreakOffTab
;
651 KAction
*m_paRemoveView
;
652 KAction
*m_paRemoveTab
;
653 KAction
*m_paRemoveOtherTabs
;
654 KAction
*m_paActivateNextTab
;
655 KAction
*m_paActivatePrevTab
;
657 KAction
*m_paSaveRemoveViewProfile
;
658 KActionMenu
*m_pamLoadViewProfile
;
660 KToggleAction
*m_paLockView
;
661 KToggleAction
*m_paLinkView
;
663 KAction
*m_paForceReload
;
664 KAction
*m_paReloadAllTabs
;
671 KAction
*m_paCopyFiles
;
672 KAction
*m_paMoveFiles
;
674 KAction
*m_paMoveTabLeft
;
675 KAction
*m_paMoveTabRight
;
677 KAction
*m_paConfigureExtensions
;
678 KAction
*m_paConfigureSpellChecking
;
680 KAnimatedButton
*m_paAnimatedLogo
;
682 KBookmarkBar
*m_paBookmarkBar
;
685 KToggleAction
* m_paFindFiles
;
687 KToggleAction
*m_ptaUseHTML
;
689 KToggleAction
*m_paShowMenuBar
;
691 KToggleFullScreenAction
*m_ptaFullScreen
;
693 bool m_bLocationBarConnected
:1;
694 bool m_bURLEnterLock
:1;
696 bool m_bHTMLAllowed
:1;
697 // Set in constructor, used in slotRunFinished
698 bool m_bNeedApplyKonqMainWindowSettings
:1;
699 bool m_urlCompletionStarted
:1;
700 bool m_prevMenuBarVisible
:1;
701 bool m_fullyConstructed
:1;
704 Qt::MouseButtons m_goMouseState
;
705 Qt::KeyboardModifiers m_goKeyboardState
;
709 QPointer
<KonqView
> m_currentView
;
711 KBookmarkMenu
* m_pBookmarkMenu
;
712 KonqExtendedBookmarkOwner
*m_pBookmarksOwner
;
713 KActionCollection
* m_bookmarksActionCollection
;
714 bool m_bookmarkBarInitialized
;
716 KonqViewManager
*m_pViewManager
;
717 KonqFrameBase
* m_pChildFrame
;
719 KonqFrameBase
* m_pWorkingTab
;
721 // Store a number of things when opening a popup, they are needed
722 // in the slots connected to the popup's actions.
723 // TODO: a struct with new/delete to save a bit of memory?
724 QString m_popupMimeType
;
726 KFileItemList m_popupItems
;
727 KParts::OpenUrlArguments m_popupUrlArgs
;
728 KParts::BrowserArguments m_popupUrlBrowserArgs
;
730 KCMultiDialog
* m_configureDialog
;
732 QLabel
* m_locationLabel
;
733 QPointer
<KonqCombo
> m_combo
;
734 static KConfig
*s_comboConfig
;
735 KUrlCompletion
*m_pURLCompletion
;
736 // just a reference to KonqHistoryManager's completionObject
737 static KCompletion
*s_pCompletion
;
739 ToggleViewGUIClient
*m_toggleViewGUIClient
;
741 QString m_initialFrameName
;
743 QList
<QAction
*> m_openWithActions
;
744 KActionMenu
*m_openWithMenu
;
745 KActionMenu
*m_viewModeMenu
;
746 QActionGroup
* m_viewModesGroup
;
747 QActionGroup
* m_closedItemsGroup
;
748 QActionGroup
* m_sessionsGroup
;
750 static QList
<KonqMainWindow
*> *s_lstViews
;
752 QString m_currentDir
; // stores current dir for relative URLs whenever applicable
754 // TODO: move to a KonqPreloadHandler class
755 static bool s_preloaded
;
756 static KonqMainWindow
* s_preloadedWindow
;
760 static QFile
*s_crashlog_file
;
763 #endif // KONQMAINWINDOW_H