?? site.cpp.svn-base
字號:
/**
* Site.cpp
*
* Copyright (C) 2008 David Andrs <pda@jasnapaka.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifdef PRSSR_APP
#include "StdAfx.h"
#include "prssr.h"
#include "misc.h"
#endif
#if defined PRSSR_TODAY
#include "../prssrtoday/StdAfx.h"
#endif
#include "Site.h"
#include "../share/reg.h"
#include "../share/defs.h"
#include "../share/fs.h"
#include "misc.h"
#include "xml/FeedFile.h"
#include "xml/OpmlFile.h"
#ifdef PRSSR_APP
#include "Config.h"
#elif defined PRSSR_TODAY
#include "../prssrtoday/Config.h"
#endif
#ifdef MYDEBUG
#undef THIS_FILE
static TCHAR THIS_FILE[] = _T(__FILE__);
#include "debug/crtdbg.h"
#define new MYDEBUG_NEW
#endif
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// registry
static LPCTSTR szName = _T("Name");
static LPCTSTR szIdx = _T("Idx");
static LPCTSTR szFileName = _T("File Name");
static LPCTSTR szXmlUrl = _T("XML URL");
static LPCTSTR szUseGlobalCacheOptions = _T("Use Global Cache Options");
static LPCTSTR szCacheItemImages = _T("Cache Item Images");
static LPCTSTR szCacheHtml = _T("Cache Html");
static LPCTSTR szCacheLimit = _T("Cache Limit");
static LPCTSTR szUpdateInterval = _T("Update Interval");
static LPCTSTR szCacheEnclosures = _T("Cache Enclosures");
static LPCTSTR szEnclosureLimit = _T("Enclosure Limit");
static LPCTSTR szETag = _T("ETag");
static LPCTSTR szLastModified = _T("LastModified");
static LPCTSTR szUserName = _T("Username");
static LPCTSTR szPassword = _T("Password");
static LPCTSTR szSort = _T("Sort");
static LPCTSTR szSortReversed = _T("SortReversed");
static LPCTSTR szUnreadCount = _T("Unread Count");
static LPCTSTR szFlaggedCount = _T("Flagged Count");
static LPCTSTR szCheckFavIcon = _T("Check FavIcon");
//#ifdef PRSSR_APP
CSiteList SiteList;
CSiteItem UnreadItems(NULL, CSiteItem::VFolder);
CSiteItem FlaggedItems(NULL, CSiteItem::VFolder);
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CFeedInfo::CFeedInfo() {
TodayShow = TRUE;
#if defined PRSSR_APP
UseGlobalCacheOptions = TRUE;
CacheItemImages = FALSE;
CacheHtml = FALSE;
CacheLimit = CACHE_LIMIT_DEFAULT;
UpdateInterval = UPDATE_INTERVAL_GLOBAL;
CacheEnclosures = FALSE;
EnclosureLimit = 0;
#endif
}
CFeedInfo &CFeedInfo::operator=(const CFeedInfo &o) {
if (this != &o) {
FileName = o.FileName;
XmlUrl = o.XmlUrl;
TodayShow = o.TodayShow;
#if defined PRSSR_APP
UseGlobalCacheOptions = o.UseGlobalCacheOptions;
CacheItemImages = o.CacheItemImages;
CacheHtml = o.CacheHtml;
CacheLimit = o.CacheLimit;
UpdateInterval = o.UpdateInterval;
CacheEnclosures = o.CacheEnclosures;
EnclosureLimit = o.EnclosureLimit;
ETag = o.ETag;
LastModified = o.LastModified;
UserName = o.UserName;
Password = o.Password;
#endif
}
return *this;
}
CFeedInfo::~CFeedInfo() {
}
#ifdef PRSSR_APP
CString CFeedInfo::GenerateFileName(const CString &url) {
return GetSha1Hash(url);
}
#endif
// CSiteItem //////////////////////////////////////////////////////////
CSiteItem::CSiteItem(CSiteItem *parent, eType type) {
LOG1(5, "CSiteItem::CSiteItem(%d)", type);
Parent = parent;
Type = type;
Info = NULL;
Feed = NULL;
#ifdef PRSSR_APP
Sort.Item = CSortInfo::Date;
Sort.Type = CSortInfo::Descending;
#endif
if (Type == Site)
Status = Empty;
else
Status = Ok;
ImageIdx = -1;
CheckFavIcon = TRUE;
Modified = FALSE;
UnreadItems = 0;
FlaggedItems = 0;
CheckFavIcon = TRUE;
InitializeCriticalSection(&CSLoadFeed);
#ifdef PRSSR_TODAY
memset(&LastUpdate, 0, sizeof(FILETIME));
#endif
}
CSiteItem::CSiteItem(CSiteItem *parent, CSiteItem *siteItem) {
LOG1(5, "CSiteItem::CSiteItem(%p)", siteItem);
Parent = parent;
Type = siteItem->Type;
Name = siteItem->Name;
ImageIdx = siteItem->ImageIdx;
CheckFavIcon = siteItem->CheckFavIcon;
Modified = siteItem->Modified;
#ifdef PRSSR_APP
Sort = siteItem->Sort;
Info = NULL;
#endif
if (siteItem->Type == Site) {
Status = Empty;
Info = new CFeedInfo();
*Info = *(siteItem->Info);
Feed = NULL;
UnreadItems = siteItem->UnreadItems;
FlaggedItems = siteItem->FlaggedItems;
}
else if (siteItem->Type == VFolder) {
Status = Empty;
Feed = NULL;
UnreadItems = 0;
FlaggedItems = 0;
}
else {
Status = Ok;
}
InitializeCriticalSection(&CSLoadFeed);
#ifdef PRSSR_TODAY
LastUpdate = siteItem->LastUpdate;
#endif
}
CSiteItem::~CSiteItem() {
LOG1(1, "CSiteItem::~CSiteItem(%S)", Name);
DeleteCriticalSection(&CSLoadFeed);
}
void CSiteItem::Destroy() {
LOG1(5, "CSiteItem::Destroy(%S)", Name);
switch (Type) {
case Site:
delete Info; Info = NULL;
if (Feed != NULL) Feed->Destroy();
delete Feed; Feed = NULL;
break;
case VFolder:
delete Info; Info = NULL;
// we do not destroy feed, since vfolder is an array of links to already existing items that are deallocated elsewhere
delete Feed; Feed = NULL;
break;
case Group:
while (!SubItems.IsEmpty()) {
CSiteItem *item = SubItems.RemoveHead();
item->Destroy();
delete item;
}
break;
}
}
void CSiteItem::EnsureSiteLoaded() {
LOG0(5, "CSiteItem::EnsureSiteLoaded()");
if (Type == Site) {
// if not loaded ->load
EnterCriticalSection(&CSLoadFeed);
if (Status == Empty) {
CFeed *feed = new CFeed();
CString pathName;
#if defined PRSSR_APP
pathName = GetCacheFile(FILE_TYPE_FEED, Config.CacheLocation, Info->FileName);
#elif defined PRSSR_TODAY
pathName.Format(_T("%s\\feeds\\%s"), Config.CacheLocation, Info->FileName);
#endif
if (feed->Load(pathName, this)) {
Status = Ok;
#ifdef PRSSR_APP
feed->UpdateHiddenFlags();
// feed->SetKeywordFlags(SiteList.GetKeywords());
#endif
if (Feed != NULL) Feed->Destroy();
delete Feed;
Feed = feed;
UpdateCachedCounts();
}
else {
Status = Error;
#if defined PRSSR_APP
// discard ETag and LastModified value (to allow update)
Info->ETag.Empty();
Info->LastModified.Empty();
#endif
UpdateCachedCounts();
if (feed != NULL) feed->Destroy();
delete feed;
}
}
LeaveCriticalSection(&CSLoadFeed);
}
}
int CSiteItem::GetUnreadCount() const {
LOG0(5, "CSiteItem::GetUnreadCount()");
if (Type == Site) {
if (Status == Ok && Feed != NULL)
return Feed->GetUnreadCount() + Feed->GetNewCount();
else
return UnreadItems;
}
else if (Type == Group) {
int unreadCount = 0;
POSITION pos = SubItems.GetHeadPosition();
while (pos != NULL) {
CSiteItem *si = SubItems.GetNext(pos);
unreadCount += si->GetUnreadCount();
}
return unreadCount;
}
else {
return 0;
}
}
int CSiteItem::GetFlaggedCount() const {
LOG0(5, "CSiteItem::GetFlaggedCount()");
if (Type == Site) {
if (Status == Ok && Feed != NULL)
return Feed->GetFlaggedCount();
else
return FlaggedItems;
}
else if (Type == Group) {
int flaggedCount = 0;
POSITION pos = SubItems.GetHeadPosition();
while (pos != NULL) {
CSiteItem *si = SubItems.GetNext(pos);
flaggedCount += si->GetFlaggedCount();
}
return flaggedCount;
}
else {
return 0;
}
}
void CSiteItem::UpdateCachedCounts() {
LOG0(5, "CSiteItem::UpdateCachedCounts()");
if (Type == Site) {
if (Feed != NULL)
UnreadItems = Feed->GetNewCount() + Feed->GetUnreadCount();
else
UnreadItems = 0;
}
else if (Type == Group) {
POSITION pos = SubItems.GetHeadPosition();
while (pos != NULL) {
CSiteItem *si = SubItems.GetNext(pos);
si->UpdateCachedCounts();
}
}
}
void CSiteItem::GetSites(CList<CSiteItem *, CSiteItem *> &sites) {
if (Type == Site)
sites.AddTail(this);
else if (Type == Group) {
POSITION pos = SubItems.GetHeadPosition();
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -