コード例 #1
0
void RouterKeygen::startUpRunToggle(bool state) {
    runOnStartUp = state;
    settings->setValue(RUN_ON_START_UP, runOnStartUp);
#ifdef Q_OS_UNIX
#ifdef Q_OS_MAC
    MacLoginItemsManager loginManager;
    if ( runOnStartUp ){
        if ( !loginManager.containsRunningApplication() ){
           loginManager.appendRunningApplication();
        }
    }
    else{
        if ( loginManager.containsRunningApplication() ){
            loginManager.removeRunningApplication();
        }
    }
#else
    QString newFile = "/home/" + QString(getenv("USER"))
                      + "/.config/autostart/routerkeygen.desktop";
    if (runOnStartUp) {
        QFile file(newFile);
        if ( file.open(QIODevice::ReadWrite) )
        {
            QTextStream stream( &file );
            stream << "[Desktop Entry]" << endl;
            stream << "Type=Application" << endl;
            stream << "Terminal=false" << endl;
            stream << "Exec=" << QCoreApplication::applicationFilePath() << " --no-gui" << endl;
            stream << "Name=" <<  QCoreApplication::applicationName() << endl;
            stream.flush();
            QFile::setPermissions(newFile,
                                  QFile::ReadOwner | QFile::WriteOwner | QFile::ReadUser
                                  | QFile::WriteUser | QFile::ReadGroup | QFile::ReadGroup
                                  | QFile::ReadOther);

        }
    } else {
        if (QFile::exists(newFile))
            QFile::remove(newFile);
    }
#endif
#endif
#ifdef Q_OS_WIN
    QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run",QSettings::NativeFormat);
    if (runOnStartUp) {
        settings.setValue("RouterKeygen", QCoreApplication::applicationFilePath().replace('/','\\')+ " --no-gui");
    } else {
        settings.remove("RouterKeygen");
    }
#endif
}
コード例 #2
0
void RouterKeygen::startUpRunToggle(bool state) {
	runOnStartUp = state;
	settings->setValue(RUN_ON_START_UP, runOnStartUp);
#ifdef Q_OS_UNIX
#ifdef Q_OS_MAC
    MacLoginItemsManager loginManager;
    if ( runOnStartUp ){
        if ( !loginManager.containsRunningApplication() ){
            if (!loginManager.appendRunningApplication())
                qDebug() << "Error setting startup state";
        }
    }
    else{
        if ( loginManager.containsRunningApplication() ){
            if (!loginManager.removeRunningApplication() )
                qDebug() << "Error setting startup state";
        }
    }
#else
	QString newFile = "/home/" + QString(getenv("USER"))
			+ "/.config/autostart/routerkeygen.desktop";
	qDebug() << newFile;
	if (runOnStartUp) {
		QFile autoStart(":/routerkeygen.desktop");
		if (!autoStart.copy(newFile))
			qDebug() << "Error while copying file";
		QFile::setPermissions(newFile,
				QFile::ReadOwner | QFile::WriteOwner | QFile::ReadUser
						| QFile::WriteUser | QFile::ReadGroup | QFile::ReadGroup
						| QFile::ReadOther);
	} else {
		if (QFile::exists(newFile))
			if (!QFile::remove(newFile))
				qDebug() << "Error while removing file";
	}
#endif
#endif
#ifdef Q_OS_WIN
	 QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run",QSettings::NativeFormat);
	    if (runOnStartUp) {
            settings.setValue("RouterKeygen", QCoreApplication::applicationFilePath().replace('/','\\')+ " -h");
	    } else {
	        settings.remove("RouterKeygen");
	    }
#endif
}