summaryrefslogtreecommitdiffstats
path: root/kdesktop/kdiconview.h
blob: f3ebe67181d7f0ec6e8faa1f6416ac1a3c4eb8f2 (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
/* This file is part of the KDE project
   Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
   Copyright (C) 2000, 2001 David Faure <faure@kde.org>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License version 2 as published by the Free Software Foundation.

   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 kdiconview_h
#define kdiconview_h

#include <tqtimer.h>
#include <tqlistview.h>

#include <konq_iconviewwidget.h>
#include <tdeaction.h>
#include <tdefileitem.h>
#include <kdirnotify.h>
#include <tdemessagebox.h>

#include <dcopclient.h>

class KDirLister;
class KonqSettings;
class KSimpleConfig;
class TDEAccel;
class KShadowEngine;
class KDesktopShadowSettings;

/**
 * This class is KDesktop's icon view.
 * The icon view is a child widget of the KDesktop widget.
 *
 * Added shadow capability by Laur Ivan (C) 2003
 * The shadow is supported by the new KFileIVIDesktop objects
 * which replace KFileIVI objects.
 */
class KDIconView : public KonqIconViewWidget, public KDirNotify
{
    Q_OBJECT

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

    virtual void initConfig( bool init );
    void configureMedia();
    /**
     * Start listing
     */
    void start();

    TDEActionCollection *actionCollection() { return &m_actionCollection; }

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

    void rearrangeIcons( SortCriterion sc, bool bSortDirectoriesFirst);

    /**
     * Re-arrange the desktop icons without confirmation.
     */
    void rearrangeIcons();

    void lineupIcons(TQIconView::Arrangement);

    void setIconsLocked( bool b );
    void setAutoAlign( bool b );

    TQStringList selectedURLs();

    void update( const TQString &url );

    /**
     * Save the icon positions
     */
    void saveIconPositions();

    /**
     * Check if the URL to the desktop has changed
     */
    void recheckDesktopURL();

    /**
     * Called when the desktop icons area has changed
     */
    void updateWorkArea( const TQRect &wr );

    /**
     * Reimplemented from KonqIconViewWidget (for image drops)
     */
    virtual void setWallpaper(const KURL &url) { emit newWallpaper( url ); }
    void setLastIconPosition( const TQPoint & );

    static KURL desktopURL();

    /// KDirNotify interface, for trash:/
    virtual void FilesAdded( const KURL & directory );
    virtual void FilesRemoved( const KURL::List & fileList );
    virtual void FilesChanged( const KURL::List & ) {}

    void startDirLister();

    TQPoint findPlaceForIconCol( int column, int dx, int dy, const TQRect &currentIconArea );
    TQPoint findPlaceForIconRow( int row, int dx, int dy, const TQRect &currentIconArea );
    TQPoint findPlaceForIcon( int column, int row, const TQRect &currentIconArea = TQRect() );

protected slots:

    // slots connected to the icon view
    void slotReturnPressed( TQIconViewItem *item );
    void slotExecuted( TQIconViewItem *item );
    void slotMouseButtonPressed(int _button, TQIconViewItem* _item, const TQPoint& _global);
    void slotMouseButtonClickedKDesktop(int _button, TQIconViewItem* _item, const TQPoint& _global);
    void slotContextMenuRequested(TQIconViewItem* _item, const TQPoint& _global);
    void slotEnableAction( const char * name, bool enabled );
public slots:
    void slotAboutToCreate(const TQPoint &pos, const TQValueList<TDEIO::CopyInfo> &files);
protected slots:
    void slotItemRenamed(TQIconViewItem*, const TQString &name);

    // slots connected to the directory lister
    void slotStarted( const KURL& url );
    void slotCompleted();
    void slotNewItems( const KFileItemList& );
    void slotDeleteItem( KFileItem * );
    void slotRefreshItems( const KFileItemList& );

    // slots connected to the popupmenu (actions)
    void slotCut();
    void slotCopy();
    void slotTrashActivated( TDEAction::ActivationReason reason, TQt::ButtonState state );
    void slotDelete();
    void slotPopupPasteTo();
    void slotProperties();

    void slotClipboardDataChanged();

    void slotNewMenuActivated();

    // For communication with KDesktop
signals:
    void colorDropEvent( TQDropEvent *e );
    void imageDropEvent( TQDropEvent *e );
    void newWallpaper( const KURL & );
    void iconMoved();
    void wheelRolled( int delta );

public slots:
    /**
     * Lineup the desktop icons.
     */
    void lineupIcons();
    void slotPaste(); // for krootwm
    void slotClear();
    void refreshIcons();

    void incIconSpacing();
    void decIconSpacing();

protected slots:
    void slotFreeSpaceOverlayStart();
    void slotFreeSpaceOverlayFinished();
    void slotFreeSpaceOverlaySettingChanged();

protected:
    void createActions();
    void setupSortKeys();
    void initDotDirectories();

    bool makeFriendlyText( KFileIVI *fileIVI );
    static TQString stripDesktopExtension( const TQString & text );
    bool isDesktopFile( KFileItem * _item ) const;
    bool isFreePosition( const TQIconViewItem *item, const TQRect &currentIconArea ) const;
    bool isFreePosition( const TQIconViewItem *item, const TQRect& rect, const TQRect &currentIconArea ) const;
    void moveToFreePosition(TQIconViewItem *item, const TQRect &currentIconArea );

    bool deleteGlobalDesktopFiles();
    void removeBuiltinIcon(TQString iconName);
    void fillMediaListView();
    void saveMediaListView();

    static void renameDesktopFile(const TQString &path, const TQString &name);

    void popupMenu( const TQPoint &_global, const KFileItemList& _items );
    virtual void showEvent( TQShowEvent *e );
    virtual void contentsDropEvent( TQDropEvent *e );
    virtual void viewportWheelEvent( TQWheelEvent * );
    virtual void contentsMousePressEvent( TQMouseEvent *e );
    virtual void mousePressEvent( TQMouseEvent *e );
    virtual void wheelEvent( TQWheelEvent* e );

private:
    void refreshTrashIcon();

    static TQRect desktopRect();
    static void saveIconPosition(KSimpleConfig *config, int x, int y);
    static void readIconPosition(KSimpleConfig *config, int &x, int &y);

    void showFreeSpaceOverlay(KFileIVI*  item);

    /** Our action collection, parent of all our actions */
    TDEActionCollection m_actionCollection;

    /** TDEAccel object, to make the actions shortcuts work */
    TDEAccel *m_accel;

    bool m_bNeedRepaint;
    bool m_bNeedSave;
    bool m_iconsLocked;
    bool m_autoAlign;

    /** true if even one icon has an icon-position entry in the .directory */
    bool m_hasExistingPos;

    /** whether the user may move/edit/remove desktop icons */
    bool m_bEditableDesktopIcons;

    /** Show dot files ? */
    bool m_bShowDot;

    /** Vertical or Horizontal align of icons on desktop */
    bool m_bVertAlign;

    /** The directory lister - created only in start() */
    KDirLister* m_dirLister;

    /** The list of urls to be merged into the desktop, in addition to desktopURL */
    KURL::List m_mergeDirs;

    /** The list of dirs to be merged into the desktop, in addition to desktopURL **/
    TQStringList m_desktopDirs;

    /** The desktop's .directory, used for storing icon positions */
    KSimpleConfig *m_dotDirectory;

    /** Position of last deleted icon - used when renaming a file */
    TQPoint m_lastDeletedIconPos;

    /** Sorting */
    SortCriterion m_eSortCriterion;
    bool m_bSortDirectoriesFirst;
    TQStringList m_itemsAlwaysFirst;

    /**
     * The shadow object
     */
    KShadowEngine *m_shadowEngine;

    /** Position where to move the next item.
     * It is set to the KRootWm position when "new file" is chosen. */
    TQPoint m_nextItemPos;

    /** Position where the last drop occurred */
    TQPoint m_dropPos;

    /** Position for the last dropped item */
    TQPoint m_lastDropPos;

    /** URL of the items which is being RMB'ed - when only one */
    KURL m_popupURL;

    /** media list management */
    bool m_enableMedia;
    TQStringList m_excludedMedia;

    // did we already get the correct desktopIconsArea (from kicker)
    // needed when we want to line up icons on a grid
    bool m_gotIconsArea;

    bool m_needDesktopAlign;

    TQListView *mMediaListView;

    TQPtrList<KFileIVI> m_paOutstandingFreeSpaceOverlays;
    TQTimer *m_paOutstandingFreeSpaceOverlaysTimer;

    TDEConfig *g_pConfig;
};

#endif