Replace dynamically built filter list with a static one
[amule.git] / src / AddFriend.cpp
blobeed70ed2fd363cc82e300b22d0039d56f073c621
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002-2011 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.
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
27 #include "AddFriend.h" // Interface declarations.
28 #include "muuli_wdr.h" // Needed for addFriendDlg
29 #include "amule.h" // Needed for theApp
30 #include "amuleDlg.h" // Needed for amuleDlg
31 #include "FriendList.h"
32 #include "NetworkFunctions.h"
33 #include "OtherFunctions.h"
34 #include "MD4Hash.h"
35 #include <common/StringFunctions.h> // Needed for unicode2char
38 BEGIN_EVENT_TABLE(CAddFriend, wxDialog)
39 EVT_BUTTON(ID_ADDFRIEND, CAddFriend::OnAddBtn)
40 EVT_BUTTON(ID_CLOSEDLG, CAddFriend::OnCloseBtn)
41 END_EVENT_TABLE()
44 CAddFriend::CAddFriend(wxWindow* parent)
45 : wxDialog(parent, 9995, _("Add a Friend"), wxDefaultPosition, wxDefaultSize,
46 wxDEFAULT_DIALOG_STYLE|wxSYSTEM_MENU)
48 wxSizer* content=addFriendDlg(this, TRUE);
49 content->Show(this, TRUE);
52 void CAddFriend::OnAddBtn(wxCommandEvent& WXUNUSED(evt))
54 wxString name = CastChild(ID_USERNAME, wxTextCtrl)->GetValue().Strip(wxString::both);
55 wxString hash = CastChild(ID_USERHASH, wxTextCtrl)->GetValue().Strip(wxString::both);
56 wxString fullip = CastChild(ID_IPADDRESS, wxTextCtrl)->GetValue().Strip(wxString::both);
57 uint16 port = StrToULong( CastChild(ID_IPORT, wxTextCtrl)->GetValue() );
58 uint32 ip = StringIPtoUint32(fullip);
60 if (!ip || !port) {
61 wxMessageBox(_("You have to enter a valid IP and port!"), _("Information"), wxOK | wxICON_INFORMATION, this);
62 return;
65 CMD4Hash userhash;
66 if ((!hash.IsEmpty()) && (!userhash.Decode(hash))) {
67 wxMessageBox(_("The specified userhash is not valid!"), _("Information"), wxOK | wxICON_INFORMATION, this);
68 return;
71 // Better than nothing at all...
72 if ( name.IsEmpty() ) {
73 name = fullip;
76 theApp->friendlist->AddFriend(userhash, ip, port, name);
78 EndModal(true); // Friend added
82 void CAddFriend::OnCloseBtn(wxCommandEvent& WXUNUSED(evt))
84 EndModal(false); // Friend not added
87 // File_checked_for_headers