00001
00002
00003
00004
00005 #include <stdlib.h>
00006 #include <qpopupmenu.h>
00007 #include <qtoolbar.h>
00008
00009 #include <opie2/oresource.h>
00010
00011 #include <qpe/storage.h>
00012
00013
00014 #include "filesystem.h"
00015
00016 PFileSystem::PFileSystem( QToolBar* bar)
00017 : QToolButton( bar )
00018 {
00019 setIconSet( Opie::Core::OResource::loadPixmap( "pcmcia", Opie::Core::OResource::SmallIcon ) );
00020
00021 m_pop = new QPopupMenu( this );
00022 connect( m_pop, SIGNAL( activated( int ) ),
00023 this, SLOT(slotSelectDir( int ) ) );
00024
00025 m_storage = new StorageInfo();
00026 connect(m_storage, SIGNAL(disksChanged() ),
00027 this, SLOT( changed() ) );
00028 changed();
00029
00030 connect(this,SIGNAL(pressed()),SLOT(slotPopUp()));
00031 }
00032
00033 PFileSystem::~PFileSystem() {
00034 delete m_storage;
00035 }
00036
00037
00038 void PFileSystem::changed() {
00039 m_pop->clear();
00040 m_dev.clear();
00041
00042
00043 QString f = getenv( "HOME" );
00044 if (!f.isEmpty()) {
00045 m_dev.insert("Home directory",f);
00046 m_pop->insertItem("Home directory");
00047 }
00048
00049 const QList<FileSystem> &fs = m_storage->fileSystems();
00050 QListIterator<FileSystem> it(fs );
00051 for ( ; it.current(); ++it ) {
00052 const QString disk = (*it)->name();
00053 const QString path = (*it)->path();
00054 m_dev.insert( disk, path );
00055 m_pop->insertItem( disk );
00056 }
00057 }
00058
00059 void PFileSystem::slotPopUp() {
00060 m_pop->exec(QCursor::pos());
00061 setDown(false);
00062 }
00063
00064 void PFileSystem::slotSelectDir( int id ) {
00065 emit changeDir( m_dev[m_pop->text(id )] );
00066 }