📄 wxcasframe.cpp
字号:
/////////////////////////////////////////////////////////////////////////////////// Name: wxCasFrame Class////// Purpose: wxCas main frame////// Author: ThePolish <thepolish@vipmail.ru>////// Copyright (C) 2004 by ThePolish////// Derived from CAS by Pedro de Oliveira <falso@rdk.homeip.net>////// Pixmats from aMule http://www.amule.org////// This program is free software; you can redistribute it and/or modify/// it under the terms of the GNU General Public License as published by/// the Free Software Foundation; either version 2 of the License, or/// (at your option) any later version.////// This program is distributed in the hope that it will be useful,/// but WITHOUT ANY WARRANTY; without even the implied warranty of/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the/// GNU General Public License for more details.////// You should have received a copy of the GNU General Public License/// along with this program; if not, write to the/// Free Software Foundation, Inc.,/// 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA////////////////////////////////////////////////////////////////////////////////#ifdef __BORLANDC__ #pragma hdrstop#endif// For all others, include the necessary headers#ifndef WX_PRECOMP #include "wx/wx.h"#endif#include <wx/config.h>#include <wx/datetime.h>#include <wx/filedlg.h>#include <wx/image.h>#include <wx/protocol/ftp.h>#include <wx/version.h>#include <wx/wfstream.h>#include "wxcasframe.h"#include "wxcasprint.h"#include "wxcasprefs.h"#include "wxcascte.h"#include "wxcaspix.h"// ConstructorWxCasFrame::WxCasFrame ( const wxString & title ) : wxFrame ( ( wxFrame * ) NULL, -1, title, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE ){ // Give it an icon#ifdef __WXMSW__ wxIcon icon(wxT("wxcas"));#else wxIcon icon; icon.CopyFromBitmap( WxCasPix::getPixmap( wxT( "wxcas" ) ) );#endif SetIcon ( icon ); // Prefs wxConfigBase * prefs = wxConfigBase::Get(); m_maxLineCount = 0; // Check if we have a previous DL max hit double absoluteMaxDL = ( double ) ( prefs->Read ( WxCasCte::ABSOLUTE_MAX_DL_KEY, 0L ) ) / 1024.0; // Stored in bytes wxDateTime absoluteMaxDlDate( ( time_t ) ( prefs->Read ( WxCasCte::ABSOLUTE_MAX_DL_DATE_KEY, ( long ) ( wxDateTime::Now().GetTicks() ) ) ) ); // Stored in Ticks // Add Online Sig file m_aMuleSig = new OnLineSig ( wxFileName( prefs-> Read ( WxCasCte::AMULESIG_PATH_KEY, WxCasCte::DEFAULT_AMULESIG_PATH ), WxCasCte::AMULESIG_FILENAME ), absoluteMaxDL, absoluteMaxDlDate ); //Save absolute hit if we reach it during constructing if ( m_aMuleSig->IsSessionMaxDlChanged() ) { SaveAbsoluteHits(); }#ifdef __LINUX__ // System monitoring on Linux m_sysMonitor = new LinuxMon ();#endif // Status Bar CreateStatusBar (); SetStatusText ( _( "Welcome!" ) ); // Frame Vertical sizer m_frameVBox = new wxBoxSizer ( wxVERTICAL ); // Add Main panel to frame (needed by win32 for padding sub panels) m_mainPanel = new wxPanel ( this, -1 ); // Main Panel Vertical Sizer m_mainPanelVBox = new wxBoxSizer ( wxVERTICAL ); // Main Panel static line m_staticLine = new wxStaticLine ( m_mainPanel, -1 );#ifdef __WXMSW__ m_BottomStaticLine = new wxStaticLine ( m_mainPanel, -1 );#endif // Statistics Static Vertical Box Sizer m_sigPanelSBox = new wxStaticBox ( m_mainPanel, -1, _( "aMule" ) ); m_sigPanelSBoxSizer = new wxStaticBoxSizer ( m_sigPanelSBox, wxVERTICAL ); // Hit Static Horizontal Box Sizer m_hitPanelSBox = new wxStaticBox ( m_mainPanel, -1, _( "Maximum DL rate since wxCas is running" ) ); m_hitPanelSBoxSizer = new wxStaticBoxSizer ( m_hitPanelSBox, wxHORIZONTAL ); // Hit Static Horizontal Box Sizer m_absHitPanelSBox = new wxStaticBox ( m_mainPanel, -1, _( "Absolute Maximum DL rate during wxCas previous runs" ) ); m_absHitPanelSBoxSizer = new wxStaticBoxSizer ( m_absHitPanelSBox, wxHORIZONTAL ); // Statistic labels m_statLine_1 = new wxStaticText ( m_mainPanel, -1, MakeStatLine_1() ); m_statLine_2 = new wxStaticText ( m_mainPanel, -1, MakeStatLine_2() ); m_statLine_3 = new wxStaticText ( m_mainPanel, -1, MakeStatLine_3() ); m_statLine_4 = new wxStaticText ( m_mainPanel, -1, MakeStatLine_4() ); m_statLine_5 = new wxStaticText ( m_mainPanel, -1, MakeStatLine_5() ); m_statLine_6 = new wxStaticText ( m_mainPanel, -1, MakeStatLine_6() ); m_statLine_7 = new wxStaticText ( m_mainPanel, -1, MakeStatLine_7() ); m_hitLine = new wxStaticText ( m_mainPanel, -1, MakeHitsLine_1() ); m_hitButton = new wxButton ( m_mainPanel, ID_HIT_BUTTON, wxString ( _( "Reset" ) ) ); m_absHitLine = new wxStaticText ( m_mainPanel, -1, MakeHitsLine_2() ); m_absHitButton = new wxButton ( m_mainPanel, ID_ABS_HIT_BUTTON, wxString ( _( "Reset" ) ) );#ifdef __LINUX__ // System monitoring on Linux // Monitoring Static Vertical Box Sizer m_monPanelSBox = new wxStaticBox ( m_mainPanel, -1, _( "System" ) ); m_monPanelSBoxSizer = new wxStaticBoxSizer ( m_monPanelSBox, wxVERTICAL ); m_sysLine_1 = new wxStaticText ( m_mainPanel, -1, MakeSysLine_1() ); m_sysLine_2 = new wxStaticText ( m_mainPanel, -1, MakeSysLine_2() );#endif // Statistic Panel Layout m_sigPanelSBoxSizer->Add ( m_statLine_1, 0, wxALL | wxALIGN_CENTER | wxGROW, 5 ); m_sigPanelSBoxSizer->Add ( m_statLine_2, 0, wxALL | wxALIGN_CENTER | wxGROW, 5 ); m_sigPanelSBoxSizer->Add ( m_statLine_3, 0, wxALL | wxALIGN_CENTER | wxGROW, 5 ); m_sigPanelSBoxSizer->Add ( m_statLine_4, 0, wxALL | wxALIGN_CENTER | wxGROW, 5 ); m_sigPanelSBoxSizer->Add ( m_statLine_5, 0, wxALL | wxALIGN_CENTER | wxGROW, 5 ); m_sigPanelSBoxSizer->Add ( m_statLine_6, 0, wxALL | wxALIGN_CENTER | wxGROW, 5 ); m_sigPanelSBoxSizer->Add ( m_statLine_7, 0, wxALL | wxALIGN_CENTER | wxGROW, 5 ); m_hitPanelSBoxSizer->Add ( m_hitLine, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxGROW, 5 ); m_hitPanelSBoxSizer->Add ( m_hitButton, 0, wxALL | wxALIGN_RIGHT, 5 ); m_absHitPanelSBoxSizer->Add ( m_absHitLine, 0, wxALL | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxGROW, 5 ); m_absHitPanelSBoxSizer->Add ( m_absHitButton, 0, wxALL | wxALIGN_RIGHT, 5 );#ifdef __LINUX__ // System monitoring on Linux m_monPanelSBoxSizer->Add ( m_sysLine_1, 0, wxALL | wxALIGN_CENTER | wxGROW, 5 ); m_monPanelSBoxSizer->Add ( m_sysLine_2, 0, wxALL | wxALIGN_CENTER | wxGROW, 5 );#endif // Main panel Layout m_mainPanelVBox->Add ( m_staticLine, 0, wxALL | wxALIGN_CENTER | wxGROW ); m_mainPanelVBox->Add ( m_sigPanelSBoxSizer, 0, wxALL | wxALIGN_CENTER | wxGROW, 10 );#ifdef __LINUX__ // System monitoring on Linux m_mainPanelVBox->Add ( m_monPanelSBoxSizer, 0, wxALL | wxALIGN_CENTER | wxGROW, 10 );#endif m_mainPanelVBox->Add ( m_hitPanelSBoxSizer, 0, wxALL | wxALIGN_CENTER | wxGROW, 10 ); m_mainPanelVBox->Add ( m_absHitPanelSBoxSizer, 0, wxALL | wxALIGN_CENTER | wxGROW, 10 );#ifdef __WXMSW__ m_mainPanelVBox->Add ( m_BottomStaticLine, 0, wxALL | wxALIGN_CENTER | wxGROW );#endif // Toolbar Pixmaps m_toolBarBitmaps[ 0 ] = WxCasPix::getPixmap( wxT( "refresh" ) ); m_toolBarBitmaps[ 1 ] = WxCasPix::getPixmap( wxT( "save" ) ); m_toolBarBitmaps[ 2 ] = WxCasPix::getPixmap( wxT( "print" ) ); m_toolBarBitmaps[ 3 ] = WxCasPix::getPixmap( wxT( "about" ) ); m_toolBarBitmaps[ 4 ] = WxCasPix::getPixmap( wxT( "stop" ) ); m_toolBarBitmaps[ 5 ] = WxCasPix::getPixmap( wxT( "prefs" ) ); // Constructing toolbar m_toolbar = new wxToolBar ( this, -1, wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL | wxTB_FLAT ); m_toolbar->SetToolBitmapSize ( wxSize ( 32, 32 ) ); m_toolbar->SetMargins ( 2, 2 ); m_toolbar->AddTool ( ID_BAR_REFRESH, wxT( "Refresh" ), m_toolBarBitmaps[ 0 ], _( "Stop Auto Refresh" ) ); m_toolbar->AddSeparator (); m_toolbar->AddTool ( ID_BAR_SAVE, wxT( "Save" ), m_toolBarBitmaps[ 1 ], _( "Save Online Statistics image" ) ); m_toolbar->AddTool ( ID_BAR_PRINT, wxT( "Print" ), m_toolBarBitmaps[ 2 ], _( "Print Online Statistics image" ) ); m_toolbar->AddTool ( ID_BAR_PREFS, wxT( "Prefs" ), m_toolBarBitmaps[ 5 ], _( "Preferences setting" ) ); m_toolbar->AddSeparator (); m_toolbar->AddTool ( ID_BAR_ABOUT, wxT( "About" ), m_toolBarBitmaps[ 3 ], _( "About wxCas" ) ); m_toolbar->Realize (); SetToolBar ( m_toolbar ); // Panel Layout m_mainPanel->SetAutoLayout( true ); m_mainPanel->SetSizer ( m_mainPanelVBox ); // Frame Layout m_frameVBox->Add ( m_mainPanel, 1, wxALL | wxGROW ); SetAutoLayout ( TRUE ); SetSizerAndFit ( m_frameVBox ); // Add refresh timer m_refresh_timer = new wxTimer ( this, ID_REFRESH_TIMER ); m_refresh_timer->Start ( 1000 * prefs->Read ( WxCasCte::REFRESH_RATE_KEY, WxCasCte::DEFAULT_REFRESH_RATE ) ); // s to ms // Add FTP update timer m_ftp_update_timer = new wxTimer ( this, ID_FTP_UPDATE_TIMER ); m_ftp_update_timer->Start ( 60000 * prefs->Read ( WxCasCte::FTP_UPDATE_RATE_KEY, WxCasCte::DEFAULT_FTP_UPDATE_RATE ) ); // min to ms}// DestructorWxCasFrame::~WxCasFrame (){ delete m_aMuleSig;#ifdef __LINUX__ // System monitoring on Linux delete m_sysMonitor;#endif}// Events tableBEGIN_EVENT_TABLE ( WxCasFrame, wxFrame )EVT_TOOL ( ID_BAR_REFRESH, WxCasFrame::OnBarRefresh )EVT_TOOL ( ID_BAR_SAVE, WxCasFrame::OnBarSave )EVT_TOOL ( ID_BAR_PRINT, WxCasFrame::OnBarPrint )EVT_TOOL ( ID_BAR_PREFS, WxCasFrame::OnBarPrefs )EVT_TOOL ( ID_BAR_ABOUT, WxCasFrame::OnBarAbout )EVT_TIMER ( ID_REFRESH_TIMER, WxCasFrame::OnRefreshTimer )EVT_TIMER ( ID_FTP_UPDATE_TIMER, WxCasFrame::OnFtpUpdateTimer )EVT_BUTTON ( ID_HIT_BUTTON, WxCasFrame::OnHitButton )EVT_BUTTON ( ID_ABS_HIT_BUTTON, WxCasFrame::OnAbsHitButton )END_EVENT_TABLE ()// Get Stat BitmapwxImage *WxCasFrame::GetStatImage () const{ wxBitmap statBitmap = WxCasPix::getPixmap( wxT( "stat" ) ); wxMemoryDC memdc; memdc.SelectObject ( statBitmap );#ifdef __WXMSW__ memdc. SetFont ( wxFont::wxFont ( 6, wxSWISS, wxNORMAL, wxBOLD ) );#else memdc. SetFont ( wxFont::wxFont ( 8, wxSWISS, wxNORMAL, wxBOLD ) );#endif memdc. SetTextForeground ( *wxWHITE ); memdc. DrawText ( m_statLine_1->GetLabel (), 25, 0 ); memdc. DrawText ( m_statLine_2->GetLabel (), 25, 17 ); memdc. DrawText ( m_statLine_3->GetLabel (), 25, 34 ); memdc. DrawText ( m_statLine_4->GetLabel (), 25, 51 ); memdc. DrawText ( m_statLine_5->GetLabel (), 25, 68 ); memdc. DrawText ( m_statLine_6->GetLabel (), 25, 85 ); memdc. DrawText ( m_statLine_7->GetLabel (), 25, 102 ); memdc. SelectObject ( wxNullBitmap ); wxImage * statImage = new wxImage ( statBitmap.ConvertToImage() ); return ( statImage );}// Refresh buttonvoidWxCasFrame::OnBarRefresh ( wxCommandEvent& WXUNUSED( event ) ){ if ( m_refresh_timer->IsRunning () ) { m_refresh_timer->Stop (); m_ftp_update_timer->Stop (); m_toolbar->DeleteTool ( ID_BAR_REFRESH ); m_toolbar->InsertTool ( 0, ID_BAR_REFRESH, wxT( "Refresh" ), m_toolBarBitmaps[ 4 ], wxNullBitmap, wxITEM_NORMAL, _( "Start Auto Refresh" ) ); m_toolbar->Realize (); SetStatusText ( _( "Auto Refresh stopped" ) ); } else { m_refresh_timer->Start (); m_ftp_update_timer->Start (); m_toolbar->DeleteTool ( ID_BAR_REFRESH ); m_toolbar->InsertTool ( 0, ID_BAR_REFRESH, wxT( "Refresh" ), m_toolBarBitmaps[ 0 ], wxNullBitmap, wxITEM_NORMAL, _( "Stop Auto Refresh" ) ); m_toolbar->Realize (); SetStatusText ( _( "Auto Refresh started" ) ); }}// Save buttonvoidWxCasFrame::OnBarSave ( wxCommandEvent& WXUNUSED( event ) ){ wxImage * statImage = GetStatImage (); wxFileDialog selectSaveFile(this, _( "Save Statistics Image" ), wxFileName::GetHomeDir (), WxCasCte::AMULESIG_IMG_NAME, wxT("PNG (*.png)|*.png|JPEG (*.jpg)|*.jpg|BMP (*.bmp)|*.bmp|"), wxFD_SAVE); selectSaveFile.ShowModal(); wxString saveFileName(selectSaveFile.GetPath()); if ( !saveFileName.empty () ) { // static list of allowed types, update if you change extensions above const wxString ext[3] = { wxT(".png"), wxT(".jpg"), wxT(".bmp") }; const wxString fileType = ext[selectSaveFile.GetFilterIndex()]; bool isValidFileType = false; for(int i=0;i<3;++i) { if(ext[i] == saveFileName.Right(4)) { isValidFileType = true; break; } } if (!isValidFileType) { saveFileName += fileType; } // wx will display a message if saving fails, file type is taken from extension statImage->SaveFile( saveFileName ); } delete statImage;}// Print buttonvoidWxCasFrame::OnBarPrint ( wxCommandEvent& WXUNUSED( event ) ){ wxPrinter printer; WxCasPrint printout ( _( "aMule Online Statistics" ) ); if ( !printer.Print ( this, &printout, TRUE ) ) { if ( wxPrinter::GetLastError () == wxPRINTER_ERROR ) { wxMessageBox ( _ ( "There was a problem printing.\nPerhaps your current printer is not set correctly?" ), _( "Printing" ), wxOK ); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -