Fix crash if key bindings specified in profile cannot be found. Improve
[personal-kdebase.git] / apps / konqueror / settings / konqhtml / htmlopts.cpp
blob54224e6f879636a990cfb55de415126e47645c03
1 /*
2 * "Misc Options" Tab for KFM configuration
4 * Copyright (C) Sven Radej 1998
5 * Copyright (C) David Faure 1998
6 * Copyright (C) 2001 Waldo Bastian <bastian@kde.org>
8 */
10 // Own
11 #include "htmlopts.h"
13 // Qt
14 #include <QtGui/QGroupBox>
15 #include <QtGui/QFormLayout>
16 #include <QtGui/QLabel>
17 #include <QtGui/QPushButton>
18 #include <QtDBus/QDBusMessage>
19 #include <QtDBus/QDBusConnection>
21 // KDE
22 #include <kglobalsettings.h> // get default for DEFAULT_CHANGECURSOR
23 #include <klocale.h>
24 #include <kdialog.h>
25 #include <knuminput.h>
26 #include <kseparator.h>
27 #include <kapplication.h>
29 // Local
30 #include "khtml_settings.h"
31 #include <KPluginFactory>
32 #include <KPluginLoader>
34 K_PLUGIN_FACTORY_DECLARATION(KcmKonqHtmlFactory)
36 //-----------------------------------------------------------------------------
38 KMiscHTMLOptions::KMiscHTMLOptions(QWidget *parent, const QVariantList&)
39 : KCModule( KcmKonqHtmlFactory::componentData(), parent ), m_groupname("HTML Settings")
41 m_pConfig = KSharedConfig::openConfig("konquerorrc", KConfig::NoGlobals);
42 int row = 0;
43 QVBoxLayout *lay = new QVBoxLayout(this);
45 // Bookmarks
46 setQuickHelp( i18n("<h1>Konqueror Browser</h1> Here you can configure Konqueror's browser "
47 "functionality. Please note that the file manager "
48 "functionality has to be configured using the \"File Manager\" "
49 "configuration module. You can make some "
50 "settings how Konqueror should handle the HTML code in "
51 "the web pages it loads. It is usually not necessary to "
52 "change anything here."));
54 QGroupBox *bgBookmarks = new QGroupBox( i18n("Boo&kmarks"));
55 QVBoxLayout *laygroup1 = new QVBoxLayout;
57 laygroup1->setSpacing(KDialog::spacingHint());
59 m_pAdvancedAddBookmarkCheckBox = new QCheckBox(i18n( "Ask for name and folder when adding bookmarks" ));
60 laygroup1->addWidget(m_pAdvancedAddBookmarkCheckBox);
62 m_pAdvancedAddBookmarkCheckBox->setWhatsThis( i18n( "If this box is checked, Konqueror will allow you to"
63 " change the title of the bookmark and choose a folder"
64 " in which to store it when you add a new bookmark." ) );
65 connect(m_pAdvancedAddBookmarkCheckBox, SIGNAL(toggled(bool)), SLOT(changed()));
66 bgBookmarks->setLayout(laygroup1);
68 m_pOnlyMarkedBookmarksCheckBox = new QCheckBox(i18n( "Show only marked bookmarks in bookmark toolbar" ), bgBookmarks);
69 laygroup1->addWidget(m_pOnlyMarkedBookmarksCheckBox);
70 m_pOnlyMarkedBookmarksCheckBox->setWhatsThis( i18n( "If this box is checked, Konqueror will show only those"
71 " bookmarks in the bookmark toolbar which you have marked to do so in the bookmark editor." ) );
72 connect(m_pOnlyMarkedBookmarksCheckBox, SIGNAL(toggled(bool)), SLOT(changed()));
74 lay->addWidget( bgBookmarks);
76 // Form completion
77 m_pFormCompletionCheckBox = new QGroupBox( i18n("Form Com&pletion"), this );
78 m_pFormCompletionCheckBox->setCheckable(true);
79 QFormLayout *laygroup2 = new QFormLayout(m_pFormCompletionCheckBox);
80 laygroup2->setSpacing(KDialog::spacingHint());
82 m_pFormCompletionCheckBox->setWhatsThis( i18n( "If this box is checked, Konqueror will remember"
83 " the data you enter in web forms and suggest it in similar fields for all forms." ) );
84 connect(m_pFormCompletionCheckBox, SIGNAL(triggered(bool)), SLOT(changed()));
86 m_pMaxFormCompletionItems = new KIntNumInput(this);
87 m_pMaxFormCompletionItems->setRange( 0, 100 );
88 laygroup2->addRow(i18n( "&Maximum completions:" ), m_pMaxFormCompletionItems );
89 m_pMaxFormCompletionItems->setWhatsThis(
90 i18n( "Here you can select how many values Konqueror will remember for a form field." ) );
91 connect(m_pMaxFormCompletionItems, SIGNAL(valueChanged(int)), SLOT(changed()));
92 connect(m_pFormCompletionCheckBox, SIGNAL(toggled(bool)), m_pMaxFormCompletionItems, SLOT(setEnabled(bool)));
94 lay->addWidget( m_pFormCompletionCheckBox);
96 // Mouse behavior
97 QGroupBox *bgMouse = new QGroupBox( i18n("Mouse Beha&vior") );
98 QVBoxLayout *laygroup3 = new QVBoxLayout(bgMouse);
99 laygroup3->setSpacing(KDialog::spacingHint());
101 m_cbCursor = new QCheckBox(i18n("Chan&ge cursor over links") );
102 laygroup3->addWidget( m_cbCursor );
103 m_cbCursor->setWhatsThis( i18n("If this option is set, the shape of the cursor will change "
104 "(usually to a hand) if it is moved over a hyperlink.") );
105 connect(m_cbCursor, SIGNAL(toggled(bool)), SLOT(changed()));
107 m_pOpenMiddleClick = new QCheckBox( i18n ("M&iddle click opens URL in selection" ), bgMouse);
108 laygroup3->addWidget( m_pOpenMiddleClick );
109 m_pOpenMiddleClick->setWhatsThis( i18n (
110 "If this box is checked, you can open the URL in the selection by middle clicking on a "
111 "Konqueror view." ) );
112 connect(m_pOpenMiddleClick, SIGNAL(toggled(bool)), SLOT(changed()));
114 m_pBackRightClick = new QCheckBox( i18n( "Right click goes &back in history" ),bgMouse);
115 laygroup3->addWidget( m_pBackRightClick );
116 m_pBackRightClick->setWhatsThis( i18n(
117 "If this box is checked, you can go back in history by right clicking on a Konqueror view. "
118 "To access the context menu, press the right mouse button and move." ) );
119 connect(m_pBackRightClick, SIGNAL(toggled(bool)), SLOT(changed()));
121 lay->addWidget( bgMouse);
123 // Misc
124 QGroupBox *bgMisc = new QGroupBox( i18nc("@title:group","Miscellaneous"));
125 QFormLayout *fl=new QFormLayout(bgMisc);
128 m_pAutoRedirectCheckBox = new QCheckBox( i18n( "Allow automatic delayed &reloading/redirecting"), this );
129 m_pAutoRedirectCheckBox->setWhatsThis( i18n( "Some web pages request an automatic reload or redirection after"
130 " a certain period of time. By unchecking this box Konqueror will ignore these requests." ) );
131 connect(m_pAutoRedirectCheckBox, SIGNAL(toggled(bool)), SLOT(changed()));
132 fl->addRow( m_pAutoRedirectCheckBox );
134 lay->addWidget( bgMisc);
136 // Checkbox to enable/disable Access Key activation through the Ctrl key.
137 m_pAccessKeys = new QCheckBox( i18n( "Enable/disable Access Ke&y activation with Ctrl key"), this );//TODO remove Enable/disable part
138 m_pAccessKeys->setWhatsThis( i18n( "Pressing the Ctrl key when viewing webpages activates KDE's Access Keys. Unchecking this box will disable this accessibility feature. (Konqueror needs to be restarted for changes to take effect.)" ) );
139 connect(m_pAccessKeys, SIGNAL(toggled(bool)), SLOT(changed()));
140 fl->addRow( m_pAccessKeys);
142 lay->addStretch(5);
144 emit changed(false);
147 KMiscHTMLOptions::~KMiscHTMLOptions()
151 void KMiscHTMLOptions::load()
153 KConfigGroup khtmlrc(KSharedConfig::openConfig("khtmlrc", KConfig::NoGlobals), "");
154 KConfigGroup cg(m_pConfig, "");
155 #define SET_GROUP(x) cg = KConfigGroup(m_pConfig, x); khtmlrc = KConfigGroup(KSharedConfig::openConfig("khtmlrc", KConfig::NoGlobals),x)
156 #define READ_BOOL(x,y) cg.readEntry(x, khtmlrc.readEntry(x, y))
157 #define READ_ENTRY(x) cg.readEntry(x, khtmlrc.readEntry(x))
160 // *** load ***
161 SET_GROUP( "MainView Settings" );
162 bool bOpenMiddleClick = READ_BOOL( "OpenMiddleClick", true );
163 bool bBackRightClick = READ_BOOL( "BackRightClick", false );
164 SET_GROUP( "HTML Settings" );
165 bool changeCursor = READ_BOOL("ChangeCursor", KDE_DEFAULT_CHANGECURSOR);
166 bool bAutoRedirect = cg.readEntry( "AutoDelayedActions", true );
168 // *** apply to GUI ***
169 m_cbCursor->setChecked( changeCursor );
170 m_pAutoRedirectCheckBox->setChecked( bAutoRedirect );
171 m_pOpenMiddleClick->setChecked( bOpenMiddleClick );
172 m_pBackRightClick->setChecked( bBackRightClick );
174 m_pFormCompletionCheckBox->setChecked( cg.readEntry( "FormCompletion", true ) );
175 m_pMaxFormCompletionItems->setValue( cg.readEntry( "MaxFormCompletionItems", 10 ) );
176 m_pMaxFormCompletionItems->setEnabled( m_pFormCompletionCheckBox->isChecked() );
178 // Reads in the value of m_accessKeysEnabled by calling accessKeysEnabled() in khtml_settings.cpp
179 KHTMLSettings settings;
180 m_pAccessKeys->setChecked( settings.accessKeysEnabled() );
182 KConfigGroup config(KSharedConfig::openConfig("kbookmarkrc", KConfig::NoGlobals), "Bookmarks");
183 m_pAdvancedAddBookmarkCheckBox->setChecked( config.readEntry("AdvancedAddBookmarkDialog", false) );
184 m_pOnlyMarkedBookmarksCheckBox->setChecked( config.readEntry("FilteredToolbar", false) );
187 void KMiscHTMLOptions::defaults()
189 bool old = m_pConfig->readDefaults();
190 m_pConfig->setReadDefaults(true);
191 load();
192 m_pConfig->setReadDefaults(old);
193 m_pAdvancedAddBookmarkCheckBox->setChecked(false);
194 m_pOnlyMarkedBookmarksCheckBox->setChecked(false);
197 void KMiscHTMLOptions::save()
199 KConfigGroup cg(m_pConfig, "MainView Settings");
200 cg.writeEntry( "OpenMiddleClick", m_pOpenMiddleClick->isChecked() );
201 cg.writeEntry( "BackRightClick", m_pBackRightClick->isChecked() );
202 cg = KConfigGroup(m_pConfig, "HTML Settings" );
203 cg.writeEntry( "ChangeCursor", m_cbCursor->isChecked() );
204 cg.writeEntry( "AutoDelayedActions", m_pAutoRedirectCheckBox->isChecked() );
205 cg.writeEntry( "FormCompletion", m_pFormCompletionCheckBox->isChecked() );
206 cg.writeEntry( "MaxFormCompletionItems", m_pMaxFormCompletionItems->value() );
208 cg.sync();
210 // Writes the value of m_pAccessKeys into khtmlrc to affect all applications using KHTML
211 KConfig _khtmlconfig("khtmlrc", KConfig::NoGlobals);
212 KConfigGroup khtmlconfig(&_khtmlconfig, "Access Keys");
213 khtmlconfig.writeEntry( "Enabled", m_pAccessKeys->isChecked() );
214 khtmlconfig.sync();
216 KConfigGroup config(KSharedConfig::openConfig("kbookmarkrc", KConfig::NoGlobals), "Bookmarks");
217 config.writeEntry("AdvancedAddBookmarkDialog", m_pAdvancedAddBookmarkCheckBox->isChecked());
218 config.writeEntry("FilteredToolbar", m_pOnlyMarkedBookmarksCheckBox->isChecked());
219 config.sync();
220 // Send signal to all konqueror instances
221 QDBusMessage message =
222 QDBusMessage::createSignal("/KonqMain", "org.kde.Konqueror.Main", "reparseConfiguration");
223 QDBusConnection::sessionBus().send(message);
225 message = QDBusMessage::createSignal("/KBookmarkManager/konqueror", "org.kde.KIO.KBookmarkManager", "bookmarkConfigChanged" );
226 QDBusConnection::sessionBus().send(message);
228 emit changed(false);
232 #include "htmlopts.moc"