[pan2: 154/268] added deletion confirmation dialog (deactivatable via prefs) for articles (hit delete to erase them,



commit b697b0b7513f779241650b56c09598e122385374
Author: Heinrich MÃller <sphemuel stud informatik uni-erlangen de>
Date:   Sat Sep 3 07:12:14 2011 +0200

    added deletion confirmation dialog (deactivatable via prefs)
    for articles (hit delete to erase them, then a popup will appear).

 pan/data/encode-cache.cc |    3 +-
 pan/gui/gui.cc           |   66 +++++++++++++++++++++++++++++++++++++++------
 pan/gui/gui.h            |    1 +
 pan/gui/prefs-ui.cc      |    2 +
 pan/tasks/encoder.cc     |    3 ++
 pan/tasks/task-upload.cc |   24 ++++++++++------
 uulib/uuencode.c         |   57 +++++++++------------------------------
 7 files changed, 93 insertions(+), 63 deletions(-)
---
diff --git a/pan/data/encode-cache.cc b/pan/data/encode-cache.cc
index e334ea7..dc401a4 100644
--- a/pan/data/encode-cache.cc
+++ b/pan/data/encode-cache.cc
@@ -202,7 +202,8 @@ EncodeCache :: update_file (std::string& data, const Quark& where)
 {
   FILE * fp = get_fp_from_mid(where);
   if (!fp) return false;
-  fwrite(data.c_str(), strlen(data.c_str()), sizeof(char), fp);
+  const char * out (data.c_str());
+  fwrite(out, strlen(out), sizeof(char), fp);
   fclose(fp);
   return true;
 }
diff --git a/pan/gui/gui.cc b/pan/gui/gui.cc
index 164ac69..b8486e5 100644
--- a/pan/gui/gui.cc
+++ b/pan/gui/gui.cc
@@ -1301,15 +1301,48 @@ void GUI :: do_cancel_article ()
   g_object_unref (message);
 }
 
+bool GUI::deletion_confirmation_dialog()
+  {
+    bool ret(false);
+    GtkWidget * d = gtk_message_dialog_new (
+      get_window(_root),
+      GtkDialogFlags(GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT),
+      GTK_MESSAGE_WARNING,
+      GTK_BUTTONS_NONE, NULL);
+    HIG :: message_dialog_set_text (GTK_MESSAGE_DIALOG(d),
+      _("You marked some articles for deletion"),
+      _("Are you sure you want to delete them?"));
+    gtk_dialog_add_buttons (GTK_DIALOG(d),
+                            GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
+                            GTK_STOCK_APPLY, GTK_RESPONSE_YES,
+                            NULL);
+    gtk_dialog_set_default_response (GTK_DIALOG(d), GTK_RESPONSE_NO);
+    ret = gtk_dialog_run (GTK_DIALOG(d)) == GTK_RESPONSE_YES;
+    gtk_widget_destroy(d);
+    return ret;
+  }
+
 void GUI :: do_delete_article ()
 {
-  const std::set<const Article*> articles (_header_pane->get_nested_selection());
-  _data.delete_articles (articles);
+  bool confirm (_prefs.get_flag("show-deletion-confirm-dialog", true));
+  bool do_delete(false);
+  if (confirm)
+  {
+    if (deletion_confirmation_dialog())
+      do_delete = true;
+  } else
+    do_delete = true;
 
-  const Quark mid (_body_pane->get_message_id());
-  foreach_const (std::set<const Article*>, articles, it)
-    if ((*it)->message_id == mid)
-      _body_pane->clear ();
+  if (do_delete)
+  {
+    const std::set<const Article*> articles (_header_pane->get_nested_selection());
+    _data.delete_articles (articles);
+
+    const Quark mid (_body_pane->get_message_id());
+    foreach_const (std::set<const Article*>, articles, it)
+      if ((*it)->message_id == mid)
+        _body_pane->clear ();
+  }
 }
 
 void GUI :: do_clear_article_cache ()
@@ -1666,6 +1699,7 @@ void GUI :: do_quit ()
 {
   gtk_main_quit ();
 }
+
 void GUI :: do_read_selected_group ()
 {
   const Quark group (_group_pane->get_first_selection ());
@@ -1714,17 +1748,31 @@ void GUI :: do_read_selected_group ()
     }
   }
 }
+
 void GUI :: do_mark_selected_groups_read ()
 {
   const quarks_v group_names (_group_pane->get_full_selection ());
   foreach_const (quarks_v, group_names, it)
     _data.mark_group_read (*it);
 }
+
 void GUI :: do_clear_selected_groups ()
 {
-  const quarks_v groups (_group_pane->get_full_selection ());
-  foreach_const (quarks_v, groups, it)
-    _data.group_clear_articles (*it);
+  bool confirm (_prefs.get_flag("show-deletion-confirm-dialog", true));
+  bool do_delete(false);
+  if (confirm)
+  {
+    if (deletion_confirmation_dialog())
+      do_delete = true;
+  } else
+    do_delete = true;
+
+  if (do_delete)
+  {
+      const quarks_v groups (_group_pane->get_full_selection ());
+      foreach_const (quarks_v, groups, it)
+      _data.group_clear_articles (*it);
+  }
 }
 
 void GUI :: do_xover_selected_groups ()
diff --git a/pan/gui/gui.h b/pan/gui/gui.h
index 7cdfe80..5c74462 100644
--- a/pan/gui/gui.h
+++ b/pan/gui/gui.h
@@ -123,6 +123,7 @@ namespace pan
       virtual void do_cancel_article ();
       virtual void do_supersede_article ();
       virtual void do_delete_article ();
+      virtual bool deletion_confirmation_dialog();
       virtual void do_clear_article_cache ();
       virtual void do_mark_article_read ();
       virtual void do_mark_article_unread ();
diff --git a/pan/gui/prefs-ui.cc b/pan/gui/prefs-ui.cc
index 0eb21a5..c7fe83f 100644
--- a/pan/gui/prefs-ui.cc
+++ b/pan/gui/prefs-ui.cc
@@ -516,6 +516,8 @@ PrefsDialog :: PrefsDialog (Prefs& prefs, GtkWindow* parent):
     HIG :: workarea_add_section_spacer (t, row, 4);
     w = new_check_button (_("Space selects next article rather than next unread"), "space-selects-next-article", true, prefs);
     HIG :: workarea_add_wide_control (t, &row, w);
+    w = new_check_button (_("Always show article deletion confirmation dialog"), "show-deletion-confirm-dialog", true, prefs);
+    HIG :: workarea_add_wide_control (t, &row, w);
     w = new_check_button (_("Smooth scrolling"), "smooth-scrolling", true, prefs);
     HIG :: workarea_add_wide_control (t, &row, w);
     w = new_check_button (_("Clear article cache on shutdown"), "clear-article-cache-on-shutdown", false, prefs);
diff --git a/pan/tasks/encoder.cc b/pan/tasks/encoder.cc
index a186ee8..1a10dbd 100644
--- a/pan/tasks/encoder.cc
+++ b/pan/tasks/encoder.cc
@@ -142,6 +142,9 @@ Encoder :: do_work()
     /* build real subject line for article*/
     tmp->subject = subject;
 
+    // DBG
+    // fp = fopen("/home/imhotep/test.pdf", "wb+");
+
     for (TaskUpload::needed_t::iterator it = needed->begin(); it != needed->end(); ++it, ++cnt)
     {
       g_snprintf(buf,sizeof(buf),"%s.%d",basename.c_str(), cnt);
diff --git a/pan/tasks/task-upload.cc b/pan/tasks/task-upload.cc
index 168324c..032e035 100644
--- a/pan/tasks/task-upload.cc
+++ b/pan/tasks/task-upload.cc
@@ -178,8 +178,9 @@ TaskUpload :: update_work (NNTP* checkin_pending)
   }
   else if (_encoder_has_run && !_needed.empty())
   {
-//    _state.set_completed();
-//    set_finished(_queue_pos);
+    // DBG
+//     _state.set_completed();
+//     set_finished(_queue_pos);
     _state.set_need_nntp(_server);
   }
   else if (_needed.empty())
@@ -204,24 +205,29 @@ TaskUpload :: prepend_headers(GMimeMessage* msg, TaskUpload::Needed * n, std::st
 
     //modify references header
     std::string mids(_references);
-    if (!_first_mid.empty()) mids += " <" + _first_mid + "> ";
-    if (_first_mid != n->last_mid && !_first && !n->last_mid.empty())  mids += "<" + n->last_mid + ">";
+    if (!_first_mid.empty()) mids += " <" + _first_mid + ">";
+    if (_first_mid != n->last_mid && !_first && !n->last_mid.empty())  mids += " <" + n->last_mid + ">";
     if (!mids.empty()) g_mime_object_set_header ((GMimeObject *) msg, "References", mids.c_str());
 
-    char * all;
+    // modify content type
+    g_snprintf(buf,sizeof(buf), "Message/Partial; number=%d; total=%d", n->partno, _total_parts);
+//    GMimeContentType * new_type = g_mime_content_type_new_from_string (buf);
+//    g_mime_object_set_content_type ((GMimeObject *) msg, new_type);
+//    g_object_unref (new_type);
+    g_mime_object_set_header ((GMimeObject *) msg, "Content-Type",buf);
+
+    char * all(g_mime_object_get_headers ((GMimeObject *) msg));
     if (_first && _queue_pos==-1)
       all = g_mime_object_to_string ((GMimeObject *) msg);
     else  if (_first && _queue_pos==0)
       all = g_mime_object_to_string ((GMimeObject *) msg);
-    else
-      all = g_mime_object_get_headers ((GMimeObject *) msg);
 
     out << all << "\n";
     if (_first && _queue_pos == -1) g_free(all);
     out << d;
     d = out.str();
 
-//    std::cerr<<d<<std::endl<<std::endl;
+    std::cerr<<d<<std::endl;
 
     if (_first) _first = !_first;
 }
@@ -298,7 +304,7 @@ TaskUpload :: on_nntp_done (NNTP * nntp,
   switch (health)
   {
     case OK:
-      increment_step(it->second.bytes); /// DBG
+      increment_step(it->second.bytes);
       _needed.erase (it);
       post_ok = true;
       break;
diff --git a/uulib/uuencode.c b/uulib/uuencode.c
index d173002..b74bb9e 100644
--- a/uulib/uuencode.c
+++ b/uulib/uuencode.c
@@ -716,50 +716,24 @@ UUEncodeStream_byFSize (FILE *outfile, FILE *infile, int encoding, long bpf, crc
       }
 
       rest -= count;
+      itemp[count] = '\0';
 
-
-        itemp[count] = '\0';
-//        count = strlen (itemp);
-
-        llen = 0;
-        optr = otemp;
+      llen = 0;
+      optr = otemp;
 
         /*
          * Busy Callback
          */
 
-        if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize))
-          {
-//            UUMessage (uuencode_id, __LINE__, UUMSG_NOTE,
-//                       uustring (S_ENCODE_CANCEL));
-            return UURET_CANCEL;
-          }
-
-        if (encoding == PT_ENCODED)
-          {
+      if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize))
+          return UURET_CANCEL;
 
-            /*
-             * If there is a line feed, replace by eolstring
-             */
-            if (count > 0 && itemp[count-1] == '\n')
-              {
-                itemp[--count] = '\0';
-                if (fwrite (itemp, sizeof(unsigned char), count, outfile) != count ||
-                    fwrite ((char *) eolstring, sizeof(unsigned char),
-                            strlen(eolstring), outfile) != strlen (eolstring))
-                  {
-                    return UURET_IOERR;
-                  }
-              }
-              else
-              {
-                size_t res;
-                if ((res=fwrite (itemp, sizeof(unsigned char), count, outfile)) != count)
-                  {
-                    return UURET_IOERR;
-                  }
-              }
-          }
+      if (encoding == PT_ENCODED)
+      {
+        size_t res;
+        if ((res=fwrite (itemp, sizeof(unsigned char), count, outfile)) != count)
+            return UURET_IOERR;
+      }
           else if (encoding == QP_ENCODED)
           {
             for (index=0; index<count; index++)
@@ -1711,21 +1685,16 @@ UUEncodePartial_byFSize (FILE *outfile, FILE *infile,
        * print sub-header
        */
 
-      // pan change (imhotep) : headers are already in the gmimemessage, so there's no need to add them
-      // to the body.
-
 //      if (encoding != YENC_ENCODED)
 //      {
 //        fprintf (outfile, "MIME-Version: 1.0%s", eolstring);
-//        fprintf (outfile, "Content-Type: %s%s",
-//                 (mimetype)?mimetype:"Application/Octet-Stream",
-//                 eolstring);
+//        fprintf (outfile, "Content-Type: Message/Partial; number=%d; total=%d;%s",
+//               partno, numparts, eolstring);
 //        fprintf (outfile, "Content-Transfer-Encoding: %s%s",
 //                 CTE_TYPE(encoding), eolstring);
 //        fprintf (outfile, "Content-Disposition: attachment; filename=\"%s\"%s",
 //                 UUFNameFilter ((outfname)?outfname:infname), eolstring);
 //      }
-//
 //      fprintf (outfile, "%s", eolstring);
 
       /*



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