summaryrefslogtreecommitdiffstats
path: root/konqueror/listview/konq_listviewwidget.h
blob: c55996306e2dfc5e7d469c7a40a4d0273cec73e1 (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
/* This file is part of the KDE project
   Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
                 2004 Michael Brade <brade@kde.org>

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

#include <tqvaluelist.h>
#include <tqvaluevector.h>

#include <kurl.h>
#include <kfileitem.h>
#include <klistview.h>
#include <kparts/browserextension.h>
#include <konq_propsview.h>
#include "konq_listviewitems.h"

namespace KIO { class Job; }

class TQCursor;
class TQRect;
class KDirLister;
class KonqFMSettings;
class ListViewPropertiesExtension;
class KToggleAction;
class KonqListView;
class KonqFileTip;
class ListViewBrowserExtension;
class TQTimer;
class TQFocusEvent;
class TQDragMoveEvent;
class TQDragEnterEvent;
class TQDragLeaveEvent;
class TQDropEvent;
class TQPaintEvent;
class TQResizeEvent;
class TQMouseEvent;

class ColumnInfo
{
public:
   ColumnInfo();
   void setData( const TQString& n, const TQString& desktopName, int kioUds,
                 KToggleAction *someAction, int theWith = -1 );
   void setData( const TQString& n, const TQString& desktopName, int kioUds /* UDS_EXTRA */,
                 TQVariant::Type type, KToggleAction *someAction, int theWith = -1 );
   int displayInColumn;
   TQString name;
   TQString desktopFileName;
   int udsId;
   TQVariant::Type type; // only used if udsId == UDS_EXTRA
   bool displayThisOne;
   KToggleAction *toggleThisOne;
   int width;
};

/**
 * The tree view widget (based on KListView).
 * Most of the functionality is here.
 */
class KonqBaseListViewWidget : public KListView
{
   friend class KonqBaseListViewItem;
   friend class KonqListView;
   friend class ListViewBrowserExtension;

   Q_OBJECT
   TQ_OBJECT
public:
   KonqBaseListViewWidget( KonqListView *parent, TQWidget *parentWidget );
   virtual ~KonqBaseListViewWidget();
   unsigned int NumberOfAtoms;

   virtual void stop();
   const KURL& url();

   struct iterator
   {
      KonqBaseListViewItem *m_p;

      iterator() : m_p( 0L ) { }
      iterator( KonqBaseListViewItem *_b ) : m_p( _b ) { }
      iterator( const iterator& _it ) : m_p( _it.m_p ) { }

      KonqBaseListViewItem& operator*() { return *m_p; }
      KonqBaseListViewItem *operator->() { return m_p; }
      bool operator==( const iterator& _it ) { return ( m_p == _it.m_p ); }
      bool operator!=( const iterator& _it ) { return ( m_p != _it.m_p ); }
      iterator& operator++();
      iterator operator++(int);
   };
   iterator begin() { iterator it( (KonqBaseListViewItem *)firstChild() ); return it; }
   iterator end() { iterator it; return it; }

   virtual bool openURL( const KURL &url );

   void selectedItems( TQPtrList<KonqBaseListViewItem> *_list );
   KFileItemList visibleFileItems();
   KFileItemList selectedFileItems();
   KURL::List selectedUrls( bool mostLocal = false );

   /** @return the KonqListViewDir which handles the directory _url */
   //virtual KonqListViewDir *findDir ( const TQString & _url );

   /**
    * @return the Properties instance for this view. Used by the items.
    */
   KonqPropsView *props() const;

   //TQPtrList<ColumnInfo> *columnConfigInfo() { return &confColumns; };
   TQValueVector<ColumnInfo>& columnConfigInfo() { return confColumns; };
   TQString sortedByColumn;

   virtual void setShowIcons( bool enable ) { m_showIcons = enable; }
   virtual bool showIcons() { return m_showIcons; }

   void setItemFont( const TQFont &f ) { m_itemFont = f; }
   TQFont itemFont() const { return m_itemFont; }
   void setItemColor( const TQColor &c ) { m_itemColor = c; }
   TQColor itemColor() const { return m_itemColor; }
   int iconSize() const { return props()->iconSize(); }

   void setAscending( bool b ) { m_bAscending = b; }
   bool ascending() const { return m_bAscending; }
   bool caseInsensitiveSort() const;

   virtual void paintEmptyArea( TQPainter *p, const TQRect &r );

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

   virtual void disableIcons( const KURL::List& lst );

   KonqListView *m_pBrowserView;
   KonqFMSettings *m_pSettings;

signals:
   void viewportAdjusted();

public slots:
   //virtual void slotOnItem( KonqBaseListViewItem* _item );
   // The '2' was added to differentiate it from KListView::slotMouseButtonClicked()
   void slotMouseButtonClicked2( int _button, TQListViewItem *_item, const TQPoint& pos, int );
   virtual void slotExecuted( TQListViewItem *_item );
   void slotItemRenamed( TQListViewItem *, const TQString &, int );

protected slots:
   void slotAutoScroll();

   // from TQListView
   virtual void slotReturnPressed( TQListViewItem *_item );
   virtual void slotCurrentChanged( TQListViewItem *_item ) { slotOnItem( _item ); }

   // slots connected to the directory lister
   virtual void slotStarted();
   virtual void slotCompleted();
   virtual void slotCanceled();
   virtual void slotClear();
   virtual void slotNewItems( const KFileItemList & );
   virtual void slotDeleteItem( KFileItem * );
   virtual void slotRefreshItems( const KFileItemList & );
   virtual void slotRedirection( const KURL & );
   void slotPopupMenu( TQListViewItem *, const TQPoint&, int );

   // forces a tqrepaint on column size changes / branch expansion
   // when there is a background pixmap
   void slotUpdateBackground();

   //Notifies the browser view of the currently selected items
   void slotSelectionChanged();
   virtual void reportItemCounts();

protected:
   //creates the listview columns according to confColumns
   virtual void createColumns();
   //reads the configuration for the columns of the current
   //protocol, it is called when the protocol changes
   //it checks/unchecks the menu items and sets confColumns
   void readProtocolConfig( const KURL& url );
   //calls updateContents of every ListViewItem, called after
   //the columns changed
   void updateListContents();

   //this is called in the constructor, so virtual would be nonsense
   void initConfig();

   virtual void startDrag();
   virtual void viewportDragMoveEvent( TQDragMoveEvent *_ev );
   virtual void viewportDragEnterEvent( TQDragEnterEvent *_ev );
   virtual void viewportDragLeaveEvent( TQDragLeaveEvent *_ev );
   virtual void viewportDropEvent( TQDropEvent *_ev );
   virtual void viewportPaintEvent( TQPaintEvent *e );
   virtual void viewportResizeEvent( TQResizeEvent *e );

   virtual void drawRubber( TQPainter * );
   virtual void contentsMousePressEvent( TQMouseEvent *e );
   virtual void contentsMouseReleaseEvent( TQMouseEvent *e );
   virtual void contentsMouseMoveEvent( TQMouseEvent *e );
   virtual void contentsWheelEvent( TQWheelEvent * e );

   virtual void leaveEvent( TQEvent *e );

   /** Common method for slotCompleted and slotCanceled */
   virtual void setComplete();

   //the second parameter is set to true when the menu shortcut is pressed,
   //so the position of the mouse pointer doesn't matter when using keyboard, aleXXX
   virtual void popupMenu( const TQPoint& _global, bool alwaysForSelectedFiles = false );

   //this one is called only by KListView, and this is friend anyways (Alex)
   //KDirLister *dirLister() const { return m_dirLister; }

protected:
   int executeArea( TQListViewItem *_item );

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

   //TQPtrList<ColumnInfo> confColumns;
   // IMO there is really no need for an advanced data structure
   //we have a fixed number of members,
   //it consumes less memory and access should be faster (Alex)
   // This might not be the case for ever... we should introduce custom fields in kio (David)
   TQValueVector<ColumnInfo> confColumns;

   KonqBaseListViewItem *m_dragOverItem;
   KonqBaseListViewItem *m_activeItem;
   TQPtrList<KonqBaseListViewItem> *m_selected;
   TQTimer *m_scrollTimer;

   TQFont m_itemFont;
   TQColor m_itemColor;

   TQRect *m_rubber;
   TQPixmap *m_backrubber;
   
   bool m_bTopLevelComplete:1;
   bool m_showIcons:1;
   bool m_bCaseInsensitive:1;
   bool m_bUpdateContentsPosAfterListing:1;
   bool m_bAscending:1;
   bool m_itemFound:1;
   bool m_restored:1;

   int m_filenameColumn;
   int m_filenameColumnWidth;

   KURL m_url;

   TQString m_itemToGoTo;
   TQStringList m_itemsToSelect;
   TQTimer *m_backgroundTimer;

   KonqFileTip *m_fileTip;
};

#endif