From: Munkyu Im Date: Tue, 26 Apr 2016 10:29:25 +0000 (+0900) Subject: dnd: modify dialog box X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.2~42^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=deab0aafbb66d28c11dc128869eee3e7a9547d11;p=sdk%2Femulator%2Fqemu.git dnd: modify dialog box - show default path for pushing file. - show sudo permission notification. - modify default button of question dialog. - add text box to input directory to be pushed. Change-Id: If90a4989c802e87c6187fb34633c528af6695bab Signed-off-by: Munkyu Im --- diff --git a/tizen/src/emul_state.c b/tizen/src/emul_state.c index 22d9dd5238..d948275a4e 100644 --- a/tizen/src/emul_state.c +++ b/tizen/src/emul_state.c @@ -124,6 +124,20 @@ const char* get_emul_skin_path(void) return _emul_info.skin_path; } +const char* get_emul_guest_home_path(void) +{ + return _emul_info.guest_home_path; +} + +void set_emul_guest_home_path(char *home_path) +{ + if (!_emul_info.guest_home_path) { + _emul_info.guest_home_path = home_path; + } else { + LOG_INFO("guest home path is already set : %s\n", _emul_info.guest_home_path); + } +} + /* CPU virtualization */ bool get_emul_cpu_accel(void) { diff --git a/tizen/src/emul_state.h b/tizen/src/emul_state.h index 90cccf1b7e..1a65aa5d40 100644 --- a/tizen/src/emul_state.h +++ b/tizen/src/emul_state.h @@ -84,6 +84,7 @@ enum { typedef struct EmulatorConfigInfo { const char *skin_path; const char *file_sharing_path; + const char *guest_home_path; /* add here */ } EmulatorConfigInfo; @@ -102,9 +103,11 @@ void set_emulator_condition(int state); void set_emul_tap_enable(bool enable); void set_emuld_connection(bool connected); void set_sdb_connection(bool connected); +void set_emul_guest_home_path(char *home_path); /* getter */ const char* get_emul_skin_path(void); +const char* get_emul_guest_home_path(void); bool get_emul_cpu_accel(void); int get_emulator_condition(void); diff --git a/tizen/src/ui/displaybase.cpp b/tizen/src/ui/displaybase.cpp index ebac382a71..e35b7653e5 100644 --- a/tizen/src/ui/displaybase.cpp +++ b/tizen/src/ui/displaybase.cpp @@ -453,6 +453,7 @@ void DisplayBase::handleDragEnterEvent(QDragEnterEvent *event) } /* check if sdb is ready */ if (!sdbHelper->isSdbReady()) { + qDebug("sdb is not ready"); event->setDropAction(Qt::IgnoreAction); return; } @@ -493,8 +494,6 @@ void DisplayBase::handleDropEvent(QDropEvent *event) } 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); @@ -504,7 +503,7 @@ void DisplayBase::handleDropEvent(QDropEvent *event) 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); + MSG_INSTALL_POPUP + installFileName, QMessageBox::Yes | QMessageBox::Default, QMessageBox::No); if (result == QMessageBox::Yes) { sdbHelper->install(fi); } @@ -514,11 +513,38 @@ void DisplayBase::handleDropEvent(QDropEvent *event) } /* 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); + QString defaultPath = sdbHelper->getGuestDefaultPushPath(); + if (!items.contains(defaultPath)) { + items << defaultPath; } + + QInputDialog *dialog = new QInputDialog(win); + bool isOk; + do { + QString dir = dialog->getItem(win, EMULATOR_TITLE, + MSG_PUSH_POPUP, items, 0, true, &isOk); + if (!isOk) { + break; + } + if (dir.isEmpty()) { + qDebug() << "dir is empty."; + QMessageBox::warning(win, EMULATOR_TITLE, MSG_EMPTY_DIR, + QMessageBox::Ok | QMessageBox::Default); + /* retry */ + continue; + } else { + if (!dir.endsWith("/")) { + dir.append("/"); + } + sdbHelper->push(fileNameList, dir); + /* TODO: check if dir is exist or has permission to push. */ + if (!items.contains(dir)) { + items << dir; + } + break; + } + } while (true); + dropping = false; } diff --git a/tizen/src/ui/displaybase.h b/tizen/src/ui/displaybase.h index 21ce9956c8..73d96c6274 100644 --- a/tizen/src/ui/displaybase.h +++ b/tizen/src/ui/displaybase.h @@ -109,7 +109,7 @@ private: TouchScreenHelper *tsHelper; MouseHelper *mouseHelper; - + QStringList items; bool dropping; QLabel *offGuide; QPixmap offGuideImg; diff --git a/tizen/src/ui/menu/sdbhelper.cpp b/tizen/src/ui/menu/sdbhelper.cpp index 3d5eb9ae60..4ac7814cdc 100644 --- a/tizen/src/ui/menu/sdbhelper.cpp +++ b/tizen/src/ui/menu/sdbhelper.cpp @@ -72,9 +72,20 @@ bool SdbHelper::isSdbReady() qDebug(MSG_SDB_NOT_READY); return false; } + + if (QString(get_emul_guest_home_path()).isEmpty()) { + return false; + } + return true; } +QString SdbHelper::getGuestDefaultPushPath() +{ + QString home_path = get_emul_guest_home_path(); + return home_path + "content" + "/"; +} + QString SdbHelper::getSdbPath() { return sdbPath; @@ -154,7 +165,14 @@ void SdbHelper::installRpm(QFileInfo fi) QString sdbSerialName = getSerialName(); program = sdbPath; /* to install rpm package, need sudo permission. */ - argRootOn << "root" << "on"; + int result = QMessageBox::question(mainWindow, EMULATOR_TITLE, + MSG_SDB_ROOT_ON, QMessageBox::Yes, QMessageBox::No | QMessageBox::Default); + if (result == QMessageBox::No) { + return; + } + + //FIXME: (sdb) cannot check sdb root status + argRootOn << "-s" << sdbSerialName << "root" << "on"; argList << argRootOn; argPush << "-s" << sdbSerialName << "push" << fi.absoluteFilePath() << GUEST_TMP_PATH; @@ -166,7 +184,7 @@ void SdbHelper::installRpm(QFileInfo fi) argRemove << "-s" << sdbSerialName << "shell" << "rm" << "-f" << destFileName; argList << argRemove; - argRootOff << "root" << "off"; + argRootOff << "-s" << sdbSerialName << "root" << "off"; argList << argRootOff; qDebug() << program << argList; @@ -200,8 +218,8 @@ void SdbHelper::handleThreadStarted() void SdbHelper::handleThreadFinished() { - progressBar->close(); - setProgressing(false); + progressBar->close(); + setProgressing(false); } void SdbHelper::handleGeometryChanged(QRect newRect) diff --git a/tizen/src/ui/menu/sdbhelper.h b/tizen/src/ui/menu/sdbhelper.h index cf167a9306..cb16241818 100644 --- a/tizen/src/ui/menu/sdbhelper.h +++ b/tizen/src/ui/menu/sdbhelper.h @@ -42,6 +42,7 @@ public: explicit SdbHelper(MainWindow *parent, DisplayBase *displaybase); QString getSdbPath(); + QString getGuestDefaultPushPath(); QString getSerialName(); void install(QFileInfo fi); void push(QList src, const QString &dest); diff --git a/tizen/src/ui/menu/sdbhelperthread.cpp b/tizen/src/ui/menu/sdbhelperthread.cpp index 37c91b0d1e..2c0389ec6f 100644 --- a/tizen/src/ui/menu/sdbhelperthread.cpp +++ b/tizen/src/ui/menu/sdbhelperthread.cpp @@ -61,10 +61,11 @@ void SdbHelperThread::run() process->start(program, arguments.at(i)); process->waitForFinished(); outMsg = QString::fromLocal8Bit(process->readAllStandardOutput()); - //FIXME: (sdb) geneal pushing log may redirect to stderr + //FIXME: (sdb) general 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()); diff --git a/tizen/src/ui/menu/sdbhelperthread.h b/tizen/src/ui/menu/sdbhelperthread.h index 778a0f139c..5cdfcfc389 100644 --- a/tizen/src/ui/menu/sdbhelperthread.h +++ b/tizen/src/ui/menu/sdbhelperthread.h @@ -43,6 +43,7 @@ class SdbHelperThread : public QThread public: explicit SdbHelperThread(SdbHelper *parent); void setArguments(int command, QString& program, QList& args); + private: void run(); SdbHelper *parent; @@ -55,9 +56,13 @@ private: 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); + void finished(QString outMsg); + public slots: void handleErrorOccured(QString errString, int exitCode); + }; #endif // SDBHELPERTHREAD_H diff --git a/tizen/src/ui/resource/ui_strings.h b/tizen/src/ui/resource/ui_strings.h index 02b6134329..55eb671212 100644 --- a/tizen/src/ui/resource/ui_strings.h +++ b/tizen/src/ui/resource/ui_strings.h @@ -132,7 +132,6 @@ #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 @@ -159,9 +158,12 @@ #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_PUSH_POPUP "Are you sure you want to push files or directories\ninto the following directory 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" +#define MSG_SDB_ROOT_ON "This job needs root priviledge.\n"\ + "Are you sure you want to continue?" +#define MSG_EMPTY_DIR "Target directory is empty.\n" /* qFatal messages */ #define MSG_INTERNAL_ERR "An internal error occurred : \n\n" diff --git a/tizen/src/util/net_helper.c b/tizen/src/util/net_helper.c index 2b8d902fc6..4340803402 100644 --- a/tizen/src/util/net_helper.c +++ b/tizen/src/util/net_helper.c @@ -47,9 +47,14 @@ DECLARE_DEBUG_CHANNEL(sdb); #define BUF_SIZE 64 +#define MAX_TRIAL 20 +#define MAX_USER_NAME_LEN 36 +#define SLEEP_WAIT_SDB 500 /* ms */ int emul_vm_base_socket; static bool sdb_daemon_is_initialized = false; +static QemuThread thread_id; +bool processing = false; int inet_strtoip(const char* str, uint32_t *ip) { @@ -388,6 +393,75 @@ static void suspend_lock_state(int state) ecs_suspend_lock_state(state); } +static void *get_user_home_path(void *args) +{ + FILE *fp; + char user_name[MAX_USER_NAME_LEN]; + int index = 0; +#ifndef CONFIG_WIN32 + const char *sdb_path = "../../../../../tools/sdb"; +#else + const char *sdb_path = "..\\..\\..\\..\\..\\tools\\sdb.exe"; +#endif + if (processing) { + return NULL; + } + processing = true; + const char *bin_dir = get_bin_path(); + + if (get_emul_guest_home_path()) { + processing = false; + return NULL; + } + gchar *cmd_root_off = g_strdup_printf("\"%s%s\" -s emulator-%d root off", bin_dir, sdb_path, get_vm_device_serial_number()); + gchar *cmd_get_home = g_strdup_printf("\"%s%s\" -s emulator-%d shell id -un", + bin_dir, sdb_path, get_vm_device_serial_number()); + + //FIXME: (sdb) cannot check sdb root status + fp = popen(cmd_root_off, "r"); + if (fp == NULL) { + LOG_WARNING("Failed to run command\n"); + g_free(cmd_root_off); + processing = false; + return NULL; + } + g_free(cmd_root_off); + pclose(fp); + + while (index++ != MAX_TRIAL) { +#ifdef CONFIG_WIN32 + Sleep(SLEEP_WAIT_SDB); +#else + usleep(SLEEP_WAIT_SDB * 1000); +#endif + fp = popen(cmd_get_home, "r"); + if (fp == NULL) { + LOG_WARNING("Failed to run command\n"); + break; + } + + while (fgets(user_name, sizeof(user_name), fp) != NULL) { + LOG_INFO("user name: %s", user_name); + if (strlen(user_name) > 2) { + /* to remove carrige return and new line character */ + user_name[strlen(user_name) - 2] = '\0'; + } + } + + if (strlen(user_name) > 0) { + gchar *user_home_path = g_strdup_printf("/home/%s/", user_name); + LOG_INFO("guest_home_user_name: %s\n", user_home_path); + set_emul_guest_home_path(user_home_path); + pclose(fp); + break; + } + pclose(fp); + } + g_free(cmd_get_home); + processing = false; + return NULL; +} + static void command_handler(char* readbuf, struct sockaddr_in* client_addr) { char command[RECV_BUF_SIZE]; @@ -399,6 +473,7 @@ static void command_handler(char* readbuf, struct sockaddr_in* client_addr) LOG_TRACE("command:%s\n", command); if (strcmp(command, "2\n" ) == 0) { sdb_daemon_is_initialized = true; + qemu_thread_create(&thread_id, "get_home_path", get_user_home_path, NULL, QEMU_THREAD_DETACHED); } else if (strcmp(command, "5\n") == 0) { register_sdb_server(readbuf, client_addr); set_sdb_connection(true);