Merge lp:~diegosarmentero/unity-scope-click/improve-manifest-and-accounts into lp:unity-scope-click

Proposed by Diego Sarmentero
Status: Merged
Merged at revision: 173
Proposed branch: lp:~diegosarmentero/unity-scope-click/improve-manifest-and-accounts
Merge into: lp:unity-scope-click
Prerequisite: lp:~diegosarmentero/unity-scope-click/open-after-install
Diff against target: 136 lines (+68/-9)
3 files modified
scope/click/interface.cpp (+63/-9)
scope/click/interface.h (+2/-0)
scope/click/scope.cpp (+3/-0)
To merge this branch: bzr merge lp:~diegosarmentero/unity-scope-click/improve-manifest-and-accounts
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Ubuntu One hackers Pending
Review via email: mp+207935@code.launchpad.net

Commit message

- Open Accounts on the proper action, and Obtain the manifest of the proper app_id

Description of the change

This branch opens Accounts for No Credentials, and only parse the manifest of the app_id requested, doesn't get the list of the manifest for all the installed apps and parse that.

To post a comment you must log in.
182. By Diego Sarmentero

remove commented code

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'scope/click/interface.cpp'
2--- scope/click/interface.cpp 2014-02-24 14:10:31 +0000
3+++ scope/click/interface.cpp 2014-02-24 14:10:31 +0000
4@@ -272,6 +272,33 @@
5 return manifests;
6 }
7
8+Manifest manifest_from_json(const std::string& json)
9+{
10+ using namespace boost::property_tree;
11+
12+ std::istringstream is(json);
13+
14+ ptree pt;
15+ read_json(is, pt);
16+
17+ std::string name = pt.get<std::string>("name");
18+ std::string version = pt.get<std::string>("version");
19+ std::string first_app_name;
20+
21+ BOOST_FOREACH(ptree::value_type &sv, pt.get_child("hooks"))
22+ {
23+ // FIXME: "primary app" for a package is not defined, we just
24+ // use first one here:
25+ first_app_name = sv.first;
26+ break;
27+ }
28+ qDebug() << "adding manifest: " << name.c_str() << version.c_str() << first_app_name.c_str();
29+
30+ Manifest manifest(name, version, first_app_name);
31+
32+ return manifest;
33+}
34+
35 void Interface::get_manifests(std::function<void(ManifestList, ManifestError)> callback)
36 {
37 QSharedPointer<QProcess> process(new QProcess());
38@@ -304,28 +331,55 @@
39 process->start(command.c_str());
40 }
41
42+void Interface::get_manifest_for_app(const std::string &app_id,
43+ std::function<void(Manifest, ManifestError)> callback)
44+{
45+ QSharedPointer<QProcess> process(new QProcess());
46+ typedef void(QProcess::*QProcessFinished)(int, QProcess::ExitStatus);
47+ typedef void(QProcess::*QProcessError)(QProcess::ProcessError);
48+ QObject::connect(process.data(),
49+ static_cast<QProcessFinished>(&QProcess::finished),
50+ [callback, process](int code, QProcess::ExitStatus /*status*/) {
51+ qDebug() << "manifest command finished with exit code:" << code;
52+ try {
53+ auto data = process.data()->readAllStandardOutput().data();
54+ Manifest manifest = manifest_from_json(data);
55+ qDebug() << "calling back ";
56+ callback(manifest, ManifestError::NoError);
57+ }
58+ catch ( ... ) {
59+ callback(Manifest(), ManifestError::ParseError);
60+ }
61+ } );
62+
63+ QObject::connect(process.data(),
64+ static_cast<QProcessError>(&QProcess::error),
65+ [callback, process](QProcess::ProcessError error) {
66+ qCritical() << "error running command:" << error;
67+ callback(Manifest(), ManifestError::CallError);
68+ } );
69+
70+ std::string command = "click info " + app_id;
71+ qDebug() << "Running command:" << command.c_str();
72+ process->start(command.c_str());
73+}
74+
75 void Interface::get_dotdesktop_filename(const std::string &app_id,
76 std::function<void(std::string, ManifestError)> callback)
77 {
78- get_manifests([app_id, callback] (ManifestList manifests, ManifestError error) {
79+ get_manifest_for_app(app_id, [app_id, callback] (Manifest manifest, ManifestError error) {
80 qDebug() << "in get_dotdesktop_filename callback";
81
82 if (error != ManifestError::NoError){
83 callback(std::string("Internal Error"), error);
84 return;
85 }
86- bool found = false;
87 qDebug() << "in get_dotdesktop_filename callback";
88
89-
90- for (auto manifest : manifests) {
91- if (manifest.name != app_id) continue;
92- found = true;
93+ if (!manifest.name.empty()) {
94 std::string ddstr = manifest.name + "_" + manifest.first_app_name + "_" + manifest.version + ".desktop";
95 callback(ddstr, ManifestError::NoError);
96- break;
97- }
98- if (!found) {
99+ } else {
100 qCritical() << "Warning: no manifest found for " << app_id.c_str();
101 callback(std::string("Not found"), ManifestError::CallError);
102 }
103
104=== modified file 'scope/click/interface.h'
105--- scope/click/interface.h 2014-02-24 14:10:31 +0000
106+++ scope/click/interface.h 2014-02-24 14:10:31 +0000
107@@ -64,6 +64,7 @@
108 typedef std::list<Manifest> ManifestList;
109
110 ManifestList manifest_list_from_json(const std::string& json);
111+Manifest manifest_from_json(const std::string& json);
112
113 class Interface
114 {
115@@ -81,6 +82,7 @@
116 static bool is_icon_identifier(const std::string &icon_id);
117 static std::string add_theme_scheme(const std::string &filename);
118 static void get_manifests(std::function<void(ManifestList, ManifestError)> callback);
119+ static void get_manifest_for_app(const std::string &app_id, std::function<void(Manifest, ManifestError)> callback);
120 static void get_dotdesktop_filename(const std::string &app_id,
121 std::function<void(std::string filename, ManifestError)> callback);
122 private:
123
124=== modified file 'scope/click/scope.cpp'
125--- scope/click/scope.cpp 2014-02-24 14:10:31 +0000
126+++ scope/click/scope.cpp 2014-02-24 14:10:31 +0000
127@@ -191,6 +191,9 @@
128 } else if (action_id == click::Preview::Actions::CONFIRM_UNINSTALL) {
129 activation->setHint(click::Preview::Actions::CONFIRM_UNINSTALL, unity::scopes::Variant(true));
130 activation->setStatus(unity::scopes::ActivationResponse::Status::ShowPreview);
131+ } else if (action_id == click::Preview::Actions::OPEN_ACCOUNTS) {
132+ std::string uri = "settings:///system/online-accounts";
133+ url_dispatch_send(uri.c_str() , NULL, NULL);
134 }
135 return scopes::ActivationBase::UPtr(activation);
136 }

Subscribers

People subscribed via source and target branches