After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 729518 - Add search provider to do computation
Add search provider to do computation
Status: RESOLVED FIXED
Product: gnome-calculator
Classification: Core
Component: general
git master
Other All
: Low enhancement
: ---
Assigned To: Michael Catanzaro
gcalctool maintainers
Depends on:
Blocks:
 
 
Reported: 2014-05-04 16:57 UTC by Bastien Nocera
Modified: 2014-05-28 21:37 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add a search provider (9.26 KB, patch)
2014-05-11 02:53 UTC, Michael Catanzaro
none Details | Review
screenshot (1.16 MB, image/png)
2014-05-11 03:06 UTC, Michael Catanzaro
  Details
Add a search provider (9.24 KB, patch)
2014-05-11 14:04 UTC, Michael Catanzaro
reviewed Details | Review
Add a search provider (9.25 KB, patch)
2014-05-11 21:02 UTC, Michael Catanzaro
committed Details | Review

Description Bastien Nocera 2014-05-04 16:57:16 UTC
Similarly to what Spotlight can do on OSX, it would be nice if typing "1 + 1" in GNOME shell's search entry would show a result of "2" in the calculator's search results. Clicking on it would launch the calculator with the operation loaded in.

See also:
http://lifehacker.com/323584/calculate-with-spotlight
Comment 1 PioneerAxon 2014-05-08 21:16:05 UTC
There are gnome-shell extensions available for this usecase.

What we can have is get the appropriate extension to be included in the default Gnome-shell extensions distribution.

The support for having Calculator launched with given expression has already been added.
Comment 2 Bastien Nocera 2014-05-08 21:46:21 UTC
I was actually thinking of search provider, not a shell extension. I'd like it to be disableable from the Search settings panel, and I'd like it to be enabled by default when the calculator is used.
Comment 3 Michael Catanzaro 2014-05-11 02:53:32 UTC
Created attachment 276310 [details] [review]
Add a search provider

The search provider will display exactly one result if and only if the
search term can be converted to an equation of the form recognized by
GNOME Calculator. If a result is activated, Calculator will be launched
displaying the equation.

To test the patch if installing to /usr/local, run sudo cp /usr/local/share/gnome-shell/search-providers/gnome-calculator-search-provider.ini /usr/share/gnome-shell/search-providers/ after installing.
Comment 4 Michael Catanzaro 2014-05-11 03:06:08 UTC
Created attachment 276311 [details]
screenshot

Sample screenshot, hopefully demonstrates that search provider works better than a shell extension

Bastien, do you want me to associate the Calculator icon with the search result?  This would create a second Calculator icon immediately to the left of the result, so there would be two Calculator icons total (like there is for Web in this screenshot).  This seems a bit silly to me so I did not add it, but I think all other applications do this.
Comment 5 Michael Catanzaro 2014-05-11 14:04:21 UTC
Created attachment 276332 [details] [review]
Add a search provider

The search provider will display exactly one result if and only if the
search term can be converted to an equation of the form recognized by
GNOME Calculator. If a result is activated, Calculator will be launched
displaying the equation.
Comment 6 Bastien Nocera 2014-05-11 16:51:19 UTC
Review of attachment 276332 [details] [review]:

::: search-provider/search-provider.vala
@@ +24,3 @@
+            int exit_status;
+            Process.spawn_command_line_sync (
+                "gnome-calculator --solve '" + terms_to_equation (terms) + "'",

This definitely needs to use g_shell_quote() instead of doing the quoting by hand.
Comment 7 Michael Catanzaro 2014-05-11 21:02:27 UTC
Created attachment 276347 [details] [review]
Add a search provider

Thanks, fixed.
Comment 8 PioneerAxon 2014-05-28 21:36:12 UTC
Review of attachment 276347 [details] [review]:

Committed.

Thank you.. :)
Comment 9 PioneerAxon 2014-05-28 21:37:30 UTC
Bastien Nocera,

Thank you for the feature request.

This feature is implemented, and will be available with next version of Calculator.

Thank you, again.. :)