~blue-shell/blue-shell/folderview-qml

« back to all changes in this revision

Viewing changes to dolphin/src/generalsettingspage.cpp

  • Committer: Peter Penz
  • Date: 2006-11-21 06:02:05 UTC
  • Revision ID: git-v1:daace0e789c3ea5e8a89e514abb717c9c360fc7f
commited initial version of Dolphin

svn path=/trunk/playground/utils/dolphin/; revision=606622

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and              *
 
3
 *   and Patrice Tremblay                                                  *
 
4
 *                                                                         *
 
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.                                   *
 
9
 *                                                                         *
 
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.                          *
 
14
 *                                                                         *
 
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
 ***************************************************************************/
 
20
 
 
21
#include "generalsettingspage.h"
 
22
 
 
23
#include <qlayout.h>
 
24
//Added by qt3to4:
 
25
#include <Q3VBoxLayout>
 
26
#include <kdialog.h>
 
27
#include <qlabel.h>
 
28
#include <qlineedit.h>
 
29
#include <q3vbox.h>
 
30
#include <q3grid.h>
 
31
#include <q3groupbox.h>
 
32
#include <klocale.h>
 
33
#include <qcheckbox.h>
 
34
#include <q3buttongroup.h>
 
35
#include <qpushbutton.h>
 
36
#include <kfiledialog.h>
 
37
#include <qradiobutton.h>
 
38
 
 
39
#include "dolphinsettings.h"
 
40
#include "dolphin.h"
 
41
#include "dolphinview.h"
 
42
#include "generalsettings.h"
 
43
 
 
44
GeneralSettingsPage::GeneralSettingsPage(QWidget* parent) :
 
45
    SettingsPageBase(parent),
 
46
    m_homeURL(0),
 
47
    m_startSplit(0),
 
48
    m_startEditable(0)
 
49
{
 
50
    Q3VBoxLayout* topLayout = new Q3VBoxLayout(parent, 2, KDialog::spacingHint());
 
51
 
 
52
    const int spacing = KDialog::spacingHint();
 
53
    const int margin = KDialog::marginHint();
 
54
    const QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
 
55
 
 
56
    GeneralSettings* settings = DolphinSettings::instance().generalSettings();
 
57
 
 
58
    Q3VBox* vBox = new Q3VBox(parent);
 
59
    vBox->setSizePolicy(sizePolicy);
 
60
    vBox->setSpacing(spacing);
 
61
    vBox->setMargin(margin);
 
62
    vBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored);
 
63
 
 
64
    // create 'Home URL' editor
 
65
    Q3GroupBox* homeGroup = new Q3GroupBox(1, Qt::Horizontal, i18n("Home URL"), vBox);
 
66
    homeGroup->setSizePolicy(sizePolicy);
 
67
    homeGroup->setMargin(margin);
 
68
 
 
69
    Q3HBox* homeURLBox = new Q3HBox(homeGroup);
 
70
    homeURLBox->setSizePolicy(sizePolicy);
 
71
    homeURLBox->setSpacing(spacing);
 
72
 
 
73
    new QLabel(i18n("Location:"), homeURLBox);
 
74
    m_homeURL = new QLineEdit(settings->homeURL(), homeURLBox);
 
75
 
 
76
    QPushButton* selectHomeURLButton = new QPushButton(SmallIcon("folder"), QString::null, homeURLBox);
 
77
    connect(selectHomeURLButton, SIGNAL(clicked()),
 
78
            this, SLOT(selectHomeURL()));
 
79
 
 
80
    Q3HBox* buttonBox = new Q3HBox(homeGroup);
 
81
    buttonBox->setSizePolicy(sizePolicy);
 
82
    buttonBox->setSpacing(spacing);
 
83
    QPushButton* useCurrentButton = new QPushButton(i18n("Use current location"), buttonBox);
 
84
    connect(useCurrentButton, SIGNAL(clicked()),
 
85
            this, SLOT(useCurrentLocation()));
 
86
    QPushButton* useDefaultButton = new QPushButton(i18n("Use default location"), buttonBox);
 
87
    connect(useDefaultButton, SIGNAL(clicked()),
 
88
            this, SLOT(useDefaulLocation()));
 
89
 
 
90
    // create 'Default View Mode' group
 
91
    Q3ButtonGroup* buttonGroup = new Q3ButtonGroup(3, Qt::Vertical, i18n("Default View Mode"), vBox);
 
92
    buttonGroup->setSizePolicy(sizePolicy);
 
93
    buttonGroup->setMargin(margin);
 
94
 
 
95
    m_iconsView = new QRadioButton(i18n("Icons"), buttonGroup);
 
96
    m_detailsView = new QRadioButton(i18n("Details"), buttonGroup);
 
97
    m_previewsView = new QRadioButton(i18n("Previews"), buttonGroup);
 
98
 
 
99
    switch (settings->defaultViewMode()) {
 
100
        case DolphinView::IconsView:    m_iconsView->setChecked(true); break;
 
101
        case DolphinView::DetailsView:  m_detailsView->setChecked(true); break;
 
102
        case DolphinView::PreviewsView: m_previewsView->setChecked(true); break;
 
103
    }
 
104
 
 
105
    // create 'Start with split view' checkbox
 
106
    m_startSplit = new QCheckBox(i18n("Start with split view"), vBox);
 
107
    m_startSplit->setChecked(settings->splitView());
 
108
 
 
109
    // create 'Start with editable navigation bar' checkbox
 
110
    m_startEditable = new QCheckBox(i18n("Start with editable navigation bar"), vBox);
 
111
    m_startEditable->setChecked(settings->editableURL());
 
112
 
 
113
    // Add a dummy widget with no restriction regarding
 
114
    // a vertical resizing. This assures that the dialog layout
 
115
    // is not stretched vertically.
 
116
    new QWidget(vBox);
 
117
 
 
118
    topLayout->addWidget(vBox);
 
119
}
 
120
 
 
121
 
 
122
GeneralSettingsPage::~GeneralSettingsPage()
 
123
{
 
124
}
 
125
 
 
126
void GeneralSettingsPage::applySettings()
 
127
{
 
128
    GeneralSettings* settings = DolphinSettings::instance().generalSettings();
 
129
 
 
130
    const KURL url(m_homeURL->text());
 
131
    KFileItem fileItem(S_IFDIR, KFileItem::Unknown, url);
 
132
    if (url.isValid() && fileItem.isDir()) {
 
133
        settings->setHomeURL(url.prettyURL());
 
134
    }
 
135
 
 
136
    DolphinView::Mode viewMode = DolphinView::IconsView;
 
137
    if (m_detailsView->isChecked()) {
 
138
        viewMode = DolphinView::DetailsView;
 
139
    }
 
140
    else if (m_previewsView->isChecked()) {
 
141
        viewMode = DolphinView::PreviewsView;
 
142
    }
 
143
    settings->setDefaultViewMode(viewMode);
 
144
 
 
145
    settings->setSplitView(m_startSplit->isChecked());
 
146
    settings->setEditableURL(m_startEditable->isChecked());
 
147
}
 
148
 
 
149
void GeneralSettingsPage::selectHomeURL()
 
150
{
 
151
    const QString homeURL(m_homeURL->text());
 
152
    KURL url(KFileDialog::getExistingURL(homeURL));
 
153
    if (!url.isEmpty()) {
 
154
        m_homeURL->setText(url.prettyURL());
 
155
    }
 
156
}
 
157
 
 
158
void GeneralSettingsPage::useCurrentLocation()
 
159
{
 
160
    const DolphinView* view = Dolphin::mainWin().activeView();
 
161
    m_homeURL->setText(view->url().prettyURL());
 
162
}
 
163
 
 
164
void GeneralSettingsPage::useDefaulLocation()
 
165
{
 
166
    m_homeURL->setText("file://" + QDir::homeDirPath());
 
167
}
 
168
 
 
169
#include "generalsettingspage.moc"