]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinview.cpp
Clean includes + port to QMenu
[dolphin.git] / src / views / dolphinview.cpp
index e7034984e9da6001c4e20c9f2c84ffd93a1b795a..b3df1ebd6ca33736dd4b3c814e7de96bc8141ef0 100644 (file)
@@ -58,7 +58,7 @@
 #include <KIO/PreviewJob>
 #include <KIO/Paste>
 #include <KJob>
-#include <KMenu>
+#include <QMenu>
 #include <KGlobal>
 #include <KMessageBox>
 #include <KJobWidgets>
@@ -81,6 +81,7 @@
 #ifdef HAVE_BALOO
     #include <Baloo/IndexerConfig>
 #endif
+#include <KFormat>
 
 namespace {
     const int MaxModeEnum = DolphinView::CompactView;
@@ -489,7 +490,7 @@ void DolphinView::readSettings()
 {
     const int oldZoomLevel = m_view->zoomLevel();
 
-    GeneralSettings::self()->readConfig();
+    GeneralSettings::self()->load();
     m_view->readSettings();
     applyViewProperties();
 
@@ -504,7 +505,7 @@ void DolphinView::readSettings()
 
 void DolphinView::writeSettings()
 {
-    GeneralSettings::self()->writeConfig();
+    GeneralSettings::self()->save();
     m_view->writeSettings();
 }
 
@@ -567,11 +568,11 @@ QString DolphinView::statusBarText() const
     if (fileCount > 0 && folderCount > 0) {
         summary = i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
                         foldersText, filesText,
-                        KGlobal::locale()->formatByteSize(totalFileSize));
+                        KFormat().formatByteSize(totalFileSize));
     } else if (fileCount > 0) {
         summary = i18nc("@info:status files (size)", "%1 (%2)",
                         filesText,
-                        KGlobal::locale()->formatByteSize(totalFileSize));
+                        KFormat().formatByteSize(totalFileSize));
     } else if (folderCount > 0) {
         summary = foldersText;
     } else {
@@ -873,7 +874,7 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos)
 {
     ViewProperties props(viewPropertiesUrl());
 
-    QPointer<KMenu> menu = new KMenu(QApplication::activeWindow());
+    QPointer<QMenu> menu = new QMenu(QApplication::activeWindow());
 
     KItemListView* view = m_container->controller()->view();
     const QSet<QByteArray> visibleRolesSet = view->visibleRoles().toSet();
@@ -1084,10 +1085,9 @@ void DolphinView::slotMouseButtonPressed(int itemIndex, Qt::MouseButtons buttons
 
     hideToolTip();
 
-    // TODO: Qt5: Replace Qt::XButton1 by Qt::BackButton and Qt::XButton2 by Qt::ForwardButton
-    if (buttons & Qt::XButton1) {
+    if (buttons & Qt::BackButton) {
         emit goBackRequested();
-    } else if (buttons & Qt::XButton2) {
+    } else if (buttons & Qt::ForwardButton) {
         emit goForwardRequested();
     }
 }
@@ -1390,13 +1390,19 @@ void DolphinView::slotDeleteFileFinished(KJob* job)
     }
 }
 
-void DolphinView::slotRenamingFailed(const KUrl& oldUrl, const KUrl& newUrl)
+void DolphinView::slotRenamingResult(KJob* job)
 {
-    const int index = m_model->index(newUrl);
-    if (index >= 0) {
-        QHash<QByteArray, QVariant> data;
-        data.insert("text", oldUrl.fileName());
-        m_model->setData(index, data);
+    if (job->error()) {
+        KIO::CopyJob *copyJob = qobject_cast<KIO::CopyJob *>(job);
+        Q_ASSERT(copyJob);
+        const QUrl newUrl = copyJob->destUrl();
+        const int index = m_model->index(KUrl(newUrl));
+        if (index >= 0) {
+            QHash<QByteArray, QVariant> data;
+            const QUrl oldUrl = copyJob->srcUrls().first();
+            data.insert("text", oldUrl.fileName());
+            m_model->setData(index, data);
+        }
     }
 }
 
@@ -1487,12 +1493,14 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, con
         if (!newName.isEmpty() && newName != oldItem.text() && newName != QLatin1String(".") && newName != QLatin1String("..")) {
             const KUrl oldUrl = oldItem.url();
 
-            const KUrl newUrl(url().path(KUrl::AddTrailingSlash) + newName);
-            const bool newNameExistsAlready = (m_model->index(newUrl) >= 0);
+            QUrl newUrl = oldUrl.adjusted(QUrl::RemoveFilename);
+            newUrl.setPath(newUrl.path() + KIO::encodeFileName(newName));
+
+            const bool newNameExistsAlready = (m_model->index(KUrl(newUrl)) >= 0);
             if (!newNameExistsAlready) {
                 // Only change the data in the model if no item with the new name
                 // is in the model yet. If there is an item with the new name
-                // already, calling KonqOperations::rename() will open a dialog
+                // already, calling KIO::CopyJob will open a dialog
                 // asking for a new name, and KFileItemModel will update the
                 // data when the dir lister signals that the file name has changed.
                 QHash<QByteArray, QVariant> data;
@@ -1500,11 +1508,15 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, con
                 m_model->setData(index, data);
             }
 
-            KonqOperations* op = KonqOperations::renameV2(this, oldUrl, newName);
-            if (op && !newNameExistsAlready) {
-                // Only connect the renamingFailed signal if there is no item with the new name
+            KIO::Job * job = KIO::moveAs(oldUrl, newUrl);
+            KJobWidgets::setWindow(job, this);
+            KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename, QList<QUrl>() << oldUrl, newUrl, job);
+            job->ui()->setAutoErrorHandlingEnabled(true);
+
+            if (!newNameExistsAlready) {
+                // Only connect the result signal if there is no item with the new name
                 // in the model yet, see bug 328262.
-                connect(op, &KonqOperations::renamingFailed, this, &DolphinView::slotRenamingFailed);
+                connect(job, &KJob::result, this, &DolphinView::slotRenamingResult);
             }
         }
     }