Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Stephen Smally © 2012
- // This program is free software; you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation; either version 2 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program; if not, write to the Free Software
- // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- // MA 02110-1301, USA.
- //
- using Pk;
- namespace Lsc.Backend {
- public class AppsManager : Object {
- // Signals
- public signal void app_added (Package app);
- public signal void category_added (string category, string group);
- public signal void loading_started (string text);
- public signal void loading_finished ();
- public signal void details_received (Package pkg, Details details);
- // PackageKit stuffs
- private Client client;
- private Control control;
- private Cancellable transaction;
- // Vars
- public string[] icon_table;
- public static void get_pkgs_cb (Progress progress, ProgressType type) {
- if (type == ProgressType.PACKAGE_ID && progress.package != null) {
- stdout.printf("%s, %s\n", progress.package.get_name(), progress.package.get_arch());
- app_added(progress.package);
- while (Gtk.events_pending())spe
- Gtk.main_iteration();
- }
- }
- public void ready () {
- loading_finished();
- }
- public void get_pkgs (string filters) {
- Bitfield filter;
- filter = filter_bitfield_from_string(filters);
- loading_started("Loading packages");
- client.get_packages_async(filter, null, (ProgressCallback) get_pkgs_cb, () => {ready();});
- }
- public void search_for_packages (string filters, string name) {
- Bitfield filter;
- filter = filter_bitfield_from_string(filters);
- loading_started("Loading packages");
- client.search_names_async(filter, {name}, null, (pkg) => {
- if (pkg.package != null) {
- app_added(pkg.package);
- }
- while (Gtk.events_pending())
- Gtk.main_iteration();
- }, () => {
- loading_finished();
- });
- }
- public void get_details (string pkg_id) {
- client.get_details_async({pkg_id},
- null,
- () => {},
- (obj, res) => {
- Results contains = client.generic_finish(res);
- details_received(get_package_from_id(pkg_id), contains.get_details_array()[0]);
- });
- }
- public Package get_package_from_id (string pkg_id) {
- Results res = client.resolve(filter_bitfield_from_string(""),
- {pkg_id},
- null,
- null);
- return res.get_package_array()[0];
- }
- private void fill_icon_table () {
- icon_table = {
- string.joinv("|", {group_enum_to_string(Group.UNKNOWN),"help-browser"}), /* fall though value */
- string.joinv("|", {group_enum_to_string(Group.ACCESSIBILITY), "preferences-desktop-accessibility"}),
- string.joinv("|", {group_enum_to_string(Group.ACCESSORIES), "applications-accessories"}),
- string.joinv("|", {group_enum_to_string(Group.ADMIN_TOOLS), "system-lock-screen"}),
- string.joinv("|", {group_enum_to_string(Group.COLLECTIONS), "pk-collection-installed"}),
- string.joinv("|", {group_enum_to_string(Group.COMMUNICATION), "folder-remote"}),
- string.joinv("|", {group_enum_to_string(Group.DESKTOP_GNOME), "pk-desktop-gnome"}),
- string.joinv("|", {group_enum_to_string(Group.DESKTOP_KDE), "pk-desktop-kde"}),
- string.joinv("|", {group_enum_to_string(Group.DESKTOP_OTHER), "user-desktop"}),
- string.joinv("|", {group_enum_to_string(Group.DESKTOP_XFCE), "pk-desktop-xfce"}),
- string.joinv("|", {group_enum_to_string(Group.DOCUMENTATION), "x-office-address-book"}),
- string.joinv("|", {group_enum_to_string(Group.EDUCATION), "utilities-system-monitor"}),
- string.joinv("|", {group_enum_to_string(Group.ELECTRONICS), "video-display"}),
- string.joinv("|", {group_enum_to_string(Group.FONTS), "preferences-desktop-font"}),
- string.joinv("|", {group_enum_to_string(Group.GAMES), "applications-games"}),
- string.joinv("|", {group_enum_to_string(Group.GRAPHICS), "applications-graphics"}),
- string.joinv("|", {group_enum_to_string(Group.INTERNET), "applications-internet"}),
- string.joinv("|", {group_enum_to_string(Group.LEGACY), "media-floppy"}),
- string.joinv("|", {group_enum_to_string(Group.LOCALIZATION), "preferences-desktop-locale"}),
- string.joinv("|", {group_enum_to_string(Group.MAPS), "applications-multimedia"}),
- string.joinv("|", {group_enum_to_string(Group.MULTIMEDIA), "applications-multimedia"}),
- string.joinv("|", {group_enum_to_string(Group.NETWORK), "network-wired"}),
- string.joinv("|", {group_enum_to_string(Group.OFFICE), "applications-office"}),
- string.joinv("|", {group_enum_to_string(Group.OTHER), "applications-other"}),
- string.joinv("|", {group_enum_to_string(Group.POWER_MANAGEMENT), "battery"}),
- string.joinv("|", {group_enum_to_string(Group.PROGRAMMING), "applications-development"}),
- string.joinv("|", {group_enum_to_string(Group.PUBLISHING), "accessories-dictionary"}),
- string.joinv("|", {group_enum_to_string(Group.REPOS), "system-file-manager"}),
- string.joinv("|", {group_enum_to_string(Group.SCIENCE), "application-certificate"}),
- string.joinv("|", {group_enum_to_string(Group.SECURITY), "network-wireless-encrypted"}),
- string.joinv("|", {group_enum_to_string(Group.SERVERS), "network-server"}),
- string.joinv("|", {group_enum_to_string(Group.SYSTEM), "applications-system"}),
- string.joinv("|", {group_enum_to_string(Group.VIRTUALIZATION), "computer"}),
- string.joinv("|", {group_enum_to_string(Group.VENDOR), "application-certificate"}),
- string.joinv("|", {group_enum_to_string(Group.NEWEST), "dialog-information"})
- };
- }
- private string group_to_icon_name(string group) {
- foreach (string couple in icon_table) {
- if (couple.split("|")[0] == group) {
- return couple.split("|")[1];
- }
- }
- return "";
- }
- public void get_categories () {
- for (int i = 0; i < Group.LAST; i++) {
- if (i != Group.COLLECTIONS && i != Group.NEWEST)
- category_added(group_to_icon_name(group_enum_to_string((Group)i)), group_enum_to_string((Group)i));
- }
- }
- public AppsManager () {
- client = new Client();
- control = new Control();
- transaction = new Cancellable();
- fill_icon_table();
- }
- }
- }
Add Comment
Please, Sign In to add comment