]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
Allow that Dolphin can also be used with global view properties. Per default Dolphin...
[dolphin.git] / src / dolphinmainwindow.cpp
index 640e7071c7fe24d68ec18c607c8ae1d7dbb9d69f..7d0e0992624a31bdb9cf9aac33efd2a504901efb 100644 (file)
 #include <kfiledialog.h>
 #include <kconfig.h>
 #include <kurl.h>
-#include <kstdaccel.h>
 #include <kaction.h>
-#include <kstdaction.h>
+#include <kstandardaction.h>
 #include <kmenu.h>
-#include <kio/renamedlg.h>
+#include <kio/renamedialog.h>
 #include <kinputdialog.h>
 #include <kshell.h>
 #include <kdesktopfile.h>
@@ -115,9 +114,10 @@ void DolphinMainWindow::setActiveView(DolphinView* view)
 }
 
 void DolphinMainWindow::dropUrls(const KUrl::List& urls,
-                       const KUrl& destination)
+                                 const KUrl& destination)
 {
-    int selectedIndex = -1;
+    m_dropDestination = destination;
+    m_droppedUrls = urls;
 
     /* KDE4-TODO
     const ButtonState keyboardState = KApplication::keyboardMouseState();
@@ -142,49 +142,22 @@ void DolphinMainWindow::dropUrls(const KUrl::List& urls,
         // no shortcut is used, hence open a popup menu
         KMenu popup(this);
 
-        popup.insertItem(SmallIcon("goto"), i18n("&Move Here") + "\t" /* KDE4-TODO: + KKey::modFlagLabel(KKey::SHIFT)*/, 0);
-        popup.insertItem(SmallIcon("editcopy"), i18n( "&Copy Here" ) /* KDE4-TODO + "\t" + KKey::modFlagLabel(KKey::CTRL)*/, 1);
-        popup.insertItem(i18n("&Link Here") /* KDE4-TODO + "\t" + KKey::modFlagLabel((KKey::ModFlag)(KKey::CTRL|KKey::SHIFT)) */, 2);
-        popup.insertSeparator();
-        popup.insertItem(SmallIcon("stop"), i18n("Cancel"), 3);
-        popup.setAccel(i18n("Escape"), 3);
+        QAction* moveAction = popup.addAction(SmallIcon("goto"), i18n("&Move Here"));
+        connect(moveAction, SIGNAL(triggered()), this, SLOT(moveDroppedItems()));
 
-        /* KDE4-TODO: selectedIndex = popup.exec(QCursor::pos()); */
-        popup.exec(QCursor::pos());
-        selectedIndex = 0; // KD4-TODO: use QAction instead of switch below
-        // See libkonq/konq_operations.cc: KonqOperations::doDropFileCopy() (and doDrop, the main method)
-    }
-
-    if (selectedIndex < 0) {
-        return;
-    }
+        QAction* copyAction = popup.addAction(SmallIcon("editcopy"), i18n( "&Copy Here" ));
+        connect(copyAction, SIGNAL(triggered()), this, SLOT(copyDroppedItems()));
 
-    switch (selectedIndex) {
-        case 0: {
-            // 'Move Here' has been selected
-            updateViewProperties(urls);
-            moveUrls(urls, destination);
-            break;
-        }
-
-        case 1: {
-            // 'Copy Here' has been selected
-            updateViewProperties(urls);
-            copyUrls(urls, destination);
-            break;
-        }
+        QAction* linkAction = popup.addAction(i18n("&Link Here"));
+        connect(linkAction, SIGNAL(triggered()), this, SLOT(linkDroppedItems()));
 
-        case 2: {
-            // 'Link Here' has been selected
-            KIO::Job* job = KIO::link(urls, destination);
-            addPendingUndoJob(job, DolphinCommand::Link, urls, destination);
-            break;
-        }
+        QAction* cancelAction = popup.addAction(SmallIcon("stop"), i18n("Cancel"));
+        popup.insertSeparator(cancelAction);
 
-        default:
-            // 'Cancel' has been selected
-            break;
+        popup.exec(QCursor::pos());
     }
+
+    m_droppedUrls.clear();
 }
 
 void DolphinMainWindow::refreshViews()
@@ -316,6 +289,22 @@ void DolphinMainWindow::openNewMainWindow()
     DolphinApplication::app()->createMainWindow()->show();
 }
 
+void DolphinMainWindow::moveDroppedItems()
+{
+    moveUrls(m_droppedUrls, m_dropDestination);
+}
+
+void DolphinMainWindow::copyDroppedItems()
+{
+    copyUrls(m_droppedUrls, m_dropDestination);
+}
+
+void DolphinMainWindow::linkDroppedItems()
+{
+    KIO::Job* job = KIO::link(m_droppedUrls, m_dropDestination);
+    addPendingUndoJob(job, DolphinCommand::Link, m_droppedUrls, m_dropDestination);
+}
+
 void DolphinMainWindow::closeEvent(QCloseEvent* event)
 {
     // KDE4-TODO
@@ -380,7 +369,7 @@ void DolphinMainWindow::createFolder()
 
 
     if (baseUrl.isLocalFile() && QFileInfo(baseUrl.path(KUrl::AddTrailingSlash) + name).exists()) {
-        name = KIO::RenameDlg::suggestName(baseUrl, i18n("New Folder"));
+        name = KIO::RenameDialog::suggestName(baseUrl, i18n("New Folder"));
     }
 
     bool ok = false;
@@ -485,7 +474,7 @@ void DolphinMainWindow::createFile()
     const bool fileExists = viewUrl.isLocalFile() &&
                             QFileInfo(viewUrl.path(KUrl::AddTrailingSlash) + KIO::encodeFileName(name)).exists();
     if (fileExists) {
-        name = KIO::RenameDlg::suggestName(viewUrl, name);
+        name = KIO::RenameDialog::suggestName(viewUrl, name);
     }
 
     // let the user change the suggested file name
@@ -610,7 +599,7 @@ void DolphinMainWindow::slotDeleteFileFinished(KJob* job)
 
 void DolphinMainWindow::slotUndoAvailable(bool available)
 {
-    QAction* undoAction = actionCollection()->action(KStdAction::stdName(KStdAction::Undo));
+    QAction* undoAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo));
     if (undoAction != 0) {
         undoAction->setEnabled(available);
     }
@@ -618,7 +607,7 @@ void DolphinMainWindow::slotUndoAvailable(bool available)
 
 void DolphinMainWindow::slotUndoTextChanged(const QString& text)
 {
-    QAction* undoAction = actionCollection()->action(KStdAction::stdName(KStdAction::Undo));
+    QAction* undoAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Undo));
     if (undoAction != 0) {
         undoAction->setText(text);
     }
@@ -626,7 +615,7 @@ void DolphinMainWindow::slotUndoTextChanged(const QString& text)
 
 void DolphinMainWindow::slotRedoAvailable(bool available)
 {
-    QAction* redoAction = actionCollection()->action(KStdAction::stdName(KStdAction::Redo));
+    QAction* redoAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Redo));
     if (redoAction != 0) {
         redoAction->setEnabled(available);
     }
@@ -634,7 +623,7 @@ void DolphinMainWindow::slotRedoAvailable(bool available)
 
 void DolphinMainWindow::slotRedoTextChanged(const QString& text)
 {
-    QAction* redoAction = actionCollection()->action(KStdAction::stdName(KStdAction::Redo));
+    QAction* redoAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Redo));
     if (redoAction != 0) {
         redoAction->setText(text);
     }
@@ -696,7 +685,7 @@ void DolphinMainWindow::paste()
 
 void DolphinMainWindow::updatePasteAction()
 {
-    QAction* pasteAction = actionCollection()->action(KStdAction::stdName(KStdAction::Paste));
+    QAction* pasteAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Paste));
     if (pasteAction == 0) {
         return;
     }
@@ -837,6 +826,12 @@ void DolphinMainWindow::stopLoading()
 
 void DolphinMainWindow::togglePreview()
 {
+    clearStatusBar();
+
+    const KToggleAction* showPreviewAction =
+        static_cast<KToggleAction*>(actionCollection()->action("show_preview"));
+    const bool show = showPreviewAction->isChecked();
+    m_activeView->setShowPreview(show);
 }
 
 void DolphinMainWindow::toggleShowHiddenFiles()
@@ -1174,11 +1169,11 @@ void DolphinMainWindow::setupActions()
     properties->setShortcut(Qt::Key_Alt | Qt::Key_Return);
     connect(properties, SIGNAL(triggered()), this, SLOT(properties()));
 
-    KStdAction::quit(this, SLOT(quit()), actionCollection());
+    KStandardAction::quit(this, SLOT(quit()), actionCollection());
 
     // setup 'Edit' menu
     UndoManager& undoManager = UndoManager::instance();
-    KStdAction::undo(this,
+    KStandardAction::undo(this,
                      SLOT(undo()),
                      actionCollection());
     connect(&undoManager, SIGNAL(undoAvailable(bool)),
@@ -1186,7 +1181,7 @@ void DolphinMainWindow::setupActions()
     connect(&undoManager, SIGNAL(undoTextChanged(const QString&)),
             this, SLOT(slotUndoTextChanged(const QString&)));
 
-    KStdAction::redo(this,
+    KStandardAction::redo(this,
                      SLOT(redo()),
                      actionCollection());
     connect(&undoManager, SIGNAL(redoAvailable(bool)),
@@ -1194,9 +1189,9 @@ void DolphinMainWindow::setupActions()
     connect(&undoManager, SIGNAL(redoTextChanged(const QString&)),
             this, SLOT(slotRedoTextChanged(const QString&)));
 
-    KStdAction::cut(this, SLOT(cut()), actionCollection());
-    KStdAction::copy(this, SLOT(copy()), actionCollection());
-    KStdAction::paste(this, SLOT(paste()), actionCollection());
+    KStandardAction::cut(this, SLOT(cut()), actionCollection());
+    KStandardAction::copy(this, SLOT(copy()), actionCollection());
+    KStandardAction::paste(this, SLOT(paste()), actionCollection());
 
     KAction* selectAll = new KAction(i18n("Select All"), actionCollection(), "select_all");
     selectAll->setShortcut(Qt::CTRL + Qt::Key_A);
@@ -1207,11 +1202,11 @@ void DolphinMainWindow::setupActions()
     connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
 
     // setup 'View' menu
-    KStdAction::zoomIn(this,
+    KStandardAction::zoomIn(this,
                        SLOT(zoomIn()),
                        actionCollection());
 
-    KStdAction::zoomOut(this,
+    KStandardAction::zoomOut(this,
                         SLOT(zoomOut()),
                         actionCollection());
 
@@ -1280,10 +1275,10 @@ void DolphinMainWindow::setupActions()
     connect(adjustViewProps, SIGNAL(triggered()), this, SLOT(adjustViewProperties()));
 
     // setup 'Go' menu
-    KStdAction::back(this, SLOT(goBack()), actionCollection());
-    KStdAction::forward(this, SLOT(goForward()), actionCollection());
-    KStdAction::up(this, SLOT(goUp()), actionCollection());
-    KStdAction::home(this, SLOT(goHome()), actionCollection());
+    KStandardAction::back(this, SLOT(goBack()), actionCollection());
+    KStandardAction::forward(this, SLOT(goForward()), actionCollection());
+    KStandardAction::up(this, SLOT(goUp()), actionCollection());
+    KStandardAction::home(this, SLOT(goHome()), actionCollection());
 
     // setup 'Tools' menu
     KAction* openTerminal = new KAction(i18n("Open Terminal"), actionCollection(), "open_terminal");
@@ -1306,28 +1301,26 @@ void DolphinMainWindow::setupActions()
     connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles()));
 
     // setup 'Settings' menu
-    KStdAction::preferences(this, SLOT(editSettings()), actionCollection());
+    KStandardAction::preferences(this, SLOT(editSettings()), actionCollection());
 }
 
 void DolphinMainWindow::setupDockWidgets()
 {
-    QDockWidget *shortcutsDock = new QDockWidget(i18n("Shortcuts"));
-
-    shortcutsDock->setObjectName("shortcutsDock");
+    QDockWidget* shortcutsDock = new QDockWidget(i18n("Shortcuts"));
+    shortcutsDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
     shortcutsDock->setWidget(new BookmarksSidebarPage(this));
 
-    shortcutsDock->toggleViewAction()->setObjectName("show_shortcuts_pane");
+    shortcutsDock->toggleViewAction()->setObjectName("show_shortcuts_panel");
     shortcutsDock->toggleViewAction()->setText(i18n("Show Shortcuts Panel"));
     actionCollection()->insert(shortcutsDock->toggleViewAction());
 
     addDockWidget(Qt::LeftDockWidgetArea, shortcutsDock);
 
-    QDockWidget *infoDock = new QDockWidget(i18n("Information"));
-
-    infoDock->setObjectName("infoDock");
+    QDockWidget* infoDock = new QDockWidget(i18n("Information"));
+    infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
     infoDock->setWidget(new InfoSidebarPage(this));
 
-    infoDock->toggleViewAction()->setObjectName("show_info_pane");
+    infoDock->toggleViewAction()->setObjectName("show_info_panel");
     infoDock->toggleViewAction()->setText(i18n("Show Information Panel"));
     actionCollection()->insert(infoDock->toggleViewAction());
 
@@ -1488,12 +1481,12 @@ void DolphinMainWindow::updateEditActions()
 
 void DolphinMainWindow::updateViewActions()
 {
-    QAction* zoomInAction = actionCollection()->action(KStdAction::stdName(KStdAction::ZoomIn));
+    QAction* zoomInAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomIn));
     if (zoomInAction != 0) {
         zoomInAction->setEnabled(m_activeView->isZoomInPossible());
     }
 
-    QAction* zoomOutAction = actionCollection()->action(KStdAction::stdName(KStdAction::ZoomOut));
+    QAction* zoomOutAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::ZoomOut));
     if (zoomOutAction != 0) {
         zoomOutAction->setEnabled(m_activeView->isZoomOutPossible());
     }
@@ -1535,35 +1528,11 @@ void DolphinMainWindow::updateViewActions()
 
 void DolphinMainWindow::updateGoActions()
 {
-    QAction* goUpAction = actionCollection()->action(KStdAction::stdName(KStdAction::Up));
+    QAction* goUpAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Up));
     const KUrl& currentUrl = m_activeView->url();
     goUpAction->setEnabled(currentUrl.upUrl() != currentUrl);
 }
 
-void DolphinMainWindow::updateViewProperties(const KUrl::List& urls)
-{
-    if (urls.isEmpty()) {
-        return;
-    }
-
-    // Updating the view properties might take up to several seconds
-    // when dragging several thousand Urls. Writing a KIO slave for this
-    // use case is not worth the effort, but at least the main widget
-    // must be disabled and a progress should be shown.
-    ProgressIndicator progressIndicator(this,
-                                        i18n("Updating view properties..."),
-                                        QString::null,
-                                        urls.count());
-
-    KUrl::List::ConstIterator end = urls.end();
-    for(KUrl::List::ConstIterator it = urls.begin(); it != end; ++it) {
-        progressIndicator.execOperation();
-
-        ViewProperties props(*it);
-        props.save();
-    }
-}
-
 void DolphinMainWindow::copyUrls(const KUrl::List& source, const KUrl& dest)
 {
     KIO::Job* job = KIO::copy(source, dest);