author | kergoth <kergoth> | 2002-05-15 16:44:53 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2002-05-15 16:44:53 (UTC) |
commit | aa5d79399aa991aa84eb8b4f48d55202473990ef (patch) (side-by-side diff) | |
tree | dda2b43b5ad001435175cce1ec943df21ef63c43 | |
parent | 7844e2aebcb289f55bf10f22ea1250773c8ad7bd (diff) | |
download | opie-aa5d79399aa991aa84eb8b4f48d55202473990ef.zip opie-aa5d79399aa991aa84eb8b4f48d55202473990ef.tar.gz opie-aa5d79399aa991aa84eb8b4f48d55202473990ef.tar.bz2 |
hmm, we dont need the same things in here twice. Compiles again.
-rw-r--r-- | noncore/unsupported/filebrowser/filebrowser.cpp | 38 |
1 files changed, 0 insertions, 38 deletions
diff --git a/noncore/unsupported/filebrowser/filebrowser.cpp b/noncore/unsupported/filebrowser/filebrowser.cpp index 7dabdb6..d16e771 100644 --- a/noncore/unsupported/filebrowser/filebrowser.cpp +++ b/noncore/unsupported/filebrowser/filebrowser.cpp @@ -352,403 +352,384 @@ void FileView::generateDir( const QString & dir ) } void FileView::rename() { itemToRename = (FileItem *) currentItem(); const QPixmap * pm; int pmw; if( itemToRename == NULL ) return; if( ( pm = itemToRename->pixmap( 0 ) ) == NULL ) pmw = 0; else pmw = pm->width(); ensureItemVisible( itemToRename ); horizontalScrollBar()->setValue( 0 ); horizontalScrollBar()->setEnabled( FALSE ); verticalScrollBar()->setEnabled( FALSE ); selected = isSelected( itemToRename ); setSelected( itemToRename, FALSE ); if( le == NULL ){ le = new InlineEdit( this ); le->setFrame( FALSE ); connect( le, SIGNAL( lostFocus() ), SLOT( endRenaming() ) ); } QRect r = itemRect( itemToRename ); r.setTop( r.top() + frameWidth() + 1 ); r.setLeft( r.left() + frameWidth() + pmw ); r.setBottom( r.bottom() + frameWidth() ); r.setWidth( columnWidth( 0 ) - pmw ); le->setGeometry( r ); le->setText( itemToRename->text( 0 ) ); le->selectAll(); le->show(); le->setFocus(); } void FileView::endRenaming() { if( le && itemToRename ){ le->hide(); setSelected( itemToRename, selected ); if( !itemToRename->rename( le->text() ) ){ QMessageBox::warning( this, tr( "Rename file" ), tr( "Rename failed!" ), tr( "&Ok" ) ); } else { updateDir(); } itemToRename = NULL; horizontalScrollBar()->setEnabled( TRUE ); verticalScrollBar()->setEnabled( TRUE ); } } void FileView::copy() { // dont keep cut files any longer than necessary // ##### a better inmplementation might be to rename the CUT file // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it. system ( "rm -rf /tmp/qpemoving" ); FileItem * i; if((i = (FileItem *) firstChild()) == 0) return; flist.clear(); while( i ){ if( i->isSelected() /*&& !i->isDir()*/ ){ flist += i->getFilePath(); } i = (FileItem *) i->nextSibling(); } } void FileView::paste() { int i, err; QString cmd, dest, basename, cd = currentDir; if(cd == "/") cd = ""; for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) { basename = (*it).mid((*it).findRev("/") + 1, (*it).length()); dest = cd + "/" + basename; if( QFile( dest ).exists() ){ i = 1; dest = cd + "/Copy of " + basename; while( QFile( dest ).exists() ){ dest.sprintf( "%s/Copy (%d) of %s", (const char *) cd, i++, (const char *) basename ); } } // // Copy a directory recursively using the "cp" command - // may have to be changed // if( QFileInfo( (*it) ).isDir() ){ cmd = "/bin/cp -fpR \"" + (*it) +"\" " + "\"" + dest + "\""; err = system( (const char *) cmd ); } else if( !copyFile( dest, (*it) ) ){ err = -1; } else { err = 0; } if ( err != 0 ) { QMessageBox::warning( this, tr("Paste file"), tr("Paste failed!"), tr("Ok") ); break; } else { updateDir(); QListViewItem * i = firstChild(); basename = dest.mid( dest.findRev("/") + 1, dest.length() ); while( i ){ if( i->text(0) == basename ){ setCurrentItem( i ); ensureItemVisible( i ); break; } i = i->nextSibling(); } } } } bool FileView::copyFile( const QString & dest, const QString & src ) { char bf[ 50000 ]; int bytesRead; bool success = TRUE; struct stat status; QFile s( src ); QFile d( dest ); if( s.open( IO_ReadOnly | IO_Raw ) && d.open( IO_WriteOnly | IO_Raw ) ) { while( (bytesRead = s.readBlock( bf, sizeof( bf ) )) == sizeof( bf ) ) { if( d.writeBlock( bf, sizeof( bf ) ) != sizeof( bf ) ){ success = FALSE; break; } } if( success && (bytesRead > 0) ){ d.writeBlock( bf, bytesRead ); } } else { success = FALSE; } // Set file permissions if( stat( (const char *) src, &status ) == 0 ){ chmod( (const char *) dest, status.st_mode ); } return success; } void FileView::cut() { int err; // ##### a better inmplementation might be to rename the CUT file // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it. QString cmd, dest, basename, cd = "/tmp/qpemoving"; QStringList newflist; newflist.clear(); cmd = "rm -rf " + cd; system ( (const char *) cmd ); cmd = "mkdir " + cd; system( (const char *) cmd ); // get the names of the files to cut FileItem * item; if((item = (FileItem *) firstChild()) == 0) return; flist.clear(); while( item ){ - if( ite - // ##### a better inmplementation might be to rename the CUT file - // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it. - QString cmd, dest, basename, cd = "/tmp/qpemoving"; - QStringList newflist; - newflist.clear(); - - cmd = "rm -rf " + cd; - system ( (const char *) cmd ); - cmd = "mkdir " + cd; - system( (const char *) cmd ); - -// get the names of the files to cut - FileItem * item; - - if((item = (FileItem *) firstChild()) == 0) return; - - flist.clear(); - while( item ){ if( item->isSelected() /*&& !item->isDir()*/ ){ flist += item->getFilePath(); } item = (FileItem *) item->nextSibling(); } // move these files into a tmp dir for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) { basename = (*it).mid((*it).findRev("/") + 1, (*it).length()); dest = cd + "/" + basename; newflist += dest; cmd = "/bin/mv -f \"" + (*it) +"\" " + "\"" + dest + "\""; err = system( (const char *) cmd ); if ( err != 0 ) { QMessageBox::warning( this, tr("Cut file"), tr("Cut failed!"), tr("Ok") ); break; } else { updateDir(); QListViewItem * im = firstChild(); basename = dest.mid( dest.findRev("/") + 1, dest.length() ); while( im ){ if( im->text(0) == basename ){ setCurrentItem( im ); ensureItemVisible( im ); break; } im = im->nextSibling(); } } } // update the filelist to point to tmp dir so paste works nicely flist = newflist; } void FileView::del() { FileItem * i; QStringList fl; QString cmd; int err; if((i = (FileItem *) firstChild()) == 0) return; while( i ){ if( i->isSelected() ){ fl += i->getFilePath(); } i = (FileItem *) i->nextSibling(); } if( fl.count() < 1 ) return; if( QMessageBox::warning( this, tr("Delete"), tr("Are you sure?"), tr("Yes"), tr("No") ) == 0) { // // Dependant upon the "rm" command - will probably have to be replaced // for ( QStringList::Iterator it = fl.begin(); it != fl.end(); ++it ) { cmd = "/bin/rm -rf \"" + (*it) + "\""; err = system( (const char *) cmd ); if ( err != 0 ) { QMessageBox::warning( this, tr("Delete"), tr("Delete failed!"), tr("Ok") ); break; } } updateDir(); } } void FileView::newFolder() { int t = 1; FileItem * i; QString nd = currentDir + "/NewFolder"; while( QFile( nd ).exists() ){ nd.sprintf( "%s/NewFolder (%d)", (const char *) currentDir, t++ ); } if( mkdir( (const char *) nd, 0777 ) != 0){ QMessageBox::warning( this, tr( "New folder" ), tr( "Folder creation failed!" ), tr( "Ok" ) ); return; } updateDir(); if((i = (FileItem *) firstChild()) == 0) return; while( i ){ if( i->isDir() && ( i->getFilePath() == nd ) ){ setCurrentItem( i ); rename(); break; } i = (FileItem *) i->nextSibling(); } } void FileView::viewAsText() { FileItem * i = (FileItem *) currentItem(); QCopEnvelope e("QPE/Application/textedit","setDocument(QString)"); e << i->getFilePath(); // Global::execute( "textedit -f ", i->getFilePath() ); } void FileView::itemClicked( QListViewItem * i) { FileItem * t = (FileItem *) i; if( t == NULL ) return; if( t->isDir() ){ setDir( t->getFilePath() ); } } void FileView::itemDblClicked( QListViewItem * i) { if(menuKeepsOpen){ cancelMenuTimer(); } FileItem * t = (FileItem *) i; if(t == NULL) return; if(t->launch() == -1){ QMessageBox::warning( this, tr( "Launch Application" ), tr( "Launch failed!" ), tr( "Ok" ) ); } } void FileView::parentDir() { setDir( currentDir + "./.." ); } void FileView::lastDir() { if( dirHistory.count() == 0 ) return; QString newDir = dirHistory.last(); dirHistory.remove( dirHistory.last() ); generateDir( newDir ); } void FileView::contentsMousePressEvent( QMouseEvent * e ) { QListView::contentsMousePressEvent( e ); menuTimer.start( 750, TRUE ); } void FileView::contentsMouseReleaseEvent( QMouseEvent * e ) { QListView::contentsMouseReleaseEvent( e ); if(!menuKeepsOpen){ menuTimer.stop(); } } void FileView::cancelMenuTimer() { if( menuTimer.isActive() ) menuTimer.stop(); } void FileView::addToDocuments() { FileItem * i = (FileItem *) currentItem(); DocLnk f; QString n = i->text(0); n.replace(QRegExp("\\..*"),""); f.setName( n ); f.setFile( i->getFilePath() ); f.writeLink(); } void FileView::run() { FileItem * i = (FileItem *) currentItem(); i->launch(); } @@ -919,211 +900,192 @@ void FileBrowser::init(const QString & dir) pasteAction = new QAction( tr("Paste"), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); connect( pasteAction, SIGNAL( activated() ), fileView, SLOT( paste() ) ); pasteAction->addTo( toolBar ); // dirLabel = new QLabel(this, "DirLabel"); connect( fileView, SIGNAL( dirChanged() ), SLOT( updateDirMenu() ) ); updateDirMenu(); QCopChannel* pcmciaChannel = new QCopChannel( "QPE/Card", this ); connect( pcmciaChannel, SIGNAL(received(const QCString &, const QByteArray &)), this, SLOT(pcmciaMessage( const QCString &, const QByteArray &)) ); } void FileBrowser::pcmciaMessage( const QCString &msg, const QByteArray &) { if ( msg == "mtabChanged()" ) { // ## Only really needed if current dir is on a card fileView->updateDir(); } } void FileBrowser::changeCaption(const QString & dir) { setCaption( dir); } void FileBrowser::dirSelected( int id ) { int i = 0, j; QString dir; // Bulid target dir from menu while( (j = dirMenu->idAt( i )) != id ){ dir += dirMenu->text( j ).stripWhiteSpace(); if( dirMenu->text( j ) != "/" ) dir += "/"; i++; } dir += dirMenu->text( dirMenu->idAt( i ) ).stripWhiteSpace(); fileView->setDir( dir ); } void FileBrowser::updateDirMenu() { QString spc, cd = fileView->cd(); QStringList l = QStringList::split( "/", cd ); int i = 0; dirMenu->clear(); dirMenu->insertItem( tr( "/" ), this, SLOT( dirSelected(int) ) ); for ( QStringList::Iterator it = l.begin(); it != l.end(); ++it ) { spc.fill( ' ', i++); dirMenu->insertItem( spc + (*it), this, SLOT( dirSelected(int) ) ); } dirMenu->setItemChecked( dirMenu->idAt( l.count() ), TRUE ); lastAction->setEnabled( fileView->history().count() != 0 ); upAction->setEnabled( cd != "/" ); } void FileBrowser::sortName() { fileView->setSorting( 0, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); fileView->sort(); sortMenu->setItemChecked( sortMenu->idAt( 0 ), TRUE ); sortMenu->setItemChecked( sortMenu->idAt( 1 ), FALSE ); sortMenu->setItemChecked( sortMenu->idAt( 2 ), FALSE ); sortMenu->setItemChecked( sortMenu->idAt( 3 ), FALSE ); } void FileBrowser::sortSize() { fileView->setSorting( 1, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); fileView->sort(); sortMenu->setItemChecked( sortMenu->idAt( 0 ), FALSE ); sortMenu->setItemChecked( sortMenu->idAt( 1 ), TRUE ); sortMenu->setItemChecked( sortMenu->idAt( 2 ), FALSE ); sortMenu->setItemChecked( sortMenu->idAt( 3 ), FALSE ); } void FileBrowser::sortDate() { fileView->setSorting( 2, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); fileView->sort(); sortMenu->setItemChecked( sortMenu->idAt( 0 ), FALSE ); sortMenu->setItemChecked( sortMenu->idAt( 1 ), FALSE ); sortMenu->setItemChecked( sortMenu->idAt( 2 ), TRUE ); sortMenu->setItemChecked( sortMenu->idAt( 3 ), FALSE ); } void FileBrowser::sortType() { fileView->setSorting( 3, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); fileView->sort(); sortMenu->setItemChecked( sortMenu->idAt( 0 ), FALSE ); sortMenu->setItemChecked( sortMenu->idAt( 1 ), FALSE ); sortMenu->setItemChecked( sortMenu->idAt( 2 ), FALSE ); sortMenu->setItemChecked( sortMenu->idAt( 3 ), TRUE ); } void FileBrowser::updateSorting() { sortMenu->setItemChecked( sortMenu->idAt( 5 ), !sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); if ( sortMenu->isItemChecked( sortMenu->idAt( 0 ) ) ) sortName(); else if ( sortMenu->isItemChecked( sortMenu->idAt( 1 ) ) ) sortSize(); else if ( sortMenu->isItemChecked( sortMenu->idAt( 2 ) ) ) sortDate(); else sortType(); } void FileView::chPerm() { FileItem * i; QStringList fl; QString cmd; if((i = (FileItem *) firstChild()) == 0) return; while( i ){ if( i->isSelected() ){ fl += i->getFilePath(); } i = (FileItem *) i->nextSibling(); } if( fl.count() < 1 ) return; if( QMessageBox::warning( this, tr("Change permissions"), tr("Are you sure?"), tr("Yes"), tr("No") ) == 0) { for ( QStringList::Iterator it = fl.begin(); it != fl.end(); ++it ) { filePermissions *filePerm; filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)(*it)); filePerm->exec(); if( filePerm) delete filePerm; break; } updateDir(); } } void FileBrowser::updateShowHidden() { bool valShowHidden=viewMenu->isItemChecked( viewMenu->idAt( 0 ) ); valShowHidden=!valShowHidden; viewMenu->setItemChecked( viewMenu->idAt( 0 ), valShowHidden ); fileView->setShowHidden(valShowHidden); Config cfg("Filebrowser"); cfg.setGroup("View"); cfg.writeEntry("Hidden",valShowHidden?"TRUE":"FALSE"); fileView->updateDir(); } void FileBrowser::updateShowSymlinks() { bool valShowSymlinks=viewMenu->isItemChecked( viewMenu->idAt( 1 ) ); valShowSymlinks=!valShowSymlinks; viewMenu->setItemChecked( viewMenu->idAt( 1 ), valShowSymlinks ); fileView->setShowSymlinks(valShowSymlinks); Config cfg("Filebrowser"); cfg.setGroup("View"); cfg.writeEntry("Symlinks",valShowSymlinks?"TRUE":"FALSE"); fileView->updateDir(); } void FileBrowser::updateShowThumbnails() { bool valShowThumbnails=viewMenu->isItemChecked( viewMenu->idAt( 2 ) ); valShowThumbnails=!valShowThumbnails; viewMenu->setItemChecked( viewMenu->idAt( 2 ), valShowThumbnails ); fileView->setShowThumbnails(valShowThumbnails); Config cfg("Filebrowser"); cfg.setGroup("View"); cfg.writeEntry("Thumbnails",valShowThumbnails?"TRUE":"FALSE"); fileView->updateDir(); } void FileBrowser::cleanUp() { QString cmdr = "rm -rf /tmp/filebrowserThumbnailCache"; // qDebug("exit"); system(cmdr.latin1()); } - -{ - bool valShowThumbnails=viewMenu->isItemChecked( viewMenu->idAt( 2 ) ); - valShowThumbnails=!valShowThumbnails; - viewMenu->setItemChecked( viewMenu->idAt( 2 ), valShowThumbnails ); - fileView->setShowThumbnails(valShowThumbnails); - - Config cfg("Filebrowser"); - cfg.setGroup("View"); - cfg.writeEntry("Thumbnails",valShowThumbnails?"TRUE":"FALSE"); - - fileView->updateDir(); -} - -void FileBrowser::cleanUp() { - QString cmdr = "rm -rf /tmp/filebrowserThumbnailCache"; -// qDebug("exit"); - system(cmdr.latin1()); -} |