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 | #include <string> |
---|
8 | #include <boost/format.hpp> |
---|
9 | #include <boost/bind.hpp> |
---|
10 | |
---|
11 | #include "stdAfx.hpp" |
---|
12 | #include "Halite.hpp" |
---|
13 | #include "HaliteWindow.hpp" |
---|
14 | |
---|
15 | #include "CSSFileDialog.hpp" |
---|
16 | #include "RadioPaneDlg.hpp" |
---|
17 | |
---|
18 | #include "HaliteDialog.hpp" |
---|
19 | #include "AdvHaliteDialog.hpp" |
---|
20 | #include "AddTorrentDialog.hpp" |
---|
21 | #include "NewTorrentDialog.hpp" |
---|
22 | #include "SplashDialog.hpp" |
---|
23 | |
---|
24 | #include "ConfigOptions.hpp" |
---|
25 | #include "halConfig.hpp" |
---|
26 | |
---|
27 | HaliteWindow::HaliteWindow(unsigned areYouMe = 0) : |
---|
28 | iniClass("HaliteWindow", "HaliteWindow"), |
---|
29 | haliteList(*this), |
---|
30 | WM_AreYouMe_(areYouMe), |
---|
31 | splitterPos(100), |
---|
32 | use_tray(true), |
---|
33 | advancedUI(false), |
---|
34 | closeToTray(false), |
---|
35 | confirmClose(true), |
---|
36 | activeTab(0) |
---|
37 | { |
---|
38 | rect.top = 10; |
---|
39 | rect.left = 10; |
---|
40 | rect.bottom = 430; |
---|
41 | rect.right = 620; |
---|
42 | |
---|
43 | load_from_ini(); |
---|
44 | } |
---|
45 | |
---|
46 | HaliteWindow::~HaliteWindow() |
---|
47 | { |
---|
48 | save_to_ini(); |
---|
49 | ATLASSERT(!::IsWindow(m_hWnd)); |
---|
50 | } |
---|
51 | |
---|
52 | BOOL HaliteWindow::PreTranslateMessage(MSG* pMsg) |
---|
53 | { |
---|
54 | if(CFrameWindowImpl<HaliteWindow>::PreTranslateMessage(pMsg)) |
---|
55 | return TRUE; |
---|
56 | |
---|
57 | if (!advancedUI) |
---|
58 | return mp_dlg->PreTranslateMessage(pMsg); |
---|
59 | else |
---|
60 | return mp_advDlg->PreTranslateMessage(pMsg); |
---|
61 | } |
---|
62 | |
---|
63 | LRESULT HaliteWindow::OnCreate(LPCREATESTRUCT lpcs) |
---|
64 | { |
---|
65 | try |
---|
66 | { |
---|
67 | HAL_DEV_MSG(L"HaliteWindow::OnCreate"); |
---|
68 | |
---|
69 | SetWindowText(L"Halite"); |
---|
70 | MoveWindow(rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, false); |
---|
71 | |
---|
72 | // MARGINS m = {20, 20, 0, 100}; |
---|
73 | // SetMargins(m); |
---|
74 | |
---|
75 | hal::event_log.post(shared_ptr<hal::EventDetail>( |
---|
76 | new hal::EventMsg(L"Loading Halite config..."))); |
---|
77 | hal::config().load_from_ini(); |
---|
78 | |
---|
79 | hal::event_log.post(shared_ptr<hal::EventDetail>( |
---|
80 | new hal::EventMsg(L"Applying setting..."))); |
---|
81 | if (!hal::config().settingsChanged()) |
---|
82 | { |
---|
83 | hal::event_log.post(boost::shared_ptr<hal::EventDetail>( |
---|
84 | new hal::EventDebug(hal::event_logger::critical, hal::app().res_wstr(HAL_WINDOW_SOCKETS_FAILED)))); |
---|
85 | |
---|
86 | MessageBox(hal::app().res_wstr(HAL_WINDOW_SOCKETS_FAILED).c_str(), 0, 0); |
---|
87 | |
---|
88 | DestroyWindow(); |
---|
89 | return 0; |
---|
90 | } |
---|
91 | |
---|
92 | hal::event_log.post(shared_ptr<hal::EventDetail>( |
---|
93 | new hal::EventMsg(L"Starting GUI..."))); |
---|
94 | |
---|
95 | RECT rc; GetClientRect(&rc); |
---|
96 | SetMenu(0); |
---|
97 | |
---|
98 | //Init ToolBar |
---|
99 | HWND hWndToolBar = CreateSimpleToolBarCtrl(m_hWnd, HAL_MAINFRAME, FALSE, ATL_SIMPLE_TOOLBAR_PANE_STYLE); |
---|
100 | |
---|
101 | // Init ReBar |
---|
102 | CreateSimpleReBar(ATL_SIMPLE_REBAR_NOBORDER_STYLE); |
---|
103 | AddSimpleReBarBand(hWndToolBar, NULL, TRUE); |
---|
104 | |
---|
105 | // Init the StatusBar |
---|
106 | m_hWndStatusBar = m_StatusBar.Create(*this); |
---|
107 | UIAddStatusBar(m_hWndStatusBar); |
---|
108 | |
---|
109 | int panes[] = {ID_DEFAULT_PANE, IDPANE_FILTER, IDPANE_DHT, IDPANE_STATUS}; |
---|
110 | m_StatusBar.SetPanes(panes, 4, false); |
---|
111 | |
---|
112 | // Create the Splitter Control |
---|
113 | m_Split.Create(m_hWnd, rc, NULL, WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN); |
---|
114 | m_Split.SetSplitterExtendedStyle(!SPLIT_PROPORTIONAL, SPLIT_PROPORTIONAL); |
---|
115 | m_Split.SetSplitterPos(splitterPos); |
---|
116 | |
---|
117 | m_hWndClient = m_Split.m_hWnd; |
---|
118 | |
---|
119 | hal::event_log.post(shared_ptr<hal::EventDetail>( |
---|
120 | new hal::EventMsg(L"Creating main listview..."))); |
---|
121 | // Create ListView and Dialog |
---|
122 | haliteList.Create(m_Split.m_hWnd, rc, NULL, |
---|
123 | LVS_REPORT|WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|LVS_SHOWSELALWAYS); |
---|
124 | haliteList.manager().attach(bind(&HaliteWindow::issueUiUpdate, this)); |
---|
125 | |
---|
126 | |
---|
127 | hal::event_log.post(shared_ptr<hal::EventDetail>( |
---|
128 | new hal::EventMsg(L"Creating classic dialog..."))); |
---|
129 | mp_dlg.reset(new HaliteDialog(*this)), |
---|
130 | mp_dlg->Create(m_Split.m_hWnd); |
---|
131 | // mp_dlg->ShowWindow(true); |
---|
132 | |
---|
133 | |
---|
134 | hal::event_log.post(shared_ptr<hal::EventDetail>( |
---|
135 | new hal::EventMsg(L"Creating advanced dialog..."))); |
---|
136 | mp_advDlg.reset(new AdvHaliteDialog(*this)); |
---|
137 | mp_advDlg->Create(m_Split.m_hWnd); |
---|
138 | // mp_advDlg->ShowWindow(true); |
---|
139 | |
---|
140 | // m_Split.SetSplitterPanes(*mp_list, *mp_dlg); |
---|
141 | |
---|
142 | hal::event_log.post(shared_ptr<hal::EventDetail>( |
---|
143 | new hal::EventMsg(L"Creating tray icon..."))); |
---|
144 | // Create the tray icon. |
---|
145 | trayIcon_.Create(this, HAL_TRAY_MENU, L"Halite", |
---|
146 | CTrayNotifyIcon::LoadIconResource(HAL_APP_ICON), WM_TRAYNOTIFY, HAL_TRAY_MENU); |
---|
147 | trayIcon_.Hide(); |
---|
148 | |
---|
149 | // Add ToolBar and register it along with StatusBar for UIUpdates |
---|
150 | UIAddToolBar(hWndToolBar); |
---|
151 | UISetCheck(ID_VIEW_TOOLBAR, 1); |
---|
152 | UISetCheck(ID_VIEW_STATUS_BAR, 1); |
---|
153 | UISetCheck(HAL_TRAY_MENU, 1); |
---|
154 | |
---|
155 | // TBBUTTONINFO tbinfo = { sizeof(TBBUTTONINFO) }; |
---|
156 | // tbinfo.dwMask = TBIF_STATE; |
---|
157 | // tbinfo.fsState = TBSTATE_INDETERMINATE; |
---|
158 | // ::SendMessage(hWndToolBar, TB_SETBUTTONINFO, ID_FILE_NEW, (LPARAM)&tbinfo); |
---|
159 | |
---|
160 | // Register UIEvents and the timer for the monitoring interval |
---|
161 | SetTimer(ID_UPDATE_TIMER, 500); |
---|
162 | SetTimer(ID_SAVE_TIMER, 5000); |
---|
163 | connectUiUpdate(bind(&HaliteWindow::updateWindow, this)); |
---|
164 | |
---|
165 | hal::event_log.post(shared_ptr<hal::EventDetail>( |
---|
166 | new hal::EventMsg(L"Registering drop target..."))); |
---|
167 | RegisterDropTarget(); |
---|
168 | |
---|
169 | // Register object for message filtering and idle updates |
---|
170 | WTL::CMessageLoop* pLoop = _Module.GetMessageLoop(); |
---|
171 | assert(pLoop != NULL); |
---|
172 | pLoop->AddMessageFilter(this); |
---|
173 | pLoop->AddIdleHandler(this); |
---|
174 | |
---|
175 | // haliteList.manager().setSelected(0); |
---|
176 | setCorrectDialog(); |
---|
177 | |
---|
178 | hal::event_log.post(shared_ptr<hal::EventDetail>( |
---|
179 | new hal::EventMsg(L"Starting event reciever..."))); |
---|
180 | hal::bittorrent().startEventReceiver(); |
---|
181 | hal::event_log.post(shared_ptr<hal::EventDetail>( |
---|
182 | new hal::EventMsg(L"Initial setup complete!"))); |
---|
183 | issueUiUpdate(); |
---|
184 | |
---|
185 | } |
---|
186 | catch(const std::exception& e) |
---|
187 | { |
---|
188 | hal::event_log.post(boost::shared_ptr<hal::EventDetail>( |
---|
189 | new hal::EventStdException(hal::event_logger::critical, e, L"HaliteWindow::OnCreate"))); |
---|
190 | |
---|
191 | DestroyWindow(); |
---|
192 | } |
---|
193 | |
---|
194 | return 0; |
---|
195 | } |
---|
196 | |
---|
197 | LRESULT HaliteWindow::OnAdvanced(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) |
---|
198 | { |
---|
199 | advancedUI = !advancedUI; |
---|
200 | setCorrectDialog(); |
---|
201 | |
---|
202 | return 0; |
---|
203 | } |
---|
204 | |
---|
205 | LRESULT HaliteWindow::OnTrayNotification(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam) |
---|
206 | { |
---|
207 | trayIcon_.OnTrayNotification(wParam, lParam); |
---|
208 | |
---|
209 | return 0; |
---|
210 | } |
---|
211 | |
---|
212 | void HaliteWindow::setCorrectDialog() |
---|
213 | { |
---|
214 | if (!advancedUI) |
---|
215 | { |
---|
216 | mp_dlg->ShowWindow(SW_SHOW); |
---|
217 | mp_advDlg->ShowWindow(SW_HIDE); |
---|
218 | m_Split.SetSplitterPanes(haliteList, *mp_dlg); |
---|
219 | } |
---|
220 | else |
---|
221 | { |
---|
222 | mp_dlg->ShowWindow(SW_HIDE); |
---|
223 | mp_advDlg->ShowWindow(SW_SHOW); |
---|
224 | m_Split.SetSplitterPanes(haliteList, *mp_advDlg); |
---|
225 | } |
---|
226 | ui().update(); |
---|
227 | } |
---|
228 | |
---|
229 | void HaliteWindow::updateWindow() |
---|
230 | { |
---|
231 | try |
---|
232 | { |
---|
233 | |
---|
234 | hal::SessionDetail details = hal::bittorrent().getSessionDetails(); |
---|
235 | |
---|
236 | if (details.port > -1) |
---|
237 | UISetText(0, |
---|
238 | (hal::wform(hal::app().res_wstr(HAL_PORT_OPEN)) % details.port ).str().c_str()); |
---|
239 | else |
---|
240 | UISetText(0, hal::app().res_wstr(HAL_NOT_LISTENING).c_str()); |
---|
241 | |
---|
242 | wstring downloadRates = (hal::wform(hal::app().res_wstr(HAL_DOWN_RATES)) |
---|
243 | % (details.speed.first/1024) |
---|
244 | % (details.speed.second/1024)).str(); |
---|
245 | |
---|
246 | UISetText(3, downloadRates.c_str()); |
---|
247 | trayIcon_.SetTooltipText(downloadRates.c_str()); |
---|
248 | |
---|
249 | if (details.dht_on) |
---|
250 | { |
---|
251 | wstring dht = (hal::wform(hal::app().res_wstr(HAL_DHT_ON)) |
---|
252 | % details.dht_nodes).str(); |
---|
253 | |
---|
254 | UISetText(2, dht.c_str()); |
---|
255 | } |
---|
256 | else |
---|
257 | { |
---|
258 | UISetText(2, hal::app().res_wstr(HAL_DHT_OFF).c_str()); |
---|
259 | } |
---|
260 | |
---|
261 | if (details.ip_filter_on) |
---|
262 | { |
---|
263 | wstring filter = (hal::wform(hal::app().res_wstr(HAL_IPFILTER_ON)) |
---|
264 | % details.ip_ranges_filtered).str(); |
---|
265 | |
---|
266 | UISetText(1, filter.c_str()); |
---|
267 | } |
---|
268 | else |
---|
269 | { |
---|
270 | UISetText(1, hal::app().res_wstr(HAL_IPFILTER_OFF).c_str()); |
---|
271 | } |
---|
272 | |
---|
273 | } HAL_GENERIC_FN_EXCEPTION_CATCH(L"HaliteWindow::updateWindow()") |
---|
274 | } |
---|
275 | |
---|
276 | void HaliteWindow::OnTimer(UINT uTimerID) |
---|
277 | { |
---|
278 | if (uTimerID == ID_UPDATE_TIMER) |
---|
279 | { |
---|
280 | issueUiUpdate(); |
---|
281 | } |
---|
282 | else if (uTimerID == ID_SAVE_TIMER) |
---|
283 | { |
---|
284 | try |
---|
285 | { |
---|
286 | |
---|
287 | hal::ini().save_data(); |
---|
288 | hal::bittorrent().save_torrent_data(); |
---|
289 | |
---|
290 | } HAL_GENERIC_FN_EXCEPTION_CATCH(L"HaliteWindow::OnTimer(ID_SAVE_TIMER)") |
---|
291 | } |
---|
292 | else |
---|
293 | { |
---|
294 | SetMsgHandled(false); |
---|
295 | } |
---|
296 | } |
---|
297 | |
---|
298 | void HaliteWindow::issueUiUpdate() |
---|
299 | { |
---|
300 | try |
---|
301 | { |
---|
302 | |
---|
303 | const hal::torrent_details_manager& torrents = hal::bittorrent().updatetorrent_details_manager( |
---|
304 | haliteList.manager().selected(), haliteList.manager().allSelected()); |
---|
305 | |
---|
306 | ui_update_signal_(torrents); |
---|
307 | |
---|
308 | } HAL_GENERIC_FN_EXCEPTION_CATCH(L"HaliteWindow::issueUiUpdate()") |
---|
309 | } |
---|
310 | |
---|
311 | LRESULT HaliteWindow::OnCopyData(HWND, PCOPYDATASTRUCT pCSD) |
---|
312 | { |
---|
313 | hal::event_log.post(shared_ptr<hal::EventDetail>( |
---|
314 | new hal::EventMsg(L"I recieved data."))); |
---|
315 | |
---|
316 | switch (pCSD->dwData) |
---|
317 | { |
---|
318 | case HALITE_SENDING_CMD: |
---|
319 | { |
---|
320 | wstring filename(static_cast<wchar_t*>(pCSD->lpData), pCSD->cbData/sizeof(wchar_t)); |
---|
321 | |
---|
322 | hal::event_log.post(shared_ptr<hal::EventDetail>( |
---|
323 | new hal::EventMsg((hal::wform(L"Recieved data: %1%.") % filename), hal::event_logger::info))); |
---|
324 | |
---|
325 | ProcessFile(filename.c_str()); |
---|
326 | break; |
---|
327 | } |
---|
328 | default: |
---|
329 | break; |
---|
330 | } |
---|
331 | return 0; |
---|
332 | } |
---|
333 | |
---|
334 | void HaliteWindow::ProcessFile(LPCTSTR lpszPath) |
---|
335 | { |
---|
336 | try |
---|
337 | { |
---|
338 | |
---|
339 | wstring default_save_folder = wpath(hal::config().default_save_folder_).native_file_string(); |
---|
340 | wstring default_move_folder = wpath(hal::config().default_move_folder_).native_file_string(); |
---|
341 | bool use_move_to = hal::config().use_move_to_; |
---|
342 | bool startPaused = false; |
---|
343 | bool managed = false; |
---|
344 | hal::bit::allocations allocation_type = hal::bit::sparse_allocation; |
---|
345 | |
---|
346 | if (!boost::filesystem::exists(default_save_folder)) |
---|
347 | boost::filesystem::create_directory(default_save_folder); |
---|
348 | |
---|
349 | if (hal::config().save_prompt_) |
---|
350 | { |
---|
351 | AddTorrentDialog addTorrent(default_save_folder, default_move_folder, use_move_to, startPaused, managed, allocation_type); |
---|
352 | |
---|
353 | if (IDOK != addTorrent.DoModal()) |
---|
354 | return; |
---|
355 | } |
---|
356 | |
---|
357 | wpath file(lpszPath, boost::filesystem::native); |
---|
358 | hal::bittorrent().add_torrent(file, wpath(default_save_folder), startPaused, managed, allocation_type, |
---|
359 | wpath(default_move_folder), use_move_to); |
---|
360 | |
---|
361 | ui().update(); |
---|
362 | |
---|
363 | } |
---|
364 | catch(const boost::filesystem::filesystem_error&) |
---|
365 | { |
---|
366 | hal::event_log.post(shared_ptr<hal::EventDetail>( |
---|
367 | new hal::EventDebug(hal::event_logger::warning, L"filesystem error"))); |
---|
368 | } |
---|
369 | } |
---|
370 | |
---|
371 | void HaliteWindow::OnClose() |
---|
372 | { |
---|
373 | if (closeToTray && trayIcon_.IsHidden()) |
---|
374 | { |
---|
375 | ShowWindow(SW_HIDE); |
---|
376 | trayIcon_.Show(); |
---|
377 | } |
---|
378 | else |
---|
379 | { |
---|
380 | if (!confirmClose || (confirmClose && |
---|
381 | MessageBox(hal::app().res_wstr(HAL_WINDOW_CLOSECONFRIM).c_str(), |
---|
382 | hal::app().res_wstr(HAL_HALITE).c_str(), MB_YESNO) == IDYES)) |
---|
383 | { |
---|
384 | DestroyWindow(); |
---|
385 | } |
---|
386 | } |
---|
387 | } |
---|
388 | |
---|
389 | void HaliteWindow::ShutdownThread() |
---|
390 | { |
---|
391 | try |
---|
392 | { |
---|
393 | |
---|
394 | win32_exception::install_handler(); |
---|
395 | hal::bittorrent().close_all(0); |
---|
396 | |
---|
397 | hal::bittorrent().stopEventReceiver(); |
---|
398 | Sleep(3000); |
---|
399 | |
---|
400 | hal::bittorrent().shutDownSession(); |
---|
401 | |
---|
402 | } HAL_GENERIC_FN_EXCEPTION_CATCH(L"HaliteWindow::ShutdownThread()") |
---|
403 | } |
---|
404 | |
---|
405 | void HaliteWindow::OnDestroy() |
---|
406 | { |
---|
407 | try |
---|
408 | { |
---|
409 | |
---|
410 | KillTimer(ID_UPDATE_TIMER); |
---|
411 | KillTimer(ID_SAVE_TIMER); |
---|
412 | |
---|
413 | Sleep(0); |
---|
414 | |
---|
415 | splitterPos = m_Split.GetSplitterPos(); |
---|
416 | |
---|
417 | save_to_ini(); |
---|
418 | hal::ini().save_data(); |
---|
419 | |
---|
420 | if (halite().showMessage()) |
---|
421 | { |
---|
422 | HAL_DEV_MSG(L"Showing SplashDialog"); |
---|
423 | |
---|
424 | SplashDialog splDlg; |
---|
425 | splDlg.DoModal(); |
---|
426 | } |
---|
427 | else |
---|
428 | { |
---|
429 | HAL_DEV_MSG(L"No SplashDialog"); |
---|
430 | |
---|
431 | thread shutdown(bind(& HaliteWindow::ShutdownThread, this)); |
---|
432 | shutdown.join(); |
---|
433 | } |
---|
434 | |
---|
435 | HAL_DEV_MSG(L"Saving before quiting"); |
---|
436 | |
---|
437 | // Resave for sake of your health. |
---|
438 | save_to_ini(); |
---|
439 | halite().save_to_ini(); |
---|
440 | hal::ini().save_data(); |
---|
441 | |
---|
442 | HAL_DEV_MSG(L"Posting Quit Message"); |
---|
443 | PostQuitMessage(0); |
---|
444 | |
---|
445 | } HAL_GENERIC_FN_EXCEPTION_CATCH(L"HaliteWindow::OnDestroy()") |
---|
446 | } |
---|
447 | |
---|
448 | void HaliteWindow::OnSize(UINT type, WTL::CSize) |
---|
449 | { |
---|
450 | if (type == SIZE_MINIMIZED) |
---|
451 | { |
---|
452 | if (use_tray) |
---|
453 | { |
---|
454 | ShowWindow(SW_HIDE); |
---|
455 | trayIcon_.Show(); |
---|
456 | } |
---|
457 | } |
---|
458 | else |
---|
459 | { |
---|
460 | if (trayIcon_.IsShowing()) |
---|
461 | trayIcon_.Hide(); |
---|
462 | |
---|
463 | GetWindowRect(rect); |
---|
464 | } |
---|
465 | |
---|
466 | SetMsgHandled(false); |
---|
467 | } |
---|
468 | |
---|
469 | void HaliteWindow::OnMove(WTL::CSize) |
---|
470 | { |
---|
471 | WINDOWPLACEMENT wnd = { sizeof(WINDOWPLACEMENT ) }; |
---|
472 | GetWindowPlacement(&wnd); |
---|
473 | |
---|
474 | if (wnd.showCmd != SW_SHOWMINIMIZED) |
---|
475 | GetWindowRect(rect); |
---|
476 | |
---|
477 | SetMsgHandled(false); |
---|
478 | } |
---|
479 | |
---|
480 | void HaliteWindow::OnShowWindow(BOOL bShow, UINT nStatus) |
---|
481 | { |
---|
482 | SetMsgHandled(false); |
---|
483 | } |
---|
484 | |
---|
485 | LRESULT HaliteWindow::OnTrayOpenHalite(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) |
---|
486 | { |
---|
487 | trayIcon_.Hide(); |
---|
488 | ShowWindow(SW_RESTORE); |
---|
489 | |
---|
490 | return 0; |
---|
491 | } |
---|
492 | |
---|
493 | LRESULT HaliteWindow::OnTrayExit(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) |
---|
494 | { |
---|
495 | PostMessage(WM_CLOSE, 0, 0); |
---|
496 | |
---|
497 | return 0; |
---|
498 | } |
---|
499 | |
---|
500 | LRESULT HaliteWindow::OnFileOpen(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) |
---|
501 | { |
---|
502 | CSSFileDialog dlgOpen(TRUE, NULL, NULL, OFN_HIDEREADONLY, L"Torrents (*.torrent)|*.torrent|", m_hWnd); |
---|
503 | |
---|
504 | if (dlgOpen.DoModal() == IDOK) |
---|
505 | { |
---|
506 | ProcessFile(dlgOpen.m_ofn.lpstrFile); |
---|
507 | } |
---|
508 | |
---|
509 | return 0; |
---|
510 | } |
---|
511 | |
---|
512 | LRESULT HaliteWindow::OnFileNew(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) |
---|
513 | { |
---|
514 | wstring title = hal::app().res_wstr(HAL_NEWT_DIALOG_TITLE); |
---|
515 | |
---|
516 | NewTorrentDialog newTorrent(title.c_str()); |
---|
517 | newTorrent.DoModal(); |
---|
518 | |
---|
519 | return 0; |
---|
520 | } |
---|
521 | |
---|
522 | LRESULT HaliteWindow::OnSettings(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) |
---|
523 | { |
---|
524 | ConfigOptionsProp sheet(this, L"Settings"); |
---|
525 | sheet.DoModal(); |
---|
526 | |
---|
527 | hal::config().settingsChanged(); |
---|
528 | setCorrectDialog(); |
---|
529 | |
---|
530 | return 0; |
---|
531 | } |
---|
532 | |
---|
533 | LRESULT HaliteWindow::OnPauseAll(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) |
---|
534 | { |
---|
535 | hal::bittorrent().pauseAllTorrents(); |
---|
536 | |
---|
537 | ui().update(); |
---|
538 | return 0; |
---|
539 | } |
---|
540 | |
---|
541 | LRESULT HaliteWindow::OnResumeAll(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) |
---|
542 | { |
---|
543 | hal::bittorrent().unpauseAllTorrents(); |
---|
544 | |
---|
545 | ui().update(); |
---|
546 | return 0; |
---|
547 | } |
---|
548 | |
---|
549 | LRESULT HaliteWindow::OnHelp(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) |
---|
550 | { |
---|
551 | ConfigOptionsProp sheet(this, L"Settings", 4); |
---|
552 | sheet.DoModal(); |
---|
553 | |
---|
554 | hal::config().settingsChanged(); |
---|
555 | |
---|
556 | return 0; |
---|
557 | } |
---|
558 | |
---|
559 | LRESULT HaliteWindow::OnViewStatusBar(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) |
---|
560 | { |
---|
561 | BOOL bVisible = !::IsWindowVisible(m_hWndStatusBar); |
---|
562 | ::ShowWindow(m_hWndStatusBar, bVisible ? SW_SHOWNOACTIVATE : SW_HIDE); |
---|
563 | UISetCheck(ID_VIEW_STATUS_BAR, bVisible); |
---|
564 | |
---|
565 | UpdateLayout(); |
---|
566 | |
---|
567 | return 0; |
---|
568 | } |
---|
569 | |
---|
570 | LRESULT HaliteWindow::OnEraseBkgnd(HDC dc) |
---|
571 | { |
---|
572 | return 1; |
---|
573 | } |
---|
574 | |
---|
575 | LRESULT HaliteWindow::OnPaint(HDC dc) |
---|
576 | { |
---|
577 | return 1; |
---|
578 | } |
---|
579 | |
---|
580 | LRESULT HaliteWindow::OnAreYouMe(UINT, WPARAM, LPARAM, BOOL&) |
---|
581 | { |
---|
582 | hal::event_log.post(shared_ptr<hal::EventDetail>( |
---|
583 | new hal::EventMsg(L"I tried to contact me."))); |
---|
584 | |
---|
585 | return WM_AreYouMe_; |
---|
586 | } |
---|