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 /libopie | |
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 | |||
@@ -1,637 +1,709 @@ | |||
1 | /* | 1 | /* |
2 | =. This file is part of the OPIE Project | 2 | =. This file is part of the OPIE Project |
3 | .=l. Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> | 3 | .=l. Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> |
4 | .>+-= | 4 | .>+-= |
5 | _;:, .> :=|. This library is free software; you can | 5 | _;:, .> :=|. This library is free software; you can |
6 | .> <`_, > . <= redistribute it and/or modify it under | 6 | .> <`_, > . <= redistribute it and/or modify it under |
7 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 7 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
8 | .="- .-=="i, .._ License as published by the Free Software | 8 | .="- .-=="i, .._ License as published by the Free Software |
9 | - . .-<_> .<> Foundation; either version 2 of the License, | 9 | - . .-<_> .<> Foundation; either version 2 of the License, |
10 | ._= =} : or (at your option) any later version. | 10 | ._= =} : or (at your option) any later version. |
11 | .%`+i> _;_. | 11 | .%`+i> _;_. |
12 | .i_,=:_. -<s. This library is distributed in the hope that | 12 | .i_,=:_. -<s. This library is distributed in the hope that |
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
14 | : .. .:, . . . without even the implied warranty of | 14 | : .. .:, . . . without even the implied warranty of |
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
17 | ..}^=.= = ; Library General Public License for more | 17 | ..}^=.= = ; Library General Public License for more |
18 | ++= -. .` .: details. | 18 | ++= -. .` .: details. |
19 | : = ...= . :.=- | 19 | : = ...= . :.=- |
20 | -. .:....=;==+<; You should have received a copy of the GNU | 20 | -. .:....=;==+<; You should have received a copy of the GNU |
21 | -_. . . )=. = Library General Public License along with | 21 | -_. . . )=. = Library General Public License along with |
22 | -- :-=` this library; see the file COPYING.LIB. | 22 | -- :-=` this library; see the file COPYING.LIB. |
23 | If not, write to the Free Software Foundation, | 23 | If not, write to the Free Software Foundation, |
24 | Inc., 59 Temple Place - Suite 330, | 24 | Inc., 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include <qnamespace.h> | 29 | #include <qnamespace.h> |
30 | #include <qpushbutton.h> | 30 | #include <qpushbutton.h> |
31 | #include <qcombobox.h> | 31 | #include <qcombobox.h> |
32 | #include <qhbox.h> | 32 | #include <qhbox.h> |
33 | #include <qvbox.h> | 33 | #include <qvbox.h> |
34 | #include <qlayout.h> | 34 | #include <qlayout.h> |
35 | #include <qwidgetstack.h> | 35 | #include <qwidgetstack.h> |
36 | #include <qlineedit.h> | 36 | #include <qlineedit.h> |
37 | #include <qcheckbox.h> | 37 | #include <qcheckbox.h> |
38 | #include <qlabel.h> | 38 | #include <qlabel.h> |
39 | #include <qheader.h> | 39 | #include <qheader.h> |
40 | #include <qdir.h> | 40 | #include <qdir.h> |
41 | #include <qpainter.h> | 41 | #include <qpainter.h> |
42 | 42 | ||
43 | #include <qpe/qpeapplication.h> | 43 | #include <qpe/qpeapplication.h> |
44 | #include <qpe/fileselector.h> | 44 | #include <qpe/fileselector.h> |
45 | #include <qpe/applnk.h> | 45 | #include <qpe/applnk.h> |
46 | #include <qpe/global.h> | 46 | #include <qpe/global.h> |
47 | #include <qpe/mimetype.h> | 47 | #include <qpe/mimetype.h> |
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; |
60 | m_mimetypes = mimetypes; | 77 | m_mimetypes = mimetypes; |
61 | if( mimetypes.isEmpty() ) | 78 | if( mimetypes.isEmpty() ) |
62 | m_autoMime = true; | 79 | m_autoMime = true; |
63 | 80 | ||
64 | m_mode = mode; | 81 | m_mode = mode; |
65 | m_shTool = true; | 82 | m_shTool = true; |
66 | m_shPerm = true; | 83 | m_shPerm = true; |
67 | m_shLne = true; | 84 | m_shLne = true; |
68 | m_shChooser = true; | 85 | m_shChooser = true; |
69 | m_shYesNo = true; | 86 | m_shYesNo = true; |
70 | // for FILESELECTOR only view is interesting | 87 | // for FILESELECTOR only view is interesting |
71 | m_location = 0; | 88 | m_location = 0; |
72 | m_homeButton = 0; | 89 | m_homeButton = 0; |
73 | m_docButton = 0; | 90 | m_docButton = 0; |
74 | m_hideButton = 0; | 91 | m_hideButton = 0; |
75 | m_ok = 0; | 92 | m_ok = 0; |
76 | m_cancel = 0; | 93 | m_cancel = 0; |
77 | m_reread = 0; | 94 | m_reread = 0; |
78 | m_up = 0; | 95 | m_up = 0; |
79 | m_View = 0; | 96 | m_View = 0; |
80 | m_select = 0; | 97 | m_select = 0; |
81 | m_stack = 0; | 98 | m_stack = 0; |
82 | 99 | ||
83 | m_select = 0; | 100 | m_select = 0; |
84 | m_stack = 0; | 101 | m_stack = 0; |
85 | m_lay = 0; | 102 | m_lay = 0; |
86 | m_boxToolbar = 0; | 103 | m_boxToolbar = 0; |
87 | m_boxOk = 0; | 104 | m_boxOk = 0; |
88 | m_edit = 0; | 105 | m_edit = 0; |
89 | 106 | ||
90 | m_fnLabel = 0; | 107 | m_fnLabel = 0; |
91 | m_checkPerm = 0; | 108 | m_checkPerm = 0; |
92 | m_mimeCheck = 0; | 109 | m_mimeCheck = 0; |
93 | m_viewCheck = 0; | 110 | m_viewCheck = 0; |
94 | 111 | ||
95 | m_dir = true; | 112 | m_dir = true; |
96 | m_files = true; | 113 | m_files = true; |
97 | 114 | ||
98 | if(m_pixmaps == 0 ) // init the pixmaps | 115 | if(m_pixmaps == 0 ) // init the pixmaps |
99 | initPics(); | 116 | initPics(); |
100 | 117 | ||
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 | -------------------- |
121 | | FileSlector | | 145 | | FileSlector | |
122 | | or | | 146 | | or | |
123 | | OSelector | | 147 | | OSelector | |
124 | | | | 148 | | | |
125 | | | | 149 | | | |
126 | ____________________ | 150 | ____________________ |
127 | | LineEdit | | 151 | | LineEdit | |
128 | ____________________ | 152 | ____________________ |
129 | | Permission Bar | | 153 | | Permission Bar | |
130 | ____________________ | 154 | ____________________ |
131 | | ViewChoose | | 155 | | ViewChoose | |
132 | ____________________ | 156 | ____________________ |
133 | | Save Cancel| | 157 | | Save Cancel| |
134 | ____________________ | 158 | ____________________ |
135 | */ | 159 | */ |
136 | void OFileSelector::delItems() | 160 | void OFileSelector::delItems() |
137 | { | 161 | { |
138 | QLayoutIterator it = m_lay->iterator(); | 162 | QLayoutIterator it = m_lay->iterator(); |
139 | while ( it.current() != 0 ){ | 163 | while ( it.current() != 0 ){ |
140 | it.deleteCurrent(); | 164 | it.deleteCurrent(); |
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 ){ |
157 | m_checkPerm = new QCheckBox(tr("Set Permission"), this, "Permission" ); | 189 | m_checkPerm = new QCheckBox(tr("Set Permission"), this, "Permission" ); |
158 | m_checkPerm->setChecked( false ); | 190 | m_checkPerm->setChecked( false ); |
159 | m_lay->addWidget(m_checkPerm ); | 191 | m_lay->addWidget(m_checkPerm ); |
160 | } | 192 | } |
161 | 193 | ||
162 | if( m_shChooser ) | 194 | if( m_shChooser ) |
163 | initializeChooser(); | 195 | initializeChooser(); |
164 | 196 | ||
165 | if(m_shYesNo ) | 197 | if(m_shYesNo ) |
166 | initializeYes(); | 198 | initializeYes(); |
167 | 199 | ||
168 | 200 | ||
169 | }; | 201 | }; |
170 | 202 | ||
171 | void OFileSelector::setYesCancelVisible( bool show ) | 203 | void OFileSelector::setYesCancelVisible( bool show ) |
172 | { | 204 | { |
173 | if ( show == m_shYesNo ) | 205 | if ( show == m_shYesNo ) |
174 | return; | 206 | return; |
175 | m_shYesNo = show; | 207 | m_shYesNo = show; |
176 | if( !show ){ | 208 | if( !show ){ |
177 | delete m_ok; | 209 | delete m_ok; |
178 | delete m_cancel; | 210 | delete m_cancel; |
179 | m_ok = 0; | 211 | m_ok = 0; |
180 | m_cancel = 0; | 212 | m_cancel = 0; |
181 | // delete m_boxOk; all ready deleted in delItems | 213 | // delete m_boxOk; all ready deleted in delItems |
182 | } | 214 | } |
183 | updateLay(); // recreate it and save the other states | 215 | updateLay(); // recreate it and save the other states |
184 | } | 216 | } |
185 | 217 | ||
186 | void OFileSelector::setToolbarVisible( bool show ) | 218 | void OFileSelector::setToolbarVisible( bool show ) |
187 | { | 219 | { |
188 | if ( m_shTool == show ) | 220 | if ( m_shTool == show ) |
189 | return; | 221 | return; |
190 | /* if( show ){ | 222 | /* if( show ){ |
191 | 223 | ||
192 | }else { | 224 | }else { |
193 | 225 | ||
194 | }*/ | 226 | }*/ |
195 | } | 227 | } |
196 | 228 | ||
197 | void OFileSelector::setPermissionBarVisible( bool show ) | 229 | void OFileSelector::setPermissionBarVisible( bool show ) |
198 | { | 230 | { |
199 | if( show == m_shPerm ) | 231 | if( show == m_shPerm ) |
200 | return; | 232 | return; |
201 | 233 | ||
202 | m_shPerm = show; | 234 | m_shPerm = show; |
203 | 235 | ||
204 | updateLay(); | 236 | updateLay(); |
205 | } | 237 | } |
206 | void OFileSelector::setLineEditVisible( bool show ) | 238 | void OFileSelector::setLineEditVisible( bool show ) |
207 | { | 239 | { |
208 | if( show == m_shLne ) | 240 | if( show == m_shLne ) |
209 | return; | 241 | return; |
210 | 242 | ||
211 | m_shLne = show; | 243 | m_shLne = show; |
212 | if( !show ){ | 244 | if( !show ){ |
213 | delete m_edit; | 245 | delete m_edit; |
214 | delete m_fnLabel; | 246 | delete m_fnLabel; |
215 | m_edit = 0; | 247 | m_edit = 0; |
216 | m_fnLabel = 0; | 248 | m_fnLabel = 0; |
217 | //delete m_boxName; will be deleted | 249 | //delete m_boxName; will be deleted |
218 | } | 250 | } |
219 | updateLay(); | 251 | updateLay(); |
220 | } | 252 | } |
221 | void OFileSelector::setChooserVisible( bool show ) | 253 | void OFileSelector::setChooserVisible( bool show ) |
222 | { | 254 | { |
223 | if( show = m_shChooser ) | 255 | if( show = m_shChooser ) |
224 | return; | 256 | return; |
225 | m_shChooser = show; | 257 | m_shChooser = show; |
226 | if( !show ){ | 258 | if( !show ){ |
227 | delete m_mimeCheck; | 259 | delete m_mimeCheck; |
228 | delete m_viewCheck; | 260 | delete m_viewCheck; |
229 | m_mimeCheck = 0; | 261 | m_mimeCheck = 0; |
230 | m_viewCheck = 0; | 262 | m_viewCheck = 0; |
231 | } | 263 | } |
232 | updateLay(); | 264 | updateLay(); |
233 | } | 265 | } |
234 | QCheckBox* OFileSelector::permissionCheckbox( ) | 266 | QCheckBox* OFileSelector::permissionCheckbox( ) |
235 | { | 267 | { |
236 | return m_checkPerm; | 268 | return m_checkPerm; |
237 | } | 269 | } |
238 | void OFileSelector::setCaseSensetive( bool caSe ) | 270 | void OFileSelector::setCaseSensetive( bool caSe ) |
239 | { | 271 | { |
240 | m_case = caSe; | 272 | m_case = caSe; |
241 | reparse(); | 273 | reparse(); |
242 | } | 274 | } |
243 | void OFileSelector::setShowFiles(bool files ){ | 275 | void OFileSelector::setShowFiles(bool files ){ |
244 | m_files = files; | 276 | m_files = files; |
245 | reparse(); | 277 | reparse(); |
246 | } | 278 | } |
247 | void OFileSelector::setPopupMenu(const QPopupMenu * ) | 279 | void OFileSelector::setPopupMenu(const QPopupMenu * ) |
248 | { | 280 | { |
249 | //delete oldpopup; | 281 | //delete oldpopup; |
250 | 282 | ||
251 | } | 283 | } |
252 | bool OFileSelector::setPermission( ) const | 284 | bool OFileSelector::setPermission( ) const |
253 | { | 285 | { |
254 | if( m_checkPerm == 0 ) | 286 | if( m_checkPerm == 0 ) |
255 | return false; | 287 | return false; |
256 | else | 288 | else |
257 | return m_checkPerm->isChecked(); | 289 | return m_checkPerm->isChecked(); |
258 | } | 290 | } |
259 | void OFileSelector::setPermissionChecked( bool check ) | 291 | void OFileSelector::setPermissionChecked( bool check ) |
260 | { | 292 | { |
261 | if( m_checkPerm == 0 ) | 293 | if( m_checkPerm == 0 ) |
262 | return; | 294 | return; |
263 | m_checkPerm->setChecked( check ); | 295 | m_checkPerm->setChecked( check ); |
264 | } | 296 | } |
265 | QString OFileSelector::selectedName( )const | 297 | QString OFileSelector::selectedName( )const |
266 | { | 298 | { |
267 | QString string; | 299 | QString string; |
268 | if( m_selector == NORMAL ){ | 300 | if( m_selector == NORMAL ){ |
269 | const DocLnk *lnk = m_select->selected(); | 301 | const DocLnk *lnk = m_select->selected(); |
270 | string = lnk->file(); | 302 | string = lnk->file(); |
271 | }else if(m_selector == EXTENDED || m_selector == EXTENDED_ALL ) { | 303 | }else if(m_selector == EXTENDED || m_selector == EXTENDED_ALL ) { |
272 | QListViewItem *item = m_View->currentItem(); | 304 | QListViewItem *item = m_View->currentItem(); |
273 | if(item != 0 ){ | 305 | if(item != 0 ){ |
274 | string = item->text( 1 ); | 306 | string = item->text( 1 ); |
275 | } | 307 | } |
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 | } |
289 | void OFileSelector::updateLay() | 321 | void OFileSelector::updateLay() |
290 | { | 322 | { |
291 | /* if( m_shTool ) | 323 | /* if( m_shTool ) |
292 | // | 324 | // |
293 | else | 325 | else |
294 | // hide | 326 | // hide |
295 | */ | 327 | */ |
296 | // save the state | 328 | // save the state |
297 | bool check = false; | 329 | bool check = false; |
298 | if( m_checkPerm != 0 ) | 330 | if( m_checkPerm != 0 ) |
299 | check = m_checkPerm->isChecked(); | 331 | check = m_checkPerm->isChecked(); |
300 | QString text; | 332 | QString text; |
301 | 333 | ||
302 | if( m_edit != 0 ) | 334 | if( m_edit != 0 ) |
303 | text = m_edit->text(); | 335 | text = m_edit->text(); |
304 | // save current mimetype | 336 | // save current mimetype |
305 | 337 | ||
306 | delItems(); | 338 | delItems(); |
307 | delete m_checkPerm; | 339 | delete m_checkPerm; |
308 | delete m_edit; | 340 | delete m_edit; |
309 | delete m_fnLabel; | 341 | delete m_fnLabel; |
310 | delete m_ok; | 342 | delete m_ok; |
311 | delete m_cancel; | 343 | delete m_cancel; |
312 | delete m_mimeCheck; | 344 | delete m_mimeCheck; |
313 | delete m_viewCheck; | 345 | delete m_viewCheck; |
314 | delete m_select; // test | 346 | delete m_select; // test |
315 | delete m_stack; | 347 | delete m_stack; |
316 | //delete m_list; | 348 | //delete m_list; |
317 | init(); | 349 | init(); |
318 | if( m_shLne ) | 350 | if( m_shLne ) |
319 | m_edit->setText(text ); | 351 | m_edit->setText(text ); |
320 | if( m_shPerm ) | 352 | if( m_shPerm ) |
321 | m_checkPerm->setChecked(check ); | 353 | m_checkPerm->setChecked(check ); |
322 | } | 354 | } |
323 | // let's update the mimetypes. Use the current mimefilter for the 2nd QDir retrieve | 355 | // let's update the mimetypes. Use the current mimefilter for the 2nd QDir retrieve |
324 | // insert QListViewItems with the right options | 356 | // insert QListViewItems with the right options |
325 | bool OFileSelector::compliesMime(const QString &path, const QString &mime ) | 357 | bool OFileSelector::compliesMime(const QString &path, const QString &mime ) |
326 | { | 358 | { |
327 | if( mime == "All" ) | 359 | if( mime == "All" ) |
328 | return true; | 360 | return true; |
329 | MimeType type( path ); | 361 | MimeType type( path ); |
330 | if( type.id() == mime ) | 362 | if( type.id() == mime ) |
331 | return true; | 363 | return true; |
332 | return false; | 364 | return false; |
333 | } | 365 | } |
334 | 366 | ||
335 | void OFileSelector::reparse() | 367 | void OFileSelector::reparse() |
336 | { | 368 | { |
337 | if(m_View== 0 || m_selector == NORMAL) | 369 | if(m_View== 0 || m_selector == NORMAL) |
338 | return; | 370 | return; |
339 | 371 | ||
340 | m_View->clear(); | 372 | m_View->clear(); |
341 | 373 | ||
342 | 374 | ||
343 | QString currMime =m_mimeCheck->currentText(); | 375 | QString currMime =m_mimeCheck->currentText(); |
344 | // update the mimetype now | 376 | // update the mimetype now |
345 | if( m_autoMime ) { | 377 | if( m_autoMime ) { |
346 | QDir dir( m_currentDir ); | 378 | QDir dir( m_currentDir ); |
347 | m_mimetypes.clear(); | 379 | m_mimetypes.clear(); |
348 | m_mimeCheck->clear(); | 380 | m_mimeCheck->clear(); |
349 | dir.setFilter( QDir::Files | QDir::Readable ); | 381 | dir.setFilter( QDir::Files | QDir::Readable ); |
350 | dir.setSorting(QDir::Size ); | 382 | dir.setSorting(QDir::Size ); |
351 | const QFileInfoList *list = dir.entryInfoList(); | 383 | const QFileInfoList *list = dir.entryInfoList(); |
352 | QFileInfoListIterator it( *list ); | 384 | QFileInfoListIterator it( *list ); |
353 | QFileInfo *fi; | 385 | QFileInfo *fi; |
354 | while( (fi=it.current()) ){ | 386 | while( (fi=it.current()) ){ |
355 | if(fi->extension() == QString::fromLatin1("desktop") ){ | 387 | if(fi->extension() == QString::fromLatin1("desktop") ){ |
356 | ++it; | 388 | ++it; |
357 | continue; | 389 | continue; |
358 | } | 390 | } |
359 | MimeType type(fi->filePath() ); | 391 | MimeType type(fi->filePath() ); |
360 | if( !m_mimetypes.contains( type.id() ) ) | 392 | if( !m_mimetypes.contains( type.id() ) ) |
361 | m_mimetypes.append( type.id() ); | 393 | m_mimetypes.append( type.id() ); |
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 ); |
374 | QFileInfo *fi; | 407 | QFileInfo *fi; |
375 | while( (fi=it.current()) ){ | 408 | while( (fi=it.current()) ){ |
376 | if(fi->fileName() == ".." || fi->fileName() == "." ){ | 409 | if(fi->fileName() == ".." || fi->fileName() == "." ){ |
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" ); |
393 | addDir(currMime, fi, TRUE ); | 426 | addDir(currMime, fi, TRUE ); |
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 | } |
407 | }else if( fi->isDir() ){ | 440 | }else if( fi->isDir() ){ |
408 | addDir(currMime, fi ); | 441 | addDir(currMime, fi ); |
409 | }else if( fi->isFile() ) { // file ? | 442 | }else if( fi->isFile() ) { // file ? |
410 | addFile(currMime, fi ); | 443 | addFile(currMime, fi ); |
411 | } | 444 | } |
412 | ++it; | 445 | ++it; |
413 | } | 446 | } |
414 | m_View->sort(); | 447 | m_View->sort(); |
415 | } | 448 | } |
416 | QString OFileSelector::directory()const | 449 | QString OFileSelector::directory()const |
417 | { | 450 | { |
418 | return m_currentDir; | 451 | return m_currentDir; |
419 | } | 452 | } |
420 | int OFileSelector::fileCount() | 453 | int OFileSelector::fileCount() |
421 | { | 454 | { |
422 | return 0; | 455 | return 0; |
423 | } | 456 | } |
424 | void OFileSelector::slotOk( ) | 457 | void OFileSelector::slotOk( ) |
425 | { | 458 | { |
426 | emit ok(); | 459 | emit ok(); |
427 | } | 460 | } |
428 | void OFileSelector::slotCancel( ) | 461 | void OFileSelector::slotCancel( ) |
429 | { | 462 | { |
430 | emit cancel(); | 463 | emit cancel(); |
431 | } | 464 | } |
432 | 465 | ||
433 | void OFileSelector::initializeName() | 466 | void OFileSelector::initializeName() |
434 | { | 467 | { |
435 | m_boxName = new QHBoxLayout(this ); | 468 | m_boxName = new QHBoxLayout(this ); |
436 | m_edit = new QLineEdit(this ); | 469 | m_edit = new QLineEdit(this ); |
437 | m_fnLabel = new QLabel(this ); | 470 | m_fnLabel = new QLabel(this ); |
438 | m_fnLabel->setText(tr("Name:") ); | 471 | m_fnLabel->setText(tr("Name:") ); |
439 | m_boxName->addWidget(m_fnLabel ); | 472 | m_boxName->addWidget(m_fnLabel ); |
440 | m_boxName->insertSpacing(1, 8 ); | 473 | m_boxName->insertSpacing(1, 8 ); |
441 | m_boxName->addWidget(m_edit, 100 ); | 474 | m_boxName->addWidget(m_edit, 100 ); |
442 | 475 | ||
443 | m_lay->addLayout(m_boxName); | 476 | m_lay->addLayout(m_boxName); |
444 | } | 477 | } |
445 | void OFileSelector::initializeYes() | 478 | void OFileSelector::initializeYes() |
446 | { | 479 | { |
447 | m_ok = new QPushButton("&Save", this, "save" ); | 480 | m_ok = new QPushButton("&Save", this, "save" ); |
448 | m_cancel = new QPushButton("C&ancel", this, "cancel" ); | 481 | m_cancel = new QPushButton("C&ancel", this, "cancel" ); |
449 | m_boxOk = new QHBoxLayout(this ); | 482 | m_boxOk = new QHBoxLayout(this ); |
450 | m_boxOk->addWidget( m_ok, Qt::AlignHCenter ); | 483 | m_boxOk->addWidget( m_ok, Qt::AlignHCenter ); |
451 | m_boxOk->insertSpacing(1, 8 ); | 484 | m_boxOk->insertSpacing(1, 8 ); |
452 | m_boxOk->addWidget( m_cancel, Qt::AlignHCenter); | 485 | m_boxOk->addWidget( m_cancel, Qt::AlignHCenter); |
453 | m_lay->addLayout(m_boxOk ); | 486 | m_lay->addLayout(m_boxOk ); |
454 | connect(m_ok, SIGNAL(clicked() ), | 487 | connect(m_ok, SIGNAL(clicked() ), |
455 | this, SLOT(slotOk() ) ); | 488 | this, SLOT(slotOk() ) ); |
456 | connect(m_cancel, SIGNAL(clicked() ), | 489 | connect(m_cancel, SIGNAL(clicked() ), |
457 | this, SLOT(slotCancel() ) ); | 490 | this, SLOT(slotCancel() ) ); |
458 | 491 | ||
459 | } | 492 | } |
460 | void OFileSelector::initializeChooser() | 493 | void OFileSelector::initializeChooser() |
461 | { | 494 | { |
462 | m_boxView = new QHBoxLayout(this ); | 495 | m_boxView = new QHBoxLayout(this ); |
463 | 496 | ||
464 | m_mimeCheck = new QComboBox(this, "mime check"); | 497 | m_mimeCheck = new QComboBox(this, "mime check"); |
465 | m_viewCheck = new QComboBox(this, "view check"); | 498 | m_viewCheck = new QComboBox(this, "view check"); |
466 | m_boxView->addWidget(m_viewCheck, 0 ); | 499 | m_boxView->addWidget(m_viewCheck, 0 ); |
467 | m_boxView->insertSpacing(1, 8 ); | 500 | m_boxView->insertSpacing(1, 8 ); |
468 | m_boxView->addWidget(m_mimeCheck, 0 ); | 501 | m_boxView->addWidget(m_mimeCheck, 0 ); |
469 | m_lay->addLayout(m_boxView ); | 502 | m_lay->addLayout(m_boxView ); |
470 | 503 | ||
471 | m_viewCheck->insertItem(tr("Documents") ); | 504 | m_viewCheck->insertItem(tr("Documents") ); |
472 | m_viewCheck->insertItem(tr("Files") ); | 505 | m_viewCheck->insertItem(tr("Files") ); |
473 | m_viewCheck->insertItem(tr("All Files") ); | 506 | m_viewCheck->insertItem(tr("All Files") ); |
474 | 507 | ||
475 | if(!m_autoMime ) | 508 | if(!m_autoMime ) |
476 | m_mimeCheck->insertItem(m_mimetypes.join("," ) ); | 509 | m_mimeCheck->insertItem(m_mimetypes.join("," ) ); |
477 | else{ // check | 510 | else{ // check |
478 | updateMimes(); | 511 | updateMimes(); |
479 | m_mimeCheck->insertStringList( m_mimetypes ); | 512 | m_mimeCheck->insertStringList( m_mimetypes ); |
480 | } | 513 | } |
481 | 514 | ||
482 | connect( m_viewCheck, SIGNAL(activated(const QString &) ), | 515 | connect( m_viewCheck, SIGNAL(activated(const QString &) ), |
483 | this, SLOT(slotViewCheck(const QString & ) ) ); | 516 | this, SLOT(slotViewCheck(const QString & ) ) ); |
484 | 517 | ||
485 | connect( m_mimeCheck, SIGNAL(activated(const QString &) ), | 518 | connect( m_mimeCheck, SIGNAL(activated(const QString &) ), |
486 | this, SLOT(slotMimeCheck(const QString & ) ) ); | 519 | this, SLOT(slotMimeCheck(const QString & ) ) ); |
487 | } | 520 | } |
488 | void OFileSelector::slotMimeCheck(const QString &view ){ | 521 | void OFileSelector::slotMimeCheck(const QString &view ){ |
489 | if(m_selector == NORMAL ){ | 522 | if(m_selector == NORMAL ){ |
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 |
504 | QString currMime = m_mimeCheck->currentText(); | 536 | QString currMime = m_mimeCheck->currentText(); |
505 | if( view == QString::fromLatin1("Documents") ){ | 537 | if( view == QString::fromLatin1("Documents") ){ |
506 | // get the mimetype now | 538 | // get the mimetype now |
507 | // check if we're the current widget and return | 539 | // check if we're the current widget and return |
508 | if( m_View != 0) // delete 0 shouldn't crash but it did :( | 540 | if( m_View != 0) // delete 0 shouldn't crash but it did :( |
509 | delete m_View; | 541 | delete m_View; |
510 | m_View = 0; | 542 | m_View = 0; |
511 | delete m_select; | 543 | delete m_select; |
512 | m_select = new FileSelector( currMime == "All" ? QString::null : currMime, | 544 | m_select = new FileSelector( currMime == "All" ? QString::null : currMime, |
513 | m_stack,"fileselector", FALSE, FALSE ); | 545 | m_stack,"fileselector", FALSE, FALSE ); |
514 | m_stack->addWidget( m_select, NORMAL ); | 546 | m_stack->addWidget( m_select, NORMAL ); |
515 | m_mimeCheck->clear(); | 547 | m_mimeCheck->clear(); |
516 | m_selector = NORMAL; | 548 | m_selector = NORMAL; |
517 | updateMimes(); | 549 | updateMimes(); |
518 | m_mimeCheck->insertStringList( m_mimetypes ); | 550 | m_mimeCheck->insertStringList( m_mimetypes ); |
519 | m_stack->raiseWidget( NORMAL ); | 551 | m_stack->raiseWidget( NORMAL ); |
520 | 552 | ||
521 | 553 | ||
522 | }else if(view == QString::fromLatin1("Files") ){ | 554 | }else if(view == QString::fromLatin1("Files") ){ |
523 | // remove from the stack | 555 | // remove from the stack |
524 | delete m_select; | 556 | delete m_select; |
525 | m_select = 0; | 557 | m_select = 0; |
526 | delete m_View; | 558 | delete m_View; |
527 | m_View = 0; | 559 | m_View = 0; |
528 | m_selector = EXTENDED; | 560 | m_selector = EXTENDED; |
529 | // create the ListView or IconView | 561 | // create the ListView or IconView |
530 | initializeListView(); | 562 | initializeListView(); |
531 | 563 | ||
532 | reparse(); | 564 | reparse(); |
533 | }else if(view == QString::fromLatin1("All Files") ) { | 565 | }else if(view == QString::fromLatin1("All Files") ) { |
534 | // remove from the stack | 566 | // remove from the stack |
535 | delete m_select; | 567 | delete m_select; |
536 | m_select = 0; | 568 | m_select = 0; |
537 | delete m_View; | 569 | delete m_View; |
538 | m_View = 0; | 570 | m_View = 0; |
539 | m_selector = EXTENDED_ALL; | 571 | m_selector = EXTENDED_ALL; |
540 | initializeListView(); | 572 | initializeListView(); |
541 | reparse(); | 573 | reparse(); |
542 | }; | 574 | }; |
543 | }; | 575 | }; |
544 | 576 | ||
545 | 577 | ||
546 | void OFileSelector::updateMimes() // lets check which mode is active | 578 | void OFileSelector::updateMimes() // lets check which mode is active |
547 | // check the current dir for items then | 579 | // check the current dir for items then |
548 | { | 580 | { |
549 | m_mimetypes.clear(); | 581 | m_mimetypes.clear(); |
550 | m_mimetypes.append("All" ); | 582 | m_mimetypes.append("All" ); |
551 | if( m_selector == NORMAL ){ | 583 | if( m_selector == NORMAL ){ |
552 | DocLnkSet set; | 584 | DocLnkSet set; |
553 | Global::findDocuments(&set, QString::null ); | 585 | Global::findDocuments(&set, QString::null ); |
554 | QListIterator<DocLnk> dit( set.children() ); | 586 | QListIterator<DocLnk> dit( set.children() ); |
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 ); |
568 | m_stack->raiseWidget( EXTENDED ); | 600 | m_stack->raiseWidget( EXTENDED ); |
569 | QPEApplication::setStylusOperation( m_View->viewport(),QPEApplication::RightOnHold); | 601 | QPEApplication::setStylusOperation( m_View->viewport(),QPEApplication::RightOnHold); |
570 | // set up the stuff | 602 | // set up the stuff |
571 | // Pixmap Name Date Size mime | 603 | // Pixmap Name Date Size mime |
572 | //(m_View->header() )->hide(); | 604 | //(m_View->header() )->hide(); |
573 | //m_View->setRootIsDecorated(false); | 605 | //m_View->setRootIsDecorated(false); |
574 | m_View->addColumn(" "); | 606 | m_View->addColumn(" "); |
575 | m_View->addColumn(tr("Name") ); | 607 | m_View->addColumn(tr("Name") ); |
576 | m_View->addColumn(tr("Size") ); | 608 | m_View->addColumn(tr("Size") ); |
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; |
633 | reparse(); | 705 | reparse(); |
634 | } | 706 | } |
635 | 707 | ||
636 | 708 | ||
637 | 709 | ||
diff --git a/libopie/ofileselector.h b/libopie/ofileselector.h index 73674e2..6936773 100644 --- a/libopie/ofileselector.h +++ b/libopie/ofileselector.h | |||
@@ -1,244 +1,249 @@ | |||
1 | /* | 1 | /* |
2 | This is based on code and idea of | 2 | This is based on code and idea of |
3 | L. J. Potter ljp@llornkcor.com | 3 | L. J. Potter ljp@llornkcor.com |
4 | Thanks a lot | 4 | Thanks a lot |
5 | 5 | ||
6 | 6 | ||
7 | =. This file is part of the OPIE Project | 7 | =. This file is part of the OPIE Project |
8 | .=l. Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> | 8 | .=l. Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> |
9 | .>+-= | 9 | .>+-= |
10 | _;:, .> :=|. This library is free software; you can | 10 | _;:, .> :=|. This library is free software; you can |
11 | .> <`_, > . <= redistribute it and/or modify it under | 11 | .> <`_, > . <= redistribute it and/or modify it under |
12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
13 | .="- .-=="i, .._ License as published by the Free Software | 13 | .="- .-=="i, .._ License as published by the Free Software |
14 | - . .-<_> .<> Foundation; either version 2 of the License, | 14 | - . .-<_> .<> Foundation; either version 2 of the License, |
15 | ._= =} : or (at your option) any later version. | 15 | ._= =} : or (at your option) any later version. |
16 | .%`+i> _;_. | 16 | .%`+i> _;_. |
17 | .i_,=:_. -<s. This library is distributed in the hope that | 17 | .i_,=:_. -<s. This library is distributed in the hope that |
18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
19 | : .. .:, . . . without even the implied warranty of | 19 | : .. .:, . . . without even the implied warranty of |
20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
22 | ..}^=.= = ; Library General Public License for more | 22 | ..}^=.= = ; Library General Public License for more |
23 | ++= -. .` .: details. | 23 | ++= -. .` .: details. |
24 | : = ...= . :.=- | 24 | : = ...= . :.=- |
25 | -. .:....=;==+<; You should have received a copy of the GNU | 25 | -. .:....=;==+<; You should have received a copy of the GNU |
26 | -_. . . )=. = Library General Public License along with | 26 | -_. . . )=. = Library General Public License along with |
27 | -- :-=` this library; see the file COPYING.LIB. | 27 | -- :-=` this library; see the file COPYING.LIB. |
28 | If not, write to the Free Software Foundation, | 28 | If not, write to the Free Software Foundation, |
29 | Inc., 59 Temple Place - Suite 330, | 29 | Inc., 59 Temple Place - Suite 330, |
30 | Boston, MA 02111-1307, USA. | 30 | Boston, MA 02111-1307, USA. |
31 | 31 | ||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #ifndef opiefileselector_h | 34 | #ifndef opiefileselector_h |
35 | #define opiefileselector_h | 35 | #define opiefileselector_h |
36 | 36 | ||
37 | #include <qwidget.h> | 37 | #include <qwidget.h> |
38 | #include <qstring.h> | 38 | #include <qstring.h> |
39 | #include <qpixmap.h> | 39 | #include <qpixmap.h> |
40 | #include <qstringlist.h> | 40 | #include <qstringlist.h> |
41 | #include <qmap.h> | 41 | #include <qmap.h> |
42 | #include <qvaluelist.h> | 42 | #include <qvaluelist.h> |
43 | 43 | ||
44 | #include <qpe/applnk.h> | 44 | #include <qpe/applnk.h> |
45 | #include <qlistview.h> | 45 | #include <qlistview.h> |
46 | /** This is OPIEs FileDialog Widget. You can use it | 46 | /** This is OPIEs FileDialog Widget. You can use it |
47 | * as a dropin replacement of the fileselector and | 47 | * as a dropin replacement of the fileselector and |
48 | * or use any of the new features. | 48 | * or use any of the new features. |
49 | * This is also a complete FileSave and FileLoad widget | 49 | * This is also a complete FileSave and FileLoad widget |
50 | * If you look for a Dialog check OFileDialog | 50 | * If you look for a Dialog check OFileDialog |
51 | * | 51 | * |
52 | */ | 52 | */ |
53 | class DocLnk; | 53 | class DocLnk; |
54 | class QCheckBox; | 54 | class QCheckBox; |
55 | class QComboBox; | 55 | class QComboBox; |
56 | class QPushButton; | 56 | class QPushButton; |
57 | class FileSelector; | 57 | class FileSelector; |
58 | class QGridLayout; | 58 | class QGridLayout; |
59 | class QLineEdit; | 59 | class QLineEdit; |
60 | class QLabel; | 60 | class QLabel; |
61 | class QWidgetStack; | 61 | class QWidgetStack; |
62 | class QHBoxLayout; | 62 | class QHBoxLayout; |
63 | class QVBoxLayout; | 63 | class QVBoxLayout; |
64 | class QPopupMenu; | 64 | 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; |
85 | } | 89 | } |
86 | QString path()const{ | 90 | QString path()const{ |
87 | return text(1 ); | 91 | return text(1 ); |
88 | } | 92 | } |
89 | QString key(int id, bool )const { | 93 | QString key(int id, bool )const { |
90 | QString ke; | 94 | QString ke; |
91 | if( id == 0 || id == 1 ){ // name | 95 | if( id == 0 || id == 1 ){ // name |
92 | if( dir ){ | 96 | if( dir ){ |
93 | ke.append("0" ); | 97 | ke.append("0" ); |
94 | ke.append( text(1) ); | 98 | ke.append( text(1) ); |
95 | }else{ | 99 | }else{ |
96 | ke.append("1" ); | 100 | ke.append("1" ); |
97 | ke.append( text(1) ); | 101 | ke.append( text(1) ); |
98 | } | 102 | } |
99 | }else if( id == 2 ){ // size | 103 | }else if( id == 2 ){ // size |
100 | return text(2); | 104 | return text(2); |
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 |
113 | public: | 118 | public: |
114 | enum Mode {OPEN=1, SAVE, FILESELECTOR }; | 119 | enum Mode {OPEN=1, SAVE, FILESELECTOR }; |
115 | enum Selector{NORMAL=1, EXTENDED = 2, EXTENDED_ALL =4 }; | 120 | enum Selector{NORMAL=1, EXTENDED = 2, EXTENDED_ALL =4 }; |
116 | enum View { DIRS = 1, FILES = 2, TREE = 4, ICON = 8 }; | 121 | enum View { DIRS = 1, FILES = 2, TREE = 4, ICON = 8 }; |
117 | OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName, const QString &fileName = QString::null, const QStringList mimetypes = QStringList() ); | 122 | OFileSelector(QWidget *wid, int mode, int selector, const QString &dirName, const QString &fileName = QString::null, const QStringList mimetypes = QStringList() ); |
118 | 123 | ||
119 | bool isToolbarVisible() const { return m_shTool; }; | 124 | bool isToolbarVisible() const { return m_shTool; }; |
120 | bool isPermissionBarVisible() const { return m_shPerm; }; | 125 | bool isPermissionBarVisible() const { return m_shPerm; }; |
121 | bool isLineEditVisible()const { return m_shLne; }; | 126 | bool isLineEditVisible()const { return m_shLne; }; |
122 | bool isChooserVisible( )const { return m_shChooser; }; | 127 | bool isChooserVisible( )const { return m_shChooser; }; |
123 | bool isYesCancelVisible()const { return m_shYesNo; }; | 128 | bool isYesCancelVisible()const { return m_shYesNo; }; |
124 | void setYesCancelVisible( bool show ); | 129 | void setYesCancelVisible( bool show ); |
125 | void setToolbarVisible( bool show ); | 130 | void setToolbarVisible( bool show ); |
126 | void setPermissionBarVisible( bool show ); | 131 | void setPermissionBarVisible( bool show ); |
127 | void setLineEditVisible(bool show) ; | 132 | void setLineEditVisible(bool show) ; |
128 | void setChooserVisible( bool chooser ); | 133 | void setChooserVisible( bool chooser ); |
129 | 134 | ||
130 | QCheckBox* permissionCheckbox(); | 135 | QCheckBox* permissionCheckbox(); |
131 | bool setPermission() const; | 136 | bool setPermission() const; |
132 | void setPermissionChecked( bool check ); | 137 | void setPermissionChecked( bool check ); |
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 ); |
146 | 151 | ||
147 | 152 | ||
148 | 153 | ||
149 | int mode()const { return m_mode; }; | 154 | int mode()const { return m_mode; }; |
150 | int selector()const { return m_selector; }; | 155 | int selector()const { return m_selector; }; |
151 | void setSelector( int ); | 156 | void setSelector( int ); |
152 | 157 | ||
153 | 158 | ||
154 | void setPopupMenu( const QPopupMenu * ); | 159 | void setPopupMenu( const QPopupMenu * ); |
155 | 160 | ||
156 | void updateLay(); | 161 | void updateLay(); |
157 | 162 | ||
158 | void reparse(); // re reads the dir | 163 | void reparse(); // re reads the dir |
159 | 164 | ||
160 | QString selectedName( )const; | 165 | QString selectedName( )const; |
161 | QStringList selectedNames()const; | 166 | QStringList selectedNames()const; |
162 | 167 | ||
163 | QString selectedPath() const; | 168 | QString selectedPath() const; |
164 | QStringList selectedPaths() const; | 169 | QStringList selectedPaths() const; |
165 | 170 | ||
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(); |
179 | void cancel(); | 184 | void cancel(); |
180 | 185 | ||
181 | protected slots: | 186 | protected slots: |
182 | void slotOk(); | 187 | void slotOk(); |
183 | void slotCancel(); | 188 | void slotCancel(); |
184 | void slotViewCheck(const QString & ); | 189 | void slotViewCheck(const QString & ); |
185 | void slotMimeCheck(const QString & ); | 190 | void slotMimeCheck(const QString & ); |
186 | protected: | 191 | protected: |
187 | void init(); | 192 | void init(); |
188 | void updateMimes(); | 193 | void updateMimes(); |
189 | int m_mode, m_selector; | 194 | int m_mode, m_selector; |
190 | QComboBox *m_location, *m_mimeCheck, *m_viewCheck; | 195 | QComboBox *m_location, *m_mimeCheck, *m_viewCheck; |
191 | QPushButton *m_homeButton, *m_docButton, *m_hideButton, *m_ok, *m_cancel; | 196 | QPushButton *m_homeButton, *m_docButton, *m_hideButton, *m_ok, *m_cancel; |
192 | QPushButton *m_reread, *m_up; | 197 | QPushButton *m_reread, *m_up; |
193 | QListView *m_View; | 198 | QListView *m_View; |
194 | QCheckBox *m_checkPerm; | 199 | QCheckBox *m_checkPerm; |
195 | 200 | ||
196 | QString m_currentDir; | 201 | QString m_currentDir; |
197 | QString m_name; | 202 | QString m_name; |
198 | QStringList m_mimetypes; | 203 | QStringList m_mimetypes; |
199 | 204 | ||
200 | FileSelector *m_select; | 205 | FileSelector *m_select; |
201 | QWidgetStack *m_stack; | 206 | QWidgetStack *m_stack; |
202 | QVBoxLayout *m_lay; | 207 | QVBoxLayout *m_lay; |
203 | QGridLayout *m_Oselector; | 208 | QGridLayout *m_Oselector; |
204 | 209 | ||
205 | QHBoxLayout *m_boxToolbar; | 210 | QHBoxLayout *m_boxToolbar; |
206 | QHBoxLayout *m_boxOk; | 211 | QHBoxLayout *m_boxOk; |
207 | QHBoxLayout *m_boxName; | 212 | QHBoxLayout *m_boxName; |
208 | QHBoxLayout *m_boxView; | 213 | QHBoxLayout *m_boxView; |
209 | 214 | ||
210 | QLineEdit *m_edit; | 215 | QLineEdit *m_edit; |
211 | QLabel *m_fnLabel; | 216 | QLabel *m_fnLabel; |
212 | bool m_shTool:1; | 217 | bool m_shTool:1; |
213 | bool m_shPerm:1; | 218 | bool m_shPerm:1; |
214 | bool m_shLne:1; | 219 | bool m_shLne:1; |
215 | bool m_shChooser:1; | 220 | bool m_shChooser:1; |
216 | bool m_shYesNo:1; | 221 | bool m_shYesNo:1; |
217 | bool m_boCheckPerm:1; | 222 | bool m_boCheckPerm:1; |
218 | bool m_autoMime:1; | 223 | bool m_autoMime:1; |
219 | bool m_case:1; | 224 | bool m_case:1; |
220 | bool m_dir:1; | 225 | bool m_dir:1; |
221 | bool m_files:1; | 226 | bool m_files:1; |
222 | 227 | ||
223 | protected: | 228 | protected: |
224 | 229 | ||
225 | private: | 230 | private: |
226 | // implementation todo | 231 | // implementation todo |
227 | virtual void addFile(const QString &mime, QFileInfo *info, bool symlink = FALSE ); | 232 | virtual void addFile(const QString &mime, QFileInfo *info, bool symlink = FALSE ); |
228 | virtual void addDir( const QString &mime, QFileInfo *info , bool symlink = FALSE ); | 233 | virtual void addDir( const QString &mime, QFileInfo *info , bool symlink = FALSE ); |
229 | virtual void addSymlink(const QString &mime, QFileInfo *info, bool broken = FALSE ){}; | 234 | virtual void addSymlink(const QString &mime, QFileInfo *info, bool broken = FALSE ){}; |
230 | void delItems(); | 235 | void delItems(); |
231 | void initializeName(); | 236 | void initializeName(); |
232 | void initializeYes(); | 237 | void initializeYes(); |
233 | void initializeChooser(); | 238 | void initializeChooser(); |
234 | void initializeListView(); | 239 | void initializeListView(); |
235 | void initPics(); | 240 | void initPics(); |
236 | bool compliesMime(const QString &path, const QString &mime); | 241 | bool compliesMime(const QString &path, const QString &mime); |
237 | 242 | ||
238 | class OFileSelectorPrivate; | 243 | class OFileSelectorPrivate; |
239 | OFileSelectorPrivate *d; | 244 | OFileSelectorPrivate *d; |
240 | static QMap<QString,QPixmap> *m_pixmaps; | 245 | static QMap<QString,QPixmap> *m_pixmaps; |
241 | }; | 246 | }; |
242 | 247 | ||
243 | 248 | ||
244 | #endif | 249 | #endif |