/*
* Copyright (C) 2001-2006 Jacek Sieka, arnetheduck on gmail point com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#if !defined(ABOUT_DLG_H)
#define ABOUT_DLG_H
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "../client/HttpConnection.h"
#include "../client/SimpleXML.h"
#include "FlatTabCtrl.h"
#include "WinUtil.h"
static const TCHAR mcdcthanks[] =
_T("Big thanks to all people that supported me through this ")
_T("development phase. Kanelbullen, Banten, Lightgirl_xp, Trem, Pothead, Flow, Rag3Rac3r ")
_T("and all those whom I've missed. \r\n")
_T("A pat on the shoulder to CraKteR, my co-developer.\r\n")
_T("A big thanks also goes out to the beta testers Anna and h. \r\n")
_T("Finally I would like to send my greats to my beloved ")
_T("girlfriend, I fancy you! \r\n\r\n")
_T("This client is based upon DC++ by Jacek Sieka (arnetheduck), but ")
_T("it also contains code created by: PPK, Big Muscle, Sulan, Trem, ")
_T("Pothead, Flow, Opera, Virus27, da sickb0y ... \r\n\r\n")
_T("McDC++ is licensed under GPL.");
class AboutDlg : public CDialogImpl<AboutDlg>, private HttpConnectionListener, private TimerManagerListener
{
public:
enum { IDD = IDD_ABOUTBOX };
enum { WM_VERSIONDATA = WM_APP + 53 };
AboutDlg() { };
virtual ~AboutDlg() { };
BEGIN_MSG_MAP(AboutDlg)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
MESSAGE_HANDLER(WM_CTLCOLORDLG, OnCtlColor)
MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnCtlColor)
MESSAGE_HANDLER(WM_VERSIONDATA, onVersionData)
COMMAND_ID_HANDLER(IDOK, OnCloseCmd)
COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd)
END_MSG_MAP()
LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) {
SetDlgItemText(IDC_VERSION, _T("McDC++ v") _T(McDCVERSIONSTRING2) _T("\n\n Built on: DC++ ") _T(VERSIONSTRING) _T("\n\nhttp://mcdcplusplus.myftp.org\n\nby McCM"));
ctrl.Attach(GetDlgItem(IDC_THANKS));
ctrl.FmtLines(TRUE);
ctrl.AppendText(mcdcthanks, TRUE);
ctrl.Detach();
SetDlgItemText(IDC_TTH, WinUtil::tth.c_str());
SetDlgItemText(IDC_LATEST, CTSTRING(DOWNLOADING));
char buf[256];
sprintf(buf, "Total Uptime: %s", WinUtil::formatTime(SETTING(TOTAL_UPTIMES)).c_str());
SetDlgItemText(IDC_TOTAL_UPTIME, Text::toT(buf).c_str());
sprintf(buf, "Upload: %s, Download: %s", Util::formatBytes(SETTING(TOTAL_UPLOADS)).c_str(), Util::formatBytes(SETTING(TOTAL_DOWNLOADS)).c_str());
SetDlgItemText(IDC_TOTALS, Text::toT(buf).c_str());
if(SETTING(TOTAL_DOWNLOADS) > 0) {
sprintf(buf, "Ratio (up/down): %.2f", ((double)SETTING(TOTAL_UPLOADS)) / ((double)SETTING(TOTAL_DOWNLOADS)));
SetDlgItemText(IDC_RATIO, Text::toT(buf).c_str());
}
sprintf(buf, "Uptime: %s", WinUtil::formatTime(Util::getUptime()).c_str());
SetDlgItemText(IDC_UPTIME, Text::toT(buf).c_str());
CenterWindow(GetParent());
if(!BOOLSETTING(DONT_DOWNLOAD_VERSION_FILE)) {
c.addListener(this);
c.downloadFile("http://www.mcdcpp.net/version.xml");
} else {
tstring* x = new tstring(_T("Version file downloading disabled"));
PostMessage(WM_VERSIONDATA, (WPARAM) x);
}
SetDlgItemText(IDC_HTTP, _T("Browser: HTTP v ") _T(McDC_HTTP_VERSION));
TimerManager::getInstance()->addListener(this);
return TRUE;
}
LRESULT onVersionData(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/) {
tstring* x = (tstring*) wParam;
SetDlgItemText(IDC_LATEST, x->c_str());
delete x;
return 0;
}
LRESULT OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
TimerManager::getInstance()->removeListener(this);
EndDialog(wID);
return 0;
}
LRESULT OnCtlColor(UINT, WPARAM wParam, LPARAM /*lParam*/, BOOL&) {
SetBkMode((HDC)wParam, SETTING(BK_SETTING));
SetTextColor((HDC)wParam, SETTING(BK_SETTING_TEXT));
return (LRESULT)WinUtil::bkBrush;
}
private:
CEdit ctrl;
HttpConnection c;
AboutDlg(const AboutDlg&) { dcassert(0); };
virtual void on(HttpConnectionListener::Data, HttpConnection* /*conn*/, const u_int8_t* buf, size_t len) throw() {
downBuf.append((char*)buf, len);
}
virtual void on(HttpConnectionListener::Complete, HttpConnection* conn, const string&) throw() {
try {
if(!downBuf.empty()) {
SimpleXML xml;
xml.fromXML(downBuf);
if(xml.findChild("DCUpdate")) {
xml.stepIn();
if(xml.findChild("Version")) {
tstring* x = new tstring(Text::toT(xml.getChildData()));
PostMessage(WM_VERSIONDATA, (WPARAM) x);
}
}
xml.stepOut();
}
} catch (...) {
// ...
}
conn->removeListener(this);
}
virtual void on(HttpConnectionListener::Failed, HttpConnection* conn, const string& aLine) throw() {
tstring* x = new tstring(Text::toT(aLine));
PostMessage(WM_VERSIONDATA, (WPARAM) x);
conn->removeListener(this);
}
virtual void on(TimerManagerListener::Second /*type*/, u_int32_t /*aTick*/) throw() {
static char buf[256];
sprintf(buf, "Uptime: %s", WinUtil::formatTime(Util::getUptime()).c_str());
SetDlgItemText(IDC_UPTIME, Text::toT(buf).c_str());
sprintf(buf, "Total Uptime: %s", WinUtil::formatTime(SETTING(TOTAL_UPTIMES)).c_str());
SetDlgItemText(IDC_TOTAL_UPTIME, Text::toT(buf).c_str());
}
string downBuf;
};
#endif // !defined(ABOUT_DLG_H)
/**
* @file
* $Id: AboutDlg.h 111 2006-11-17 12:42:35Z mccm $
*/