-rw-r--r-- | libopie/ofileselector.cc | 58 |
1 files changed, 55 insertions, 3 deletions
diff --git a/libopie/ofileselector.cc b/libopie/ofileselector.cc index 6c59f89..74b308e 100644 --- a/libopie/ofileselector.cc +++ b/libopie/ofileselector.cc | |||
@@ -1,1200 +1,1252 @@ | |||
1 | 1 | ||
2 | 2 | ||
3 | #include <qcheckbox.h> | 3 | #include <qcheckbox.h> |
4 | #include <qcombobox.h> | 4 | #include <qcombobox.h> |
5 | #include <qheader.h> | 5 | #include <qheader.h> |
6 | #include <qlabel.h> | 6 | #include <qlabel.h> |
7 | #include <qabstractlayout.h> | 7 | #include <qabstractlayout.h> |
8 | #include <qlayout.h> | 8 | #include <qlayout.h> |
9 | #include <qlineedit.h> | 9 | #include <qlineedit.h> |
10 | #include <qlistview.h> | 10 | #include <qlistview.h> |
11 | #include <qmessagebox.h> | 11 | #include <qmessagebox.h> |
12 | #include <qpainter.h> | 12 | #include <qpainter.h> |
13 | #include <qpushbutton.h> | 13 | #include <qpushbutton.h> |
14 | #include <qwidgetstack.h> | 14 | #include <qwidgetstack.h> |
15 | #include <qpopupmenu.h> | 15 | #include <qpopupmenu.h> |
16 | #include <qdir.h> | 16 | #include <qdir.h> |
17 | #include <qfile.h> | 17 | #include <qfile.h> |
18 | #include <qfileinfo.h> | 18 | #include <qfileinfo.h> |
19 | #include <qtimer.h> | 19 | #include <qtimer.h> |
20 | 20 | ||
21 | #include <qpe/qpeapplication.h> | 21 | #include <qpe/qpeapplication.h> |
22 | #include <qpe/applnk.h> | 22 | #include <qpe/applnk.h> |
23 | #include <qpe/fileselector.h> | 23 | #include <qpe/fileselector.h> |
24 | #include <qpe/global.h> | 24 | #include <qpe/global.h> |
25 | #include <qpe/mimetype.h> | 25 | #include <qpe/mimetype.h> |
26 | #include <qpe/resource.h> | 26 | #include <qpe/resource.h> |
27 | #include <qpe/storage.h> | 27 | #include <qpe/storage.h> |
28 | 28 | ||
29 | #include <unistd.h> | 29 | #include <unistd.h> |
30 | #include <stdlib.h> | 30 | #include <stdlib.h> |
31 | #include <sys/stat.h> | 31 | #include <sys/stat.h> |
32 | 32 | ||
33 | #include "ofileselector.h" | 33 | #include "ofileselector.h" |
34 | 34 | ||
35 | 35 | ||
36 | QMap<QString,QPixmap> *OFileSelector::m_pixmaps = 0; | 36 | QMap<QString,QPixmap> *OFileSelector::m_pixmaps = 0; |
37 | 37 | ||
38 | namespace { | 38 | namespace { |
39 | int indexByString( const QComboBox *box, const QString &str ){ | 39 | int indexByString( const QComboBox *box, const QString &str ){ |
40 | int index= 0; | 40 | int index= 0; |
41 | for(int i= 0; i < box->count(); i++ ){ | 41 | for(int i= 0; i < box->count(); i++ ){ |
42 | if( str == box->text(i ) ){ | 42 | if( str == box->text(i ) ){ |
43 | index= i; | 43 | index= i; |
44 | break; | 44 | break; |
45 | } | 45 | } |
46 | } | 46 | } |
47 | return index; | 47 | return index; |
48 | } | 48 | } |
49 | class OFileSelectorItem : public QListViewItem { | 49 | class OFileSelectorItem : public QListViewItem { |
50 | public: | 50 | public: |
51 | OFileSelectorItem(QListView *view, const QPixmap &pixmap, const QString &path, | 51 | OFileSelectorItem(QListView *view, const QPixmap &pixmap, const QString &path, |
52 | const QString &date, const QString &size, const QString &mDir, | 52 | const QString &date, const QString &size, const QString &mDir, |
53 | bool isLocked=false, bool isDir=false ): QListViewItem(view) { | 53 | bool isLocked=false, bool isDir=false ): QListViewItem(view) { |
54 | setPixmap(0, pixmap ); | 54 | setPixmap(0, pixmap ); |
55 | setText(1, path ); | 55 | setText(1, path ); |
56 | setText(2, size ); | 56 | setText(2, size ); |
57 | setText(3, date ); | 57 | setText(3, date ); |
58 | //setText(4, mDir ); | 58 | //setText(4, mDir ); |
59 | m_dir = mDir; | 59 | m_dir = mDir; |
60 | dir = isDir; | 60 | dir = isDir; |
61 | mLocked = isLocked; | 61 | mLocked = isLocked; |
62 | } | 62 | } |
63 | bool isLocked() const{ | 63 | bool isLocked() const{ |
64 | return mLocked; | 64 | return mLocked; |
65 | } | 65 | } |
66 | QString directory()const{ | 66 | QString directory()const{ |
67 | return m_dir; | 67 | return m_dir; |
68 | } | 68 | } |
69 | bool isDir()const{ | 69 | bool isDir()const{ |
70 | return dir; | 70 | return dir; |
71 | } | 71 | } |
72 | QString path()const{ | 72 | QString path()const{ |
73 | return text(1 ); | 73 | return text(1 ); |
74 | } | 74 | } |
75 | QString key(int id, bool )const { | 75 | QString key(int id, bool )const { |
76 | QString ke; | 76 | QString ke; |
77 | if( id == 0 || id == 1 ){ // name | 77 | if( id == 0 || id == 1 ){ // name |
78 | if( dir ){ | 78 | if( dir ){ |
79 | ke.append("0" ); | 79 | ke.append("0" ); |
80 | ke.append( text(1) ); | 80 | ke.append( text(1) ); |
81 | }else{ | 81 | }else{ |
82 | ke.append("1" ); | 82 | ke.append("1" ); |
83 | ke.append( text(1) ); | 83 | ke.append( text(1) ); |
84 | } | 84 | } |
85 | }else if( id == 2 ){ // size | 85 | }else if( id == 2 ){ // size |
86 | return text(2); | 86 | return text(2); |
87 | }else if( id == 3 ){ // date | 87 | }else if( id == 3 ){ // date |
88 | return text(3); | 88 | return text(3); |
89 | } | 89 | } |
90 | return ke; | 90 | return ke; |
91 | }; | 91 | }; |
92 | private: | 92 | private: |
93 | bool mLocked:1; | 93 | bool mLocked:1; |
94 | bool dir:1; | 94 | bool dir:1; |
95 | QString m_dir; | 95 | QString m_dir; |
96 | }; | 96 | }; |
97 | }; | 97 | }; |
98 | 98 | ||
99 | 99 | ||
100 | OFileSelector::OFileSelector( QWidget *wid, int mode, int selector, | 100 | OFileSelector::OFileSelector( QWidget *wid, int mode, int selector, |
101 | const QString &dirName, | 101 | const QString &dirName, |
102 | const QString &fileName, | 102 | const QString &fileName, |
103 | const QMap<QString,QStringList>& mimeTypes) | 103 | const QMap<QString,QStringList>& mimeTypes) |
104 | : QWidget( wid, "OFileSelector") | 104 | : QWidget( wid, "OFileSelector") |
105 | { | 105 | { |
106 | m_mimetypes = mimeTypes; | 106 | m_mimetypes = mimeTypes; |
107 | if (mode == SAVE ) | 107 | if (mode == SAVE ) |
108 | m_name = fileName; | 108 | m_name = fileName; |
109 | initVars(); | 109 | initVars(); |
110 | m_mode = mode; | 110 | m_mode = mode; |
111 | m_selector = selector; | 111 | m_selector = selector; |
112 | m_currentDir = dirName; | 112 | m_currentDir = dirName; |
113 | init(); | 113 | init(); |
114 | //QTimer::singleShot(6*1000, this, SLOT( slotTest() ) ); | 114 | //QTimer::singleShot(6*1000, this, SLOT( slotTest() ) ); |
115 | } | 115 | } |
116 | 116 | ||
117 | OFileSelector::OFileSelector(const QString &mimeFilter, QWidget *parent, | 117 | OFileSelector::OFileSelector(const QString &mimeFilter, QWidget *parent, |
118 | const char *name, bool newVisible, | 118 | const char *name, bool newVisible, |
119 | bool closeVisible ) | 119 | bool closeVisible ) |
120 | : QWidget( parent, name ) | 120 | : QWidget( parent, name ) |
121 | { | 121 | { |
122 | if (!mimeFilter.isEmpty() ) { | 122 | if (!mimeFilter.isEmpty() ) { |
123 | QStringList list = QStringList::split(";", mimeFilter ); | 123 | QStringList list = QStringList::split(";", mimeFilter ); |
124 | m_mimetypes.insert(mimeFilter, list ); | 124 | m_mimetypes.insert(mimeFilter, list ); |
125 | } | 125 | } |
126 | initVars(); | 126 | initVars(); |
127 | m_currentDir = QPEApplication::documentDir(); | 127 | m_currentDir = QPEApplication::documentDir(); |
128 | m_mode = OPEN; | 128 | m_mode = OPEN; |
129 | m_selector = NORMAL; | 129 | m_selector = NORMAL; |
130 | m_shClose = closeVisible; | 130 | m_shClose = closeVisible; |
131 | m_shNew = newVisible; | 131 | m_shNew = newVisible; |
132 | m_shLne = false; | 132 | m_shLne = false; |
133 | m_shPerm = false; | 133 | m_shPerm = false; |
134 | m_shYesNo = false; | 134 | m_shYesNo = false; |
135 | init(); | 135 | init(); |
136 | 136 | ||
137 | 137 | ||
138 | } | 138 | } |
139 | 139 | ||
140 | OFileSelector::~OFileSelector() | 140 | OFileSelector::~OFileSelector() |
141 | { | 141 | { |
142 | 142 | ||
143 | 143 | ||
144 | } | 144 | } |
145 | 145 | ||
146 | void OFileSelector::setNewVisible( bool visible ) | 146 | void OFileSelector::setNewVisible( bool visible ) |
147 | { | 147 | { |
148 | m_shNew = visible; | 148 | m_shNew = visible; |
149 | if( m_selector == NORMAL ){ | 149 | if( m_selector == NORMAL ){ |
150 | delete m_select; | 150 | delete m_select; |
151 | // we need to initialize but keep the selected mimetype | 151 | // we need to initialize but keep the selected mimetype |
152 | QString mime = currentMimeType(); | 152 | QString mime = currentMimeType(); |
153 | m_select = new FileSelector( mime , | 153 | m_select = new FileSelector( mime , |
154 | m_stack, "fileselector", | 154 | m_stack, "fileselector", |
155 | m_shNew, m_shClose); | 155 | m_shNew, m_shClose); |
156 | connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ), | 156 | connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ), |
157 | this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) ); | 157 | this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) ); |
158 | //connect to close me and other signals as well | 158 | //connect to close me and other signals as well |
159 | m_stack->addWidget( m_select, NORMAL ); | 159 | m_stack->addWidget( m_select, NORMAL ); |
160 | }else{ | 160 | }else{ |
161 | m_new->show(); | 161 | m_new->show(); |
162 | } | 162 | } |
163 | } | 163 | } |
164 | void OFileSelector::setCloseVisible( bool visible ) | 164 | void OFileSelector::setCloseVisible( bool visible ) |
165 | { | 165 | { |
166 | m_shClose = visible; | 166 | m_shClose = visible; |
167 | if( m_selector == NORMAL ){ | 167 | if( m_selector == NORMAL ){ |
168 | setNewVisible( m_shNew ); // yeah baby | 168 | setNewVisible( m_shNew ); // yeah baby |
169 | }else{ | 169 | }else{ |
170 | m_close->show(); | 170 | m_close->show(); |
171 | } | 171 | } |
172 | } | 172 | } |
173 | void OFileSelector::reread() | 173 | void OFileSelector::reread() |
174 | { | 174 | { |
175 | if( m_selector == NORMAL ){ | 175 | if( m_selector == NORMAL ){ |
176 | setNewVisible( m_shNew ); // make it a initializeSelector | 176 | setNewVisible( m_shNew ); // make it a initializeSelector |
177 | }else if ( m_selector == EXTENDED || m_selector == EXTENDED_ALL ){ | 177 | }else if ( m_selector == EXTENDED || m_selector == EXTENDED_ALL ){ |
178 | reparse(); | 178 | reparse(); |
179 | //}else{ | 179 | //}else{ |
180 | //; | 180 | //; |
181 | } | 181 | } |
182 | } | 182 | } |
183 | 183 | ||
184 | const DocLnk *OFileSelector::selected() | 184 | const DocLnk *OFileSelector::selected() |
185 | { | 185 | { |
186 | if( m_selector == NORMAL ){ | 186 | if( m_selector == NORMAL ){ |
187 | return m_select->selected(); | 187 | return m_select->selected(); |
188 | }else{ | 188 | }else{ |
189 | DocLnk *lnk = new DocLnk(selectedDocument() ); | 189 | DocLnk *lnk = new DocLnk(selectedDocument() ); |
190 | return lnk; | 190 | return lnk; |
191 | } | 191 | } |
192 | } | 192 | } |
193 | 193 | ||
194 | void OFileSelector::setYesCancelVisible( bool show ) | 194 | void OFileSelector::setYesCancelVisible( bool show ) |
195 | { | 195 | { |
196 | initializeYes(); // FIXME if YesCancel is not shown we will initialize it to hide it :( | 196 | initializeYes(); // FIXME if YesCancel is not shown we will initialize it to hide it :( |
197 | m_shYesNo = show; | 197 | m_shYesNo = show; |
198 | if( m_shYesNo ) | 198 | if( m_shYesNo ) |
199 | m_boxOk->show(); | 199 | m_boxOk->show(); |
200 | else | 200 | else |
201 | m_boxOk->hide(); | 201 | m_boxOk->hide(); |
202 | 202 | ||
203 | } | 203 | } |
204 | void OFileSelector::setToolbarVisible( bool show ) | 204 | void OFileSelector::setToolbarVisible( bool show ) |
205 | { | 205 | { |
206 | m_shTool = show; | 206 | m_shTool = show; |
207 | initializeListView(); // FIXME see above waste of memory | 207 | initializeListView(); // FIXME see above waste of memory |
208 | if(!m_shTool ){ | 208 | if(!m_shTool ){ |
209 | m_location->hide(); | 209 | m_location->hide(); |
210 | m_up->hide(); | 210 | m_up->hide(); |
211 | m_homeButton->hide(); | 211 | m_homeButton->hide(); |
212 | m_docButton->hide(); | 212 | m_docButton->hide(); |
213 | }else{ | 213 | }else{ |
214 | m_location->show(); | 214 | m_location->show(); |
215 | m_up->show(); | 215 | m_up->show(); |
216 | m_homeButton->show(); | 216 | m_homeButton->show(); |
217 | m_docButton->show(); | 217 | m_docButton->show(); |
218 | } | 218 | } |
219 | } | 219 | } |
220 | void OFileSelector::setPermissionBarVisible( bool show ) | 220 | void OFileSelector::setPermissionBarVisible( bool show ) |
221 | { | 221 | { |
222 | m_shPerm = show; | 222 | m_shPerm = show; |
223 | initializePerm(); | 223 | initializePerm(); |
224 | if( m_shPerm ) | 224 | if( m_shPerm ) |
225 | m_checkPerm->show(); | 225 | m_checkPerm->show(); |
226 | else | 226 | else |
227 | m_checkPerm->hide(); | 227 | m_checkPerm->hide(); |
228 | } | 228 | } |
229 | void OFileSelector::setLineEditVisible( bool show ) | 229 | void OFileSelector::setLineEditVisible( bool show ) |
230 | { | 230 | { |
231 | if( show ){ | 231 | if( show ){ |
232 | initializeName(); | 232 | initializeName(); |
233 | m_boxName->show(); | 233 | m_boxName->show(); |
234 | }else{ | 234 | }else{ |
235 | if( m_shLne && m_boxName != 0 ){ // check if we showed before this is the way to go | 235 | if( m_shLne && m_boxName != 0 ){ // check if we showed before this is the way to go |
236 | m_boxName->hide(); | 236 | m_boxName->hide(); |
237 | } | 237 | } |
238 | } | 238 | } |
239 | m_shLne = show; | 239 | m_shLne = show; |
240 | } | 240 | } |
241 | 241 | ||
242 | void OFileSelector::setChooserVisible( bool show ) | 242 | void OFileSelector::setChooserVisible( bool show ) |
243 | { | 243 | { |
244 | m_shChooser = show; | 244 | m_shChooser = show; |
245 | initializeChooser(); | 245 | initializeChooser(); |
246 | if( m_shChooser ){ | 246 | if( m_shChooser ){ |
247 | m_boxView->hide(); | 247 | m_boxView->hide(); |
248 | }else{ | 248 | }else{ |
249 | m_boxView->show(); | 249 | m_boxView->show(); |
250 | } | 250 | } |
251 | } | 251 | } |
252 | 252 | ||
253 | QCheckBox* OFileSelector::permissionCheckbox() | 253 | QCheckBox* OFileSelector::permissionCheckbox() |
254 | { | 254 | { |
255 | if( m_selector == NORMAL ) | 255 | if( m_selector == NORMAL ) |
256 | return 0l; | 256 | return 0l; |
257 | else | 257 | else |
258 | return m_checkPerm; | 258 | return m_checkPerm; |
259 | } | 259 | } |
260 | bool OFileSelector::setPermission()const | 260 | bool OFileSelector::setPermission()const |
261 | { | 261 | { |
262 | return m_checkPerm == 0 ? false : m_checkPerm->isChecked(); | 262 | return m_checkPerm == 0 ? false : m_checkPerm->isChecked(); |
263 | } | 263 | } |
264 | void OFileSelector::setPermissionChecked( bool check ) | 264 | void OFileSelector::setPermissionChecked( bool check ) |
265 | { | 265 | { |
266 | if( m_checkPerm ) | 266 | if( m_checkPerm ) |
267 | m_checkPerm->setChecked( check ); | 267 | m_checkPerm->setChecked( check ); |
268 | } | 268 | } |
269 | 269 | ||
270 | void OFileSelector::setMode(int mode) // FIXME do direct raising | 270 | void OFileSelector::setMode(int mode) // FIXME do direct raising |
271 | { | 271 | { |
272 | m_mode = mode; | 272 | m_mode = mode; |
273 | if( m_selector == NORMAL ) | 273 | if( m_selector == NORMAL ) |
274 | return; | 274 | return; |
275 | } | 275 | } |
276 | void OFileSelector::setShowDirs(bool ) | 276 | void OFileSelector::setShowDirs(bool ) |
277 | { | 277 | { |
278 | m_dir = true; | 278 | m_dir = true; |
279 | reparse(); | 279 | reparse(); |
280 | } | 280 | } |
281 | void OFileSelector::setCaseSensetive(bool caSe ) | 281 | void OFileSelector::setCaseSensetive(bool caSe ) |
282 | { | 282 | { |
283 | m_case = caSe; | 283 | m_case = caSe; |
284 | reparse(); | 284 | reparse(); |
285 | } | 285 | } |
286 | void OFileSelector::setShowFiles(bool show ) | 286 | void OFileSelector::setShowFiles(bool show ) |
287 | { | 287 | { |
288 | m_files = show; | 288 | m_files = show; |
289 | reparse(); | 289 | reparse(); |
290 | } | 290 | } |
291 | /// | 291 | /// |
292 | bool OFileSelector::cd(const QString &path ) | 292 | bool OFileSelector::cd(const QString &path ) |
293 | { | 293 | { |
294 | m_currentDir = path; | 294 | m_currentDir = path; |
295 | reparse(); | 295 | reparse(); |
296 | return true; | 296 | return true; |
297 | } | 297 | } |
298 | void OFileSelector::setSelector(int mode ) | 298 | void OFileSelector::setSelector(int mode ) |
299 | { | 299 | { |
300 | QString text; | 300 | QString text; |
301 | switch( mode ){ | 301 | switch( mode ){ |
302 | case NORMAL: | 302 | case NORMAL: |
303 | text = tr("Documents"); | 303 | text = tr("Documents"); |
304 | break; | 304 | break; |
305 | case EXTENDED: | 305 | case EXTENDED: |
306 | text = tr("Files"); | 306 | text = tr("Files"); |
307 | break; | 307 | break; |
308 | case EXTENDED_ALL: | 308 | case EXTENDED_ALL: |
309 | text = tr("All Files"); | 309 | text = tr("All Files"); |
310 | break; | 310 | break; |
311 | } | 311 | } |
312 | slotViewCheck( text ); | 312 | slotViewCheck( text ); |
313 | } | 313 | } |
314 | 314 | ||
315 | void OFileSelector::setPopupMenu(QPopupMenu *popup ) | 315 | void OFileSelector::setPopupMenu(QPopupMenu *popup ) |
316 | { | 316 | { |
317 | m_custom = popup; | 317 | m_custom = popup; |
318 | m_showPopup = true; | 318 | m_showPopup = true; |
319 | } | 319 | } |
320 | 320 | ||
321 | //void OFileSelector::updateL | 321 | //void OFileSelector::updateL |
322 | 322 | ||
323 | QString OFileSelector::selectedName() const | 323 | QString OFileSelector::selectedName() const |
324 | { | 324 | { |
325 | QString name; | 325 | QString name; |
326 | if( m_selector == NORMAL ){ | 326 | if( m_selector == NORMAL ){ |
327 | const DocLnk *lnk = m_select->selected(); | 327 | const DocLnk *lnk = m_select->selected(); |
328 | name = lnk->file(); | 328 | name = lnk->file(); |
329 | delete lnk; | 329 | delete lnk; |
330 | }else if( m_selector == EXTENDED || m_selector == EXTENDED_ALL ){ | 330 | }else if( m_selector == EXTENDED || m_selector == EXTENDED_ALL ){ |
331 | QListViewItem *item = m_View->currentItem(); | 331 | QListViewItem *item = m_View->currentItem(); |
332 | if( item != 0 ) | 332 | if( item != 0 ) |
333 | name = m_currentDir + "/" + item->text( 1 ); | 333 | name = m_currentDir + "/" + item->text( 1 ); |
334 | }else { // installed view | 334 | }else { // installed view |
335 | ; | 335 | ; |
336 | } | 336 | } |
337 | return name; | 337 | return name; |
338 | } | 338 | } |
339 | QStringList OFileSelector::selectedNames()const | 339 | QStringList OFileSelector::selectedNames()const |
340 | { | 340 | { |
341 | QStringList list; | 341 | QStringList list; |
342 | if( m_selector == NORMAL ){ | 342 | if( m_selector == NORMAL ){ |
343 | list << selectedName(); | 343 | list << selectedName(); |
344 | }else if ( m_selector == EXTENDED || m_selector == EXTENDED_ALL ) { | 344 | }else if ( m_selector == EXTENDED || m_selector == EXTENDED_ALL ) { |
345 | list << selectedName(); // FIXME implement multiple Selections | 345 | list << selectedName(); // FIXME implement multiple Selections |
346 | } | 346 | } |
347 | return list; | 347 | return list; |
348 | } | 348 | } |
349 | /** If mode is set to the Dir selection this will return the selected path. | 349 | /** If mode is set to the Dir selection this will return the selected path. |
350 | * | 350 | * |
351 | * | 351 | * |
352 | */ | 352 | */ |
353 | QString OFileSelector::selectedPath()const | 353 | QString OFileSelector::selectedPath()const |
354 | { | 354 | { |
355 | QString path; | 355 | QString path; |
356 | if( m_selector == NORMAL ){ | 356 | if( m_selector == NORMAL ){ |
357 | path = QPEApplication::documentDir(); | 357 | path = QPEApplication::documentDir(); |
358 | }else if( m_selector == EXTENDED || m_selector == EXTENDED_ALL ){ | 358 | }else if( m_selector == EXTENDED || m_selector == EXTENDED_ALL ){ |
359 | ; | 359 | ; |
360 | } | 360 | } |
361 | return path; | 361 | return path; |
362 | } | 362 | } |
363 | QStringList OFileSelector::selectedPaths() const | 363 | QStringList OFileSelector::selectedPaths() const |
364 | { | 364 | { |
365 | QStringList list; | 365 | QStringList list; |
366 | list << selectedPath(); | 366 | list << selectedPath(); |
367 | return list; | 367 | return list; |
368 | } | 368 | } |
369 | QString OFileSelector::directory()const | 369 | QString OFileSelector::directory()const |
370 | { | 370 | { |
371 | if( m_selector == NORMAL ) | 371 | if( m_selector == NORMAL ) |
372 | return QPEApplication::documentDir(); | 372 | return QPEApplication::documentDir(); |
373 | 373 | ||
374 | return QDir(m_currentDir).absPath(); | 374 | return QDir(m_currentDir).absPath(); |
375 | } | 375 | } |
376 | 376 | ||
377 | int OFileSelector::fileCount() | 377 | int OFileSelector::fileCount() |
378 | { | 378 | { |
379 | int count; | 379 | int count; |
380 | switch( m_selector ){ | 380 | switch( m_selector ){ |
381 | case NORMAL: | 381 | case NORMAL: |
382 | count = m_select->fileCount(); | 382 | count = m_select->fileCount(); |
383 | break; | 383 | break; |
384 | //case CUSTOM: | 384 | //case CUSTOM: |
385 | case EXTENDED: | 385 | case EXTENDED: |
386 | case EXTENDED_ALL: | 386 | case EXTENDED_ALL: |
387 | default: | 387 | default: |
388 | count = m_View->childCount(); | 388 | count = m_View->childCount(); |
389 | break; | 389 | break; |
390 | } | 390 | } |
391 | return count; | 391 | return count; |
392 | } | 392 | } |
393 | DocLnk OFileSelector::selectedDocument() const | 393 | DocLnk OFileSelector::selectedDocument() const |
394 | { | 394 | { |
395 | DocLnk lnk; | 395 | DocLnk lnk; |
396 | switch( m_selector ){ | 396 | switch( m_selector ){ |
397 | case NORMAL:{ | 397 | case NORMAL:{ |
398 | const DocLnk *lnk2 = m_select->selected(); | 398 | const DocLnk *lnk2 = m_select->selected(); |
399 | lnk = DocLnk(*lnk2 ); // copy | 399 | lnk = DocLnk(*lnk2 ); // copy |
400 | delete lnk2; | 400 | delete lnk2; |
401 | break; | 401 | break; |
402 | } | 402 | } |
403 | case EXTENDED: | 403 | case EXTENDED: |
404 | case EXTENDED_ALL: | 404 | case EXTENDED_ALL: |
405 | default: | 405 | default: |
406 | lnk = DocLnk( selectedName() ); // new DocLnk | 406 | lnk = DocLnk( selectedName() ); // new DocLnk |
407 | break; | 407 | break; |
408 | } | 408 | } |
409 | return lnk; | 409 | return lnk; |
410 | } | 410 | } |
411 | QValueList<DocLnk> OFileSelector::selectedDocuments() const | 411 | QValueList<DocLnk> OFileSelector::selectedDocuments() const |
412 | { | 412 | { |
413 | QValueList<DocLnk> docs; | 413 | QValueList<DocLnk> docs; |
414 | docs.append( selectedDocument() ); | 414 | docs.append( selectedDocument() ); |
415 | return docs; | 415 | return docs; |
416 | } | 416 | } |
417 | 417 | ||
418 | 418 | ||
419 | // slots internal | 419 | // slots internal |
420 | 420 | ||
421 | void OFileSelector::slotOk() | 421 | void OFileSelector::slotOk() |
422 | { | 422 | { |
423 | emit ok(); | 423 | emit ok(); |
424 | } | 424 | } |
425 | void OFileSelector::slotCancel() | 425 | void OFileSelector::slotCancel() |
426 | { | 426 | { |
427 | emit cancel(); | 427 | emit cancel(); |
428 | } | 428 | } |
429 | void OFileSelector::slotViewCheck(const QString &sel) | 429 | void OFileSelector::slotViewCheck(const QString &sel) |
430 | { | 430 | { |
431 | if( sel == tr("Documents" ) ){ | 431 | if( sel == tr("Documents" ) ){ |
432 | if( m_select == 0 ){ | 432 | if( m_select == 0 ){ |
433 | // autMime? fix cause now we use All and not the current | 433 | // autMime? fix cause now we use All and not the current |
434 | // yes currentMime fixes that for us | 434 | // yes currentMime fixes that for us |
435 | QString mime = currentMimeType(); | 435 | QString mime = currentMimeType(); |
436 | m_select = new FileSelector(mime, | 436 | m_select = new FileSelector(mime, |
437 | m_stack, "fileselector", | 437 | m_stack, "fileselector", |
438 | FALSE, FALSE); | 438 | FALSE, FALSE); |
439 | connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ), | 439 | connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ), |
440 | this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) ); | 440 | this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) ); |
441 | //connect to close me and other signals as well | 441 | //connect to close me and other signals as well |
442 | 442 | ||
443 | m_stack->addWidget( m_select, NORMAL ); | 443 | m_stack->addWidget( m_select, NORMAL ); |
444 | } | 444 | } |
445 | m_stack->raiseWidget( NORMAL ); | 445 | m_stack->raiseWidget( NORMAL ); |
446 | m_selector = NORMAL; | 446 | m_selector = NORMAL; |
447 | }else if( sel == tr("Files") ){ | 447 | }else if( sel == tr("Files") ){ |
448 | m_selector = EXTENDED; | 448 | m_selector = EXTENDED; |
449 | initializeListView(); | 449 | initializeListView(); |
450 | reparse(); | 450 | reparse(); |
451 | m_stack->raiseWidget( EXTENDED ); | 451 | m_stack->raiseWidget( EXTENDED ); |
452 | }else if( sel == tr("All Files") ){ | 452 | }else if( sel == tr("All Files") ){ |
453 | m_selector = EXTENDED_ALL; | 453 | m_selector = EXTENDED_ALL; |
454 | initializeListView(); | 454 | initializeListView(); |
455 | reparse(); | 455 | reparse(); |
456 | m_stack->raiseWidget( EXTENDED ); // same widget other QFileFilter | 456 | m_stack->raiseWidget( EXTENDED ); // same widget other QFileFilter |
457 | } | 457 | } |
458 | } | 458 | } |
459 | // not yet finished..... | 459 | // not yet finished..... |
460 | QString OFileSelector::currentMimeType() const{ | 460 | QString OFileSelector::currentMimeType() const{ |
461 | QString mime; | 461 | QString mime; |
462 | QString currentText; | 462 | QString currentText; |
463 | if (m_shChooser ) | 463 | if (m_shChooser ) |
464 | currentText = m_mimeCheck->currentText(); | 464 | currentText = m_mimeCheck->currentText(); |
465 | 465 | ||
466 | if (tr("All") == currentText ) return QString::null; | 466 | if (tr("All") == currentText ) return QString::null; |
467 | else if (currentText.isEmpty() ) { | 467 | else if (currentText.isEmpty() ) { |
468 | ; | 468 | ; |
469 | }else { | 469 | }else { |
470 | QMap<QString, QStringList>::ConstIterator it; | 470 | QMap<QString, QStringList>::ConstIterator it; |
471 | it = m_mimetypes.find( currentText ); | 471 | it = m_mimetypes.find( currentText ); |
472 | if ( it == m_mimetypes.end() ) { | 472 | if ( it == m_mimetypes.end() ) { |
473 | mime = it.data().join(";"); | 473 | mime = it.data().join(";"); |
474 | }else{ | 474 | }else{ |
475 | mime = currentText; | 475 | mime = currentText; |
476 | } | 476 | } |
477 | } | 477 | } |
478 | return mime; | 478 | return mime; |
479 | } | 479 | } |
480 | void OFileSelector::slotMimeCheck(const QString &mime) | 480 | void OFileSelector::slotMimeCheck(const QString &mime) |
481 | { | 481 | { |
482 | if( m_selector == NORMAL ){ | 482 | if( m_selector == NORMAL ){ |
483 | //if( m_autoMime ){ | 483 | //if( m_autoMime ){ |
484 | QString newMimeType; | 484 | QString newMimeType; |
485 | if (mime != tr("All") ) { | 485 | if (mime != tr("All") ) { |
486 | QMap<QString, QStringList>::Iterator it; | 486 | QMap<QString, QStringList>::Iterator it; |
487 | it = m_mimetypes.find(mime); | 487 | it = m_mimetypes.find(mime); |
488 | if ( it != m_mimetypes.end() ) { | 488 | if ( it != m_mimetypes.end() ) { |
489 | newMimeType = it.data().join(";"); | 489 | newMimeType = it.data().join(";"); |
490 | }else{ | 490 | }else{ |
491 | newMimeType = mime; | 491 | newMimeType = mime; |
492 | } | 492 | } |
493 | } | 493 | } |
494 | delete m_select; | 494 | delete m_select; |
495 | m_select = new FileSelector( newMimeType, | 495 | m_select = new FileSelector( newMimeType, |
496 | m_stack, "fileselector", | 496 | m_stack, "fileselector", |
497 | FALSE, FALSE); | 497 | FALSE, FALSE); |
498 | 498 | ||
499 | connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ), | 499 | connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ), |
500 | this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) ); | 500 | this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) ); |
501 | //connect to close me and other signals as well | 501 | //connect to close me and other signals as well |
502 | m_stack->addWidget( m_select, NORMAL ); | 502 | m_stack->addWidget( m_select, NORMAL ); |
503 | m_stack->raiseWidget( NORMAL ); | 503 | m_stack->raiseWidget( NORMAL ); |
504 | updateMimes(); | 504 | updateMimes(); |
505 | updateMimeCheck(); | 505 | updateMimeCheck(); |
506 | m_mimeCheck->setCurrentItem(indexByString( m_mimeCheck, mime) ); | 506 | m_mimeCheck->setCurrentItem(indexByString( m_mimeCheck, mime) ); |
507 | //} | 507 | //} |
508 | }else{ // others | 508 | }else{ // others |
509 | qWarning("Mime %s", mime.latin1() ); | 509 | qWarning("Mime %s", mime.latin1() ); |
510 | if(m_shChooser ){ | 510 | if(m_shChooser ){ |
511 | qWarning("Current Text %s", m_mimeCheck->currentText().latin1() ); | 511 | qWarning("Current Text %s", m_mimeCheck->currentText().latin1() ); |
512 | //m_mimeCheck->setCurrentItem(indexByString( m_mimeCheck, mime) ); | 512 | //m_mimeCheck->setCurrentItem(indexByString( m_mimeCheck, mime) ); |
513 | } | 513 | } |
514 | reparse(); | 514 | reparse(); |
515 | } | 515 | } |
516 | 516 | ||
517 | } | 517 | } |
518 | void OFileSelector::slotLocationActivated(const QString &file) | 518 | void OFileSelector::slotLocationActivated(const QString &file) |
519 | { | 519 | { |
520 | cd(file.left(file.find("<-",0,TRUE))); | 520 | cd(file.left(file.find("<-",0,TRUE))); |
521 | reparse(); | 521 | reparse(); |
522 | } | 522 | } |
523 | void OFileSelector::slotInsertLocationPath(const QString ¤tPath, int count) | 523 | void OFileSelector::slotInsertLocationPath(const QString ¤tPath, int count) |
524 | { | 524 | { |
525 | QStringList pathList; | 525 | QStringList pathList; |
526 | bool underDog = FALSE; | 526 | bool underDog = FALSE; |
527 | for(int i=0;i<count;i++) { | 527 | for(int i=0;i<count;i++) { |
528 | pathList << m_location->text(i); | 528 | pathList << m_location->text(i); |
529 | if( m_location->text(i) == currentPath) | 529 | if( m_location->text(i) == currentPath) |
530 | underDog = TRUE; | 530 | underDog = TRUE; |
531 | } | 531 | } |
532 | if( !underDog) { | 532 | if( !underDog) { |
533 | m_location->clear(); | 533 | m_location->clear(); |
534 | if( currentPath.left(2)=="//") | 534 | if( currentPath.left(2)=="//") |
535 | pathList.append( currentPath.right(currentPath.length()-1) ); | 535 | pathList.append( currentPath.right(currentPath.length()-1) ); |
536 | else | 536 | else |
537 | pathList.append( currentPath ); | 537 | pathList.append( currentPath ); |
538 | m_location->insertStringList( pathList,-1); | 538 | m_location->insertStringList( pathList,-1); |
539 | } | 539 | } |
540 | } | 540 | } |
541 | void OFileSelector::locationComboChanged() | 541 | void OFileSelector::locationComboChanged() |
542 | { | 542 | { |
543 | cd( m_location->lineEdit()->text()); | 543 | cd( m_location->lineEdit()->text()); |
544 | reparse(); | 544 | reparse(); |
545 | } | 545 | } |
546 | void OFileSelector::init() | 546 | void OFileSelector::init() |
547 | { | 547 | { |
548 | m_lay = new QVBoxLayout( this ); | 548 | m_lay = new QVBoxLayout( this ); |
549 | m_lay->setSpacing(0 ); | 549 | m_lay->setSpacing(0 ); |
550 | 550 | ||
551 | m_stack = new QWidgetStack( this ); | 551 | m_stack = new QWidgetStack( this ); |
552 | if( m_selector == NORMAL ){ | 552 | if( m_selector == NORMAL ){ |
553 | QString mime; | 553 | QString mime; |
554 | if (!m_autoMime) { | 554 | if (!m_autoMime) { |
555 | if (!m_mimetypes.isEmpty() ) { | 555 | if (!m_mimetypes.isEmpty() ) { |
556 | QMap<QString, QStringList>::Iterator it; | 556 | QMap<QString, QStringList>::Iterator it; |
557 | it = m_mimetypes.begin(); // cause we're in the init | 557 | it = m_mimetypes.begin(); // cause we're in the init |
558 | mime = it.data().join(";"); | 558 | mime = it.data().join(";"); |
559 | } | 559 | } |
560 | } | 560 | } |
561 | m_select = new FileSelector(mime, | 561 | m_select = new FileSelector(mime, |
562 | m_stack, "fileselector", | 562 | m_stack, "fileselector", |
563 | FALSE, FALSE); | 563 | FALSE, FALSE); |
564 | 564 | ||
565 | connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ), | 565 | connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ), |
566 | this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) ); | 566 | this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) ); |
567 | //connect to close me and other signals as well | 567 | //connect to close me and other signals as well |
568 | 568 | ||
569 | m_stack->addWidget( m_select, NORMAL ); | 569 | m_stack->addWidget( m_select, NORMAL ); |
570 | m_stack->raiseWidget( NORMAL ); | 570 | m_stack->raiseWidget( NORMAL ); |
571 | }else{ // we're in init so it will be EXTENDED or EXTENDED_ALL | 571 | }else{ // we're in init so it will be EXTENDED or EXTENDED_ALL |
572 | // and initializeListview will take care of those | 572 | // and initializeListview will take care of those |
573 | // toolbar get's generade in initializeListView | 573 | // toolbar get's generade in initializeListView |
574 | initializeListView( ); // will raise the widget as well | 574 | initializeListView( ); // will raise the widget as well |
575 | } | 575 | } |
576 | m_lay->addWidget( m_stack, 100 ); // add to the layout 10 = stretch | 576 | m_lay->addWidget( m_stack, 100 ); // add to the layout 10 = stretch |
577 | 577 | ||
578 | if( m_shLne ) // the LineEdit with the current FileName | 578 | if( m_shLne ) // the LineEdit with the current FileName |
579 | initializeName(); | 579 | initializeName(); |
580 | 580 | ||
581 | if( m_shPerm ) // the Permission QCheckBox | 581 | if( m_shPerm ) // the Permission QCheckBox |
582 | initializePerm(); | 582 | initializePerm(); |
583 | 583 | ||
584 | if( m_shChooser ) // the Chooser for the view and Mimetypes | 584 | if( m_shChooser ) // the Chooser for the view and Mimetypes |
585 | initializeChooser(); | 585 | initializeChooser(); |
586 | 586 | ||
587 | if( m_shYesNo ) // the Yes No button row | 587 | if( m_shYesNo ) // the Yes No button row |
588 | initializeYes( ); | 588 | initializeYes( ); |
589 | } | 589 | } |
590 | void OFileSelector::updateMimes() | 590 | void OFileSelector::updateMimes() |
591 | { | 591 | { |
592 | if( m_autoMime ){ | 592 | if( m_autoMime ){ |
593 | m_mimetypes.clear(); | 593 | m_mimetypes.clear(); |
594 | m_mimetypes.insert( tr("All"), QString::null ); | 594 | m_mimetypes.insert( tr("All"), QString::null ); |
595 | if( m_selector == NORMAL ){ | 595 | if( m_selector == NORMAL ){ |
596 | DocLnkSet set; | 596 | DocLnkSet set; |
597 | Global::findDocuments(&set, QString::null ); | 597 | Global::findDocuments(&set, QString::null ); |
598 | QListIterator<DocLnk> dit( set.children() ); | 598 | QListIterator<DocLnk> dit( set.children() ); |
599 | for( ; dit.current(); ++dit ){ | 599 | for( ; dit.current(); ++dit ){ |
600 | if( !m_mimetypes.contains( (*dit)->type() ) ) | 600 | if( !m_mimetypes.contains( (*dit)->type() ) ) |
601 | m_mimetypes.insert( (*dit)->type(), (*dit)->type() ); | 601 | m_mimetypes.insert( (*dit)->type(), (*dit)->type() ); |
602 | } | 602 | } |
603 | }// else done in reparse | 603 | }// else done in reparse |
604 | } | 604 | } |
605 | } | 605 | } |
606 | void OFileSelector::initVars() | 606 | void OFileSelector::initVars() |
607 | { | 607 | { |
608 | if( m_mimetypes.isEmpty() ) | 608 | if( m_mimetypes.isEmpty() ) |
609 | m_autoMime = true; | 609 | m_autoMime = true; |
610 | else | 610 | else |
611 | m_autoMime = false; | 611 | m_autoMime = false; |
612 | m_shClose = false; | 612 | m_shClose = false; |
613 | m_shNew = false; | 613 | m_shNew = false; |
614 | m_shTool = true; | 614 | m_shTool = true; |
615 | m_shPerm = false; | 615 | m_shPerm = false; |
616 | m_shLne = true; | 616 | m_shLne = true; |
617 | m_shChooser = true; | 617 | m_shChooser = true; |
618 | m_shYesNo = true; | 618 | m_shYesNo = true; |
619 | m_case = false; | 619 | m_case = false; |
620 | m_dir = true; | 620 | m_dir = true; |
621 | m_files = true; | 621 | m_files = true; |
622 | m_showPopup = false; | 622 | m_showPopup = false; |
623 | if(m_pixmaps == 0 ) // init the pixmaps | 623 | if(m_pixmaps == 0 ) // init the pixmaps |
624 | initPics(); | 624 | initPics(); |
625 | 625 | ||
626 | // pointers | 626 | // pointers |
627 | m_location = 0; | 627 | m_location = 0; |
628 | m_mimeCheck = 0; | 628 | m_mimeCheck = 0; |
629 | m_viewCheck = 0; | 629 | m_viewCheck = 0; |
630 | m_homeButton = 0; | 630 | m_homeButton = 0; |
631 | m_docButton = 0; | 631 | m_docButton = 0; |
632 | m_hideButton = 0; | 632 | m_hideButton = 0; |
633 | m_ok = 0; | 633 | m_ok = 0; |
634 | m_cancel = 0; | 634 | m_cancel = 0; |
635 | m_reread = 0; | 635 | m_reread = 0; |
636 | m_up = 0; | 636 | m_up = 0; |
637 | m_View = 0; | 637 | m_View = 0; |
638 | m_checkPerm = 0; | 638 | m_checkPerm = 0; |
639 | m_pseudo = 0; | 639 | m_pseudo = 0; |
640 | m_pseudoLayout = 0; | 640 | m_pseudoLayout = 0; |
641 | m_select = 0; | 641 | m_select = 0; |
642 | m_stack = 0; | 642 | m_stack = 0; |
643 | m_lay = 0; | 643 | m_lay = 0; |
644 | m_Oselector = 0; | 644 | m_Oselector = 0; |
645 | m_boxToolbar = 0; | 645 | m_boxToolbar = 0; |
646 | m_boxOk = 0; | 646 | m_boxOk = 0; |
647 | m_boxName = 0; | 647 | m_boxName = 0; |
648 | m_boxView = 0; | 648 | m_boxView = 0; |
649 | m_custom = 0; | 649 | m_custom = 0; |
650 | m_edit = 0; | 650 | m_edit = 0; |
651 | m_fnLabel = 0; | 651 | m_fnLabel = 0; |
652 | m_new = 0; | 652 | m_new = 0; |
653 | m_close = 0; | 653 | m_close = 0; |
654 | } | 654 | } |
655 | void OFileSelector::addFile(const QString &mime, QFileInfo *info, bool symlink) | 655 | void OFileSelector::addFile(const QString &mime, QFileInfo *info, bool symlink) |
656 | { | 656 | { |
657 | if(!m_files) | 657 | if(!m_files) |
658 | return; | 658 | return; |
659 | // if( !compliesMime(info->absFilePath(), mime ) ) | 659 | // if( !compliesMime(info->absFilePath(), mime ) ) |
660 | // return; | 660 | // return; |
661 | MimeType type( info->absFilePath() ); | 661 | MimeType type( info->absFilePath() ); |
662 | if( mime != tr("All") && type.id() != mime ) | 662 | if (!compliesMime( type.id() ) ) |
663 | return; | 663 | return; |
664 | |||
664 | QPixmap pix = type.pixmap(); | 665 | QPixmap pix = type.pixmap(); |
665 | QString dir; | 666 | QString dir; |
666 | QString name; | 667 | QString name; |
667 | bool locked; | 668 | bool locked; |
668 | if( pix.isNull() ) | 669 | if( pix.isNull() ) |
669 | pix = Resource::loadPixmap( "UnknownDocument-14"); | 670 | pix = Resource::loadPixmap( "UnknownDocument-14"); |
670 | dir = info->dirPath( true ); | 671 | dir = info->dirPath( true ); |
671 | if( symlink ) | 672 | if( symlink ) |
672 | name = info->fileName() + " -> " +info->dirPath() + "/" + info->readLink(); | 673 | name = info->fileName() + " -> " +info->dirPath() + "/" + info->readLink(); |
673 | else { | 674 | else { |
674 | name = info->fileName(); | 675 | name = info->fileName(); |
675 | if( ( m_mode == OPEN && !info->isReadable() )|| | 676 | if( ( m_mode == OPEN && !info->isReadable() )|| |
676 | ( m_mode == SAVE && !info->isWritable() ) ){ | 677 | ( m_mode == SAVE && !info->isWritable() ) ){ |
677 | 678 | ||
678 | locked = true; pix = Resource::loadPixmap("locked"); | 679 | locked = true; pix = Resource::loadPixmap("locked"); |
679 | } | 680 | } |
680 | } | 681 | } |
681 | new OFileSelectorItem( m_View, pix, name, | 682 | new OFileSelectorItem( m_View, pix, name, |
682 | info->lastModified().toString(), | 683 | info->lastModified().toString(), |
683 | QString::number( info->size() ), | 684 | QString::number( info->size() ), |
684 | dir, locked ); | 685 | dir, locked ); |
685 | } | 686 | } |
686 | void OFileSelector::addDir(const QString &mime, QFileInfo *info, bool symlink ) | 687 | void OFileSelector::addDir(const QString &mime, QFileInfo *info, bool symlink ) |
687 | { | 688 | { |
688 | if(!m_dir) | 689 | if(!m_dir) |
689 | return; | 690 | return; |
690 | if( m_selector == EXTENDED_ALL || m_selector == EXTENDED ){ | 691 | if( m_selector == EXTENDED_ALL || m_selector == EXTENDED ){ |
691 | bool locked = false; | 692 | bool locked = false; |
692 | QString name; | 693 | QString name; |
693 | QPixmap pix; | 694 | QPixmap pix; |
694 | if( ( m_mode == OPEN && !info->isReadable() ) || ( m_mode == SAVE && !info->isWritable() ) ){ | 695 | if( ( m_mode == OPEN && !info->isReadable() ) || ( m_mode == SAVE && !info->isWritable() ) ){ |
695 | locked = true; | 696 | locked = true; |
696 | if( symlink ) | 697 | if( symlink ) |
697 | pix = (*m_pixmaps)["symlinkedlocked"]; | 698 | pix = (*m_pixmaps)["symlinkedlocked"]; |
698 | else | 699 | else |
699 | pix = Resource::loadPixmap("lockedfolder"); | 700 | pix = Resource::loadPixmap("lockedfolder"); |
700 | }else { // readable | 701 | }else { // readable |
701 | pix = symlink ? (*m_pixmaps)["dirsymlink"] : Resource::loadPixmap("folder") ; | 702 | pix = symlink ? (*m_pixmaps)["dirsymlink"] : Resource::loadPixmap("folder") ; |
702 | } | 703 | } |
703 | name = symlink ? info->fileName() + "->" + info->dirPath(true) + "/" +info->readLink() : info->fileName() ; | 704 | name = symlink ? info->fileName() + "->" + info->dirPath(true) + "/" +info->readLink() : info->fileName() ; |
704 | new OFileSelectorItem( m_View, pix, name, | 705 | new OFileSelectorItem( m_View, pix, name, |
705 | info->lastModified().toString(), | 706 | info->lastModified().toString(), |
706 | QString::number( info->size() ), | 707 | QString::number( info->size() ), |
707 | info->dirPath( true ), locked, | 708 | info->dirPath( true ), locked, |
708 | true ); | 709 | true ); |
709 | 710 | ||
710 | }// else CUSTOM View | 711 | }// else CUSTOM View |
711 | } | 712 | } |
712 | void OFileSelector::delItems() | 713 | void OFileSelector::delItems() |
713 | { | 714 | { |
714 | 715 | ||
715 | } | 716 | } |
716 | void OFileSelector::initializeName() | 717 | void OFileSelector::initializeName() |
717 | { | 718 | { |
718 | /** Name Layout Line | 719 | /** Name Layout Line |
719 | * This is the Layout line arranged in | 720 | * This is the Layout line arranged in |
720 | * horizontal way each components | 721 | * horizontal way each components |
721 | * are next to each other | 722 | * are next to each other |
722 | * but we will only do this if | 723 | * but we will only do this if |
723 | * we didn't initialize a while ago. | 724 | * we didn't initialize a while ago. |
724 | */ | 725 | */ |
725 | if( m_boxName == 0 ){ | 726 | if( m_boxName == 0 ){ |
726 | m_boxName = new QHBox( this ); // remove this this? or use a QHBox | 727 | m_boxName = new QHBox( this ); // remove this this? or use a QHBox |
727 | m_fnLabel = new QLabel( m_boxName ); | 728 | m_fnLabel = new QLabel( m_boxName ); |
728 | m_fnLabel->setText( tr("Name:") ); | 729 | m_fnLabel->setText( tr("Name:") ); |
729 | m_edit = new QLineEdit( m_boxName ); | 730 | m_edit = new QLineEdit( m_boxName ); |
730 | m_edit->setText( m_name ); | 731 | m_edit->setText( m_name ); |
731 | //m_boxName->addWidget( m_fnLabel ); | 732 | //m_boxName->addWidget( m_fnLabel ); |
732 | m_boxName->setMargin( 5 ); | 733 | m_boxName->setMargin( 5 ); |
733 | m_boxName->setSpacing( 8 ); | 734 | m_boxName->setSpacing( 8 ); |
734 | //m_boxName->setStretchFactor(m_edit, 100 ); // 100 is stretch factor | 735 | //m_boxName->setStretchFactor(m_edit, 100 ); // 100 is stretch factor |
735 | 736 | ||
736 | m_lay->addWidget( m_boxName, 0 ); // add it to the topLevel layout | 737 | m_lay->addWidget( m_boxName, 0 ); // add it to the topLevel layout |
737 | }// else we already initialized | 738 | }// else we already initialized |
738 | // maybe show the components? | 739 | // maybe show the components? |
739 | // | 740 | // |
740 | } | 741 | } |
741 | void OFileSelector::initializeYes() | 742 | void OFileSelector::initializeYes() |
742 | { | 743 | { |
743 | /** The Save Cancel bar | 744 | /** The Save Cancel bar |
744 | * | 745 | * |
745 | */ | 746 | */ |
746 | if( m_boxOk == 0 ){ | 747 | if( m_boxOk == 0 ){ |
747 | m_boxOk = new QHBox( this ); | 748 | m_boxOk = new QHBox( this ); |
748 | m_ok = new QPushButton( tr("&Save"),m_boxOk , "save" ); | 749 | m_ok = new QPushButton( tr("&Save"),m_boxOk , "save" ); |
749 | m_cancel = new QPushButton( tr("C&ancel"), m_boxOk, "cancel" ); | 750 | m_cancel = new QPushButton( tr("C&ancel"), m_boxOk, "cancel" ); |
750 | 751 | ||
751 | //m_boxOk->addWidget( m_ok ); | 752 | //m_boxOk->addWidget( m_ok ); |
752 | //m_boxOk->addWidget( m_cancel ); | 753 | //m_boxOk->addWidget( m_cancel ); |
753 | m_boxOk->setMargin( 5 ); | 754 | m_boxOk->setMargin( 5 ); |
754 | m_boxOk->setSpacing( 10 ); | 755 | m_boxOk->setSpacing( 10 ); |
755 | m_lay->addWidget( m_boxOk, 0 ); | 756 | m_lay->addWidget( m_boxOk, 0 ); |
756 | 757 | ||
757 | connect( m_ok, SIGNAL( clicked() ), | 758 | connect( m_ok, SIGNAL( clicked() ), |
758 | this, SLOT(slotOk() ) ); | 759 | this, SLOT(slotOk() ) ); |
759 | connect( m_cancel, SIGNAL( clicked() ), | 760 | connect( m_cancel, SIGNAL( clicked() ), |
760 | this, SLOT( slotCancel() ) ); | 761 | this, SLOT( slotCancel() ) ); |
761 | } | 762 | } |
762 | } | 763 | } |
763 | /* | 764 | /* |
764 | * OK m_mimeCheck is a QComboBox we now want to fill | 765 | * OK m_mimeCheck is a QComboBox we now want to fill |
765 | * out that combobox | 766 | * out that combobox |
766 | * if automime we need to update the mimetypes | 767 | * if automime we need to update the mimetypes |
767 | */ | 768 | */ |
768 | void OFileSelector::updateMimeCheck() { | 769 | void OFileSelector::updateMimeCheck() { |
769 | m_mimeCheck->clear(); | 770 | m_mimeCheck->clear(); |
770 | if (m_autoMime ) { | 771 | if (m_autoMime ) { |
771 | //m_mimeCheck->insertItem( tr("All") ); | 772 | //m_mimeCheck->insertItem( tr("All") ); |
772 | updateMimes(); | 773 | updateMimes(); |
773 | } | 774 | } |
774 | 775 | ||
775 | QMap<QString, QStringList>::Iterator it; | 776 | QMap<QString, QStringList>::Iterator it; |
776 | for (it = m_mimetypes.begin(); it != m_mimetypes.end(); ++it ) { | 777 | for (it = m_mimetypes.begin(); it != m_mimetypes.end(); ++it ) { |
777 | m_mimeCheck->insertItem( it.key() ); | 778 | m_mimeCheck->insertItem( it.key() ); |
778 | } | 779 | } |
779 | } | 780 | } |
780 | 781 | ||
781 | void OFileSelector::initializeChooser() | 782 | void OFileSelector::initializeChooser() |
782 | { | 783 | { |
783 | if( m_boxView == 0 ){ | 784 | if( m_boxView == 0 ){ |
784 | m_boxView = new QHBox( this ); | 785 | m_boxView = new QHBox( this ); |
785 | m_viewCheck = new QComboBox( m_boxView, "view check"); | 786 | m_viewCheck = new QComboBox( m_boxView, "view check"); |
786 | m_mimeCheck = new QComboBox( m_boxView, "mime check"); | 787 | m_mimeCheck = new QComboBox( m_boxView, "mime check"); |
787 | m_boxView->setSpacing( 8 ); | 788 | m_boxView->setSpacing( 8 ); |
788 | m_lay->addWidget(m_boxView, 0 ); | 789 | m_lay->addWidget(m_boxView, 0 ); |
789 | 790 | ||
790 | m_viewCheck->insertItem( tr("Documents") ); | 791 | m_viewCheck->insertItem( tr("Documents") ); |
791 | m_viewCheck->insertItem( tr("Files") ); | 792 | m_viewCheck->insertItem( tr("Files") ); |
792 | m_viewCheck->insertItem( tr("All Files") ); | 793 | m_viewCheck->insertItem( tr("All Files") ); |
793 | updateMimeCheck(); | 794 | updateMimeCheck(); |
794 | 795 | ||
795 | connect( m_viewCheck, SIGNAL( activated(const QString & ) ), | 796 | connect( m_viewCheck, SIGNAL( activated(const QString & ) ), |
796 | this, SLOT( slotViewCheck(const QString & ) ) ); | 797 | this, SLOT( slotViewCheck(const QString & ) ) ); |
797 | connect( m_mimeCheck, SIGNAL( activated(const QString & ) ), | 798 | connect( m_mimeCheck, SIGNAL( activated(const QString & ) ), |
798 | this, SLOT( slotMimeCheck( const QString & ) ) ); | 799 | this, SLOT( slotMimeCheck( const QString & ) ) ); |
799 | } | 800 | } |
800 | } | 801 | } |
801 | void OFileSelector::initializeListView() | 802 | void OFileSelector::initializeListView() |
802 | { | 803 | { |
803 | if( m_pseudo == 0 ){ | 804 | if( m_pseudo == 0 ){ |
804 | m_pseudo = new QWidget( m_stack, "Pseudo Widget"); | 805 | m_pseudo = new QWidget( m_stack, "Pseudo Widget"); |
805 | m_pseudoLayout = new QVBoxLayout( m_pseudo ); | 806 | m_pseudoLayout = new QVBoxLayout( m_pseudo ); |
806 | // toolbar | 807 | // toolbar |
807 | m_boxToolbar = new QHBox( m_pseudo ); | 808 | m_boxToolbar = new QHBox( m_pseudo ); |
808 | m_boxToolbar->setSpacing(0 ); // next to each other please | 809 | m_boxToolbar->setSpacing(0 ); // next to each other please |
809 | 810 | ||
810 | // toolbar members | 811 | // toolbar members |
811 | { | 812 | { |
812 | // location QComboBox | 813 | // location QComboBox |
813 | m_location = new QComboBox( m_boxToolbar ); | 814 | m_location = new QComboBox( m_boxToolbar ); |
814 | m_location->setEditable( TRUE ); | 815 | m_location->setEditable( TRUE ); |
815 | m_location->setDuplicatesEnabled( FALSE ); | 816 | m_location->setDuplicatesEnabled( FALSE ); |
816 | connect( m_location, SIGNAL(activated(const QString &) ), | 817 | connect( m_location, SIGNAL(activated(const QString &) ), |
817 | this, SLOT( slotLocationActivated(const QString &) ) ); | 818 | this, SLOT( slotLocationActivated(const QString &) ) ); |
818 | connect( m_location->lineEdit(), SIGNAL(returnPressed() ), | 819 | connect( m_location->lineEdit(), SIGNAL(returnPressed() ), |
819 | this, SLOT(locationComboChanged() ) ); | 820 | this, SLOT(locationComboChanged() ) ); |
820 | // UP Button | 821 | // UP Button |
821 | m_up = new QPushButton(Resource::loadIconSet("up"),"", | 822 | m_up = new QPushButton(Resource::loadIconSet("up"),"", |
822 | m_boxToolbar,"cdUpButton"); | 823 | m_boxToolbar,"cdUpButton"); |
823 | m_up->setFixedSize( QSize( 20, 20 ) ); | 824 | m_up->setFixedSize( QSize( 20, 20 ) ); |
824 | connect(m_up ,SIGNAL(clicked()),this,SLOT(cdUP() ) ); | 825 | connect(m_up ,SIGNAL(clicked()),this,SLOT(cdUP() ) ); |
825 | m_up->setFlat(TRUE); | 826 | m_up->setFlat(TRUE); |
826 | 827 | ||
827 | // Home Button | 828 | // Home Button |
828 | m_homeButton = new QPushButton(Resource::loadIconSet("home") , | 829 | m_homeButton = new QPushButton(Resource::loadIconSet("home") , |
829 | "", m_boxToolbar); | 830 | "", m_boxToolbar); |
830 | m_homeButton->setFixedSize( QSize( 20, 20 ) ); | 831 | m_homeButton->setFixedSize( QSize( 20, 20 ) ); |
831 | connect(m_homeButton,SIGNAL(clicked()),this,SLOT(slotHome() ) ); | 832 | connect(m_homeButton,SIGNAL(clicked()),this,SLOT(slotHome() ) ); |
832 | m_homeButton->setFlat(TRUE); | 833 | m_homeButton->setFlat(TRUE); |
833 | // Documents Button | 834 | // Documents Button |
834 | m_docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"", | 835 | m_docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"", |
835 | m_boxToolbar,"docsButton"); | 836 | m_boxToolbar,"docsButton"); |
836 | m_docButton->setFixedSize( QSize( 20, 20 ) ); | 837 | m_docButton->setFixedSize( QSize( 20, 20 ) ); |
837 | connect(m_homeButton,SIGNAL(clicked()),this,SLOT(slotDoc() ) ); | 838 | connect(m_homeButton,SIGNAL(clicked()),this,SLOT(slotDoc() ) ); |
838 | m_docButton->setFlat(TRUE); | 839 | m_docButton->setFlat(TRUE); |
839 | 840 | ||
840 | // Close button | 841 | // Close button |
841 | m_close = new QPushButton( Resource::loadIconSet( "close"), "", | 842 | m_close = new QPushButton( Resource::loadIconSet( "close"), "", |
842 | m_boxToolbar ); | 843 | m_boxToolbar ); |
843 | connect( m_close, SIGNAL(clicked() ), this, SIGNAL(closeMe() ) ); | 844 | connect( m_close, SIGNAL(clicked() ), this, SIGNAL(closeMe() ) ); |
844 | m_close->setFixedSize( 20, 20 ); | 845 | m_close->setFixedSize( 20, 20 ); |
845 | 846 | ||
846 | m_boxToolbar->setFixedHeight( 20 ); | 847 | m_boxToolbar->setFixedHeight( 20 ); |
847 | m_pseudoLayout->addWidget(m_boxToolbar ); | 848 | m_pseudoLayout->addWidget(m_boxToolbar ); |
848 | 849 | ||
849 | // let;s fill the Location ComboBox | 850 | // let;s fill the Location ComboBox |
850 | StorageInfo storage; | 851 | StorageInfo storage; |
851 | const QList<FileSystem> &fs = storage.fileSystems(); | 852 | const QList<FileSystem> &fs = storage.fileSystems(); |
852 | QListIterator<FileSystem> it ( fs ); | 853 | QListIterator<FileSystem> it ( fs ); |
853 | for( ; it.current(); ++it ){ | 854 | for( ; it.current(); ++it ){ |
854 | const QString disk = (*it)->name(); | 855 | const QString disk = (*it)->name(); |
855 | const QString path = (*it)->path(); | 856 | const QString path = (*it)->path(); |
856 | m_location->insertItem(path+ "<-"+disk ); | 857 | m_location->insertItem(path+ "<-"+disk ); |
857 | } | 858 | } |
858 | int count = m_location->count(); | 859 | int count = m_location->count(); |
859 | m_location->insertItem( m_currentDir ); | 860 | m_location->insertItem( m_currentDir ); |
860 | m_location->setCurrentItem( count ); | 861 | m_location->setCurrentItem( count ); |
861 | // due to the New and Close button we can not simply hide m_boxToolBar to not show it | 862 | // due to the New and Close button we can not simply hide m_boxToolBar to not show it |
862 | if( !m_shTool ){ | 863 | if( !m_shTool ){ |
863 | m_location->hide( ); | 864 | m_location->hide( ); |
864 | m_up->hide( ); | 865 | m_up->hide( ); |
865 | m_homeButton->hide( ); | 866 | m_homeButton->hide( ); |
866 | m_docButton->hide( ); | 867 | m_docButton->hide( ); |
867 | } | 868 | } |
868 | if(!m_shClose ) | 869 | if(!m_shClose ) |
869 | m_close->hide(); | 870 | m_close->hide(); |
870 | if(!m_shNew) | 871 | if(!m_shNew) |
871 | m_close->hide(); | 872 | m_close->hide(); |
872 | 873 | ||
873 | } // off toolbar | 874 | } // off toolbar |
874 | // the Main ListView | 875 | // the Main ListView |
875 | // make a QWidgetStack first so Views can share the Toolbar | 876 | // make a QWidgetStack first so Views can share the Toolbar |
876 | m_View = new QListView( m_pseudo, "Extended view"); | 877 | m_View = new QListView( m_pseudo, "Extended view"); |
877 | QPEApplication::setStylusOperation( m_View->viewport(), | 878 | QPEApplication::setStylusOperation( m_View->viewport(), |
878 | QPEApplication::RightOnHold); | 879 | QPEApplication::RightOnHold); |
879 | m_View->addColumn(" " ); | 880 | m_View->addColumn(" " ); |
880 | m_View->addColumn(tr("Name"), 135 ); | 881 | m_View->addColumn(tr("Name"), 135 ); |
881 | m_View->addColumn(tr("Size"), -1 ); | 882 | m_View->addColumn(tr("Size"), -1 ); |
882 | m_View->addColumn(tr("Date"), 60 ); | 883 | m_View->addColumn(tr("Date"), 60 ); |
883 | m_View->addColumn(tr("Mime Type"), -1 ); | 884 | m_View->addColumn(tr("Mime Type"), -1 ); |
884 | QHeader *header = m_View->header(); | 885 | QHeader *header = m_View->header(); |
885 | header->hide(); | 886 | header->hide(); |
886 | m_View->setSorting( 1 ); | 887 | m_View->setSorting( 1 ); |
887 | m_View->setAllColumnsShowFocus( TRUE ); | 888 | m_View->setAllColumnsShowFocus( TRUE ); |
888 | 889 | ||
889 | connect(m_View, SIGNAL(selectionChanged() ), | 890 | connect(m_View, SIGNAL(selectionChanged() ), |
890 | this, SLOT(slotSelectionChanged() ) ); | 891 | this, SLOT(slotSelectionChanged() ) ); |
891 | 892 | ||
892 | connect(m_View, SIGNAL(currentChanged(QListViewItem *) ), | 893 | connect(m_View, SIGNAL(currentChanged(QListViewItem *) ), |
893 | this, SLOT(slotCurrentChanged(QListViewItem * ) ) ); | 894 | this, SLOT(slotCurrentChanged(QListViewItem * ) ) ); |
894 | 895 | ||
895 | connect(m_View, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint &, int) ), | 896 | connect(m_View, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint &, int) ), |
896 | this, SLOT(slotClicked( int, QListViewItem *, const QPoint &, int) ) ); | 897 | this, SLOT(slotClicked( int, QListViewItem *, const QPoint &, int) ) ); |
897 | 898 | ||
898 | connect(m_View, SIGNAL(mouseButtonPressed(int, QListViewItem *, const QPoint &, int )), | 899 | connect(m_View, SIGNAL(mouseButtonPressed(int, QListViewItem *, const QPoint &, int )), |
899 | this, SLOT(slotRightButton(int, QListViewItem *, const QPoint &, int ) ) ); | 900 | this, SLOT(slotRightButton(int, QListViewItem *, const QPoint &, int ) ) ); |
900 | 901 | ||
901 | m_pseudoLayout->addWidget( m_View, 288 ); | 902 | m_pseudoLayout->addWidget( m_View, 288 ); |
902 | m_stack->addWidget( m_pseudo, EXTENDED ); | 903 | m_stack->addWidget( m_pseudo, EXTENDED ); |
903 | } | 904 | } |
904 | } | 905 | } |
905 | void OFileSelector::initializePerm() | 906 | void OFileSelector::initializePerm() |
906 | { | 907 | { |
907 | if( m_checkPerm == 0 ){ | 908 | if( m_checkPerm == 0 ){ |
908 | m_checkPerm = new QCheckBox(tr("Ser Permission"), this, "perm"); | 909 | m_checkPerm = new QCheckBox(tr("Ser Permission"), this, "perm"); |
909 | m_checkPerm->setChecked( false ); | 910 | m_checkPerm->setChecked( false ); |
910 | m_lay->addWidget( m_checkPerm ); | 911 | m_lay->addWidget( m_checkPerm ); |
911 | 912 | ||
912 | } | 913 | } |
913 | } | 914 | } |
914 | void OFileSelector::initPics() | 915 | void OFileSelector::initPics() |
915 | { | 916 | { |
916 | m_pixmaps = new QMap<QString,QPixmap>; | 917 | m_pixmaps = new QMap<QString,QPixmap>; |
917 | QPixmap pm = Resource::loadPixmap( "folder" ); | 918 | QPixmap pm = Resource::loadPixmap( "folder" ); |
918 | QPixmap lnk = Resource::loadPixmap( "opie/symlink" ); | 919 | QPixmap lnk = Resource::loadPixmap( "opie/symlink" ); |
919 | QPainter painter( &pm ); | 920 | QPainter painter( &pm ); |
920 | painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); | 921 | painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); |
921 | pm.setMask( pm.createHeuristicMask( FALSE ) ); | 922 | pm.setMask( pm.createHeuristicMask( FALSE ) ); |
922 | m_pixmaps->insert("dirsymlink", pm ); | 923 | m_pixmaps->insert("dirsymlink", pm ); |
923 | 924 | ||
924 | QPixmap pm2 = Resource::loadPixmap( "lockedfolder" ); | 925 | QPixmap pm2 = Resource::loadPixmap( "lockedfolder" ); |
925 | QPainter pen(&pm2 ); | 926 | QPainter pen(&pm2 ); |
926 | pen.drawPixmap(pm2.width()-lnk.width(), pm2.height()-lnk.height(), lnk ); | 927 | pen.drawPixmap(pm2.width()-lnk.width(), pm2.height()-lnk.height(), lnk ); |
927 | pm2.setMask( pm2.createHeuristicMask( FALSE ) ); | 928 | pm2.setMask( pm2.createHeuristicMask( FALSE ) ); |
928 | m_pixmaps->insert("symlinkedlocked", pm2 ); | 929 | m_pixmaps->insert("symlinkedlocked", pm2 ); |
929 | } | 930 | } |
930 | // if a mime complies with the m_mimeCheck->currentItem | 931 | // if a mime complies with the m_mimeCheck->currentItem |
931 | bool OFileSelector::compliesMime( const QString &path, const QString &mime ) | 932 | bool OFileSelector::compliesMime( const QString &path, const QString &mime ) |
932 | { | 933 | { |
933 | if( mime == "All" ) | 934 | if( mime == "All" ) |
934 | return true; | 935 | return true; |
935 | MimeType type( path ); | 936 | MimeType type( path ); |
936 | if( type.id() == mime ) | 937 | if( type.id() == mime ) |
937 | return true; | 938 | return true; |
938 | return false; | 939 | return false; |
939 | } | 940 | } |
940 | /* check if the mimetype in mime | 941 | /* check if the mimetype in mime |
941 | * complies with the one which is current | 942 | * complies with the one which is current |
942 | */ | 943 | */ |
944 | /* | ||
945 | * We've the mimetype of the file | ||
946 | * We need to get the stringlist of the current mimetype | ||
947 | * | ||
948 | * mime = image/jpeg | ||
949 | * QStringList = 'image/*' | ||
950 | * or QStringList = image/jpeg;image/png;application/x-ogg | ||
951 | * or QStringList = application/x-ogg;image/*; | ||
952 | * with all these mime filters it should get acceptes | ||
953 | * to do so we need to look if mime is contained inside | ||
954 | * the stringlist | ||
955 | * if it's contained return true | ||
956 | * if not ( I'm no RegExp expert at all ) we'll look if a '/*' | ||
957 | * is contained in the mimefilter and then we will | ||
958 | * look if both are equal until the '/' | ||
959 | */ | ||
943 | bool OFileSelector::compliesMime( const QString& mime ) { | 960 | bool OFileSelector::compliesMime( const QString& mime ) { |
961 | qWarning("mimetype is %s", mime.latin1() ); | ||
962 | QString currentText; | ||
963 | if (m_shChooser ) | ||
964 | currentText = m_mimeCheck->currentText(); | ||
944 | 965 | ||
966 | qWarning("current text is %s", currentText.latin1() ); | ||
967 | QMap<QString, QStringList>::Iterator it; | ||
968 | QStringList list; | ||
969 | if ( currentText == tr("All") ) return true; | ||
970 | else if ( currentText.isEmpty() && !m_mimetypes.isEmpty() ) { | ||
971 | it = m_mimetypes.begin(); | ||
972 | list = it.data(); | ||
973 | }else if ( currentText.isEmpty() ) return true; | ||
974 | else{ | ||
975 | it = m_mimetypes.find(currentText ); | ||
976 | if ( it == m_mimetypes.end() ) qWarning("not there"), list << currentText; | ||
977 | else qWarning("found"), list = it.data(); | ||
978 | } | ||
979 | // dump it now | ||
980 | //for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | ||
981 | // qWarning( "%s", (*it).latin1() ); | ||
982 | //} | ||
983 | |||
984 | |||
985 | if ( list.contains(mime) ) return true; | ||
986 | qWarning("list doesn't contain it "); | ||
987 | QStringList::Iterator it2; | ||
988 | int pos; | ||
989 | int pos2; | ||
990 | for ( it2 = list.begin(); it2 != list.end(); ++it2 ) { | ||
991 | pos = (*it2).findRev("/*"); | ||
992 | if ( pos >= 0 ) { | ||
993 | if ( mime.contains( (*it2).left(pos) ) ) return true; | ||
994 | } | ||
995 | } | ||
996 | return false; | ||
945 | } | 997 | } |
946 | void OFileSelector::slotFileSelected( const QString &string ) | 998 | void OFileSelector::slotFileSelected( const QString &string ) |
947 | { | 999 | { |
948 | if( m_shLne ) | 1000 | if( m_shLne ) |
949 | m_edit->setText( string ); | 1001 | m_edit->setText( string ); |
950 | emit fileSelected( string ); | 1002 | emit fileSelected( string ); |
951 | } | 1003 | } |
952 | void OFileSelector::slotFileBridgeSelected( const DocLnk &lnk ) | 1004 | void OFileSelector::slotFileBridgeSelected( const DocLnk &lnk ) |
953 | { | 1005 | { |
954 | slotFileSelected( lnk.name() ); | 1006 | slotFileSelected( lnk.name() ); |
955 | // emit fileSelected( lnk ); | 1007 | // emit fileSelected( lnk ); |
956 | } | 1008 | } |
957 | void OFileSelector::slotSelectionChanged() | 1009 | void OFileSelector::slotSelectionChanged() |
958 | { | 1010 | { |
959 | 1011 | ||
960 | } | 1012 | } |
961 | void OFileSelector::slotCurrentChanged(QListViewItem* item ) | 1013 | void OFileSelector::slotCurrentChanged(QListViewItem* item ) |
962 | { | 1014 | { |
963 | if( item == 0 ) | 1015 | if( item == 0 ) |
964 | return; | 1016 | return; |
965 | if( m_selector == EXTENDED || m_selector == EXTENDED_ALL ) { | 1017 | if( m_selector == EXTENDED || m_selector == EXTENDED_ALL ) { |
966 | OFileSelectorItem *sel = (OFileSelectorItem*) item; // start to use the C++ casts ;) | 1018 | OFileSelectorItem *sel = (OFileSelectorItem*) item; // start to use the C++ casts ;) |
967 | if(!sel->isDir() ){ | 1019 | if(!sel->isDir() ){ |
968 | if( m_shLne ) | 1020 | if( m_shLne ) |
969 | m_edit->setText( sel->text(1) ); | 1021 | m_edit->setText( sel->text(1) ); |
970 | } | 1022 | } |
971 | } | 1023 | } |
972 | } | 1024 | } |
973 | void OFileSelector::slotClicked( int button, QListViewItem *item, const QPoint &, int) | 1025 | void OFileSelector::slotClicked( int button, QListViewItem *item, const QPoint &, int) |
974 | { | 1026 | { |
975 | if ( item == 0 ) | 1027 | if ( item == 0 ) |
976 | return; | 1028 | return; |
977 | 1029 | ||
978 | if( button != Qt::LeftButton ) | 1030 | if( button != Qt::LeftButton ) |
979 | return; | 1031 | return; |
980 | 1032 | ||
981 | switch( m_selector ){ | 1033 | switch( m_selector ){ |
982 | default: | 1034 | default: |
983 | break; | 1035 | break; |
984 | case EXTENDED: // fall through | 1036 | case EXTENDED: // fall through |
985 | case EXTENDED_ALL:{ | 1037 | case EXTENDED_ALL:{ |
986 | OFileSelectorItem *sel = (OFileSelectorItem*)item; | 1038 | OFileSelectorItem *sel = (OFileSelectorItem*)item; |
987 | if(!sel->isLocked() ){ | 1039 | if(!sel->isLocked() ){ |
988 | QStringList str = QStringList::split("->", sel->text(1) ); | 1040 | QStringList str = QStringList::split("->", sel->text(1) ); |
989 | if( sel->isDir() ){ | 1041 | if( sel->isDir() ){ |
990 | cd( sel->directory() + "/" + str[0].stripWhiteSpace() ); | 1042 | cd( sel->directory() + "/" + str[0].stripWhiteSpace() ); |
991 | // if MODE Dir m_shLne set the Text | 1043 | // if MODE Dir m_shLne set the Text |
992 | }else{ | 1044 | }else{ |
993 | if( m_shLne ) | 1045 | if( m_shLne ) |
994 | m_edit->setText( str[0].stripWhiteSpace() ); | 1046 | m_edit->setText( str[0].stripWhiteSpace() ); |
995 | emit fileSelected( sel->directory() + "/" + str[0].stripWhiteSpace() ); | 1047 | emit fileSelected( sel->directory() + "/" + str[0].stripWhiteSpace() ); |
996 | } | 1048 | } |
997 | } | 1049 | } |
998 | break; | 1050 | break; |
999 | } | 1051 | } |
1000 | } | 1052 | } |
1001 | } | 1053 | } |
1002 | void OFileSelector::slotRightButton(int button, QListViewItem *item, const QPoint &, int ) | 1054 | void OFileSelector::slotRightButton(int button, QListViewItem *item, const QPoint &, int ) |
1003 | { | 1055 | { |
1004 | if( item == 0 ) | 1056 | if( item == 0 ) |
1005 | return; | 1057 | return; |
1006 | 1058 | ||
1007 | if( button != Qt::RightButton ) | 1059 | if( button != Qt::RightButton ) |
1008 | return; | 1060 | return; |
1009 | slotContextMenu( item ); | 1061 | slotContextMenu( item ); |
1010 | } | 1062 | } |
1011 | void OFileSelector::slotContextMenu( QListViewItem *item) | 1063 | void OFileSelector::slotContextMenu( QListViewItem *item) |
1012 | { | 1064 | { |
1013 | 1065 | ||
1014 | } | 1066 | } |
1015 | void OFileSelector::slotChangedDir() | 1067 | void OFileSelector::slotChangedDir() |
1016 | { | 1068 | { |
1017 | OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem(); | 1069 | OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem(); |
1018 | if(sel->isDir() ){ | 1070 | if(sel->isDir() ){ |
1019 | QStringList str = QStringList::split("->", sel->text(1) ); | 1071 | QStringList str = QStringList::split("->", sel->text(1) ); |
1020 | cd( sel->directory() + "/" + str[0].stripWhiteSpace() ); | 1072 | cd( sel->directory() + "/" + str[0].stripWhiteSpace() ); |
1021 | } | 1073 | } |
1022 | } | 1074 | } |
1023 | void OFileSelector::slotOpen() | 1075 | void OFileSelector::slotOpen() |
1024 | { | 1076 | { |
1025 | OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem(); | 1077 | OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem(); |
1026 | if(!sel->isDir() ){ | 1078 | if(!sel->isDir() ){ |
1027 | QStringList str = QStringList::split("->", sel->text(1) ); | 1079 | QStringList str = QStringList::split("->", sel->text(1) ); |
1028 | slotFileSelected( sel->directory() +"/" +str[0].stripWhiteSpace() ); | 1080 | slotFileSelected( sel->directory() +"/" +str[0].stripWhiteSpace() ); |
1029 | } | 1081 | } |
1030 | } | 1082 | } |
1031 | void OFileSelector::slotRescan() | 1083 | void OFileSelector::slotRescan() |
1032 | { | 1084 | { |
1033 | 1085 | ||
1034 | } | 1086 | } |
1035 | void OFileSelector::slotRename() | 1087 | void OFileSelector::slotRename() |
1036 | { | 1088 | { |
1037 | reparse(); | 1089 | reparse(); |
1038 | } | 1090 | } |
1039 | void OFileSelector::slotDelete() | 1091 | void OFileSelector::slotDelete() |
1040 | { | 1092 | { |
1041 | OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem(); | 1093 | OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem(); |
1042 | QStringList list = QStringList::split("->", sel->text(1) ); | 1094 | QStringList list = QStringList::split("->", sel->text(1) ); |
1043 | if( sel->isDir() ){ | 1095 | if( sel->isDir() ){ |
1044 | QString str = QString::fromLatin1("rm -rf ") + sel->directory() +"/" + list[0]; //better safe than sorry | 1096 | QString str = QString::fromLatin1("rm -rf ") + sel->directory() +"/" + list[0]; //better safe than sorry |
1045 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+list[0], | 1097 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+list[0], |
1046 | tr("Yes"),tr("No"),0,1,1) ) { | 1098 | tr("Yes"),tr("No"),0,1,1) ) { |
1047 | case 0: | 1099 | case 0: |
1048 | ::system(str.utf8().data() ); | 1100 | ::system(str.utf8().data() ); |
1049 | break; | 1101 | break; |
1050 | } | 1102 | } |
1051 | } else { | 1103 | } else { |
1052 | QFile::remove( list[0] ); | 1104 | QFile::remove( list[0] ); |
1053 | } | 1105 | } |
1054 | m_View->takeItem( sel ); | 1106 | m_View->takeItem( sel ); |
1055 | delete sel; | 1107 | delete sel; |
1056 | } | 1108 | } |
1057 | void OFileSelector::cdUP() | 1109 | void OFileSelector::cdUP() |
1058 | { | 1110 | { |
1059 | QDir dir( m_currentDir ); | 1111 | QDir dir( m_currentDir ); |
1060 | dir.cdUp(); | 1112 | dir.cdUp(); |
1061 | if(dir.exists() ){ | 1113 | if(dir.exists() ){ |
1062 | m_currentDir = dir.absPath(); | 1114 | m_currentDir = dir.absPath(); |
1063 | reparse(); | 1115 | reparse(); |
1064 | int count = m_location->count(); | 1116 | int count = m_location->count(); |
1065 | slotInsertLocationPath( m_currentDir, count); | 1117 | slotInsertLocationPath( m_currentDir, count); |
1066 | m_location->setCurrentItem( indexByString( m_location, m_currentDir)); | 1118 | m_location->setCurrentItem( indexByString( m_location, m_currentDir)); |
1067 | //this wont work in all instances | 1119 | //this wont work in all instances |
1068 | // FIXME | 1120 | // FIXME |
1069 | } | 1121 | } |
1070 | } | 1122 | } |
1071 | void OFileSelector::slotHome() | 1123 | void OFileSelector::slotHome() |
1072 | { | 1124 | { |
1073 | cd(QDir::homeDirPath() ); | 1125 | cd(QDir::homeDirPath() ); |
1074 | } | 1126 | } |
1075 | void OFileSelector::slotDoc() | 1127 | void OFileSelector::slotDoc() |
1076 | { | 1128 | { |
1077 | cd(QPEApplication::documentDir() ); | 1129 | cd(QPEApplication::documentDir() ); |
1078 | } | 1130 | } |
1079 | void OFileSelector::slotNavigate( ) | 1131 | void OFileSelector::slotNavigate( ) |
1080 | { | 1132 | { |
1081 | 1133 | ||
1082 | } | 1134 | } |
1083 | // fill the View with life | 1135 | // fill the View with life |
1084 | void OFileSelector::reparse() | 1136 | void OFileSelector::reparse() |
1085 | { | 1137 | { |
1086 | if( m_selector == NORMAL ) | 1138 | if( m_selector == NORMAL ) |
1087 | return; | 1139 | return; |
1088 | if( m_selector == EXTENDED || m_selector == EXTENDED_ALL ) | 1140 | if( m_selector == EXTENDED || m_selector == EXTENDED_ALL ) |
1089 | m_View->clear(); | 1141 | m_View->clear(); |
1090 | else // custom view | 1142 | else // custom view |
1091 | ; // currentView()->clear(); | 1143 | ; // currentView()->clear(); |
1092 | if( m_shChooser) | 1144 | if( m_shChooser) |
1093 | qWarning("reparse %s", m_mimeCheck->currentText().latin1() ); | 1145 | qWarning("reparse %s", m_mimeCheck->currentText().latin1() ); |
1094 | 1146 | ||
1095 | QString currentMimeType; | 1147 | QString currentMimeType; |
1096 | // let's update the mimetype | 1148 | // let's update the mimetype |
1097 | if( m_autoMime ){ | 1149 | if( m_autoMime ){ |
1098 | m_mimetypes.clear(); | 1150 | m_mimetypes.clear(); |
1099 | // ok we can change mimetype so we need to be able to give a selection | 1151 | // ok we can change mimetype so we need to be able to give a selection |
1100 | if( m_shChooser ) { | 1152 | if( m_shChooser ) { |
1101 | currentMimeType = m_mimeCheck->currentText(); | 1153 | currentMimeType = m_mimeCheck->currentText(); |
1102 | m_mimeCheck->clear(); | 1154 | m_mimeCheck->clear(); |
1103 | 1155 | ||
1104 | // let's find possible mimetypes | 1156 | // let's find possible mimetypes |
1105 | QDir dir( m_currentDir ); | 1157 | QDir dir( m_currentDir ); |
1106 | dir.setFilter( QDir::Files | QDir::Readable ); | 1158 | dir.setFilter( QDir::Files | QDir::Readable ); |
1107 | dir.setSorting( QDir::Size ); | 1159 | dir.setSorting( QDir::Size ); |
1108 | const QFileInfoList *list = dir.entryInfoList(); | 1160 | const QFileInfoList *list = dir.entryInfoList(); |
1109 | QFileInfoListIterator it( *list ); | 1161 | QFileInfoListIterator it( *list ); |
1110 | QFileInfo *fi; | 1162 | QFileInfo *fi; |
1111 | while( (fi=it.current() ) ) { | 1163 | while( (fi=it.current() ) ) { |
1112 | if( fi->extension() == QString::fromLatin1("desktop") ){ | 1164 | if( fi->extension() == QString::fromLatin1("desktop") ){ |
1113 | ++it; | 1165 | ++it; |
1114 | continue; | 1166 | continue; |
1115 | } | 1167 | } |
1116 | MimeType type( fi->absFilePath() ); | 1168 | MimeType type( fi->absFilePath() ); |
1117 | if( !m_mimetypes.contains( type.id() ) ){ | 1169 | if( !m_mimetypes.contains( type.id() ) ){ |
1118 | //qWarning("Type %s", type.id().latin1() ); | 1170 | //qWarning("Type %s", type.id().latin1() ); |
1119 | m_mimetypes.insert( type.id(), type.id() ); | 1171 | m_mimetypes.insert( type.id(), type.id() ); |
1120 | } | 1172 | } |
1121 | 1173 | ||
1122 | ++it; | 1174 | ++it; |
1123 | } | 1175 | } |
1124 | // add them to the chooser | 1176 | // add them to the chooser |
1125 | updateMimeCheck(); | 1177 | updateMimeCheck(); |
1126 | m_mimeCheck->setCurrentItem( indexByString( m_mimeCheck, currentMimeType ) ); | 1178 | m_mimeCheck->setCurrentItem( indexByString( m_mimeCheck, currentMimeType ) ); |
1127 | currentMimeType = m_mimeCheck->currentText(); | 1179 | currentMimeType = m_mimeCheck->currentText(); |
1128 | } | 1180 | } |
1129 | }else { // no autoMime | 1181 | }else { // no autoMime |
1130 | // let the mimetype be set from out side the m_mimeCheck FEATURE | 1182 | // let the mimetype be set from out side the m_mimeCheck FEATURE |
1131 | 1183 | ||
1132 | if( m_shChooser ){ | 1184 | if( m_shChooser ){ |
1133 | currentMimeType = m_mimeCheck->currentText(); | 1185 | currentMimeType = m_mimeCheck->currentText(); |
1134 | updateMimeCheck(); | 1186 | // updateMimeCheck(); |
1135 | } | 1187 | } |
1136 | } | 1188 | } |
1137 | // now we got our mimetypes we can add the files | 1189 | // now we got our mimetypes we can add the files |
1138 | 1190 | ||
1139 | QDir dir( m_currentDir ); | 1191 | QDir dir( m_currentDir ); |
1140 | 1192 | ||
1141 | int sort; | 1193 | int sort; |
1142 | if ( m_case ) | 1194 | if ( m_case ) |
1143 | sort = (QDir::IgnoreCase | QDir::Name | QDir::DirsFirst | QDir::Reversed); | 1195 | sort = (QDir::IgnoreCase | QDir::Name | QDir::DirsFirst | QDir::Reversed); |
1144 | else | 1196 | else |
1145 | sort = (QDir::Name | QDir::DirsFirst | QDir::Reversed); | 1197 | sort = (QDir::Name | QDir::DirsFirst | QDir::Reversed); |
1146 | dir.setSorting( sort ); | 1198 | dir.setSorting( sort ); |
1147 | 1199 | ||
1148 | int filter; | 1200 | int filter; |
1149 | if( m_selector == EXTENDED_ALL /*|| m_selector ==CUSTOM_ALL */ ){ | 1201 | if( m_selector == EXTENDED_ALL /*|| m_selector ==CUSTOM_ALL */ ){ |
1150 | filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; | 1202 | filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; |
1151 | }else | 1203 | }else |
1152 | filter = QDir::Files | QDir::Dirs | QDir::All; | 1204 | filter = QDir::Files | QDir::Dirs | QDir::All; |
1153 | dir.setFilter( filter ); | 1205 | dir.setFilter( filter ); |
1154 | 1206 | ||
1155 | // now go through all files | 1207 | // now go through all files |
1156 | const QFileInfoList *list = dir.entryInfoList(); | 1208 | const QFileInfoList *list = dir.entryInfoList(); |
1157 | QFileInfoListIterator it( *list ); | 1209 | QFileInfoListIterator it( *list ); |
1158 | QFileInfo *fi; | 1210 | QFileInfo *fi; |
1159 | while( (fi=it.current() ) ){ | 1211 | while( (fi=it.current() ) ){ |
1160 | //qWarning("True and only" ); | 1212 | //qWarning("True and only" ); |
1161 | if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ){ | 1213 | if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ){ |
1162 | //qWarning(".. or ." ); | 1214 | //qWarning(".. or ." ); |
1163 | ++it; | 1215 | ++it; |
1164 | continue; | 1216 | continue; |
1165 | } | 1217 | } |
1166 | if( fi->isSymLink() ){ | 1218 | if( fi->isSymLink() ){ |
1167 | QString file = fi->dirPath( true ) + "/" + fi->readLink(); | 1219 | QString file = fi->dirPath( true ) + "/" + fi->readLink(); |
1168 | for( int i = 0; i<=4; i++) { // 5 tries to prevent dos | 1220 | for( int i = 0; i<=4; i++) { // 5 tries to prevent dos |
1169 | QFileInfo info( file ); | 1221 | QFileInfo info( file ); |
1170 | if( !info.exists() ){ | 1222 | if( !info.exists() ){ |
1171 | addSymlink( currentMimeType, fi, TRUE ); | 1223 | addSymlink( currentMimeType, fi, TRUE ); |
1172 | break; | 1224 | break; |
1173 | }else if( info.isDir() ){ | 1225 | }else if( info.isDir() ){ |
1174 | addDir( currentMimeType, fi, TRUE ); | 1226 | addDir( currentMimeType, fi, TRUE ); |
1175 | break; | 1227 | break; |
1176 | }else if( info.isFile() ){ | 1228 | }else if( info.isFile() ){ |
1177 | addFile( currentMimeType, fi, TRUE ); | 1229 | addFile( currentMimeType, fi, TRUE ); |
1178 | break; | 1230 | break; |
1179 | }else if( info.isSymLink() ){ | 1231 | }else if( info.isSymLink() ){ |
1180 | file = info.dirPath(true ) + "/" + info.readLink() ; | 1232 | file = info.dirPath(true ) + "/" + info.readLink() ; |
1181 | break; | 1233 | break; |
1182 | }else if( i == 4){ | 1234 | }else if( i == 4){ |
1183 | addSymlink( currentMimeType, fi ); | 1235 | addSymlink( currentMimeType, fi ); |
1184 | } | 1236 | } |
1185 | } // off for loop | 1237 | } // off for loop |
1186 | }else if( fi->isDir() ){ | 1238 | }else if( fi->isDir() ){ |
1187 | addDir( currentMimeType, fi ); | 1239 | addDir( currentMimeType, fi ); |
1188 | }else if( fi->isFile() ){ | 1240 | }else if( fi->isFile() ){ |
1189 | addFile( currentMimeType, fi ); | 1241 | addFile( currentMimeType, fi ); |
1190 | } | 1242 | } |
1191 | //qWarning( "%s", fi->fileName().latin1() ); | 1243 | //qWarning( "%s", fi->fileName().latin1() ); |
1192 | ++it; | 1244 | ++it; |
1193 | } // of while loop | 1245 | } // of while loop |
1194 | m_View->sort(); | 1246 | m_View->sort(); |
1195 | if( m_shTool ){ | 1247 | if( m_shTool ){ |
1196 | m_location->insertItem( m_currentDir ); | 1248 | m_location->insertItem( m_currentDir ); |
1197 | 1249 | ||
1198 | } | 1250 | } |
1199 | // reenable painting and updates | 1251 | // reenable painting and updates |
1200 | } | 1252 | } |