unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: 42977@debbugs.gnu.org
Subject: bug#42977: 28.0.50; New gnus-dbus library providing (optional) D-Bus->Gnus integration
Date: Fri, 21 Aug 2020 13:43:07 -0700	[thread overview]
Message-ID: <87imdb6884.fsf@ericabrahamsen.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 670 bytes --]


The attached patch provides a new gnus-dbus.el library, allowing systems
with dbus support to register a signal that closes all Gnus servers when
the system is going down for sleep. This is kind of a stop-gap solution
for the larger problems discussed in #40748.

It only does anything if Emacs has been compiled with dbus support, and
if the user sets the `gnus-dbus-close-on-sleep' to non-nil (it defaults
to nil).

Right now I've done this by checking the value of that option in
`gnus-1', but I could just as easily have the library add a startup
hook.

I assume this would require a mention in the manual. Is it something
we'd add to NEWS, as well?

Thanks,
Eric


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-basic-D-Bus-integration-to-Gnus.patch --]
[-- Type: text/x-patch, Size: 4296 bytes --]

From 414051f4fb7d60a6674b7267dc7f73025ddb1a3b Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
Date: Fri, 21 Aug 2020 13:36:58 -0700
Subject: [PATCH] Add basic D-Bus integration to Gnus

* lisp/gnus/gnus-dbus.el: New library, registering a signal that
closes all Gnus servers when the system is going to sleep.
* lisp/gnus/gnus-start.el: Check new option
`gnus-dbus-close-on-sleep', and register the appropriate D-Bus signal
if it is non-nil.
* lisp/gnus/gnus.el: New gnus-dbus customization group.
---
 lisp/gnus/gnus-dbus.el  | 66 +++++++++++++++++++++++++++++++++++++++++
 lisp/gnus/gnus-start.el |  3 ++
 lisp/gnus/gnus.el       |  4 +++
 3 files changed, 73 insertions(+)
 create mode 100644 lisp/gnus/gnus-dbus.el

diff --git a/lisp/gnus/gnus-dbus.el b/lisp/gnus/gnus-dbus.el
new file mode 100644
index 0000000000..14f0abb6be
--- /dev/null
+++ b/lisp/gnus/gnus-dbus.el
@@ -0,0 +1,66 @@
+;;; gnus-dbus.el --- DBUS integration for Gnus       -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2020  Free Software Foundation, Inc.
+
+;; Author: Eric Abrahamsen <eric@ericabrahamsen.net>
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This library contains some Gnus integration for systems using DBUS.
+;; At present it registers a signal to close all Gnus servers before
+;; system sleep or hibernation.
+
+;;; Code:
+
+(require 'dbus)
+
+(defcustom gnus-dbus-close-on-sleep nil
+  "When non-nil, close Gnus servers on system sleep."
+  :group 'gnus-dbus
+  :type 'boolean)
+
+(defvar gnus-dbus-sleep-registration-object nil
+  "Object returned from `dbus-register-signal'.
+Used to unregistering the signal.")
+
+(defun gnus-dbus-register-sleep-signal ()
+  "Use `dbus-register-signal' to close servers on sleep."
+  (when (featurep 'dbusbind)
+    (setq gnus-dbus-sleep-registration-object
+	  (dbus-register-signal :system
+				"org.freedesktop.login1"
+				"/org/freedesktop/login1"
+				"org.freedesktop.login1.Manager"
+				"PrepareForSleep"
+				#'gnus-dbus-sleep-handler))
+    (gnus-add-shutdown #'gnus-dbus-unregister-sleep-signal 'gnus)))
+
+(defun gnus-dbus-sleep-handler (sleep-start)
+  ;; Sleep-start is t before sleeping.
+  (when (and sleep-start
+	     (gnus-alive-p))
+    (condition-case nil
+	(gnus-close-all-servers)
+      (error nil))))
+
+(defun gnus-dbus-unregister-sleep-signal ()
+  (condition-case nil
+      (dbus-unregister-object
+       gnus-dbus-sleep-registration-object)
+    (wrong-type-argument nil)))
+
+(provide 'gnus-dbus)
+;;; gnus-dbus.el ends here
diff --git a/lisp/gnus/gnus-start.el b/lisp/gnus/gnus-start.el
index ba8b91be5c..fe600f107c 100644
--- a/lisp/gnus/gnus-start.el
+++ b/lisp/gnus/gnus-start.el
@@ -31,6 +31,7 @@
 (require 'gnus-range)
 (require 'gnus-util)
 (require 'gnus-cloud)
+(require 'gnus-dbus)
 (autoload 'message-make-date "message")
 (autoload 'gnus-agent-read-servers-validate "gnus-agent")
 (autoload 'gnus-agent-save-local "gnus-agent")
@@ -798,6 +799,8 @@ gnus-1
 	  (gnus-run-hooks 'gnus-setup-news-hook)
 	  (when gnus-agent
 	    (gnus-request-create-group "queue" '(nndraft "")))
+	  (when gnus-dbus-close-on-sleep
+	    (gnus-dbus-register-sleep-signal))
 	  (gnus-start-draft-setup)
 	  ;; Generate the group buffer.
 	  (gnus-group-list-groups level)
diff --git a/lisp/gnus/gnus.el b/lisp/gnus/gnus.el
index cecf4d4fb4..f615d49d27 100644
--- a/lisp/gnus/gnus.el
+++ b/lisp/gnus/gnus.el
@@ -292,6 +292,10 @@ gnus-fun
   :link '(custom-manual "(gnus)Exiting Gnus")
   :group 'gnus)
 
+(defgroup gnus-dbus nil
+  "D-Bus integration for Gnus."
+  :group 'gnus)
+
 (defconst gnus-version-number "5.13"
   "Version number for this version of Gnus.")
 
-- 
2.28.0


             reply	other threads:[~2020-08-21 20:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-21 20:43 Eric Abrahamsen [this message]
2020-08-22  6:33 ` bug#42977: 28.0.50; New gnus-dbus library providing (optional) D-Bus->Gnus integration Eli Zaretskii
2020-08-22 13:53 ` Lars Ingebrigtsen
2020-08-22 18:00   ` Eric Abrahamsen
2020-08-23 12:27     ` Lars Ingebrigtsen
2020-08-25 17:43       ` Eric Abrahamsen
2020-08-25 19:21         ` Lars Ingebrigtsen
2020-08-25 19:33           ` Eric Abrahamsen
2020-08-25 19:37             ` Lars Ingebrigtsen
2020-08-27  1:19               ` Eric Abrahamsen
2020-08-27 13:37                 ` Lars Ingebrigtsen
2020-08-27 21:20                   ` Eric Abrahamsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87imdb6884.fsf@ericabrahamsen.net \
    --to=eric@ericabrahamsen.net \
    --cc=42977@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).