Diffstat (limited to 'libopie2/opieui/fileselector/ofileselector.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opieui/fileselector/ofileselector.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/libopie2/opieui/fileselector/ofileselector.cpp b/libopie2/opieui/fileselector/ofileselector.cpp index 5528aed..b06defd 100644 --- a/libopie2/opieui/fileselector/ofileselector.cpp +++ b/libopie2/opieui/fileselector/ofileselector.cpp | |||
@@ -41,51 +41,53 @@ | |||
41 | #include <qpe/qpeapplication.h> | 41 | #include <qpe/qpeapplication.h> |
42 | #include <qpe/mimetype.h> | 42 | #include <qpe/mimetype.h> |
43 | #include <qpe/resource.h> | 43 | #include <qpe/resource.h> |
44 | #include <qpe/storage.h> | 44 | #include <qpe/storage.h> |
45 | 45 | ||
46 | /* QT */ | 46 | /* QT */ |
47 | #include <qcombobox.h> | 47 | #include <qcombobox.h> |
48 | #include <qdir.h> | 48 | #include <qdir.h> |
49 | #include <qhbox.h> | 49 | #include <qhbox.h> |
50 | #include <qheader.h> | 50 | #include <qheader.h> |
51 | #include <qlabel.h> | 51 | #include <qlabel.h> |
52 | #include <qlayout.h> | 52 | #include <qlayout.h> |
53 | #include <qlineedit.h> | 53 | #include <qlineedit.h> |
54 | #include <qlistview.h> | 54 | #include <qlistview.h> |
55 | #include <qpopupmenu.h> | 55 | #include <qpopupmenu.h> |
56 | #include <qwidgetstack.h> | 56 | #include <qwidgetstack.h> |
57 | #include <qregexp.h> | 57 | #include <qregexp.h> |
58 | #include <qobjectlist.h> | 58 | #include <qobjectlist.h> |
59 | 59 | ||
60 | using namespace Opie::Ui::Internal; | 60 | using namespace Opie::Ui::Internal; |
61 | 61 | ||
62 | namespace Opie { | 62 | namespace Opie { |
63 | namespace Ui { | 63 | namespace Ui { |
64 | namespace Internal { | 64 | namespace Internal { |
65 | OFileViewInterface::OFileViewInterface( OFileSelector* selector ) | 65 | OFileViewInterface::OFileViewInterface( OFileSelector* _selector ) |
66 | : m_selector( selector ) | 66 | : m_selector( _selector ) |
67 | {} | 67 | { |
68 | selector()->registerView( this ); | ||
69 | } | ||
68 | 70 | ||
69 | OFileViewInterface::~OFileViewInterface() | 71 | OFileViewInterface::~OFileViewInterface() |
70 | {} | 72 | {} |
71 | 73 | ||
72 | QString OFileViewInterface::name()const | 74 | QString OFileViewInterface::name()const |
73 | { | 75 | { |
74 | return m_name; | 76 | return m_name; |
75 | } | 77 | } |
76 | 78 | ||
77 | void OFileViewInterface::setName( const QString& name ) | 79 | void OFileViewInterface::setName( const QString& name ) |
78 | { | 80 | { |
79 | m_name = name; | 81 | m_name = name; |
80 | } | 82 | } |
81 | 83 | ||
82 | OFileSelector* OFileViewInterface::selector()const | 84 | OFileSelector* OFileViewInterface::selector()const |
83 | { | 85 | { |
84 | return m_selector; | 86 | return m_selector; |
85 | } | 87 | } |
86 | 88 | ||
87 | DocLnk OFileViewInterface::selectedDocument()const | 89 | DocLnk OFileViewInterface::selectedDocument()const |
88 | { | 90 | { |
89 | return DocLnk( selectedName() ); | 91 | return DocLnk( selectedName() ); |
90 | } | 92 | } |
91 | 93 | ||
@@ -490,49 +492,49 @@ void OFileViewFileListView::reread( bool all ) | |||
490 | addDir( fi ); | 492 | addDir( fi ); |
491 | else if( fi->isFile() ) | 493 | else if( fi->isFile() ) |
492 | addFile( fi ); | 494 | addFile( fi ); |
493 | 495 | ||
494 | ++it; | 496 | ++it; |
495 | } // of while loop | 497 | } // of while loop |
496 | m_view->sort(); | 498 | m_view->sort(); |
497 | 499 | ||
498 | } | 500 | } |
499 | int OFileViewFileListView::fileCount()const | 501 | int OFileViewFileListView::fileCount()const |
500 | { | 502 | { |
501 | return m_view->childCount(); | 503 | return m_view->childCount(); |
502 | } | 504 | } |
503 | 505 | ||
504 | QString OFileViewFileListView::currentDir()const | 506 | QString OFileViewFileListView::currentDir()const |
505 | { | 507 | { |
506 | return m_currentDir; | 508 | return m_currentDir; |
507 | } | 509 | } |
508 | 510 | ||
509 | OFileSelector* OFileViewFileListView::selector() | 511 | OFileSelector* OFileViewFileListView::selector() |
510 | { | 512 | { |
511 | return m_sel; | 513 | return m_sel; |
512 | } | 514 | } |
513 | 515 | ||
514 | bool OFileViewFileListView::eventFilter (QObject *o, QEvent *e) | 516 | bool OFileViewFileListView::eventFilter (QObject *, QEvent *e) |
515 | { | 517 | { |
516 | if ( e->type() == QEvent::KeyPress ) | 518 | if ( e->type() == QEvent::KeyPress ) |
517 | { | 519 | { |
518 | QKeyEvent *k = (QKeyEvent *)e; | 520 | QKeyEvent *k = (QKeyEvent *)e; |
519 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) | 521 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) |
520 | { | 522 | { |
521 | slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0); | 523 | slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0); |
522 | return true; | 524 | return true; |
523 | } | 525 | } |
524 | } | 526 | } |
525 | return false; | 527 | return false; |
526 | } | 528 | } |
527 | 529 | ||
528 | void OFileViewFileListView::connectSlots() | 530 | void OFileViewFileListView::connectSlots() |
529 | { | 531 | { |
530 | connect(m_view, SIGNAL(clicked(QListViewItem*) ), | 532 | connect(m_view, SIGNAL(clicked(QListViewItem*) ), |
531 | this, SLOT(slotCurrentChanged(QListViewItem*) ) ); | 533 | this, SLOT(slotCurrentChanged(QListViewItem*) ) ); |
532 | connect(m_view, SIGNAL(mouseButtonClicked(int,QListViewItem*,const QPoint&,int) ), | 534 | connect(m_view, SIGNAL(mouseButtonClicked(int,QListViewItem*,const QPoint&,int) ), |
533 | this, SLOT(slotClicked(int,QListViewItem*,const QPoint&,int) ) ); | 535 | this, SLOT(slotClicked(int,QListViewItem*,const QPoint&,int) ) ); |
534 | } | 536 | } |
535 | 537 | ||
536 | void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) | 538 | void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) |
537 | { | 539 | { |
538 | if (!item) | 540 | if (!item) |
@@ -926,49 +928,49 @@ OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const | |||
926 | */ | 928 | */ |
927 | void OFileSelector::initUI() | 929 | void OFileSelector::initUI() |
928 | { | 930 | { |
929 | QVBoxLayout* lay = new QVBoxLayout( this ); | 931 | QVBoxLayout* lay = new QVBoxLayout( this ); |
930 | 932 | ||
931 | m_stack = new QWidgetStack( this ); | 933 | m_stack = new QWidgetStack( this ); |
932 | lay->addWidget( m_stack, 1000 ); | 934 | lay->addWidget( m_stack, 1000 ); |
933 | 935 | ||
934 | m_nameBox = new QHBox( this ); | 936 | m_nameBox = new QHBox( this ); |
935 | (void)new QLabel( tr("Name:"), m_nameBox ); | 937 | (void)new QLabel( tr("Name:"), m_nameBox ); |
936 | m_lneEdit = new QLineEdit( m_nameBox ); | 938 | m_lneEdit = new QLineEdit( m_nameBox ); |
937 | m_lneEdit ->installEventFilter(this); | 939 | m_lneEdit ->installEventFilter(this); |
938 | lay->addWidget( m_nameBox ); | 940 | lay->addWidget( m_nameBox ); |
939 | 941 | ||
940 | m_cmbBox = new QHBox( this ); | 942 | m_cmbBox = new QHBox( this ); |
941 | m_cmbView = new QComboBox( m_cmbBox ); | 943 | m_cmbView = new QComboBox( m_cmbBox ); |
942 | m_cmbMime = new QComboBox( m_cmbBox ); | 944 | m_cmbMime = new QComboBox( m_cmbBox ); |
943 | lay->addWidget( m_cmbBox ); | 945 | lay->addWidget( m_cmbBox ); |
944 | } | 946 | } |
945 | 947 | ||
946 | /* | 948 | /* |
947 | * This will make sure that the return key in the name edit causes dialogs to close | 949 | * This will make sure that the return key in the name edit causes dialogs to close |
948 | */ | 950 | */ |
949 | 951 | ||
950 | bool OFileSelector::eventFilter (QObject *o, QEvent *e) | 952 | bool OFileSelector::eventFilter (QObject *, QEvent *e) |
951 | { | 953 | { |
952 | if ( e->type() == QEvent::KeyPress ) | 954 | if ( e->type() == QEvent::KeyPress ) |
953 | { | 955 | { |
954 | QKeyEvent *k = (QKeyEvent *)e; | 956 | QKeyEvent *k = (QKeyEvent *)e; |
955 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) | 957 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) |
956 | { | 958 | { |
957 | emit ok(); | 959 | emit ok(); |
958 | return true; | 960 | return true; |
959 | } | 961 | } |
960 | } | 962 | } |
961 | return false; | 963 | return false; |
962 | } | 964 | } |
963 | 965 | ||
964 | /* | 966 | /* |
965 | * This will insert the MimeTypes into the Combo Box | 967 | * This will insert the MimeTypes into the Combo Box |
966 | * And also connect the changed signal | 968 | * And also connect the changed signal |
967 | * | 969 | * |
968 | * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes | 970 | * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes |
969 | */ | 971 | */ |
970 | void OFileSelector::initMime() | 972 | void OFileSelector::initMime() |
971 | { | 973 | { |
972 | MimeTypes::Iterator it; | 974 | MimeTypes::Iterator it; |
973 | for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it ) | 975 | for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it ) |
974 | { | 976 | { |
@@ -977,53 +979,60 @@ void OFileSelector::initMime() | |||
977 | m_cmbMime->setCurrentItem( 0 ); | 979 | m_cmbMime->setCurrentItem( 0 ); |
978 | 980 | ||
979 | connect( m_cmbMime, SIGNAL(activated(int) ), | 981 | connect( m_cmbMime, SIGNAL(activated(int) ), |
980 | this, SLOT(slotMimeTypeChanged() ) ); | 982 | this, SLOT(slotMimeTypeChanged() ) ); |
981 | 983 | ||
982 | } | 984 | } |
983 | 985 | ||
984 | void OFileSelector::initViews() | 986 | void OFileSelector::initViews() |
985 | { | 987 | { |
986 | m_cmbView->insertItem( QObject::tr("Documents") ); | 988 | m_cmbView->insertItem( QObject::tr("Documents") ); |
987 | m_cmbView->insertItem( QObject::tr("Files") ); | 989 | m_cmbView->insertItem( QObject::tr("Files") ); |
988 | m_cmbView->insertItem( QObject::tr("All Files") ); | 990 | m_cmbView->insertItem( QObject::tr("All Files") ); |
989 | connect(m_cmbView, SIGNAL(activated(const QString&) ), | 991 | connect(m_cmbView, SIGNAL(activated(const QString&) ), |
990 | this, SLOT(slotViewChange(const QString&) ) ); | 992 | this, SLOT(slotViewChange(const QString&) ) ); |
991 | 993 | ||
992 | 994 | ||
993 | m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) ); | 995 | m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) ); |
994 | 996 | ||
995 | /* see above why add both */ | 997 | /* see above why add both */ |
996 | OFileViewInterface* in = new OFileViewFileSystem( this ); | 998 | OFileViewInterface* in = new OFileViewFileSystem( this ); |
997 | m_views.insert( QObject::tr("Files"), in ); | 999 | m_views.insert( QObject::tr("Files"), in ); |
998 | m_views.insert( QObject::tr("All Files"), in ); | 1000 | m_views.insert( QObject::tr("All Files"), in ); |
999 | } | 1001 | } |
1000 | 1002 | ||
1003 | void OFileSelector::registerView( const Internal::OFileViewInterface* iface ) { | ||
1004 | m_viewsPtr.append( iface ); | ||
1005 | } | ||
1006 | |||
1007 | |||
1001 | /** | 1008 | /** |
1002 | * d'tor | 1009 | * d'tor |
1003 | */ | 1010 | */ |
1004 | OFileSelector::~OFileSelector() | 1011 | OFileSelector::~OFileSelector() |
1005 | { | 1012 | { |
1013 | m_viewsPtr.setAutoDelete( true ); | ||
1014 | m_viewsPtr.clear(); | ||
1006 | } | 1015 | } |
1007 | 1016 | ||
1008 | 1017 | ||
1009 | 1018 | ||
1010 | /** | 1019 | /** |
1011 | * Convience function for the fileselector | 1020 | * Convience function for the fileselector |
1012 | * make sure to delete the DocLnk | 1021 | * make sure to delete the DocLnk |
1013 | * | 1022 | * |
1014 | * @see DocLnk | 1023 | * @see DocLnk |
1015 | * @todo remove in ODP | 1024 | * @todo remove in ODP |
1016 | */ | 1025 | */ |
1017 | const DocLnk* OFileSelector::selected() | 1026 | const DocLnk* OFileSelector::selected() |
1018 | { | 1027 | { |
1019 | DocLnk* lnk = new DocLnk( currentView()->selectedDocument() ); | 1028 | DocLnk* lnk = new DocLnk( currentView()->selectedDocument() ); |
1020 | return lnk; | 1029 | return lnk; |
1021 | } | 1030 | } |
1022 | 1031 | ||
1023 | /** | 1032 | /** |
1024 | * | 1033 | * |
1025 | * @return the name of the selected file | 1034 | * @return the name of the selected file |
1026 | */ | 1035 | */ |
1027 | QString OFileSelector::selectedName()const | 1036 | QString OFileSelector::selectedName()const |
1028 | { | 1037 | { |
1029 | return currentView()->selectedName(); | 1038 | return currentView()->selectedName(); |