diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2008-09-01 14:09:11 +0000 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2008-09-01 14:09:11 +0000 |
| commit | d931e3ef909e8985dd79090252f670e0ede7fc94 (patch) | |
| tree | 9afc3f9e7849da775025b3f2ff6bcb8caccbc055 /client | |
| parent | 0c8f56b4f22deac3f30d0d746e2341d53a13c880 (diff) | |
| download | instadisc-d931e3ef909e8985dd79090252f670e0ede7fc94.tar.gz instadisc-d931e3ef909e8985dd79090252f670e0ede7fc94.tar.bz2 instadisc-d931e3ef909e8985dd79090252f670e0ede7fc94.zip | |
Client: Added Unread flag
Next step is to implement the "Mark as ...." options. Refs #49
Diffstat (limited to 'client')
6 files changed, 241 insertions, 90 deletions
| 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; | |||
| 6 | 6 | ||
| 7 | import com.sleepycat.persist.model.Entity; | 7 | import com.sleepycat.persist.model.Entity; |
| 8 | import com.sleepycat.persist.model.PrimaryKey; | 8 | import com.sleepycat.persist.model.PrimaryKey; |
| 9 | import java.util.Date; | ||
| 9 | import java.util.HashMap; | 10 | import java.util.HashMap; |
| 10 | 11 | ||
| 11 | /** | 12 | /** |
| @@ -22,9 +23,12 @@ public class Item { | |||
| 22 | private String author; | 23 | private String author; |
| 23 | private String url; | 24 | private String url; |
| 24 | private HashMap<String, String> semantics; | 25 | private HashMap<String, String> semantics; |
| 26 | private Boolean unread; | ||
| 27 | private Date recieved; | ||
| 25 | 28 | ||
| 26 | public Item() { | 29 | public Item() { |
| 27 | semantics = new HashMap<String, String>(); | 30 | semantics = new HashMap<String, String>(); |
| 31 | unread = true; | ||
| 28 | } | 32 | } |
| 29 | 33 | ||
| 30 | public Integer getID() { | 34 | public Integer getID() { |
| @@ -48,7 +52,17 @@ public class Item { | |||
| 48 | } | 52 | } |
| 49 | 53 | ||
| 50 | public HashMap<String, String> getSemantics() { | 54 | public HashMap<String, String> getSemantics() { |
| 51 | return semantics; | 55 | return semantics; |
| 56 | } | ||
| 57 | |||
| 58 | public Boolean getUnread() | ||
| 59 | { | ||
| 60 | return unread; | ||
| 61 | } | ||
| 62 | |||
| 63 | public Date getRecieved() | ||
| 64 | { | ||
| 65 | return recieved; | ||
| 52 | } | 66 | } |
| 53 | 67 | ||
| 54 | public void setID(Integer id) { | 68 | public void setID(Integer id) { |
| @@ -74,6 +88,16 @@ public class Item { | |||
| 74 | public void setSemantics(HashMap<String, String> semantics) { | 88 | public void setSemantics(HashMap<String, String> semantics) { |
| 75 | this.semantics = semantics; | 89 | this.semantics = semantics; |
| 76 | } | 90 | } |
| 91 | |||
| 92 | public void setUnread(Boolean unread) | ||
| 93 | { | ||
| 94 | this.unread = unread; | ||
| 95 | } | ||
| 96 | |||
| 97 | public void setRecieved(Date recieved) | ||
| 98 | { | ||
| 99 | this.recieved = recieved; | ||
| 100 | } | ||
| 77 | 101 | ||
| 78 | public String getSemantics(String key) { | 102 | public String getSemantics(String key) { |
| 79 | return semantics.get(key); | 103 | 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 { | |||
| 40 | esConfig.setAllowCreate(true); | 40 | esConfig.setAllowCreate(true); |
| 41 | envConfig.setTransactional(true); | 41 | envConfig.setTransactional(true); |
| 42 | esConfig.setTransactional(true); | 42 | esConfig.setTransactional(true); |
| 43 | try { | 43 | try |
| 44 | { | ||
| 44 | e = new Environment(new File(loc), envConfig); | 45 | e = new Environment(new File(loc), envConfig); |
| 45 | es = new EntityStore(e, "EntityStore", esConfig); | 46 | es = new EntityStore(e, "EntityStore", esConfig); |
| 46 | } catch (DatabaseException ex) { | 47 | } catch (DatabaseException ex) |
| 48 | { | ||
| 47 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 49 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
| 48 | System.exit(1); | 50 | System.exit(1); |
| 49 | } | 51 | } |
| 50 | Runtime.getRuntime().addShutdownHook(new Thread(new CloseEnvironmentThread(e))); | 52 | Runtime.getRuntime().addShutdownHook(new Thread(new CloseEnvironmentThread(e))); |
| 51 | Runtime.getRuntime().addShutdownHook(new Thread(new CloseEntityStoreThread(es))); | 53 | Runtime.getRuntime().addShutdownHook(new Thread(new CloseEntityStoreThread(es))); |
| 52 | 54 | ||
| 53 | try { | 55 | try |
| 56 | { | ||
| 54 | oldVerID = es.getPrimaryIndex(Integer.class, OldVerID.class); | 57 | oldVerID = es.getPrimaryIndex(Integer.class, OldVerID.class); |
| 55 | idConfig = es.getPrimaryIndex(String.class, IDConfig.class); | 58 | idConfig = es.getPrimaryIndex(String.class, IDConfig.class); |
| 56 | subscription = es.getPrimaryIndex(String.class, Subscription.class); | 59 | subscription = es.getPrimaryIndex(String.class, Subscription.class); |
| 57 | filter = es.getPrimaryIndex(Integer.class, Filter.class); | 60 | filter = es.getPrimaryIndex(Integer.class, Filter.class); |
| 58 | item = es.getPrimaryIndex(Integer.class, Item.class); | 61 | item = es.getPrimaryIndex(Integer.class, Item.class); |
| 59 | } catch (DatabaseException ex) { | 62 | } catch (DatabaseException ex) |
| 63 | { | ||
| 60 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 64 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
| 61 | } | 65 | } |
| 62 | } | 66 | } |
| 63 | 67 | ||
| 64 | public static String getConfig(String key) { | 68 | public static String getConfig(String key) { |
| 65 | synchronized (idConfig) { | 69 | synchronized (idConfig) |
| 66 | try { | 70 | { |
| 71 | try | ||
| 72 | { | ||
| 67 | return idConfig.get(key).getValue(); | 73 | return idConfig.get(key).getValue(); |
| 68 | } catch (DatabaseException ex) { | 74 | } catch (DatabaseException ex) |
| 75 | { | ||
| 69 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 76 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
| 70 | return ""; | 77 | return ""; |
| 71 | } | 78 | } |
| @@ -73,16 +80,21 @@ public class Wrapper { | |||
| 73 | } | 80 | } |
| 74 | 81 | ||
| 75 | public static void setConfig(String key, String value) { | 82 | public static void setConfig(String key, String value) { |
| 76 | synchronized (idConfig) { | 83 | synchronized (idConfig) |
| 77 | try { | 84 | { |
| 85 | try | ||
| 86 | { | ||
| 78 | Transaction t = e.beginTransaction(null, null); | 87 | Transaction t = e.beginTransaction(null, null); |
| 79 | 88 | ||
| 80 | try { | 89 | try |
| 81 | if (idConfig.contains(key)) { | 90 | { |
| 91 | if (idConfig.contains(key)) | ||
| 92 | { | ||
| 82 | IDConfig temp = idConfig.get(key); | 93 | IDConfig temp = idConfig.get(key); |
| 83 | temp.setValue(value); | 94 | temp.setValue(value); |
| 84 | idConfig.put(t, temp); | 95 | idConfig.put(t, temp); |
| 85 | } else { | 96 | } else |
| 97 | { | ||
| 86 | IDConfig temp = new IDConfig(); | 98 | IDConfig temp = new IDConfig(); |
| 87 | temp.setKey(key); | 99 | temp.setKey(key); |
| 88 | temp.setValue(value); | 100 | temp.setValue(value); |
| @@ -90,29 +102,36 @@ public class Wrapper { | |||
| 90 | } | 102 | } |
| 91 | 103 | ||
| 92 | t.commit(); | 104 | t.commit(); |
| 93 | } catch (Exception ex) { | 105 | } catch (Exception ex) |
| 106 | { | ||
| 94 | t.abort(); | 107 | t.abort(); |
| 95 | } | 108 | } |
| 96 | } catch (DatabaseException ex) { | 109 | } catch (DatabaseException ex) |
| 110 | { | ||
| 97 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 111 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
| 98 | } | 112 | } |
| 99 | } | 113 | } |
| 100 | } | 114 | } |
| 101 | 115 | ||
| 102 | public static boolean containsOldVerID(Integer id) { | 116 | public static boolean containsOldVerID(Integer id) { |
| 103 | try { | 117 | try |
| 118 | { | ||
| 104 | return oldVerID.contains(id); | 119 | return oldVerID.contains(id); |
| 105 | } catch (DatabaseException ex) { | 120 | } catch (DatabaseException ex) |
| 121 | { | ||
| 106 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 122 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
| 107 | return false; | 123 | return false; |
| 108 | } | 124 | } |
| 109 | } | 125 | } |
| 110 | 126 | ||
| 111 | public static int countOldVerID() { | 127 | public static int countOldVerID() { |
| 112 | synchronized (oldVerID) { | 128 | synchronized (oldVerID) |
| 113 | try { | 129 | { |
| 130 | try | ||
| 131 | { | ||
| 114 | return (int) oldVerID.count(); | 132 | return (int) oldVerID.count(); |
| 115 | } catch (DatabaseException ex) { | 133 | } catch (DatabaseException ex) |
| 134 | { | ||
| 116 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 135 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
| 117 | return 0; | 136 | return 0; |
| 118 | } | 137 | } |
| @@ -120,49 +139,62 @@ public class Wrapper { | |||
| 120 | } | 139 | } |
| 121 | 140 | ||
| 122 | public static void addOldVerID(Integer id) { | 141 | public static void addOldVerID(Integer id) { |
| 123 | synchronized (oldVerID) { | 142 | synchronized (oldVerID) |
| 124 | try { | 143 | { |
| 144 | try | ||
| 145 | { | ||
| 125 | Transaction t = e.beginTransaction(null, null); | 146 | Transaction t = e.beginTransaction(null, null); |
| 126 | 147 | ||
| 127 | try { | 148 | try |
| 149 | { | ||
| 128 | OldVerID temp = new OldVerID(); | 150 | OldVerID temp = new OldVerID(); |
| 129 | temp.setID(id); | 151 | temp.setID(id); |
| 130 | oldVerID.put(t, temp); | 152 | oldVerID.put(t, temp); |
| 131 | 153 | ||
| 132 | t.commit(); | 154 | t.commit(); |
| 133 | } catch (Exception ex) { | 155 | } catch (Exception ex) |
| 156 | { | ||
| 134 | t.abort(); | 157 | t.abort(); |
| 135 | } | 158 | } |
| 136 | } catch (DatabaseException ex) { | 159 | } catch (DatabaseException ex) |
| 160 | { | ||
| 137 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 161 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
| 138 | } | 162 | } |
| 139 | } | 163 | } |
| 140 | } | 164 | } |
| 141 | 165 | ||
| 142 | public static void dropFromTopOldVerID() { | 166 | public static void dropFromTopOldVerID() { |
| 143 | synchronized (oldVerID) { | 167 | synchronized (oldVerID) |
| 144 | try { | 168 | { |
| 169 | try | ||
| 170 | { | ||
| 145 | Transaction t = e.beginTransaction(null, null); | 171 | Transaction t = e.beginTransaction(null, null); |
| 146 | 172 | ||
| 147 | try { | 173 | try |
| 174 | { | ||
| 148 | Iterator<Entry<Integer, OldVerID>> i = oldVerID.map().entrySet().iterator(); | 175 | Iterator<Entry<Integer, OldVerID>> i = oldVerID.map().entrySet().iterator(); |
| 149 | oldVerID.delete(t, i.next().getKey()); | 176 | oldVerID.delete(t, i.next().getKey()); |
| 150 | 177 | ||
| 151 | t.commit(); | 178 | t.commit(); |
| 152 | } catch (Exception ex) { | 179 | } catch (Exception ex) |
| 180 | { | ||
| 153 | t.abort(); | 181 | t.abort(); |
| 154 | } | 182 | } |
| 155 | } catch (DatabaseException ex) { | 183 | } catch (DatabaseException ex) |
| 184 | { | ||
| 156 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 185 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
| 157 | } | 186 | } |
| 158 | } | 187 | } |
| 159 | } | 188 | } |
| 160 | 189 | ||
| 161 | public static Subscription getSubscription(String url) { | 190 | public static Subscription getSubscription(String url) { |
| 162 | synchronized (subscription) { | 191 | synchronized (subscription) |
| 163 | try { | 192 | { |
| 193 | try | ||
| 194 | { | ||
| 164 | return subscription.get(url); | 195 | return subscription.get(url); |
| 165 | } catch (DatabaseException ex) { | 196 | } catch (DatabaseException ex) |
| 197 | { | ||
| 166 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 198 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
| 167 | return null; | 199 | return null; |
| 168 | } | 200 | } |
| @@ -170,10 +202,13 @@ public class Wrapper { | |||
| 170 | } | 202 | } |
| 171 | 203 | ||
| 172 | public static boolean existsSubscription(String url) { | 204 | public static boolean existsSubscription(String url) { |
| 173 | synchronized (subscription) { | 205 | synchronized (subscription) |
| 174 | try { | 206 | { |
| 207 | try | ||
| 208 | { | ||
| 175 | return subscription.contains(url); | 209 | return subscription.contains(url); |
| 176 | } catch (DatabaseException ex) { | 210 | } catch (DatabaseException ex) |
| 211 | { | ||
| 177 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 212 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
| 178 | return false; | 213 | return false; |
| 179 | } | 214 | } |
| @@ -181,30 +216,37 @@ public class Wrapper { | |||
| 181 | } | 216 | } |
| 182 | 217 | ||
| 183 | public static void addSubscription(Subscription s) { | 218 | public static void addSubscription(Subscription s) { |
| 184 | synchronized (subscription) { | 219 | synchronized (subscription) |
| 185 | try { | 220 | { |
| 221 | try | ||
| 222 | { | ||
| 186 | Transaction t = e.beginTransaction(null, null); | 223 | Transaction t = e.beginTransaction(null, null); |
| 187 | 224 | ||
| 188 | try { | 225 | try |
| 226 | { | ||
| 189 | subscription.put(t, s); | 227 | subscription.put(t, s); |
| 190 | 228 | ||
| 191 | t.commit(); | 229 | t.commit(); |
| 192 | } catch (Exception ex) { | 230 | } catch (Exception ex) |
| 231 | { | ||
| 193 | t.abort(); | 232 | t.abort(); |
| 194 | } | 233 | } |
| 195 | } catch (DatabaseException ex) { | 234 | } catch (DatabaseException ex) |
| 235 | { | ||
| 196 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 236 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
| 197 | } | 237 | } |
| 198 | } | 238 | } |
| 199 | } | 239 | } |
| 200 | 240 | ||
| 201 | public static Subscription[] getAllSubscription() { | 241 | public static Subscription[] getAllSubscription() { |
| 202 | synchronized (subscription) { | 242 | synchronized (subscription) |
| 243 | { | ||
| 203 | Collection vals = subscription.map().values(); | 244 | Collection vals = subscription.map().values(); |
| 204 | Subscription subs[] = new Subscription[vals.size()]; | 245 | Subscription subs[] = new Subscription[vals.size()]; |
| 205 | Iterator i = vals.iterator(); | 246 | Iterator i = vals.iterator(); |
| 206 | int j = 0; | 247 | int j = 0; |
| 207 | while (i.hasNext()) { | 248 | while (i.hasNext()) |
| 249 | { | ||
| 208 | subs[j] = (Subscription) i.next(); | 250 | subs[j] = (Subscription) i.next(); |
| 209 | j++; | 251 | j++; |
| 210 | } | 252 | } |
| @@ -213,51 +255,65 @@ public class Wrapper { | |||
| 213 | } | 255 | } |
| 214 | 256 | ||
| 215 | public static void deleteSubscription(String url) { | 257 | public static void deleteSubscription(String url) { |
| 216 | synchronized (subscription) { | 258 | synchronized (subscription) |
| 217 | try { | 259 | { |
| 260 | try | ||
| 261 | { | ||
| 218 | Transaction t = e.beginTransaction(null, null); | 262 | Transaction t = e.beginTransaction(null, null); |
| 219 | 263 | ||
| 220 | try { | 264 | try |
| 265 | { | ||
| 221 | subscription.delete(t, url); | 266 | subscription.delete(t, url); |
| 222 | 267 | ||
| 223 | t.commit(); | 268 | t.commit(); |
| 224 | } catch (Exception ex) { | 269 | } catch (Exception ex) |
| 270 | { | ||
| 225 | t.abort(); | 271 | t.abort(); |
| 226 | } | 272 | } |
| 227 | } catch (DatabaseException ex) { | 273 | } catch (DatabaseException ex) |
| 274 | { | ||
| 228 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 275 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
| 229 | } | 276 | } |
| 230 | } | 277 | } |
| 231 | } | 278 | } |
| 232 | 279 | ||
| 233 | public static void addFilter(Filter f) { | 280 | public static void addFilter(Filter f) { |
| 234 | if (f.getID() == -65536) { | 281 | if (f.getID() == -65536) |
| 282 | { | ||
| 235 | f.setID(Integer.decode(Wrapper.getConfig("nextFilterID"))); | 283 | f.setID(Integer.decode(Wrapper.getConfig("nextFilterID"))); |
| 236 | Wrapper.setConfig("nextFilterID", Integer.toString(Integer.decode(Wrapper.getConfig("nextFilterID")) + 1)); | 284 | Wrapper.setConfig("nextFilterID", Integer.toString(Integer.decode(Wrapper.getConfig("nextFilterID")) + 1)); |
| 237 | } | 285 | } |
| 238 | 286 | ||
| 239 | synchronized (filter) { | 287 | synchronized (filter) |
| 240 | try { | 288 | { |
| 289 | try | ||
| 290 | { | ||
| 241 | Transaction t = e.beginTransaction(null, null); | 291 | Transaction t = e.beginTransaction(null, null); |
| 242 | 292 | ||
| 243 | try { | 293 | try |
| 294 | { | ||
| 244 | filter.put(t, f); | 295 | filter.put(t, f); |
| 245 | 296 | ||
| 246 | t.commit(); | 297 | t.commit(); |
| 247 | } catch (Exception ex) { | 298 | } catch (Exception ex) |
| 299 | { | ||
| 248 | t.abort(); | 300 | t.abort(); |
| 249 | } | 301 | } |
| 250 | } catch (DatabaseException ex) { | 302 | } catch (DatabaseException ex) |
| 303 | { | ||
| 251 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 304 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
| 252 | } | 305 | } |
| 253 | } | 306 | } |
| 254 | } | 307 | } |
| 255 | 308 | ||
| 256 | public static Filter getFilter(Integer id) { | 309 | public static Filter getFilter(Integer id) { |
| 257 | synchronized (filter) { | 310 | synchronized (filter) |
| 258 | try { | 311 | { |
| 312 | try | ||
| 313 | { | ||
| 259 | return filter.get(id); | 314 | return filter.get(id); |
| 260 | } catch (DatabaseException ex) { | 315 | } catch (DatabaseException ex) |
| 316 | { | ||
| 261 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 317 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
| 262 | return null; | 318 | return null; |
| 263 | } | 319 | } |
| @@ -265,30 +321,37 @@ public class Wrapper { | |||
| 265 | } | 321 | } |
| 266 | 322 | ||
| 267 | public static void deleteFilter(Integer id) { | 323 | public static void deleteFilter(Integer id) { |
| 268 | synchronized (filter) { | 324 | synchronized (filter) |
| 269 | try { | 325 | { |
| 326 | try | ||
| 327 | { | ||
| 270 | Transaction t = e.beginTransaction(null, null); | 328 | Transaction t = e.beginTransaction(null, null); |
| 271 | 329 | ||
| 272 | try { | 330 | try |
| 331 | { | ||
| 273 | filter.delete(t, id); | 332 | filter.delete(t, id); |
| 274 | 333 | ||
| 275 | t.commit(); | 334 | t.commit(); |
| 276 | } catch (Exception ex) { | 335 | } catch (Exception ex) |
| 336 | { | ||
| 277 | t.abort(); | 337 | t.abort(); |
| 278 | } | 338 | } |
| 279 | } catch (DatabaseException ex) { | 339 | } catch (DatabaseException ex) |
| 340 | { | ||
| 280 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 341 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
| 281 | } | 342 | } |
| 282 | } | 343 | } |
| 283 | } | 344 | } |
| 284 | 345 | ||
| 285 | public static Filter[] getAllFilter() { | 346 | public static Filter[] getAllFilter() { |
| 286 | synchronized (filter) { | 347 | synchronized (filter) |
| 348 | { | ||
| 287 | Collection vals = filter.map().values(); | 349 | Collection vals = filter.map().values(); |
| 288 | Filter fils[] = new Filter[vals.size()]; | 350 | Filter fils[] = new Filter[vals.size()]; |
| 289 | Iterator i = vals.iterator(); | 351 | Iterator i = vals.iterator(); |
| 290 | int j = 0; | 352 | int j = 0; |
| 291 | while (i.hasNext()) { | 353 | while (i.hasNext()) |
| 354 | { | ||
| 292 | fils[j] = (Filter) i.next(); | 355 | fils[j] = (Filter) i.next(); |
| 293 | j++; | 356 | j++; |
| 294 | } | 357 | } |
| @@ -297,37 +360,45 @@ public class Wrapper { | |||
| 297 | } | 360 | } |
| 298 | 361 | ||
| 299 | public static Integer countItem() { | 362 | public static Integer countItem() { |
| 300 | synchronized (item) { | 363 | synchronized (item) |
| 364 | { | ||
| 301 | return item.map().size(); | 365 | return item.map().size(); |
| 302 | } | 366 | } |
| 303 | } | 367 | } |
| 304 | 368 | ||
| 305 | public static void dropFromTopItem() { | 369 | public static void dropFromTopItem() { |
| 306 | synchronized (item) { | 370 | synchronized (item) |
| 307 | try { | 371 | { |
| 372 | try | ||
| 373 | { | ||
| 308 | Transaction t = e.beginTransaction(null, null); | 374 | Transaction t = e.beginTransaction(null, null); |
| 309 | 375 | ||
| 310 | try { | 376 | try |
| 377 | { | ||
| 311 | Iterator<Entry<Integer, Item>> i = item.map().entrySet().iterator(); | 378 | Iterator<Entry<Integer, Item>> i = item.map().entrySet().iterator(); |
| 312 | item.delete(t, i.next().getKey()); | 379 | item.delete(t, i.next().getKey()); |
| 313 | 380 | ||
| 314 | t.commit(); | 381 | t.commit(); |
| 315 | } catch (Exception ex) { | 382 | } catch (Exception ex) |
| 383 | { | ||
| 316 | t.abort(); | 384 | t.abort(); |
| 317 | } | 385 | } |
| 318 | } catch (DatabaseException ex) { | 386 | } catch (DatabaseException ex) |
| 387 | { | ||
| 319 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 388 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
| 320 | } | 389 | } |
| 321 | } | 390 | } |
| 322 | } | 391 | } |
| 323 | 392 | ||
| 324 | public static Item[] getAllItem() { | 393 | public static Item[] getAllItem() { |
| 325 | synchronized (item) { | 394 | synchronized (item) |
| 395 | { | ||
| 326 | Collection vals = item.map().values(); | 396 | Collection vals = item.map().values(); |
| 327 | Item items[] = new Item[vals.size()]; | 397 | Item items[] = new Item[vals.size()]; |
| 328 | Iterator i = vals.iterator(); | 398 | Iterator i = vals.iterator(); |
| 329 | int j = 0; | 399 | int j = 0; |
| 330 | while (i.hasNext()) { | 400 | while (i.hasNext()) |
| 401 | { | ||
| 331 | items[j] = (Item) i.next(); | 402 | items[j] = (Item) i.next(); |
| 332 | j++; | 403 | j++; |
| 333 | } | 404 | } |
| @@ -336,18 +407,48 @@ public class Wrapper { | |||
| 336 | } | 407 | } |
| 337 | 408 | ||
| 338 | public static void addItem(Item i) { | 409 | public static void addItem(Item i) { |
| 339 | synchronized (item) { | 410 | synchronized (item) |
| 340 | try { | 411 | { |
| 412 | try | ||
| 413 | { | ||
| 341 | Transaction t = e.beginTransaction(null, null); | 414 | Transaction t = e.beginTransaction(null, null); |
| 342 | 415 | ||
| 343 | try { | 416 | try |
| 417 | { | ||
| 344 | item.put(t, i); | 418 | item.put(t, i); |
| 345 | 419 | ||
| 346 | t.commit(); | 420 | t.commit(); |
| 347 | } catch (Exception ex) { | 421 | } catch (Exception ex) |
| 422 | { | ||
| 423 | t.abort(); | ||
| 424 | } | ||
| 425 | } catch (DatabaseException ex) | ||
| 426 | { | ||
| 427 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | ||
| 428 | } | ||
| 429 | } | ||
| 430 | } | ||
| 431 | |||
| 432 | public static void setUnreadFlagItem(Integer id, Boolean value) { | ||
| 433 | synchronized (item) | ||
| 434 | { | ||
| 435 | try | ||
| 436 | { | ||
| 437 | Transaction t = e.beginTransaction(null, null); | ||
| 438 | |||
| 439 | try | ||
| 440 | { | ||
| 441 | Item i = item.get(id); | ||
| 442 | i.setUnread(value); | ||
| 443 | item.put(t, i); | ||
| 444 | |||
| 445 | t.commit(); | ||
| 446 | } catch (Exception ex) | ||
| 447 | { | ||
| 348 | t.abort(); | 448 | t.abort(); |
| 349 | } | 449 | } |
| 350 | } catch (DatabaseException ex) { | 450 | } catch (DatabaseException ex) |
| 451 | { | ||
| 351 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); | 452 | Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); |
| 352 | } | 453 | } |
| 353 | } | 454 | } |
| 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; | |||
| 8 | import com.fourisland.instadisc.Database.Wrapper; | 8 | import com.fourisland.instadisc.Database.Wrapper; |
| 9 | import com.fourisland.instadisc.Item.Categories.Category; | 9 | import com.fourisland.instadisc.Item.Categories.Category; |
| 10 | import java.awt.Component; | 10 | import java.awt.Component; |
| 11 | import java.text.DateFormat; | ||
| 12 | import java.text.SimpleDateFormat; | ||
| 11 | import javax.swing.JLabel; | 13 | import javax.swing.JLabel; |
| 12 | import javax.swing.JList; | 14 | import javax.swing.JList; |
| 13 | import javax.swing.ListCellRenderer; | 15 | import javax.swing.ListCellRenderer; |
| @@ -23,20 +25,32 @@ public class IDItemListCellRenderer extends JLabel implements ListCellRenderer { | |||
| 23 | 25 | ||
| 24 | this.setIcon(Category.iconFromCategory(Wrapper.getSubscription(item.getSubscription()).getCategory())); | 26 | this.setIcon(Category.iconFromCategory(Wrapper.getSubscription(item.getSubscription()).getCategory())); |
| 25 | 27 | ||
| 26 | if (item.getAuthor().equals("")) { | 28 | if (item.getAuthor().equals("")) |
| 29 | { | ||
| 27 | this.setText("<HTML><I>" + Wrapper.getSubscription(item.getSubscription()).getTitle() + "</I>, <B>" + item.getTitle() + "</B>"); | 30 | this.setText("<HTML><I>" + Wrapper.getSubscription(item.getSubscription()).getTitle() + "</I>, <B>" + item.getTitle() + "</B>"); |
| 28 | } else { | 31 | } else |
| 32 | { | ||
| 29 | this.setText("<HTML><I>" + Wrapper.getSubscription(item.getSubscription()).getTitle() + "</I>, <B>" + item.getTitle() + "</B> by " + item.getAuthor()); | 33 | this.setText("<HTML><I>" + Wrapper.getSubscription(item.getSubscription()).getTitle() + "</I>, <B>" + item.getTitle() + "</B> by " + item.getAuthor()); |
| 30 | } | 34 | } |
| 35 | |||
| 36 | if (item.getUnread()) | ||
| 37 | { | ||
| 38 | this.setText(this.getText() + "<BR><B>New </B> at " + new SimpleDateFormat("EEEE, MMMM d yyyy k:mm aa").format(item.getRecieved())); | ||
| 39 | } | ||
| 40 | |||
| 41 | if (arg3) | ||
| 42 | { | ||
| 43 | this.setForeground(arg0.getSelectionForeground()); | ||
| 44 | this.setBackground(arg0.getSelectionBackground()); | ||
| 45 | } else | ||
| 46 | { | ||
| 47 | this.setForeground(arg0.getForeground()); | ||
| 31 | 48 | ||
| 32 | /*if (item.getUnread()) { | 49 | if (item.getUnread()) |
| 33 | this.setBackground(Color.YELLOW); | 50 | { |
| 34 | } else */ { | 51 | this.setBackground(java.awt.Color.yellow); |
| 35 | if (arg3) { | 52 | } else |
| 36 | this.setForeground(arg0.getSelectionForeground()); | 53 | { |
| 37 | this.setBackground(arg0.getSelectionBackground()); | ||
| 38 | } else { | ||
| 39 | this.setForeground(arg0.getForeground()); | ||
| 40 | this.setBackground(arg0.getBackground()); | 54 | this.setBackground(arg0.getBackground()); |
| 41 | } | 55 | } |
| 42 | } | 56 | } |
| 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 { | |||
| 330 | try { | 330 | try { |
| 331 | if (java.awt.Desktop.isDesktopSupported()) | 331 | if (java.awt.Desktop.isDesktopSupported()) |
| 332 | { | 332 | { |
| 333 | Wrapper.setUnreadFlagItem(item.getID(), false); | ||
| 334 | refreshItemPane(); | ||
| 335 | |||
| 333 | java.awt.Desktop.getDesktop().browse(new URI(item.getURL())); | 336 | java.awt.Desktop.getDesktop().browse(new URI(item.getURL())); |
| 334 | } else { | 337 | } else { |
| 335 | statusMessageLabel.setText("Error: Desktop not supported"); | 338 | doText("Error: Desktop not supported"); |
| 336 | } | 339 | } |
| 337 | } catch (IOException ex) { | 340 | } catch (IOException ex) { |
| 338 | Logger.getLogger(InstaDiscView.class.getName()).log(Level.SEVERE, null, ex); | 341 | Logger.getLogger(InstaDiscView.class.getName()).log(Level.SEVERE, null, ex); |
| @@ -378,7 +381,7 @@ public class InstaDiscView extends FrameView { | |||
| 378 | { | 381 | { |
| 379 | java.awt.Desktop.getDesktop().browse(new URI("http://fourisland.com/projects/instadisc/")); | 382 | java.awt.Desktop.getDesktop().browse(new URI("http://fourisland.com/projects/instadisc/")); |
| 380 | } else { | 383 | } else { |
| 381 | statusMessageLabel.setText("Error: Desktop not supported"); | 384 | doText("Error: Desktop not supported"); |
| 382 | } | 385 | } |
| 383 | } catch (IOException ex) | 386 | } catch (IOException ex) |
| 384 | { | 387 | { |
| 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 @@ | |||
| 1 | package com.fourisland.instadisc.Item.Categories; | ||
| 2 | |||
| 3 | public class Unread | ||
| 4 | { | ||
| 5 | 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}; | ||
| 6 | } | ||
| 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; | |||
| 10 | import com.fourisland.instadisc.XmlRpc; | 10 | import com.fourisland.instadisc.XmlRpc; |
| 11 | import java.awt.SystemTray; | 11 | import java.awt.SystemTray; |
| 12 | import java.awt.TrayIcon.MessageType; | 12 | import java.awt.TrayIcon.MessageType; |
| 13 | import java.util.Calendar; | ||
| 13 | import java.util.HashMap; | 14 | import java.util.HashMap; |
| 14 | 15 | ||
| 15 | /** | 16 | /** |
| @@ -54,6 +55,8 @@ public class Item { | |||
| 54 | temp.remove("URL"); | 55 | temp.remove("URL"); |
| 55 | item.setSemantics(temp); | 56 | item.setSemantics(temp); |
| 56 | 57 | ||
| 58 | item.setUnread(true); | ||
| 59 | item.setRecieved(Calendar.getInstance().getTime()); | ||
| 57 | Wrapper.addItem(item); | 60 | Wrapper.addItem(item); |
| 58 | 61 | ||
| 59 | ((InstaDiscView) InstaDiscApp.getApplication().getMainView()).refreshItemPane(); | 62 | ((InstaDiscView) InstaDiscApp.getApplication().getMainView()).refreshItemPane(); |
