- ConversionWorker runs pipeline on background QThread so the GUI stays responsive during conversion; emits file_done, preview_ready, finished - MainWindow adds: output-format QComboBox, film-type QComboBox, Batch button that opens an AppConfig INI file and discovers files from batch.input_dir - main.cpp: --batch and --config flags trigger CLI mode without Qt Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
77 lines
2.4 KiB
C++
77 lines
2.4 KiB
C++
#include "cli/CliRunner.h"
|
||
|
||
#include <algorithm>
|
||
#include <iostream>
|
||
#include <string>
|
||
|
||
#ifndef NO_GUI
|
||
#include "gui/MainWindow.h"
|
||
#include <QApplication>
|
||
#endif
|
||
|
||
/**
|
||
* @brief Application entry point.
|
||
*
|
||
* Supports two operating modes:
|
||
*
|
||
* **GUI mode** (default when compiled with Qt):
|
||
* Launches the Qt MainWindow.
|
||
*
|
||
* **CLI / batch mode** (activated by `--cli` or `--batch`):
|
||
* Processes files from the command line or a config file without any GUI.
|
||
* Progress is written to stderr; errors are logged but do not abort the batch.
|
||
*
|
||
* @note The `--batch` flag (or `--config <file>`) implies CLI mode.
|
||
*/
|
||
int main(int argc, char* argv[]) {
|
||
// Determine whether CLI/batch mode was requested.
|
||
bool cli_mode = false;
|
||
for (int i = 1; i < argc; ++i) {
|
||
const std::string arg{argv[i]};
|
||
if (arg == "--cli" || arg == "--batch" || arg == "--config") {
|
||
cli_mode = true;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (cli_mode) {
|
||
// ── CLI / Batch mode (no Qt dependency) ─────────────────────────────
|
||
auto config_result = photoconv::CliRunner::parse_args(argc, argv);
|
||
if (!config_result.has_value()) {
|
||
// "Help requested" is not an error – exit 0.
|
||
const bool is_help = config_result.error().message == "Help requested";
|
||
if (!is_help) {
|
||
std::cerr << config_result.error().format() << std::endl;
|
||
}
|
||
return is_help ? 0 : 1;
|
||
}
|
||
|
||
photoconv::CliRunner runner;
|
||
auto result = runner.run(config_result.value());
|
||
if (!result.has_value()) {
|
||
std::cerr << result.error().format() << std::endl;
|
||
return 1;
|
||
}
|
||
|
||
// Exit code 0 if at least one file was converted, 1 otherwise.
|
||
return result.value() > 0 ? 0 : 1;
|
||
}
|
||
|
||
#ifndef NO_GUI
|
||
// ── GUI mode ─────────────────────────────────────────────────────────────
|
||
QApplication app{argc, argv};
|
||
app.setApplicationName("Photo Converter");
|
||
app.setApplicationVersion("0.1.0");
|
||
app.setOrganizationName("photo-converter");
|
||
|
||
photoconv::MainWindow window;
|
||
window.show();
|
||
|
||
return app.exec();
|
||
#else
|
||
std::cerr << "This build was compiled without GUI support.\n"
|
||
"Use --cli or --batch mode.\n";
|
||
return 1;
|
||
#endif
|
||
}
|