]>
cloud.milkyroute.net Git - dolphin.git/blob - src/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 "dolphinview.h"
25 #include "dolphinsettings.h"
26 #include "dolphinsortfilterproxymodel.h"
27 #include "dolphin_generalsettings.h"
28 #include "viewproperties.h"
29 #include "viewpropsprogressinfo.h"
31 #include <config-nepomuk.h>
33 #include <nepomuk/resourcemanager.h>
36 #include <kcomponentdata.h>
38 #include <kiconloader.h>
39 #include <kio/netaccess.h>
40 #include <kmessagebox.h>
41 #include <kstandarddirs.h>
45 #include <QButtonGroup>
48 #include <QGridLayout>
52 #include <QPushButton>
53 #include <QRadioButton>
56 ViewPropertiesDialog::ViewPropertiesDialog(DolphinView
* dolphinView
) :
59 m_dolphinView(dolphinView
),
68 m_applyToCurrentFolder(0),
69 m_applyToSubFolders(0),
72 Q_ASSERT(dolphinView
!= 0);
73 const bool useGlobalViewProps
= DolphinSettings::instance().generalSettings()->globalViewProps();
75 setCaption(i18nc("@title:window", "View Properties"));
76 setButtons(KDialog::Ok
| KDialog::Cancel
| KDialog::Apply
);
78 const KUrl
& url
= dolphinView
->url();
79 m_viewProps
= new ViewProperties(url
);
80 m_viewProps
->setAutoSaveEnabled(false);
82 QWidget
* main
= new QWidget();
83 QVBoxLayout
* topLayout
= new QVBoxLayout();
85 // create 'Properties' group containing view mode, sorting, sort order and show hidden files
86 QWidget
* propsBox
= main
;
87 if (!useGlobalViewProps
) {
88 propsBox
= new QGroupBox(i18nc("@title:group", "Properties"), main
);
91 QLabel
* viewModeLabel
= new QLabel(i18nc("@label:listbox", "View mode:"), propsBox
);
92 m_viewMode
= new QComboBox(propsBox
);
93 m_viewMode
->addItem(KIcon("fileview-icon"), i18nc("@item:inlistbox", "Icons"));
94 m_viewMode
->addItem(KIcon("fileview-detailed"), i18nc("@item:inlistbox", "Details"));
95 m_viewMode
->addItem(KIcon("fileview-column"), i18nc("@item:inlistbox", "Column"));
97 QLabel
* sortingLabel
= new QLabel(i18nc("@label:listbox", "Sorting:"), propsBox
);
98 QWidget
* sortingBox
= new QWidget(propsBox
);
100 m_sortOrder
= new QComboBox(sortingBox
);
101 m_sortOrder
->addItem(i18nc("@item:inlistbox", "Ascending"));
102 m_sortOrder
->addItem(i18nc("@item:inlistbox", "Descending"));
104 m_sorting
= new QComboBox(sortingBox
);
105 m_sorting
->addItem(i18nc("@item:inlistbox Sort", "By Name"));
106 m_sorting
->addItem(i18nc("@item:inlistbox Sort", "By Size"));
107 m_sorting
->addItem(i18nc("@item:inlistbox Sort", "By Date"));
108 m_sorting
->addItem(i18nc("@item:inlistbox Sort", "By Permissions"));
109 m_sorting
->addItem(i18nc("@item:inlistbox Sort", "By Owner"));
110 m_sorting
->addItem(i18nc("@item:inlistbox Sort", "By Group"));
111 m_sorting
->addItem(i18nc("@item:inlistbox Sort", "By Type"));
113 if (!Nepomuk::ResourceManager::instance()->init()) {
114 m_sorting
->addItem(i18nc("@item:inlistbox Sort", "By Rating"));
115 m_sorting
->addItem(i18nc("@item:inlistbox Sort", "By Tags"));
119 QHBoxLayout
* sortingLayout
= new QHBoxLayout();
120 sortingLayout
->setMargin(0);
121 sortingLayout
->addWidget(m_sortOrder
);
122 sortingLayout
->addWidget(m_sorting
);
123 sortingBox
->setLayout(sortingLayout
);
125 m_showPreview
= new QCheckBox(i18nc("@option:check", "Show preview"), propsBox
);
126 m_showInGroups
= new QCheckBox(i18nc("@option:check", "Show in Groups"), propsBox
);
127 m_showHiddenFiles
= new QCheckBox(i18nc("@option:check", "Show hidden files"), propsBox
);
129 m_additionalInfo
= new QPushButton(i18nc("@action:button", "Additional Information"), propsBox
);
130 connect(m_additionalInfo
, SIGNAL(clicked()),
131 this, SLOT(configureAdditionalInfo()));
133 QGridLayout
* propsBoxLayout
= new QGridLayout(propsBox
);
134 propsBoxLayout
->addWidget(viewModeLabel
, 0, 0);
135 propsBoxLayout
->addWidget(m_viewMode
, 0, 1);
136 propsBoxLayout
->addWidget(sortingLabel
, 1, 0);
137 propsBoxLayout
->addWidget(sortingBox
, 1, 1);
138 propsBoxLayout
->addWidget(m_showPreview
, 2, 0);
139 propsBoxLayout
->addWidget(m_showInGroups
, 3, 0);
140 propsBoxLayout
->addWidget(m_showHiddenFiles
, 4, 0);
141 propsBoxLayout
->addWidget(m_additionalInfo
, 5, 0);
143 topLayout
->addWidget(propsBox
);
145 connect(m_viewMode
, SIGNAL(activated(int)),
146 this, SLOT(slotViewModeChanged(int)));
147 connect(m_sorting
, SIGNAL(activated(int)),
148 this, SLOT(slotSortingChanged(int)));
149 connect(m_sortOrder
, SIGNAL(activated(int)),
150 this, SLOT(slotSortOrderChanged(int)));
151 connect(m_additionalInfo
, SIGNAL(activated(int)),
152 this, SLOT(slotAdditionalInfoChanged(int)));
153 connect(m_showPreview
, SIGNAL(clicked()),
154 this, SLOT(slotShowPreviewChanged()));
155 connect(m_showInGroups
, SIGNAL(clicked()),
156 this, SLOT(slotCategorizedSortingChanged()));
157 connect(m_showHiddenFiles
, SIGNAL(clicked()),
158 this, SLOT(slotShowHiddenFilesChanged()));
160 connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
161 connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply()));
163 // Only show the following settings if the view properties are remembered
164 // for each directory:
165 if (!useGlobalViewProps
) {
166 // create 'Apply View Properties To' group
167 QGroupBox
* applyBox
= new QGroupBox(i18nc("@title:group", "Apply View Properties To"), main
);
169 m_applyToCurrentFolder
= new QRadioButton(i18nc("@option:radio Apply View Properties To",
170 "Current folder"), applyBox
);
171 m_applyToCurrentFolder
->setChecked(true);
172 m_applyToSubFolders
= new QRadioButton(i18nc("@option:radio Apply View Properties To",
173 "Current folder including all sub folders"), applyBox
);
174 m_applyToAllFolders
= new QRadioButton(i18nc("@option:radio Apply View Properties To",
175 "All folders"), applyBox
);
177 QButtonGroup
* applyGroup
= new QButtonGroup(this);
178 applyGroup
->addButton(m_applyToCurrentFolder
);
179 applyGroup
->addButton(m_applyToSubFolders
);
180 applyGroup
->addButton(m_applyToAllFolders
);
182 QVBoxLayout
* applyBoxLayout
= new QVBoxLayout(applyBox
);
183 applyBoxLayout
->addWidget(m_applyToCurrentFolder
);
184 applyBoxLayout
->addWidget(m_applyToSubFolders
);
185 applyBoxLayout
->addWidget(m_applyToAllFolders
);
187 m_useAsDefault
= new QCheckBox(i18nc("@option:check", "Use as default for new folders"), main
);
189 topLayout
->addWidget(applyBox
);
190 topLayout
->addWidget(m_useAsDefault
);
192 connect(m_applyToCurrentFolder
, SIGNAL(clicked()),
193 this, SLOT(markAsDirty()));
194 connect(m_applyToSubFolders
, SIGNAL(clicked()),
195 this, SLOT(markAsDirty()));
196 connect(m_applyToAllFolders
, SIGNAL(clicked()),
197 this, SLOT(markAsDirty()));
198 connect(m_useAsDefault
, SIGNAL(clicked()),
199 this, SLOT(markAsDirty()));
202 main
->setLayout(topLayout
);
205 const KConfigGroup
dialogConfig(KSharedConfig::openConfig("dolphinrc"),
206 "ViewPropertiesDialog");
207 restoreDialogSize(dialogConfig
);
212 ViewPropertiesDialog::~ViewPropertiesDialog()
218 KConfigGroup
dialogConfig(KSharedConfig::openConfig("dolphinrc"),
219 "ViewPropertiesDialog");
220 saveDialogSize(dialogConfig
, KConfigBase::Persistent
);
223 void ViewPropertiesDialog::slotOk()
225 applyViewProperties();
229 void ViewPropertiesDialog::slotApply()
231 applyViewProperties();
234 void ViewPropertiesDialog::slotViewModeChanged(int index
)
236 m_viewProps
->setViewMode(static_cast<DolphinView::Mode
>(index
));
239 const DolphinView::Mode mode
= m_viewProps
->viewMode();
240 m_showInGroups
->setEnabled(mode
== DolphinView::IconsView
);
241 m_additionalInfo
->setEnabled(mode
!= DolphinView::ColumnView
);
244 void ViewPropertiesDialog::slotSortingChanged(int index
)
246 const DolphinView::Sorting sorting
= DolphinSortFilterProxyModel::sortingForColumn(index
);
247 m_viewProps
->setSorting(sorting
);
251 void ViewPropertiesDialog::slotSortOrderChanged(int index
)
253 const Qt::SortOrder sortOrder
= (index
== 0) ? Qt::AscendingOrder
: Qt::DescendingOrder
;
254 m_viewProps
->setSortOrder(sortOrder
);
258 void ViewPropertiesDialog::slotCategorizedSortingChanged()
260 m_viewProps
->setCategorizedSorting(m_showInGroups
->isChecked());
264 void ViewPropertiesDialog::slotShowPreviewChanged()
266 const bool show
= m_showPreview
->isChecked();
267 m_viewProps
->setShowPreview(show
);
271 void ViewPropertiesDialog::slotShowHiddenFilesChanged()
273 const bool show
= m_showHiddenFiles
->isChecked();
274 m_viewProps
->setShowHiddenFiles(show
);
278 void ViewPropertiesDialog::markAsDirty()
283 void ViewPropertiesDialog::configureAdditionalInfo()
285 const KFileItemDelegate::InformationList info
= m_viewProps
->additionalInfo();
286 AdditionalInfoDialog
dialog(this, info
);
287 if (dialog
.exec() == QDialog::Accepted
) {
288 m_viewProps
->setAdditionalInfo(dialog
.additionalInfo());
293 void ViewPropertiesDialog::applyViewProperties()
295 const bool applyToSubFolders
= m_isDirty
&&
296 (m_applyToSubFolders
!= 0) &&
297 m_applyToSubFolders
->isChecked();
298 if (applyToSubFolders
) {
299 const QString
text(i18nc("@info", "The view properties of all sub folders will be changed. Do you want to continue?"));
300 if (KMessageBox::questionYesNo(this, text
) == KMessageBox::No
) {
304 ViewPropsProgressInfo
* info
= new ViewPropsProgressInfo(m_dolphinView
,
305 m_dolphinView
->url(),
307 info
->setWindowModality(Qt::NonModal
);
311 const bool applyToAllFolders
= m_isDirty
&&
312 (m_applyToAllFolders
!= 0) &&
313 m_applyToAllFolders
->isChecked();
314 if (applyToAllFolders
) {
315 const QString
text(i18nc("@info", "The view properties of all folders will be changed. Do you want to continue?"));
316 if (KMessageBox::questionYesNo(this, text
) == KMessageBox::No
) {
320 // Updating the global view properties time stamp in the general settings makes
321 // all existing viewproperties invalid, as they have a smaller time stamp.
322 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
323 settings
->setViewPropsTimestamp(QDateTime::currentDateTime());
325 // This is also a good chance to make a cleanup of all mirrored view properties:
326 const KUrl mirroredDir
= ViewProperties::mirroredDirectory();
327 KIO::NetAccess::del(mirroredDir
, this);
332 m_dolphinView
->setMode(m_viewProps
->viewMode());
333 m_dolphinView
->setSorting(m_viewProps
->sorting());
334 m_dolphinView
->setSortOrder(m_viewProps
->sortOrder());
335 m_dolphinView
->setCategorizedSorting(m_viewProps
->categorizedSorting());
336 m_dolphinView
->setAdditionalInfo(m_viewProps
->additionalInfo());
337 m_dolphinView
->setShowPreview(m_viewProps
->showPreview());
338 m_dolphinView
->setShowHiddenFiles(m_viewProps
->showHiddenFiles());
342 if (m_useAsDefault
&& m_useAsDefault
->isChecked()) {
343 // For directories where no .directory file is available, the .directory
344 // file stored for the global view properties is used as fallback. To update
345 // this file we temporary turn on the global view properties mode.
346 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
347 Q_ASSERT(!settings
->globalViewProps());
349 settings
->setGlobalViewProps(true);
350 ViewProperties
defaultProps(m_dolphinView
->url());
351 defaultProps
.setDirProperties(*m_viewProps
);
353 settings
->setGlobalViewProps(false);
357 void ViewPropertiesDialog::loadSettings()
360 const int index
= static_cast<int>(m_viewProps
->viewMode());
361 m_viewMode
->setCurrentIndex(index
);
363 // load sort order and sorting
364 const int sortOrderIndex
= (m_viewProps
->sortOrder() == Qt::AscendingOrder
) ? 0 : 1;
365 m_sortOrder
->setCurrentIndex(sortOrderIndex
);
366 m_sorting
->setCurrentIndex(m_viewProps
->sorting());
368 m_additionalInfo
->setEnabled(index
!= DolphinView::ColumnView
);
370 // load show preview, show in groups and show hidden files settings
371 m_showPreview
->setChecked(m_viewProps
->showPreview());
373 m_showInGroups
->setChecked(m_viewProps
->categorizedSorting());
374 m_showInGroups
->setEnabled(index
== DolphinView::IconsView
); // only the icons view supports categorized sorting
376 m_showHiddenFiles
->setChecked(m_viewProps
->showHiddenFiles());
379 #include "viewpropertiesdialog.moc"