Skip to content

Commit

Permalink
🎨 Some code style
Browse files Browse the repository at this point in the history
  • Loading branch information
sergius02 committed Sep 24, 2020
1 parent 9a31028 commit 0c2aacc
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 89 deletions.
149 changes: 75 additions & 74 deletions src/widgets/Box.vala
Original file line number Diff line number Diff line change
@@ -1,82 +1,83 @@
public abstract class Sherlock.Box : Gtk.Box {

protected Sherlock.Application application { 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.image_address = application.builder.get_object (stackPrefix + "_ImageAddress") as Gtk.Image;
this.image_timezone = application.builder.get_object (stackPrefix + "_ImageTimezone") as Gtk.Image;
this.image_latlong = application.builder.get_object (stackPrefix + "_ImageLatLong") as Gtk.Image;
this.image_isp = application.builder.get_object (stackPrefix + "_ImageISP") as Gtk.Image;
this.image_as = application.builder.get_object (stackPrefix + "_ImageAS") as Gtk.Image;

this.label_address = application.builder.get_object (stackPrefix + "_LabelAddress") as Gtk.Label;
this.label_timezone = application.builder.get_object (stackPrefix + "_LabelTimezone") as Gtk.Label;
this.label_latlong = application.builder.get_object (stackPrefix + "_LabelLatLong") as Gtk.Label;
this.label_isp = application.builder.get_object (stackPrefix + "_LabelISP") as Gtk.Label;
this.label_as = application.builder.get_object (stackPrefix + "_LabelAS") as Gtk.Label;

this.button_address = application.builder.get_object (stackPrefix + "_ButtonAddress") as Gtk.Button;
this.button_timezone = application.builder.get_object (stackPrefix + "_ButtonTimezone") as Gtk.Button;
this.button_latlong = application.builder.get_object (stackPrefix + "_ButtonLatLong") as Gtk.Button;
this.button_isp = application.builder.get_object (stackPrefix + "_ButtonISP") as Gtk.Button;
this.button_as = application.builder.get_object (stackPrefix + "_ButtonAS") as Gtk.Button;

this.button_json_output = application.builder.get_object (stackPrefix + "_ButtonJSON") as Gtk.Button;
this.label_json_output = application.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 = application.builder.get_object (stackPrefix + "_ButtonRevealerJSON") as Gtk.Button;
var revealer_json = application.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( () => {
application.clipboard.set_text (label.get_text (), -1);
application.notification.set_body (_(notificationText + " copied to clipboard!"));
application.send_notification ("com.github.sergius02.sherlock", application.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 @@ -85,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);
}

}
8 changes: 4 additions & 4 deletions src/widgets/DeviceIPBox.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ public class Sherlock.DeviceIPBox : Sherlock.Box {

initUI ("deviceIP");

this.image_ip = application.builder.get_object ("deviceIP_ImageIP") as Gtk.Image;
this.label_ip = application.builder.get_object ("deviceIP_LabelIP") as Gtk.Label;
this.button_ip = application.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
4 changes: 2 additions & 2 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 (Sherlock.Application application) {
this.headerbar_github = application.builder.get_object ("headerbar_github") as Gtk.LinkButton;
this.linkbuttonGithub = application.builder.get_object ("headerbar_github") as Gtk.LinkButton;
}

}
24 changes: 15 additions & 9 deletions src/widgets/SearchIPBox.vala
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
public class Sherlock.SearchIPBox : Sherlock.Box {

private Gtk.Grid gridInfo;

private Gtk.Button buttonSearchIP;

private Gtk.Entry entryIP;

public SearchIPBox (Sherlock.Application application) {
this.application = application;

initUI ("searchIP");

var gridinfo = application.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 = application.builder.get_object ("searchIP_ButtonSearchIP") as Gtk.Button;
button_searchip.clicked.connect( () => {
var entryip = application.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 ());
});
}

Expand Down

0 comments on commit 0c2aacc

Please sign in to comment.