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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
/*
* Qt UI
*
* Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact:
* Munkyu Im <munkyu.im@samsung.com>
* GiWoong Kim <giwoong.kim@samsung.com>
* Sangho Park <sangho1206.park@samsung.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
* Contributors:
* - S-Core Co., Ltd
*
*/
#include "config-host.h"
#include "mainwindow.h"
#include "displaybase.h"
#include "sdbhelper.h"
#include "sdbhelperthread.h"
#include "resource/ui_strings.h"
extern "C" {
#include "emul_state.h"
#include "util/net_helper.h"
}
SdbHelper::SdbHelper(MainWindow *parent, DisplayBase *displaybase)
{
QString tmpSdbPath = QCoreApplication::applicationDirPath();
#ifdef CONFIG_WIN32
QString tmpAnsiconPath = QCoreApplication::applicationDirPath();
tmpAnsiconPath += "\\..\\..\\..\\..\\..\\tools\\ansicon.exe";
ansiconPath = QDir::toNativeSeparators(tmpAnsiconPath);
sdbPath = QDir::toNativeSeparators(tmpSdbPath);
tmpSdbPath += "\\..\\..\\..\\..\\..\\tools\\sdb.exe";
#else
tmpSdbPath += "/../../../../../tools/sdb";
#endif
sdbPath = QDir::toNativeSeparators(tmpSdbPath);
this->mainWindow = parent;
this->displaybase = displaybase;
this->progressing = false;
connect(this, SIGNAL(geometryChanged(QRect)), this, SLOT(handleGeometryChanged(QRect)));
}
bool SdbHelper::isSdbReady()
{
QFileInfo sdbFileInfo(sdbPath);
if (sdbFileInfo.exists() == false) {
qDebug(MSG_SDB_NOT_EXIST);
return false;
}
if (!is_sdb_daemon_initialized()) {
qDebug(MSG_SDB_NOT_READY);
return false;
}
if (QString(get_platform_default_home()).isEmpty()) {
return false;
}
return true;
}
QString SdbHelper::getGuestDefaultPushPath()
{
QString home_path = get_platform_default_home();
return home_path + "content" + "/";
}
QString SdbHelper::getSdbPath()
{
return sdbPath;
}
MainWindow *SdbHelper::getMainWindow()
{
return mainWindow;
}
DisplayBase *SdbHelper::getDisplayBase()
{
return displaybase;
}
void SdbHelper::updateGeometry(QRect rect)
{
emit geometryChanged(rect);
}
void SdbHelper::push(QList<QString> srcList, const QString &dest)
{
QString program;
QStringList arguments;
QList<QStringList> argList;
QString sdbSerialName = getSerialName();
program = sdbPath;
foreach ( const QString &src, srcList) {
arguments << "-s" << sdbSerialName << "push" << src << dest + g_path_get_basename(src.toLocal8Bit().data());
argList << arguments;
}
SdbHelperThread *thread = new SdbHelperThread(this);
thread->setArguments(SDB_PUSH_COMMNAD , program, argList);
connect(thread, SIGNAL(started()), this, SLOT(handleThreadStarted()));
connect(thread, SIGNAL(finished()), this, SLOT(handleThreadFinished()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
thread->start();
}
void SdbHelper::install(QFileInfo fi)
{
if (QString::compare(fi.suffix(), FILE_EXTENSION_RPM, Qt::CaseInsensitive) == 0) {
installRpm(fi);
return;
}
QString program;
QStringList arguments;
QList<QStringList> argList;
QString sdbSerialName = getSerialName();
program = sdbPath;
arguments << "-s" << sdbSerialName << "install" << fi.absoluteFilePath();
argList << arguments;
qDebug() << program << arguments;
SdbHelperThread *thread = new SdbHelperThread(this);
thread->setArguments(SDB_INSTALL_COMMAND, program, argList);
connect(thread, SIGNAL(started()), this, SLOT(handleThreadStarted()));
connect(thread, SIGNAL(finished()), this, SLOT(handleThreadFinished()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
thread->start();
}
void SdbHelper::installRpm(QFileInfo fi)
{
QString program;
QStringList argRootOn;
QStringList argPush;
QStringList argInstall;
QStringList argRemove;
QStringList argRootOff;
QList<QStringList> argList;
QString baseName = fi.fileName();
QString destFileName = QString(GUEST_TMP_PATH + baseName);
QString sdbSerialName = getSerialName();
program = sdbPath;
/* to install rpm package, need sudo permission. */
int result = QMessageBox::question(mainWindow, EMULATOR_TITLE,
MSG_SDB_ROOT_ON, QMessageBox::Yes, QMessageBox::No | QMessageBox::Default);
if (result == QMessageBox::No) {
return;
}
//FIXME: (sdb) cannot check sdb root status
argRootOn << "-s" << sdbSerialName << "root" << "on";
argList << argRootOn;
argPush << "-s" << sdbSerialName << "push" << fi.absoluteFilePath() << GUEST_TMP_PATH;
argList << argPush;
argInstall << "-s" << sdbSerialName << "shell" << "rpm" << "-Uvh" << destFileName << "--force" << "--nodeps";
argList << argInstall;
argRemove << "-s" << sdbSerialName << "shell" << "rm" << "-f" << destFileName;
argList << argRemove;
argRootOff << "-s" << sdbSerialName << "root" << "off";
argList << argRootOff;
qDebug() << program << argList;
SdbHelperThread *thread = new SdbHelperThread(this);
thread->setArguments(SDB_INSTALL_COMMAND, program, argList);
connect(thread, SIGNAL(started()), this, SLOT(handleThreadStarted()));
connect(thread, SIGNAL(finished()), this, SLOT(handleThreadFinished()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
thread->start();
}
void SdbHelper::handleThreadStarted()
{
progressBar = new QProgressBar((QWidget *)mainWindow);
progressBar->setAlignment(Qt::AlignCenter);
progressBar->setMinimum(0);
progressBar->setMaximum(0);
progressBar->setValue(0);
progressBar->setTextVisible(false);
progressBar->setAttribute(Qt::WA_DeleteOnClose);
progressBar->setWindowModality(Qt::NonModal);
QRect rect = getDisplayBase()->getGeometry();
int x = rect.x() + (rect.width() - progressBar->width()) / 2;
int y = rect.y() + (rect.height() - progressBar->height()) / 2;
progressBar->move(x,y);
progressBar->resize(PROGRESSBAR_DEFAULT_WITDH, PROGRESSBAR_DEFAULT_HEIGHT);
setProgressing(true);
progressBar->show();
}
void SdbHelper::handleThreadFinished()
{
progressBar->close();
setProgressing(false);
}
void SdbHelper::handleGeometryChanged(QRect newRect)
{
//XXX: need to support rotation?
qDebug() << "handleGeometryChanged: " << newRect;
if (isProgressing()) {
QRect rect = getDisplayBase()->getGeometry();
int x = rect.x() + (rect.width() - progressBar->width()) / 2;
int y = rect.y() + (rect.height() - progressBar->height()) / 2;
qDebug() << " x: " << x << " ,y: " << y;
progressBar->move(x,y);
progressBar->update();
}
}
void SdbHelper::setProgressing(bool isProgressing)
{
this->progressing = isProgressing;
}
bool SdbHelper::isProgressing()
{
return this->progressing;
}
QString SdbHelper::getSerialName()
{
QString sdbPort = QString::number(get_vm_device_serial_number());
QString sdbSerialName;
if (is_netclient_tap_attached()) {
sdbSerialName = QString(get_guest_ip());
} else {
sdbSerialName = "emulator-" + sdbPort;
}
return sdbSerialName;
}
void SdbHelper::openShell(QString title)
{
qDebug() << "open the shell";
QString command;
QStringList arguments;
QString sdbSerialName = getSerialName();
#ifdef CONFIG_WIN32
command = ansiconPath;
arguments << "sdb" << "-s" << sdbSerialName << "shell";
#elif defined CONFIG_DARWIN
command = QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + "/sdbscript");
arguments << sdbPath << sdbSerialName;
#else
command = "/usr/bin/gnome-terminal";
const QString titleOption = "--title=" + title;
arguments << titleOption << "-x" << sdbPath << "-s" << sdbSerialName << "shell";
#endif
qDebug() << command << arguments;
QProcess::startDetached(command, arguments);
}
|