X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/dde6f0a0772eee324e2838ba4a076a83193f163c..abf17941f7:/src/viewpropertiesdialog.cpp diff --git a/src/viewpropertiesdialog.cpp b/src/viewpropertiesdialog.cpp index 594c487d2..350113a3c 100644 --- a/src/viewpropertiesdialog.cpp +++ b/src/viewpropertiesdialog.cpp @@ -15,16 +15,28 @@ * 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 "viewpropertiesdialog.h" +#include "viewpropsprogressinfo.h" +#include "dolphinview.h" +#include "dolphinsettings.h" +#include "dolphinsortfilterproxymodel.h" +#include "generalsettings.h" +#include "viewproperties.h" +#include + +#include #include #include +#include #include -#include +#include +#include +#include #include #include #include @@ -33,15 +45,22 @@ #include #include -#include "viewproperties.h" -#include "dolphinview.h" - ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) : KDialog(dolphinView), m_isDirty(false), - m_dolphinView(dolphinView) + m_dolphinView(dolphinView), + m_viewProps(0), + m_viewMode(0), + m_sorting(0), + 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); @@ -54,13 +73,15 @@ 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); m_viewMode->addItem(SmallIcon("view_icon"), i18n("Icons")); m_viewMode->addItem(SmallIcon("view_text"), i18n("Details")); - m_viewMode->addItem(SmallIcon("gvdirpart"), i18n("Previews")); const int index = static_cast(m_viewProps->viewMode()); m_viewMode->setCurrentIndex(index); @@ -69,14 +90,10 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) : m_sorting->addItem("By Name"); m_sorting->addItem("By Size"); m_sorting->addItem("By Date"); - int sortingIdx = 0; - switch (m_viewProps->sorting()) { - case DolphinView::SortByName: sortingIdx = 0; break; - case DolphinView::SortBySize: sortingIdx = 1; break; - case DolphinView::SortByDate: sortingIdx = 2; break; - default: break; - } - m_sorting->setCurrentIndex(sortingIdx); + m_sorting->addItem("By Permissions"); + m_sorting->addItem("By Owner"); + m_sorting->addItem("By Group"); + m_sorting->setCurrentIndex(m_viewProps->sorting()); QLabel* sortOrderLabel = new QLabel(i18n("Sort order:"), propsBox); m_sortOrder = new QComboBox(propsBox); @@ -85,8 +102,11 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) : const int sortOrderIdx = (m_viewProps->sortOrder() == Qt::Ascending) ? 0 : 1; m_sortOrder->setCurrentIndex(sortOrderIdx); + m_showPreview = new QCheckBox(i18n("Show preview"), propsBox); + m_showPreview->setChecked(m_viewProps->showPreview()); + m_showHiddenFiles = new QCheckBox(i18n("Show hidden files"), propsBox); - m_showHiddenFiles->setChecked(m_viewProps->isShowHiddenFilesEnabled()); + m_showHiddenFiles->setChecked(m_viewProps->showHiddenFiles()); QGridLayout* propsBoxLayout = new QGridLayout(propsBox); propsBoxLayout->addWidget(viewModeLabel, 0, 0); @@ -96,24 +116,10 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) : propsBoxLayout->addWidget(m_sorting, 1, 1); propsBoxLayout->addWidget(sortOrderLabel, 2, 0); propsBoxLayout->addWidget(m_sortOrder, 2, 1); - propsBoxLayout->addWidget(m_showHiddenFiles, 3, 0); - - // create 'Apply view properties to:' group - QGroupBox* buttonBox = new QGroupBox(i18n("Apply view properties to:"), main); - m_applyToCurrentFolder = new QRadioButton(i18n("Current folder"), buttonBox); - m_applyToSubFolders = new QRadioButton(i18n("Current folder including all sub folders"), buttonBox); - m_applyToAllFolders = new QRadioButton(i18n("All folders"), buttonBox); - - QVBoxLayout* buttonBoxLayout = new QVBoxLayout(); - buttonBoxLayout->addWidget(m_applyToCurrentFolder); - buttonBoxLayout->addWidget(m_applyToSubFolders); - buttonBoxLayout->addWidget(m_applyToAllFolders); - buttonBox->setLayout(buttonBoxLayout); - - m_applyToCurrentFolder->setChecked(true); + propsBoxLayout->addWidget(m_showPreview, 3, 0); + propsBoxLayout->addWidget(m_showHiddenFiles, 4, 0); topLayout->addWidget(propsBox); - topLayout->addWidget(buttonBox); connect(m_viewMode, SIGNAL(activated(int)), this, SLOT(slotViewModeChanged(int))); @@ -121,18 +127,50 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) : this, SLOT(slotSortingChanged(int))); connect(m_sortOrder, SIGNAL(activated(int)), this, SLOT(slotSortOrderChanged(int))); + connect(m_showPreview, SIGNAL(clicked()), + this, SLOT(slotShowPreviewChanged())); connect(m_showHiddenFiles, SIGNAL(clicked()), this, SLOT(slotShowHiddenFilesChanged())); - connect(m_applyToCurrentFolder, SIGNAL(clicked()), - this, SLOT(slotApplyToCurrentFolder())); - connect(m_applyToSubFolders, SIGNAL(clicked()), - this, SLOT(slotApplyToSubFolders())); - connect(m_applyToAllFolders, SIGNAL(clicked()), - this, SLOT(slotApplyToAllFolders())); 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 (!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())); + } + main->setLayout(topLayout); setMainWidget(main); } @@ -164,12 +202,7 @@ void ViewPropertiesDialog::slotViewModeChanged(int index) void ViewPropertiesDialog::slotSortingChanged(int index) { - DolphinView::Sorting sorting = DolphinView::SortByName; - switch (index) { - case 1: sorting = DolphinView::SortBySize; break; - case 2: sorting = DolphinView::SortByDate; break; - default: break; - } + const DolphinView::Sorting sorting = DolphinSortFilterProxyModel::sortingForColumn(index); m_viewProps->setSorting(sorting); m_isDirty = true; } @@ -181,56 +214,88 @@ void ViewPropertiesDialog::slotSortOrderChanged(int index) m_isDirty = true; } -void ViewPropertiesDialog::slotShowHiddenFilesChanged() +void ViewPropertiesDialog::slotShowPreviewChanged() { - const bool show = m_showHiddenFiles->isChecked(); - m_viewProps->setShowHiddenFilesEnabled(show); + const bool show = m_showPreview->isChecked(); + m_viewProps->setShowPreview(show); m_isDirty = true; } -void ViewPropertiesDialog::slotApplyToCurrentFolder() -{ - m_isDirty = true; -} - -void ViewPropertiesDialog::slotApplyToSubFolders() +void ViewPropertiesDialog::slotShowHiddenFilesChanged() { - //m_viewProps->setValidForSubDirs(true); + const bool show = m_showHiddenFiles->isChecked(); + m_viewProps->setShowHiddenFiles(show); m_isDirty = true; } -void ViewPropertiesDialog::slotApplyToAllFolders() +void ViewPropertiesDialog::markAsDirty() { m_isDirty = true; } void ViewPropertiesDialog::applyViewProperties() { - if (m_applyToAllFolders->isChecked()) { - if (m_isDirty) { - const QString text(i18n("The view properties of all folders will be replaced. Do you want to continue?")); - if (KMessageBox::questionYesNo(this, text) == KMessageBox::No) { - return; - } + 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; } - ViewProperties props(QDir::homePath()); - props.setViewMode(m_viewProps->viewMode()); - props.setSorting(m_viewProps->sorting()); - props.setSortOrder(m_viewProps->sortOrder()); - props.setShowHiddenFilesEnabled(m_viewProps->isShowHiddenFilesEnabled()); - //props.setValidForSubDirs(true); + ViewPropsProgressInfo* info = new ViewPropsProgressInfo(m_dolphinView, + m_dolphinView->url(), + *m_viewProps); + info->setWindowModality(Qt::NonModal); + info->show(); } - else if (m_applyToSubFolders->isChecked() && m_isDirty) { - const QString text(i18n("The view properties of all sub folders will be replaced. Do you want to continue?")); + + 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->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; + + 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"