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);
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();
252 void KDirSelectDialog::Private::slotDelete()
254 const KUrl url = m_treeView->selectedUrl();
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 );
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 );
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() );
494 if ( !caption.isNull() )
497 if ( myDialog.exec() == QDialog::Accepted )
503 #include "kdirselectdialog.moc"