diff --git a/.gitignore b/.gitignore index 42afabf..17b52b2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -/build \ No newline at end of file +/build + +*.glade~ \ No newline at end of file diff --git a/resources/com.github.sergius02.sherlock.xml b/resources/com.github.sergius02.sherlock.xml index 314d480..45e0346 100644 --- a/resources/com.github.sergius02.sherlock.xml +++ b/resources/com.github.sergius02.sherlock.xml @@ -2,6 +2,7 @@ ui/sherlock.glade + css/sherlock.css icons/icon_ip.svg icons/icon_address.svg diff --git a/resources/css/sherlock.css b/resources/css/sherlock.css new file mode 100644 index 0000000..69ef8c8 --- /dev/null +++ b/resources/css/sherlock.css @@ -0,0 +1,4 @@ +.json-output-background { + background-color: #282a36; + color: #fafafa; +} \ No newline at end of file diff --git a/resources/ui/sherlock.glade b/resources/ui/sherlock.glade index b763a2c..c0bc4ad 100644 --- a/resources/ui/sherlock.glade +++ b/resources/ui/sherlock.glade @@ -1,5 +1,5 @@ - + @@ -66,6 +66,9 @@ True False /com/github/sergius02/sherlock/icons/icon_copy.svg + True @@ -493,11 +496,11 @@ 0 + - False @@ -917,6 +920,9 @@ 0 + diff --git a/src/Application.vala b/src/Application.vala index 6c9273c..56b770a 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -1,4 +1,19 @@ -public class Application : Gtk.Application { +public class Sherlock.Application : Gtk.Application { + + public Gtk.Builder builder; + + public Notification notification; + + public Gtk.CssProvider cssProvider; + + public Gtk.Clipboard clipboard; + + public Gtk.ApplicationWindow window; + + public static int main (string[] args) { + var app = new Application (); + return app.run (args); + } public Application () { Object ( @@ -8,16 +23,21 @@ public class Application : Gtk.Application { } protected override void activate () { - var builder = new Gtk.Builder.from_resource ("/com/github/sergius02/sherlock/ui/sherlock.glade"); + this.builder = new Gtk.Builder.from_resource ("/com/github/sergius02/sherlock/ui/sherlock.glade"); + this.cssProvider = new Gtk.CssProvider(); + this.cssProvider.load_from_resource ("/com/github/sergius02/sherlock/css/sherlock.css"); + Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER); + + this.notification = new Notification (_("Sherlock")); builder.set_application (this); - var window = builder.get_object ("main_window") as Gtk.ApplicationWindow; - var clipboard = Gtk.Clipboard.get_for_display (window.get_display (), Gdk.SELECTION_CLIPBOARD); + this.window = builder.get_object ("main_window") as Gtk.ApplicationWindow; + this.clipboard = Gtk.Clipboard.get_for_display (this.window.get_display (), Gdk.SELECTION_CLIPBOARD); - add_window (window); + add_window (this.window); - window.show_all (); + this.window.show_all (); - new Sherlock.Window (builder, clipboard); + new Sherlock.Window (this); } } \ No newline at end of file diff --git a/src/Main.vala b/src/Main.vala deleted file mode 100644 index 0ef83c0..0000000 --- a/src/Main.vala +++ /dev/null @@ -1,4 +0,0 @@ -public static int main (string[] args) { - var app = new Application (); - return app.run (args); -} diff --git a/src/meson.build b/src/meson.build index ddd52ff..c1e9b68 100644 --- a/src/meson.build +++ b/src/meson.build @@ -3,7 +3,6 @@ sources = files ( 'model/ResponseObject.vala', 'model/HTTPRequestHelper.vala', - 'Main.vala', 'Application.vala', 'widgets/Window.vala', diff --git a/src/model/ResponseObject.vala b/src/model/ResponseObject.vala index d6ebf0b..0c4c918 100644 --- a/src/model/ResponseObject.vala +++ b/src/model/ResponseObject.vala @@ -1,19 +1,19 @@ public class Sherlock.ResponseObject { - public string status { get; set; } - public string country { get; set; } - public string countryCode { get; set; } - public string region { get; set; } - public string regionName { get; set; } - public string city { get; set; } - public string zip { get; set; } - public string lat { get; set; } - public string lon { get; set; } - public string timezone { get; set; } - public string isp { get; set; } - public string org { get; set; } - public string as { get; set; } - public string query { get; set; } + public string status; + public string country; + public string countryCode; + public string region; + public string regionName; + public string city; + public string zip; + public string lat; + public string lon; + public string timezone; + public string isp; + public string org; + public string as; + public string query; public ResponseObject (Json.Object root_object) { this.status = root_object.get_string_member("status"); diff --git a/src/widgets/Box.vala b/src/widgets/Box.vala index 3a86b6b..645fdad 100644 --- a/src/widgets/Box.vala +++ b/src/widgets/Box.vala @@ -1,88 +1,83 @@ public abstract class Sherlock.Box : Gtk.Box { - protected Gtk.Application application { get; set; } - protected Gtk.Builder builder { get; set; } - protected Gtk.Clipboard clipboard { get; set; } - protected Notification notification { get; set; } - - protected Gtk.Label label_ip { get; set; } - protected Gtk.Label label_address { get; set; } - protected Gtk.Label label_timezone { get; set; } - protected Gtk.Label label_latlong { get; set; } - protected Gtk.Label label_isp { get; set; } - protected Gtk.Label label_as { get; set; } - - protected Gtk.Image image_ip { get; set; } - protected Gtk.Image image_address { get; set; } - protected Gtk.Image image_timezone { get; set; } - protected Gtk.Image image_latlong { get; set; } - protected Gtk.Image image_isp { get; set; } - protected Gtk.Image image_as { get; set; } - - protected Gtk.Button button_ip { get; set; } - protected Gtk.Button button_address { get; set; } - protected Gtk.Button button_timezone { get; set; } - protected Gtk.Button button_latlong { get; set; } - protected Gtk.Button button_isp { get; set; } - protected Gtk.Button button_as { get; set; } - - protected Gtk.Label label_json_output { get; set;} - protected Gtk.Button button_json_output { get; set; } - - protected Gtk.Button button_buttonrevealer { get; set; } + protected Sherlock.Application application; + + protected Gtk.Label labelIP; + protected Gtk.Label labelAddress; + protected Gtk.Label labelTimezone; + protected Gtk.Label labelLatlong; + protected Gtk.Label labelISP; + protected Gtk.Label labelAS; + + protected Gtk.Image imageIP; + protected Gtk.Image imageAddress; + protected Gtk.Image imageTimezone; + protected Gtk.Image imageLatlong; + protected Gtk.Image imageISP; + protected Gtk.Image imageAS; + + protected Gtk.Button buttonIP; + protected Gtk.Button buttonAddress; + protected Gtk.Button buttonTimezone; + protected Gtk.Button buttonLatlong; + protected Gtk.Button buttonISP; + protected Gtk.Button buttonAS; + + protected Gtk.Label labelJSONOutput; + protected Gtk.Button buttonJSONOutput; + + protected Gtk.Button buttonRevealer; + protected Gtk.Revealer revealerJSON; protected void initUI (string stackPrefix) { - this.application = this.builder.get_application (); - this.notification = new Notification (_("Sherlock")); - - this.image_address = builder.get_object (stackPrefix + "_ImageAddress") as Gtk.Image; - this.image_timezone = builder.get_object (stackPrefix + "_ImageTimezone") as Gtk.Image; - this.image_latlong = builder.get_object (stackPrefix + "_ImageLatLong") as Gtk.Image; - this.image_isp = builder.get_object (stackPrefix + "_ImageISP") as Gtk.Image; - this.image_as = builder.get_object (stackPrefix + "_ImageAS") as Gtk.Image; - - this.label_address = builder.get_object (stackPrefix + "_LabelAddress") as Gtk.Label; - this.label_timezone = builder.get_object (stackPrefix + "_LabelTimezone") as Gtk.Label; - this.label_latlong = builder.get_object (stackPrefix + "_LabelLatLong") as Gtk.Label; - this.label_isp = builder.get_object (stackPrefix + "_LabelISP") as Gtk.Label; - this.label_as = builder.get_object (stackPrefix + "_LabelAS") as Gtk.Label; - - this.button_address = builder.get_object (stackPrefix + "_ButtonAddress") as Gtk.Button; - this.button_timezone = builder.get_object (stackPrefix + "_ButtonTimezone") as Gtk.Button; - this.button_latlong = builder.get_object (stackPrefix + "_ButtonLatLong") as Gtk.Button; - this.button_isp = builder.get_object (stackPrefix + "_ButtonISP") as Gtk.Button; - this.button_as = builder.get_object (stackPrefix + "_ButtonAS") as Gtk.Button; - - this.button_json_output = builder.get_object (stackPrefix + "_ButtonJSON") as Gtk.Button; - this.label_json_output = builder.get_object (stackPrefix + "_LabelJsonOutput") as Gtk.Label; - - setCopyButtonAction (button_address, label_address, "Address"); - setCopyButtonAction (button_timezone, label_timezone, "Timezone"); - setCopyButtonAction (button_latlong, label_latlong, "Latitude and longitude"); - setCopyButtonAction (button_isp, label_isp, "ISP"); - setCopyButtonAction (button_as, label_as, "AS"); - setCopyButtonAction (button_json_output, label_json_output, "JSON"); - - this.button_buttonrevealer = builder.get_object (stackPrefix + "_ButtonRevealerJSON") as Gtk.Button; - var revealer_json = builder.get_object (stackPrefix + "_RevealerJSON") as Gtk.Revealer; - - button_buttonrevealer.clicked.connect( () => { - if (!revealer_json.get_reveal_child()) { - revealer_json.set_reveal_child(true); - button_buttonrevealer.set_label(_("Hide JSON response")); + this.imageAddress = this.application.builder.get_object (stackPrefix + "_ImageAddress") as Gtk.Image; + this.imageTimezone = this.application.builder.get_object (stackPrefix + "_ImageTimezone") as Gtk.Image; + this.imageLatlong = this.application.builder.get_object (stackPrefix + "_ImageLatLong") as Gtk.Image; + this.imageISP = this.application.builder.get_object (stackPrefix + "_ImageISP") as Gtk.Image; + this.imageAS = this.application.builder.get_object (stackPrefix + "_ImageAS") as Gtk.Image; + + this.labelAddress = this.application.builder.get_object (stackPrefix + "_LabelAddress") as Gtk.Label; + this.labelTimezone = this.application.builder.get_object (stackPrefix + "_LabelTimezone") as Gtk.Label; + this.labelLatlong = this.application.builder.get_object (stackPrefix + "_LabelLatLong") as Gtk.Label; + this.labelISP = this.application.builder.get_object (stackPrefix + "_LabelISP") as Gtk.Label; + this.labelAS = this.application.builder.get_object (stackPrefix + "_LabelAS") as Gtk.Label; + + this.buttonAddress = this.application.builder.get_object (stackPrefix + "_ButtonAddress") as Gtk.Button; + this.buttonTimezone = this.application.builder.get_object (stackPrefix + "_ButtonTimezone") as Gtk.Button; + this.buttonLatlong = this.application.builder.get_object (stackPrefix + "_ButtonLatLong") as Gtk.Button; + this.buttonISP = this.application.builder.get_object (stackPrefix + "_ButtonISP") as Gtk.Button; + this.buttonAS = this.application.builder.get_object (stackPrefix + "_ButtonAS") as Gtk.Button; + + this.buttonJSONOutput = this.application.builder.get_object (stackPrefix + "_ButtonJSON") as Gtk.Button; + this.labelJSONOutput = this.application.builder.get_object (stackPrefix + "_LabelJsonOutput") as Gtk.Label; + + setCopyButtonAction (this.buttonAddress, labelAddress, "Address"); + setCopyButtonAction (this.buttonTimezone, labelTimezone, "Timezone"); + setCopyButtonAction (this.buttonLatlong, labelLatlong, "Latitude and longitude"); + setCopyButtonAction (this.buttonISP, labelISP, "ISP"); + setCopyButtonAction (this.buttonAS, labelAS, "AS"); + setCopyButtonAction (this.buttonJSONOutput, labelJSONOutput, "JSON"); + + this.buttonRevealer = this.application.builder.get_object (stackPrefix + "_ButtonRevealerJSON") as Gtk.Button; + this.revealerJSON = this.application.builder.get_object (stackPrefix + "_RevealerJSON") as Gtk.Revealer; + + this.buttonRevealer.clicked.connect( () => { + if (!this.revealerJSON.get_reveal_child()) { + this.revealerJSON.set_reveal_child(true); + this.buttonRevealer.set_label(_("Hide JSON response")); } else { - revealer_json.set_reveal_child(false); - button_buttonrevealer.set_label(_("Show JSON response")); + this.revealerJSON.set_reveal_child(false); + this.buttonRevealer.set_label(_("Show JSON response")); } }); } protected void setCopyButtonAction (Gtk.Button button, Gtk.Label label, string notificationText) { button.clicked.connect( () => { - clipboard.set_text (label.get_text (), -1); - notification.set_body (_(notificationText + " copied to clipboard!")); - application.send_notification ("com.github.sergius02.sherlock", notification); + this.application.clipboard.set_text (label.get_text (), -1); + this.application.notification.set_body (_(notificationText + " copied to clipboard!")); + this.application.send_notification ("com.github.sergius02.sherlock", application.notification); }); } @@ -91,17 +86,17 @@ public abstract class Sherlock.Box : Gtk.Box { var response = httpRequestHelper.generateHTTPRequest (text); if (text == "") { - this.label_ip.set_text (response.query); + this.labelIP.set_text (response.query); } - this.label_address.set_text (response.zip + " " + response.city + ", " + response.regionName + ", " + response.country); - this.label_timezone.set_text (response.timezone); - this.label_latlong.set_text (response.lat + ", " + response.lon); - this.label_isp.set_text (response.org + ", " + response.isp); - this.label_as.set_text (response.as); + this.labelAddress.set_text (response.zip + " " + response.city + ", " + response.regionName + ", " + response.country); + this.labelTimezone.set_text (response.timezone); + this.labelLatlong.set_text (response.lat + ", " + response.lon); + this.labelISP.set_text (response.org + ", " + response.isp); + this.labelAS.set_text (response.as); var resultJSON = httpRequestHelper.get_result (); - this.label_json_output.set_text (resultJSON); + this.labelJSONOutput.set_text (resultJSON); } } \ No newline at end of file diff --git a/src/widgets/DeviceIPBox.vala b/src/widgets/DeviceIPBox.vala index 4fd3585..30b54ff 100644 --- a/src/widgets/DeviceIPBox.vala +++ b/src/widgets/DeviceIPBox.vala @@ -1,15 +1,14 @@ public class Sherlock.DeviceIPBox : Sherlock.Box { - public DeviceIPBox (Gtk.Builder builder, Gtk.Clipboard clipboard) { - this.builder = builder; - this.clipboard = clipboard; - + public DeviceIPBox (Sherlock.Application application) { + this.application = application; + initUI ("deviceIP"); - this.image_ip = builder.get_object ("deviceIP_ImageIP") as Gtk.Image; - this.label_ip = builder.get_object ("deviceIP_LabelIP") as Gtk.Label; - this.button_ip = builder.get_object ("deviceIP_ButtonIP") as Gtk.Button; - setCopyButtonAction(this.button_ip, this.label_ip, "IP"); + this.imageIP = application.builder.get_object ("deviceIP_ImageIP") as Gtk.Image; + this.labelIP = application.builder.get_object ("deviceIP_LabelIP") as Gtk.Label; + this.buttonIP = application.builder.get_object ("deviceIP_ButtonIP") as Gtk.Button; + setCopyButtonAction(this.buttonIP, this.labelIP, "IP"); fillLabels (""); } diff --git a/src/widgets/HeaderBar.vala b/src/widgets/HeaderBar.vala index 2201d25..5702480 100644 --- a/src/widgets/HeaderBar.vala +++ b/src/widgets/HeaderBar.vala @@ -1,9 +1,9 @@ public class Sherlock.HeaderBar { - private Gtk.Button headerbar_github { get; set; } + private Gtk.Button linkbuttonGithub { get; set; } - public HeaderBar (Gtk.Builder builder) { - this.headerbar_github = builder.get_object ("headerbar_github") as Gtk.LinkButton; + public HeaderBar (Sherlock.Application application) { + this.linkbuttonGithub = application.builder.get_object ("headerbar_github") as Gtk.LinkButton; } } diff --git a/src/widgets/SearchIPBox.vala b/src/widgets/SearchIPBox.vala index 074451d..680c920 100644 --- a/src/widgets/SearchIPBox.vala +++ b/src/widgets/SearchIPBox.vala @@ -1,21 +1,26 @@ public class Sherlock.SearchIPBox : Sherlock.Box { - public SearchIPBox (Gtk.Builder builder, Gtk.Clipboard clipboard) { - this.builder = builder; - this.clipboard = clipboard; + private Gtk.Grid gridInfo; + + private Gtk.Button buttonSearchIP; + + private Gtk.Entry entryIP; + + public SearchIPBox (Sherlock.Application application) { + this.application = application; initUI ("searchIP"); - var gridinfo = builder.get_object ("searchIP_GridInfo") as Gtk.Grid; - gridinfo.visible = false; - this.button_buttonrevealer.visible = false; + this.gridInfo = application.builder.get_object ("searchIP_GridInfo") as Gtk.Grid; + gridInfo.visible = false; + this.buttonRevealer.visible = false; - var button_searchip = builder.get_object ("searchIP_ButtonSearchIP") as Gtk.Button; - button_searchip.clicked.connect( () => { - var entryip = builder.get_object ("searchIP_EntryIP") as Gtk.Entry; - gridinfo.visible = true; - this.button_buttonrevealer.visible = true; - fillLabels (entryip.get_text ()); + this.buttonSearchIP = application.builder.get_object ("searchIP_ButtonSearchIP") as Gtk.Button; + buttonSearchIP.clicked.connect( () => { + this.entryIP = application.builder.get_object ("searchIP_EntryIP") as Gtk.Entry; + this.gridInfo.visible = true; + this.buttonRevealer.visible = true; + fillLabels (this.entryIP.get_text ()); }); } diff --git a/src/widgets/Window.vala b/src/widgets/Window.vala index 219be9a..75ccb1f 100644 --- a/src/widgets/Window.vala +++ b/src/widgets/Window.vala @@ -1,17 +1,15 @@ public class Sherlock.Window { - private Gtk.Builder builder { set; get; } - - public Window (Gtk.Builder builder, Gtk.Clipboard clipboard) { + public Window (Sherlock.Application application) { // The Headerbar - new Sherlock.HeaderBar (builder); + new Sherlock.HeaderBar (application); // Device IP page - new Sherlock.DeviceIPBox (builder, clipboard); + new Sherlock.DeviceIPBox (application); // Search IP page - new Sherlock.SearchIPBox (builder, clipboard); + new Sherlock.SearchIPBox (application); }