summaryrefslogtreecommitdiffabout
path: root/microkde/ofileselector_p.cpp
Unidiff
Diffstat (limited to 'microkde/ofileselector_p.cpp') (more/less context) (show whitespace changes)
-rw-r--r--microkde/ofileselector_p.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/microkde/ofileselector_p.cpp b/microkde/ofileselector_p.cpp
index fd5f965..f85f8f4 100644
--- a/microkde/ofileselector_p.cpp
+++ b/microkde/ofileselector_p.cpp
@@ -340,147 +340,173 @@ void OFileViewFileListView::reread( bool all ) {
340 continue; 340 continue;
341 } 341 }
342 342
343 /* 343 /*
344 * It is a symlink we try to resolve it now but don't let us attack by DOS 344 * It is a symlink we try to resolve it now but don't let us attack by DOS
345 * 345 *
346 */ 346 */
347 if( fi->isSymLink() ){ 347 if( fi->isSymLink() ){
348 QString file = fi->dirPath( true ) + "/" + fi->readLink(); 348 QString file = fi->dirPath( true ) + "/" + fi->readLink();
349 for( int i = 0; i<=4; i++) { // 5 tries to prevent dos 349 for( int i = 0; i<=4; i++) { // 5 tries to prevent dos
350 QFileInfo info( file ); 350 QFileInfo info( file );
351 if( !info.exists() ){ 351 if( !info.exists() ){
352 addSymlink( fi, TRUE ); 352 addSymlink( fi, TRUE );
353 break; 353 break;
354 }else if( info.isDir() ){ 354 }else if( info.isDir() ){
355 addDir( fi, TRUE ); 355 addDir( fi, TRUE );
356 break; 356 break;
357 }else if( info.isFile() ){ 357 }else if( info.isFile() ){
358 addFile( fi, TRUE ); 358 addFile( fi, TRUE );
359 break; 359 break;
360 }else if( info.isSymLink() ){ 360 }else if( info.isSymLink() ){
361 file = info.dirPath(true ) + "/" + info.readLink() ; 361 file = info.dirPath(true ) + "/" + info.readLink() ;
362 break; 362 break;
363 }else if( i == 4){ // couldn't resolve symlink add it as symlink 363 }else if( i == 4){ // couldn't resolve symlink add it as symlink
364 addSymlink( fi ); 364 addSymlink( fi );
365 } 365 }
366 } // off for loop for symlink resolving 366 } // off for loop for symlink resolving
367 }else if( fi->isDir() ) 367 }else if( fi->isDir() )
368 addDir( fi ); 368 addDir( fi );
369 else if( fi->isFile() ) 369 else if( fi->isFile() )
370 addFile( fi ); 370 addFile( fi );
371 371
372 ++it; 372 ++it;
373 } // of while loop 373 } // of while loop
374 m_view->sort(); 374 m_view->sort();
375 375
376} 376}
377int OFileViewFileListView::fileCount()const{ 377int OFileViewFileListView::fileCount()const{
378 return m_view->childCount(); 378 return m_view->childCount();
379} 379}
380QString OFileViewFileListView::currentDir()const{ 380QString OFileViewFileListView::currentDir()const{
381 return m_currentDir; 381 return m_currentDir;
382} 382}
383OFileSelector* OFileViewFileListView::selector() { 383OFileSelector* OFileViewFileListView::selector() {
384 return m_sel; 384 return m_sel;
385} 385}
386 386
387bool OFileViewFileListView::eventFilter (QObject *o, QEvent *e) { 387bool OFileViewFileListView::eventFilter (QObject *o, QEvent *e) {
388#if 0
388 if ( e->type() == QEvent::KeyPress ) { 389 if ( e->type() == QEvent::KeyPress ) {
389 QKeyEvent *k = (QKeyEvent *)e; 390 QKeyEvent *k = (QKeyEvent *)e;
390 if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) { 391 if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) {
391 slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0); 392 slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0);
392 return true; 393 return true;
393 } 394 }
394 } 395 }
396#endif
395 return false; 397 return false;
396} 398}
397 399
398 400
399void OFileViewFileListView::connectSlots() { 401void OFileViewFileListView::connectSlots() {
400 connect(m_view, SIGNAL(clicked(QListViewItem*) ), 402 connect(m_view, SIGNAL(clicked(QListViewItem*) ),
401 this, SLOT(slotCurrentChanged(QListViewItem*) ) ); 403 this, SLOT(slotCurrentChanged(QListViewItem*) ) );
402 connect(m_view, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint&, int ) ), 404 connect(m_view, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint&, int ) ),
403 this, SLOT(slotClicked(int, QListViewItem*, const QPoint&, int ) ) ); 405 this, SLOT(slotClicked(int, QListViewItem*, const QPoint&, int ) ) );
406 connect(m_view, SIGNAL(doubleClicked( QListViewItem* )),
407 this, SLOT(slotDoubleClicked(QListViewItem* ) ) );
408 connect(m_view, SIGNAL(returnPressed( QListViewItem* )),
409 this, SLOT(slotDoubleClicked(QListViewItem* ) ) );
404} 410}
405void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) { 411void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) {
406 if (!item) 412 if (!item)
407 return; 413 return;
408#if 0 414#if 0
409 415
410 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); 416 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item);
411 417
412 if (!sel->isDir() ) { 418 if (!sel->isDir() ) {
413 selector()->m_lneEdit->setText( sel->text(1) ); 419 selector()->m_lneEdit->setText( sel->text(1) );
414 // if in fileselector mode we will emit selected 420 // if in fileselector mode we will emit selected
415 if ( selector()->mode() == OFileSelector::FileSelector ) { 421 if ( selector()->mode() == OFileSelector::FileSelector ) {
416 qWarning("slot Current Changed"); 422 qWarning("slot Current Changed");
417 QStringList str = QStringList::split("->", sel->text(1) ); 423 QStringList str = QStringList::split("->", sel->text(1) );
418 QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); 424 QString path = sel->directory() + "/" + str[0].stripWhiteSpace();
419 emit selector()->fileSelected( path ); 425 emit selector()->fileSelected( path );
420 DocLnk lnk( path ); 426 DocLnk lnk( path );
421 emit selector()->fileSelected( lnk ); 427 emit selector()->fileSelected( lnk );
422 } 428 }
423 } 429 }
424#endif 430#endif
425} 431}
432void OFileViewFileListView::slotDoubleClicked(QListViewItem* item ) {
433 if (!item ) return;
434 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item);
435 if (!sel->isLocked() ) {
436 QStringList str = QStringList::split("->", sel->text(1) );
437 if (sel->isDir() ) {
438 m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace();
439 emit selector()->dirSelected( m_currentDir );
440 reread( m_all );
441 }else { // file
442 //qWarning("slot Clicked");
443 selector()->m_lneEdit->setText( str[0].stripWhiteSpace() );
444 QString path = sel->directory() + "/" + str[0].stripWhiteSpace();
445 emit selector()->fileSelected( path );
446 DocLnk lnk( path );
447 emit selector()->fileSelected( lnk );
448 emit selector()->ok();
449 }
450 } // not locked
451}
426void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) { 452void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) {
427 if (!item || ( button != Qt::LeftButton) ) 453 if (!item || ( button != Qt::LeftButton) )
428 return; 454 return;
429 455
430 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); 456 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item);
431 if (!sel->isLocked() ) { 457 if (!sel->isLocked() ) {
432 QStringList str = QStringList::split("->", sel->text(1) ); 458 QStringList str = QStringList::split("->", sel->text(1) );
433 if (sel->isDir() ) { 459 if (sel->isDir() ) {
434 m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace(); 460 m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace();
435 emit selector()->dirSelected( m_currentDir ); 461 emit selector()->dirSelected( m_currentDir );
436 reread( m_all ); 462 reread( m_all );
437 }else { // file 463 }else { // file
438 qWarning("slot Clicked"); 464 //qWarning("slot Clicked");
439 selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); 465 selector()->m_lneEdit->setText( str[0].stripWhiteSpace() );
440 QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); 466 QString path = sel->directory() + "/" + str[0].stripWhiteSpace();
441 emit selector()->fileSelected( path ); 467 emit selector()->fileSelected( path );
442 DocLnk lnk( path ); 468 DocLnk lnk( path );
443 emit selector()->fileSelected( lnk ); 469 emit selector()->fileSelected( lnk );
444 } 470 }
445 } // not locked 471 } // not locked
446} 472}
447void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) { 473void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) {
448 MimeType type( info->absFilePath() ); 474 MimeType type( info->absFilePath() );
449 if (!compliesMime( type.id() ) ) 475 if (!compliesMime( type.id() ) )
450 return; 476 return;
451 477
452 QPixmap pix = type.pixmap(); 478 QPixmap pix = type.pixmap();
453 QString dir, name; bool locked; 479 QString dir, name; bool locked;
454 if ( pix.isNull() ) { 480 if ( pix.isNull() ) {
455 QWMatrix matrix; 481 QWMatrix matrix;
456 QPixmap pixer(Resource::loadPixmap("UnknownDocument") ); 482 QPixmap pixer(Resource::loadPixmap("UnknownDocument") );
457 matrix.scale( .4, .4 ); 483 matrix.scale( .4, .4 );
458 pix = pixer.xForm( matrix ); 484 pix = pixer.xForm( matrix );
459 } 485 }
460 dir = info->dirPath( true ); 486 dir = info->dirPath( true );
461 locked = false; 487 locked = false;
462 if ( symlink ) 488 if ( symlink )
463 name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink(); 489 name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink();
464 else{ 490 else{
465 name = info->fileName(); 491 name = info->fileName();
466 if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) || 492 if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) ||
467 ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) { 493 ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) {
468 locked = true; pix = Resource::loadPixmap("locked"); 494 locked = true; pix = Resource::loadPixmap("locked");
469 } 495 }
470 } 496 }
471 (void)new OFileSelectorItem( m_view, pix, name, 497 (void)new OFileSelectorItem( m_view, pix, name,
472 KGlobal::locale()->formatDateTime(info->lastModified(),true, true, KLocale::ISODate), 498 KGlobal::locale()->formatDateTime(info->lastModified(),true, true, KLocale::ISODate),
473 QString::number( info->size() ), 499 QString::number( info->size() ),
474 dir, locked ); 500 dir, locked );
475} 501}
476void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) { 502void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) {
477 bool locked = false; QString name; QPixmap pix; 503 bool locked = false; QString name; QPixmap pix;
478 504
479 if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) || 505 if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) ||
480 ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) { 506 ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) {
481 locked = true; 507 locked = true;
482 if ( symlink ) 508 if ( symlink )
483 pix = Resource::loadPixmap( "symlink" ); 509 pix = Resource::loadPixmap( "symlink" );
484 else 510 else
485 pix = Resource::loadPixmap( "lockedfolder" ); 511 pix = Resource::loadPixmap( "lockedfolder" );
486 }else 512 }else