KDirStat – a graphical disk usage utility
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

848 linhas
22KB

  1. /*
  2. * File name: kdirstatapp.cpp
  3. * Summary: The KDirStat application - menu bar, tool bar, ...
  4. * License: GPL - See file COPYING for details.
  5. *
  6. * Author: Stefan Hundhammer <sh@suse.de>
  7. * Parts auto-generated by KDevelop
  8. *
  9. * Updated: 2004-12-06
  10. */
  11. #include <tqclipboard.h>
  12. #include <tqpopupmenu.h>
  13. #include <tqsplitter.h>
  14. #include <tdeaccel.h>
  15. #include <tdeaction.h>
  16. #include <kapp.h>
  17. #include <tdeconfig.h>
  18. #include <tdefiledialog.h>
  19. #include <kiconloader.h>
  20. #include <tdelocale.h>
  21. #include <tdemenubar.h>
  22. #include <tdemessagebox.h>
  23. #include <krun.h>
  24. #include <kstatusbar.h>
  25. #include <kstdaction.h>
  26. #include <kurlrequesterdlg.h>
  27. #include "kdirstatapp.h"
  28. #include "kcleanupcollection.h"
  29. #include "kdirtree.h"
  30. #include "kpacman.h"
  31. #include "ktreemapview.h"
  32. #include "ktreemaptile.h"
  33. #include "kcleanupcollection.h"
  34. #include "kactivitytracker.h"
  35. #include "kdirtreeview.h"
  36. #include "kdirstatsettings.h"
  37. #define USER_CLEANUPS 10 // Number of user cleanup actions
  38. #define ID_STATUS_MSG 1
  39. #define ID_PACMAN 42
  40. #define PACMAN_WIDTH 350
  41. #define PACMAN_INTERVAL 75 // millisec
  42. #define INITIAL_FEEDBACK_REMINDER 2000L
  43. #define FEEDBACK_REMINDER_INTERVAL 1000L
  44. using namespace KDirStat;
  45. KDirStatApp::KDirStatApp( TQWidget* , const char* name )
  46. : TDEMainWindow( 0, name )
  47. {
  48. // Simple inits
  49. _activityTracker = 0; // Might or might not be needed
  50. // Those will be created delayed, only when needed
  51. _settingsDialog = 0;
  52. _feedbackDialog = 0;
  53. _treemapView = 0;
  54. _pacMan = 0;
  55. _pacManDelimiter = 0;
  56. // Set up internal (mainWin -> mainWin) connections
  57. connect( this, TQT_SIGNAL( readConfig ( void ) ),
  58. this, TQT_SLOT ( readMainWinConfig( void ) ) );
  59. connect( this, TQT_SIGNAL( saveConfig ( void ) ),
  60. this, TQT_SLOT ( saveMainWinConfig( void ) ) );
  61. // Create main window
  62. _splitter = new TQSplitter( Qt::Vertical, this );
  63. setCentralWidget( _splitter );
  64. _treeView = new KDirTreeView( _splitter );
  65. connect( _treeView, TQT_SIGNAL( progressInfo( const TQString & ) ),
  66. this, TQT_SLOT ( statusMsg ( const TQString & ) ) );
  67. connect( _treeView, TQT_SIGNAL( selectionChanged( KFileInfo * ) ),
  68. this, TQT_SLOT ( selectionChanged( KFileInfo * ) ) );
  69. connect( _treeView, TQT_SIGNAL( contextMenu( KDirTreeViewItem *, const TQPoint & ) ),
  70. this, TQT_SLOT ( contextMenu( KDirTreeViewItem *, const TQPoint & ) ) );
  71. connect( this, TQT_SIGNAL( readConfig() ), _treeView, TQT_SLOT ( readConfig() ) );
  72. connect( this, TQT_SIGNAL( saveConfig() ), _treeView, TQT_SLOT ( saveConfig() ) );
  73. connect( _treeView, TQT_SIGNAL( finished() ), TQT_TQOBJECT(this), TQT_SLOT( createTreemapView() ) );
  74. connect( _treeView, TQT_SIGNAL( aborted() ), TQT_TQOBJECT(this), TQT_SLOT( createTreemapView() ) );
  75. connect( _treeView, TQT_SIGNAL( startingReading() ), TQT_TQOBJECT(this), TQT_SLOT( deleteTreemapView() ) );
  76. connect( _treeView, TQT_SIGNAL( startingReading() ), TQT_TQOBJECT(this), TQT_SLOT( updateActions() ) );
  77. connect( _treeView, TQT_SIGNAL( finished() ), TQT_TQOBJECT(this), TQT_SLOT( updateActions() ) );
  78. connect( _treeView, TQT_SIGNAL( aborted() ), TQT_TQOBJECT(this), TQT_SLOT( updateActions() ) );
  79. // Call inits to invoke all other construction parts
  80. initStatusBar();
  81. initActions();
  82. initCleanups();
  83. createGUI();
  84. initActivityTracker();
  85. _treeViewContextMenu = (TQPopupMenu *) factory()->container( "treeViewContextMenu", this );
  86. _treemapContextMenu = (TQPopupMenu *) factory()->container( "treemapContextMenu", this );
  87. readMainWinConfig();
  88. // Disable certain actions at startup
  89. _editCopy->setEnabled( false );
  90. _reportMailToOwner->setEnabled( false );
  91. _fileRefreshAll->setEnabled( false );
  92. _fileRefreshSelected->setEnabled( false );
  93. updateActions();
  94. }
  95. KDirStatApp::~KDirStatApp()
  96. {
  97. delete _cleanupCollection;
  98. }
  99. void
  100. KDirStatApp::initActions()
  101. {
  102. _fileAskOpenDir = KStdAction::open ( TQT_TQOBJECT(this), TQT_SLOT( fileAskOpenDir() ), actionCollection() );
  103. _fileAskOpenUrl = new TDEAction( i18n( "Open &URL..." ), "konqueror", 0,
  104. TQT_TQOBJECT(this), TQT_SLOT( fileAskOpenUrl() ),
  105. actionCollection(), "file_open_url" );
  106. _fileOpenRecent = KStdAction::openRecent ( TQT_TQOBJECT(this), TQT_SLOT( fileOpenRecent( const KURL& ) ), actionCollection() );
  107. _fileCloseDir = KStdAction::close ( TQT_TQOBJECT(this), TQT_SLOT( fileCloseDir() ), actionCollection() );
  108. _fileRefreshAll = new TDEAction( i18n( "Refresh &All" ), "reload", 0,
  109. TQT_TQOBJECT(this), TQT_SLOT( refreshAll() ),
  110. actionCollection(), "file_refresh_all" );
  111. _fileRefreshSelected = new TDEAction( i18n( "Refresh &Selected" ), 0,
  112. TQT_TQOBJECT(this), TQT_SLOT( refreshSelected() ),
  113. actionCollection(), "file_refresh_selected" );
  114. _fileContinueReadingAtMountPoint = new TDEAction( i18n( "Continue Reading at &Mount Point" ), "drive-harddisk-mounted", 0,
  115. TQT_TQOBJECT(this), TQT_SLOT( refreshSelected() ), actionCollection(),
  116. "file_continue_reading_at_mount_point" );
  117. _fileStopReading = new TDEAction( i18n( "Stop Rea&ding" ), "process-stop", 0,
  118. TQT_TQOBJECT(this), TQT_SLOT( stopReading() ), actionCollection(),
  119. "file_stop_reading" );
  120. _fileQuit = KStdAction::quit ( TQT_TQOBJECT(kapp), TQT_SLOT( quit() ), actionCollection() );
  121. _editCopy = KStdAction::copy ( TQT_TQOBJECT(this), TQT_SLOT( editCopy() ), actionCollection() );
  122. _showToolBar = KStdAction::showToolbar ( TQT_TQOBJECT(this), TQT_SLOT( toggleToolBar() ), actionCollection() );
  123. _showStatusBar = KStdAction::showStatusbar ( TQT_TQOBJECT(this), TQT_SLOT( toggleStatusBar() ), actionCollection() );
  124. _cleanupOpenWith = new TDEAction( i18n( "Open With" ), 0,
  125. TQT_TQOBJECT(this), TQT_SLOT( cleanupOpenWith() ),
  126. actionCollection(), "cleanup_open_with" );
  127. _treemapZoomIn = new TDEAction( i18n( "Zoom in" ), "zoom-in", Key_Plus,
  128. TQT_TQOBJECT(this), TQT_SLOT( treemapZoomIn() ),
  129. actionCollection(), "treemap_zoom_in" );
  130. _treemapZoomOut = new TDEAction( i18n( "Zoom out" ), "zoom-out", Key_Minus,
  131. TQT_TQOBJECT(this), TQT_SLOT( treemapZoomOut() ),
  132. actionCollection(), "treemap_zoom_out" );
  133. _treemapSelectParent= new TDEAction( i18n( "Select Parent" ), "go-up", Key_Asterisk,
  134. TQT_TQOBJECT(this), TQT_SLOT( treemapSelectParent() ),
  135. actionCollection(), "treemap_select_parent" );
  136. _treemapRebuild = new TDEAction( i18n( "Rebuild Treemap" ), 0,
  137. TQT_TQOBJECT(this), TQT_SLOT( treemapRebuild() ),
  138. actionCollection(), "treemap_rebuild" );
  139. _showTreemapView = new TDEToggleAction( i18n( "Show Treemap" ), Key_F9,
  140. TQT_TQOBJECT(this), TQT_SLOT( toggleTreemapView() ),
  141. actionCollection(), "options_show_treemap" );
  142. new TDEAction( i18n( "Help about Treemaps" ), "help", 0,
  143. TQT_TQOBJECT(this), TQT_SLOT( treemapHelp() ),
  144. actionCollection(), "treemap_help" );
  145. TDEAction * pref = KStdAction::preferences( TQT_TQOBJECT(this), TQT_SLOT( preferences() ), actionCollection() );
  146. _reportMailToOwner = new TDEAction( i18n( "Send &Mail to Owner" ), "mail_generic", 0,
  147. TQT_TQOBJECT(_treeView), TQT_SLOT( sendMailToOwner() ),
  148. actionCollection(), "report_mail_to_owner" );
  149. _helpSendFeedbackMail = new TDEAction( i18n( "Send &Feedback Mail..." ), 0,
  150. TQT_TQOBJECT(this), TQT_SLOT( sendFeedbackMail() ),
  151. actionCollection(), "help_send_feedback_mail" );
  152. _fileAskOpenDir->setStatusText ( i18n( "Opens a directory" ) );
  153. _fileAskOpenUrl->setStatusText ( i18n( "Opens a (possibly remote) directory" ) );
  154. _fileOpenRecent->setStatusText ( i18n( "Opens a recently used directory" ) );
  155. _fileCloseDir->setStatusText ( i18n( "Closes the current directory" ) );
  156. _fileRefreshAll->setStatusText ( i18n( "Re-reads the entire directory tree" ) );
  157. _fileRefreshSelected->setStatusText ( i18n( "Re-reads the selected subtree" ) );
  158. _fileContinueReadingAtMountPoint->setStatusText( i18n( "Scan mounted file systems" ) );
  159. _fileStopReading->setStatusText ( i18n( "Stops directory reading" ) );
  160. _fileQuit->setStatusText ( i18n( "Quits the application" ) );
  161. _editCopy->setStatusText ( i18n( "Copies the URL of the selected item to the clipboard" ) );
  162. _showToolBar->setStatusText ( i18n( "Enables/disables the toolbar" ) );
  163. _showStatusBar->setStatusText ( i18n( "Enables/disables the statusbar" ) );
  164. _cleanupOpenWith->setStatusText ( i18n( "Open file or directory with arbitrary application" ) );
  165. _showTreemapView->setStatusText ( i18n( "Enables/disables the treemap view" ) );
  166. _treemapZoomIn->setStatusText ( i18n( "Zoom treemap in" ) );
  167. _treemapZoomOut->setStatusText ( i18n( "Zoom treemap out" ) );
  168. _treemapSelectParent->setStatusText ( i18n( "Select parent" ) );
  169. _treemapRebuild->setStatusText ( i18n( "Rebuild treemap to fit into available space" ) );
  170. pref->setStatusText ( i18n( "Opens the preferences dialog" ) );
  171. _reportMailToOwner->setStatusText ( i18n( "Sends a mail to the owner of the selected subtree" ) );
  172. }
  173. void
  174. KDirStatApp::initCleanups()
  175. {
  176. _cleanupCollection = new KCleanupCollection( actionCollection() );
  177. TQ_CHECK_PTR( _cleanupCollection );
  178. _cleanupCollection->addStdCleanups();
  179. _cleanupCollection->addUserCleanups( USER_CLEANUPS );
  180. _cleanupCollection->slotReadConfig();
  181. connect( _treeView, TQT_SIGNAL( selectionChanged( KFileInfo * ) ),
  182. _cleanupCollection, TQT_SIGNAL( selectionChanged( KFileInfo * ) ) );
  183. connect( this, TQT_SIGNAL( readConfig( void ) ),
  184. _cleanupCollection, TQT_SIGNAL( readConfig( void ) ) );
  185. connect( this, TQT_SIGNAL( saveConfig( void ) ),
  186. _cleanupCollection, TQT_SIGNAL( saveConfig( void ) ) );
  187. }
  188. void
  189. KDirStatApp::revertCleanupsToDefaults()
  190. {
  191. KCleanupCollection defaultCollection;
  192. defaultCollection.addStdCleanups();
  193. defaultCollection.addUserCleanups( USER_CLEANUPS );
  194. *_cleanupCollection = defaultCollection;
  195. }
  196. void
  197. KDirStatApp::initPacMan( bool enablePacMan )
  198. {
  199. if ( enablePacMan )
  200. {
  201. if ( ! _pacMan )
  202. {
  203. _pacMan = new KPacMan( toolBar(), 16, false, "tde toolbar widget" );
  204. _pacMan->setInterval( PACMAN_INTERVAL ); // millisec
  205. int id = ID_PACMAN;
  206. toolBar()->insertWidget( id, PACMAN_WIDTH, _pacMan );
  207. toolBar()->setItemAutoSized( id, false );
  208. _pacManDelimiter = new TQWidget( toolBar() );
  209. toolBar()->insertWidget( ++id, 1, _pacManDelimiter );
  210. connect( _treeView, TQT_SIGNAL( startingReading() ), _pacMan, TQT_SLOT( start() ) );
  211. connect( _treeView, TQT_SIGNAL( finished() ), _pacMan, TQT_SLOT( stop () ) );
  212. connect( _treeView, TQT_SIGNAL( aborted() ), _pacMan, TQT_SLOT( stop () ) );
  213. }
  214. }
  215. else
  216. {
  217. if ( _pacMan )
  218. {
  219. delete _pacMan;
  220. _pacMan = 0;
  221. }
  222. if ( _pacManDelimiter )
  223. {
  224. delete _pacManDelimiter;
  225. _pacManDelimiter = 0;
  226. }
  227. }
  228. }
  229. void
  230. KDirStatApp::initStatusBar()
  231. {
  232. statusBar()->insertItem( i18n( "Ready." ), ID_STATUS_MSG );
  233. }
  234. void
  235. KDirStatApp::initActivityTracker()
  236. {
  237. if ( ! doFeedbackReminder() )
  238. return;
  239. _activityTracker = new KActivityTracker( TQT_TQOBJECT(this), "Feedback",
  240. INITIAL_FEEDBACK_REMINDER );
  241. connect( _activityTracker, TQT_SIGNAL( thresholdReached() ),
  242. this, TQT_SLOT ( askForFeedback() ) );
  243. connect( _treeView, TQT_SIGNAL( userActivity( int ) ),
  244. _activityTracker, TQT_SLOT ( trackActivity( int ) ) );
  245. connect( _cleanupCollection, TQT_SIGNAL( userActivity( int ) ),
  246. _activityTracker, TQT_SLOT ( trackActivity( int ) ) );
  247. }
  248. void
  249. KDirStatApp::openURL( const KURL& url )
  250. {
  251. statusMsg( i18n( "Opening directory..." ) );
  252. _treeView->openURL( url );
  253. _fileOpenRecent->addURL( url );
  254. _fileRefreshAll->setEnabled( true );
  255. setCaption( url.fileName(), false );
  256. statusMsg( i18n( "Ready." ) );
  257. }
  258. void KDirStatApp::readMainWinConfig()
  259. {
  260. TDEConfig * config = kapp->config();
  261. config->setGroup( "General Options" );
  262. // Status settings of the various bars and views
  263. _showToolBar->setChecked( config->readBoolEntry( "Show Toolbar", true ) );
  264. toggleToolBar();
  265. _showStatusBar->setChecked( config->readBoolEntry( "Show Statusbar", true ) );
  266. toggleStatusBar();
  267. _showTreemapView->setChecked( config->readBoolEntry( "Show Treemap", true ) );
  268. toggleTreemapView();
  269. // Position settings of the various bars
  270. TDEToolBar::BarPosition toolBarPos;
  271. toolBarPos = ( TDEToolBar::BarPosition ) config->readNumEntry( "ToolBarPos", TDEToolBar::Top );
  272. toolBar( "mainToolBar" )->setBarPos( toolBarPos );
  273. _treemapViewHeight = config->readNumEntry( "TreemapViewHeight", 250 );
  274. // initialize the recent file list
  275. _fileOpenRecent->loadEntries( config,"Recent Files" );
  276. TQSize size = config->readSizeEntry( "Geometry" );
  277. if( ! size.isEmpty() )
  278. resize( size );
  279. config->setGroup( "Animation" );
  280. initPacMan( config->readBoolEntry( "ToolbarPacMan", true ) );
  281. _treeView->enablePacManAnimation( config->readBoolEntry( "DirTreePacMan", false ) );
  282. }
  283. void
  284. KDirStatApp::saveMainWinConfig()
  285. {
  286. TDEConfig * config = kapp->config();
  287. config->setGroup( "General Options" );
  288. config->writeEntry( "Geometry", size() );
  289. config->writeEntry( "Show Toolbar", _showToolBar->isChecked() );
  290. config->writeEntry( "Show Statusbar", _showStatusBar->isChecked() );
  291. config->writeEntry( "Show Treemap", _showTreemapView->isChecked() );
  292. config->writeEntry( "ToolBarPos", (int) toolBar( "mainToolBar" )->barPos() );
  293. if ( _treemapView )
  294. config->writeEntry( "TreemapViewHeight", _treemapView->height() );
  295. _fileOpenRecent->saveEntries( config,"Recent Files" );
  296. }
  297. void
  298. KDirStatApp::saveProperties( TDEConfig *config )
  299. {
  300. (void) config;
  301. // TODO
  302. }
  303. void
  304. KDirStatApp::readProperties( TDEConfig *config )
  305. {
  306. (void) config;
  307. // TODO
  308. }
  309. bool
  310. KDirStatApp::queryClose()
  311. {
  312. return true;
  313. }
  314. bool
  315. KDirStatApp::queryExit()
  316. {
  317. emit saveConfig();
  318. return true;
  319. }
  320. //============================================================================
  321. // Slots
  322. //============================================================================
  323. void
  324. KDirStatApp::fileAskOpenDir()
  325. {
  326. statusMsg( i18n( "Opening directory..." ) );
  327. KURL url = KFileDialog::getExistingDirectory( TQString(), this, i18n( "Open Directory..." ) );
  328. if( ! url.isEmpty() )
  329. openURL( fixedUrl( url.url() ) );
  330. statusMsg( i18n( "Ready." ) );
  331. }
  332. void
  333. KDirStatApp::fileAskOpenUrl()
  334. {
  335. statusMsg( i18n( "Opening URL..." ) );
  336. KURL url = KURLRequesterDlg::getURL( TQString(), // startDir
  337. this, i18n( "Open URL..." ) );
  338. if( ! url.isEmpty() )
  339. openURL( fixedUrl( url.url() ) );
  340. statusMsg( i18n( "Ready." ) );
  341. }
  342. void
  343. KDirStatApp::fileOpenRecent( const KURL& url )
  344. {
  345. statusMsg( i18n( "Opening directory..." ) );
  346. if( ! url.isEmpty() )
  347. openURL( fixedUrl( url.url() ) );
  348. statusMsg( i18n( "Ready." ) );
  349. }
  350. void
  351. KDirStatApp::fileCloseDir()
  352. {
  353. statusMsg( i18n( "Closing directory..." ) );
  354. _treeView->clear();
  355. _fileRefreshAll->setEnabled( false );
  356. close();
  357. statusMsg( i18n( "Ready." ) );
  358. }
  359. void
  360. KDirStatApp::refreshAll()
  361. {
  362. statusMsg( i18n( "Refreshing directory tree..." ) );
  363. _treeView->refreshAll();
  364. statusMsg( i18n( "Ready." ) );
  365. }
  366. void
  367. KDirStatApp::refreshSelected()
  368. {
  369. if ( ! _treeView->selection() )
  370. return;
  371. statusMsg( i18n( "Refreshing selected subtree..." ) );
  372. _treeView->refreshSelected();
  373. statusMsg( i18n( "Ready." ) );
  374. }
  375. void
  376. KDirStatApp::stopReading()
  377. {
  378. _treeView->abortReading();
  379. }
  380. void
  381. KDirStatApp::editCopy()
  382. {
  383. if ( _treeView->selection() )
  384. kapp->clipboard()->setText( TQString::fromLocal8Bit(_treeView->selection()->orig()->url()) );
  385. #if 0
  386. #warning debug
  387. if ( _activityTracker )
  388. _activityTracker->trackActivity( 800 );
  389. #endif
  390. }
  391. void
  392. KDirStatApp::cleanupOpenWith()
  393. {
  394. if ( ! _treeView->selection() )
  395. return;
  396. KFileInfo * sel = _treeView->selection()->orig();
  397. if ( sel->isDotEntry() )
  398. return;
  399. KURL::List urlList( KURL( sel->url() ) );
  400. KRun::displayOpenWithDialog( urlList, false );
  401. }
  402. void
  403. KDirStatApp::selectionChanged( KFileInfo *selection )
  404. {
  405. if ( selection )
  406. {
  407. _editCopy->setEnabled( true );
  408. _reportMailToOwner->setEnabled( true );
  409. _fileRefreshSelected->setEnabled( ! selection->isDotEntry() );
  410. _cleanupOpenWith->setEnabled( ! selection->isDotEntry() );
  411. if ( selection->isMountPoint() &&
  412. selection->readState() == KDirOnRequestOnly )
  413. {
  414. _fileContinueReadingAtMountPoint->setEnabled( true );
  415. }
  416. else
  417. _fileContinueReadingAtMountPoint->setEnabled( false );
  418. statusMsg( TQString::fromLocal8Bit(selection->url()) );
  419. }
  420. else
  421. {
  422. _editCopy->setEnabled( false );
  423. _reportMailToOwner->setEnabled( false );
  424. _fileRefreshSelected->setEnabled( false );
  425. _fileContinueReadingAtMountPoint->setEnabled( false );
  426. _cleanupOpenWith->setEnabled( false );
  427. statusMsg( "" );
  428. }
  429. updateActions();
  430. }
  431. void
  432. KDirStatApp::updateActions()
  433. {
  434. _treemapZoomIn->setEnabled ( _treemapView && _treemapView->canZoomIn() );
  435. _treemapZoomOut->setEnabled( _treemapView && _treemapView->canZoomOut() );
  436. _treemapRebuild->setEnabled( _treemapView && _treemapView->rootTile() );
  437. _treemapSelectParent->setEnabled( _treemapView && _treemapView->canSelectParent() );
  438. if ( _treeView->tree() && _treeView->tree()->isBusy() )
  439. _fileStopReading->setEnabled( true );
  440. else
  441. _fileStopReading->setEnabled( false );
  442. }
  443. void
  444. KDirStatApp::treemapZoomIn()
  445. {
  446. if ( _treemapView )
  447. {
  448. _treemapView->zoomIn();
  449. updateActions();
  450. }
  451. }
  452. void
  453. KDirStatApp::treemapZoomOut()
  454. {
  455. if ( _treemapView )
  456. {
  457. _treemapView->zoomOut();
  458. updateActions();
  459. }
  460. }
  461. void
  462. KDirStatApp::treemapSelectParent()
  463. {
  464. if ( _treemapView )
  465. {
  466. _treemapView->selectParent();
  467. updateActions();
  468. }
  469. }
  470. void
  471. KDirStatApp::treemapRebuild()
  472. {
  473. if ( _treemapView )
  474. {
  475. _treemapView->rebuildTreemap();
  476. updateActions();
  477. }
  478. }
  479. void
  480. KDirStatApp::treemapHelp()
  481. {
  482. kapp->invokeHelp( "treemap_intro" );
  483. }
  484. void
  485. KDirStatApp::toggleToolBar()
  486. {
  487. if ( _showToolBar->isChecked() ) toolBar( "mainToolBar" )->show();
  488. else toolBar( "mainToolBar" )->hide();
  489. }
  490. void
  491. KDirStatApp::toggleStatusBar()
  492. {
  493. if ( _showStatusBar->isChecked() ) statusBar()->show();
  494. else statusBar()->hide();
  495. }
  496. void
  497. KDirStatApp::toggleTreemapView()
  498. {
  499. if ( _showTreemapView->isChecked() )
  500. {
  501. if ( ! _treemapView )
  502. createTreemapView();
  503. }
  504. else
  505. {
  506. if ( _treemapView )
  507. deleteTreemapView();
  508. }
  509. }
  510. void
  511. KDirStatApp::preferences()
  512. {
  513. if ( ! _settingsDialog )
  514. {
  515. _settingsDialog = new KDirStat::KSettingsDialog( this );
  516. TQ_CHECK_PTR( _settingsDialog );
  517. }
  518. if ( ! _settingsDialog->isVisible() )
  519. _settingsDialog->show();
  520. }
  521. void
  522. KDirStatApp::askForFeedback()
  523. {
  524. if ( ! doFeedbackReminder() )
  525. return;
  526. TDEConfig * config = kapp->config();
  527. switch ( KMessageBox::warningYesNoCancel( this,
  528. i18n( "Now that you know this program for some time,\n"
  529. "wouldn't you like to tell the authors your opinion about it?\n"
  530. "\n"
  531. "Open Source software depends on user feedback.\n"
  532. "Your opinion can help us make the software better." ),
  533. i18n( "Please tell us your opinion!" ), // caption
  534. i18n( "Open &Feedback Form..." ), // yesButton
  535. i18n( "&No, and don't ask again!" ) // noButton
  536. )
  537. )
  538. {
  539. case KMessageBox::Yes:
  540. sendFeedbackMail();
  541. break;
  542. case KMessageBox::No: // ...and don't ask again
  543. config->setGroup( "Feedback" );
  544. config->writeEntry( "dontAsk", true );
  545. config->sync(); // make sure this doesn't get lost even if the app is killed or crashes
  546. break;
  547. case KMessageBox::Cancel:
  548. break;
  549. }
  550. config->setGroup( "Feedback" );
  551. int remindersCount = config->readNumEntry ( "remindersCount", 0 );
  552. config->writeEntry( "remindersCount", ++remindersCount );
  553. if ( _activityTracker )
  554. {
  555. _activityTracker->setThreshold( _activityTracker->threshold()
  556. + FEEDBACK_REMINDER_INTERVAL );
  557. }
  558. }
  559. void
  560. KDirStatApp::feedbackMailSent()
  561. {
  562. TDEConfig * config = kapp->config();
  563. config->setGroup( "Feedback" );
  564. config->writeEntry( "mailSent", true );
  565. config->sync();
  566. }
  567. bool
  568. KDirStatApp::doFeedbackReminder()
  569. {
  570. TDEConfig * config = kapp->config();
  571. config->setGroup( "Feedback" );
  572. bool mailSent = config->readBoolEntry( "mailSent", false );
  573. bool dontAsk = config->readBoolEntry( "dontAsk", false );
  574. int remindersCount = config->readNumEntry ( "remindersCount", 0 );
  575. return !mailSent && !dontAsk && remindersCount < 5;
  576. }
  577. void
  578. KDirStatApp::statusMsg( const TQString &text )
  579. {
  580. // Change status message permanently
  581. statusBar()->clear();
  582. statusBar()->changeItem( text, ID_STATUS_MSG );
  583. }
  584. void
  585. KDirStatApp::contextMenu( KDirTreeViewItem * item, const TQPoint &pos )
  586. {
  587. NOT_USED( item );
  588. if ( _treeViewContextMenu )
  589. _treeViewContextMenu->popup( pos );
  590. }
  591. void
  592. KDirStatApp::contextMenu( KTreemapTile * tile, const TQPoint &pos )
  593. {
  594. NOT_USED( tile );
  595. if ( _treemapContextMenu )
  596. _treemapContextMenu->popup( pos );
  597. }
  598. void
  599. KDirStatApp::createTreemapView()
  600. {
  601. if ( ! _showTreemapView->isChecked() || ! _treeView->tree() )
  602. return;
  603. if ( _treemapView )
  604. delete _treemapView;
  605. _treemapView = new KTreemapView( _treeView->tree(), _splitter,
  606. TQSize( _splitter->width(), _treemapViewHeight ) );
  607. TQ_CHECK_PTR( _treemapView );
  608. connect( _treemapView, TQT_SIGNAL( contextMenu( KTreemapTile *, const TQPoint & ) ),
  609. this, TQT_SLOT ( contextMenu( KTreemapTile *, const TQPoint & ) ) );
  610. connect( _treemapView, TQT_SIGNAL( treemapChanged() ),
  611. this, TQT_SLOT ( updateActions() ) );
  612. connect( _treemapView, TQT_SIGNAL( selectionChanged( KFileInfo * ) ),
  613. this, TQT_SLOT ( selectionChanged( KFileInfo * ) ) );
  614. if ( _activityTracker )
  615. {
  616. connect( _treemapView, TQT_SIGNAL( userActivity ( int ) ),
  617. _activityTracker, TQT_SLOT ( trackActivity( int ) ) );
  618. }
  619. _treemapView->show(); // TQSplitter needs explicit show() for new children
  620. updateActions();
  621. }
  622. void
  623. KDirStatApp::deleteTreemapView()
  624. {
  625. if ( _treemapView )
  626. {
  627. _treemapViewHeight = _treemapView->height();
  628. delete _treemapView;
  629. }
  630. _treemapView = 0;
  631. updateActions();
  632. }
  633. #include "kdirstatapp.moc"
  634. // EOF