From 88dcec64527842076a3a77b4347236c39b2b97b3 Mon Sep 17 00:00:00 2001 From: GiWoong Kim Date: Fri, 10 Jul 2015 17:32:44 +0900 Subject: [PATCH] menu: add ShellOpener class for Shell menu Change-Id: I5df4e2741b14a7d51d1d89643d887c3248da4530 Signed-off-by: GiWoong Kim --- tizen/src/ui/menu/Makefile.objs | 1 + tizen/src/ui/menu/contextmenu.cpp | 52 ++++++----------------- tizen/src/ui/menu/contextmenu.h | 9 ++-- tizen/src/ui/menu/shellopener.cpp | 87 +++++++++++++++++++++++++++++++++++++++ tizen/src/ui/menu/shellopener.h | 49 ++++++++++++++++++++++ 5 files changed, 155 insertions(+), 43 deletions(-) create mode 100644 tizen/src/ui/menu/shellopener.cpp create mode 100644 tizen/src/ui/menu/shellopener.h diff --git a/tizen/src/ui/menu/Makefile.objs b/tizen/src/ui/menu/Makefile.objs index bb9a371..81e8928 100644 --- a/tizen/src/ui/menu/Makefile.objs +++ b/tizen/src/ui/menu/Makefile.objs @@ -6,6 +6,7 @@ obj-$(CONFIG_QT) += menuitem.o obj-$(CONFIG_QT) += advancedmenuitem.o obj-$(CONFIG_QT) += scalemenuitem.o obj-$(CONFIG_QT) += screenshotview.o +obj-$(CONFIG_QT) += shellopener.o $(obj)/moc_aboutdialog.o: $(obj)/moc_aboutdialog.cpp $(obj)/moc_aboutdialog.cpp: $(obj)/aboutdialog.h diff --git a/tizen/src/ui/menu/contextmenu.cpp b/tizen/src/ui/menu/contextmenu.cpp index f4a98c2..5a2005f 100644 --- a/tizen/src/ui/menu/contextmenu.cpp +++ b/tizen/src/ui/menu/contextmenu.cpp @@ -41,8 +41,6 @@ ContextMenu::ContextMenu(QWidget *parent) : QMenu(parent) this->infoDialog = NULL; this->aboutDialog = NULL; this->screenshotDialog = NULL; - this->vmName = this->parent->uiInfo->vmName + " : " - + QString::number(get_device_serial_number()); advancedMenu = NULL; switchMenu = NULL; @@ -58,6 +56,13 @@ ContextMenu::ContextMenu(QWidget *parent) : QMenu(parent) actionForceClose = NULL; actionClose = NULL; + vmName = this->parent->uiInfo->vmName + " : " + + QString::number(get_device_serial_number()); + + /* for SDB shell */ + shellOpener = new ShellOpener(); + + /* for close */ longPressTimer = new QTimer(this); createItems(this, this->parent->uiInfo->menuList); @@ -518,20 +523,7 @@ void ContextMenu::slotShell() return; } - QString sdbPort = QString::number(get_device_serial_number()); - QString sdbSerialName; - if (is_netclient_tap_attached()) { - sdbSerialName = QString(get_emul_guest_ip()); - } else { - sdbSerialName = "emulator-" + sdbPort; - } - - QString sdbPath = QCoreApplication::applicationDirPath(); -#ifdef CONFIG_WIN32 - sdbPath += "\\..\\..\\..\\..\\..\\tools\\ansicon.exe"; -#else - sdbPath += "/../../../../../tools/sdb"; -#endif + const QString sdbPath = shellOpener->getSdbPath(); QFileInfo sdbFileInfo(sdbPath); if (sdbFileInfo.exists() == false) { @@ -541,30 +533,8 @@ void ContextMenu::slotShell() return; } - QString command; - QStringList arguments; - -#ifdef CONFIG_WIN32 - command = "cmd.exe"; - arguments << "/c" << "start" << sdbPath << "sdb" << "-s" << sdbSerialName << "shell"; -#elif defined CONFIG_DARWIN - command = QCoreApplication::applicationDirPath() + "/sdbscript"; - arguments << sdbPath << sdbSerialName; -#else - command = "/usr/bin/gnome-terminal"; - QString title = "--title=" + vmName; - arguments << title << "-x" << sdbPath << "-s" << sdbSerialName << "shell"; -#endif - - qDebug() << command << arguments; - - try { - QProcess::startDetached(command, arguments); - } catch (QString &error) { - showMsgBox(QMessageBox::Warning, - "Failed to open Shell : " + error); - return; - } + /* start command in a new process */ + shellOpener->openShell(vmName); } #ifdef CONFIG_WIN32 @@ -863,5 +833,7 @@ ContextMenu::~ContextMenu() { qDebug("destroy menu"); + delete shellOpener; + longPressTimer->stop(); } diff --git a/tizen/src/ui/menu/contextmenu.h b/tizen/src/ui/menu/contextmenu.h index b710322..f058848 100644 --- a/tizen/src/ui/menu/contextmenu.h +++ b/tizen/src/ui/menu/contextmenu.h @@ -38,6 +38,7 @@ #include "aboutdialog.h" #include "screenshotdialog.h" #include "menu/menuitem.h" +#include "menu/shellopener.h" #include "input/keyboardshortcut.h" class MainWindow; @@ -115,14 +116,13 @@ private: QAction *addGeneralAction(QMenu *menu, const QIcon &icon, const QString &text, const char *slot); QMessageBox *showMsgBox(QMessageBox::Icon iconType, const QString &text, - QMessageBox::StandardButtons buttons = QMessageBox::NoButton, - QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); + QMessageBox::StandardButtons buttons = QMessageBox::NoButton, + QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); MainWindow *parent; QString vmName; DetailedInfoDialog *infoDialog; AboutDialog *aboutDialog; - QTimer *longPressTimer; QMenu *advancedMenu; QMenu *switchMenu; @@ -141,5 +141,8 @@ private: QSignalMapper *switchMapper; QSignalMapper *scaleMapper; QSignalMapper *controllerMapper; + + ShellOpener *shellOpener; + QTimer *longPressTimer; }; #endif // CONTEXTMENU_H diff --git a/tizen/src/ui/menu/shellopener.cpp b/tizen/src/ui/menu/shellopener.cpp new file mode 100644 index 0000000..a39e1bb --- /dev/null +++ b/tizen/src/ui/menu/shellopener.cpp @@ -0,0 +1,87 @@ +/* + * Qt UI + * + * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * GiWoong Kim + * Sangho Park + * + * 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 "shellopener.h" + +extern "C" { +#include "emul_state.h" +} + +ShellOpener::ShellOpener() +{ + sdbPath = QCoreApplication::applicationDirPath(); +#ifdef CONFIG_WIN32 + sdbPath += "\\..\\..\\..\\..\\..\\tools\\ansicon.exe"; +#else + sdbPath += "/../../../../../tools/sdb"; +#endif +} + +QString ShellOpener::getSdbPath() +{ + return sdbPath; +} + +void ShellOpener::openShell(QString title) +{ + qDebug() << "open the shell"; + + QString command; + QStringList arguments; + + QString sdbPort = QString::number(get_device_serial_number()); + QString sdbSerialName; + if (is_netclient_tap_attached()) { + sdbSerialName = QString(get_emul_guest_ip()); + } else { + sdbSerialName = "emulator-" + sdbPort; + } + +#ifdef CONFIG_WIN32 + command = "cmd.exe"; + arguments << "/c" << "start" << sdbPath << "sdb" << "-s" << sdbSerialName << "shell"; +#elif defined CONFIG_DARWIN + command = 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); +} + +ShellOpener::~ShellOpener() +{ + qDebug("destroy shell opener"); +} diff --git a/tizen/src/ui/menu/shellopener.h b/tizen/src/ui/menu/shellopener.h new file mode 100644 index 0000000..da55e58 --- /dev/null +++ b/tizen/src/ui/menu/shellopener.h @@ -0,0 +1,49 @@ +/* + * Qt UI + * + * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * GiWoong Kim + * Sangho Park + * + * 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 + * + */ + +#ifndef SHELLOPENER_H +#define SHELLOPENER_H + +#include + + +class ShellOpener +{ +public: + ShellOpener(); + ~ShellOpener(); + + QString getSdbPath(); + void openShell(QString title); + +private: + QString sdbPath; +}; + +#endif // SHELLOPENER_H -- 2.7.4