[pan2/testing: 170/279] partial fix for a few things, still a little buggy (sorry about that)



commit e0c8ae24d1b92f8553520dbc0ccc0d22e4f2cbfd
Author: Heinrich MÃller <sphemuel stud informatik uni-erlangen de>
Date:   Wed Jul 13 21:17:33 2011 +0200

    partial fix for a few things, still a little buggy (sorry about that)

 pan/gui/gui.cc           |   80 ++++++++++++++++++++++++++++++++++++++++++++++
 pan/gui/gui.h            |    8 ++++
 pan/gui/post-ui.cc       |   13 +++++--
 pan/tasks/encoder.h      |    2 +-
 pan/tasks/task-upload.cc |   49 ++++++++++++++++++++--------
 pan/tasks/task-upload.h  |    5 +--
 uulib/uuencode.c         |   33 +++++++++----------
 7 files changed, 151 insertions(+), 39 deletions(-)
---
diff --git a/pan/gui/gui.cc b/pan/gui/gui.cc
index 82368c4..48e7bfa 100644
--- a/pan/gui/gui.cc
+++ b/pan/gui/gui.cc
@@ -162,6 +162,21 @@ namespace
   }
 }
 
+namespace
+{
+  enum {
+        TARGET_STRING,
+        TARGET_ROOTWIN
+  };
+
+  static GtkTargetEntry target_list[] = {
+          { "STRING",     0, TARGET_STRING },
+          { "text/plain", 0, TARGET_STRING },
+          { "application/x-rootwindow-drop", 0, TARGET_ROOTWIN }
+  };
+}
+
+
 
 GUI :: GUI (Data& data, Queue& queue, ArticleCache& cache, EncodeCache& encode_cache, Prefs& prefs, GroupPrefs& group_prefs):
   _data (data),
@@ -259,6 +274,14 @@ GUI :: GUI (Data& data, Queue& queue, ArticleCache& cache, EncodeCache& encode_c
   gtk_widget_set_tooltip_text (w, _("Open the Task Manager"));
   gtk_button_set_relief (GTK_BUTTON(w), GTK_RELIEF_NONE);
   g_signal_connect (w, "clicked", G_CALLBACK(show_task_window_cb), this);
+
+  // drag and drop for message-ids
+//  gtk_drag_dest_set(w,GTK_DEST_DEFAULT_ALL,target_list,3,GDK_ACTION_COPY);
+//  gtk_drag_dest_add_text_targets(w);
+//  gtk_drag_dest_add_uri_targets(w);
+//  g_signal_connect (w, "drag-data-received", G_CALLBACK(dragged_rcvd), this);
+//  g_signal_connect (w, "drag-drop", G_CALLBACK (dragged), this);
+
   gtk_container_add (GTK_CONTAINER(w), _queue_size_label);
   frame = gtk_frame_new (NULL);
   gtk_container_set_border_width (GTK_CONTAINER(frame), 0);
@@ -565,6 +588,63 @@ GUI :: prompt_user_for_filename (GtkWindow * parent, const Prefs& prefs)
   return file;
 }
 
+gboolean GUI ::dragged(GtkWidget *wgt, GdkDragContext *context, int x, int y,
+              GtkSelectionData *seldata, guint info, guint time,
+              gpointer userdata)
+{
+
+  gtk_drag_finish (context, true, true, time);
+
+  GUI * p(static_cast<GUI*>(userdata));
+
+  std::cerr<<"dragged\n";
+
+  GdkAtom target_type;
+
+  /* If the source offers a target */
+  if (context-> targets)
+  {
+    target_type = GDK_POINTER_TO_ATOM
+            (g_list_nth_data (context-> targets, TARGET_STRING));
+
+    gtk_drag_get_data(wgt,context,target_type,time);
+  }
+
+  return true;
+
+}
+
+void GUI ::dragged_rcvd(GtkWidget *wgt, GdkDragContext *context, int x, int y,
+              GtkSelectionData *seldata, guint info, guint time,
+              gpointer userdata)
+{
+
+  gtk_drag_finish (context, true, true, time);
+
+  std::cerr<<"dragged rcvd\n";
+
+  GUI * p(static_cast<GUI*>(userdata));
+
+  GtkWidget * header_pane;
+  GtkTreeIter   iter;
+
+  header_pane = GTK_WIDGET(userdata);
+  std::cerr<<"data : "<<(gchar*)seldata->data<<std::endl;
+  Article a;
+  a.message_id = Quark((gchar*)seldata->data);
+  a.xref.insert ("2", "alt.binaries.test", 0);
+  a.set_part_count (1);
+  a.is_binary = true;
+  std::vector<Article> v;
+  v.push_back(a);
+  SaveDialog * dialog = new SaveDialog (p->_prefs, p->_group_prefs, p->_data, p->_data,
+                                        p->_cache, p->_data, p->_queue, get_window(p->_root), p->_header_pane->get_group(), v);
+  gtk_widget_show (dialog->root());
+
+  gtk_drag_finish (context, true, false, time);
+
+}
+
 void GUI :: do_save_articles ()
 {
   std::string path;
diff --git a/pan/gui/gui.h b/pan/gui/gui.h
index a6c1f51..5470a09 100644
--- a/pan/gui/gui.h
+++ b/pan/gui/gui.h
@@ -217,6 +217,14 @@ namespace pan
       std::list<Task*> _active_tasks;
       std::string _charset;
 
+      static gboolean dragged(GtkWidget *wgt, GdkDragContext *context, int x, int y,
+              GtkSelectionData *seldata, guint info, guint time,
+              gpointer userdata);
+
+      static void dragged_rcvd(GtkWidget *wgt, GdkDragContext *context, int x, int y,
+              GtkSelectionData *seldata, guint info, guint time,
+              gpointer userdata);
+
       void set_charset (const StringView& v);
 
       void upkeep ();
diff --git a/pan/gui/post-ui.cc b/pan/gui/post-ui.cc
index 5405cd2..20d5c02 100644
--- a/pan/gui/post-ui.cc
+++ b/pan/gui/post-ui.cc
@@ -153,7 +153,7 @@ PostUI:: update_filequeue_label (GtkTreeSelection *selection)
       TaskUpload * task (*it);
       kb += task->_bytes/1024;
     }
-    g_snprintf(str,sizeof(str), _("Upload Queue : %d Tasks, %ld KB (~ %.2f MB) total ."), tasks.size(), kb, kb/1024.0f);
+    g_snprintf(str,sizeof(str), _("Upload Queue : %ld Tasks, %ld KB (~ %.2f MB) total ."), tasks.size(), kb, kb/1024.0f);
     gtk_label_set_text (GTK_LABEL(_filequeue_label), str);
 }
 
@@ -1087,7 +1087,7 @@ PostUI :: maybe_post_message (GMimeMessage * message)
       : GNKSA::generate_message_id_from_email_address (profile.address);
     StringView domain(d);
 
-    /// TODO maybe update tasks' msgs here ???
+    /// TODO maybe update tasks' msg headers here ???
 
     /* init taskupload variables before adding the tasks to the queue for processing */
     foreach (PostUI::tasks_t, tasks, it)
@@ -1116,6 +1116,9 @@ PostUI :: maybe_post_message (GMimeMessage * message)
       // (for example for saving the nzb file). it will be hidden and destroyed on destruction of
       // the last Taskupload task.
       // (perhaps this could be changed if we added a listener for this in gui.cc and let post-ui.cc die) (??)
+
+      std::string last_mid;
+
       foreach (std::set<int>, t->_wanted, pit)
       {
         if (custom_mid)
@@ -1128,6 +1131,8 @@ PostUI :: maybe_post_message (GMimeMessage * message)
         g_snprintf(buf,sizeof(buf),"%s.%d", basename, *pit);
         n.message_id = buf;
         n.partno = *pit;
+        n.last_mid = last_mid;
+        last_mid = n.mid;
         t->_needed.insert(std::pair<int,TaskUpload::Needed>(*pit,n));
       }
       t->build_needed_tasks();
@@ -1476,11 +1481,11 @@ PostUI :: new_message_from_ui (Mode mode, bool copy_body)
   g_free (pch);
 
   // User-Agent
-  if (mode==POSTING && _prefs.get_flag (USER_AGENT_PREFS_KEY, true))
+  if ((mode==POSTING || mode == UPLOADING) && _prefs.get_flag (USER_AGENT_PREFS_KEY, true))
     g_mime_object_set_header ((GMimeObject *) msg, "User-Agent", get_user_agent());
 
   // Message-ID for single text-only posts
-  if (mode==POSTING && _prefs.get_flag (MESSAGE_ID_PREFS_KEY, false)) {
+  if ((mode==POSTING || mode==UPLOADING) && _prefs.get_flag (MESSAGE_ID_PREFS_KEY, false)) {
     const std::string message_id = !profile.fqdn.empty()
       ? GNKSA::generate_message_id (profile.fqdn)
       : GNKSA::generate_message_id_from_email_address (profile.address);
diff --git a/pan/tasks/encoder.h b/pan/tasks/encoder.h
index f7c7a89..6f962cd 100644
--- a/pan/tasks/encoder.h
+++ b/pan/tasks/encoder.h
@@ -41,7 +41,7 @@ extern "C" {
 namespace pan
 {
   /**
-   * Encodes attachments (yEnc) for posting to usenet groups.
+   * Encodes attachments (yEnc, BASE64,MIME PT) for posting to usenet groups.
    *
    * @author Heinrich Mueller <eddie_v gmx de>
    * @author Calin Culianu <calin ajvar org>
diff --git a/pan/tasks/task-upload.cc b/pan/tasks/task-upload.cc
index fcb94a9..c4937ad 100644
--- a/pan/tasks/task-upload.cc
+++ b/pan/tasks/task-upload.cc
@@ -108,6 +108,20 @@ TaskUpload :: TaskUpload (const std::string         & filename,
 
 }
 
+namespace
+{
+  const char * build_subject_line (char* buf, int size, std::string& s, std::string& n, int p, int tp, TaskUpload::EncodeMode em)
+  {
+
+      if (tp != 1)
+        g_snprintf(buf, size,"%s - \"%s\" %s (%03d/%03d)", s.c_str(), n.c_str(), em == TaskUpload::YENC ? "yEnc" : "", p, tp );
+      else
+        g_snprintf(buf, size,"%s - \"%s\"  %s", s.c_str(), n.c_str(), em == TaskUpload::YENC ? "yEnc" : "");
+
+    return buf;
+  }
+}
+
 void
 TaskUpload :: build_needed_tasks()
 {
@@ -120,10 +134,8 @@ TaskUpload :: build_needed_tasks()
   _cache.reserve(_mids);
 
   /* build new master subject */
-  char sub[2048];
-  g_snprintf(sub,2048,"%s - \"%s\" - (%03d/%03d)", _subject.c_str(), _basename.c_str(), 1, _total_parts);
-  _master_subject = sub;
-
+  char buf[4096];
+  _master_subject = build_subject_line (buf, 4096, _subject, _basename, 1, _total_parts, _encode_mode);
 }
 
 void
@@ -149,9 +161,9 @@ TaskUpload :: update_work (NNTP* checkin_pending)
   }
   else if ((_encoder_has_run && !_needed.empty()))
   {
-    _state.set_completed();
-    set_finished(_queue_pos);
-//    _state.set_need_nntp(_server);
+//    _state.set_completed();
+//    set_finished(_queue_pos);
+    _state.set_need_nntp(_server);
   }
   else if (_needed.empty())
   {
@@ -160,6 +172,17 @@ TaskUpload :: update_work (NNTP* checkin_pending)
   }
 }
 
+namespace
+{
+  void mod_refs (GMimeMessage* msg, std::string& refs, std::string& mid)
+  {
+    if (mid.empty()) return ; // do nothing if no new mids are added
+    char buf[4096];
+    g_snprintf(buf,sizeof(buf), "%s <%s>", refs.c_str(), mid.c_str());
+    g_mime_object_set_header ((GMimeObject *) msg, "References", buf);
+  }
+}
+
 void
 TaskUpload :: prepend_headers(GMimeMessage* msg, TaskUpload::Needed * n, std::string& d)
 {
@@ -169,13 +192,11 @@ TaskUpload :: prepend_headers(GMimeMessage* msg, TaskUpload::Needed * n, std::st
     if (!n->mid.empty()) pan_g_mime_message_set_message_id (msg, n->mid.c_str());
 
     //modify subject
-    char buf[2048];
-    g_snprintf(buf, sizeof(buf), "%s - \"%s\" - %s(%d/%d)",
-               _subject.c_str(),
-               _basename.c_str(),
-               (_encode_mode==YENC ? " yEnc ":""),
-               n->partno, _total_parts);
-    g_mime_message_set_subject (msg, buf);
+    char buf[4096];
+    g_mime_message_set_subject (msg, build_subject_line (buf, 4096, _subject, _basename, n->partno, _total_parts, _encode_mode));
+
+    //modify references header
+    mod_refs (msg, _references,  n->last_mid);
 
     //extract whole message with headers (for first message, others only post headers + encoded data)
     char * all;
diff --git a/pan/tasks/task-upload.h b/pan/tasks/task-upload.h
index b685e7b..b260002 100644
--- a/pan/tasks/task-upload.h
+++ b/pan/tasks/task-upload.h
@@ -72,12 +72,11 @@ namespace pan
         unsigned long bytes;
         int partno;
         NNTP* nntp;
-        std::string message_id;
+        std::string message_id, last_mid;
         std::string mid; // for rng
         std::string cachename;
         Xref xref;
-        bool encoded;
-        Needed (): nntp(0), bytes(0) , partno(1), encoded(false) {}
+        Needed (): nntp(0), bytes(0) , partno(1) {}
         void reset() { nntp = 0; }
       };
 
diff --git a/uulib/uuencode.c b/uulib/uuencode.c
index 47117ab..5b4d1c6 100644
--- a/uulib/uuencode.c
+++ b/uulib/uuencode.c
@@ -699,15 +699,14 @@ UUEncodeStream_byFSize (FILE *outfile, FILE *infile, int encoding, long bpf, crc
   long rest = bpf;
   long current = 0;
 
+  ///TODO fixme!!
+
   if (encoding == PT_ENCODED || encoding == QP_ENCODED)
     {
       while (!feof (infile) && rest > 0 )
       {
         current = rest > 255 ? 255 : rest;
 
-//        if (_FP_fgets (itemp, 255, infile) == NULL)
-//          break;
-
       if ((count = fread (itemp, sizeof(unsigned char), current, infile)) != 255)
       {
         if (count == 0)
@@ -1472,7 +1471,7 @@ UUEncodePartial (FILE *outfile, FILE *infile,
                        eolstring);
             }
 
-          fprintf (outfile, "=ypart begin=%d end=%d%s",
+          fprintf (outfile, "=ypart begin=%ld end=%ld%s",
                    (partno-1)*linperfile*128+1,
                    (partno*linperfile*128) < progress.totsize ?
                    (partno*linperfile*128) : progress.totsize,
@@ -1546,7 +1545,7 @@ UUEncodePartial (FILE *outfile, FILE *infile,
     {
       if (numparts != 1)
         {
-          fprintf (outfile, "=yend size=%d part=%d pcrc32=%08lx",
+          fprintf (outfile, "=yend size=%ld part=%d pcrc32=%08lx",
                    (partno*linperfile*128) < progress.totsize ?
                    linperfile*128 : (progress.totsize-(partno-1)*linperfile*128),
                    partno,
@@ -1554,7 +1553,7 @@ UUEncodePartial (FILE *outfile, FILE *infile,
         }
       else
         {
-          fprintf (outfile, "=yend size=%d",
+          fprintf (outfile, "=yend size=%ld",
                    progress.totsize);
         }
       if (feof (theifile))
@@ -1645,10 +1644,10 @@ UUEncodePartial_byFSize (FILE *outfile, FILE *infile,
                          infname, strerror (uu_errno=errno));
               return UURET_IOERR;
             }
-          if (bpf <= 0)
+          if (finfo.st_size <= bpf)
             numparts = 1;
           else
-            numparts = (int) ((long)ceill(finfo.st_size / bpf));
+            numparts = (int) (ceill(finfo.st_size / bpf));
 
           themode  = (filemode) ? filemode : ((int) finfo.st_mode & 0777);
           thesize  = (long) finfo.st_size;
@@ -1668,10 +1667,10 @@ UUEncodePartial_byFSize (FILE *outfile, FILE *infile,
               themode =  (int) finfo.st_mode & 0777;
               thesize = (long) finfo.st_size;
 
-              if (bpf <= 0)
+              if (finfo.st_size <= bpf)
                 numparts = 1;
               else
-                numparts = (int) ((long)ceill(thesize / bpf));
+                numparts = (int) (ceill(thesize / bpf));
 
 
             }
@@ -1738,7 +1737,7 @@ UUEncodePartial_byFSize (FILE *outfile, FILE *infile,
         }
     }
 
-
+  printf("numparts %d\n", numparts);
 
   if (encoding == YENC_ENCODED)
     {
@@ -1762,7 +1761,7 @@ UUEncodePartial_byFSize (FILE *outfile, FILE *infile,
                        eolstring);
             }
 
-          fprintf (outfile, "=ypart begin=%d end=%d%s",
+          fprintf (outfile, "=ypart begin=%ld end=%ld%s",
                    (partno-1)*bpf,
                    (partno*bpf) < progress.totsize ?
                    (partno*bpf) : progress.totsize,
@@ -1836,7 +1835,7 @@ UUEncodePartial_byFSize (FILE *outfile, FILE *infile,
   {
     if (numparts != 1)
       {
-        fprintf (outfile, "=yend size=%d part=%d pcrc32=%08lx",
+        fprintf (outfile, "=yend size=%ld part=%d pcrc32=%08lx",
                  (partno*bpf) < progress.totsize ?
                  bpf : (progress.totsize-(partno-1)*bpf),
                  partno,
@@ -1844,7 +1843,7 @@ UUEncodePartial_byFSize (FILE *outfile, FILE *infile,
       }
     else
       {
-        fprintf (outfile, "=yend size=%d",
+        fprintf (outfile, "=yend size=%ld",
                  progress.totsize);
       }
     if (feof (theifile))
@@ -2293,7 +2292,7 @@ UUEncodeToFile (FILE *infile, char *infname, int encoding,
                            eolstring);
                 }
 
-              fprintf (outfile, "=ypart begin=%d end=%d%s",
+              fprintf (outfile, "=ypart begin=%ld end=%ld%s",
                        (part-1)*linperfile*128+1,
                        (part*linperfile*128) < progress.totsize ?
                        (part*linperfile*128) : progress.totsize,
@@ -2347,7 +2346,7 @@ UUEncodeToFile (FILE *infile, char *infname, int encoding,
         {
           if (numparts != 1)
             {
-              fprintf (outfile, "=yend size=%d part=%d pcrc32=%08lx",
+              fprintf (outfile, "=yend size=%ld part=%d pcrc32=%08lx",
                        (part*linperfile*128) < progress.totsize ?
                        linperfile*128 : (progress.totsize-(part-1)*linperfile*128),
                        part,
@@ -2355,7 +2354,7 @@ UUEncodeToFile (FILE *infile, char *infname, int encoding,
             }
           else
             {
-              fprintf (outfile, "=yend size=%d",
+              fprintf (outfile, "=yend size=%ld",
                        progress.totsize);
             }
           if (feof (theifile))



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