Introducing a plug-in to handle mailing-lists

This commit is contained in:
Pierre Pronchery 2011-11-20 05:18:53 +00:00
parent 17387f49a0
commit 91cd02a153
8 changed files with 162 additions and 5 deletions

View File

@ -87,6 +87,7 @@ dist:
$(PACKAGE)-$(VERSION)/src/account/rss.c \
$(PACKAGE)-$(VERSION)/src/account/Makefile \
$(PACKAGE)-$(VERSION)/src/account/project.conf \
$(PACKAGE)-$(VERSION)/src/plugins/mailing-lists.c \
$(PACKAGE)-$(VERSION)/src/plugins/search.c \
$(PACKAGE)-$(VERSION)/src/plugins/Makefile \
$(PACKAGE)-$(VERSION)/src/plugins/project.conf \

View File

@ -36,4 +36,10 @@ typedef enum _FolderType
# define FT_LAST FT_FOLDER
# define FT_COUNT (FT_LAST + 1)
/* public */
/* functions */
/* accessors */
char const * folder_get_name(Folder * folder);
#endif /* !DESKTOP_MAILER_FOLDER_H */

View File

@ -25,4 +25,9 @@ typedef struct _Message Message;
typedef struct _AccountMessage AccountMessage;
/* functions */
/* accessors */
char const * message_get_header(Message * message, char const * header);
#endif /* !DESKTOP_MAILER_MESSAGE_H */

View File

@ -35,7 +35,6 @@ void folder_delete(Folder * folder);
/* accessors */
AccountFolder * folder_get_data(Folder * folder);
gboolean folder_get_iter(Folder * folder, GtkTreeIter * iter);
char const * folder_get_name(Folder * folder);
FolderType folder_get_type(Folder * folder);
void folder_set_type(Folder * folder, FolderType type);

View File

@ -34,7 +34,6 @@ void message_delete(Message * message);
/* accessors */
GtkTextBuffer * message_get_body(Message * message);
AccountMessage * message_get_data(Message * message);
char const * message_get_header(Message * message, char const * header);
gboolean message_get_iter(Message * message, GtkTreeIter * iter);
GtkListStore * message_get_store(Message * message);

View File

@ -1,4 +1,4 @@
TARGETS = search.so
TARGETS = mailing-lists.so search.so
PREFIX = /usr/local
DESTDIR =
LIBDIR = $(PREFIX)/lib
@ -19,6 +19,13 @@ INSTALL ?= install
all: $(TARGETS)
mailing-lists_OBJS = mailing-lists.o
mailing-lists_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
mailing-lists_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
mailing-lists.so: $(mailing-lists_OBJS)
$(CCSHARED) -o mailing-lists.so $(mailing-lists_OBJS) $(mailing-lists_LDFLAGS)
search_OBJS = search.o
search_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
search_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
@ -26,20 +33,26 @@ search_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
search.so: $(search_OBJS)
$(CCSHARED) -o search.so $(search_OBJS) $(search_LDFLAGS)
mailing-lists.o: mailing-lists.c ../../include/Mailer.h
$(CC) $(mailing-lists_CFLAGS) -c mailing-lists.c
search.o: search.c ../../include/Mailer.h
$(CC) $(search_CFLAGS) -c search.c
clean:
$(RM) -- $(search_OBJS)
$(RM) -- $(mailing-lists_OBJS) $(search_OBJS)
distclean: clean
$(RM) -- $(TARGETS)
install: $(TARGETS)
$(MKDIR) $(DESTDIR)$(LIBDIR)/Mailer/plugins
$(INSTALL) -m 0644 -- mailing-lists.so $(DESTDIR)$(LIBDIR)/Mailer/plugins/mailing-lists.so
$(MKDIR) $(DESTDIR)$(LIBDIR)/Mailer/plugins
$(INSTALL) -m 0644 -- search.so $(DESTDIR)$(LIBDIR)/Mailer/plugins/search.so
uninstall:
$(RM) -- $(DESTDIR)$(LIBDIR)/Mailer/plugins/mailing-lists.so
$(RM) -- $(DESTDIR)$(LIBDIR)/Mailer/plugins/search.so
.PHONY: all clean distclean install uninstall

126
src/plugins/mailing-lists.c Normal file
View File

@ -0,0 +1,126 @@
/* $Id$ */
/* Copyright (c) 2011 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Desktop Mailer */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <stdlib.h>
#include "Mailer/plugin.h"
/* Mailing-lists */
/* private */
/* types */
typedef struct _MailingLists
{
GtkWidget * vbox;
GtkWidget * folder;
GtkWidget * message;
GtkWidget * name;
} MailingLists;
/* protected */
/* prototypes */
/* plug-in */
static GtkWidget * _ml_init(MailerPlugin * plugin);
static void _ml_destroy(MailerPlugin * plugin);
static void _ml_refresh(MailerPlugin * plugin, Folder * folder,
Message * message);
/* public */
/* variables */
/* plug-in */
MailerPlugin plugin =
{
NULL,
"Mailing-lists",
NULL,
_ml_init,
_ml_destroy,
_ml_refresh,
NULL
};
/* protected */
/* functions */
/* plug-in */
/* ml_init */
static GtkWidget * _ml_init(MailerPlugin * plugin)
{
MailingLists * ml;
if((ml = malloc(sizeof(*ml))) == NULL)
return NULL;
plugin->priv = ml;
ml->vbox = gtk_vbox_new(FALSE, 4);
ml->folder = gtk_label_new("");
/* FIXME set a bold font */
gtk_misc_set_alignment(GTK_MISC(ml->folder), 0.0, 0.5);
gtk_box_pack_start(GTK_BOX(ml->vbox), ml->folder, FALSE, TRUE, 0);
ml->message = gtk_label_new("");
gtk_misc_set_alignment(GTK_MISC(ml->message), 0.0, 0.5);
gtk_box_pack_start(GTK_BOX(ml->vbox), ml->message, FALSE, TRUE, 0);
ml->name = gtk_label_new("");
gtk_misc_set_alignment(GTK_MISC(ml->name), 0.0, 0.5);
gtk_box_pack_start(GTK_BOX(ml->vbox), ml->name, FALSE, TRUE, 0);
return ml->vbox;
}
/* ml_destroy */
static void _ml_destroy(MailerPlugin * plugin)
{
MailingLists * ml = plugin->priv;
free(ml);
}
/* ml_refresh */
static void _ml_refresh(MailerPlugin * plugin, Folder * folder,
Message * message)
{
MailingLists * ml = plugin->priv;
char const * id;
if(folder == NULL)
{
gtk_widget_hide(ml->folder);
gtk_widget_hide(ml->message);
gtk_widget_hide(ml->name);
return;
}
gtk_label_set_text(GTK_LABEL(ml->folder), folder_get_name(folder));
gtk_widget_show(ml->folder);
if(message == NULL)
{
gtk_widget_hide(ml->message);
gtk_widget_hide(ml->name);
return;
}
if((id = message_get_header(message, "List-Id")) == NULL)
{
gtk_label_set_text(GTK_LABEL(ml->message),
"Not a mailing-list");
gtk_widget_show(ml->message);
gtk_widget_hide(ml->name);
return;
}
/* XXX parse and beautify the list's name */
gtk_label_set_text(GTK_LABEL(ml->name), id);
gtk_widget_show(ml->name);
}

View File

@ -1,10 +1,18 @@
targets=search
targets=mailing-lists,search
cppflags_force=-I ../../include
cflags_force=-W -fPIC `pkg-config --cflags gtk+-2.0`
cflags=-Wall -g -O2 -pedantic
ldflags_force=`pkg-config --libs gtk+-2.0`
dist=Makefile
[mailing-lists]
type=plugin
sources=mailing-lists.c
install=$(LIBDIR)/Mailer/plugins
[mailing-lists.c]
depends=../../include/Mailer.h
[search]
type=plugin
sources=search.c