Author: jflesch
Date: 2007-04-18 14:04:50 +0000 (Wed, 18 Apr 2007)
New Revision: 12772

Modified:
   trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java
   trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java
   trunk/apps/Thaw/src/thaw/gui/IconBox.java
   trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
   trunk/apps/Thaw/src/thaw/i18n/thaw.properties
   trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
   trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java
   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/IndexManagementHelper.java
   trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java
Log:
Changing the way the hash are computed for the insertions

Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java      2007-04-18 13:17:23 UTC 
(rev 12771)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPClientGet.java      2007-04-18 14:04:50 UTC 
(rev 12772)
@@ -415,29 +415,21 @@

                        final int code = 
Integer.parseInt(message.getValue("Code"));

-                       if((maxRetries == -1) || (attempt >= maxRetries) || 
(code == 25)) {
-                           status = "Failed 
("+message.getValue("CodeDescription")+")";
-                           progress = 100;
-                           running = false;
-                           successful = false;
+                       status = "Failed 
("+message.getValue("CodeDescription")+")";
+                       progress = 100;
+                       running = false;
+                       successful = false;

-                           fatal = true;
+                       fatal = true;

-                           if((message.getValue("Fatal") != null) &&
-                              message.getValue("Fatal").equals("false")) {
-                                   fatal = false;
-                                   status = status + " (non-fatal)";
-                           }
-
-                           queueManager.getQueryManager().deleteObserver(this);
-                       } else {
-                           status = "Retrying";
-                           running = true;
-                           successful = true;
-                           progress = 0;
-                           start(queueManager);
+                       if((message.getValue("Fatal") != null) &&
+                          message.getValue("Fatal").equals("false")) {
+                               fatal = false;
+                               status = status + " (non-fatal)";
                        }

+                       queueManager.getQueryManager().deleteObserver(this);
+
                        setChanged();
                        this.notifyObservers();


Modified: trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java      2007-04-18 13:17:23 UTC 
(rev 12771)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPClientPut.java      2007-04-18 14:04:50 UTC 
(rev 12772)
@@ -206,8 +206,10 @@
                if 
(queueManager.getQueryManager().getConnection().isLocalSocket() && localFile != 
null) {
                        status = "Computing hash to get approval from the node 
...";

+                       identifier = queueManager.getAnID() + "-"+ 
localFile.getName();
+
                        String salt = 
queueManager.getQueryManager().getConnection().getClientHello().getConnectionId()
-                               +"-"+ localFile.getPath() /* Client token */
+                               +"-"+ identifier
                                +"-";
                        Logger.info(this, "Salt used for this transfer: ~" + 
salt+ "~");

@@ -298,7 +300,7 @@

                status = "Sending to the node";

-               if(identifier == null) {
+               if(identifier == null) { /* see start() ; when computing hash */
                        if (localFile != null)
                                identifier = queueManager.getAnID() + "-"+ 
localFile.getName();
                        else
@@ -844,15 +846,22 @@
        public String getInsertionKey() {
                String key = null;

-               if((keyType == 0) && (publicKey != null))
+               if ((keyType == 0) && (publicKey != null))
                        key = publicKey;
-               if((keyType == 0) && (publicKey == null))
+               if ((keyType == 0) && (publicKey == null))
                        key = "CHK@";
-               if(keyType == 1)
+               if (keyType == 1)
                        key = "KSK@" + name + "-"+ Integer.toString(rev);
-               if(keyType == 2)
+               if (keyType == 2 && privateKey.startsWith("SSK"))
                        key = privateKey + name+"-"+rev;
+               if (keyType == 2 && privateKey.startsWith("USK"))
+                       key = privateKey + name + "/" + rev;

+               if (key == null) {
+                       Logger.warning(this, "Unknown key type ?! May result in 
a strange behavior !");
+                       return privateKey;
+               }
+
                return key;
        }


Modified: trunk/apps/Thaw/src/thaw/gui/IconBox.java
===================================================================
--- trunk/apps/Thaw/src/thaw/gui/IconBox.java   2007-04-18 13:17:23 UTC (rev 
12771)
+++ trunk/apps/Thaw/src/thaw/gui/IconBox.java   2007-04-18 14:04:50 UTC (rev 
12772)
@@ -222,7 +222,7 @@
                IconBox.link                = 
IconBox.loadIcon("indexBrowser.png");
                IconBox.minLink             = 
IconBox.loadIcon("min-indexBrowser.png");
                IconBox.minIndexSettings    = 
IconBox.loadIcon("min-indexSettings.png");
-               IconBox.indexSettings       = 
IconBox.loadIcon("min-indexSettings.png");
+               IconBox.indexSettings       = 
IconBox.loadIcon("indexSettings.png");
        }

 }

Modified: trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties     2007-04-18 
13:17:23 UTC (rev 12771)
+++ trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties     2007-04-18 
14:04:50 UTC (rev 12772)
@@ -287,7 +287,9 @@

 thaw.plugin.index.addKeys=Ajouter des clefs sp?cifiques
 thaw.plugin.index.changeIndexKeys=Changer les clefs de l'index
+thaw.plugin.index.indexSettings=Changer les r?glages de l'index
 thaw.plugin.index.unknownIndexes=Indexes inconnus:
+thaw.plugin.index.allowComments=Commentaires autoris?s

 thaw.plugin.index.importIndex=Importer le contenu de l'index depuis un fichier
 thaw.plugin.index.exportIndex=Exporter le contenu de l'index vers un fichier

Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2007-04-18 13:17:23 UTC 
(rev 12771)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2007-04-18 14:04:50 UTC 
(rev 12772)
@@ -279,7 +279,9 @@

 thaw.plugin.index.addKeys=Add specific key(s)
 thaw.plugin.index.changeIndexKeys=Change the index keys
+thaw.plugin.index.indexSettings=Change the ndex settings
 thaw.plugin.index.unknownIndexes=Unknown indexes:
+thaw.plugin.index.allowComments=Comments allowed

 thaw.plugin.index.importIndex=Import index content from a file
 thaw.plugin.index.exportIndex=Export index content to a file

Modified: trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties    2007-04-18 13:17:23 UTC 
(rev 12771)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties    2007-04-18 14:04:50 UTC 
(rev 12772)
@@ -287,7 +287,9 @@

 thaw.plugin.index.addKeys=Ajouter des clefs sp\u00e9cifiques
 thaw.plugin.index.changeIndexKeys=Changer les clefs de l'index
+thaw.plugin.index.indexSettings=Changer les r\u00e9glages de l'index
 thaw.plugin.index.unknownIndexes=Indexes inconnus:
+thaw.plugin.index.allowComments=Commentaires autoris\u00e9s

 thaw.plugin.index.importIndex=Importer le contenu de l'index depuis un fichier
 thaw.plugin.index.exportIndex=Exporter le contenu de l'index vers un fichier

Modified: trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java 2007-04-18 
13:17:23 UTC (rev 12771)
+++ trunk/apps/Thaw/src/thaw/plugins/index/DatabaseManager.java 2007-04-18 
14:04:50 UTC (rev 12772)
@@ -62,7 +62,7 @@
  *  |-- indexFolders (id, name, positionInTree)
  *  | |-- [...]
  *  |
- *  |-- indexes (id, realName, displayName, publicKey, [privateKey], 
positionInTree, newRev, publishPrivateKey (0/1))
+ *  |-- indexes (id, realName, displayName, publicKey, [privateKey], 
positionInTree, ...)
  *    |-- links (id, indexName, indexPublicKey)
  *    |-- files (id, filename, publicKey, mime, size)
  *      |-- metadatas (id, name, value)
@@ -94,7 +94,7 @@

                if (config.getValue("indexDatabaseVersion") == null) {
                        newDb = true;
-                       config.setValue("indexDatabaseVersion", "4");
+                       config.setValue("indexDatabaseVersion", "5");
                } else {

                        /* CONVERTIONS */
@@ -123,6 +123,13 @@
                                        config.setValue("indexDatabaseVersion", 
"4");
                        }

+                       if 
("4".equals(config.getValue("indexDatabaseVersion"))) {
+                               if (splashScreen != null)
+                                       splashScreen.setStatus("Converting 
database ...");
+                               if (convertDatabase_4_to_5(db))
+                                       config.setValue("indexDatabaseVersion", 
"5");
+                       }
+
                        /* ... */
                }

@@ -162,6 +169,7 @@
                          + "positionInTree INTEGER NOT NULL, "
                          + "revision INTEGER NOT NULL, "
                          + "newRev BOOLEAN DEFAULT FALSE NOT NULL, "
+                         + "newCommment BOOLEAN DEFAULT FALSE NOT NULL, "
                          + "parent INTEGER NULL, " /* direct parent */
                          + "PRIMARY KEY (id), "
                          + "FOREIGN KEY (parent) REFERENCES indexFolders 
(id))");
@@ -184,6 +192,7 @@
                //+ "FOREIGN KEY (parentId) REFERENCES indexFolders (id))");


+               /* not used at the moment */
                sendQuery(db,
                          "CREATE CACHED TABLE categories ("
                          + "id INTEGER IDENTITY NOT NULL,"
@@ -241,6 +250,23 @@
                          + "id INTEGER IDENTITY NOT NULL,"
                          + "publicKey VARCHAR(350) NOT NULL,"
                          + "name VARCHAR(255) NOT NULL)");
+
+               sendQuery(db,
+                         "CREATE CACHED TABLE indexCommentKeys ("
+                         + "id INTEGER IDENTITY NOT NULL,"
+                         + "publicKey VARCHAR(255) NOT NULL,"
+                         + "privateKey VARCHAR(255) NOT NULL,"
+                         + "indexId INTEGER NOT NULL,"
+                         + "FOREIGN KEY (indexId) REFERENCES indexes (id))");
+
+               sendQuery(db,
+                         "CREATE CACHED TABLE indexComments ("
+                         + "id INTEGER IDENTITY NOT NULL,"
+                         + "author VARCHAR(255) NOT NULL,"
+                         + "text VARCHAR(16384) NOT NULL," /* 16 KB */
+                         + "rev INTEGER NOT NULL,"
+                         + "indexId INTEGER NOT NULL,"
+                         + "FOREIGN KEY (indexId) REFERENCES indexes (id))");
        }


@@ -254,7 +280,17 @@
                sendQuery(db, "DROP TABLE links");

                sendQuery(db, "DROP TABLE indexes");
-               sendQuery(db, "DROP TABLE indexCategories");
+               sendQuery(db, "DROP TABLE indexFolders");
+
+               sendQuery(db, "DROP TABLE indexParents");
+               sendQuery(db, "DROP TABLE folderParents");
+
+               sendQuery(db, "DROP TABLE indexCommentKeys");
+               sendQuery(db, "DROP TABLE indexComments");
+
+               sendQuery(db, "DROP TABLE categories");
+
+               sendQuery(db, "DROP TABLE indexBlackList");
        }


@@ -872,4 +908,13 @@

                return true;
        }
+
+       public static boolean convertDatabase_4_to_5(Hsqldb db) {
+               if (!sendQuery(db, "ALTER TABLE indexes ADD COLUMN newComment 
BOOLEAN DEFAULT false")) {
+                       Logger.error(new DatabaseManager(), "Error while 
converting the database (3 to 4) ! (adding column to index table)");
+                       return false;
+               }
+
+               return true;
+       }
 }

Modified: trunk/apps/Thaw/src/thaw/plugins/index/File.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/File.java    2007-04-18 13:17:23 UTC 
(rev 12771)
+++ trunk/apps/Thaw/src/thaw/plugins/index/File.java    2007-04-18 14:04:50 UTC 
(rev 12772)
@@ -162,7 +162,15 @@
                if (filename == null)
                        reloadDataFromDb(id);

-               return filename;
+               String res;
+
+               try {
+                       res = java.net.URLDecoder.decode(filename, "UTF-8");
+               } catch (final java.io.UnsupportedEncodingException e) {
+                       res = filename;
+               }
+
+               return res;
        }

        public long getSize() {

Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Index.java   2007-04-18 13:17:23 UTC 
(rev 12771)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java   2007-04-18 14:04:50 UTC 
(rev 12772)
@@ -53,14 +53,16 @@
 import javax.xml.parsers.SAXParser;


+import thaw.core.I18n;
+import thaw.core.Logger;

 import thaw.fcp.FreenetURIHelper;
-import thaw.core.I18n;
-import thaw.core.Logger;
 import thaw.fcp.FCPClientGet;
 import thaw.fcp.FCPClientPut;
 import thaw.fcp.FCPQueueManager;
 import thaw.fcp.FCPTransferQuery;
+import thaw.fcp.FCPGenerateSSK;
+
 import thaw.plugins.Hsqldb;
 import thaw.plugins.insertPlugin.DefaultMIMETypes;

@@ -743,10 +745,6 @@

                String key;

-               /* We will trust the node for the incrementation
-                  execept if a rev is specified */
-
-
                if (specificRev >= 0) {
                        key = FreenetURIHelper.convertUSKtoSSK(publicKey);
                        key = FreenetURIHelper.changeSSKRevision(key, 
specificRev, 0);
@@ -987,6 +985,9 @@
                rootEl.appendChild(getXMLLinks(xmlDoc));
                rootEl.appendChild(getXMLFileList(xmlDoc));

+               if (canHaveComments())
+                       rootEl.appendChild(getXMLCommentInfos(xmlDoc));
+
                return true;
        }

@@ -1104,6 +1105,23 @@



+       public Element getXMLCommentInfos(final Document xmlDoc) {
+               final Element infos = xmlDoc.createElement("comments");
+
+               infos.setAttribute("publicKey", getCommentPublicKey());
+               infos.setAttribute("privateKey", getCommentPrivateKey());
+
+               /* TODO : Black list */
+
+               return infos;
+       }
+
+
+
+
+       /*********** INDEX LOADING **************/
+
+
        public void loadXML(final String filePath) {
                loadXML(filePath, true);
        }
@@ -1158,14 +1176,6 @@
                }

                /**
-                * Called when parsing is finished
-                * @see org.xml.sax.ContentHandler#endDocument()
-                */
-               public void endDocument() throws SAXException {
-                       /* \_o< */
-               }
-
-               /**
                 * Called when starting to parse in a specific name space
                 * @param prefix name space prefix
                 * @param URI name space URI
@@ -1188,6 +1198,8 @@
                private boolean ownerTag = false;
                private boolean privateKeyTag = false;

+               private boolean hasCommentTag = false;
+
                private PreparedStatement insertFileSt = null;
                private PreparedStatement insertLinkSt = null;

@@ -1285,6 +1297,20 @@

                        }

+
+                       if ("comments".equals(rawName)) {
+                               String pub = attrs.getValue("publicKey");
+                               String priv = attrs.getValue("privateKey");
+
+                               if (pub != null && priv != null) {
+                                       hasCommentTag = true;
+                                       Logger.debug(this, "Comment allowed in 
this index");
+                                       setCommentKeys(pub, priv);
+                               }
+                       }
+
+
+
                        /* ignore unknown tags */

                        /* et paf ! Ca fait des Chocapics(tm)(r)(c)(m)(dtc) ! */
@@ -1363,6 +1389,17 @@

                }

+
+               /**
+                * Called when parsing is finished
+                * @see org.xml.sax.ContentHandler#endDocument()
+                */
+               public void endDocument() throws SAXException {
+                       if (!hasCommentTag) {
+                               Logger.debug(this, "No comment allowed in this 
index");
+                               purgeCommentKeys();
+                       }
+               }
        }


@@ -1541,9 +1578,136 @@
         * @return an SSK@
         */
        public String getCommentPublicKey() {
-               /* TODO */
+               try {
+                       synchronized(db.dbLock) {
+                               PreparedStatement st;
+
+                               st = 
db.getConnection().prepareStatement("SELECT publicKey FROM indexCommentKeys 
WHERE indexId = ? LIMIT 1");
+                               st.setInt(1, id);
+
+                               ResultSet set = st.executeQuery();
+
+                               if (set != null && set.next())
+                                       return set.getString("publicKey");
+
+                       }
+               } catch(SQLException e) {
+                       Logger.error(this, "Unable to get comment public key 
because : "+e.toString());
+               }
+
                return null;
        }


+       /**
+        * @return an SSK@
+        */
+       public String getCommentPrivateKey() {
+               try {
+                       synchronized(db.dbLock) {
+                               PreparedStatement st;
+
+                               st = 
db.getConnection().prepareStatement("SELECT privateKey FROM indexCommentKeys 
WHERE indexId = ? LIMIT 1");
+                               st.setInt(1, id);
+
+                               ResultSet set = st.executeQuery();
+
+                               if (set != null && set.next())
+                                       return set.getString("privateKey");
+
+                       }
+               } catch(SQLException e) {
+                       Logger.error(this, "Unable to get comment public key 
because : "+e.toString());
+               }
+
+
+               return null;
+       }
+
+       /**
+        * Will also purge comments !
+        */
+       public void purgeCommentKeys() {
+               try {
+                       synchronized(db.dbLock) {
+                               PreparedStatement st;
+
+                               st = 
db.getConnection().prepareStatement("DELETE FROM indexCommentKeys WHERE indexId 
= ?");
+                               st.setInt(1, id);
+                               st.execute();
+
+                               st = 
db.getConnection().prepareStatement("DELETE FROM indexComments WHERE indexId = 
?");
+                               st.setInt(1, id);
+                               st.execute();
+                       }
+               } catch(SQLException e) {
+                       Logger.error(this, "Unable to purge comment keys, 
because : "+e.toString());
+               }
+       }
+
+
+       /**
+        * will reset the comments !
+        */
+       public void setCommentKeys(String publicKey, String privateKey) {
+               purgeCommentKeys();
+
+               try {
+                       synchronized(db.dbLock) {
+                               PreparedStatement st;
+
+                               st = 
db.getConnection().prepareStatement("INSERT INTO indexCommentKeys (publicKey, 
privateKey, indexId) VALUES (?, ?, ?)");
+                               st.setString(1, publicKey);
+                               st.setString(2, privateKey);
+                               st.setInt(3, id);
+
+                               st.execute();
+                       }
+               } catch(SQLException e) {
+                       Logger.error(this, "Unable to set comment keys, because 
: "+e.toString());
+               }
+       }
+
+
+       protected class CommentKeyRegenerator implements Observer {
+               private FCPGenerateSSK sskGenerator;
+
+               public CommentKeyRegenerator(FCPQueueManager queueManager) {
+                       sskGenerator = new FCPGenerateSSK();
+                       sskGenerator.addObserver(this);
+
+                       sskGenerator.start(queueManager);
+               }
+
+
+               public void update(Observable o, Object param) {
+                       if (o instanceof FCPGenerateSSK) {
+                               
setCommentKeys(((FCPGenerateSSK)o).getPublicKey(),
+                                              
((FCPGenerateSSK)o).getPrivateKey());
+                       }
+               }
+
+       }
+
+       public void regeneratedCommentKeys(FCPQueueManager queueManager) {
+               new CommentKeyRegenerator(queueManager);
+       }
+
+
+       public boolean canHaveComments() {
+               return (getCommentPublicKey() != null);
+       }
+
+
+       public boolean postComment(FCPQueueManager queueManager, String author, 
String msg) {
+               String privKey;
+
+               if ((privKey = getCommentPrivateKey()) == null) {
+                       return false;
+               }
+
+               Comment comment = new Comment(this, -1, author, msg);
+
+               return comment.insertComment(queueManager);
+       }
 }

Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java   
2007-04-18 13:17:23 UTC (rev 12771)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java   
2007-04-18 14:04:50 UTC (rev 12772)
@@ -245,14 +245,18 @@



+       /**
+        * In fact, this dialog allows to change various settings related to 
the index
+        */
        public static class KeyAsker implements ActionListener, MouseListener {
                private JButton okButton;
                private JButton cancelButton;
                private int formState;

-               private JTextField publicKeyField = null;
-               private JTextField privateKeyField = null;
+               private JTextField publicKeyField       = null;
+               private JTextField privateKeyField      = null;
                private JCheckBox  publishPrivateKeyBox = null;
+               private JCheckBox  allowCommentsBox     = null;

                private JPopupMenu popupMenuA;
                private JPopupMenu popupMenuB;
@@ -266,12 +270,15 @@
                                               final String defaultPublicKey,
                                               final String defaultPrivateKey,
                                               final boolean 
defaultPublishPrivateKey,
+                                              final boolean 
defaultAllowComments,
                                               final boolean 
enablePublishPrivateKeyChoice,
                                               final IndexBrowserPanel 
indexBrowser) {
                        KeyAsker asker = new KeyAsker();
                        asker.askKeysBis(askPrivateKey, defaultPublicKey,
                                         defaultPrivateKey, 
defaultPublishPrivateKey,
-                                        enablePublishPrivateKeyChoice, 
indexBrowser);
+                                        defaultAllowComments,
+                                        enablePublishPrivateKeyChoice,
+                                        indexBrowser);
                        if (asker.getPublicKey() != null)
                                return asker;
                        else
@@ -282,6 +289,7 @@
                private String publicKeyResult = null;
                private String privateKeyResult = null;
                private boolean publishPrivateKey = false;
+               private boolean allowComments = false;


                public String getPublicKey() {
@@ -296,10 +304,15 @@
                        return publishPrivateKey;
                }

+               public boolean getAllowComments() {
+                       return allowComments;
+               }
+
                public synchronized void askKeysBis(final boolean askPrivateKey,
                                                    String defaultPublicKey,
                                                    String defaultPrivateKey,
                                                    boolean 
defaultPublishPrivateKey,
+                                                   boolean 
defaultAllowComments,
                                                    final boolean 
enablePublishPrivateKeyChoice,
                                                    final IndexBrowserPanel 
indexBrowser) {
                        formState = 0;
@@ -314,11 +327,15 @@

                        frame.getContentPane().setLayout(new BorderLayout());

-                       publicKeyField = new JTextField(defaultPublicKey);
-                       privateKeyField = new JTextField(defaultPrivateKey);
+                       publicKeyField       = new JTextField(defaultPublicKey);
+                       privateKeyField      = new 
JTextField(defaultPrivateKey);
                        publishPrivateKeyBox = new 
JCheckBox(I18n.getMessage("thaw.plugin.index.publishPrivateKey"),
                                                             
defaultPublishPrivateKey);
                        
publishPrivateKeyBox.setEnabled(enablePublishPrivateKeyChoice);
+                       allowCommentsBox     = new 
JCheckBox(I18n.getMessage("thaw.plugin.index.allowComments"),
+                                                            
defaultAllowComments);
+                       
allowCommentsBox.setEnabled(enablePublishPrivateKeyChoice); /* if we can't 
publish the private key, we can't change comment setting */
+
                        final JPanel subPanelA = new JPanel(); /* left  => 
labels */
                        final JPanel subPanelB = new JPanel(); /* right => 
textfield */

@@ -349,7 +366,7 @@
                        frame.getContentPane().add(subPanelB, 
BorderLayout.CENTER);

                        final JPanel subPanelC = new JPanel();
-                       subPanelC.setLayout(new GridLayout(2, 1));
+                       subPanelC.setLayout(new GridLayout(3, 1));

                        final JPanel subSubPanelC = new JPanel();
                        subSubPanelC.setLayout(new GridLayout(1, 2));
@@ -364,11 +381,12 @@
                        subSubPanelC.add(cancelButton);

                        subPanelC.add(publishPrivateKeyBox);
+                       subPanelC.add(allowCommentsBox);
                        subPanelC.add(subSubPanelC);

                        frame.getContentPane().add(subPanelC, 
BorderLayout.SOUTH);

-                       frame.setSize(700, 120);
+                       frame.setSize(700, 140);
                        frame.setVisible(true);

                        try {
@@ -400,8 +418,9 @@
                        else
                                publishPrivateKey = 
publishPrivateKeyBox.isSelected();

+                       allowComments = allowCommentsBox.isSelected();
+
                        Logger.info(this, "public : "+publicKeyResult + " ; 
Private : "+privateKeyResult);
-
                }

                public synchronized void actionPerformed(final ActionEvent e) {
@@ -413,7 +432,7 @@
                                formState = 2;
                        }

-                       notify();
+                       notifyAll();
                }

                public void mouseClicked(final MouseEvent e) { }
@@ -440,10 +459,10 @@
        }


-       public static class IndexKeyModifier extends BasicIndexAction 
implements Runnable {
+       public static class IndexModifier extends BasicIndexAction implements 
Runnable {

-               public IndexKeyModifier(final IndexBrowserPanel indexBrowser, 
final AbstractButton actionSource) {
-                       super(null, indexBrowser, actionSource);
+               public IndexModifier(final FCPQueueManager queueManager, final 
IndexBrowserPanel indexBrowser, final AbstractButton actionSource) {
+                       super(queueManager, indexBrowser, actionSource);
                }

                public void setTarget(final IndexTreeNode node) {
@@ -456,16 +475,28 @@
                public void apply() {
                        final Index index = ((Index)getTarget());

-                       final KeyAsker asker = KeyAsker.askKeys(true, 
index.getPublicKey(), index.getPrivateKey(), index.getPublishPrivateKey(), 
true, getIndexBrowserPanel());
+                       final KeyAsker asker = KeyAsker.askKeys(true, 
index.getPublicKey(),
+                                                               
index.getPrivateKey(), index.getPublishPrivateKey(),
+                                                               
index.canHaveComments(), true, getIndexBrowserPanel());

-                       if (asker == null)
+                       if (asker == null) {
+                               Logger.info(this, "Change cancelled");
                                return;
+                       }

                        /* Could be done in one shot ... but this way is so 
easier .... :) */
                        index.setPrivateKey(asker.getPrivateKey());
                        
index.setPublishPrivateKey(asker.getPublishPrivateKey());
                        index.setPublicKey(asker.getPublicKey());

+                       if (index.canHaveComments() && 
!asker.getAllowComments()) {
+                               Logger.notice(this, "Purging comments ...");
+                               index.purgeCommentKeys();
+                       } else if (!index.canHaveComments() && 
asker.getAllowComments()) {
+                               Logger.notice(this, "Purging comments & 
regenerating keys ...");
+                               index.regeneratedCommentKeys(getQueueManager());
+                       }
+
                        getIndexBrowserPanel().getIndexTree().refresh(index);
                }
        }
@@ -489,7 +520,7 @@
                        String privateKey = null;
                        boolean publishPrivate = false;

-                       asker = KeyAsker.askKeys(true, "USK@", "SSK@", false, 
false, getIndexBrowserPanel());
+                       asker = KeyAsker.askKeys(true, "USK@", "SSK@", false, 
false, false, getIndexBrowserPanel());

                        if (asker == null)
                                return;
@@ -1493,7 +1524,7 @@
                public void setTarget(final IndexTreeNode node) {
                        super.setTarget(node);
                        getActionSource().setEnabled(node instanceof Index
-                                                    && 
((Index)node).getCommentPublicKey() != null);
+                                                    && 
((Index)node).canHaveComments());
                }

                public void apply() {
@@ -1514,7 +1545,7 @@
                public void setTarget(final IndexTreeNode node) {
                        super.setTarget(node);
                        getActionSource().setEnabled(node instanceof Index
-                                                    && 
((Index)node).getCommentPublicKey() != null);
+                                                    && 
((Index)node).canHaveComments());
                }

                public void apply() {

Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java       2007-04-18 
13:17:23 UTC (rev 12771)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexTree.java       2007-04-18 
14:04:50 UTC (rev 12772)
@@ -234,10 +234,10 @@
                indexMenu.add(item);
                indexAndFileActions.add(new 
IndexManagementHelper.IndexBlackLister(indexBrowser, item));

-               item = new 
JMenuItem(I18n.getMessage("thaw.plugin.index.changeIndexKeys"),
-                                    IconBox.minKey);
+               item = new 
JMenuItem(I18n.getMessage("thaw.plugin.index.indexSettings"),
+                                    IconBox.minIndexSettings);
                indexMenu.add(item);
-               indexAndFileActions.add(new 
IndexManagementHelper.IndexKeyModifier(indexBrowser, item));
+               indexAndFileActions.add(new 
IndexManagementHelper.IndexModifier(queueManager, indexBrowser, item));

                item = new 
JMenuItem(I18n.getMessage("thaw.plugin.index.copyPrivateKey"));
                indexMenu.add(item);
@@ -321,9 +321,9 @@
                toolbarModifier.addButtonToTheToolbar(button);
                toolbarActions.add(action);

-               button = new JButton(IconBox.key);
-               
button.setToolTipText(I18n.getMessage("thaw.plugin.index.changeIndexKeys"));
-               action = new 
IndexManagementHelper.IndexKeyModifier(indexBrowser, button);
+               button = new JButton(IconBox.indexSettings);
+               
button.setToolTipText(I18n.getMessage("thaw.plugin.index.indexSettings"));
+               action = new IndexManagementHelper.IndexModifier(queueManager, 
indexBrowser, button);
                action.setTarget(getRoot());
                toolbarModifier.addButtonToTheToolbar(button);
                toolbarActions.add(action);


Reply via email to