Пример #1
0
bool uwsgiProcess::run(const QString &appFilename, int port, bool restart)
{
    QDir projectDir;
    if (!uwsgiProcess::findProjectDir(QDir::current(), &projectDir)) {
        qDebug() << "Error: failed to find project";
        return false;
    }

    QString localFilename = appFilename;
    if (localFilename.isEmpty()) {
        localFilename = findApplication(projectDir);
    }

    QFileInfo fileInfo(localFilename);
    if (!fileInfo.exists()) {
        qDebug() << "Error: Application file not found";
        return false;
    }

    QStringList args;
    args.append(QStringLiteral("--http-socket"));
    args.append(QLatin1String(":") % QString::number(port));

    args.append(QStringLiteral("--chdir"));
    args.append(projectDir.absolutePath());

    args.append(QStringLiteral("-M"));

    args.append(QStringLiteral("--plugin"));
    args.append(QStringLiteral("cutelyst"));

    args.append(QStringLiteral("--cutelyst-app"));
    args.append(localFilename);

    if (restart) {
        args.append(QStringLiteral("--lazy"));
        args.append(QStringLiteral("--touch-reload"));
        args.append(localFilename);
    }

#ifdef Q_OS_UNIX
    if (setup_unix_signal_handlers()) {
        return false;
    }
#endif

    qDebug() << "Running: uwsgi" << args.join(QStringLiteral(" ")).toLatin1().data();

    // Enable loggin if restart is set
    if (restart && !qEnvironmentVariableIsSet("QT_LOGGING_RULES")) {
        QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
        env.insert(QStringLiteral("QT_LOGGING_RULES"), QStringLiteral("cutelyst.*=true"));
        m_proc->setProcessEnvironment(env);
    }

    m_proc->start(QStringLiteral("uwsgi"), args);

    return true;
}
Пример #2
0
bool uwsgiProcess::run(const QString &appFilename, int port, bool restart)
{
    QDir projectDir;
    if (!uwsgiProcess::findProjectDir(QDir::current(), &projectDir)) {
        qDebug() << "Error: failed to find project";
        return false;
    }

    QString localFilename = appFilename;
    if (localFilename.isEmpty()) {
        localFilename = findApplication(projectDir);
    }

    QFileInfo fileInfo(localFilename);
    if (!fileInfo.exists()) {
        qDebug() << "Error: Application file not found";
        return false;
    }

    QStringList args;
    args.append(QStringLiteral("--http-socket"));
    args.append(QLatin1String(":") % QString::number(port));

    args.append(QStringLiteral("--chdir"));
    args.append(projectDir.absolutePath());

    args.append(QStringLiteral("-M"));

    args.append(QStringLiteral("--plugin"));
    args.append(QStringLiteral("cutelyst"));

    args.append(QStringLiteral("--cutelyst-app"));
    args.append(localFilename);

    if (restart) {
        args.append(QStringLiteral("--lazy"));
        args.append(QStringLiteral("--touch-reload"));
        args.append(localFilename);
    }

    if (setup_unix_signal_handlers()) {
        return false;
    }

    qDebug() << "Running: uwsgi" << args.join(QStringLiteral(" ")).toLatin1().data();

    m_proc->start(QStringLiteral("uwsgi"), args);

    return true;
}
Пример #3
0
SortEngine::SortEngine(SortInterface* interface, int fdRead, int fdWrite):_interface(interface), _fdRead(fdRead), _fdWrite(fdWrite), _pid(getpid()), _count(0), _final(false)
{
  setup_unix_signal_handlers();
  _interface->setPid(_pid);
  _inputVector=_readQVectorFromPipe(fdRead);
  _interface->setInputVector(_inputVector);
  if(fdWrite==-1)
    _final=true;
  if (::socketpair(AF_UNIX, SOCK_STREAM, 0, _sigusrFd))
    qFatal("Couldn't create USR socketpair");
  
  _snUsr = new QSocketNotifier(_sigusrFd[1], QSocketNotifier::Read, this);
  connect(_snUsr, SIGNAL(activated(int)), this, SLOT(handleSigUsr()));
  
}
Пример #4
0
SignalHandler::SignalHandler(QObject *parent) :
    QObject(parent)
{
    if (socketpair(AF_UNIX, SOCK_STREAM, 0, sigintFd))
        qFatal("Couldn't create INT socketpair");

    if (socketpair(AF_UNIX, SOCK_STREAM, 0, sigtermFd))
        qFatal("Couldn't create TERM socketpair");

    snInt = new QSocketNotifier(sigintFd[1], QSocketNotifier::Read, this);
    connect(snInt, SIGNAL(activated(int)), this, SLOT(handleSigInt()));
    snTerm = new QSocketNotifier(sigtermFd[1], QSocketNotifier::Read, this);
    connect(snTerm, SIGNAL(activated(int)), this, SLOT(handleSigTerm()));

    setup_unix_signal_handlers();
}
Пример #5
0
MainWindow::MainWindow()
	: QMainWindow() {

	if (::socketpair(AF_UNIX, SOCK_STREAM, 0, sigtermFd))
		qFatal("Couldn't create TERM socketpair");

	snTerm = new QSocketNotifier(sigtermFd[1], QSocketNotifier::Read, this);
	connect(snTerm, SIGNAL(activated(int)), this, SLOT(handleSigTerm()));

	setup_unix_signal_handlers();

	m_old_geometry = QRect();

	setWindowTitle(WINDOW_CAPTION);
	setWindowIcon(g_icon_ssr);

	QWidget *centralwidget = new QWidget(this);
	setCentralWidget(centralwidget);

	m_page_welcome = new PageWelcome(this);
	m_page_input = new PageInput(this);
	m_page_output = new PageOutput(this);
	m_page_record = new PageRecord(this);
	m_page_done = new PageDone(this);

	m_stacked_layout = new QStackedLayout(centralwidget);
	m_stacked_layout->addWidget(m_page_welcome);
	m_stacked_layout->addWidget(m_page_input);
	m_stacked_layout->addWidget(m_page_output);
	m_stacked_layout->addWidget(m_page_record);
	m_stacked_layout->addWidget(m_page_done);
	m_stacked_layout->setCurrentWidget(m_page_welcome);

	LoadSettings();

	// warning for glitch with proprietary NVIDIA drivers
	if(GetNVidiaDisableFlipping() == NVIDIA_DISABLE_FLIPPING_ASK || GetNVidiaDisableFlipping() == NVIDIA_DISABLE_FLIPPING_YES) {
		if(NVidiaDetectFlipping()) {
			bool disable;
			if(GetNVidiaDisableFlipping() == NVIDIA_DISABLE_FLIPPING_ASK) {
				enum_button button = MessageBox(QMessageBox::Warning, NULL, MainWindow::WINDOW_CAPTION,
												MainWindow::tr("SimpleScreenRecorder has detected that you are using the proprietary NVIDIA driver with flipping enabled. "
															   "This is known to cause glitches during recording. It is recommended to disable flipping. Do you want me to do this for you?\n\n"
															   "You can also change this option manually in the NVIDIA control panel.", "Don't translate 'flipping' unless NVIDIA does the same"),
												BUTTON_YES | BUTTON_YES_ALWAYS | BUTTON_NO | BUTTON_NO_NEVER, BUTTON_YES);
				if(button == BUTTON_YES_ALWAYS)
					SetNVidiaDisableFlipping(NVIDIA_DISABLE_FLIPPING_YES);
				if(button == BUTTON_NO_NEVER)
					SetNVidiaDisableFlipping(NVIDIA_DISABLE_FLIPPING_NO);
				disable = (button == BUTTON_YES || button == BUTTON_YES_ALWAYS);
			} else {
				disable = true;
			}
			if(disable) {
				if(!NVidiaDisableFlipping()) {
					SetNVidiaDisableFlipping(NVIDIA_DISABLE_FLIPPING_ASK);
					MessageBox(QMessageBox::Warning, NULL, MainWindow::WINDOW_CAPTION,
							   MainWindow::tr("I couldn't disable flipping for some reason - sorry! Try disabling it in the NVIDIA control panel.",
											  "Don't translate 'flipping' unless NVIDIA does the same"),
							   BUTTON_OK, BUTTON_OK);
				}
			}
		}
	}

	// maybe show the window
	if(!g_option_start_hidden)
		show();
	m_page_record->UpdateShowHide();

	// if autostart, cycle through all of the pages to get all settings in place,
	// then begin recording using defaults from conf file
	if(g_option_autostart) {
		GoPageInput();
		GoPageOutput();
		GoPageRecord();
		m_page_record->StartOutput();
	}

}
Пример #6
0
int main(int argc, char *argv[])
{
    // Qt initialisation
    QApplication a(argc, argv);

#ifdef Q_OS_LINUX
    setup_unix_signal_handlers();
#endif

    QStringList pathlist = QCoreApplication::libraryPaths();
    qDebug() << pathlist;
#if QT_VERSION >= 0x050000
    // Fixing the qt5 plugin mess
    pathlist << ".";
    QCoreApplication::setLibraryPaths(pathlist);
#endif

    // Creating the QT log file

    QDir homeDir = QDir::home();
    if (!homeDir.cd(Pip3lineConst::USER_DIRECTORY)) {
        if (!homeDir.mkpath(Pip3lineConst::USER_DIRECTORY)) {
            qWarning("Cannot create user directory for log file");
        }
    }

    homeDir = QDir::home();
    if (homeDir.cd(Pip3lineConst::USER_DIRECTORY)) {
        QByteArray logdir = homeDir.absolutePath().append(QDir::separator()).append("pip3line_gui.log").toLocal8Bit();
#ifdef Q_CC_MSVC
#define BUFFERSIZE 200

        char buffer[BUFFERSIZE];
        memset((void *)buffer, 0, BUFFERSIZE);

        errno_t err = fopen_s (&_logFile, logdir.constData(),"w");
        if ( err != 0) {
            strerror_s(buffer, BUFFERSIZE, err);
            qWarning( buffer );
#else
        _logFile = fopen (logdir.constData(),"w");

        if (_logFile == NULL) {
            qWarning("Cannot open log file for writing");
#endif
        } else {
#if QT_VERSION >= 0x050000
            qInstallMessageHandler(myMessageOutput);
#else
            qInstallMsgHandler(myMessageOutput);
#endif
        }
    }


#if QT_VERSION >= 0x050000
    // forcing style for Qt5. can be overwritten at runtime
    // with the option -style [style name]
    // An indicative list of available themes is given in the Help->info dialog
    QStringList stylelist = QStyleFactory::keys();
    if (stylelist.contains("Fusion"))
        QApplication::setStyle("Fusion");
#ifdef Q_OS_WIN
    else if (stylelist.contains("WindowsVista"))
        QApplication::setStyle("WindowsVista");
    else if (stylelist.contains("WindowsXP"))
        QApplication::setStyle("WindowsXP");
#endif

#endif

    a.setStyleSheet("QWidget{ selection-background-color: blue}");
    qDebug() << "App started";
    QStyle *currentStyle = QApplication::style();
    qDebug() << "Style" << currentStyle << currentStyle->objectName();

    // Cleaning the PATH on Windows to avoid library corruption whenever loading plugins
    qputenv("PATH", QByteArray());

#ifdef Q_OS_UNIX
    qputenv("LD_PRELOAD", QByteArray());

#endif

    QStringList list = QApplication::arguments();

    bool debugging =  false;
    if (list.contains(DEBUG_CMD)) {
        debugging = true;
        list.removeAll(DEBUG_CMD);
    }

    QString fileName;
    if (list.contains(FILE_CMD)) {
        int index = list.indexOf(FILE_CMD);
        if (list.size() > index + 1) {
            fileName = list.at(index + 1);
            list.removeAt(index);
            list.removeAt(index);
        } else {
            qCritical() << QObject::tr("Missing file name for --file, ignoring.");
        }
    }

    int ret = 0;
    w = new(std::nothrow) MainWindow(debugging);
    if (w != NULL) {
        if (!fileName.isEmpty())
            w->loadFile(fileName);

        w->show();

        ret = a.exec();
        //qWarning() << "App ending";

        MainWindow * wt = w;
        w = NULL;
        delete wt;
    }

    if (_logFile != NULL) {
        fclose (_logFile);
        _logFile = NULL;
    }

    return ret;
}
Пример #7
0
int main(int argc, char *argv[])
{
#ifndef _DEBUG
	InitMiniDumpWriter(GetNeoVersion(true).toStdWString().c_str());
#endif

#ifndef WIN32
    setup_unix_signal_handlers();
#endif

    bool bGui = false;
    bool bCore = false;
	bool bTray = false;
    bool bDaemon = false;

    for(int i=0; i<argc; i++)
    {
        if(strcmp(argv[i],"-unify") == 0)
        {
            bGui = true;
            bCore = true;
        }
        else if(strcmp(argv[i],"-gui") == 0)
            bGui = true;
        else if(strcmp(argv[i],"-core") == 0)
            bCore = true;
        else if(strcmp(argv[i],"-daemon") == 0)
            bDaemon = true;
		else if(strcmp(argv[i],"-tray") == 0)
			bTray = true;
    }

    bool bConsole = (bCore || bDaemon) && !bTray;

    // Note: we need a Q*Applicatio instance to read the settings, so here we can start the core always onl with command lin
    CScoped<QCoreApplication> pApp = bConsole ? new QCoreApplication(argc, argv) : new QApplication(argc, argv);

	if(bDaemon)
    {
        setbuf(stdout, NULL);

        if(bCore)
        {
#ifndef WIN32
            // Note: when a process becomes orphan (that is, its parent dies) it is adopted by init.
            g_NoInt = true;
#endif
        }
        else
        {
            QProcess* pCoreProcess = new QProcess();
            pCoreProcess->setProcessChannelMode(QProcess::MergedChannels);
            QStringList Arguments;
            Arguments.append("-core");
            Arguments.append("-daemon");
            pCoreProcess->start(QApplication::applicationFilePath(), Arguments);

            pCoreProcess->waitForStarted();

            for(;pCoreProcess->state() == QProcess::Running;)
            {
                QCoreApplication::processEvents();

                if(!pCoreProcess->canReadLine())
                {
                    QThread::currentThread()->msleep(10);
                    continue;
                }

                printf("%s", pCoreProcess->readLine().data());
            }

            return 0;
        }
    }

	CScoped<QtLocalPeer> pPeer = new QtLocalPeer(bConsole ? "NeoCore" : (bGui && bTray ? "NeoGUI" : "NeoApp"));
	if(pPeer->isClient())
	{
		QStringList Args = QApplication::instance()->arguments();
		for(int i=1; i < Args.count(); i++)
		{
			QString Arg = Args.at(i);
			if(Arg.left(1) != "-")
				pPeer->sendMessage(Arg);
		}
		return 0;
	}

    CSettings::InitSettingsEnvironment(APP_ORGANISATION, APP_NAME, APP_DOMAIN);
    CScoped<CSettings> Settings = new CSettings("NeoLoader", CNeoLoader::GetDefaultSettings());

#ifndef WIN32
    g_NoHup = Settings->GetBool("Integration/NoHUP") || bDaemon;
#endif

    for(int i=0; i<argc; i++)
    {

        if(strcmp(argv[i],"-name") == 0 && ++i<argc)
            Settings->SetSetting("Core/LocalName", QString(argv[i]));
        else if(strcmp(argv[i],"-port") == 0 && ++i<argc)
            Settings->SetSetting("Core/RemotePort", QString(argv[i]).toInt());
		else if(strcmp(argv[i],"-password") == 0 && ++i<argc)
            Settings->SetSetting("Core/Password", QString(argv[i]));
    }

	int NeoMode = CNeoLoader::eNoNeo;
	if(bConsole)
		NeoMode = CNeoLoader::eNeoCore;
	else // Some kind of GUI mode
	{
		if(bGui)
			NeoMode = bTray ? CNeoLoader::eGUIProcess : CNeoLoader::eRemoteGUI;
		else if(bCore) // Core with Tray
		{
			NeoMode = CNeoLoader::eCoreProcess;
			if(bTray)
				NeoMode |= CNeoLoader::eMinimized;
		}
		else
		{
			QString Mode = Settings->GetString("Core/Mode");
			if(Mode == "Separate")
				NeoMode = CNeoLoader::eCoreProcess;
			else if(Mode == "Local")
				NeoMode = CNeoLoader::eLocalGUI;
			else if(Mode == "Remote")
				NeoMode = CNeoLoader::eRemoteGUI;
			else //if(Mode == "Unified")
				NeoMode = CNeoLoader::eUnified;
		}
	}

    if ((NeoMode & CNeoLoader::eNeoCore) != 0)
		new CNeoCore(Settings);

	if ((NeoMode & CNeoLoader::eNeoGUI) != 0)
        new CNeoLoader(Settings, NeoMode);

	int Ret = 0;

    if(theLoader || theCore)
    {
		QObject::connect(pPeer, SIGNAL(messageReceived(const QString&)), bConsole ? (QObject*)theCore : (QObject*)theLoader, SLOT(OnMessage(const QString&)));

		QStringList Args = QApplication::instance()->arguments();
		for(int i=1; i < Args.count(); i++)
		{
			QString Arg = Args.at(i);
			if(Arg.left(1) != "-")
				QMetaObject::invokeMethod(bConsole ? (QObject*)theCore : (QObject*)theLoader, "OnMessage", Qt::QueuedConnection, Q_ARG(const QString&, Arg));
		}

        Ret = pApp->exec();

        delete theCore;
        delete theLoader;
    }