public List<LedCommandRX44> engine_g;
public List<LedCommandRX44> engine_b;
- public override bool parse (string line) {
+ public override void parse (string line) throws LedPatternError {
string[] key_value = line.split ("=");
- if (key_value.length != 2) {
- print ("pattern line does not contain '=': %s\n", line);
- return false;
- }
+ if (key_value.length != 2)
+ throw new LedPatternError.INVALID_PATTERN ("pattern line does not contain '=': " + line);
+
+ name = key_value[0];
string[] p = key_value[1].split (";");
- if (p.length != 6) {
- print ("pattern does not contain 6 components: %d\n", p.length);
- return false;
- }
+ if (p.length != 6)
+ throw new LedPatternError.INVALID_PATTERN ("%s does not contain 6 components: %d".printf (name, p.length));
- if (p[3].length > 16*4 || p[4].length > 16*4 || p[5].length > 16*4) {
- print ("pattern too long!\n");
- return false;
- }
+ if (p[3].length > 16*4 || p[4].length > 16*4 || p[5].length > 16*4)
+ throw new LedPatternError.INVALID_PATTERN ("%s engine pattern too long!".printf (name));
+
+ if (p[3].length % 4 != 0 || p[4].length % 4 != 0 || p[5].length % 4 != 0)
+ throw new LedPatternError.INVALID_PATTERN ("%s engine pattern not an even number of bytes!".printf (name));
- name = key_value[0];
priority = p[0].to_int ();
screen_on = p[1].to_int ();
timeout = p[2].to_int ();
engine_b = parse_pattern (p[5]);
on_changed ();
- return true;
}
private List<LedCommandRX44> parse_pattern (string pattern) {
public List<LedCommandRX51> engine1;
public List<LedCommandRX51> engine2;
- public override bool parse (string line) {
+ public override void parse (string line) throws LedPatternError {
string[] key_value = line.split ("=");
- if (key_value.length != 2) {
- print ("pattern line does not contain '=': %s\n", line);
- return false;
- }
+ if (key_value.length != 2)
+ throw new LedPatternError.INVALID_PATTERN ("pattern line does not contain '=': " + line);
+
+ name = key_value[0];
string[] p = key_value[1].split (";");
- if (p.length != 6) {
- print ("pattern does not contain 6 components: %d\n", p.length);
- return false;
- }
+ if (p.length != 6)
+ throw new LedPatternError.INVALID_PATTERN ("%s does not contain 6 components: %d".printf (name, p.length));
- if (p[4].length > 16*4 || p[5].length > 16*4) {
- print ("pattern too long!\n");
- return false;
- }
+ if (p[4].length > 16*4 || p[5].length > 16*4)
+ throw new LedPatternError.INVALID_PATTERN ("%s engine pattern too long!".printf (name));
+
+ if (p[4].length % 4 != 0 || p[5].length % 4 != 0)
+ throw new LedPatternError.INVALID_PATTERN ("%s engine pattern not an even number of bytes!".printf (name));
- name = key_value[0];
priority = p[0].to_int ();
screen_on = p[1].to_int ();
timeout = p[2].to_int ();
}
on_changed ();
- return true;
}
private void parse_led_map (string led_map, out LedColor color1, out LedColor color2) {
public void on_changed () {
bool unresolved = calculate_timing ();
- if (unresolved)
+ if (unresolved) {
unresolved = calculate_timing ();
- if (unresolved)
+ }
+ if (unresolved) {
Hildon.Banner.show_information (null, null, "Timing unresolved");
+ }
changed ();
}
* along with LED Pattern Editor. If not, see <http://www.gnu.org/licenses/>.
*/
+errordomain LedPatternError {
+ INVALID_PATTERN;
+}
+
abstract class LedPattern : Object {
enum ScreenOn {
DISPLAY_OFF = 0,
public double duration;
public abstract string dump ();
- public abstract bool parse (string line);
+ public abstract void parse (string line) throws LedPatternError;
public signal void changed ();
}
void on_text_received (Gtk.Clipboard clipboard, string text) {
var clip_pattern = new LedPatternRX51 ();
- if (clip_pattern.parse (text)) {
+ try {
+ clip_pattern.parse (text);
lpv.pattern.replace_with (clip_pattern);
- } else {
+ } catch (LedPatternError e) {
Hildon.Banner.show_information (null, null, "Not a valid pattern");
}
}
pattern = new LedPatternRX51 ();
break;
}
- pattern.parse (line);
- list.append (pattern);
+ try {
+ pattern.parse (line);
+ list.append (pattern);
+ } catch (LedPatternError e) {
+ Hildon.Banner.show_information (null, null, e.message);
+ }
}
line = f.read_line ();
}