summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/ofileselector.cc1
1 files changed, 1 insertions, 0 deletions
diff --git a/libopie/ofileselector.cc b/libopie/ofileselector.cc
index d780da9..8299b3d 100644
--- a/libopie/ofileselector.cc
+++ b/libopie/ofileselector.cc
@@ -1,395 +1,396 @@
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 <qpushbutton.h> 13#include <qpushbutton.h>
13#include <qwidgetstack.h> 14#include <qwidgetstack.h>
14#include <qpopupmenu.h> 15#include <qpopupmenu.h>
15#include <qdir.h> 16#include <qdir.h>
16#include <qfile.h> 17#include <qfile.h>
17#include <qfileinfo.h> 18#include <qfileinfo.h>
18#include <qtimer.h> 19#include <qtimer.h>
19 20
20#include <qpe/qpeapplication.h> 21#include <qpe/qpeapplication.h>
21#include <qpe/applnk.h> 22#include <qpe/applnk.h>
22#include <qpe/fileselector.h> 23#include <qpe/fileselector.h>
23#include <qpe/global.h> 24#include <qpe/global.h>
24#include <qpe/mimetype.h> 25#include <qpe/mimetype.h>
25#include <qpe/resource.h> 26#include <qpe/resource.h>
26#include <qpe/storage.h> 27#include <qpe/storage.h>
27 28
28#include <unistd.h> 29#include <unistd.h>
29#include <stdlib.h> 30#include <stdlib.h>
30#include <sys/stat.h> 31#include <sys/stat.h>
31 32
32#include "ofileselector.h" 33#include "ofileselector.h"
33 34
34 35
35QMap<QString,QPixmap> *OFileSelector::m_pixmaps = 0; 36QMap<QString,QPixmap> *OFileSelector::m_pixmaps = 0;
36 37
37namespace { 38namespace {
38 int indexByString( const QComboBox *box, const QString &str ){ 39 int indexByString( const QComboBox *box, const QString &str ){
39 int index= 0; 40 int index= 0;
40 for(int i= 0; i < box->count(); i++ ){ 41 for(int i= 0; i < box->count(); i++ ){
41 if( str == box->text(i ) ){ 42 if( str == box->text(i ) ){
42 index= i; 43 index= i;
43 break; 44 break;
44 } 45 }
45 } 46 }
46 return index; 47 return index;
47 } 48 }
48 class OFileSelectorItem : public QListViewItem { 49 class OFileSelectorItem : public QListViewItem {
49 public: 50 public:
50 OFileSelectorItem(QListView *view, const QPixmap &pixmap, const QString &path, 51 OFileSelectorItem(QListView *view, const QPixmap &pixmap, const QString &path,
51 const QString &date, const QString &size, const QString &mDir, 52 const QString &date, const QString &size, const QString &mDir,
52 bool isLocked=false, bool isDir=false ): QListViewItem(view) { 53 bool isLocked=false, bool isDir=false ): QListViewItem(view) {
53 setPixmap(0, pixmap ); 54 setPixmap(0, pixmap );
54 setText(1, path ); 55 setText(1, path );
55 setText(2, size ); 56 setText(2, size );
56 setText(3, date ); 57 setText(3, date );
57 //setText(4, mDir ); 58 //setText(4, mDir );
58 m_dir = mDir; 59 m_dir = mDir;
59 dir = isDir; 60 dir = isDir;
60 mLocked = isLocked; 61 mLocked = isLocked;
61 } 62 }
62 bool isLocked() const{ 63 bool isLocked() const{
63 return mLocked; 64 return mLocked;
64 } 65 }
65 QString directory()const{ 66 QString directory()const{
66 return m_dir; 67 return m_dir;
67 } 68 }
68 bool isDir()const{ 69 bool isDir()const{
69 return dir; 70 return dir;
70 } 71 }
71 QString path()const{ 72 QString path()const{
72 return text(1 ); 73 return text(1 );
73 } 74 }
74 QString key(int id, bool )const { 75 QString key(int id, bool )const {
75 QString ke; 76 QString ke;
76 if( id == 0 || id == 1 ){ // name 77 if( id == 0 || id == 1 ){ // name
77 if( dir ){ 78 if( dir ){
78 ke.append("0" ); 79 ke.append("0" );
79 ke.append( text(1) ); 80 ke.append( text(1) );
80 }else{ 81 }else{
81 ke.append("1" ); 82 ke.append("1" );
82 ke.append( text(1) ); 83 ke.append( text(1) );
83 } 84 }
84 }else if( id == 2 ){ // size 85 }else if( id == 2 ){ // size
85 return text(2); 86 return text(2);
86 }else if( id == 3 ){ // date 87 }else if( id == 3 ){ // date
87 return text(3); 88 return text(3);
88 } 89 }
89 return ke; 90 return ke;
90 }; 91 };
91 private: 92 private:
92 bool mLocked:1; 93 bool mLocked:1;
93 bool dir:1; 94 bool dir:1;
94 QString m_dir; 95 QString m_dir;
95 }; 96 };
96}; 97};
97 98
98 99
99OFileSelector::OFileSelector( QWidget *wid, int mode, int selector, 100OFileSelector::OFileSelector( QWidget *wid, int mode, int selector,
100 const QString &dirName, 101 const QString &dirName,
101 const QString &fileName, 102 const QString &fileName,
102 const QStringList &mimeTypes ) 103 const QStringList &mimeTypes )
103 : QWidget( wid, "OFileSelector") 104 : QWidget( wid, "OFileSelector")
104{ 105{
105 m_mimetypes = mimeTypes; 106 m_mimetypes = mimeTypes;
106 initVars(); 107 initVars();
107 m_mode = mode; 108 m_mode = mode;
108 m_selector = selector; 109 m_selector = selector;
109 m_currentDir = dirName; 110 m_currentDir = dirName;
110 init(); 111 init();
111QTimer::singleShot(6*1000, this, SLOT( slotTest() ) ); 112QTimer::singleShot(6*1000, this, SLOT( slotTest() ) );
112} 113}
113 114
114OFileSelector::OFileSelector(const QString &mimeFilter, QWidget *parent, 115OFileSelector::OFileSelector(const QString &mimeFilter, QWidget *parent,
115 const char *name, bool newVisible = TRUE, 116 const char *name, bool newVisible = TRUE,
116 bool closeVisible = FALSE ) 117 bool closeVisible = FALSE )
117 : QWidget( parent, name ) 118 : QWidget( parent, name )
118{ 119{
119 m_mimetypes = QStringList::split(";", mimeFilter ); 120 m_mimetypes = QStringList::split(";", mimeFilter );
120 initVars(); 121 initVars();
121 m_currentDir = QPEApplication::documentDir(); 122 m_currentDir = QPEApplication::documentDir();
122 m_mode = OPEN; 123 m_mode = OPEN;
123 m_selector = NORMAL; 124 m_selector = NORMAL;
124 m_shClose = closeVisible; 125 m_shClose = closeVisible;
125 m_shNew = newVisible; 126 m_shNew = newVisible;
126 m_shLne = false; 127 m_shLne = false;
127 m_shPerm = false; 128 m_shPerm = false;
128 m_shYesNo = false; 129 m_shYesNo = false;
129 init(); 130 init();
130 131
131 132
132} 133}
133 134
134OFileSelector::~OFileSelector() 135OFileSelector::~OFileSelector()
135{ 136{
136 137
137} 138}
138 139
139void OFileSelector::setNewVisible( bool visible ) 140void OFileSelector::setNewVisible( bool visible )
140{ 141{
141 m_shNew = visible; 142 m_shNew = visible;
142 if( m_selector == NORMAL ){ 143 if( m_selector == NORMAL ){
143 delete m_select; 144 delete m_select;
144 // we need to initialize but keep the selected mimetype 145 // we need to initialize but keep the selected mimetype
145 QString mime = m_mimeCheck == 0 ? QString::null : m_mimeCheck->currentText() ; 146 QString mime = m_mimeCheck == 0 ? QString::null : m_mimeCheck->currentText() ;
146 m_select = new FileSelector( m_autoMime ? mime : m_mimetypes.join(";") , 147 m_select = new FileSelector( m_autoMime ? mime : m_mimetypes.join(";") ,
147 m_stack, "fileselector", 148 m_stack, "fileselector",
148 m_shNew, m_shClose); 149 m_shNew, m_shClose);
149 connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ), 150 connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ),
150 this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) ); 151 this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) );
151 //connect to close me and other signals as well 152 //connect to close me and other signals as well
152 m_stack->addWidget( m_select, NORMAL ); 153 m_stack->addWidget( m_select, NORMAL );
153 }else{ 154 }else{
154 m_new->show(); 155 m_new->show();
155 } 156 }
156} 157}
157void OFileSelector::setCloseVisible( bool visible ) 158void OFileSelector::setCloseVisible( bool visible )
158{ 159{
159 m_shClose = visible; 160 m_shClose = visible;
160 if( m_selector == NORMAL ){ 161 if( m_selector == NORMAL ){
161 setNewVisible( m_shNew ); // yeah baby 162 setNewVisible( m_shNew ); // yeah baby
162 }else{ 163 }else{
163 m_close->show(); 164 m_close->show();
164 } 165 }
165} 166}
166void OFileSelector::reread() 167void OFileSelector::reread()
167{ 168{
168 if( m_selector == NORMAL ){ 169 if( m_selector == NORMAL ){
169 setNewVisible( m_shNew ); // make it a initializeSelector 170 setNewVisible( m_shNew ); // make it a initializeSelector
170 }else if ( m_selector == EXTENDED || m_selector == EXTENDED_ALL ){ 171 }else if ( m_selector == EXTENDED || m_selector == EXTENDED_ALL ){
171 reparse(); 172 reparse();
172 //}else{ 173 //}else{
173 //; 174 //;
174 } 175 }
175} 176}
176 177
177const DocLnk *OFileSelector::selected() 178const DocLnk *OFileSelector::selected()
178{ 179{
179 if( m_selector == NORMAL ){ 180 if( m_selector == NORMAL ){
180 return m_select->selected(); 181 return m_select->selected();
181 }else{ 182 }else{
182 DocLnk *lnk = new DocLnk(selectedDocument() ); 183 DocLnk *lnk = new DocLnk(selectedDocument() );
183 return lnk; 184 return lnk;
184 } 185 }
185} 186}
186 187
187void OFileSelector::setYesCancelVisible( bool show ) 188void OFileSelector::setYesCancelVisible( bool show )
188{ 189{
189 initializeYes(); // FIXME if YesCancel is not shown we will initialize it to hide it :( 190 initializeYes(); // FIXME if YesCancel is not shown we will initialize it to hide it :(
190 m_shYesNo = show; 191 m_shYesNo = show;
191 if( m_shYesNo ) 192 if( m_shYesNo )
192 m_boxOk->show(); 193 m_boxOk->show();
193 else 194 else
194 m_boxOk->hide(); 195 m_boxOk->hide();
195 196
196} 197}
197void OFileSelector::setToolbarVisible( bool show ) 198void OFileSelector::setToolbarVisible( bool show )
198{ 199{
199 m_shTool = show; 200 m_shTool = show;
200 initializeListView(); // FIXME see above waste of memory 201 initializeListView(); // FIXME see above waste of memory
201 if(!m_shTool ){ 202 if(!m_shTool ){
202 m_location->hide(); 203 m_location->hide();
203 m_up->hide(); 204 m_up->hide();
204 m_homeButton->hide(); 205 m_homeButton->hide();
205 m_docButton->hide(); 206 m_docButton->hide();
206 }else{ 207 }else{
207 m_location->show(); 208 m_location->show();
208 m_up->show(); 209 m_up->show();
209 m_homeButton->show(); 210 m_homeButton->show();
210 m_docButton->show(); 211 m_docButton->show();
211 } 212 }
212} 213}
213void OFileSelector::setPermissionBarVisible( bool show ) 214void OFileSelector::setPermissionBarVisible( bool show )
214{ 215{
215 m_shPerm = show; 216 m_shPerm = show;
216 initializePerm(); 217 initializePerm();
217 if( m_shPerm ) 218 if( m_shPerm )
218 m_checkPerm->show(); 219 m_checkPerm->show();
219 else 220 else
220 m_checkPerm->hide(); 221 m_checkPerm->hide();
221} 222}
222void OFileSelector::setLineEditVisible( bool show ) 223void OFileSelector::setLineEditVisible( bool show )
223{ 224{
224 if( show ){ 225 if( show ){
225 initializeName(); 226 initializeName();
226 m_boxName->show(); 227 m_boxName->show();
227 }else{ 228 }else{
228 if( m_shLne && m_boxName != 0 ){ // check if we showed before this is the way to go 229 if( m_shLne && m_boxName != 0 ){ // check if we showed before this is the way to go
229 m_boxName->hide(); 230 m_boxName->hide();
230 } 231 }
231 } 232 }
232 m_shLne = show; 233 m_shLne = show;
233} 234}
234 235
235void OFileSelector::setChooserVisible( bool show ) 236void OFileSelector::setChooserVisible( bool show )
236{ 237{
237 m_shChooser = show; 238 m_shChooser = show;
238 initializeChooser(); 239 initializeChooser();
239 if( m_shChooser ){ 240 if( m_shChooser ){
240 m_boxView->hide(); 241 m_boxView->hide();
241 }else{ 242 }else{
242 m_boxView->show(); 243 m_boxView->show();
243 } 244 }
244} 245}
245 246
246QCheckBox* OFileSelector::permissionCheckbox() 247QCheckBox* OFileSelector::permissionCheckbox()
247{ 248{
248 if( m_selector == NORMAL ) 249 if( m_selector == NORMAL )
249 return 0l; 250 return 0l;
250 else 251 else
251 return m_checkPerm; 252 return m_checkPerm;
252} 253}
253bool OFileSelector::setPermission()const 254bool OFileSelector::setPermission()const
254{ 255{
255 return m_checkPerm == 0 ? false : m_checkPerm->isChecked(); 256 return m_checkPerm == 0 ? false : m_checkPerm->isChecked();
256} 257}
257void OFileSelector::setPermissionChecked( bool check ) 258void OFileSelector::setPermissionChecked( bool check )
258{ 259{
259 if( m_checkPerm ) 260 if( m_checkPerm )
260 m_checkPerm->setChecked( check ); 261 m_checkPerm->setChecked( check );
261} 262}
262 263
263void OFileSelector::setMode(int mode) // FIXME do direct raising 264void OFileSelector::setMode(int mode) // FIXME do direct raising
264{ 265{
265 m_mode = mode; 266 m_mode = mode;
266 if( m_selector == NORMAL ) 267 if( m_selector == NORMAL )
267 return; 268 return;
268} 269}
269void OFileSelector::setShowDirs(bool ) 270void OFileSelector::setShowDirs(bool )
270{ 271{
271 m_dir = true; 272 m_dir = true;
272 reparse(); 273 reparse();
273} 274}
274void OFileSelector::setCaseSensetive(bool caSe ) 275void OFileSelector::setCaseSensetive(bool caSe )
275{ 276{
276 m_case = caSe; 277 m_case = caSe;
277 reparse(); 278 reparse();
278} 279}
279void OFileSelector::setShowFiles(bool show ) 280void OFileSelector::setShowFiles(bool show )
280{ 281{
281 m_files = show; 282 m_files = show;
282 reparse(); 283 reparse();
283} 284}
284/// 285///
285bool OFileSelector::cd(const QString &path ) 286bool OFileSelector::cd(const QString &path )
286{ 287{
287 m_currentDir = path; 288 m_currentDir = path;
288 reparse(); 289 reparse();
289 return true; 290 return true;
290} 291}
291void OFileSelector::setSelector(int mode ) 292void OFileSelector::setSelector(int mode )
292{ 293{
293QString text; 294QString text;
294 switch( mode ){ 295 switch( mode ){
295 case NORMAL: 296 case NORMAL:
296 text = tr("Documents"); 297 text = tr("Documents");
297 break; 298 break;
298 case EXTENDED: 299 case EXTENDED:
299 text = tr("Files"); 300 text = tr("Files");
300 break; 301 break;
301 case EXTENDED_ALL: 302 case EXTENDED_ALL:
302 text = tr("All Files"); 303 text = tr("All Files");
303 break; 304 break;
304 } 305 }
305 slotViewCheck( text ); 306 slotViewCheck( text );
306} 307}
307 308
308void OFileSelector::setPopupMenu(QPopupMenu *popup ) 309void OFileSelector::setPopupMenu(QPopupMenu *popup )
309{ 310{
310 m_custom = popup; 311 m_custom = popup;
311 m_showPopup = true; 312 m_showPopup = true;
312} 313}
313 314
314//void OFileSelector::updateL 315//void OFileSelector::updateL
315 316
316QString OFileSelector::selectedName() const 317QString OFileSelector::selectedName() const
317{ 318{
318 QString name; 319 QString name;
319 if( m_selector == NORMAL ){ 320 if( m_selector == NORMAL ){
320 const DocLnk *lnk = m_select->selected(); 321 const DocLnk *lnk = m_select->selected();
321 name = lnk->file(); 322 name = lnk->file();
322 delete lnk; 323 delete lnk;
323 }else if( m_selector == EXTENDED || m_selector == EXTENDED_ALL ){ 324 }else if( m_selector == EXTENDED || m_selector == EXTENDED_ALL ){
324 QListViewItem *item = m_View->currentItem(); 325 QListViewItem *item = m_View->currentItem();
325 if( item != 0 ) 326 if( item != 0 )
326 name = m_currentDir + "/" + item->text( 1 ); 327 name = m_currentDir + "/" + item->text( 1 );
327 }else { // installed view 328 }else { // installed view
328 ; 329 ;
329 } 330 }
330 return name; 331 return name;
331} 332}
332QStringList OFileSelector::selectedNames()const 333QStringList OFileSelector::selectedNames()const
333{ 334{
334 QStringList list; 335 QStringList list;
335 if( m_selector == NORMAL ){ 336 if( m_selector == NORMAL ){
336 list << selectedName(); 337 list << selectedName();
337 }else if ( m_selector == EXTENDED || m_selector == EXTENDED_ALL ) { 338 }else if ( m_selector == EXTENDED || m_selector == EXTENDED_ALL ) {
338 list << selectedName(); // FIXME implement multiple Selections 339 list << selectedName(); // FIXME implement multiple Selections
339 } 340 }
340 return list; 341 return list;
341} 342}
342/** If mode is set to the Dir selection this will return the selected path. 343/** If mode is set to the Dir selection this will return the selected path.
343 * 344 *
344 * 345 *
345 */ 346 */
346QString OFileSelector::selectedPath()const 347QString OFileSelector::selectedPath()const
347{ 348{
348 QString path; 349 QString path;
349 if( m_selector == NORMAL ){ 350 if( m_selector == NORMAL ){
350 path = QPEApplication::documentDir(); 351 path = QPEApplication::documentDir();
351 }else if( m_selector == EXTENDED || m_selector == EXTENDED_ALL ){ 352 }else if( m_selector == EXTENDED || m_selector == EXTENDED_ALL ){
352 ; 353 ;
353 } 354 }
354 return path; 355 return path;
355} 356}
356QStringList OFileSelector::selectedPaths() const 357QStringList OFileSelector::selectedPaths() const
357{ 358{
358 QStringList list; 359 QStringList list;
359 list << selectedPath(); 360 list << selectedPath();
360 return list; 361 return list;
361} 362}
362QString OFileSelector::directory()const 363QString OFileSelector::directory()const
363{ 364{
364 if( m_selector == NORMAL ) 365 if( m_selector == NORMAL )
365 return QPEApplication::documentDir(); 366 return QPEApplication::documentDir();
366 367
367 return QDir(m_currentDir).absPath(); 368 return QDir(m_currentDir).absPath();
368} 369}
369 370
370int OFileSelector::fileCount() 371int OFileSelector::fileCount()
371{ 372{
372 int count; 373 int count;
373 switch( m_selector ){ 374 switch( m_selector ){
374 case NORMAL: 375 case NORMAL:
375 count = m_select->fileCount(); 376 count = m_select->fileCount();
376 break; 377 break;
377 //case CUSTOM: 378 //case CUSTOM:
378 case EXTENDED: 379 case EXTENDED:
379 case EXTENDED_ALL: 380 case EXTENDED_ALL:
380 default: 381 default:
381 count = m_View->childCount(); 382 count = m_View->childCount();
382 break; 383 break;
383 } 384 }
384 return count; 385 return count;
385} 386}
386DocLnk OFileSelector::selectedDocument() const 387DocLnk OFileSelector::selectedDocument() const
387{ 388{
388 DocLnk lnk; 389 DocLnk lnk;
389 switch( m_selector ){ 390 switch( m_selector ){
390 case NORMAL:{ 391 case NORMAL:{
391 const DocLnk *lnk2 = m_select->selected(); 392 const DocLnk *lnk2 = m_select->selected();
392 lnk = DocLnk(*lnk2 ); // copy 393 lnk = DocLnk(*lnk2 ); // copy
393 delete lnk2; 394 delete lnk2;
394 break; 395 break;
395 } 396 }