konqviewmanager.h 11.3 KB
Newer Older
1 2
/*  This file is part of the KDE project
    Copyright (C) 1999 Simon Hausmann <hausmann@kde.org>
3

4 5 6 7
    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.
8

9 10 11 12
    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.
13

14 15
    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
16
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 18

*/
19

20 21
#ifndef __konq_viewmanager_h__
#define __konq_viewmanager_h__
22

23
#include "konqprivate_export.h"
24
#include "konqfactory.h"
25

Dirk Mueller's avatar
Dirk Mueller committed
26 27
#include <QtCore/QMap>
#include <QtCore/QPointer>
28

29
#include <KService>
30

David Faure's avatar
David Faure committed
31
#include <kparts/partmanager.h>
32
#include "konqopenurlrequest.h"
33

34
class KonqFrameTabs;
35
class QString;
36
class QTimer;
37
class KConfig;
38
class KConfigGroup;
39
class KonqMainWindow;
40
class KonqFrameBase;
41
class KonqFrameContainer;
Doug Hanley's avatar
 
Doug Hanley committed
42
class KonqFrameContainerBase;
43
class KonqView;
44
class KActionMenu;
45

46 47 48
namespace KParts
{
  class ReadOnlyPart;
Dirk Mueller's avatar
Dirk Mueller committed
49
}
50

51
class KONQ_TESTS_EXPORT KonqViewManager : public KParts::PartManager
52
{
David Faure's avatar
David Faure committed
53
    Q_OBJECT
54
public:
David Faure's avatar
David Faure committed
55 56
    explicit KonqViewManager( KonqMainWindow *mainWindow );
    ~KonqViewManager();
57

David Faure's avatar
David Faure committed
58
    KonqView* createFirstView( const QString &serviceType, const QString &serviceName );
Doug Hanley's avatar
 
Doug Hanley committed
59

60
  /**
61
   * Splits the view, depending on orientation, either horizontally or
David Faure's avatar
David Faure committed
62 63 64
   * 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.
65
   * Returns the newly created view or 0 if the view couldn't be created.
66 67
   *
   * @param newOneFirst if true, move the new view as the first one (left or top)
68
   */
69 70
  KonqView* splitView( KonqView* view,
                       Qt::Orientation orientation,
71
                       bool newOneFirst = false, bool forceAutoEmbed = false );
72

73
  /**
74 75 76 77
   * 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.
78 79
   *
   * @param newOneFirst if true, move the new view as the first one (left or top)
80
   */
81 82 83 84 85
  KonqView* splitMainContainer( KonqView* currentView,
                            Qt::Orientation orientation,
                            const QString & serviceType = QString(),
                            const QString & serviceName = QString(),
                            bool newOneFirst = false );
Doug Hanley's avatar
 
Doug Hanley committed
86

Doug Hanley's avatar
 
Doug Hanley committed
87
  /**
David Faure's avatar
David Faure committed
88
   * Adds a tab to m_tabContainer
Doug Hanley's avatar
 
Doug Hanley committed
89
   */
David Faure's avatar
David Faure committed
90
  KonqView* addTab(const QString &serviceType,
Laurent Montel's avatar
Laurent Montel committed
91
                   const QString &serviceName = QString(),
92
                   bool passiveMode = false, bool openAfterCurrentPage = false );
93

94 95


Doug Hanley's avatar
 
Doug Hanley committed
96 97 98
  /**
   * Duplicates the specified tab, or else the current one if none is specified
   */
99
  void duplicateTab( KonqFrameBase* tab, bool openAfterCurrentPage = false );
Doug Hanley's avatar
 
Doug Hanley committed
100

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

Doug Hanley's avatar
 
Doug Hanley committed
107 108 109 110
  /**
   * Break the current tab off into a new window,
   * if none is specified, the current one is used
   */
111
  void breakOffTab( KonqFrameBase* tab, const QSize& windowSize );
Doug Hanley's avatar
 
Doug Hanley committed
112

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

Doug Hanley's avatar
 
Doug Hanley committed
119
  /**
120
   * Removes specified tab
Doug Hanley's avatar
 
Doug Hanley committed
121 122
   * Also takes care of setting another view as active if the active view was in this tab
   */
123
  void removeTab( KonqFrameBase* tab );
Doug Hanley's avatar
 
Doug Hanley committed
124

125
  /**
126
   * Removes all, but the specified tab.
127 128
   * Also takes care of setting the specified tab as active if the active view was not in this tab
   */
129
  void removeOtherTabs( KonqFrameBase* tab );
130

131 132 133 134 135 136 137 138 139 140 141 142
  /**
   * Locates and activates the next tab
   *
   */
  void activateNextTab();

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

Stephan Binner's avatar
 
Stephan Binner committed
143 144 145 146 147 148
  /**
   * Activate given tab
   *
   */
  void activateTab(int position);

149 150
    void moveTabBackward();
    void moveTabForward();
151

Laurent Montel's avatar
Laurent Montel committed
152
    void reloadAllTabs();
153

154 155 156

    KonqFrameTabs *tabContainer();

157 158 159 160 161 162
  /**
   * Brings the tab specified by @p view to the front of the stack
   *
   */
  void showTab( KonqView *view );

163 164 165 166 167
  /**
   * Updates favicon pixmaps used in tabs
   *
   */
  void updatePixmaps();
Stephan Binner's avatar
 
Stephan Binner committed
168

169
  /**
170
   * Saves the current view layout to a config file.
171
   * Remove config file before saving, especially if saveURLs is false.
172
   * @param cfg the config file
173 174
   * @param saveURLs whether to save the URLs in the profile
   * @param saveWindowSize whether to save the size of the window in the profile
175
   */
176 177 178 179 180 181 182 183 184 185 186 187
  void saveViewProfile( KConfig & cfg, bool saveURLs, bool saveWindowSize );

  /**
   * Saves the current view layout to a config file.
   * Remove config file before saving, especially if saveURLs is false.
   * @param fileName the name of the config file
   * @param profileName the name of the profile
   * @param saveURLs whether to save the URLs in the profile
   * @param saveWindowSize whether to save the size of the window in the profile
   */
  void saveViewProfile( const QString & fileName, const QString & profileName,
                        bool saveURLs, bool saveWindowSize );
188 189

  /**
190
   * Loads a view layout from a config file. Removes all views before loading.
191
   * @param cfg the config file
192
   * @param filename if set, remember the file name of the profile (for save settings)
Laurent Montel's avatar
Laurent Montel committed
193
   * It has to be under the profiles dir. Otherwise, set to QString()
194
   * @param forcedURL if set, the URL to open, whatever the profile says
195
   * @param req attributes related to @p forcedURL
196 197
   * @param resetWindow if the profile doesn't have attributes like size or toolbar
   * settings, they will be reset to the defaults
198
   */
199
  void loadViewProfile( KConfig& cfg, const QString & filename,
Laurent Montel's avatar
KURL--  
Laurent Montel committed
200
                        const KUrl & forcedURL = KUrl(),
201
                        const KonqOpenURLRequest &req = KonqOpenURLRequest(),
202
                        bool resetWindow = false, bool openUrl = true );
203

204 205
  /**
   * Loads a view layout from a config file. Removes all views before loading.
206 207
   * @param path the full path to the config file
   * @param filename if set, remember the file name of the profile (for save settings)
Laurent Montel's avatar
Laurent Montel committed
208
   * It has to be under the profiles dir. Otherwise, set to QString()
209
   * @param forcedURL if set, the URL to open, whatever the profile says
210
   * @param req attributes related to @p forcedURL
211 212
   * @param resetWindow if the profile doesn't have attributes like size or toolbar
   * settings, they will be reset to the defaults
213
   */
214
  void loadViewProfile( const QString & path, const QString & filename,
Laurent Montel's avatar
KURL--  
Laurent Montel committed
215
                        const KUrl & forcedURL = KUrl(),
216
                        const KonqOpenURLRequest &req = KonqOpenURLRequest(),
217
                        bool resetWindow = false, bool openUrl = true );
218 219 220 221 222
  /**
   * Return the filename of the last profile that was loaded
   * by the view manager. For "save settings".
   */
  QString currentProfile() const { return m_currentProfile; }
223 224 225 226 227
  /**
   * Return the name (i18n'ed) of the last profile that was loaded
   * by the view manager. For "save settings".
   */
  QString currentProfileText() const { return m_currentProfileText; }
228

229
  /**
230
   * Whether we are currently loading a profile
231
   */
232
  bool isLoadingProfile() const { return m_bLoadingProfile; }
233

234 235
  void clear();

236
  KonqView *chooseNextView( KonqView *view );
237

238 239 240 241 242 243 244 245
  /**
   * 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();

246
  void setProfiles( KActionMenu *profiles );
247

248
  void profileListDirty( bool broadcast = true );
249

250 251
//  KonqFrameBase *docContainer() const { return m_pDocContainer; }
//  void setDocContainer( KonqFrameBase* docContainer ) { m_pDocContainer = docContainer; }
252

253 254
  KonqMainWindow *mainWindow() const { return m_pMainWindow; }

255 256 257
  /**
   * Reimplemented from PartManager
   */
258 259 260 261 262
  virtual void removePart( KParts::Part * part );

  /**
   * Reimplemented from PartManager
   */
263
  virtual void setActivePart( KParts::Part *part, QWidget *widget = 0 );
264

265 266
  void setActivePart( KParts::Part *part, bool immediate );

267 268
  void showProfileDlg( const QString & preselectProfile );

George Staikos's avatar
 
George Staikos committed
269 270 271
  /**
   *   The widget is the one which you are referring to.
   */
272
  static QSize readConfigSize( KConfigGroup &cfg, QWidget *widget = NULL);
273

274
#ifndef NDEBUG
Doug Hanley's avatar
 
Doug Hanley committed
275
  void printFullHierarchy( KonqFrameContainerBase * container );
276
#endif
Doug Hanley's avatar
 
Doug Hanley committed
277

278
  void setLoading( KonqView *view, bool loading );
279

280 281 282
  void showHTML(bool b);

  QString profileHomeURL() const { return m_profileHomeURL; }
283

Laurent Montel's avatar
Laurent Montel committed
284
protected Q_SLOTS:
285 286
  void emitActivePartChanged();

287 288 289
  void slotProfileDlg();

  void slotProfileActivated( int id );
290 291

  void slotProfileListAboutToShow();
292

293 294
  void slotPassiveModePartDeleted();

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

297 298
protected:

299 300 301 302 303
  /**
   * 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
304
   * @param openUrl whether to open urls at all (from the profile or using @p defaultURL).
305 306
   *  (this is set to false when we have a forcedURL to open)
   */
307
  void loadItem( KConfigGroup &cfg, KonqFrameContainerBase *parent,
308
                 const QString &name, const KUrl & defaultURL, bool openUrl, bool openAfterCurrentPage = false );
309

310
  // Disabled - we do it ourselves
311
  virtual void setActiveComponent(const KComponentData &) {}
312

313
private:
314
  /**
315
   * Creates a new View based on the given ServiceType. If serviceType is empty
316
   * it clones the current view.
317
   * Returns the newly created view.
318
   */
319 320
  KonqViewFactory createView( const QString &serviceType,
                              const QString &serviceName,
321
                              KService::Ptr &service,
Aaron J. Seigo's avatar
Aaron J. Seigo committed
322 323
                              KService::List &partServiceOffers,
                              KService::List &appServiceOffers,
324
			      bool forceAutoEmbed = false );
325

326
  /**
327
   * Mainly creates the backend structure(KonqView) for a view and
328 329
   * connects it
   */
Doug Hanley's avatar
 
Doug Hanley committed
330
  KonqView *setupView( KonqFrameContainerBase *parentContainer,
331 332
                       KonqViewFactory &viewFactory,
                       const KService::Ptr &service,
Aaron J. Seigo's avatar
Aaron J. Seigo committed
333 334
                       const KService::List &partServiceOffers,
                       const KService::List &appServiceOffers,
335
                       const QString &serviceType,
336
                       bool passiveMode, bool openAfterCurrentPage = false);
337

338
#ifndef NDEBUG
339
  //just for debugging
340
  void printSizeInfo( KonqFrameBase* frame,
Doug Hanley's avatar
 
Doug Hanley committed
341
                      KonqFrameContainerBase* parent,
342
                      const char* msg );
343
#endif
344

345
  KonqMainWindow *m_pMainWindow;
Doug Hanley's avatar
 
Doug Hanley committed
346

347
  KonqFrameTabs *m_tabContainer;
348

349
  QPointer<KActionMenu> m_pamProfiles;
350
  bool m_bProfileListDirty;
351
  bool m_bLoadingProfile;
352
  QString m_currentProfile;
353
  QString m_currentProfileText;
354
  QString m_profileHomeURL;
355 356

  QMap<QString, QString> m_mapProfileNames;
357 358

  QTimer *m_activePartChangedTimer;
359 360 361
};

#endif