-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebwindow.cpp
184 lines (156 loc) · 5.5 KB
/
webwindow.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include "webwindow.h"
#include "mainwindow.h"
#include "ui_webwindow.h"
#include "qdebug.h"
#include "drawer.h"
#include "drawerdp.h"
#include "settingsdialog.h"
#include "utils.h"
#include <QDir>
#include <QDirIterator>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonValue>
#include <QSettings>
void checkLogFile()
{
QFileInfo info1(LOG_FILE_NAME);
if (info1.size() > LAG_FILE_MAX_SIZE)
{
QFile::remove(LOG_FILE_NAME);
}
}
WebWindow::WebWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::WebWindow)
{
ui->setupUi(this);
this->initWeb();
this->mainWindow = new MainWindow(this);
checkLogFile();
qDebug() << " Start application" << LOG_DATA;
}
WebWindow::~WebWindow()
{
delete ui;
}
void WebWindow::attachObject()
{
QWebFrame * frame = this->ui->webView->page()->mainFrame();
frame->addToJavaScriptWindowObject( QString("api"), this );
}
bool WebWindow::isShowA0()
{
SPTK_SETTINGS * sptk_settings = SettingsDialog::getSPTKsettings();
return sptk_settings->dp->showA0;
}
bool WebWindow::isShowF0()
{
SPTK_SETTINGS * sptk_settings = SettingsDialog::getSPTKsettings();
return sptk_settings->dp->showF0;
}
bool WebWindow::isShowError()
{
SPTK_SETTINGS * sptk_settings = SettingsDialog::getSPTKsettings();
return sptk_settings->dp->showError;
}
bool WebWindow::isShowTime()
{
SPTK_SETTINGS * sptk_settings = SettingsDialog::getSPTKsettings();
return sptk_settings->dp->showTime;
}
void WebWindow::setShowA0(QVariant value)
{
QSettings settings(SETTINGS_FILE, QSettings::IniFormat);
settings.setPath(QSettings::IniFormat, QSettings::UserScope, QApplication::applicationDirPath());
settings.setValue("dp/showA0", value.toBool());
qDebug() << "setShowA0 " << value.toBool() << LOG_DATA;
}
void WebWindow::setShowF0(QVariant value)
{
QSettings settings(SETTINGS_FILE, QSettings::IniFormat);
settings.setPath(QSettings::IniFormat, QSettings::UserScope, QApplication::applicationDirPath());
settings.setValue("dp/showF0", value.toBool());
qDebug() << "setShowF0 " << value.toBool() << LOG_DATA;
}
void WebWindow::setShowError(QVariant value)
{
QSettings settings(SETTINGS_FILE, QSettings::IniFormat);
settings.setPath(QSettings::IniFormat, QSettings::UserScope, QApplication::applicationDirPath());
settings.setValue("dp/showError", value.toBool());
qDebug() << "setShowError " << value.toBool() << LOG_DATA;
}
void WebWindow::setShowTime(QVariant value)
{
QSettings settings(SETTINGS_FILE, QSettings::IniFormat);
settings.setPath(QSettings::IniFormat, QSettings::UserScope, QApplication::applicationDirPath());
settings.setValue("dp/showTime", value.toBool());
qDebug() << "setShowTime " << value.toBool() << LOG_DATA;
}
QString WebWindow::getFiles()
{
QStringList files = scanDirItems(QApplication::applicationDirPath() + DATA_PATH_TRAINING, WAVE_TYPE, QApplication::applicationDirPath() + DATA_PATH);
files.sort();
QString lastPath = "";
QJsonArray jResult;
QJsonObject jSection;
QJsonArray jList;
for(int i=0; i<files.size();i++)
{
QString file = files.at(i);
int lastIndex = file.lastIndexOf("/");
int firstIndex = file.indexOf("/", 1);
QString filePath = file.left(lastIndex).replace("/", " ");
QString fileTitle = filePath.mid(firstIndex).replace("/", " ");
QString fileName = file.mid(lastIndex).replace("/", " ");
if (lastPath == "") lastPath = fileTitle;
if (lastPath != fileTitle)
{
jSection["title"] = lastPath;
jSection["files"] = jList;
jResult.append(jSection);
QJsonObject jNewSection;
jSection = jNewSection;
lastPath = fileTitle;
QJsonArray jNewList;
jList = jNewList;
}
QJsonObject jItem;
jItem["title"] = fileName;
jItem["text"] = fileName;
jItem["path"] = file;
jList.append(jItem);
}
jSection["title"] = lastPath;
jSection["files"] = jList;
jResult.append(jSection);
QJsonDocument jDoc(jResult);
return QString(jDoc.toJson(QJsonDocument::Compact));
}
void WebWindow::initWeb()
{
QWebFrame * frame = this->ui->webView->page()->mainFrame();
attachObject();
connect(frame , SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(attachObject()) );
qDebug() << (QApplication::applicationDirPath() + "/html/index.html") << LOG_DATA;
this->ui->webView->load(QUrl::fromLocalFile(QApplication::applicationDirPath() + "/html/index.html"));
ui->webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
connect(ui->webView, SIGNAL(linkClicked(QUrl)), this, SLOT(linkClickedWebView(QUrl)));
}
void WebWindow::linkClickedWebView(QUrl url) {
qDebug() << url.path() << LOG_DATA;
qDebug() << url.fileName() << LOG_DATA;
qDebug() << url.toString() << LOG_DATA;
if (url.toString().endsWith(".wav#dp")) {
this->mainWindow->evaluation(url.path(), new DrawerDP());
}else if (url.toString().endsWith(".wav#play")) {
this->mainWindow->playRecord(url.path());
}else if(url.fileName() == "settings.window"){
this->mainWindow->settingsShow();
}else if(url.fileName() == "main.window"){
this->mainWindow->show();
}else{
ui->webView->load(url);
}
}