X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/abf8f1917d1ef044cf732eb873ce28bf805f27af..abf17941f7:/src/viewpropertiesdialog.cpp diff --git a/src/viewpropertiesdialog.cpp b/src/viewpropertiesdialog.cpp index 48e565a09..350113a3c 100644 --- a/src/viewpropertiesdialog.cpp +++ b/src/viewpropertiesdialog.cpp @@ -26,11 +26,17 @@ #include "generalsettings.h" #include "viewproperties.h" +#include + +#include #include #include +#include #include -#include +#include +#include +#include #include #include #include @@ -49,10 +55,12 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) : m_sortOrder(0), m_showPreview(0), m_showHiddenFiles(0), + m_applyToCurrentFolder(0), m_applyToSubFolders(0), m_useAsDefault(0) { assert(dolphinView != 0); + const bool useGlobalViewProps = DolphinSettings::instance().generalSettings()->globalViewProps(); setCaption(i18n("View Properties")); setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Apply); @@ -65,7 +73,10 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) : QVBoxLayout* topLayout = new QVBoxLayout(); // create 'Properties' group containing view mode, sorting, sort order and show hidden files - QGroupBox* propsBox = new QGroupBox(i18n("Properties"), main); + QWidget* propsBox = main; + if (!useGlobalViewProps) { + propsBox = new QGroupBox(i18n("Properties"), main); + } QLabel* viewModeLabel = new QLabel(i18n("View mode:"), propsBox); m_viewMode = new QComboBox(propsBox); @@ -126,14 +137,36 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) : // 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); + if (!useGlobalViewProps) { + // create 'Apply view properties to:' group + QGroupBox* applyBox = new QGroupBox(i18n("Apply view properties to:"), main); + + m_applyToCurrentFolder = new QRadioButton(i18n("Current folder"), applyBox); + m_applyToCurrentFolder->setChecked(true); + m_applyToSubFolders = new QRadioButton(i18n("Current folder including all sub folders"), applyBox); + m_applyToAllFolders = new QRadioButton(i18n("All folders"),applyBox); + + QButtonGroup* applyGroup = new QButtonGroup(this); + applyGroup->addButton(m_applyToCurrentFolder); + applyGroup->addButton(m_applyToSubFolders); + applyGroup->addButton(m_applyToAllFolders); + + QVBoxLayout* applyBoxLayout = new QVBoxLayout(applyBox); + applyBoxLayout->addWidget(m_applyToCurrentFolder); + applyBoxLayout->addWidget(m_applyToSubFolders); + applyBoxLayout->addWidget(m_applyToAllFolders); + + m_useAsDefault = new QCheckBox(i18n("Use as default for new folders"), main); + + topLayout->addWidget(applyBox); topLayout->addWidget(m_useAsDefault); + connect(m_applyToCurrentFolder, SIGNAL(clicked()), + this, SLOT(markAsDirty())); connect(m_applyToSubFolders, SIGNAL(clicked()), this, SLOT(markAsDirty())); + connect(m_applyToAllFolders, SIGNAL(clicked()), + this, SLOT(markAsDirty())); connect(m_useAsDefault, SIGNAL(clicked()), this, SLOT(markAsDirty())); } @@ -218,6 +251,27 @@ void ViewPropertiesDialog::applyViewProperties() info->show(); } + const bool applyToAllFolders = m_isDirty && + (m_applyToAllFolders != 0) && + m_applyToAllFolders->isChecked(); + if (applyToAllFolders) { + const QString text(i18n("The view properties of all folders will be changed. Do you want to continue?")); + if (KMessageBox::questionYesNo(this, text) == KMessageBox::No) { + return; + } + + // Updating the global view properties time stamp in the general settings makes + // all existing viewproperties invalid, as they have a smaller time stamp. + GeneralSettings* settings = DolphinSettings::instance().generalSettings(); + settings->setViewPropsTimestamp(QDateTime::currentDateTime()); + + // This is also a good chance to make a cleanup of all mirrored view properties: + QString basePath = KGlobal::mainComponent().componentName(); + basePath.append("/view_properties/"); + const QString mirroredViewProps = KStandardDirs::locateLocal("data", basePath); + KIO::NetAccess::del(mirroredViewProps, this); + } + m_viewProps->save(); m_dolphinView->setMode(m_viewProps->viewMode()); @@ -228,7 +282,20 @@ void ViewPropertiesDialog::applyViewProperties() m_isDirty = false; - // TODO: handle m_useAsDefault setting + if (m_useAsDefault->isChecked()) { + // For directories where no .directory file is available, the .directory + // file stored for the global view properties is used as fallback. To update + // this file we temporary turn on the global view properties mode. + GeneralSettings* settings = DolphinSettings::instance().generalSettings(); + assert(!settings->globalViewProps()); + + settings->setGlobalViewProps(true); + ViewProperties defaultProps(m_dolphinView->url()); + defaultProps.setDirProperties(*m_viewProps); + kDebug() << "saving global viewprops" << endl; + defaultProps.save(); + settings->setGlobalViewProps(false); + } } #include "viewpropertiesdialog.moc"