2 // This file is part of the aMule Project.
4 // Copyright (c) 2005-2008 aMule Team ( admin@amule.org / http://www.amule.org )
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
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.
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.
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
27 #include <wx/cmdline.h> // Needed for wxCmdLineParser
28 #include <wx/config.h> // Do_not_auto_remove (win32)
29 #include <wx/fileconf.h> // Needed for wxFileConfig
32 #include <common/Format.h>
33 #include <common/StringFunctions.h>
34 #include <common/MD5Sum.h>
37 #include <include/common/EventIDs.h>
40 #include "amule.h" // Interface declarations.
41 #include "amuleDlg.h" // Needed for CamuleDlg
42 #include "ClientCredits.h"
43 #include "SourceListCtrl.h"
44 #include "DataToText.h" // Needed for GetSoftName()
45 #include "DownloadListCtrl.h" // Needed for CDownloadListCtrl
46 #include "GuiEvents.h"
47 #ifdef ENABLE_IP2COUNTRY
48 #include "IP2Country.h" // Needed for IP2Country
50 #include "InternalEvents.h" // Needed for wxEVT_CORE_FINISHED_HTTP_DOWNLOAD
52 #include "muuli_wdr.h" // Needed for IDs
53 #include "PartFile.h" // Needed for CPartFile
54 #include "SearchDlg.h" // Needed for CSearchDlg
55 #include "Server.h" // Needed for GetListName
56 #include "ServerWnd.h" // Needed for CServerWnd
57 #include "SharedFilesCtrl.h" // Needed for CSharedFilesCtrl
58 #include "SharedFilesWnd.h" // Needed for CSharedFilesWnd
59 #include "TransferWnd.h" // Needed for CTransferWnd
60 #include "updownclient.h"
61 #include "ServerListCtrl.h" // Needed for CServerListCtrl
62 #include "ScopedPtr.h"
65 CEConnectDlg::CEConnectDlg()
67 wxDialog(theApp
->amuledlg
, -1, _("Connect to remote amule"), wxDefaultPosition
)
69 CoreConnect(this, true);
71 wxString pref_host
, pref_port
;
72 wxConfig::Get()->Read(wxT("/EC/Host"), &pref_host
, wxT("localhost"));
73 wxConfig::Get()->Read(wxT("/EC/Port"), &pref_port
, wxT("4712"));
74 wxConfig::Get()->Read(wxT("/EC/Password"), &pwd_hash
);
76 CastChild(ID_REMOTE_HOST
, wxTextCtrl
)->SetValue(pref_host
);
77 CastChild(ID_REMOTE_PORT
, wxTextCtrl
)->SetValue(pref_port
);
78 CastChild(ID_EC_PASSWD
, wxTextCtrl
)->SetValue(pwd_hash
);
84 wxString
CEConnectDlg::PassHash()
90 BEGIN_EVENT_TABLE(CEConnectDlg
, wxDialog
)
91 EVT_BUTTON(wxID_OK
, CEConnectDlg::OnOK
)
95 void CEConnectDlg::OnOK(wxCommandEvent
& evt
)
97 wxString s_port
= CastChild(ID_REMOTE_PORT
, wxTextCtrl
)->GetValue();
98 port
= StrToLong(s_port
);
100 host
= CastChild(ID_REMOTE_HOST
, wxTextCtrl
)->GetValue();
101 passwd
= CastChild(ID_EC_PASSWD
, wxTextCtrl
)->GetValue();
103 if (passwd
!= pwd_hash
) {
104 pwd_hash
= MD5Sum(passwd
).GetHash();
106 m_save_user_pass
= CastChild(ID_EC_SAVE
, wxCheckBox
)->IsChecked();
111 DEFINE_LOCAL_EVENT_TYPE(wxEVT_EC_INIT_DONE
)
114 BEGIN_EVENT_TABLE(CamuleRemoteGuiApp
, wxApp
)
116 EVT_TIMER(ID_CORE_TIMER_EVENT
, CamuleRemoteGuiApp::OnPollTimer
)
118 EVT_CUSTOM(wxEVT_EC_CONNECTION
, -1, CamuleRemoteGuiApp::OnECConnection
)
119 EVT_CUSTOM(wxEVT_EC_INIT_DONE
, -1, CamuleRemoteGuiApp::OnECInitDone
)
121 EVT_MULE_NOTIFY(CamuleRemoteGuiApp::OnNotifyEvent
)
123 #ifdef ENABLE_IP2COUNTRY
124 // HTTPDownload finished
125 EVT_MULE_INTERNAL(wxEVT_CORE_FINISHED_HTTP_DOWNLOAD
, -1, CamuleRemoteGuiApp::OnFinishedHTTPDownload
)
130 IMPLEMENT_APP(CamuleRemoteGuiApp
)
133 int CamuleRemoteGuiApp::OnExit()
137 return wxApp::OnExit();
141 void CamuleRemoteGuiApp::OnPollTimer(wxTimerEvent
&)
143 static int request_step
= 0;
145 if (m_connect
->RequestFifoFull()) {
149 switch (request_step
) {
151 serverconnect
->ReQuery();
152 serverlist
->UpdateUserFileStatus(serverconnect
->GetCurrentServer());
156 CECPacket
stats_req(EC_OP_STAT_REQ
);
157 m_connect
->SendRequest(&m_stats_updater
, &stats_req
);
158 amuledlg
->ShowTransferRate();
163 if (amuledlg
->m_sharedfileswnd
->IsShown()) {
164 // update both downloads and shared files
165 knownfiles
->DoRequery(EC_OP_GET_UPDATE
, EC_TAG_KNOWNFILE
);
166 } else if (amuledlg
->m_serverwnd
->IsShown()) {
167 //serverlist->FullReload(EC_OP_GET_SERVER_LIST);
168 } else if (amuledlg
->m_transferwnd
->IsShown()) {
169 // update both downloads and shared files
170 knownfiles
->DoRequery(EC_OP_GET_UPDATE
, EC_TAG_KNOWNFILE
);
171 if (amuledlg
->m_transferwnd
->clientlistctrl
->GetShowing()) {
172 // Kry_GUI Request the client list.
174 amuledlg
->m_transferwnd
->ShowQueueCount(theStats::GetWaitingUserCount());
175 } else if (amuledlg
->m_searchwnd
->IsShown()) {
176 if (searchlist
->m_curr_search
!= -1) {
177 searchlist
->DoRequery(EC_OP_SEARCH_RESULTS
, EC_TAG_SEARCHFILE
);
184 AddLogLineCS(wxT("WTF?")); // should not happen. :-)
188 // Check for new links once per second.
189 static uint32 lastED2KLinkCheck
= 0;
190 if (GetTickCount() - lastED2KLinkCheck
>= 1000) {
192 lastED2KLinkCheck
= GetTickCount();
197 void CamuleRemoteGuiApp::OnFinishedHTTPDownload(CMuleInternalEvent
& event
)
199 #ifdef ENABLE_IP2COUNTRY
200 if (event
.GetInt() == HTTP_GeoIP
) {
201 amuledlg
->IP2CountryDownloadFinished(event
.GetExtraLong());
202 // If we updated, the dialog is already up. Redraw it to show the flags.
209 void CamuleRemoteGuiApp::ShutDown(wxCloseEvent
&WXUNUSED(evt
))
211 // Stop the Core Timer
215 // Destroy the EC socket
216 m_connect
->Destroy();
221 amuledlg
->DlgShutDown();
228 bool CamuleRemoteGuiApp::OnInit()
234 theApp
= &wxGetApp();
236 // Handle uncaught exceptions
237 InstallMuleExceptionHandler();
239 // Parse cmdline arguments.
240 if (!InitCommon(AMULE_APP_BASE::argc
, AMULE_APP_BASE::argv
)) {
244 // Create the polling timer
245 poll_timer
= new wxTimer(this,ID_CORE_TIMER_EVENT
);
247 AddLogLineCS(_("Fatal Error: Failed to create Poll Timer"));
251 m_connect
= new CRemoteConnect(this);
253 glob_prefs
= new CPreferencesRem(m_connect
);
255 wxConfig::Get()->Read(wxT("/EC/ZLIB"), &enableZLIB
, 1);
256 m_connect
->SetCapabilities(enableZLIB
!= 0, true, false); // ZLIB, UTF8 numbers, notification
258 InitCustomLanguages();
259 InitLocale(m_locale
, StrLang2wx(thePrefs::GetLanguageID()));
261 if (ShowConnectionDialog()) {
262 AddLogLineNS(_("Going to event loop..."));
270 bool CamuleRemoteGuiApp::CryptoAvailable() const
272 return thePrefs::IsSecureIdentEnabled(); // good enough
276 bool CamuleRemoteGuiApp::ShowConnectionDialog()
278 dialog
= new CEConnectDlg
;
280 if (m_skipConnectionDialog
) {
283 } else if (dialog
->ShowModal() != wxID_OK
) {
288 AddLogLineNS(_("Connecting..."));
289 if (!m_connect
->ConnectToCore(dialog
->Host(), dialog
->Port(),
290 dialog
->Login(), dialog
->PassHash(),
291 wxT("amule-remote"), wxT("0x0001"))) {
292 wxMessageBox(_("Connection failed "),_("ERROR"),wxOK
);
301 void CamuleRemoteGuiApp::OnECConnection(wxEvent
& event
) {
302 wxECSocketEvent
& evt
= *((wxECSocketEvent
*)&event
);
303 AddLogLineNS(_("Remote GUI EC event handler"));
304 wxString reply
= evt
.GetServerReply();
305 AddLogLineM(true, reply
);
306 if (evt
.GetResult() == true) {
307 // Connected - go to next init step
308 glob_prefs
->LoadRemote();
310 AddLogLineNS(_("Going down"));
311 if (dialog
) { // connect failed
313 (CFormat(_("Connection Failed. Unable to connect to %s:%d\n")) % dialog
->Host() % dialog
->Port()) + reply
,
315 } else { // server disconnected (probably terminated) later
316 wxMessageBox(_("Connection closed - aMule has terminated probably."), _("ERROR"), wxOK
);
323 void CamuleRemoteGuiApp::OnECInitDone(wxEvent
& )
329 void CamuleRemoteGuiApp::OnNotifyEvent(CMuleGUIEvent
& evt
)
335 void CamuleRemoteGuiApp::Startup() {
337 if (dialog
->SaveUserPass()) {
338 wxConfig::Get()->Write(wxT("/EC/Host"), dialog
->Host());
339 wxConfig::Get()->Write(wxT("/EC/Port"), dialog
->Port());
340 wxConfig::Get()->Write(wxT("/EC/Password"), dialog
->PassHash());
348 serverconnect
= new CServerConnectRem(m_connect
);
349 m_statistics
= new CStatistics(*m_connect
);
351 clientlist
= new CClientListRem(m_connect
);
352 searchlist
= new CSearchListRem(m_connect
);
353 serverlist
= new CServerListRem(m_connect
);
355 sharedfiles
= new CSharedFilesRem(m_connect
);
356 knownfiles
= new CKnownFilesRem(m_connect
);
358 // bugfix - do this before creating the uploadqueue
359 downloadqueue
= new CDownQueueRem(m_connect
);
360 uploadqueue
= new CUpQueueRem(m_connect
);
361 ipfilter
= new CIPFilterRem(m_connect
);
363 // Create main dialog
364 InitGui(m_geometryEnabled
, m_geometryString
);
366 // Forward wxLog events to CLogger
367 wxLog::SetActiveTarget(new CLoggerTarget
);
368 serverlist
->FullReload(EC_OP_GET_SERVER_LIST
);
369 knownfiles
->DoRequery(EC_OP_GET_UPDATE
, EC_TAG_KNOWNFILE
);
371 // Start the Poll Timer
372 poll_timer
->Start(1000);
373 amuledlg
->StartGuiTimer();
375 // Now activate GeoIP, so that the download dialog doesn't get destroyed immediately
376 #ifdef ENABLE_IP2COUNTRY
377 if (thePrefs::IsGeoIPEnabled()) {
378 amuledlg
->m_IP2Country
->Enable();
384 int CamuleRemoteGuiApp::ShowAlert(wxString msg
, wxString title
, int flags
)
386 return CamuleGuiBase::ShowAlert(msg
, title
, flags
);
390 void CamuleRemoteGuiApp::AddRemoteLogLine(const wxString
& line
)
392 amuledlg
->AddLogLine(line
);
395 int CamuleRemoteGuiApp::InitGui(bool geometry_enabled
, wxString
&geom_string
)
397 CamuleGuiBase::InitGui(geometry_enabled
, geom_string
);
398 SetTopWindow(amuledlg
);
399 AddLogLineN(_("Ready")); // The first log line after the window is up triggers output of all the ones before
404 bool CamuleRemoteGuiApp::CopyTextToClipboard(wxString strText
)
406 return CamuleGuiBase::CopyTextToClipboard(strText
);
410 uint32
CamuleRemoteGuiApp::GetPublicIP()
416 wxString
CamuleRemoteGuiApp::GetLog(bool)
418 return wxEmptyString
;
422 wxString
CamuleRemoteGuiApp::GetServerLog(bool)
424 return wxEmptyString
;
428 bool CamuleRemoteGuiApp::AddServer(CServer
*, bool)
430 // #warning TODO: Add remote command
435 bool CamuleRemoteGuiApp::IsFirewalled() const
437 if (IsConnectedED2K() && !serverconnect
->IsLowID()) {
441 return IsFirewalledKad();
445 bool CamuleRemoteGuiApp::IsConnectedED2K() const {
446 return serverconnect
&& serverconnect
->IsConnected();
450 void CamuleRemoteGuiApp::StartKad() {
451 m_connect
->StartKad();
455 void CamuleRemoteGuiApp::StopKad() {
456 m_connect
->StopKad();
460 void CamuleRemoteGuiApp::BootstrapKad(uint32 ip
, uint16 port
)
462 CECPacket
req(EC_OP_KAD_BOOTSTRAP_FROM_IP
);
463 req
.AddTag(CECTag(EC_TAG_BOOTSTRAP_IP
, ip
));
464 req
.AddTag(CECTag(EC_TAG_BOOTSTRAP_PORT
, port
));
466 m_connect
->SendPacket(&req
);
470 void CamuleRemoteGuiApp::UpdateNotesDat(const wxString
& url
)
472 CECPacket
req(EC_OP_KAD_UPDATE_FROM_URL
);
473 req
.AddTag(CECTag(EC_TAG_KADEMLIA_UPDATE_URL
, url
));
475 m_connect
->SendPacket(&req
);
479 void CamuleRemoteGuiApp::DisconnectED2K() {
480 if (IsConnectedED2K()) {
481 m_connect
->DisconnectED2K();
486 uint32
CamuleRemoteGuiApp::GetED2KID() const
488 return serverconnect
? serverconnect
->GetClientID() : 0;
492 uint32
CamuleRemoteGuiApp::GetID() const
498 void CamuleRemoteGuiApp::ShowUserCount() {
501 static const wxString s_singlenetstatusformat
= _("Users: %s | Files: %s");
502 static const wxString s_bothnetstatusformat
= _("Users: E: %s K: %s | Files: E: %s K: %s");
504 if (thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia()) {
505 buffer
= CFormat(s_bothnetstatusformat
) % CastItoIShort(theStats::GetED2KUsers()) % CastItoIShort(theStats::GetKadUsers()) % CastItoIShort(theStats::GetED2KFiles()) % CastItoIShort(theStats::GetKadFiles());
506 } else if (thePrefs::GetNetworkED2K()) {
507 buffer
= CFormat(s_singlenetstatusformat
) % CastItoIShort(theStats::GetED2KUsers()) % CastItoIShort(theStats::GetED2KFiles());
508 } else if (thePrefs::GetNetworkKademlia()) {
509 buffer
= CFormat(s_singlenetstatusformat
) % CastItoIShort(theStats::GetKadUsers()) % CastItoIShort(theStats::GetKadFiles());
511 buffer
= _("No networks selected");
514 Notify_ShowUserCount(buffer
);
519 * Preferences: holds both local and remote settings.
521 * First, everything is loaded from local config file. Later, settings
522 * that are relevant on remote side only are loaded thru EC
524 CPreferencesRem::CPreferencesRem(CRemoteConnect
*conn
)
529 // Settings queried from remote side
531 m_exchange_send_selected_prefs
=
533 EC_PREFS_CONNECTIONS
|
534 EC_PREFS_MESSAGEFILTER
|
539 EC_PREFS_DIRECTORIES
|
541 EC_PREFS_CORETWEAKS
|
542 EC_PREFS_REMOTECONTROLS
|
544 m_exchange_recv_selected_prefs
=
545 m_exchange_send_selected_prefs
|
550 void CPreferencesRem::HandlePacket(const CECPacket
*packet
)
552 ((CEC_Prefs_Packet
*)packet
)->Apply();
554 const CECTag
*cat_tags
= packet
->GetTagByName(EC_TAG_PREFS_CATEGORIES
);
556 for (CECTag::const_iterator it
= cat_tags
->begin(); it
!= cat_tags
->end(); it
++) {
557 const CECTag
&cat_tag
= *it
;
558 Category_Struct
*cat
= new Category_Struct
;
559 cat
->title
= cat_tag
.GetTagByName(EC_TAG_CATEGORY_TITLE
)->GetStringData();
560 cat
->path
= CPath(cat_tag
.GetTagByName(EC_TAG_CATEGORY_PATH
)->GetStringData());
561 cat
->comment
= cat_tag
.GetTagByName(EC_TAG_CATEGORY_COMMENT
)->GetStringData();
562 cat
->color
= cat_tag
.GetTagByName(EC_TAG_CATEGORY_COLOR
)->GetInt();
563 cat
->prio
= cat_tag
.GetTagByName(EC_TAG_CATEGORY_PRIO
)->GetInt();
564 theApp
->glob_prefs
->AddCat(cat
);
567 Category_Struct
*cat
= new Category_Struct
;
568 cat
->title
= _("All");
570 cat
->prio
= PR_NORMAL
;
571 theApp
->glob_prefs
->AddCat(cat
);
573 wxECInitDoneEvent event
;
574 theApp
->AddPendingEvent(event
);
579 bool CPreferencesRem::LoadRemote()
582 // override local settings with remote
583 CECPacket
req(EC_OP_GET_PREFERENCES
, EC_DETAIL_UPDATE
);
585 // bring categories too
586 req
.AddTag(CECTag(EC_TAG_SELECT_PREFS
, m_exchange_recv_selected_prefs
));
588 m_conn
->SendRequest(this, &req
);
594 void CPreferencesRem::SendToRemote()
596 CEC_Prefs_Packet
pref_packet(m_exchange_send_selected_prefs
, EC_DETAIL_UPDATE
, EC_DETAIL_FULL
);
597 m_conn
->SendPacket(&pref_packet
);
601 class CCatHandler
: public CECPacketHandlerBase
{
602 virtual void HandlePacket(const CECPacket
*packet
);
606 void CCatHandler::HandlePacket(const CECPacket
*packet
)
608 if (packet
->GetOpCode() == EC_OP_FAILED
) {
609 const CECTag
* catTag
= packet
->GetTagByName(EC_TAG_CATEGORY
);
610 const CECTag
* pathTag
= packet
->GetTagByName(EC_TAG_CATEGORY_PATH
);
611 if (catTag
&& pathTag
&& catTag
->GetInt() < theApp
->glob_prefs
->GetCatCount()) {
612 int cat
= catTag
->GetInt();
613 Category_Struct
* cs
= theApp
->glob_prefs
->GetCategory(cat
);
614 wxMessageBox(CFormat(_("Can't create directory '%s' for category '%s', keeping directory '%s'."))
615 % cs
->path
.GetPrintable() % cs
->title
% pathTag
->GetStringData(),
617 cs
->path
= CPath(pathTag
->GetStringData());
618 theApp
->amuledlg
->m_transferwnd
->UpdateCategory(cat
);
619 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->Refresh();
626 bool CPreferencesRem::CreateCategory(
627 Category_Struct
*& category
,
628 const wxString
& name
,
630 const wxString
& comment
,
634 CECPacket
req(EC_OP_CREATE_CATEGORY
);
635 CEC_Category_Tag
tag(0xffffffff, name
, path
.GetRaw(), comment
, color
, prio
);
637 m_conn
->SendRequest(new CCatHandler
, &req
);
639 category
= new Category_Struct();
640 category
->path
= path
;
641 category
->title
= name
;
642 category
->comment
= comment
;
643 category
->color
= color
;
644 category
->prio
= prio
;
652 bool CPreferencesRem::UpdateCategory(
654 const wxString
& name
,
656 const wxString
& comment
,
660 CECPacket
req(EC_OP_UPDATE_CATEGORY
);
661 CEC_Category_Tag
tag(cat
, name
, path
.GetRaw(), comment
, color
, prio
);
663 m_conn
->SendRequest(new CCatHandler
, &req
);
665 Category_Struct
*category
= m_CatList
[cat
];
666 category
->path
= path
;
667 category
->title
= name
;
668 category
->comment
= comment
;
669 category
->color
= color
;
670 category
->prio
= prio
;
676 void CPreferencesRem::RemoveCat(uint8 cat
)
678 CECPacket
req(EC_OP_DELETE_CATEGORY
);
679 CEC_Category_Tag
tag(cat
, EC_DETAIL_CMD
);
681 m_conn
->SendPacket(&req
);
682 CPreferences::RemoveCat(cat
);
687 // Container implementation
689 CServerConnectRem::CServerConnectRem(CRemoteConnect
*conn
)
696 void CServerConnectRem::ConnectToAnyServer()
698 CECPacket
req(EC_OP_SERVER_CONNECT
);
699 m_Conn
->SendPacket(&req
);
703 void CServerConnectRem::StopConnectionTry()
705 // lfroen: isn't Disconnect the same ?
709 void CServerConnectRem::Disconnect()
711 CECPacket
req(EC_OP_SERVER_DISCONNECT
);
712 m_Conn
->SendPacket(&req
);
716 void CServerConnectRem::ConnectToServer(CServer
*server
)
718 m_Conn
->ConnectED2K(server
->GetIP(), server
->GetPort());
722 bool CServerConnectRem::ReQuery()
724 CECPacket
stat_req(EC_OP_GET_CONNSTATE
);
725 m_Conn
->SendRequest(this, &stat_req
);
731 void CServerConnectRem::HandlePacket(const CECPacket
*packet
)
733 CEC_ConnState_Tag
*tag
=
734 (CEC_ConnState_Tag
*)packet
->GetTagByName(EC_TAG_CONNSTATE
);
739 theApp
->m_ConnState
= 0;
741 m_ID
= tag
->GetEd2kId();
742 theApp
->m_clientID
= tag
->GetClientId();
744 if (tag
->IsConnectedED2K()) {
745 CECTag
*srvtag
= tag
->GetTagByName(EC_TAG_SERVER
);
749 server
= theApp
->serverlist
->GetByID(srvtag
->GetIPv4Data().IP());
750 if (m_CurrServer
&& (server
!= m_CurrServer
)) {
751 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->
752 HighlightServer(m_CurrServer
, false);
754 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->
755 HighlightServer(server
, true);
756 m_CurrServer
= server
;
757 theApp
->m_ConnState
|= CONNECTED_ED2K
;
759 if ( m_CurrServer
) {
760 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->
761 HighlightServer(m_CurrServer
, false);
766 if (tag
->IsConnectedKademlia()) {
767 if (tag
->IsKadFirewalled()) {
768 theApp
->m_ConnState
|= CONNECTED_KAD_FIREWALLED
;
770 theApp
->m_ConnState
|= CONNECTED_KAD_OK
;
773 if (tag
->IsKadRunning()) {
774 theApp
->m_ConnState
|= CONNECTED_KAD_NOT
;
778 theApp
->amuledlg
->ShowConnectionState();
783 * Server list: host list of ed2k servers.
785 CServerListRem::CServerListRem(CRemoteConnect
*conn
)
787 CRemoteContainer
<CServer
, uint32
, CEC_Server_Tag
>(conn
, false)
792 void CServerListRem::HandlePacket(const CECPacket
*packet
)
794 CRemoteContainer
<CServer
, uint32
, CEC_Server_Tag
>::HandlePacket(packet
);
799 void CServerListRem::UpdateServerMetFromURL(wxString url
)
801 CECPacket
req(EC_OP_SERVER_UPDATE_FROM_URL
);
802 req
.AddTag(CECTag(EC_TAG_SERVERS_UPDATE_URL
, url
));
804 m_conn
->SendPacket(&req
);
808 void CServerListRem::SaveServerMet()
810 // lfroen: stub, nothing to do
814 void CServerListRem::FilterServers()
821 void CServerListRem::RemoveServer(CServer
* server
)
823 m_conn
->RemoveServer(server
->GetIP(),server
->GetPort());
827 void CServerListRem::UpdateUserFileStatus(CServer
*server
)
830 m_TotalUser
= server
->GetUsers();
831 m_TotalFile
= server
->GetFiles();
836 CServer
*CServerListRem::GetServerByAddress(const wxString
& WXUNUSED(address
), uint16
WXUNUSED(port
)) const
838 // It's ok to return 0 for context where this code is used in remote gui
842 CServer
*CServerListRem::GetServerByIPTCP(uint32
WXUNUSED(nIP
), uint16
WXUNUSED(nPort
)) const
844 // It's ok to return 0 for context where this code is used in remote gui
848 CServer
*CServerListRem::CreateItem(CEC_Server_Tag
*tag
)
850 return new CServer(tag
);
854 void CServerListRem::DeleteItem(CServer
*in_srv
)
856 CScopedPtr
<CServer
> srv(in_srv
);
857 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->RemoveServer(srv
.get());
861 uint32
CServerListRem::GetItemID(CServer
*server
)
863 return server
->GetIP();
867 void CServerListRem::ProcessItemUpdate(CEC_Server_Tag
*, CServer
*)
869 // server list is always realoaded from scratch
874 void CServerListRem::ReloadControl()
876 for(iterator it
= begin(); it
!= end(); it
++) {
878 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->RefreshServer(srv
);
883 CIPFilterRem::CIPFilterRem(CRemoteConnect
* conn
)
889 void CIPFilterRem::Reload()
891 CECPacket
req(EC_OP_IPFILTER_RELOAD
);
892 m_conn
->SendPacket(&req
);
896 void CIPFilterRem::Update(wxString url
)
898 CECPacket
req(EC_OP_IPFILTER_UPDATE
);
899 req
.AddTag(CECTag(EC_TAG_STRING
, url
));
901 m_conn
->SendPacket(&req
);
908 CSharedFilesRem::CSharedFilesRem(CRemoteConnect
*conn
)
914 void CSharedFilesRem::Reload(bool, bool)
916 CECPacket
req(EC_OP_SHAREDFILES_RELOAD
);
918 m_conn
->SendPacket(&req
);
922 void CSharedFilesRem::AddFilesFromDirectory(const CPath
& path
)
924 CECPacket
req(EC_OP_SHAREDFILES_ADD_DIRECTORY
);
926 req
.AddTag(CECTag(EC_TAG_PREFS_DIRECTORIES
, path
.GetRaw()));
928 m_conn
->SendPacket(&req
);
932 bool CSharedFilesRem::RenameFile(CKnownFile
* file
, const CPath
& newName
)
934 // We use the printable name, as the filename originated from user input,
935 // and the filesystem name might not be valid on the remote host.
936 const wxString strNewName
= newName
.GetPrintable();
938 CECPacket
request(EC_OP_RENAME_FILE
);
939 request
.AddTag(CECTag(EC_TAG_KNOWNFILE
, file
->GetFileHash()));
940 request
.AddTag(CECTag(EC_TAG_PARTFILE_NAME
, strNewName
));
942 m_conn
->SendPacket(&request
);
948 void CKnownFilesRem::DeleteItem(CKnownFile
* file
)
950 uint32 id
= file
->ECID();
951 if (theApp
->sharedfiles
->count(id
)) {
952 theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
->RemoveFile(file
);
953 theApp
->sharedfiles
->erase(id
);
955 if (theApp
->downloadqueue
->count(id
)) {
956 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->RemoveFile((CPartFile
*) file
);
957 theApp
->downloadqueue
->erase(id
);
963 uint32
CKnownFilesRem::GetItemID(CKnownFile
*file
)
969 void CKnownFilesRem::ProcessItemUpdate(CEC_SharedFile_Tag
*tag
, CKnownFile
*file
)
971 CECTag
*parttag
= tag
->GetTagByName(EC_TAG_PARTFILE_PART_STATUS
);
973 const uint8
*data
= file
->m_partStatus
.Decode(
974 (uint8
*)parttag
->GetTagData(),
975 parttag
->GetTagDataLen());
976 for(int i
= 0; i
< file
->GetPartCount(); ++i
) {
977 file
->m_AvailPartFrequency
[i
] = data
[i
];
980 tag
->GetRequests(&file
->statistic
.requested
);
981 tag
->GetAllRequests(&file
->statistic
.alltimerequested
);
982 tag
->GetAccepts(&file
->statistic
.accepted
);
983 tag
->GetAllAccepts(&file
->statistic
.alltimeaccepted
);
984 tag
->GetXferred(&file
->statistic
.transferred
);
985 tag
->GetAllXferred(&file
->statistic
.alltimetransferred
);
986 tag
->UpPrio(&file
->m_iUpPriorityEC
);
987 if (file
->m_iUpPriorityEC
>= 10) {
988 file
->m_iUpPriority
= file
->m_iUpPriorityEC
- 10;
989 file
->m_bAutoUpPriority
= true;
991 file
->m_iUpPriority
= file
->m_iUpPriorityEC
;
992 file
->m_bAutoUpPriority
= false;
994 tag
->GetCompleteSourcesLow(&file
->m_nCompleteSourcesCountLo
);
995 tag
->GetCompleteSourcesHigh(&file
->m_nCompleteSourcesCountHi
);
996 tag
->GetCompleteSources(&file
->m_nCompleteSourcesCount
);
998 tag
->GetOnQueue(&file
->m_queuedCount
);
1000 requested
+= file
->statistic
.requested
;
1001 transferred
+= file
->statistic
.transferred
;
1002 accepted
+= file
->statistic
.transferred
;
1004 theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
->UpdateItem(file
);
1006 if (file
->IsPartFile()) {
1007 ProcessItemUpdatePartfile((CEC_PartFile_Tag
*) tag
, (CPartFile
*) file
);
1011 void CSharedFilesRem::SetFilePrio(CKnownFile
*file
, uint8 prio
)
1013 CECPacket
req(EC_OP_SHARED_SET_PRIO
);
1015 CECTag
hashtag(EC_TAG_PARTFILE
, file
->GetFileHash());
1016 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_PRIO
, prio
));
1018 req
.AddTag(hashtag
);
1020 m_conn
->SendPacket(&req
);
1023 void CKnownFilesRem::ProcessUpdate(const CECPacket
*reply
, CECPacket
*, int)
1029 std::set
<uint32
> core_files
;
1030 for (CECPacket::const_iterator it
= reply
->begin(); it
!= reply
->end(); it
++) {
1031 CEC_SharedFile_Tag
*tag
= (CEC_SharedFile_Tag
*) & *it
;
1032 uint32 id
= tag
->ID();
1033 core_files
.insert(id
);
1034 if ( m_items_hash
.count(id
) ) {
1035 // Item already known: update it
1036 ProcessItemUpdate(tag
, m_items_hash
[id
]);
1038 CKnownFile
* newFile
;
1039 if (tag
->GetTagName() == EC_TAG_PARTFILE
) {
1040 CPartFile
*file
= new CPartFile((CEC_PartFile_Tag
*) tag
);
1041 ProcessItemUpdate(tag
, file
);
1042 // GUI doesn't allow clear finished files well at the moment,
1043 // so don't show finished files for now until GUI gets unlocked.
1044 // Files completing while GUI is open will still show.
1045 if (file
->IsPartFile()) {
1046 (*theApp
->downloadqueue
)[id
] = file
;
1047 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->AddFile(file
);
1051 newFile
= new CKnownFile(tag
);
1052 ProcessItemUpdate(tag
, newFile
);
1053 (*theApp
->sharedfiles
)[id
] = newFile
;
1054 theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
->ShowFile(newFile
);
1059 // remove items no longer present
1060 for(iterator it
= begin(); it
!= end();) {
1061 iterator it2
= it
++;
1062 if (!core_files
.count(GetItemID(*it2
))) {
1063 RemoveItem(it2
); // This calls DeleteItem, where it is removed from lists and views.
1068 CKnownFilesRem::CKnownFilesRem(CRemoteConnect
* conn
) : CRemoteContainer
<CKnownFile
, uint32
, CEC_SharedFile_Tag
>(conn
, true)
1077 * List of uploading and waiting clients.
1079 CUpDownClientListRem::CUpDownClientListRem(CRemoteConnect
*conn
, int viewtype
)
1081 CRemoteContainer
<CUpDownClient
, uint32
, CEC_UpDownClient_Tag
>(conn
, true)
1083 m_viewtype
= viewtype
;
1087 CUpDownClient::CUpDownClient(CEC_UpDownClient_Tag
*tag
) : CECID(tag
->ID())
1089 m_bRemoteQueueFull
= false;
1090 m_nUserIDHybrid
= tag
->UserID();
1091 m_Username
= tag
->ClientName();
1092 m_clientSoft
= tag
->ClientSoftware();
1093 m_clientVersionString
= GetSoftName(m_clientSoft
);
1094 m_clientSoftString
= m_clientVersionString
;
1095 m_bEmuleProtocol
= false;
1097 // The functions to retrieve m_clientVerString information are
1098 // currently in BaseClient.cpp, which is not linked in remote-gui app.
1099 // So, in the meantime, we use a tag sent from core.
1100 m_clientVerString
= tag
->SoftVerStr();
1101 m_strModVersion
= wxEmptyString
;
1102 wxString clientModString
;
1103 if (!clientModString
.IsEmpty()) {
1104 m_clientVerString
+= wxT(" - ") + clientModString
;
1106 m_fullClientVerString
= m_clientSoftString
+ wxT(" ") + m_clientVerString
;
1109 m_UserHash
= tag
->UserHash();
1112 m_nConnectIP
= m_dwUserIP
= tag
->UserIP();
1113 m_nUserPort
= tag
->UserPort();
1114 m_FullUserIP
= m_nConnectIP
;
1117 m_dwServerIP
= tag
->ServerIP();
1118 m_nServerPort
= tag
->ServerPort();
1119 m_ServerName
= tag
->ServerName();
1125 if (tag
->HaveFile()) {
1126 m_uploadingfile
= theApp
->knownfiles
->GetByID(tag
->FileID());
1128 m_uploadingfile
= NULL
;
1131 m_nCurSessionUp
= 0;
1133 credits
= new CClientCredits(new CreditStruct());
1136 uint16
CUpQueueRem::GetWaitingPosition(const CUpDownClient
*client
) const
1138 return client
->GetWaitingPosition();
1141 /* Warning: do common base */
1144 bool CUpDownClient::IsIdentified() const
1146 return m_identState
== IS_IDENTIFIED
;
1150 bool CUpDownClient::IsBadGuy() const
1152 return m_identState
== IS_IDBADGUY
;
1156 bool CUpDownClient::SUIFailed() const
1158 return m_identState
== IS_IDFAILED
;
1162 bool CUpDownClient::SUINeeded() const
1164 return m_identState
== IS_IDNEEDED
;
1168 bool CUpDownClient::SUINotSupported() const
1170 return m_identState
== IS_NOTAVAILABLE
;
1174 uint64
CUpDownClient::GetDownloadedTotal() const
1176 return credits
->GetDownloadedTotal();
1180 uint64
CUpDownClient::GetUploadedTotal() const
1182 return credits
->GetUploadedTotal();
1186 double CUpDownClient::GetScoreRatio() const
1188 return credits
->GetScoreRatio(GetIP(), theApp
->CryptoAvailable());
1194 CUpDownClient::~CUpDownClient()
1200 CUpDownClient
*CUpDownClientListRem::CreateItem(CEC_UpDownClient_Tag
*tag
)
1202 CUpDownClient
*client
= new CUpDownClient(tag
);
1203 ProcessItemUpdate(tag
, client
);
1205 //theApp->amuledlg->m_transferwnd->clientlistctrl->InsertClient(client, (ViewType)m_viewtype);
1211 void CUpDownClientListRem::DeleteItem(CUpDownClient
*client
)
1213 //theApp->amuledlg->m_transferwnd->clientlistctrl->RemoveClient(client, (ViewType)m_viewtype);
1218 uint32
CUpDownClientListRem::GetItemID(CUpDownClient
*client
)
1220 return client
->ECID();
1224 void CUpDownClientListRem::ProcessItemUpdate(
1225 CEC_UpDownClient_Tag
*tag
,
1226 CUpDownClient
*client
)
1228 tag
->UserID(&client
->m_nUserIDHybrid
);
1229 tag
->GetCurrentIdentState(&client
->m_identState
);
1230 tag
->HasObfuscatedConnection(&client
->m_hasbeenobfuscatinglately
);
1231 tag
->HasExtendedProtocol(&client
->m_bEmuleProtocol
);
1233 tag
->WaitingPosition(&client
->m_waitingPosition
);
1234 tag
->RemoteQueueRank(&client
->m_nRemoteQueueRank
);
1235 client
->m_bRemoteQueueFull
= client
->m_nRemoteQueueRank
== 0xffff;
1236 tag
->AskedCount(&client
->m_cAsked
);
1238 tag
->ClientDownloadState(&client
->m_nDownloadState
);
1239 tag
->ClientUploadState(&client
->m_nUploadState
);
1241 tag
->SpeedUp(&client
->m_nUpDatarate
);
1242 if ( client
->m_nDownloadState
== DS_DOWNLOADING
) {
1243 tag
->SpeedDown(&client
->kBpsDown
);
1245 client
->kBpsDown
= 0;
1248 tag
->WaitTime(&client
->m_WaitTime
);
1249 tag
->XferTime(&client
->m_UpStartTimeDelay
);
1250 tag
->LastReqTime(&client
->m_dwLastUpRequest
);
1251 tag
->QueueTime(&client
->m_WaitStartTime
);
1253 CreditStruct
*credit_struct
=
1254 (CreditStruct
*)client
->credits
->GetDataStruct();
1255 tag
->XferUp(&credit_struct
->uploaded
);
1256 tag
->XferUpSession(&client
->m_nTransferredUp
);
1258 tag
->XferDown(&credit_struct
->downloaded
);
1259 tag
->XferDownSession(&client
->m_nTransferredDown
);
1261 tag
->Score(&client
->m_score
);
1262 tag
->Rating(&client
->m_rating
);
1264 theApp
->amuledlg
->m_transferwnd
->clientlistctrl
->UpdateClient(client
,
1265 theApp
->amuledlg
->m_transferwnd
->clientlistctrl
->GetListView()); // Fixme, Listview shouldn't be required as parameter
1269 CUpQueueRem::CUpQueueRem(CRemoteConnect
*conn
)
1271 m_up_list(conn
, vtUploading
), m_wait_list(conn
, vtQueued
)
1277 * Download queue container: hold PartFiles with progress status
1282 bool CDownQueueRem::AddLink(const wxString
&link
, uint8 cat
)
1284 CECPacket
req(EC_OP_ADD_LINK
);
1285 CECTag
link_tag(EC_TAG_STRING
, link
);
1286 link_tag
.AddTag(CECTag(EC_TAG_PARTFILE_CAT
, cat
));
1287 req
.AddTag(link_tag
);
1289 m_conn
->SendPacket(&req
);
1294 void CDownQueueRem::ResetCatParts(int cat
)
1296 // Called when category is deleted. Command will be performed on the remote side,
1297 // but files still should be updated here right away, or drawing errors (colour not available)
1299 for (iterator it
= begin(); it
!= end(); it
++) {
1300 CPartFile
* file
= it
->second
;
1302 if ( file
->GetCategory() == cat
) {
1303 // Reset the category
1304 file
->SetCategory( 0 );
1305 } else if ( file
->GetCategory() > cat
) {
1306 // Set to the new position of the original category
1307 file
->SetCategory( file
->GetCategory() - 1 );
1314 void CKnownFilesRem::ProcessItemUpdatePartfile(CEC_PartFile_Tag
*tag
, CPartFile
*file
)
1319 tag
->Speed(&file
->m_kbpsDown
);
1320 file
->kBpsDown
= file
->m_kbpsDown
/ 1024.0;
1322 tag
->SizeXfer(&file
->transferred
);
1323 tag
->SizeDone(&file
->completedsize
);
1324 tag
->SourceXferCount(&file
->transferingsrc
);
1325 tag
->SourceNotCurrCount(&file
->m_notCurrentSources
);
1326 tag
->SourceCount(&file
->m_source_count
);
1327 tag
->SourceCountA4AF(&file
->m_a4af_source_count
);
1328 tag
->FileStatus(&file
->status
);
1329 tag
->Stopped(&file
->m_stopped
);
1331 tag
->LastSeenComplete(&file
->lastseencomplete
);
1332 tag
->LastDateChanged(&file
->m_lastDateChanged
);
1333 tag
->DownloadActiveTime(&file
->m_nDlActiveTime
);
1334 tag
->AvailablePartCount(&file
->m_availablePartsCount
);
1335 tag
->Shared(&file
->m_isShared
);
1337 tag
->GetLostDueToCorruption(&file
->m_iLostDueToCorruption
);
1338 tag
->GetGainDueToCompression(&file
->m_iGainDueToCompression
);
1339 tag
->TotalPacketsSavedDueToICH(&file
->m_iTotalPacketsSavedDueToICH
);
1341 tag
->FileCat(&file
->m_category
);
1343 tag
->DownPrio(&file
->m_iDownPriorityEC
);
1344 if ( file
->m_iDownPriorityEC
>= 10 ) {
1345 file
->m_iDownPriority
= file
->m_iDownPriorityEC
- 10;
1346 file
->m_bAutoDownPriority
= true;
1348 file
->m_iDownPriority
= file
->m_iDownPriorityEC
;
1349 file
->m_bAutoDownPriority
= false;
1352 file
->percentcompleted
= (100.0*file
->GetCompletedSize()) / file
->GetFileSize();
1355 // Copy part/gap status
1357 CECTag
*gaptag
= tag
->GetTagByName(EC_TAG_PARTFILE_GAP_STATUS
);
1358 CECTag
*parttag
= tag
->GetTagByName(EC_TAG_PARTFILE_PART_STATUS
);
1359 CECTag
*reqtag
= tag
->GetTagByName(EC_TAG_PARTFILE_REQ_STATUS
);
1360 if (gaptag
|| parttag
|| reqtag
) {
1361 PartFileEncoderData
&encoder
= file
->m_PartFileEncoderData
;
1364 ArrayOfUInts64 gaps
;
1365 encoder
.DecodeGaps(gaptag
, gaps
);
1366 int gap_size
= gaps
.size() / 2;
1368 file
->m_gaplist
.Init(file
->GetFileSize(), false);
1371 for (int j
= 0; j
< gap_size
; j
++) {
1372 file
->m_gaplist
.AddGap(gaps
[2*j
], gaps
[2*j
+1]);
1376 encoder
.DecodeParts(parttag
, file
->m_SrcpartFrequency
);
1378 wxASSERT (file
->m_SrcpartFrequency
.size() == file
->GetPartCount());
1381 ArrayOfUInts64 reqs
;
1382 encoder
.DecodeReqs(reqtag
, reqs
);
1383 int req_size
= reqs
.size() / 2;
1385 DeleteContents(file
->m_requestedblocks_list
);
1388 for (int j
= 0; j
< req_size
; j
++) {
1389 Requested_Block_Struct
* block
= new Requested_Block_Struct
;
1390 block
->StartOffset
= reqs
[2*j
];
1391 block
->EndOffset
= reqs
[2*j
+1];
1392 file
->m_requestedblocks_list
.push_back(block
);
1397 // Get source names and counts
1398 CECTag
*srcnametag
= tag
->GetTagByName(EC_TAG_PARTFILE_SOURCE_NAMES
);
1400 SourcenameItemMap
&map
= file
->GetSourcenameItemMap();
1401 for (CECTag::const_iterator it
= srcnametag
->begin(); it
!= srcnametag
->end(); it
++) {
1402 uint32 key
= it
->GetInt();
1403 int count
= it
->GetTagByNameSafe(EC_TAG_PARTFILE_SOURCE_NAMES_COUNTS
)->GetInt();
1407 SourcenameItem
&item
= map
[key
];
1409 const CECTag
*nametag
= it
->GetTagByName(EC_TAG_PARTFILE_SOURCE_NAMES
);
1411 item
.name
= nametag
->GetStringData();
1418 CECTag
*commenttag
= tag
->GetTagByName(EC_TAG_PARTFILE_COMMENTS
);
1420 file
->ClearFileRatingList();
1421 for (CECTag::const_iterator it
= commenttag
->begin(); it
!= commenttag
->end(); ) {
1422 wxString u
= (it
++)->GetStringData();
1423 wxString f
= (it
++)->GetStringData();
1424 int r
= (it
++)->GetInt();
1425 wxString c
= (it
++)->GetStringData();
1426 file
->AddFileRatingList(u
, f
, r
, c
);
1428 file
->UpdateFileRatingCommentAvail();
1431 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->UpdateItem(file
);
1433 // If file is shared check if it is already listed in shared files.
1434 // If not, add it and show it.
1435 if (file
->IsShared() && !theApp
->sharedfiles
->count(file
->ECID())) {
1436 (*theApp
->sharedfiles
)[file
->ECID()] = file
;
1437 theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
->ShowFile(file
);
1442 void CDownQueueRem::SendFileCommand(CPartFile
*file
, ec_tagname_t cmd
)
1445 req
.AddTag(CECTag(EC_TAG_PARTFILE
, file
->GetFileHash()));
1447 m_conn
->SendPacket(&req
);
1451 void CDownQueueRem::Prio(CPartFile
*file
, uint8 prio
)
1453 CECPacket
req(EC_OP_PARTFILE_PRIO_SET
);
1455 CECTag
hashtag(EC_TAG_PARTFILE
, file
->GetFileHash());
1456 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_PRIO
, prio
));
1457 req
.AddTag(hashtag
);
1459 m_conn
->SendPacket(&req
);
1463 void CDownQueueRem::AutoPrio(CPartFile
*file
, bool flag
)
1465 CECPacket
req(EC_OP_PARTFILE_PRIO_SET
);
1467 CECTag
hashtag(EC_TAG_PARTFILE
, file
->GetFileHash());
1469 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_PRIO
,
1470 (uint8
)(flag
? PR_AUTO
: file
->GetDownPriority())));
1471 req
.AddTag(hashtag
);
1473 m_conn
->SendPacket(&req
);
1477 void CDownQueueRem::Category(CPartFile
*file
, uint8 cat
)
1479 CECPacket
req(EC_OP_PARTFILE_SET_CAT
);
1480 file
->SetCategory(cat
);
1482 CECTag
hashtag(EC_TAG_PARTFILE
, file
->GetFileHash());
1483 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_CAT
, cat
));
1484 req
.AddTag(hashtag
);
1486 m_conn
->SendPacket(&req
);
1490 void CDownQueueRem::AddSearchToDownload(CSearchFile
* file
, uint8 category
)
1492 CECPacket
req(EC_OP_DOWNLOAD_SEARCH_RESULT
);
1493 CECTag
hashtag(EC_TAG_PARTFILE
, file
->GetFileHash());
1494 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_CAT
, category
));
1495 req
.AddTag(hashtag
);
1497 m_conn
->SendPacket(&req
);
1501 // This is an ugly hack and to be deleted when GUI is unlocked!
1502 // (replacing iterate-by-index with iteration)
1503 // It will only work for linear iteration starting with 0 (as used in CTransferWnd::UpdateCategory)
1504 CPartFile
* CDownQueueRem::GetFileByIndex(unsigned int idx
)
1506 static CDownQueueRem::iterator it
;
1513 return (it
++)->second
;
1517 CClientListRem::CClientListRem(CRemoteConnect
*conn
)
1523 void CClientListRem::FilterQueues()
1530 CSearchListRem::CSearchListRem(CRemoteConnect
*conn
) : CRemoteContainer
<CSearchFile
, uint32
, CEC_SearchFile_Tag
>(conn
, true)
1536 wxString
CSearchListRem::StartNewSearch(
1537 uint32
* nSearchID
, SearchType search_type
,
1538 const CSearchList::CSearchParams
& params
)
1540 CECPacket
search_req(EC_OP_SEARCH_START
);
1541 EC_SEARCH_TYPE ec_search_type
= EC_SEARCH_LOCAL
;
1542 switch(search_type
) {
1543 case LocalSearch
: ec_search_type
= EC_SEARCH_LOCAL
; break;
1544 case GlobalSearch
: ec_search_type
= EC_SEARCH_GLOBAL
; break;
1545 case KadSearch
: ec_search_type
= EC_SEARCH_KAD
; break;
1548 CEC_Search_Tag(params
.searchString
, ec_search_type
,
1549 params
.typeText
, params
.extension
, params
.availability
,
1550 params
.minSize
, params
.maxSize
));
1552 m_conn
->SendPacket(&search_req
);
1553 m_curr_search
= *(nSearchID
); // No kad remote search yet.
1557 return wxEmptyString
; // EC reply will have the error mesg is needed.
1561 void CSearchListRem::StopGlobalSearch()
1563 if (m_curr_search
!= -1) {
1564 CECPacket
search_req(EC_OP_SEARCH_STOP
);
1565 m_conn
->SendPacket(&search_req
);
1570 void CSearchListRem::StopKadSearch()
1572 // FIXME implementation needed
1576 void CSearchListRem::HandlePacket(const CECPacket
*packet
)
1578 if ( packet
->GetOpCode() == EC_OP_SEARCH_PROGRESS
) {
1579 CoreNotify_Search_Update_Progress(packet
->GetFirstTagSafe()->GetInt());
1581 CRemoteContainer
<CSearchFile
, uint32
, CEC_SearchFile_Tag
>::HandlePacket(packet
);
1586 CSearchFile::CSearchFile(CEC_SearchFile_Tag
*tag
)
1590 m_showChildren(false),
1592 m_completeSourceCount(0),
1594 m_downloadStatus(NEW
),
1599 SetFileName(CPath(tag
->FileName()));
1600 m_abyFileHash
= tag
->FileHash();
1601 SetFileSize(tag
->SizeFull());
1603 m_searchID
= theApp
->searchlist
->m_curr_search
;
1608 // dtor is virtual - must be implemented
1609 CSearchFile::~CSearchFile()
1614 CSearchFile
*CSearchListRem::CreateItem(CEC_SearchFile_Tag
*tag
)
1616 CSearchFile
*file
= new CSearchFile(tag
);
1617 ProcessItemUpdate(tag
, file
);
1619 theApp
->amuledlg
->m_searchwnd
->AddResult(file
);
1625 void CSearchListRem::DeleteItem(CSearchFile
*file
)
1631 uint32
CSearchListRem::GetItemID(CSearchFile
*file
)
1633 return file
->ECID();
1637 void CSearchListRem::ProcessItemUpdate(CEC_SearchFile_Tag
*tag
, CSearchFile
*file
)
1639 uint32 sourceCount
= file
->m_sourceCount
;
1640 uint32 completeSourceCount
= file
->m_completeSourceCount
;
1641 CSearchFile::DownloadStatus status
= file
->m_downloadStatus
;
1642 tag
->SourceCount(&file
->m_sourceCount
);
1643 tag
->CompleteSourceCount(&file
->m_completeSourceCount
);
1644 tag
->DownloadStatus((uint32
*) &file
->m_downloadStatus
);
1646 if (file
->m_sourceCount
!= sourceCount
1647 || file
->m_completeSourceCount
!= completeSourceCount
1648 || file
->m_downloadStatus
!= status
) {
1649 if (theApp
->amuledlg
&& theApp
->amuledlg
->m_searchwnd
) {
1650 theApp
->amuledlg
->m_searchwnd
->UpdateResult(file
);
1656 bool CSearchListRem::Phase1Done(const CECPacket
*WXUNUSED(reply
))
1658 CECPacket
progress_req(EC_OP_SEARCH_PROGRESS
);
1659 m_conn
->SendRequest(this, &progress_req
);
1665 void CSearchListRem::RemoveResults(long nSearchID
)
1667 ResultMap::iterator it
= m_results
.find(nSearchID
);
1668 if (it
!= m_results
.end()) {
1669 CSearchResultList
& list
= it
->second
;
1670 for (unsigned int i
= 0; i
< list
.size(); ++i
) {
1673 m_results
.erase(it
);
1678 const CSearchResultList
& CSearchListRem::GetSearchResults(long nSearchID
)
1680 ResultMap::const_iterator it
= m_results
.find(nSearchID
);
1681 if (it
!= m_results
.end()) {
1685 // TODO: Should we assert in this case?
1686 static CSearchResultList list
;
1691 void CStatsUpdaterRem::HandlePacket(const CECPacket
*packet
)
1693 theStats::UpdateStats(packet
);
1694 theApp
->ShowUserCount(); // maybe there should be a check if a usercount changed ?
1698 bool CUpDownClient::IsBanned() const
1706 // Those functions have different implementation in remote gui
1708 void CUpDownClient::Ban()
1715 void CUpDownClient::UnBan()
1722 void CUpDownClient::RequestSharedFileList()
1729 void CKnownFile::SetFileComment(const wxString
&)
1732 wxMessageBox(_("Comments and ratings are not supported on remote gui yet"), _("Information"), wxOK
| wxICON_INFORMATION
);
1736 void CKnownFile::SetFileRating(unsigned char)
1742 // I don't think it will be implemented - too match data transfer. But who knows ?
1743 wxString
CUpDownClient::ShowDownloadingParts() const
1745 return wxEmptyString
;
1749 bool CUpDownClient::SwapToAnotherFile(
1750 bool WXUNUSED(bIgnoreNoNeeded
),
1751 bool WXUNUSED(ignoreSuspensions
),
1752 bool WXUNUSED(bRemoveCompletely
),
1753 CPartFile
* WXUNUSED(toFile
))
1762 // Those functions are virtual. So even they don't get called they must
1763 // be defined so linker will be happy
1765 CPacket
* CKnownFile::CreateSrcInfoPacket(const CUpDownClient
*, uint8
/*byRequestedVersion*/, uint16
/*nRequestedOptions*/)
1772 bool CKnownFile::LoadFromFile(const class CFileDataIO
*)
1779 void CKnownFile::UpdatePartsInfo()
1785 CPacket
* CPartFile::CreateSrcInfoPacket(CUpDownClient
const *, uint8
/*byRequestedVersion*/, uint16
/*nRequestedOptions*/)
1792 void CPartFile::UpdatePartsInfo()
1798 void CPartFile::UpdateFileRatingCommentAvail()
1800 bool prevComment
= m_hasComment
;
1801 int prevRating
= m_iUserRating
;
1803 m_hasComment
= false;
1805 int ratingCount
= 0;
1807 FileRatingList::iterator it
= m_FileRatingList
.begin();
1808 for (; it
!= m_FileRatingList
.end(); ++it
) {
1809 SFileRating
& cur_rat
= *it
;
1811 if (!cur_rat
.Comment
.IsEmpty()) {
1812 m_hasComment
= true;
1815 uint8 rating
= cur_rat
.Rating
;
1817 wxASSERT(rating
<= 5);
1820 m_iUserRating
+= rating
;
1825 m_iUserRating
/= ratingCount
;
1826 wxASSERT(m_iUserRating
> 0 && m_iUserRating
<= 5);
1829 if ((prevComment
!= m_hasComment
) || (prevRating
!= m_iUserRating
)) {
1830 UpdateDisplayedInfo();
1834 bool CPartFile::SavePartFile(bool)
1840 CamuleRemoteGuiApp
*theApp
;
1843 // since gui is not linked with amule.cpp - define events here
1845 DEFINE_LOCAL_EVENT_TYPE(wxEVT_CORE_FINISHED_HTTP_DOWNLOAD
)
1846 DEFINE_LOCAL_EVENT_TYPE(wxEVT_CORE_SOURCE_DNS_DONE
)
1847 DEFINE_LOCAL_EVENT_TYPE(wxEVT_CORE_UDP_DNS_DONE
)
1848 DEFINE_LOCAL_EVENT_TYPE(wxEVT_CORE_SERVER_DNS_DONE
)
1849 // File_checked_for_headers