]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinview.cpp
KFileItemModel: interface cleanups
[dolphin.git] / src / views / dolphinview.cpp
index 137b73d0902e7b4a143fa12efd20b1caf234edc9..3fbe56ebacd5a16fd403853c966ed71b221c3b49 100644 (file)
@@ -136,17 +136,17 @@ DolphinView::DolphinView(const KUrl& url, QWidget* parent) :
     connect(controller, SIGNAL(modelChanged(KItemModelBase*,KItemModelBase*)), this, SLOT(slotModelChanged(KItemModelBase*,KItemModelBase*)));
 
     KFileItemModel* model = fileItemModel();
-    connect(model, SIGNAL(dirLoadingStarted()),            this, SLOT(slotDirLoadingStarted()));
-    connect(model, SIGNAL(dirLoadingCompleted()),          this, SLOT(slotDirLoadingCompleted()));
-    connect(model, SIGNAL(dirLoadingProgress(int)),        this, SIGNAL(dirLoadingProgress(int)));
-    connect(model, SIGNAL(dirSortingProgress(int)),        this, SIGNAL(dirSortingProgress(int)));
+    connect(model, SIGNAL(directoryLoadingStarted()),       this, SLOT(slotDirectoryLoadingStarted()));
+    connect(model, SIGNAL(directoryLoadingCompleted()),     this, SLOT(slotDirectoryLoadingCompleted()));
+    connect(model, SIGNAL(directoryLoadingProgress(int)),   this, SIGNAL(directoryLoadingProgress(int)));
+    connect(model, SIGNAL(directorySortingProgress(int)),   this, SIGNAL(directorySortingProgress(int)));
     connect(model, SIGNAL(itemsChanged(KItemRangeList,QSet<QByteArray>)),
             this, SLOT(slotItemsChanged()));
-    connect(model, SIGNAL(itemsRemoved(KItemRangeList)),   this, SIGNAL(itemCountChanged()));
-    connect(model, SIGNAL(itemsInserted(KItemRangeList)),  this, SIGNAL(itemCountChanged()));
-    connect(model, SIGNAL(infoMessage(QString)),           this, SIGNAL(infoMessage(QString)));
-    connect(model, SIGNAL(errorMessage(QString)),          this, SIGNAL(errorMessage(QString)));
-    connect(model, SIGNAL(redirection(KUrl,KUrl)),         this, SLOT(slotRedirection(KUrl,KUrl)));
+    connect(model, SIGNAL(itemsRemoved(KItemRangeList)),    this, SIGNAL(itemCountChanged()));
+    connect(model, SIGNAL(itemsInserted(KItemRangeList)),   this, SIGNAL(itemCountChanged()));
+    connect(model, SIGNAL(infoMessage(QString)),            this, SIGNAL(infoMessage(QString)));
+    connect(model, SIGNAL(errorMessage(QString)),           this, SIGNAL(errorMessage(QString)));
+    connect(model, SIGNAL(directoryRedirection(KUrl,KUrl)), this, SLOT(slotDirectoryRedirection(KUrl,KUrl)));
 
     KItemListView* view = controller->view();
     view->installEventFilter(this);
@@ -347,7 +347,7 @@ void DolphinView::markUrlAsCurrent(const KUrl& url)
     m_currentItemUrl = url;
 }
 
-void DolphinView::setItemSelectionEnabled(const QRegExp& pattern, bool enabled)
+void DolphinView::selectItems(const QRegExp& pattern, bool enabled)
 {
     const KItemListSelectionManager::SelectionMode mode = enabled
                                                         ? KItemListSelectionManager::Select
@@ -417,7 +417,7 @@ void DolphinView::setSortFoldersFirst(bool foldersFirst)
 bool DolphinView::sortFoldersFirst() const
 {
     KFileItemModel* model = fileItemModel();
-    return model->sortFoldersFirst();
+    return model->sortDirectoriesFirst();
 }
 
 void DolphinView::setVisibleRoles(const QList<QByteArray>& roles)
@@ -457,7 +457,7 @@ void DolphinView::reload()
 
 void DolphinView::stopLoading()
 {
-    fileItemModel()->cancelDirLoading();
+    fileItemModel()->cancelDirectoryLoading();
 }
 
 void DolphinView::readSettings()
@@ -490,23 +490,6 @@ QString DolphinView::nameFilter() const
     return fileItemModel()->nameFilter();
 }
 
-void DolphinView::calculateItemCount(int& fileCount,
-                                     int& folderCount,
-                                     KIO::filesize_t& totalFileSize) const
-{
-    const KFileItemModel* model = fileItemModel();
-    const int itemCount = model->count();
-    for (int i = 0; i < itemCount; ++i) {
-        const KFileItem item = model->fileItem(i);
-        if (item.isDir()) {
-            ++folderCount;
-        } else {
-            ++fileCount;
-            totalFileSize += item.size();
-        }
-    }
-}
-
 QString DolphinView::statusBarText() const
 {
     QString summary;
@@ -517,7 +500,7 @@ QString DolphinView::statusBarText() const
     int fileCount = 0;
     KIO::filesize_t totalFileSize = 0;
 
-    if (hasSelection()) {
+    if (m_container->controller()->selectionManager()->hasSelection()) {
         // Give a summary of the status of the selected files
         const KFileItemList list = selectedItems();
         foreach (const KFileItem& item, list) {
@@ -985,11 +968,11 @@ void DolphinView::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* even
 void DolphinView::slotModelChanged(KItemModelBase* current, KItemModelBase* previous)
 {
     if (previous != 0) {
-        disconnect(previous, SIGNAL(dirLoadingCompleted()), this, SLOT(slotDirLoadingCompleted()));
+        disconnect(previous, SIGNAL(directoryLoadingCompleted()), this, SLOT(slotDirectoryLoadingCompleted()));
     }
 
     Q_ASSERT(qobject_cast<KFileItemModel*>(current));
-    connect(current, SIGNAL(loadingCompleted()), this, SLOT(slotDirLoadingCompleted()));
+    connect(current, SIGNAL(loadingCompleted()), this, SLOT(slotDirectoryLoadingCompleted()));
 
     KFileItemModel* fileItemModel = static_cast<KFileItemModel*>(current);
     m_versionControlObserver->setModel(fileItemModel);
@@ -1059,7 +1042,7 @@ void DolphinView::updateSortFoldersFirst(bool foldersFirst)
     props.setSortFoldersFirst(foldersFirst);
 
     KFileItemModel* model = fileItemModel();
-    model->setSortFoldersFirst(foldersFirst);
+    model->setSortDirectoriesFirst(foldersFirst);
 
     emit sortFoldersFirstChanged(foldersFirst);
 }
@@ -1095,7 +1078,7 @@ void DolphinView::restoreState(QDataStream& stream)
     // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
     QSet<KUrl> urls;
     stream >> urls;
-    fileItemModel()->restoreExpandedUrls(urls);
+    fileItemModel()->restoreExpandedDirectories(urls);
 }
 
 void DolphinView::saveState(QDataStream& stream)
@@ -1117,12 +1100,7 @@ void DolphinView::saveState(QDataStream& stream)
     stream << QPoint(x, y);
 
     // Save expanded folders (only relevant for the details view - the set will be empty in other view modes)
-    stream << fileItemModel()->expandedUrls();
-}
-
-bool DolphinView::hasSelection() const
-{
-    return m_container->controller()->selectionManager()->hasSelection();
+    stream << fileItemModel()->expandedDirectories();
 }
 
 KFileItem DolphinView::rootItem() const
@@ -1153,7 +1131,7 @@ void DolphinView::selectAndScrollToCreatedItem()
     m_createdItemUrl = KUrl();
 }
 
-void DolphinView::slotRedirection(const KUrl& oldUrl, const KUrl& newUrl)
+void DolphinView::slotDirectoryRedirection(const KUrl& oldUrl, const KUrl& newUrl)
 {
     if (oldUrl.equals(url(), KUrl::CompareWithoutTrailingSlash)) {
         emit redirection(oldUrl, newUrl);
@@ -1209,6 +1187,23 @@ void DolphinView::hideToolTip()
     }
 }
 
+void DolphinView::calculateItemCount(int& fileCount,
+                                     int& folderCount,
+                                     KIO::filesize_t& totalFileSize) const
+{
+    const KFileItemModel* model = fileItemModel();
+    const int itemCount = model->count();
+    for (int i = 0; i < itemCount; ++i) {
+        const KFileItem item = model->fileItem(i);
+        if (item.isDir()) {
+            ++folderCount;
+        } else {
+            ++fileCount;
+            totalFileSize += item.size();
+        }
+    }
+}
+
 void DolphinView::showHoverInformation(const KFileItem& item)
 {
     emit requestItemInfo(item);
@@ -1228,7 +1223,7 @@ void DolphinView::slotDeleteFileFinished(KJob* job)
     }
 }
 
-void DolphinView::slotDirLoadingStarted()
+void DolphinView::slotDirectoryLoadingStarted()
 {
     // Disable the writestate temporary until it can be determined in a fast way
     // in DolphinView::slotLoadingCompleted()
@@ -1237,16 +1232,16 @@ void DolphinView::slotDirLoadingStarted()
         emit writeStateChanged(m_isFolderWritable);
     }
 
-    emit startedDirLoading(url());
+    emit directoryLoadingStarted();
 }
 
-void DolphinView::slotDirLoadingCompleted()
+void DolphinView::slotDirectoryLoadingCompleted()
 {
-    // Update the view-state. This has to be done using a Qt::QueuedConnection
+    // Update the view-state. This has to be done asynchronously
     // because the view might not be in its final state yet.
     QTimer::singleShot(0, this, SLOT(updateViewState()));
 
-    emit finishedDirLoading(url());
+    emit directoryLoadingCompleted();
 
     updateWritableState();
 }
@@ -1313,9 +1308,9 @@ void DolphinView::loadDirectory(const KUrl& url, bool reload)
 
     KFileItemModel* model = fileItemModel();
     if (reload) {
-        model->refreshDir(url);
+        model->refreshDirectory(url);
     } else {
-        model->loadDir(url);
+        model->loadDirectory(url);
     }
 }
 
@@ -1375,8 +1370,8 @@ void DolphinView::applyViewProperties()
     }
 
     const bool sortFoldersFirst = props.sortFoldersFirst();
-    if (sortFoldersFirst != model->sortFoldersFirst()) {
-        model->setSortFoldersFirst(sortFoldersFirst);
+    if (sortFoldersFirst != model->sortDirectoriesFirst()) {
+        model->setSortDirectoriesFirst(sortFoldersFirst);
         emit sortFoldersFirstChanged(sortFoldersFirst);
     }