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 "ClientListCtrl.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 switch(amuledlg
->m_transferwnd
->clientlistctrl
->GetListView()) {
173 uploadqueue
->ReQueryUp();
176 uploadqueue
->ReQueryWait();
183 amuledlg
->m_transferwnd
->ShowQueueCount(theStats::GetWaitingUserCount());
184 } else if (amuledlg
->m_searchwnd
->IsShown()) {
185 if (searchlist
->m_curr_search
!= -1) {
186 searchlist
->DoRequery(EC_OP_SEARCH_RESULTS
, EC_TAG_SEARCHFILE
);
193 AddLogLineCS(wxT("WTF?")); // should not happen. :-)
197 // Check for new links once per second.
198 static uint32 lastED2KLinkCheck
= 0;
199 if (GetTickCount() - lastED2KLinkCheck
>= 1000) {
201 lastED2KLinkCheck
= GetTickCount();
206 void CamuleRemoteGuiApp::OnFinishedHTTPDownload(CMuleInternalEvent
& event
)
208 #ifdef ENABLE_IP2COUNTRY
209 if (event
.GetInt() == HTTP_GeoIP
) {
210 amuledlg
->IP2CountryDownloadFinished(event
.GetExtraLong());
211 // If we updated, the dialog is already up. Redraw it to show the flags.
218 void CamuleRemoteGuiApp::ShutDown(wxCloseEvent
&WXUNUSED(evt
))
220 // Stop the Core Timer
224 // Destroy the EC socket
225 m_connect
->Destroy();
230 amuledlg
->DlgShutDown();
237 bool CamuleRemoteGuiApp::OnInit()
243 theApp
= &wxGetApp();
245 // Handle uncaught exceptions
246 InstallMuleExceptionHandler();
248 // Parse cmdline arguments.
249 if (!InitCommon(AMULE_APP_BASE::argc
, AMULE_APP_BASE::argv
)) {
253 // Create the polling timer
254 poll_timer
= new wxTimer(this,ID_CORE_TIMER_EVENT
);
256 AddLogLineCS(_("Fatal Error: Failed to create Poll Timer"));
260 m_connect
= new CRemoteConnect(this);
262 glob_prefs
= new CPreferencesRem(m_connect
);
264 InitCustomLanguages();
265 InitLocale(m_locale
, StrLang2wx(thePrefs::GetLanguageID()));
267 if (ShowConnectionDialog()) {
268 AddLogLineNS(_("Going to event loop..."));
276 bool CamuleRemoteGuiApp::CryptoAvailable() const
278 return thePrefs::IsSecureIdentEnabled(); // good enough
282 bool CamuleRemoteGuiApp::ShowConnectionDialog()
284 dialog
= new CEConnectDlg
;
286 if (m_skipConnectionDialog
) {
289 } else if (dialog
->ShowModal() != wxID_OK
) {
294 AddLogLineNS(_("Connecting..."));
295 if (!m_connect
->ConnectToCore(dialog
->Host(), dialog
->Port(),
296 dialog
->Login(), dialog
->PassHash(),
297 wxT("amule-remote"), wxT("0x0001"))) {
298 wxMessageBox(_("Connection failed "),_("ERROR"),wxOK
);
307 void CamuleRemoteGuiApp::OnECConnection(wxEvent
& event
) {
308 wxECSocketEvent
& evt
= *((wxECSocketEvent
*)&event
);
309 AddLogLineNS(_("Remote GUI EC event handler"));
310 wxString reply
= evt
.GetServerReply();
311 AddLogLineM(true, reply
);
312 if (evt
.GetResult() == true) {
313 // Connected - go to next init step
314 glob_prefs
->LoadRemote();
316 AddLogLineNS(_("Going down"));
317 if (dialog
) { // connect failed
319 (CFormat(_("Connection Failed. Unable to connect to %s:%d\n")) % dialog
->Host() % dialog
->Port()) + reply
,
321 } else { // server disconnected (probably terminated) later
322 wxMessageBox(_("Connection closed - aMule has terminated probably."), _("ERROR"), wxOK
);
329 void CamuleRemoteGuiApp::OnECInitDone(wxEvent
& )
335 void CamuleRemoteGuiApp::OnNotifyEvent(CMuleGUIEvent
& evt
)
341 void CamuleRemoteGuiApp::Startup() {
343 if (dialog
->SaveUserPass()) {
344 wxConfig::Get()->Write(wxT("/EC/Host"), dialog
->Host());
345 wxConfig::Get()->Write(wxT("/EC/Port"), dialog
->Port());
346 wxConfig::Get()->Write(wxT("/EC/Password"), dialog
->PassHash());
354 serverconnect
= new CServerConnectRem(m_connect
);
355 m_statistics
= new CStatistics(*m_connect
);
357 clientlist
= new CClientListRem(m_connect
);
358 searchlist
= new CSearchListRem(m_connect
);
359 serverlist
= new CServerListRem(m_connect
);
361 sharedfiles
= new CSharedFilesRem(m_connect
);
362 knownfiles
= new CKnownFilesRem(m_connect
);
364 // bugfix - do this before creating the uploadqueue
365 downloadqueue
= new CDownQueueRem(m_connect
);
366 uploadqueue
= new CUpQueueRem(m_connect
);
367 ipfilter
= new CIPFilterRem(m_connect
);
369 // Create main dialog
370 InitGui(m_geometryEnabled
, m_geometryString
);
372 // Forward wxLog events to CLogger
373 wxLog::SetActiveTarget(new CLoggerTarget
);
374 serverlist
->FullReload(EC_OP_GET_SERVER_LIST
);
375 knownfiles
->DoRequery(EC_OP_GET_UPDATE
, EC_TAG_KNOWNFILE
);
377 // Start the Poll Timer
378 poll_timer
->Start(1000);
379 amuledlg
->StartGuiTimer();
381 // Now activate GeoIP, so that the download dialog doesn't get destroyed immediately
382 #ifdef ENABLE_IP2COUNTRY
383 if (thePrefs::IsGeoIPEnabled()) {
384 amuledlg
->m_IP2Country
->Enable();
390 int CamuleRemoteGuiApp::ShowAlert(wxString msg
, wxString title
, int flags
)
392 return CamuleGuiBase::ShowAlert(msg
, title
, flags
);
396 void CamuleRemoteGuiApp::AddRemoteLogLine(const wxString
& line
)
398 amuledlg
->AddLogLine(line
);
401 int CamuleRemoteGuiApp::InitGui(bool geometry_enabled
, wxString
&geom_string
)
403 CamuleGuiBase::InitGui(geometry_enabled
, geom_string
);
404 SetTopWindow(amuledlg
);
405 AddLogLineN(_("Ready")); // The first log line after the window is up triggers output of all the ones before
410 bool CamuleRemoteGuiApp::CopyTextToClipboard(wxString strText
)
412 return CamuleGuiBase::CopyTextToClipboard(strText
);
416 uint32
CamuleRemoteGuiApp::GetPublicIP()
422 wxString
CamuleRemoteGuiApp::GetLog(bool)
424 return wxEmptyString
;
428 wxString
CamuleRemoteGuiApp::GetServerLog(bool)
430 return wxEmptyString
;
434 bool CamuleRemoteGuiApp::AddServer(CServer
*, bool)
436 // #warning TODO: Add remote command
441 bool CamuleRemoteGuiApp::IsFirewalled() const
443 if (IsConnectedED2K() && !serverconnect
->IsLowID()) {
447 return IsFirewalledKad();
451 bool CamuleRemoteGuiApp::IsConnectedED2K() const {
452 return serverconnect
&& serverconnect
->IsConnected();
456 void CamuleRemoteGuiApp::StartKad() {
457 m_connect
->StartKad();
461 void CamuleRemoteGuiApp::StopKad() {
462 m_connect
->StopKad();
466 void CamuleRemoteGuiApp::BootstrapKad(uint32 ip
, uint16 port
)
468 CECPacket
req(EC_OP_KAD_BOOTSTRAP_FROM_IP
);
469 req
.AddTag(CECTag(EC_TAG_BOOTSTRAP_IP
, ip
));
470 req
.AddTag(CECTag(EC_TAG_BOOTSTRAP_PORT
, port
));
472 m_connect
->SendPacket(&req
);
476 void CamuleRemoteGuiApp::UpdateNotesDat(const wxString
& url
)
478 CECPacket
req(EC_OP_KAD_UPDATE_FROM_URL
);
479 req
.AddTag(CECTag(EC_TAG_KADEMLIA_UPDATE_URL
, url
));
481 m_connect
->SendPacket(&req
);
485 void CamuleRemoteGuiApp::DisconnectED2K() {
486 if (IsConnectedED2K()) {
487 m_connect
->DisconnectED2K();
492 uint32
CamuleRemoteGuiApp::GetED2KID() const
494 return serverconnect
? serverconnect
->GetClientID() : 0;
498 uint32
CamuleRemoteGuiApp::GetID() const
504 void CamuleRemoteGuiApp::ShowUserCount() {
507 static const wxString s_singlenetstatusformat
= _("Users: %s | Files: %s");
508 static const wxString s_bothnetstatusformat
= _("Users: E: %s K: %s | Files: E: %s K: %s");
510 if (thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia()) {
511 buffer
= CFormat(s_bothnetstatusformat
) % CastItoIShort(theStats::GetED2KUsers()) % CastItoIShort(theStats::GetKadUsers()) % CastItoIShort(theStats::GetED2KFiles()) % CastItoIShort(theStats::GetKadFiles());
512 } else if (thePrefs::GetNetworkED2K()) {
513 buffer
= CFormat(s_singlenetstatusformat
) % CastItoIShort(theStats::GetED2KUsers()) % CastItoIShort(theStats::GetED2KFiles());
514 } else if (thePrefs::GetNetworkKademlia()) {
515 buffer
= CFormat(s_singlenetstatusformat
) % CastItoIShort(theStats::GetKadUsers()) % CastItoIShort(theStats::GetKadFiles());
517 buffer
= _("No networks selected");
520 Notify_ShowUserCount(buffer
);
525 * Preferences: holds both local and remote settings.
527 * First, everything is loaded from local config file. Later, settings
528 * that are relevant on remote side only are loaded thru EC
530 CPreferencesRem::CPreferencesRem(CRemoteConnect
*conn
)
535 // Settings queried from remote side
537 m_exchange_send_selected_prefs
=
539 EC_PREFS_CONNECTIONS
|
540 EC_PREFS_MESSAGEFILTER
|
545 EC_PREFS_DIRECTORIES
|
547 EC_PREFS_CORETWEAKS
|
548 EC_PREFS_REMOTECONTROLS
|
550 m_exchange_recv_selected_prefs
=
551 m_exchange_send_selected_prefs
|
556 void CPreferencesRem::HandlePacket(const CECPacket
*packet
)
558 ((CEC_Prefs_Packet
*)packet
)->Apply();
560 if ( packet
->GetTagByName(EC_TAG_PREFS_CATEGORIES
) != 0 ) {
561 for (size_t i
= 0; i
< packet
->GetTagByName(EC_TAG_PREFS_CATEGORIES
)->GetTagCount(); i
++) {
562 const CECTag
*cat_tag
= packet
->GetTagByName(EC_TAG_PREFS_CATEGORIES
)->GetTagByIndex(i
);
563 Category_Struct
*cat
= new Category_Struct
;
564 cat
->title
= cat_tag
->GetTagByName(EC_TAG_CATEGORY_TITLE
)->GetStringData();
565 cat
->path
= CPath(cat_tag
->GetTagByName(EC_TAG_CATEGORY_PATH
)->GetStringData());
566 cat
->comment
= cat_tag
->GetTagByName(EC_TAG_CATEGORY_COMMENT
)->GetStringData();
567 cat
->color
= cat_tag
->GetTagByName(EC_TAG_CATEGORY_COLOR
)->GetInt();
568 cat
->prio
= cat_tag
->GetTagByName(EC_TAG_CATEGORY_PRIO
)->GetInt();
569 theApp
->glob_prefs
->AddCat(cat
);
572 Category_Struct
*cat
= new Category_Struct
;
573 cat
->title
= _("All");
575 cat
->prio
= PR_NORMAL
;
576 theApp
->glob_prefs
->AddCat(cat
);
578 wxECInitDoneEvent event
;
579 theApp
->AddPendingEvent(event
);
584 bool CPreferencesRem::LoadRemote()
587 // override local settings with remote
588 CECPacket
req(EC_OP_GET_PREFERENCES
, EC_DETAIL_UPDATE
);
590 // bring categories too
591 req
.AddTag(CECTag(EC_TAG_SELECT_PREFS
, m_exchange_recv_selected_prefs
));
593 m_conn
->SendRequest(this, &req
);
599 void CPreferencesRem::SendToRemote()
601 CEC_Prefs_Packet
pref_packet(m_exchange_send_selected_prefs
, EC_DETAIL_UPDATE
, EC_DETAIL_FULL
);
602 m_conn
->SendPacket(&pref_packet
);
606 class CCatHandler
: public CECPacketHandlerBase
{
607 virtual void HandlePacket(const CECPacket
*packet
);
611 void CCatHandler::HandlePacket(const CECPacket
*packet
)
613 if (packet
->GetOpCode() == EC_OP_FAILED
) {
614 const CECTag
* catTag
= packet
->GetTagByName(EC_TAG_CATEGORY
);
615 const CECTag
* pathTag
= packet
->GetTagByName(EC_TAG_CATEGORY_PATH
);
616 if (catTag
&& pathTag
&& catTag
->GetInt() < theApp
->glob_prefs
->GetCatCount()) {
617 int cat
= catTag
->GetInt();
618 Category_Struct
* cs
= theApp
->glob_prefs
->GetCategory(cat
);
619 wxMessageBox(CFormat(_("Can't create directory '%s' for category '%s', keeping directory '%s'."))
620 % cs
->path
.GetPrintable() % cs
->title
% pathTag
->GetStringData(),
622 cs
->path
= CPath(pathTag
->GetStringData());
623 theApp
->amuledlg
->m_transferwnd
->UpdateCategory(cat
);
624 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->Refresh();
631 bool CPreferencesRem::CreateCategory(
632 Category_Struct
*& category
,
633 const wxString
& name
,
635 const wxString
& comment
,
639 CECPacket
req(EC_OP_CREATE_CATEGORY
);
640 CEC_Category_Tag
tag(0xffffffff, name
, path
.GetRaw(), comment
, color
, prio
);
642 m_conn
->SendRequest(new CCatHandler
, &req
);
644 category
= new Category_Struct();
645 category
->path
= path
;
646 category
->title
= name
;
647 category
->comment
= comment
;
648 category
->color
= color
;
649 category
->prio
= prio
;
657 bool CPreferencesRem::UpdateCategory(
659 const wxString
& name
,
661 const wxString
& comment
,
665 CECPacket
req(EC_OP_UPDATE_CATEGORY
);
666 CEC_Category_Tag
tag(cat
, name
, path
.GetRaw(), comment
, color
, prio
);
668 m_conn
->SendRequest(new CCatHandler
, &req
);
670 Category_Struct
*category
= m_CatList
[cat
];
671 category
->path
= path
;
672 category
->title
= name
;
673 category
->comment
= comment
;
674 category
->color
= color
;
675 category
->prio
= prio
;
681 void CPreferencesRem::RemoveCat(uint8 cat
)
683 CECPacket
req(EC_OP_DELETE_CATEGORY
);
684 CEC_Category_Tag
tag(cat
, EC_DETAIL_CMD
);
686 m_conn
->SendPacket(&req
);
687 CPreferences::RemoveCat(cat
);
692 // Container implementation
694 CServerConnectRem::CServerConnectRem(CRemoteConnect
*conn
)
701 void CServerConnectRem::ConnectToAnyServer()
703 CECPacket
req(EC_OP_SERVER_CONNECT
);
704 m_Conn
->SendPacket(&req
);
708 void CServerConnectRem::StopConnectionTry()
710 // lfroen: isn't Disconnect the same ?
714 void CServerConnectRem::Disconnect()
716 CECPacket
req(EC_OP_SERVER_DISCONNECT
);
717 m_Conn
->SendPacket(&req
);
721 void CServerConnectRem::ConnectToServer(CServer
*server
)
723 m_Conn
->ConnectED2K(server
->GetIP(), server
->GetPort());
727 bool CServerConnectRem::ReQuery()
729 CECPacket
stat_req(EC_OP_GET_CONNSTATE
);
730 m_Conn
->SendRequest(this, &stat_req
);
736 void CServerConnectRem::HandlePacket(const CECPacket
*packet
)
738 CEC_ConnState_Tag
*tag
=
739 (CEC_ConnState_Tag
*)packet
->GetTagByName(EC_TAG_CONNSTATE
);
744 theApp
->m_ConnState
= 0;
746 m_ID
= tag
->GetEd2kId();
747 theApp
->m_clientID
= tag
->GetClientId();
749 if (tag
->IsConnectedED2K()) {
750 CECTag
*srvtag
= tag
->GetTagByName(EC_TAG_SERVER
);
754 server
= theApp
->serverlist
->GetByID(srvtag
->GetIPv4Data().IP());
755 if (m_CurrServer
&& (server
!= m_CurrServer
)) {
756 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->
757 HighlightServer(m_CurrServer
, false);
759 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->
760 HighlightServer(server
, true);
761 m_CurrServer
= server
;
762 theApp
->m_ConnState
|= CONNECTED_ED2K
;
764 if ( m_CurrServer
) {
765 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->
766 HighlightServer(m_CurrServer
, false);
771 if (tag
->IsConnectedKademlia()) {
772 if (tag
->IsKadFirewalled()) {
773 theApp
->m_ConnState
|= CONNECTED_KAD_FIREWALLED
;
775 theApp
->m_ConnState
|= CONNECTED_KAD_OK
;
778 if (tag
->IsKadRunning()) {
779 theApp
->m_ConnState
|= CONNECTED_KAD_NOT
;
783 theApp
->amuledlg
->ShowConnectionState();
788 * Server list: host list of ed2k servers.
790 CServerListRem::CServerListRem(CRemoteConnect
*conn
)
792 CRemoteContainer
<CServer
, uint32
, CEC_Server_Tag
>(conn
, false)
797 void CServerListRem::HandlePacket(const CECPacket
*packet
)
799 CRemoteContainer
<CServer
, uint32
, CEC_Server_Tag
>::HandlePacket(packet
);
804 void CServerListRem::UpdateServerMetFromURL(wxString url
)
806 CECPacket
req(EC_OP_SERVER_UPDATE_FROM_URL
);
807 req
.AddTag(CECTag(EC_TAG_SERVERS_UPDATE_URL
, url
));
809 m_conn
->SendPacket(&req
);
813 void CServerListRem::SaveServerMet()
815 // lfroen: stub, nothing to do
819 void CServerListRem::FilterServers()
826 void CServerListRem::RemoveServer(CServer
* server
)
828 m_conn
->RemoveServer(server
->GetIP(),server
->GetPort());
832 void CServerListRem::UpdateUserFileStatus(CServer
*server
)
835 m_TotalUser
= server
->GetUsers();
836 m_TotalFile
= server
->GetFiles();
841 CServer
*CServerListRem::GetServerByAddress(const wxString
& WXUNUSED(address
), uint16
WXUNUSED(port
)) const
843 // It's ok to return 0 for context where this code is used in remote gui
847 CServer
*CServerListRem::GetServerByIPTCP(uint32
WXUNUSED(nIP
), uint16
WXUNUSED(nPort
)) const
849 // It's ok to return 0 for context where this code is used in remote gui
853 CServer
*CServerListRem::CreateItem(CEC_Server_Tag
*tag
)
855 return new CServer(tag
);
859 void CServerListRem::DeleteItem(CServer
*in_srv
)
861 CScopedPtr
<CServer
> srv(in_srv
);
862 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->RemoveServer(srv
.get());
866 uint32
CServerListRem::GetItemID(CServer
*server
)
868 return server
->GetIP();
872 void CServerListRem::ProcessItemUpdate(CEC_Server_Tag
*, CServer
*)
874 // server list is always realoaded from scratch
879 void CServerListRem::ReloadControl()
881 for(iterator it
= begin(); it
!= end(); it
++) {
883 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->RefreshServer(srv
);
888 CIPFilterRem::CIPFilterRem(CRemoteConnect
* conn
)
894 void CIPFilterRem::Reload()
896 CECPacket
req(EC_OP_IPFILTER_RELOAD
);
897 m_conn
->SendPacket(&req
);
901 void CIPFilterRem::Update(wxString url
)
903 CECPacket
req(EC_OP_IPFILTER_UPDATE
);
904 req
.AddTag(CECTag(EC_TAG_STRING
, url
));
906 m_conn
->SendPacket(&req
);
913 CSharedFilesRem::CSharedFilesRem(CRemoteConnect
*conn
)
919 void CSharedFilesRem::Reload(bool, bool)
921 CECPacket
req(EC_OP_SHAREDFILES_RELOAD
);
923 m_conn
->SendPacket(&req
);
927 void CSharedFilesRem::AddFilesFromDirectory(const CPath
& path
)
929 CECPacket
req(EC_OP_SHAREDFILES_ADD_DIRECTORY
);
931 req
.AddTag(CECTag(EC_TAG_PREFS_DIRECTORIES
, path
.GetRaw()));
933 m_conn
->SendPacket(&req
);
937 bool CSharedFilesRem::RenameFile(CKnownFile
* file
, const CPath
& newName
)
939 // We use the printable name, as the filename originated from user input,
940 // and the filesystem name might not be valid on the remote host.
941 const wxString strNewName
= newName
.GetPrintable();
943 CECPacket
request(EC_OP_RENAME_FILE
);
944 request
.AddTag(CECTag(EC_TAG_KNOWNFILE
, file
->GetFileHash()));
945 request
.AddTag(CECTag(EC_TAG_PARTFILE_NAME
, strNewName
));
947 m_conn
->SendPacket(&request
);
953 void CKnownFilesRem::DeleteItem(CKnownFile
* file
)
955 uint32 id
= file
->ECID();
956 if (theApp
->sharedfiles
->count(id
)) {
957 theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
->RemoveFile(file
);
958 theApp
->sharedfiles
->erase(id
);
960 if (theApp
->downloadqueue
->count(id
)) {
961 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->RemoveFile((CPartFile
*) file
);
962 theApp
->downloadqueue
->erase(id
);
968 uint32
CKnownFilesRem::GetItemID(CKnownFile
*file
)
974 void CKnownFilesRem::ProcessItemUpdate(CEC_SharedFile_Tag
*tag
, CKnownFile
*file
)
976 CECTag
*parttag
= tag
->GetTagByName(EC_TAG_PARTFILE_PART_STATUS
);
978 const uint8
*data
= file
->m_partStatus
.Decode(
979 (uint8
*)parttag
->GetTagData(),
980 parttag
->GetTagDataLen());
981 for(int i
= 0; i
< file
->GetPartCount(); ++i
) {
982 file
->m_AvailPartFrequency
[i
] = data
[i
];
985 tag
->GetRequests(&file
->statistic
.requested
);
986 tag
->GetAllRequests(&file
->statistic
.alltimerequested
);
987 tag
->GetAccepts(&file
->statistic
.accepted
);
988 tag
->GetAllAccepts(&file
->statistic
.alltimeaccepted
);
989 tag
->GetXferred(&file
->statistic
.transferred
);
990 tag
->GetAllXferred(&file
->statistic
.alltimetransferred
);
991 tag
->UpPrio(&file
->m_iUpPriorityEC
);
992 if (file
->m_iUpPriorityEC
>= 10) {
993 file
->m_iUpPriority
= file
->m_iUpPriorityEC
- 10;
994 file
->m_bAutoUpPriority
= true;
996 file
->m_iUpPriority
= file
->m_iUpPriorityEC
;
997 file
->m_bAutoUpPriority
= false;
999 tag
->GetCompleteSourcesLow(&file
->m_nCompleteSourcesCountLo
);
1000 tag
->GetCompleteSourcesHigh(&file
->m_nCompleteSourcesCountHi
);
1002 requested
+= file
->statistic
.requested
;
1003 transferred
+= file
->statistic
.transferred
;
1004 accepted
+= file
->statistic
.transferred
;
1006 theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
->UpdateItem(file
);
1008 if (file
->IsPartFile()) {
1009 ProcessItemUpdatePartfile((CEC_PartFile_Tag
*) tag
, (CPartFile
*) file
);
1013 void CSharedFilesRem::SetFilePrio(CKnownFile
*file
, uint8 prio
)
1015 CECPacket
req(EC_OP_SHARED_SET_PRIO
);
1017 CECTag
hashtag(EC_TAG_PARTFILE
, file
->GetFileHash());
1018 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_PRIO
, prio
));
1020 req
.AddTag(hashtag
);
1022 m_conn
->SendPacket(&req
);
1025 void CKnownFilesRem::ProcessUpdate(const CECPacket
*reply
, CECPacket
*, int)
1031 std::set
<uint32
> core_files
;
1032 for (size_t i
= 0;i
< reply
->GetTagCount();i
++) {
1033 CEC_SharedFile_Tag
*tag
= (CEC_SharedFile_Tag
*)reply
->GetTagByIndex(i
);
1034 uint32 id
= tag
->ID();
1035 core_files
.insert(id
);
1036 if ( m_items_hash
.count(id
) ) {
1037 // Item already known: update it
1038 ProcessItemUpdate(tag
, m_items_hash
[id
]);
1040 CKnownFile
* newFile
;
1041 if (tag
->GetTagName() == EC_TAG_PARTFILE
) {
1042 CPartFile
*file
= new CPartFile((CEC_PartFile_Tag
*) tag
);
1043 ProcessItemUpdate(tag
, file
);
1044 (*theApp
->downloadqueue
)[id
] = file
;
1045 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->AddFile(file
);
1048 newFile
= new CKnownFile(tag
);
1049 ProcessItemUpdate(tag
, newFile
);
1050 (*theApp
->sharedfiles
)[id
] = newFile
;
1051 theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
->ShowFile(newFile
);
1056 // remove items no longer present
1057 for(iterator it
= begin(); it
!= end();) {
1058 iterator it2
= it
++;
1059 if (!core_files
.count(GetItemID(*it2
))) {
1060 RemoveItem(it2
); // This calls DeleteItem, where it is removed from lists and views.
1065 CKnownFilesRem::CKnownFilesRem(CRemoteConnect
* conn
) : CRemoteContainer
<CKnownFile
, uint32
, CEC_SharedFile_Tag
>(conn
, true)
1074 * List of uploading and waiting clients.
1076 CUpDownClientListRem::CUpDownClientListRem(CRemoteConnect
*conn
, int viewtype
)
1078 CRemoteContainer
<CUpDownClient
, uint32
, CEC_UpDownClient_Tag
>(conn
, true)
1080 m_viewtype
= viewtype
;
1084 CUpDownClient::CUpDownClient(CEC_UpDownClient_Tag
*tag
) : CECID(tag
->ID())
1086 m_bRemoteQueueFull
= false;
1087 m_nUserIDHybrid
= tag
->UserID();
1088 m_Username
= tag
->ClientName();
1089 m_clientSoft
= tag
->ClientSoftware();
1090 m_clientVersionString
= GetSoftName(m_clientSoft
);
1091 m_clientSoftString
= m_clientVersionString
;
1092 m_bEmuleProtocol
= false;
1094 // The functions to retrieve m_clientVerString information are
1095 // currently in BaseClient.cpp, which is not linked in remote-gui app.
1096 // So, in the meantime, we use a tag sent from core.
1097 m_clientVerString
= tag
->SoftVerStr();
1098 m_strModVersion
= wxEmptyString
;
1099 wxString clientModString
;
1100 if (!clientModString
.IsEmpty()) {
1101 m_clientVerString
+= wxT(" - ") + clientModString
;
1103 m_fullClientVerString
= m_clientSoftString
+ wxT(" ") + m_clientVerString
;
1106 m_UserHash
= tag
->UserHash();
1109 m_nConnectIP
= m_dwUserIP
= tag
->UserIP();
1110 m_nUserPort
= tag
->UserPort();
1111 m_FullUserIP
= m_nConnectIP
;
1114 m_dwServerIP
= tag
->ServerIP();
1115 m_nServerPort
= tag
->ServerPort();
1116 m_ServerName
= tag
->ServerName();
1119 if (tag
->HaveFile()) {
1120 m_uploadingfile
= theApp
->knownfiles
->GetByID(tag
->FileID());
1122 m_uploadingfile
= NULL
;
1125 m_nCurSessionUp
= 0;
1127 credits
= new CClientCredits(new CreditStruct());
1130 uint16
CUpQueueRem::GetWaitingPosition(const CUpDownClient
*client
) const
1132 return client
->GetWaitingPosition();
1135 /* Warning: do common base */
1138 bool CUpDownClient::IsIdentified() const
1140 return m_identState
== IS_IDENTIFIED
;
1144 bool CUpDownClient::IsBadGuy() const
1146 return m_identState
== IS_IDBADGUY
;
1150 bool CUpDownClient::SUIFailed() const
1152 return m_identState
== IS_IDFAILED
;
1156 bool CUpDownClient::SUINeeded() const
1158 return m_identState
== IS_IDNEEDED
;
1162 bool CUpDownClient::SUINotSupported() const
1164 return m_identState
== IS_NOTAVAILABLE
;
1168 uint64
CUpDownClient::GetDownloadedTotal() const
1170 return credits
->GetDownloadedTotal();
1174 uint64
CUpDownClient::GetUploadedTotal() const
1176 return credits
->GetUploadedTotal();
1180 double CUpDownClient::GetScoreRatio() const
1182 return credits
->GetScoreRatio(GetIP(), theApp
->CryptoAvailable());
1188 CUpDownClient::~CUpDownClient()
1194 CUpDownClient
*CUpDownClientListRem::CreateItem(CEC_UpDownClient_Tag
*tag
)
1196 CUpDownClient
*client
= new CUpDownClient(tag
);
1197 ProcessItemUpdate(tag
, client
);
1199 theApp
->amuledlg
->m_transferwnd
->clientlistctrl
->InsertClient(client
, (ViewType
)m_viewtype
);
1205 void CUpDownClientListRem::DeleteItem(CUpDownClient
*client
)
1207 theApp
->amuledlg
->m_transferwnd
->clientlistctrl
->
1208 RemoveClient(client
, (ViewType
)m_viewtype
);
1213 uint32
CUpDownClientListRem::GetItemID(CUpDownClient
*client
)
1215 return client
->ECID();
1219 void CUpDownClientListRem::ProcessItemUpdate(
1220 CEC_UpDownClient_Tag
*tag
,
1221 CUpDownClient
*client
)
1223 tag
->UserID(&client
->m_nUserIDHybrid
);
1224 tag
->GetCurrentIdentState(&client
->m_identState
);
1225 tag
->HasObfuscatedConnection(&client
->m_hasbeenobfuscatinglately
);
1226 tag
->HasExtendedProtocol(&client
->m_bEmuleProtocol
);
1228 tag
->WaitingPosition(&client
->m_waitingPosition
);
1229 tag
->RemoteQueueRank(&client
->m_nRemoteQueueRank
);
1230 client
->m_bRemoteQueueFull
= client
->m_nRemoteQueueRank
== 0xffff;
1231 tag
->AskedCount(&client
->m_cAsked
);
1233 tag
->ClientDownloadState(&client
->m_nDownloadState
);
1234 tag
->ClientUploadState(&client
->m_nUploadState
);
1236 tag
->SpeedUp(&client
->m_nUpDatarate
);
1237 if ( client
->m_nDownloadState
== DS_DOWNLOADING
) {
1238 tag
->SpeedDown(&client
->kBpsDown
);
1240 client
->kBpsDown
= 0;
1243 tag
->WaitTime(&client
->m_WaitTime
);
1244 tag
->XferTime(&client
->m_UpStartTimeDelay
);
1245 tag
->LastReqTime(&client
->m_dwLastUpRequest
);
1246 tag
->QueueTime(&client
->m_WaitStartTime
);
1248 CreditStruct
*credit_struct
=
1249 (CreditStruct
*)client
->credits
->GetDataStruct();
1250 tag
->XferUp(&credit_struct
->uploaded
);
1251 tag
->XferUpSession(&client
->m_nTransferredUp
);
1253 tag
->XferDown(&credit_struct
->downloaded
);
1254 tag
->XferDownSession(&client
->m_nTransferredDown
);
1256 tag
->Score(&client
->m_score
);
1257 tag
->Rating(&client
->m_rating
);
1259 theApp
->amuledlg
->m_transferwnd
->clientlistctrl
->UpdateClient(client
,
1260 theApp
->amuledlg
->m_transferwnd
->clientlistctrl
->GetListView()); // Fixme, Listview shouldn't be required as parameter
1264 CUpQueueRem::CUpQueueRem(CRemoteConnect
*conn
)
1266 m_up_list(conn
, vtUploading
), m_wait_list(conn
, vtQueued
)
1272 * Download queue container: hold PartFiles with progress status
1277 bool CDownQueueRem::AddLink(const wxString
&link
, uint8 cat
)
1279 CECPacket
req(EC_OP_ADD_LINK
);
1280 CECTag
link_tag(EC_TAG_STRING
, link
);
1281 link_tag
.AddTag(CECTag(EC_TAG_PARTFILE_CAT
, cat
));
1282 req
.AddTag(link_tag
);
1284 m_conn
->SendPacket(&req
);
1289 void CDownQueueRem::ResetCatParts(int cat
)
1291 // Called when category is deleted. Command will be performed on the remote side,
1292 // but files still should be updated here right away, or drawing errors (colour not available)
1294 for (iterator it
= begin(); it
!= end(); it
++) {
1295 CPartFile
* file
= it
->second
;
1297 if ( file
->GetCategory() == cat
) {
1298 // Reset the category
1299 file
->SetCategory( 0 );
1300 } else if ( file
->GetCategory() > cat
) {
1301 // Set to the new position of the original category
1302 file
->SetCategory( file
->GetCategory() - 1 );
1309 void CKnownFilesRem::ProcessItemUpdatePartfile(CEC_PartFile_Tag
*tag
, CPartFile
*file
)
1314 tag
->Speed(&file
->m_kbpsDown
);
1315 file
->kBpsDown
= file
->m_kbpsDown
/ 1024.0;
1317 tag
->SizeXfer(&file
->transferred
);
1318 tag
->SizeDone(&file
->completedsize
);
1319 tag
->SourceXferCount(&file
->transferingsrc
);
1320 tag
->SourceNotCurrCount(&file
->m_notCurrentSources
);
1321 tag
->SourceCount(&file
->m_source_count
);
1322 tag
->SourceCountA4AF(&file
->m_a4af_source_count
);
1323 tag
->FileStatus(&file
->status
);
1324 tag
->Stopped(&file
->m_stopped
);
1326 tag
->LastSeenComplete(&file
->lastseencomplete
);
1327 tag
->LastDateChanged(&file
->m_lastDateChanged
);
1328 tag
->DownloadActiveTime(&file
->m_nDlActiveTime
);
1329 tag
->AvailablePartCount(&file
->m_availablePartsCount
);
1330 tag
->Shared(&file
->m_isShared
);
1332 tag
->GetLostDueToCorruption(&file
->m_iLostDueToCorruption
);
1333 tag
->GetGainDueToCompression(&file
->m_iGainDueToCompression
);
1334 tag
->TotalPacketsSavedDueToICH(&file
->m_iTotalPacketsSavedDueToICH
);
1336 tag
->FileCat(&file
->m_category
);
1338 tag
->DownPrio(&file
->m_iDownPriorityEC
);
1339 if ( file
->m_iDownPriorityEC
>= 10 ) {
1340 file
->m_iDownPriority
= file
->m_iDownPriorityEC
- 10;
1341 file
->m_bAutoDownPriority
= true;
1343 file
->m_iDownPriority
= file
->m_iDownPriorityEC
;
1344 file
->m_bAutoDownPriority
= false;
1347 file
->percentcompleted
= (100.0*file
->GetCompletedSize()) / file
->GetFileSize();
1350 // Copy part/gap status
1352 CECTag
*gaptag
= tag
->GetTagByName(EC_TAG_PARTFILE_GAP_STATUS
);
1353 CECTag
*parttag
= tag
->GetTagByName(EC_TAG_PARTFILE_PART_STATUS
);
1354 CECTag
*reqtag
= tag
->GetTagByName(EC_TAG_PARTFILE_REQ_STATUS
);
1355 if (gaptag
|| parttag
|| reqtag
) {
1356 PartFileEncoderData
&encoder
= file
->m_PartFileEncoderData
;
1359 ArrayOfUInts64 gaps
;
1360 encoder
.DecodeGaps(gaptag
, gaps
);
1361 int gap_size
= gaps
.size() / 2;
1363 file
->m_gaplist
.Init(file
->GetFileSize(), false);
1366 for (int j
= 0; j
< gap_size
; j
++) {
1367 file
->m_gaplist
.AddGap(gaps
[2*j
], gaps
[2*j
+1]);
1371 encoder
.DecodeParts(parttag
, file
->m_SrcpartFrequency
);
1373 wxASSERT (file
->m_SrcpartFrequency
.size() == file
->GetPartCount());
1376 ArrayOfUInts64 reqs
;
1377 encoder
.DecodeReqs(reqtag
, reqs
);
1378 int req_size
= reqs
.size() / 2;
1380 DeleteContents(file
->m_requestedblocks_list
);
1383 for (int j
= 0; j
< req_size
; j
++) {
1384 Requested_Block_Struct
* block
= new Requested_Block_Struct
;
1385 block
->StartOffset
= reqs
[2*j
];
1386 block
->EndOffset
= reqs
[2*j
+1];
1387 file
->m_requestedblocks_list
.push_back(block
);
1392 // Get source names and counts
1393 CECTag
*srcnametag
= tag
->GetTagByName(EC_TAG_PARTFILE_SOURCE_NAMES
);
1395 SourcenameItemMap
&map
= file
->GetSourcenameItemMap();
1396 size_t max
= srcnametag
->GetTagCount();
1397 for (size_t i
= 0; i
< max
; i
++) {
1398 CECTag
*ntag
= srcnametag
->GetTagByIndex(i
);
1399 uint32 key
= ntag
->GetInt();
1400 int count
= ntag
->GetTagByNameSafe(EC_TAG_PARTFILE_SOURCE_NAMES_COUNTS
)->GetInt();
1404 SourcenameItem
&item
= map
[key
];
1406 CECTag
*nametag
= ntag
->GetTagByName(EC_TAG_PARTFILE_SOURCE_NAMES
);
1408 item
.name
= nametag
->GetStringData();
1415 CECTag
*commenttag
= tag
->GetTagByName(EC_TAG_PARTFILE_COMMENTS
);
1417 file
->ClearFileRatingList();
1418 int max
= commenttag
->GetTagCount();
1419 for (int i
= 0; i
< max
- 3; ) {
1420 wxString u
= commenttag
->GetTagByIndex(i
++)->GetStringData();
1421 wxString f
= commenttag
->GetTagByIndex(i
++)->GetStringData();
1422 int r
= commenttag
->GetTagByIndex(i
++)->GetInt();
1423 wxString c
= commenttag
->GetTagByIndex(i
++)->GetStringData();
1424 file
->AddFileRatingList(u
, f
, r
, c
);
1426 file
->UpdateFileRatingCommentAvail();
1429 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->UpdateItem(file
);
1431 // If file is shared check if it is already listed in shared files.
1432 // If not, add it and show it.
1433 if (file
->IsShared() && !theApp
->sharedfiles
->count(file
->ECID())) {
1434 (*theApp
->sharedfiles
)[file
->ECID()] = file
;
1435 theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
->ShowFile(file
);
1440 void CDownQueueRem::SendFileCommand(CPartFile
*file
, ec_tagname_t cmd
)
1443 req
.AddTag(CECTag(EC_TAG_PARTFILE
, file
->GetFileHash()));
1445 m_conn
->SendPacket(&req
);
1449 void CDownQueueRem::Prio(CPartFile
*file
, uint8 prio
)
1451 CECPacket
req(EC_OP_PARTFILE_PRIO_SET
);
1453 CECTag
hashtag(EC_TAG_PARTFILE
, file
->GetFileHash());
1454 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_PRIO
, prio
));
1455 req
.AddTag(hashtag
);
1457 m_conn
->SendPacket(&req
);
1461 void CDownQueueRem::AutoPrio(CPartFile
*file
, bool flag
)
1463 CECPacket
req(EC_OP_PARTFILE_PRIO_SET
);
1465 CECTag
hashtag(EC_TAG_PARTFILE
, file
->GetFileHash());
1467 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_PRIO
,
1468 (uint8
)(flag
? PR_AUTO
: file
->GetDownPriority())));
1469 req
.AddTag(hashtag
);
1471 m_conn
->SendPacket(&req
);
1475 void CDownQueueRem::Category(CPartFile
*file
, uint8 cat
)
1477 CECPacket
req(EC_OP_PARTFILE_SET_CAT
);
1478 file
->SetCategory(cat
);
1480 CECTag
hashtag(EC_TAG_PARTFILE
, file
->GetFileHash());
1481 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_CAT
, cat
));
1482 req
.AddTag(hashtag
);
1484 m_conn
->SendPacket(&req
);
1488 void CDownQueueRem::AddSearchToDownload(CSearchFile
* file
, uint8 category
)
1490 CECPacket
req(EC_OP_DOWNLOAD_SEARCH_RESULT
);
1491 CECTag
hashtag(EC_TAG_PARTFILE
, file
->GetFileHash());
1492 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_CAT
, category
));
1493 req
.AddTag(hashtag
);
1495 m_conn
->SendPacket(&req
);
1499 // This is an ugly hack and to be deleted when GUI is unlocked!
1500 // (replacing iterate-by-index with iteration)
1501 // It will only work for linear iteration starting with 0 (as used in CTransferWnd::UpdateCategory)
1502 CPartFile
* CDownQueueRem::GetFileByIndex(unsigned int idx
)
1504 static CDownQueueRem::iterator it
;
1520 CClientListRem::CClientListRem(CRemoteConnect
*conn
)
1526 void CClientListRem::FilterQueues()
1533 CSearchListRem::CSearchListRem(CRemoteConnect
*conn
) : CRemoteContainer
<CSearchFile
, CMD4Hash
, CEC_SearchFile_Tag
>(conn
, true)
1539 wxString
CSearchListRem::StartNewSearch(
1540 uint32
* nSearchID
, SearchType search_type
,
1541 const CSearchList::CSearchParams
& params
)
1543 CECPacket
search_req(EC_OP_SEARCH_START
);
1544 EC_SEARCH_TYPE ec_search_type
= EC_SEARCH_LOCAL
;
1545 switch(search_type
) {
1546 case LocalSearch
: ec_search_type
= EC_SEARCH_LOCAL
; break;
1547 case GlobalSearch
: ec_search_type
= EC_SEARCH_GLOBAL
; break;
1548 case KadSearch
: ec_search_type
= EC_SEARCH_KAD
; break;
1551 CEC_Search_Tag(params
.searchString
, ec_search_type
,
1552 params
.typeText
, params
.extension
, params
.availability
,
1553 params
.minSize
, params
.maxSize
));
1555 m_conn
->SendPacket(&search_req
);
1556 m_curr_search
= *(nSearchID
); // No kad remote search yet.
1560 return wxEmptyString
; // EC reply will have the error mesg is needed.
1564 void CSearchListRem::StopGlobalSearch()
1566 if (m_curr_search
!= -1) {
1567 CECPacket
search_req(EC_OP_SEARCH_STOP
);
1568 m_conn
->SendPacket(&search_req
);
1573 void CSearchListRem::StopKadSearch()
1575 // FIXME implementation needed
1579 void CSearchListRem::HandlePacket(const CECPacket
*packet
)
1581 if ( packet
->GetOpCode() == EC_OP_SEARCH_PROGRESS
) {
1582 CoreNotify_Search_Update_Progress(packet
->GetTagByIndex(0)->GetInt());
1584 CRemoteContainer
<CSearchFile
, CMD4Hash
, CEC_SearchFile_Tag
>::HandlePacket(packet
);
1589 CSearchFile::CSearchFile(CEC_SearchFile_Tag
*tag
)
1592 m_showChildren(false),
1594 m_completeSourceCount(0),
1596 m_downloadStatus(NEW
),
1600 SetFileName(CPath(tag
->FileName()));
1601 m_abyFileHash
= tag
->ID();
1602 SetFileSize(tag
->SizeFull());
1604 m_searchID
= theApp
->searchlist
->m_curr_search
;
1609 // dtor is virtual - must be implemented
1610 CSearchFile::~CSearchFile()
1615 CSearchFile
*CSearchListRem::CreateItem(CEC_SearchFile_Tag
*tag
)
1617 CSearchFile
*file
= new CSearchFile(tag
);
1618 ProcessItemUpdate(tag
, file
);
1620 theApp
->amuledlg
->m_searchwnd
->AddResult(file
);
1626 void CSearchListRem::DeleteItem(CSearchFile
*file
)
1632 CMD4Hash
CSearchListRem::GetItemID(CSearchFile
*file
)
1634 return file
->GetFileHash();
1638 void CSearchListRem::ProcessItemUpdate(CEC_SearchFile_Tag
*tag
, CSearchFile
*file
)
1640 uint32 sourceCount
= file
->m_sourceCount
;
1641 uint32 completeSourceCount
= file
->m_completeSourceCount
;
1642 CSearchFile::DownloadStatus status
= file
->m_downloadStatus
;
1643 tag
->SourceCount(&file
->m_sourceCount
);
1644 tag
->CompleteSourceCount(&file
->m_completeSourceCount
);
1645 tag
->DownloadStatus((uint32
*) &file
->m_downloadStatus
);
1647 if (file
->m_sourceCount
!= sourceCount
1648 || file
->m_completeSourceCount
!= completeSourceCount
1649 || file
->m_downloadStatus
!= status
) {
1650 if (theApp
->amuledlg
&& theApp
->amuledlg
->m_searchwnd
) {
1651 theApp
->amuledlg
->m_searchwnd
->UpdateResult(file
);
1657 bool CSearchListRem::Phase1Done(const CECPacket
*WXUNUSED(reply
))
1659 CECPacket
progress_req(EC_OP_SEARCH_PROGRESS
);
1660 m_conn
->SendRequest(this, &progress_req
);
1666 void CSearchListRem::RemoveResults(long nSearchID
)
1668 ResultMap::iterator it
= m_results
.find(nSearchID
);
1669 if (it
!= m_results
.end()) {
1670 CSearchResultList
& list
= it
->second
;
1671 for (unsigned int i
= 0; i
< list
.size(); ++i
) {
1674 m_results
.erase(it
);
1679 const CSearchResultList
& CSearchListRem::GetSearchResults(long nSearchID
)
1681 ResultMap::const_iterator it
= m_results
.find(nSearchID
);
1682 if (it
!= m_results
.end()) {
1686 // TODO: Should we assert in this case?
1687 static CSearchResultList list
;
1692 void CStatsUpdaterRem::HandlePacket(const CECPacket
*packet
)
1694 theStats::UpdateStats(packet
);
1695 theApp
->ShowUserCount(); // maybe there should be a check if a usercount changed ?
1699 bool CUpDownClient::IsBanned() const
1707 // Those functions have different implementation in remote gui
1709 void CUpDownClient::Ban()
1716 void CUpDownClient::UnBan()
1723 void CUpDownClient::RequestSharedFileList()
1730 void CKnownFile::SetFileComment(const wxString
&)
1733 wxMessageBox(_("Comments and ratings are not supported on remote gui yet"), _("Information"), wxOK
| wxICON_INFORMATION
);
1737 void CKnownFile::SetFileRating(unsigned char)
1743 // I don't think it will be implemented - too match data transfer. But who knows ?
1744 wxString
CUpDownClient::ShowDownloadingParts() const
1746 return wxEmptyString
;
1750 bool CUpDownClient::SwapToAnotherFile(
1751 bool WXUNUSED(bIgnoreNoNeeded
),
1752 bool WXUNUSED(ignoreSuspensions
),
1753 bool WXUNUSED(bRemoveCompletely
),
1754 CPartFile
* WXUNUSED(toFile
))
1763 // Those functions are virtual. So even they don't get called they must
1764 // be defined so linker will be happy
1766 CPacket
* CKnownFile::CreateSrcInfoPacket(const CUpDownClient
*, uint8
/*byRequestedVersion*/, uint16
/*nRequestedOptions*/)
1773 bool CKnownFile::LoadFromFile(const class CFileDataIO
*)
1780 void CKnownFile::UpdatePartsInfo()
1786 CPacket
* CPartFile::CreateSrcInfoPacket(CUpDownClient
const *, uint8
/*byRequestedVersion*/, uint16
/*nRequestedOptions*/)
1793 void CPartFile::UpdatePartsInfo()
1799 void CPartFile::UpdateFileRatingCommentAvail()
1801 bool prevComment
= m_hasComment
;
1802 int prevRating
= m_iUserRating
;
1804 m_hasComment
= false;
1806 int ratingCount
= 0;
1808 FileRatingList::iterator it
= m_FileRatingList
.begin();
1809 for (; it
!= m_FileRatingList
.end(); ++it
) {
1810 SFileRating
& cur_rat
= *it
;
1812 if (!cur_rat
.Comment
.IsEmpty()) {
1813 m_hasComment
= true;
1816 uint8 rating
= cur_rat
.Rating
;
1818 wxASSERT(rating
<= 5);
1821 m_iUserRating
+= rating
;
1826 m_iUserRating
/= ratingCount
;
1827 wxASSERT(m_iUserRating
> 0 && m_iUserRating
<= 5);
1830 if ((prevComment
!= m_hasComment
) || (prevRating
!= m_iUserRating
)) {
1831 UpdateDisplayedInfo();
1835 bool CPartFile::SavePartFile(bool)
1841 CamuleRemoteGuiApp
*theApp
;
1844 // since gui is not linked with amule.cpp - define events here
1846 DEFINE_LOCAL_EVENT_TYPE(wxEVT_CORE_FINISHED_HTTP_DOWNLOAD
)
1847 DEFINE_LOCAL_EVENT_TYPE(wxEVT_CORE_SOURCE_DNS_DONE
)
1848 DEFINE_LOCAL_EVENT_TYPE(wxEVT_CORE_UDP_DNS_DONE
)
1849 DEFINE_LOCAL_EVENT_TYPE(wxEVT_CORE_SERVER_DNS_DONE
)
1850 // File_checked_for_headers