X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/197f9a4280d601a7dc145e9eb1dd2ffca6fb8980..de4ffa3322c8d919ebdb0cdb51115bace8aa8d11:/src/dolphinmainwindow.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index fdda8d9e6..ad144d625 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -16,7 +16,7 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #include "dolphinmainwindow.h" @@ -36,11 +36,10 @@ #include #include #include -#include #include -#include +#include #include -#include +#include #include #include #include @@ -51,6 +50,7 @@ #include #include #include +#include #include #include @@ -79,28 +79,19 @@ 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) @@ -123,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(); @@ -150,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) - } + QAction* copyAction = popup.addAction(SmallIcon("editcopy"), i18n( "&Copy Here" )); + connect(copyAction, SIGNAL(triggered()), this, SLOT(copyDroppedItems())); - if (selectedIndex < 0) { - return; - } + QAction* linkAction = popup.addAction(i18n("&Link Here")); + connect(linkAction, SIGNAL(triggered()), this, SLOT(linkDroppedItems())); - 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* cancelAction = popup.addAction(SmallIcon("stop"), i18n("Cancel")); + popup.insertSeparator(cancelAction); - case 2: { - // 'Link Here' has been selected - KIO::Job* job = KIO::link(urls, destination); - addPendingUndoJob(job, DolphinCommand::Link, urls, destination); - break; - } - - default: - // 'Cancel' has been selected - break; + popup.exec(QCursor::pos()); } + + m_droppedUrls.clear(); } void DolphinMainWindow::refreshViews() @@ -217,7 +182,8 @@ void DolphinMainWindow::refreshViews() m_splitter, url, props.viewMode(), - props.isShowHiddenFilesEnabled()); + props.showHiddenFiles()); + connectViewSignals(i); m_view[i]->show(); } } @@ -229,24 +195,6 @@ void DolphinMainWindow::refreshViews() emit activeViewChanged(); } -void DolphinMainWindow::slotHistoryChanged() -{ - updateHistory(); -} - -void DolphinMainWindow::slotUrlChanged(const KUrl& url) -{ - updateEditActions(); - updateGoActions(); - setCaption(url.fileName()); -} - -void DolphinMainWindow::slotUrlChangeRequest(const KUrl& url) -{ - clearStatusBar(); - m_activeView->setUrl(url); -} - void DolphinMainWindow::slotViewModeChanged() { updateViewActions(); @@ -256,14 +204,7 @@ void DolphinMainWindow::slotShowHiddenFilesChanged() { KToggleAction* showHiddenFilesAction = static_cast(actionCollection()->action("show_hidden_files")); - showHiddenFilesAction->setChecked(m_activeView->isShowHiddenFilesEnabled()); -} - -void DolphinMainWindow::slotShowFilterBarChanged() -{ - KToggleAction* showFilterBarAction = - static_cast(actionCollection()->action("show_filter_bar")); - showFilterBarAction->setChecked(m_activeView->isFilterBarVisible()); + showHiddenFilesAction->setChecked(m_activeView->showHiddenFiles()); } void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting) @@ -314,34 +255,75 @@ void DolphinMainWindow::slotSelectionChanged() emit selectionChanged(); } -void DolphinMainWindow::slotRedo() +void DolphinMainWindow::slotHistoryChanged() +{ + updateHistory(); +} + +void DolphinMainWindow::slotUrlChanged(const KUrl& url) +{ + updateEditActions(); + updateGoActions(); + setCaption(url.fileName()); +} + +void DolphinMainWindow::updateFilterBarAction(bool show) +{ + KToggleAction* showFilterBarAction = + static_cast(actionCollection()->action("show_filter_bar")); + showFilterBarAction->setChecked(show); +} + +void DolphinMainWindow::redo() { UndoManager::instance().redo(this); } -void DolphinMainWindow::slotUndo() +void DolphinMainWindow::undo() { UndoManager::instance().undo(this); } -void DolphinMainWindow::slotNewMainWindow() +void DolphinMainWindow::openNewMainWindow() { DolphinApplication::app()->createMainWindow()->show(); } -void DolphinMainWindow::closeEvent(QCloseEvent* event) +void DolphinMainWindow::moveDroppedItems() { - // KDE4-TODO - //KConfig* config = KGlobal::config(); - //config->setGroup("General"); - //config->writeEntry("First Run", false); + 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) +{ DolphinSettings& settings = DolphinSettings::instance(); GeneralSettings* generalSettings = settings.generalSettings(); generalSettings->setFirstRun(false); settings.save(); + // TODO: I assume there will be a generic way in KDE 4 to store the docks + // of the main window. In the meantime they are stored manually: + QString filename = KStandardDirs::locateLocal("data", KGlobal::instance()->instanceName()); + filename.append("/panels_layout"); + QFile file(filename); + if (file.open(QIODevice::WriteOnly)) { + QByteArray data = saveState(); + file.write(data); + file.close(); + } + KMainWindow::closeEvent(event); } @@ -361,14 +343,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(); @@ -393,7 +375,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; @@ -455,7 +437,7 @@ void DolphinMainWindow::createFile() clearStatusBar(); // TODO: const Entry& entry = m_createFileTemplates[QString(sender->name())]; - // should be enough. Anyway: the implemantation of [] does a linear search internally too. + // should be enough. Anyway: the implementation of [] does a linear search internally too. KSortableList::ConstIterator it = m_createFileTemplates.begin(); KSortableList::ConstIterator end = m_createFileTemplates.end(); @@ -463,7 +445,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; } @@ -480,7 +462,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"); @@ -490,7 +472,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"). @@ -498,7 +480,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 @@ -577,7 +559,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); @@ -623,7 +605,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); } @@ -631,7 +613,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); } @@ -639,7 +621,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); } @@ -647,7 +629,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); } @@ -655,37 +637,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()); @@ -704,34 +680,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")); @@ -740,10 +712,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(); @@ -788,11 +760,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); @@ -819,12 +786,16 @@ void DolphinMainWindow::toggleSortOrder() void DolphinMainWindow::toggleSplitView() { if (m_view[SecondaryIdx] == 0) { + const int newWidth = (m_view[PrimaryIdx]->width() - m_splitter->handleWidth()) / 2; // create a secondary view m_view[SecondaryIdx] = new DolphinView(this, - m_splitter, + 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() << newWidth << newWidth); m_view[SecondaryIdx]->show(); } else { @@ -841,7 +812,7 @@ void DolphinMainWindow::toggleSplitView() // From an implementation point of view it is more efficient to close // the primary view and exchange the internal pointers afterwards. m_view[PrimaryIdx]->close(); - m_view[PrimaryIdx]->deleteLater(); + delete m_view[PrimaryIdx]; m_view[PrimaryIdx] = m_view[SecondaryIdx]; m_view[SecondaryIdx] = 0; setActiveView(m_view[PrimaryIdx]); @@ -859,14 +830,24 @@ void DolphinMainWindow::stopLoading() { } -void DolphinMainWindow::showHiddenFiles() +void DolphinMainWindow::togglePreview() +{ + clearStatusBar(); + + const KToggleAction* showPreviewAction = + static_cast(actionCollection()->action("show_preview")); + const bool show = showPreviewAction->isChecked(); + m_activeView->setShowPreview(show); +} + +void DolphinMainWindow::toggleShowHiddenFiles() { clearStatusBar(); const KToggleAction* showHiddenFilesAction = static_cast(actionCollection()->action("show_hidden_files")); const bool show = showHiddenFilesAction->isChecked(); - m_activeView->setShowHiddenFilesEnabled(show); + m_activeView->setShowHiddenFiles(show); } void DolphinMainWindow::showFilterBar() @@ -1057,7 +1038,7 @@ void DolphinMainWindow::addUndoOperation(KJob* job) while (sourceIt != sourceEnd) { QMap::ConstIterator metaIt = metaData.find("trashUrl-" + (*sourceIt).path()); if (metaIt != metaData.end()) { - newSourceUrls.append(KUrl(metaIt.data())); + newSourceUrls.append(KUrl(metaIt.value())); } ++sourceIt; } @@ -1121,7 +1102,9 @@ void DolphinMainWindow::init() m_splitter, homeUrl, props.viewMode(), - props.isShowHiddenFilesEnabled()); + props.showHiddenFiles()); + connectViewSignals(PrimaryIdx); + m_view[PrimaryIdx]->show(); m_activeView = m_view[PrimaryIdx]; @@ -1161,105 +1144,125 @@ void DolphinMainWindow::loadSettings() } updateViewActions(); + + // TODO: I assume there will be a generic way in KDE 4 to restore the docks + // of the main window. In the meantime they are restored manually (see also + // DolphinMainWindow::closeEvent() for more details): + QString filename = KStandardDirs::locateLocal("data", KGlobal::instance()->instanceName()); + filename.append("/panels_layout"); + QFile file(filename); + if (file.open(QIODevice::ReadOnly)) { + QByteArray data = file.readAll(); + restoreState(data); + file.close(); + } } void DolphinMainWindow::setupActions() { // setup 'File' menu - KAction *action = new KAction(KIcon("window_new"), i18n( "New &Window" ), actionCollection(), "new_window" ); - connect(action, SIGNAL(triggered()), this, SLOT(slotNewMainWindow())); + QAction *action = actionCollection()->addAction("new_window"); + action->setIcon(KIcon("window_new")); + action->setText(i18n("New &Window")); + connect(action, SIGNAL(triggered()), this, SLOT(openNewMainWindow())); - KAction* createFolder = new KAction(i18n("Folder..."), actionCollection(), "create_folder"); + QAction* createFolder = actionCollection()->addAction("create_folder"); + createFolder->setText(i18n("Folder...")); createFolder->setIcon(KIcon("folder")); createFolder->setShortcut(Qt::Key_N); connect(createFolder, SIGNAL(triggered()), this, SLOT(createFolder())); - KAction* rename = new KAction(i18n("Rename"), actionCollection(), "rename"); + QAction* rename = actionCollection()->addAction("rename"); + rename->setText(i18n("Rename")); rename->setShortcut(Qt::Key_F2); connect(rename, SIGNAL(triggered()), this, SLOT(rename())); - KAction* moveToTrash = new KAction(i18n("Move to Trash"), actionCollection(), "move_to_trash"); + QAction* moveToTrash = actionCollection()->addAction("move_to_trash"); + moveToTrash->setText(i18n("Move to Trash")); moveToTrash->setIcon(KIcon("edittrash")); moveToTrash->setShortcut(QKeySequence::Delete); connect(moveToTrash, SIGNAL(triggered()), this, SLOT(moveToTrash())); - KAction* deleteAction = new KAction(i18n("Delete"), actionCollection(), "delete"); + QAction* deleteAction = actionCollection()->addAction("delete"); + deleteAction->setText(i18n("Delete")); deleteAction->setShortcut(Qt::ALT | Qt::Key_Delete); deleteAction->setIcon(KIcon("editdelete")); connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItems())); - KAction* properties = new KAction(i18n("Propert&ies"), actionCollection(), "properties"); + QAction* properties = actionCollection()->addAction("properties"); + properties->setText(i18n("Propert&ies")); 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, - SLOT(slotUndo()), + KStandardAction::undo(this, + SLOT(undo()), actionCollection()); connect(&undoManager, SIGNAL(undoAvailable(bool)), this, SLOT(slotUndoAvailable(bool))); connect(&undoManager, SIGNAL(undoTextChanged(const QString&)), this, SLOT(slotUndoTextChanged(const QString&))); - KStdAction::redo(this, - SLOT(slotRedo()), + KStandardAction::redo(this, + SLOT(redo()), actionCollection()); connect(&undoManager, SIGNAL(redoAvailable(bool)), this, SLOT(slotRedoAvailable(bool))); 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"); + QAction* selectAll = actionCollection()->addAction("select_all"); + selectAll->setText(i18n("Select All")); selectAll->setShortcut(Qt::CTRL + Qt::Key_A); connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll())); - KAction* invertSelection = new KAction(i18n("Invert Selection"), actionCollection(), "invert_selection"); + QAction* invertSelection = actionCollection()->addAction("invert_selection"); + invertSelection->setText(i18n("Invert Selection")); invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A); 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()); - KToggleAction* iconsView = new KToggleAction(i18n("Icons"), actionCollection(), "icons"); + KToggleAction* iconsView = actionCollection()->add("icons"); + iconsView->setText(i18n("Icons")); iconsView->setShortcut(Qt::CTRL | Qt::Key_1); iconsView->setIcon(KIcon("view_icon")); connect(iconsView, SIGNAL(triggered()), this, SLOT(setIconsView())); - KToggleAction* detailsView = new KToggleAction(i18n("Details"), actionCollection(), "details"); + KToggleAction* detailsView = actionCollection()->add("details"); + detailsView->setText(i18n("Details")); detailsView->setShortcut(Qt::CTRL | Qt::Key_2); 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"); + KToggleAction* sortByName = actionCollection()->add("by_name"); + sortByName->setText(i18n("By Name")); connect(sortByName, SIGNAL(triggered()), this, SLOT(sortByName())); - KToggleAction* sortBySize = new KToggleAction(i18n("By Size"), actionCollection(), "by_size"); + KToggleAction* sortBySize = actionCollection()->add("by_size"); + sortBySize->setText(i18n("By Size")); connect(sortBySize, SIGNAL(triggered()), this, SLOT(sortBySize())); - KToggleAction* sortByDate = new KToggleAction(i18n("By Date"), actionCollection(), "by_date"); + KToggleAction* sortByDate = actionCollection()->add("by_date"); + sortByDate->setText(i18n("By Date")); connect(sortByDate, SIGNAL(triggered()), this, SLOT(sortByDate())); QActionGroup* sortGroup = new QActionGroup(this); @@ -1267,66 +1270,105 @@ void DolphinMainWindow::setupActions() sortGroup->addAction(sortBySize); sortGroup->addAction(sortByDate); - KToggleAction* sortDescending = new KToggleAction(i18n("Descending"), actionCollection(), "descending"); + KToggleAction* sortDescending = actionCollection()->add("descending"); + sortDescending->setText(i18n("Descending")); connect(sortDescending, SIGNAL(triggered()), this, SLOT(toggleSortOrder())); - KToggleAction* showHiddenFiles = new KToggleAction(i18n("Show Hidden Files"), actionCollection(), "show_hidden_files"); + KToggleAction* showPreview = actionCollection()->add("show_preview"); + showPreview->setText(i18n("Show Preview")); + connect(showPreview, SIGNAL(triggered()), this, SLOT(togglePreview())); + + KToggleAction* showHiddenFiles = actionCollection()->add("show_hidden_files"); + showHiddenFiles->setText(i18n("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"); + KToggleAction* split = actionCollection()->add("split_view"); + split->setText(i18n("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"); + QAction* reload = actionCollection()->addAction("reload"); + reload->setText(i18n("Reload")); reload->setShortcut(Qt::Key_F5); reload->setIcon(KIcon("reload")); connect(reload, SIGNAL(triggered()), this, SLOT(reloadView())); - KAction* stop = new KAction(i18n("Stop"), actionCollection(), "stop"); + QAction* stop = actionCollection()->addAction("stop"); + stop->setText(i18n("Stop")); stop->setIcon(KIcon("stop")); connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading())); - KToggleAction* showFullLocation = new KToggleAction(i18n("Show Full Location"), actionCollection(), "editable_location"); + KToggleAction* showFullLocation = actionCollection()->add("editable_location"); + showFullLocation->setText(i18n("Show Full Location")); showFullLocation->setShortcut(Qt::CTRL | Qt::Key_L); connect(showFullLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation())); - KToggleAction* editLocation = new KToggleAction(i18n("Edit Location"), actionCollection(), "edit_location"); + KToggleAction* editLocation = actionCollection()->add("edit_location"); + editLocation->setText(i18n("Edit Location")); editLocation->setShortcut(Qt::Key_F6); connect(editLocation, SIGNAL(triggered()), this, SLOT(editLocation())); - KAction* adjustViewProps = new KAction(i18n("Adjust View Properties..."), actionCollection(), "view_properties"); + QAction* adjustViewProps = actionCollection()->addAction("view_properties"); + adjustViewProps->setText(i18n("Adjust View Properties...")); 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"); + QAction* openTerminal = actionCollection()->addAction("open_terminal"); + openTerminal->setText(i18n("Open Terminal")); openTerminal->setShortcut(Qt::Key_F4); openTerminal->setIcon(KIcon("konsole")); connect(openTerminal, SIGNAL(triggered()), this, SLOT(openTerminal())); - KAction* findFile = new KAction(i18n("Find File..."), actionCollection(), "find_file"); + QAction* findFile = actionCollection()->addAction("find_file"); + findFile->setText(i18n("Find File...")); findFile->setShortcut(Qt::Key_F); findFile->setIcon(KIcon("filefind")); connect(findFile, SIGNAL(triggered()), this, SLOT(findFile())); - KToggleAction* showFilterBar = new KToggleAction(i18n("Show Filter Bar"), actionCollection(), "show_filter_bar"); + KToggleAction* showFilterBar = actionCollection()->add("show_filter_bar"); + showFilterBar->setText(i18n("Show Filter Bar")); showFilterBar->setShortcut(Qt::Key_Slash); connect(showFilterBar, SIGNAL(triggered()), this, SLOT(showFilterBar())); - KAction* compareFiles = new KAction(i18n("Compare Files"), actionCollection(), "compare_files"); + QAction* compareFiles = actionCollection()->addAction("compare_files"); + compareFiles->setText(i18n("Compare Files")); compareFiles->setIcon(KIcon("kompare")); compareFiles->setEnabled(false); 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("Bookmarks")); + shortcutsDock->setObjectName("bookmarksDock"); + shortcutsDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + shortcutsDock->setWidget(new BookmarksSidebarPage(this)); + + shortcutsDock->toggleViewAction()->setText(i18n("Show Bookmarks Panel")); + actionCollection()->addAction("show_bookmarks_panel", shortcutsDock->toggleViewAction()); + + addDockWidget(Qt::LeftDockWidgetArea, shortcutsDock); + + QDockWidget* infoDock = new QDockWidget(i18n("Information")); + infoDock->setObjectName("infoDock"); + infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + infoDock->setWidget(new InfoSidebarPage(this)); + + infoDock->toggleViewAction()->setText(i18n("Show Information Panel")); + actionCollection()->addAction("show_info_panel", infoDock->toggleViewAction()); + + addDockWidget(Qt::RightDockWidgetArea, infoDock); } void DolphinMainWindow::setupCreateNewMenuActions() @@ -1483,12 +1525,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()); } @@ -1501,9 +1543,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; } @@ -1522,7 +1564,7 @@ void DolphinMainWindow::updateViewActions() KToggleAction* showHiddenFilesAction = static_cast(actionCollection()->action("show_hidden_files")); - showHiddenFilesAction->setChecked(m_activeView->isShowHiddenFilesEnabled()); + showHiddenFilesAction->setChecked(m_activeView->showHiddenFiles()); KToggleAction* splitAction = static_cast(actionCollection()->action("split_view")); splitAction->setChecked(m_view[SecondaryIdx] != 0); @@ -1530,35 +1572,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); @@ -1572,9 +1590,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*))); @@ -1590,29 +1608,28 @@ void DolphinMainWindow::clearStatusBar() m_activeView->statusBar()->clear(); } -void DolphinMainWindow::setupDockWidgets() -{ - QDockWidget *shortcutsDock = new QDockWidget(i18n("Shortcuts")); - - shortcutsDock->setObjectName("shortcutsDock"); - shortcutsDock->setWidget(new BookmarksSidebarPage(this)); - - shortcutsDock->toggleViewAction()->setObjectName("show_shortcuts_pane"); - shortcutsDock->toggleViewAction()->setText(i18n("Show Shortcuts Panel")); - actionCollection()->insert(shortcutsDock->toggleViewAction()); - - addDockWidget(Qt::LeftDockWidgetArea, shortcutsDock); - - QDockWidget *infoDock = new QDockWidget(i18n("Information")); - - infoDock->setObjectName("infoDock"); - infoDock->setWidget(new InfoSidebarPage(this)); - - infoDock->toggleViewAction()->setObjectName("show_info_pane"); - infoDock->toggleViewAction()->setText(i18n("Show Information Panel")); - actionCollection()->insert(infoDock->toggleViewAction()); +void DolphinMainWindow::connectViewSignals(int viewIndex) +{ + DolphinView* view = m_view[viewIndex]; + connect(view, SIGNAL(modeChanged()), + this, SLOT(slotViewModeChanged())); + connect(view, SIGNAL(showHiddenFilesChanged()), + this, SLOT(slotShowHiddenFilesChanged())); + connect(view, SIGNAL(sortingChanged(DolphinView::Sorting)), + this, SLOT(slotSortingChanged(DolphinView::Sorting))); + connect(view, SIGNAL(sortOrderChanged(Qt::SortOrder)), + this, SLOT(slotSortOrderChanged(Qt::SortOrder))); + connect(view, SIGNAL(selectionChanged()), + this, SLOT(slotSelectionChanged())); + connect(view, SIGNAL(showFilterBarChanged(bool)), + this, SLOT(updateFilterBarAction(bool))); + + const UrlNavigator* navigator = view->urlNavigator(); + connect(navigator, SIGNAL(urlChanged(const KUrl&)), + this, SLOT(slotUrlChanged(const KUrl&))); + connect(navigator, SIGNAL(historyChanged()), + this, SLOT(slotHistoryChanged())); - addDockWidget(Qt::RightDockWidgetArea, infoDock); } #include "dolphinmainwindow.moc"