[Title] fix a bug where transfer dialog of connection explorer show wrong information...
authorshingil.kang <shingil.kang@samsung.com>
Tue, 11 Jun 2013 03:12:38 +0000 (12:12 +0900)
committershingil.kang <shingil.kang@samsung.com>
Tue, 11 Jun 2013 03:30:06 +0000 (12:30 +0900)
[Desc.]
[Issue]

Change-Id: Ifbe15d1ab2a721037e2242949b534e88308a23f1

org.tizen.common.connection/src/org/tizen/common/connection/ui/SyncProgressMonitor.java
org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncService.java
org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncServiceConstants.java

index 9913ef0..59cad6c 100644 (file)
@@ -1,19 +1,28 @@
 /*
- * Copyright (C) 2009 The Android Open Source Project
+ *  Common
+ *
+ * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Kangho Kim <kh5325.kim@samsung.com>
+ * Shingil kang <shingil.kang@samsung.com>
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- *      http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
  */
-
 package org.tizen.common.connection.ui;
 
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -26,9 +35,7 @@ import org.tizen.sdblib.service.ISyncProgressMonitor;
  * Implementation of the {@link ISyncProgressMonitor} wrapping an Eclipse
  * {@link IProgressMonitor}.
  */
-public class
-SyncProgressMonitor
-implements ISyncProgressMonitor
+public class SyncProgressMonitor implements ISyncProgressMonitor
 {
 
     protected static String[] UNITS = new String[] { "B", "KB", "MB", "GB" };
@@ -41,39 +48,30 @@ implements ISyncProgressMonitor
     private String labelFrom = "From: ";
     private String labelTo = "To: ";
     private String labelSize = "Size: ";
-    
+
     protected long totalWork;
-    
+
     protected long worked;
-    
+
     protected int estimated;
-    
+
     protected int rate;
 
-    protected static
-    String
-    getSizeAndUnit(
-       final long size
-    )
+    protected static String getSizeAndUnit(final long size)
     {
         int index = 0;
         double value = size;
-        
-        while ( index < UNITS.length - 1 && value >= 1000 )
+
+        while (index < UNITS.length - 1 && value >= 1000)
         {
-               value /= 1000.00;
-               ++index;
+            value /= 1000.00;
+            ++index;
         }
-        
-        return String.format( FORMATS[index], value, UNITS[index] );
+
+        return String.format(FORMATS[index], value, UNITS[index]);
     }
 
-    public
-    SyncProgressMonitor(
-       final TransferProgressMonitorDialog tmd,
-       final IProgressMonitor monitor,
-       final String name
-    )
+    public SyncProgressMonitor(final TransferProgressMonitorDialog tmd, final IProgressMonitor monitor, final String name)
     {
         this.dialog = tmd;
         this.monitor = monitor;
@@ -82,16 +80,17 @@ implements ISyncProgressMonitor
 
     public void start(long totalWork)
     {
-       this.totalWork = totalWork;
-       this.rate = 1;
-       this.estimated = 0;
-        while( totalWork > Integer.MAX_VALUE )
+        this.totalWork = totalWork;
+        this.rate = 1;
+        this.estimated = 0;
+
+        while (totalWork > Integer.MAX_VALUE)
         {
             totalWork /= 10;
             this.rate *= 10;
         }
-        monitor.beginTask(name, (int) (totalWork / this.rate) );
-       apply();
+        monitor.beginTask(name, (int) (totalWork));
+        apply();
     }
 
     public void stop()
@@ -99,13 +98,11 @@ implements ISyncProgressMonitor
         monitor.done();
     }
 
-    public void advance( long work )
+    public void advance(long work)
     {
-       worked += work;
-       int difference = (int) (estimated - ( worked / this.rate ));
-       estimated += difference;
-        monitor.worked( difference );
-       apply();
+        worked += work;
+        monitor.worked((int) work / rate);
+        apply();
     }
 
     public boolean isCanceled()
@@ -113,12 +110,12 @@ implements ISyncProgressMonitor
         return monitor.isCanceled();
     }
 
-    public void startSubTask( String name )
+    public void startSubTask(String name)
     {
-       this.name = name;
-       apply();
+        this.name = name;
+        apply();
     }
-    
+
     protected void apply()
     {
         final Label fromLabel = dialog.getFromLabel();
@@ -135,7 +132,7 @@ implements ISyncProgressMonitor
         final String sizeStr;
 
         String[] subTasks = name.split("\t");
-        if (name == null || subTasks.length != 3)
+        if (name == null || subTasks.length != 2)
         {
             fromStr = subTasks[0];
             toStr = "";
@@ -145,10 +142,10 @@ implements ISyncProgressMonitor
         {
             fromStr = labelFrom + subTasks[0];
             toStr = labelTo + subTasks[1];
-            sizeStr = labelSize + String.format( "( %s / %s )", getSizeAndUnit( getWorked() ), getSizeAndUnit( getTotal() ) );
+            sizeStr = labelSize + String.format("( %s / %s )", getSizeAndUnit(getWorked()), getSizeAndUnit(getTotal()));
         }
 
-        SWTUtil.asyncExec(new Runnable()
+        SWTUtil.syncExec(new Runnable()
         {
             @Override
             public void run()
@@ -160,15 +157,15 @@ implements ISyncProgressMonitor
         });
     }
 
-       @Override
+    @Override
     public long getTotal()
     {
-           return totalWork;
+        return totalWork;
     }
 
-       @Override
+    @Override
     public long getWorked()
     {
-           return worked;
+        return worked;
     }
 }
index 755fda5..5983242 100644 (file)
@@ -26,6 +26,8 @@
 package org.tizen.sdblib.service;
 
 import static org.tizen.sdblib.service.SyncServiceConstants.MESSAGE_SIZECHECKING;
+import static org.tizen.sdblib.service.SyncServiceConstants.MESSAGE_PULL_FILES;
+import static org.tizen.sdblib.service.SyncServiceConstants.MESSAGE_PUSH_FILES;
 import static org.tizen.sdblib.service.SyncServiceConstants.RESULT_CANCELED;
 import static org.tizen.sdblib.service.SyncServiceConstants.RESULT_CONNECTION_ERROR;
 import static org.tizen.sdblib.service.SyncServiceConstants.RESULT_FILE_READ_ERROR;
@@ -202,58 +204,77 @@ implements Closeable
         monitor.start( -1 );
         monitor.startSubTask( MESSAGE_SIZECHECKING );
 
+        SyncResult result;
+
         // compute the number of file to move
         try {
                long total = getTotalSize(entries, monitor);
+               monitor.startSubTask( MESSAGE_PULL_FILES );
                monitor.stop();
 
             // start the monitor
             monitor.start(total);
+            result= doPull(entries, localPath, monitor, timeOut);
+        }
+        catch ( final InterruptedException e )
+        {
+            return new SyncResult( RESULT_CANCELED );
+        }
+        finally
+        {
+            monitor.stop();
+        }
+
+        return result;
+    }
 
+    public SyncResult
+    doPull(
+        final FileEntry[] entries,
+        final String localPath,
+        ISyncProgressMonitor monitor,
+        final int timeOut
+    )
+    {
+        monitor = nvl( monitor, NullSyncProgressMonitor.getInstance() );
+
+        try {
             for ( final FileEntry entry : entries )
             {
-               final String path = addTailingPath( localPath, entry.getName() );
-               if ( entry.isDirectory() )
-               {
-                       new File( path ).mkdir();
+                final String path = addTailingPath( localPath, entry.getName() );
+                if ( entry.isDirectory() )
+                {
+                    new File( path ).mkdir();
 
                     FileEntry[] children = entry.getChildren();
-                    pull(children, path, monitor, timeOut);
-               }
-               else
-               {
+                    doPull(children, path, monitor, timeOut);
+                }
+                else
+                {
                     monitor.startSubTask( String.format("%s\t%s", entry.getFullPath(), path ) );
 
-                       FileOutputStream fileOut = null;
-                       try
-                       {
-                               fileOut = new FileOutputStream( path );
-                               SyncResult result = doPull( entry, fileOut, monitor, timeOut );
-                               if ( RESULT_OK != result.getCode() )
-                               {
-                                       return result;
-                               }
-                       }
-                       finally
-                       {
-                               tryClose( fileOut );
-                       }
-               }
+                    FileOutputStream fileOut = null;
+                    try
+                    {
+                        fileOut = new FileOutputStream( path );
+                        SyncResult result = doPull( entry, fileOut, monitor, timeOut );
+                        if ( RESULT_OK != result.getCode() )
+                        {
+                            return result;
+                        }
+                    }
+                    finally
+                    {
+                        tryClose( fileOut );
+                    }
+                }
             }
 
             return new SyncResult( RESULT_OK );
         }
-        catch ( final InterruptedException e )
-        {
-            return new SyncResult( RESULT_CANCELED );
-        }
-        catch ( final IOException e ) 
-        {
-               return new SyncResult( RESULT_CONNECTION_ERROR, e );
-        }
-        finally
+        catch ( final IOException e )
         {
-            monitor.stop();
+            return new SyncResult( RESULT_CONNECTION_ERROR, e );
         }
     }
     
@@ -297,7 +318,7 @@ implements Closeable
 
                        // write the content in the file
                        out.write( data, 0, nBytes );
-                       monitor.advance( nBytes );
+                monitor.advance( nBytes );
                }
 
                return new SyncResult( RESULT_OK );
@@ -436,10 +457,11 @@ implements Closeable
         try {
                // get the total count of the bytes to transfer
                long total = getTotalLocalFileSizeLong( locals, monitor );
+            monitor.startSubTask( MESSAGE_PUSH_FILES );
                monitor.stop();
-               
+
             monitor.start( total );
-            
+
             final String remotePath = remote.getFullPath();
             
             
index a0c4185..cbb45dd 100644 (file)
@@ -32,6 +32,8 @@ import org.tizen.sdblib.util.MapUtil;
 public class SyncServiceConstants\r
 {\r
     static final String MESSAGE_SIZECHECKING = "File size checking: it can take some time.";\r
+    static final String MESSAGE_PULL_FILES = "Pulling file(s) from the device";\r
+    static final String MESSAGE_PUSH_FILES = "Pushing file(s) to the device";\r
 \r
     /** Result code for transfer success. */\r
     public static final int RESULT_OK = 0;\r