Esempio n. 1
0
/*------------------------------------------------------------------------
 * Display the current splash-screen.
 *
 *  @param session		The MXit session object
 */
void splash_display(struct MXitSession* session)
{
	const char* splashId = NULL;
	char* filename;
	gchar* imgdata;
	gsize imglen;
	int imgid = -1;

	/* Get current splash ID */
	splashId = splash_current(session);
	if (splashId == NULL)		/* no splash-screen */
		return;

	purple_debug_info(MXIT_PLUGIN_ID, "Display Splash: '%s'\n", splashId);

	/* Load splash-screen image from file */
	filename = g_strdup_printf("%s" G_DIR_SEPARATOR_S "mxit" G_DIR_SEPARATOR_S "%s.png", purple_user_dir(), splashId);
	if (g_file_get_contents(filename, &imgdata, &imglen, NULL)) {
		char buf[128];

		/* Add splash-image to imagestore */
		imgid = purple_imgstore_new_with_id(g_memdup(imgdata, imglen), imglen, NULL);

		/* Generate and display message */
		g_snprintf(buf, sizeof(buf),
		           "<img src=\"" PURPLE_STORED_IMAGE_PROTOCOL "%d\">", imgid);

		/* Open a request-type popup to display the image */
		{
			PurpleRequestFields*		fields;
			PurpleRequestFieldGroup*	group;
			PurpleRequestField*			field;

			fields = purple_request_fields_new();
			group = purple_request_field_group_new(NULL);
			purple_request_fields_add_group(fields, group);

			field = purple_request_field_image_new("splash", "", imgdata, imglen);		/* add splash image */
			purple_request_field_group_add_field(group, field);

			if (splash_clickable(session)) {
				purple_request_fields(session->con, _("MXit Advertising"), NULL, NULL, fields,
					_("More Information"), G_CALLBACK(splash_click_ok), _("Close"), NULL, purple_request_cpar_from_account(session->acc), session->con);
			}
			else {
				purple_request_fields(session->con, _("MXit Advertising"), NULL, NULL, fields,
					_("Continue"), G_CALLBACK(splash_click_ok), _("Close"), NULL, purple_request_cpar_from_account(session->acc), session->con);
			}
		}

		/* Release reference to image */
		purple_imgstore_unref_by_id(imgid);

		g_free(imgdata);
	}

	g_free(filename);
}
Esempio n. 2
0
/*------------------------------------------------------------------------
 * Display the current splash-screen, or a notification pop-up if one is not available.
 *
 *  @param action	The action object
 */
static void mxit_splash_action( PurplePluginAction* action )
{
	PurpleConnection*		gc		= (PurpleConnection*) action->context;
	struct MXitSession*		session	= purple_connection_get_protocol_data( gc );

	if ( splash_current( session ) != NULL )
		splash_display( session );
	else
		mxit_popup( PURPLE_NOTIFY_MSG_INFO, _( "View Splash" ), _( "There is no splash-screen currently available" ) );
}
Esempio n. 3
0
/*------------------------------------------------------------------------
 * The user has clicked OK on the Splash request form.
 *
 *  @param gc			The connection object
 *  @param fields		The list of fields in the accepted form
 */
static void splash_click_ok(PurpleConnection* gc, PurpleRequestFields* fields)
{
	struct MXitSession*	session	= purple_connection_get_protocol_data(gc);
	const char* splashId;

	/* Get current splash ID */
	splashId = splash_current(session);
	if (splashId == NULL)		/* no splash-screen */
		return;

	/* if is clickable, then send click event */
	if (splash_clickable(session))
		mxit_send_splashclick(session, splashId);
}
Esempio n. 4
0
/*------------------------------------------------------------------------
 * Remove the stored splash-screen (if it exists).
 *
 *  @param session		The MXit session object
 */
void splash_remove(struct MXitSession* session)
{
	const char* splashId = NULL;
	char* filename;

	/* Get current splash ID */
	splashId = splash_current(session);

	if (splashId != NULL) {
		purple_debug_info(MXIT_PLUGIN_ID, "Removing splashId: '%s'\n", splashId);

		/* Delete stored splash image */
		filename = g_strdup_printf("%s" G_DIR_SEPARATOR_S "mxit" G_DIR_SEPARATOR_S "%s.png", purple_user_dir(), purple_escape_filename(splashId));
		g_unlink(filename);
		g_free(filename);

		/* Clear current splash ID from settings */
		purple_account_set_string(session->acc, MXIT_CONFIG_SPLASHID, "");
		purple_account_set_bool(session->acc, MXIT_CONFIG_SPLASHCLICK, FALSE);
	}
}