00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdio.h>
00020 #include <stdlib.h>
00021
00022 #include "qlineedit.h"
00023 #include "qtoolbutton.h"
00024
00025 #include "scqtfileedit.h"
00026
00027 #include <qpe/qpeapplication.h>
00028
00029
00030
00031
00032 static const char* const file_xpm[]={
00033 "16 16 5 1",
00034 ". c #7f7f7f",
00035 "# c None",
00036 "c c #000000",
00037 "b c #bfbfbf",
00038 "a c #ffffff",
00039 "################",
00040 "..........######",
00041 ".aaaaaaaab.#####",
00042 ".aaaaaaaaba.####",
00043 ".aaaaaaaacccc###",
00044 ".aaaaaaaaaabc###",
00045 ".aaaaaaaaaabc###",
00046 ".aaaaaaaaaabc###",
00047 ".aaaaaaaaaabc###",
00048 ".aaaaaaaaaabc###",
00049 ".aaaaaaaaaabc###",
00050 ".aaaaaaaaaabc###",
00051 ".aaaaaaaaaabc###",
00052 ".aaaaaaaaaabc###",
00053 ".bbbbbbbbbbbc###",
00054 "ccccccccccccc###"};
00055
00056
00057 static const char * const link_file_xpm[]={
00058 "16 16 10 1",
00059 "h c #808080",
00060 "g c #a0a0a0",
00061 "d c #c3c3c3",
00062 ". c #7f7f7f",
00063 "c c #000000",
00064 "b c #bfbfbf",
00065 "f c #303030",
00066 "e c #585858",
00067 "a c #ffffff",
00068 "# c None",
00069 "################",
00070 "..........######",
00071 ".aaaaaaaab.#####",
00072 ".aaaaaaaaba.####",
00073 ".aaaaaaaacccc###",
00074 ".aaaaaaaaaabc###",
00075 ".aaaaaaaaaabc###",
00076 ".aaaaaaaaaadc###",
00077 ".aaaaaaaaaadc###",
00078 ".aaaacccccccc###",
00079 ".aaaacaaaaaac###",
00080 ".aaaacaeaeaac###",
00081 ".aaaacaefcfac###",
00082 ".aaaacaagchac###",
00083 ".ddddcaaahaac###",
00084 "ccccccccccccc###"};
00085
00086
00087 static const char * const closed_xpm[]={
00088 "16 16 6 1",
00089 ". c None",
00090 "b c #ffff00",
00091 "d c #000000",
00092 "* c #999999",
00093 "a c #cccccc",
00094 "c c #ffffff",
00095 "................",
00096 "................",
00097 "..*****.........",
00098 ".*ababa*........",
00099 "*abababa******..",
00100 "*cccccccccccc*d.",
00101 "*cbababababab*d.",
00102 "*cabababababa*d.",
00103 "*cbababababab*d.",
00104 "*cabababababa*d.",
00105 "*cbababababab*d.",
00106 "*cabababababa*d.",
00107 "*cbababababab*d.",
00108 "**************d.",
00109 ".dddddddddddddd.",
00110 "................"};
00111
00112
00113 static const char* const cdtoparent_xpm[]={
00114 "15 13 3 1",
00115 ". c None",
00116 "* c #000000",
00117 "a c #ffff99",
00118 "..*****........",
00119 ".*aaaaa*.......",
00120 "***************",
00121 "*aaaaaaaaaaaaa*",
00122 "*aaaa*aaaaaaaa*",
00123 "*aaa***aaaaaaa*",
00124 "*aa*****aaaaaa*",
00125 "*aaaa*aaaaaaaa*",
00126 "*aaaa*aaaaaaaa*",
00127 "*aaaa******aaa*",
00128 "*aaaaaaaaaaaaa*",
00129 "*aaaaaaaaaaaaa*",
00130 "***************"};
00131
00132 ScQtFileEditDlg::ScQtFileEditDlg( QWidget *parent, const char *name,
00133 const QString &path, const QString &filter )
00134 : ScQtFileDlg( parent, name, TRUE ), QDir( path, filter )
00135 {
00136
00137
00138 #ifdef DEBUGFILEEDIT
00139 printf ("\nScQtFileEditDlg:: constructor name=%s", name );
00140 printf ("\n path=%s", (const char *)path );
00141 printf ("\n filter=%s", (const char *)filter );
00142 printf ("\n parent=%p", parent );
00143 fflush(stdout);
00144 #endif
00145
00146 bpath = path;
00147 bfilter = filter;
00148 exflag = false;
00149
00150 ListView->setAllColumnsShowFocus( TRUE );
00151 ListView->setColumnAlignment( 1, Qt::AlignRight );
00152
00153 fileIcon = new QPixmap( (const char **)file_xpm);
00154 dirIcon = new QPixmap( (const char **)closed_xpm);
00155 linkIcon = new QPixmap( (const char **)link_file_xpm);
00156 cdToParentIcon = new QPixmap( (const char **)cdtoparent_xpm);
00157
00158 #ifdef QWS
00159 QPEApplication::execDialog( this );
00160 #endif
00161
00162 mkdirflag = false;
00163 MkDirButton->setEnabled( false );
00164
00165 initDirCombo( bpath );
00166 initTypeCombo( bfilter );
00167
00168 dirstr = tr("dir");
00169 filestr = tr("file");
00170 linkstr = tr("link");
00171
00172 rFlag = false;
00173
00174 showTimer.stop();
00175 connect( &showTimer, SIGNAL(timeout()), SLOT( slotShowDir() ) );
00176
00177 fmode = QDir::All;
00178 fnfilter = false;
00179 fsorting = false;
00180
00181 }
00182
00183 ScQtFileEditDlg::~ScQtFileEditDlg()
00184 {
00185 #ifdef DEBUGFILEEDIT
00186 printf ("\nScQtFileEditDlg::destructor called" );
00187 fflush(stdout);
00188 #endif
00189
00190 if ( fileIcon != NULL )
00191 {
00192 delete fileIcon;
00193 fileIcon = NULL;
00194 }
00195 if ( dirIcon != NULL )
00196 {
00197 delete dirIcon;
00198 dirIcon = NULL;
00199 }
00200 if ( linkIcon != NULL )
00201 {
00202 delete linkIcon;
00203 linkIcon = NULL;
00204 }
00205 if ( cdToParentIcon != NULL )
00206 {
00207 delete cdToParentIcon;
00208 cdToParentIcon = NULL;
00209 }
00210 }
00211
00212 void ScQtFileEditDlg::readIt( )
00213 {
00214 qfil = readDir( bpath, bfilter );
00215 slotShowDir( );
00216 }
00217
00218 void ScQtFileEditDlg::setAutoExtension( bool ex )
00219 {
00220 exflag = ex;
00221 }
00222
00223
00224 int ScQtFileEditDlg::checkComboEntryExists( QComboBox *com, const QString &str )
00225 {
00226 int i;
00227
00228 if ( com )
00229 {
00230 for ( i = 0; i < com->count(); i++ )
00231 {
00232 if ( com->text( i ) == str )
00233 {
00234 com->setCurrentItem( i );
00235 return( 1 );
00236 }
00237 }
00238 }
00239
00240 return( 0 );
00241 }
00242
00243
00244 void ScQtFileEditDlg::initDirCombo( const QString &str )
00245 {
00246 DirComboBox->clear();
00247 DirComboBox->insertItem( "/" );
00248 if ( str.isEmpty() )
00249 return;
00250 DirComboBox->insertItem( str, -1 );
00251 }
00252
00253 void ScQtFileEditDlg::initTypeCombo( const QString &str )
00254 {
00255 TypeComboBox->clear();
00256 TypeComboBox->insertItem( "*" );
00257 if ( str.isEmpty() )
00258 return;
00259 TypeComboBox->insertItem( str, -1 );
00260 }
00261
00262 void ScQtFileEditDlg::insDirCombo( const QString &str )
00263 {
00264 if ( str.isEmpty() )
00265 return;
00266
00267 if ( !checkComboEntryExists( DirComboBox, str ) )
00268 {
00269 if ( DirComboBox->count() >= MAXDIRCOMBOCOUNT )
00270 {
00271
00272 DirComboBox->removeItem( 1 );
00273 }
00274
00275 DirComboBox->insertItem( str, -1 );
00276 DirComboBox->setCurrentItem( DirComboBox->count() - 1 );
00277 }
00278 }
00279
00280 void ScQtFileEditDlg::insTypeCombo( const QString &str )
00281 {
00282 if ( str.isEmpty() )
00283 return;
00284
00285 if ( !checkComboEntryExists( TypeComboBox, str ) )
00286 {
00287 if ( TypeComboBox->count() >= MAXTYPECOMBOCOUNT )
00288 {
00289
00290 TypeComboBox->removeItem( 1 );
00291 }
00292
00293 TypeComboBox->insertItem( str, -1 );
00294 TypeComboBox->setCurrentItem( TypeComboBox->count() - 1 );
00295 }
00296 }
00297
00298
00299 const QFileInfoList *ScQtFileEditDlg::readDir( const QString &path, const QString &filter )
00300 {
00301 static QString qpath, qfilter;
00302
00303 #ifdef DEBUGFILEEDIT
00304 printf ("\nScQtFileEditDlg::readDir called, path = %s", (const char *)path );
00305 printf ("\n filter = %s", (const char *)filter );
00306 fflush(stdout);
00307 #endif
00308
00309 rFlag = true;
00310
00311 if ( path.isEmpty() )
00312 qpath = "/";
00313 else
00314 qpath = path;
00315
00316 if ( filter.isEmpty() )
00317 qfilter = "*";
00318 else
00319 qfilter = filter;
00320
00321 insDirCombo( qpath );
00322 insTypeCombo( qfilter );
00323
00324 setFilter( fmode );
00325 if ( fsorting )
00326 setSorting( QDir::DirsFirst | QDir::Name );
00327 if ( fnfilter )
00328 setNameFilter( qfilter );
00329 setPath( qpath );
00330
00331 const QFileInfoList *dirlist = entryInfoList();
00332
00333 if ( !dirlist )
00334 {
00335 rFlag = false;
00336 return( 0 );
00337 }
00338
00339 rFlag = false;
00340
00341 return( dirlist );
00342 }
00343
00344 QString ScQtFileEditDlg::getResult( )
00345 {
00346 static QString qstr;
00347
00348 #ifdef DEBUGFILEEDIT
00349 printf ("\nScQtFileEditDlg::getResult called" );
00350 fflush(stdout);
00351 #endif
00352
00353 qstr = bpath + "/";
00354 qstr = qstr + filename;
00355 bpath = cleanDirPath( qstr );
00356
00357 return( bpath );
00358 }
00359
00360 QString ScQtFileEditDlg::getFileName( )
00361 {
00362 int a;
00363 static QString qstr;
00364
00365 #ifdef DEBUGFILEEDIT
00366 printf ("\nScQtFileEditDlg::getFileName called" );
00367 fflush(stdout);
00368 #endif
00369
00370 a = bpath.findRev( "/", -1, TRUE );
00371 if (a == -1)
00372 qstr = bpath;
00373 else
00374 qstr = bpath.right( bpath.length() - a - 1 );
00375
00376 return( qstr );
00377 }
00378
00379
00380
00381 void ScQtFileEditDlg::slotShowDir()
00382 {
00383 static QListViewItem *qlvitem;
00384 static QString ftypestr, fsizestr;
00385 static QFileInfo *fi;
00386
00387 if ( !qfil )
00388 return;
00389
00390 ListView->clear();
00391 QFileInfoListIterator it( *qfil );
00392 if ( !it )
00393 return;
00394
00395 while ( (fi=it.current()) )
00396 {
00397 if ( !fi )
00398 return;
00399
00400 if ( !fi->fileName().isNull() )
00401 {
00402 if ( fi->isDir() == TRUE )
00403 {
00404 ftypestr = dirstr;
00405 fsizestr = "" ;
00406 }
00407 else if ( fi->isSymLink() == TRUE )
00408 {
00409 ftypestr = linkstr;
00410 fsizestr = "" ;
00411 }
00412 else if ( fi->isFile() == TRUE )
00413 {
00414 ftypestr = filestr;
00415 fsizestr.sprintf( "%d", fi->size() );
00416 }
00417 else
00418 {
00419 printf( "something else\n" );
00420 fflush(stdout);
00421 }
00422
00423 if ( !(fi->fileName() == "." ) )
00424 {
00425 qlvitem = new QListViewItem ( ListView, fi->fileName(), fsizestr, ftypestr );
00426 if ( fi->fileName() == ".." )
00427 qlvitem->setPixmap( 0, *cdToParentIcon );
00428 else if ( fi->isDir() == TRUE )
00429 qlvitem->setPixmap( 0, *dirIcon );
00430 else if ( fi->isSymLink() == TRUE )
00431 qlvitem->setPixmap( 0, *linkIcon );
00432 else if ( fi->isFile() == TRUE )
00433 qlvitem->setPixmap( 0, *fileIcon );
00434 }
00435 }
00436 ++it;
00437 }
00438 }
00439
00440 void ScQtFileEditDlg::slotDirComboBoxChanged( int item )
00441 {
00442 if ( !rFlag )
00443 {
00444 bpath = DirComboBox->currentText( );
00445 qfil = readDir( bpath, bfilter );
00446 slotShowDir( );
00447 }
00448 }
00449
00450 void ScQtFileEditDlg::slotTypeComboBoxChanged( int item )
00451 {
00452 if ( !rFlag )
00453 {
00454 bfilter = TypeComboBox->currentText( );
00455 qfil = readDir( bpath, bfilter );
00456 slotShowDir( );
00457 }
00458 }
00459
00460 void ScQtFileEditDlg::slotFileTextChanged( const QString &txt )
00461 {
00462 filename = txt;
00463 }
00464
00465 void ScQtFileEditDlg::slotSelectionChanged( QListViewItem *item )
00466 {
00467 static QString qstr, rstr;
00468
00469 #ifdef DEBUGFILEEDIT
00470 printf ("\nScQtFileEditDlg::slotSelectionChanged called" );
00471 fflush(stdout);
00472 #endif
00473 if ( item )
00474 {
00475 if ( !item->text(2) )
00476 return;
00477
00478 if ( item->text(2) == dirstr )
00479 {
00480 if ( !rFlag )
00481 {
00482 rstr = bpath;
00483 qstr = bpath + "/";
00484 qstr = qstr + item->text(0);
00485 bpath = cleanDirPath( qstr );
00486 qfil = readDir( bpath, bfilter );
00487 if ( qfil == 0 )
00488 {
00489 bpath = rstr;
00490
00491 qfil = readDir( bpath, bfilter );
00492 }
00493 showTimer.start( 10, true );
00494 }
00495 }
00496 else if ( item->text(2) == filestr )
00497 {
00498 FNameLineEdit->setText( item->text(0) );
00499 filename = item->text(0);
00500 }
00501 }
00502 }
00503
00504
00505 void ScQtFileEditDlg::slotMkDir( )
00506 {
00507 QString qstr;
00508
00509 if ( !FNameLineEdit->text().isEmpty() )
00510 {
00511 qstr = bpath + "/";
00512 qstr = qstr + FNameLineEdit->text();
00513 mkdir( qstr, true );
00514 qfil = readDir( bpath, bfilter );
00515 FNameLineEdit->setText( "" );
00516 slotShowDir( );
00517 }
00518 }
00519
00520 void ScQtFileEditDlg::slotDoubleClicked( QListViewItem *item )
00521 {
00522 static QString qstr, rstr;
00523
00524 #ifdef DEBUGFILEEDIT
00525 printf ("\nScQtFileEditDlg::slotDoubleClicked called" );
00526 fflush(stdout);
00527 #endif
00528
00529 if ( item )
00530 {
00531 if ( item->text(2) == dirstr )
00532 {
00533 if ( !rFlag )
00534 {
00535 rstr = bpath;
00536 qstr = bpath + "/";
00537 qstr = qstr + item->text(0);
00538 bpath = cleanDirPath( qstr );
00539 qfil = readDir( bpath, bfilter );
00540 if ( qfil == 0 )
00541 {
00542 bpath = rstr;
00543
00544 qfil = readDir( bpath, bfilter );
00545 }
00546 showTimer.start( 10, TRUE );
00547 }
00548 }
00549 }
00550 }
00551
00552 void ScQtFileEditDlg::autoExtension( )
00553 {
00554 QString qstr;
00555 int len;
00556
00557 if ( exflag )
00558 {
00559 qstr = TypeComboBox->currentText( );
00560 if ( qstr != "*" )
00561 {
00562 len = qstr.findRev( ".", -1 );
00563 if ( len >= 0 )
00564 {
00565 qstr = qstr.right( qstr.length() - len );
00566 len = filename.findRev( qstr, -1 );
00567 if ( len < 0 )
00568 filename = filename + qstr;
00569 }
00570 }
00571 }
00572 }
00573
00574 void ScQtFileEditDlg::setMode( int mode )
00575 {
00576 fmode = mode;
00577 }
00578
00579 void ScQtFileEditDlg::setNFilter( bool ff )
00580 {
00581 fnfilter = ff;
00582 }
00583
00584 void ScQtFileEditDlg::setFSorting( bool ff )
00585 {
00586 fsorting = ff;
00587 }
00588
00589 void ScQtFileEditDlg::allowMkDir( bool mkdir )
00590 {
00591 mkdirflag = mkdir;
00592 MkDirButton->setEnabled( mkdir );
00593 }
00594
00595
00596 void ScQtFileEditDlg::slotOK( )
00597 {
00598 #ifdef DEBUGFILEEDIT
00599 printf ("\nScQtFileEditDlg::slotOK called" );
00600 fflush(stdout);
00601 #endif
00602 autoExtension();
00603
00604 accept();
00605 }
00606
00607 void ScQtFileEditDlg::slotCancel( )
00608 {
00609
00610 #ifdef DEBUGFILEEDIT
00611 printf ("\nScQtFileEditDlg::slotCancel called" );
00612 fflush(stdout);
00613 #endif
00614
00615 reject();
00616 }
00617
00618
00619
00620
00621 ScQtFileEdit::ScQtFileEdit( QWidget *parent, const char *name )
00622 {
00623 #ifdef DEBUGFILEEDIT
00624 printf ("\nScQtFileEdit constructor called");
00625 fflush(stdout);
00626 #endif
00627 }
00628
00629 ScQtFileEdit::~ScQtFileEdit()
00630 {
00631 #ifdef DEBUGFILEEDIT
00632 printf ("\nScQtFileEdit destructor called");
00633 fflush(stdout);
00634 #endif
00635 }
00636
00637 QString ScQtFileEdit::getOpenFileName( QWidget *parent, const char *name,
00638 const QString &path, const QString &filter )
00639 {
00640 static ScQtFileEditDlg *fd;
00641 static QString fname;
00642
00643 #ifdef DEBUGFILEEDIT
00644 printf ("\nScQtFileEdit::getOpenFileName name=%s", name );
00645 printf ("\n path=%s", (const char *)path );
00646 printf ("\n filter=%s", (const char *)filter );
00647 fflush(stdout);
00648 #endif
00649
00650 fd = new ScQtFileEditDlg( parent, name, path, filter );
00651 fd->setAutoExtension( false );
00652 fd->setMode( QDir::All|QDir::System );
00653 fd->setNFilter( true );
00654 fd->setFSorting( true );
00655 fd->readIt();
00656 fd->exec();
00657
00658 if ( fd->result() == QDialog::Accepted )
00659 fname = fd->getResult();
00660 else
00661 fname = "";
00662
00663 delete fd;
00664 return( fname );
00665 }
00666
00667 QString ScQtFileEdit::getSaveAsFileName( QWidget *parent, const char *name,
00668 const QString &path, const QString &filter )
00669 {
00670 static ScQtFileEditDlg *fd;
00671 static QString fname;
00672
00673 #ifdef DEBUGFILEEDIT
00674 printf ("\nScQtFileEdit::getSaveAsFileName name=%s", name );
00675 printf ("\n path=%s", (const char *)path );
00676 printf ("\n filter=%s", (const char *)filter );
00677 fflush(stdout);
00678 #endif
00679
00680 fd = new ScQtFileEditDlg( parent, name, path, filter );
00681 fd->allowMkDir( true );
00682 fd->setAutoExtension( true );
00683 fd->setNFilter( true );
00684 fd->setFSorting( true );
00685 fd->readIt();
00686 fd->exec();
00687
00688 if ( fd->result() == QDialog::Accepted )
00689 fname = fd->getResult();
00690 else
00691 fname = "";
00692
00693 delete fd;
00694 return( fname );
00695 }
00696
00697 QString ScQtFileEdit::getDirName( QWidget *parent, const char *name,
00698 const QString &path )
00699 {
00700 static ScQtFileEditDlg *fd;
00701 static QString fname;
00702
00703 #ifdef DEBUGFILEEDIT
00704 printf ("\nScQtFileEdit::getDirName name=%s", name );
00705 printf ("\n path=%s", (const char *)path );
00706 fflush(stdout);
00707 #endif
00708
00709 fd = new ScQtFileEditDlg( parent, name, path );
00710 fd->setMode( QDir::Dirs );
00711 fd->setNFilter( false );
00712 fd->setFSorting( true );
00713 fd->readIt();
00714 fd->exec();
00715
00716 if ( fd->result() == QDialog::Accepted )
00717 fname = fd->getResult();
00718 else
00719 fname = "";
00720
00721 delete fd;
00722 return( fname );
00723 }
00724
00725 QString ScQtFileEdit::mkDir( QWidget *parent, const char *name,
00726 const QString &path, const QString &filter )
00727 {
00728 static ScQtFileEditDlg *fd;
00729 static QString fname;
00730
00731 #ifdef DEBUGFILEEDIT
00732 printf ("\nScQtFileEdit::mkDir name=%s", name );
00733 printf ("\n basepath=%s", (const char *)path );
00734 printf ("\n filter=%s", (const char *)filter );
00735 fflush(stdout);
00736 #endif
00737
00738 fd = new ScQtFileEditDlg( parent, name, path, filter );
00739 fd->setAutoExtension( true );
00740 fd->allowMkDir( true );
00741 fd->setNFilter( false );
00742 fd->setFSorting( true );
00743 fd->readIt();
00744 fd->exec();
00745
00746 if ( fd->result() == QDialog::Accepted )
00747 fname = fd->getResult();
00748 else
00749 fname = "";
00750
00751 delete fd;
00752 return( fname );
00753 }
00754