From 7aff1e4cb053394db57c2814d5fe1e6493e0cc75 Mon Sep 17 00:00:00 2001 From: watcherhd Date: Sat, 26 Nov 2011 14:19:43 +0000 Subject: Project folders rename part 2 git-svn-id: http://miranda-plugins.googlecode.com/svn/trunk@214 e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb --- Gps+/options.cpp | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 Gps+/options.cpp (limited to 'Gps+/options.cpp') diff --git a/Gps+/options.cpp b/Gps+/options.cpp new file mode 100644 index 0000000..c152fdd --- /dev/null +++ b/Gps+/options.cpp @@ -0,0 +1,151 @@ +/* + GPS+: Service plugin for Miranda IM + Copyright 2007-2008 persei + + persei@miranda.im + http://persei.miranda.im + http://svn.miranda.im/mainrepo/gps+ + + 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. +*/ + +#include "common.h" + +extern HINSTANCE hInst; + +BOOL CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch ( msg ) { + case WM_INITDIALOG: + { + DWORD Ports_MemSize = 0; + DWORD Ports_Count = 0; + BYTE* lpPorts = NULL; + + //Getting Ports_MemSize value... + EnumPorts(NULL, + 1, + lpPorts, + 0, + &Ports_MemSize, + &Ports_Count); + + + //Getting lpPorts... + lpPorts = new BYTE[Ports_MemSize]; + EnumPorts(NULL, + 1, + lpPorts, + Ports_MemSize, + &Ports_MemSize, + &Ports_Count); + + PORT_INFO_1 *pPortInfo; + pPortInfo = (PORT_INFO_1 *)lpPorts - 1; + + for(int i = 0; i < Ports_Count; i++) + { + pPortInfo++; + if(!strstr(pPortInfo->pName, "COM")) continue; + + pPortInfo->pName[strlen(pPortInfo->pName) - 1] = 0; + + char COM_string[255]; + + sprintf_s(COM_string, 255, "\\\\.\\%s", pPortInfo->pName); + + HANDLE h = CreateFile(COM_string, GENERIC_READ|GENERIC_WRITE, 0, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,NULL); + + if(h != INVALID_HANDLE_VALUE) + { + CloseHandle(h); + SendDlgItemMessage(hwndDlg, IDC_COMPORT, CB_ADDSTRING, 0, (LPARAM)pPortInfo->pName); + } + } + + + WORD wPort = DBGetContactSettingWord(NULL, "GPS+", "Port", 999); + if(wPort != 999){ + char ComPort[255]; + sprintf_s(ComPort, 255, "COM%d", wPort); + SetDlgItemText(hwndDlg, IDC_COMPORT, ComPort); + } + + CheckDlgButton(hwndDlg, IDC_AUTODISCONNECT, DBGetContactSettingByte(NULL, "GPS+", "AutoDisconnect", 1)); + CheckDlgButton(hwndDlg, IDC_CHECKSUM, DBGetContactSettingByte(NULL, "GPS+", "CheckSum", 1)); + + TranslateDialogDefault( hwndDlg ); + return TRUE; + } + case WM_COMMAND: + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + return TRUE; + case WM_NOTIFY: + if (((LPNMHDR)lParam)->code == PSN_APPLY ) { + WORD wPort = 0; + char ComPort[255]; + GetDlgItemText(hwndDlg, IDC_COMPORT, ComPort, 255); + sscanf(ComPort, "COM%d", &wPort); + if(wPort == 0){ + MessageBox(0, Translate("Wrong port specified"), Translate("Error"), MB_OK); + } + else + { + gps.SetPort(wPort); + if(gps.ReConnect()) + { + DBWriteContactSettingWord(NULL, "GPS+", "Port", wPort); + } + else + { + MessageBox(0, Translate("Unnable connect to specified port"), Translate("Error"), MB_OK); + } + + } + DBWriteContactSettingByte(NULL, "GPS+", "CheckSum", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_CHECKSUM)); + DBWriteContactSettingByte(NULL, "GPS+", "AutoDisconnect", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_AUTODISCONNECT)); + gps.SetAutoDisconnect(DBGetContactSettingByte(NULL, "GPS+", "AutoDisconnect", 1) ? 5 : 0); + gps.SetCheckSum(DBGetContactSettingByte(NULL, "GPS+", "CheckSum", 1)); + } + return TRUE; + } + + return FALSE; +} + +int OptionsInit(WPARAM wParam, LPARAM lParam) +{ + OPTIONSDIALOGPAGE odp; + + odp.cbSize = 60; + odp.position = -790000000; + odp.hInstance = hInst; + odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS); + odp.flags = ODPF_BOLDGROUPS; + odp.pszTitle = Translate("GPS+"); + odp.pszGroup = Translate("Services"); + odp.nIDBottomSimpleControl = 0; + odp.pfnDlgProc = DlgProcOptions; + CallService( MS_OPT_ADDPAGE, wParam,( LPARAM )&odp ); + + return 0; +} + + +void InitOptions() +{ + HookEvent(ME_OPT_INITIALISE, OptionsInit); +} \ No newline at end of file -- cgit v1.2.3