X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fmce-ini-parse.vala;h=3198ed54bc24ecbe865e0b74eaa5d98882dcecb4;hb=1dbfa6f55383b49db8c5838636cbdf2a12ae8a64;hp=d7a4438982a21e2bf8833f58e29af56cd608e6a4;hpb=fa59477c020267fdfbc7182cc98014e8d33a85b0;p=led-pattern-ed
diff --git a/src/mce-ini-parse.vala b/src/mce-ini-parse.vala
index d7a4438..3198ed5 100644
--- a/src/mce-ini-parse.vala
+++ b/src/mce-ini-parse.vala
@@ -16,17 +16,42 @@
* along with LED Pattern Editor. If not, see .
*/
-List mce_ini_parse () {
- var list = new List ();
+enum DeviceType {
+ RX44,
+ RX51
+}
+
+static const DeviceType device = DeviceType.RX51;
+
+List mce_ini_parse () {
+ var list = new List ();
var f = FileStream.open ("/etc/mce/mce.ini", "r");
+ string pattern_section = null;
+
+ switch (device) {
+ case DeviceType.RX44:
+ pattern_section = "[LEDPatternNJoyRX44]";
+ break;
+ case DeviceType.RX51:
+ pattern_section = "[LEDPatternLystiRX51]";
+ break;
+ }
var line = f.read_line ();
while (line != null) {
- if (line == "[LEDPatternLystiRX51]") {
+ if (line == pattern_section) {
line = f.read_line ();
while ((line != null) && (line[0] != '[')) {
if (line.has_prefix ("Pattern")) {
- var pattern = new LedPatternRX51 ();
+ LedPattern pattern = null;
+ switch (device) {
+ case DeviceType.RX44:
+ pattern = new LedPatternRX44 ();
+ break;
+ case DeviceType.RX51:
+ pattern = new LedPatternRX51 ();
+ break;
+ }
pattern.parse (line);
list.append (pattern);
}
@@ -39,18 +64,28 @@ List mce_ini_parse () {
return list;
}
-void mce_ini_store (List list) {
+void mce_ini_store (List list) {
var f = FileStream.open ("/etc/mce/mce.ini", "r");
var g = FileStream.open ("/tmp/mce.ini", "w");
+ string pattern_section = null;
+
+ switch (device) {
+ case DeviceType.RX44:
+ pattern_section = "[LEDPatternNJoyRX44]";
+ break;
+ case DeviceType.RX51:
+ pattern_section = "[LEDPatternLystiRX51]";
+ break;
+ }
var line = f.read_line ();
while (line != null) {
- if (line == "[LEDPatternLystiRX51]") {
+ if (line == pattern_section) {
g.printf ("%s\n", line);
line = f.read_line ();
while ((line != null) && (line[0] != '[')) {
if (line.has_prefix ("Pattern")) {
- unowned List node;
+ unowned List node;
for (node = list.first (); node != null; node = node.next) {
if (line.has_prefix (node.data.name + "=")) {
g.printf ("%s\n", node.data.dump ());