dnd: implement file push/install
authorMunkyu Im <munkyu.im@samsung.com>
Tue, 12 Apr 2016 09:00:09 +0000 (18:00 +0900)
committerMunkyu Im <munkyu.im@samsung.com>
Tue, 19 Apr 2016 05:20:24 +0000 (14:20 +0900)
 - install: support one wgt/tpk/rpm file.
 - push: support multiple files/directories.
 - rename "shellopener" to "sdbhelper" and
   add more sdb specific job.
- Limitation:
  We use sdb client to push/install, but it has
  some issues related with exit code and error message.
  it will be fixed soon by sdb developers.

Change-Id: I5e6f06b36f8a354e79a9c42386042c3ca7b3c89a
Signed-off-by: Munkyu Im <munkyu.im@samsung.com>
12 files changed:
tizen/src/ui/displaybase.cpp
tizen/src/ui/displaybase.h
tizen/src/ui/menu/Makefile.objs
tizen/src/ui/menu/contextmenu.cpp
tizen/src/ui/menu/contextmenu.h
tizen/src/ui/menu/sdbhelper.cpp [new file with mode: 0644]
tizen/src/ui/menu/sdbhelper.h [new file with mode: 0644]
tizen/src/ui/menu/sdbhelperthread.cpp [new file with mode: 0644]
tizen/src/ui/menu/sdbhelperthread.h [new file with mode: 0644]
tizen/src/ui/menu/shellopener.cpp [deleted file]
tizen/src/ui/menu/shellopener.h [deleted file]
tizen/src/ui/resource/ui_strings.h

index 04fcadf900a8cf3b6714320762f8734aa839076b..ebac382a71607a15fd35464aa0d873195847967d 100644 (file)
@@ -32,6 +32,7 @@
 #include "displaybase.h"
 #include "mainwindow.h"
 #include "resource/ui_strings.h"
+#include "menu/sdbhelper.h"
 
 extern "C" {
 #include "util/ui_operations.h"
@@ -63,6 +64,8 @@ DisplayBase::DisplayBase(DisplayType *displayForm, QSize resolution, qreal scale
     this->movingMode = false;
     this->grabPos = SKINVIEW_NULLITY_POSITION;
     this->grabWinPos = win->pos();
+    this->dropping = false;
+    this->sdbHelper = new SdbHelper((MainWindow *)widget->parentWidget(), this);
 
     this->isTsEnabled = is_touchscreen_enabled();
     if (isTsEnabled == true) {
@@ -220,6 +223,9 @@ void DisplayBase::handleResize(QResizeEvent *event)
             maskImage.width() * scaleFactor,
             maskImage.height() * scaleFactor).mask());
     }
+
+    /* update widget position */
+    sdbHelper->updateGeometry(rect);
 }
 
 QPoint DisplayBase::getGuestPos(QPoint hostPos)
@@ -441,17 +447,79 @@ void DisplayBase::turnOffMovingMode()
 
 void DisplayBase::handleDragEnterEvent(QDragEnterEvent *event)
 {
-    if (event->mimeData()->hasUrls()) {
+    if (!event->mimeData()->hasUrls()) {
+        qDebug() << "ignore action";
+        event->setDropAction(Qt::IgnoreAction);
+    }
+    /* check if sdb is ready */
+    if (!sdbHelper->isSdbReady()) {
+        event->setDropAction(Qt::IgnoreAction);
+        return;
+    }
+
+    foreach (const QUrl &url, event->mimeData()->urls()) {
+        QString fileName = url.toLocalFile();
+        if (fileName.isEmpty()) {
+            qDebug() << "empty file";
+            event->setDropAction(Qt::IgnoreAction);
+            return;
+        }
+    }
+
+    if (dropping == false && sdbHelper->isProgressing() == false) {
         event->acceptProposedAction();
+        event->setDropAction(Qt::CopyAction);
+    } else {
+        event->setDropAction(Qt::IgnoreAction);
     }
 }
 
 void DisplayBase::handleDropEvent(QDropEvent *event)
 {
-    foreach (const QUrl &url, event->mimeData()->urls()) {
+    dropping = true;
+    QList<QUrl> urls = event->mimeData()->urls();
+    QList<QString> fileNameList;
+    int result;
+    foreach (const QUrl &url, urls) {
         QString fileName = url.toLocalFile();
-        qDebug() << "Dropped file:" << fileName;
+        if (!fileName.isEmpty()) {
+            fileNameList << fileName;
+        }
+    }
+
+    if (fileNameList.isEmpty()) {
+        qDebug("There is nothing to drop.");
+        return;
     }
+    qDebug() << "fileNameList: " << fileNameList;
+
+    //TODO: support user selected path
+    QString path = SDB_PUSH_DEFAULT_PATH;
+    /* Installation is supported if dropping item is only one packaging file.*/
+    if (fileNameList.size() == 1) {
+        QString installFileName = fileNameList.at(0);
+        QFileInfo fi(installFileName);
+        QString extension = fi.suffix();
+        if (QString::compare(extension, FILE_EXTENSION_WGT, Qt::CaseInsensitive) == 0 ||
+                QString::compare(extension, FILE_EXTENSION_TPK, Qt::CaseInsensitive) == 0 ||
+                QString::compare(extension, FILE_EXTENSION_RPM, Qt::CaseInsensitive) == 0) {
+            result = QMessageBox::question(win, EMULATOR_TITLE,
+                    MSG_INSTALL_POPUP + installFileName, QMessageBox::Yes, QMessageBox::No | QMessageBox::Default);
+            if (result == QMessageBox::Yes) {
+                sdbHelper->install(fi);
+            }
+            dropping = false;
+            return;
+        }
+    }
+
+    /* multiple files */
+    result = QMessageBox::question(win, EMULATOR_TITLE,
+            MSG_PUSH_POPUP + path, QMessageBox::Yes, QMessageBox::No | QMessageBox::Default);
+    if (result == QMessageBox::Yes) {
+        sdbHelper->push(fileNameList, path);
+    }
+    dropping = false;
 }
 
 bool DisplayBase::isMovingMode()
@@ -491,4 +559,7 @@ DisplayBase::~DisplayBase()
     if (mouseHelper != NULL) {
         delete mouseHelper;
     }
+    if (sdbHelper != NULL) {
+        delete sdbHelper;
+    }
 }
index 3279f663ab2143b7f5b4973c51fcef008c53646d..21ce9956c8464bdbdd266f823a0e05d09b0a1846 100644 (file)
 #include "input/mousehelper.h"
 
 class MainWindow;
+class SdbHelper;
 
 class DisplayBase
 {
 public:
+    SdbHelper *sdbHelper;
     void switchForm(DisplayType *displayForm);
     void scaleForm(qreal scaleFactor);
     void update();
     void updateGeometry();
+    QWidget *getWidget();
     const QRect &getGeometry();
     QRegion getMask();
 
@@ -107,6 +110,7 @@ private:
     TouchScreenHelper *tsHelper;
     MouseHelper *mouseHelper;
 
+    bool dropping;
     QLabel *offGuide;
     QPixmap offGuideImg;
     bool offGuideShown;
index f01325a877a71ec48e2d3f82377a81cfec0bc091..22975104f19e6b3ede2b4fd3a6e3e0e038a2cbbc 100644 (file)
@@ -5,7 +5,9 @@ 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-$(CONFIG_QT) += sdbhelper.o moc_sdbhelper.o
+obj-$(CONFIG_QT) += sdbhelperthread.o moc_sdbhelperthread.o
+
 
 $(obj)/moc_detailedinfodialog.cpp: $(obj)/detailedinfodialog.h
        moc $< -o $@
@@ -13,6 +15,10 @@ $(obj)/moc_contextmenu.cpp: $(obj)/contextmenu.h
        moc $< -o $@
 $(obj)/moc_screenshotdialog.cpp: $(obj)/screenshotdialog.h
        moc $< -o $@
+$(obj)/moc_sdbhelper.cpp: $(obj)/sdbhelper.h
+       moc $< -o $@
+$(obj)/moc_sdbhelperthread.cpp: $(obj)/sdbhelperthread.h
+       moc $< -o $@
 
 # product extension
 ifdef CONFIG_EXTENSION_PATH
index 4e4514ca82db15de040647194571589cc22c3e4c..ce681217f68c2d66f46a7838ddb897dd56606145 100644 (file)
@@ -80,7 +80,7 @@ ContextMenu::ContextMenu(QWidget *parent) : QMenu(parent)
         + QString::number(get_vm_device_serial_number());
 
     /* for SDB shell */
-    shellOpener = new ShellOpener();
+    sdbHelper = new SdbHelper(this->parent, this->parent->getDisplay());
 
     /* for close */
     longPressTimer = new QTimer(this);
@@ -917,7 +917,7 @@ void ContextMenu::slotShell()
 {
     qDebug("SDB shell");
 
-    const QString sdbPath = shellOpener->getSdbPath();
+    const QString sdbPath = sdbHelper->getSdbPath();
 
     QFileInfo sdbFileInfo(sdbPath);
     if (sdbFileInfo.exists() == false) {
@@ -931,7 +931,7 @@ void ContextMenu::slotShell()
     }
 
     /* start command in a new process */
-    shellOpener->openShell(vmName);
+    sdbHelper->openShell(vmName);
 }
 
 void ContextMenu::slotControlPanel()
@@ -1145,7 +1145,7 @@ ContextMenu::~ContextMenu()
         infoDialog = NULL;
     }
 
-    delete shellOpener;
+    delete sdbHelper;
 
     longPressTimer->stop();
 
index bae1553eb7995c492f55a2449f88b5928274a718..7dad213ff9b94aa5c295e040db2859efabec7dfb 100644 (file)
@@ -39,7 +39,7 @@
 #include "aboutdialog.h"
 #include "screenshotdialog.h"
 #include "menu/menuitem.h"
-#include "menu/shellopener.h"
+#include "menu/sdbhelper.h"
 #include "input/keyboardshortcut.h"
 
 class MainWindow;
@@ -161,7 +161,7 @@ private:
     QSignalMapper *scaleMapper;
     QSignalMapper *controllerMapper;
 
-    ShellOpener *shellOpener;
+    SdbHelper *sdbHelper;
     QTimer *longPressTimer;
     QTimer *rebootTimer;
 };
diff --git a/tizen/src/ui/menu/sdbhelper.cpp b/tizen/src/ui/menu/sdbhelper.cpp
new file mode 100644 (file)
index 0000000..3d5eb9a
--- /dev/null
@@ -0,0 +1,266 @@
+/*
+ * Qt UI
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Munkyu Im <munkyu.im@samsung.com>
+ * 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 "mainwindow.h"
+#include "sdbhelper.h"
+#include "sdbhelperthread.h"
+#include "resource/ui_strings.h"
+
+extern "C" {
+#include "emul_state.h"
+#include "util/net_helper.h"
+}
+
+SdbHelper::SdbHelper(MainWindow *parent, DisplayBase *displaybase)
+{
+    QString tmpSdbPath = QCoreApplication::applicationDirPath();
+#ifdef CONFIG_WIN32
+    QString tmpAnsiconPath = QCoreApplication::applicationDirPath();
+    tmpAnsiconPath += "\\..\\..\\..\\..\\..\\tools\\ansicon.exe";
+    ansiconPath = QDir::toNativeSeparators(tmpAnsiconPath);
+
+    sdbPath = QDir::toNativeSeparators(tmpSdbPath);
+    tmpSdbPath += "\\..\\..\\..\\..\\..\\tools\\sdb.exe";
+#else
+    tmpSdbPath += "/../../../../../tools/sdb";
+#endif
+    sdbPath = QDir::toNativeSeparators(tmpSdbPath);
+    this->mainWindow = parent;
+    this->displaybase = displaybase;
+    this->progressing = false;
+
+    connect(this, SIGNAL(geometryChanged(QRect)), this, SLOT(handleGeometryChanged(QRect)));
+}
+
+bool SdbHelper::isSdbReady()
+{
+    QFileInfo sdbFileInfo(sdbPath);
+    if (sdbFileInfo.exists() == false) {
+        qDebug(MSG_SDB_NOT_EXIST);
+        return false;
+    }
+
+    if (!is_sdb_daemon_initialized()) {
+        qDebug(MSG_SDB_NOT_READY);
+        return false;
+    }
+    return true;
+}
+
+QString SdbHelper::getSdbPath()
+{
+    return sdbPath;
+}
+
+MainWindow *SdbHelper::getMainWindow()
+{
+    return mainWindow;
+}
+
+DisplayBase *SdbHelper::getDisplayBase()
+{
+    return displaybase;
+}
+
+void SdbHelper::updateGeometry(QRect rect)
+{
+    emit geometryChanged(rect);
+}
+
+void SdbHelper::push(QList<QString> srcList, const QString &dest)
+{
+    QString program;
+    QStringList arguments;
+    QList<QStringList> argList;
+
+    QString sdbSerialName = getSerialName();
+    program = sdbPath;
+    foreach ( const QString &src, srcList) {
+        arguments << "-s" << sdbSerialName << "push" << src << dest + g_path_get_basename(src.toLocal8Bit().data());
+        argList << arguments;
+    }
+
+    SdbHelperThread *thread = new SdbHelperThread(this);
+    thread->setArguments(SDB_PUSH_COMMNAD , program, argList);
+    connect(thread, SIGNAL(started()), this, SLOT(handleThreadStarted()));
+    connect(thread, SIGNAL(finished()), this, SLOT(handleThreadFinished()));
+    connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
+    thread->start();
+}
+
+void SdbHelper::install(QFileInfo fi)
+{
+    if (QString::compare(fi.suffix(), FILE_EXTENSION_RPM, Qt::CaseInsensitive) == 0) {
+        installRpm(fi);
+        return;
+    }
+    QString program;
+    QStringList arguments;
+    QList<QStringList> argList;
+
+    QString sdbSerialName = getSerialName();
+    program = sdbPath;
+    arguments << "-s" << sdbSerialName << "install" << fi.absoluteFilePath();
+    argList << arguments;
+    qDebug() << program << arguments;
+
+    SdbHelperThread *thread = new SdbHelperThread(this);
+    thread->setArguments(SDB_INSTALL_COMMAND, program, argList);
+    connect(thread, SIGNAL(started()), this, SLOT(handleThreadStarted()));
+    connect(thread, SIGNAL(finished()), this, SLOT(handleThreadFinished()));
+    connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
+    thread->start();
+}
+
+void SdbHelper::installRpm(QFileInfo fi)
+{
+    QString program;
+    QStringList argRootOn;
+    QStringList argPush;
+    QStringList argInstall;
+    QStringList argRemove;
+    QStringList argRootOff;
+    QList<QStringList> argList;
+    QString baseName = fi.fileName();
+    QString destFileName = QString(GUEST_TMP_PATH + baseName);
+    QString sdbSerialName = getSerialName();
+    program = sdbPath;
+    /* to install rpm package, need sudo permission. */
+    argRootOn << "root" << "on";
+    argList << argRootOn;
+
+    argPush << "-s" << sdbSerialName << "push" << fi.absoluteFilePath() << GUEST_TMP_PATH;
+    argList << argPush;
+
+    argInstall << "-s" << sdbSerialName << "shell" << "rpm" << "-Uvh" << destFileName << "--force" << "--nodeps";
+    argList << argInstall;
+
+    argRemove << "-s" << sdbSerialName << "shell" << "rm" << "-f" << destFileName;
+    argList << argRemove;
+
+    argRootOff << "root" << "off";
+    argList << argRootOff;
+
+    qDebug() << program << argList;
+
+    SdbHelperThread *thread = new SdbHelperThread(this);
+    thread->setArguments(SDB_INSTALL_COMMAND, program, argList);
+    connect(thread, SIGNAL(started()), this, SLOT(handleThreadStarted()));
+    connect(thread, SIGNAL(finished()), this, SLOT(handleThreadFinished()));
+    connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
+    thread->start();
+}
+
+void SdbHelper::handleThreadStarted()
+{
+    progressBar = new QProgressBar((QWidget *)mainWindow);
+    progressBar->setAlignment(Qt::AlignCenter);
+    progressBar->setMinimum(0);
+    progressBar->setMaximum(0);
+    progressBar->setValue(0);
+    progressBar->setTextVisible(false);
+    progressBar->setAttribute(Qt::WA_DeleteOnClose);
+    progressBar->setWindowModality(Qt::NonModal);
+    QRect rect = getDisplayBase()->getGeometry();
+    int x = rect.x() + (rect.width() - progressBar->width()) / 2;
+    int y = rect.y() + (rect.height() - progressBar->height()) / 2;
+    progressBar->move(x,y);
+    progressBar->resize(PROGRESSBAR_DEFAULT_WITDH, PROGRESSBAR_DEFAULT_HEIGHT);
+    setProgressing(true);
+    progressBar->show();
+}
+
+void SdbHelper::handleThreadFinished()
+{
+   progressBar->close();
+   setProgressing(false);
+}
+
+void SdbHelper::handleGeometryChanged(QRect newRect)
+{
+    //XXX: need to support rotation?
+    qDebug() << "handleGeometryChanged: " << newRect;
+    if (isProgressing()) {
+        QRect rect = getDisplayBase()->getGeometry();
+        int x = rect.x() + (rect.width() - progressBar->width()) / 2;
+        int y = rect.y() + (rect.height() - progressBar->height()) / 2;
+        qDebug() << " x: " << x << " ,y: " << y;
+        progressBar->move(x,y);
+        progressBar->update();
+    }
+}
+
+void SdbHelper::setProgressing(bool isProgressing)
+{
+    this->progressing = isProgressing;
+}
+
+bool SdbHelper::isProgressing()
+{
+    return this->progressing;
+}
+
+QString SdbHelper::getSerialName()
+{
+    QString sdbPort = QString::number(get_vm_device_serial_number());
+    QString sdbSerialName;
+    if (is_netclient_tap_attached()) {
+        sdbSerialName = QString(get_guest_ip());
+    } else {
+        sdbSerialName = "emulator-" + sdbPort;
+    }
+    return sdbSerialName;
+}
+
+void SdbHelper::openShell(QString title)
+{
+    qDebug() << "open the shell";
+
+    QString command;
+    QStringList arguments;
+
+    QString sdbSerialName = getSerialName();
+#ifdef CONFIG_WIN32
+    command = ansiconPath;
+    arguments << "sdb" << "-s" << sdbSerialName << "shell";
+#elif defined CONFIG_DARWIN
+    command = QDir::toNativeSeparators(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);
+}
diff --git a/tizen/src/ui/menu/sdbhelper.h b/tizen/src/ui/menu/sdbhelper.h
new file mode 100644 (file)
index 0000000..cf167a9
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * 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 SDBHELPER_H
+#define SDBHELPER_H
+
+#include <QtWidgets>
+
+class MainWindow;
+class DisplayBase;
+
+class SdbHelper : public QObject
+{
+    Q_OBJECT
+public:
+    explicit SdbHelper(MainWindow *parent, DisplayBase *displaybase);
+
+    QString getSdbPath();
+    QString getSerialName();
+    void install(QFileInfo fi);
+    void push(QList<QString> src, const QString &dest);
+    void openShell(QString title);
+    bool isProgressing();
+    DisplayBase *getDisplayBase();
+    MainWindow *getMainWindow();
+    void updateGeometry(QRect rect);
+    bool isSdbReady();
+
+signals:
+    void geometryChanged(QRect rect);
+
+private:
+    QString sdbPath;
+#ifdef CONFIG_WIN32
+    QString ansiconPath;
+#endif
+    bool progressing;
+    MainWindow *mainWindow;
+    QProgressBar *progressBar;
+    QProcess *process;
+    DisplayBase *displaybase;
+    void setProgressing(bool isProgressing);
+    void installRpm(QFileInfo fi);
+
+public slots:
+    void handleThreadStarted();
+    void handleThreadFinished();
+    void handleGeometryChanged(QRect rect);
+};
+
+#endif // SDBHELPER_H
diff --git a/tizen/src/ui/menu/sdbhelperthread.cpp b/tizen/src/ui/menu/sdbhelperthread.cpp
new file mode 100644 (file)
index 0000000..86b7028
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * Qt UI
+ *
+ * Copyright (C) 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Munkyu Im <munkyu.im@samsung.com>
+ * seokYeon Hwang <syeon.hwang@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 "sdbhelperthread.h"
+#include "sdbhelper.h"
+#include "displaybase.h"
+#include "resource/ui_strings.h"
+
+extern "C" {
+#include "emul_state.h"
+}
+
+SdbHelperThread::SdbHelperThread(SdbHelper *parent)
+{
+    this->parent = parent;
+    connect(this, SIGNAL(errorOccured(QString, int)), this, SLOT(handleErrorOccured(QString, int)));
+}
+
+void SdbHelperThread::setArguments(int command, QString &program, QList<QStringList> &args)
+{
+    this->command = command;
+    this->program = program;
+    this->arguments = args;
+}
+
+void SdbHelperThread::run()
+{
+    if (program.isEmpty() || arguments.isEmpty())
+        return;
+
+    for (int i = 0; i < arguments.size(); ++i) {
+        qDebug() << "program: " << program << arguments.at(i);
+        process = new QProcess();
+        process->deleteLater();
+        process->start(program, arguments.at(i));
+        process->waitForFinished();
+        outMsg = QString::fromLocal8Bit(process->readAllStandardOutput());
+        //FIXME: (sdb) geneal pushing log may redirect to stderr
+        errorMsg = QString::fromLocal8Bit(process->readAllStandardError());
+        qDebug() << "errorMsg" << errorMsg;
+        qDebug() << "outMsg" << outMsg;
+        //FIXME: (sdb) general sdb installation failure message is printed with stdout */
+        if (command == SDB_INSTALL_COMMAND && outMsg.contains(SDB_INSTALL_FAILURE)) {
+            emit errorOccured(outMsg, process->exitCode());
+            return;
+        }
+        if (process->exitCode() || process->exitStatus()) {
+            emit errorOccured(errorMsg, process->exitCode());
+            return;
+        }
+        process->close();
+    }
+}
+
+void SdbHelperThread::handleErrorOccured(QString errString, int exitCode)
+{
+    qDebug() << "exitcode: " << exitCode;
+    //FIXME: (sdb) cannot returns exit code like "no space left"
+    showMsgBox(QMessageBox::Warning, MSG_SDB_FAILED_PROCESSING + errString);
+    if (process) {
+        process->close();
+    }
+}
+
+QMessageBox *SdbHelperThread::showMsgBox(
+    QMessageBox::Icon iconType, const QString &text,
+    QMessageBox::StandardButtons buttons,
+    QMessageBox::StandardButton defaultButton)
+{
+    qWarning() << text;
+
+    QMessageBox *msgBox = new QMessageBox(iconType,
+        EMULATOR_TITLE, text, buttons, (QWidget *)parent->getMainWindow());
+    if (defaultButton != QMessageBox::NoButton) {
+        msgBox->setDefaultButton(defaultButton);
+    }
+    msgBox->setAttribute(Qt::WA_DeleteOnClose);
+    msgBox->setModal(false);
+    msgBox->show(); /* non-blocking */
+
+    return msgBox;
+}
diff --git a/tizen/src/ui/menu/sdbhelperthread.h b/tizen/src/ui/menu/sdbhelperthread.h
new file mode 100644 (file)
index 0000000..778a0f1
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Qt UI
+ *
+ * Copyright (C) 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Munkyu Im <munkyu.im@samsung.com>
+ * seokYeon Hwang <syeon.hwang@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 SDBHELPERTHREAD_H
+#define SDBHELPERTHREAD_H
+
+#include <QtWidgets>
+#include <QProcess>
+#include <QThread>
+#include <QDebug>
+
+class SdbHelper;
+
+class SdbHelperThread : public QThread
+{
+    Q_OBJECT
+public:
+    explicit SdbHelperThread(SdbHelper *parent);
+    void setArguments(int command, QString& program, QList<QStringList>& args);
+private:
+    void run();
+    SdbHelper *parent;
+    QProcess *process;
+    QString program;
+    QList<QStringList> arguments;
+    int command;
+    QString errorMsg;
+    QString outMsg;
+    QMessageBox *showMsgBox(QMessageBox::Icon iconType, const QString &text,
+        QMessageBox::StandardButtons buttons = QMessageBox::NoButton,
+        QMessageBox::StandardButton defaultButton = QMessageBox::NoButton);
+signals:
+    void errorOccured(QString errString, int exitCode);
+public slots:
+    void handleErrorOccured(QString errString, int exitCode);
+};
+#endif // SDBHELPERTHREAD_H
diff --git a/tizen/src/ui/menu/shellopener.cpp b/tizen/src/ui/menu/shellopener.cpp
deleted file mode 100644 (file)
index cd1bc1d..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * 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()
-{
-    QString tmpSdbPath = QCoreApplication::applicationDirPath();
-#ifdef CONFIG_WIN32
-    tmpSdbPath += "\\..\\..\\..\\..\\..\\tools\\ansicon.exe";
-#else
-    tmpSdbPath += "/../../../../../tools/sdb";
-#endif
-    sdbPath = QDir::toNativeSeparators(tmpSdbPath);
-}
-
-QString ShellOpener::getSdbPath()
-{
-    return sdbPath;
-}
-
-void ShellOpener::openShell(QString title)
-{
-    qDebug() << "open the shell";
-
-    QString command;
-    QStringList arguments;
-
-    QString sdbPort = QString::number(get_vm_device_serial_number());
-    QString sdbSerialName;
-    if (is_netclient_tap_attached()) {
-        sdbSerialName = QString(get_guest_ip());
-    } else {
-        sdbSerialName = "emulator-" + sdbPort;
-    }
-
-#ifdef CONFIG_WIN32
-    command = sdbPath;
-    arguments << "sdb" << "-s" << sdbSerialName << "shell";
-#elif defined CONFIG_DARWIN
-    command = QDir::toNativeSeparators(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()
-{
-    /* do nothing */
-}
diff --git a/tizen/src/ui/menu/shellopener.h b/tizen/src/ui/menu/shellopener.h
deleted file mode 100644 (file)
index da55e58..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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
index 5e6b6bd8de3c79bd5695f9be1abe14cc1d38f21d..02b6134329c48fe6c12740d8d12a202a7f8bd9fb 100644 (file)
 #define ABOUT_BUILD_DATE_TEXT "Build Date"
 #define ABOUT_VISIT_TEXT "Visit"
 
+/* SDB related */
+#define FILE_EXTENSION_WGT "wgt"
+#define FILE_EXTENSION_TPK "tpk"
+#define FILE_EXTENSION_RPM "rpm"
+#define SDB_PUSH_DEFAULT_PATH "/home/developer/"
+#define GUEST_TMP_PATH "/tmp/"
+#define SDB_INSTALL_FAILURE "val[fail]"
+#define SDB_PUSH_COMMNAD 1
+#define SDB_INSTALL_COMMAND 2
+#define PROGRESSBAR_DEFAULT_WITDH 100
+#define PROGRESSBAR_DEFAULT_HEIGHT 20
+
 /* style sheet*/
 #define STYLE_TOOLTIP "QToolTip {"\
                   "color: black; background-color: white; border: 1px solid black; }"
 #define MSG_FORCE_CLOSE_POPUP "If you force stop an emulator, it may cause some problems.\n"\
                           "Are you sure you want to continue?"
 #define MSG_CLOSE_POPUP "Do you really want to quit this program?"
+#define MSG_PUSH_POPUP "Are you sure you want to push files or directories\ninto the following path of the emulator?\n"
+#define MSG_INSTALL_POPUP "Are you sure you want to install the following package file?\n"
+#define MSG_SDB_FAILED_PROCESSING "Failed while processing.\n\nError Message:\n"
 
 /* qFatal messages */
 #define MSG_INTERNAL_ERR "An internal error occurred : \n\n"