Source

pynoto / src / Project / ProjectPlugin.cpp

#include <QDebug>
#include <QtPlugin>
#include <QFileDialog>
#include <QMessageBox>
#include "ProjectPlugin.h"
#include "ProjectManagerWidget.h"
#include "Properties/ProjectProperties.h"
#include "CreateProjectDlg.h"
#include "ProjectRunner.h"

namespace Project {

ProjectPlugin::~ProjectPlugin()
{
    delete _project;
}

bool ProjectPlugin::initialize()
{
    _project = new ProjectFile();
    _runner = new ProjectRunner(_project);
    connect(_runner, SIGNAL(stoped()), SIGNAL(stoped()));
    connect(_runner, SIGNAL(output(QString)), SIGNAL(output(QString)));
    connect(_runner, SIGNAL(error(QString)), SIGNAL(error(QString)));
    initialized = true;
    return false;
}

QWidget * ProjectPlugin::widget(QWidget * parent)
{
    return new ProjectManagerWidget(parent, _project);
}

IProject * ProjectPlugin::project()
{
    return _project;
}

void ProjectPlugin::editProperties(QWidget * parent)
{
    ProjectProperties pprop(_project, parent);
    pprop.exec();
}

void ProjectPlugin::createNewProject(QWidget *parent)
{
    CreateProjectDlg dlg(parent);
    if (dlg.exec() == QDialog::Accepted){
        QString path = dlg.projectPath();
        if (QFile::exists(path)){
            if (QMessageBox::question(
                        parent,
                        tr("File exists"),
                        tr("Project file %1 already exists. Owerride?").arg(path),
                        QMessageBox::Yes | QMessageBox::No
                        ) == QMessageBox::No)
                return;
        }
        QFile file(path);
        if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)){
            QTextStream st(&file);
            st << "[common]" << endl;
            st << "name=" << dlg.name() << endl;
            file.close();
        }
        _project->unload();
        _project->load(path);
        ProjectProperties pprop(_project, parent);
        pprop.exec();
    }
}

void ProjectPlugin::run()
{
    if (_runner->run())
        emit runned();
}

void ProjectPlugin::stop()
{
    if (_runner->stop())
        emit stoped();
}

}

Q_EXPORT_PLUGIN2(project, Project::ProjectPlugin)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.