]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinmainwindow.cpp
SVN_SILENT make it compile (Dlg->Dialog)
[dolphin.git] / src / dolphinmainwindow.cpp
index 8706316d835a2963a3afbd6d2d93de48e32294d5..15d9b02f1665084f6f1c72f2667ba89d93642496 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>
@@ -51,6 +50,7 @@
 #include <kstandarddirs.h>
 #include <krun.h>
 #include <klocale.h>
+#include <konqmimedata.h>
 
 #include <qclipboard.h>
 #include <q3dragobject.h>
 DolphinMainWindow::DolphinMainWindow() :
     KMainWindow(0),
     m_splitter(0),
-    m_activeView(0),
-    m_clipboardContainsCutData(false)
+    m_activeView(0)
 {
     setObjectName("Dolphin");
     m_view[PrimaryIdx] = 0;
     m_view[SecondaryIdx] = 0;
-
-    m_fileGroupActions.setAutoDelete(true);
-
-    // TODO: the following members are not used yet. See documentation
-    // of DolphinMainWindow::linkGroupActions() and DolphinMainWindow::linkToDeviceActions()
-    // in the header file for details.
-    //m_linkGroupActions.setAutoDelete(true);
-    //m_linkToDeviceActions.setAutoDelete(true);
 }
 
 DolphinMainWindow::~DolphinMainWindow()
 {
-    /*
-     * bye, bye managed window
-     */
-    DolphinApplication::app()->removeMainWindow( this );
+    qDeleteAll(m_fileGroupActions);
+    m_fileGroupActions.clear();
+
+    DolphinApplication::app()->removeMainWindow(this);
 }
 
 void DolphinMainWindow::setActiveView(DolphinView* view)
@@ -217,7 +208,7 @@ void DolphinMainWindow::refreshViews()
                                         m_splitter,
                                         url,
                                         props.viewMode(),
-                                        props.isShowHiddenFilesEnabled());
+                                        props.showHiddenFiles());
             connectViewSignals(i);
             m_view[i]->show();
         }
@@ -239,7 +230,7 @@ void DolphinMainWindow::slotShowHiddenFilesChanged()
 {
     KToggleAction* showHiddenFilesAction =
         static_cast<KToggleAction*>(actionCollection()->action("show_hidden_files"));
-    showHiddenFilesAction->setChecked(m_activeView->isShowHiddenFilesEnabled());
+    showHiddenFilesAction->setChecked(m_activeView->showHiddenFiles());
 }
 
 void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting)
@@ -356,14 +347,14 @@ void DolphinMainWindow::readProperties(KConfig* config)
 {
     config->setGroup("Primary view");
     m_view[PrimaryIdx]->setUrl(config->readEntry("Url"));
-    m_view[PrimaryIdx]->setUrlEditable(config->readBoolEntry("Editable Url"));
+    m_view[PrimaryIdx]->setUrlEditable(config->readEntry("Editable Url", false));
     if (config->hasGroup("Secondary view")) {
         config->setGroup("Secondary view");
         if (m_view[SecondaryIdx] == 0) {
             toggleSplitView();
         }
         m_view[SecondaryIdx]->setUrl(config->readEntry("Url"));
-        m_view[SecondaryIdx]->setUrlEditable(config->readBoolEntry("Editable Url"));
+        m_view[SecondaryIdx]->setUrlEditable(config->readEntry("Editable Url", false));
     }
     else if (m_view[SecondaryIdx] != 0) {
         toggleSplitView();
@@ -388,7 +379,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;
@@ -458,7 +449,7 @@ void DolphinMainWindow::createFile()
     bool found = false;
     CreateFileEntry entry;
     while (!found && (it != end)) {
-        if ((*it).index() == senderName) {
+        if ((*it).key() == senderName) {
             entry = (*it).value();
             found = true;
         }
@@ -475,7 +466,7 @@ void DolphinMainWindow::createFile()
 
     // Get the source path of the template which should be copied.
     // The source path is part of the Url entry of the desktop file.
-    const int pos = entry.templatePath.findRev('/');
+    const int pos = entry.templatePath.lastIndexOf('/');
     QString sourcePath(entry.templatePath.left(pos + 1));
     sourcePath += KDesktopFile(entry.templatePath, true).readPathEntry("Url");
 
@@ -485,7 +476,7 @@ void DolphinMainWindow::createFile()
     name.replace("...", QString::null);
 
     // add the file extension to the name
-    name.append(sourcePath.right(sourcePath.length() - sourcePath.findRev('.')));
+    name.append(sourcePath.right(sourcePath.length() - sourcePath.lastIndexOf('.')));
 
     // Check whether a file with the current name already exists. If yes suggest automatically
     // a unique file name (e. g. "HTML File" will be replaced by "HTML File_1").
@@ -493,7 +484,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
@@ -572,7 +563,7 @@ void DolphinMainWindow::deleteItems()
     const bool del = KMessageBox::warningContinueCancel(this,
                                                         text,
                                                         QString::null,
-                                                        KGuiItem(i18n("Delete"), SmallIcon("editdelete"))
+                                                        KGuiItem(i18n("Delete"), KIcon("editdelete"))
                                                        ) == KMessageBox::Continue;
     if (del) {
         KIO::Job* job = KIO::del(list);
@@ -618,7 +609,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);
     }
@@ -626,7 +617,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);
     }
@@ -634,7 +625,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);
     }
@@ -642,7 +633,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);
     }
@@ -650,37 +641,31 @@ void DolphinMainWindow::slotRedoTextChanged(const QString& text)
 
 void DolphinMainWindow::cut()
 {
-    // TODO: this boolean doesn't work between instances of dolphin or with konqueror or with other
-    // apps. The "application/x-kde-cutselection" mimetype should be used instead, see KonqMimeData
-    // in libkonq
-    m_clipboardContainsCutData = true;
-    /* KDE4-TODO: Q3DragObject* data = new KUrlDrag(m_activeView->selectedUrls(),
-                                       widget());
-    QApplication::clipboard()->setData(data);*/
+    QMimeData* mimeData = new QMimeData();
+    const KUrl::List kdeUrls = m_activeView->selectedUrls();
+    const KUrl::List mostLocalUrls;
+    KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, true);
+    QApplication::clipboard()->setMimeData(mimeData);
 }
 
 void DolphinMainWindow::copy()
 {
-    m_clipboardContainsCutData = false;
-    /* KDE4-TODO:
-    Q3DragObject* data = new KUrlDrag(m_activeView->selectedUrls(),
-                                     widget());
-    QApplication::clipboard()->setData(data);*/
+    QMimeData* mimeData = new QMimeData();
+    const KUrl::List kdeUrls = m_activeView->selectedUrls();
+    const KUrl::List mostLocalUrls;
+    KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, false);
+
+    QApplication::clipboard()->setMimeData(mimeData);
 }
 
 void DolphinMainWindow::paste()
 {
-    /* KDE4-TODO:   - see KonqOperations::doPaste
     QClipboard* clipboard = QApplication::clipboard();
-    QMimeSource* data = clipboard->data();
-    if (!KUrlDrag::canDecode(data)) {
-        return;
-    }
+    const QMimeData* mimeData = clipboard->mimeData();
 
     clearStatusBar();
 
-    KUrl::List sourceUrls;
-    KUrlDrag::decode(data, sourceUrls);
+    const KUrl::List sourceUrls = KUrl::List::fromMimeData(mimeData);
 
     // per default the pasting is done into the current Url of the view
     KUrl destUrl(m_activeView->url());
@@ -699,34 +684,30 @@ void DolphinMainWindow::paste()
         }
     }
 
-
-    updateViewProperties(sourceUrls);
-    if (m_clipboardContainsCutData) {
+    if (KonqMimeData::decodeIsCutSelection(mimeData)) {
         moveUrls(sourceUrls, destUrl);
-        m_clipboardContainsCutData = false;
         clipboard->clear();
     }
     else {
         copyUrls(sourceUrls, destUrl);
-    }*/
+    }
 }
 
 void DolphinMainWindow::updatePasteAction()
 {
-    QAction* pasteAction = actionCollection()->action(KStdAction::stdName(KStdAction::Paste));
+    QAction* pasteAction = actionCollection()->action(KStandardAction::stdName(KStandardAction::Paste));
     if (pasteAction == 0) {
         return;
     }
 
     QString text(i18n("Paste"));
     QClipboard* clipboard = QApplication::clipboard();
-    QMimeSource* data = clipboard->data();
-    /* KDE4-TODO:
-    if (KUrlDrag::canDecode(data)) {
+    const QMimeData* mimeData = clipboard->mimeData();
+
+    KUrl::List urls = KUrl::List::fromMimeData(mimeData);
+    if (!urls.isEmpty()) {
         pasteAction->setEnabled(true);
 
-        KUrl::List urls;
-        KUrlDrag::decode(data, urls);
         const int count = urls.count();
         if (count == 1) {
             pasteAction->setText(i18n("Paste 1 File"));
@@ -735,10 +716,10 @@ void DolphinMainWindow::updatePasteAction()
             pasteAction->setText(i18n("Paste %1 Files").arg(count));
         }
     }
-    else {*/
+    else {
         pasteAction->setEnabled(false);
         pasteAction->setText(i18n("Paste"));
-    //}
+    }
 
     if (pasteAction->isEnabled()) {
         KUrl::List urls = m_activeView->selectedUrls();
@@ -783,11 +764,6 @@ void DolphinMainWindow::setDetailsView()
     m_activeView->setMode(DolphinView::DetailsView);
 }
 
-void DolphinMainWindow::setPreviewsView()
-{
-    m_activeView->setMode(DolphinView::PreviewsView);
-}
-
 void DolphinMainWindow::sortByName()
 {
     m_activeView->setSorting(DolphinView::SortByName);
@@ -820,7 +796,7 @@ void DolphinMainWindow::toggleSplitView()
                                                0,
                                                m_view[PrimaryIdx]->url(),
                                                m_view[PrimaryIdx]->mode(),
-                                               m_view[PrimaryIdx]->isShowHiddenFilesEnabled());
+                                               m_view[PrimaryIdx]->showHiddenFiles());
         connectViewSignals(SecondaryIdx);
         m_splitter->addWidget(m_view[SecondaryIdx]);
         m_splitter->setSizes(QList<int>() << newWidth << newWidth);
@@ -858,14 +834,24 @@ void DolphinMainWindow::stopLoading()
 {
 }
 
-void DolphinMainWindow::showHiddenFiles()
+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()
 {
     clearStatusBar();
 
     const KToggleAction* showHiddenFilesAction =
         static_cast<KToggleAction*>(actionCollection()->action("show_hidden_files"));
     const bool show = showHiddenFilesAction->isChecked();
-    m_activeView->setShowHiddenFilesEnabled(show);
+    m_activeView->setShowHiddenFiles(show);
 }
 
 void DolphinMainWindow::showFilterBar()
@@ -1056,7 +1042,7 @@ void DolphinMainWindow::addUndoOperation(KJob* job)
                 while (sourceIt != sourceEnd) {
                     QMap<QString, QString>::ConstIterator metaIt = metaData.find("trashUrl-" + (*sourceIt).path());
                     if (metaIt != metaData.end()) {
-                        newSourceUrls.append(KUrl(metaIt.data()));
+                        newSourceUrls.append(KUrl(metaIt.value()));
                     }
                     ++sourceIt;
                 }
@@ -1120,7 +1106,7 @@ void DolphinMainWindow::init()
                                          m_splitter,
                                          homeUrl,
                                          props.viewMode(),
-                                         props.isShowHiddenFilesEnabled());
+                                         props.showHiddenFiles());
     connectViewSignals(PrimaryIdx);
     m_view[PrimaryIdx]->show();
 
@@ -1193,11 +1179,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)),
@@ -1205,7 +1191,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)),
@@ -1213,9 +1199,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);
@@ -1226,11 +1212,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());
 
@@ -1244,15 +1230,9 @@ void DolphinMainWindow::setupActions()
     detailsView->setIcon(KIcon("view_text"));
     connect(detailsView, SIGNAL(triggered()), this, SLOT(setDetailsView()));
 
-    KToggleAction* previewsView = new KToggleAction(i18n("Previews"), actionCollection(), "previews");
-    previewsView->setShortcut(Qt::CTRL | Qt::Key_3);
-    previewsView->setIcon(KIcon("gvdirpart"));
-    connect(previewsView, SIGNAL(triggered()), this, SLOT(setPreviewsView()));
-
     QActionGroup* viewModeGroup = new QActionGroup(this);
     viewModeGroup->addAction(iconsView);
     viewModeGroup->addAction(detailsView);
-    viewModeGroup->addAction(previewsView);
 
     KToggleAction* sortByName = new KToggleAction(i18n("By Name"), actionCollection(), "by_name");
     connect(sortByName, SIGNAL(triggered()), this, SLOT(sortByName()));
@@ -1271,16 +1251,20 @@ void DolphinMainWindow::setupActions()
     KToggleAction* sortDescending = new KToggleAction(i18n("Descending"), actionCollection(), "descending");
     connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder()));
 
+    KToggleAction* showPreview = new KToggleAction(i18n("Show Preview"), actionCollection(), "show_preview");
+    connect(showPreview, SIGNAL(triggered()), this, SLOT(togglePreview()));
+
     KToggleAction* showHiddenFiles = new KToggleAction(i18n("Show Hidden Files"), actionCollection(), "show_hidden_files");
     //showHiddenFiles->setShortcut(Qt::ALT | Qt::Key_      KDE4-TODO: what Qt-Key represents '.'?
-    connect(showHiddenFiles, SIGNAL(triggered()), this, SLOT(showHiddenFiles()));
+    connect(showHiddenFiles, SIGNAL(triggered()), this, SLOT(toggleShowHiddenFiles()));
 
     KToggleAction* split = new KToggleAction(i18n("Split View"), actionCollection(), "split_view");
     split->setShortcut(Qt::Key_F10);
     split->setIcon(KIcon("view_left_right"));
     connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView()));
 
-    KAction* reload = new KAction(i18n("Reload"), "F5", actionCollection(), "reload");
+    KAction* reload = new KAction(actionCollection(), "reload");
+    reload->setText(i18n("Reload"));
     reload->setShortcut(Qt::Key_F5);
     reload->setIcon(KIcon("reload"));
     connect(reload, SIGNAL(triggered()), this, SLOT(reloadView()));
@@ -1301,10 +1285,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");
@@ -1327,7 +1311,7 @@ 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()
@@ -1509,12 +1493,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());
     }
@@ -1527,9 +1511,9 @@ void DolphinMainWindow::updateViewActions()
         case DolphinView::DetailsView:
             action = actionCollection()->action("details");
             break;
-        case DolphinView::PreviewsView:
-            action = actionCollection()->action("previews");
-            break;
+        //case DolphinView::PreviewsView:
+        //    action = actionCollection()->action("previews");
+        //    break;
         default:
             break;
     }
@@ -1548,7 +1532,7 @@ void DolphinMainWindow::updateViewActions()
 
     KToggleAction* showHiddenFilesAction =
         static_cast<KToggleAction*>(actionCollection()->action("show_hidden_files"));
-    showHiddenFilesAction->setChecked(m_activeView->isShowHiddenFilesEnabled());
+    showHiddenFilesAction->setChecked(m_activeView->showHiddenFiles());
 
     KToggleAction* splitAction = static_cast<KToggleAction*>(actionCollection()->action("split_view"));
     splitAction->setChecked(m_view[SecondaryIdx] != 0);
@@ -1556,7 +1540,7 @@ 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);
 }
@@ -1598,9 +1582,9 @@ void DolphinMainWindow::moveUrls(const KUrl::List& source, const KUrl& dest)
 }
 
 void DolphinMainWindow::addPendingUndoJob(KIO::Job* job,
-                                DolphinCommand::Type commandType,
-                                const KUrl::List& source,
-                                const KUrl& dest)
+                                          DolphinCommand::Type commandType,
+                                          const KUrl::List& source,
+                                          const KUrl& dest)
 {
     connect(job, SIGNAL(result(KJob*)),
             this, SLOT(addUndoOperation(KJob*)));