示例#1
0
void
CConnectionManager::ProcessMessage(Json::Value& msg)
{
	CString command = UnpackValue(msg["command"]);
	if (command==_T("AboutMe"))
	{
		m_Connected = true;
		m_Agent = UnpackValue(msg["agent"]);
		m_Version = UnpackValue(msg["version"]);
		CString log;
		log.Format(_T("Connected to %s %s"), m_Agent, m_Version);
		m_Parent->Log(log, ICON_CONNECTED);
		RequestResetLastSentTitle();
		RequestSendInfoAboutPage();
		UpdateIcon();
	}
	if (command==_T("DoRefresh"))
	{
		CString name = UnpackValue(msg["name"]);
		CString story = GetStory(msg);
		CString log;

		// test current url
		CString url = GetURL(m_Parent->GetBrowser());
		m_CS.Enter(); // m_SitesModel can be accessed by watchdog
		bool answer = m_SitesModel.Test(url);
		m_CS.Leave();

		if (answer)
		{
			log.Format(_T("Refresh request from %s: %s"), name, story);
			m_Parent->Log(log, ICON_REFRESH);
			PerformRefresh();
		}
		else
		{
			log.Format(_T("Refresh request from %s (not allowed for this site - modify 'Allowed Sites' using XRefresh toolbar icon)"), name);
			m_Parent->Log(log, ICON_CANCEL);
		}
	}
}
示例#2
0
CString 
CConnectionManager::GetStory(Json::Value& msg)
{
	int changed = 0;
	int created = 0;
	int deleted = 0;
	int renamed = 0;
	Json::Value files = msg["files"];
	for (unsigned int i=0; i<files.size(); i++)
	{
		Json::Value file = files[i];
		CString action = UnpackValue(file["action"]);
		if (action==_T("changed")) changed++;
		if (action==_T("created")) created++;
		if (action==_T("deleted")) deleted++;
		if (action==_T("renamed")) renamed++;
	}
	
	CString fs;
	CString s[4];
	int i = 0;
	fs = FileSentence(created, _T("created"));
	if (fs.GetLength()) s[i++] = fs;
	fs = FileSentence(deleted, _T("deleted"));
	if (fs.GetLength()) s[i++] = fs;
	fs = FileSentence(changed, _T("changed"));
	if (fs.GetLength()) s[i++] = fs;
	fs = FileSentence(renamed, _T("renamed"));
	if (fs.GetLength()) s[i++] = fs;
	
	CString story;
	if (i==0) return _T("?");
	if (i==1) story.Format(_T("%s"), s[0]);
	if (i==2) story.Format(_T("%s and %s"), s[0], s[1]);
	if (i==3) story.Format(_T("%s, %s and %s"), s[0], s[1], s[2]);
	if (i==4) story.Format(_T("%s, %s, %s and %s"), s[0], s[1], s[2], s[3], s[4]);
	return story;
}
示例#3
0
文件: spmxml.cpp 项目: smurav/gis36
QVariant CSpmXml::GetAttr(const QString& strAttrName, xmlNodePtr pNode)
{
	QVariant vtRes;

	pNode = GetNode(pNode);
	if (0 == pNode)
		return vtRes;

	if (!xmlHasProp(pNode, BAD_CAST strAttrName.toUtf8().data()))
		return vtRes;

	QString strValue = QString::fromUtf8((char *)xmlGetProp(pNode, BAD_CAST strAttrName.toUtf8().data()));
	if (strValue.startsWith(":", Qt::CaseInsensitive)) // Возможно хранится вариант
	{
		vtRes = UnpackValue(strValue);
		if (vtRes.isValid())
			return vtRes;
		else
			return strValue;
	}
	else
		return strValue;
}
示例#4
0
文件: spmxml.cpp 项目: smurav/gis36
QVariant CSpmXml::GetValue(xmlNodePtr pNode)
{
	QVariant vtRes;

	pNode = GetNode(pNode);
	if (0 == pNode)
		return vtRes;

	if (pNode->type != XML_TEXT_NODE && pNode->type != XML_COMMENT_NODE)	// patch by vpasha 01.09.09
		return vtRes;

	QString strValue = QString::fromUtf8((char *)xmlNodeGetContent(pNode));
	if (strValue.startsWith(":", Qt::CaseInsensitive)) // Возможно хранится вариант
	{
		vtRes = UnpackValue(strValue);
		if (vtRes.isValid())
			return vtRes;
		else
			return strValue;
	}
	else
		return strValue;
}