#include <assert.h>
#include <QApplication>
+#include <QClipboard>
#include <QDropEvent>
#include <QItemSelectionModel>
#include <QMouseEvent>
#include <kdirmodel.h>
#include <kfileitemdelegate.h>
#include <klocale.h>
+#include <kiconeffect.h>
#include <kio/netaccess.h>
#include <kio/renamedialog.h>
+#include <kio/previewjob.h>
#include <kmimetyperesolver.h>
+#include <konqmimedata.h>
#include <konq_operations.h>
#include <kurl.h>
m_controller(0),
m_iconsView(0),
m_detailsView(0),
+ m_fileItemDelegate(0),
m_filterBar(0),
m_statusBar(0),
m_dirModel(0),
this, SLOT(updateActivationState()));
m_urlNavigator = new UrlNavigator(url, this);
+ 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&)),
this, SLOT(updateStatusBar()));
connect(m_dirLister, SIGNAL(completed()),
this, SLOT(updateItemCount()));
+ connect(m_dirLister, SIGNAL(completed()),
+ this, SLOT(updateCutItems()));
+ connect(m_dirLister, SIGNAL(newItems(const KFileItemList&)),
+ this, SLOT(generatePreviews(const KFileItemList&)));
connect(m_dirLister, SIGNAL(infoMessage(const QString&)),
this, SLOT(showInfoMessage(const QString&)));
connect(m_dirLister, SIGNAL(errorMessage(const QString&)),
m_controller = new DolphinController(this);
connect(m_controller, SIGNAL(requestContextMenu(const QPoint&)),
this, SLOT(openContextMenu(const QPoint&)));
- connect(m_controller, SIGNAL(urlsDropped(const KUrl::List&, const QPoint&)),
- this, SLOT(dropUrls(const KUrl::List&, const QPoint&)));
+ connect(m_controller, SIGNAL(urlsDropped(const KUrl::List&, const QModelIndex&, QWidget*)),
+ this, SLOT(dropUrls(const KUrl::List&, const QModelIndex&, QWidget*)));
connect(m_controller, SIGNAL(sortingChanged(DolphinView::Sorting)),
this, SLOT(updateSorting(DolphinView::Sorting)));
connect(m_controller, SIGNAL(sortOrderChanged(Qt::SortOrder)),
ViewProperties props(m_urlNavigator->url());
props.setShowPreview(show);
- // TODO: wait until previews are possible with KFileItemDelegate
+ m_controller->setShowPreview(show);
emit showPreviewChanged();
+ reload();
}
bool DolphinView::showPreview() const
{
- // TODO: wait until previews are possible with KFileItemDelegate
- return true;
+ return m_controller->showPreview();
}
void DolphinView::setShowHiddenFiles(bool show)
props.save();
m_dirLister->setShowingDotFiles(show);
+ m_urlNavigator->setShowHiddenFiles(show);
emit showHiddenFilesChanged();
void DolphinView::zoomIn()
{
- //itemEffectsManager()->zoomIn();
+ m_controller->triggerZoomIn();
}
void DolphinView::zoomOut()
{
- //itemEffectsManager()->zoomOut();
+ m_controller->triggerZoomOut();
}
bool DolphinView::isZoomInPossible() const
{
- return false; //itemEffectsManager()->isZoomInPossible();
+ return m_controller->isZoomInPossible();
}
bool DolphinView::isZoomOutPossible() const
{
- return false; //itemEffectsManager()->isZoomOutPossible();
+ return m_controller->isZoomOutPossible();
}
void DolphinView::setSorting(Sorting sorting)
return m_proxyModel->sortOrder();
}
+void DolphinView::setAdditionalInfo(KFileItemDelegate::AdditionalInformation info)
+{
+ ViewProperties props(m_urlNavigator->url());
+ props.setAdditionalInfo(info);
+
+ m_fileItemDelegate->setAdditionalInformation(info);
+
+ emit additionalInfoChanged(info);
+ reload();
+}
+
+KFileItemDelegate::AdditionalInformation DolphinView::additionalInfo() const
+{
+ return m_fileItemDelegate->additionalInformation();
+}
+
void DolphinView::goBack()
{
m_urlNavigator->goBack();
// Our view has a selection, we will map them back to the DirModel
// and then fill the KFileItemList.
- assert((view != 0) && (view->selectionModel() != 0));
+ Q_ASSERT((view != 0) && (view->selectionModel() != 0));
const QItemSelection selection = m_proxyModel->mapSelectionToSource(view->selectionModel()->selection());
KFileItemList itemList;
const QModelIndexList indexList = selection.indexes();
QModelIndexList::const_iterator end = indexList.end();
for (QModelIndexList::const_iterator it = indexList.begin(); it != end; ++it) {
- assert((*it).isValid());
+ Q_ASSERT((*it).isValid());
KFileItem* item = m_dirModel->itemForIndex(*it);
if (item != 0) {
emit sortOrderChanged(sortOrder);
}
- // TODO: handle previews (props.showPreview())
+ KFileItemDelegate::AdditionalInformation info = props.additionalInfo();
+ if (info != m_fileItemDelegate->additionalInformation()) {
+ m_fileItemDelegate->setAdditionalInformation(info);
+
+ emit additionalInfoChanged(info);
+ }
+
+ const bool showPreview = props.showPreview();
+ if (showPreview != m_controller->showPreview()) {
+ m_controller->setShowPreview(showPreview);
+ emit showPreviewChanged();
+ }
startDirLister(url);
emit urlChanged(url);
void DolphinView::triggerItem(const QModelIndex& index)
{
+ if (!isValidNameIndex(index)) {
+ return;
+ }
+
const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
if ((modifier & Qt::ShiftModifier) || (modifier & Qt::ControlModifier)) {
// items are selected by the user, hence don't trigger the
return;
}
+ // Prefer the local path over the URL. This assures that the
+ // volume space information is correct. Assuming that the URL is media:/sda1,
+ // and the local path is /windows/C: For the URL the space info is related
+ // to the root partition (and hence wrong) and for the local path the space
+ // info is related to the windows partition (-> correct).
+ const QString localPath(item->localPath());
+ KUrl url;
+ if (localPath.isEmpty()) {
+ url = item->url();
+ }
+ else {
+ url = localPath;
+ }
+
if (item->isDir()) {
- // Prefer the local path over the URL. This assures that the
- // volume space information is correct. Assuming that the URL is media:/sda1,
- // and the local path is /windows/C: For the URL the space info is related
- // to the root partition (and hence wrong) and for the local path the space
- // info is related to the windows partition (-> correct).
- const QString localPath(item->localPath());
- if (localPath.isEmpty()) {
- setUrl(item->url());
+ setUrl(url);
+ }
+ else if (item->isFile()) {
+ // allow to browse through ZIP and tar files
+ KMimeType::Ptr mime = item->mimeTypePtr();
+ if (mime->is("application/x-zip")) {
+ url.setProtocol("zip");
+ setUrl(url);
+ }
+ else if (mime->is("application/x-tar") ||
+ mime->is("application/x-tarz") ||
+ mime->is("application/x-tbz") ||
+ mime->is("application/x-tgz") ||
+ mime->is("application/x-tzo")) {
+ url.setProtocol("tar");
+ setUrl(url);
}
else {
- setUrl(KUrl(localPath));
+ item->run();
}
}
else {
void DolphinView::updateItemCount()
{
if (m_showProgress) {
- m_statusBar->setProgressText(QString::null);
+ m_statusBar->setProgressText(QString());
m_statusBar->setProgress(100);
m_showProgress = false;
}
QTimer::singleShot(0, this, SLOT(restoreContentsPos()));
}
+void DolphinView::generatePreviews(const KFileItemList& items)
+{
+ if (m_controller->showPreview()) {
+ KIO::PreviewJob* job = KIO::filePreview(items, 128);
+ connect(job, SIGNAL(gotPreview(const KFileItem*, const QPixmap&)),
+ this, SLOT(showPreview(const KFileItem*, const QPixmap&)));
+ }
+
+ const QMimeData* mimeData = QApplication::clipboard()->mimeData();
+ if (KonqMimeData::decodeIsCutSelection(mimeData)) {
+ QTimer::singleShot(0, this, SLOT(applyCutEffect()));
+ }
+}
+
+void DolphinView::showPreview(const KFileItem* item, const QPixmap& pixmap)
+{
+ Q_ASSERT(item != 0);
+ const QModelIndex idx = m_dirModel->indexForItem(*item);
+ if (idx.isValid() && (idx.column() == 0)) {
+ const QMimeData* mimeData = QApplication::clipboard()->mimeData();
+ if (KonqMimeData::decodeIsCutSelection(mimeData) && isCutItem(*item)) {
+ KIconEffect iconEffect;
+ QPixmap cutPixmap = iconEffect.apply(pixmap, K3Icon::Desktop, K3Icon::DisabledState);
+ m_dirModel->setData(idx, cutPixmap, Qt::DecorationRole);
+ }
+ else {
+ m_dirModel->setData(idx, pixmap, Qt::DecorationRole);
+ }
+ }
+}
+
void DolphinView::restoreContentsPos()
{
int index = 0;
m_mainWindow->setActiveView(this);
}
+void DolphinView::updateCutItems()
+{
+ const QMimeData* mimeData = QApplication::clipboard()->mimeData();
+ if (!KonqMimeData::decodeIsCutSelection(mimeData)) {
+ return;
+ }
+
+ KFileItemList items(m_dirLister->items());
+ KFileItemList::const_iterator it = items.begin();
+ const KFileItemList::const_iterator end = items.end();
+ while (it != end) {
+ KFileItem* item = *it;
+ if (isCutItem(*item)) {
+ QPixmap pixmap = item->pixmap(0);
+ KIconEffect iconEffect;
+ pixmap = iconEffect.apply(pixmap, K3Icon::Desktop, K3Icon::DisabledState);
+ const QModelIndex idx = m_dirModel->indexForItem(*item);
+ if (idx.isValid()) {
+ m_dirModel->setData(idx, pixmap, Qt::DecorationRole);
+ }
+ }
+ ++it;
+ }
+}
+
void DolphinView::changeNameFilter(const QString& nameFilter)
{
// The name filter of KDirLister does a 'hard' filtering, which
KFileItem* item = 0;
const QModelIndex index = itemView()->indexAt(pos);
- if (index.isValid()) {
+ if (isValidNameIndex(index)) {
item = fileItem(index);
}
}
void DolphinView::dropUrls(const KUrl::List& urls,
- const QPoint& pos)
+ const QModelIndex& index,
+ QWidget* source)
{
KFileItem* directory = 0;
- const QModelIndex index = itemView()->indexAt(pos);
- if (index.isValid()) {
+ if (isValidNameIndex(index)) {
KFileItem* item = fileItem(index);
assert(item != 0);
if (item->isDir()) {
}
}
+ if ((directory == 0) && (source == itemView())) {
+ // The dropping is done into the same viewport where
+ // the dragging has been started. Just ignore this...
+ return;
+ }
+
const KUrl& destination = (directory == 0) ? url() :
directory->url();
+
+ kDebug() << "DolphinView::dropUrls() - destination: " << destination.prettyUrl() << endl;
+
dropUrls(urls, destination);
}
m_topLayout->removeWidget(view);
view->close();
view->deleteLater();
+ view = 0;
m_iconsView = 0;
m_detailsView = 0;
+ m_fileItemDelegate = 0;
}
assert(m_iconsView == 0);
break;
}
+ assert(view != 0);
+
+ m_fileItemDelegate = new KFileItemDelegate(view);
+ view->setItemDelegate(m_fileItemDelegate);
+
view->setModel(m_proxyModel);
view->setSelectionMode(QAbstractItemView::ExtendedSelection);
- KFileItemDelegate* delegate = new KFileItemDelegate(this);
- delegate->setAdditionalInformation(KFileItemDelegate::FriendlyMimeType);
- view->setItemDelegate(delegate);
-
new KMimeTypeResolver(view, m_dirModel);
m_topLayout->insertWidget(1, view);
QAbstractItemView* DolphinView::itemView() const
{
- assert((m_iconsView == 0) || (m_detailsView == 0));
+ Q_ASSERT((m_iconsView == 0) || (m_detailsView == 0));
if (m_detailsView != 0) {
return m_detailsView;
}
return m_iconsView;
}
+bool DolphinView::isValidNameIndex(const QModelIndex& index) const
+{
+ return index.isValid() && (index.column() == KDirModel::Name);
+}
+
+bool DolphinView::isCutItem(const KFileItem& item) const
+{
+ const QMimeData* mimeData = QApplication::clipboard()->mimeData();
+ const KUrl::List cutUrls = KUrl::List::fromMimeData(mimeData);
+
+ const KUrl& itemUrl = item.url();
+ KUrl::List::const_iterator it = cutUrls.begin();
+ const KUrl::List::const_iterator end = cutUrls.end();
+ while (it != end){
+ if (*it == itemUrl) {
+ return true;
+ }
+ ++it;
+ }
+
+ return false;
+}
+
#include "dolphinview.moc"