menu: make a wrapper function of message box 10/36410/3
authorGiWoong Kim <giwoong.kim@samsung.com>
Fri, 6 Mar 2015 06:36:16 +0000 (15:36 +0900)
committerGiWoong Kim <giwoong.kim@samsung.com>
Fri, 6 Mar 2015 08:33:42 +0000 (17:33 +0900)
Change-Id: I487a1f191d9f65a105f7e0ab50ed09202190ebfd
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/ui/menu/contextmenu.cpp
tizen/src/ui/menu/contextmenu.h
tizen/src/ui/uiutil.cpp

index 54df96f..b1d0bc2 100644 (file)
@@ -28,8 +28,6 @@
  *
  */
 
-#include <QtWidgets>
-
 #include "contextmenu.h"
 #include "emulator_common.h"
 #include "mainwindow.h"
@@ -496,15 +494,8 @@ void ContextMenu::slotShell()
     qDebug("SDB shell");
 
     if (is_sdbd_initialized == 0) {
-        QString msg = "SDB is not ready.\nPlease wait until the emulator is completely boot up.";
-        qDebug() << msg;
-
-        QMessageBox *msgBox = new QMessageBox(QMessageBox::Information,
-            "Emulator", msg, QMessageBox::Ok, (QWidget*)parent);
-        msgBox->setAttribute(Qt::WA_DeleteOnClose);
-        msgBox->setModal(false);
-        msgBox->show();
-
+        showMsgBox(QMessageBox::Warning,
+            "SDB is not ready.\nPlease wait until the emulator is completely boot up.");
         return;
     }
 
@@ -520,16 +511,9 @@ void ContextMenu::slotShell()
 
     QFileInfo sdbFileInfo(sdbPath);
     if (sdbFileInfo.exists() == false) {
-        QString msg = "SDB file does not exist in the following path.\n"
-            + sdbFileInfo.absoluteFilePath();
-        qWarning() << msg;
-
-        QMessageBox *msgBox = new QMessageBox(QMessageBox::Warning,
-            "Emulator", msg, QMessageBox::Ok, (QWidget*)parent);
-        msgBox->setAttribute(Qt::WA_DeleteOnClose);
-        msgBox->setModal(false);
-        msgBox->show();
-
+        showMsgBox(QMessageBox::Warning,
+            "SDB file does not exist in the following path.\n"
+            + sdbFileInfo.absoluteFilePath());
         return;
     }
 
@@ -553,15 +537,8 @@ void ContextMenu::slotShell()
     try {
         QProcess::startDetached(command, arguments);
     } catch (QString &error) {
-        QString msg = "Failed to open Shell : " + error;
-        qDebug() << msg;
-
-        QMessageBox *msgBox = new QMessageBox(QMessageBox::Warning,
-            "Emulator", msg, QMessageBox::Ok ,(QWidget*)parent);
-        msgBox->setAttribute(Qt::WA_DeleteOnClose);
-        msgBox->setModal(false);
-        msgBox->show();
-
+        showMsgBox(QMessageBox::Warning,
+            "Failed to open Shell : " + error);
         return;
     }
 }
@@ -640,17 +617,6 @@ static bool menu_get_java_path(char** java_path)
 }
 #endif
 
-void ContextMenu::showPopup(QString msg)
-{
-    qDebug() << msg;
-
-    QMessageBox *msgBox = new QMessageBox(QMessageBox::Warning,
-        "Emulator", msg, QMessageBox::Ok, (QWidget*)parent);
-    msgBox->setAttribute(Qt::WA_DeleteOnClose);
-    msgBox->setModal(false);
-    msgBox->show();
-}
-
 void ContextMenu::slotControlPanel()
 {
     qDebug("Control Panel");
@@ -667,7 +633,8 @@ void ContextMenu::slotControlPanel()
 
     QFileInfo ecpFileInfo(ecpPath);
     if (!ecpFileInfo.exists()) {
-        showPopup("Control Panel file does not exist in the following path.\n"
+        showMsgBox(QMessageBox::Warning,
+            "Control Panel file does not exist in the following path.\n"
             + ecpFileInfo.absoluteFilePath());
         return;
     }
@@ -684,7 +651,7 @@ void ContextMenu::slotControlPanel()
         if (menu_get_java_path(&path)) {
             command = QString::fromLocal8Bit(path);
         } else {
-            showPopup("Failed to get java path.");
+            showMsgBox(QMessageBox::Warning, "Failed to get java path.");
             free(path);
             return;
         }
@@ -707,7 +674,7 @@ void ContextMenu::slotControlPanel()
     try {
         QProcess::startDetached(command, arguments);
     } catch (QString &error) {
-        showPopup("Failed to open Control Panel : " + error);
+        showMsgBox(QMessageBox::Warning, "Failed to open Control Panel : " + error);
         return;
     }
 }
@@ -761,28 +728,35 @@ void ContextMenu::slotForceClose()
 {
     qDebug("force close");
 
-    QMessageBox *msg = new QMessageBox((QWidget*)parent);
-    msg->setAttribute(Qt::WA_DeleteOnClose);
-    msg->setWindowTitle("Emulator");
-    msg->setText("If you force stop an emulator, it may cause some problems.\n"
-        "Are you sure you want to continue?");
-    msg->setStandardButtons(QMessageBox::Yes|QMessageBox::No);
-    msg->setDefaultButton(QMessageBox::Yes);
-    msg->setIcon(QMessageBox::Question);
-    msg->setModal(false);
-    msg->show();
-    connect(msg, SIGNAL(buttonClicked(QAbstractButton *)),
-                            this, SLOT(slotForceCloseSelected(QAbstractButton *)));
-}
-
-void ContextMenu::slotForceCloseSelected(QAbstractButton *btn)
-{
-    if (btn->text().compare("&Yes") == 0) {
-        qDebug() << "exit!";
-        /* force close */
-        shutdown_qemu_gracefully(1);
-    } else {
-        qDebug() << "cancel";
+    QMessageBox *msgBox = showMsgBox(QMessageBox::Question,
+        "If you force stop an emulator, it may cause some problems.\n"
+        "Are you sure you want to continue?", QMessageBox::Yes | QMessageBox::No);
+
+    connect(msgBox, SIGNAL(buttonClicked(QAbstractButton *)),
+        this, SLOT(slotForceCloseSelected(QAbstractButton *)));
+}
+
+void ContextMenu::slotForceCloseSelected(QAbstractButton *button)
+{
+    QMessageBox *msgBox = (QMessageBox *)button->parent()->parent();
+    if (msgBox == NULL) {
+        qWarning() << "invalid slot call";
+        return;
+    }
+
+    switch(msgBox->standardButton(button)) {
+        case QMessageBox::Yes:
+            qDebug() << "exit!";
+            shutdown_qemu_gracefully(3);
+
+            break;
+        case QMessageBox::No:
+            qDebug() << "cancel";
+
+            break;
+        default:
+            /* do nothing */
+            break;
     }
 }
 
@@ -794,6 +768,7 @@ void ContextMenu::slotPwkeyRelease()
 void ContextMenu::slotClose()
 {
     qDebug("close");
+
     do_hw_key_event(KEY_PRESSED, HARD_KEY_POWER);
 
     longPressTimer->setInterval(CLOSE_POWER_KEY_INTERVAL);
@@ -822,6 +797,23 @@ QAction *ContextMenu::getActionTopMost()
     return actionTopMost;
 }
 
+QMessageBox *ContextMenu::showMsgBox(
+    int iconType, const QString &text, int buttons)
+{
+    qDebug() << text;
+
+    QMessageBox *msgBox = new QMessageBox((QMessageBox::Icon)iconType,
+        "Emulator", text, (QMessageBox::StandardButton)buttons, parent);
+    msgBox->setAttribute(Qt::WA_DeleteOnClose);
+    msgBox->show(); /* non-blocking */
+
+#ifdef CONFIG_LINUX
+    slotTopMost(parent->getUIState()->isOnTop());
+#endif
+
+    return msgBox;
+}
+
 ContextMenu::~ContextMenu()
 {
     qDebug("destroy menu");
index cacc56c..e4682bc 100644 (file)
@@ -114,7 +114,7 @@ protected:
 private:
     QAction *addGeneralAction(QMenu *menu,
         const QIcon &icon, const QString &text, const char *slot);
-    void showPopup(QString msg);
+    QMessageBox *showMsgBox(int iconType, const QString &text, int buttons = 0);
 
     MainWindow *parent;
     QString vmName;
index 1e50c73..d476ab5 100644 (file)
@@ -51,7 +51,7 @@ void UIUtil::setTopMost(QWidget *widget, bool on)
     HWND hWndInsertAfter = ((on == true) ? HWND_TOPMOST : HWND_NOTOPMOST);
     SetWindowPos(hWnd, hWndInsertAfter, widget->pos().x(), widget->pos().y(), 0, 0, SWP_NOSIZE);
 #elif defined(CONFIG_LINUX)
-    Displaydisplay = XOpenDisplay(NULL);
+    Display *display = XOpenDisplay(NULL);
     if (display == NULL) {
         qDebug("Error: XOpenDisplay() Failed. Always on top failed.");
         return;