summaryrefslogtreecommitdiffstats
path: root/konq-plugins/fsview/fsview.h
blob: 91471c50b1240a54d8cb6efe8c74ab15a5e7e202 (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
/* This file is part of FSView.
   Copyright (C) 2002, 2003 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>

   KCachegrind is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License as published by the Free Software Foundation, version 2.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

/*
 * FSView specialisaton of TreeMap classes.
 */

#ifndef FSVIEW_H
#define FSVIEW_H

#include <tqmap.h>
#include <tqptrlist.h>
#include <tqfileinfo.h>
#include <tqstring.h>

#include <kmimetype.h>

#include "treemap.h"
#include "inode.h"
#include "scan.h"

class KConfig;

/* Cached Metric info config */
class MetricEntry
{
 public:
  MetricEntry()
    { size = 0.0; fileCount = 0; dirCount = 0; }
  MetricEntry(double s, unsigned int f, unsigned int d)
    { size = s; fileCount = f; dirCount = d; }

  double size;
  unsigned int fileCount, dirCount;
};

/**
 * The root object for the treemap.
 *
 * Does context menu handling and
 * asynchronous file size update
 */
class FSView : public TreeMapWidget, public ScanListener
{
  Q_OBJECT
  TQ_OBJECT

public:
  enum ColorMode { None = 0, Depth, Name, Owner, Group, Mime };

  FSView(Inode*, TQWidget* parent=0, const char* name=0);
  ~FSView();

  KConfig* config() { return _config; }

  void setPath(TQString);
  TQString path() { return _path; }
  int pathDepth() { return _pathDepth; }
  
  void setColorMode(FSView::ColorMode cm);
  FSView::ColorMode colorMode() const { return _colorMode; }
  // returns true if string was recognized
  bool setColorMode(TQString);
  TQString colorModeString() const;

  void requestUpdate(Inode*);

  /* Implementation of listener interface of ScanManager.
   * Used to calculate progress info */
  void scanFinished(ScanDir*);

  void stop();

  static bool getDirMetric(const TQString&, double&, unsigned int&, unsigned int&);
  static void setDirMetric(const TQString&, double, unsigned int, unsigned int);
  void saveMetric(KConfigGroup*);
  void saveFSOptions();

  // for color mode
  void addColorItems(TQPopupMenu*, int);

  KURL::List selectedUrls();

public slots:
  void selected(TreeMapItem*);
  void contextMenu(TreeMapItem*, const TQPoint &);
  void quit();
  void doUpdate();
  void doRedraw();
  void colorActivated(int);

 signals:
  void started();
  void progress(int percent, int dirs, const TQString& lastDir);
  void completed(int dirs);

 private:
  KConfig* _config;
  ScanManager _sm;

  // when a contextMenu is shown, we don't allow async. refreshs
  bool _allowRefresh;
  // a cache for directory sizes with long lasting updates
  static TQMap<TQString, MetricEntry> _dirMetric;

  // current root path
  int _pathDepth;
  TQString _path;

  // for progress info
  int _progressPhase;
  int _chunkData1, _chunkData2, _chunkData3;
  int _chunkSize1, _chunkSize2, _chunkSize3;
  int _progress, _progressSize, _dirsFinished;
  ScanDir* _lastDir;

  ColorMode _colorMode;
  int _colorID;
};

#endif // FSVIEW_H