Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=frugal-tweak.git;a=commitdiff;h=3f17b93c82edbd525587db32173bcd18452a88d6

commit 3f17b93c82edbd525587db32173bcd18452a88d6
Author: bouleetbil <bouleet...@frogdev.info>
Date:   Sat Sep 11 19:22:56 2010 +0200

*added cache for inform new postfrom planet

diff --git a/frugal-mono-tools/Configuration.cs 
b/frugal-mono-tools/Configuration.cs
index c6f0619..2f3f7f1 100644
--- a/frugal-mono-tools/Configuration.cs
+++ b/frugal-mono-tools/Configuration.cs
@@ -20,6 +20,73 @@ using System.Text.RegularExpressions;
using System.IO;
namespace frugalmonotools
{
+
+       //only uses by rss for now
+       public class Cache
+       {
+               private const string confFile=@"/.cache/FrugalTools";
+               private int _nbFlux = 0;
+               private string _latest="";
+               public Cache()
+               {
+                       //read value
+                       try{
+                               string filedesc = GetConfFile();
+                               string content = Outils.ReadFile(filedesc);
+                               string[] lines = content.Split('\n');
+                               foreach (string line in lines)
+                               {
+                                        if (Regex.Matches(line, 
"nbRSS").Count>0)
+                                               {
+                                                       int nb = 
int.Parse(line.Split('=')[1]);
+                                                       this.SetNbFlux(nb);
+                                               }
+                                        if (Regex.Matches(line, 
"last").Count>0)
+                                               {
+                                                       string last = 
line.Split('=')[1];
+                                                       this.SetLatest(last);
+                                               }
+                               }
+                       }
+                       catch{  }
+               }
+               public void CacheSave()
+               {
+                       try
+                       {
+                               StreamWriter FileConf = new 
StreamWriter(GetConfFile());
+                               FileConf.WriteLine("nbRSS="+this.GetNbFlux());
+                               FileConf.WriteLine("last="+this.GetLatest());
+                               FileConf.Close();
+                       }
+                       catch(Exception exe)
+                       {
+                               Console.WriteLine(exe.Message);
+                       }
+               }
+               public string GetConfFile(){
+                       return 
Environment.GetFolderPath(System.Environment.SpecialFolder
+.Personal)+confFile;
+               }
+               public int GetNbFlux()
+               {
+                       return _nbFlux;
+               }
+               public void SetNbFlux(int valeur)
+               {
+                       _nbFlux=valeur;
+               }
+
+               public string GetLatest()
+               {
+                       return _latest;
+               }
+               public void SetLatest(string valeur)
+               {
+                       _latest=valeur;
+               }
+       }
+
public class Configuration
{

diff --git a/frugal-mono-tools/Main.cs b/frugal-mono-tools/Main.cs
index 37e1c29..b7b92a2 100644
--- a/frugal-mono-tools/Main.cs
+++ b/frugal-mono-tools/Main.cs
@@ -35,6 +35,7 @@ namespace frugalmonotools
//pacman-g2 initialise
public static PacmanG2 pacmanG2 = new PacmanG2();
public static Configuration configuration = new Configuration();
+               public static Cache cache = new Cache();

private static void checkUpdate(object source, ElapsedEventArgs e)
{
diff --git a/frugal-mono-tools/MainWindow.cs b/frugal-mono-tools/MainWindow.cs
index e342fb4..ba99752 100644
--- a/frugal-mono-tools/MainWindow.cs
+++ b/frugal-mono-tools/MainWindow.cs
@@ -365,12 +365,15 @@ public partial class MainWindow : Gtk.Window
RssChannel rssChannel = (RssChannel)rssFeed.Channels[0];

i = 0;
+                       string latest="";
foreach (RssItem item in rssChannel.Items)
{
string titre=item.Title;
modelFlux.AppendValues(titre,i);
+                               if(latest 
=="")latest=item.Link.AbsoluteUri.ToString();
i++;
}
+                       InformNewFlux(latest);
}
catch{}

@@ -391,6 +394,17 @@ public partial class MainWindow : Gtk.Window
UpdateToTreeview();
IgnorepkgToSAI();
}
+       private void InformNewFlux(string latest)
+       {
+                       if (MainClass.cache.GetLatest()!=latest)
+                       {
+                               IconSummaryBody notif= new IconSummaryBody();
+                               if(MainClass.configuration.Get_ShowNotif()) 
notif.ShowMessage("Frugalware","News are available.");
+                               //write cache
+                               MainClass.cache.SetLatest(latest);
+                               MainClass.cache.CacheSave();
+               }
+       }
private void IgnorepkgToSAI()
{
SAI_ignorePkg.Text="";
@@ -427,27 +441,20 @@ public partial class MainWindow : Gtk.Window
{
//RSS
try{
-                       int count = modelFlux.Data.Count;
modelFlux.Clear();
rssFeed =RssFeed.Read(UrlPlanet);
RssChannel rssChannel = (RssChannel)rssFeed.Channels[0];

int i = 0;
+                       string latest="";
foreach (RssItem item in rssChannel.Items)
{
string titre=item.Title;
+                               if(latest 
=="")latest=item.Link.AbsoluteUri.ToString();
modelFlux.AppendValues(titre,i);
i++;
}
-
-                       if(modelFlux.Data.Count!=count)
-                       {
-                               if(MainClass.configuration.Get_ShowNotif())
-                               {
-                                       IconSummaryBody notif= new 
IconSummaryBody();
-                                       notif.ShowMessage("Frugalware","New RSS 
entry");
-                               }
-                       }
+                       InformNewFlux(latest);
}
catch{}
}
_______________________________________________
Frugalware-git mailing list
Frugalware-git@frugalware.org
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to