#include "Cache.hpp" #include #include #include using namespace std; using namespace net::lliurex::apt; Cache::Cache() { } Cache::Cache(function progress,function ready) { this->cb_progress=progress; this->cb_ready=ready; } Cache::~Cache() { } void Cache::OnSignal(const Glib::ustring& sender_name, const Glib::ustring& signal_name, const Glib::VariantContainerBase& parameters) { //cout<<"-- "< prop_name; parameters.get_child(prop_name,0); //cout<<"-- "< p; q.get_child(p,0); //cout<<"* ["< desc; qq.get_child(desc,2); //cout< current; Glib::Variant total; qq.get_child(current,0); qq.get_child(total,1); //cout<<"progress: "<<(float)100.0f * current.get()/total.get()<0) { progress = (int)(100.0f * current.get()/total.get()); } } } if(signal_name=="Finished") { if(cancel_request==false) cb_ready(); loop->quit(); } } void Cache::Update() { cancel_request=false; Glib::Thread::create(sigc::mem_fun(*this, &Cache::UpdateThread), true); } void Cache::UpdateThread() { progress=0; connection = Gio::DBus::Connection::get_sync(Gio::DBus::BUS_TYPE_SYSTEM); if(!connection) { throw runtime_error("Failed to connect to system bus"); } Glib::RefPtr proxy; proxy = Gio::DBus::Proxy::create_sync(connection, "org.debian.apt", "/org/debian/apt", "org.debian.apt"); try { const Glib::VariantContainerBase address = proxy->call_sync("UpdateCache"); Glib::Variant res; address.get_child(res); cout<<"Address: "<signal_signal().connect(sigc::mem_fun(*this,&Cache::OnSignal)); transaction_proxy->call_sync("Run"); cout<<"waiting for a train..."<run(); } catch(Gio::DBus::Error e) { //should we really exit from the application? cerr<<"Error: "<call_sync("Cancel"); } catch(Gio::DBus::Error e) { cerr<<"Error: "<