]>
cloud.milkyroute.net Git - dolphin.git/blob - src/settings/viewpropertiesdialog.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #include "viewpropertiesdialog.h"
23 #include "additionalinfodialog.h"
24 #include "views/dolphinview.h"
25 #include "settings/dolphinsettings.h"
26 #include "dolphin_generalsettings.h"
27 #include "dolphin_iconsmodesettings.h"
28 #include "viewpropsprogressinfo.h"
30 #include <config-nepomuk.h>
32 #include <Nepomuk/ResourceManager>
35 #include <KComponentData>
37 #include <KIconLoader>
38 #include <KIO/NetAccess>
39 #include <KMessageBox>
40 #include <KStandardDirs>
45 #include <QButtonGroup>
47 #include <QGridLayout>
51 #include <QPushButton>
52 #include <QRadioButton>
55 #include <views/dolphinsortfilterproxymodel.h>
56 #include <views/viewproperties.h>
58 ViewPropertiesDialog::ViewPropertiesDialog(DolphinView
* dolphinView
) :
61 m_dolphinView(dolphinView
),
66 m_sortFoldersFirst(0),
71 m_applyToCurrentFolder(0),
72 m_applyToSubFolders(0),
73 m_applyToAllFolders(0),
76 Q_ASSERT(dolphinView
!= 0);
77 const bool useGlobalViewProps
= DolphinSettings::instance().generalSettings()->globalViewProps();
79 setCaption(i18nc("@title:window", "View Properties"));
80 setButtons(KDialog::Ok
| KDialog::Cancel
| KDialog::Apply
);
82 const KUrl
& url
= dolphinView
->url();
83 m_viewProps
= new ViewProperties(url
);
84 m_viewProps
->setAutoSaveEnabled(false);
86 QWidget
* main
= new QWidget();
87 QVBoxLayout
* topLayout
= new QVBoxLayout();
89 // create 'Properties' group containing view mode, sorting, sort order and show hidden files
90 QWidget
* propsBox
= main
;
91 if (!useGlobalViewProps
) {
92 propsBox
= new QGroupBox(i18nc("@title:group", "Properties"), main
);
95 QWidget
* propsGrid
= new QWidget();
97 QLabel
* viewModeLabel
= new QLabel(i18nc("@label:listbox", "View mode:"), propsGrid
);
98 m_viewMode
= new KComboBox(propsGrid
);
99 m_viewMode
->addItem(KIcon("view-list-icons"), i18nc("@item:inlistbox", "Icons"));
100 m_viewMode
->addItem(KIcon("view-list-details"), i18nc("@item:inlistbox", "Details"));
101 m_viewMode
->addItem(KIcon("view-file-columns"), i18nc("@item:inlistbox", "Column"));
103 QLabel
* sortingLabel
= new QLabel(i18nc("@label:listbox", "Sorting:"), propsGrid
);
104 QWidget
* sortingBox
= new QWidget(propsGrid
);
106 m_sortOrder
= new KComboBox(sortingBox
);
107 m_sortOrder
->addItem(i18nc("@item:inlistbox Sort", "Ascending"));
108 m_sortOrder
->addItem(i18nc("@item:inlistbox Sort", "Descending"));
110 m_sorting
= new KComboBox(sortingBox
);
111 m_sorting
->addItem(i18nc("@item:inlistbox Sort", "By Name"));
112 m_sorting
->addItem(i18nc("@item:inlistbox Sort", "By Size"));
113 m_sorting
->addItem(i18nc("@item:inlistbox Sort", "By Date"));
114 m_sorting
->addItem(i18nc("@item:inlistbox Sort", "By Permissions"));
115 m_sorting
->addItem(i18nc("@item:inlistbox Sort", "By Owner"));
116 m_sorting
->addItem(i18nc("@item:inlistbox Sort", "By Group"));
117 m_sorting
->addItem(i18nc("@item:inlistbox Sort", "By Type"));
119 // TODO: Hided "sort by rating" and "sort by tags" as without caching the performance
120 // is too slow currently (Nepomuk will support caching in future releases).
122 // if (!Nepomuk::ResourceManager::instance()->init()) {
123 // m_sorting->addItem(i18nc("@item:inlistbox Sort", "By Rating"));
124 // m_sorting->addItem(i18nc("@item:inlistbox Sort", "By Tags"));
127 m_sortFoldersFirst
= new QCheckBox(i18nc("@option:check", "Show folders first"));
128 m_showPreview
= new QCheckBox(i18nc("@option:check", "Show preview"));
129 m_showInGroups
= new QCheckBox(i18nc("@option:check", "Show in groups"));
130 m_showHiddenFiles
= new QCheckBox(i18nc("@option:check", "Show hidden files"));
132 m_additionalInfo
= new QPushButton(i18nc("@action:button", "Additional Information"));
134 QHBoxLayout
* sortingLayout
= new QHBoxLayout();
135 sortingLayout
->setMargin(0);
136 sortingLayout
->addWidget(m_sortOrder
);
137 sortingLayout
->addWidget(m_sorting
);
138 sortingBox
->setLayout(sortingLayout
);
140 QGridLayout
* propsGridLayout
= new QGridLayout(propsGrid
);
141 propsGridLayout
->addWidget(viewModeLabel
, 0, 0, Qt::AlignRight
);
142 propsGridLayout
->addWidget(m_viewMode
, 0, 1);
143 propsGridLayout
->addWidget(sortingLabel
, 1, 0, Qt::AlignRight
);
144 propsGridLayout
->addWidget(sortingBox
, 1, 1);
146 QVBoxLayout
* propsBoxLayout
= new QVBoxLayout(propsBox
);
147 propsBoxLayout
->addWidget(propsGrid
);
148 propsBoxLayout
->addWidget(m_sortFoldersFirst
);
149 propsBoxLayout
->addWidget(m_showPreview
);
150 propsBoxLayout
->addWidget(m_showInGroups
);
151 propsBoxLayout
->addWidget(m_showHiddenFiles
);
152 propsBoxLayout
->addWidget(m_additionalInfo
);
154 topLayout
->addWidget(propsBox
);
156 connect(m_viewMode
, SIGNAL(currentIndexChanged(int)),
157 this, SLOT(slotViewModeChanged(int)));
158 connect(m_sorting
, SIGNAL(currentIndexChanged(int)),
159 this, SLOT(slotSortingChanged(int)));
160 connect(m_sortOrder
, SIGNAL(currentIndexChanged(int)),
161 this, SLOT(slotSortOrderChanged(int)));
162 connect(m_additionalInfo
, SIGNAL(clicked()),
163 this, SLOT(configureAdditionalInfo()));
164 connect(m_sortFoldersFirst
, SIGNAL(clicked()),
165 this, SLOT(slotSortFoldersFirstChanged()));
166 connect(m_showPreview
, SIGNAL(clicked()),
167 this, SLOT(slotShowPreviewChanged()));
168 connect(m_showInGroups
, SIGNAL(clicked()),
169 this, SLOT(slotCategorizedSortingChanged()));
170 connect(m_showHiddenFiles
, SIGNAL(clicked()),
171 this, SLOT(slotShowHiddenFilesChanged()));
173 connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
174 connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply()));
176 // Only show the following settings if the view properties are remembered
177 // for each directory:
178 if (!useGlobalViewProps
) {
179 // create 'Apply View Properties To' group
180 QGroupBox
* applyBox
= new QGroupBox(i18nc("@title:group", "Apply View Properties To"), main
);
182 m_applyToCurrentFolder
= new QRadioButton(i18nc("@option:radio Apply View Properties To",
183 "Current folder"), applyBox
);
184 m_applyToCurrentFolder
->setChecked(true);
185 m_applyToSubFolders
= new QRadioButton(i18nc("@option:radio Apply View Properties To",
186 "Current folder including all sub-folders"), applyBox
);
187 m_applyToAllFolders
= new QRadioButton(i18nc("@option:radio Apply View Properties To",
188 "All folders"), applyBox
);
190 QButtonGroup
* applyGroup
= new QButtonGroup(this);
191 applyGroup
->addButton(m_applyToCurrentFolder
);
192 applyGroup
->addButton(m_applyToSubFolders
);
193 applyGroup
->addButton(m_applyToAllFolders
);
195 QVBoxLayout
* applyBoxLayout
= new QVBoxLayout(applyBox
);
196 applyBoxLayout
->addWidget(m_applyToCurrentFolder
);
197 applyBoxLayout
->addWidget(m_applyToSubFolders
);
198 applyBoxLayout
->addWidget(m_applyToAllFolders
);
200 m_useAsDefault
= new QCheckBox(i18nc("@option:check", "Use these view properties as default"), main
);
202 topLayout
->addWidget(applyBox
);
203 topLayout
->addWidget(m_useAsDefault
);
205 connect(m_applyToCurrentFolder
, SIGNAL(clicked(bool)),
206 this, SLOT(markAsDirty(bool)));
207 connect(m_applyToSubFolders
, SIGNAL(clicked(bool)),
208 this, SLOT(markAsDirty(bool)));
209 connect(m_applyToAllFolders
, SIGNAL(clicked(bool)),
210 this, SLOT(markAsDirty(bool)));
211 connect(m_useAsDefault
, SIGNAL(clicked(bool)),
212 this, SLOT(markAsDirty(bool)));
215 main
->setLayout(topLayout
);
218 const KConfigGroup
dialogConfig(KSharedConfig::openConfig("dolphinrc"),
219 "ViewPropertiesDialog");
220 restoreDialogSize(dialogConfig
);
225 ViewPropertiesDialog::~ViewPropertiesDialog()
231 KConfigGroup
dialogConfig(KSharedConfig::openConfig("dolphinrc"),
232 "ViewPropertiesDialog");
233 saveDialogSize(dialogConfig
, KConfigBase::Persistent
);
236 void ViewPropertiesDialog::slotOk()
238 applyViewProperties();
242 void ViewPropertiesDialog::slotApply()
244 applyViewProperties();
248 void ViewPropertiesDialog::slotViewModeChanged(int index
)
250 m_viewProps
->setViewMode(static_cast<DolphinView::Mode
>(index
));
253 const DolphinView::Mode mode
= m_viewProps
->viewMode();
254 m_showInGroups
->setEnabled(mode
== DolphinView::IconsView
);
255 m_additionalInfo
->setEnabled(mode
!= DolphinView::ColumnView
);
258 void ViewPropertiesDialog::slotSortingChanged(int index
)
260 const DolphinView::Sorting sorting
= DolphinSortFilterProxyModel::sortingForColumn(index
);
261 m_viewProps
->setSorting(sorting
);
265 void ViewPropertiesDialog::slotSortOrderChanged(int index
)
267 const Qt::SortOrder sortOrder
= (index
== 0) ? Qt::AscendingOrder
: Qt::DescendingOrder
;
268 m_viewProps
->setSortOrder(sortOrder
);
272 void ViewPropertiesDialog::slotCategorizedSortingChanged()
274 m_viewProps
->setCategorizedSorting(m_showInGroups
->isChecked());
278 void ViewPropertiesDialog::slotSortFoldersFirstChanged()
280 const bool foldersFirst
= m_sortFoldersFirst
->isChecked();
281 m_viewProps
->setSortFoldersFirst(foldersFirst
);
285 void ViewPropertiesDialog::slotShowPreviewChanged()
287 const bool show
= m_showPreview
->isChecked();
288 m_viewProps
->setShowPreview(show
);
292 void ViewPropertiesDialog::slotShowHiddenFilesChanged()
294 const bool show
= m_showHiddenFiles
->isChecked();
295 m_viewProps
->setShowHiddenFiles(show
);
299 void ViewPropertiesDialog::markAsDirty(bool isDirty
)
302 enableButtonApply(isDirty
);
305 void ViewPropertiesDialog::configureAdditionalInfo()
307 KFileItemDelegate::InformationList info
= m_viewProps
->additionalInfo();
308 const bool useDefaultInfo
= (m_viewProps
->viewMode() == DolphinView::DetailsView
) &&
309 (info
.isEmpty() || info
.contains(KFileItemDelegate::NoInformation
));
310 if (useDefaultInfo
) {
311 // Using the details view without any additional information (-> additional column)
312 // makes no sense and leads to a usability problem as no viewport area is available
313 // anymore. Hence as fallback provide at least a size and date column.
315 info
.append(KFileItemDelegate::Size
);
316 info
.append(KFileItemDelegate::ModificationTime
);
317 m_viewProps
->setAdditionalInfo(info
);
320 QPointer
<AdditionalInfoDialog
> dialog
= new AdditionalInfoDialog(this, info
);
321 if (dialog
->exec() == QDialog::Accepted
) {
322 m_viewProps
->setAdditionalInfo(dialog
->informationList());
328 void ViewPropertiesDialog::applyViewProperties()
330 // if nothing changed in the dialog, we have nothing to apply
335 const bool applyToSubFolders
= (m_applyToSubFolders
!= 0) &&
336 m_applyToSubFolders
->isChecked();
337 if (applyToSubFolders
) {
338 const QString
text(i18nc("@info", "The view properties of all sub-folders will be changed. Do you want to continue?"));
339 if (KMessageBox::questionYesNo(this, text
) == KMessageBox::No
) {
343 ViewPropsProgressInfo
* info
= new ViewPropsProgressInfo(m_dolphinView
,
344 m_dolphinView
->url(),
346 info
->setAttribute(Qt::WA_DeleteOnClose
);
347 info
->setWindowModality(Qt::NonModal
);
351 const bool applyToAllFolders
= (m_applyToAllFolders
!= 0) &&
352 m_applyToAllFolders
->isChecked();
354 // If the user selected 'Apply To All Folders' the view properties implicitely
355 // are also used as default for new folders.
356 const bool useAsDefault
= applyToAllFolders
||
357 ((m_useAsDefault
!= 0) && m_useAsDefault
->isChecked());
359 // For directories where no .directory file is available, the .directory
360 // file stored for the global view properties is used as fallback. To update
361 // this file we temporary turn on the global view properties mode.
362 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
363 Q_ASSERT(!settings
->globalViewProps());
365 settings
->setGlobalViewProps(true);
366 ViewProperties
defaultProps(m_dolphinView
->url());
367 defaultProps
.setDirProperties(*m_viewProps
);
369 settings
->setGlobalViewProps(false);
372 if (applyToAllFolders
) {
373 const QString
text(i18nc("@info", "The view properties of all folders will be changed. Do you want to continue?"));
374 if (KMessageBox::questionYesNo(this, text
) == KMessageBox::No
) {
378 // Updating the global view properties time stamp in the general settings makes
379 // all existing viewproperties invalid, as they have a smaller time stamp.
380 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
381 settings
->setViewPropsTimestamp(QDateTime::currentDateTime());
384 m_dolphinView
->setMode(m_viewProps
->viewMode());
385 m_dolphinView
->setSorting(m_viewProps
->sorting());
386 m_dolphinView
->setSortOrder(m_viewProps
->sortOrder());
387 m_dolphinView
->setSortFoldersFirst(m_viewProps
->sortFoldersFirst());
388 m_dolphinView
->setCategorizedSorting(m_viewProps
->categorizedSorting());
389 m_dolphinView
->setAdditionalInfo(m_viewProps
->additionalInfo());
390 m_dolphinView
->setShowPreview(m_viewProps
->showPreview());
391 m_dolphinView
->setShowHiddenFiles(m_viewProps
->showHiddenFiles());
398 void ViewPropertiesDialog::loadSettings()
401 const int index
= static_cast<int>(m_viewProps
->viewMode());
402 m_viewMode
->setCurrentIndex(index
);
404 // load sort order and sorting
405 const int sortOrderIndex
= (m_viewProps
->sortOrder() == Qt::AscendingOrder
) ? 0 : 1;
406 m_sortOrder
->setCurrentIndex(sortOrderIndex
);
407 m_sorting
->setCurrentIndex(m_viewProps
->sorting());
409 const bool enabled
= (index
== DolphinView::DetailsView
) ||
410 (index
== DolphinView::IconsView
);
411 m_additionalInfo
->setEnabled(enabled
);
413 m_sortFoldersFirst
->setChecked(m_viewProps
->sortFoldersFirst());
414 // load show preview, show in groups and show hidden files settings
415 m_showPreview
->setChecked(m_viewProps
->showPreview());
417 m_showInGroups
->setChecked(m_viewProps
->categorizedSorting());
418 m_showInGroups
->setEnabled(index
== DolphinView::IconsView
); // only the icons view supports categorized sorting
420 m_showHiddenFiles
->setChecked(m_viewProps
->showHiddenFiles());
424 #include "viewpropertiesdialog.moc"