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

WndSystem.cpp

Go to the documentation of this file.
00001 //
00002 // WndSystem.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 "WndSystem.h"
00026 #include "Neighbours.h"
00027 #include "Skin.h"
00028 
00029 #ifdef _DEBUG
00030 #define new DEBUG_NEW
00031 #undef THIS_FILE
00032 static char THIS_FILE[] = __FILE__;
00033 #endif
00034 
00035 IMPLEMENT_SERIAL(CSystemWnd, CPanelWnd, 0)
00036 
00037 BEGIN_MESSAGE_MAP(CSystemWnd, CPanelWnd)
00038         //{{AFX_MSG_MAP(CSystemWnd)
00039         ON_WM_CREATE()
00040         ON_WM_SIZE()
00041         ON_WM_CONTEXTMENU()
00042         ON_COMMAND(ID_SYSTEM_CLEAR, OnSystemClear)
00043         ON_WM_DESTROY()
00044         ON_UPDATE_COMMAND_UI(ID_SYSTEM_VERBOSE, OnUpdateSystemVerbose)
00045         ON_COMMAND(ID_SYSTEM_VERBOSE, OnSystemVerbose)
00046         ON_UPDATE_COMMAND_UI(ID_SYSTEM_TIMESTAMP, OnUpdateSystemTimestamp)
00047         ON_COMMAND(ID_SYSTEM_TIMESTAMP, OnSystemTimestamp)
00048         ON_COMMAND(ID_SYSTEM_TEST, OnSystemTest)
00049         //}}AFX_MSG_MAP
00050 END_MESSAGE_MAP()
00051 
00052 
00054 // CSystemWnd construction
00055 
00056 CSystemWnd::CSystemWnd() : CPanelWnd( TRUE, TRUE )
00057 {
00058         Create( IDR_SYSTEMFRAME );
00059 }
00060 
00061 CSystemWnd::~CSystemWnd()
00062 {
00063 }
00064 
00066 // CSystemWnd operations
00067 
00068 void CSystemWnd::Add(int nType, LPCTSTR pszText)
00069 {
00070         if ( nType == MSG_DEBUG && ! Settings.General.Debug ) return;
00071         if ( nType != MSG_SYSTEM && ! Settings.General.VerboseMode ) return;
00072 
00073         if ( Settings.General.ShowTimestamp )
00074         {
00075                 CTime pNow = CTime::GetCurrentTime();
00076                 CString strLine;
00077                 strLine.Format( _T("[%.2i:%.2i:%.2i] %s"),
00078                         pNow.GetHour(), pNow.GetMinute(), pNow.GetSecond(), pszText );
00079                 m_wndText.AddLine( nType, strLine );
00080         }
00081         else
00082         {
00083                 m_wndText.AddLine( nType, pszText );
00084         }
00085 }
00086 
00087 void CSystemWnd::Clear()
00088 {
00089         m_wndText.Clear();
00090 }
00091 
00092 void CSystemWnd::OnSkinChange()
00093 {
00094         CPanelWnd::OnSkinChange();
00095         m_wndText.Clear( FALSE );
00096         if ( Settings.Live.LoadWindowState == FALSE )
00097         {
00098                 ShowStartupText();
00099         }
00100 }
00101 
00102 void CSystemWnd::ShowStartupText()
00103 {
00104         CString strBody;
00105         Skin.LoadString( strBody, IDS_SYSTEM_MESSAGE );
00106 
00107         Replace( strBody, _T("(version)"), (LPCTSTR)theApp.m_sVersion );
00108 
00109         for ( strBody += '\n' ; strBody.GetLength() ; )
00110         {
00111                 CString strLine = strBody.SpanExcluding( _T("\r\n") );
00112                 strBody = strBody.Mid( strLine.GetLength() + 1 );
00113 
00114                 strLine.TrimLeft();
00115                 strLine.TrimRight();
00116                 if ( strLine.IsEmpty() ) continue;
00117 
00118                 if ( strLine == _T(".") ) strLine.Empty();
00119 
00120                 if ( _tcsnicmp( strLine, _T("!"), 1 ) == 0 )
00121                         m_wndText.AddLine( MSG_SYSTEM, (LPCTSTR)strLine + 1 );
00122                 else
00123                         m_wndText.AddLine( MSG_DEFAULT, strLine );
00124         }
00125 }
00126 
00128 // CSystemWnd message handlers
00129 
00130 int CSystemWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
00131 {
00132         if ( CPanelWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
00133 
00134         CRect rc;
00135         m_wndText.Create( WS_VISIBLE, rc, this, 100 );
00136 
00137         LoadState( _T("CSystemWnd"), FALSE );
00138         theApp.Message( MSG_DEBUG, _T("IsG2HubCapable() = %i"), Neighbours.IsG2HubCapable() );
00139         theApp.Message( MSG_DEBUG, _T("IsG1UltrapeerCapable() = %i"), Neighbours.IsG1UltrapeerCapable() );
00140 
00141         return 0;
00142 }
00143 
00144 void CSystemWnd::OnDestroy()
00145 {
00146         SaveState( _T("CSystemWnd") );
00147         CPanelWnd::OnDestroy();
00148 }
00149 
00150 void CSystemWnd::OnSize(UINT nType, int cx, int cy)
00151 {
00152         CPanelWnd::OnSize( nType, cx, cy );
00153         m_wndText.SetWindowPos( NULL, 0, 0, cx, cy, SWP_NOZORDER );
00154 }
00155 
00156 void CSystemWnd::OnContextMenu(CWnd* pWnd, CPoint point)
00157 {
00158         TrackPopupMenu( _T("CSystemWnd"), point );
00159 }
00160 
00161 BOOL CSystemWnd::PreTranslateMessage(MSG* pMsg)
00162 {
00163         if ( pMsg->message == WM_KEYDOWN )
00164         {
00165                 if ( pMsg->wParam == VK_PRIOR )
00166                 {
00167                         m_wndText.PostMessage( WM_VSCROLL, MAKELONG( SB_PAGEUP, 0 ), NULL );
00168                         return TRUE;
00169                 }
00170                 else if ( pMsg->wParam == VK_NEXT )
00171                 {
00172                         m_wndText.PostMessage( WM_VSCROLL, MAKELONG( SB_PAGEDOWN, 0 ), NULL );
00173                         return TRUE;
00174                 }
00175         }
00176 
00177         return CPanelWnd::PreTranslateMessage(pMsg);
00178 }
00179 
00180 void CSystemWnd::OnUpdateSystemVerbose(CCmdUI* pCmdUI)
00181 {
00182         pCmdUI->SetCheck( Settings.General.VerboseMode );
00183 }
00184 
00185 void CSystemWnd::OnSystemVerbose()
00186 {
00187         Settings.General.VerboseMode = ! Settings.General.VerboseMode;
00188 }
00189 
00190 void CSystemWnd::OnUpdateSystemTimestamp(CCmdUI* pCmdUI)
00191 {
00192         pCmdUI->SetCheck( Settings.General.ShowTimestamp );
00193 }
00194 
00195 void CSystemWnd::OnSystemTimestamp()
00196 {
00197         Settings.General.ShowTimestamp = ! Settings.General.ShowTimestamp;
00198 }
00199 
00200 void CSystemWnd::OnSystemClear()
00201 {
00202         Clear();
00203 }
00204 
00205 #include "CrawlSession.h"
00206 
00207 void CSystemWnd::OnSystemTest()
00208 {
00209         CrawlSession.m_bActive = ! CrawlSession.m_bActive;
00210 
00211         if ( CrawlSession.m_bActive )
00212         {
00213                 CrawlSession.Bootstrap();
00214         }
00215         else
00216         {
00217                 theApp.Message( MSG_SYSTEM, _T("CCrawlSession: %i hubs, %i leaves"),
00218                         CrawlSession.GetHubCount(), CrawlSession.GetLeafCount() );
00219         }
00220 }

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