home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 April / enter-2004-04.iso / files / httrack-3.30.exe / {app} / src_win / WinHTTrack / OptionTab7.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2003-02-23  |  9.4 KB  |  340 lines

  1. // OptionTab7.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Shell.h"
  6. #include "OptionTab7.h"
  7. #include "AddFilter.h"
  8.  
  9. /* basic HTTrack defs */
  10. extern "C" {
  11.   #include "htsglobal.h"
  12.   #include "htsbase.h"
  13. }
  14.  
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20.  
  21. /////////////////////////////////////////////////////////////////////////////
  22. // COptionTab7 property page
  23.  
  24. IMPLEMENT_DYNCREATE(COptionTab7, CPropertyPage)
  25.  
  26. COptionTab7::COptionTab7() : CPropertyPage(COptionTab7::IDD)
  27. {
  28.   // Patcher titre
  29.   if (LANG_T(-1)) {    // Patcher en franτais
  30.     m_psp.pszTitle=LANG(LANG_IOPT7); // titre
  31.     m_psp.dwFlags|=PSP_USETITLE;
  32.   }
  33.   m_psp.dwFlags|=PSP_HASHELP;
  34.   //
  35.     //{{AFX_DATA_INIT(COptionTab7)
  36.     m_url2 = _T("");
  37.     //}}AFX_DATA_INIT
  38. }
  39.  
  40. COptionTab7::~COptionTab7()
  41. {
  42. }
  43.  
  44. void COptionTab7::DoDataExchange(CDataExchange* pDX)
  45. {
  46.     CPropertyPage::DoDataExchange(pDX);
  47.     //{{AFX_DATA_MAP(COptionTab7)
  48.     DDX_Text(pDX, IDC_URL2, m_url2);
  49.     //}}AFX_DATA_MAP
  50. }
  51.  
  52.  
  53. BEGIN_MESSAGE_MAP(COptionTab7, CPropertyPage)
  54.     //{{AFX_MSG_MAP(COptionTab7)
  55.     ON_BN_CLICKED(IDC_ADD1, OnAdd1)
  56.     ON_BN_CLICKED(IDC_ADD2, OnAdd2)
  57.     ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
  58.     ON_BN_CLICKED(IDC_CHECK2, OnCheck2)
  59.     ON_BN_CLICKED(IDC_CHECK3, OnCheck3)
  60.     //}}AFX_MSG_MAP
  61.   ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )
  62. END_MESSAGE_MAP()
  63.  
  64. /////////////////////////////////////////////////////////////////////////////
  65. // COptionTab7 message handlers
  66.  
  67. void NewFilter(int i,char* s) {  // 0: forbid 1: accept
  68.   CAddFilter AddF;
  69.   AddF.type=i;
  70.   if (AddF.type==0)
  71.     AddF.m_addtype=LANG(LANG_B20); /*"Links following this rule will be forbidden:"*/
  72.   else
  73.     AddF.m_addtype=LANG(LANG_B21); // "Links following this rule will be accepted:";
  74.   if (AddF.DoModal()==IDOK) {
  75.     char query[2048],t[256],as[256];
  76.     char* q;
  77.  
  78.     // error
  79.     if (AddF.m_afquery.GetLength() >= sizeof(query) - 2 ) {
  80.       return;
  81.     }
  82.  
  83.     strcpybuff(s,"");
  84.     strcpybuff(query,AddF.m_afquery);
  85.     q=query;
  86.     
  87.     if (AddF.m_aftype==10) {
  88.       if (i==0)
  89.         strcpybuff(s,"-");
  90.       else
  91.         strcpybuff(s,"+");
  92.       strcatbuff(s,"*");
  93.     } else {
  94.       while(strlen(q)>0) {
  95.         while ((*q==' ') || (*q==',')) q++;
  96.         strcpybuff(t,"");
  97.         {  // prochain (sΘparΘ par des ,)
  98.           char *a,*b;
  99.           a=strchr(q,' ');
  100.           b=strchr(q,',');
  101.           if (a && b) {  // dΘpartager
  102.             if ((int) b < (int) a)
  103.               a=b;
  104.           } else if (b) a=b;
  105.           
  106.           if (a) {
  107.             strcpybuff (t,"");
  108.             strncat(t,q,(int) a-(int) q);
  109.             q=a+1;
  110.           } else {
  111.             strcpybuff(t,q);
  112.             strcpybuff(q,"");
  113.           }
  114.         }
  115.         
  116.         if (strlen(t)>0) {
  117.           strcpybuff(as,"");
  118.           switch (AddF.m_aftype) {
  119.           case 0:  // ext
  120.             sprintf(as,"*.%s",t);
  121.             break;
  122.           case 1:  // contient
  123.             sprintf(as,"*/*%s*",t);
  124.             break;
  125.           case 2:  // this one
  126.             sprintf(as,"*/%s",t);
  127.             break;
  128.           case 3:  // folder contains
  129.             sprintf(as,"*/*%s*/*",t);
  130.             break;
  131.           case 4:  // this folder
  132.             sprintf(as,"*/%s/*",t);
  133.             break;
  134.           case 5:  // domaine
  135.             sprintf(as,"*[name].%s/*",t);
  136.             break;
  137.           case 6:  // contien
  138.             sprintf(as,"*[name].*[name]%s*[name].*[name]/*",t);
  139.             break;
  140.           case 7:  // host
  141.             sprintf(as,"%s/*",t);
  142.             break;
  143.           case 8:  // link contient
  144.             sprintf(as,"*%s*",t);
  145.             break;
  146.           case 9:  // lien exact
  147.             sprintf(as,"%s",t);
  148.             break;
  149.           }
  150.           if (strlen(as)>0) {
  151.             if (i==0)
  152.               strcatbuff(s,"-");
  153.             else
  154.               strcatbuff(s,"+");
  155.             strcatbuff(s,as);
  156.             strcatbuff(s,"\x0d\x0a");
  157.           }
  158.         }
  159.       }
  160.       
  161.     }
  162.  
  163.   } else strcpybuff(s,"");
  164. }
  165.  
  166.  
  167. void COptionTab7::OnAdd1() 
  168. {
  169.   char s[1024]; s[0]='\0';
  170.   NewFilter(0,s);
  171.   if (strlen(s)>0) {
  172.     char tempo[HTS_URLMAXSIZE*16];
  173.     {
  174.       CString st;
  175.       GetDlgItemText(IDC_URL2,st);
  176.       if (st.GetLength() < sizeof(tempo) - 2)
  177.         strcpybuff(tempo,st);
  178.       else
  179.         tempo[0] = '\0';
  180.     }
  181.     if (strlen(tempo)>0) {
  182.       if ((tempo[strlen(tempo)-1]!=' ') && (tempo[strlen(tempo)-1]!='\n') && (tempo[strlen(tempo)-1]!=13))
  183.         strcatbuff(tempo,"\x0d\x0a");
  184.     }
  185.     strcatbuff(tempo,s);
  186.     //    m_url2=tempo;
  187.     SetDlgItemText(IDC_URL2,tempo);
  188.   }
  189. }
  190.  
  191. void COptionTab7::OnAdd2() 
  192. {
  193.   char s[1024]; s[0]='\0';
  194.   NewFilter(1,s);
  195.   if (strlen(s)>0) {
  196.     char tempo[HTS_URLMAXSIZE*16];
  197.     {
  198.       CString st;
  199.       GetDlgItemText(IDC_URL2,st);
  200.       if (st.GetLength() < sizeof(tempo) - 2)
  201.         strcpybuff(tempo,st);
  202.       else
  203.         tempo[0] = '\0';
  204.     }
  205.     if (strlen(tempo)>0) {
  206.       if ((tempo[strlen(tempo)-1]!=' ') && (tempo[strlen(tempo)-1]!='\n') && (tempo[strlen(tempo)-1]!=13))
  207.         strcatbuff(tempo,"\x0d\x0a");
  208.     }
  209.     strcatbuff(tempo,s);
  210.     //    m_url2=tempo;
  211.     SetDlgItemText(IDC_URL2,tempo);
  212.   }
  213. }
  214.  
  215. BOOL COptionTab7::OnInitDialog() 
  216. {
  217.     CPropertyPage::OnInitDialog();
  218.   EnableToolTips(true);     // TOOL TIPS
  219.  
  220.   // mode modif α la volΘe
  221.   if (modify==1) {
  222.     GetDlgItem(IDC_ADD1) ->ModifyStyle(0,WS_DISABLED);
  223.     GetDlgItem(IDC_ADD2) ->ModifyStyle(0,WS_DISABLED);
  224.     GetDlgItem(IDC_URL2) ->ModifyStyle(0,WS_DISABLED);
  225.     GetDlgItem(IDC_STATIC_finfo) ->ModifyStyle(0,WS_DISABLED);
  226.     GetDlgItem(IDC_STATIC_tip) ->ModifyStyle(0,WS_DISABLED);
  227.   } else {
  228.     GetDlgItem(IDC_ADD1) ->ModifyStyle(WS_DISABLED,0);
  229.     GetDlgItem(IDC_ADD2) ->ModifyStyle(WS_DISABLED,0);
  230.     GetDlgItem(IDC_URL2) ->ModifyStyle(WS_DISABLED,0);
  231.     GetDlgItem(IDC_STATIC_finfo) ->ModifyStyle(WS_DISABLED,0);
  232.     GetDlgItem(IDC_STATIC_tip) ->ModifyStyle(WS_DISABLED,0);
  233.   }
  234.  
  235.   // Patcher l'interface pour les Franτais ;-)
  236.   if (LANG_T(-1)) {    // Patcher en franτais
  237.     SetWindowText(LANG(LANG_B9)); // "Filtres");
  238.     SetDlgItemText(IDC_STATIC_finfo,LANG(LANG_B10)); // "Vous pouvez exclure ou accepter plusieurs URLs ou liens, en utilisant les jokers\nVous pouvez utiliser les virgules ou les espaces entre les filtres\nExemple: +*.zip,-www.*.com,-www.*.edu/cgi-bin/*.cgi");
  239.     SetDlgItemText(IDC_ADD1,LANG(LANG_B11)); // "Exclure lien(s)..");
  240.     SetDlgItemText(IDC_ADD2,LANG(LANG_B12)); // "Accepter lien(s)..");
  241.     SetDlgItemText(IDC_STATIC_tip,LANG(LANG_B13)); // "Conseil: Si vous voulez accepter tous les fichiers gif d'un site, utilisez quelque chose comme +www.monweb.com/*.gif\n(+*.gif autorisera TOUS les fichiers gif sur TOUS les sites)");
  242.   }
  243.  
  244.     return TRUE;  // return TRUE unless you set the focus to a control
  245.                   // EXCEPTION: OCX Property Pages should return FALSE
  246. }
  247.  
  248.  
  249.  
  250. // ------------------------------------------------------------
  251. // TOOL TIPS
  252. //
  253. // ajouter dans le .cpp:
  254. // remplacer les deux Wid1:: par le nom de la classe::
  255. // dans la message map, ajouter
  256. // ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )
  257. // dans initdialog ajouter
  258. // EnableToolTips(true);     // TOOL TIPS
  259. //
  260. // ajouter dans le .h:
  261. // char* GetTip(int id);
  262. // et en generated message map
  263. // afx_msg BOOL OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult );
  264. BOOL COptionTab7::OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
  265. {
  266.   TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
  267.   UINT nID =pNMHDR->idFrom;
  268.   if (pTTT->uFlags & TTF_IDISHWND)
  269.   {
  270.     // idFrom is actually the HWND of the tool
  271.     nID = ::GetDlgCtrlID((HWND)nID);
  272.     if(nID)
  273.     {
  274.       char* st=GetTip(nID);
  275.       if (st != "") {
  276.         pTTT->lpszText = st;
  277.         pTTT->hinst = AfxGetResourceHandle();
  278.         return(TRUE);
  279.       }
  280.     }
  281.   }
  282.   return(FALSE);
  283. }
  284. char* COptionTab7::GetTip(int ID)
  285. {
  286.   switch(ID) {
  287.     case IDC_ADD1: return LANG(LANG_C1);   /*"Add refuse filter"*/ break;
  288.     case IDC_ADD2: return LANG(LANG_C2);   /*"Add accept filter"*/ break;
  289.     case IDC_URL2: return LANG(LANG_C3);   /*"Extra filters"*/ break;
  290.   }
  291.   return "";
  292. }
  293. // TOOL TIPS
  294. // ------------------------------------------------------------
  295.  
  296. void COptionTab7::EnsureIncluded(BOOL state, CString filter)  {
  297.   /* wipe all selected filters */
  298.   CString st;
  299.   CString ftok=filter;
  300.   GetDlgItemText(IDC_URL2,st);
  301.   ftok+=" ";
  302.   while(ftok.Find(' ')>=0) {
  303.     CString token=ftok.Mid(0,ftok.Find(' '));
  304.     ftok=ftok.Mid(ftok.Find(' ')+1);
  305.     ftok.TrimLeft();
  306.     st.Replace(token,"");
  307.     st.Replace("\r"," ");
  308.     st.Replace("\t"," ");
  309.     st.Replace("  "," ");
  310.     st.Replace(" \n","\n");
  311.     st.Replace("\n ","\n");
  312.     st.Replace("\n\n","\n");
  313.   }
  314.   st.TrimLeft();
  315.   st.TrimRight();
  316.   /* add ? */
  317.   if (state) {
  318.     st+="\n";
  319.     st+=filter;
  320.   }
  321.   st.Replace("\n","\r\n");      // W32 compatible
  322.   SetDlgItemText(IDC_URL2,st);
  323. }
  324.  
  325.  
  326. void COptionTab7::OnCheck1() 
  327. {
  328.   EnsureIncluded(this->IsDlgButtonChecked(IDC_CHECK1),"+*.gif +*.jpg +*.png +*.tif +*.bmp");
  329. }
  330.  
  331. void COptionTab7::OnCheck2() 
  332. {
  333.   EnsureIncluded(this->IsDlgButtonChecked(IDC_CHECK2),"+*.zip +*.tar +*.tgz +*.gz +*.rar +*.z +*.exe");
  334. }
  335.  
  336. void COptionTab7::OnCheck3() 
  337. {
  338.   EnsureIncluded(this->IsDlgButtonChecked(IDC_CHECK3),"+*.mov +*.mpg +*.mpeg +*.avi +*.asf +*.mp3 +*.mp2 +*.rm +*.wav +*.vob +*.qt +*.vid +*.ac3 +*.wma +*.wmv");
  339. }
  340.