Author: jflesch
Date: 2008-02-05 16:56:43 +0000 (Tue, 05 Feb 2008)
New Revision: 17547

Added:
   trunk/apps/Thaw/src/thaw/plugins/webOfTrust/
   trunk/apps/Thaw/src/thaw/plugins/webOfTrust/WebOfTrustConfigTab.java
Modified:
   trunk/apps/Thaw/src/thaw/core/Config.java
   trunk/apps/Thaw/src/thaw/core/Core.java
   trunk/apps/Thaw/src/thaw/core/Logger.java
   trunk/apps/Thaw/src/thaw/core/PluginManager.java
   trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
   trunk/apps/Thaw/src/thaw/i18n/thaw.properties
   trunk/apps/Thaw/src/thaw/plugins/Signatures.java
   trunk/apps/Thaw/src/thaw/plugins/WebOfTrust.java
   trunk/apps/Thaw/src/thaw/plugins/signatures/DatabaseManager.java
Log:
Implement the config tab for the web of trust (does almost nothing atm)

Modified: trunk/apps/Thaw/src/thaw/core/Config.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Config.java   2008-02-05 09:22:17 UTC (rev 
17546)
+++ trunk/apps/Thaw/src/thaw/core/Config.java   2008-02-05 16:56:43 UTC (rev 
17547)
@@ -78,7 +78,8 @@
                String currentValue = getValue(key);

                if ( (currentValue != null && !currentValue.equals(value))
-                    || (currentValue == null && value != null ) ) {
+                    || (currentValue == null && value != null)
+                    || (currentValue != null && value == null) ) {

                        /* we get the plugin list to reload */
                        Vector pluginList = (Vector)listeners.get(key);
@@ -100,7 +101,10 @@
                        }

                        /* and to finish, we set the value */
-                       parameters.put(key, value);
+                       if (value != null)
+                               parameters.put(key, value);
+                       else
+                               parameters.remove(key);
                }
        }


Modified: trunk/apps/Thaw/src/thaw/core/Core.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Core.java     2008-02-05 09:22:17 UTC (rev 
17546)
+++ trunk/apps/Thaw/src/thaw/core/Core.java     2008-02-05 16:56:43 UTC (rev 
17547)
@@ -421,8 +421,13 @@

                lookAndFeel = theme;

+               /* the recommandation is to set the lnf before displaying the 
first window */
+               /* but I had more bugs with the GTK lnf when I followed the 
recommandation than
+                * when I didn't. So now I only change it when the main window 
is already displayed :p */

-               if (mainWindow.getMainFrame().isVisible())
+               if (mainWindow != null
+                       && mainWindow.getMainFrame() != null
+                       && mainWindow.getMainFrame().isVisible())
                        reallySetTheme(lookAndFeel);
        }

@@ -444,8 +449,9 @@
                        if (splashScreen != null)
                                splashScreen.rebuild();
                } catch (final Exception e) {
-                       Logger.warning(this, "Exception while setting the L&F : 
" + e.getMessage());
-                       Logger.warning(this, "Using the default lookAndFeel");
+                       Logger.warning(this, "Exception while setting the L&F : 
" + e.toString() + " ; " + e.getMessage());
+                       e.printStackTrace();
+                       Logger.warning(this, "Will use the default 
lookAndFeel");
                }

                return true;

Modified: trunk/apps/Thaw/src/thaw/core/Logger.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Logger.java   2008-02-05 09:22:17 UTC (rev 
17546)
+++ trunk/apps/Thaw/src/thaw/core/Logger.java   2008-02-05 16:56:43 UTC (rev 
17547)
@@ -16,7 +16,7 @@
        public final static int LOG_LEVEL_DEBUG   = 4;
        public final static int LOG_LEVEL_VERBOSE = 5;

-       private static int LOG_LEVEL = 2;
+       private static int LOG_LEVEL = 3;


        public final static String[] PREFIXES = new String[] {

Modified: trunk/apps/Thaw/src/thaw/core/PluginManager.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/PluginManager.java    2008-02-05 09:22:17 UTC 
(rev 17546)
+++ trunk/apps/Thaw/src/thaw/core/PluginManager.java    2008-02-05 16:56:43 UTC 
(rev 17547)
@@ -31,6 +31,7 @@
                "thaw.plugins.ThemeSelector",
                "thaw.plugins.Hsqldb",
                "thaw.plugins.Signatures",
+               "thaw.plugins.WebOfTrust",
                "thaw.plugins.IndexBrowser",
                "thaw.plugins.IndexExporter",
                "thaw.plugins.IndexTreeRebuilder",

Modified: trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties     2008-02-05 
09:22:17 UTC (rev 17546)
+++ trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties     2008-02-05 
16:56:43 UTC (rev 17547)
@@ -711,3 +711,9 @@

 ## Web of Trust
 thaw.plugin.wot=Toile de confiance
+thaw.plugin.wot.activated=Activer la toile de confiance
+thaw.plugin.wot.usedIdentity=Identit? utilis?e pour publier la liste de 
confiances
+thaw.plugin.wot.usedIdentity.none=[Ne pas publier la liste de confiance]
+thaw.plugin.wot.numberOfRefresh=Nombre de liste de confiances ? rafraichir 
simultan?ment
+
+

Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2008-02-05 09:22:17 UTC 
(rev 17546)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2008-02-05 16:56:43 UTC 
(rev 17547)
@@ -721,4 +721,9 @@
 ## Web of trust

 thaw.plugin.wot=Web of Trust
+thaw.plugin.wot.activated=Activate the web of trust
+thaw.plugin.wot.usedIdentity=Identity used to publish your trust list
+thaw.plugin.wot.usedIdentity.none=[Don't publish the trust list]
+thaw.plugin.wot.numberOfRefresh=Number of trust list to refresh simultaneously

+

Modified: trunk/apps/Thaw/src/thaw/plugins/Signatures.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/Signatures.java    2008-02-05 09:22:17 UTC 
(rev 17546)
+++ trunk/apps/Thaw/src/thaw/plugins/Signatures.java    2008-02-05 16:56:43 UTC 
(rev 17547)
@@ -116,16 +116,20 @@

                used--;

-               if (used == 0)
+               if (used == 0) {
                        db.unregisterChild(this);
+                       db = null;
+               }
        }


        public void realStop() {
                used--;

-               if (used == 0)
+               if (used == 0) {
                        db.unregisterChild(this);
+                       db = null;
+               }
        }

        public String getNameForUser() {

Modified: trunk/apps/Thaw/src/thaw/plugins/WebOfTrust.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/WebOfTrust.java    2008-02-05 09:22:17 UTC 
(rev 17546)
+++ trunk/apps/Thaw/src/thaw/plugins/WebOfTrust.java    2008-02-05 16:56:43 UTC 
(rev 17547)
@@ -3,14 +3,67 @@
 import javax.swing.ImageIcon;

 import thaw.core.Core;
-import thaw.core.Plugin;
+import thaw.core.Logger;
 import thaw.core.I18n;
+import thaw.plugins.Hsqldb;
+import thaw.plugins.Signatures;
+import thaw.plugins.webOfTrust.WebOfTrustConfigTab;

-public class WebOfTrust implements Plugin {
+public class WebOfTrust extends thaw.core.LibraryPlugin {
+       private Core core;
+       private Hsqldb db;
+       private Signatures sigs;

-       public WebOfTrust() {
+       private WebOfTrustConfigTab configTab = null;
+       
+       private int used = 0;
+       
+       public WebOfTrust() { used = 0; }
+       
+       private boolean loadDeps(Core core) {
+               /* Hsqldb */
+               if(core.getPluginManager().getPlugin("thaw.plugins.Hsqldb") == 
null) {
+                       Logger.info(this, "Loading Hsqldb plugin");

+                       
if(core.getPluginManager().loadPlugin("thaw.plugins.Hsqldb") == null
+                          || 
!core.getPluginManager().runPlugin("thaw.plugins.Hsqldb")) {
+                               Logger.error(this, "Unable to load 
thaw.plugins.Hsqldb !");
+                               return false;
+                       }
+               }
+
+               db = 
(Hsqldb)core.getPluginManager().getPlugin("thaw.plugins.Hsqldb");
+               db.registerChild(this);
+
+               /* Signatures */
+               if(core.getPluginManager().getPlugin("thaw.plugins.Signatures") 
== null) {
+                       Logger.info(this, "Loading Signatures plugin");
+
+                       
if(core.getPluginManager().loadPlugin("thaw.plugins.Signatures") == null
+                          || 
!core.getPluginManager().runPlugin("thaw.plugins.Signatures")) {
+                               Logger.error(this, "Unable to load 
thaw.plugins.Signatures !");
+                               return false;
+                       }
+               }
+
+               sigs = 
(Signatures)core.getPluginManager().getPlugin("thaw.plugins.Signatures");
+               sigs.registerChild(this);
+               
+               return true;
        }
+       
+       private boolean unloadDeps(Core core) {
+               
+               if (sigs != null)
+                       sigs.unregisterChild(this);
+               if (db != null)
+                       db.unregisterChild(this);
+               
+               sigs = null;
+               db = null;
+               
+               return true;
+       }

        public ImageIcon getIcon() {
                return thaw.gui.IconBox.trust;
@@ -21,12 +74,48 @@
        }

        public boolean run(Core core) {
+               core.getConfig().addListener("wotActivated",        this);
+               core.getConfig().addListener("wotIdentityUsed",     this);
+               core.getConfig().addListener("wotNumberOfRefresh",  this);

-               return false;
+               used++;
+               
+               this.core = core;
+               
+               if (!loadDeps(core))
+                       return false;
+               
+               configTab = new WebOfTrustConfigTab(core.getConfigWindow(),
+                                                                               
        core.getConfig(), db);
+
+               
core.getConfigWindow().addTab(I18n.getMessage("thaw.plugin.wot"),
+                             thaw.gui.IconBox.minTrust,
+                             configTab.getPanel());
+
+               return true;
        }

        public void stop() {
+               used--;
+               
+               if (configTab != null) {
+                       core.getConfigWindow().removeTab(configTab.getPanel());
+                       configTab = null;
+               }
+               
+               if (used == 0)
+                       unloadDeps(core);
+       }

+       public void realStart() {
+               used++;
        }

+       public void realStop() {
+               used--;
+               
+               if (used == 0)
+                       unloadDeps(core);
+       }
+
 }

Modified: trunk/apps/Thaw/src/thaw/plugins/signatures/DatabaseManager.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/signatures/DatabaseManager.java    
2008-02-05 09:22:17 UTC (rev 17546)
+++ trunk/apps/Thaw/src/thaw/plugins/signatures/DatabaseManager.java    
2008-02-05 16:56:43 UTC (rev 17547)
@@ -102,7 +102,7 @@
        }


-       /* dropTables is not implements because signatures may be VERY 
important */
+       /* dropTables is not implemented because signatures may be VERY 
important */
        /* (anyway, because of the foreign key, it would probably fail */

        protected static boolean convertDatabase_1_to_2(Hsqldb db) {

Added: trunk/apps/Thaw/src/thaw/plugins/webOfTrust/WebOfTrustConfigTab.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/webOfTrust/WebOfTrustConfigTab.java        
                        (rev 0)
+++ trunk/apps/Thaw/src/thaw/plugins/webOfTrust/WebOfTrustConfigTab.java        
2008-02-05 16:56:43 UTC (rev 17547)
@@ -0,0 +1,124 @@
+package thaw.plugins.webOfTrust;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Iterator;
+import java.util.Observable;
+import java.util.Observer;
+import java.util.Vector;
+
+import javax.swing.JCheckBox;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JComboBox;
+
+import thaw.core.Config;
+import thaw.core.I18n;
+import thaw.plugins.Hsqldb;
+import thaw.plugins.signatures.Identity;
+
+public class WebOfTrustConfigTab implements Observer, ActionListener {
+       private thaw.core.ConfigWindow configWindow;
+       private Config config;
+       private Hsqldb db;
+       
+       private JPanel panel;
+       private JCheckBox activated;
+       private JComboBox identityUsed;
+       private JComboBox numberOfRefresh;
+       
+       public WebOfTrustConfigTab(thaw.core.ConfigWindow configWindow,
+                                                       Config config, Hsqldb 
db) {
+               this.configWindow = configWindow;
+               this.config = config;
+               this.db = db;
+               
+               panel = new JPanel(new java.awt.GridLayout(15, 1));
+               
+               activated = new 
JCheckBox(I18n.getMessage("thaw.plugin.wot.activated"));
+               panel.add(activated);
+               
+               panel.add(new JLabel(""));
+               panel.add(new 
JLabel(I18n.getMessage("thaw.plugin.wot.usedIdentity")));
+               
+               identityUsed = new JComboBox();
+               panel.add(identityUsed);
+               
+               panel.add(new JLabel(""));
+               panel.add(new 
JLabel(I18n.getMessage("thaw.plugin.wot.numberOfRefresh")));
+               
+               numberOfRefresh = new JComboBox();
+               for (int i = 0 ; i <= 100 ; i++)
+                       numberOfRefresh.addItem(new Integer(i));
+               panel.add(numberOfRefresh);
+               
+               resetContentOfIdentitySelector();
+               reloadSettings();
+               readActivated();
+               
+               activated.addActionListener(this);
+               configWindow.addObserver(this);
+       }
+       
+       private void resetContentOfIdentitySelector() {
+               Vector identities = Identity.getYourIdentities(db);
+               
+               identityUsed.removeAllItems();
+               
identityUsed.addItem(I18n.getMessage("thaw.plugin.wot.usedIdentity.none"));
+               
+               for (Iterator it = identities.iterator();
+                       it.hasNext();) {
+                       identityUsed.addItem(it.next().toString());
+               }
+       }
+       
+       protected void reloadSettings() {
+               /* default values */
+               activated.setSelected(true);
+               numberOfRefresh.setSelectedItem(new Integer(10));
+               
identityUsed.setSelectedItem(I18n.getMessage("thaw.plugin.wot.usedIdentity.none"));
+               
+               /* loading values */
+               if (config.getValue("wotActivated") != null)
+                       
activated.setSelected(Boolean.valueOf(config.getValue("wotActivated")).booleanValue());
+               if (config.getValue("wotIdentityUsed") != null)
+                       
identityUsed.setSelectedItem(config.getValue("wotIdentityUsed"));
+               if (config.getValue("wotNumberOfRefresh") != null)
+                       numberOfRefresh.setSelectedItem(new 
Integer(config.getValue("wotNumberOfRefresh")));
+       }
+       
+       protected void saveSettings() {
+               config.setValue("wotActivated", 
Boolean.valueOf(activated.isSelected()).toString());
+
+               if (identityUsed.getSelectedIndex() <= 0)
+                       config.setValue("wotIdentityUsed", null);
+               else
+                       config.setValue("wotIdentityUsed", 
identityUsed.getSelectedItem().toString());
+
+               config.setValue("wotNumberOfRefresh", 
numberOfRefresh.getSelectedItem().toString());
+       }
+       
+       private void readActivated() {
+               boolean s = activated.isSelected();
+               
+               identityUsed.setEnabled(s);
+               numberOfRefresh.setEnabled(s);
+       }
+       
+       public JPanel getPanel() {
+               return panel;
+       }
+
+       public void update(Observable o, Object param) {
+               if (param == configWindow.getOkButton())
+                       saveSettings();
+
+               resetContentOfIdentitySelector();
+               reloadSettings();
+               readActivated();
+       }
+
+       public void actionPerformed(ActionEvent e) {
+               readActivated();
+       }
+}


Reply via email to