Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

DlgNewSearch.cpp

Go to the documentation of this file.
00001 //
00002 // DlgNewSearch.cpp
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //
00021 
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Settings.h"
00025 #include "QuerySearch.h"
00026 #include "Schema.h"
00027 #include "XML.h"
00028 #include "Skin.h"
00029 #include "DlgNewSearch.h"
00030 
00031 #include "SHA.h"
00032 #include "ED2K.h"
00033 #include "TigerTree.h"
00034 
00035 #ifdef _DEBUG
00036 #define new DEBUG_NEW
00037 #undef THIS_FILE
00038 static char THIS_FILE[] = __FILE__;
00039 #endif
00040 
00041 BEGIN_MESSAGE_MAP(CNewSearchDlg, CSkinDialog)
00042         //{{AFX_MSG_MAP(CNewSearchDlg)
00043         ON_WM_SIZE()
00044         ON_WM_GETMINMAXINFO()
00045         ON_CBN_SELCHANGE(IDC_SCHEMAS, OnSelChangeSchemas)
00046         ON_CBN_CLOSEUP(IDC_SCHEMAS, OnCloseUpSchemas)
00047         ON_EN_CHANGE(IDC_SEARCH, OnChangeSearch)
00048         //}}AFX_MSG_MAP
00049 END_MESSAGE_MAP()
00050 
00051 
00053 // CNewSearchDlg dialog
00054 
00055 CNewSearchDlg::CNewSearchDlg(CWnd* pParent, CQuerySearch* pSearch, BOOL bLocal, BOOL bAgain) : CSkinDialog( CNewSearchDlg::IDD, pParent )
00056 {
00057         //{{AFX_DATA_INIT(CNewSearchDlg)
00058         //}}AFX_DATA_INIT
00059         m_pSearch       = pSearch;
00060         m_bLocal        = bLocal;
00061         m_bAgain        = bAgain;
00062 }
00063 
00064 CNewSearchDlg::~CNewSearchDlg()
00065 {
00066         if ( m_pSearch ) delete m_pSearch;
00067 }
00068 
00069 void CNewSearchDlg::DoDataExchange(CDataExchange* pDX)
00070 {
00071         CSkinDialog::DoDataExchange(pDX);
00072         //{{AFX_DATA_MAP(CNewSearchDlg)
00073         DDX_Control(pDX, IDCANCEL, m_wndCancel);
00074         DDX_Control(pDX, IDOK, m_wndOK);
00075         DDX_Control(pDX, IDC_SCHEMAS, m_wndSchemas);
00076         DDX_Control(pDX, IDC_SEARCH, m_wndSearch);
00077         //}}AFX_DATA_MAP
00078 }
00079 
00081 // CNewSearchDlg message handlers
00082 
00083 BOOL CNewSearchDlg::OnInitDialog()
00084 {
00085         CSkinDialog::OnInitDialog();
00086 
00087         SkinMe( _T("CNewSearchDlg"), IDR_SEARCHFRAME );
00088 
00089         SelectCaption( this, m_bLocal ? 2 : ( m_bAgain ? 1 : 0 ) );
00090 
00091         CRect rc;
00092         CString strText;
00093         m_wndSchema.Create( WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP, rc, this, IDC_METADATA );
00094 
00095         LoadString( strText, IDS_SEARCH_PLAIN_TEXT );
00096         m_wndSchemas.m_sNoSchemaText = strText;
00097         m_wndSchemas.Load( Settings.Search.LastSchemaURI );
00098 
00099         if ( m_pSearch != NULL )
00100         {
00101                 m_wndSchemas.Select( m_pSearch->m_pSchema );
00102         }
00103         else
00104         {
00105                 m_pSearch = new CQuerySearch();
00106         }
00107 
00108         OnSelChangeSchemas();
00109 
00110         if ( m_pSearch->m_pXML )
00111         {
00112                 m_wndSchema.UpdateData( m_pSearch->m_pXML->GetFirstElement(), FALSE );
00113         }
00114 
00115         Settings.LoadWindow( _T("NewSearch"), this );
00116 
00117         OnCloseUpSchemas();
00118 
00119         if ( m_pSearch->m_bSHA1 )
00120         {
00121                 m_wndSearch.SetWindowText( CSHA::HashToString( &m_pSearch->m_pSHA1, TRUE ) );
00122                 m_wndSchema.ShowWindow( SW_HIDE );
00123         }
00124         else
00125         {
00126                 m_wndSearch.SetWindowText( m_pSearch->m_sSearch );
00127         }
00128 
00129         if ( m_wndSchemas.GetCurSel() > 0 ) m_wndSchemas.SetFocus();
00130 
00131         return FALSE;
00132 }
00133 
00134 void CNewSearchDlg::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
00135 {
00136         CSkinDialog::OnGetMinMaxInfo( lpMMI );
00137         lpMMI->ptMinTrackSize.x = 256;
00138         lpMMI->ptMinTrackSize.y = 128;
00139 }
00140 
00141 void CNewSearchDlg::OnSize(UINT nType, int cx, int cy)
00142 {
00143         CSkinDialog::OnSize( nType, cx, cy );
00144 
00145         if ( ! IsWindow( m_wndSchema.m_hWnd ) ) return;
00146 
00147         int nSpacing    = 8;
00148         int nHeight             = 20;
00149         int nButtonSize = 72;
00150 
00151         m_wndSearch.SetWindowPos( NULL, nSpacing, nSpacing, cx - nSpacing * 2, nHeight, SWP_NOZORDER );
00152         m_wndSchemas.SetWindowPos( NULL, nSpacing, nSpacing * 2 + nHeight, cx - nSpacing * 2, nHeight, SWP_NOZORDER );
00153 
00154         if ( cy > nSpacing * 5 + nHeight * 3 + 4 )
00155         {
00156                 m_wndSchema.SetWindowPos( NULL,
00157                         nSpacing, nSpacing * 3 + nHeight * 2,
00158                         cx - nSpacing * 2, cy - nSpacing * 5 - nHeight * 3 - 4,
00159                         SWP_NOZORDER|SWP_SHOWWINDOW );
00160         }
00161         else
00162         {
00163                 m_wndSchema.ShowWindow( SW_HIDE );
00164         }
00165 
00166         nHeight += 4;
00167 
00168         m_wndOK.SetWindowPos( NULL, nSpacing - 1, cy - nSpacing - nHeight, nButtonSize, nHeight, SWP_NOZORDER );
00169         m_wndCancel.SetWindowPos( NULL, nSpacing * 2 + nButtonSize - 1, cy - nSpacing - nHeight, nButtonSize, nHeight, SWP_NOZORDER );
00170 }
00171 
00172 void CNewSearchDlg::OnSelChangeSchemas()
00173 {
00174         CSchema* pSchema = m_wndSchemas.GetSelected();
00175         m_wndSchema.SetSchema( pSchema, TRUE );
00176 }
00177 
00178 void CNewSearchDlg::OnCloseUpSchemas()
00179 {
00180         CSchema* pSchema = m_wndSchemas.GetSelected();
00181 
00182         CRect rcWindow;
00183         GetWindowRect( &rcWindow );
00184 
00185         if ( pSchema != NULL )
00186         {
00187                 if ( rcWindow.Height() <= 200 )
00188                 {
00189                         SetWindowPos( NULL, 0, 0, rcWindow.Width(), 264, SWP_NOMOVE|SWP_NOZORDER );
00190                 }
00191                 PostMessage( WM_KEYDOWN, VK_TAB );
00192         }
00193         else
00194         {
00195                 m_wndSearch.SetFocus();
00196         }
00197 }
00198 
00199 void CNewSearchDlg::OnChangeSearch()
00200 {
00201         CString strSearch;
00202         m_wndSearch.GetWindowText( strSearch );
00203 
00204         BOOL bHash = FALSE;
00205         TIGEROOT pTiger;
00206         SHA1 pSHA1;
00207         MD4 pED2K;
00208 
00209         bHash |= CSHA::HashFromURN( strSearch, &pSHA1 );
00210         bHash |= CTigerNode::HashFromURN( strSearch, &pTiger );
00211         bHash |= CED2K::HashFromURN( strSearch, &pED2K );
00212 
00213         if ( m_wndSchema.IsWindowVisible() == bHash )
00214         {
00215                 m_wndSchema.ShowWindow( bHash ? SW_HIDE : SW_SHOW );
00216         }
00217 }
00218 
00219 BOOL CNewSearchDlg::PreTranslateMessage(MSG* pMsg)
00220 {
00221         if ( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_TAB )
00222         {
00223                 CWnd* pFocus = GetFocus();
00224                 if ( m_wndSchema.OnTab() ) return TRUE;
00225         }
00226 
00227         return CSkinDialog::PreTranslateMessage( pMsg );
00228 }
00229 
00230 void CNewSearchDlg::OnOK()
00231 {
00232         Settings.SaveWindow( _T("NewSearch"), this );
00233 
00234         m_wndSearch.GetWindowText( m_pSearch->m_sSearch );
00235 
00236         CSchema* pSchema = m_wndSchemas.GetSelected();
00237 
00238         if ( m_pSearch->m_pXML != NULL ) delete m_pSearch->m_pXML;
00239 
00240         m_pSearch->m_pSchema    = NULL;
00241         m_pSearch->m_pXML               = NULL;
00242 
00243         if ( pSchema != NULL )
00244         {
00245                 m_pSearch->m_pSchema    = pSchema;
00246                 m_pSearch->m_pXML               = pSchema->Instantiate();
00247 
00248                 m_wndSchema.UpdateData( m_pSearch->m_pXML->AddElement( pSchema->m_sSingular ), TRUE );
00249 
00250                 Settings.Search.LastSchemaURI = pSchema->m_sURI;
00251         }
00252         else
00253         {
00254                 Settings.Search.LastSchemaURI.Empty();
00255         }
00256 
00257         if ( ! m_pSearch->CheckValid() )
00258         {
00259                 m_wndSearch.SetFocus();
00260                 return;
00261         }
00262 
00263         CSkinDialog::OnOK();
00264 }
00265 
00266 CQuerySearch* CNewSearchDlg::GetSearch()
00267 {
00268         CQuerySearch* pSearch = m_pSearch;
00269         m_pSearch = NULL;
00270         return pSearch;
00271 }
00272 

Generated on Thu Dec 15 10:39:39 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2