summaryrefslogtreecommitdiffstats
path: root/konqueror/iconview/konq_iconview.h
blob: d66cc4cc8fa0fc2282d190c9191b91eb633f36f7 (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
/*  This file is part of the KDE project
    Copyright (C) 1998, 1999 Torben Weis <[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; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#ifndef __konq_iconview_h__
#define __konq_iconview_h__

#include <tdeparts/browserextension.h>
#include <konq_iconviewwidget.h>
#include <konq_operations.h>
#include <konq_dirpart.h>
#include <kmimetyperesolver.h>
#include <tqptrdict.h>
#include <tqptrlist.h>
#include <tdefileivi.h>

class KonqPropsView;
class KFileItem;
class KDirLister;
class TDEAction;
class TDEToggleAction;
class TDEActionMenu;
class TQIconViewItem;
class IconViewBrowserExtension;

/**
 * The Icon View for konqueror.
 * The "Kfm" in the name stands for file management since it shows files :)
 */
class KonqKfmIconView : public KonqDirPart
{
  friend class IconViewBrowserExtension; // to access m_pProps
  Q_OBJECT
  TQ_PROPERTY( bool supportsUndo READ supportsUndo )
  TQ_PROPERTY( TQString viewMode READ viewMode WRITE setViewMode )
public:

  enum SortCriterion { NameCaseSensitive, NameCaseInsensitive, Size, Type, Date };

  KonqKfmIconView( TQWidget *parentWidget, TQObject *parent, const char *name, const TQString& mode );
  virtual ~KonqKfmIconView();

  virtual const KFileItem * currentItem();
  virtual KFileItemList selectedFileItems() {return m_pIconView->selectedFileItems();};


  KonqIconViewWidget *iconViewWidget() const { return m_pIconView; }

  bool supportsUndo() const { return true; }

  void setViewMode( const TQString &mode );
  TQString viewMode() const { return m_mode; }

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

  // See KMimeTypeResolver
  void mimeTypeDeterminationFinished();
  void determineIcon( KFileIVI * item );
  int iconSize() { return m_pIconView->iconSize(); }

public slots:
  void slotPreview( bool toggle );
  void slotShowDirectoryOverlays();
  void slotShowFreeSpaceOverlays();
  void slotShowDot();
  void slotSelect();
  void slotUnselect();
  void slotSelectAll();
  void slotUnselectAll();
  void slotInvertSelection();

  void slotSortByNameCaseSensitive( bool toggle );
  void slotSortByNameCaseInsensitive( bool toggle );
  void slotSortBySize( bool toggle );
  void slotSortByType( bool toggle );
  void slotSortByDate( bool toggle );
  void slotSortDescending();
  void slotSortDirsFirst();

protected slots:
  // slots connected to QIconView
  void slotReturnPressed( TQIconViewItem *item );
  void slotMouseButtonPressed(int, TQIconViewItem*, const TQPoint&);
  void slotMouseButtonClicked(int, TQIconViewItem*, const TQPoint&);
  void slotContextMenuRequested(TQIconViewItem*, const TQPoint&);
  void slotOnItem( TQIconViewItem *item );
  void slotOnViewport();
  void slotSelectionChanged();

  // Slot used for spring loading folders
  void slotDragHeld( TQIconViewItem *item );
  void slotDragMove( bool accepted );
  void slotDragEntered( bool accepted );
  void slotDragLeft();
  void slotDragFinished();

  // slots connected to the directory lister - or to the kfind interface
  // They are reimplemented from KonqDirPart.
  virtual void slotStarted();
  virtual void slotCanceled();
  void slotCanceled( const KURL& url );
  virtual void slotCompleted();
  virtual void slotNewItems( const KFileItemList& );
  virtual void slotDeleteItem( KFileItem * );
  virtual void slotRefreshItems( const KFileItemList& );
  virtual void slotClear();
  virtual void slotRedirection( const KURL & );
  virtual void slotDirectoryOverlayStart();
  virtual void slotFreeSpaceOverlayStart();
  virtual void slotDirectoryOverlayFinished();
  virtual void slotFreeSpaceOverlayFinished();

  /**
   * This is the 'real' finished slot, where we emit the completed() signal
   * after everything was done.
   */
  void slotRenderingFinished();
  // (Re)Draws m_pIconView's contents. Connected to m_pTimeoutRefreshTimer.
  void slotRefreshViewport();

  // Connected to KonqDirPart
  void slotKFindOpened();
  void slotKFindClosed();

protected:
  virtual bool openFile() { return true; }
  virtual bool doOpenURL( const KURL& );
  virtual bool doCloseURL();

  virtual void newIconSize( int size );

  void setupSorting( SortCriterion criterion );

  /** */
  void setupSortKeys();

  TQString makeSizeKey( KFileIVI *item );

  /** The directory lister for this URL */
  KDirLister* m_dirLister;

  /**
   * Set to true while the constructor is running.
   * @ref #initConfig needs to know about that.
   */
  bool m_bInit:1;

  /**
   * Set to true while the dirlister is running, _if_ we asked it
   * explicitly (openURL). If it is auto-updating, this is not set to true.
   */
  bool m_bLoading:1;

  /**
   * Set to true if we still need to emit completed() at some point
   * (after the loading is finished and after the visible icons have been
   * processed)
   */
  bool m_bNeedEmitCompleted:1;

  /**
   * Set to true if slotCompleted needs to realign the icons
   */
  bool m_bNeedAlign:1;

  bool m_bUpdateContentsPosAfterListing:1;

  bool m_bDirPropertiesChanged:1;
  
  /**
   * Set in doCloseURL and used in setViewMode to restart a preview
   * job interrupted when switching to IconView or MultiColumnView.
   * Hacks like this must be removed in KDE4!
   */
  bool m_bPreviewRunningBeforeCloseURL:1;

  bool m_bNeedSetCurrentItem:1;
  
  KFileIVI * m_pEnsureVisible;
  
  TQStringList m_itemsToSelect;
  
  SortCriterion m_eSortCriterion;

  TDEToggleAction *m_paDotFiles;
  TDEToggleAction *m_paDirectoryOverlays;
  TDEToggleAction *m_paFreeSpaceOverlays;
  TDEToggleAction *m_paEnablePreviews;
  TQPtrList<KFileIVI> m_paOutstandingOverlays;
  TQTimer *m_paOutstandingOverlaysTimer;
/*  TDEToggleAction *m_paImagePreview;
  TDEToggleAction *m_paTextPreview;
  TDEToggleAction *m_paHTMLPreview;*/
  TDEActionMenu *m_pamPreview;
  TQPtrList<TDEToggleAction> m_paPreviewPlugins;
  TDEActionMenu *m_pamSort;

  TDEAction *m_paSelect;
  TDEAction *m_paUnselect;
  TDEAction *m_paSelectAll;
  TDEAction *m_paUnselectAll;
  TDEAction *m_paInvertSelection;

  TDEToggleAction *m_paSortDirsFirst;

  KonqIconViewWidget *m_pIconView;

  TQTimer *m_pTimeoutRefreshTimer;

  TQPtrDict<KFileIVI> m_itemDict; // maps KFileItem * -> KFileIVI *

  KMimeTypeResolver<KFileIVI,KonqKfmIconView> * m_mimeTypeResolver;

  TQString m_mode;

  private:
  void showDirectoryOverlay(KFileIVI*  item);
  void showFreeSpaceOverlay(KFileIVI*  item);
};

class IconViewBrowserExtension : public KonqDirPartBrowserExtension
{
  Q_OBJECT
  friend class KonqKfmIconView; // so that it can emit our signals
public:
  IconViewBrowserExtension( KonqKfmIconView *iconView );

  virtual int xOffset();
  virtual int yOffset();

public slots:
  // Those slots are automatically connected by the shell
  void reparseConfiguration();
  void setSaveViewPropertiesLocally( bool value );
  void setNameFilter( const TQString &nameFilter );

  void refreshMimeTypes() { m_iconView->iconViewWidget()->refreshMimeTypes(); }

  void rename() { m_iconView->iconViewWidget()->renameSelectedItem(); }
  void cut() { m_iconView->iconViewWidget()->cutSelection(); }
  void copy() { m_iconView->iconViewWidget()->copySelection(); }
  void paste() { m_iconView->iconViewWidget()->pasteSelection(); }
  void pasteTo( const KURL &u ) { m_iconView->iconViewWidget()->paste( u ); }

  void trash();
  void del() { KonqOperations::del(m_iconView->iconViewWidget(),
                                   KonqOperations::DEL,
                                   m_iconView->iconViewWidget()->selectedUrls()); }
  void properties();
  void editMimeType();

  // void print();

private:
  KonqKfmIconView *m_iconView;
  bool m_bSaveViewPropertiesLocally;
};

class SpringLoadingManager : public QObject
{
    Q_OBJECT
private:
    SpringLoadingManager();
    static SpringLoadingManager *s_self;
public:
    static SpringLoadingManager &self();
    static bool exists();

    void springLoadTrigger(KonqKfmIconView *view, KFileItem *file,
                           TQIconViewItem *item);

    void dragLeft(KonqKfmIconView *view);
    void dragEntered(KonqKfmIconView *view);
    void dragFinished(KonqKfmIconView *view);

private slots:
    void finished();

private:
    KURL m_startURL;
    KParts::ReadOnlyPart *m_startPart;

    // Timer allowing to know the user wants to abort the spring loading
    // and go back to his start url (closing the opened window if needed)
    TQTimer m_endTimer;
};


#endif