/**
 * Creates a button and adds it to the main menu
 * Adds on the button a command that sends the connection request to Facebook
 */
void FacebookDemoMoblet::addNotesButton(FacebookDemoGUI::FacebookDemoScreen *menu)
{
	using namespace FacebookDemoGUI;
	using namespace FacebookDemoApplication;

	OpenMenuCommand *notesButtonCmd = new OpenMenuCommand(menu);

	/**
	 * We only want to retrieve from Facebook the "id", "subject" and "from" fields from an Album object
	 */
	MAUtil::Vector<MAUtil::String> fields;
	fields.add("id");
	fields.add("subject");
//	fields.add("from");
	ConnectionRequestCommand *displayNotesCmd = new ConnectionRequestCommand( mFacebookManager,
			notesButtonCmd->getMenuScreen(),
			Connections<User>::notes(), fields, "me");
	ListItem *displayNotes = new ListItem(displayNotesCmd, "Display notes");
	notesButtonCmd->addMenuItem(displayNotes);

	//create new friend list
	AddCommand<Note> *createNoteCmd = new AddCommand<Note>( mFacebookManager,
			notesButtonCmd->getMenuScreen());
	createNoteCmd->setNoteParams("New note created with MOSYNC_SDK", "Testing creating a note with Facebook library");
	ListItem *createNote = new ListItem(createNoteCmd, "Create Note");
	notesButtonCmd->addMenuItem(createNote);

	ListItem *listsButton = new ListItem(notesButtonCmd, "notes");
	menu->add(listsButton);
}
/**
 * Creates a button and adds it to the main menu
 * Adds on the button a command that sends the connection request to Facebook
 */
void FacebookDemoMoblet::addStatusMessagesButton(FacebookDemoGUI::FacebookDemoScreen *menu)
{
	using namespace FacebookDemoGUI;
	using namespace FacebookDemoApplication;

	OpenMenuCommand *statusButtonCmd = new OpenMenuCommand(menu);

	/**
	 * We only want to retrieve from Facebook the "name", "id", "message" fields from an StatusMessage object
	 */
	MAUtil::Vector<MAUtil::String> fields;
	fields.add("id");
	fields.add("message");
	ConnectionRequestCommand *displayStatusesCmd = new ConnectionRequestCommand( mFacebookManager,
			menu, Connections<User>::statuses(), fields, "me");
	ListItem *displayStatuses = new ListItem(displayStatusesCmd, "Display status messages");
	statusButtonCmd->addMenuItem(displayStatuses);

	//create new status message
	AddCommand<StatusMessage> *createStatusMsgCmd = new AddCommand<StatusMessage>( mFacebookManager, menu);
	createStatusMsgCmd->setMessage("New status message created with MOSYNC_SDK");
	ListItem *createStatusMsg = new ListItem(createStatusMsgCmd, "Create StatusMessage");
	statusButtonCmd->addMenuItem(createStatusMsg);

	ListItem *statusButton = new ListItem(statusButtonCmd, "status messages");
	menu->add(statusButton);
}
/**
 * Creates a button and adds it to the main menu
 * Adds on the button a command that sends the connection request to Facebook
 */
void FacebookDemoMoblet::addCheckinsButton(FacebookDemoGUI::FacebookDemoScreen *menu)
{
	using namespace FacebookDemoGUI;
	using namespace FacebookDemoApplication;

	OpenMenuCommand *checkinsButtonCmd = new OpenMenuCommand(menu);

	/**
	 * We only want to retrieve from Facebook the "place" and "id" fields from an Checkin object
	 */
	MAUtil::Vector<MAUtil::String> fields;
	fields.add("id");
	fields.add("place");
	//fields.add("application");
	ConnectionRequestCommand *displayCheckinsCmd = new ConnectionRequestCommand( mFacebookManager,
			checkinsButtonCmd->getMenuScreen(), Connections<User>::checkins(), fields, "me");

	ListItem *displayCheckins = new ListItem(displayCheckinsCmd, "display checkins");
	checkinsButtonCmd->addMenuItem(displayCheckins);

	//create new checkin
	AddCommand<Checkin> *createCheckinCmd = new AddCommand<Checkin>( mFacebookManager,
			checkinsButtonCmd->getMenuScreen());
	MAUtil::String placeIdMoSync = "126381597427662";
	Coordinate coordMoSync;
	coordMoSync.mLatitude = "59.339451";
	coordMoSync.mLongitude = "18.05798";
	createCheckinCmd->setCheckinParams(placeIdMoSync, coordMoSync);

	ListItem *createCheckin = new ListItem(createCheckinCmd, "create checkin");
	checkinsButtonCmd->addMenuItem(createCheckin);

	ListItem *checkinsButton = new ListItem(checkinsButtonCmd, "checkins");
	menu->add(checkinsButton);
}
/**
 * Creates a button and adds it to the main menu
 * Adds on the button a command that sends the connection request to Facebook
 */
void FacebookDemoMoblet::addAlbumsButton(FacebookDemoGUI::FacebookDemoScreen *menu)
{
	using namespace FacebookDemoGUI;
	using namespace FacebookDemoApplication;

	OpenMenuCommand *albumsButtonCmd = new OpenMenuCommand(menu);

	/**
	 * We only want to retrieve from Facebook the "name", "id", "description" and "count" fields from an Album object
	 */
	MAUtil::Vector<MAUtil::String> fields;
	fields.add("name");
	fields.add("id");
//	fields.add("description");
//	fields.add("count");
	ConnectionRequestCommand *displayAlbumsCmd = new ConnectionRequestCommand(  mFacebookManager,
			albumsButtonCmd->getMenuScreen(),
			Connections<User>::albums(), fields, "me");

	ListItem *displayAlbums = new ListItem(displayAlbumsCmd, "display albums");
	albumsButtonCmd->addMenuItem(displayAlbums);

	//create new album
	AddCommand<Album> *createAlbumCmd = new AddCommand<Album>( mFacebookManager,
			albumsButtonCmd->getMenuScreen());
	createAlbumCmd->setAlbumName("New album created with MOSYNC_SDK");

	ListItem *createAlbum = new ListItem(createAlbumCmd, "create album");
	albumsButtonCmd->addMenuItem(createAlbum);

	ListItem *albumsButton = new ListItem(albumsButtonCmd, "albums");
	menu->add(albumsButton);
}
Exemplo n.º 5
0
void AddCommandTest::testAddItem()
{
    QTemporaryFile tempFile;
    tempFile.setAutoRemove(false);
    tempFile.open();
    tempFile.write("Hello World!");

    const char *args[6] = {
        "akonadiclient",
        "add",
        "/res3",
        tempFile.fileName().toLocal8Bit().data(),
        "--base",
        QDir::tempPath().toLocal8Bit().data()
    };

    tempFile.close();
    KCmdLineArgs *parsedArgs = getParsedArgs(6, args);

    AddCommand *command = new AddCommand(this);

    int ret = command->init(parsedArgs);
    QCOMPARE(ret, 0);

    ret = runCommand(command);
    QCOMPARE(ret, 0);
}
Exemplo n.º 6
0
					void Client::main(std::string args[])
					{
						//1:组装命令和接收者
						//创建接收者
						OperationApi *operation = new Operation();
						//创建命令
						AddCommand *addCmd = new AddCommand(5);
						SubstractCommand *substractCmd = new SubstractCommand(3);
						//组装命令和接收者
						addCmd->setOperation(operation);
						substractCmd->setOperation(operation);

						//2:把命令设置到持有者,就是计算器里面
						Calculator *calculator = new Calculator();
						calculator->setAddCmd(addCmd);
						calculator->setSubstractCmd(substractCmd);

						//3:模拟按下按钮,测试一下
						calculator->addPressed();
						puts("一次加法运算后的结果为:"+operation->getResult());
						calculator->substractPressed();
						puts("一次减法运算后的结果为:"+operation->getResult());

						//测试撤消
						calculator->undoPressed();
						puts("撤销一次后的结果为:"+operation->getResult());
						calculator->undoPressed();
						puts("再撤销一次后的结果为:"+operation->getResult());

						//测试恢复
						calculator->redoPressed();
						puts("恢复操作一次后的结果为:"+operation->getResult());
						calculator->redoPressed();
						puts("再恢复操作一次后的结果为:"+operation->getResult());
					}
/**
 * Creates a button and adds it to the main menu
 * Adds on the button a command that sends the connection request to Facebook
 */
void FacebookDemoMoblet::addFriendListsButton(FacebookDemoGUI::FacebookDemoScreen *menu)
{
	using namespace FacebookDemoGUI;
	using namespace FacebookDemoApplication;

	OpenMenuCommand *listsButtonCmd = new OpenMenuCommand(menu);

	//display the friend lists
	ConnectionRequestCommand *displayListsCmd = new ConnectionRequestCommand( mFacebookManager,
			listsButtonCmd->getMenuScreen(),
			Connections<User>::friendlists(), "me");
	ListItem *displayLists = new ListItem(displayListsCmd, "Display friend lists");
	listsButtonCmd->addMenuItem(displayLists);

	//create new friend list
	tm tmTimeStamp;
	split_time(maLocalTime(), &tmTimeStamp);
	MAUtil::String strTimeStamp;
	strTimeStamp = MAUtil::integerToString(tmTimeStamp.tm_year + 1900);
	strTimeStamp += "/";
	strTimeStamp += MAUtil::integerToString(tmTimeStamp.tm_mon);
	strTimeStamp += "/";
	strTimeStamp += MAUtil::integerToString(tmTimeStamp.tm_mday);
	strTimeStamp += "_";
	strTimeStamp += MAUtil::integerToString(tmTimeStamp.tm_hour);
	strTimeStamp += ":";
	strTimeStamp += MAUtil::integerToString(tmTimeStamp.tm_min);
	strTimeStamp += ":";
	strTimeStamp += MAUtil::integerToString(tmTimeStamp.tm_sec);

//	strTimeStamp += MAUtil::integerToString(tmTimeStamp.tm_sec + rand());

	AddCommand<FriendList> *createListCmd = new AddCommand<FriendList>( mFacebookManager,
			listsButtonCmd->getMenuScreen() );
	createListCmd->setFriendlistName(strTimeStamp);

	ListItem *createList = new ListItem(createListCmd, "Create friend list");
	listsButtonCmd->addMenuItem(createList);

	ListItem *listsButton = new ListItem(listsButtonCmd, "friendLists");
	menu->add(listsButton);
}
/**
 * Creates a button and adds it to the main menu
 * Adds on the button a command that sends the connection request to Facebook
 */
void FacebookDemoMoblet::addEventsButton(FacebookDemoGUI::FacebookDemoScreen *menu)
{
	using namespace FacebookDemoGUI;
	using namespace FacebookDemoApplication;

	OpenMenuCommand *eventsButtonCmd = new OpenMenuCommand(menu);

	/**
	 * We only want to retrieve from Facebook the "name", "id", "name" and "start_time" and "location" fields from an Event object
	 */
	MAUtil::Vector<MAUtil::String> fields;
	fields.add("id");
	fields.add("name");
//	fields.add("start_time");
	fields.add("location");
	ConnectionRequestCommand *displayEventsCmd = new ConnectionRequestCommand( mFacebookManager,
			eventsButtonCmd->getMenuScreen(), Connections<User>::events(), fields, "me");

	ListItem *displayEvents = new ListItem(displayEventsCmd, "Display events");
	eventsButtonCmd->addMenuItem(displayEvents);

	//create new event
	AddCommand<Event> *createEventCmd = new AddCommand<Event>( mFacebookManager,
			eventsButtonCmd->getMenuScreen());

	//event
	UnixTimeStamp startTimeStamp(Date("2012", "10", "6"), Time("4","15","30"));
	UnixTimeStamp endTimeStamp(Date("2012", "10", "6"), Time("5", "20","00"));

	createEventCmd->setEventParams("New event created with MOSYNC_SDK", startTimeStamp, endTimeStamp,
			"Testing creating an event", "Stockholm");

	ListItem *createEvent = new ListItem(createEventCmd, "Create event");
	eventsButtonCmd->addMenuItem(createEvent);

	ListItem *eventsButton = new ListItem(eventsButtonCmd, "events");
	menu->add(eventsButton);
}
Exemplo n.º 9
0
void AddCommandTest::testAddItem()
{
    QDir dir(mTempDir->name());
    dir.cd("foo");
    QDir::setCurrent(dir.absolutePath());

    CollectionResolveJob *resolveJob = new CollectionResolveJob("/res3", this);
    QVERIFY(resolveJob->hasUsableInput());
    AKVERIFYEXEC(resolveJob);

    QVERIFY(resolveJob->collection().isValid());

    Collection col;
    col.setName("test");
    col.setParentCollection(resolveJob->collection());

    CollectionCreateJob *createJob = new CollectionCreateJob(col, this);
    AKVERIFYEXEC(createJob);

    col = createJob->collection();
    QVERIFY(col.isValid());

    const int numArgs = 5;
    QVector<QByteArray> args;
    args.reserve(numArgs);
    args << "akonadiclient" << "add" << "/res3/test" << "../test.txt" << "bar";

    const char *testArgs[numArgs];
    for (int i = 0; i < numArgs; i++) {
        testArgs[i] = args.at(i).data();
    }

    KCmdLineArgs *parsedArgs = getParsedArgs(numArgs, testArgs);

    AddCommand *command = new AddCommand(this);

    int ret = command->init(parsedArgs);
    QCOMPARE(ret, 0);

    ret = runCommand(command);
    QCOMPARE(ret, 0);

    ItemFetchJob *itemFetchJob1 = new ItemFetchJob(col, this);
    itemFetchJob1->fetchScope().fetchAllAttributes(false);
    itemFetchJob1->fetchScope().fetchFullPayload(true);

    AKVERIFYEXEC(itemFetchJob1);

    QCOMPARE(itemFetchJob1->items().count(), 1);
    QCOMPARE(itemFetchJob1->items().at(0).payloadData(), QByteArray("Testing"));

    CollectionFetchJob *fetchJob1 = new CollectionFetchJob(col, CollectionFetchJob::FirstLevel, this);
    AKVERIFYEXEC(fetchJob1);

    QCOMPARE(fetchJob1->collections().count(), 1);

    col = fetchJob1->collections().at(0);
    QCOMPARE(col.name(), QString("bar"));

    ItemFetchJob *itemFetchJob2 = new ItemFetchJob(col, this);
    itemFetchJob2->fetchScope().fetchAllAttributes(false);
    itemFetchJob2->fetchScope().fetchFullPayload(true);

    AKVERIFYEXEC(itemFetchJob2);
    QCOMPARE(itemFetchJob2->items().count(), 1);
    QCOMPARE(itemFetchJob2->items().at(0).payloadData(), QByteArray("Bar Item"));
}