CInfo.cpp

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2006 Chris Schoeneman
00004  * 
00005  * This package is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * found in the file COPYING that should have accompanied this file.
00008  * 
00009  * This package is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  */
00014 
00015 #include "ProtocolTypes.h"
00016 #include "CStringUtil.h"
00017 #include "Version.h"
00018 #include "CArch.h"
00019 #include "CInfo.h"
00020 #include "LaunchUtil.h"
00021 #include "resource.h"
00022 
00023 //
00024 // CInfo
00025 //
00026 
00027 CInfo*                  CInfo::s_singleton = NULL;
00028 
00029 CInfo::CInfo(HWND parent) :
00030     m_parent(parent)
00031 {
00032     assert(s_singleton == NULL);
00033     s_singleton = this;
00034 }
00035 
00036 CInfo::~CInfo()
00037 {
00038     s_singleton = NULL;
00039 }
00040 
00041 void
00042 CInfo::doModal()
00043 {
00044     // do dialog
00045     DialogBoxParam(s_instance, MAKEINTRESOURCE(IDD_INFO),
00046                                 m_parent, (DLGPROC)dlgProc, (LPARAM)this);
00047 }
00048 
00049 void
00050 CInfo::init(HWND hwnd)
00051 {
00052     // collect info
00053     CString version    =
00054         CStringUtil::format(getString(IDS_TITLE).c_str(), kApplication, kVersion);
00055     CString hostname   = ARCH->getHostName();
00056     CString address    = ARCH->addrToString(ARCH->nameToAddr(hostname));
00057     CString userConfig = ARCH->getUserDirectory();
00058     if (!userConfig.empty()) {
00059         userConfig = ARCH->concatPath(userConfig, CONFIG_NAME);
00060     }
00061     CString sysConfig  = ARCH->getSystemDirectory();
00062     if (!sysConfig.empty()) {
00063         sysConfig = ARCH->concatPath(sysConfig, CONFIG_NAME);
00064     }
00065 
00066     // set info
00067     HWND child;
00068     child = getItem(hwnd, IDC_INFO_VERSION);
00069     setWindowText(child, version);
00070     child = getItem(hwnd, IDC_INFO_HOSTNAME);
00071     setWindowText(child, hostname);
00072     child = getItem(hwnd, IDC_INFO_IP_ADDRESS);
00073     setWindowText(child, address);
00074     child = getItem(hwnd, IDC_INFO_USER_CONFIG);
00075     setWindowText(child, userConfig);
00076     child = getItem(hwnd, IDC_INFO_SYS_CONFIG);
00077     setWindowText(child, sysConfig);
00078 
00079     // focus on okay button
00080     SetFocus(getItem(hwnd, IDOK));
00081 }
00082 
00083 BOOL
00084 CInfo::doDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM)
00085 {
00086     switch (message) {
00087     case WM_INITDIALOG:
00088         init(hwnd);
00089         return FALSE;
00090 
00091     case WM_COMMAND:
00092         switch (LOWORD(wParam)) {
00093         case IDOK:
00094         case IDCANCEL:
00095             EndDialog(hwnd, 0);
00096             return TRUE;
00097         }
00098         break;
00099 
00100     default:
00101         break;
00102     }
00103 
00104     return FALSE;
00105 }
00106 
00107 BOOL CALLBACK
00108 CInfo::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
00109 {
00110     return s_singleton->doDlgProc(hwnd, message, wParam, lParam);
00111 }

Generated on Fri Nov 6 00:18:45 2009 for synergy-plus by  doxygen 1.4.7