view plugins/timestamp.c @ 6623:156e6643f9db

[gaim-migrate @ 7147] Bjoern Voigt writes: "i18n23.patch contains: - Updated German translation - removed some (around 15-30) strings: The patch reduces the work of the translators a bit and makes the Gaim UI more consistent for all users (also for the native English users). I sorted the translatable strings with: $ cd po $ xgettext -s --default-domain=gaim --directory=.. --add-comments \ --keyword=_ --keyword=N_ --files-from=./POTFILES.in # -> look at gaim.po A lot of strings look very similar, for instance "Age" and "Age:" "Last Name" and "Lastname" "An error message" and "An error message." I tried to eliminate one string for each pair. This is possible, if string concatination functions like g_strconcat() or g_snprintf() are used. I also changed some uppercase letters to lowercase letters. But I changed very few strings, because this can be better done by a native speaker. THERE IS STILL SOME WORK TO DO: Most of the error messages have dots (".") at the end, some not. There are still some spellings of same words, for instance "screenname" and "screen name". If you are interested, please sort the strings (see above) and look at the sorted file gaim.po." committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Mon, 25 Aug 2003 15:42:39 +0000
parents 42fdf16f1dad
children 083d1e4a9c78
line wrap: on
line source

/* iChat-like timestamps by Sean Egan.
 *
 * Modified by: Chris J. Friesen <Darth_Sebulba04@yahoo.com> Jan 05, 2003.
 * <INSERT GPL HERE> */

#include "internal.h"

#include "conversation.h"
#include "debug.h"
#include "signals.h"

#include "gtkimhtml.h"
#include "gtkplugin.h"
#include "gtkutils.h"

#define TIMESTAMP_PLUGIN_ID "gtk-timestamp"

/* Set the default to 5 minutes. */
static int timestamp = 5 * 60 * 1000;

static GSList *timestamp_timeouts;

static gboolean do_timestamp (gpointer data)
{
	GaimConversation *c = (GaimConversation *)data;
	char *buf;
	char mdate[6];
	time_t tim = time(NULL);

	if (!g_list_find(gaim_get_conversations(), c))
		return FALSE;

	strftime(mdate, sizeof(mdate), "%H:%M", localtime(&tim));
	buf = g_strdup_printf("            %s", mdate);
	gaim_conversation_write(c, NULL, buf, -1, GAIM_MESSAGE_NO_LOG, tim);
	g_free(buf);
	return TRUE;
}

static void timestamp_new_convo(GaimConversation *conv)
{
	do_timestamp(conv);

	timestamp_timeouts = g_slist_append(timestamp_timeouts,
			GINT_TO_POINTER(g_timeout_add(timestamp, do_timestamp, conv)));

}

static void set_timestamp(GtkWidget *button, GtkWidget *spinner) {
	int tm;

	tm = 0;

	tm = CLAMP(gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinner)), 1, G_MAXINT);
	gaim_debug(GAIM_DEBUG_MISC, "timestamp", "setting  time to %d mins\n", tm);

	tm = tm * 60 * 1000;

	timestamp = tm;
}

static GtkWidget *
get_config_frame(GaimPlugin *plugin)
{
	GtkWidget *ret;
	GtkWidget *frame, *label;
	GtkWidget *vbox, *hbox;
	GtkAdjustment *adj;
	GtkWidget *spinner, *button;

	ret = gtk_vbox_new(FALSE, 18);
	gtk_container_set_border_width (GTK_CONTAINER (ret), 12);

	frame = gaim_gtk_make_frame(ret, _("iChat Timestamp"));
	vbox = gtk_vbox_new(FALSE, 5);
	gtk_container_add(GTK_CONTAINER(frame), vbox);

	hbox = gtk_hbox_new(FALSE, 5);
	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);

	label = gtk_label_new(_("Delay"));
	gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);

	adj = (GtkAdjustment *)gtk_adjustment_new(timestamp/(60*1000), 1, G_MAXINT, 1, 0, 0);
	spinner = gtk_spin_button_new(adj, 0, 0);
	gtk_box_pack_start(GTK_BOX(hbox), spinner, TRUE, TRUE, 0);

	label = gtk_label_new(_("minutes."));
	gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);

	hbox = gtk_hbox_new(TRUE, 5);
	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);

	button = gtk_button_new_with_mnemonic(_("_Apply"));
	gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5);
	g_signal_connect(G_OBJECT(button), "clicked",
					 G_CALLBACK(set_timestamp), spinner);

	gtk_widget_show_all(ret);
	return ret;
}

static gboolean
plugin_load(GaimPlugin *plugin)
{
	GList *cnvs;
	GaimConversation *c;

	timestamp_timeouts = NULL;
	for (cnvs = gaim_get_conversations(); cnvs != NULL; cnvs = cnvs->next) {
		c = cnvs->data;
		timestamp_new_convo(c);
	}

	gaim_signal_connect(gaim_conversations_get_handle(),
						"conversation-created",
						plugin, GAIM_CALLBACK(timestamp_new_convo), NULL);

	return TRUE;
}

static gboolean
plugin_unload(GaimPlugin *plugin)
{
	GSList *to;

	for (to = timestamp_timeouts; to != NULL; to = to->next)
		g_source_remove(GPOINTER_TO_INT(to->data));

	g_slist_free(timestamp_timeouts);

	return TRUE;
}

static GaimGtkPluginUiInfo ui_info =
{
	get_config_frame
};

static GaimPluginInfo info =
{
	2,                                                /**< api_version    */
	GAIM_PLUGIN_STANDARD,                             /**< type           */
	GAIM_GTK_PLUGIN_TYPE,                             /**< ui_requirement */
	0,                                                /**< flags          */
	NULL,                                             /**< dependencies   */
	GAIM_PRIORITY_DEFAULT,                            /**< priority       */

	TIMESTAMP_PLUGIN_ID,                              /**< id             */
	N_("Timestamp"),                                  /**< name           */
	VERSION,                                          /**< version        */
	                                                  /**  summary        */
	N_("Adds iChat-style timestamps to conversations every N minutes."),
	                                                  /**  description    */
	N_("Adds iChat-style timestamps to conversations every N minutes."),
	"Sean Egan <bj91704@binghamton.edu>",             /**< author         */
	GAIM_WEBSITE,                                     /**< homepage       */

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

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

static void
init_plugin(GaimPlugin *plugin)
{
}

GAIM_INIT_PLUGIN(timestamp, init_plugin, info)