Implementing a plug-in system

This commit is contained in:
Pierre Pronchery 2011-10-23 11:08:45 +00:00
parent 17419b5769
commit 3c0c63c9cd
13 changed files with 531 additions and 121 deletions

View File

@ -53,6 +53,7 @@ dist:
$(PACKAGE)-$(VERSION)/include/Mailer/folder.h \
$(PACKAGE)-$(VERSION)/include/Mailer/mailer.h \
$(PACKAGE)-$(VERSION)/include/Mailer/message.h \
$(PACKAGE)-$(VERSION)/include/Mailer/plugin.h \
$(PACKAGE)-$(VERSION)/include/Mailer/transport.h \
$(PACKAGE)-$(VERSION)/include/Mailer/Makefile \
$(PACKAGE)-$(VERSION)/include/Mailer/project.conf \
@ -86,6 +87,9 @@ dist:
$(PACKAGE)-$(VERSION)/src/account/rss.c \
$(PACKAGE)-$(VERSION)/src/account/Makefile \
$(PACKAGE)-$(VERSION)/src/account/project.conf \
$(PACKAGE)-$(VERSION)/src/plugins/search.c \
$(PACKAGE)-$(VERSION)/src/plugins/Makefile \
$(PACKAGE)-$(VERSION)/src/plugins/project.conf \
$(PACKAGE)-$(VERSION)/Makefile \
$(PACKAGE)-$(VERSION)/COPYING \
$(PACKAGE)-$(VERSION)/config.h \

View File

@ -23,5 +23,6 @@
# include "Mailer/mailer.h"
# include "Mailer/account.h"
# include "Mailer/transport.h"
# include "Mailer/plugin.h"
#endif /* !DESKTOP_MAILER_H */

View File

@ -23,6 +23,8 @@ install:
$(MKDIR) $(DESTDIR)$(PREFIX)/include/Desktop/Mailer
$(INSTALL) -m 0644 -- message.h $(DESTDIR)$(PREFIX)/include/Desktop/Mailer/message.h
$(MKDIR) $(DESTDIR)$(PREFIX)/include/Desktop/Mailer
$(INSTALL) -m 0644 -- plugin.h $(DESTDIR)$(PREFIX)/include/Desktop/Mailer/plugin.h
$(MKDIR) $(DESTDIR)$(PREFIX)/include/Desktop/Mailer
$(INSTALL) -m 0644 -- transport.h $(DESTDIR)$(PREFIX)/include/Desktop/Mailer/transport.h
uninstall:
@ -30,6 +32,7 @@ uninstall:
$(RM) -- $(DESTDIR)$(PREFIX)/include/Desktop/Mailer/folder.h
$(RM) -- $(DESTDIR)$(PREFIX)/include/Desktop/Mailer/mailer.h
$(RM) -- $(DESTDIR)$(PREFIX)/include/Desktop/Mailer/message.h
$(RM) -- $(DESTDIR)$(PREFIX)/include/Desktop/Mailer/plugin.h
$(RM) -- $(DESTDIR)$(PREFIX)/include/Desktop/Mailer/transport.h
.PHONY: all clean distclean install uninstall

42
include/Mailer/plugin.h Normal file
View File

@ -0,0 +1,42 @@
/* $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/>. */
#ifndef DESKTOP_MAILER_PLUGIN_H
# define DESKTOP_MAILER_PLUGIN_H
/* MailerPlugin */
/* types */
typedef struct _MailerPluginHelper
{
Mailer * mailer;
int (*error)(Mailer * mailer, char const * message, int ret);
} MailerPluginHelper;
typedef struct _MailerPlugin MailerPlugin;
struct _MailerPlugin
{
MailerPluginHelper * helper;
char const * name;
char const * icon;
int (*init)(MailerPlugin * plugin);
int (*destroy)(MailerPlugin * plugin);
void * priv;
};
#endif /* !DESKTOP_MAILER_PLUGIN_H */

View File

@ -1,4 +1,4 @@
includes=account.h,folder.h,mailer.h,message.h,transport.h
includes=account.h,folder.h,mailer.h,message.h,plugin.h,transport.h
dist=Makefile
[account.h]
@ -13,5 +13,8 @@ install=$(PREFIX)/include/Desktop/Mailer
[message.h]
install=$(PREFIX)/include/Desktop/Mailer
[plugin.h]
install=$(PREFIX)/include/Desktop/Mailer
[transport.h]
install=$(PREFIX)/include/Desktop/Mailer

170
po/fr.po
View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Mailer 0.0.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2011-09-29 00:11+0200\n"
"POT-Creation-Date: 2011-10-23 13:06+0200\n"
"PO-Revision-Date: 2010-10-02 23:25+0200\n"
"Last-Translator: Pierre Pronchery <khorben@defora.org>\n"
"Language-Team: French\n"
@ -28,11 +28,11 @@ msgstr "_Enregistrer"
msgid "Save _as..."
msgstr "Enregistrer _sous..."
#: ../src/compose.c:119 ../src/mailer.c:130
#: ../src/compose.c:119 ../src/mailer.c:146
msgid "_Print"
msgstr "_Imprimer"
#: ../src/compose.c:120 ../src/mailer.c:131
#: ../src/compose.c:120 ../src/mailer.c:147
msgid "Print pre_view"
msgstr "_Aperçu avant impression"
@ -52,7 +52,7 @@ msgstr "_Annuler"
msgid "_Redo"
msgstr "_Refaire"
#: ../src/compose.c:136 ../src/mailer.c:141
#: ../src/compose.c:136 ../src/mailer.c:157
msgid "_Cut"
msgstr "Co_uper"
@ -60,7 +60,7 @@ msgstr "Co_uper"
msgid "_Copy"
msgstr "_Copier"
#: ../src/compose.c:140 ../src/mailer.c:145
#: ../src/compose.c:140 ../src/mailer.c:161
msgid "_Paste"
msgstr "C_oller"
@ -68,7 +68,7 @@ msgstr "C_oller"
msgid "_Select all"
msgstr "Sélectionner _tout"
#: ../src/compose.c:150 ../src/mailer.c:155
#: ../src/compose.c:150 ../src/mailer.c:171
msgid "_Unselect all"
msgstr "Tout _désélectionner"
@ -76,16 +76,16 @@ msgstr "Tout _désélectionner"
msgid "Add field"
msgstr "Ajouter un champ"
#: ../src/compose.c:165 ../src/compose.c:167 ../src/mailer.c:182
#: ../src/mailer.c:184
#: ../src/compose.c:165 ../src/compose.c:167 ../src/mailer.c:198
#: ../src/mailer.c:200
msgid "_About"
msgstr "_A propos"
#: ../src/compose.c:174 ../src/mailer.c:191
#: ../src/compose.c:174 ../src/mailer.c:207
msgid "_File"
msgstr "_Fichier"
#: ../src/compose.c:175 ../src/mailer.c:192
#: ../src/compose.c:175 ../src/mailer.c:208
msgid "_Edit"
msgstr "_Edition"
@ -93,7 +93,7 @@ msgstr "_Edition"
msgid "_View"
msgstr "_Vue"
#: ../src/compose.c:177 ../src/mailer.c:194
#: ../src/compose.c:177 ../src/mailer.c:210
msgid "_Help"
msgstr "_Aide"
@ -161,8 +161,8 @@ msgstr "Sujet: "
msgid "Attach file..."
msgstr "Joindre un fichier..."
#: ../src/compose.c:674 ../src/compose.c:678 ../src/mailer.c:845
#: ../src/mailer.c:849
#: ../src/compose.c:674 ../src/compose.c:678 ../src/mailer.c:908
#: ../src/mailer.c:912
msgid "Error"
msgstr "Erreur"
@ -206,147 +206,147 @@ msgstr "Envoyés"
msgid "Trash"
msgstr "Corbeille"
#: ../src/mailer.c:106
#: ../src/mailer.c:122
msgid "New account"
msgstr "Nouveau compte"
#: ../src/mailer.c:106
#: ../src/mailer.c:122
msgid "Account settings"
msgstr "Paramètres du compte"
#: ../src/mailer.c:106
#: ../src/mailer.c:122
msgid "Account confirmation"
msgstr "Confirmation du compte"
#: ../src/mailer.c:124
#: ../src/mailer.c:140
msgid "_New mail"
msgstr "_Nouveau message"
#: ../src/mailer.c:127 ../src/mailer.c:204
#: ../src/mailer.c:143 ../src/mailer.c:220
msgid "Send / Receive"
msgstr "Envoyer / Recevoir"
#: ../src/mailer.c:134
#: ../src/mailer.c:150
msgid "_Quit"
msgstr "_Quitter"
#: ../src/mailer.c:143
#: ../src/mailer.c:159
msgid "Cop_y"
msgstr "_Copier"
#: ../src/mailer.c:148
#: ../src/mailer.c:164
msgid "Select _all"
msgstr "Sélectionner _tout"
#: ../src/mailer.c:157
#: ../src/mailer.c:173
msgid "_Preferences"
msgstr "_Préférences"
#: ../src/mailer.c:164
#: ../src/mailer.c:180
msgid "_Reply"
msgstr "_Répondre"
#: ../src/mailer.c:166
#: ../src/mailer.c:182
msgid "Reply to _all"
msgstr "Répondre à _tous"
#: ../src/mailer.c:168
#: ../src/mailer.c:184
msgid "_Forward"
msgstr "_Transmettre"
#: ../src/mailer.c:171
#: ../src/mailer.c:187
msgid "_Delete"
msgstr "_Supprimer"
#: ../src/mailer.c:174
#: ../src/mailer.c:190
msgid "_View source"
msgstr "Afficher la _source"
#: ../src/mailer.c:193
#: ../src/mailer.c:209
msgid "_Message"
msgstr "_Message"
#: ../src/mailer.c:201 ../src/mailer.c:227 ../src/mailer.c:241
#: ../src/mailer.c:217 ../src/mailer.c:243 ../src/mailer.c:257
msgid "New mail"
msgstr "Nouveau message"
#: ../src/mailer.c:205
#: ../src/mailer.c:221
msgid "Stop"
msgstr "Stop"
#: ../src/mailer.c:208 ../src/mailer.c:230 ../src/mailer.c:244
#: ../src/mailer.c:224 ../src/mailer.c:246 ../src/mailer.c:260
msgid "Reply"
msgstr "Répondre"
#: ../src/mailer.c:209 ../src/mailer.c:231 ../src/mailer.c:245
#: ../src/mailer.c:225 ../src/mailer.c:247 ../src/mailer.c:261
msgid "Reply to all"
msgstr "Répondre à tous"
#: ../src/mailer.c:211 ../src/mailer.c:233 ../src/mailer.c:247
#: ../src/mailer.c:227 ../src/mailer.c:249 ../src/mailer.c:263
msgid "Forward"
msgstr "Transmettre"
#: ../src/mailer.c:214 ../src/mailer.c:235 ../src/mailer.c:249
#: ../src/mailer.c:230 ../src/mailer.c:251 ../src/mailer.c:265
msgid "Delete"
msgstr "Supprimer"
#: ../src/mailer.c:215 ../src/mailer.c:250
#: ../src/mailer.c:231 ../src/mailer.c:266
msgid "Print"
msgstr "Imprimer"
#: ../src/mailer.c:218
#: ../src/mailer.c:234
msgid "Preferences"
msgstr "Préférences"
#: ../src/mailer.c:332
#: ../src/mailer.c:355
msgid "Mailer"
msgstr "Mailer"
#: ../src/mailer.c:335 ../src/mailer.c:517
#: ../src/mailer.c:358 ../src/mailer.c:544
msgid "Folders"
msgstr "Dossiers"
#: ../src/mailer.c:386
#: ../src/mailer.c:413
msgid "Message list"
msgstr "Liste des messages"
#: ../src/mailer.c:416
#: ../src/mailer.c:443
msgid "Message"
msgstr "Message"
#: ../src/mailer.c:582
#: ../src/mailer.c:609
msgid "Subject"
msgstr "Sujet"
#: ../src/mailer.c:584
#: ../src/mailer.c:611
msgid "From"
msgstr "De"
#: ../src/mailer.c:586
#: ../src/mailer.c:613
msgid "To"
msgstr "À"
#: ../src/mailer.c:588
#: ../src/mailer.c:615
msgid "Date"
msgstr "Date"
#: ../src/mailer.c:703
#: ../src/mailer.c:730
msgid " Subject: "
msgstr " Sujet: "
#: ../src/mailer.c:704
#: ../src/mailer.c:731
msgid " From: "
msgstr " De: "
#: ../src/mailer.c:705
#: ../src/mailer.c:732
msgid " To: "
msgstr " À: "
#: ../src/mailer.c:706
#: ../src/mailer.c:733
msgid " Date: "
msgstr " Date: "
#: ../src/mailer.c:977
#: ../src/mailer.c:1040
msgid ""
"The messages selected will be deleted.\n"
"Continue?"
@ -354,140 +354,144 @@ msgstr ""
"Les messages sélectionnés vont être effacés.\n"
"Continuer?"
#: ../src/mailer.c:1085
#: ../src/mailer.c:1183
msgid "Mailer - View source"
msgstr "Mailer - Source"
#: ../src/mailer.c:1160
#: ../src/mailer.c:1258
msgid "Re: "
msgstr "Re: "
#: ../src/mailer.c:1355
#: ../src/mailer.c:1450
msgid "Mailer preferences"
msgstr "Préférences de Mailer"
#: ../src/mailer.c:1400
#: ../src/mailer.c:1521 ../src/mailer.c:1604
msgid "Enabled"
msgstr "Actif"
#: ../src/mailer.c:1404
#: ../src/mailer.c:1525 ../src/mailer.c:1610
msgid "Name"
msgstr "Nom"
#: ../src/mailer.c:1408
#: ../src/mailer.c:1529
msgid "Type"
msgstr "Type"
#: ../src/mailer.c:1432
#: ../src/mailer.c:1553
msgid "Accounts"
msgstr "Comptes"
#: ../src/mailer.c:1439
#: ../src/mailer.c:1568
msgid "Messages font:"
msgstr "Police des messages:"
#: ../src/mailer.c:1449
#: ../src/mailer.c:1578
msgid "Display"
msgstr "Affichage"
#: ../src/mailer.c:1527
#: ../src/mailer.c:1621
msgid "Plug-ins"
msgstr "Greffons"
#: ../src/mailer.c:1744
msgid "No account plug-in available"
msgstr "Aucun greffon de compte disponible"
#: ../src/mailer.c:1682 ../src/mailer.c:1970
#: ../src/mailer.c:1899 ../src/mailer.c:2187
msgid "Account name"
msgstr "Nom du compte"
#: ../src/mailer.c:1689
#: ../src/mailer.c:1906
msgid "Your name"
msgstr "Votre nom"
#: ../src/mailer.c:1696
#: ../src/mailer.c:1913
msgid "e-mail address"
msgstr "Adresse e-mail"
#: ../src/mailer.c:1703
#: ../src/mailer.c:1920
msgid "Type of account"
msgstr "Type de compte"
#: ../src/mailer.c:1859
#: ../src/mailer.c:2076
msgid "Choose file"
msgstr "Choisir un fichier"
#: ../src/mailer.c:2041
#: ../src/mailer.c:2258
msgid "hidden"
msgstr "masqué"
#: ../src/mailer.c:2075
#: ../src/mailer.c:2292
msgid "Yes"
msgstr "Oui"
#: ../src/mailer.c:2075
#: ../src/mailer.c:2292
msgid "No"
msgstr "Non"
#: ../src/mailer.c:2103
#: ../src/mailer.c:2320
msgid "Account type "
msgstr "Type de compte "
#: ../src/mailer.c:2104
#: ../src/mailer.c:2321
msgid " active\n"
msgstr " actif\n"
#: ../src/mailer.c:2166
#: ../src/mailer.c:2383
msgid "Edit account: "
msgstr "Modification du compte: "
#: ../src/mailer.c:2188
#: ../src/mailer.c:2405
msgid "Account name:"
msgstr "Nom du compte :"
#: ../src/mailer.c:2197
#: ../src/mailer.c:2414
msgid "Identity:"
msgstr "Identité :"
#: ../src/mailer.c:2202
#: ../src/mailer.c:2419
msgid "Name:"
msgstr "Nom :"
#: ../src/mailer.c:2213
#: ../src/mailer.c:2430
msgid "Address:"
msgstr "Adresse :"
#: ../src/mailer.c:2224
#: ../src/mailer.c:2441
msgid "Organization:"
msgstr "Organisation :"
#: ../src/mailer.c:2237
#: ../src/mailer.c:2454
msgid "Account"
msgstr "Compte"
#: ../src/mailer.c:2242
#: ../src/mailer.c:2459
msgid "Settings"
msgstr "Paramètres"
#: ../src/mailer.c:2296
#: ../src/mailer.c:2513
msgid "An error occured while saving preferences"
msgstr "Une erreur est survenue pendant la sauvegarde des préférences"
#: ../src/mailer.c:2474 ../src/mailer.c:2478
#: ../src/mailer.c:2725 ../src/mailer.c:2729
msgid "Question"
msgstr "Question"
#: ../src/mailer.c:2528
#: ../src/mailer.c:2779
#, c-format
msgid "%s/%s: %d %s"
msgstr "%s/%s: %d %s"
#: ../src/mailer.c:2531
#: ../src/mailer.c:2782
msgid "messages"
msgstr "messages"
#: ../src/mailer.c:2531
#: ../src/mailer.c:2782
msgid "message"
msgstr "message"
#: ../src/mailer.c:2534
#: ../src/mailer.c:2785
msgid "Ready"
msgstr "Prêt"

View File

@ -1,4 +1,4 @@
SUBDIRS = account
SUBDIRS = account plugins
TARGETS = compose mailer
PREFIX = /usr/local
DESTDIR =

View File

@ -51,6 +51,17 @@
/* Mailer */
/* private */
/* types */
enum _MailerPluginColumn
{
MPC_NAME = 0,
MPC_NAME_DISPLAY,
MPC_PLUGIN,
MPC_MAILERPLUGIN,
MPC_WIDGET
};
#define MPC_LAST MPC_WIDGET
#define MPC_COUNT (MPC_LAST + 1)
struct _Mailer
{
Account ** available; /* XXX consider using another data type */
@ -89,10 +100,15 @@ struct _Mailer
gint statusbar_id;
/* about */
GtkWidget * ab_window;
/* plug-ins */
GtkListStore * pl_store;
MailerPluginHelper pl_helper;
/* preferences */
GtkWidget * pr_window;
GtkWidget * pr_accounts;
GtkWidget * pr_messages_font;
GtkListStore * pr_plugins_store;
GtkWidget * pr_plugins;
};
/* FIXME use a more elegant model with an AccountMessage directly */
@ -255,6 +271,7 @@ static DesktopToolbar _mailer_bo_toolbar[] =
/* prototypes */
/* accessors */
static gboolean _mailer_plugin_is_enabled(Mailer * mailer, char const * plugin);
static char const * _mailer_get_font(Mailer * mailer);
static char * _mailer_get_config_filename(void);
@ -289,7 +306,7 @@ static int _mailer_config_load_account(Mailer * mailer, char const * name)
/* public */
/* functions */
/* mailer_new */
static int _new_plugins(Mailer * mailer);
static int _new_accounts(Mailer * mailer);
static GtkWidget * _new_folders_view(Mailer * mailer);
static void _on_folders_changed(GtkTreeSelection * selection, gpointer data);
static GtkWidget * _new_headers_view(Mailer * mailer);
@ -299,7 +316,9 @@ static GtkTreeViewColumn * _headers_view_column_pixbuf(GtkTreeView * view,
static GtkTreeViewColumn * _headers_view_column_text(GtkTreeView * view,
char const * title, int id, int sortid, int boldid);
static void _on_headers_changed(GtkTreeSelection * selection, gpointer data);
static gboolean _new_config_load(gpointer data);
static gboolean _new_idle(gpointer data);
static void _idle_config_load(Mailer * mailer);
static void _idle_plugins_load(Mailer * mailer);
Mailer * mailer_new(void)
{
@ -318,11 +337,15 @@ Mailer * mailer_new(void)
error_print("mailer");
return NULL;
}
_new_plugins(mailer);
/* accounts */
_new_accounts(mailer);
mailer->account = NULL;
mailer->account_cnt = 0;
mailer->account_cur = NULL;
mailer->folder_cur = NULL;
/* plug-ins */
mailer->pl_helper.mailer = mailer;
mailer->pl_helper.error = mailer_error;
/* widgets */
group = gtk_accel_group_new();
mailer->fo_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
@ -372,6 +395,10 @@ Mailer * mailer_new(void)
gtk_box_pack_start(GTK_BOX(vbox), mailer->statusbar, FALSE, TRUE, 0);
gtk_container_add(GTK_CONTAINER(mailer->fo_window), vbox);
gtk_widget_show_all(vbox);
/* plug-ins */
mailer->pl_store = gtk_list_store_new(MPC_COUNT, G_TYPE_STRING,
G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_POINTER,
G_TYPE_POINTER);
/* messages list */
#ifndef EMBEDDED
mailer->he_window = mailer->fo_window;
@ -448,11 +475,11 @@ Mailer * mailer_new(void)
_mailer_update_status(mailer);
gtk_widget_show(mailer->fo_window);
/* load configuration */
mailer->source = g_idle_add(_new_config_load, mailer);
mailer->source = g_idle_add(_new_idle, mailer);
return mailer;
}
static int _new_plugins(Mailer * mailer)
static int _new_accounts(Mailer * mailer)
{
int ret = 0;
char * dirname;
@ -744,9 +771,17 @@ static GtkWidget * _new_headers(Mailer * mailer)
return vbox;
}
static gboolean _new_config_load(gpointer data)
static gboolean _new_idle(gpointer data)
{
Mailer * mailer = data;
_idle_config_load(mailer);
_idle_plugins_load(mailer);
return FALSE;
}
static void _idle_config_load(Mailer * mailer)
{
char * filename;
char const * value;
PangoFontDescription * font;
@ -755,9 +790,9 @@ static gboolean _new_config_load(gpointer data)
mailer->source = 0;
if((mailer->config = config_new()) == NULL)
return FALSE;
return;
if((filename = _mailer_get_config_filename()) == NULL)
return FALSE;
return;
if(config_load(mailer->config, filename) != 0)
mailer_error(NULL, error_get(), 1);
free(filename);
@ -767,9 +802,9 @@ static gboolean _new_config_load(gpointer data)
pango_font_description_free(font);
if((value = config_get(mailer->config, NULL, "accounts")) == NULL
|| value[0] == '\0')
return FALSE;
return;
if((p = strdup(value)) == NULL)
return FALSE;
return;
value = p;
for(q = p; *q != '\0'; q++)
{
@ -782,7 +817,34 @@ static gboolean _new_config_load(gpointer data)
if(value[0] != '\0')
_mailer_config_load_account(mailer, value);
free(p);
return FALSE;
}
static void _idle_plugins_load(Mailer * mailer)
{
char const * plugins;
char * p;
char * q;
size_t i;
if((plugins = config_get(mailer->config, NULL, "plugins")) == NULL)
return;
if((p = strdup(plugins)) == NULL)
return; /* XXX report error */
for(q = p, i = 0;;)
{
if(q[i] == '\0')
{
mailer_load(mailer, q);
break;
}
if(q[i++] != ',')
continue;
q[i - 1] = '\0';
mailer_load(mailer, q);
q += i;
i = 0;
}
free(p);
}
@ -799,6 +861,7 @@ void mailer_delete(Mailer * mailer)
for(i = 0; i < mailer->account_cnt; i++)
account_delete(mailer->account[i]);
free(mailer->account);
g_object_unref(mailer->pl_store);
object_delete(mailer);
}
@ -1053,6 +1116,41 @@ void mailer_cut(Mailer * mailer)
}
/* mailer_load */
int mailer_load(Mailer * mailer, char const * plugin)
{
Plugin * p;
MailerPlugin * mp;
GtkWidget * widget;
GtkTreeIter iter;
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, plugin);
#endif
if(_mailer_plugin_is_enabled(mailer, plugin))
return 0;
if((p = plugin_new(LIBDIR, PACKAGE, "plugins", plugin)) == NULL)
return -mailer_error(NULL, error_get(), 1);
if((mp = plugin_lookup(p, "plugin")) == NULL)
{
plugin_delete(p);
return -mailer_error(NULL, error_get(), 1);
}
mp->helper = &mailer->pl_helper;
if(mp->init == NULL || (widget = mp->init(mp)) == NULL)
{
plugin_delete(p);
return -mailer_error(NULL, error_get(), 1);
}
gtk_widget_hide(widget);
gtk_list_store_append(mailer->pl_store, &iter);
gtk_list_store_set(mailer->pl_store, &iter, MPC_NAME, plugin,
MPC_NAME_DISPLAY, mp->name, MPC_PLUGIN, p,
MPC_MAILERPLUGIN, mp, MPC_WIDGET, widget, -1);
return 0;
}
/* mailer_open_selected_source */
static void _open_selected_source(Mailer * mailer, GtkTreeModel * model,
GtkTreeIter * iter);
@ -1262,6 +1360,7 @@ void mailer_show_about(Mailer * mailer, gboolean show)
mailer->fo_window));
desktop_about_dialog_set_name(dialog, PACKAGE);
desktop_about_dialog_set_version(dialog, VERSION);
desktop_about_dialog_set_website(dialog, "http://www.defora.org/");
desktop_about_dialog_set_authors(dialog, _authors);
desktop_about_dialog_set_copyright(dialog, _copyright);
desktop_about_dialog_set_logo_icon_name(dialog, "mailer");
@ -1311,7 +1410,11 @@ typedef enum _AccountColumn
#define AC_LAST AC_WIDGET
#define AC_COUNT (AC_LAST + 1)
static void _preferences_accounts(Mailer * mailer, GtkWidget * notebook);
static void _preferences_display(Mailer * mailer, GtkWidget * notebook);
static void _preferences_plugins(Mailer * mailer, GtkWidget * notebook);
static void _preferences_set(Mailer * mailer);
static void _preferences_set_plugins(Mailer * mailer);
/* callbacks */
static gboolean _on_preferences_closex(gpointer data);
@ -1327,21 +1430,13 @@ static void _on_preferences_ok(gpointer data);
static int _preferences_ok_accounts(Mailer * mailer);
static int _preferences_ok_display(Mailer * mailer);
static int _preferences_ok_save(Mailer * mailer);
static void _preferences_on_plugin_toggled(GtkCellRendererToggle * renderer,
char * path, gpointer data);
void mailer_show_preferences(Mailer * mailer, gboolean show)
{
GtkWidget * vbox;
GtkWidget * notebook;
GtkWidget * hbox;
GtkWidget * vbox2;
GtkWidget * vbox3;
GtkWidget * widget;
GtkSizeGroup * group;
GtkListStore * store;
size_t i;
Account * ac;
GtkTreeIter iter;
GtkCellRenderer * renderer;
if(mailer->pr_window != NULL)
{
@ -1368,6 +1463,32 @@ void mailer_show_preferences(Mailer * mailer, gboolean show)
#endif
notebook = gtk_notebook_new();
/* accounts */
_preferences_accounts(mailer, notebook);
/* display */
_preferences_display(mailer, notebook);
/* plug-ins */
_preferences_plugins(mailer, notebook);
gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
_preferences_set(mailer);
gtk_widget_show_all(vbox);
if(show)
gtk_widget_show(mailer->pr_window);
else
gtk_widget_hide(mailer->pr_window);
}
static void _preferences_accounts(Mailer * mailer, GtkWidget * notebook)
{
GtkWidget * vbox2;
GtkWidget * vbox3;
GtkWidget * hbox;
GtkWidget * widget;
GtkListStore * store;
GtkCellRenderer * renderer;
size_t i;
Account * ac;
GtkTreeIter iter;
vbox2 = gtk_vbox_new(FALSE, 4);
gtk_container_set_border_width(GTK_CONTAINER(vbox2), 4);
hbox = gtk_hbox_new(FALSE, 4);
@ -1430,10 +1551,18 @@ void mailer_show_preferences(Mailer * mailer, gboolean show)
gtk_box_pack_start(GTK_BOX(vbox2), hbox, TRUE, TRUE, 0);
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox2, gtk_label_new(
_("Accounts")));
/* display */
}
static void _preferences_display(Mailer * mailer, GtkWidget * notebook)
{
GtkSizeGroup * group;
GtkWidget * vbox2;
GtkWidget * hbox;
GtkWidget * widget;
group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
vbox2 = gtk_vbox_new(FALSE, 4);
gtk_container_set_border_width(GTK_CONTAINER(vbox2), 4);
group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
/* default font */
hbox = gtk_hbox_new(FALSE, 4);
widget = gtk_label_new(_("Messages font:"));
@ -1447,13 +1576,49 @@ void mailer_show_preferences(Mailer * mailer, gboolean show)
gtk_box_pack_start(GTK_BOX(vbox2), hbox, FALSE, FALSE, 0);
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox2, gtk_label_new(
_("Display")));
gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
_preferences_set(mailer);
gtk_widget_show_all(vbox);
if(show)
gtk_widget_show(mailer->pr_window);
else
gtk_widget_hide(mailer->pr_window);
}
static void _preferences_plugins(Mailer * mailer, GtkWidget * notebook)
{
GtkWidget * vbox;
GtkWidget * widget;
GtkCellRenderer * renderer;
GtkTreeViewColumn * column;
vbox = gtk_vbox_new(FALSE, 4);
gtk_container_set_border_width(GTK_CONTAINER(vbox), 4);
widget = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(widget),
GTK_SHADOW_IN);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(widget),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
mailer->pr_plugins_store = gtk_list_store_new(4, G_TYPE_STRING,
G_TYPE_BOOLEAN, GDK_TYPE_PIXBUF, G_TYPE_STRING);
mailer->pr_plugins = gtk_tree_view_new_with_model(GTK_TREE_MODEL(
mailer->pr_plugins_store));
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(mailer->pr_plugins),
FALSE);
renderer = gtk_cell_renderer_toggle_new();
g_signal_connect(renderer, "toggled", G_CALLBACK(
_preferences_on_plugin_toggled), mailer);
column = gtk_tree_view_column_new_with_attributes(_("Enabled"),
renderer, "active", 1, NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(mailer->pr_plugins), column);
column = gtk_tree_view_column_new_with_attributes(NULL,
gtk_cell_renderer_pixbuf_new(), "pixbuf", 2, NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(mailer->pr_plugins), column);
column = gtk_tree_view_column_new_with_attributes(_("Name"),
gtk_cell_renderer_text_new(), "text", 3, NULL);
gtk_tree_view_column_set_sort_column_id(column, 3);
gtk_tree_view_append_column(GTK_TREE_VIEW(mailer->pr_plugins), column);
gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(
mailer->pr_plugins_store), 3,
GTK_SORT_ASCENDING);
gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(mailer->pr_plugins), TRUE);
gtk_container_add(GTK_CONTAINER(widget), mailer->pr_plugins);
gtk_box_pack_start(GTK_BOX(vbox), widget, TRUE, TRUE, 0);
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox, gtk_label_new(
_("Plug-ins")));
}
static void _preferences_set(Mailer * mailer)
@ -1463,6 +1628,58 @@ static void _preferences_set(Mailer * mailer)
p = _mailer_get_font(mailer);
gtk_font_button_set_font_name(GTK_FONT_BUTTON(mailer->pr_messages_font),
p);
_preferences_set_plugins(mailer);
}
static void _preferences_set_plugins(Mailer * mailer)
{
DIR * dir;
struct dirent * de;
GtkIconTheme * theme;
char const ext[] = ".so";
size_t len;
Plugin * p;
MailerPlugin * mp;
GtkTreeIter iter;
gboolean enabled;
GdkPixbuf * pixbuf;
gtk_list_store_clear(mailer->pr_plugins_store);
if((dir = opendir(LIBDIR "/" PACKAGE "/plugins")) == NULL)
return;
theme = gtk_icon_theme_get_default();
while((de = readdir(dir)) != NULL)
{
if((len = strlen(de->d_name)) < sizeof(ext))
continue;
if(strcmp(&de->d_name[len - sizeof(ext) + 1], ext) != 0)
continue;
de->d_name[len - sizeof(ext) + 1] = '\0';
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s() \"%s\"\n", __func__, de->d_name);
#endif
if((p = plugin_new(LIBDIR, PACKAGE, "plugins", de->d_name))
== NULL)
continue;
if((mp = plugin_lookup(p, "plugin")) == NULL)
{
plugin_delete(p);
continue;
}
enabled = _mailer_plugin_is_enabled(mailer, de->d_name);
if(mp->icon == NULL)
pixbuf = gtk_icon_theme_load_icon(theme,
"gnome-settings", 24, 0, NULL);
else
pixbuf = gtk_icon_theme_load_icon(theme, mp->icon, 24,
0, NULL);
gtk_list_store_append(mailer->pr_plugins_store, &iter);
gtk_list_store_set(mailer->pr_plugins_store, &iter,
0, de->d_name, 1, enabled, 2, pixbuf,
3, mp->name, -1);
plugin_delete(p);
}
closedir(dir);
}
static gboolean _on_preferences_closex(gpointer data)
@ -2386,6 +2603,18 @@ static int _preferences_ok_save(Mailer * mailer)
return ret;
}
static void _preferences_on_plugin_toggled(GtkCellRendererToggle * renderer,
char * path, gpointer data)
{
Mailer * mailer = data;
GtkTreeIter iter;
gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(
mailer->pr_plugins_store), &iter, path);
gtk_list_store_set(mailer->pr_plugins_store, &iter, 1,
!gtk_cell_renderer_toggle_get_active(renderer), -1);
}
/* mailer_unselect_all */
void mailer_unselect_all(Mailer * mailer)
@ -2433,6 +2662,28 @@ static char * _mailer_get_config_filename(void)
}
/* mailer_plugin_is_enabled */
static gboolean _mailer_plugin_is_enabled(Mailer * mailer, char const * plugin)
{
GtkTreeModel * model = GTK_TREE_MODEL(mailer->pl_store);
GtkTreeIter iter;
gchar * p;
gboolean valid;
int res;
for(valid = gtk_tree_model_get_iter_first(model, &iter); valid == TRUE;
valid = gtk_tree_model_iter_next(model, &iter))
{
gtk_tree_model_get(model, &iter, MPC_NAME, &p, -1);
res = strcmp(p, plugin);
g_free(p);
if(res == 0)
return TRUE;
}
return FALSE;
}
/* mailer_get_font */
static char const * _mailer_get_font(Mailer * mailer)
{

View File

@ -60,6 +60,7 @@ void mailer_set_status(Mailer * mailer, char const * status);
/* useful */
int mailer_error(Mailer * mailer, char const * message, int ret);
/* accounts */
int mailer_account_add(Mailer * mailer, Account * account);
#if 0 /* FIXME deprecate? */
int mailer_account_disable(Mailer * mailer, Account * account);
@ -68,6 +69,12 @@ int mailer_account_enable(Mailer * mailer, Account * account);
/* FIXME implement
int mailer_account_remove(Mailer * mailer, Account * account); */
/* plug-ins */
int mailer_load(Mailer * mailer, char const * plugin);
void mailer_compose(Mailer * mailer);
/* selection */
void mailer_delete_selected(Mailer * mailer);
void mailer_open_selected_source(Mailer * mailer);
@ -75,18 +82,18 @@ void mailer_open_selected_source(Mailer * mailer);
void mailer_reply_selected(Mailer * mailer);
void mailer_reply_selected_to_all(Mailer * mailer);
void mailer_select_all(Mailer * mailer);
void mailer_unselect_all(Mailer * mailer);
/* clipboard */
void mailer_cut(Mailer * mailer);
void mailer_copy(Mailer * mailer);
void mailer_paste(Mailer * mailer);
void mailer_select_all(Mailer * mailer);
void mailer_unselect_all(Mailer * mailer);
/* interface */
void mailer_show_about(Mailer * mailer, gboolean show);
void mailer_show_body(Mailer * mailer, gboolean show);
void mailer_show_headers(Mailer * mailer, gboolean show);
void mailer_show_preferences(Mailer * mailer, gboolean show);
void mailer_compose(Mailer * mailer);
#endif /* !MAILER_SRC_MAILER_H */

45
src/plugins/Makefile Normal file
View File

@ -0,0 +1,45 @@
TARGETS = search.so
PREFIX = /usr/local
DESTDIR =
LIBDIR = $(PREFIX)/lib
CC ?= cc
CPPFLAGSF= -I ../../include
CPPFLAGS?=
CFLAGSF = -W -fPIC `pkg-config --cflags glib-2.0`
CFLAGS = -Wall -g -O2 -pedantic
LDFLAGSF= `pkg-config --libs glib-2.0`
AR ?= ar
RANLIB ?= ranlib
CCSHARED?= $(CC) -shared
RM ?= rm -f
LN ?= ln -f
MKDIR ?= mkdir -p
INSTALL ?= install
all: $(TARGETS)
search_OBJS = search.o
search_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
search_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) `pkg-config --libs gtk+-2.0`
search.so: $(search_OBJS)
$(CCSHARED) -o search.so $(search_OBJS) $(search_LDFLAGS)
search.o: search.c ../../include/Mailer.h
$(CC) $(search_CFLAGS) `pkg-config --cflags gtk+-2.0` -c search.c
clean:
$(RM) -- $(search_OBJS)
distclean: clean
$(RM) -- $(TARGETS)
install: $(TARGETS)
$(MKDIR) $(DESTDIR)$(LIBDIR)/Mailer/plugins
$(INSTALL) -m 0644 -- search.so $(DESTDIR)$(LIBDIR)/Mailer/plugins/search.so
uninstall:
$(RM) -- $(DESTDIR)$(LIBDIR)/Mailer/plugins/search.so
.PHONY: all clean distclean install uninstall

16
src/plugins/project.conf Normal file
View File

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

34
src/plugins/search.c Normal file
View File

@ -0,0 +1,34 @@
/* $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.h"
/* Sarch */
/* protected */
/* variables */
/* plug-in */
MailerPlugin plugin =
{
NULL,
"Search",
"search",
NULL,
NULL,
NULL
};

View File

@ -1,4 +1,4 @@
subdirs=account
subdirs=account,plugins
targets=compose,mailer
cppflags_force=-I ../include
#cppflags=-D EMBEDDED