From: GiWoong Kim Date: Fri, 6 Mar 2015 06:36:16 +0000 (+0900) Subject: menu: make a wrapper function of message box X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.2~553 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0abd9b229b9873f6f8e834ba89b4c805916cc732;p=sdk%2Femulator%2Fqemu.git menu: make a wrapper function of message box Change-Id: I487a1f191d9f65a105f7e0ab50ed09202190ebfd Signed-off-by: GiWoong Kim --- diff --git a/tizen/src/ui/menu/contextmenu.cpp b/tizen/src/ui/menu/contextmenu.cpp index 54df96ff32..b1d0bc2aba 100644 --- a/tizen/src/ui/menu/contextmenu.cpp +++ b/tizen/src/ui/menu/contextmenu.cpp @@ -28,8 +28,6 @@ * */ -#include - #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"); diff --git a/tizen/src/ui/menu/contextmenu.h b/tizen/src/ui/menu/contextmenu.h index cacc56c88c..e4682bc060 100644 --- a/tizen/src/ui/menu/contextmenu.h +++ b/tizen/src/ui/menu/contextmenu.h @@ -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; diff --git a/tizen/src/ui/uiutil.cpp b/tizen/src/ui/uiutil.cpp index 1e50c73a78..d476ab5818 100644 --- a/tizen/src/ui/uiutil.cpp +++ b/tizen/src/ui/uiutil.cpp @@ -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) - Display* display = XOpenDisplay(NULL); + Display *display = XOpenDisplay(NULL); if (display == NULL) { qDebug("Error: XOpenDisplay() Failed. Always on top failed."); return;