Upstream tarball 20080304
[amule.git] / src / ClientDetailDialog.cpp
blob55b7b600746f053c78aa3d184f1de6e922bbea5a
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
35 // CClientDetailDialog dialog
37 BEGIN_EVENT_TABLE(CClientDetailDialog,wxDialog)
38 EVT_BUTTON(ID_CLOSEWND,CClientDetailDialog::OnBnClose)
39 END_EVENT_TABLE()
42 CClientDetailDialog::CClientDetailDialog(
43 wxWindow *parent,
44 CUpDownClient *client)
46 wxDialog(
47 parent,
48 9997,
49 _("Client Details"),
50 wxDefaultPosition,
51 wxDefaultSize,
52 wxDEFAULT_DIALOG_STYLE)
54 m_client = client;
55 wxSizer* content = clientDetails(this, true);
56 OnInitDialog();
57 content->SetSizeHints(this);
58 content->Show(this, true);
61 CClientDetailDialog::~CClientDetailDialog()
65 void CClientDetailDialog::OnBnClose(wxCommandEvent& WXUNUSED(evt))
67 EndModal(0);
70 bool CClientDetailDialog::OnInitDialog() {
71 // Username, Userhash and Rating
72 if (!m_client->GetUserName().IsEmpty()) {
73 CastChild(ID_DNAME, wxStaticText)->SetLabel(
74 m_client->GetUserName());
75 // if we have client name we have userhash
76 wxASSERT(!m_client->GetUserHash().IsEmpty());
77 CastChild(ID_DHASH, wxStaticText)->SetLabel(
78 m_client->GetUserHash().Encode());
79 CastChild(ID_DRATING, wxStaticText)->SetLabel(
80 wxString::Format(wxT("%.1f"), m_client->GetRating()));
81 } else {
82 CastChild(ID_DNAME, wxStaticText)->SetLabel(_("Unknown"));
83 CastChild(ID_DHASH, wxStaticText)->SetLabel(_("Unknown"));
84 CastChild(ID_DRATING, wxStaticText)->SetLabel(_("Unknown"));;
87 // Client Software
88 wxString OSInfo = m_client->GetClientOSInfo();
89 if (!OSInfo.IsEmpty()) {
90 CastChild(ID_DSOFT, wxStaticText)->SetLabel(
91 m_client->GetSoftStr()+wxT(" (")+OSInfo+wxT(")"));
92 } else {
93 CastChild(ID_DSOFT, wxStaticText)->SetLabel(
94 m_client->GetSoftStr());
97 // Client Version
98 CastChild(ID_DVERSION, wxStaticText)->SetLabel(
99 m_client->GetSoftVerStr());
101 // User ID
102 CastChild(ID_DID, wxStaticText)->SetLabel(
103 CFormat(wxT("%u (%s)")) % ENDIAN_NTOHL(m_client->GetIP()) % (m_client->HasLowID() ? _("LowID") : _("HighID")));
105 // Client IP/Port
106 CastChild(ID_DIP, wxStaticText)->SetLabel(
107 m_client->GetFullIP() +
108 wxString::Format(wxT(":%i"), m_client->GetUserPort()));
110 // Server IP/Port/Name
111 if (m_client->GetServerIP()) {
112 wxString srvaddr = Uint32toStringIP(m_client->GetServerIP());
113 CastChild(ID_DSIP, wxStaticText)->SetLabel(
114 srvaddr +
115 wxString::Format(wxT(":%i"),m_client->GetServerPort()));
116 CastChild(ID_DSNAME, wxStaticText)->SetLabel(
117 m_client->GetServerName());
118 } else {
119 CastChild(ID_DSIP, wxStaticText)->SetLabel(_("Unknown"));
120 CastChild(ID_DSNAME, wxStaticText)->SetLabel(_("Unknown"));
123 // File Name
124 const CKnownFile* file = m_client->GetUploadFile();
125 if (file) {
126 wxString filename = MakeStringEscaped(
127 TruncateFilename(file->GetFileName(), 60));
128 CastChild(ID_DDOWNLOADING, wxStaticText)->SetLabel(filename);
129 } else {
130 CastChild(ID_DDOWNLOADING, wxStaticText)->SetLabel(wxT("-"));
133 // Upload
134 CastChild(ID_DDUP, wxStaticText)->SetLabel(
135 CastItoXBytes(m_client->GetTransferredDown()));
137 // Download
138 CastChild(ID_DDOWN, wxStaticText)->SetLabel(
139 CastItoXBytes(m_client->GetTransferredUp()));
141 // Average Upload Rate
142 CastChild(ID_DAVUR, wxStaticText)->SetLabel(
143 wxString::Format(_("%.1f kB/s"),
144 m_client->GetKBpsDown()));
146 // Average Download Rate
147 CastChild(ID_DAVDR, wxStaticText)->SetLabel(
148 wxString::Format(_("%.1f kB/s"),
149 m_client->GetUploadDatarate() / 1024.0f));
151 // Total Upload
152 CastChild(ID_DUPTOTAL, wxStaticText)->SetLabel(
153 CastItoXBytes(m_client->GetDownloadedTotal()));
155 // Total Download
156 CastChild(ID_DDOWNTOTAL, wxStaticText)->SetLabel(
157 CastItoXBytes(m_client->GetUploadedTotal()));
159 // DL/UP Modifier
160 CastChild(ID_DRATIO, wxStaticText)->SetLabel(
161 wxString::Format(wxT("%.1f"),
162 (float)m_client->GetScoreRatio()));
164 // Secure Ident
165 if (theApp->CryptoAvailable()) {
166 if (m_client->SUINotSupported()) {
167 CastChild(IDC_CDIDENT, wxStaticText)->SetLabel(
168 _("Not Supported"));
169 } else if (m_client->SUIFailed()) {
170 CastChild(IDC_CDIDENT, wxStaticText)->SetLabel(
171 _("Failed"));
172 } else if (m_client->SUINeeded()) {
173 CastChild(IDC_CDIDENT, wxStaticText)->SetLabel(
174 _("Not complete"));
175 } else if (m_client->IsBadGuy()) {
176 CastChild(IDC_CDIDENT, wxStaticText)->SetLabel(
177 _("Bad Guy"));
178 } else if (m_client->IsIdentified()) {
179 CastChild(IDC_CDIDENT, wxStaticText)->SetLabel(
180 _("Verified - OK"));
182 } else {
183 CastChild(IDC_CDIDENT, wxStaticText)->SetLabel(
184 _("Not Available"));
187 // Queue Score
188 if (m_client->GetUploadState() != US_NONE) {
189 CastChild(ID_DSCORE, wxStaticText)->SetLabel(
190 wxString::Format(_("%u (QR: %u)"),
191 m_client->GetScore(
192 false, m_client->IsDownloading(), false),
193 theApp->uploadqueue->GetWaitingPosition(m_client)));
194 } else {
195 CastChild(ID_DSCORE, wxStaticText)->SetLabel(wxT("-"));
197 Layout();
199 return true;
201 // File_checked_for_headers