-rw-r--r-- | core/apps/textedit/fileBrowser.cpp | 35 | ||||
-rw-r--r-- | core/apps/textedit/fileBrowser.h | 3 |
2 files changed, 28 insertions, 10 deletions
diff --git a/core/apps/textedit/fileBrowser.cpp b/core/apps/textedit/fileBrowser.cpp index 7a3a703..8c942a1 100644 --- a/core/apps/textedit/fileBrowser.cpp +++ b/core/apps/textedit/fileBrowser.cpp | |||
@@ -91,156 +91,152 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags | |||
91 | 91 | ||
92 | docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"",this,"docsButton"); | 92 | docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"",this,"docsButton"); |
93 | docButton->setMinimumSize( QSize( 20, 20 ) ); | 93 | docButton->setMinimumSize( QSize( 20, 20 ) ); |
94 | docButton->setMaximumSize( QSize( 20, 20 ) ); | 94 | docButton->setMaximumSize( QSize( 20, 20 ) ); |
95 | connect( docButton,SIGNAL(released()),this,SLOT( docButtonPushed()) ); | 95 | connect( docButton,SIGNAL(released()),this,SLOT( docButtonPushed()) ); |
96 | docButton->setFlat(TRUE); | 96 | docButton->setFlat(TRUE); |
97 | layout->addMultiCellWidget( docButton, 0, 0, 6, 6 ); | 97 | layout->addMultiCellWidget( docButton, 0, 0, 6, 6 ); |
98 | 98 | ||
99 | homeButton = new QPushButton( Resource::loadIconSet("home"),"",this,"homeButton"); | 99 | homeButton = new QPushButton( Resource::loadIconSet("home"),"",this,"homeButton"); |
100 | homeButton->setMinimumSize( QSize( 20, 20 ) ); | 100 | homeButton->setMinimumSize( QSize( 20, 20 ) ); |
101 | homeButton->setMaximumSize( QSize( 20, 20 ) ); | 101 | homeButton->setMaximumSize( QSize( 20, 20 ) ); |
102 | connect(homeButton,SIGNAL(released()),this,SLOT(homeButtonPushed()) ); | 102 | connect(homeButton,SIGNAL(released()),this,SLOT(homeButtonPushed()) ); |
103 | homeButton->setFlat(TRUE); | 103 | homeButton->setFlat(TRUE); |
104 | layout->addMultiCellWidget( homeButton, 0, 0, 7, 7 ); | 104 | layout->addMultiCellWidget( homeButton, 0, 0, 7, 7 ); |
105 | 105 | ||
106 | FileStack = new QWidgetStack( this ); | 106 | FileStack = new QWidgetStack( this ); |
107 | 107 | ||
108 | ListView = new QListView( this, "ListView" ); | 108 | ListView = new QListView( this, "ListView" ); |
109 | // ListView->setMinimumSize( QSize( 100, 25 ) ); | 109 | // ListView->setMinimumSize( QSize( 100, 25 ) ); |
110 | ListView->addColumn( tr( "Name" ) ); | 110 | ListView->addColumn( tr( "Name" ) ); |
111 | ListView->setColumnWidth(0,120); | 111 | ListView->setColumnWidth(0,120); |
112 | ListView->setSorting( 2, FALSE); | 112 | ListView->setSorting( 2, FALSE); |
113 | ListView->addColumn( tr( "Size" ) ); | 113 | ListView->addColumn( tr( "Size" ) ); |
114 | ListView->setColumnWidth(1,-1); | 114 | ListView->setColumnWidth(1,-1); |
115 | ListView->addColumn( "Date",-1); | 115 | ListView->addColumn( "Date",-1); |
116 | 116 | ||
117 | ListView->setColumnWidthMode(0,QListView::Manual); | 117 | ListView->setColumnWidthMode(0,QListView::Manual); |
118 | ListView->setColumnAlignment(1,QListView::AlignRight); | 118 | ListView->setColumnAlignment(1,QListView::AlignRight); |
119 | ListView->setColumnAlignment(2,QListView::AlignRight); | 119 | ListView->setColumnAlignment(2,QListView::AlignRight); |
120 | ListView->setAllColumnsShowFocus( TRUE ); | 120 | ListView->setAllColumnsShowFocus( TRUE ); |
121 | 121 | ||
122 | QPEApplication::setStylusOperation( ListView->viewport(),QPEApplication::RightOnHold); | 122 | QPEApplication::setStylusOperation( ListView->viewport(),QPEApplication::RightOnHold); |
123 | connect( ListView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | 123 | connect( ListView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), |
124 | this,SLOT( ListPressed(int, QListViewItem *, const QPoint&, int)) ); | 124 | this,SLOT( ListPressed(int, QListViewItem *, const QPoint&, int)) ); |
125 | 125 | ||
126 | connect( ListView, SIGNAL( clicked( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); | 126 | connect( ListView, SIGNAL( clicked( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); |
127 | 127 | ||
128 | FileStack->addWidget( ListView, get_unique_id() ); | 128 | FileStack->addWidget( ListView, get_unique_id() ); |
129 | 129 | ||
130 | fileSelector = new FileSelector( mimeType, FileStack, "fileselector" , FALSE, FALSE); //buggy | 130 | fileSelector = new FileSelector( mimeType, FileStack, "fileselector" , FALSE, FALSE); //buggy |
131 | // connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); | 131 | // connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); |
132 | // connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); | 132 | // connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); |
133 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) ); | 133 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) ); |
134 | layout->addMultiCellWidget( FileStack, 1, 1, 0, 7 ); | 134 | layout->addMultiCellWidget( FileStack, 1, 1, 0, 7 ); |
135 | 135 | ||
136 | SelectionCombo = new QComboBox( FALSE, this, "SelectionCombo" ); | 136 | SelectionCombo = new QComboBox( FALSE, this, "SelectionCombo" ); |
137 | SelectionCombo->insertItem( tr( "Documents" ) ); | 137 | SelectionCombo->insertItem( tr( "Documents" ) ); |
138 | SelectionCombo->insertItem( tr( "All files" ) ); | 138 | SelectionCombo->insertItem( tr( "All files" ) ); |
139 | SelectionCombo->insertItem( tr( "Hidden files" ) ); | 139 | SelectionCombo->insertItem( tr( "Hidden files" ) ); |
140 | // SelectionCombo->setMaximumWidth(120); | 140 | // SelectionCombo->setMaximumWidth(120); |
141 | layout->addMultiCellWidget( SelectionCombo, 2, 2, 0, 3 ); | 141 | layout->addMultiCellWidget( SelectionCombo, 2, 2, 0, 3 ); |
142 | 142 | ||
143 | connect( SelectionCombo, SIGNAL( activated( const QString & ) ), | 143 | connect( SelectionCombo, SIGNAL( activated( const QString & ) ), |
144 | this, SLOT( selectionChanged( const QString & ) ) ); | 144 | this, SLOT( selectionChanged( const QString & ) ) ); |
145 | 145 | ||
146 | typemb = new MenuButton(this); | 146 | typemb = new MenuButton(this); |
147 | typemb->setLabel(tr("Type: %1")); | 147 | typemb->setLabel(tr("Type: %1")); |
148 | typemb->setMinimumWidth(110); | 148 | typemb->setMinimumWidth(110); |
149 | typemb->setFixedHeight(22); | 149 | typemb->setFixedHeight(22); |
150 | layout->addMultiCellWidget( typemb, 2, 2, 4, 7 ); | 150 | layout->addMultiCellWidget( typemb, 2, 2, 4, 7 ); |
151 | updateMimeTypeMenu() ; | 151 | updateMimeTypeMenu() ; |
152 | 152 | ||
153 | currentDir.setPath(QDir::currentDirPath()); | 153 | currentDir.setPath(QDir::currentDirPath()); |
154 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden */| QDir::All); | 154 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden */| QDir::All); |
155 | currentDir.setNameFilter(filterStr); | ||
155 | 156 | ||
156 | populateList(); | 157 | populateList(); |
157 | move(0,15); | 158 | move(0,15); |
158 | } | 159 | } |
159 | 160 | ||
160 | fileBrowser::~fileBrowser() | 161 | fileBrowser::~fileBrowser() |
161 | { | 162 | { |
162 | } | 163 | } |
163 | 164 | ||
164 | void fileBrowser::setMimeType(const QString &type) { | ||
165 | mimeType = type; | ||
166 | } | ||
167 | |||
168 | void fileBrowser::setFileView( int selection ) | 165 | void fileBrowser::setFileView( int selection ) |
169 | { | 166 | { |
170 | SelectionCombo->setCurrentItem( selection ); | 167 | SelectionCombo->setCurrentItem( selection ); |
171 | selectionChanged( SelectionCombo->currentText() ); | 168 | selectionChanged( SelectionCombo->currentText() ); |
172 | } | 169 | } |
173 | 170 | ||
174 | void fileBrowser::populateList() | 171 | void fileBrowser::populateList() |
175 | { | 172 | { |
176 | ListView->clear(); | 173 | ListView->clear(); |
177 | bool isDir=FALSE; | 174 | bool isDir=FALSE; |
178 | //qDebug(currentDir.canonicalPath()); | 175 | //qDebug(currentDir.canonicalPath()); |
179 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | 176 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); |
180 | currentDir.setMatchAllDirs(TRUE); | 177 | currentDir.setMatchAllDirs(TRUE); |
181 | 178 | ||
182 | currentDir.setNameFilter(filterStr); | ||
183 | // currentDir.setNameFilter("*.txt;*.etx"); | 179 | // currentDir.setNameFilter("*.txt;*.etx"); |
184 | QString fileL, fileS, fileDate; | 180 | QString fileL, fileS, fileDate; |
185 | const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); | 181 | const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); |
186 | QFileInfoListIterator it(*list); | 182 | QFileInfoListIterator it(*list); |
187 | QFileInfo *fi; | 183 | QFileInfo *fi; |
188 | while ( (fi=it.current()) ) { | 184 | while ( (fi=it.current()) ) { |
189 | 185 | ||
190 | if (fi->isSymLink() ){ | 186 | if (fi->isSymLink() ){ |
191 | QString symLink=fi->readLink(); | 187 | QString symLink=fi->readLink(); |
192 | // qDebug("Symlink detected "+symLink); | 188 | // qDebug("Symlink detected "+symLink); |
193 | QFileInfo sym( symLink); | 189 | QFileInfo sym( symLink); |
194 | fileS.sprintf( "%10li", sym.size() ); | 190 | fileS.sprintf( "%10li", sym.size() ); |
195 | fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); | 191 | fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); |
196 | fileDate = sym.lastModified().toString(); | 192 | fileDate = sym.lastModified().toString(); |
197 | } else { | 193 | } else { |
198 | // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); | 194 | // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); |
199 | fileS.sprintf( "%10li", fi->size() ); | 195 | fileS.sprintf( "%10li", fi->size() ); |
200 | fileL.sprintf( "%s",fi->fileName().data() ); | 196 | fileL.sprintf( "%s",fi->fileName().data() ); |
201 | fileDate= fi->lastModified().toString(); | 197 | fileDate= fi->lastModified().toString(); |
202 | if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { | 198 | if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { |
203 | fileL+="/"; | 199 | fileL+="/"; |
204 | isDir=TRUE; | 200 | isDir=TRUE; |
205 | // qDebug( fileL); | 201 | // qDebug( fileL); |
206 | } | 202 | } |
207 | } | 203 | } |
208 | if(fileL !="./") { | 204 | if(fileL !="./") { |
209 | item= new QListViewItem( ListView,fileL,fileS , fileDate); | 205 | item= new QListViewItem( ListView,fileL,fileS , fileDate); |
210 | QPixmap pm; | 206 | QPixmap pm; |
211 | 207 | ||
212 | if(isDir || fileL.find("/",0,TRUE) != -1) { | 208 | if(isDir || fileL.find("/",0,TRUE) != -1) { |
213 | if( !QDir( fi->filePath() ).isReadable()) | 209 | if( !QDir( fi->filePath() ).isReadable()) |
214 | pm = Resource::loadPixmap( "lockedfolder" ); | 210 | pm = Resource::loadPixmap( "lockedfolder" ); |
215 | else | 211 | else |
216 | pm= Resource::loadPixmap( "folder" ); | 212 | pm= Resource::loadPixmap( "folder" ); |
217 | item->setPixmap( 0,pm ); | 213 | item->setPixmap( 0,pm ); |
218 | } else { | 214 | } else { |
219 | if( !fi->isReadable() ) | 215 | if( !fi->isReadable() ) |
220 | pm = Resource::loadPixmap( "locked" ); | 216 | pm = Resource::loadPixmap( "locked" ); |
221 | else { | 217 | else { |
222 | MimeType mt(fi->filePath()); | 218 | MimeType mt(fi->filePath()); |
223 | pm=mt.pixmap(); | 219 | pm=mt.pixmap(); |
224 | if(pm.isNull()) | 220 | if(pm.isNull()) |
225 | pm = Resource::loadPixmap( "UnknownDocument-14" ); | 221 | pm = Resource::loadPixmap( "UnknownDocument-14" ); |
226 | item->setPixmap( 0,pm); | 222 | item->setPixmap( 0,pm); |
227 | } | 223 | } |
228 | } | 224 | } |
229 | if( fileL.find("->",0,TRUE) != -1) { | 225 | if( fileL.find("->",0,TRUE) != -1) { |
230 | // overlay link image | 226 | // overlay link image |
231 | pm= Resource::loadPixmap( "folder" ); | 227 | pm= Resource::loadPixmap( "folder" ); |
232 | QPixmap lnk = Resource::loadPixmap( "symlink" ); | 228 | QPixmap lnk = Resource::loadPixmap( "symlink" ); |
233 | QPainter painter( &pm ); | 229 | QPainter painter( &pm ); |
234 | painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); | 230 | painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); |
235 | pm.setMask( pm.createHeuristicMask( FALSE ) ); | 231 | pm.setMask( pm.createHeuristicMask( FALSE ) ); |
236 | item->setPixmap( 0, pm); | 232 | item->setPixmap( 0, pm); |
237 | } | 233 | } |
238 | } | 234 | } |
239 | isDir=FALSE; | 235 | isDir=FALSE; |
240 | ++it; | 236 | ++it; |
241 | } | 237 | } |
242 | ListView->setSorting( 3, FALSE); | 238 | ListView->setSorting( 3, FALSE); |
243 | QString currentPath = currentDir.canonicalPath(); | 239 | QString currentPath = currentDir.canonicalPath(); |
244 | 240 | ||
245 | fillCombo( (const QString &)currentPath); | 241 | fillCombo( (const QString &)currentPath); |
246 | // dirPathCombo->lineEdit()->setText(currentPath); | 242 | // dirPathCombo->lineEdit()->setText(currentPath); |
@@ -325,254 +321,277 @@ void fileBrowser::homeButtonPushed() { | |||
325 | QString current = QDir::homeDirPath(); | 321 | QString current = QDir::homeDirPath(); |
326 | chdir( current.latin1() ); | 322 | chdir( current.latin1() ); |
327 | currentDir.cd( current, TRUE); | 323 | currentDir.cd( current, TRUE); |
328 | populateList(); | 324 | populateList(); |
329 | update(); | 325 | update(); |
330 | } | 326 | } |
331 | 327 | ||
332 | void fileBrowser::docButtonPushed() { | 328 | void fileBrowser::docButtonPushed() { |
333 | QString current = QPEApplication::documentDir(); | 329 | QString current = QPEApplication::documentDir(); |
334 | chdir( current.latin1() ); | 330 | chdir( current.latin1() ); |
335 | currentDir.cd( current, TRUE); | 331 | currentDir.cd( current, TRUE); |
336 | populateList(); | 332 | populateList(); |
337 | update(); | 333 | update(); |
338 | 334 | ||
339 | } | 335 | } |
340 | 336 | ||
341 | void fileBrowser::selectionChanged( const QString &select ) | 337 | void fileBrowser::selectionChanged( const QString &select ) |
342 | { | 338 | { |
343 | if ( select == "Documents") { | 339 | if ( select == "Documents") { |
344 | FileStack->raiseWidget( fileSelector ); | 340 | FileStack->raiseWidget( fileSelector ); |
345 | dirPathCombo->hide(); | 341 | dirPathCombo->hide(); |
346 | cdUpButton->hide(); | 342 | cdUpButton->hide(); |
347 | docButton->hide(); | 343 | docButton->hide(); |
348 | homeButton->hide(); | 344 | homeButton->hide(); |
349 | } else { | 345 | } else { |
350 | if ( select == "All files" ) | 346 | if ( select == "All files" ) |
351 | currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::All); | 347 | currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::All); |
352 | else | 348 | else |
353 | currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); | 349 | currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); |
354 | 350 | ||
355 | populateList(); | 351 | populateList(); |
356 | update(); | 352 | update(); |
357 | dirPathCombo->show(); | 353 | dirPathCombo->show(); |
358 | cdUpButton->show(); | 354 | cdUpButton->show(); |
359 | docButton->show(); | 355 | docButton->show(); |
360 | homeButton->show(); | 356 | homeButton->show(); |
361 | FileStack->raiseWidget( ListView ); | 357 | FileStack->raiseWidget( ListView ); |
362 | } | 358 | } |
363 | } | 359 | } |
364 | 360 | ||
365 | void fileBrowser::docOpen( const DocLnk &doc ) | 361 | void fileBrowser::docOpen( const DocLnk &doc ) |
366 | { | 362 | { |
367 | fileList.append( doc.file().latin1() ); | 363 | fileList.append( doc.file().latin1() ); |
368 | accept(); | 364 | accept(); |
369 | } | 365 | } |
370 | 366 | ||
371 | void fileBrowser::ListPressed( int mouse, QListViewItem *item, const QPoint &point, int i) | 367 | void fileBrowser::ListPressed( int mouse, QListViewItem *item, const QPoint &point, int i) |
372 | { | 368 | { |
373 | switch (mouse) { | 369 | switch (mouse) { |
374 | case 1: | 370 | case 1: |
375 | break; | 371 | break; |
376 | case 2: | 372 | case 2: |
377 | showListMenu(item); | 373 | showListMenu(item); |
378 | break; | 374 | break; |
379 | }; | 375 | }; |
380 | } | 376 | } |
381 | 377 | ||
382 | void fileBrowser::showListMenu(QListViewItem *item) { | 378 | void fileBrowser::showListMenu(QListViewItem *item) { |
383 | 379 | ||
384 | QPopupMenu m;// = new QPopupMenu( Local_View ); | 380 | QPopupMenu m;// = new QPopupMenu( Local_View ); |
385 | if( item->text(0).find("/",0,TRUE)) | 381 | if( item->text(0).find("/",0,TRUE)) |
386 | m.insertItem( tr( "Change Directory" ), this, SLOT( doCd() )); | 382 | m.insertItem( tr( "Change Directory" ), this, SLOT( doCd() )); |
387 | else | 383 | else |
388 | m.insertItem( tr( "Make Directory" ), this, SLOT( makDir() )); | 384 | m.insertItem( tr( "Make Directory" ), this, SLOT( makDir() )); |
389 | m.insertItem( tr( "Rescan" ), this, SLOT( populateList()() )); | 385 | m.insertItem( tr( "Rescan" ), this, SLOT( populateList() )); |
390 | m.insertItem( tr( "Rename" ), this, SLOT( localRename() )); | 386 | m.insertItem( tr( "Rename" ), this, SLOT( localRename() )); |
391 | m.insertSeparator(); | 387 | m.insertSeparator(); |
392 | m.insertItem( tr( "Delete" ), this, SLOT( localDelete() )); | 388 | m.insertItem( tr( "Delete" ), this, SLOT( localDelete() )); |
393 | m.exec( QCursor::pos() ); | 389 | m.exec( QCursor::pos() ); |
394 | 390 | ||
395 | } | 391 | } |
396 | 392 | ||
397 | void fileBrowser::doCd() { | 393 | void fileBrowser::doCd() { |
398 | listClicked( ListView->currentItem()); | 394 | listClicked( ListView->currentItem()); |
399 | } | 395 | } |
400 | 396 | ||
401 | void fileBrowser::makDir() { | 397 | void fileBrowser::makDir() { |
402 | InputDialog *fileDlg; | 398 | InputDialog *fileDlg; |
403 | fileDlg = new InputDialog(this,"Make Directory",TRUE, 0); | 399 | fileDlg = new InputDialog(this,"Make Directory",TRUE, 0); |
404 | fileDlg->exec(); | 400 | fileDlg->exec(); |
405 | if( fileDlg->result() == 1 ) { | 401 | if( fileDlg->result() == 1 ) { |
406 | QString filename = fileDlg->LineEdit1->text(); | 402 | QString filename = fileDlg->LineEdit1->text(); |
407 | currentDir.mkdir( currentDir.canonicalPath()+"/"+filename); | 403 | currentDir.mkdir( currentDir.canonicalPath()+"/"+filename); |
408 | } | 404 | } |
409 | populateList(); | 405 | populateList(); |
410 | } | 406 | } |
411 | 407 | ||
412 | void fileBrowser::localRename() { | 408 | void fileBrowser::localRename() { |
413 | QString curFile = ListView->currentItem()->text(0); | 409 | QString curFile = ListView->currentItem()->text(0); |
414 | InputDialog *fileDlg; | 410 | InputDialog *fileDlg; |
415 | fileDlg = new InputDialog(this,"Rename",TRUE, 0); | 411 | fileDlg = new InputDialog(this,"Rename",TRUE, 0); |
416 | fileDlg->inputText = curFile; | 412 | fileDlg->inputText = curFile; |
417 | fileDlg->exec(); | 413 | fileDlg->exec(); |
418 | if( fileDlg->result() == 1 ) { | 414 | if( fileDlg->result() == 1 ) { |
419 | QString oldname = currentDir.canonicalPath() + "/" + curFile; | 415 | QString oldname = currentDir.canonicalPath() + "/" + curFile; |
420 | QString newName = currentDir.canonicalPath() + "/" + fileDlg->LineEdit1->text();//+".playlist"; | 416 | QString newName = currentDir.canonicalPath() + "/" + fileDlg->LineEdit1->text();//+".playlist"; |
421 | if( rename(oldname.latin1(), newName.latin1())== -1) | 417 | if( rename(oldname.latin1(), newName.latin1())== -1) |
422 | QMessageBox::message("Note","Could not rename"); | 418 | QMessageBox::message("Note","Could not rename"); |
423 | } | 419 | } |
424 | populateList(); | 420 | populateList(); |
425 | } | 421 | } |
426 | 422 | ||
427 | void fileBrowser::localDelete() { | 423 | void fileBrowser::localDelete() { |
428 | QString f = ListView->currentItem()->text(0); | 424 | QString f = ListView->currentItem()->text(0); |
429 | if(QDir(f).exists() ) { | 425 | if(QDir(f).exists() ) { |
430 | switch ( QMessageBox::warning(this,"Delete","Do you really want to delete\n"+f+ | 426 | switch ( QMessageBox::warning(this,"Delete","Do you really want to delete\n"+f+ |
431 | " ?\nIt must be empty","Yes","No",0,0,1) ) { | 427 | " ?\nIt must be empty","Yes","No",0,0,1) ) { |
432 | case 0: { | 428 | case 0: { |
433 | f=currentDir.canonicalPath()+"/"+f; | 429 | f=currentDir.canonicalPath()+"/"+f; |
434 | QString cmd="rmdir "+f; | 430 | QString cmd="rmdir "+f; |
435 | system( cmd.latin1()); | 431 | system( cmd.latin1()); |
436 | populateList(); | 432 | populateList(); |
437 | } | 433 | } |
438 | break; | 434 | break; |
439 | case 1: | 435 | case 1: |
440 | // exit | 436 | // exit |
441 | break; | 437 | break; |
442 | }; | 438 | }; |
443 | 439 | ||
444 | } else { | 440 | } else { |
445 | switch ( QMessageBox::warning(this,"Delete","Do you really want to delete\n"+f | 441 | switch ( QMessageBox::warning(this,"Delete","Do you really want to delete\n"+f |
446 | +" ?","Yes","No",0,0,1) ) { | 442 | +" ?","Yes","No",0,0,1) ) { |
447 | case 0: { | 443 | case 0: { |
448 | f=currentDir.canonicalPath()+"/"+f; | 444 | f=currentDir.canonicalPath()+"/"+f; |
449 | QString cmd="rm "+f; | 445 | QString cmd="rm "+f; |
450 | system( cmd.latin1()); | 446 | system( cmd.latin1()); |
451 | populateList(); | 447 | populateList(); |
452 | } | 448 | } |
453 | break; | 449 | break; |
454 | case 1: | 450 | case 1: |
455 | // exit | 451 | // exit |
456 | break; | 452 | break; |
457 | }; | 453 | }; |
458 | } | 454 | } |
459 | } | 455 | } |
460 | 456 | ||
461 | void fileBrowser::updateMimeTypeMenu() { | 457 | void fileBrowser::updateMimeTypeMenu() { |
462 | 458 | ||
463 | disconnect( typemb, SIGNAL(selected(const QString&)), | 459 | disconnect( typemb, SIGNAL(selected(const QString&)), |
464 | this, SLOT(showType(const QString&)) ); | 460 | this, SLOT(showType(const QString&)) ); |
465 | 461 | ||
466 | QString prev; | 462 | QString prev; |
467 | 463 | ||
468 | // Type filter | 464 | // Type filter |
469 | QStringList types; | 465 | QStringList types; |
470 | types << tr("All"); | 466 | types << tr("All"); |
471 | types << "--"; | 467 | types << "--"; |
472 | types += getMimeTypes(); | 468 | types += getMimeTypes(); |
473 | prev = typemb->currentText(); | 469 | prev = typemb->currentText(); |
474 | typemb->clear(); | 470 | typemb->clear(); |
475 | typemb->insertItems(types); | 471 | typemb->insertItems(types); |
476 | // typemb->select(prev); | 472 | // typemb->select(prev); |
477 | 473 | ||
478 | connect(typemb, SIGNAL(selected(const QString&)), this, SLOT(showType(const QString&))); | 474 | connect(typemb, SIGNAL(selected(const QString&)), this, SLOT(showType(const QString&))); |
479 | } | 475 | } |
480 | 476 | ||
481 | void fileBrowser::showType(const QString &t) { | 477 | void fileBrowser::showType(const QString &t) { |
482 | 478 | ||
483 | qDebug(t); | 479 | qDebug(t); |
484 | mimeType = t+"/*"; | 480 | if(t.find("All",0,TRUE) != -1) { |
481 | filterStr = "*"; | ||
482 | } else { | ||
483 | QStringList list = mimetypes.grep( t,TRUE); | ||
484 | QString ext; | ||
485 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | ||
486 | mimeType =(*it); | ||
487 | MimeType mt( mimeType); | ||
488 | qDebug("mime "+mimeType); | ||
489 | // qDebug("description "+mt.description()); | ||
490 | // qDebug( "id "+mt.id()); | ||
491 | qDebug("extension "+mt.extension()); | ||
492 | if( mt.extension().isEmpty()) | ||
493 | filterStr = "*"; | ||
494 | else | ||
495 | filterStr = "*."+ mt.extension()+" "; | ||
496 | // printf( "%s \n", (*it).latin1() ); | ||
497 | } | ||
498 | } | ||
499 | currentDir.setNameFilter(filterStr); | ||
500 | |||
501 | populateList(); | ||
502 | update(); | ||
485 | // if(fileSelector) { | 503 | // if(fileSelector) { |
486 | // disconnect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) ); | 504 | // disconnect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) ); |
487 | // delete fileSelector; | 505 | // delete fileSelector; |
488 | // } | 506 | // } |
489 | // fileSelector = new FileSelector( mimeType, FileStack, "fileselector" , FALSE, FALSE); //buggy | 507 | // fileSelector = new FileSelector( mimeType, FileStack, "fileselector" , FALSE, FALSE); //buggy |
490 | // connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); | 508 | // connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); |
491 | // connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); | 509 | // connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); |
492 | // connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) ); | 510 | // connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) ); |
493 | // fileSelector->reread(); | 511 | // fileSelector->reread(); |
494 | repaint(); | ||
495 | // if ( t == tr("All") ) { | 512 | // if ( t == tr("All") ) { |
496 | // icons->setTypeFilter("",TRUE); | 513 | // icons->setTypeFilter("",TRUE); |
497 | // } else { | 514 | // } else { |
498 | // icons->setTypeFilter(t+"/*",TRUE); | 515 | // icons->setTypeFilter(t+"/*",TRUE); |
499 | // } | 516 | // } |
500 | 517 | ||
501 | } | 518 | } |
502 | 519 | ||
503 | QStringList fileBrowser::getMimeTypes() { | 520 | QStringList fileBrowser::getMimeTypes() { |
521 | |||
504 | QStringList r; | 522 | QStringList r; |
505 | AppLnkSet apps( QPEApplication::qpeDir() + "apps" ); | 523 | AppLnkSet apps( QPEApplication::qpeDir() + "apps" ); |
506 | QFile file( QPEApplication::qpeDir()+"etc/available.mime"); | 524 | QFile file( QPEApplication::qpeDir()+"etc/available.mime"); |
507 | file.open( IO_WriteOnly|IO_Truncate);//) | 525 | file.open( IO_WriteOnly|IO_Truncate);//) |
508 | for ( QListIterator<AppLnk> it( apps.children() ); it.current(); ++it ) { | 526 | for ( QListIterator<AppLnk> it( apps.children() ); it.current(); ++it ) { |
509 | AppLnk* l; | 527 | AppLnk* l; |
510 | l = it.current(); | 528 | l = it.current(); |
511 | QStringList maj = l->mimeTypes(); | 529 | QStringList maj = l->mimeTypes(); |
512 | QStringList::ConstIterator f; | 530 | QStringList::ConstIterator f; |
513 | for ( f = maj.begin(); f != maj.end(); f++ ) { | 531 | for ( f = maj.begin(); f != maj.end(); f++ ) { |
514 | QString temp = *f; | 532 | QString temp = *f; |
533 | mimetypes << temp; | ||
515 | int sl = temp.find('/'); | 534 | int sl = temp.find('/'); |
516 | if (sl >= 0) { | 535 | if (sl >= 0) { |
517 | QString k = temp.left(sl); | 536 | QString k = temp.left(sl); |
518 | if( r.grep(k,TRUE).isEmpty() ) { | 537 | if( r.grep(k,TRUE).isEmpty() ) { |
519 | r << k; | 538 | r << k; |
520 | k+="\n"; | 539 | k+="\n"; |
521 | file.writeBlock( k.latin1(), k.length()); | 540 | file.writeBlock( k.latin1(), k.length()); |
522 | } | 541 | } |
523 | } | 542 | } |
524 | } | 543 | } |
525 | } | 544 | } |
526 | r.sort(); | 545 | r.sort(); |
527 | file.close(); | 546 | file.close(); |
528 | return r; | 547 | return r; |
529 | } | 548 | } |
530 | 549 | ||
531 | void fileBrowser::receive( const QCString &msg, const QByteArray &data ) { | 550 | void fileBrowser::receive( const QCString &msg, const QByteArray &data ) { |
532 | // QDataStream stream( data, IO_ReadOnly ); | 551 | // QDataStream stream( data, IO_ReadOnly ); |
533 | // if (msg == "keyRegister(int key, QString channel, QString message)") | 552 | // if (msg == "keyRegister(int key, QString channel, QString message)") |
534 | // { | 553 | // { |
535 | // int k; | 554 | // int k; |
536 | // QString c, m; | 555 | // QString c, m; |
537 | // stream >> k; | 556 | // stream >> k; |
538 | // stream >> c; | 557 | // stream >> c; |
539 | // stream >> m; | 558 | // stream >> m; |
540 | } | 559 | } |
541 | 560 | ||
542 | void fileBrowser::dirPathComboActivated( const QString & current) { | 561 | void fileBrowser::dirPathComboActivated( const QString & current) { |
543 | chdir( current.latin1() ); | 562 | chdir( current.latin1() ); |
544 | currentDir.cd( current, TRUE); | 563 | currentDir.cd( current, TRUE); |
545 | populateList(); | 564 | populateList(); |
546 | update(); | 565 | update(); |
547 | } | 566 | } |
548 | 567 | ||
549 | void fileBrowser::dirPathEditPressed() { | 568 | void fileBrowser::dirPathEditPressed() { |
550 | QString current = dirPathCombo->lineEdit()->text(); | 569 | QString current = dirPathCombo->lineEdit()->text(); |
551 | chdir( current.latin1() ); | 570 | chdir( current.latin1() ); |
552 | currentDir.cd( current, TRUE); | 571 | currentDir.cd( current, TRUE); |
553 | populateList(); | 572 | populateList(); |
554 | update(); | 573 | update(); |
555 | } | 574 | } |
556 | 575 | ||
557 | void fileBrowser::fillCombo(const QString ¤tPath) { | 576 | void fileBrowser::fillCombo(const QString ¤tPath) { |
558 | 577 | ||
559 | dirPathCombo->lineEdit()->setText(currentPath); | 578 | dirPathCombo->lineEdit()->setText(currentPath); |
560 | 579 | ||
561 | if( dirPathStringList.grep(currentPath,TRUE).isEmpty() ) { | 580 | if( dirPathStringList.grep(currentPath,TRUE).isEmpty() ) { |
562 | dirPathCombo->clear(); | 581 | dirPathCombo->clear(); |
563 | dirPathStringList.prepend(currentPath ); | 582 | dirPathStringList.prepend(currentPath ); |
564 | dirPathCombo->insertStringList( dirPathStringList,-1); | 583 | dirPathCombo->insertStringList( dirPathStringList,-1); |
565 | } | 584 | } |
566 | } | 585 | } |
567 | 586 | ||
568 | 587 | ||
569 | InputDialog::InputDialog( QWidget* parent, const char* name, bool modal, WFlags fl ) | 588 | InputDialog::InputDialog( QWidget* parent, const char* name, bool modal, WFlags fl ) |
570 | : QDialog( parent, name, modal, fl ) | 589 | : QDialog( parent, name, modal, fl ) |
571 | { | 590 | { |
572 | if ( !name ) | 591 | if ( !name ) |
573 | setName( "InputDialog" ); | 592 | setName( "InputDialog" ); |
574 | resize( 234, 50 ); | 593 | resize( 234, 50 ); |
575 | setMaximumSize( QSize( 240, 50 ) ); | 594 | setMaximumSize( QSize( 240, 50 ) ); |
576 | setCaption( tr(name ) ); | 595 | setCaption( tr(name ) ); |
577 | 596 | ||
578 | LineEdit1 = new QLineEdit( this, "LineEdit1" ); | 597 | LineEdit1 = new QLineEdit( this, "LineEdit1" ); |
diff --git a/core/apps/textedit/fileBrowser.h b/core/apps/textedit/fileBrowser.h index 1138d80..339483f 100644 --- a/core/apps/textedit/fileBrowser.h +++ b/core/apps/textedit/fileBrowser.h | |||
@@ -1,120 +1,119 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | ** | 2 | ** |
3 | ** Created: Fri Dec 14 08:16:02 2001 | 3 | ** Created: Fri Dec 14 08:16:02 2001 |
4 | ** | 4 | ** |
5 | ** This file may be distributed and/or modified under the terms of the | 5 | ** This file may be distributed and/or modified under the terms of the |
6 | ** GNU General Public License version 2 as published by the Free Software | 6 | ** GNU General Public License version 2 as published by the Free Software |
7 | ** Foundation and appearing in the file LICENSE.GPL included in the | 7 | ** Foundation and appearing in the file LICENSE.GPL included in the |
8 | ** packaging of this file. | 8 | ** packaging of this file. |
9 | ** | 9 | ** |
10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
12 | ** | 12 | ** |
13 | copyright Sun 02-17-2002 22:28:23 L. J. Potter ljp@llornkcor.com | 13 | copyright Sun 02-17-2002 22:28:23 L. J. Potter ljp@llornkcor.com |
14 | ****************************************************************************/ | 14 | ****************************************************************************/ |
15 | #ifndef FILEBROWSER_H | 15 | #ifndef FILEBROWSER_H |
16 | #define FILEBROWSER_H | 16 | #define FILEBROWSER_H |
17 | 17 | ||
18 | //#include <qvariant.h> | 18 | //#include <qvariant.h> |
19 | #include <qdialog.h> | 19 | #include <qdialog.h> |
20 | #include <qfile.h> | 20 | #include <qfile.h> |
21 | #include <qdir.h> | 21 | #include <qdir.h> |
22 | #include <qstringlist.h> | 22 | #include <qstringlist.h> |
23 | #include <qlabel.h> | 23 | #include <qlabel.h> |
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qdict.h> | 25 | #include <qdict.h> |
26 | 26 | ||
27 | #include <qpe/filemanager.h> | 27 | #include <qpe/filemanager.h> |
28 | 28 | ||
29 | #include <qvariant.h> | 29 | #include <qvariant.h> |
30 | #include <qdialog.h> | 30 | #include <qdialog.h> |
31 | class QLineEdit; | 31 | class QLineEdit; |
32 | 32 | ||
33 | class QVBoxLayout; | 33 | class QVBoxLayout; |
34 | class QHBoxLayout; | 34 | class QHBoxLayout; |
35 | class QGridLayout; | 35 | class QGridLayout; |
36 | class QListView; | 36 | class QListView; |
37 | class QListViewItem; | 37 | class QListViewItem; |
38 | class QPushButton; | 38 | class QPushButton; |
39 | class QComboBox; | 39 | class QComboBox; |
40 | class QWidgetStack; | 40 | class QWidgetStack; |
41 | class FileSelector; | 41 | class FileSelector; |
42 | class QPoint; | 42 | class QPoint; |
43 | class MenuButton; | 43 | class MenuButton; |
44 | class QRegExp; | 44 | class QRegExp; |
45 | 45 | ||
46 | 46 | ||
47 | class fileBrowser : public QDialog | 47 | class fileBrowser : public QDialog |
48 | { | 48 | { |
49 | Q_OBJECT | 49 | Q_OBJECT |
50 | 50 | ||
51 | public: | 51 | public: |
52 | fileBrowser( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ,const QString filter=0); | 52 | fileBrowser( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ,const QString filter=0); |
53 | ~fileBrowser(); | 53 | ~fileBrowser(); |
54 | 54 | ||
55 | QString selectedFileName; | 55 | QString selectedFileName; |
56 | QFile file; | 56 | QFile file; |
57 | QStringList fileList; | 57 | QStringList fileList; |
58 | QComboBox *SelectionCombo; | 58 | QComboBox *SelectionCombo; |
59 | public slots: | 59 | public slots: |
60 | void setFileView( int ); | 60 | void setFileView( int ); |
61 | void setMimeType(const QString &); | ||
62 | 61 | ||
63 | private: | 62 | private: |
64 | // QDict<void> mimes; | 63 | // QDict<void> mimes; |
65 | QPushButton *buttonOk, *buttonCancel, *homeButton, *docButton, *hideButton, *cdUpButton; | 64 | QPushButton *buttonOk, *buttonCancel, *homeButton, *docButton, *hideButton, *cdUpButton; |
66 | QListView* ListView; | 65 | QListView* ListView; |
67 | QLabel *dirLabel; | 66 | QLabel *dirLabel; |
68 | QString filterStr, mimeType; | 67 | QString filterStr, mimeType; |
69 | QDir currentDir; | 68 | QDir currentDir; |
70 | QStringList dirPathStringList; | 69 | QStringList dirPathStringList, mimetypes; |
71 | QListViewItem * item; | 70 | QListViewItem * item; |
72 | QComboBox *dirPathCombo; | 71 | QComboBox *dirPathCombo; |
73 | MenuButton *typemb; | 72 | MenuButton *typemb; |
74 | QWidgetStack *FileStack; | 73 | QWidgetStack *FileStack; |
75 | FileSelector *fileSelector; | 74 | FileSelector *fileSelector; |
76 | QRegExp tf; | 75 | QRegExp tf; |
77 | QStringList getMimeTypes(); | 76 | QStringList getMimeTypes(); |
78 | void fillCombo( const QString&); | 77 | void fillCombo( const QString&); |
79 | 78 | ||
80 | private slots: | 79 | private slots: |
81 | void populateList(); | 80 | void populateList(); |
82 | void homeButtonPushed(); | 81 | void homeButtonPushed(); |
83 | void docButtonPushed(); | 82 | void docButtonPushed(); |
84 | void ListPressed( int, QListViewItem *, const QPoint&, int); | 83 | void ListPressed( int, QListViewItem *, const QPoint&, int); |
85 | void showListMenu(QListViewItem*); | 84 | void showListMenu(QListViewItem*); |
86 | void doCd(); | 85 | void doCd(); |
87 | void makDir(); | 86 | void makDir(); |
88 | void localRename(); | 87 | void localRename(); |
89 | void localDelete(); | 88 | void localDelete(); |
90 | void receive( const QCString &msg, const QByteArray &data ); | 89 | void receive( const QCString &msg, const QByteArray &data ); |
91 | void dirPathComboActivated( const QString & ); | 90 | void dirPathComboActivated( const QString & ); |
92 | void upDir(); | 91 | void upDir(); |
93 | void listClicked( QListViewItem * ); | 92 | void listClicked( QListViewItem * ); |
94 | void selectionChanged( const QString & ); | 93 | void selectionChanged( const QString & ); |
95 | void OnOK(); | 94 | void OnOK(); |
96 | void docOpen( const DocLnk & ); | 95 | void docOpen( const DocLnk & ); |
97 | void updateMimeTypeMenu(); | 96 | void updateMimeTypeMenu(); |
98 | void showType(const QString &); | 97 | void showType(const QString &); |
99 | void dirPathEditPressed(); | 98 | void dirPathEditPressed(); |
100 | 99 | ||
101 | protected slots: | 100 | protected slots: |
102 | 101 | ||
103 | protected: | 102 | protected: |
104 | 103 | ||
105 | }; | 104 | }; |
106 | 105 | ||
107 | 106 | ||
108 | class InputDialog : public QDialog | 107 | class InputDialog : public QDialog |
109 | { | 108 | { |
110 | Q_OBJECT | 109 | Q_OBJECT |
111 | 110 | ||
112 | public: | 111 | public: |
113 | InputDialog( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); | 112 | InputDialog( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); |
114 | ~InputDialog(); | 113 | ~InputDialog(); |
115 | QString inputText; | 114 | QString inputText; |
116 | QLineEdit* LineEdit1; | 115 | QLineEdit* LineEdit1; |
117 | 116 | ||
118 | }; | 117 | }; |
119 | 118 | ||
120 | #endif // FILEBROWSER_H | 119 | #endif // FILEBROWSER_H |