Example #1
0
WLayoutChatLog::WLayoutChatLog(ITreeItemChatLogEvents * pContactOrGroupParent)
	{
	Assert(pContactOrGroupParent != NULL);
	m_pContactOrGroup_NZ = pContactOrGroupParent;
	m_pContactParent_YZ = (pContactOrGroupParent->EGetRuntimeClass() == RTI(TContact)) ? (TContact *)pContactOrGroupParent : NULL;
	m_pwFindText = NULL;
	m_tidChatStateComposing = d_zNA;

	#ifdef COMPILE_WITH_CHATLOG_HTML
	m_pwChatLog_NZ = new WChatLogHtml(this, pContactOrGroupParent);
	#else
	m_pwChatLog_NZ = new WChatLog(this, pContactOrGroupParent);
	#endif
	setStretchFactor(0, 5);
	/*
	if (pContactParent_YZ != NULL)
		{
		if (pContactParent_YZ->m_uFlagsContact & TContact::FC_kfContactNeedsInvitation)
			WidgetContactInvitation_Show();
		if (pContactParent_YZ->m_uFlagsContact & TContact::FC_kfContactUnsolicited)
			Layout_NoticeAuxiliaryAdd(PA_DELETING new WNoticeContactUnsolicited(pContactParent_YZ));
		}
	*/

	m_pwChatInput = new WChatInput(this);

	QWidget * pWidget = new QWidget(this);
//	pWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
	OLayoutHorizontal * pLayoutMessageInput = new OLayoutHorizontal(pWidget);
	pLayoutMessageInput->setContentsMargins(0, 0, 5, 0);
	pLayoutMessageInput->addWidget(m_pwChatInput);
	OLayoutVertical * pLayoutButtons = new OLayoutVerticalAlignTop(pLayoutMessageInput);
	pLayoutButtons->setSpacing(0);
	m_pwButtonSendBitcoin = new WButtonIconForToolbar(eMenuIcon_Bitcoin, "Send Bitcoins");
	pLayoutButtons->addWidget(m_pwButtonSendBitcoin);
	connect(m_pwButtonSendBitcoin, SIGNAL(clicked()), this, SLOT(SL_ButtonSendBitcoin()));

	WButtonIconForToolbar * pwButton = new WButtonIconForToolbar(eMenuIcon_FileUpload, "Send File\n\nYou may drag and drop the file, or copy & paste the file from Windows Explorer");
	pLayoutButtons->addWidget(pwButton);
	connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonSendFile()));

	pwButton = new WButtonIconForToolbar(eMenuIcon_ContactAdd, "Add people to the converstation");
	pLayoutButtons->addWidget(pwButton);
	connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonAddContacts()));

	pwButton = new WButtonIconForToolbar(eMenuIcon_Vote, "Send a ballot to the group to vote");
	pLayoutButtons->addWidget(pwButton);
	connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonSendBallot()));

	setChildrenCollapsible(false);		// Do not allow the widget WChatInput() to collapse; it would be very confusing to the user

//	addWidget(PA_CHILD m_pwChatLog);
	//addWidget(PA_CHILD new WFindText(m_pwChatLog->document()));
//	addWidget(PA_CHILD m_pwChatInput);
	setAcceptDrops(true);
	}
WNavigationTree::WNavigationTree() : QDockWidget(tr("Navigation"))
	{
	g_pwNavigationTree = this;
	setObjectName(c_sNavigation);
	m_pTreeWidgetItemEditing = NULL;

	//setStyleSheet("border: 1px solid red;");
	g_pwButtonSwitchProfile = new WButtonIconForToolbarWithDropDownMenu(this, eMenuIconIdentities, NULL);
	g_pwButtonSwitchProfile->setCursor(Qt::ArrowCursor);	// We need to explicitly set the cursor to arrow because the caption uses the OpenHandCursor which every child inherits
	g_pwMenuSwitchProfile = g_pwButtonSwitchProfile->PwGetMenu();
	connect(g_pwMenuSwitchProfile, SIGNAL(aboutToShow()), this, SLOT(SL_MenuProfilesShow()));
	connect(g_pwMenuSwitchProfile, SIGNAL(triggered(QAction*)), this, SLOT(SL_MenuProfileSelected(QAction*)));

#if 1
	setTitleBarWidget(PA_CHILD new WNavigationTreeCaption);	// Customize the title bar of the navigation tree
#endif

	QWidget * pwWidgetLayout = new QWidget(this);	// Since the QDockWidget can handle only one widget, we create a widget with a layout inside
	OLayoutVertical * pLayoutVertical = new OLayoutVertical(pwWidgetLayout);		// Vertical layout to stack the profile switcher, search, tree view and the status.
	Layout_MarginsClear(INOUT pLayoutVertical);
	pLayoutVertical->setSpacing(0);

	WEditSearch * pwEditSearch = new WEditSearch;
	connect(pwEditSearch, SIGNAL(textChanged(QString)), this, SLOT(SL_EditSearchTextChanged(QString)));
	pLayoutVertical->addWidget(pwEditSearch);


	//setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
	setFeatures(/*DockWidgetClosable |*/ DockWidgetMovable | DockWidgetFloatable);	// Hide the close button in the title bar

	m_pwTreeView = new WTreeWidget;
	m_pwTreeView->header()->hide();
	m_pwTreeView->setContextMenuPolicy(Qt::CustomContextMenu);	// Send the signal customContextMenuRequested()
	//m_pwTreeView->setFrameStyle(QFrame::NoFrame);
	connect(m_pwTreeView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(SL_TreeCustomContextMenuRequested(QPoint)));
	connect(m_pwTreeView, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(SL_TreeItemSelectionChanged(QTreeWidgetItem*,QTreeWidgetItem*)));
	connect(m_pwTreeView, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(SL_TreeItemClicked(QTreeWidgetItem*,int)));

	pLayoutVertical->addWidget(m_pwTreeView);

	OLayoutHorizontal * pLayout = new OLayoutHorizontal(pLayoutVertical);
	//pLayout->addWidget(new WLabel("Status:"));

	g_pwButtonStatusOfNavigationTree = new WButtonIconForToolbarWithDropDownMenu(this, eMenuAction_PresenceAccountOffline, "Status: Online");
	g_pwButtonStatusOfNavigationTree->setToolTip("Change your status");

	EMenuAction eMenuAction_Presence = (EMenuAction)(g_uPreferences & P_kmPresenceMask);
	if (eMenuAction_Presence == ezMenuActionNone)
		eMenuAction_Presence = eMenuAction_PresenceAccountOnline;
	Widget_SetIconButton(INOUT g_pwButtonStatusOfNavigationTree, eMenuAction_Presence);
	g_pwMenuStatus = (WMenu *)g_pwButtonStatusOfNavigationTree->menu();
	g_pwMenuStatus->InitAsDymanicMenu();
	/*
	g_pwMenuStatus = new WMenu;
	g_pwMenuStatus->InitAsDymanicMenu();
	g_pwButtonStatusOfNavigationTree->setMenu(g_pwMenuStatus);
	*/
//	connect(g_pMenuStatus, SIGNAL(aboutToShow()), g_pwMainWindow, SLOT(SL_MenuAboutToShow()));
//	connect(g_pMenuStatus, SIGNAL(triggered(QAction*)), g_pwMainWindow, SLOT(SL_MenuActionTriggered(QAction*)));

//	pwButtonStatus->addAction(new QAction("test", pwButtonStatus));

	pLayout->addWidget(g_pwButtonStatusOfNavigationTree);
	pLayout->addStretch();
	//WButtonTextWithIcon * pwButtonAddContact = new WButtonTextWithIcon("Add Peer |Add a new peer to your profile", eMenuAction_ContactAdd);
	WButtonIconForToolbar * pwButtonAddContact = new WButtonIconForToolbar(eMenuAction_ContactAdd, "Add a new peer to your "d_sza_profile);
	pLayout->addWidget(pwButtonAddContact, Qt::AlignBottom);
	connect(pwButtonAddContact, SIGNAL(clicked()), this, SLOT(SL_ContactNew()));

	//pLayoutVertical->addWidget(g_pwButtonStatusOfNavigationTree);
#if 1
	setWidget(PA_CHILD pwWidgetLayout);
#else
	setWidget(PA_CHILD m_pwTreeView);
#endif
	}
void
WLayoutApplicationMayanX::SL_InternetRequestCompleted(QNetworkReply * poNetworkReply)
	{
	CInternetResponseWebMethodXmlSoap oInternetResponse(poNetworkReply);

	// First of all, check if there is an error from the server
	CXmlNode * pXmlNodeError = oInternetResponse.PGetXmlNodeError();
	if (pXmlNodeError != NULL)
		{
		MessageLog_AppendTextFormatSev(eSeverityErrorWarning, "SL_InternetRequestCompleted() with the following error:\n^N", pXmlNodeError);
		int nCode = pXmlNodeError->NFindElementOrAttributeValueNumeric("nCode");
		if (nCode == eCodeUserNotFound)
			{
			// The user is not found or does not exist, therefore clear the m_strxUserID so we may retry
			m_pApplication->m_strxUserID.Empty();
			}
		if (nCode == eCodeUserAlreadyExist)
			{
			// The user already exists, so fetch the xUserID from the
			m_pApplication->m_strxUserID = pXmlNodeError->PszuFindElementValue("xDescriptionParam");
			SL_ExchangeLogin();	// Attempt to login again
			}
		return;
		}

	CXmlNode * pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserRegister");
	if (pXmlNode != NULL)
		{
		m_pApplication->m_strxUserID = pXmlNode->m_pszuTagValue;
		if (!m_pApplication->m_strxUserID.FIsEmptyString())
			SL_ExchangeLogin();		// Attempt to login with the new UserID.
		else
			EMessageBoxWarning("The API 'UserRegister' returned an invalid UserID of value '$S'", &m_pApplication->m_strxUserID);
		return;
		}
	pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserLogin");
	if (pXmlNode != NULL)
		{
		CBin binChallenge;
		binChallenge.BinAppendBinaryDataFromBase64Szv(pXmlNode->PszuFindElementValue("bChallenge"));
		if (!binChallenge.FIsEmptyBinary())
			{
			// We received a challenge, so respond to it now
			CBin binResponseData = m_pApplication->m_pProfileParent->m_strKeyPublic;
			binResponseData.BinAppendCBin(binChallenge);
			//MessageLog_AppendTextFormatCo(d_coBlue, " bIdentity: {B/}\n bChallenge: {B/}\n bIdentity + bChallenge: {B/}\n", &m_pTreeItemParent->m_binKeyPublic, &binChallenge, &binResponseData);
			binResponseData.BinHashToMd5();

			CInternetRequestWebMethodXmlMayanX oRequest("UserLogin");
			oRequest.BinAppendXmlElementText("xUserID", m_pApplication->m_strxUserID);
			oRequest.BinAppendXmlElementBinaryBase64("bResponse", binResponseData);
			m_oInternetServer.RequestSend(&oRequest);
			return;
			}
		if (m_oInternetServer.m_strxSessionID.FIsEmptyString())
			{
			m_oInternetServer.m_strxSessionID = pXmlNode->PszuFindElementValue("xSessionID");
			//m_oInternetServer.m_strxSessionID = (PSZUC)"as8323jas932e";
			if (!m_oInternetServer.m_strxSessionID.FIsEmptyString())
				{
				MessageLog_AppendTextFormatCo(d_coBlue, "Login successful: xSessionID = $S\n", &m_oInternetServer.m_strxSessionID);
				OLayoutHorizontal * poLayoutOrder = new OLayoutHorizontal((QWidget *)NULL);
				m_poLayoutButtons->addRow(poLayoutOrder);
				m_pwEditQuantity = new WEditNumber;
				poLayoutOrder->Layout_AddLabelAndWidgetH_PA("Quantity:", m_pwEditQuantity);
				m_pwEditPrice = new WEditNumber;
				poLayoutOrder->Layout_AddLabelAndWidgetH_PA("Price:", m_pwEditPrice);
				WButtonTextWithIcon * pwButton = new WButtonTextWithIcon("Place Order", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy);
				poLayoutOrder->addWidget(pwButton);
				poLayoutOrder->addWidget(PA_CHILD new QWidget, 1);
				connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonUserOrderAdd()));

				//Updating user balance
				OLayoutHorizontal * poLayoutUserBalance = new OLayoutHorizontal((QWidget *)NULL);
				m_poLayoutButtons->addRow(poLayoutUserBalance);
                m_pwEditUpdateBalanceQuantity = new WEditNumber;
                m_pwEditUpdateBalanceUserId = new WEditNumber;
                poLayoutUserBalance->Layout_AddLabelAndWidgetH_PA("User Id:", m_pwEditUpdateBalanceUserId);
                poLayoutUserBalance->Layout_AddLabelAndWidgetH_PA("Quantity:", m_pwEditUpdateBalanceQuantity);
                m_pwLabelBalance=new WLabel;
				pwButton = new WButtonTextWithIcon("Update Balance", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy);
                poLayoutUserBalance->addWidget(pwButton);
                poLayoutUserBalance->addWidget(m_pwLabelBalance);
				poLayoutUserBalance->addWidget(PA_CHILD new QWidget, 1);
                connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonUserBalanceUpdate()));

                //Cancel an Order
                OLayoutHorizontal * poLayoutCancelAnOrder = new OLayoutHorizontal((QWidget *)NULL);
                m_poLayoutButtons->addRow(poLayoutCancelAnOrder);
                m_pwEditIdToCancelOrder = new WEditNumber;
                poLayoutCancelAnOrder->Layout_AddLabelAndWidgetH_PA("Id:", m_pwEditIdToCancelOrder);
				pwButton = new WButtonTextWithIcon("Cancel Order", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy);
                poLayoutCancelAnOrder->addWidget(pwButton);
                poLayoutCancelAnOrder->addWidget(PA_CHILD new QWidget, 1);
                connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonUserOrderCancel()));

                //Update an Order
                OLayoutHorizontal * poLayoutUpdateAnOrder = new OLayoutHorizontal((QWidget *)NULL);
                m_poLayoutButtons->addRow(poLayoutUpdateAnOrder);
                m_pwEditIdToUpdateOrder = new WEditNumber;
                poLayoutUpdateAnOrder->Layout_AddLabelAndWidgetH_PA("Id:", m_pwEditIdToUpdateOrder);
                m_pwEditPriceToUpdateOrder = new WEditNumber;
                poLayoutUpdateAnOrder->Layout_AddLabelAndWidgetH_PA("Price:", m_pwEditPriceToUpdateOrder);
                m_pwEditQuantityToUpdateOrder = new WEditNumber;
                poLayoutUpdateAnOrder->Layout_AddLabelAndWidgetH_PA("Quantity:", m_pwEditQuantityToUpdateOrder);
				pwButton = new WButtonTextWithIcon("Update Order", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy);
                poLayoutUpdateAnOrder->addWidget(pwButton);
                poLayoutUpdateAnOrder->addWidget(PA_CHILD new QWidget, 1);
                connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonUserOrderUpdate()));

                //Update User's Account
                OLayoutHorizontal* poLayoutUpdateUsersAccount = new OLayoutHorizontal((QWidget *)NULL);
                m_poLayoutButtons->addRow(poLayoutUpdateUsersAccount);
                m_pwEditUpdateAccountId=new WEditNumber;
                m_pwEditUpdateAccountName = new WEdit;
                m_pwEditUpdateAccountRole = new WEditNumber;
                poLayoutUpdateUsersAccount->Layout_AddLabelAndWidgetH_PA("User Id:", m_pwEditUpdateAccountId);
                poLayoutUpdateUsersAccount->Layout_AddLabelAndWidgetH_PA("User Name:", m_pwEditUpdateAccountName);
                poLayoutUpdateUsersAccount->Layout_AddLabelAndWidgetH_PA("User Role:", m_pwEditUpdateAccountRole);
				pwButton = new WButtonTextWithIcon("Update User Account", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy);
                poLayoutUpdateUsersAccount->addWidget(pwButton);
                poLayoutUpdateUsersAccount->addWidget(PA_CHILD new QWidget, 1);
                connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonUserAccountUpdate()));

                //Get User's Document
                OLayoutHorizontal* poLayoutUserDocuments = new OLayoutHorizontal((QWidget *)NULL);
                m_poLayoutButtons->addRow(poLayoutUserDocuments);
                m_pwEditGetUserDocumentId=new WEditNumber;
                poLayoutUserDocuments->Layout_AddLabelAndWidgetH_PA("Document Id:", m_pwEditGetUserDocumentId);
				pwButton = new WButtonTextWithIcon("Get Document", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy);
                poLayoutUserDocuments->addWidget(pwButton);
                poLayoutUserDocuments->addWidget(PA_CHILD new QWidget, 1);
                connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonUserDocumentGet()));

                //Buttons to Fetch Data
                OLayoutHorizontal* poLayoutFetchData = new OLayoutHorizontal((QWidget *)NULL);
                m_poLayoutButtons->addRow(poLayoutFetchData);
                    //Fetching User's Balances

					pwButton = new WButtonTextWithIcon("Fetch User's' Balances", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy);
                    poLayoutFetchData->addWidget(pwButton);
                    connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonFetchUserBalances()));

                    //Fetching Users
					pwButton = new WButtonTextWithIcon("Fetch Users", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy);
                    poLayoutFetchData->addWidget(pwButton);
                    connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonFetchUsers()));

                    //Fetching User's Documents
					pwButton = new WButtonTextWithIcon("Fetch User's Documents", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy);
                    poLayoutFetchData->addWidget(pwButton);
                    connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonFetchUserDocuments()));

                    //Upload a Document
					pwButton = new WButtonTextWithIcon("Upload a Document...", eMenuIcon_Bitcoin); // eMenuIconCoffeeBuy);
                    poLayoutFetchData->addWidget(pwButton);
                    connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonUploadADocument()));

                poLayoutFetchData->addWidget(PA_CHILD new QWidget, 1);

				/*
				// We have a valid Session ID, so we may download the bids.  For this, we will display a new button
				WButtonTextWithIcon * pwButton = new WButtonTextWithIcon("Download Market Bids", eMenuIconCoffeeBuy);
				m_poLayoutButtons->addRow(pwButton);
				connect(pwButton, SIGNAL(clicked()), this, SLOT(SL_ButtonDownloadMarketBids()));
				*/
				m_pwLabelWelcome->hide();
				m_pwButtonRegister->hide();
				DisplayOrders(0);
                DisplayUserBalances(0);
				}
			}
		return;
		} // if (UserLogin)

	pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserOrderAdd");
	if (pXmlNode != NULL)
		{
		DisplayOrders(pXmlNode);
		DisplayMarketOrders(pXmlNode);	// Also add the new order to the Market Orders
		return;
		}
	pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserOrders");
	if (pXmlNode != NULL)
		{
		DisplayOrders(pXmlNode);
		return;
		}

	pXmlNode = oInternetResponse.PGetXmlNodeResponse("MarketOrders");
	if (pXmlNode != NULL)
		{
		DisplayMarketOrders(pXmlNode);
		return;
		}

    pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserBalanceUpdate");
    if (pXmlNode != NULL)
        {
        DisplayUserBalanceUpdated(pXmlNode);
        return;
        }

    pXmlNode = oInternetResponse.PGetXmlNodeResponse("FetchUserBalances");
    if (pXmlNode != NULL)
        {
        MessageLog_AppendTextFormatCo(d_coRed, "Fetching user balances\n\n");
        DisplayUserBalances(pXmlNode);
        return;
        }

    pXmlNode = oInternetResponse.PGetXmlNodeResponse("FetchUsers");
    if (pXmlNode != NULL)
        {
        MessageLog_AppendTextFormatCo(d_coRed, "Fetching all users\n\n");
        DisplayUsers(pXmlNode);
        return;
        }

    pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserAccountUpdate");
    if (pXmlNode != NULL)
        {
        MessageLog_AppendTextFormatCo(d_coRed, "updating user account\n\n");
        DisplayUserAccountUpdate(pXmlNode);
        return;
        }

    pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserDocuments");
    if (pXmlNode != NULL)
        {
        MessageLog_AppendTextFormatCo(d_coRed, "getting all user's documents\n\n");
        DisplayAllUsersDocuments(pXmlNode);
        return;
        }


    pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserDocumentGet");
    if (pXmlNode != NULL)
        {
        MessageLog_AppendTextFormatCo(d_coRed, "getting all user's documents\n\n");
        SaveUsersDocument(pXmlNode);
        return;
            }

    pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserOrderUpdate");
    if (pXmlNode != NULL)
        {
        UserOrderUpdate(pXmlNode);
        return;
            }

    pXmlNode = oInternetResponse.PGetXmlNodeResponse("UserOrderCancel");
    if (pXmlNode != NULL)
        {
        UserOrderCancel(pXmlNode);
        return;
            }

	} // SL_InternetRequestCompleted()