]>
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"
22 #include "viewpropsprogressinfo.h"
23 #include "dolphinview.h"
24 #include "dolphinsettings.h"
25 #include "dolphinsortfilterproxymodel.h"
26 #include "dolphin_generalsettings.h"
27 #include "viewproperties.h"
29 #include <config-nepomuk.h>
31 #include <nepomuk/resourcemanager.h>
34 #include <kcomponentdata.h>
36 #include <kiconloader.h>
37 #include <kio/netaccess.h>
38 #include <kmessagebox.h>
39 #include <kstandarddirs.h>
43 #include <QButtonGroup>
46 #include <QGridLayout>
50 #include <QPushButton>
51 #include <QRadioButton>
54 ViewPropertiesDialog::ViewPropertiesDialog(DolphinView
* dolphinView
) :
57 m_dolphinView(dolphinView
),
66 m_applyToCurrentFolder(0),
67 m_applyToSubFolders(0),
70 Q_ASSERT(dolphinView
!= 0);
71 const bool useGlobalViewProps
= DolphinSettings::instance().generalSettings()->globalViewProps();
73 setCaption(i18nc("@title:window", "View Properties"));
74 setButtons(KDialog::Ok
| KDialog::Cancel
| KDialog::Apply
);
76 const KUrl
& url
= dolphinView
->url();
77 m_viewProps
= new ViewProperties(url
);
78 m_viewProps
->setAutoSaveEnabled(false);
80 QWidget
* main
= new QWidget();
81 QVBoxLayout
* topLayout
= new QVBoxLayout();
83 // create 'Properties' group containing view mode, sorting, sort order and show hidden files
84 QWidget
* propsBox
= main
;
85 if (!useGlobalViewProps
) {
86 propsBox
= new QGroupBox(i18nc("@title:group", "Properties"), main
);
89 QLabel
* viewModeLabel
= new QLabel(i18nc("@label:listbox", "View mode:"), propsBox
);
90 m_viewMode
= new QComboBox(propsBox
);
91 m_viewMode
->addItem(KIcon("fileview-icon"), i18nc("@item:inlistbox", "Icons"));
92 m_viewMode
->addItem(KIcon("fileview-detailed"), i18nc("@item:inlistbox", "Details"));
93 m_viewMode
->addItem(KIcon("fileview-column"), i18nc("@item:inlistbox", "Column"));
95 QLabel
* sortingLabel
= new QLabel(i18nc("@label:listbox", "Sorting:"), propsBox
);
96 QWidget
* sortingBox
= new QWidget(propsBox
);
98 m_sortOrder
= new QComboBox(sortingBox
);
99 m_sortOrder
->addItem(i18nc("@item:inlistbox", "Ascending"));
100 m_sortOrder
->addItem(i18nc("@item:inlistbox", "Descending"));
102 m_sorting
= new QComboBox(sortingBox
);
103 m_sorting
->addItem(i18nc("@item:inlistbox Sort", "By Name"));
104 m_sorting
->addItem(i18nc("@item:inlistbox Sort", "By Size"));
105 m_sorting
->addItem(i18nc("@item:inlistbox Sort", "By Date"));
106 m_sorting
->addItem(i18nc("@item:inlistbox Sort", "By Permissions"));
107 m_sorting
->addItem(i18nc("@item:inlistbox Sort", "By Owner"));
108 m_sorting
->addItem(i18nc("@item:inlistbox Sort", "By Group"));
109 m_sorting
->addItem(i18nc("@item:inlistbox Sort", "By Type"));
111 if (!Nepomuk::ResourceManager::instance()->init()) {
112 m_sorting
->addItem(i18nc("@item:inlistbox Sort", "By Rating"));
113 m_sorting
->addItem(i18nc("@item:inlistbox Sort", "By Tags"));
117 QHBoxLayout
* sortingLayout
= new QHBoxLayout();
118 sortingLayout
->setMargin(0);
119 sortingLayout
->addWidget(m_sortOrder
);
120 sortingLayout
->addWidget(m_sorting
);
121 sortingBox
->setLayout(sortingLayout
);
123 QLabel
* additionalInfoLabel
= new QLabel(i18nc("@label:listbox", "Additional information:"), propsBox
);
124 m_additionalInfo
= new QComboBox(propsBox
);
125 m_additionalInfo
->addItem(i18nc("@item:inlistbox Additional info", "No Information"),
126 KFileItemDelegate::NoInformation
);
127 m_additionalInfo
->addItem(i18nc("@item:inlistbox Additional info", "Type"),
128 KFileItemDelegate::FriendlyMimeType
);
129 m_additionalInfo
->addItem(i18nc("@item:inlistbox Additional info", "Size"),
130 KFileItemDelegate::Size
);
131 m_additionalInfo
->addItem(i18nc("@item:inlistbox Additional info", "Date"),
132 KFileItemDelegate::ModificationTime
);
134 m_showPreview
= new QCheckBox(i18nc("@option:check", "Show preview"), propsBox
);
135 m_showInGroups
= new QCheckBox(i18nc("@option:check", "Show in Groups"), propsBox
);
136 m_showHiddenFiles
= new QCheckBox(i18nc("@option:check", "Show hidden files"), propsBox
);
138 QGridLayout
* propsBoxLayout
= new QGridLayout(propsBox
);
139 propsBoxLayout
->addWidget(viewModeLabel
, 0, 0);
140 propsBoxLayout
->addWidget(m_viewMode
, 0, 1);
141 propsBoxLayout
->addWidget(sortingLabel
, 1, 0);
142 propsBoxLayout
->addWidget(sortingBox
, 1, 1);
143 propsBoxLayout
->addWidget(additionalInfoLabel
, 2, 0);
144 propsBoxLayout
->addWidget(m_additionalInfo
, 2, 1);
145 propsBoxLayout
->addWidget(m_showPreview
, 3, 0);
146 propsBoxLayout
->addWidget(m_showInGroups
, 4, 0);
147 propsBoxLayout
->addWidget(m_showHiddenFiles
, 5, 0);
149 topLayout
->addWidget(propsBox
);
151 connect(m_viewMode
, SIGNAL(activated(int)),
152 this, SLOT(slotViewModeChanged(int)));
153 connect(m_sorting
, SIGNAL(activated(int)),
154 this, SLOT(slotSortingChanged(int)));
155 connect(m_sortOrder
, SIGNAL(activated(int)),
156 this, SLOT(slotSortOrderChanged(int)));
157 connect(m_additionalInfo
, SIGNAL(activated(int)),
158 this, SLOT(slotAdditionalInfoChanged(int)));
159 connect(m_showPreview
, SIGNAL(clicked()),
160 this, SLOT(slotShowPreviewChanged()));
161 connect(m_showInGroups
, SIGNAL(clicked()),
162 this, SLOT(slotCategorizedSortingChanged()));
163 connect(m_showHiddenFiles
, SIGNAL(clicked()),
164 this, SLOT(slotShowHiddenFilesChanged()));
166 connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
167 connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply()));
169 // Only show the following settings if the view properties are remembered
170 // for each directory:
171 if (!useGlobalViewProps
) {
172 // create 'Apply View Properties To' group
173 QGroupBox
* applyBox
= new QGroupBox(i18nc("@title:group", "Apply View Properties To"), main
);
175 m_applyToCurrentFolder
= new QRadioButton(i18nc("@option:radio Apply View Properties To",
176 "Current folder"), applyBox
);
177 m_applyToCurrentFolder
->setChecked(true);
178 m_applyToSubFolders
= new QRadioButton(i18nc("@option:radio Apply View Properties To",
179 "Current folder including all sub folders"), applyBox
);
180 m_applyToAllFolders
= new QRadioButton(i18nc("@option:radio Apply View Properties To",
181 "All folders"), applyBox
);
183 QButtonGroup
* applyGroup
= new QButtonGroup(this);
184 applyGroup
->addButton(m_applyToCurrentFolder
);
185 applyGroup
->addButton(m_applyToSubFolders
);
186 applyGroup
->addButton(m_applyToAllFolders
);
188 QVBoxLayout
* applyBoxLayout
= new QVBoxLayout(applyBox
);
189 applyBoxLayout
->addWidget(m_applyToCurrentFolder
);
190 applyBoxLayout
->addWidget(m_applyToSubFolders
);
191 applyBoxLayout
->addWidget(m_applyToAllFolders
);
193 m_useAsDefault
= new QCheckBox(i18nc("@option:check", "Use as default for new folders"), main
);
195 topLayout
->addWidget(applyBox
);
196 topLayout
->addWidget(m_useAsDefault
);
198 connect(m_applyToCurrentFolder
, SIGNAL(clicked()),
199 this, SLOT(markAsDirty()));
200 connect(m_applyToSubFolders
, SIGNAL(clicked()),
201 this, SLOT(markAsDirty()));
202 connect(m_applyToAllFolders
, SIGNAL(clicked()),
203 this, SLOT(markAsDirty()));
204 connect(m_useAsDefault
, SIGNAL(clicked()),
205 this, SLOT(markAsDirty()));
208 main
->setLayout(topLayout
);
211 const KConfigGroup
dialogConfig(KSharedConfig::openConfig("dolphinrc"),
212 "ViewPropertiesDialog");
213 restoreDialogSize(dialogConfig
);
218 ViewPropertiesDialog::~ViewPropertiesDialog()
224 KConfigGroup
dialogConfig(KSharedConfig::openConfig("dolphinrc"),
225 "ViewPropertiesDialog");
226 saveDialogSize(dialogConfig
, KConfigFlags::Persistent
);
229 void ViewPropertiesDialog::slotOk()
231 applyViewProperties();
235 void ViewPropertiesDialog::slotApply()
237 applyViewProperties();
240 void ViewPropertiesDialog::slotViewModeChanged(int index
)
242 m_viewProps
->setViewMode(static_cast<DolphinView::Mode
>(index
));
245 const bool iconsViewEnabled
= (m_viewProps
->viewMode() == DolphinView::IconsView
);
246 m_showInGroups
->setEnabled(iconsViewEnabled
);
247 m_additionalInfo
->setEnabled(iconsViewEnabled
);
250 void ViewPropertiesDialog::slotSortingChanged(int index
)
252 const DolphinView::Sorting sorting
= DolphinSortFilterProxyModel::sortingForColumn(index
);
253 m_viewProps
->setSorting(sorting
);
257 void ViewPropertiesDialog::slotSortOrderChanged(int index
)
259 const Qt::SortOrder sortOrder
= (index
== 0) ? Qt::AscendingOrder
: Qt::DescendingOrder
;
260 m_viewProps
->setSortOrder(sortOrder
);
264 void ViewPropertiesDialog::slotCategorizedSortingChanged()
266 m_viewProps
->setCategorizedSorting(m_showInGroups
->isChecked());
270 void ViewPropertiesDialog::slotAdditionalInfoChanged(int index
)
272 KFileItemDelegate::InformationList info
;
274 case 1: info
<< KFileItemDelegate::FriendlyMimeType
; break;
275 case 2: info
<< KFileItemDelegate::Size
; break;
276 case 3: info
<< KFileItemDelegate::ModificationTime
; break;
279 m_viewProps
->setAdditionalInfo(info
);
283 void ViewPropertiesDialog::slotShowPreviewChanged()
285 const bool show
= m_showPreview
->isChecked();
286 m_viewProps
->setShowPreview(show
);
290 void ViewPropertiesDialog::slotShowHiddenFilesChanged()
292 const bool show
= m_showHiddenFiles
->isChecked();
293 m_viewProps
->setShowHiddenFiles(show
);
297 void ViewPropertiesDialog::markAsDirty()
302 void ViewPropertiesDialog::applyViewProperties()
304 const bool applyToSubFolders
= m_isDirty
&&
305 (m_applyToSubFolders
!= 0) &&
306 m_applyToSubFolders
->isChecked();
307 if (applyToSubFolders
) {
308 const QString
text(i18nc("@info", "The view properties of all sub folders will be changed. Do you want to continue?"));
309 if (KMessageBox::questionYesNo(this, text
) == KMessageBox::No
) {
313 ViewPropsProgressInfo
* info
= new ViewPropsProgressInfo(m_dolphinView
,
314 m_dolphinView
->url(),
316 info
->setWindowModality(Qt::NonModal
);
320 const bool applyToAllFolders
= m_isDirty
&&
321 (m_applyToAllFolders
!= 0) &&
322 m_applyToAllFolders
->isChecked();
323 if (applyToAllFolders
) {
324 const QString
text(i18nc("@info", "The view properties of all folders will be changed. Do you want to continue?"));
325 if (KMessageBox::questionYesNo(this, text
) == KMessageBox::No
) {
329 // Updating the global view properties time stamp in the general settings makes
330 // all existing viewproperties invalid, as they have a smaller time stamp.
331 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
332 settings
->setViewPropsTimestamp(QDateTime::currentDateTime());
334 // This is also a good chance to make a cleanup of all mirrored view properties:
335 const KUrl mirroredDir
= ViewProperties::mirroredDirectory();
336 KIO::NetAccess::del(mirroredDir
, this);
341 m_dolphinView
->setMode(m_viewProps
->viewMode());
342 m_dolphinView
->setSorting(m_viewProps
->sorting());
343 m_dolphinView
->setSortOrder(m_viewProps
->sortOrder());
344 m_dolphinView
->setCategorizedSorting(m_viewProps
->categorizedSorting());
345 m_dolphinView
->setAdditionalInfo(m_viewProps
->additionalInfo());
346 m_dolphinView
->setShowPreview(m_viewProps
->showPreview());
347 m_dolphinView
->setShowHiddenFiles(m_viewProps
->showHiddenFiles());
351 if (m_useAsDefault
->isChecked()) {
352 // For directories where no .directory file is available, the .directory
353 // file stored for the global view properties is used as fallback. To update
354 // this file we temporary turn on the global view properties mode.
355 GeneralSettings
* settings
= DolphinSettings::instance().generalSettings();
356 Q_ASSERT(!settings
->globalViewProps());
358 settings
->setGlobalViewProps(true);
359 ViewProperties
defaultProps(m_dolphinView
->url());
360 defaultProps
.setDirProperties(*m_viewProps
);
362 settings
->setGlobalViewProps(false);
366 void ViewPropertiesDialog::loadSettings()
369 const int index
= static_cast<int>(m_viewProps
->viewMode());
370 m_viewMode
->setCurrentIndex(index
);
371 const bool iconsViewEnabled
= (index
== DolphinView::IconsView
);
373 // load sort order and sorting
374 const int sortOrderIndex
= (m_viewProps
->sortOrder() == Qt::AscendingOrder
) ? 0 : 1;
375 m_sortOrder
->setCurrentIndex(sortOrderIndex
);
376 m_sorting
->setCurrentIndex(m_viewProps
->sorting());
378 // load additional info
379 KFileItemDelegate::InformationList info
= m_viewProps
->additionalInfo();
380 const int addInfoIndex
= m_additionalInfo
->findData(info
.isEmpty() ? KFileItemDelegate::NoInformation
: info
.first());
381 m_additionalInfo
->setCurrentIndex(addInfoIndex
);
382 m_additionalInfo
->setEnabled(iconsViewEnabled
);
384 // load show preview, show in groups and show hidden files settings
385 m_showPreview
->setChecked(m_viewProps
->showPreview());
387 m_showInGroups
->setChecked(m_viewProps
->categorizedSorting());
388 m_showInGroups
->setEnabled(iconsViewEnabled
); // only the icons view supports categorized sorting
390 m_showHiddenFiles
->setChecked(m_viewProps
->showHiddenFiles());
393 #include "viewpropertiesdialog.moc"