delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / apps / konqueror / src / konqview.h
blob79d738ce4e9fceb96fc65494f983267343a55b22
1 /*
2 * This file is part of the KDE project
3 * Copyright (C) 1998-2005 David Faure <faure@kde.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program 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
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 **/
20 #ifndef __konq_view_h__
21 #define __konq_view_h__
23 #include "konqmainwindow.h" // hmm, please move PageSecurity out of konq_mainwindow...
24 #include "konqfactory.h"
25 #include "konqframe.h"
27 #include <kservice.h>
29 #include <QtCore/QList>
31 #include <QtCore/QObject>
32 #include <QtCore/QStringList>
33 #include <QtCore/QPointer>
34 #include <QtCore/QEvent>
36 class KonqRun;
37 class KonqFrame;
38 class KonqBrowserInterface;
39 namespace KParts
41 class BrowserExtension;
42 class StatusBarExtension;
45 struct HistoryEntry
47 void loadItem( const KConfigGroup& config, const QString &prefix, const KonqFrameBase::Options &options);
48 void saveConfig( KConfigGroup& config, const QString &prefix, const KonqFrameBase::Options &options);
50 KUrl url;
51 QString locationBarURL; // can be different from url when showing a index.html
52 QString title;
53 QByteArray buffer;
54 QString strServiceType;
55 QString strServiceName;
56 QByteArray postData;
57 QString postContentType;
58 bool doPost;
59 QString pageReferrer;
60 KonqMainWindow::PageSecurity pageSecurity;
61 bool reload; // This is used when History entry is restored from a config file
64 /* This class represents a child of the main view. The main view maintains
65 * the list of children. A KonqView contains a Browser::View and
66 * handles it. It's more or less the backend structure for the views.
67 * The widget handling stuff is done by the KonqFrame.
69 class KONQ_TESTS_EXPORT KonqView : public QObject
71 Q_OBJECT
72 public:
74 /**
75 * Create a konqueror view
76 * @param viewFactory the factory to be used to create the part
77 * @param viewFrame the frame where to create the view
78 * @param mainWindow is the main window :-)
79 * @param service the service implementing the part
80 * @param partServiceOffers list of part offers found by the factory
81 * @param appServiceOffers list of app offers found by the factory
82 * @param serviceType the serviceType implemented by the part
83 * @param passiveMode whether to initially make the view passive
85 KonqView( KonqViewFactory &viewFactory,
86 KonqFrame* viewFrame,
87 KonqMainWindow * mainWindow,
88 const KService::Ptr &service,
89 const KService::List &partServiceOffers,
90 const KService::List &appServiceOffers,
91 const QString &serviceType,
92 bool passiveMode);
94 ~KonqView();
96 /**
97 * Displays another URL, but without changing the view mode (caller has to
98 * ensure that the call makes sense)
99 * @param url the URL to open
100 * @param locationBarURL the URL to set in the location bar (see @ref setLocationBarURL)
101 * @param nameFilter e.g. *.cpp
102 * @param tempFile whether to delete the file after use
104 void openUrl( const KUrl &url,
105 const QString & locationBarURL,
106 const QString &nameFilter = QString(),
107 bool tempFile = false );
110 * Change the part inside this view if necessary.
111 * Contract: the caller should call stop() first.
113 * @param mimeType the mime type we want to show
114 * @param serviceName allows to enforce a particular service to be chosen,
115 * @see KonqFactory.
116 * @param forceAutoEmbed
118 bool changePart(const QString &mimeType,
119 const QString &serviceName = QString(),
120 bool forceAutoEmbed = false);
123 * Ensures that this view's part supports the given @p mimeType,
124 * otherwise calls changePart.
126 bool ensureViewSupports(const QString& mimeType,
127 bool forceAutoEmbed);
130 * Call this to prevent next openUrl() call from changing history lists
131 * Used when the same URL is reloaded (for instance with another view mode)
133 * Calling with lock=false is a hack reserved to the "find" feature.
135 void lockHistory( bool lock = true ) { m_bLockHistory = lock; }
138 * @return true if view can go back
140 bool canGoBack() const { return m_lstHistoryIndex > 0; }
143 * @return true if view can go forward
145 bool canGoForward() const { return m_lstHistoryIndex != m_lstHistory.count()-1; }
148 * @return the position in the history
150 int historyIndex() const { return m_lstHistoryIndex; }
152 int historyLength() { return m_lstHistory.count(); }
155 * Move in history. +1 is "forward", -1 is "back", you can guess the rest.
157 void go( int steps );
160 * Helper function for go() and KonqViewManager
162 void restoreHistory();
164 void setHistoryIndex(int index) { m_lstHistoryIndex = index; }
167 * @return the history of this view
169 const QList<HistoryEntry*> & history() { return m_lstHistory; }
172 * @return the HistoryEntry at postion @p pos
174 const HistoryEntry* historyAt(int pos);
179 HistoryEntry* currentHistoryEntry() const { return m_lstHistory.value( m_lstHistoryIndex ); }
182 * Creates a deep copy of the @p other view's history buffers.
184 void copyHistory( KonqView *other );
187 * Set the KonqRun instance that is running something for this view
188 * The main window uses this to store the KonqRun for each child view.
190 void setRun( KonqRun * run );
192 KonqRun *run() const { return m_pRun; }
195 * Stop loading
197 void stop();
200 * Retrieve view's URL
202 KUrl url() const;
204 KUrl upUrl() const;
207 * Get view's location bar URL, i.e. the one that the view signals
208 * It can be different from url(), for instance if we display a index.html
210 QString locationBarURL() const { return m_sLocationBarURL; }
213 * Get the URL that was typed to get the current URL.
215 QString typedUrl() const { return m_sTypedURL; }
217 * Set the URL that was typed to get the current URL.
219 void setTypedURL( const QString & u ) { m_sTypedURL = u; }
222 * Returns the name filter, if any, like *.txt
224 QString nameFilter() const;
227 * Return the security state of page in view
229 KonqMainWindow::PageSecurity pageSecurity() const { return m_pageSecurity; }
232 * @return the part embedded into this view
234 KParts::ReadOnlyPart *part() const { return m_pPart; }
237 * see KonqViewManager::removePart
239 void partDeleted() { m_pPart = 0L; }
242 * Return true if the loading in the view was aborted due to an error
243 * or to user cancellation
245 bool aborted() const { return m_bAborted; }
247 KParts::BrowserExtension *browserExtension() const;
249 KParts::StatusBarExtension *statusBarExtension() const;
252 * @return a pointer to the KonqFrame which the view lives in
254 KonqFrame* frame() const { return m_pKonqFrame; }
257 * @return the servicetype this view is currently displaying
258 * This is usually a mimetype, but it can be "Browser/View"
259 * for toggle views like the sidebar or the embedded konsole.
261 QString serviceType() const { return m_serviceType; }
264 * @return the servicetypes this view is capable to display
266 QStringList serviceTypes() const { return m_service->serviceTypes(); }
268 bool supportsMimeType( const QString &mimeType ) const;
270 // True if showing a directory
271 bool showsDirectory() const;
273 // True if "Use index.html" is set (->the view doesn't necessarily show HTML!)
274 bool allowHTML() const { return m_bAllowHTML; }
275 void setAllowHTML( bool allow ) { m_bAllowHTML = allow; }
277 // True if currently loading
278 bool isLoading() const { return m_bLoading; }
279 void setLoading( bool loading, bool hasPending = false );
281 // True if "locked to current location" (and their view mode, in fact)
282 bool isLockedLocation() const { return m_bLockedLocation; }
283 void setLockedLocation( bool b );
285 // True if can't be made active (e.g. dirtree).
286 bool isPassiveMode() const { return m_bPassiveMode; }
287 void setPassiveMode( bool mode );
289 // True if is hierarchical view
290 bool isHierarchicalView() const { return m_bHierarchicalView; }
291 void setHierarchicalView( bool mode );
293 // True if 'link' symbol set
294 bool isLinkedView() const { return m_bLinkedView; }
295 void setLinkedView( bool mode );
297 // True if toggle view
298 void setToggleView( bool b ) { m_bToggleView = b; }
299 bool isToggleView() const { return m_bToggleView; }
301 // True if it always follows the active view
302 void setFollowActive(bool b) { m_bFollowActive = b; }
303 bool isFollowActive() { return m_bFollowActive; }
305 // True if locked to current view mode
306 // Toggle views and passive views are locked to their view mode.
307 bool isLockedViewMode() const { return m_bToggleView || m_bPassiveMode; }
309 // True if "builtin" (see X-KDE-BrowserView-Built-Into)
310 //bool isBuiltinView() const { return m_bBuiltinView; }
313 * The current viewmode used by this view -- only meaningful
314 * when the part implements several view modes internally, like DolphinPart.
316 QString internalViewMode() const;
318 * Switch the internal view mode in this view -- only meaningful
319 * when the part implements several view modes internally, like DolphinPart.
321 void setInternalViewMode(const QString& viewMode);
323 KService::Ptr service() { return m_service; }
325 QString caption() const { return m_caption; }
327 KService::List partServiceOffers() { return m_partServiceOffers; }
328 KService::List appServiceOffers() { return m_appServiceOffers; }
330 KonqMainWindow *mainWindow() const { return m_pMainWindow; }
332 // return true if the method was found, false if the execution failed
333 bool callExtensionMethod( const char *methodName );
334 bool callExtensionBoolMethod( const char *methodName, bool value );
335 bool callExtensionURLMethod( const char *methodName, const KUrl& value );
337 void setViewName( const QString &name );
338 QString viewName() const;
340 // True to enable the context popup menu
341 void enablePopupMenu( bool b );
342 bool isPopupMenuEnabled() const { return m_bPopupMenuEnabled; }
344 void reparseConfiguration();
346 void disableScrolling();
348 QStringList frameNames() const;
350 QString dbusObjectPath();
351 QString partObjectPath();
353 void goHistory( int steps );
355 // Set the KGlobal active componentData(the one used by KBugReport)
356 void setActiveComponent();
358 // Called before reloading this view. Sets args.reload to true, and offers to repost form data.
359 // Returns false in case the reload must be canceled.
360 bool prepareReload( KParts::OpenUrlArguments& args, KParts::BrowserArguments& browserArgs, bool softReload );
362 // overload for the QString version
363 void setLocationBarURL( const KUrl& locationBarURL );
366 * Saves config in a KConfigGroup
368 void saveConfig( KConfigGroup& config, const QString &prefix, const KonqFrameBase::Options &options);
369 void loadHistoryConfig( const KConfigGroup& config, const QString &prefix);
371 static QStringList childFrameNames( KParts::ReadOnlyPart *part );
373 static KParts::BrowserHostExtension *hostExtension( KParts::ReadOnlyPart *part, const QString &name );
375 Q_SIGNALS:
378 * Signal the main window that the embedded part changed (e.g. because of changePart)
380 void sigPartChanged( KonqView *childView, KParts::ReadOnlyPart *oldPart, KParts::ReadOnlyPart *newPart );
383 * Emitted in slotCompleted
385 void viewCompleted( KonqView * view );
388 * Emitted only if the option backRightClick is activated
390 void backRightClick();
392 public Q_SLOTS:
394 * Store location-bar URL in the child view
395 * and updates the main view if this view is the current one
396 * May be different from url e.g. if using "allowHTML".
398 void setLocationBarURL( const QString & locationBarURL );
400 * get an icon for the URL from the BrowserExtension
402 void setIconURL( const KUrl &iconURL );
404 void setTabIcon( const KUrl &url );
406 void setCaption( const QString & caption );
408 void setPageSecurity( int );
410 // connected to the KROP's KIO::Job
411 // but also to KonqRun's job
412 void slotInfoMessage( KJob *, const QString &msg );
414 private Q_SLOTS:
415 // connected to the KROP's KIO::Job
416 void slotStarted( KIO::Job * job );
417 void slotCompleted();
418 void slotCompleted( bool );
419 void slotCanceled( const QString & errMsg );
420 void slotPercent( KJob *, unsigned long percent );
421 void slotSpeed( KJob *, unsigned long bytesPerSecond );
424 * Connected to the BrowserExtension
426 void slotSelectionInfo( const KFileItemList &items );
427 void slotMouseOverInfo( const KFileItem& item );
428 void slotOpenURLNotify();
429 void slotEnableAction( const char * name, bool enabled );
430 void slotSetActionText( const char* name, const QString& text );
431 void slotMoveTopLevelWidget( int x, int y );
432 void slotResizeTopLevelWidget( int w, int h );
433 void slotRequestFocus(KParts::ReadOnlyPart*);
435 private:
436 void enableBackRightClick( bool b );
438 * Replace the current view with a new view, created by @p viewFactory.
440 void switchView( KonqViewFactory &viewFactory );
443 * Connects the internal part to the main window.
444 * Do this after creating it and before inserting it.
446 void connectPart();
449 * Creates a new entry in the history.
451 void createHistoryEntry();
454 * Appends a entry in the history.
456 void appendHistoryEntry(HistoryEntry * historyEntry);
459 * Updates the current entry in the history.
460 * @param saveLocationBarURL whether to save the location bar URL as part of it
461 * (not done in openUrl, to be able to revert if aborting)
463 void updateHistoryEntry(bool saveLocationBarURL);
465 void aboutToOpenURL( const KUrl &url, const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments() );
467 void setPartMimeType();
469 void finishedWithCurrentURL();
471 virtual bool eventFilter( QObject *obj, QEvent *e );
473 ////////////////// private members ///////////////
475 KParts::ReadOnlyPart *m_pPart;
477 QString m_sLocationBarURL;
478 QString m_sTypedURL;
479 KonqMainWindow::PageSecurity m_pageSecurity;
482 * The full history (back + current + forward)
484 QList<HistoryEntry*> m_lstHistory;
486 * The current position in the history
488 int m_lstHistoryIndex;
491 * The post data that _resulted_ in this page.
492 * e.g. when submitting a form, and the result is an image, this data will be
493 * set (and saved/restored) when the image is being viewed. Necessary for reload.
495 QByteArray m_postData;
496 QString m_postContentType;
497 bool m_doPost;
500 * The referrer that was used to obtain this page.
502 QString m_pageReferrer;
504 KonqMainWindow *m_pMainWindow;
505 KonqRun *m_pRun;
506 KonqFrame *m_pKonqFrame;
508 uint m_bAllowHTML:1;
509 uint m_bLoading:1;
510 uint m_bLockedLocation:1;
511 uint m_bPassiveMode:1;
512 uint m_bLinkedView:1;
513 uint m_bToggleView:1;
514 uint m_bLockHistory:1;
515 uint m_bAborted:1;
516 uint m_bGotIconURL:1;
517 uint m_bPopupMenuEnabled:1;
518 uint m_bFollowActive:1;
519 uint m_bPendingRedirection:1;
520 uint m_bBuiltinView:1;
521 uint m_bURLDropHandling:1;
522 uint m_bBackRightClick:1;
523 uint m_bHierarchicalView:1;
524 uint m_bDisableScrolling:1;
525 KService::List m_partServiceOffers;
526 KService::List m_appServiceOffers;
527 KService::Ptr m_service;
528 QString m_serviceType;
529 QString m_caption;
530 QString m_tempFile;
531 QString m_dbusObjectPath;
532 KonqBrowserInterface *m_browserIface;
533 int m_randID;
536 #endif