summaryrefslogtreecommitdiffstats
path: root/ksquirrel/sidebar/sq_treeview.h
blob: e12ebdbe274b652b7d2eb6b5cee4372e23557565 (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
/***************************************************************************
                          sq_treeview.h  -  description
                             -------------------
    begin                : Mon Mar 15 2004
    copyright            : (C) 2004 by Baryshev Dmitry
    email                : ksquirrel.iv@gmail.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 SQ_TREEVIEW_H
#define SQ_TREEVIEW_H

#include <tqstringlist.h>

#include <kfiletreeview.h>
#include <kurl.h>

class KDirWatch;

class SQ_TreeViewItem;
class SQ_ThreadDirLister;
class SQ_TreeViewMenu;

/*
 *  We should subclass KFileTreeBranch to let us create
 *  our own items. See SQ_TreeViewitem.
 */
class SQ_FileTreeViewBranch : public KFileTreeBranch
{
    public:
        SQ_FileTreeViewBranch(KFileTreeView*, const KURL &url, const TQString &name, const TQPixmap &pix);
        ~SQ_FileTreeViewBranch();

    protected:
        virtual KFileTreeViewItem *createTreeViewItem(KFileTreeViewItem *tqparent, KFileItem *fileItem);
};

/*
 *  SQ_TreeView represents a file tree.
 */

class SQ_TreeView : public KFileTreeView
{
    Q_OBJECT
  TQ_OBJECT

    public:
        SQ_TreeView(TQWidget *tqparent = 0, const char *name = 0);
        ~SQ_TreeView();

        enum Recursion { No = 0, Files, Dirs, FilesDirs };

        /*
         *  Recursion settings. If recursion > 0, treeview will
         *  show a number of files/directories in the given directory.
         *  It will look like that:
         *
         *  + mypictures [8]
         *  | + wallpapers [231]
         *  | + nature [12]
         *  | + pets [43]
         *    | + cats [22]
         *    | + dogs [32]
         *
         *  This operation is threaded.
         */
        void setupRecursion();

        /*
         *  Load new url, if tree is visible. Save url and do nothing
         *  otherwise.
         */
        void emitNewURL(const KURL &url);

        virtual void clearSelection();
        virtual void setSelected(TQListViewItem *item, bool selected);
        virtual void setCurrentItem(TQListViewItem *item);
        virtual void setOpen(TQListViewItem *item, bool open);

        static SQ_TreeView* instance() { return m_instance; }

    protected:
        virtual void customEvent(TQCustomEvent *e);
        virtual void startAnimation(KFileTreeViewItem* item, const char*, uint);
        virtual void stopAnimation(KFileTreeViewItem* item);
        virtual void viewportResizeEvent(TQResizeEvent *);
        virtual void contentsMousePressEvent(TQMouseEvent *e);
        virtual void contentsMouseDoubleClickEvent(TQMouseEvent *e);

        /*
         *  On show event load saved url, if any. See emitNewURL().
         */
        virtual void showEvent(TQShowEvent *);

    private:
        void toggle(SQ_TreeViewItem *, bool, bool = false);
        void setRecursion(int);

        /*
         *  Set given item visible, current, and populate it.
         */
        void populateItem(KFileTreeViewItem *);

        /*
         *  Search first available url in variable 'paths'. Open found item.
         *  If item was found return true.
         */
        bool doSearch();

    private slots:
        /*
         *  Load url.
         */
        void slotNewURL(const KURL &url);

        void slotCurrentChanged(TQListViewItem *);
        void slotAddToFolderBasket();
        void slotClearChecked();
        void slotDirty(const TQString &);
        void slotDeleteItemMy(KFileItem *);

        /*
         *  Item executed. Let's pass its url to SQ_WidgetStack (if needed).
         */
        void slotItemExecuted(TQListViewItem*);

        /*
         *  New item is opened. Try to continue loading url.
         */
        void slotOpened(KFileTreeViewItem *);

        void slotNewTreeViewItems(KFileTreeBranch*, const KFileTreeViewItemList &);
        void slotDelayedScan();
        void slotAnimation();

        void slotDropped(TQDropEvent *, TQListViewItem *, TQListViewItem *);
        void slotContextMenu(KListView *, TQListViewItem *, const TQPoint &);

    signals:
        void newURL(const KURL &url);

        /*
         *  Since 0.7.0 our file manager supports multiple directories.
         *  These signals tell SQ_DirOperator to add or remove some
         *  urls.
         */
        void urlAdded(const KURL &);
        void urlRemoved(const KURL &);

    private:
        SQ_FileTreeViewBranch *root;
        TQStringList paths;
        KURL pendingURL, cURL;
        SQ_ThreadDirLister    *lister;
        KFileTreeViewItemList m_mapFolders;
        TQTimer *m_animTimer, *scanTimer;
        bool m_ignoreClick;
        int m_recurs;
        SQ_TreeViewMenu *menu;
        KDirWatch *dw;
        KFileTreeViewItem *itemToBeOpened;

        static SQ_TreeView *m_instance;
};

#endif