void BtTreeModel::copySelected(QList< QPair<QModelIndex, QString> > toBeCopied) { while ( ! toBeCopied.isEmpty() ) { QPair<QModelIndex,QString> thisPair = toBeCopied.takeFirst(); QModelIndex ndx = thisPair.first; QString name = thisPair.second; switch ( type(ndx) ) { case BtTreeItem::EQUIPMENT: Equipment *copyKit, *oldKit; oldKit = equipment(ndx); copyKit = Database::instance().newEquipment(oldKit); // Create a deep copy. copyKit->setName(name); break; case BtTreeItem::FERMENTABLE: Fermentable *copyFerm, *oldFerm; oldFerm = fermentable(ndx); copyFerm = Database::instance().newFermentable(oldFerm); // Create a deep copy. copyFerm->setName(name); break; case BtTreeItem::HOP: Hop *copyHop, *oldHop; oldHop = hop(ndx); copyHop = Database::instance().newHop(oldHop); // Create a deep copy. copyHop->setName(name); break; case BtTreeItem::MISC: Misc *copyMisc, *oldMisc; oldMisc = misc(ndx); copyMisc = Database::instance().newMisc(oldMisc); // Create a deep copy. copyMisc->setName(name); break; case BtTreeItem::RECIPE: Recipe *copyRec, *oldRec; oldRec = recipe(ndx); copyRec = Database::instance().newRecipe(oldRec); // Create a deep copy. copyRec->setName(name); break; case BtTreeItem::STYLE: Style *copyStyle, *oldStyle; oldStyle = style(ndx); copyStyle = Database::instance().newStyle(oldStyle); // Create a deep copy. copyStyle->setName(name); break; case BtTreeItem::YEAST: Yeast *copyYeast, *oldYeast; oldYeast = yeast(ndx); copyYeast = Database::instance().newYeast(oldYeast); // Create a deep copy. copyYeast->setName(name); break; default: Brewtarget::logW(QString("deleteSelected:: unknown type %1").arg(type(ndx))); } } }
void BtTreeModel::deleteSelected(QModelIndexList victims) { QModelIndexList toBeDeleted = victims; // trust me while ( ! toBeDeleted.isEmpty() ) { QModelIndex ndx = toBeDeleted.takeFirst(); switch ( type(ndx) ) { case BtTreeItem::EQUIPMENT: Database::instance().remove( equipment(ndx) ); break; case BtTreeItem::FERMENTABLE: Database::instance().remove( fermentable(ndx) ); break; case BtTreeItem::HOP: Database::instance().remove( hop(ndx) ); break; case BtTreeItem::MISC: Database::instance().remove( misc(ndx) ); break; case BtTreeItem::RECIPE: Database::instance().remove( recipe(ndx) ); break; case BtTreeItem::STYLE: Database::instance().remove( style(ndx) ); break; case BtTreeItem::YEAST: Database::instance().remove( yeast(ndx) ); break; case BtTreeItem::BREWNOTE: Database::instance().remove( brewNote(ndx) ); break; case BtTreeItem::FOLDER: // This one is weird. toBeDeleted += allChildren(ndx); removeFolder(ndx); break; default: Brewtarget::logW(QString("deleteSelected:: unknown type %1").arg(type(ndx))); } } }
void BtTreeModel::copySelected(QList< QPair<QModelIndex, QString> > toBeCopied) { bool failed = false; while ( ! toBeCopied.isEmpty() ) { QPair<QModelIndex,QString> thisPair = toBeCopied.takeFirst(); QModelIndex ndx = thisPair.first; QString name = thisPair.second; switch ( type(ndx) ) { case BtTreeItem::EQUIPMENT: Equipment *copyKit, *oldKit; oldKit = equipment(ndx); copyKit = Database::instance().newEquipment(oldKit); // Create a deep copy. if ( copyKit) copyKit->setName(name); else failed = true; break; case BtTreeItem::FERMENTABLE: Fermentable *copyFerm, *oldFerm; oldFerm = fermentable(ndx); copyFerm = Database::instance().newFermentable(oldFerm); // Create a deep copy. if ( copyFerm ) copyFerm->setName(name); else failed = true; break; case BtTreeItem::HOP: Hop *copyHop, *oldHop; oldHop = hop(ndx); copyHop = Database::instance().newHop(oldHop); // Create a deep copy. if ( copyHop ) copyHop->setName(name); else failed = true; break; case BtTreeItem::MISC: Misc *copyMisc, *oldMisc; oldMisc = misc(ndx); copyMisc = Database::instance().newMisc(oldMisc); // Create a deep copy. if ( copyMisc ) copyMisc->setName(name); else failed = true; break; case BtTreeItem::RECIPE: Recipe *copyRec, *oldRec; oldRec = recipe(ndx); copyRec = Database::instance().newRecipe(oldRec); // Create a deep copy. if ( copyRec ) copyRec->setName(name); else failed = true; break; case BtTreeItem::STYLE: Style *copyStyle, *oldStyle; oldStyle = style(ndx); copyStyle = Database::instance().newStyle(oldStyle); // Create a deep copy. if ( copyStyle ) copyStyle->setName(name); else failed = true; break; case BtTreeItem::YEAST: Yeast *copyYeast, *oldYeast; oldYeast = yeast(ndx); copyYeast = Database::instance().newYeast(oldYeast); // Create a deep copy. if ( copyYeast ) copyYeast->setName(name); else failed = true; break; default: Brewtarget::logW(QString("copySelected:: unknown type %1").arg(type(ndx))); } if ( failed ) { QMessageBox::warning(0, tr("Could not copy"), tr("There was an unexpected error creating %1").arg(name)); return; } } }
/* Decompress all of the files on the command line, or from stdin if no arguments. */ int main(int argc, char **argv) { FILE *in; int ret; unsigned char *source; void *dest; size_t len, got; #ifdef DEBUG /* process verbosity option */ if (argc > 1 && argv[1][0] == '-') { char *opt; --argc; opt = *++argv; while (*++opt) { if (*opt == 'v') yeast_verbosity++; else { fprintf(stderr, "deb: invalid option %s\n", opt); return 1; } } } #endif /* decompress each file on the remaining command line */ if (--argc) { for (;;) { in = fopen(*++argv, "rb"); if (in == NULL) { fprintf(stderr, "error opening %s\n", *argv); continue; } ret = load(in, &source, &len, 0); fclose(in); if (ret < 0) { fprintf(stderr, "error reading %s\n", *argv); continue; } if (ret > 0) { fputs("out of memory\n", stderr); return 1; } fputs(*argv, stderr); fputs(":\n", stderr); ret = yeast(&dest, &got, source, &len, 0); fprintf(stderr, "uncompressed length = %zu\n", got); if (ret) fprintf(stderr, "yeast() returned %d\n", ret); deliver(*argv, dest, got); free(dest); free(source); if (--argc == 0) break; putc('\n', stderr); } } /* or if no names on the remaining command line, decompress from stdin */ else { SET_BINARY_MODE(stdin); ret = load(stdin, &source, &len, 0); if (ret) { fputs(ret > 0 ? "out of memory\n" : "error reading stdin\n", stderr); return 1; } ret = yeast(&dest, &got, source, &len, 0); fprintf(stderr, "uncompressed length = %zu\n", got); if (ret) fprintf(stderr, "yeast() returned %d\n", ret); deliver("deb", dest, got); free(dest); free(source); } return 0; }