]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinviewcontainer.cpp
Remove reference to a slot which does not exist. Almost identical code can be found...
[dolphin.git] / src / dolphinviewcontainer.cpp
index 0b2812a7ce1e7be18426353cf437ae1c237577ec..379c238d97ae0d9fc20c92b28a9c20ec58aa72a0 100644 (file)
@@ -60,9 +60,7 @@
 
 DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow,
                                            QWidget* parent,
-                                           const KUrl& url,
-                                           DolphinView::Mode mode,
-                                           bool showHiddenFiles) :
+                                           const KUrl& url) :
     QWidget(parent),
     m_showProgress(false),
     m_folderCount(0),
@@ -83,14 +81,11 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow,
     m_topLayout->setSpacing(0);
     m_topLayout->setMargin(0);
 
-    connect(m_mainWindow, SIGNAL(activeViewChanged()),
-            this, SLOT(updateActivationState()));
-
-    QClipboard* clipboard = QApplication::clipboard();
-    connect(clipboard, SIGNAL(dataChanged()),
-            this, SLOT(updateCutItems()));
-
     m_urlNavigator = new KUrlNavigator(DolphinSettings::instance().placesModel(), url, this);
+    connect(m_urlNavigator, SIGNAL(urlsDropped(const KUrl::List&, const KUrl&)),
+            m_mainWindow, SLOT(dropUrls(const KUrl::List&, const KUrl&)));
+    connect(m_urlNavigator, SIGNAL(activated()),
+            this, SLOT(activate()));
 
     const GeneralSettings* settings = DolphinSettings::instance().generalSettings();
     m_urlNavigator->setUrlEditable(settings->editableUrl());
@@ -99,7 +94,6 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow,
     m_dirLister = new DolphinDirLister();
     m_dirLister->setAutoUpdate(true);
     m_dirLister->setMainWindow(this);
-    m_dirLister->setShowingDotFiles(showHiddenFiles);
     m_dirLister->setDelayedMimeTypes(true);
 
     m_dirModel = new KDirModel();
@@ -117,10 +111,6 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow,
             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&)),
@@ -130,20 +120,30 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow,
                              url,
                              m_dirLister,
                              m_dirModel,
-                             m_proxyModel,
-                             mode,
-                             showHiddenFiles);
+                             m_proxyModel);
     connect(m_view, SIGNAL(urlChanged(const KUrl&)),
             m_urlNavigator, SLOT(setUrl(const KUrl&)));
-    connect(m_view, SIGNAL(requestContextMenu(KFileItem*, const KUrl&)),
-            this, SLOT(openContextMenu(KFileItem*, const KUrl&)));
+    connect(m_view, SIGNAL(requestContextMenu(KFileItem, const KUrl&)),
+            this, SLOT(openContextMenu(KFileItem, const KUrl&)));
     connect(m_view, SIGNAL(urlsDropped(const KUrl::List&, const KUrl&)),
             m_mainWindow, SLOT(dropUrls(const KUrl::List&, const KUrl&)));
+    connect(m_view, SIGNAL(contentsMoved(int, int)),
+            this, SLOT(saveContentsPos(int, int)));
+    connect(m_view, SIGNAL(requestItemInfo(KFileItem)),
+            this, SLOT(showItemInfo(KFileItem)));
+    connect(m_view, SIGNAL(errorMessage(const QString&)),
+            this, SLOT(showErrorMessage(const QString&)));
+    connect(m_view, SIGNAL(infoMessage(const QString&)),
+            this, SLOT(showInfoMessage(const QString&)));
+    connect(m_view, SIGNAL(itemTriggered(KFileItem)),
+            this, SLOT(slotItemTriggered(KFileItem)));
 
     connect(m_urlNavigator, SIGNAL(urlChanged(const KUrl&)),
             m_view, SLOT(setUrl(const KUrl&)));
 
     m_statusBar = new DolphinStatusBar(this, url);
+    connect(m_view, SIGNAL(urlChanged(const KUrl&)),
+            m_statusBar, SLOT(updateSpaceInfoContent(const KUrl&)));
 
     m_filterBar = new FilterBar(this);
     m_filterBar->setVisible(settings->filterBar());
@@ -189,11 +189,11 @@ bool DolphinViewContainer::isActive() const
 void DolphinViewContainer::renameSelectedItems()
 {
     DolphinViewContainer* view = m_mainWindow->activeViewContainer();
-    const KUrl::List urls = m_view->selectedUrls();
-    if (urls.count() > 1) {
+    const QList<KFileItem> items = m_view->selectedItems();
+    if (items.count() > 1) {
         // More than one item has been selected for renaming. Open
         // a rename dialog and rename all items afterwards.
-        RenameDialog dialog(urls);
+        RenameDialog dialog(items);
         if (dialog.exec() == QDialog::Rejected) {
             return;
         }
@@ -212,10 +212,10 @@ void DolphinViewContainer::renameSelectedItems()
             Q_ASSERT(replaceIndex >= 0);
             int index = 1;
 
-            KUrl::List::const_iterator it = urls.begin();
-            KUrl::List::const_iterator end = urls.end();
+            QList<KFileItem>::const_iterator it = items.begin();
+            QList<KFileItem>::const_iterator end = items.end();
             while (it != end) {
-                const KUrl& oldUrl = *it;
+                const KUrl& oldUrl = (*it).url();
                 QString number;
                 number.setNum(index++);
 
@@ -233,12 +233,12 @@ void DolphinViewContainer::renameSelectedItems()
     } else {
         // Only one item has been selected for renaming. Use the custom
         // renaming mechanism from the views.
-        Q_ASSERT(urls.count() == 1);
+        Q_ASSERT(items.count() == 1);
 
         // TODO: Think about using KFileItemDelegate as soon as it supports editing.
         // Currently the RenameDialog is used, but I'm not sure whether inline renaming
         // is a benefit for the user at all -> let's wait for some input first...
-        RenameDialog dialog(urls);
+        RenameDialog dialog(items);
         if (dialog.exec() == QDialog::Rejected) {
             return;
         }
@@ -248,7 +248,7 @@ void DolphinViewContainer::renameSelectedItems()
             view->statusBar()->setMessage(dialog.errorString(),
                                           DolphinStatusBar::Error);
         } else {
-            const KUrl& oldUrl = urls.first();
+            const KUrl& oldUrl = items.first().url();
             KUrl newUrl = oldUrl;
             newUrl.setFileName(newName);
             m_mainWindow->rename(oldUrl, newUrl);
@@ -256,11 +256,6 @@ void DolphinViewContainer::renameSelectedItems()
     }
 }
 
-DolphinStatusBar* DolphinViewContainer::statusBar() const
-{
-    return m_statusBar;
-}
-
 bool DolphinViewContainer::isFilterBarVisible() const
 {
     return m_filterBar->isVisible();
@@ -271,74 +266,27 @@ bool DolphinViewContainer::isUrlEditable() const
     return m_urlNavigator->isUrlEditable();
 }
 
-KFileItem* DolphinViewContainer::fileItem(const QModelIndex index) const
+KFileItem DolphinViewContainer::fileItem(const QModelIndex& index) const
 {
     const QModelIndex dirModelIndex = m_proxyModel->mapToSource(index);
     return m_dirModel->itemForIndex(dirModelIndex);
 }
 
-void DolphinViewContainer::rename(const KUrl& source, const QString& newName)
+void DolphinViewContainer::updateProgress(int percent)
 {
-    bool ok = false;
-
-    if (newName.isEmpty() || (source.fileName() == newName)) {
-        return;
-    }
-
-    KUrl dest(source.upUrl());
-    dest.addPath(newName);
-
-    const bool destExists = KIO::NetAccess::exists(dest, false, this);
-    if (destExists) {
-        // the destination already exists, hence ask the user
-        // how to proceed...
-        KIO::RenameDialog renameDialog(this,
-                                       i18n("File Already Exists"),
-                                       source.path(),
-                                       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;
-        }
-
-        default:
-            // the renaming operation has been canceled
-            return;
+    if (!m_showProgress) {
+        // Only show the directory loading progress if the status bar does
+        // not contain another progress information. This means that
+        // the directory loading progress information has the lowest priority.
+        const QString progressText(m_statusBar->progressText());
+        const QString loadingText(i18nc("@info:progress", "Loading folder..."));
+        m_showProgress = progressText.isEmpty() || (progressText == loadingText);
+        if (m_showProgress) {
+            m_statusBar->setProgressText(loadingText);
+            m_statusBar->setProgress(0);
         }
-    } 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),
-                                DolphinStatusBar::OperationCompleted);
-
-        KonqOperations::rename(this, source, destFileName);
-    } else {
-        m_statusBar->setMessage(i18n("Renaming of file '%1' to '%2' failed.", source.fileName(), destFileName),
-                                DolphinStatusBar::Error);
-    }
-}
-
-DolphinMainWindow* DolphinViewContainer::mainWindow() const
-{
-    return m_mainWindow;
-}
-
-void DolphinViewContainer::updateProgress(int percent)
-{
     if (m_showProgress) {
         m_statusBar->setProgress(percent);
     }
@@ -371,7 +319,16 @@ void DolphinViewContainer::updateItemCount()
 
     updateStatusBar();
 
-    QTimer::singleShot(0, this, SLOT(restoreContentsPos()));
+    QTimer::singleShot(100, this, SLOT(restoreContentsPos()));
+}
+
+void DolphinViewContainer::showItemInfo(const KFileItem& item)
+{
+    if (item.isNull()) {
+        m_statusBar->clear();
+    } else {
+        m_statusBar->setMessage(item.getStatusBarInfo(), DolphinStatusBar::Default);
+    }
 }
 
 void DolphinViewContainer::showInfoMessage(const QString& msg)
@@ -401,7 +358,7 @@ QString DolphinViewContainer::defaultStatusBarText() const
 QString DolphinViewContainer::selectionStatusBarText() const
 {
     QString text;
-    const KFileItemList list = m_view->selectedItems();
+    const QList<KFileItem> list = m_view->selectedItems();
     if (list.isEmpty()) {
         // when an item is triggered, it is temporary selected but selectedItems()
         // will return an empty list
@@ -411,21 +368,21 @@ QString DolphinViewContainer::selectionStatusBarText() const
     int fileCount = 0;
     int folderCount = 0;
     KIO::filesize_t byteSize = 0;
-    KFileItemList::const_iterator it = list.begin();
-    const KFileItemList::const_iterator end = list.end();
+    QList<KFileItem>::const_iterator it = list.begin();
+    const QList<KFileItem>::const_iterator end = list.end();
     while (it != end) {
-        KFileItem* item = *it;
-        if (item->isDir()) {
+        const KFileItem& item = *it;
+        if (item.isDir()) {
             ++folderCount;
         } else {
             ++fileCount;
-            byteSize += item->size();
+            byteSize += item.size();
         }
         ++it;
     }
 
     if (folderCount > 0) {
-        text = i18np("1 Folder selected", "%1 Folders selected", folderCount);
+        text = i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount);
         if (fileCount > 0) {
             text += ", ";
         }
@@ -433,7 +390,7 @@ QString DolphinViewContainer::selectionStatusBarText() const
 
     if (fileCount > 0) {
         const QString sizeText(KIO::convertSize(byteSize));
-        text += i18np("1 File selected (%2)", "%1 Files selected (%2)", fileCount, sizeText);
+        text += i18ncp("@info:status", "1 File selected (%2)", "%1 Files selected (%2)", fileCount, sizeText);
     }
 
     return text;
@@ -493,11 +450,58 @@ void DolphinViewContainer::changeNameFilter(const QString& nameFilter)
 #endif
 }
 
-void DolphinViewContainer::openContextMenu(KFileItem* item,
+void DolphinViewContainer::openContextMenu(const KFileItem& item,
                                            const KUrl& url)
 {
     DolphinContextMenu contextMenu(m_mainWindow, item, url);
     contextMenu.open();
 }
 
+void DolphinViewContainer::saveContentsPos(int x, int y)
+{
+    m_urlNavigator->savePosition(x, y);
+}
+
+void DolphinViewContainer::restoreContentsPos()
+{
+    if (!url().isEmpty()) {
+        const QPoint pos = m_urlNavigator->savedPosition();
+        m_view->setContentsPosition(pos.x(), pos.y());
+    }
+}
+
+void DolphinViewContainer::activate()
+{
+    setActive(true);
+}
+
+void DolphinViewContainer::slotItemTriggered(const KFileItem& item)
+{
+    // Prefer the local path over the URL.
+    bool isLocal;
+    KUrl url = item.mostLocalUrl(isLocal);
+
+    if (item.isDir()) {
+        m_view->setUrl(url);
+    } 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");
+            m_view->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")) {
+            url.setProtocol("tar");
+            m_view->setUrl(url);
+        } else {
+            item.run();
+        }
+    } else {
+        item.run();
+    }
+}
+
 #include "dolphinviewcontainer.moc"