示例#1
0
/*
 * Adds a Checkin object for a User
 * @param PROFILE_ID - the id of the User for which the Checkin object is created.
 * @param placeId - the id of the place to which the checkin is made.
 * @param coord - the coordinates of the checkin place.
 * @param tags - list of tagged friends. String containing comma separated list of user id's.
 * @param message - the message that will be posted along with the Checkin
 */
void FacebookPublisher2::addCheckin(const MAUtil::String &PROFILE_ID,	const MAUtil::String &placeId,
									const Coordinate &coord,			const MAUtil::String &tags,
									const MAUtil::String &message)
{

	MAUtil::Map<MAUtil::String, MAUtil::String> params;

	params["place"] = placeId;

	MAUtil::String coordStr = "{\"latitude\":\"" + coord.mLatitude +"\",";
	coordStr += "\"longitude\":\"" + coord.mLongitude + "\"}";

	params["coordinates"] = coordStr;

	MAUtil::String postdata = "method=POST" + mPostdataSeparator;
	postdata += "place=";
	postdata += placeId + mPostdataSeparator;
	postdata += coordStr;
	if(tags.size()>0)
	{
		postdata = mPostdataSeparator + "tags=" + tags;
	}
	if(message.size()>0)
	{
		postdata = mPostdataSeparator + "message=" + message;
	}

	mFacebook->requestGraph(PUBLISH, STRING, PROFILE_ID + "/checkins", HTTP_POST, params, postdata);
}
示例#2
0
void Login::actionSubmit(const MAUtil::String& mail, const MAUtil::String& pwd)
{
	auth_token = "";
	memset(buffer, 0, sizeof(buffer));

	int res = mHttp.create((MAUtil::String(Manager::main->host) + "/" + qLogin).c_str(), HTTP_POST);

	if (res < 0)
	{
		manager->view->callbackAuthentication();
		return;
	}

	// escape input
	static MAUtil::String jsonQuery;
	jsonQuery = "{\"email\": " + Wormhole::Encoder::JSONStringify(mail.c_str()) + ", \"password\": " + Wormhole::Encoder::JSONStringify(pwd.c_str()) + "}";

	mHttp.setRequestHeader("Accept", "application/json");
	mHttp.setRequestHeader("Content-type", "application/json");

	char buf[32];
	sprintf(buf, "%d", jsonQuery.size());

	mHttp.setRequestHeader("Content-length", buf);

	mHttp.write(jsonQuery.c_str(), jsonQuery.size());
}
示例#3
0
/*
 * Adds a Post object to a to a User wall.
 * @param message - the message to be posted
 * @param link - the link to be included in post.
 * @param pictureUrl - a picture url to be included in post.
 * @param actions - a Vector of Action objects (objects containing name and link) to be included in the post.
 * @param id - the id of the user on which wall the post will be displayed.
 */
void FacebookPublisher2::addPostOnWall(const MAUtil::String &ID, const MAUtil::String &message, const MAUtil::String &link,
			const MAUtil::String &name, const MAUtil::String &caption, const MAUtil::String &description )
{
	MAUtil::Map<MAUtil::String, MAUtil::String> params;

	MAUtil::String postdata = "message=" + message;

	if(link.size()>0)
	{
		postdata += mPostdataSeparator + "link=" + link;
	}

//	if(pictureUrl.size()>0)
//	{
//		postdata += mPostdataSeparator + "picture=" + pictureUrl;
//	}
	if(name.size()>0)
	{
		postdata += mPostdataSeparator + "name=" + name;
	}
	if(caption.size()>0)
	{
		postdata += mPostdataSeparator + "caption=" + caption;
	}
	if(description.size()>0)
	{
		postdata += mPostdataSeparator + "description=" + description;
	}

	mFacebook->requestGraph(PUBLISH, STRING, ID + "/feed", HTTP_POST, postdata);
}
示例#4
0
/*
 * Adds a Event object for a User.
 * @param PROFILE_ID - the id of the User to which the event is added.
 * @param eventName - the name of the event.
 * @param eventStartTime - the start time of the Event.
 * @param eventEndTime - the end time of the Event.
 * @param message - the message to be posted alog with the event
 * @param location - the name of the location
 * @param privacyType - a string that can have the following values: "PUBLIC",
 */
void FacebookPublisher2::addEvent(const MAUtil::String &PROFILE_ID,		const MAUtil::String &name,
									const UnixTimeStamp &start_time,	const UnixTimeStamp &end_time,
									const MAUtil::String &message,		const MAUtil::String &location,
									const MAUtil::String &privacyType)
{
	MAUtil::String postdata = "name=" + name;

	postdata += mPostdataSeparator;
	postdata += "start_time=";
	postdata += start_time.getTimeStamp();


	if(!end_time.isEmpty())
	{
		postdata += mPostdataSeparator;
		postdata += "end_time=";
		postdata += end_time.getTimeStamp();
	}

	if(message.size()>0)
	{
		postdata += mPostdataSeparator + "message=" + message;
	}
	if(location.size()>0)
	{
		postdata += mPostdataSeparator + "location=" + location;
	}
	if(privacyType.size()>0)
	{
		postdata += mPostdataSeparator + "privacy_type =" + privacyType;
	}

	mFacebook->requestGraph(PUBLISH, STRING, PROFILE_ID + "/events", HTTP_POST, postdata);
}
示例#5
0
bool Facebook::extractConnectionTypeAndId(FacebookRequest *req, MAUtil::String &connectionType, MAUtil::String &id) const
{
	const MAUtil::String path = req->getPath();

	int found = path.findFirstOf('/');
	if(String::npos == found)
	{
		return false;
	}
	id = path.substr(0, found);
	connectionType = path.substr(found+1);

    return (connectionType.size()>0 && id.size()>0);
}
示例#6
0
	/**
	 * Reads the CountryTable file.
	 * Data will be written into mCountryFileNames.
	 */
	void DatabaseManager::readCountryTableFile()
	{
		// Reset array.
		mCountryFileNames.clear();

		// Open CountryTable file.
		MAUtil::String filePath = mFileUtil->getLocalPath() + COUNTRY_TABLE_FILE_NAME;
		MAUtil::String fileContent;
		if (!mFileUtil->readTextFromFile(filePath, fileContent))
		{
			printf("Cannot read text from CountryTable");
			return;
		}

		//Read file content.
		MAUtil::YAJLDom::Value* root = MAUtil::YAJLDom::parse(
			(const unsigned char*)fileContent.c_str(), fileContent.size());
		MAUtil::YAJLDom::Value* countries = root->getValueForKey(sCountriesKey);
		MAUtil::YAJLDom::ArrayValue* countriesArray = (MAUtil::YAJLDom::ArrayValue*) countries;
		MAUtil::Vector<MAUtil::YAJLDom::Value*> allCountries = countriesArray->getValues();

		// Get all country files that we should read next.
		for (int index = 0; index < allCountries.size(); index++)
		{
			MAUtil::YAJLDom::Value* countryValue = allCountries[index];
			MAUtil::String countryFileName = countryValue->toString();
			mCountryFileNames.add(countryFileName);
		}
		delete root;
	}
示例#7
0
文件: main.cpp 项目: AliSayed/MoSync
static bool writeAFile(const MAUtil::String& dir) {
	// find a root path
	printf("Dir: '%s'\n", dir.c_str());
	FileLister fl;
	int res = fl.start(dir.c_str());
	if(res < 0) {
		printf("Error %i\n", res);
		return false;
	}
	MAUtil::String file;
	while(1) {
		res = fl.next(file);
		printf("%i: '%s'\n", res, file.c_str());
		if(res < 0) {
			printf("Error %i\n", res);
			return false;
		}
		if(res == 0) {
			printf("Dir '%s' ends.\n", dir.c_str());
			return false;
		}
		if(file[file.size()-1] == '/') {
			if(tryToWrite(dir + file))
				return true;
			if(writeAFile(dir + file))
				return true;
		}
	}
}
示例#8
0
/*
 * Adds a Link object to a to a User wall.
 * @param link - the link to be posted.
 * @param message - the message to be posted with the link
 * @param id - the id of the user on which wall the link will be displayed.
 */
void FacebookPublisher2::addLinkOnWall(const MAUtil::String &ID, const MAUtil::String &link, const MAUtil::String &message)
{
	MAUtil::String postdata = "link=" + link;
	if(message.size()>0)
	{
		postdata += mPostdataSeparator + "message=" + message;
	}
	mFacebook->requestGraph(PUBLISH, STRING, ID + "/feed", HTTP_POST, postdata);
}
示例#9
0
/*
 * Adds a Album object.
 * @param OBJECT_ID - the id of the User for which the Album object is created.
 * @param name - the name of the Album.
 * @param message - the message of the Album.
 */
void FacebookPublisher2::addAlbum(const MAUtil::String &PROFILE_ID, const MAUtil::String &name, const MAUtil::String &message)
{
	MAUtil::String postdata = "name=" + name;
	if(message.size()>0)
	{
		postdata += mPostdataSeparator + "message=" + message;
	}
	mFacebook->requestGraph(PUBLISH, STRING, PROFILE_ID + "/albums", HTTP_POST, postdata);
}
示例#10
0
/**
 * The constructor creates the user interface and the FacebookManager
 */
FacebookDemoMoblet::FacebookDemoMoblet(const MAUtil::String &appId)
{
    if(appId.size()==0)
    {
        maPanic(1, "This application requires an application id. Please see file config.h");
    }

    initializeFacebook(appId);
    createGUI();
    login();
}
	/**
	 * Constructor.
	 */
	ApplicationController::ApplicationController() :
		mMainScreen(NULL),
		mDatabase(NULL),
		mCountSucceededTests(0)
	{
		mMainScreen = new MainScreen();
		mMainScreen->show();

		this->log("Application started!");

		mDatabase = new DatabaseManager();
		DatabaseProduct* dbProduct = new DatabaseProduct();

		int platform = getPlatform();
		if (platform != IOS &&
			platform != ANDROID)
		{
			maAlert("Error", "This program runs only on Android and iOS devices",
				"OK", NULL, NULL);
		}
		else if ( PurchaseManager::getInstance()->checkPurchaseSupported() != MA_PURCHASE_RES_OK )
		{
			maAlert("Error", "Billing is not supported on this device",
				"OK", NULL, NULL);
		}
		else
		{
			MAUtil::String developerKey = DEVELOPER_PUBLIC_KEY;
			if ( developerKey.size() == 0 &&
				 platform == ANDROID )
			{
				maAlert("Error", "You need to set developer key in Config.h ",
					"OK", NULL, NULL);
			}
			else
			{
				this->log("Creating tests...");
				this->createTests();
				this->log("Tests are created!");
				this->runNextTest();
			}
		}
	}
示例#12
0
	/**
	 * Read a given country file.
	 * Data will be added into mCountries.
	 * @param countryFileName File name to read.
	 */
	void DatabaseManager::readCountryFile(MAUtil::String& countryFileName)
	{
		// Open and read file content.
		MAUtil::String filePath = mFileUtil->getLocalPath() + countryFileName;
		MAUtil::String fileContent;
		if (!mFileUtil->readTextFromFile(filePath, fileContent))
		{
			printf("Cannot read text from %s", filePath.c_str());
			return;
		}

		// Extract JSON values.
		MAUtil::YAJLDom::Value* root = MAUtil::YAJLDom::parse(
			(const unsigned char*)fileContent.c_str(), fileContent.size());
		MAUtil::String name = root->getValueForKey(sCountryNameKey)->toString();
		int flagID = root->getValueForKey(sCountryFlagIDKey)->toInt();
		MAUtil::String population = root->getValueForKey(sCountryPopulationKey)->toString();
		MAUtil::String area = root->getValueForKey(sCountryAreaKey)->toString();
		MAUtil::String languages = root->getValueForKey(sCountryLanguagesKey)->toString();
		MAUtil::String government = root->getValueForKey(sCountryGovernmentKey)->toString();
		MAUtil::String capital = root->getValueForKey(sCountryCapitalKey)->toString();

		// Create and fill Country object with read data.
		Country* country = new Country();
		country->setName(name);
		country->setFlagID(flagID);
		country->setPopulation(population);
		country->setArea(area);
		country->setLanguages(languages);
		country->setGovernment(government);
		country->setCapital(capital);

		// Add object to map and array.
		mCountriesMap.insert(country->getID(), country);
		mCountriesArray.add(country);

		// Delete JSON root object.
		delete root;
	}
示例#13
0
文件: Main.cpp 项目: Ginox/MoSync
	/**
	 * Constructor that creates the UI.
	 * If billing is not supported, no screen is shown.
	 */
	NativeUIMoblet():
		mController(NULL)
	{
		MAUtil::String developerKey = DEVELOPER_PUBLIC_KEY;
		int platform = getPlatform();
		int result = IAP::PurchaseManager::getInstance()->checkPurchaseSupported();
		if (platform != IOS &&
			platform != ANDROID)
		{
			maAlert("Error", "This program runs only on Android and iOS devices",
				"OK", NULL, NULL);
		}
		else if ( result != MA_PURCHASE_RES_OK )
		{
			MAUtil::String errorMessage = "Billing is not supported on this device, because of error "
					+ MAUtil::integerToString(result);
			maAlert("Error", errorMessage.c_str(), "OK", NULL, NULL);
		}
		else
		{
			if ( platform == ANDROID && developerKey.size() == 0 )
			{
				maAlert("Error", "You need to set developer key in Config.h ",
					"OK", NULL, NULL);
			}
			else if ( platform == ANDROID &&
					PurchaseManager::getInstance()->setPublicKey(DEVELOPER_PUBLIC_KEY)
						== MA_PURCHASE_RES_MALFORMED_PUBLIC_KEY )
			{
				maAlert("Error", "Malformed developer key in Config.h ",
					"OK", NULL, NULL);
			}
			else
			{
				mController = new ApplicationController();
			}
		}
	}
示例#14
0
/*
 * Handle events on screen's widgets
 * NOTE: take care to dismiss the Keyboard until you press other buttons,
 * because it is not modal.
 */
void HomeScreen::widgetClicked(MAHandle widgetHandle)
{
	if (widgetHandle == mSearchButton)
	{
		// Disable the search button until new search is made.
		maWidgetSetProperty(mSearchButton, MAW_WIDGET_ENABLED, "false");

		// Close the edit box forced.
		maWidgetSetProperty(mEditBox, MAW_EDIT_BOX_SHOW_KEYBOARD, "false");

		// Declare a buffer for the text contained in the edit box.
		char textBuffer[256];

		// Get the text from the edit box and put it into the buffer.
		int textLength = maWidgetGetProperty(mEditBox, MAW_EDIT_BOX_TEXT,
				textBuffer, 256);

		// If the text does not fit in the buffer, textLength will be set
		// to -1, therefore we need to check that the length is greater than
		// or equal to 0, otherwise we just ignore the event.
		if (textLength == MAW_RES_INVALID_STRING_BUFFER_SIZE
			||
			strcmp(textBuffer,"") == 0)
		{
			return;
		}

		MAUtil::String text = textBuffer;
		// Now we can perform a wiki search.
		// After the result is received and processed, go to next screen.
		if (text.size() > 2)
		{
			// Show the progress bar and it's label.
			maWidgetSetProperty(mProgressLabel,MAW_WIDGET_VISIBLE, "true");
			maWidgetSetProperty(mProgressBar, MAW_WIDGET_VISIBLE, "true");

			// This label is indicating that a search action is in progress.
			maWidgetSetProperty(
				mProgressLabel, MAW_LABEL_TEXT, MESSAGE_WAITNOTE.c_str());

			// Initiate the search with a result limit.
			mWiki->search(text, mSliderValue);
		}
	}
	else if ( mCategoryBoxes[0] == widgetHandle)
	{
		// If All category is selected, all the other ones are selected also.
		char buf[6];
		maWidgetGetProperty(mCategoryBoxes[0], MAW_CHECK_BOX_CHECKED, buf, 6);

		// make sure the first 4 chars are lower case so we can have our strcmp with "true"
		for(int i = 0; i < 4; i++) {
			buf[i] = tolower(buf[i]);
		}

		if (strcmp(buf,"true") == 0)
		{
			// Check the other ones.
			for (int i=1; i < mCategoryBoxes.size(); i++)
			{
				maWidgetSetProperty(mCategoryBoxes[i], MAW_CHECK_BOX_CHECKED, "true");
			}
		}
		else
		{
			// Uncheck all.
			for (int i=1; i < mCategoryBoxes.size(); i++)
			{
				maWidgetSetProperty(mCategoryBoxes[i], MAW_CHECK_BOX_CHECKED, "false");
			}
		}
	}
	else
	{
		// If any other category then All is unchecked, than uncheck All also.
		for (int i=1; i< mCategoryBoxes.size(); i++)
		{
			if ( mCategoryBoxes[i] == widgetHandle )
			{
				char buf[6];
				maWidgetGetProperty
				(mCategoryBoxes[i], MAW_CHECK_BOX_CHECKED, buf, 6);
				if (strcmp(buf,"false") == 0)
				{
					maWidgetSetProperty(
						mCategoryBoxes[0], MAW_CHECK_BOX_CHECKED, "false");
				}
				break;
			}
		}
	}
}