]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.h
Fix infinite recursion if the default text is empty.
[dolphin.git] / src / dolphinmainwindow.h
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com> *
4 * Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 #ifndef DOLPHIN_MAINWINDOW_H
23 #define DOLPHIN_MAINWINDOW_H
24
25 #include "dolphinview.h"
26 #include "panels/panel.h"
27
28 #include <config-nepomuk.h>
29
30 #include <kfileitemdelegate.h>
31 #include <kio/fileundomanager.h>
32 #include <ksortablelist.h>
33 #include <kxmlguiwindow.h>
34 #include <kactionmenu.h>
35
36 #include <QtCore/QList>
37
38 typedef KIO::FileUndoManager::CommandType CommandType;
39
40 class KAction;
41 class DolphinViewActionHandler;
42 class DolphinApplication;
43 class DolphinSearchBox;
44 class DolphinSettingsDialog;
45 class DolphinViewContainer;
46 class DolphinRemoteEncoding;
47 class KNewMenu;
48 class KTabBar;
49 class KUrl;
50 class QSplitter;
51
52 /**
53 * @short Main window for Dolphin.
54 *
55 * Handles the menus, toolbars and Dolphin views.
56 */
57 class DolphinMainWindow: public KXmlGuiWindow
58 {
59 Q_OBJECT
60 Q_CLASSINFO("D-Bus Interface", "org.kde.dolphin.MainWindow")
61 Q_PROPERTY(int id READ getId SCRIPTABLE true)
62 friend class DolphinApplication;
63
64 public:
65 virtual ~DolphinMainWindow();
66
67 /**
68 * Returns the currently active view.
69 * All menu actions are applied to this view. When
70 * having a split view setup, the nonactive view
71 * is usually shown in darker colors.
72 */
73 DolphinViewContainer* activeViewContainer() const;
74
75 /**
76 * Returns true, if the main window contains two instances
77 * of a view container. The active view constainer can be
78 * accessed by DolphinMainWindow::activeViewContainer().
79 */
80 bool isSplit() const;
81
82 /**
83 * If the main window contains two instances of a view container
84 * (DolphinMainWindow::isSplit() returns true), then the
85 * two views get toggled (the right view is on the left, the left
86 * view on the right).
87 */
88 void toggleViews();
89
90 /** Renames the item represented by \a oldUrl to \a newUrl. */
91 void rename(const KUrl& oldUrl, const KUrl& newUrl);
92
93 /**
94 * Refreshes the views of the main window by recreating them dependent from
95 * the given Dolphin settings.
96 */
97 void refreshViews();
98
99 /**
100 * Returns the 'Create New...' sub menu which also can be shared
101 * with other menus (e. g. a context menu).
102 */
103 KNewMenu* newMenu() const;
104
105 /**
106 * Returns the 'Show Menubar' action which can be shared with
107 * other menus (e. g. a context menu).
108 */
109 KAction* showMenuBarAction() const;
110
111 public slots:
112 /**
113 * Pastes the clipboard data into the currently selected folder
114 * of the active view. If not exactly one folder is selected,
115 * no pasting is done at all.
116 */
117 void pasteIntoFolder();
118
119 /**
120 * Returns the main window ID used through DBus.
121 */
122 int getId() const;
123
124 /**
125 * Inform all affected dolphin components (panels, views) of an URL
126 * change.
127 */
128 void changeUrl(const KUrl& url);
129
130 /**
131 * Inform all affected dolphin components that a selection change is
132 * requested.
133 */
134 void changeSelection(const KFileItemList& selection);
135
136 /** Stores all settings and quits Dolphin. */
137 void quit();
138
139 signals:
140 /**
141 * Is sent if the selection of the currently active view has
142 * been changed.
143 */
144 void selectionChanged(const KFileItemList& selection);
145
146 /**
147 * Is sent if the url of the currently active view has
148 * been changed.
149 */
150 void urlChanged(const KUrl& url);
151
152 /**
153 * Is emitted if information of an item is requested to be shown e. g. in the panel.
154 * If item is null, no item information request is pending.
155 */
156 void requestItemInfo(const KFileItem& item);
157
158 protected:
159 /** @see QMainWindow::closeEvent() */
160 virtual void closeEvent(QCloseEvent* event);
161
162 /** @see KMainWindow::saveProperties() */
163 virtual void saveProperties(KConfigGroup& group);
164
165 /** @see KMainWindow::readProperties() */
166 virtual void readProperties(const KConfigGroup& group);
167
168 private slots:
169 void clearStatusBar();
170
171 /** Updates the 'Create New...' sub menu. */
172 void updateNewMenu();
173
174 void createDirectory();
175
176 /** Shows the error message in the status bar of the active view. */
177 void showErrorMessage(const QString& message);
178
179 /**
180 * Updates the state of the 'Undo' menu action dependent
181 * from the parameter \a available.
182 */
183 void slotUndoAvailable(bool available);
184
185 /** Invoked when an action in the recent tabs menu is clicked. */
186 void restoreClosedTab(QAction* action);
187
188 /** Sets the text of the 'Undo' menu action to \a text. */
189 void slotUndoTextChanged(const QString& text);
190
191 /** Performs the current undo operation. */
192 void undo();
193
194 /**
195 * Copies all selected items to the clipboard and marks
196 * the items as cutted.
197 */
198 void cut();
199
200 /** Copies all selected items to the clipboard. */
201 void copy();
202
203 /** Pastes the clipboard data to the active view. */
204 void paste();
205
206 /**
207 * Updates the text of the paste action dependent from
208 * the number of items which are in the clipboard.
209 */
210 void updatePasteAction();
211
212 /** Selects all items from the active view. */
213 void selectAll();
214
215 /**
216 * Inverts the selection of all items of the active view:
217 * Selected items get nonselected and nonselected items get
218 * selected.
219 */
220 void invertSelection();
221
222 /**
223 * Switches between one and two views:
224 * If one view is visible, it will get split into two views.
225 * If already two views are visible, the nonactivated view gets closed.
226 */
227 void toggleSplitView();
228
229 /** Reloads the current active view. */
230 void reloadView();
231
232 /** Stops the loading process for the current active view. */
233 void stopLoading();
234
235 /**
236 * Toggles between showing and hiding of the filter bar
237 */
238 void toggleFilterBarVisibility(bool show);
239
240 /**
241 * Toggles between edit and browse mode of the navigation bar.
242 */
243 void toggleEditLocation();
244
245 /**
246 * Switches to the edit mode of the navigation bar and selects
247 * the whole URL, so that it can be replaced by the user. If the edit mode is
248 * already active, it is assured that the navigation bar get focused.
249 */
250 void replaceLocation();
251
252 /** Goes back on step of the URL history. */
253 void goBack();
254
255 /** Goes forward one step of the URL history. */
256 void goForward();
257
258 /** Goes up one hierarchy of the current URL. */
259 void goUp();
260
261 /** Goes to the home URL. */
262 void goHome();
263
264 /** Opens Kompare for 2 selected files. */
265 void compareFiles();
266
267 /**
268 * Hides the menu bar if it is visible, makes the menu bar
269 * visible if it is hidden.
270 */
271 void toggleShowMenuBar();
272
273 /** Opens a terminal window for the current location. */
274 void openTerminal();
275
276 /** Opens the settings dialog for Dolphin. */
277 void editSettings();
278
279 /** Updates the state of the 'Show Full Location' action. */
280 void slotEditableStateChanged(bool editable);
281
282 /**
283 * Updates the state of the 'Edit' menu actions and emits
284 * the signal selectionChanged().
285 */
286 void slotSelectionChanged(const KFileItemList& selection);
287
288 /** Enables changing of tabs via mouse wheel. */
289 void slotWheelMoved(int wheelDelta);
290
291 /** Emits the signal requestItemInfo(). */
292 void slotRequestItemInfo(const KFileItem&);
293
294 /**
295 * Updates the state of the 'Back' and 'Forward' menu
296 * actions corresponding to the current history.
297 */
298 void updateHistory();
299
300 /** Updates the state of the 'Show filter bar' menu action. */
301 void updateFilterBarAction(bool show);
302
303 /** Open a new main window. */
304 void openNewMainWindow();
305
306 /** Opens a new view with the current URL that is part of a tab. */
307 void openNewTab();
308
309 /**
310 * Opens a new tab showing the URL \a url.
311 */
312 void openNewTab(const KUrl& url);
313
314 void activateNextTab();
315
316 void activatePrevTab();
317
318 /**
319 * Opens the selected folder in a new tab.
320 */
321 void openInNewTab();
322
323 /**
324 * Opens the selected folder in a new window.
325 */
326 void openInNewWindow();
327
328 /** Toggles the active view if two views are shown within the main window. */
329 void toggleActiveView();
330
331 /**
332 * Indicates in the statusbar that the execution of the command \a command
333 * has been finished.
334 */
335 void showCommand(CommandType command);
336
337 /**
338 * Activates the tab with the index \a index, which means that the current view
339 * is replaced by the view of the given tab.
340 */
341 void setActiveTab(int index);
342
343 /** Closes the currently active tab. */
344 void closeTab();
345
346 /**
347 * Closes the tab with the index \index and activates the tab with index - 1.
348 */
349 void closeTab(int index);
350
351
352 /**
353 * Opens a context menu for the tab with the index \a index
354 * on the position \a pos.
355 */
356 void openTabContextMenu(int index, const QPoint& pos);
357
358 /**
359 * Handles a click on a places item: if the middle mouse button is
360 * clicked, a new tab is opened for \a url, otherwise the current
361 * view is replaced by \a url.
362 */
363 void handlePlacesClick(const KUrl& url, Qt::MouseButtons buttons);
364
365 /**
366 * Is connected to the KTabBar signal testCanDecode() and adjusts
367 * the output parameter \a accept.
368 */
369 void slotTestCanDecode(const QDragMoveEvent* event, bool& accept);
370
371 /**
372 * Is connected with the Dolphin search box and searchs items that
373 * match to the text entered in the search bar.
374 */
375 void searchItems(const KUrl& url);
376
377 /**
378 * Is connected to the QTabBar signal tabMoved(int from, int to).
379 * Reorders the list of tabs after a tab was moved in the tab bar
380 * and sets m_tabIndex to the new index of the current tab.
381 */
382 void slotTabMoved(int from, int to);
383
384 private:
385 DolphinMainWindow(int id);
386 void init();
387
388 /**
389 * Activates the given view, which means that
390 * all menu actions are applied to this view. When
391 * having a split view setup, the nonactive view
392 * is usually shown in darker colors.
393 */
394 void setActiveViewContainer(DolphinViewContainer* view);
395
396 void setupActions();
397 void setupDockWidgets();
398 void updateEditActions();
399 void updateViewActions();
400 void updateGoActions();
401
402 /**
403 * Adds the tab[\a index] to the closed tab menu's list of actions.
404 */
405 void rememberClosedTab(int index);
406
407 /**
408 * Connects the signals from the created DolphinView with
409 * the DolphinViewContainer \a container with the corresponding slots of
410 * the DolphinMainWindow. This method must be invoked each
411 * time a DolphinView has been created.
412 */
413 void connectViewSignals(DolphinViewContainer* container);
414
415 /**
416 * Updates the text of the split action:
417 * If two views are shown, the text is set to "Split",
418 * otherwise the text is set to "Join". The icon
419 * is updated to match with the text and the currently active view.
420 */
421 void updateSplitAction();
422
423 /** Returns the name of the tab for the URL \a url. */
424 QString tabName(const KUrl& url) const;
425
426 bool isKompareInstalled() const;
427
428 void createSecondaryView(int tabIndex);
429
430 /**
431 * Helper method for saveProperties() and readProperties(): Returns
432 * the property string for a tab with the index \a tabIndex and
433 * the property \a property.
434 */
435 QString tabProperty(const QString& property, int tabIndex) const;
436
437 /**
438 * Sets the window caption to url.fileName() if this is non-empty,
439 * "/" if the URL is "file:///", and url.protocol() otherwise.
440 */
441 void setUrlAsCaption(const KUrl& url);
442
443 QString squeezedText(const QString& text) const;
444
445 private:
446 /**
447 * Implements a custom error handling for the undo manager. This
448 * assures that all errors are shown in the status bar of Dolphin
449 * instead as modal error dialog with an OK button.
450 */
451 class UndoUiInterface : public KIO::FileUndoManager::UiInterface
452 {
453 public:
454 UndoUiInterface();
455 virtual ~UndoUiInterface();
456 virtual void jobError(KIO::Job* job);
457 };
458
459 KNewMenu* m_newMenu;
460 KActionMenu* m_recentTabsMenu;
461 KAction* m_showMenuBar;
462 KTabBar* m_tabBar;
463 DolphinViewContainer* m_activeViewContainer;
464 QVBoxLayout* m_centralWidgetLayout;
465 DolphinSearchBox* m_searchBox;
466 int m_id;
467
468 struct ViewTab
469 {
470 ViewTab() : isPrimaryViewActive(true), primaryView(0), secondaryView(0), splitter(0) {}
471 bool isPrimaryViewActive;
472 DolphinViewContainer* primaryView;
473 DolphinViewContainer* secondaryView;
474 QSplitter* splitter;
475 };
476
477 int m_tabIndex;
478 QList<ViewTab> m_viewTab;
479
480 DolphinViewActionHandler* m_actionHandler;
481 DolphinRemoteEncoding* m_remoteEncoding;
482 QPointer<DolphinSettingsDialog> m_settingsDialog;
483 };
484
485 inline DolphinViewContainer* DolphinMainWindow::activeViewContainer() const
486 {
487 return m_activeViewContainer;
488 }
489
490 inline bool DolphinMainWindow::isSplit() const
491 {
492 return m_viewTab[m_tabIndex].secondaryView != 0;
493 }
494
495 inline KNewMenu* DolphinMainWindow::newMenu() const
496 {
497 return m_newMenu;
498 }
499
500 inline KAction* DolphinMainWindow::showMenuBarAction() const
501 {
502 return m_showMenuBar;
503 }
504
505 inline int DolphinMainWindow::getId() const
506 {
507 return m_id;
508 }
509
510 #endif // DOLPHIN_MAINWINDOW_H
511