From d931e3ef909e8985dd79090252f670e0ede7fc94 Mon Sep 17 00:00:00 2001
From: Kelly Rauchenberger <fefferburbia@gmail.com>
Date: Mon, 1 Sep 2008 14:09:11 +0000
Subject: Client: Added Unread flag

Next step is to implement the "Mark as ...." options. Refs #49
---
 .../com/fourisland/instadisc/Database/Item.java    |  26 ++-
 .../com/fourisland/instadisc/Database/Wrapper.java | 255 ++++++++++++++-------
 .../instadisc/IDItemListCellRenderer.java          |  34 ++-
 .../com/fourisland/instadisc/InstaDiscView.java    |   7 +-
 .../instadisc/Item/Categories/Unread.java          |   6 +
 .../src/com/fourisland/instadisc/Item/Item.java    |   3 +
 6 files changed, 241 insertions(+), 90 deletions(-)
 create mode 100644 client/trunk/src/com/fourisland/instadisc/Item/Categories/Unread.java

(limited to 'client/trunk/src')

diff --git a/client/trunk/src/com/fourisland/instadisc/Database/Item.java b/client/trunk/src/com/fourisland/instadisc/Database/Item.java
index 7dbc89b..3a31eb5 100644
--- a/client/trunk/src/com/fourisland/instadisc/Database/Item.java
+++ b/client/trunk/src/com/fourisland/instadisc/Database/Item.java
@@ -6,6 +6,7 @@ package com.fourisland.instadisc.Database;
 
 import com.sleepycat.persist.model.Entity;
 import com.sleepycat.persist.model.PrimaryKey;
+import java.util.Date;
 import java.util.HashMap;
 
 /**
@@ -22,9 +23,12 @@ public class Item {
     private String author;
     private String url;
     private HashMap<String, String> semantics;
+    private Boolean unread;
+    private Date recieved;
 
     public Item() {
         semantics = new HashMap<String, String>();
+        unread = true;
     }
 
     public Integer getID() {
@@ -48,7 +52,17 @@ public class Item {
     }
 
     public HashMap<String, String> getSemantics() {
-        return semantics;
+        return semantics;   
+    }
+    
+    public Boolean getUnread()
+    {
+        return unread;
+    }
+    
+    public Date getRecieved()
+    {
+        return recieved;
     }
 
     public void setID(Integer id) {
@@ -74,6 +88,16 @@ public class Item {
     public void setSemantics(HashMap<String, String> semantics) {
         this.semantics = semantics;
     }
+    
+    public void setUnread(Boolean unread)
+    {
+        this.unread = unread;
+    }
+    
+    public void setRecieved(Date recieved)
+    {
+        this.recieved = recieved;
+    }
 
     public String getSemantics(String key) {
         return semantics.get(key);
diff --git a/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java b/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java
index 5945e9b..40040d9 100644
--- a/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java
+++ b/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java
@@ -40,32 +40,39 @@ public class Wrapper {
         esConfig.setAllowCreate(true);
         envConfig.setTransactional(true);
         esConfig.setTransactional(true);
-        try {
+        try
+        {
             e = new Environment(new File(loc), envConfig);
             es = new EntityStore(e, "EntityStore", esConfig);
-        } catch (DatabaseException ex) {
+        } catch (DatabaseException ex)
+        {
             Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex);
             System.exit(1);
         }
         Runtime.getRuntime().addShutdownHook(new Thread(new CloseEnvironmentThread(e)));
         Runtime.getRuntime().addShutdownHook(new Thread(new CloseEntityStoreThread(es)));
 
-        try {
+        try
+        {
             oldVerID = es.getPrimaryIndex(Integer.class, OldVerID.class);
             idConfig = es.getPrimaryIndex(String.class, IDConfig.class);
             subscription = es.getPrimaryIndex(String.class, Subscription.class);
             filter = es.getPrimaryIndex(Integer.class, Filter.class);
             item = es.getPrimaryIndex(Integer.class, Item.class);
-        } catch (DatabaseException ex) {
+        } catch (DatabaseException ex)
+        {
             Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex);
         }
     }
 
     public static String getConfig(String key) {
-        synchronized (idConfig) {
-            try {
+        synchronized (idConfig)
+        {
+            try
+            {
                 return idConfig.get(key).getValue();
-            } catch (DatabaseException ex) {
+            } catch (DatabaseException ex)
+            {
                 Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex);
                 return "";
             }
@@ -73,16 +80,21 @@ public class Wrapper {
     }
 
     public static void setConfig(String key, String value) {
-        synchronized (idConfig) {
-            try {
+        synchronized (idConfig)
+        {
+            try
+            {
                 Transaction t = e.beginTransaction(null, null);
 
-                try {
-                    if (idConfig.contains(key)) {
+                try
+                {
+                    if (idConfig.contains(key))
+                    {
                         IDConfig temp = idConfig.get(key);
                         temp.setValue(value);
                         idConfig.put(t, temp);
-                    } else {
+                    } else
+                    {
                         IDConfig temp = new IDConfig();
                         temp.setKey(key);
                         temp.setValue(value);
@@ -90,29 +102,36 @@ public class Wrapper {
                     }
 
                     t.commit();
-                } catch (Exception ex) {
+                } catch (Exception ex)
+                {
                     t.abort();
                 }
-            } catch (DatabaseException ex) {
+            } catch (DatabaseException ex)
+            {
                 Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex);
             }
         }
     }
 
     public static boolean containsOldVerID(Integer id) {
-        try {
+        try
+        {
             return oldVerID.contains(id);
-        } catch (DatabaseException ex) {
+        } catch (DatabaseException ex)
+        {
             Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex);
             return false;
         }
     }
 
     public static int countOldVerID() {
-        synchronized (oldVerID) {
-            try {
+        synchronized (oldVerID)
+        {
+            try
+            {
                 return (int) oldVerID.count();
-            } catch (DatabaseException ex) {
+            } catch (DatabaseException ex)
+            {
                 Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex);
                 return 0;
             }
@@ -120,49 +139,62 @@ public class Wrapper {
     }
 
     public static void addOldVerID(Integer id) {
-        synchronized (oldVerID) {
-            try {
+        synchronized (oldVerID)
+        {
+            try
+            {
                 Transaction t = e.beginTransaction(null, null);
 
-                try {
+                try
+                {
                     OldVerID temp = new OldVerID();
                     temp.setID(id);
                     oldVerID.put(t, temp);
 
                     t.commit();
-                } catch (Exception ex) {
+                } catch (Exception ex)
+                {
                     t.abort();
                 }
-            } catch (DatabaseException ex) {
+            } catch (DatabaseException ex)
+            {
                 Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex);
             }
         }
     }
-    
+
     public static void dropFromTopOldVerID() {
-        synchronized (oldVerID) {
-            try {
+        synchronized (oldVerID)
+        {
+            try
+            {
                 Transaction t = e.beginTransaction(null, null);
 
-                try {
+                try
+                {
                     Iterator<Entry<Integer, OldVerID>> i = oldVerID.map().entrySet().iterator();
                     oldVerID.delete(t, i.next().getKey());
 
                     t.commit();
-                } catch (Exception ex) {
+                } catch (Exception ex)
+                {
                     t.abort();
                 }
-            } catch (DatabaseException ex) {
+            } catch (DatabaseException ex)
+            {
                 Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex);
             }
         }
     }
 
     public static Subscription getSubscription(String url) {
-        synchronized (subscription) {
-            try {
+        synchronized (subscription)
+        {
+            try
+            {
                 return subscription.get(url);
-            } catch (DatabaseException ex) {
+            } catch (DatabaseException ex)
+            {
                 Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex);
                 return null;
             }
@@ -170,10 +202,13 @@ public class Wrapper {
     }
 
     public static boolean existsSubscription(String url) {
-        synchronized (subscription) {
-            try {
+        synchronized (subscription)
+        {
+            try
+            {
                 return subscription.contains(url);
-            } catch (DatabaseException ex) {
+            } catch (DatabaseException ex)
+            {
                 Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex);
                 return false;
             }
@@ -181,30 +216,37 @@ public class Wrapper {
     }
 
     public static void addSubscription(Subscription s) {
-        synchronized (subscription) {
-            try {
+        synchronized (subscription)
+        {
+            try
+            {
                 Transaction t = e.beginTransaction(null, null);
 
-                try {
+                try
+                {
                     subscription.put(t, s);
 
                     t.commit();
-                } catch (Exception ex) {
+                } catch (Exception ex)
+                {
                     t.abort();
                 }
-            } catch (DatabaseException ex) {
+            } catch (DatabaseException ex)
+            {
                 Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex);
             }
         }
     }
 
     public static Subscription[] getAllSubscription() {
-        synchronized (subscription) {
+        synchronized (subscription)
+        {
             Collection vals = subscription.map().values();
             Subscription subs[] = new Subscription[vals.size()];
             Iterator i = vals.iterator();
             int j = 0;
-            while (i.hasNext()) {
+            while (i.hasNext())
+            {
                 subs[j] = (Subscription) i.next();
                 j++;
             }
@@ -213,51 +255,65 @@ public class Wrapper {
     }
 
     public static void deleteSubscription(String url) {
-        synchronized (subscription) {
-            try {
+        synchronized (subscription)
+        {
+            try
+            {
                 Transaction t = e.beginTransaction(null, null);
 
-                try {
+                try
+                {
                     subscription.delete(t, url);
 
                     t.commit();
-                } catch (Exception ex) {
+                } catch (Exception ex)
+                {
                     t.abort();
                 }
-            } catch (DatabaseException ex) {
+            } catch (DatabaseException ex)
+            {
                 Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex);
             }
         }
     }
 
     public static void addFilter(Filter f) {
-        if (f.getID() == -65536) {
+        if (f.getID() == -65536)
+        {
             f.setID(Integer.decode(Wrapper.getConfig("nextFilterID")));
             Wrapper.setConfig("nextFilterID", Integer.toString(Integer.decode(Wrapper.getConfig("nextFilterID")) + 1));
         }
 
-        synchronized (filter) {
-            try {
+        synchronized (filter)
+        {
+            try
+            {
                 Transaction t = e.beginTransaction(null, null);
 
-                try {
+                try
+                {
                     filter.put(t, f);
 
                     t.commit();
-                } catch (Exception ex) {
+                } catch (Exception ex)
+                {
                     t.abort();
                 }
-            } catch (DatabaseException ex) {
+            } catch (DatabaseException ex)
+            {
                 Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex);
             }
         }
     }
 
     public static Filter getFilter(Integer id) {
-        synchronized (filter) {
-            try {
+        synchronized (filter)
+        {
+            try
+            {
                 return filter.get(id);
-            } catch (DatabaseException ex) {
+            } catch (DatabaseException ex)
+            {
                 Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex);
                 return null;
             }
@@ -265,30 +321,37 @@ public class Wrapper {
     }
 
     public static void deleteFilter(Integer id) {
-        synchronized (filter) {
-            try {
+        synchronized (filter)
+        {
+            try
+            {
                 Transaction t = e.beginTransaction(null, null);
 
-                try {
+                try
+                {
                     filter.delete(t, id);
 
                     t.commit();
-                } catch (Exception ex) {
+                } catch (Exception ex)
+                {
                     t.abort();
                 }
-            } catch (DatabaseException ex) {
+            } catch (DatabaseException ex)
+            {
                 Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex);
             }
         }
     }
 
     public static Filter[] getAllFilter() {
-        synchronized (filter) {
+        synchronized (filter)
+        {
             Collection vals = filter.map().values();
             Filter fils[] = new Filter[vals.size()];
             Iterator i = vals.iterator();
             int j = 0;
-            while (i.hasNext()) {
+            while (i.hasNext())
+            {
                 fils[j] = (Filter) i.next();
                 j++;
             }
@@ -297,37 +360,45 @@ public class Wrapper {
     }
 
     public static Integer countItem() {
-        synchronized (item) {
+        synchronized (item)
+        {
             return item.map().size();
         }
     }
 
     public static void dropFromTopItem() {
-        synchronized (item) {
-            try {
+        synchronized (item)
+        {
+            try
+            {
                 Transaction t = e.beginTransaction(null, null);
 
-                try {
+                try
+                {
                     Iterator<Entry<Integer, Item>> i = item.map().entrySet().iterator();
                     item.delete(t, i.next().getKey());
 
                     t.commit();
-                } catch (Exception ex) {
+                } catch (Exception ex)
+                {
                     t.abort();
                 }
-            } catch (DatabaseException ex) {
+            } catch (DatabaseException ex)
+            {
                 Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex);
             }
         }
     }
 
     public static Item[] getAllItem() {
-        synchronized (item) {
+        synchronized (item)
+        {
             Collection vals = item.map().values();
             Item items[] = new Item[vals.size()];
             Iterator i = vals.iterator();
             int j = 0;
-            while (i.hasNext()) {
+            while (i.hasNext())
+            {
                 items[j] = (Item) i.next();
                 j++;
             }
@@ -336,18 +407,48 @@ public class Wrapper {
     }
 
     public static void addItem(Item i) {
-        synchronized (item) {
-            try {
+        synchronized (item)
+        {
+            try
+            {
                 Transaction t = e.beginTransaction(null, null);
 
-                try {
+                try
+                {
                     item.put(t, i);
 
                     t.commit();
-                } catch (Exception ex) {
+                } catch (Exception ex)
+                {
+                    t.abort();
+                }
+            } catch (DatabaseException ex)
+            {
+                Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex);
+            }
+        }
+    }
+
+    public static void setUnreadFlagItem(Integer id, Boolean value) {
+        synchronized (item)
+        {
+            try
+            {
+                Transaction t = e.beginTransaction(null, null);
+                
+                try
+                {
+                    Item i = item.get(id);
+                    i.setUnread(value);
+                    item.put(t, i);
+                    
+                    t.commit();
+                } catch (Exception ex)
+                {
                     t.abort();
                 }
-            } catch (DatabaseException ex) {
+            } catch (DatabaseException ex)
+            {
                 Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex);
             }
         }
diff --git a/client/trunk/src/com/fourisland/instadisc/IDItemListCellRenderer.java b/client/trunk/src/com/fourisland/instadisc/IDItemListCellRenderer.java
index 21924e8..dd14b21 100644
--- a/client/trunk/src/com/fourisland/instadisc/IDItemListCellRenderer.java
+++ b/client/trunk/src/com/fourisland/instadisc/IDItemListCellRenderer.java
@@ -8,6 +8,8 @@ import com.fourisland.instadisc.Database.Item;
 import com.fourisland.instadisc.Database.Wrapper;
 import com.fourisland.instadisc.Item.Categories.Category;
 import java.awt.Component;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
 import javax.swing.JLabel;
 import javax.swing.JList;
 import javax.swing.ListCellRenderer;
@@ -23,20 +25,32 @@ public class IDItemListCellRenderer extends JLabel implements ListCellRenderer {
 
         this.setIcon(Category.iconFromCategory(Wrapper.getSubscription(item.getSubscription()).getCategory()));
 
-        if (item.getAuthor().equals("")) {
+        if (item.getAuthor().equals(""))
+        {
             this.setText("<HTML><I>" + Wrapper.getSubscription(item.getSubscription()).getTitle() + "</I>, <B>" + item.getTitle() + "</B>");
-        } else {
+        } else
+        {
             this.setText("<HTML><I>" + Wrapper.getSubscription(item.getSubscription()).getTitle() + "</I>, <B>" + item.getTitle() + "</B> by " + item.getAuthor());
         }
+        
+        if (item.getUnread())
+        {
+            this.setText(this.getText() + "<BR><B>New </B> at " + new SimpleDateFormat("EEEE, MMMM d yyyy k:mm aa").format(item.getRecieved()));
+        }
+        
+        if (arg3)
+        {
+            this.setForeground(arg0.getSelectionForeground());
+            this.setBackground(arg0.getSelectionBackground());
+        } else
+        {
+            this.setForeground(arg0.getForeground());
 
-        /*if (item.getUnread()) {
-        this.setBackground(Color.YELLOW);
-        } else */        {
-            if (arg3) {
-                this.setForeground(arg0.getSelectionForeground());
-                this.setBackground(arg0.getSelectionBackground());
-            } else {
-                this.setForeground(arg0.getForeground());
+            if (item.getUnread())
+            {
+                this.setBackground(java.awt.Color.yellow);
+            } else
+            {
                 this.setBackground(arg0.getBackground());
             }
         }
diff --git a/client/trunk/src/com/fourisland/instadisc/InstaDiscView.java b/client/trunk/src/com/fourisland/instadisc/InstaDiscView.java
index 6f7b397..a7a3308 100644
--- a/client/trunk/src/com/fourisland/instadisc/InstaDiscView.java
+++ b/client/trunk/src/com/fourisland/instadisc/InstaDiscView.java
@@ -330,9 +330,12 @@ public class InstaDiscView extends FrameView {
             try {
                 if (java.awt.Desktop.isDesktopSupported())
                 {
+                    Wrapper.setUnreadFlagItem(item.getID(), false);
+                    refreshItemPane();
+                    
                     java.awt.Desktop.getDesktop().browse(new URI(item.getURL()));
                 } else {
-                    statusMessageLabel.setText("Error: Desktop not supported");
+                    doText("Error: Desktop not supported");
                 }
             } catch (IOException ex) {
                 Logger.getLogger(InstaDiscView.class.getName()).log(Level.SEVERE, null, ex);
@@ -378,7 +381,7 @@ public class InstaDiscView extends FrameView {
             {
                 java.awt.Desktop.getDesktop().browse(new URI("http://fourisland.com/projects/instadisc/"));
             } else {
-                statusMessageLabel.setText("Error: Desktop not supported");
+                doText("Error: Desktop not supported");
             }
         } catch (IOException ex)
         {
diff --git a/client/trunk/src/com/fourisland/instadisc/Item/Categories/Unread.java b/client/trunk/src/com/fourisland/instadisc/Item/Categories/Unread.java
new file mode 100644
index 0000000..c3df46e
--- /dev/null
+++ b/client/trunk/src/com/fourisland/instadisc/Item/Categories/Unread.java
@@ -0,0 +1,6 @@
+package com.fourisland.instadisc.Item.Categories;
+
+public class Unread
+{
+	public static byte[] unread = new byte[] {-119,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,0,16,0,0,0,16,8,6,0,0,0,31,-13,-1,97,0,0,0,4,103,65,77,65,0,0,-81,-56,55,5,-118,-23,0,0,0,25,116,69,88,116,83,111,102,116,119,97,114,101,0,65,100,111,98,101,32,73,109,97,103,101,82,101,97,100,121,113,-55,101,60,0,0,1,12,73,68,65,84,56,-53,-35,-110,-63,74,2,81,20,-122,47,-76,-19,1,124,-125,-34,35,122,-127,54,61,-126,-53,90,-42,-50,85,-101,-111,-64,77,98,16,-76,78,87,-83,36,-93,-123,-85,89,72,32,-72,80,36,44,-80,104,54,78,-112,-125,98,26,95,-25,-36,51,99,-24,-74,-123,-32,-64,-57,25,-26,-36,-1,-101,115,-25,-114,3,-36,127,112,-37,32,8,-36,-71,16,-89,-75,32,68,66,81,72,-124,-66,-48,18,106,-62,-66,-112,79,57,22,-70,90,-99,15,79,99,-72,61,-64,-121,-109,-56,-18,-65,19,-120,-5,-16,-47,-126,94,13,74,-69,112,-97,55,52,60,-22,-62,101,14,21,76,-104,79,-16,18,125,-85,6,-101,-89,120,-111,10,53,56,29,-55,-77,51,120,125,48,-18,-114,-32,107,-88,-3,-95,91,-122,-38,87,22,-52,4,-117,-103,77,-16,30,66,-25,6,-58,111,-16,-7,108,-63,-24,9,94,26,42,104,-4,9,-76,-22,20,-21,19,4,46,-92,-72,99,-62,65,93,-74,83,-123,-97,57,92,-17,105,-1,112,85,-96,65,-67,-42,39,-56,-74,-39,-82,-64,-29,-119,-83,9,-12,16,-20,20,-78,47,-82,-75,-20,27,86,103,-23,41,-124,-62,-123,-105,4,-82,-78,-78,102,91,-2,-60,77,11,126,1,8,106,-3,60,98,109,109,37,0,0,0,0,73,69,78,68,-82,66,96,-126,-1};
+}
diff --git a/client/trunk/src/com/fourisland/instadisc/Item/Item.java b/client/trunk/src/com/fourisland/instadisc/Item/Item.java
index 927101b..2fe97dc 100644
--- a/client/trunk/src/com/fourisland/instadisc/Item/Item.java
+++ b/client/trunk/src/com/fourisland/instadisc/Item/Item.java
@@ -10,6 +10,7 @@ import com.fourisland.instadisc.InstaDiscView;
 import com.fourisland.instadisc.XmlRpc;
 import java.awt.SystemTray;
 import java.awt.TrayIcon.MessageType;
+import java.util.Calendar;
 import java.util.HashMap;
 
 /**
@@ -54,6 +55,8 @@ public class Item {
             temp.remove("URL");
             item.setSemantics(temp);
             
+            item.setUnread(true);
+            item.setRecieved(Calendar.getInstance().getTime());
             Wrapper.addItem(item);
 
             ((InstaDiscView) InstaDiscApp.getApplication().getMainView()).refreshItemPane();
-- 
cgit 1.4.1