1 | |
---|
2 | // Copyright Eóin O'Callaghan 2006 - 2008. |
---|
3 | // Distributed under the Boost Software License, Version 1.0. |
---|
4 | // (See accompanying file LICENSE_1_0.txt or copy at |
---|
5 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
6 | |
---|
7 | #pragma once |
---|
8 | |
---|
9 | #define ID_NTPLVM_BEGIN 19000 |
---|
10 | #define ID_NTPLVM_NEW ID_NTPLVM_BEGIN + 1 |
---|
11 | #define ID_NTPLVM_EDIT ID_NTPLVM_BEGIN + 2 |
---|
12 | #define ID_NTPLVM_DELETE ID_NTPLVM_BEGIN + 3 |
---|
13 | #define HAL_NTPLVM_NAMES ID_NTPLVM_BEGIN + 4 |
---|
14 | |
---|
15 | #define HAL_NEWT_ADD_PEERS 14500 |
---|
16 | #define HAL_NEWT_ADD_PEERS_URL_TEXT HAL_NEWT_ADD_PEERS + 1 |
---|
17 | #define HAL_NEWT_ADD_PEERS_URL_EDIT HAL_NEWT_ADD_PEERS + 2 |
---|
18 | #define HAL_NEWT_ADD_PEERS_TYP_TEXT HAL_NEWT_ADD_PEERS + 3 |
---|
19 | #define HAL_NEWT_ADD_PEERS_TYP_CBOX HAL_NEWT_ADD_PEERS + 4 |
---|
20 | #define HAL_NEWT_ADD_DHT_PORT HAL_NEWT_ADD_PEERS + 7 |
---|
21 | #define HAL_NEWT_ADD_DHT_PORT_TEXT HAL_NEWT_ADD_PEERS + 8 |
---|
22 | |
---|
23 | #define HAL_NEWT_ADD_PEERS_WEB HAL_NEWT_ADD_PEERS + 5 |
---|
24 | #define HAL_NEWT_ADD_PEERS_DHT HAL_NEWT_ADD_PEERS + 6 |
---|
25 | #define HAL_NEWT_EDIT_PEER HAL_NEWT_ADD_PEERS + 9 |
---|
26 | #define HAL_NEWT_ADD_NEW_PEER HAL_NEWT_ADD_PEERS + 10 |
---|
27 | |
---|
28 | #ifndef RC_INVOKED |
---|
29 | |
---|
30 | #include <boost/signals.hpp> |
---|
31 | #include <boost/function.hpp> |
---|
32 | |
---|
33 | #include "stdAfx.hpp" |
---|
34 | #include "global/string_conv.hpp" |
---|
35 | #include "halIni.hpp" |
---|
36 | #include "HaliteSortListViewCtrl.hpp" |
---|
37 | |
---|
38 | #include "GenericAddDialog.hpp" |
---|
39 | #include "GenericAddListView.hpp" |
---|
40 | |
---|
41 | class NewTorrent_PeersAddDialog : |
---|
42 | public ATL::CDialogImpl<NewTorrent_PeersAddDialog>, |
---|
43 | public WTLx::GenericAddDialog<NewTorrent_PeersAddDialog, HAL_PEEREDIT>, |
---|
44 | public WTL::CDialogResize<NewTorrent_PeersAddDialog>, |
---|
45 | public CWinDataExchangeEx<NewTorrent_PeersAddDialog> |
---|
46 | { |
---|
47 | public: |
---|
48 | typedef NewTorrent_PeersAddDialog thisClass; |
---|
49 | typedef WTLx::GenericAddDialog<thisClass, HAL_PEEREDIT> genericBaseClass; |
---|
50 | typedef WTL::CDialogResize<thisClass> resizeClass; |
---|
51 | |
---|
52 | public: |
---|
53 | NewTorrent_PeersAddDialog(wstring title, hal::web_seed_or_dht_node_detail& peer) : |
---|
54 | genericBaseClass(title, "genericAddDlgs/NewTorrentAddPeers", "NewTorrentAddPeers"), |
---|
55 | peer_(peer) |
---|
56 | {} |
---|
57 | |
---|
58 | BEGIN_MSG_MAP_EX(thisClass) |
---|
59 | MSG_WM_INITDIALOG(onInitDialog) |
---|
60 | COMMAND_HANDLER_EX(HAL_NEWT_ADD_PEERS_TYP_CBOX, CBN_SELCHANGE, OnTypeChanged) |
---|
61 | |
---|
62 | CHAIN_MSG_MAP(resizeClass) |
---|
63 | CHAIN_MSG_MAP(genericBaseClass) |
---|
64 | END_MSG_MAP() |
---|
65 | |
---|
66 | BEGIN_DDX_MAP(thisClass) |
---|
67 | DDX_EX_STDWSTRING(HAL_NEWT_ADD_PEERS_URL_EDIT, peer_.url); |
---|
68 | DDX_INT(HAL_NEWT_ADD_DHT_PORT, peer_.port) |
---|
69 | DDX_EX_STDWSTRING(HAL_NEWT_ADD_PEERS_TYP_CBOX, peer_.type) |
---|
70 | END_DDX_MAP() |
---|
71 | |
---|
72 | BEGIN_DLGRESIZE_MAP(thisClass) |
---|
73 | DLGRESIZE_CONTROL(HAL_NEWT_ADD_PEERS_URL_EDIT, DLSZ_SIZE_X) |
---|
74 | DLGRESIZE_CONTROL(HAL_NEWT_ADD_PEERS_TYP_CBOX, DLSZ_MOVE_X) |
---|
75 | DLGRESIZE_CONTROL(HAL_NEWT_ADD_PEERS_URL_TEXT, DLSZ_SIZE_X) |
---|
76 | DLGRESIZE_CONTROL(HAL_NEWT_ADD_PEERS_TYP_TEXT, DLSZ_MOVE_X) |
---|
77 | DLGRESIZE_CONTROL(HAL_NEWT_ADD_DHT_PORT_TEXT, DLSZ_MOVE_X) |
---|
78 | DLGRESIZE_CONTROL(HAL_NEWT_ADD_DHT_PORT, DLSZ_MOVE_X) |
---|
79 | DLGRESIZE_CONTROL(IDOK, DLSZ_MOVE_X|DLSZ_MOVE_Y) |
---|
80 | DLGRESIZE_CONTROL(IDCANCEL, DLSZ_MOVE_X|DLSZ_MOVE_Y) |
---|
81 | END_DLGRESIZE_MAP() |
---|
82 | |
---|
83 | LRESULT onInitDialog(HWND, LPARAM) |
---|
84 | { |
---|
85 | WTL::CComboBox peerTypes; |
---|
86 | |
---|
87 | peerTypes.Attach(GetDlgItem(HAL_NEWT_ADD_PEERS_TYP_CBOX)); |
---|
88 | |
---|
89 | peerTypes.AddString(hal::app().res_wstr(HAL_NEWT_ADD_PEERS_WEB).c_str()); |
---|
90 | peerTypes.AddString(hal::app().res_wstr(HAL_NEWT_ADD_PEERS_DHT).c_str()); |
---|
91 | |
---|
92 | if (hal::app().res_wstr(HAL_NEWT_ADD_PEERS_WEB) == peer_.type) |
---|
93 | peerTypes.SetCurSel(1); |
---|
94 | else |
---|
95 | { |
---|
96 | peerTypes.SetCurSel(0); |
---|
97 | ::EnableWindow(GetDlgItem(HAL_NEWT_ADD_DHT_PORT_TEXT), true); |
---|
98 | ::EnableWindow(GetDlgItem(HAL_NEWT_ADD_DHT_PORT), true); |
---|
99 | } |
---|
100 | |
---|
101 | resizeClass::DlgResize_Init(false, true, WS_CLIPCHILDREN); |
---|
102 | |
---|
103 | SetMsgHandled(false); |
---|
104 | return 0; |
---|
105 | } |
---|
106 | |
---|
107 | void OnTypeChanged(UINT uNotifyCode, int nID, CWindow wndCtl) |
---|
108 | { |
---|
109 | hal::win_c_str<std::wstring> str_buf(MAX_PATH); |
---|
110 | wndCtl.GetWindowText(str_buf, str_buf.size()); |
---|
111 | |
---|
112 | if (str_buf.str() == hal::app().res_wstr(HAL_NEWT_ADD_PEERS_WEB)) |
---|
113 | { |
---|
114 | ::EnableWindow(GetDlgItem(HAL_NEWT_ADD_DHT_PORT_TEXT), false); |
---|
115 | ::EnableWindow(GetDlgItem(HAL_NEWT_ADD_DHT_PORT), false); |
---|
116 | } |
---|
117 | else |
---|
118 | { |
---|
119 | ::EnableWindow(GetDlgItem(HAL_NEWT_ADD_DHT_PORT_TEXT), true); |
---|
120 | ::EnableWindow(GetDlgItem(HAL_NEWT_ADD_DHT_PORT), true); |
---|
121 | } |
---|
122 | } |
---|
123 | |
---|
124 | private: |
---|
125 | wstring title_; |
---|
126 | hal::web_seed_or_dht_node_detail& peer_; |
---|
127 | }; |
---|
128 | |
---|
129 | class NewTorrent_PeersListViewCtrl : |
---|
130 | public CHaliteSortListViewCtrl<NewTorrent_PeersListViewCtrl>, |
---|
131 | public hal::IniBase<NewTorrent_PeersListViewCtrl>, |
---|
132 | public WTLx::GenericAddListView<NewTorrent_PeersListViewCtrl, true>, |
---|
133 | private boost::noncopyable |
---|
134 | { |
---|
135 | typedef NewTorrent_PeersListViewCtrl thisClass; |
---|
136 | typedef hal::IniBase<thisClass> iniClass; |
---|
137 | typedef CHaliteSortListViewCtrl<thisClass> listClass; |
---|
138 | typedef WTLx::GenericAddListView<thisClass, true> genericAddlistClass; |
---|
139 | |
---|
140 | friend class listClass; |
---|
141 | |
---|
142 | public: |
---|
143 | enum { |
---|
144 | LISTVIEW_ID_MENU = HAL_GENERIC_ADD_LV_MENU, |
---|
145 | LISTVIEW_ID_COLUMNNAMES = HAL_NTPLVM_NAMES, |
---|
146 | LISTVIEW_ID_COLUMNWIDTHS = HAL_TRACKER_LISTVIEW_DEFAULTS |
---|
147 | }; |
---|
148 | |
---|
149 | NewTorrent_PeersListViewCtrl() : |
---|
150 | iniClass("listviews/NewTorrentPeers", "NewPeersListView") |
---|
151 | {} |
---|
152 | |
---|
153 | BEGIN_MSG_MAP_EX(thisClass) |
---|
154 | MSG_WM_DESTROY(OnDestroy) |
---|
155 | |
---|
156 | CHAIN_MSG_MAP(genericAddlistClass) |
---|
157 | CHAIN_MSG_MAP(listClass) |
---|
158 | DEFAULT_REFLECTION_HANDLER() |
---|
159 | END_MSG_MAP() |
---|
160 | |
---|
161 | void uiUpdate(const hal::torrent_details_ptr pT); |
---|
162 | void saveSettings(); |
---|
163 | |
---|
164 | friend class boost::serialization::access; |
---|
165 | template<class Archive> |
---|
166 | void serialize(Archive& ar, const unsigned int version) |
---|
167 | { |
---|
168 | ar & boost::serialization::make_nvp("listview", boost::serialization::base_object<listClass>(*this)); |
---|
169 | } |
---|
170 | |
---|
171 | void newItem(); |
---|
172 | void editItem(int); |
---|
173 | void deleteItem(int); |
---|
174 | |
---|
175 | private: |
---|
176 | void OnAttach(); |
---|
177 | void OnDestroy(); |
---|
178 | }; |
---|
179 | |
---|
180 | typedef NewTorrent_PeersListViewCtrl::SelectionManager NewTorrent_PeersListViewManager; |
---|
181 | |
---|
182 | #endif |
---|