diff options
-rw-r--r-- | protocols/Tox/res/resource.rc | 43 | ||||
-rw-r--r-- | protocols/Tox/src/common.h | 5 | ||||
-rw-r--r-- | protocols/Tox/src/main.cpp | 2 | ||||
-rw-r--r-- | protocols/Tox/src/resource.h | 3 | ||||
-rw-r--r-- | protocols/Tox/src/tox_events.cpp | 18 | ||||
-rw-r--r-- | protocols/Tox/src/tox_network.cpp | 14 | ||||
-rw-r--r-- | protocols/Tox/src/tox_options.cpp | 453 | ||||
-rw-r--r-- | protocols/Tox/src/tox_proto.h | 2 |
8 files changed, 311 insertions, 229 deletions
diff --git a/protocols/Tox/res/resource.rc b/protocols/Tox/res/resource.rc index 0a599bf4fa..910f7ec8b4 100644 --- a/protocols/Tox/res/resource.rc +++ b/protocols/Tox/res/resource.rc @@ -97,28 +97,28 @@ BEGIN LTEXT "Tox profile contains your ID and friend list.\r\nYou may import existing profile from other tox client.",IDC_STATIC,12,91,174,21
END
-IDD_OPTIONS_MAIN DIALOGEX 0, 0, 312, 255
+IDD_OPTIONS_MAIN DIALOGEX 0, 0, 310, 235
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_SYSMENU
EXSTYLE WS_EX_CONTROLPARENT
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
LTEXT "Name:",IDC_STATIC,12,33,69,11
- EDITTEXT IDC_NAME,81,31,219,12,ES_AUTOHSCROLL
+ EDITTEXT IDC_NAME,81,31,217,12,ES_AUTOHSCROLL
LTEXT "Tox ID:",IDC_STATIC,12,17,69,11
- EDITTEXT IDC_TOXID,81,15,199,12,ES_AUTOHSCROLL | ES_READONLY
- GROUPBOX "Connection settings",IDC_STATIC,7,123,298,40
+ EDITTEXT IDC_TOXID,81,15,195,12,ES_AUTOHSCROLL | ES_READONLY
+ GROUPBOX "Connection settings",IDC_STATIC,7,123,296,40
CONTROL "Disable UDP (force Tox to use TCP)",IDC_DISABLE_UDP,
- "Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,135,288,10
- CONTROL "Disable IPv6",IDC_DISABLE_IPV6,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,149,288,10
- GROUPBOX "Tox",IDC_STATIC,7,2,298,122
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,135,286,10
+ CONTROL "Disable IPv6",IDC_DISABLE_IPV6,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,149,286,10
+ GROUPBOX "Tox",IDC_STATIC,7,2,296,122
LTEXT "Default group:",IDC_STATIC,12,66,69,12
- EDITTEXT IDC_GROUP,81,63,219,12,ES_AUTOHSCROLL
- PUSHBUTTON "C",IDC_CLIPBOARD,284,15,16,13
+ EDITTEXT IDC_GROUP,81,63,217,12,ES_AUTOHSCROLL
+ PUSHBUTTON "C",IDC_CLIPBOARD,282,15,16,13
LTEXT "Password:",IDC_STATIC,12,49,69,8,NOT WS_VISIBLE
- EDITTEXT IDC_PASSWORD,81,47,219,12,ES_PASSWORD | ES_AUTOHSCROLL | NOT WS_VISIBLE
+ EDITTEXT IDC_PASSWORD,81,47,217,12,ES_PASSWORD | ES_AUTOHSCROLL | NOT WS_VISIBLE
PUSHBUTTON "Import tox profile",IDC_IMPORT_PROFILE,81,78,100,14,WS_DISABLED
- LTEXT "Tox profile contains your ID and friend list.\r\nYou may import existing profile from other tox client.",IDC_STATIC,81,95,219,25
- GROUPBOX "Multimedia",IDC_STATIC,7,164,298,87,NOT WS_VISIBLE
+ LTEXT "Tox profile contains your ID and friend list.\r\nYou may import existing profile from other tox client.",IDC_STATIC,81,95,217,25
+ GROUPBOX "Multimedia",IDC_STATIC,7,164,296,87,NOT WS_VISIBLE
LTEXT "Audio input device",IDC_STATIC,12,174,60,8,NOT WS_VISIBLE
COMBOBOX IDC_COMBO_AUDIOINPUT,12,184,138,30,CBS_DROPDOWN | CBS_SORT | NOT WS_VISIBLE | WS_VSCROLL | WS_TABSTOP
LTEXT "Audio output device",IDC_STATIC,12,200,65,8,NOT WS_VISIBLE
@@ -159,13 +159,13 @@ 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
+IDD_OPTIONS_NODES DIALOGEX 0, 0, 310, 235
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,253,187,50,14
+ CONTROL "",IDC_NODESLIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,8,7,295,201
+ PUSHBUTTON "Add",IDC_ADDNODE,253,213,50,14
END
IDD_NODE_EDITOR DIALOGEX 0, 0, 298, 85
@@ -210,14 +210,13 @@ BEGIN IDD_OPTIONS_MAIN, DIALOG
BEGIN
LEFTMARGIN, 7
- RIGHTMARGIN, 305
+ RIGHTMARGIN, 303
VERTGUIDE, 12
VERTGUIDE, 81
- VERTGUIDE, 280
- VERTGUIDE, 284
- VERTGUIDE, 300
+ VERTGUIDE, 276
+ VERTGUIDE, 282
+ VERTGUIDE, 298
TOPMARGIN, 7
- BOTTOMMARGIN, 254
END
IDD_SEARCH, DIALOG
@@ -239,6 +238,10 @@ BEGIN IDD_OPTIONS_NODES, DIALOG
BEGIN
+ LEFTMARGIN, 8
+ RIGHTMARGIN, 303
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 227
END
IDD_NODE_EDITOR, DIALOG
diff --git a/protocols/Tox/src/common.h b/protocols/Tox/src/common.h index fcdb4b3aea..5e2953ca62 100644 --- a/protocols/Tox/src/common.h +++ b/protocols/Tox/src/common.h @@ -48,7 +48,7 @@ extern HINSTANCE g_hInstance; #define TOX_ERROR -1
#define TOX_MAX_CONNECT_RETRIES 200
-#define TOX_MAX_DISCONNECT_RETRIES 100
+#define TOX_MAX_DISCONNECT_RETRIES 200
#define TOX_INI_PATH "%miranda_path%\\Plugins\\tox.ini"
@@ -80,7 +80,4 @@ T CreateFunction(LPCSTR functionName) return reinterpret_cast<T>(GetProcAddress(g_hToxLibrary, functionName));
}
-int OptInit(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 2fd10c2110..fd0f48aab0 100644 --- a/protocols/Tox/src/main.cpp +++ b/protocols/Tox/src/main.cpp @@ -37,8 +37,6 @@ extern "C" int __declspec(dllexport) Load(void) {
mir_getLP(&pluginInfo);
- HookEvent(ME_OPT_INITIALISE, OptInit);
-
PROTOCOLDESCRIPTOR pd = { sizeof(pd) };
pd.szName = MODULE;
pd.type = PROTOTYPE_PROTOCOL;
diff --git a/protocols/Tox/src/resource.h b/protocols/Tox/src/resource.h index 1b8a19fab3..e554f90be7 100644 --- a/protocols/Tox/src/resource.h +++ b/protocols/Tox/src/resource.h @@ -1,6 +1,6 @@ //{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
-// Used by d:\Miranda_orig\protocols\Tox\res\resource.rc
+// Used by e:\Projects\C++\MirandaNG\protocols\Tox\res\resource.rc
//
#define IDD_USER_INFO 101
#define IDD_PASSWORD 102
@@ -34,7 +34,6 @@ #define IDC_AUDIOFILTER 1023
#define IDC_COMBO_VIDEOINPUT 1024
-
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
diff --git a/protocols/Tox/src/tox_events.cpp b/protocols/Tox/src/tox_events.cpp index 72626f5283..3820c500dd 100644 --- a/protocols/Tox/src/tox_events.cpp +++ b/protocols/Tox/src/tox_events.cpp @@ -26,20 +26,12 @@ int CToxProto::OnOptionsInit(WPARAM wParam, LPARAM) odp.pfnDlgProc = MainOptionsProc;
Options_AddPage(wParam, &odp);
- mir_free(title);
-
- return 0;
-}
-
-int OptInit(WPARAM wParam, LPARAM)
-{
- OPTIONSDIALOGPAGE odp = { sizeof(odp) };
- odp.hInstance = g_hInstance;
- odp.flags = ODPF_BOLDGROUPS;
+ odp.pszTab = LPGEN("Nodes");
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS_NODES);
- odp.pszGroup = LPGEN("Network");
- odp.pszTitle = LPGEN("Tox nodes");
- odp.pfnDlgProc = ToxNodesOptionsProc;
+ odp.pfnDlgProc = NodesOptionsProc;
Options_AddPage(wParam, &odp);
+
+ mir_free(title);
+
return 0;
}
diff --git a/protocols/Tox/src/tox_network.cpp b/protocols/Tox/src/tox_network.cpp index dcc7f39153..8fa5d85aa5 100644 --- a/protocols/Tox/src/tox_network.cpp +++ b/protocols/Tox/src/tox_network.cpp @@ -8,23 +8,25 @@ bool CToxProto::IsOnline() int CToxProto::BootstrapNodesFromDb(bool isIPv6)
{
int nodesLoaded = 0;
- int nodeCount = db_get_w(NULL, MODULE, TOX_SETTINGS_NODE_COUNT, 0);
+ char module[MAX_PATH];
+ mir_snprintf(module, SIZEOF(module), "%s_NODES", m_szModuleName);
+ int nodeCount = db_get_w(NULL, module, TOX_SETTINGS_NODE_COUNT, 0);
if (nodeCount > 0)
{
char setting[MAX_PATH];
for (int i = 0; i < nodeCount; i++)
{
mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV4, i);
- ptrA address(db_get_sa(NULL, MODULE, setting));
+ ptrA address(db_get_sa(NULL, module, setting));
mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PORT, i);
- int port = db_get_w(NULL, MODULE, setting, 33445);
+ int port = db_get_w(NULL, module, setting, 33445);
mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PKEY, i);
- ptrA pubKey(db_get_sa(NULL, MODULE, setting));
+ ptrA pubKey(db_get_sa(NULL, module, setting));
nodesLoaded += tox_bootstrap_from_address(tox, address, port, ToxBinAddress(pubKey));
if (isIPv6)
{
mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV6, i);
- address = db_get_sa(NULL, MODULE, setting);
+ address = db_get_sa(NULL, module, setting);
nodesLoaded += tox_bootstrap_from_address(tox, address, port, ToxBinAddress(pubKey));
}
}
@@ -125,7 +127,7 @@ void CToxProto::CheckConnection(int &retriesCount) }
else
{
- if (retriesCount == TOX_MAX_DISCONNECT_RETRIES - 10)
+ if (retriesCount == TOX_MAX_DISCONNECT_RETRIES - 20)
{
debugLogA("CToxProto::CheckConnection: lost connection with DHT");
retriesCount--;
diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp index a8182f1727..fc3e07d697 100644 --- a/protocols/Tox/src/tox_options.cpp +++ b/protocols/Tox/src/tox_options.cpp @@ -202,7 +202,29 @@ struct ItemInfo HWND hwndList;
};
-static WNDPROC oldWndProc = NULL;
+int AddItemToListView(HWND hwndList, UINT mask, int iGroupId, int iItem, int iSubItem, char *pszText, int iImage = -1)
+{
+ LVITEMA lvi = { 0 };
+ lvi.mask = mask;
+ lvi.iItem = iItem;
+ lvi.iSubItem = iSubItem;
+ lvi.iGroupId = iGroupId;
+ lvi.iImage = iImage;
+ lvi.pszText = mir_strdup(pszText);
+ return SendMessage(hwndList, LVM_INSERTITEMA, 0, (LPARAM)&lvi);
+}
+
+int SetSubItemToListView(HWND hwndList, UINT mask, int iGroupId, int iItem, int iSubItem, char *pszText, int iImage = -1)
+{
+ LVITEMA lvi = { 0 };
+ lvi.mask = mask;
+ lvi.iItem = iItem;
+ lvi.iSubItem = iSubItem;
+ lvi.iGroupId = iGroupId;
+ lvi.iImage = iImage;
+ lvi.pszText = mir_strdup(pszText);
+ return SendMessage(hwndList, LVM_SETITEMA, 0, (LPARAM)&lvi);
+}
INT_PTR CALLBACK EditNodeDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
@@ -270,48 +292,27 @@ INT_PTR CALLBACK EditNodeDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l break;
}
- LVITEMA lvi = { 0 };
- lvi.mask = 0;
- lvi.iImage = -1;
- lvi.iItem = itemInfo->iItem;
- if (lvi.iItem == -1)
+ GetDlgItemTextA(hwndDlg, IDC_IPV4, value, SIZEOF(value));
+ int iItem = itemInfo->iItem;
+ if (iItem == -1)
{
- lvi.iItem = ListView_GetItemCount(itemInfo->hwndList);
- SendMessage(itemInfo->hwndList, LVM_INSERTITEMA, 0, (LPARAM)&lvi);
- ListView_SetItemState(itemInfo->hwndList, lvi.iItem, LVIS_FOCUSED | LVIS_SELECTED, 0x000F);
- ListView_EnsureVisible(itemInfo->hwndList, lvi.iItem, TRUE);
+ iItem = ListView_GetItemCount(itemInfo->hwndList);
+ AddItemToListView(itemInfo->hwndList, LVIF_GROUPID | LVIF_TEXT | LVIF_IMAGE, 1, iItem, 0, value);
+ ListView_SetItemState(itemInfo->hwndList, iItem, LVIS_FOCUSED | LVIS_SELECTED, 0x000F);
+ ListView_EnsureVisible(itemInfo->hwndList, iItem, TRUE);
+ }
+ else
+ {
+ SetSubItemToListView(itemInfo->hwndList, LVIF_TEXT, 1, iItem, 0, value);
}
- lvi.cchTextMax = MAX_PATH;
- lvi.mask = LVIF_TEXT | LVIF_IMAGE;
-
- GetDlgItemTextA(hwndDlg, IDC_IPV4, value, SIZEOF(value));
- lvi.iSubItem = 0;
- lvi.pszText = mir_strdup(value);
- SendMessage(itemInfo->hwndList, LVM_SETITEMA, 0, (LPARAM)&lvi);
-
GetDlgItemTextA(hwndDlg, IDC_IPV6, value, SIZEOF(value));
- lvi.iSubItem = 1;
- lvi.pszText = mir_strdup(value);
- SendMessage(itemInfo->hwndList, LVM_SETITEMA, 0, (LPARAM)&lvi);
-
+ SetSubItemToListView(itemInfo->hwndList, LVIF_TEXT, 1, iItem, 1, value);
GetDlgItemTextA(hwndDlg, IDC_PORT, value, SIZEOF(value));
- lvi.iSubItem = 2;
- lvi.pszText = mir_strdup(value);
- SendMessage(itemInfo->hwndList, LVM_SETITEMA, 0, (LPARAM)&lvi);
-
+ SetSubItemToListView(itemInfo->hwndList, LVIF_TEXT, 1, iItem, 2, value);
GetDlgItemTextA(hwndDlg, IDC_PKEY, value, SIZEOF(value));
- lvi.iSubItem = 3;
- lvi.pszText = mir_strdup(value);
- SendMessage(itemInfo->hwndList, LVM_SETITEMA, 0, (LPARAM)&lvi);
-
- lvi.mask = LVIF_IMAGE;
- lvi.iSubItem = 4;
- lvi.iImage = 0;
- ListView_SetItem(itemInfo->hwndList, &lvi);
-
- lvi.iSubItem = 5;
- lvi.iImage = 1;
- ListView_SetItem(itemInfo->hwndList, &lvi);
+ SetSubItemToListView(itemInfo->hwndList, LVIF_TEXT, 1, iItem, 3, value);
+ SetSubItemToListView(itemInfo->hwndList, LVIF_IMAGE, 1, iItem, 4, value, 0);
+ SetSubItemToListView(itemInfo->hwndList, LVIF_IMAGE, 1, iItem, 5, value, 1);
EndDialog(hwndDlg, IDOK);
}
@@ -331,147 +332,230 @@ INT_PTR CALLBACK EditNodeDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l return FALSE;
}
-LRESULT CALLBACK RowItemsSubProc(HWND hwndList, UINT msg, WPARAM wParam, LPARAM lParam)
+INT_PTR CALLBACK NodeListSubProc(HWND hwndList, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
- if (msg == WM_LBUTTONDOWN)
+ LVITEMA lvi = { 0 };
+
+ switch (uMsg)
{
- LVHITTESTINFO hi;
- hi.pt.x = LOWORD(lParam);
- hi.pt.y = HIWORD(lParam);
- ListView_SubItemHitTest(hwndList, &hi);
- if (hi.iSubItem == 4)
+ case WM_INITDIALOG:
+ {
+ TCHAR *userName = (TCHAR*)lParam;
+
+ HIMAGELIST hImageList = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 2, 0);
+ HICON icon = LoadSkinnedIcon(SKINICON_OTHER_TYPING);
+ ImageList_AddIcon(hImageList, icon); Skin_ReleaseIcon(icon);
+ icon = LoadSkinnedIcon(SKINICON_OTHER_DELETE);
+ ImageList_AddIcon(hImageList, icon); Skin_ReleaseIcon(icon);
+ ListView_SetImageList(hwndList, hImageList, LVSIL_SMALL);
+
+ LVCOLUMN lvc = { 0 };
+ lvc.mask = LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
+
+ lvc.iOrder = 0;
+ lvc.pszText = L"IPv4";
+ lvc.cx = 100;
+ ListView_InsertColumn(hwndList, lvc.iOrder, (LPARAM)&lvc);
+
+ lvc.iOrder = 1;
+ lvc.pszText = L"IPv6";
+ lvc.cx = 100;
+ ListView_InsertColumn(hwndList, lvc.iOrder, (LPARAM)&lvc);
+
+ lvc.iOrder = 2;
+ lvc.pszText = TranslateT("Port");
+ lvc.cx = 50;
+ ListView_InsertColumn(hwndList, lvc.iOrder, (LPARAM)&lvc);
+
+ lvc.iOrder = 3;
+ lvc.pszText = TranslateT("Public key");
+ lvc.cx = 130;
+ ListView_InsertColumn(hwndList, lvc.iOrder, (LPARAM)&lvc);
+
+ lvc.iOrder = 4;
+ lvc.pszText = NULL;
+ lvc.cx = 32 - GetSystemMetrics(SM_CXVSCROLL);
+ ListView_InsertColumn(hwndList, lvc.iOrder, (LPARAM)&lvc);
+
+ lvc.iOrder = 5;
+ lvc.cx = 32 - GetSystemMetrics(SM_CXVSCROLL);
+ ListView_InsertColumn(hwndList, lvc.iOrder, (LPARAM)&lvc);
+
+ LVGROUP lvg = { sizeof(LVGROUP) };
+ lvg.mask = LVGF_HEADER | LVGF_GROUPID;
+
+ lvg.pszHeader = TranslateT("Common nodes");
+ lvg.iGroupId = 0;
+ ListView_InsertGroup(hwndList, lvg.iGroupId, &lvg);
+
+ TCHAR userGroupName[MAX_PATH];
+ mir_sntprintf(userGroupName, SIZEOF(userGroupName), _T("%s %s"), userName, TranslateT("nodes"));
+ lvg.pszHeader = mir_tstrdup(userGroupName);
+ lvg.iGroupId = 1;
+ ListView_InsertGroup(hwndList, lvg.iGroupId, &lvg);
+
+ ListView_EnableGroupView(hwndList, TRUE);
+
+ ListView_SetExtendedListViewStyle(hwndList, LVS_EX_SUBITEMIMAGES | LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP);
+ ListView_DeleteAllItems(hwndList);
+ }
+ break;
+
+ case WM_NOTIFY:
+ switch (((NMHDR*)lParam)->code)
{
- ItemInfo itemInfo = { hi.iItem, hwndList };
- if (DialogBoxParam(
- g_hInstance,
- MAKEINTRESOURCE(IDD_ADDNODE),
- GetParent(hwndList), EditNodeDlgProc,
- (LPARAM)&itemInfo) == IDOK)
+ case NM_CLICK:
+ {
+ lvi.iItem = ((NMITEMACTIVATE*)lParam)->iItem;
+ lvi.mask = LVIF_GROUPID;
+ SendMessage(hwndList, LVM_GETITEMA, 0, (LPARAM)&lvi);
+ lvi.iSubItem = ((NMITEMACTIVATE*)lParam)->iSubItem;
+ if (lvi.iGroupId && lvi.iSubItem == 4)
{
- SendMessage(GetParent(GetParent(hwndList)), PSM_CHANGED, 0, 0);
+ ItemInfo itemInfo = { lvi.iItem, hwndList };
+ if (DialogBoxParam(
+ g_hInstance,
+ MAKEINTRESOURCE(IDD_ADDNODE),
+ GetParent(hwndList), EditNodeDlgProc,
+ (LPARAM)&itemInfo) == IDOK)
+ {
+ SendMessage(GetParent(GetParent(hwndList)), PSM_CHANGED, 0, 0);
+ }
+ }
+ else if (lvi.iGroupId && lvi.iSubItem == 5)
+ {
+ if (MessageBox(hwndList, TranslateT("Are you sure?"), TranslateT("Node deleting"), MB_YESNO | MB_ICONWARNING) == IDYES)
+ {
+ ListView_DeleteItem(hwndList, lvi.iItem);
+ SendMessage(GetParent(GetParent(hwndList)), PSM_CHANGED, 0, 0);
+ }
}
}
- else if (hi.iSubItem == 5)
+ break;
+
+ case NM_DBLCLK:
{
- if (MessageBox(hwndList, TranslateT("Are you sure?"), TranslateT("Node deleting"), MB_YESNO | MB_ICONWARNING) == IDYES)
+ lvi.iItem = ((NMITEMACTIVATE*)lParam)->iItem;
+ lvi.mask = LVIF_GROUPID;
+ SendMessage(hwndList, LVM_GETITEMA, 0, (LPARAM)&lvi);
+ if (lvi.iGroupId || (lvi.iGroupId == 0 && lvi.iItem == -1))
{
- ListView_DeleteItem(hwndList, hi.iItem);
- SendMessage(GetParent(GetParent(hwndList)), PSM_CHANGED, 0, 0);
+ ItemInfo itemInfo = { lvi.iItem, hwndList };
+ if (DialogBoxParam(
+ g_hInstance,
+ MAKEINTRESOURCE(IDD_ADDNODE),
+ GetParent(hwndList), EditNodeDlgProc,
+ (LPARAM)&itemInfo) == IDOK)
+ {
+ SendMessage(GetParent(GetParent(hwndList)), PSM_CHANGED, 0, 0);
+ }
}
}
- }
-
- if (msg == WM_KEYDOWN && wParam == VK_DELETE)
- {
- int sel = ListView_GetSelectionMark(hwndList);
- if (MessageBox(hwndList, TranslateT("Are you sure?"), TranslateT("Node deleting"), MB_YESNO | MB_ICONWARNING) == IDYES)
+ break;
+
+ case LVN_KEYDOWN:
{
- ListView_DeleteItem(hwndList, sel);
- SendMessage(GetParent(GetParent(hwndList)), PSM_CHANGED, 0, 0);
+ lvi.iItem = ListView_GetSelectionMark(hwndList);
+ lvi.mask = LVIF_GROUPID;
+ SendMessage(hwndList, LVM_GETITEMA, 0, (LPARAM)&lvi);
+ if (lvi.iGroupId && lvi.iItem != -1 && ((LPNMLVKEYDOWN)lParam)->wVKey == VK_DELETE)
+ {
+ if (MessageBox(
+ GetParent(hwndList),
+ TranslateT("Are you sure?"),
+ TranslateT("Node deleting"),
+ MB_YESNO | MB_ICONWARNING) == IDYES)
+ {
+ ListView_DeleteItem(hwndList, lvi.iItem);
+ SendMessage(GetParent(GetParent(hwndList)), PSM_CHANGED, 0, 0);
+ }
+ }
}
+ break;
+ }
+ break;
+
+ default:
+ return CallWindowProc((WNDPROC)GetClassLong(hwndList, GCL_WNDPROC), hwndList, uMsg, wParam, lParam);
}
-
- return CallWindowProc(oldWndProc, hwndList, msg, wParam, lParam);
+ return FALSE;
}
-INT_PTR CALLBACK ToxNodesOptionsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+INT_PTR CALLBACK CToxProto::NodesOptionsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
+ CToxProto *proto = (CToxProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
HWND hwndList = GetDlgItem(hwndDlg, IDC_NODESLIST);
- switch (msg)
+ switch (uMsg)
{
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
{
- oldWndProc = (WNDPROC)SetWindowLongPtr(hwndList, GWLP_WNDPROC, (LONG_PTR)RowItemsSubProc);
-
- HIMAGELIST hImageList = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 2, 0);
- HICON icon = LoadSkinnedIcon(SKINICON_OTHER_TYPING);
- ImageList_AddIcon(hImageList, icon); Skin_ReleaseIcon(icon);
- icon = LoadSkinnedIcon(SKINICON_OTHER_DELETE);
- ImageList_AddIcon(hImageList, icon); Skin_ReleaseIcon(icon);
- ListView_SetImageList(hwndList, hImageList, LVSIL_SMALL);
-
- ListView_SetExtendedListViewStyle(hwndList, LVS_EX_SUBITEMIMAGES | LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP);
-
- LVCOLUMNA lvc = { 0 };
- lvc.mask = LVCF_WIDTH | LVCF_TEXT;
- lvc.fmt = LVCFMT_LEFT;
-
- lvc.iSubItem = 0;
- lvc.pszText = "IPv4";
- lvc.cx = 100;
- SendMessage(hwndList, LVM_INSERTCOLUMNA, 0, (LPARAM)&lvc);
-
- lvc.iSubItem = 1;
- lvc.pszText = "IPv6";
- lvc.cx = 100;
- SendMessage(hwndList, LVM_INSERTCOLUMNA, 1, (LPARAM)&lvc);
-
- lvc.iSubItem = 2;
- lvc.pszText = Translate("Port");
- lvc.cx = 50;
- SendMessage(hwndList, LVM_INSERTCOLUMNA, 2, (LPARAM)&lvc);
-
- lvc.iSubItem = 3;
- lvc.pszText = Translate("Public key");
- lvc.cx = 130;
- SendMessage(hwndList, LVM_INSERTCOLUMNA, 3, (LPARAM)&lvc);
-
- lvc.iSubItem = 4;
- lvc.pszText = NULL;
- lvc.cx = 32 - GetSystemMetrics(SM_CXVSCROLL);
- ListView_InsertColumn(hwndList, 4, &lvc);
-
- lvc.iSubItem = 5;
- lvc.cx = 32 - GetSystemMetrics(SM_CXVSCROLL);
- ListView_InsertColumn(hwndList, 5, &lvc);
+ proto = (CToxProto*)lParam;
+ SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
- char setting[MAX_PATH];
+ CallWindowProc((WNDPROC)NodeListSubProc, hwndList, WM_INITDIALOG, wParam, (LPARAM)proto->m_tszUserName);
- LVITEMA lvi = { 0 };
- lvi.cchTextMax = MAX_PATH;
+ int iItem = 0;
- int nodeCount = db_get_w(NULL, MODULE, TOX_SETTINGS_NODE_COUNT, 0);
- for (lvi.iItem = 0; lvi.iItem < nodeCount; lvi.iItem++)
+ if (IsFileExists((TCHAR*)VARST(_T(TOX_INI_PATH))))
{
- lvi.iImage = -1;
- lvi.mask = LVIF_TEXT | LVIF_IMAGE;
+ char fileName[MAX_PATH];
+ mir_strcpy(fileName, VARS(TOX_INI_PATH));
- mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV4, lvi.iItem);
- lvi.iSubItem = 0;
- lvi.pszText = db_get_sa(NULL, MODULE, setting);
- SendMessage(hwndList, LVM_INSERTITEMA, 0, (LPARAM)&lvi);
+ char *section, sections[MAX_PATH], value[MAX_PATH];
+ GetPrivateProfileSectionNamesA(sections, SIZEOF(sections), fileName);
+ section = sections;
+ while (*section != NULL)
+ {
+ if (strstr(section, TOX_SETTINGS_NODE_PREFIX) == section)
+ {
+ GetPrivateProfileStringA(section, "IPv4", NULL, value, SIZEOF(value), fileName);
+ AddItemToListView(hwndList, LVIF_GROUPID | LVIF_TEXT | LVIF_IMAGE, 0, iItem, 0, value);
- mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV6, lvi.iItem);
- lvi.iSubItem = 1;
- lvi.pszText = db_get_sa(NULL, MODULE, setting);
- SendMessage(hwndList, LVM_SETITEMA, 0, (LPARAM)&lvi);
+ GetPrivateProfileStringA(section, "IPv6", NULL, value, SIZEOF(value), fileName);
+ SetSubItemToListView(hwndList, LVIF_TEXT, 0, iItem, 1, value);
+
+ GetPrivateProfileStringA(section, "Port", NULL, value, SIZEOF(value), fileName);
+ SetSubItemToListView(hwndList, LVIF_TEXT, 0, iItem, 2, value);
+
+ GetPrivateProfileStringA(section, "PubKey", NULL, value, SIZEOF(value), fileName);
+ SetSubItemToListView(hwndList, LVIF_TEXT, 0, iItem, 3, value);
+
+ iItem++;
+ }
+ section += strlen(section) + 1;
+ }
+ }
- mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PORT, lvi.iItem);
- int port = db_get_w(NULL, MODULE, setting, 0);
+ char module[MAX_PATH], setting[MAX_PATH];
+ mir_snprintf(module, SIZEOF(module), "%s_Nodes", proto->m_szModuleName);
+ int nodeCount = db_get_w(NULL, module, TOX_SETTINGS_NODE_COUNT, 0);
+ for (int i = 0; i < nodeCount; i++, iItem++)
+ {
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV4, i);
+ ptrA value(db_get_sa(NULL, module, setting));
+ AddItemToListView(hwndList, LVIF_GROUPID | LVIF_TEXT | LVIF_IMAGE, 1, iItem, 0, value);
+
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV6, i);
+ value = db_get_sa(NULL, module, setting);
+ SetSubItemToListView(hwndList, LVIF_TEXT, 1, iItem, 1, value);
+
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PORT, i);
+ int port = db_get_w(NULL, module, setting, 0);
if (port > 0)
{
char portNum[10];
itoa(port, portNum, 10);
- lvi.pszText = mir_strdup(portNum);
+ SetSubItemToListView(hwndList, LVIF_TEXT, 1, iItem, 2, portNum);
}
- lvi.iSubItem = 2;
- SendMessage(hwndList, LVM_SETITEMA, 0, (LPARAM)&lvi);
- mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PKEY, lvi.iItem);
- lvi.iSubItem = 3;
- lvi.pszText = db_get_sa(NULL, MODULE, setting);
- SendMessage(hwndList, LVM_SETITEMA, 0, (LPARAM)&lvi);
-
- lvi.mask = LVIF_IMAGE;
- lvi.iSubItem = 4;
- lvi.iImage = 0;
- ListView_SetItem(hwndList, &lvi);
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PKEY, i);
+ value = db_get_sa(NULL, module, setting);
+ SetSubItemToListView(hwndList, LVIF_TEXT, 1, iItem, 3, value);
- lvi.iSubItem = 5;
- lvi.iImage = 1;
- ListView_SetItem(hwndList, &lvi);
+ SetSubItemToListView(hwndList, LVIF_IMAGE, 1, iItem, 4, value, 0);
+ SetSubItemToListView(hwndList, LVIF_IMAGE, 1, iItem, 5, value, 1);
}
}
return TRUE;
@@ -485,82 +569,87 @@ INT_PTR CALLBACK ToxNodesOptionsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR if (DialogBoxParam(
g_hInstance,
MAKEINTRESOURCE(IDD_ADDNODE),
- hwndDlg, EditNodeDlgProc,
+ GetParent(hwndList), EditNodeDlgProc,
(LPARAM)&itemInfo) == IDOK)
{
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ SendMessage(GetParent(GetParent(hwndList)), PSM_CHANGED, 0, 0);
}
- return FALSE;
}
}
break;
case WM_NOTIFY:
- NMHDR *hdr = (NMHDR*)lParam;
- switch (hdr->code)
+ switch (((LPNMHDR)lParam)->code)
{
+ case NM_CLICK:
case NM_DBLCLK:
- {
- int iItem = ListView_GetNextItem(hwndList, -1, LVNI_SELECTED);
- ItemInfo itemInfo = { iItem, hwndList };
- if (DialogBoxParam(
- g_hInstance,
- MAKEINTRESOURCE(IDD_ADDNODE),
- hwndDlg, EditNodeDlgProc,
- (LPARAM)&itemInfo) == IDOK)
+ case LVN_KEYDOWN:
+ if (((NMHDR*)lParam)->hwndFrom == hwndList)
{
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ return CallWindowProc((WNDPROC)NodeListSubProc, hwndList, uMsg, wParam, lParam);
}
- }
- break;
+ break;
case PSN_APPLY:
{
char setting[MAX_PATH];
LVITEMA lvi = { 0 };
- lvi.mask = LVIF_TEXT;
lvi.cchTextMax = MAX_PATH;
lvi.pszText = (char*)mir_alloc(MAX_PATH);
+ char module[MAX_PATH];
+ mir_snprintf(module, SIZEOF(module), "%s_Nodes", proto->m_szModuleName);
+
+ int iItem = 0;
int itemCount = ListView_GetItemCount(hwndList);
- for (lvi.iItem = 0; lvi.iItem < itemCount; lvi.iItem++)
+ for (int i = 0; i < itemCount; i++)
{
+ lvi.iItem = i;
+ lvi.mask = LVIF_GROUPID;
+ SendMessage(hwndList, LVM_GETITEMA, 0, (LPARAM)&lvi);
+ if (lvi.iGroupId == 0)
+ {
+ continue;
+ }
+
+ lvi.mask = LVIF_TEXT;
lvi.iSubItem = 0;
SendMessage(hwndList, LVM_GETITEMA, 0, (LPARAM)&lvi);
- mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV4, lvi.iItem);
- db_set_s(NULL, MODULE, setting, lvi.pszText);
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV4, iItem);
+ db_set_s(NULL, module, setting, lvi.pszText);
lvi.iSubItem = 1;
SendMessage(hwndList, LVM_GETITEMA, 0, (LPARAM)&lvi);
- mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV6, lvi.iItem);
- db_set_s(NULL, MODULE, setting, lvi.pszText);
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV6, iItem);
+ db_set_s(NULL, module, setting, lvi.pszText);
lvi.iSubItem = 2;
SendMessage(hwndList, LVM_GETITEMA, 0, (LPARAM)&lvi);
- mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PORT, lvi.iItem);
- db_set_w(NULL, MODULE, setting, atoi(lvi.pszText));
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PORT, iItem);
+ db_set_w(NULL, module, setting, atoi(lvi.pszText));
lvi.iSubItem = 3;
SendMessage(hwndList, LVM_GETITEMA, 0, (LPARAM)&lvi);
- mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PKEY, lvi.iItem);
- db_set_s(NULL, MODULE, setting, lvi.pszText);
- }
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PKEY, iItem);
+ db_set_s(NULL, module, setting, lvi.pszText);
- int nodeCount = db_get_b(NULL, MODULE, TOX_SETTINGS_NODE_COUNT, 0);
- for (lvi.iItem = itemCount; lvi.iItem < nodeCount; lvi.iItem++)
+ iItem++;
+ }
+ itemCount = iItem;
+ int nodeCount = db_get_b(NULL, module, TOX_SETTINGS_NODE_COUNT, 0);
+ for (iItem = itemCount; iItem < nodeCount; iItem++)
{
- mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV4, lvi.iItem);
- db_unset(NULL, MODULE, setting);
- mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV6, lvi.iItem);
- db_unset(NULL, MODULE, setting);
- mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PORT, lvi.iItem);
- db_unset(NULL, MODULE, setting);
- mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PKEY, lvi.iItem);
- db_unset(NULL, MODULE, setting);
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV4, iItem);
+ db_unset(NULL, module, setting);
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_IPV6, iItem);
+ db_unset(NULL, module, setting);
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PORT, iItem);
+ db_unset(NULL, module, setting);
+ mir_snprintf(setting, SIZEOF(setting), TOX_SETTINGS_NODE_PKEY, iItem);
+ db_unset(NULL, module, setting);
}
-
- db_set_b(NULL, MODULE, TOX_SETTINGS_NODE_COUNT, itemCount);
+ db_set_b(NULL, module, TOX_SETTINGS_NODE_COUNT, itemCount);
}
return TRUE;
}
diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index 047969eca2..0b53d7ba86 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -113,6 +113,8 @@ private: // options
static INT_PTR CALLBACK MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+ static INT_PTR CALLBACK NodesOptionsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
+
int __cdecl OnOptionsInit(WPARAM wParam, LPARAM lParam);
INT_PTR __cdecl OnAccountManagerInit(WPARAM, LPARAM);
|