]>
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 // TODO: Hided "sort by rating" and "sort by tags" as without caching the performance
114 // is too slow currently (Nepomuk will support caching in future releases).
116 // if (!Nepomuk::ResourceManager::instance()->init()) {
117 // m_sorting->addItem(i18nc("@item:inlistbox Sort", "By Rating"));
118 // m_sorting->addItem(i18nc("@item:inlistbox Sort", "By Tags"));
122 QHBoxLayout
* sortingLayout
= new QHBoxLayout();
123 sortingLayout
->setMargin(0);
124 sortingLayout
->addWidget(m_sortOrder
);
125 sortingLayout
->addWidget(m_sorting
);
126 sortingBox
->setLayout(sortingLayout
);
128 m_showPreview
= new QCheckBox(i18nc("@option:check", "Show preview"), propsBox
);
129 m_showInGroups
= new QCheckBox(i18nc("@option:check", "Show in Groups"), propsBox
);
130 m_showHiddenFiles
= new QCheckBox(i18nc("@option:check", "Show hidden files"), propsBox
);
132 m_additionalInfo
= new QPushButton(i18nc("@action:button", "Additional Information"), propsBox
);
133 connect(m_additionalInfo
, SIGNAL(clicked()),
134 this, SLOT(configureAdditionalInfo()));
136 QGridLayout
* propsBoxLayout
= new QGridLayout(propsBox
);
137 propsBoxLayout
->addWidget(viewModeLabel
, 0, 0);
138 propsBoxLayout
->addWidget(m_viewMode
, 0, 1);
139 propsBoxLayout
->addWidget(sortingLabel
, 1, 0);
140 propsBoxLayout
->addWidget(sortingBox
, 1, 1);
141 propsBoxLayout
->addWidget(m_showPreview
, 2, 0);
142 propsBoxLayout
->addWidget(m_showInGroups
, 3, 0);
143 propsBoxLayout
->addWidget(m_showHiddenFiles
, 4, 0);
144 propsBoxLayout
->addWidget(m_additionalInfo
, 5, 0);
146 topLayout
->addWidget(propsBox
);
148 connect(m_viewMode
, SIGNAL(activated(int)),
149 this, SLOT(slotViewModeChanged(int)));
150 connect(m_sorting
, SIGNAL(activated(int)),
151 this, SLOT(slotSortingChanged(int)));
152 connect(m_sortOrder
, SIGNAL(activated(int)),
153 this, SLOT(slotSortOrderChanged(int)));
154 connect(m_additionalInfo
, SIGNAL(activated(int)),
155 this, SLOT(slotAdditionalInfoChanged(int)));
156 connect(m_showPreview
, SIGNAL(clicked()),
157 this, SLOT(slotShowPreviewChanged()));
158 connect(m_showInGroups
, SIGNAL(clicked()),
159 this, SLOT(slotCategorizedSortingChanged()));
160 connect(m_showHiddenFiles
, SIGNAL(clicked()),
161 this, SLOT(slotShowHiddenFilesChanged()));
163 connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
164 connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply()));
166 // Only show the following settings if the view properties are remembered
167 // for each directory:
168 if (!useGlobalViewProps
) {
169 // create 'Apply View Properties To' group
170 QGroupBox
* applyBox
= new QGroupBox(i18nc("@title:group", "Apply View Properties To"), main
);
172 m_applyToCurrentFolder
= new QRadioButton(i18nc("@option:radio Apply View Properties To",
173 "Current folder"), applyBox
);
174 m_applyToCurrentFolder
->setChecked(true);
175 m_applyToSubFolders
= new QRadioButton(i18nc("@option:radio Apply View Properties To",
176 "Current folder including all sub folders"), applyBox
);
177 m_applyToAllFolders
= new QRadioButton(i18nc("@option:radio Apply View Properties To",
178 "All folders"), applyBox
);
180 QButtonGroup
* applyGroup
= new QButtonGroup(this);
181 applyGroup
->addButton(m_applyToCurrentFolder
);
182 applyGroup
->addButton(m_applyToSubFolders
);
183 applyGroup
->addButton(m_applyToAllFolders
);
185 QVBoxLayout
* applyBoxLayout
= new QVBoxLayout(applyBox
);
186 applyBoxLayout
->addWidget(m_applyToCurrentFolder
);
187 applyBoxLayout
->addWidget(m_applyToSubFolders
);
188 applyBoxLayout
->addWidget(m_applyToAllFolders
);
190 m_useAsDefault
= new QCheckBox(i18nc("@option:check", "Use as default for new folders"), main
);
192 topLayout
->addWidget(applyBox
);
193 topLayout
->addWidget(m_useAsDefault
);
195 connect(m_applyToCurrentFolder
, SIGNAL(clicked()),
196 this, SLOT(markAsDirty()));
197 connect(m_applyToSubFolders
, SIGNAL(clicked()),
198 this, SLOT(markAsDirty()));
199 connect(m_applyToAllFolders
, SIGNAL(clicked()),
200 this, SLOT(markAsDirty()));
201 connect(m_useAsDefault
, SIGNAL(clicked()),
202 this, SLOT(markAsDirty()));
205 main
->setLayout(topLayout
);
208 const KConfigGroup
dialogConfig(KSharedConfig::openConfig("dolphinrc"),
209 "ViewPropertiesDialog");
210 restoreDialogSize(dialogConfig
);
215 ViewPropertiesDialog::~ViewPropertiesDialog()
221 KConfigGroup
dialogConfig(KSharedConfig::openConfig("dolphinrc"),
222 "ViewPropertiesDialog");
223 saveDialogSize(dialogConfig
, KConfigBase::Persistent
);
226 void ViewPropertiesDialog::slotOk()
228 applyViewProperties();
232 void ViewPropertiesDialog::slotApply()
234 applyViewProperties();
237 void ViewPropertiesDialog::slotViewModeChanged(int index
)
239 m_viewProps
->setViewMode(static_cast<DolphinView::Mode
>(index
));
242 const DolphinView::Mode mode
= m_viewProps
->viewMode();
243 m_showInGroups
->setEnabled(mode
== DolphinView::IconsView
);
244 m_additionalInfo
->setEnabled(mode
!= DolphinView::ColumnView
);
247 void ViewPropertiesDialog::slotSortingChanged(int index
)
249 const DolphinView::Sorting sorting
= DolphinSortFilterProxyModel::sortingForColumn(index
);
250 m_viewProps
->setSorting(sorting
);
254 void ViewPropertiesDialog::slotSortOrderChanged(int index
)
256 const Qt::SortOrder sortOrder
= (index
== 0) ? Qt::AscendingOrder
: Qt::DescendingOrder
;
257 m_viewProps
->setSortOrder(sortOrder
);
261 void ViewPropertiesDialog::slotCategorizedSortingChanged()
263 m_viewProps
->setCategorizedSorting(m_showInGroups
->isChecked());
267 void ViewPropertiesDialog::slotShowPreviewChanged()
269 const bool show
= m_showPreview
->isChecked();
270 m_viewProps
->setShowPreview(show
);
274 void ViewPropertiesDialog::slotShowHiddenFilesChanged()
276 const bool show
= m_showHiddenFiles
->isChecked();
277 m_viewProps
->setShowHiddenFiles(show
);
281 void ViewPropertiesDialog::markAsDirty()
286 void ViewPropertiesDialog::configureAdditionalInfo()
288 KFileItemDelegate::InformationList info
= m_viewProps
->additionalInfo();
289 const bool useDefaultInfo
= (m_viewProps
->viewMode() == DolphinView::DetailsView
) &&
290 (info
.isEmpty() || info
.contains(KFileItemDelegate::NoInformation
));
291 if (useDefaultInfo
) {
292 // Using the details view without any additional information (-> additional column)
293 // makes no sense and leads to a usability problem as no viewport area is available
294 // anymore. Hence as fallback provide at least a size and date column.
296 info
.append(KFileItemDelegate::Size
);
297 info
.append(KFileItemDelegate::ModificationTime
);
298 m_viewProps
->setAdditionalInfo(info
);
301 AdditionalInfoDialog
dialog(this, info
);
302 if (dialog
.exec() == QDialog::Accepted
) {
303 m_viewProps
->setAdditionalInfo(dialog
.additionalInfo());
308 void ViewPropertiesDialog::applyViewProperties()
310 const bool applyToSubFolders
= m_isDirty
&&
311 (m_applyToSubFolders
!= 0) &&
312 m_applyToSubFolders
->isChecked();
313 if (applyToSubFolders
) {
314 const QString
text(i18nc("@info", "The view properties of all sub folders will be changed. Do you want to continue?"));
315 if (KMessageBox::questionYesNo(this, text
) == KMessageBox::No
) {
319 ViewPropsProgressInfo
* info
= new ViewPropsProgressInfo(m_dolphinView
,
320 m_dolphinView
->url(),
322 info
->setWindowModality(Qt::NonModal
);
326 const bool applyToAllFolders
= m_isDirty
&&
327 (m_applyToAllFolders
!= 0) &&
328 m_applyToAllFolders
->isChecked();
329 if (applyToAllFolders
) {
330 const QString
text(i18nc("@info", "The view properties of all folders will be changed. Do you want to continue?"));
331 if (KMessageBox::questionYesNo(this, text
) == KMessageBox::No
) {
335 // Updating the global view properties time stamp in the general settings makes
336 // all existing viewproperties invalid, as they have a smaller time stamp.
337 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
338 settings
->setViewPropsTimestamp(QDateTime::currentDateTime());
340 // This is also a good chance to make a cleanup of all mirrored view properties:
341 const KUrl mirroredDir
= ViewProperties::mirroredDirectory();
342 KIO::NetAccess::del(mirroredDir
, this);
347 m_dolphinView
->setMode(m_viewProps
->viewMode());
348 m_dolphinView
->setSorting(m_viewProps
->sorting());
349 m_dolphinView
->setSortOrder(m_viewProps
->sortOrder());
350 m_dolphinView
->setCategorizedSorting(m_viewProps
->categorizedSorting());
351 m_dolphinView
->setAdditionalInfo(m_viewProps
->additionalInfo());
352 m_dolphinView
->setShowPreview(m_viewProps
->showPreview());
353 m_dolphinView
->setShowHiddenFiles(m_viewProps
->showHiddenFiles());
357 if (m_useAsDefault
&& m_useAsDefault
->isChecked()) {
358 // For directories where no .directory file is available, the .directory
359 // file stored for the global view properties is used as fallback. To update
360 // this file we temporary turn on the global view properties mode.
361 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
362 Q_ASSERT(!settings
->globalViewProps());
364 settings
->setGlobalViewProps(true);
365 ViewProperties
defaultProps(m_dolphinView
->url());
366 defaultProps
.setDirProperties(*m_viewProps
);
368 settings
->setGlobalViewProps(false);
372 void ViewPropertiesDialog::loadSettings()
375 const int index
= static_cast<int>(m_viewProps
->viewMode());
376 m_viewMode
->setCurrentIndex(index
);
378 // load sort order and sorting
379 const int sortOrderIndex
= (m_viewProps
->sortOrder() == Qt::AscendingOrder
) ? 0 : 1;
380 m_sortOrder
->setCurrentIndex(sortOrderIndex
);
381 m_sorting
->setCurrentIndex(m_viewProps
->sorting());
383 m_additionalInfo
->setEnabled(index
!= DolphinView::ColumnView
);
385 // load show preview, show in groups and show hidden files settings
386 m_showPreview
->setChecked(m_viewProps
->showPreview());
388 m_showInGroups
->setChecked(m_viewProps
->categorizedSorting());
389 m_showInGroups
->setEnabled(index
== DolphinView::IconsView
); // only the icons view supports categorized sorting
391 m_showHiddenFiles
->setChecked(m_viewProps
->showHiddenFiles());
394 #include "viewpropertiesdialog.moc"