-rw-r--r-- | libopie/ofileselector.h | 308 |
1 files changed, 72 insertions, 236 deletions
diff --git a/libopie/ofileselector.h b/libopie/ofileselector.h index d06aa0a..bdb3e56 100644 --- a/libopie/ofileselector.h +++ b/libopie/ofileselector.h | |||
@@ -5,7 +5,7 @@ | |||
5 | 5 | ||
6 | 6 | ||
7 | =. This file is part of the OPIE Project | 7 | =. This file is part of the OPIE Project |
8 | .=l. Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> | 8 | .=l. Copyright (c) 2002,2003 Holger Freyther <zecke@handhelds.org> |
9 | .>+-= | 9 | .>+-= |
10 | _;:, .> :=|. This library is free software; you can | 10 | _;:, .> :=|. This library is free software; you can |
11 | .> <`_, > . <= redistribute it and/or modify it under | 11 | .> <`_, > . <= redistribute it and/or modify it under |
@@ -31,284 +31,120 @@ | |||
31 | 31 | ||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #ifndef opiefileselector_h | ||
35 | #define opiefileselector_h | ||
36 | 34 | ||
35 | #ifndef OPIE_OFILESELECTOR_FOO_H | ||
36 | #define OPIE_OFILESELECTOR_FOO_H | ||
37 | |||
38 | #include <qlist.h> | ||
37 | #include <qwidget.h> | 39 | #include <qwidget.h> |
38 | #include <qstring.h> | ||
39 | #include <qpixmap.h> | ||
40 | #include <qstringlist.h> | ||
41 | #include <qmap.h> | 40 | #include <qmap.h> |
42 | #include <qvaluelist.h> | 41 | #include <qvaluelist.h> |
42 | #include <qstringlist.h> | ||
43 | 43 | ||
44 | #include <qpe/applnk.h> | 44 | #include <qpe/applnk.h> |
45 | #include <qlistview.h> | ||
46 | 45 | ||
46 | typedef QMap<QString, QStringList> MimeTypes; | ||
47 | 47 | ||
48 | class DocLnk; | 48 | class OFileViewInterface; |
49 | class QCheckBox; | 49 | class OFileViewFileListView; |
50 | class QComboBox; | ||
51 | class QPushButton; | ||
52 | class FileSelector; | ||
53 | class QGridLayout; | ||
54 | class QLineEdit; | 50 | class QLineEdit; |
55 | class QLabel; | 51 | class QComboBox; |
56 | class QWidgetStack; | 52 | class QWidgetStack; |
57 | class QHBoxLayout; | ||
58 | class QVBoxLayout; | ||
59 | class QPopupMenu; | ||
60 | class QFileInfo; | ||
61 | class QHBox; | 53 | class QHBox; |
62 | // | ||
63 | |||
64 | typedef QMap< QString, QStringList> MimeTypes; | ||
65 | |||
66 | /** | ||
67 | * This is OPIEs FileDialog Widget. You can use it | ||
68 | * as a dropin replacement of the fileselector and | ||
69 | * or use any of the new features. | ||
70 | * This is also a complete FileSave and FileLoad widget | ||
71 | * If you look for a Dialog check OFileDialog | ||
72 | * | ||
73 | * NOTE THAT the API will change to be more extendable! | ||
74 | */ | ||
75 | class OFileSelector : public QWidget { | 54 | class OFileSelector : public QWidget { |
76 | Q_OBJECT | 55 | Q_OBJECT |
56 | friend class OFileViewInterface; | ||
57 | friend class OFileViewFileListView; | ||
77 | public: | 58 | public: |
78 | /** | 59 | enum Mode { Open=1, Save=2, FileSelector=4, OPEN=1, SAVE=2, FILESELECTOR=4 }; |
79 | * The mode of the file selector | 60 | // enum OldMode { OPEN=1, SAVE=2, FILESELECTOR = 4 }; |
80 | * Either open, save, fileselector or dir browsing mode | 61 | enum Selector { Normal = 0, Extended=1, ExtendedAll =2, Default=3, NORMAL=0,EXTENDED=1, EXTENDED_ALL =2, DEFAULT=3 }; |
81 | * | 62 | // enum OldSelector { NORMAL = 0, EXTENDED =1, EXTENDED_ALL = 2}; |
82 | */ | ||
83 | enum Mode {OPEN=1, SAVE=2, FILESELECTOR=4, DIR=8 }; | ||
84 | |||
85 | /** | ||
86 | * Selector. Either NORMAL for the one shipped with | ||
87 | * libqpe or EXTENDED. for the EXTENDED | ||
88 | * EXTENDED_ALL also shows 'hidden' files | ||
89 | */ | ||
90 | enum Selector{NORMAL=0, EXTENDED = 1, EXTENDED_ALL =2 }; | ||
91 | |||
92 | /** | ||
93 | * This is reserved for futrue views | ||
94 | */ | ||
95 | enum View { DIRS = 1, FILES = 2, TREE = 4, ICON = 8 }; | ||
96 | 63 | ||
97 | /** | 64 | OFileSelector(QWidget* parent, int mode, int selector, |
98 | * A c'tor which should be used for advanced mode | ||
99 | * @param wid the parent | ||
100 | * @param mode the Mode of the Selector | ||
101 | * @param selector the current View of the Selector | ||
102 | * @param dirName in which dir to start | ||
103 | * @param fileName a proposed filename | ||
104 | * @param mimetypes A list of mimetypes \ | ||
105 | * QString is for a identifier name like "Text files" | ||
106 | * the coresponding QStringList is used for the mimetypes | ||
107 | * if empty it'll fill the list of mimetypes depending | ||
108 | * on the content of the current directory | ||
109 | */ | ||
110 | |||
111 | OFileSelector(QWidget *wid, int mode, int selector, | ||
112 | const QString &dirName, | 65 | const QString &dirName, |
113 | const QString &fileName = QString::null, | 66 | const QString& fileName, |
114 | const MimeTypes &mimetypes = MimeTypes() ); | 67 | const MimeTypes& mimetypes = MimeTypes(), |
68 | bool newVisible = FALSE, bool closeVisible = FALSE ); | ||
115 | 69 | ||
116 | |||
117 | /** | ||
118 | * This is a QPE compatible c'tor | ||
119 | */ | ||
120 | OFileSelector(const QString &mimeFilter, QWidget *parent, | 70 | OFileSelector(const QString &mimeFilter, QWidget *parent, |
121 | const char *name, bool newVisible = TRUE, | 71 | const char* name = 0, bool newVisible = TRUE, bool closeVisible = FALSE ); |
122 | bool closeVisible = FALSE ); | ||
123 | |||
124 | ~OFileSelector(); | 72 | ~OFileSelector(); |
125 | 73 | ||
126 | // currently only for the FILESELECTOR Mode | ||
127 | /** | ||
128 | */ | ||
129 | void setNewVisible( bool /*b*/ ); | ||
130 | void setCloseVisible(bool /*b*/ ); | ||
131 | |||
132 | // end file selector mode | ||
133 | // deprecated | ||
134 | void reread(); | ||
135 | // make sure not to leak please | ||
136 | const DocLnk *selected(); | 74 | const DocLnk *selected(); |
137 | // end deprecated | ||
138 | |||
139 | bool isToolbarVisible() const { return m_shTool; }; | ||
140 | bool isPermissionBarVisible() const { return m_shPerm; }; | ||
141 | bool isLineEditVisible()const { return m_shLne; }; | ||
142 | bool isChooserVisible( )const { return m_shChooser; }; | ||
143 | bool isYesCancelVisible()const { return m_shYesNo; }; | ||
144 | void setYesCancelVisible( bool show ); | ||
145 | void setToolbarVisible( bool show ); | ||
146 | void setPermissionBarVisible( bool show ); | ||
147 | void setLineEditVisible(bool show) ; | ||
148 | void setChooserVisible( bool chooser ); | ||
149 | |||
150 | QCheckBox* permissionCheckbox(); | ||
151 | bool setPermission() const; | ||
152 | void setPermissionChecked( bool check ); | ||
153 | |||
154 | void setMode( int ); | ||
155 | |||
156 | bool showDirs()const { return m_dir; } | ||
157 | void setShowDirs(bool ); | ||
158 | |||
159 | const QListView* listView() { return m_View; }; | ||
160 | |||
161 | bool isCaseSensetive()const { return m_case; } | ||
162 | void setCaseSensetive(bool caSe ); | ||
163 | |||
164 | bool showFiles()const { return m_files; }; | ||
165 | void setShowFiles(bool ); | ||
166 | bool cd(const QString &path ); | ||
167 | |||
168 | |||
169 | int mode()const { return m_mode; }; | ||
170 | int selector()const { return m_selector; }; | ||
171 | void setSelector( int ); | ||
172 | |||
173 | bool showPopup()const { return m_showPopup; }; | ||
174 | void setShowPopup( bool pop ) { m_showPopup = pop; }; | ||
175 | void setPopupMenu( QPopupMenu * ); | ||
176 | |||
177 | // void updateLay(); | ||
178 | |||
179 | void reparse(); // re reads the dir | ||
180 | 75 | ||
181 | QString selectedName( )const; | 76 | QString selectedName( )const; |
182 | QStringList selectedNames()const; | ||
183 | |||
184 | QString selectedPath() const; | 77 | QString selectedPath() const; |
185 | QStringList selectedPaths() const; | ||
186 | |||
187 | QString directory()const; | 78 | QString directory()const; |
188 | int fileCount() const; | ||
189 | 79 | ||
190 | /* the user needs to delete it */ | ||
191 | DocLnk selectedDocument()const; | 80 | DocLnk selectedDocument()const; |
192 | /* the user needs to delete it */ | 81 | |
193 | QValueList<DocLnk> selectedDocuments()const; | 82 | int fileCount()const; |
83 | void reread(); | ||
84 | |||
85 | int mode()const; | ||
86 | int selector()const; | ||
87 | |||
88 | |||
89 | void setNewVisible( bool b ); | ||
90 | void setCloseVisible( bool b ); | ||
91 | void setNameVisible( bool b ); | ||
194 | 92 | ||
195 | signals: | 93 | signals: |
94 | void dirSelected( const QString& ); | ||
196 | void fileSelected( const DocLnk & ); | 95 | void fileSelected( const DocLnk & ); |
197 | void fileSelected( const QString & ); | 96 | void fileSelected( const QString & ); |
198 | void dirSelected(const QString &dir ); | 97 | void newSelected( const DocLnk& ); |
199 | void closeMe(); | 98 | void closeMe(); |
200 | void ok(); | 99 | void ok(); |
201 | void cancel(); | 100 | void cancel(); |
202 | void contextMenu(); | ||
203 | |||
204 | private slots: | ||
205 | void slotTest() { qWarning("slotTest" ); setLineEditVisible(false ); }; | ||
206 | void slotOk(); | ||
207 | void slotCancel(); | ||
208 | void slotViewCheck(const QString & ); | ||
209 | void slotMimeCheck(const QString & ); | ||
210 | void slotLocationActivated(const QString & ); | ||
211 | void slotInsertLocationPath(const QString &, int); | ||
212 | void locationComboChanged(); | ||
213 | 101 | ||
102 | /* used by the ViewInterface */ | ||
214 | private: | 103 | private: |
215 | void init(); | 104 | bool showNew()const; |
216 | void updateMimes(); | 105 | bool showClose()const; |
217 | 106 | MimeTypes mimeTypes()const; | |
218 | protected: | 107 | QStringList currentMimeType()const; |
219 | 108 | ||
220 | private: | 109 | private: |
221 | int m_mode, m_selector; | 110 | /* inits the Widgets */ |
222 | QComboBox *m_location, *m_mimeCheck, *m_viewCheck; | 111 | void initUI(); |
223 | QPushButton *m_homeButton, *m_docButton, *m_hideButton, *m_ok, *m_cancel; | 112 | /* inits the MimeType ComboBox content + connects signals and slots */ |
224 | QPushButton *m_reread, *m_up, *m_new, *m_close; | 113 | void initMime(); |
225 | QListView *m_View; | 114 | /* init the Views :) */ |
226 | QCheckBox *m_checkPerm; | 115 | void initViews(); |
227 | QWidget *m_pseudo; | ||
228 | QVBoxLayout *m_pseudoLayout; | ||
229 | |||
230 | QString m_currentDir; | ||
231 | QString m_name; | ||
232 | // QStringList m_mimetypes; | ||
233 | QMap<QString, QStringList> m_mimetypes; | ||
234 | |||
235 | FileSelector *m_select; | ||
236 | QWidgetStack *m_stack; | ||
237 | QVBoxLayout *m_lay; | ||
238 | QGridLayout *m_Oselector; | ||
239 | |||
240 | QHBox *m_boxToolbar; | ||
241 | QHBox *m_boxOk; // (no layout anymore) wait | ||
242 | QHBox *m_boxName; // (no Layout anymore) wait | ||
243 | QHBox *m_boxView; | ||
244 | |||
245 | QPopupMenu *m_custom; | ||
246 | 116 | ||
247 | QLineEdit *m_edit; | 117 | private: |
248 | QLabel *m_fnLabel; | 118 | QLineEdit* m_lneEdit; // the LineEdit for the Name |
119 | QComboBox *m_cmbView, *m_cmbMime; // two ComboBoxes to select the View and MimeType | ||
120 | QWidgetStack* m_stack; // our widget stack which will contain the views | ||
121 | OFileViewInterface* currentView()const; // returns the currentView | ||
122 | OFileViewInterface* m_current; // here is the view saved | ||
123 | bool m_shNew : 1; // should we show New? | ||
124 | bool m_shClose : 1; // should we show Close? | ||
125 | MimeTypes m_mimeType; // list of mimetypes | ||
126 | |||
127 | QMap<QString, OFileViewInterface*> m_views; // QString translated view name + ViewInterface Ptr | ||
128 | QHBox* m_nameBox; // the LineEdit + Label is hold here | ||
129 | QHBox* m_cmbBox; // this holds the two combo boxes | ||
130 | |||
131 | QString m_startDir; | ||
132 | int m_mode; | ||
133 | int m_selector; | ||
134 | |||
135 | struct Data; // used for future versions | ||
136 | Data *d; | ||
249 | 137 | ||
250 | bool m_shClose : 1; | 138 | private slots: |
251 | bool m_shNew : 1; | 139 | void slotMimeTypeChanged(); |
252 | bool m_shTool : 1; | ||
253 | bool m_shPerm : 1; | ||
254 | bool m_shLne : 1; | ||
255 | bool m_shChooser : 1; | ||
256 | bool m_shYesNo : 1; | ||
257 | bool m_boCheckPerm : 1; | ||
258 | bool m_autoMime : 1; | ||
259 | bool m_case : 1; | ||
260 | bool m_dir : 1; | ||
261 | bool m_files : 1; | ||
262 | bool m_showPopup : 1; | ||
263 | 140 | ||
264 | void initVars(); | 141 | /* will set the text of the lineedit and emit a fileChanged signal */ |
265 | virtual void addFile(const QString &mime, QFileInfo *info, bool symlink = FALSE ); | 142 | void slotDocLnkBridge( const DocLnk& ); |
266 | virtual void addDir( const QString &mime, QFileInfo *info , bool symlink = FALSE ); | 143 | void slotFileBridge( const QString& ); |
267 | virtual void addSymlink(const QString &, QFileInfo *, bool = FALSE ){}; | 144 | void slotViewChange( const QString& ); |
268 | void delItems(); | ||
269 | void initializeName(); | ||
270 | void initializeYes(); | ||
271 | void initializeChooser(); | ||
272 | void initializeListView(); | ||
273 | void initializePerm(); | ||
274 | void initPics(); | ||
275 | bool compliesMime(const QString &path, | ||
276 | const QString &mime); | ||
277 | bool compliesMime(const QString& mime ); | ||
278 | /** | ||
279 | * Updates the QComboBox with the current mimetypes | ||
280 | */ | ||
281 | void updateMimeCheck(); | ||
282 | 145 | ||
283 | /** | 146 | bool eventFilter (QObject *o, QEvent *e); |
284 | * Returns the current mimetype | ||
285 | */ | ||
286 | QString currentMimeType()const; | ||
287 | class OFileSelectorPrivate; | ||
288 | OFileSelectorPrivate *d; | ||
289 | static QMap<QString,QPixmap> *m_pixmaps; | ||
290 | 147 | ||
291 | private slots: | ||
292 | void slotFileSelected(const QString & ); // not really meant to be a slot | ||
293 | void slotFileBridgeSelected( const DocLnk & ); | ||
294 | virtual void slotSelectionChanged(); | ||
295 | virtual void slotCurrentChanged(QListViewItem* ); | ||
296 | virtual void slotClicked( int, QListViewItem *item, const QPoint &, int); | ||
297 | virtual void slotRightButton(int, QListViewItem *, const QPoint &, int ); | ||
298 | virtual void slotContextMenu( QListViewItem *item); | ||
299 | // listview above | ||
300 | // popup below | ||
301 | virtual void slotChangedDir(); | ||
302 | virtual void slotOpen(); | ||
303 | virtual void slotRescan(); | ||
304 | virtual void slotRename(); | ||
305 | virtual void slotDelete(); | ||
306 | virtual void cdUP(); | ||
307 | virtual void slotHome(); | ||
308 | virtual void slotDoc(); | ||
309 | virtual void slotNavigate( ); | ||
310 | }; | 148 | }; |
311 | 149 | ||
312 | |||
313 | #endif | 150 | #endif |
314 | |||