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> *
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. *
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. *
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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 ***************************************************************************/
29 #include <kapplication.h>
30 #include <kmainwindow.h>
31 #include <q3valuelist.h>
32 #include <q3ptrlist.h>
35 #include <QCloseEvent>
36 #include <ksortablelist.h>
38 #include "dolphinview.h"
39 #include "undomanager.h"
53 * @short Main window for Dolphin.
55 * Handles the menus, toolbars and Dolphin views.
57 * @author Peter Penz <peter.penz@gmx.at>
59 class Dolphin
: public KMainWindow
65 * Returns the instance for the Dolphin main window.
67 // KXMLGUIClient::instance() already in use :-(
68 static Dolphin
& mainWin();
73 * Activates the given view, which means that
74 * all menu actions are applied to this view. When
75 * having a split view setup the nonactive view
76 * is usually shown in darker colors.
78 void setActiveView(DolphinView
* view
);
81 * Returns the currently active view. See
82 * Dolphin::setActiveView() for more details.
84 DolphinView
* activeView() const { return m_activeView
; }
87 * Handles the dropping of URLs to the given
88 * destination. A context menu with the options
89 * 'Move Here', 'Copy Here', 'Link Here' and
90 * 'Cancel' is offered to the user.
91 * @param urls List of URLs which have been
93 * @param destination Destination URL, where the
94 * list or URLs should be moved,
95 * copied or linked to.
97 void dropURLs(const KUrl::List
& urls
,
98 const KUrl
& destination
);
101 * Returns 'true', if the clipboard contains data
102 * which has been cutted by the Cut action (Ctrl + X).
104 bool clipboardContainsCutData() const { return m_clipboardContainsCutData
; }
107 * Returns the list of actions which are part of the file group
108 * of the 'Create New...' sub menu. Usually the list contains actions
109 * for creating folders, text files, HTML files etc.
111 const Q3PtrList
<KAction
>& fileGroupActions() const { return m_fileGroupActions
; }
112 //const QPtrList<KAction>& linkGroupActions() const { return m_linkGroupActions; }
113 //const QPtrList<KAction>& linkToDeviceActions() const { return m_linkToDeviceActions; }
116 * Refreshs the views of the main window by recreating them dependent from
117 * the given Dolphin settings.
123 * Is send if the active view has been changed in
124 * the split view mode.
126 void activeViewChanged();
129 * Is send if the selection of the currently active view has
132 void selectionChanged();
136 * Updates the state of the 'Back' and 'Forward' menu
137 * actions corresponding the the current history.
139 void slotHistoryChanged();
142 * Updates the caption of the main window and the state
143 * of all menu actions which depend from a changed URL.
145 void slotURLChanged(const KUrl
& url
);
148 * Go to the given URL.
150 void slotURLChangeRequest(const KUrl
& url
);
152 /** Updates the state of all 'View' menu actions. */
153 void slotViewModeChanged();
155 /** Updates the state of the 'Show hidden files' menu action. */
156 void slotShowHiddenFilesChanged();
158 /** Updates the state of the 'Show filter bar' menu action. */
159 void slotShowFilterBarChanged();
161 /** Updates the state of the 'Sort by' actions. */
162 void slotSortingChanged(DolphinView::Sorting sorting
);
164 /** Updates the state of the 'Sort Ascending/Descending' action. */
165 void slotSortOrderChanged(Qt::SortOrder order
);
167 /** Updates the state of the 'Edit' menu actions. */
168 void slotSelectionChanged();
171 /** @see QMainWindow::closeEvent */
172 virtual void closeEvent(QCloseEvent
* event
);
175 * This method is called when it is time for the app to save its
176 * properties for session management purposes.
178 void saveProperties(KConfig
*);
181 * This method is called when this app is restored. The KConfig
182 * object points to the session management config file that was saved
183 * with @ref saveProperties
185 void readProperties(KConfig
*);
188 /** Opens an input dialog for creating a new folder. */
191 /** Creates a file with the MIME type given by the sender. */
194 /** Renames the selected item of the active view. */
197 /** Moves the selected items of the active view to the trash. */
200 /** Deletes the selected items of the active view. */
204 * Opens the properties window for the selected items of the
205 * active view. The properties windows shows informations
206 * like name, size and permissions.
210 /** Stores all settings and quits Dolphin. */
214 * Shows the error information of the job \a job
217 void slotHandleJobError(KIO::Job
* job
);
220 * Indicates in the status bar that the delete operation
221 * of the job \a job has been finished.
223 void slotDeleteFileFinished(KIO::Job
* job
);
226 * Updates the state of the 'Undo' menu action dependent
227 * from the parameter \a available.
229 void slotUndoAvailable(bool available
);
231 /** Sets the text of the 'Undo' menu action to \a text. */
232 void slotUndoTextChanged(const QString
& text
);
235 * Updates the state of the 'Redo' menu action dependent
236 * from the parameter \a available.
238 void slotRedoAvailable(bool available
);
240 /** Sets the text of the 'Redo' menu action to \a text. */
241 void slotRedoTextChanged(const QString
& text
);
244 * Copies all selected items to the clipboard and marks
245 * the items as cutted.
249 /** Copies all selected items to the clipboard. */
252 /** Pastes the clipboard data to the active view. */
256 * Updates the text of the paste action dependent from
257 * the number of items which are in the clipboard.
259 void updatePasteAction();
261 /** Selects all items from the active view. */
265 * Inverts the selection of all items of the active view:
266 * Selected items get nonselected and nonselected items get
269 void invertSelection();
271 /** The current active view is switched to the icons mode. */
274 /** The current active view is switched to the details mode. */
275 void setDetailsView();
277 /** The current active view is switched to the previews mode. */
278 void setPreviewsView();
280 /** The sorting of the current view should be done by the name. */
283 /** The sorting of the current view should be done by the size. */
286 /** The sorting of the current view should be done by the date. */
289 /** Switches between an ascending and descending sorting order. */
290 void toggleSortOrder();
293 * Switches between one and two views:
294 * If one view is visible, it will get split into two views.
295 * If already two views are visible, the nonactivated view gets closed.
297 void toggleSplitView();
299 /** Reloads the current active view. */
302 /** Stops the loading process for the current active view. */
306 * Switches between showing and hiding of hidden marked files dependent
307 * from the current state of the 'Show Hidden Files' menu toggle action.
309 void showHiddenFiles();
312 * Switches between showing and hiding of the filter bar dependent
313 * from the current state of the 'Show Filter Bar' menu toggle action.
315 void showFilterBar();
317 /** Increases the size of the current set view mode. */
320 /** Decreases the size of the current set view mode. */
324 * Toggles between edit and brose mode of the navigation bar.
326 void toggleEditLocation();
329 * Switches to the edit mode of the navigation bar. If the edit mode is
330 * already active, it is assured that the navigation bar get focused.
335 * Opens the view properties dialog, which allows to modify the properties
336 * of the currently active view.
338 void adjustViewProperties();
340 /** Goes back on step of the URL history. */
343 /** Goes forward one step of the URL history. */
346 /** Goes up one hierarchy of the current URL. */
349 /** Goes to the home URL. */
352 /** Opens a terminal for the current shown directory. */
355 /** Opens KFind for the current shown directory. */
358 /** Opens Kompare for 2 selected files. */
361 /** Opens the settings dialog for Dolphin. */
365 * Adds the undo operation given by \a job
366 * to the UndoManager.
368 void addUndoOperation(KIO::Job
* job
);
371 void toggleSidebar();
374 * Stores the current sidebar width and closes
386 void setupCreateNewMenuActions();
387 void updateHistory();
388 void updateEditActions();
389 void updateViewActions();
390 void updateGoActions();
391 void updateViewProperties(const KUrl::List
& urls
);
392 void copyURLs(const KUrl::List
& source
, const KUrl
& dest
);
393 void moveURLs(const KUrl::List
& source
, const KUrl
& dest
);
394 void addPendingUndoJob(KIO::Job
* job
,
395 DolphinCommand::Type commandType
,
396 const KUrl::List
& source
,
398 void clearStatusBar();
401 QSplitter
* m_splitter
;
403 DolphinView
* m_activeView
;
406 * Dolphin supports only one or two views, which
407 * are handled internally as primary and secondary view.
414 DolphinView
* m_view
[SecondaryIdx
+ 1];
416 /// If set to true, the clipboard contains data which should be cutted after pasting.
417 bool m_clipboardContainsCutData
;
420 * Asynchronous operations like 'Move' and 'Copy' may only be added as undo
421 * operation after they have been finished successfully. When an asynchronous
422 * operation is started, it is added to a pending undo jobs list in the meantime.
423 * As soon as the job has been finished, the operation is added to the undo mangager.
425 * @see Dolphin::addPendingUndoJob
426 * @see Dolphin::addUndoOperation
431 DolphinCommand command
;
433 Q3ValueList
<UndoInfo
> m_pendingUndoJobs
;
435 /** Contains meta information for creating files. */
436 struct CreateFileEntry
440 QString templatePath
;
445 Q3PtrList
<KAction
> m_fileGroupActions
;
446 KSortableList
<CreateFileEntry
,QString
> m_createFileTemplates
;
448 // TODO: not used yet. See documentation of Dolphin::linkGroupActions()
449 // and Dolphin::linkToDeviceActions() in for details.
450 //QPtrList<KAction> m_linkGroupActions;
451 //QPtrList<KAction> m_linkToDeviceActions;
454 #endif // _DOLPHIN_H_