-rw-r--r-- | libopie/ofileselector.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/libopie/ofileselector.cpp b/libopie/ofileselector.cpp index 1ba94ae..2a6aed0 100644 --- a/libopie/ofileselector.cpp +++ b/libopie/ofileselector.cpp | |||
@@ -1,584 +1,584 @@ | |||
1 | #include <qcombobox.h> | 1 | #include <qcombobox.h> |
2 | #include <qdir.h> | 2 | #include <qdir.h> |
3 | #include <qlabel.h> | 3 | #include <qlabel.h> |
4 | #include <qlayout.h> | 4 | #include <qlayout.h> |
5 | #include <qlineedit.h> | 5 | #include <qlineedit.h> |
6 | #include <qpopupmenu.h> | 6 | #include <qpopupmenu.h> |
7 | #include <qwidgetstack.h> | 7 | #include <qwidgetstack.h> |
8 | 8 | ||
9 | /* hacky but we need to get FileSelector::filter */ | 9 | /* hacky but we need to get FileSelector::filter */ |
10 | #define private public | 10 | #define private public |
11 | #include <qpe/fileselector.h> | 11 | #include <qpe/fileselector.h> |
12 | #undef private | 12 | #undef private |
13 | 13 | ||
14 | #include <qpe/qpeapplication.h> | 14 | #include <qpe/qpeapplication.h> |
15 | #include <qpe/mimetype.h> | 15 | #include <qpe/mimetype.h> |
16 | #include <qpe/resource.h> | 16 | #include <qpe/resource.h> |
17 | #include <qpe/storage.h> | 17 | #include <qpe/storage.h> |
18 | 18 | ||
19 | #include "ofileselector_p.h" | 19 | #include "ofileselector_p.h" |
20 | #include "ofileselector.h" | 20 | #include "ofileselector.h" |
21 | 21 | ||
22 | 22 | ||
23 | 23 | ||
24 | OFileViewInterface::OFileViewInterface( OFileSelector* selector ) | 24 | OFileViewInterface::OFileViewInterface( OFileSelector* selector ) |
25 | : m_selector( selector ) { | 25 | : m_selector( selector ) { |
26 | } | 26 | } |
27 | OFileViewInterface::~OFileViewInterface() { | 27 | OFileViewInterface::~OFileViewInterface() { |
28 | } | 28 | } |
29 | QString OFileViewInterface::name()const{ | 29 | QString OFileViewInterface::name()const{ |
30 | return m_name; | 30 | return m_name; |
31 | } | 31 | } |
32 | void OFileViewInterface::setName( const QString& name ) { | 32 | void OFileViewInterface::setName( const QString& name ) { |
33 | m_name = name; | 33 | m_name = name; |
34 | } | 34 | } |
35 | OFileSelector* OFileViewInterface::selector()const { | 35 | OFileSelector* OFileViewInterface::selector()const { |
36 | return m_selector; | 36 | return m_selector; |
37 | } | 37 | } |
38 | DocLnk OFileViewInterface::selectedDocument()const { | 38 | DocLnk OFileViewInterface::selectedDocument()const { |
39 | return DocLnk( selectedName() ); | 39 | return DocLnk( selectedName() ); |
40 | } | 40 | } |
41 | bool OFileViewInterface::showNew()const { | 41 | bool OFileViewInterface::showNew()const { |
42 | return selector()->showNew(); | 42 | return selector()->showNew(); |
43 | } | 43 | } |
44 | bool OFileViewInterface::showClose()const { | 44 | bool OFileViewInterface::showClose()const { |
45 | return selector()->showClose(); | 45 | return selector()->showClose(); |
46 | } | 46 | } |
47 | MimeTypes OFileViewInterface::mimeTypes()const { | 47 | MimeTypes OFileViewInterface::mimeTypes()const { |
48 | return selector()->mimeTypes(); | 48 | return selector()->mimeTypes(); |
49 | } | 49 | } |
50 | QStringList OFileViewInterface::currentMimeType()const { | 50 | QStringList OFileViewInterface::currentMimeType()const { |
51 | return selector()->currentMimeType(); | 51 | return selector()->currentMimeType(); |
52 | } | 52 | } |
53 | void OFileViewInterface::activate( const QString& ) { | 53 | void OFileViewInterface::activate( const QString& ) { |
54 | // not implemented here | 54 | // not implemented here |
55 | } | 55 | } |
56 | void OFileViewInterface::ok() { | 56 | void OFileViewInterface::ok() { |
57 | emit selector()->ok(); | 57 | emit selector()->ok(); |
58 | } | 58 | } |
59 | void OFileViewInterface::cancel() { | 59 | void OFileViewInterface::cancel() { |
60 | emit selector()->cancel(); | 60 | emit selector()->cancel(); |
61 | } | 61 | } |
62 | void OFileViewInterface::closeMe() { | 62 | void OFileViewInterface::closeMe() { |
63 | emit selector()->closeMe(); | 63 | emit selector()->closeMe(); |
64 | } | 64 | } |
65 | void OFileViewInterface::fileSelected( const QString& str) { | 65 | void OFileViewInterface::fileSelected( const QString& str) { |
66 | emit selector()->fileSelected( str); | 66 | emit selector()->fileSelected( str); |
67 | } | 67 | } |
68 | void OFileViewInterface::fileSelected( const DocLnk& lnk) { | 68 | void OFileViewInterface::fileSelected( const DocLnk& lnk) { |
69 | emit selector()->fileSelected( lnk ); | 69 | emit selector()->fileSelected( lnk ); |
70 | } | 70 | } |
71 | void OFileViewInterface::setCurrentFileName( const QString& str ) { | 71 | void OFileViewInterface::setCurrentFileName( const QString& str ) { |
72 | selector()->m_lneEdit->setText( str ); | 72 | selector()->m_lneEdit->setText( str ); |
73 | } | 73 | } |
74 | QString OFileViewInterface::currentFileName()const{ | 74 | QString OFileViewInterface::currentFileName()const{ |
75 | return selector()->m_lneEdit->text(); | 75 | return selector()->m_lneEdit->text(); |
76 | } | 76 | } |
77 | QString OFileViewInterface::startDirectory()const{ | 77 | QString OFileViewInterface::startDirectory()const{ |
78 | return selector()->m_startDir; | 78 | return selector()->m_startDir; |
79 | } | 79 | } |
80 | 80 | ||
81 | 81 | ||
82 | ODocumentFileView::ODocumentFileView( OFileSelector* selector ) | 82 | ODocumentFileView::ODocumentFileView( OFileSelector* selector ) |
83 | : OFileViewInterface( selector ) { | 83 | : OFileViewInterface( selector ) { |
84 | m_selector = 0; | 84 | m_selector = 0; |
85 | setName( QObject::tr("Documents") ); | 85 | setName( QObject::tr("Documents") ); |
86 | } | 86 | } |
87 | ODocumentFileView::~ODocumentFileView() { | 87 | ODocumentFileView::~ODocumentFileView() { |
88 | 88 | ||
89 | } | 89 | } |
90 | QString ODocumentFileView::selectedName()const { | 90 | QString ODocumentFileView::selectedName()const { |
91 | if (!m_selector) | 91 | if (!m_selector) |
92 | return QString::null; | 92 | return QString::null; |
93 | 93 | ||
94 | return m_selector->selectedDocument().file(); | 94 | return m_selector->selectedDocument().file(); |
95 | } | 95 | } |
96 | QString ODocumentFileView::selectedPath()const { | 96 | QString ODocumentFileView::selectedPath()const { |
97 | return QPEApplication::documentDir(); | 97 | return QPEApplication::documentDir(); |
98 | } | 98 | } |
99 | QString ODocumentFileView::directory()const { | 99 | QString ODocumentFileView::directory()const { |
100 | return selectedPath(); | 100 | return selectedPath(); |
101 | } | 101 | } |
102 | void ODocumentFileView::reread() { | 102 | void ODocumentFileView::reread() { |
103 | if (!m_selector) | 103 | if (!m_selector) |
104 | return; | 104 | return; |
105 | 105 | ||
106 | m_selector->setNewVisible( showNew() ); | 106 | m_selector->setNewVisible( showNew() ); |
107 | m_selector->setCloseVisible( showClose() ); | 107 | m_selector->setCloseVisible( showClose() ); |
108 | m_selector->filter = currentMimeType().join(";"); | 108 | m_selector->filter = currentMimeType().join(";"); |
109 | m_selector->reread(); | 109 | m_selector->reread(); |
110 | } | 110 | } |
111 | int ODocumentFileView::fileCount()const { | 111 | int ODocumentFileView::fileCount()const { |
112 | if (!m_selector) | 112 | if (!m_selector) |
113 | return -1; | 113 | return -1; |
114 | 114 | ||
115 | return m_selector->fileCount(); | 115 | return m_selector->fileCount(); |
116 | } | 116 | } |
117 | DocLnk ODocumentFileView::selectedDocument()const { | 117 | DocLnk ODocumentFileView::selectedDocument()const { |
118 | if (!m_selector) | 118 | if (!m_selector) |
119 | return DocLnk(); | 119 | return DocLnk(); |
120 | 120 | ||
121 | return m_selector->selectedDocument(); | 121 | return m_selector->selectedDocument(); |
122 | } | 122 | } |
123 | QWidget* ODocumentFileView::widget( QWidget* parent ) { | 123 | QWidget* ODocumentFileView::widget( QWidget* parent ) { |
124 | if (!m_selector ) { | 124 | if (!m_selector ) { |
125 | m_selector = new FileSelector(currentMimeType().join(";"), parent, "fileselector", showNew(), showClose() ); | 125 | m_selector = new FileSelector(currentMimeType().join(";"), parent, "fileselector", showNew(), showClose() ); |
126 | QObject::connect(m_selector, SIGNAL(fileSelected( const DocLnk& ) ), | 126 | QObject::connect(m_selector, SIGNAL(fileSelected(const DocLnk&) ), |
127 | selector(), SLOT(slotDocLnkBridge(const DocLnk&) ) ); | 127 | selector(), SLOT(slotDocLnkBridge(const DocLnk&) ) ); |
128 | QObject::connect(m_selector, SIGNAL(closeMe() ), | 128 | QObject::connect(m_selector, SIGNAL(closeMe() ), |
129 | selector(), SIGNAL(closeMe() ) ); | 129 | selector(), SIGNAL(closeMe() ) ); |
130 | QObject::connect(m_selector, SIGNAL(newSelected(const DocLnk& ) ), | 130 | QObject::connect(m_selector, SIGNAL(newSelected(const DocLnk&) ), |
131 | selector(), SIGNAL(newSelected(const DocLnk& ) ) ); | 131 | selector(), SIGNAL(newSelected(const DocLnk&) ) ); |
132 | } | 132 | } |
133 | 133 | ||
134 | return m_selector; | 134 | return m_selector; |
135 | } | 135 | } |
136 | 136 | ||
137 | /* | 137 | /* |
138 | * This is the file system view used | 138 | * This is the file system view used |
139 | * we use a QListView + QListViewItems for it | 139 | * we use a QListView + QListViewItems for it |
140 | */ | 140 | */ |
141 | 141 | ||
142 | OFileSelectorItem::OFileSelectorItem( QListView* view, const QPixmap& pixmap, | 142 | OFileSelectorItem::OFileSelectorItem( QListView* view, const QPixmap& pixmap, |
143 | const QString& path, const QString& date, | 143 | const QString& path, const QString& date, |
144 | const QString& size, const QString& dir, | 144 | const QString& size, const QString& dir, |
145 | bool isLocked, bool isDir ) | 145 | bool isLocked, bool isDir ) |
146 | : QListViewItem( view ) | 146 | : QListViewItem( view ) |
147 | { | 147 | { |
148 | setPixmap(0, pixmap ); | 148 | setPixmap(0, pixmap ); |
149 | setText(1, path ); | 149 | setText(1, path ); |
150 | setText(2, size ); | 150 | setText(2, size ); |
151 | setText(3, date ); | 151 | setText(3, date ); |
152 | m_isDir = isDir; | 152 | m_isDir = isDir; |
153 | m_dir = dir; | 153 | m_dir = dir; |
154 | m_locked = isLocked; | 154 | m_locked = isLocked; |
155 | } | 155 | } |
156 | OFileSelectorItem::~OFileSelectorItem() { | 156 | OFileSelectorItem::~OFileSelectorItem() { |
157 | 157 | ||
158 | } | 158 | } |
159 | bool OFileSelectorItem::isLocked()const { | 159 | bool OFileSelectorItem::isLocked()const { |
160 | return m_locked; | 160 | return m_locked; |
161 | } | 161 | } |
162 | QString OFileSelectorItem::directory()const { | 162 | QString OFileSelectorItem::directory()const { |
163 | return m_dir; | 163 | return m_dir; |
164 | } | 164 | } |
165 | bool OFileSelectorItem::isDir()const { | 165 | bool OFileSelectorItem::isDir()const { |
166 | return m_isDir; | 166 | return m_isDir; |
167 | } | 167 | } |
168 | QString OFileSelectorItem::path()const { | 168 | QString OFileSelectorItem::path()const { |
169 | return text( 1 ); | 169 | return text( 1 ); |
170 | } | 170 | } |
171 | QString OFileSelectorItem::key( int id, bool )const { | 171 | QString OFileSelectorItem::key( int id, bool )const { |
172 | QString ke; | 172 | QString ke; |
173 | if( id == 0 || id == 1 ){ // name | 173 | if( id == 0 || id == 1 ){ // name |
174 | if( m_isDir ){ | 174 | if( m_isDir ){ |
175 | ke.append("0" ); | 175 | ke.append("0" ); |
176 | ke.append( text(1) ); | 176 | ke.append( text(1) ); |
177 | }else{ | 177 | }else{ |
178 | ke.append("1" ); | 178 | ke.append("1" ); |
179 | ke.append( text(1) ); | 179 | ke.append( text(1) ); |
180 | } | 180 | } |
181 | return ke; | 181 | return ke; |
182 | }else | 182 | }else |
183 | return text( id ); | 183 | return text( id ); |
184 | 184 | ||
185 | } | 185 | } |
186 | 186 | ||
187 | OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& startDir, | 187 | OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& startDir, |
188 | OFileSelector* sel) | 188 | OFileSelector* sel) |
189 | : QWidget( parent ), m_sel( sel ) { | 189 | : QWidget( parent ), m_sel( sel ) { |
190 | m_all = false; | 190 | m_all = false; |
191 | QVBoxLayout* lay = new QVBoxLayout( this ); | 191 | QVBoxLayout* lay = new QVBoxLayout( this ); |
192 | m_currentDir = startDir; | 192 | m_currentDir = startDir; |
193 | 193 | ||
194 | /* | 194 | /* |
195 | * now we add a special bar | 195 | * now we add a special bar |
196 | * One Button For Up | 196 | * One Button For Up |
197 | * Home | 197 | * Home |
198 | * Doc | 198 | * Doc |
199 | * And a dropdown menu with FileSystems | 199 | * And a dropdown menu with FileSystems |
200 | * FUTURE: one to change dir with lineedit | 200 | * FUTURE: one to change dir with lineedit |
201 | * Bookmarks | 201 | * Bookmarks |
202 | * Create Dir | 202 | * Create Dir |
203 | */ | 203 | */ |
204 | QHBox* box = new QHBox(this ); | 204 | QHBox* box = new QHBox(this ); |
205 | box->setBackgroundMode( PaletteButton ); | 205 | box->setBackgroundMode( PaletteButton ); |
206 | box->setSpacing( 0 ); | 206 | box->setSpacing( 0 ); |
207 | 207 | ||
208 | QToolButton *btn = new QToolButton( box ); | 208 | QToolButton *btn = new QToolButton( box ); |
209 | btn->setIconSet( Resource::loadIconSet("up") ); | 209 | btn->setIconSet( Resource::loadIconSet("up") ); |
210 | connect(btn, SIGNAL(clicked() ), | 210 | connect(btn, SIGNAL(clicked() ), |
211 | this, SLOT( cdUP() ) ); | 211 | this, SLOT( cdUP() ) ); |
212 | 212 | ||
213 | btn = new QToolButton( box ); | 213 | btn = new QToolButton( box ); |
214 | btn->setIconSet( Resource::loadIconSet("home") ); | 214 | btn->setIconSet( Resource::loadIconSet("home") ); |
215 | connect(btn, SIGNAL(clicked() ), | 215 | connect(btn, SIGNAL(clicked() ), |
216 | this, SLOT( cdHome() ) ); | 216 | this, SLOT( cdHome() ) ); |
217 | 217 | ||
218 | btn = new QToolButton( box ); | 218 | btn = new QToolButton( box ); |
219 | btn->setIconSet( Resource::loadIconSet("DocsIcon") ); | 219 | btn->setIconSet( Resource::loadIconSet("DocsIcon") ); |
220 | connect(btn, SIGNAL(clicked() ), | 220 | connect(btn, SIGNAL(clicked() ), |
221 | this, SLOT(cdDoc() ) ); | 221 | this, SLOT(cdDoc() ) ); |
222 | 222 | ||
223 | m_btnNew = new QToolButton( box ); | 223 | m_btnNew = new QToolButton( box ); |
224 | m_btnNew->setIconSet( Resource::loadIconSet("new") ); | 224 | m_btnNew->setIconSet( Resource::loadIconSet("new") ); |
225 | connect(m_btnNew, SIGNAL(clicked() ), | 225 | connect(m_btnNew, SIGNAL(clicked() ), |
226 | this, SLOT(slotNew() ) ); | 226 | this, SLOT(slotNew() ) ); |
227 | 227 | ||
228 | 228 | ||
229 | m_btnClose = new QToolButton( box ); | 229 | m_btnClose = new QToolButton( box ); |
230 | m_btnClose->setIconSet( Resource::loadIconSet("close") ); | 230 | m_btnClose->setIconSet( Resource::loadIconSet("close") ); |
231 | connect(m_btnClose, SIGNAL(clicked() ), | 231 | connect(m_btnClose, SIGNAL(clicked() ), |
232 | selector(), SIGNAL(closeMe() ) ); | 232 | selector(), SIGNAL(closeMe() ) ); |
233 | 233 | ||
234 | btn = new QToolButton( box ); | 234 | btn = new QToolButton( box ); |
235 | btn->setIconSet( Resource::loadIconSet("cardmon/pcmcia") ); | 235 | btn->setIconSet( Resource::loadIconSet("cardmon/pcmcia") ); |
236 | 236 | ||
237 | /* let's fill device parts */ | 237 | /* let's fill device parts */ |
238 | QPopupMenu* pop = new QPopupMenu(this); | 238 | QPopupMenu* pop = new QPopupMenu(this); |
239 | connect(pop, SIGNAL( activated(int) ), | 239 | connect(pop, SIGNAL( activated(int) ), |
240 | this, SLOT(slotFSActivated(int) ) ); | 240 | this, SLOT(slotFSActivated(int) ) ); |
241 | 241 | ||
242 | StorageInfo storage; | 242 | StorageInfo storage; |
243 | const QList<FileSystem> &fs = storage.fileSystems(); | 243 | const QList<FileSystem> &fs = storage.fileSystems(); |
244 | QListIterator<FileSystem> it(fs); | 244 | QListIterator<FileSystem> it(fs); |
245 | for ( ; it.current(); ++it ) { | 245 | for ( ; it.current(); ++it ) { |
246 | const QString disk = (*it)->name(); | 246 | const QString disk = (*it)->name(); |
247 | const QString path = (*it)->path(); | 247 | const QString path = (*it)->path(); |
248 | m_dev.insert( disk, path ); | 248 | m_dev.insert( disk, path ); |
249 | pop->insertItem( disk ); | 249 | pop->insertItem( disk ); |
250 | } | 250 | } |
251 | m_fsPop = pop; | 251 | m_fsPop = pop; |
252 | 252 | ||
253 | 253 | ||
254 | btn->setPopup( pop ); | 254 | btn->setPopup( pop ); |
255 | 255 | ||
256 | lay->addWidget( box ); | 256 | lay->addWidget( box ); |
257 | 257 | ||
258 | m_view = new QListView( this ); | 258 | m_view = new QListView( this ); |
259 | 259 | ||
260 | m_view->installEventFilter(this); | 260 | m_view->installEventFilter(this); |
261 | 261 | ||
262 | QPEApplication::setStylusOperation( m_view->viewport(), | 262 | QPEApplication::setStylusOperation( m_view->viewport(), |
263 | QPEApplication::RightOnHold); | 263 | QPEApplication::RightOnHold); |
264 | m_view->addColumn(" " ); | 264 | m_view->addColumn(" " ); |
265 | m_view->addColumn(tr("Name"), 135 ); | 265 | m_view->addColumn(tr("Name"), 135 ); |
266 | m_view->addColumn(tr("Size"), -1 ); | 266 | m_view->addColumn(tr("Size"), -1 ); |
267 | m_view->addColumn(tr("Date"), 60 ); | 267 | m_view->addColumn(tr("Date"), 60 ); |
268 | m_view->addColumn(tr("Mime Type"), -1 ); | 268 | m_view->addColumn(tr("Mime Type"), -1 ); |
269 | 269 | ||
270 | 270 | ||
271 | m_view->setSorting( 1 ); | 271 | m_view->setSorting( 1 ); |
272 | m_view->setAllColumnsShowFocus( TRUE ); | 272 | m_view->setAllColumnsShowFocus( TRUE ); |
273 | 273 | ||
274 | lay->addWidget( m_view, 1000 ); | 274 | lay->addWidget( m_view, 1000 ); |
275 | connectSlots(); | 275 | connectSlots(); |
276 | } | 276 | } |
277 | OFileViewFileListView::~OFileViewFileListView() { | 277 | OFileViewFileListView::~OFileViewFileListView() { |
278 | } | 278 | } |
279 | void OFileViewFileListView::slotNew() { | 279 | void OFileViewFileListView::slotNew() { |
280 | DocLnk lnk; | 280 | DocLnk lnk; |
281 | emit selector()->newSelected( lnk ); | 281 | emit selector()->newSelected( lnk ); |
282 | } | 282 | } |
283 | OFileSelectorItem* OFileViewFileListView::currentItem()const{ | 283 | OFileSelectorItem* OFileViewFileListView::currentItem()const{ |
284 | QListViewItem* item = m_view->currentItem(); | 284 | QListViewItem* item = m_view->currentItem(); |
285 | if (!item ) | 285 | if (!item ) |
286 | return 0l; | 286 | return 0l; |
287 | 287 | ||
288 | return static_cast<OFileSelectorItem*>(item); | 288 | return static_cast<OFileSelectorItem*>(item); |
289 | } | 289 | } |
290 | void OFileViewFileListView::reread( bool all ) { | 290 | void OFileViewFileListView::reread( bool all ) { |
291 | m_view->clear(); | 291 | m_view->clear(); |
292 | 292 | ||
293 | if (selector()->showClose() ) | 293 | if (selector()->showClose() ) |
294 | m_btnClose->show(); | 294 | m_btnClose->show(); |
295 | else | 295 | else |
296 | m_btnClose->hide(); | 296 | m_btnClose->hide(); |
297 | 297 | ||
298 | if (selector()->showNew() ) | 298 | if (selector()->showNew() ) |
299 | m_btnNew->show(); | 299 | m_btnNew->show(); |
300 | else | 300 | else |
301 | m_btnNew->hide(); | 301 | m_btnNew->hide(); |
302 | 302 | ||
303 | m_mimes = selector()->currentMimeType(); | 303 | m_mimes = selector()->currentMimeType(); |
304 | m_all = all; | 304 | m_all = all; |
305 | 305 | ||
306 | QDir dir( m_currentDir ); | 306 | QDir dir( m_currentDir ); |
307 | if (!dir.exists() ) | 307 | if (!dir.exists() ) |
308 | return; | 308 | return; |
309 | 309 | ||
310 | dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed ); | 310 | dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed ); |
311 | int filter; | 311 | int filter; |
312 | if (m_all ) | 312 | if (m_all ) |
313 | filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; | 313 | filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; |
314 | else | 314 | else |
315 | filter = QDir::Files | QDir::Dirs | QDir::All; | 315 | filter = QDir::Files | QDir::Dirs | QDir::All; |
316 | dir.setFilter( filter ); | 316 | dir.setFilter( filter ); |
317 | 317 | ||
318 | // now go through all files | 318 | // now go through all files |
319 | const QFileInfoList *list = dir.entryInfoList(); | 319 | const QFileInfoList *list = dir.entryInfoList(); |
320 | if (!list) { | 320 | if (!list) { |
321 | cdUP(); | 321 | cdUP(); |
322 | return; | 322 | return; |
323 | } | 323 | } |
324 | QFileInfoListIterator it( *list ); | 324 | QFileInfoListIterator it( *list ); |
325 | QFileInfo *fi; | 325 | QFileInfo *fi; |
326 | while( (fi=it.current() ) ){ | 326 | while( (fi=it.current() ) ){ |
327 | if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ){ | 327 | if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ){ |
328 | ++it; | 328 | ++it; |
329 | continue; | 329 | continue; |
330 | } | 330 | } |
331 | 331 | ||
332 | /* | 332 | /* |
333 | * It is a symlink we try to resolve it now but don't let us attack by DOS | 333 | * It is a symlink we try to resolve it now but don't let us attack by DOS |
334 | * | 334 | * |
335 | */ | 335 | */ |
336 | if( fi->isSymLink() ){ | 336 | if( fi->isSymLink() ){ |
337 | QString file = fi->dirPath( true ) + "/" + fi->readLink(); | 337 | QString file = fi->dirPath( true ) + "/" + fi->readLink(); |
338 | for( int i = 0; i<=4; i++) { // 5 tries to prevent dos | 338 | for( int i = 0; i<=4; i++) { // 5 tries to prevent dos |
339 | QFileInfo info( file ); | 339 | QFileInfo info( file ); |
340 | if( !info.exists() ){ | 340 | if( !info.exists() ){ |
341 | addSymlink( fi, TRUE ); | 341 | addSymlink( fi, TRUE ); |
342 | break; | 342 | break; |
343 | }else if( info.isDir() ){ | 343 | }else if( info.isDir() ){ |
344 | addDir( fi, TRUE ); | 344 | addDir( fi, TRUE ); |
345 | break; | 345 | break; |
346 | }else if( info.isFile() ){ | 346 | }else if( info.isFile() ){ |
347 | addFile( fi, TRUE ); | 347 | addFile( fi, TRUE ); |
348 | break; | 348 | break; |
349 | }else if( info.isSymLink() ){ | 349 | }else if( info.isSymLink() ){ |
350 | file = info.dirPath(true ) + "/" + info.readLink() ; | 350 | file = info.dirPath(true ) + "/" + info.readLink() ; |
351 | break; | 351 | break; |
352 | }else if( i == 4){ // couldn't resolve symlink add it as symlink | 352 | }else if( i == 4){ // couldn't resolve symlink add it as symlink |
353 | addSymlink( fi ); | 353 | addSymlink( fi ); |
354 | } | 354 | } |
355 | } // off for loop for symlink resolving | 355 | } // off for loop for symlink resolving |
356 | }else if( fi->isDir() ) | 356 | }else if( fi->isDir() ) |
357 | addDir( fi ); | 357 | addDir( fi ); |
358 | else if( fi->isFile() ) | 358 | else if( fi->isFile() ) |
359 | addFile( fi ); | 359 | addFile( fi ); |
360 | 360 | ||
361 | ++it; | 361 | ++it; |
362 | } // of while loop | 362 | } // of while loop |
363 | m_view->sort(); | 363 | m_view->sort(); |
364 | 364 | ||
365 | } | 365 | } |
366 | int OFileViewFileListView::fileCount()const{ | 366 | int OFileViewFileListView::fileCount()const{ |
367 | return m_view->childCount(); | 367 | return m_view->childCount(); |
368 | } | 368 | } |
369 | QString OFileViewFileListView::currentDir()const{ | 369 | QString OFileViewFileListView::currentDir()const{ |
370 | return m_currentDir; | 370 | return m_currentDir; |
371 | } | 371 | } |
372 | OFileSelector* OFileViewFileListView::selector() { | 372 | OFileSelector* OFileViewFileListView::selector() { |
373 | return m_sel; | 373 | return m_sel; |
374 | } | 374 | } |
375 | 375 | ||
376 | bool OFileViewFileListView::eventFilter (QObject *o, QEvent *e) { | 376 | bool OFileViewFileListView::eventFilter (QObject *o, QEvent *e) { |
377 | if ( e->type() == QEvent::KeyPress ) { | 377 | if ( e->type() == QEvent::KeyPress ) { |
378 | QKeyEvent *k = (QKeyEvent *)e; | 378 | QKeyEvent *k = (QKeyEvent *)e; |
379 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) { | 379 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) { |
380 | slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0); | 380 | slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0); |
381 | return true; | 381 | return true; |
382 | } | 382 | } |
383 | } | 383 | } |
384 | return false; | 384 | return false; |
385 | } | 385 | } |
386 | 386 | ||
387 | 387 | ||
388 | void OFileViewFileListView::connectSlots() { | 388 | void OFileViewFileListView::connectSlots() { |
389 | connect(m_view, SIGNAL(clicked(QListViewItem*) ), | 389 | connect(m_view, SIGNAL(clicked(QListViewItem*) ), |
390 | this, SLOT(slotCurrentChanged(QListViewItem*) ) ); | 390 | this, SLOT(slotCurrentChanged(QListViewItem*) ) ); |
391 | connect(m_view, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint&, int ) ), | 391 | connect(m_view, SIGNAL(mouseButtonClicked(int,QListViewItem*,const QPoint&,int) ), |
392 | this, SLOT(slotClicked(int, QListViewItem*, const QPoint&, int ) ) ); | 392 | this, SLOT(slotClicked(int,QListViewItem*,const QPoint&,int) ) ); |
393 | } | 393 | } |
394 | void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) { | 394 | void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) { |
395 | if (!item) | 395 | if (!item) |
396 | return; | 396 | return; |
397 | #if 0 | 397 | #if 0 |
398 | 398 | ||
399 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); | 399 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); |
400 | 400 | ||
401 | if (!sel->isDir() ) { | 401 | if (!sel->isDir() ) { |
402 | selector()->m_lneEdit->setText( sel->text(1) ); | 402 | selector()->m_lneEdit->setText( sel->text(1) ); |
403 | // if in fileselector mode we will emit selected | 403 | // if in fileselector mode we will emit selected |
404 | if ( selector()->mode() == OFileSelector::FileSelector ) { | 404 | if ( selector()->mode() == OFileSelector::FileSelector ) { |
405 | qWarning("slot Current Changed"); | 405 | qWarning("slot Current Changed"); |
406 | QStringList str = QStringList::split("->", sel->text(1) ); | 406 | QStringList str = QStringList::split("->", sel->text(1) ); |
407 | QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); | 407 | QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); |
408 | emit selector()->fileSelected( path ); | 408 | emit selector()->fileSelected( path ); |
409 | DocLnk lnk( path ); | 409 | DocLnk lnk( path ); |
410 | emit selector()->fileSelected( lnk ); | 410 | emit selector()->fileSelected( lnk ); |
411 | } | 411 | } |
412 | } | 412 | } |
413 | #endif | 413 | #endif |
414 | } | 414 | } |
415 | void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) { | 415 | void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) { |
416 | if (!item || ( button != Qt::LeftButton) ) | 416 | if (!item || ( button != Qt::LeftButton) ) |
417 | return; | 417 | return; |
418 | 418 | ||
419 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); | 419 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); |
420 | if (!sel->isLocked() ) { | 420 | if (!sel->isLocked() ) { |
421 | QStringList str = QStringList::split("->", sel->text(1) ); | 421 | QStringList str = QStringList::split("->", sel->text(1) ); |
422 | if (sel->isDir() ) { | 422 | if (sel->isDir() ) { |
423 | m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace(); | 423 | m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace(); |
424 | emit selector()->dirSelected( m_currentDir ); | 424 | emit selector()->dirSelected( m_currentDir ); |
425 | reread( m_all ); | 425 | reread( m_all ); |
426 | }else { // file | 426 | }else { // file |
427 | qWarning("slot Clicked"); | 427 | qWarning("slot Clicked"); |
428 | selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); | 428 | selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); |
429 | QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); | 429 | QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); |
430 | emit selector()->fileSelected( path ); | 430 | emit selector()->fileSelected( path ); |
431 | DocLnk lnk( path ); | 431 | DocLnk lnk( path ); |
432 | emit selector()->fileSelected( lnk ); | 432 | emit selector()->fileSelected( lnk ); |
433 | } | 433 | } |
434 | } // not locked | 434 | } // not locked |
435 | } | 435 | } |
436 | void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) { | 436 | void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) { |
437 | MimeType type( info->absFilePath() ); | 437 | MimeType type( info->absFilePath() ); |
438 | if (!compliesMime( type.id() ) ) | 438 | if (!compliesMime( type.id() ) ) |
439 | return; | 439 | return; |
440 | 440 | ||
441 | QPixmap pix = type.pixmap(); | 441 | QPixmap pix = type.pixmap(); |
442 | QString dir, name; bool locked; | 442 | QString dir, name; bool locked; |
443 | if ( pix.isNull() ) { | 443 | if ( pix.isNull() ) { |
444 | QWMatrix matrix; | 444 | QWMatrix matrix; |
445 | QPixmap pixer(Resource::loadPixmap("UnknownDocument") ); | 445 | QPixmap pixer(Resource::loadPixmap("UnknownDocument") ); |
446 | matrix.scale( .4, .4 ); | 446 | matrix.scale( .4, .4 ); |
447 | pix = pixer.xForm( matrix ); | 447 | pix = pixer.xForm( matrix ); |
448 | } | 448 | } |
449 | dir = info->dirPath( true ); | 449 | dir = info->dirPath( true ); |
450 | locked = false; | 450 | locked = false; |
451 | if ( symlink ) | 451 | if ( symlink ) |
452 | name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink(); | 452 | name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink(); |
453 | else{ | 453 | else{ |
454 | name = info->fileName(); | 454 | name = info->fileName(); |
455 | if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) || | 455 | if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) || |
456 | ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) { | 456 | ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) { |
457 | locked = true; pix = Resource::loadPixmap("locked"); | 457 | locked = true; pix = Resource::loadPixmap("locked"); |
458 | } | 458 | } |
459 | } | 459 | } |
460 | (void)new OFileSelectorItem( m_view, pix, name, | 460 | (void)new OFileSelectorItem( m_view, pix, name, |
461 | info->lastModified().toString(), QString::number( info->size() ), | 461 | info->lastModified().toString(), QString::number( info->size() ), |
462 | dir, locked ); | 462 | dir, locked ); |
463 | } | 463 | } |
464 | void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) { | 464 | void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) { |
465 | bool locked = false; QString name; QPixmap pix; | 465 | bool locked = false; QString name; QPixmap pix; |
466 | 466 | ||
467 | if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) || | 467 | if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) || |
468 | ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) { | 468 | ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) { |
469 | locked = true; | 469 | locked = true; |
470 | if ( symlink ) | 470 | if ( symlink ) |
471 | pix = Resource::loadPixmap( "opie/symlink" ); | 471 | pix = Resource::loadPixmap( "opie/symlink" ); |
472 | else | 472 | else |
473 | pix = Resource::loadPixmap( "lockedfolder" ); | 473 | pix = Resource::loadPixmap( "lockedfolder" ); |
474 | }else | 474 | }else |
475 | pix = symlink ? Resource::loadPixmap( "opie/symlink") : Resource::loadPixmap("folder"); | 475 | pix = symlink ? Resource::loadPixmap( "opie/symlink") : Resource::loadPixmap("folder"); |
476 | 476 | ||
477 | name = symlink ? info->fileName() + " -> " + info->dirPath(true) + "/" + info->readLink() : | 477 | name = symlink ? info->fileName() + " -> " + info->dirPath(true) + "/" + info->readLink() : |
478 | info->fileName(); | 478 | info->fileName(); |
479 | 479 | ||
480 | (void)new OFileSelectorItem( m_view, pix, name, | 480 | (void)new OFileSelectorItem( m_view, pix, name, |
481 | info->lastModified().toString(), | 481 | info->lastModified().toString(), |
482 | QString::number( info->size() ), | 482 | QString::number( info->size() ), |
483 | info->dirPath( true ), locked, true ); | 483 | info->dirPath( true ), locked, true ); |
484 | 484 | ||
485 | 485 | ||
486 | } | 486 | } |
487 | void OFileViewFileListView::addSymlink( QFileInfo* , bool ) { | 487 | void OFileViewFileListView::addSymlink( QFileInfo* , bool ) { |
488 | 488 | ||
489 | } | 489 | } |
490 | void OFileViewFileListView::cdUP() { | 490 | void OFileViewFileListView::cdUP() { |
491 | QDir dir( m_currentDir ); | 491 | QDir dir( m_currentDir ); |
492 | dir.cdUp(); | 492 | dir.cdUp(); |
493 | 493 | ||
494 | if (!dir.exists() ) | 494 | if (!dir.exists() ) |
495 | m_currentDir = "/"; | 495 | m_currentDir = "/"; |
496 | else | 496 | else |
497 | m_currentDir = dir.absPath(); | 497 | m_currentDir = dir.absPath(); |
498 | 498 | ||
499 | emit selector()->dirSelected( m_currentDir ); | 499 | emit selector()->dirSelected( m_currentDir ); |
500 | reread( m_all ); | 500 | reread( m_all ); |
501 | } | 501 | } |
502 | void OFileViewFileListView::cdHome() { | 502 | void OFileViewFileListView::cdHome() { |
503 | m_currentDir = QDir::homeDirPath(); | 503 | m_currentDir = QDir::homeDirPath(); |
504 | emit selector()->dirSelected( m_currentDir ); | 504 | emit selector()->dirSelected( m_currentDir ); |
505 | reread( m_all ); | 505 | reread( m_all ); |
506 | } | 506 | } |
507 | void OFileViewFileListView::cdDoc() { | 507 | void OFileViewFileListView::cdDoc() { |
508 | m_currentDir = QPEApplication::documentDir(); | 508 | m_currentDir = QPEApplication::documentDir(); |
509 | emit selector()->dirSelected( m_currentDir ); | 509 | emit selector()->dirSelected( m_currentDir ); |
510 | reread( m_all ); | 510 | reread( m_all ); |
511 | } | 511 | } |
512 | void OFileViewFileListView::changeDir( const QString& dir ) { | 512 | void OFileViewFileListView::changeDir( const QString& dir ) { |
513 | m_currentDir = dir; | 513 | m_currentDir = dir; |
514 | emit selector()->dirSelected( m_currentDir ); | 514 | emit selector()->dirSelected( m_currentDir ); |
515 | reread( m_all ); | 515 | reread( m_all ); |
516 | } | 516 | } |
517 | void OFileViewFileListView::slotFSActivated( int id ) { | 517 | void OFileViewFileListView::slotFSActivated( int id ) { |
518 | changeDir ( m_dev[m_fsPop->text(id)] ); | 518 | changeDir ( m_dev[m_fsPop->text(id)] ); |
519 | } | 519 | } |
520 | 520 | ||
521 | /* check if the mimetype in mime | 521 | /* check if the mimetype in mime |
522 | * complies with the one which is current | 522 | * complies with the one which is current |
523 | */ | 523 | */ |
524 | /* | 524 | /* |
525 | * We've the mimetype of the file | 525 | * We've the mimetype of the file |
526 | * We need to get the stringlist of the current mimetype | 526 | * We need to get the stringlist of the current mimetype |
527 | * | 527 | * |
528 | * mime = image@slashjpeg | 528 | * mime = image@slashjpeg |
529 | * QStringList = 'image@slash*' | 529 | * QStringList = 'image@slash*' |
530 | * or QStringList = image/jpeg;image/png;application/x-ogg | 530 | * or QStringList = image/jpeg;image/png;application/x-ogg |
531 | * or QStringList = application/x-ogg;image@slash*; | 531 | * or QStringList = application/x-ogg;image@slash*; |
532 | * with all these mime filters it should get acceptes | 532 | * with all these mime filters it should get acceptes |
533 | * to do so we need to look if mime is contained inside | 533 | * to do so we need to look if mime is contained inside |
534 | * the stringlist | 534 | * the stringlist |
535 | * if it's contained return true | 535 | * if it's contained return true |
536 | * if not ( I'm no RegExp expert at all ) we'll look if a '@slash*' | 536 | * if not ( I'm no RegExp expert at all ) we'll look if a '@slash*' |
537 | * is contained in the mimefilter and then we will | 537 | * is contained in the mimefilter and then we will |
538 | * look if both are equal until the '/' | 538 | * look if both are equal until the '/' |
539 | */ | 539 | */ |
540 | bool OFileViewFileListView::compliesMime( const QString& str) { | 540 | bool OFileViewFileListView::compliesMime( const QString& str) { |
541 | if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() ) | 541 | if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() ) |
542 | return true; | 542 | return true; |
543 | 543 | ||
544 | for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it ) { | 544 | for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it ) { |
545 | QRegExp reg( (*it) ); | 545 | QRegExp reg( (*it) ); |
546 | reg.setWildcard( true ); | 546 | reg.setWildcard( true ); |
547 | if ( str.find( reg ) != -1 ) | 547 | if ( str.find( reg ) != -1 ) |
548 | return true; | 548 | return true; |
549 | 549 | ||
550 | } | 550 | } |
551 | return false; | 551 | return false; |
552 | } | 552 | } |
553 | /* | 553 | /* |
554 | * The listView giving access to the file system! | 554 | * The listView giving access to the file system! |
555 | */ | 555 | */ |
556 | class OFileViewFileSystem : public OFileViewInterface { | 556 | class OFileViewFileSystem : public OFileViewInterface { |
557 | public: | 557 | public: |
558 | OFileViewFileSystem( OFileSelector* ); | 558 | OFileViewFileSystem( OFileSelector* ); |
559 | ~OFileViewFileSystem(); | 559 | ~OFileViewFileSystem(); |
560 | 560 | ||
561 | QString selectedName() const; | 561 | QString selectedName() const; |
562 | QString selectedPath() const; | 562 | QString selectedPath() const; |
563 | 563 | ||
564 | QString directory()const; | 564 | QString directory()const; |
565 | void reread(); | 565 | void reread(); |
566 | int fileCount()const; | 566 | int fileCount()const; |
567 | 567 | ||
568 | QWidget* widget( QWidget* parent ); | 568 | QWidget* widget( QWidget* parent ); |
569 | void activate( const QString& ); | 569 | void activate( const QString& ); |
570 | private: | 570 | private: |
571 | OFileViewFileListView* m_view; | 571 | OFileViewFileListView* m_view; |
572 | bool m_all : 1; | 572 | bool m_all : 1; |
573 | }; | 573 | }; |
574 | OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel) | 574 | OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel) |
575 | : OFileViewInterface( sel ) { | 575 | : OFileViewInterface( sel ) { |
576 | m_view = 0; | 576 | m_view = 0; |
577 | m_all = false; | 577 | m_all = false; |
578 | } | 578 | } |
579 | OFileViewFileSystem::~OFileViewFileSystem() { | 579 | OFileViewFileSystem::~OFileViewFileSystem() { |
580 | } | 580 | } |
581 | QString OFileViewFileSystem::selectedName()const{ | 581 | QString OFileViewFileSystem::selectedName()const{ |
582 | if (!m_view ) | 582 | if (!m_view ) |
583 | return QString::null; | 583 | return QString::null; |
584 | 584 | ||
@@ -591,339 +591,339 @@ QString OFileViewFileSystem::selectedPath()const{ | |||
591 | } | 591 | } |
592 | QString OFileViewFileSystem::directory()const{ | 592 | QString OFileViewFileSystem::directory()const{ |
593 | if (!m_view) | 593 | if (!m_view) |
594 | return QString::null; | 594 | return QString::null; |
595 | 595 | ||
596 | OFileSelectorItem* item = m_view->currentItem(); | 596 | OFileSelectorItem* item = m_view->currentItem(); |
597 | if (!item ) | 597 | if (!item ) |
598 | return QString::null; | 598 | return QString::null; |
599 | 599 | ||
600 | return QDir(item->directory() ).absPath(); | 600 | return QDir(item->directory() ).absPath(); |
601 | } | 601 | } |
602 | void OFileViewFileSystem::reread() { | 602 | void OFileViewFileSystem::reread() { |
603 | if (!m_view) | 603 | if (!m_view) |
604 | return; | 604 | return; |
605 | 605 | ||
606 | m_view->reread( m_all ); | 606 | m_view->reread( m_all ); |
607 | } | 607 | } |
608 | int OFileViewFileSystem::fileCount()const{ | 608 | int OFileViewFileSystem::fileCount()const{ |
609 | if (!m_view ) | 609 | if (!m_view ) |
610 | return -1; | 610 | return -1; |
611 | return m_view->fileCount(); | 611 | return m_view->fileCount(); |
612 | } | 612 | } |
613 | QWidget* OFileViewFileSystem::widget( QWidget* parent ) { | 613 | QWidget* OFileViewFileSystem::widget( QWidget* parent ) { |
614 | if (!m_view ) { | 614 | if (!m_view ) { |
615 | m_view = new OFileViewFileListView( parent, startDirectory(), selector() ); | 615 | m_view = new OFileViewFileListView( parent, startDirectory(), selector() ); |
616 | } | 616 | } |
617 | return m_view; | 617 | return m_view; |
618 | } | 618 | } |
619 | void OFileViewFileSystem::activate( const QString& str) { | 619 | void OFileViewFileSystem::activate( const QString& str) { |
620 | m_all = (str != QObject::tr("Files") ); | 620 | m_all = (str != QObject::tr("Files") ); |
621 | 621 | ||
622 | 622 | ||
623 | } | 623 | } |
624 | 624 | ||
625 | /* Selector */ | 625 | /* Selector */ |
626 | /** | 626 | /** |
627 | * @short new and complete c'tor | 627 | * @short new and complete c'tor |
628 | * | 628 | * |
629 | * Create a OFileSelector to let the user select a file. It can | 629 | * Create a OFileSelector to let the user select a file. It can |
630 | * either be used to open a file, select a save name in a dir or | 630 | * either be used to open a file, select a save name in a dir or |
631 | * as a dropin for the FileSelector. | 631 | * as a dropin for the FileSelector. |
632 | * | 632 | * |
633 | * <pre> | 633 | * <pre> |
634 | * QMap<QString, QStringList> mimeTypes; | 634 | * QMap<QString, QStringList> mimeTypes; |
635 | * QStringList types; | 635 | * QStringList types; |
636 | * types << "text@slash* "; | 636 | * types << "text@slash* "; |
637 | * types << "audio@slash*"; | 637 | * types << "audio@slash*"; |
638 | * mimeTypes.insert( tr("Audio and Text"), types ); | 638 | * mimeTypes.insert( tr("Audio and Text"), types ); |
639 | * mimeTypes.insert( tr("All"), "*@slash*); | 639 | * mimeTypes.insert( tr("All"), "*@slash*); |
640 | * | 640 | * |
641 | * now you could create your fileselector | 641 | * now you could create your fileselector |
642 | * </pre> | 642 | * </pre> |
643 | * | 643 | * |
644 | * | 644 | * |
645 | * @param parent the parent of this widget | 645 | * @param parent the parent of this widget |
646 | * @param mode The mode from the enum Mode (Open,Save,FILESELECTOR) | 646 | * @param mode The mode from the enum Mode (Open,Save,FILESELECTOR) |
647 | * @param sel The selector to be used | 647 | * @param sel The selector to be used |
648 | * @param dirName The name of the dir to start int | 648 | * @param dirName The name of the dir to start int |
649 | * @param fileName The fileName placed in the fileselector lineedit | 649 | * @param fileName The fileName placed in the fileselector lineedit |
650 | * @param mimetypes The MimeType map of used mimetypes | 650 | * @param mimetypes The MimeType map of used mimetypes |
651 | * @param showNew Show a New Button. Most likely to be used in the FileSelector view. | 651 | * @param showNew Show a New Button. Most likely to be used in the FileSelector view. |
652 | * @param showClose Show a Close Button. Most likely to be used in FileSelector view. | 652 | * @param showClose Show a Close Button. Most likely to be used in FileSelector view. |
653 | * | 653 | * |
654 | */ | 654 | */ |
655 | OFileSelector::OFileSelector( QWidget* parent, int mode, int sel, | 655 | OFileSelector::OFileSelector( QWidget* parent, int mode, int sel, |
656 | const QString& dirName, const QString& fileName, | 656 | const QString& dirName, const QString& fileName, |
657 | const MimeTypes& mimetypes, | 657 | const MimeTypes& mimetypes, |
658 | bool showNew, bool showClose) | 658 | bool showNew, bool showClose) |
659 | : QWidget( parent, "OFileSelector" ) | 659 | : QWidget( parent, "OFileSelector" ) |
660 | { | 660 | { |
661 | m_current = 0; | 661 | m_current = 0; |
662 | m_shNew = showNew; | 662 | m_shNew = showNew; |
663 | m_shClose = showClose; | 663 | m_shClose = showClose; |
664 | m_mimeType = mimetypes; | 664 | m_mimeType = mimetypes; |
665 | m_startDir = dirName; | 665 | m_startDir = dirName; |
666 | 666 | ||
667 | m_mode = mode; | 667 | m_mode = mode; |
668 | m_selector = sel; | 668 | m_selector = sel; |
669 | 669 | ||
670 | initUI(); | 670 | initUI(); |
671 | m_lneEdit->setText( fileName ); | 671 | m_lneEdit->setText( fileName ); |
672 | initMime(); | 672 | initMime(); |
673 | initViews(); | 673 | initViews(); |
674 | 674 | ||
675 | QString str; | 675 | QString str; |
676 | switch ( m_selector ) { | 676 | switch ( m_selector ) { |
677 | default: | 677 | default: |
678 | case Normal: | 678 | case Normal: |
679 | str = QObject::tr("Documents"); | 679 | str = QObject::tr("Documents"); |
680 | m_cmbView->setCurrentItem( 0 ); | 680 | m_cmbView->setCurrentItem( 0 ); |
681 | break; | 681 | break; |
682 | case Extended: | 682 | case Extended: |
683 | str = QObject::tr("Files"); | 683 | str = QObject::tr("Files"); |
684 | m_cmbView->setCurrentItem( 1 ); | 684 | m_cmbView->setCurrentItem( 1 ); |
685 | break; | 685 | break; |
686 | case ExtendedAll: | 686 | case ExtendedAll: |
687 | str = QObject::tr("All Files"); | 687 | str = QObject::tr("All Files"); |
688 | m_cmbView->setCurrentItem( 2 ); | 688 | m_cmbView->setCurrentItem( 2 ); |
689 | break; | 689 | break; |
690 | } | 690 | } |
691 | slotViewChange( str ); | 691 | slotViewChange( str ); |
692 | 692 | ||
693 | } | 693 | } |
694 | 694 | ||
695 | /** | 695 | /** |
696 | * This a convience c'tor to just substitute the use of FileSelector | 696 | * This a convience c'tor to just substitute the use of FileSelector |
697 | */ | 697 | */ |
698 | OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name, | 698 | OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name, |
699 | bool showNew, bool showClose ) | 699 | bool showNew, bool showClose ) |
700 | : QWidget( parent, name ) | 700 | : QWidget( parent, name ) |
701 | { | 701 | { |
702 | m_current = 0; | 702 | m_current = 0; |
703 | m_shNew = showNew; | 703 | m_shNew = showNew; |
704 | m_shClose = showClose; | 704 | m_shClose = showClose; |
705 | m_startDir = QPEApplication::documentDir(); | 705 | m_startDir = QPEApplication::documentDir(); |
706 | 706 | ||
707 | if (!mimeFilter.isEmpty() ) | 707 | if (!mimeFilter.isEmpty() ) |
708 | m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) ); | 708 | m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) ); |
709 | 709 | ||
710 | m_mode = OFileSelector::FileSelector; | 710 | m_mode = OFileSelector::FileSelector; |
711 | m_selector = OFileSelector::Normal; | 711 | m_selector = OFileSelector::Normal; |
712 | 712 | ||
713 | initUI(); | 713 | initUI(); |
714 | initMime(); | 714 | initMime(); |
715 | initViews(); | 715 | initViews(); |
716 | m_cmbView->setCurrentItem( 0 ); | 716 | m_cmbView->setCurrentItem( 0 ); |
717 | slotViewChange( QObject::tr("Documents") ); | 717 | slotViewChange( QObject::tr("Documents") ); |
718 | } | 718 | } |
719 | /* | 719 | /* |
720 | * INIT UI will set up the basic GUI | 720 | * INIT UI will set up the basic GUI |
721 | * Layout: Simple VBoxLayout | 721 | * Layout: Simple VBoxLayout |
722 | * On top a WidgetStack containing the Views... | 722 | * On top a WidgetStack containing the Views... |
723 | * - List View | 723 | * - List View |
724 | * - Document View | 724 | * - Document View |
725 | * Below we will have a Label + LineEdit | 725 | * Below we will have a Label + LineEdit |
726 | * Below we will have two ComoBoxes one for choosing the view one for | 726 | * Below we will have two ComoBoxes one for choosing the view one for |
727 | * choosing the mimetype | 727 | * choosing the mimetype |
728 | */ | 728 | */ |
729 | void OFileSelector::initUI() { | 729 | void OFileSelector::initUI() { |
730 | QVBoxLayout* lay = new QVBoxLayout( this ); | 730 | QVBoxLayout* lay = new QVBoxLayout( this ); |
731 | 731 | ||
732 | m_stack = new QWidgetStack( this ); | 732 | m_stack = new QWidgetStack( this ); |
733 | lay->addWidget( m_stack, 1000 ); | 733 | lay->addWidget( m_stack, 1000 ); |
734 | 734 | ||
735 | m_nameBox = new QHBox( this ); | 735 | m_nameBox = new QHBox( this ); |
736 | (void)new QLabel( tr("Name:"), m_nameBox ); | 736 | (void)new QLabel( tr("Name:"), m_nameBox ); |
737 | m_lneEdit = new QLineEdit( m_nameBox ); | 737 | m_lneEdit = new QLineEdit( m_nameBox ); |
738 | m_lneEdit ->installEventFilter(this); | 738 | m_lneEdit ->installEventFilter(this); |
739 | lay->addWidget( m_nameBox ); | 739 | lay->addWidget( m_nameBox ); |
740 | 740 | ||
741 | m_cmbBox = new QHBox( this ); | 741 | m_cmbBox = new QHBox( this ); |
742 | m_cmbView = new QComboBox( m_cmbBox ); | 742 | m_cmbView = new QComboBox( m_cmbBox ); |
743 | m_cmbMime = new QComboBox( m_cmbBox ); | 743 | m_cmbMime = new QComboBox( m_cmbBox ); |
744 | lay->addWidget( m_cmbBox ); | 744 | lay->addWidget( m_cmbBox ); |
745 | } | 745 | } |
746 | 746 | ||
747 | /* | 747 | /* |
748 | * This will make sure that the return key in the name edit causes dialogs to close | 748 | * This will make sure that the return key in the name edit causes dialogs to close |
749 | */ | 749 | */ |
750 | 750 | ||
751 | bool OFileSelector::eventFilter (QObject *o, QEvent *e) { | 751 | bool OFileSelector::eventFilter (QObject *o, QEvent *e) { |
752 | if ( e->type() == QEvent::KeyPress ) { | 752 | if ( e->type() == QEvent::KeyPress ) { |
753 | QKeyEvent *k = (QKeyEvent *)e; | 753 | QKeyEvent *k = (QKeyEvent *)e; |
754 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) { | 754 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) { |
755 | emit ok(); | 755 | emit ok(); |
756 | return true; | 756 | return true; |
757 | } | 757 | } |
758 | } | 758 | } |
759 | return false; | 759 | return false; |
760 | } | 760 | } |
761 | 761 | ||
762 | /* | 762 | /* |
763 | * This will insert the MimeTypes into the Combo Box | 763 | * This will insert the MimeTypes into the Combo Box |
764 | * And also connect the changed signal | 764 | * And also connect the changed signal |
765 | * | 765 | * |
766 | * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes | 766 | * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes |
767 | */ | 767 | */ |
768 | void OFileSelector::initMime() { | 768 | void OFileSelector::initMime() { |
769 | MimeTypes::Iterator it; | 769 | MimeTypes::Iterator it; |
770 | for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it ) { | 770 | for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it ) { |
771 | m_cmbMime->insertItem( it.key() ); | 771 | m_cmbMime->insertItem( it.key() ); |
772 | } | 772 | } |
773 | m_cmbMime->setCurrentItem( 0 ); | 773 | m_cmbMime->setCurrentItem( 0 ); |
774 | 774 | ||
775 | connect( m_cmbMime, SIGNAL(activated(int) ), | 775 | connect( m_cmbMime, SIGNAL(activated(int) ), |
776 | this, SLOT(slotMimeTypeChanged() ) ); | 776 | this, SLOT(slotMimeTypeChanged() ) ); |
777 | 777 | ||
778 | } | 778 | } |
779 | void OFileSelector::initViews() { | 779 | void OFileSelector::initViews() { |
780 | m_cmbView->insertItem( QObject::tr("Documents") ); | 780 | m_cmbView->insertItem( QObject::tr("Documents") ); |
781 | m_cmbView->insertItem( QObject::tr("Files") ); | 781 | m_cmbView->insertItem( QObject::tr("Files") ); |
782 | m_cmbView->insertItem( QObject::tr("All Files") ); | 782 | m_cmbView->insertItem( QObject::tr("All Files") ); |
783 | connect(m_cmbView, SIGNAL(activated( const QString& ) ), | 783 | connect(m_cmbView, SIGNAL(activated(const QString&) ), |
784 | this, SLOT(slotViewChange( const QString& ) ) ); | 784 | this, SLOT(slotViewChange(const QString&) ) ); |
785 | 785 | ||
786 | 786 | ||
787 | m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) ); | 787 | m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) ); |
788 | 788 | ||
789 | /* see above why add both */ | 789 | /* see above why add both */ |
790 | OFileViewInterface* in = new OFileViewFileSystem( this ); | 790 | OFileViewInterface* in = new OFileViewFileSystem( this ); |
791 | m_views.insert( QObject::tr("Files"), in ); | 791 | m_views.insert( QObject::tr("Files"), in ); |
792 | m_views.insert( QObject::tr("All Files"), in ); | 792 | m_views.insert( QObject::tr("All Files"), in ); |
793 | } | 793 | } |
794 | 794 | ||
795 | /** | 795 | /** |
796 | * d'tor | 796 | * d'tor |
797 | */ | 797 | */ |
798 | OFileSelector::~OFileSelector() { | 798 | OFileSelector::~OFileSelector() { |
799 | 799 | ||
800 | } | 800 | } |
801 | 801 | ||
802 | /** | 802 | /** |
803 | * Convience function for the fileselector | 803 | * Convience function for the fileselector |
804 | * make sure to delete the DocLnk | 804 | * make sure to delete the DocLnk |
805 | * | 805 | * |
806 | * @see DocLnk | 806 | * @see DocLnk |
807 | * @todo remove in ODP | 807 | * @todo remove in ODP |
808 | */ | 808 | */ |
809 | const DocLnk* OFileSelector::selected() { | 809 | const DocLnk* OFileSelector::selected() { |
810 | DocLnk* lnk = new DocLnk( currentView()->selectedDocument() ); | 810 | DocLnk* lnk = new DocLnk( currentView()->selectedDocument() ); |
811 | return lnk; | 811 | return lnk; |
812 | } | 812 | } |
813 | 813 | ||
814 | /** | 814 | /** |
815 | * | 815 | * |
816 | * @return the name of the selected file | 816 | * @return the name of the selected file |
817 | */ | 817 | */ |
818 | QString OFileSelector::selectedName()const{ | 818 | QString OFileSelector::selectedName()const{ |
819 | return currentView()->selectedName(); | 819 | return currentView()->selectedName(); |
820 | } | 820 | } |
821 | 821 | ||
822 | /** | 822 | /** |
823 | * @return the selected path | 823 | * @return the selected path |
824 | */ | 824 | */ |
825 | QString OFileSelector::selectedPath()const { | 825 | QString OFileSelector::selectedPath()const { |
826 | return currentView()->selectedPath(); | 826 | return currentView()->selectedPath(); |
827 | } | 827 | } |
828 | 828 | ||
829 | /** | 829 | /** |
830 | * @return the directory name | 830 | * @return the directory name |
831 | */ | 831 | */ |
832 | QString OFileSelector::directory()const { | 832 | QString OFileSelector::directory()const { |
833 | return currentView()->directory(); | 833 | return currentView()->directory(); |
834 | } | 834 | } |
835 | 835 | ||
836 | /** | 836 | /** |
837 | * @return a DocLnk for the selected document | 837 | * @return a DocLnk for the selected document |
838 | */ | 838 | */ |
839 | DocLnk OFileSelector::selectedDocument()const { | 839 | DocLnk OFileSelector::selectedDocument()const { |
840 | return currentView()->selectedDocument(); | 840 | return currentView()->selectedDocument(); |
841 | } | 841 | } |
842 | 842 | ||
843 | /** | 843 | /** |
844 | * @return the number of items for the current view | 844 | * @return the number of items for the current view |
845 | */ | 845 | */ |
846 | int OFileSelector::fileCount()const { | 846 | int OFileSelector::fileCount()const { |
847 | return currentView()->fileCount(); | 847 | return currentView()->fileCount(); |
848 | } | 848 | } |
849 | 849 | ||
850 | /** | 850 | /** |
851 | * @return reparse the file content | 851 | * @return reparse the file content |
852 | */ | 852 | */ |
853 | void OFileSelector::reread() { | 853 | void OFileSelector::reread() { |
854 | return currentView()->reread(); | 854 | return currentView()->reread(); |
855 | } | 855 | } |
856 | OFileViewInterface* OFileSelector::currentView()const{ | 856 | OFileViewInterface* OFileSelector::currentView()const{ |
857 | return m_current; | 857 | return m_current; |
858 | } | 858 | } |
859 | bool OFileSelector::showNew()const { | 859 | bool OFileSelector::showNew()const { |
860 | return m_shNew; | 860 | return m_shNew; |
861 | } | 861 | } |
862 | bool OFileSelector::showClose()const { | 862 | bool OFileSelector::showClose()const { |
863 | return m_shClose; | 863 | return m_shClose; |
864 | } | 864 | } |
865 | MimeTypes OFileSelector::mimeTypes()const { | 865 | MimeTypes OFileSelector::mimeTypes()const { |
866 | return m_mimeType; | 866 | return m_mimeType; |
867 | } | 867 | } |
868 | 868 | ||
869 | /** | 869 | /** |
870 | * @return the Mode of the OFileSelector | 870 | * @return the Mode of the OFileSelector |
871 | */ | 871 | */ |
872 | int OFileSelector::mode()const{ | 872 | int OFileSelector::mode()const{ |
873 | return m_mode; | 873 | return m_mode; |
874 | } | 874 | } |
875 | 875 | ||
876 | /** | 876 | /** |
877 | * @return the Selector of the OFileSelector | 877 | * @return the Selector of the OFileSelector |
878 | */ | 878 | */ |
879 | int OFileSelector::selector()const{ | 879 | int OFileSelector::selector()const{ |
880 | return m_selector; | 880 | return m_selector; |
881 | } | 881 | } |
882 | QStringList OFileSelector::currentMimeType()const { | 882 | QStringList OFileSelector::currentMimeType()const { |
883 | return m_mimeType[m_cmbMime->currentText()]; | 883 | return m_mimeType[m_cmbMime->currentText()]; |
884 | } | 884 | } |
885 | void OFileSelector::slotMimeTypeChanged() { | 885 | void OFileSelector::slotMimeTypeChanged() { |
886 | reread(); | 886 | reread(); |
887 | } | 887 | } |
888 | void OFileSelector::slotDocLnkBridge( const DocLnk& lnk) { | 888 | void OFileSelector::slotDocLnkBridge( const DocLnk& lnk) { |
889 | m_lneEdit->setText( lnk.name() ); | 889 | m_lneEdit->setText( lnk.name() ); |
890 | emit fileSelected( lnk ); | 890 | emit fileSelected( lnk ); |
891 | emit fileSelected( lnk.name() ); | 891 | emit fileSelected( lnk.name() ); |
892 | } | 892 | } |
893 | void OFileSelector::slotFileBridge( const QString& str) { | 893 | void OFileSelector::slotFileBridge( const QString& str) { |
894 | DocLnk lnk( str ); | 894 | DocLnk lnk( str ); |
895 | emit fileSelected( lnk ); | 895 | emit fileSelected( lnk ); |
896 | } | 896 | } |
897 | void OFileSelector::slotViewChange( const QString& view ) { | 897 | void OFileSelector::slotViewChange( const QString& view ) { |
898 | OFileViewInterface* interface = m_views[view]; | 898 | OFileViewInterface* interface = m_views[view]; |
899 | if (!interface) | 899 | if (!interface) |
900 | return; | 900 | return; |
901 | 901 | ||
902 | interface->activate( view ); | 902 | interface->activate( view ); |
903 | if (m_current) | 903 | if (m_current) |
904 | m_stack->removeWidget( m_current->widget( m_stack ) ); | 904 | m_stack->removeWidget( m_current->widget( m_stack ) ); |
905 | 905 | ||
906 | static int id = 1; | 906 | static int id = 1; |
907 | 907 | ||
908 | m_stack->addWidget( interface->widget(m_stack), id ); | 908 | m_stack->addWidget( interface->widget(m_stack), id ); |
909 | m_stack->raiseWidget( id ); | 909 | m_stack->raiseWidget( id ); |
910 | 910 | ||
911 | interface->reread(); | 911 | interface->reread(); |
912 | m_current = interface; | 912 | m_current = interface; |
913 | 913 | ||
914 | id++; | 914 | id++; |
915 | } | 915 | } |
916 | void OFileSelector::setNewVisible( bool b ) { | 916 | void OFileSelector::setNewVisible( bool b ) { |
917 | m_shNew = b; | 917 | m_shNew = b; |
918 | currentView()->reread(); | 918 | currentView()->reread(); |
919 | } | 919 | } |
920 | void OFileSelector::setCloseVisible( bool b ) { | 920 | void OFileSelector::setCloseVisible( bool b ) { |
921 | m_shClose = b; | 921 | m_shClose = b; |
922 | currentView()->reread(); | 922 | currentView()->reread(); |
923 | } | 923 | } |
924 | void OFileSelector::setNameVisible( bool b ) { | 924 | void OFileSelector::setNameVisible( bool b ) { |
925 | if ( b ) | 925 | if ( b ) |
926 | m_nameBox->show(); | 926 | m_nameBox->show(); |
927 | else | 927 | else |
928 | m_nameBox->hide(); | 928 | m_nameBox->hide(); |
929 | } | 929 | } |