summaryrefslogtreecommitdiff
path: root/libopie
authorzecke <zecke>2002-03-30 23:26:49 (UTC)
committer zecke <zecke>2002-03-30 23:26:49 (UTC)
commit5d12c8fb75458262f6414073759b4c610f615525 (patch) (unidiff)
tree45a3158271b748c6e5ff98afcf7014a25cd447d8 /libopie
parentf3376cde32aa6a03070fb8f2d1428cedcbe49425 (diff)
downloadopie-5d12c8fb75458262f6414073759b4c610f615525.zip
opie-5d12c8fb75458262f6414073759b4c610f615525.tar.gz
opie-5d12c8fb75458262f6414073759b4c610f615525.tar.bz2
This time thanks to tronical (Simon Hausmann) for reviewing the interface
the selector is almost done so better start porting to it A dialog will come when beeing done with the real widget
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/ofileselector.cc134
-rw-r--r--libopie/ofileselector.h11
2 files changed, 111 insertions, 34 deletions
diff --git a/libopie/ofileselector.cc b/libopie/ofileselector.cc
index 61ab2c4..1807575 100644
--- a/libopie/ofileselector.cc
+++ b/libopie/ofileselector.cc
@@ -51,6 +51,23 @@
51 51
52QMap<QString,QPixmap> *OFileSelector::m_pixmaps = 0; 52QMap<QString,QPixmap> *OFileSelector::m_pixmaps = 0;
53 53
54namespace {
55
56 int indexByString( const QComboBox *box, const QString &str ){
57 int index= -1;
58 for(int i= 0; i < box->count(); i++ ){
59 qWarning("str T%sT boxT%sT", str.latin1(), box->text(i).latin1() );
60 if( str == box->text(i ) ){
61 index= i;
62 break;
63 }
64 }
65 return index;
66 }
67
68};
69
70
54OFileSelector::OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName, 71OFileSelector::OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName,
55 const QString &fileName, const QStringList mimetypes ) : QWidget( wid ) 72 const QString &fileName, const QStringList mimetypes ) : QWidget( wid )
56{ 73{
@@ -104,14 +121,21 @@ OFileSelector::OFileSelector(QWidget *wid, int mode, int selector, const QString
104} 121}
105void OFileSelector::initPics() 122void OFileSelector::initPics()
106{ 123{
124 qWarning("init pics" );
107 m_pixmaps = new QMap<QString,QPixmap>; 125 m_pixmaps = new QMap<QString,QPixmap>;
108 QPixmap pm = Resource::loadPixmap( "folder " ); 126 QPixmap pm = Resource::loadPixmap( "folder" );
109 QPixmap lnk = Resource::loadPixmap( "symlink" ); 127 QPixmap lnk = Resource::loadPixmap( "symlink" );
110 QPainter painter( &pm ); 128 QPainter painter( &pm );
111 painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); 129 painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk );
112 pm.setMask( pm.createHeuristicMask( FALSE ) ); 130 pm.setMask( pm.createHeuristicMask( FALSE ) );
113 m_pixmaps->insert("dirsymlink", pm ); 131 m_pixmaps->insert("dirsymlink", pm );
114 132
133 QPixmap pm2 = Resource::loadPixmap( "lockedfolder" );
134 QPainter pen(&pm2 );
135 pen.drawPixmap(pm2.width()-lnk.width(), pm2.height()-lnk.height(), lnk );
136 pm2.setMask( pm2.createHeuristicMask( FALSE ) );
137 m_pixmaps->insert("symlinkedlocked", pm2 );
138
115}; 139};
116// let's initialize the gui 140// let's initialize the gui
117/** 141/**
@@ -144,10 +168,18 @@ void OFileSelector::init()
144{ 168{
145 169
146 m_stack = new QWidgetStack(this, "wstack" ); 170 m_stack = new QWidgetStack(this, "wstack" );
147 m_select = new FileSelector(m_mimetypes.join(";"), m_stack, "fileselector", FALSE, FALSE ); 171 if( m_selector == NORMAL ){
148 m_stack->addWidget(m_select, NORMAL ); 172 QString currMime;
149 m_lay->addWidget(m_stack ); 173 if( m_mimeCheck != 0 )
150 m_stack->raiseWidget(NORMAL ); 174 currMime = m_mimeCheck->currentText();
175 updateMimes();
176 m_select = new FileSelector( currMime == "All" ? QString::null : currMime , m_stack, "fileselector", FALSE, FALSE );
177 m_stack->addWidget(m_select, NORMAL );
178 m_lay->addWidget(m_stack );
179 m_stack->raiseWidget(NORMAL );
180 }else {
181 initializeListView();
182 }
151 183
152 if(m_shLne ){ 184 if(m_shLne ){
153 initializeName(); 185 initializeName();
@@ -279,7 +311,7 @@ QString OFileSelector::selectedName( )const
279QStringList OFileSelector::selectedNames()const 311QStringList OFileSelector::selectedNames()const
280{ 312{
281 QStringList list; 313 QStringList list;
282 314 return list;
283} 315}
284DocLnk OFileSelector::selectedDocument( )const 316DocLnk OFileSelector::selectedDocument( )const
285{ 317{
@@ -365,6 +397,7 @@ void OFileSelector::reparse()
365 m_mimetypes.prepend("All" ); 397 m_mimetypes.prepend("All" );
366 m_mimeCheck->insertStringList(m_mimetypes ); 398 m_mimeCheck->insertStringList(m_mimetypes );
367 // set it to the current mimetype 399 // set it to the current mimetype
400 m_mimeCheck->setCurrentItem( indexByString( m_mimeCheck, currMime ) );
368 }; 401 };
369 QDir dir( m_currentDir ); 402 QDir dir( m_currentDir );
370 //dir.setFilter(-1 ); 403 //dir.setFilter(-1 );
@@ -380,10 +413,10 @@ void OFileSelector::reparse()
380 qWarning("Test: %s", fi->fileName().latin1() ); 413 qWarning("Test: %s", fi->fileName().latin1() );
381 if(fi->isSymLink() ){ 414 if(fi->isSymLink() ){
382 qWarning("Symlink %s", fi->fileName().latin1() ); 415 qWarning("Symlink %s", fi->fileName().latin1() );
383 QString file = fi->readLink(); 416 QString file = fi->dirPath(true)+"/"+ fi->readLink();
384 qWarning("File ->%s", file.latin1() ); 417 qWarning("File ->%s", file.latin1() );
385 for(int i=0; i<=4; i++ ){ // prepend from dos 418 for(int i=0; i<=4; i++ ){ // prepend from dos
386 QFileInfo info( fi->dirPath()+ "/"+file ); 419 QFileInfo info( file );
387 if( !info.exists() ){ 420 if( !info.exists() ){
388 qWarning("does not exist" ); 421 qWarning("does not exist" );
389 addSymlink(currMime, fi, TRUE ); 422 addSymlink(currMime, fi, TRUE );
@@ -397,7 +430,7 @@ void OFileSelector::reparse()
397 addFile(currMime, fi, TRUE ); 430 addFile(currMime, fi, TRUE );
398 break; 431 break;
399 }else if( info.isSymLink() ){ 432 }else if( info.isSymLink() ){
400 file = info.readLink(); 433 file = info.dirPath(true)+ "/"+ info.readLink();
401 qWarning("isSymlink again %s", file.latin1() ); 434 qWarning("isSymlink again %s", file.latin1() );
402 }else if( i == 4 ){ // just insert it and have the symlink symbol 435 }else if( i == 4 ){ // just insert it and have the symlink symbol
403 addSymlink(currMime, fi ); 436 addSymlink(currMime, fi );
@@ -493,8 +526,7 @@ void OFileSelector::slotMimeCheck(const QString &view ){
493 m_stack->addWidget( m_select, NORMAL ); 526 m_stack->addWidget( m_select, NORMAL );
494 m_stack->raiseWidget( NORMAL ); 527 m_stack->raiseWidget( NORMAL );
495 }else{ 528 }else{
496 529 reparse();
497
498 } 530 }
499} 531}
500 532
@@ -558,7 +590,7 @@ void OFileSelector::updateMimes() // lets check which mode is active
558 } 590 }
559 }else{ 591 }else{
560 // should be allreday updatet 592 // should be allreday updatet
561 593 ;
562 } 594 }
563}; 595};
564void OFileSelector::initializeListView() 596void OFileSelector::initializeListView()
@@ -580,6 +612,13 @@ void OFileSelector::initializeListView()
580 header->hide(); 612 header->hide();
581 m_View->setSorting(1 ); 613 m_View->setSorting(1 );
582}; 614};
615/* If a item is locked depends on the mode
616 if we're in OPEN !isReadable is locked
617 if we're in SAVE !isWriteable is locked
618
619
620 */
621
583 622
584void OFileSelector::addFile(const QString &mime, QFileInfo *info, bool symlink ){ 623void OFileSelector::addFile(const QString &mime, QFileInfo *info, bool symlink ){
585 qWarning("Add Files" ); 624 qWarning("Add Files" );
@@ -589,6 +628,9 @@ void OFileSelector::addFile(const QString &mime, QFileInfo *info, bool symlink )
589 } 628 }
590 629
591 MimeType type( info->filePath() ); 630 MimeType type( info->filePath() );
631 QString name;
632 QString dir;
633 bool locked= false;
592 if(mime == "All" ){ 634 if(mime == "All" ){
593 ; 635 ;
594 }else if( type.id() != mime ) { 636 }else if( type.id() != mime ) {
@@ -597,16 +639,28 @@ void OFileSelector::addFile(const QString &mime, QFileInfo *info, bool symlink )
597 QPixmap pix = type.pixmap(); 639 QPixmap pix = type.pixmap();
598 if(pix.isNull() ) 640 if(pix.isNull() )
599 pix = Resource::loadPixmap( "UnknownDocument-14" ); 641 pix = Resource::loadPixmap( "UnknownDocument-14" );
600 if( symlink ) // have a blended pic sometime 642 dir = info->dirPath( true );
601 new OFileSelectorItem( m_View, pix, info->fileName(), 643 if( symlink ) { // check if the readLink is readable
602 info->lastModified().toString(), 644 // do it right later
603 QString::number(info->size() ), 645 name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink();
604 info->dirPath(true) ); 646 }else{ // keep track of the icons
605 else 647 name = info->fileName();
606 new OFileSelectorItem( m_View, pix, info->fileName(), 648 if( m_mode == OPEN ){
607 info->lastModified().toString(), 649 if( !info->isReadable() ){
608 QString::number(info->size() ), 650 locked = true;
609 info->dirPath(true) ); 651 pix = Resource::loadPixmap("locked" );
652 }
653 }else if( m_mode == SAVE ){
654 if( !info->isWritable() ){
655 locked = true;
656 pix = Resource::loadPixmap("locked" );
657 }
658 }
659 }
660 new OFileSelectorItem( m_View, pix, name,
661 info->lastModified().toString(),
662 QString::number( info->size() ),
663 dir, locked );
610} 664}
611void OFileSelector::addDir(const QString &mime, QFileInfo *info, bool symlink ) 665void OFileSelector::addDir(const QString &mime, QFileInfo *info, bool symlink )
612{ 666{
@@ -614,16 +668,34 @@ void OFileSelector::addDir(const QString &mime, QFileInfo *info, bool symlink )
614 return; 668 return;
615 //if( showDirs ) 669 //if( showDirs )
616 { 670 {
671 bool locked;
672 QString name;
673 QPixmap pix;
674 if( ( m_mode == OPEN && !info->isReadable() ) || ( m_mode == SAVE && !info->isWritable() ) ){
675 locked = true;
676 if( symlink ){
677 pix = (*m_pixmaps)["symlinkedlocked"];
678 }else{
679 pix = Resource::loadPixmap("lockedfolder" );
680 }
681 }else{
682 if( symlink ){
683 pix = (*m_pixmaps)["dirsymlink" ];
684 }else{
685 pix = Resource::loadPixmap("folder" );
686 }
687 }
617 if( symlink){ 688 if( symlink){
618 QPixmap map = (*m_pixmaps)["dirsymlink" ]; 689 name = info->fileName()+ "->"+ info->dirPath(true) +"/" +info->readLink();
619 qWarning("Symlink" ); 690
620 new OFileSelectorItem(m_View, map, 691 }else{
621 info->fileName(), info->lastModified().toString() , 692 //if(info->isReadable() )
622 QString::number(info->size() ),info->dirPath(true), true ); 693 name = info->fileName();
623 }else 694 }
624 new OFileSelectorItem(m_View, Resource::loadPixmap("folder" ), 695
625 info->fileName(), info->lastModified().toString(), 696 new OFileSelectorItem(m_View, pix,
626 QString::number(info->size() ),info->dirPath(true), true ); 697 name, info->lastModified().toString(),
698 QString::number(info->size() ),info->dirPath(true), locked, true );
627 699
628 } 700 }
629} 701}
diff --git a/libopie/ofileselector.h b/libopie/ofileselector.h
index 73674e2..6936773 100644
--- a/libopie/ofileselector.h
+++ b/libopie/ofileselector.h
@@ -68,7 +68,7 @@ class 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 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 );
@@ -76,6 +76,10 @@ class OFileSelectorItem : public QListViewItem {
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;
80 }
81 bool locked() const{
82 return mLocked;
79 } 83 }
80 QString directory()const{ 84 QString directory()const{
81 return m_dir; 85 return m_dir;
@@ -104,6 +108,7 @@ class OFileSelectorItem : public QListViewItem {
104 return ke; 108 return ke;
105 }; 109 };
106 private: 110 private:
111 bool mLocked:1;
107 bool dir:1; 112 bool dir:1;
108 QString m_dir; 113 QString m_dir;
109}; 114};
@@ -136,7 +141,7 @@ class OFileSelector : public QWidget {
136 bool showDirs()const { return m_dir; } 141 bool showDirs()const { return m_dir; }
137 void setShowDirs(bool ); 142 void setShowDirs(bool );
138 143
139 const QListView* listview() { return m_View; }; 144 const QListView* listView() { return m_View; };
140 145
141 bool isCaseSensetive()const { return m_case; } 146 bool isCaseSensetive()const { return m_case; }
142 void setCaseSensetive(bool caSe ); 147 void setCaseSensetive(bool caSe );
@@ -169,7 +174,7 @@ class OFileSelector : public QWidget {
169 /* the user needs to delete it */ 174 /* the user needs to delete it */
170 DocLnk selectedDocument()const; 175 DocLnk selectedDocument()const;
171 /* the user needs to delete it */ 176 /* the user needs to delete it */
172 QValueList<DocLnk> selectedDocuments(); 177 QValueList<DocLnk> selectedDocuments()const;
173 178
174 signals: 179 signals:
175 void fileSelected( const DocLnk & ); 180 void fileSelected( const DocLnk & );