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

commit 704d1bcf424f987f727484f4eadd842ff50898e3
Author: bouleetbil <bouleet...@frogdev.info>
Date:   Sun Jan 2 22:19:15 2011 +0100

*update database every 30min
*added module xml parser

diff --git a/frugal-tweak-vala/DATA/01.system.xml 
b/frugal-tweak-vala/DATA/01.system.xml
new file mode 100644
index 0000000..599930c
--- /dev/null
+++ b/frugal-tweak-vala/DATA/01.system.xml
@@ -0,0 +1,6 @@
+<module>
+       <tittle>system</tittle>
+       <description>Description</description>
+       <command>command to exec</command>
+       <group>Group</group>
+</module>
diff --git a/frugal-tweak-vala/Makefile b/frugal-tweak-vala/Makefile
index 46d4a6a..4ab92ee 100644
--- a/frugal-tweak-vala/Makefile
+++ b/frugal-tweak-vala/Makefile
@@ -14,7 +14,7 @@ PACMANUPDATESOURCES = $(SOURCEDIR)/Tree.vala 
$(SOURCEDIR)/Pacman-update.vala $(S

#for start modules
FRUGALTWEAKSOURCES = $(SOURCEDIR)/MainClient.vala $(SOURCEDIR)/Tree.vala 
$(SOURCEDIR)/pacman.vala $(SOURCEDIR)/tools.vala \
-                                               $(SOURCEDIR)/popup.vala 
$(SOURCEDIR)/configuration.vala \
+                                               $(SOURCEDIR)/popup.vala 
$(SOURCEDIR)/configuration.vala $(SOURCEDIR)/Module.vala\
./vapi/config.vapi

ENABLEINDICATE = 0
@@ -29,6 +29,7 @@ all: daemon terminal browser frugalwaretweak pacmanupdate

frugalwaretweak:
$(VALAC)  --save-temps --define=$(DEBUGFLAG) --pkg gio-2.0 --pkg gtk+-2.0 --pkg 
gmodule-2.0 --pkg pacman  --pkg unique-1.0 --pkg libnotify \
+       --pkg libxml-2.0 \
--define=$(INDICATEFLAG) $(INDICATEVALA) \
$(FRUGALTWEAKSOURCES) -o frugalware-tweak2

diff --git a/frugal-tweak-vala/src/MainClient.vala 
b/frugal-tweak-vala/src/MainClient.vala
index 9539eab..92f773b 100644
--- a/frugal-tweak-vala/src/MainClient.vala
+++ b/frugal-tweak-vala/src/MainClient.vala
@@ -21,6 +21,7 @@ using Gtk;
using Unique;
using Popup;
using Tree;
+using Module;

int main (string[] args) {

@@ -63,6 +64,9 @@ int main (string[] args) {
#if DEBUG
//for tested notification
Popup.PopupShow("titre test","test");
+               //Tools.ConsoleDebug("test1\n");
+               Module module = new Module("01.system.xml");
+               Tools.ConsoleDebug("test module : "+module.GetTittle()+"\n");
#endif

window.show_all ();
diff --git a/frugal-tweak-vala/src/Module.vala 
b/frugal-tweak-vala/src/Module.vala
new file mode 100644
index 0000000..c5b3367
--- /dev/null
+++ b/frugal-tweak-vala/src/Module.vala
@@ -0,0 +1,106 @@
+/*
+ *
+ * (C) 2010 bouleetbil <bouleet...@frogdev.info>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  
USA
+ */
+
+using Xml;
+
+class Module: Object {
+       string _tittle = "";
+       string _description = "";
+       string _command = "";
+       string _group = ""; //not yet use
+       const string _dir = "/usr/share/frugalware-tweak/plugins/";
+
+
+       public Module(string FileToParse)
+       {
+               string path = this._dir+FileToParse;
+               Parser.init();
+               Xml.Doc* doc = Parser.parse_file (path);
+               Xml.Node* root = doc->get_root_element ();
+               parse_node (root);
+               Parser.cleanup();
+               delete doc;
+       }
+       private void parse_node (Xml.Node* node) {
+               // Loop over the passed node's children
+               for (Xml.Node* iter = node->children; iter != null; iter = 
iter->next) {
+               // Spaces between tags are also nodes, discard them
+               if (iter->type != ElementType.ELEMENT_NODE) {
+                       continue;
+               }
+
+               // Get the node's name
+               string node_name = iter->name;
+               // Get the node's content with <tags> stripped
+               string node_content = iter->get_content ();
+               analyzeattr(node_name,node_content);
+
+               // Now parse the node's properties (attributes) ...
+               parse_properties (iter);
+
+               // Followed by its children nodes
+               parse_node (iter);
+               }
+       }
+
+       private void parse_properties (Xml.Node* node) {
+               // Loop over the passed node's properties (attributes)
+               for (Xml.Attr* prop = node->properties; prop != null; prop = 
prop->next) {
+               string attr_name = prop->name;
+
+               // Notice the ->children which points to a Node*
+               // (Attr doesn't feature content)
+               string attr_content = prop->children->content;
+               analyzeattr(attr_name,attr_content);
+               }
+       }
+       private void analyzeattr(string attr, string content)
+       {
+               //Tools.ConsoleDebug(attr+" : "+content+"\n");
+               switch (attr) {
+                       case "tittle" :
+                               this._tittle=content;
+                               break;
+                       case "description":
+                               this._description=content;
+                               break;
+                       case "command":
+                               this._command=content;
+                               break;
+                       case "group":
+                               this._group=content;
+                               break;
+                       default :
+                               Tools.ConsoleDebug("unknown "+attr+" : 
"+content+"\n");
+                               break;
+               }
+       }
+       public string GetTittle(){
+               return this._tittle;
+       }
+       public string GetDescription(){
+               return this._description;
+       }
+       public string GetCommand(){
+               return this._command;
+       }
+       public string GetGroup(){
+               return this._group;
+       }
+}
diff --git a/frugal-tweak-vala/src/daemon.vala 
b/frugal-tweak-vala/src/daemon.vala
index 2a44b1c..2e6255d 100644
--- a/frugal-tweak-vala/src/daemon.vala
+++ b/frugal-tweak-vala/src/daemon.vala
@@ -37,7 +37,6 @@ class Deamon : GLib.Object {
while(true)
{
Thread.usleep(1800000000);      //1/2 hour
-               Thread.usleep(1800000000); //1/2 hour
UpdateAllDatabase();
}
}
_______________________________________________
Frugalware-git mailing list
Frugalware-git@frugalware.org
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to