Fix crash if key bindings specified in profile cannot be found. Improve
[personal-kdebase.git] / apps / konqueror / settings / performance / konqueror.cpp
blob4ca7e847fd874009ad1846d99918807c73e1f98f
1 /*
2 * Copyright (c) 2003 Lubos Lunak <l.lunak@kde.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include "konqueror.h"
21 #include <kconfig.h>
22 #include <QtDBus/QtDBus>
23 #include <QtGui/QRadioButton>
24 #include <QtGui/QSpinBox>
25 #include <QtGui/QLabel>
26 #include <QtGui/QCheckBox>
27 #include <klocale.h>
29 namespace KCMPerformance
32 Konqueror::Konqueror( QWidget* parent_P )
33 : Konqueror_ui( parent_P )
35 rb_never_reuse->setWhatsThis(
36 i18n( "Disables the minimization of memory usage and allows you "
37 "to make each browsing activity independent from the others" ));
38 rb_file_browsing_reuse->setWhatsThis(
39 i18n( "<p>With this option activated, only one instance of Konqueror "
40 "used for file browsing will exist in the memory of your computer "
41 "at any moment, "
42 "no matter how many file browsing windows you open, "
43 "thus reducing resource requirements.</p>"
44 "<p>Be aware that this also means that, if something goes wrong, "
45 "all your file browsing windows will be closed simultaneously</p>" ));
46 rb_always_reuse->setWhatsThis(
47 i18n( "<p>With this option activated, only one instance of Konqueror "
48 "will exist in the memory of your computer at any moment, "
49 "no matter how many browsing windows you open, "
50 "thus reducing resource requirements.</p>"
51 "<p>Be aware that this also means that, if something goes wrong, "
52 "all your browsing windows will be closed simultaneously.</p>" ));
53 connect( rb_never_reuse, SIGNAL( toggled(bool)), SIGNAL( changed()));
54 connect( rb_file_browsing_reuse, SIGNAL( toggled(bool)), SIGNAL( changed()));
55 connect( rb_always_reuse, SIGNAL( toggled(bool)), SIGNAL( changed()));
56 rb_file_browsing_reuse->setChecked( true );
58 QString tmp =
59 i18n( "<p>If non-zero, this option allows keeping Konqueror instances "
60 "in memory after all their windows have been closed, up to the "
61 "number specified in this option.</p>"
62 "<p>When a new Konqueror instance is needed, one of these preloaded "
63 "instances will be reused instead, improving responsiveness at "
64 "the expense of the memory required by the preloaded instances.</p>" );
65 sb_preload_count->setWhatsThis( tmp );
66 lb_preload_count->setWhatsThis( tmp );
67 cb_preload_on_startup->setWhatsThis(
68 i18n( "<p>If enabled, an instance of Konqueror will be preloaded after the ordinary KDE "
69 "startup sequence.</p>"
70 "<p>This will make the first Konqueror window open faster, but "
71 "at the expense of longer KDE startup times (but you will be able to work "
72 "while it is loading, so you may not even notice that it is taking longer).</p>" ));
73 cb_always_have_preloaded->setWhatsThis(
74 i18n( "<p>If enabled, KDE will always try to have one preloaded Konqueror instance ready; "
75 "preloading a new instance in the background whenever there is not one available, "
76 "so that windows will always open quickly.</p>"
77 "<p><b>Warning:</b> In some cases, it is actually possible that this will "
78 "reduce perceived performance.</p>" ));
79 connect( sb_preload_count, SIGNAL( valueChanged( int )), SLOT( preload_count_changed( int )));
80 connect( sb_preload_count, SIGNAL( valueChanged( int )), SIGNAL( changed()));
81 connect( cb_preload_on_startup, SIGNAL( toggled(bool)), SIGNAL( changed()));
82 connect( cb_always_have_preloaded, SIGNAL( toggled(bool)), SIGNAL( changed()));
83 defaults();
86 void Konqueror::preload_count_changed( int count )
88 cb_preload_on_startup->setEnabled( count >= 1 );
89 // forcing preloading with count == 1 can often do more harm than good, because
90 // if there's one konqy preloaded, and the user requests "starting" new konqueror,
91 // the preloaded instance will be used, new one will be preloaded, and if the user soon
92 // "quits" konqueror, one of the instances will have to be terminated
93 cb_always_have_preloaded->setEnabled( count >= 2 );
96 void Konqueror::load()
98 KConfig _cfg( "konquerorrc" );
99 KConfigGroup cfg(&_cfg, "Reusing" );
100 allowed_parts = cfg.readEntry( "SafeParts", "SAFE" );
101 if( allowed_parts == "ALL" )
102 rb_always_reuse->setChecked( true );
103 else if( allowed_parts.isEmpty())
104 rb_never_reuse->setChecked( true );
105 else
106 rb_file_browsing_reuse->setChecked( true );
107 sb_preload_count->setValue( cfg.readEntry( "MaxPreloadCount", 1 ));
108 cb_always_have_preloaded->setChecked( cfg.readEntry( "AlwaysHavePreloaded", false));
109 cb_preload_on_startup->setChecked( cfg.readEntry( "PreloadOnStartup", false));
112 void Konqueror::save()
114 KConfig _cfg( "konquerorrc" );
115 KConfigGroup cfg(&_cfg, "Reusing" );
116 if( rb_always_reuse->isChecked())
117 allowed_parts = "ALL";
118 else if( rb_never_reuse->isChecked())
119 allowed_parts = "";
120 else
122 if( allowed_parts.isEmpty() || allowed_parts == "ALL" )
123 allowed_parts = "SAFE";
124 // else - keep allowed_parts as read from the file, as the user may have modified the list there
126 cfg.writeEntry( "SafeParts", allowed_parts );
127 int count = sb_preload_count->value();
128 cfg.writeEntry( "MaxPreloadCount", count );
129 cfg.writeEntry( "PreloadOnStartup", cb_preload_on_startup->isChecked() && count >= 1 );
130 cfg.writeEntry( "AlwaysHavePreloaded", cb_always_have_preloaded->isChecked() && count >= 2 );
131 cfg.sync();
132 QDBusMessage message =
133 QDBusMessage::createSignal("/KonqMain", "org.kde.Konqueror.Main", "reparseConfiguration");
134 QDBusConnection::sessionBus().send(message);
136 QDBusInterface kded("org.kde.kded", "/modules/konqy_preloader", "org.kde.konqueror.Preloader");
137 kded.call( "reconfigure" );
140 void Konqueror::defaults()
142 rb_file_browsing_reuse->setChecked( true );
143 allowed_parts = "SAFE";
144 sb_preload_count->setValue( 1 );
145 cb_preload_on_startup->setChecked( false );
146 cb_always_have_preloaded->setChecked( false );
147 preload_count_changed( sb_preload_count->value());
150 } // namespace
152 #include "konqueror.moc"