23 #include <QtCore/QDir>
24 #include <QtCore/QStringList>
25 #include <QtGui/QLayout>
62 class KDirSelectDialog::Private
67 m_localOnly( localOnly ),
68 m_comboLocked( false ),
77 void slotCurrentChanged();
78 void slotExpand(
const QModelIndex&);
79 void slotUrlActivated(
const QString&);
80 void slotComboTextChanged(
const QString&);
81 void slotContextMenuRequested(
const QPoint&);
83 void slotMoveToTrash();
85 void slotProperties();
89 bool m_comboLocked : 1;
101 KAction* showHiddenFoldersAction;
109 m_urlCombo->setHistoryItems( conf.readPathEntry(
"History Items",
QStringList() ));
111 const QSize size = conf.readEntry(
"DirSelectDialog Size",
QSize());
112 if (size.isValid()) {
113 m_parent->resize(size);
120 KConfigGroup::WriteConfigFlags flags(KConfigGroup::Persistent|KConfigGroup::Global);
121 conf.writePathEntry(
"History Items", m_urlCombo->historyItems(), flags );
122 conf.writeEntry(
"DirSelectDialog Size", m_parent->size(), flags );
127 void KDirSelectDialog::Private::slotMkdir()
130 QString where = m_parent->url().pathOrUrl();
132 if ( m_parent->url().isLocalFile() && QFileInfo( m_parent->url().path(
KUrl::AddTrailingSlash) + name ).exists() )
136 i18nc(
"@label:textbox",
"Create new folder in:\n%1" , where ),
137 name, &ok, m_parent));
141 bool selectDirectory =
true;
142 bool writeOk =
false;
144 KUrl folderurl( m_parent->url() );
146 const QStringList dirs = directory.split(
'/', QString::SkipEmptyParts );
147 QStringList::ConstIterator it = dirs.begin();
149 for ( ; it != dirs.end(); ++it )
151 folderurl.addPath( *it );
158 QString which = folderurl.isLocalFile() ? folderurl.path() : folderurl.prettyUrl();
160 selectDirectory =
false;
162 else if ( !writeOk ) {
165 else if ( selectDirectory ) {
166 m_parent->setCurrentUrl( folderurl );
170 void KDirSelectDialog::Private::slotCurrentChanged()
175 const KUrl u = m_treeView->currentUrl();
183 m_urlCombo->setEditText( u.
prettyUrl() );
186 m_urlCombo->setEditText(
QString() );
189 void KDirSelectDialog::Private::slotUrlActivated(
const QString& text )
191 if ( text.isEmpty() )
195 m_urlCombo->addToHistory( url.prettyUrl() );
197 if ( m_parent->localOnly() && !url.isLocalFile() )
200 KUrl oldUrl = m_treeView->currentUrl();
201 if ( oldUrl.isEmpty() )
204 m_parent->setCurrentUrl( oldUrl );
207 void KDirSelectDialog::Private::slotComboTextChanged(
const QString& text )
209 m_treeView->blockSignals(
true);
212 if( url.isLocalFile() && !m_treeView->rootUrl().isParentOf( url ) )
215 while(tmp !=
KUrl(
"file:///")) {
219 m_treeView->setRootUrl( url );
222 m_treeView->setCurrentUrl( url );
223 m_treeView->blockSignals(
false );
226 void KDirSelectDialog::Private::slotContextMenuRequested(
const QPoint& pos )
228 m_contextMenu->popup( m_treeView->viewport()->mapToGlobal(pos) );
231 void KDirSelectDialog::Private::slotExpand(
const QModelIndex &index)
233 m_treeView->setExpanded(index, !m_treeView->isExpanded(index));
236 void KDirSelectDialog::Private::slotNewFolder()
241 void KDirSelectDialog::Private::slotMoveToTrash()
243 const KUrl url = m_treeView->selectedUrl();
247 copyJob->ui()->setWindow(m_parent);
248 copyJob->ui()->setAutoErrorHandlingEnabled(
true);
252 void KDirSelectDialog::Private::slotDelete()
254 const KUrl url = m_treeView->selectedUrl();
258 deleteJob->ui()->setWindow(m_parent);
259 deleteJob->ui()->setAutoErrorHandlingEnabled(
true);
263 void KDirSelectDialog::Private::slotProperties()
267 dialog->setAttribute(Qt::WA_DeleteOnClose);
275 :
KDialog( parent , Qt::WindowMinMaxButtonsHint),
279 d(
new Private( localOnly,
this ) )
281 setCaption(
i18nc(
"@title:window",
"Select Folder") );
283 setButtonGuiItem( User1,
KGuiItem(
i18nc(
"@action:button",
"New Folder..."),
"folder-new" ) );
284 setDefaultButton(
Ok);
285 button(
Ok)->setFocus();
289 QHBoxLayout *hlay =
new QHBoxLayout( page);
291 QVBoxLayout *mainLayout =
new QVBoxLayout();
293 d->m_actions->addAssociatedWidget(
this);
296 d->m_placesView->setObjectName( QLatin1String(
"speedbar" ) );
297 d->m_placesView->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
298 d->m_placesView->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
299 connect( d->m_placesView, SIGNAL(urlChanged(
KUrl)),
300 SLOT(setCurrentUrl(
KUrl)) );
301 hlay->addWidget( d->m_placesView );
302 hlay->addLayout( mainLayout );
305 d->m_treeView->setDirOnlyMode(
true);
306 d->m_treeView->setContextMenuPolicy(Qt::CustomContextMenu);
308 for (
int i = 1; i < d->m_treeView->model()->columnCount(); ++i)
309 d->m_treeView->hideColumn(i);
312 d->m_urlCombo->setLayoutDirection( Qt::LeftToRight );
313 d->m_urlCombo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
314 d->m_urlCombo->setTrapReturnKey(
true );
317 comp->setMode( KUrlCompletion::DirCompletion );
318 d->m_urlCombo->setCompletionObject( comp,
true );
319 d->m_urlCombo->setAutoDeleteCompletionObject(
true );
320 d->m_urlCombo->setDuplicatesEnabled(
false );
322 d->m_contextMenu =
new KMenu(
this );
325 d->m_actions->addAction( newFolder->objectName(), newFolder );
326 newFolder->setIcon(
KIcon(
"folder-new" ) );
328 connect( newFolder, SIGNAL(triggered(
bool)),
this, SLOT(slotNewFolder()) );
329 d->m_contextMenu->addAction( newFolder );
331 d->moveToTrash =
new KAction(
i18nc(
"@action:inmenu",
"Move to Trash" ),
this );
332 d->m_actions->addAction( d->moveToTrash->objectName(), d->moveToTrash );
333 d->moveToTrash->setIcon(
KIcon(
"user-trash" ) );
334 d->moveToTrash->setShortcut(
KShortcut(Qt::Key_Delete));
335 connect( d->moveToTrash, SIGNAL(triggered(
bool)),
this, SLOT(slotMoveToTrash()) );
336 d->m_contextMenu->addAction( d->moveToTrash );
338 d->deleteAction =
new KAction(
i18nc(
"@action:inmenu",
"Delete"),
this );
339 d->m_actions->addAction( d->deleteAction->objectName(), d->deleteAction );
340 d->deleteAction->setIcon(
KIcon(
"edit-delete" ) );
341 d->deleteAction->setShortcut(
KShortcut( Qt::SHIFT + Qt::Key_Delete ) );
342 connect( d->deleteAction, SIGNAL(triggered(
bool)),
this, SLOT(slotDelete()) );
343 d->m_contextMenu->addAction( d->deleteAction );
345 d->m_contextMenu->addSeparator();
347 d->showHiddenFoldersAction =
new KToggleAction(
i18nc(
"@option:check",
"Show Hidden Folders"),
this );
348 d->m_actions->addAction( d->showHiddenFoldersAction->objectName(), d->showHiddenFoldersAction );
349 d->showHiddenFoldersAction->setShortcut( Qt::Key_F8 );
350 connect( d->showHiddenFoldersAction, SIGNAL(triggered(
bool)), d->m_treeView, SLOT(setShowHiddenFiles(
bool)) );
351 d->m_contextMenu->addAction( d->showHiddenFoldersAction );
352 d->m_contextMenu->addSeparator();
355 d->m_actions->addAction(propertiesAction->objectName(), propertiesAction);
356 propertiesAction->setIcon(
KIcon(
"document-properties"));
358 connect( propertiesAction, SIGNAL(triggered(
bool)),
this, SLOT(slotProperties()) );
359 d->m_contextMenu->addAction( propertiesAction );
361 d->m_startURL = KFileDialog::getStartUrl( startDir, d->m_recentDirClass );
362 if ( localOnly && !d->m_startURL.isLocalFile() )
364 d->m_startURL =
KUrl();
366 if (QDir(docPath).exists())
367 d->m_startURL.setPath( docPath );
369 d->m_startURL.setPath( QDir::homePath() );
372 d->m_startDir = d->m_startURL;
373 d->m_rootUrl = d->m_treeView->rootUrl();
377 mainLayout->addWidget( d->m_treeView, 1 );
378 mainLayout->addWidget( d->m_urlCombo, 0 );
380 connect( d->m_treeView, SIGNAL(currentChanged(
KUrl)),
381 SLOT(slotCurrentChanged()));
382 connect( d->m_treeView, SIGNAL(activated(QModelIndex)),
383 SLOT(slotExpand(QModelIndex)));
384 connect( d->m_treeView, SIGNAL(customContextMenuRequested(
QPoint)),
385 SLOT(slotContextMenuRequested(
QPoint)));
387 connect( d->m_urlCombo, SIGNAL(editTextChanged(
QString)),
388 SLOT(slotComboTextChanged(
QString)));
389 connect( d->m_urlCombo, SIGNAL(activated(
QString)),
390 SLOT(slotUrlActivated(
QString)));
391 connect( d->m_urlCombo, SIGNAL(returnPressed(
QString)),
392 SLOT(slotUrlActivated(
QString)));
394 connect(
this, SIGNAL(user1Clicked()),
this, SLOT(slotNewFolder()));
396 setCurrentUrl(d->m_startURL);
407 KUrl comboUrl(d->m_urlCombo->currentText());
409 if ( comboUrl.isValid() ) {
417 kDebug() << comboUrl.path() <<
" is not an accessible directory";
418 return d->m_treeView->currentUrl();
423 return d->m_treeView;
428 return d->m_localOnly;
433 return d->m_startDir;
438 if ( !url.isValid() )
441 if (url.
protocol() != d->m_rootUrl.protocol()) {
444 d->m_treeView->setRootUrl( u );
451 bool isHidden = fileName.length() > 1 && fileName[0] ==
'.' &&
452 (fileName.length() > 2 ? fileName[1] !=
'.' :
true);
453 bool showHiddenFiles = isHidden && !d->m_treeView->showHiddenFiles();
454 if (showHiddenFiles) {
455 d->showHiddenFoldersAction->setChecked(
true);
456 d->m_treeView->setShowHiddenFiles(
true);
459 d->m_treeView->setCurrentUrl( url );
465 if (!selectedUrl.isValid()) {
469 if (!d->m_recentDirClass.isEmpty()) {
473 d->m_urlCombo->addToHistory( selectedUrl.
prettyUrl() );
474 KFileDialog::setStartDir(
url() );
483 KDialog::hideEvent(event);
494 if ( !caption.isNull() )
495 myDialog.setCaption( caption );
497 if ( myDialog.exec() == QDialog::Accepted )
503 #include "kdirselectdialog.moc"
KDirSelectDialog(const KUrl &startDir=KUrl(), bool localOnly=false, QWidget *parent=0L)
Creates a new directory selection dialog.
QString i18n(const char *text)
void setCurrentUrl(const KUrl &url)
Sets the current url in the dialog.
This class allows to display a KFilePlacesModel.
QAbstractItemView * view() const
Returns a pointer to the view which is used for displaying the directories.
const char * name(StandardAction id)
void add(const QString &fileClass, const QString &directory)
static bool synchronousRun(Job *job, QWidget *window, QByteArray *data=0, KUrl *finalURL=0, QMap< QString, QString > *metaData=0)
StatJob * stat(const KUrl &url, JobFlags flags=DefaultFlags)
bool cd(const QString &_dir)
The file treeview offers a treeview on the filesystem.
QString toLocalFile(AdjustPathOption trailing=LeaveTrailingSlash) const
static bool mkdir(const KUrl &url, QWidget *window, int permissions=-1)
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
bool askDeleteConfirmation(const KUrl::List &urls, DeletionType deletionType, ConfirmationType confirmationType)
QString i18nc(const char *ctxt, const char *text)
KSharedConfigPtr config()
TsConfig readConfig(const QString &fname)
static bool exists(const KUrl &url, bool source, QWidget *window)
QString encodeFileName(const QString &str)
static void sorry(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
static KUrl selectDirectory(const KUrl &startDir=KUrl(), bool localOnly=false, QWidget *parent=0L, const QString &caption=QString())
Creates a KDirSelectDialog, and returns the result.
virtual void hideEvent(QHideEvent *event)
Reimplemented for saving the dialog geometry.
void setShortcut(const KShortcut &shortcut, ShortcutTypes type=ShortcutTypes(ActiveShortcut|DefaultShortcut))
static QString documentPath()
static KUrl mostLocalUrl(const KUrl &url, QWidget *window)
A pretty dialog for a KDirSelect control for selecting directories.
DeleteJob * del(const KUrl &src, JobFlags flags=DefaultFlags)
QString fileName(const DirectoryOptions &options=IgnoreTrailingSlash) const
~KDirSelectDialog()
Destroys the directory selection dialog.
QString url(AdjustPathOption trailing=LeaveTrailingSlash) const
bool localOnly() const
Returns whether only local directories can be selected.
const UDSEntry & statResult() const
KUrl url() const
Returns the currently selected URL, or an empty one if no item is selected.
QString prettyUrl(AdjustPathOption trailing=LeaveTrailingSlash) const
CopyJob * trash(const KUrl &src, JobFlags flags=DefaultFlags)
This class is a list view model.