KDirStat – a graphical disk usage utility
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

882 lines
22KB

  1. /*
  2. * File name: kdirtreeview.h
  3. * Summary: High level classes for KDirStat
  4. * License: LGPL - See file COPYING.LIB for details.
  5. * Author: Stefan Hundhammer <sh@suse.de>
  6. *
  7. * Updated: 2003-08-26
  8. */
  9. #ifndef KDirTreeView_h
  10. #define KDirTreeView_h
  11. // Alternative parent class for KDirTreeView.
  12. //
  13. // If you change this, don't forget to change the KDirTreeView class
  14. // declaration also. Unfortunately there this 'define' can't be used -
  15. // it seems to confuse the 'moc' preprocessor.
  16. #define USE_KLISTVIEW 0
  17. #define DEBUG_COUNTERS 10
  18. #ifdef HAVE_CONFIG_H
  19. # include <config.h>
  20. #endif
  21. #include <tqdatetime.h>
  22. #include <tqlistview.h>
  23. #include <tqpixmap.h>
  24. #include <tdelistview.h>
  25. #include "kdirtree.h"
  26. // Forward declarations
  27. class TQWidget;
  28. class TQTimer;
  29. class TQPopupMenu;
  30. class KPacManAnimation;
  31. // Open a new name space since KDE's name space is pretty much cluttered
  32. // already - all names that would even remotely match are already used up,
  33. // yet the resprective classes don't quite fit the purposes required here.
  34. namespace KDirStat
  35. {
  36. #define KDirTreeViewMaxFillColor 16
  37. #if USE_KLISTVIEW
  38. # define KDirTreeViewParentClass TDEListView
  39. #else
  40. # define KDirTreeViewParentClass TQListView
  41. #endif
  42. class KDirTreeViewItem;
  43. class KDirTreeView: public TQListView
  44. // Using
  45. // class KDirTreeView: public KDirTreeViewParentClass
  46. // or some other 'ifdef' ... construct seems to confuse "moc".
  47. {
  48. Q_OBJECT
  49. public:
  50. /**
  51. * Default constructor.
  52. **/
  53. KDirTreeView( TQWidget * parent = 0 );
  54. /**
  55. * Destructor.
  56. **/
  57. virtual ~KDirTreeView();
  58. /**
  59. * Locate the counterpart to an original tree item "wanted" somewhere
  60. * within this view tree. Returns 0 on failure.
  61. * If "lazy" is set, only the open part of the tree is searched.
  62. * "doClone" specifies whether or not to (deferred) clone nodes that
  63. * are not cloned yet. This is only used if "lazy" is false.
  64. **/
  65. KDirTreeViewItem * locate( KFileInfo * wanted,
  66. bool lazy = true,
  67. bool doClone = true );
  68. /**
  69. * Get the first child of this view or 0 if there is none.
  70. * Use the child's next() method to get the next child.
  71. * Reimplemented from @ref TQListView.
  72. **/
  73. KDirTreeViewItem * firstChild() const
  74. { return (KDirTreeViewItem *) KDirTreeViewParentClass::firstChild(); }
  75. /**
  76. * Return the currently selected item or 0, if none is selected.
  77. **/
  78. KDirTreeViewItem * selection() const { return _selection; }
  79. /**
  80. * Returns the default level until which items are opened by default
  81. * (unless they are dot entries).
  82. **/
  83. int openLevel() const { return _openLevel; }
  84. /**
  85. * Returns true if the view tree is to be cloned lazily, i.e. only
  86. * those view tree branches that are really visible are synced with the
  87. * original tree.
  88. **/
  89. bool doLazyClone() const { return _doLazyClone; }
  90. /**
  91. * Enable / disable PacMan animation in this tree view during directory
  92. * reading. This is disabled by default since it eats quite some
  93. * performance.
  94. **/
  95. void enablePacManAnimation( bool enable ) { _doPacManAnimation = enable; }
  96. /**
  97. * Returns true if the PacMan animation is to be used during directory
  98. * reading.
  99. **/
  100. bool doPacManAnimation() const { return _doPacManAnimation; }
  101. /**
  102. * Returns the number of open items in the entire tree.
  103. **/
  104. int openCount();
  105. /**
  106. * Return the percentage bar fill color for the specified directory
  107. * level (0..MaxInt). Wraps around every usedFillColors() colors.
  108. **/
  109. const TQColor & fillColor( int level ) const;
  110. /**
  111. * Very much like @ref fillColor(), but doesn't wrap around at @ref
  112. * usedFillColors(), but at KDirTreeViewMaxFillColor.
  113. **/
  114. const TQColor & rawFillColor( int level ) const;
  115. /**
  116. * Set the fill color of percentage bars of the specified directory
  117. * level (0..KDirTreeViewMaxFillColor-1).
  118. *
  119. * Calling repaint() after setting all desired colors is the
  120. * caller's responsibility.
  121. **/
  122. void setFillColor( int level, const TQColor &color );
  123. /**
  124. * Set all tree colors to default values.
  125. **/
  126. void setDefaultFillColors();
  127. /**
  128. * Set the number of used percentage bar fill colors
  129. * (1..KDirTreeViewMaxFillColor).
  130. **/
  131. void setUsedFillColors( int usedFillColors );
  132. /**
  133. * Returns the number of used percentage bar fill colors.
  134. **/
  135. int usedFillColors() const { return _usedFillColors; }
  136. /**
  137. * Set the tree background color.
  138. *
  139. * Calling repaint() after setting all desired colors is the
  140. * caller's responsibility.
  141. **/
  142. void setTreeBackground( const TQColor &color );
  143. /**
  144. * Returns the tree background color.
  145. **/
  146. const TQColor & treeBackground() const { return _treeBackground; }
  147. /**
  148. * Returns the background color for percentage bars.
  149. **/
  150. const TQColor & percentageBarBackground() const { return _percentageBarBackground; }
  151. /**
  152. * (Try to) ensure good contrast between the tree background and the
  153. * percentage bars' 3D edges - prevent ugly 3D effects which will
  154. * inevitably be the case for a white background (which unfortunately
  155. * is very common): The percentage bars use white and black for 3D
  156. * borders - like any other widget. But other widgets normally can
  157. * assume their parent widget uses some more neutral color so white and
  158. * black will result in at least some minimal contrast.
  159. *
  160. * This function automagically sets a reasonable default background
  161. * color for the tree display: If the current color scheme's document
  162. * background color (as used for input fields, lists etc.) is white or
  163. * black, use the palette midlight color (the same color as "normal"
  164. * widgets like push buttons etc., but brighter). For all other colors
  165. * than white, the document background color (the palette base color)
  166. * is used.
  167. **/
  168. void ensureContrast();
  169. /**
  170. * Set the sort column.
  171. *
  172. * Reimplemented from TQListView so we can keep track of the sort column.
  173. **/
  174. virtual void setSorting( int column, bool increasing = TRUE );
  175. /**
  176. * Returns the internal @ref KDirTree this view works on.
  177. * Handle with caution: This might be short-lived information.
  178. * The view might choose to create a new tree shortly after returning
  179. * this, so don't store this pointer internally.
  180. **/
  181. KDirTree *tree() { return _tree; }
  182. int nameCol() const { return _nameCol; }
  183. int iconCol() const { return _iconCol; }
  184. int percentBarCol() const { return _percentBarCol; }
  185. int percentNumCol() const { return _percentNumCol; }
  186. int totalSizeCol() const { return _totalSizeCol; }
  187. int workingStatusCol() const { return _workingStatusCol; }
  188. int ownSizeCol() const { return _ownSizeCol; }
  189. int totalItemsCol() const { return _totalItemsCol; }
  190. int totalFilesCol() const { return _totalFilesCol; }
  191. int totalSubDirsCol() const { return _totalSubDirsCol; }
  192. int latestMtimeCol() const { return _latestMtimeCol; }
  193. int readJobsCol() const { return _readJobsCol; }
  194. int sortCol() const { return _sortCol; }
  195. TQPixmap openDirIcon() const { return _openDirIcon; }
  196. TQPixmap closedDirIcon() const { return _closedDirIcon; }
  197. TQPixmap openDotEntryIcon() const { return _openDotEntryIcon; }
  198. TQPixmap closedDotEntryIcon() const { return _closedDotEntryIcon; }
  199. TQPixmap unreadableDirIcon() const { return _unreadableDirIcon; }
  200. TQPixmap mountPointIcon() const { return _mountPointIcon; }
  201. TQPixmap fileIcon() const { return _fileIcon; }
  202. TQPixmap symLinkIcon() const { return _symLinkIcon; }
  203. TQPixmap blockDevIcon() const { return _blockDevIcon; }
  204. TQPixmap charDevIcon() const { return _charDevIcon; }
  205. TQPixmap fifoIcon() const { return _fifoIcon; }
  206. TQPixmap stopIcon() const { return _stopIcon; }
  207. TQPixmap workingIcon() const { return _workingIcon; }
  208. TQPixmap readyIcon() const { return _readyIcon; }
  209. /**
  210. * Set function name of debug function #i
  211. **/
  212. void setDebugFunc( int i, const TQString & functionName );
  213. /**
  214. * Increase debug counter #i
  215. **/
  216. void incDebugCount( int i );
  217. public slots:
  218. /**
  219. * Open a directory URL. Assume "file:" protocol unless otherwise specified.
  220. **/
  221. void openURL( KURL url );
  222. /**
  223. * Refresh (i.e. re-read from disk) the entire tree.
  224. **/
  225. void refreshAll();
  226. /**
  227. * Refresh (i.e. re-read from disk) the selected subtree.
  228. **/
  229. void refreshSelected();
  230. /**
  231. * Forcefully stop a running read process.
  232. **/
  233. void abortReading();
  234. /**
  235. * Clear this view's contents.
  236. **/
  237. void clear();
  238. /**
  239. * Select a (TQListViewItem) item. Triggers selectionChanged() signals.
  240. **/
  241. void selectItem( TQListViewItem *item );
  242. /**
  243. * Select an item. Triggers selectionChanged() signals.
  244. * Overloaded for convenience.
  245. **/
  246. void selectItem( KDirTreeViewItem *item ) { selectItem( (TQListViewItem *) item ); }
  247. /**
  248. * Select a KDirTree item. Used for connecting the @ref
  249. * KDirTree::selectionChanged() signal.
  250. **/
  251. void selectItem( KFileInfo *item );
  252. /**
  253. * Clear the current selection. Triggers selectionChanged() signals.
  254. **/
  255. void clearSelection();
  256. /**
  257. * Close all tree branches except the one specified.
  258. **/
  259. void closeAllExcept( KDirTreeViewItem *except );
  260. /**
  261. * Send a standardized mail to the owner of the selected branch.
  262. * The user will get a mailer window where he can edit that mail all he
  263. * likes before deciding to send or discard it.
  264. *
  265. * The mail includes all currently open branches from the selected
  266. * branch on.
  267. **/
  268. void sendMailToOwner();
  269. /**
  270. * Notification of a change in the KDE palette, i.e. the user selected
  271. * and applied different colors in the KDE control center.
  272. **/
  273. void paletteChanged();
  274. /**
  275. * Read configuration and initialize variables accordingly.
  276. * Will be called automatically in the constructor.
  277. **/
  278. void readConfig();
  279. /**
  280. * Save configuraton.
  281. **/
  282. void saveConfig() const;
  283. /**
  284. * Emit a @ref userActivity() signal worth 'points' activity points.
  285. **/
  286. void logActivity( int points );
  287. /**
  288. * Returns the minimum recommended size for this widget.
  289. * Reimplemented from TQWidget.
  290. **/
  291. virtual TQSize minimumSizeHint() const { return TQSize( 0, 0 ); }
  292. protected slots:
  293. /**
  294. * Add a child as a clone of original tree item "newChild" to this view
  295. * tree.
  296. **/
  297. void addChild ( KFileInfo *newChild );
  298. /**
  299. * Delete a cloned child.
  300. **/
  301. void deleteChild ( KFileInfo *newChild );
  302. /**
  303. * Recursively update the visual representation of the summary fields.
  304. * This update is as lazy as possible for optimum performance since it
  305. * is called very frequently as a cyclic update.
  306. **/
  307. void updateSummary();
  308. /**
  309. * Signal end of all read jobs, finalize display and terminate pending
  310. * cyclic visual update.
  311. **/
  312. void slotFinished();
  313. /**
  314. * Signal abortion of all read jobs, finalize display and terminate pending
  315. * cyclic visual update.
  316. **/
  317. void slotAborted();
  318. /**
  319. * Signal end of one read job at this level and finalize display of
  320. * this level.
  321. **/
  322. void finalizeLocal( KDirInfo *dir );
  323. /**
  324. * Display progress information in the status bar. Automatically adds
  325. * the elapsed time of a directory scan.
  326. **/
  327. void sendProgressInfo( const TQString & currentDir = "" );
  328. /**
  329. * Set up everything prior to reading: Cyclic update timer, display
  330. * busy state, default sorting, stopwatch.
  331. **/
  332. void prepareReading();
  333. /**
  334. * Change the tree display to "busy" state, i.e. add a column to
  335. * display the number of pending read jobs for each level.
  336. **/
  337. void busyDisplay();
  338. /**
  339. * Change the tree display back to "idle" state, i.e. remove columns
  340. * that are useful only while directories are being read, like the
  341. * pending read jobs column.
  342. **/
  343. void idleDisplay();
  344. /**
  345. * Pop up context menu (i.e. emit the contextMenu() signal) or open a
  346. * small info popup with exact information, depending on 'column'.
  347. **/
  348. void popupContextMenu ( TQListViewItem * listViewItem,
  349. const TQPoint & pos,
  350. int column );
  351. /**
  352. * Pop up info window with exact byte size.
  353. **/
  354. void popupContextSizeInfo ( const TQPoint & pos,
  355. KFileSize size );
  356. /**
  357. * Pop up info window with arbitrary one-line text.
  358. **/
  359. void popupContextInfo ( const TQPoint & pos,
  360. const TQString & info );
  361. protected slots:
  362. /**
  363. * Notification that a column has just been resized, thus may need
  364. * repaining.
  365. **/
  366. void columnResized( int column, int oldSize, int newSize );
  367. signals:
  368. /**
  369. * Single line progress information, emitted when the read status
  370. * changes - typically when a new directory is being read. Connect to a
  371. * status bar etc. to keep the user busy.
  372. **/
  373. void progressInfo( const TQString &infoLine );
  374. /**
  375. * Emitted when reading is started.
  376. **/
  377. void startingReading();
  378. /**
  379. * Emitted when reading this tree is finished.
  380. **/
  381. void finished();
  382. /**
  383. * Emitted when reading this tree has been aborted.
  384. **/
  385. void aborted();
  386. /**
  387. * Emitted when the currently selected item changes.
  388. * Caution: 'item' may be 0 when the selection is cleared.
  389. **/
  390. void selectionChanged( KDirTreeViewItem *item );
  391. /**
  392. * Emitted when the currently selected item changes.
  393. * Caution: 'item' may be 0 when the selection is cleared.
  394. **/
  395. void selectionChanged( KFileInfo *item );
  396. /**
  397. * Emitted when a context menu for this item should be opened.
  398. * (usually on right click). 'pos' contains the click's mouse
  399. * coordinates.
  400. *
  401. * NOTE:
  402. *
  403. * This is _not_ the same as @ref TQListView::rightButtonClicked():
  404. * The context menu may not open on a right click on every column,
  405. * usually only in the nameCol().
  406. **/
  407. void contextMenu( KDirTreeViewItem *item, const TQPoint &pos );
  408. /**
  409. * Emitted at user activity. Some interactive actions are assigned an
  410. * amount of "activity points" that can be used to judge whether or not
  411. * the user is actually using this program or if it's just idly sitting
  412. * around on the desktop. This is intended for use together with a @ref
  413. * KActivityTracker.
  414. **/
  415. void userActivity( int points );
  416. protected:
  417. KDirTree * _tree;
  418. TQTimer * _updateTimer;
  419. TQTime _stopWatch;
  420. TQString _currentDir;
  421. KDirTreeViewItem * _selection;
  422. TQPopupMenu * _contextInfo;
  423. int _idContextInfo;
  424. int _openLevel;
  425. bool _doLazyClone;
  426. bool _doPacManAnimation;
  427. int _updateInterval; // millisec
  428. int _usedFillColors;
  429. TQColor _fillColor [ KDirTreeViewMaxFillColor ];
  430. TQColor _treeBackground;
  431. TQColor _percentageBarBackground;
  432. // The various columns in which to display information
  433. int _nameCol;
  434. int _iconCol;
  435. int _percentNumCol;
  436. int _percentBarCol;
  437. int _totalSizeCol;
  438. int _workingStatusCol;
  439. int _ownSizeCol;
  440. int _totalItemsCol;
  441. int _totalFilesCol;
  442. int _totalSubDirsCol;
  443. int _latestMtimeCol;
  444. int _readJobsCol;
  445. int _sortCol;
  446. int _debugCount[ DEBUG_COUNTERS ];
  447. TQString _debugFunc [ DEBUG_COUNTERS ];
  448. // The various icons
  449. TQPixmap _openDirIcon;
  450. TQPixmap _closedDirIcon;
  451. TQPixmap _openDotEntryIcon;
  452. TQPixmap _closedDotEntryIcon;
  453. TQPixmap _unreadableDirIcon;
  454. TQPixmap _mountPointIcon;
  455. TQPixmap _fileIcon;
  456. TQPixmap _symLinkIcon;
  457. TQPixmap _blockDevIcon;
  458. TQPixmap _charDevIcon;
  459. TQPixmap _fifoIcon;
  460. TQPixmap _stopIcon;
  461. TQPixmap _workingIcon;
  462. TQPixmap _readyIcon;
  463. };
  464. class KDirTreeViewItem: public TQListViewItem
  465. {
  466. public:
  467. /**
  468. * Constructor for the root item.
  469. **/
  470. KDirTreeViewItem ( KDirTreeView * view,
  471. KFileInfo * orig );
  472. /**
  473. * Constructor for all other items.
  474. **/
  475. KDirTreeViewItem ( KDirTreeView * view,
  476. KDirTreeViewItem * parent,
  477. KFileInfo * orig );
  478. /**
  479. * Destructor.
  480. **/
  481. virtual ~KDirTreeViewItem();
  482. /**
  483. * Locate the counterpart to an original tree item "wanted" somewhere
  484. * within this view tree. Returns 0 on failure.
  485. *
  486. * When "lazy" is set, only the open part of the tree is searched.
  487. * "doClone" specifies whether or not to (deferred) clone nodes that
  488. * are not cloned yet. This is only used if "lazy" is false.
  489. * "Level" is just a hint for the current tree level for better
  490. * performance. It will be calculated automatically if omitted.
  491. **/
  492. KDirTreeViewItem * locate( KFileInfo * wanted,
  493. bool lazy = true,
  494. bool doClone = true,
  495. int level = -1 );
  496. /**
  497. * Recursively update the visual representation of the summary fields.
  498. * This update is as lazy as possible for optimum performance.
  499. **/
  500. void updateSummary();
  501. /**
  502. * Bring (the top level of) this branch of the view tree in sync with
  503. * the original tree. Does _not_ recurse into subdirectories - only
  504. * this level of this branch is processed. Called when lazy tree
  505. * cloning is in effect and this branch is about to be opened.
  506. **/
  507. void deferredClone();
  508. /**
  509. * Finalize this level - clean up unneeded / undesired dot entries.
  510. **/
  511. void finalizeLocal();
  512. /**
  513. * Returns the corresponding view.
  514. **/
  515. KDirTreeView * view() { return _view; }
  516. /**
  517. * Returns the parent view item or 0 if this is the root.
  518. **/
  519. KDirTreeViewItem * parent() { return _parent; }
  520. /**
  521. * Returns the corresponding original item of the "real" (vs. view)
  522. * tree where all the important information resides.
  523. **/
  524. KFileInfo * orig() { return _orig; }
  525. /**
  526. * Returns the first child of this item or 0 if there is none.
  527. * Use the child's next() method to get the next child.
  528. * Reimplemented from @ref TQListViewItem.
  529. **/
  530. KDirTreeViewItem * firstChild() const
  531. { return (KDirTreeViewItem *) TQListViewItem::firstChild(); }
  532. /**
  533. * Returns the next sibling of this item or 0 if there is none.
  534. * (Kind of) reimplemented from @ref TQListViewItem.
  535. **/
  536. KDirTreeViewItem * next() const
  537. { return (KDirTreeViewItem *) TQListViewItem::nextSibling(); }
  538. /**
  539. * Comparison function used for sorting the list.
  540. *
  541. * Using this function is much more efficient than overwriting
  542. * TQListViewItem::key() which operates on TQStrings.
  543. *
  544. * Returns:
  545. * -1 if this < other
  546. * 0 if this == other
  547. * +1 if this > other
  548. *
  549. * Reimplemented from TQListViewItem
  550. **/
  551. virtual int compare( TQListViewItem * other,
  552. int col,
  553. bool ascending ) const;
  554. /**
  555. * Perform any necessary pending updates when a branch is opened.
  556. * Reimplemented from @ref TQListViewItem.
  557. **/
  558. virtual void setOpen( bool open );
  559. /**
  560. * Notification that a branch in this subtree has been opened or close
  561. * somewhere. Don't call this if the state hasn't really changed!
  562. **/
  563. void openNotify( bool open );
  564. /**
  565. * Recursively open this subtree and all its ancestors up to the root.
  566. **/
  567. void openSubtree();
  568. /**
  569. * Recursively close all tree branches from here on downwards.
  570. **/
  571. void closeSubtree();
  572. /**
  573. * Close all tree branches except this one from the root on.
  574. **/
  575. void closeAllExceptThis();
  576. /**
  577. * Returns the number of open items in this subtree.
  578. **/
  579. int openCount() const { return _openCount; }
  580. /**
  581. * Recursively return an ASCII representation of all open items from
  582. * here on.
  583. **/
  584. TQString asciiDump();
  585. protected:
  586. /**
  587. * Set the appropriate icon depending on this item's type and open /
  588. * closed state.
  589. **/
  590. void setIcon();
  591. /**
  592. * Remove dot entry if it doesn't have any children.
  593. * Reparent all of the dot entry's children if there are no
  594. * subdirectories on this level.
  595. **/
  596. void cleanupDotEntries();
  597. /**
  598. * Find this entry's dot entry (clone).
  599. *
  600. * This doesn't create one if deferred cloning is in effect (which is
  601. * not a drawback since cloning directory nodes create a dot entry
  602. * clone along with the directory clone).
  603. *
  604. * Returns 0 if there is no dot entry clone.
  605. **/
  606. KDirTreeViewItem * findDotEntry() const;
  607. /**
  608. * Paint method. Reimplemented from @ref TQListViewItem so different
  609. * colors can be used - and of course for painting percentage bars.
  610. *
  611. * Reimplemented from @ref TQListViewItem.
  612. **/
  613. virtual void paintCell ( TQPainter * painter,
  614. const TQColorGroup & colorGroup,
  615. int column,
  616. int width,
  617. int alignment );
  618. /**
  619. * Paint a percentage bar into a @ref TQListViewItem cell.
  620. * 'width' is the width of the entire cell.
  621. * 'indent' is the number of pixels to indent the bar.
  622. **/
  623. void paintPercentageBar ( float percent,
  624. TQPainter * painter,
  625. int indent,
  626. int width,
  627. const TQColor & fillColor,
  628. const TQColor & barBackground );
  629. /**
  630. * Generic comparison function.
  631. **/
  632. template<typename T> inline
  633. int compare( T a, T b ) const
  634. {
  635. if ( a < b ) return -1;
  636. if ( a > b ) return 1;
  637. return 0;
  638. }
  639. private:
  640. /**
  641. * Initializations common to all constructors.
  642. **/
  643. void init ( KDirTreeView * view,
  644. KDirTreeViewItem * parent,
  645. KFileInfo * orig );
  646. protected:
  647. // Data members
  648. KDirTreeView * _view;
  649. KDirTreeViewItem * _parent;
  650. KFileInfo * _orig;
  651. KPacManAnimation * _pacMan;
  652. float _percent;
  653. int _openCount;
  654. };
  655. inline kdbgstream & operator<< ( kdbgstream & stream, KDirTreeViewItem * item )
  656. {
  657. if ( item )
  658. {
  659. if ( item->orig() )
  660. {
  661. stream << item->orig()->debugUrl();
  662. }
  663. else
  664. {
  665. stream << "<NULL orig()> " << endl;
  666. }
  667. }
  668. else
  669. stream << "<NULL>";
  670. return stream;
  671. }
  672. //----------------------------------------------------------------------
  673. // Static Functions
  674. //----------------------------------------------------------------------
  675. /**
  676. * Format a file size with all digits, yet human readable using the current
  677. * locale's thousand separator, i.e. 12,345,678 rather than 12345678
  678. **/
  679. TQString formatSizeLong( KFileSize size );
  680. /**
  681. * Format a file size for use within a TQListView::key() function:
  682. * Right-justify and fill with leading zeroes.
  683. **/
  684. TQString hexKey( KFileSize size );
  685. /**
  686. * Format a millisecond granularity time human readable.
  687. * Milliseconds will only be inluded if 'showMilliSeconds' is true.
  688. **/
  689. TQString formatTime ( long millisec,
  690. bool showMilliSeconds = false );
  691. /**
  692. * Format counters of any kind.
  693. *
  694. * Returns an empty string if 'suppressZero' is 'true' and the value of
  695. * 'count' is 0.
  696. **/
  697. TQString formatCount( int count, bool suppressZero = false );
  698. /**
  699. * Format percentages.
  700. **/
  701. TQString formatPercent( float percent );
  702. /**
  703. * Format time and date human-readable as "yyyy-mm-dd hh:mm:ss"
  704. * - unlike that ctime() crap that is really useless.
  705. * See the source for more about why this format.
  706. **/
  707. TQString formatTimeDate( time_t rawTime );
  708. /**
  709. * Format time and date according to the current locale for those who
  710. * really must have that brain-dead ctime() format.
  711. **/
  712. TQString localeTimeDate( time_t rawTime );
  713. /**
  714. * Return a color that contrasts to 'contrastColor'.
  715. **/
  716. TQColor contrastingColor ( const TQColor &desiredColor,
  717. const TQColor &contrastColor );
  718. } // namespace KDirStat
  719. #endif // ifndef KDirTreeView_h
  720. // EOF