1//
2// This file is part of the aMule Project.
3//
4// Copyright (c) 2003-2011 Angel Vidal ( kry@amule.org )
5// Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
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.
10//
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.
15//
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
24//
25
26
27#include "ECTag.h"		// Needed for CECTag
28#include "ECSpecialTags.h"	// Needed for special EC tag creator classes
29
30#include <common/Format.h>		// Needed for CFormat
31
32#include "../../../OtherFunctions.h"	// Needed for CastXtoY
33#include "../../../Constants.h"			// Needed for PS_*
34
35wxString CEC_PartFile_Tag::GetFileStatusString() const
36{
37	uint8 nFileStatus = FileStatus();
38
39        if ((nFileStatus == PS_HASHING) || (nFileStatus == PS_WAITINGFORHASH)) {
40                return _("Hashing");
41        } else {
42                switch (nFileStatus) {
43                        case PS_COMPLETING:
44                                return _("Completing");
45                        case PS_COMPLETE:
46                                return _("Complete");
47                        case PS_PAUSED:
48                                return _("Paused");
49                        case PS_ERROR:
50                                return _("Erroneous");
51                        default:
52                                if (SourceXferCount() > 0) {
53                                        return _("Downloading");
54                                } else {
55                                        return _("Waiting");
56                                }
57                }
58                // if stopped
59        }
60}
61
62//
63// Search request
64//
65CEC_Search_Tag::CEC_Search_Tag(const wxString &name, EC_SEARCH_TYPE search_type, const wxString &file_type,
66			const wxString &extension, uint32 avail, uint64 min_size, uint64 max_size) : CECTag(EC_TAG_SEARCH_TYPE, (uint32)search_type)
67{
68	AddTag(CECTag(EC_TAG_SEARCH_NAME, name));
69	AddTag(CECTag(EC_TAG_SEARCH_FILE_TYPE, file_type));
70	if ( !extension.IsEmpty() ) {
71		AddTag(CECTag(EC_TAG_SEARCH_EXTENSION, extension));
72	}
73	if ( avail ) {
74		AddTag(CECTag(EC_TAG_SEARCH_AVAILABILITY, avail));
75	}
76	if ( min_size != 0 ) {
77		AddTag(CECTag(EC_TAG_SEARCH_MIN_SIZE, min_size));
78	}
79	if ( max_size != 0 ) {
80		AddTag(CECTag(EC_TAG_SEARCH_MAX_SIZE, max_size));
81	}
82}
83
84void FormatValue(CFormat& format, const CECTag* tag)
85{
86	wxASSERT(tag->GetTagName() == EC_TAG_STAT_NODE_VALUE);
87
88	wxString extra;
89	const CECTag *tmp_tag = tag->GetTagByName(EC_TAG_STAT_NODE_VALUE);
90	if (tmp_tag) {
91		wxString tmp_fmt;
92		const CECTag* tmp_vt = tmp_tag->GetTagByName(EC_TAG_STAT_VALUE_TYPE);
93		EC_STATTREE_NODE_VALUE_TYPE tmp_valueType = tmp_vt != NULL ? (EC_STATTREE_NODE_VALUE_TYPE)tmp_vt->GetInt() : EC_VALUE_INTEGER;
94		switch (tmp_valueType) {
95			case EC_VALUE_INTEGER:
96				tmp_fmt = wxT("%llu");
97				break;
98			case EC_VALUE_DOUBLE:
99				tmp_fmt = wxT("%.2f%%");	// it's used for percentages
100				break;
101			default:
102				tmp_fmt = wxT("%s");
103		}
104		CFormat tmp_format(wxT(" (") + tmp_fmt + wxT(")"));
105		FormatValue(tmp_format, tmp_tag);
106		extra = tmp_format.GetString();
107	}
108
109	const CECTag* vt = tag->GetTagByName(EC_TAG_STAT_VALUE_TYPE);
110	EC_STATTREE_NODE_VALUE_TYPE valueType = vt != NULL ? (EC_STATTREE_NODE_VALUE_TYPE)vt->GetInt() : EC_VALUE_INTEGER;
111	switch (valueType) {
112		case EC_VALUE_INTEGER:
113			format = format % tag->GetInt();
114			break;
115		case EC_VALUE_ISTRING:
116			format = format % (CFormat(wxT("%u")) % tag->GetInt() + extra);
117			break;
118		case EC_VALUE_BYTES:
119			format = format % (CastItoXBytes(tag->GetInt()) + extra);
120			break;
121		case EC_VALUE_ISHORT:
122			format = format % (CastItoIShort(tag->GetInt()) + extra);
123			break;
124		case EC_VALUE_TIME:
125			format = format % (CastSecondsToHM(tag->GetInt()) + extra);
126			break;
127		case EC_VALUE_SPEED:
128			format = format % (CastItoSpeed(tag->GetInt()) + extra);
129			break;
130		case EC_VALUE_STRING:
131			format = format % (wxGetTranslation(tag->GetStringData()) + extra);
132			break;
133		case EC_VALUE_DOUBLE:
134			format = format % tag->GetDoubleData();
135			break;
136		default:
137			wxFAIL;
138	}
139}
140
141wxString CEC_StatTree_Node_Tag::GetDisplayString() const
142{
143	wxString en_label = GetStringData();
144	wxString my_label = wxGetTranslation(en_label);
145	// This is needed for client names, for example
146	if (my_label == en_label) {
147		if (en_label.Right(4) == wxT(": %s")) {
148			my_label = wxGetTranslation(en_label.Mid(0, en_label.Length() - 4)) + wxString(wxT(": %s"));
149		}
150	}
151	CFormat label(my_label);
152	for (const_iterator it = begin(); it != end(); it++) {
153		if (it->GetTagName() == EC_TAG_STAT_NODE_VALUE) {
154			FormatValue(label, &*it);
155		}
156	}
157	return label.GetString();
158}
159// File_checked_for_headers
160