updated mblist-window.c



Hello,

I just downloaded the latest version of Balsa.   I like the program so
far...  I thought it would
be fun to hack a bit so I looked at the TODO and saw the comment about
message counts
in the message list window.  This is something I want as well.  I added
two columns to the
GtkCTree in mblist-window.c,Unread & Total.  I also added column
headings.  A few
comments:

1) there seems to be no easy fast way to get  message counts without
scanning the
    mailbox.  Is  this true?
2) if the mailbox isn't open, I have to open it (mailbox_open_ref ) to
get the message
    counts.  Should I close mailboxes that I open?  My gut feeling is
yes.
3) currently the message counts don't get updated when messages are
moved,
    deleted, received or read.  Any sugestions for a good solution?
4) sugestions for functionality are welcome

I don't know what the policy for contributing to Balsa is, this work was
very impulsive.
If someone has already coded this or if there is no interest in my work,
sorry
for wasting your time.  If there is interest, I will follow through with
my effort to make this
complete.




*** balsa-0.4.6.2/src/mblist-window.c Sun Aug 23 15:09:48 1998
--- balsa-current/src/mblist-window.c Mon Oct 19 23:31:55 1998
***************
*** 76,86 ****
--- 76,89 ----
  static void open_cb (GtkWidget *, gpointer);
  static void close_cb (GtkWidget *, gpointer);

+ static void message_counts (Mailbox *, gchar *, gchar *);
+
  static gboolean mailbox_nodes_to_ctree (GtkCTree *, guint, GNode *,
GtkCTreeNode *, gpointer);

  void
  mblist_open_window (GnomeMDI * mdi)
  {
+   gchar *titles[] = { "Mailbox", "Unread", "Total" };
    GtkWidget *bbox;
    GtkWidget *button;
    GdkColor *transparent = NULL;
***************
*** 131,140 ****
          (GtkSignalFunc) gtk_false,
          NULL);

!   mblw->ctree = GTK_CTREE (gtk_ctree_new (1, 0));
    gtk_ctree_set_line_style (mblw->ctree, GTK_CTREE_LINES_DOTTED);
    gtk_clist_set_policy (GTK_CLIST (mblw->ctree), GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
    gtk_clist_set_row_height (GTK_CLIST (mblw->ctree), 16);
    gtk_box_pack_start (GTK_BOX (GTK_DIALOG (mblw->window)->vbox),
GTK_WIDGET (mblw->ctree), TRUE, TRUE, 0);
    gtk_widget_show (GTK_WIDGET (mblw->ctree));

--- 134,147 ----
          (GtkSignalFunc) gtk_false,
          NULL);

!   mblw->ctree = GTK_CTREE (gtk_ctree_new_with_titles (3, 0, titles));
    gtk_ctree_set_line_style (mblw->ctree, GTK_CTREE_LINES_DOTTED);
    gtk_clist_set_policy (GTK_CLIST (mblw->ctree), GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
    gtk_clist_set_row_height (GTK_CLIST (mblw->ctree), 16);
+   gtk_clist_set_column_width (GTK_CLIST (mblw->ctree), 0, 100);
+   gtk_clist_set_column_width (GTK_CLIST (mblw->ctree), 1, 50);
+   gtk_clist_set_column_width (GTK_CLIST (mblw->ctree), 2, 50);
+
    gtk_box_pack_start (GTK_BOX (GTK_DIALOG (mblw->window)->vbox),
GTK_WIDGET (mblw->ctree), TRUE, TRUE, 0);
    gtk_widget_show (GTK_WIDGET (mblw->ctree));

***************
*** 183,190 ****
  mblist_redraw ()
  {
    GtkCTreeNode *ctnode;
    gchar *text[] =
!   {"Balsa"};   /* for root tree stub */
    if (!GTK_IS_CTREE (mblw->ctree))
      return;

--- 190,198 ----
  mblist_redraw ()
  {
    GtkCTreeNode *ctnode;
+   gchar buff1[1024], buff2[1024];
    gchar *text[] =
!   {"Balsa","",""};   /* for root tree stub */
    if (!GTK_IS_CTREE (mblw->ctree))
      return;

***************
*** 204,211 ****
--- 212,225 ----
       NULL, NULL, NULL, FALSE, TRUE);
  #endif

+   text[1] = buff1;
+   text[2] = buff2;
+
    /* inbox */
    text[0] = "Inbox";
+
+   message_counts(balsa_app.inbox, text[1], text[2]);
+
  #ifndef GTK_HAVE_FEATURES_1_1_2
    ctnode = gtk_ctree_insert (mblw->ctree, mblw->parent, NULL, text, 5,
inboxpix,
          inbox_mask, inboxpix, inbox_mask, FALSE, TRUE);
***************
*** 218,223 ****
--- 232,239 ----

    /* outbox */
    text[0] = "Outbox";
+   message_counts(balsa_app.outbox, text[1], text[2]);
+
  #ifndef GTK_HAVE_FEATURES_1_1_2
    ctnode = gtk_ctree_insert (mblw->ctree, mblw->parent, NULL, text, 5,
outboxpix,
       outbox_mask, outboxpix, outbox_mask, FALSE, TRUE);
***************
*** 228,235 ****
    gtk_ctree_node_set_row_data (mblw->ctree, ctnode, balsa_app.outbox);

  #endif

!   /* inbox */
    text[0] = "Trash";
  #ifndef GTK_HAVE_FEATURES_1_1_2
    ctnode = gtk_ctree_insert (mblw->ctree, mblw->parent, NULL, text, 5,
trashpix,
          trash_mask, trashpix, trash_mask, FALSE, TRUE);
--- 244,252 ----
    gtk_ctree_node_set_row_data (mblw->ctree, ctnode, balsa_app.outbox);

  #endif

!   /* trash */
    text[0] = "Trash";
+   message_counts(balsa_app.trash, text[1], text[2]);
  #ifndef GTK_HAVE_FEATURES_1_1_2
    ctnode = gtk_ctree_insert (mblw->ctree, mblw->parent, NULL, text, 5,
trashpix,
          trash_mask, trashpix, trash_mask, FALSE, TRUE);
***************
*** 263,268 ****
--- 280,286 ----
     GtkCTreeNode * cnode,
     gpointer data)
  {
+   gchar buff1[1024], buff2[1024];
    MailboxNode *mbnode;

    if (!gnode || (!(mbnode = gnode->data)))
***************
*** 270,275 ****
--- 288,295 ----

    if (mbnode->mailbox)
      {
+       message_counts(mbnode->mailbox, buff1, buff2);
+
        if (mbnode->mailbox->type == MAILBOX_IMAP)
   {
     gtk_ctree_set_node_info (ctree, cnode, mbnode->mailbox->name, 5,
***************
*** 319,324 ****
--- 339,347 ----
  #endif
       }
   }
+
+       gtk_ctree_node_set_text(ctree, cnode, 1, buff1);
+       gtk_ctree_node_set_text(ctree, cnode, 2, buff2);
      }
    if (mbnode->name && !mbnode->mailbox)
      {
***************
*** 327,332 ****
--- 350,358 ----
            closed_folder, closed_mask,
            open_folder, open_mask,
            G_NODE_IS_LEAF (gnode), TRUE);
+
+       gtk_ctree_node_set_text(ctree, cnode, 1, "-");
+       gtk_ctree_node_set_text(ctree, cnode, 2, "-");
      }
    return TRUE;
  }
***************
*** 504,507 ****
--- 530,572 ----
    gtk_widget_show (menuitem);

    return menu;
+ }
+
+ static void
+ message_counts (Mailbox * mailbox, gchar *new_messages_str, gchar
*messages_str)
+ {
+   gint opened = 0;
+   gint new_messages = 0;
+   gint messages = 0;
+   Message *message;
+   GList *list;
+
+   if (mailbox->open_ref == 0)
+     {
+       mailbox_open_ref (mailbox);
+       opened = 1;
+     }
+
+
+   list = mailbox->message_list;
+   while (list)
+     {
+       message = (Message *) list->data;
+       list = list->next;
+
+       messages++;
+
+       if (message->flags & MESSAGE_FLAG_NEW)
+         new_messages++;
+     }
+
+   snprintf (new_messages_str, 1024, "%d", new_messages);
+   snprintf (messages_str, 1024, "%d", messages);
+
+   if (opened)
+     {
+       /* close the mailbox ?? */
+     }
+
+   return;
  }




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