00001 #include <qcombobox.h>
00002 #include <qdir.h>
00003 #include <qhbox.h>
00004 #include <qheader.h>
00005 #include <qlabel.h>
00006 #include <qlayout.h>
00007 #include <qlineedit.h>
00008 #include <qlistview.h>
00009 #include <qpopupmenu.h>
00010 #include <qwidgetstack.h>
00011 #include <qregexp.h>
00012 #include <qobjectlist.h>
00013
00014
00015 #define private public
00016 #include <qpe/fileselector.h>
00017 #undef private
00018
00019 #include <qpe/qpeapplication.h>
00020 #include <qpe/mimetype.h>
00021 #include <qpe/resource.h>
00022 #include <qpe/storage.h>
00023
00024 #include "ofileselector_p.h"
00025 #include "ofileselector.h"
00026
00027
00028
00029 OFileViewInterface::OFileViewInterface( OFileSelector* selector )
00030 : m_selector( selector ) {
00031 }
00032 OFileViewInterface::~OFileViewInterface() {
00033 }
00034 QString OFileViewInterface::name()const{
00035 return m_name;
00036 }
00037 void OFileViewInterface::setName( const QString& name ) {
00038 m_name = name;
00039 }
00040 OFileSelector* OFileViewInterface::selector()const {
00041 return m_selector;
00042 }
00043 DocLnk OFileViewInterface::selectedDocument()const {
00044 return DocLnk( selectedName() );
00045 }
00046 bool OFileViewInterface::showNew()const {
00047 return selector()->showNew();
00048 }
00049 bool OFileViewInterface::showClose()const {
00050 return selector()->showClose();
00051 }
00052 MimeTypes OFileViewInterface::mimeTypes()const {
00053 return selector()->mimeTypes();
00054 }
00055 QStringList OFileViewInterface::currentMimeType()const {
00056 return selector()->currentMimeType();
00057 }
00058 void OFileViewInterface::activate( const QString& ) {
00059
00060 }
00061 void OFileViewInterface::ok() {
00062 emit selector()->ok();
00063 }
00064 void OFileViewInterface::cancel() {
00065 emit selector()->cancel();
00066 }
00067 void OFileViewInterface::closeMe() {
00068 emit selector()->closeMe();
00069 }
00070 void OFileViewInterface::fileSelected( const QString& str) {
00071 emit selector()->fileSelected( str);
00072 }
00073 void OFileViewInterface::fileSelected( const DocLnk& lnk) {
00074 emit selector()->fileSelected( lnk );
00075 }
00076 void OFileViewInterface::setCurrentFileName( const QString& str ) {
00077 selector()->m_lneEdit->setText( str );
00078 }
00079 QString OFileViewInterface::currentFileName()const{
00080 return selector()->m_lneEdit->text();
00081 }
00082 QString OFileViewInterface::startDirectory()const{
00083 return selector()->m_startDir;
00084 }
00085
00086
00087 ODocumentFileView::ODocumentFileView( OFileSelector* selector )
00088 : OFileViewInterface( selector ) {
00089 m_selector = 0;
00090 setName( QObject::tr("Documents") );
00091 }
00092 ODocumentFileView::~ODocumentFileView() {
00093
00094 }
00095 QString ODocumentFileView::selectedName()const {
00096 if (!m_selector)
00097 return QString::null;
00098
00099 return m_selector->selectedDocument().file();
00100 }
00101 QString ODocumentFileView::selectedPath()const {
00102 return QPEApplication::documentDir();
00103 }
00104 QString ODocumentFileView::directory()const {
00105 return selectedPath();
00106 }
00107 void ODocumentFileView::reread() {
00108 if (!m_selector)
00109 return;
00110
00111 m_selector->setNewVisible( showNew() );
00112 m_selector->setCloseVisible( showClose() );
00113 m_selector->filter = currentMimeType().join(";");
00114 m_selector->reread();
00115 }
00116 int ODocumentFileView::fileCount()const {
00117 if (!m_selector)
00118 return -1;
00119
00120 return m_selector->fileCount();
00121 }
00122 DocLnk ODocumentFileView::selectedDocument()const {
00123 if (!m_selector)
00124 return DocLnk();
00125
00126 return m_selector->selectedDocument();
00127 }
00128 QWidget* ODocumentFileView::widget( QWidget* parent ) {
00129 if (!m_selector ) {
00130 m_selector = new FileSelector(currentMimeType().join(";"), parent, "fileselector", showNew(), showClose() );
00131 QObject::connect(m_selector, SIGNAL(fileSelected( const DocLnk& ) ),
00132 selector(), SLOT(slotDocLnkBridge(const DocLnk&) ) );
00133 QObject::connect(m_selector, SIGNAL(closeMe() ),
00134 selector(), SIGNAL(closeMe() ) );
00135 QObject::connect(m_selector, SIGNAL(newSelected(const DocLnk& ) ),
00136 selector(), SIGNAL(newSelected(const DocLnk& ) ) );
00137 }
00138
00139 return m_selector;
00140 }
00141
00142
00143
00144
00145
00146
00147 OFileSelectorItem::OFileSelectorItem( QListView* view, const QPixmap& pixmap,
00148 const QString& path, const QString& date,
00149 const QString& size, const QString& dir,
00150 bool isLocked, bool isDir )
00151 : QListViewItem( view )
00152 {
00153 setPixmap(0, pixmap );
00154 setText(1, path );
00155 setText(2, size );
00156 setText(3, date );
00157 m_isDir = isDir;
00158 m_dir = dir;
00159 m_locked = isLocked;
00160 }
00161 OFileSelectorItem::~OFileSelectorItem() {
00162
00163 }
00164 bool OFileSelectorItem::isLocked()const {
00165 return m_locked;
00166 }
00167 QString OFileSelectorItem::directory()const {
00168 return m_dir;
00169 }
00170 bool OFileSelectorItem::isDir()const {
00171 return m_isDir;
00172 }
00173 QString OFileSelectorItem::path()const {
00174 return text( 1 );
00175 }
00176 QString OFileSelectorItem::key( int id, bool )const {
00177 QString ke;
00178 if( id == 0 || id == 1 ){
00179 if( m_isDir ){
00180 ke.append("0" );
00181 ke.append( text(1) );
00182 }else{
00183 ke.append("1" );
00184 ke.append( text(1) );
00185 }
00186 return ke;
00187 }else
00188 return text( id );
00189
00190 }
00191
00192 OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& startDir,
00193 OFileSelector* sel)
00194 : QWidget( parent ), m_sel( sel ) {
00195 m_all = false;
00196 QVBoxLayout* lay = new QVBoxLayout( this );
00197 m_currentDir = startDir;
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209 QHBox* box = new QHBox(this );
00210 box->setBackgroundMode( PaletteButton );
00211 box->setSpacing( 0 );
00212
00213 QToolButton *btn = new QToolButton( box );
00214 btn->setIconSet( Resource::loadIconSet("up") );
00215 connect(btn, SIGNAL(clicked() ),
00216 this, SLOT( cdUP() ) );
00217
00218 btn = new QToolButton( box );
00219 btn->setIconSet( Resource::loadIconSet("home") );
00220 connect(btn, SIGNAL(clicked() ),
00221 this, SLOT( cdHome() ) );
00222
00223 btn = new QToolButton( box );
00224 btn->setIconSet( Resource::loadIconSet("DocsIcon") );
00225 connect(btn, SIGNAL(clicked() ),
00226 this, SLOT(cdDoc() ) );
00227
00228 m_btnNew = new QToolButton( box );
00229 m_btnNew->setIconSet( Resource::loadIconSet("new") );
00230 connect(m_btnNew, SIGNAL(clicked() ),
00231 this, SLOT(slotNew() ) );
00232
00233
00234 m_btnClose = new QToolButton( box );
00235 m_btnClose->setIconSet( Resource::loadIconSet("close") );
00236 connect(m_btnClose, SIGNAL(clicked() ),
00237 selector(), SIGNAL(closeMe() ) );
00238
00239 btn = new QToolButton( box );
00240 btn->setIconSet( Resource::loadIconSet("cardmon/pcmcia") );
00241
00242
00243 QPopupMenu* pop = new QPopupMenu(this);
00244 connect(pop, SIGNAL( activated(int) ),
00245 this, SLOT(slotFSActivated(int) ) );
00246
00247 StorageInfo storage;
00248 const QList<FileSystem> &fs = storage.fileSystems();
00249 QListIterator<FileSystem> it(fs);
00250 for ( ; it.current(); ++it ) {
00251 const QString disk = (*it)->name();
00252 const QString path = (*it)->path();
00253 m_dev.insert( disk, path );
00254 pop->insertItem( disk );
00255 }
00256 m_fsPop = pop;
00257
00258
00259 btn->setPopup( pop );
00260
00261 lay->addWidget( box );
00262
00263 m_view = new QListView( this );
00264
00265 m_view->installEventFilter(this);
00266
00267 QPEApplication::setStylusOperation( m_view->viewport(),
00268 QPEApplication::RightOnHold);
00269 m_view->addColumn(" " );
00270 m_view->addColumn(tr("Name"), 135 );
00271 m_view->addColumn(tr("Size"), -1 );
00272 m_view->addColumn(tr("Date"), 60 );
00273 m_view->addColumn(tr("Mime Type"), -1 );
00274
00275
00276 m_view->setSorting( 1 );
00277 m_view->setAllColumnsShowFocus( TRUE );
00278
00279 lay->addWidget( m_view, 1000 );
00280 connectSlots();
00281 }
00282 OFileViewFileListView::~OFileViewFileListView() {
00283 }
00284 void OFileViewFileListView::slotNew() {
00285 DocLnk lnk;
00286 emit selector()->newSelected( lnk );
00287 }
00288 OFileSelectorItem* OFileViewFileListView::currentItem()const{
00289 QListViewItem* item = m_view->currentItem();
00290 if (!item )
00291 return 0l;
00292
00293 return static_cast<OFileSelectorItem*>(item);
00294 }
00295 void OFileViewFileListView::reread( bool all ) {
00296 m_view->clear();
00297
00298 if (selector()->showClose() )
00299 m_btnClose->show();
00300 else
00301 m_btnClose->hide();
00302
00303 if (selector()->showNew() )
00304 m_btnNew->show();
00305 else
00306 m_btnNew->hide();
00307
00308 m_mimes = selector()->currentMimeType();
00309 m_all = all;
00310
00311 QDir dir( m_currentDir );
00312 if (!dir.exists() )
00313 return;
00314
00315 dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed );
00316 int filter;
00317 if (m_all )
00318 filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All;
00319 else
00320 filter = QDir::Files | QDir::Dirs | QDir::All;
00321 dir.setFilter( filter );
00322
00323
00324 const QFileInfoList *list = dir.entryInfoList();
00325 if (!list) {
00326 cdUP();
00327 return;
00328 }
00329 QFileInfoListIterator it( *list );
00330 QFileInfo *fi;
00331 while( (fi=it.current() ) ){
00332 if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ){
00333 ++it;
00334 continue;
00335 }
00336
00337
00338
00339
00340
00341 if( fi->isSymLink() ){
00342 QString file = fi->dirPath( true ) + "/" + fi->readLink();
00343 for( int i = 0; i<=4; i++) {
00344 QFileInfo info( file );
00345 if( !info.exists() ){
00346 addSymlink( fi, TRUE );
00347 break;
00348 }else if( info.isDir() ){
00349 addDir( fi, TRUE );
00350 break;
00351 }else if( info.isFile() ){
00352 addFile( fi, TRUE );
00353 break;
00354 }else if( info.isSymLink() ){
00355 file = info.dirPath(true ) + "/" + info.readLink() ;
00356 break;
00357 }else if( i == 4){
00358 addSymlink( fi );
00359 }
00360 }
00361 }else if( fi->isDir() )
00362 addDir( fi );
00363 else if( fi->isFile() )
00364 addFile( fi );
00365
00366 ++it;
00367 }
00368 m_view->sort();
00369
00370 }
00371 int OFileViewFileListView::fileCount()const{
00372 return m_view->childCount();
00373 }
00374 QString OFileViewFileListView::currentDir()const{
00375 return m_currentDir;
00376 }
00377 OFileSelector* OFileViewFileListView::selector() {
00378 return m_sel;
00379 }
00380
00381 bool OFileViewFileListView::eventFilter (QObject *o, QEvent *e) {
00382 if ( e->type() == QEvent::KeyPress ) {
00383 QKeyEvent *k = (QKeyEvent *)e;
00384 if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) {
00385 slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0);
00386 return true;
00387 }
00388 }
00389 return false;
00390 }
00391
00392
00393 void OFileViewFileListView::connectSlots() {
00394 connect(m_view, SIGNAL(clicked(QListViewItem*) ),
00395 this, SLOT(slotCurrentChanged(QListViewItem*) ) );
00396 connect(m_view, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint&, int ) ),
00397 this, SLOT(slotClicked(int, QListViewItem*, const QPoint&, int ) ) );
00398 }
00399 void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) {
00400 if (!item)
00401 return;
00402 #if 0
00403
00404 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item);
00405
00406 if (!sel->isDir() ) {
00407 selector()->m_lneEdit->setText( sel->text(1) );
00408
00409 if ( selector()->mode() == OFileSelector::FileSelector ) {
00410 qWarning("slot Current Changed");
00411 QStringList str = QStringList::split("->", sel->text(1) );
00412 QString path = sel->directory() + "/" + str[0].stripWhiteSpace();
00413 emit selector()->fileSelected( path );
00414 DocLnk lnk( path );
00415 emit selector()->fileSelected( lnk );
00416 }
00417 }
00418 #endif
00419 }
00420 void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) {
00421 if (!item || ( button != Qt::LeftButton) )
00422 return;
00423
00424 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item);
00425 if (!sel->isLocked() ) {
00426 QStringList str = QStringList::split("->", sel->text(1) );
00427 if (sel->isDir() ) {
00428 m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace();
00429 emit selector()->dirSelected( m_currentDir );
00430 reread( m_all );
00431 }else {
00432 qWarning("slot Clicked");
00433 selector()->m_lneEdit->setText( str[0].stripWhiteSpace() );
00434 QString path = sel->directory() + "/" + str[0].stripWhiteSpace();
00435 emit selector()->fileSelected( path );
00436 DocLnk lnk( path );
00437 emit selector()->fileSelected( lnk );
00438 }
00439 }
00440 }
00441 void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) {
00442 MimeType type( info->absFilePath() );
00443 if (!compliesMime( type.id() ) )
00444 return;
00445
00446 QPixmap pix = type.pixmap();
00447 QString dir, name; bool locked;
00448 if ( pix.isNull() ) {
00449 QWMatrix matrix;
00450 QPixmap pixer(Resource::loadPixmap("UnknownDocument") );
00451 matrix.scale( .4, .4 );
00452 pix = pixer.xForm( matrix );
00453 }
00454 dir = info->dirPath( true );
00455 locked = false;
00456 if ( symlink )
00457 name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink();
00458 else{
00459 name = info->fileName();
00460 if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) ||
00461 ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) {
00462 locked = true; pix = Resource::loadPixmap("locked");
00463 }
00464 }
00465 (void)new OFileSelectorItem( m_view, pix, name,
00466 info->lastModified().toString(), QString::number( info->size() ),
00467 dir, locked );
00468 }
00469 void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) {
00470 bool locked = false; QString name; QPixmap pix;
00471
00472 if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) ||
00473 ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) {
00474 locked = true;
00475 if ( symlink )
00476 pix = Resource::loadPixmap( "opie/symlink" );
00477 else
00478 pix = Resource::loadPixmap( "lockedfolder" );
00479 }else
00480 pix = symlink ? Resource::loadPixmap( "opie/symlink") : Resource::loadPixmap("folder");
00481
00482 name = symlink ? info->fileName() + " -> " + info->dirPath(true) + "/" + info->readLink() :
00483 info->fileName();
00484
00485 (void)new OFileSelectorItem( m_view, pix, name,
00486 info->lastModified().toString(),
00487 QString::number( info->size() ),
00488 info->dirPath( true ), locked, true );
00489
00490
00491 }
00492 void OFileViewFileListView::addSymlink( QFileInfo* , bool ) {
00493
00494 }
00495 void OFileViewFileListView::cdUP() {
00496 QDir dir( m_currentDir );
00497 dir.cdUp();
00498
00499 if (!dir.exists() )
00500 m_currentDir = "/";
00501 else
00502 m_currentDir = dir.absPath();
00503
00504 emit selector()->dirSelected( m_currentDir );
00505 reread( m_all );
00506 }
00507 void OFileViewFileListView::cdHome() {
00508 m_currentDir = QDir::homeDirPath();
00509 emit selector()->dirSelected( m_currentDir );
00510 reread( m_all );
00511 }
00512 void OFileViewFileListView::cdDoc() {
00513 m_currentDir = QPEApplication::documentDir();
00514 emit selector()->dirSelected( m_currentDir );
00515 reread( m_all );
00516 }
00517 void OFileViewFileListView::changeDir( const QString& dir ) {
00518 m_currentDir = dir;
00519 emit selector()->dirSelected( m_currentDir );
00520 reread( m_all );
00521 }
00522 void OFileViewFileListView::slotFSActivated( int id ) {
00523 changeDir ( m_dev[m_fsPop->text(id)] );
00524 }
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545 bool OFileViewFileListView::compliesMime( const QString& str) {
00546 if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() )
00547 return true;
00548
00549 for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it ) {
00550 QRegExp reg( (*it) );
00551 reg.setWildcard( true );
00552 if ( str.find( reg ) != -1 )
00553 return true;
00554
00555 }
00556 return false;
00557 }
00558
00559
00560
00561 class OFileViewFileSystem : public OFileViewInterface {
00562 public:
00563 OFileViewFileSystem( OFileSelector* );
00564 ~OFileViewFileSystem();
00565
00566 QString selectedName() const;
00567 QString selectedPath() const;
00568
00569 QString directory()const;
00570 void reread();
00571 int fileCount()const;
00572
00573 QWidget* widget( QWidget* parent );
00574 void activate( const QString& );
00575 private:
00576 OFileViewFileListView* m_view;
00577 bool m_all : 1;
00578 };
00579 OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel)
00580 : OFileViewInterface( sel ) {
00581 m_view = 0;
00582 m_all = false;
00583 }
00584 OFileViewFileSystem::~OFileViewFileSystem() {
00585 }
00586 QString OFileViewFileSystem::selectedName()const{
00587 if (!m_view )
00588 return QString::null;
00589
00590 QString cFN=currentFileName();
00591 if (cFN.startsWith("/")) return cFN;
00592 return m_view->currentDir() + "/" + cFN;
00593 }
00594 QString OFileViewFileSystem::selectedPath()const{
00595 return QString::null;
00596 }
00597 QString OFileViewFileSystem::directory()const{
00598 if (!m_view)
00599 return QString::null;
00600
00601 OFileSelectorItem* item = m_view->currentItem();
00602 if (!item )
00603 return QString::null;
00604
00605 return QDir(item->directory() ).absPath();
00606 }
00607 void OFileViewFileSystem::reread() {
00608 if (!m_view)
00609 return;
00610
00611 m_view->reread( m_all );
00612 }
00613 int OFileViewFileSystem::fileCount()const{
00614 if (!m_view )
00615 return -1;
00616 return m_view->fileCount();
00617 }
00618 QWidget* OFileViewFileSystem::widget( QWidget* parent ) {
00619 if (!m_view ) {
00620 m_view = new OFileViewFileListView( parent, startDirectory(), selector() );
00621 }
00622 return m_view;
00623 }
00624 void OFileViewFileSystem::activate( const QString& str) {
00625 m_all = (str != QObject::tr("Files") );
00626
00627
00628 }
00629
00630
00660 OFileSelector::OFileSelector( QWidget* parent, int mode, int sel,
00661 const QString& dirName, const QString& fileName,
00662 const MimeTypes& mimetypes,
00663 bool showNew, bool showClose)
00664 : QWidget( parent, "OFileSelector" )
00665 {
00666 m_current = 0;
00667 m_shNew = showNew;
00668 m_shClose = showClose;
00669 m_mimeType = mimetypes;
00670 m_startDir = dirName;
00671
00672 m_mode = mode;
00673 m_selector = sel;
00674
00675 initUI();
00676 m_lneEdit->setText( fileName );
00677 initMime();
00678 initViews();
00679
00680 QString str;
00681 switch ( m_selector ) {
00682 default:
00683 case Normal:
00684 str = QObject::tr("Documents");
00685 m_cmbView->setCurrentItem( 0 );
00686 break;
00687 case Extended:
00688 str = QObject::tr("Files");
00689 m_cmbView->setCurrentItem( 1 );
00690 break;
00691 case ExtendedAll:
00692 str = QObject::tr("All Files");
00693 m_cmbView->setCurrentItem( 2 );
00694 break;
00695 }
00696 slotViewChange( str );
00697
00698 }
00699
00703 OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name,
00704 bool showNew, bool showClose )
00705 : QWidget( parent, name )
00706 {
00707 m_current = 0;
00708 m_shNew = showNew;
00709 m_shClose = showClose;
00710 m_startDir = QPEApplication::documentDir();
00711
00712 if (!mimeFilter.isEmpty() )
00713 m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) );
00714
00715 m_mode = OFileSelector::FileSelector;
00716 m_selector = OFileSelector::Normal;
00717
00718 initUI();
00719 initMime();
00720 initViews();
00721 m_cmbView->setCurrentItem( 0 );
00722 slotViewChange( QObject::tr("Documents") );
00723 }
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734 void OFileSelector::initUI() {
00735 QVBoxLayout* lay = new QVBoxLayout( this );
00736
00737 m_stack = new QWidgetStack( this );
00738 lay->addWidget( m_stack, 1000 );
00739
00740 m_nameBox = new QHBox( this );
00741 (void)new QLabel( tr("Name:"), m_nameBox );
00742 m_lneEdit = new QLineEdit( m_nameBox );
00743 m_lneEdit ->installEventFilter(this);
00744 lay->addWidget( m_nameBox );
00745
00746 m_cmbBox = new QHBox( this );
00747 m_cmbView = new QComboBox( m_cmbBox );
00748 m_cmbMime = new QComboBox( m_cmbBox );
00749 lay->addWidget( m_cmbBox );
00750 }
00751
00752
00753
00754
00755
00756 bool OFileSelector::eventFilter (QObject *o, QEvent *e) {
00757 if ( e->type() == QEvent::KeyPress ) {
00758 QKeyEvent *k = (QKeyEvent *)e;
00759 if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) {
00760 emit ok();
00761 return true;
00762 }
00763 }
00764 return false;
00765 }
00766
00767
00768
00769
00770
00771
00772
00773 void OFileSelector::initMime() {
00774 MimeTypes::Iterator it;
00775 for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it ) {
00776 m_cmbMime->insertItem( it.key() );
00777 }
00778 m_cmbMime->setCurrentItem( 0 );
00779
00780 connect( m_cmbMime, SIGNAL(activated(int) ),
00781 this, SLOT(slotMimeTypeChanged() ) );
00782
00783 }
00784 void OFileSelector::initViews() {
00785 m_cmbView->insertItem( QObject::tr("Documents") );
00786 m_cmbView->insertItem( QObject::tr("Files") );
00787 m_cmbView->insertItem( QObject::tr("All Files") );
00788 connect(m_cmbView, SIGNAL(activated( const QString& ) ),
00789 this, SLOT(slotViewChange( const QString& ) ) );
00790
00791
00792 m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) );
00793
00794
00795 OFileViewInterface* in = new OFileViewFileSystem( this );
00796 m_views.insert( QObject::tr("Files"), in );
00797 m_views.insert( QObject::tr("All Files"), in );
00798 }
00799
00803 OFileSelector::~OFileSelector() {
00804
00805 }
00806
00814 const DocLnk* OFileSelector::selected() {
00815 DocLnk* lnk = new DocLnk( currentView()->selectedDocument() );
00816 return lnk;
00817 }
00818
00823 QString OFileSelector::selectedName()const{
00824 return currentView()->selectedName();
00825 }
00826
00830 QString OFileSelector::selectedPath()const {
00831 return currentView()->selectedPath();
00832 }
00833
00837 QString OFileSelector::directory()const {
00838 return currentView()->directory();
00839 }
00840
00844 DocLnk OFileSelector::selectedDocument()const {
00845 return currentView()->selectedDocument();
00846 }
00847
00851 int OFileSelector::fileCount()const {
00852 return currentView()->fileCount();
00853 }
00854
00858 void OFileSelector::reread() {
00859 return currentView()->reread();
00860 }
00861 OFileViewInterface* OFileSelector::currentView()const{
00862 return m_current;
00863 }
00864 bool OFileSelector::showNew()const {
00865 return m_shNew;
00866 }
00867 bool OFileSelector::showClose()const {
00868 return m_shClose;
00869 }
00870 MimeTypes OFileSelector::mimeTypes()const {
00871 return m_mimeType;
00872 }
00873
00877 int OFileSelector::mode()const{
00878 return m_mode;
00879 }
00880
00884 int OFileSelector::selector()const{
00885 return m_selector;
00886 }
00887 QStringList OFileSelector::currentMimeType()const {
00888 return m_mimeType[m_cmbMime->currentText()];
00889 }
00890 void OFileSelector::slotMimeTypeChanged() {
00891 reread();
00892 }
00893 void OFileSelector::slotDocLnkBridge( const DocLnk& lnk) {
00894 m_lneEdit->setText( lnk.name() );
00895 emit fileSelected( lnk );
00896 emit fileSelected( lnk.name() );
00897 }
00898 void OFileSelector::slotFileBridge( const QString& str) {
00899 DocLnk lnk( str );
00900 emit fileSelected( lnk );
00901 }
00902 void OFileSelector::slotViewChange( const QString& view ) {
00903 OFileViewInterface* interface = m_views[view];
00904 if (!interface)
00905 return;
00906
00907 interface->activate( view );
00908 if (m_current)
00909 m_stack->removeWidget( m_current->widget( m_stack ) );
00910
00911 static int id = 1;
00912
00913 m_stack->addWidget( interface->widget(m_stack), id );
00914 m_stack->raiseWidget( id );
00915
00916 interface->reread();
00917 m_current = interface;
00918
00919 id++;
00920 }
00921 void OFileSelector::setNewVisible( bool b ) {
00922 m_shNew = b;
00923 currentView()->reread();
00924 }
00925 void OFileSelector::setCloseVisible( bool b ) {
00926 m_shClose = b;
00927 currentView()->reread();
00928 }
00929 void OFileSelector::setNameVisible( bool b ) {
00930 if ( b )
00931 m_nameBox->show();
00932 else
00933 m_nameBox->hide();
00934 }