author | zecke <zecke> | 2004-07-24 13:16:26 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-07-24 13:16:26 (UTC) |
commit | 144d91fee9e0ec0cb672508637c639cfbbf4e750 (patch) (unidiff) | |
tree | 802d12ac283361e3d5d710a6b8387dc22b88c462 /libopie2 | |
parent | 1efb57a4cffc8a19a0dadbd008ff205d3d61d216 (diff) | |
download | opie-144d91fee9e0ec0cb672508637c639cfbbf4e750.zip opie-144d91fee9e0ec0cb672508637c639cfbbf4e750.tar.gz opie-144d91fee9e0ec0cb672508637c639cfbbf4e750.tar.bz2 |
Delete the Views which are created in the OFileSelector
Add a new member and one method to register the view.
The views themselves (baseclass) call this function.
Simply going over the viewMap wouldn't work as we can
have the same instance contained twice under a different name
-rw-r--r-- | libopie2/opieui/fileselector/ofileselector.cpp | 19 | ||||
-rw-r--r-- | libopie2/opieui/fileselector/ofileselector.h | 10 |
2 files changed, 24 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 | |||
@@ -53,27 +53,29 @@ | |||
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; |
@@ -502,25 +504,25 @@ int OFileViewFileListView::fileCount()const | |||
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 | } |
@@ -938,25 +940,25 @@ void OFileSelector::initUI() | |||
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 | } |
@@ -989,29 +991,36 @@ void OFileSelector::initViews() | |||
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() |
diff --git a/libopie2/opieui/fileselector/ofileselector.h b/libopie2/opieui/fileselector/ofileselector.h index 8bcd9ee..de2b98a 100644 --- a/libopie2/opieui/fileselector/ofileselector.h +++ b/libopie2/opieui/fileselector/ofileselector.h | |||
@@ -35,24 +35,25 @@ | |||
35 | #ifndef OFILESELECTOR_H | 35 | #ifndef OFILESELECTOR_H |
36 | #define OFILESELECTOR_H | 36 | #define OFILESELECTOR_H |
37 | 37 | ||
38 | /* OPIE */ | 38 | /* OPIE */ |
39 | #include <qpe/applnk.h> | 39 | #include <qpe/applnk.h> |
40 | 40 | ||
41 | /* QT */ | 41 | /* QT */ |
42 | #include <qlist.h> | 42 | #include <qlist.h> |
43 | #include <qwidget.h> | 43 | #include <qwidget.h> |
44 | #include <qmap.h> | 44 | #include <qmap.h> |
45 | #include <qvaluelist.h> | 45 | #include <qvaluelist.h> |
46 | #include <qstringlist.h> | 46 | #include <qstringlist.h> |
47 | #include <qlist.h> | ||
47 | 48 | ||
48 | class QLineEdit; | 49 | class QLineEdit; |
49 | class QComboBox; | 50 | class QComboBox; |
50 | class QWidgetStack; | 51 | class QWidgetStack; |
51 | class QHBox; | 52 | class QHBox; |
52 | 53 | ||
53 | typedef QMap<QString, QStringList> MimeTypes; | 54 | typedef QMap<QString, QStringList> MimeTypes; |
54 | 55 | ||
55 | namespace Opie { | 56 | namespace Opie { |
56 | namespace Ui { | 57 | namespace Ui { |
57 | 58 | ||
58 | namespace Internal { | 59 | namespace Internal { |
@@ -174,35 +175,44 @@ private: | |||
174 | bool showClose()const; | 175 | bool showClose()const; |
175 | MimeTypes mimeTypes()const; | 176 | MimeTypes mimeTypes()const; |
176 | QStringList currentMimeType()const; | 177 | QStringList currentMimeType()const; |
177 | 178 | ||
178 | private: | 179 | private: |
179 | /* inits the Widgets */ | 180 | /* inits the Widgets */ |
180 | void initUI(); | 181 | void initUI(); |
181 | /* inits the MimeType ComboBox content + connects signals and slots */ | 182 | /* inits the MimeType ComboBox content + connects signals and slots */ |
182 | void initMime(); | 183 | void initMime(); |
183 | /* init the Views :) */ | 184 | /* init the Views :) */ |
184 | void initViews(); | 185 | void initViews(); |
185 | 186 | ||
187 | |||
188 | /* | ||
189 | * register a view for deletion. | ||
190 | * This happens on creation of a OFileViewInterface | ||
191 | */ | ||
192 | void registerView( const Internal::OFileViewInterface* ); | ||
193 | |||
186 | private: | 194 | private: |
187 | QLineEdit* m_lneEdit; // the LineEdit for the Name | 195 | QLineEdit* m_lneEdit; // the LineEdit for the Name |
188 | QComboBox *m_cmbView, *m_cmbMime; // two ComboBoxes to select the View and MimeType | 196 | QComboBox *m_cmbView, *m_cmbMime; // two ComboBoxes to select the View and MimeType |
189 | QWidgetStack* m_stack; // our widget stack which will contain the views | 197 | QWidgetStack* m_stack; // our widget stack which will contain the views |
190 | Internal::OFileViewInterface* currentView() const; // returns the currentView | 198 | Internal::OFileViewInterface* currentView() const; // returns the currentView |
191 | Internal::OFileViewInterface* m_current; // here is the view saved | 199 | Internal::OFileViewInterface* m_current; // here is the view saved |
192 | bool m_shNew : 1; // should we show New? | 200 | bool m_shNew : 1; // should we show New? |
193 | bool m_shClose : 1; // should we show Close? | 201 | bool m_shClose : 1; // should we show Close? |
194 | MimeTypes m_mimeType; // list of mimetypes | 202 | MimeTypes m_mimeType; // list of mimetypes |
195 | 203 | ||
196 | QMap<QString, Internal::OFileViewInterface*> m_views; // QString translated view name + ViewInterface Ptr | 204 | QMap<QString, Internal::OFileViewInterface*> m_views; // QString translated view name + ViewInterface Ptr |
205 | /* views register themselves automatically */ | ||
206 | QList<Internal::OFileViewInterface> m_viewsPtr; | ||
197 | QHBox* m_nameBox; // the LineEdit + Label is hold here | 207 | QHBox* m_nameBox; // the LineEdit + Label is hold here |
198 | QHBox* m_cmbBox; // this holds the two combo boxes | 208 | QHBox* m_cmbBox; // this holds the two combo boxes |
199 | 209 | ||
200 | QString m_startDir; | 210 | QString m_startDir; |
201 | int m_mode; | 211 | int m_mode; |
202 | int m_selector; | 212 | int m_selector; |
203 | 213 | ||
204 | struct Data; // used for future versions | 214 | struct Data; // used for future versions |
205 | Data *d; | 215 | Data *d; |
206 | 216 | ||
207 | private slots: | 217 | private slots: |
208 | void slotMimeTypeChanged(); | 218 | void slotMimeTypeChanged(); |