Looking more into the sources, I think I didn't started right. Instead
of re-using current "menu" I should create my own. It does not look so
difficult after all.
I'll slowly progress on the patch whenever I have some time. My question
is, would this functionality be considered to including into mutt-kz?
Thank you
--
Vlad
On po, kvě 13, 2013 at 10:26:43dop. +0200, Vladimir Marek wrote:
Hi,
I'm playing with notumuch and mutt-kz trying to find out my optimal
setup. For this I often want to see what tags have give message(s)
assigned to them. I found some spare time on weekend I devoted to that,
which resulted in the attached patch. It's alpha version, so it's in no
way complete, bug free etc. But it can display tags assigned to given
message(s). What I want to achieve in the end is
- display the tags in browser (similarly to how you browse available
mailboxes for example) (done)
- display how many messages from the group has given tag assigned
- ability to add/remove the tags directly from browser. Ideally the
browser would just remember which tags you added/removed and later it
would call 'modify-labels' which would do rest of the work.
Comments welcome.
Cheers
--
Vlad
diff --git a/OPS.NOTMUCH b/OPS.NOTMUCH
index c69691c..a50c453 100644
--- a/OPS.NOTMUCH
+++ b/OPS.NOTMUCH
@@ -2,3 +2,4 @@ OP_MAIN_CHANGE_VFOLDER "open a different virtual folder"
OP_MAIN_VFOLDER_FROM_QUERY "generate virtual folder from query"
OP_MAIN_MODIFY_LABELS "modify (notmuch) tags"
OP_MAIN_MODIFY_LABELS_THEN_HIDE "modify labeld and then hide message"
+OP_MAIN_BROWSE_LABELS "browse (notmuch) tags"
diff --git a/browser.c b/browser.c
index 39b839c..f36c570 100644
--- a/browser.c
+++ b/browser.c
@@ -493,6 +493,16 @@ static int examine_vfolders (MUTTMENU *menu, struct browser_state
*state)
browser_sort (state);
return 0;
}
+
+static int examine_tags (MUTTMENU *menu, struct browser_state *state, char ***fnames,
int *count)
+{
+ mutt_buffy_check (0);
+
+ init_state (state, menu);
+ nm_add_tags(menu, state, add_folder);
+ browser_sort (state);
+ return 0;
+}
#endif
static int examine_mailboxes (MUTTMENU *menu, struct browser_state *state)
@@ -707,7 +717,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char
***files, int *num
#endif
}
#ifdef USE_NOTMUCH
- else if (!(flags & M_SEL_VFOLDER))
+ else if (!(flags & (M_SEL_VFOLDER|M_SEL_NOTMUCH_TAGS) ))
#else
else
#endif
@@ -742,6 +752,8 @@ void _mutt_select_file (char *f, size_t flen, int flags, char
***files, int *num
if (flags & M_SEL_VFOLDER) {
if (examine_vfolders (NULL, &state) == -1)
goto bail;
+ } else if (flags & M_SEL_NOTMUCH_TAGS) {
+ examine_tags (NULL, &state, files, numfiles);
} else
#endif
if (buffy)
diff --git a/curs_main.c b/curs_main.c
index 153eedf..bd28ac8 100644
--- a/curs_main.c
+++ b/curs_main.c
@@ -1253,6 +1253,7 @@ int mutt_index_menu (void)
break;
case OP_MAIN_CHANGE_VFOLDER:
+ case OP_MAIN_BROWSE_LABELS:
#endif
case OP_SIDEBAR_OPEN:
case OP_MAIN_CHANGE_FOLDER:
@@ -1270,6 +1271,8 @@ int mutt_index_menu (void)
#ifdef USE_NOTMUCH
else if (op == OP_MAIN_CHANGE_VFOLDER)
cp = _("Open virtual folder");
+ else if (op == OP_MAIN_BROWSE_LABELS)
+ cp = _("Edit available labels");
#endif
else
cp = _("Open mailbox");
@@ -1290,9 +1293,41 @@ int mutt_index_menu (void)
{
mutt_buffy (buf, sizeof (buf));
#ifdef USE_NOTMUCH
+/* XXXXXXXXXXXXXXXXXXXX */
+ // printf ("curs_main 1 '%s'\n\r", buf);
if (op == OP_MAIN_CHANGE_VFOLDER)
mutt_enter_vfolder (cp, buf, sizeof (buf), &menu->redraw, 1);
- else
+ else if (op == OP_MAIN_BROWSE_LABELS) {
+ // printf ("curs_main 2\n\r");
+
+ /*
+ const char *prompt, char *buf, size_t blen,
+ int *redraw, int buffy, int multiple,
+ char ***files, int *numfiles, int flags
+ */
+ nm_browse_tags_init(Context);
+
+ if (tag && !option (OPTAUTOTAG))
+ {
+ // printf ("Count: %d\n\r", Context->vcount);
+ for (j = 0; j < Context->vcount; j++) {
+ if (Context->hdrs[Context->v2r[j]]->tagged) {
+ nm_browse_tags (Context->hdrs[Context->v2r[j]]);
+ // printf ("...\n\r");
+ }
+ }
+ }
+ else
+ {
+ nm_browse_tags (CURHDR);
+ }
+ _mutt_enter_fname(
+ cp,buf,sizeof(buf),
+ &menu->redraw,1,0,
+ NULL,NULL,M_SEL_NOTMUCH_TAGS|M_SEL_MULTI);
+
+ nm_browse_tags_finish(Context);
+ } else
#endif
if ( op == OP_SIDEBAR_OPEN )
{
diff --git a/functions.h b/functions.h
index c27d9f1..7e6d46f 100644
--- a/functions.h
+++ b/functions.h
@@ -171,8 +171,9 @@ const struct binding_t OpMain[] = { /* map: index */
#ifdef USE_NOTMUCH
{ "change-vfolder", OP_MAIN_CHANGE_VFOLDER, "X" },
{ "vfolder-from-query", OP_MAIN_VFOLDER_FROM_QUERY, "\033X"
},
- { "modify-labels", OP_MAIN_MODIFY_LABELS, "`" },
+ { "modify-labels", OP_MAIN_MODIFY_LABELS, NULL },
{ "modify-labels-then-hide", OP_MAIN_MODIFY_LABELS_THEN_HIDE, NULL },
+ { "browse-labels", OP_MAIN_BROWSE_LABELS, "`" },
#endif
{ "sidebar-scroll-up", OP_SIDEBAR_SCROLL_UP, NULL },
{ "sidebar-scroll-down", OP_SIDEBAR_SCROLL_DOWN, NULL },
@@ -287,8 +288,9 @@ const struct binding_t OpPager[] = { /* map: pager */
#ifdef USE_NOTMUCH
{ "change-vfolder", OP_MAIN_CHANGE_VFOLDER, "X" },
{ "vfolder-from-query", OP_MAIN_VFOLDER_FROM_QUERY, "\033X" },
- { "modify-labels", OP_MAIN_MODIFY_LABELS, "`" },
+ { "modify-labels", OP_MAIN_MODIFY_LABELS, NULL },
{ "modify-labels-then-hide", OP_MAIN_MODIFY_LABELS_THEN_HIDE, NULL },
+ { "browse-labels", OP_MAIN_BROWSE_LABELS, "`" },
#endif
{ "sidebar-scroll-up", OP_SIDEBAR_SCROLL_UP, NULL },
{ "sidebar-scroll-down", OP_SIDEBAR_SCROLL_DOWN, NULL },
diff --git a/mutt.h b/mutt.h
index e94e228..29d14d2 100644
--- a/mutt.h
+++ b/mutt.h
@@ -304,6 +304,7 @@ enum
#define M_SEL_MULTI (1<<1)
#define M_SEL_FOLDER (1<<2)
#define M_SEL_VFOLDER (1<<3)
+#define M_SEL_NOTMUCH_TAGS (1<<4)
/* flags for parse_spam_list */
#define M_SPAM 1
diff --git a/mutt_notmuch.c b/mutt_notmuch.c
index 9ede705..243a30d 100644
--- a/mutt_notmuch.c
+++ b/mutt_notmuch.c
@@ -1536,3 +1536,110 @@ done:
ctx->msgcount > oldmsgcount ? M_NEW_MAIL :
new_flags ? M_FLAGS : 0;
}
+
+struct browse_tags {
+ notmuch_database_t *db;
+ HASH *hash;
+ char **tags;
+ int ntags, tags_size;
+} browse_tags;
+
+
+int
+nm_browse_tags_init (CONTEXT *ctx)
+{
+ struct nm_ctxdata *data;
+
+ if ( ! (data = get_ctxdata(ctx)) ) {
+ // printf ("error, no data?\n\r");
+ return -1;
+ }
+ browse_tags.db = NULL;
+
+ // printf ("browse 1\n\r");
+ if ( ! (browse_tags.db = get_db(data, TRUE)) ) {
+ // printf ("error, no db\n\r");
+ return -1;
+ }
+ browse_tags.hash = hash_create(50, 0);
+ browse_tags.ntags = 0;
+ browse_tags.tags_size = 0;
+ browse_tags.tags = NULL;
+ // printf ("browse 2\n\r");
+ return 0;
+}
+
+int
+nm_add_tags (MUTTMENU *menu, struct browser_state *state, void(*add_folder)(MUTTMENU *,
struct browser_state *, const char *, const char *, const struct stat *, unsigned int,
unsigned int all))
+{
+ int i;
+
+ // printf ("browse 3\n\r");
+ for (i=0; i<browse_tags.ntags; i++) {
+ // printf ("adding folder '%s'\n\r", browse_tags.tags[i]);
+ add_folder (menu, state, browse_tags.tags[i], "tag", NULL, 0, 0);
+ safe_free(&(browse_tags.tags[i]));
+ }
+ safe_free(&browse_tags.tags);
+ browse_tags.db = NULL;
+ hash_destroy(&browse_tags.hash, NULL);
+ browse_tags.hash = NULL;
+
+ return 0;
+}
+
+int
+nm_browse_tags_finish(CONTEXT *ctx)
+{
+ struct nm_ctxdata *data;
+
+ if ( ! (data = get_ctxdata(ctx)) ) {
+ // printf ("error, no data?\n\r");
+ return -1;
+ }
+
+ if (!is_longrun(data))
+ release_db(data);
+
+ return 0;
+}
+
+int
+nm_browse_tags (HEADER *hdr)
+{
+ notmuch_message_t *msg;
+ notmuch_tags_t *tags;
+ unsigned int *count;
+
+ if ( ! browse_tags.db ) {
+ // printf ("error, no db (2)\n\r");
+ return -1;
+ }
+
+ if ( !(msg = get_nm_message(browse_tags.db, hdr)) ) {
+ // printf ("error, no msg\n\r");
+ return -1;
+ }
+ for (tags = notmuch_message_get_tags (msg);
+ notmuch_tags_valid (tags);
+ notmuch_tags_move_to_next (tags)) {
+ const char *tag_str = notmuch_tags_get (tags);
+ count = hash_find(browse_tags.hash, tag_str);
+ if (count) {
+ (*count)++;
+ } else {
+ count = safe_malloc(sizeof(unsigned int));
+ (*count)=1;
+ hash_insert(browse_tags.hash, tag_str, count, 0);
+ if (browse_tags.ntags == browse_tags.tags_size) {
+ browse_tags.tags_size += 20;
+ safe_realloc(&browse_tags.tags, browse_tags.tags_size * sizeof (char*));
+ }
+ browse_tags.tags[browse_tags.ntags++] = safe_strdup(tag_str);
+ // printf ("tags: %d\n\r", browse_tags.ntags);
+ }
+ // printf ("TAG: '%s' %d\n\r", tag_str, (*count));
+ }
+
+ return 0;
+}
diff --git a/mutt_notmuch.h b/mutt_notmuch.h
index 80f50ae..5f87bcf 100644
--- a/mutt_notmuch.h
+++ b/mutt_notmuch.h
@@ -4,6 +4,9 @@
#ifndef _MUTT_NOTMUCH_H_
#define _MUTT_NOTMUCH_H_ 1
+#include "mutt_menu.h"
+#include "browser.h"
+
int nm_read_query(CONTEXT *ctx);
int nm_sync(CONTEXT * ctx, int *index_hint);
int nm_check_database(CONTEXT * ctx, int *index_hint);
@@ -22,6 +25,10 @@ char *nm_get_description(CONTEXT *ctx);
void nm_debug_check(CONTEXT *ctx);
+int nm_browse_tags_init (CONTEXT *);
+int nm_browse_tags (HEADER *);
+int nm_add_tags (MUTTMENU *, struct browser_state *, void(*)(MUTTMENU *, struct
browser_state *, const char *, const char *, const struct stat *, unsigned int, unsigned
int all));
+int nm_browse_tags_finish(CONTEXT *);
/*
* functions usable outside notmuch CONTEXT
*/
_______________________________________________
mutt-kz mailing list
mutt-kz(a)lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/mutt-kz