[pan: 6/15] Clean up the mail sender code
- From: Dominique Dumont <ddumont src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pan: 6/15] Clean up the mail sender code
- Date: Sun, 12 Jun 2022 09:12:11 +0000 (UTC)
commit 9c368330ef51770d07c4071b6dfb5b8d41c38ec5
Author: Thomas Tanner <thosrtanner googlemail com>
Date: Tue May 31 22:20:40 2022 +0100
Clean up the mail sender code
Make it handle errors better
pan/gui/post-ui.cc | 40 +++++++++++++++++++++++++++-------------
pan/gui/post-ui.h | 9 ++++++---
2 files changed, 33 insertions(+), 16 deletions(-)
---
diff --git a/pan/gui/post-ui.cc b/pan/gui/post-ui.cc
index 97d8674..6e9eb5a 100644
--- a/pan/gui/post-ui.cc
+++ b/pan/gui/post-ui.cc
@@ -661,6 +661,10 @@ PostUI :: add_actions (GtkWidget * box)
gtk_action_group_set_sensitive(_agroup, true);
+ //Remember the spawn button
+ _spawner_action = gtk_action_group_get_action(_agroup, "run-editor");
+
+
}
void
@@ -1306,7 +1310,6 @@ PostUI :: maybe_post_message (GMimeMessage * message)
/***
****
***/
-EditorSpawner *spawner;
class Destroyer {
public:
@@ -1333,7 +1336,11 @@ void
PostUI :: spawn_editor ()
{
- // log error if this is already running or disable the button
+ //Protect against bouncy keypresses
+ if (not gtk_action_get_sensitive(_spawner_action)) {
+ return;
+ }
+
// open a new tmp file
char * fname (0);
@@ -1364,11 +1371,20 @@ PostUI :: spawn_editor ()
fclose(fp);
- using namespace std::placeholders;
- spawner = new EditorSpawner(fname,
- std::bind(&spawn_editor_dead, this, _1, _2),
- _prefs);
- d.retain();
+ try
+ {
+ using namespace std::placeholders;
+ _spawner.reset(
+ new EditorSpawner(fname,
+ std::bind(&spawn_editor_dead, this, _1, _2),
+ _prefs));
+ d.retain();
+ gtk_action_set_sensitive(_spawner_action, false);
+ }
+ catch (EditorSpawnerError const &)
+ {
+ //Do nothing. There should be a big red exclamation on the status line
+ }
}
void
@@ -1395,8 +1411,9 @@ PostUI::spawn_editor_dead(int status, char *fname)
::remove(fname);
g_free(fname);
+ gtk_action_set_sensitive(_spawner_action, true);
+ _spawner.reset();
gtk_window_present(GTK_WINDOW(root()));
-
}
namespace
@@ -2333,8 +2350,9 @@ PostUI :: body_view_realized_cb (GtkWidget*, gpointer self_gpointer)
self->set_message (self->_message);
self->_unchanged_body = self->get_body ();
- if (self->_prefs.get_flag ("always-run-editor", false))
+ if (self->_prefs.get_flag ("always-run-editor", false)) {
self->spawn_editor ();
+ }
g_signal_handler_disconnect (self->_body_view, self->body_view_realized_handler);
@@ -2956,9 +2974,6 @@ PostUI :: ~PostUI ()
if (_draft_autosave_idle_tag)
g_source_remove (_draft_autosave_idle_tag);
- if (_child_id != 0)
- g_source_remove(_child_id);
-
g_object_unref (G_OBJECT(_message));
_upload_queue.remove_listener (this);
@@ -3105,7 +3120,6 @@ PostUI :: PostUI (GtkWindow * parent,
_draft_autosave_idle_tag(0),
_body_changed_id(0),
_body_changed_idle_tag(0),
- _child_id(0),
_filequeue_eventbox (0),
_filequeue_label (0),
_realized(false),
diff --git a/pan/gui/post-ui.h b/pan/gui/post-ui.h
index 870baae..c415f9c 100644
--- a/pan/gui/post-ui.h
+++ b/pan/gui/post-ui.h
@@ -29,8 +29,11 @@
#include <pan/data/encode-cache.h>
#include "group-prefs.h"
+#include <memory>
+
namespace pan
{
+ class EditorSpawner;
class Profiles;
class TaskPost;
class UploadQueue;
@@ -158,8 +161,6 @@ namespace pan
GMimeContentEncoding _enc;
- guint _child_id;
-
/* binpost */
bool _file_queue_empty;
TaskUpload* _upload_ptr;
@@ -229,7 +230,6 @@ namespace pan
public:
void set_spellcheck_enabled (bool);
- void spawn_editor_dead(int, char *);
public:
tasks_t get_selected_files () const;
@@ -246,6 +246,9 @@ namespace pan
static void on_parts_box_clicked_cb (GtkCellRendererToggle *cell, gchar *path_str, gpointer user_data);
private:
+ GtkAction * _spawner_action;
+ std::unique_ptr<EditorSpawner> _spawner;
+ void spawn_editor_dead(int, char *);
TaskUpload* upload_ptr() { return _upload_ptr; }
UploadQueue _upload_queue;
Mutex mut;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]