Simplify CUpDownClient::GetScore()
[amule.git] / src / ClientDetailDialog.cpp
blob5be21e6f836b9ca6458a9b24d0ea21ddb2adbffa
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-2008 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("%u"), m_client->GetScore(false, true)));
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)")) % m_client->GetUserIDHybrid() % (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 switch (m_client->GetObfuscationStatus()) {
127 case OBST_ENABLED: buffer = _("Enabled"); break;
128 case OBST_SUPPORTED: buffer = _("Supported"); break;
129 case OBST_NOT_SUPPORTED: buffer = _("Not supported"); break;
130 case OBST_DISABLED: buffer = _("Disabled"); break;
131 default: buffer = _("Unknown"); break;
133 CastChild(IDT_OBFUSCATION, wxStaticText)->SetLabel(buffer);
135 // Kad
136 if (m_client->GetKadPort()) {
137 CastChild(IDT_KAD, wxStaticText)->SetLabel(_("Connected"));
138 } else {
139 CastChild(IDT_KAD, wxStaticText)->SetLabel(_("Disconnected"));
142 // File Name
143 const CKnownFile* file = m_client->GetUploadFile();
144 if (file) {
145 wxString filename = MakeStringEscaped(file->GetFileName().TruncatePath(60));
146 CastChild(ID_DDOWNLOADING, wxStaticText)->SetLabel(filename);
147 } else {
148 CastChild(ID_DDOWNLOADING, wxStaticText)->SetLabel(wxT("-"));
151 // Upload
152 CastChild(ID_DDUP, wxStaticText)->SetLabel(
153 CastItoXBytes(m_client->GetTransferredDown()));
155 // Download
156 CastChild(ID_DDOWN, wxStaticText)->SetLabel(
157 CastItoXBytes(m_client->GetTransferredUp()));
159 // Average Upload Rate
160 CastChild(ID_DAVUR, wxStaticText)->SetLabel(
161 wxString::Format(_("%.1f kB/s"),
162 m_client->GetKBpsDown()));
164 // Average Download Rate
165 CastChild(ID_DAVDR, wxStaticText)->SetLabel(
166 wxString::Format(_("%.1f kB/s"),
167 m_client->GetUploadDatarate() / 1024.0f));
169 // Total Upload
170 CastChild(ID_DUPTOTAL, wxStaticText)->SetLabel(
171 CastItoXBytes(m_client->GetDownloadedTotal()));
173 // Total Download
174 CastChild(ID_DDOWNTOTAL, wxStaticText)->SetLabel(
175 CastItoXBytes(m_client->GetUploadedTotal()));
177 // DL/UP Modifier
178 CastChild(ID_DRATIO, wxStaticText)->SetLabel(
179 wxString::Format(wxT("%.1f"),
180 (float)m_client->GetScoreRatio()));
182 // Secure Ident
183 if (theApp->CryptoAvailable()) {
184 if (m_client->SUINotSupported()) {
185 CastChild(IDC_CDIDENT, wxStaticText)->SetLabel(
186 _("Not supported"));
187 } else if (m_client->SUIFailed()) {
188 CastChild(IDC_CDIDENT, wxStaticText)->SetLabel(
189 _("Failed"));
190 } else if (m_client->SUINeeded()) {
191 CastChild(IDC_CDIDENT, wxStaticText)->SetLabel(
192 _("Not complete"));
193 } else if (m_client->IsBadGuy()) {
194 CastChild(IDC_CDIDENT, wxStaticText)->SetLabel(
195 _("Bad Guy"));
196 } else if (m_client->IsIdentified()) {
197 CastChild(IDC_CDIDENT, wxStaticText)->SetLabel(
198 _("Verified - OK"));
200 } else {
201 CastChild(IDC_CDIDENT, wxStaticText)->SetLabel(
202 _("Not Available"));
205 // Queue Score
206 if (m_client->GetUploadState() != US_NONE) {
207 CastChild(ID_DSCORE, wxStaticText)->SetLabel(
208 wxString::Format(_("%u (QR: %u)"),
209 m_client->GetScore(),
210 m_client->GetUploadQueueWaitingPosition()));
211 } else {
212 CastChild(ID_DSCORE, wxStaticText)->SetLabel(wxT("-"));
214 Layout();
216 return true;
218 // File_checked_for_headers