Beispiel #1
0
int main(int argc, char **argv)
{
    const QString errorstr = "Fatal error from the ALSA sequencer. "
        "This usually happens when the kernel doesn't have ALSA support, "
        "or the device node (/dev/snd/seq) doesn't exists, "
        "or the kernel module (snd_seq) is not loaded. "
        "Please check your ALSA/MIDI configuration.";

    CmdLineArgs args;
    signal(SIGINT, signalHandler);
    signal(SIGTERM, signalHandler);

    args.setUsage("[options] port [bpm]");
    args.addRequiredArgument("port", "Destination, MIDI port identifier");
    args.addOptionalArgument("bpm", "Tempo, in beats per minute (default=120)");
    args.parse(argc, argv);

    try {
        metronome = new Metronome();
        QVariant port = args.getArgument("port");
        if (!port.isNull())
            metronome->subscribe(port.toString());
        QVariant bpm = args.getArgument("bpm");
        metronome->play(bpm.toString());
    } catch (const SequencerError& ex) {
        cerr << errorstr + " Returned error was: " + ex.qstrError() << endl;
    } catch (...) {
        cerr << errorstr << endl;
    }
    delete metronome;
    return 0;
}
Beispiel #2
0
int main(int argc, char **argv)
{
    const QString errorstr = "Fatal error from the ALSA sequencer. "
        "This usually happens when the kernel doesn't have ALSA support, "
        "or the device node (/dev/snd/seq) doesn't exists, "
        "or the kernel module (snd_seq) is not loaded. "
        "Please check your ALSA/MIDI configuration.";

    CmdLineArgs args;
    args.setUsage("[port]");
    args.addOptionalArgument("port", "Source MIDI port");
    args.parse(argc, argv);
    try {
        test = new QDumpMIDI();
        signal(SIGINT, signalHandler);
        signal(SIGTERM, signalHandler);
        QVariant portName = args.getArgument("port");
        if (!portName.isNull())
            test->subscribe(portName.toString());
        test->run();
    } catch (const SequencerError& ex) {
        cerr << errorstr + " Returned error was: " + ex.qstrError() << endl;
    } catch (...) {
        cerr << errorstr << endl;
    }
    delete test;
    return 0;
}
Beispiel #3
0
int main(int argc, char *argv[])
{
    QSpyWrk spy;
    CmdLineArgs args;
    args.setUsage("[options] file");
    args.addOption('v', "verbose", "Verbose output");
    args.addRequiredArgument("file", "Input WRK file name");
    args.parse(argc, argv);

    QVariant verbose = args.getOption("verbose");
    if (!verbose.isNull())
        spy.setVerbosity(true);

    QVariantList files = args.getArguments("file");
    QStringList fileNames;
    foreach(const QVariant& a, files) {
        QFileInfo f(a.toString());
        if (f.exists())
            fileNames += f.canonicalFilePath();
        else
            cout << "File not found: " << a.toString() << endl;
    }
int main(int argc, char **argv)
{
#ifdef Q_WS_WIN
	// Make sure Windows doesn't load DLLs from the current working directory
	SetDllDirectoryA("");
	SetSearchPathMode(BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE);
#endif

	setlocale(LC_CTYPE, "");
	
#if defined(Q_WS_X11) && defined(AUTOTYPE)
	QApplication* app = new KeepassApplication(argc,argv);
#else
	QApplication* app = new QApplication(argc,argv);
#endif
	EventListener* eventListener = new EventListener();
	app->installEventFilter(eventListener);
	
	QApplication::setQuitOnLastWindowClosed(false);
	
	AppDir = QApplication::applicationFilePath();
	AppDir.truncate(AppDir.lastIndexOf("/"));
#if defined(Q_WS_X11)
	DataDir = AppDir+"/../share/keepassx";
	if (!QFile::exists(DataDir) && QFile::exists(AppDir+"/share"))
		DataDir = AppDir+"/share";
	const char* env = getenv("XDG_CONFIG_HOME");
	if (!env) {
		HomeDir = QDir::homePath() + "/.config";
	}
	else {
		QString qenv = QTextCodec::codecForLocale()->toUnicode(env);
		if (qenv[0] == '/')
			HomeDir = qenv;
		else
			HomeDir = QDir::homePath() + '/' + qenv;
	}
	HomeDir += "/keepassx";
#elif defined(Q_WS_MAC)
	HomeDir = QDir::homePath()+"/.keepassx";
	DataDir = AppDir+"/../Resources/keepassx";
#else //Q_WS_WIN
	HomeDir = qtWindowsConfigPath(CSIDL_APPDATA);
	if(!HomeDir.isEmpty() && QFile::exists(HomeDir))
		HomeDir = QDir::fromNativeSeparators(HomeDir)+"/KeePassX";
	else
		HomeDir = QDir::homePath()+"/KeePassX";
	
	DataDir = AppDir+"/share";
#endif
	DataDir = QDir::cleanPath(DataDir);
	
	CmdLineArgs args;
	if ( !args.parse(QApplication::arguments()) ){
		qCritical("%s\n", CSTR( args.error() ));
		args.printHelp();
		return 1;
	}
	if (args.help()){
		args.printHelp();
		return 1;
	}

	//Load Config
	QString IniFilename;
	if(args.configLocation().isEmpty()){
		if(!QDir(HomeDir).exists()){
			QDir conf(QDir::homePath());
			if(!QDir().mkpath(HomeDir))
				qWarning("Warning: Could not create directory '%s'", CSTR(HomeDir));
		}
		IniFilename=HomeDir+"/config.ini";
	}
	else
		IniFilename=args.configLocation();

#ifdef Q_WS_X11
	{
		QString OldHomeDir = QDir::homePath()+"/.keepassx";
		if (args.configLocation().isEmpty() && QFile::exists(OldHomeDir+"/config") && !QFile::exists(HomeDir+"/config")) {
			QFile::rename(OldHomeDir+"/config", HomeDir+"/config.ini");
			if (QDir(OldHomeDir).entryList(QDir::AllEntries|QDir::NoDotAndDotDot|QDir::Hidden|QDir::System).count()==0)
				QDir().rmdir(OldHomeDir);
		}
	}
#else
	if (args.configLocation().isEmpty() && QFile::exists(HomeDir+"/config") && !QFile::exists(HomeDir+"/config.ini"))
		QFile::rename(HomeDir+"/config", HomeDir+"/config.ini");
#endif
	config = new KpxConfig(IniFilename);
	fileDlgHistory.load();
	
	// PlugIns
	/*
#ifdef Q_WS_X11
	if(config->integrPlugin()!=KpxConfig::NoIntegr){
		QString LibName="libkeepassx-";
		if(config->integrPlugin()==KpxConfig::KDE)
			LibName+="kde.so";
		else if(config->integrPlugin()==KpxConfig::Gnome)
			LibName+="gnome.so";
		QString filename=findPlugin(LibName);
		if(filename!=QString()){
			QPluginLoader plugin(filename);
			if(!plugin.load()){
				PluginLoadError=plugin.errorString();
				qWarning("Could not load desktop integration plugin:");
				qWarning("%s", CSTR(PluginLoadError));
			}
			else{
				QObject *plugininstance=plugin.instance();
				IFileDialog* fdlg=qobject_cast<IFileDialog*>(plugininstance);
				IconLoader=qobject_cast<IIconTheme*>(plugininstance);
				if(IconLoader==NULL){
					qWarning("Error: Integration Plugin: Could not initialize IconTheme interface.");
				}
				KpxFileDialogs::setPlugin(fdlg);
				if(config->integrPlugin()==KpxConfig::KDE){
					IKdeInit* kdeinit=qobject_cast<IKdeInit*>(plugin.instance());
					app=kdeinit->getMainAppObject(argc,argv);
					if(!app) PluginLoadError = "Initialization failed.";
				}
				if(config->integrPlugin()==KpxConfig::Gnome){
					IGnomeInit* ginit=qobject_cast<IGnomeInit*>(plugin.instance());
					if(!ginit->init(argc,argv)){
						KpxFileDialogs::setPlugin(NULL);
						qWarning("GtkIntegrPlugin: Gtk init failed.");
						PluginLoadError = "Initialization failed.";
					}
				}
			}
		}
		else{
			qWarning(CSTR(QString("Could not load desktop integration plugin: File '%1' not found.").arg(LibName)));
			PluginLoadError=QApplication::translate("Main", "Could not locate library file.");
		}
	}
#endif
	*/
	
	DetailViewTemplate=config->detailViewTemplate();

	loadImages();
	KpxBookmarks::load();
	initYarrow(); //init random number generator
	SecString::generateSessionKey();
	
	installTranslator();

#ifdef Q_WS_MAC
	QApplication::processEvents();
	if (args.file().isEmpty() && !eventListener->file().isEmpty()) {
		args.setFile(eventListener->file());
	}
#endif

	KeepassMainWindow *mainWin = new KeepassMainWindow(args.file(), args.startMinimized(), args.startLocked());
#ifdef Q_WS_MAC
	eventListener->setMainWin(mainWin);
#endif

	int r=app->exec();
	delete mainWin;
	delete eventListener;

	fileDlgHistory.save();
	SecString::deleteSessionKey();
	delete app;
	delete config;
	return r;
}
Beispiel #5
0
int main(int argc, char **argv)
{
    QApplication* app=NULL;
    initAppPaths(argc,argv);
    CmdLineArgs args;
    if(!args.preparse(argc,argv)) { // searches only for the -cfg parameter
        qCritical(CSTR(args.error()));
        return 1;
    }

    //Load Config
    QString IniFilename;
    if(args.configLocation().isEmpty()) {
        if(!QDir(HomeDir).exists()) {
            QDir conf(QDir::homePath());
            if(!QDir().mkpath(HomeDir))
                qWarning("Warning: Could not create directory '%s'", CSTR(HomeDir));
        }
        IniFilename=HomeDir+"/config";
    }
    else
        IniFilename=args.configLocation();

    config = new KpxConfig(IniFilename);
    fileDlgHistory.load();

    // PlugIns

    if(config->integrPlugin()!=KpxConfig::NoIntegr) {
        QString LibName="libkeepassx-";
        if(config->integrPlugin()==KpxConfig::KDE)
            LibName+="kde.so";
        else if(config->integrPlugin()==KpxConfig::Gnome)
            LibName+="gnome.so";
        QString filename=findPlugin(LibName);
        if(filename!=QString()) {
            QPluginLoader plugin(filename);
            if(!plugin.load()) {
                PluginLoadError=plugin.errorString();
                qWarning("Could not load desktop integration plugin:");
                qWarning(CSTR(PluginLoadError));
            }
            else {
                QObject *plugininstance=plugin.instance();
                IFileDialog* fdlg=qobject_cast<IFileDialog*>(plugininstance);
                IconLoader=qobject_cast<IIconTheme*>(plugininstance);
                if(IconLoader==NULL) {
                    qWarning("Error: Integration Plugin: Could not initialize IconTheme interface.");
                }
                KpxFileDialogs::setPlugin(fdlg);
                if(config->integrPlugin()==KpxConfig::KDE) {
                    IKdeInit* kdeinit=qobject_cast<IKdeInit*>(plugin.instance());
                    app=kdeinit->getMainAppObject(argc,argv);
                    if(!app)PluginLoadError=QObject::tr("Initialization failed.");
                }
                if(config->integrPlugin()==KpxConfig::Gnome) {
                    IGnomeInit* ginit=qobject_cast<IGnomeInit*>(plugin.instance());
                    if(!ginit->init(argc,argv)) {
                        KpxFileDialogs::setPlugin(NULL);
                        qWarning("GtkIntegrPlugin: Gtk init failed.");
                        PluginLoadError=QObject::tr("Initialization failed.");
                    }
                }
            }
        }
        else {
            qWarning(CSTR(QString("Could not load desktop integration plugin: File '%1' not found.").arg(LibName)));
            PluginLoadError=QObject::tr("Could not locate library file.");
        }
    }
    if(!app) {
#if defined(Q_WS_X11) && defined(GLOBAL_AUTOTYPE)
        app = new KeepassApplication(argc,argv);
#else
        app = new QApplication(argc,argv);
#endif
    }
    args.parse(QApplication::arguments());


    //Internationalization
    QLocale loc;
    if(!args.language().size())
        loc=QLocale::system();
    else
        loc=QLocale(args.language());

    QTranslator* translator = NULL;
    QTranslator* qtTranslator=NULL;
    translator=new QTranslator;
    qtTranslator=new QTranslator;

    if(loadTranslation(translator,"keepass-",loc.name(),QStringList()
                       << DataDir+"/i18n/"
                       << HomeDir))
    {
        app->installTranslator(translator);
        TrActive=true;
    }
    else {
        if(loc.name()!="en_US")
            qWarning(QString("Kpx: No Translation found for '%1 (%2)' using 'English (UnitedStates)'")
                     .arg(QLocale::languageToString(loc.language()))
                     .arg(QLocale::countryToString(loc.country())).toAscii());
        delete translator;
        TrActive=false;
    }

    if(TrActive) {
        if(loadTranslation(qtTranslator,"qt_",loc.name(),QStringList()
                           << QLibraryInfo::location(QLibraryInfo::TranslationsPath)
                           << DataDir+"/i18n/"
                           << HomeDir))
            app->installTranslator(qtTranslator);
        else {
            if(loc.name()!="en_US")
                qWarning(QString("Qt: No Translation found for '%1 (%2)' using 'English (UnitedStates)'")
                         .arg(QLocale::languageToString(loc.language()))
                         .arg(QLocale::countryToString(loc.country())).toAscii());
            delete qtTranslator;
        }
    }

    DetailViewTemplate=config->detailViewTemplate();

    loadImages();
    KpxBookmarks::load();
    initYarrow(); //init random number generator
    SecString::generateSessionKey();

    eventListener = new EventListener();
    app->installEventFilter(eventListener);

    QApplication::setQuitOnLastWindowClosed(false);
    KeepassMainWindow *mainWin = new KeepassMainWindow(args.file(), args.startMinimized(), args.startLocked());
    int r=app->exec();
    delete mainWin;
    delete eventListener;

    fileDlgHistory.save();
    delete app;
    delete config;
    return r;
}