konqviewmanager.h 11.5 KB
Newer Older
1 2
/*  This file is part of the KDE project
    Copyright (C) 1999 Simon Hausmann <hausmann@kde.org>
3
    Copyright (C) 2007 Eduardo Robles Elvira <edulix@gmail.com>
4

5 6 7 8
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
9

10 11 12 13
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
14

15 16
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
Dirk Mueller's avatar
Dirk Mueller committed
17
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 19

*/
20

21 22
#ifndef __konq_viewmanager_h__
#define __konq_viewmanager_h__
23

24
#include "konqprivate_export.h"
25
#include "konqfactory.h"
26
#include "konqframe.h"
27

28 29 30
#include <QMap>
#include <QPointer>
#include <QUrl>
31

32
#include <KService>
33

David Faure's avatar
David Faure committed
34
#include <kparts/partmanager.h>
35
#include "konqopenurlrequest.h"
36
#include <ksharedconfig.h>
37

38
class KonqFrameTabs;
39
class QString;
40
class KConfig;
41
class KConfigGroup;
42
class KonqMainWindow;
43
class KonqFrameBase;
44
class KonqFrameContainer;
Doug Hanley's avatar
 
Doug Hanley committed
45
class KonqFrameContainerBase;
46
class KonqView;
47
class KonqClosedTabItem;
48
class KonqClosedWindowItem;
49

50 51
namespace KParts
{
52
class ReadOnlyPart;
Dirk Mueller's avatar
Dirk Mueller committed
53
}
54

55
class KONQ_TESTS_EXPORT KonqViewManager : public KParts::PartManager
56
{
David Faure's avatar
David Faure committed
57
    Q_OBJECT
58
public:
59
    explicit KonqViewManager(KonqMainWindow *mainWindow);
David Faure's avatar
David Faure committed
60
    ~KonqViewManager();
61

62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
    KonqView *createFirstView(const QString &mimeType, const QString &serviceName);

    /**
     * Splits the view, depending on orientation, either horizontally or
     * vertically. The first view in the splitter will contain the initial
     * view, the other will be a new one, constructed from the same service
     * (part) as the first view.
     * Returns the newly created view or 0 if the view couldn't be created.
     *
     * @param newOneFirst if true, move the new view as the first one (left or top)
     */
    KonqView *splitView(KonqView *view,
                        Qt::Orientation orientation,
                        bool newOneFirst = false, bool forceAutoEmbed = false);

    /**
     * Does basically the same as splitView() but inserts the new view inside the
     * specified container (usually used with the main container, to insert
     * the new view at the top of the view tree).
     * Returns the newly created view or 0 if the view couldn't be created.
     *
     * @param newOneFirst if true, move the new view as the first one (left or top)
     */
    KonqView *splitMainContainer(KonqView *currentView,
                                 Qt::Orientation orientation,
                                 const QString &serviceType = QString(),
                                 const QString &serviceName = QString(),
                                 bool newOneFirst = false);

    /**
     * Adds a tab to m_tabContainer
     */
    KonqView *addTab(const QString &serviceType,
                     const QString &serviceName = QString(),
                     bool passiveMode = false, bool openAfterCurrentPage = false, int pos = -1);

    /**
     * Duplicates the specified tab
     */
    void duplicateTab(int tabIndex, bool openAfterCurrentPage = false);

    /**
     * creates a new tab from a history entry
     * used for MMB on back/forward
     */
    KonqView *addTabFromHistory(KonqView *currentView, int steps, bool openAfterCurrentPage);

    /**
     * Break the specified tab off into a new window
     */
    KonqMainWindow *breakOffTab(int tab, const QSize &windowSize);

    /**
     * Guess!:-)
     * Also takes care of setting another view as active if @p view was the active view
     */
    void removeView(KonqView *view);

    /**
     * Removes specified tab
     * Also takes care of setting another view as active if the active view was in this tab
     */
    void removeTab(KonqFrameBase *tab, bool emitAboutToRemoveSignal = true);

    /**
     * Removes all, but the specified tab.
     * Also takes care of setting the specified tab as active if the active view was not in this tab
     * @param tabIndex the index of the tab
     */
    void removeOtherTabs(int tabIndex);

    /**
     * Locates and activates the next tab
     *
     */
    void activateNextTab();

    /**
     * Locates and activates the previous tab
     *
     */
    void activatePrevTab();

    /**
     * Activate given tab
     *
     */
    void activateTab(int position);
Stephan Binner's avatar
 
Stephan Binner committed
150

151 152
    void moveTabBackward();
    void moveTabForward();
153

Laurent Montel's avatar
Laurent Montel committed
154
    void reloadAllTabs();
155

156 157 158
    /**
     * Creates the tabwidget on demand and returns it.
     */
159 160
    KonqFrameTabs *tabContainer();

161 162 163 164 165
    /**
     * Returns true if the tabwidget exists and the tabbar is visible
     */
    bool isTabBarVisible() const;

166 167 168
    // Apply configuration that applies to us, like alwaysTabbedMode.
    void applyConfiguration();

David Faure's avatar
David Faure committed
169 170 171 172 173
    /**
     * Brings the tab specified by @p tabIndex to the front of the stack
     */
    void showTab(int tabIndex);

174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
    /**
     * Brings the tab specified by @p view to the front of the stack
     * Deprecated, used the other one; this one breaks too easily with splitted views
     * (if passing the current view to @p view)
     */
    void showTab(KonqView *view);

    /**
     * Updates favicon pixmaps used in tabs
     *
     */
    void updatePixmaps();

    /**
     * Saves the current view layout to a group in a config file.
     * This is shared between saveViewProfileToFile and saveProperties (session management)
     * Remove config file before saving, especially if saveURLs is false.
     * @param cfg the config file
     * @param options whether to save nothing, the URLs or the complete history of each view in the profile
     */
194 195
    void saveViewConfigToGroup(KConfigGroup &cfg, KonqFrameBase::Options options);

196 197 198 199 200 201 202 203 204
    /**
     * Loads a view layout from a config file. Removes all views before loading.
     * @param cfg the config file
     * @param filename if set, remember the file name of the profile (for save settings)
     * It has to be under the profiles dir. Otherwise, set to QString()
     * @param forcedUrl if set, the URL to open, whatever the profile says
     * @param req attributes related to @p forcedUrl
     * settings, they will be reset to the defaults
     */
205
    void loadViewConfigFromGroup(const KConfigGroup &cfg, const QString &filename,
206
                                  const QUrl &forcedUrl = QUrl(),
207
                                  const KonqOpenURLRequest &req = KonqOpenURLRequest(),
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
                                  bool openUrl = true);
    /**
     * Whether we are currently loading a profile
     */
    bool isLoadingProfile() const
    {
        return m_bLoadingProfile;
    }

    void clear();

    KonqView *chooseNextView(KonqView *view);

    /**
     * Called whenever
     * - the total number of views changed
     * - the number of views in passive mode changed
     * The implementation takes care of showing or hiding the statusbar indicators
     */
    void viewCountChanged();

    KonqMainWindow *mainWindow() const
    {
        return m_pMainWindow;
    }
233

234 235 236
    /**
     * Reimplemented from PartManager
     */
237
    void removePart(KParts::Part *part) Q_DECL_OVERRIDE;
238

239 240 241
    /**
     * Reimplemented from PartManager
     */
242
    void setActivePart(KParts::Part *part, QWidget *widget = 0) Q_DECL_OVERRIDE;
243

244
    void doSetActivePart(KParts::ReadOnlyPart *part);
245

246
    void applyWindowSize(const KConfigGroup &profileGroup);
247

248
#ifndef NDEBUG
249
    void printFullHierarchy();
250
#endif
Doug Hanley's avatar
 
Doug Hanley committed
251

252
    void setLoading(KonqView *view, bool loading);
253

254
    /**
David Faure's avatar
David Faure committed
255
     * Creates a copy of the current window
256
     */
257
    KonqMainWindow *duplicateWindow();
David Faure's avatar
David Faure committed
258

259 260
    /**
     * Open a saved window.
261
     *
262 263 264
     * @param openTabsInsideCurrentWindow if true, it will try to open the
     * tabs inside current window.
     */
265 266
    KonqMainWindow *openSavedWindow(const KConfigGroup &configGroup,
                                    bool openTabsInsideCurrentWindow);
267

268 269 270 271 272
    /**
     * Open a saved window in a new KonqMainWindow instance.
     * It doesn't have the openTabsInsideCurrentWindow because this is the
     * static version.
     */
273
    static KonqMainWindow *openSavedWindow(const KConfigGroup &configGroup);
274 275

public Q_SLOTS:
276 277 278
    /**
     * Opens a previously closed window in a new window
     */
279
    static void openClosedWindow(const KonqClosedWindowItem &closedTab);
280

David Faure's avatar
David Faure committed
281 282 283
    /**
     * Opens a previously closed tab in a new tab
     */
284
    void openClosedTab(const KonqClosedTabItem &closedTab);
David Faure's avatar
David Faure committed
285

286
private Q_SLOTS:
287
    void emitActivePartChanged();
288

289
    void slotPassiveModePartDeleted();
290

291
    void slotActivePartChanged(KParts::Part *newPart);
Doug Hanley's avatar
 
Doug Hanley committed
292

293
private:
294

295 296 297 298 299 300 301 302 303 304 305 306 307 308
    /**
     * Load the config entries for a view.
     * @param cfg the config file
     * ...
     * @param defaultURL the URL to use if the profile doesn't contain urls
     * @param openUrl whether to open urls at all (from the profile or using @p defaultURL).
     *  (this is set to false when we have a forcedUrl to open)
     * @param forcedUrl open this URL instead of the one from the profile
     * @param forcedService use this service (part) instead of the one from the profile
     */
    void loadItem(const KConfigGroup &cfg, KonqFrameContainerBase *parent,
                  const QString &name, const QUrl &defaultURL, bool openUrl,
                  const QUrl &forcedUrl, const QString &forcedService,
                  bool openAfterCurrentPage = false, int pos = -1);
309

310
    void loadRootItem(const KConfigGroup &cfg, KonqFrameContainerBase *parent,
311 312 313 314
                      const QUrl &defaultURL, bool openUrl,
                      const QUrl &forcedUrl, const QString &forcedService = QString(),
                      bool openAfterCurrentPage = false,
                      int pos = -1);
315

316
    void createTabContainer(QWidget *parent, KonqFrameContainerBase *parentContainer);
317

318
signals:
David Faure's avatar
David Faure committed
319
// the signal is only emitted when the contents of the view represented by
320
// "tab" are going to be lost for good.
321
    void aboutToRemoveTab(KonqFrameBase *tab);
322

323
private:
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
    /**
     * Creates a new View based on the given ServiceType. If serviceType is empty
     * it clones the current view.
     * Returns the newly created view.
     */
    KonqViewFactory createView(const QString &serviceType,  /* can be servicetype or mimetype */
                               const QString &serviceName,
                               KService::Ptr &service,
                               KService::List &partServiceOffers,
                               KService::List &appServiceOffers,
                               bool forceAutoEmbed = false);

    /**
     * Mainly creates the backend structure(KonqView) for a view and
     * connects it
     */
    KonqView *setupView(KonqFrameContainerBase *parentContainer,
                        KonqViewFactory &viewFactory,
                        const KService::Ptr &service,
                        const KService::List &partServiceOffers,
                        const KService::List &appServiceOffers,
                        const QString &serviceType,
                        bool passiveMode, bool openAfterCurrentPage = false, int pos = -1);
347

348
#ifndef NDEBUG
349 350 351 352
    //just for debugging
    void printSizeInfo(KonqFrameBase *frame,
                       KonqFrameContainerBase *parent,
                       const char *msg);
353
#endif
354

355
    KonqMainWindow *m_pMainWindow;
Doug Hanley's avatar
 
Doug Hanley committed
356

357
    KonqFrameTabs *m_tabContainer;
358

359
    bool m_bLoadingProfile;
360

361
    QMap<QString /*display name*/, QString /*path to file*/> m_mapProfileNames;
362 363 364
};

#endif