Skip to content

Commit

Permalink
🔀️ Merge pull request #8 from sergius02/development
Browse files Browse the repository at this point in the history
  • Loading branch information
sergius02 authored Sep 24, 2020
2 parents 49407c5 + 13cbde0 commit 85425aa
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 140 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/build
/build

*.glade~
1 change: 1 addition & 0 deletions resources/com.github.sergius02.sherlock.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<gresources>
<gresource prefix="/com/github/sergius02/sherlock/">
<file>ui/sherlock.glade</file>
<file>css/sherlock.css</file>

<file>icons/icon_ip.svg</file>
<file>icons/icon_address.svg</file>
Expand Down
4 changes: 4 additions & 0 deletions resources/css/sherlock.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.json-output-background {
background-color: #282a36;
color: #fafafa;
}
14 changes: 10 additions & 4 deletions resources/ui/sherlock.glade
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.37.0 -->
<!-- Generated with glade 3.39.0 -->
<interface>
<requires lib="gtk+" version="3.22"/>
<object class="GtkImage" id="image_Github">
Expand Down Expand Up @@ -66,6 +66,9 @@
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="resource">/com/github/sergius02/sherlock/icons/icon_copy.svg</property>
<style>
<class name="json-output-background"/>
</style>
</object>
<object class="GtkImage" id="image_copyJSON2">
<property name="visible">True</property>
Expand Down Expand Up @@ -493,11 +496,11 @@
<property name="top-attach">0</property>
</packing>
</child>
<style>
<class name="json-output-background"/>
</style>
</object>
</child>
<style>
<class name="json-output-background"/>
</style>
</object>
<packing>
<property name="expand">False</property>
Expand Down Expand Up @@ -917,6 +920,9 @@
<property name="top-attach">0</property>
</packing>
</child>
<style>
<class name="json-output-background"/>
</style>
</object>
</child>
</object>
Expand Down
34 changes: 27 additions & 7 deletions src/Application.vala
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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);
}
}
4 changes: 0 additions & 4 deletions src/Main.vala

This file was deleted.

1 change: 0 additions & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ sources = files (
'model/ResponseObject.vala',
'model/HTTPRequestHelper.vala',

'Main.vala',
'Application.vala',

'widgets/Window.vala',
Expand Down
28 changes: 14 additions & 14 deletions src/model/ResponseObject.vala
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
155 changes: 75 additions & 80 deletions src/widgets/Box.vala
Original file line number Diff line number Diff line change
@@ -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);
});
}

Expand All @@ -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);
}

}
15 changes: 7 additions & 8 deletions src/widgets/DeviceIPBox.vala
Original file line number Diff line number Diff line change
@@ -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 ("");
}
Expand Down
6 changes: 3 additions & 3 deletions src/widgets/HeaderBar.vala
Original file line number Diff line number Diff line change
@@ -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;
}

}
Loading

0 comments on commit 85425aa

Please sign in to comment.