[pan: 4/15] Preliminary work for editing score file




commit 816d014988e4025ef2a8996ce5ceb87a31e744d0
Author: Thomas Tanner <thosrtanner googlemail com>
Date:   Tue May 31 17:58:34 2022 +0100

    Preliminary work for editing score file

 pan/gui/actions.cc |  8 ++++++++
 pan/gui/gui.cc     | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 pan/gui/gui.h      |  3 +++
 pan/gui/pan-ui.h   |  2 ++
 pan/gui/pan.ui.h   |  1 +
 5 files changed, 66 insertions(+), 1 deletion(-)
---
diff --git a/pan/gui/actions.cc b/pan/gui/actions.cc
index 15c91ce..5905198 100644
--- a/pan/gui/actions.cc
+++ b/pan/gui/actions.cc
@@ -26,6 +26,7 @@
 #include <pan/data-impl/data-impl.h>
 #include <pan/tasks/task-xover.h>
 #include <pan/icons/pan-pixbufs.h>
+
 #include "actions.h"
 #include "pad.h"
 #include "gui.h"
@@ -187,6 +188,8 @@ namespace pan
   void do_tip_jar                      (GtkAction*) { pan_ui->do_tip_jar(); }
   void do_about_pan                    (GtkAction*) { pan_ui->do_about_pan(); }
 
+  void do_edit_scores(GtkAction * a) { pan_ui->do_edit_scores(a); }
+
   void do_work_online         (GtkToggleAction * a) { pan_ui->do_work_online         
(gtk_toggle_action_get_active(a)); }
   void do_layout              (GtkToggleAction * a) { pan_ui->do_layout              
(gtk_toggle_action_get_active(a)); }
   void do_show_group_pane     (GtkToggleAction * a) { pan_ui->do_show_group_pane     
(gtk_toggle_action_get_active(a)); }
@@ -452,6 +455,11 @@ namespace pan
         NULL,
         G_CALLBACK(do_show_group_preferences_dialog) },
 
+      { "launch-scores-editor", GTK_STOCK_PREFERENCES,
+        N_("Edit S_core File"), NULL,
+        NULL,
+        G_CALLBACK(do_edit_scores) },
+
       { "show-profiles-dialog", GTK_STOCK_EDIT,
         N_("Edit P_osting Profiles"), NULL,
         NULL,
diff --git a/pan/gui/gui.cc b/pan/gui/gui.cc
index 23629a9..0d58975 100644
--- a/pan/gui/gui.cc
+++ b/pan/gui/gui.cc
@@ -30,6 +30,11 @@ extern "C" {
 #include <glib/gi18n.h>
 #include <pan/general/debug.h>
 #include <pan/general/e-util.h>
+/**/
+#include <memory>
+#include <pan/general/editor-spawner.h>
+#include <pan/general/file-util.h>
+/**/
 #include <pan/general/file-util.h>
 #include <pan/general/macros.h>
 #include <pan/usenet-utils/scorefile.h>
@@ -73,6 +78,7 @@ extern "C" {
 
 #include <pan/usenet-utils/gpg.h>
 
+
 namespace
 {
   std::string get_accel_filename () {
@@ -2371,6 +2377,52 @@ GUI :: on_prefs_string_changed (const StringView& key, const StringView& value)
   }
 }
 
+namespace {
+
+EditorSpawner *spawner;
+GtkAction *spawner_action;
+
+}
+
+void
+GUI :: do_edit_scores (GtkAction *a)
+{
+  //Protect against bouncy keypresses
+  if (not gtk_action_get_sensitive(a)) {
+    return;
+  }
+
+  gtk_action_set_sensitive(a, false);
+  spawner_action = a;
+
+  //This is wrong because this might not be the filename
+  char *filename = g_build_filename(file::get_pan_home().c_str(), "Score", NULL);
+  if (not file::file_exists(filename)) {
+    GError *err{nullptr};
+    g_close(g_creat(filename, 0700), &err);
+    if (err != nullptr) {
+      //log error
+      return;
+    }
+  }
+
+  using namespace std::placeholders;
+  spawner = new EditorSpawner(filename,
+                              std::bind(edit_scores_cleanup, this, _1, _2),
+                              _prefs);
+}
+
+void
+GUI :: edit_scores_cleanup(int status, char *filename)
+{
+  //rescore articles
+  g_free(filename);
+  gtk_action_set_sensitive(spawner_action, true);
+  delete spawner;
+  gtk_window_present(get_window(_root));
+}
+
+
 #ifdef HAVE_GNUTLS
 
 void
@@ -2423,5 +2475,4 @@ GUI :: on_valid_cert_added (gnutls_x509_crt_t cert, std::string server)
   debug_SSL("whitelist ("<<server<<") ("<<cert<<")");
 }
 
-
 #endif
diff --git a/pan/gui/gui.h b/pan/gui/gui.h
index b8269ef..b2815cb 100644
--- a/pan/gui/gui.h
+++ b/pan/gui/gui.h
@@ -198,6 +198,8 @@ namespace pan
       virtual void do_refresh_groups ();
       virtual void do_subscribe_selected_groups ();
       virtual void do_unsubscribe_selected_groups ();
+      virtual void do_edit_scores(GtkAction *);
+
 #ifdef HAVE_GNUTLS
       void do_show_cert_failed_dialog(VerifyData* data);
       bool confirm_accept_new_cert_dialog(GtkWindow*, gnutls_x509_crt_t, const Quark&);
@@ -305,6 +307,7 @@ namespace pan
       static void prefs_dialog_destroyed_cb (GtkWidget * w, gpointer self);
       void prefs_dialog_destroyed (GtkWidget* w);
       int score_int_from_string(std::string val, const char* rules[]);
+      void edit_scores_cleanup(int, char *);
 #ifdef HAVE_GNUTLS
       static gboolean show_cert_failed_cb(gpointer gp);
 #endif
diff --git a/pan/gui/pan-ui.h b/pan/gui/pan-ui.h
index 151475a..c32851f 100644
--- a/pan/gui/pan-ui.h
+++ b/pan/gui/pan-ui.h
@@ -142,6 +142,8 @@ namespace pan
 #define MATCH_HIGH_SCORING    (1<<4)
 #define MATCH_WATCHED         (1<<5)
     virtual void do_match_on_score_state (int) = 0;
+
+    virtual void do_edit_scores(GtkAction *) = 0;
   };
 }
 
diff --git a/pan/gui/pan.ui.h b/pan/gui/pan.ui.h
index 438abdc..ef89ebd 100644
--- a/pan/gui/pan.ui.h
+++ b/pan/gui/pan.ui.h
@@ -26,6 +26,7 @@ const char * fallback_ui_file =
 "      <menuitem action='show-profiles-dialog' />\n"
 "      <menuitem action='show-preferences-dialog' />\n"
 "      <menuitem action='show-group-preferences-dialog' />\n"
+"      <menuitem action='launch-scores-editor' />\n"
 "    </menu>\n"
 "    <menu action='view-menu'>\n"
 "      <menuitem action='show-toolbar' />\n"


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]