Beispiel #1
0
  QSharedPointer<CaptureDevice> TimeLapseCapture::parseArguments() {
    QCommandLineParser parser;
    ErrorMessageHelper die(err.device(), &parser);

    parser.setApplicationDescription("Tool for capture sequence of images from digital camera (V4L or GPhoto2 API).");
    parser.addHelpOption();
    parser.addVersionOption();

    QCommandLineOption outputOption(QStringList() << "o" << "output",
      QCoreApplication::translate("main", "Output directory."),
      QCoreApplication::translate("main", "directory"));
    parser.addOption(outputOption);

    QCommandLineOption verboseOption(QStringList() << "V" << "verbose",
      QCoreApplication::translate("main", "Verbose output."));
    parser.addOption(verboseOption);

    QCommandLineOption deviceOption(QStringList() << "d" << "device",
      QCoreApplication::translate("main", "Capture device."),
      QCoreApplication::translate("main", "device"));
    parser.addOption(deviceOption);

    QCommandLineOption listOption(QStringList() << "l" << "list",
      QCoreApplication::translate("main", "List available capture devices and exits."));
    parser.addOption(listOption);

    QCommandLineOption intervalOption(QStringList() << "i" << "interval",
      QCoreApplication::translate("main", "Capture interval (in milliseconds). Default is 10000."),
      QCoreApplication::translate("main", "interval"));
    parser.addOption(intervalOption);

    QCommandLineOption cntOption(QStringList() << "c" << "count",
      QCoreApplication::translate("main", "How many images should be captured. Default value is infinite."),
      QCoreApplication::translate("main", "count"));
    parser.addOption(cntOption);

    QCommandLineOption rowOption(QStringList() << "r" << "raw",
      QCoreApplication::translate("main", "Store all captured images in raw."));
    parser.addOption(rowOption);

    QCommandLineOption getShutterSpeedOption(QStringList() << "s" << "shutterspeed-options",
      QCoreApplication::translate("main", "Prints available shutterspeed setting choices and exits."));
    parser.addOption(getShutterSpeedOption);

    QCommandLineOption adaptiveShutterSpeedOption(QStringList() << "a" << "adaptive-shutterspeed",
      QCoreApplication::translate("main",
      "Camera shutterspeed will be adaptively changed after exposure metering.\n"
      "This option setup how many images should be used for exposure metering. \n"
      "Default value is 0 - it means that shutterspeed will not be changed by capture tool."
      ),
      QCoreApplication::translate("main", "count"));
    parser.addOption(adaptiveShutterSpeedOption);

    QCommandLineOption shutterSpeedStepOption(QStringList() << "shutterspeed-step",
      QCoreApplication::translate("main",
      "How large should be step when changing shutterspeed. \n"
      "Default value is 1."
      ),
      QCoreApplication::translate("main", "step"));
    parser.addOption(shutterSpeedStepOption);

    QCommandLineOption minShutterSpeedOption(QStringList() << "min-shutterspeed",
      QCoreApplication::translate("main", "Minimum shutterspeed (fastest shutter) used by adaptive shutterspeed"),
      QCoreApplication::translate("main", "shutterspeed"));
    parser.addOption(minShutterSpeedOption);

    QCommandLineOption maxShutterSpeedOption(QStringList() << "max-shutterspeed",
      QCoreApplication::translate("main",
      "Maximum shutterspeed (slowest shutter) used by adaptive shutterspeed.\n"
      "If camera supports BULB shutterspeed, it can be defined as \"BULB:XX\" here (it means bulb with XX s exposure)."
      ),
      QCoreApplication::translate("main", "shutterspeed"));
    parser.addOption(maxShutterSpeedOption);

    // Process the actual command line arguments given by the user
    parser.process(*this);

    // verbose?
    if (!parser.isSet(verboseOption)) {
      blackHole = new BlackHoleDevice();
      verboseOutput.setDevice(blackHole);
    } else {
      // verbose
      verboseOutput << "Turning on verbose output..." << endl;
      verboseOutput << applicationName() << " " << applicationVersion() << endl;
    }

    // raw?
    storeRawImages = parser.isSet(rowOption);

    // interval
    if (parser.isSet(intervalOption)) {
      bool ok = false;
      long i = parser.value(intervalOption).toLong(&ok);
      if (!ok) die << "Cant parse interval.";
      if (i <= 0) die << "Interval have to be possitive";
      interval = i;
    }

    // count
    if (parser.isSet(cntOption)) {
      bool ok = false;
      int i = parser.value(cntOption).toInt(&ok);
      if (!ok) die << "Cant parse count.";
      cnt = i;
    }

    // list devices?
    QList<QSharedPointer < CaptureDevice>> devices = listDevices();
    QSharedPointer<CaptureDevice> dev;
    if (parser.isSet(listOption)) {
      if (devices.isEmpty()) {
        die << QCoreApplication::translate("main", "No compatible capture device found");
      } else {
        out << "Found devices: " << endl;
        for (QSharedPointer<CaptureDevice> d : devices) {
          out << "  " << d->toString() << endl;
        }
      }
      std::exit(0);
    }
    // capture device
    bool assigned = false;
    if (!parser.isSet(deviceOption)) {
      verboseOutput << "Found devices: " << endl;
      for (QSharedPointer<CaptureDevice> d : devices) {
        if (!assigned) {
          dev = d;
          assigned = true;
        }
        verboseOutput << "  " << d->toString() << endl;
      }
      if (!assigned)
        die << "No supported device.";
    } else {
      QString devVal = parser.value(deviceOption);
      for (QSharedPointer<CaptureDevice> d : devices) {
        if (d->toString().contains(devVal, Qt::CaseInsensitive)) {
          assigned = true;
          dev = d;
          break;
        }
      }
      if (!assigned) {
        die << QString("No device matching \"%1\" found.").arg(devVal);
      }
    }
    out << "Using device " << dev->toString() << endl;

    // getShutterSpeedOption ?
    QList<ShutterSpeedChoice> choices = dev->getShutterSpeedChoices();
    if (parser.isSet(getShutterSpeedOption)) {
      if (choices.isEmpty()) {
        err << "Device " << dev->toShortString() << " don't support shutterspeed setting" << endl;
      } else {
        out << "Device " << dev->toShortString() << " shutterspeed choices:" << endl;
        for (ShutterSpeedChoice ch : choices) {
          out << "  " << ch.toString() << endl;
        }
        out << "Current shutter speed: " << dev->currentShutterSpeed().toString() << endl;
      }
      std::exit(0);
    }

    // automatic chutter speed
    // this functionality is experimental!
    if (parser.isSet(adaptiveShutterSpeedOption)) {
      bool ok = false;
      int changeThreshold = parser.value(adaptiveShutterSpeedOption).toInt(&ok);
      if (!ok) die << "Cant parse adaptive shutterspeed option.";

      if (changeThreshold > 0) {

        if (choices.isEmpty()) {
          die << "Camera don't support shutterspeed setting.";
        } else {

          ShutterSpeedChoice currentShutterSpeed;
          ShutterSpeedChoice minShutterSpeed;
          ShutterSpeedChoice maxShutterSpeed;

          currentShutterSpeed = dev->currentShutterSpeed();
          minShutterSpeed = choices.first();
          for (ShutterSpeedChoice ch : choices) {
            if ((!ch.isBulb()) && ch.toMicrosecond() > maxShutterSpeed.toMicrosecond())
              maxShutterSpeed = ch;
          }

          int shutterSpeedStep = 1;
          if (parser.isSet(shutterSpeedStepOption)) {
            bool ok = false;
            shutterSpeedStep = parser.value(shutterSpeedStepOption).toInt(&ok);
            if (!ok) die << "Cant parse shutterspeed step.";
            if (shutterSpeedStep < 1) die << "Shutterspeed step can be less than one.";
          }
          if (parser.isSet(minShutterSpeedOption)) {
            QString optStr = parser.value(minShutterSpeedOption);
            minShutterSpeed = getShutterSpeed(optStr, choices, &die);
          }
          if (parser.isSet(maxShutterSpeedOption)) {
            QString optStr = parser.value(maxShutterSpeedOption);
            maxShutterSpeed = getShutterSpeed(optStr, choices, &die);
          }

          out << "Using automatic shutter speed:" << endl;
          out << "  current shutter speed: " << currentShutterSpeed.toString() << endl;
          out << "  min shutter speed:     " << minShutterSpeed.toString() << endl;
          out << "  max shutter speed:     " << maxShutterSpeed.toString() << endl;
          out << "  change threshold:      " << changeThreshold << endl;
          out << "  change step:           " << shutterSpeedStep << endl;

          if (minShutterSpeed.toMicrosecond() <= 0
            || maxShutterSpeed.toMicrosecond() <= 0
            || maxShutterSpeed.toMicrosecond() < minShutterSpeed.toMicrosecond())
            die << "Invalid shutter speed configurarion";

          if (maxShutterSpeed.toMs() > interval) {
            err << QString("Warning: Maximum shutter speed (%1 ms) is greater than capture interval (%2 ms)!")
              .arg(maxShutterSpeed.toMs())
              .arg(interval) << endl;
          }
          shutterSpdAlg = new MatrixMeteringAlg(choices, currentShutterSpeed, minShutterSpeed, maxShutterSpeed,
            &err, &verboseOutput, changeThreshold, shutterSpeedStep);
        }
      }
    }

    // output
    if (!parser.isSet(outputOption))
      die << "Output directory is not set";
    output = QDir(parser.value(outputOption));
    if (output.exists())
      err << "Output directory exists already." << endl;
    if (!output.mkpath("."))
      die << QString("Can't create output directory %1 !").arg(output.path());

    return dev;
  }
cCommandLineInterface::cCommandLineInterface(QCoreApplication *qapplication)
{
	// text from http://sourceforge.net/projects/mandelbulber/
	parser.setApplicationDescription("Mandelbulber is an easy to use, "
		"handy application designed to help you render 3D Mandelbrot fractals called Mandelbulb "
		"and some other kind of 3D fractals like Mandelbox, Bulbbox, Juliabulb, Menger Sponge");
	parser.addHelpOption();
	parser.addVersionOption();
	QCommandLineOption noguiOption(QStringList() << "n" << "nogui",
		QCoreApplication::translate("main", "Start program without GUI."));

	QCommandLineOption keyframeOption(QStringList() << "K" << "keyframe",
		QCoreApplication::translate("main", "Render keyframe animation"));

	QCommandLineOption flightOption(QStringList() << "F" << "flight",
		QCoreApplication::translate("main", "Render flight animation"));

	QCommandLineOption startOption(QStringList() << "s" << "start",
		QCoreApplication::translate("main", "Start rendering from frame number <N>."),
		QCoreApplication::translate("main", "N"));

	QCommandLineOption endOption(QStringList() << "e" << "end",
		QCoreApplication::translate("main", "Stop rendering on frame number <N>."),
		QCoreApplication::translate("main", "N"));

	QCommandLineOption overrideOption(QStringList() << "O" << "override",
		QCoreApplication::translate("main", "Override item '<KEY>' from settings file with new value '<value>'.\n"
			"Specify multiple KEY=VALUE pairs by separating with a '#' (KEY1=VALUE1#KEY2=VALUE2). Quote whole expression to avoid whitespace parsing issues\n"
			"Override fractal parameter in the form 'fractal<N>_KEY=VALUE' with <N> as index of fractal"),
		QCoreApplication::translate("main", "KEY=VALUE"));

	QCommandLineOption listOption(QStringList() << "L" << "list",
		QCoreApplication::translate("main", "List all possible parameters '<KEY>' with corresponding default value '<value>'."));

	QCommandLineOption formatOption(QStringList() << "f" << "format",
		QCoreApplication::translate("main", "Image output format:\n"
			"jpg - JPEG format\n"
			"png - PNG format\n"
			"png16 - 16-bit PNG format\n"
			"png16alpha - 16-bit PNG with alpha channel format\n"
			"exr - EXR format"),
		QCoreApplication::translate("main", "FORMAT"));

	QCommandLineOption resOption(QStringList() << "r" << "res",
		QCoreApplication::translate("main", "Override image resolution."),
		QCoreApplication::translate("main", "WIDTHxHEIGHT"));

	QCommandLineOption fpkOption("fpk",
		QCoreApplication::translate("main", "Override frames per key parameter."),
		QCoreApplication::translate("main", "N"));

	QCommandLineOption serverOption(QStringList() << "S" << "server",
		QCoreApplication::translate("main", "Set application as a server listening for clients."));

	QCommandLineOption hostOption(QStringList() << "H" << "host",
		QCoreApplication::translate("main", "Set application as a client connected to server of given Host address"
			" (Host can be of type IPv4, IPv6 and Domain name address)."),
		QCoreApplication::translate("main", "N.N.N.N"));

	QCommandLineOption portOption(QStringList() << "p" << "port",
		QCoreApplication::translate("main", "Set network port number for Netrender (default 5555)."),
		QCoreApplication::translate("main", "N"));

	QCommandLineOption noColorOption(QStringList() << "C" << "no-cli-color",
		QCoreApplication::translate("main", "Start program without ANSI colors, when execution on CLI."));

	QCommandLineOption outputOption(QStringList() << "o" << "output",
		QCoreApplication::translate("main", "Save rendered image(s) to this file / folder."),
		QCoreApplication::translate("main", "N"));

	QCommandLineOption queueOption(QStringList() << "q" << "queue",
		QCoreApplication::translate("main", "Render all images from common queue."));

	QCommandLineOption statsOption(QStringList() << "stats",
		QCoreApplication::translate("main", "Show statistics while renderering in CLI mode."));

	QCommandLineOption helpInputOption(QStringList() << "help-input",
		QCoreApplication::translate("main", "Show help about input."));

	parser.addPositionalArgument("settings_file", QCoreApplication::translate("main",
		"file with fractal settings (program also tries\nto find file in ./mandelbulber/settings directory)\n"
		"When settings_file is put as a command line argument then program will start in noGUI mode"
		"<settings_file> can also be specified as a list, see all options with --help-input"
	));

	parser.addOption(noguiOption);
	parser.addOption(outputOption);
	parser.addOption(keyframeOption);
	parser.addOption(flightOption);
	parser.addOption(startOption);
	parser.addOption(endOption);
	parser.addOption(overrideOption);
	parser.addOption(listOption);
	parser.addOption(formatOption);
	parser.addOption(resOption);
	parser.addOption(fpkOption);
	parser.addOption(serverOption);
	parser.addOption(hostOption);
	parser.addOption(portOption);
	parser.addOption(noColorOption);
	parser.addOption(queueOption);
	parser.addOption(statsOption);
	parser.addOption(helpInputOption);

	// Process the actual command line arguments given by the user
	parser.process(*qapplication);
	args = parser.positionalArguments();

	cliData.nogui = parser.isSet(noguiOption);
	cliData.keyframe = parser.isSet(keyframeOption);
	cliData.flight = parser.isSet(flightOption);
	cliData.startFrameText = parser.value(startOption);
	cliData.endFrameText = parser.value(endOption);
	cliData.overrideParametersText = parser.value(overrideOption);
	cliData.imageFileFormat = parser.value(formatOption);
	cliData.resolution = parser.value(resOption);
	cliData.fpkText = parser.value(fpkOption);
	cliData.server = parser.isSet(serverOption);
	cliData.host = parser.value(hostOption);
	cliData.portText = parser.value(portOption);
	cliData.outputText = parser.value(outputOption);
	cliData.listParameters = parser.isSet(listOption);
	cliData.queue = parser.isSet(queueOption);
	cliData.showInputHelp = parser.isSet(helpInputOption);
	systemData.statsOnCLI = parser.isSet(statsOption);

#ifdef WIN32 /* WINDOWS */
	systemData.useColor = false;
#else
	systemData.useColor = !parser.isSet(noColorOption);
#endif  /* WINDOWS */

	if(cliData.listParameters) cliData.nogui = true;
	if(cliData.queue) cliData.nogui = true;

	cliTODO = modeBootOnly;
}
Beispiel #3
0
int main(int argc, char **argv)
{
	QCoreApplication app(argc, argv);
    QCoreApplication::setApplicationName("Problemsolver");
    QCoreApplication::setApplicationVersion("0.0.1");

	QCommandLineParser parser;
    parser.setApplicationDescription("Problem Problem solver using OptiX.");
    parser.addHelpOption();
    parser.addVersionOption();
	parser.addPositionalArgument("source", "Problem definition input file.");
	QCommandLineOption deviceOption(QStringList() << "d" << "device", "Device number id. Use -l to list devices.", "device", "0");
	QCommandLineOption listOption(QStringList() << "l" << "list", "List present CUDA devices in the machine.");
	parser.addOption(deviceOption);
	parser.addOption(listOption);

	parser.process(app);
	const QStringList args = parser.positionalArguments();
	if(args.isEmpty())
	{
		std::cerr << "Missing source parameter" << std::endl;
		parser.showHelp(1);
	}

	QString inputPath = args.first();

	if(parser.isSet(listOption))  // -l, then list available devices.
	{
		listDevices();
		exit(0);
	}
	
	// parse -d option
	bool parseOk;
	int deviceNumber = parser.value(deviceOption).toInt(&parseOk);
	if(!parseOk)
	{
		std::cerr << "Expect a number for device option." << std::endl;
		parser.showHelp(1);
	}
	if(deviceNumber < 0)
	{
		std::cerr << "Option --device(-d) can't be negative." << std::endl;
		parser.showHelp(1);
	}
	// find and check selected device
	ComputeDeviceRepository repository;
	const std::vector<ComputeDevice> & repo = repository.getComputeDevices();
	if(repo.empty())
	{
		std::cerr << "No computing device found"
			"You must have a CUDA enabled GPU to run this application. "
			"The CUDA GPUs nVidia developer page(https://developer.nvidia.com/cuda-gpus) has a "
			"list of all supported devices." << std::endl;
		exit(1);
	}
	if(deviceNumber >= repo.size())
	{
		std::cerr << "Invalid device number " << deviceNumber << "." << std::endl
			<<  "Try -l to list available computing devices." << std::endl;
		exit(1);
	}

	ComputeDevice device = repo.at(deviceNumber);

	// Task parented to the application so that it
    // will be deleted by the application.
	Main *main = new Main(&app, inputPath, device);

    // This will cause the application to exit when
    // the task signals finished.    
    QObject::connect(main, SIGNAL(finished()), &app, SLOT(quit()));

    // This will run the task from the application event loop.
    QTimer::singleShot(0, main, SLOT(run()));

    return app.exec();
}
Beispiel #4
0
int runRcc(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);
    QCoreApplication::setApplicationVersion(QStringLiteral(QT_VERSION_STR));

    // Note that rcc isn't translated.
    // If you use this code as an example for a translated app, make sure to translate the strings.
    QCommandLineParser parser;
    parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
    parser.setApplicationDescription(QLatin1String("Qt Resource Compiler version " QT_VERSION_STR));
    parser.addHelpOption();
    parser.addVersionOption();

    QCommandLineOption outputOption(QStringList() << QStringLiteral("o") << QStringLiteral("output"));
    outputOption.setDescription(QStringLiteral("Write output to <file> rather than stdout."));
    outputOption.setValueName(QStringLiteral("file"));
    parser.addOption(outputOption);

    QCommandLineOption tempOption(QStringList() << QStringLiteral("t") << QStringLiteral("temp"));
    tempOption.setDescription(QStringLiteral("Use temporary <file> for big resources."));
    tempOption.setValueName(QStringLiteral("file"));
    parser.addOption(tempOption);

    QCommandLineOption nameOption(QStringLiteral("name"), QStringLiteral("Create an external initialization function with <name>."), QStringLiteral("name"));
    parser.addOption(nameOption);

    QCommandLineOption rootOption(QStringLiteral("root"), QStringLiteral("Prefix resource access path with root path."), QStringLiteral("path"));
    parser.addOption(rootOption);

    QCommandLineOption compressOption(QStringLiteral("compress"), QStringLiteral("Compress input files by <level>."), QStringLiteral("level"));
    parser.addOption(compressOption);

    QCommandLineOption nocompressOption(QStringLiteral("no-compress"), QStringLiteral("Disable all compression."));
    parser.addOption(nocompressOption);

    QCommandLineOption thresholdOption(QStringLiteral("threshold"), QStringLiteral("Threshold to consider compressing files."), QStringLiteral("level"));
    parser.addOption(thresholdOption);

    QCommandLineOption binaryOption(QStringLiteral("binary"), QStringLiteral("Output a binary file for use as a dynamic resource."));
    parser.addOption(binaryOption);

    QCommandLineOption passOption(QStringLiteral("pass"), QStringLiteral("Pass number for big resources"), QStringLiteral("number"));
    parser.addOption(passOption);

    QCommandLineOption namespaceOption(QStringLiteral("namespace"), QStringLiteral("Turn off namespace macros."));
    parser.addOption(namespaceOption);

    QCommandLineOption verboseOption(QStringLiteral("verbose"), QStringLiteral("Enable verbose mode."));
    parser.addOption(verboseOption);

    QCommandLineOption listOption(QStringLiteral("list"), QStringLiteral("Only list .qrc file entries, do not generate code."));
    parser.addOption(listOption);

    QCommandLineOption projectOption(QStringLiteral("project"), QStringLiteral("Output a resource file containing all files from the current directory."));
    parser.addOption(projectOption);

    parser.addPositionalArgument(QStringLiteral("inputs"), QStringLiteral("Input files (*.qrc)."));


    //parse options
    parser.process(app);

    QString errorMsg;
    RCCResourceLibrary library;
    if (parser.isSet(nameOption))
        library.setInitName(parser.value(nameOption));
    if (parser.isSet(rootOption)) {
        library.setResourceRoot(QDir::cleanPath(parser.value(rootOption)));
        if (library.resourceRoot().isEmpty()
                || library.resourceRoot().at(0) != QLatin1Char('/'))
            errorMsg = QLatin1String("Root must start with a /");
    }
    if (parser.isSet(compressOption))
        library.setCompressLevel(parser.value(compressOption).toInt());
    if (parser.isSet(nocompressOption))
        library.setCompressLevel(-2);
    if (parser.isSet(thresholdOption))
        library.setCompressThreshold(parser.value(thresholdOption).toInt());
    if (parser.isSet(binaryOption))
        library.setFormat(RCCResourceLibrary::Binary);
    if (parser.isSet(passOption)) {
        if (parser.value(passOption) == QLatin1String("1"))
            library.setFormat(RCCResourceLibrary::Pass1);
        else if (parser.value(passOption) == QLatin1String("2"))
            library.setFormat(RCCResourceLibrary::Pass2);
        else
            errorMsg = QLatin1String("Pass number must be 1 or 2");
    }
    if (parser.isSet(namespaceOption))
        library.setUseNameSpace(!library.useNameSpace());
    if (parser.isSet(verboseOption))
        library.setVerbose(true);

    const bool list = parser.isSet(listOption);
    const bool projectRequested = parser.isSet(projectOption);
    const QStringList filenamesIn = parser.positionalArguments();

    foreach (const QString &file, filenamesIn) {
        if (!QFile::exists(file)) {
            qWarning("%s: File does not exist '%s'", argv[0], qPrintable(file));
            return 1;
        }
    }

    QString outFilename = parser.value(outputOption);
    QString tempFilename = parser.value(tempOption);

    if (projectRequested) {
        return createProject(outFilename);
    }

    if (filenamesIn.isEmpty())
        errorMsg = QStringLiteral("No input files specified.");

    if (!errorMsg.isEmpty()) {
        fprintf(stderr, "%s: %s\n", argv[0], qPrintable(errorMsg));
        parser.showHelp(1);
        return 1;
    }
    QFile errorDevice;
    errorDevice.open(stderr, QIODevice::WriteOnly|QIODevice::Text);

    if (library.verbose())
        errorDevice.write("Qt resource compiler\n");

    library.setInputFiles(filenamesIn);

    if (!library.readFiles(list, errorDevice))
        return 1;

    QFile out;

    // open output
    QIODevice::OpenMode mode = QIODevice::NotOpen;
    switch (library.format()) {
        case RCCResourceLibrary::C_Code:
        case RCCResourceLibrary::Pass1:
            mode = QIODevice::WriteOnly | QIODevice::Text;
            break;
        case RCCResourceLibrary::Pass2:
        case RCCResourceLibrary::Binary:
            mode = QIODevice::WriteOnly;
            break;
    }


    if (outFilename.isEmpty() || outFilename == QLatin1String("-")) {
#ifdef Q_OS_WIN
        // Make sure fwrite to stdout doesn't do LF->CRLF
        if (library.format() == RCCResourceLibrary::Binary)
            _setmode(_fileno(stdout), _O_BINARY);
#endif // Q_OS_WIN
        // using this overload close() only flushes.
        out.open(stdout, mode);
    } else {
        out.setFileName(outFilename);
        if (!out.open(mode)) {
            const QString msg = QString::fromLatin1("Unable to open %1 for writing: %2\n").arg(outFilename).arg(out.errorString());
            errorDevice.write(msg.toUtf8());
            return 1;
        }
    }

    // do the task
    if (list) {
        const QStringList data = library.dataFiles();
        for (int i = 0; i < data.size(); ++i) {
            out.write(qPrintable(QDir::cleanPath(data.at(i))));
            out.write("\n");
        }
        return 0;
    }

    QFile temp;
    if (!tempFilename.isEmpty()) {
        temp.setFileName(tempFilename);
        if (!temp.open(QIODevice::ReadOnly)) {
            const QString msg = QString::fromUtf8("Unable to open temporary file %1 for reading: %2\n")
                    .arg(outFilename).arg(out.errorString());
            errorDevice.write(msg.toUtf8());
            return 1;
        }
    }
    bool success = library.output(out, temp, errorDevice);
    if (!success) {
        // erase the output file if we failed
        out.remove();
        return 1;
    }
    return 0;
}