#include <QDir>
#include <QDebug>
#include <QWebFrame>
+#include <QLocalSocket>
#include "TKLog.h"
#include "DNGlobal.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
- mEngine(NULL), mWebInterface(NULL)
+ mEngine(NULL), mWebInterface(NULL), mControlledByCreator(false), mCreatorIPCServer(NULL)
{
+ QStringList arguments = qApp->arguments();
+ for (int i = 0; i < arguments.length(); i++)
+ {
+ if (!mControlledByCreator && arguments.at(i) == "-creatorControlled")
+ {
+ i++;
+ if (i < arguments.length() && arguments.at(i).indexOf("denncoCreator_") == 0)
+ {
+ mCreatorIPCServer = new QLocalServer(this);
+ if (mCreatorIPCServer->listen(arguments.at(i)))
+ {
+ mControlledByCreator = true;
+ }
+ }
+ }
+ }
+
instance = this;
ui->setupUi(this);
this->setWindowTitle(windowTitle);
- QString defaultPath(QDir::homePath());
- QString contentPath = QString::fromStdString(DNSettings::getValue(DNSettings::CONTEXT_PATH, defaultPath.toStdString()));
+ if (!mControlledByCreator)
+ {
+ QString defaultPath(QDir::homePath());
+ QString contentPath = QString::fromStdString(DNSettings::getValue(DNSettings::CONTEXT_PATH, defaultPath.toStdString()));
- ui->filePath->setText(contentPath);
+ ui->filePath->setText(contentPath);
- ui->console->document()->setMaximumBlockCount(500);
- QFont monofont("Courier");
- monofont.setStyleHint(QFont::Monospace);
- ui->console->setFont(monofont);
- TKLog::setDestination(this);
- connect(this, SIGNAL(consoleUpdated()), this, SLOT(update()), Qt::AutoConnection);
+ ui->console->document()->setMaximumBlockCount(500);
+ QFont monofont("Courier");
+ monofont.setStyleHint(QFont::Monospace);
+ ui->console->setFont(monofont);
+ TKLog::setDestination(this);
+ connect(this, SIGNAL(consoleUpdated()), this, SLOT(update()), Qt::AutoConnection);
- std::string savedWindowStateStr = DNSettings::getValue(DNSettings::WINDOWLAYOUT,"");
- QByteArray savedWindowStateQArray(savedWindowStateStr.c_str());
- restoreState(QByteArray::fromHex(savedWindowStateQArray));
+ std::string savedWindowStateStr = DNSettings::getValue(DNSettings::WINDOWLAYOUT,"");
+ QByteArray savedWindowStateQArray(savedWindowStateStr.c_str());
+ restoreState(QByteArray::fromHex(savedWindowStateQArray));
- std::string savedWindowGeometoryStr = DNSettings::getValue(DNSettings::WINDOWGEOMETORY,"");
- QByteArray savedWindowGeometoryQArray(savedWindowGeometoryStr.c_str());
- restoreGeometry(QByteArray::fromHex(savedWindowGeometoryQArray));
+ std::string savedWindowGeometoryStr = DNSettings::getValue(DNSettings::WINDOWGEOMETORY,"");
+ QByteArray savedWindowGeometoryQArray(savedWindowGeometoryStr.c_str());
+ restoreGeometry(QByteArray::fromHex(savedWindowGeometoryQArray));
+ }
+ else
+ {
+ ui->filePath->setText("");
+ ui->filePath->setEnabled(false);
+ ui->chooseDirButton->setVisible(false);
+
+ ui->console->document()->setMaximumBlockCount(500);
+ QFont monofont("Courier");
+ monofont.setStyleHint(QFont::Monospace);
+ ui->console->setFont(monofont);
+ TKLog::setDestination(this);
+ connect(this, SIGNAL(consoleUpdated()), this, SLOT(update()), Qt::AutoConnection);
+
+ std::string savedWindowStateStr = DNSettings::getValue(DNSettings::CREATORCONTROLLED_WINDOWLAYOUT,"");
+ QByteArray savedWindowStateQArray(savedWindowStateStr.c_str());
+ restoreState(QByteArray::fromHex(savedWindowStateQArray));
+
+ std::string savedWindowGeometoryStr = DNSettings::getValue(DNSettings::CREATORCONTROLLED_WINDOWGEOMETORY,"");
+ QByteArray savedWindowGeometoryQArray(savedWindowGeometoryStr.c_str());
+ restoreGeometry(QByteArray::fromHex(savedWindowGeometoryQArray));
+
+ connect(mCreatorIPCServer, SIGNAL(newConnection()), this, SLOT(on_newRequestFromCreator()));
+ }
}
MainWindow::~MainWindow()
{
+ if (mCreatorIPCServer)
+ delete mCreatorIPCServer;
+
instance = 0;
delete ui;
}
void MainWindow::closeEvent(QCloseEvent *event)
{
- QByteArray savingWindowStateQArray = saveState().toHex();
- DNSettings::setValue(DNSettings::WINDOWLAYOUT, savingWindowStateQArray.constData());
+ if (!mControlledByCreator)
+ {
+ QByteArray savingWindowStateQArray = saveState().toHex();
+ DNSettings::setValue(DNSettings::WINDOWLAYOUT, savingWindowStateQArray.constData());
+
+ QByteArray savingWindowGeometoryQArray = saveGeometry().toHex();
+ DNSettings::setValue(DNSettings::WINDOWGEOMETORY, savingWindowGeometoryQArray.constData());
+ }
+ else
+ {
+ QByteArray savingWindowStateQArray = saveState().toHex();
+ DNSettings::setValue(DNSettings::CREATORCONTROLLED_WINDOWLAYOUT, savingWindowStateQArray.constData());
- QByteArray savingWindowGeometoryQArray = saveGeometry().toHex();
- DNSettings::setValue(DNSettings::WINDOWGEOMETORY, savingWindowGeometoryQArray.constData());
+ QByteArray savingWindowGeometoryQArray = saveGeometry().toHex();
+ DNSettings::setValue(DNSettings::CREATORCONTROLLED_WINDOWGEOMETORY, savingWindowGeometoryQArray.constData());
+ }
stopEngine();
deleteCurrentEngine();
#endif
}
+void MainWindow::on_newRequestFromCreator()
+{
+ QLocalSocket *clientConnection = mCreatorIPCServer->nextPendingConnection();
+ connect(clientConnection, SIGNAL(disconnected()), clientConnection, SLOT(deleteLater()));
+
+ while(clientConnection->state() == QLocalSocket::ConnectedState || clientConnection->state() == QLocalSocket::ConnectingState)
+ {
+ clientConnection->waitForReadyRead();
+ QString readString = clientConnection->readAll();
+ QStringList requestData = readString.split(",");
+
+ if (requestData.length() < 1)
+ continue;
+
+ if (requestData.at(0) == "load" && requestData.length() == 2)
+ {
+ #ifdef DEBUG
+ qDebug() << "DEBUG: recieved load request from denncoCreator. New contant path:" << requestData.at(1) << endl;
+ #endif
+ ui->filePath->setText(requestData.at(1));
+
+ clientConnection->disconnectFromServer();
+
+ if (QString::compare(ui->startButton->text(), "Start", Qt::CaseInsensitive) != 0)
+ {
+ stopEngine();
+ }
+
+ deleteCurrentEngine();
+
+ if (startEngine())
+ {
+ ui->startButton->setText("Stop");
+ }
+ break;
+ }
+ else if (requestData.at(0) == "close")
+ {
+ close();
+ break;
+ }
+ }
+}