]>
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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "viewpropertiesdialog.h"
26 #include <q3buttongroup.h>
27 #include <qcheckbox.h>
28 #include <qradiobutton.h>
29 #include <qpushbutton.h>
30 #include <qsizepolicy.h>
31 #include <q3groupbox.h>
32 #include <qcombobox.h>
34 #include <Q3VBoxLayout>
35 #include <kiconloader.h>
36 #include <kmessagebox.h>
39 #include "viewproperties.h"
40 #include "dolphinview.h"
42 ViewPropertiesDialog::ViewPropertiesDialog(DolphinView
* dolphinView
) :
43 KDialog(dolphinView
, static_cast<Qt::WFlags
>(Ok
/* KDE4-TODO: Apply | Cancel*/)),
45 m_dolphinView(dolphinView
)
47 assert(dolphinView
!= 0);
49 const int margin
= KDialog::marginHint();
50 const QSizePolicy
sizePolicy(QSizePolicy::Preferred
, QSizePolicy::Fixed
);
52 const KUrl
& url
= dolphinView
->url();
53 m_viewProps
= new ViewProperties(url
);
54 m_viewProps
->setAutoSaveEnabled(false);
56 Q3VBoxLayout
* topLayout
= new Q3VBoxLayout(mainWidget(), 0, spacingHint());
58 // create 'Properties' group containing view mode, sorting, sort order and show hidden files
59 Q3GroupBox
* propsGroup
= new Q3GroupBox(2, Qt::Horizontal
, i18n("Properties"), mainWidget());
60 propsGroup
->setSizePolicy(sizePolicy
);
61 propsGroup
->setMargin(margin
);
63 new QLabel(i18n("View mode:"), propsGroup
);
64 m_viewMode
= new QComboBox(propsGroup
);
65 m_viewMode
->insertItem(SmallIcon("view_icon"), i18n("Icons"));
66 m_viewMode
->insertItem(SmallIcon("view_text"), i18n("Details"));
67 m_viewMode
->insertItem(SmallIcon("gvdirpart"), i18n("Previews"));
68 const int index
= static_cast<int>(m_viewProps
->viewMode());
69 m_viewMode
->setCurrentItem(index
);
71 new QLabel(i18n("Sorting:"), propsGroup
);
72 m_sorting
= new QComboBox(propsGroup
);
73 m_sorting
->insertItem("By Name");
74 m_sorting
->insertItem("By Size");
75 m_sorting
->insertItem("By Date");
77 switch (m_viewProps
->sorting()) {
78 case DolphinView::SortByName
: sortingIdx
= 0; break;
79 case DolphinView::SortBySize
: sortingIdx
= 1; break;
80 case DolphinView::SortByDate
: sortingIdx
= 2; break;
83 m_sorting
->setCurrentItem(sortingIdx
);
85 new QLabel(i18n("Sort order:"), propsGroup
);
86 m_sortOrder
= new QComboBox(propsGroup
);
87 m_sortOrder
->insertItem(i18n("Ascending"));
88 m_sortOrder
->insertItem(i18n("Descending"));
89 const int sortOrderIdx
= (m_viewProps
->sortOrder() == Qt::Ascending
) ? 0 : 1;
90 m_sortOrder
->setCurrentItem(sortOrderIdx
);
92 m_showHiddenFiles
= new QCheckBox(i18n("Show hidden files"), propsGroup
);
93 m_showHiddenFiles
->setChecked(m_viewProps
->isShowHiddenFilesEnabled());
95 // create 'Apply view properties to:' group
96 Q3ButtonGroup
* buttonGroup
= new Q3ButtonGroup(3,
98 i18n("Apply view properties to:"),
100 buttonGroup
->setSizePolicy(sizePolicy
);
101 buttonGroup
->setMargin(margin
);
103 m_applyToCurrentFolder
= new QRadioButton(i18n("Current folder"), buttonGroup
);
104 buttonGroup
->insert(m_applyToCurrentFolder
);
106 m_applyToSubFolders
= new QRadioButton(i18n("Current folder including all sub folders"), buttonGroup
);
107 buttonGroup
->insert(m_applyToSubFolders
);
109 m_applyToAllFolders
= new QRadioButton(i18n("All folders"), buttonGroup
);
110 buttonGroup
->insert(m_applyToAllFolders
);
112 if (m_viewProps
->isValidForSubDirs()) {
113 m_applyToSubFolders
->setChecked(true);
116 m_applyToCurrentFolder
->setChecked(true);
119 topLayout
->addWidget(propsGroup
);
120 topLayout
->addWidget(buttonGroup
);
122 connect(m_viewMode
, SIGNAL(activated(int)),
123 this, SLOT(slotViewModeChanged(int)));
124 connect(m_sorting
, SIGNAL(activated(int)),
125 this, SLOT(slotSortingChanged(int)));
126 connect(m_sortOrder
, SIGNAL(activated(int)),
127 this, SLOT(slotSortOrderChanged(int)));
128 connect(m_showHiddenFiles
, SIGNAL(clicked()),
129 this, SLOT(slotShowHiddenFilesChanged()));
130 connect(m_applyToCurrentFolder
, SIGNAL(clicked()),
131 this, SLOT(slotApplyToCurrentFolder()));
132 connect(m_applyToSubFolders
, SIGNAL(clicked()),
133 this, SLOT(slotApplyToSubFolders()));
134 connect(m_applyToAllFolders
, SIGNAL(clicked()),
135 this, SLOT(slotApplyToAllFolders()));
138 ViewPropertiesDialog::~ViewPropertiesDialog()
145 void ViewPropertiesDialog::slotOk()
147 applyViewProperties();
148 // KDE4-TODO: KDialog::slotOk();
151 void ViewPropertiesDialog::slotApply()
153 applyViewProperties();
154 // KDE4-TODO: KDialog::slotApply();
157 void ViewPropertiesDialog::slotViewModeChanged(int index
)
159 assert((index
>= 0) && (index
<= 2));
160 m_viewProps
->setViewMode(static_cast<DolphinView::Mode
>(index
));
164 void ViewPropertiesDialog::slotSortingChanged(int index
)
166 DolphinView::Sorting sorting
= DolphinView::SortByName
;
168 case 1: sorting
= DolphinView::SortBySize
; break;
169 case 2: sorting
= DolphinView::SortByDate
; break;
172 m_viewProps
->setSorting(sorting
);
176 void ViewPropertiesDialog::slotSortOrderChanged(int index
)
178 Qt::SortOrder sortOrder
= (index
== 0) ? Qt::Ascending
: Qt::Descending
;
179 m_viewProps
->setSortOrder(sortOrder
);
183 void ViewPropertiesDialog::slotShowHiddenFilesChanged()
185 const bool show
= m_showHiddenFiles
->isChecked();
186 m_viewProps
->setShowHiddenFilesEnabled(show
);
190 void ViewPropertiesDialog::slotApplyToCurrentFolder()
192 m_viewProps
->setValidForSubDirs(false);
196 void ViewPropertiesDialog::slotApplyToSubFolders()
198 m_viewProps
->setValidForSubDirs(true);
202 void ViewPropertiesDialog::slotApplyToAllFolders()
207 void ViewPropertiesDialog::applyViewProperties()
209 if (m_applyToAllFolders
->isChecked()) {
211 const QString
text(i18n("The view properties of all folders will be replaced. Do you want to continue?"));
212 if (KMessageBox::questionYesNo(this, text
) == KMessageBox::No
) {
217 ViewProperties
props(QDir::homeDirPath());
218 props
.setViewMode(m_viewProps
->viewMode());
219 props
.setSorting(m_viewProps
->sorting());
220 props
.setSortOrder(m_viewProps
->sortOrder());
221 props
.setShowHiddenFilesEnabled(m_viewProps
->isShowHiddenFilesEnabled());
222 props
.setValidForSubDirs(true);
224 else if (m_applyToSubFolders
->isChecked() && m_isDirty
) {
225 const QString
text(i18n("The view properties of all sub folders will be replaced. Do you want to continue?"));
226 if (KMessageBox::questionYesNo(this, text
) == KMessageBox::No
) {
232 m_dolphinView
->setViewProperties(*m_viewProps
);
236 #include "viewpropertiesdialog.moc"