menu: add ShellOpener class for Shell menu
authorGiWoong Kim <giwoong.kim@samsung.com>
Fri, 10 Jul 2015 08:32:44 +0000 (17:32 +0900)
committerGiWoong Kim <giwoong.kim@samsung.com>
Sat, 11 Jul 2015 01:55:20 +0000 (10:55 +0900)
Change-Id: I5df4e2741b14a7d51d1d89643d887c3248da4530
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/ui/menu/Makefile.objs
tizen/src/ui/menu/contextmenu.cpp
tizen/src/ui/menu/contextmenu.h
tizen/src/ui/menu/shellopener.cpp [new file with mode: 0644]
tizen/src/ui/menu/shellopener.h [new file with mode: 0644]

index bb9a371fed0c756aab0cd28b452166cfb10b00d9..81e892886541a5dbd1543393fd0abcbf04d012ef 100644 (file)
@@ -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
index f4a98c24b7a7212ba23cf3d3f0551ad3b6e4598c..5a2005fb941636605aa581d8ace3c4772b3f795c 100644 (file)
@@ -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();
 }
index b710322dcf26d34b9bd3e6454a8ca9c34fe65938..f0588486fcd2126e255994cd252add9501cf423c 100644 (file)
@@ -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 (file)
index 0000000..a39e1bb
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Qt UI
+ *
+ * Copyright (C) 2015 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-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 (file)
index 0000000..da55e58
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Qt UI
+ *
+ * Copyright (C) 2015 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
+ *
+ */
+
+#ifndef SHELLOPENER_H
+#define SHELLOPENER_H
+
+#include <QtWidgets>
+
+
+class ShellOpener
+{
+public:
+    ShellOpener();
+    ~ShellOpener();
+
+    QString getSdbPath();
+    void openShell(QString title);
+
+private:
+    QString sdbPath;
+};
+
+#endif // SHELLOPENER_H