add more spacing
[personal-kdebase.git] / apps / konqueror / src / konqviewmanager.h
blobd92a4545a455a0ea55a6e5f1328f7bce0d657b75
1 /* This file is part of the KDE project
2 Copyright (C) 1999 Simon Hausmann <hausmann@kde.org>
3 Copyright (C) 2007 Eduardo Robles Elvira <edulix@gmail.com>
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.
21 #ifndef __konq_viewmanager_h__
22 #define __konq_viewmanager_h__
24 #include "konqprivate_export.h"
25 #include "konqfactory.h"
26 #include "konqframe.h"
28 #include <QtCore/QMap>
29 #include <QtCore/QPointer>
31 #include <KService>
33 #include <kparts/partmanager.h>
34 #include "konqopenurlrequest.h"
36 class KMainWindow;
37 class KonqFrameTabs;
38 class QString;
39 class QTimer;
40 class KConfig;
41 class KConfigGroup;
42 class KonqMainWindow;
43 class KonqFrameBase;
44 class KonqFrameContainer;
45 class KonqFrameContainerBase;
46 class KonqView;
47 class KActionMenu;
48 class KonqClosedTabItem;
49 class KonqClosedWindowItem;
51 namespace KParts
53 class ReadOnlyPart;
56 class KONQ_TESTS_EXPORT KonqViewManager : public KParts::PartManager
58 Q_OBJECT
59 public:
60 explicit KonqViewManager( KonqMainWindow *mainWindow );
61 ~KonqViewManager();
63 KonqView* createFirstView( const QString &mimeType, const QString &serviceName );
65 /**
66 * Splits the view, depending on orientation, either horizontally or
67 * vertically. The first view in the splitter will contain the initial
68 * view, the other will be a new one, constructed from the same service
69 * (part) as the first view.
70 * Returns the newly created view or 0 if the view couldn't be created.
72 * @param newOneFirst if true, move the new view as the first one (left or top)
74 KonqView* splitView( KonqView* view,
75 Qt::Orientation orientation,
76 bool newOneFirst = false, bool forceAutoEmbed = false );
78 /**
79 * Does basically the same as splitView() but inserts the new view inside the
80 * specified container (usually used with the main container, to insert
81 * the new view at the top of the view tree).
82 * Returns the newly created view or 0 if the view couldn't be created.
84 * @param newOneFirst if true, move the new view as the first one (left or top)
86 KonqView* splitMainContainer( KonqView* currentView,
87 Qt::Orientation orientation,
88 const QString & serviceType = QString(),
89 const QString & serviceName = QString(),
90 bool newOneFirst = false );
92 /**
93 * Adds a tab to m_tabContainer
95 KonqView* addTab(const QString &serviceType,
96 const QString &serviceName = QString(),
97 bool passiveMode = false, bool openAfterCurrentPage = false, int pos = -1 );
99 /**
100 * Duplicates the specified tab, or else the current one if none is specified
102 void duplicateTab( KonqFrameBase* tab, bool openAfterCurrentPage = false );
105 * creates a new tab from a history entry
106 * used for MMB on back/forward
108 KonqView* addTabFromHistory( KonqView* currentView, int steps, bool openAfterCurrentPage );
111 * Break the current tab off into a new window,
112 * if none is specified, the current one is used
114 void breakOffTab( KonqFrameBase* tab, const QSize& windowSize );
117 * Guess!:-)
118 * Also takes care of setting another view as active if @p view was the active view
120 void removeView( KonqView *view );
123 * Removes specified tab
124 * Also takes care of setting another view as active if the active view was in this tab
126 void removeTab( KonqFrameBase* tab, bool emitAboutToRemoveSignal = true );
129 * Removes all, but the specified tab.
130 * Also takes care of setting the specified tab as active if the active view was not in this tab
131 * @param tab must exist
133 void removeOtherTabs( KonqFrameBase* tab );
136 * Locates and activates the next tab
139 void activateNextTab();
142 * Locates and activates the previous tab
145 void activatePrevTab();
148 * Activate given tab
151 void activateTab(int position);
153 void moveTabBackward();
154 void moveTabForward();
156 void reloadAllTabs();
159 * Creates the tabwidget on demand and returns it.
161 KonqFrameTabs *tabContainer();
164 * Returns true if the tabwidget exists and the tabbar is visible
166 bool isTabBarVisible() const;
168 // Apply configuration that applies to us, like alwaysTabbedMode.
169 void applyConfiguration();
172 * Brings the tab specified by @p view to the front of the stack
175 void showTab( KonqView *view );
178 * Updates favicon pixmaps used in tabs
181 void updatePixmaps();
184 * Saves the current view layout to a config file, including menu/toolbar settings.
185 * Remove config file before saving, especially if saveURLs is false.
186 * @param fileName the name of the config file
187 * @param profileName the name of the profile
188 * @param saveURLs whether to save the URLs in the profile
190 void saveViewProfileToFile(const QString & fileName, const QString & profileName,
191 KonqFrameBase::Options options);
194 * Saves the current view layout to a group in a config file.
195 * This is shared between saveViewProfileToFile and saveProperties (session management)
196 * Remove config file before saving, especially if saveURLs is false.
197 * @param cfg the config file
198 * @param options whether to save nothing, the URLs or the complete history of each view in the profile
200 void saveViewProfileToGroup(KConfigGroup & cfg, KonqFrameBase::Options options);
204 * Loads a view layout from a config file. Removes all views before loading.
205 * @param path the full path to the config file
206 * @param filename if set, remember the file name of the profile (for save settings)
207 * It has to be under the profiles dir. Otherwise, set to QString()
208 * @param forcedUrl if set, the URL to open, whatever the profile says
209 * @param req attributes related to @p forcedUrl
210 * @param resetWindow if the profile doesn't have attributes like size or toolbar
211 * settings, they will be reset to the defaults
213 void loadViewProfileFromFile( const QString & path, const QString & filename,
214 const KUrl & forcedUrl = KUrl(),
215 const KonqOpenURLRequest &req = KonqOpenURLRequest(),
216 bool resetWindow = false, bool openUrl = true );
217 // Overload for KonqMisc::createBrowserWindowFromProfile
218 void loadViewProfileFromConfig( const KSharedConfigPtr& config,
219 const QString& path,
220 const QString & filename,
221 const KUrl & forcedUrl = KUrl(),
222 const KonqOpenURLRequest &req = KonqOpenURLRequest(),
223 bool resetWindow = false, bool openUrl = true );
225 * Loads a view layout from a config file. Removes all views before loading.
226 * @param cfg the config file
227 * @param filename if set, remember the file name of the profile (for save settings)
228 * It has to be under the profiles dir. Otherwise, set to QString()
229 * @param forcedUrl if set, the URL to open, whatever the profile says
230 * @param req attributes related to @p forcedUrl
231 * @param resetWindow if the profile doesn't have attributes like size or toolbar
232 * settings, they will be reset to the defaults
234 void loadViewProfileFromGroup( const KConfigGroup& cfg, const QString & filename,
235 const KUrl & forcedUrl = KUrl(),
236 const KonqOpenURLRequest &req = KonqOpenURLRequest(),
237 bool openUrl = true );
239 * Return the filename of the last profile that was loaded
240 * by the view manager. For "save settings".
242 QString currentProfile() const { return m_currentProfile; }
244 * Return the name (i18n'ed) of the last profile that was loaded
245 * by the view manager. For "save settings".
247 QString currentProfileText() const { return m_currentProfileText; }
250 * Whether we are currently loading a profile
252 bool isLoadingProfile() const { return m_bLoadingProfile; }
254 void clear();
256 KonqView *chooseNextView( KonqView *view );
259 * Called whenever
260 * - the total number of views changed
261 * - the number of views in passive mode changed
262 * The implementation takes care of showing or hiding the statusbar indicators
264 void viewCountChanged();
266 void setProfiles( KActionMenu *profiles );
268 void profileListDirty( bool broadcast = true );
270 // KonqFrameBase *docContainer() const { return m_pDocContainer; }
271 // void setDocContainer( KonqFrameBase* docContainer ) { m_pDocContainer = docContainer; }
273 KonqMainWindow *mainWindow() const { return m_pMainWindow; }
276 * Reimplemented from PartManager
278 virtual void removePart( KParts::Part * part );
281 * Reimplemented from PartManager
283 virtual void setActivePart( KParts::Part *part, QWidget *widget = 0 );
285 void doSetActivePart( KParts::Part *part );
287 void showProfileDlg( const QString & preselectProfile );
290 * Read default size from profile (e.g. Width=80%)
292 static QSize readDefaultSize(const KConfigGroup& cfg, QWidget* window);
294 #ifndef NDEBUG
295 void printFullHierarchy();
296 #endif
298 void setLoading( KonqView *view, bool loading );
300 void showHTML(bool b);
303 * Normalize the name of the .rc file to use; this is just
304 * for handling compatibility with old profiles mentionning
305 * konq-webbrowsing.rc or konq-filemanagement.rc
307 static QString normalizedXMLFileName(const QString& xmluiFile);
310 * Creates a copy of the current window
312 KonqMainWindow* duplicateWindow();
315 * Open a saved window.
317 * @param openTabsInsideCurrentWindow if true, it will try to open the
318 * tabs inside current window.
320 KonqMainWindow *openSavedWindow(const KConfigGroup& configGroup,
321 bool openTabsInsideCurrentWindow);
324 * Open a saved window in a new KonqMainWindow instance.
325 * It doesn't have the openTabsInsideCurrentWindow because this is the
326 * static version.
328 static KonqMainWindow *openSavedWindow(const KConfigGroup& configGroup);
330 public Q_SLOTS:
332 * Opens a previously closed window in a new window
334 static void openClosedWindow(const KonqClosedWindowItem& closedTab);
337 * Opens a previously closed tab in a new tab
339 void openClosedTab(const KonqClosedTabItem& closedTab);
341 private Q_SLOTS:
342 void emitActivePartChanged();
344 void slotProfileDlg();
346 void slotProfileActivated(QAction* action);
348 void slotProfileListAboutToShow();
350 void slotPassiveModePartDeleted();
352 void slotActivePartChanged ( KParts::Part *newPart );
354 private:
357 * Load the config entries for a view.
358 * @param cfg the config file
359 * ...
360 * @param defaultURL the URL to use if the profile doesn't contain urls
361 * @param openUrl whether to open urls at all (from the profile or using @p defaultURL).
362 * (this is set to false when we have a forcedUrl to open)
364 void loadItem( const KConfigGroup &cfg, KonqFrameContainerBase *parent,
365 const QString &name, const KUrl & defaultURL, bool openUrl,
366 const KUrl& forcedUrl,
367 bool openAfterCurrentPage = false, int pos = -1 );
369 void loadRootItem( const KConfigGroup &cfg, KonqFrameContainerBase *parent,
370 const KUrl & defaultURL, bool openUrl,
371 const KUrl& forcedUrl,
372 bool openAfterCurrentPage = false,
373 int pos = -1 );
375 void createTabContainer(QWidget* parent, KonqFrameContainerBase* parentContainer);
377 // Disabled - we do it ourselves
378 virtual void setActiveComponent(const KComponentData &) {}
380 void setCurrentProfile(const QString& profileFileName);
382 signals:
383 // the signal is only emitted when the contents of the view represented by
384 // "tab" are going to be lost for good.
385 void aboutToRemoveTab( KonqFrameBase* tab );
387 private:
389 * Creates a new View based on the given ServiceType. If serviceType is empty
390 * it clones the current view.
391 * Returns the newly created view.
393 KonqViewFactory createView( const QString &serviceType, /* can be servicetype or mimetype */
394 const QString &serviceName,
395 KService::Ptr &service,
396 KService::List &partServiceOffers,
397 KService::List &appServiceOffers,
398 bool forceAutoEmbed = false );
401 * Mainly creates the backend structure(KonqView) for a view and
402 * connects it
404 KonqView *setupView( KonqFrameContainerBase *parentContainer,
405 KonqViewFactory &viewFactory,
406 const KService::Ptr &service,
407 const KService::List &partServiceOffers,
408 const KService::List &appServiceOffers,
409 const QString &serviceType,
410 bool passiveMode, bool openAfterCurrentPage = false, int pos = -1);
412 #ifndef NDEBUG
413 //just for debugging
414 void printSizeInfo( KonqFrameBase* frame,
415 KonqFrameContainerBase* parent,
416 const char* msg );
417 #endif
419 KonqMainWindow *m_pMainWindow;
421 KonqFrameTabs *m_tabContainer;
423 QPointer<KActionMenu> m_pamProfiles;
424 bool m_bProfileListDirty;
425 bool m_bLoadingProfile;
426 QString m_currentProfile;
427 QString m_currentProfileText;
429 QMap<QString /*display name*/, QString /*path to file*/> m_mapProfileNames;
432 #endif