-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtopjcdialog.cpp
executable file
·142 lines (125 loc) · 4.53 KB
/
topjcdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include "topjcdialog.h"
#include "ui_topjcdialog.h"
#include "webtabcontents.h"
#include <QtGui>
#include <QLocalServer>
#include <QFile>
#include <QDir>
#include <QMessageBox>
#if QT_VERSION >= 0x050000
#include <QStandardPaths>
#else
#include <QDesktopServices>
#endif //QT_VERSION >= 0x050000
/** Constructor
LinksDialog::LinksDialog(RsPeers *peers, RsFiles *files, QWidget *parent)
: MainPage(parent), mPeers(peers), mFiles(files)
{
}**/
WebBridgeRS *eBridge = new WebBridgeRS();
WebScriptDialog::WebScriptDialog(QWidget *parent) :
MainPage(parent),
ui(new Ui::WebScriptDialog)
{
ui->setupUi(this);
bridge = eBridge;
#ifdef EMBPYTHON
embpyqt = new EmbeddedPyQt();
bridge->embpyqt = embpyqt;
embpyqt->registerObject(*bridge);
embpyqt->registerMetaObject(WebBridgeRS::staticMetaObject);
embpyqt->registerObject(*this);
embpyqt->init("embpyqt/python/initembpyqt.py");
embpyqt->execute("from embeddedpyqt import *", true);
connect(ui->pythonBtn, SIGNAL(clicked()), this, SLOT(doPython()));
#else
delete ui->pythonBtn;
#endif
connect(ui->newTabBtn, SIGNAL(clicked()), this, SLOT(addTab()));
connect(ui->closeTabBtn, SIGNAL(clicked()), this, SLOT(removeTab()));
connect(ui->rpcBtn, SIGNAL(clicked()), this, SLOT(startRPC()));
connect( bridge, SIGNAL(newTabUrl(QString)), this, SLOT(onNewTabUrl(QString)) );
}
void WebScriptDialog::startRPC(){
#if QT_VERSION >= 0x050000
QDir tempDirectory(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
#else
QDir tempDirectory(QDesktopServices::storageLocation(QDesktopServices::TempLocation));
#endif //QT_VERSION >= 0x050000
QString serviceName = tempDirectory.absoluteFilePath("testservice");
//serviceName = "testservice";
std::cerr << "starting RPC Server\n";
if (QFile::exists(serviceName) && !QFile::remove(serviceName)) {
std::cerr << "couldn't delete temporary service";
QMessageBox::warning(window(), QString("Error"), QString("Couldn't delete temporary service"));
}else{
std::cerr << "temp service: "<< serviceName.toStdString().c_str() << "\n";
QMessageBox::information(window(), QString("Service name"), serviceName);
rpcServer.addService(bridge);
if (!rpcServer.listen(QHostAddress("127.0.0.1"), 11111)) {
std::cerr << "could not start server\n: " << rpcServer.errorString().toStdString().c_str() << "\n";
QMessageBox::warning(window(), QString("Error"), QString("Could not start server"));
} else {
std::cerr << "Server Started\n";
QMessageBox::information(window(), QString(""), QString("Server Started"));
}
}
}
WebScriptDialog::~WebScriptDialog()
{
delete ui;
}
void WebScriptDialog::changeLocation()
{
//QUrl url = QUrl(ui->lineEdit->text());
//webview->load(url);
//webview->setFocus();
}
void WebScriptDialog::adjustLocation()
{
//ui->lineEdit->setText(webview->url().toString());
}
void WebScriptDialog::setP3service(p3JsonRS *p3servicein)
{
//webview->setP3service(p3servicein);
p3service = p3servicein;
//p3service->bridge = bridge;
bridge->p3service = p3service;
//std::cerr << "bridge on set: " << p3service->bridge << std::endl;
addTab();
}
void WebScriptDialog::doPython()
{
#ifdef EMBPYTHON
embpyqt->execute("embpyqt_console.Visible = True", true);
#endif
}
void WebScriptDialog::addTab(){
onNewTabUrl("html/index.html");
}
void WebScriptDialog::onNewTabUrl(QString url)
{
WebTabContents * wtc = new WebTabContents(this);
wtc->getWebView()->setUrl(QUrl(url));
ui->webTabs->addTab(wtc,QString("WSRS"));
connect( wtc->getWebView(), SIGNAL(titleChanged(QString)), this, SLOT(onTitleChanged(QString)) );
connect( wtc->getWebView(), SIGNAL(requestTabForHash(QString)), this, SLOT(onNewRsTab(QString)) );
}
void WebScriptDialog::onNewRsTab(QString hash){
onNewTabUrl("html/loading.html?hash="+hash);
WebTabContents * wtc = qobject_cast<WebTabContents *>(ui->webTabs->widget(ui->webTabs->count()-1));
wtc->getWebView()->setHashQue(hash);
//ui->webTabs->currentIndex();
//ui->webTabs->currentWidget();
}
void WebScriptDialog::onTitleChanged(QString title){
WebTabContents * wtc = qobject_cast<WebTabContents *>(QObject::sender()->parent());
int index = ui->webTabs->indexOf(wtc);
ui->webTabs->setTabText(index, title);
}
void WebScriptDialog::removeTab()
{
WebTabContents * wtc = qobject_cast<WebTabContents *>(ui->webTabs->currentWidget());
ui->webTabs->removeTab(ui->webTabs->currentIndex());
delete(wtc);
}