#include <QAbstractItemView>
#include <QApplication>
+#include <QBoxLayout>
#include <QClipboard>
+#include <QDropEvent>
+#include <QGraphicsSceneDragDropEvent>
#include <QKeyEvent>
#include <QItemSelection>
-#include <QBoxLayout>
#include <QTimer>
#include <QScrollBar>
#include "dolphin_detailsmodesettings.h"
#include "dolphin_generalsettings.h"
#include "dolphinitemlistcontainer.h"
+#include "draganddrophelper.h"
#include "renamedialog.h"
#include "settings/dolphinsettings.h"
+#include "versioncontrol/versioncontrolobserver.h"
#include "viewmodecontroller.h"
#include "viewproperties.h"
#include "views/tooltips/tooltipmanager.h"
m_container(0),
m_toolTipManager(0),
m_selectionChangedTimer(0),
- m_currentItemIndex(-1),
+ m_currentItemUrl(),
m_restoredContentsPosition(),
m_createdItemUrl(),
- m_selectedItems()
+ m_selectedUrls(),
+ m_versionControlObserver(0)
{
m_topLayout = new QVBoxLayout(this);
m_topLayout->setSpacing(0);
connect(m_dirLister, SIGNAL(redirection(KUrl,KUrl)), this, SLOT(slotRedirection(KUrl,KUrl)));
connect(m_dirLister, SIGNAL(started(KUrl)), this, SLOT(slotDirListerStarted(KUrl)));
- connect(m_dirLister, SIGNAL(completed()), this, SLOT(slotDirListerCompleted()));
connect(m_dirLister, SIGNAL(refreshItems(QList<QPair<KFileItem,KFileItem> >)),
this, SLOT(slotRefreshItems()));
connect(m_dirLister, SIGNAL(itemsDeleted(KFileItemList)), this, SIGNAL(itemCountChanged()));
m_container = new DolphinItemListContainer(m_dirLister, this);
- QHash<QByteArray, int> visibleRoles;
- visibleRoles.insert("name", 0);
- m_container->setVisibleRoles(visibleRoles);
+ m_container->setVisibleRoles(QList<QByteArray>() << "name");
KItemListController* controller = m_container->controller();
controller->setSelectionBehavior(KItemListController::MultiSelection);
connect(controller, SIGNAL(itemExpansionToggleClicked(int)), this, SLOT(slotItemExpansionToggleClicked(int)));
connect(controller, SIGNAL(itemHovered(int)), this, SLOT(slotItemHovered(int)));
connect(controller, SIGNAL(itemUnhovered(int)), this, SLOT(slotItemUnhovered(int)));
+ connect(controller, SIGNAL(itemDropEvent(int,QGraphicsSceneDragDropEvent*)), this, SLOT(slotItemDropEvent(int,QGraphicsSceneDragDropEvent*)));
+ connect(controller, SIGNAL(modelChanged(KItemModelBase*,KItemModelBase*)), this, SLOT(slotModelChanged(KItemModelBase*,KItemModelBase*)));
+
+ KFileItemModel* model = fileItemModel();
+ if (model) {
+ connect(model, SIGNAL(loadingCompleted()), this, SLOT(slotLoadingCompleted()));
+ }
KItemListSelectionManager* selectionManager = controller->selectionManager();
connect(selectionManager, SIGNAL(selectionChanged(QSet<int>,QSet<int>)),
m_toolTipManager = new ToolTipManager(this);
+ m_versionControlObserver = new VersionControlObserver(this);
+ m_versionControlObserver->setModel(model);
+ connect(m_versionControlObserver, SIGNAL(infoMessage(QString)), this, SIGNAL(infoMessage(QString)));
+ connect(m_versionControlObserver, SIGNAL(errorMessage(QString)), this, SIGNAL(errorMessage(QString)));
+ connect(m_versionControlObserver, SIGNAL(operationCompletedMessage(QString)), this, SIGNAL(operationCompletedMessage(QString)));
+
applyViewProperties();
m_topLayout->addWidget(m_container);
void DolphinView::markUrlsAsSelected(const QList<KUrl>& urls)
{
- foreach (const KUrl& url, urls) {
- KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
- m_selectedItems.append(item);
- }
+ m_selectedUrls = urls;
}
void DolphinView::setItemSelectionEnabled(const QRegExp& pattern, bool enabled)
DolphinView::Sorting DolphinView::sorting() const
{
- return DolphinView::SortByName;
- //return m_viewAccessor.proxyModel()->sorting();
+ KItemModelBase* model = m_container->controller()->model();
+ return sortingForSortRole(model->sortRole());
}
void DolphinView::setSortOrder(Qt::SortOrder order)
Qt::SortOrder DolphinView::sortOrder() const
{
- return Qt::AscendingOrder; // m_viewAccessor.proxyModel()->sortOrder();
+ KItemModelBase* model = fileItemModel();
+ return model->sortOrder();
}
void DolphinView::setSortFoldersFirst(bool foldersFirst)
bool DolphinView::sortFoldersFirst() const
{
- return true; // m_viewAccessor.proxyModel()->sortFoldersFirst();
+ KFileItemModel* model = fileItemModel();
+ return model->sortFoldersFirst();
}
void DolphinView::setAdditionalInfoList(const QList<AdditionalInfo>& info)
QByteArray viewState;
QDataStream saveStream(&viewState, QIODevice::WriteOnly);
saveState(saveStream);
- m_selectedItems= selectedItems();
+
+ const KFileItemList itemList = selectedItems();
+ m_selectedUrls.clear();
+ m_selectedUrls = itemList.urlList();
setUrl(url());
loadDirectory(url(), true);
QList<QAction*> DolphinView::versionControlActions(const KFileItemList& items) const
{
- Q_UNUSED(items);
- return QList<QAction*>(); //m_dolphinViewController->versionControlActions(items);
+ QList<QAction*> actions;
+
+ if (items.isEmpty()) {
+ const KFileItem item = fileItemModel()->rootItem();
+ actions = m_versionControlObserver->actions(KFileItemList() << item);
+ } else {
+ actions = m_versionControlObserver->actions(items);
+ }
+
+ return actions;
}
void DolphinView::setUrl(const KUrl& url)
return;
}
- m_selectedItems = selectedItems();
+ const KFileItemList itemList = selectedItems();
+ m_selectedUrls.clear();
+ m_selectedUrls = itemList.urlList();
ViewProperties props(url());
props.setHiddenFilesShown(show);
const int numSteps = numDegrees / 15;
setZoomLevel(zoomLevel() + numSteps);
+ event->accept();
+ } else {
+ event->ignore();
}
- event->accept();
}
void DolphinView::activate()
void DolphinView::slotItemActivated(int index)
{
+ Q_UNUSED(index);
+
const KFileItemList items = selectedItems();
- if (items.isEmpty())
+ if (items.isEmpty()) {
return;
+ }
+
if (items.count() == 1) {
emit itemActivated(items.at(0)); // caught by DolphinViewContainer or DolphinPart
- }
- else {
- foreach (const KFileItem& fileItem, items) {
- if (fileItem.isDir()) {
- emit tabRequested(fileItem.url());
+ } else {
+ foreach (const KFileItem& item, items) {
+ if (item.isDir()) {
+ emit tabRequested(item.url());
} else {
- emit itemActivated(fileItem);
+ emit itemActivated(item);
}
}
}
emit requestItemInfo(KFileItem());
}
+void DolphinView::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event)
+{
+ const KFileItem destItem = fileItemModel()->fileItem(index);
+
+ QDropEvent dropEvent(event->pos().toPoint(),
+ event->possibleActions(),
+ event->mimeData(),
+ event->buttons(),
+ event->modifiers());
+
+ DragAndDropHelper::dropUrls(destItem, url(), &dropEvent, this);
+}
+
+void DolphinView::slotModelChanged(KItemModelBase* current, KItemModelBase* previous)
+{
+ if (previous != 0) {
+ disconnect(previous, SIGNAL(loadingCompleted()), this, SLOT(slotLoadingCompleted()));
+ }
+
+ Q_ASSERT(qobject_cast<KFileItemModel*>(current));
+ connect(current, SIGNAL(loadingCompleted()), this, SLOT(slotLoadingCompleted()));
+
+ KFileItemModel* fileItemModel = static_cast<KFileItemModel*>(current);
+ m_versionControlObserver->setModel(fileItemModel);
+}
+
void DolphinView::slotSelectionChanged(const QSet<int>& current, const QSet<int>& previous)
{
const int currentCount = current.count();
ViewProperties props(url());
props.setSortOrder(order);
- //m_viewAccessor.proxyModel()->setSortOrder(order);
+ KItemModelBase* model = fileItemModel();
+ model->setSortOrder(order);
emit sortOrderChanged(order);
}
ViewProperties props(url());
props.setSortFoldersFirst(foldersFirst);
- //m_viewAccessor.proxyModel()->setSortFoldersFirst(foldersFirst);
+ KFileItemModel* model = fileItemModel();
+ model->setSortFoldersFirst(foldersFirst);
emit sortFoldersFirstChanged(foldersFirst);
}
bool DolphinView::itemsExpandable() const
{
- return false; //m_viewAccessor.itemsExpandable();
+ return m_mode == DetailsView;
}
void DolphinView::restoreState(QDataStream& stream)
{
// Restore the current item that had the keyboard focus
- stream >> m_currentItemIndex;
+ stream >> m_currentItemUrl;
// Restore the view position
stream >> m_restoredContentsPosition;
// Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
- QSet<KUrl> urlsToExpand;
- stream >> urlsToExpand;
- /*const DolphinDetailsViewExpander* expander = m_viewAccessor.setExpandedUrls(urlsToExpand);
- if (expander) {
- m_expanderActive = true;
- connect (expander, SIGNAL(completed()), this, SLOT(slotLoadingCompleted()));
- }
- else {
- m_expanderActive = false;
- }*/
+ QSet<KUrl> urls;
+ stream >> urls;
+ fileItemModel()->restoreExpandedUrls(urls);
}
void DolphinView::saveState(QDataStream& stream)
{
// Save the current item that has the keyboard focus
- stream << m_container->controller()->selectionManager()->currentItem();
+ const int currentIndex = m_container->controller()->selectionManager()->currentItem();
+ if (currentIndex != -1) {
+ KFileItem item = fileItemModel()->fileItem(currentIndex);
+ KUrl currentItemUrl = item.url();
+ stream << currentItemUrl;
+ } else {
+ stream << KUrl();
+ }
// Save view position
const qreal x = m_container->horizontalScrollBar()->value();
stream << QPoint(x, y);
// Save expanded folders (only relevant for the details view - the set will be empty in other view modes)
- //stream << m_viewAccessor.expandedUrls();
+ stream << fileItemModel()->expandedUrls();
}
bool DolphinView::hasSelection() const
void DolphinView::updateViewState()
{
- if (m_currentItemIndex >= 0) {
+ if (m_currentItemUrl != KUrl()) {
KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
- selectionManager->setCurrentItem(m_currentItemIndex);
- m_currentItemIndex =-1;
+ const int currentIndex = fileItemModel()->index(m_currentItemUrl);
+ if (currentIndex != -1) {
+ selectionManager->setCurrentItem(currentIndex);
+ } else {
+ selectionManager->setCurrentItem(0);
+ }
+ m_currentItemUrl = KUrl();
}
if (!m_restoredContentsPosition.isNull()) {
m_container->verticalScrollBar()->setValue(y);
}
- if (!m_selectedItems.isEmpty()) {
+ if (!m_selectedUrls.isEmpty()) {
KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
QSet<int> selectedItems = selectionManager->selectedItems();
const KFileItemModel* model = fileItemModel();
- foreach (const KFileItem& selectedItem, m_selectedItems) {
- const int index = model->index(selectedItem);
+ foreach (const KUrl& url, m_selectedUrls) {
+ const int index = model->index(url);
if (index >= 0) {
selectedItems.insert(index);
}
}
selectionManager->setSelectedItems(selectedItems);
- m_selectedItems.clear();
+ m_selectedUrls.clear();
}
}
void DolphinView::slotDirListerStarted(const KUrl& url)
{
// Disable the writestate temporary until it can be determined in a fast way
- // in DolphinView::slotDirListerCompleted()
+ // in DolphinView::slotLoadingCompleted()
if (m_isFolderWritable) {
m_isFolderWritable = false;
emit writeStateChanged(m_isFolderWritable);
emit startedPathLoading(url);
}
-void DolphinView::slotDirListerCompleted()
+void DolphinView::slotLoadingCompleted()
{
// Update the view-state. This has to be done using a Qt::QueuedConnection
// because the view might not be in its final state yet (the view also
}*/
const DolphinView::Sorting sorting = props.sorting();
- KItemModelBase* model = m_container->controller()->model();
+ KFileItemModel* model = fileItemModel();
const QByteArray newSortRole = sortRoleForSorting(sorting);
if (newSortRole != model->sortRole()) {
model->setSortRole(newSortRole);
emit sortingChanged(sorting);
}
-/*
+
const Qt::SortOrder sortOrder = props.sortOrder();
- if (sortOrder != m_viewAccessor.proxyModel()->sortOrder()) {
- m_viewAccessor.proxyModel()->setSortOrder(sortOrder);
+ if (sortOrder != model->sortOrder()) {
+ model->setSortOrder(sortOrder);
emit sortOrderChanged(sortOrder);
}
const bool sortFoldersFirst = props.sortFoldersFirst();
- if (sortFoldersFirst != m_viewAccessor.proxyModel()->sortFoldersFirst()) {
- m_viewAccessor.proxyModel()->setSortFoldersFirst(sortFoldersFirst);
+ if (sortFoldersFirst != model->sortFoldersFirst()) {
+ model->setSortFoldersFirst(sortFoldersFirst);
emit sortFoldersFirstChanged(sortFoldersFirst);
}
-*/
+
const QList<DolphinView::AdditionalInfo> infoList = props.additionalInfoList();
if (infoList != m_additionalInfoList) {
const QList<DolphinView::AdditionalInfo> previousList = m_additionalInfoList;
{
const AdditionalInfoAccessor& infoAccessor = AdditionalInfoAccessor::instance();
- QHash<QByteArray, int> visibleRoles;
- visibleRoles.insert("name", 0);
+ QList<QByteArray> visibleRoles;
+ visibleRoles.reserve(m_additionalInfoList.count() + 1);
+ visibleRoles.append("name");
- int index = 1;
foreach (AdditionalInfo info, m_additionalInfoList) {
- visibleRoles.insert(infoAccessor.role(info), index);
- ++index;
+ visibleRoles.append(infoAccessor.role(info));
}
m_container->setVisibleRoles(visibleRoles);
return QByteArray();
}
+DolphinView::Sorting DolphinView::sortingForSortRole(const QByteArray& sortRole) const
+{
+ static QHash<QByteArray, DolphinView::Sorting> sortHash;
+ if (sortHash.isEmpty()) {
+ sortHash.insert("name", SortByName);
+ sortHash.insert("size", SortBySize);
+ sortHash.insert("date", SortByDate);
+ sortHash.insert("permissions", SortByPermissions);
+ sortHash.insert("owner", SortByOwner);
+ sortHash.insert("group", SortByGroup);
+ sortHash.insert("type", SortByType);
+ sortHash.insert("destination", SortByDestination);
+ sortHash.insert("path", SortByPath);
+ }
+ return sortHash.value(sortRole);
+}
+
+void DolphinView::markUrlAsCurrent(const KUrl& url)
+{
+ m_currentItemUrl = url;
+}
+
#include "dolphinview.moc"