From 0a1a69241815b1e27051a51fa87f0b2f6fdbf2b4 Mon Sep 17 00:00:00 2001 From: Kirill Volinsky Date: Sat, 14 Feb 2015 18:23:37 +0000 Subject: first draft of add node dialog git-svn-id: http://svn.miranda-ng.org/main/trunk@12105 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/res/resource.rc | 33 ++++++ protocols/Tox/src/common.h | 7 ++ protocols/Tox/src/main.cpp | 4 + protocols/Tox/src/resource.h | 60 ++++++----- protocols/Tox/src/tox_events.cpp | 23 ++++- protocols/Tox/src/tox_options.cpp | 210 +++++++++++++++++++++++++++++++++++++- 6 files changed, 308 insertions(+), 29 deletions(-) diff --git a/protocols/Tox/res/resource.rc b/protocols/Tox/res/resource.rc index 0ad27956f3..e972922bdc 100644 --- a/protocols/Tox/res/resource.rc +++ b/protocols/Tox/res/resource.rc @@ -160,6 +160,34 @@ BEGIN LTEXT "Tox profile is encrypted. Enter the password to continue.",IDC_STATIC,7,5,197,18 END +IDD_OPTIONS_NODES DIALOGEX 0, 0, 314, 234 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD +EXSTYLE WS_EX_CONTROLPARENT +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + CONTROL "",IDC_NODESLIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,9,8,294,174 + PUSHBUTTON "Add",IDC_ADDNODE,79,187,50,14 + PUSHBUTTON "Change",IDC_CHANGE,133,187,50,14 + PUSHBUTTON "Remove",IDC_REMOVE,187,187,50,14 +END + +IDD_ADDNODE DIALOGEX 0, 0, 355, 131 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_NOFAILCREATE | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_CONTROLPARENT +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + LTEXT "IPv4",IDC_STATIC,34,15,25,8 + EDITTEXT IDC_IPV4,6,26,102,14,ES_AUTOHSCROLL + LTEXT "IPv6",IDC_STATIC,207,14,15,8 + EDITTEXT IDC_IPV6,159,26,94,14,ES_AUTOHSCROLL + LTEXT "Port",IDC_STATIC,321,16,34,8 + EDITTEXT IDC_PORT,306,26,40,14,ES_AUTOHSCROLL + LTEXT "Client ID",IDC_STATIC,143,65,63,8 + EDITTEXT IDC_CLIENTID,16,79,328,14,ES_AUTOHSCROLL + DEFPUSHBUTTON "OK",IDOK,200,110,50,14 + PUSHBUTTON "Cancel",IDCANCEL,267,111,50,14 +END + ///////////////////////////////////////////////////////////////////////////// // @@ -220,6 +248,11 @@ BEGIN VERTGUIDE, 7 BOTTOMMARGIN, 70 END + + IDD_ADDNODE, DIALOG + BEGIN + BOTTOMMARGIN, 130 + END END #endif // APSTUDIO_INVOKED diff --git a/protocols/Tox/src/common.h b/protocols/Tox/src/common.h index 93b22b718e..767f127f32 100644 --- a/protocols/Tox/src/common.h +++ b/protocols/Tox/src/common.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -68,4 +69,10 @@ T CreateFunction(LPCSTR functionName) return reinterpret_cast(GetProcAddress(g_hToxLibrary, functionName)); } +extern HWND hAddNodeDlg; + +int OptInit(WPARAM wParam, LPARAM lParam); +int PreShutdown(WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK ToxNodesOptionsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); + #endif //_COMMON_H_ \ No newline at end of file diff --git a/protocols/Tox/src/main.cpp b/protocols/Tox/src/main.cpp index 00510624a7..d8022cf6ac 100644 --- a/protocols/Tox/src/main.cpp +++ b/protocols/Tox/src/main.cpp @@ -37,6 +37,10 @@ extern "C" int __declspec(dllexport) Load(void) { mir_getLP(&pluginInfo); + HookEvent(ME_OPT_INITIALISE, OptInit); + HookEvent(ME_SYSTEM_PRESHUTDOWN, PreShutdown); + + PROTOCOLDESCRIPTOR pd = { sizeof(pd) }; pd.szName = "TOX"; pd.type = PROTOTYPE_PROTOCOL; diff --git a/protocols/Tox/src/resource.h b/protocols/Tox/src/resource.h index 123b897341..9bbf7d0004 100644 --- a/protocols/Tox/src/resource.h +++ b/protocols/Tox/src/resource.h @@ -1,39 +1,45 @@ //{{NO_DEPENDENCIES}} // Microsoft Visual C++ generated include file. -// Used by E:\Projects\C++\MirandaNG\protocols\Tox\res\resource.rc +// Used by d:\Miranda_orig\protocols\Tox\res\resource.rc // -#define IDD_INFO_JABBER 103 -#define IDD_ACCOUNT_INFO 103 -#define IDD_USER_INFO 103 -#define IDD_PASSWORD 111 -#define IDI_TOX 1000 -#define IDD_PROFILE_MANAGER 1001 -#define IDD_PROFILE_IMPORT 1001 -#define IDC_TOXID 1002 -#define IDD_ACCOUNT_MANAGER 1003 -#define IDC_CLIPBOARD 1004 -#define IDD_OPTIONS_MAIN 1005 -#define IDC_PROFILE_PATH 1007 -#define IDC_SEARCH 1008 -#define IDC_PASSWORD 1008 -#define IDC_BROWSE_PROFILE 1010 -#define IDC_NAME 1011 -#define IDC_GROUP 1012 -#define IDC_DISABLE_UDP 1013 -#define IDC_DISABLE_IPV6 1014 -#define IDD_SEARCH 1015 -#define IDC_DNS_ID 1016 -#define IDC_SAVEFORSESSION 1048 -#define IDC_SAVEPERMANENT 1324 -#define IDC_SAVEPERMANENTLY 1324 +#define IDD_USER_INFO 101 +#define IDD_PASSWORD 102 +#define IDD_PROFILE_IMPORT 103 +#define IDD_ACCOUNT_MANAGER 104 +#define IDD_SEARCH 105 +#define IDD_OPTIONS_MAIN 106 +#define IDD_OPTIONS_NODES 107 +#define IDD_ADDNODE 108 +#define IDI_TOX 120 +#define IDC_TOXID 1001 +#define IDC_CLIPBOARD 1002 +#define IDC_PROFILE_PATH 1003 +#define IDC_SEARCH 1004 +#define IDC_PASSWORD 1005 +#define IDC_BROWSE_PROFILE 1006 +#define IDC_NAME 1007 +#define IDC_GROUP 1008 +#define IDC_DISABLE_UDP 1009 +#define IDC_DISABLE_IPV6 1010 +#define IDC_DNS_ID 1011 +#define IDC_SAVEPERMANENT 1012 +#define IDC_SAVEPERMANENTLY 1013 +#define IDC_NODESLIST 1014 +#define IDC_ADDNODE 1015 +#define IDC_CHANGE 1016 +#define IDC_REMOVE 1017 +#define IDC_IPV4 1018 +#define IDC_IPV6 1019 +#define IDC_PORT 1020 +#define IDC_CLIENTID 1021 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_RESOURCE_VALUE 108 #define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1017 +#define _APS_NEXT_CONTROL_VALUE 1024 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/protocols/Tox/src/tox_events.cpp b/protocols/Tox/src/tox_events.cpp index 0f577dcdb7..d0b30674d2 100644 --- a/protocols/Tox/src/tox_events.cpp +++ b/protocols/Tox/src/tox_events.cpp @@ -29,4 +29,25 @@ int CToxProto::OnOptionsInit(WPARAM wParam, LPARAM) mir_free(title); return 0; -} \ No newline at end of file +} + +int OptInit(WPARAM wParam, LPARAM) +{ + OPTIONSDIALOGPAGE odp = { sizeof(odp) }; + odp.hInstance = g_hInstance; + odp.flags = ODPF_BOLDGROUPS; + odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS_NODES); + odp.pszGroup = LPGEN("Network"); + odp.pszTitle = LPGEN("Tox nodes"); + odp.pfnDlgProc = ToxNodesOptionsProc; + Options_AddPage(wParam, &odp); + return 0; +} + +int PreShutdown(WPARAM, LPARAM) +{ + if (hAddNodeDlg) + SendMessage(hAddNodeDlg, WM_CLOSE, 0, 0); + + return 0; +} diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp index f19abec6bd..687d8a20db 100644 --- a/protocols/Tox/src/tox_options.cpp +++ b/protocols/Tox/src/tox_options.cpp @@ -1,5 +1,7 @@ #include "common.h" +HWND hAddNodeDlg; + INT_PTR CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { CToxProto *proto = (CToxProto*)GetWindowLongPtr(hwnd, GWLP_USERDATA); @@ -114,4 +116,210 @@ INT_PTR CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l } return FALSE; -} \ No newline at end of file +} + +void CreateList(HWND hwndList) +{ + SendMessage(hwndList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES); + + LVCOLUMN lvc = { 0 }; + // Initialize the LVCOLUMN structure. + // The mask specifies that the format, width, text, and + // subitem members of the structure are valid. + lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; + lvc.fmt = LVCFMT_LEFT; + + lvc.iSubItem = 0; + lvc.pszText = TranslateT("IPv4"); + lvc.cx = 100; // width of column in pixels + ListView_InsertColumn(hwndList, 0, &lvc); + + lvc.iSubItem = 1; + lvc.pszText = TranslateT("IPv6"); + lvc.cx = 100; // width of column in pixels + ListView_InsertColumn(hwndList, 1, &lvc); + + lvc.iSubItem = 2; + lvc.pszText = TranslateT("Port"); + lvc.cx = 100; // width of column in pixels + ListView_InsertColumn(hwndList, 2, &lvc); + + lvc.iSubItem = 3; + lvc.pszText = TranslateT("Client ID"); + lvc.cx = 100; // width of column in pixels + ListView_InsertColumn(hwndList, 3, &lvc); +} + +INT_PTR CALLBACK AddNodeDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam); + SetWindowText(hwndDlg, TranslateT("Add node")); + Utils_RestoreWindowPositionNoSize(hwndDlg, NULL, MODULE, "AddNodeDlg"); + return TRUE; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDOK: + TCHAR str[MAX_PATH]; + char passw[MAX_PATH]; + /*{ + if (!GetDlgItemText(hwndDlg, IDC_FEEDTITLE, str, SIZEOF(str))) { + MessageBox(hwndDlg, TranslateT("Enter Feed name"), TranslateT("Error"), MB_OK); + break; + } + if (!GetDlgItemText(hwndDlg, IDC_FEEDURL, str, SIZEOF(str)) || mir_tstrcmp(str, _T("http://")) == 0) { + MessageBox(hwndDlg, TranslateT("Enter Feed URL"), TranslateT("Error"), MB_OK); + break; + } + if (!GetDlgItemText(hwndDlg, IDC_TAGSEDIT, str, SIZEOF(str))) { + MessageBox(hwndDlg, TranslateT("Enter message format"), TranslateT("Error"), MB_OK); + break; + } + + MCONTACT hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); + CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)MODULE); + GetDlgItemText(hwndDlg, IDC_FEEDTITLE, str, SIZEOF(str)); + db_set_ts(hContact, MODULE, "Nick", str); + + HWND hwndList = (HWND)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + GetDlgItemText(hwndDlg, IDC_FEEDURL, str, SIZEOF(str)); + db_set_ts(hContact, MODULE, "URL", str); + db_set_b(hContact, MODULE, "CheckState", 1); + db_set_dw(hContact, MODULE, "UpdateTime", (DWORD)GetDlgItemInt(hwndDlg, IDC_CHECKTIME, NULL, false)); + GetDlgItemText(hwndDlg, IDC_TAGSEDIT, str, SIZEOF(str)); + db_set_ts(hContact, MODULE, "MsgFormat", str); + db_set_w(hContact, MODULE, "Status", CallProtoService(MODULE, PS_GETSTATUS, 0, 0)); + if (IsDlgButtonChecked(hwndDlg, IDC_USEAUTH)) { + db_set_b(hContact, MODULE, "UseAuth", 1); + GetDlgItemText(hwndDlg, IDC_LOGIN, str, SIZEOF(str)); + db_set_ts(hContact, MODULE, "Login", str); + GetDlgItemTextA(hwndDlg, IDC_PASSWORD, passw, SIZEOF(passw)); + db_set_s(hContact, MODULE, "Password", passw); + } + DeleteAllItems(hwndList); + UpdateList(hwndList); + }*/ + // fall through + + case IDCANCEL: + DestroyWindow(hwndDlg); + break; + } + break; + + case WM_CLOSE: + DestroyWindow(hwndDlg); + break; + + case WM_DESTROY: + hAddNodeDlg = 0; + Utils_SaveWindowPosition(hwndDlg, NULL, MODULE, "AddNodeDlg"); + break; + } + + return FALSE; +} + +INT_PTR CALLBACK ToxNodesOptionsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + HWND hwndList = GetDlgItem(hwndDlg, IDC_NODESLIST); + int sel; + + switch (msg) { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); + CreateList(hwndList); + //UpdateList(hwndList); + return TRUE; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDC_ADDNODE: + if (hAddNodeDlg == 0) + hAddNodeDlg = CreateDialogParam(g_hInstance, MAKEINTRESOURCE(IDD_ADDNODE), hwndDlg, AddNodeDlgProc, (LPARAM)hwndList); + return FALSE; + + case IDC_CHANGE: + sel = ListView_GetSelectionMark(hwndList); + /*{ + ItemInfo SelItem = { 0 }; + ListView_GetItemText(hwndList, sel, 0, SelItem.nick, SIZEOF(SelItem.nick)); + ListView_GetItemText(hwndList, sel, 1, SelItem.url, SIZEOF(SelItem.url)); + SelItem.hwndList = hwndList; + SelItem.SelNumber = sel; + CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_ADDFEED), hwndDlg, DlgProcChangeFeedOpts, (LPARAM)&SelItem); + }*/ + return FALSE; + + case IDC_REMOVE: + if (MessageBox(hwndDlg, TranslateT("Are you sure?"), TranslateT("Contact deleting"), MB_YESNO | MB_ICONWARNING) == IDYES) { + TCHAR nick[MAX_PATH], url[MAX_PATH]; + int sel = ListView_GetSelectionMark(hwndList); + ListView_GetItemText(hwndList, sel, 0, nick, SIZEOF(nick)); + ListView_GetItemText(hwndList, sel, 1, url, SIZEOF(url)); + + for (MCONTACT hContact = db_find_first(MODULE); hContact; hContact = db_find_next(hContact, MODULE)) { + ptrT dbNick(db_get_tsa(hContact, MODULE, "Nick")); + if (dbNick == NULL) + break; + if (mir_tstrcmp(dbNick, nick)) + continue; + + ptrT dbURL(db_get_tsa(hContact, MODULE, "URL")); + if (dbURL == NULL) + break; + if (mir_tstrcmp(dbURL, url)) + continue; + + CallService(MS_DB_CONTACT_DELETE, (WPARAM)hContact, 0); + ListView_DeleteItem(hwndList, sel); + break; + } + } + return FALSE; + } + break; + + case WM_NOTIFY: + NMHDR *hdr = (NMHDR *)lParam; + switch (hdr->code) { + case PSN_APPLY: + //db_set_b(NULL, MODULE, "StartupRetrieve", IsDlgButtonChecked(hwndDlg, IDC_STARTUPRETRIEVE)); + { + int i = 0; + for (MCONTACT hContact = db_find_first(MODULE); hContact; hContact = db_find_next(hContact, MODULE)) { + db_set_b(hContact, MODULE, "CheckState", ListView_GetCheckState(hwndList, i)); + if (!ListView_GetCheckState(hwndList, i)) + db_set_b(hContact, "CList", "Hidden", 1); + else + db_unset(hContact, "CList", "Hidden"); + i++; + } + } + break; + + case NM_DBLCLK: + sel = ListView_GetHotItem(hwndList); + /*if (sel != -1) { + ItemInfo SelItem = { 0 }; + ListView_GetItemText(hwndList, sel, 0, SelItem.nick, SIZEOF(SelItem.nick)); + ListView_GetItemText(hwndList, sel, 1, SelItem.url, SIZEOF(SelItem.url)); + SelItem.hwndList = hwndList; + SelItem.SelNumber = sel; + CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_ADDFEED), hwndDlg, DlgProcChangeFeedOpts, (LPARAM)&SelItem); + }*/ + break; + + case LVN_ITEMCHANGED: + NMLISTVIEW *nmlv = (NMLISTVIEW *)lParam; + //if (((nmlv->uNewState ^ nmlv->uOldState) & LVIS_STATEIMAGEMASK) && !UpdateListFlag) + // SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + } + } + return FALSE; +} -- cgit v1.2.3