Ejemplo n.º 1
0
void CtrfFolderColumn::SetImageID(CaDisplayInfo* pDisplayInfo)
{
	int nImage, nImageExpand;
	int nEmptyImage, nEmptyImageExpand;

	pDisplayInfo->GetEmptyImage  (nEmptyImage, nEmptyImageExpand);
	pDisplayInfo->GetFolderImage (nImage, nImageExpand);
	m_treeCtrlData.SetImage (nImage, nImageExpand);
	
	CtrfItemData* pEmptyNode = GetEmptyNode();
	if (pEmptyNode)
	{
		pEmptyNode->GetTreeCtrlData().SetImage (nEmptyImage, nEmptyImageExpand);
	}
}
Ejemplo n.º 2
0
BOOL CNetRssProtocol::SendNet_StatusExch(const char* szRec,const char* szProtocol)
{
	if(CString(szProtocol)=="sms"){
		return 1;
	}
	if(objSettings.lRSSLocUser){
		if(isScreenSaverActiveOrCLocked()){
			return -1;
		}
	}
	CString szRecipient=GetCompNameNoProtocol(szRec);
	int iPerson=objSettings.AddrBook.FindPersonByIP(szRecipient,TRUE);
	if(iPerson!=-1){
		if(objSettings.AddrBook.aPersons[iPerson]->IsGroup()){
			// Групповой-заблокирован
			return -1;
		};
	}
	CWebWorld url;
	CString sRSS=url.GetWebPage(szRecipient);
	if(sRSS==""){
		// Не доступен
		return -1;
	}
	#ifdef _DEBUG
	CString sFile=CString("lastblog")+szRecipient+".xml";//http://davydov.blogspot.com/atom.xml
	MakeSafeFileName(sFile);
	SaveFile(CString("c://")+sFile,sRSS);
	#endif
	int iStatus=1;
	XDoc* feedDoc=parseXML(sRSS);
	XNode* feed=0;
	if(feedDoc){
		feed=feedDoc->GetRoot();
		if(!feed){
			delete feedDoc;
			return -1;
		}
		CString sLnewsBuildDate=aLoadedRss[szRecipient];
		int iMaxNews=objSettings.dwProtocolRSSMAxNews;
		if(sLnewsBuildDate==""){
			iMaxNews=5;
		}
		CString sLnewsBuildDateToSet="";
		BOOL bAtom=0;
		CString sGlobalTitle;
		if(feed->GetChild("channel",1)==GetEmptyNode() && feed->GetChild("title",1)!=GetEmptyNode()){
			// Atom!!!
			bAtom=1;
			sGlobalTitle=feed->GetChild("title",1)->value;
		}else{
			sGlobalTitle=feed->GetChild("channel",1)->GetChild("title",1)->value;
		}
		CString sFrom="";
		if(iPerson!=-1){
			sFrom=objSettings.AddrBook.aPersons[iPerson]->GetTitle();
		}else{
			sFrom=sGlobalTitle+"/rss";
		}
		CXMLNodes feedItems;
		if(bAtom){
			feed->FindByTagName("entry",FALSE,feedItems);
		}else{
			feed->GetChild("channel",1)->FindByTagName("item",FALSE,feedItems);
		}
		int iCount=0;
		int iLenCount=feedItems.GetSize();
		if(iLenCount==0){
			// Может rdf???
			feed->FindByTagName("item",FALSE,feedItems);
			iLenCount=feedItems.GetSize();
		}
		CString sSummary;
		while(iCount<iLenCount && iCount<iMaxNews){
			XNode* item=feedItems[iCount];
			CString sPubDate;
			if(bAtom){
				sPubDate=item->GetChild("issued",1)->value;
			}else{
				sPubDate=item->GetChild("pubDate",1)->value;
				if(sPubDate==""){
					//rdf???
					sPubDate=item->GetChild("dc:date",1)->value;
				}
			}
			//sPubDate=UnescapeString(sPubDate);
			StripTags(sPubDate);
			DeEntitize(sPubDate);

			CString sTitle;
			sTitle=item->GetChild("title",1)->value;
			//sTitle=UnescapeString(sTitle);
			StripTags(sTitle);
			DeEntitize(sTitle);
			if(sTitle==""){
				sTitle=sGlobalTitle;
			}
			
			CString sAuthor;
			if(bAtom){
				LPXNode pAut;
				pAut=item->GetChild("author",1);
				if(pAut->iBeginPos!=-1 && pAut->iEndPos!=-1){
					sAuthor=sRSS.Mid(pAut->iBeginPos,pAut->iEndPos-pAut->iBeginPos);
				}
			}else{
				sAuthor=item->GetChild("author",1)->value;
				if(sAuthor==""){
					//rdf???
					sAuthor=item->GetChild("dc:creator",1)->value;
				}
			}
			//sAuthor=UnescapeString(sAuthor);
			StripTags(sAuthor);
			DeEntitize(sAuthor);
			if(sAuthor!=""){
				sTitle+=" (";
				sTitle+=sAuthor;
				sTitle+=")";
			}
			
			LPXNode pDesk;
			if(bAtom){
				pDesk=item->GetChild("content",1);
			}else{
				pDesk=item->GetChild("description",1);
			}
			CString sDesk;
			if(pDesk->iBeginPos!=-1 && pDesk->iEndPos!=-1){
				sDesk=sRSS.Mid(pDesk->iBeginPos,pDesk->iEndPos-pDesk->iBeginPos);
			}
			/*
			if(sDesk.Find("%20")!=-1){
				sDesk=UnescapeString(sDesk);
			}
			*/
			CString sDeskL=sDesk;
			sDeskL.MakeLower();
			if(sDeskL.Find(";div")!=-1 || sDeskL.Find(";span")!=-1){
				// Для извращенных...
				DeEntitize(sDesk);
				StripTags(sDesk);
			}else{
				// Это по правильному
				StripTags(sDesk);
				DeEntitize(sDesk);
			}
			sDesk.TrimLeft();
			sDesk.TrimRight();

			CString sLink;
			if(bAtom){
				CXMLNodes feedLinks;
				item->FindByTagName("link",FALSE,feedLinks);
				for(int j=0;j<feedLinks.GetSize();j++){
					XNode* itemLnk=feedLinks[j];
					sLink=itemLnk->GetAttr("href")->value;
					CString sType=itemLnk->GetAttr("type")->value;
					sType.MakeLower();
					if(sType.Find("text")!=-1){
						break;// Наша линка!
					}
				}
			}else{
				sLink=item->GetChild("link",1)->value;
			}
			sLink=UnescapeString(sLink);
			StripTags(sLink);
			DeEntitize(sLink);
			sLink.TrimLeft();
			sLink.TrimRight();
			
			{
				CSmartLock SL(&csRssFeeds,TRUE);
				CString sRnewsBuildDate=sLink+"\t"+sPubDate+" "+sTitle+" "+sDesk;
				if(sLnewsBuildDate==sRnewsBuildDate){
					if(iCount==0){
						iStatus=1;
					}
					break;
				}
				if(sLnewsBuildDateToSet==""){// Запомнили самую первую новость
					sLnewsBuildDateToSet=sRnewsBuildDate;
				}
				/*
				#ifdef _DEBUG
				else{
					sDesk+="\nOld id-text:"+sLnewsBuildDate;
					sDesk+="\nNew id-text:"+sRnewsBuildDate;
				}
				#endif
				*/
			}

			if(sPubDate!=""){
				COleDateTime dt;
				dt.ParseDateTime(sPubDate);
				if(dt.GetStatus()==COleDateTimeSpan::valid){
					sTitle=dt.Format("%x %X. ")+sTitle;
				}
			}
			CString sNews=sTitle;
			sNews+="\n";
			if(sDesk!=""){
				sNews+="\n";
				sNews+=sDesk;
			}
			if(sLink!=""){
				sNews+="\n\n";
				sNews+=_l("Read more")+": ";
				sNews+=sLink;
			}
			CDataXMLSaver::Xml2Str(sNews);
			if(objSettings.lRSSSummar){
				sSummary+="\n";
				sSummary+="\n";
				sSummary+=sTitle;
				sSummary+="\n";
				sSummary+=_l("Read more")+": ";
				sSummary+=sLink;
			}else{
				CString sAttach="";
				if(objSettings.dwProtocolRSSOType){
					sAttach+=Format("["DEF_OPENTYPE"%i]",objSettings.dwProtocolRSSOType);
				}
				OpenMessage(sFrom,"",sNews,"",sAttach,sGlobalTitle);
			}
			iCount++;
		}
		if(sSummary!=""){
			CString sAttach="";
			if(objSettings.dwProtocolRSSOType){
				sAttach+=Format("["DEF_OPENTYPE"%i]",objSettings.dwProtocolRSSOType);
			}
			sSummary.TrimLeft();
			OpenMessage(sFrom,"",sSummary,"",sAttach,sGlobalTitle);
		}
		if(feedDoc){
			delete feedDoc;
		}
		if(sLnewsBuildDateToSet!=""){
			aLoadedRss.SetAt(szRecipient,sLnewsBuildDateToSet);
		}
	}
	if(iPerson!=-1){
		objSettings.AddrBook.aPersons[iPerson]->iOnlineStatus=iStatus;
		RefreshUserStatusIcon(iPerson);
	}
	return 0;
}
Ejemplo n.º 3
0
/*-----------------------------------------------------------------------------
 *  设置data cache
 *  先获取indexnode,进行时间对比
 *  然后获取旧的数据,并在linktable中分配新的空间
 *  然后修改indexnode中的相关值
 *-----------------------------------------------------------------------------*/
int SetCacheDataByKey(HashTable *pstHashTable, IndexNode *pstIndexNode, char *sDataBuf, uint32_t dwDataLen)
/*int SetCacheDataByKey(HashTable *pstHashTable, uint32_t dwUin, uint64_t ddwTime,char *sDataBuf, uint32_t dwDataLen)*/
{
    int ret = 0;
    IndexNode *pstOldIndexNode = NULL, *pstNewIndexNode = NULL;
    uint32_t dwStartPos = 0,dwNextPos = 0, dwUin = 0;
    uint64_t ddwTime = 0;

    if(pstHashTable == NULL || pstIndexNode == NULL || sDataBuf == NULL || dwDataLen == 0)
    {
        return -1;
    }

    dwUin = pstIndexNode->dwUin;
    ddwTime = pstIndexNode->ddwLastPublicTime;

    if((ret = GetIndexNode(pstHashTable,dwUin, &pstOldIndexNode)) < 0)
    {
        DD("Get dwUin = %d IndexNode error. ret = %d\n", dwUin, ret);
        /*return -2;*/
    }

    dwUinDataLen = 0;
    /*判断顺序时间*/
    if(pstOldIndexNode != NULL)
    {
        DD("pstOldIndexNode->ddwLastPublicTime = %ld\t ddwTime = %ld.\n", pstOldIndexNode->ddwLastPublicTime, ddwTime);
        if(pstOldIndexNode->ddwLastPublicTime >= ddwTime)
        {
            DD("pstOldIndexNode->ddwLastPublicTime = %ld\t ddwTime = %ld.\n", pstOldIndexNode->ddwLastPublicTime, ddwTime);
            return -2;
        }

        printf("--------------获取旧数据-------------\n");
        dwUinDataLen = MAX_UIN_CACHED_BUFLEN;
        if((ret = GetCacheDataByPos(pstHashTable, dwUin, szUinData,&dwUinDataLen)) < 0)
        {
            /*第一次写入*/
            if(ret == UIN_NOT_EXIST)
            {
            }
            else
            {
                DD("GetCacheDataByPos error. ret = %d\n",ret);
                return -3;
            }
        }
    }

    printf("len = %d\t data = %s\n", dwUinDataLen, szUinData);
    memcpy(szUinData + dwUinDataLen, sDataBuf, dwDataLen);
    dwUinDataLen += dwDataLen;

    /*if((ret = SetLinkTableDataByKey(dwUin, sDataBuf, dwDataLen,&dwStartPos)) < 0)*/
    if((ret = SetLinkTableDataByKey(dwUin, szUinData, dwUinDataLen,&dwStartPos)) < 0)
    {
        fprintf(stderr, "SetLinkTableDataByKey error. ret = %d error = %s\n", ret, strerror(errno));
        return -4;
    }
    printf("startpos = %d\n", dwStartPos);

    /*如果没有索引节点*/
    if(pstOldIndexNode == NULL)
    {
        DD("get new index node\n");
        /*获取一个新的索引节点*/
        if((pstNewIndexNode = GetEmptyNode(pstHashTable,dwUin)) == NULL)
        {
            /*如果失败 则释放之前申请的linktable资源*/
            ClearOldElement(dwUin,dwStartPos);
            return -5;
        }
        pstNewIndexNode->dwPosition = dwStartPos;
        /*pstNewIndexNode->dwDatalen = dwDataLen;*/
        pstNewIndexNode->dwDatalen = dwUinDataLen;
        pstNewIndexNode->ddwLastPublicTime = ddwTime;
        pstNewIndexNode->ddwUnitSeq = pstIndexNode->ddwUnitSeq;
        pstNewIndexNode->ddwUinSeq = pstIndexNode->ddwUinSeq;
        printf("SetCacheDataByKey pstIndexNode->dwUin = %d\n",pstNewIndexNode->dwUin);
        printf("SetCacheDataByKey pstIndexNode->dwPosition = %d\n",pstNewIndexNode->dwPosition);
        printf("SetCacheDataByKey pstIndexNode->dwDatalen = %d\n",pstNewIndexNode->dwDatalen);
        printf("SetCacheDataByKey pstIndexNode->ddwLastPublicTime = %ld\n",pstNewIndexNode->ddwLastPublicTime);
    }
    /*有索引节点 修改起始块号 释放之前申请的块*/
    else
    {
        dwNextPos = pstOldIndexNode->dwPosition;
        pstOldIndexNode->dwPosition = dwStartPos;
        pstOldIndexNode->dwDatalen = dwUinDataLen;
        pstOldIndexNode->ddwLastPublicTime = ddwTime;
        pstOldIndexNode->ddwUnitSeq = pstIndexNode->ddwUnitSeq;
        pstOldIndexNode->ddwUinSeq = pstIndexNode->ddwUinSeq;
        printf("SetCacheDataByKey pstIndexNode->dwUin = %d\n",pstOldIndexNode->dwUin);
        printf("SetCacheDataByKey pstIndexNode->dwPosition = %d\n",pstOldIndexNode->dwPosition);
        printf("SetCacheDataByKey pstIndexNode->dwDatalen = %d\n",pstOldIndexNode->dwDatalen);
        printf("SetCacheDataByKey pstIndexNode->ddwLastPublicTime = %ld\n",pstOldIndexNode->ddwLastPublicTime);
        ClearOldElement(dwUin, dwNextPos);
    }

    return 0;
}