summary refs log blame commit diff stats
path: root/src/common/dbus/dbus-plugin.h
blob: a28d16fbfe218b5015b9fc3a7ae01163d17a187e (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
                                                              













                                                                       
                                                                            




                     

                             
 
                                                               





                                                       
/* dbus-plugin.c - hexchat plugin for remote access using DBUS
 * Copyright (C) 2006 Claessens Xavier
 *
 * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 *
 * Claessens Xavier
 * xclaesse@gmail.com
 */

#ifndef HEXCHAT_DBUS_PLUGIN_H
#define HEXCHAT_DBUS_PLUGIN_H

int	dbus_plugin_init	(hexchat_plugin *plugin_handle,
				 char **plugin_name,
				 char **plugin_desc,
				 char **plugin_version,
				 char *arg);

#endif
/* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/* HexChat 2.0 plugin: Mail checker */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

#include "hexchat-plugin.h"


static hexchat_plugin *ph;	/* plugin handle */

static int
mail_items(char *file)
{
	FILE *fp;
	int items;
	char buf[512];

	fp = fopen(file, "r");
	if(!fp)
		return 1;

	items = 0;
	while(fgets(buf, sizeof buf, fp))
	{
		if(!strncmp(buf, "From ", 5))
			items++;
	}
	fclose(fp);

	return items;
}

static void
xchat_mail_check (void)
{
	static int last_size = -1;
	int size;
	struct stat st;
	char buf[512];
	char *maildir;

	maildir = getenv("MAIL");
	if(!maildir)
	{
		snprintf (buf, sizeof(buf), "/var/spool/mail/%s", getenv("USER"));
		maildir = buf;
	}

	if(stat(maildir, &st) < 0)
		return;

	size = st.st_size;

	if(last_size == -1)
	{
		last_size = size;
		return;
	}

	if(size > last_size)
	{
		hexchat_printf(ph,
	"-\0033-\0039-\017\tYou have new mail (%d messages, %d bytes total).",
				mail_items(maildir), size);
	}

	last_size = size;
}

static int timeout_cb(void *userdata)
{
	xchat_mail_check();

	return 1;
}

int hexchat_plugin_init(hexchat_plugin *plugin_handle,
				char **plugin_name, char **plugin_desc, char **plugin_version,
				char *arg)
{
	ph = plugin_handle;

	*plugin_name = "MailCheck";
	*plugin_desc = "Checks your mailbox every 30 seconds";
	*plugin_version = "0.1";

	hexchat_hook_timer(ph, 30000, timeout_cb, 0);

	return 1;
}