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 wxConfig::Get()->Read(wxT("/EC/ZLIB"), &enableZLIB
, 1);
265 m_connect
->SetCapabilities(enableZLIB
!= 0, true, false); // ZLIB, UTF8 numbers, notification
267 InitCustomLanguages();
268 InitLocale(m_locale
, StrLang2wx(thePrefs::GetLanguageID()));
270 if (ShowConnectionDialog()) {
271 AddLogLineNS(_("Going to event loop..."));
279 bool CamuleRemoteGuiApp::CryptoAvailable() const
281 return thePrefs::IsSecureIdentEnabled(); // good enough
285 bool CamuleRemoteGuiApp::ShowConnectionDialog()
287 dialog
= new CEConnectDlg
;
289 if (m_skipConnectionDialog
) {
292 } else if (dialog
->ShowModal() != wxID_OK
) {
297 AddLogLineNS(_("Connecting..."));
298 if (!m_connect
->ConnectToCore(dialog
->Host(), dialog
->Port(),
299 dialog
->Login(), dialog
->PassHash(),
300 wxT("amule-remote"), wxT("0x0001"))) {
301 wxMessageBox(_("Connection failed "),_("ERROR"),wxOK
);
310 void CamuleRemoteGuiApp::OnECConnection(wxEvent
& event
) {
311 wxECSocketEvent
& evt
= *((wxECSocketEvent
*)&event
);
312 AddLogLineNS(_("Remote GUI EC event handler"));
313 wxString reply
= evt
.GetServerReply();
314 AddLogLineM(true, reply
);
315 if (evt
.GetResult() == true) {
316 // Connected - go to next init step
317 glob_prefs
->LoadRemote();
319 AddLogLineNS(_("Going down"));
320 if (dialog
) { // connect failed
322 (CFormat(_("Connection Failed. Unable to connect to %s:%d\n")) % dialog
->Host() % dialog
->Port()) + reply
,
324 } else { // server disconnected (probably terminated) later
325 wxMessageBox(_("Connection closed - aMule has terminated probably."), _("ERROR"), wxOK
);
332 void CamuleRemoteGuiApp::OnECInitDone(wxEvent
& )
338 void CamuleRemoteGuiApp::OnNotifyEvent(CMuleGUIEvent
& evt
)
344 void CamuleRemoteGuiApp::Startup() {
346 if (dialog
->SaveUserPass()) {
347 wxConfig::Get()->Write(wxT("/EC/Host"), dialog
->Host());
348 wxConfig::Get()->Write(wxT("/EC/Port"), dialog
->Port());
349 wxConfig::Get()->Write(wxT("/EC/Password"), dialog
->PassHash());
357 serverconnect
= new CServerConnectRem(m_connect
);
358 m_statistics
= new CStatistics(*m_connect
);
360 clientlist
= new CClientListRem(m_connect
);
361 searchlist
= new CSearchListRem(m_connect
);
362 serverlist
= new CServerListRem(m_connect
);
364 sharedfiles
= new CSharedFilesRem(m_connect
);
365 knownfiles
= new CKnownFilesRem(m_connect
);
367 // bugfix - do this before creating the uploadqueue
368 downloadqueue
= new CDownQueueRem(m_connect
);
369 uploadqueue
= new CUpQueueRem(m_connect
);
370 ipfilter
= new CIPFilterRem(m_connect
);
372 // Create main dialog
373 InitGui(m_geometryEnabled
, m_geometryString
);
375 // Forward wxLog events to CLogger
376 wxLog::SetActiveTarget(new CLoggerTarget
);
377 serverlist
->FullReload(EC_OP_GET_SERVER_LIST
);
378 knownfiles
->DoRequery(EC_OP_GET_UPDATE
, EC_TAG_KNOWNFILE
);
380 // Start the Poll Timer
381 poll_timer
->Start(1000);
382 amuledlg
->StartGuiTimer();
384 // Now activate GeoIP, so that the download dialog doesn't get destroyed immediately
385 #ifdef ENABLE_IP2COUNTRY
386 if (thePrefs::IsGeoIPEnabled()) {
387 amuledlg
->m_IP2Country
->Enable();
393 int CamuleRemoteGuiApp::ShowAlert(wxString msg
, wxString title
, int flags
)
395 return CamuleGuiBase::ShowAlert(msg
, title
, flags
);
399 void CamuleRemoteGuiApp::AddRemoteLogLine(const wxString
& line
)
401 amuledlg
->AddLogLine(line
);
404 int CamuleRemoteGuiApp::InitGui(bool geometry_enabled
, wxString
&geom_string
)
406 CamuleGuiBase::InitGui(geometry_enabled
, geom_string
);
407 SetTopWindow(amuledlg
);
408 AddLogLineN(_("Ready")); // The first log line after the window is up triggers output of all the ones before
413 bool CamuleRemoteGuiApp::CopyTextToClipboard(wxString strText
)
415 return CamuleGuiBase::CopyTextToClipboard(strText
);
419 uint32
CamuleRemoteGuiApp::GetPublicIP()
425 wxString
CamuleRemoteGuiApp::GetLog(bool)
427 return wxEmptyString
;
431 wxString
CamuleRemoteGuiApp::GetServerLog(bool)
433 return wxEmptyString
;
437 bool CamuleRemoteGuiApp::AddServer(CServer
*, bool)
439 // #warning TODO: Add remote command
444 bool CamuleRemoteGuiApp::IsFirewalled() const
446 if (IsConnectedED2K() && !serverconnect
->IsLowID()) {
450 return IsFirewalledKad();
454 bool CamuleRemoteGuiApp::IsConnectedED2K() const {
455 return serverconnect
&& serverconnect
->IsConnected();
459 void CamuleRemoteGuiApp::StartKad() {
460 m_connect
->StartKad();
464 void CamuleRemoteGuiApp::StopKad() {
465 m_connect
->StopKad();
469 void CamuleRemoteGuiApp::BootstrapKad(uint32 ip
, uint16 port
)
471 CECPacket
req(EC_OP_KAD_BOOTSTRAP_FROM_IP
);
472 req
.AddTag(CECTag(EC_TAG_BOOTSTRAP_IP
, ip
));
473 req
.AddTag(CECTag(EC_TAG_BOOTSTRAP_PORT
, port
));
475 m_connect
->SendPacket(&req
);
479 void CamuleRemoteGuiApp::UpdateNotesDat(const wxString
& url
)
481 CECPacket
req(EC_OP_KAD_UPDATE_FROM_URL
);
482 req
.AddTag(CECTag(EC_TAG_KADEMLIA_UPDATE_URL
, url
));
484 m_connect
->SendPacket(&req
);
488 void CamuleRemoteGuiApp::DisconnectED2K() {
489 if (IsConnectedED2K()) {
490 m_connect
->DisconnectED2K();
495 uint32
CamuleRemoteGuiApp::GetED2KID() const
497 return serverconnect
? serverconnect
->GetClientID() : 0;
501 uint32
CamuleRemoteGuiApp::GetID() const
507 void CamuleRemoteGuiApp::ShowUserCount() {
510 static const wxString s_singlenetstatusformat
= _("Users: %s | Files: %s");
511 static const wxString s_bothnetstatusformat
= _("Users: E: %s K: %s | Files: E: %s K: %s");
513 if (thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia()) {
514 buffer
= CFormat(s_bothnetstatusformat
) % CastItoIShort(theStats::GetED2KUsers()) % CastItoIShort(theStats::GetKadUsers()) % CastItoIShort(theStats::GetED2KFiles()) % CastItoIShort(theStats::GetKadFiles());
515 } else if (thePrefs::GetNetworkED2K()) {
516 buffer
= CFormat(s_singlenetstatusformat
) % CastItoIShort(theStats::GetED2KUsers()) % CastItoIShort(theStats::GetED2KFiles());
517 } else if (thePrefs::GetNetworkKademlia()) {
518 buffer
= CFormat(s_singlenetstatusformat
) % CastItoIShort(theStats::GetKadUsers()) % CastItoIShort(theStats::GetKadFiles());
520 buffer
= _("No networks selected");
523 Notify_ShowUserCount(buffer
);
528 * Preferences: holds both local and remote settings.
530 * First, everything is loaded from local config file. Later, settings
531 * that are relevant on remote side only are loaded thru EC
533 CPreferencesRem::CPreferencesRem(CRemoteConnect
*conn
)
538 // Settings queried from remote side
540 m_exchange_send_selected_prefs
=
542 EC_PREFS_CONNECTIONS
|
543 EC_PREFS_MESSAGEFILTER
|
548 EC_PREFS_DIRECTORIES
|
550 EC_PREFS_CORETWEAKS
|
551 EC_PREFS_REMOTECONTROLS
|
553 m_exchange_recv_selected_prefs
=
554 m_exchange_send_selected_prefs
|
559 void CPreferencesRem::HandlePacket(const CECPacket
*packet
)
561 ((CEC_Prefs_Packet
*)packet
)->Apply();
563 const CECTag
*cat_tags
= packet
->GetTagByName(EC_TAG_PREFS_CATEGORIES
);
565 for (CECTag::const_iterator it
= cat_tags
->begin(); it
!= cat_tags
->end(); it
++) {
566 const CECTag
&cat_tag
= *it
;
567 Category_Struct
*cat
= new Category_Struct
;
568 cat
->title
= cat_tag
.GetTagByName(EC_TAG_CATEGORY_TITLE
)->GetStringData();
569 cat
->path
= CPath(cat_tag
.GetTagByName(EC_TAG_CATEGORY_PATH
)->GetStringData());
570 cat
->comment
= cat_tag
.GetTagByName(EC_TAG_CATEGORY_COMMENT
)->GetStringData();
571 cat
->color
= cat_tag
.GetTagByName(EC_TAG_CATEGORY_COLOR
)->GetInt();
572 cat
->prio
= cat_tag
.GetTagByName(EC_TAG_CATEGORY_PRIO
)->GetInt();
573 theApp
->glob_prefs
->AddCat(cat
);
576 Category_Struct
*cat
= new Category_Struct
;
577 cat
->title
= _("All");
579 cat
->prio
= PR_NORMAL
;
580 theApp
->glob_prefs
->AddCat(cat
);
582 wxECInitDoneEvent event
;
583 theApp
->AddPendingEvent(event
);
588 bool CPreferencesRem::LoadRemote()
591 // override local settings with remote
592 CECPacket
req(EC_OP_GET_PREFERENCES
, EC_DETAIL_UPDATE
);
594 // bring categories too
595 req
.AddTag(CECTag(EC_TAG_SELECT_PREFS
, m_exchange_recv_selected_prefs
));
597 m_conn
->SendRequest(this, &req
);
603 void CPreferencesRem::SendToRemote()
605 CEC_Prefs_Packet
pref_packet(m_exchange_send_selected_prefs
, EC_DETAIL_UPDATE
, EC_DETAIL_FULL
);
606 m_conn
->SendPacket(&pref_packet
);
610 class CCatHandler
: public CECPacketHandlerBase
{
611 virtual void HandlePacket(const CECPacket
*packet
);
615 void CCatHandler::HandlePacket(const CECPacket
*packet
)
617 if (packet
->GetOpCode() == EC_OP_FAILED
) {
618 const CECTag
* catTag
= packet
->GetTagByName(EC_TAG_CATEGORY
);
619 const CECTag
* pathTag
= packet
->GetTagByName(EC_TAG_CATEGORY_PATH
);
620 if (catTag
&& pathTag
&& catTag
->GetInt() < theApp
->glob_prefs
->GetCatCount()) {
621 int cat
= catTag
->GetInt();
622 Category_Struct
* cs
= theApp
->glob_prefs
->GetCategory(cat
);
623 wxMessageBox(CFormat(_("Can't create directory '%s' for category '%s', keeping directory '%s'."))
624 % cs
->path
.GetPrintable() % cs
->title
% pathTag
->GetStringData(),
626 cs
->path
= CPath(pathTag
->GetStringData());
627 theApp
->amuledlg
->m_transferwnd
->UpdateCategory(cat
);
628 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->Refresh();
635 bool CPreferencesRem::CreateCategory(
636 Category_Struct
*& category
,
637 const wxString
& name
,
639 const wxString
& comment
,
643 CECPacket
req(EC_OP_CREATE_CATEGORY
);
644 CEC_Category_Tag
tag(0xffffffff, name
, path
.GetRaw(), comment
, color
, prio
);
646 m_conn
->SendRequest(new CCatHandler
, &req
);
648 category
= new Category_Struct();
649 category
->path
= path
;
650 category
->title
= name
;
651 category
->comment
= comment
;
652 category
->color
= color
;
653 category
->prio
= prio
;
661 bool CPreferencesRem::UpdateCategory(
663 const wxString
& name
,
665 const wxString
& comment
,
669 CECPacket
req(EC_OP_UPDATE_CATEGORY
);
670 CEC_Category_Tag
tag(cat
, name
, path
.GetRaw(), comment
, color
, prio
);
672 m_conn
->SendRequest(new CCatHandler
, &req
);
674 Category_Struct
*category
= m_CatList
[cat
];
675 category
->path
= path
;
676 category
->title
= name
;
677 category
->comment
= comment
;
678 category
->color
= color
;
679 category
->prio
= prio
;
685 void CPreferencesRem::RemoveCat(uint8 cat
)
687 CECPacket
req(EC_OP_DELETE_CATEGORY
);
688 CEC_Category_Tag
tag(cat
, EC_DETAIL_CMD
);
690 m_conn
->SendPacket(&req
);
691 CPreferences::RemoveCat(cat
);
696 // Container implementation
698 CServerConnectRem::CServerConnectRem(CRemoteConnect
*conn
)
705 void CServerConnectRem::ConnectToAnyServer()
707 CECPacket
req(EC_OP_SERVER_CONNECT
);
708 m_Conn
->SendPacket(&req
);
712 void CServerConnectRem::StopConnectionTry()
714 // lfroen: isn't Disconnect the same ?
718 void CServerConnectRem::Disconnect()
720 CECPacket
req(EC_OP_SERVER_DISCONNECT
);
721 m_Conn
->SendPacket(&req
);
725 void CServerConnectRem::ConnectToServer(CServer
*server
)
727 m_Conn
->ConnectED2K(server
->GetIP(), server
->GetPort());
731 bool CServerConnectRem::ReQuery()
733 CECPacket
stat_req(EC_OP_GET_CONNSTATE
);
734 m_Conn
->SendRequest(this, &stat_req
);
740 void CServerConnectRem::HandlePacket(const CECPacket
*packet
)
742 CEC_ConnState_Tag
*tag
=
743 (CEC_ConnState_Tag
*)packet
->GetTagByName(EC_TAG_CONNSTATE
);
748 theApp
->m_ConnState
= 0;
750 m_ID
= tag
->GetEd2kId();
751 theApp
->m_clientID
= tag
->GetClientId();
753 if (tag
->IsConnectedED2K()) {
754 CECTag
*srvtag
= tag
->GetTagByName(EC_TAG_SERVER
);
758 server
= theApp
->serverlist
->GetByID(srvtag
->GetIPv4Data().IP());
759 if (m_CurrServer
&& (server
!= m_CurrServer
)) {
760 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->
761 HighlightServer(m_CurrServer
, false);
763 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->
764 HighlightServer(server
, true);
765 m_CurrServer
= server
;
766 theApp
->m_ConnState
|= CONNECTED_ED2K
;
768 if ( m_CurrServer
) {
769 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->
770 HighlightServer(m_CurrServer
, false);
775 if (tag
->IsConnectedKademlia()) {
776 if (tag
->IsKadFirewalled()) {
777 theApp
->m_ConnState
|= CONNECTED_KAD_FIREWALLED
;
779 theApp
->m_ConnState
|= CONNECTED_KAD_OK
;
782 if (tag
->IsKadRunning()) {
783 theApp
->m_ConnState
|= CONNECTED_KAD_NOT
;
787 theApp
->amuledlg
->ShowConnectionState();
792 * Server list: host list of ed2k servers.
794 CServerListRem::CServerListRem(CRemoteConnect
*conn
)
796 CRemoteContainer
<CServer
, uint32
, CEC_Server_Tag
>(conn
, false)
801 void CServerListRem::HandlePacket(const CECPacket
*packet
)
803 CRemoteContainer
<CServer
, uint32
, CEC_Server_Tag
>::HandlePacket(packet
);
808 void CServerListRem::UpdateServerMetFromURL(wxString url
)
810 CECPacket
req(EC_OP_SERVER_UPDATE_FROM_URL
);
811 req
.AddTag(CECTag(EC_TAG_SERVERS_UPDATE_URL
, url
));
813 m_conn
->SendPacket(&req
);
817 void CServerListRem::SaveServerMet()
819 // lfroen: stub, nothing to do
823 void CServerListRem::FilterServers()
830 void CServerListRem::RemoveServer(CServer
* server
)
832 m_conn
->RemoveServer(server
->GetIP(),server
->GetPort());
836 void CServerListRem::UpdateUserFileStatus(CServer
*server
)
839 m_TotalUser
= server
->GetUsers();
840 m_TotalFile
= server
->GetFiles();
845 CServer
*CServerListRem::GetServerByAddress(const wxString
& WXUNUSED(address
), uint16
WXUNUSED(port
)) const
847 // It's ok to return 0 for context where this code is used in remote gui
851 CServer
*CServerListRem::GetServerByIPTCP(uint32
WXUNUSED(nIP
), uint16
WXUNUSED(nPort
)) const
853 // It's ok to return 0 for context where this code is used in remote gui
857 CServer
*CServerListRem::CreateItem(CEC_Server_Tag
*tag
)
859 return new CServer(tag
);
863 void CServerListRem::DeleteItem(CServer
*in_srv
)
865 CScopedPtr
<CServer
> srv(in_srv
);
866 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->RemoveServer(srv
.get());
870 uint32
CServerListRem::GetItemID(CServer
*server
)
872 return server
->GetIP();
876 void CServerListRem::ProcessItemUpdate(CEC_Server_Tag
*, CServer
*)
878 // server list is always realoaded from scratch
883 void CServerListRem::ReloadControl()
885 for(iterator it
= begin(); it
!= end(); it
++) {
887 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->RefreshServer(srv
);
892 CIPFilterRem::CIPFilterRem(CRemoteConnect
* conn
)
898 void CIPFilterRem::Reload()
900 CECPacket
req(EC_OP_IPFILTER_RELOAD
);
901 m_conn
->SendPacket(&req
);
905 void CIPFilterRem::Update(wxString url
)
907 CECPacket
req(EC_OP_IPFILTER_UPDATE
);
908 req
.AddTag(CECTag(EC_TAG_STRING
, url
));
910 m_conn
->SendPacket(&req
);
917 CSharedFilesRem::CSharedFilesRem(CRemoteConnect
*conn
)
923 void CSharedFilesRem::Reload(bool, bool)
925 CECPacket
req(EC_OP_SHAREDFILES_RELOAD
);
927 m_conn
->SendPacket(&req
);
931 void CSharedFilesRem::AddFilesFromDirectory(const CPath
& path
)
933 CECPacket
req(EC_OP_SHAREDFILES_ADD_DIRECTORY
);
935 req
.AddTag(CECTag(EC_TAG_PREFS_DIRECTORIES
, path
.GetRaw()));
937 m_conn
->SendPacket(&req
);
941 bool CSharedFilesRem::RenameFile(CKnownFile
* file
, const CPath
& newName
)
943 // We use the printable name, as the filename originated from user input,
944 // and the filesystem name might not be valid on the remote host.
945 const wxString strNewName
= newName
.GetPrintable();
947 CECPacket
request(EC_OP_RENAME_FILE
);
948 request
.AddTag(CECTag(EC_TAG_KNOWNFILE
, file
->GetFileHash()));
949 request
.AddTag(CECTag(EC_TAG_PARTFILE_NAME
, strNewName
));
951 m_conn
->SendPacket(&request
);
957 void CKnownFilesRem::DeleteItem(CKnownFile
* file
)
959 uint32 id
= file
->ECID();
960 if (theApp
->sharedfiles
->count(id
)) {
961 theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
->RemoveFile(file
);
962 theApp
->sharedfiles
->erase(id
);
964 if (theApp
->downloadqueue
->count(id
)) {
965 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->RemoveFile((CPartFile
*) file
);
966 theApp
->downloadqueue
->erase(id
);
972 uint32
CKnownFilesRem::GetItemID(CKnownFile
*file
)
978 void CKnownFilesRem::ProcessItemUpdate(CEC_SharedFile_Tag
*tag
, CKnownFile
*file
)
980 CECTag
*parttag
= tag
->GetTagByName(EC_TAG_PARTFILE_PART_STATUS
);
982 const uint8
*data
= file
->m_partStatus
.Decode(
983 (uint8
*)parttag
->GetTagData(),
984 parttag
->GetTagDataLen());
985 for(int i
= 0; i
< file
->GetPartCount(); ++i
) {
986 file
->m_AvailPartFrequency
[i
] = data
[i
];
989 tag
->GetRequests(&file
->statistic
.requested
);
990 tag
->GetAllRequests(&file
->statistic
.alltimerequested
);
991 tag
->GetAccepts(&file
->statistic
.accepted
);
992 tag
->GetAllAccepts(&file
->statistic
.alltimeaccepted
);
993 tag
->GetXferred(&file
->statistic
.transferred
);
994 tag
->GetAllXferred(&file
->statistic
.alltimetransferred
);
995 tag
->UpPrio(&file
->m_iUpPriorityEC
);
996 if (file
->m_iUpPriorityEC
>= 10) {
997 file
->m_iUpPriority
= file
->m_iUpPriorityEC
- 10;
998 file
->m_bAutoUpPriority
= true;
1000 file
->m_iUpPriority
= file
->m_iUpPriorityEC
;
1001 file
->m_bAutoUpPriority
= false;
1003 tag
->GetCompleteSourcesLow(&file
->m_nCompleteSourcesCountLo
);
1004 tag
->GetCompleteSourcesHigh(&file
->m_nCompleteSourcesCountHi
);
1005 tag
->GetCompleteSources(&file
->m_nCompleteSourcesCount
);
1007 tag
->GetOnQueue(&file
->m_queuedCount
);
1009 requested
+= file
->statistic
.requested
;
1010 transferred
+= file
->statistic
.transferred
;
1011 accepted
+= file
->statistic
.transferred
;
1013 theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
->UpdateItem(file
);
1015 if (file
->IsPartFile()) {
1016 ProcessItemUpdatePartfile((CEC_PartFile_Tag
*) tag
, (CPartFile
*) file
);
1020 void CSharedFilesRem::SetFilePrio(CKnownFile
*file
, uint8 prio
)
1022 CECPacket
req(EC_OP_SHARED_SET_PRIO
);
1024 CECTag
hashtag(EC_TAG_PARTFILE
, file
->GetFileHash());
1025 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_PRIO
, prio
));
1027 req
.AddTag(hashtag
);
1029 m_conn
->SendPacket(&req
);
1032 void CKnownFilesRem::ProcessUpdate(const CECPacket
*reply
, CECPacket
*, int)
1038 std::set
<uint32
> core_files
;
1039 for (CECPacket::const_iterator it
= reply
->begin(); it
!= reply
->end(); it
++) {
1040 CEC_SharedFile_Tag
*tag
= (CEC_SharedFile_Tag
*) & *it
;
1041 uint32 id
= tag
->ID();
1042 core_files
.insert(id
);
1043 if ( m_items_hash
.count(id
) ) {
1044 // Item already known: update it
1045 ProcessItemUpdate(tag
, m_items_hash
[id
]);
1047 CKnownFile
* newFile
;
1048 if (tag
->GetTagName() == EC_TAG_PARTFILE
) {
1049 CPartFile
*file
= new CPartFile((CEC_PartFile_Tag
*) tag
);
1050 ProcessItemUpdate(tag
, file
);
1051 // GUI doesn't allow clear finished files well at the moment,
1052 // so don't show finished files for now until GUI gets unlocked.
1053 // Files completing while GUI is open will still show.
1054 if (file
->IsPartFile()) {
1055 (*theApp
->downloadqueue
)[id
] = file
;
1056 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->AddFile(file
);
1060 newFile
= new CKnownFile(tag
);
1061 ProcessItemUpdate(tag
, newFile
);
1062 (*theApp
->sharedfiles
)[id
] = newFile
;
1063 theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
->ShowFile(newFile
);
1068 // remove items no longer present
1069 for(iterator it
= begin(); it
!= end();) {
1070 iterator it2
= it
++;
1071 if (!core_files
.count(GetItemID(*it2
))) {
1072 RemoveItem(it2
); // This calls DeleteItem, where it is removed from lists and views.
1077 CKnownFilesRem::CKnownFilesRem(CRemoteConnect
* conn
) : CRemoteContainer
<CKnownFile
, uint32
, CEC_SharedFile_Tag
>(conn
, true)
1086 * List of uploading and waiting clients.
1088 CUpDownClientListRem::CUpDownClientListRem(CRemoteConnect
*conn
, int viewtype
)
1090 CRemoteContainer
<CUpDownClient
, uint32
, CEC_UpDownClient_Tag
>(conn
, true)
1092 m_viewtype
= viewtype
;
1096 CUpDownClient::CUpDownClient(CEC_UpDownClient_Tag
*tag
) : CECID(tag
->ID())
1098 m_bRemoteQueueFull
= false;
1099 m_nUserIDHybrid
= tag
->UserID();
1100 m_Username
= tag
->ClientName();
1101 m_clientSoft
= tag
->ClientSoftware();
1102 m_clientVersionString
= GetSoftName(m_clientSoft
);
1103 m_clientSoftString
= m_clientVersionString
;
1104 m_bEmuleProtocol
= false;
1106 // The functions to retrieve m_clientVerString information are
1107 // currently in BaseClient.cpp, which is not linked in remote-gui app.
1108 // So, in the meantime, we use a tag sent from core.
1109 m_clientVerString
= tag
->SoftVerStr();
1110 m_strModVersion
= wxEmptyString
;
1111 wxString clientModString
;
1112 if (!clientModString
.IsEmpty()) {
1113 m_clientVerString
+= wxT(" - ") + clientModString
;
1115 m_fullClientVerString
= m_clientSoftString
+ wxT(" ") + m_clientVerString
;
1118 m_UserHash
= tag
->UserHash();
1121 m_nConnectIP
= m_dwUserIP
= tag
->UserIP();
1122 m_nUserPort
= tag
->UserPort();
1123 m_FullUserIP
= m_nConnectIP
;
1126 m_dwServerIP
= tag
->ServerIP();
1127 m_nServerPort
= tag
->ServerPort();
1128 m_ServerName
= tag
->ServerName();
1131 if (tag
->HaveFile()) {
1132 m_uploadingfile
= theApp
->knownfiles
->GetByID(tag
->FileID());
1134 m_uploadingfile
= NULL
;
1137 m_nCurSessionUp
= 0;
1139 credits
= new CClientCredits(new CreditStruct());
1142 uint16
CUpQueueRem::GetWaitingPosition(const CUpDownClient
*client
) const
1144 return client
->GetWaitingPosition();
1147 /* Warning: do common base */
1150 bool CUpDownClient::IsIdentified() const
1152 return m_identState
== IS_IDENTIFIED
;
1156 bool CUpDownClient::IsBadGuy() const
1158 return m_identState
== IS_IDBADGUY
;
1162 bool CUpDownClient::SUIFailed() const
1164 return m_identState
== IS_IDFAILED
;
1168 bool CUpDownClient::SUINeeded() const
1170 return m_identState
== IS_IDNEEDED
;
1174 bool CUpDownClient::SUINotSupported() const
1176 return m_identState
== IS_NOTAVAILABLE
;
1180 uint64
CUpDownClient::GetDownloadedTotal() const
1182 return credits
->GetDownloadedTotal();
1186 uint64
CUpDownClient::GetUploadedTotal() const
1188 return credits
->GetUploadedTotal();
1192 double CUpDownClient::GetScoreRatio() const
1194 return credits
->GetScoreRatio(GetIP(), theApp
->CryptoAvailable());
1200 CUpDownClient::~CUpDownClient()
1206 CUpDownClient
*CUpDownClientListRem::CreateItem(CEC_UpDownClient_Tag
*tag
)
1208 CUpDownClient
*client
= new CUpDownClient(tag
);
1209 ProcessItemUpdate(tag
, client
);
1211 theApp
->amuledlg
->m_transferwnd
->clientlistctrl
->InsertClient(client
, (ViewType
)m_viewtype
);
1217 void CUpDownClientListRem::DeleteItem(CUpDownClient
*client
)
1219 theApp
->amuledlg
->m_transferwnd
->clientlistctrl
->
1220 RemoveClient(client
, (ViewType
)m_viewtype
);
1225 uint32
CUpDownClientListRem::GetItemID(CUpDownClient
*client
)
1227 return client
->ECID();
1231 void CUpDownClientListRem::ProcessItemUpdate(
1232 CEC_UpDownClient_Tag
*tag
,
1233 CUpDownClient
*client
)
1235 tag
->UserID(&client
->m_nUserIDHybrid
);
1236 tag
->GetCurrentIdentState(&client
->m_identState
);
1237 tag
->HasObfuscatedConnection(&client
->m_hasbeenobfuscatinglately
);
1238 tag
->HasExtendedProtocol(&client
->m_bEmuleProtocol
);
1240 tag
->WaitingPosition(&client
->m_waitingPosition
);
1241 tag
->RemoteQueueRank(&client
->m_nRemoteQueueRank
);
1242 client
->m_bRemoteQueueFull
= client
->m_nRemoteQueueRank
== 0xffff;
1243 tag
->AskedCount(&client
->m_cAsked
);
1245 tag
->ClientDownloadState(&client
->m_nDownloadState
);
1246 tag
->ClientUploadState(&client
->m_nUploadState
);
1248 tag
->SpeedUp(&client
->m_nUpDatarate
);
1249 if ( client
->m_nDownloadState
== DS_DOWNLOADING
) {
1250 tag
->SpeedDown(&client
->kBpsDown
);
1252 client
->kBpsDown
= 0;
1255 tag
->WaitTime(&client
->m_WaitTime
);
1256 tag
->XferTime(&client
->m_UpStartTimeDelay
);
1257 tag
->LastReqTime(&client
->m_dwLastUpRequest
);
1258 tag
->QueueTime(&client
->m_WaitStartTime
);
1260 CreditStruct
*credit_struct
=
1261 (CreditStruct
*)client
->credits
->GetDataStruct();
1262 tag
->XferUp(&credit_struct
->uploaded
);
1263 tag
->XferUpSession(&client
->m_nTransferredUp
);
1265 tag
->XferDown(&credit_struct
->downloaded
);
1266 tag
->XferDownSession(&client
->m_nTransferredDown
);
1268 tag
->Score(&client
->m_score
);
1269 tag
->Rating(&client
->m_rating
);
1271 theApp
->amuledlg
->m_transferwnd
->clientlistctrl
->UpdateClient(client
,
1272 theApp
->amuledlg
->m_transferwnd
->clientlistctrl
->GetListView()); // Fixme, Listview shouldn't be required as parameter
1276 CUpQueueRem::CUpQueueRem(CRemoteConnect
*conn
)
1278 m_up_list(conn
, vtUploading
), m_wait_list(conn
, vtQueued
)
1284 * Download queue container: hold PartFiles with progress status
1289 bool CDownQueueRem::AddLink(const wxString
&link
, uint8 cat
)
1291 CECPacket
req(EC_OP_ADD_LINK
);
1292 CECTag
link_tag(EC_TAG_STRING
, link
);
1293 link_tag
.AddTag(CECTag(EC_TAG_PARTFILE_CAT
, cat
));
1294 req
.AddTag(link_tag
);
1296 m_conn
->SendPacket(&req
);
1301 void CDownQueueRem::ResetCatParts(int cat
)
1303 // Called when category is deleted. Command will be performed on the remote side,
1304 // but files still should be updated here right away, or drawing errors (colour not available)
1306 for (iterator it
= begin(); it
!= end(); it
++) {
1307 CPartFile
* file
= it
->second
;
1309 if ( file
->GetCategory() == cat
) {
1310 // Reset the category
1311 file
->SetCategory( 0 );
1312 } else if ( file
->GetCategory() > cat
) {
1313 // Set to the new position of the original category
1314 file
->SetCategory( file
->GetCategory() - 1 );
1321 void CKnownFilesRem::ProcessItemUpdatePartfile(CEC_PartFile_Tag
*tag
, CPartFile
*file
)
1326 tag
->Speed(&file
->m_kbpsDown
);
1327 file
->kBpsDown
= file
->m_kbpsDown
/ 1024.0;
1329 tag
->SizeXfer(&file
->transferred
);
1330 tag
->SizeDone(&file
->completedsize
);
1331 tag
->SourceXferCount(&file
->transferingsrc
);
1332 tag
->SourceNotCurrCount(&file
->m_notCurrentSources
);
1333 tag
->SourceCount(&file
->m_source_count
);
1334 tag
->SourceCountA4AF(&file
->m_a4af_source_count
);
1335 tag
->FileStatus(&file
->status
);
1336 tag
->Stopped(&file
->m_stopped
);
1338 tag
->LastSeenComplete(&file
->lastseencomplete
);
1339 tag
->LastDateChanged(&file
->m_lastDateChanged
);
1340 tag
->DownloadActiveTime(&file
->m_nDlActiveTime
);
1341 tag
->AvailablePartCount(&file
->m_availablePartsCount
);
1342 tag
->Shared(&file
->m_isShared
);
1344 tag
->GetLostDueToCorruption(&file
->m_iLostDueToCorruption
);
1345 tag
->GetGainDueToCompression(&file
->m_iGainDueToCompression
);
1346 tag
->TotalPacketsSavedDueToICH(&file
->m_iTotalPacketsSavedDueToICH
);
1348 tag
->FileCat(&file
->m_category
);
1350 tag
->DownPrio(&file
->m_iDownPriorityEC
);
1351 if ( file
->m_iDownPriorityEC
>= 10 ) {
1352 file
->m_iDownPriority
= file
->m_iDownPriorityEC
- 10;
1353 file
->m_bAutoDownPriority
= true;
1355 file
->m_iDownPriority
= file
->m_iDownPriorityEC
;
1356 file
->m_bAutoDownPriority
= false;
1359 file
->percentcompleted
= (100.0*file
->GetCompletedSize()) / file
->GetFileSize();
1362 // Copy part/gap status
1364 CECTag
*gaptag
= tag
->GetTagByName(EC_TAG_PARTFILE_GAP_STATUS
);
1365 CECTag
*parttag
= tag
->GetTagByName(EC_TAG_PARTFILE_PART_STATUS
);
1366 CECTag
*reqtag
= tag
->GetTagByName(EC_TAG_PARTFILE_REQ_STATUS
);
1367 if (gaptag
|| parttag
|| reqtag
) {
1368 PartFileEncoderData
&encoder
= file
->m_PartFileEncoderData
;
1371 ArrayOfUInts64 gaps
;
1372 encoder
.DecodeGaps(gaptag
, gaps
);
1373 int gap_size
= gaps
.size() / 2;
1375 file
->m_gaplist
.Init(file
->GetFileSize(), false);
1378 for (int j
= 0; j
< gap_size
; j
++) {
1379 file
->m_gaplist
.AddGap(gaps
[2*j
], gaps
[2*j
+1]);
1383 encoder
.DecodeParts(parttag
, file
->m_SrcpartFrequency
);
1385 wxASSERT (file
->m_SrcpartFrequency
.size() == file
->GetPartCount());
1388 ArrayOfUInts64 reqs
;
1389 encoder
.DecodeReqs(reqtag
, reqs
);
1390 int req_size
= reqs
.size() / 2;
1392 DeleteContents(file
->m_requestedblocks_list
);
1395 for (int j
= 0; j
< req_size
; j
++) {
1396 Requested_Block_Struct
* block
= new Requested_Block_Struct
;
1397 block
->StartOffset
= reqs
[2*j
];
1398 block
->EndOffset
= reqs
[2*j
+1];
1399 file
->m_requestedblocks_list
.push_back(block
);
1404 // Get source names and counts
1405 CECTag
*srcnametag
= tag
->GetTagByName(EC_TAG_PARTFILE_SOURCE_NAMES
);
1407 SourcenameItemMap
&map
= file
->GetSourcenameItemMap();
1408 for (CECTag::const_iterator it
= srcnametag
->begin(); it
!= srcnametag
->end(); it
++) {
1409 uint32 key
= it
->GetInt();
1410 int count
= it
->GetTagByNameSafe(EC_TAG_PARTFILE_SOURCE_NAMES_COUNTS
)->GetInt();
1414 SourcenameItem
&item
= map
[key
];
1416 const CECTag
*nametag
= it
->GetTagByName(EC_TAG_PARTFILE_SOURCE_NAMES
);
1418 item
.name
= nametag
->GetStringData();
1425 CECTag
*commenttag
= tag
->GetTagByName(EC_TAG_PARTFILE_COMMENTS
);
1427 file
->ClearFileRatingList();
1428 for (CECTag::const_iterator it
= commenttag
->begin(); it
!= commenttag
->end(); ) {
1429 wxString u
= (it
++)->GetStringData();
1430 wxString f
= (it
++)->GetStringData();
1431 int r
= (it
++)->GetInt();
1432 wxString c
= (it
++)->GetStringData();
1433 file
->AddFileRatingList(u
, f
, r
, c
);
1435 file
->UpdateFileRatingCommentAvail();
1438 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->UpdateItem(file
);
1440 // If file is shared check if it is already listed in shared files.
1441 // If not, add it and show it.
1442 if (file
->IsShared() && !theApp
->sharedfiles
->count(file
->ECID())) {
1443 (*theApp
->sharedfiles
)[file
->ECID()] = file
;
1444 theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
->ShowFile(file
);
1449 void CDownQueueRem::SendFileCommand(CPartFile
*file
, ec_tagname_t cmd
)
1452 req
.AddTag(CECTag(EC_TAG_PARTFILE
, file
->GetFileHash()));
1454 m_conn
->SendPacket(&req
);
1458 void CDownQueueRem::Prio(CPartFile
*file
, uint8 prio
)
1460 CECPacket
req(EC_OP_PARTFILE_PRIO_SET
);
1462 CECTag
hashtag(EC_TAG_PARTFILE
, file
->GetFileHash());
1463 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_PRIO
, prio
));
1464 req
.AddTag(hashtag
);
1466 m_conn
->SendPacket(&req
);
1470 void CDownQueueRem::AutoPrio(CPartFile
*file
, bool flag
)
1472 CECPacket
req(EC_OP_PARTFILE_PRIO_SET
);
1474 CECTag
hashtag(EC_TAG_PARTFILE
, file
->GetFileHash());
1476 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_PRIO
,
1477 (uint8
)(flag
? PR_AUTO
: file
->GetDownPriority())));
1478 req
.AddTag(hashtag
);
1480 m_conn
->SendPacket(&req
);
1484 void CDownQueueRem::Category(CPartFile
*file
, uint8 cat
)
1486 CECPacket
req(EC_OP_PARTFILE_SET_CAT
);
1487 file
->SetCategory(cat
);
1489 CECTag
hashtag(EC_TAG_PARTFILE
, file
->GetFileHash());
1490 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_CAT
, cat
));
1491 req
.AddTag(hashtag
);
1493 m_conn
->SendPacket(&req
);
1497 void CDownQueueRem::AddSearchToDownload(CSearchFile
* file
, uint8 category
)
1499 CECPacket
req(EC_OP_DOWNLOAD_SEARCH_RESULT
);
1500 CECTag
hashtag(EC_TAG_PARTFILE
, file
->GetFileHash());
1501 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_CAT
, category
));
1502 req
.AddTag(hashtag
);
1504 m_conn
->SendPacket(&req
);
1508 // This is an ugly hack and to be deleted when GUI is unlocked!
1509 // (replacing iterate-by-index with iteration)
1510 // It will only work for linear iteration starting with 0 (as used in CTransferWnd::UpdateCategory)
1511 CPartFile
* CDownQueueRem::GetFileByIndex(unsigned int idx
)
1513 static CDownQueueRem::iterator it
;
1520 return (it
++)->second
;
1524 CClientListRem::CClientListRem(CRemoteConnect
*conn
)
1530 void CClientListRem::FilterQueues()
1537 CSearchListRem::CSearchListRem(CRemoteConnect
*conn
) : CRemoteContainer
<CSearchFile
, uint32
, CEC_SearchFile_Tag
>(conn
, true)
1543 wxString
CSearchListRem::StartNewSearch(
1544 uint32
* nSearchID
, SearchType search_type
,
1545 const CSearchList::CSearchParams
& params
)
1547 CECPacket
search_req(EC_OP_SEARCH_START
);
1548 EC_SEARCH_TYPE ec_search_type
= EC_SEARCH_LOCAL
;
1549 switch(search_type
) {
1550 case LocalSearch
: ec_search_type
= EC_SEARCH_LOCAL
; break;
1551 case GlobalSearch
: ec_search_type
= EC_SEARCH_GLOBAL
; break;
1552 case KadSearch
: ec_search_type
= EC_SEARCH_KAD
; break;
1555 CEC_Search_Tag(params
.searchString
, ec_search_type
,
1556 params
.typeText
, params
.extension
, params
.availability
,
1557 params
.minSize
, params
.maxSize
));
1559 m_conn
->SendPacket(&search_req
);
1560 m_curr_search
= *(nSearchID
); // No kad remote search yet.
1564 return wxEmptyString
; // EC reply will have the error mesg is needed.
1568 void CSearchListRem::StopGlobalSearch()
1570 if (m_curr_search
!= -1) {
1571 CECPacket
search_req(EC_OP_SEARCH_STOP
);
1572 m_conn
->SendPacket(&search_req
);
1577 void CSearchListRem::StopKadSearch()
1579 // FIXME implementation needed
1583 void CSearchListRem::HandlePacket(const CECPacket
*packet
)
1585 if ( packet
->GetOpCode() == EC_OP_SEARCH_PROGRESS
) {
1586 CoreNotify_Search_Update_Progress(packet
->GetFirstTagSafe()->GetInt());
1588 CRemoteContainer
<CSearchFile
, uint32
, CEC_SearchFile_Tag
>::HandlePacket(packet
);
1593 CSearchFile::CSearchFile(CEC_SearchFile_Tag
*tag
)
1597 m_showChildren(false),
1599 m_completeSourceCount(0),
1601 m_downloadStatus(NEW
),
1606 SetFileName(CPath(tag
->FileName()));
1607 m_abyFileHash
= tag
->FileHash();
1608 SetFileSize(tag
->SizeFull());
1610 m_searchID
= theApp
->searchlist
->m_curr_search
;
1615 // dtor is virtual - must be implemented
1616 CSearchFile::~CSearchFile()
1621 CSearchFile
*CSearchListRem::CreateItem(CEC_SearchFile_Tag
*tag
)
1623 CSearchFile
*file
= new CSearchFile(tag
);
1624 ProcessItemUpdate(tag
, file
);
1626 theApp
->amuledlg
->m_searchwnd
->AddResult(file
);
1632 void CSearchListRem::DeleteItem(CSearchFile
*file
)
1638 uint32
CSearchListRem::GetItemID(CSearchFile
*file
)
1640 return file
->ECID();
1644 void CSearchListRem::ProcessItemUpdate(CEC_SearchFile_Tag
*tag
, CSearchFile
*file
)
1646 uint32 sourceCount
= file
->m_sourceCount
;
1647 uint32 completeSourceCount
= file
->m_completeSourceCount
;
1648 CSearchFile::DownloadStatus status
= file
->m_downloadStatus
;
1649 tag
->SourceCount(&file
->m_sourceCount
);
1650 tag
->CompleteSourceCount(&file
->m_completeSourceCount
);
1651 tag
->DownloadStatus((uint32
*) &file
->m_downloadStatus
);
1653 if (file
->m_sourceCount
!= sourceCount
1654 || file
->m_completeSourceCount
!= completeSourceCount
1655 || file
->m_downloadStatus
!= status
) {
1656 if (theApp
->amuledlg
&& theApp
->amuledlg
->m_searchwnd
) {
1657 theApp
->amuledlg
->m_searchwnd
->UpdateResult(file
);
1663 bool CSearchListRem::Phase1Done(const CECPacket
*WXUNUSED(reply
))
1665 CECPacket
progress_req(EC_OP_SEARCH_PROGRESS
);
1666 m_conn
->SendRequest(this, &progress_req
);
1672 void CSearchListRem::RemoveResults(long nSearchID
)
1674 ResultMap::iterator it
= m_results
.find(nSearchID
);
1675 if (it
!= m_results
.end()) {
1676 CSearchResultList
& list
= it
->second
;
1677 for (unsigned int i
= 0; i
< list
.size(); ++i
) {
1680 m_results
.erase(it
);
1685 const CSearchResultList
& CSearchListRem::GetSearchResults(long nSearchID
)
1687 ResultMap::const_iterator it
= m_results
.find(nSearchID
);
1688 if (it
!= m_results
.end()) {
1692 // TODO: Should we assert in this case?
1693 static CSearchResultList list
;
1698 void CStatsUpdaterRem::HandlePacket(const CECPacket
*packet
)
1700 theStats::UpdateStats(packet
);
1701 theApp
->ShowUserCount(); // maybe there should be a check if a usercount changed ?
1705 bool CUpDownClient::IsBanned() const
1713 // Those functions have different implementation in remote gui
1715 void CUpDownClient::Ban()
1722 void CUpDownClient::UnBan()
1729 void CUpDownClient::RequestSharedFileList()
1736 void CKnownFile::SetFileComment(const wxString
&)
1739 wxMessageBox(_("Comments and ratings are not supported on remote gui yet"), _("Information"), wxOK
| wxICON_INFORMATION
);
1743 void CKnownFile::SetFileRating(unsigned char)
1749 // I don't think it will be implemented - too match data transfer. But who knows ?
1750 wxString
CUpDownClient::ShowDownloadingParts() const
1752 return wxEmptyString
;
1756 bool CUpDownClient::SwapToAnotherFile(
1757 bool WXUNUSED(bIgnoreNoNeeded
),
1758 bool WXUNUSED(ignoreSuspensions
),
1759 bool WXUNUSED(bRemoveCompletely
),
1760 CPartFile
* WXUNUSED(toFile
))
1769 // Those functions are virtual. So even they don't get called they must
1770 // be defined so linker will be happy
1772 CPacket
* CKnownFile::CreateSrcInfoPacket(const CUpDownClient
*, uint8
/*byRequestedVersion*/, uint16
/*nRequestedOptions*/)
1779 bool CKnownFile::LoadFromFile(const class CFileDataIO
*)
1786 void CKnownFile::UpdatePartsInfo()
1792 CPacket
* CPartFile::CreateSrcInfoPacket(CUpDownClient
const *, uint8
/*byRequestedVersion*/, uint16
/*nRequestedOptions*/)
1799 void CPartFile::UpdatePartsInfo()
1805 void CPartFile::UpdateFileRatingCommentAvail()
1807 bool prevComment
= m_hasComment
;
1808 int prevRating
= m_iUserRating
;
1810 m_hasComment
= false;
1812 int ratingCount
= 0;
1814 FileRatingList::iterator it
= m_FileRatingList
.begin();
1815 for (; it
!= m_FileRatingList
.end(); ++it
) {
1816 SFileRating
& cur_rat
= *it
;
1818 if (!cur_rat
.Comment
.IsEmpty()) {
1819 m_hasComment
= true;
1822 uint8 rating
= cur_rat
.Rating
;
1824 wxASSERT(rating
<= 5);
1827 m_iUserRating
+= rating
;
1832 m_iUserRating
/= ratingCount
;
1833 wxASSERT(m_iUserRating
> 0 && m_iUserRating
<= 5);
1836 if ((prevComment
!= m_hasComment
) || (prevRating
!= m_iUserRating
)) {
1837 UpdateDisplayedInfo();
1841 bool CPartFile::SavePartFile(bool)
1847 CamuleRemoteGuiApp
*theApp
;
1850 // since gui is not linked with amule.cpp - define events here
1852 DEFINE_LOCAL_EVENT_TYPE(wxEVT_CORE_FINISHED_HTTP_DOWNLOAD
)
1853 DEFINE_LOCAL_EVENT_TYPE(wxEVT_CORE_SOURCE_DNS_DONE
)
1854 DEFINE_LOCAL_EVENT_TYPE(wxEVT_CORE_UDP_DNS_DONE
)
1855 DEFINE_LOCAL_EVENT_TYPE(wxEVT_CORE_SERVER_DNS_DONE
)
1856 // File_checked_for_headers