summaryrefslogtreecommitdiffstats
path: root/kcontrol/konqhtml/htmlopts.cpp
blob: ed87ea349d53fa8adf9cd22947eed2135461057b (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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
////
// "Misc Options" Tab for KFM configuration
//
// (c) Sven Radej 1998
// (c) David Faure 1998
// (c) 2001 Waldo Bastian <bastian@kde.org>
//

#include <tqlayout.h>//CT - 12Nov1998
#include <tqwhatsthis.h>
#include <tqvgroupbox.h>
#include <tqlabel.h>
#include <tqpushbutton.h>

#include "htmlopts.h"

#include <konq_defaults.h> // include default values directly from konqueror
#include <tdeglobalsettings.h> // get default for DEFAULT_CHANGECURSOR
#include <tdelocale.h>
#include <kdialog.h>
#include <knuminput.h>
#include <kseparator.h>

#include <tdeapplication.h>
#include <dcopclient.h>


#include "htmlopts.moc"

enum UnderlineLinkType { UnderlineAlways=0, UnderlineNever=1, UnderlineHover=2 };
enum AnimationsType { AnimationsAlways=0, AnimationsNever=1, AnimationsLoopOnce=2 };
enum SmoothScrollingType { SmoothScrollingAlways=0, SmoothScrollingNever=1, SmoothScrollingWhenEfficient=2 };
//-----------------------------------------------------------------------------

KMiscHTMLOptions::KMiscHTMLOptions(TDEConfig *config, TQString group, TQWidget *parent, const char *)
    : TDECModule( parent, "kcmkonqhtml" ), m_pConfig(config), m_groupname(group)
{
    int row = 0;
    TQGridLayout *lay = new TQGridLayout(this, 10, 2, 0, KDialog::spacingHint());

    // Bookmarks
    setQuickHelp( i18n("<h1>Konqueror Browser</h1> Here you can configure Konqueror's browser "
              "functionality. Please note that the file manager "
              "functionality has to be configured using the \"File Manager\" "
              "configuration module. You can make some "
              "settings how Konqueror should handle the HTML code in "
              "the web pages it loads. It is usually not necessary to "
              "change anything here."));

    TQVGroupBox *bgBookmarks = new TQVGroupBox( i18n("Boo&kmarks"), this );
    m_pAdvancedAddBookmarkCheckBox = new TQCheckBox(i18n( "Ask for name and folder when adding bookmarks" ), bgBookmarks);
    TQWhatsThis::add( m_pAdvancedAddBookmarkCheckBox, i18n( "If this box is checked, Konqueror will allow you to"
                                                        " change the title of the bookmark and choose a folder in which to store it when you add a new bookmark." ) );
    connect(m_pAdvancedAddBookmarkCheckBox, TQT_SIGNAL(clicked()), TQT_SLOT(slotChanged()));

    m_pOnlyMarkedBookmarksCheckBox = new TQCheckBox(i18n( "Show only marked bookmarks in bookmark toolbar" ), bgBookmarks);
    TQWhatsThis::add( m_pOnlyMarkedBookmarksCheckBox, i18n( "If this box is checked, Konqueror will show only those"
                                                         " bookmarks in the bookmark toolbar which you have marked to do so in the bookmark editor." ) );
    connect(m_pOnlyMarkedBookmarksCheckBox, TQT_SIGNAL(clicked()), TQT_SLOT(slotChanged()));

    lay->addMultiCellWidget( bgBookmarks, row, row, 0, 1 );
    row++;

     // Form completion

    TQVGroupBox *bgForm = new TQVGroupBox( i18n("Form Com&pletion"), this );
    m_pFormCompletionCheckBox = new TQCheckBox(i18n( "Enable com&pletion of forms" ), bgForm);
    TQWhatsThis::add( m_pFormCompletionCheckBox, i18n( "If this box is checked, Konqueror will remember"
                                                        " the data you enter in web forms and suggest it in similar fields for all forms." ) );
    connect(m_pFormCompletionCheckBox, TQT_SIGNAL(clicked()), TQT_SLOT(slotChanged()));

    m_pMaxFormCompletionItems = new KIntNumInput( bgForm );
    m_pMaxFormCompletionItems->setLabel( i18n( "&Maximum completions:" ) );
    m_pMaxFormCompletionItems->setRange( 0, 100 );
    TQWhatsThis::add( m_pMaxFormCompletionItems,
        i18n( "Here you can select how many values Konqueror will remember for a form field." ) );
    connect(m_pMaxFormCompletionItems, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(slotChanged()));

    lay->addMultiCellWidget( bgForm, row, row, 0, 1 );
    row++;

    // Mouse behavior

    TQVGroupBox *bgMouse = new TQVGroupBox( i18n("Mouse Beha&vior"), this );

    m_cbCursor = new TQCheckBox(i18n("Chan&ge cursor over links"), bgMouse );
    TQWhatsThis::add( m_cbCursor, i18n("If this option is set, the shape of the cursor will change "
       "(usually to a hand) if it is moved over a hyperlink.") );
    connect(m_cbCursor, TQT_SIGNAL(clicked()), TQT_SLOT(slotChanged()));

    m_pOpenMiddleClick = new TQCheckBox( i18n ("M&iddle click opens URL in selection" ), bgMouse );
    TQWhatsThis::add( m_pOpenMiddleClick, i18n (
      "If this box is checked, you can open the URL in the selection by middle clicking on a "
      "Konqueror view." ) );
    connect(m_pOpenMiddleClick, TQT_SIGNAL(clicked()), TQT_SLOT(slotChanged()));

    m_pBackRightClick = new TQCheckBox( i18n( "Right click goes &back in history" ), bgMouse );
    TQWhatsThis::add( m_pBackRightClick, i18n(
      "If this box is checked, you can go back in history by right clicking on a Konqueror view. "
      "To access the context menu, press the right mouse button and move." ) );
    connect(m_pBackRightClick, TQT_SIGNAL(clicked()), TQT_SLOT(slotChanged()));

    lay->addMultiCellWidget( bgMouse, row, row, 0, 1 );
    row++;

    // Misc

    m_pAutoLoadImagesCheckBox = new TQCheckBox( i18n( "A&utomatically load images"), this );
    TQWhatsThis::add( m_pAutoLoadImagesCheckBox, i18n( "If this box is checked, Konqueror will automatically load any images that are embedded in a web page. Otherwise, it will display placeholders for the images, and you can then manually load the images by clicking on the image button.<br>Unless you have a very slow network connection, you will probably want to check this box to enhance your browsing experience." ) );
    connect(m_pAutoLoadImagesCheckBox, TQT_SIGNAL(clicked()), TQT_SLOT(slotChanged()));
    lay->addMultiCellWidget( m_pAutoLoadImagesCheckBox, row, row, 0, 1 );
    row++;

    m_pEnableFavIconCheckBox = new TQCheckBox( i18n( "Enable &favicons"), this );
    TQWhatsThis::add( m_pEnableFavIconCheckBox, i18n( "If this box is checked, Konqueror will automatically load and display favicon images that are associated with a web page. These images appear in the Location bar. Otherwise a generic image will appear." ) );
    connect(m_pEnableFavIconCheckBox, TQT_SIGNAL(clicked()), TQT_SLOT(slotChanged()));
    lay->addMultiCellWidget( m_pEnableFavIconCheckBox, row, row, 0, 1 );
    row++;

    m_pUnfinishedImageFrameCheckBox = new TQCheckBox( i18n( "Dra&w frame around not completely loaded images"), this );
    TQWhatsThis::add( m_pUnfinishedImageFrameCheckBox, i18n( "If this box is checked, Konqueror will draw a frame as placeholder around not yet fully loaded images that are embedded in a web page.<br>Especially if you have a slow network connection, you will probably want to check this box to enhance your browsing experience." ) );
    connect(m_pUnfinishedImageFrameCheckBox, TQT_SIGNAL(clicked()), TQT_SLOT(slotChanged()));
    lay->addMultiCellWidget( m_pUnfinishedImageFrameCheckBox, row, row, 0, 1 );
    row++;

    m_pAutoRedirectCheckBox = new TQCheckBox( i18n( "Allow automatic delayed &reloading/redirecting"), this );
    TQWhatsThis::add( m_pAutoRedirectCheckBox,
    i18n( "Some web pages request an automatic reload or redirection after a certain period of time. By unchecking this box Konqueror will ignore these requests." ) );
    connect(m_pAutoRedirectCheckBox, TQT_SIGNAL(clicked()), TQT_SLOT(slotChanged()));
    lay->addMultiCellWidget( m_pAutoRedirectCheckBox, row, row, 0, 1 );
    row++;


    // More misc

    KSeparator *sep = new KSeparator(this);
    lay->addMultiCellWidget(sep, row, row, 0, 1);
    row++;

    TQLabel *label = new TQLabel( i18n("Und&erline links:"), this);
    m_pUnderlineCombo = new TQComboBox( false, this );
    label->setBuddy(m_pUnderlineCombo);
    m_pUnderlineCombo->insertItem(i18n("underline","Enabled"), UnderlineAlways);
    m_pUnderlineCombo->insertItem(i18n("underline","Disabled"), UnderlineNever);
    m_pUnderlineCombo->insertItem(i18n("Only on Hover"), UnderlineHover);
    lay->addWidget(label, row, 0);
    lay->addWidget(m_pUnderlineCombo, row, 1);
    row++;
    TQString whatsThis = i18n("Controls how Konqueror handles underlining hyperlinks:<br>"
	    "<ul><li><b>Enabled</b>: Always underline links</li>"
	    "<li><b>Disabled</b>: Never underline links</li>"
	    "<li><b>Only on Hover</b>: Underline when the mouse is moved over the link</li>"
	    "</ul><br><i>Note: The site's CSS definitions can override this value</i>");
    TQWhatsThis::add( label, whatsThis);
    TQWhatsThis::add( m_pUnderlineCombo, whatsThis);
    connect(m_pUnderlineCombo, TQT_SIGNAL(activated(int)), TQT_SLOT(slotChanged()));



    label = new TQLabel( i18n("A&nimations:"), this);
    m_pAnimationsCombo = new TQComboBox( false, this );
    label->setBuddy(m_pAnimationsCombo);
    m_pAnimationsCombo->insertItem(i18n("animations","Enabled"), AnimationsAlways);
    m_pAnimationsCombo->insertItem(i18n("animations","Disabled"), AnimationsNever);
    m_pAnimationsCombo->insertItem(i18n("Show Only Once"), AnimationsLoopOnce);
    lay->addWidget(label, row, 0);
    lay->addWidget(m_pAnimationsCombo, row, 1);
    row++;
    whatsThis = i18n("Controls how Konqueror shows animated images:<br>"
	    "<ul><li><b>Enabled</b>: Show all animations completely.</li>"
	    "<li><b>Disabled</b>: Never show animations, show the start image only.</li>"
	    "<li><b>Show only once</b>: Show all animations completely but do not repeat them.</li></ul>");
    TQWhatsThis::add( label, whatsThis);
    TQWhatsThis::add( m_pAnimationsCombo, whatsThis);
    connect(m_pAnimationsCombo, TQT_SIGNAL(activated(int)), TQT_SLOT(slotChanged()));

    label = new TQLabel( i18n("Sm&ooth scrolling"), this);
    m_pSmoothScrollingCombo = new TQComboBox( false, this );
    label->setBuddy(m_pSmoothScrollingCombo);
    m_pSmoothScrollingCombo->insertItem(i18n("SmoothScrolling","Enabled"), SmoothScrollingAlways);
    m_pSmoothScrollingCombo->insertItem(i18n("SmoothScrolling","Disabled"), SmoothScrollingNever);
    // not implemented: m_pSmoothScrollingCombo->insertItem(i18n("SmoothScrolling","WhenEfficient"), SmoothScrollingWhenEfficient);
    lay->addWidget(label, row, 0);
    lay->addWidget(m_pSmoothScrollingCombo, row, 1);
    row++;
    whatsThis = i18n("Determines whether Konqueror should use smooth steps to scroll HTML pages, or whole steps:<br>"
	    "<ul><li><b>Always</b>: Always use smooth steps when scrolling.</li>"
	    "<li><b>Never</b>: Never use smooth scrolling, scroll with whole steps instead.</li>"
	    // not implemented: "<li><b>When Efficient</b>: Only use smooth scrolling on pages where it can be achieved with moderate usage of system resources.</li>"
	    "</ul>");
    TQWhatsThis::add( label, whatsThis);
    TQWhatsThis::add( m_pSmoothScrollingCombo, whatsThis);
    connect(m_pSmoothScrollingCombo, TQT_SIGNAL(activated(int)), TQT_SLOT(slotChanged()));


    lay->setRowStretch(row, 1);

    load();
    emit changed(false);
}

KMiscHTMLOptions::~KMiscHTMLOptions()
{
    delete m_pConfig;
}

void KMiscHTMLOptions::load()
{
	load( false );
}

void KMiscHTMLOptions::load( bool useDefaults )
{
    TDEConfig tdehtmlrc("tdehtmlrc", true, false);
    tdehtmlrc.setReadDefaults( useDefaults );
	 m_pConfig->setReadDefaults( useDefaults );

#define SET_GROUP(x) m_pConfig->setGroup(x); tdehtmlrc.setGroup(x)
#define READ_BOOL(x,y) m_pConfig->readBoolEntry(x, tdehtmlrc.readBoolEntry(x, y))
#define READ_ENTRY(x) m_pConfig->readEntry(x, tdehtmlrc.readEntry(x))


    // *** load ***
    SET_GROUP( "MainView Settings" );
    bool bOpenMiddleClick = READ_BOOL( "OpenMiddleClick", true );
    bool bBackRightClick = READ_BOOL( "BackRightClick", false );
    SET_GROUP( "HTML Settings" );
    bool changeCursor = READ_BOOL("ChangeCursor", KDE_DEFAULT_CHANGECURSOR);
    bool underlineLinks = READ_BOOL("UnderlineLinks", DEFAULT_UNDERLINELINKS);
    bool hoverLinks = READ_BOOL("HoverLinks", true);
    bool bAutoLoadImages = READ_BOOL( "AutoLoadImages", true );
    bool bEnableFavIcon = READ_BOOL( "EnableFavicon", true );
    bool bUnfinishedImageFrame = READ_BOOL( "UnfinishedImageFrame", true );
    TQString strAnimations = READ_ENTRY( "ShowAnimations" ).lower();

    bool bAutoRedirect = m_pConfig->readBoolEntry( "AutoDelayedActions", true );

    // *** apply to GUI ***
    m_cbCursor->setChecked( changeCursor );
    m_pAutoLoadImagesCheckBox->setChecked( bAutoLoadImages );
    m_pEnableFavIconCheckBox->setChecked( bEnableFavIcon );
    m_pUnfinishedImageFrameCheckBox->setChecked( bUnfinishedImageFrame );
    m_pAutoRedirectCheckBox->setChecked( bAutoRedirect );
    m_pOpenMiddleClick->setChecked( bOpenMiddleClick );
    m_pBackRightClick->setChecked( bBackRightClick );

    // we use two keys for link underlining so that this config file
    // is backwards compatible with KDE 2.0.  the HoverLink setting
    // has precedence over the UnderlineLinks setting
    if (hoverLinks)
    {
        m_pUnderlineCombo->setCurrentItem( UnderlineHover );
    }
    else
    {
        if (underlineLinks)
            m_pUnderlineCombo->setCurrentItem( UnderlineAlways );
        else
            m_pUnderlineCombo->setCurrentItem( UnderlineNever );
    }
    if (strAnimations == "disabled")
       m_pAnimationsCombo->setCurrentItem( AnimationsNever );
    else if (strAnimations == "looponce")
       m_pAnimationsCombo->setCurrentItem( AnimationsLoopOnce );
    else
       m_pAnimationsCombo->setCurrentItem( AnimationsAlways );

    m_pFormCompletionCheckBox->setChecked( m_pConfig->readBoolEntry( "FormCompletion", true ) );
    m_pMaxFormCompletionItems->setValue( m_pConfig->readNumEntry( "MaxFormCompletionItems", 10 ) );
    m_pMaxFormCompletionItems->setEnabled( m_pFormCompletionCheckBox->isChecked() );

    TDEConfig config("kbookmarkrc", true, false);
    config.setReadDefaults( useDefaults );
	  config.setGroup("Bookmarks");
    m_pAdvancedAddBookmarkCheckBox->setChecked( config.readBoolEntry("AdvancedAddBookmarkDialog", false) );
    m_pOnlyMarkedBookmarksCheckBox->setChecked( config.readBoolEntry("FilteredToolbar", false) );

    TDEConfig kdeglobals("kdeglobals", true, false);
    kdeglobals.setReadDefaults( useDefaults );
	 kdeglobals.setGroup("KDE");
    bool smoothScrolling = kdeglobals.readBoolEntry("SmoothScrolling", DEFAULT_SMOOTHSCROLL);
    if (smoothScrolling)
	m_pSmoothScrollingCombo->setCurrentItem( SmoothScrollingAlways );
    else
	m_pSmoothScrollingCombo->setCurrentItem( SmoothScrollingNever );

	 emit changed( useDefaults );

#undef READ_ENTRY
#undef READ_BOOL
#undef SET_GROUP
}

void KMiscHTMLOptions::defaults()
{
	load( true );
}

void KMiscHTMLOptions::save()
{
    m_pConfig->setGroup( "MainView Settings" );
    m_pConfig->writeEntry( "OpenMiddleClick", m_pOpenMiddleClick->isChecked() );
    m_pConfig->writeEntry( "BackRightClick", m_pBackRightClick->isChecked() );
    m_pConfig->setGroup( "HTML Settings" );
    m_pConfig->writeEntry( "ChangeCursor", m_cbCursor->isChecked() );
    m_pConfig->writeEntry( "AutoLoadImages", m_pAutoLoadImagesCheckBox->isChecked() );
    m_pConfig->writeEntry( "EnableFavicon", m_pEnableFavIconCheckBox->isChecked() );
    m_pConfig->writeEntry( "UnfinishedImageFrame", m_pUnfinishedImageFrameCheckBox->isChecked() );
    m_pConfig->writeEntry( "AutoDelayedActions", m_pAutoRedirectCheckBox->isChecked() );
    switch(m_pUnderlineCombo->currentItem())
    {
      case UnderlineAlways:
        m_pConfig->writeEntry( "UnderlineLinks", true );
        m_pConfig->writeEntry( "HoverLinks", false );
        break;
      case UnderlineNever:
        m_pConfig->writeEntry( "UnderlineLinks", false );
        m_pConfig->writeEntry( "HoverLinks", false );
        break;
      case UnderlineHover:
        m_pConfig->writeEntry( "UnderlineLinks", false );
        m_pConfig->writeEntry( "HoverLinks", true );
        break;
    }
    switch(m_pAnimationsCombo->currentItem())
    {
      case AnimationsAlways:
        m_pConfig->writeEntry( "ShowAnimations", "Enabled" );
        break;
      case AnimationsNever:
        m_pConfig->writeEntry( "ShowAnimations", "Disabled" );
        break;
      case AnimationsLoopOnce:
        m_pConfig->writeEntry( "ShowAnimations", "LoopOnce" );
        break;
    }

    m_pConfig->writeEntry( "FormCompletion", m_pFormCompletionCheckBox->isChecked() );
    m_pConfig->writeEntry( "MaxFormCompletionItems", m_pMaxFormCompletionItems->value() );
    m_pConfig->sync();

    TDEConfig config("kbookmarkrc", false, false);
    config.setGroup("Bookmarks");
    config.writeEntry("AdvancedAddBookmarkDialog", m_pAdvancedAddBookmarkCheckBox->isChecked());
    config.writeEntry("FilteredToolbar", m_pOnlyMarkedBookmarksCheckBox->isChecked());
    config.sync();

    TDEConfig kdeglobals("kdeglobals", false, false);
    kdeglobals.setGroup("KDE");
    switch(m_pSmoothScrollingCombo->currentItem())
    {
      case SmoothScrollingAlways:
        kdeglobals.writeEntry( "SmoothScrolling", true );
        break;
      case SmoothScrollingNever:
        kdeglobals.writeEntry( "SmoothScrolling", false );
        break;
      // case SmoothScrollingWhenEfficient:
        // kdeglobals.writeEntry( "SmoothScrolling", somethingelse );
        // break;
    }
    kdeglobals.sync();

  TQByteArray data;
  if ( !kapp->dcopClient()->isAttached() )
    kapp->dcopClient()->attach();
  kapp->dcopClient()->send( "konqueror*", "KonquerorIface", "reparseConfiguration()", data );

    emit changed(false);
}

void KMiscHTMLOptions::slotChanged()
{
    m_pMaxFormCompletionItems->setEnabled( m_pFormCompletionCheckBox->isChecked() );
    emit changed(true);
}