00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "Downloads_Opinions.h"
00009 #include "vmsMaliciousDownloadChecker.h"
00010 #include <mshtml.h>
00011
00012 #ifdef _DEBUG
00013 #define new DEBUG_NEW
00014 #undef THIS_FILE
00015 static char THIS_FILE[] = __FILE__;
00016 #endif
00017
00018 #define WM_OPINIONS_UPDATECONTENT (WM_APP+1)
00019
00020 CDownloads_Opinions::CDownloads_Opinions()
00021 {
00022 m_wbEventRcvr.m_pwndOpinions = this;
00023 m_enCS = DOCS_UNKNOWN;
00024 m_cSetAsCurrentTabAfterLoadComplete = 0;
00025 }
00026
00027 CDownloads_Opinions::~CDownloads_Opinions()
00028 {
00029 }
00030
00031 BEGIN_MESSAGE_MAP(CDownloads_Opinions, CWnd)
00032
00033 ON_WM_CREATE()
00034 ON_WM_SIZE()
00035
00036 ON_MESSAGE (WM_OPINIONS_UPDATECONTENT, OnUpdateContent)
00037 END_MESSAGE_MAP()
00038
00039 void CDownloads_Opinions::Set_ActiveDownload(vmsDownloadSmartPtr dld)
00040 {
00041 if (dld != m_dld)
00042 {
00043 m_dld = dld;
00044 m_enCS = DOCS_UNKNOWN;
00045 if (IsWindowVisible ())
00046 UpdateContent ();
00047 }
00048 }
00049
00050 bool CDownloads_Opinions::Create(CWnd *pwndParent)
00051 {
00052 CRect rc (0, 0, 50, 50);
00053
00054 if (FALSE == CWnd::Create (AfxRegisterWndClass (0, LoadCursor (NULL, IDC_ARROW), (HBRUSH) (COLOR_WINDOW+1), NULL) ,
00055 NULL, WS_CHILD | WS_VISIBLE, rc, pwndParent, 0x19821))
00056 return false;
00057
00058 return true;
00059 }
00060
00061 int CDownloads_Opinions::OnCreate(LPCREATESTRUCT lpCreateStruct)
00062 {
00063 if (CWnd::OnCreate(lpCreateStruct) == -1)
00064 return -1;
00065
00066 CRect rc (0, 0, 50, 50);
00067 m_wb.Create (NULL, WS_CHILD|WS_VISIBLE, rc, this, 0);
00068
00069 m_wbEventRcvr.Attach ();
00070
00071 UpdateContent ();
00072
00073 return 0;
00074 }
00075
00076 void CDownloads_Opinions::OnSize(UINT nType, int cx, int cy)
00077 {
00078 CWnd::OnSize(nType, cx, cy);
00079 m_wb.MoveWindow (0, 0, cx, cy);
00080 }
00081
00082 void CDownloads_Opinions::UpdateContent(bool bSetAsCurrentTabAfterLoadComplete)
00083 {
00084 if (bSetAsCurrentTabAfterLoadComplete)
00085 InterlockedIncrement (&m_cSetAsCurrentTabAfterLoadComplete);
00086 PostMessage (WM_OPINIONS_UPDATECONTENT);
00087 }
00088
00089 BOOL CDownloads_Opinions::PreTranslateMessage(MSG* pMsg)
00090 {
00091 HACCEL hAccel = ((CFrameWnd*)AfxGetApp ()->m_pMainWnd)->GetDefaultAccelerator();
00092 if (hAccel != NULL && ::TranslateAccelerator(AfxGetApp ()->m_pMainWnd->m_hWnd, hAccel, pMsg))
00093 return TRUE;
00094
00095 if (IsDialogMessage (pMsg))
00096 return TRUE;
00097
00098 return CWnd::PreTranslateMessage(pMsg);
00099 }
00100
00101 LRESULT CDownloads_Opinions::OnUpdateContent(WPARAM, LPARAM)
00102 {
00103 try{
00104
00105 if (m_dld == NULL)
00106 {
00107 if (m_enCS != DOCS_BLANK)
00108 {
00109
00110 m_enCS = DOCS_BLANK;
00111 m_wb.Navigate ("about:blank", NULL, NULL, NULL, NULL);
00112 }
00113 }
00114 else
00115 {
00116 bool bShowOpinions = false;
00117 if (m_dld->pMgr->IsDownloading () &&
00118 _App.Community_DisplayOpinionsAtDlding ())
00119 {
00120
00121
00122 if (m_dld->dwFlags & (DLD_HASOPINIONS_YES | DLD_HASOPINIONS_NO))
00123 bShowOpinions = (m_dld->dwFlags & DLD_HASOPINIONS_YES) != 0;
00124 else
00125 _pwndDownloads->CheckDldHasOpinions (m_dld);
00126 }
00127
00128 if (bShowOpinions == false)
00129 {
00130 m_enCS = DOCS_OPINION;
00131 m_wb.Navigate ("http://fdm.freedownloadmanager.org/fromfdm/opinion.html", NULL, NULL, NULL, NULL);
00132 }
00133 else
00134 {
00135
00136 if (m_enCS != DOCS_OPINIONS)
00137 {
00138 m_enCS = DOCS_OPINIONS;
00139 CString str;
00140 CString strUrl;
00141 if (m_dld->pMgr->IsBittorrent ())
00142 strUrl = m_dld->pMgr->GetBtDownloadMgr ()->get_InfoHash ();
00143 else
00144 strUrl = vmsMaliciousDownloadChecker::EncodeUrl (m_dld->pMgr->get_URL ());
00145 str.Format ("http://fdm.freedownloadmanager.org/fromfdm/showopinions.html?url=%s", strUrl);
00146 m_wb.Navigate (str, NULL, NULL, NULL, NULL);
00147 }
00148 }
00149 }
00150
00151 }catch (...) {}
00152
00153 return 0;
00154 }