Author: Paul_R
Date: 2008-08-29 15:36:19 +0200 (Fri, 29 Aug 2008)
New Revision: 1634

Modified:
   
software_suite_v2/software/gadgets/tuxdroid-gadget-feed/trunk/tuxdroid-gadget-feed/gadgets.xml
   
software_suite_v2/software/gadgets/tuxdroid-gadget-feed/trunk/tuxdroid-gadget-feed/sources/net/karmaLab/tuxDroid/gadgets/FeedGadget.java
Log:
* Added a new parameter to enable/disable the notification.
  This parameter will be removed as soon as the notification on the 
  framework work.


Modified: 
software_suite_v2/software/gadgets/tuxdroid-gadget-feed/trunk/tuxdroid-gadget-feed/gadgets.xml
===================================================================
--- 
software_suite_v2/software/gadgets/tuxdroid-gadget-feed/trunk/tuxdroid-gadget-feed/gadgets.xml
      2008-08-29 10:20:09 UTC (rev 1633)
+++ 
software_suite_v2/software/gadgets/tuxdroid-gadget-feed/trunk/tuxdroid-gadget-feed/gadgets.xml
      2008-08-29 13:36:19 UTC (rev 1634)
@@ -39,6 +39,11 @@
                                description="Feed Address"
                                type="string"
                                
defaultValue="http://artisan.karma-lab.net/rss.xml"; />
+                       <parameter
+                               name="notified"
+                               description="Alert mode"
+                               type="boolean"
+                               defaultValue="false" />
                </parameters>
                <commands>
                        <command name="play" description="play"/>

Modified: 
software_suite_v2/software/gadgets/tuxdroid-gadget-feed/trunk/tuxdroid-gadget-feed/sources/net/karmaLab/tuxDroid/gadgets/FeedGadget.java
===================================================================
--- 
software_suite_v2/software/gadgets/tuxdroid-gadget-feed/trunk/tuxdroid-gadget-feed/sources/net/karmaLab/tuxDroid/gadgets/FeedGadget.java
    2008-08-29 10:20:09 UTC (rev 1633)
+++ 
software_suite_v2/software/gadgets/tuxdroid-gadget-feed/trunk/tuxdroid-gadget-feed/sources/net/karmaLab/tuxDroid/gadgets/FeedGadget.java
    2008-08-29 13:36:19 UTC (rev 1634)
@@ -24,8 +24,8 @@
 
 import java.io.*;
 import java.net.URL;
-import java.net.URLConnection;
 import java.util.Vector;
+import java.io.FileInputStream;
 
 import net.karmaLab.beans.mapping.annotation.Published;
 import net.karmaLab.xml.feed.Feed;
@@ -36,6 +36,31 @@
 import com.kysoh.tuxdroid.gadget.framework.gadget.SimpleGadgetConfiguration;
 
 public class FeedGadget extends SimpleGadget<FeedGadget.Configuration> {
+       
+       public static class State implements Serializable {
+               /**
+                * 
+                */
+               private static final long serialVersionUID = 1L;
+               private Vector<String> lastMessages = new Vector<String>();
+
+               /**
+                * @return the lastMessages
+                */
+               public Vector<String> getLastMessages() {
+                       return lastMessages;
+               }
+
+               /**
+                * @param lastMessages
+                *            the lastMessages to set
+                */
+               public void setLastMessages(Vector<String> lastMessages) {
+                       this.lastMessages = lastMessages;
+               }
+
+       }
+       
        public static class Configuration extends SimpleGadgetConfiguration {
                private String address = 
"http://artisan.karma-lab.net/rss.xml";; //$NON-NLS-1$
 
@@ -48,6 +73,8 @@
                private boolean readDescription = false;
 
                private String title = "Artisan"; //$NON-NLS-1$
+               
+               private boolean notified = false;
 
                @Published
                public String getAddress() {
@@ -97,6 +124,14 @@
                public void setTitle(String title) {
                        this.title = title;
                }
+               
+               public void setNotified(boolean enabled) {
+                       this.notified = enabled;
+               }
+               
+               public boolean isNotified() {
+                       return this.notified;
+               }
        }
 
        public static void main(String[] args) throws Exception {
@@ -105,40 +140,75 @@
 
        @Override
        public void start() throws FeedReaderException, IOException {   
-               throwTrace("Loading " + configuration().getTitle() + " 
stream"); //$NON-NLS-1$ //$NON-NLS-2$
+               //throwTrace("Loading " + configuration().getTitle() + " 
stream"); //$NON-NLS-1$ //$NON-NLS-2$
+               
+               State state = null;
+               ObjectInputStream inputStream;
+               File sessionId = null;
+               
+               if (configuration().isNotified()) {
+                       /* Load the last state if exists */
+                       sessionId = new File(System.getProperty("user.home") + 
File.separator + 
+                                       "MyTux" + File.separator + 
"TuxDroidSettings" + File.separator + 
+                                       configuration().getTitle());
+                       
+                       if (sessionId.exists()) {
+                               inputStream = new ObjectInputStream(new 
FileInputStream(sessionId));
+                               try {
+                                       state = (State) 
inputStream.readObject();
+                               } catch (ClassNotFoundException e) {
+                                       e.printStackTrace();
+                               }
+                       } else {
+                               state = new State();
+                       }
+               }
+               
+               /* Open the connection */
                URL feedUrl = new URL(configuration().getAddress());
-               
                Feed feed = new Feed(feedUrl.openStream());
                
+               boolean notification = false;
                int count = configuration().getNumberOfEntries();
                String message = "";
+               
                for (FeedEntry entry : feed) {
                        boolean found = false;
-                       for (String title : configuration().getLastTitles()) {
-                               if (entry.getTitle().equals(title)) {
-                                       found = true;
-                                       break;
+                       int j = 0;
+                       if (configuration().isNotified()) {
+                               while (!found && j < 
state.getLastMessages().size()) {
+                                       if 
(entry.getTitle().equalsIgnoreCase(state.getLastMessages().get(j))) {
+                                               found = true;
+                                       }
+                                       j++;
                                }
                        }
+
                        if (!found) {
+                               notification = true;
                                
configuration().getLastTitles().insertElementAt(entry.getTitle(), 0);
                                message = message + configuration().getTitle() 
+ " : " + entry.getTitle().trim() + ". ";
 
                                if (configuration().isReadDescription()) {
                                        message = message + 
entry.getTextDescription() + " ";
                                }
+                               if (configuration().isNotified()) {
+                                       
state.getLastMessages().add(entry.getTitle());
+                               }
                        }
                        if (--count == 0) {
                                break;
                        }
                }
-               throwMessage(this.searchForPercent(message));
-               
-               if (configuration().getLastTitles().size() > 
configuration().getNumberOfEntries()) {
-                       for (int i = 0; i < 
configuration().getNumberOfEntries() - configuration().getLastTitles().size(); 
i++) {
-                               
configuration().getLastTitles().remove(configuration().getNumberOfEntries());
-                       }
+               if (notification) {
+                       throwMessage(this.searchForPercent(message));
                }
+                               
+               if (configuration().isNotified()) {
+                       ObjectOutputStream outputStream = new 
ObjectOutputStream(new FileOutputStream(sessionId));
+                       outputStream.writeObject(state);
+                       outputStream.close();
+               }
        }
        
        /**


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to