menu: modified CopyToClipboard on Ubuntu 64bit 52/18852/1
authorGiWoong Kim <giwoong.kim@samsung.com>
Fri, 21 Mar 2014 11:35:54 +0000 (20:35 +0900)
committerGiWoong Kim <giwoong.kim@samsung.com>
Wed, 2 Apr 2014 05:50:48 +0000 (14:50 +0900)
replace JNI-GTK to Python-GTK

Change-Id: I5663d9768eeb5e78979295615fd91577febac17f
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/Makefile
tizen/src/skin/client/build.xml
tizen/src/skin/client/native_src/clipboard.py [new file with mode: 0644]
tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkin.java
tizen/src/skin/client/src/org/tizen/emulator/skin/EmulatorSkinMain.java
tizen/src/skin/client/src/org/tizen/emulator/skin/screenshot/ScreenShotDialog.java

index 9967cf6..efb53f6 100644 (file)
@@ -135,7 +135,7 @@ endif
 
 # use GTK for CopyToClipboard on Ubuntu 12.04 64bit
 ifdef CONFIG_LINUX
-       cp -pP skin/client/native_src/libclipboard.so $(EMUL_DIR)/bin
+       cp -pP skin/client/native_src/clipboard.py $(EMUL_DIR)/bin
 endif
 
 # change loading path of dynamic shared libraries on MAC OS X
@@ -244,7 +244,7 @@ endif
 
 # use GTK for CopyToClipboard on Ubuntu 12.04 64bit
 ifdef CONFIG_LINUX
-       cp -pP skin/client/native_src/libclipboard.so $(DIBS_COMMON_DIR)/bin
+       cp -pP skin/client/native_src/clipboard.py $(DIBS_COMMON_DIR)/bin
 endif
 
 # change loading path of dynamic shared libraries on MAC OS X
index 814e1c6..4fe9f2f 100644 (file)
                        <arg line="libshared.so" />
                </exec>
 
+               <!--
                <exec dir="native_src" executable="./check-gtk.sh" outputproperty="gtkabi" failifexecutionfails="false" />
                <echo message="gtkversion : ${gtkabi}" />
 
                </javah>
                <echo message="build libclipboard.so" />
                <exec executable="pkg-config" outputproperty="gtk" failifexecutionfails="false">
-                       <arg line="--cflags" />
-                       <arg line="--libs" />
+                       <arg line="- -cflags" />
+                       <arg line="- -libs" />
                        <arg line="${gtkabi}" />
                </exec>
                <exec dir="native_src" executable="gcc" failifexecutionfails="false">
                        <arg line="-o" />
                        <arg line="libclipboard.so" />
                </exec>
+               -->
 
                <delete>
                        <fileset dir="native_src" includes="**/*.h" />
diff --git a/tizen/src/skin/client/native_src/clipboard.py b/tizen/src/skin/client/native_src/clipboard.py
new file mode 100644 (file)
index 0000000..074e827
--- /dev/null
@@ -0,0 +1,15 @@
+#!/usr/bin/env python
+
+import pygtk
+import gtk
+import sys
+
+def copy_image(f):
+    image = gtk.gdk.pixbuf_new_from_file(f)
+
+    clipboard = gtk.clipboard_get()
+    clipboard.set_image(image)
+    clipboard.store()
+
+
+copy_image(sys.argv[1]);
index 4a33e73..43c5463 100755 (executable)
@@ -142,7 +142,7 @@ public class EmulatorSkin {
        private static Logger logger =
                        SkinLogger.getSkinLogger(EmulatorSkin.class).getLogger();
 
-       protected EmulatorConfig config;
+       public EmulatorConfig config;
        protected Shell shell;
        protected ImageRegistry imageRegistry;
        protected Canvas lcdCanvas;
index c8ef6d9..6c8ebbb 100644 (file)
@@ -138,6 +138,8 @@ public class EmulatorSkinMain {
                        logger.info("swt platform : " + SWT.getPlatform());
                        logger.info("swt version : " + SWT.getVersion());
 
+                       logger.info("working directory" + System.getProperty("user.dir"));
+
                        /* startup arguments parsing */
                        Map<String, String> argsMap = parseArgs(args);
                        EmulatorConfig.validateArgs(argsMap);
index 103a39c..a1506ca 100644 (file)
@@ -43,7 +43,6 @@ import java.util.logging.Logger;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.ScrolledComposite;
 import org.eclipse.swt.dnd.Clipboard;
-import org.eclipse.swt.dnd.DND;
 import org.eclipse.swt.dnd.ImageTransfer;
 import org.eclipse.swt.dnd.Transfer;
 import org.eclipse.swt.events.MouseEvent;
@@ -69,12 +68,12 @@ import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.FileDialog;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.MessageBox;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.ToolBar;
 import org.eclipse.swt.widgets.ToolItem;
 import org.tizen.emulator.skin.EmulatorSkin;
 import org.tizen.emulator.skin.config.EmulatorConfig;
+import org.tizen.emulator.skin.config.EmulatorConfig.ArgsConstants;
 import org.tizen.emulator.skin.exception.ScreenShotException;
 import org.tizen.emulator.skin.image.ImageRegistry;
 import org.tizen.emulator.skin.image.ImageRegistry.IconName;
@@ -98,30 +97,6 @@ public class ScreenShotDialog {
        private static Logger logger =
                        SkinLogger.getSkinLogger(ScreenShotDialog.class).getLogger();
 
-       static {
-               /* load JNI library file */
-               try {
-                       if (SwtUtil.isLinuxPlatform() == true &&
-                                       SwtUtil.is64bitPlatform() == true) {
-                               System.loadLibrary(JNI_LIBRARY_FILE);
-                       }
-               } catch (UnsatisfiedLinkError e) {
-                       logger.severe("Failed to load a " + JNI_LIBRARY_FILE + " file.\n" + e);
-
-                       Shell temp = new Shell(Display.getDefault());
-                       MessageBox messageBox = new MessageBox(temp, SWT.ICON_ERROR);
-                       messageBox.setText("Emulator");
-                       messageBox.setMessage(
-                                       "Failed to load a JNI library file from "
-                                       + System.getProperty("java.library.path") + ".\n\n" + e);
-                       messageBox.open();
-                       temp.dispose();
-               }
-       }
-
-       /* define JNI function */
-       public native int copyToClipboard(int width, int height, byte buf[]);
-
        protected EmulatorSkin skin;
        protected EmulatorConfig config;
        private Shell shell;
@@ -527,21 +502,46 @@ public class ScreenShotDialog {
 
                                loader.data = new ImageData[] { shotData };
 
-                               ByteArrayOutputStream bao = new ByteArrayOutputStream();
-                               loader.save(bao, SWT.IMAGE_PNG);
-
-                               ImageData pngData = new ImageData(
-                                               new ByteArrayInputStream(bao.toByteArray()));
-
                                if (SwtUtil.isLinuxPlatform() == true &&
                                                SwtUtil.is64bitPlatform() == true) {
-                                       /* use JNI for Ubuntu 12.04 64bit */
-                                       int result = copyToClipboard(
-                                                       pngData.width, pngData.height, pngData.data);
-                                       if (result < 0) {
-                                               DND.error(DND.ERROR_CANNOT_SET_CLIPBOARD);
+                                       /* use Python for Ubuntu 64bit */
+                                       FileOutputStream fos = null;
+                                       String fileName = "screenshot" +
+                                                       skin.config.getArgInt(ArgsConstants.VM_BASE_PORT) + ".png";
+
+                                       try {
+                                               fos = new FileOutputStream(fileName, false);
+                                       } catch (FileNotFoundException ee) {
+                                               logger.log(Level.SEVERE, ee.getMessage(), ee);
+                                               SkinUtil.openMessage(shell, null,
+                                                               "Failed to copy to clipboard : \n" + ee.getMessage(),
+                                                               SWT.ICON_ERROR, config);
+                                               return;
+                                       }
+
+                                       loader.save(fos, SWT.IMAGE_PNG);
+                                       IOUtil.close(fos);
+
+                                       ProcessBuilder procPy = new ProcessBuilder();
+                                       procPy.command("python", "clipboard.py", fileName);
+
+                                       logger.info(procPy.command().toString());
+
+                                       try {
+                                               procPy.start();
+                                       } catch (Exception ee) {
+                                               logger.log(Level.SEVERE, ee.getMessage(), ee);
+                                               SkinUtil.openMessage(shell, null,
+                                                               "Failed to copy to clipboard : \n" + ee.getMessage(),
+                                                               SWT.ICON_ERROR, config);
                                        }
                                } else {
+                                       ByteArrayOutputStream bao = new ByteArrayOutputStream();
+                                       loader.save(bao, SWT.IMAGE_PNG);
+
+                                       ImageData pngData = new ImageData(
+                                                       new ByteArrayInputStream(bao.toByteArray()));
+
                                        Object[] imageObject = new Object[] { pngData };
 
                                        Transfer[] transfer = new Transfer[] { ImageTransfer.getInstance() };