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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
|
/*
* Qt UI
*
* Copyright (C) 2014 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact:
* 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-target.h"
#include "build_info.h"
#include "detailedinfodialog.h"
#include "resource/ui_strings.h"
#include "mainwindow.h"
#include "menu/advancedmenuitem.h"
#include "emul_state.h"
extern "C" {
int get_display_pixel_density(void);
}
#define TABLE_BORDER_SIZE 2
#define TAB_BORDER_SIZE 4
#define DIALOG_HORIZ_SPACE 20
#define DIALOG_VERTIC_SPACE 60
#define DIALOG_MIN_WIDTH 200
#define DIALOG_MIN_HEIGHT 200
#define DIALOG_DEF_WIDTH 480
#define DIALOG_DEF_HEIGHT 360
DetailedInfoDialog::DetailedInfoDialog(QWidget *parent) :
QDialog(parent)
{
win = ((MainWindow *)parent);
keyboardShortcut = win->getKeyboardShortcut();
// remove ? button
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
setWindowTitle(DETAILED_INFO_TITLE);
setMinimumWidth(DIALOG_MIN_WIDTH);
setMinimumHeight(DIALOG_MIN_HEIGHT);
baseLayout = new QVBoxLayout(this);
baseLayout->setMargin(10);
baseLayout->setSpacing(10);
/* upside */
upsideLayout = new QHBoxLayout();
upsideLayout->setMargin(0);
upsideLayout->setSpacing(0);
/* tab */
tabWidget = new QTabWidget(this);
{
/* VM information table */
vmInfoTable = createVmInfoTable();
tabWidget->addTab(vmInfoTable, tr(DETAILED_INFO_VMTAB_TITLE));
// FIXME: temporarily remove shortcut dialog in DARWIN
#ifndef CONFIG_DARWIN
/* shortcut information table */
QTabWidget *shortcutTab = new QTabWidget(tabWidget);
menuShortcutTable = createShortcutInfoTable();
shortcutTab->addTab(menuShortcutTable, "Menu");
keyShortcutTable = createShortcutInfoTable();
shortcutTab->addTab(keyShortcutTable, "HW Key");
tabWidget->addTab(shortcutTab, DETAILED_INFO_SHORTCUTTAB_TITLE);
#endif
}
upsideLayout->addWidget(tabWidget);
baseLayout->addLayout(upsideLayout);
/* downside */
downsideLayout = new QHBoxLayout();
downsideLayout->setAlignment(Qt::AlignRight);
downsideLayout->setMargin(0);
QPushButton *okBtn = new QPushButton("OK", this);
connect(okBtn, SIGNAL(clicked()), this, SLOT(close()));
downsideLayout->addWidget(okBtn);
baseLayout->addLayout(downsideLayout);
resize(DIALOG_DEF_WIDTH, DIALOG_DEF_HEIGHT);
}
QTableWidget *DetailedInfoDialog::createVmInfoTable()
{
QTableWidget *vmInfo = new QTableWidget();
vmInfo->setStyleSheet(STYLE_TOOLTIP);
/* horizontal headers */
QStringList headers;
headers << DETAILED_INFO_VMTAB_HEADER1 << DETAILED_INFO_VMTAB_HEADER2;
vmInfo->setColumnCount(headers.count());
vmInfo->setHorizontalHeaderLabels(headers);
vmInfo->horizontalHeader()->setStretchLastSection(true);
vmInfo->verticalHeader()->hide();
vmInfo->setEditTriggers(QAbstractItemView::NoEditTriggers);
vmInfo->setAlternatingRowColors(true);
/* insert table items */
insertTableRow(vmInfo, QString(DETAILED_INFO_VM_NAME),
win->getUiInfo()->getVmName());
insertTableRow(vmInfo, QString(DETAILED_INFO_SKIN_NAME),
win->getUiInfo()->getSkinName());
#ifdef TARGET_X86_64
insertTableRow(vmInfo, QString(DETAILED_INFO_CPU), "x86 (64bit)");
#else
insertTableRow(vmInfo, QString(DETAILED_INFO_CPU), "x86 (32bit)");
#endif
insertTableRow(vmInfo, QString(DETAILED_INFO_RAM_SIZE),
QString::number(get_ram_size() >> 20) + " MiB");
insertTableRow(vmInfo, QString(DETAILED_INFO_DISPLAY),
QString::number(win->getUiInfo()->getResolution().width()) + "x" +
QString::number(win->getUiInfo()->getResolution().height()) + " (" +
QString::number(get_display_pixel_density()) + " ppi)");
/* network connection type */
QString networkType = (is_netclient_tap_attached()) ? "Bridged" : "NAT";
insertTableRow(vmInfo, QString(DETAILED_INFO_NETWORK_CONNECTION),
networkType + " type");
insertTableRow(vmInfo, QString(DETAILED_INFO_CPU_VT),
(get_emul_cpu_accel()) ?
QString(GENERIC_TEXT_ENABLED) : QString(GENERIC_TEXT_DISABLED));
insertTableRow(vmInfo, QString(DETAILED_INFO_GPU_VT),
(is_gpu_accel_enabled()) ?
QString(GENERIC_TEXT_ENABLED) : QString(GENERIC_TEXT_DISABLED));
/* platform image version */
QString imageVer = QString::fromLocal8Bit(get_drive_image_ver());
if (imageVer.isEmpty() == false) {
insertTableRow(vmInfo, QString(DETAILED_INFO_DRIVE_IMAGE_VER), imageVer);
}
QString drive_image_file(
QString::fromLocal8Bit(get_drive_image_file()));
if (drive_image_file.isEmpty() == false) {
insertTableRow(vmInfo, QString(DETAILED_INFO_DRIVE_IMAGE_FILE),
drive_image_file, drive_image_file);
}
QString sharingPath(QString::fromLocal8Bit(
get_host_directory_sharing_path()));
insertTableRow(vmInfo, QString(DETAILED_INFO_HDS_PATH),
(sharingPath.isEmpty()) ? QString(GENERIC_TEXT_NONE) : sharingPath);
QString kernel_log_redirect_file(
QString::fromLocal8Bit(get_kernel_log_redirect_file()));
if (kernel_log_redirect_file.isEmpty() == false) {
insertTableRow(vmInfo, QString(DETAILED_INFO_KERNEL_LOG_FILE),
kernel_log_redirect_file, kernel_log_redirect_file);
}
QString log_redirect_file(QString::fromLocal8Bit(get_log_redirect_file()));
if (log_redirect_file.isEmpty() == false) {
insertTableRow(vmInfo, QString(DETAILED_INFO_EMUL_LOG_FILE),
log_redirect_file, log_redirect_file);
}
/* emulator version */
QString versionFilePath = QDir(QCoreApplication::applicationDirPath() +
QDir::separator() + SDK_ROOT_PATH + SDK_VERSION_FILE).absolutePath();
QSettings versionFile(versionFilePath, QSettings::IniFormat);
QString sdkVer = versionFile.value(SDK_VERSION_FILE_KEY).toString();
if (sdkVer.isEmpty() == true) {
qWarning() << "failed to load SDK version file from" << versionFilePath;
sdkVer = GENERIC_TEXT_UNDEFINED;
}
QString pkgVer = QString(pkginfo_version).section(':', 1).trimmed();
insertTableRow(vmInfo, QString(DETAILED_INFO_EMUL_VER), QString(get_platform_version()).section('-', 1).trimmed() +
" Release on " + sdkVer + " SDK (" + pkgVer + ")");
/* add double click event listener */
connect(vmInfo, SIGNAL(cellDoubleClicked(int, int)),
this, SLOT(slotCellOpen(int, int)));
return vmInfo;
}
QTableWidget *DetailedInfoDialog::createShortcutInfoTable()
{
QTableWidget *shortcutInfo = new QTableWidget();
/* horizontal headers */
QStringList headers;
headers << DETAILED_INFO_SHORTCUTTAB_HEADER1 << DETAILED_INFO_SHORTCUTTAB_HEADER2;
shortcutInfo->setColumnCount(headers.count());
shortcutInfo->setHorizontalHeaderLabels(headers);
shortcutInfo->horizontalHeader()->setStretchLastSection(true);
shortcutInfo->verticalHeader()->hide();
shortcutInfo->setEditTriggers(QAbstractItemView::NoEditTriggers);
shortcutInfo->setAlternatingRowColors(true);
return shortcutInfo;
}
void DetailedInfoDialog::updateShortcutTableItems()
{
/* insert menu shortcut info */
{
qDebug() << "clear" <<
menuShortcutTable->rowCount() << "menu shortcut items";
removeTableRows(menuShortcutTable, 0, menuShortcutTable->rowCount());
insertMenuShortcutInfo(win->getUiInfo()->getMenuList());
menuShortcutTable->resizeColumnsToContents();
qDebug() << menuShortcutTable->rowCount() <<
"menu shortcut items have been inserted";
}
/* insert HW key shortcut info */
{
qDebug() << "clear" <<
keyShortcutTable->rowCount() << "key shortcut items";
removeTableRows(keyShortcutTable, 0, keyShortcutTable->rowCount());
// TODO: consider getHwKeyShortcutMap()
insertHwKeyShortcutInfo(
win->getUiInfo()->getMainForm()->getKeyList());
ControllerForm *conForm = win->getUiInfo()->getConForm();
if (conForm != NULL) {
insertHwKeyShortcutInfo(
win->getUiInfo()->getConForm()->getKeyList(),
QString(" (controller)"));
}
keyShortcutTable->resizeColumnsToContents();
qDebug() << keyShortcutTable->rowCount() <<
"key shortcut items have been inserted";
}
}
void DetailedInfoDialog::insertMenuShortcutInfo(QList<MenuItem *> &list)
{
MenuItem *item = NULL;
for (int i = 0; i < list.count(); i++) {
item = list.at(i);
if (item != NULL) {
if (item->getType() == MenuItemType::separator) {
/* do nothing */
} else if (item->getType() == MenuItemType::advancedItem) {
/* insert advanced menu shortcut info */
AdvancedMenuItem *advItem = (AdvancedMenuItem *)item;
insertMenuShortcutInfo(advItem->getMenuList());
} else if (item->getAction() != NULL &&
item->getShortcuts().isEmpty() == false) {
QMap<QString, QKeySequence>::iterator iter = item->getShortcuts().begin();
for ( ; iter != item->getShortcuts().end(); iter++) {
QString function = item->getAction()->iconText().isEmpty() ?
item->getAction()->text() : item->getAction()->iconText();
function += " " + iter.key();
QString keySequence = iter.value().toString();
#ifdef CONFIG_DARWIN
keySequence.replace(XML_QT_METAKEY_STRING, XML_QT_CTRLKEY_STRING);
#endif
insertTableRow(menuShortcutTable, function, keySequence);
}
}
}
}
}
void DetailedInfoDialog::insertHwKeyShortcutInfo(
QList<HardwareKey *> &list, QString source)
{
HardwareKey *hwKey = NULL;
for (int i = 0; i < list.count(); i++) {
hwKey = list.at(i);
if (hwKey && hwKey->getKeySequence().isEmpty() == false &&
hwKey->getName().isEmpty() == false) {
QString keySequence = hwKey->getKeySequence().toString();
#ifdef CONFIG_DARWIN
keySequence.replace(XML_QT_METAKEY_STRING, XML_QT_CTRLKEY_STRING);
#endif
insertTableRow(keyShortcutTable, hwKey->getName() + source, keySequence);
}
}
}
/* override */
void DetailedInfoDialog::showEvent(QShowEvent *event)
{
// FIXME: temporarily remove shortcut dialog in DARWIN
#ifndef CONFIG_DARWIN
updateShortcutTableItems();
#endif
if ((windowState() & Qt::WindowMaximized) == 0) {
tabWidget->setCurrentIndex(0);
resizeTableToContents(vmInfoTable);
}
move(win->geometry().center().x() - (geometry().size().width() / 2),
win->geometry().center().y() - (geometry().size().height() / 2));
QDialog::showEvent(event);
}
/* override */
void DetailedInfoDialog::resizeEvent(QResizeEvent *event)
{
/* do nothing */
QDialog::resizeEvent(event);
}
void DetailedInfoDialog::resizeTableToContents(QTableWidget *table)
{
/* width */
int tWidth = qMin(table->columnWidth(0) + table->columnWidth(1), DIALOG_DEF_WIDTH);
tWidth += TABLE_BORDER_SIZE + TAB_BORDER_SIZE + DIALOG_HORIZ_SPACE;
/* height */
int tHeight = table->horizontalHeader()->height();
for (int tRow = 0; tRow < table->rowCount(); tRow++) {
tHeight += table->rowHeight(tRow);
}
tHeight += TABLE_BORDER_SIZE +
tabWidget->tabBar()->sizeHint().height() + DIALOG_VERTIC_SPACE;
resize(tWidth, tHeight);
table->resizeColumnsToContents();
}
void DetailedInfoDialog::insertTableRow(QTableWidget *table,
const QString& key, const QString& value, const QString& tooltip)
{
const int row = table->rowCount();
table->insertRow(row);
table->setItem(row, 0, new QTableWidgetItem(key));
QTableWidgetItem *item = new QTableWidgetItem(value);
table->setItem(row, 1, item);
if (!tooltip.isNull() && !tooltip.isEmpty()) {
item->setToolTip(tooltip);
}
}
void DetailedInfoDialog::insertTableRow(QTableWidget *table,
const QString& key, const QString& value)
{
insertTableRow(table, QString(key), QString(value), QString());
}
void DetailedInfoDialog::removeTableRows(
QTableWidget *table, int startIndex, int lastIndex)
{
for (int index = startIndex; index < lastIndex; index++) {
table->removeRow(startIndex);
}
}
void DetailedInfoDialog::slotCellOpen(int nRow, int nCol)
{
if (nCol <= 0 || nRow >= vmInfoTable->rowCount()) {
return;
}
QTableWidgetItem *item = vmInfoTable->item(nRow, 0);
qDebug() << item->text() << "item was double clicked";
QString path = "";
if (item->text().compare(DETAILED_INFO_HDS_PATH) == 0 ||
item->text().compare(DETAILED_INFO_EMUL_LOG_FILE) == 0 ||
item->text().compare(DETAILED_INFO_KERNEL_LOG_FILE) == 0 ||
item->text().compare(DETAILED_INFO_DRIVE_IMAGE_FILE) == 0) {
qDebug("open the specified path");
/* get path item */
item = vmInfoTable->item(nRow, nCol);
if (item->text().compare(GENERIC_TEXT_NONE) == 0 ||
item->text().isEmpty() == true) {
/* ignore this event */
qWarning("specified path is empty");
return;
}
path = item->text();
} else if (item->text().compare(DETAILED_INFO_SKIN_NAME) == 0) {
qDebug("open the skin path");
/* skin name item */
if (win->getUiInfo()->getSkinPath().isEmpty() == true) {
/* ignore this event */
qWarning("specified skin path is empty");
return;
}
path = win->getUiInfo()->getSkinPath();
} else {
/* ignore this event */
qDebug("do nothing");
return;
}
QFileInfo pathInfo(path);
if (pathInfo.isDir() == true) {
/* directory path */
if (QDesktopServices::openUrl(
QUrl("file:///" + path, QUrl::TolerantMode)) == false) {
qWarning() << "cannot open the path:" + path;
return;
}
} else if (pathInfo.isFile() == true) {
/* file path */
if (QDesktopServices::openUrl(
QUrl("file:///" + pathInfo.absolutePath(), QUrl::TolerantMode)) == false) {
qWarning() << "cannot open the file:" + pathInfo.absolutePath();
return;
}
} else {
qWarning() << "invalid path info:" << path;
}
}
DetailedInfoDialog::~DetailedInfoDialog()
{
qDebug("destroy detailed info dialog");
}
|