diff mbox series

[bug#36000,1/4] guix: Add helper for generating desktop entryfiles.

Message ID 20190530071138.31690-1-mail@ambrevar.xyz
State Accepted
Headers show
Series [bug#36000,1/4] guix: Add helper for generating desktop entryfiles. | expand

Checks

Context Check Description
cbaines/applying patch success Successfully applied

Commit Message

Pierre Neidhardt May 30, 2019, 7:11 a.m. UTC
* guix/build/utils.scm (make-desktop-entry-file): New procedure.
---
 guix/build/utils.scm | 99 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 99 insertions(+)

Comments

Pierre Neidhardt Oct. 12, 2019, 8:43 a.m. UTC | #1
Can we merge this in core updates?
Any blocker?

Thanks!
Efraim Flashner Oct. 12, 2019, 6:44 p.m. UTC | #2
On Sat, Oct 12, 2019 at 10:43:56AM +0200, Pierre Neidhardt wrote:
> Can we merge this in core updates?
> Any blocker?
> 

The wrapping is wrong at the very top, it should be under the 'e' in
define. It looks good. I didn't look too much at the logic (my weak
point) but this should be a very welcome addition.

Why core-updates specifically?
Pierre Neidhardt Oct. 12, 2019, 7:05 p.m. UTC | #3
Cc-ing Nicolas since he was part of the discussion:
https://lists.gnu.org/archive/html/guix-devel/2019-05/msg00404.html

Efraim Flashner <efraim@flashner.co.il> writes:

> The wrapping is wrong at the very top, it should be under the 'e' in
> define.

You mean the indentation?  I'm not sure what's wrong, could you write a snippet?

> Why core-updates specifically?

Because this rebuilds the world :(
Efraim Flashner Oct. 12, 2019, 7:12 p.m. UTC | #4
On Sat, Oct 12, 2019 at 09:05:38PM +0200, Pierre Neidhardt wrote:
> Cc-ing Nicolas since he was part of the discussion:
> https://lists.gnu.org/archive/html/guix-devel/2019-05/msg00404.html
> 
> Efraim Flashner <efraim@flashner.co.il> writes:
> 
> > The wrapping is wrong at the very top, it should be under the 'e' in
> > define.
> 
> You mean the indentation?  I'm not sure what's wrong, could you write a snippet?
> 

Yeah, I did mean indentation. I meant that it should be

(define* (...
  next-line-here

but then I checked guix/build/utils and saw that all the other ones are
indented the way you have it so keep it :).

> > Why core-updates specifically?
> 
> Because this rebuilds the world :(
> 

Ah, that's unfortunate
Pierre Neidhardt Oct. 18, 2019, 8:43 a.m. UTC | #5
So shall I merge it on staging then?
Ludovic Courtès Oct. 18, 2019, 2:40 p.m. UTC | #6
Hi,

Pierre Neidhardt <mail@ambrevar.xyz> skribis:

> So shall I merge it on staging then?

I think ‘staging’ is in fact pretty much ready, no?  Marius?

  https://ci.guix.gnu.org/jobset/staging-staging

Ludo’.
Marius Bakke Oct. 18, 2019, 3:10 p.m. UTC | #7
Ludovic Courtès <ludo@gnu.org> writes:

> Hi,
>
> Pierre Neidhardt <mail@ambrevar.xyz> skribis:
>
>> So shall I merge it on staging then?
>
> I think ‘staging’ is in fact pretty much ready, no?  Marius?
>
>   https://ci.guix.gnu.org/jobset/staging-staging

Indeed, it will be merged within a day or two and is currently only
taking bugfixes.
Marius Bakke Oct. 18, 2019, 3:13 p.m. UTC | #8
Pierre Neidhardt <mail@ambrevar.xyz> writes:

> So shall I merge it on staging then?

This is world-rebuilding change, no?  In that case it has to go through
'core-updates' as per the branch rebuild policy:

https://guix.gnu.org/manual/en/guix.html#Submitting-Patches

(it would be good to shorten that section a bit...)
Pierre Neidhardt Oct. 18, 2019, 3:22 p.m. UTC | #9
Sorry, my email this morning meant "core-updates", as per the other
comments in this thread!

So should I merge on core-updates then?
Marius Bakke Oct. 18, 2019, 3:24 p.m. UTC | #10
Pierre Neidhardt <mail@ambrevar.xyz> writes:

> Sorry, my email this morning meant "core-updates", as per the other
> comments in this thread!
>
> So should I merge on core-updates then?

If you think it is ready, go for it!  :-)
Pierre Neidhardt Oct. 19, 2019, 10:46 a.m. UTC | #11
Done, thanks!
diff mbox series

Patch

diff --git a/guix/build/utils.scm b/guix/build/utils.scm
index 5fe3286843..21bdc42719 100644
--- a/guix/build/utils.scm
+++ b/guix/build/utils.scm
@@ -1100,6 +1100,105 @@  with definitions for VARS."
         (chmod prog-tmp #o755)
         (rename-file prog-tmp prog))))
 
+(define* (make-desktop-entry-file destination #:key
+                                  (type "Application") ; One of "Application", "Link" or "Directory".
+                                  (version "1.1")
+                                  name
+                                  (generic-name name)
+                                  (no-display #f)
+                                  comment
+                                  icon
+                                  (hidden #f)
+                                  only-show-in
+                                  not-show-in
+                                  (d-bus-activatable #f)
+                                  try-exec
+                                  exec
+                                  path
+                                  (terminal #f)
+                                  actions
+                                  mime-type
+                                  (categories "Application")
+                                  implements
+                                  keywords
+                                  (startup-notify #t)
+                                  startup-w-m-class
+                                  #:rest all-args)
+  "Create a desktop entry file at DESTINATION.
+You must specify NAME.
+
+Values can be booleans, numbers, strings or list of strings.
+
+Additionally, locales can be specified with an alist where the key is the
+locale.  The #f key specifies the default.  Example:
+
+  #:name '((#f \"I love Guix\") (\"fr\" \"J'aime Guix\"))
+
+produces
+
+  Name=I love Guix
+  Name[fr]=J'aime Guix
+
+For a complete description of the format, see the specifications at
+https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html."
+  (define (escape-semicolon s)
+    (string-join (string-split s #\;) "\\;"))
+  (define* (parse key value #:optional locale)
+    (set! value (match value
+                  (#t "true")
+                  (#f "false")
+                  ((?  number? n) n)
+                  ((?  string? s) (escape-semicolon s))
+                  ((?  list? value)
+                   (catch 'wrong-type-arg
+                     (lambda () (string-join (map escape-semicolon value) ";"))
+                     (lambda args (error "List arguments can only contain strings: ~a" args))))
+                  (_ (error "Value must be a boolean, number, string or list of strings"))))
+    (format #t "~a=~a~%"
+            (if locale
+                (format #f "~a[~a]" key locale)
+                key)
+            value))
+
+  (define key-error-message "This procedure only takes key arguments beside DESTINATION")
+
+  (unless name
+    (error "Missing NAME key argument"))
+  (unless (member #:type all-args)
+    (set! all-args (append (list #:type type) all-args)))
+  (mkdir-p (dirname destination))
+
+  (with-output-to-file destination
+    (lambda ()
+      (format #t "[Desktop Entry]~%")
+      (let loop ((args all-args))
+        (match args
+          (() #t)
+          ((_) (error key-error-message))
+          ((key value . ...)
+           (unless (keyword? key)
+             (error key-error-message))
+           (set! key
+                 (string-join (map string-titlecase
+                                   (string-split (symbol->string
+                                                  (keyword->symbol key))
+                                                 #\-))
+                              ""))
+           (match value
+             (((_ . _) . _)
+              (for-each (lambda (locale-subvalue)
+                          (parse key
+                                 (if (and (list? (cdr locale-subvalue))
+                                          (= 1 (length (cdr locale-subvalue))))
+                                     ;; Support both proper and improper lists for convenience.
+                                     (cadr locale-subvalue)
+                                     (cdr locale-subvalue))
+                                 (car locale-subvalue)))
+                        value))
+             (_
+              (parse key value)))
+           (loop (cddr args))))))))
+
 
 ;;;
 ;;; Locales.