summaryrefslogtreecommitdiffstats
path: root/src/gvcore/fileviewcontroller.h
blob: 101ce9ae53bc41cb7b3e128da62ea999243beeee (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
/*
Gwenview - A simple image viewer for TDE
Copyright 2000-2004 Aurélien Gâteau

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

// TQt 
#include <tqdir.h>
#include <tqslider.h>
#include <tqwidget.h>

// KDE
#include <kdirlister.h>
#include <tdefileitem.h>
#include <tdeio/job.h>
#include <kurl.h>

#include "libgwenview_export.h"
class TQIconViewItem;
class TQListViewItem;
class TQPopupMenu;

class TDEAccel;
class TDEAction;
class TDEActionCollection;
class TDEConfig;
class TDEListView;
class TDERadioAction;
class TDEToggleAction;

namespace Gwenview {
class FileViewBase;
class FileDetailView;
class FileThumbnailView;
class ImageLoader;


class DirLister;

class LIBGWENVIEW_EXPORT FileViewController : public TQWidget {
Q_OBJECT
  

public:
	enum Mode { FILE_LIST, THUMBNAIL};
	enum FilterMode { ALL, IMAGES_ONLY, VIDEOS_ONLY };

	FileViewController(TQWidget* parent,TDEActionCollection*);
	~FileViewController();

	// Properties
	void setMode(Mode);
	
	TQString fileName() const;
	KURL url() const;
	KURL dirURL() const;
	uint fileCount() const;
	int shownFilePosition() const;
	
	uint selectionSize() const;

	FileViewBase* currentFileView() const;
	FileThumbnailView* fileThumbnailView() const { return mFileThumbnailView; }
	
	TDEAction* selectFirst() const { return mSelectFirst; }
	TDEAction* selectLast() const { return mSelectLast; }
	TDEAction* selectPrevious() const { return mSelectPrevious; }
	TDEAction* selectNext() const { return mSelectNext; }
	TDEAction* selectPreviousDir() const { return mSelectPreviousDir; }
	TDEAction* selectNextDir() const { return mSelectNextDir; }
	TDEAction* selectFirstSubDir() const { return mSelectFirstSubDir; }
	TDERadioAction* listMode() const { return mListMode; }
	TDERadioAction* sideThumbnailMode() const { return mSideThumbnailMode; }
	TDERadioAction* bottomThumbnailMode() const { return mBottomThumbnailMode; }
	TDEToggleAction* showDotFiles() const { return mShowDotFiles; }

	KURL::List selectedURLs() const;
	KURL::List selectedImageURLs() const;
	/**
	 * If set to true, no error messages will be displayed.
	 */
	void setSilentMode( bool silent );
	/**
	 * Returns true if there was an error since last URL had been opened.
	 */
	bool lastURLError() const;
	/**
	 * Tries to open again the active URL. Useful for showing error messages
	 * initially supressed by silent mode.
	 */
	void retryURL();

	void refreshItems( const KURL::List& urls ); // used by a workaround in KIPIInterface

	virtual void setFocus();
	
public slots:
	void setDirURL(const KURL&);
	void setFileNameToSelect(const TQString&);

	void slotSelectFirst();
	void slotSelectLast();
	void slotSelectPrevious();
	void slotSelectNext();
	void slotSelectPreviousDir();
	void slotSelectNextDir();
	void slotSelectFirstSubDir();

	void updateThumbnail(const KURL&);

	void updateFromSettings();

	void setShowFilterBar(bool);
	// 'int' suck, but I don't want to #include fileviewconfig.h
	void setFilterMode(int);
	void setFilterName(const TQString&);
	void setFilterFromDate(const TQDate&);
	void setFilterToDate(const TQDate&);
	void applyFilter();

signals:
	void urlChanged(const KURL&);
	/**
	 * Used by DirPart to tell Konqueror to change directory
	 */
	void directoryChanged(const KURL&);

	void selectionChanged();
	void completed();
	void canceled();
	void imageDoubleClicked();
	void shownFileItemRefreshed(const KFileItem*);
	void sortingChanged();
	void requestContextMenu(const TQPoint& pos, bool onItem);

private slots:
	void delayedDirListerCompleted();
	
	// Used to enter directories
	void slotViewExecuted();

	// Used to change the current image
	void slotViewClicked();

	void slotViewDoubleClicked();
	
	// These two methods forward the context menu requests from either view to
	// openContextMenu(const TQPoint&);
	void openContextMenu(TDEListView*, TQListViewItem*, const TQPoint&);
	void openContextMenu(TQIconViewItem*,const TQPoint&);

	// Get called by the thumbnail mode actions
	void updateViewMode();
	
	// Get called by the thumbnail slider
	void updateThumbnailSize(int);

	void toggleShowDotFiles();
	void setSorting();
	void updateSortMenu(TQDir::SortSpec);

	// Dir lister slots
	void dirListerDeleteItem(KFileItem* item);
	void dirListerNewItems(const KFileItemList& items);
	void dirListerRefreshItems(const KFileItemList&);
	void dirListerClear();
	void dirListerStarted();
	void dirListerCanceled();
	void dirListerCompleted();

	void openDropURLMenu(TQDropEvent*, KFileItem*);

	void prefetchDone();

	void resetNameFilter();
	void resetFromFilter();
	void resetToFilter();

private:
	struct Private;
	Private* d;
	Mode mMode;
	FileDetailView* mFileDetailView;
	FileThumbnailView* mFileThumbnailView;
	DirLister* mDirLister;
	KURL mDirURL;
	ImageLoader* mPrefetch;

	// Our actions
	TDEAction* mSelectFirst;
	TDEAction* mSelectLast;
	TDEAction* mSelectPrevious;
	TDEAction* mSelectNext;
	TDEAction* mSelectPreviousDir;
	TDEAction* mSelectNextDir;
	TDEAction* mSelectFirstSubDir;
	
	TDERadioAction* mListMode;
	TDERadioAction* mSideThumbnailMode;
	TDERadioAction* mBottomThumbnailMode;

	TQSlider* mSizeSlider;

	TDEToggleAction* mShowDotFiles;

	// Temp data used by the dir lister
	bool mThumbnailsNeedUpdate;
	TQString mFileNameToSelect;
	enum ChangeDirStatusVals {
		CHANGE_DIR_STATUS_NONE,
		CHANGE_DIR_STATUS_PREV,
		CHANGE_DIR_STATUS_NEXT
	} mChangeDirStatus;

	bool mBrowsing;
	bool mSelecting;
	
	/**
	 * Browse to the given item. Prevents multiple calls using mBrowsing.
	 */
	void browseTo(KFileItem* item);

	void browseToFileNameToSelect();
	void emitURLChanged();
	void updateActions();
	void prefetch( KFileItem* item );
	
	KFileItem* findFirstImage() const;
	KFileItem* findLastImage() const;
	KFileItem* findPreviousImage() const;
	KFileItem* findNextImage() const;
	KFileItem* findItemByFileName(const TQString& fileName) const;

	bool eventFilter(TQObject*, TQEvent*);
};


} // namespace
#endif