summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/ofileselector.cc36
1 files changed, 30 insertions, 6 deletions
diff --git a/libopie/ofileselector.cc b/libopie/ofileselector.cc
index 98290e0..824acf2 100644
--- a/libopie/ofileselector.cc
+++ b/libopie/ofileselector.cc
@@ -96,94 +96,96 @@ namespace {
};
};
OFileSelector::OFileSelector( QWidget *wid, int mode, int selector,
const QString &dirName,
const QString &fileName,
const QMap<QString,QStringList>& mimeTypes)
: QWidget( wid, "OFileSelector")
{
m_mimetypes = mimeTypes;
if (mode == SAVE )
m_name = fileName;
initVars();
m_mode = mode;
m_selector = selector;
m_currentDir = dirName;
init();
//QTimer::singleShot(6*1000, this, SLOT( slotTest() ) );
}
OFileSelector::OFileSelector(const QString &mimeFilter, QWidget *parent,
const char *name, bool newVisible,
bool closeVisible )
: QWidget( parent, name )
{
if (!mimeFilter.isEmpty() ) {
QStringList list = QStringList::split(";", mimeFilter );
m_mimetypes.insert(mimeFilter, list );
}
initVars();
m_currentDir = QPEApplication::documentDir();
- m_mode = OPEN;
+ m_mode = FILESELECTOR;
m_selector = NORMAL;
m_shClose = closeVisible;
m_shNew = newVisible;
m_shLne = false;
m_shPerm = false;
m_shYesNo = false;
init();
}
OFileSelector::~OFileSelector()
{
}
void OFileSelector::setNewVisible( bool visible )
{
m_shNew = visible;
if( m_selector == NORMAL ){
delete m_select;
// we need to initialize but keep the selected mimetype
QString mime = currentMimeType();
m_select = new FileSelector( mime ,
m_stack, "fileselector",
m_shNew, m_shClose);
connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ),
this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) );
+ connect(m_select, SIGNAL(closeMe() ),
+ this, SIGNAL(closeMe() ) );
//connect to close me and other signals as well
m_stack->addWidget( m_select, NORMAL );
}else{
m_new->show();
}
}
void OFileSelector::setCloseVisible( bool visible )
{
m_shClose = visible;
if( m_selector == NORMAL ){
setNewVisible( m_shNew ); // yeah baby
}else{
m_close->show();
}
}
void OFileSelector::reread()
{
if( m_selector == NORMAL ){
setNewVisible( m_shNew ); // make it a initializeSelector
}else if ( m_selector == EXTENDED || m_selector == EXTENDED_ALL ){
reparse();
//}else{
//;
}
}
const DocLnk *OFileSelector::selected()
{
if( m_selector == NORMAL ){
return m_select->selected();
}else{
DocLnk *lnk = new DocLnk(selectedDocument() );
@@ -406,193 +408,199 @@ DocLnk OFileSelector::selectedDocument() const
lnk = DocLnk( selectedName() ); // new DocLnk
break;
}
return lnk;
}
QValueList<DocLnk> OFileSelector::selectedDocuments() const
{
QValueList<DocLnk> docs;
docs.append( selectedDocument() );
return docs;
}
// slots internal
void OFileSelector::slotOk()
{
emit ok();
}
void OFileSelector::slotCancel()
{
emit cancel();
}
void OFileSelector::slotViewCheck(const QString &sel)
{
if( sel == tr("Documents" ) ){
if( m_select == 0 ){
// autMime? fix cause now we use All and not the current
// yes currentMime fixes that for us
QString mime = currentMimeType();
m_select = new FileSelector(mime,
m_stack, "fileselector",
- FALSE, FALSE);
+ m_shNew, m_shClose);
connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ),
this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) );
+ connect(m_select, SIGNAL(closeMe() ),
+ this, SIGNAL(closeMe() ) );
//connect to close me and other signals as well
m_stack->addWidget( m_select, NORMAL );
}
m_stack->raiseWidget( NORMAL );
m_selector = NORMAL;
}else if( sel == tr("Files") ){
m_selector = EXTENDED;
initializeListView();
reparse();
m_stack->raiseWidget( EXTENDED );
}else if( sel == tr("All Files") ){
m_selector = EXTENDED_ALL;
initializeListView();
reparse();
m_stack->raiseWidget( EXTENDED ); // same widget other QFileFilter
}
}
// not yet finished.....
QString OFileSelector::currentMimeType() const{
QString mime;
QString currentText;
if (m_shChooser )
currentText = m_mimeCheck->currentText();
if (tr("All") == currentText ) return QString::null;
else if (currentText.isEmpty() ) {
;
}else {
QMap<QString, QStringList>::ConstIterator it;
it = m_mimetypes.find( currentText );
if ( it == m_mimetypes.end() ) {
mime = it.data().join(";");
}else{
mime = currentText;
}
}
return mime;
}
void OFileSelector::slotMimeCheck(const QString &mime)
{
if( m_selector == NORMAL ){
//if( m_autoMime ){
QString newMimeType;
if (mime != tr("All") ) {
QMap<QString, QStringList>::Iterator it;
it = m_mimetypes.find(mime);
if ( it != m_mimetypes.end() ) {
newMimeType = it.data().join(";");
}else{
newMimeType = mime;
}
}
delete m_select;
m_select = new FileSelector( newMimeType,
m_stack, "fileselector",
- FALSE, FALSE);
+ m_shNew, m_shClose);
connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ),
this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) );
+ connect(m_select, SIGNAL(closeMe() ),
+ this, SIGNAL(closeMe() ) );
//connect to close me and other signals as well
m_stack->addWidget( m_select, NORMAL );
m_stack->raiseWidget( NORMAL );
updateMimes();
updateMimeCheck();
m_mimeCheck->setCurrentItem(indexByString( m_mimeCheck, mime) );
//}
}else{ // others
qWarning("Mime %s", mime.latin1() );
if(m_shChooser ){
qWarning("Current Text %s", m_mimeCheck->currentText().latin1() );
//m_mimeCheck->setCurrentItem(indexByString( m_mimeCheck, mime) );
}
reparse();
}
}
void OFileSelector::slotLocationActivated(const QString &file)
{
cd(file.left(file.find("<-",0,TRUE)));
reparse();
}
void OFileSelector::slotInsertLocationPath(const QString &currentPath, int count)
{
QStringList pathList;
bool underDog = FALSE;
for(int i=0;i<count;i++) {
pathList << m_location->text(i);
if( m_location->text(i) == currentPath)
underDog = TRUE;
}
if( !underDog) {
m_location->clear();
if( currentPath.left(2)=="//")
pathList.append( currentPath.right(currentPath.length()-1) );
else
pathList.append( currentPath );
m_location->insertStringList( pathList,-1);
}
}
void OFileSelector::locationComboChanged()
{
cd( m_location->lineEdit()->text());
reparse();
}
void OFileSelector::init()
{
m_lay = new QVBoxLayout( this );
m_lay->setSpacing(0 );
m_stack = new QWidgetStack( this );
if( m_selector == NORMAL ){
QString mime;
if (!m_autoMime) {
if (!m_mimetypes.isEmpty() ) {
QMap<QString, QStringList>::Iterator it;
it = m_mimetypes.begin(); // cause we're in the init
mime = it.data().join(";");
}
}
m_select = new FileSelector(mime,
m_stack, "fileselector",
- FALSE, FALSE);
+ m_shNew, m_shClose);
connect(m_select, SIGNAL(fileSelected( const DocLnk & ) ),
this, SLOT( slotFileBridgeSelected(const DocLnk & ) ) );
+ connect(m_select, SIGNAL(closeMe() ),
+ this, SIGNAL( closeMe() ) );
//connect to close me and other signals as well
m_stack->addWidget( m_select, NORMAL );
m_stack->raiseWidget( NORMAL );
}else{ // we're in init so it will be EXTENDED or EXTENDED_ALL
// and initializeListview will take care of those
// toolbar get's generade in initializeListView
initializeListView( ); // will raise the widget as well
m_stack->raiseWidget( EXTENDED );
}
m_lay->addWidget( m_stack, 100 ); // add to the layout 10 = stretch
if( m_shLne ) // the LineEdit with the current FileName
initializeName();
if( m_shPerm ) // the Permission QCheckBox
initializePerm();
if( m_shChooser ) // the Chooser for the view and Mimetypes
initializeChooser();
if( m_shYesNo ) // the Yes No button row
initializeYes( );
if (m_selector != NORMAL )
reparse();
}
void OFileSelector::updateMimes()
{
if( m_autoMime ){
m_mimetypes.clear();
m_mimetypes.insert( tr("All"), QString::null );
@@ -845,66 +853,66 @@ void OFileSelector::initializeListView()
m_docButton->setFlat(TRUE);
// Close button
m_close = new QPushButton( Resource::loadIconSet( "close"), "",
m_boxToolbar );
connect( m_close, SIGNAL(clicked() ), this, SIGNAL(closeMe() ) );
m_close->setFixedSize( 20, 20 );
m_boxToolbar->setFixedHeight( 20 );
m_pseudoLayout->addWidget(m_boxToolbar );
// let;s fill the Location ComboBox
StorageInfo storage;
const QList<FileSystem> &fs = storage.fileSystems();
QListIterator<FileSystem> it ( fs );
for( ; it.current(); ++it ){
const QString disk = (*it)->name();
const QString path = (*it)->path();
m_location->insertItem(path+ "<-"+disk );
}
int count = m_location->count();
m_location->insertItem( m_currentDir );
m_location->setCurrentItem( count );
// due to the New and Close button we can not simply hide m_boxToolBar to not show it
if( !m_shTool ){
m_location->hide( );
m_up->hide( );
m_homeButton->hide( );
m_docButton->hide( );
}
if(!m_shClose )
m_close->hide();
- if(!m_shNew)
- m_close->hide();
+ //if(!m_shNew)
+ //m_close->hide();
} // off toolbar
// the Main ListView
// make a QWidgetStack first so Views can share the Toolbar
m_View = new QListView( m_pseudo, "Extended view");
QPEApplication::setStylusOperation( m_View->viewport(),
QPEApplication::RightOnHold);
m_View->addColumn(" " );
m_View->addColumn(tr("Name"), 135 );
m_View->addColumn(tr("Size"), -1 );
m_View->addColumn(tr("Date"), 60 );
m_View->addColumn(tr("Mime Type"), -1 );
QHeader *header = m_View->header();
header->hide();
m_View->setSorting( 1 );
m_View->setAllColumnsShowFocus( TRUE );
connect(m_View, SIGNAL(selectionChanged() ),
this, SLOT(slotSelectionChanged() ) );
connect(m_View, SIGNAL(currentChanged(QListViewItem *) ),
this, SLOT(slotCurrentChanged(QListViewItem * ) ) );
connect(m_View, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint &, int) ),
this, SLOT(slotClicked( int, QListViewItem *, const QPoint &, int) ) );
connect(m_View, SIGNAL(mouseButtonPressed(int, QListViewItem *, const QPoint &, int )),
this, SLOT(slotRightButton(int, QListViewItem *, const QPoint &, int ) ) );
m_pseudoLayout->addWidget( m_View, 288 );
m_stack->addWidget( m_pseudo, EXTENDED );
}
@@ -993,126 +1001,142 @@ bool OFileSelector::compliesMime( const QString& mime ) {
QStringList::Iterator it2;
int pos;
int pos2;
for ( it2 = list.begin(); it2 != list.end(); ++it2 ) {
pos = (*it2).findRev("/*");
if ( pos >= 0 ) {
if ( mime.contains( (*it2).left(pos) ) ) return true;
}
}
return false;
}
void OFileSelector::slotFileSelected( const QString &string )
{
if( m_shLne )
m_edit->setText( string );
emit fileSelected( string );
}
void OFileSelector::slotFileBridgeSelected( const DocLnk &lnk )
{
slotFileSelected( lnk.name() );
// emit fileSelected( lnk );
}
void OFileSelector::slotSelectionChanged()
{
}
void OFileSelector::slotCurrentChanged(QListViewItem* item )
{
if( item == 0 )
return;
if( m_selector == EXTENDED || m_selector == EXTENDED_ALL ) {
OFileSelectorItem *sel = (OFileSelectorItem*) item; // start to use the C++ casts ;)
+ qWarning("current changed");
if(!sel->isDir() ){
if( m_shLne )
m_edit->setText( sel->text(1) );
+
+ if (m_mode == FILESELECTOR ) {
+ QStringList str = QStringList::split("->", sel->text(1) );
+ QString path =sel->directory() + "/" + str[0].stripWhiteSpace();
+ emit fileSelected(path );
+ DocLnk lnk( path );
+ emit fileSelected(lnk );
+ }
}
}
}
void OFileSelector::slotClicked( int button, QListViewItem *item, const QPoint &, int)
{
if ( item == 0 )
return;
if( button != Qt::LeftButton )
return;
switch( m_selector ){
default:
break;
case EXTENDED: // fall through
case EXTENDED_ALL:{
OFileSelectorItem *sel = (OFileSelectorItem*)item;
if(!sel->isLocked() ){
QStringList str = QStringList::split("->", sel->text(1) );
if( sel->isDir() ){
cd( sel->directory() + "/" + str[0].stripWhiteSpace() );
// if MODE Dir m_shLne set the Text
}else{
if( m_shLne )
m_edit->setText( str[0].stripWhiteSpace() );
+ qWarning("selected here in slot clicked");
emit fileSelected( sel->directory() + "/" + str[0].stripWhiteSpace() );
+ DocLnk lnk( sel->directory() + "/" + str[0].stripWhiteSpace() );
+ qWarning("file selected");
+ emit fileSelected( lnk );
}
}
break;
}
}
}
void OFileSelector::slotRightButton(int button, QListViewItem *item, const QPoint &, int )
{
if( item == 0 )
return;
if( button != Qt::RightButton )
return;
slotContextMenu( item );
}
void OFileSelector::slotContextMenu( QListViewItem *item)
{
}
void OFileSelector::slotChangedDir()
{
OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem();
if(sel->isDir() ){
QStringList str = QStringList::split("->", sel->text(1) );
cd( sel->directory() + "/" + str[0].stripWhiteSpace() );
}
}
void OFileSelector::slotOpen()
{
OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem();
if(!sel->isDir() ){
QStringList str = QStringList::split("->", sel->text(1) );
slotFileSelected( sel->directory() +"/" +str[0].stripWhiteSpace() );
+ qWarning("slot open");
+ // DocLnk lnk( sel->directory() + "/" + str[0].stripWhiteSpace() );
+ //emit fileSelected( lnk );
}
}
void OFileSelector::slotRescan()
{
}
void OFileSelector::slotRename()
{
reparse();
}
void OFileSelector::slotDelete()
{
OFileSelectorItem *sel = (OFileSelectorItem*)m_View->currentItem();
QStringList list = QStringList::split("->", sel->text(1) );
if( sel->isDir() ){
QString str = QString::fromLatin1("rm -rf ") + sel->directory() +"/" + list[0]; //better safe than sorry
switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+list[0],
tr("Yes"),tr("No"),0,1,1) ) {
case 0:
::system(str.utf8().data() );
break;
}
} else {
QFile::remove( list[0] );
}
m_View->takeItem( sel );
delete sel;
}
void OFileSelector::cdUP()
{
QDir dir( m_currentDir );
dir.cdUp();