Author: jflesch
Date: 2007-08-08 17:53:27 +0000 (Wed, 08 Aug 2007)
New Revision: 14527

Modified:
   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/Index.java
   trunk/apps/Thaw/src/thaw/plugins/index/IndexConfigDialog.java
   trunk/apps/Thaw/src/thaw/plugins/index/IndexContainer.java
   trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
   trunk/apps/Thaw/src/thaw/plugins/index/IndexParser.java
   trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKDraft.java
Log:
Make it possible to specify a category / subcategory / etc for an index (will 
be use to sort them automatically when downloaded)

Modified: trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties     2007-08-08 
17:09:30 UTC (rev 14526)
+++ trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties     2007-08-08 
17:53:27 UTC (rev 14527)
@@ -400,7 +400,11 @@
 thaw.plugin.index.changeCategory=Changer
 thaw.plugin.index.categoryUnspecified=[Non-sp?cifi?]

+thaw.plugin.index.category=Categorie

+thaw.plugin.index.categories=Categories (S?parateur: '/')
+
+
 # Peer monitor

 thaw.plugin.peerMonitor.peerMonitor=Connexion
@@ -614,3 +618,6 @@
 thaw.plugin.miniFrost.days=jours

 thaw.plugin.miniFrost.actions=[ACTIONS]
+
+thaw.plugin.miniFrost.collision=Collision au moment de l'insertion d'un 
message sur la board 'X'.\n Nouvel essai sur un nouveau slot.
+

Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2007-08-08 17:09:30 UTC 
(rev 14526)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2007-08-08 17:53:27 UTC 
(rev 14527)
@@ -410,7 +410,12 @@
 thaw.plugin.index.changeCategory=Change
 thaw.plugin.index.categoryUnspecified=[Unspecified]

+thaw.plugin.index.blackList=Index blacklist

+thaw.plugin.index.category=Category
+thaw.plugin.index.categories=Categories (Separator: '/')
+
+
 # Peer monitor

 thaw.plugin.peerMonitor.peerMonitor=Connection
@@ -454,10 +459,7 @@
 thaw.plugin.themeSelector.theme=Theme


-thaw.plugin.index.blackList=Index blacklist

-
-
 thaw.plugin.signature.signatures=Identities
 thaw.plugin.signature.pluginName=Signature management
 thaw.plugin.signature.yourIdentities=Manage your identities
@@ -630,3 +632,5 @@
 thaw.plugin.miniFrost.days=days

 thaw.plugin.miniFrost.actions=[ACTIONS]
+
+thaw.plugin.miniFrost.collision=Collision while inserting a message for the 
board 'X'.\n Will try with another slot.

Modified: trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties    2007-08-08 17:09:30 UTC 
(rev 14526)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties    2007-08-08 17:53:27 UTC 
(rev 14527)
@@ -400,7 +400,11 @@
 thaw.plugin.index.changeCategory=Changer
 thaw.plugin.index.categoryUnspecified=[Non-sp\u00e9cifi\u00e9]

+thaw.plugin.index.category=Categorie

+thaw.plugin.index.categories=Categories (S\u00e9parateur: '/')
+
+
 # Peer monitor

 thaw.plugin.peerMonitor.peerMonitor=Connexion
@@ -614,3 +618,6 @@
 thaw.plugin.miniFrost.days=jours

 thaw.plugin.miniFrost.actions=[ACTIONS]
+
+thaw.plugin.miniFrost.collision=Collision au moment de l'insertion d'un 
message sur la board 'X'.\n Nouvel essai sur un nouveau slot.
+

Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Index.java   2007-08-08 17:09:30 UTC 
(rev 14526)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java   2007-08-08 17:53:27 UTC 
(rev 14527)
@@ -1853,28 +1853,32 @@
                                PreparedStatement st;
                                ResultSet set;

-                               int catId = 0;
+                               int catId = 1;

-                               while (catId == 0) {
-                                       /* localisation */
+                               st = 
db.getConnection().prepareStatement("SELECT id FROM categories "+
+                                                                        "WHERE 
name = ? LIMIT 1");
+                               st.setString(1, category.toLowerCase());
+
+                               set = st.executeQuery();
+
+                               if (!set.next()) {
+
                                        st = 
db.getConnection().prepareStatement("SELECT id FROM categories "+
-                                                                               
 "WHERE name = ? LIMIT 1");
-                                       st.setString(1, category.toLowerCase());
-
+                                                                               
 "ORDER by id DESC LIMIT 1");
                                        set = st.executeQuery();
+                                       if (set.next())
+                                               catId = set.getInt("id")+1;

-                                       if (set.next())
-                                               catId = set.getInt("id");
-                                       else {
-                                               /* insertion */
-                                               st = 
db.getConnection().prepareStatement("INSERT INTO categories "+
-                                                                               
         "(name) VALUES (?)");
-                                               st.setString(1, 
category.toLowerCase());
-                                               st.execute();
-                                       }
+                                       /* insertion */
+                                       st = 
db.getConnection().prepareStatement("INSERT INTO categories "+
+                                                                               
 "(id, name) VALUES (?, ?)");
+                                       st.setInt(1, catId);
+                                       st.setString(2, category.toLowerCase());
+                                       st.execute();
+                               } else {
+                                       catId = set.getInt("id");
                                }

-
                                /* set the categoryId of the index */

                                st = 
db.getConnection().prepareStatement("UPDATE indexes SET categoryId = ? "+

Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexConfigDialog.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexConfigDialog.java       
2007-08-08 17:09:30 UTC (rev 14526)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexConfigDialog.java       
2007-08-08 17:53:27 UTC (rev 14527)
@@ -9,6 +9,8 @@
 import javax.swing.JMenuItem;
 import javax.swing.JPanel;
 import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JScrollPane;

 import java.awt.GridLayout;
 import java.awt.BorderLayout;
@@ -18,6 +20,15 @@
 import java.awt.event.MouseListener;
 import java.awt.event.MouseEvent;

+import javax.swing.event.ListSelectionListener;
+import javax.swing.event.ListSelectionEvent;
+
+import java.sql.*;
+
+import java.util.Vector;
+import java.util.Iterator;
+
+
 import thaw.fcp.FCPQueueManager;
 import thaw.fcp.FreenetURIHelper;
 import thaw.core.I18n;
@@ -25,9 +36,13 @@
 import thaw.plugins.Hsqldb;


-public class IndexConfigDialog implements ActionListener, MouseListener {
+public class IndexConfigDialog implements ActionListener, MouseListener,
+                                         ListSelectionListener {
+
        public final static int SIZE_X = 700;
        public final static int SIZE_Y = 170;
+       public final static int CATEGORY_DIALOG_SIZE_X = 400;
+       public final static int CATEGORY_DIALOG_SIZE_Y = 400;

        private JDialog frame;

@@ -47,9 +62,9 @@
        private JTextField privateKeyField      = null;
        private JCheckBox  publishPrivateKeyBox = null;
        private JCheckBox  allowCommentsBox     = null;
+       private JLabel     categoryLabel        = null;
+       private JButton    changeCategory       = null;

-       private JButton    changeCategory;
-
        private JPopupMenu popupMenuA;
        private JPopupMenu popupMenuB;

@@ -151,18 +166,15 @@
                                            false :
                                            (index.getPrivateKey() != null));

+               categoryLabel = new JLabel("");

+
                resetCommentsButton = new 
JButton(I18n.getMessage("thaw.plugin.index.comment.reset"));
                resetCommentsButton.setEnabled(index != null && 
index.getPrivateKey() != null);
                resetCommentsButton.addActionListener(this);

-               String cat = (index == null ? null : index.getCategory());
+               updateCategoryLabel();

-               if (cat == null)
-                       cat = 
I18n.getMessage("thaw.plugin.index.categoryUnspecified");
-
-               JLabel categoryLabel = new 
JLabel(I18n.getMessage("thaw.plugin.index.category")
-                                                 +" "+cat);
                changeCategory = new 
JButton(I18n.getMessage("thaw.plugin.index.changeCategory"));
                changeCategory.setEnabled(index != null && 
index.getPrivateKey() != null);
                changeCategory.addActionListener(this);
@@ -282,6 +294,101 @@
        }


+
+       private JDialog categoryDialog;
+       private JList categoryList;
+       private JTextField categoryField;
+       private JButton categoryOkButton;
+       private JButton categoryCancelButton;
+
+
+       public void updateCategoryLabel() {
+               String cat = (index == null ? null : index.getCategory());
+
+               if (cat == null)
+                       cat = 
I18n.getMessage("thaw.plugin.index.categoryUnspecified");
+
+               
categoryLabel.setText(I18n.getMessage("thaw.plugin.index.category")
+                                     +": "+cat);
+       }
+
+       public Vector getCategories() {
+               Vector v = new Vector();
+
+               try {
+                       synchronized(db.dbLock) {
+                               PreparedStatement st;
+
+                               st = 
db.getConnection().prepareStatement("SELECT id, name "+
+                                                                        "FROM 
categories "+
+                                                                        "ORDER 
BY name");
+
+                               ResultSet set = st.executeQuery();
+
+                               while(set.next()) {
+                                       v.add(set.getString("name"));
+                               }
+                       }
+               } catch(SQLException e) {
+                       Logger.error(this, "Can't get index categories list 
because : "+e.toString());
+               }
+
+               return v;
+       }
+
+
+       public void showCategoryDialog() {
+               Vector cats = getCategories();
+
+               categoryDialog = new JDialog(frame,
+                                            
I18n.getMessage("thaw.plugin.index.category"));
+
+               categoryList = new JList(cats);
+               categoryOkButton = new 
JButton(I18n.getMessage("thaw.common.ok"));
+               categoryCancelButton = new 
JButton(I18n.getMessage("thaw.common.cancel"));
+               categoryField = new JTextField("");
+
+               categoryList.addListSelectionListener(this);
+               categoryOkButton.addActionListener(this);
+               categoryCancelButton.addActionListener(this);
+
+               String cat = index.getCategory();
+
+               if (cat != null) {
+                       categoryList.setSelectedIndex(cats.indexOf(cat));
+                       categoryField.setText(cat);
+               }
+
+
+               categoryDialog.getContentPane().setLayout(new BorderLayout(5, 
5));
+
+
+               JPanel buttonPanel = new JPanel(new GridLayout(1, 2));
+               buttonPanel.add(categoryOkButton);
+               buttonPanel.add(categoryCancelButton);
+
+               JPanel southPanel = new JPanel(new GridLayout(2, 1));
+               southPanel.add(categoryField);
+               southPanel.add(buttonPanel);
+
+
+               categoryDialog.getContentPane().add(new 
JLabel(I18n.getMessage("thaw.plugin.index.categories")),
+                                                   BorderLayout.NORTH);
+               categoryDialog.getContentPane().add(new 
JScrollPane(categoryList),
+                                                   BorderLayout.CENTER);
+               categoryDialog.getContentPane().add(southPanel,
+                                                   BorderLayout.SOUTH);
+
+               categoryDialog.setSize(CATEGORY_DIALOG_SIZE_X, 
CATEGORY_DIALOG_SIZE_Y);
+               categoryDialog.setVisible(true);
+       }
+
+
+       public void valueChanged(ListSelectionEvent e) {
+               categoryField.setText((String)categoryList.getSelectedValue());
+       }
+
+
        public void actionPerformed(final ActionEvent e) {
                if (e.getSource() == okButton) {
                        formState = 1;
@@ -304,8 +411,18 @@

                } else if (e.getSource() == changeCategory) {

-                       /* TODO */
+                       showCategoryDialog();

+               } else if (e.getSource() == categoryOkButton) {
+
+                       index.setCategory(categoryField.getText());
+                       categoryDialog.setVisible(false);
+                       updateCategoryLabel();
+
+               } else if (e.getSource() == categoryCancelButton) {
+
+                       categoryDialog.setVisible(false);
+
                }
        }


Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexContainer.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexContainer.java  2007-08-08 
17:09:30 UTC (rev 14526)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexContainer.java  2007-08-08 
17:53:27 UTC (rev 14527)
@@ -70,4 +70,8 @@

        public void setPublishPrivateKey(boolean publish);
        public void setPrivateKey(String key);
+
+
+       public void setCategory(String str);
+       public String getCategory();
 }

Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java   
2007-08-08 17:09:30 UTC (rev 14526)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java   
2007-08-08 17:53:27 UTC (rev 14527)
@@ -202,6 +202,8 @@
                        FCPGenerateSSK sskGenerator = (FCPGenerateSSK)o;
                        Hsqldb db = getIndexBrowserPanel().getDb();

+                       Index index;
+
                        synchronized(db.dbLock) {
                                try {
                                        PreparedStatement st;
@@ -244,20 +246,26 @@

                                        st.execute();

-                                       Index index = new Index(db, 
getIndexBrowserPanel().getConfig(),
-                                                               id, 
(TreeNode)getTarget(),
-                                                               
sskGenerator.getPublicKey(), 0, sskGenerator.getPrivateKey(),
-                                                               name, null,
-                                                               false, false);
+                                       index = new Index(db, 
getIndexBrowserPanel().getConfig(),
+                                                         id, 
(TreeNode)getTarget(),
+                                                         
sskGenerator.getPublicKey(), 0, sskGenerator.getPrivateKey(),
+                                                         name, null,
+                                                         false, false);

-                                       
((MutableTreeNode)getTarget()).insert((index), 0);
-
-
-                                       
getIndexBrowserPanel().getIndexTree().refresh(getTarget());
                                } catch(SQLException e) {
                                        Logger.error(new 
IndexManagementHelper(), "Error while creating index: "+e.toString());
+                                       return;
                                }
                        }
+
+                       ((MutableTreeNode)getTarget()).insert((index), 0);
+
+                       
getIndexBrowserPanel().getIndexTree().refresh(getTarget());
+
+                       IndexConfigDialog dialog = new 
IndexConfigDialog(getIndexBrowserPanel(),
+                                                                        
getQueueManager(),
+                                                                        index);
+                       dialog.promptUser();
                }
        }

@@ -481,7 +489,8 @@
                                                                           
I18n.getMessage("thaw.plugin.index.categoryName"),
                                                                           
I18n.getMessage("thaw.plugin.index.newCategory"));

-                       
IndexManagementHelper.addIndexFolder(getIndexBrowserPanel(), 
(IndexFolder)getTarget(), name);
+                       if (name != null)
+                               
IndexManagementHelper.addIndexFolder(getIndexBrowserPanel(), 
(IndexFolder)getTarget(), name);
                }
        }


Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexParser.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexParser.java     2007-08-08 
17:09:30 UTC (rev 14526)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexParser.java     2007-08-08 
17:53:27 UTC (rev 14527)
@@ -172,6 +172,17 @@

                header.appendChild(date);

+               /* category */
+
+               String cat = index.getCategory();
+
+               if (cat != null) {
+                       Element category = xmlDoc.createElement("category");
+                       Text categoryText = xmlDoc.createTextNode(cat);
+                       category.appendChild(categoryText);
+                       header.appendChild(category);
+               }
+
                /* TODO : Author */

                return header;
@@ -326,10 +337,12 @@
                private boolean privateKeyTag = false;
                private boolean dateTag = false;
                private boolean commentsTag = false;
+               private boolean categoryTag = false;

                private boolean hasCommentTag = false;

                private String dateStr = null;
+               private String categoryStr = null;


                /**
@@ -367,6 +380,11 @@
                                return;
                        }

+                       if ("category".equals(rawName)) {
+                               categoryTag = true;
+                               return;
+                       }
+
                        if ("link".equals(rawName)
                            || "index".equals(rawName)) { /* links */

@@ -442,6 +460,11 @@
                                return;
                        }

+                       if ("category".equals(rawName)) {
+                               categoryTag = false;
+                               return;
+                       }
+
                        if ("header".equals(rawName)) {
                                if (dateStr != null) {
                                        java.text.SimpleDateFormat sdf =
@@ -450,6 +473,9 @@

                                        index.setInsertionDate(dateUtil);
                                }
+
+                               if (categoryStr != null)
+                                       index.setCategory(categoryStr);
                        }

                        if ("comments".equals(rawName)) {
@@ -479,6 +505,10 @@
                                dateStr = txt;
                        }

+                       if (categoryTag) {
+                               categoryStr = txt;
+                       }
+
                        if (privateKeyTag) {
                                if (index.getPrivateKey() == null
                                    || 
index.getPrivateKey().trim().equals(txt.trim())) {

Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKDraft.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKDraft.java   
2007-08-08 17:09:30 UTC (rev 14526)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKDraft.java   
2007-08-08 17:53:27 UTC (rev 14527)
@@ -259,6 +259,14 @@
                                        return;
                                }

+                               String announce = 
I18n.getMessage("thaw.plugin.miniFrost.collision");
+                               announce = announce.replaceAll("X", 
board.toString());
+
+                               
thaw.plugins.TrayIcon.popMessage(board.getFactory().getCore().getPluginManager(),
+                                                                "MiniFrost",
+                                                                announce,
+                                                                
thaw.gui.SysTrayIcon.MSG_WARNING);
+
                                put.deleteObserver(this);
                                put.stop(queueManager);
                                queueManager.remove(put);


Reply via email to