From 5253d1ab77fab1995ede03fb934edd67f1359ba8 Mon Sep 17 00:00:00 2001 From: s_nakamoto Date: Mon, 15 Feb 2010 04:03:07 +0000 Subject: strip out unfinished product, review and market stuff, enable _() instead of wxT() in uiproject.fbp so it uses wxGetTranslation for the wxFormBuilder generated part of the UI git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@64 1a98c847-1fd6-4fd8-948a-caf3550aa51b --- ui.cpp | 930 +---------------------------------------------------------------- 1 file changed, 10 insertions(+), 920 deletions(-) (limited to 'ui.cpp') diff --git a/ui.cpp b/ui.cpp index aad599c77c..f506fcf3e7 100644 --- a/ui.cpp +++ b/ui.cpp @@ -7,22 +7,15 @@ #include #endif -void ThreadRequestProductDetails(void* parg); -void ThreadRandSendTest(void* parg); bool GetStartOnSystemStartup(); void SetStartOnSystemStartup(bool fAutoStart); DEFINE_EVENT_TYPE(wxEVT_UITHREADCALL) -DEFINE_EVENT_TYPE(wxEVT_REPLY1) -DEFINE_EVENT_TYPE(wxEVT_REPLY2) -DEFINE_EVENT_TYPE(wxEVT_REPLY3) CMainFrame* pframeMain = NULL; CMyTaskBarIcon* ptaskbaricon = NULL; -bool fRandSendTest = false; -void RandSend(); extern int g_isPainting; bool fClosedToTray = false; @@ -210,93 +203,6 @@ int ThreadSafeMessageBox(const string& message, const string& caption, int style -////////////////////////////////////////////////////////////////////////////// -// -// Custom events -// -// If this code gets used again, it should be replaced with something like UIThreadCall - -set setCallbackAvailable; -CCriticalSection cs_setCallbackAvailable; - -void AddCallbackAvailable(void* p) -{ - CRITICAL_BLOCK(cs_setCallbackAvailable) - setCallbackAvailable.insert(p); -} - -void RemoveCallbackAvailable(void* p) -{ - CRITICAL_BLOCK(cs_setCallbackAvailable) - setCallbackAvailable.erase(p); -} - -bool IsCallbackAvailable(void* p) -{ - CRITICAL_BLOCK(cs_setCallbackAvailable) - return setCallbackAvailable.count(p); - return false; -} - -template -void AddPendingCustomEvent(wxEvtHandler* pevthandler, int nEventID, const T pbeginIn, const T pendIn) -{ - // Need to rewrite with something like UIThreadCall - // I'm tired of maintaining this hack that's only called by unfinished unused code. - assert(("Unimplemented", 0)); - //if (!pevthandler) - // return; - // - //const char* pbegin = (pendIn != pbeginIn) ? &pbeginIn[0] : NULL; - //const char* pend = pbegin + (pendIn - pbeginIn) * sizeof(pbeginIn[0]); - //wxCommandEvent event(nEventID); - //wxString strData(wxChar(0), (pend - pbegin) / sizeof(wxChar) + 1); - //memcpy(&strData[0], pbegin, pend - pbegin); - //event.SetString(strData); - //event.SetInt(pend - pbegin); - // - //pevthandler->AddPendingEvent(event); -} - -template -void AddPendingCustomEvent(wxEvtHandler* pevthandler, int nEventID, const T& obj) -{ - CDataStream ss; - ss << obj; - AddPendingCustomEvent(pevthandler, nEventID, ss.begin(), ss.end()); -} - -void AddPendingReplyEvent1(void* pevthandler, CDataStream& vRecv) -{ - if (IsCallbackAvailable(pevthandler)) - AddPendingCustomEvent((wxEvtHandler*)pevthandler, wxEVT_REPLY1, vRecv.begin(), vRecv.end()); -} - -void AddPendingReplyEvent2(void* pevthandler, CDataStream& vRecv) -{ - if (IsCallbackAvailable(pevthandler)) - AddPendingCustomEvent((wxEvtHandler*)pevthandler, wxEVT_REPLY2, vRecv.begin(), vRecv.end()); -} - -void AddPendingReplyEvent3(void* pevthandler, CDataStream& vRecv) -{ - if (IsCallbackAvailable(pevthandler)) - AddPendingCustomEvent((wxEvtHandler*)pevthandler, wxEVT_REPLY3, vRecv.begin(), vRecv.end()); -} - -CDataStream GetStreamFromEvent(const wxCommandEvent& event) -{ - wxString strData = event.GetString(); - const char* pszBegin = strData.c_str(); - return CDataStream(pszBegin, pszBegin + event.GetInt(), SER_NETWORK); -} - - - - - - - ////////////////////////////////////////////////////////////////////////////// // // CMainFrame @@ -1180,16 +1086,6 @@ void CMainFrame::OnMouseEventsAddress(wxMouseEvent& event) event.Skip(); } -void CMainFrame::OnButtonCopy(wxCommandEvent& event) -{ - // Copy address box to clipboard - if (wxTheClipboard->Open()) - { - wxTheClipboard->SetData(new wxTextDataObject(m_textCtrlAddress->GetValue())); - wxTheClipboard->Close(); - } -} - void CMainFrame::OnButtonChange(wxCommandEvent& event) { CYourAddressDialog dialog(this, string(m_textCtrlAddress->GetValue())); @@ -1208,6 +1104,16 @@ void CMainFrame::OnButtonChange(wxCommandEvent& event) } } +void CMainFrame::OnButtonCopy(wxCommandEvent& event) +{ + // Copy address box to clipboard + if (wxTheClipboard->Open()) + { + wxTheClipboard->SetData(new wxTextDataObject(m_textCtrlAddress->GetValue())); + wxTheClipboard->Close(); + } +} + void CMainFrame::OnListItemActivated(wxListEvent& event) { uint256 hash((string)GetItemText(m_listCtrl, event.GetIndex(), 1)); @@ -1228,28 +1134,6 @@ void CMainFrame::OnListItemActivated(wxListEvent& event) //pdialog->Show(); } -void CMainFrame::OnListItemActivatedProductsSent(wxListEvent& event) -{ - CProduct& product = *(CProduct*)event.GetItem().GetData(); - CEditProductDialog* pdialog = new CEditProductDialog(this); - pdialog->SetProduct(product); - pdialog->Show(); -} - -void CMainFrame::OnListItemActivatedOrdersSent(wxListEvent& event) -{ - CWalletTx& order = *(CWalletTx*)event.GetItem().GetData(); - CViewOrderDialog* pdialog = new CViewOrderDialog(this, order, false); - pdialog->Show(); -} - -void CMainFrame::OnListItemActivatedOrdersReceived(wxListEvent& event) -{ - CWalletTx& order = *(CWalletTx*)event.GetItem().GetData(); - CViewOrderDialog* pdialog = new CViewOrderDialog(this, order, true); - pdialog->Show(); -} - @@ -2525,800 +2409,6 @@ void CAddressBookDialog::OnClose(wxCloseEvent& event) -////////////////////////////////////////////////////////////////////////////// -// -// CProductsDialog -// - -bool CompareIntStringPairBestFirst(const pair& item1, const pair& item2) -{ - return (item1.first > item2.first); -} - -CProductsDialog::CProductsDialog(wxWindow* parent) : CProductsDialogBase(parent) -{ - // Init column headers - m_listCtrl->InsertColumn(0, "Title", wxLIST_FORMAT_LEFT, 200); - m_listCtrl->InsertColumn(1, "Price", wxLIST_FORMAT_LEFT, 80); - m_listCtrl->InsertColumn(2, "Seller", wxLIST_FORMAT_LEFT, 80); - m_listCtrl->InsertColumn(3, "Stars", wxLIST_FORMAT_LEFT, 50); - m_listCtrl->InsertColumn(4, "Power", wxLIST_FORMAT_LEFT, 50); - - // Tally top categories - map mapTopCategories; - CRITICAL_BLOCK(cs_mapProducts) - for (map::iterator mi = mapProducts.begin(); mi != mapProducts.end(); ++mi) - mapTopCategories[(*mi).second.mapValue["category"]]++; - - // Sort top categories - vector > vTopCategories; - for (map::iterator mi = mapTopCategories.begin(); mi != mapTopCategories.end(); ++mi) - vTopCategories.push_back(make_pair((*mi).second, (*mi).first)); - sort(vTopCategories.begin(), vTopCategories.end(), CompareIntStringPairBestFirst); - - // Fill categories combo box - int nLimit = 250; - for (vector >::iterator it = vTopCategories.begin(); it != vTopCategories.end() && nLimit-- > 0; ++it) - m_comboBoxCategory->Append((*it).second); - - // Fill window with initial search - //wxCommandEvent event; - //OnButtonSearch(event); -} - -void CProductsDialog::OnCombobox(wxCommandEvent& event) -{ - OnButtonSearch(event); -} - -bool CompareProductsBestFirst(const CProduct* p1, const CProduct* p2) -{ - return (p1->nAtoms > p2->nAtoms); -} - -void CProductsDialog::OnButtonSearch(wxCommandEvent& event) -{ - string strCategory = (string)m_comboBoxCategory->GetValue(); - string strSearch = (string)m_textCtrlSearch->GetValue(); - - // Search products - vector vProductsFound; - CRITICAL_BLOCK(cs_mapProducts) - { - for (map::iterator mi = mapProducts.begin(); mi != mapProducts.end(); ++mi) - { - CProduct& product = (*mi).second; - if (product.mapValue["category"].find(strCategory) != -1) - { - if (product.mapValue["title"].find(strSearch) != -1 || - product.mapValue["description"].find(strSearch) != -1 || - product.mapValue["seller"].find(strSearch) != -1) - { - vProductsFound.push_back(&product); - } - } - } - } - - // Sort - sort(vProductsFound.begin(), vProductsFound.end(), CompareProductsBestFirst); - - // Display - foreach(CProduct* pproduct, vProductsFound) - { - InsertLine(m_listCtrl, - pproduct->mapValue["title"], - pproduct->mapValue["price"], - pproduct->mapValue["seller"], - pproduct->mapValue["stars"], - itostr(pproduct->nAtoms)); - } -} - -void CProductsDialog::OnListItemActivated(wxListEvent& event) -{ - // Doubleclick opens product - CViewProductDialog* pdialog = new CViewProductDialog(this, m_vProduct[event.GetIndex()]); - pdialog->Show(); -} - - - - - - - -////////////////////////////////////////////////////////////////////////////// -// -// CEditProductDialog -// - -CEditProductDialog::CEditProductDialog(wxWindow* parent) : CEditProductDialogBase(parent) -{ - m_textCtrlLabel[0 ] = m_textCtrlLabel0; - m_textCtrlLabel[1 ] = m_textCtrlLabel1; - m_textCtrlLabel[2 ] = m_textCtrlLabel2; - m_textCtrlLabel[3 ] = m_textCtrlLabel3; - m_textCtrlLabel[4 ] = m_textCtrlLabel4; - m_textCtrlLabel[5 ] = m_textCtrlLabel5; - m_textCtrlLabel[6 ] = m_textCtrlLabel6; - m_textCtrlLabel[7 ] = m_textCtrlLabel7; - m_textCtrlLabel[8 ] = m_textCtrlLabel8; - m_textCtrlLabel[9 ] = m_textCtrlLabel9; - m_textCtrlLabel[10] = m_textCtrlLabel10; - m_textCtrlLabel[11] = m_textCtrlLabel11; - m_textCtrlLabel[12] = m_textCtrlLabel12; - m_textCtrlLabel[13] = m_textCtrlLabel13; - m_textCtrlLabel[14] = m_textCtrlLabel14; - m_textCtrlLabel[15] = m_textCtrlLabel15; - m_textCtrlLabel[16] = m_textCtrlLabel16; - m_textCtrlLabel[17] = m_textCtrlLabel17; - m_textCtrlLabel[18] = m_textCtrlLabel18; - m_textCtrlLabel[19] = m_textCtrlLabel19; - - m_textCtrlField[0 ] = m_textCtrlField0; - m_textCtrlField[1 ] = m_textCtrlField1; - m_textCtrlField[2 ] = m_textCtrlField2; - m_textCtrlField[3 ] = m_textCtrlField3; - m_textCtrlField[4 ] = m_textCtrlField4; - m_textCtrlField[5 ] = m_textCtrlField5; - m_textCtrlField[6 ] = m_textCtrlField6; - m_textCtrlField[7 ] = m_textCtrlField7; - m_textCtrlField[8 ] = m_textCtrlField8; - m_textCtrlField[9 ] = m_textCtrlField9; - m_textCtrlField[10] = m_textCtrlField10; - m_textCtrlField[11] = m_textCtrlField11; - m_textCtrlField[12] = m_textCtrlField12; - m_textCtrlField[13] = m_textCtrlField13; - m_textCtrlField[14] = m_textCtrlField14; - m_textCtrlField[15] = m_textCtrlField15; - m_textCtrlField[16] = m_textCtrlField16; - m_textCtrlField[17] = m_textCtrlField17; - m_textCtrlField[18] = m_textCtrlField18; - m_textCtrlField[19] = m_textCtrlField19; - - m_buttonDel[0 ] = m_buttonDel0; - m_buttonDel[1 ] = m_buttonDel1; - m_buttonDel[2 ] = m_buttonDel2; - m_buttonDel[3 ] = m_buttonDel3; - m_buttonDel[4 ] = m_buttonDel4; - m_buttonDel[5 ] = m_buttonDel5; - m_buttonDel[6 ] = m_buttonDel6; - m_buttonDel[7 ] = m_buttonDel7; - m_buttonDel[8 ] = m_buttonDel8; - m_buttonDel[9 ] = m_buttonDel9; - m_buttonDel[10] = m_buttonDel10; - m_buttonDel[11] = m_buttonDel11; - m_buttonDel[12] = m_buttonDel12; - m_buttonDel[13] = m_buttonDel13; - m_buttonDel[14] = m_buttonDel14; - m_buttonDel[15] = m_buttonDel15; - m_buttonDel[16] = m_buttonDel16; - m_buttonDel[17] = m_buttonDel17; - m_buttonDel[18] = m_buttonDel18; - m_buttonDel[19] = m_buttonDel19; - - for (int i = 1; i < FIELDS_MAX; i++) - ShowLine(i, false); - - LayoutAll(); -} - -void CEditProductDialog::LayoutAll() -{ - m_scrolledWindow->Layout(); - m_scrolledWindow->GetSizer()->Fit(m_scrolledWindow); - this->Layout(); -} - -void CEditProductDialog::ShowLine(int i, bool fShow) -{ - m_textCtrlLabel[i]->Show(fShow); - m_textCtrlField[i]->Show(fShow); - m_buttonDel[i]->Show(fShow); -} - -void CEditProductDialog::OnButtonDel0(wxCommandEvent& event) { OnButtonDel(event, 0); } -void CEditProductDialog::OnButtonDel1(wxCommandEvent& event) { OnButtonDel(event, 1); } -void CEditProductDialog::OnButtonDel2(wxCommandEvent& event) { OnButtonDel(event, 2); } -void CEditProductDialog::OnButtonDel3(wxCommandEvent& event) { OnButtonDel(event, 3); } -void CEditProductDialog::OnButtonDel4(wxCommandEvent& event) { OnButtonDel(event, 4); } -void CEditProductDialog::OnButtonDel5(wxCommandEvent& event) { OnButtonDel(event, 5); } -void CEditProductDialog::OnButtonDel6(wxCommandEvent& event) { OnButtonDel(event, 6); } -void CEditProductDialog::OnButtonDel7(wxCommandEvent& event) { OnButtonDel(event, 7); } -void CEditProductDialog::OnButtonDel8(wxCommandEvent& event) { OnButtonDel(event, 8); } -void CEditProductDialog::OnButtonDel9(wxCommandEvent& event) { OnButtonDel(event, 9); } -void CEditProductDialog::OnButtonDel10(wxCommandEvent& event) { OnButtonDel(event, 10); } -void CEditProductDialog::OnButtonDel11(wxCommandEvent& event) { OnButtonDel(event, 11); } -void CEditProductDialog::OnButtonDel12(wxCommandEvent& event) { OnButtonDel(event, 12); } -void CEditProductDialog::OnButtonDel13(wxCommandEvent& event) { OnButtonDel(event, 13); } -void CEditProductDialog::OnButtonDel14(wxCommandEvent& event) { OnButtonDel(event, 14); } -void CEditProductDialog::OnButtonDel15(wxCommandEvent& event) { OnButtonDel(event, 15); } -void CEditProductDialog::OnButtonDel16(wxCommandEvent& event) { OnButtonDel(event, 16); } -void CEditProductDialog::OnButtonDel17(wxCommandEvent& event) { OnButtonDel(event, 17); } -void CEditProductDialog::OnButtonDel18(wxCommandEvent& event) { OnButtonDel(event, 18); } -void CEditProductDialog::OnButtonDel19(wxCommandEvent& event) { OnButtonDel(event, 19); } - -void CEditProductDialog::OnButtonDel(wxCommandEvent& event, int n) -{ - Freeze(); - int x, y; - m_scrolledWindow->GetViewStart(&x, &y); - int i; - for (i = n; i < FIELDS_MAX-1; i++) - { - m_textCtrlLabel[i]->SetValue(m_textCtrlLabel[i+1]->GetValue()); - m_textCtrlField[i]->SetValue(m_textCtrlField[i+1]->GetValue()); - if (!m_buttonDel[i+1]->IsShown()) - break; - } - m_textCtrlLabel[i]->SetValue(""); - m_textCtrlField[i]->SetValue(""); - ShowLine(i, false); - m_buttonAddField->Enable(true); - LayoutAll(); - m_scrolledWindow->Scroll(0, y); - Thaw(); -} - -void CEditProductDialog::OnButtonAddField(wxCommandEvent& event) -{ - for (int i = 0; i < FIELDS_MAX; i++) - { - if (!m_buttonDel[i]->IsShown()) - { - Freeze(); - ShowLine(i, true); - if (i == FIELDS_MAX-1) - m_buttonAddField->Enable(false); - LayoutAll(); - m_scrolledWindow->Scroll(0, 99999); - Thaw(); - break; - } - } -} - -void AddToMyProducts(CProduct product) -{ - CProduct& productInsert = mapMyProducts[product.GetHash()]; - productInsert = product; - //InsertLine(pframeMain->m_listCtrlProductsSent, &productInsert, - // product.mapValue["category"], - // product.mapValue["title"].substr(0, 100), - // product.mapValue["description"].substr(0, 100), - // product.mapValue["price"], - // ""); -} - -void CEditProductDialog::OnButtonSend(wxCommandEvent& event) -{ - CProduct product; - GetProduct(product); - - // Sign the detailed product - product.vchPubKeyFrom = keyUser.GetPubKey(); - if (!keyUser.Sign(product.GetSigHash(), product.vchSig)) - { - wxMessageBox("Error digitally signing the product "); - return; - } - - // Save detailed product - AddToMyProducts(product); - - // Strip down to summary product - product.mapDetails.clear(); - product.vOrderForm.clear(); - - // Sign the summary product - if (!keyUser.Sign(product.GetSigHash(), product.vchSig)) - { - wxMessageBox("Error digitally signing the product "); - return; - } - - // Verify - if (!product.CheckProduct()) - { - wxMessageBox("Errors found in product "); - return; - } - - // Broadcast - AdvertStartPublish(pnodeLocalHost, MSG_PRODUCT, 0, product); - - Destroy(); -} - -void CEditProductDialog::OnButtonPreview(wxCommandEvent& event) -{ - CProduct product; - GetProduct(product); - CViewProductDialog* pdialog = new CViewProductDialog(this, product); - pdialog->Show(); -} - -void CEditProductDialog::OnButtonCancel(wxCommandEvent& event) -{ - Destroy(); -} - -void CEditProductDialog::SetProduct(const CProduct& productIn) -{ - CProduct product = productIn; - - m_comboBoxCategory->SetValue(product.mapValue["category"]); - m_textCtrlTitle->SetValue(product.mapValue["title"]); - m_textCtrlPrice->SetValue(product.mapValue["price"]); - m_textCtrlDescription->SetValue(product.mapValue["description"]); - m_textCtrlInstructions->SetValue(product.mapValue["instructions"]); - - for (int i = 0; i < FIELDS_MAX; i++) - { - bool fUsed = i < product.vOrderForm.size(); - m_buttonDel[i]->Show(fUsed); - m_textCtrlLabel[i]->Show(fUsed); - m_textCtrlField[i]->Show(fUsed); - if (!fUsed) - continue; - - m_textCtrlLabel[i]->SetValue(product.vOrderForm[i].first); - string strControl = product.vOrderForm[i].second; - if (strControl.substr(0, 5) == "text=") - m_textCtrlField[i]->SetValue(""); - else if (strControl.substr(0, 7) == "choice=") - m_textCtrlField[i]->SetValue(strControl.substr(7)); - else - m_textCtrlField[i]->SetValue(strControl); - } -} - -void CEditProductDialog::GetProduct(CProduct& product) -{ - // map mapValue; - // vector > vOrderForm; - - product.mapValue["category"] = m_comboBoxCategory->GetValue().Trim(); - product.mapValue["title"] = m_textCtrlTitle->GetValue().Trim(); - product.mapValue["price"] = m_textCtrlPrice->GetValue().Trim(); - product.mapValue["description"] = m_textCtrlDescription->GetValue().Trim(); - product.mapValue["instructions"] = m_textCtrlInstructions->GetValue().Trim(); - - for (int i = 0; i < FIELDS_MAX; i++) - { - if (m_buttonDel[i]->IsShown()) - { - string strLabel = (string)m_textCtrlLabel[i]->GetValue().Trim(); - string strControl = (string)m_textCtrlField[i]->GetValue(); - if (strControl.empty()) - strControl = "text="; - else - strControl = "choice=" + strControl; - product.vOrderForm.push_back(make_pair(strLabel, strControl)); - } - } -} - - - - - - - -////////////////////////////////////////////////////////////////////////////// -// -// CViewProductDialog -// - -CViewProductDialog::CViewProductDialog(wxWindow* parent, const CProduct& productIn) : CViewProductDialogBase(parent) -{ - Connect(wxEVT_REPLY1, wxCommandEventHandler(CViewProductDialog::OnReply1), NULL, this); - AddCallbackAvailable(GetEventHandler()); - - // Fill display with product summary while waiting for details - product = productIn; - UpdateProductDisplay(false); - - m_buttonBack->Enable(false); - m_buttonNext->Enable(!product.vOrderForm.empty()); - m_htmlWinReviews->Show(true); - m_scrolledWindow->Show(false); - this->Layout(); - - // Request details from seller - CreateThread(ThreadRequestProductDetails, new pair(product, GetEventHandler())); -} - -CViewProductDialog::~CViewProductDialog() -{ - RemoveCallbackAvailable(GetEventHandler()); -} - -void ThreadRequestProductDetails(void* parg) -{ - // Extract parameters - pair* pitem = (pair*)parg; - CProduct product = pitem->first; - wxEvtHandler* pevthandler = pitem->second; - delete pitem; - - // Connect to seller - CNode* pnode = ConnectNode(product.addr, 5 * 60); - if (!pnode) - { - CDataStream ssEmpty; - AddPendingReplyEvent1(pevthandler, ssEmpty); - return; - } - - // Request detailed product, with response going to OnReply1 via dialog's event handler - pnode->PushRequest("getdetails", product.GetHash(), AddPendingReplyEvent1, (void*)pevthandler); -} - -void CViewProductDialog::OnReply1(wxCommandEvent& event) -{ - CDataStream ss = GetStreamFromEvent(event); - if (ss.empty()) - { - product.mapValue["description"] = "-- CAN'T CONNECT TO SELLER --\n"; - UpdateProductDisplay(true); - return; - } - - int nRet; - CProduct product2; - try - { - ss >> nRet; - if (nRet > 0) - throw false; - ss >> product2; - if (product2.GetHash() != product.GetHash()) - throw false; - if (!product2.CheckSignature()) - throw false; - } - catch (...) - { - product.mapValue["description"] = "-- INVALID RESPONSE --\n"; - UpdateProductDisplay(true); - return; - } - - product = product2; - UpdateProductDisplay(true); -} - -bool CompareReviewsBestFirst(const CReview* p1, const CReview* p2) -{ - return (p1->nAtoms > p2->nAtoms); -} - -void CViewProductDialog::UpdateProductDisplay(bool fDetails) -{ - // Product and reviews - string strHTML; - strHTML.reserve(4000); - strHTML += "\n" - "\n" - "\n" - "\n" - "\n"; - strHTML += "Category: " + HtmlEscape(product.mapValue["category"]) + "
\n"; - strHTML += "Title: " + HtmlEscape(product.mapValue["title"]) + "
\n"; - strHTML += "Price: " + HtmlEscape(product.mapValue["price"]) + "
\n"; - - if (!fDetails) - strHTML += "Loading details...
\n
\n"; - else - strHTML += HtmlEscape(product.mapValue["description"], true) + "
\n
\n"; - - strHTML += "Reviews:
\n
\n"; - - if (!product.vchPubKeyFrom.empty()) - { - CReviewDB reviewdb("r"); - - // Get reviews - vector vReviews; - reviewdb.ReadReviews(product.GetUserHash(), vReviews); - - // Get reviewer's number of atoms - vector vSortedReviews; - vSortedReviews.reserve(vReviews.size()); - for (vector::reverse_iterator it = vReviews.rbegin(); it != vReviews.rend(); ++it) - { - CReview& review = *it; - CUser user; - reviewdb.ReadUser(review.GetUserHash(), user); - review.nAtoms = user.GetAtomCount(); - vSortedReviews.push_back(&review); - } - - reviewdb.Close(); - - // Sort - stable_sort(vSortedReviews.begin(), vSortedReviews.end(), CompareReviewsBestFirst); - - // Format reviews - foreach(CReview* preview, vSortedReviews) - { - CReview& review = *preview; - int nStars = atoi(review.mapValue["stars"].c_str()); - if (nStars < 1 || nStars > 5) - continue; - - strHTML += "" + itostr(nStars) + (nStars == 1 ? " star" : " stars") + ""; - strHTML += "     "; - strHTML += DateStr(atoi64(review.mapValue["date"])) + "
\n"; - strHTML += HtmlEscape(review.mapValue["review"], true); - strHTML += "
\n
\n"; - } - } - - strHTML += "\n\n"; - - // Shrink capacity to fit - string(strHTML.begin(), strHTML.end()).swap(strHTML); - - m_htmlWinReviews->SetPage(strHTML); - - ///// need to find some other indicator to use so can allow empty order form - if (product.vOrderForm.empty()) - return; - - // Order form - m_staticTextInstructions->SetLabel(product.mapValue["instructions"]); - for (int i = 0; i < FIELDS_MAX; i++) - { - m_staticTextLabel[i] = NULL; - m_textCtrlField[i] = NULL; - m_choiceField[i] = NULL; - } - - // Construct flexgridsizer - wxBoxSizer* bSizer21 = (wxBoxSizer*)m_scrolledWindow->GetSizer(); - wxFlexGridSizer* fgSizer; - fgSizer = new wxFlexGridSizer(0, 2, 0, 0); - fgSizer->AddGrowableCol(1); - fgSizer->SetFlexibleDirection(wxBOTH); - fgSizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED); - - // Construct order form fields - wxWindow* windowLast = NULL; - for (int i = 0; i < product.vOrderForm.size(); i++) - { - string strLabel = product.vOrderForm[i].first; - string strControl = product.vOrderForm[i].second; - - if (strLabel.size() < 20) - strLabel.insert(strLabel.begin(), 20 - strLabel.size(), ' '); - - m_staticTextLabel[i] = new wxStaticText(m_scrolledWindow, wxID_ANY, strLabel, wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT); - m_staticTextLabel[i]->Wrap(-1); - fgSizer->Add(m_staticTextLabel[i], 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5); - - if (strControl.substr(0, 5) == "text=") - { - m_textCtrlField[i] = new wxTextCtrl(m_scrolledWindow, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0); - fgSizer->Add(m_textCtrlField[i], 1, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 5); - windowLast = m_textCtrlField[i]; - } - else if (strControl.substr(0, 7) == "choice=") - { - vector vChoices; - ParseString(strControl.substr(7), ',', vChoices); - - wxArrayString arraystring; - foreach(const string& str, vChoices) - arraystring.Add(str); - - m_choiceField[i] = new wxChoice(m_scrolledWindow, wxID_ANY, wxDefaultPosition, wxDefaultSize, arraystring, 0); - fgSizer->Add(m_choiceField[i], 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); - windowLast = m_choiceField[i]; - } - else - { - m_textCtrlField[i] = new wxTextCtrl(m_scrolledWindow, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0); - fgSizer->Add(m_textCtrlField[i], 1, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 5); - m_staticTextLabel[i]->Show(false); - m_textCtrlField[i]->Show(false); - } - } - - // Insert after instructions and before submit/cancel buttons - bSizer21->Insert(2, fgSizer, 0, wxEXPAND|wxRIGHT|wxLEFT, 5); - m_scrolledWindow->Layout(); - bSizer21->Fit(m_scrolledWindow); - this->Layout(); - - // Fixup the tab order - m_buttonSubmitForm->MoveAfterInTabOrder(windowLast); - m_buttonCancelForm->MoveAfterInTabOrder(m_buttonSubmitForm); - //m_buttonBack->MoveAfterInTabOrder(m_buttonCancelForm); - //m_buttonNext->MoveAfterInTabOrder(m_buttonBack); - //m_buttonCancel->MoveAfterInTabOrder(m_buttonNext); - this->Layout(); -} - -void CViewProductDialog::GetOrder(CWalletTx& wtx) -{ - wtx.SetNull(); - for (int i = 0; i < product.vOrderForm.size(); i++) - { - string strValue; - if (m_textCtrlField[i]) - strValue = m_textCtrlField[i]->GetValue().Trim(); - else - strValue = m_choiceField[i]->GetStringSelection(); - wtx.vOrderForm.push_back(make_pair(m_staticTextLabel[i]->GetLabel(), strValue)); - } -} - -void CViewProductDialog::OnButtonSubmitForm(wxCommandEvent& event) -{ - m_buttonSubmitForm->Enable(false); - m_buttonCancelForm->Enable(false); - - CWalletTx wtx; - GetOrder(wtx); - - CSendingDialog* pdialog = new CSendingDialog(this, product.addr, atoi64(product.mapValue["price"]), wtx); - if (!pdialog->ShowModal()) - { - m_buttonSubmitForm->Enable(true); - m_buttonCancelForm->Enable(true); - return; - } -} - -void CViewProductDialog::OnButtonCancelForm(wxCommandEvent& event) -{ - Destroy(); -} - -void CViewProductDialog::OnButtonBack(wxCommandEvent& event) -{ - Freeze(); - m_htmlWinReviews->Show(true); - m_scrolledWindow->Show(false); - m_buttonBack->Enable(false); - m_buttonNext->Enable(!product.vOrderForm.empty()); - this->Layout(); - Thaw(); -} - -void CViewProductDialog::OnButtonNext(wxCommandEvent& event) -{ - if (!product.vOrderForm.empty()) - { - Freeze(); - m_htmlWinReviews->Show(false); - m_scrolledWindow->Show(true); - m_buttonBack->Enable(true); - m_buttonNext->Enable(false); - this->Layout(); - Thaw(); - } -} - -void CViewProductDialog::OnButtonCancel(wxCommandEvent& event) -{ - Destroy(); -} - - - - - - - -////////////////////////////////////////////////////////////////////////////// -// -// CViewOrderDialog -// - -CViewOrderDialog::CViewOrderDialog(wxWindow* parent, CWalletTx order, bool fReceived) : CViewOrderDialogBase(parent) -{ - int64 nPrice = (fReceived ? order.GetCredit() : order.GetDebit()); - - string strHTML; - strHTML.reserve(4000); - strHTML += "\n" - "\n" - "\n" - "\n" - "\n"; - strHTML += "Time: " + HtmlEscape(DateTimeStr(order.nTimeReceived)) + "
\n"; - strHTML += "Price: " + HtmlEscape(FormatMoney(nPrice)) + "
\n"; - strHTML += "Status: " + HtmlEscape(FormatTxStatus(order)) + "
\n"; - - strHTML += "\n"; - for (int i = 0; i < order.vOrderForm.size(); i++) - { - strHTML += " "; - strHTML += "\n"; - } - strHTML += "
" + HtmlEscape(order.vOrderForm[i].first) + ":" + HtmlEscape(order.vOrderForm[i].second) + "
\n"; - - strHTML += "\n\n"; - - // Shrink capacity to fit - // (strings are ref counted, so it may live on in SetPage) - string(strHTML.begin(), strHTML.end()).swap(strHTML); - - m_htmlWin->SetPage(strHTML); -} - -void CViewOrderDialog::OnButtonOK(wxCommandEvent& event) -{ - Destroy(); -} - - - - - - - -////////////////////////////////////////////////////////////////////////////// -// -// CEditReviewDialog -// - -CEditReviewDialog::CEditReviewDialog(wxWindow* parent) : CEditReviewDialogBase(parent) -{ -} - -void CEditReviewDialog::OnButtonSubmit(wxCommandEvent& event) -{ - if (m_choiceStars->GetSelection() == -1) - { - wxMessageBox("Please select a rating "); - return; - } - - CReview review; - GetReview(review); - - // Sign the review - review.vchPubKeyFrom = keyUser.GetPubKey(); - if (!keyUser.Sign(review.GetSigHash(), review.vchSig)) - { - wxMessageBox("Unable to digitally sign the review "); - return; - } - - // Broadcast - if (!review.AcceptReview()) - { - wxMessageBox("Save failed "); - return; - } - RelayMessage(CInv(MSG_REVIEW, review.GetHash()), review); - - Destroy(); -} - -void CEditReviewDialog::OnButtonCancel(wxCommandEvent& event) -{ - Destroy(); -} - -void CEditReviewDialog::GetReview(CReview& review) -{ - review.mapValue["time"] = i64tostr(GetAdjustedTime()); - review.mapValue["stars"] = itostr(m_choiceStars->GetSelection()+1); - review.mapValue["review"] = m_textCtrlReview->GetValue(); -} - - - - - - - ////////////////////////////////////////////////////////////////////////////// // // CMyTaskBarIcon -- cgit v1.2.3