Author: jflesch
Date: 2007-08-02 18:57:47 +0000 (Thu, 02 Aug 2007)
New Revision: 14468
Modified:
trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
trunk/apps/Thaw/src/thaw/i18n/thaw.properties
trunk/apps/Thaw/src/thaw/plugins/MiniFrost.java
trunk/apps/Thaw/src/thaw/plugins/ToolbarModifier.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/MiniFrostConfigTab.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/BoardFactory.java
Log:
Add an automatic cleaning of the database at each startup of Thaw
Modified: trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties 2007-08-02
16:32:17 UTC (rev 14467)
+++ trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties 2007-08-02
18:57:47 UTC (rev 14468)
@@ -601,3 +601,8 @@
thaw.plugin.miniFrost.modifyRegexp=Modifier les r?gles de filtrage
thaw.plugin.miniFrost.seeTree=Voir les messages sous forme d'arbre
+thaw.plugin.miniFrost.archiveAfter=Archiver automatiquement les messages apr?s:
+thaw.plugin.miniFrost.deleteAfter=Effacer automatiquement les messages apr?s:
+
+thaw.plugin.miniFrost.days=jours
+
Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2007-08-02 16:32:17 UTC
(rev 14467)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2007-08-02 18:57:47 UTC
(rev 14468)
@@ -619,3 +619,7 @@
thaw.plugin.miniFrost.modifyRegexp=Modify the filtering rules
thaw.plugin.miniFrost.seeTree=See message tree
+
+thaw.plugin.miniFrost.archiveAfter=Automatically archive the messages after:
+thaw.plugin.miniFrost.deleteAfter=Automatically delete the messages after:
+thaw.plugin.miniFrost.days=days
Modified: trunk/apps/Thaw/src/thaw/plugins/MiniFrost.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/MiniFrost.java 2007-08-02 16:32:17 UTC
(rev 14467)
+++ trunk/apps/Thaw/src/thaw/plugins/MiniFrost.java 2007-08-02 18:57:47 UTC
(rev 14468)
@@ -3,6 +3,7 @@
import thaw.core.I18n;
import thaw.core.Core;
import thaw.core.Logger;
+import thaw.core.Config;
import thaw.plugins.miniFrost.MiniFrostPanel;
import thaw.plugins.miniFrost.interfaces.BoardFactory;
@@ -13,6 +14,9 @@
public class MiniFrost implements thaw.core.Plugin {
+ public final static int DEFAULT_ARCHIVE_AFTER = 7; /* days */
+ public final static int DEFAULT_DELETE_AFTER = 60; /* days */
+
private Core core;
private Hsqldb hsqldb;
@@ -37,6 +41,7 @@
if (!loadDeps()
|| !initFactories()
+ || !cleanUp(core.getConfig())
|| !loadGUI()
|| !loadAutoRefresh())
return false;
@@ -90,6 +95,27 @@
}
+ protected boolean cleanUp(Config config) {
+ int archiveAfter = DEFAULT_ARCHIVE_AFTER;
+ int deleteAfter = DEFAULT_DELETE_AFTER;
+
+ if (config.getValue("miniFrostArchiveAfter") != null)
+ archiveAfter =
Integer.parseInt(config.getValue("miniFrostArchiveAfter"));
+
+ if (config.getValue("miniFrostDeleteAfter") != null)
+ deleteAfter =
Integer.parseInt(config.getValue("miniFrostDeleteAfter"));
+
+ boolean b = true;
+
+ for (int i = 0 ; i < factories.length ; i++) {
+ if (!factories[i].cleanUp(archiveAfter, deleteAfter))
+ b = false;
+ }
+
+ return b;
+ }
+
+
protected boolean loadGUI() {
miniFrostPanel = new MiniFrostPanel(core.getConfig(), hsqldb,
this);
Modified: trunk/apps/Thaw/src/thaw/plugins/ToolbarModifier.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/ToolbarModifier.java 2007-08-02
16:32:17 UTC (rev 14467)
+++ trunk/apps/Thaw/src/thaw/plugins/ToolbarModifier.java 2007-08-02
18:57:47 UTC (rev 14468)
@@ -40,6 +40,9 @@
* @param position if == -1, then the button is put at the end
*/
public void addButtonToTheToolbar(final JButton button, int position) {
+ if (button != null)
+ button.setBorderPainted(false);
+
if (position < 0)
buttons.add(button);
else {
Modified: trunk/apps/Thaw/src/thaw/plugins/miniFrost/MiniFrostConfigTab.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/MiniFrostConfigTab.java
2007-08-02 16:32:17 UTC (rev 14467)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/MiniFrostConfigTab.java
2007-08-02 18:57:47 UTC (rev 14468)
@@ -20,7 +20,9 @@
import thaw.core.Logger;
import thaw.gui.IconBox;
+import thaw.plugins.MiniFrost;
+
public class MiniFrostConfigTab implements Observer, ActionListener {
private Config config;
@@ -33,6 +35,14 @@
public final static int MAX_BOARDS = 30;
private JComboBox maxBoards;
+
+ public final static int MIN_DAYS = 0;
+ public final static int MAX_DAYS = 365;
+
+ private JComboBox archiveAfter;
+ private JComboBox deleteAfter;
+
+
private JButton regexpButton;
@@ -50,11 +60,25 @@
for (int i = MIN_BOARDS ; i <= MAX_BOARDS ; i++)
maxBoards.addItem(Integer.toString(i));
+ archiveAfter = new JComboBox();
+ deleteAfter = new JComboBox();
+
+ for (int i = MIN_DAYS ; i <= MAX_DAYS ; i++) {
+ archiveAfter.addItem(Integer.toString(i)+ "
"+I18n.getMessage("thaw.plugin.miniFrost.days"));
+ deleteAfter.addItem( Integer.toString(i)+ "
"+I18n.getMessage("thaw.plugin.miniFrost.days"));
+ }
+
selectValue();
panel.add(new
JLabel(I18n.getMessage("thaw.plugin.miniFrost.maxBoardsRefreshed")));
panel.add(maxBoards);
+ panel.add(new
JLabel(I18n.getMessage("thaw.plugin.miniFrost.archiveAfter")));
+ panel.add(archiveAfter);
+
+ panel.add(new
JLabel(I18n.getMessage("thaw.plugin.miniFrost.deleteAfter")));
+ panel.add(deleteAfter);
+
JPanel regexpPanel = new JPanel(new BorderLayout());
regexpPanel.add(new JLabel(""), BorderLayout.CENTER);
regexpButton = new
JButton(I18n.getMessage("thaw.plugin.miniFrost.modifyRegexp"));
@@ -85,21 +109,53 @@
if (config.getValue("miniFrostAutoRefreshMaxBoards") != null) {
max =
Integer.parseInt(config.getValue("miniFrostAutoRefreshMaxBoards"));
- Logger.info(this, "Max: "+Integer.toString(max));
+ Logger.info(this, "Max boards: "+Integer.toString(max));
} else {
max = AutoRefresh.DEFAULT_MAX_BOARDS_REFRESHING;
}
maxBoards.setSelectedIndex(max-MIN_BOARDS);
+
+
+ if (config.getValue("miniFrostArchiveAfter") != null) {
+ max =
Integer.parseInt(config.getValue("miniFrostArchiveAfter"));
+ Logger.info(this, "Archive after:
"+Integer.toString(max));
+ } else {
+ max = MiniFrost.DEFAULT_ARCHIVE_AFTER;
+ }
+
+ archiveAfter.setSelectedIndex(max-MIN_DAYS);
+
+
+ if (config.getValue("miniFrostDeleteAfter") != null) {
+ max =
Integer.parseInt(config.getValue("miniFrostDeleteAfter"));
+ Logger.info(this, "Delete after:
"+Integer.toString(max));
+ } else {
+ max = MiniFrost.DEFAULT_DELETE_AFTER;
+ }
+
+ deleteAfter.setSelectedIndex(max-MIN_DAYS);
}
+ private String extractNumber(JComboBox box) {
+ String[] split = ((String)box.getSelectedItem()).split(" ");
+ return split[0];
+ }
+
+
public void update(Observable o, Object param) {
if (param == configWindow.getOkButton()) {
config.setValue("miniFrostAutoRefreshMaxBoards",
(String)maxBoards.getSelectedItem());
+ config.setValue("miniFrostArchiveAfter",
+ extractNumber(archiveAfter));
+
+ config.setValue("miniFrostDeleteAfter",
+ extractNumber(deleteAfter));
+
} else if (param == configWindow.getCancelButton()) {
selectValue();
Modified:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
2007-08-02 16:32:17 UTC (rev 14467)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
2007-08-02 18:57:47 UTC (rev 14468)
@@ -74,6 +74,33 @@
return true;
}
+
+ public boolean cleanUp(int archiveAfter, int deleteAfter) {
+ try {
+ synchronized(db.dbLock) {
+ PreparedStatement st;
+
+ java.sql.Timestamp timestamp = new
java.sql.Timestamp(new Date().getTime() - (deleteAfter * 24 * 60*60*1000));
+
+ st =
db.getConnection().prepareStatement("DELETE from frostKSKMessages WHERE date <
?");
+ st.setTimestamp(1, timestamp);
+ st.execute();
+
+
+ timestamp = new java.sql.Timestamp(new
Date().getTime() - (archiveAfter * 24 * 60*60*1000));
+
+ st =
db.getConnection().prepareStatement("UPDATE frostKSKMessages SET archived =
TRUE WHERE date < ?");
+ st.setTimestamp(1, timestamp);
+ st.execute();
+ }
+ } catch(SQLException e) {
+ Logger.error(this, "Can't cleanup the db because :
"+e.toString());
+ }
+
+ return true;
+ }
+
+
public MiniFrost getPlugin() {
return plugin;
}
Modified:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/BoardFactory.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/BoardFactory.java
2007-08-02 16:32:17 UTC (rev 14467)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/interfaces/BoardFactory.java
2007-08-02 18:57:47 UTC (rev 14468)
@@ -17,6 +17,8 @@
MiniFrost miniFrost);
+ public boolean cleanUp(int archiveAfter, int deleteAfter);
+
/**
* @return all the boards managed by this factory
*/