Esempio n. 1
0
int main(int argc, wchar_t *argv[]) {
#else
int main(int argc, char *argv[]) {
#endif

#ifdef READ_TUWIEN
	QCoreApplication::setOrganizationName("TU Wien");
	QCoreApplication::setOrganizationDomain("https://nomacs.org");
	QCoreApplication::setApplicationName("nomacs [READ]");
#else
	QCoreApplication::setOrganizationName("nomacs");
	QCoreApplication::setOrganizationDomain("https://nomacs.org");
	QCoreApplication::setApplicationName("Image Lounge");
#endif
	
	nmc::DkUtils::registerFileVersion();

#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
    QApplication::setAttribute(Qt::AA_DisableHighDpiScaling, true);
#endif

	QApplication app(argc, (char**)argv);

	// init settings
	nmc::DkSettingsManager::instance().init();
	nmc::DkMetaDataHelper::initialize();	// this line makes the XmpParser thread-save - so don't delete it even if you seem to know what you do

	nmc::DefaultSettings settings;
	int mode = settings.value("AppSettings/appMode", nmc::DkSettingsManager::param().app().appMode).toInt();

	// uncomment this for the single instance feature...
	//// check for single instance
	//nmc::DkRunGuard guard;
	//
	//if (!guard.tryRunning()) {
	//	qDebug() << "nomacs is already running - quitting...";
	//	return 0;
	//}

	// CMD parser --------------------------------------------------------------------
	QCommandLineParser parser;
	
	parser.addHelpOption();
	parser.addVersionOption();
	parser.addPositionalArgument("image", QObject::tr("An input image."));

	// fullscreen (-f)
	QCommandLineOption fullScreenOpt(QStringList() << "f" << "fullscreen", QObject::tr("Start in fullscreen."));
	parser.addOption(fullScreenOpt);

	QCommandLineOption slideshowOpt(QStringList() << "slideshow", QObject::tr("Start slideshow playback"));
	parser.addOption(slideshowOpt);

	QCommandLineOption pongOpt(QStringList() << "pong", QObject::tr("Start Pong."));
	parser.addOption(pongOpt);

	QCommandLineOption privateOpt(QStringList() << "p" << "private", QObject::tr("Start in private mode."));
	parser.addOption(privateOpt);

	QCommandLineOption modeOpt(QStringList() << "m" << "mode",
		QObject::tr("Set the viewing mode <mode>."),
		QObject::tr("default | frameless | pseudocolor"));
	parser.addOption(modeOpt);

	QCommandLineOption sourceDirOpt(QStringList() << "d" << "directory",
		QObject::tr("Load all files of a <directory>."),
		QObject::tr("directory"));
	parser.addOption(sourceDirOpt);

	QCommandLineOption tabOpt(QStringList() << "t" << "tab",
		QObject::tr("Load <images> to tabs."),
		QObject::tr("images"));
	parser.addOption(tabOpt);

	QCommandLineOption batchOpt(QStringList() << "batch",
		QObject::tr("Batch processing of <batch-settings.pnm>."),
		QObject::tr("batch-settings-path"));
	parser.addOption(batchOpt);

	QCommandLineOption batchLogOpt(QStringList() << "batch-log",
		QObject::tr("Saves batch log to <log-path.txt>."),
		QObject::tr("log-path.txt"));
	parser.addOption(batchLogOpt);

	QCommandLineOption importSettingsOpt(QStringList() << "import-settings",
		QObject::tr("Imports the settings from <settings-path.ini> and saves them."),
		QObject::tr("settings-path.ini"));
	parser.addOption(importSettingsOpt);
	
	QCommandLineOption registerFilesOpt(QStringList() << "register-files", QObject::tr("Register file associations (Windows only)."));
	parser.addOption(registerFilesOpt);

	parser.process(app);
	
	// CMD parser --------------------------------------------------------------------
	nmc::DkPluginManager::createPluginsPath();

	
	// compute batch process
	if (!parser.value(batchOpt).isEmpty()) {
		
		QString logPath;
		if (!parser.value(batchLogOpt).isEmpty())
			logPath = parser.value(batchLogOpt);

		QString batchSettingsPath = parser.value(batchOpt);
		nmc::DkBatchProcessing::computeBatch(batchSettingsPath, logPath);
		
		return 0;
	}

	bool noUI = false;

	// apply default settings
	if (!parser.value(importSettingsOpt).isEmpty()) {
		QString settingsPath = parser.value(importSettingsOpt);
		nmc::DkSettingsManager::importSettings(settingsPath);
		noUI = true;
	}

	// apply default settings
	if (parser.isSet(registerFilesOpt)) {
		
		nmc::DkFileFilterHandling::registerFileAssociations();
		noUI = true;
	}

	if (noUI)
		return 0;

	//install translations
	QString translationName = "nomacs_" + 
		settings.value("GlobalSettings/language", nmc::DkSettingsManager::param().global().language).toString() + ".qm";
	QString translationNameQt = "qt_" + 
		settings.value("GlobalSettings/language", nmc::DkSettingsManager::param().global().language).toString() + ".qm";

	QTranslator translator;
	nmc::DkSettingsManager::param().loadTranslation(translationName, translator);
	app.installTranslator(&translator);

	QTranslator translatorQt;
	nmc::DkSettingsManager::param().loadTranslation(translationNameQt, translatorQt);
	app.installTranslator(&translatorQt);

	nmc::DkNoMacs* w = 0;
	nmc::DkPong* pw = 0;	// pong

	// show pink icons if nomacs is in private mode
	if(parser.isSet(privateOpt)) {
		nmc::DkSettingsManager::param().display().iconColor = QColor(136, 0, 125);
		nmc::DkSettingsManager::param().app().privateMode = true;
	}

	if (parser.isSet(modeOpt)) {
		QString pm = parser.value(modeOpt);

		if (pm == "default")
			mode = nmc::DkSettingsManager::param().mode_default;
		else if (pm == "frameless")
			mode = nmc::DkSettingsManager::param().mode_frameless;
		else if (pm == "pseudocolor")
			mode = nmc::DkSettingsManager::param().mode_contrast;
		else
			qWarning() << "illegal mode: " << pm << "use either <default>, <frameless> or <pseudocolor>";

		nmc::DkSettingsManager::param().app().currentAppMode = mode;
	}

	nmc::DkTimer dt;

	// initialize nomacs
	if (mode == nmc::DkSettingsManager::param().mode_frameless) {
		w = new nmc::DkNoMacsFrameless();
		qDebug() << "this is the frameless nomacs...";
	}
	else if (mode == nmc::DkSettingsManager::param().mode_contrast) {
		w = new nmc::DkNoMacsContrast();
		qDebug() << "this is the contrast nomacs...";
	}
	else if (parser.isSet(pongOpt)) {
		pw = new nmc::DkPong();
		int rVal = app.exec();
		return rVal;
	}
	else
		w = new nmc::DkNoMacsIpl();

	// show what we got...
	w->show();

	if (w)
		w->onWindowLoaded();

	qInfo() << "Initialization takes: " << dt;

	nmc::DkCentralWidget* cw = w->getTabWidget();

	bool loading = false;

	if (!parser.positionalArguments().empty()) {

		QString filePath = parser.positionalArguments()[0].trimmed();

		if (!filePath.isEmpty()) {
			w->loadFile(QFileInfo(filePath).absoluteFilePath());	// update folder + be silent
			loading = true;
		}
	}

	// load directory preview
	if (!parser.value(sourceDirOpt).trimmed().isEmpty()) {
		cw->loadDirToTab(parser.value(sourceDirOpt));
		loading = true;
	}

	// load to tabs
	if (!parser.value(tabOpt).isEmpty()) {
		QStringList tabPaths = parser.values(tabOpt);
		loading = true;

		for (const QString& filePath : tabPaths)
			cw->addTab(filePath);
	}
	
	// load recent files if there is nothing to display
	if (!loading &&
		nmc::DkSettingsManager::param().app().showRecentFiles) {
		cw->showRecentFiles();
	}

	int fullScreenMode = settings.value("AppSettings/currentAppMode", nmc::DkSettingsManager::param().app().currentAppMode).toInt();

	if (fullScreenMode == nmc::DkSettingsManager::param().mode_default_fullscreen		||
		fullScreenMode == nmc::DkSettingsManager::param().mode_frameless_fullscreen		||
		fullScreenMode == nmc::DkSettingsManager::param().mode_contrast_fullscreen		||
		parser.isSet(fullScreenOpt)) {
		w->enterFullScreen();
		qDebug() << "trying to enter fullscreen...";
	}

	if (parser.isSet(slideshowOpt)) {
		cw->startSlideshow();
	}

#ifdef Q_WS_MAC
	nmc::DkNomacsOSXEventFilter *osxEventFilter = new nmc::DkNomacsOSXEventFilter();
	app.installEventFilter(osxEventFilter);
	QObject::connect(osxEventFilter, SIGNAL(loadFile(const QFileInfo&)),
		w, SLOT(loadFile(const QFileInfo&)));
#endif

	int rVal = -1;
	try {
		rVal = app.exec();
	}
	catch (const std::bad_alloc&) {
		
		QMessageBox::critical(0, QObject::tr("Critical Error"), 
			QObject::tr("Sorry, nomacs ran out of memory..."), QMessageBox::Ok);
	}

	if (w)
		delete w;	// we need delete so that settings are saved (from destructors)
	if (pw)
		delete pw;

	return rVal;
}
Esempio n. 2
0
int main(int argc, wchar_t *argv[]) {
#else
int main(int argc, char *argv[]) {
#endif

	qDebug() << "nomacs - Image Lounge\n";

#ifdef READ_TUWIEN
	QCoreApplication::setOrganizationName("TU Wien");
	QCoreApplication::setOrganizationDomain("http://www.nomacs.org");
	QCoreApplication::setApplicationName("nomacs - Image Lounge [READ]");
#else
	QCoreApplication::setOrganizationName("nomacs");
	QCoreApplication::setOrganizationDomain("http://www.nomacs.org");
	QCoreApplication::setApplicationName("Image Lounge");
#endif
	
	nmc::DkUtils::registerFileVersion();

	QApplication a(argc, (char**)argv);
	qDebug() << "argument count: " << argc;

	// CMD parser --------------------------------------------------------------------
	QCommandLineParser parser;

	//parser.setApplicationDescription("Test helper");
	parser.addHelpOption();
	parser.addVersionOption();
	parser.addPositionalArgument("image", QObject::tr("An input image."));

	// fullscreen (-f)
	QCommandLineOption fullScreenOpt(QStringList() << "f" << "fullscreen", QObject::tr("Start in fullscreen."));
	parser.addOption(fullScreenOpt);

	QCommandLineOption pongOpt(QStringList() << "x" << "pong", QObject::tr("Start Pong."));
	parser.addOption(pongOpt);

	QCommandLineOption privateOpt(QStringList() << "p" << "private", QObject::tr("Start in private mode."));
	parser.addOption(privateOpt);

	QCommandLineOption modeOpt(QStringList() << "m" << "mode",
		QObject::tr("Set the viewing mode <mode>."),
		QObject::tr("default | frameless | pseudocolor"));
	parser.addOption(modeOpt);

	QCommandLineOption sourceDirOpt(QStringList() << "d" << "directory",
		QObject::tr("Load all files of a <directory>."),
		QObject::tr("directory"));
	parser.addOption(sourceDirOpt);

	QCommandLineOption tabOpt(QStringList() << "t" << "tab",
		QObject::tr("Load <images> to tabs."),
		QObject::tr("images"));
	parser.addOption(tabOpt);

	parser.process(a);
	// CMD parser --------------------------------------------------------------------

	nmc::Settings::param().initFileFilters();
	QSettings& settings = nmc::Settings::instance().getSettings();
	
	nmc::Settings::param().load();	// load in constructor??

	int mode = settings.value("AppSettings/appMode", nmc::Settings::param().app().appMode).toInt();
	nmc::Settings::param().app().currentAppMode = mode;

	createPluginsPath();

	nmc::DkNoMacs* w = 0;
	nmc::DkPong* pw = 0;	// pong

	QString translationName = "nomacs_"+ settings.value("GlobalSettings/language", nmc::Settings::param().global().language).toString() + ".qm";
	QString translationNameQt = "qt_"+ settings.value("GlobalSettings/language", nmc::Settings::param().global().language).toString() + ".qm";
	
	QTranslator translator;
	nmc::Settings::param().loadTranslation(translationName, translator);
	a.installTranslator(&translator);
	
	QTranslator translatorQt;
	nmc::Settings::param().loadTranslation(translationNameQt, translatorQt);
	a.installTranslator(&translatorQt);

	// show pink icons if nomacs is in private mode
	if(parser.isSet(privateOpt)) {
		nmc::Settings::param().display().iconColor = QColor(136, 0, 125);
		nmc::Settings::param().app().privateMode = true;
	}

	if (parser.isSet(modeOpt)) {
		QString pm = parser.value(modeOpt);// .trimmed();

		if (pm == "default")
			mode = nmc::Settings::param().mode_default;
		else if (pm == "frameless")
			mode = nmc::Settings::param().mode_frameless;
		else if (pm == "pseudocolor")
			mode = nmc::Settings::param().mode_contrast;
		else
			qWarning() << "illegal mode: " << pm << "use either <default>, <frameless> or <pseudocolor>";
	}

	qDebug() << "mode: " << mode;

	nmc::DkTimer dt;

	// initialize nomacs
	if (mode == nmc::Settings::param().mode_frameless) {
		w = static_cast<nmc::DkNoMacs*> (new nmc::DkNoMacsFrameless());
		qDebug() << "this is the frameless nomacs...";
	}
	else if (mode == nmc::Settings::param().mode_contrast) {
		w = static_cast<nmc::DkNoMacs*> (new nmc::DkNoMacsContrast());
		qDebug() << "this is the contrast nomacs...";
	}
	else if (parser.isSet(pongOpt)) {
		pw = new nmc::DkPong();
		int rVal = a.exec();
		return rVal;
	}
	else
		w = static_cast<nmc::DkNoMacs*> (new nmc::DkNoMacsIpl());	// slice it

	if (w)
		w->onWindowLoaded();

	qDebug() << "Initialization takes: " << dt.getTotal();

	if (!parser.positionalArguments().empty()) {
		w->loadFile(QFileInfo(parser.positionalArguments()[0]).absoluteFilePath());	// update folder + be silent
		qDebug() << "loading: " << parser.positionalArguments()[0];
	}
	else if (nmc::Settings::param().app().showRecentFiles)
		w->showRecentFiles();

	// load directory preview
	if (!parser.value(sourceDirOpt).isEmpty()) {
		nmc::DkCentralWidget* cw = w->getTabWidget();
		cw->loadDirToTab(parser.value(sourceDirOpt));
	}

	// load to tabs
	if (!parser.value(tabOpt).isEmpty()) {
		nmc::DkCentralWidget* cw = w->getTabWidget();
		
		QStringList tabPaths = parser.values(tabOpt);
		
		for (const QString& filePath : tabPaths)
			cw->addTab(filePath);
	}

	int fullScreenMode = settings.value("AppSettings/currentAppMode", nmc::Settings::param().app().currentAppMode).toInt();

	if (fullScreenMode == nmc::Settings::param().mode_default_fullscreen		||
		fullScreenMode == nmc::Settings::param().mode_frameless_fullscreen	||
		fullScreenMode == nmc::Settings::param().mode_contrast_fullscreen		||
		parser.isSet(fullScreenOpt)) {
		w->enterFullScreen();
		qDebug() << "trying to enter fullscreen...";
	}

#ifdef Q_WS_MAC
	nmc::DkNomacsOSXEventFilter *osxEventFilter = new nmc::DkNomacsOSXEventFilter();
	a.installEventFilter(osxEventFilter);
	QObject::connect(osxEventFilter, SIGNAL(loadFile(const QFileInfo&)),
		w, SLOT(loadFile(const QFileInfo&)));
#endif

	int rVal = a.exec();

	if (w)
		delete w;	// we need delete so that settings are saved (from destructors)
	if (pw)
		delete pw;

	return rVal;
}