📄 sitemanagerdlg.cpp.svn-base
字号:
CSiteItem *item = new CSiteItem(NULL, CSiteItem::Site);
// add site offline
CFeedInfo *info = new CFeedInfo();
info->FileName = CFeedInfo::GenerateFileName(dlgAdd.m_strURL);
info->XmlUrl= dlgAdd.m_strURL;
info->TodayShow = ShowNewChannelsOnToday;
item->Status = CSiteItem::Error;
item->Name = dlgAdd.m_strName;
item->Info = info;
item->CheckFavIcon = TRUE;
// add it to the list
AddItem(hParent, item);
m_ctlSites.Expand(hParent, TVE_EXPAND);
}
// if (Config.SetPropertiesAfterSiteAdded)
// SetSiteProperties(item);
}
}
void CSiteManagerDlg::OnAddGroup() {
LOG0(1, "CSiteManagerDlg::OnAddGroup()");
HTREEITEM hItem = m_ctlSites.GetSelectedItem();
if (hItem == NULL) return;
CSiteItem *parent = (CSiteItem *) m_ctlSites.GetItemData(hItem);
if (parent->Type == CSiteItem::Site) {
hItem = m_ctlSites.GetParentItem(hItem);
parent = (CSiteItem *) m_ctlSites.GetItemData(hItem);
}
m_bAddingGroup = TRUE;
m_ctlSites.ModifyStyle(0, TVS_EDITLABELS);
m_ctlSites.Expand(hItem, TVE_EXPAND);
HTREEITEM hNewItem = InsertGroup(hItem, new CSiteItem(parent, CSiteItem::Group), TVI_FIRST);
m_ctlSites.Expand(hItem, TVE_EXPAND);
m_ctlSites.EnsureVisible(hNewItem);
m_ctlSites.EditLabel(hNewItem);
}
void CSiteManagerDlg::OnEdit() {
LOG0(1, "CSiteManagerDlg::OnEdit()");
HTREEITEM hSelItem = m_ctlSites.GetSelectedItem();
if (hSelItem == NULL || hSelItem == m_ctlSites.GetRootItem())
return;
CSiteItem *si = (CSiteItem *) m_ctlSites.GetItemData(hSelItem);
if (si->Type == CSiteItem::Site)
SiteProperties(si, this);
}
void CSiteManagerDlg::OnRemove() {
LOG0(1, "CSiteManagerDlg::OnRemove()");
HTREEITEM hSelItem = m_ctlSites.GetSelectedItem();
if (hSelItem == NULL || hSelItem == m_ctlSites.GetRootItem())
return;
if (PrssrMessageBox(IDS_CONFIRM_OPERATION, IDS_DELETE_ITEMS, MB_YESNO | MB_ICONSTOP, IDS_DELETE) == IDYES) {
CSiteItem *si = (CSiteItem *) m_ctlSites.GetItemData(hSelItem);
// update subscription in syncer
if (Syncer != NULL && Connection.IsAvailable() == S_OK) {
CWaitCursor wait;
Syncer->RemoveSubscription(si->Info->XmlUrl);
}
DeleteItem(hSelItem, TRUE);
UpdateControls();
}
}
void CSiteManagerDlg::OnRename() {
LOG0(1, "CSiteManagerDlg::OnRename()");
HTREEITEM hSelItem = m_ctlSites.GetSelectedItem();
if (hSelItem == NULL || hSelItem == m_ctlSites.GetRootItem())
return;
CSiteItem *si = (CSiteItem *) m_ctlSites.GetItemData(hSelItem);
// edit name
m_bAddingGroup = FALSE;
m_ctlSites.ModifyStyle(0, TVS_EDITLABELS);
m_ctlSites.EnsureVisible(hSelItem);
m_ctlSites.EditLabel(hSelItem);
}
void CSiteManagerDlg::OnMoveDown() {
LOG0(1, "CSiteManagerDlg::OnMoveDown()");
HTREEITEM hSelItem = m_ctlSites.GetSelectedItem();
if (hSelItem == NULL) return;
// find next item to insert
HTREEITEM hNext = m_ctlSites.GetNextVisibleItem(hSelItem);
HTREEITEM hParent = m_ctlSites.GetParentItem(hNext);
while (hNext != NULL) {
if (hParent == m_ctlSites.GetRootItem()) {
break;
}
else if (hParent == hSelItem) {
// try the next visible item
hNext = m_ctlSites.GetNextVisibleItem(hNext);
hParent = hNext;
}
hParent = m_ctlSites.GetParentItem(hParent);
}
if (hNext != NULL && hParent == m_ctlSites.GetRootItem()) {
CSiteItem *item = (CSiteItem *) m_ctlSites.GetItemData(hSelItem);
// remove item
CreateSiteList(hSelItem);
DeleteItem(hSelItem, FALSE);
// insert it back to the right place
HTREEITEM hInsParent = m_ctlSites.GetParentItem(hNext);
HTREEITEM hNewItem = AddItem(hInsParent, item, hNext);
m_ctlSites.EnsureVisible(hNewItem);
m_ctlSites.SelectItem(hNewItem);
}
}
void CSiteManagerDlg::OnMoveUp() {
LOG0(1, "CSiteManagerDlg::OnMoveUp()");
HTREEITEM hSelItem = m_ctlSites.GetSelectedItem();
if (hSelItem == NULL) return;
HTREEITEM hParent = m_ctlSites.GetParentItem(hSelItem);
HTREEITEM hPrev = m_ctlSites.GetPrevSiblingItem(hSelItem);
if (hParent != NULL) {
CSiteItem *parent = (CSiteItem *) m_ctlSites.GetItemData(hParent);
CSiteItem *item = (CSiteItem *) m_ctlSites.GetItemData(hSelItem);
if (hPrev == NULL) {
HTREEITEM hPrevParent = m_ctlSites.GetParentItem(hParent);
if (hPrevParent != NULL) {
// remove item
CreateSiteList(hSelItem);
DeleteItem(hSelItem, FALSE);
// insert
HTREEITEM hAfterItem = m_ctlSites.GetPrevSiblingItem(hParent);
HTREEITEM hNewItem;
if (hAfterItem == NULL)
hNewItem = AddItem(hPrevParent, item, TVI_FIRST);
else
hNewItem = AddItem(hPrevParent, item, hAfterItem);
m_ctlSites.EnsureVisible(hNewItem);
m_ctlSites.SelectItem(hNewItem);
}
}
else {
// remove item
CreateSiteList(hSelItem);
DeleteItem(hSelItem, FALSE);
// insert
HTREEITEM hAfterItem = m_ctlSites.GetPrevSiblingItem(hPrev);
if (hAfterItem == NULL)
hAfterItem = TVI_FIRST;
HTREEITEM hNewItem = AddItem(hParent, item, hAfterItem);
m_ctlSites.EnsureVisible(hNewItem);
m_ctlSites.SelectItem(hNewItem);
}
}
}
void CSiteManagerDlg::OnSearch() {
LOG0(1, "CSiteManagerDlg::OnSearch()");
CList<CSearchResultItem *, CSearchResultItem *> SearchResults;
CSearchDlg dlgSearch(this);
dlgSearch.SearchResults = &SearchResults;
if (dlgSearch.DoModal() == IDOK) {
// display results in dialog
CSearchResultsDlg dlgResults(this);
dlgResults.SearchResults = &SearchResults;
if (SearchResults.GetCount() > 0)
dlgResults.SetMenu(IDR_ADD);
else
dlgResults.SetMenu(IDR_CANCEL);
if (dlgResults.DoModal() == IDOK) {
HTREEITEM hParent = m_ctlSites.GetRootItem();
CSiteItem *parent = (CSiteItem *) m_ctlSites.GetItemData(hParent);
// setup the feed info for sites added
POSITION pos = SearchResults.GetHeadPosition();
while (pos != NULL) {
CSearchResultItem *sri = SearchResults.GetNext(pos);
// prepare data structures
CSiteItem *item = new CSiteItem(parent, CSiteItem::Site);
item->Status = CSiteItem::Error;
item->Name = sri->SiteName;
item->Info = new CFeedInfo();
item->Info->XmlUrl = sri->XMLURL;
item->Info->FileName = CFeedInfo::GenerateFileName(sri->XMLURL);
item->Info->TodayShow = ShowNewChannelsOnToday;
// add it to the list
AddItem(hParent, item);
}
}
// free search results
while (!SearchResults.IsEmpty())
delete SearchResults.RemoveHead();
}
}
void CSiteManagerDlg::OnImportOpml() {
LOG0(1, "CSiteManagerDlg::OnImport()");
CImportDlg dlgImport(this);
if (dlgImport.DoModal() == IDOK) {
CWaitCursor *wait = new CWaitCursor();
// load site list
COpmlFile opml;
BOOL gotOpml = FALSE;
CSiteList siteListToImport;
if (opml.LoadFromFile(dlgImport.m_strPath)) {
CSiteItem *root = new CSiteItem(NULL, CSiteItem::Group);
if (opml.Parse(root)) {
siteListToImport.CreateFrom(root);
siteListToImport.SetRoot(root);
gotOpml = TRUE;
}
else
delete root;
}
delete wait;
if (gotOpml) {
// select sites to import
CImportFeedsDlg dlgFeeds;
dlgFeeds.SiteList = &siteListToImport;
if (dlgFeeds.DoModal() == IDOK) {
CWaitCursor wait;
// append/overwrite
if (dlgFeeds.m_bAppendFeeds) {
// append
HTREEITEM hRoot = m_ctlSites.GetRootItem();
// insert new items
CSiteItem *root = siteListToImport.GetRoot();
POSITION pos = root->SubItems.GetHeadPosition();
while (pos != NULL) {
CSiteItem *si = root->SubItems.GetNext(pos);
MergeItem(hRoot, si);
}
delete root; // free root node which was not added
}
else {
// overwrite sites
// free items
CSiteItem *group = (CSiteItem *) m_ctlSites.GetItemData(m_ctlSites.GetRootItem());
group->Destroy();
delete group;
// insert new items
m_ctlSites.DeleteAllItems();
MapGroupToTreeItem.RemoveAll();
MapUrlToTreeItem.RemoveAll();
AddItem(TVI_ROOT, siteListToImport.GetRoot());
siteListToImport.Detach();
}
m_ctlSites.Expand(m_ctlSites.GetRootItem(), TVE_EXPAND);
UpdateControls();
}
}
else {
Error(IDS_ERROR_LOADING_OPML);
}
}
}
void CSiteManagerDlg::OnExportOpml() {
LOG0(1, "CSiteManagerDlg::OnExportOpml()");
CExportDlg dlg(this);
if (dlg.DoModal() == IDOK) {
CString strDestinationFileName = GetCacheFile(FILE_TYPE_OPML, dlg.m_strPath, OPML_FILENAME);
BOOL bExport = TRUE;
if (FileExists(strDestinationFileName))
bExport = PrssrMessageBox(IDS_CONFIRM_OPERATION, IDS_OVERWRITE_OPML, MB_YESNO | MB_ICONSTOP, IDS_OVERWRITE) == IDYES;
if (bExport) {
HTREEITEM hRoot = m_ctlSites.GetRootItem();
CreateSiteList(hRoot);
CSiteItem *root = (CSiteItem *) m_ctlSites.GetItemData(hRoot);
CSiteList siteListToExport;
siteListToExport.SetRoot(root);
COpmlFile opml;
if (opml.Export(strDestinationFileName, siteListToExport)) AfxMessageBox(IDS_EXPORT_OK);
else Error(IDS_CANT_EXPORT_FILE);
siteListToExport.Detach();
}
}
}
void CSiteManagerDlg::OnSyncSubscriptions() {
LOG0(1, "CSiteManagerDlg::OnSyncSubscriptions()");
if (Syncer != NULL) {
CSyncProgressDlg progress(Syncer->Downloader, this);
progress.OpenDialog(IDS_DOWNLOADING_FEED, this);
BOOL bOK = FALSE;
BOOL disconnect;
if (CheckConnection(Config.AutoConnect, disconnect)) {
CSiteList siteListToImport;
if (Syncer->GetSubscriptions(siteListToImport)) {
// append
HTREEITEM hRoot = m_ctlSites.GetRootItem();
// insert new items
CSiteItem *root = siteListToImport.GetRoot();
POSITION pos = root->SubItems.GetHeadPosition();
while (pos != NULL) {
CSiteItem *si = root->SubItems.GetNext(pos);
MergeItem(hRoot, si);
}
delete root; // free root node which was not added
m_ctlSites.Expand(m_ctlSites.GetRootItem(), TVE_EXPAND);
UpdateControls();
}
else {
// TODO: report an error
}
if (disconnect)
Connection.HangupConnection();
}
else {
// error: can not connect to the Internet
}
progress.CloseDialog();
}
}
void CSiteManagerDlg::OnUpdateSyncSubscriptions(CCmdUI *pCmdUI) {
LOG0(3, "CSiteManagerDlg::OnUpdateSyncSubscriptions()");
pCmdUI->Enable(Config.SyncSite != SYNC_SITE_NONE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -