home *** CD-ROM | disk | FTP | other *** search
/ Practical Internet 2002 February / Practical Internet February 2002.iso / pc / Software / Browsing / httrack-3.09e2.exe / {app} / src_win / WinHTTrack / OptionTab7.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-30  |  7.7 KB  |  278 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. #include "htsglobal.h"
  11.  
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // COptionTab7 property page
  20.  
  21. IMPLEMENT_DYNCREATE(COptionTab7, CPropertyPage)
  22.  
  23. COptionTab7::COptionTab7() : CPropertyPage(COptionTab7::IDD)
  24. {
  25.   // Patcher titre
  26.   if (LANG_T(-1)) {    // Patcher en franτais
  27.     m_psp.pszTitle=LANG(LANG_IOPT7); // titre
  28.     m_psp.dwFlags|=PSP_USETITLE;
  29.   }
  30.   m_psp.dwFlags|=PSP_HASHELP;
  31.   //
  32.     //{{AFX_DATA_INIT(COptionTab7)
  33.     m_url2 = _T("");
  34.     //}}AFX_DATA_INIT
  35. }
  36.  
  37. COptionTab7::~COptionTab7()
  38. {
  39. }
  40.  
  41. void COptionTab7::DoDataExchange(CDataExchange* pDX)
  42. {
  43.     CPropertyPage::DoDataExchange(pDX);
  44.     //{{AFX_DATA_MAP(COptionTab7)
  45.     DDX_Text(pDX, IDC_URL2, m_url2);
  46.     //}}AFX_DATA_MAP
  47. }
  48.  
  49.  
  50. BEGIN_MESSAGE_MAP(COptionTab7, CPropertyPage)
  51.     //{{AFX_MSG_MAP(COptionTab7)
  52.     ON_BN_CLICKED(IDC_ADD1, OnAdd1)
  53.     ON_BN_CLICKED(IDC_ADD2, OnAdd2)
  54.     //}}AFX_MSG_MAP
  55.   ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )
  56. END_MESSAGE_MAP()
  57.  
  58. /////////////////////////////////////////////////////////////////////////////
  59. // COptionTab7 message handlers
  60.  
  61. void NewFilter(int i,char* s) {  // 0: forbid 1: accept
  62.   CAddFilter AddF;
  63.   AddF.type=i;
  64.   if (AddF.type==0)
  65.     AddF.m_addtype=LANG(LANG_B20); /*"Links following this rule will be forbidden:"*/
  66.   else
  67.     AddF.m_addtype=LANG(LANG_B21); // "Links following this rule will be accepted:";
  68.   if (AddF.DoModal()==IDOK) {
  69.     char query[256],t[256],as[256];
  70.     char* q;
  71.     strcpy(s,"");
  72.     strcpy(query,AddF.m_afquery);
  73.     q=query;
  74.     
  75.     if (AddF.m_aftype==10) {
  76.       if (i==0)
  77.         strcpy(s,"-");
  78.       else
  79.         strcpy(s,"+");
  80.       strcat(s,"*");
  81.     } else {
  82.       while(strlen(q)>0) {
  83.         while ((*q==' ') || (*q==',')) q++;
  84.         strcpy(t,"");
  85.         {  // prochain (sΘparΘ par des ,)
  86.           char *a,*b;
  87.           a=strchr(q,' ');
  88.           b=strchr(q,',');
  89.           if (a && b) {  // dΘpartager
  90.             if ((int) b < (int) a)
  91.               a=b;
  92.           } else if (b) a=b;
  93.           
  94.           if (a) {
  95.             strcpy (t,"");
  96.             strncat(t,q,(int) a-(int) q);
  97.             q=a+1;
  98.           } else {
  99.             strcpy(t,q);
  100.             strcpy(q,"");
  101.           }
  102.         }
  103.         
  104.         if (strlen(t)>0) {
  105.           strcpy(as,"");
  106.           switch (AddF.m_aftype) {
  107.           case 0:  // ext
  108.             sprintf(as,"*.%s",t);
  109.             break;
  110.           case 1:  // contient
  111.             sprintf(as,"*/*%s*",t);
  112.             break;
  113.           case 2:  // this one
  114.             sprintf(as,"*/%s",t);
  115.             break;
  116.           case 3:  // folder contains
  117.             sprintf(as,"*/*%s*/*",t);
  118.             break;
  119.           case 4:  // this folder
  120.             sprintf(as,"*/%s/*",t);
  121.             break;
  122.           case 5:  // domaine
  123.             sprintf(as,"*[name].%s/*",t);
  124.             break;
  125.           case 6:  // contien
  126.             sprintf(as,"*[name].*[name]%s*[name].*[name]/*",t);
  127.             break;
  128.           case 7:  // host
  129.             sprintf(as,"%s/*",t);
  130.             break;
  131.           case 8:  // link contient
  132.             sprintf(as,"*%s*",t);
  133.             break;
  134.           case 9:  // lien exact
  135.             sprintf(as,"%s",t);
  136.             break;
  137.           }
  138.           if (strlen(as)>0) {
  139.             if (i==0)
  140.               strcat(s,"-");
  141.             else
  142.               strcat(s,"+");
  143.             strcat(s,as);
  144.             strcat(s,"\x0d\x0a");
  145.           }
  146.         }
  147.       }
  148.       
  149.     }
  150.  
  151.   } else strcpy(s,"");
  152. }
  153.  
  154.  
  155. void COptionTab7::OnAdd1() 
  156. {
  157.   char s[256]; s[0]='\0';
  158.   NewFilter(0,s);
  159.   if (strlen(s)>0) {
  160.     char tempo[HTS_URLMAXSIZE*4];
  161.     {
  162.       CString st;
  163.       GetDlgItemText(IDC_URL2,st);
  164.       strcpy(tempo,st);
  165.     }
  166.     if (strlen(tempo)>0) {
  167.       if ((tempo[strlen(tempo)-1]!=' ') && (tempo[strlen(tempo)-1]!='\n') && (tempo[strlen(tempo)-1]!=13))
  168.         strcat(tempo,"\x0d\x0a");
  169.     }
  170.     strcat(tempo,s);
  171.     //    m_url2=tempo;
  172.     SetDlgItemText(IDC_URL2,tempo);
  173.   }
  174. }
  175.  
  176. void COptionTab7::OnAdd2() 
  177. {
  178.   char s[256]; s[0]='\0';
  179.   NewFilter(1,s);
  180.   if (strlen(s)>0) {
  181.     char tempo[HTS_URLMAXSIZE*2];
  182.     {
  183.       CString st;
  184.       GetDlgItemText(IDC_URL2,st);
  185.       strcpy(tempo,st);
  186.     }
  187.     if (strlen(tempo)>0) {
  188.       if ((tempo[strlen(tempo)-1]!=' ') && (tempo[strlen(tempo)-1]!='\n') && (tempo[strlen(tempo)-1]!=13))
  189.         strcat(tempo,"\x0d\x0a");
  190.     }
  191.     strcat(tempo,s);
  192.     //    m_url2=tempo;
  193.     SetDlgItemText(IDC_URL2,tempo);
  194.   }
  195. }
  196.  
  197. BOOL COptionTab7::OnInitDialog() 
  198. {
  199.     CPropertyPage::OnInitDialog();
  200.   EnableToolTips(true);     // TOOL TIPS
  201.  
  202.   // mode modif α la volΘe
  203.   if (modify==1) {
  204.     GetDlgItem(IDC_ADD1) ->ModifyStyle(0,WS_DISABLED);
  205.     GetDlgItem(IDC_ADD2) ->ModifyStyle(0,WS_DISABLED);
  206.     GetDlgItem(IDC_URL2) ->ModifyStyle(0,WS_DISABLED);
  207.     GetDlgItem(IDC_STATIC_finfo) ->ModifyStyle(0,WS_DISABLED);
  208.     GetDlgItem(IDC_STATIC_tip) ->ModifyStyle(0,WS_DISABLED);
  209.   } else {
  210.     GetDlgItem(IDC_ADD1) ->ModifyStyle(WS_DISABLED,0);
  211.     GetDlgItem(IDC_ADD2) ->ModifyStyle(WS_DISABLED,0);
  212.     GetDlgItem(IDC_URL2) ->ModifyStyle(WS_DISABLED,0);
  213.     GetDlgItem(IDC_STATIC_finfo) ->ModifyStyle(WS_DISABLED,0);
  214.     GetDlgItem(IDC_STATIC_tip) ->ModifyStyle(WS_DISABLED,0);
  215.   }
  216.  
  217.   // Patcher l'interface pour les Franτais ;-)
  218.   if (LANG_T(-1)) {    // Patcher en franτais
  219.     SetWindowText(LANG(LANG_B9)); // "Filtres");
  220.     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");
  221.     SetDlgItemText(IDC_ADD1,LANG(LANG_B11)); // "Exclure lien(s)..");
  222.     SetDlgItemText(IDC_ADD2,LANG(LANG_B12)); // "Accepter lien(s)..");
  223.     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)");
  224.   }
  225.  
  226.     return TRUE;  // return TRUE unless you set the focus to a control
  227.                   // EXCEPTION: OCX Property Pages should return FALSE
  228. }
  229.  
  230.  
  231.  
  232. // ------------------------------------------------------------
  233. // TOOL TIPS
  234. //
  235. // ajouter dans le .cpp:
  236. // remplacer les deux Wid1:: par le nom de la classe::
  237. // dans la message map, ajouter
  238. // ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )
  239. // dans initdialog ajouter
  240. // EnableToolTips(true);     // TOOL TIPS
  241. //
  242. // ajouter dans le .h:
  243. // char* GetTip(int id);
  244. // et en generated message map
  245. // afx_msg BOOL OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult );
  246. BOOL COptionTab7::OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
  247. {
  248.   TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
  249.   UINT nID =pNMHDR->idFrom;
  250.   if (pTTT->uFlags & TTF_IDISHWND)
  251.   {
  252.     // idFrom is actually the HWND of the tool
  253.     nID = ::GetDlgCtrlID((HWND)nID);
  254.     if(nID)
  255.     {
  256.       char* st=GetTip(nID);
  257.       if (st != "") {
  258.         pTTT->lpszText = st;
  259.         pTTT->hinst = AfxGetResourceHandle();
  260.         return(TRUE);
  261.       }
  262.     }
  263.   }
  264.   return(FALSE);
  265. }
  266. char* COptionTab7::GetTip(int ID)
  267. {
  268.   switch(ID) {
  269.     case IDC_ADD1: return LANG(LANG_C1);   /*"Add refuse filter"*/ break;
  270.     case IDC_ADD2: return LANG(LANG_C2);   /*"Add accept filter"*/ break;
  271.     case IDC_URL2: return LANG(LANG_C3);   /*"Extra filters"*/ break;
  272.   }
  273.   return "";
  274. }
  275. // TOOL TIPS
  276. // ------------------------------------------------------------
  277.  
  278.