summaryrefslogtreecommitdiff
path: root/noncore
authorllornkcor <llornkcor>2002-02-24 17:05:29 (UTC)
committer llornkcor <llornkcor>2002-02-24 17:05:29 (UTC)
commitf39b6cfe0cccca9dac39b4b15cfe076426d5a4c5 (patch) (unidiff)
treee0cd32c7d9d5673ca0ef317a52f1ce9cae1957c4 /noncore
parent3008905fb88af28835417f722642d93bd1417f69 (diff)
downloadopie-f39b6cfe0cccca9dac39b4b15cfe076426d5a4c5.zip
opie-f39b6cfe0cccca9dac39b4b15cfe076426d5a4c5.tar.gz
opie-f39b6cfe0cccca9dac39b4b15cfe076426d5a4c5.tar.bz2
changed how view as text was being executed
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/filebrowser/filebrowser.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/noncore/unsupported/filebrowser/filebrowser.cpp b/noncore/unsupported/filebrowser/filebrowser.cpp
index eaf5eeb..10dff07 100644
--- a/noncore/unsupported/filebrowser/filebrowser.cpp
+++ b/noncore/unsupported/filebrowser/filebrowser.cpp
@@ -1,125 +1,127 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "inlineedit.h" 21#include "inlineedit.h"
22#include "filebrowser.h" 22#include "filebrowser.h"
23#include "filePermissions.h" 23#include "filePermissions.h"
24#include <qpe/resource.h> 24#include <qpe/resource.h>
25#include <qpe/global.h> 25#include <qpe/global.h>
26#include <qpe/mimetype.h> 26#include <qpe/mimetype.h>
27#include <qpe/applnk.h> 27#include <qpe/applnk.h>
28 28
29#include <qcopchannel_qws.h> 29#include <qcopchannel_qws.h>
30#include <qcopenvelope_qws.h>
31
30#include <qmessagebox.h> 32#include <qmessagebox.h>
31#include <qdir.h> 33#include <qdir.h>
32#include <qregexp.h> 34#include <qregexp.h>
33#include <qheader.h> 35#include <qheader.h>
34#include <qpe/qpetoolbar.h> 36#include <qpe/qpetoolbar.h>
35#include <qpopupmenu.h> 37#include <qpopupmenu.h>
36#include <qpe/qpemenubar.h> 38#include <qpe/qpemenubar.h>
37#include <qaction.h> 39#include <qaction.h>
38#include <qstringlist.h> 40#include <qstringlist.h>
39#include <qcursor.h> 41#include <qcursor.h>
40#include <qmultilineedit.h> 42#include <qmultilineedit.h>
41#include <qfont.h> 43#include <qfont.h>
42 44
43#include <unistd.h> 45#include <unistd.h>
44#include <stdlib.h> 46#include <stdlib.h>
45#include <sys/stat.h> 47#include <sys/stat.h>
46 48
47// 49//
48// FileItem 50// FileItem
49// 51//
50FileItem::FileItem( QListView * parent, const QFileInfo & fi ) 52FileItem::FileItem( QListView * parent, const QFileInfo & fi )
51 : QListViewItem( parent ), 53 : QListViewItem( parent ),
52 fileInfo( fi ) 54 fileInfo( fi )
53{ 55{
54 QDate d = fi.lastModified().date(); 56 QDate d = fi.lastModified().date();
55 57
56 setText( 0, fi.fileName() ); 58 setText( 0, fi.fileName() );
57 setText( 1, sizeString( fi.size() ) + " " ); 59 setText( 1, sizeString( fi.size() ) + " " );
58 setText( 2, QString().sprintf("%4d-%02d-%02d",d.year(), d.month(), d.day() ) ); 60 setText( 2, QString().sprintf("%4d-%02d-%02d",d.year(), d.month(), d.day() ) );
59 61
60 MimeType mt(fi.filePath()); 62 MimeType mt(fi.filePath());
61 63
62 if( fi.isDir() ) 64 if( fi.isDir() )
63 setText( 3, "directory" ); 65 setText( 3, "directory" );
64 else if( isLib() ) 66 else if( isLib() )
65 setText( 3, "library" ); 67 setText( 3, "library" );
66 else 68 else
67 setText( 3, mt.description() ); 69 setText( 3, mt.description() );
68 70
69 QPixmap pm; 71 QPixmap pm;
70 if( fi.isDir() ){ 72 if( fi.isDir() ){
71 if( !QDir( fi.filePath() ).isReadable() ) 73 if( !QDir( fi.filePath() ).isReadable() )
72 pm = Resource::loadPixmap( "lockedfolder" ); 74 pm = Resource::loadPixmap( "lockedfolder" );
73 else 75 else
74 pm = Resource::loadPixmap( "folder" ); 76 pm = Resource::loadPixmap( "folder" );
75 } 77 }
76 else if( !fi.isReadable() ) 78 else if( !fi.isReadable() )
77 pm = Resource::loadPixmap( "locked" ); 79 pm = Resource::loadPixmap( "locked" );
78 else if( isLib() ) 80 else if( isLib() )
79 pm = Resource::loadPixmap( "library" ); 81 pm = Resource::loadPixmap( "library" );
80 else 82 else
81 pm = mt.pixmap(); 83 pm = mt.pixmap();
82 if ( pm.isNull() ) 84 if ( pm.isNull() )
83 pm = Resource::loadPixmap("UnknownDocument-14"); 85 pm = Resource::loadPixmap("UnknownDocument-14");
84 setPixmap(0,pm); 86 setPixmap(0,pm);
85} 87}
86 88
87QString FileItem::sizeString( unsigned int s ) 89QString FileItem::sizeString( unsigned int s )
88{ 90{
89 double size = s; 91 double size = s;
90 92
91 if ( size > 1024 * 1024 * 1024 ) 93 if ( size > 1024 * 1024 * 1024 )
92 return QString().sprintf( "%.1f", size / ( 1024 * 1024 * 1024 ) ) + "G"; 94 return QString().sprintf( "%.1f", size / ( 1024 * 1024 * 1024 ) ) + "G";
93 else if ( size > 1024 * 1024 ) 95 else if ( size > 1024 * 1024 )
94 return QString().sprintf( "%.1f", size / ( 1024 * 1024 ) ) + "M"; 96 return QString().sprintf( "%.1f", size / ( 1024 * 1024 ) ) + "M";
95 else if ( size > 1024 ) 97 else if ( size > 1024 )
96 return QString().sprintf( "%.1f", size / ( 1024 ) ) + "K"; 98 return QString().sprintf( "%.1f", size / ( 1024 ) ) + "K";
97 else 99 else
98 return QString::number( size ) + "B"; 100 return QString::number( size ) + "B";
99} 101}
100 102
101QString FileItem::key( int column, bool ascending ) const 103QString FileItem::key( int column, bool ascending ) const
102{ 104{
103 QString tmp; 105 QString tmp;
104 106
105 ascending = ascending; 107 ascending = ascending;
106 108
107 if( (column == 0) && fileInfo.isDir() ){ // Sort by name 109 if( (column == 0) && fileInfo.isDir() ){ // Sort by name
108 // We want the directories to appear at the top of the list 110 // We want the directories to appear at the top of the list
109 tmp = (char) 0; 111 tmp = (char) 0;
110 return (tmp + text( column ).lower()); 112 return (tmp + text( column ).lower());
111 } 113 }
112 else if( column == 2 ) { // Sort by date 114 else if( column == 2 ) { // Sort by date
113 QDateTime epoch( QDate( 1980, 1, 1 ) ); 115 QDateTime epoch( QDate( 1980, 1, 1 ) );
114 tmp.sprintf( "%08d", epoch.secsTo( fileInfo.lastModified() ) ); 116 tmp.sprintf( "%08d", epoch.secsTo( fileInfo.lastModified() ) );
115 return tmp; 117 return tmp;
116 } 118 }
117 else if( column == 1 ) { // Sort by size 119 else if( column == 1 ) { // Sort by size
118 return tmp.sprintf( "%08d", fileInfo.size() ); 120 return tmp.sprintf( "%08d", fileInfo.size() );
119 } 121 }
120 122
121 return text( column ).lower(); 123 return text( column ).lower();
122} 124}
123 125
124bool FileItem::isLib() 126bool FileItem::isLib()
125{ 127{
@@ -453,193 +455,195 @@ void FileView::cut()
453 cmd = "/bin/mv -f \"" + (*it) +"\" " + "\"" + dest + "\""; 455 cmd = "/bin/mv -f \"" + (*it) +"\" " + "\"" + dest + "\"";
454 err = system( (const char *) cmd ); 456 err = system( (const char *) cmd );
455 457
456 if ( err != 0 ) { 458 if ( err != 0 ) {
457 QMessageBox::warning( this, tr("Cut file"), tr("Cut failed!"), 459 QMessageBox::warning( this, tr("Cut file"), tr("Cut failed!"),
458 tr("Ok") ); 460 tr("Ok") );
459 break; 461 break;
460 } else { 462 } else {
461 updateDir(); 463 updateDir();
462 QListViewItem * im = firstChild(); 464 QListViewItem * im = firstChild();
463 basename = dest.mid( dest.findRev("/") + 1, dest.length() ); 465 basename = dest.mid( dest.findRev("/") + 1, dest.length() );
464 466
465 while( im ){ 467 while( im ){
466 if( im->text(0) == basename ){ 468 if( im->text(0) == basename ){
467 setCurrentItem( im ); 469 setCurrentItem( im );
468 ensureItemVisible( im ); 470 ensureItemVisible( im );
469 break; 471 break;
470 } 472 }
471 im = im->nextSibling(); 473 im = im->nextSibling();
472 } 474 }
473 } 475 }
474 } 476 }
475 477
476 // update the filelist to point to tmp dir so paste works nicely 478 // update the filelist to point to tmp dir so paste works nicely
477 flist = newflist; 479 flist = newflist;
478} 480}
479 481
480void FileView::del() 482void FileView::del()
481{ 483{
482 FileItem * i; 484 FileItem * i;
483 QStringList fl; 485 QStringList fl;
484 QString cmd; 486 QString cmd;
485 int err; 487 int err;
486 488
487 if((i = (FileItem *) firstChild()) == 0) return; 489 if((i = (FileItem *) firstChild()) == 0) return;
488 490
489 while( i ){ 491 while( i ){
490 if( i->isSelected() ){ 492 if( i->isSelected() ){
491 fl += i->getFilePath(); 493 fl += i->getFilePath();
492 } 494 }
493 i = (FileItem *) i->nextSibling(); 495 i = (FileItem *) i->nextSibling();
494 } 496 }
495 if( fl.count() < 1 ) return; 497 if( fl.count() < 1 ) return;
496 498
497 if( QMessageBox::warning( this, tr("Delete"), tr("Are you sure?"), 499 if( QMessageBox::warning( this, tr("Delete"), tr("Are you sure?"),
498 tr("Yes"), tr("No") ) == 0) 500 tr("Yes"), tr("No") ) == 0)
499 { 501 {
500 // 502 //
501 // Dependant upon the "rm" command - will probably have to be replaced 503 // Dependant upon the "rm" command - will probably have to be replaced
502 // 504 //
503 for ( QStringList::Iterator it = fl.begin(); it != fl.end(); ++it ) { 505 for ( QStringList::Iterator it = fl.begin(); it != fl.end(); ++it ) {
504 cmd = "/bin/rm -rf \"" + (*it) + "\""; 506 cmd = "/bin/rm -rf \"" + (*it) + "\"";
505 err = system( (const char *) cmd ); 507 err = system( (const char *) cmd );
506 if ( err != 0 ) { 508 if ( err != 0 ) {
507 QMessageBox::warning( this, tr("Delete"), tr("Delete failed!"), 509 QMessageBox::warning( this, tr("Delete"), tr("Delete failed!"),
508 tr("Ok") ); 510 tr("Ok") );
509 break; 511 break;
510 } 512 }
511 } 513 }
512 updateDir(); 514 updateDir();
513 } 515 }
514} 516}
515 517
516void FileView::newFolder() 518void FileView::newFolder()
517{ 519{
518 int t = 1; 520 int t = 1;
519 FileItem * i; 521 FileItem * i;
520 QString nd = currentDir + "/NewFolder"; 522 QString nd = currentDir + "/NewFolder";
521 523
522 while( QFile( nd ).exists() ){ 524 while( QFile( nd ).exists() ){
523 nd.sprintf( "%s/NewFolder (%d)", (const char *) currentDir, t++ ); 525 nd.sprintf( "%s/NewFolder (%d)", (const char *) currentDir, t++ );
524 } 526 }
525 527
526 if( mkdir( (const char *) nd, 0777 ) != 0){ 528 if( mkdir( (const char *) nd, 0777 ) != 0){
527 QMessageBox::warning( this, tr( "New folder" ), 529 QMessageBox::warning( this, tr( "New folder" ),
528 tr( "Folder creation failed!" ), 530 tr( "Folder creation failed!" ),
529 tr( "Ok" ) ); 531 tr( "Ok" ) );
530 return; 532 return;
531 } 533 }
532 updateDir(); 534 updateDir();
533 535
534 if((i = (FileItem *) firstChild()) == 0) return; 536 if((i = (FileItem *) firstChild()) == 0) return;
535 537
536 while( i ){ 538 while( i ){
537 if( i->isDir() && ( i->getFilePath() == nd ) ){ 539 if( i->isDir() && ( i->getFilePath() == nd ) ){
538 setCurrentItem( i ); 540 setCurrentItem( i );
539 rename(); 541 rename();
540 break; 542 break;
541 } 543 }
542 i = (FileItem *) i->nextSibling(); 544 i = (FileItem *) i->nextSibling();
543 } 545 }
544} 546}
545 547
546void FileView::viewAsText() 548void FileView::viewAsText()
547{ 549{
548 FileItem * i = (FileItem *) currentItem(); 550 FileItem * i = (FileItem *) currentItem();
549 Global::execute( "textedit -f ", i->getFilePath() ); 551 QCopEnvelope e("QPE/Application/textedit","setDocument(QString)");
552 e << i->getFilePath();
553// Global::execute( "textedit -f ", i->getFilePath() );
550} 554}
551 555
552void FileView::itemClicked( QListViewItem * i) 556void FileView::itemClicked( QListViewItem * i)
553{ 557{
554 FileItem * t = (FileItem *) i; 558 FileItem * t = (FileItem *) i;
555 559
556 if( t == NULL ) return; 560 if( t == NULL ) return;
557 if( t->isDir() ){ 561 if( t->isDir() ){
558 setDir( t->getFilePath() ); 562 setDir( t->getFilePath() );
559 } 563 }
560} 564}
561 565
562void FileView::itemDblClicked( QListViewItem * i) 566void FileView::itemDblClicked( QListViewItem * i)
563{ 567{
564 FileItem * t = (FileItem *) i; 568 FileItem * t = (FileItem *) i;
565 569
566 if(t == NULL) return; 570 if(t == NULL) return;
567 if(t->launch() == -1){ 571 if(t->launch() == -1){
568 QMessageBox::warning( this, tr( "Launch Application" ), 572 QMessageBox::warning( this, tr( "Launch Application" ),
569 tr( "Launch failed!" ), tr( "Ok" ) ); 573 tr( "Launch failed!" ), tr( "Ok" ) );
570 } 574 }
571} 575}
572 576
573void FileView::parentDir() 577void FileView::parentDir()
574{ 578{
575 setDir( currentDir + "./.." ); 579 setDir( currentDir + "./.." );
576} 580}
577 581
578void FileView::lastDir() 582void FileView::lastDir()
579{ 583{
580 if( dirHistory.count() == 0 ) return; 584 if( dirHistory.count() == 0 ) return;
581 585
582 QString newDir = dirHistory.last(); 586 QString newDir = dirHistory.last();
583 dirHistory.remove( dirHistory.last() ); 587 dirHistory.remove( dirHistory.last() );
584 generateDir( newDir ); 588 generateDir( newDir );
585} 589}
586 590
587void FileView::contentsMousePressEvent( QMouseEvent * e ) 591void FileView::contentsMousePressEvent( QMouseEvent * e )
588{ 592{
589 QListView::contentsMousePressEvent( e ); 593 QListView::contentsMousePressEvent( e );
590 menuTimer.start( 750, TRUE ); 594 menuTimer.start( 750, TRUE );
591} 595}
592 596
593void FileView::contentsMouseReleaseEvent( QMouseEvent * e ) 597void FileView::contentsMouseReleaseEvent( QMouseEvent * e )
594{ 598{
595 QListView::contentsMouseReleaseEvent( e ); 599 QListView::contentsMouseReleaseEvent( e );
596 menuTimer.stop(); 600 menuTimer.stop();
597} 601}
598 602
599void FileView::cancelMenuTimer() 603void FileView::cancelMenuTimer()
600{ 604{
601 if( menuTimer.isActive() ) 605 if( menuTimer.isActive() )
602 menuTimer.stop(); 606 menuTimer.stop();
603} 607}
604 608
605void FileView::addToDocuments() 609void FileView::addToDocuments()
606{ 610{
607 FileItem * i = (FileItem *) currentItem(); 611 FileItem * i = (FileItem *) currentItem();
608 DocLnk f; 612 DocLnk f;
609 QString n = i->text(0); 613 QString n = i->text(0);
610 n.replace(QRegExp("\\..*"),""); 614 n.replace(QRegExp("\\..*"),"");
611 f.setName( n ); 615 f.setName( n );
612 f.setFile( i->getFilePath() ); 616 f.setFile( i->getFilePath() );
613 f.writeLink(); 617 f.writeLink();
614} 618}
615 619
616void FileView::run() 620void FileView::run()
617{ 621{
618 FileItem * i = (FileItem *) currentItem(); 622 FileItem * i = (FileItem *) currentItem();
619 i->launch(); 623 i->launch();
620} 624}
621 625
622void FileView::showFileMenu() 626void FileView::showFileMenu()
623{ 627{
624 FileItem * i = (FileItem *) currentItem(); 628 FileItem * i = (FileItem *) currentItem();
625 if ( !i ) 629 if ( !i )
626 return; 630 return;
627 631
628 QPopupMenu * m = new QPopupMenu( this ); 632 QPopupMenu * m = new QPopupMenu( this );
629 633
630 if ( !i->isDir() ) { 634 if ( !i->isDir() ) {
631 m->insertItem( tr( "Add to Documents" ), this, SLOT( addToDocuments() ) ); 635 m->insertItem( tr( "Add to Documents" ), this, SLOT( addToDocuments() ) );
632 m->insertSeparator(); 636 m->insertSeparator();
633 } 637 }
634 638
635 MimeType mt(i->getFilePath()); 639 MimeType mt(i->getFilePath());
636 const AppLnk* app = mt.application(); 640 const AppLnk* app = mt.application();
637 641
638 if ( !i->isDir() ) { 642 if ( !i->isDir() ) {
639 if ( app ) 643 if ( app )
640 m->insertItem( app->pixmap(), tr( "Open in " + app->name() ), this, SLOT( run() ) ); 644 m->insertItem( app->pixmap(), tr( "Open in " + app->name() ), this, SLOT( run() ) );
641 else if( i->isExecutable() ) 645 else if( i->isExecutable() )
642 m->insertItem( Resource::loadPixmap( i->text( 0 ) ), tr( "Run" ), this, SLOT( run() ) ); 646 m->insertItem( Resource::loadPixmap( i->text( 0 ) ), tr( "Run" ), this, SLOT( run() ) );
643 647
644 m->insertItem( Resource::loadPixmap( "txt" ), tr( "View as text" ), 648 m->insertItem( Resource::loadPixmap( "txt" ), tr( "View as text" ),
645 this, SLOT( viewAsText() ) ); 649 this, SLOT( viewAsText() ) );