summaryrefslogtreecommitdiffstats
path: root/kdirstat/kdirstatapp.cpp
blob: c83496d680e98de72323f2b1193905e00800b4f0 (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
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
/*
 *   File name:	kdirstatapp.cpp
 *   Summary:	The KDirStat application - menu bar, tool bar, ...
 *   License:	GPL - See file COPYING for details.
 *
 *   Author:	Stefan Hundhammer <sh@suse.de>
 *		Parts auto-generated by KDevelop
 *
 *   Updated:	2004-12-06
 */


#include <tqclipboard.h>
#include <tqpopupmenu.h>
#include <tqsplitter.h>

#include <tdeaccel.h>
#include <tdeaction.h>
#include <kapp.h>
#include <tdeconfig.h>
#include <tdefiledialog.h>
#include <kiconloader.h>
#include <tdelocale.h>
#include <tdemenubar.h>
#include <tdemessagebox.h>
#include <krun.h>
#include <kstatusbar.h>
#include <kstdaction.h>
#include <kurlrequesterdlg.h>

#include "kdirstatapp.h"
#include "kcleanupcollection.h"
#include "kdirtree.h"
#include "kpacman.h"
#include "ktreemapview.h"
#include "ktreemaptile.h"
#include "kcleanupcollection.h"
#include "kactivitytracker.h"
#include "kdirtreeview.h"
#include "kdirstatsettings.h"


#define	USER_CLEANUPS	10	// Number of user cleanup actions

#define ID_STATUS_MSG	1
#define ID_PACMAN	42
#define PACMAN_WIDTH	350
#define PACMAN_INTERVAL	75	// millisec

#define INITIAL_FEEDBACK_REMINDER	2000L
#define FEEDBACK_REMINDER_INTERVAL	1000L


using namespace KDirStat;


KDirStatApp::KDirStatApp( TQWidget* , const char* name )
    : TDEMainWindow( 0, name )
{
    // Simple inits

    _activityTracker	= 0;	// Might or might not be needed


    // Those will be created delayed, only when needed

    _settingsDialog 	= 0;
    _feedbackDialog 	= 0;
    _treemapView	= 0;
    _pacMan		= 0;
    _pacManDelimiter	= 0;


    // Set up internal (mainWin -> mainWin) connections

    connect( this,	TQT_SIGNAL( readConfig       ( void ) ),
	     this,	TQT_SLOT  ( readMainWinConfig( void ) ) );

    connect( this,	TQT_SIGNAL( saveConfig       ( void ) ),
	     this,	TQT_SLOT  ( saveMainWinConfig( void ) ) );


    // Create main window

    _splitter = new TQSplitter( Qt::Vertical, this );
    setCentralWidget( _splitter );

    _treeView = new KDirTreeView( _splitter );

    connect( _treeView, TQT_SIGNAL( progressInfo( const TQString & ) ),
	     this,      TQT_SLOT  ( statusMsg   ( const TQString & ) ) );

    connect( _treeView, TQT_SIGNAL( selectionChanged( KFileInfo * ) ),
	     this,      TQT_SLOT  ( selectionChanged( KFileInfo * ) ) );

    connect( _treeView, TQT_SIGNAL( contextMenu( KDirTreeViewItem *, const TQPoint & ) ),
	     this,      TQT_SLOT  ( contextMenu( KDirTreeViewItem *, const TQPoint & ) ) );

    connect( this,	TQT_SIGNAL( readConfig() 		), _treeView,	TQT_SLOT  ( readConfig() ) );
    connect( this,	TQT_SIGNAL( saveConfig() 		), _treeView,	TQT_SLOT  ( saveConfig() ) );

    connect( _treeView, TQT_SIGNAL( finished()		), TQT_TQOBJECT(this), TQT_SLOT( createTreemapView() ) );
    connect( _treeView, TQT_SIGNAL( aborted()		), TQT_TQOBJECT(this), TQT_SLOT( createTreemapView() ) );
    connect( _treeView, TQT_SIGNAL( startingReading()	), TQT_TQOBJECT(this), TQT_SLOT( deleteTreemapView() ) );

    connect( _treeView, TQT_SIGNAL( startingReading()	), TQT_TQOBJECT(this), TQT_SLOT( updateActions() ) );
    connect( _treeView, TQT_SIGNAL( finished()        	), TQT_TQOBJECT(this), TQT_SLOT( updateActions() ) );
    connect( _treeView, TQT_SIGNAL( aborted()         	), TQT_TQOBJECT(this), TQT_SLOT( updateActions() ) );

    // Call inits to invoke all other construction parts

    initStatusBar();
    initActions();
    initCleanups();
    createGUI();
    initActivityTracker();

    _treeViewContextMenu = (TQPopupMenu *) factory()->container( "treeViewContextMenu", this );
    _treemapContextMenu	 = (TQPopupMenu *) factory()->container( "treemapContextMenu",  this );

    readMainWinConfig();


    // Disable certain actions at startup

    _editCopy->setEnabled( false );
    _reportMailToOwner->setEnabled( false );
    _fileRefreshAll->setEnabled( false );
    _fileRefreshSelected->setEnabled( false );
    updateActions();
}


KDirStatApp::~KDirStatApp()
{
    delete _cleanupCollection;
}



void
KDirStatApp::initActions()
{
    _fileAskOpenDir	= KStdAction::open		( TQT_TQOBJECT(this), TQT_SLOT( fileAskOpenDir() ), 		actionCollection() );

    _fileAskOpenUrl	= new TDEAction( i18n( "Open &URL..." ), "konqueror", 0,
				       TQT_TQOBJECT(this), TQT_SLOT( fileAskOpenUrl() ),
				       actionCollection(), "file_open_url" );

    _fileOpenRecent	= KStdAction::openRecent	( TQT_TQOBJECT(this), TQT_SLOT( fileOpenRecent( const KURL& ) ),	actionCollection() );
    _fileCloseDir	= KStdAction::close		( TQT_TQOBJECT(this), TQT_SLOT( fileCloseDir() ), 		actionCollection() );

    _fileRefreshAll		= new TDEAction( i18n( "Refresh &All" ), "reload", 0,
					       TQT_TQOBJECT(this), TQT_SLOT( refreshAll() ),
					       actionCollection(), "file_refresh_all" );

    _fileRefreshSelected	= new TDEAction( i18n( "Refresh &Selected" ), 0,
					       TQT_TQOBJECT(this), TQT_SLOT( refreshSelected() ),
					       actionCollection(), "file_refresh_selected" );

    _fileContinueReadingAtMountPoint = new TDEAction( i18n( "Continue Reading at &Mount Point" ), "hdd_mount", 0,
						    TQT_TQOBJECT(this), TQT_SLOT( refreshSelected() ), actionCollection(),
						    "file_continue_reading_at_mount_point" );

    _fileStopReading	= new TDEAction( i18n( "Stop Rea&ding" ), "process-stop", 0,
				       TQT_TQOBJECT(this), TQT_SLOT( stopReading() ), actionCollection(),
				       "file_stop_reading" );

    _fileQuit		= KStdAction::quit		( TQT_TQOBJECT(kapp), TQT_SLOT( quit()  		), actionCollection() );
    _editCopy		= KStdAction::copy		( TQT_TQOBJECT(this), TQT_SLOT( editCopy() 		), actionCollection() );
    _showToolBar	= KStdAction::showToolbar	( TQT_TQOBJECT(this), TQT_SLOT( toggleToolBar()		), actionCollection() );
    _showStatusBar	= KStdAction::showStatusbar	( TQT_TQOBJECT(this), TQT_SLOT( toggleStatusBar()	), actionCollection() );

    _cleanupOpenWith	= new TDEAction( i18n( "Open With" ), 0,
				       TQT_TQOBJECT(this), TQT_SLOT( cleanupOpenWith() ),
				       actionCollection(), "cleanup_open_with" );

    _treemapZoomIn 	= new TDEAction( i18n( "Zoom in" ), "zoom-in", Key_Plus,
				       TQT_TQOBJECT(this), TQT_SLOT( treemapZoomIn() ),
				       actionCollection(), "treemap_zoom_in" );

    _treemapZoomOut 	= new TDEAction( i18n( "Zoom out" ), "zoom-out", Key_Minus,
				       TQT_TQOBJECT(this), TQT_SLOT( treemapZoomOut() ),
				       actionCollection(), "treemap_zoom_out" );

    _treemapSelectParent= new TDEAction( i18n( "Select Parent" ), "go-up", Key_Asterisk,
				       TQT_TQOBJECT(this), TQT_SLOT( treemapSelectParent() ),
				       actionCollection(), "treemap_select_parent" );

    _treemapRebuild 	= new TDEAction( i18n( "Rebuild Treemap" ), 0,
				       TQT_TQOBJECT(this), TQT_SLOT( treemapRebuild() ),
				       actionCollection(), "treemap_rebuild" );

    _showTreemapView	= new TDEToggleAction( i18n( "Show Treemap" ), Key_F9,
					     TQT_TQOBJECT(this), TQT_SLOT( toggleTreemapView() ),
					     actionCollection(), "options_show_treemap" );

    new TDEAction( i18n( "Help about Treemaps" ), "help", 0,
		 TQT_TQOBJECT(this), TQT_SLOT( treemapHelp() ),
		 actionCollection(), "treemap_help" );

    TDEAction * pref	= KStdAction::preferences( TQT_TQOBJECT(this), TQT_SLOT( preferences()	), actionCollection() );

    _reportMailToOwner	= new TDEAction( i18n( "Send &Mail to Owner" ), "mail_generic", 0,
				       TQT_TQOBJECT(_treeView), TQT_SLOT( sendMailToOwner() ),
				       actionCollection(), "report_mail_to_owner" );

    _helpSendFeedbackMail = new TDEAction( i18n( "Send &Feedback Mail..." ), 0,
					 TQT_TQOBJECT(this), TQT_SLOT( sendFeedbackMail() ),
					 actionCollection(), "help_send_feedback_mail" );


    _fileAskOpenDir->setStatusText	( i18n( "Opens a directory"	 		) );
    _fileAskOpenUrl->setStatusText	( i18n( "Opens a (possibly remote) directory"	) );
    _fileOpenRecent->setStatusText	( i18n( "Opens a recently used directory"	) );
    _fileCloseDir->setStatusText	( i18n( "Closes the current directory" 		) );
    _fileRefreshAll->setStatusText	( i18n( "Re-reads the entire directory tree"	) );
    _fileRefreshSelected->setStatusText	( i18n( "Re-reads the selected subtree"		) );
    _fileContinueReadingAtMountPoint->setStatusText( i18n( "Scan mounted file systems"	) );
    _fileStopReading->setStatusText	( i18n( "Stops directory reading"		) );
    _fileQuit->setStatusText		( i18n( "Quits the application" 		) );
    _editCopy->setStatusText		( i18n( "Copies the URL of the selected item to the clipboard" ) );
    _showToolBar->setStatusText		( i18n( "Enables/disables the toolbar" 		) );
    _showStatusBar->setStatusText	( i18n( "Enables/disables the statusbar" 	) );
    _cleanupOpenWith->setStatusText	( i18n( "Open file or directory with arbitrary application" ) );
    _showTreemapView->setStatusText	( i18n( "Enables/disables the treemap view" 	) );
    _treemapZoomIn->setStatusText	( i18n( "Zoom treemap in"		 	) );
    _treemapZoomOut->setStatusText	( i18n( "Zoom treemap out"		 	) );
    _treemapSelectParent->setStatusText	( i18n( "Select parent"			 	) );
    _treemapRebuild->setStatusText	( i18n( "Rebuild treemap to fit into available space" ) );
    pref->setStatusText			( i18n( "Opens the preferences dialog"		) );
    _reportMailToOwner->setStatusText	( i18n( "Sends a mail to the owner of the selected subtree" ) );
}


void
KDirStatApp::initCleanups()
{
    _cleanupCollection = new KCleanupCollection( actionCollection() );
    CHECK_PTR( _cleanupCollection );
    _cleanupCollection->addStdCleanups();
    _cleanupCollection->addUserCleanups( USER_CLEANUPS );
    _cleanupCollection->slotReadConfig();

    connect( _treeView,          TQT_SIGNAL( selectionChanged( KFileInfo * ) ),
	     _cleanupCollection, TQT_SIGNAL( selectionChanged( KFileInfo * ) ) );

    connect( this,               TQT_SIGNAL( readConfig( void ) ),
	     _cleanupCollection, TQT_SIGNAL( readConfig( void ) ) );

    connect( this,               TQT_SIGNAL( saveConfig( void ) ),
	     _cleanupCollection, TQT_SIGNAL( saveConfig( void ) ) );
}


void
KDirStatApp::revertCleanupsToDefaults()
{
    KCleanupCollection defaultCollection;
    defaultCollection.addStdCleanups();
    defaultCollection.addUserCleanups( USER_CLEANUPS );
    *_cleanupCollection = defaultCollection;
}


void
KDirStatApp::initPacMan( bool enablePacMan )
{
    if ( enablePacMan )
    {
	if ( ! _pacMan )
	{
	    _pacMan = new KPacMan( toolBar(), 16, false, "tde toolbar widget" );
	    _pacMan->setInterval( PACMAN_INTERVAL );	// millisec
	    int id = ID_PACMAN;
	    toolBar()->insertWidget( id, PACMAN_WIDTH, _pacMan );
	    toolBar()->setItemAutoSized( id, false );

	    _pacManDelimiter = new TQWidget( toolBar() );
	    toolBar()->insertWidget( ++id, 1, _pacManDelimiter );

	    connect( _treeView, TQT_SIGNAL( startingReading() ), _pacMan, TQT_SLOT( start() ) );
	    connect( _treeView, TQT_SIGNAL( finished()        ), _pacMan, TQT_SLOT( stop () ) );
	    connect( _treeView, TQT_SIGNAL( aborted()         ), _pacMan, TQT_SLOT( stop () ) );
	}
    }
    else
    {
	if ( _pacMan )
	{
	    delete _pacMan;
	    _pacMan = 0;
	}

	if ( _pacManDelimiter )
	{
	    delete _pacManDelimiter;
	    _pacManDelimiter = 0;
	}
    }
}


void
KDirStatApp::initStatusBar()
{
    statusBar()->insertItem( i18n( "Ready." ), ID_STATUS_MSG );
}


void
KDirStatApp::initActivityTracker()
{
    if ( ! doFeedbackReminder() )
	return;

    _activityTracker = new KActivityTracker( TQT_TQOBJECT(this), "Feedback",
					     INITIAL_FEEDBACK_REMINDER );

    connect( _activityTracker,  TQT_SIGNAL( thresholdReached() ),
	     this,		TQT_SLOT  ( askForFeedback() ) );

    connect( _treeView,		TQT_SIGNAL( userActivity( int ) ),
	     _activityTracker,	TQT_SLOT  ( trackActivity( int ) ) );

    connect( _cleanupCollection, TQT_SIGNAL( userActivity( int ) ),
	     _activityTracker,   TQT_SLOT  ( trackActivity( int ) ) );
}


void
KDirStatApp::openURL( const KURL& url )
{
    statusMsg( i18n( "Opening directory..." ) );

    _treeView->openURL( url );
    _fileOpenRecent->addURL( url );
    _fileRefreshAll->setEnabled( true );
    setCaption( url.fileName(), false );

    statusMsg( i18n( "Ready." ) );
}


void KDirStatApp::readMainWinConfig()
{

    TDEConfig * config = kapp->config();
    config->setGroup( "General Options" );

    // Status settings of the various bars and views

    _showToolBar->setChecked( config->readBoolEntry( "Show Toolbar", true ) );
    toggleToolBar();

    _showStatusBar->setChecked( config->readBoolEntry( "Show Statusbar", true ) );
    toggleStatusBar();

    _showTreemapView->setChecked( config->readBoolEntry( "Show Treemap", true ) );
    toggleTreemapView();


    // Position settings of the various bars

    TDEToolBar::BarPosition toolBarPos;
    toolBarPos = ( TDEToolBar::BarPosition ) config->readNumEntry( "ToolBarPos", TDEToolBar::Top );
    toolBar( "mainToolBar" )->setBarPos( toolBarPos );

    _treemapViewHeight = config->readNumEntry( "TreemapViewHeight", 250 );

    // initialize the recent file list
    _fileOpenRecent->loadEntries( config,"Recent Files" );

    TQSize size = config->readSizeEntry( "Geometry" );

    if( ! size.isEmpty() )
	resize( size );

    config->setGroup( "Animation" );
    initPacMan( config->readBoolEntry( "ToolbarPacMan", true ) );
    _treeView->enablePacManAnimation( config->readBoolEntry( "DirTreePacMan", false ) );
}


void
KDirStatApp::saveMainWinConfig()
{
    TDEConfig * config = kapp->config();

    config->setGroup( "General Options" );

    config->writeEntry( "Geometry", 		size() );
    config->writeEntry( "Show Toolbar", 	_showToolBar->isChecked() );
    config->writeEntry( "Show Statusbar",	_showStatusBar->isChecked() );
    config->writeEntry( "Show Treemap",		_showTreemapView->isChecked() );
    config->writeEntry( "ToolBarPos", 		(int) toolBar( "mainToolBar" )->barPos() );

    if ( _treemapView )
	config->writeEntry( "TreemapViewHeight", _treemapView->height() );

    _fileOpenRecent->saveEntries( config,"Recent Files" );
}


void
KDirStatApp::saveProperties( TDEConfig *config )
{
    (void) config;
    // TODO
}


void
KDirStatApp::readProperties( TDEConfig *config )
{
    (void) config;
    // TODO
}


bool
KDirStatApp::queryClose()
{
    return true;
}

bool
KDirStatApp::queryExit()
{
    emit saveConfig();

    return true;
}


//============================================================================
//				     Slots
//============================================================================


void
KDirStatApp::fileAskOpenDir()
{
    statusMsg( i18n( "Opening directory..." ) );

    KURL url = KFileDialog::getExistingDirectory( TQString(), this, i18n( "Open Directory..." ) );

    if( ! url.isEmpty() )
	openURL( fixedUrl( url.url() ) );

    statusMsg( i18n( "Ready." ) );
}


void
KDirStatApp::fileAskOpenUrl()
{
    statusMsg( i18n( "Opening URL..." ) );

    KURL url = KURLRequesterDlg::getURL( TQString(),	// startDir
					 this, i18n( "Open URL..." ) );

    if( ! url.isEmpty() )
	openURL( fixedUrl( url.url() ) );

    statusMsg( i18n( "Ready." ) );
}


void
KDirStatApp::fileOpenRecent( const KURL& url )
{
    statusMsg( i18n( "Opening directory..." ) );

    if( ! url.isEmpty() )
	openURL( fixedUrl( url.url() ) );

    statusMsg( i18n( "Ready." ) );
}


void
KDirStatApp::fileCloseDir()
{
    statusMsg( i18n( "Closing directory..." ) );

    _treeView->clear();
    _fileRefreshAll->setEnabled( false );
    close();

    statusMsg( i18n( "Ready." ) );
}


void
KDirStatApp::refreshAll()
{
    statusMsg( i18n( "Refreshing directory tree..." ) );
    _treeView->refreshAll();
    statusMsg( i18n( "Ready." ) );
}


void
KDirStatApp::refreshSelected()
{
    if ( ! _treeView->selection() )
	return;

    statusMsg( i18n( "Refreshing selected subtree..." ) );
    _treeView->refreshSelected();
    statusMsg( i18n( "Ready." ) );
}


void
KDirStatApp::stopReading()
{
    _treeView->abortReading();
}


void
KDirStatApp::editCopy()
{
    if ( _treeView->selection() )
	kapp->clipboard()->setText( TQString::fromLocal8Bit(_treeView->selection()->orig()->url()) );

#if 0
#warning debug
    if ( _activityTracker )
	_activityTracker->trackActivity( 800 );
#endif
}


void
KDirStatApp::cleanupOpenWith()
{
    if ( ! _treeView->selection() )
	return;

    KFileInfo * sel = _treeView->selection()->orig();

    if ( sel->isDotEntry() )
	return;

    KURL::List urlList( KURL( sel->url()  ) );
    KRun::displayOpenWithDialog( urlList, false );
}


void
KDirStatApp::selectionChanged( KFileInfo *selection )
{
    if ( selection )
    {
	_editCopy->setEnabled( true );
	_reportMailToOwner->setEnabled( true );
	_fileRefreshSelected->setEnabled( ! selection->isDotEntry() );
	_cleanupOpenWith->setEnabled( ! selection->isDotEntry() );

	if ( selection->isMountPoint() &&
	     selection->readState() == KDirOnRequestOnly )
	{
	    _fileContinueReadingAtMountPoint->setEnabled( true );
	}
	else
	    _fileContinueReadingAtMountPoint->setEnabled( false );

	statusMsg( TQString::fromLocal8Bit(selection->url()) );
    }
    else
    {
	_editCopy->setEnabled( false );
	_reportMailToOwner->setEnabled( false );
	_fileRefreshSelected->setEnabled( false );
	_fileContinueReadingAtMountPoint->setEnabled( false );
	_cleanupOpenWith->setEnabled( false );
	statusMsg( "" );
    }

    updateActions();
}


void
KDirStatApp::updateActions()
{
    _treemapZoomIn->setEnabled ( _treemapView && _treemapView->canZoomIn() );
    _treemapZoomOut->setEnabled( _treemapView && _treemapView->canZoomOut() );
    _treemapRebuild->setEnabled( _treemapView && _treemapView->rootTile() );
    _treemapSelectParent->setEnabled( _treemapView && _treemapView->canSelectParent() );

    if ( _treeView->tree() && _treeView->tree()->isBusy() )
	_fileStopReading->setEnabled( true );
    else
	_fileStopReading->setEnabled( false );
}


void
KDirStatApp::treemapZoomIn()
{
    if ( _treemapView )
    {
	_treemapView->zoomIn();
	updateActions();
    }
}


void
KDirStatApp::treemapZoomOut()
{
    if ( _treemapView )
    {
	_treemapView->zoomOut();
	updateActions();
    }
}


void
KDirStatApp::treemapSelectParent()
{
    if ( _treemapView )
    {
	_treemapView->selectParent();
	updateActions();
    }
}


void
KDirStatApp::treemapRebuild()
{
    if ( _treemapView )
    {
	_treemapView->rebuildTreemap();
	updateActions();
    }
}


void
KDirStatApp::treemapHelp()
{
    kapp->invokeHelp( "treemap_intro" );
}


void
KDirStatApp::toggleToolBar()
{
    if   ( _showToolBar->isChecked() )	toolBar( "mainToolBar" )->show();
    else				toolBar( "mainToolBar" )->hide();
}


void
KDirStatApp::toggleStatusBar()
{
    if   ( _showStatusBar->isChecked() )	statusBar()->show();
    else					statusBar()->hide();
}


void
KDirStatApp::toggleTreemapView()
{
    if   ( _showTreemapView->isChecked() )
    {
	if ( ! _treemapView )
	    createTreemapView();
    }
    else
    {
	if ( _treemapView )
	    deleteTreemapView();
    }
}


void
KDirStatApp::preferences()
{
    if ( ! _settingsDialog )
    {
	_settingsDialog = new KDirStat::KSettingsDialog( this );
	CHECK_PTR( _settingsDialog );
    }

    if ( ! _settingsDialog->isVisible() )
	_settingsDialog->show();
}


void
KDirStatApp::askForFeedback()
{
    if ( ! doFeedbackReminder() )
	return;

    TDEConfig * config = kapp->config();

    switch ( KMessageBox::warningYesNoCancel( this,
					      i18n( "Now that you know this program for some time,\n"
						    "wouldn't you like to tell the authors your opinion about it?\n"
						    "\n"
						    "Open Source software depends on user feedback.\n"
						    "Your opinion can help us make the software better." ),
					      i18n( "Please tell us your opinion!" ),	// caption
					      i18n( "Open &Feedback Form..." ),		// yesButton
					      i18n( "&No, and don't ask again!" )	// noButton
					      )
	     )
    {
	case KMessageBox::Yes:
	    sendFeedbackMail();
	    break;

	case KMessageBox::No:	// ...and don't ask again
	    config->setGroup( "Feedback" );
	    config->writeEntry( "dontAsk", true );
	    config->sync();	// make sure this doesn't get lost even if the app is killed or crashes
	    break;

	case KMessageBox::Cancel:
	    break;
    }

    config->setGroup( "Feedback" );
    int  remindersCount = config->readNumEntry ( "remindersCount", 0 );
    config->writeEntry( "remindersCount", ++remindersCount );

    if ( _activityTracker )
    {
	_activityTracker->setThreshold( _activityTracker->threshold()
					+ FEEDBACK_REMINDER_INTERVAL );
    }
}


void
KDirStatApp::feedbackMailSent()
{
    TDEConfig * config = kapp->config();
    config->setGroup( "Feedback" );
    config->writeEntry( "mailSent", true );
    config->sync();
}


bool
KDirStatApp::doFeedbackReminder()
{
    TDEConfig * config = kapp->config();
    config->setGroup( "Feedback" );

    bool mailSent	= config->readBoolEntry( "mailSent", false );
    bool dontAsk	= config->readBoolEntry( "dontAsk", false );
    int  remindersCount = config->readNumEntry ( "remindersCount", 0 );

    return !mailSent && !dontAsk && remindersCount < 5;
}


void
KDirStatApp::statusMsg( const TQString &text )
{
    // Change status message permanently

    statusBar()->clear();
    statusBar()->changeItem( text, ID_STATUS_MSG );
}


void
KDirStatApp::contextMenu( KDirTreeViewItem * item, const TQPoint &pos )
{
    NOT_USED( item );

    if ( _treeViewContextMenu )
	_treeViewContextMenu->popup( pos );
}


void
KDirStatApp::contextMenu( KTreemapTile * tile, const TQPoint &pos )
{
    NOT_USED( tile );

    if ( _treemapContextMenu )
	_treemapContextMenu->popup( pos );
}


void
KDirStatApp::createTreemapView()
{
    if ( ! _showTreemapView->isChecked() || ! _treeView->tree() )
	return;

    if ( _treemapView )
	delete _treemapView;

    _treemapView = new KTreemapView( _treeView->tree(), _splitter,
				     TQSize( _splitter->width(), _treemapViewHeight ) );
    CHECK_PTR( _treemapView );

    connect( _treemapView,	TQT_SIGNAL( contextMenu( KTreemapTile *, const TQPoint & ) ),
	     this,		TQT_SLOT  ( contextMenu( KTreemapTile *, const TQPoint & ) ) );

    connect( _treemapView,	TQT_SIGNAL( treemapChanged()	),
	     this,		TQT_SLOT  ( updateActions()	) 	);

    connect( _treemapView,	TQT_SIGNAL( selectionChanged( KFileInfo * ) ),
	     this,      	TQT_SLOT  ( selectionChanged( KFileInfo * ) ) );

    if ( _activityTracker )
    {
	connect( _treemapView,		TQT_SIGNAL( userActivity ( int )	),
		 _activityTracker,	TQT_SLOT  ( trackActivity( int ) 	) );
    }

    _treemapView->show(); // TQSplitter needs explicit show() for new children
    updateActions();
}


void
KDirStatApp::deleteTreemapView()
{
    if ( _treemapView )
    {
	_treemapViewHeight = _treemapView->height();
	delete _treemapView;
    }

    _treemapView = 0;
    updateActions();
}



// EOF