From jflesch at freenetproject.org Sun Oct 1 13:57:42 2006 From: jflesch at freenetproject.org (jflesch at freenetproject.org) Date: Sun, 1 Oct 2006 13:57:42 +0000 (UTC) Subject: [Thaw-dev] r10586 - in trunk/apps/Thaw/src/thaw: core fcp i18n plugins/index Message-ID: <20061001135742.2852B9BE17@emu.freenetproject.org> Author: jflesch Date: 2006-10-01 13:57:36 +0000 (Sun, 01 Oct 2006) New Revision: 10586 Modified: trunk/apps/Thaw/src/thaw/core/Config.java trunk/apps/Thaw/src/thaw/core/Core.java trunk/apps/Thaw/src/thaw/core/NodeConfigPanel.java trunk/apps/Thaw/src/thaw/core/PluginManager.java trunk/apps/Thaw/src/thaw/core/ThawConfigPanel.java trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java trunk/apps/Thaw/src/thaw/fcp/FCPQueryManager.java trunk/apps/Thaw/src/thaw/i18n/thaw.properties trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java trunk/apps/Thaw/src/thaw/plugins/index/Index.java trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java trunk/apps/Thaw/src/thaw/plugins/index/Link.java trunk/apps/Thaw/src/thaw/plugins/index/TableCreator.java Log: Create separate sockets to transfer files (if global == true) Modified: trunk/apps/Thaw/src/thaw/core/Config.java =================================================================== --- trunk/apps/Thaw/src/thaw/core/Config.java 2006-09-30 02:46:55 UTC (rev 10585) +++ trunk/apps/Thaw/src/thaw/core/Config.java 2006-10-01 13:57:36 UTC (rev 10586) @@ -27,7 +27,7 @@ /** * This class the thaw config. * - * @author Jerome Flesch + * @author Jerome Flesch */ public class Config { @@ -291,15 +291,24 @@ return false; } + /** + * Set the value only if it doesn't exits. + */ + public void setDefaultValue(String name, String val) { + if (getValue(name) == null) + setValue(name, val); + } public void setDefaultValues() { - setValue("nodeAddress", "127.0.0.1"); - setValue("nodePort", "9481"); - setValue("maxSimultaneousDownloads", "-1"); - setValue("maxSimultaneousInsertions", "-1"); - setValue("maxUploadSpeed", "-1"); - setValue("thawId", "thaw_"+Integer.toString((new Random()).nextInt(1000))); - setValue("advancedMode", "false"); + setDefaultValue("nodeAddress", "127.0.0.1"); + setDefaultValue("nodePort", "9481"); + setDefaultValue("maxSimultaneousDownloads", "-1"); + setDefaultValue("maxSimultaneousInsertions", "-1"); + setDefaultValue("maxUploadSpeed", "-1"); + setDefaultValue("thawId", "thaw_"+Integer.toString((new Random()).nextInt(1000))); + setDefaultValue("advancedMode", "false"); + setDefaultValue("userNickname", "Another anonymous"); + setDefaultValue("multipleSockets", "true"); } } Modified: trunk/apps/Thaw/src/thaw/core/Core.java =================================================================== --- trunk/apps/Thaw/src/thaw/core/Core.java 2006-09-30 02:46:55 UTC (rev 10585) +++ trunk/apps/Thaw/src/thaw/core/Core.java 2006-10-01 13:57:36 UTC (rev 10586) @@ -34,7 +34,7 @@ private static String lookAndFeel = null; public final static int MAX_CONNECT_TRIES = 3; - public final static int TIME_BETWEEN_EACH_TRY = 2500; + public final static int TIME_BETWEEN_EACH_TRY = 3000; /** @@ -131,8 +131,7 @@ config = new Config(); config.loadConfig(); - if(config.isEmpty()) - config.setDefaultValues(); + config.setDefaultValues(); return true; } @@ -159,7 +158,8 @@ if(connection == null) { connection = new FCPConnection(config.getValue("nodeAddress"), Integer.parseInt(config.getValue("nodePort")), - Integer.parseInt(config.getValue("maxUploadSpeed"))); + Integer.parseInt(config.getValue("maxUploadSpeed")), + Boolean.valueOf(config.getValue("multipleSockets")).booleanValue()); } else { connection.setNodeAddress(config.getValue("nodeAddress")); connection.setNodePort(Integer.parseInt(config.getValue("nodePort"))); Modified: trunk/apps/Thaw/src/thaw/core/NodeConfigPanel.java =================================================================== --- trunk/apps/Thaw/src/thaw/core/NodeConfigPanel.java 2006-09-30 02:46:55 UTC (rev 10585) +++ trunk/apps/Thaw/src/thaw/core/NodeConfigPanel.java 2006-10-01 13:57:36 UTC (rev 10586) @@ -8,6 +8,7 @@ import java.awt.event.ActionListener; import javax.swing.JTextField; import javax.swing.JLabel; +import javax.swing.JCheckBox; import java.util.Observer; import java.util.Observable; @@ -42,6 +43,7 @@ private JLabel[] paramLabels = new JLabel[paramNames.length]; private JTextField[] paramFields = new JTextField[configNames.length]; + private JCheckBox multipleSockets = null; public NodeConfigPanel(ConfigWindow configWindow, Core core) { @@ -63,6 +65,11 @@ nodeConfigPanel.add(paramFields[i]); } + multipleSockets = new JCheckBox(I18n.getMessage("thaw.config.multipleSockets"), + Boolean.valueOf(core.getConfig().getValue("multipleSockets")).booleanValue()); + nodeConfigPanel.add(new JLabel(" ")); + nodeConfigPanel.add(multipleSockets); + setVisibility(Boolean.valueOf(core.getConfig().getValue("advancedMode")).booleanValue()); configWindow.addObserver(this); @@ -78,6 +85,7 @@ paramFields[i].setVisible(advancedMode); } + multipleSockets.setVisible(advancedMode); } @@ -87,6 +95,8 @@ core.getConfig().setValue(configNames[i], paramFields[i].getText()); } + core.getConfig().setValue("multipleSockets", Boolean.toString(multipleSockets.isSelected())); + setVisibility(Boolean.valueOf(core.getConfig().getValue("advancedMode")).booleanValue()); } @@ -100,6 +110,8 @@ paramFields[i].setText(value); } + + multipleSockets.setSelected(Boolean.valueOf(core.getConfig().getValue("multipleSockets")).booleanValue()); } } Modified: trunk/apps/Thaw/src/thaw/core/PluginManager.java =================================================================== --- trunk/apps/Thaw/src/thaw/core/PluginManager.java 2006-09-30 02:46:55 UTC (rev 10585) +++ trunk/apps/Thaw/src/thaw/core/PluginManager.java 2006-10-01 13:57:36 UTC (rev 10586) @@ -11,9 +11,9 @@ private final static String[] defaultPlugins = {"thaw.plugins.QueueWatcher", "thaw.plugins.InsertPlugin", "thaw.plugins.FetchPlugin", - "thaw.plugins.StatusBar", - "thaw.plugins.IndexEditor", - "thaw.plugins.IndexBrowser"}; + "thaw.plugins.StatusBar"}; + //"thaw.plugins.IndexEditor", + //"thaw.plugins.IndexBrowser"}; private Core core = null; Modified: trunk/apps/Thaw/src/thaw/core/ThawConfigPanel.java =================================================================== --- trunk/apps/Thaw/src/thaw/core/ThawConfigPanel.java 2006-09-30 02:46:55 UTC (rev 10585) +++ trunk/apps/Thaw/src/thaw/core/ThawConfigPanel.java 2006-10-01 13:57:36 UTC (rev 10586) @@ -7,6 +7,8 @@ import java.awt.event.WindowEvent; import java.awt.event.ActionListener; import javax.swing.JCheckBox; +import javax.swing.JLabel; +import javax.swing.JTextField; import java.util.Observer; import java.util.Observable; @@ -20,8 +22,12 @@ private JCheckBox advancedModeBox = null; + private JLabel nicknameLabel = null; + private JTextField nicknameField = null; + private boolean advancedMode; + public ThawConfigPanel(ConfigWindow configWindow, Core core) { this.core = core; @@ -36,7 +42,17 @@ advancedModeBox = new JCheckBox(I18n.getMessage("thaw.config.advancedMode"), advancedMode); + nicknameLabel = new JLabel(I18n.getMessage("thaw.config.nickname")); + + if (core.getConfig().getValue("userNickname") == null) + nicknameField = new JTextField("Another anonymous"); + else + nicknameField = new JTextField(core.getConfig().getValue("userNickname")); + thawConfigPanel.add(advancedModeBox); + thawConfigPanel.add(new JLabel(" ")); + thawConfigPanel.add(nicknameLabel); + thawConfigPanel.add(nicknameField); configWindow.addObserver(this); } @@ -51,10 +67,12 @@ if(arg == core.getConfigWindow().getOkButton()) { advancedMode = advancedModeBox.isSelected(); core.getConfig().setValue("advancedMode", Boolean.toString(advancedMode)); + core.getConfig().setValue("userNickname", nicknameField.getText()); } if(arg == core.getConfigWindow().getCancelButton()) { advancedModeBox.setSelected(advancedMode); + nicknameField.setText(core.getConfig().getValue("userNickname")); } } Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java =================================================================== --- trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java 2006-09-30 02:46:55 UTC (rev 10585) +++ trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java 2006-10-01 13:57:36 UTC (rev 10586) @@ -19,6 +19,7 @@ private final static int BLOCK_SIZE = 32768; private FCPQueueManager queueManager; + private FCPQueryManager duplicatedQueryManager; private String key = null; private String filename = null; /* Extract from the key */ @@ -136,11 +137,11 @@ } else { String cutcut[] = key.split("/"); - if(!key.startsWith("USK@")) { - filename = cutcut[cutcut.length-1]; - } else { - filename = cutcut[cutcut.length-2]; - } + //if(!key.startsWith("USK@")) { + filename = cutcut[cutcut.length-1]; + //} else { + //filename = cutcut[cutcut.length-2]; + //} } Logger.debug(this, "Query for getting "+key+" created"); @@ -197,8 +198,15 @@ public void update(Observable o, Object arg) { + + FCPQueryManager queryManager = null; FCPMessage message = (FCPMessage)arg; + if (o instanceof FCPQueryManager) + queryManager = (FCPQueryManager)o; + else + queryManager = queueManager.getQueryManager(); /* default one */ + if(message.getValue("Identifier") == null || !message.getValue("Identifier").equals(identifier)) return; @@ -291,6 +299,14 @@ if(message.getMessageName().equals("GetFailed")) { Logger.debug(this, "GetFailed !"); + if (message.getValue("RedirectURI") != null) { + Logger.debug(this, "Redirected !"); + key = message.getValue("RedirectURI"); + status = "Redirected ..."; + start(queueManager); + return; + } + Logger.warning(this, "==== GET FAILED ===\n"+message.toString()); if(!isRunning()) { /* Must be a "GetFailed: cancelled by caller", so we simply ignore */ @@ -376,7 +392,7 @@ notifyObservers(); - if(fetchDirectly(getPath(), fileSize, true)) { + if(fetchDirectly(queryManager.getConnection(), getPath(), fileSize, true)) { successful = true; status = "Available"; } else { @@ -387,15 +403,23 @@ Logger.info(this, "File received"); - queueManager.getQueryManager().getConnection().unlockReading(); - queueManager.getQueryManager().getConnection().unlockWriting(); + queryManager.getConnection().unlockReading(); + queryManager.getConnection().unlockWriting(); + + isLockOwner= false; running = false; progress = 100; - queueManager.getQueryManager().deleteObserver(this); + queryManager.deleteObserver(this); + if (queryManager != queueManager.getQueryManager()) { + queueManager.getQueryManager().deleteObserver(this); + queryManager.getConnection().disconnect(); + duplicatedQueryManager = null; + } + setChanged(); notifyObservers(); @@ -495,9 +519,15 @@ return false; } + if (globalQueue) { /* If not global, we need to remain on the same socket */ + duplicatedQueryManager = queueManager.getQueryManager().duplicate(identifier); + duplicatedQueryManager.addObserver(this); + } else + duplicatedQueryManager = queueManager.getQueryManager(); - Logger.info(this, "Waiting socket avaibility ..."); - status = "Waiting socket avaibility ..."; + + Logger.info(this, "Waiting for socket avaibility ..."); + status = "Waiting for socket avaibility ..."; progress = 99; running = true; @@ -505,7 +535,7 @@ notifyObservers(); - Thread fork = new Thread(new UnlockWaiter(this, queueManager.getQueryManager().getConnection(), dir)); + Thread fork = new Thread(new UnlockWaiter(this, duplicatedQueryManager.getConnection(), dir)); fork.start(); return true; @@ -538,7 +568,7 @@ - queueManager.getQueryManager().writeMessage(getRequestStatus, false); + duplicatedQueryManager.writeMessage(getRequestStatus, false); return true; } @@ -552,15 +582,11 @@ - private boolean fetchDirectly(String file, long size, boolean reallyWrite) { - FCPConnection connection; - + private boolean fetchDirectly(FCPConnection connection, String file, long size, boolean reallyWrite) { File newFile = new File(file); FileOutputStream fileWriter = null; - connection = queueManager.getQueryManager().getConnection(); - if(reallyWrite) { Logger.info(this, "Writing file to disk ..."); Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java =================================================================== --- trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java 2006-09-30 02:46:55 UTC (rev 10585) +++ trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java 2006-10-01 13:57:36 UTC (rev 10586) @@ -76,7 +76,7 @@ } /** - * To start anew insertion. + * To start a new insertion. */ public FCPClientPut(File file, int keyType, int rev, String name, @@ -613,6 +613,9 @@ fatal = false; } + Logger.warning(this, "==== PUT FAILED ==="); + Logger.warning(this, msg.toString()); + setChanged(); notifyObservers(); return; Modified: trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java =================================================================== --- trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java 2006-09-30 02:46:55 UTC (rev 10585) +++ trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java 2006-10-01 13:57:36 UTC (rev 10586) @@ -3,7 +3,6 @@ import java.net.Socket; import java.io.InputStream; import java.io.OutputStream; -/* import java.io.BufferedReader; */ import java.io.BufferedInputStream; import java.util.Observable; @@ -49,22 +48,29 @@ private long lastWrite = 0; /* real writes ; System.currentTimeMillis() */ + private boolean duplicationAllowed = true; + /** * Don't connect. Call connect() for that. * @param maxUploadSpeed in KB: -1 means no limit + * @param duplicationAllowed FCPClientGet and FCPClientPut will be allowed to open a separate socket to transfer the files */ public FCPConnection(String nodeAddress, int port, - int maxUploadSpeed) + int maxUploadSpeed, + boolean duplicationAllowed) { if(DEBUG_MODE) { Logger.notice(this, "DEBUG_MODE ACTIVATED"); } + maxUploadSpeed = -1; + setNodeAddress(nodeAddress); setNodePort(port); setMaxUploadSpeed(maxUploadSpeed); + setDuplicationAllowed(duplicationAllowed); } @@ -80,6 +86,9 @@ this.maxUploadSpeed = max; } + public void setDuplicationAllowed(boolean allowed) { + this.duplicationAllowed = allowed; + } public void disconnect() { try { @@ -89,7 +98,7 @@ Logger.info(this, "Disconnect(): Already disconnected."); } } catch(java.io.IOException e) { - Logger.warning(this, "Unable to close cleanly the connection : "+e.toString()); + Logger.warning(this, "Unable to close cleanly the connection : "+e.toString() +" ; "+e.getMessage()); } socket = null; @@ -130,7 +139,7 @@ return false; } catch(java.io.IOException e) { Logger.error(this, "Error while trying to connect to "+nodeAddress+":"+port+" : "+ - e.toString()); + e.toString() + " ; "+e.getMessage()); socket = null; return false; } @@ -144,7 +153,7 @@ in = socket.getInputStream(); out = socket.getOutputStream(); } catch(java.io.IOException e) { - Logger.error(this, "Socket and connection established, but unable to get in/output streams ?! : "+e.toString()); + Logger.error(this, "Socket and connection established, but unable to get in/output streams ?! : "+e.toString()+ " ; "+e.getMessage() ); return false; } @@ -252,7 +261,7 @@ out.write(data); } catch(java.io.IOException e) { - Logger.warning(this, "Unable to write() on the socket ?! : "+ e.toString()); + Logger.warning(this, "Unable to write() on the socket ?! : "+ e.toString()+ " ; "+e.getMessage()); disconnect(); return false; } @@ -344,7 +353,7 @@ return rdBytes; } catch(java.io.IOException e) { Logger.error(this, "IOException while reading raw bytes on socket => disconnection"); - Logger.error(this, e.getMessage() + ":" +e.getCause()); + Logger.error(this, e.getMessage() + ":" +e.getCause().toString()+ " ; "+e.getMessage() ); disconnect(); return -2; /* -1 can mean eof */ } @@ -429,9 +438,9 @@ } catch (java.io.IOException e) { if(isConnected()) - Logger.error(this, "IOException while reading but still connected, wtf? : "+e.toString()); + Logger.error(this, "IOException while reading but still connected, wtf? : "+e.toString()+ " ; "+e.getMessage() ); else - Logger.notice(this, "IOException. Disconnected."); + Logger.notice(this, "IOException. Disconnected. : "+e.toString() + " ; "+e.getMessage()); disconnect(); @@ -444,4 +453,28 @@ return null; } + + /** + * If duplicationAllowed, returns a copy of this object, using a different socket and differents lock / buffer. + * If !duplicationAllowed, returns this object. + * The duplicate socket is just connected but not initialized (ClientHello, etc). + */ + public FCPConnection duplicate() { + if (!duplicationAllowed) + return this; + + Logger.info(this, "Duplicating connection to the node ..."); + + FCPConnection newConnection; + + newConnection = new FCPConnection(nodeAddress, port, -1, duplicationAllowed); /* upload limit is useless here, since we can't do a global limit on all the connections */ + + if (!newConnection.connect()) { + Logger.warning(this, "Unable to duplicate socket !"); + return this; + } + + return newConnection; + } + } Modified: trunk/apps/Thaw/src/thaw/fcp/FCPQueryManager.java =================================================================== --- trunk/apps/Thaw/src/thaw/fcp/FCPQueryManager.java 2006-09-30 02:46:55 UTC (rev 10585) +++ trunk/apps/Thaw/src/thaw/fcp/FCPQueryManager.java 2006-10-01 13:57:36 UTC (rev 10586) @@ -135,5 +135,36 @@ } } + + /** + * This function is mainly used by FCPClientGet to have a separate socket to transfer the files. + * If FCPConnection is allowed to duplicate itself, then it will duplicate it and create a dedicated FCPQueryManager for. + * A FCPClientHello is sent with the given id. + * @return This object if it cannot duplicate FCPConnection + */ + public FCPQueryManager duplicate(String connectionId) { + FCPConnection newConnection; + FCPQueryManager queryManager; + + newConnection = connection.duplicate(); + + if (newConnection == connection) + return this; + + queryManager = new FCPQueryManager(newConnection); + + queryManager.startListening(); + + FCPClientHello clientHello = new FCPClientHello(queryManager, connectionId); + + if (!clientHello.start(null)) { + Logger.warning(this, "ID already used ?! Using initial socket ..."); + newConnection.disconnect(); + return this; + } + + return queryManager; + } + } Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties =================================================================== --- trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2006-09-30 02:46:55 UTC (rev 10585) +++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2006-10-01 13:57:36 UTC (rev 10586) @@ -102,7 +102,10 @@ thaw.config.advancedMode=Advanced mode +thaw.config.nickname=Your nickname +thaw.config.multipleSockets=Allow Thaw to exchange many files at ones with the node + ## Plugins thaw.plugin.insert.fileToInsert=File to insert thaw.plugin.insert.filesToInsert=File(s) to insert Modified: trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties =================================================================== --- trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties 2006-09-30 02:46:55 UTC (rev 10585) +++ trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties 2006-10-01 13:57:36 UTC (rev 10586) @@ -193,8 +193,8 @@ thaw.plugin.index.yourIndexes=Vos indexes thaw.plugin.index.indexes=Indexes -thaw.plugin.index.addIndex=Add a file index -thaw.plugin.index.createIndex=Cr?er a file index +thaw.plugin.index.addIndex=Ajouter un index de fichiers +thaw.plugin.index.createIndex=Cr?er un index de fichiers thaw.plugin.index.addCategory=Ajouter un r?pertoire thaw.plugin.index.rename=Renommer thaw.plugin.index.delete=Effacer Modified: trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java 2006-09-30 02:46:55 UTC (rev 10585) +++ trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java 2006-10-01 13:57:36 UTC (rev 10586) @@ -223,7 +223,7 @@ FCPClientPut insertion = new FCPClientPut(new java.io.File(file.getLocalPath()), 0, 0, null, null, 4, - true, 2, false); /* getCHKOnly */ + true, 2, true); /* getCHKOnly */ insertion.start(queueManager); file.setTransfer(insertion); Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2006-09-30 02:46:55 UTC (rev 10585) +++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2006-10-01 13:57:36 UTC (rev 10586) @@ -33,7 +33,7 @@ import thaw.plugins.Hsqldb; import thaw.core.*; -public class Index extends java.util.Observable implements FileList, IndexTreeNode, java.util.Observer { +public class Index extends java.util.Observable implements FileList, LinkList, IndexTreeNode, java.util.Observer { private Hsqldb db; private IndexTree tree; @@ -50,6 +50,7 @@ private int revision = 0; private Vector fileList; + private Vector linkList; private DefaultMutableTreeNode treeNode; @@ -60,11 +61,14 @@ private FCPTransferQuery transfer = null; private java.io.File targetFile = null; + private String author = null; + + public Index(Hsqldb db, FCPQueueManager queueManager, int id, IndexCategory parent, String realName, String displayName, String publicKey, String privateKey, - int revision, + int revision, String author, boolean modifiable) { this.queueManager = queueManager; @@ -85,6 +89,8 @@ this.revision = revision; + this.author = author; + treeNode.setUserObject(this); } @@ -120,21 +126,21 @@ id = 1; } - st = c.prepareStatement("INSERT INTO indexes (id, originalName, displayName, publicKey, privateKey, positionInTree, revision, parent) "+ - "VALUES (?, ?,?,?,?,?,?, ?)"); + st = c.prepareStatement("INSERT INTO indexes (id, originalName, displayName, publicKey, privateKey, author, positionInTree, revision, parent) VALUES (?, ?,?,?,?,?, ?,?, ?)"); st.setInt(1, id); st.setString(2, realName); st.setString(3, displayName); st.setString(4, publicKey); st.setString(5, privateKey); - st.setInt(6, 0); + st.setString(6, author); + st.setInt(7, 0); - st.setInt(7, revision); + st.setInt(8, revision); if(parent.getId() >= 0) - st.setInt(8, parent.getId()); + st.setInt(9, parent.getId()); else - st.setNull(8, Types.INTEGER); + st.setNull(9, Types.INTEGER); st.execute(); @@ -178,16 +184,18 @@ public void delete() { try { loadFiles(null, false); + loadLinks(null, false); - for(Iterator fileIt = fileList.iterator(); - fileIt.hasNext(); ) { + for(Iterator fileIt = fileList.iterator(); fileIt.hasNext(); ) { thaw.plugins.index.File file = (thaw.plugins.index.File)fileIt.next(); file.delete(); } + for (Iterator linkIt = linkList.iterator(); linkIt.hasNext() ;) { + Link link = (Link)linkIt.next(); + link.delete(); + } - /* TODO : Delete links */ - Connection c = db.getConnection(); PreparedStatement st = c.prepareStatement("DELETE FROM indexes WHERE id = ?"); st.setInt(1, id); @@ -244,7 +252,14 @@ } public void purgeLinkList() { - /* TODO */ + try { + Connection c = db.getConnection(); + PreparedStatement st = c.prepareStatement("DELETE FROM links WHERE indexParent = ?"); + st.setInt(1, getId()); + st.execute(); + } catch(SQLException e) { + Logger.warning(this, "Unable to purge da list ! Exception: "+e.toString()); + } } public void purgeFileList() { @@ -261,7 +276,7 @@ public void save() { try { Connection c = db.getConnection(); - PreparedStatement st = c.prepareStatement("UPDATE indexes SET originalName = ?, displayName = ?, publicKey = ?, privateKey = ?, positionInTree = ?, revision = ?, parent = ? WHERE id = ?"); + PreparedStatement st = c.prepareStatement("UPDATE indexes SET originalName = ?, displayName = ?, publicKey = ?, privateKey = ?, positionInTree = ?, revision = ?, parent = ? , author = ? WHERE id = ?"); st.setString(1, realName); st.setString(2, displayName); @@ -278,8 +293,10 @@ st.setNull(7, Types.INTEGER); else st.setInt(7, ((IndexTreeNode)treeNode.getParent()).getId()); + + st.setString(8, author); - st.setInt(8, getId()); + st.setInt(9, getId()); st.execute(); } catch(SQLException e) { @@ -339,6 +356,10 @@ Logger.info(this, "Updating index ..."); + publicKey = transfer.getFileKey(); + + Logger.info(this, "Most up-to-date key found: " + publicKey); + loadXML(file); save(); @@ -456,14 +477,114 @@ * Do the update all the files in the database. */ public void updateFileList() { - for(Iterator it = fileList.iterator(); - it.hasNext();) { + for(Iterator it = fileList.iterator(); it.hasNext();) { thaw.plugins.index.File file = (thaw.plugins.index.File)it.next(); file.update(); } } + //// LINKS //// + + public void addLink(Link link) { + link.setParent(this); + link.insert(); + + if (linkList != null) { + linkList.add(link); + + setChanged(); + notifyObservers(link); + } + } + + public void removeLink(Link link) { + link.delete(); + + if (linkList != null) { + linkList.remove(link); + setChanged(); + notifyObservers(link); + } + } + + /** + * Update all the links in the database. + */ + public void updateLinkList() { + for(Iterator it = linkList.iterator(); it.hasNext();) { + Link link = (Link)it.next(); + link.update(); + } + } + + public void loadLinks(String columnToSort, boolean asc) + { + if(linkList != null) + return; + + linkList = new Vector(); + + try { + String query = "SELECT id, publicKey, mark, comment, indexTarget FROM links WHERE indexParent = ?"; + + if(columnToSort != null) { + query = query + "ORDER BY " + columnToSort; + + if(!asc) + query = query + " DESC"; + } + + PreparedStatement st = db.getConnection().prepareStatement(query); + + st.setInt(1, getId()); + + if(st.execute()) { + ResultSet results = st.getResultSet(); + + while(results.next()) { + String[] split = publicKey.split("/"); + try { + String indexName = split[split.length-2]; + Link link = new Link(db, indexName, publicKey, this); + linkList.add(link); + } catch(Exception e) { + Logger.warning(this, "Unable to add index '"+publicKey+"' to the list because: "+e.toString()); + } + } + } + + + } catch(java.sql.SQLException e) { + Logger.warning(this, "Unable to get the link list for index: '"+toString()+"' because: "+e.toString()); + } + + } + + /* Returns a copy ! */ + public Vector getLinkList() + { + Vector newList = new Vector(); + + for(Iterator it = linkList.iterator(); + it.hasNext();) { + newList.add(it.next()); + } + + return newList; + } + + public Link getLink(int index) + { + return (Link)linkList.get(index); + } + + public void unloadLinks() + { + linkList = null; + } + + //// XML //// public void generateXML(java.io.File file) { @@ -524,7 +645,7 @@ return; } - serializer.setOutputProperty(OutputKeys.ENCODING,"ISO-8859-1"); + serializer.setOutputProperty(OutputKeys.ENCODING,"UTF-8"); serializer.setOutputProperty(OutputKeys.INDENT,"yes"); /* final step */ @@ -543,9 +664,14 @@ Text titleText = xmlDoc.createTextNode(toString()); title.appendChild(titleText); - /* TODO : Allow to change username + email */ Element owner = xmlDoc.createElement("owner"); - Text ownerText = xmlDoc.createTextNode("Another anonymous"); + Text ownerText; + + if (author == null) + ownerText = xmlDoc.createTextNode("Another anonymous"); + else + ownerText = xmlDoc.createTextNode(author); + owner.appendChild(ownerText); header.appendChild(title); @@ -617,8 +743,10 @@ Element header = (Element)rootEl.getElementsByTagName("header").item(0); realName = getHeaderElement(header, "title"); - - /* TODO : Author */ + author = getHeaderElement(header, "author"); + + if (author == null) + author = "Another anonymous"; } public String getHeaderElement(Element header, String name) { Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java 2006-09-30 02:46:55 UTC (rev 10585) +++ trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java 2006-10-01 13:57:36 UTC (rev 10586) @@ -243,7 +243,7 @@ String query; - query = "SELECT id, originalName, displayName, publicKey, privateKey, positionInTree, revision FROM indexes"; + query = "SELECT id, originalName, displayName, publicKey, privateKey, author, positionInTree, revision FROM indexes"; if(id < 0) query = query + " WHERE parent IS NULL"; @@ -278,9 +278,12 @@ int revision = result.getInt("revision"); + String author = result.getString("author"); + set(children, position, (new Index(db, queueManager, id, this, realName, displayName, publicKey, privateKey, revision, + author, modifiables)).getTreeNode()); } } catch (java.sql.SQLException e) { Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java 2006-09-30 02:46:55 UTC (rev 10585) +++ trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java 2006-10-01 13:57:36 UTC (rev 10586) @@ -271,7 +271,7 @@ IndexCategory parent = (IndexCategory)selectedNode; - Index index = new Index(db, queueManager, -2, parent, name, name, publicKey, null, 0, modifiables); + Index index = new Index(db, queueManager, -2, parent, name, name, publicKey, null, 0, null, modifiables); if(modifiables) index.generateKeys(queueManager); Modified: trunk/apps/Thaw/src/thaw/plugins/index/Link.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/Link.java 2006-09-30 02:46:55 UTC (rev 10585) +++ trunk/apps/Thaw/src/thaw/plugins/index/Link.java 2006-10-01 13:57:36 UTC (rev 10586) @@ -2,28 +2,126 @@ import java.sql.*; -import thaw.fcp.*; +import thaw.core.Logger; import thaw.plugins.Hsqldb; public class Link extends java.util.Observable { + private int id; - String indexName = null; - String key = null; + private String indexName = null; + private String key = null; - public Link() { + private Index parent = null; - } + private Hsqldb db; - public Link(String indexName, String key) { + + public Link(Hsqldb hsqldb, String indexName, String key, Index parent) { this.indexName = indexName; this.key = key; + this.parent = parent; } + public String getKey() { + return key; + } + + public void setParent(Index index) { + this.parent = index; + } + + public Index getParent() { + return parent; + } + public String getIndexName() { return indexName; } - public String getKey() { + public void setIndexKey(String key) { + this.key = key; + + setChanged(); + notifyObservers(); + } + + public String getIndexKey() { return key; } + + public void insert() { + try { + PreparedStatement st; + + st = db.getConnection().prepareStatement("SELECT id FROM links ORDER BY id DESC LIMIT 1"); + + try { + if(st.execute()) { + ResultSet result = st.getResultSet(); + result.next(); + id = result.getInt("id")+1; + } else + id = 1; + } catch(SQLException e) { + id = 1; + } + + + st = db.getConnection().prepareStatement("INSERT INTO links (id, publicKey, "+ + "mark, comment, indexParent, indexTarget) "+ + "VALUES (?, ?, ?, ?, ?, ?)"); + st.setInt(1, id); + + if(key != null) + st.setString(2, key); + else + st.setString(2, indexName); + + st.setInt(3, 0); + st.setString(4, "No comment"); + st.setInt(5, parent.getId()); + st.setNull(6, Types.INTEGER); + + st.execute(); + } catch(SQLException e) { + Logger.error(this, "Unable to insert link to '"+indexName+"' because: "+e.toString()); + } + + + } + + public void delete() { + try { + PreparedStatement st; + + st = db.getConnection().prepareStatement("DELETE FROM links WHERE id = ?"); + st.setInt(1, id); + + st.execute(); + + } catch(SQLException e) { + Logger.error(this, "Unable to remove link to '"+indexName+"' because: "+e.toString()); + } + } + + public void update() { + try { + PreparedStatement st; + + st = db.getConnection().prepareStatement("UPDATE links SET publicKey = ?, indexParent = ? WHERE id = ?"); + + if(key != null) + st.setString(1, key); + else + st.setString(1, indexName); + + st.setInt(2, getParent().getId()); + + st.setInt(3, id); + + st.execute(); + } catch(SQLException e) { + Logger.error(this, "Unable to update link to '"+indexName+"' because: "+e.toString()); + } + } } Modified: trunk/apps/Thaw/src/thaw/plugins/index/TableCreator.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/TableCreator.java 2006-09-30 02:46:55 UTC (rev 10585) +++ trunk/apps/Thaw/src/thaw/plugins/index/TableCreator.java 2006-10-01 13:57:36 UTC (rev 10586) @@ -53,15 +53,16 @@ sendQuery(db, "CREATE CACHED TABLE indexes (" - + "id INTEGER IDENTITY NOT NULL," - + "originalName VARCHAR(255) NOT NULL," - + "displayName VARCHAR(255) NULL," - + "publicKey VARCHAR(255) NOT NULL," - + "privateKey VARCHAR(255) NULL," - + "positionInTree INTEGER NOT NULL," - + "revision INTEGER NOT NULL," - + "parent INTEGER NULL," - + "PRIMARY KEY (id)," + + "id INTEGER IDENTITY NOT NULL, " + + "originalName VARCHAR(255) NOT NULL, " + + "displayName VARCHAR(255) NULL, " + + "publicKey VARCHAR(255) NOT NULL, " + + "privateKey VARCHAR(255) NULL, " + + "author VARCHAR(255) NULL, " + + "positionInTree INTEGER NOT NULL, " + + "revision INTEGER NOT NULL, " + + "parent INTEGER NULL, " + + "PRIMARY KEY (id), " + "FOREIGN KEY (parent) REFERENCES indexCategories (id))"); sendQuery(db, From jflesch at freenetproject.org Wed Oct 4 20:20:35 2006 From: jflesch at freenetproject.org (jflesch at freenetproject.org) Date: Wed, 4 Oct 2006 20:20:35 +0000 (UTC) Subject: [Thaw-dev] r10601 - in trunk/apps/Thaw/src/thaw: core fcp plugins/index Message-ID: <20061004202035.29F8A9CA66@emu.freenetproject.org> Author: jflesch Date: 2006-10-04 20:20:32 +0000 (Wed, 04 Oct 2006) New Revision: 10601 Modified: trunk/apps/Thaw/src/thaw/core/Logger.java trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java trunk/apps/Thaw/src/thaw/plugins/index/Index.java trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java trunk/apps/Thaw/src/thaw/plugins/index/TableCreator.java Log: Fix index key creations / downloads Modified: trunk/apps/Thaw/src/thaw/core/Logger.java =================================================================== --- trunk/apps/Thaw/src/thaw/core/Logger.java 2006-10-04 20:02:47 UTC (rev 10600) +++ trunk/apps/Thaw/src/thaw/core/Logger.java 2006-10-04 20:20:32 UTC (rev 10601) @@ -94,10 +94,10 @@ * As it. Similar to verbose() */ public static void asIt(Object o, String msg) { - if(LOG_LEVEL >= 5) { + //if(LOG_LEVEL >= 5) { System.out.println(msg); notifyLogListeners(msg); - } + //} } Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java =================================================================== --- trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java 2006-10-04 20:02:47 UTC (rev 10600) +++ trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java 2006-10-04 20:20:32 UTC (rev 10601) @@ -132,16 +132,12 @@ status = "Waiting"; - if(key.indexOf('/') == key.length()-1) { - filename = "index.html"; - } else { - String cutcut[] = key.split("/"); - - //if(!key.startsWith("USK@")) { + String cutcut[] = key.split("/"); + + if(!key.endsWith("/")) { filename = cutcut[cutcut.length-1]; - //} else { - //filename = cutcut[cutcut.length-2]; - //} + } else { + filename = "index.html"; } Logger.debug(this, "Query for getting "+key+" created"); @@ -519,13 +515,9 @@ return false; } - if (globalQueue) { /* If not global, we need to remain on the same socket */ - duplicatedQueryManager = queueManager.getQueryManager().duplicate(identifier); - duplicatedQueryManager.addObserver(this); - } else - duplicatedQueryManager = queueManager.getQueryManager(); + duplicatedQueryManager = queueManager.getQueryManager().duplicate(identifier); + duplicatedQueryManager.addObserver(this); - Logger.info(this, "Waiting for socket avaibility ..."); status = "Waiting for socket avaibility ..."; progress = 99; @@ -542,7 +534,11 @@ } public synchronized boolean continueSaveFileTo(String dir) { - Logger.debug(this, "Asking file to the node..."); + try { + Thread.sleep(20000); + } catch(java.lang.InterruptedException e){ + } + Logger.info(this, "Asking file '"+filename+"' to the node..."); destinationDir = dir; @@ -565,9 +561,7 @@ else getRequestStatus.setValue("Global", "false"); getRequestStatus.setValue("OnlyData", "true"); - - duplicatedQueryManager.writeMessage(getRequestStatus, false); return true; Modified: trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java =================================================================== --- trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java 2006-10-04 20:02:47 UTC (rev 10600) +++ trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java 2006-10-04 20:20:32 UTC (rev 10601) @@ -71,6 +71,9 @@ setNodePort(port); setMaxUploadSpeed(maxUploadSpeed); setDuplicationAllowed(duplicationAllowed); + + lockWriting = false; + lockReading = false; } Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2006-10-04 20:02:47 UTC (rev 10600) +++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2006-10-04 20:20:32 UTC (rev 10601) @@ -310,7 +310,7 @@ public String getKey() { if(modifiable) - return publicKey.replaceFirst("SSK@", "USK@")+realName+"/"+revision+"/"; + return publicKey.replaceFirst("SSK@", "USK@")+realName+"/"+revision+"/"+realName+".xml"; else return publicKey; } Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java 2006-10-04 20:02:47 UTC (rev 10600) +++ trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java 2006-10-04 20:20:32 UTC (rev 10601) @@ -257,7 +257,8 @@ try { String[] cutcut = publicKey.split("/"); - name = cutcut[cutcut.length-2]; + name = cutcut[cutcut.length-1]; + name = name.replaceAll(".xml", ""); } catch(Exception exc) { Logger.warning(this, "Error while parsing index key: "+publicKey+" because: "+exc.toString() ); name = publicKey; Modified: trunk/apps/Thaw/src/thaw/plugins/index/TableCreator.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/TableCreator.java 2006-10-04 20:02:47 UTC (rev 10600) +++ trunk/apps/Thaw/src/thaw/plugins/index/TableCreator.java 2006-10-04 20:20:32 UTC (rev 10601) @@ -79,7 +79,7 @@ sendQuery(db, "CREATE CACHED TABLE links (" - + "id INTEGER IDENTIFY NOT NULL," + + "id INTEGER IDENTITY NOT NULL," + "publicKey VARCHAR(350) NOT NULL," // key ~= 100 + filename == 255 max + "mark INTEGER NOT NULL," + "comment VARCHAR(512) NOT NULL," From jflesch at freenetproject.org Thu Oct 5 17:40:44 2006 From: jflesch at freenetproject.org (jflesch at freenetproject.org) Date: Thu, 5 Oct 2006 17:40:44 +0000 (UTC) Subject: [Thaw-dev] r10613 - trunk/apps/Thaw/src/thaw/fcp Message-ID: <20061005174044.0F91C9BCC3@emu.freenetproject.org> Author: jflesch Date: 2006-10-05 17:40:42 +0000 (Thu, 05 Oct 2006) New Revision: 10613 Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java Log: Fix CHK key when inserting (again...) Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java =================================================================== --- trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java 2006-10-05 17:23:53 UTC (rev 10612) +++ trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java 2006-10-05 17:40:42 UTC (rev 10613) @@ -579,14 +579,10 @@ publicKey = msg.getValue("URI"); publicKey = publicKey.replaceAll("freenet:", ""); - if(keyType == 0) - publicKey = publicKey + "/" + name; if(keyType == 1) publicKey = "KSK@"+name+"-" + Integer.toString(rev); //if(keyType == 2) // publicKey = publicKey + "/" + name + "-" + Integer.toString(rev); - if(keyType == 2) - publicKey = publicKey; status = "Finished"; From nextgens at freenetproject.org Sun Oct 8 09:30:46 2006 From: nextgens at freenetproject.org (nextgens at freenetproject.org) Date: Sun, 8 Oct 2006 09:30:46 +0000 (UTC) Subject: [Thaw-dev] r10648 - trunk/apps/Thaw/src/thaw/i18n Message-ID: <20061008093046.6BF799CD30@emu.freenetproject.org> Author: nextgens Date: 2006-10-08 09:30:44 +0000 (Sun, 08 Oct 2006) New Revision: 10648 Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties Log: Thaw: fix a typo: maybe it should be 'allow thaw to use more than one socket', that would be much more meaningfull Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties =================================================================== --- trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2006-10-06 23:19:43 UTC (rev 10647) +++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2006-10-08 09:30:44 UTC (rev 10648) @@ -104,7 +104,7 @@ thaw.config.nickname=Your nickname -thaw.config.multipleSockets=Allow Thaw to exchange many files at ones with the node +thaw.config.multipleSockets=Allow Thaw to exchange many files at once with the node ## Plugins thaw.plugin.insert.fileToInsert=File to insert From jflesch at freenetproject.org Sun Oct 8 20:21:10 2006 From: jflesch at freenetproject.org (jflesch at freenetproject.org) Date: Sun, 8 Oct 2006 20:21:10 +0000 (UTC) Subject: [Thaw-dev] r10650 - in trunk/apps/Thaw/src/thaw: core fcp i18n plugins/index Message-ID: <20061008202110.362F59CA67@emu.freenetproject.org> Author: jflesch Date: 2006-10-08 20:21:05 +0000 (Sun, 08 Oct 2006) New Revision: 10650 Added: trunk/apps/Thaw/src/thaw/plugins/index/FileAndLinkList.java Modified: trunk/apps/Thaw/src/thaw/core/Logger.java trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java trunk/apps/Thaw/src/thaw/i18n/thaw.properties trunk/apps/Thaw/src/thaw/plugins/index/File.java trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java trunk/apps/Thaw/src/thaw/plugins/index/Index.java trunk/apps/Thaw/src/thaw/plugins/index/IndexBrowserPanel.java trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java trunk/apps/Thaw/src/thaw/plugins/index/IndexEditorPanel.java trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java trunk/apps/Thaw/src/thaw/plugins/index/IndexTreeNode.java trunk/apps/Thaw/src/thaw/plugins/index/Link.java trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java trunk/apps/Thaw/src/thaw/plugins/index/Tables.java Log: It is now possible to make links to other file indexes Modified: trunk/apps/Thaw/src/thaw/core/Logger.java =================================================================== --- trunk/apps/Thaw/src/thaw/core/Logger.java 2006-10-08 17:20:46 UTC (rev 10649) +++ trunk/apps/Thaw/src/thaw/core/Logger.java 2006-10-08 20:21:05 UTC (rev 10650) @@ -94,10 +94,10 @@ * As it. Similar to verbose() */ public static void asIt(Object o, String msg) { - //if(LOG_LEVEL >= 5) { + if(LOG_LEVEL >= 5) { System.out.println(msg); notifyLogListeners(msg); - //} + } } Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java =================================================================== --- trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java 2006-10-08 17:20:46 UTC (rev 10649) +++ trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java 2006-10-08 20:21:05 UTC (rev 10650) @@ -217,17 +217,20 @@ status = "Available"; fileSize = (new Long(message.getValue("DataLength"))).longValue(); - progress = 100; - running = false; - successful = true; - if(isPersistent()) { if(destinationDir != null) { if(!fileExists(destinationDir)) { + progress = 99; + running = true; + successful = false; saveFileTo(destinationDir); - } else + } else { + progress = 100; + running = false; + successful = true; 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"); Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java =================================================================== --- trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java 2006-10-08 17:20:46 UTC (rev 10649) +++ trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java 2006-10-08 20:21:05 UTC (rev 10650) @@ -577,6 +577,15 @@ running = false; publicKey = msg.getValue("URI"); + + if (publicKey == null) { + status = "[Warning]"; + Logger.warning(this, "PutSuccessful message without URI field ?!"); + setChanged(); + notifyObservers(); + return; + } + publicKey = publicKey.replaceAll("freenet:", ""); if(keyType == 1) Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties =================================================================== --- trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2006-10-08 17:20:46 UTC (rev 10649) +++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2006-10-08 20:21:05 UTC (rev 10650) @@ -201,6 +201,7 @@ thaw.plugin.index.indexes=Indexes thaw.plugin.index.addIndex=Add a file index +thaw.plugin.index.addIndexFromLink=Add this index to your list thaw.plugin.index.createIndex=Create a file index thaw.plugin.index.addCategory=Add a folder thaw.plugin.index.rename=Rename Modified: trunk/apps/Thaw/src/thaw/plugins/index/File.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/File.java 2006-10-08 17:20:46 UTC (rev 10649) +++ trunk/apps/Thaw/src/thaw/plugins/index/File.java 2006-10-08 20:21:05 UTC (rev 10650) @@ -73,7 +73,7 @@ public File(Hsqldb db, Element fileElement, Index parent) { this.db = db; - id = Integer.parseInt(fileElement.getAttribute("id")); + id = Integer.parseInt(fileElement.getAttribute("id")); /* will be changed when inserted in the database */ publicKey = fileElement.getAttribute("key"); localPath = null; @@ -290,8 +290,10 @@ public Element getXML(Document xmlDoc) { - if(getPublicKey() == null) + if(getPublicKey() == null) { + Logger.notice(this, "No public key for file '"+fileName+"' => not added to the index"); return null; + } Element file = xmlDoc.createElement("file"); Added: trunk/apps/Thaw/src/thaw/plugins/index/FileAndLinkList.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/FileAndLinkList.java 2006-10-08 17:20:46 UTC (rev 10649) +++ trunk/apps/Thaw/src/thaw/plugins/index/FileAndLinkList.java 2006-10-08 20:21:05 UTC (rev 10650) @@ -0,0 +1,5 @@ +package thaw.plugins.index; + +public interface FileAndLinkList extends FileList, LinkList { + +} Modified: trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java 2006-10-08 17:20:46 UTC (rev 10649) +++ trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java 2006-10-08 20:21:05 UTC (rev 10650) @@ -358,7 +358,6 @@ } public void refresh(TableModelEvent e) { - fireTableChanged(e); } Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2006-10-08 17:20:46 UTC (rev 10649) +++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2006-10-08 20:21:05 UTC (rev 10650) @@ -33,7 +33,7 @@ import thaw.plugins.Hsqldb; import thaw.core.*; -public class Index extends java.util.Observable implements FileList, LinkList, IndexTreeNode, java.util.Observer { +public class Index extends java.util.Observable implements FileAndLinkList, IndexTreeNode, java.util.Observer { private Hsqldb db; private IndexTree tree; @@ -94,6 +94,10 @@ treeNode.setUserObject(this); } + public void setParent(IndexCategory parent) { + this.parent = parent; + } + public DefaultMutableTreeNode getTreeNode() { return treeNode; } @@ -137,7 +141,7 @@ st.setInt(8, revision); - if(parent.getId() >= 0) + if(parent != null && parent.getId() >= 0) st.setInt(9, parent.getId()); else st.setNull(9, Types.INTEGER); @@ -183,8 +187,8 @@ public void delete() { try { - loadFiles(null, false); - loadLinks(null, false); + loadFiles(null, true); + loadLinks(null, true); for(Iterator fileIt = fileList.iterator(); fileIt.hasNext(); ) { thaw.plugins.index.File file = (thaw.plugins.index.File)fileIt.next(); @@ -205,6 +209,23 @@ } } + + protected String changeRevision(String key, int move) { + try { + String newKey; + String[] split = key.split("/"); + newKey = split[0] + "/" + split[1] + "/" + + Integer.toString(Integer.parseInt(split[2])+move) + "/" + + split[3]; + + } catch (Exception e) { + Logger.warning(this, "Unable to add a revision to the key '"+key+"' because : "+e.toString()); + } + + return key; + } + + public void update() { targetFile = new java.io.File(toString()+".xml"); @@ -235,7 +256,7 @@ Logger.info(this, "Getting last version"); - clientGet = new FCPClientGet(publicKey, 4, 2, false, System.getProperty("java.io.tmpdir")); + clientGet = new FCPClientGet(changeRevision(publicKey, 1), 4, 2, false, System.getProperty("java.io.tmpdir")); transfer = clientGet; clientGet.addObserver(this); @@ -257,6 +278,7 @@ PreparedStatement st = c.prepareStatement("DELETE FROM links WHERE indexParent = ?"); st.setInt(1, getId()); st.execute(); + linkList = new Vector(); } catch(SQLException e) { Logger.warning(this, "Unable to purge da list ! Exception: "+e.toString()); } @@ -268,6 +290,7 @@ PreparedStatement st = c.prepareStatement("DELETE FROM files WHERE indexParent = ?"); st.setInt(1, getId()); st.execute(); + fileList = new Vector(); } catch(SQLException e) { Logger.warning(this, "Unable to purge da list ! Exception: "+e.toString()); } @@ -383,8 +406,10 @@ ////// FILE LIST //////// public void loadFiles(String columnToSort, boolean asc) { - if(fileList != null) + if(fileList != null) { + Logger.notice(this, "Files already loaded, won't reload them"); return; + } fileList = new Vector(); @@ -520,8 +545,10 @@ public void loadLinks(String columnToSort, boolean asc) { - if(linkList != null) + if(linkList != null) { + Logger.notice(this, "Links aleady loaded, won't reload ..."); return; + } linkList = new Vector(); @@ -543,10 +570,8 @@ ResultSet results = st.getResultSet(); while(results.next()) { - String[] split = publicKey.split("/"); try { - String indexName = split[split.length-2]; - Link link = new Link(db, indexName, publicKey, this); + Link link = new Link(db, results, this); linkList.add(link); } catch(Exception e) { Logger.warning(this, "Unable to add index '"+publicKey+"' to the list because: "+e.toString()); @@ -683,6 +708,22 @@ public Element getXMLLinks(Document xmlDoc) { Element links = xmlDoc.createElement("indexes"); + if (linkList == null) { + loadLinks(null, true); + } + + for (Iterator it = getLinkList().iterator(); + it.hasNext();) { + Link link = (Link)it.next(); + + Element xmlLink = link.getXML(xmlDoc); + + if (xmlLink != null) + links.appendChild(xmlLink); + else + Logger.warning(this, "Unable to get XML for the link '"+link.getIndexName()+"' => Gruick da link"); + } + return links; } @@ -769,14 +810,14 @@ if(list.item(i).getNodeType() == Node.ELEMENT_NODE) { Element e = (Element)list.item(i); - /* TODO : Links */ + Link link = new Link(db, e, this); + addLink(link); } } } public void loadFileList(Element rootEl) { - fileList = new Vector(); purgeFileList(); Element filesEl = (Element)rootEl.getElementsByTagName("files").item(0); @@ -792,4 +833,18 @@ } } + + static String getNameFromKey(String key) { + String name = null; + try { + String[] cutcut = key.split("/"); + name = cutcut[cutcut.length-1]; + name = name.replaceAll(".xml", ""); + } catch (Exception e) { + Logger.warning(e, "thaw.plugins.index.Index: Error while parsing index key: "+key+" because: "+e.toString() ); + name = key; + } + return name; + } + } Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexBrowserPanel.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/IndexBrowserPanel.java 2006-10-08 17:20:46 UTC (rev 10649) +++ trunk/apps/Thaw/src/thaw/plugins/index/IndexBrowserPanel.java 2006-10-08 20:21:05 UTC (rev 10650) @@ -1,4 +1,4 @@ -package thaw.plugins; +package thaw.plugins.index; import javax.swing.JPanel; import javax.swing.JSplitPane; @@ -17,7 +17,7 @@ import thaw.core.*; import thaw.fcp.*; -import thaw.plugins.index.*; +import thaw.plugins.Hsqldb; public class IndexBrowserPanel implements javax.swing.event.TreeSelectionListener, ActionListener { @@ -44,7 +44,7 @@ listAndDetails = new JPanel(); listAndDetails.setLayout(new BorderLayout(10, 10)); - tables = new Tables(false, queueManager); + tables = new Tables(false, db, queueManager, indexTree); fileDetails = new FileDetailsEditor(false); listAndDetails.add(tables.getPanel(), BorderLayout.CENTER); @@ -65,18 +65,29 @@ public void save() { indexTree.save(); } + + + protected void setList(FileAndLinkList l) { + setFileList(l); + setLinkList(l); + } protected void setFileList(FileList l) { tables.getFileTable().setFileList(l); } + + protected void setLinkList(LinkList l) { + tables.getLinkTable().setLinkList(l); + } public void valueChanged(javax.swing.event.TreeSelectionEvent e) { javax.swing.tree.TreePath path = e.getPath(); - + + setList(null); + if(path == null) { Logger.notice(this, "Path null ?"); - setFileList(null); return; } @@ -84,17 +95,19 @@ if(node == null) { Logger.notice(this, "Node null ?"); - setFileList(null); return; } - if(node instanceof FileList) { + if (node instanceof FileList) { Logger.info(this, "FileList !"); setFileList((FileList)node); - return; } - - setFileList(null); + + if (node instanceof LinkList) { + Logger.info(this, "LinkList !"); + setLinkList((LinkList)node); + } + } Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java 2006-10-08 17:20:46 UTC (rev 10649) +++ trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java 2006-10-08 20:21:05 UTC (rev 10650) @@ -48,6 +48,10 @@ } + public void setParent(IndexCategory parent) { + this.parent = parent; + } + public DefaultMutableTreeNode getTreeNode() { return this; } Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexEditorPanel.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/IndexEditorPanel.java 2006-10-08 17:20:46 UTC (rev 10649) +++ trunk/apps/Thaw/src/thaw/plugins/index/IndexEditorPanel.java 2006-10-08 20:21:05 UTC (rev 10650) @@ -1,4 +1,4 @@ -package thaw.plugins; +package thaw.plugins.index; import javax.swing.JPanel; import javax.swing.JSplitPane; @@ -19,7 +19,9 @@ import thaw.plugins.index.*; +import thaw.plugins.Hsqldb; + public class IndexEditorPanel implements java.util.Observer, javax.swing.event.TreeSelectionListener, ActionListener { public final static int DEFAULT_INSERTION_PRIORITY = 4; @@ -36,7 +38,8 @@ private JButton insertAndAddButton; private JButton linkButton; - private FileList fileList = null; + private FileList fileList = null; /* Index or SearchResult object */ + private LinkList linkList = null; private Hsqldb db; private FCPQueueManager queueManager; @@ -48,12 +51,6 @@ indexTree = new IndexTree(I18n.getMessage("thaw.plugin.index.yourIndexes"), true, false, queueManager, db); - listAndDetails = new JPanel(); - listAndDetails.setLayout(new BorderLayout(0, 0)); - - tables = new Tables(true, queueManager); - fileDetails = new FileDetailsEditor(true); - toolBar = new JToolBar(); toolBar.setFloatable(false); @@ -75,6 +72,12 @@ toolBar.addSeparator(); toolBar.add(linkButton); + tables = new Tables(true, db, queueManager, indexTree); + fileDetails = new FileDetailsEditor(true); + + listAndDetails = new JPanel(); + listAndDetails.setLayout(new BorderLayout(0, 0)); + listAndDetails.add(toolBar, BorderLayout.NORTH); listAndDetails.add(tables.getPanel(), BorderLayout.CENTER); listAndDetails.add(fileDetails.getPanel(), BorderLayout.SOUTH); @@ -101,6 +104,17 @@ linkButton.setEnabled(a); } + protected void setList(FileAndLinkList l) { + setLinkList(l); + setFileList(l); + } + + protected void setLinkList(LinkList l) { + buttonsEnabled(l != null && l instanceof Index); + this.linkList = l; + tables.getLinkTable().setLinkList(l); + } + protected void setFileList(FileList l) { buttonsEnabled(l != null && l instanceof Index); @@ -111,9 +125,10 @@ public void valueChanged(javax.swing.event.TreeSelectionEvent e) { javax.swing.tree.TreePath path = e.getPath(); + setList(null); + if(path == null) { Logger.notice(this, "Path null ?"); - setFileList(null); return; } @@ -121,16 +136,19 @@ if(node == null) { Logger.notice(this, "Node null ?"); - setFileList(null); return; } - if(node instanceof FileList) { + if(node instanceof FileList) { + Logger.info(this, "FileList !"); setFileList((FileList)node); - return; } - - setFileList(null); + + if(node instanceof LinkList) { + Logger.info(this, "LinkList !"); + setLinkList((LinkList)node); + } + } @@ -189,14 +207,15 @@ public class LinkMaker implements Runnable { - public LinkMaker() { + public LinkMaker() { } - } - public void run() { IndexSelecter indexSelecter = new IndexSelecter(); String indexKey = indexSelecter.askForAnIndexURI(db); - + if (indexKey != null) { + Link newLink = new Link(db, indexKey, (Index)linkList); + ((Index)linkList).addLink(newLink); + } } } @@ -204,8 +223,7 @@ if(o instanceof FCPClientPut) { FCPClientPut clientPut = (FCPClientPut)o; if(clientPut.isFinished()) { - queueManager.remove(clientPut); - + queueManager.remove(clientPut); } } } Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java 2006-10-08 17:20:46 UTC (rev 10649) +++ trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java 2006-10-08 20:21:05 UTC (rev 10650) @@ -3,6 +3,7 @@ import javax.swing.JPanel; import java.awt.BorderLayout; import javax.swing.JTree; +import javax.swing.tree.TreeSelectionModel; import javax.swing.tree.TreeNode; import javax.swing.tree.MutableTreeNode; import javax.swing.tree.DefaultMutableTreeNode; @@ -170,6 +171,9 @@ tree.setCellRenderer(treeRenderer); + if (selectionOnly) + tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); + panel.add(new JScrollPane(tree)); } @@ -255,14 +259,8 @@ Logger.warning(this, "UnsupportedEncodingException (UTF-8): "+exc.toString()); } - try { - String[] cutcut = publicKey.split("/"); - name = cutcut[cutcut.length-1]; - name = name.replaceAll(".xml", ""); - } catch(Exception exc) { - Logger.warning(this, "Error while parsing index key: "+publicKey+" because: "+exc.toString() ); - name = publicKey; - } + name = Index.getNameFromKey(publicKey); + } else name = askAName(I18n.getMessage("thaw.plugin.index.indexName"), I18n.getMessage("thaw.plugin.index.newIndex")); @@ -413,4 +411,18 @@ } } + + void addToRoot(IndexTreeNode node) { + node.setParent(root); + root.insert(node.getTreeNode(), root.getChildCount()); + reloadModel(root); + } + + /** + * @param node can be null + */ + void reloadModel(DefaultMutableTreeNode node) { + treeModel.reload(node); + } + } Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexTreeNode.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/IndexTreeNode.java 2006-10-08 17:20:46 UTC (rev 10649) +++ trunk/apps/Thaw/src/thaw/plugins/index/IndexTreeNode.java 2006-10-08 20:21:05 UTC (rev 10650) @@ -7,6 +7,8 @@ public interface IndexTreeNode { public DefaultMutableTreeNode getTreeNode(); + + public void setParent(IndexCategory parent); /** * get Id of this node in the database. Modified: trunk/apps/Thaw/src/thaw/plugins/index/Link.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/Link.java 2006-10-08 17:20:46 UTC (rev 10649) +++ trunk/apps/Thaw/src/thaw/plugins/index/Link.java 2006-10-08 20:21:05 UTC (rev 10650) @@ -2,6 +2,11 @@ import java.sql.*; +import org.w3c.dom.Element; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + import thaw.core.Logger; import thaw.plugins.Hsqldb; @@ -20,8 +25,32 @@ this.indexName = indexName; this.key = key; this.parent = parent; + this.db = hsqldb; } + public Link(Hsqldb hsqldb, String key, Index parent) { + this(hsqldb, Index.getNameFromKey(key), key, parent); + } + + public Link(Hsqldb hsqldb, ResultSet resultSet, Index parent) throws SQLException { + this.db = hsqldb; + this.id = resultSet.getInt("id"); + this.key = resultSet.getString("publicKey"); + + this.indexName = Index.getNameFromKey(this.key); + + this.parent = parent; + } + + public Link(Hsqldb hsqldb, Element linkElement, Index parent) { + this.db = hsqldb; + this.key = linkElement.getAttribute("key"); + + this.indexName = Index.getNameFromKey(this.key); + + this.parent = parent; + } + public String getKey() { return key; } @@ -124,4 +153,13 @@ Logger.error(this, "Unable to update link to '"+indexName+"' because: "+e.toString()); } } + + + public Element getXML(Document xmlDoc) { + Element link = xmlDoc.createElement("index"); + + link.setAttribute("key", key); + + return link; + } } Modified: trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java 2006-10-08 17:20:46 UTC (rev 10649) +++ trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java 2006-10-08 20:21:05 UTC (rev 10650) @@ -41,6 +41,9 @@ import thaw.core.*; import thaw.fcp.*; +import thaw.plugins.Hsqldb; + + public class LinkTable implements MouseListener, KeyListener, ActionListener { private JPanel panel; @@ -52,11 +55,20 @@ private FCPQueueManager queueManager; private boolean modifiables; + private JPopupMenu rightClickMenu; + private JMenuItem removeLinks; + private JMenuItem addThisIndex; + private JMenuItem copyKey; + private IndexTree indexTree; + + private Hsqldb db; + private int[] selectedRows; - public LinkTable (boolean modifiables, FCPQueueManager queueManager) { + public LinkTable (boolean modifiables, Hsqldb db, FCPQueueManager queueManager, IndexTree tree) { this.modifiables = modifiables; this.queueManager = queueManager; + this.db = db; linkListModel = new LinkListModel(); table = new JTable(linkListModel); @@ -68,6 +80,23 @@ panel.add(new JLabel(I18n.getMessage("thaw.plugin.index.linkList")), BorderLayout.NORTH); panel.add(new JScrollPane(table)); + rightClickMenu = new JPopupMenu(); + removeLinks = new JMenuItem(I18n.getMessage("thaw.common.remove")); + addThisIndex = new JMenuItem(I18n.getMessage("thaw.plugin.index.addIndexFromLink")); + copyKey = new JMenuItem(I18n.getMessage("thaw.plugin.index.copyKey")); + + removeLinks.addActionListener(this); + addThisIndex.addActionListener(this); + copyKey.addActionListener(this); + + if (modifiables) + rightClickMenu.add(removeLinks); + rightClickMenu.add(addThisIndex); + rightClickMenu.add(copyKey); + + table.addMouseListener(this); + + indexTree = tree; } public JPanel getPanel() { @@ -89,7 +118,12 @@ } public void mouseClicked(MouseEvent e) { - + if(e.getButton() == MouseEvent.BUTTON3 + && linkList != null) { + removeLinks.setEnabled(linkList instanceof Index); + selectedRows = table.getSelectedRows(); + rightClickMenu.show(e.getComponent(), e.getX(), e.getY()); + } } public void mouseEntered(MouseEvent e) { } @@ -107,7 +141,44 @@ public void keyTyped(KeyEvent e) { } public void actionPerformed(ActionEvent e) { + Vector links; + String keyList = ""; + if (linkList == null) + return; + + links = linkList.getLinkList(); + + for (int i = 0 ; i < selectedRows.length; i++) { + + if (e.getSource() == removeLinks) { + Link link = (Link)links.get(selectedRows[i]); + ((Index)linkList).removeLink(link); + } + + if (e.getSource() == addThisIndex) { + Link link = (Link)links.get(selectedRows[i]); + Index index = new Index(db, queueManager, -2, null, Index.getNameFromKey(link.getKey()), + Index.getNameFromKey(link.getKey()), link.getKey(), null, + 0, null, false); + index.create(); + indexTree.addToRoot(index); + } + + if (e.getSource() == copyKey) { + Link link = (Link)links.get(selectedRows[i]); + if (link.getKey() != null) + keyList = keyList + link.getKey() + "\n"; + } + } + + if(e.getSource() == copyKey) { + Toolkit tk = Toolkit.getDefaultToolkit(); + StringSelection st = new StringSelection(keyList); + Clipboard cp = tk.getSystemClipboard(); + cp.setContents(st, null); + } + } @@ -134,7 +205,7 @@ } if (newLinkList != null && (newLinkList instanceof Observable)) { - ((Observable)newLinkList).deleteObserver(this); + ((Observable)newLinkList).addObserver(this); } linkList = newLinkList; @@ -162,6 +233,8 @@ } } + refresh(); + } public int getRowCount() { @@ -199,13 +272,12 @@ refresh(event); } - public void refresh(int row) { + public void refresh(int row) { TableModelEvent event = new TableModelEvent(this, row); refresh(event); } public void refresh(TableModelEvent e) { - fireTableChanged(e); } Modified: trunk/apps/Thaw/src/thaw/plugins/index/Tables.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/Tables.java 2006-10-08 17:20:46 UTC (rev 10649) +++ trunk/apps/Thaw/src/thaw/plugins/index/Tables.java 2006-10-08 20:21:05 UTC (rev 10650) @@ -6,6 +6,8 @@ import thaw.fcp.FCPQueueManager; +import thaw.plugins.Hsqldb; + /** * Contains a FileTable, a LinkTable, and a SearchBar */ @@ -16,12 +18,12 @@ private FileTable fileTable; private LinkTable linkTable; - public Tables(boolean modifiables, FCPQueueManager queueManager) { + public Tables(boolean modifiables, Hsqldb db, FCPQueueManager queueManager, IndexTree tree) { panel = new JPanel(); panel.setLayout(new BorderLayout(10, 10)); fileTable = new FileTable(modifiables, queueManager); - linkTable = new LinkTable(modifiables, queueManager); + linkTable = new LinkTable(modifiables, db, queueManager, tree); searchBar = new SearchBar(fileTable, linkTable); From jflesch at freenetproject.org Mon Oct 9 20:35:42 2006 From: jflesch at freenetproject.org (jflesch at freenetproject.org) Date: Mon, 9 Oct 2006 20:35:42 +0000 (UTC) Subject: [Thaw-dev] r10654 - trunk/apps/Thaw/src/thaw/plugins/index Message-ID: <20061009203542.AD2609BB7F@emu.freenetproject.org> Author: jflesch Date: 2006-10-09 20:35:41 +0000 (Mon, 09 Oct 2006) New Revision: 10654 Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java Log: Should fix index update mechanism Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2006-10-08 21:19:49 UTC (rev 10653) +++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2006-10-09 20:35:41 UTC (rev 10654) @@ -214,10 +214,12 @@ try { String newKey; String[] split = key.split("/"); + newKey = split[0] + "/" + split[1] + "/" + Integer.toString(Integer.parseInt(split[2])+move) + "/" + split[3]; + return newKey; } catch (Exception e) { Logger.warning(this, "Unable to add a revision to the key '"+key+"' because : "+e.toString()); } @@ -254,9 +256,13 @@ } else { FCPClientGet clientGet; - Logger.info(this, "Getting last version"); + Logger.info(this, "Getting lastest version ..."); - clientGet = new FCPClientGet(changeRevision(publicKey, 1), 4, 2, false, System.getProperty("java.io.tmpdir")); + String key = changeRevision(publicKey, 1); + + Logger.info(this, "Key asked: "+key); + + clientGet = new FCPClientGet(key, 4, 2, false, System.getProperty("java.io.tmpdir")); transfer = clientGet; clientGet.addObserver(this); @@ -399,6 +405,13 @@ } } + + if (transfer.isFinished() && !transfer.isSuccessful()) { + Logger.info(this, "Unable to get new version of the index"); + transfer = null; + return; + } + } } From jflesch at freenetproject.org Tue Oct 10 06:18:11 2006 From: jflesch at freenetproject.org (jflesch at freenetproject.org) Date: Tue, 10 Oct 2006 06:18:11 +0000 (UTC) Subject: [Thaw-dev] r10655 - trunk/apps/Thaw/src/thaw/fcp Message-ID: <20061010061811.7781C9BC2F@emu.freenetproject.org> Author: jflesch Date: 2006-10-10 06:18:09 +0000 (Tue, 10 Oct 2006) New Revision: 10655 Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java Log: Fix status display when downloading Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java =================================================================== --- trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java 2006-10-09 20:35:41 UTC (rev 10654) +++ trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java 2006-10-10 06:18:09 UTC (rev 10655) @@ -214,18 +214,19 @@ if(!alreadySaved) { alreadySaved = true; - status = "Available"; fileSize = (new Long(message.getValue("DataLength"))).longValue(); if(isPersistent()) { if(destinationDir != null) { if(!fileExists(destinationDir)) { + status = "Requesting file from the node"; progress = 99; running = true; successful = false; saveFileTo(destinationDir); } else { + status = "Available"; progress = 100; running = false; successful = true; From jflesch at freenetproject.org Tue Oct 10 17:29:00 2006 From: jflesch at freenetproject.org (jflesch at freenetproject.org) Date: Tue, 10 Oct 2006 17:29:00 +0000 (UTC) Subject: [Thaw-dev] r10656 - trunk/apps/Thaw/src/thaw/fcp Message-ID: <20061010172900.31B059BF76@emu.freenetproject.org> Author: jflesch Date: 2006-10-10 17:28:58 +0000 (Tue, 10 Oct 2006) New Revision: 10656 Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java Log: Fix FCPClientGet Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java =================================================================== --- trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java 2006-10-10 06:18:09 UTC (rev 10655) +++ trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java 2006-10-10 17:28:58 UTC (rev 10656) @@ -224,7 +224,7 @@ progress = 99; running = true; successful = false; - saveFileTo(destinationDir); + saveFileTo(destinationDir, false); } else { status = "Available"; progress = 100; @@ -498,7 +498,11 @@ } } - public synchronized boolean saveFileTo(String dir) { + public boolean saveFileTo(String dir) { + return this.saveFileTo(dir, true); + } + + public synchronized boolean saveFileTo(String dir, boolean checkStatus) { fromTheNodeProgress = 0; if(dir == null) { @@ -509,7 +513,7 @@ destinationDir = dir; - if(!isFinished() || !isSuccessful()) { + if(checkStatus && (!isFinished() || !isSuccessful())) { Logger.warning(this, "Unable to fetch a file not finished"); return false; } @@ -519,6 +523,8 @@ return false; } + Logger.info(this, "Duplicating socket ..."); + duplicatedQueryManager = queueManager.getQueryManager().duplicate(identifier); duplicatedQueryManager.addObserver(this); @@ -538,10 +544,7 @@ } public synchronized boolean continueSaveFileTo(String dir) { - try { - Thread.sleep(20000); - } catch(java.lang.InterruptedException e){ - } + Logger.info(this, "Asking file '"+filename+"' to the node..."); destinationDir = dir; Modified: trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java =================================================================== --- trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java 2006-10-10 06:18:09 UTC (rev 10655) +++ trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java 2006-10-10 17:28:58 UTC (rev 10656) @@ -263,6 +263,7 @@ lastWrite = System.currentTimeMillis(); out.write(data); + out.flush(); } catch(java.io.IOException e) { Logger.warning(this, "Unable to write() on the socket ?! : "+ e.toString()+ " ; "+e.getMessage()); disconnect(); From jflesch at freenetproject.org Tue Oct 10 18:52:08 2006 From: jflesch at freenetproject.org (jflesch at freenetproject.org) Date: Tue, 10 Oct 2006 18:52:08 +0000 (UTC) Subject: [Thaw-dev] r10657 - in trunk/apps/Thaw/src/thaw/plugins: . index Message-ID: <20061010185208.066E79BE04@emu.freenetproject.org> Author: jflesch Date: 2006-10-10 18:52:05 +0000 (Tue, 10 Oct 2006) New Revision: 10657 Modified: trunk/apps/Thaw/src/thaw/plugins/FetchPlugin.java trunk/apps/Thaw/src/thaw/plugins/index/Index.java trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java Log: Fix index first update Modified: trunk/apps/Thaw/src/thaw/plugins/FetchPlugin.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/FetchPlugin.java 2006-10-10 17:28:58 UTC (rev 10656) +++ trunk/apps/Thaw/src/thaw/plugins/FetchPlugin.java 2006-10-10 18:52:05 UTC (rev 10657) @@ -57,6 +57,7 @@ String[] subKey = keys[i].split("\\?"); /* Because of VolodyA :p */ String key = subKey[0].replaceFirst("http://127.0.0.1:8888/", ""); + key = key.replaceFirst("http://localhost/", ""); try { key = java.net.URLDecoder.decode(key, "UTF-8"); Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2006-10-10 17:28:58 UTC (rev 10656) +++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2006-10-10 18:52:05 UTC (rev 10657) @@ -63,12 +63,17 @@ private String author = null; + private boolean freshIndex = false; + /** + * The bigest constructor of the world ... + * @param fresh If set to true, won't increment revision for the next update + */ public Index(Hsqldb db, FCPQueueManager queueManager, int id, IndexCategory parent, String realName, String displayName, String publicKey, String privateKey, - int revision, String author, + int revision, String author, boolean fresh, boolean modifiable) { this.queueManager = queueManager; @@ -77,6 +82,7 @@ this.db = db; this.tree = tree; + this.freshIndex = fresh; this.id = id; this.parent = parent; this.realName = realName; @@ -258,8 +264,13 @@ Logger.info(this, "Getting lastest version ..."); - String key = changeRevision(publicKey, 1); + String key; + if (!freshIndex) + key = changeRevision(publicKey, 1); + else + key = publicKey; + Logger.info(this, "Key asked: "+key); clientGet = new FCPClientGet(key, 4, 2, false, System.getProperty("java.io.tmpdir")); Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java 2006-10-10 17:28:58 UTC (rev 10656) +++ trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java 2006-10-10 18:52:05 UTC (rev 10657) @@ -287,7 +287,7 @@ set(children, position, (new Index(db, queueManager, id, this, realName, displayName, publicKey, privateKey, revision, - author, + author, false, modifiables)).getTreeNode()); } } catch (java.sql.SQLException e) { Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java 2006-10-10 17:28:58 UTC (rev 10656) +++ trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java 2006-10-10 18:52:05 UTC (rev 10657) @@ -252,6 +252,8 @@ if(!modifiables) { publicKey = askAName(I18n.getMessage("thaw.plugin.index.indexKey"), "USK@"); + publicKey = publicKey.replaceFirst("http://127.0.0.1/", ""); + publicKey = publicKey.replaceFirst("http://localhost/", ""); try { publicKey = java.net.URLDecoder.decode(publicKey, "UTF-8"); @@ -263,14 +265,14 @@ } else name = askAName(I18n.getMessage("thaw.plugin.index.indexName"), - I18n.getMessage("thaw.plugin.index.newIndex")); + I18n.getMessage("thaw.plugin.index.newIndex")); if(name == null) return; IndexCategory parent = (IndexCategory)selectedNode; - Index index = new Index(db, queueManager, -2, parent, name, name, publicKey, null, 0, null, modifiables); + Index index = new Index(db, queueManager, -2, parent, name, name, publicKey, null, 0, null, true, modifiables); if(modifiables) index.generateKeys(queueManager); Modified: trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java 2006-10-10 17:28:58 UTC (rev 10656) +++ trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java 2006-10-10 18:52:05 UTC (rev 10657) @@ -160,7 +160,7 @@ Link link = (Link)links.get(selectedRows[i]); Index index = new Index(db, queueManager, -2, null, Index.getNameFromKey(link.getKey()), Index.getNameFromKey(link.getKey()), link.getKey(), null, - 0, null, false); + 0, null, true, false); index.create(); indexTree.addToRoot(index); } From jflesch at freenetproject.org Sun Oct 15 21:56:26 2006 From: jflesch at freenetproject.org (jflesch at freenetproject.org) Date: Sun, 15 Oct 2006 21:56:26 +0000 (UTC) Subject: [Thaw-dev] r10664 - in trunk/apps/Thaw/src/thaw: fcp plugins plugins/index Message-ID: <20061015215626.7B48C9CCDF@emu.freenetproject.org> Author: jflesch Date: 2006-10-15 21:56:19 +0000 (Sun, 15 Oct 2006) New Revision: 10664 Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java trunk/apps/Thaw/src/thaw/fcp/FCPQueueLoader.java trunk/apps/Thaw/src/thaw/plugins/FetchPlugin.java trunk/apps/Thaw/src/thaw/plugins/index/File.java trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java trunk/apps/Thaw/src/thaw/plugins/index/Index.java trunk/apps/Thaw/src/thaw/plugins/index/IndexBrowserPanel.java trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java trunk/apps/Thaw/src/thaw/plugins/index/IndexEditorPanel.java trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java trunk/apps/Thaw/src/thaw/plugins/index/IndexTreeNode.java trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java trunk/apps/Thaw/src/thaw/plugins/index/SearchBar.java trunk/apps/Thaw/src/thaw/plugins/index/SearchResult.java trunk/apps/Thaw/src/thaw/plugins/index/TableCreator.java trunk/apps/Thaw/src/thaw/plugins/index/Tables.java Log: Thaw now implements a search mechanism Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java =================================================================== --- trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java 2006-10-15 17:21:03 UTC (rev 10663) +++ trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java 2006-10-15 21:56:19 UTC (rev 10664) @@ -14,7 +14,7 @@ * TODO: Use streams instead of writing directly the file. */ public class FCPClientGet extends Observable implements Observer, FCPTransferQuery { - private final static int MAX_RETRIES = -1; + private int maxRetries = -1; private final static int PACKET_SIZE = 1024; private final static int BLOCK_SIZE = 32768; @@ -73,9 +73,10 @@ public FCPClientGet(String id, String key, int priority, int persistence, boolean globalQueue, String destinationDir, String status, int progress, + int maxRetries, FCPQueueManager queueManager) { - this(key, priority, persistence, globalQueue, destinationDir); + this(key, priority, persistence, globalQueue, maxRetries, destinationDir); progressReliable = false; @@ -111,6 +112,7 @@ */ public FCPClientGet(String key, int priority, int persistence, boolean globalQueue, + int maxRetries, String destinationDir) { @@ -120,6 +122,7 @@ progressReliable = false; fromTheNodeProgress = 0; + this.maxRetries = maxRetries; this.key = key; this.priority = priority; this.persistence = persistence; @@ -164,7 +167,7 @@ queryMessage.setValue("URI", getFileKey()); queryMessage.setValue("Identifier", identifier); queryMessage.setValue("Verbosity", "1"); - queryMessage.setValue("MaxRetries", Integer.toString(MAX_RETRIES)); + queryMessage.setValue("MaxRetries", Integer.toString(maxRetries)); queryMessage.setValue("PriorityClass", Integer.toString(priority)); if(destinationDir != null) @@ -318,7 +321,7 @@ int code = Integer.parseInt(message.getValue("Code")); - if(MAX_RETRIES == -1 || attempt >= MAX_RETRIES || code == 25) { + if(maxRetries == -1 || attempt >= maxRetries || code == 25) { status = "Failed ("+message.getValue("CodeDescription")+")"; progress = 100; running = false; @@ -837,7 +840,7 @@ } public int getMaxAttempt() { - return MAX_RETRIES; + return maxRetries; } public boolean isSuccessful() { @@ -870,12 +873,13 @@ result.put("FileSize", Long.toString(fileSize)); result.put("Running", Boolean.toString(running)); result.put("Successful", Boolean.toString(successful)); + result.put("MaxRetries", Integer.toString(maxRetries)); return result; } public boolean setParameters(HashMap parameters) { - + key = (String)parameters.get("URI"); Logger.debug(this, "Resuming key : "+key); @@ -895,6 +899,7 @@ fileSize = Long.parseLong((String)parameters.get("FileSize")); running = Boolean.valueOf((String)parameters.get("Running")).booleanValue(); successful = Boolean.valueOf((String)parameters.get("Successful")).booleanValue(); + maxRetries = Integer.parseInt((String)parameters.get("MaxRetries")); if(persistence == 2 && !isFinished()) { progress = 0; Modified: trunk/apps/Thaw/src/thaw/fcp/FCPQueueLoader.java =================================================================== --- trunk/apps/Thaw/src/thaw/fcp/FCPQueueLoader.java 2006-10-15 17:21:03 UTC (rev 10663) +++ trunk/apps/Thaw/src/thaw/fcp/FCPQueueLoader.java 2006-10-15 21:56:19 UTC (rev 10664) @@ -72,7 +72,7 @@ msg.getValue("URI"), // key priority, persistence, global, destinationDir, "Fetching", 0, - queueManager); + -1, queueManager); if(queueManager.addQueryToTheRunningQueue(clientGet, false)) Modified: trunk/apps/Thaw/src/thaw/plugins/FetchPlugin.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/FetchPlugin.java 2006-10-15 17:21:03 UTC (rev 10663) +++ trunk/apps/Thaw/src/thaw/plugins/FetchPlugin.java 2006-10-15 21:56:19 UTC (rev 10664) @@ -68,7 +68,7 @@ core.getQueueManager().addQueryToThePendingQueue(new FCPClientGet(key, priority, persistence, - globalQueue, + globalQueue, -1, destination)); } Modified: trunk/apps/Thaw/src/thaw/plugins/index/File.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/File.java 2006-10-15 17:21:03 UTC (rev 10663) +++ trunk/apps/Thaw/src/thaw/plugins/index/File.java 2006-10-15 21:56:19 UTC (rev 10664) @@ -63,7 +63,7 @@ publicKey = resultSet.getString("publicKey"); localPath = resultSet.getString("localPath"); size = resultSet.getLong("size"); - category = resultSet.getString("category"); + //category = resultSet.getString("category"); deduceFilenameFromKey(); @@ -162,6 +162,11 @@ } public void insert() { + if (parent == null) { + Logger.notice(this, "insert(): No parent !"); + return; + } + try { PreparedStatement st; @@ -216,6 +221,7 @@ } public void delete() { + try { PreparedStatement st; @@ -230,6 +236,11 @@ } public void update() { + if (parent == null) { + Logger.notice(this, "update(): No parent !"); + return; + } + try { PreparedStatement st; Modified: trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java 2006-10-15 17:21:03 UTC (rev 10663) +++ trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java 2006-10-15 21:56:19 UTC (rev 10664) @@ -204,7 +204,7 @@ if(e.getSource() == downloadFiles) { thaw.plugins.index.File file = index.getFile(selectedRows[i]); - FCPClientGet clientGet = new FCPClientGet(file.getPublicKey(), 4, 0, true, + FCPClientGet clientGet = new FCPClientGet(file.getPublicKey(), 4, 0, true, -1, destination.getPath()); queueManager.addQueryToThePendingQueue(clientGet); @@ -292,7 +292,6 @@ for(Iterator it = files.iterator(); it.hasNext(); ) { thaw.plugins.index.File file = (thaw.plugins.index.File)it.next(); - file.addObserver(this); } } @@ -362,16 +361,18 @@ } public void update(java.util.Observable o, Object param) { - if(param instanceof thaw.plugins.index.File) { + /*if(param instanceof thaw.plugins.index.File + && o instanceof thaw.plugins.index.Index) { - /* TODO : It can be a remove ... to check ... */ - thaw.plugins.index.File file = (thaw.plugins.index.File)param; file.deleteObserver(this); - file.addObserver(this); - } + if (((Index)o).isInIndex(file)) + file.addObserver(this); + + }*/ + refresh(); /* TODO : Do it more nicely ... :) */ } } Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2006-10-15 17:21:03 UTC (rev 10663) +++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2006-10-15 21:56:19 UTC (rev 10664) @@ -96,7 +96,7 @@ this.revision = revision; this.author = author; - + treeNode.setUserObject(this); } @@ -189,6 +189,7 @@ } catch(SQLException e) { Logger.error(this, "Unable to rename the index '"+this.displayName+"' in '"+name+"', because: "+e.toString()); } + } public void delete() { @@ -273,7 +274,7 @@ Logger.info(this, "Key asked: "+key); - clientGet = new FCPClientGet(key, 4, 2, false, System.getProperty("java.io.tmpdir")); + clientGet = new FCPClientGet(key, 4, 2, false, 1, System.getProperty("java.io.tmpdir")); transfer = clientGet; clientGet.addObserver(this); @@ -373,6 +374,7 @@ Logger.debug(this, "Index public key: "+publicKey); Logger.debug(this, "Index private key: "+privateKey); + } if(o == transfer) { @@ -424,6 +426,12 @@ } } + + if (o instanceof thaw.plugins.index.File + || o instanceof Link) { + setChanged(); + notifyObservers(o); + } } @@ -456,7 +464,7 @@ while(results.next()) { thaw.plugins.index.File file = new thaw.plugins.index.File(db, results, this); - fileList.add(file); + addFileToList(file); } } @@ -464,6 +472,9 @@ } catch(java.sql.SQLException e) { Logger.warning(this, "Unable to get the file list for index: '"+toString()+"' because: "+e.toString()); } + + setChanged(); + notifyObservers(); } /** @@ -495,22 +506,44 @@ } } + if (fileList != null) { + for (Iterator it = fileList.iterator(); + it.hasNext();) + { + thaw.plugins.index.File file = (thaw.plugins.index.File)it.next(); + file.deleteObserver(this); + } + } + fileList = null; } + /** + * Note for myself: For external use only ! (file will be inserted in the database etc) + */ public void addFile(thaw.plugins.index.File file) { file.setParent(this); file.insert(); - if(fileList != null) { - fileList.add(file); + addFileToList(file); - setChanged(); - notifyObservers(file); - } + setChanged(); + notifyObservers(file); } + + /** + * Won't notify + */ + protected void addFileToList(thaw.plugins.index.File file) { + if (fileList == null) + loadFiles(null, true); + file.addObserver(this); + fileList.add(file); + } + + public void removeFile(thaw.plugins.index.File file) { file.delete(); @@ -545,6 +578,7 @@ setChanged(); notifyObservers(link); } + } public void removeLink(Link link) { @@ -555,6 +589,7 @@ setChanged(); notifyObservers(link); } + } /** @@ -851,10 +886,13 @@ if(list.item(i).getNodeType() == Node.ELEMENT_NODE) { Element e = (Element)list.item(i); - thaw.plugins.index.File file = new thaw.plugins.index.File(db, e, this); - addFile(file); + thaw.plugins.index.File file = new thaw.plugins.index.File(db, e, this); + addFileToList(file); } } + + setChanged(); + notifyObservers(); } @@ -871,4 +909,18 @@ return name; } + + public Vector getIndexIds() { + Vector ids = new Vector(); + ids.add(new Integer(getId())); + return ids; + } + + + public boolean isInIndex(thaw.plugins.index.File file) { + if (fileList == null) + loadFiles(null, true); + return fileList.contains(file); + } + } Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexBrowserPanel.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/IndexBrowserPanel.java 2006-10-15 17:21:03 UTC (rev 10663) +++ trunk/apps/Thaw/src/thaw/plugins/index/IndexBrowserPanel.java 2006-10-15 21:56:19 UTC (rev 10664) @@ -68,16 +68,15 @@ protected void setList(FileAndLinkList l) { - setFileList(l); - setLinkList(l); + tables.setList(l); } - + protected void setFileList(FileList l) { - tables.getFileTable().setFileList(l); + tables.setFileList(l); } protected void setLinkList(LinkList l) { - tables.getLinkTable().setLinkList(l); + tables.setLinkList(l); } Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java 2006-10-15 17:21:03 UTC (rev 10663) +++ trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java 2006-10-15 21:56:19 UTC (rev 10664) @@ -370,6 +370,19 @@ return name; } + public Vector getIndexIds() + { + Vector result = new Vector(); + + for(Iterator it = children.iterator(); + it.hasNext();) { + IndexTreeNode node = (IndexTreeNode)((DefaultMutableTreeNode)it.next()).getUserObject(); + result.addAll(node.getIndexIds()); + } + + return result; + } + public boolean isLeaf() { return false; } Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexEditorPanel.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/IndexEditorPanel.java 2006-10-15 17:21:03 UTC (rev 10663) +++ trunk/apps/Thaw/src/thaw/plugins/index/IndexEditorPanel.java 2006-10-15 21:56:19 UTC (rev 10664) @@ -112,14 +112,14 @@ protected void setLinkList(LinkList l) { buttonsEnabled(l != null && l instanceof Index); this.linkList = l; - tables.getLinkTable().setLinkList(l); + tables.setLinkList(l); } protected void setFileList(FileList l) { buttonsEnabled(l != null && l instanceof Index); this.fileList = l; - tables.getFileTable().setFileList(l); + tables.setFileList(l); } public void valueChanged(javax.swing.event.TreeSelectionEvent e) { Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java 2006-10-15 17:21:03 UTC (rev 10663) +++ trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java 2006-10-15 21:56:19 UTC (rev 10664) @@ -241,6 +241,23 @@ notifyObservers(selectedNode); } + public IndexTreeNode getSelectedNode() { + Object obj = tree.getLastSelectedPathComponent(); + + if (obj == null) + return null; + + if (obj instanceof IndexTreeNode) + return (IndexTreeNode)obj; + + if (obj instanceof DefaultMutableTreeNode) + return ((IndexTreeNode)(((DefaultMutableTreeNode)obj).getUserObject())); + + Logger.notice(this, "getSelectedNode(): Unknow kind of node ?!"); + + return null; + } + public void actionPerformed(ActionEvent e) { if(selectedNode == null) return; Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexTreeNode.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/IndexTreeNode.java 2006-10-15 17:21:03 UTC (rev 10663) +++ trunk/apps/Thaw/src/thaw/plugins/index/IndexTreeNode.java 2006-10-15 21:56:19 UTC (rev 10664) @@ -1,5 +1,7 @@ package thaw.plugins.index; +import java.util.Vector; + import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.MutableTreeNode; @@ -47,5 +49,8 @@ */ public String getKey(); + + public Vector getIndexIds(); + public void addObserver(java.util.Observer o); } Modified: trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java 2006-10-15 17:21:03 UTC (rev 10663) +++ trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java 2006-10-15 21:56:19 UTC (rev 10664) @@ -229,7 +229,7 @@ for(Iterator it = links.iterator(); it.hasNext(); ) { thaw.plugins.index.Link link = (thaw.plugins.index.Link)it.next(); - link.addObserver(this); + //link.addObserver(this); } } @@ -288,8 +288,8 @@ thaw.plugins.index.Link link = (thaw.plugins.index.Link)param; - link.deleteObserver(this); - link.addObserver(this); + //link.deleteObserver(this); + //link.addObserver(this); } refresh(); /* TODO : Do it more nicely ... :) */ Modified: trunk/apps/Thaw/src/thaw/plugins/index/SearchBar.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/SearchBar.java 2006-10-15 17:21:03 UTC (rev 10663) +++ trunk/apps/Thaw/src/thaw/plugins/index/SearchBar.java 2006-10-15 21:56:19 UTC (rev 10664) @@ -7,15 +7,29 @@ import java.awt.BorderLayout; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; + import thaw.core.I18n; -public class SearchBar { +import thaw.plugins.Hsqldb; + +public class SearchBar implements ActionListener { private JPanel panel; private JTextField userText; private JButton validationButton; - public SearchBar(FileTable fileTable, LinkTable linkTable) { + private Hsqldb db; + private IndexTree tree; + + private Tables tables; + + public SearchBar(Hsqldb db, IndexTree indexTree, Tables tables) { + this.db = db; + this.tree = indexTree; + this.tables = tables; + panel = new JPanel(); panel.setLayout(new BorderLayout(10, 10)); @@ -25,10 +39,24 @@ panel.add(new JLabel(I18n.getMessage("thaw.plugin.index.search.label")), BorderLayout.WEST); panel.add(userText, BorderLayout.CENTER); panel.add(validationButton, BorderLayout.EAST); + + userText.addActionListener(this); + validationButton.addActionListener(this); } public JPanel getPanel() { return panel; } + public void actionPerformed(ActionEvent e) { + if (userText.getText() == null) + return; + + if (tree.getSelectedNode() == null) + return; + + SearchResult sr = new SearchResult(db, userText.getText(), tree.getSelectedNode()); + tables.setList(sr); + } + } Modified: trunk/apps/Thaw/src/thaw/plugins/index/SearchResult.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/SearchResult.java 2006-10-15 17:21:03 UTC (rev 10663) +++ trunk/apps/Thaw/src/thaw/plugins/index/SearchResult.java 2006-10-15 21:56:19 UTC (rev 10664) @@ -1,30 +1,160 @@ package thaw.plugins.index; import java.util.Vector; +import java.util.Iterator; +import java.util.Observable; +import java.util.Observer; -public class SearchResult implements FileList { +import java.sql.*; +import thaw.plugins.Hsqldb; + +import thaw.core.Logger; + +public class SearchResult extends Observable implements FileAndLinkList { + private Vector fileList = null; + private Vector linkList = null; - public SearchResult() { + private String[] search = null; + private Vector indexIds = null; + private Hsqldb db; + + public SearchResult(Hsqldb hsqldb, String search, IndexTreeNode node) { + this.search = search.split(" "); + this.indexIds = node.getIndexIds(); + this.db = hsqldb; } + protected PreparedStatement makeSearchQuery(String fields, String table, Vector indexIds, String[] searchPatterns, + String columnToSort, boolean asc) throws SQLException { + String query = ""; + PreparedStatement st; + + query = "SELECT "+fields+" FROM "+table+" WHERE (FALSE"; + + for (Iterator it = indexIds.iterator(); + it.hasNext();) { + it.next(); + query = query + " OR indexParent = ?"; + } + + query = query + ") AND (TRUE"; + + for (int i = 0 ; i < searchPatterns.length; i++) { + query = query + " AND LOWER(publicKey) LIKE ?"; + } + + query = query +")"; + + if(columnToSort != null) { + query = query + "ORDER BY " + columnToSort; + + if(!asc) + query = query + " DESC"; + } + + Connection c = db.getConnection(); + st = c.prepareStatement(query); + + int i; + + i = 1; + + for (Iterator it = indexIds.iterator(); + it.hasNext(); i++) { + st.setInt(i, (Integer)it.next()); + } + + for (int j = 0 ; j < searchPatterns.length; j++) { + st.setString(i+j, "%"+(searchPatterns[j]).toLowerCase()+"%"); + } + + return st; + } + public void loadFiles(String columnToSort, boolean asc) { + if (fileList != null) { + Logger.notice(this, "Files already loaded, won't reload them"); + return; + } + fileList = new Vector(); + + try { + PreparedStatement st = makeSearchQuery("id, publicKey, localPath, mime, size, category, indexParent", + "files", indexIds, search, columnToSort, asc); + if (st.execute()) { + ResultSet results = st.getResultSet(); + + while(results.next()) { + thaw.plugins.index.File file = new thaw.plugins.index.File(db, results, null); + fileList.add(file); + } + } + } catch(SQLException e) { + Logger.warning(this, "Exception while searching: "+e.toString()); + } + + setChanged(); + notifyObservers(); } + public void loadLinks(String columnToSort, boolean asc) { + if (linkList != null) { + Logger.notice(this, "Links already loaded, won't reload them"); + return; + } + linkList = new Vector(); + + try { + PreparedStatement st = makeSearchQuery("id, publicKey, mark, comment, indexTarget, indexParent", + "links", indexIds, search, columnToSort, asc); + if (st.execute()) { + ResultSet results = st.getResultSet(); + + while(results.next()) { + Link link = new Link(db, results, null); + linkList.add(link); + } + } + } catch(SQLException e) { + Logger.warning(this, "Exception while searching: "+e.toString()); + } + + setChanged(); + notifyObservers(); + } + + public Vector getFileList() { return fileList; } + public Vector getLinkList() { + return linkList; + } + + + public thaw.plugins.index.File getFile(int index) { return null; } + public Link getLink(int index) { + return null; + } + + + public void unloadFiles() { fileList = null; - } + } + public void unloadLinks() { + fileList = null; + } + } Modified: trunk/apps/Thaw/src/thaw/plugins/index/TableCreator.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/TableCreator.java 2006-10-15 17:21:03 UTC (rev 10663) +++ trunk/apps/Thaw/src/thaw/plugins/index/TableCreator.java 2006-10-15 21:56:19 UTC (rev 10664) @@ -41,6 +41,8 @@ * Can be safely called, even if the tables already exist. */ public static void createTables(Hsqldb db) { + //sendQuery(db, + // "SET IGNORECASE TRUE"); sendQuery(db, "CREATE CACHED TABLE indexCategories (" + "id INTEGER IDENTITY NOT NULL," Modified: trunk/apps/Thaw/src/thaw/plugins/index/Tables.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/Tables.java 2006-10-15 17:21:03 UTC (rev 10663) +++ trunk/apps/Thaw/src/thaw/plugins/index/Tables.java 2006-10-15 21:56:19 UTC (rev 10664) @@ -25,7 +25,7 @@ fileTable = new FileTable(modifiables, queueManager); linkTable = new LinkTable(modifiables, db, queueManager, tree); - searchBar = new SearchBar(fileTable, linkTable); + searchBar = new SearchBar(db, tree, this); panel.add(searchBar.getPanel(), BorderLayout.NORTH); panel.add(new JSplitPane(JSplitPane.VERTICAL_SPLIT, @@ -34,14 +34,28 @@ } - public FileTable getFileTable() { + protected FileTable getFileTable() { return fileTable; } - public LinkTable getLinkTable() { + protected LinkTable getLinkTable() { return linkTable; } + public void setLinkList(LinkList linkList) { + getLinkTable().setLinkList(linkList); + } + + public void setFileList(FileList fileList) { + getFileTable().setFileList(fileList); + } + + public void setList(FileAndLinkList l) { + setFileList(l); + setLinkList(l); + } + + public JPanel getPanel() { return panel; } From jflesch at freenetproject.org Sun Oct 15 22:01:01 2006 From: jflesch at freenetproject.org (jflesch at freenetproject.org) Date: Sun, 15 Oct 2006 22:01:01 +0000 (UTC) Subject: [Thaw-dev] r10665 - trunk/apps/Thaw/src/thaw/plugins/index Message-ID: <20061015220101.4D1049CCDF@emu.freenetproject.org> Author: jflesch Date: 2006-10-15 22:00:59 +0000 (Sun, 15 Oct 2006) New Revision: 10665 Modified: trunk/apps/Thaw/src/thaw/plugins/index/SearchResult.java Log: Fix 1.4 compatibility Modified: trunk/apps/Thaw/src/thaw/plugins/index/SearchResult.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/SearchResult.java 2006-10-15 21:56:19 UTC (rev 10664) +++ trunk/apps/Thaw/src/thaw/plugins/index/SearchResult.java 2006-10-15 22:00:59 UTC (rev 10665) @@ -65,7 +65,7 @@ for (Iterator it = indexIds.iterator(); it.hasNext(); i++) { - st.setInt(i, (Integer)it.next()); + st.setInt(i, ((Integer)it.next()).intValue()); } for (int j = 0 ; j < searchPatterns.length; j++) { From jflesch at freenetproject.org Sun Oct 15 22:14:34 2006 From: jflesch at freenetproject.org (jflesch at freenetproject.org) Date: Sun, 15 Oct 2006 22:14:34 +0000 (UTC) Subject: [Thaw-dev] r10666 - trunk/apps/Thaw/src/thaw/core Message-ID: <20061015221434.D03199BCF6@emu.freenetproject.org> Author: jflesch Date: 2006-10-15 22:14:33 +0000 (Sun, 15 Oct 2006) New Revision: 10666 Modified: trunk/apps/Thaw/src/thaw/core/PluginManager.java Log: Reactivate index functionality by default Modified: trunk/apps/Thaw/src/thaw/core/PluginManager.java =================================================================== --- trunk/apps/Thaw/src/thaw/core/PluginManager.java 2006-10-15 22:00:59 UTC (rev 10665) +++ trunk/apps/Thaw/src/thaw/core/PluginManager.java 2006-10-15 22:14:33 UTC (rev 10666) @@ -11,9 +11,9 @@ private final static String[] defaultPlugins = {"thaw.plugins.QueueWatcher", "thaw.plugins.InsertPlugin", "thaw.plugins.FetchPlugin", - "thaw.plugins.StatusBar"}; - //"thaw.plugins.IndexEditor", - //"thaw.plugins.IndexBrowser"}; + "thaw.plugins.StatusBar", + "thaw.plugins.IndexEditor", + "thaw.plugins.IndexBrowser"}; private Core core = null; From jflesch at freenetproject.org Tue Oct 17 18:27:14 2006 From: jflesch at freenetproject.org (jflesch at freenetproject.org) Date: Tue, 17 Oct 2006 18:27:14 +0000 (UTC) Subject: [Thaw-dev] r10667 - in trunk/apps/Thaw/src/thaw: fcp plugins/index Message-ID: <20061017182714.781E120AFA5@emu.freenetproject.org> Author: jflesch Date: 2006-10-17 18:27:11 +0000 (Tue, 17 Oct 2006) New Revision: 10667 Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java trunk/apps/Thaw/src/thaw/plugins/index/Index.java Log: Correct type conversion in FCPClientGet Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java =================================================================== --- trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java 2006-10-15 22:14:33 UTC (rev 10666) +++ trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java 2006-10-17 18:27:11 UTC (rev 10667) @@ -357,9 +357,9 @@ if(message.getValue("Total") != null && message.getValue("Succeeded") != null) { - fileSize = ((new Long(message.getValue("Total"))).longValue())*BLOCK_SIZE; - long required = (new Long(message.getValue("Total"))).longValue(); - long succeeded = (new Long(message.getValue("Succeeded"))).longValue(); + fileSize = Long.parseLong(message.getValue("Total"))*BLOCK_SIZE; + long required = Long.parseLong(message.getValue("Total")); + long succeeded = Long.parseLong(message.getValue("Succeeded")); progress = (int) ((long)((succeeded * 98) / required)); Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2006-10-15 22:14:33 UTC (rev 10666) +++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2006-10-17 18:27:11 UTC (rev 10667) @@ -422,6 +422,8 @@ if (transfer.isFinished() && !transfer.isSuccessful()) { Logger.info(this, "Unable to get new version of the index"); transfer = null; + setChanged(); + notifyObservers(); return; } From jflesch at freenetproject.org Tue Oct 17 21:38:42 2006 From: jflesch at freenetproject.org (jflesch at freenetproject.org) Date: Tue, 17 Oct 2006 21:38:42 +0000 (UTC) Subject: [Thaw-dev] r10668 - trunk/apps/Thaw/src/thaw/fcp Message-ID: <20061017213842.B6B899BE52@emu.freenetproject.org> Author: jflesch Date: 2006-10-17 21:38:40 +0000 (Tue, 17 Oct 2006) New Revision: 10668 Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java Log: Fix typo Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java =================================================================== --- trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java 2006-10-17 18:27:11 UTC (rev 10667) +++ trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java 2006-10-17 21:38:40 UTC (rev 10668) @@ -531,8 +531,8 @@ duplicatedQueryManager = queueManager.getQueryManager().duplicate(identifier); duplicatedQueryManager.addObserver(this); - Logger.info(this, "Waiting for socket avaibility ..."); - status = "Waiting for socket avaibility ..."; + Logger.info(this, "Waiting for socket ..."); + status = "Waiting for socket availability ..."; progress = 99; running = true; From jflesch at freenetproject.org Wed Oct 18 06:05:59 2006 From: jflesch at freenetproject.org (jflesch at freenetproject.org) Date: Wed, 18 Oct 2006 06:05:59 +0000 (UTC) Subject: [Thaw-dev] r10669 - trunk/apps/Thaw/src/thaw/fcp Message-ID: <20061018060559.DA2A39BF1F@emu.freenetproject.org> Author: jflesch Date: 2006-10-18 06:05:57 +0000 (Wed, 18 Oct 2006) New Revision: 10669 Modified: trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java Log: Fix NPE Modified: trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java =================================================================== --- trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java 2006-10-17 21:38:40 UTC (rev 10668) +++ trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java 2006-10-18 06:05:57 UTC (rev 10669) @@ -356,8 +356,14 @@ return rdBytes; } catch(java.io.IOException e) { - Logger.error(this, "IOException while reading raw bytes on socket => disconnection"); - Logger.error(this, e.getMessage() + ":" +e.getCause().toString()+ " ; "+e.getMessage() ); + Logger.error(this, "IOException while reading raw bytes on socket => disconnection:"); + Logger.error(this, " ========="); + Logger.error(this, e.getMessage() + ":"); + if (e.getCause() != null) + Logger.error(this, e.getCause().toString()); + Logger.error(this, e.getMessage() ); + Logger.error(this, " ========="); + disconnect(); return -2; /* -1 can mean eof */ } From jflesch at freenetproject.org Wed Oct 18 18:37:22 2006 From: jflesch at freenetproject.org (jflesch at freenetproject.org) Date: Wed, 18 Oct 2006 18:37:22 +0000 (UTC) Subject: [Thaw-dev] r10670 - trunk/apps/Thaw/src/thaw/plugins/index Message-ID: <20061018183722.A18709C754@emu.freenetproject.org> Author: jflesch Date: 2006-10-18 18:37:20 +0000 (Wed, 18 Oct 2006) New Revision: 10670 Modified: trunk/apps/Thaw/src/thaw/plugins/index/File.java trunk/apps/Thaw/src/thaw/plugins/index/Index.java trunk/apps/Thaw/src/thaw/plugins/index/Link.java Log: Fix index loading (yes, again.) Modified: trunk/apps/Thaw/src/thaw/plugins/index/File.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/File.java 2006-10-18 06:05:57 UTC (rev 10669) +++ trunk/apps/Thaw/src/thaw/plugins/index/File.java 2006-10-18 18:37:20 UTC (rev 10670) @@ -278,6 +278,39 @@ } } + + public boolean isInTheDatabase() { + if (parent == null) { + Logger.notice(this, "isInTheDatabase(): No parent !"); + return false; + } + + try { + PreparedStatement st; + + st = db.getConnection().prepareStatement("SELECT publicKey from files WHERE publicKey = ? AND indexParent = ?"); + + if(publicKey != null) + st.setString(1, publicKey); + else + st.setString(1, fileName); + + st.setInt(2, getParent().getId()); + + if(st.execute()) { + ResultSet result = st.getResultSet(); + if (result != null && result.next()) { + return true; + } + } + + } catch(SQLException e) { + + } + + return false; + } + public void update(java.util.Observable o, Object param) { if(o == transfer) { Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2006-10-18 06:05:57 UTC (rev 10669) +++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2006-10-18 18:37:20 UTC (rev 10670) @@ -372,7 +372,7 @@ publicKey = sskGenerator.getPublicKey(); privateKey = sskGenerator.getPrivateKey(); - Logger.debug(this, "Index public key: "+publicKey); + Logger.debug(this, "Index public key: " +publicKey); Logger.debug(this, "Index private key: "+privateKey); } @@ -526,12 +526,15 @@ */ public void addFile(thaw.plugins.index.File file) { file.setParent(this); - file.insert(); - addFileToList(file); + if (!file.isInTheDatabase()) { + file.insert(); - setChanged(); - notifyObservers(file); + addFileToList(file); + + setChanged(); + notifyObservers(file); + } } @@ -572,13 +575,16 @@ public void addLink(Link link) { link.setParent(this); - link.insert(); - if (linkList != null) { - linkList.add(link); + if (!link.isInTheDatabase()) { + link.insert(); - setChanged(); - notifyObservers(link); + if (linkList != null) { + linkList.add(link); + + setChanged(); + notifyObservers(link); + } } } @@ -633,7 +639,7 @@ while(results.next()) { try { Link link = new Link(db, results, this); - linkList.add(link); + addLink(link); } catch(Exception e) { Logger.warning(this, "Unable to add index '"+publicKey+"' to the list because: "+e.toString()); } @@ -889,7 +895,7 @@ Element e = (Element)list.item(i); thaw.plugins.index.File file = new thaw.plugins.index.File(db, e, this); - addFileToList(file); + addFile(file); } } Modified: trunk/apps/Thaw/src/thaw/plugins/index/Link.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/Link.java 2006-10-18 06:05:57 UTC (rev 10669) +++ trunk/apps/Thaw/src/thaw/plugins/index/Link.java 2006-10-18 18:37:20 UTC (rev 10670) @@ -119,6 +119,37 @@ } + + public boolean isInTheDatabase() { + if (parent == null) { + Logger.notice(this, "isInTheDatabase(): No parent !"); + return false; + } + + try { + PreparedStatement st; + + st = db.getConnection().prepareStatement("SELECT publicKey from links WHERE publicKey = ? AND indexParent = ?"); + + st.setString(1, key); + + st.setInt(2, getParent().getId()); + + if(st.execute()) { + ResultSet result = st.getResultSet(); + if (result != null && result.next()) { + return true; + } + } + + } catch(SQLException e) { + Logger.error(this, "Unable to check if link '"+key+"' exists because: "+e.toString()); + } + + return false; + } + + public void delete() { try { PreparedStatement st; From jflesch at freenetproject.org Wed Oct 18 20:11:57 2006 From: jflesch at freenetproject.org (jflesch at freenetproject.org) Date: Wed, 18 Oct 2006 20:11:57 +0000 (UTC) Subject: [Thaw-dev] r10671 - trunk/apps/Thaw/src/thaw/plugins/index Message-ID: <20061018201157.E0E319C77D@emu.freenetproject.org> Author: jflesch Date: 2006-10-18 20:11:56 +0000 (Wed, 18 Oct 2006) New Revision: 10671 Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java Log: Fix link display Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2006-10-18 18:37:20 UTC (rev 10670) +++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2006-10-18 20:11:56 UTC (rev 10671) @@ -531,10 +531,12 @@ file.insert(); addFileToList(file); - + setChanged(); notifyObservers(file); } + else + Logger.notice(this, "File already in the database for this index"); } @@ -579,16 +581,22 @@ if (!link.isInTheDatabase()) { link.insert(); - if (linkList != null) { - linkList.add(link); - - setChanged(); - notifyObservers(link); - } + addLinkToList(link); + setChanged(); + notifyObservers(link); } + else + Logger.notice(this, "Link already in the database for this index"); } + protected void addLinkToList(Link link) { + if (linkList == null) + loadLinks(null, true); + + linkList.add(link); + } + public void removeLink(Link link) { link.delete(); @@ -639,7 +647,7 @@ while(results.next()) { try { Link link = new Link(db, results, this); - addLink(link); + addLinkToList(link); } catch(Exception e) { Logger.warning(this, "Unable to add index '"+publicKey+"' to the list because: "+e.toString()); } From jflesch at freenetproject.org Thu Oct 19 19:32:26 2006 From: jflesch at freenetproject.org (jflesch at freenetproject.org) Date: Thu, 19 Oct 2006 19:32:26 +0000 (UTC) Subject: [Thaw-dev] r10675 - in trunk/apps/Thaw/src/thaw: core i18n plugins/index Message-ID: <20061019193226.091C39BCC7@emu.freenetproject.org> Author: jflesch Date: 2006-10-19 19:32:18 +0000 (Thu, 19 Oct 2006) New Revision: 10675 Modified: trunk/apps/Thaw/src/thaw/core/MainWindow.java trunk/apps/Thaw/src/thaw/i18n/thaw.properties trunk/apps/Thaw/src/thaw/plugins/index/Index.java trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java Log: Add translator names to the 'About' dialog Modified: trunk/apps/Thaw/src/thaw/core/MainWindow.java =================================================================== --- trunk/apps/Thaw/src/thaw/core/MainWindow.java 2006-10-19 16:30:37 UTC (rev 10674) +++ trunk/apps/Thaw/src/thaw/core/MainWindow.java 2006-10-19 19:32:18 UTC (rev 10675) @@ -366,7 +366,10 @@ new JLabel(I18n.getMessage("thaw.about.l3")), new JLabel(I18n.getMessage("thaw.about.l4")), new JLabel(""), - new JLabel(I18n.getMessage("thaw.about.l6")) + new JLabel(I18n.getMessage("thaw.about.l6")), + new JLabel(""), + new JLabel(I18n.getMessage("thaw.about.l7")), + new JLabel(I18n.getMessage("thaw.about.l8")) }; labels[0].setFont(new Font("Dialog", Font.BOLD, 30)); Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties =================================================================== --- trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2006-10-19 16:30:37 UTC (rev 10674) +++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2006-10-19 19:32:18 UTC (rev 10675) @@ -180,8 +180,9 @@ thaw.about.l3=2006(c) Freenet Project Incorporated thaw.about.l4=under GPLv2 thaw.about.l6=Icon theme "Gorilla" created by Jimmac (http://jimmac.musichall.cz/icons.php) +thaw.about.l7=French translation: Sylvain Petreolle +thaw.about.l8=German translation: Michael Helmling - ## HsqlDb thaw.plugin.hsqldb.database=Database thaw.plugin.hsqldb.console=Sql console Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2006-10-19 16:30:37 UTC (rev 10674) +++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2006-10-19 19:32:18 UTC (rev 10675) @@ -63,17 +63,15 @@ private String author = null; - private boolean freshIndex = false; /** * The bigest constructor of the world ... - * @param fresh If set to true, won't increment revision for the next update */ public Index(Hsqldb db, FCPQueueManager queueManager, int id, IndexCategory parent, String realName, String displayName, String publicKey, String privateKey, - int revision, String author, boolean fresh, + int revision, String author, boolean modifiable) { this.queueManager = queueManager; @@ -82,7 +80,6 @@ this.db = db; this.tree = tree; - this.freshIndex = fresh; this.id = id; this.parent = parent; this.realName = realName; @@ -249,7 +246,7 @@ revision++; - clientPut = new FCPClientPut(targetFile, 2, revision, toString(), privateKey, 4, false, 2); + clientPut = new FCPClientPut(targetFile, 2, revision, toString(), privateKey, 4, false, 0); transfer = clientPut; clientPut.addObserver(this); @@ -267,11 +264,13 @@ String key; - if (!freshIndex) + if (!isEmpty()) key = changeRevision(publicKey, 1); else key = publicKey; + //key = key.replaceFirst("USK@", "SSK@"); + Logger.info(this, "Key asked: "+key); clientGet = new FCPClientGet(key, 4, 2, false, 1, System.getProperty("java.io.tmpdir")); @@ -397,7 +396,7 @@ java.io.File file = new java.io.File(transfer.getPath()); Logger.info(this, "Updating index ..."); - + publicKey = transfer.getFileKey(); Logger.info(this, "Most up-to-date key found: " + publicKey); @@ -437,6 +436,19 @@ } + public boolean isEmpty() { + if (fileList == null) + loadFiles(null, true); + if (linkList == null) + loadLinks(null, true); + + if (fileList.size() == 0 && linkList.size() == 0) + return true; + + return false; + } + + ////// FILE LIST //////// public void loadFiles(String columnToSort, boolean asc) { Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java 2006-10-19 16:30:37 UTC (rev 10674) +++ trunk/apps/Thaw/src/thaw/plugins/index/IndexCategory.java 2006-10-19 19:32:18 UTC (rev 10675) @@ -287,7 +287,7 @@ set(children, position, (new Index(db, queueManager, id, this, realName, displayName, publicKey, privateKey, revision, - author, false, + author, modifiables)).getTreeNode()); } } catch (java.sql.SQLException e) { Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java 2006-10-19 16:30:37 UTC (rev 10674) +++ trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java 2006-10-19 19:32:18 UTC (rev 10675) @@ -289,7 +289,7 @@ IndexCategory parent = (IndexCategory)selectedNode; - Index index = new Index(db, queueManager, -2, parent, name, name, publicKey, null, 0, null, true, modifiables); + Index index = new Index(db, queueManager, -2, parent, name, name, publicKey, null, 0, null, modifiables); if(modifiables) index.generateKeys(queueManager); Modified: trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java 2006-10-19 16:30:37 UTC (rev 10674) +++ trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java 2006-10-19 19:32:18 UTC (rev 10675) @@ -160,7 +160,7 @@ Link link = (Link)links.get(selectedRows[i]); Index index = new Index(db, queueManager, -2, null, Index.getNameFromKey(link.getKey()), Index.getNameFromKey(link.getKey()), link.getKey(), null, - 0, null, true, false); + 0, null, false); index.create(); indexTree.addToRoot(index); } From jflesch at freenetproject.org Thu Oct 19 21:11:46 2006 From: jflesch at freenetproject.org (jflesch at freenetproject.org) Date: Thu, 19 Oct 2006 21:11:46 +0000 (UTC) Subject: [Thaw-dev] r10676 - trunk/apps/Thaw/src/thaw/plugins/index Message-ID: <20061019211146.2DD069BC2F@emu.freenetproject.org> Author: jflesch Date: 2006-10-19 21:11:44 +0000 (Thu, 19 Oct 2006) New Revision: 10676 Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java Log: Thaw will trust the node to discover the new revision of an index Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2006-10-19 19:32:18 UTC (rev 10675) +++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java 2006-10-19 21:11:44 UTC (rev 10676) @@ -264,13 +264,17 @@ String key; - if (!isEmpty()) - key = changeRevision(publicKey, 1); - else - key = publicKey; + /* We will trust the node for the incrementation */ + /* + if (!isEmpty()) + key = changeRevision(publicKey, 1); + else + key = publicKey; + */ - //key = key.replaceFirst("USK@", "SSK@"); + key = publicKey; + Logger.info(this, "Key asked: "+key); clientGet = new FCPClientGet(key, 4, 2, false, 1, System.getProperty("java.io.tmpdir")); From jflesch at freenetproject.org Thu Oct 19 22:16:16 2006 From: jflesch at freenetproject.org (jflesch at freenetproject.org) Date: Thu, 19 Oct 2006 22:16:16 +0000 (UTC) Subject: [Thaw-dev] r10677 - in trunk/apps/Thaw: images src/thaw/core src/thaw/plugins/index Message-ID: <20061019221616.137E89C74F@emu.freenetproject.org> Author: jflesch Date: 2006-10-19 22:16:13 +0000 (Thu, 19 Oct 2006) New Revision: 10677 Added: trunk/apps/Thaw/images/index-new.png Modified: trunk/apps/Thaw/src/thaw/core/IconBox.java trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java Log: Add a toolbar in the index browser / editor Added: trunk/apps/Thaw/images/index-new.png =================================================================== (Binary files differ) Property changes on: trunk/apps/Thaw/images/index-new.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-10-19 21:11:44 UTC (rev 10676) +++ trunk/apps/Thaw/src/thaw/core/IconBox.java 2006-10-19 22:16:13 UTC (rev 10677) @@ -39,7 +39,10 @@ public static ImageIcon makeALinkAction; public static ImageIcon minIndex; + public static ImageIcon indexNew; + public static ImageIcon refreshAction; + public static ImageIcon clearAction; public static ImageIcon settings; @@ -93,6 +96,8 @@ minIndex = new ImageIcon((new IconBox()).getClass().getClassLoader().getResource("index.png")); + indexNew = + new ImageIcon((new IconBox()).getClass().getClassLoader().getResource("index-new.png")); downloads = new ImageIcon((new IconBox()).getClass().getClassLoader().getResource("go-first.png")); @@ -132,6 +137,9 @@ minReconnectAction = new ImageIcon((new IconBox()).getClass().getClassLoader().getResource("min-view-refresh.png")); + refreshAction = + new ImageIcon((new IconBox()).getClass().getClassLoader().getResource("index-refresh.png")); + quitAction = new ImageIcon((new IconBox()).getClass().getClassLoader().getResource("system-log-out.png")); minQuitAction = Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java =================================================================== --- trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java 2006-10-19 21:11:44 UTC (rev 10676) +++ trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java 2006-10-19 22:16:13 UTC (rev 10677) @@ -38,6 +38,11 @@ import java.awt.Color; + +import javax.swing.JToolBar; +import javax.swing.JButton; + + import thaw.plugins.Hsqldb; import thaw.core.*; import thaw.fcp.*; @@ -55,6 +60,10 @@ private JTree tree; private IndexCategory root; + private JToolBar toolBar; + private JButton newIndex; + private JButton refreshAll; + private JPopupMenu indexCategoryMenu; private JPopupMenu indexMenu; @@ -174,7 +183,31 @@ if (selectionOnly) tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); - panel.add(new JScrollPane(tree)); + + + toolBar = new JToolBar(); + + newIndex = new JButton(IconBox.indexNew); + if (!modifiables) + newIndex.setToolTipText(I18n.getMessage("thaw.plugin.index.addIndex")); + else + newIndex.setToolTipText(I18n.getMessage("thaw.plugin.index.createIndex")); + newIndex.addActionListener(this); + + + if (!modifiables) { + refreshAll = new JButton(IconBox.refreshAction); + refreshAll.setToolTipText(I18n.getMessage("thaw.plugin.index.downloadIndexes")); + refreshAll.addActionListener(this); + } + + + toolBar.add(newIndex); + if (!modifiables) + toolBar.add(refreshAll); + + panel.add(toolBar, BorderLayout.NORTH); + panel.add(new JScrollPane(tree), BorderLayout.CENTER); } @@ -260,9 +293,10 @@ public void actionPerformed(ActionEvent e) { if(selectedNode == null) - return; + selectedNode = root; - if(e.getSource() == addIndex) { + if(e.getSource() == addIndex + || e.getSource() == newIndex) { String name = null; String publicKey = null; @@ -287,8 +321,13 @@ if(name == null) return; - IndexCategory parent = (IndexCategory)selectedNode; + IndexCategory parent; + if (e.getSource() == addIndex) + parent = (IndexCategory)selectedNode; + else + parent = root; + Index index = new Index(db, queueManager, -2, parent, name, name, publicKey, null, 0, null, modifiables); if(modifiables) @@ -358,6 +397,10 @@ || e.getSource() == updateIndexCategory) { selectedNode.update(); } + + if (e.getSource() == refreshAll) { + root.update(); + } if(e.getSource() == copyKey || e.getSource() == copyKeys) { From jflesch at freenetproject.org Fri Oct 20 06:19:17 2006 From: jflesch at freenetproj