Example #1
0
void MainWindow::loadConfigs(QString path)
{
    if (!QFile(path).exists()) {
        QMessageBox::warning(this, tr("Ошибка открытия файла"),
                             tr("Не найден файл настроек gostunnel:\n") + path);
        return;
    }
    ui->lwGroups->clear();
    connections.clear();

    QStringList groups;
    QSettings st(path, QSettings::IniFormat);
    groups << st.childGroups();

    for (int i = 0; i < groups.count(); i++) {
        QProcess *proc = new QProcess(this);
        proc->setObjectName(groups.at(i));
        connections.insert(groups.at(i), proc);
        QListWidgetItem *item = new QListWidgetItem(groups.at(i),
                                                    ui->lwGroups);
    }
    if (!groups.isEmpty()) {
        ui->lwGroups->item(0)->setSelected(true);
        loadConfig(groups.first());
    }
}
Example #2
0
void MainWindow::on_btnAddGroup_clicked()
{
    QString name = "Connection" + searchFreeNumber(connections.keys(),
                                                   QString("Connection"));
    QString label = tr("Введите название нового подключения");
    bool ok = false;
    QList<QListWidgetItem *> list = ui->lwGroups->findItems(name, Qt::MatchWrap);
    while (true) {
        name = QInputDialog::getText(
                    this,
                    tr("Ввод названия нового подключения"),
                    label, QLineEdit::Normal, name, &ok);
        list = ui->lwGroups->findItems(name, Qt::MatchWrap);
        if (ok && list.count() > 0) {
            label = tr("Подключение с таким названием уже существует!\n"
                       "Введите другое название");
            name = "Connection" + searchFreeNumber(connections.keys(),
                                                   QString("Connection"));
        } else if (ok) {
            break;
        } else {
            return;
        }
    }
    QProcess *proc = new QProcess(this);
    proc->setObjectName(name);
    connections.insert(name, proc);
    QListWidgetItem *item = new QListWidgetItem(name);
    ui->lwGroups->addItem(item);
    ui->lwGroups->setCurrentItem(item);
    loadConfig(name);
}
Example #3
0
void MainWindow::on_lwGroups_doubleClicked(const QModelIndex &index)
{
    if (connections.value(index.data().toString())->pid() > 0) {

        QMessageBox::information(this,
                                 tr("Невозможно изменить имя подключения"),
                                 tr("В настоящее время подключение активно, "
                                    "остановите подключение для изменения настроек"));
    } else {
        QString oldName = index.data().toString();
        QString newName = oldName;
        QString label = tr("Введите новое название подключения:");
        bool ok = false;
        QList<QListWidgetItem *> list;
        while (true) {
            newName = QInputDialog::getText(
                        this,
                        tr("Изменение названия подключения"),
                        label, QLineEdit::Normal, newName, &ok);
            list = ui->lwGroups->findItems(newName, Qt::MatchWrap);
            if (ok && list.count() > 0) {
                if (newName == oldName) {
                    return;
                }
                label = tr("Подключение с таким названием уже существует!\n"
                           "Введите другое название:");
                newName = oldName;
            } else if (newName.contains(QRegExp("\\w*[\\.\\s\\,]+\\w*"))) {
                label = tr("Некорректное название подключение!\n"
                           "Строка содержит неподдерживаемые символы\n"
                           "Введите другое название:");
                newName = oldName;
            } else if (ok) {
                break;
            } else {
                return;
            }
        }
        ui->lwGroups->currentItem()->setText(newName);
        QProcess *proc = connections.value(oldName);
        proc->setObjectName(newName);
        connections.insert(newName, proc);
        connections.remove(oldName);
        deleteConfig(oldName);
        saveConfig(newName);
    }
}
Example #4
0
QProcess *PuppetCreator::puppetProcess(const QString &puppetPath,
                                       const QString &puppetMode,
                                       const QString &socketToken,
                                       QObject *handlerObject,
                                       const char *outputSlot,
                                       const char *finishSlot) const
{
    QProcess *puppetProcess = new QProcess;
    puppetProcess->setObjectName(puppetMode);
    puppetProcess->setProcessEnvironment(processEnvironment());
    QObject::connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()), puppetProcess, SLOT(kill()));
    QObject::connect(puppetProcess, SIGNAL(finished(int,QProcess::ExitStatus)), handlerObject, finishSlot);
    bool fowardQmlpuppetOutput = !qgetenv("FORWARD_QMLPUPPET_OUTPUT").isEmpty();
    if (fowardQmlpuppetOutput) {
        puppetProcess->setProcessChannelMode(QProcess::MergedChannels);
        QObject::connect(puppetProcess, SIGNAL(readyRead()), handlerObject, outputSlot);
    }
    puppetProcess->start(puppetPath, QStringList() << socketToken << puppetMode << "-graphicssystem raster");

    return puppetProcess;
}
Example #5
0
void SofaModeler::runInSofa(	const std::string &sceneFilename, Node* root)
{
    if (!root) return;
    // Init the scene
    sofa::gui::GUIManager::Init("Modeler");

    //Saving the scene in a temporary file ==> doesn't modify the current Node of the simulation
    std::string path;
    if (sceneFilename.empty()) path=presetPath;
    else path = sofa::helper::system::SetDirectory::GetParentDir(sceneFilename.c_str())+std::string("/");


    std::string filename=path + std::string("temp") + (++count) + std::string(".scn");
    simulation::tree::getSimulation()->exportXML(root,filename.c_str());

    //Make a copy of the .view if it exists for the current viewer
    const std::string &extension=sofa::helper::system::SetDirectory::GetExtension(sceneFilename.c_str());

    if (!sceneFilename.empty() && !extension.empty())
    {

        std::string viewFile = sceneFilename;
        //Get the name of the viewer
        std::string viewerName;
        for (unsigned int i=0; i<listActionGUI.size(); ++i)
        {
            if (listActionGUI[i]->isChecked())
            {
                viewerName = listActionGUI[i]->text().toStdString();
                if (viewerName == "default")
                    viewerName = sofa::gui::GUIManager::GetValidGUIName();

                if (viewerName == "qt") //default viewer: no extension
                {
                    viewerName.clear();
                }
                break;
            }
        }

        std::string viewerExtension;
        if (!viewerName.empty())
            viewerExtension += "." + viewerName;
        viewerExtension += ".view";

        viewFile += viewerExtension;

        if ( !sofa::helper::system::DataRepository.findFile ( viewFile ) )
        {
            viewFile = sceneFilename+".view";
            viewerExtension = ".view";
        }

        //        std::cerr << "viewFile = " << viewFile << std::endl;
        if ( sofa::helper::system::DataRepository.findFile ( viewFile ) )
        {
            std::ifstream originalViewFile(viewFile.c_str());
            const std::string nameCopyViewFile(path + std::string("temp") + count + ".scn" + viewerExtension );
            std::ofstream copyViewFile(nameCopyViewFile.c_str());
            std::string line;
            while (std::getline(originalViewFile, line)) copyViewFile << line << "\n";

            copyViewFile.close();
            originalViewFile.close();
        }
    }
    if (count > '9') count = '0';

    QString messageLaunch;
    QStringList argv;
    //=======================================
    // Run Sofa
    if (sofaBinary.empty()) //If no specific binary is specified, we use runSofa
    {
        std::string binaryName="runSofa";
#ifndef NDEBUG
        binaryName+="_d";
#endif

#ifdef WIN32
        sofaBinary = binPath + binaryName + ".exe";
#else
        sofaBinary = binPath + binaryName;
#endif
    }

    argv << QString(filename.c_str());

    messageLaunch = QString("Use command: ")
            + QString(sofaBinary.c_str())
            + QString(" ");

    //Setting the GUI
    for (unsigned int i=0; i<listActionGUI.size(); ++i)
    {
        if (listActionGUI[i]->isChecked())
        {
            if (std::string(listActionGUI[i]->text().toStdString()) != "default")
            {
                argv << "-g" << listActionGUI[i]->text();
                messageLaunch += QString("-g ") + QString(listActionGUI[i]->text());
            }
            break;
        }
    }

    //retrive plugins
    typedef sofa::helper::system::PluginManager::PluginMap PluginMap;
    PluginMap& pluginMap = PluginManager::getInstance().getPluginMap();
    PluginManager::PluginIterator it;

    for( it = pluginMap.begin(); it != pluginMap.end(); ++it )
    {
        argv << "-l" << QString((it->first).c_str()) << " ";
        messageLaunch += QString("-l ") + QString((it->first).c_str());
    }


    argv << "-t";


    QProcess *p = new QProcess(this);


    p->setWorkingDirectory(QString(binPath.c_str()) );
    p->setObjectName(QString(filename.c_str()) );


    connect(p, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(sofaExited(int, QProcess::ExitStatus)));
    QDir dir(QString(sofa::helper::system::SetDirectory::GetParentDir(sceneFilename.c_str()).c_str()));
    connect(p, SIGNAL( readyReadStandardOutput () ), this , SLOT ( redirectStdout() ) );
    connect(p, SIGNAL( readyReadStandardError () ), this , SLOT ( redirectStderr() ) );

    p->start(QString(sofaBinary.c_str()), argv);

    mapSofa.insert(std::make_pair(tabGraph, p));

    statusBar()->showMessage(messageLaunch,5000);
}