author | zecke <zecke> | 2002-03-30 23:26:49 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-03-30 23:26:49 (UTC) |
commit | 5d12c8fb75458262f6414073759b4c610f615525 (patch) (unidiff) | |
tree | 45a3158271b748c6e5ff98afcf7014a25cd447d8 | |
parent | f3376cde32aa6a03070fb8f2d1428cedcbe49425 (diff) | |
download | opie-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
-rw-r--r-- | libopie/ofileselector.cc | 134 | ||||
-rw-r--r-- | libopie/ofileselector.h | 11 |
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 | |||
@@ -48,12 +48,29 @@ | |||
48 | #include <qpe/resource.h> | 48 | #include <qpe/resource.h> |
49 | 49 | ||
50 | #include "ofileselector.h" | 50 | #include "ofileselector.h" |
51 | 51 | ||
52 | QMap<QString,QPixmap> *OFileSelector::m_pixmaps = 0; | 52 | QMap<QString,QPixmap> *OFileSelector::m_pixmaps = 0; |
53 | 53 | ||
54 | namespace { | ||
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 | |||
54 | OFileSelector::OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName, | 71 | OFileSelector::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 | { |
57 | m_selector = selector; | 74 | m_selector = selector; |
58 | m_currentDir = dirName; | 75 | m_currentDir = dirName; |
59 | m_name = fileName; | 76 | m_name = fileName; |
@@ -101,20 +118,27 @@ OFileSelector::OFileSelector(QWidget *wid, int mode, int selector, const QString | |||
101 | m_lay = new QVBoxLayout(this); | 118 | m_lay = new QVBoxLayout(this); |
102 | init(); | 119 | init(); |
103 | m_edit->setText( fileName ); | 120 | m_edit->setText( fileName ); |
104 | } | 121 | } |
105 | void OFileSelector::initPics() | 122 | void 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 | /** |
118 | -------------------- | 142 | -------------------- |
119 | | cmbBox Button | | 143 | | cmbBox Button | |
120 | -------------------- | 144 | -------------------- |
@@ -141,16 +165,24 @@ void OFileSelector::delItems() | |||
141 | } | 165 | } |
142 | } | 166 | } |
143 | void OFileSelector::init() | 167 | 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(); |
154 | } | 186 | } |
155 | 187 | ||
156 | if(m_shPerm ){ | 188 | if(m_shPerm ){ |
@@ -276,13 +308,13 @@ QString OFileSelector::selectedName( )const | |||
276 | } | 308 | } |
277 | return string; | 309 | return string; |
278 | } | 310 | } |
279 | QStringList OFileSelector::selectedNames()const | 311 | QStringList OFileSelector::selectedNames()const |
280 | { | 312 | { |
281 | QStringList list; | 313 | QStringList list; |
282 | 314 | return list; | |
283 | } | 315 | } |
284 | DocLnk OFileSelector::selectedDocument( )const | 316 | DocLnk OFileSelector::selectedDocument( )const |
285 | { | 317 | { |
286 | DocLnk lnk; | 318 | DocLnk lnk; |
287 | return lnk; | 319 | return lnk; |
288 | } | 320 | } |
@@ -362,12 +394,13 @@ void OFileSelector::reparse() | |||
362 | 394 | ||
363 | ++it; | 395 | ++it; |
364 | } | 396 | } |
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 ); |
371 | dir.setSorting(QDir::Name | QDir::DirsFirst | QDir::Reversed | QDir::IgnoreCase ); | 404 | dir.setSorting(QDir::Name | QDir::DirsFirst | QDir::Reversed | QDir::IgnoreCase ); |
372 | const QFileInfoList *list = dir.entryInfoList(); | 405 | const QFileInfoList *list = dir.entryInfoList(); |
373 | QFileInfoListIterator it( *list ); | 406 | QFileInfoListIterator it( *list ); |
@@ -377,16 +410,16 @@ void OFileSelector::reparse() | |||
377 | ++it; | 410 | ++it; |
378 | continue; | 411 | continue; |
379 | } | 412 | } |
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 ); |
390 | break; | 423 | break; |
391 | }else if( info.isDir() ){ | 424 | }else if( info.isDir() ){ |
392 | qWarning("isDir" ); | 425 | qWarning("isDir" ); |
@@ -394,13 +427,13 @@ void OFileSelector::reparse() | |||
394 | break; | 427 | break; |
395 | }else if( info.isFile() ){ | 428 | }else if( info.isFile() ){ |
396 | qWarning("isFile" ); | 429 | qWarning("isFile" ); |
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 ); |
404 | qWarning("level too deep" ); | 437 | qWarning("level too deep" ); |
405 | } | 438 | } |
406 | } | 439 | } |
@@ -490,14 +523,13 @@ void OFileSelector::slotMimeCheck(const QString &view ){ | |||
490 | delete m_select; | 523 | delete m_select; |
491 | m_select = new FileSelector(view == "All" ? QString::null : view | 524 | m_select = new FileSelector(view == "All" ? QString::null : view |
492 | , m_stack, "fileselector", FALSE, FALSE ); | 525 | , m_stack, "fileselector", FALSE, FALSE ); |
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 | ||
501 | void OFileSelector::slotViewCheck(const QString &view ){ | 533 | void OFileSelector::slotViewCheck(const QString &view ){ |
502 | qWarning("changed: show %s", view.latin1() ); | 534 | qWarning("changed: show %s", view.latin1() ); |
503 | // if the current view is the one | 535 | // if the current view is the one |
@@ -555,13 +587,13 @@ void OFileSelector::updateMimes() // lets check which mode is active | |||
555 | for ( ; dit.current(); ++dit ) { | 587 | for ( ; dit.current(); ++dit ) { |
556 | if( !m_mimetypes.contains((*dit)->type() ) ) | 588 | if( !m_mimetypes.contains((*dit)->type() ) ) |
557 | m_mimetypes.append( (*dit)->type() ); | 589 | m_mimetypes.append( (*dit)->type() ); |
558 | } | 590 | } |
559 | }else{ | 591 | }else{ |
560 | // should be allreday updatet | 592 | // should be allreday updatet |
561 | 593 | ; | |
562 | } | 594 | } |
563 | }; | 595 | }; |
564 | void OFileSelector::initializeListView() | 596 | void OFileSelector::initializeListView() |
565 | { | 597 | { |
566 | m_View = new QListView(m_stack, "Extended view" ); | 598 | m_View = new QListView(m_stack, "Extended view" ); |
567 | m_stack->addWidget( m_View, EXTENDED ); | 599 | m_stack->addWidget( m_View, EXTENDED ); |
@@ -577,56 +609,96 @@ void OFileSelector::initializeListView() | |||
577 | m_View->addColumn(tr("Date"), 60 ); | 609 | m_View->addColumn(tr("Date"), 60 ); |
578 | m_View->addColumn(tr("Mime Type") ); | 610 | m_View->addColumn(tr("Mime Type") ); |
579 | QHeader *header = m_View->header(); | 611 | QHeader *header = m_View->header(); |
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 | ||
584 | void OFileSelector::addFile(const QString &mime, QFileInfo *info, bool symlink ){ | 623 | void OFileSelector::addFile(const QString &mime, QFileInfo *info, bool symlink ){ |
585 | qWarning("Add Files" ); | 624 | qWarning("Add Files" ); |
586 | if( !m_files ){ | 625 | if( !m_files ){ |
587 | qWarning("not mfiles" ); | 626 | qWarning("not mfiles" ); |
588 | return; | 627 | return; |
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 ) { |
595 | return; | 637 | return; |
596 | } | 638 | } |
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 | } |
611 | void OFileSelector::addDir(const QString &mime, QFileInfo *info, bool symlink ) | 665 | void OFileSelector::addDir(const QString &mime, QFileInfo *info, bool symlink ) |
612 | { | 666 | { |
613 | if(!m_dir ) | 667 | if(!m_dir ) |
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 | } |
630 | void OFileSelector::setShowDirs(bool dir ) | 702 | void OFileSelector::setShowDirs(bool dir ) |
631 | { | 703 | { |
632 | m_dir = dir; | 704 | m_dir = dir; |
diff --git a/libopie/ofileselector.h b/libopie/ofileselector.h index 73674e2..6936773 100644 --- a/libopie/ofileselector.h +++ b/libopie/ofileselector.h | |||
@@ -65,20 +65,24 @@ class QPopupMenu; | |||
65 | class QFileInfo; | 65 | class QFileInfo; |
66 | // | 66 | // |
67 | class OFileSelectorItem : public QListViewItem { | 67 | 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 ); |
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; | ||
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; |
82 | } | 86 | } |
83 | bool isDir()const{ | 87 | bool isDir()const{ |
84 | return dir; | 88 | return dir; |
@@ -101,12 +105,13 @@ class OFileSelectorItem : public QListViewItem { | |||
101 | }else if( id == 3 ){ // date | 105 | }else if( id == 3 ){ // date |
102 | return text(3); | 106 | return text(3); |
103 | } | 107 | } |
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 | }; |
110 | 115 | ||
111 | class OFileSelector : public QWidget { | 116 | class OFileSelector : public QWidget { |
112 | Q_OBJECT | 117 | Q_OBJECT |
@@ -133,13 +138,13 @@ class OFileSelector : public QWidget { | |||
133 | 138 | ||
134 | void setMode( int ); | 139 | void setMode( int ); |
135 | 140 | ||
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 ); |
143 | 148 | ||
144 | bool showFiles()const { return m_files; }; | 149 | bool showFiles()const { return m_files; }; |
145 | void setShowFiles(bool ); | 150 | void setShowFiles(bool ); |
@@ -166,13 +171,13 @@ class OFileSelector : public QWidget { | |||
166 | QString directory()const; | 171 | QString directory()const; |
167 | int fileCount(); | 172 | int fileCount(); |
168 | 173 | ||
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 & ); |
176 | void fileSelected( const QString & ); | 181 | void fileSelected( const QString & ); |
177 | void closeMe(); | 182 | void closeMe(); |
178 | void ok(); | 183 | void ok(); |