void str_formalize( std::basic_string< CharType > & formattedString, int maxSize, const CharType * format, va_list vaList )
    {
        std::vector< CharType > strText( maxSize + 1, 0 );

        try
        {

            if ( format )
            {
                size_t written = str_vprintf( strText.data(), maxSize + 1, format, vaList );
                formattedString.assign( strText.data(), strText.data() + std::min( written, size_t( maxSize ) ) );
            }
        }
        catch ( ... )
        {
            StringStream message;
            message << ERROR_DB_FORMALIZE << formattedString.c_str();
            DB_EXCEPT( EDatabaseExceptionCodes_DateTimeError, message.str() );
        }
    }
void TextField::setText(const std::string& text)
{
    std::string strText(text);
    if (isMaxLengthEnabled())
    {
        strText = strText.substr(0, getMaxLength());
    }
    const char* content = strText.c_str();
    if (isPasswordEnabled())
    {
        _textFieldRenderer->setPasswordText(content);
        _textFieldRenderer->setString("");
        _textFieldRenderer->insertText(content, strlen(content));
    }
    else
    {
        _textFieldRenderer->setString(content);
    }
    textfieldRendererScaleChangedWithSize();
}
void StyleHelper::drawListViewItemThumb(QPainter* p, const QRect& rc, int nBadgeType,
                                        const QString& title, const QString& lead, const QString& abs,
                                        bool bFocused, bool bSelected)
{
    QRect rcd(rc);

    QFont fontTitle;
    int nFontHeight = Utils::StyleHelper::fontHead(fontTitle);

    if (!title.isEmpty()) {
        QRect rcTitle = Utils::StyleHelper::drawBadgeIcon(p, rcd, nFontHeight, nBadgeType, bFocused, bSelected);

        rcTitle.setCoords(rcTitle.right(), rcTitle.y(), rcd.right(), rcd.bottom());
        QString strTitle(title);
        QColor colorTitle = Utils::StyleHelper::listViewItemTitle(bSelected, bFocused);
        rcTitle = Utils::StyleHelper::drawText(p, rcTitle, strTitle, 1, Qt::AlignVCenter, colorTitle, fontTitle);
        rcd.adjust(0, rcTitle.height() + margin(), 0, 0);
    }

    QFont fontThumb;
    nFontHeight = Utils::StyleHelper::fontNormal(fontThumb);

    QRect rcLead;
    if (!lead.isEmpty()) {
        QString strInfo(lead);
        QColor colorDate = Utils::StyleHelper::listViewItemLead(bSelected, bFocused);
        rcLead = Utils::StyleHelper::drawText(p, rcd, strInfo, 1, Qt::AlignVCenter, colorDate, fontThumb);
    }

    if (!abs.isEmpty()) {
        QString strText(abs);
        QRect rcLine1(rcd.adjusted(rcLead.width(), 0, 0, 0));
        QColor colorSummary = Utils::StyleHelper::listViewItemSummary(bSelected, bFocused);
        rcLine1 = Utils::StyleHelper::drawText(p, rcLine1, strText, 1, Qt::AlignVCenter, colorSummary, fontThumb, false);

        if (!strText.isEmpty()) {
            QRect rcLine2(rcd.adjusted(0, rcLine1.height(), 0, 0));
            rcLine2 = Utils::StyleHelper::drawText(p, rcLine2, strText, 2, Qt::AlignVCenter, colorSummary, fontThumb);
        }
    }
}
void CLogAnalyzerView::OnEditLocatelogtrace()
{
    if (m_logger->GetActiveUISetting().isNull())
    {
        ERROR_MESSAGEBOX("CLogAnalyseDlg::OnQuickLocatethislineinnotepadd : UI Setting has incorrect info.");
        return;
    }
    //Get the selected component name
    tstring strText(m_strSelComponent.GetBuffer(m_strSelComponent.GetLength())); 
    //Get the selected trace log

    const std::map<tstring, Poco::SharedPtr<CComponent>>& components = m_logger->GetComponents();
    std::map<tstring, Poco::SharedPtr<CComponent>>::const_iterator ite = components.find(strText);
    if (ite != components.end())
    {
        //Search trace log
        const std::vector<Poco::SharedPtr<CTraceLog>>& traceLogs = ite->second->GetTraceLogs();
        TCHAR itemText[512] = {0};
        POSITION pt = m_traceList.GetFirstSelectedItemPosition();
        int nSelIndex = m_traceList.GetNextSelectedItem(pt);
        CString strLine = m_traceList.GetItemText(nSelIndex, 0);
        int nLine = Poco::NumberParser::parse(strLine.GetBuffer(strLine.GetLength()));

        for (int i = 0; i < traceLogs.size(); ++i)
        {
            if (nLine == traceLogs.at(i)->m_nLine)
            {
                std::vector<tstring> args;
                itoa(traceLogs.at(i)->m_nLine, itemText, 10);
                tstring strCommandLine = m_logger->GetActiveUISetting()->GetNodepadPath();
                strCommandLine += " -n";
                strCommandLine += itemText;
                strCommandLine += " \"";
                strCommandLine += m_logger->GetFileName();
                strCommandLine += "\"";
                Poco::Process::launch(strCommandLine, args);
                break;
            }
        }
    }
}
Beispiel #5
0
void CLogView::OnEventCopy() 
{
	// TODO: Add your command handler code here
	int nItem;
    CString strText(_T(""));
    POSITION pos = m_pLogList->GetFirstSelectedItemPosition();
	if  (pos  ==  NULL)
	{
		::MessageBox(NULL,"请先选择要复制的事件记录 ...","提示",MB_ICONINFORMATION);
		return;
	}
	else
	{
		//获取所有选中项目的内容。
		while (pos)
		{
			nItem = m_pLogList->GetNextSelectedItem(pos);
			strText += m_pLogList->GetItemText(nItem, 0) + " ";
			strText += m_pLogList->GetItemText(nItem, 1) + _T("\r\n");
		}
		//将内容保存到剪贴板。
		if (!strText.IsEmpty())
		{
			if (OpenClipboard())
			{
				EmptyClipboard();
				HGLOBAL hClipboardData = GlobalAlloc(GHND | GMEM_SHARE, (strText.GetLength() + 1) * sizeof(TCHAR));
				if (hClipboardData)
				{
					TCHAR* pszData = (TCHAR *)GlobalLock(hClipboardData);
					_tcscpy(pszData, strText);
					GlobalUnlock(hClipboardData);
					SetClipboardData(CF_TEXT, hClipboardData);
				}
				CloseClipboard();
			}
		}
	}
}
Beispiel #6
0
	bool CStrUtils::IsFloat( std::string const & strIn )
	{
		bool bReturn = false;
		std::string strText( strIn );
		std::vector< std::string > arraySplitted;
		std::size_t nSize;

		CStrUtils::Replace( strText, ",", "." );
		CStrUtils::Split( strText, ".", arraySplitted );
		nSize = arraySplitted.size();

		if ( nSize > 0 && nSize < 3 )
		{
			bReturn = CStrUtils::IsInteger( arraySplitted[0] );

			if ( bReturn && nSize > 1 )
			{
				bReturn = CStrUtils::IsInteger( arraySplitted[1] );
			}
		}

		return bReturn;
	}
void CSocketServer::OnReceive(int nErrorCode)
{
	// TODO: Add your specialized code here and/or call the base class
	char s[1024]; CString szIP; UINT szPort;

	GetPeerName(szIP,szPort);
	int nLen = Receive(s,1024);
	s[nLen]=L'\0';
	CString strText(s);

	SetInfoReceive(strText);
	SetClientIP(szIP);
	SetClientPort(szPort);
	if (strText.GetLength()>3 && (strText.Left(3) == L"con"))
	{
		CStaticClass::m_bControl = true;
		CStaticClass::m_csReceiveInfo = strText;
		SetEvent(CStaticClass::m_hEventRecieve);
	}


	CSocket::OnReceive(nErrorCode);
}
Beispiel #8
0
	std::wstring UTF8ToUnicode(const std::string& str)
	{
		WCHAR*   pElementText;
		int iTextLen;
		iTextLen = MultiByteToWideChar(CP_UTF8,
			0,
			str.c_str(),
			-1,
			NULL,
			0);
		pElementText = new WCHAR[iTextLen + 1];
		memset((void*)pElementText, 0, sizeof(WCHAR) * (iTextLen + 1));
		::MultiByteToWideChar(CP_UTF8,
			0,
			str.c_str(),
			-1,
			pElementText,
			iTextLen
			);
		std::wstring strText(pElementText);
		delete[] pElementText;
		return strText;
	}
void HtmlBookReader::addConvertedDataToBuffer(const char *text, std::size_t len, bool convert) {
	if (len > 0) {
		if (myDontBreakParagraph) {
			while ((len > 0) && isspace(*text)) {
				--len;
				++text;
			}
			if (len == 0) {
				return;
			}
		}
		if (convert) {
			myConverter->convert(myConverterBuffer, text, text + len);
			myBookReader.addData(myConverterBuffer);
			myBookReader.addContentsData(myConverterBuffer);
			myConverterBuffer.erase();
		} else {
			std::string strText(text, len);
			myBookReader.addData(strText);
			myBookReader.addContentsData(strText);
		}
		myDontBreakParagraph = false;
	}
}
void CLogAnalyzerView::OnEditOpensourcefile()
{
    if (m_logger->GetActiveUISetting().isNull())
    {
        ERROR_MESSAGEBOX("UI Setting has incorrect info.");
        return;
    }

    BOOL bPython = m_logger->GetActiveUISetting()->GetPythonModuleFlag();
    int nIdentifier = m_logger->GetActiveUISetting()->GetColumnIdentifier();
    if (nIdentifier == -1 && !bPython)
    {
        ERROR_MESSAGEBOX("Cannot open related source file since this UI Setting doesn't have column identifier or define python function.");
        return;
    }

    //Get the selected component name
    tstring strText(m_strSelComponent.GetBuffer(m_strSelComponent.GetLength())); 
    //Get the selected trace log

    const std::map<tstring, Poco::SharedPtr<CComponent>>& components = m_logger->GetComponents();
    std::map<tstring, Poco::SharedPtr<CComponent>>::const_iterator ite = components.find(strText);

    HCURSOR holdcursor, hwaitcursor;
    hwaitcursor = LoadCursor(NULL,IDC_WAIT);
    holdcursor = ::SetCursor(hwaitcursor);

    try
    {
        if (ite != components.end())
        {
            //Search trace log
            const std::vector<Poco::SharedPtr<CTraceLog>>& traceLogs = ite->second->GetTraceLogs();
            for (int i = 0; i < traceLogs.size(); ++i)
            {
                TCHAR itemText[512] = {0};
                POSITION pt = m_traceList.GetFirstSelectedItemPosition();
                int nSelIndex = m_traceList.GetNextSelectedItem(pt);
                CString strLine = m_traceList.GetItemText(nSelIndex, 0);
                int nLine = Poco::NumberParser::parse(strLine.GetBuffer(strLine.GetLength()));
                if (nLine == traceLogs.at(i)->m_nLine)
                {
                    m_logger->GetAssocatedSourceFiles(traceLogs.at(i));
                    if (!traceLogs.at(i)->m_strSourceCodeFile.empty())
                    {
                        //Open file and go to the specify line
                        std::vector<tstring> args;
                        itoa(traceLogs.at(i)->m_nLineInSourceFile, itemText, 10);
                        tstring strCommandLine = m_logger->GetActiveUISetting()->GetNodepadPath();
                        strCommandLine += " -n";
                        strCommandLine += itemText;
                        strCommandLine += " \"";
                        strCommandLine += traceLogs.at(i)->m_strSourceCodeFile;
                        strCommandLine += "\"";
                        Poco::Process::launch(strCommandLine, args);
                        break;
                    }
                    else
                        ERROR_MESSAGEBOX("Cannot find the trace Id, Please modify the path for the related component.");
                    break;
                }
            }
        }
    }
    catch (std::exception& e)
    {
        CString strMessage = "Exception :";
        strMessage += e.what();
        ERROR_MESSAGEBOX(strMessage);
    }
    catch (...)
    {
        ERROR_MESSAGEBOX("Unknown exception");
    }
    ::SetCursor(holdcursor);
}
//-------------------------------------------------------------------------
void FKAnimateSaxDelegator::textHandler(void *ctx, const char *s, int len)
{
	if(m_eCurState==eState_None)
		return;

	string	strText((char*)s, 0, len);
	int		nIndex = 0;
	float	fDelay = 0.0f;

	switch ( m_eCurState )
	{
	case eState_Plist:
		m_vecPlists.push_back( strText );
		break;
	case eState_Animation:
		break;
	case eState_Name:
		{
			if( m_vecAnimates.size() == 0 )
				break;
			nIndex = m_vecAnimates.size() - 1;
			m_vecAnimates[nIndex].m_strName = strText;
		}
		break;
	case eState_Delay:
		{
			if( m_vecAnimates.size() == 0 )
				break;
			nIndex = m_vecAnimates.size() - 1;
			fDelay = (float)FKCW_Base_Utils::AtoF(strText);
			m_vecAnimates[nIndex].m_fDelay = fDelay;
		}
		break;
	case eState_FlipX:
		{
			if( m_vecAnimates.size() == 0 )
				break;
			nIndex = m_vecAnimates.size() - 1;
			m_vecAnimates[nIndex].m_bIsFlipX = (strText == "true");
		}
		break;
	case eState_FlipY:
		{
			if( m_vecAnimates.size() == 0 )
				break;
			nIndex = m_vecAnimates.size() - 1;
			m_vecAnimates[nIndex].m_bIsFlipY = (strText == "true");
		}
		break;
	case eState_Sprite_Frame:
		{
			if( m_vecAnimates.size() == 0 )
				break;
			nIndex = m_vecAnimates.size() - 1;
			m_vecAnimates[nIndex].m_vecSpriteFrame.push_back( strText );
		}
		break;
	default:
		break;
	}
}
void CLabel::OnPaint() 
{
	CPaintDC dc(this); // device context for painting

	DWORD dwFlags = 0;

	CRect rc;
	GetClientRect(rc);
	CString strText( m_sText );

	CBitmap bmp;


	///////////////////////////////////////////////////////
	//
	// Set up for double buffering...
	//
	CDC* pDCMem;
	CBitmap*	pOldBitmap = NULL;

	if (!m_bTransparent)
	{
		pDCMem = new CDC;
		pDCMem->CreateCompatibleDC(&dc);
		bmp.CreateCompatibleBitmap(&dc,rc.Width(),rc.Height());
		pOldBitmap = pDCMem->SelectObject(&bmp);
	}
	else
	{
		pDCMem = &dc;
	}

	UINT nMode = pDCMem->SetBkMode(TRANSPARENT);


	COLORREF crText = pDCMem->SetTextColor(m_crText);
	CFont *pOldFont = pDCMem->SelectObject(&m_font);


	// Fill in backgound if not transparent
	if (!m_bTransparent)
	{
		if (m_fillmode == Normal)
		{
			CBrush br;
			
			if (m_hBackBrush != NULL)
				br.Attach(m_hBackBrush);
			else
				br.Attach(m_hwndBrush);
					
			pDCMem->FillRect(rc,&br);

			br.Detach();
		}
		else // Gradient Fill
		{
			DrawGradientFill(pDCMem, &rc, m_crLoColor, m_crHiColor, 100);
		}

	}
	

	// If the text is flashing turn the text color on
	// then to the color of the window background.

	LOGBRUSH lb;
	ZeroMemory(&lb,sizeof(lb));

	// Stop Checking complaining
	if (m_hBackBrush)
		::GetObject(m_hBackBrush,sizeof(lb),&lb);


	// Something to do with flashing
	if (!m_bState && m_Type == Text)
		pDCMem->SetTextColor(lb.lbColor);

	DWORD style = GetStyle();
	
	switch (style & SS_TYPEMASK)
	{
		case SS_RIGHT: 
			dwFlags = DT_RIGHT | DT_WORDBREAK; 
			break; 
		
		case SS_CENTER: 
			dwFlags = SS_CENTER | DT_WORDBREAK;
			break;

		case SS_LEFTNOWORDWRAP: 
			dwFlags = DT_LEFT; 
			break;

		default: // treat other types as left
			case SS_LEFT: 
				dwFlags = DT_LEFT | DT_WORDBREAK; 
				break;
	}	

		
	// Added to expand tabs...
	if(strText.Find(_T('\t')) != -1)
		dwFlags |= DT_EXPANDTABS;

	// If the text centered make an assumtion that
	// the will want to center verticly as well
	if (style & SS_CENTERIMAGE)
	{
		dwFlags = DT_CENTER;

		// Apply 
		if (strText.Find(_T("\r\n")) == -1)
		{
			dwFlags |= DT_VCENTER;

			// And because DT_VCENTER only works with single lines
			dwFlags |= DT_SINGLELINE; 
		}

	}

	//
	// 3333   DDDDD
	//     3  D    D
	//   33   D     D    E F X 
	//     3  D    D
	// 3333   DDDDD
	//
	//
	if (m_bRotation)
	{
		int nAlign = pDCMem->SetTextAlign (TA_BASELINE);

		CPoint pt;
		GetViewportOrgEx (pDCMem->m_hDC,&pt) ;
		SetViewportOrgEx (pDCMem->m_hDC,rc.Width() / 2, rc.Height() / 2, NULL) ;
		pDCMem->TextOut (0, 0, strText) ;
		SetViewportOrgEx (pDCMem->m_hDC,pt.x / 2, pt.y / 2, NULL) ;
		pDCMem->SetTextAlign (nAlign);
	}
	else
	{
		// convert to UNICODE and use the WIDE version of DrawText()
		// Why?  because DrawText seems to have a bug with Japanese 
		// characters.

		USES_CONVERSION;

		WCHAR* wsz = T2OLE( strText );
		::DrawTextExW( *pDCMem, wsz, (int)(::wcslen( wsz )), rc, dwFlags, NULL ); 
		if (m_bFont3d)
		{
			pDCMem->SetTextColor(m_cr3DHiliteColor);

			if (m_3dType == Raised)
				rc.OffsetRect(-1,-1);
			else
				rc.OffsetRect(1,1);

//			::DrawTextW( *pDCMem, wsz, ::wcslen( wsz ), rc, dwFlags ); 
		}
	}

	// Restore DC's State
	pDCMem->SetBkMode(nMode);
	pDCMem->SelectObject(pOldFont);
	pDCMem->SetTextColor(crText);

	if (!m_bTransparent)
	{
		dc.BitBlt(0,0,rc.Width(),rc.Height(),pDCMem,0,0,SRCCOPY);
		// continue DC restore 
		pDCMem->SelectObject ( pOldBitmap ) ;
		delete pDCMem;
	}
}
void CProgressCtrlEx::OnPaint()
{
	CPaintDC paintDC(this);

	int nMin = 0;
	int nMax = 0;

	GetRange(nMin, nMax);
	ASSERT(nMin <= nMax);

	int nPos = GetPos();
	ASSERT(nPos >= nMin && nPos <= nMax);

	DWORD dwStyle = GetStyle();

	BOOL bVertical = FALSE;
	if (dwStyle & PBS_VERTICAL)
	{
		bVertical = TRUE;
	}

	CDC dc;
	dc.CreateCompatibleDC(&paintDC);
	ASSERT(dc.GetSafeHdc());

	CRect rect;
	GetClientRect(&rect);

	CBitmap bmp;
	bmp.CreateCompatibleBitmap(&paintDC, rect.Width(), rect.Height());
	ASSERT(bmp.GetSafeHandle());

	CBitmap* pOldBitmap = (CBitmap*)dc.SelectObject(&bmp);

	CFont* pOldFont = NULL;
	CWnd* pParent = GetParent();
	ASSERT(pParent);

	CFont* pFont = pParent->GetFont();
	ASSERT(pFont);
	if (bVertical)
	{
		if (NULL == m_font.GetSafeHandle())
		{
			LOGFONT lf = { 0 };
			pFont->GetLogFont(&lf);
			lf.lfEscapement = 900;
			m_font.CreateFontIndirect(&lf);
		}
		ASSERT(m_font.GetSafeHandle());
		pOldFont = (CFont*)dc.SelectObject(&m_font);
	}
	else
	{
		pOldFont = (CFont*)dc.SelectObject(pFont);
	}

	double dPercent = (double)(nPos - nMin) / ((double)(nMax - nMin));

	dc.DrawEdge(rect, EDGE_SUNKEN, BF_RECT | BF_FLAT);

	CRect rc(rect);
	rc.DeflateRect(CSize(2, 2));
	dc.FillSolidRect(&rc, m_clrBarBkColor);

	CString strText(_T(""));
	GetWindowText(strText);

	if (m_bShowPercent)
	{
		strText.AppendFormat(_T("%d%% "), static_cast<int>((dPercent * 100.0) + 0.5));
	}

	dc.SetBkMode(TRANSPARENT);
	dc.SetTextColor(m_clrTextColor);

	CPoint pt(0, 0);
	CSize size = dc.GetOutputTextExtent(strText);

	if (!bVertical)
	{
		switch (m_AlignText)
		{
		case ALIGN_LEFT:
			pt.x = rc.left;
			break;

		case ALIGN_RIGHT:
			pt.x = rc.right - size.cx;
			break;

		case ALIGN_CENTER:
		default:
			pt.x = rc.left + (rc.Width() - size.cx) / 2;
			break;
		}
		pt.y = rc.top + (rc.Height() - size.cy) / 2;

		CRect rcPos(rc);

		rcPos.right = rcPos.left + (int)(dPercent * rcPos.Width());
		dc.FillSolidRect(rcPos, m_clrBarColor);

		dc.SetTextColor(m_clrTextColor);
		dc.ExtTextOut(pt.x, pt.y, ETO_OPAQUE, rcPos, strText, NULL);

		dc.SetTextColor(m_clrTextBkColor);
		dc.ExtTextOut(pt.x, pt.y, ETO_CLIPPED, &rcPos, strText, NULL);
	}
	else
	{
		switch (m_AlignText)
		{
		case ALIGN_LEFT:
			pt.y = rc.bottom;
			break;

		case ALIGN_RIGHT:
			pt.y = rc.top + size.cx;
			break;

		case ALIGN_CENTER:
		default:
			pt.y = rc.bottom - (rc.Height() - size.cx) / 2;
			break;
		}
		pt.x = rc.left + (rc.Width() - size.cy) / 2;

		CRect rcPos(rc);

		rcPos.top = rcPos.bottom - (int)(dPercent * rcPos.Height());
		dc.FillSolidRect(rcPos, m_clrBarColor);

		dc.SetTextColor(m_clrTextColor);
		dc.ExtTextOut(pt.x, pt.y, ETO_OPAQUE, rcPos, strText, NULL);

		dc.SetTextColor(m_clrTextBkColor);
		dc.ExtTextOut(pt.x, pt.y, ETO_CLIPPED, &rcPos, strText, NULL);
	}

	paintDC.BitBlt(rect.left, rect.top, rect.Width(), rect.Height(), &dc, 0, 0, SRCCOPY);

	dc.SelectObject(pOldFont);
	dc.SelectObject(pOldBitmap);
	bmp.DeleteObject();

	dc.DeleteDC();
}
void DlgEncrypt::on_pushButtonEncrypt_clicked()
{
    QString qstrText = ui->plainTextEdit->toPlainText().trimmed();
    // --------------------------------
    if (qstrText.isEmpty())
    {
        // pop up a message box warning that the input text is empty.
        //
        QMessageBox::warning(this, tr("Input Text is Empty"),
                             tr("Please paste some text to be signed/encrypted."));
        return;
    }
    else
    {
        if (m_bSign)
        {
            if (m_nymId.isEmpty())
            {
                QMessageBox::warning(this, tr("Missing Signer"),
                                     tr("No signer is selected. Perhaps you need to create an identity first, to sign with."));
                return;
            }
            else
            {
                // Sign the contents.
                //
                std::string  str_nym    (m_nymId.toStdString());
                opentxs::String     strNym     (str_nym.c_str());
                opentxs::Identifier nym_id     (strNym);

                std::string  str_text   (qstrText.toStdString());
                opentxs::String     strText    (str_text.c_str());
//              opentxs::OTASCIIArmor ascText    (strText);
//              std::string  str_encoded(ascText.Get());
//              opentxs::String     strEncoded (str_encoded.c_str());
//              std::string  str_type   ("MESSAGE");

                if (!nym_id.IsEmpty())
                {
                    opentxs::OTPasswordData thePWData("Signer passphrase");

                    opentxs::Nym * pNym = opentxs::OTAPI_Wrap::OTAPI()->GetOrLoadPrivateNym(nym_id,
                                                                           false, //bChecking=false
                                                                           __FUNCTION__,
                                                                           &thePWData);
                    if (NULL == pNym)
                    {
                        QString qstrErrorMsg = QString("%1: %2").arg(tr("Failed loading the signer; unable to continue. NymID")).arg(m_nymId);
                        QMessageBox::warning(this, tr("Failed Loading Signer"), qstrErrorMsg);
                        return;
                    }
                    else
                    {
                        // FOR VERIFY STEP:
    //                  inline opentxs::String & opentxs::OTSignedFile::GetFilePayload()                       { return m_strSignedFilePayload;   }

                        opentxs::String     strSignedOutput;
                        opentxs::OTSignedFile theSignedFile;

                        theSignedFile.SetSignerNymID(strNym);

                        theSignedFile.SetFilePayload(strText);
                        theSignedFile.SignContract(*pNym, &thePWData);
                        theSignedFile.SaveContract();
                        theSignedFile.SaveContractRaw(strSignedOutput);

                        // Set the result onto qstrText
                        //
                        if (!strSignedOutput.Exists())
                        {
                            QMessageBox::warning(this, tr("Signing Failed"),
                                                 tr("Failed trying to sign, using the selected identity."));
                            return;
                        }
                        else if (!theSignedFile.VerifySignature(*pNym))
                        {
                            QMessageBox::warning(this, tr("Test Verification Failed"),
                                                 tr("Failed trying to test verify, immediately after signing. Trying authentication key..."));

                            if (!theSignedFile.VerifySigAuthent(*pNym))
                            {
                                QMessageBox::warning(this, tr("Authent Test Also Failed"),
                                                     tr("Failed trying to verify signature with authentication key as well."));
                                return;
                            }
                            else
                                QMessageBox::information(this, tr("SUCCESS USING AUTHENTICATION KEY"), tr("Tried authent key instead of signing key, and it worked!"));
                        }
                        else
                        {
                            std::string str_signed_output(strSignedOutput.Get());
                            qstrText = QString::fromStdString(str_signed_output);
                        }
                    } // else (we have pNym.)
                }
//              std::string  str_output (opentxs::OTAPI_Wrap::It()->FlatSign(str_nym, str_encoded, str_type));
            }
        }
        // --------------------------------
        // Encrypt qstrText and pop up a dialog with the encrypted result.
        //
        if (m_bEncrypt)
        {
            if (ui->listWidgetAdded->count() > 0)
            {
                std::set<const opentxs::Nym*> setRecipients;
                bool      bRecipientsShouldBeAvailable = false;

                // Loop through each NymID in listWidgetAdded, and put them on a opentxs::setOfNyms
                // so we can pass them along to opentxs::OTEnvelope (and so we can clean them up afterwards.)
                // UPDATE: Can't clean them up! Because the wallet only owns private nyms, not public
                // ones, we never know for sure which ones are safe to erase. TODO: Fix in OT by using
                // shared_ptr.
                //
                for (int nIndex = 0; nIndex < ui->listWidgetAdded->count(); ++nIndex)
                {
                    bRecipientsShouldBeAvailable = true;

                    QListWidgetItem   * pItem    = ui->listWidgetAdded->item(nIndex);
                    QVariant            qvarItem = pItem->data(Qt::UserRole);
                    QString             qstrNymID(qvarItem.toString());
                    std::string         str_nym(qstrNymID.toStdString());
                    opentxs::String     strNym(str_nym.c_str());
                    opentxs::Identifier nym_id(strNym);

                    if (!nym_id.IsEmpty())
                    {
                        opentxs::OTPasswordData thePWData("Sometimes need to load private part of nym in order to use its public key. (Fix that!)");

                        const opentxs::Nym * pNym = opentxs::OTAPI_Wrap::OTAPI()->GetOrLoadNym(nym_id,
                                                                               false, //bChecking=false
                                                                               __FUNCTION__,
                                                                               &thePWData);
                        if (NULL == pNym)
                        {
                            QString qstrErrorMsg = QString("%1: %2").arg(tr("Failed loading a recipient; attempting to continue without. NymID")).arg(qstrNymID);

                            QMessageBox::warning(this, tr("Failed Loading Recipient"), qstrErrorMsg);
                        }
                        else
                        {
                            setRecipients.insert(setRecipients.begin(), pNym);
                        }
                    }
                    // qstrNymID will be passed to opentxs::OTEnvelope on its recipient list.
                } // for (selected Nyms.)
                // ---------------------------------------------------
                // We might also want to encrypt to the Signer's Nym, if there is one.
                // We'll default this to ON, but give users the choice to deactivate it.
                //
                if (ui->checkBoxAlso->isVisible() &&
                    ui->checkBoxAlso->isEnabled() &&
                    ui->checkBoxAlso->isChecked() &&
                    !m_nymId.isEmpty())
                {
                    std::string str_signer_nym(m_nymId.toStdString());
                    opentxs::String strSignerNymID(str_signer_nym.c_str());
                    bool bSignerIsAlreadyThere = false;

                    //FOR_EACH(opentxs::setOfNyms(), setRecipients) // See if it's already there, in which case we don't need to do anything else.
                    for(auto it = setRecipients.begin(); it != setRecipients.end(); ++ it)
                    {
                        const opentxs::Nym       * pNym = *it;
                        opentxs::String            strNymID;
                        pNym->GetIdentifier(strNymID);

                        if (strSignerNymID.Compare(strNymID))
                            bSignerIsAlreadyThere = true;
                    }
                    // -------------------------
                    if (!bSignerIsAlreadyThere) // Not already there? Add signer to list of recipients.
                    {
                        bRecipientsShouldBeAvailable = true;

                        opentxs::Identifier signer_nym_id(strSignerNymID);

                        if (!signer_nym_id.IsEmpty())
                        {
                            opentxs::OTPasswordData thePWData("Sometimes need to load private part of nym in order to use its public key. (Fix that!)");

                            auto pNym =
                                opentxs::App::Me().Contract().Nym(signer_nym_id);
                            if (!pNym)
                            {
                                QString qstrErrorMsg = QString("%1: %2").
                                        arg(tr("Failed trying to load the signer; attempting to continue without. NymID")).arg(m_nymId);
                                QMessageBox::warning(this, tr("Failed Loading Signer"), qstrErrorMsg);
                            }
                            else
                            {
                                setRecipients.insert(setRecipients.begin(), pNym.get());
                            }
                        }
                    }
                }
                // ---------------------------------------------------
                if (setRecipients.size() > 0)
                {
                    opentxs::OTEnvelope theEnvelope;
                    opentxs::String   strInput(qstrText.toStdString().c_str());

                    if (!theEnvelope.Seal(setRecipients, strInput))
                    {
                        QMessageBox::warning(this, tr("Encryption Failed"),
                                             tr("Failed trying to encrypt message."));
                        return;
                    }
                    else
                    {
                        // Success encrypting!
                        //
                        opentxs::String     strOutput;
                        opentxs::OTASCIIArmor ascCiphertext(theEnvelope);

                        if (ascCiphertext.WriteArmoredString(strOutput, "ENVELOPE")) // -----BEGIN OT ARMORED ENVELOPE-----
                        {
                            std::string str_output(strOutput.Get());
                            qstrText = QString::fromStdString(str_output);
                        }
                    }
                }
                else if (bRecipientsShouldBeAvailable) // They should be, but they weren't.
                {
                    QMessageBox::warning(this, tr("Failed Loading Recipients"),
                                         tr("Due to failure loading any of the recipients, unable to commence."));
                    return;
                }
            } // if (listItems.size() > 0)
        } // if (m_bEncrypt)
        // -------------------
        // If it's NOT encrypted, but it IS signed, then we want to OT ARMOR it as well.
        // (We don't have to if it's encrypted, since that process already armors it for us.
        //  But this is for the case where it's signed and NOT encrypted.)
        //
        else if (m_bSign && !qstrText.isEmpty())
        {
            std::string  str_text(qstrText.toStdString());
            opentxs::String     strText (str_text.c_str());
            opentxs::String     strOutput;
            opentxs::OTASCIIArmor ascText (strText);

            if (ascText.WriteArmoredString(strOutput, "SIGNED FILE")) // -----BEGIN OT ARMORED SIGNED FILE-----
            {
                std::string str_output(strOutput.Get());
                qstrText = QString::fromStdString(str_output);
            }
        }
        // -----------------------------------------------
        // if qstrText still contains something, pop up a dialog to display the result to the user.
        //
        if (!qstrText.isEmpty())
        {
            QString qstrType("Output:");

            if (m_bSign)
            {
                qstrType = QString(tr("Signed Output:"));
            }
            // -----------
            if (m_bEncrypt)
            {
                if (m_bSign)
                    qstrType = QString(tr("Signed and Encrypted Output:"));
                else
                    qstrType = QString(tr("Encrypted Output:"));
            }
            // -----------
            QString qstrSubTitle(tr("Be sure to copy it somewhere before closing this dialog."));
            // -----------
            // Pop up the result dialog.
            //
            DlgExportedToPass dlgExported(this, qstrText,
                                          qstrType,
                                          qstrSubTitle, false);
            dlgExported.exec();
        }
    } // if (!qstrText.isEmpty())
}
Beispiel #15
0
void CNetParam::OnBnClickedButtonSave()
{
	// TODO: 在此添加控件通知处理程序代码

	CString strText(_T(""));

	m_networkinfo.cur_network = m_NetWorkCarding.GetCurSel();

	m_SignPort.GetWindowText(strText);
	m_networkinfo.cmd_port = _ttoi(strText);

	m_DataPort.GetWindowText(strText);
	m_networkinfo.data_port = _ttoi(strText);

	m_WebPort.GetWindowText(strText);
	m_networkinfo.web_port = _ttoi(strText);

	m_TalkPort.GetWindowText(strText);
	m_networkinfo.talk_port = _ttoi(strText);

	m_networkinfo.network->type = m_NetWorkType.GetCurSel();

	m_MacAddress.GetWindowText(strText);
	memset(m_networkinfo.network->mac, '\0', sizeof(m_networkinfo.network->mac));
	memcpy(m_networkinfo.network->mac, strText.GetBuffer(0), strText.GetLength());
	strText.ReleaseBuffer();

	m_networkinfo.network->dhcp_enable = m_StartDhcp.GetCheck();

	m_IpAddr.GetWindowText(strText);
	memset(m_networkinfo.network->ip, '\0', sizeof(m_networkinfo.network->ip));
	memcpy(m_networkinfo.network->ip, strText.GetBuffer(0), strText.GetLength());
	strText.ReleaseBuffer();

	m_ChildNet.GetWindowText(strText);
	memset(m_networkinfo.network->netmask, '\0', sizeof(m_networkinfo.network->netmask));
	memcpy(m_networkinfo.network->netmask, strText.GetBuffer(0), strText.GetLength());
	strText.ReleaseBuffer();

	m_NetAddr.GetWindowText(strText);
	memset(m_networkinfo.network->gateway, '\0', sizeof(m_networkinfo.network->gateway));
	memcpy(m_networkinfo.network->gateway, strText.GetBuffer(0), strText.GetLength());
	strText.ReleaseBuffer();

	m_networkinfo.auto_dns_enable = m_StartAtupDns.GetCheck();

	m_MainDns.GetWindowText(strText);
	memset(m_networkinfo.main_dns, '\0', sizeof(m_networkinfo.main_dns));
	memcpy(m_networkinfo.main_dns, strText.GetBuffer(0), strText.GetLength());
	strText.ReleaseBuffer();

	m_BackUpDns.GetWindowText(strText);
	memset(m_networkinfo.backup_dns, '\0', sizeof(m_networkinfo.backup_dns));
	memcpy(m_networkinfo.backup_dns, strText.GetBuffer(0), strText.GetLength());
	strText.ReleaseBuffer();

	int iRet = -1;
	iRet = JNetSetParam(g_PubData.g_vLoginHandle[g_PubData.g_iAttributeIng],0,PARAM_NETWORK_INFO, (char *)&m_networkinfo, sizeof(m_networkinfo), TRUE);
	if( iRet != 0)
	{
		AfxMessageBox( g_PubData.g_strSetMessage);
		return ;
	}
	
	m_platform.is_con_cms = m_StartTerrace.GetCheck();

	m_CmsAddr.GetWindowText(strText);
	memset(m_platform.cms_ip, '\0', sizeof(m_platform.cms_ip));
	memcpy(m_platform.cms_ip, strText.GetBuffer(0), strText.GetLength());
	strText.ReleaseBuffer();

	m_CmsPort.GetWindowText(strText);
	m_platform.cms_port = _ttoi(strText);

	m_MdsAddr.GetWindowText(strText);
	memset(m_platform.mds_ip, '\0', sizeof(m_platform.mds_ip));
	memcpy(m_platform.mds_ip, strText.GetBuffer(0), strText.GetLength());
	strText.ReleaseBuffer();

	m_MdsPort.GetWindowText(strText);
	m_platform.mds_port = _ttoi(strText);

	m_Puid.GetWindowText(strText);
	memset(m_platform.pu_id, '\0', sizeof(m_platform.pu_id));
	memcpy(m_platform.pu_id, strText.GetBuffer(0), strText.GetLength());
	strText.ReleaseBuffer();

	m_platform.protocol = m_TransProtocol.GetCurSel();

	iRet = -1;
	iRet = JNetSetParam(g_PubData.g_vLoginHandle[g_PubData.g_iAttributeIng],0,PARAM_PLATFORM_INFO, (char *)&m_platform, sizeof(m_platform), TRUE);
	if( iRet != 0)
	{
		AfxMessageBox(g_PubData.g_strSetMessage);
		return ;
	}

}
Beispiel #16
0
void CDxDatePickerMonth::DrawDaysOfWeek(CDCHandle dc)
{
    if (m_rcDaysOfWeek.IsRectEmpty())
        return;

    // fill background
    dc.FillSolidRect(m_rcDaysOfWeek, m_clrDaysOfWeekBack);

    // draw days of week text
    dc.SetBkColor(m_clrDaysOfWeekBack);
    dc.SetTextColor(m_clrDaysOfWeekText);

    HFONT hFontOld = (HFONT)dc.SelectFont(CDxFontManager::GetSingleton().GetFont(DUIF_DEFAULTFONT));

    int nMaxX = 0;
    SIZE szText;

    dc.GetTextExtent(_T("XX"), 2, &szText);

    int nTwoLetterWidth = szText.cx;
    int nWholeLetterWidth = 0;

    for (int i = 0; i < XTP_WEEK_DAYS; i++)
    {
        CString strText(m_pControl->GetDayOfWeekName(i));

        dc.GetTextExtent(strText, strText.GetLength(), &szText);
        nWholeLetterWidth = max(nWholeLetterWidth, szText.cx);
    }

    for (int nDayDelta = 0; nDayDelta < XTP_WEEK_DAYS; nDayDelta++)
    {
        // calc item rect
        CDxDatePickerDay* pDay = GetDay(nDayDelta);
        CRect rcItem(pDay->GetRect());
        rcItem.top = m_rcDaysOfWeek.top;
        rcItem.bottom = m_rcDaysOfWeek.bottom - 2;
        nMaxX = rcItem.right;

        // get item text
        CString strText(m_pControl->GetDayOfWeekName(pDay->GetDate().GetDayOfWeek()));

        // Check if we can draw whole text
        if (nWholeLetterWidth + 4 <= rcItem.Width())
        {
            dc.DrawText(strText, strText.GetLength(), &rcItem, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
        }
        else if (nTwoLetterWidth + 4 <= rcItem.Width()) // Draw 2 letters
        {
            int nChrLen = (int)_tcsnbcnt(strText, 2);
            dc.DrawText(strText, nChrLen, &rcItem, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
        }
        else // Draw only first letter
        {
            int nChrLen = (int)_tcsnbcnt(strText, 1);
            dc.DrawText(strText, nChrLen, &rcItem, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
        }
    }

    // draw bottom line on days of the week
    CRect rcBottomLine(m_rcDaysOfWeek);
    rcBottomLine.bottom--;
    rcBottomLine.top = rcBottomLine.bottom - 1;
    rcBottomLine.left = m_rcWeekNumbers.right - 1;
    rcBottomLine.right = nMaxX;
    dc.FillSolidRect(rcBottomLine, m_clrMonthBorder);

    dc.SelectFont(hFontOld);
}
Beispiel #17
0
void CUIThread::vWriteTextToTrace(UINT /*unParam*/, LONG lParam)
{
    //CHAR* pacText = (CHAR*)lParam;
	CString strText((CHAR*)lParam);
    m_podTraceWinObj->vDisplayString(strText);
}
Beispiel #18
0
void CChevronOwnerDrawMenu::DrawItem(LPDRAWITEMSTRUCT pdis)
{
	ASSERT(pdis->CtlType == ODT_MENU);

	CString strText(_T(""));
	CSize Size;   

	CDC *pDC;
	pDC = CDC::FromHandle(pdis->hDC);
	int nSave = pDC->SaveDC();
	
	// getting the text (on the right of the bitmap)
	MENUITEMINFO info;
	ZeroMemory(&info, sizeof(MENUITEMINFO));
	info.cbSize = sizeof(MENUITEMINFO);
	info.fMask = MIIM_STRING;
	BOOL bGotText = FALSE;
	if(GetMenuItemInfo(pdis->itemID, &info))
	{
		LPTSTR pszText;

		pszText = strText.GetBuffer(info.cch);
		info.dwTypeData = pszText;
		info.cch++; // space for zero terminator
		bGotText = GetMenuItemInfo(pdis->itemID, &info);
		strText.ReleaseBuffer();
	}

	CBitmap *pBmp;
	pBmp = (CBitmap *) pdis->itemData;

	// Find the rect that will center the bitmap in the menu item
	CRect rc, rcItem(pdis->rcItem);
	BOOL bGotBitmap = FALSE;
	int nBitmapHeight = 0;
	int nBitmapWidth = 0;
	if(pBmp && pBmp->IsKindOf(RUNTIME_CLASS(CBitmap)))
	{
		BITMAP bitmap;
		bGotBitmap = TRUE;
		pBmp->GetObject(sizeof(BITMAP), &bitmap);
		nBitmapHeight = bitmap.bmHeight;
		nBitmapWidth = bitmap.bmWidth;
	}
	else
	{
		// using default icon size
		bGotBitmap = FALSE;
		nBitmapHeight = ::GetSystemMetrics(SM_CYSMICON);
		nBitmapWidth = ::GetSystemMetrics(SM_CXSMICON);
	}
	rc.top = rcItem.Height() / 2 - nBitmapHeight / 2 + rcItem.top - 1;
	rc.left = 0;
	rc.right = nBitmapWidth + 1;
	rc.bottom = nBitmapHeight + 1;
	rc.bottom += rc.top;
	rc.right += rc.left;

	
	//the actual drawing begins
	COLORREF crMenu = ::GetSysColor(COLOR_MENU);
	CDC dcMem;
	dcMem.CreateCompatibleDC(NULL);

	pDC->SelectObject(&m_MenuFont);
	Size = pDC->GetTextExtent(strText);

	// Selected (possibly grayed)
	if(pdis->itemState & ODS_SELECTED)
	{
		// MenuColor
		CRect rcFill(pdis->rcItem);
		rcFill.left = rc.right + 2;
		pDC->FillSolidRect(rcFill, ::GetSysColor(COLOR_HIGHLIGHT));

		// if not grayed and not checked, raise the button
		if (bGotBitmap)
		{
			if(!(pdis->itemState & (ODS_GRAYED | ODS_CHECKED)))
			{
				pDC->Draw3dRect(rc.left, rc.top, rc.Width() + 1, rc.Height() + 1,
					::GetSysColor(COLOR_BTNHIGHLIGHT), ::GetSysColor(COLOR_BTNSHADOW));
			}
		}
		
		// Text
		if (bGotText)
		{
			pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
			pDC->SetTextColor(
				(pdis->itemState & ODS_GRAYED) ? crMenu : ::GetSysColor(COLOR_HIGHLIGHTTEXT));

			pDC->ExtTextOut(rc.right + 3, rc.top + rc.Height() / 2 - Size.cy / 2,
				ETO_OPAQUE, NULL, strText, NULL);
		}
	}
	else
	{
		pDC->FillSolidRect(&pdis->rcItem, crMenu);
		pDC->SetBkColor(crMenu);

		// Grayed (disabled)
		if(pdis->itemState & ODS_GRAYED)
		{
			pDC->SetTextColor(::GetSysColor(COLOR_3DHILIGHT));
			pDC->SetBkMode(TRANSPARENT);

			// Text
			if (bGotText)
			{
				pDC->ExtTextOut(rc.right + 4, rc.top + rc.Height() / 2 - Size.cy / 2 + 1, ETO_OPAQUE, NULL, strText, NULL);
				pDC->SetTextColor(::GetSysColor(COLOR_GRAYTEXT));
				pDC->ExtTextOut(rc.right + 3, rc.top + rc.Height() / 2 - Size.cy / 2, 0, NULL, strText, NULL);
			}
		}
		// Everything else
		else
		{
			// if checked draw as pushed
			if (bGotBitmap)
			{
				if(pdis->itemState & ODS_CHECKED)
				{
					pDC->Draw3dRect(rc.left, rc.top, rc.Width() + 1, rc.Height() + 1,
						::GetSysColor(COLOR_BTNSHADOW), ::GetSysColor(COLOR_BTNHIGHLIGHT));
				}
			}
			
			// text
			if (bGotText)
			{
				pDC->SetBkColor(crMenu);
				pDC->SetTextColor(::GetSysColor(COLOR_MENUTEXT));
				pDC->ExtTextOut(rc.right + 3, rc.top + rc.Height() / 2 - Size.cy / 2, ETO_OPAQUE, NULL, strText, NULL);
			}
		}
	}

	// The bitmap...
	if (bGotBitmap)
	{
		CBitmap bmp;
		int x = 0, y = 0;
		if(pdis->itemState & ODS_GRAYED)
		{
			::AfxGetGrayBitmap(*pBmp, &bmp, crMenu);
			pBmp = &bmp;
		}
		else
		{
			if(pdis->itemState & ODS_CHECKED)
			{
				::AfxGetDitheredBitmap(*pBmp, &bmp, crMenu, RGB(255, 255, 255));
				pBmp = &bmp;
			}
		}

		CDC dcMem;
		dcMem.CreateCompatibleDC(NULL);
		dcMem.SelectObject(pBmp);

		rc.InflateRect(-1, -1);

		pDC->BitBlt(rc.left, rc.top, rc.right, rc.bottom, &dcMem, x, y, SRCCOPY);
	}
	
	pDC->RestoreDC(nSave);
}
STDMETHODIMP
CDirect2DRM::CreateImageFromWrappedTextExt(
				BSTR bstrText,
				IFont *pFont,
				BOOL bShadowed,
				DWORD width, 
				DWORD height,
				DWORD nPoint,
				LPDIRECT2DRMIMAGE *ppImage)
{
	MMASSERT(ppImage);
	if (m_pImageCache == NULL)
		return E_NOTINITIALIZED;

	HRESULT hr;
	LPD2DRMIMAGEPRIVATE pImagePriv = NULL;
	CMFImage *pmfi = NULL;
	SIZE size = {width, height };
	CString strText(bstrText);
	IFont *pIFont = NULL;
	CY ptsize = {nPoint*10000, 0};

	HFONT hFont = NULL;
	if ( pFont != NULL )
	{
		hr = pFont->get_hFont( &hFont);
		if (FAILED(hr))
			goto e_CreateImageFromText;
	} else {
		pIFont = GetDefaultFont();
		hr = pIFont->put_Size(ptsize);
		hr = pIFont->get_hFont( &hFont);
		
		if (FAILED(hr))
			goto e_CreateImageFromText;
	}
	
		// get a reference to the MFImage from the image cache
	if (FAILED(hr = m_pImageCache->GetImageFromText(strText, hFont, 0x00FFFFFF, bShadowed, 0, &size, &pmfi)) ||
		// CoCreate the D2DRMImage object
		FAILED(hr = CoCreateInstance(
						CLSID_CDirect2DRMImage,
						NULL,
						CLSCTX_INPROC_SERVER,
						IID_ID2DRMImagePrivate,
						(LPVOID *) &pImagePriv)) ||
		// initialize the D2DRMImage with the MFImage
		FAILED(hr = pImagePriv->InitFromMFImage(this, pmfi, 0)))
		goto e_CreateImageFromText;

	*ppImage = (LPDIRECT2DRMIMAGE) pImagePriv;

	// release the extra reference we had from the CreateImageFromText
	pmfi->Release();
	MMRELEASE(pIFont);
	return S_OK;

e_CreateImageFromText:
	MMRELEASE(pImagePriv);
	MMRELEASE(pmfi);
	MMRELEASE(pIFont);
	return hr;
}
/**
 * Called to copy over the progress information from @a pOtherProgress.
 *
 * @param   pOtherProgress  The source of the information.
 * @param   fEarly          Early copy.
 *
 * @note    The caller owns the write lock and as cleared mptrOtherProgress
 *          already (or we might recurse forever)!
 */
void ProgressProxy::copyProgressInfo(IProgress *pOtherProgress, bool fEarly)
{
    HRESULT hrc;
    LogFlowThisFunc(("\n"));

    NOREF(fEarly);

    /*
     * No point in doing this if the progress object was canceled already.
     */
    if (!mCanceled)
    {
        /* Detect if the other progress object was canceled. */
        BOOL fCanceled;
        hrc = pOtherProgress->COMGETTER(Canceled)(&fCanceled);
        if (FAILED(hrc))
            fCanceled = FALSE;
        if (fCanceled)
        {
            LogFlowThisFunc(("Canceled\n"));
            mCanceled = TRUE;
            if (m_pfnCancelCallback)
                m_pfnCancelCallback(m_pvCancelUserArg);
        }
        else
        {
            /* Has it completed? */
            BOOL fCompleted;
            hrc = pOtherProgress->COMGETTER(Completed)(&fCompleted);
            if (FAILED(hrc))
                fCompleted = TRUE;
            Assert(fCompleted || fEarly);
            if (fCompleted)
            {
                /* Check the result. */
                LONG hrcResult;
                hrc = pOtherProgress->COMGETTER(ResultCode)(&hrcResult);
                if (FAILED(hrc))
                    hrcResult = hrc;
                if (SUCCEEDED((HRESULT)hrcResult))
                    LogFlowThisFunc(("Succeeded\n"));
                else
                {
                    /* Get the error information. */
                    ComPtr<IVirtualBoxErrorInfo> ptrErrorInfo;
                    hrc = pOtherProgress->COMGETTER(ErrorInfo)(ptrErrorInfo.asOutParam());
                    if (SUCCEEDED(hrc) && !ptrErrorInfo.isNull())
                    {
                        Bstr bstrIID;
                        hrc = ptrErrorInfo->COMGETTER(InterfaceID)(bstrIID.asOutParam()); AssertComRC(hrc);
                        if (FAILED(hrc))
                            bstrIID.setNull();

                        Bstr bstrComponent;
                        hrc = ptrErrorInfo->COMGETTER(Component)(bstrComponent.asOutParam()); AssertComRC(hrc);
                        if (FAILED(hrc))
                            bstrComponent = "failed";

                        Bstr bstrText;
                        hrc = ptrErrorInfo->COMGETTER(Text)(bstrText.asOutParam()); AssertComRC(hrc);
                        if (FAILED(hrc))
                            bstrText = "<failed>";

                        Utf8Str strText(bstrText);
                        LogFlowThisFunc(("Got ErrorInfo(%s); hrcResult=%Rhrc\n", strText.c_str(), hrcResult));
                        Progress::notifyComplete((HRESULT)hrcResult,
                                                 Guid(bstrIID).ref(),
                                                 Utf8Str(bstrComponent).c_str(),
                                                 "%s", strText.c_str());
                    }
                    else
                    {
                        LogFlowThisFunc(("ErrorInfo failed with hrc=%Rhrc; hrcResult=%Rhrc\n", hrc, hrcResult));
                        Progress::notifyComplete((HRESULT)hrcResult,
                                                 COM_IIDOF(IProgress),
                                                 "ProgressProxy",
                                                 tr("No error info"));
                    }
                }
            }
            else
                LogFlowThisFunc(("Not completed\n"));
        }
    }
    else
        LogFlowThisFunc(("Already canceled\n"));

    /*
     * Did cancelable state change (point of no return)?
     */
    if (mCancelable && !mCompleted && !mCanceled)
    {
        BOOL fCancelable;
        hrc = pOtherProgress->COMGETTER(Cancelable)(&fCancelable); AssertComRC(hrc);
        if (SUCCEEDED(hrc) && !fCancelable)
        {
            LogFlowThisFunc(("point-of-no-return reached\n"));
            mCancelable = FALSE;
        }
    }
}
Beispiel #21
0
	int Debug(lua_State *L)
	{
		std::string strText( lua_tolstring( L, -1, NULL ) );
		OutputDebugString( strText.c_str() );
		return 0;
	}