X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/76866f783cfd5e84a85b6e9024aa554f3969ecec..dc3e19744dedef4b185eb0becb00a28c74381c4c:/src/dolphinview.cpp diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index bf92b34f4..eddd220d3 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -22,9 +22,9 @@ #include -#include -#include // TODO +#include #include +#include #include #include @@ -45,18 +45,16 @@ #include "dolphiniconsview.h" #include "dolphincontextmenu.h" #include "filterbar.h" -#include "progressindicator.h" #include "renamedialog.h" #include "urlnavigator.h" #include "viewproperties.h" -DolphinView::DolphinView(DolphinMainWindow *mainWindow, - QWidget *parent, +DolphinView::DolphinView(DolphinMainWindow* mainWindow, + QWidget* parent, const KUrl& url, Mode mode, bool showHiddenFiles) : QWidget(parent), - m_refreshing(false), m_showProgress(false), m_mode(mode), m_iconSize(0), @@ -92,17 +90,17 @@ DolphinView::DolphinView(DolphinMainWindow *mainWindow, m_dirLister->setDelayedMimeTypes(true); connect(m_dirLister, SIGNAL(clear()), - this, SLOT(slotClear())); + this, SLOT(updateStatusBar())); connect(m_dirLister, SIGNAL(percent(int)), - this, SLOT(slotPercent(int))); + this, SLOT(updateProgress(int))); connect(m_dirLister, SIGNAL(deleteItem(KFileItem*)), - this, SLOT(slotDeleteItem(KFileItem*))); + this, SLOT(updateStatusBar())); connect(m_dirLister, SIGNAL(completed()), - this, SLOT(slotCompleted())); + this, SLOT(updateItemCount())); connect(m_dirLister, SIGNAL(infoMessage(const QString&)), - this, SLOT(slotInfoMessage(const QString&))); + this, SLOT(showInfoMessage(const QString&))); connect(m_dirLister, SIGNAL(errorMessage(const QString&)), - this, SLOT(slotErrorMessage(const QString&))); + this, SLOT(showErrorMessage(const QString&))); m_dirModel = new KDirModel(); m_dirModel->setDirLister(m_dirLister); @@ -118,8 +116,8 @@ DolphinView::DolphinView(DolphinMainWindow *mainWindow, m_filterBar = new FilterBar(this); m_filterBar->hide(); connect(m_filterBar, SIGNAL(filterChanged(const QString&)), - this, SLOT(slotChangeNameFilter(const QString&))); - connect(m_filterBar, SIGNAL(closed()), + this, SLOT(changeNameFilter(const QString&))); + connect(m_filterBar, SIGNAL(closeRequest()), this, SLOT(closeFilterBar())); m_topLayout->addWidget(m_urlNavigator); @@ -159,7 +157,7 @@ bool DolphinView::isActive() const void DolphinView::setMode(Mode mode) { if (mode == m_mode) { - return; // the wished mode is already set + return; // the wished mode is already set } m_mode = mode; @@ -242,19 +240,17 @@ void DolphinView::renameSelectedItems() assert(newName.contains('#')); const int urlsCount = urls.count(); - ProgressIndicator* progressIndicator = - new ProgressIndicator(mainWindow(), - i18n("Renaming items..."), - i18n("Renaming finished."), - urlsCount); // iterate through all selected items and rename them... const int replaceIndex = newName.indexOf('#'); assert(replaceIndex >= 0); for (int i = 0; i < urlsCount; ++i) { const KUrl& source = urls[i]; + QString number; + number.setNum(i + 1); + QString name(newName); - name.replace(replaceIndex, 1, renameIndexPresentation(i + 1, urlsCount)); + name.replace(replaceIndex, 1, number); if (source.fileName() != name) { KUrl dest(source.upUrl()); @@ -262,8 +258,6 @@ void DolphinView::renameSelectedItems() const bool destExists = KIO::NetAccess::exists(dest, false, view); if (destExists) { - delete progressIndicator; - progressIndicator = 0; view->statusBar()->setMessage(i18n("Renaming failed (item '%1' already exists).",name), DolphinStatusBar::Error); break; @@ -275,11 +269,7 @@ void DolphinView::renameSelectedItems() //undoMan.addCommand(command); } } - - progressIndicator->execOperation(); } - delete progressIndicator; - progressIndicator = 0; //undoMan.endMacro(); } @@ -330,12 +320,12 @@ DolphinStatusBar* DolphinView::statusBar() const int DolphinView::contentsX() const { - return 0; //scrollView()->contentsX(); + return itemView()->horizontalScrollBar()->value(); } int DolphinView::contentsY() const { - return 0; //scrollView()->contentsY(); + return itemView()->verticalScrollBar()->value(); } void DolphinView::refreshSettings() @@ -343,29 +333,6 @@ void DolphinView::refreshSettings() startDirLister(m_urlNavigator->url()); } -void DolphinView::updateStatusBar() -{ - // As the item count information is less important - // in comparison with other messages, it should only - // be shown if: - // - the status bar is empty or - // - shows already the item count information or - // - shows only a not very important information - // - if any progress is given don't show the item count info at all - const QString msg(m_statusBar->message()); - const bool updateStatusBarMsg = (msg.isEmpty() || - (msg == m_statusBar->defaultText()) || - (m_statusBar->type() == DolphinStatusBar::Information)) && - (m_statusBar->progress() == 100); - - const QString text(hasSelection() ? selectionStatusBarText() : defaultStatusBarText()); - m_statusBar->setDefaultText(text); - - if (updateStatusBarMsg) { - m_statusBar->setMessage(text, DolphinStatusBar::Default); - } -} - void DolphinView::emitRequestItemInfo(const KUrl& url) { emit requestItemInfo(url); @@ -460,7 +427,7 @@ void DolphinView::setUrlEditable(bool editable) m_urlNavigator->editUrl(editable); } -const Q3ValueList DolphinView::urlHistory(int& index) const +const QLinkedList DolphinView::urlHistory(int& index) const { return m_urlNavigator->history(index); } @@ -511,9 +478,10 @@ KUrl::List DolphinView::selectedUrls() const return urls; } -const KFileItem* DolphinView::currentFileItem() const +KFileItem* DolphinView::fileItem(const QModelIndex index) const { - return 0; // fileView()->currentFileItem(); + const QModelIndex dirModelIndex = m_proxyModel->mapToSource(index); + return m_dirModel->itemForIndex(dirModelIndex); } void DolphinView::openContextMenu(KFileItem* fileInfo, const QPoint& pos) @@ -588,25 +556,9 @@ void DolphinView::reload() startDirLister(m_urlNavigator->url(), true); } -void DolphinView::slotUrlListDropped(QDropEvent* /* event */, - const KUrl::List& urls, - const KUrl& url) +void DolphinView::declareViewActive() { - KUrl destination(url); - if (destination.isEmpty()) { - destination = m_urlNavigator->url(); - } - else { - // Check whether the destination Url is a directory. If this is not the - // case, use the navigator Url as destination (otherwise the destination, - // which represents a file, would be replaced by a copy- or move-operation). - KFileItem fileItem(KFileItem::Unknown, KFileItem::Unknown, destination); - if (!fileItem.isDir()) { - destination = m_urlNavigator->url(); - } - } - - mainWindow()->dropUrls(urls, destination); + mainWindow()->setActiveView( this ); } void DolphinView::mouseReleaseEvent(QMouseEvent* event) @@ -653,25 +605,30 @@ void DolphinView::loadDirectory(const KUrl& url) startDirLister(url); emit urlChanged(url); + + m_statusBar->clear(); } void DolphinView::triggerItem(const QModelIndex& index) { + const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers(); + if ((modifier & Qt::ShiftModifier) || (modifier & Qt::ControlModifier)) { + // items are selected by the user, hence don't trigger the + // item specified by 'index' + return; + } + KFileItem* item = m_dirModel->itemForIndex(m_proxyModel->mapToSource(index)); if (item == 0) { return; } 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 + // 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). - //m_dirLister->stop(); - //m_dirLister->openUrl(item->url()); - //return; - const QString localPath(item->localPath()); if (localPath.isEmpty()) { setUrl(item->url()); @@ -685,41 +642,15 @@ void DolphinView::triggerItem(const QModelIndex& index) } } -void DolphinView::slotPercent(int percent) +void DolphinView::updateProgress(int percent) { if (m_showProgress) { m_statusBar->setProgress(percent); } } -void DolphinView::slotClear() -{ - //fileView()->clearView(); - updateStatusBar(); -} - -void DolphinView::slotDeleteItem(KFileItem* item) -{ - //fileView()->removeItem(item); - updateStatusBar(); -} - -void DolphinView::slotCompleted() +void DolphinView::updateItemCount() { - m_refreshing = true; - - //KFileView* view = fileView(); - //view->clearView(); - - // TODO: in Qt4 the code should get a lot - // simpler and nicer due to Interview... - /*if (m_iconsView != 0) { - m_iconsView->beginItemUpdates(); - } - if (m_iconsView != 0) { - m_iconsView->beginItemUpdates(); - }*/ - if (m_showProgress) { m_statusBar->setProgressText(QString::null); m_statusBar->setProgress(100); @@ -735,7 +666,6 @@ void DolphinView::slotCompleted() while (it != end) { KFileItem* item = *it; - //view->insertItem(item); if (item->isDir()) { ++m_folderCount; } @@ -747,32 +677,32 @@ void DolphinView::slotCompleted() updateStatusBar(); - /*if (m_iconsView != 0) { - // Prevent a flickering of the icon view widget by giving a small - // timeslot to swallow asynchronous update events. - m_iconsView->setUpdatesEnabled(false); - QTimer::singleShot(10, this, SLOT(slotDelayedUpdate())); - } - - if (m_iconsView != 0) { - m_iconsView->endItemUpdates(); - m_refreshing = false; - }*/ + QTimer::singleShot(0, this, SLOT(restoreContentsPos())); } -void DolphinView::slotInfoMessage(const QString& msg) +void DolphinView::restoreContentsPos() { - m_statusBar->setMessage(msg, DolphinStatusBar::Information); + int index = 0; + const QLinkedList history = urlHistory(index); + if (!history.isEmpty()) { + QAbstractItemView* view = itemView(); + // TODO: view->setCurrentItem(history[index].currentFileName()); + + QLinkedList::const_iterator it = history.begin(); + it += index; + view->horizontalScrollBar()->setValue((*it).contentsX()); + view->verticalScrollBar()->setValue((*it).contentsY()); + } } -void DolphinView::slotErrorMessage(const QString& msg) +void DolphinView::showInfoMessage(const QString& msg) { - m_statusBar->setMessage(msg, DolphinStatusBar::Error); + m_statusBar->setMessage(msg, DolphinStatusBar::Information); } -void DolphinView::slotGrabActivation() +void DolphinView::showErrorMessage(const QString& msg) { - mainWindow()->setActiveView(this); + m_statusBar->setMessage(msg, DolphinStatusBar::Error); } void DolphinView::emitSelectionChangedSignal() @@ -786,16 +716,6 @@ void DolphinView::closeFilterBar() emit showFilterBarChanged(false); } -void DolphinView::slotContentsMoving(int x, int y) -{ - if (!m_refreshing) { - // Only emit a 'contents moved' signal if the user - // moved the content by adjusting the sliders. Adjustments - // resulted by refreshing a directory should not be respected. - emit contentsMoved(x, y); - } -} - void DolphinView::startDirLister(const KUrl& url, bool reload) { if (!url.isValid()) { @@ -821,7 +741,6 @@ void DolphinView::startDirLister(const KUrl& url, bool reload) m_statusBar->setProgress(0); } - m_refreshing = true; m_dirLister->stop(); m_dirLister->openUrl(url, false, reload); } @@ -914,26 +833,7 @@ QString DolphinView::selectionStatusBarText() const return text; } -QString DolphinView::renameIndexPresentation(int index, int itemCount) const -{ - // assure that the string reprentation for all indicess have the same - // number of characters based on the given number of items - QString str(QString::number(index)); - int chrCount = 1; - while (itemCount >= 10) { - ++chrCount; - itemCount /= 10; - } - str.reserve(chrCount); - - const int insertCount = chrCount - str.length(); - for (int i = 0; i < insertCount; ++i) { - str.insert(0, '0'); - } - return str; -} - -void DolphinView::slotShowFilterBar(bool show) +void DolphinView::showFilterBar(bool show) { assert(m_filterBar != 0); if (show) { @@ -944,12 +844,30 @@ void DolphinView::slotShowFilterBar(bool show) } } -void DolphinView::declareViewActive() +void DolphinView::updateStatusBar() { - mainWindow()->setActiveView( this ); + // As the item count information is less important + // in comparison with other messages, it should only + // be shown if: + // - the status bar is empty or + // - shows already the item count information or + // - shows only a not very important information + // - if any progress is given don't show the item count info at all + const QString msg(m_statusBar->message()); + const bool updateStatusBarMsg = (msg.isEmpty() || + (msg == m_statusBar->defaultText()) || + (m_statusBar->type() == DolphinStatusBar::Information)) && + (m_statusBar->progress() == 100); + + const QString text(hasSelection() ? selectionStatusBarText() : defaultStatusBarText()); + m_statusBar->setDefaultText(text); + + if (updateStatusBarMsg) { + m_statusBar->setMessage(text, DolphinStatusBar::Default); + } } -void DolphinView::slotChangeNameFilter(const QString& nameFilter) +void DolphinView::changeNameFilter(const QString& nameFilter) { // The name filter of KDirLister does a 'hard' filtering, which // means that only the items are shown where the names match @@ -979,7 +897,7 @@ void DolphinView::createView() // delete current view QAbstractItemView* view = itemView(); if (view != 0) { - m_topLayout->remove(view); + m_topLayout->removeWidget(view); view->close(); view->deleteLater(); m_iconsView = 0;