/*
* Boiler Plate Plugin - Edit as desired....
*
*
* 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; either version 2
* of the License, or (at your option) any later version.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#define PLUGIN_ID "french"
#define PLUGIN_STATIC_NAME "french"
#define PLUGIN_NAME "french"
#define PLUGIN_SUMMARY "Google translator"
#define PLUGIN_DESCRIPTION "On the fly google translator. /fr <word> to translate."
#define AUTHOR_NAME "Yarek T"
#define WEBSITE_NAME ""
#include <gtk/gtk.h>
#include "internal.h"
#include "debug.h"
#include "version.h"
#include <cmds.h>
#include "util.h"
#include "connection.h"
#include "string.h"
#include "gtkaccount.h"
#include "gtkblist.h"
#include "gtkconv.h"
#include "gtkplugin.h"
static PurpleCmdId fr_cmd_id = 0; //register commands /fr
gchar it[100]; //allocated globaly because of
//dynamic allocation problems
static void
fetch_page(PurpleUtilFetchUrlData *url_data, PurpleConversation *conv,
const gchar *rawpage, size_t len, const gchar *error_message)
{
/* XXX: make sure that 'conv' has not been closed */
char front[] = "<div id=result_box dir=ltr>"; //the start of the string we want
char back[] = "</div>"; //the end of the string we want
char * start = strstr(rawpage, front); //search the heap for the string
char * end = strstr(start, back); //find out where our string ends
int length = end - start + 1; //find out how long is our string
purple_debug_info("FR:ENPTY", "%s", it); //Empty var "it" to check what garbige is in it
strncpy(it, start, MIN(sizeof(it), length)); //copy from string it get what we want
if(conv->type == PURPLE_CONV_TYPE_IM)
purple_conv_im_send(PURPLE_CONV_IM(conv), msg);
else if(conv->type == PURPLE_CONV_TYPE_CHAT)
purple_conv_chat_send(PURPLE_CONV_CHAT(conv), msg);
purple_debug_info("URL DATA", "%s", purple_markup_strip_html(it)); //debug to check the data is OK
}
static void
do_fetch(char *message, PurpleConversation *conv)
{ // Code below is pretty much not finished. the commented code would be best (but non working) way
char *url = g_strdup_printf("http://translate.google.com/translate_t?langpair=en|fr&hl=en&ie=UTF8&text=%s",
purple_url_encode(message));
purple_util_fetch_url(url, TRUE, NULL, FALSE, fetch_page, conv);
}
static PurpleCmdRet
fr_it(PurpleConversation *conv, const gchar *cmd, gchar **args, gchar *error, void *data)
{
gchar *msg;
do_fetch(args[0], conv);
g_free(msg);
return PURPLE_CMD_RET_OK;
}
static gboolean
plugin_load(PurplePlugin *plugin)
{
fr_cmd_id = purple_cmd_register("fr", "s", PURPLE_CMD_P_PLUGIN,
PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_CHAT,
NULL,
PURPLE_CMD_FUNC(fr_it),
_("fr"),
NULL);
return TRUE;
}
static gboolean
plugin_unload(PurplePlugin *plugin) {
purple_cmd_unregister(fr_cmd_id);
return TRUE;
}
/* ======================================================================== */
static PurplePluginInfo info =
{
PURPLE_PLUGIN_MAGIC,
PURPLE_MAJOR_VERSION,
PURPLE_MINOR_VERSION,
PURPLE_PLUGIN_STANDARD, /**< type */
PIDGIN_PLUGIN_TYPE, /**< ui_requirement */
0, /**< flags */
NULL, /**< dependencies */
PURPLE_PRIORITY_DEFAULT, /**< priority */
PLUGIN_ID, /**< id */
PLUGIN_NAME, /**< name */
VERSION, /**< version */
/** summary */
PLUGIN_SUMMARY,
/** description */
PLUGIN_DESCRIPTION,
AUTHOR_NAME, /**< author */
WEBSITE_NAME, /**< homepage */
plugin_load, /**< load */
plugin_unload, /**< unload */
NULL, /**< destroy */
NULL, /**< ui_info */
NULL, /**< extra_info */
NULL, /**( prefs info */
NULL,
/* padding */
NULL,
NULL,
NULL,
NULL
};
/* ======================================================================== */
static void
init_plugin(PurplePlugin *plugin) {
}
PURPLE_INIT_PLUGIN(PLUGIN_ID, init_plugin, info)