summaryrefslogtreecommitdiffstats
path: root/kdirstat/kdirstatsettings.h
blob: 2985f560b6782ae09d04f85754ef0e7c4e1baf8e (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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
/*
 *   File name:	kdirstatsettings.h
 *   Summary:	Settings dialog for KDirStat
 *   License:	GPL - See file COPYING for details.
 *   Author:	Stefan Hundhammer <sh@suse.de>
 *
 *   Updated:	2003-01-07
 */


#ifndef KDirStatSettings_h
#define KDirStatSettings_h


#ifdef HAVE_CONFIG_H
#   include <config.h>
#endif

#include <tqlistbox.h>
#include <kdialogbase.h>
#include "kcleanup.h"
#include "kcleanupcollection.h"
#include "kdirstatapp.h"


class TQCheckBox;
class TQComboBox;
class TQHGroupBox;
class TQLabel;
class TQLineEdit;
class TQRadioButton;
class TQSlider;
class TQSpinBox;
class TQVGroupBox;
class TQWidget;

class KColorButton;


#define KDirStatSettingsMaxColorButton	12


namespace KDirStat
{
    class KCleanupListBox;
    class KCleanupPropertiesPage;
    class KDirTreeView;
    class KTreemapView;


    /**
     * Settings dialog for KDirStat
     *
     * @short Settings dialog for KDirStat
     **/
    class KSettingsDialog: public KDialogBase
    {
	Q_OBJECT
  

    public:

	/**
	 * Constructor.
	 *
	 * Notice there is no parent widget passed but the application's main
	 * window so its functions can be accessed. The parent of this widget
	 * is always 0 since this is a dialog.
	 **/

	KSettingsDialog( KDirStatApp * mainWin );

	/**
	 * Destructor.
	 **/
	virtual ~KSettingsDialog();


	/**
	 * Overwritten from @ref TQDialog() to get any chance to set up the
	 * dialog contents when the dialog gets shown - every time, not just at
	 * program startup when the settings dialog is created (!).
	 *
	 * TQTabDialog used to have 'aboutToShow()' for a good reason, but the
	 * creators of @ref KDialogBase in their infinite wisdom chose not to
	 * include anything similar. How is that supposed to work, anyway?
	 * Everything I saw in any other KDE sources looked to me like ugly
	 * hacks to work around this. Am I really supposed to destroy my
	 * settings dialog and create a new one every time it pops up? This can
	 * certainly not be the way to go.
	 *
	 * This overwritten show() method sends that @ref aboutToShow() signal
	 * before calling the parent class show() method.
	 **/
	virtual void show();


    public slots:

        /**
	 * Reimplemented from @ref KDialogBase to ask for confirmation.
	 * Emits signal @ref defaultClicked() when the user confirms.
	 **/
        virtual void slotDefault();

        /**
	 * Reimplemented from @ref KDialogBase to set the appropriate help
	 * topic prior to invoking online help.
	 **/
        virtual void slotHelp();


    signals:

	/**
	 * Emitted when (you might have guessed it) the dialog is about to be
	 * shown. Connect this to slots that fill the individual dialog pages'
	 * widgets contents (input fields etc.)
	 **/
	void aboutToShow();

    protected:

	KDirStatApp *	_mainWin;
	int		_cleanupsPageIndex;
	int		_treeColorsPageIndex;
	int		_treemapPageIndex;
	int		_generalSettingsPageIndex;

    }; // class KSettingsDialog



    /**
     * Abstract base class for all settings pages. Contains stubs for methods
     * that all settings pages have in common: setup(), apply(),
     * revertToDefaults().
     *
     * Note: This class contains pure virtuals - it cannot be
     * instantiated. Rather, derive your own classes from this one.
     **/
    class KSettingsPage: public TQWidget
    {
	Q_OBJECT
  

    public:

	/**
	 * Constructor.
	 *
	 * Sets up standard connections to the methods defined in this class,
	 * e.g., apply(), setup(), revertToDefaults().
	 **/
	KSettingsPage( KSettingsDialog *	dialog,
		       TQWidget *		parent );

	/**
	 * Destructor.
	 **/
	virtual ~KSettingsPage();


    public slots:

	/**
	 * Apply the changes.
	 *
	 * Derived classes need to reimplement this method.
	 **/
        virtual void apply() = 0;

	/**
	 * Revert all values to their defaults.
	 *
	 * Derived classes need to reimplement this method.
	 **/
	virtual void revertToDefaults() = 0;

	/**
	 * Set up all fields prior to displaying the dialog.
	 *
	 * Derived classes need to reimplement this method.
	 **/
	virtual void setup() = 0;


    public:

	/**
	 * Returns the page index of this page.
	 * This seems to be the only way to find out which settings page is in
	 * the foreground for a @ref KDialogBase page.
	 **/
	int pageIndex() { return _pageIndex; }

    protected:

	int _pageIndex;

    }; // class KSettingsPage



    /**
     * Settings tab page for the tree colors.
     *
     * Uses a vertical slider on the left side and a column of color
     * selection buttons on the right side. The slider enables/disables
     * the color buttons from top to bottom (at least one button is always
     * enabled). Each button represents the percentage fill color of one
     * directory level within the tree. When the tree widget runs out of
     * colors (i.e. there are more directory levels than different
     * colors), it will wrap around to the first color.
     *
     * @short settings page for tree colors
     * @author Stefan Hundhammer <sh@suse.de>
     **/
    class KTreeColorsPage: public KSettingsPage
    {
	Q_OBJECT
  

    public:

	/**
	 * Constructor
	 **/
	KTreeColorsPage( KSettingsDialog *	dialog,
			 TQWidget *		parent,
			 KDirStatApp *		mainWin );

	/**
	 * Destructor
	 **/
	virtual ~KTreeColorsPage();


    public slots:

	/**
	 * Apply the changes.
	 *
	 * Inherited from @ref KSettingsPage.
	 **/
        virtual void apply();

	/**
	 * Revert all values to their defaults.
	 *
	 * Inherited from @ref KSettingsPage.
	 **/
	virtual void revertToDefaults();

	/**
	 * Set up all fields prior to displaying the dialog.
	 *
	 * Inherited from @ref KSettingsPage.
	 **/
	virtual void setup();


    protected slots:

	/**
	 * Enable all colors up to color no. 'maxColors'.
	 **/
	void enableColors( int maxColors );


    protected:


	KDirStatApp *		_mainWin;
	KDirTreeView *		_treeView;
	TQSlider *		_slider;
	KColorButton *		_colorButton [ KDirStatSettingsMaxColorButton ];
	TQLabel *		_colorLabel  [ KDirStatSettingsMaxColorButton ];

	int			_maxButtons;

    }; // class KTreeColorsPage



    /**
     * Settings tab page for cleanup actions.
     *
     * Uses a KCleanupListBox for selection of one cleanup action and a
     * KCleanupPropertiesPage for editing this cleanup action's
     * properties. This class handles just the switching between the individual
     * cleanups. It copies the cleanup actions inserted and works with the
     * copies only until it is requested to save the changes or revert all
     * values to their defaults.
     *
     * @short settings page for cleanup actions
     **/
    class KCleanupPage: public KSettingsPage
    {
	Q_OBJECT
  

    public:

	/**
	 * Constructor
	 **/
	KCleanupPage( KSettingsDialog *	dialog,
		      TQWidget *		parent,
		      KDirStatApp *	mainWin );

	/**
	 * Destructor
	 **/
	virtual ~KCleanupPage();

	/**
	 * Insert an entry for a cleanup action. This is the original value
	 * that will be changed only when receiving the apply() or
	 * defaultValues() signals.
	 **/
	void insert( KCleanup *cleanup );

	/**
	 * Import all cleanup actions from the originals (from the main
	 * window) to internal working copies.
	 **/
	void importCleanups();

	/**
	 * Copy the internal working copies of the cleanup actions back to
	 * the main window's originals. Take care of pending changes within
	 * the current properties page's fields prior to that.
	 **/
	void exportCleanups();


    public slots:

	/**
	 * Apply the changes.
	 *
	 * Inherited from @ref KSettingsPage.
	 **/
        virtual void apply();

	/**
	 * Revert all values to their defaults.
	 *
	 * Inherited from @ref KSettingsPage.
	 **/
	virtual void revertToDefaults();

	/**
	 * Set up all fields prior to displaying the dialog.
	 *
	 * Inherited from @ref KSettingsPage.
	 **/
	virtual void setup();

	/**
	 * Switch back and forth between all the cleanup actions very much
	 * like in a tab dialog: Exchange field contents of the cleanup
	 * properties page with the cleanup specified. Store the old
	 * properties page contents in the working copies of the cleanups.
	 **/
	void changeCleanup( KCleanup * cleanup );


    protected:

	/**
	 * Retrieve any pending changes from the properties page and store
	 * them in the cleanup specified.
	 **/
	void storeProps( KCleanup * cleanup );


	//
	// Data members
	//

	KCleanupListBox *		_listBox;
	KCleanupPropertiesPage *	_props;
	KDirStatApp *			_mainWin;

	KCleanupCollection		_workCleanupCollection;
	KCleanup *			_currentCleanup;

    }; // class KCleanupPage



    /**
     * List box for cleanup actions.
     *
     * This is meant as a substitute for a tabbed dialog inside the tabbed
     * dialog which would be much too wide and possibly confusing. Plus, this
     * list box is supposed to take care of its own geometry - the normal
     * dumbass list box obviously cannot do that. It just uses some random
     * geometry, relying on scroll bars for everything else. But in this
     * special case we want all items to be visible at all times without scroll
     * bars.
     *
     * @short cleanup list box
     **/
    class KCleanupListBox: public TQListBox
    {
	Q_OBJECT
  

    public:

	/**
	 * Constructor.
	 **/
	KCleanupListBox( TQWidget * parent = 0 );

	/**
	 * Destructor.
	 **/
	virtual ~KCleanupListBox() {};

	/**
	 * Reimplemented so we can make sure all items are visible at all times
	 * without scrolling. In fact, we never want to see a scroll bar with
	 * this kind of list box.
	 **/
	virtual TQSize sizeHint() const;

	/**
	 * Insert an entry for a cleanup action into the list box. Uses the
	 * cleanup action's internally stored title for display.
	 **/
	void insert( KCleanup * cleanup );

	/**
	 * Returns the currently selected cleanup of 0 if nothing is selected.
	 **/
	KCleanup * selection()	{ return _selection; }

	/**
	 * Update the list item's text that corresponds to 'cleanup' - the user
	 * may have entered a new cleanup name. '0' means "check all items".
	 **/
	void updateTitle( KCleanup * cleanup = 0 );


    signals:

	/**
	 * Emitted when the user selects a list item, i.e. a cleanup action.
	 **/
	void selectCleanup( KCleanup * cleanup );


    protected slots:

	/**
	 * Select an item.
	 **/
	void selectCleanup( TQListBoxItem * item );


    protected:

	KCleanup * _selection;

    }; // class KCleanupListBox



    /**
     * List box item for a KCleanupListBox.
     **/
    class KCleanupListBoxItem: public TQListBoxText
    {
    public:

	/**
	 * Constructor.
	 **/
	KCleanupListBoxItem( KCleanupListBox *	listBox,
			     KCleanup *	 	cleanup );

	/**
	 * Returns the corresponding cleanup.
	 **/
	KCleanup * cleanup() { return _cleanup; }

	/**
	 * Update the list box display with the cleanup's name which may have
	 * changed - the user may have entered a new one.
	 **/
	void updateTitle();


    protected:


	// Data members

	KCleanup * _cleanup;

    }; // class KCleanupListBoxItem



    /**
     * Properties page for one cleanup action.
     **/
    class KCleanupPropertiesPage: public TQWidget
    {
	Q_OBJECT
  

    public:

	/**
	 * Constructor
	 **/
	KCleanupPropertiesPage( TQWidget *	parent,
				KDirStatApp *	mainWin );

	/**
	 * Retrieve the page's fields' values and store them in the cleanup
	 * action.
	 **/
	KCleanup fields( void ) const;


    public slots:

	/**
	 * Set the page's fields' values with the cleanup action's
	 * contents.
	 **/
	void setFields( const KCleanup * cleanup );

	/**
	 * Enable / disable all of the properties page's fields except the
	 * 'enabled' check box.
	 **/
	void enableFields( bool active );


    protected:

	TQString			_id;
	TQCheckBox *		_enabled;
	TQWidget *		_fields;
	TQLineEdit *		_title;
	TQLineEdit *		_command;
	TQCheckBox *		_recurse;
	TQCheckBox *		_askForConfirmation;
	TQCheckBox *		_worksForDir;
	TQCheckBox *		_worksForFile;
	TQCheckBox *		_worksForDotEntry;
	TQComboBox *		_worksForProtocols;
	TQComboBox *		_refreshPolicy;

	KDirStatApp *		_mainWin;

    }; // class KCleanupPropertiesPage



    /**
     * Settings tab page for general/misc settings.
     **/
    class KGeneralSettingsPage: public KSettingsPage
    {
	Q_OBJECT
  

    public:

	/**
	 * Constructor
	 **/
	KGeneralSettingsPage( KSettingsDialog *	dialog,
			      TQWidget *		parent,
			      KDirStatApp *	mainWin );

	/**
	 * Destructor
	 **/
	virtual ~KGeneralSettingsPage();


    public slots:

	/**
	 * Apply the changes.
	 *
	 * Inherited from @ref KSettingsPage.
	 **/
        virtual void apply();

	/**
	 * Revert all values to their defaults.
	 *
	 * Inherited from @ref KSettingsPage.
	 **/
	virtual void revertToDefaults();

	/**
	 * Set up all fields prior to displaying the dialog.
	 *
	 * Inherited from @ref KSettingsPage.
	 **/
	virtual void setup();

	/**
	 * Check the enabled state of all widgets depending on the value of
	 * other widgets.
	 **/
	void checkEnabledState();


    protected:

	// Data members

	KDirStatApp *	_mainWin;
	KDirTreeView *	_treeView;

	TQCheckBox *	_crossFileSystems;
	TQCheckBox *	_enableLocalDirReader;

	TQCheckBox *	_enableToolBarAnimation;
	TQCheckBox *	_enableTreeViewAnimation;

    }; // class KGeneralSettingsPage



    /**
     * Settings tab page for treemap settings.
     **/
    class KTreemapPage: public KSettingsPage
    {
	Q_OBJECT
  

    public:

	/**
	 * Constructor
	 **/
	KTreemapPage( KSettingsDialog *	dialog,
		      TQWidget *		parent,
		      KDirStatApp *	mainWin );

	/**
	 * Destructor
	 **/
	virtual ~KTreemapPage();


    public slots:

	/**
	 * Apply the changes.
	 *
	 * Inherited from @ref KSettingsPage.
	 **/
        virtual void apply();

	/**
	 * Revert all values to their defaults.
	 *
	 * Inherited from @ref KSettingsPage.
	 **/
	virtual void revertToDefaults();

	/**
	 * Set up all fields prior to displaying the dialog.
	 *
	 * Inherited from @ref KSettingsPage.
	 **/
	virtual void setup();

	/**
	 * Check the enabled state of all widgets depending on the value of
	 * other widgets.
	 **/
	void checkEnabledState();


    protected:

	/**
	 * Returns the main window's current treemap view or 0 if there is
	 * none. Don't cache this value, it changes frequently!
	 **/
	KTreemapView * treemapView() const { return _mainWin->treemapView(); }

	/**
	 * Convenience method to read a color from 'config'.
	 **/
	TQColor readColorEntry( TDEConfig * 	config,
			       const char * 	entryName,
			       TQColor 		defaultColor );

	// Data members

	KDirStatApp *		_mainWin;

	
	// Widgets
	
	TQCheckBox *		_squarify;
	TQCheckBox *		_doCushionShading;
	TQVGroupBox *		_cushionParams;
	TQSlider *		    _ambientLight;
	TQSpinBox *		    _ambientLightSB;
	TQSlider *		    _heightScalePercent;
	TQSpinBox *		    _heightScalePercentSB;
	TQCheckBox *		    _ensureContrast;
	TQCheckBox *		    _forceCushionGrid;
	KColorButton *		    _cushionGridColor;
	TQLabel *		    _cushionGridColorL;
	TQHGroupBox *		_plainTileParams;
	KColorButton *		    _fileFillColor;
	KColorButton *		    _dirFillColor;
	KColorButton *		    _outlineColor;
	KColorButton *		_highlightColor;
	TQSpinBox *		_minTileSize;
	TQCheckBox *		_autoResize;
	
    }; // class KTreemapPage

}	// namespace KDirStat


/**
 * Add a horizontal stretch widget to take all excess space.
 **/
void addHStretch( TQWidget * parent );

/**
 * Add a vertical stretch widget to take all excess space.
 **/
void addVStretch( TQWidget * parent );



#endif // ifndef KDirStatSettings_h


// EOF