1/*
2 Copyright (C) 2001 Michael Jarrett <michaelj@corel.com>
3 Copyright (C) 2001 Carsten Pfeiffer <pfeiffer@kde.org>
4 Copyright (C) 2009 Shaun Reich <shaun.reich@kdemail.net>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License version 2 as published by the Free Software Foundation.
9
10 This library 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 GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#ifndef KDIRSELECTDIALOG_H
22#define KDIRSELECTDIALOG_H
23
24#include <kfile_export.h>
25
26#include <kdialog.h>
27#include <kurl.h>
28
29class QAbstractItemView;
30
31/**
32 * A pretty dialog for a KDirSelect control for selecting directories.
33 * @author Michael Jarrett <michaelj@corel.com>
34 * @see KFileDialog
35 */
36class KFILE_EXPORT KDirSelectDialog : public KDialog
37{
38 Q_OBJECT
39
40public:
41 /**
42 * Creates a new directory selection dialog.
43 * @internal use the static selectDirectory function
44 * @param startDir the directory, initially shown
45 * @param localOnly unused. You can only select paths below the startDir
46 * @param parent the parent for the dialog, usually 0L
47 */
48 explicit KDirSelectDialog(const KUrl& startDir = KUrl(),
49 bool localOnly = false,
50 QWidget *parent = 0L);
51
52 /**
53 * Destroys the directory selection dialog.
54 */
55 ~KDirSelectDialog();
56
57 /**
58 * Returns the currently selected URL, or an empty one if no item is selected.
59 *
60 * If the URL entered in the combobox is valid and exists, it is returned.
61 * Otherwise, the URL selected in the treeview is returned instead.
62 */
63 KUrl url() const;
64
65 /**
66 * Returns a pointer to the view which is used for displaying the directories.
67 */
68 QAbstractItemView* view() const;
69
70 /**
71 * Returns whether only local directories can be selected.
72 */
73 bool localOnly() const;
74
75 /**
76 * Creates a KDirSelectDialog, and returns the result.
77 * @param startDir the directory, initially shown
78 * The tree will display this directory and subdirectories of it.
79 * @param localOnly unused. You can only select paths below the startDir
80 * @param parent the parent widget to use for the dialog, or NULL to create a parent-less dialog
81 * @param caption the caption to use for the dialog, or QString() for the default caption
82 * @return The URL selected, or an empty URL if the user canceled
83 * or no URL was selected.
84 *
85 * NOTE: if you use this method and nothing else from libkfile,
86 * then you can use KFileDialog::getExistingDirectory (if localOnly was true)
87 * or KFileDialog::getExistingDirectoryUrl (if localOnly was false),
88 * and then you can link to libkio only instead of libkfile.
89 */
90 static KUrl selectDirectory( const KUrl& startDir = KUrl(),
91 bool localOnly = false, QWidget *parent = 0L,
92 const QString& caption = QString());
93
94 /**
95 * @return The path for the root node
96 */
97 KUrl startDir() const;
98
99public Q_SLOTS:
100 /**
101 * Sets the current @p url in the dialog.
102 */
103 void setCurrentUrl( const KUrl& url );
104
105protected:
106 virtual void accept();
107
108 /**
109 * Reimplemented for saving the dialog geometry.
110 */
111 virtual void hideEvent( QHideEvent *event );
112
113private:
114 class Private;
115 Private* const d;
116
117 Q_PRIVATE_SLOT( d, void slotCurrentChanged() )
118 Q_PRIVATE_SLOT( d, void slotExpand(const QModelIndex&) )
119 Q_PRIVATE_SLOT( d, void slotUrlActivated(const QString&) )
120 Q_PRIVATE_SLOT( d, void slotComboTextChanged(const QString&) )
121 Q_PRIVATE_SLOT( d, void slotContextMenuRequested(const QPoint&) )
122 Q_PRIVATE_SLOT( d, void slotNewFolder() )
123 Q_PRIVATE_SLOT( d, void slotMoveToTrash() )
124 Q_PRIVATE_SLOT( d, void slotDelete() )
125 Q_PRIVATE_SLOT( d, void slotProperties() )
126};
127
128#endif
129