X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/b1d5b6b7467d15417131c8df8fdecb22b2008db4..328de208710faebaa275e2ef8ddb28a78ea5a2f0:/src/dolphinmainwindow.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 938d41cbc..61b7bb221 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" @@ -77,11 +77,12 @@ DolphinMainWindow::DolphinMainWindow() : - KMainWindow(0, "Dolphin"), + KMainWindow(0), m_splitter(0), m_activeView(0), m_clipboardContainsCutData(false) { + setObjectName("Dolphin"); m_view[PrimaryIdx] = 0; m_view[SecondaryIdx] = 0; @@ -217,6 +218,7 @@ void DolphinMainWindow::refreshViews() url, props.viewMode(), props.isShowHiddenFilesEnabled()); + connectViewSignals(i); m_view[i]->show(); } } @@ -228,24 +230,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(); @@ -258,16 +242,9 @@ void DolphinMainWindow::slotShowHiddenFilesChanged() showHiddenFilesAction->setChecked(m_activeView->isShowHiddenFilesEnabled()); } -void DolphinMainWindow::slotShowFilterBarChanged() -{ - KToggleAction* showFilterBarAction = - static_cast(actionCollection()->action("show_filter_bar")); - showFilterBarAction->setChecked(m_activeView->isFilterBarVisible()); -} - void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting) { - KAction* action = 0; + QAction* action = 0; switch (sorting) { case DolphinView::SortByName: action = actionCollection()->action("by_name"); @@ -305,7 +282,7 @@ void DolphinMainWindow::slotSelectionChanged() selectedUrlsCount += m_view[SecondaryIdx]->selectedUrls().count(); } - KAction* compareFilesAction = actionCollection()->action("compare_files"); + QAction* compareFilesAction = actionCollection()->action("compare_files"); compareFilesAction->setEnabled(selectedUrlsCount == 2); m_activeView->updateStatusBar(); @@ -313,17 +290,36 @@ 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(); } @@ -360,14 +356,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(); @@ -458,11 +454,11 @@ void DolphinMainWindow::createFile() KSortableList::ConstIterator it = m_createFileTemplates.begin(); KSortableList::ConstIterator end = m_createFileTemplates.end(); - const QString senderName(sender()->name()); + const QString senderName(sender()->objectName()); bool found = false; CreateFileEntry entry; while (!found && (it != end)) { - if ((*it).index() == senderName) { + if ((*it).key() == senderName) { entry = (*it).value(); found = true; } @@ -479,17 +475,17 @@ 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"); - QString name(i18n(entry.name.ascii())); + QString name(i18n(entry.name.toAscii())); // Most entry names end with "..." (e. g. "HTML File..."), which is ok for // menus but no good choice for a new file name -> remove the dots... 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"). @@ -589,20 +585,7 @@ void DolphinMainWindow::deleteItems() void DolphinMainWindow::properties() { - const KFileItemList* sourceList = m_activeView->selectedItems(); - if (sourceList == 0) { - return; - } - - KFileItemList list; - KFileItemList::const_iterator it = sourceList->begin(); - const KFileItemList::const_iterator end = sourceList->end(); - KFileItem* item = 0; - while (it != end) { - list.append(item); - ++it; - } - + const KFileItemList list = m_activeView->selectedItems(); new KPropertiesDialog(list, this); } @@ -635,7 +618,7 @@ void DolphinMainWindow::slotDeleteFileFinished(KJob* job) void DolphinMainWindow::slotUndoAvailable(bool available) { - KAction* undoAction = actionCollection()->action(KStdAction::stdName(KStdAction::Undo)); + QAction* undoAction = actionCollection()->action(KStdAction::stdName(KStdAction::Undo)); if (undoAction != 0) { undoAction->setEnabled(available); } @@ -643,7 +626,7 @@ void DolphinMainWindow::slotUndoAvailable(bool available) void DolphinMainWindow::slotUndoTextChanged(const QString& text) { - KAction* undoAction = actionCollection()->action(KStdAction::stdName(KStdAction::Undo)); + QAction* undoAction = actionCollection()->action(KStdAction::stdName(KStdAction::Undo)); if (undoAction != 0) { undoAction->setText(text); } @@ -651,7 +634,7 @@ void DolphinMainWindow::slotUndoTextChanged(const QString& text) void DolphinMainWindow::slotRedoAvailable(bool available) { - KAction* redoAction = actionCollection()->action(KStdAction::stdName(KStdAction::Redo)); + QAction* redoAction = actionCollection()->action(KStdAction::stdName(KStdAction::Redo)); if (redoAction != 0) { redoAction->setEnabled(available); } @@ -659,7 +642,7 @@ void DolphinMainWindow::slotRedoAvailable(bool available) void DolphinMainWindow::slotRedoTextChanged(const QString& text) { - KAction* redoAction = actionCollection()->action(KStdAction::stdName(KStdAction::Redo)); + QAction* redoAction = actionCollection()->action(KStdAction::stdName(KStdAction::Redo)); if (redoAction != 0) { redoAction->setText(text); } @@ -730,14 +713,14 @@ void DolphinMainWindow::paste() void DolphinMainWindow::updatePasteAction() { - KAction* pasteAction = actionCollection()->action(KStdAction::stdName(KStdAction::Paste)); + QAction* pasteAction = actionCollection()->action(KStdAction::stdName(KStdAction::Paste)); if (pasteAction == 0) { return; } QString text(i18n("Paste")); QClipboard* clipboard = QApplication::clipboard(); - QMimeSource* data = clipboard->data(); + const QMimeData* data = clipboard->mimeData(); /* KDE4-TODO: if (KUrlDrag::canDecode(data)) { pasteAction->setEnabled(true); @@ -831,12 +814,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()); + connectViewSignals(SecondaryIdx); + m_splitter->addWidget(m_view[SecondaryIdx]); + m_splitter->setSizes(QList() << newWidth << newWidth); m_view[SecondaryIdx]->show(); } else { @@ -853,7 +840,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]); @@ -1069,7 +1056,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; } @@ -1134,6 +1121,8 @@ void DolphinMainWindow::init() homeUrl, props.viewMode(), props.isShowHiddenFilesEnabled()); + connectViewSignals(PrimaryIdx); + m_view[PrimaryIdx]->show(); m_activeView = m_view[PrimaryIdx]; @@ -1179,7 +1168,7 @@ 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())); + connect(action, SIGNAL(triggered()), this, SLOT(openNewMainWindow())); KAction* createFolder = new KAction(i18n("Folder..."), actionCollection(), "create_folder"); createFolder->setIcon(KIcon("folder")); @@ -1209,7 +1198,7 @@ void DolphinMainWindow::setupActions() // setup 'Edit' menu UndoManager& undoManager = UndoManager::instance(); KStdAction::undo(this, - SLOT(slotUndo()), + SLOT(undo()), actionCollection()); connect(&undoManager, SIGNAL(undoAvailable(bool)), this, SLOT(slotUndoAvailable(bool))); @@ -1217,7 +1206,7 @@ void DolphinMainWindow::setupActions() this, SLOT(slotUndoTextChanged(const QString&))); KStdAction::redo(this, - SLOT(slotRedo()), + SLOT(redo()), actionCollection()); connect(&undoManager, SIGNAL(redoAvailable(bool)), this, SLOT(slotRedoAvailable(bool))); @@ -1341,6 +1330,31 @@ void DolphinMainWindow::setupActions() KStdAction::preferences(this, SLOT(editSettings()), actionCollection()); } +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()); + + addDockWidget(Qt::RightDockWidgetArea, infoDock); +} + void DolphinMainWindow::setupCreateNewMenuActions() { // Parts of the following code have been taken @@ -1448,12 +1462,12 @@ void DolphinMainWindow::updateHistory() int index = 0; const Q3ValueList list = m_activeView->urlHistory(index); - KAction* backAction = actionCollection()->action("go_back"); + QAction* backAction = actionCollection()->action("go_back"); if (backAction != 0) { backAction->setEnabled(index < static_cast(list.count()) - 1); } - KAction* forwardAction = actionCollection()->action("go_forward"); + QAction* forwardAction = actionCollection()->action("go_forward"); if (forwardAction != 0) { forwardAction->setEnabled(index > 0); } @@ -1461,22 +1475,22 @@ void DolphinMainWindow::updateHistory() void DolphinMainWindow::updateEditActions() { - const KFileItemList* list = m_activeView->selectedItems(); - if ((list == 0) || (*list).isEmpty()) { + const KFileItemList list = m_activeView->selectedItems(); + if (list.isEmpty()) { stateChanged("has_no_selection"); } else { stateChanged("has_selection"); - KAction* renameAction = actionCollection()->action("rename"); + QAction* renameAction = actionCollection()->action("rename"); if (renameAction != 0) { - renameAction->setEnabled(list->count() >= 1); + renameAction->setEnabled(list.count() >= 1); } bool enableMoveToTrash = true; - KFileItemList::const_iterator it = list->begin(); - const KFileItemList::const_iterator end = list->end(); + KFileItemList::const_iterator it = list.begin(); + const KFileItemList::const_iterator end = list.end(); while (it != end) { KFileItem* item = *it; const KUrl& url = item->url(); @@ -1487,7 +1501,7 @@ void DolphinMainWindow::updateEditActions() ++it; } - KAction* moveToTrashAction = actionCollection()->action("move_to_trash"); + QAction* moveToTrashAction = actionCollection()->action("move_to_trash"); moveToTrashAction->setEnabled(enableMoveToTrash); } updatePasteAction(); @@ -1495,17 +1509,17 @@ void DolphinMainWindow::updateEditActions() void DolphinMainWindow::updateViewActions() { - KAction* zoomInAction = actionCollection()->action(KStdAction::stdName(KStdAction::ZoomIn)); + QAction* zoomInAction = actionCollection()->action(KStdAction::stdName(KStdAction::ZoomIn)); if (zoomInAction != 0) { zoomInAction->setEnabled(m_activeView->isZoomInPossible()); } - KAction* zoomOutAction = actionCollection()->action(KStdAction::stdName(KStdAction::ZoomOut)); + QAction* zoomOutAction = actionCollection()->action(KStdAction::stdName(KStdAction::ZoomOut)); if (zoomOutAction != 0) { zoomOutAction->setEnabled(m_activeView->isZoomOutPossible()); } - KAction* action = 0; + QAction* action = 0; switch (m_activeView->mode()) { case DolphinView::IconsView: action = actionCollection()->action("icons"); @@ -1542,7 +1556,7 @@ void DolphinMainWindow::updateViewActions() void DolphinMainWindow::updateGoActions() { - KAction* goUpAction = actionCollection()->action(KStdAction::stdName(KStdAction::Up)); + QAction* goUpAction = actionCollection()->action(KStdAction::stdName(KStdAction::Up)); const KUrl& currentUrl = m_activeView->url(); goUpAction->setEnabled(currentUrl.upUrl() != currentUrl); } @@ -1602,19 +1616,28 @@ void DolphinMainWindow::clearStatusBar() m_activeView->statusBar()->clear(); } -void DolphinMainWindow::setupDockWidgets() -{ - QDockWidget *shortcutsDock = new QDockWidget(i18n("Shortcuts")); - shortcutsDock->setObjectName("shortcutsDock"); - shortcutsDock->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); - shortcutsDock->setWidget(new BookmarksSidebarPage(this)); - addDockWidget(Qt::LeftDockWidgetArea, shortcutsDock); +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())); - QDockWidget *infoDock = new QDockWidget(i18n("Information")); - infoDock->setObjectName("infoDock"); - infoDock->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); - infoDock->setWidget(new InfoSidebarPage(this)); - addDockWidget(Qt::RightDockWidgetArea, infoDock); } #include "dolphinmainwindow.moc"