DiveLogImportDialog::DiveLogImportDialog(QStringList fn, QWidget *parent) : QDialog(parent),
	selector(true),
	ui(new Ui::DiveLogImportDialog)
{
	ui->setupUi(this);
	fileNames = fn;
	column = 0;
	delta = "0";
	hw = "";
	txtLog = false;

	/* Add indexes of XSLTs requiring special handling to the list */
	specialCSV << SENSUS;
	specialCSV << SUBSURFACE;
	specialCSV << DL7;
	specialCSV << AV1;
	specialCSV << POSEIDON;

	for (const CSVAppConfig &conf: CSVApps)
		ui->knownImports->addItem(conf.name);

	ui->CSVSeparator->addItems( QStringList() << tr("Tab") << "," << ";" << "|");

	loadFileContents(-1, INITIAL);

	/* manually import CSV file */
	QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this);
	connect(close, SIGNAL(activated()), this, SLOT(close()));
	QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this);
	connect(quit, SIGNAL(activated()), parent, SLOT(close()));

	connect(ui->CSVSeparator, SIGNAL(currentIndexChanged(int)), this, SLOT(loadFileContentsSeperatorSelected(int)));
	connect(ui->knownImports, SIGNAL(currentIndexChanged(int)), this, SLOT(loadFileContentsKnownTypesSelected(int)));
}
void DiveLogImportDialog::loadFileContentsKnownTypesSelected(int value)
{
	loadFileContents(value, KNOWNTYPES);
}
void DiveLogImportDialog::loadFileContentsSeperatorSelected(int value)
{
	loadFileContents(value, SEPARATOR);
}
示例#4
0
//****************************************************************************
bool parseArgs (const int argc, const char* const argv[]) {

	unsigned int argumentIndex = 0;
	std::string argument;
	char argCharacter = '\0';
	char selectedMode = '\0';
	unsigned int key = 0;
	std::string input;
	std::string output;
	std::string inputFile;
	std::string outputFile;
	bool hasInput = false;
	bool hasOutputFile = false;
	bool hasInputFile = false;
	bool usageErrorOccured = false;

	if (argc <= 1) {

		usageErrorOccured = true;

	} else {

		argumentIndex = 1;

	}

	while (argumentIndex < static_cast<unsigned int> (argc) && !usageErrorOccured) {

		argument = argv[argumentIndex];

		// Is the argument a flag? (-e, -d, etc.)
		if (argument.length () > 1 && argument[0] == '-') {

			argCharacter = argument[1];

			switch (argCharacter) {

			case INPUT_FILENAME_ARG:

				argumentIndex++;

				if (argumentIndex < static_cast<unsigned int> (argc) && !hasInput && selectedMode != HELP_ARG) {

					inputFile = argv[argumentIndex];
					hasInputFile = true;
					hasInput = true;

				} else {

					usageErrorOccured = true;

				}

				break;

			case OUTPUT_FILENAME_ARG:

				argumentIndex++;

				if (argumentIndex < static_cast<unsigned int> (argc) && !hasOutputFile && selectedMode != HELP_ARG) {

					outputFile = argv[argumentIndex];
					hasOutputFile = true;

				} else {

					usageErrorOccured = true;

				}

				break;

			case INPUT_TEXT_ARG:

				argumentIndex++;

				if (argumentIndex < static_cast<unsigned int> (argc) && !hasInput && selectedMode != HELP_ARG) {

					input = argv[argumentIndex];
					hasInput = true;

				} else {

					usageErrorOccured = true;

				}

				break;

			case ENCIPHER_ARG:
			case DECIPHER_ARG:

				// Assume that a mode has not been selected already and check for a valid key.
				// We do not break so that we roll into the next cases and check if our assumption
				// on the selected mode was right, if not we exit anyways.

				argumentIndex++;

				if (!((argumentIndex < static_cast<unsigned int> (argc)) && parseCStringAsKey (argv[argumentIndex], key))) {

					usageErrorOccured = true;
					break;

				}

			case CRACK_ARG:
			case BRUTE_FORCE_ARG:

				if (selectedMode == '\0') {

					selectedMode = argCharacter;
					break;

				} else {

					usageErrorOccured = true;

				}

				break;

			case HELP_ARG:

				if (selectedMode == '\0' && !hasInput && !hasOutputFile && !hasInputFile) {

					selectedMode = argCharacter;
					break;

				} else {

					usageErrorOccured = true;

				}

				break;

			default:

				usageErrorOccured = true;
				break;

			}

		} else {

			// Not enough arguments.
			usageErrorOccured = true;

		}

		argumentIndex++;
		
	}

	if (usageErrorOccured) {

		printUsageError ();
		return false;

	}

	if (hasInputFile) {

		if (!loadFileContents (inputFile, input)) {

			printFileLoadingError (inputFile);
			return false;

		}

	}

	switch (selectedMode) {

	case HELP_ARG:
		printHelp ();
		break;

	case ENCIPHER_ARG:
		output = encipherAndPrint (input, key);
		break;

	case DECIPHER_ARG:
		output = decipherAndPrint (input, key);
		break;

	case BRUTE_FORCE_ARG:
		output = bruteForceAndPrint (input);
		break;

	case CRACK_ARG:
		output = crackAndPrint (input);
		break;

		// Shouldn't happen.
	default:
		printUsageError ();
		break;

	}

	if (hasOutputFile) {

		if (!saveFile (outputFile, output)) {

			printFileSavingError (outputFile);
			return false;

		}

	}

	return true;

}