summaryrefslogtreecommitdiffstats
path: root/ksquirrel/sq_widgetstack.h
blob: 65d910f7667b41530ec078037aee6b70fd6f5fe2 (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
/***************************************************************************
                          sq_widgetstack.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_WIDGETSTACK_H
#define SQ_WIDGETSTACK_H

#include <tqobject.h>
#include <tqstring.h>

#include <kurl.h>
#include <kfileitem.h>

#include "sq_diroperator.h"

namespace KIO { class Job; }

class TQTimer;

class KAction;
class KToggleAction;
class KFileView;

/*
 *  SQ_WidgetStack is a simple wrapper for file manager (navigator).
 *
 *  It serves all file actions (Copy, Move, Link to...), thumbnail
 *  updates, selecting/deselecting files with +/-  etc.
 */

class SQ_WidgetStack : public TQObject
{
    Q_OBJECT
  TQ_OBJECT

    public:
        /*
         *  Create navigator.
         *  id ::=
         *    0 = List view
         *    1 = Icon view
         *    2 = Detail view
         *    3 = Thumbnail view
         */
        SQ_WidgetStack(TQWidget *tqparent, const int id);

        ~SQ_WidgetStack();

        /*
         *  Direction for moveTo(). 
         */
        enum Direction { Next = 0, Previous };

        enum FileAction { Copy = 0, Cut, Link, Unknown };

        enum moveToError { moveSuccess = 0, moveFailed } ;

        SQ_DirOperator* diroperator() const;

        bool updateRunning() const;

        void repeat();

        void init();

        void saveState();

        /*
         *  Get current url. Just calls SQ_DirOperator::url().
         */
        KURL url() const;

        /*
         *  Selected items in currently visible diroperator.
         */
        const KFileItemList* selectedItems() const;

        /*
         *  All items in currently visible diroperator.
         */
        const KFileItemList* items() const;

        /*
         *  Update grid for thumbnail view. New grid is calcalated from item
         *  margins (from Options).
         */
        void updateGrid(bool arrange);

        /*
         *  Reread current directory.
         */
        void updateView();

        /*
         *  Quick access to SQ_DirOperator::actionCollection::action()
         */
        KAction *action(const TQString &name);

        /*
         *  Select first supported image in current directory.
         *  Used by SQ_GLWidget.
         */
        void firstFile();

        /*
         *  Select last supported image in current directory.
         *  Used by SQ_GLWidget.
         */
        void lastFile();

        static SQ_WidgetStack* instance() { return m_instance; }

    private:

        void emitNewLastURL(const KURL &u);

        void moveToFirstLast(Direction d, bool exec = true);
        /*
         *  Save currently selected items' paths, if any.
         *
         *  Return true, if at least one url was saved.
         */
        bool prepare();

        /*
         *  Execute SQ_SelectDeselectGroup dialog, and select or
         *  deselect files after it has been closed.
         */
        void selectDeselectGroup(bool select);

        /*
         *  Set current url for all _other_ widgets and objects (bookmarks,
         *  tree, SQ_QuickOperator etc.)
         */
        void setURL(const KURL &, bool = true);

    signals:
        void newLastURL(const TQString &);

    public slots:
        /*
         *  Change view type. See SQ_DirOperator::ViewT for more.
         */
        void raiseWidget(SQ_DirOperator::ViewT, bool doUpdate = true);

        void slotSelectFirstFile();
        void slotSelectLastFile();

        void emitNextSelected();
        void emitPreviousSelected();

        /*
         *  Set filter.
         */
        void setNameFilter(const TQString&);

        /*
         *  Used by SQ_FileThumbView to manipulate thumbnail progress.
         */
        void thumbnailsUpdateEnded();
        void thumbnailUpdateStart(int);
        void thumbnailProcess();
        void slotDelayedShowProgress();

        /*
         *  Set url
         */
        void setURLForCurrent(const TQString &, bool parseTree = true);
        void setURLForCurrent(const KURL &, bool parseTree = true);
        void slotRunSeparately();

        /*
         *  Select next/prevous supported image in filemanager.
         *  Do nothing, if no more supported images found in given
         *  direction.
         */
        int moveTo(Direction direction, KFileItem *it = 0, bool useSupported = true);

        /*
         *  Get current filter.
         */
        TQString nameFilter() const;

        /*
         *  Slots for file actions: copy, move, cut...
         */
        void slotFileCopy();
        void slotFileCut();
        void slotFilePaste();
        void slotFileCopyTo();
        void slotFileMoveTo();
        void slotFileLinkTo();

    private slots:
        void slotRecreateThumbnail();
        void slotDelayedRecreateThumbnail();

        void slotTreeMenuDone(const KURL &, int);

        void slotJobResult(KIO::Job *job);

        /*
         *  User wants to select to deselect some files.
         */
        void slotSelectGroup();
        void slotDeselectGroup();

        /*
         *  Deselect all files.
         */
        void slotDeselectAll();

        /*
         *  Select all files.
         */
        void slotSelectAll();

    private:
        /*
         *  File manager itself
         */
        SQ_DirOperator    *dirop;

        TQTimer        *timerShowProgress;
        KURL::List    files; // files to copy, move or link
        KURL          lastURL;
        FileAction    fileaction;

        static SQ_WidgetStack    *m_instance;
};

inline
SQ_DirOperator* SQ_WidgetStack::diroperator() const
{
    return dirop;
}

#endif