summaryrefslogtreecommitdiff
path: root/libslcompat/slfileselector.h
blob: 94ed3b789a61b904ff1327d612138b24c9118d83 (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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
/*
 * Copyright (C) 2002 SHARP CORPORATION All rights reserved.
 */
#ifndef _SLFILESELECTOR_H_INCLUDED
#define _SLFILESELECTOR_H_INCLUDED

#include <opie2/ofileselector.h>
#include <qhbox.h>
#include <qvbox.h>
#include <qlistview.h>
#include <qiconview.h>
#include <qtoolbutton.h>
#include <qfileinfo.h>
#include <qtableview.h>
#include <qwidgetstack.h>
#include <qvaluelist.h>

#include <qpe/applnk.h>
#include <qpe/mimetype.h>
#include <sl/slmisc.h>

class QComboBox;
class SlFileItemType;
class QCopChannel;

struct SlFileListItemPrivate;
class SlFileListItem
{
public:
	SlFileListItem(const QFileInfo&,const MimeType&);
	~SlFileListItem();
	const QFileInfo &file() const;
	const MimeType &mimeType() const;
	const QString getItemIconFilePath() const;
	const QString name() const;
	void setName(const QString&);
	const QString sortKey() const;
	void setSortKey(const QString&);
	QPixmap pixmap() const;
	QPixmap bigPixmap() const;
	const QString dateString() const;
	const QString typeString() const;
	const QString bytesString() const;
	void setDevice();
	bool isDevice() const;
	enum ColumnItem {
		Name = 1,
		Type,
		Date,
		Bytes,
		Custom = 100
	};
private:
	SlFileListItemPrivate *p;
	SlFileListItem(const SlFileListItem&);
};

typedef QValueList<SlFileListItem*> SlFileList;
typedef QValueList<SlFileListItem::ColumnItem> SlFileListColumnConf;

class SlFileListViewItem;

struct SlFileListViewPrivate;
class SlFileListView : public QListView
{
	Q_OBJECT

public:
	SlFileListView(QWidget*, const char*);
	~SlFileListView();
	void createFileList(SlFileList&);
	int fileCount() const;
	void updateItem(SlFileListViewItem*);
	void createItem(SlFileListItem*);
	void deleteItem(const QString&);
	void deleteItem(SlFileListViewItem*);
	SlFileListViewItem* searchItem(const QString&);
	SlFileListColumnConf columnConf();
	void setColumnConf(SlFileListColumnConf&);
	void updateColumn();
	static const QString columnItemName(SlFileListItem::ColumnItem);
	static const SlFileListColumnConf columnItemList();

	//virtual void takeItem( SlFileListViewItem * );

	SlMisc::SlListColumnInfos columnWidthInfos();

protected:
	//void keyPressEvent( QKeyEvent *e );

signals:
	void keyPressed(QKeyEvent *e,bool &isAccepted);

protected slots:

private:
	friend class SlFileSelector;
	SlFileListViewPrivate *p;
	SlFileListView(const SlFileListView&);
};

class SlFileIconViewItem;

struct SlFileIconViewPrivate;
class SlFileIconView : public QIconView
{
	Q_OBJECT

public:
	SlFileIconView(QWidget*, const char*);
	~SlFileIconView();
	void createFileList(SlFileList&);
	int fileCount() const;
	void updateItem(SlFileIconViewItem*);
	void createItem(SlFileListItem*);
	void deleteItem(const QString&);
	void deleteItem(SlFileIconViewItem*);
	SlFileIconViewItem* searchItem(const QString&);
	void setSorting(int column,bool ascending);
	int sortColumn() const;
	void repaintItemsForce();
	SlFileListColumnConf columnConf();
	void setColumnConf(SlFileListColumnConf&);

	//virtual void takeItem( SlFileIconViewItem * );

protected:
	//void keyPressEvent( QKeyEvent *e );

protected slots:

signals:
	void keyPressed(QKeyEvent *e,bool &isAccepted);

private:
	friend class SlFileSelector;
	SlFileIconViewPrivate *p;
	SlFileIconView(const SlFileIconView&);
};

class SlFileSelectorFilter : public QObject
{
public:
	SlFileSelectorFilter(QWidget *parent,const char *name=0);
	~SlFileSelectorFilter();

	virtual bool isAddToList(QFileInfo&) const = 0;
private:
	SlFileSelectorFilter(const SlFileSelectorFilter&);
};

typedef QList<MimeType> SlFileMimeTypeList;

struct SlFileSelectorPrivate;
class SlFileSelector : public Opie::Ui::OFileSelector /*QVBox*/
{
	Q_OBJECT

public:


	enum SlFileSelectorViewType {

		ListView = 1,

		IconView
	};


	enum SlFileOverwirteMode {

		Overwrite = 1,

		NewName,

		Error
	};
	SlFileSelector(const QString &dirPath,
				   const QString &mimefilter,
				   QWidget *parent,
				   const char *name);
	SlFileSelector(const QString &currentFileName,
				   SlFileSelectorViewType type,
				   const QString &mimeFilter,
				   SlFileListColumnConf &items,
				   int sortColumn,bool sortAscending,
				   SlFileSelectorFilter *filter=NULL,
				   bool isRecursive=FALSE,
				   QWidget *parent=NULL,
				   const char *name=NULL,
				   WFlags f=0);
	SlFileSelector(QWidget *parent=NULL,const char *name=NULL,WFlags f=0);
	virtual ~SlFileSelector();
	void createFileList();
	void createFileList(QDir&);
	int fileCount() const;
	const QFileInfo* selected();
	void modifyItem(QFileInfo*,bool);
	void createItem(QString&);
	void deleteItem(const QString&);
	void deleteItem();
	void updateItem(const QString&);
	SlFileListItem* searchItem(const QString&);
	void setSelected();
	void setSelected(const QString&);
	void ensureItemVisible();
	SlFileListItem* selectedItem();
	bool setSelectedNext(bool);
	bool setSelectedPrev(bool);
	const QString currentDir();
	void setSorting(int,bool);
	int sortColumn() const;
	bool ascending() const;
	SlFileSelectorViewType viewType();
	void setColumnItem(SlFileListColumnConf&);
	void setViewType(SlFileSelectorViewType);
	void setListView();
	void setIconView();
	int columnWidth(int);
	void setColumnWidth(int,int);
	static const QString columnItemName(SlFileListItem::ColumnItem);
	static const SlFileListColumnConf columnItemList();

	int columns() const;

	bool upDir();
	bool isTopDir();

	void setCurrentFile(const QString&);
	const QString currentFile(bool isReal=FALSE);
	static bool copyFile(const QString&,const QString&,
						 SlFileOverwirteMode m=Error,
						 QString *resultName=NULL);

	static bool copyFileCreateDir(const QString &srcName,
								  const QString &dstName,
								  SlFileOverwirteMode m=Error,
								  QString *resultName=NULL);
	static bool moveFile(const QString&,const QString&,
						 SlFileOverwirteMode m=Error,
						 QString *resultName=NULL);
	static QString getCopyFileName(const QString&);

	const QStringList& recent() const;
	void setRecent(const QStringList&);


	void setRecent(const QStringList&,bool isReplace);
	void setRecentEnabled(bool);

	const QStringList& history() const;
	void setHistory(const QStringList&);


	void setHistory(const QStringList&,bool isReplace);
	bool isHistoryBackAvailable() const;
	bool isHistoryForwardAvailable() const;
	bool historyBack();
	bool historyForward();
	QPopupMenu *backHistoryPopupMenu() const;
	QPopupMenu *forwardHistoryPopupMenu() const;
	void setColumnConf(SlFileListColumnConf&);

	void sendFileUpdateMessage(const QString&);
	void updateView();
	void recreateIcon();
	void focusToNext();
	void focusToPrev();
	bool rename();
	bool newfolder();
	bool del();
	bool duplicate();
	bool cut();
	bool copy();
	bool paste();
	void setMimeFilter(const QString &);
	void clearTmpFolder();

	void setRecursive(bool,bool);
	bool recursive() const;
	void setFilter(SlFileSelectorFilter *);
	SlFileSelectorFilter *filter();
	bool isEnablePaste();

	static bool deleteFile(const QString&);
	static bool deleteDir(const QDir&);
	static bool copyDir(const QString &srcName,const QString &dstName,
						SlFileOverwirteMode m=Error);
	static bool moveDir(const QString&,const QString&,
						SlFileOverwirteMode m=Error);
	static QString getCopyDirName(const QString &);
	static bool makeDir(const QString &path);

	static uint size(const QString &fName);
	static uint fileFree(const QString &fName);



	enum DesktopMode {

		HideDesktop = 1,

		ShowAll,

		FileTab
	};
	void setDesktopMode(DesktopMode mode);
	void setEnabledSystemChannel(bool);
	void showUpDirBtn(bool);
	void showWritableFile(bool);


	void setEnableSD(bool);
	void setEnableCF(bool);
	bool getEnableSD();
	bool getEnableCF();




	void sendKeyPressEvent( QKeyEvent *e );

	void setScale(int scale);
	int scale() const;

	SlMisc::SlListColumnInfos columnWidthInfos();



	enum FocusMode {

		Auto = 1,

		ByTab,

		ByCommand
	};
	void setFocusMode(FocusMode mode);

	void adjustContentsSize();

	static void updateFile(const QString &filename);

	bool delFile(const QString &mymsg);

	bool isIncludedFile(const QString &filename);

signals:


	void selectionChanged(const QFileInfo &file,bool isDevice);


	void fileSelected(const QFileInfo &file);


	void dirOpened(const QDir &dir);


	void enabledPaste(bool);


	void columnWidthChanged(int column,int oldSize,int newSize);


	void itemRightPressed(const QFileInfo &file,const QPoint &pos);


	void selectionLost();


	//void keyPressed(QKeyEvent *e,bool &isAccepted);
/*
private slots:
	void fileClicked(QListViewItem *);
	void fileClicked(QIconViewItem *);
	void selectionChanged(QListViewItem *);
	void selectionChanged(QIconViewItem *);
	void dMenuChanged(int);
	void changeDirectory(int,bool isImmediate=TRUE);
	void hMenuSelected(int);
	void cardMessage( const QCString &, const QByteArray &);
	void systemMessage( const QCString &, const QByteArray &);
	void headerClicked(int);
	void asyncHMenuSelected();
	void asyncDMenuChanged();
	void rightPressed(QIconViewItem *,const QPoint&);
	void rightPressed(QListViewItem *,const QPoint&,int);
	void upDirClicked();
	void slotKeyPressed(QKeyEvent *e,bool &isAccepted);
*/
protected:
	void focusInEvent(QFocusEvent*);
	void show();
	void keyPressEvent( QKeyEvent *e );

private:
	void openDirInside(QDir&);
	void createMyPda();
	void init();
	SlFileSelectorPrivate *p;
	SlFileSelector(const SlFileSelector&);
	ulong focusWidgets() const;
	QWidget* nextFocus(QWidget *,bool) const;
	bool focusToTheWidget(QWidget *);
};

#endif