diff --git a/src/Application.vala b/src/Application.vala index e47987d..c2485cc 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -36,7 +36,9 @@ public class Application : Granite.Application { var css_provider = new Gtk.CssProvider (); css_provider.load_from_resource ("com/github/manexim/home/styles/application.css"); - Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); + Gtk.StyleContext.add_provider_for_screen ( + Gdk.Screen.get_default (), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION + ); } public static int main (string[] args) { diff --git a/src/lifx/Packet.vala b/src/lifx/Packet.vala index 19ffe7d..647f85c 100644 --- a/src/lifx/Packet.vala +++ b/src/lifx/Packet.vala @@ -74,26 +74,26 @@ public class Lifx.Packet { // payload payload = new Json.Object (); - const uint8 i = 36; + const uint8 INDEX = 36; switch (type) { case 3: // StateService - payload.set_int_member ("service", buffer.read_uint8 (i)); - payload.set_int_member ("port", buffer.read_uint32_le (i + 1)); + payload.set_int_member ("service", buffer.read_uint8 (INDEX))); + payload.set_int_member ("port", buffer.read_uint32_le (INDEX) + 1)); break; case 13: // StateHostInfo - payload.set_double_member ("signal", buffer.read_float_le (i)); - payload.set_int_member ("tx", buffer.read_uint32_le (i + 4)); - payload.set_int_member ("rx", buffer.read_uint32_le (i + 8)); + payload.set_double_member ("signal", buffer.read_float_le (INDEX))); + payload.set_int_member ("tx", buffer.read_uint32_le (INDEX) + 4)); + payload.set_int_member ("rx", buffer.read_uint32_le (INDEX) + 8)); break; case 15: // StateHostFirmware - payload.set_double_member ("signal", buffer.read_float_le (i)); - payload.set_int_member ("tx", buffer.read_uint32_le (i + 4)); - payload.set_int_member ("rx", buffer.read_uint32_le (i + 8)); + payload.set_double_member ("signal", buffer.read_float_le (INDEX))); + payload.set_int_member ("tx", buffer.read_uint32_le (INDEX) + 4)); + payload.set_int_member ("rx", buffer.read_uint32_le (INDEX) + 8)); break; case 22: // StatePower Types.Power power = Types.Power.UNKNOWN; - uint16 power_t = buffer.read_uint16_le (i); + uint16 power_t = buffer.read_uint16_le (INDEX)); if (power_t > 0) { power = Types.Power.ON; } else if (power_t == 0) { @@ -102,10 +102,10 @@ public class Lifx.Packet { payload.set_int_member ("level", power); break; case 25: // StateLabel - payload.set_string_member ("label", (string) buffer.slice (i, i + 32).raw); + payload.set_string_member ("label", (string) buffer.slice (INDEX), INDEX + 32).raw); break; case 33: // StateVersion - uint32 product = buffer.read_uint32_le (i + 4); + uint32 product = buffer.read_uint32_le (INDEX) + 4); string model = ""; bool supports_color = false; bool supports_infrared = false; @@ -255,14 +255,14 @@ public class Lifx.Packet { payload.set_boolean_member ("supportsMultizone", supports_multizone); break; case 107: // State - payload.set_int_member ("hue", buffer.read_uint16_le (i)); - payload.set_int_member ("saturation", buffer.read_uint16_le (i + 2)); - payload.set_int_member ("brightness", buffer.read_uint16_le (i + 4)); - payload.set_int_member ("kelvin", buffer.read_uint16_le (i + 6)); + payload.set_int_member ("hue", buffer.read_uint16_le (INDEX))); + payload.set_int_member ("saturation", buffer.read_uint16_le (INDEX) + 2)); + payload.set_int_member ("brightness", buffer.read_uint16_le (INDEX) + 4)); + payload.set_int_member ("kelvin", buffer.read_uint16_le (INDEX) + 6)); // power Types.Power power = Types.Power.UNKNOWN; - uint16 power_t = buffer.read_uint16_le (i + 10); + uint16 power_t = buffer.read_uint16_le (INDEX) + 10); if (power_t > 0) { power = Types.Power.ON; } else if (power_t == 0) { @@ -270,11 +270,11 @@ public class Lifx.Packet { } payload.set_int_member ("power", power); - payload.set_string_member ("label", (string) buffer.slice (i + 12, i + 44).raw); + payload.set_string_member ("label", (string) buffer.slice (INDEX) + 12, INDEX + 44).raw); break; case 118: // StatePower Types.Power power = Types.Power.UNKNOWN; - uint16 power_t = buffer.read_uint16_le (i); + uint16 power_t = buffer.read_uint16_le (INDEX)); if (power_t > 0) { power = Types.Power.ON; } else if (power_t == 0) { @@ -284,7 +284,7 @@ public class Lifx.Packet { break; default: var a = new Json.Array (); - var raw = buffer.slice (i, (uint8) size).raw; + var raw = buffer.slice (INDEX), (uint8) size).raw; for (uint8 j = 0; j < raw.length; j++) { a.add_int_element (raw[j]); @@ -326,11 +326,11 @@ public class Lifx.Packet { // frame address Buffer buf2 = new Buffer.alloc (16); for (uint8 i = 0; i < 8; i++) { - buf2.write_uint8(target_parts[i], i); + buf2.write_uint8 (target_parts[i], i); } // header - Buffer buf3 = new Buffer.alloc(12); + Buffer buf3 = new Buffer.alloc (12); buf3.write_uint16_le (type, 8); uint8 byte14 = (ack_required << 1) | res_required; diff --git a/src/lifx/Service.vala b/src/lifx/Service.vala index cb7fbb0..9b156fa 100644 --- a/src/lifx/Service.vala +++ b/src/lifx/Service.vala @@ -61,7 +61,9 @@ public class Lifx.Service { } } - public void set_color (Lifx.Lamp lamp, uint16 hue, uint16 saturation, uint16 brightness, uint16 kelvin, uint32 duration=0) { + public void set_color ( + Lifx.Lamp lamp, uint16 hue, uint16 saturation, uint16 brightness, uint16 kelvin, uint32 duration=0 + ) { var packet = new Lifx.Packet (); packet.type = 102; packet.tagged = false; @@ -186,9 +188,9 @@ public class Lifx.Service { #if HAVE_SO_REUSEPORT int32 enable = 1; - Posix.setsockopt( + Posix.setsockopt ( socket.fd, Platform.Socket.SOL_SOCKET, Platform.Socket.SO_REUSEPORT, &enable, - (Posix.socklen_t) sizeof(int) + (Posix.socklen_t) sizeof (int) ); #endif diff --git a/src/pages/HueBridgeOnboardingPage.vala b/src/pages/HueBridgeOnboardingPage.vala index db68494..1e1dba7 100644 --- a/src/pages/HueBridgeOnboardingPage.vala +++ b/src/pages/HueBridgeOnboardingPage.vala @@ -38,7 +38,7 @@ public class Pages.HueBridgeOnboardingPage : Gtk.Grid { label = new Gtk.Label (_("Press the push-link button in the middle of the Hue bridge.")); spinner = new Gtk.Spinner (); - spinner.start (); + spinner.start (); attach (icon, 0, 0, 1, 1); attach (label, 0, 1, 1, 1); diff --git a/src/pages/LoadingPage.vala b/src/pages/LoadingPage.vala index 3703ead..4d8fa17 100644 --- a/src/pages/LoadingPage.vala +++ b/src/pages/LoadingPage.vala @@ -25,13 +25,13 @@ public class Pages.LoadingPage : Gtk.Grid { valign = Gtk.Align.CENTER; var label = new Gtk.Label (_("Looking for smart home gadgets to control.")); - label.halign = Gtk.Align.CENTER; - label.valign = Gtk.Align.CENTER; + label.halign = Gtk.Align.CENTER; + label.valign = Gtk.Align.CENTER; var spinner = new Gtk.Spinner (); - spinner.halign = Gtk.Align.CENTER; - spinner.valign = Gtk.Align.CENTER; - spinner.start (); + spinner.halign = Gtk.Align.CENTER; + spinner.valign = Gtk.Align.CENTER; + spinner.start (); attach (label, 0, 0, 1, 1); attach (spinner, 0, 2, 1, 1); diff --git a/src/philips/hue/BridgeController.vala b/src/philips/hue/BridgeController.vala index b6b8364..ff89564 100644 --- a/src/philips/hue/BridgeController.vala +++ b/src/philips/hue/BridgeController.vala @@ -45,10 +45,12 @@ public class Philips.Hue.BridgeController { // replace with // because otherwise the node can not be found - GLib.Regex r = /.*().*/; + GLib.Regex r = ".*().*"; Xml.Doc* doc; try { - var patched = r.replace ((string) message.response_body.data, (ssize_t) message.response_body.length, 0, ""); + var patched = r.replace ( + (string) message.response_body.data, (ssize_t) message.response_body.length, 0, "" + ); Xml.Parser.init (); @@ -57,19 +59,19 @@ public class Philips.Hue.BridgeController { stderr.printf ("failed to read the .xml file\n"); } - Xml.XPath.Context context = new Xml.XPath.Context(doc); + Xml.XPath.Context context = new Xml.XPath.Context (doc); if (context == null) { stderr.printf ("failed to create the xpath context\n"); } - Xml.XPath.Object* obj = context.eval_expression("/root/device/friendlyName"); + Xml.XPath.Object* obj = context.eval_expression ("/root/device/friendlyName"); if (obj == null) { stderr.printf ("failed to evaluate xpath\n"); } Xml.Node* node = null; - if (obj->nodesetval != null && obj->nodesetval->item(0) != null) { - node = obj->nodesetval->item(0); + if (obj->nodesetval != null && obj->nodesetval->item (0) != null) { + node = obj->nodesetval->item (0); } else { stderr.printf ("failed to find the expected node\n"); } @@ -78,14 +80,14 @@ public class Philips.Hue.BridgeController { delete obj; - obj = context.eval_expression("/root/device/manufacturer"); + obj = context.eval_expression ("/root/device/manufacturer"); if (obj == null) { stderr.printf ("failed to evaluate xpath\n"); } node = null; - if (obj->nodesetval != null && obj->nodesetval->item(0) != null) { - node = obj->nodesetval->item(0); + if (obj->nodesetval != null && obj->nodesetval->item (0) != null) { + node = obj->nodesetval->item (0); } else { stderr.printf ("failed to find the expected node\n"); } @@ -94,14 +96,14 @@ public class Philips.Hue.BridgeController { delete obj; - obj = context.eval_expression("/root/device/modelName"); + obj = context.eval_expression ("/root/device/modelName"); if (obj == null) { stderr.printf ("failed to evaluate xpath\n"); } node = null; - if (obj->nodesetval != null && obj->nodesetval->item(0) != null) { - node = obj->nodesetval->item(0); + if (obj->nodesetval != null && obj->nodesetval->item (0) != null) { + node = obj->nodesetval->item (0); } else { stderr.printf ("failed to find the expected node\n"); } @@ -149,7 +151,7 @@ public class Philips.Hue.BridgeController { string response = (string) message.response_body.flatten ().data; - var parser = new Json.Parser(); + var parser = new Json.Parser (); parser.load_from_data (response, -1); foreach (var element in parser.get_root ().get_array ().get_elements ()) { @@ -184,7 +186,7 @@ public class Philips.Hue.BridgeController { string response = (string) message.response_body.flatten ().data; try { - var parser = new Json.Parser(); + var parser = new Json.Parser (); parser.load_from_data (response, -1); var object = parser.get_root ().get_object (); var lights = object.get_object_member ("lights"); @@ -207,7 +209,8 @@ public class Philips.Hue.BridgeController { if (light.get_object_member ("state").has_member ("ct")) { lamp.supports_color_temperature = true; - lamp.color_temperature = (uint16) (1000000.0 / light.get_object_member ("state").get_int_member ("ct")); + lamp.color_temperature = (uint16) (1000000.0 / light.get_object_member ("state") + .get_int_member ("ct")); } if (light.get_object_member ("state").has_member ("hue")) { diff --git a/src/philips/hue/Service.vala b/src/philips/hue/Service.vala index 0dba059..736765f 100644 --- a/src/philips/hue/Service.vala +++ b/src/philips/hue/Service.vala @@ -121,9 +121,9 @@ public class Philips.Hue.Service { #if HAVE_SO_REUSEPORT int32 enable = 1; - Posix.setsockopt( + Posix.setsockopt ( socket.fd, Platform.Socket.SOL_SOCKET, Platform.Socket.SO_REUSEPORT, &enable, - (Posix.socklen_t) sizeof(int) + (Posix.socklen_t) sizeof (int) ); #endif @@ -144,7 +144,7 @@ public class Philips.Hue.Service { size_t read = s.receive (buffer); buffer[read] = 0; // null-terminate string - GLib.Regex r_hue_bridgeid = /.*hue-bridgeid:\s*([^\s]*).*/; + GLib.Regex r_hue_bridgeid = ".*hue-bridgeid:\\s*([^\\s]*).*"; string hue_bridgeid; GLib.MatchInfo mi; if (r_hue_bridgeid.match ((string) buffer, 0, out mi)) { @@ -244,7 +244,7 @@ public class Philips.Hue.Service { } private void found_bridge_ssdp (string bridgeid, string message) { - GLib.Regex r_location = /.*LOCATION:\s*((http:\/\/)(.*):(\d*)([^\s]*)).*/; + GLib.Regex r_location = ".*LOCATION:\\s*((http:\/\/)(.*):(\\d*)([^\\s]*)).*"; string url, protocol, host, port, path; GLib.MatchInfo mi; if (r_location.match (message, 0, out mi)) { diff --git a/src/services/Settings.vala b/src/services/Settings.vala index 20323f2..52f057a 100644 --- a/src/services/Settings.vala +++ b/src/services/Settings.vala @@ -75,7 +75,7 @@ public class Settings : Granite.Services.Settings { return true; }, (value, expected_type) => { - return new Variant.string(value.get_boolean() ? "dark" : "no-preference"); + return new Variant.string (value.get_boolean () ? "dark" : "no-preference"); }, null, null @@ -102,7 +102,7 @@ public class Settings : Granite.Services.Settings { } public Json.Object configuration_as_json () throws GLib.Error { - var parser = new Json.Parser(); + var parser = new Json.Parser (); parser.load_from_data (configuration, -1); var object = parser.get_root ().get_object (); diff --git a/src/types/Power.vala b/src/types/Power.vala index 6e00f60..6a578dc 100644 --- a/src/types/Power.vala +++ b/src/types/Power.vala @@ -25,7 +25,7 @@ public enum Types.Power { OFF = 0, ON = 65535; - public string to_string() { + public string to_string () { switch (this) { case UNKNOWN: return "unknown"; @@ -37,7 +37,7 @@ public enum Types.Power { return "on"; default: print ("ERROR: Unsupported value %d\n", this); - assert_not_reached(); + assert_not_reached (); } } } diff --git a/src/utils/Buffer.vala b/src/utils/Buffer.vala index 185efa4..ee0f4a0 100644 --- a/src/utils/Buffer.vala +++ b/src/utils/Buffer.vala @@ -51,22 +51,22 @@ public class Buffer { return offset + 1; } - private uint16 readUInt16Backwards (uint8 offset) { + private uint16 read_uint16_backwards (uint8 offset) { return this.values[offset + 1] | (this.values[offset] << 8); } - private uint16 readUInt16Forwards (uint8 offset) { + private uint16 read_uint16_forwards (uint8 offset) { return this.values[offset] | (this.values[offset + 1] << 8); } public uint16 read_uint16_be (uint8 offset) { if (Platform.is_big_endian ()) { - return this.readUInt16Forwards (offset); + return this.read_uint16_forwards (offset); } - return this.readUInt16Backwards (offset); + return this.read_uint16_backwards (offset); } public uint16 read_uint16_le (uint8 offset) { @@ -77,14 +77,14 @@ public class Buffer { return this.readUInt16Forwards (offset); } - private uint8 writeUInt16Backwards (uint16 value, uint8 offset) { + private uint8 writer_uint16_backwards (uint16 value, uint8 offset) { this.values[offset + 1] = (uint8) (value & 0xff); this.values[offset] = (uint8) ((value >> 8) & 0xff); return offset + 2; } - private uint8 writeUInt16Forwards (uint16 value, uint8 offset) { + private uint8 write_uint16_forwards (uint16 value, uint8 offset) { this.values[offset] = (uint8) (value & 0xff); this.values[offset + 1] = (uint8) ((value >> 8) & 0xff); @@ -93,28 +93,28 @@ public class Buffer { public uint8 write_uint16_be (uint16 value, uint8 offset) { if (Platform.is_big_endian ()) { - return this.writeUInt16Forwards (value, offset); + return this.write_uint16_forwards (value, offset); } - return this.writeUInt16Backwards (value, offset); + return this.writer_uint16_backwards (value, offset); } public uint8 write_uint16_le (uint16 value, uint8 offset) { if (Platform.is_big_endian ()) { - return this.writeUInt16Backwards (value, offset); + return this.writer_uint16_backwards (value, offset); } - return this.writeUInt16Forwards (value, offset); + return this.write_uint16_forwards (value, offset); } - private uint32 readUInt32Backwards (uint8 offset) { + private uint32 read_uint32_backwards (uint8 offset) { return this.values[offset + 3] | (this.values[offset + 2] << 8) | (this.values[offset + 1] << 16) | (this.values[offset] << 24); } - private uint32 readUInt32Forwards (uint8 offset) { + private uint32 read_uint32_forwards (uint8 offset) { return this.values[offset] | (this.values[offset + 1] << 8) | (this.values[offset + 2] << 16) @@ -123,21 +123,21 @@ public class Buffer { public uint32 read_uint32_be (uint8 offset) { if (Platform.is_big_endian ()) { - return this.readUInt32Forwards (offset); + return this.read_uint32_forwards (offset); } - return this.readUInt32Backwards (offset); + return this.read_uint32_backwards (offset); } public uint32 read_uint32_le (uint8 offset) { if (Platform.is_big_endian ()) { - return this.readUInt32Backwards (offset); + return this.read_uint32_backwards (offset); } - return this.readUInt32Forwards (offset); + return this.read_uint32_forwards (offset); } - private uint8 writeUInt32Backwards (uint32 value, uint8 offset) { + private uint8 write_uint32_backwards (uint32 value, uint8 offset) { this.values[offset + 3] = (uint8) (value & 0xff); this.values[offset + 2] = (uint8) ((value >> 8) & 0xff); this.values[offset + 1] = (uint8) ((value >> 16) & 0xff); @@ -146,7 +146,7 @@ public class Buffer { return offset + 4; } - private uint8 writeUInt32Forwards (uint32 value, uint8 offset) { + private uint8 write_uint32_forwards (uint32 value, uint8 offset) { this.values[offset] = (uint8) (value & 0xff); this.values[offset + 1] = (uint8) ((value >> 8) & 0xff); this.values[offset + 2] = (uint8) ((value >> 16) & 0xff); @@ -157,28 +157,28 @@ public class Buffer { public uint8 write_uint32_be (uint32 value, uint8 offset) { if (Platform.is_big_endian ()) { - return this.writeUInt32Forwards (value, offset); + return this.write_uint32_forwards (value, offset); } - return this.writeUInt32Backwards (value, offset); + return this.write_uint32_backwards (value, offset); } public uint8 write_uint32_le (uint32 value, uint8 offset) { if (Platform.is_big_endian ()) { - return this.writeUInt32Backwards (value, offset); + return this.write_uint32_backwards (value, offset); } - return this.writeUInt32Forwards (value, offset); + return this.write_uint32_forwards (value, offset); } - private float readFloatBackwards (uint8 offset) { + private float read_float_backwards (uint8 offset) { float f = (float) 0.0; Posix.memcpy (&f, &this.values[offset], 4); return f; } - private float readFloatForwards (uint8 offset) { + private float read_float_forwards (uint8 offset) { float f = (float) 0.0; Posix.memcpy (&f, &this.values[offset], 4); @@ -187,27 +187,27 @@ public class Buffer { public float read_float_be (uint8 offset) { if (Platform.is_big_endian ()) { - return this.readFloatForwards (offset); + return this.read_float_forwards (offset); } - return this.readFloatBackwards (offset); + return this.read_float_backwards (offset); } public float read_float_le (uint8 offset) { if (Platform.is_big_endian ()) { - return this.readFloatBackwards (offset); + return this.read_float_backwards (offset); } - return this.readFloatForwards (offset); + return this.read_float_forwards (offset); } - private uint8 writeFloatBackwards (float value, uint8 offset) { + private uint8 write_float_backwards (float value, uint8 offset) { Posix.memcpy (&this.values[offset], &value, 4); return 4; } - private uint8 writeFloatForwards (float value, uint8 offset) { + private uint8 write_float_forwards (float value, uint8 offset) { Posix.memcpy (&this.values[offset], &value, 4); return 4; @@ -215,18 +215,18 @@ public class Buffer { public uint8 write_float_be (float value, uint8 offset) { if (Platform.is_big_endian ()) { - return this.writeFloatForwards (value, offset); + return this.write_float_forwards (value, offset); } - return this.writeFloatBackwards (value, offset); + return this.write_float_backwards (value, offset); } public uint8 write_float_le (float value, uint8 offset) { if (Platform.is_big_endian ()) { - return this.writeFloatBackwards (value, offset); + return this.write_float_backwards (value, offset); } - return this.writeFloatForwards (value, offset); + return this.write_float_forwards (value, offset); } public Buffer concat (Buffer list) { diff --git a/src/views/Overview.vala b/src/views/Overview.vala index 59ead13..6a3342d 100644 --- a/src/views/Overview.vala +++ b/src/views/Overview.vala @@ -26,9 +26,11 @@ public class Views.Overview : Gtk.ScrolledWindow { private Gtk.Grid grid; public Overview () { - var network_alert_view = new Granite.Widgets.AlertView (_("Network Is Not Available"), - _("Connect to the network to control your smart home gadgets."), - "network-error"); + var network_alert_view = new Granite.Widgets.AlertView ( + _("Network Is Not Available"), + _("Connect to the network to control your smart home gadgets."), + "network-error" + ); network_alert_view.get_style_context ().remove_class (Gtk.STYLE_CLASS_VIEW); network_alert_view.show_action (_("Network Settingsā€¦")); @@ -110,8 +112,8 @@ public class Views.Overview : Gtk.ScrolledWindow { grid.attach (hubs_revealer, 0, 2, 1, 1); - var philipsHueService = Philips.Hue.Service.instance; - philipsHueService.on_new_bridge.connect ((bridge) => { + var philips_hue_service = Philips.Hue.Service.instance; + philips_hue_service.on_new_bridge.connect ((bridge) => { if (loading_revealer.child_revealed) { loading_revealer.reveal_child = false; } diff --git a/src/widgets/ColorPicker.vala b/src/widgets/ColorPicker.vala index a9c1035..07603e3 100644 --- a/src/widgets/ColorPicker.vala +++ b/src/widgets/ColorPicker.vala @@ -60,7 +60,7 @@ public class Widgets.ColorPicker: Gtk.DrawingArea { string shadow_color = "#A9A9A9"; for (int i = 1; i <= shadow_width; i++) { ctx.arc (xc, yc, radius - i, angle1, angle2); - Gdk.RGBA c = Gdk.RGBA(); + Gdk.RGBA c = Gdk.RGBA (); c.parse (shadow_color); c.alpha = shadow_alpha / ((shadow_width - i + 1) * (shadow_width - i + 1)); Gdk.cairo_set_source_rgba (ctx, c);