some code improvements
This commit is contained in:
parent
66e66eab7e
commit
271c4a4204
35
src/aur.vala
35
src/aur.vala
@ -33,15 +33,16 @@ namespace AUR {
|
|||||||
var session = new Soup.Session ();
|
var session = new Soup.Session ();
|
||||||
var message = new Soup.Message ("GET", uri);
|
var message = new Soup.Message ("GET", uri);
|
||||||
var parser = new Json.Parser ();
|
var parser = new Json.Parser ();
|
||||||
unowned Json.Object root_object;
|
|
||||||
session.send_message (message);
|
session.send_message (message);
|
||||||
try {
|
try {
|
||||||
parser.load_from_data ((string) message.response_body.flatten ().data, -1);
|
parser.load_from_data ((string) message.response_body.flatten ().data, -1);
|
||||||
root_object = parser.get_root ().get_object ();
|
|
||||||
prev_inter = root_object.get_array_member ("results");
|
|
||||||
} catch (Error e) {
|
} catch (Error e) {
|
||||||
print (e.message);
|
print (e.message);
|
||||||
}
|
}
|
||||||
|
unowned Json.Node? root = parser.get_root ();
|
||||||
|
if (root != null) {
|
||||||
|
prev_inter = root.get_object ().get_array_member ("results");
|
||||||
|
}
|
||||||
int length = needles.length;
|
int length = needles.length;
|
||||||
if (length == 1)
|
if (length == 1)
|
||||||
return prev_inter;
|
return prev_inter;
|
||||||
@ -55,11 +56,13 @@ namespace AUR {
|
|||||||
session.send_message (message);
|
session.send_message (message);
|
||||||
try {
|
try {
|
||||||
parser.load_from_data ((string) message.response_body.flatten ().data, -1);
|
parser.load_from_data ((string) message.response_body.flatten ().data, -1);
|
||||||
root_object = parser.get_root ().get_object ();
|
|
||||||
found = root_object.get_array_member ("results");
|
|
||||||
} catch (Error e) {
|
} catch (Error e) {
|
||||||
print (e.message);
|
print (e.message);
|
||||||
}
|
}
|
||||||
|
root = parser.get_root ();
|
||||||
|
if (root != null) {
|
||||||
|
found = root.get_object ().get_array_member ("results");
|
||||||
|
}
|
||||||
foreach (var prev_inter_node in prev_inter.get_elements ()) {
|
foreach (var prev_inter_node in prev_inter.get_elements ()) {
|
||||||
foreach (var found_node in found.get_elements ()) {
|
foreach (var found_node in found.get_elements ()) {
|
||||||
if (strcmp (prev_inter_node.get_object ().get_string_member ("Name"),
|
if (strcmp (prev_inter_node.get_object ().get_string_member ("Name"),
|
||||||
@ -68,27 +71,31 @@ namespace AUR {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i != (length -1))
|
if (i != (length -1)) {
|
||||||
prev_inter = inter;
|
prev_inter = inter;
|
||||||
|
}
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
return inter;
|
return inter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Json.Object? info (string pkgname) {
|
public Json.Object info (string pkgname) {
|
||||||
unowned Json.Object? pkg_info = null;
|
var pkg_info = new Json.Object ();
|
||||||
string uri = rpc_url + rpc_info + Uri.escape_string (pkgname);
|
string uri = rpc_url + rpc_info + Uri.escape_string (pkgname);
|
||||||
var session = new Soup.Session ();
|
var session = new Soup.Session ();
|
||||||
var message = new Soup.Message ("GET", uri);
|
var message = new Soup.Message ("GET", uri);
|
||||||
session.send_message (message);
|
session.send_message (message);
|
||||||
|
var parser = new Json.Parser ();
|
||||||
try {
|
try {
|
||||||
var parser = new Json.Parser ();
|
|
||||||
parser.load_from_data ((string) message.response_body.flatten ().data, -1);
|
parser.load_from_data ((string) message.response_body.flatten ().data, -1);
|
||||||
pkg_info = parser.get_root ().get_object ().get_object_member ("results");
|
|
||||||
} catch (Error e) {
|
} catch (Error e) {
|
||||||
stderr.printf ("Failed to get infos about %s from AUR\n", pkgname);
|
stderr.printf ("Failed to get infos about %s from AUR\n", pkgname);
|
||||||
print (e.message);
|
print (e.message);
|
||||||
}
|
}
|
||||||
|
unowned Json.Node? root = parser.get_root ();
|
||||||
|
if (root != null) {
|
||||||
|
pkg_info = root.get_object ().get_object_member ("results");
|
||||||
|
}
|
||||||
return pkg_info;
|
return pkg_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,14 +111,16 @@ namespace AUR {
|
|||||||
var session = new Soup.Session ();
|
var session = new Soup.Session ();
|
||||||
var message = new Soup.Message ("GET", builder.str);
|
var message = new Soup.Message ("GET", builder.str);
|
||||||
session.send_message (message);
|
session.send_message (message);
|
||||||
|
var parser = new Json.Parser ();
|
||||||
try {
|
try {
|
||||||
var parser = new Json.Parser ();
|
|
||||||
parser.load_from_data ((string) message.response_body.flatten ().data, -1);
|
parser.load_from_data ((string) message.response_body.flatten ().data, -1);
|
||||||
unowned Json.Object root_object = parser.get_root ().get_object ();
|
|
||||||
results = root_object.get_array_member ("results");
|
|
||||||
} catch (Error e) {
|
} catch (Error e) {
|
||||||
print (e.message);
|
print (e.message);
|
||||||
}
|
}
|
||||||
|
unowned Json.Node? root = parser.get_root ();
|
||||||
|
if (root != null) {
|
||||||
|
results = root.get_object ().get_array_member ("results");
|
||||||
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -469,7 +469,7 @@ namespace Pamac {
|
|||||||
return pkgs;
|
return pkgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void populate_packages_list (Alpm.List<Alpm.Package?>? pkgs, Json.Array? aur_pkgs = null) {
|
public void populate_packages_list (Alpm.List<Alpm.Package?>? pkgs, Json.Array? aur_pkgs = new Json.Array ()) {
|
||||||
packages_treeview.freeze_child_notify ();
|
packages_treeview.freeze_child_notify ();
|
||||||
packages_treeview.set_model (null);
|
packages_treeview.set_model (null);
|
||||||
|
|
||||||
@ -924,7 +924,7 @@ namespace Pamac {
|
|||||||
Json.Array aur_pkgs;
|
Json.Array aur_pkgs;
|
||||||
Alpm.List<Alpm.Package?> pkgs = search_pkgs.end (res, out aur_pkgs);
|
Alpm.List<Alpm.Package?> pkgs = search_pkgs.end (res, out aur_pkgs);
|
||||||
populate_packages_list (pkgs, aur_pkgs);
|
populate_packages_list (pkgs, aur_pkgs);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1058,7 +1058,7 @@ namespace Pamac {
|
|||||||
text.append ("\n");
|
text.append ("\n");
|
||||||
}
|
}
|
||||||
} catch (GLib.Error e) {
|
} catch (GLib.Error e) {
|
||||||
GLib.stderr.printf("%s\n", e.message);
|
GLib.stderr.printf ("%s\n", e.message);
|
||||||
}
|
}
|
||||||
history_dialog.textview.buffer.set_text (text.str, (int) text.len);
|
history_dialog.textview.buffer.set_text (text.str, (int) text.len);
|
||||||
history_dialog.run ();
|
history_dialog.run ();
|
||||||
|
@ -29,23 +29,18 @@ namespace Pamac {
|
|||||||
foreach (unowned Alpm.Package alpm_pkg in alpm_pkgs) {
|
foreach (unowned Alpm.Package alpm_pkg in alpm_pkgs) {
|
||||||
all_pkgs.append (new Pamac.Package (alpm_pkg, null));
|
all_pkgs.append (new Pamac.Package (alpm_pkg, null));
|
||||||
}
|
}
|
||||||
if (aur_pkgs != null) {
|
bool found;
|
||||||
unowned Json.Object pkg_info;
|
foreach (var node in aur_pkgs.get_elements ()) {
|
||||||
string name;
|
// add only the packages which are not already in the list
|
||||||
bool found;
|
found = false;
|
||||||
foreach (var node in aur_pkgs.get_elements ()) {
|
foreach (Pamac.Package pkg in all_pkgs) {
|
||||||
pkg_info = node.get_object ();
|
if (pkg.name == node.get_object ().get_string_member ("Name")) {
|
||||||
name = pkg_info.get_string_member ("Name");
|
found = true;
|
||||||
// add only the packages which are not already in the list
|
break;
|
||||||
found = false;
|
|
||||||
foreach (Pamac.Package pkg in all_pkgs) {
|
|
||||||
if (pkg.name == name) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (found == false)
|
}
|
||||||
all_pkgs.append (new Pamac.Package (null, pkg_info));
|
if (found == false) {
|
||||||
|
all_pkgs.append (new Pamac.Package (null, node.get_object ()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (all_pkgs.length () == 0) {
|
if (all_pkgs.length () == 0) {
|
||||||
|
@ -537,7 +537,7 @@ namespace Pamac {
|
|||||||
public void build_aur_packages () {
|
public void build_aur_packages () {
|
||||||
print ("building packages\n");
|
print ("building packages\n");
|
||||||
string action = dgettext (null,"Building packages") + "...";
|
string action = dgettext (null,"Building packages") + "...";
|
||||||
spawn_in_term ({"echo", "-n", action});
|
spawn_in_term ({"echo", action});
|
||||||
progress_dialog.action_label.set_text (action);
|
progress_dialog.action_label.set_text (action);
|
||||||
progress_dialog.progressbar.set_fraction (0);
|
progress_dialog.progressbar.set_fraction (0);
|
||||||
progress_dialog.progressbar.set_text ("");
|
progress_dialog.progressbar.set_text ("");
|
||||||
@ -1131,7 +1131,7 @@ namespace Pamac {
|
|||||||
|
|
||||||
void on_emit_generate_mirrorlist_start () {
|
void on_emit_generate_mirrorlist_start () {
|
||||||
string action = dgettext (null, "Generating mirrorlist") + "...";
|
string action = dgettext (null, "Generating mirrorlist") + "...";
|
||||||
spawn_in_term ({"echo", "-n", action});
|
spawn_in_term ({"echo", action});
|
||||||
progress_dialog.action_label.set_text (action);
|
progress_dialog.action_label.set_text (action);
|
||||||
progress_dialog.progressbar.set_fraction (0);
|
progress_dialog.progressbar.set_fraction (0);
|
||||||
progress_dialog.progressbar.set_text ("");
|
progress_dialog.progressbar.set_text ("");
|
||||||
|
Loading…
Reference in New Issue
Block a user