Upstream tarball 20080504
[amule.git] / src / ClientDetailDialog.cpp
blobcbfa8bf927819fc0d1c5c4e9047941a4edf57412
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002 Merkur ( devs@emule-project.net / http://www.emule-project.net )
6 //
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
9 // respective authors.
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "ClientDetailDialog.h" // Interface declarations
27 #include "PartFile.h" // Needed for CPartFile
28 #include "UploadQueue.h" // Needed for CUploadQueue
29 #include "ServerList.h" // Needed for CServerList
30 #include "amule.h" // Needed for theApp
31 #include "Server.h" // Needed for CServer
32 #include "updownclient.h" // Needed for CUpDownClient
33 #include "muuli_wdr.h" // Needed for ID_CLOSEWND
34 #include "Preferences.h" // Needed for thePrefs
36 // CClientDetailDialog dialog
38 BEGIN_EVENT_TABLE(CClientDetailDialog,wxDialog)
39 EVT_BUTTON(ID_CLOSEWND,CClientDetailDialog::OnBnClose)
40 END_EVENT_TABLE()
43 CClientDetailDialog::CClientDetailDialog(
44 wxWindow *parent,
45 CUpDownClient *client)
47 wxDialog(
48 parent,
49 9997,
50 _("Client Details"),
51 wxDefaultPosition,
52 wxDefaultSize,
53 wxDEFAULT_DIALOG_STYLE)
55 m_client = client;
56 wxSizer* content = clientDetails(this, true);
57 OnInitDialog();
58 content->SetSizeHints(this);
59 content->Show(this, true);
62 CClientDetailDialog::~CClientDetailDialog()
66 void CClientDetailDialog::OnBnClose(wxCommandEvent& WXUNUSED(evt))
68 EndModal(0);
71 bool CClientDetailDialog::OnInitDialog() {
72 // Username, Userhash and Rating
73 if (!m_client->GetUserName().IsEmpty()) {
74 CastChild(ID_DNAME, wxStaticText)->SetLabel(
75 m_client->GetUserName());
76 // if we have client name we have userhash
77 wxASSERT(!m_client->GetUserHash().IsEmpty());
78 CastChild(ID_DHASH, wxStaticText)->SetLabel(
79 m_client->GetUserHash().Encode());
80 CastChild(ID_DRATING, wxStaticText)->SetLabel(
81 wxString::Format(wxT("%.1f"), m_client->GetRating()));
82 } else {
83 CastChild(ID_DNAME, wxStaticText)->SetLabel(_("Unknown"));
84 CastChild(ID_DHASH, wxStaticText)->SetLabel(_("Unknown"));
85 CastChild(ID_DRATING, wxStaticText)->SetLabel(_("Unknown"));;
88 // Client Software
89 wxString OSInfo = m_client->GetClientOSInfo();
90 if (!OSInfo.IsEmpty()) {
91 CastChild(ID_DSOFT, wxStaticText)->SetLabel(
92 m_client->GetSoftStr()+wxT(" (")+OSInfo+wxT(")"));
93 } else {
94 CastChild(ID_DSOFT, wxStaticText)->SetLabel(
95 m_client->GetSoftStr());
98 // Client Version
99 CastChild(ID_DVERSION, wxStaticText)->SetLabel(
100 m_client->GetSoftVerStr());
102 // User ID
103 CastChild(ID_DID, wxStaticText)->SetLabel(
104 CFormat(wxT("%u (%s)")) % ENDIAN_NTOHL(m_client->GetIP()) % (m_client->HasLowID() ? _("LowID") : _("HighID")));
106 // Client IP/Port
107 CastChild(ID_DIP, wxStaticText)->SetLabel(
108 m_client->GetFullIP() +
109 wxString::Format(wxT(":%i"), m_client->GetUserPort()));
111 // Server IP/Port/Name
112 if (m_client->GetServerIP()) {
113 wxString srvaddr = Uint32toStringIP(m_client->GetServerIP());
114 CastChild(ID_DSIP, wxStaticText)->SetLabel(
115 srvaddr +
116 wxString::Format(wxT(":%i"),m_client->GetServerPort()));
117 CastChild(ID_DSNAME, wxStaticText)->SetLabel(
118 m_client->GetServerName());
119 } else {
120 CastChild(ID_DSIP, wxStaticText)->SetLabel(_("Unknown"));
121 CastChild(ID_DSNAME, wxStaticText)->SetLabel(_("Unknown"));
124 // Obfuscation
125 wxString buffer;
126 if (thePrefs::IsClientCryptLayerSupported()) {
127 if (m_client->SupportsCryptLayer()) {
128 if ((m_client->RequestsCryptLayer() || thePrefs::IsClientCryptLayerRequested()) && m_client->HasObfuscatedConnectionBeenEstablished()) {
129 buffer = _("Enabled");
130 } else {
131 buffer = _("Supported");
133 } else {
134 buffer = _("Not supported");
136 } else {
137 buffer = _("Disabled");
139 CastChild(IDT_OBFUSCATION, wxStaticText)->SetLabel(buffer);
141 // Kad
142 if (m_client->GetKadPort()) {
143 CastChild(IDT_KAD, wxStaticText)->SetLabel(_("Connected"));
144 } else {
145 CastChild(IDT_KAD, wxStaticText)->SetLabel(_("Disconnected"));
148 // File Name
149 const CKnownFile* file = m_client->GetUploadFile();
150 if (file) {
151 wxString filename = MakeStringEscaped(
152 TruncateFilename(file->GetFileName(), 60));
153 CastChild(ID_DDOWNLOADING, wxStaticText)->SetLabel(filename);
154 } else {
155 CastChild(ID_DDOWNLOADING, wxStaticText)->SetLabel(wxT("-"));
158 // Upload
159 CastChild(ID_DDUP, wxStaticText)->SetLabel(
160 CastItoXBytes(m_client->GetTransferredDown()));
162 // Download
163 CastChild(ID_DDOWN, wxStaticText)->SetLabel(
164 CastItoXBytes(m_client->GetTransferredUp()));
166 // Average Upload Rate
167 CastChild(ID_DAVUR, wxStaticText)->SetLabel(
168 wxString::Format(_("%.1f kB/s"),
169 m_client->GetKBpsDown()));
171 // Average Download Rate
172 CastChild(ID_DAVDR, wxStaticText)->SetLabel(
173 wxString::Format(_("%.1f kB/s"),
174 m_client->GetUploadDatarate() / 1024.0f));
176 // Total Upload
177 CastChild(ID_DUPTOTAL, wxStaticText)->SetLabel(
178 CastItoXBytes(m_client->GetDownloadedTotal()));
180 // Total Download
181 CastChild(ID_DDOWNTOTAL, wxStaticText)->SetLabel(
182 CastItoXBytes(m_client->GetUploadedTotal()));
184 // DL/UP Modifier
185 CastChild(ID_DRATIO, wxStaticText)->SetLabel(
186 wxString::Format(wxT("%.1f"),
187 (float)m_client->GetScoreRatio()));
189 // Secure Ident
190 if (theApp->CryptoAvailable()) {
191 if (m_client->SUINotSupported()) {
192 CastChild(IDC_CDIDENT, wxStaticText)->SetLabel(
193 _("Not supported"));
194 } else if (m_client->SUIFailed()) {
195 CastChild(IDC_CDIDENT, wxStaticText)->SetLabel(
196 _("Failed"));
197 } else if (m_client->SUINeeded()) {
198 CastChild(IDC_CDIDENT, wxStaticText)->SetLabel(
199 _("Not complete"));
200 } else if (m_client->IsBadGuy()) {
201 CastChild(IDC_CDIDENT, wxStaticText)->SetLabel(
202 _("Bad Guy"));
203 } else if (m_client->IsIdentified()) {
204 CastChild(IDC_CDIDENT, wxStaticText)->SetLabel(
205 _("Verified - OK"));
207 } else {
208 CastChild(IDC_CDIDENT, wxStaticText)->SetLabel(
209 _("Not Available"));
212 // Queue Score
213 if (m_client->GetUploadState() != US_NONE) {
214 CastChild(ID_DSCORE, wxStaticText)->SetLabel(
215 wxString::Format(_("%u (QR: %u)"),
216 m_client->GetScore(
217 false, m_client->IsDownloading(), false),
218 theApp->uploadqueue->GetWaitingPosition(m_client)));
219 } else {
220 CastChild(ID_DSCORE, wxStaticText)->SetLabel(wxT("-"));
222 Layout();
224 return true;
226 // File_checked_for_headers