From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([209.51.188.92]:54479) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWFlE-0000fX-Fg for guix-patches@gnu.org; Thu, 30 May 2019 03:46:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWFlC-00023q-K7 for guix-patches@gnu.org; Thu, 30 May 2019 03:46:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:47141) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hWFlC-00023k-Gz for guix-patches@gnu.org; Thu, 30 May 2019 03:46:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hWFlC-0005sS-CY for guix-patches@gnu.org; Thu, 30 May 2019 03:46:02 -0400 Subject: [bug#36000] [PATCH 1/4] guix: Add helper for generating desktop entry files. Resent-Message-ID: Received: from eggs.gnu.org ([209.51.188.92]:54400) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWFkL-0000Xq-9U for guix-patches@gnu.org; Thu, 30 May 2019 03:45:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWFkJ-0001gL-Sp for guix-patches@gnu.org; Thu, 30 May 2019 03:45:09 -0400 Received: from mslow2.mail.gandi.net ([217.70.178.242]:58044) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWFkJ-0001fC-I1 for guix-patches@gnu.org; Thu, 30 May 2019 03:45:07 -0400 Received: from relay8-d.mail.gandi.net (unknown [217.70.183.201]) by mslow2.mail.gandi.net (Postfix) with ESMTP id 60AC03AACCB for ; Thu, 30 May 2019 07:12:06 +0000 (UTC) Received: from localhost.localdomain (lfbn-1-4117-19.w92-169.abo.wanadoo.fr [92.169.116.19]) (Authenticated sender: mail@ambrevar.xyz) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 202941BF205 for ; Thu, 30 May 2019 07:11:39 +0000 (UTC) From: Pierre Neidhardt Date: Thu, 30 May 2019 09:11:38 +0200 Message-Id: <20190530071138.31690-1-mail@ambrevar.xyz> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 36000@debbugs.gnu.org * guix/build/utils.scm (make-desktop-entry-file): New procedure. --- guix/build/utils.scm | 99 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) 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)))) =20 +(define* (make-desktop-entry-file destination #:key + (type "Application") ; One of "Applica= tion", "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 th= e +locale. The #f key specifies the default. Example: + + #:name '((#f \"I love Guix\") (\"fr\" \"J'aime Guix\")) + +produces + + Name=3DI love Guix + Name[fr]=3DJ'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 contai= n strings: ~a" args)))) + (_ (error "Value must be a boolean, number, string or = list of strings")))) + (format #t "~a=3D~a~%" + (if locale + (format #f "~a[~a]" key locale) + key) + value)) + + (define key-error-message "This procedure only takes key arguments bes= ide 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)) + (=3D 1 (length (cdr locale-sub= value)))) + ;; Support both proper and improper= lists for convenience. + (cadr locale-subvalue) + (cdr locale-subvalue)) + (car locale-subvalue))) + value)) + (_ + (parse key value))) + (loop (cddr args)))))))) + =0C ;;; ;;; Locales. --=20 2.21.0