Author: jflesch
Date: 2006-08-16 16:58:39 +0000 (Wed, 16 Aug 2006)
New Revision: 10122
Added:
trunk/apps/Thaw/images/edit-clear.png
Modified:
trunk/apps/Thaw/src/thaw/core/IconBox.java
trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java
trunk/apps/Thaw/src/thaw/i18n/thaw.properties
trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
trunk/apps/Thaw/src/thaw/plugins/QueueWatcher.java
trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java
Log:
Add 'clear all finished transfer' function + undo r10119 + fix downloads
deadlock (\o/)
Added: trunk/apps/Thaw/images/edit-clear.png
===================================================================
(Binary files differ)
Property changes on: trunk/apps/Thaw/images/edit-clear.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: trunk/apps/Thaw/src/thaw/core/IconBox.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/IconBox.java 2006-08-16 16:21:34 UTC (rev
10121)
+++ trunk/apps/Thaw/src/thaw/core/IconBox.java 2006-08-16 16:58:39 UTC (rev
10122)
@@ -36,6 +36,8 @@
public static ImageIcon insertAndAddToIndexAction;
+ public static ImageIcon clearAction;
+
public static ImageIcon settings;
public static ImageIcon minSettings;
@@ -90,6 +92,9 @@
minDownloads =
new ImageIcon((new
IconBox()).getClass().getClassLoader().getResource("min-go-first.png"));
+ clearAction =
+ new ImageIcon((new
IconBox()).getClass().getClassLoader().getResource("edit-clear.png"));
+
settings =
new ImageIcon((new
IconBox()).getClass().getClassLoader().getResource("preferences-system.png"));
minSettings =
Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java 2006-08-16 16:21:34 UTC
(rev 10121)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java 2006-08-16 16:58:39 UTC
(rev 10122)
@@ -38,9 +38,11 @@
private long fileSize;
private boolean running = false;
- private boolean successful = false;
+ private boolean successful = true;
private boolean fatal = true;
private boolean isLockOwner = false;
+
+ private boolean alreadySaved = false;
/**
@@ -80,9 +82,15 @@
this.progress = progress;
this.status = status;
+
+ if(status == null) {
+ Logger.warning(this, "status == null ?!");
+ status = "(null)";
+ }
+
this.identifier = id;
- successful = false;
+ successful = true;
running = true;
if(progress < 100) {
@@ -194,31 +202,33 @@
Logger.debug(this, "DataFound!");
if(!isFinished()) {
- status = "Available";
- fileSize = (new
Long(message.getValue("DataLength"))).longValue();
+ if(!alreadySaved) {
+ alreadySaved = true;
+
+ status = "Available";
+ fileSize = (new
Long(message.getValue("DataLength"))).longValue();
+
+ progress = 100;
+ running = false;
+ successful = true;
+
+ if(isPersistent()) {
+ if(destinationDir != null) {
+
+
if(!fileExists(destinationDir)) {
+
saveFileTo(destinationDir);
+ } else
+
Logger.info(this, "File already existing. Not rewrited");
+
+ } else {
+ Logger.info(this,
"Don't know where to put file, so file not asked to the node");
+ }
+ }
- progress = 100;
- successful = true;
-
- if(isPersistent()) {
- if(destinationDir != null) {
-
- if(!fileExists(destinationDir))
-
saveFileTo(destinationDir);
- else
- Logger.info(this, "File
already existing. Not rewrited");
-
- } else {
- Logger.info(this, "Don't know
where to put file, so file not asked to the node");
- }
+
+ setChanged();
+ notifyObservers();
}
-
-
- fromTheNodeProgress = 100;
- progressReliable = true;
-
- setChanged();
- notifyObservers();
}
return;
@@ -252,6 +262,9 @@
successful = false;
fatal = true;
+ setChanged();
+ notifyObservers();
+
if(message.getValue("Fatal") != null &&
message.getValue("Fatal").equals("false")) {
fatal = false;
@@ -266,8 +279,6 @@
queueManager.getQueryManager().deleteObserver(this);
- setChanged();
- notifyObservers();
return;
}
@@ -275,6 +286,8 @@
if(message.getMessageName().equals("GetFailed")) {
Logger.debug(this, "GetFailed !");
+ Logger.warning(this, "==== GET FAILED
===\n"+message.toString());
+
if(!isRunning()) { /* Must be a "GetFailed: cancelled
by caller", so we simply ignore */
Logger.info(this, "Cancellation confirmed.");
return;
@@ -301,6 +314,9 @@
queueManager.getQueryManager().deleteObserver(this);
} else {
status = "Retrying";
+ running = true;
+ successful = true;
+ progress = 0;
start(queueManager);
}
@@ -318,10 +334,10 @@
if(message.getValue("Total") != null
&& message.getValue("Succeeded") != null) {
fileSize = ((new
Long(message.getValue("Total"))).longValue())*BLOCK_SIZE;
- long required = (new
Long(message.getValue("Required"))).longValue();
+ long required = (new
Long(message.getValue("Total"))).longValue();
long succeeded = (new
Long(message.getValue("Succeeded"))).longValue();
- progress = (int)((succeeded * 99) / required);
+ progress = (int) ((long)((succeeded * 98) /
required));
status = "Fetching";
@@ -330,6 +346,9 @@
progressReliable = true;
}
+ successful = true;
+ running = true;
+
setChanged();
notifyObservers();
}
@@ -342,6 +361,9 @@
fileSize = message.getAmountOfDataWaiting();
+ running = true;
+ successful = true;
+ progress = 99;
status = "Writing to disk";
Logger.info(this, "Receiving file ...");
@@ -354,6 +376,8 @@
status = "Available";
} else {
Logger.warning(this, "Unable to fetch correctly
the file. This may create problems on socket");
+ successful = false;
+ status = "Error while receveing the file";
}
Logger.info(this, "File received");
@@ -401,13 +425,19 @@
Logger.warning(this, "UnlockWaiter.run() : Wtf
?");
}
+ try {
+ Thread.sleep((new
java.util.Random()).nextInt(1500));
+ } catch(java.lang.InterruptedException e) {
+
+ }
+
while(true) {
if(!connection.isReadingLocked()
&& (!connection.isWritingLocked()))
break;
try {
- Thread.sleep(200);
+ Thread.sleep(500);
} catch(java.lang.InterruptedException e) {
}
@@ -463,6 +493,8 @@
Logger.info(this, "Waiting socket avaibility ...");
status = "Waiting socket avaibility ...";
+ progress = 99;
+ running = true;
setChanged();
notifyObservers();
@@ -480,7 +512,8 @@
destinationDir = dir;
status = "Requesting file";
-
+ progress = 99;
+ running = true;
setChanged();
notifyObservers();
@@ -541,7 +574,7 @@
long origSize = size;
long startTime = System.currentTimeMillis();
- boolean success = true;
+ boolean writingSuccessful = true;
while(size > 0) {
@@ -559,7 +592,8 @@
if(amount <= -1) {
Logger.error(this, "Socket closed, damn !");
status = "Read error";
- success = false;
+ successful = false;
+ writingSuccessful = false;
break;
}
@@ -569,6 +603,8 @@
} catch(java.io.IOException e) {
Logger.error(this, "Unable to write
file on disk ... out of space ? : "+e.toString());
status = "Write error";
+ writingSuccessful = false;
+ successful = false;
return false;
}
}
@@ -591,13 +627,13 @@
try {
fileWriter.close();
- if(!success)
+ if(!writingSuccessful)
newFile.delete();
} catch(java.io.IOException e) {
Logger.notice(this, "Unable to close correctly
file on disk !? : "+e.toString());
}
- }
+ }
Logger.info(this, "File written");
@@ -644,6 +680,7 @@
removeRequest();
progress = 0;
+ running = false;
successful = false;
status = "Delayed";
@@ -662,6 +699,7 @@
}
progress = 100;
+ running = false;
successful = false;
fatal = true;
status = "Stopped";
@@ -721,6 +759,9 @@
}
public boolean isProgressionReliable() {
+ if(progress == 0 || progress >= 99)
+ return true;
+
return progressReliable;
}
@@ -825,6 +866,7 @@
if(persistence == 2 && !isFinished()) {
progress = 0;
+ running = false;
status = "Waiting";
}
Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2006-08-16 16:21:34 UTC
(rev 10121)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2006-08-16 16:58:39 UTC
(rev 10122)
@@ -43,7 +43,8 @@
thaw.common.no=No
thaw.common.priority=Priority
-thaw.common.removeFromTheList=Remove from the list
+thaw.common.clearFinished=Remove from the list all the finished transfers
+thaw.common.removeFromTheList=Remove from the list selected transfers
thaw.common.cancel=Cancel
thaw.common.delay=Delay
thaw.common.copyKeysToClipboard=Copy keys to clipboard
Modified: trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties 2006-08-16 16:21:34 UTC
(rev 10121)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties 2006-08-16 16:58:39 UTC
(rev 10122)
@@ -43,7 +43,8 @@
thaw.common.no=Non
thaw.common.priority=Priorit?
-thaw.common.removeFromTheList=Enlever de la liste
+thaw.common.clearFinished=Enlever de la liste tout les transferts finis
+thaw.common.removeFromTheList=Enlever de la liste les transferts s?lectionn?s
thaw.common.cancel=Annuler
thaw.common.delay=D?lai
thaw.common.copyKeysToClipboard=Copier les cl?s vers le presse papiers
Modified: trunk/apps/Thaw/src/thaw/plugins/QueueWatcher.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/QueueWatcher.java 2006-08-16 16:21:34 UTC
(rev 10121)
+++ trunk/apps/Thaw/src/thaw/plugins/QueueWatcher.java 2006-08-16 16:58:39 UTC
(rev 10122)
@@ -51,8 +51,8 @@
detailPanel = new DetailPanel(core);
- queuePanels[0] = new QueuePanel(core, detailPanel,
core.getQueueManager(), false); /* download */
- queuePanels[1] = new QueuePanel(core, detailPanel,
core.getQueueManager(), true); /* upload */
+ queuePanels[0] = new QueuePanel(core, detailPanel, false); /*
download */
+ queuePanels[1] = new QueuePanel(core, detailPanel, true); /*
upload */
panel = new JPanel();
Modified: trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java
2006-08-16 16:21:34 UTC (rev 10121)
+++ trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java
2006-08-16 16:58:39 UTC (rev 10122)
@@ -55,6 +55,7 @@
private DetailPanel detailPanel;
private JPopupMenu rightClickMenu;
+ private JMenuItem clearFinishedItem;
private JMenuItem removeItem;
private JMenuItem cancelItem;
private JMenuItem delayItem;
@@ -72,13 +73,15 @@
private boolean insertionQueue = false;
- public QueuePanel(Core core, DetailPanel detailPanel, FCPQueueManager
queueManager, boolean isForInsertionQueue) {
+ public QueuePanel(Core core, DetailPanel detailPanel,
+ boolean isForInsertionQueue) {
+
insertionQueue = isForInsertionQueue;
this.core = core;
this.detailPanel = detailPanel;
- tableModel = new QueueTableModel(isForInsertionQueue,
queueManager);
+ tableModel = new QueueTableModel(isForInsertionQueue,
core.getQueueManager());
table = new JTable(tableModel);
@@ -111,6 +114,7 @@
tableModel.addTableModelListener(table);
rightClickMenu = new JPopupMenu();
+ clearFinishedItem = new
JMenuItem(I18n.getMessage("thaw.common.clearFinished"));
removeItem = new
JMenuItem(I18n.getMessage("thaw.common.removeFromTheList"));
cancelItem = new
JMenuItem(I18n.getMessage("thaw.common.cancel"));
delayItem = new JMenuItem(I18n.getMessage("thaw.common.delay"));
@@ -130,7 +134,7 @@
unknowPriority = new JRadioButtonMenuItem("Coin");
priorityGroup.add(unknowPriority);
-
+ rightClickMenu.add(clearFinishedItem);
rightClickMenu.add(removeItem);
if(
Integer.parseInt(core.getConfig().getValue("maxSimultaneousDownloads")) >= 0
@@ -151,6 +155,7 @@
rightClickMenu.add(priorityMenu);
}
+ clearFinishedItem.addActionListener(this);
removeItem.addActionListener(this);
cancelItem.addActionListener(this);
copyKeysItem.addActionListener(this);
@@ -213,8 +218,7 @@
String toAdd = "%";
- if(!query.isProgressionReliable()
- && query.getProgression() != 0)
+ if(!query.isProgressionReliable())
toAdd = toAdd + " [*]";
bar.setString(progress.toString() +
toAdd);
@@ -354,6 +358,11 @@
String keys = "";
File dir = null;
+ if(e.getSource() == clearFinishedItem) {
+ removeAllFinishedTransfers();
+ return;
+ }
+
if(e.getSource() == downloadItem) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle(I18n.getMessage("thaw.common.downloadLocally"));
@@ -452,6 +461,20 @@
}
+ public void removeAllFinishedTransfers() {
+ Vector queries = tableModel.getQueries();
+
+ for(Iterator it = queries.iterator();
+ it.hasNext(); ) {
+ FCPTransferQuery query = (FCPTransferQuery)it.next();
+ if(query.isFinished()) {
+ if(query.stop(core.getQueueManager())) {
+ core.getQueueManager().remove(query);
+ }
+ }
+ }
+ }
+
/**
* Manage it on a different thread to avoid UI freeze.
*/