| File: | rootdir/src/amuleDlg.cpp |
| Warning: | line 454, column 6 This statement is never executed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | // |
| 2 | // This file is part of the aMule Project. |
| 3 | // |
| 4 | // Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org ) |
| 5 | // Copyright (c) 2002-2011 Merkur ( devs@emule-project.net / http://www.emule-project.net ) |
| 6 | // |
| 7 | // Any parts of this program derived from the xMule, lMule or eMule project, |
| 8 | // or contributed by third-party developers are copyrighted by their |
| 9 | // respective authors. |
| 10 | // |
| 11 | // This program is free software; you can redistribute it and/or modify |
| 12 | // it under the terms of the GNU General Public License as published by |
| 13 | // the Free Software Foundation; either version 2 of the License, or |
| 14 | // (at your option) any later version. |
| 15 | // |
| 16 | // This program is distributed in the hope that it will be useful, |
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | // GNU General Public License for more details. |
| 20 | // |
| 21 | // You should have received a copy of the GNU General Public License |
| 22 | // along with this program; if not, write to the Free Software |
| 23 | // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
| 24 | // |
| 25 | |
| 26 | #include <wx/app.h> |
| 27 | |
| 28 | #include <wx/archive.h> |
| 29 | #include <wx/config.h> // Do_not_auto_remove (MacOS 10.3, wx 2.7) |
| 30 | #include <wx/confbase.h> // Do_not_auto_remove (MacOS 10.3, wx 2.7) |
| 31 | #include <wx/html/htmlwin.h> |
| 32 | #include <wx/mimetype.h> // Do_not_auto_remove (win32) |
| 33 | #include <wx/stattext.h> |
| 34 | #include <wx/stdpaths.h> |
| 35 | #include <wx/textfile.h> // Do_not_auto_remove (win32) |
| 36 | #include <wx/tokenzr.h> |
| 37 | #include <wx/wfstream.h> |
| 38 | #include <wx/zipstrm.h> |
| 39 | #include <wx/sysopt.h> |
| 40 | #include <wx/wupdlock.h> // Needed for wxWindowUpdateLocker |
| 41 | #include <wx/utils.h> // Needed for wxFindWindowAtPoint |
| 42 | |
| 43 | #include <common/EventIDs.h> |
| 44 | |
| 45 | #include "config.h" // Needed for SVNDATE, PACKAGE, VERSION |
| 46 | #include "amuleDlg.h" // Interface declarations. |
| 47 | |
| 48 | #include <common/Format.h> // Needed for CFormat |
| 49 | #include "amule.h" // Needed for theApp |
| 50 | #include "ChatWnd.h" // Needed for CChatWnd |
| 51 | #include "SourceListCtrl.h" // Needed for CSourceListCtrl |
| 52 | #include "DownloadListCtrl.h" // Needed for CDownloadListCtrl |
| 53 | #include "DownloadQueue.h" // Needed for CDownloadQueue |
| 54 | #include "KadDlg.h" // Needed for CKadDlg |
| 55 | #include "Logger.h" |
| 56 | #include "MuleTrayIcon.h" |
| 57 | #include "muuli_wdr.h" // Needed for ID_BUTTON* |
| 58 | #include "Preferences.h" // Needed for CPreferences |
| 59 | #include "PrefsUnifiedDlg.h" |
| 60 | #include "SearchDlg.h" // Needed for CSearchDlg |
| 61 | #include "Server.h" // Needed for CServer |
| 62 | #include "ServerConnect.h" // Needed for CServerConnect |
| 63 | #include "ServerWnd.h" // Needed for CServerWnd |
| 64 | #include "SharedFilesWnd.h" // Needed for CSharedFilesWnd |
| 65 | #include "SharedFilePeersListCtrl.h" // Needed for CSharedFilePeersListCtrl |
| 66 | #include "Statistics.h" // Needed for theStats |
| 67 | #include "StatisticsDlg.h" // Needed for CStatisticsDlg |
| 68 | #include "TerminationProcess.h" // Needed for CTerminationProcess |
| 69 | #include "TransferWnd.h" // Needed for CTransferWnd |
| 70 | #ifndef CLIENT_GUI |
| 71 | #include "PartFileConvertDlg.h" |
| 72 | #endif |
| 73 | #include "IPFilter.h" |
| 74 | |
| 75 | #ifndef __WINDOWS__ |
| 76 | #include "aMule.xpm" |
| 77 | #endif |
| 78 | |
| 79 | #include "kademlia/kademlia/Kademlia.h" |
| 80 | #include "MuleVersion.h" // Needed for GetMuleVersion() |
| 81 | |
| 82 | #ifdef ENABLE_IP2COUNTRY1 |
| 83 | #include "IP2Country.h" // Needed for IP2Country |
| 84 | #endif |
| 85 | |
| 86 | #ifdef ENABLE_IP2COUNTRY1 // That's no bug. MSVC has ENABLE_IP2COUNTRY always on, |
| 87 | // but dummy GeoIP.h turns ENABLE_IP2COUNTRY off again. |
| 88 | void CamuleDlg::IP2CountryDownloadFinished(uint32 result) |
| 89 | { |
| 90 | m_IP2Country->DownloadFinished(result); |
| 91 | } |
| 92 | |
| 93 | void CamuleDlg::EnableIP2Country() |
| 94 | { |
| 95 | if (thePrefs::IsGeoIPEnabled()) { |
| 96 | m_IP2Country->Enable(); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | #else |
| 101 | |
| 102 | void CamuleDlg::IP2CountryDownloadFinished(uint32){} |
| 103 | void CamuleDlg::EnableIP2Country(){} |
| 104 | |
| 105 | #endif |
| 106 | |
| 107 | BEGIN_EVENT_TABLE(CamuleDlg, wxFrame)const wxEventTable CamuleDlg::sm_eventTable = { &wxFrame:: sm_eventTable, &CamuleDlg::sm_eventTableEntries[0] }; const wxEventTable *CamuleDlg::GetEventTable() const { return & CamuleDlg::sm_eventTable; } wxEventHashTable CamuleDlg::sm_eventHashTable (CamuleDlg::sm_eventTable); wxEventHashTable &CamuleDlg:: GetEventHashTable() const { return CamuleDlg::sm_eventHashTable ; } const wxEventTableEntry CamuleDlg::sm_eventTableEntries[] = { |
| 108 | |
| 109 | EVT_TOOL(ID_BUTTONNETWORKS, CamuleDlg::OnToolBarButton)wxEventTableEntry(wxEVT_MENU, 10334, wxID_ANY, wxNewEventTableFunctor (wxEVT_MENU, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate ::EventArgOf<wxCommandEventFunction>::type>(&CamuleDlg ::OnToolBarButton))), __null), |
| 110 | EVT_TOOL(ID_BUTTONSEARCH, CamuleDlg::OnToolBarButton)wxEventTableEntry(wxEVT_MENU, 10335, wxID_ANY, wxNewEventTableFunctor (wxEVT_MENU, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate ::EventArgOf<wxCommandEventFunction>::type>(&CamuleDlg ::OnToolBarButton))), __null), |
| 111 | EVT_TOOL(ID_BUTTONDOWNLOADS, CamuleDlg::OnToolBarButton)wxEventTableEntry(wxEVT_MENU, 10336, wxID_ANY, wxNewEventTableFunctor (wxEVT_MENU, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate ::EventArgOf<wxCommandEventFunction>::type>(&CamuleDlg ::OnToolBarButton))), __null), |
| 112 | EVT_TOOL(ID_BUTTONSHARED, CamuleDlg::OnToolBarButton)wxEventTableEntry(wxEVT_MENU, 10337, wxID_ANY, wxNewEventTableFunctor (wxEVT_MENU, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate ::EventArgOf<wxCommandEventFunction>::type>(&CamuleDlg ::OnToolBarButton))), __null), |
| 113 | EVT_TOOL(ID_BUTTONMESSAGES, CamuleDlg::OnToolBarButton)wxEventTableEntry(wxEVT_MENU, 10338, wxID_ANY, wxNewEventTableFunctor (wxEVT_MENU, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate ::EventArgOf<wxCommandEventFunction>::type>(&CamuleDlg ::OnToolBarButton))), __null), |
| 114 | EVT_TOOL(ID_BUTTONSTATISTICS, CamuleDlg::OnToolBarButton)wxEventTableEntry(wxEVT_MENU, 10339, wxID_ANY, wxNewEventTableFunctor (wxEVT_MENU, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate ::EventArgOf<wxCommandEventFunction>::type>(&CamuleDlg ::OnToolBarButton))), __null), |
| 115 | EVT_TOOL(ID_ABOUT, CamuleDlg::OnAboutButton)wxEventTableEntry(wxEVT_MENU, 10342, wxID_ANY, wxNewEventTableFunctor (wxEVT_MENU, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate ::EventArgOf<wxCommandEventFunction>::type>(&CamuleDlg ::OnAboutButton))), __null), |
| 116 | |
| 117 | EVT_TOOL(ID_BUTTONNEWPREFERENCES, CamuleDlg::OnPrefButton)wxEventTableEntry(wxEVT_MENU, 10340, wxID_ANY, wxNewEventTableFunctor (wxEVT_MENU, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate ::EventArgOf<wxCommandEventFunction>::type>(&CamuleDlg ::OnPrefButton))), __null), |
| 118 | EVT_TOOL(ID_BUTTONIMPORT, CamuleDlg::OnImportButton)wxEventTableEntry(wxEVT_MENU, 10341, wxID_ANY, wxNewEventTableFunctor (wxEVT_MENU, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate ::EventArgOf<wxCommandEventFunction>::type>(&CamuleDlg ::OnImportButton))), __null), |
| 119 | |
| 120 | EVT_TOOL(ID_BUTTONCONNECT, CamuleDlg::OnBnConnect)wxEventTableEntry(wxEVT_MENU, 10333, wxID_ANY, wxNewEventTableFunctor (wxEVT_MENU, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate ::EventArgOf<wxCommandEventFunction>::type>(&CamuleDlg ::OnBnConnect))), __null), |
| 121 | |
| 122 | EVT_CLOSE(CamuleDlg::OnClose)wxEventTableEntry(wxEVT_CLOSE_WINDOW, wxID_ANY, wxID_ANY, wxNewEventTableFunctor (wxEVT_CLOSE_WINDOW, wxEventFunctionCast(wxPrivate::DoCast< wxPrivate::EventArgOf<wxCloseEventFunction>::type>(& CamuleDlg::OnClose))), __null), |
| 123 | EVT_ICONIZE(CamuleDlg::OnMinimize)wxEventTableEntry(wxEVT_ICONIZE, wxID_ANY, wxID_ANY, wxNewEventTableFunctor (wxEVT_ICONIZE, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate ::EventArgOf<wxIconizeEventFunction>::type>(&CamuleDlg ::OnMinimize))), __null), |
| 124 | |
| 125 | EVT_BUTTON(ID_BUTTON_FAST, CamuleDlg::OnBnClickedFast)wxEventTableEntry(wxEVT_BUTTON, 10000, wxID_ANY, wxNewEventTableFunctor (wxEVT_BUTTON, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate ::EventArgOf<wxCommandEventFunction>::type>(&CamuleDlg ::OnBnClickedFast))), __null), |
| 126 | |
| 127 | EVT_TIMER(ID_GUI_TIMER_EVENT, CamuleDlg::OnGUITimer)wxEventTableEntry(wxEVT_TIMER, ID_GUI_TIMER_EVENT, wxID_ANY, wxNewEventTableFunctor (wxEVT_TIMER, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate ::EventArgOf<wxTimerEventFunction>::type>(&CamuleDlg ::OnGUITimer))), __null), |
| 128 | |
| 129 | EVT_SIZE(CamuleDlg::OnMainGUISizeChange)wxEventTableEntry(wxEVT_SIZE, wxID_ANY, wxID_ANY, wxNewEventTableFunctor (wxEVT_SIZE, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate ::EventArgOf<wxSizeEventFunction>::type>(&CamuleDlg ::OnMainGUISizeChange))), __null), |
| 130 | |
| 131 | EVT_KEY_UP(CamuleDlg::OnKeyPressed)wxEventTableEntry(wxEVT_KEY_UP, wxID_ANY, wxID_ANY, wxNewEventTableFunctor (wxEVT_KEY_UP, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate ::EventArgOf<wxCharEventFunction>::type>(&CamuleDlg ::OnKeyPressed))), __null), |
| 132 | |
| 133 | EVT_MENU(wxID_EXIT, CamuleDlg::OnExit)wxEventTableEntry(wxEVT_MENU, wxID_EXIT, wxID_ANY, wxNewEventTableFunctor (wxEVT_MENU, wxEventFunctionCast(wxPrivate::DoCast<wxPrivate ::EventArgOf<wxCommandEventFunction>::type>(&CamuleDlg ::OnExit))), __null), |
| 134 | |
| 135 | END_EVENT_TABLE()wxEventTableEntry(wxEVT_NULL, 0, 0, __null, __null) }; |
| 136 | |
| 137 | #ifndef wxCLOSE_BOX0x1000 |
| 138 | #define wxCLOSE_BOX0x1000 0 |
| 139 | #endif |
| 140 | |
| 141 | CamuleDlg::CamuleDlg( |
| 142 | wxWindow* pParent, |
| 143 | const wxString &title, |
| 144 | wxPoint where, |
| 145 | wxSize dlg_size) |
| 146 | : |
| 147 | wxFrame( |
| 148 | pParent, -1, title, where, dlg_size, |
| 149 | wxCAPTION0x20000000|wxRESIZE_BORDER0x0040|wxSYSTEM_MENU0x0800|wxDIALOG_NO_PARENT0x00000020| |
| 150 | wxRESIZE_BORDER0x0040|wxMINIMIZE_BOX0x0400|wxMAXIMIZE_BOX0x0200|wxCLOSE_BOX0x1000, |
| 151 | wxT("aMule")L"aMule"), |
| 152 | m_activewnd(NULL__null), |
| 153 | m_transferwnd(NULL__null), |
| 154 | m_serverwnd(NULL__null), |
| 155 | m_sharedfileswnd(NULL__null), |
| 156 | m_searchwnd(NULL__null), |
| 157 | m_chatwnd(NULL__null), |
| 158 | m_statisticswnd(NULL__null), |
| 159 | m_kademliawnd(NULL__null), |
| 160 | m_prefsDialog(NULL__null), |
| 161 | m_srv_split_pos(0), |
| 162 | m_imagelist(16,16), |
| 163 | m_tblist(32,32), |
| 164 | m_prefsVisible(false), |
| 165 | m_wndToolbar(NULL__null), |
| 166 | m_wndTaskbarNotifier(NULL__null), |
| 167 | m_nActiveDialog(DT_NETWORKS_WND), |
| 168 | m_is_safe_state(false), |
| 169 | m_BlinkMessages(false), |
| 170 | m_CurrentBlinkBitmap(24), |
| 171 | m_last_iconizing(0), |
| 172 | m_skinFileName(), |
| 173 | m_clientSkinNames(CLIENT_SKIN_SIZE) |
| 174 | { |
| 175 | // Initialize skin names |
| 176 | m_clientSkinNames[Client_Green_Smiley] = wxT("Transfer")L"Transfer"; |
| 177 | m_clientSkinNames[Client_Red_Smiley] = wxT("Connecting")L"Connecting"; |
| 178 | m_clientSkinNames[Client_Yellow_Smiley] = wxT("OnQueue")L"OnQueue"; |
| 179 | m_clientSkinNames[Client_Grey_Smiley] = wxT("A4AFNoNeededPartsQueueFull")L"A4AFNoNeededPartsQueueFull"; |
| 180 | m_clientSkinNames[Client_White_Smiley] = wxT("StatusUnknown")L"StatusUnknown"; |
| 181 | m_clientSkinNames[Client_ExtendedProtocol_Smiley] = wxT("ExtendedProtocol")L"ExtendedProtocol"; |
| 182 | m_clientSkinNames[Client_SecIdent_Smiley] = wxT("SecIdent")L"SecIdent"; |
| 183 | m_clientSkinNames[Client_BadGuy_Smiley] = wxT("BadGuy")L"BadGuy"; |
| 184 | m_clientSkinNames[Client_CreditsGrey_Smiley] = wxT("CreditsGrey")L"CreditsGrey"; |
| 185 | m_clientSkinNames[Client_CreditsYellow_Smiley] = wxT("CreditsYellow")L"CreditsYellow"; |
| 186 | m_clientSkinNames[Client_Upload_Smiley] = wxT("Upload")L"Upload"; |
| 187 | m_clientSkinNames[Client_Friend_Smiley] = wxT("Friend")L"Friend"; |
| 188 | m_clientSkinNames[Client_eMule_Smiley] = wxT("eMule")L"eMule"; |
| 189 | m_clientSkinNames[Client_mlDonkey_Smiley] = wxT("mlDonkey")L"mlDonkey"; |
| 190 | m_clientSkinNames[Client_eDonkeyHybrid_Smiley] = wxT("eDonkeyHybrid")L"eDonkeyHybrid"; |
| 191 | m_clientSkinNames[Client_aMule_Smiley] = wxT("aMule")L"aMule"; |
| 192 | m_clientSkinNames[Client_lphant_Smiley] = wxT("lphant")L"lphant"; |
| 193 | m_clientSkinNames[Client_Shareaza_Smiley] = wxT("Shareaza")L"Shareaza"; |
| 194 | m_clientSkinNames[Client_xMule_Smiley] = wxT("xMule")L"xMule"; |
| 195 | m_clientSkinNames[Client_Unknown] = wxT("Unknown")L"Unknown"; |
| 196 | m_clientSkinNames[Client_InvalidRating_Smiley] = wxT("InvalidRatingOnFile")L"InvalidRatingOnFile"; |
| 197 | m_clientSkinNames[Client_PoorRating_Smiley] = wxT("PoorRatingOnFile")L"PoorRatingOnFile"; |
| 198 | m_clientSkinNames[Client_GoodRating_Smiley] = wxT("GoodRatingOnFile")L"GoodRatingOnFile"; |
| 199 | m_clientSkinNames[Client_FairRating_Smiley] = wxT("FairRatingOnFile")L"FairRatingOnFile"; |
| 200 | m_clientSkinNames[Client_ExcellentRating_Smiley] = wxT("ExcellentRatingOnFile")L"ExcellentRatingOnFile"; |
| 201 | m_clientSkinNames[Client_CommentOnly_Smiley] = wxT("CommentOnly")L"CommentOnly"; |
| 202 | m_clientSkinNames[Client_Encryption_Smiley] = wxT("Encrypted")L"Encrypted"; |
| 203 | |
| 204 | // wxWidgets send idle events to ALL WINDOWS by default... *SIGH* |
| 205 | wxIdleEvent::SetMode(wxIDLE_PROCESS_SPECIFIED); |
| 206 | wxUpdateUIEvent::SetMode(wxUPDATE_UI_PROCESS_SPECIFIED); |
| 207 | wxInitAllImageHandlers(); |
| 208 | Apply_Clients_Skin(); |
| 209 | |
| 210 | #ifdef __WINDOWS__ |
| 211 | wxSystemOptions::SetOption(wxT("msw.remap")L"msw.remap", 0); |
| 212 | #endif |
| 213 | |
| 214 | #if !defined(__WXMAC__) |
| 215 | // this crashes on Mac with wx 2.9 |
| 216 | SetIcon(wxICON(aMule)wxIcon( aMule_xpm )); |
| 217 | #endif |
| 218 | |
| 219 | srand(time(NULL__null)); |
| 220 | |
| 221 | // Create new sizer and stuff a wxPanel in there. |
| 222 | wxFlexGridSizer *s_main = new wxFlexGridSizer(1); |
| 223 | s_main->AddGrowableCol(0); |
| 224 | s_main->AddGrowableRow(0); |
| 225 | |
| 226 | wxPanel* p_cnt = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize); |
| 227 | s_main->Add(p_cnt, 0, wxGROW|wxEXPAND, 0); |
| 228 | muleDlg(p_cnt, false, true); |
| 229 | SetSizer(s_main, true); |
| 230 | |
| 231 | m_serverwnd = new CServerWnd(p_cnt, m_srv_split_pos); |
| 232 | AddLogLineN(wxEmptyString)theLogger.AddLogLine(L"amuleDlg.cpp", 232, false, logStandard , wxEmptyString); |
| 233 | AddLogLineN(wxT(" - ") +theLogger.AddLogLine(L"amuleDlg.cpp", 234, false, logStandard , L" - " + CFormat(wxGetTranslation(("This is aMule %s based on eMule." ))) % GetMuleVersion()) |
| 234 | CFormat(_("This is aMule %s based on eMule.")) % GetMuleVersion())theLogger.AddLogLine(L"amuleDlg.cpp", 234, false, logStandard , L" - " + CFormat(wxGetTranslation(("This is aMule %s based on eMule." ))) % GetMuleVersion()); |
| 235 | AddLogLineN(wxT(" ") +theLogger.AddLogLine(L"amuleDlg.cpp", 236, false, logStandard , L" " + CFormat(wxGetTranslation(("Running on %s"))) % wxGetOsDescription ()) |
| 236 | CFormat(_("Running on %s")) % wxGetOsDescription())theLogger.AddLogLine(L"amuleDlg.cpp", 236, false, logStandard , L" " + CFormat(wxGetTranslation(("Running on %s"))) % wxGetOsDescription ()); |
| 237 | AddLogLineN(wxT(" - ") +theLogger.AddLogLine(L"amuleDlg.cpp", 238, false, logStandard , L" - " + wxString(wxGetTranslation(("Visit http://www.amule.org to check if a new version is available." )))) |
| 238 | wxString(_("Visit http://www.amule.org to check if a new version is available.")))theLogger.AddLogLine(L"amuleDlg.cpp", 238, false, logStandard , L" - " + wxString(wxGetTranslation(("Visit http://www.amule.org to check if a new version is available." )))); |
| 239 | AddLogLineN(wxEmptyString)theLogger.AddLogLine(L"amuleDlg.cpp", 239, false, logStandard , wxEmptyString); |
| 240 | |
| 241 | #ifdef ENABLE_IP2COUNTRY1 |
| 242 | m_GeoIPavailable = true; |
| 243 | m_IP2Country = new CIP2Country(thePrefs::GetConfigDir()); |
| 244 | #else |
| 245 | m_GeoIPavailable = false; |
| 246 | #endif |
| 247 | m_searchwnd = new CSearchDlg(p_cnt); |
| 248 | m_transferwnd = new CTransferWnd(p_cnt); |
| 249 | m_sharedfileswnd = new CSharedFilesWnd(p_cnt); |
| 250 | m_statisticswnd = new CStatisticsDlg(p_cnt, theApp->m_statistics); |
| 251 | m_chatwnd = new CChatWnd(p_cnt); |
| 252 | m_kademliawnd = CastChild(wxT("kadWnd"), CKadDlg)dynamic_cast<CKadDlg*>( FindWindow( L"kadWnd" ) ); |
| 253 | |
| 254 | m_serverwnd->Show(false); |
| 255 | m_searchwnd->Show(false); |
| 256 | m_transferwnd->Show(false); |
| 257 | m_sharedfileswnd->Show(false); |
| 258 | m_statisticswnd->Show(false); |
| 259 | m_chatwnd->Show(false); |
| 260 | |
| 261 | // Create the GUI timer |
| 262 | gui_timer=new wxTimer(this,ID_GUI_TIMER_EVENT); |
| 263 | if (!gui_timer) { |
| 264 | AddLogLineN(_("FATAL ERROR: Failed to create Timer"))theLogger.AddLogLine(L"amuleDlg.cpp", 264, false, logStandard , wxGetTranslation(("FATAL ERROR: Failed to create Timer"))); |
| 265 | exit(1); |
| 266 | } |
| 267 | |
| 268 | // Set transfers as active window |
| 269 | Create_Toolbar(thePrefs::VerticalToolbar()); |
| 270 | SetActiveDialog(DT_TRANSFER_WND, m_transferwnd); |
| 271 | m_wndToolbar->ToggleTool(ID_BUTTONDOWNLOADS10336, true ); |
| 272 | |
| 273 | bool override_where = (where != wxDefaultPosition); |
| 274 | bool override_size = ( |
| 275 | (dlg_size.x != DEFAULT_SIZE_X800) || |
| 276 | (dlg_size.y != DEFAULT_SIZE_Y600) ); |
| 277 | if (!LoadGUIPrefs(override_where, override_size)) { |
| 278 | // Prefs not loaded for some reason, exit |
| 279 | AddLogLineC(wxT("Error! Unable to load Preferences") )theLogger.AddLogLine(L"amuleDlg.cpp", 279, true, logStandard, L"Error! Unable to load Preferences"); |
| 280 | return; |
| 281 | } |
| 282 | |
| 283 | // Prepare the dialog, sets the splitter-position (AFTER window size is set) |
| 284 | m_transferwnd->Prepare(); |
| 285 | |
| 286 | m_is_safe_state = true; |
| 287 | |
| 288 | // Init statistics stuff, better do it asap |
| 289 | m_statisticswnd->Init(); |
| 290 | m_kademliawnd->Init(); |
| 291 | m_searchwnd->UpdateCatChoice(); |
| 292 | |
| 293 | if (thePrefs::UseTrayIcon()) { |
| 294 | CreateSystray(); |
| 295 | } |
| 296 | |
| 297 | Show(true); |
| 298 | // Must we start minimized? |
| 299 | if (thePrefs::GetStartMinimized()) { |
| 300 | Iconize(true); |
| 301 | } |
| 302 | |
| 303 | // Set shortcut keys |
| 304 | wxAcceleratorEntry entries[] = { |
| 305 | wxAcceleratorEntry(wxACCEL_CTRL, wxT('Q')L'Q', wxID_EXIT) |
| 306 | }; |
| 307 | |
| 308 | SetAcceleratorTable(wxAcceleratorTable(itemsof(entries)(sizeof(entries) / sizeof(entries[0])), entries)); |
| 309 | ShowED2KLinksHandler( thePrefs::GetFED2KLH() ); |
| 310 | |
| 311 | wxNotebook* logs_notebook = CastChild( ID_SRVLOG_NOTEBOOK, wxNotebook)dynamic_cast<wxNotebook*>( FindWindow( 10252 ) ); |
| 312 | wxNotebook* networks_notebook = CastChild( ID_NETNOTEBOOK, wxNotebook)dynamic_cast<wxNotebook*>( FindWindow( 10317 ) ); |
| 313 | |
| 314 | wxASSERT(logs_notebook->GetPageCount() == 4)do { if ( logs_notebook->GetPageCount() == 4 ) { } else if ( wxTheAssertHandler && (wxOnAssert("amuleDlg.cpp", 314 , __FUNCTION__, "logs_notebook->GetPageCount() == 4", (const char*)__null), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while ( (void)0, 0 ); |
| 315 | wxASSERT(networks_notebook->GetPageCount() == 2)do { if ( networks_notebook->GetPageCount() == 2 ) { } else if ( wxTheAssertHandler && (wxOnAssert("amuleDlg.cpp" , 315, __FUNCTION__, "networks_notebook->GetPageCount() == 2" , (const char*)__null), wxTrapInAssert) ) { wxTrapInAssert = false ; asm volatile ("int $3"); } } while ( (void)0, 0 ); |
| 316 | |
| 317 | for (uint32 i = 0; i < logs_notebook->GetPageCount(); ++i) { |
| 318 | m_logpages[i].page = logs_notebook->GetPage(i); |
| 319 | m_logpages[i].name = logs_notebook->GetPageText(i); |
| 320 | } |
| 321 | |
| 322 | for (uint32 i = 0; i < networks_notebook->GetPageCount(); ++i) { |
| 323 | m_networkpages[i].page = networks_notebook->GetPage(i); |
| 324 | m_networkpages[i].name = networks_notebook->GetPageText(i); |
| 325 | } |
| 326 | |
| 327 | DoNetworkRearrange(); |
| 328 | } |
| 329 | |
| 330 | |
| 331 | // Madcat - Sets Fast ED2K Links Handler on/off. |
| 332 | void CamuleDlg::ShowED2KLinksHandler( bool show ) |
| 333 | { |
| 334 | // Errorchecking in case the pointer becomes invalid ... |
| 335 | if (s_fed2klh == NULL__null) { |
| 336 | wxLogWarningfor ( bool wxdoif336 = false; !wxdoif336 && wxLog::IsLevelEnabled (wxLOG_Warning, wxString::FromAscii(wxLOG_COMPONENT)); wxdoif336 = true ) wxLogger(wxLOG_Warning, "amuleDlg.cpp", 336, __FUNCTION__ , wxLOG_COMPONENT).Log(wxT("Unable to find Fast ED2K Links handler sizer! Hiding FED2KLH aborted.")L"Unable to find Fast ED2K Links handler sizer! Hiding FED2KLH aborted."); |
| 337 | return; |
| 338 | } |
| 339 | |
| 340 | s_dlgcnt->Show( s_fed2klh, show ); |
| 341 | s_dlgcnt->Layout(); |
| 342 | } |
| 343 | |
| 344 | // Toogles ed2k link handler. |
| 345 | void CamuleDlg::ToogleED2KLinksHandler() |
| 346 | { |
| 347 | // Errorchecking in case the pointer becomes invalid ... |
| 348 | if (s_fed2klh == NULL__null) { |
| 349 | wxLogWarningfor ( bool wxdoif349 = false; !wxdoif349 && wxLog::IsLevelEnabled (wxLOG_Warning, wxString::FromAscii(wxLOG_COMPONENT)); wxdoif349 = true ) wxLogger(wxLOG_Warning, "amuleDlg.cpp", 349, __FUNCTION__ , wxLOG_COMPONENT).Log(wxT("Unable to find Fast ED2K Links handler sizer! Toogling FED2KLH aborted.")L"Unable to find Fast ED2K Links handler sizer! Toogling FED2KLH aborted."); |
| 350 | return; |
| 351 | } |
| 352 | ShowED2KLinksHandler(!s_dlgcnt->IsShown(s_fed2klh)); |
| 353 | } |
| 354 | |
| 355 | void CamuleDlg::SetActiveDialog(DialogType type, wxWindow* dlg) |
| 356 | { |
| 357 | m_nActiveDialog = type; |
| 358 | |
| 359 | if ( type == DT_TRANSFER_WND ) { |
| 360 | if (thePrefs::ShowCatTabInfos()) { |
| 361 | m_transferwnd->UpdateCatTabTitles(); |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | if ( m_activewnd ) { |
| 366 | m_activewnd->Show(false); |
| 367 | contentSizer->Detach(m_activewnd); |
| 368 | } |
| 369 | |
| 370 | contentSizer->Add(dlg, 1, wxALIGN_LEFT|wxEXPAND); |
| 371 | dlg->Show(true); |
| 372 | m_activewnd=dlg; |
| 373 | s_dlgcnt->Layout(); |
| 374 | |
| 375 | // Since we might be suspending redrawing while hiding the dialog |
| 376 | // we have to refresh it once it is visible again |
| 377 | dlg->Refresh( true ); |
| 378 | dlg->SetFocus(); |
| 379 | |
| 380 | if ( type == DT_SHARED_WND ) { |
| 381 | // set up splitter now that window sizes are defined |
| 382 | m_sharedfileswnd->Prepare(); |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | |
| 387 | void CamuleDlg::UpdateTrayIcon(int percent) |
| 388 | { |
| 389 | // set trayicon-icon |
| 390 | if(!theApp->IsConnected()) { |
| 391 | m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_DISCONNECTED, percent); |
| 392 | } else { |
| 393 | if(theApp->IsConnectedED2K() && theApp->serverconnect->IsLowID()) { |
| 394 | m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_LOWID, percent); |
| 395 | } else { |
| 396 | m_wndTaskbarNotifier->SetTrayIcon(TRAY_ICON_HIGHID, percent); |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | |
| 402 | void CamuleDlg::CreateSystray() |
| 403 | { |
| 404 | wxCHECK_RET(m_wndTaskbarNotifier == NULL,if ( m_wndTaskbarNotifier == __null ) {} else { do { if ( wxTheAssertHandler && (wxOnAssert("amuleDlg.cpp", 405, __FUNCTION__, "\"m_wndTaskbarNotifier == __null\"" , L"Systray already created"), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while ( (void)0, 0 ); return ; } struct wxDummyCheckStruct405 |
| 405 | wxT("Systray already created"))if ( m_wndTaskbarNotifier == __null ) {} else { do { if ( wxTheAssertHandler && (wxOnAssert("amuleDlg.cpp", 405, __FUNCTION__, "\"m_wndTaskbarNotifier == __null\"" , L"Systray already created"), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while ( (void)0, 0 ); return ; } struct wxDummyCheckStruct405; |
| 406 | |
| 407 | m_wndTaskbarNotifier = new CMuleTrayIcon(); |
| 408 | // This will effectively show the Tray Icon. |
| 409 | UpdateTrayIcon(0); |
| 410 | } |
| 411 | |
| 412 | |
| 413 | void CamuleDlg::RemoveSystray() |
| 414 | { |
| 415 | delete m_wndTaskbarNotifier; |
| 416 | m_wndTaskbarNotifier = NULL__null; |
| 417 | } |
| 418 | |
| 419 | |
| 420 | void CamuleDlg::OnToolBarButton(wxCommandEvent& ev) |
| 421 | { |
| 422 | static int lastbutton = ID_BUTTONDOWNLOADS10336; |
| 423 | |
| 424 | // Kry - just if the GUI is ready for it |
| 425 | if ( m_is_safe_state ) { |
| 426 | |
| 427 | // Rehide the handler if needed |
| 428 | if ( lastbutton == ID_BUTTONSEARCH10335 && !thePrefs::GetFED2KLH() ) { |
| 429 | if (ev.GetId() != ID_BUTTONSEARCH10335) { |
| 430 | ShowED2KLinksHandler( false ); |
| 431 | } else { |
| 432 | // Toogle ED2K handler. |
| 433 | ToogleED2KLinksHandler(); |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | if ( lastbutton != ev.GetId() ) { |
| 438 | switch ( ev.GetId() ) { |
| 439 | case ID_BUTTONNETWORKS10334: |
| 440 | SetActiveDialog(DT_NETWORKS_WND, m_serverwnd); |
| 441 | // Set serverlist splitter position |
| 442 | CastChild( wxT("SrvSplitterWnd"), wxSplitterWindow )dynamic_cast<wxSplitterWindow*>( FindWindow( L"SrvSplitterWnd" ) )->SetSashPosition(m_srv_split_pos, true); |
| 443 | break; |
| 444 | |
| 445 | case ID_BUTTONSEARCH10335: |
| 446 | // The search dialog should always display the handler |
| 447 | if ( !thePrefs::GetFED2KLH() ) |
| 448 | ShowED2KLinksHandler( true ); |
| 449 | |
| 450 | SetActiveDialog(DT_SEARCH_WND, m_searchwnd); |
| 451 | break; |
| 452 | |
| 453 | case ID_BUTTONDOWNLOADS10336: |
| 454 | SetActiveDialog(DT_TRANSFER_WND, m_transferwnd); |
This statement is never executed | |
| 455 | // Prepare the dialog, sets the splitter-position |
| 456 | m_transferwnd->Prepare(); |
| 457 | break; |
| 458 | |
| 459 | case ID_BUTTONSHARED10337: |
| 460 | SetActiveDialog(DT_SHARED_WND, m_sharedfileswnd); |
| 461 | break; |
| 462 | |
| 463 | case ID_BUTTONMESSAGES10338: |
| 464 | m_BlinkMessages = false; |
| 465 | SetActiveDialog(DT_CHAT_WND, m_chatwnd); |
| 466 | break; |
| 467 | |
| 468 | case ID_BUTTONSTATISTICS10339: |
| 469 | SetActiveDialog(DT_STATS_WND, m_statisticswnd); |
| 470 | break; |
| 471 | |
| 472 | // This shouldn't happen, but just in case |
| 473 | default: |
| 474 | AddLogLineC(wxT("Unknown button triggered CamuleApp::OnToolBarButton().") )theLogger.AddLogLine(L"amuleDlg.cpp", 474, true, logStandard, L"Unknown button triggered CamuleApp::OnToolBarButton()."); |
| 475 | break; |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | m_wndToolbar->ToggleTool(lastbutton, lastbutton == ev.GetId() ); |
| 480 | lastbutton = ev.GetId(); |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | |
| 485 | void CamuleDlg::OnAboutButton(wxCommandEvent& WXUNUSED(ev)) |
| 486 | { |
| 487 | wxString msg = wxT(" ")L" "; |
| 488 | #ifdef CLIENT_GUI |
| 489 | msg << _("aMule remote control ")wxGetTranslation(("aMule remote control ")) << wxT(VERSION)L"SVN"; |
| 490 | #else |
| 491 | msg << wxT("aMule ")L"aMule " << wxT(VERSION)L"SVN"; |
| 492 | #endif |
| 493 | msg << wxT(" ")L" "; |
| 494 | #ifdef SVNDATE"rev. gb8d4e39" |
| 495 | msg << _("Snapshot:")wxGetTranslation(("Snapshot:")) << wxT("\n ")L"\n " << wxT(SVNDATE)L"rev. gb8d4e39"; |
| 496 | #endif |
| 497 | msg << wxT("\n\n")L"\n\n" << _("'All-Platform' p2p client based on eMule \n\n")wxGetTranslation(("'All-Platform' p2p client based on eMule \n\n" )) << |
| 498 | _("Website: http://www.amule.org \n")wxGetTranslation(("Website: http://www.amule.org \n")) << |
| 499 | _("Forum: http://forum.amule.org \n")wxGetTranslation(("Forum: http://forum.amule.org \n")) << |
| 500 | _("FAQ: http://wiki.amule.org \n\n")wxGetTranslation(("FAQ: http://wiki.amule.org \n\n")) << |
| 501 | _("Contact: admin@amule.org (administrative issues) \n")wxGetTranslation(("Contact: admin@amule.org (administrative issues) \n" )) << |
| 502 | _("Copyright (c) 2003-2019 aMule Team \n\n")wxGetTranslation(("Copyright (c) 2003-2019 aMule Team \n\n")) << |
| 503 | _("Part of aMule is based on \n")wxGetTranslation(("Part of aMule is based on \n")) << |
| 504 | _("Kademlia: Peer-to-peer routing based on the XOR metric.\n")wxGetTranslation(("Kademlia: Peer-to-peer routing based on the XOR metric.\n" )) << |
| 505 | _(" Copyright (c) 2002-2011 Petar Maymounkov ( petar@post.harvard.edu )\n")wxGetTranslation((" Copyright (c) 2002-2011 Petar Maymounkov ( petar@post.harvard.edu )\n" )) << |
| 506 | _("http://kademlia.scs.cs.nyu.edu\n")wxGetTranslation(("http://kademlia.scs.cs.nyu.edu\n")); |
| 507 | |
| 508 | if (m_is_safe_state) { |
| 509 | wxMessageBox(msg, _("Message")wxGetTranslation(("Message")), wxOK0x00000004 | wxICON_INFORMATION0x00000800, this); |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | |
| 514 | void CamuleDlg::OnPrefButton(wxCommandEvent& WXUNUSED(ev)) |
| 515 | { |
| 516 | if (m_is_safe_state) { |
| 517 | if (m_prefsDialog == NULL__null) { |
| 518 | m_prefsDialog = new PrefsUnifiedDlg(this); |
| 519 | } |
| 520 | |
| 521 | m_prefsDialog->TransferToWindow(); |
| 522 | m_prefsDialog->Show(true); |
| 523 | m_prefsDialog->Raise(); |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | |
| 528 | void CamuleDlg::OnImportButton(wxCommandEvent& WXUNUSED(ev)) |
| 529 | { |
| 530 | #ifndef CLIENT_GUI |
| 531 | if (m_is_safe_state) { |
| 532 | CPartFileConvertDlg::ShowGUI(NULL__null); |
| 533 | } |
| 534 | #endif |
| 535 | } |
| 536 | |
| 537 | |
| 538 | CamuleDlg::~CamuleDlg() |
| 539 | { |
| 540 | theApp->amuledlg = NULL__null; |
| 541 | |
| 542 | #ifdef ENABLE_IP2COUNTRY1 |
| 543 | delete m_IP2Country; |
| 544 | #endif |
| 545 | |
| 546 | AddLogLineN(_("aMule dialog destroyed"))theLogger.AddLogLine(L"amuleDlg.cpp", 546, false, logStandard , wxGetTranslation(("aMule dialog destroyed"))); |
| 547 | } |
| 548 | |
| 549 | |
| 550 | void CamuleDlg::OnBnConnect(wxCommandEvent& WXUNUSED(evt)) |
| 551 | { |
| 552 | |
| 553 | bool disconnect = (theApp->IsConnectedED2K() || theApp->serverconnect->IsConnecting()) |
| 554 | #ifdef CLIENT_GUI |
| 555 | || theApp->IsConnectedKad() // there's no Kad running state atm |
| 556 | #else |
| 557 | || (Kademlia::CKademlia::IsRunning()) |
| 558 | #endif |
| 559 | ; |
| 560 | if (thePrefs::GetNetworkED2K()) { |
| 561 | if (disconnect) { |
| 562 | //disconnect if currently connected |
| 563 | if (theApp->serverconnect->IsConnecting()) { |
| 564 | theApp->serverconnect->StopConnectionTry(); |
| 565 | } else { |
| 566 | theApp->serverconnect->Disconnect(); |
| 567 | } |
| 568 | } else { |
| 569 | //connect if not currently connected |
| 570 | AddLogLineC(_("Connecting"))theLogger.AddLogLine(L"amuleDlg.cpp", 570, true, logStandard, wxGetTranslation(("Connecting"))); |
| 571 | theApp->serverconnect->ConnectToAnyServer(); |
| 572 | } |
| 573 | } else { |
| 574 | wxASSERT(!theApp->IsConnectedED2K())do { if ( !theApp->IsConnectedED2K() ) { } else if ( wxTheAssertHandler && (wxOnAssert("amuleDlg.cpp", 574, __FUNCTION__, "!theApp->IsConnectedED2K()" , (const char*)__null), wxTrapInAssert) ) { wxTrapInAssert = false ; asm volatile ("int $3"); } } while ( (void)0, 0 ); |
| 575 | } |
| 576 | |
| 577 | // Connect Kad also |
| 578 | if (thePrefs::GetNetworkKademlia()) { |
| 579 | if( disconnect ) { |
| 580 | theApp->StopKad(); |
| 581 | } else { |
| 582 | theApp->StartKad(); |
| 583 | } |
| 584 | } else { |
| 585 | #ifndef CLIENT_GUI |
| 586 | wxASSERT(!Kademlia::CKademlia::IsRunning())do { if ( !Kademlia::CKademlia::IsRunning() ) { } else if ( wxTheAssertHandler && (wxOnAssert("amuleDlg.cpp", 586, __FUNCTION__, "!Kademlia::CKademlia::IsRunning()" , (const char*)__null), wxTrapInAssert) ) { wxTrapInAssert = false ; asm volatile ("int $3"); } } while ( (void)0, 0 ); |
| 587 | #endif |
| 588 | } |
| 589 | |
| 590 | ShowConnectionState(); |
| 591 | } |
| 592 | |
| 593 | |
| 594 | void CamuleDlg::ResetLog(int id) |
| 595 | { |
| 596 | wxTextCtrl* ct = CastByID(id, m_serverwnd, wxTextCtrl)dynamic_cast<wxTextCtrl*>( wxWindow::FindWindowById( (id ), (m_serverwnd) ) ); |
| 597 | wxCHECK_RET(ct, wxT("Resetting unknown log"))if ( ct ) {} else { do { if ( wxTheAssertHandler && ( wxOnAssert("amuleDlg.cpp", 597, __FUNCTION__, "\"ct\"", L"Resetting unknown log" ), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile ( "int $3"); } } while ( (void)0, 0 ); return; } struct wxDummyCheckStruct597; |
| 598 | |
| 599 | ct->Clear(); |
| 600 | |
| 601 | if (id == ID_LOGVIEW10242) { |
| 602 | // Also clear the log line |
| 603 | wxStaticText* text = CastChild(wxT("infoLabel"), wxStaticText)dynamic_cast<wxStaticText*>( FindWindow( L"infoLabel" ) ); |
| 604 | text->SetLabel(wxEmptyString); |
| 605 | text->GetParent()->Layout(); |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | |
| 610 | void CamuleDlg::AddLogLine(const wxString& line) |
| 611 | { |
| 612 | bool addtostatusbar = line[0] == '!'; |
| 613 | wxString bufferline = line.Mid(1); |
| 614 | |
| 615 | // Add the message to the log-view |
| 616 | wxTextCtrl* ct = CastByID( ID_LOGVIEW, m_serverwnd, wxTextCtrl )dynamic_cast<wxTextCtrl*>( wxWindow::FindWindowById( (10242 ), (m_serverwnd) ) ); |
| 617 | if ( ct ) { |
| 618 | // Bold critical log-lines |
| 619 | // Works in Windows too thanks to wxTE_RICH2 style in muuli |
| 620 | wxTextAttr style = ct->GetDefaultStyle(); |
| 621 | wxFont font = style.GetFont(); |
| 622 | font.SetWeight(addtostatusbar ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL); |
| 623 | style.SetFont(font); |
| 624 | style.SetFontSize(8); |
| 625 | ct->SetDefaultStyle(style); |
| 626 | ct->AppendText(bufferline); |
| 627 | ct->ShowPosition( ct->GetLastPosition() - 1 ); |
| 628 | } |
| 629 | |
| 630 | |
| 631 | // Set the status-bar if the event warrents it |
| 632 | if ( addtostatusbar ) { |
| 633 | // Escape "&"s, which would otherwise not show up |
| 634 | bufferline.Replace( wxT("&")L"&", wxT("&&")L"&&" ); |
| 635 | wxStaticText* text = CastChild( wxT("infoLabel"), wxStaticText )dynamic_cast<wxStaticText*>( FindWindow( L"infoLabel" ) ); |
| 636 | // Only show the first line if multiple lines |
| 637 | text->SetLabel( bufferline.BeforeFirst( wxT('\n')L'\n' ) ); |
| 638 | text->SetToolTip( bufferline ); |
| 639 | text->GetParent()->Layout(); |
| 640 | } |
| 641 | |
| 642 | } |
| 643 | |
| 644 | |
| 645 | void CamuleDlg::AddServerMessageLine(wxString& message) |
| 646 | { |
| 647 | wxTextCtrl* cv= CastByID( ID_SERVERINFO, m_serverwnd, wxTextCtrl )dynamic_cast<wxTextCtrl*>( wxWindow::FindWindowById( (10240 ), (m_serverwnd) ) ); |
| 648 | if(cv) { |
| 649 | if (message.Length() > 500) { |
| 650 | cv->AppendText(message.Left(500) + wxT("\n")L"\n"); |
| 651 | } else { |
| 652 | cv->AppendText(message + wxT("\n")L"\n"); |
| 653 | } |
| 654 | cv->ShowPosition(cv->GetLastPosition()-1); |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | |
| 659 | void CamuleDlg::ShowConnectionState(bool skinChanged) |
| 660 | { |
| 661 | static wxImageList status_arrows(16,16,true,0); |
| 662 | if (!status_arrows.GetImageCount()) { |
| 663 | // Generate the image list (This is only done once) |
| 664 | for (int t = 0; t < 7; ++t) { |
| 665 | status_arrows.Add(connImages(t)); |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | m_serverwnd->UpdateED2KInfo(); |
| 670 | m_serverwnd->UpdateKadInfo(); |
| 671 | |
| 672 | |
| 673 | //////////////////////////////////////////////////////////// |
| 674 | // Determine the status of the networks |
| 675 | // |
| 676 | enum ED2KState { ED2KOff = 0, ED2KLowID = 1, ED2KConnecting = 2, ED2KHighID = 3, ED2KUndef = -1 }; |
| 677 | enum EKadState { EKadOff = 4, EKadFW = 5, EKadConnecting = 5, EKadOK = 6, EKadUndef = -1 }; |
| 678 | |
| 679 | ED2KState ed2kState = ED2KOff; |
| 680 | EKadState kadState = EKadOff; |
| 681 | |
| 682 | //////////////////////////////////////////////////////////// |
| 683 | // Update the label on the status-bar and determine |
| 684 | // the states of the two networks. |
| 685 | // |
| 686 | wxString msgED2K; |
| 687 | if (theApp->IsConnectedED2K()) { |
| 688 | CServer* server = theApp->serverconnect->GetCurrentServer(); |
| 689 | if (server) { |
| 690 | msgED2K = CFormat(wxT("eD2k: %s")L"eD2k: %s") % server->GetListName(); |
| 691 | } |
| 692 | |
| 693 | if (theApp->serverconnect->IsLowID()) { |
| 694 | ed2kState = ED2KLowID; |
| 695 | } else { |
| 696 | ed2kState = ED2KHighID; |
| 697 | } |
| 698 | } else if (theApp->serverconnect->IsConnecting()) { |
| 699 | msgED2K = _("eD2k: Connecting")wxGetTranslation(("eD2k: Connecting")); |
| 700 | |
| 701 | ed2kState = ED2KConnecting; |
| 702 | } else if (thePrefs::GetNetworkED2K()) { |
| 703 | msgED2K = _("eD2k: Disconnected")wxGetTranslation(("eD2k: Disconnected")); |
| 704 | } |
| 705 | |
| 706 | wxString msgKad; |
| 707 | if (theApp->IsConnectedKad()) { |
| 708 | if (theApp->IsFirewalledKad()) { |
| 709 | msgKad = _("Kad: Firewalled")wxGetTranslation(("Kad: Firewalled")); |
| 710 | |
| 711 | kadState = EKadFW; |
| 712 | } else { |
| 713 | msgKad = _("Kad: Connected")wxGetTranslation(("Kad: Connected")); |
| 714 | |
| 715 | kadState = EKadOK; |
| 716 | } |
| 717 | } else if (theApp->IsKadRunning()) { |
| 718 | msgKad = _("Kad: Connecting")wxGetTranslation(("Kad: Connecting")); |
| 719 | |
| 720 | kadState = EKadConnecting; |
| 721 | } else if (thePrefs::GetNetworkKademlia()) { |
| 722 | msgKad = _("Kad: Off")wxGetTranslation(("Kad: Off")); |
| 723 | } |
| 724 | |
| 725 | wxStaticText* connLabel = CastChild( wxT("connLabel"), wxStaticText )dynamic_cast<wxStaticText*>( FindWindow( L"connLabel" ) ); |
| 726 | { wxCHECK_RET(connLabel, wxT("'connLabel' widget not found"))if ( connLabel ) {} else { do { if ( wxTheAssertHandler && (wxOnAssert("amuleDlg.cpp", 726, __FUNCTION__, "\"connLabel\"" , L"'connLabel' widget not found"), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while ( (void)0, 0 ); return ; } struct wxDummyCheckStruct726; } |
| 727 | |
| 728 | wxString labelMsg; |
| 729 | if (msgED2K.Length() && msgKad.Length()) { |
| 730 | labelMsg = msgED2K + wxT(" | ")L" | " + msgKad; |
| 731 | } else { |
| 732 | labelMsg = msgED2K + msgKad; |
| 733 | } |
| 734 | |
| 735 | connLabel->SetLabel(labelMsg); |
| 736 | connLabel->GetParent()->Layout(); |
| 737 | |
| 738 | |
| 739 | //////////////////////////////////////////////////////////// |
| 740 | // Update the connect/disconnect/cancel button. |
| 741 | // |
| 742 | enum EConnState { |
| 743 | ECS_Unknown, |
| 744 | ECS_Connected, |
| 745 | ECS_Connecting, |
| 746 | ECS_Disconnected |
| 747 | }; |
| 748 | |
| 749 | static EConnState s_oldState = ECS_Unknown; |
| 750 | EConnState currentState = ECS_Disconnected; |
| 751 | |
| 752 | if (theApp->serverconnect->IsConnecting() || |
| 753 | (theApp->IsKadRunning() && !theApp->IsConnectedKad())) { |
| 754 | currentState = ECS_Connecting; |
| 755 | } else if (theApp->IsConnected()) { |
| 756 | currentState = ECS_Connected; |
| 757 | } else { |
| 758 | currentState = ECS_Disconnected; |
| 759 | } |
| 760 | |
| 761 | if ( (true == skinChanged) || (currentState != s_oldState) ) { |
| 762 | wxWindowUpdateLocker freezer(m_wndToolbar); |
| 763 | |
| 764 | wxToolBarToolBase* toolbarTool = m_wndToolbar->FindById(ID_BUTTONCONNECT10333); |
| 765 | |
| 766 | switch (currentState) { |
| 767 | case ECS_Connecting: |
| 768 | toolbarTool->SetLabel(_("Cancel")wxGetTranslation(("Cancel"))); |
| 769 | toolbarTool->SetShortHelp(_("Stop the current connection attempts")wxGetTranslation(("Stop the current connection attempts"))); |
| 770 | toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(2)); |
| 771 | break; |
| 772 | |
| 773 | case ECS_Connected: |
| 774 | toolbarTool->SetLabel(_("Disconnect")wxGetTranslation(("Disconnect"))); |
| 775 | toolbarTool->SetShortHelp(_("Disconnect from the currently connected networks")wxGetTranslation(("Disconnect from the currently connected networks" ))); |
| 776 | toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(1)); |
| 777 | break; |
| 778 | |
| 779 | default: |
| 780 | toolbarTool->SetLabel(_("Connect")wxGetTranslation(("Connect"))); |
| 781 | toolbarTool->SetShortHelp(_("Connect to the currently enabled networks")wxGetTranslation(("Connect to the currently enabled networks" ))); |
| 782 | toolbarTool->SetNormalBitmap(m_tblist.GetBitmap(0)); |
| 783 | } |
| 784 | |
| 785 | m_wndToolbar->EnableTool(ID_BUTTONCONNECT10333, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()) && theApp->ipfilter->IsReady()); |
| 786 | |
| 787 | s_oldState = currentState; |
| 788 | } |
| 789 | |
| 790 | |
| 791 | //////////////////////////////////////////////////////////// |
| 792 | // Update the globe-icon in the lower-right corner. |
| 793 | // (only if connection state has changed) |
| 794 | // |
| 795 | static ED2KState s_ED2KOldState = ED2KUndef; |
| 796 | static EKadState s_EKadOldState = EKadUndef; |
| 797 | if (ed2kState != s_ED2KOldState || kadState != s_EKadOldState) { |
| 798 | s_ED2KOldState = ed2kState; |
| 799 | s_EKadOldState = kadState; |
| 800 | wxStaticBitmap* connBitmap = CastChild( wxT("connImage"), wxStaticBitmap )dynamic_cast<wxStaticBitmap*>( FindWindow( L"connImage" ) ); |
| 801 | wxCHECK_RET(connBitmap, wxT("'connImage' widget not found"))if ( connBitmap ) {} else { do { if ( wxTheAssertHandler && (wxOnAssert("amuleDlg.cpp", 801, __FUNCTION__, "\"connBitmap\"" , L"'connImage' widget not found"), wxTrapInAssert) ) { wxTrapInAssert = false; asm volatile ("int $3"); } } while ( (void)0, 0 ); return ; } struct wxDummyCheckStruct801; |
| 802 | |
| 803 | wxBitmap statusIcon = connBitmap->GetBitmap(); |
| 804 | // Sanity check - otherwise there's a crash here if aMule runs out of resources |
| 805 | if (statusIcon.GetRefData() == NULL__null) { |
| 806 | return; |
| 807 | } |
| 808 | |
| 809 | wxMemoryDC bitmapDC(statusIcon); |
| 810 | |
| 811 | status_arrows.Draw(kadState, bitmapDC, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT0x0002); |
| 812 | status_arrows.Draw(ed2kState, bitmapDC, 0, 0, wxIMAGELIST_DRAW_TRANSPARENT0x0002); |
| 813 | |
| 814 | connBitmap->SetBitmap(statusIcon); |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | |
| 819 | void CamuleDlg::ShowUserCount(const wxString& info) |
| 820 | { |
| 821 | wxStaticText* label = CastChild( wxT("userLabel"), wxStaticText )dynamic_cast<wxStaticText*>( FindWindow( L"userLabel" ) ); |
| 822 | |
| 823 | // Update Kad tab |
| 824 | m_serverwnd->UpdateKadInfo(); |
| 825 | |
| 826 | label->SetLabel(info); |
| 827 | label->GetParent()->Layout(); |
| 828 | } |
| 829 | |
| 830 | |
| 831 | void CamuleDlg::ShowTransferRate() |
| 832 | { |
| 833 | float kBpsUp = theStats::GetUploadRate() / 1024.0; |
| 834 | float kBpsDown = theStats::GetDownloadRate() / 1024.0; |
| 835 | float MBpsUp = kBpsUp / 1024.0; |
| 836 | float MBpsDown = kBpsDown / 1024.0; |
| 837 | bool showMBpsUp = (MBpsUp >= 1); |
| 838 | bool showMBpsDown = (MBpsDown >= 1); |
| 839 | wxString buffer; |
| 840 | if( thePrefs::ShowOverhead() ) |
| 841 | { |
| 842 | buffer = CFormat(_("Up: %.1f%s (%.1f) | Down: %.1f%s (%.1f)")wxGetTranslation(("Up: %.1f%s (%.1f) | Down: %.1f%s (%.1f)"))) |
| 843 | % (showMBpsUp ? MBpsUp : kBpsUp) % (showMBpsUp ? _(" MB/s")wxGetTranslation((" MB/s")) : ((kBpsUp > 0) ? _(" kB/s")wxGetTranslation((" kB/s")) : wxT("")L"")) % (theStats::GetUpOverheadRate() / 1024.0) |
| 844 | % (showMBpsDown ? MBpsDown : kBpsDown) % (showMBpsDown ? _(" MB/s")wxGetTranslation((" MB/s")) : ((kBpsDown > 0) ? _(" kB/s")wxGetTranslation((" kB/s")) : wxT("")L"")) % (theStats::GetDownOverheadRate() / 1024.0); |
| 845 | } else { |
| 846 | buffer = CFormat(_("Up: %.1f%s | Down: %.1f%s")wxGetTranslation(("Up: %.1f%s | Down: %.1f%s"))) |
| 847 | % (showMBpsUp ? MBpsUp : kBpsUp) % (showMBpsUp ? _(" MB/s")wxGetTranslation((" MB/s")) : ((kBpsUp > 0) ? _(" kB/s")wxGetTranslation((" kB/s")) : wxT("")L"")) |
| 848 | % (showMBpsDown ? MBpsDown : kBpsDown) % (showMBpsDown ? _(" MB/s")wxGetTranslation((" MB/s")) : ((kBpsDown > 0) ? _(" kB/s")wxGetTranslation((" kB/s")) : wxT("")L"")); |
| 849 | } |
| 850 | buffer.Truncate(50); // Max size 50 |
| 851 | |
| 852 | wxStaticText* label = CastChild( wxT("speedLabel"), wxStaticText )dynamic_cast<wxStaticText*>( FindWindow( L"speedLabel" ) ); |
| 853 | label->SetLabel(buffer); |
| 854 | label->GetParent()->Layout(); |
| 855 | |
| 856 | // Show upload/download speed in title |
| 857 | if (thePrefs::GetShowRatesOnTitle()) { |
| 858 | wxString UpDownSpeed = CFormat(wxT("Up: %.1f%s | Down: %.1f%s")L"Up: %.1f%s | Down: %.1f%s") |
| 859 | % (showMBpsUp ? MBpsUp : kBpsUp) % (showMBpsUp ? _(" MB/s")wxGetTranslation((" MB/s")) : ((kBpsUp > 0) ? _(" kB/s")wxGetTranslation((" kB/s")) : wxT("")L"")) |
| 860 | % (showMBpsDown ? MBpsDown : kBpsDown) % (showMBpsDown ? _(" MB/s")wxGetTranslation((" MB/s")) : ((kBpsDown > 0) ? _(" kB/s")wxGetTranslation((" kB/s")) : wxT("")L"")); |
| 861 | if (thePrefs::GetShowRatesOnTitle() == 1) { |
| 862 | SetTitle(theApp->m_FrameTitle + wxT(" -- ")L" -- " + UpDownSpeed); |
| 863 | } else { |
| 864 | SetTitle(UpDownSpeed + wxT(" -- ")L" -- " + theApp->m_FrameTitle); |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | wxASSERT((m_wndTaskbarNotifier != NULL) == thePrefs::UseTrayIcon())do { if ( (m_wndTaskbarNotifier != __null) == thePrefs::UseTrayIcon () ) { } else if ( wxTheAssertHandler && (wxOnAssert( "amuleDlg.cpp", 868, __FUNCTION__, "(m_wndTaskbarNotifier != __null) == thePrefs::UseTrayIcon()" , (const char*)__null), wxTrapInAssert) ) { wxTrapInAssert = false ; asm volatile ("int $3"); } } while ( (void)0, 0 ); |
| 869 | if (m_wndTaskbarNotifier) { |
| 870 | // set trayicon-icon |
| 871 | int percentDown = (int)ceil((kBpsDown*100) / thePrefs::GetMaxGraphDownloadRate()); |
| 872 | UpdateTrayIcon( ( percentDown > 100 ) ? 100 : percentDown); |
| 873 | |
| 874 | wxString buffer2; |
| 875 | if ( theApp->IsConnected() ) { |
| 876 | buffer2 = CFormat(_("aMule (%s | Connected)")wxGetTranslation(("aMule (%s | Connected)"))) % buffer; |
| 877 | } else { |
| 878 | buffer2 = CFormat(_("aMule (%s | Disconnected)")wxGetTranslation(("aMule (%s | Disconnected)"))) % buffer; |
| 879 | } |
| 880 | m_wndTaskbarNotifier->SetTrayToolTip(buffer2); |
| 881 | } |
| 882 | |
| 883 | wxStaticBitmap* bmp = CastChild( wxT("transferImg"), wxStaticBitmap )dynamic_cast<wxStaticBitmap*>( FindWindow( L"transferImg" ) ); |
| 884 | bmp->SetBitmap(dlStatusImages((kBpsUp>0.01 ? 2 : 0) + (kBpsDown>0.01 ? 1 : 0))); |
| 885 | } |
| 886 | |
| 887 | void CamuleDlg::DlgShutDown() |
| 888 | { |
| 889 | // Are we already shutting down or still on init? |
| 890 | if ( m_is_safe_state == false ) { |
| 891 | return; |
| 892 | } |
| 893 | |
| 894 | // we are going DOWN |
| 895 | m_is_safe_state = false; |
| 896 | |
| 897 | // Stop the GUI Timer |
| 898 | delete gui_timer; |
| 899 | m_transferwnd->downloadlistctrl->DeleteAllItems(); |
| 900 | |
| 901 | // We want to delete the systray too! |
| 902 | RemoveSystray(); |
| 903 | } |
| 904 | |
| 905 | void CamuleDlg::OnClose(wxCloseEvent& evt) |
| 906 | { |
| 907 | if (thePrefs::HideOnClose() && evt.CanVeto()) { |
| 908 | Show(false); |
| 909 | evt.Veto(); |
| 910 | return; |
| 911 | } |
| 912 | |
| 913 | // This will be here till the core close is != app close |
| 914 | if (evt.CanVeto() && thePrefs::IsConfirmExitEnabled() ) { |
| 915 | if (wxNO0x00000008 == wxMessageBox(wxString(CFormat(_("Do you really want to exit %s?")wxGetTranslation(("Do you really want to exit %s?"))) % theApp->GetMuleAppName()), |
| 916 | wxString(_("Exit confirmation")wxGetTranslation(("Exit confirmation"))), wxYES_NO(0x00000002 | 0x00000008), this)) { |
| 917 | evt.Veto(); |
| 918 | return; |
| 919 | } |
| 920 | } |
| 921 | |
| 922 | SaveGUIPrefs(); |
| 923 | |
| 924 | Enable(false); |
| 925 | Show(false); |
| 926 | |
| 927 | theApp->ShutDown(evt); |
| 928 | } |
| 929 | |
| 930 | |
| 931 | void CamuleDlg::OnBnClickedFast(wxCommandEvent& WXUNUSED(evt)) |
| 932 | { |
| 933 | wxTextCtrl* ctl = CastChild( wxT("FastEd2kLinks"), wxTextCtrl )dynamic_cast<wxTextCtrl*>( FindWindow( L"FastEd2kLinks" ) ); |
| 934 | |
| 935 | for ( int i = 0; i < ctl->GetNumberOfLines(); i++ ) { |
| 936 | wxString strlink = ctl->GetLineText(i); |
| 937 | strlink.Trim(true); |
| 938 | strlink.Trim(false); |
| 939 | if ( !strlink.IsEmpty() ) { |
| 940 | theApp->downloadqueue->AddLink( strlink, m_transferwnd->downloadlistctrl->GetCategory() ); |
| 941 | } |
| 942 | } |
| 943 | |
| 944 | ctl->SetValue(wxEmptyString); |
| 945 | } |
| 946 | |
| 947 | |
| 948 | // Formerly known as LoadRazorPrefs() |
| 949 | bool CamuleDlg::LoadGUIPrefs(bool override_pos, bool override_size) |
| 950 | { |
| 951 | // Create a config base for loading razor preferences |
| 952 | wxConfigBase *config = wxConfigBase::Get(); |
| 953 | // If config haven't been created exit without loading |
| 954 | if (config == NULL__null) { |
| 955 | return false; |
| 956 | } |
| 957 | |
| 958 | // The section where to save in in file |
| 959 | wxString section = wxT("/Razor_Preferences/")L"/Razor_Preferences/"; |
| 960 | |
| 961 | // Get window size and position |
| 962 | int x1 = config->Read(section + wxT("MAIN_X_POS")L"MAIN_X_POS", -1); |
| 963 | int y1 = config->Read(section + wxT("MAIN_Y_POS")L"MAIN_Y_POS", -1); |
| 964 | int x2 = config->Read(section + wxT("MAIN_X_SIZE")L"MAIN_X_SIZE", -1); |
| 965 | int y2 = config->Read(section + wxT("MAIN_Y_SIZE")L"MAIN_Y_SIZE", -1); |
| 966 | |
| 967 | int maximized = config->Read(section + wxT("Maximized")L"Maximized", 01); |
| 968 | |
| 969 | // Kry - Random usable pos for m_srv_split_pos |
| 970 | m_srv_split_pos = config->Read(section + wxT("SRV_SPLITTER_POS")L"SRV_SPLITTER_POS", 463l); |
| 971 | if (!override_size) { |
| 972 | if (x2 > 0 && y2 > 0) { |
| 973 | SetSize(x2, y2); |
| 974 | } else { |
| 975 | #ifndef __WXGTK__1 |
| 976 | // Probably first run. |
| 977 | Maximize(); |
| 978 | #endif |
| 979 | } |
| 980 | } |
| 981 | |
| 982 | if (!override_pos) { |
| 983 | // If x1 and y1 != -1 Redefine location |
| 984 | if(x1 != -1 && y1 != -1) { |
| 985 | wxRect display = wxGetClientDisplayRect(); |
| 986 | if (x1 <= display.GetRightTop().x && y1 <= display.GetRightBottom().y) { |
| 987 | Move(x1, y1); |
| 988 | } else { |
| 989 | // It's offscreen... so let's not. |
| 990 | } |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | if (!override_size && !override_pos && maximized) { |
| 995 | Maximize(); |
| 996 | } |
| 997 | |
| 998 | return true; |
| 999 | } |
| 1000 | |
| 1001 | |
| 1002 | bool CamuleDlg::SaveGUIPrefs() |
| 1003 | { |
| 1004 | /* Razor 1a - Modif by MikaelB |
| 1005 | Save client size and position */ |
| 1006 | |
| 1007 | // Create a config base for saving razor preferences |
| 1008 | wxConfigBase *config = wxConfigBase::Get(); |
| 1009 | // If config haven't been created exit without saving |
| 1010 | if (config == NULL__null) { |
| 1011 | return false; |
| 1012 | } |
| 1013 | // The section where to save in in file |
| 1014 | wxString section = wxT("/Razor_Preferences/")L"/Razor_Preferences/"; |
| 1015 | |
| 1016 | if (!IsIconized()) { |
| 1017 | // Main window location and size |
| 1018 | int x1, y1, x2, y2; |
| 1019 | GetPosition(&x1, &y1); |
| 1020 | GetSize(&x2, &y2); |
| 1021 | |
| 1022 | // Saving window size and position |
| 1023 | config->Write(section+wxT("MAIN_X_POS")L"MAIN_X_POS", (long) x1); |
| 1024 | config->Write(section+wxT("MAIN_Y_POS")L"MAIN_Y_POS", (long) y1); |
| 1025 | |
| 1026 | config->Write(section+wxT("MAIN_X_SIZE")L"MAIN_X_SIZE", (long) x2); |
| 1027 | config->Write(section+wxT("MAIN_Y_SIZE")L"MAIN_Y_SIZE", (long) y2); |
| 1028 | |
| 1029 | config->Write(section+wxT("Maximized")L"Maximized", (long) (IsMaximized() ? 1 : 0)); |
| 1030 | } |
| 1031 | |
| 1032 | // Saving sash position of splitter in server window |
| 1033 | config->Write(section+wxT("SRV_SPLITTER_POS")L"SRV_SPLITTER_POS", (long) m_srv_split_pos); |
| 1034 | |
| 1035 | config->Flush(true); |
| 1036 | |
| 1037 | /* End modif */ |
| 1038 | |
| 1039 | return true; |
| 1040 | } |
| 1041 | |
| 1042 | |
| 1043 | void CamuleDlg::OnMinimize(wxIconizeEvent& evt) |
| 1044 | { |
| 1045 | // Evil Hack: check if the mouse is inside the window |
| 1046 | #ifndef __WINDOWS__ |
| 1047 | if (wxFindWindowAtPoint(wxGetMousePosition())) |
| 1048 | #endif |
| 1049 | { |
| 1050 | if (m_prefsDialog && m_prefsDialog->IsShown()) { |
| 1051 | // Veto. |
| 1052 | } else { |
| 1053 | if (m_wndTaskbarNotifier && thePrefs::DoMinToTray()) { |
| 1054 | Show(!evt.IsIconized()); |
| 1055 | } |
| 1056 | else { |
| 1057 | evt.Skip(); |
| 1058 | } |
| 1059 | } |
| 1060 | } |
| 1061 | } |
| 1062 | |
| 1063 | void CamuleDlg::OnGUITimer(wxTimerEvent& WXUNUSED(evt)) |
| 1064 | { |
| 1065 | // Former TimerProc section |
| 1066 | |
| 1067 | static uint32 msPrev1, msPrev5; |
| 1068 | |
| 1069 | uint32 msCur = theStats::GetUptimeMillis(); |
| 1070 | |
| 1071 | // can this actually happen under wxwin ? |
| 1072 | if (!SafeState()) { |
| 1073 | return; |
| 1074 | } |
| 1075 | |
| 1076 | #ifndef CLIENT_GUI |
| 1077 | static uint32 msPrevGraph, msPrevStats; |
| 1078 | int msGraphUpdate = thePrefs::GetTrafficOMeterInterval() * 1000; |
| 1079 | if ((msGraphUpdate > 0) && ((msCur / msGraphUpdate) > (msPrevGraph / msGraphUpdate))) { |
| 1080 | // trying to get the graph shifts evenly spaced after a change in the update period |
| 1081 | msPrevGraph = msCur; |
| 1082 | |
| 1083 | GraphUpdateInfo update = theApp->m_statistics->GetPointsForUpdate(); |
| 1084 | |
| 1085 | m_statisticswnd->UpdateStatGraphs(theStats::GetPeakConnections(), update); |
| 1086 | m_kademliawnd->UpdateGraph(update); |
| 1087 | } |
| 1088 | |
| 1089 | int sStatsUpdate = thePrefs::GetStatsInterval(); |
| 1090 | if ((sStatsUpdate > 0) && ((int)(msCur - msPrevStats) > sStatsUpdate*1000)) { |
| 1091 | if (m_statisticswnd->IsShownOnScreen()) { |
| 1092 | msPrevStats = msCur; |
| 1093 | m_statisticswnd->ShowStatistics(); |
| 1094 | } |
| 1095 | } |
| 1096 | #endif |
| 1097 | |
| 1098 | if (msCur-msPrev5 > 5000) { // every 5 seconds |
| 1099 | msPrev5 = msCur; |
| 1100 | ShowTransferRate(); |
| 1101 | if (thePrefs::ShowCatTabInfos() && theApp->amuledlg->m_activewnd == theApp->amuledlg->m_transferwnd) { |
| 1102 | m_transferwnd->UpdateCatTabTitles(); |
| 1103 | } |
| 1104 | if (thePrefs::AutoSortDownload()) { |
| 1105 | m_transferwnd->downloadlistctrl->SortList(); |
| 1106 | m_transferwnd->clientlistctrl->SortList(); |
| 1107 | m_sharedfileswnd->peerslistctrl->SortList(); |
| 1108 | } |
| 1109 | m_kademliawnd->UpdateNodeCount(CStatistics::GetKadNodes()); |
| 1110 | } |
| 1111 | |
| 1112 | if (msCur-msPrev1 > 1000) { // every second |
| 1113 | msPrev1 = msCur; |
| 1114 | if (m_CurrentBlinkBitmap == 12) { |
| 1115 | m_CurrentBlinkBitmap = 7; |
| 1116 | SetMessagesTool(); |
| 1117 | } else { |
| 1118 | if (m_BlinkMessages) { |
| 1119 | m_CurrentBlinkBitmap = 12; |
| 1120 | SetMessagesTool(); |
| 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | } |
| 1125 | } |
| 1126 | |
| 1127 | |
| 1128 | void CamuleDlg::SetMessagesTool() |
| 1129 | { |
| 1130 | wxWindowUpdateLocker freezer(m_wndToolbar); |
| 1131 | #ifdef __WXCOCOA__ |
| 1132 | m_wndToolbar->FindById(ID_BUTTONMESSAGES10338)->SetNormalBitmap(m_tblist.GetBitmap(m_CurrentBlinkBitmap)); |
| 1133 | #else |
| 1134 | m_wndToolbar->SetToolNormalBitmap(ID_BUTTONMESSAGES10338, m_tblist.GetBitmap(m_CurrentBlinkBitmap)); |
| 1135 | #endif |
| 1136 | } |
| 1137 | |
| 1138 | void CamuleDlg::LaunchUrl( const wxString& url ) |
| 1139 | { |
| 1140 | wxString cmd; |
| 1141 | |
| 1142 | cmd = thePrefs::GetBrowser(); |
| 1143 | wxString tmp = url; |
| 1144 | // Pipes cause problems, so escape them |
| 1145 | tmp.Replace( wxT("|")L"|", wxT("%7C")L"%7C" ); |
| 1146 | |
| 1147 | if ( !cmd.IsEmpty() ) { |
| 1148 | if (!cmd.Replace(wxT("%s")L"%s", tmp)) { |
| 1149 | // No %s found, just append the url |
| 1150 | cmd += wxT(" ")L" " + tmp; |
| 1151 | } |
| 1152 | |
| 1153 | CTerminationProcess *p = new CTerminationProcess(cmd); |
| 1154 | if (wxExecute(cmd, wxEXEC_ASYNC, p)) { |
| 1155 | AddLogLineN(_("Launch Command: ") + cmd)theLogger.AddLogLine(L"amuleDlg.cpp", 1155, false, logStandard , wxGetTranslation(("Launch Command: ")) + cmd); |
| 1156 | return; |
| 1157 | } else { |
| 1158 | delete p; |
| 1159 | } |
| 1160 | } else { |
| 1161 | wxLaunchDefaultBrowser(tmp); |
| 1162 | return; |
| 1163 | } |
| 1164 | // Unable to execute browser. But this error message doesn't make sense, |
| 1165 | // cosidering that you _can't_ set the browser executable path... =/ |
| 1166 | wxLogErrorfor ( bool wxdoif1166 = false; !wxdoif1166 && wxLog:: IsLevelEnabled(wxLOG_Error, wxString::FromAscii(wxLOG_COMPONENT )); wxdoif1166 = true ) wxLogger(wxLOG_Error, "amuleDlg.cpp", 1166, __FUNCTION__, wxLOG_COMPONENT).Log(wxT("Unable to launch browser. Please set correct browser executable path in Preferences.")L"Unable to launch browser. Please set correct browser executable path in Preferences."); |
| 1167 | } |
| 1168 | |
| 1169 | |
| 1170 | bool CamuleDlg::Check_and_Init_Skin() |
| 1171 | { |
| 1172 | bool ret = true; |
| 1173 | wxString skinFileName(thePrefs::GetSkin()); |
| 1174 | |
| 1175 | if (skinFileName.IsEmpty() || skinFileName.IsSameAs(_("- default -")wxGetTranslation(("- default -")))) { |
| 1176 | return false; |
| 1177 | } |
| 1178 | |
| 1179 | wxString userDir(JoinPaths(thePrefs::GetConfigDir(), wxT("skins")L"skins") + wxFileName::GetPathSeparator()); |
| 1180 | |
| 1181 | wxStandardPathsBase &spb(wxStandardPaths::Get()); |
| 1182 | #ifdef __WINDOWS__ |
| 1183 | wxString dataDir(spb.GetPluginsDir()); |
| 1184 | #elif defined(__WXMAC__) |
| 1185 | wxString dataDir(spb.GetDataDir()); |
| 1186 | #else |
| 1187 | wxString dataDir(spb.GetDataDir().BeforeLast(wxT('/')L'/') + wxT("/amule")L"/amule"); |
| 1188 | #endif |
| 1189 | wxString systemDir(JoinPaths(dataDir,wxT("skins")L"skins") + wxFileName::GetPathSeparator()); |
| 1190 | |
| 1191 | |
| 1192 | skinFileName.Replace(wxT("User:")L"User:", userDir ); |
| 1193 | skinFileName.Replace(wxT("System:")L"System:", systemDir ); |
| 1194 | |
| 1195 | m_skinFileName.Assign(skinFileName); |
| 1196 | if (!m_skinFileName.FileExists()) { |
| 1197 | AddLogLineC(CFormat(theLogger.AddLogLine(L"amuleDlg.cpp", 1199, true, logStandard , CFormat( wxGetTranslation(("Skin directory '%s' does not exist" ))) % skinFileName) |
| 1198 | _("Skin directory '%s' does not exist")) %theLogger.AddLogLine(L"amuleDlg.cpp", 1199, true, logStandard , CFormat( wxGetTranslation(("Skin directory '%s' does not exist" ))) % skinFileName) |
| 1199 | skinFileName )theLogger.AddLogLine(L"amuleDlg.cpp", 1199, true, logStandard , CFormat( wxGetTranslation(("Skin directory '%s' does not exist" ))) % skinFileName); |
| 1200 | ret = false; |
| 1201 | } else if (!m_skinFileName.IsFileReadable()) { |
| 1202 | AddLogLineC(CFormat(theLogger.AddLogLine(L"amuleDlg.cpp", 1204, true, logStandard , CFormat( wxGetTranslation(("WARNING: Unable to open skin file '%s' for read" ))) % skinFileName) |
| 1203 | _("WARNING: Unable to open skin file '%s' for read")) %theLogger.AddLogLine(L"amuleDlg.cpp", 1204, true, logStandard , CFormat( wxGetTranslation(("WARNING: Unable to open skin file '%s' for read" ))) % skinFileName) |
| 1204 | skinFileName)theLogger.AddLogLine(L"amuleDlg.cpp", 1204, true, logStandard , CFormat( wxGetTranslation(("WARNING: Unable to open skin file '%s' for read" ))) % skinFileName); |
| 1205 | ret = false; |
| 1206 | } |
| 1207 | |
| 1208 | wxFFileInputStream in(m_skinFileName.GetFullPath()); |
| 1209 | wxZipInputStream zip(in); |
| 1210 | wxZipEntry *entry; |
| 1211 | |
| 1212 | while ((entry = zip.GetNextEntry()) != NULL__null) { |
| 1213 | wxZipEntry*& current = cat[entry->GetInternalName()]; |
| 1214 | delete current; |
| 1215 | current = entry; |
| 1216 | } |
| 1217 | |
| 1218 | return ret; |
| 1219 | } |
| 1220 | |
| 1221 | |
| 1222 | void CamuleDlg::Add_Skin_Icon( |
| 1223 | const wxString &iconName, |
| 1224 | const wxBitmap &stdIcon, |
| 1225 | bool useSkins) |
| 1226 | { |
| 1227 | wxImage new_image; |
| 1228 | if (useSkins) { |
| 1229 | wxFFileInputStream in(m_skinFileName.GetFullPath()); |
| 1230 | wxZipInputStream zip(in); |
| 1231 | |
| 1232 | ZipCatalog::iterator it = cat.find(wxZipEntry::GetInternalName(iconName + wxT(".png")L".png")); |
| 1233 | if ( it != cat.end() ) { |
| 1234 | zip.OpenEntry(*it->second); |
| 1235 | if ( !new_image.LoadFile(zip,wxBITMAP_TYPE_PNG) ) { |
| 1236 | AddLogLineN(wxT("Warning: Error loading icon for ") +theLogger.AddLogLine(L"amuleDlg.cpp", 1237, false, logStandard , L"Warning: Error loading icon for " + iconName) |
| 1237 | iconName)theLogger.AddLogLine(L"amuleDlg.cpp", 1237, false, logStandard , L"Warning: Error loading icon for " + iconName); |
| 1238 | useSkins = false; |
| 1239 | } |
| 1240 | }else { |
| 1241 | AddLogLineN(wxT("Warning: Can't load icon for ") +theLogger.AddLogLine(L"amuleDlg.cpp", 1242, false, logStandard , L"Warning: Can't load icon for " + iconName) |
| 1242 | iconName)theLogger.AddLogLine(L"amuleDlg.cpp", 1242, false, logStandard , L"Warning: Can't load icon for " + iconName); |
| 1243 | useSkins = false; |
| 1244 | } |
| 1245 | |
| 1246 | } |
| 1247 | |
| 1248 | wxBitmap bmp(useSkins ? new_image : stdIcon); |
| 1249 | if (iconName.StartsWith(wxT("Client_")L"Client_")) { |
| 1250 | m_imagelist.Add(bmp); |
| 1251 | } else if (iconName.StartsWith(wxT("Toolbar_")L"Toolbar_")) { |
| 1252 | m_tblist.Add(bmp); |
| 1253 | } |
| 1254 | } |
| 1255 | |
| 1256 | |
| 1257 | void CamuleDlg::Apply_Clients_Skin() |
| 1258 | { |
| 1259 | bool useSkins = Check_and_Init_Skin(); |
| 1260 | |
| 1261 | // Clear the client image list |
| 1262 | m_imagelist.RemoveAll(); |
| 1263 | |
| 1264 | // Add the images to the image list |
| 1265 | for (int i = 0; i < CLIENT_SKIN_SIZE; ++i) { |
| 1266 | Add_Skin_Icon(wxT("Client_")L"Client_" + m_clientSkinNames[i], |
| 1267 | clientImages(i), useSkins); |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | |
| 1272 | void CamuleDlg::Apply_Toolbar_Skin(wxToolBar *wndToolbar) |
| 1273 | { |
| 1274 | bool useSkins = Check_and_Init_Skin(); |
| 1275 | |
| 1276 | |
| 1277 | // Clear the toolbar image list |
| 1278 | m_tblist.RemoveAll(); |
| 1279 | |
| 1280 | // Add the images to the image list |
| 1281 | Add_Skin_Icon(wxT("Toolbar_Connect")L"Toolbar_Connect", connButImg(0), useSkins); |
| 1282 | Add_Skin_Icon(wxT("Toolbar_Disconnect")L"Toolbar_Disconnect", connButImg(1), useSkins); |
| 1283 | Add_Skin_Icon(wxT("Toolbar_Connecting")L"Toolbar_Connecting", connButImg(2), useSkins); |
| 1284 | Add_Skin_Icon(wxT("Toolbar_Network")L"Toolbar_Network", amuleDlgImages(20), useSkins); |
| 1285 | Add_Skin_Icon(wxT("Toolbar_Transfers")L"Toolbar_Transfers", amuleDlgImages(21), useSkins); |
| 1286 | Add_Skin_Icon(wxT("Toolbar_Search")L"Toolbar_Search", amuleDlgImages(22), useSkins); |
| 1287 | Add_Skin_Icon(wxT("Toolbar_Shared")L"Toolbar_Shared", amuleDlgImages(23), useSkins); |
| 1288 | Add_Skin_Icon(wxT("Toolbar_Messages")L"Toolbar_Messages", amuleDlgImages(24), useSkins); |
| 1289 | Add_Skin_Icon(wxT("Toolbar_Stats")L"Toolbar_Stats", amuleDlgImages(25), useSkins); |
| 1290 | Add_Skin_Icon(wxT("Toolbar_Prefs")L"Toolbar_Prefs", amuleDlgImages(26), useSkins); |
| 1291 | Add_Skin_Icon(wxT("Toolbar_Import")L"Toolbar_Import", amuleDlgImages(32), useSkins); |
| 1292 | Add_Skin_Icon(wxT("Toolbar_About")L"Toolbar_About", amuleDlgImages(29), useSkins); |
| 1293 | Add_Skin_Icon(wxT("Toolbar_Blink")L"Toolbar_Blink", amuleDlgImages(33), useSkins); |
| 1294 | |
| 1295 | // Build aMule toolbar |
| 1296 | wndToolbar->SetMargins(0, 0); |
| 1297 | |
| 1298 | // Placeholder. Gets updated by ShowConnectionState |
| 1299 | wndToolbar->AddTool(ID_BUTTONCONNECT10333, wxT("...")L"...", m_tblist.GetBitmap(0)); |
| 1300 | |
| 1301 | wndToolbar->AddSeparator(); |
| 1302 | wndToolbar->AddTool(ID_BUTTONNETWORKS10334, _("Networks")wxGetTranslation(("Networks")), m_tblist.GetBitmap(3), wxNullBitmap, wxITEM_CHECK, _("Networks Window")wxGetTranslation(("Networks Window"))); |
| 1303 | wndToolbar->AddTool(ID_BUTTONSEARCH10335, _("Searches")wxGetTranslation(("Searches")), m_tblist.GetBitmap(5), wxNullBitmap, wxITEM_CHECK, _("Searches Window")wxGetTranslation(("Searches Window"))); |
| 1304 | wndToolbar->AddTool(ID_BUTTONDOWNLOADS10336, _("Downloads")wxGetTranslation(("Downloads")), m_tblist.GetBitmap(4), wxNullBitmap, wxITEM_CHECK, _("Downloads Window")wxGetTranslation(("Downloads Window"))); |
| 1305 | wndToolbar->AddTool(ID_BUTTONSHARED10337, _("Shared files")wxGetTranslation(("Shared files")), m_tblist.GetBitmap(6), wxNullBitmap, wxITEM_CHECK, _("Shared Files Window")wxGetTranslation(("Shared Files Window"))); |
| 1306 | wndToolbar->AddTool(ID_BUTTONMESSAGES10338, _("Messages")wxGetTranslation(("Messages")), m_tblist.GetBitmap(7), wxNullBitmap, wxITEM_CHECK, _("Messages Window")wxGetTranslation(("Messages Window"))); |
| 1307 | wndToolbar->AddTool(ID_BUTTONSTATISTICS10339, _("Statistics")wxGetTranslation(("Statistics")), m_tblist.GetBitmap(8), wxNullBitmap, wxITEM_CHECK, _("Statistics Graph Window")wxGetTranslation(("Statistics Graph Window"))); |
| 1308 | wndToolbar->AddSeparator(); |
| 1309 | wndToolbar->AddTool(ID_BUTTONNEWPREFERENCES10340, _("Preferences")wxGetTranslation(("Preferences")), m_tblist.GetBitmap(9), wxNullBitmap, wxITEM_NORMAL, _("Preferences Settings Window")wxGetTranslation(("Preferences Settings Window"))); |
| 1310 | #ifndef CLIENT_GUI |
| 1311 | wndToolbar->AddTool(ID_BUTTONIMPORT10341, _("Import")wxGetTranslation(("Import")), m_tblist.GetBitmap(10), wxNullBitmap, wxITEM_NORMAL, _("The partfile importer tool")wxGetTranslation(("The partfile importer tool"))); |
| 1312 | #endif |
| 1313 | wndToolbar->AddTool(ID_ABOUT10342, _("About")wxGetTranslation(("About")), m_tblist.GetBitmap(11), wxNullBitmap, wxITEM_NORMAL, _("About/Help")wxGetTranslation(("About/Help"))); |
| 1314 | |
| 1315 | wndToolbar->ToggleTool(ID_BUTTONDOWNLOADS10336, true); |
| 1316 | |
| 1317 | // Needed for non-GTK platforms, where the |
| 1318 | // items don't get added immediately. |
| 1319 | wndToolbar->Realize(); |
| 1320 | |
| 1321 | // Updates the "Connect" button, and so on. |
| 1322 | ShowConnectionState(true); |
| 1323 | } |
| 1324 | |
| 1325 | |
| 1326 | void CamuleDlg::Create_Toolbar(bool orientation) |
| 1327 | { |
| 1328 | Freeze(); |
| 1329 | // Create ToolBar from the one designed by wxDesigner (BigBob) |
| 1330 | wxToolBar *current = GetToolBar(); |
| 1331 | |
| 1332 | wxASSERT(current == m_wndToolbar)do { if ( current == m_wndToolbar ) { } else if ( wxTheAssertHandler && (wxOnAssert("amuleDlg.cpp", 1332, __FUNCTION__, "current == m_wndToolbar" , (const char*)__null), wxTrapInAssert) ) { wxTrapInAssert = false ; asm volatile ("int $3"); } } while ( (void)0, 0 ); |
| 1333 | |
| 1334 | if (current) { |
| 1335 | bool oldorientation = ((current->GetWindowStyle() & wxTB_VERTICAL) == wxTB_VERTICAL); |
| 1336 | if (oldorientation != orientation) { |
| 1337 | current->Destroy(); |
| 1338 | SetToolBar(NULL__null); // Remove old one if present |
| 1339 | m_wndToolbar = NULL__null; |
| 1340 | } else { |
| 1341 | current->ClearTools(); |
| 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | if (!m_wndToolbar) { |
| 1346 | m_wndToolbar = CreateToolBar((orientation ? wxTB_VERTICAL : wxTB_HORIZONTAL) | |
| 1347 | wxNO_BORDERwxBORDER_NONE | wxTB_TEXT | wxTB_FLAT | |
| 1348 | wxCLIP_CHILDREN0x00400000 | wxTB_NODIVIDER); |
| 1349 | |
| 1350 | m_wndToolbar->SetToolBitmapSize(wxSize(32, 32)); |
| 1351 | } |
| 1352 | |
| 1353 | Apply_Toolbar_Skin(m_wndToolbar); |
| 1354 | |
| 1355 | Thaw(); |
| 1356 | } |
| 1357 | |
| 1358 | |
| 1359 | void CamuleDlg::OnMainGUISizeChange(wxSizeEvent& evt) |
| 1360 | { |
| 1361 | wxFrame::OnSize(evt); |
| 1362 | if (m_transferwnd && m_transferwnd->clientlistctrl) { |
| 1363 | // Transfer window's splitter set again if it's hidden. |
| 1364 | if (!m_transferwnd->clientlistctrl->GetShowing()) { |
| 1365 | int height = m_transferwnd->clientlistctrl->GetSize().GetHeight(); |
| 1366 | wxSplitterWindow* splitter = |
| 1367 | CastChild(wxT("splitterWnd"), wxSplitterWindow)dynamic_cast<wxSplitterWindow*>( FindWindow( L"splitterWnd" ) ); |
| 1368 | height += splitter->GetWindow1()->GetSize().GetHeight(); |
| 1369 | splitter->SetSashPosition( height ); |
| 1370 | } |
| 1371 | } |
| 1372 | } |
| 1373 | |
| 1374 | |
| 1375 | void CamuleDlg::OnKeyPressed(wxKeyEvent& event) |
| 1376 | { |
| 1377 | if (event.GetKeyCode() == WXK_F1) { |
| 1378 | // Ctrl/Alt/Shift must not be pressed, to avoid |
| 1379 | // conflicts with other (global) shortcuts. |
| 1380 | if (!event.HasModifiers() && !event.ShiftDown()) { |
| 1381 | LaunchUrl(wxT("http://wiki.amule.org")L"http://wiki.amule.org"); |
| 1382 | return; |
| 1383 | } |
| 1384 | } |
| 1385 | |
| 1386 | event.Skip(); |
| 1387 | } |
| 1388 | |
| 1389 | |
| 1390 | void CamuleDlg::OnExit(wxCommandEvent& WXUNUSED(evt)) |
| 1391 | { |
| 1392 | Close(true); |
| 1393 | } |
| 1394 | |
| 1395 | void CamuleDlg::DoNetworkRearrange() |
| 1396 | { |
| 1397 | #if !defined(__WXOSX_COCOA__) |
| 1398 | // in Mac OS with wxWidgets >= 3.0 and COCOA the following seems to cause problems |
| 1399 | // (window is not refreshed after changes in network settings) |
| 1400 | wxWindowUpdateLocker freezer(this); |
| 1401 | #endif |
| 1402 | |
| 1403 | wxToolBarToolBase* toolbarTool = m_wndToolbar->FindById(ID_BUTTONNETWORKS10334); |
| 1404 | |
| 1405 | // set the log windows |
| 1406 | wxNotebook* logs_notebook = CastChild( ID_SRVLOG_NOTEBOOK, wxNotebook)dynamic_cast<wxNotebook*>( FindWindow( 10252 ) ); |
| 1407 | |
| 1408 | while (logs_notebook->GetPageCount() > 1) { |
| 1409 | logs_notebook->RemovePage(logs_notebook->GetPageCount() - 1); |
| 1410 | } |
| 1411 | |
| 1412 | if (thePrefs::GetNetworkED2K()) { |
| 1413 | #ifndef CLIENT_GUI |
| 1414 | logs_notebook->AddPage(m_logpages[1].page, m_logpages[1].name); |
| 1415 | #endif |
| 1416 | logs_notebook->AddPage(m_logpages[2].page, m_logpages[2].name); |
| 1417 | } |
| 1418 | |
| 1419 | if (thePrefs::GetNetworkKademlia()) { |
| 1420 | logs_notebook->AddPage(m_logpages[3].page, m_logpages[3].name); |
| 1421 | } |
| 1422 | |
| 1423 | // Set the main window. |
| 1424 | // If we have both networks active, activate a notebook to select between them. |
| 1425 | // If only one is active, show the window directly without a surrounding one tab notebook. |
| 1426 | |
| 1427 | // States: |
| 1428 | // 1: ED2K only |
| 1429 | // 2: Kad only |
| 1430 | // 3: both (in Notebook) |
| 1431 | |
| 1432 | static uint8 currentState = 3; // on startup we have both enabled |
| 1433 | uint8 newState; |
| 1434 | if (thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia()) { |
| 1435 | newState = 3; |
| 1436 | toolbarTool->SetLabel(_("Networks")wxGetTranslation(("Networks"))); |
| 1437 | } |
| 1438 | else if (thePrefs::GetNetworkED2K()) { |
| 1439 | newState = 1; |
| 1440 | toolbarTool->SetLabel(_("eD2k network")wxGetTranslation(("eD2k network"))); |
| 1441 | } |
| 1442 | else { // Kad only or no network |
| 1443 | newState = 2; // no network makes no sense anyway, so just show Kad there |
| 1444 | toolbarTool->SetLabel(thePrefs::GetNetworkKademlia() ? _("Kad network")wxGetTranslation(("Kad network")) : _("No network")wxGetTranslation(("No network"))); |
| 1445 | } |
| 1446 | |
| 1447 | if (newState != currentState) { |
| 1448 | wxNotebook* networks_notebook = CastChild(ID_NETNOTEBOOK, wxNotebook)dynamic_cast<wxNotebook*>( FindWindow( 10317 ) ); |
| 1449 | // First hide all windows |
| 1450 | networks_notebook->Show(false); |
| 1451 | m_networkpages[0].page->Show(false); |
| 1452 | m_networkpages[1].page->Show(false); |
| 1453 | m_networknotebooksizer->Clear(); |
| 1454 | |
| 1455 | wxWindow* replacement = NULL__null; |
| 1456 | |
| 1457 | // Move both pages into the notebook if they aren't already there. |
| 1458 | if (currentState == 1) { // ED2K |
| 1459 | m_networkpages[0].page->Reparent(networks_notebook); |
| 1460 | networks_notebook->InsertPage(0, m_networkpages[0].page, m_networkpages[0].name); |
| 1461 | } else if (currentState == 2) { // Kad |
| 1462 | m_networkpages[1].page->Reparent(networks_notebook); |
| 1463 | networks_notebook->AddPage(m_networkpages[1].page, m_networkpages[1].name); |
| 1464 | } |
| 1465 | |
| 1466 | // Now both pages are in the notebook. If we want to show one of them outside, move it back out again. |
| 1467 | // Windows that are part of a notebook can't be reparented. |
| 1468 | if (newState == 3) { |
| 1469 | // Since we messed with the notebook, we now have to show both pages, one after the other. |
| 1470 | // Otherwise GTK gets confused and shows the first tab only. |
| 1471 | // (So much for "platform independent".) |
| 1472 | networks_notebook->SetSelection(1); |
| 1473 | m_networkpages[1].page->Show(); |
| 1474 | networks_notebook->SetSelection(0); |
| 1475 | m_networkpages[0].page->Show(); |
| 1476 | replacement = networks_notebook; |
| 1477 | } else if (newState == 1) { |
| 1478 | replacement = m_networkpages[0].page; |
| 1479 | networks_notebook->RemovePage(0); |
| 1480 | } else { |
| 1481 | replacement = m_networkpages[1].page; |
| 1482 | networks_notebook->RemovePage(1); |
| 1483 | } |
| 1484 | |
| 1485 | replacement->Reparent(m_networknotebooksizer->GetContainingWindow()); |
| 1486 | replacement->Show(); |
| 1487 | m_networknotebooksizer->Add(replacement, 1, wxGROW | wxALIGN_CENTER_VERTICAL | wxTOP, 5); |
| 1488 | m_networknotebooksizer->Layout(); |
| 1489 | currentState = newState; |
| 1490 | } |
| 1491 | |
| 1492 | // Tool bar |
| 1493 | |
| 1494 | m_wndToolbar->EnableTool(ID_BUTTONNETWORKS10334, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia())); |
| 1495 | m_wndToolbar->EnableTool(ID_BUTTONCONNECT10333, (thePrefs::GetNetworkED2K() || thePrefs::GetNetworkKademlia()) && theApp->ipfilter->IsReady()); |
| 1496 | |
| 1497 | ShowConnectionState(); // status in the bottom right |
| 1498 | m_searchwnd->FixSearchTypes(); |
| 1499 | } |
| 1500 | |
| 1501 | // File_checked_for_headers |