summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/TODO17
-rw-r--r--libopie/ofileselector.cc191
-rw-r--r--libopie/ofileselector.h37
3 files changed, 233 insertions, 12 deletions
diff --git a/libopie/TODO b/libopie/TODO
new file mode 100644
index 0000000..c1bf6d1
--- a/dev/null
+++ b/libopie/TODO
@@ -0,0 +1,17 @@
1- xmltree done
2
3- tododb
4 - set Alarms
5 - multiple categories
6 - Attendees
7
8- OFileSelector
9 - DocLnk when not in Document Mode
10 - TreeView have a own OFileSelectorItem for this
11 - IconView add a QIconView to the widgetstack
12 - Move OFileSelectorItem to it's own files
13 - add functions to access the member variables
14 - debug
15
16- Clickable labels?
17 Harlekin you wanted them in the libs? \ No newline at end of file
diff --git a/libopie/ofileselector.cc b/libopie/ofileselector.cc
index 128292f..b583125 100644
--- a/libopie/ofileselector.cc
+++ b/libopie/ofileselector.cc
@@ -1,717 +1,900 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> 3             .=l. Copyright (c) 2002 Holger Freyther <zecke@handhelds.org>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can 5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under 6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License, 9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version. 10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_. 11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that 12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details. 18++=   -.     .`     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB. 22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#include <qnamespace.h> 29#include <qnamespace.h>
30#include <qpushbutton.h> 30#include <qpushbutton.h>
31#include <qcombobox.h> 31#include <qcombobox.h>
32#include <qhbox.h> 32#include <qhbox.h>
33#include <qvbox.h> 33#include <qvbox.h>
34#include <qlayout.h> 34#include <qlayout.h>
35#include <qwidgetstack.h> 35#include <qwidgetstack.h>
36#include <qlineedit.h> 36#include <qlineedit.h>
37#include <qcheckbox.h> 37#include <qcheckbox.h>
38#include <qlabel.h> 38#include <qlabel.h>
39#include <qheader.h> 39#include <qheader.h>
40#include <qdir.h> 40#include <qdir.h>
41#include <qpainter.h> 41#include <qpainter.h>
42#include <qaction.h>
43#include <qpopupmenu.h>
44#include <qcursor.h>
42 45
43#include <qpe/qpeapplication.h> 46#include <qpe/qpeapplication.h>
44#include <qpe/fileselector.h> 47#include <qpe/fileselector.h>
45#include <qpe/applnk.h> 48#include <qpe/applnk.h>
46#include <qpe/global.h> 49#include <qpe/global.h>
47#include <qpe/mimetype.h> 50#include <qpe/mimetype.h>
48#include <qpe/resource.h> 51#include <qpe/resource.h>
49 52
53#include <unistd.h>
54#include <stdlib.h>
55#include <sys/stat.h>
56
50#include "ofileselector.h" 57#include "ofileselector.h"
51 58
52QMap<QString,QPixmap> *OFileSelector::m_pixmaps = 0; 59QMap<QString,QPixmap> *OFileSelector::m_pixmaps = 0;
53 60
54namespace { 61namespace {
55 62
56 int indexByString( const QComboBox *box, const QString &str ){ 63 int indexByString( const QComboBox *box, const QString &str ){
57 int index= -1; 64 int index= -1;
58 for(int i= 0; i < box->count(); i++ ){ 65 for(int i= 0; i < box->count(); i++ ){
59 qWarning("str T%sT boxT%sT", str.latin1(), box->text(i).latin1() ); 66 qWarning("str T%sT boxT%sT", str.latin1(), box->text(i).latin1() );
60 if( str == box->text(i ) ){ 67 if( str == box->text(i ) ){
61 index= i; 68 index= i;
62 break; 69 break;
63 } 70 }
64 } 71 }
65 return index; 72 return index;
66 } 73 }
67 74
68}; 75};
69 76
70 77
71OFileSelector::OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName, 78OFileSelector::OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName,
72 const QString &fileName, const QStringList mimetypes ) : QWidget( wid ) 79 const QString &fileName, const QStringList mimetypes ) : QWidget( wid )
73{ 80{
74 m_selector = selector; 81 m_selector = selector;
75 m_currentDir = dirName; 82 m_currentDir = dirName;
76 m_name = fileName; 83 m_name = fileName;
77 m_mimetypes = mimetypes; 84 m_mimetypes = mimetypes;
78 if( mimetypes.isEmpty() ) 85 if( mimetypes.isEmpty() )
79 m_autoMime = true; 86 m_autoMime = true;
80 87
81 m_mode = mode; 88 m_mode = mode;
82 m_shTool = true; 89 m_shTool = true;
83 m_shPerm = true; 90 m_shPerm = true;
84 m_shLne = true; 91 m_shLne = true;
85 m_shChooser = true; 92 m_shChooser = true;
86 m_shYesNo = true; 93 m_shYesNo = true;
87 // for FILESELECTOR only view is interesting 94 // for FILESELECTOR only view is interesting
88 m_location = 0; 95 m_location = 0;
89 m_homeButton = 0; 96 m_homeButton = 0;
90 m_docButton = 0; 97 m_docButton = 0;
91 m_hideButton = 0; 98 m_hideButton = 0;
92 m_ok = 0; 99 m_ok = 0;
93 m_cancel = 0; 100 m_cancel = 0;
94 m_reread = 0; 101 m_reread = 0;
95 m_up = 0; 102 m_up = 0;
96 m_View = 0; 103 m_View = 0;
97 m_select = 0; 104 m_select = 0;
98 m_stack = 0; 105 m_stack = 0;
99 106
100 m_select = 0; 107 m_select = 0;
101 m_stack = 0; 108 m_stack = 0;
102 m_lay = 0; 109 m_lay = 0;
103 m_boxToolbar = 0; 110 m_boxToolbar = 0;
104 m_boxOk = 0; 111 m_boxOk = 0;
105 m_edit = 0; 112 m_edit = 0;
106 113
107 m_fnLabel = 0; 114 m_fnLabel = 0;
108 m_checkPerm = 0; 115 m_checkPerm = 0;
109 m_mimeCheck = 0; 116 m_mimeCheck = 0;
110 m_viewCheck = 0; 117 m_viewCheck = 0;
111 118
112 m_dir = true; 119 m_dir = true;
113 m_files = true; 120 m_files = true;
121 m_custom = 0;
114 122
115 if(m_pixmaps == 0 ) // init the pixmaps 123 if(m_pixmaps == 0 ) // init the pixmaps
116 initPics(); 124 initPics();
117 125
118 m_lay = new QVBoxLayout(this); 126 m_lay = new QVBoxLayout(this);
119 init(); 127 init();
120 m_edit->setText( fileName ); 128 m_edit->setText( fileName );
121} 129}
122void OFileSelector::initPics() 130void OFileSelector::initPics()
123{ 131{
124 qWarning("init pics" ); 132 qWarning("init pics" );
125 m_pixmaps = new QMap<QString,QPixmap>; 133 m_pixmaps = new QMap<QString,QPixmap>;
126 QPixmap pm = Resource::loadPixmap( "folder" ); 134 QPixmap pm = Resource::loadPixmap( "folder" );
127 QPixmap lnk = Resource::loadPixmap( "symlink" ); 135 QPixmap lnk = Resource::loadPixmap( "symlink" );
128 QPainter painter( &pm ); 136 QPainter painter( &pm );
129 painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); 137 painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk );
130 pm.setMask( pm.createHeuristicMask( FALSE ) ); 138 pm.setMask( pm.createHeuristicMask( FALSE ) );
131 m_pixmaps->insert("dirsymlink", pm ); 139 m_pixmaps->insert("dirsymlink", pm );
132 140
133 QPixmap pm2 = Resource::loadPixmap( "lockedfolder" ); 141 QPixmap pm2 = Resource::loadPixmap( "lockedfolder" );
134 QPainter pen(&pm2 ); 142 QPainter pen(&pm2 );
135 pen.drawPixmap(pm2.width()-lnk.width(), pm2.height()-lnk.height(), lnk ); 143 pen.drawPixmap(pm2.width()-lnk.width(), pm2.height()-lnk.height(), lnk );
136 pm2.setMask( pm2.createHeuristicMask( FALSE ) ); 144 pm2.setMask( pm2.createHeuristicMask( FALSE ) );
137 m_pixmaps->insert("symlinkedlocked", pm2 ); 145 m_pixmaps->insert("symlinkedlocked", pm2 );
138 146
139}; 147};
140// let's initialize the gui 148// let's initialize the gui
141/** 149/**
142 -------------------- 150 --------------------
143 | cmbBox Button | 151 | cmbBox Button |
144 -------------------- 152 --------------------
145 | FileSlector | 153 | FileSlector |
146 | or | 154 | or |
147 | OSelector | 155 | OSelector |
148 | | 156 | |
149 | | 157 | |
150 ____________________ 158 ____________________
151 | LineEdit | 159 | LineEdit |
152 ____________________ 160 ____________________
153 | Permission Bar | 161 | Permission Bar |
154 ____________________ 162 ____________________
155 | ViewChoose | 163 | ViewChoose |
156 ____________________ 164 ____________________
157 | Save Cancel| 165 | Save Cancel|
158 ____________________ 166 ____________________
159 */ 167 */
160void OFileSelector::delItems() 168void OFileSelector::delItems()
161{ 169{
162 QLayoutIterator it = m_lay->iterator(); 170 QLayoutIterator it = m_lay->iterator();
163 while ( it.current() != 0 ){ 171 while ( it.current() != 0 ){
164 it.deleteCurrent(); 172 it.deleteCurrent();
165 } 173 }
166} 174}
167void OFileSelector::init() 175void OFileSelector::init()
168{ 176{
169 177
170 m_stack = new QWidgetStack(this, "wstack" ); 178 m_stack = new QWidgetStack(this, "wstack" );
171 if( m_selector == NORMAL ){ 179 if( m_selector == NORMAL ){
172 QString currMime; 180 QString currMime;
173 if( m_mimeCheck != 0 ) 181 if( m_mimeCheck != 0 )
174 currMime = m_mimeCheck->currentText(); 182 currMime = m_mimeCheck->currentText();
175 183
176 updateMimes(); 184 updateMimes();
177 m_select = new FileSelector( currMime == "All" ? QString::null : currMime , m_stack, "fileselector", FALSE, FALSE ); 185 m_select = new FileSelector( currMime == "All" ? QString::null : currMime , m_stack, "fileselector", FALSE, FALSE );
178 m_stack->addWidget(m_select, NORMAL ); 186 m_stack->addWidget(m_select, NORMAL );
179 m_lay->addWidget(m_stack ); 187 m_lay->addWidget(m_stack );
180 m_stack->raiseWidget(NORMAL ); 188 m_stack->raiseWidget(NORMAL );
189 connect(m_select, SIGNAL(fileSelected( const DocLnk &) ), this, SLOT(slotFileBridgeSelected(const DocLnk &) ) );
181 }else { 190 }else {
182 initializeListView(); 191 initializeListView();
183 } 192 }
184 193
185 if(m_shLne ){ 194 if(m_shLne ){
186 initializeName(); 195 initializeName();
187 } 196 }
188 197
189 if(m_shPerm ){ 198 if(m_shPerm ){
190 m_checkPerm = new QCheckBox(tr("Set Permission"), this, "Permission" ); 199 m_checkPerm = new QCheckBox(tr("Set Permission"), this, "Permission" );
191 m_checkPerm->setChecked( false ); 200 m_checkPerm->setChecked( false );
192 m_lay->addWidget(m_checkPerm ); 201 m_lay->addWidget(m_checkPerm );
193 } 202 }
194 203
195 if( m_shChooser ) 204 if( m_shChooser )
196 initializeChooser(); 205 initializeChooser();
197 206
198 if(m_shYesNo ) 207 if(m_shYesNo )
199 initializeYes(); 208 initializeYes();
200 209
201 210
202}; 211};
203 212
204void OFileSelector::setYesCancelVisible( bool show ) 213void OFileSelector::setYesCancelVisible( bool show )
205{ 214{
206 if ( show == m_shYesNo ) 215 if ( show == m_shYesNo )
207 return; 216 return;
208 m_shYesNo = show; 217 m_shYesNo = show;
209 if( !show ){ 218 if( !show ){
210 delete m_ok; 219 delete m_ok;
211 delete m_cancel; 220 delete m_cancel;
212 m_ok = 0; 221 m_ok = 0;
213 m_cancel = 0; 222 m_cancel = 0;
214 // delete m_boxOk; all ready deleted in delItems 223 // delete m_boxOk; all ready deleted in delItems
215 } 224 }
216 updateLay(); // recreate it and save the other states 225 updateLay(); // recreate it and save the other states
217} 226}
218 227
219void OFileSelector::setToolbarVisible( bool show ) 228void OFileSelector::setToolbarVisible( bool show )
220{ 229{
221 if ( m_shTool == show ) 230 if ( m_shTool == show )
222 return; 231 return;
223 /* if( show ){ 232 /* if( show ){
224 233
225 }else { 234 }else {
226 235
227 }*/ 236 }*/
228} 237}
229 238
230void OFileSelector::setPermissionBarVisible( bool show ) 239void OFileSelector::setPermissionBarVisible( bool show )
231{ 240{
232 if( show == m_shPerm ) 241 if( show == m_shPerm )
233 return; 242 return;
234 243
235 m_shPerm = show; 244 m_shPerm = show;
236 245
237 updateLay(); 246 updateLay();
238} 247}
239void OFileSelector::setLineEditVisible( bool show ) 248void OFileSelector::setLineEditVisible( bool show )
240{ 249{
241 if( show == m_shLne ) 250 if( show == m_shLne )
242 return; 251 return;
243 252
244 m_shLne = show; 253 m_shLne = show;
245 if( !show ){ 254 if( !show ){
246 delete m_edit; 255 delete m_edit;
247 delete m_fnLabel; 256 delete m_fnLabel;
248 m_edit = 0; 257 m_edit = 0;
249 m_fnLabel = 0; 258 m_fnLabel = 0;
250 //delete m_boxName; will be deleted 259 //delete m_boxName; will be deleted
251 } 260 }
252 updateLay(); 261 updateLay();
253} 262}
254void OFileSelector::setChooserVisible( bool show ) 263void OFileSelector::setChooserVisible( bool show )
255{ 264{
256 if( show = m_shChooser ) 265 if( show = m_shChooser )
257 return; 266 return;
258 m_shChooser = show; 267 m_shChooser = show;
259 if( !show ){ 268 if( !show ){
260 delete m_mimeCheck; 269 delete m_mimeCheck;
261 delete m_viewCheck; 270 delete m_viewCheck;
262 m_mimeCheck = 0; 271 m_mimeCheck = 0;
263 m_viewCheck = 0; 272 m_viewCheck = 0;
264 } 273 }
265 updateLay(); 274 updateLay();
266} 275}
267QCheckBox* OFileSelector::permissionCheckbox( ) 276QCheckBox* OFileSelector::permissionCheckbox( )
268{ 277{
269 return m_checkPerm; 278 return m_checkPerm;
270} 279}
271void OFileSelector::setCaseSensetive( bool caSe ) 280void OFileSelector::setCaseSensetive( bool caSe )
272{ 281{
273 m_case = caSe; 282 m_case = caSe;
274 reparse(); 283 reparse();
275} 284}
276void OFileSelector::setShowFiles(bool files ){ 285void OFileSelector::setShowFiles(bool files ){
277 m_files = files; 286 m_files = files;
278 reparse(); 287 reparse();
279} 288}
280void OFileSelector::setPopupMenu(const QPopupMenu * ) 289void OFileSelector::setPopupMenu(QPopupMenu *pop )
281{ 290{
282 //delete oldpopup; 291 //delete oldpopup;
283 292 m_custom = pop;
284} 293}
285bool OFileSelector::setPermission( ) const 294bool OFileSelector::setPermission( ) const
286{ 295{
287 if( m_checkPerm == 0 ) 296 if( m_checkPerm == 0 )
288 return false; 297 return false;
289 else 298 else
290 return m_checkPerm->isChecked(); 299 return m_checkPerm->isChecked();
291} 300}
292void OFileSelector::setPermissionChecked( bool check ) 301void OFileSelector::setPermissionChecked( bool check )
293{ 302{
294 if( m_checkPerm == 0 ) 303 if( m_checkPerm == 0 )
295 return; 304 return;
296 m_checkPerm->setChecked( check ); 305 m_checkPerm->setChecked( check );
297} 306}
298QString OFileSelector::selectedName( )const 307QString OFileSelector::selectedName( )const
299{ 308{
300 QString string; 309 QString string;
301 if( m_selector == NORMAL ){ 310 if( m_selector == NORMAL ){
302 const DocLnk *lnk = m_select->selected(); 311 const DocLnk *lnk = m_select->selected();
303 string = lnk->file(); 312 string = lnk->file();
304 }else if(m_selector == EXTENDED || m_selector == EXTENDED_ALL ) { 313 }else if(m_selector == EXTENDED || m_selector == EXTENDED_ALL ) {
305 QListViewItem *item = m_View->currentItem(); 314 QListViewItem *item = m_View->currentItem();
306 if(item != 0 ){ 315 if(item != 0 ){
307 string = item->text( 1 ); 316 string = item->text( 1 );
308 } 317 }
309 } 318 }
310 return string; 319 return string;
311} 320}
312QStringList OFileSelector::selectedNames()const 321QStringList OFileSelector::selectedNames()const
313{ 322{
314 QStringList list; 323 QStringList list;
315 return list; 324 return list;
316} 325}
317DocLnk OFileSelector::selectedDocument( )const 326DocLnk OFileSelector::selectedDocument( )const
318{ 327{
319 DocLnk lnk; 328 DocLnk lnk;
320 return lnk; 329 return lnk;
321} 330}
322void OFileSelector::updateLay() 331void OFileSelector::updateLay()
323{ 332{
324 /* if( m_shTool ) 333 /* if( m_shTool )
325 // 334 //
326 else 335 else
327 // hide 336 // hide
328 */ 337 */
329 // save the state 338 // save the state
330 bool check = false; 339 bool check = false;
331 if( m_checkPerm != 0 ) 340 if( m_checkPerm != 0 )
332 check = m_checkPerm->isChecked(); 341 check = m_checkPerm->isChecked();
333 QString text; 342 QString text;
334 343
335 if( m_edit != 0 ) 344 if( m_edit != 0 )
336 text = m_edit->text(); 345 text = m_edit->text();
337 // save current mimetype 346 // save current mimetype
338 347
339 delItems(); 348 delItems();
340 delete m_checkPerm; 349 delete m_checkPerm;
341 m_checkPerm = 0; 350 m_checkPerm = 0;
342 delete m_edit; 351 delete m_edit;
343 m_edit = 0; 352 m_edit = 0;
344 delete m_fnLabel; 353 delete m_fnLabel;
345 m_fnLabel = 0; 354 m_fnLabel = 0;
346 delete m_ok; 355 delete m_ok;
347 m_ok = 0; 356 m_ok = 0;
348 delete m_cancel; 357 delete m_cancel;
349 m_cancel = 0; 358 m_cancel = 0;
350 delete m_mimeCheck; 359 delete m_mimeCheck;
351 m_mimeCheck = 0; 360 m_mimeCheck = 0;
352 delete m_viewCheck; 361 delete m_viewCheck;
353 m_viewCheck = 0; 362 m_viewCheck = 0;
354 delete m_select; // test 363 delete m_select; // test
355 delete m_stack; 364 delete m_stack;
356 //delete m_list; 365 //delete m_list;
357 init(); 366 init();
358 if( m_shLne ) 367 if( m_shLne )
359 m_edit->setText(text ); 368 m_edit->setText(text );
360 if( m_shPerm ) 369 if( m_shPerm )
361 m_checkPerm->setChecked(check ); 370 m_checkPerm->setChecked(check );
362} 371}
363// let's update the mimetypes. Use the current mimefilter for the 2nd QDir retrieve 372// let's update the mimetypes. Use the current mimefilter for the 2nd QDir retrieve
364// insert QListViewItems with the right options 373// insert QListViewItems with the right options
365bool OFileSelector::compliesMime(const QString &path, const QString &mime ) 374bool OFileSelector::compliesMime(const QString &path, const QString &mime )
366{ 375{
367 if( mime == "All" ) 376 if( mime == "All" )
368 return true; 377 return true;
369 MimeType type( path ); 378 MimeType type( path );
370 if( type.id() == mime ) 379 if( type.id() == mime )
371 return true; 380 return true;
372 return false; 381 return false;
373} 382}
374 383
375void OFileSelector::reparse() 384void OFileSelector::reparse()
376{ 385{
377 if(m_View== 0 || m_selector == NORMAL) 386 if(m_View== 0 || m_selector == NORMAL)
378 return; 387 return;
379 388
380 m_View->clear(); 389 m_View->clear();
381 390
382 391
383 QString currMime =m_mimeCheck->currentText(); 392 QString currMime =m_mimeCheck->currentText();
384 // update the mimetype now 393 // update the mimetype now
385 if( m_autoMime ) { 394 if( m_autoMime ) {
386 QDir dir( m_currentDir ); 395 QDir dir( m_currentDir );
387 m_mimetypes.clear(); 396 m_mimetypes.clear();
388 m_mimeCheck->clear(); 397 m_mimeCheck->clear();
389 dir.setFilter( QDir::Files | QDir::Readable ); 398 dir.setFilter( QDir::Files | QDir::Readable );
390 dir.setSorting(QDir::Size ); 399 dir.setSorting(QDir::Size );
391 const QFileInfoList *list = dir.entryInfoList(); 400 const QFileInfoList *list = dir.entryInfoList();
392 QFileInfoListIterator it( *list ); 401 QFileInfoListIterator it( *list );
393 QFileInfo *fi; 402 QFileInfo *fi;
394 while( (fi=it.current()) ){ 403 while( (fi=it.current()) ){
395 if(fi->extension() == QString::fromLatin1("desktop") ){ 404 if(fi->extension() == QString::fromLatin1("desktop") ){
396 ++it; 405 ++it;
397 continue; 406 continue;
398 } 407 }
399 MimeType type(fi->filePath() ); 408 MimeType type(fi->filePath() );
400 if( !m_mimetypes.contains( type.id() ) ) 409 if( !m_mimetypes.contains( type.id() ) )
401 m_mimetypes.append( type.id() ); 410 m_mimetypes.append( type.id() );
402 411
403 ++it; 412 ++it;
404 } 413 }
405 m_mimetypes.prepend("All" ); 414 m_mimetypes.prepend("All" );
406 m_mimeCheck->insertStringList(m_mimetypes ); 415 m_mimeCheck->insertStringList(m_mimetypes );
407 // set it to the current mimetype 416 // set it to the current mimetype
408 m_mimeCheck->setCurrentItem( indexByString( m_mimeCheck, currMime ) ); 417 m_mimeCheck->setCurrentItem( indexByString( m_mimeCheck, currMime ) );
409 }; 418 };
410 QDir dir( m_currentDir ); 419 QDir dir( m_currentDir );
411 //dir.setFilter(-1 ); 420 //dir.setFilter(-1 );
412 dir.setSorting(QDir::Name | QDir::DirsFirst | QDir::Reversed | QDir::IgnoreCase ); 421 dir.setSorting(QDir::Name | QDir::DirsFirst | QDir::Reversed | QDir::IgnoreCase );
413 const QFileInfoList *list = dir.entryInfoList(); 422 const QFileInfoList *list = dir.entryInfoList();
414 QFileInfoListIterator it( *list ); 423 QFileInfoListIterator it( *list );
415 QFileInfo *fi; 424 QFileInfo *fi;
416 while( (fi=it.current()) ){ 425 while( (fi=it.current()) ){
417 if(fi->fileName() == ".." || fi->fileName() == "." ){ 426 if(fi->fileName() == ".." || fi->fileName() == "." ){
418 ++it; 427 ++it;
419 continue; 428 continue;
420 } 429 }
421 qWarning("Test: %s", fi->fileName().latin1() ); 430 qWarning("Test: %s", fi->fileName().latin1() );
422 if(fi->isSymLink() ){ 431 if(fi->isSymLink() ){
423 qWarning("Symlink %s", fi->fileName().latin1() ); 432 qWarning("Symlink %s", fi->fileName().latin1() );
424 QString file = fi->dirPath(true)+"/"+ fi->readLink(); 433 QString file = fi->dirPath(true)+"/"+ fi->readLink();
425 qWarning("File ->%s", file.latin1() ); 434 qWarning("File ->%s", file.latin1() );
426 for(int i=0; i<=4; i++ ){ // prepend from dos 435 for(int i=0; i<=4; i++ ){ // prepend from dos
427 QFileInfo info( file ); 436 QFileInfo info( file );
428 if( !info.exists() ){ 437 if( !info.exists() ){
429 qWarning("does not exist" ); 438 qWarning("does not exist" );
430 addSymlink(currMime, fi, TRUE ); 439 addSymlink(currMime, fi, TRUE );
431 break; 440 break;
432 }else if( info.isDir() ){ 441 }else if( info.isDir() ){
433 qWarning("isDir" ); 442 qWarning("isDir" );
434 addDir(currMime, fi, TRUE ); 443 addDir(currMime, fi, TRUE );
435 break; 444 break;
436 }else if( info.isFile() ){ 445 }else if( info.isFile() ){
437 qWarning("isFile" ); 446 qWarning("isFile" );
438 addFile(currMime, fi, TRUE ); 447 addFile(currMime, fi, TRUE );
439 break; 448 break;
440 }else if( info.isSymLink() ){ 449 }else if( info.isSymLink() ){
441 file = info.dirPath(true)+ "/"+ info.readLink(); 450 file = info.dirPath(true)+ "/"+ info.readLink();
442 qWarning("isSymlink again %s", file.latin1() ); 451 qWarning("isSymlink again %s", file.latin1() );
443 }else if( i == 4 ){ // just insert it and have the symlink symbol 452 }else if( i == 4 ){ // just insert it and have the symlink symbol
444 addSymlink(currMime, fi ); 453 addSymlink(currMime, fi );
445 qWarning("level too deep" ); 454 qWarning("level too deep" );
446 } 455 }
447 } 456 }
448 }else if( fi->isDir() ){ 457 }else if( fi->isDir() ){
449 addDir(currMime, fi ); 458 addDir(currMime, fi );
450 }else if( fi->isFile() ) { // file ? 459 }else if( fi->isFile() ) { // file ?
451 addFile(currMime, fi ); 460 addFile(currMime, fi );
452 } 461 }
453 ++it; 462 ++it;
454 } 463 }
455 m_View->sort(); 464 m_View->sort();
456} 465}
457QString OFileSelector::directory()const 466QString OFileSelector::directory()const
458{ 467{
459 return m_currentDir; 468 return m_currentDir;
460} 469}
461int OFileSelector::fileCount() 470int OFileSelector::fileCount()
462{ 471{
463 return 0; 472 return 0;
464} 473}
465void OFileSelector::slotOk( ) 474void OFileSelector::slotOk( )
466{ 475{
467 emit ok(); 476 emit ok();
468} 477}
469void OFileSelector::slotCancel( ) 478void OFileSelector::slotCancel( )
470{ 479{
471 emit cancel(); 480 emit cancel();
472} 481}
473 482
474void OFileSelector::initializeName() 483void OFileSelector::initializeName()
475{ 484{
476 m_boxName = new QHBoxLayout(this ); 485 m_boxName = new QHBoxLayout(this );
477 m_edit = new QLineEdit(this ); 486 m_edit = new QLineEdit(this );
478 m_fnLabel = new QLabel(this ); 487 m_fnLabel = new QLabel(this );
479 m_fnLabel->setText(tr("Name:") ); 488 m_fnLabel->setText(tr("Name:") );
480 m_boxName->addWidget(m_fnLabel ); 489 m_boxName->addWidget(m_fnLabel );
481 m_boxName->insertSpacing(1, 8 ); 490 m_boxName->insertSpacing(1, 8 );
482 m_boxName->addWidget(m_edit, 100 ); 491 m_boxName->addWidget(m_edit, 100 );
483 492
484 m_lay->addLayout(m_boxName); 493 m_lay->addLayout(m_boxName);
485} 494}
486void OFileSelector::initializeYes() 495void OFileSelector::initializeYes()
487{ 496{
488 m_ok = new QPushButton("&Save", this, "save" ); 497 m_ok = new QPushButton("&Save", this, "save" );
489 m_cancel = new QPushButton("C&ancel", this, "cancel" ); 498 m_cancel = new QPushButton("C&ancel", this, "cancel" );
490 m_boxOk = new QHBoxLayout(this ); 499 m_boxOk = new QHBoxLayout(this );
491 m_boxOk->addWidget( m_ok, Qt::AlignHCenter ); 500 m_boxOk->addWidget( m_ok, Qt::AlignHCenter );
492 m_boxOk->insertSpacing(1, 8 ); 501 m_boxOk->insertSpacing(1, 8 );
493 m_boxOk->addWidget( m_cancel, Qt::AlignHCenter); 502 m_boxOk->addWidget( m_cancel, Qt::AlignHCenter);
494 m_lay->addLayout(m_boxOk ); 503 m_lay->addLayout(m_boxOk );
495 connect(m_ok, SIGNAL(clicked() ), 504 connect(m_ok, SIGNAL(clicked() ),
496 this, SLOT(slotOk() ) ); 505 this, SLOT(slotOk() ) );
497 connect(m_cancel, SIGNAL(clicked() ), 506 connect(m_cancel, SIGNAL(clicked() ),
498 this, SLOT(slotCancel() ) ); 507 this, SLOT(slotCancel() ) );
499 508
500} 509}
501void OFileSelector::initializeChooser() 510void OFileSelector::initializeChooser()
502{ 511{
503 m_boxView = new QHBoxLayout(this ); 512 m_boxView = new QHBoxLayout(this );
504 513
505 m_mimeCheck = new QComboBox(this, "mime check"); 514 m_mimeCheck = new QComboBox(this, "mime check");
506 m_viewCheck = new QComboBox(this, "view check"); 515 m_viewCheck = new QComboBox(this, "view check");
507 m_boxView->addWidget(m_viewCheck, 0 ); 516 m_boxView->addWidget(m_viewCheck, 0 );
508 m_boxView->insertSpacing(1, 8 ); 517 m_boxView->insertSpacing(1, 8 );
509 m_boxView->addWidget(m_mimeCheck, 0 ); 518 m_boxView->addWidget(m_mimeCheck, 0 );
510 m_lay->addLayout(m_boxView ); 519 m_lay->addLayout(m_boxView );
511 520
512 m_viewCheck->insertItem(tr("Documents") ); 521 m_viewCheck->insertItem(tr("Documents") );
513 m_viewCheck->insertItem(tr("Files") ); 522 m_viewCheck->insertItem(tr("Files") );
514 m_viewCheck->insertItem(tr("All Files") ); 523 m_viewCheck->insertItem(tr("All Files") );
515 524
516 if(!m_autoMime ) 525 if(!m_autoMime )
517 m_mimeCheck->insertItem(m_mimetypes.join("," ) ); 526 m_mimeCheck->insertItem(m_mimetypes.join("," ) );
518 else{ // check 527 else{ // check
519 updateMimes(); 528 updateMimes();
520 m_mimeCheck->insertStringList( m_mimetypes ); 529 m_mimeCheck->insertStringList( m_mimetypes );
521 } 530 }
522 531
523 connect( m_viewCheck, SIGNAL(activated(const QString &) ), 532 connect( m_viewCheck, SIGNAL(activated(const QString &) ),
524 this, SLOT(slotViewCheck(const QString & ) ) ); 533 this, SLOT(slotViewCheck(const QString & ) ) );
525 534
526 connect( m_mimeCheck, SIGNAL(activated(const QString &) ), 535 connect( m_mimeCheck, SIGNAL(activated(const QString &) ),
527 this, SLOT(slotMimeCheck(const QString & ) ) ); 536 this, SLOT(slotMimeCheck(const QString & ) ) );
528} 537}
529void OFileSelector::slotMimeCheck(const QString &view ){ 538void OFileSelector::slotMimeCheck(const QString &view ){
530 if(m_selector == NORMAL ){ 539 if(m_selector == NORMAL ){
531 delete m_select; 540 delete m_select;
532 m_select = new FileSelector(view == "All" ? QString::null : view 541 m_select = new FileSelector(view == "All" ? QString::null : view
533 , m_stack, "fileselector", FALSE, FALSE ); 542 , m_stack, "fileselector", FALSE, FALSE );
534 m_stack->addWidget( m_select, NORMAL ); 543 m_stack->addWidget( m_select, NORMAL );
535 m_stack->raiseWidget( NORMAL ); 544 m_stack->raiseWidget( NORMAL );
536 }else{ 545 }else{
537 reparse(); 546 reparse();
538 } 547 }
539} 548}
540 549
541void OFileSelector::slotViewCheck(const QString &view ){ 550void OFileSelector::slotViewCheck(const QString &view ){
542 qWarning("changed: show %s", view.latin1() ); 551 qWarning("changed: show %s", view.latin1() );
543 // if the current view is the one 552 // if the current view is the one
544 QString currMime = m_mimeCheck->currentText(); 553 QString currMime = m_mimeCheck->currentText();
545 if( view == QString::fromLatin1("Documents") ){ 554 if( view == QString::fromLatin1("Documents") ){
546 // get the mimetype now 555 // get the mimetype now
547 // check if we're the current widget and return 556 // check if we're the current widget and return
548 if( m_View != 0) // delete 0 shouldn't crash but it did :( 557 if( m_View != 0) // delete 0 shouldn't crash but it did :(
549 delete m_View; 558 delete m_View;
550 m_View = 0; 559 m_View = 0;
551 delete m_select; 560 delete m_select;
552 m_select = new FileSelector( currMime == "All" ? QString::null : currMime, 561 m_select = new FileSelector( currMime == "All" ? QString::null : currMime,
553 m_stack,"fileselector", FALSE, FALSE ); 562 m_stack,"fileselector", FALSE, FALSE );
554 m_stack->addWidget( m_select, NORMAL ); 563 m_stack->addWidget( m_select, NORMAL );
555 m_mimeCheck->clear(); 564 m_mimeCheck->clear();
556 m_selector = NORMAL; 565 m_selector = NORMAL;
557 updateMimes(); 566 updateMimes();
558 m_mimeCheck->insertStringList( m_mimetypes ); 567 m_mimeCheck->insertStringList( m_mimetypes );
559 m_stack->raiseWidget( NORMAL ); 568 m_stack->raiseWidget( NORMAL );
560 569 connect(m_select, SIGNAL(fileSelected( const DocLnk &) ), this, SLOT(slotFileBridgeSelected(const DocLnk &) ) );
561 570
562 }else if(view == QString::fromLatin1("Files") ){ 571 }else if(view == QString::fromLatin1("Files") ){
563 // remove from the stack 572 // remove from the stack
564 delete m_select; 573 delete m_select;
565 m_select = 0; 574 m_select = 0;
566 delete m_View; 575 delete m_View;
567 m_View = 0; 576 m_View = 0;
568 m_selector = EXTENDED; 577 m_selector = EXTENDED;
569 // create the ListView or IconView 578 // create the ListView or IconView
570 initializeListView(); 579 initializeListView();
571 580
572 reparse(); 581 reparse();
573 }else if(view == QString::fromLatin1("All Files") ) { 582 }else if(view == QString::fromLatin1("All Files") ) {
574 // remove from the stack 583 // remove from the stack
575 delete m_select; 584 delete m_select;
576 m_select = 0; 585 m_select = 0;
577 delete m_View; 586 delete m_View;
578 m_View = 0; 587 m_View = 0;
579 m_selector = EXTENDED_ALL; 588 m_selector = EXTENDED_ALL;
580 initializeListView(); 589 initializeListView();
581 reparse(); 590 reparse();
582 }; 591 };
583}; 592};
584 593
585 594
586void OFileSelector::updateMimes() // lets check which mode is active 595void OFileSelector::updateMimes() // lets check which mode is active
587 // check the current dir for items then 596 // check the current dir for items then
588{ 597{
589 m_mimetypes.clear(); 598 m_mimetypes.clear();
590 m_mimetypes.append("All" ); 599 m_mimetypes.append("All" );
591 if( m_selector == NORMAL ){ 600 if( m_selector == NORMAL ){
592 DocLnkSet set; 601 DocLnkSet set;
593 Global::findDocuments(&set, QString::null ); 602 Global::findDocuments(&set, QString::null );
594 QListIterator<DocLnk> dit( set.children() ); 603 QListIterator<DocLnk> dit( set.children() );
595 for ( ; dit.current(); ++dit ) { 604 for ( ; dit.current(); ++dit ) {
596 if( !m_mimetypes.contains((*dit)->type() ) ) 605 if( !m_mimetypes.contains((*dit)->type() ) )
597 m_mimetypes.append( (*dit)->type() ); 606 m_mimetypes.append( (*dit)->type() );
598 } 607 }
599 }else{ 608 }else{
600 // should be allreday updatet 609 // should be allreday updatet
601 ; 610 ;
602 } 611 }
603}; 612};
604void OFileSelector::initializeListView() 613void OFileSelector::initializeListView()
605{ 614{
606 m_View = new QListView(m_stack, "Extended view" ); 615 m_View = new QListView(m_stack, "Extended view" );
607 m_stack->addWidget( m_View, EXTENDED ); 616 m_stack->addWidget( m_View, EXTENDED );
608 m_stack->raiseWidget( EXTENDED ); 617 m_stack->raiseWidget( EXTENDED );
609 QPEApplication::setStylusOperation( m_View->viewport(),QPEApplication::RightOnHold); 618 QPEApplication::setStylusOperation( m_View->viewport(),QPEApplication::RightOnHold);
610 // set up the stuff 619 // set up the stuff
611 // Pixmap Name Date Size mime 620 // Pixmap Name Date Size mime
612 //(m_View->header() )->hide(); 621 //(m_View->header() )->hide();
613 //m_View->setRootIsDecorated(false); 622 //m_View->setRootIsDecorated(false);
614 m_View->addColumn(" "); 623 m_View->addColumn(" ");
615 m_View->addColumn(tr("Name") ); 624 m_View->addColumn(tr("Name") );
616 m_View->addColumn(tr("Size") ); 625 m_View->addColumn(tr("Size") );
617 m_View->addColumn(tr("Date"), 60 ); 626 m_View->addColumn(tr("Date"), 60 );
618 m_View->addColumn(tr("Mime Type") ); 627 m_View->addColumn(tr("Mime Type") );
619 QHeader *header = m_View->header(); 628 QHeader *header = m_View->header();
620 header->hide(); 629 header->hide();
621 m_View->setSorting(1 ); 630 m_View->setSorting(1 );
631 // connect now
632 connect(m_View, SIGNAL(selectionChanged() ), this, SLOT(slotSelectionChanged() ) );
633 connect(m_View, SIGNAL(currentChanged(QListViewItem *) ), this, SLOT(slotCurrentChanged(QListViewItem * ) ) );
634 connect(m_View, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint &, int) ),
635 this, SLOT(slotClicked( int, QListViewItem *, const QPoint &, int) ) );
636 connect(m_View, SIGNAL(mouseButtonPressed(int, QListViewItem *, const QPoint &, int )),
637 this, SLOT(slotRightButton(int, QListViewItem *, const QPoint &, int ) ) );
622}; 638};
623/* If a item is locked depends on the mode 639/* If a item is locked depends on the mode
624 if we're in OPEN !isReadable is locked 640 if we're in OPEN !isReadable is locked
625 if we're in SAVE !isWriteable is locked 641 if we're in SAVE !isWriteable is locked
626 642
627 643
628 */ 644 */
629 645
630 646
631void OFileSelector::addFile(const QString &mime, QFileInfo *info, bool symlink ){ 647void OFileSelector::addFile(const QString &mime, QFileInfo *info, bool symlink ){
632 qWarning("Add Files" ); 648 qWarning("Add Files" );
633 if( !m_files ){ 649 if( !m_files ){
634 qWarning("not mfiles" ); 650 qWarning("not mfiles" );
635 return; 651 return;
636 } 652 }
637 653
638 MimeType type( info->filePath() ); 654 MimeType type( info->filePath() );
639 QString name; 655 QString name;
640 QString dir; 656 QString dir;
641 bool locked= false; 657 bool locked= false;
642 if(mime == "All" ){ 658 if(mime == "All" ){
643 ; 659 ;
644 }else if( type.id() != mime ) { 660 }else if( type.id() != mime ) {
645 return; 661 return;
646 } 662 }
647 QPixmap pix = type.pixmap(); 663 QPixmap pix = type.pixmap();
648 if(pix.isNull() ) 664 if(pix.isNull() )
649 pix = Resource::loadPixmap( "UnknownDocument-14" ); 665 pix = Resource::loadPixmap( "UnknownDocument-14" );
650 dir = info->dirPath( true ); 666 dir = info->dirPath( true );
651 if( symlink ) { // check if the readLink is readable 667 if( symlink ) { // check if the readLink is readable
652 // do it right later 668 // do it right later
653 name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink(); 669 name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink();
654 }else{ // keep track of the icons 670 }else{ // keep track of the icons
655 name = info->fileName(); 671 name = info->fileName();
656 if( m_mode == OPEN ){ 672 if( m_mode == OPEN ){
657 if( !info->isReadable() ){ 673 if( !info->isReadable() ){
658 locked = true; 674 locked = true;
659 pix = Resource::loadPixmap("locked" ); 675 pix = Resource::loadPixmap("locked" );
660 } 676 }
661 }else if( m_mode == SAVE ){ 677 }else if( m_mode == SAVE ){
662 if( !info->isWritable() ){ 678 if( !info->isWritable() ){
663 locked = true; 679 locked = true;
664 pix = Resource::loadPixmap("locked" ); 680 pix = Resource::loadPixmap("locked" );
665 } 681 }
666 } 682 }
667 } 683 }
668 new OFileSelectorItem( m_View, pix, name, 684 new OFileSelectorItem( m_View, pix, name,
669 info->lastModified().toString(), 685 info->lastModified().toString(),
670 QString::number( info->size() ), 686 QString::number( info->size() ),
671 dir, locked ); 687 dir, locked );
672} 688}
673void OFileSelector::addDir(const QString &mime, QFileInfo *info, bool symlink ) 689void OFileSelector::addDir(const QString &mime, QFileInfo *info, bool symlink )
674{ 690{
675 if(!m_dir ) 691 if(!m_dir )
676 return; 692 return;
677 //if( showDirs ) 693 //if( showDirs )
678 { 694 {
679 bool locked; 695 bool locked=false;
680 QString name; 696 QString name;
681 QPixmap pix; 697 QPixmap pix;
682 if( ( m_mode == OPEN && !info->isReadable() ) || ( m_mode == SAVE && !info->isWritable() ) ){ 698 if( ( m_mode == OPEN && !info->isReadable() ) || ( m_mode == SAVE && !info->isWritable() ) ){
683 locked = true; 699 locked = true;
684 if( symlink ){ 700 if( symlink ){
685 pix = (*m_pixmaps)["symlinkedlocked"]; 701 pix = (*m_pixmaps)["symlinkedlocked"];
686 }else{ 702 }else{
687 pix = Resource::loadPixmap("lockedfolder" ); 703 pix = Resource::loadPixmap("lockedfolder" );
688 } 704 }
689 }else{ 705 }else{
690 if( symlink ){ 706 if( symlink ){
691 pix = (*m_pixmaps)["dirsymlink" ]; 707 pix = (*m_pixmaps)["dirsymlink" ];
692 }else{ 708 }else{
693 pix = Resource::loadPixmap("folder" ); 709 pix = Resource::loadPixmap("folder" );
694 } 710 }
695 } 711 }
696 if( symlink){ 712 if( symlink){
697 name = info->fileName()+ "->"+ info->dirPath(true) +"/" +info->readLink(); 713 name = info->fileName()+ "->"+ info->dirPath(true) +"/" +info->readLink();
698 714
699 }else{ 715 }else{
700 //if(info->isReadable() ) 716 //if(info->isReadable() )
701 name = info->fileName(); 717 name = info->fileName();
702 } 718 }
703 719
704 new OFileSelectorItem(m_View, pix, 720 new OFileSelectorItem(m_View, pix,
705 name, info->lastModified().toString(), 721 name, info->lastModified().toString(),
706 QString::number(info->size() ),info->dirPath(true), locked, true ); 722 QString::number(info->size() ),info->dirPath(true), locked, true );
707 723
708 } 724 }
709} 725}
710void OFileSelector::setShowDirs(bool dir ) 726void OFileSelector::setShowDirs(bool dir )
711{ 727{
712 m_dir = dir; 728 m_dir = dir;
713 reparse(); 729 reparse();
714} 730}
715 731
732void OFileSelector::slotFileSelected(const QString &string )
733{
734 if(m_shLne )
735 m_edit->setText( string );
736
737 emit fileSelected( string );
738 // do AppLnk stuff
739}
740void OFileSelector::slotFileBridgeSelected( const DocLnk &lnk )
741{
742 slotFileSelected(lnk.name() );
743 emit fileSelected( lnk );
744}
745void OFileSelector::slotSelectionChanged() // get the current items
746 // fixme
747{
748 qWarning("selection changed" );
749}
750void OFileSelector::slotCurrentChanged(QListViewItem *item )
751{
752 qWarning("current changed" );
753 if( item == 0 )
754 return;
755
756 if( m_selector == EXTENDED || m_selector == EXTENDED_ALL ){
757 OFileSelectorItem *sel = (OFileSelectorItem*)item;
758 if(!sel->isDir() ){
759 qWarning("is not dir" );
760 if(m_shLne ){
761 m_edit->setText(sel->text(1) );
762 qWarning("setTexy" );
763 }
764 }
765 }else {
766 qWarning("mode not extended" );
767 }
768}
769// either select or change dir
770void OFileSelector::slotClicked( int button, QListViewItem *item, const QPoint &point, int )
771{
772 if( item == 0 )
773 return;
774
775 if( button != Qt::LeftButton )
776 return;
777
778 qWarning("clicked" );
779 if(m_selector == EXTENDED || m_selector == EXTENDED_ALL ){
780 qWarning("inside" );
781 OFileSelectorItem *sel = (OFileSelectorItem*)item;
782 if(!sel->isLocked() ){ // not locked either changedir or open
783 QStringList str = QStringList::split("->", sel->text(1) );
784 if(sel->isDir() ){
785 cd( sel->directory() + "/" + str[0] );
786 }else{
787 qWarning("file" );
788 if(m_shLne )
789 m_edit->setText(str[0] );
790 emit fileSelected(str[0] );
791 // emit DocLnk need to do it
792 }
793 }else{
794 qWarning( "locked" );
795 }
796 };
797}
798void OFileSelector::slotRightButton(int button, QListViewItem *item, const QPoint &, int )
799{
800 if( button != Qt::RightButton )
801 return;
802 qWarning("right button" );
803 slotContextMenu(item);
804}
805void OFileSelector::slotContextMenu(QListViewItem *item)
806{
807 qWarning("context menu" );
808 if( m_custom !=0){
809 m_custom->exec();
810 }else{
811 QPopupMenu menu;
812 QAction act;
813 OFileSelectorItem *sel = (OFileSelectorItem*)item;
814 if(sel->isDir() ){
815 act.setText( tr("Change Directory") );
816 act.addTo(&menu );
817 connect(&act, SIGNAL(activated() ),
818 this, SLOT(slotChangedDir() ) );
819 }else{
820 act.setText( tr("Open file" ) );
821 act.addTo( &menu );
822 connect(&act, SIGNAL(activated() ),
823 this, SLOT(slotOpen() ) );
824 }
825 QAction rescan;
826 rescan.setText( tr("Rescan") );
827 rescan.addTo( &menu );
828 connect(&act, SIGNAL(activated() ),
829 this, SLOT(slotRescan() ) );
830
831 QAction rename;
832 rename.setText( tr("Rename") );
833 rename.addTo( &menu );
834 connect(&act, SIGNAL(activated() ),
835 this, SLOT(slotRename() ) );
836
837 menu.insertSeparator();
838 QAction delItem;
839 delItem.setText( tr("Delete") );
840 delItem.addTo(&menu );
841 connect(&act, SIGNAL(activated() ),
842 this, SLOT(slotDelete() ) );
843
844 menu.exec(QCursor::pos() );
845 }
846}
847bool OFileSelector::cd(const QString &str )
848{
849 qWarning(" dir %s", str.latin1() );
850 QDir dir( str);
851 if(dir.exists() ){
852 m_currentDir = str;
853 reparse();
854 return true;
855 }
856 return false;
857}
858
859void OFileSelector::slotChangedDir()
860{
861 OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem();
862 if(sel->isDir() ){
863 QStringList str = QStringList::split("->", sel->text(1) );
864 cd( sel->directory() + "/" + str[0] );
865 }
866}
867void OFileSelector::slotOpen()
868{
869 OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem();
870 if(!sel->isDir() ){
871 QStringList str = QStringList::split("->", sel->text(1) );
872 slotFileSelected( str[0] );
873 }
874}
875void OFileSelector::slotRescan()
876{
877 reparse();
878}
879void OFileSelector::slotRename()
880{
881 // rename inline
882}
883void OFileSelector::slotDelete()
884{
885 qWarning("delete slot" );
886 OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem();
887 QStringList list = QStringList::split("->", sel->text(1) );
888 if( sel->isDir() ){
889 QString str = QString::fromLatin1("rm -rf ") + list[0];
890 ::system(str.utf8().data() );
891 }else{
892 QFile::remove( list[0] );
893 }
894 m_View->takeItem( sel );
895 delete sel;
896}
897
898
716 899
717 900
diff --git a/libopie/ofileselector.h b/libopie/ofileselector.h
index 6936773..458e552 100644
--- a/libopie/ofileselector.h
+++ b/libopie/ofileselector.h
@@ -1,249 +1,270 @@
1/* 1/*
2 This is based on code and idea of 2 This is based on code and idea of
3 L. J. Potter ljp@llornkcor.com 3 L. J. Potter ljp@llornkcor.com
4 Thanks a lot 4 Thanks a lot
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 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
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This library is distributed in the hope that 17    .i_,=:_.      -<s. This library is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#ifndef opiefileselector_h 34#ifndef opiefileselector_h
35#define opiefileselector_h 35#define opiefileselector_h
36 36
37#include <qwidget.h> 37#include <qwidget.h>
38#include <qstring.h> 38#include <qstring.h>
39#include <qpixmap.h> 39#include <qpixmap.h>
40#include <qstringlist.h> 40#include <qstringlist.h>
41#include <qmap.h> 41#include <qmap.h>
42#include <qvaluelist.h> 42#include <qvaluelist.h>
43 43
44#include <qpe/applnk.h> 44#include <qpe/applnk.h>
45#include <qlistview.h> 45#include <qlistview.h>
46/** This is OPIEs FileDialog Widget. You can use it 46/** This is OPIEs FileDialog Widget. You can use it
47 * as a dropin replacement of the fileselector and 47 * as a dropin replacement of the fileselector and
48 * or use any of the new features. 48 * or use any of the new features.
49 * This is also a complete FileSave and FileLoad widget 49 * This is also a complete FileSave and FileLoad widget
50 * If you look for a Dialog check OFileDialog 50 * If you look for a Dialog check OFileDialog
51 * 51 *
52 */ 52 */
53class DocLnk; 53class DocLnk;
54class QCheckBox; 54class QCheckBox;
55class QComboBox; 55class QComboBox;
56class QPushButton; 56class QPushButton;
57class FileSelector; 57class FileSelector;
58class QGridLayout; 58class QGridLayout;
59class QLineEdit; 59class QLineEdit;
60class QLabel; 60class QLabel;
61class QWidgetStack; 61class QWidgetStack;
62class QHBoxLayout; 62class QHBoxLayout;
63class QVBoxLayout; 63class QVBoxLayout;
64class QPopupMenu; 64class QPopupMenu;
65class QFileInfo; 65class QFileInfo;
66// 66//
67class OFileSelectorItem : public QListViewItem { 67class OFileSelectorItem : public QListViewItem {
68 public: 68 public:
69 OFileSelectorItem(QListView *view, const QPixmap &pixmap, const QString &path, 69 OFileSelectorItem(QListView *view, const QPixmap &pixmap, const QString &path,
70 const QString &date, const QString &size, const QString &mDir, 70 const QString &date, const QString &size, const QString &mDir,
71 bool isLocked=false, bool isDir=false ): QListViewItem(view) { 71 bool isLocked=false, bool isDir=false ): QListViewItem(view) {
72 setPixmap(0, pixmap ); 72 setPixmap(0, pixmap );
73 setText(1, path ); 73 setText(1, path );
74 setText(2, size ); 74 setText(2, size );
75 setText(3, date ); 75 setText(3, date );
76 //setText(4, mDir ); 76 //setText(4, mDir );
77 m_dir = mDir; 77 m_dir = mDir;
78 dir = isDir; 78 dir = isDir;
79 mLocked = isLocked; 79 mLocked = isLocked;
80 } 80 }
81 bool locked() const{ 81 bool isLocked() const{
82 return mLocked; 82 return mLocked;
83 } 83 }
84 QString directory()const{ 84 QString directory()const{
85 return m_dir; 85 return m_dir;
86 } 86 }
87 bool isDir()const{ 87 bool isDir()const{
88 return dir; 88 return dir;
89 } 89 }
90 QString path()const{ 90 QString path()const{
91 return text(1 ); 91 return text(1 );
92 } 92 }
93 QString key(int id, bool )const { 93 QString key(int id, bool )const {
94 QString ke; 94 QString ke;
95 if( id == 0 || id == 1 ){ // name 95 if( id == 0 || id == 1 ){ // name
96 if( dir ){ 96 if( dir ){
97 ke.append("0" ); 97 ke.append("0" );
98 ke.append( text(1) ); 98 ke.append( text(1) );
99 }else{ 99 }else{
100 ke.append("1" ); 100 ke.append("1" );
101 ke.append( text(1) ); 101 ke.append( text(1) );
102 } 102 }
103 }else if( id == 2 ){ // size 103 }else if( id == 2 ){ // size
104 return text(2); 104 return text(2);
105 }else if( id == 3 ){ // date 105 }else if( id == 3 ){ // date
106 return text(3); 106 return text(3);
107 } 107 }
108 return ke; 108 return ke;
109 }; 109 };
110 private: 110 private:
111 bool mLocked:1; 111 bool mLocked:1;
112 bool dir:1; 112 bool dir:1;
113 QString m_dir; 113 QString m_dir;
114}; 114};
115 115
116class OFileSelector : public QWidget { 116class OFileSelector : public QWidget {
117 Q_OBJECT 117 Q_OBJECT
118 public: 118 public:
119 enum Mode {OPEN=1, SAVE, FILESELECTOR }; 119 enum Mode {OPEN=1, SAVE, FILESELECTOR };
120 enum Selector{NORMAL=1, EXTENDED = 2, EXTENDED_ALL =4 }; 120 enum Selector{NORMAL=1, EXTENDED = 2, EXTENDED_ALL =4 };
121 enum View { DIRS = 1, FILES = 2, TREE = 4, ICON = 8 }; 121 enum View { DIRS = 1, FILES = 2, TREE = 4, ICON = 8 };
122 OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName, const QString &fileName = QString::null, const QStringList mimetypes = QStringList() ); 122 OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName, const QString &fileName = QString::null, const QStringList mimetypes = QStringList() );
123 123
124 bool isToolbarVisible() const { return m_shTool; }; 124 bool isToolbarVisible() const { return m_shTool; };
125 bool isPermissionBarVisible() const { return m_shPerm; }; 125 bool isPermissionBarVisible() const { return m_shPerm; };
126 bool isLineEditVisible()const { return m_shLne; }; 126 bool isLineEditVisible()const { return m_shLne; };
127 bool isChooserVisible( )const { return m_shChooser; }; 127 bool isChooserVisible( )const { return m_shChooser; };
128 bool isYesCancelVisible()const { return m_shYesNo; }; 128 bool isYesCancelVisible()const { return m_shYesNo; };
129 void setYesCancelVisible( bool show ); 129 void setYesCancelVisible( bool show );
130 void setToolbarVisible( bool show ); 130 void setToolbarVisible( bool show );
131 void setPermissionBarVisible( bool show ); 131 void setPermissionBarVisible( bool show );
132 void setLineEditVisible(bool show) ; 132 void setLineEditVisible(bool show) ;
133 void setChooserVisible( bool chooser ); 133 void setChooserVisible( bool chooser );
134 134
135 QCheckBox* permissionCheckbox(); 135 QCheckBox* permissionCheckbox();
136 bool setPermission() const; 136 bool setPermission() const;
137 void setPermissionChecked( bool check ); 137 void setPermissionChecked( bool check );
138 138
139 void setMode( int ); 139 void setMode( int );
140 140
141 bool showDirs()const { return m_dir; } 141 bool showDirs()const { return m_dir; }
142 void setShowDirs(bool ); 142 void setShowDirs(bool );
143 143
144 const QListView* listView() { return m_View; }; 144 const QListView* listView() { return m_View; };
145 145
146 bool isCaseSensetive()const { return m_case; } 146 bool isCaseSensetive()const { return m_case; }
147 void setCaseSensetive(bool caSe ); 147 void setCaseSensetive(bool caSe );
148 148
149 bool showFiles()const { return m_files; }; 149 bool showFiles()const { return m_files; };
150 void setShowFiles(bool ); 150 void setShowFiles(bool );
151 151 bool cd(const QString &path );
152 152
153 153
154 int mode()const { return m_mode; }; 154 int mode()const { return m_mode; };
155 int selector()const { return m_selector; }; 155 int selector()const { return m_selector; };
156 void setSelector( int ); 156 void setSelector( int );
157 157
158 158
159 void setPopupMenu( const QPopupMenu * ); 159 void setPopupMenu( QPopupMenu * );
160 160
161 void updateLay(); 161 void updateLay();
162 162
163 void reparse(); // re reads the dir 163 void reparse(); // re reads the dir
164 164
165 QString selectedName( )const; 165 QString selectedName( )const;
166 QStringList selectedNames()const; 166 QStringList selectedNames()const;
167 167
168 QString selectedPath() const; 168 QString selectedPath() const;
169 QStringList selectedPaths() const; 169 QStringList selectedPaths() const;
170 170
171 QString directory()const; 171 QString directory()const;
172 int fileCount(); 172 int fileCount();
173 173
174 /* the user needs to delete it */ 174 /* the user needs to delete it */
175 DocLnk selectedDocument()const; 175 DocLnk selectedDocument()const;
176 /* the user needs to delete it */ 176 /* the user needs to delete it */
177 QValueList<DocLnk> selectedDocuments()const; 177 QValueList<DocLnk> selectedDocuments()const;
178 178
179 signals: 179 signals:
180 void fileSelected( const DocLnk & ); 180 void fileSelected( const DocLnk & );
181 void fileSelected( const QString & ); 181 void fileSelected( const QString & );
182 void closeMe(); 182 void closeMe();
183 void ok(); 183 void ok();
184 void cancel(); 184 void cancel();
185 185
186 protected slots: 186 protected slots:
187 void slotOk(); 187 void slotOk();
188 void slotCancel(); 188 void slotCancel();
189 void slotViewCheck(const QString & ); 189 void slotViewCheck(const QString & );
190 void slotMimeCheck(const QString & ); 190 void slotMimeCheck(const QString & );
191 protected: 191 protected:
192 void init(); 192 void init();
193 void updateMimes(); 193 void updateMimes();
194 int m_mode, m_selector; 194
195 protected:
196
197 private:
198int m_mode, m_selector;
195 QComboBox *m_location, *m_mimeCheck, *m_viewCheck; 199 QComboBox *m_location, *m_mimeCheck, *m_viewCheck;
196 QPushButton *m_homeButton, *m_docButton, *m_hideButton, *m_ok, *m_cancel; 200 QPushButton *m_homeButton, *m_docButton, *m_hideButton, *m_ok, *m_cancel;
197 QPushButton *m_reread, *m_up; 201 QPushButton *m_reread, *m_up;
198 QListView *m_View; 202 QListView *m_View;
199 QCheckBox *m_checkPerm; 203 QCheckBox *m_checkPerm;
200 204
201 QString m_currentDir; 205 QString m_currentDir;
202 QString m_name; 206 QString m_name;
203 QStringList m_mimetypes; 207 QStringList m_mimetypes;
204 208
205 FileSelector *m_select; 209 FileSelector *m_select;
206 QWidgetStack *m_stack; 210 QWidgetStack *m_stack;
207 QVBoxLayout *m_lay; 211 QVBoxLayout *m_lay;
208 QGridLayout *m_Oselector; 212 QGridLayout *m_Oselector;
209 213
210 QHBoxLayout *m_boxToolbar; 214 QHBoxLayout *m_boxToolbar;
211 QHBoxLayout *m_boxOk; 215 QHBoxLayout *m_boxOk;
212 QHBoxLayout *m_boxName; 216 QHBoxLayout *m_boxName;
213 QHBoxLayout *m_boxView; 217 QHBoxLayout *m_boxView;
214 218
219 QPopupMenu *m_custom;
220
215 QLineEdit *m_edit; 221 QLineEdit *m_edit;
216 QLabel *m_fnLabel; 222 QLabel *m_fnLabel;
217 bool m_shTool:1; 223 bool m_shTool:1;
218 bool m_shPerm:1; 224 bool m_shPerm:1;
219 bool m_shLne:1; 225 bool m_shLne:1;
220 bool m_shChooser:1; 226 bool m_shChooser:1;
221 bool m_shYesNo:1; 227 bool m_shYesNo:1;
222 bool m_boCheckPerm:1; 228 bool m_boCheckPerm:1;
223 bool m_autoMime:1; 229 bool m_autoMime:1;
224 bool m_case:1; 230 bool m_case:1;
225 bool m_dir:1; 231 bool m_dir:1;
226 bool m_files:1; 232 bool m_files:1;
227 233
228 protected:
229
230 private:
231 // implementation todo 234 // implementation todo
232 virtual void addFile(const QString &mime, QFileInfo *info, bool symlink = FALSE ); 235 virtual void addFile(const QString &mime, QFileInfo *info, bool symlink = FALSE );
233 virtual void addDir( const QString &mime, QFileInfo *info , bool symlink = FALSE ); 236 virtual void addDir( const QString &mime, QFileInfo *info , bool symlink = FALSE );
234 virtual void addSymlink(const QString &mime, QFileInfo *info, bool broken = FALSE ){}; 237 virtual void addSymlink(const QString &, QFileInfo *, bool = FALSE ){};
235 void delItems(); 238 void delItems();
236 void initializeName(); 239 void initializeName();
237 void initializeYes(); 240 void initializeYes();
238 void initializeChooser(); 241 void initializeChooser();
239 void initializeListView(); 242 void initializeListView();
240 void initPics(); 243 void initPics();
241 bool compliesMime(const QString &path, const QString &mime); 244 bool compliesMime(const QString &path, const QString &mime);
242 245
243 class OFileSelectorPrivate; 246 class OFileSelectorPrivate;
244 OFileSelectorPrivate *d; 247 OFileSelectorPrivate *d;
245 static QMap<QString,QPixmap> *m_pixmaps; 248 static QMap<QString,QPixmap> *m_pixmaps;
249
250private slots:
251 void slotFileSelected(const QString & ); // not really meant to be a slot
252 void slotFileBridgeSelected( const DocLnk & );
253 virtual void slotSelectionChanged();
254 virtual void slotCurrentChanged(QListViewItem* );
255 virtual void slotClicked( int, QListViewItem *item, const QPoint &, int);
256 virtual void slotRightButton(int, QListViewItem *, const QPoint &, int );
257 virtual void slotContextMenu( QListViewItem *item);
258 // listview crap see above
259 // PopupMenu crap
260 virtual void slotChangedDir();
261 virtual void slotOpen();
262 virtual void slotRescan();
263 virtual void slotRename();
264 virtual void slotDelete();
265
246}; 266};
247 267
248 268
249#endif 269#endif
270