From: Scott H. <sh...@us...> - 2004-09-20 01:29:41
|
Update of /cvsroot/mpio/kmpio/kmpio In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26489/kmpio Modified Files: kmpio_interface.cpp kmpio_interface.h kmpio_mainwidget.cpp kmpio_mainwidget.h Log Message: added recursive upload/download/delete functionss. added recursive upload/download/delete functions. Index: kmpio_mainwidget.cpp =================================================================== RCS file: /cvsroot/mpio/kmpio/kmpio/kmpio_mainwidget.cpp,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** kmpio_mainwidget.cpp 25 Apr 2004 15:09:42 -0000 1.25 --- kmpio_mainwidget.cpp 20 Sep 2004 01:29:32 -0000 1.26 *************** *** 385,389 **** QAction *shiftFileUpAction = new QAction( this, "shiftFileUpAction"); shiftFileUpAction->setText( trUtf8( "Move file up in MPIO play list. Hot-Key: Alt+Up" ) ); ! shiftFileUpAction->setMenuText( trUtf8( "Playlist: Move file up\tAlt-Up" ) ); shiftFileUpAction->setAccel( 0 ); --- 385,389 ---- QAction *shiftFileUpAction = new QAction( this, "shiftFileUpAction"); shiftFileUpAction->setText( trUtf8( "Move file up in MPIO play list. Hot-Key: Alt+Up" ) ); ! shiftFileUpAction->setMenuText( trUtf8( "Playlist: Move file up\tAlt+Up" ) ); shiftFileUpAction->setAccel( 0 ); *************** *** 403,406 **** --- 403,412 ---- renameFileAction->setAccel( 0 ); + + QAction *deleteFileAction = new QAction( this, "deleteFileAction"); + deleteFileAction->setText( trUtf8( "Delete file in MPIO memory. Hot-Key: Del" ) ); + deleteFileAction->setMenuText( trUtf8( "&Delete MPIO file" ) ); + deleteFileAction->setAccel( 0 ); + QAction *uploadAsMusicAction = new QAction( this, "uploadMusicAction"); uploadAsMusicAction->setText( trUtf8( "Upload music files to MPIO player") ); *************** *** 409,413 **** QAction *uploadAsPlainAction = new QAction( this, "uploadPlainAction"); ! uploadAsPlainAction->setText( trUtf8( "Upload music files to MPIO player") ); uploadAsPlainAction->setMenuText( trUtf8( "upload &Plain files" ) ); uploadAsPlainAction->setAccel( 0 ); --- 415,419 ---- QAction *uploadAsPlainAction = new QAction( this, "uploadPlainAction"); ! uploadAsPlainAction->setText( trUtf8( "Upload plain files to MPIO player") ); uploadAsPlainAction->setMenuText( trUtf8( "upload &Plain files" ) ); uploadAsPlainAction->setAccel( 0 ); *************** *** 466,469 **** --- 472,477 ---- uploadAsConfAction->addTo( uploadMenu ); + deleteFileAction->addTo( mpioMenu ); + mpioMenu->insertSeparator(); shiftFileUpAction->addTo( mpioMenu ); *************** *** 498,501 **** --- 506,511 ---- connect( renameFileAction, SIGNAL( activated() ), this, SLOT( mpioRenameFile() ) ); + connect( deleteFileAction, SIGNAL( activated() ), + this, SLOT( deleteFile() ) ); connect( playerInfoAction, SIGNAL( activated() ), this, SLOT( playerInfo() ) ); *************** *** 707,712 **** for ( QStringList::Iterator it = entries.begin(); it != entries.end(); ++it ) { ! ftotal = QStringList::split("*", *it); lvi = new QListViewItem(kmpio_externalfiles, kmpio_externalfiles->lastItem()); lvi->setText(0,ftotal[0]); --- 717,726 ---- for ( QStringList::Iterator it = entries.begin(); it != entries.end(); ++it ) { ! ftotal = QStringList::split("*", *it); + + if (ftotal[3].left(7) == FTYPE_NAME_UNKNOWN) // skip unknown filetypes + continue; + lvi = new QListViewItem(kmpio_externalfiles, kmpio_externalfiles->lastItem()); lvi->setText(0,ftotal[0]); *************** *** 731,736 **** for ( QStringList::Iterator it = entries.begin(); it != entries.end(); ++it ) { ! ftotal = QStringList::split("*", *it); lvi = new QListViewItem(kmpio_internalfiles, kmpio_internalfiles->lastItem()); lvi->setText(0,ftotal[0]); --- 745,754 ---- for ( QStringList::Iterator it = entries.begin(); it != entries.end(); ++it ) { ! ftotal = QStringList::split("*", *it); + + if (ftotal[3].left(7) == FTYPE_NAME_UNKNOWN) // skip unknown filetypes + continue; + lvi = new QListViewItem(kmpio_internalfiles, kmpio_internalfiles->lastItem()); lvi->setText(0,ftotal[0]); *************** *** 843,846 **** --- 861,865 ---- int tabsel = targetTab->currentPageIndex(); + if (tabsel == 0) { curr = kmpio_internalfiles->currentItem(); *************** *** 911,914 **** --- 930,934 ---- QListViewItem *curr; QStringList fnames; + QValueList<QListViewItem*> itemList; int tab = targetTab->currentPageIndex(); *************** *** 929,934 **** QListViewItem *curr; QStringList fnames; ! int tab = targetTab->currentPageIndex(); if (tab == 0) --- 949,960 ---- QListViewItem *curr; QStringList fnames; + QValueList<QListViewItem*> itemList; + int tab; ! if (!isConnected()) { ! not_connected(); ! return; ! } ! tab = targetTab->currentPageIndex(); if (tab == 0) *************** *** 938,948 **** while (curr != NULL) { ! if ( (curr->isSelected()) & ! (curr->text(3) != QString(FTYPE_NAME_DIR) ) ) { ! fnames.append(curr->text(0)); ! } ! curr = curr->nextSibling(); } ! // for ( QStringList::Iterator it = fnames.begin(); // it != fnames.end(); ++it ) { --- 964,986 ---- while (curr != NULL) { ! if ( (curr->isSelected()) ) ! itemList.append(curr); ! curr = curr->nextSibling(); } ! ! for ( QValueList<QListViewItem*>::Iterator it = itemList.begin(); ! it != itemList.end(); ++it ) ! { ! curr = *it; ! if (curr->text(3) == QString(FTYPE_NAME_DIR) ) ! { ! downloadDir(curr->text(0)); ! } ! else ! { ! fnames.append(curr->text(0)); ! } ! } ! // for ( QStringList::Iterator it = fnames.begin(); // it != fnames.end(); ++it ) { *************** *** 961,964 **** --- 999,1063 ---- } + void kmpio_mainwidget::downloadDir(QString dirname) + { + QStringList entries, ftotal, fnames; + QString oldPath; + + int tab = targetTab->currentPageIndex(); + if (tab == 0) + { + if (interface->chdirInternal(dirname)) + return; + // give error message if fail + } + else + { + if(interface->chdirExternal(dirname)) + return; + // give error message if fail + } + oldPath = QDir::current().absPath(); // QDir::currentDirPath(); + + if (!QDir::setCurrent(dirname)) + { + QDir::current().mkdir(dirname); + QDir::setCurrent(dirname); + } + + if (tab == 0) + entries = interface->getDirectoryInternal(); + else + entries = interface->getDirectoryExternal(); + + + for ( QStringList::Iterator it = entries.begin(); + it != entries.end(); ++it ) { + ftotal = QStringList::split("*", *it); + if (ftotal[3].left(7) == FTYPE_NAME_UNKNOWN) // skip unknown filetypes + continue; + if (ftotal[3] == QString(FTYPE_NAME_DIR)) + { + if (ftotal[0] == "." || ftotal[0] == "..") + continue; + downloadDir(ftotal[0]); + } + else + fnames.append(ftotal[0]); + } + + if (tab == 0) { + interface->mgetFile(fnames, MPIO_INTERNAL_MEM); + interface->chdirInternal(".."); + readDirInternal(); + } else { + interface->mgetFile(fnames, MPIO_EXTERNAL_MEM); + interface->chdirExternal(".."); + readDirExternal(); + } + QDir::setCurrent(oldPath); + + download_completed(); + } + void kmpio_mainwidget::download_completed() { parseCurrentDir(); *************** *** 991,1000 **** return; } ! QListViewItem *curr; QStringList fnames; QFileInfo testname; int tab = targetTab->currentPageIndex(); ! curr = kmpio_localfiles->firstChild(); while (curr != NULL) { --- 1090,1115 ---- return; } ! QListViewItem *curr = NULL, *fileCurr; QStringList fnames; QFileInfo testname; int tab = targetTab->currentPageIndex(); ! fileCurr = kmpio_localfiles->firstChild(); ! // fprintf (stderr, "%p\n", fileCurr); ! while (fileCurr != NULL) ! { ! if (fileCurr->isSelected()) ! { ! curr = kmpio_localfiles->firstChild(); ! break; ! } ! fileCurr = fileCurr->nextSibling(); ! } ! if (curr == NULL) ! { ! curr = kmpio_localdirectory->firstChild(); ! } ! ! // fprintf (stderr, "%p\n", curr); while (curr != NULL) { *************** *** 1002,1007 **** testname = curr->text(0); if (testname.isFile()) { ! fnames.append(curr->text(0)); } } curr = curr->nextSibling(); --- 1117,1131 ---- testname = curr->text(0); if (testname.isFile()) { ! fnames.append(curr->text(0)); } + else if(testname.isDir()) + { + if (testname.fileName() == "." || + testname.fileName() == "..") + continue; + fprintf (stderr, "upload %s\n", (const char*)testname.fileName()); + uploadDir(testname.fileName(), type); + } + } curr = curr->nextSibling(); *************** *** 1022,1025 **** --- 1146,1150 ---- interface->mputFileAs(fnames,MPIO_EXTERNAL_MEM,type); + upload_completed(); } *************** *** 1034,1041 **** } void kmpio_mainwidget::deleteFile() { QListViewItem *curr; QStringList fnames; ! int mem = targetTab->currentPageIndex(); if (mem == 0) --- 1159,1237 ---- } + void kmpio_mainwidget::uploadDir(QString dirname, mpio_filetype_t type) + { + int tab = targetTab->currentPageIndex(); + if (tab == 0) + { + if (interface->changeDirectory(dirname, MPIO_INTERNAL_MEM)) + { + interface->createDirectory(dirname, MPIO_INTERNAL_MEM); + interface->chdirInternal(dirname); + } + } + else + { + if(interface->changeDirectory(dirname, MPIO_EXTERNAL_MEM)) + { + interface->createDirectory(dirname, MPIO_EXTERNAL_MEM); + interface->chdirExternal(dirname); + } + } + QDir d(QDir::current()); + fprintf (stderr, "dir: %s\n", (const char*)d.absPath()); + d.cd(dirname); + + QString fileTypeString = fileTypes->currentText(); + fileTypeString.replace( QRegExp(".*\\("), "" ); + fileTypeString.replace( QRegExp("\\).*"), "" ); + + d.setFilter (QDir::All); + d.setNameFilter(fileTypeString.lower() + QString(";") + fileTypeString.upper()); + d.setMatchAllDirs(true); + d.setSorting( QDir::Name | QDir::DirsFirst ); + + fprintf (stderr, "dir: %s\n", (const char*)d.absPath()); + + QString oldPath = QDir::current().absPath(); + QDir::setCurrent(d.absPath()); + + const QFileInfoList *list = d.entryInfoList(); + QFileInfoListIterator it( *list ); + QFileInfo *fi; + QString strsize; + QStringList fnames; + + while ( (fi = it.current()) != 0 ) { + if (fi->isDir()) { + if (fi->fileName() != "." && fi->fileName() != "..") + uploadDir(fi->fileName(), type); + } else { + fnames.append(fi->fileName()); + } + ++it; + } + + + if (tab == 0) { + interface->mputFileAs(fnames,MPIO_INTERNAL_MEM,type); + interface->chdirInternal(".."); + } else { + interface->mputFileAs(fnames,MPIO_EXTERNAL_MEM,type); + interface->chdirExternal(".."); + } + QDir::setCurrent(oldPath); + } + void kmpio_mainwidget::deleteFile() { QListViewItem *curr; QStringList fnames; ! QStringList dirNames; ! int mem; ! ! if (!isConnected()) { ! not_connected(); ! return; ! } ! mem = targetTab->currentPageIndex(); if (mem == 0) *************** *** 1045,1055 **** while (curr != NULL) { ! if (curr->isSelected()) { ! fnames.append(curr->text(0)); ! } curr = curr->nextSibling(); } ! ! if (!fnames.isEmpty()) { QString msg; msg.sprintf("Are you sure you want to delete %d file%s\n" --- 1241,1259 ---- while (curr != NULL) { ! if (curr->isSelected()) { ! if (curr->text(3) == QString(FTYPE_NAME_DIR)) { ! QString dirName = curr->text(0); ! if (dirName == QString(".") || dirName == QString("..")) ! continue; ! dirNames.append(curr->text(0)); ! } else { ! fnames.append(curr->text(0)); ! } ! } curr = curr->nextSibling(); } ! ! ! if (!fnames.isEmpty() || !dirNames.isEmpty()) { QString msg; msg.sprintf("Are you sure you want to delete %d file%s\n" *************** *** 1072,1075 **** --- 1276,1284 ---- // interface->delFileExternal(fname); // } + for ( QStringList::Iterator it = dirNames.begin(); + it != dirNames.end(); ++it ) + { + deleteDir(QString(*it)); + } if (mem == 0) *************** *** 1079,1082 **** --- 1288,1344 ---- } } + delete_completed(); + } + + void kmpio_mainwidget::deleteDir(QString dirname) + { + int tab = targetTab->currentPageIndex(); + if (tab == 0) + { + if (interface->changeDirectory(dirname, MPIO_INTERNAL_MEM)) + { + // give error message if fail + return; + } + } + else + { + if(interface->changeDirectory(dirname, MPIO_EXTERNAL_MEM)) + { + // give error message if fail + return; + } + } + QStringList entries; + if (tab == 0) + entries = interface->getDirectoryInternal(); + else + entries = interface->getDirectoryExternal(); + QStringList ftotal, fnames; + + for ( QStringList::Iterator it = entries.begin(); + it != entries.end(); ++it ) { + ftotal = QStringList::split("*", *it); + if (ftotal[3] == FTYPE_NAME_UNKNOWN) + continue; + if (ftotal[3] == QString(FTYPE_NAME_DIR)) + { + if (ftotal[0] == "." || ftotal[0] == "..") + continue; + deleteDir(ftotal[0]); + } + else + fnames.append(ftotal[0]); + } + + if (tab == 0) { + interface->mdelFile(fnames, MPIO_INTERNAL_MEM); + interface->chdirInternal(".."); + interface->delFileInternal(dirname); + } else { + interface->mdelFile(fnames, MPIO_EXTERNAL_MEM); + interface->chdirExternal(".."); + interface->delFileExternal(dirname); + } } Index: kmpio_interface.cpp =================================================================== RCS file: /cvsroot/mpio/kmpio/kmpio/kmpio_interface.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** kmpio_interface.cpp 25 Nov 2003 18:47:33 -0000 1.15 --- kmpio_interface.cpp 20 Sep 2004 01:29:31 -0000 1.16 *************** *** 224,228 **** tmp = tm.toString(Qt::LocalDate).latin1(); } ! fileinfo.sprintf("%d*"+tmp, fsize ); } --- 224,228 ---- tmp = tm.toString(Qt::LocalDate).latin1(); } ! fileinfo.sprintf("%d* "+tmp, fsize ); } *************** *** 237,245 **** int kmpio_interface::chdirExternal(QString fname) { ! return changeDirectory(fname, MPIO_EXTERNAL_MEM); } int kmpio_interface::chdirInternal(QString fname) { ! return changeDirectory(fname, MPIO_INTERNAL_MEM); } --- 237,261 ---- int kmpio_interface::chdirExternal(QString fname) { ! int p; ! p = changeDirectory(fname, MPIO_EXTERNAL_MEM); ! ! if (p != 0) { ! // Error occurred ! progress->hide(); ! failure(); ! } ! return p; } int kmpio_interface::chdirInternal(QString fname) { ! int p; ! p = changeDirectory(fname, MPIO_INTERNAL_MEM); ! ! if (p != 0) { ! // Error occurred ! progress->hide(); ! failure(); ! } ! return p; } *************** *** 250,259 **** p = mpio_directory_cd( handle, card, (unsigned char*)fname_utf8.data() ); - - if (p != 0) { - // Error occurred - progress->hide(); - failure(); - } return p; } --- 266,269 ---- Index: kmpio_interface.h =================================================================== RCS file: /cvsroot/mpio/kmpio/kmpio/kmpio_interface.h,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** kmpio_interface.h 26 Oct 2003 17:30:29 -0000 1.12 --- kmpio_interface.h 20 Sep 2004 01:29:32 -0000 1.13 *************** *** 44,47 **** --- 44,48 ---- #define FTYPE_NAME_DIR "Directory" #define FTYPE_NAME_PLAIN "Plain" + #define FTYPE_NAME_UNKNOWN "Unknown" class kmpio_progress; Index: kmpio_mainwidget.h =================================================================== RCS file: /cvsroot/mpio/kmpio/kmpio/kmpio_mainwidget.h,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** kmpio_mainwidget.h 26 Sep 2003 17:42:45 -0000 1.13 --- kmpio_mainwidget.h 20 Sep 2004 01:29:32 -0000 1.14 *************** *** 152,156 **** --- 152,158 ---- virtual void mpioDblClick(); virtual void downloadFile(); + virtual void downloadDir(QString dirname); virtual void uploadFile(); + virtual void uploadDir(QString dirname, mpio_filetype_t type); virtual void uploadMusicFile(); *************** *** 164,167 **** --- 166,171 ---- virtual void mpioDirectorySelected(); virtual void deleteFile(); + virtual void deleteDir(QString dirname); + virtual void formatInternalMemory(); virtual void formatExternalMemory(); |