author | zautrix <zautrix> | 2005-06-18 18:03:50 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-06-18 18:03:50 (UTC) |
commit | 3d86c369e8b48b340e4093b034f1347defea876b (patch) (unidiff) | |
tree | 50becb886d75770ce35108f4f97837b6b9d5664f /microkde | |
parent | 45c93de5a458e7ca0c293eebe504a9d949cc045c (diff) | |
download | kdepimpi-3d86c369e8b48b340e4093b034f1347defea876b.zip kdepimpi-3d86c369e8b48b340e4093b034f1347defea876b.tar.gz kdepimpi-3d86c369e8b48b340e4093b034f1347defea876b.tar.bz2 |
file dialog fixes
-rw-r--r-- | microkde/ofileselector_p.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/microkde/ofileselector_p.cpp b/microkde/ofileselector_p.cpp index e2af32b..488dee2 100644 --- a/microkde/ofileselector_p.cpp +++ b/microkde/ofileselector_p.cpp | |||
@@ -1,488 +1,489 @@ | |||
1 | #include <qcombobox.h> | 1 | #include <qcombobox.h> |
2 | #include <qdir.h> | 2 | #include <qdir.h> |
3 | #include <qhbox.h> | 3 | #include <qhbox.h> |
4 | #include <qheader.h> | 4 | #include <qheader.h> |
5 | #include <qlabel.h> | 5 | #include <qlabel.h> |
6 | #include <qlayout.h> | 6 | #include <qlayout.h> |
7 | #include <qlineedit.h> | 7 | #include <qlineedit.h> |
8 | #include <qlistview.h> | 8 | #include <qlistview.h> |
9 | #include <qpopupmenu.h> | 9 | #include <qpopupmenu.h> |
10 | #include <qwidgetstack.h> | 10 | #include <qwidgetstack.h> |
11 | #include <qregexp.h> | 11 | #include <qregexp.h> |
12 | #include <qobjectlist.h> | 12 | #include <qobjectlist.h> |
13 | 13 | ||
14 | /* hacky but we need to get FileSelector::filter */ | 14 | /* hacky but we need to get FileSelector::filter */ |
15 | #define private public | 15 | #define private public |
16 | #include <qpe/fileselector.h> | 16 | #include <qpe/fileselector.h> |
17 | #undef private | 17 | #undef private |
18 | 18 | ||
19 | #include <qpe/qpeapplication.h> | 19 | #include <qpe/qpeapplication.h> |
20 | #include <qpe/mimetype.h> | 20 | #include <qpe/mimetype.h> |
21 | #include <qpe/resource.h> | 21 | #include <qpe/resource.h> |
22 | #include <qpe/storage.h> | 22 | #include <qpe/storage.h> |
23 | #include <kglobal.h> | 23 | #include <kglobal.h> |
24 | #include <klocale.h> | 24 | #include <klocale.h> |
25 | 25 | ||
26 | #include "ofileselector_p.h" | 26 | #include "ofileselector_p.h" |
27 | //US#include "ofileselector.h" | 27 | //US#include "ofileselector.h" |
28 | 28 | ||
29 | #include "klocale.h" | 29 | #include "klocale.h" |
30 | 30 | ||
31 | OFileViewInterface::OFileViewInterface( OFileSelector* selector ) | 31 | OFileViewInterface::OFileViewInterface( OFileSelector* selector ) |
32 | : m_selector( selector ) { | 32 | : m_selector( selector ) { |
33 | } | 33 | } |
34 | OFileViewInterface::~OFileViewInterface() { | 34 | OFileViewInterface::~OFileViewInterface() { |
35 | } | 35 | } |
36 | QString OFileViewInterface::name()const{ | 36 | QString OFileViewInterface::name()const{ |
37 | return m_name; | 37 | return m_name; |
38 | } | 38 | } |
39 | void OFileViewInterface::setName( const QString& name ) { | 39 | void OFileViewInterface::setName( const QString& name ) { |
40 | m_name = name; | 40 | m_name = name; |
41 | } | 41 | } |
42 | OFileSelector* OFileViewInterface::selector()const { | 42 | OFileSelector* OFileViewInterface::selector()const { |
43 | return m_selector; | 43 | return m_selector; |
44 | } | 44 | } |
45 | 45 | ||
46 | DocLnk OFileViewInterface::selectedDocument()const { | 46 | DocLnk OFileViewInterface::selectedDocument()const { |
47 | return DocLnk( selectedName() ); | 47 | return DocLnk( selectedName() ); |
48 | } | 48 | } |
49 | 49 | ||
50 | bool OFileViewInterface::showNew()const { | 50 | bool OFileViewInterface::showNew()const { |
51 | return selector()->showNew(); | 51 | return selector()->showNew(); |
52 | } | 52 | } |
53 | bool OFileViewInterface::showClose()const { | 53 | bool OFileViewInterface::showClose()const { |
54 | return selector()->showClose(); | 54 | return selector()->showClose(); |
55 | } | 55 | } |
56 | MimeTypes OFileViewInterface::mimeTypes()const { | 56 | MimeTypes OFileViewInterface::mimeTypes()const { |
57 | return selector()->mimeTypes(); | 57 | return selector()->mimeTypes(); |
58 | } | 58 | } |
59 | QStringList OFileViewInterface::currentMimeType()const { | 59 | QStringList OFileViewInterface::currentMimeType()const { |
60 | return selector()->currentMimeType(); | 60 | return selector()->currentMimeType(); |
61 | } | 61 | } |
62 | void OFileViewInterface::activate( const QString& ) { | 62 | void OFileViewInterface::activate( const QString& ) { |
63 | // not implemented here | 63 | // not implemented here |
64 | } | 64 | } |
65 | void OFileViewInterface::ok() { | 65 | void OFileViewInterface::ok() { |
66 | emit selector()->ok(); | 66 | emit selector()->ok(); |
67 | } | 67 | } |
68 | void OFileViewInterface::cancel() { | 68 | void OFileViewInterface::cancel() { |
69 | emit selector()->cancel(); | 69 | emit selector()->cancel(); |
70 | } | 70 | } |
71 | void OFileViewInterface::closeMe() { | 71 | void OFileViewInterface::closeMe() { |
72 | emit selector()->closeMe(); | 72 | emit selector()->closeMe(); |
73 | } | 73 | } |
74 | void OFileViewInterface::fileSelected( const QString& str) { | 74 | void OFileViewInterface::fileSelected( const QString& str) { |
75 | emit selector()->fileSelected( str); | 75 | emit selector()->fileSelected( str); |
76 | } | 76 | } |
77 | void OFileViewInterface::fileSelected( const DocLnk& lnk) { | 77 | void OFileViewInterface::fileSelected( const DocLnk& lnk) { |
78 | emit selector()->fileSelected( lnk ); | 78 | emit selector()->fileSelected( lnk ); |
79 | } | 79 | } |
80 | void OFileViewInterface::setCurrentFileName( const QString& str ) { | 80 | void OFileViewInterface::setCurrentFileName( const QString& str ) { |
81 | selector()->m_lneEdit->setText( str ); | 81 | selector()->m_lneEdit->setText( str ); |
82 | } | 82 | } |
83 | QString OFileViewInterface::currentFileName()const{ | 83 | QString OFileViewInterface::currentFileName()const{ |
84 | return selector()->m_lneEdit->text(); | 84 | return selector()->m_lneEdit->text(); |
85 | } | 85 | } |
86 | QString OFileViewInterface::startDirectory()const{ | 86 | QString OFileViewInterface::startDirectory()const{ |
87 | return selector()->m_startDir; | 87 | return selector()->m_startDir; |
88 | } | 88 | } |
89 | 89 | ||
90 | 90 | ||
91 | ODocumentFileView::ODocumentFileView( OFileSelector* selector ) | 91 | ODocumentFileView::ODocumentFileView( OFileSelector* selector ) |
92 | : OFileViewInterface( selector ) { | 92 | : OFileViewInterface( selector ) { |
93 | m_selector = 0; | 93 | m_selector = 0; |
94 | setName( i18n("Documents") ); | 94 | setName( i18n("Documents") ); |
95 | } | 95 | } |
96 | ODocumentFileView::~ODocumentFileView() { | 96 | ODocumentFileView::~ODocumentFileView() { |
97 | 97 | ||
98 | } | 98 | } |
99 | QString ODocumentFileView::selectedName()const { | 99 | QString ODocumentFileView::selectedName()const { |
100 | if (!m_selector) | 100 | if (!m_selector) |
101 | return QString::null; | 101 | return QString::null; |
102 | 102 | ||
103 | return m_selector->selected()->file(); | 103 | return m_selector->selected()->file(); |
104 | } | 104 | } |
105 | QString ODocumentFileView::selectedPath()const { | 105 | QString ODocumentFileView::selectedPath()const { |
106 | return QPEApplication::documentDir(); | 106 | return QPEApplication::documentDir(); |
107 | } | 107 | } |
108 | QString ODocumentFileView::directory()const { | 108 | QString ODocumentFileView::directory()const { |
109 | return selectedPath(); | 109 | return selectedPath(); |
110 | } | 110 | } |
111 | void ODocumentFileView::reread() { | 111 | void ODocumentFileView::reread() { |
112 | if (!m_selector) | 112 | if (!m_selector) |
113 | return; | 113 | return; |
114 | 114 | ||
115 | m_selector->setNewVisible( showNew() ); | 115 | m_selector->setNewVisible( showNew() ); |
116 | m_selector->setCloseVisible( showClose() ); | 116 | m_selector->setCloseVisible( showClose() ); |
117 | m_selector->filter = currentMimeType().join(";"); | 117 | m_selector->filter = currentMimeType().join(";"); |
118 | m_selector->reread(); | 118 | m_selector->reread(); |
119 | } | 119 | } |
120 | int ODocumentFileView::fileCount()const { | 120 | int ODocumentFileView::fileCount()const { |
121 | if (!m_selector) | 121 | if (!m_selector) |
122 | return -1; | 122 | return -1; |
123 | 123 | ||
124 | return m_selector->fileCount(); | 124 | return m_selector->fileCount(); |
125 | } | 125 | } |
126 | 126 | ||
127 | DocLnk ODocumentFileView::selectedDocument()const { | 127 | DocLnk ODocumentFileView::selectedDocument()const { |
128 | if (!m_selector) | 128 | if (!m_selector) |
129 | return DocLnk(); | 129 | return DocLnk(); |
130 | DocLnk lnk = *m_selector->selected(); | 130 | DocLnk lnk = *m_selector->selected(); |
131 | return lnk; | 131 | return lnk; |
132 | } | 132 | } |
133 | 133 | ||
134 | QWidget* ODocumentFileView::widget( QWidget* parent ) { | 134 | QWidget* ODocumentFileView::widget( QWidget* parent ) { |
135 | if (!m_selector ) { | 135 | if (!m_selector ) { |
136 | m_selector = new FileSelector(currentMimeType().join(";"), parent, "fileselector", showNew(), showClose() ); | 136 | m_selector = new FileSelector(currentMimeType().join(";"), parent, "fileselector", showNew(), showClose() ); |
137 | QObject::connect(m_selector, SIGNAL(fileSelected( const DocLnk& ) ), | 137 | QObject::connect(m_selector, SIGNAL(fileSelected( const DocLnk& ) ), |
138 | selector(), SLOT(slotDocLnkBridge(const DocLnk&) ) ); | 138 | selector(), SLOT(slotDocLnkBridge(const DocLnk&) ) ); |
139 | QObject::connect(m_selector, SIGNAL(closeMe() ), | 139 | QObject::connect(m_selector, SIGNAL(closeMe() ), |
140 | selector(), SIGNAL(closeMe() ) ); | 140 | selector(), SIGNAL(closeMe() ) ); |
141 | QObject::connect(m_selector, SIGNAL(newSelected(const DocLnk& ) ), | 141 | QObject::connect(m_selector, SIGNAL(newSelected(const DocLnk& ) ), |
142 | selector(), SIGNAL(newSelected(const DocLnk& ) ) ); | 142 | selector(), SIGNAL(newSelected(const DocLnk& ) ) ); |
143 | } | 143 | } |
144 | 144 | ||
145 | return m_selector; | 145 | return m_selector; |
146 | } | 146 | } |
147 | 147 | ||
148 | /* | 148 | /* |
149 | * This is the file system view used | 149 | * This is the file system view used |
150 | * we use a QListView + QListViewItems for it | 150 | * we use a QListView + QListViewItems for it |
151 | */ | 151 | */ |
152 | 152 | ||
153 | OFileSelectorItem::OFileSelectorItem( QListView* view, const QPixmap& pixmap, | 153 | OFileSelectorItem::OFileSelectorItem( QListView* view, const QPixmap& pixmap, |
154 | const QString& path, const QString& date, | 154 | const QString& path, const QString& date, |
155 | const QString& size, const QString& dir, | 155 | const QString& size, const QString& dir, |
156 | bool isLocked, bool isDir ) | 156 | bool isLocked, bool isDir ) |
157 | : QListViewItem( view ) | 157 | : QListViewItem( view ) |
158 | { | 158 | { |
159 | 159 | ||
160 | QString kind; | 160 | QString kind = "dir";; |
161 | QString _path = path; | 161 | QString _path = path; |
162 | if ( isDir ) | 162 | if ( !isDir ){ |
163 | kind = "dir"; | 163 | int arrow = path.findRev( "." ,-1); |
164 | else | 164 | if (arrow > 0 ) { |
165 | kind = "file"; | 165 | kind = path.mid(arrow+1); |
166 | } | ||
167 | } | ||
166 | setPixmap(0, pixmap ); | 168 | setPixmap(0, pixmap ); |
167 | int arrow = path.find( "->" ); | 169 | int arrow = path.find( "->" ); |
168 | if (arrow > 0 ) { | 170 | if (arrow > 0 ) { |
169 | kind += path.mid( arrow ); | ||
170 | _path = path.left(arrow); | 171 | _path = path.left(arrow); |
171 | } | 172 | } |
172 | setText(1, _path ); | 173 | setText(1, _path ); |
173 | setText(2, size ); | 174 | setText(2, size ); |
174 | setText(3, date ); | 175 | setText(3, date ); |
175 | setText(4, kind ); | 176 | setText(4, kind ); |
176 | m_isDir = isDir; | 177 | m_isDir = isDir; |
177 | m_dir = dir; | 178 | m_dir = dir; |
178 | m_locked = isLocked; | 179 | m_locked = isLocked; |
179 | } | 180 | } |
180 | OFileSelectorItem::~OFileSelectorItem() { | 181 | OFileSelectorItem::~OFileSelectorItem() { |
181 | 182 | ||
182 | } | 183 | } |
183 | bool OFileSelectorItem::isLocked()const { | 184 | bool OFileSelectorItem::isLocked()const { |
184 | return m_locked; | 185 | return m_locked; |
185 | } | 186 | } |
186 | QString OFileSelectorItem::directory()const { | 187 | QString OFileSelectorItem::directory()const { |
187 | return m_dir; | 188 | return m_dir; |
188 | } | 189 | } |
189 | bool OFileSelectorItem::isDir()const { | 190 | bool OFileSelectorItem::isDir()const { |
190 | return m_isDir; | 191 | return m_isDir; |
191 | } | 192 | } |
192 | QString OFileSelectorItem::path()const { | 193 | QString OFileSelectorItem::path()const { |
193 | return text( 1 ); | 194 | return text( 1 ); |
194 | } | 195 | } |
195 | QString OFileSelectorItem::key( int id, bool )const { | 196 | QString OFileSelectorItem::key( int id, bool )const { |
196 | QString ke; | 197 | QString ke; |
197 | if( id == 0 || id == 1 ){ // name | 198 | if( id == 0 || id == 1 ){ // name |
198 | if( m_isDir ){ | 199 | if( m_isDir ){ |
199 | ke.append("0" ); | 200 | ke.append("0" ); |
200 | ke.append( text(1) ); | 201 | ke.append( text(1) ); |
201 | }else{ | 202 | }else{ |
202 | ke.append("1" ); | 203 | ke.append("1" ); |
203 | ke.append( text(1) ); | 204 | ke.append( text(1) ); |
204 | } | 205 | } |
205 | return ke; | 206 | return ke; |
206 | } else if ( id == 2 ) { | 207 | } else if ( id == 2 ) { |
207 | QString sort = "00000000"; | 208 | QString sort = "00000000"; |
208 | sort = sort.left( 9-text( 2 ).length()) + text( 2 ); | 209 | sort = sort.left( 9-text( 2 ).length()) + text( 2 ); |
209 | return sort; | 210 | return sort; |
210 | 211 | ||
211 | } else | 212 | } else |
212 | return text( id ); | 213 | return text( id ); |
213 | 214 | ||
214 | } | 215 | } |
215 | 216 | ||
216 | OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& startDir, | 217 | OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& startDir, |
217 | OFileSelector* sel) | 218 | OFileSelector* sel) |
218 | : QWidget( parent ), m_sel( sel ) { | 219 | : QWidget( parent ), m_sel( sel ) { |
219 | m_all = false; | 220 | m_all = false; |
220 | QVBoxLayout* lay = new QVBoxLayout( this ); | 221 | QVBoxLayout* lay = new QVBoxLayout( this ); |
221 | m_currentDir = startDir; | 222 | m_currentDir = startDir; |
222 | 223 | ||
223 | /* | 224 | /* |
224 | * now we add a special bar | 225 | * now we add a special bar |
225 | * One Button For Up | 226 | * One Button For Up |
226 | * Home | 227 | * Home |
227 | * Doc | 228 | * Doc |
228 | * And a dropdown menu with FileSystems | 229 | * And a dropdown menu with FileSystems |
229 | * FUTURE: one to change dir with lineedit | 230 | * FUTURE: one to change dir with lineedit |
230 | * Bookmarks | 231 | * Bookmarks |
231 | * Create Dir | 232 | * Create Dir |
232 | */ | 233 | */ |
233 | QHBox* box = new QHBox(this ); | 234 | QHBox* box = new QHBox(this ); |
234 | box->setBackgroundMode( PaletteButton ); | 235 | box->setBackgroundMode( PaletteButton ); |
235 | box->setSpacing( 0 ); | 236 | box->setSpacing( 0 ); |
236 | 237 | ||
237 | QToolButton *btn = new QToolButton( box ); | 238 | QToolButton *btn = new QToolButton( box ); |
238 | btn->setIconSet( Resource::loadPixmap("up") ); | 239 | btn->setIconSet( Resource::loadPixmap("up") ); |
239 | connect(btn, SIGNAL(clicked() ), | 240 | connect(btn, SIGNAL(clicked() ), |
240 | this, SLOT( cdUP() ) ); | 241 | this, SLOT( cdUP() ) ); |
241 | 242 | ||
242 | btn = new QToolButton( box ); | 243 | btn = new QToolButton( box ); |
243 | btn->setIconSet( Resource::loadPixmap("home") ); | 244 | btn->setIconSet( Resource::loadPixmap("home") ); |
244 | connect(btn, SIGNAL(clicked() ), | 245 | connect(btn, SIGNAL(clicked() ), |
245 | this, SLOT( cdHome() ) ); | 246 | this, SLOT( cdHome() ) ); |
246 | 247 | ||
247 | btn = new QToolButton( box ); | 248 | btn = new QToolButton( box ); |
248 | btn->setIconSet( Resource::loadPixmap("DocsIcon") ); | 249 | btn->setIconSet( Resource::loadPixmap("DocsIcon") ); |
249 | connect(btn, SIGNAL(clicked() ), | 250 | connect(btn, SIGNAL(clicked() ), |
250 | this, SLOT(cdDoc() ) ); | 251 | this, SLOT(cdDoc() ) ); |
251 | 252 | ||
252 | m_btnNew = new QToolButton( box ); | 253 | m_btnNew = new QToolButton( box ); |
253 | m_btnNew->setIconSet( Resource::loadPixmap("new") ); | 254 | m_btnNew->setIconSet( Resource::loadPixmap("new") ); |
254 | connect(m_btnNew, SIGNAL(clicked() ), | 255 | connect(m_btnNew, SIGNAL(clicked() ), |
255 | this, SLOT(slotNew() ) ); | 256 | this, SLOT(slotNew() ) ); |
256 | 257 | ||
257 | 258 | ||
258 | m_btnClose = new QToolButton( box ); | 259 | m_btnClose = new QToolButton( box ); |
259 | m_btnClose->setIconSet( Resource::loadPixmap("close") ); | 260 | m_btnClose->setIconSet( Resource::loadPixmap("close") ); |
260 | connect(m_btnClose, SIGNAL(clicked() ), | 261 | connect(m_btnClose, SIGNAL(clicked() ), |
261 | selector(), SIGNAL(closeMe() ) ); | 262 | selector(), SIGNAL(closeMe() ) ); |
262 | 263 | ||
263 | btn = new QToolButton( box ); | 264 | btn = new QToolButton( box ); |
264 | btn->setIconSet( Resource::loadPixmap("cardmon/pcmcia") ); | 265 | btn->setIconSet( Resource::loadPixmap("cardmon/pcmcia") ); |
265 | 266 | ||
266 | /* let's fill device parts */ | 267 | /* let's fill device parts */ |
267 | QPopupMenu* pop = new QPopupMenu(this); | 268 | QPopupMenu* pop = new QPopupMenu(this); |
268 | connect(pop, SIGNAL( activated(int) ), | 269 | connect(pop, SIGNAL( activated(int) ), |
269 | this, SLOT(slotFSActivated(int) ) ); | 270 | this, SLOT(slotFSActivated(int) ) ); |
270 | 271 | ||
271 | StorageInfo storage; | 272 | StorageInfo storage; |
272 | const QList<FileSystem> &fs = storage.fileSystems(); | 273 | const QList<FileSystem> &fs = storage.fileSystems(); |
273 | QListIterator<FileSystem> it(fs); | 274 | QListIterator<FileSystem> it(fs); |
274 | for ( ; it.current(); ++it ) { | 275 | for ( ; it.current(); ++it ) { |
275 | const QString disk = (*it)->name(); | 276 | const QString disk = (*it)->name(); |
276 | const QString path = (*it)->path(); | 277 | const QString path = (*it)->path(); |
277 | m_dev.insert( disk, path ); | 278 | m_dev.insert( disk, path ); |
278 | pop->insertItem( disk ); | 279 | pop->insertItem( disk ); |
279 | } | 280 | } |
280 | m_fsPop = pop; | 281 | m_fsPop = pop; |
281 | 282 | ||
282 | 283 | ||
283 | btn->setPopup( pop ); | 284 | btn->setPopup( pop ); |
284 | btn->setPopupDelay ( 0 ); | 285 | btn->setPopupDelay ( 0 ); |
285 | lay->addWidget( box ); | 286 | lay->addWidget( box ); |
286 | 287 | ||
287 | m_view = new QListView( this ); | 288 | m_view = new QListView( this ); |
288 | 289 | ||
289 | m_view->installEventFilter(this); | 290 | m_view->installEventFilter(this); |
290 | 291 | ||
291 | QPEApplication::setStylusOperation( m_view->viewport(), | 292 | QPEApplication::setStylusOperation( m_view->viewport(), |
292 | QPEApplication::RightOnHold); | 293 | QPEApplication::RightOnHold); |
293 | m_view->addColumn(" " ); | 294 | m_view->addColumn(" " ); |
294 | m_view->addColumn(i18n("Name"), 135 ); | 295 | m_view->addColumn(i18n("Name"), 150 ); |
295 | m_view->addColumn(i18n("Size"), -1 ); | 296 | m_view->addColumn(i18n("Size"), -1 ); |
296 | m_view->addColumn(i18n("Date"), 60 ); | 297 | m_view->addColumn(i18n("Date"), -1 ); |
297 | m_view->addColumn(i18n("Mime Type"), -1 ); | 298 | m_view->addColumn(i18n("Mime Type"), -1 ); |
298 | 299 | ||
299 | 300 | ||
300 | m_view->setSorting( 1 ); | 301 | m_view->setSorting( 1 ); |
301 | m_view->setAllColumnsShowFocus( TRUE ); | 302 | m_view->setAllColumnsShowFocus( TRUE ); |
302 | 303 | ||
303 | lay->addWidget( m_view, 1000 ); | 304 | lay->addWidget( m_view, 1000 ); |
304 | connectSlots(); | 305 | connectSlots(); |
305 | } | 306 | } |
306 | OFileViewFileListView::~OFileViewFileListView() { | 307 | OFileViewFileListView::~OFileViewFileListView() { |
307 | } | 308 | } |
308 | void OFileViewFileListView::slotNew() { | 309 | void OFileViewFileListView::slotNew() { |
309 | DocLnk lnk; | 310 | DocLnk lnk; |
310 | emit selector()->newSelected( lnk ); | 311 | emit selector()->newSelected( lnk ); |
311 | } | 312 | } |
312 | OFileSelectorItem* OFileViewFileListView::currentItem()const{ | 313 | OFileSelectorItem* OFileViewFileListView::currentItem()const{ |
313 | QListViewItem* item = m_view->currentItem(); | 314 | QListViewItem* item = m_view->currentItem(); |
314 | if (!item ) | 315 | if (!item ) |
315 | return 0l; | 316 | return 0l; |
316 | 317 | ||
317 | return static_cast<OFileSelectorItem*>(item); | 318 | return static_cast<OFileSelectorItem*>(item); |
318 | } | 319 | } |
319 | void OFileViewFileListView::reread( bool all ) { | 320 | void OFileViewFileListView::reread( bool all ) { |
320 | m_view->clear(); | 321 | m_view->clear(); |
321 | 322 | ||
322 | if (selector()->showClose() ) | 323 | if (selector()->showClose() ) |
323 | m_btnClose->show(); | 324 | m_btnClose->show(); |
324 | else | 325 | else |
325 | m_btnClose->hide(); | 326 | m_btnClose->hide(); |
326 | 327 | ||
327 | if (selector()->showNew() ) | 328 | if (selector()->showNew() ) |
328 | m_btnNew->show(); | 329 | m_btnNew->show(); |
329 | else | 330 | else |
330 | m_btnNew->hide(); | 331 | m_btnNew->hide(); |
331 | 332 | ||
332 | m_mimes = selector()->currentMimeType(); | 333 | m_mimes = selector()->currentMimeType(); |
333 | m_all = all; | 334 | m_all = all; |
334 | 335 | ||
335 | QDir dir( m_currentDir ); | 336 | QDir dir( m_currentDir ); |
336 | if (!dir.exists() ) | 337 | if (!dir.exists() ) |
337 | return; | 338 | return; |
338 | topLevelWidget()->setCaption( dir.path() ); | 339 | topLevelWidget()->setCaption( dir.path() ); |
339 | dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed ); | 340 | dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed ); |
340 | int filter; | 341 | int filter; |
341 | if (m_all ) | 342 | if (m_all ) |
342 | filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; | 343 | filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All; |
343 | else | 344 | else |
344 | filter = QDir::Files | QDir::Dirs | QDir::All; | 345 | filter = QDir::Files | QDir::Dirs | QDir::All; |
345 | dir.setFilter( filter ); | 346 | dir.setFilter( filter ); |
346 | 347 | ||
347 | // now go through all files | 348 | // now go through all files |
348 | const QFileInfoList *list = dir.entryInfoList(); | 349 | const QFileInfoList *list = dir.entryInfoList(); |
349 | if (!list) { | 350 | if (!list) { |
350 | cdUP(); | 351 | cdUP(); |
351 | return; | 352 | return; |
352 | } | 353 | } |
353 | QFileInfoListIterator it( *list ); | 354 | QFileInfoListIterator it( *list ); |
354 | QFileInfo *fi; | 355 | QFileInfo *fi; |
355 | while( (fi=it.current() ) ){ | 356 | while( (fi=it.current() ) ){ |
356 | if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ){ | 357 | if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ){ |
357 | ++it; | 358 | ++it; |
358 | continue; | 359 | continue; |
359 | } | 360 | } |
360 | 361 | ||
361 | /* | 362 | /* |
362 | * It is a symlink we try to resolve it now but don't let us attack by DOS | 363 | * It is a symlink we try to resolve it now but don't let us attack by DOS |
363 | * | 364 | * |
364 | */ | 365 | */ |
365 | if( fi->isSymLink() ){ | 366 | if( fi->isSymLink() ){ |
366 | qDebug("SYMLINK "); | 367 | qDebug("SYMLINK "); |
367 | QString file = fi->readLink(); | 368 | QString file = fi->readLink(); |
368 | for( int i = 0; i<=5; i++) { // 5 tries to prevent dos | 369 | for( int i = 0; i<=5; i++) { // 5 tries to prevent dos |
369 | QFileInfo info( file ); | 370 | QFileInfo info( file ); |
370 | qDebug("FILE %s ", file.latin1()); | 371 | qDebug("FILE %s ", file.latin1()); |
371 | if( !info.exists() ){ | 372 | if( !info.exists() ){ |
372 | addSymlink( fi, TRUE ); | 373 | addSymlink( fi, TRUE ); |
373 | break; | 374 | break; |
374 | }else if( info.isDir() ){ | 375 | }else if( info.isDir() ){ |
375 | addDir( fi, TRUE ); | 376 | addDir( fi, TRUE ); |
376 | break; | 377 | break; |
377 | }else if( info.isFile() ){ | 378 | }else if( info.isFile() ){ |
378 | addFile( fi, TRUE ); | 379 | addFile( fi, TRUE ); |
379 | break; | 380 | break; |
380 | }else if( info.isSymLink() ){ | 381 | }else if( info.isSymLink() ){ |
381 | file = info.readLink() ; | 382 | file = info.readLink() ; |
382 | break; | 383 | break; |
383 | }else if( i == 4){ // couldn't resolve symlink add it as symlink | 384 | }else if( i == 4){ // couldn't resolve symlink add it as symlink |
384 | addSymlink( fi ); | 385 | addSymlink( fi ); |
385 | } | 386 | } |
386 | } // off for loop for symlink resolving | 387 | } // off for loop for symlink resolving |
387 | }else if( fi->isDir() ) | 388 | }else if( fi->isDir() ) |
388 | addDir( fi ); | 389 | addDir( fi ); |
389 | else if( fi->isFile() ) | 390 | else if( fi->isFile() ) |
390 | addFile( fi ); | 391 | addFile( fi ); |
391 | 392 | ||
392 | ++it; | 393 | ++it; |
393 | } // of while loop | 394 | } // of while loop |
394 | m_view->sort(); | 395 | m_view->sort(); |
395 | 396 | ||
396 | } | 397 | } |
397 | int OFileViewFileListView::fileCount()const{ | 398 | int OFileViewFileListView::fileCount()const{ |
398 | return m_view->childCount(); | 399 | return m_view->childCount(); |
399 | } | 400 | } |
400 | QString OFileViewFileListView::currentDir()const{ | 401 | QString OFileViewFileListView::currentDir()const{ |
401 | return m_currentDir; | 402 | return m_currentDir; |
402 | } | 403 | } |
403 | OFileSelector* OFileViewFileListView::selector() { | 404 | OFileSelector* OFileViewFileListView::selector() { |
404 | return m_sel; | 405 | return m_sel; |
405 | } | 406 | } |
406 | 407 | ||
407 | bool OFileViewFileListView::eventFilter (QObject *o, QEvent *e) { | 408 | bool OFileViewFileListView::eventFilter (QObject *o, QEvent *e) { |
408 | #if 0 | 409 | #if 0 |
409 | if ( e->type() == QEvent::KeyPress ) { | 410 | if ( e->type() == QEvent::KeyPress ) { |
410 | QKeyEvent *k = (QKeyEvent *)e; | 411 | QKeyEvent *k = (QKeyEvent *)e; |
411 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) { | 412 | if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) { |
412 | slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0); | 413 | slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0); |
413 | return true; | 414 | return true; |
414 | } | 415 | } |
415 | } | 416 | } |
416 | #endif | 417 | #endif |
417 | return false; | 418 | return false; |
418 | } | 419 | } |
419 | 420 | ||
420 | 421 | ||
421 | void OFileViewFileListView::connectSlots() { | 422 | void OFileViewFileListView::connectSlots() { |
422 | connect(m_view, SIGNAL(clicked(QListViewItem*) ), | 423 | connect(m_view, SIGNAL(clicked(QListViewItem*) ), |
423 | this, SLOT(slotCurrentChanged(QListViewItem*) ) ); | 424 | this, SLOT(slotCurrentChanged(QListViewItem*) ) ); |
424 | connect(m_view, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint&, int ) ), | 425 | connect(m_view, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint&, int ) ), |
425 | this, SLOT(slotClicked(int, QListViewItem*, const QPoint&, int ) ) ); | 426 | this, SLOT(slotClicked(int, QListViewItem*, const QPoint&, int ) ) ); |
426 | connect(m_view, SIGNAL(doubleClicked( QListViewItem* )), | 427 | connect(m_view, SIGNAL(doubleClicked( QListViewItem* )), |
427 | this, SLOT(slotDoubleClicked(QListViewItem* ) ) ); | 428 | this, SLOT(slotDoubleClicked(QListViewItem* ) ) ); |
428 | connect(m_view, SIGNAL(returnPressed( QListViewItem* )), | 429 | connect(m_view, SIGNAL(returnPressed( QListViewItem* )), |
429 | this, SLOT(slotDoubleClicked(QListViewItem* ) ) ); | 430 | this, SLOT(slotDoubleClicked(QListViewItem* ) ) ); |
430 | } | 431 | } |
431 | void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) { | 432 | void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) { |
432 | if (!item) | 433 | if (!item) |
433 | return; | 434 | return; |
434 | #if 0 | 435 | #if 0 |
435 | 436 | ||
436 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); | 437 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); |
437 | 438 | ||
438 | if (!sel->isDir() ) { | 439 | if (!sel->isDir() ) { |
439 | selector()->m_lneEdit->setText( sel->text(1) ); | 440 | selector()->m_lneEdit->setText( sel->text(1) ); |
440 | // if in fileselector mode we will emit selected | 441 | // if in fileselector mode we will emit selected |
441 | if ( selector()->mode() == OFileSelector::FileSelector ) { | 442 | if ( selector()->mode() == OFileSelector::FileSelector ) { |
442 | qWarning("slot Current Changed"); | 443 | qWarning("slot Current Changed"); |
443 | QStringList str = QStringList::split("->", sel->text(1) ); | 444 | QStringList str = QStringList::split("->", sel->text(1) ); |
444 | QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); | 445 | QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); |
445 | emit selector()->fileSelected( path ); | 446 | emit selector()->fileSelected( path ); |
446 | DocLnk lnk( path ); | 447 | DocLnk lnk( path ); |
447 | emit selector()->fileSelected( lnk ); | 448 | emit selector()->fileSelected( lnk ); |
448 | } | 449 | } |
449 | } | 450 | } |
450 | #endif | 451 | #endif |
451 | } | 452 | } |
452 | void OFileViewFileListView::slotDoubleClicked(QListViewItem* item ) { | 453 | void OFileViewFileListView::slotDoubleClicked(QListViewItem* item ) { |
453 | if (!item ) return; | 454 | if (!item ) return; |
454 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); | 455 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); |
455 | if (!sel->isLocked() ) { | 456 | if (!sel->isLocked() ) { |
456 | QStringList str = QStringList::split("->", sel->text(1) ); | 457 | QStringList str = QStringList::split("->", sel->text(1) ); |
457 | if (sel->isDir() ) { | 458 | if (sel->isDir() ) { |
458 | m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace(); | 459 | m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace(); |
459 | emit selector()->dirSelected( m_currentDir ); | 460 | emit selector()->dirSelected( m_currentDir ); |
460 | reread( m_all ); | 461 | reread( m_all ); |
461 | }else { // file | 462 | }else { // file |
462 | //qWarning("slot Clicked"); | 463 | //qWarning("slot Clicked"); |
463 | selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); | 464 | selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); |
464 | QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); | 465 | QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); |
465 | emit selector()->fileSelected( path ); | 466 | emit selector()->fileSelected( path ); |
466 | DocLnk lnk( path ); | 467 | DocLnk lnk( path ); |
467 | emit selector()->fileSelected( lnk ); | 468 | emit selector()->fileSelected( lnk ); |
468 | emit selector()->ok(); | 469 | emit selector()->ok(); |
469 | } | 470 | } |
470 | } // not locked | 471 | } // not locked |
471 | } | 472 | } |
472 | void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) { | 473 | void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) { |
473 | if (!item || ( button != Qt::LeftButton) ) | 474 | if (!item || ( button != Qt::LeftButton) ) |
474 | return; | 475 | return; |
475 | 476 | ||
476 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); | 477 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); |
477 | if (!sel->isLocked() ) { | 478 | if (!sel->isLocked() ) { |
478 | QStringList str = QStringList::split("->", sel->text(1) ); | 479 | QStringList str = QStringList::split("->", sel->text(1) ); |
479 | if (sel->isDir() ) { | 480 | if (sel->isDir() ) { |
480 | m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace(); | 481 | m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace(); |
481 | emit selector()->dirSelected( m_currentDir ); | 482 | emit selector()->dirSelected( m_currentDir ); |
482 | reread( m_all ); | 483 | reread( m_all ); |
483 | }else { // file | 484 | }else { // file |
484 | //qWarning("slot Clicked"); | 485 | //qWarning("slot Clicked"); |
485 | selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); | 486 | selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); |
486 | QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); | 487 | QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); |
487 | emit selector()->fileSelected( path ); | 488 | emit selector()->fileSelected( path ); |
488 | DocLnk lnk( path ); | 489 | DocLnk lnk( path ); |