KDirStat – a graphical disk usage utility
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

kdirstatsettings.cpp 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056
  1. /*
  2. * File name: kdirstatsettings.cpp
  3. * Summary: Settings dialog for KDirStat
  4. * License: GPL - See file COPYING for details.
  5. * Author: Stefan Hundhammer <sh@suse.de>
  6. *
  7. * Updated: 2003-01-30
  8. */
  9. #include <tqbuttongroup.h>
  10. #include <tqcheckbox.h>
  11. #include <tqcombobox.h>
  12. #include <tqlabel.h>
  13. #include <tqlayout.h>
  14. #include <tqlineedit.h>
  15. #include <tqslider.h>
  16. #include <tqvbox.h>
  17. #include <tqhgroupbox.h>
  18. #include <tqvgroupbox.h>
  19. #include <tqspinbox.h>
  20. #include <kcolorbutton.h>
  21. #include <tdelocale.h>
  22. #include <tdemessagebox.h>
  23. #include "kdirtreeview.h"
  24. #include "ktreemapview.h"
  25. #include "kdirstatsettings.h"
  26. using namespace KDirStat;
  27. KSettingsDialog::KSettingsDialog( KDirStatApp *mainWin )
  28. : KDialogBase( Tabbed, // dialogFace
  29. i18n( "Settings" ), // caption
  30. Ok | Apply | Default | Cancel | Help, // buttonMask
  31. Ok, // defaultButton
  32. 0, // parent
  33. 0, // name
  34. false ) // modal
  35. , _mainWin( mainWin )
  36. {
  37. /**
  38. * This may seem like overkill, but I didn't find any other way to get
  39. * geometry management right with KDialogBase, yet maintain a modular and
  40. * object-oriented design:
  41. *
  42. * Each individual settings page is added with 'addVBoxPage()' to get some
  43. * initial geometry management. Only then can some generic widget be added
  44. * into this - and I WANT my settings pages to be generic widgets. I want
  45. * them to be self-sufficient - no monolithic mess of widget creation in my
  46. * code, intermixed with all kinds of layout objects.
  47. *
  48. * The ordinary KDialogBase::addPage() just creates a TQFrame which is too
  49. * dumb for any kind of geometry management - it cannot even handle one
  50. * single child right. So, let's have KDialogBase create something more
  51. * intelligent: A TQVBox (which is derived from TQFrame anyway). This TQVBox
  52. * gets only one child - the KSettingsPage. This KSettingsPage handles its
  53. * own layout.
  54. **/
  55. TQWidget * page;
  56. page = addVBoxPage( i18n( "&Cleanups" ) );
  57. _cleanupsPageIndex = pageIndex( page );
  58. new KCleanupPage( this, page, _mainWin );
  59. page = addVBoxPage( i18n( "&Tree Colors" ) );
  60. _treeColorsPageIndex = pageIndex( page );
  61. new KTreeColorsPage( this, page, _mainWin );
  62. page = addVBoxPage( i18n( "Tree&map" ) );
  63. _treemapPageIndex = pageIndex( page );
  64. new KTreemapPage( this, page, _mainWin );
  65. page = addVBoxPage( i18n( "&General" ) );
  66. _generalSettingsPageIndex = pageIndex( page );
  67. new KGeneralSettingsPage( this, page, _mainWin );
  68. // resize( sizeHint() );
  69. }
  70. KSettingsDialog::~KSettingsDialog()
  71. {
  72. // NOP
  73. }
  74. void
  75. KSettingsDialog::show()
  76. {
  77. emit aboutToShow();
  78. KDialogBase::show();
  79. }
  80. void
  81. KSettingsDialog::slotDefault()
  82. {
  83. if ( KMessageBox::warningContinueCancel( this,
  84. i18n( "Really revert all settings to their default values?\n"
  85. "You will lose all changes you ever made!" ),
  86. i18n( "Please Confirm" ), // caption
  87. i18n( "&Really Revert to Defaults" ) // continueButton
  88. ) == KMessageBox::Continue )
  89. {
  90. emit defaultClicked();
  91. emit applyClicked();
  92. }
  93. }
  94. void
  95. KSettingsDialog::slotHelp()
  96. {
  97. TQString helpTopic = "";
  98. if ( activePageIndex() == _cleanupsPageIndex ) helpTopic = "configuring_cleanups";
  99. else if ( activePageIndex() == _treeColorsPageIndex ) helpTopic = "tree_colors";
  100. else if ( activePageIndex() == _treemapPageIndex ) helpTopic = "treemap_settings";
  101. else if ( activePageIndex() == _generalSettingsPageIndex) helpTopic = "general_settings";
  102. // kdDebug() << "Help topic: " << helpTopic << endl;
  103. kapp->invokeHelp( helpTopic );
  104. }
  105. /*--------------------------------------------------------------------------*/
  106. KSettingsPage::KSettingsPage( KSettingsDialog * dialog,
  107. TQWidget * parent )
  108. : TQWidget( parent )
  109. {
  110. connect( dialog, TQT_SIGNAL( aboutToShow ( void ) ),
  111. this, TQT_SLOT ( setup ( void ) ) );
  112. connect( dialog, TQT_SIGNAL( okClicked ( void ) ),
  113. this, TQT_SLOT ( apply ( void ) ) );
  114. connect( dialog, TQT_SIGNAL( applyClicked ( void ) ),
  115. this, TQT_SLOT ( apply ( void ) ) );
  116. connect( dialog, TQT_SIGNAL( defaultClicked ( void ) ),
  117. this, TQT_SLOT ( revertToDefaults( void ) ) );
  118. }
  119. KSettingsPage::~KSettingsPage()
  120. {
  121. // NOP
  122. }
  123. /*--------------------------------------------------------------------------*/
  124. KTreeColorsPage::KTreeColorsPage( KSettingsDialog * dialog,
  125. TQWidget * parent,
  126. KDirStatApp * mainWin )
  127. : KSettingsPage( dialog, parent )
  128. , _mainWin( mainWin )
  129. , _treeView( mainWin->treeView() )
  130. , _maxButtons( KDirStatSettingsMaxColorButton )
  131. {
  132. // Outer layout box
  133. TQHBoxLayout * outerBox = new TQHBoxLayout( this,
  134. 0, // border
  135. dialog->spacingHint() );
  136. // Inner layout box with a column of color buttons
  137. TQGridLayout *grid = new TQGridLayout( _maxButtons, // rows
  138. _maxButtons + 1, // cols
  139. dialog->spacingHint() );
  140. outerBox->addLayout( grid, 1 );
  141. grid->setColStretch( 0, 0 ); // label column - dont' stretch
  142. for ( int i=1; i < _maxButtons; i++ )
  143. {
  144. grid->setColStretch( i, 1 ); // all other columns stretch as you like
  145. }
  146. for ( int i=0; i < _maxButtons; i++ )
  147. {
  148. TQString labelText;
  149. labelText=i18n( "Tree Level %1" ).arg(i+1);
  150. _colorLabel[i] = new TQLabel( labelText, this );
  151. grid->addWidget( _colorLabel [i], i, 0 );
  152. _colorButton[i] = new KColorButton( this );
  153. _colorButton[i]->setMinimumSize( TQSize( 80, 10 ) );
  154. grid->addMultiCellWidget( _colorButton [i], i, i, i+1, _maxButtons );
  155. grid->setRowStretch( i, 1 );
  156. }
  157. // Vertical slider
  158. _slider = new TQSlider( 1, // minValue
  159. _maxButtons, // maxValue
  160. 1, // pageStep
  161. 1, // value
  162. Qt::Vertical,
  163. this );
  164. outerBox->addWidget( _slider, 0 );
  165. outerBox->activate();
  166. connect( _slider, TQT_SIGNAL( valueChanged( int ) ),
  167. this, TQT_SLOT ( enableColors( int ) ) );
  168. }
  169. KTreeColorsPage::~KTreeColorsPage()
  170. {
  171. // NOP
  172. }
  173. void
  174. KTreeColorsPage::apply()
  175. {
  176. _treeView->setUsedFillColors( _slider->value() );
  177. for ( int i=0; i < _maxButtons; i++ )
  178. {
  179. _treeView->setFillColor( i, _colorButton [i]->color() );
  180. }
  181. _treeView->triggerUpdate();
  182. }
  183. void
  184. KTreeColorsPage::revertToDefaults()
  185. {
  186. _treeView->setDefaultFillColors();
  187. setup();
  188. }
  189. void
  190. KTreeColorsPage::setup()
  191. {
  192. for ( int i=0; i < _maxButtons; i++ )
  193. {
  194. _colorButton [i]->setColor( _treeView->rawFillColor(i) );
  195. }
  196. _slider->setValue( _treeView->usedFillColors() );
  197. enableColors( _treeView->usedFillColors() );
  198. }
  199. void
  200. KTreeColorsPage::enableColors( int maxColors )
  201. {
  202. for ( int i=0; i < _maxButtons; i++ )
  203. {
  204. _colorButton [i]->setEnabled( i < maxColors );
  205. _colorLabel [i]->setEnabled( i < maxColors );
  206. }
  207. }
  208. /*--------------------------------------------------------------------------*/
  209. KCleanupPage::KCleanupPage( KSettingsDialog * dialog,
  210. TQWidget * parent,
  211. KDirStatApp * mainWin )
  212. : KSettingsPage( dialog, parent )
  213. , _mainWin( mainWin )
  214. , _currentCleanup( 0 )
  215. {
  216. // Copy the main window's cleanup collection.
  217. _workCleanupCollection = *mainWin->cleanupCollection();
  218. // Create layout and widgets.
  219. TQHBoxLayout * layout = new TQHBoxLayout( this,
  220. 0, // border
  221. dialog->spacingHint() ); // spacing
  222. _listBox = new KCleanupListBox( this );
  223. _props = new KCleanupPropertiesPage( this, mainWin );
  224. // Connect list box signals to reflect changes in the list
  225. // selection in the cleanup properties page - whenever the user
  226. // clicks on a different cleanup in the list, the properties page
  227. // will display that cleanup's values.
  228. connect( _listBox, TQT_SIGNAL( selectCleanup( KCleanup * ) ),
  229. this, TQT_SLOT ( changeCleanup( KCleanup * ) ) );
  230. // Fill list box so it can determine a reasonable startup geometry - that
  231. // doesn't work if it happens only later.
  232. setup();
  233. // Now that _listBox will (hopefully) have determined a reasonable
  234. // default geometry, add the widgets to the layout.
  235. layout->addWidget( _listBox, 0 );
  236. layout->addWidget( _props , 1 );
  237. layout->activate();
  238. }
  239. KCleanupPage::~KCleanupPage()
  240. {
  241. // NOP
  242. }
  243. void
  244. KCleanupPage::changeCleanup( KCleanup * newCleanup )
  245. {
  246. if ( _currentCleanup && newCleanup != _currentCleanup )
  247. {
  248. storeProps( _currentCleanup );
  249. }
  250. _currentCleanup = newCleanup;
  251. _props->setFields( _currentCleanup );
  252. }
  253. void
  254. KCleanupPage::apply()
  255. {
  256. exportCleanups();
  257. }
  258. void
  259. KCleanupPage::revertToDefaults()
  260. {
  261. _mainWin->revertCleanupsToDefaults();
  262. setup();
  263. }
  264. void
  265. KCleanupPage::setup()
  266. {
  267. importCleanups();
  268. // Fill the list box.
  269. _listBox->clear();
  270. KCleanupList cleanupList = _workCleanupCollection.cleanupList();
  271. KCleanupListIterator it( cleanupList );
  272. while ( *it )
  273. {
  274. _listBox->insert( *it );
  275. ++it;
  276. }
  277. // (Re-) Initialize list box.
  278. // _listBox->resize( _listBox->sizeHint() );
  279. _listBox->setSelected( 0, true );
  280. }
  281. void
  282. KCleanupPage::importCleanups()
  283. {
  284. // Copy the main window's cleanup collecton to _workCleanupCollection.
  285. _workCleanupCollection = * _mainWin->cleanupCollection();
  286. // Pointers to the old collection contents are now invalid!
  287. _currentCleanup = 0;
  288. }
  289. void
  290. KCleanupPage::exportCleanups()
  291. {
  292. // Retrieve any pending changes from the properties page and store
  293. // them in the current cleanup.
  294. storeProps( _currentCleanup );
  295. // Copy the _workCleanupCollection to the main window's cleanup
  296. // collection.
  297. * _mainWin->cleanupCollection() = _workCleanupCollection;
  298. }
  299. void
  300. KCleanupPage::storeProps( KCleanup * cleanup )
  301. {
  302. if ( cleanup )
  303. {
  304. // Retrieve the current fields contents and store them in the current
  305. // cleanup.
  306. *cleanup = _props->fields();
  307. // Update the list box accordingly - the cleanup's title may have
  308. // changed, too!
  309. _listBox->updateTitle( cleanup );
  310. }
  311. }
  312. /*--------------------------------------------------------------------------*/
  313. KCleanupListBox::KCleanupListBox( TQWidget *parent )
  314. : TQListBox( parent )
  315. {
  316. _selection = 0;
  317. connect( this,
  318. TQT_SIGNAL( selectionChanged( TQListBoxItem *) ),
  319. TQT_SLOT ( selectCleanup ( TQListBoxItem *) ) );
  320. }
  321. TQSize
  322. KCleanupListBox::sizeHint() const
  323. {
  324. // FIXME: Is this still needed with TQt 2.x?
  325. if ( count() < 1 )
  326. {
  327. // As long as the list is empty, sizeHint() would default to
  328. // (0,0) which is ALWAYS just a pain in the ass. We'd rather
  329. // have an absolutely random value than this.
  330. return TQSize( 100, 100 );
  331. }
  332. else
  333. {
  334. // Calculate the list contents and take 3D frames (2*2 pixels)
  335. // into account.
  336. return TQSize ( maxItemWidth() + 5,
  337. count() * itemHeight( 0 ) + 4 );
  338. }
  339. }
  340. void
  341. KCleanupListBox::insert( KCleanup * cleanup )
  342. {
  343. // Create a new listbox item - this will insert itself (!) automatically.
  344. // It took me half an afternoon to figure _this_ out. Not too intuitive
  345. // when there is an insertItem() method, too, eh?
  346. new KCleanupListBoxItem( this, cleanup );
  347. }
  348. void
  349. KCleanupListBox::selectCleanup( TQListBoxItem * listBoxItem )
  350. {
  351. KCleanupListBoxItem * item = (KCleanupListBoxItem *) listBoxItem;
  352. _selection = item->cleanup();
  353. emit selectCleanup( _selection );
  354. }
  355. void
  356. KCleanupListBox::updateTitle( KCleanup * cleanup )
  357. {
  358. KCleanupListBoxItem * item = (KCleanupListBoxItem *) firstItem();
  359. while ( item )
  360. {
  361. if ( ! cleanup || item->cleanup() == cleanup )
  362. item->updateTitle();
  363. item = (KCleanupListBoxItem *) item->next();
  364. }
  365. }
  366. /*--------------------------------------------------------------------------*/
  367. KCleanupListBoxItem::KCleanupListBoxItem( KCleanupListBox * listBox,
  368. KCleanup * cleanup )
  369. : TQListBoxText( listBox )
  370. , _cleanup( cleanup )
  371. {
  372. TQ_CHECK_PTR( cleanup );
  373. setText( cleanup->cleanTitle() );
  374. }
  375. void
  376. KCleanupListBoxItem::updateTitle()
  377. {
  378. setText( _cleanup->cleanTitle() );
  379. }
  380. /*--------------------------------------------------------------------------*/
  381. KCleanupPropertiesPage::KCleanupPropertiesPage( TQWidget * parent,
  382. KDirStatApp * mainWin )
  383. : TQWidget( parent )
  384. , _mainWin( mainWin )
  385. {
  386. TQVBoxLayout *outerBox = new TQVBoxLayout( this, 0, 0 ); // border, spacing
  387. // The topmost check box: "Enabled".
  388. _enabled = new TQCheckBox( i18n( "&Enabled" ), this );
  389. outerBox->addWidget( _enabled, 0 );
  390. outerBox->addSpacing( 7 );
  391. outerBox->addStretch();
  392. connect( _enabled, TQT_SIGNAL( toggled ( bool ) ),
  393. this, TQT_SLOT ( enableFields( bool ) ) );
  394. // All other widgets of this page are grouped together in a
  395. // separate subwidget so they can all be enabled / disabled
  396. // together.
  397. _fields = new TQWidget( this );
  398. outerBox->addWidget( _fields, 1 );
  399. TQVBoxLayout *fieldsBox = new TQVBoxLayout( _fields );
  400. // Grid layout for the edit fields, their labels, some
  401. // explanatory text and the "recurse?" check box.
  402. TQGridLayout *grid = new TQGridLayout( 7, // rows
  403. 2, // cols
  404. 4 ); // spacing
  405. fieldsBox->addLayout( grid, 0 );
  406. fieldsBox->addStretch();
  407. fieldsBox->addSpacing( 5 );
  408. grid->setColStretch( 0, 0 ); // column for field labels - dont' stretch
  409. grid->setColStretch( 1, 1 ); // column for edit fields - stretch as you like
  410. // Edit fields for cleanup action title and command line.
  411. TQLabel *label;
  412. _title = new TQLineEdit( _fields ); grid->addWidget( _title, 0, 1 );
  413. _command = new TQLineEdit( _fields ); grid->addWidget( _command, 1, 1 );
  414. label = new TQLabel( _title, i18n( "&Title:" ), _fields ); grid->addWidget( label, 0, 0 );
  415. label = new TQLabel( _command, i18n( "&Command Line:" ), _fields ); grid->addWidget( label, 1, 0 );
  416. label = new TQLabel( i18n( "%p Full Path" ), _fields );
  417. grid->addWidget( label, 2, 1 );
  418. label = new TQLabel( i18n( "%n File / Directory Name Without Path" ), _fields );
  419. grid->addWidget( label, 3, 1 );
  420. label = new TQLabel( i18n( "%t TDE Trash Directory" ), _fields );
  421. grid->addWidget( label, 4, 1 );
  422. // "Recurse into subdirs" check box
  423. _recurse = new TQCheckBox( i18n( "&Recurse into Subdirectories" ), _fields );
  424. grid->addWidget( _recurse, 5, 1 );
  425. // "Ask for confirmation" check box
  426. _askForConfirmation = new TQCheckBox( i18n( "&Ask for Confirmation" ), _fields );
  427. grid->addWidget( _askForConfirmation, 6, 1 );
  428. // The "Works for..." check boxes, grouped together in a button group.
  429. TQButtonGroup *worksFor = new TQButtonGroup( i18n( "Works for..." ), _fields );
  430. TQVBoxLayout *worksForBox = new TQVBoxLayout( worksFor, 15, 2 );
  431. fieldsBox->addWidget( worksFor, 0 );
  432. fieldsBox->addSpacing( 5 );
  433. fieldsBox->addStretch();
  434. _worksForDir = new TQCheckBox( i18n( "&Directories" ), worksFor );
  435. _worksForFile = new TQCheckBox( i18n( "&Files" ), worksFor );
  436. _worksForDotEntry = new TQCheckBox( i18n( "<Files> P&seudo Entries"), worksFor );
  437. worksForBox->addWidget( _worksForDir , 1 );
  438. worksForBox->addWidget( _worksForFile , 1 );
  439. worksForBox->addWidget( _worksForDotEntry , 1 );
  440. worksForBox->addSpacing( 5 );
  441. _worksForProtocols = new TQComboBox( false, worksFor );
  442. worksForBox->addWidget( _worksForProtocols, 1 );
  443. _worksForProtocols->insertItem( i18n( "On Local Machine Only ('file:/' Protocol)" ) );
  444. _worksForProtocols->insertItem( i18n( "Network Transparent (ftp, smb, tar, ...)" ) );
  445. // Grid layout for combo boxes at the bottom
  446. grid = new TQGridLayout( 1, // rows
  447. 2, // cols
  448. 4 ); // spacing
  449. fieldsBox->addLayout( grid, 0 );
  450. fieldsBox->addSpacing( 5 );
  451. fieldsBox->addStretch();
  452. int row = 0;
  453. // The "Refresh policy" combo box
  454. _refreshPolicy = new TQComboBox( false, _fields );
  455. grid->addWidget( _refreshPolicy, row, 1 );
  456. label = new TQLabel( _refreshPolicy, i18n( "Refresh &Policy:" ), _fields );
  457. grid->addWidget( label, row++, 0 );
  458. // Caution: The order of those entries must match the order of
  459. // 'enum RefreshPolicy' in 'kcleanup.h'!
  460. //
  461. // I don't like this one bit. The ComboBox should provide something better
  462. // than mere numeric IDs. One of these days I'm going to rewrite this
  463. // thing!
  464. _refreshPolicy->insertItem( i18n( "No Refresh" ) );
  465. _refreshPolicy->insertItem( i18n( "Refresh This Entry" ) );
  466. _refreshPolicy->insertItem( i18n( "Refresh This Entry's Parent" ) );
  467. _refreshPolicy->insertItem( i18n( "Assume Entry Has Been Deleted" ) );
  468. outerBox->activate();
  469. setMinimumSize( sizeHint() );
  470. }
  471. void
  472. KCleanupPropertiesPage::enableFields( bool active )
  473. {
  474. _fields->setEnabled( active );
  475. }
  476. void
  477. KCleanupPropertiesPage::setFields( const KCleanup * cleanup )
  478. {
  479. _id = cleanup->id();
  480. _enabled->setChecked ( cleanup->enabled() );
  481. _title->setText ( cleanup->title() );
  482. _command->setText ( cleanup->command() );
  483. _recurse->setChecked ( cleanup->recurse() );
  484. _askForConfirmation->setChecked ( cleanup->askForConfirmation() );
  485. _worksForDir->setChecked ( cleanup->worksForDir() );
  486. _worksForFile->setChecked ( cleanup->worksForFile() );
  487. _worksForDotEntry->setChecked ( cleanup->worksForDotEntry() );
  488. _worksForProtocols->setCurrentItem ( cleanup->worksLocalOnly() ? 0 : 1 );
  489. _refreshPolicy->setCurrentItem ( cleanup->refreshPolicy() );
  490. enableFields( cleanup->enabled() );
  491. }
  492. KCleanup
  493. KCleanupPropertiesPage::fields() const
  494. {
  495. KCleanup cleanup( _id );
  496. cleanup.setEnabled ( _enabled->isChecked() );
  497. cleanup.setTitle ( _title->text() );
  498. cleanup.setCommand ( _command->text() );
  499. cleanup.setRecurse ( _recurse->isChecked() );
  500. cleanup.setAskForConfirmation ( _askForConfirmation->isChecked() );
  501. cleanup.setWorksForDir ( _worksForDir->isChecked() );
  502. cleanup.setWorksForFile ( _worksForFile->isChecked() );
  503. cleanup.setWorksLocalOnly ( _worksForProtocols->currentItem() == 0 ? true : false );
  504. cleanup.setWorksForDotEntry ( _worksForDotEntry->isChecked() );
  505. cleanup.setRefreshPolicy ( (KCleanup::RefreshPolicy) _refreshPolicy->currentItem() );
  506. return cleanup;
  507. }
  508. /*--------------------------------------------------------------------------*/
  509. KGeneralSettingsPage::KGeneralSettingsPage( KSettingsDialog * dialog,
  510. TQWidget * parent,
  511. KDirStatApp * mainWin )
  512. : KSettingsPage( dialog, parent )
  513. , _mainWin( mainWin )
  514. , _treeView( mainWin->treeView() )
  515. {
  516. // Create layout and widgets.
  517. TQVBoxLayout * layout = new TQVBoxLayout( this, 5, // border
  518. dialog->spacingHint() ); // spacing
  519. TQVGroupBox * gbox = new TQVGroupBox( i18n( "Directory Reading" ), this );
  520. layout->addWidget( gbox );
  521. _crossFileSystems = new TQCheckBox( i18n( "Cross &File System Boundaries" ), gbox );
  522. _enableLocalDirReader = new TQCheckBox( i18n( "Use Optimized &Local Directory Read Methods" ), gbox );
  523. connect( _enableLocalDirReader, TQT_SIGNAL( stateChanged( int ) ),
  524. this, TQT_SLOT ( checkEnabledState() ) );
  525. layout->addSpacing( 10 );
  526. gbox = new TQVGroupBox( i18n( "Animation" ), this );
  527. layout->addWidget( gbox );
  528. _enableToolBarAnimation = new TQCheckBox( i18n( "P@cM@n Animation in Tool &Bar" ), gbox );
  529. _enableTreeViewAnimation = new TQCheckBox( i18n( "P@cM@n Animation in Directory &Tree" ), gbox );
  530. }
  531. KGeneralSettingsPage::~KGeneralSettingsPage()
  532. {
  533. // NOP
  534. }
  535. void
  536. KGeneralSettingsPage::apply()
  537. {
  538. TDEConfig * config = kapp->config();
  539. config->setGroup( "Directory Reading" );
  540. config->writeEntry( "CrossFileSystems", _crossFileSystems->isChecked() );
  541. config->writeEntry( "EnableLocalDirReader", _enableLocalDirReader->isChecked() );
  542. config->setGroup( "Animation" );
  543. config->writeEntry( "ToolbarPacMan", _enableToolBarAnimation->isChecked() );
  544. config->writeEntry( "DirTreePacMan", _enableTreeViewAnimation->isChecked() );
  545. _mainWin->initPacMan( _enableToolBarAnimation->isChecked() );
  546. _treeView->enablePacManAnimation( _enableTreeViewAnimation->isChecked() );
  547. }
  548. void
  549. KGeneralSettingsPage::revertToDefaults()
  550. {
  551. _crossFileSystems->setChecked( false );
  552. _enableLocalDirReader->setChecked( true );
  553. _enableToolBarAnimation->setChecked( true );
  554. _enableTreeViewAnimation->setChecked( false );
  555. }
  556. void
  557. KGeneralSettingsPage::setup()
  558. {
  559. TDEConfig * config = kapp->config();
  560. config->setGroup( "Directory Reading" );
  561. _crossFileSystems->setChecked ( config->readBoolEntry( "CrossFileSystems" , false) );
  562. _enableLocalDirReader->setChecked ( config->readBoolEntry( "EnableLocalDirReader" , true ) );
  563. _enableToolBarAnimation->setChecked ( _mainWin->pacManEnabled() );
  564. _enableTreeViewAnimation->setChecked( _treeView->doPacManAnimation() );
  565. checkEnabledState();
  566. }
  567. void
  568. KGeneralSettingsPage::checkEnabledState()
  569. {
  570. _crossFileSystems->setEnabled( _enableLocalDirReader->isChecked() );
  571. }
  572. /*--------------------------------------------------------------------------*/
  573. KTreemapPage::KTreemapPage( KSettingsDialog * dialog,
  574. TQWidget * parent,
  575. KDirStatApp * mainWin )
  576. : KSettingsPage( dialog, parent )
  577. , _mainWin( mainWin )
  578. {
  579. // kdDebug() << k_funcinfo << endl;
  580. TQVBoxLayout * layout = new TQVBoxLayout( this, 0, 0 ); // parent, border, spacing
  581. TQVBox * vbox = new TQVBox( this );
  582. vbox->setSpacing( dialog->spacingHint() );
  583. layout->addWidget( vbox );
  584. _squarify = new TQCheckBox( i18n( "S&quarify Treemap" ), vbox );
  585. _doCushionShading = new TQCheckBox( i18n( "Use C&ushion Shading" ), vbox );
  586. // Cushion parameters
  587. TQVGroupBox * gbox = new TQVGroupBox( i18n( "Cushion Parameters" ), vbox );
  588. _cushionParams = gbox;
  589. gbox->addSpace( 7 );
  590. gbox->setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Expanding ) );
  591. TQLabel * label = new TQLabel( i18n( "Ambient &Light" ), gbox );
  592. TQHBox * hbox = new TQHBox( gbox );
  593. _ambientLight = new TQSlider ( MinAmbientLight, MaxAmbientLight, 10, // min, max, pageStep
  594. DefaultAmbientLight,Qt::Horizontal, hbox );
  595. _ambientLightSB = new TQSpinBox( MinAmbientLight, MaxAmbientLight, 1, // min, max, step
  596. hbox );
  597. _ambientLightSB->setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Minimum ) );
  598. label->setBuddy( _ambientLightSB );
  599. gbox->addSpace( 7 );
  600. label = new TQLabel( i18n( "&Height Scale" ), gbox );
  601. hbox = new TQHBox( gbox );
  602. _heightScalePercent = new TQSlider( MinHeightScalePercent, MaxHeightScalePercent, 10, // min, max, pageStep
  603. DefaultHeightScalePercent,Qt::Horizontal, hbox );
  604. _heightScalePercentSB = new TQSpinBox( MinHeightScalePercent, MaxHeightScalePercent, 1, // min, max, step
  605. hbox );
  606. _heightScalePercentSB->setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Minimum ) );
  607. label->setBuddy( _heightScalePercentSB );
  608. gbox->addSpace( 10 );
  609. _ensureContrast = new TQCheckBox( i18n( "Draw Lines if Lo&w Contrast" ), gbox );
  610. hbox = new TQHBox( gbox );
  611. _forceCushionGrid = new TQCheckBox( i18n( "Always Draw &Grid" ), hbox );
  612. addHStretch( hbox );
  613. _cushionGridColorL = new TQLabel( " " + i18n( "Gr&id Color: " ), hbox );
  614. _cushionGridColor = new KColorButton( hbox );
  615. _cushionGridColorL->setBuddy( _cushionGridColor );
  616. _cushionGridColorL->setAlignment( AlignRight | AlignVCenter );
  617. // addVStretch( vbox );
  618. // Plain treemaps parameters
  619. _plainTileParams = new TQHGroupBox( i18n( "Colors for Plain Treemaps" ), vbox );
  620. _plainTileParams->addSpace( 7 );
  621. label = new TQLabel( i18n( "&Files: " ), _plainTileParams );
  622. _fileFillColor = new KColorButton( _plainTileParams );
  623. label->setBuddy( _fileFillColor );
  624. label->setAlignment( AlignRight | AlignVCenter );
  625. label = new TQLabel( " " + i18n( "&Directories: " ), _plainTileParams );
  626. _dirFillColor = new KColorButton( _plainTileParams );
  627. label->setBuddy( _dirFillColor );
  628. label->setAlignment( AlignRight | AlignVCenter );
  629. label = new TQLabel( i18n( "Gr&id: " ), _plainTileParams );
  630. _outlineColor = new KColorButton( _plainTileParams );
  631. label->setBuddy( _outlineColor );
  632. label->setAlignment( AlignRight | AlignVCenter );
  633. // Misc
  634. TQWidget * gridBox = new TQWidget( vbox );
  635. TQGridLayout * grid = new TQGridLayout( gridBox, 2, 3, dialog->spacingHint() ); // rows, cols, spacing
  636. grid->setColStretch( 0, 0 ); // (col, stretch) don't stretch this column
  637. grid->setColStretch( 1, 0 ); // don't stretch
  638. grid->setColStretch( 2, 1 ); // stretch this as you like
  639. label = new TQLabel( i18n( "Hi&ghlight R&ectangle: " ), gridBox );
  640. _highlightColor = new KColorButton( gridBox );
  641. label->setBuddy( _highlightColor );
  642. grid->addWidget( label, 0, 0 );
  643. grid->addWidget( _highlightColor, 0, 1 );
  644. label = new TQLabel( i18n( "Minim&um Treemap Tile Size: " ), gridBox );
  645. _minTileSize = new TQSpinBox( 0, 30, 1, gridBox ); // min, max, step, parent
  646. label->setBuddy( _minTileSize );
  647. grid->addWidget( label, 1, 0 );
  648. grid->addWidget( _minTileSize, 1, 1 );
  649. _autoResize = new TQCheckBox( i18n( "Auto-&Resize Treemap" ), vbox );
  650. // Connections
  651. connect( _ambientLight, TQT_SIGNAL( valueChanged(int) ),
  652. _ambientLightSB, TQT_SLOT ( setValue (int) ) );
  653. connect( _ambientLightSB, TQT_SIGNAL( valueChanged(int) ),
  654. _ambientLight, TQT_SLOT ( setValue (int) ) );
  655. connect( _heightScalePercent, TQT_SIGNAL( valueChanged(int) ),
  656. _heightScalePercentSB, TQT_SLOT ( setValue (int) ) );
  657. connect( _heightScalePercentSB, TQT_SIGNAL( valueChanged(int) ),
  658. _heightScalePercent, TQT_SLOT ( setValue (int) ) );
  659. connect( _doCushionShading, TQT_SIGNAL( stateChanged( int ) ), this, TQT_SLOT( checkEnabledState() ) );
  660. connect( _forceCushionGrid, TQT_SIGNAL( stateChanged( int ) ), this, TQT_SLOT( checkEnabledState() ) );
  661. checkEnabledState();
  662. }
  663. KTreemapPage::~KTreemapPage()
  664. {
  665. // NOP
  666. }
  667. void
  668. KTreemapPage::apply()
  669. {
  670. TDEConfig * config = kapp->config();
  671. config->setGroup( "Treemaps" );
  672. config->writeEntry( "Squarify", _squarify->isChecked() );
  673. config->writeEntry( "CushionShading", _doCushionShading->isChecked() );
  674. config->writeEntry( "AmbientLight", _ambientLight->value() );
  675. config->writeEntry( "HeightScaleFactor", _heightScalePercent->value() / 100.0 );
  676. config->writeEntry( "EnsureContrast", _ensureContrast->isChecked() );
  677. config->writeEntry( "ForceCushionGrid", _forceCushionGrid->isChecked() );
  678. config->writeEntry( "MinTileSize", _minTileSize->value() );
  679. config->writeEntry( "AutoResize", _autoResize->isChecked() );
  680. config->writeEntry( "CushionGridColor", _cushionGridColor->color() );
  681. config->writeEntry( "OutlineColor", _outlineColor->color() );
  682. config->writeEntry( "FileFillColor", _fileFillColor->color() );
  683. config->writeEntry( "DirFillColor", _dirFillColor->color() );
  684. config->writeEntry( "HighlightColor", _highlightColor->color() );
  685. if ( treemapView() )
  686. {
  687. treemapView()->readConfig();
  688. treemapView()->rebuildTreemap();
  689. }
  690. }
  691. void
  692. KTreemapPage::revertToDefaults()
  693. {
  694. _squarify->setChecked( true );
  695. _doCushionShading->setChecked( true );
  696. _ambientLight->setValue( DefaultAmbientLight );
  697. _heightScalePercent->setValue( DefaultHeightScalePercent );
  698. _ensureContrast->setChecked( true );
  699. _forceCushionGrid->setChecked( false );
  700. _minTileSize->setValue( DefaultMinTileSize );
  701. _autoResize->setChecked( true );
  702. _cushionGridColor->setColor ( TQColor( 0x80, 0x80, 0x80 ) );
  703. _outlineColor->setColor ( black );
  704. _fileFillColor->setColor ( TQColor( 0xde, 0x8d, 0x53 ) );
  705. _dirFillColor->setColor ( TQColor( 0x10, 0x7d, 0xb4 ) );
  706. _highlightColor->setColor ( red );
  707. }
  708. void
  709. KTreemapPage::setup()
  710. {
  711. TDEConfig * config = kapp->config();
  712. config->setGroup( "Treemaps" );
  713. _squarify->setChecked ( config->readBoolEntry( "Squarify" , true ) );
  714. _doCushionShading->setChecked ( config->readBoolEntry( "CushionShading" , true ) );
  715. _ambientLight->setValue ( config->readNumEntry( "AmbientLight" , DefaultAmbientLight ) );
  716. _heightScalePercent->setValue( (int) ( 100 * config->readDoubleNumEntry ( "HeightScaleFactor", DefaultHeightScaleFactor ) ) );
  717. _ensureContrast->setChecked ( config->readBoolEntry( "EnsureContrast" , true ) );
  718. _forceCushionGrid->setChecked ( config->readBoolEntry( "ForceCushionGrid" , false ) );
  719. _minTileSize->setValue ( config->readNumEntry ( "MinTileSize" , DefaultMinTileSize ) );
  720. _autoResize->setChecked ( config->readBoolEntry( "AutoResize" , true ) );
  721. _cushionGridColor->setColor ( readColorEntry( config, "CushionGridColor" , TQColor( 0x80, 0x80, 0x80 ) ) );
  722. _outlineColor->setColor ( readColorEntry( config, "OutlineColor" , black ) );
  723. _fileFillColor->setColor ( readColorEntry( config, "FileFillColor" , TQColor( 0xde, 0x8d, 0x53 ) ) );
  724. _dirFillColor->setColor ( readColorEntry( config, "DirFillColor" , TQColor( 0x10, 0x7d, 0xb4 ) ) );
  725. _highlightColor->setColor ( readColorEntry( config, "HighlightColor" , red ) );
  726. _ambientLightSB->setValue( _ambientLight->value() );
  727. _heightScalePercentSB->setValue( _heightScalePercent->value() );
  728. checkEnabledState();
  729. }
  730. void
  731. KTreemapPage::checkEnabledState()
  732. {
  733. _cushionParams->setEnabled( _doCushionShading->isChecked() );
  734. _plainTileParams->setEnabled( ! _doCushionShading->isChecked() );
  735. if ( _doCushionShading->isChecked() )
  736. {
  737. _cushionGridColor->setEnabled ( _forceCushionGrid->isChecked() );
  738. _cushionGridColorL->setEnabled( _forceCushionGrid->isChecked() );
  739. _ensureContrast->setEnabled ( ! _forceCushionGrid->isChecked() );
  740. }
  741. }
  742. TQColor
  743. KTreemapPage::readColorEntry( TDEConfig * config, const char * entryName, TQColor defaultColor )
  744. {
  745. return config->readColorEntry( entryName, &defaultColor );
  746. }
  747. void
  748. addHStretch( TQWidget * parent )
  749. {
  750. TQWidget * stretch = new TQWidget( parent );
  751. stretch->setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, // hor
  752. TQSizePolicy::Minimum, // vert
  753. 1, // hstretch
  754. 0 ) ); // vstretch
  755. }
  756. void
  757. addVStretch( TQWidget * parent )
  758. {
  759. TQWidget * stretch = new TQWidget( parent );
  760. stretch->setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, // hor
  761. TQSizePolicy::Expanding, // vert
  762. 0, // hstretch
  763. 1 ) ); // vstretch
  764. }
  765. #include "kdirstatsettings.moc"
  766. // EOF