summaryrefslogtreecommitdiffstats
path: root/libkonq/konq_dirpart.h
blob: 9c5d0735ebdff070f4330184cc4df84968bfc546 (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
/* This file is part of the KDE projects
   Copyright (C) 2000 David Faure <[email protected]>

   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.

   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.
*/

#ifndef __konqdirpart_h
#define __konqdirpart_h

#include <tqstring.h>
#include <kparts/part.h>
#include <kparts/browserextension.h>
#include <kfileitem.h>
#include <kdatastream.h>
#include <kio/global.h>
#include <libkonq_export.h>

class KDirLister;
namespace KParts { class BrowserExtension; }
class KonqPropsView;
class TQScrollView;
class KAction;
class KToggleAction;
class KonqDirPartBrowserExtension;

class LIBKONQ_EXPORT KonqDirPart: public KParts::ReadOnlyPart
{
    Q_OBJECT

    friend class KonqDirPartBrowserExtension;

public:
    KonqDirPart( TQObject *parent, const char *name );

    virtual ~KonqDirPart();

    /**
     * The derived part should call this in its constructor
     */
    void setBrowserExtension( KonqDirPartBrowserExtension * extension )
      { m_extension = extension; }

    KonqDirPartBrowserExtension * extension()
      { return m_extension; }

    /**
     * The derived part should call this in its constructor
     */
    void setDirLister( KDirLister* lister );
    // TODO KDE4 create the KDirLister here and simplify the parts?

    TQScrollView * scrollWidget();

    virtual void saveState( TQDataStream &stream );
    virtual void restoreState( TQDataStream &stream );

    /** Called when LMB'ing an item in a directory view.
     * @param fileItem must be set
     * @param widget is only set as parent pointer for dialog boxes */
    void lmbClicked( KFileItem * fileItem );

    /** Called when MMB'ing an item in a directory view.
     * @param fileItem if 0 it means we MMB'ed the background. */
    void mmbClicked( KFileItem * fileItem );

    void setNameFilter( const TQString & nameFilter ) { m_nameFilter = nameFilter; }

    TQString nameFilter() const { return m_nameFilter; }

    void setFilesToSelect( const TQStringList & filesToSelect ) { m_filesToSelect = filesToSelect; }

    /**
     * Sets per directory mime-type based filtering.
     *
     * This method causes only the items matching the mime-type given
     * by @p filters to be displayed. You can supply multiple mime-types
     * by separating them with a space, eg. "text/plain image/x-png".
     * To clear all the filters set for the current url simply call this
     * function with a null or empty argument.
     *
     * NOTE: the filter(s) specified here only apply to the current
     * directory as returned by @ref #url().
     *
     * @param filter mime-type(s) to filter directory by.
     */
    void setMimeFilter (const TQStringList& filters);

    /**
     * Completely clears the internally stored list of mime filters
     * set by call to @ref #setMimeFilter.
     */
    TQStringList mimeFilter() const;


    KonqPropsView * props() const { return m_pProps; }

    /**
     * "Cut" icons : disable those whose URL is in lst, enable the others
     */
    virtual void disableIcons( const KURL::List & lst ) = 0;

    /**
     * This class takes care of the counting of items, size etc. in the
     * current directory. Call this in slotClear.
     */
    void resetCount();

    /**
     * Update the counts for those new items
     */
    void newItems( const KFileItemList & entries );

    /**
     * Update the counts with this item being deleted
     */
    void deleteItem( KFileItem * fileItem );

    /**
     * Show the counts for the directory in the status bar
     */
    void emitTotalCount();

    // ##### TODO KDE 4: remove!
    /**
     * Show the counts for the list of items in the status bar.
     * If none are provided emitTotalCount() is called to display
     * the counts for the whole directory. However, that does not work
     * for a treeview.
     * 
     * @deprecated
     */
    void emitCounts( const KFileItemList & lst, bool selectionChanged );
    
    /**
     * Show the counts for the list of items in the status bar. The list
     * can be empty.
     * 
     * @param lst the list of fileitems for which to display the counts
     * @since 3.4
     */
    void emitCounts( const KFileItemList & lst );

    void emitMouseOver( const KFileItem * item );

    /**
     * Enables or disables the paste action. This depends both on
     * the data in the clipboard and the number of files selected
     * (pasting is only possible if not more than one file is selected).
     */
    void updatePasteAction();

    /**
     * Change the icon size of the view.
     * The view should call it initially.
     * The view should also reimplement it, to update the icons.
     */
    virtual void newIconSize( int size );

    /**
     * This is called by the actions that change the icon size.
     * It stores the new size and calls newIconSize.
     */
    void setIconSize( int size );

    /**
     * This is called by konqueror itself, when the "find" functionality is activated
     */
    void setFindPart( KParts::ReadOnlyPart * part );

    KParts::ReadOnlyPart * findPart() const { return m_findPart; }

    virtual const KFileItem * currentItem() = 0; // { return 0L; }

    virtual KFileItemList selectedFileItems() { return KFileItemList(); }

    /**
     * Re-implemented for internal reasons.  API is unaffected.  All inheriting
     * classes should re-implement @ref doCloseURL() instead instead of this one.
     */
    bool closeURL ();

signals:

    /**
     * Emitted whenever the current URL is about to be changed.
     */
    void aboutToOpenURL();

    /**
     * We emit this if we want a find part to be created for us.
     * This happens when restoring from history
     */
    void findOpen( KonqDirPart * );

    /**
     * We emit this _after_ a find part has been created for us.
     * This also happens initially.
     */
    void findOpened( KonqDirPart * );

    /**
     * We emit this to ask konq to close the find part
     */
    void findClosed( KonqDirPart * );

    /**
     * Emitted as the part is updated with new items.
     * Useful for informing plugins of changes in view.
     */
    void itemsAdded( const KFileItemList& );

    /**
     * Emitted as the part is updated with these items.
     * Useful for informing plugins of changes in view.
     */
    void itemRemoved( const KFileItem* );

    /**
     * Emitted with the list of filtered-out items whenever
     * a mime-based filter(s) is set.
     */
    void itemsFilteredByMime( const KFileItemList& );

public slots:

    /**
     * Re-implemented for internal reasons.  API is unaffected.  All inheriting
     * classes should re-implement @ref doOpenURL() instead instead of this one.
     */
     bool openURL (const KURL&);

    /**
     * This is called either by the part's close button, or by the
     * dir part itself, if entering a directory. It deletes the find
     * part.
     */
    void slotFindClosed();

    /**
     * Start the animated "K" during kfindpart's file search
     */
    void slotStartAnimationSearching();

    /**
     * Start the animated "K" during kfindpart's file search
     */
    void slotStopAnimationSearching();

    void slotBackgroundSettings();

    /**
     * Called when the clipboard's data changes, to update the 'cut' icons
     * Call this when the directory's listing is finished, to draw icons as cut.
     */
    void slotClipboardDataChanged();

    void slotIncIconSize();
    void slotDecIconSize();

    void slotIconSizeToggled( bool );

    // slots connected to the directory lister - or to the kfind interface
    virtual void slotStarted() = 0;
    virtual void slotCanceled() = 0;
    virtual void slotCompleted() = 0;
    virtual void slotNewItems( const KFileItemList& ) = 0;
    virtual void slotDeleteItem( KFileItem * ) = 0;
    virtual void slotRefreshItems( const KFileItemList& ) = 0;
    virtual void slotClear() = 0;
    virtual void slotRedirection( const KURL & ) = 0;

private slots:
    void slotIconChanged(int group);
protected:
    /**
     * Invoked from openURL to enable childern classes to
     * handle open URL requests.
     */
    virtual bool doOpenURL( const KURL& ) = 0;
    virtual bool doCloseURL () = 0;

protected:

    TQString m_nameFilter;
    TQStringList m_filesToSelect;

    KonqPropsView * m_pProps;

    KAction *m_paIncIconSize;
    KAction *m_paDecIconSize;
    KToggleAction *m_paDefaultIcons;
    KToggleAction *m_paHugeIcons;
    KToggleAction *m_paLargeIcons;
    KToggleAction *m_paMediumIcons;
    KToggleAction *m_paSmallIcons;

    KParts::ReadOnlyPart * m_findPart;
    KonqDirPartBrowserExtension * m_extension;

    // Remove all those in KDE4
    int m_iIconSize[5];
    TDEIO::filesize_t m_lDirSize;
    uint m_lFileCount;
    uint m_lDirCount;

private:
    void saveFindState( TQDataStream& );
    void restoreFindState( TQDataStream& );

    void adjustIconSizes();

    class KonqDirPartPrivate;
    KonqDirPartPrivate* d;
};

class LIBKONQ_EXPORT KonqDirPartBrowserExtension : public KParts::BrowserExtension
{
public:
    KonqDirPartBrowserExtension( KonqDirPart* dirPart )
        : KParts::BrowserExtension( dirPart )
        , m_dirPart( dirPart )
    {}

    /**
     * This calls saveState in KonqDirPart, and also takes care of the "find part".
     *
     * If your KonqDirPart-derived class needs to save and restore state,
     * you should probably override KonqDirPart::saveState
     * and KonqDirPart::restoreState, not the following methods.
     */
    virtual void saveState( TQDataStream &stream );
    virtual void restoreState( TQDataStream &stream );

private:
    KonqDirPart* m_dirPart;
};

#endif