summaryrefslogtreecommitdiffstats
path: root/src/viewpropertiesdialog.cpp
blob: 5f87a6253068dc18f91d489284e5781a102f9d1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/***************************************************************************
 *   Copyright (C) 2006 by Peter Penz                                      *
 *   [email protected]                                                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
 ***************************************************************************/

#include "viewpropertiesdialog.h"
#include <tdelocale.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqvbox.h>
#include <tqbuttongroup.h>
#include <tqcheckbox.h>
#include <tqradiobutton.h>
#include <tqpushbutton.h>
#include <tqsizepolicy.h>
#include <tqgroupbox.h>
#include <tqcombobox.h>
#include <kiconloader.h>
#include <tdemessagebox.h>
#include <assert.h>

#include "viewproperties.h"
#include "dolphinview.h"

ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
    KDialogBase(Plain, i18n("View Properties"),
                Ok|Apply|Cancel, Ok),
    m_isDirty(false),
    m_dolphinView(dolphinView)
{
    assert(dolphinView != 0);

    const int margin = KDialog::marginHint();
    const TQSizePolicy sizePolicy(TQSizePolicy::Preferred, TQSizePolicy::Fixed);

    const KURL& url = dolphinView->url();
    m_viewProps = new ViewProperties(url);
    m_viewProps->setAutoSaveEnabled(false);

    TQVBoxLayout* topLayout = new TQVBoxLayout(plainPage(), 0, spacingHint());

    // create 'Properties' group containing view mode, sorting, sort order and show hidden files
    TQGroupBox* propsGroup = new TQGroupBox(2, TQt::Horizontal, i18n("Properties"), plainPage());
    propsGroup->setSizePolicy(sizePolicy);
    propsGroup->setMargin(margin);

    new TQLabel(i18n("View mode:"), propsGroup);
    m_viewMode = new TQComboBox(propsGroup);
    m_viewMode->insertItem(SmallIcon("view_icon"), i18n("Icons"));
    m_viewMode->insertItem(SmallIcon("view_text"), i18n("Details"));
    m_viewMode->insertItem(SmallIcon("gvdirpart"), i18n("Previews"));
    const int index = static_cast<int>(m_viewProps->viewMode());
    m_viewMode->setCurrentItem(index);

    new TQLabel(i18n("Sorting:"), propsGroup);
    m_sorting = new TQComboBox(propsGroup);
    m_sorting->insertItem("By Name");
    m_sorting->insertItem("By Size");
    m_sorting->insertItem("By Date");
    int sortingIdx = 0;
    switch (m_viewProps->sorting()) {
        case DolphinView::SortByName: sortingIdx = 0; break;
        case DolphinView::SortBySize: sortingIdx = 1; break;
        case DolphinView::SortByDate: sortingIdx = 2; break;
        default: break;
    }
    m_sorting->setCurrentItem(sortingIdx);

    new TQLabel(i18n("Sort order:"), propsGroup);
    m_sortOrder = new TQComboBox(propsGroup);
    m_sortOrder->insertItem(i18n("Ascending"));
    m_sortOrder->insertItem(i18n("Descending"));
    const int sortOrderIdx = (m_viewProps->sortOrder() == TQt::Ascending) ? 0 : 1;
    m_sortOrder->setCurrentItem(sortOrderIdx);

    m_showHiddenFiles = new TQCheckBox(i18n("Show hidden files"), propsGroup);
    m_showHiddenFiles->setChecked(m_viewProps->isShowHiddenFilesEnabled());

    // create 'Apply view properties to:' group
    TQButtonGroup* buttonGroup = new TQButtonGroup(3,
                                                 TQt::Vertical,
                                                 i18n("Apply view properties to:"),
                                                 plainPage());
    buttonGroup->setSizePolicy(sizePolicy);
    buttonGroup->setMargin(margin);

    m_applyToCurrentFolder = new TQRadioButton(i18n("Current folder"), buttonGroup);
    buttonGroup->insert(m_applyToCurrentFolder);

    m_applyToSubFolders = new TQRadioButton(i18n("Current folder including all sub folders"), buttonGroup);
    buttonGroup->insert(m_applyToSubFolders);

    m_applyToAllFolders = new TQRadioButton(i18n("All folders"), buttonGroup);
    buttonGroup->insert(m_applyToAllFolders);

    if (m_viewProps->isValidForSubDirs()) {
        m_applyToSubFolders->setChecked(true);
    }
    else {
        m_applyToCurrentFolder->setChecked(true);
    }

    topLayout->addWidget(propsGroup);
    topLayout->addWidget(buttonGroup);

    connect(m_viewMode, TQ_SIGNAL(activated(int)),
            this, TQ_SLOT(slotViewModeChanged(int)));
    connect(m_sorting, TQ_SIGNAL(activated(int)),
            this, TQ_SLOT(slotSortingChanged(int)));
    connect(m_sortOrder, TQ_SIGNAL(activated(int)),
            this, TQ_SLOT(slotSortOrderChanged(int)));
    connect(m_showHiddenFiles, TQ_SIGNAL(clicked()),
            this, TQ_SLOT(slotShowHiddenFilesChanged()));
    connect(m_applyToCurrentFolder, TQ_SIGNAL(clicked()),
            this, TQ_SLOT(slotApplyToCurrentFolder()));
    connect(m_applyToSubFolders, TQ_SIGNAL(clicked()),
            this, TQ_SLOT(slotApplyToSubFolders()));
    connect(m_applyToAllFolders, TQ_SIGNAL(clicked()),
            this, TQ_SLOT(slotApplyToAllFolders()));
}

ViewPropertiesDialog::~ViewPropertiesDialog()
{
    m_isDirty = false;
    delete m_viewProps;
    m_viewProps = 0;
}

void ViewPropertiesDialog::slotOk()
{
    applyViewProperties();
    KDialogBase::slotOk();
}

void ViewPropertiesDialog::slotApply()
{
    applyViewProperties();
    KDialogBase::slotApply();
}

void ViewPropertiesDialog::slotViewModeChanged(int index)
{
    assert((index >= 0) && (index <= 2));
    m_viewProps->setViewMode(static_cast<DolphinView::Mode>(index));
    m_isDirty = true;
}

void ViewPropertiesDialog::slotSortingChanged(int index)
{
    DolphinView::Sorting sorting = DolphinView::SortByName;
    switch (index) {
        case 1: sorting = DolphinView::SortBySize; break;
        case 2: sorting = DolphinView::SortByDate; break;
        default: break;
    }
    m_viewProps->setSorting(sorting);
    m_isDirty = true;
}

void ViewPropertiesDialog::slotSortOrderChanged(int index)
{
    TQt::SortOrder sortOrder = (index == 0) ? TQt::Ascending : TQt::Descending;
    m_viewProps->setSortOrder(sortOrder);
    m_isDirty = true;
}

void ViewPropertiesDialog::slotShowHiddenFilesChanged()
{
    const bool show = m_showHiddenFiles->isChecked();
    m_viewProps->setShowHiddenFilesEnabled(show);
    m_isDirty = true;
}

void ViewPropertiesDialog::slotApplyToCurrentFolder()
{
    m_viewProps->setValidForSubDirs(false);
    m_isDirty = true;
}

void ViewPropertiesDialog::slotApplyToSubFolders()
{
    m_viewProps->setValidForSubDirs(true);
    m_isDirty = true;
}

void ViewPropertiesDialog::slotApplyToAllFolders()
{
    m_isDirty = true;
}

void ViewPropertiesDialog::applyViewProperties()
{
    if (m_applyToAllFolders->isChecked()) {
        if (m_isDirty) {
            const TQString text(i18n("The view properties of all folders will be replaced. Do you want to continue?"));
            if (KMessageBox::questionYesNo(this, text) == KMessageBox::No) {
                return;
            }
        }

        ViewProperties props(TQDir::homeDirPath());
        props.setViewMode(m_viewProps->viewMode());
        props.setSorting(m_viewProps->sorting());
        props.setSortOrder(m_viewProps->sortOrder());
        props.setShowHiddenFilesEnabled(m_viewProps->isShowHiddenFilesEnabled());
        props.setValidForSubDirs(true);
    }
    else if (m_applyToSubFolders->isChecked() && m_isDirty) {
        const TQString text(i18n("The view properties of all sub folders will be replaced. Do you want to continue?"));
        if (KMessageBox::questionYesNo(this, text) == KMessageBox::No) {
            return;
        }
    }

    m_viewProps->save();
    m_dolphinView->setViewProperties(*m_viewProps);
    m_isDirty = false;
}

#include "viewpropertiesdialog.moc"