summaryrefslogtreecommitdiffstats
path: root/quanta/treeviews/basetreeview.h
blob: 18ff5ae0811d7c12eb82e4d5bf2df839a660fd62 (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
/***************************************************************************
                          BaseTreeView.h  -  description
                             -------------------
    begin                : Thu Jun 1 2000
    copyright            : (C) 2000 by Dmitry Poplavsky & Alexander Yakovlev & Eric Laffoon <pdima@users.sourceforge.net,yshurik@linuxfan.com,sequitur@easystreet.com>
                           (C) 2001-2004 Andras Mantia <amantia@kde.org>
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program 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; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef BASETREEVIEW_H
#define BASETREEVIEW_H

//qt includes
#include <tqvaluelist.h>

//kde includes
#include <kfiletreebranch.h>
#include <kfiletreeview.h>
#include <kfiletreeviewitem.h>

// quanta includes
#include "quantacommon.h"

//foward declarations
class TQListViewItem;
class TQString;
class TQPixmap;
class TQPoint;
class TQRegExp;
class TQCloseEvent;

class KAction;
class KFileItem;
class KPopupMenu;
class KPropertiesDialog;
class KURL;
class FileInfoDlg;
class BaseTreeViewToolTip;
class QuantaPlugin;

/**
 * @short a KFileTreeViewItem with some specials.
 *
 * @author Jens Herden <jens@kdewebdev.org>
 */
class BaseTreeViewItem : public KFileTreeViewItem {

public:
  BaseTreeViewItem( KFileTreeViewItem *parent, KFileItem* item, KFileTreeBranch *brnch );

  /**
  sorts folders separate from files
  */
  TQString key (int column, bool ascending) const;

  /**
  makes compare independent from locale
  */
  int compare( TQListViewItem *i, int col, bool ascending ) const;

  /**
  makes open files bold and the second column lighter
  */
  void paintCell(TQPainter *p, const TQColorGroup &cg, int column, int width, int align);

  /**
  refresh icon
  */
  void refreshIcon();
};

/**
 * @short a KFileTreeBranch that uses @ref BaseTreeViewItem and does some special filtering.
 *
 * @author Jens Herden <jens@kdewebdev.org>
 */
class BaseTreeBranch : public KFileTreeBranch {
   Q_OBJECT
  TQ_OBJECT

public:
  BaseTreeBranch(KFileTreeView *parent, const KURL& url,
                  const TQString& name, const TQPixmap& pix,
                  bool showHidden = false, KFileTreeViewItem *branchRoot = 0);
  /**
  get the BaseTreeViewItem
  */
  virtual KFileTreeViewItem* createTreeViewItem( KFileTreeViewItem *parent,
                                                 KFileItem *fileItem );
  /**
  does custom filtering
  */
  bool matchesFilter(const KFileItem *item) const;

  /**
  files matching to this will not be shown
  */
  TQRegExp excludeFilterRx;

  /**
  adds the current open folders of the branch to a stringslist.
  Attention: no check for double entries is done

  @param openFolder the list where to add the URL strings
  */
  void addOpenFolder(TQStringList *openFolder);

  /** opens the next folder in @ref folderToOpen */
  void reopenFolder();

  /** list of folders to open */
  TQStringList folderToOpen;

  /** inform the dirwatcher to update all open folders */
  void updateOpenFolder();

};


/**
 * @short the base class for many of Quantas treeviews
 *
 * @ref FilesTreeView, @ref ScriptTreeView, @ref ProjectTreeView and
 * @ref TemplatesTreeView use this class.
 *
 */
class BaseTreeView : public KFileTreeView {
   Q_OBJECT
  TQ_OBJECT

public:
  BaseTreeView(TQWidget *parent = 0L, const char *name = 0L);
  virtual ~BaseTreeView();

  /**
   * Saves the list view's tqlayout (column widtsh, column order, sort column)
   * to a KConfig group. Reimplemented to save the open folders.
   *
   * @param config the KConfig object to write to
   * @param group the config group to use
   */
  void saveLayout(KConfig *config, const TQString &group);

  /**
   * Reads the list view's tqlayout from a KConfig group as stored with
   * saveLayout. Reimplemented to load the open folders.
   *
   * @param config the KConfig object to read from
   * @param group the config group to use
   */
  void restoreLayout(KConfig *config, const TQString &group);

   /**
  * en/disable saving a list of open folders in @ref saveLayout and
  * restoring the tree status in @ref restoreLayout
  */
  void setSaveOpenFolder(bool b = true) { m_saveOpenFolder = b; };

  /** reads property @ref setSaveOpenFolder */
  bool saveOpenFolder() { return m_saveOpenFolder; };

public slots:
  /**
  sets new project information
  */
  void slotNewProjectLoaded(const TQString &, const KURL &, const KURL &);
  /**
  repaints all treeview items
  */
  void slotDocumentClosed(const KURL& url);

protected slots:

  void slotCopy();
  void slotPaste();
  void slotDelete();
  virtual void slotJobFinished( KIO::Job *job);
  void slotInsertInProject();
  void slotInsertDirInProject();
  virtual void slotReturnPressed(TQListViewItem *item);
  virtual void slotDropped (TQWidget *, TQDropEvent *, KURL::List&, KURL&);
  /**
   sends value from KIO::Job to progressbar
   */
  virtual void slotPercent(KIO::Job *job, unsigned long value);

  void slotPopulateFinished(KFileTreeViewItem *item);
  /**
  shows open with dialog for the current item
  */
  void slotOpenWith();

  /** Opens the current item with the selected associated application */
  void slotOpenWithApplication();
  /**
  Called for: double click, return, Open

  emits a signal (@ref openFile or @ref openImage)
  or expands an archiv (@ref expandArchiv) in the tree
  */
  virtual void slotSelectFile(TQListViewItem *item);
  /**
  emits the signal @ref insertTag
  */
  void slotInsertTag();
  /**
  reloads the current branch
  */
  void slotReload();
  /**
  reloads all branches
  */
  virtual void slotReloadAllTrees();
  /**
  reloads one branche
  */
  virtual void reload(BaseTreeBranch *btb);
  /**
  opens the properties dialog
  */
  void slotProperties();
  /**
  applies changed properties
  */
  virtual void slotPropertiesApplied();
  /**
  emits the signal @ref open
  */
  void slotOpen();
  /**
  emits the signal @ref closeFile
  */
  void slotClose();

  /**
  starts the inline rename of the current item
  */
  void slotStartRename();

  /**
  connect signal itemRenamed to this slot to handle inline rename
   */
  virtual void slotRenameItem(TQListViewItem* kvtvi, const TQString & newText, int col);
  /**
  create a site template tarball from the selected directory
  */
  virtual void slotCreateSiteTemplate();
  /**
   Creates a folder under the current item
   */
  virtual void slotCreateFolder();
  /**
  Creates a file under the current item
   */
  virtual void slotCreateFile();

  virtual void slotOpenWithActivated(int id);

protected:
  /**
  implement this to create a branch and add this branch to the treeview
  @param url the root of the branch
  @return the new branch
  */
  virtual KFileTreeBranch* newBranch(const KURL& url) = 0;

  /**
  called when an item was renamed in the properties dialog
  the default implementation emits the signal @ref renamed
  */
  virtual void itemRenamed(const KURL& , const KURL& );

  /**
  called when the description of an item was changed,
  the default implementation does nothing
  @param item the treeview item
  @param newDesc the new description of item
  */
  virtual void itemDescChanged(KFileTreeViewItem* item, const TQString& newDesc)
  {
    Q_UNUSED(item);
    Q_UNUSED(newDesc);
  };
  /**
  @return true if the clipboard contains one or more valid path
  */
  bool isPathInClipboard();

  /**
  adds the Quanta fileinfopage to the properties dialog
  @param propDlg the dialog where to add the page
  @return pointer to to just added page
  */
  virtual FileInfoDlg* addFileInfoPage(KPropertiesDialog *propDlg);

  /**
  expands an archiv inside of the tree
  @return true if expanding was possible
  */
  bool expandArchiv (KFileTreeViewItem *item);
  bool acceptDrag(TQDropEvent* e ) const;
  void findDrop(const TQPoint &pos, TQListViewItem *&parent, TQListViewItem *&after);

  /**
  this is for project and template tree to reduce includes there
  */
  bool isFileOpen(const KURL &url);

  /** Inserts an Open With submenu into @param menu which lists
  the possible applications that can open the current item and an
  "Other" entry to bring up the Open With dialog. If no application
  is associated with the type of the current item, the menu will bring up the Open With dialog immediately.
  @param menu the menu where the Open With submenu should be inserted
  @param position the position in this menu
  */
  void insertOpenWithMenu(KPopupMenu *menu, int position);
  KPropertiesDialog *propDlg;
  TQString m_projectName;
  KURL m_projectBaseURL;
  FileInfoDlg* fileInfoDlg;
  /** the parent of the treeview
      the passwords are cached there
    */
  TQWidget * m_parent;

  BaseTreeViewToolTip * m_tooltip;
  // some stuff for renaming
  void doRename(KFileTreeViewItem* kvtvi, const TQString & newName);
  /** reimplemented to reset renameable */
  void cancelRename(int col);

signals:
  void openFile(const KURL&);
  void openImage(const KURL&);
  void open(TQListViewItem *name);
  void insertDirInProject(const KURL&);
  void insertFileInProject(const KURL&);
  void insertTag(const KURL &, DirInfo);
  /**
  file or folder has been renamed
  */
  void renamed(const KURL &, const KURL &);
  /**
  close the file in Quanta
  */
  void closeFile( const KURL& );

private:
  bool m_saveOpenFolder;
  KPopupMenu *m_openWithMenu;
  int m_openWithMenuId;
  TQValueList<KAction *> m_openWithActions;
  TQMap<int, QuantaPlugin*> m_pluginIds;
};

#endif