summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/ofileselector.cc123
-rw-r--r--libopie/ofileselector.h15
2 files changed, 111 insertions, 27 deletions
diff --git a/libopie/ofileselector.cc b/libopie/ofileselector.cc
index cb18039..d1f1e1f 100644
--- a/libopie/ofileselector.cc
+++ b/libopie/ofileselector.cc
@@ -39,12 +39,14 @@
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> 42#include <qaction.h>
43#include <qpopupmenu.h> 43#include <qpopupmenu.h>
44#include <qcursor.h> 44#include <qcursor.h>
45#include <qstringlist.h>
46#include <qmessagebox.h>
45 47
46#include <qpe/qpeapplication.h> 48#include <qpe/qpeapplication.h>
47#include <qpe/fileselector.h> 49#include <qpe/fileselector.h>
48#include <qpe/applnk.h> 50#include <qpe/applnk.h>
49#include <qpe/global.h> 51#include <qpe/global.h>
50#include <qpe/mimetype.h> 52#include <qpe/mimetype.h>
@@ -131,12 +133,13 @@ OFileSelector::OFileSelector(QWidget *wid, int mode, int selector, const QString
131 initPics(); 133 initPics();
132 134
133 m_lay = new QVBoxLayout(this); 135 m_lay = new QVBoxLayout(this);
134 init(); 136 init();
135 m_edit->setText( fileName ); 137 m_edit->setText( fileName );
136} 138}
139
137void OFileSelector::initPics() 140void OFileSelector::initPics()
138{ 141{
139 qWarning("init pics" ); 142 qWarning("init pics" );
140 m_pixmaps = new QMap<QString,QPixmap>; 143 m_pixmaps = new QMap<QString,QPixmap>;
141 QPixmap pm = Resource::loadPixmap( "folder" ); 144 QPixmap pm = Resource::loadPixmap( "folder" );
142 QPixmap lnk = Resource::loadPixmap( "opie/symlink" ); 145 QPixmap lnk = Resource::loadPixmap( "opie/symlink" );
@@ -148,13 +151,14 @@ void OFileSelector::initPics()
148 QPixmap pm2 = Resource::loadPixmap( "lockedfolder" ); 151 QPixmap pm2 = Resource::loadPixmap( "lockedfolder" );
149 QPainter pen(&pm2 ); 152 QPainter pen(&pm2 );
150 pen.drawPixmap(pm2.width()-lnk.width(), pm2.height()-lnk.height(), lnk ); 153 pen.drawPixmap(pm2.width()-lnk.width(), pm2.height()-lnk.height(), lnk );
151 pm2.setMask( pm2.createHeuristicMask( FALSE ) ); 154 pm2.setMask( pm2.createHeuristicMask( FALSE ) );
152 m_pixmaps->insert("symlinkedlocked", pm2 ); 155 m_pixmaps->insert("symlinkedlocked", pm2 );
153 156
154}; 157}
158
155// let's initialize the gui 159// let's initialize the gui
156/** 160/**
157 -------------------- 161 --------------------
158 | cmbBox Button | 162 | cmbBox Button |
159 -------------------- 163 --------------------
160 | FileSlector | 164 | FileSlector |
@@ -176,12 +180,13 @@ void OFileSelector::delItems()
176{ 180{
177 QLayoutIterator it = m_lay->iterator(); 181 QLayoutIterator it = m_lay->iterator();
178 while ( it.current() != 0 ){ 182 while ( it.current() != 0 ){
179 it.deleteCurrent(); 183 it.deleteCurrent();
180 } 184 }
181} 185}
186
182void OFileSelector::init() 187void OFileSelector::init()
183{ 188{
184 189
185 m_stack = new QWidgetStack(this, "wstack" ); 190 m_stack = new QWidgetStack(this, "wstack" );
186 if( m_selector == NORMAL ){ 191 if( m_selector == NORMAL ){
187 QString currMime; 192 QString currMime;
@@ -213,13 +218,13 @@ void OFileSelector::init()
213 initializeChooser(); 218 initializeChooser();
214 219
215 if(m_shYesNo ) 220 if(m_shYesNo )
216 initializeYes(); 221 initializeYes();
217 222
218 223
219}; 224}
220 225
221void OFileSelector::setYesCancelVisible( bool show ) 226void OFileSelector::setYesCancelVisible( bool show )
222{ 227{
223 if ( show == m_shYesNo ) 228 if ( show == m_shYesNo )
224 return; 229 return;
225 m_shYesNo = show; 230 m_shYesNo = show;
@@ -258,12 +263,13 @@ void OFileSelector::setPermissionBarVisible( bool show )
258 return; 263 return;
259 264
260 m_shPerm = show; 265 m_shPerm = show;
261 266
262 updateLay(); 267 updateLay();
263} 268}
269
264void OFileSelector::setLineEditVisible( bool show ) 270void OFileSelector::setLineEditVisible( bool show )
265{ 271{
266 if( show == m_shLne ) 272 if( show == m_shLne )
267 return; 273 return;
268 274
269 m_shLne = show; 275 m_shLne = show;
@@ -273,12 +279,13 @@ void OFileSelector::setLineEditVisible( bool show )
273 m_edit = 0; 279 m_edit = 0;
274 m_fnLabel = 0; 280 m_fnLabel = 0;
275 //delete m_boxName; will be deleted 281 //delete m_boxName; will be deleted
276 } 282 }
277 updateLay(); 283 updateLay();
278} 284}
285
279void OFileSelector::setChooserVisible( bool show ) 286void OFileSelector::setChooserVisible( bool show )
280{ 287{
281 if( show = m_shChooser ) 288 if( show = m_shChooser )
282 return; 289 return;
283 m_shChooser = show; 290 m_shChooser = show;
284 if( !show ){ 291 if( !show ){
@@ -286,43 +293,50 @@ void OFileSelector::setChooserVisible( bool show )
286 delete m_viewCheck; 293 delete m_viewCheck;
287 m_mimeCheck = 0; 294 m_mimeCheck = 0;
288 m_viewCheck = 0; 295 m_viewCheck = 0;
289 } 296 }
290 updateLay(); 297 updateLay();
291} 298}
299
292QCheckBox* OFileSelector::permissionCheckbox( ) 300QCheckBox* OFileSelector::permissionCheckbox( )
293{ 301{
294 return m_checkPerm; 302 return m_checkPerm;
295} 303}
304
296void OFileSelector::setCaseSensetive( bool caSe ) 305void OFileSelector::setCaseSensetive( bool caSe )
297{ 306{
298 m_case = caSe; 307 m_case = caSe;
299 reparse(); 308 reparse();
300} 309}
310
301void OFileSelector::setShowFiles(bool files ){ 311void OFileSelector::setShowFiles(bool files ){
302 m_files = files; 312 m_files = files;
303 reparse(); 313 reparse();
304} 314}
315
305void OFileSelector::setPopupMenu(QPopupMenu *pop ) 316void OFileSelector::setPopupMenu(QPopupMenu *pop )
306{ 317{
307 //delete oldpopup; 318 //delete oldpopup;
308 m_custom = pop; 319 m_custom = pop;
309} 320}
321
310bool OFileSelector::setPermission( ) const 322bool OFileSelector::setPermission( ) const
311{ 323{
312 if( m_checkPerm == 0 ) 324 if( m_checkPerm == 0 )
313 return false; 325 return false;
314 else 326 else
315 return m_checkPerm->isChecked(); 327 return m_checkPerm->isChecked();
316} 328}
329
317void OFileSelector::setPermissionChecked( bool check ) 330void OFileSelector::setPermissionChecked( bool check )
318{ 331{
319 if( m_checkPerm == 0 ) 332 if( m_checkPerm == 0 )
320 return; 333 return;
321 m_checkPerm->setChecked( check ); 334 m_checkPerm->setChecked( check );
322} 335}
336
323QString OFileSelector::selectedName( )const 337QString OFileSelector::selectedName( )const
324{ 338{
325 QString string; 339 QString string;
326 if( m_selector == NORMAL ){ 340 if( m_selector == NORMAL ){
327 const DocLnk *lnk = m_select->selected(); 341 const DocLnk *lnk = m_select->selected();
328 string = lnk->file(); 342 string = lnk->file();
@@ -331,17 +345,19 @@ QString OFileSelector::selectedName( )const
331 if(item != 0 ){ 345 if(item != 0 ){
332 string = m_currentDir + "/" + item->text( 1 ); 346 string = m_currentDir + "/" + item->text( 1 );
333 } 347 }
334 } 348 }
335 return string; 349 return string;
336} 350}
351
337QStringList OFileSelector::selectedNames()const 352QStringList OFileSelector::selectedNames()const
338{ 353{
339 QStringList list; 354 QStringList list;
340 return list; 355 return list;
341} 356}
357
342DocLnk OFileSelector::selectedDocument( )const 358DocLnk OFileSelector::selectedDocument( )const
343{ 359{
344 DocLnk lnk; 360 DocLnk lnk;
345 return lnk; 361 return lnk;
346} 362}
347void OFileSelector::updateLay() 363void OFileSelector::updateLay()
@@ -382,12 +398,13 @@ void OFileSelector::updateLay()
382 init(); 398 init();
383 if( m_shLne ) 399 if( m_shLne )
384 m_edit->setText(text ); 400 m_edit->setText(text );
385 if( m_shPerm ) 401 if( m_shPerm )
386 m_checkPerm->setChecked(check ); 402 m_checkPerm->setChecked(check );
387} 403}
404
388// let's update the mimetypes. Use the current mimefilter for the 2nd QDir retrieve 405// let's update the mimetypes. Use the current mimefilter for the 2nd QDir retrieve
389// insert QListViewItems with the right options 406// insert QListViewItems with the right options
390bool OFileSelector::compliesMime(const QString &path, const QString &mime ) 407bool OFileSelector::compliesMime(const QString &path, const QString &mime )
391{ 408{
392 if( mime == "All" ) 409 if( mime == "All" )
393 return true; 410 return true;
@@ -429,12 +446,13 @@ void OFileSelector::reparse()
429 } 446 }
430 m_mimetypes.prepend("All" ); 447 m_mimetypes.prepend("All" );
431 m_mimeCheck->insertStringList(m_mimetypes ); 448 m_mimeCheck->insertStringList(m_mimetypes );
432 // set it to the current mimetype 449 // set it to the current mimetype
433 m_mimeCheck->setCurrentItem( indexByString( m_mimeCheck, currMime ) ); 450 m_mimeCheck->setCurrentItem( indexByString( m_mimeCheck, currMime ) );
434 }; 451 };
452
435 QDir dir( m_currentDir ); 453 QDir dir( m_currentDir );
436 //dir.setFilter(-1 ); 454 //dir.setFilter(-1 );
437 int sort = QDir::Name | QDir::DirsFirst | QDir::Reversed; 455 int sort = QDir::Name | QDir::DirsFirst | QDir::Reversed;
438 if( m_case ) 456 if( m_case )
439 sort = QDir::IgnoreCase; 457 sort = QDir::IgnoreCase;
440 dir.setSorting( sort ); 458 dir.setSorting( sort );
@@ -494,24 +512,29 @@ void OFileSelector::reparse()
494 addFile(currMime, fi ); 512 addFile(currMime, fi );
495 } 513 }
496 ++it; 514 ++it;
497 } 515 }
498 m_View->sort(); 516 m_View->sort();
499} 517}
518
500QString OFileSelector::directory()const 519QString OFileSelector::directory()const
501{ 520{
502 return m_currentDir; 521 QDir d( m_currentDir);
522 return d.absPath();
503} 523}
524
504int OFileSelector::fileCount() 525int OFileSelector::fileCount()
505{ 526{
506 return 0; 527 return 0;
507} 528}
529
508void OFileSelector::slotOk( ) 530void OFileSelector::slotOk( )
509{ 531{
510 emit ok(); 532 emit ok();
511} 533}
534
512void OFileSelector::slotCancel( ) 535void OFileSelector::slotCancel( )
513{ 536{
514 emit cancel(); 537 emit cancel();
515} 538}
516 539
517void OFileSelector::initializeName() 540void OFileSelector::initializeName()
@@ -523,12 +546,13 @@ void OFileSelector::initializeName()
523 m_boxName->addWidget(m_fnLabel ); 546 m_boxName->addWidget(m_fnLabel );
524 m_boxName->insertSpacing(1, 8 ); 547 m_boxName->insertSpacing(1, 8 );
525 m_boxName->addWidget(m_edit, 100 ); 548 m_boxName->addWidget(m_edit, 100 );
526 549
527 m_lay->addLayout(m_boxName); 550 m_lay->addLayout(m_boxName);
528} 551}
552
529void OFileSelector::initializeYes() 553void OFileSelector::initializeYes()
530{ 554{
531 m_ok = new QPushButton("&Save", this, "save" ); 555 m_ok = new QPushButton("&Save", this, "save" );
532 m_cancel = new QPushButton("C&ancel", this, "cancel" ); 556 m_cancel = new QPushButton("C&ancel", this, "cancel" );
533 m_boxOk = new QHBoxLayout(this ); 557 m_boxOk = new QHBoxLayout(this );
534 m_boxOk->addWidget( m_ok, Qt::AlignHCenter ); 558 m_boxOk->addWidget( m_ok, Qt::AlignHCenter );
@@ -538,12 +562,13 @@ void OFileSelector::initializeYes()
538 connect(m_ok, SIGNAL(clicked() ), 562 connect(m_ok, SIGNAL(clicked() ),
539 this, SLOT(slotOk() ) ); 563 this, SLOT(slotOk() ) );
540 connect(m_cancel, SIGNAL(clicked() ), 564 connect(m_cancel, SIGNAL(clicked() ),
541 this, SLOT(slotCancel() ) ); 565 this, SLOT(slotCancel() ) );
542 566
543} 567}
568
544void OFileSelector::initializeChooser() 569void OFileSelector::initializeChooser()
545{ 570{
546 m_boxView = new QHBoxLayout(this ); 571 m_boxView = new QHBoxLayout(this );
547 572
548 m_mimeCheck = new QComboBox(this, "mime check"); 573 m_mimeCheck = new QComboBox(this, "mime check");
549 m_viewCheck = new QComboBox(this, "view check"); 574 m_viewCheck = new QComboBox(this, "view check");
@@ -567,12 +592,13 @@ void OFileSelector::initializeChooser()
567 connect( m_viewCheck, SIGNAL(activated(const QString &) ), 592 connect( m_viewCheck, SIGNAL(activated(const QString &) ),
568 this, SLOT(slotViewCheck(const QString & ) ) ); 593 this, SLOT(slotViewCheck(const QString & ) ) );
569 594
570 connect( m_mimeCheck, SIGNAL(activated(const QString &) ), 595 connect( m_mimeCheck, SIGNAL(activated(const QString &) ),
571 this, SLOT(slotMimeCheck(const QString & ) ) ); 596 this, SLOT(slotMimeCheck(const QString & ) ) );
572} 597}
598
573void OFileSelector::slotMimeCheck(const QString &view ){ 599void OFileSelector::slotMimeCheck(const QString &view ){
574 if(m_selector == NORMAL ){ 600 if(m_selector == NORMAL ){
575 delete m_select; 601 delete m_select;
576 m_select = new FileSelector(view == "All" ? QString::null : view 602 m_select = new FileSelector(view == "All" ? QString::null : view
577 , m_stack, "fileselector", FALSE, FALSE ); 603 , m_stack, "fileselector", FALSE, FALSE );
578 m_stack->addWidget( m_select, NORMAL ); 604 m_stack->addWidget( m_select, NORMAL );
@@ -642,13 +668,13 @@ void OFileSelector::slotViewCheck(const QString &view ){
642 m_View = 0; 668 m_View = 0;
643 669
644 m_selector = EXTENDED_ALL; 670 m_selector = EXTENDED_ALL;
645 initializeListView(); 671 initializeListView();
646 reparse(); 672 reparse();
647 }; 673 };
648}; 674}
649 675
650 676
651void OFileSelector::updateMimes() // lets check which mode is active 677void OFileSelector::updateMimes() // lets check which mode is active
652 // check the current dir for items then 678 // check the current dir for items then
653{ 679{
654 m_mimetypes.clear(); 680 m_mimetypes.clear();
@@ -662,13 +688,14 @@ void OFileSelector::updateMimes() // lets check which mode is active
662 m_mimetypes.append( (*dit)->type() ); 688 m_mimetypes.append( (*dit)->type() );
663 } 689 }
664 }else{ 690 }else{
665 // should be allreday updatet 691 // should be allreday updatet
666 ; 692 ;
667 } 693 }
668}; 694}
695
669void OFileSelector::initializeListView() 696void OFileSelector::initializeListView()
670{ 697{
671 // just to make sure but clean it up better FIXME 698 // just to make sure but clean it up better FIXME
672 delete m_View; 699 delete m_View;
673 m_View = 0; 700 m_View = 0;
674 delete m_boxToolbar; 701 delete m_boxToolbar;
@@ -690,12 +717,13 @@ void OFileSelector::initializeListView()
690 m_pseudo = new QWidget(m_stack, "Pseudo Widget"); 717 m_pseudo = new QWidget(m_stack, "Pseudo Widget");
691 m_pseudoLayout = new QVBoxLayout(m_pseudo ); 718 m_pseudoLayout = new QVBoxLayout(m_pseudo );
692 if(m_shTool ){ 719 if(m_shTool ){
693 m_boxToolbar = new QHBoxLayout( ); 720 m_boxToolbar = new QHBoxLayout( );
694 m_boxToolbar->setAutoAdd( true ); 721 m_boxToolbar->setAutoAdd( true );
695 m_location = new QComboBox(m_pseudo ); 722 m_location = new QComboBox(m_pseudo );
723 connect( m_location, SIGNAL(activated(const QString &) ), this, SLOT( locationComboActivated(const QString & ) ) );
696 724
697 m_up = new QPushButton(Resource::loadIconSet("up"),"", m_pseudo,"cdUpButton"); 725 m_up = new QPushButton(Resource::loadIconSet("up"),"", m_pseudo,"cdUpButton");
698 m_up->setFixedSize( QSize( 20, 20 ) ); 726 m_up->setFixedSize( QSize( 20, 20 ) );
699 connect(m_up ,SIGNAL(clicked()),this,SLOT(cdUP() ) ); 727 connect(m_up ,SIGNAL(clicked()),this,SLOT(cdUP() ) );
700 m_up->setFlat(TRUE); 728 m_up->setFlat(TRUE);
701 729
@@ -802,12 +830,13 @@ void OFileSelector::addFile(const QString &mime, QFileInfo *info, bool symlink )
802 } 830 }
803 new OFileSelectorItem( m_View, pix, name, 831 new OFileSelectorItem( m_View, pix, name,
804 info->lastModified().toString(), 832 info->lastModified().toString(),
805 QString::number( info->size() ), 833 QString::number( info->size() ),
806 dir, locked ); 834 dir, locked );
807} 835}
836
808void OFileSelector::addDir(const QString &mime, QFileInfo *info, bool symlink ) 837void OFileSelector::addDir(const QString &mime, QFileInfo *info, bool symlink )
809{ 838{
810 if(!m_dir ) 839 if(!m_dir )
811 return; 840 return;
812 //if( showDirs ) 841 //if( showDirs )
813 { 842 {
@@ -839,12 +868,13 @@ void OFileSelector::addDir(const QString &mime, QFileInfo *info, bool symlink )
839 new OFileSelectorItem(m_View, pix, 868 new OFileSelectorItem(m_View, pix,
840 name, info->lastModified().toString(), 869 name, info->lastModified().toString(),
841 QString::number(info->size() ),info->dirPath(true), locked, true ); 870 QString::number(info->size() ),info->dirPath(true), locked, true );
842 871
843 } 872 }
844} 873}
874
845void OFileSelector::setShowDirs(bool dir ) 875void OFileSelector::setShowDirs(bool dir )
846{ 876{
847 m_dir = dir; 877 m_dir = dir;
848 reparse(); 878 reparse();
849} 879}
850 880
@@ -853,22 +883,25 @@ void OFileSelector::slotFileSelected(const QString &string )
853 if(m_shLne ) 883 if(m_shLne )
854 m_edit->setText( string ); 884 m_edit->setText( string );
855 885
856 emit fileSelected( string ); 886 emit fileSelected( string );
857 // do AppLnk stuff 887 // do AppLnk stuff
858} 888}
889
859void OFileSelector::slotFileBridgeSelected( const DocLnk &lnk ) 890void OFileSelector::slotFileBridgeSelected( const DocLnk &lnk )
860{ 891{
861 slotFileSelected(lnk.name() ); 892 slotFileSelected(lnk.name() );
862 emit fileSelected( lnk ); 893 emit fileSelected( lnk );
863} 894}
895
864void OFileSelector::slotSelectionChanged() // get the current items 896void OFileSelector::slotSelectionChanged() // get the current items
865 // fixme 897 // fixme
866{ 898{
867 qWarning("selection changed" ); 899 qWarning("selection changed" );
868} 900}
901
869void OFileSelector::slotCurrentChanged(QListViewItem *item ) 902void OFileSelector::slotCurrentChanged(QListViewItem *item )
870{ 903{
871 qWarning("current changed" ); 904 qWarning("current changed" );
872 if( item == 0 ) 905 if( item == 0 )
873 return; 906 return;
874 907
@@ -882,12 +915,13 @@ void OFileSelector::slotCurrentChanged(QListViewItem *item )
882 } 915 }
883 } 916 }
884 }else { 917 }else {
885 qWarning("mode not extended" ); 918 qWarning("mode not extended" );
886 } 919 }
887} 920}
921
888// either select or change dir 922// either select or change dir
889void OFileSelector::slotClicked( int button, QListViewItem *item, const QPoint &point, int ) 923void OFileSelector::slotClicked( int button, QListViewItem *item, const QPoint &point, int )
890{ 924{
891 if( item == 0 ) 925 if( item == 0 )
892 return; 926 return;
893 927
@@ -898,35 +932,37 @@ void OFileSelector::slotClicked( int button, QListViewItem *item, const QPoint &
898 if(m_selector == EXTENDED || m_selector == EXTENDED_ALL ){ 932 if(m_selector == EXTENDED || m_selector == EXTENDED_ALL ){
899 qWarning("inside" ); 933 qWarning("inside" );
900 OFileSelectorItem *sel = (OFileSelectorItem*)item; 934 OFileSelectorItem *sel = (OFileSelectorItem*)item;
901 if(!sel->isLocked() ){ // not locked either changedir or open 935 if(!sel->isLocked() ){ // not locked either changedir or open
902 QStringList str = QStringList::split("->", sel->text(1) ); 936 QStringList str = QStringList::split("->", sel->text(1) );
903 if(sel->isDir() ){ 937 if(sel->isDir() ){
904 cd( sel->directory() + "/" + str[0] ); 938 cd( sel->directory() + "/" + str[0] );
905 }else{ 939 } else {
906 qWarning("file" ); 940 qWarning("file" );
907 if(m_shLne ) 941 if(m_shLne )
908 m_edit->setText(str[0] ); 942 m_edit->setText(str[0] );
909 emit fileSelected(str[0] ); 943 emit fileSelected(str[0] );
910 // emit DocLnk need to do it 944 // emit DocLnk need to do it
911 } 945 }
912 }else{ 946 } else {
913 qWarning( "locked" ); 947 qWarning( "locked" );
914 } 948 }
915 }; 949 };
916} 950}
951
917void OFileSelector::slotRightButton(int button, QListViewItem *item, const QPoint &, int ) 952void OFileSelector::slotRightButton(int button, QListViewItem *item, const QPoint &, int )
918{ 953{
919 if (item == 0 ) 954 if (item == 0 )
920 return; 955 return;
921 956
922 if( button != Qt::RightButton ) 957 if( button != Qt::RightButton )
923 return; 958 return;
924 qWarning("right button" ); 959 qWarning("right button" );
925 slotContextMenu(item); 960 slotContextMenu(item);
926} 961}
962
927void OFileSelector::slotContextMenu(QListViewItem *item) 963void OFileSelector::slotContextMenu(QListViewItem *item)
928{ 964{
929 qWarning("context menu" ); 965 qWarning("context menu" );
930 if( item ==0 || !m_showPopup ) 966 if( item ==0 || !m_showPopup )
931 return; 967 return;
932 968
@@ -972,62 +1008,88 @@ void OFileSelector::slotContextMenu(QListViewItem *item)
972 connect(&delItem, SIGNAL(activated() ), 1008 connect(&delItem, SIGNAL(activated() ),
973 this, SLOT(slotDelete() ) ); 1009 this, SLOT(slotDelete() ) );
974 1010
975 menu.exec(QCursor::pos() ); 1011 menu.exec(QCursor::pos() );
976 } 1012 }
977} 1013}
1014
978bool OFileSelector::cd(const QString &str ) 1015bool OFileSelector::cd(const QString &str )
979{ 1016{
980 qWarning(" dir %s", str.latin1() ); 1017 qWarning(" dir %s", str.latin1() );
981 QDir dir( str); 1018 QDir dir( str);
982 if(dir.exists() ){ 1019 if(dir.exists() ){
983 m_currentDir = str; 1020 m_currentDir = dir.absPath();
984 reparse(); 1021 reparse();
985 if(m_shTool ){ 1022 if(m_shTool ){
986 int count = m_location->count(); 1023 int count = m_location->count();
987 m_location->insertItem(str ); 1024 insertLocationPath( str ,count );
988 m_location->setCurrentItem( count ); 1025 m_location->setCurrentItem( count );
989 } 1026 }
990 return true; 1027 return true;
991 } 1028 }
992 return false; 1029 return false;
993} 1030}
994 1031
1032void OFileSelector::insertLocationPath(const QString &currentPath, int count) {
1033 QStringList pathList;
1034 for(int i=0;i<count;i++) {
1035 pathList << m_location->text(i);
1036 }
1037 if( pathList.grep( currentPath,TRUE).isEmpty() ) {
1038 m_location->clear();
1039 if( currentPath.left(2)=="//")
1040 pathList.append( currentPath.right(currentPath.length()-1) );
1041 else
1042 pathList.append( currentPath );
1043 m_location->insertStringList( pathList,-1);
1044 }
1045}
1046
995void OFileSelector::slotChangedDir() 1047void OFileSelector::slotChangedDir()
996{ 1048{
997 OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem(); 1049 OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem();
998 if(sel->isDir() ){ 1050 if(sel->isDir() ){
999 QStringList str = QStringList::split("->", sel->text(1) ); 1051 QStringList str = QStringList::split("->", sel->text(1) );
1000 cd( sel->directory() + "/" + str[0] ); 1052 cd( sel->directory() + "/" + str[0] );
1053
1001 } 1054 }
1002} 1055}
1056
1003void OFileSelector::slotOpen() 1057void OFileSelector::slotOpen()
1004{ 1058{
1005 OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem(); 1059 OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem();
1006 if(!sel->isDir() ){ 1060 if(!sel->isDir() ){
1007 QStringList str = QStringList::split("->", sel->text(1) ); 1061 QStringList str = QStringList::split("->", sel->text(1) );
1008 slotFileSelected( str[0] ); 1062 slotFileSelected( str[0] );
1009 } 1063 }
1010} 1064}
1065
1011void OFileSelector::slotRescan() 1066void OFileSelector::slotRescan()
1012{ 1067{
1013 reparse(); 1068 reparse();
1014} 1069}
1070
1015void OFileSelector::slotRename() 1071void OFileSelector::slotRename()
1016{ 1072{
1017 // rename inline 1073 // rename inline
1018} 1074}
1075
1019void OFileSelector::slotDelete() 1076void OFileSelector::slotDelete()
1020{ 1077{
1021 qWarning("delete slot" ); 1078 qWarning("delete slot" );
1022 OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem(); 1079 OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem();
1023 QStringList list = QStringList::split("->", sel->text(1) ); 1080 QStringList list = QStringList::split("->", sel->text(1) );
1024 if( sel->isDir() ){ 1081 if( sel->isDir() ){
1025 QString str = QString::fromLatin1("rm -rf ") + list[0]; 1082 QString str = QString::fromLatin1("rm -rf ") + list[0]; //better safe than sorry
1026 ::system(str.utf8().data() ); 1083 switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+list[0],
1027 }else{ 1084 tr("Yes"),tr("No"),0,1,1) ) {
1085 case 0:
1086 ::system(str.utf8().data() );
1087 break;
1088 }
1089 } else {
1028 QFile::remove( list[0] ); 1090 QFile::remove( list[0] );
1029 } 1091 }
1030 m_View->takeItem( sel ); 1092 m_View->takeItem( sel );
1031 delete sel; 1093 delete sel;
1032} 1094}
1033 1095
@@ -1036,22 +1098,41 @@ void OFileSelector::cdUP()
1036 QDir dir( m_currentDir ); 1098 QDir dir( m_currentDir );
1037 dir.cdUp(); 1099 dir.cdUp();
1038 if(dir.exists() ){ 1100 if(dir.exists() ){
1039 m_currentDir = dir.absPath(); 1101 m_currentDir = dir.absPath();
1040 reparse(); 1102 reparse();
1041 int count = m_location->count(); 1103 int count = m_location->count();
1042 m_location->insertItem(m_currentDir ); 1104 insertLocationPath( m_currentDir,count );
1043 m_location->setCurrentItem( count ); 1105 m_location->setCurrentItem( indexFromString(m_currentDir ));
1106//this wont work in all instances
1107 // FIXME
1044 } 1108 }
1045} 1109}
1110
1111int OFileSelector::indexFromString(const QString &str) {
1112
1113 for(int i=0;i< m_location->count();i++) {
1114 if(str == m_location->text(i))
1115 return i;
1116 }
1117 return 0;
1118}
1119
1046void OFileSelector::slotHome() 1120void OFileSelector::slotHome()
1047{ 1121{
1048 cd(QDir::homeDirPath() ); 1122 cd(QDir::homeDirPath() );
1049} 1123}
1124
1050void OFileSelector::slotDoc() 1125void OFileSelector::slotDoc()
1051{ 1126{
1052 cd(QDir::homeDirPath() + "/Documents" ); 1127 cd(QDir::homeDirPath() + "/Documents" );
1053} 1128}
1129
1054void OFileSelector::slotNavigate() 1130void OFileSelector::slotNavigate()
1055{ 1131{
1056 1132
1057} 1133}
1134
1135void OFileSelector::locationComboActivated(const QString & file ) {
1136 cd(file.left(file.find("<-",0,TRUE)));
1137 reparse();
1138}
diff --git a/libopie/ofileselector.h b/libopie/ofileselector.h
index 5e98a1e..81a9e63 100644
--- a/libopie/ofileselector.h
+++ b/libopie/ofileselector.h
@@ -64,14 +64,14 @@ class 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;
@@ -91,17 +91,17 @@ class OFileSelectorItem : public QListViewItem {
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 }
@@ -187,12 +187,15 @@ class OFileSelector : public QWidget {
187 187
188 protected slots: 188 protected slots:
189 void slotOk(); 189 void slotOk();
190 void slotCancel(); 190 void slotCancel();
191 void slotViewCheck(const QString & ); 191 void slotViewCheck(const QString & );
192 void slotMimeCheck(const QString & ); 192 void slotMimeCheck(const QString & );
193 void locationComboActivated(const QString & );
194 void insertLocationPath(const QString &, int);
195 int indexFromString(const QString &);
193 protected: 196 protected:
194 void init(); 197 void init();
195 void updateMimes(); 198 void updateMimes();
196 199
197 protected: 200 protected:
198 201