~ubuntu-branches/ubuntu/utopic/kdebase/utopic

« back to all changes in this revision

Viewing changes to konqueror/sidebar/history_module/kcmhistory.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Debian Qt/KDE Maintainers, José Manuel Santamaría Lema, Modestas Vainius
  • Date: 2011-05-26 02:53:50 UTC
  • mfrom: (0.7.7 upstream) (0.4.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 296.
  • Revision ID: james.westby@ubuntu.com-20110526025350-7o10g65yegec2rnq
Tags: 4:4.6.3-1
* New upstream release.

[ José Manuel Santamaría Lema ]
* Bump kde-sc-dev-latest build dependency to 4:4.6.3.
* Bump Standards-Version to 3.9.2; no changes needed.

[ Modestas Vainius ]
* Enable DLRestrictions for libraries in this package. Requires
  libdlrestrictions-dev 0.14 and kdelibs5-dev 4:4.6.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  kcmhistory.cpp
 
3
 *  Copyright (c) 2000,2001 Carsten Pfeiffer <pfeiffer@kde.org>
 
4
 *  Copyright (c) 2002 Stephan Binner <binner@kde.org>
 
5
 *
 
6
 *  based on kcmtaskbar.cpp
 
7
 *  Copyright (c) 2000 Kurt Granroth <granroth@kde.org>
 
8
 *
 
9
 *  This program is free software; you can redistribute it and/or modify
 
10
 *  it under the terms of the GNU General Public License as published by
 
11
 *  the Free Software Foundation; either version 2 of the License, or
 
12
 *  (at your option) any later version.
 
13
 *
 
14
 *  This program is distributed in the hope that it will be useful,
 
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 *  GNU General Public License for more details.
 
18
 *
 
19
 *  You should have received a copy of the GNU General Public License
 
20
 *  along with this program; if not, write to the Free Software
 
21
 */
 
22
 
 
23
// Own
 
24
#include "kcmhistory.h"
 
25
 
 
26
// Qt
 
27
#include <QtGui/QCheckBox>
 
28
#include <QtGui/QComboBox>
 
29
#include <QtGui/QLayout>
 
30
#include <QtGui/QPushButton>
 
31
#include <QtGui/QRadioButton>
 
32
 
 
33
// KDE
 
34
#include <kapplication.h>
 
35
#include <kconfig.h>
 
36
#include <kdialog.h>
 
37
#include <kfontdialog.h>
 
38
#include <kglobal.h>
 
39
#include <kicon.h>
 
40
#include <klocale.h>
 
41
#include <kmessagebox.h>
 
42
#include <knuminput.h>
 
43
#include <KPluginFactory>
 
44
#include <KPluginLoader>
 
45
 
 
46
#include <konq_historyprovider.h>
 
47
#include <konqhistorysettings.h>
 
48
 
 
49
// Local
 
50
 
 
51
K_PLUGIN_FACTORY(KCMHistoryFactory,
 
52
        registerPlugin<HistorySidebarConfig>();
 
53
        )
 
54
K_EXPORT_PLUGIN(KCMHistoryFactory("kcmhistory"))
 
55
 
 
56
HistorySidebarConfig::HistorySidebarConfig( QWidget *parent, const QVariantList & )
 
57
    : KCModule (KCMHistoryFactory::componentData(), parent, QVariantList())
 
58
{
 
59
    KGlobal::locale()->insertCatalog("konqueror");
 
60
 
 
61
    m_settings = KonqHistorySettings::self();
 
62
 
 
63
    if (!KParts::HistoryProvider::exists())
 
64
        new KonqHistoryProvider(this);
 
65
 
 
66
    QVBoxLayout *topLayout = new QVBoxLayout(this);
 
67
    dialog = new KonqSidebarHistoryDlg(this);
 
68
 
 
69
    dialog->spinEntries->setRange( 0, INT_MAX );
 
70
    dialog->spinExpire->setRange(  0, INT_MAX );
 
71
    dialog->spinExpire->setSuffix( ki18np(" day", " days") );
 
72
 
 
73
    dialog->spinNewer->setRange( 0, INT_MAX );
 
74
    dialog->spinOlder->setRange( 0, INT_MAX );
 
75
 
 
76
    dialog->comboNewer->insertItem( KonqHistorySettings::MINUTES,
 
77
                                    i18np("Minute", "Minutes", 0) );
 
78
    dialog->comboNewer->insertItem( KonqHistorySettings::DAYS,
 
79
                                    i18np("Day", "Days", 0) );
 
80
 
 
81
    dialog->comboOlder->insertItem( KonqHistorySettings::MINUTES,
 
82
                                    i18np("Minute", "Minutes", 0) );
 
83
    dialog->comboOlder->insertItem( KonqHistorySettings::DAYS,
 
84
                                    i18np("Day", "Days", 0) );
 
85
 
 
86
    connect( dialog->cbExpire, SIGNAL( toggled( bool )),
 
87
             dialog->spinExpire, SLOT( setEnabled( bool )));
 
88
    connect( dialog->spinExpire, SIGNAL( valueChanged( int )),
 
89
             this, SLOT( slotExpireChanged()));
 
90
 
 
91
    connect( dialog->spinNewer, SIGNAL( valueChanged( int )),
 
92
             SLOT( slotNewerChanged( int )));
 
93
    connect( dialog->spinOlder, SIGNAL( valueChanged( int )),
 
94
             SLOT( slotOlderChanged( int )));
 
95
 
 
96
    connect( dialog->btnFontNewer, SIGNAL( clicked() ),
 
97
             SLOT( slotGetFontNewer() ));
 
98
    connect( dialog->btnFontOlder, SIGNAL( clicked() ),
 
99
             SLOT( slotGetFontOlder() ));
 
100
    connect( dialog->btnClearHistory, SIGNAL( clicked() ),
 
101
             SLOT( slotClearHistory() ));
 
102
 
 
103
    connect( dialog->cbDetailedTips, SIGNAL( toggled( bool )),
 
104
             SLOT( configChanged() ));
 
105
    connect( dialog->cbExpire, SIGNAL( toggled( bool )),
 
106
             SLOT( configChanged() ));
 
107
    connect( dialog->spinEntries, SIGNAL( valueChanged( int )),
 
108
             SLOT( configChanged() ));
 
109
    connect( dialog->comboNewer, SIGNAL( currentIndexChanged( int )),
 
110
             SLOT( configChanged() ));
 
111
    connect( dialog->comboOlder, SIGNAL( currentIndexChanged( int )),
 
112
             SLOT( configChanged() ));
 
113
 
 
114
    dialog->show();
 
115
    topLayout->addWidget(dialog);
 
116
    load();
 
117
}
 
118
 
 
119
void HistorySidebarConfig::configChanged()
 
120
{
 
121
    emit changed(true);
 
122
}
 
123
 
 
124
void HistorySidebarConfig::load()
 
125
{
 
126
    KConfig _config( "konquerorrc" );
 
127
    KConfigGroup config(&_config, "HistorySettings");
 
128
    dialog->spinExpire->setValue( config.readEntry( "Maximum age of History entries", 90) );
 
129
    dialog->spinEntries->setValue( config.readEntry( "Maximum of History entries", 500 ) );
 
130
    dialog->cbExpire->setChecked( dialog->spinExpire->value() > 0 );
 
131
 
 
132
    dialog->spinNewer->setValue( m_settings->m_valueYoungerThan );
 
133
    dialog->spinOlder->setValue( m_settings->m_valueOlderThan );
 
134
 
 
135
    dialog->comboNewer->setCurrentIndex( m_settings->m_metricYoungerThan );
 
136
    dialog->comboOlder->setCurrentIndex( m_settings->m_metricOlderThan );
 
137
 
 
138
    dialog->cbDetailedTips->setChecked( m_settings->m_detailedTips );
 
139
 
 
140
    m_fontNewer = m_settings->m_fontYoungerThan;
 
141
    m_fontOlder = m_settings->m_fontOlderThan;
 
142
 
 
143
    // enable/disable widgets
 
144
    dialog->spinExpire->setEnabled( dialog->cbExpire->isChecked() );
 
145
 
 
146
    slotExpireChanged();
 
147
    slotNewerChanged( dialog->spinNewer->value() );
 
148
    slotOlderChanged( dialog->spinOlder->value() );
 
149
 
 
150
    emit changed(false);
 
151
}
 
152
 
 
153
void HistorySidebarConfig::save()
 
154
{
 
155
    quint32 age   = dialog->cbExpire->isChecked() ? dialog->spinExpire->value() : 0;
 
156
    quint32 count = dialog->spinEntries->value();
 
157
 
 
158
    KonqHistoryProvider::self()->emitSetMaxAge( age );
 
159
    KonqHistoryProvider::self()->emitSetMaxCount( count );
 
160
 
 
161
    m_settings->m_valueYoungerThan = dialog->spinNewer->value();
 
162
    m_settings->m_valueOlderThan   = dialog->spinOlder->value();
 
163
 
 
164
    m_settings->m_metricYoungerThan = dialog->comboNewer->currentIndex();
 
165
    m_settings->m_metricOlderThan   = dialog->comboOlder->currentIndex();
 
166
 
 
167
    m_settings->m_detailedTips = dialog->cbDetailedTips->isChecked();
 
168
 
 
169
    m_settings->m_fontYoungerThan = m_fontNewer;
 
170
    m_settings->m_fontOlderThan   = m_fontOlder;
 
171
 
 
172
    m_settings->applySettings();
 
173
 
 
174
    emit changed(false);
 
175
}
 
176
 
 
177
void HistorySidebarConfig::defaults()
 
178
{
 
179
    dialog->spinEntries->setValue( 500 );
 
180
    dialog->cbExpire->setChecked( true );
 
181
    dialog->spinExpire->setValue( 90 );
 
182
 
 
183
    dialog->spinNewer->setValue( 1 );
 
184
    dialog->spinOlder->setValue( 2 );
 
185
 
 
186
    dialog->comboNewer->setCurrentIndex( KonqHistorySettings::DAYS );
 
187
    dialog->comboOlder->setCurrentIndex( KonqHistorySettings::DAYS );
 
188
 
 
189
    dialog->cbDetailedTips->setChecked( true );
 
190
 
 
191
    m_fontNewer = QFont();
 
192
    m_fontNewer.setItalic( true );
 
193
    m_fontOlder = QFont();
 
194
}
 
195
 
 
196
QString HistorySidebarConfig::quickHelp() const
 
197
{
 
198
    return i18n("<h1>History Sidebar</h1>"
 
199
                " You can configure the history sidebar here.");
 
200
}
 
201
 
 
202
void HistorySidebarConfig::slotExpireChanged()
 
203
{
 
204
    configChanged();
 
205
}
 
206
 
 
207
// change hour to days, minute to minutes and the other way round,
 
208
// depending on the value of the spinbox, and synchronize the two spinBoxes
 
209
// to enfore newer <= older.
 
210
void HistorySidebarConfig::slotNewerChanged( int value )
 
211
{
 
212
    dialog->comboNewer->setItemText( KonqHistorySettings::DAYS,
 
213
                                     i18np ( "Day", "Days", value) );
 
214
    dialog->comboNewer->setItemText( KonqHistorySettings::MINUTES,
 
215
                                     i18np ( "Minute", "Minutes", value) );
 
216
 
 
217
    if ( dialog->spinNewer->value() > dialog->spinOlder->value() )
 
218
        dialog->spinOlder->setValue( dialog->spinNewer->value() );
 
219
    configChanged();
 
220
}
 
221
 
 
222
void HistorySidebarConfig::slotOlderChanged( int value )
 
223
{
 
224
    dialog->comboOlder->setItemText( KonqHistorySettings::DAYS,
 
225
                                     i18np ( "Day", "Days", value) );
 
226
    dialog->comboOlder->setItemText( KonqHistorySettings::MINUTES,
 
227
                                     i18np ( "Minute", "Minutes", value) );
 
228
 
 
229
    if ( dialog->spinNewer->value() > dialog->spinOlder->value() )
 
230
        dialog->spinNewer->setValue( dialog->spinOlder->value() );
 
231
 
 
232
    configChanged();
 
233
}
 
234
 
 
235
void HistorySidebarConfig::slotGetFontNewer()
 
236
{
 
237
    int result = KFontDialog::getFont( m_fontNewer, false, this );
 
238
    if ( result == KFontDialog::Accepted )
 
239
        configChanged();
 
240
}
 
241
 
 
242
void HistorySidebarConfig::slotGetFontOlder()
 
243
{
 
244
    int result = KFontDialog::getFont( m_fontOlder, false, this );
 
245
    if ( result == KFontDialog::Accepted )
 
246
        configChanged();
 
247
}
 
248
 
 
249
void HistorySidebarConfig::slotClearHistory()
 
250
{
 
251
    KGuiItem guiitem = KStandardGuiItem::clear();
 
252
    guiitem.setIcon( KIcon("edit-clear-history"));
 
253
    if ( KMessageBox::warningContinueCancel( this,
 
254
                                     i18n("Do you really want to clear "
 
255
                                          "the entire history?"),
 
256
                                     i18n("Clear History?"), guiitem )
 
257
         == KMessageBox::Continue ) {
 
258
        KonqHistoryProvider::self()->emitClear();
 
259
    }
 
260
}
 
261
 
 
262
#include "kcmhistory.moc"