| File: | rootdir/src/amule-gui.cpp |
| Warning: | line 301, column 3 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) 2004-2011 aMule Team ( admin@amule.org / http://www.amule.org ) |
| 5 | // |
| 6 | // Any parts of this program derived from the xMule, lMule or eMule project, |
| 7 | // or contributed by third-party developers are copyrighted by their |
| 8 | // respective authors. |
| 9 | // |
| 10 | // This program is free software; you can redistribute it and/or modify |
| 11 | // it under the terms of the GNU General Public License as published by |
| 12 | // the Free Software Foundation; either version 2 of the License, or |
| 13 | // (at your option) any later version. |
| 14 | // |
| 15 | // This program is distributed in the hope that it will be useful, |
| 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | // GNU General Public License for more details. |
| 19 | // |
| 20 | // You should have received a copy of the GNU General Public License |
| 21 | // along with this program; if not, write to the Free Software |
| 22 | // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
| 23 | // |
| 24 | |
| 25 | #include "amule.h" // Interface declarations. |
| 26 | |
| 27 | #include <common/EventIDs.h> |
| 28 | #include <common/ClientVersion.h> |
| 29 | |
| 30 | #include <wx/clipbrd.h> // Needed for wxClipBoard |
| 31 | #include <wx/sizer.h> |
| 32 | #include <wx/tokenzr.h> // Needed for wxStringTokenizer |
| 33 | |
| 34 | #include "SharedFilesWnd.h" // Needed for CSharedFilesWnd |
| 35 | #include "Timer.h" // Needed for CTimer |
| 36 | #include "PartFile.h" // Needed for CPartFile |
| 37 | |
| 38 | #include "muuli_wdr.h" // Needed for IDs |
| 39 | #include "amuleDlg.h" // Needed for CamuleDlg |
| 40 | #include "PartFileConvert.h" |
| 41 | #include "ThreadTasks.h" |
| 42 | #include "Logger.h" // Needed for EVT_MULE_LOGGING |
| 43 | #include "GuiEvents.h" // Needed for EVT_MULE_NOTIFY |
| 44 | |
| 45 | #ifdef __WXMAC__ |
| 46 | #include <CoreFoundation/CFBundle.h> // Do_not_auto_remove |
| 47 | #include <ApplicationServices/ApplicationServices.h> // For LSRegisterURL // Do_not_auto_remove |
| 48 | #endif |
| 49 | |
| 50 | #ifndef CLIENT_GUI |
| 51 | #include "InternalEvents.h" // Needed for wxEVT_* |
| 52 | |
| 53 | BEGIN_EVENT_TABLE(CamuleGuiApp, wxApp)const wxEventTable CamuleGuiApp::sm_eventTable = { &wxApp ::sm_eventTable, &CamuleGuiApp::sm_eventTableEntries[0] } ; const wxEventTable *CamuleGuiApp::GetEventTable() const { return &CamuleGuiApp::sm_eventTable; } wxEventHashTable CamuleGuiApp ::sm_eventHashTable(CamuleGuiApp::sm_eventTable); wxEventHashTable &CamuleGuiApp::GetEventHashTable() const { return CamuleGuiApp ::sm_eventHashTable; } const wxEventTableEntry CamuleGuiApp:: sm_eventTableEntries[] = { |
| 54 | |
| 55 | #ifndef ASIO_SOCKETS |
| 56 | // Socket handlers |
| 57 | // Listen Socket |
| 58 | EVT_SOCKET(ID_LISTENSOCKET_EVENT, CamuleGuiApp::ListenSocketHandler)wxEventTableEntry(wxEVT_SOCKET, ID_LISTENSOCKET_EVENT, wxID_ANY , wxNewEventTableFunctor(wxEVT_SOCKET, wxEventFunctionCast(wxPrivate ::DoCast<wxPrivate::EventArgOf<wxSocketEventFunction> ::type>(&CamuleGuiApp::ListenSocketHandler))), __null) , |
| 59 | |
| 60 | // UDP Socket (servers) |
| 61 | EVT_SOCKET(ID_SERVERUDPSOCKET_EVENT, CamuleGuiApp::UDPSocketHandler)wxEventTableEntry(wxEVT_SOCKET, ID_SERVERUDPSOCKET_EVENT, wxID_ANY , wxNewEventTableFunctor(wxEVT_SOCKET, wxEventFunctionCast(wxPrivate ::DoCast<wxPrivate::EventArgOf<wxSocketEventFunction> ::type>(&CamuleGuiApp::UDPSocketHandler))), __null), |
| 62 | // UDP Socket (clients) |
| 63 | EVT_SOCKET(ID_CLIENTUDPSOCKET_EVENT, CamuleGuiApp::UDPSocketHandler)wxEventTableEntry(wxEVT_SOCKET, ID_CLIENTUDPSOCKET_EVENT, wxID_ANY , wxNewEventTableFunctor(wxEVT_SOCKET, wxEventFunctionCast(wxPrivate ::DoCast<wxPrivate::EventArgOf<wxSocketEventFunction> ::type>(&CamuleGuiApp::UDPSocketHandler))), __null), |
| 64 | #endif |
| 65 | |
| 66 | // Socket timers (TCP + UDP) |
| 67 | EVT_MULE_TIMER(ID_SERVER_RETRY_TIMER_EVENT, CamuleGuiApp::OnTCPTimer)wxEventTableEntry(MULE_EVT_TIMER, ID_SERVER_RETRY_TIMER_EVENT , -1, wxNewEventTableFunctor(MULE_EVT_TIMER, (wxObjectEventFunction ) (wxEventFunction) static_cast<MuleTimerEventFunction> (&CamuleGuiApp::OnTCPTimer)), (wxObject*) __null), |
| 68 | |
| 69 | // Core timer |
| 70 | EVT_MULE_TIMER(ID_CORE_TIMER_EVENT, CamuleGuiApp::OnCoreTimer)wxEventTableEntry(MULE_EVT_TIMER, ID_CORE_TIMER_EVENT, -1, wxNewEventTableFunctor (MULE_EVT_TIMER, (wxObjectEventFunction) (wxEventFunction) static_cast <MuleTimerEventFunction>(&CamuleGuiApp::OnCoreTimer )), (wxObject*) __null), |
| 71 | |
| 72 | EVT_MULE_NOTIFY(CamuleGuiApp::OnNotifyEvent)wxEventTableEntry(MULE_EVT_NOTIFY, -1, -1, wxNewEventTableFunctor (MULE_EVT_NOTIFY, (wxObjectEventFunction) (wxEventFunction) static_cast <MuleNotifyEventFunction>(&CamuleGuiApp::OnNotifyEvent )), (wxObject*) __null), |
| 73 | |
| 74 | // Async dns handling |
| 75 | EVT_MULE_INTERNAL(wxEVT_CORE_UDP_DNS_DONE, -1, CamuleGuiApp::OnUDPDnsDone)wxEventTableEntry(wxEVT_CORE_UDP_DNS_DONE, -1, -1, wxNewEventTableFunctor (wxEVT_CORE_UDP_DNS_DONE, (wxObjectEventFunction) (wxEventFunction ) static_cast<MuleInternalEventFunction>(&CamuleGuiApp ::OnUDPDnsDone)), (wxObject*) __null), |
| 76 | |
| 77 | EVT_MULE_INTERNAL(wxEVT_CORE_SOURCE_DNS_DONE, -1, CamuleGuiApp::OnSourceDnsDone)wxEventTableEntry(wxEVT_CORE_SOURCE_DNS_DONE, -1, -1, wxNewEventTableFunctor (wxEVT_CORE_SOURCE_DNS_DONE, (wxObjectEventFunction) (wxEventFunction ) static_cast<MuleInternalEventFunction>(&CamuleGuiApp ::OnSourceDnsDone)), (wxObject*) __null), |
| 78 | |
| 79 | EVT_MULE_INTERNAL(wxEVT_CORE_SERVER_DNS_DONE, -1, CamuleGuiApp::OnServerDnsDone)wxEventTableEntry(wxEVT_CORE_SERVER_DNS_DONE, -1, -1, wxNewEventTableFunctor (wxEVT_CORE_SERVER_DNS_DONE, (wxObjectEventFunction) (wxEventFunction ) static_cast<MuleInternalEventFunction>(&CamuleGuiApp ::OnServerDnsDone)), (wxObject*) __null), |
| 80 | |
| 81 | // Hash ended notifier |
| 82 | EVT_MULE_HASHING(CamuleGuiApp::OnFinishedHashing)wxEventTableEntry(MULE_EVT_HASHING, -1, -1, wxNewEventTableFunctor (MULE_EVT_HASHING, (wxObjectEventFunction) (wxEventFunction) static_cast <MuleHashingEventFunction>(&CamuleGuiApp::OnFinishedHashing )), (wxObject*) __null), |
| 83 | EVT_MULE_AICH_HASHING(CamuleGuiApp::OnFinishedAICHHashing)wxEventTableEntry(MULE_EVT_AICH_HASHING, -1, -1, wxNewEventTableFunctor (MULE_EVT_AICH_HASHING, (wxObjectEventFunction) (wxEventFunction ) static_cast<MuleHashingEventFunction>(&CamuleGuiApp ::OnFinishedAICHHashing)), (wxObject*) __null), |
| 84 | |
| 85 | // File completion ended notifier |
| 86 | EVT_MULE_FILE_COMPLETED(CamuleGuiApp::OnFinishedCompletion)wxEventTableEntry(MULE_EVT_FILE_COMPLETED, -1, -1, wxNewEventTableFunctor (MULE_EVT_FILE_COMPLETED, (wxObjectEventFunction) (wxEventFunction ) static_cast<MuleCompletionEventFunction>(&CamuleGuiApp ::OnFinishedCompletion)), (wxObject*) __null), |
| 87 | |
| 88 | // HTTPDownload finished |
| 89 | EVT_MULE_INTERNAL(wxEVT_CORE_FINISHED_HTTP_DOWNLOAD, -1, CamuleGuiApp::OnFinishedHTTPDownload)wxEventTableEntry(wxEVT_CORE_FINISHED_HTTP_DOWNLOAD, -1, -1, wxNewEventTableFunctor (wxEVT_CORE_FINISHED_HTTP_DOWNLOAD, (wxObjectEventFunction) ( wxEventFunction) static_cast<MuleInternalEventFunction> (&CamuleGuiApp::OnFinishedHTTPDownload)), (wxObject*) __null ), |
| 90 | |
| 91 | // Disk space preallocation finished |
| 92 | EVT_MULE_ALLOC_FINISHED(CamuleGuiApp::OnFinishedAllocation)wxEventTableEntry(MULE_EVT_ALLOC_FINISHED, -1, -1, wxNewEventTableFunctor (MULE_EVT_ALLOC_FINISHED, (wxObjectEventFunction) (wxEventFunction ) static_cast<MuleAllocFinishedEventFunction>(&CamuleGuiApp ::OnFinishedAllocation)), (wxObject*) __null), |
| 93 | END_EVENT_TABLE()wxEventTableEntry(wxEVT_NULL, 0, 0, __null, __null) }; |
| 94 | |
| 95 | |
| 96 | IMPLEMENT_APP(CamuleGuiApp)int main(int argc, char **argv) { ; ; return wxEntry(argc, argv ); } CamuleGuiApp& wxGetApp() { return *static_cast<CamuleGuiApp *>(wxApp::GetInstance()); } wxAppConsole *wxCreateApp() { wxAppConsole ::CheckBuildOptions("3" "." "2" " (" "wchar_t" ",compiler with C++ ABI compatible with gcc 4" ",wx containers" ",compatible with 3.0" ")", "your program") ; return new CamuleGuiApp; } wxAppInitializer wxTheAppInitializer ((wxAppInitializerFunction) wxCreateApp); |
| 97 | |
| 98 | #endif // CLIENT_GUI |
| 99 | |
| 100 | CamuleGuiBase::CamuleGuiBase() |
| 101 | { |
| 102 | // Disable these checks for now. The code really needs updating to |
| 103 | // eliminate these inconsistent flag uses, but these checks are new |
| 104 | // since wx3.0, and this should just return us to what 3.0 did. |
| 105 | wxSizerFlags::DisableConsistencyChecks(); |
| 106 | |
| 107 | amuledlg = NULL__null; |
| 108 | } |
| 109 | |
| 110 | |
| 111 | CamuleGuiBase::~CamuleGuiBase() |
| 112 | { |
| 113 | #ifndef CLIENT_GUI |
| 114 | CPartFileConvert::StopThread(); |
| 115 | #endif |
| 116 | } |
| 117 | |
| 118 | |
| 119 | int CamuleGuiBase::ShowAlert(wxString msg, wxString title, int flags) |
| 120 | { |
| 121 | return wxMessageBox(msg, title, flags); |
| 122 | } |
| 123 | |
| 124 | |
| 125 | int CamuleGuiBase::InitGui(bool geometry_enabled, wxString &geom_string) |
| 126 | { |
| 127 | // Standard size is 800x600 at position (0,0) |
| 128 | int geometry_x = 0; |
| 129 | int geometry_y = 0; |
| 130 | unsigned int geometry_width = 800; |
| 131 | unsigned int geometry_height = 600; |
| 132 | |
| 133 | if ( geometry_enabled ) { |
| 134 | // I plan on moving this to a separate function, as it just clutters up OnInit() |
| 135 | /* |
| 136 | This implementation might work with mac, provided that the |
| 137 | SetSize() function works as expected. |
| 138 | */ |
| 139 | |
| 140 | // Remove possible prefix |
| 141 | if ( geom_string.GetChar(0) == '=' ) { |
| 142 | geom_string.Remove( 0, 1 ); |
| 143 | } |
| 144 | |
| 145 | // Stupid ToLong functions forces me to use longs =( |
| 146 | long width = geometry_width; |
| 147 | long height = geometry_height; |
| 148 | |
| 149 | // Get the available display area |
| 150 | wxRect display = wxGetClientDisplayRect(); |
| 151 | |
| 152 | // We want to place aMule inside the client area by default |
| 153 | long x = display.x; |
| 154 | long y = display.y; |
| 155 | |
| 156 | // Tokenize the string |
| 157 | wxStringTokenizer tokens(geom_string, wxT("xX+-")L"xX+-"); |
| 158 | |
| 159 | // First part: Program width |
| 160 | if ( tokens.GetNextToken().ToLong( &width ) ) { |
| 161 | wxString prefix = geom_string[ tokens.GetPosition() - 1 ]; |
| 162 | if ( prefix == wxT("x")L"x" || prefix == wxT("X")L"X" ) { |
| 163 | // Second part: Program height |
| 164 | if ( tokens.GetNextToken().ToLong( &height ) ) { |
| 165 | prefix = geom_string[ tokens.GetPosition() - 1 ]; |
| 166 | if ( prefix == wxT("+")L"+" || prefix == wxT("-")L"-" ) { |
| 167 | // Third part: X-Offset |
| 168 | if ( tokens.GetNextToken().ToLong( &x ) ) { |
| 169 | if ( prefix == wxT("-")L"-" ) |
| 170 | x = display.GetRight() - ( width + x ); |
| 171 | prefix = geom_string[ tokens.GetPosition() - 1 ]; |
| 172 | if ( prefix == wxT("+")L"+" || prefix == wxT("-")L"-" ) { |
| 173 | // Fourth part: Y-Offset |
| 174 | if ( tokens.GetNextToken().ToLong( &y ) ) { |
| 175 | if ( prefix == wxT("-")L"-" ) |
| 176 | y = display.GetBottom() - ( height + y ); |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | // We need at least height and width to override default geometry |
| 182 | geometry_enabled = true; |
| 183 | geometry_x = x; |
| 184 | geometry_y = y; |
| 185 | geometry_width = width; |
| 186 | geometry_height = height; |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | ResetTitle(); |
| 193 | |
| 194 | // Should default/last-used position be overridden? |
| 195 | if ( geometry_enabled ) { |
| 196 | amuledlg = new CamuleDlg(NULL__null, m_FrameTitle, |
| 197 | wxPoint(geometry_x,geometry_y), |
| 198 | wxSize( geometry_width, geometry_height - 58 )); |
| 199 | } else { |
| 200 | amuledlg = new CamuleDlg(NULL__null, m_FrameTitle); |
| 201 | } |
| 202 | |
| 203 | return 0; |
| 204 | } |
| 205 | |
| 206 | // Sets m_FrameTitle |
| 207 | void CamuleGuiBase::ResetTitle() |
| 208 | { |
| 209 | #ifdef SVNDATE"rev. g20625be" |
| 210 | #ifdef CLIENT_GUI |
| 211 | m_FrameTitle = CFormat(wxT("aMule remote control %s %s")L"aMule remote control %s %s") % wxT( VERSION )L"SVN" % wxT( SVNDATE )L"rev. g20625be"; |
| 212 | #else |
| 213 | m_FrameTitle = CFormat(wxT("aMule %s %s")L"aMule %s %s") % wxT( VERSION )L"SVN" % wxT( SVNDATE )L"rev. g20625be"; |
| 214 | #endif |
| 215 | #else |
| 216 | #ifdef CLIENT_GUI |
| 217 | m_FrameTitle = _("aMule remote control")wxGetTranslation(("aMule remote control")); |
| 218 | #else |
| 219 | m_FrameTitle = _("aMule")wxGetTranslation(("aMule")); |
| 220 | #endif |
| 221 | |
| 222 | if (thePrefs::ShowVersionOnTitle()) { |
| 223 | m_FrameTitle += wxT(' ')L' '; |
| 224 | m_FrameTitle += wxT( VERSION )L"SVN"; |
| 225 | } |
| 226 | #endif |
| 227 | } |
| 228 | |
| 229 | |
| 230 | // Sets the contents of the clipboard. Prior content erased. |
| 231 | bool CamuleGuiBase::CopyTextToClipboard(wxString strText) |
| 232 | { |
| 233 | bool ClipBoardOpen = wxTheClipboard(wxClipboard::Get())->Open(); |
| 234 | if (ClipBoardOpen) { |
| 235 | wxTheClipboard(wxClipboard::Get())->UsePrimarySelection(false); |
| 236 | wxTheClipboard(wxClipboard::Get())->SetData(new wxTextDataObject(strText)); |
| 237 | wxTheClipboard(wxClipboard::Get())->Close(); |
| 238 | } |
| 239 | |
| 240 | return ClipBoardOpen; |
| 241 | } |
| 242 | |
| 243 | |
| 244 | void CamuleGuiBase::AddGuiLogLine(const wxString& line) |
| 245 | { |
| 246 | if (amuledlg) { |
| 247 | while ( !m_logLines.empty() ) { |
| 248 | amuledlg->AddLogLine(m_logLines.front()); |
| 249 | m_logLines.pop_front(); |
| 250 | } |
| 251 | amuledlg->AddLogLine(line); |
| 252 | } else { |
| 253 | m_logLines.push_back(line); |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | |
| 258 | #ifndef CLIENT_GUI |
| 259 | |
| 260 | int CamuleGuiApp::InitGui(bool geometry_enable, wxString &geometry_string) |
| 261 | { |
| 262 | CamuleGuiBase::InitGui(geometry_enable, geometry_string); |
| 263 | SetTopWindow(amuledlg); |
| 264 | return 0; |
| 265 | } |
| 266 | |
| 267 | |
| 268 | int CamuleGuiApp::ShowAlert(wxString msg, wxString title, int flags) |
| 269 | { |
| 270 | return CamuleGuiBase::ShowAlert(msg, title, flags); |
| 271 | } |
| 272 | |
| 273 | |
| 274 | int CamuleGuiApp::OnExit() |
| 275 | { |
| 276 | delete core_timer; |
| 277 | |
| 278 | return CamuleApp::OnExit(); |
| 279 | } |
| 280 | |
| 281 | |
| 282 | void CamuleGuiApp::ShutDown(wxCloseEvent &WXUNUSED(evt)) |
| 283 | { |
| 284 | amuledlg->DlgShutDown(); |
| 285 | amuledlg->Destroy(); |
| 286 | CamuleApp::ShutDown(); |
| 287 | } |
| 288 | |
| 289 | |
| 290 | bool CamuleGuiApp::OnInit() |
| 291 | { |
| 292 | amuledlg = NULL__null; |
| 293 | |
| 294 | if ( !CamuleApp::OnInit() ) { |
| 295 | return false; |
| 296 | } |
| 297 | |
| 298 | // Create the Core timer |
| 299 | core_timer = new CTimer(this,ID_CORE_TIMER_EVENT); |
| 300 | if (!core_timer) { |
| 301 | AddLogLineCS(_("Fatal Error: Failed to create Core Timer"))theLogger.AddLogLine(L"amule-gui.cpp", 301, true, logStandard , wxGetTranslation(("Fatal Error: Failed to create Core Timer" )), true); |
This statement is never executed | |
| 302 | OnExit(); |
| 303 | } |
| 304 | |
| 305 | // Start the Core and Gui timers |
| 306 | |
| 307 | // Note: wxTimer can be off by more than 10% !!! |
| 308 | // In addition to the systematic error introduced by wxTimer, we are losing |
| 309 | // timer cycles due to high CPU load. I've observed about 0.5% random loss of cycles under |
| 310 | // low load, and more than 6% lost cycles with heavy download traffic and/or other tasks |
| 311 | // in the system, such as a video player or a VMware virtual machine. |
| 312 | // The upload queue process loop has now been rewritten to compensate for timer errors. |
| 313 | // When adding functionality, assume that the timer is only approximately correct; |
| 314 | // for measurements, always use the system clock [::GetTickCount()]. |
| 315 | core_timer->Start(CORE_TIMER_PERIOD100); |
| 316 | amuledlg->StartGuiTimer(); |
| 317 | |
| 318 | #ifdef __WXMAC__ |
| 319 | // This tells the OS to notice the ed2kHelperScript.app inside aMule.app. |
| 320 | // ed2kHelperScript.app describes itself (Info.plist) as handling ed2k URLs. |
| 321 | // So, from then on the OS will know to pass ed2k URLs to the helper app. |
| 322 | CFURLRef ed2kHelperUrl = CFBundleCopyAuxiliaryExecutableURL( |
| 323 | CFBundleGetMainBundle(), CFSTR("ed2kHelperScript.app")); |
| 324 | if (ed2kHelperUrl) { |
| 325 | LSRegisterURL(ed2kHelperUrl, true); |
| 326 | CFRelease(ed2kHelperUrl); |
| 327 | } |
| 328 | #endif |
| 329 | |
| 330 | return true; |
| 331 | } |
| 332 | |
| 333 | |
| 334 | wxString CamuleGuiApp::GetLog(bool reset) |
| 335 | { |
| 336 | if ( reset ) { |
| 337 | amuledlg->ResetLog(ID_LOGVIEW10242); |
| 338 | } |
| 339 | return CamuleApp::GetLog(reset); |
| 340 | } |
| 341 | |
| 342 | |
| 343 | wxString CamuleGuiApp::GetServerLog(bool reset) |
| 344 | { |
| 345 | if ( reset ) { |
| 346 | amuledlg->ResetLog(ID_SERVERINFO10240); |
| 347 | } |
| 348 | return CamuleApp::GetServerLog(reset); |
| 349 | } |
| 350 | |
| 351 | |
| 352 | void CamuleGuiApp::AddServerMessageLine(wxString &msg) |
| 353 | { |
| 354 | amuledlg->AddServerMessageLine(msg); |
| 355 | CamuleApp::AddServerMessageLine(msg); |
| 356 | } |
| 357 | |
| 358 | #endif /* CLIENT_GUI */ |
| 359 | // File_checked_for_headers |