#include <kdirmodel.h>
#include <kfileitemdelegate.h>
+#include <kfileplacesmodel.h>
#include <klocale.h>
#include <kiconeffect.h>
#include <kio/netaccess.h>
#include "dolphincontextmenu.h"
#include "filterbar.h"
#include "renamedialog.h"
-#include "urlnavigator.h"
+#include "kurlnavigator.h"
#include "viewproperties.h"
#include "dolphinsettings.h"
#include "dolphin_generalsettings.h"
const KUrl& url,
Mode mode,
bool showHiddenFiles) :
- QWidget(parent),
- m_showProgress(false),
- m_blockContentsMovedSignal(false),
- m_mode(mode),
- m_iconSize(0),
- m_folderCount(0),
- m_fileCount(0),
- m_mainWindow(mainWindow),
- m_topLayout(0),
- m_urlNavigator(0),
- m_controller(0),
- m_iconsView(0),
- m_detailsView(0),
- m_columnView(0),
- m_fileItemDelegate(0),
- m_filterBar(0),
- m_statusBar(0),
- m_dirModel(0),
- m_dirLister(0),
- m_proxyModel(0)
+ QWidget(parent),
+ m_showProgress(false),
+ m_blockContentsMovedSignal(false),
+ m_mode(mode),
+ m_iconSize(0),
+ m_folderCount(0),
+ m_fileCount(0),
+ m_mainWindow(mainWindow),
+ m_topLayout(0),
+ m_urlNavigator(0),
+ m_controller(0),
+ m_iconsView(0),
+ m_detailsView(0),
+ m_columnView(0),
+ m_fileItemDelegate(0),
+ m_filterBar(0),
+ m_statusBar(0),
+ m_dirModel(0),
+ m_dirLister(0),
+ m_proxyModel(0)
{
hide();
setFocusPolicy(Qt::StrongFocus);
connect(clipboard, SIGNAL(dataChanged()),
this, SLOT(updateCutItems()));
- m_urlNavigator = new UrlNavigator(DolphinSettings::instance().bookmarkManager(), url, this);
+ m_urlNavigator = new KUrlNavigator(DolphinSettings::instance().placesModel(), url, this);
m_urlNavigator->setUrlEditable(DolphinSettings::instance().generalSettings()->editableUrl());
m_urlNavigator->setHomeUrl(DolphinSettings::instance().generalSettings()->homeUrl());
- m_urlNavigator->setShowHiddenFiles(showHiddenFiles);
connect(m_urlNavigator, SIGNAL(urlChanged(const KUrl&)),
this, SLOT(loadDirectory(const KUrl&)));
connect(m_urlNavigator, SIGNAL(urlsDropped(const KUrl::List&, const KUrl&)),
connect(m_urlNavigator, SIGNAL(activated()),
this, SLOT(requestActivation()));
connect(this, SIGNAL(contentsMoved(int, int)),
- m_urlNavigator, SLOT(storeContentsPosition(int, int)));
+ m_urlNavigator, SLOT(savePosition(int, int)));
m_statusBar = new DolphinStatusBar(this);
m_filterBar = new FilterBar(this);
m_filterBar->hide();
connect(m_filterBar, SIGNAL(filterChanged(const QString&)),
- this, SLOT(changeNameFilter(const QString&)));
+ this, SLOT(changeNameFilter(const QString&)));
connect(m_filterBar, SIGNAL(closeRequest()),
this, SLOT(closeFilterBar()));
props.save();
m_dirLister->setShowingDotFiles(show);
- m_urlNavigator->setShowHiddenFiles(show);
-
emit showHiddenFilesChanged();
reload();
if (newName.isEmpty()) {
view->statusBar()->setMessage(dialog.errorString(),
DolphinStatusBar::Error);
- }
- else {
+ } else {
// TODO: check how this can be integrated into KonqUndoManager/KonqOperations
// as one operation instead of n rename operations like it is done now...
Q_ASSERT(newName.contains('#'));
name.replace(replaceIndex, 1, number);
if (oldUrl.fileName() != name) {
- KUrl newUrl(oldUrl.upUrl());
- newUrl.addPath(name);
+ KUrl newUrl = oldUrl;
+ newUrl.setFileName(name);
m_mainWindow->rename(oldUrl, newUrl);
}
++it;
}
}
- }
- else {
+ } else {
// Only one item has been selected for renaming. Use the custom
// renaming mechanism from the views.
Q_ASSERT(urls.count() == 1);
if (newName.isEmpty()) {
view->statusBar()->setMessage(dialog.errorString(),
DolphinStatusBar::Error);
- }
- else {
+ } else {
const KUrl& oldUrl = urls.first();
- KUrl newUrl = oldUrl.upUrl();
- newUrl.addPath(newName);
+ KUrl newUrl = oldUrl;
+ newUrl.setFileName(newName);
m_mainWindow->rename(oldUrl, newUrl);
}
}
return itemView()->verticalScrollBar()->value();
}
-void DolphinView::refreshSettings()
-{
- startDirLister(m_urlNavigator->url());
-}
-
void DolphinView::emitRequestItemInfo(const KUrl& url)
{
emit requestItemInfo(url);
bool DolphinView::isFilterBarVisible() const
{
- return m_filterBar->isVisible();
+ return m_filterBar->isVisible();
}
bool DolphinView::isUrlEditable() const
dest.addPath(newName);
const bool destExists = KIO::NetAccess::exists(dest,
- false,
- mainWindow()->activeView());
+ false,
+ mainWindow()->activeView());
if (destExists) {
// the destination already exists, hence ask the user
// how to proceed...
dest.path(),
KIO::M_OVERWRITE);
switch (renameDialog.exec()) {
- case KIO::R_OVERWRITE:
- // the destination should be overwritten
- ok = KIO::NetAccess::file_move(source, dest, -1, true);
- break;
-
- case KIO::R_RENAME: {
- // a new name for the destination has been used
- KUrl newDest(renameDialog.newDestUrl());
- ok = KIO::NetAccess::file_move(source, newDest);
- break;
- }
+ case KIO::R_OVERWRITE:
+ // the destination should be overwritten
+ ok = KIO::NetAccess::file_move(source, dest, -1, true);
+ break;
- default:
- // the renaming operation has been canceled
- reload();
- return;
+ case KIO::R_RENAME: {
+ // a new name for the destination has been used
+ KUrl newDest(renameDialog.newDestUrl());
+ ok = KIO::NetAccess::file_move(source, newDest);
+ break;
}
- }
- else {
+
+ default:
+ // the renaming operation has been canceled
+ reload();
+ return;
+ }
+ } else {
// no destination exists, hence just move the file to
// do the renaming
ok = KIO::NetAccess::file_move(source, dest);
const QString destFileName = dest.fileName();
if (ok) {
- m_statusBar->setMessage(i18n("Renamed file '%1' to '%2'.",source.fileName(), destFileName),
+ m_statusBar->setMessage(i18n("Renamed file '%1' to '%2'.", source.fileName(), destFileName),
DolphinStatusBar::OperationCompleted);
KonqOperations::rename(this, source, destFileName);
- }
- else {
- m_statusBar->setMessage(i18n("Renaming of file '%1' to '%2' failed.",source.fileName(), destFileName),
+ } else {
+ m_statusBar->setMessage(i18n("Renaming of file '%1' to '%2' failed.", source.fileName(), destFileName),
DolphinStatusBar::Error);
reload();
}
void DolphinView::loadDirectory(const KUrl& url)
{
- if(!isActive()) {
+ if (!isActive()) {
requestActivation();
}
KUrl url;
if (localPath.isEmpty()) {
url = item->url();
- }
- else {
+ } else {
url = localPath;
}
if (item->isDir()) {
setUrl(url);
- }
- else if (item->isFile()) {
+ } else if (item->isFile()) {
// allow to browse through ZIP and tar files
KMimeType::Ptr mime = item->mimeTypePtr();
if (mime->is("application/zip")) {
url.setProtocol("zip");
setUrl(url);
- }
- else if (mime->is("application/x-tar") ||
- mime->is("application/x-tarz") ||
- mime->is("application/x-bzip-compressed-tar") ||
- mime->is("application/x-compressed-tar") ||
- mime->is("application/x-tzo")) {
+ } else if (mime->is("application/x-tar") ||
+ mime->is("application/x-tarz") ||
+ mime->is("application/x-bzip-compressed-tar") ||
+ mime->is("application/x-compressed-tar") ||
+ mime->is("application/x-tzo")) {
url.setProtocol("tar");
setUrl(url);
- }
- else {
+ } else {
item->run();
}
- }
- else {
+ } else {
item->run();
}
}
KFileItem* item = *it;
if (item->isDir()) {
++m_folderCount;
- }
- else {
+ } else {
++m_fileCount;
}
++it;
KIconEffect iconEffect;
const QPixmap cutPixmap = iconEffect.apply(pixmap, K3Icon::Desktop, K3Icon::DisabledState);
m_dirModel->setData(idx, QIcon(cutPixmap), Qt::DecorationRole);
- }
- else {
+ } else {
m_dirModel->setData(idx, QIcon(pixmap), Qt::DecorationRole);
}
}
void DolphinView::restoreContentsPos()
{
- UrlNavigator::HistoryElem historyItem = m_urlNavigator->currentHistoryItem();
- if (!historyItem.url().isEmpty()) {
+ KUrl currentUrl = m_urlNavigator->url();
+ if (!currentUrl.isEmpty()) {
QAbstractItemView* view = itemView();
- // TODO: view->setCurrentItem(historyItem.currentFileName());
- view->horizontalScrollBar()->setValue(historyItem.contentsX());
- view->verticalScrollBar()->setValue(historyItem.contentsY());
+ // TODO: view->setCurrentItem(m_urlNavigator->currentFileName());
+ QPoint pos = m_urlNavigator->savedPosition();
+ view->horizontalScrollBar()->setValue(pos.x());
+ view->verticalScrollBar()->setValue(pos.y());
}
}
const QString location(url.pathOrUrl());
if (location.isEmpty()) {
m_statusBar->setMessage(i18n("The location is empty."), DolphinStatusBar::Error);
- }
- else {
- m_statusBar->setMessage(i18n("The location '%1' is invalid.",location),
+ } else {
+ m_statusBar->setMessage(i18n("The location '%1' is invalid.", location),
DolphinStatusBar::Error);
}
return;
m_blockContentsMovedSignal = true;
m_dirLister->stop();
+ bool openDir = true;
bool keepOldDirs = isColumnViewActive();
- if (keepOldDirs && !m_dirLister->url().isParentOf(url)) {
- // The current URL is not a child of the dir lister
- // URL. This may happen when e. g. a bookmark has been selected
- // and hence the view must be reset.
- keepOldDirs = false;
+ if (keepOldDirs) {
+ if (reload) {
+ keepOldDirs = false;
+
+ const KUrl& dirListerUrl = m_dirLister->url();
+ if (dirListerUrl.isValid()) {
+ const KUrl::List dirs = m_dirLister->directories();
+ KUrl url;
+ foreach(url, dirs) {
+ m_dirLister->updateDirectory(url);
+ }
+ openDir = false;
+ }
+ } else if (m_dirLister->directories().contains(url)) {
+ // The dir lister contains the directory already, so
+ // KDirLister::openUrl() may not been invoked twice.
+ m_dirLister->updateDirectory(url);
+ openDir = false;
+ } else {
+ const KUrl& dirListerUrl = m_dirLister->url();
+ if ((dirListerUrl == url) || !m_dirLister->url().isParentOf(url)) {
+ // The current URL is not a child of the dir lister
+ // URL. This may happen when e. g. a bookmark has been selected
+ // and hence the view must be reset.
+ keepOldDirs = false;
+ }
+ }
+ }
+
+ if (openDir) {
+ m_dirLister->openUrl(url, keepOldDirs, reload);
}
- m_dirLister->openUrl(url, keepOldDirs, reload);
}
QString DolphinView::defaultStatusBarText() const
KIO::filesize_t byteSize = 0;
KFileItemList::const_iterator it = list.begin();
const KFileItemList::const_iterator end = list.end();
- while (it != end){
+ while (it != end) {
KFileItem* item = *it;
if (item->isDir()) {
++folderCount;
- }
- else {
+ } else {
++fileCount;
byteSize += item->size();
}
Q_ASSERT(m_filterBar != 0);
if (show) {
m_filterBar->show();
- }
- else {
+ } else {
m_filterBar->hide();
}
}
KUrl baseUrl = url();
KUrl url;
QItemSelection new_selection;
- foreach (KFileItem* item, selection) {
+ foreach(KFileItem* item, selection) {
url = item->url().upUrl();
if (baseUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) {
QModelIndex index = m_proxyModel->mapFromSource(m_dirModel->indexForItem(*item));
m_dirLister->setNameFilter(adjustedFilter);
m_dirLister->emitChanges();
#else
- m_proxyModel->setFilterRegExp( nameFilter );
+ m_proxyModel->setFilterRegExp(nameFilter);
#endif
}
}
const KUrl& destination = (directory == 0) ? url() :
- directory->url();
+ directory->url();
dropUrls(urls, destination);
}
void DolphinView::updateActivationState()
{
m_urlNavigator->setActive(isActive());
- if(isActive()) {
+ if (isActive()) {
emit urlChanged(url());
emit selectionChanged(selectedItems());
}
// ... and recreate it representing the current mode
switch (m_mode) {
- case IconsView:
- m_iconsView = new DolphinIconsView(this, m_controller);
- view = m_iconsView;
- break;
-
- case DetailsView:
- m_detailsView = new DolphinDetailsView(this, m_controller);
- view = m_detailsView;
- break;
-
- case ColumnView:
- m_columnView = new DolphinColumnView(this, m_controller);
- view = m_columnView;
- break;
+ case IconsView:
+ m_iconsView = new DolphinIconsView(this, m_controller);
+ view = m_iconsView;
+ break;
+
+ case DetailsView:
+ m_detailsView = new DolphinDetailsView(this, m_controller);
+ view = m_detailsView;
+ break;
+
+ case ColumnView:
+ m_columnView = new DolphinColumnView(this, m_controller);
+ view = m_columnView;
+ break;
}
Q_ASSERT(view != 0);
const QModelIndex topLeft = itemModel->index(0, 0);
const QModelIndex bottomRight = itemModel->index(itemModel->rowCount() - 1,
- itemModel->columnCount() - 1);
+ itemModel->columnCount() - 1);
QItemSelection selection(topLeft, bottomRight);
selectionModel->select(selection, flags);
{
if (m_detailsView != 0) {
return m_detailsView;
- }
- else if (m_columnView != 0) {
+ } else if (m_columnView != 0) {
return m_columnView;
}
const KUrl& itemUrl = item.url();
KUrl::List::const_iterator it = cutUrls.begin();
const KUrl::List::const_iterator end = cutUrls.end();
- while (it != end){
+ while (it != end) {
if (*it == itemUrl) {
return true;
}