From: Peter Penz Date: Wed, 20 Dec 2006 20:50:32 +0000 (+0000) Subject: - Performance optimization in DolphinView::loadDirectory() (don't store the view... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/b0b162135dce2c6f5a7687a2928afb24a5b613ec - Performance optimization in DolphinView::loadDirectory() (don't store the view properties for each property individually) - Get rid of methods which are not used anymore due to moving to KDirModel. - Respect GeneralSettings::globalViewProps() setting when storing view properties. svn path=/trunk/playground/utils/dolphin/; revision=615255 --- diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index c1b99d9a8..f3e2e293c 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -837,6 +837,12 @@ void DolphinMainWindow::stopLoading() 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() diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 35737e41b..d66cfd924 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -188,6 +188,22 @@ DolphinView::Mode DolphinView::mode() const return m_mode; } +void DolphinView::setShowPreview(bool show) +{ + ViewProperties props(m_urlNavigator->url()); + props.setShowPreview(show); + + // TODO: wait until previews are possible with KFileItemDelegate + + emit showPreviewChanged(); +} + +bool DolphinView::showPreview() const +{ + // TODO: wait until previews are possible with KFileItemDelegate + return true; +} + void DolphinView::setShowHiddenFiles(bool show) { if (m_dirLister->showingDotFiles() == show) { @@ -210,14 +226,6 @@ bool DolphinView::showHiddenFiles() const return m_dirLister->showingDotFiles(); } -void DolphinView::setViewProperties(const ViewProperties& props) -{ - setMode(props.viewMode()); - setSorting(props.sorting()); - setSortOrder(props.sortOrder()); - setShowHiddenFiles(props.showHiddenFiles()); -} - void DolphinView::renameSelectedItems() { const KUrl::List urls = selectedUrls(); @@ -618,34 +626,38 @@ DolphinMainWindow* DolphinView::mainWindow() const void DolphinView::loadDirectory(const KUrl& url) { const ViewProperties props(url); - setMode(props.viewMode()); + + const Mode mode = props.viewMode(); + if (m_mode != mode) { + m_mode = mode; + applyModeToView(); + emit modeChanged(); + } const bool showHiddenFiles = props.showHiddenFiles(); - setShowHiddenFiles(showHiddenFiles); - m_dirLister->setShowingDotFiles(showHiddenFiles); + if (showHiddenFiles != m_dirLister->showingDotFiles()) { + m_dirLister->setShowingDotFiles(showHiddenFiles); + emit showHiddenFilesChanged(); + } - setSorting(props.sorting()); - setSortOrder(props.sortOrder()); + const DolphinView::Sorting sorting = props.sorting(); + if (sorting != m_proxyModel->sorting()) { + m_proxyModel->setSorting(sorting); + emit sortingChanged(sorting); + } + + const Qt::SortOrder sortOrder = props.sortOrder(); + if (sortOrder != m_proxyModel->sortOrder()) { + m_proxyModel->setSortOrder(sortOrder); + emit sortOrderChanged(sortOrder); + } + + // TODO: handle previews (props.showPreview()) startDirLister(url); emit urlChanged(url); } -void DolphinView::triggerIconsViewItem(Q3IconViewItem* item) -{ - /* KDE4-TODO: - const Qt::ButtonState keyboardState = KApplication::keyboardMouseState(); - const bool isSelectionActive = ((keyboardState & Qt::ShiftModifier) > 0) || - ((keyboardState & Qt::ControlModifier) > 0);*/ - const bool isSelectionActive = false; - if ((item != 0) && !isSelectionActive) { - // Updating the Url must be done outside the scope of this slot, - // as iconview items will get deleted. - QTimer::singleShot(0, this, SLOT(updateUrl())); - mainWindow()->setActiveView(this); - } -} - void DolphinView::triggerItem(const QModelIndex& index) { KFileItem* item = m_dirModel->itemForIndex(index); @@ -676,35 +688,6 @@ void DolphinView::triggerItem(const QModelIndex& index) } } -void DolphinView::updateUrl() -{ - //KFileView* fileView = (m_iconsView != 0) ? static_cast(m_iconsView) : - // static_cast(m_iconsView); - - KFileItem* fileItem = 0; // TODO: fileView->currentFileItem(); - if (fileItem == 0) { - return; - } - - if (fileItem->isDir()) { - // Prefer the local path over the Url. This assures that the - // volume space information is correct. Assuming that the Url is media:/sda1, - // and the local path is /windows/C: For the Url the space info is related - // to the root partition (and hence wrong) and for the local path the space - // info is related to the windows partition (-> correct). - const QString localPath(fileItem->localPath()); - if (localPath.isEmpty()) { - setUrl(fileItem->url()); - } - else { - setUrl(KUrl(localPath)); - } - } - else { - fileItem->run(); - } -} - void DolphinView::slotPercent(int percent) { if (m_showProgress) { diff --git a/src/dolphinview.h b/src/dolphinview.h index 297dd3bd8..cd3df38b3 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -129,13 +129,35 @@ public: void requestActivation(); bool isActive() const; + /** + * Changes the view mode for the current directory to \a mode. + * If the view properties should be remembered for each directory + * (GeneralSettings::globalViewProps() returns false), then the + * changed view mode will be be stored automatically. + */ void setMode(Mode mode); Mode mode() const; + + /** + * Turns on the file preview for the all files of the current directory, + * if \a show is true. + * If the view properties should be remembered for each directory + * (GeneralSettings::globalViewProps() returns false), then the + * preview setting will be be stored automatically. + */ + void setShowPreview(bool show); + bool showPreview() const; + + /** + * Shows all hidden files of the current directory, + * if \a show is true. + * If the view properties should be remembered for each directory + * (GeneralSettings::globalViewProps() returns false), then the + * show hidden file setting will be be stored automatically. + */ void setShowHiddenFiles(bool show); bool showHiddenFiles() const; - void setViewProperties(const ViewProperties& props); - /** * Triggers the renaming of the currently selected items, where * the user must input a new name for the items. @@ -347,6 +369,9 @@ signals: */ void modeChanged(); + /** Is emitted if the 'show preview' property has been changed. */ + void showPreviewChanged(); + /** Is emitted if the 'show hidden files' property has been changed. */ void showHiddenFilesChanged(); @@ -383,9 +408,7 @@ protected: private slots: void loadDirectory(const KUrl& kurl); - void triggerIconsViewItem(Q3IconViewItem *item); void triggerItem(const QModelIndex& index); - void updateUrl(); void slotPercent(int percent); void slotClear(); diff --git a/src/viewproperties.cpp b/src/viewproperties.cpp index 60e91cabf..cd66519fd 100644 --- a/src/viewproperties.cpp +++ b/src/viewproperties.cpp @@ -20,9 +20,8 @@ #include -#include -#include -#include +#include +#include #include #include @@ -30,8 +29,8 @@ #include #include "viewproperties.h" - #include "dolphinsettings.h" +#include "generalsettings.h" #define FILE_NAME "/.directory" @@ -168,9 +167,12 @@ void ViewProperties::updateTimeStamp() void ViewProperties::save() { - KStandardDirs::makeDir(m_filepath); - m_node->writeConfig(); - m_changedProps = false; + const bool rememberSettings = !DolphinSettings::instance().generalSettings()->globalViewProps(); + if (rememberSettings) { + KStandardDirs::makeDir(m_filepath); + m_node->writeConfig(); + m_changedProps = false; + } } ViewProperties::ViewProperties(const ViewProperties& props) diff --git a/src/viewproperties.h b/src/viewproperties.h index a98800407..992429241 100644 --- a/src/viewproperties.h +++ b/src/viewproperties.h @@ -66,10 +66,27 @@ public: void setSortOrder(Qt::SortOrder sortOrder); Qt::SortOrder sortOrder() const; + /** + * If \a autoSave is true, the properties are automatically + * saved when the destructor is called. Per default autosaving + * is enabled. + */ void setAutoSaveEnabled(bool autoSave); bool isAutoSaveEnabled() const; void updateTimeStamp(); + + /** + * Saves the view properties for the directory specified + * in the constructor. The method is automatically + * invoked in the destructor, if + * ViewProperties::isAutoSaveEnabled() returns true. + * + * Note that the saving of the properties will be ignored + * if GeneralSettings::globalViewProps() returns true: in + * this case view properties may not be remembered for + * each directory. + */ void save(); private: diff --git a/src/viewpropertiesdialog.cpp b/src/viewpropertiesdialog.cpp index 3f440633f..a187ef89a 100644 --- a/src/viewpropertiesdialog.cpp +++ b/src/viewpropertiesdialog.cpp @@ -20,6 +20,10 @@ #include "viewpropertiesdialog.h" #include "viewpropsprogressinfo.h" +#include "dolphinview.h" +#include "dolphinsettings.h" +#include "generalsettings.h" +#include "viewproperties.h" #include #include @@ -34,9 +38,6 @@ #include #include -#include "viewproperties.h" -#include "dolphinview.h" - ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) : KDialog(dolphinView), m_isDirty(false), @@ -110,12 +111,7 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) : propsBoxLayout->addWidget(m_showPreview, 3, 0); propsBoxLayout->addWidget(m_showHiddenFiles, 4, 0); - m_applyToSubFolders = new QCheckBox(i18n("Apply changes to all sub folders"), main); - m_useAsDefault = new QCheckBox(i18n("Use as default"), main); - topLayout->addWidget(propsBox); - topLayout->addWidget(m_applyToSubFolders); - topLayout->addWidget(m_useAsDefault); connect(m_viewMode, SIGNAL(activated(int)), this, SLOT(slotViewModeChanged(int))); @@ -128,14 +124,23 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) : connect(m_showHiddenFiles, SIGNAL(clicked()), this, SLOT(slotShowHiddenFilesChanged())); - connect(m_applyToSubFolders, SIGNAL(clicked()), - this, SLOT(markAsDirty())); - connect(m_applyToSubFolders, SIGNAL(clicked()), - this, SLOT(markAsDirty())); - connect(this, SIGNAL(okClicked()), this, SLOT(slotOk())); connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply())); + // Only show the following settings if the view properties are remembered + // for each directory: + if (!DolphinSettings::instance().generalSettings()->globalViewProps()) { + m_applyToSubFolders = new QCheckBox(i18n("Apply changes to all sub folders"), main); + m_useAsDefault = new QCheckBox(i18n("Use as default"), main); + topLayout->addWidget(m_applyToSubFolders); + topLayout->addWidget(m_useAsDefault); + + connect(m_applyToSubFolders, SIGNAL(clicked()), + this, SLOT(markAsDirty())); + connect(m_useAsDefault, SIGNAL(clicked()), + this, SLOT(markAsDirty())); + } + main->setLayout(topLayout); setMainWidget(main); } @@ -205,7 +210,10 @@ void ViewPropertiesDialog::markAsDirty() void ViewPropertiesDialog::applyViewProperties() { - if (m_applyToSubFolders->isChecked() && m_isDirty) { + const bool applyToSubFolders = m_isDirty && + (m_applyToSubFolders != 0) && + m_applyToSubFolders->isChecked(); + if (applyToSubFolders) { const QString text(i18n("The view properties of all sub folders will be changed. Do you want to continue?")); if (KMessageBox::questionYesNo(this, text) == KMessageBox::No) { return; @@ -219,7 +227,13 @@ void ViewPropertiesDialog::applyViewProperties() } m_viewProps->save(); - m_dolphinView->setViewProperties(*m_viewProps); + + m_dolphinView->setMode(m_viewProps->viewMode()); + m_dolphinView->setSorting(m_viewProps->sorting()); + m_dolphinView->setSortOrder(m_viewProps->sortOrder()); + m_dolphinView->setShowPreview(m_viewProps->showPreview()); + m_dolphinView->setShowHiddenFiles(m_viewProps->showHiddenFiles()); + m_isDirty = false; // TODO: handle m_useAsDefault setting