static PidginStatusIconTheme *
create_icon_theme(GtkWidget *window)
{
	int s, i, j;
	const char *dirname = g_get_tmp_dir();
	PidginStatusIconTheme *theme;
	const char *author;
#ifndef _WIN32
	author = getlogin();
#else
	author = "user";
#endif
	theme = g_object_new(PIDGIN_TYPE_STATUS_ICON_THEME, "type", "status-icon",
				"author", author,
				"directory", dirname,
				NULL);

	for (s = 0; sections[s].heading; s++) {
		GtkWidget *vbox = g_object_get_data(G_OBJECT(window), sections[s].heading);
		for (i = 0; sections[s].options[i].stockid; i++) {
			GtkWidget *image = g_object_get_data(G_OBJECT(vbox), sections[s].options[i].stockid);
			GdkPixbuf *pixbuf = g_object_get_data(G_OBJECT(image), "pixbuf");
			if (!pixbuf)
				continue;
			pidgin_icon_theme_set_icon(PIDGIN_ICON_THEME(theme), sections[s].options[i].stockid,
					sections[s].options[i].stockid);
			for (j = 0; stocksizes[j]; j++) {
				int width, height;
				GtkIconSize iconsize;
				char size[8];
				char *name;
				GdkPixbuf *scale;
				GError *error = NULL;

				if (!(sections[s].flags & (1 << j)))
					continue;

				iconsize = gtk_icon_size_from_name(stocksizes[j]);
				gtk_icon_size_lookup(iconsize, &width, &height);
				g_snprintf(size, sizeof(size), "%d", width);

				if (i == 0) {
					name = g_build_filename(dirname, size, NULL);
					purple_build_dir(name, S_IRUSR | S_IWUSR | S_IXUSR);
					g_free(name);
				}

				name = g_build_filename(dirname, size, sections[s].options[i].stockid, NULL);
				scale = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR);
				gdk_pixbuf_save(scale, name, "png", &error, "compression", "9", NULL);
				g_free(name);
				g_object_unref(G_OBJECT(scale));
				if (error)
					g_error_free(error);
			}
		}
	}
	return theme;
}
Пример #2
0
static int create_dir(std::string dir, int mode) {
#ifdef WIN32
	replace(dir, "/", "\\");
#endif
	char *dirname = g_path_get_dirname(dir.c_str());
	int ret = purple_build_dir(dirname, mode);
	g_free(dirname);
	return ret;
}
Пример #3
0
static gboolean
ensure_path_exists(const char *dir)
{
	if (!g_file_test(dir, G_FILE_TEST_IS_DIR))
	{
		if (purple_build_dir(dir, S_IRUSR | S_IWUSR | S_IXUSR))
			return FALSE;
	}

	return TRUE;
}
Пример #4
0
/* Creates the certificate directory if it doesn't exist,
 * returns TRUE if it's successful or it already exists,
 * returns FALSE if there was an error.
 */
static gboolean
ensure_certificate_dir(GError **error)
{
	gchar *dir = make_certificate_path(NULL);
	gboolean ret = TRUE;

	if (purple_build_dir(dir, 0700) != 0) {
		g_set_error_literal(error, G_FILE_ERROR,
				g_file_error_from_errno(errno),
				g_strerror(errno));
		ret = FALSE;
	}

	g_free(dir);
	return ret;
}
Пример #5
0
/*------------------------------------------------------------------------
 * Save a new splash-screen for later display.
 *
 *  @param session		The MXit session object
 *  @param splashID		The ID of the splash-screen
 *  @param data			Splash-screen image data (PNG format)
 *  @param datalen		Splash-screen image data size
 */
void splash_update(struct MXitSession* session, const char* splashId, const char* data, unsigned int datalen, gboolean clickable)
{
	char* dir;
	char* filename;

	/* Remove the current splash-screen */
	splash_remove(session);

	/* Save the new splash image */
	dir = g_strdup_printf("%s" G_DIR_SEPARATOR_S "mxit", purple_user_dir());
	purple_build_dir(dir, S_IRUSR | S_IWUSR | S_IXUSR);		/* ensure directory exists */

	filename = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s.png", dir, purple_escape_filename(splashId));
	if (purple_util_write_data_to_file_absolute(filename, data, datalen)) {
		/* Store new splash-screen ID to settings */
		purple_account_set_string(session->acc, MXIT_CONFIG_SPLASHID, splashId);
		purple_account_set_bool(session->acc, MXIT_CONFIG_SPLASHCLICK, clickable );
	}

	g_free(dir);
	g_free(filename);
}
Пример #6
0
static void
install_selected_file_cb(gpointer handle, const char *filename)
{
	/* Try to init the selected file.
	 * If it succeeds, try to make a copy of the file in $USERDIR/plugins/.
	 * If the copy succeeds, unload and destroy the plugin in the original
	 *  location and init+load the new one.
	 * Select the plugin in the plugin list.
	 */
	char *path;
	PurplePlugin *plugin;

	g_return_if_fail(plugins.window);

	plugin = purple_plugin_probe(filename);
	if (!plugin) {
		purple_notify_error(handle, _("Error loading plugin"),
				_("The selected file is not a valid plugin."),
				_("Please open the debug window and try again to see the exact error message."), NULL);
		return;
	}
	if (g_list_find(gnt_tree_get_rows(GNT_TREE(plugins.tree)), plugin)) {
		purple_plugin_load(plugin);
		gnt_tree_set_choice(GNT_TREE(plugins.tree), plugin, purple_plugin_is_loaded(plugin));
		gnt_tree_set_selected(GNT_TREE(plugins.tree), plugin);
		return;
	}

	path = g_build_filename(purple_user_dir(), "plugins", NULL);
	if (purple_build_dir(path, S_IRUSR | S_IWUSR | S_IXUSR) == 0) {
		char *content = NULL;
		gsize length = 0;

		if (g_file_get_contents(filename, &content, &length, NULL)) {
			char *file = g_path_get_basename(filename);
			g_free(path);
			path = g_build_filename(purple_user_dir(), "plugins", file, NULL);
			if (purple_util_write_data_to_file_absolute(path, content, length)) {
				purple_plugin_destroy(plugin);
				plugin = purple_plugin_probe(path);
				if (!plugin) {
					purple_debug_warning("gntplugin", "This is really strange. %s can be loaded, but %s can't!\n",
							filename, path);
					g_unlink(path);
					plugin = purple_plugin_probe(filename);
				}
			} else {
			}
		}
		g_free(content);
	}
	g_free(path);

	purple_plugin_load(plugin);

	if (plugin->info->type == PURPLE_PLUGIN_LOADER) {
		GList *cur;
		for (cur = PURPLE_PLUGIN_LOADER_INFO(plugin)->exts; cur != NULL;
				cur = cur->next)
			purple_plugins_probe(cur->data);
		return;
	}

	if (plugin->info->type != PURPLE_PLUGIN_STANDARD ||
			(plugin->info->flags & PURPLE_PLUGIN_FLAG_INVISIBLE) ||
			plugin->error)
		return;

	gnt_tree_add_choice(GNT_TREE(plugins.tree), plugin,
			gnt_tree_create_row(GNT_TREE(plugins.tree), plugin->info->name), NULL, NULL);
	gnt_tree_set_choice(GNT_TREE(plugins.tree), plugin, purple_plugin_is_loaded(plugin));
	gnt_tree_set_row_flags(GNT_TREE(plugins.tree), plugin, GNT_TEXT_FLAG_BOLD);
	gnt_tree_set_selected(GNT_TREE(plugins.tree), plugin);
}
Пример #7
0
static void purple_init(account_t *acc)
{
	PurplePlugin *prpl = purple_plugins_find_with_id((char *) acc->prpl->data);
	PurplePluginProtocolInfo *pi = prpl->info->extra_info;
	PurpleAccount *pa;
	GList *i, *st;
	set_t *s;
	char help_title[64];
	GString *help;
	static gboolean dir_fixed = FALSE;

	/* Layer violation coming up: Making an exception for libpurple here.
	   Dig in the IRC state a bit to get a username. Ideally we should
	   check if s/he identified but this info doesn't seem *that* important.
	   It's just that fecking libpurple can't *not* store this shit.

	   Remember that libpurple is not really meant to be used on public
	   servers anyway! */
	if (!dir_fixed) {
		PurpleCertificatePool *pool;
		irc_t *irc = acc->bee->ui_data;
		char *dir;

		dir = g_strdup_printf("%s/purple/%s", global.conf->configdir, irc->user->nick);
		purple_util_set_user_dir(dir);
		g_free(dir);

		purple_blist_load();
		purple_prefs_load();

		if (proxytype == PROXY_SOCKS4A) {
			/* do this here after loading prefs. yes, i know, it sucks */
			purple_prefs_set_bool("/purple/proxy/socks4_remotedns", TRUE);
		}

		/* re-create the certificate cache directory */
		pool = purple_certificate_find_pool("x509", "tls_peers");
		dir = purple_certificate_pool_mkpath(pool, NULL);
		purple_build_dir(dir, 0700);
		g_free(dir);

		dir_fixed = TRUE;
	}

	help = g_string_new("");
	g_string_printf(help, "BitlBee libpurple module %s (%s).\n\nSupported settings:",
	                (char *) acc->prpl->name, prpl->info->name);

	if (pi->user_splits) {
		GList *l;
		g_string_append_printf(help, "\n* username: Username");
		for (l = pi->user_splits; l; l = l->next) {
			g_string_append_printf(help, "%c%s",
			                       purple_account_user_split_get_separator(l->data),
			                       purple_account_user_split_get_text(l->data));
		}
	}

	/* Convert all protocol_options into per-account setting variables. */
	for (i = pi->protocol_options; i; i = i->next) {
		PurpleAccountOption *o = i->data;
		const char *name;
		char *def = NULL;
		set_eval eval = NULL;
		void *eval_data = NULL;
		GList *io = NULL;
		GSList *opts = NULL;

		name = purple_account_option_get_setting(o);

		switch (purple_account_option_get_type(o)) {
		case PURPLE_PREF_STRING:
			def = g_strdup(purple_account_option_get_default_string(o));

			g_string_append_printf(help, "\n* %s (%s), %s, default: %s",
			                       name, purple_account_option_get_text(o),
			                       "string", def);

			break;

		case PURPLE_PREF_INT:
			def = g_strdup_printf("%d", purple_account_option_get_default_int(o));
			eval = set_eval_int;

			g_string_append_printf(help, "\n* %s (%s), %s, default: %s",
			                       name, purple_account_option_get_text(o),
			                       "integer", def);

			break;

		case PURPLE_PREF_BOOLEAN:
			if (purple_account_option_get_default_bool(o)) {
				def = g_strdup("true");
			} else {
				def = g_strdup("false");
			}
			eval = set_eval_bool;

			g_string_append_printf(help, "\n* %s (%s), %s, default: %s",
			                       name, purple_account_option_get_text(o),
			                       "boolean", def);

			break;

		case PURPLE_PREF_STRING_LIST:
			def = g_strdup(purple_account_option_get_default_list_value(o));

			g_string_append_printf(help, "\n* %s (%s), %s, default: %s",
			                       name, purple_account_option_get_text(o),
			                       "list", def);
			g_string_append(help, "\n  Possible values: ");

			for (io = purple_account_option_get_list(o); io; io = io->next) {
				PurpleKeyValuePair *kv = io->data;
				opts = g_slist_append(opts, kv->value);
				/* TODO: kv->value is not a char*, WTF? */
				if (strcmp(kv->value, kv->key) != 0) {
					g_string_append_printf(help, "%s (%s), ", (char *) kv->value, kv->key);
				} else {
					g_string_append_printf(help, "%s, ", (char *) kv->value);
				}
			}
			g_string_truncate(help, help->len - 2);
			eval = set_eval_list;
			eval_data = opts;

			break;

		default:
			/** No way to talk to the user right now, invent one when
			this becomes important.
			irc_rootmsg( acc->irc, "Setting with unknown type: %s (%d) Expect stuff to break..\n",
			             name, purple_account_option_get_type( o ) );
			*/
			g_string_append_printf(help, "\n* [%s] UNSUPPORTED (type %d)",
			                       name, purple_account_option_get_type(o));
			name = NULL;
		}

		if (name != NULL) {
			s = set_add(&acc->set, name, def, eval, acc);
			s->flags |= ACC_SET_OFFLINE_ONLY;
			s->eval_data = eval_data;
			g_free(def);
		}
	}

	g_snprintf(help_title, sizeof(help_title), "purple %s", (char *) acc->prpl->name);
	help_add_mem(&global.help, help_title, help->str);
	g_string_free(help, TRUE);

	s = set_add(&acc->set, "display_name", NULL, set_eval_display_name, acc);
	s->flags |= ACC_SET_ONLINE_ONLY;

	if (pi->options & OPT_PROTO_MAIL_CHECK) {
		s = set_add(&acc->set, "mail_notifications", "false", set_eval_bool, acc);
		s->flags |= ACC_SET_OFFLINE_ONLY;

		s = set_add(&acc->set, "mail_notifications_handle", NULL, NULL, acc);
		s->flags |= ACC_SET_OFFLINE_ONLY | SET_NULL_OK;
	}

	if (strcmp(prpl->info->name, "Gadu-Gadu") == 0) {
		s = set_add(&acc->set, "gg_sync_contacts", "true", set_eval_bool, acc);
	}

	/* Go through all away states to figure out if away/status messages
	   are possible. */
	pa = purple_account_new(acc->user, (char *) acc->prpl->data);
	for (st = purple_account_get_status_types(pa); st; st = st->next) {
		PurpleStatusPrimitive prim = purple_status_type_get_primitive(st->data);

		if (prim == PURPLE_STATUS_AVAILABLE) {
			if (purple_status_type_get_attr(st->data, "message")) {
				acc->flags |= ACC_FLAG_STATUS_MESSAGE;
			}
		} else if (prim != PURPLE_STATUS_OFFLINE) {
			if (purple_status_type_get_attr(st->data, "message")) {
				acc->flags |= ACC_FLAG_AWAY_MESSAGE;
			}
		}
	}
	purple_accounts_remove(pa);
}