void edit() /* This function will edit an existing record */ { int index; struct product tempProduct; unsigned int oldcode=0; do{ clrscr(); puts("\t\t\tProduct Edit\n\n\n"); oldcode=getExistingCode("Enter Code of product to Edit(0 for cancel): "); // Get a valid Code, This is previous code if(oldcode==0) return; // if 0 was entered, return to main menu index=getIndexByCode(oldcode); // Get index of valid code tempProduct.code = getNewCode("Enter a new code for change between 0 and 65535: ") ; // Get a valid Code, This is new code strcpy( tempProduct.name , getNewName("Enter a new name for change without spaces (max 50 characters): ") ); // Get a valid Name tempProduct.price = getNewPrice("Enter a new price for change between 0 and 4294967295: ") ; // Get a valid Price arrMain[index].code = tempProduct.code ; // Put code into main array strcpy( arrMain[index].name , tempProduct.name ); // Put name into main array arrMain[index].price = tempProduct.price ; // Put price into main array puts("\n Saved..."); // Record Edited, tell user }while(yesno("Do you want to edit a new product? ")==true); getch(); // wait... }
/* ============================================================================= =============================================================================== */ bool CWorld::addTexture(CTextureLayer &Texture, int iNdx) { if (!Texture.getName().size()) Texture.setName(getFileNameBase(Texture.getLink())); if (!Texture.getName().size()) Texture.setName("New Image"); if (getTextureSet().getTextureLayerIndex(Texture.getName()) != -1) { string str; for (int i = 1; getTextureSet().getTextureLayerIndex(str = getNewName(Texture.getName(), i)) != -1; i++); Texture.setName(str); } if ((Texture.getLink().substr(0, 11) == "datasvr/GIS") && !getDDSTileSupport()) { cout << ("DDS Texture Support unavailable. Changing DDS Tiled set to gradient."); Texture.setID("grad"); Texture.editGradient().addFile("system/gradients/land_tones.bmp", 0, EARTHMAX); Texture.editGradient().addFile("system/gradients/sea_1.bmp", EARTHMIN, 0); Texture.editGradient().updateMap(); } bool bRet = getTerrain().addTexture(Texture, iNdx); return bRet; }
/* ============================================================================= =============================================================================== */ bool CWorld::addLayout(CLayout &Layout, int iNdx) { if (!Layout.getName().size()) Layout.setName(getFileNameBase(Layout.getLink())); if (!Layout.getName().size()) Layout.setName("New Layout"); if (getLayoutSet().getLayoutIndex(Layout.getName()) != -1) { string str; for (int i = 1; getLayoutSet().getLayoutIndex(str = getNewName(Layout.getName(), i)) != -1; i++); Layout.setName(str); } bool bRet = getLayoutSet().addLayout(Layout, iNdx); return bRet; }
/* ============================================================================= =============================================================================== */ bool CWorld::addDataLayer(CDataLayer &DataLayer, int iNdx) { if (!DataLayer.getName().size()) DataLayer.setName(getFileNameBase(DataLayer.getLink())); if (!DataLayer.getName().size()) DataLayer.setName("New Dataset"); if (getDataSet().getDataLayerIndex(DataLayer.getName()) != -1) { string str; for (int i = 1; getDataSet().getDataLayerIndex(str = getNewName(DataLayer.getName(), i)) != -1; i++); DataLayer.setName(str); } bool bRet = getDataSet().addDataLayer(DataLayer, iNdx); return bRet; }
/* ============================================================================= =============================================================================== */ bool CWorld::addTerrain(CTerrainLayer &Terrain, int iNdx) { if (!Terrain.getName().size()) Terrain.setName(getFileNameBase(Terrain.getLink())); if (!Terrain.getName().size()) Terrain.setName("New Terrain"); if (getTerrainSet().getTerrainLayerIndex(Terrain.getName()) != -1) { string str; for (int i = 1; getTerrainSet().getTerrainLayerIndex(str = getNewName(Terrain.getName(), i)) != -1; i++); Terrain.setName(str); } bool bRet = getTerrain().addTerrain(Terrain, iNdx); return bRet; }
void EditConfigWindow::addNewParameter(ConfigMap::RegisterType type) { ConfigMap::Parameter newParameter; newParameter.m_type = type; QString newName; if (!getNewName(newName)) return; if (editParameter(newParameter)) { m_config->setNewParameter(newName.toStdString(), newParameter); m_tables[type]->clearContents(); m_map = m_config->m_map; initTab(type); } }
void Widget::example(){ QString text = tr("example"); if(isRename()){ if(isNewName()){ text = getNewName(); } if(isPrependExifDate()){ text.prepend(getDateTime("").toString(ui->exifLineEdit->text())); } if(isAppendExifDate()){ text.append(getDateTime("").toString(ui->exifLineEdit->text())); } if(!(getPrefix().isEmpty() && getSuffix().isEmpty())){ text.prepend(getPrefix()); text.append(getSuffix()); } } ui->exampleLabel->setText(text); }
void create()/* This function appends a new record to main array */ { struct product tempProduct; do{ clrscr(); puts("\t\t\tNew Product\n\n\n"); tempProduct.code = getNewCode("Enter a new code between 0 and 65535(0 for cancel): ") ; // Get a valid Code if(tempProduct.code==0) return; // if 0 was entered, return to main menu strcpy( tempProduct.name , getNewName("Enter a new name without spaces (max 50 characters): ") ); // Get a valid Name tempProduct.price = getNewPrice("Enter a new price between 0 and 4294967295: ") ; // Get a valid Price arrMain[eoarr].blnInclude = true ; // take this record into account arrMain[eoarr].code = tempProduct.code ; // Put code into main array strcpy( arrMain[eoarr].name , tempProduct.name ); // Put name into main array arrMain[eoarr].price = tempProduct.price ; // Put price into main array eoarr++; // plus one array counter, a new record is appended to array puts("\n Saved..."); }while(yesno("Do you want to enter a new Product details?")==true); getch(); }
void K3bDataUrlAddingDialog::slotCopyMoveItems() { if( m_bCanceled ) return; // // Pop first item from the item list // K3bDataItem* item = m_items.first().first; K3bDirItem* dir = m_items.first().second; m_items.remove( m_items.begin() ); ++m_filesHandled; m_infoLabel->setText( item->k3bPath() ); if( m_totalFiles == 0 ) m_counterLabel->setText( QString("(%1)").arg(m_filesHandled) ); else m_counterLabel->setText( QString("(%1/%2)").arg(m_filesHandled).arg(m_totalFiles) ); if( dir == item->parent() ) { kdDebug() << "(K3bDataUrlAddingDialog) trying to move an item into its own parent dir." << endl; } else if( dir == item ) { kdDebug() << "(K3bDataUrlAddingDialog) trying to move an item into itselft." << endl; } else { // // Let's see if an item with that name alredy exists // if( K3bDataItem* oldItem = dir->find( item->k3bName() ) ) { // // reuse an existing dir: move all child items into the old dir // if( oldItem->isDir() && item->isDir() ) { const QPtrList<K3bDataItem>& cl = dynamic_cast<K3bDirItem*>( item )->children(); for( QPtrListIterator<K3bDataItem> it( cl ); *it; ++it ) m_items.append( qMakePair( *it, dynamic_cast<K3bDirItem*>( oldItem ) ) ); // FIXME: we need to remove the old dir item } // // we cannot replace files in the old session with dirs and vice versa (I think) // files are handled in K3bFileItem constructor and dirs handled above // else if( oldItem->isFromOldSession() && item->isDir() != oldItem->isDir() ) { QString newName; if( getNewName( newName, dir, newName ) ) { if( m_copyItems ) item = item->copy(); item->setK3bName( newName ); dir->addDataItem( item ); } } else if( m_bExistingItemsReplaceAll ) { // // if we replace an item from an old session K3bDirItem::addDataItem takes care // of replacing the item // if( !oldItem->isFromOldSession() ) delete oldItem; if( m_copyItems ) item = item->copy(); dir->addDataItem( item ); } else if( !m_bExistingItemsIgnoreAll ) { switch( K3bMultiChoiceDialog::choose( i18n("File already exists"), i18n("<p>File <em>%1</em> already exists in " "project folder <em>%2</em>.") .arg( item->k3bName() ) .arg("/" + dir->k3bPath()), QMessageBox::Warning, this, 0, 6, KGuiItem( i18n("Replace"), QString::null, i18n("Replace the existing file") ), KGuiItem( i18n("Replace All"), QString::null, i18n("Always replace existing files") ), KGuiItem( i18n("Ignore"), QString::null, i18n("Keep the existing file") ), KGuiItem( i18n("Ignore All"), QString::null, i18n("Always keep the existing file") ), KGuiItem( i18n("Rename"), QString::null, i18n("Rename the new file") ), KStdGuiItem::cancel() ) ) { case 2: // replace all m_bExistingItemsReplaceAll = true; // fallthrough case 1: // replace // // if we replace an item from an old session K3bDirItem::addDataItem takes care // of replacing the item // if( !oldItem->isFromOldSession() ) delete oldItem; if( m_copyItems ) item = item->copy(); dir->addDataItem( item ); break; case 4: // ignore all m_bExistingItemsIgnoreAll = true; // fallthrough case 3: // ignore // do nothing break; case 5: {// rename QString newName; if( getNewName( newName, dir, newName ) ) { if( m_copyItems ) item = item->copy(); item->setK3bName( newName ); dir->addDataItem( item ); } break; } case 6: // cancel slotCancel(); return; } } } // // No old item with the same name // else { if( m_copyItems ) item = item->copy(); dir->addDataItem( item ); } } if( m_items.isEmpty() ) { m_dirSizeJob->cancel(); accept(); } else { updateProgress(); QTimer::singleShot( 0, this, SLOT(slotCopyMoveItems()) ); } }
void K3bDataUrlAddingDialog::slotAddUrls() { if( m_bCanceled ) return; // add next url KURL url = m_urlQueue.first().first; K3bDirItem* dir = m_urlQueue.first().second; m_urlQueue.remove( m_urlQueue.begin() ); // // HINT: // we only use QFileInfo::absFilePath() and QFileInfo::isHidden() // both do not cause QFileInfo to stat, thus no speed improvement // can come from removing QFileInfo usage here. // QFileInfo info(url.path()); QString absFilePath( info.absFilePath() ); QString resolved( absFilePath ); bool valid = true; k3b_struct_stat statBuf, resolvedStatBuf; bool isSymLink = false; bool isDir = false; bool isFile = false; ++m_filesHandled; #if 0 m_infoLabel->setText( url.path() ); if( m_totalFiles == 0 ) m_counterLabel->setText( QString("(%1)").arg(m_filesHandled) ); else m_counterLabel->setText( QString("(%1/%2)").arg(m_filesHandled).arg(m_totalFiles) ); #endif // // 1. Check if we want and can add the url // if( !url.isLocalFile() ) { valid = false; m_nonLocalFiles.append( url.path() ); } else if( k3b_lstat( QFile::encodeName(absFilePath), &statBuf ) != 0 ) { valid = false; m_notFoundFiles.append( url.path() ); } else if( !m_encodingConverter->encodedLocally( QFile::encodeName( url.path() ) ) ) { valid = false; m_invalidFilenameEncodingFiles.append( url.path() ); } else { isSymLink = S_ISLNK(statBuf.st_mode); isFile = S_ISREG(statBuf.st_mode); isDir = S_ISDIR(statBuf.st_mode); // symlinks are always readable and can always be added to a project // but we need to know if the symlink points to a directory if( isSymLink ) { resolved = K3b::resolveLink( absFilePath ); k3b_stat( QFile::encodeName(resolved), &resolvedStatBuf ); isDir = S_ISDIR(resolvedStatBuf.st_mode); } else { if( ::access( QFile::encodeName( absFilePath ), R_OK ) != 0 ) { valid = false; m_unreadableFiles.append( url.path() ); } else if( isFile && (unsigned long long)statBuf.st_size >= 0xFFFFFFFFULL ) { if ( !k3bcore->externalBinManager()->binObject( "mkisofs" )->hasFeature( "no-4gb-limit" ) ) { valid = false; m_tooBigFiles.append( url.path() ); } } } // FIXME: if we do not add hidden dirs the progress gets messed up! // // check for hidden and system files // if( valid ) { if( info.isHidden() && !addHiddenFiles() ) valid = false; if( S_ISCHR(statBuf.st_mode) || S_ISBLK(statBuf.st_mode) || S_ISFIFO(statBuf.st_mode) || S_ISSOCK(statBuf.st_mode) ) if( !addSystemFiles() ) valid = false; if( isSymLink ) if( S_ISCHR(resolvedStatBuf.st_mode) || S_ISBLK(resolvedStatBuf.st_mode) || S_ISFIFO(resolvedStatBuf.st_mode) || S_ISSOCK(resolvedStatBuf.st_mode) ) if( !addSystemFiles() ) valid = false; } } // // 2. Handle the url // QString newName = url.fileName(); // filenames cannot end in backslashes (mkisofs problem. See comments in k3bisoimager.cpp (escapeGraftPoint())) bool bsAtEnd = false; while( newName[newName.length()-1] == '\\' ) { newName.truncate( newName.length()-1 ); bsAtEnd = true; } if( bsAtEnd ) m_mkisofsLimitationRenamedFiles.append( url.path() + " -> " + newName ); // backup dummy name if( newName.isEmpty() ) newName = "1"; K3bDirItem* newDirItem = 0; // // The source is valid. Now check if the project already contains a file with that name // and if so handle it properly // if( valid ) { if( K3bDataItem* oldItem = dir->find( newName ) ) { // // reuse an existing dir // if( oldItem->isDir() && isDir ) newDirItem = dynamic_cast<K3bDirItem*>(oldItem); // // we cannot replace files in the old session with dirs and vice versa (I think) // files are handled in K3bFileItem constructor and dirs handled above // else if( oldItem->isFromOldSession() && isDir != oldItem->isDir() ) { if( !getNewName( newName, dir, newName ) ) valid = false; } else if( m_bExistingItemsIgnoreAll ) valid = false; else if( oldItem->localPath() == resolved ) { // // Just ignore if the same file is added again // valid = false; } else if( m_bExistingItemsReplaceAll ) { // if we replace an item from an old session the K3bFileItem constructor takes care // of replacing the item if( !oldItem->isFromOldSession() ) delete oldItem; } // // Let the user choose // else { switch( K3bMultiChoiceDialog::choose( i18n("File already exists"), i18n("<p>File <em>%1</em> already exists in " "project folder <em>%2</em>.") .arg(newName) .arg('/' + dir->k3bPath()), QMessageBox::Warning, this, 0, 6, KGuiItem( i18n("Replace"), QString::null, i18n("Replace the existing file") ), KGuiItem( i18n("Replace All"), QString::null, i18n("Always replace existing files") ), KGuiItem( i18n("Ignore"), QString::null, i18n("Keep the existing file") ), KGuiItem( i18n("Ignore All"), QString::null, i18n("Always keep the existing file") ), KGuiItem( i18n("Rename"), QString::null, i18n("Rename the new file") ), KStdGuiItem::cancel() ) ) { case 2: // replace all m_bExistingItemsReplaceAll = true; // fallthrough case 1: // replace // if we replace an item from an old session the K3bFileItem constructor takes care // of replacing the item if( !oldItem->isFromOldSession() ) delete oldItem; break; case 4: // ignore all m_bExistingItemsIgnoreAll = true; // fallthrough case 3: // ignore valid = false; break; case 5: // rename if( !getNewName( newName, dir, newName ) ) valid = false; break; case 6: // cancel slotCancel(); return; } } } } // // One more thing to warn the user about: We cannot follow links to folders since that // would change the doc. So we simply ask the user what to do with a link to a folder // if( valid ) { // let's see if this link starts a loop // that means if it points to some folder above this one // if so we cannot follow it anyway if( isDir && isSymLink && !absFilePath.startsWith( resolved ) ) { bool followLink = dir->doc()->isoOptions().followSymbolicLinks() || m_bFolderLinksFollowAll; if( !followLink && !m_bFolderLinksAddAll ) { switch( K3bMultiChoiceDialog::choose( i18n("Adding link to folder"), i18n("<p>'%1' is a symbolic link to folder '%2'." "<p>If you intend to make K3b follow symbolic links you should consider letting K3b do this now " "since K3b will not be able to do so afterwards because symbolic links to folders inside a " "K3b project cannot be resolved." "<p><b>If you do not intend to enable the option <em>follow symbolic links</em> you may safely " "ignore this warning and choose to add the link to the project.</b>") .arg(absFilePath) .arg(resolved ), QMessageBox::Warning, this, 0, 5, i18n("Follow link now"), i18n("Always follow links"), i18n("Add link to project"), i18n("Always add links"), KStdGuiItem::cancel() ) ) { case 2: m_bFolderLinksFollowAll = true; case 1: followLink = true; break; case 4: m_bFolderLinksAddAll = true; case 3: followLink = false; break; case 5: slotCancel(); return; } } if( followLink ) { absFilePath = resolved; isSymLink = false; // count the files in the followed dir if( m_dirSizeJob->active() ) m_dirSizeQueue.append( KURL::fromPathOrURL(absFilePath) ); else { m_progressWidget->setTotalSteps( 0 ); m_dirSizeJob->setUrls( KURL::fromPathOrURL(absFilePath) ); m_dirSizeJob->start(); } } } } // // Project valid also (we overwrite or renamed) // now create the new item // if( valid ) { // // Set the volume id from the first added url // only if the doc was not changed yet // if( m_urls.count() == 1 && !dir->doc()->isModified() && !dir->doc()->isSaved() ) { dir->doc()->setVolumeID( K3b::removeFilenameExtension( newName ) ); } if( isDir && !isSymLink ) { if( !newDirItem ) { // maybe we reuse an already existing dir newDirItem = new K3bDirItem( newName , dir->doc(), dir ); newDirItem->setLocalPath( url.path() ); // HACK: see k3bdiritem.h } QDir newDir( absFilePath ); int dirFilter = QDir::All|QDir::Hidden|QDir::System; QStringList dlist = newDir.entryList( dirFilter ); const QString& dot = KGlobal::staticQString( "." ); const QString& dotdot = KGlobal::staticQString( ".." ); dlist.remove( dot ); dlist.remove( dotdot ); for( QStringList::Iterator it = dlist.begin(); it != dlist.end(); ++it ) { m_urlQueue.append( qMakePair( KURL::fromPathOrURL(absFilePath + '/' + *it), newDirItem ) ); } } else { (void)new K3bFileItem( &statBuf, &resolvedStatBuf, url.path(), dir->doc(), dir, newName ); } } if( m_urlQueue.isEmpty() ) { m_dirSizeJob->cancel(); m_progressWidget->setProgress( 100 ); accept(); } else { updateProgress(); QTimer::singleShot( 0, this, SLOT(slotAddUrls()) ); } }
int RenameFileCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } string newName = outputfile; //look for file types if (fastafile != "") { newName = getNewName(fastafile, "fasta"); renameOrCopy(fastafile, newName); m->setFastaFile(newName); } if (qualfile != "") { newName = getNewName(qualfile, "qfile"); renameOrCopy(qualfile, newName); m->setQualFile(newName); } if (phylipfile != "") { newName = getNewName(phylipfile, "phylip"); renameOrCopy(phylipfile, newName); m->setPhylipFile(newName); } if (columnfile != "") { newName = getNewName(columnfile, "column"); renameOrCopy(columnfile, newName); m->setColumnFile(newName); } if (listfile != "") { newName = getNewName(listfile, "list"); renameOrCopy(listfile, newName); m->setListFile(newName); } if (rabundfile != "") { newName = getNewName(rabundfile, "rabund"); renameOrCopy(rabundfile, newName); m->setRabundFile(newName); } if (sabundfile != "") { newName = getNewName(sabundfile, "sabund"); renameOrCopy(sabundfile, newName); m->setSabundFile(newName); } if (namefile != "") { newName = getNewName(namefile, "name"); renameOrCopy(namefile, newName); m->setNameFile(newName); } if (groupfile != "") { newName = getNewName(groupfile, "group"); renameOrCopy(groupfile, newName); m->setGroupFile(newName); } if (treefile != "") { newName = getNewName(treefile, "tree"); renameOrCopy(treefile, newName); m->setTreeFile(newName); } if (sharedfile != "") { newName = getNewName(sharedfile, "shared"); renameOrCopy(sharedfile, newName); m->setSharedFile(newName); } if (relabundfile != "") { newName = getNewName(relabundfile, "relabund"); renameOrCopy(relabundfile, newName); m->setRelAbundFile(newName); } if (designfile != "") { newName = getNewName(designfile, "design"); renameOrCopy(designfile, newName); m->setDesignFile(newName); } if (sfffile != "") { newName = getNewName(sfffile, "sff"); renameOrCopy(sfffile, newName); m->setSFFFile(newName); } if (oligosfile != "") { newName = getNewName(oligosfile, "oligos"); renameOrCopy(oligosfile, newName); m->setOligosFile(newName); } if (accnosfile != "") { newName = getNewName(accnosfile, "accnos"); renameOrCopy(accnosfile, newName); m->setAccnosFile(newName); } if (taxonomyfile != "") { newName = getNewName(taxonomyfile, "taxonomy"); renameOrCopy(taxonomyfile, newName); m->setTaxonomyFile(newName); } if (constaxonomyfile != "") { newName = getNewName(constaxonomyfile, "constaxonomy"); renameOrCopy(constaxonomyfile, newName); m->setConsTaxonomyFile(newName); } if (flowfile != "") { newName = getNewName(flowfile, "flow"); renameOrCopy(flowfile, newName); m->setFlowFile(newName); } if (biomfile != "") { newName = getNewName(biomfile, "biom"); renameOrCopy(biomfile, newName); m->setBiomFile(newName); } if (countfile != "") { newName = getNewName(countfile, "count"); renameOrCopy(countfile, newName); m->setCountTableFile(newName); } if (summaryfile != "") { newName = getNewName(summaryfile, "summary"); renameOrCopy(summaryfile, newName); m->setSummaryFile(newName); } if (filefile != "") { newName = getNewName(filefile, "file"); renameOrCopy(filefile, newName); m->setFileFile(newName); } if (inputfile != "") { newName = getNewName(inputfile, "input"); renameOrCopy(inputfile, newName); } m->mothurOutEndLine(); m->mothurOut("Current files saved by mothur:"); m->mothurOutEndLine(); if (m->hasCurrentFiles()) { m->printCurrentFiles(""); } return 0; } catch(exception& e) { m->errorOut(e, "RenameFileCommand", "execute"); exit(1); } }