view plugins/timestamp_format.c @ 13914:3ae8a3935406

[gaim-migrate @ 16414] First stab at trying to fix the MSN http connect method. It still doesn't work, and I'm not sure why, but it gets a lot farther in the signon process now. For those unfamiliar with the issue, the MSN http connect method stopped working after all the non-blocking I/O changes. The http connect method is apparently used by lots of people behind silly firewalls and stuff, and therefore we really shouldn't release Gaim 2.0.0 without it working, because people will complain. The two main problems were 1. The outgoing message queue was removed in favor of buffering all data to one large buffer. This sounds good in theory... but apparently each message sent to and from the server has a "SessionID" in the HTTP header. Every message we send should use the same SessionID as the last packet we received from the server. So basically you can't put two messages into the outgoing buffer at the same time because you don't have the correct SessionID to use for the second message. You have to wait until you get the reply from the server. 2. There were some strange buffer problems with using the wrong variable when trying to combine the header+body into one buffer before sending the message. I also fixed a small memleak or two, added some comments, and tried to clean up the code a little. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Mon, 03 Jul 2006 20:39:04 +0000
parents c73c7dd0721f
children f94309c7c480
line wrap: on
line source

#include "internal.h"

#include "debug.h"
#include "log.h"
#include "plugin.h"
#include "util.h"
#include "version.h"

#include "gtkconv.h"
#include "gtkplugin.h"

#include <time.h>

static GaimPluginPrefFrame *
get_plugin_pref_frame(GaimPlugin *plugin)
{
	GaimPluginPrefFrame *frame;
	GaimPluginPref *ppref;

	frame = gaim_plugin_pref_frame_new();

	ppref = gaim_plugin_pref_new_with_label(_("Timestamp Format Options"));
	gaim_plugin_pref_frame_add(frame, ppref);

	ppref = gaim_plugin_pref_new_with_name_and_label(
			"/plugins/gtk/timestamp_format/force_24hr",
			_("_Force (traditional Gaim) 24-hour time format"));
	gaim_plugin_pref_frame_add(frame, ppref);

	ppref = gaim_plugin_pref_new_with_label(_("Show dates in..."));
	gaim_plugin_pref_frame_add(frame, ppref);

	ppref = gaim_plugin_pref_new_with_name_and_label(
			"/plugins/gtk/timestamp_format/use_dates/conversation",
			_("Co_nversations:"));
        gaim_plugin_pref_set_type(ppref, GAIM_PLUGIN_PREF_CHOICE);
        gaim_plugin_pref_add_choice(ppref, _("For delayed messages"), "automatic");
        gaim_plugin_pref_add_choice(ppref, _("For delayed messages and in chats"), "chats");
        gaim_plugin_pref_add_choice(ppref, _("Always"), "always");
	gaim_plugin_pref_frame_add(frame, ppref);

	ppref = gaim_plugin_pref_new_with_name_and_label(
			"/plugins/gtk/timestamp_format/use_dates/log",
			_("_Message Logs:"));
        gaim_plugin_pref_set_type(ppref, GAIM_PLUGIN_PREF_CHOICE);
        gaim_plugin_pref_add_choice(ppref, _("For delayed messages"), "automatic");
        gaim_plugin_pref_add_choice(ppref, _("For delayed messages and in chats"), "chats");
        gaim_plugin_pref_add_choice(ppref, _("Always"), "always");
	gaim_plugin_pref_frame_add(frame, ppref);

	return frame;
}

static char *timestamp_cb_common(GaimConversation *conv,
                                 const struct tm *tm,
                                 gboolean force,
                                 const char *dates)
{
	g_return_val_if_fail(conv != NULL, NULL);
	g_return_val_if_fail(tm != NULL, NULL);
	g_return_val_if_fail(dates != NULL, NULL);

	if (!strcmp(dates, "always") ||
	    (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT &&
	     !strcmp(dates, "chats")) ||
	    (time(NULL) > (mktime((struct tm *)tm) + 20*60)))
	{
		if (force)
			return g_strdup(gaim_utf8_strftime("%Y-%m-%d %H:%M:%S", tm));
		else
			return g_strdup(gaim_date_format_long(tm));
	}

	if (force)
		return g_strdup(gaim_utf8_strftime("%H:%M:%S", tm));

	return NULL;
}

static char *conversation_timestamp_cb(GaimConversation *conv,
                                       const struct tm *tm, gpointer data)
{
	gboolean force = gaim_prefs_get_bool(
				"/plugins/gtk/timestamp_format/force_24hr");
	const char *dates = gaim_prefs_get_string(
				"/plugins/gtk/timestamp_format/use_dates/conversation");

	g_return_val_if_fail(conv != NULL, NULL);
	g_return_val_if_fail(tm != NULL, NULL);

	return timestamp_cb_common(conv, tm, force, dates);
}

static char *log_timestamp_cb(GaimLog *log,
                                  const struct tm *tm, gpointer data)
{
	gboolean force = gaim_prefs_get_bool(
				"/plugins/gtk/timestamp_format/force_24hr");
	const char *dates = gaim_prefs_get_string(
				"/plugins/gtk/timestamp_format/use_dates/log");

	g_return_val_if_fail(log != NULL, NULL);
	g_return_val_if_fail(tm != NULL, NULL);

	if (log->type == GAIM_LOG_SYSTEM)
	{
		if (force)
			return g_strdup(gaim_utf8_strftime("%Y-%m-%d %H:%M:%S", tm));
		else
			return NULL;
	}

	return timestamp_cb_common(log->conv, tm, force, dates);
}

static gboolean
plugin_load(GaimPlugin *plugin)
{
	gaim_signal_connect(gaim_gtk_conversations_get_handle(), "conversation-timestamp",
	                    plugin, GAIM_CALLBACK(conversation_timestamp_cb), NULL);
	gaim_signal_connect(gaim_log_get_handle(), "log-timestamp",
	                    plugin, GAIM_CALLBACK(log_timestamp_cb), NULL);
	return TRUE;
}

static gboolean
plugin_unload(GaimPlugin *plugin)
{
	return TRUE;
}

static GaimPluginUiInfo prefs_info = {
        get_plugin_pref_frame,
	0,   /* page num (Reserved) */
	NULL /* frame (Reserved) */
};

static GaimPluginInfo info =
{
	GAIM_PLUGIN_MAGIC,
	GAIM_MAJOR_VERSION,
	GAIM_MINOR_VERSION,
	GAIM_PLUGIN_STANDARD,                             /**< type           */
	GAIM_GTK_PLUGIN_TYPE,                             /**< ui_requirement */
	0,                                                /**< flags          */
	NULL,                                             /**< dependencies   */
	GAIM_PRIORITY_DEFAULT,                            /**< priority       */

	NULL,                                             /**< id             */
	N_("Message Timestamp Formats"),                  /**< name           */
	VERSION,                                          /**< version        */
	                                                  /**  summary        */
	N_("Customizes the message timestamp formats."),
	                                                  /**  description    */
	N_("This plugin allows the user to customize "
	   "conversation and logging message timestamp "
	   "formats."),
	"Richard Laager <rlaager@users.sf.net>",          /**< author         */
	GAIM_WEBSITE,                                     /**< homepage       */

	plugin_load,                                      /**< load           */
	plugin_unload,                                    /**< unload         */
	NULL,                                             /**< destroy        */

	NULL,                                             /**< ui_info        */
	NULL,                                             /**< extra_info     */
	&prefs_info,                                      /**< prefs_info     */
	NULL                                              /**< actions        */
};

static void
init_plugin(GaimPlugin *plugin)
{
	gaim_prefs_add_none("/plugins/gtk");
	gaim_prefs_add_none("/plugins/gtk/timestamp_format");

	gaim_prefs_add_bool("/plugins/gtk/timestamp_format/force_24hr", TRUE);

	gaim_prefs_add_none("/plugins/gtk/timestamp_format/use_dates");
	gaim_prefs_add_string("/plugins/gtk/timestamp_format/use_dates/conversation", "automatic");
	gaim_prefs_add_string("/plugins/gtk/timestamp_format/use_dates/log", "automatic");
}

GAIM_INIT_PLUGIN(timestamp_format, init_plugin, info)