summaryrefslogtreecommitdiff
path: root/plugins/DbEditorPP
diff options
context:
space:
mode:
authorDmitry Kuzkin <bio@ktaspb.ru>2015-06-18 12:36:07 +0000
committerDmitry Kuzkin <bio@ktaspb.ru>2015-06-18 12:36:07 +0000
commit1bb9a86b26d3a9964844d42fa25690ce0a028258 (patch)
tree6c0645ade07ec6b4d36e38a1ba77e457e8cf6ade /plugins/DbEditorPP
parenta27ae3e0c1f1f17596db3abeae16ec3fc4b4ba80 (diff)
true unicode build (ansi build is possible but useless)
new search/replace dialog edit improvements (type check) resident settings support (fully resident modules are still invisible) remove obsolete things code cleanup git-svn-id: http://svn.miranda-ng.org/main/trunk@14243 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/DbEditorPP')
-rw-r--r--plugins/DbEditorPP/dbeditorpp_10.sln29
-rw-r--r--plugins/DbEditorPP/dbeditorpp_10.suobin0 -> 17920 bytes
-rw-r--r--plugins/DbEditorPP/dbeditorpp_10.vcxproj25
-rw-r--r--plugins/DbEditorPP/dbeditorpp_10.vcxproj.filters72
-rw-r--r--plugins/DbEditorPP/dbeditorpp_10.vcxproj.user3
-rw-r--r--plugins/DbEditorPP/res/binary.ico (renamed from plugins/DbEditorPP/res/Icon_15.ico)bin1150 -> 1150 bytes
-rw-r--r--plugins/DbEditorPP/res/byte.ico (renamed from plugins/DbEditorPP/res/Icon_17.ico)bin1150 -> 1150 bytes
-rw-r--r--plugins/DbEditorPP/res/closed.ico (renamed from plugins/DbEditorPP/res/Yellow.ico)bin1150 -> 1150 bytes
-rw-r--r--plugins/DbEditorPP/res/dword.ico (renamed from plugins/DbEditorPP/res/Icon_16.ico)bin1150 -> 1150 bytes
-rw-r--r--plugins/DbEditorPP/res/empty.icobin0 -> 1150 bytes
-rw-r--r--plugins/DbEditorPP/res/offline.ico (renamed from plugins/DbEditorPP/res/offline2.ico)bin5430 -> 5430 bytes
-rw-r--r--plugins/DbEditorPP/res/online.ico (renamed from plugins/DbEditorPP/res/online2.ico)bin5430 -> 5430 bytes
-rw-r--r--plugins/DbEditorPP/res/opened.ico (renamed from plugins/DbEditorPP/res/Yellow_open.ico)bin1150 -> 1150 bytes
-rw-r--r--plugins/DbEditorPP/res/regedit.ico (renamed from plugins/DbEditorPP/res/Icon_1.ico)bin5430 -> 5430 bytes
-rw-r--r--plugins/DbEditorPP/res/resource.apsbin0 -> 69132 bytes
-rw-r--r--plugins/DbEditorPP/res/resource.rc175
-rw-r--r--plugins/DbEditorPP/res/settings.ico (renamed from plugins/DbEditorPP/res/Icon_4.ico)bin1150 -> 1150 bytes
-rw-r--r--plugins/DbEditorPP/res/string.ico (renamed from plugins/DbEditorPP/res/Icon_14.ico)bin1150 -> 1150 bytes
-rw-r--r--plugins/DbEditorPP/res/word.ico (renamed from plugins/DbEditorPP/res/Icon_18.ico)bin1150 -> 1150 bytes
-rw-r--r--plugins/DbEditorPP/src/Version.h10
-rw-r--r--plugins/DbEditorPP/src/addeditsettingsdlg.cpp439
-rw-r--r--plugins/DbEditorPP/src/copymodule.cpp146
-rw-r--r--plugins/DbEditorPP/src/deletemodule.cpp47
-rw-r--r--plugins/DbEditorPP/src/exportimport.cpp329
-rw-r--r--plugins/DbEditorPP/src/findwindow.cpp839
-rw-r--r--plugins/DbEditorPP/src/headers.h288
-rw-r--r--plugins/DbEditorPP/src/icons.cpp128
-rw-r--r--plugins/DbEditorPP/src/main.cpp536
-rw-r--r--plugins/DbEditorPP/src/main_window.cpp376
-rw-r--r--plugins/DbEditorPP/src/modsettingenum.cpp213
-rw-r--r--plugins/DbEditorPP/src/modsettingenum.h18
-rw-r--r--plugins/DbEditorPP/src/modules.cpp95
-rw-r--r--plugins/DbEditorPP/src/moduletree.cpp802
-rw-r--r--plugins/DbEditorPP/src/options.cpp4
-rw-r--r--plugins/DbEditorPP/src/renamemodule.cpp70
-rw-r--r--plugins/DbEditorPP/src/resource.h15
-rw-r--r--plugins/DbEditorPP/src/settinglist.cpp1361
-rw-r--r--plugins/DbEditorPP/src/settingsdlg.cpp333
-rw-r--r--plugins/DbEditorPP/src/threads.cpp48
-rw-r--r--plugins/DbEditorPP/src/watchedvars.cpp372
40 files changed, 3341 insertions, 3432 deletions
diff --git a/plugins/DbEditorPP/dbeditorpp_10.sln b/plugins/DbEditorPP/dbeditorpp_10.sln
new file mode 100644
index 0000000000..d5e835f441
--- /dev/null
+++ b/plugins/DbEditorPP/dbeditorpp_10.sln
@@ -0,0 +1,29 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DbEditorPP", "dbeditorpp_10.vcxproj", "{9C6040B8-1173-40FA-A3DB-DE044CCD8250}"
+EndProject
+Global
+ GlobalSection(DPCodeReviewSolutionGUID) = preSolution
+ DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000}
+ EndGlobalSection
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Debug|x64 = Debug|x64
+ Release|Win32 = Release|Win32
+ Release|x64 = Release|x64
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {9C6040B8-1173-40FA-A3DB-DE044CCD8250}.Debug|Win32.ActiveCfg = Debug|Win32
+ {9C6040B8-1173-40FA-A3DB-DE044CCD8250}.Debug|Win32.Build.0 = Debug|Win32
+ {9C6040B8-1173-40FA-A3DB-DE044CCD8250}.Debug|x64.ActiveCfg = Debug|x64
+ {9C6040B8-1173-40FA-A3DB-DE044CCD8250}.Debug|x64.Build.0 = Debug|x64
+ {9C6040B8-1173-40FA-A3DB-DE044CCD8250}.Release|Win32.ActiveCfg = Release|Win32
+ {9C6040B8-1173-40FA-A3DB-DE044CCD8250}.Release|Win32.Build.0 = Release|Win32
+ {9C6040B8-1173-40FA-A3DB-DE044CCD8250}.Release|x64.ActiveCfg = Release|x64
+ {9C6040B8-1173-40FA-A3DB-DE044CCD8250}.Release|x64.Build.0 = Release|x64
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/plugins/DbEditorPP/dbeditorpp_10.suo b/plugins/DbEditorPP/dbeditorpp_10.suo
new file mode 100644
index 0000000000..7c3cabb742
--- /dev/null
+++ b/plugins/DbEditorPP/dbeditorpp_10.suo
Binary files differ
diff --git a/plugins/DbEditorPP/dbeditorpp_10.vcxproj b/plugins/DbEditorPP/dbeditorpp_10.vcxproj
index 3218b64987..d7a9902684 100644
--- a/plugins/DbEditorPP/dbeditorpp_10.vcxproj
+++ b/plugins/DbEditorPP/dbeditorpp_10.vcxproj
@@ -25,7 +25,7 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
- <CharacterSet>MultiByte</CharacterSet>
+ <CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
@@ -35,7 +35,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
- <CharacterSet>MultiByte</CharacterSet>
+ <CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
@@ -186,9 +186,9 @@
<ClCompile Include="src\stdafx.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
- <ClCompile Include="src\modules.cpp" />
+ <ClCompile Include="src\renamemodule.cpp" />
<ClCompile Include="src\modsettingenum.cpp" />
- <ClCompile Include="src\addeditsettingsdlg.cpp" />
+ <ClCompile Include="src\settingsdlg.cpp" />
<ClCompile Include="src\copymodule.cpp" />
<ClCompile Include="src\deletemodule.cpp" />
<ClCompile Include="src\findwindow.cpp" />
@@ -200,7 +200,6 @@
<ClCompile Include="src\watchedvars.cpp" />
</ItemGroup>
<ItemGroup>
- <ClInclude Include="src\modsettingenum.h" />
<ClInclude Include="src\headers.h" />
<ClInclude Include="src\resource.h" />
<ClInclude Include="src\Version.h" />
@@ -208,6 +207,22 @@
<ItemGroup>
<None Include="docs\dbeditorpp_readme.txt" />
<None Include="docs\dbeditorpp_translation.txt" />
+ <None Include="res\binary.ico" />
+ <None Include="res\byte.ico" />
+ <None Include="res\contacts.ico" />
+ <None Include="res\dbepp.ico" />
+ <None Include="res\dword.ico" />
+ <None Include="res\handle.ico" />
+ <None Include="res\known.ico" />
+ <None Include="res\known_open.ico" />
+ <None Include="res\offline.ico" />
+ <None Include="res\online.ico" />
+ <None Include="res\regedit.ico" />
+ <None Include="res\settings.ico" />
+ <None Include="res\string.ico" />
+ <None Include="res\unicode.ico" />
+ <None Include="res\usermenu.ico" />
+ <None Include="res\word.ico" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="res\resource.rc" />
diff --git a/plugins/DbEditorPP/dbeditorpp_10.vcxproj.filters b/plugins/DbEditorPP/dbeditorpp_10.vcxproj.filters
index 8b6ce891ed..7adc2fb193 100644
--- a/plugins/DbEditorPP/dbeditorpp_10.vcxproj.filters
+++ b/plugins/DbEditorPP/dbeditorpp_10.vcxproj.filters
@@ -5,9 +5,6 @@
<UniqueIdentifier>{bc4414ca-bfab-4385-a016-6239272b67ab}</UniqueIdentifier>
<Extensions>cpp;c;cxx;rc;def;r;odl;idl;hpj;bat</Extensions>
</Filter>
- <Filter Include="Source Files\ModSetting Enuming">
- <UniqueIdentifier>{8ba4deb9-307a-4c99-9c87-2243a0ef802e}</UniqueIdentifier>
- </Filter>
<Filter Include="Source Files\dialogs">
<UniqueIdentifier>{b1b3b1b6-9fe0-435d-b8ab-1715cc5e7430}</UniqueIdentifier>
</Filter>
@@ -30,15 +27,6 @@
<ClCompile Include="src\main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="src\modules.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="src\modsettingenum.cpp">
- <Filter>Source Files\ModSetting Enuming</Filter>
- </ClCompile>
- <ClCompile Include="src\addeditsettingsdlg.cpp">
- <Filter>Source Files\dialogs</Filter>
- </ClCompile>
<ClCompile Include="src\copymodule.cpp">
<Filter>Source Files\dialogs</Filter>
</ClCompile>
@@ -66,11 +54,17 @@
<ClCompile Include="src\stdafx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\settingsdlg.cpp">
+ <Filter>Source Files\dialogs</Filter>
+ </ClCompile>
+ <ClCompile Include="src\modsettingenum.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="src\renamemodule.cpp">
+ <Filter>Source Files\dialogs</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
- <ClInclude Include="src\modsettingenum.h">
- <Filter>Source Files\ModSetting Enuming</Filter>
- </ClInclude>
<ClInclude Include="src\headers.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -84,6 +78,54 @@
<ItemGroup>
<None Include="docs\dbeditorpp_readme.txt" />
<None Include="docs\dbeditorpp_translation.txt" />
+ <None Include="res\regedit.ico">
+ <Filter>Resource Files</Filter>
+ </None>
+ <None Include="res\known.ico">
+ <Filter>Resource Files</Filter>
+ </None>
+ <None Include="res\known_open.ico">
+ <Filter>Resource Files</Filter>
+ </None>
+ <None Include="res\settings.ico">
+ <Filter>Resource Files</Filter>
+ </None>
+ <None Include="res\online.ico">
+ <Filter>Resource Files</Filter>
+ </None>
+ <None Include="res\dbepp.ico">
+ <Filter>Resource Files</Filter>
+ </None>
+ <None Include="res\usermenu.ico">
+ <Filter>Resource Files</Filter>
+ </None>
+ <None Include="res\string.ico">
+ <Filter>Resource Files</Filter>
+ </None>
+ <None Include="res\contacts.ico">
+ <Filter>Resource Files</Filter>
+ </None>
+ <None Include="res\binary.ico">
+ <Filter>Resource Files</Filter>
+ </None>
+ <None Include="res\dword.ico">
+ <Filter>Resource Files</Filter>
+ </None>
+ <None Include="res\byte.ico">
+ <Filter>Resource Files</Filter>
+ </None>
+ <None Include="res\word.ico">
+ <Filter>Resource Files</Filter>
+ </None>
+ <None Include="res\offline.ico">
+ <Filter>Resource Files</Filter>
+ </None>
+ <None Include="res\unicode.ico">
+ <Filter>Resource Files</Filter>
+ </None>
+ <None Include="res\handle.ico">
+ <Filter>Resource Files</Filter>
+ </None>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="res\resource.rc">
diff --git a/plugins/DbEditorPP/dbeditorpp_10.vcxproj.user b/plugins/DbEditorPP/dbeditorpp_10.vcxproj.user
new file mode 100644
index 0000000000..695b5c78b9
--- /dev/null
+++ b/plugins/DbEditorPP/dbeditorpp_10.vcxproj.user
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+</Project> \ No newline at end of file
diff --git a/plugins/DbEditorPP/res/Icon_15.ico b/plugins/DbEditorPP/res/binary.ico
index 13b738a42d..13b738a42d 100644
--- a/plugins/DbEditorPP/res/Icon_15.ico
+++ b/plugins/DbEditorPP/res/binary.ico
Binary files differ
diff --git a/plugins/DbEditorPP/res/Icon_17.ico b/plugins/DbEditorPP/res/byte.ico
index 8b29982627..8b29982627 100644
--- a/plugins/DbEditorPP/res/Icon_17.ico
+++ b/plugins/DbEditorPP/res/byte.ico
Binary files differ
diff --git a/plugins/DbEditorPP/res/Yellow.ico b/plugins/DbEditorPP/res/closed.ico
index 862df74513..862df74513 100644
--- a/plugins/DbEditorPP/res/Yellow.ico
+++ b/plugins/DbEditorPP/res/closed.ico
Binary files differ
diff --git a/plugins/DbEditorPP/res/Icon_16.ico b/plugins/DbEditorPP/res/dword.ico
index e862b66552..e862b66552 100644
--- a/plugins/DbEditorPP/res/Icon_16.ico
+++ b/plugins/DbEditorPP/res/dword.ico
Binary files differ
diff --git a/plugins/DbEditorPP/res/empty.ico b/plugins/DbEditorPP/res/empty.ico
new file mode 100644
index 0000000000..70ec4b659b
--- /dev/null
+++ b/plugins/DbEditorPP/res/empty.ico
Binary files differ
diff --git a/plugins/DbEditorPP/res/offline2.ico b/plugins/DbEditorPP/res/offline.ico
index 2216ad7b63..2216ad7b63 100644
--- a/plugins/DbEditorPP/res/offline2.ico
+++ b/plugins/DbEditorPP/res/offline.ico
Binary files differ
diff --git a/plugins/DbEditorPP/res/online2.ico b/plugins/DbEditorPP/res/online.ico
index ddc67a5d5e..ddc67a5d5e 100644
--- a/plugins/DbEditorPP/res/online2.ico
+++ b/plugins/DbEditorPP/res/online.ico
Binary files differ
diff --git a/plugins/DbEditorPP/res/Yellow_open.ico b/plugins/DbEditorPP/res/opened.ico
index aa5a0e5b33..aa5a0e5b33 100644
--- a/plugins/DbEditorPP/res/Yellow_open.ico
+++ b/plugins/DbEditorPP/res/opened.ico
Binary files differ
diff --git a/plugins/DbEditorPP/res/Icon_1.ico b/plugins/DbEditorPP/res/regedit.ico
index fcd52eda5a..fcd52eda5a 100644
--- a/plugins/DbEditorPP/res/Icon_1.ico
+++ b/plugins/DbEditorPP/res/regedit.ico
Binary files differ
diff --git a/plugins/DbEditorPP/res/resource.aps b/plugins/DbEditorPP/res/resource.aps
new file mode 100644
index 0000000000..51087305fd
--- /dev/null
+++ b/plugins/DbEditorPP/res/resource.aps
Binary files differ
diff --git a/plugins/DbEditorPP/res/resource.rc b/plugins/DbEditorPP/res/resource.rc
index 53daced5b7..e193f8e7c6 100644
--- a/plugins/DbEditorPP/res/resource.rc
+++ b/plugins/DbEditorPP/res/resource.rc
@@ -24,34 +24,26 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
// Dialog
//
-IDD_FIND DIALOGEX 0, 0, 340, 249
-STYLE DS_SETFONT | DS_SETFOREGROUND | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
-CAPTION "Database Editor++ search and replace"
+IDD_FIND DIALOGEX 0, 0, 395, 250
+STYLE DS_SETFONT | DS_SETFOREGROUND | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
+CAPTION "Search and replace"
FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN
- GROUPBOX "Search for",IDC_STATIC,3,1,268,58
- LTEXT "Text:",IDC_STATIC,10,74,26,8
- EDITTEXT IDC_TEXT,40,13,216,12,ES_AUTOHSCROLL
- LTEXT "In:",IDC_STATIC,10,30,23,8
- LTEXT "In:",IDC_STATIC,10,90,23,8,NOT WS_VISIBLE
- CONTROL "Case sensitive",IDC_CASESENSITIVE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,40,30,72,10
- CONTROL "Module name",IDC_MODNAME,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,40,44,73,10
- CONTROL "Module name",IDC_MODNAME2,"Button",BS_AUTORADIOBUTTON | NOT WS_VISIBLE | WS_DISABLED | WS_GROUP | WS_TABSTOP,40,90,73,10
- CONTROL "Exact match",IDC_EXACT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,115,30,64,10
- CONTROL "Setting name",IDC_SETTINGNAME,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,115,44,72,10
- CONTROL "Setting name",IDC_SETTINGNAME2,"Button",BS_AUTORADIOBUTTON | NOT WS_VISIBLE | WS_DISABLED | WS_TABSTOP,115,90,72,10
- CONTROL "Setting value",IDC_SETTINGVALUE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,194,44,69,10
- CONTROL "Setting value",IDC_SETTINGVALUE2,"Button",BS_AUTORADIOBUTTON | NOT WS_VISIBLE | WS_DISABLED | WS_TABSTOP,194,90,67,10
- DEFPUSHBUTTON "&Search",IDC_SEARCH,277,5,60,14
- GROUPBOX "Replace with",IDC_STATIC,3,60,334,30
- LTEXT "Text:",IDC_STATIC,10,15,26,8
- EDITTEXT IDC_REPLACE,40,72,216,12,ES_AUTOHSCROLL
- CONTROL "Entirely",IDC_ENTIRELY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,262,74,67,10
- CONTROL "Found field",IDC_FOUND,"Button",BS_AUTORADIOBUTTON | NOT WS_VISIBLE | WS_TABSTOP,267,90,65,10
- PUSHBUTTON "&Replace",IDOK,277,25,60,14
- PUSHBUTTON "&Cancel",IDCANCEL,277,45,60,14
- LISTBOX IDC_LIST,3,95,334,136,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP
- CONTROL "",IDC_SBAR,"msctls_statusbar32",WS_TABSTOP | 0x100,3,237,334,12
+ GROUPBOX "Search for",IDC_SEARCH2,4,1,387,45
+ EDITTEXT IDC_TEXT,10,11,232,12,ES_AUTOHSCROLL
+ CONTROL "Exact match",IDC_EXACT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,249,12,69,8
+ DEFPUSHBUTTON "&Search",IDC_SEARCH,325,10,60,14
+ CONTROL "Module name",IDC_MODNAME,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,29,69,10
+ CONTROL "Setting name",IDC_SETTINGNAME,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,94,29,71,10
+ CONTROL "Setting value",IDC_SETTINGVALUE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,172,29,68,10
+ CONTROL "Case sensitive",IDC_CASESENSITIVE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,249,30,69,8
+ PUSHBUTTON "&Cancel",IDCANCEL,325,27,60,14
+ GROUPBOX "Replace with",IDC_STATIC,4,47,387,28
+ EDITTEXT IDC_REPLACE,10,57,232,12,ES_AUTOHSCROLL
+ CONTROL "Entirely",IDC_ENTIRELY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,249,58,69,10
+ PUSHBUTTON "&Replace",IDOK,325,56,60,14
+ CONTROL "List1",IDC_LIST,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_SORTDESCENDING | LVS_SHAREIMAGELISTS | LVS_AUTOARRANGE | WS_BORDER | WS_TABSTOP,4,80,387,152
+ CONTROL "",IDC_SBAR,"msctls_statusbar32",WS_TABSTOP | 0x100,4,238,387,12
END
IDD_OPTIONS DIALOGEX 0, 0, 314, 92
@@ -86,13 +78,13 @@ BEGIN
END
IDD_EDIT_SETTING DIALOGEX 0, 0, 252, 133
-STYLE DS_SETFONT | DS_MODALFRAME | DS_SETFOREGROUND | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION
+STYLE DS_SETFONT | DS_MODALFRAME | DS_SETFOREGROUND | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION
CAPTION "Edit setting"
FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN
- LTEXT "Value name:",IDC_STATIC,7,7,238,8
+ LTEXT "Name",IDC_STATIC,7,7,238,8
EDITTEXT IDC_SETTINGNAME,7,18,238,14,ES_AUTOHSCROLL
- LTEXT "Value data:",IDC_STATIC,7,37,159,8
+ LTEXT "Value",IDC_STATIC,7,37,159,8
EDITTEXT IDC_SETTINGVALUE,7,49,159,14,ES_AUTOHSCROLL
EDITTEXT IDC_STRING,7,49,238,54,ES_MULTILINE | ES_WANTRETURN | NOT WS_VISIBLE | WS_VSCROLL | WS_HSCROLL
EDITTEXT IDC_BLOB,7,49,238,54,ES_MULTILINE | NOT WS_VISIBLE | WS_VSCROLL
@@ -108,13 +100,13 @@ BEGIN
PUSHBUTTON "Cancel",IDCANCEL,132,114,50,14
END
-IDD_WATCH_DIAG DIALOGEX 0, 0, 414, 190
+IDD_WATCH_DIAG DIALOGEX 0, 0, 413, 199
STYLE DS_SETFONT | DS_SETFOREGROUND | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "Watched database settings"
MENU IDR_WATCHWINDOWMENU
FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN
- CONTROL "List1",IDC_VARS,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_SORTDESCENDING | LVS_SHAREIMAGELISTS | LVS_AUTOARRANGE | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,0,0,414,190
+ CONTROL "List1",IDC_VARS,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_SORTDESCENDING | LVS_SHAREIMAGELISTS | LVS_AUTOARRANGE | WS_BORDER | WS_TABSTOP,0,0,413,199
END
IDD_COPY_MOD DIALOGEX 0, 0, 186, 67
@@ -132,25 +124,24 @@ END
IDD_IMPORT DIALOGEX 0, 0, 268, 170
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
-CAPTION "Import module/settings"
+CAPTION "Import"
FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN
- LTEXT "Paste the settings to import here.",IDC_STATIC,7,7,105,8
+ LTEXT "Paste the settings to import here:",IDC_STATIC,7,7,254,8
EDITTEXT IDC_TEXT,7,18,254,124,ES_MULTILINE | ES_WANTRETURN | WS_VSCROLL | WS_HSCROLL
DEFPUSHBUTTON "Import",IDOK,153,149,50,14
PUSHBUTTON "Cancel",IDCANCEL,211,149,50,14
- PUSHBUTTON "Insert &CR/LF",IDC_CRLF,20,149,58,14
END
-IDD_MAIN DIALOGEX 0, 0, 408, 225
+IDD_MAIN DIALOGEX 0, 0, 549, 238
STYLE DS_ABSALIGN | DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "Database Editor++"
MENU IDR_MAINMENU
FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN
- CONTROL "Tree1",IDC_MODULES,"SysTreeView32",TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | TVS_EDITLABELS | TVS_DISABLEDRAGDROP | TVS_SHOWSELALWAYS | WS_BORDER | WS_HSCROLL | WS_TABSTOP,0,3,102,222
- CONTROL "List1",IDC_SETTINGS,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_SORTASCENDING | LVS_SHAREIMAGELISTS | WS_BORDER | WS_TABSTOP,103,3,305,222
- CONTROL "",IDC_SPLITTER,"Static",SS_ENHMETAFILE,102,3,1,222
+ CONTROL "Tree1",IDC_MODULES,"SysTreeView32",TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | TVS_EDITLABELS | TVS_DISABLEDRAGDROP | TVS_SHOWSELALWAYS | WS_BORDER | WS_HSCROLL | WS_TABSTOP,0,0,131,237
+ CONTROL "List1",IDC_SETTINGS,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_SORTASCENDING | LVS_SHAREIMAGELISTS | WS_BORDER | WS_TABSTOP,135,0,410,237
+ CONTROL "",IDC_SPLITTER,"Static",SS_ENHMETAFILE,131,0,4,235
END
@@ -164,19 +155,20 @@ GUIDELINES DESIGNINFO
BEGIN
IDD_FIND, DIALOG
BEGIN
- LEFTMARGIN, 3
- RIGHTMARGIN, 337
+ LEFTMARGIN, 4
+ RIGHTMARGIN, 391
VERTGUIDE, 10
- VERTGUIDE, 40
- VERTGUIDE, 115
- VERTGUIDE, 194
- VERTGUIDE, 277
- TOPMARGIN, 7
- HORZGUIDE, 18
- HORZGUIDE, 35
- HORZGUIDE, 48
- HORZGUIDE, 68
- HORZGUIDE, 95
+ VERTGUIDE, 16
+ VERTGUIDE, 94
+ VERTGUIDE, 172
+ VERTGUIDE, 249
+ VERTGUIDE, 325
+ TOPMARGIN, 1
+ BOTTOMMARGIN, 249
+ HORZGUIDE, 17
+ HORZGUIDE, 34
+ HORZGUIDE, 63
+ HORZGUIDE, 99
END
IDD_OPTIONS, DIALOG
@@ -235,9 +227,11 @@ BEGIN
IDD_MAIN, DIALOG
BEGIN
- VERTGUIDE, 102
- VERTGUIDE, 103
- TOPMARGIN, 3
+ RIGHTMARGIN, 545
+ VERTGUIDE, 131
+ VERTGUIDE, 135
+ BOTTOMMARGIN, 237
+ HORZGUIDE, 237
END
END
#endif // APSTUDIO_INVOKED
@@ -250,22 +244,23 @@ END
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
-ICO_REGEDIT ICON "Icon_1.ico"
-ICO_KNOWN ICON "Yellow.ico"
-ICO_KNOWNOPEN ICON "Yellow_open.ico"
-ICO_SETTINGS ICON "Icon_4.ico"
-ICO_ONLINE ICON "online2.ico"
+ICO_REGEDIT ICON "regedit.ico"
+ICO_CLOSED ICON "closed.ico"
+ICO_OPENED ICON "opened.ico"
+ICO_SETTINGS ICON "settings.ico"
+ICO_ONLINE ICON "online.ico"
ICO_DBE_BUTT ICON "dbepp.ico"
ICO_REGUSER ICON "usermenu.ico"
-ICO_STRING ICON "Icon_14.ico"
-ICO_CONTACTS ICON "Contacts.ico"
-ICO_BINARY ICON "Icon_15.ico"
-ICO_DWORD ICON "Icon_16.ico"
-ICO_BYTE ICON "Icon_17.ico"
-ICO_WORD ICON "Icon_18.ico"
-ICO_OFFLINE ICON "offline2.ico"
+ICO_STRING ICON "string.ico"
+ICO_CONTACTS ICON "contacts.ico"
+ICO_BINARY ICON "binary.ico"
+ICO_DWORD ICON "dword.ico"
+ICO_BYTE ICON "byte.ico"
+ICO_WORD ICON "word.ico"
+ICO_OFFLINE ICON "offline.ico"
ICO_UNICODE ICON "unicode.ico"
ICO_HANDLE ICON "handle.ico"
+ICO_EMPTY ICON "empty.ico"
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
@@ -311,6 +306,8 @@ BEGIN
BEGIN
MENUITEM "&Search and replace", MENU_FINDANDREPLACE
MENUITEM SEPARATOR
+ MENUITEM "&Fix resident settings", MENU_FIX_RESIDENT
+ MENUITEM SEPARATOR
MENUITEM "&Delete module", MENU_DELETE
END
POPUP "&Watches"
@@ -341,6 +338,8 @@ BEGIN
MENUITEM "Edit &Words in Hex", MENU_WORD_HEX
MENUITEM "Edit &Dwords in Hex", MENU_DWORD_HEX
MENUITEM SEPARATOR
+ MENUITEM "&Inline edit", MENU_INLINE_EDIT
+ MENUITEM SEPARATOR
MENUITEM "&Restore position", MENU_SAVE_POSITION
MENUITEM "&Open options", MENU_OPEN_OPTIONS
END
@@ -350,7 +349,17 @@ IDR_CONTEXTMENU MENU
BEGIN
POPUP "Item context"
BEGIN
- MENUITEM "&Edit/rename", MENU_EDIT_SET
+ MENUITEM "&Edit", MENU_EDIT_SET
+ MENUITEM "&Copy", MENU_COPY_SET
+ MENUITEM "&Delete", MENU_DELETE_SET
+ POPUP "Convert to"
+ BEGIN
+ MENUITEM "&Byte", MENU_CHANGE2BYTE
+ MENUITEM "&Word", MENU_CHANGE2WORD
+ MENUITEM "&Dword", MENU_CHANGE2DWORD
+ MENUITEM "&String", MENU_CHANGE2STRING
+ MENUITEM "&Unicode", MENU_CHANGE2UNICODE
+ END
MENUITEM SEPARATOR
POPUP "New"
BEGIN
@@ -361,37 +370,25 @@ BEGIN
MENUITEM "&Unicode", MENU_ADD_UNICODE
MENUITEM "BL&OB", MENU_ADD_BLOB
END
- POPUP "&Convert to"
- BEGIN
- MENUITEM "&Byte", MENU_CHANGE2BYTE
- MENUITEM "&Word", MENU_CHANGE2WORD
- MENUITEM "&Dword", MENU_CHANGE2DWORD
- MENUITEM "&String", MENU_CHANGE2STRING
- MENUITEM "&Unicode", MENU_CHANGE2UNICODE
- END
- POPUP "Encyption"
- BEGIN
- MENUITEM "View decrypted string", MENU_VIEWDECRYPT
- MENUITEM "View encrypted string", MENU_VIEWENCRYPT
- MENUITEM "Decrypt string", MENU_DECRYPT
- MENUITEM "Encrypt string", MENU_ENCRYPT
- END
MENUITEM SEPARATOR
MENUITEM "&Watch", MENU_WATCH_ITEM
- MENUITEM "&Delete", MENU_DELETE_SET
+ MENUITEM "&Refresh", MENU_REFRESH
+
END
POPUP "Null Mod context"
BEGIN
MENUITEM "&Rename", MENU_RENAME_MOD
MENUITEM "Copy to contact", MENU_COPY_MOD
+ MENUITEM "&Delete", MENU_DELETE_MOD
MENUITEM SEPARATOR
MENUITEM "Export module", MENU_EXPORTMODULE
MENUITEM SEPARATOR
MENUITEM "&Watch", MENU_WATCH_ITEM
- MENUITEM "&Delete", MENU_DELETE_MOD
+ MENUITEM "&Refresh", MENU_REFRESH
END
POPUP "Contact menu"
BEGIN
+ MENUITEM "&Add module", MENU_ADD_MODULE
MENUITEM "&Clone", MENU_CLONE_CONTACT
MENUITEM "&Delete", MENU_DELETE_CONTACT
MENUITEM SEPARATOR
@@ -402,17 +399,20 @@ BEGIN
MENUITEM "From pasted text", MENU_IMPORTFROMTEXT
END
MENUITEM SEPARATOR
- MENUITEM "&Add module", MENU_ADD_MODULE
+ MENUITEM "&Refresh", MENU_REFRESH
END
POPUP "NULL contact menu"
BEGIN
MENUITEM "&Add module", MENU_ADD_MODULE
+ MENUITEM SEPARATOR
MENUITEM "Export settings", MENU_EXPORTCONTACT
POPUP "Import settings"
BEGIN
MENUITEM "From a file", MENU_IMPORTFROMFILE
MENUITEM "From pasted text", MENU_IMPORTFROMTEXT
END
+ MENUITEM SEPARATOR
+ MENUITEM "&Refresh", MENU_REFRESH
END
POPUP "Contacts menu"
BEGIN
@@ -422,17 +422,20 @@ BEGIN
MENUITEM "From a file", MENU_IMPORTFROMFILE
MENUITEM "From pasted text", MENU_IMPORTFROMTEXT
END
+ MENUITEM SEPARATOR
+ MENUITEM "&Refresh", MENU_REFRESH
END
POPUP "Contact Mod context"
BEGIN
MENUITEM "&Rename", MENU_RENAME_MOD
MENUITEM "Copy to contact", MENU_COPY_MOD
+ MENUITEM "&Delete", MENU_DELETE_MOD
MENUITEM SEPARATOR
MENUITEM "Export module", MENU_EXPORTMODULE
MENUITEM "Export module from all contacts", MENU_EXPORTDB
MENUITEM SEPARATOR
MENUITEM "&Watch", MENU_WATCH_ITEM
- MENUITEM "&Delete", MENU_DELETE_MOD
+ MENUITEM "&Refresh", MENU_REFRESH
END
POPUP "new item"
BEGIN
@@ -445,6 +448,8 @@ BEGIN
MENUITEM "&Unicode", MENU_ADD_UNICODE
MENUITEM "BL&OB", MENU_ADD_BLOB
END
+ MENUITEM SEPARATOR
+ MENUITEM "&Refresh", MENU_REFRESH
END
END
diff --git a/plugins/DbEditorPP/res/Icon_4.ico b/plugins/DbEditorPP/res/settings.ico
index 7c6b07c71a..7c6b07c71a 100644
--- a/plugins/DbEditorPP/res/Icon_4.ico
+++ b/plugins/DbEditorPP/res/settings.ico
Binary files differ
diff --git a/plugins/DbEditorPP/res/Icon_14.ico b/plugins/DbEditorPP/res/string.ico
index 0ac0844f9b..0ac0844f9b 100644
--- a/plugins/DbEditorPP/res/Icon_14.ico
+++ b/plugins/DbEditorPP/res/string.ico
Binary files differ
diff --git a/plugins/DbEditorPP/res/Icon_18.ico b/plugins/DbEditorPP/res/word.ico
index 654b6e5c36..654b6e5c36 100644
--- a/plugins/DbEditorPP/res/Icon_18.ico
+++ b/plugins/DbEditorPP/res/word.ico
Binary files differ
diff --git a/plugins/DbEditorPP/src/Version.h b/plugins/DbEditorPP/src/Version.h
index 053c14ebcd..1065e6fbb0 100644
--- a/plugins/DbEditorPP/src/Version.h
+++ b/plugins/DbEditorPP/src/Version.h
@@ -1,7 +1,7 @@
-#define __MAJOR_VERSION 3
-#define __MINOR_VERSION 2
+#define __MAJOR_VERSION 4
+#define __MINOR_VERSION 0
#define __RELEASE_NUM 0
-#define __BUILD_NUM 2
+#define __BUILD_NUM 0
#include <stdver.h>
@@ -9,6 +9,6 @@
#define __FILENAME "DbEditorPP.dll"
#define __DESCRIPTION "Advanced Database Editor."
#define __AUTHOR "Bio, Jonathan Gordon"
-#define __AUTHOREMAIL "bio@msx.ru, jdgordy@gmail.com"
+#define __AUTHOREMAIL "bio@ktaspb.ru, jdgordy@gmail.com"
#define __AUTHORWEB "http://miranda-ng.org/p/DbEditorPP/"
-#define __COPYRIGHT "© 2003-2011 Bio, Jonathan Gordon"
+#define __COPYRIGHT "© 2003-2015 Bio, Jonathan Gordon"
diff --git a/plugins/DbEditorPP/src/addeditsettingsdlg.cpp b/plugins/DbEditorPP/src/addeditsettingsdlg.cpp
deleted file mode 100644
index 52c14c0f32..0000000000
--- a/plugins/DbEditorPP/src/addeditsettingsdlg.cpp
+++ /dev/null
@@ -1,439 +0,0 @@
-#include "headers.h"
-
-static BOOL Convert(MCONTACT hContact, char* module, char* setting, int value, int toType) // 0 = byte, 1 = word, 2 = dword, 3 = string
-{
- int Result = 1;
- char temp[64];
-
- switch (toType) {
- case 0:
- if (value > 0xFF)
- Result = 0;
- else
- db_set_b(hContact, module, setting, (BYTE)value);
- break;
- case 1:
- if (value > 0xFFFF)
- Result = 0;
- else
- db_set_w(hContact, module, setting, (WORD)value);
- break;
- case 2:
- db_set_dw(hContact, module, setting, (DWORD)value);
- break;
- case 3:
- db_unset(hContact, module, setting);
- db_set_s(hContact, module, setting, itoa(value, temp, 10));
- break;
- }
- return Result;
-}
-
-
-BOOL convertSetting(MCONTACT hContact, char* module, char* setting, int toType) // 0 = byte, 1 = word, 2 = dword, 3 = string, 4 = unicode
-{
- DBVARIANT dbv = { 0 };
- BOOL Result = 0;
-
- if (!GetSetting(hContact, module, setting, &dbv)) {
- switch (dbv.type) {
- case DBVT_BYTE:
- Result = Convert(hContact, module, setting, dbv.bVal, toType);
- break;
-
- case DBVT_WORD:
- Result = Convert(hContact, module, setting, dbv.wVal, toType);
- break;
-
- case DBVT_DWORD:
- Result = Convert(hContact, module, setting, dbv.dVal, toType);
- break;
-
- case DBVT_ASCIIZ:
- if (toType == 4) // convert to UNICODE
- {
- int len = (int)mir_strlen(dbv.pszVal) + 1;
- WCHAR *wc = (WCHAR*)_alloca(len*sizeof(WCHAR));
- MultiByteToWideChar(CP_ACP, 0, dbv.pszVal, -1, wc, len);
- Result = !db_set_ws(hContact, module, setting, wc);
- }
- else if (mir_strlen(dbv.pszVal) < 11 && toType != 3) {
- int val = atoi(dbv.pszVal);
- if (val == 0 && dbv.pszVal[0] != '0')
- break;
-
- Result = Convert(hContact, module, setting, val, toType);
- }
- break;
-
- case DBVT_UTF8:
- if (toType == 3) { // convert to ANSI
- int len = (int)mir_strlen(dbv.pszVal) + 1;
- char *sz = (char*)_alloca(len * 3);
- WCHAR *wc = (WCHAR*)_alloca(len*sizeof(WCHAR));
- MultiByteToWideChar(CP_UTF8, 0, dbv.pszVal, -1, wc, len);
- WideCharToMultiByte(CP_ACP, 0, wc, -1, sz, len, NULL, NULL);
- Result = !db_set_s(hContact, module, setting, sz);
- }
- break;
- }
-
- if (!Result)
- msg(Translate("Cannot Convert!"), modFullname);
-
- db_free(&dbv);
- }
-
- return Result;
-}
-
-
-int saveAsType(HWND hwnd)
-{
- if (IsDlgButtonChecked(hwnd, CHK_BYTE))
- return 0;
- else if (IsDlgButtonChecked(hwnd, CHK_WORD))
- return 1;
- else if (IsDlgButtonChecked(hwnd, CHK_DWORD))
- return 2;
- else if (IsDlgButtonChecked(hwnd, CHK_STRING))
- return 3;
- return 3;
-}
-
-
-INT_PTR CALLBACK EditSettingDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- switch (msg)
- {
- case WM_INITDIALOG:
- {
- char tmp[32];
- SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)lParam);
- switch (((struct DBsetting*)lParam)->dbv.type)
- {
- case DBVT_BYTE:
- ShowWindow(GetDlgItem(hwnd, IDC_STRING), SW_HIDE);
- if (!((struct DBsetting*)lParam)->setting[0])
- {
- SetWindowText(hwnd, Translate("New BYTE value"));
- }
- else
- {
- SetWindowText(hwnd, Translate("Edit BYTE value"));
- SetDlgItemText(hwnd, IDC_SETTINGNAME, ((struct DBsetting*)lParam)->setting);
- SetDlgItemText(hwnd, IDC_SETTINGVALUE, itoa(((struct DBsetting*)lParam)->dbv.bVal, tmp, 10));
- }
- CheckRadioButton(hwnd, CHK_HEX, CHK_DECIMAL, CHK_DECIMAL);
- CheckRadioButton(hwnd, CHK_BYTE, CHK_STRING, CHK_BYTE);
- break;
- case DBVT_WORD:
- ShowWindow(GetDlgItem(hwnd, IDC_STRING), SW_HIDE);
- if (!((struct DBsetting*)lParam)->setting[0])
- {
- SetWindowText(hwnd, Translate("New WORD value"));
- }
- else
- {
- SetWindowText(hwnd, Translate("Edit WORD value"));
- SetDlgItemText(hwnd, IDC_SETTINGNAME, ((struct DBsetting*)lParam)->setting);
- SetDlgItemText(hwnd, IDC_SETTINGVALUE, itoa(((struct DBsetting*)lParam)->dbv.wVal, tmp, 10));
- }
- CheckRadioButton(hwnd, CHK_HEX, CHK_DECIMAL, CHK_DECIMAL);
- CheckRadioButton(hwnd, CHK_BYTE, CHK_STRING, CHK_WORD);
- break;
- case DBVT_DWORD:
- ShowWindow(GetDlgItem(hwnd, IDC_STRING), SW_HIDE);
- if (!((struct DBsetting*)lParam)->setting[0])
- {
- SetWindowText(hwnd, Translate("New DWORD value"));
- }
- else
- {
- char text[32];
- SetWindowText(hwnd, Translate("Edit DWORD value"));
- SetDlgItemText(hwnd, IDC_SETTINGNAME, ((struct DBsetting*)lParam)->setting);
- mir_snprintf(text, SIZEOF(text), "%X", ((struct DBsetting*)lParam)->dbv.dVal);
- SetDlgItemText(hwnd, IDC_SETTINGVALUE, text);
- }
- CheckRadioButton(hwnd, CHK_HEX, CHK_DECIMAL, CHK_HEX);
- CheckRadioButton(hwnd, CHK_BYTE, CHK_STRING, CHK_DWORD);
- break;
- case DBVT_ASCIIZ:
- ShowWindow(GetDlgItem(hwnd, IDC_STRING), SW_SHOW);
- ShowWindow(GetDlgItem(hwnd, IDC_SETTINGVALUE), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, CHK_HEX), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, CHK_DECIMAL), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, GRP_BASE), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, GRP_TYPE), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, CHK_BYTE), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, CHK_WORD), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, CHK_DWORD), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, CHK_STRING), SW_HIDE);
- if (!((struct DBsetting*)lParam)->setting[0])
- {
- SetWindowText(hwnd, Translate("New STRING value"));
- }
- else
- {
- SetWindowText(hwnd, Translate("Edit STRING value"));
- SetDlgItemText(hwnd, IDC_SETTINGNAME, ((struct DBsetting*)lParam)->setting);
- SetDlgItemText(hwnd, IDC_STRING, ((struct DBsetting*)lParam)->dbv.pszVal);
- }
- break;
- case DBVT_UTF8:
- ShowWindow(GetDlgItem(hwnd, IDC_STRING), SW_SHOW);
- ShowWindow(GetDlgItem(hwnd, IDC_SETTINGVALUE), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, CHK_HEX), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, CHK_DECIMAL), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, GRP_BASE), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, GRP_TYPE), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, CHK_BYTE), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, CHK_WORD), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, CHK_DWORD), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, CHK_STRING), SW_HIDE);
- if (!((struct DBsetting*)lParam)->setting[0])
- {
- SetWindowText(hwnd, Translate("New UNICODE value"));
- }
- else
- {
- char *tmp = (((struct DBsetting*)lParam)->dbv.pszVal);
- int length = (int)mir_strlen(tmp) + 1;
- WCHAR *wc = (WCHAR*)_alloca(length*sizeof(WCHAR));
- MultiByteToWideChar(CP_UTF8, 0, tmp, -1, wc, length);
- SetDlgItemTextW(hwnd, IDC_STRING, wc);
-
- SetWindowText(hwnd, Translate("Edit UNICODE value"));
- SetDlgItemText(hwnd, IDC_SETTINGNAME, ((struct DBsetting*)lParam)->setting);
- }
- break;
- case DBVT_BLOB:
- {
- ShowWindow(GetDlgItem(hwnd, IDC_STRING), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, IDC_SETTINGVALUE), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, IDC_BLOB), SW_SHOW);
-
- if (!((struct DBsetting*)lParam)->setting[0])
- {
- SetWindowText(hwnd, Translate("New BLOB value"));
- }
- else
- {
- int j;
- char tmp[16];
- int len = ((struct DBsetting*)lParam)->dbv.cpbVal;
- char *data = (char*)_alloca(3 * (len + 1) + 10);
- BYTE *p = ((struct DBsetting*)lParam)->dbv.pbVal;
-
- if (!data) return TRUE;
- data[0] = '\0';
-
- for (j = 0; j < len; j++)
- {
- mir_snprintf(tmp, "%02X ", (BYTE)p[j]);
- mir_strcat(data, tmp);
- }
-
- SetWindowText(hwnd, Translate("Edit BLOB value"));
- SetDlgItemText(hwnd, IDC_SETTINGNAME, ((struct DBsetting*)lParam)->setting);
- SetDlgItemText(hwnd, IDC_BLOB, data);
- }
- ShowWindow(GetDlgItem(hwnd, CHK_HEX), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, CHK_DECIMAL), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, GRP_BASE), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, GRP_TYPE), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, CHK_BYTE), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, CHK_WORD), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, CHK_DWORD), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, CHK_STRING), SW_HIDE);
- }
- break;
- default: return TRUE;
- }
- TranslateDialogDefault(hwnd);
- }
- return TRUE;
- case WM_COMMAND:
- switch (LOWORD(wParam))
- {
- case CHK_BYTE:
- case CHK_WORD:
- case CHK_DWORD:
- EnableWindow(GetDlgItem(hwnd, CHK_HEX), 1);
- EnableWindow(GetDlgItem(hwnd, CHK_DECIMAL), 1);
- CheckRadioButton(hwnd, CHK_BYTE, CHK_STRING, LOWORD(wParam));
- break;
- case CHK_STRING:
- EnableWindow(GetDlgItem(hwnd, CHK_HEX), 0);
- EnableWindow(GetDlgItem(hwnd, CHK_DECIMAL), 0);
- CheckRadioButton(hwnd, CHK_BYTE, CHK_STRING, LOWORD(wParam));
- break;
-
- case CHK_HEX:
- case CHK_DECIMAL:
- CheckRadioButton(hwnd, CHK_HEX, CHK_DECIMAL, LOWORD(wParam));
- {
- char *setting, temp[32];
- int settingLength, tmp;
- settingLength = GetWindowTextLength(GetDlgItem(hwnd, IDC_SETTINGVALUE));
- if (settingLength)
- {
- setting = (char*)_alloca(settingLength + 1);
- if (setting)
- {
- // havta convert it with mir_snprintf()
- GetDlgItemText(hwnd, IDC_SETTINGVALUE, setting, settingLength + 1);
- if (LOWORD(wParam) == CHK_DECIMAL && IsDlgButtonChecked(hwnd, CHK_DECIMAL))
- {
- sscanf(setting, "%X", &tmp);
- mir_snprintf(temp, SIZEOF(temp), "%ld", tmp);
- }
- else
- {
- sscanf(setting, "%d", &tmp);
- mir_snprintf(temp, SIZEOF(temp), "%X", tmp);
- }
- SetDlgItemText(hwnd, IDC_SETTINGVALUE, temp);
- }
- }
- }
- break;
- case IDOK:
- {
- struct DBsetting *dbsetting = (struct DBsetting*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- char *setting, *value;
- int settingLength, valueLength, valueID = IDC_SETTINGVALUE;
- settingLength = GetWindowTextLength(GetDlgItem(hwnd, IDC_SETTINGNAME));
-
- if (IsWindowVisible(GetDlgItem(hwnd, IDC_STRING)))
- valueID = IDC_STRING;
- else
- if (IsWindowVisible(GetDlgItem(hwnd, IDC_SETTINGVALUE)))
- valueID = IDC_SETTINGVALUE;
- else
- if (IsWindowVisible(GetDlgItem(hwnd, IDC_BLOB)))
- valueID = IDC_BLOB;
- else
- break;
-
- valueLength = GetWindowTextLength(GetDlgItem(hwnd, valueID));
-
- if (dbsetting->dbv.type == DBVT_UTF8)
- valueLength *= sizeof(WCHAR);
-
- if (settingLength)
- {
- int settingValue;
- setting = (char*)_alloca(settingLength + 1);
-
- if (valueLength)
- value = (char*)_alloca(valueLength + 2);
- else
- value = (char*)_alloca(2);
-
- if (!setting || !value)
- {
- msg(Translate("Couldn't allocate enough memory!"), modFullname);
- DestroyWindow(hwnd);
- break;
- }
-
- GetDlgItemText(hwnd, IDC_SETTINGNAME, setting, settingLength + 1);
-
- if (valueLength)
- {
- if (dbsetting->dbv.type == DBVT_UTF8)
- GetDlgItemTextW(hwnd, valueID, (LPWSTR)value, (valueLength + 2));
- else
- GetDlgItemText(hwnd, valueID, value, valueLength + 1);
- }
- else
- if (IsWindowVisible(GetDlgItem(hwnd, IDC_STRING)) || (saveAsType(hwnd) == 3))
- memcpy(value, "\0\0", 2);
- else
- mir_strcpy(value, "0");
-
- // delete the old setting
- if (mir_strcmp(setting, dbsetting->setting) && dbsetting->setting && (dbsetting->setting)[0] != 0)
- db_unset(dbsetting->hContact, dbsetting->module, dbsetting->setting);
-
- // delete the setting if we are saving as a different type
- switch (dbsetting->dbv.type)
- {
- case DBVT_BYTE:
- if (saveAsType(hwnd) != 0) db_unset(dbsetting->hContact, dbsetting->module, setting);
- break;
- case DBVT_WORD:
- if (saveAsType(hwnd) != 1) db_unset(dbsetting->hContact, dbsetting->module, setting);
- break;
- case DBVT_DWORD:
- if (saveAsType(hwnd) != 2) db_unset(dbsetting->hContact, dbsetting->module, setting);
- break;
- //case DBVT_ASCIIZ:
- //db_set_s(dbsetting->hContact, dbsetting->module, setting, value);
- //break;
- }
- // write the setting
- switch (saveAsType(hwnd))
- {
- case 0:
- if (IsDlgButtonChecked(hwnd, CHK_HEX)) sscanf(value, "%x", &settingValue);
- else sscanf(value, "%d", &settingValue);
- db_set_b(dbsetting->hContact, dbsetting->module, setting, (BYTE)settingValue);
- break;
- case 1:
- if (IsDlgButtonChecked(hwnd, CHK_HEX)) sscanf(value, "%x", &settingValue);
- else sscanf(value, "%d", &settingValue);
- db_set_w(dbsetting->hContact, dbsetting->module, setting, (WORD)settingValue);
- break;
- case 2:
- if (IsDlgButtonChecked(hwnd, CHK_HEX)) sscanf(value, "%x", &settingValue);
- else sscanf(value, "%d", &settingValue);
- db_set_dw(dbsetting->hContact, dbsetting->module, setting, (DWORD)settingValue);
- break;
- case 3:
- if (dbsetting->dbv.type == DBVT_UTF8)
- db_set_ws(dbsetting->hContact, dbsetting->module, setting, (WCHAR*)value);
- else if (dbsetting->dbv.type == DBVT_BLOB)
- WriteBlobFromString(dbsetting->hContact, dbsetting->module, setting, value, valueLength);
- else if (dbsetting->dbv.type == DBVT_ASCIIZ)
- db_set_s(dbsetting->hContact, dbsetting->module, setting, value);
- break;
- }
-
- }
- } // fall through
- case IDCANCEL:
- {
- struct DBsetting *dbsetting = (struct DBsetting*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- mir_free(dbsetting->module);
- mir_free(dbsetting->setting);
- mir_free(dbsetting);
- DestroyWindow(hwnd);
- }
- break;
- }
- break;
- }
- return 0;
-}
-
-void editSetting(MCONTACT hContact, char* module, char* setting)
-{
- DBVARIANT dbv = { 0 }; // freed in the dialog
- if (!GetSetting(hContact, module, setting, &dbv))
- {
- struct DBsetting *dbsetting = (struct DBsetting *)mir_alloc(sizeof(struct DBsetting)); // gets free()ed in the window proc
-
- dbsetting->dbv = dbv; // freed in the dialog
- dbsetting->hContact = hContact;
- dbsetting->module = mir_tstrdup(module);
- dbsetting->setting = mir_tstrdup(setting);
-
- if (dbv.type == DBVT_UTF8)
- CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_EDIT_SETTING), hwnd2mainWindow, EditSettingDlgProc, (LPARAM)dbsetting);
- else
- CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd2mainWindow, EditSettingDlgProc, (LPARAM)dbsetting);
- }
-} \ No newline at end of file
diff --git a/plugins/DbEditorPP/src/copymodule.cpp b/plugins/DbEditorPP/src/copymodule.cpp
index ed84119b4b..cd88af3515 100644
--- a/plugins/DbEditorPP/src/copymodule.cpp
+++ b/plugins/DbEditorPP/src/copymodule.cpp
@@ -1,103 +1,63 @@
#include "headers.h"
-void copyModule(char* module, MCONTACT hContactFrom, MCONTACT hContactTo)
+void copyModule(const char *module, MCONTACT hContactFrom, MCONTACT hContactTo)
{
ModuleSettingLL msll;
- EnumSettings(hContactFrom, module, &msll);
-
- ModSetLinkLinkItem *setting = msll.first;
- while (setting) {
- DBVARIANT dbv;
- if (!GetSetting(hContactFrom, module, setting->name, &dbv)) {
- switch (dbv.type) {
- case DBVT_BYTE:
- db_set_b(hContactTo, module, setting->name, dbv.bVal);
- break;
- case DBVT_WORD:
- db_set_w(hContactTo, module, setting->name, dbv.wVal);
- break;
- case DBVT_DWORD:
- db_set_dw(hContactTo, module, setting->name, dbv.dVal);
- break;
- case DBVT_ASCIIZ:
- db_set_s(hContactTo, module, setting->name, dbv.pszVal);
- break;
- case DBVT_UTF8:
- db_set_utf(hContactTo, module, setting->name, dbv.pszVal);
- break;
- case DBVT_BLOB:
- db_set_blob(hContactTo, module, setting->name, dbv.pbVal, dbv.cpbVal);
- break;
- }
+ if (IsModuleEmpty(hContactFrom, module) || !EnumSettings(hContactFrom, module, &msll))
+ return;
+
+ DBVARIANT dbv;
+ for(ModSetLinkLinkItem *setting = msll.first; setting; setting = setting->next) {
+ if (!db_get_s(hContactFrom, module, setting->name, &dbv, 0)) {
+ db_set(hContactTo, module, setting->name, &dbv);
+ db_free(&dbv);
}
- db_free(&dbv);
- setting = setting->next;
}
FreeModuleSettingLL(&msll);
}
INT_PTR CALLBACK copyModDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
- ModuleAndContact *mac = (ModuleAndContact *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- if (msg == WM_INITDIALOG)
+ switch (msg) {
+ case WM_INITDIALOG:
{
- int index, loaded;
- char szProto[256];
- for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- if (GetValue(hContact, "Protocol", "p", szProto, SIZEOF(szProto)))
- loaded = IsProtocolLoaded(szProto);
- else
- loaded = 0;
-
- // filter
- if ((loaded && Mode == MODE_UNLOADED) || (!loaded && Mode == MODE_LOADED))
- continue;
-
- // contacts name
- WCHAR nick[256];
- WCHAR protoW[256]; // unicode proto
-
- if (szProto[0])
- a2u(szProto, protoW, SIZEOF(protoW));
- else
- protoW[0] = 0;
-
- if (!szProto[0] || !loaded) {
- if (protoW) {
- if (Order)
- mir_snwprintf(nick, SIZEOF(nick), L"(%s) %s %s", protoW, GetContactName(hContact, szProto, 1), L"(UNLOADED)");
- else
- mir_snwprintf(nick, SIZEOF(nick), L"%s (%s) %s", GetContactName(hContact, szProto, 1), protoW, L"(UNLOADED)");
- }
- else mir_wstrcpy(nick, nick_unknownW);
- }
- else {
- if (Order)
- mir_snwprintf(nick, SIZEOF(nick), L"(%s) %s", protoW, GetContactName(hContact, szProto, 1));
- else
- mir_snwprintf(nick, SIZEOF(nick), L"%s (%s)", GetContactName(hContact, szProto, 1), protoW);
- }
+ TranslateDialogDefault(hwnd);
+ SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
+ ModuleAndContact *mac = (ModuleAndContact *)lParam;
+ TCHAR name[NAME_SIZE], msg[MSG_SIZE];
- index = SendDlgItemMessageW(hwnd, IDC_CONTACTS, CB_ADDSTRING, 0, (LPARAM)nick);
- SendDlgItemMessageW(hwnd, IDC_CONTACTS, CB_SETITEMDATA, index, hContact);
+ mir_sntprintf(msg, TranslateT("Copy module \"%s\""), _A2T(mac->module));
+ SetWindowText(hwnd, msg);
+
+ for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
+ {
+ if (ApplyProtoFilter(hContact))
+ continue;
+
+ GetContactName(hContact, NULL, name, SIZEOF(name));
+
+ int index = SendDlgItemMessage(hwnd, IDC_CONTACTS, CB_ADDSTRING, 0, (LPARAM)name);
+ SendDlgItemMessage(hwnd, IDC_CONTACTS, CB_SETITEMDATA, index, hContact);
}
- index = (int)SendDlgItemMessage(hwnd, IDC_CONTACTS, CB_INSERTSTRING, 0, (LPARAM)Translate("Settings"));
+ GetContactName(NULL, NULL, name, SIZEOF(name));
+ int index = (int)SendDlgItemMessage(hwnd, IDC_CONTACTS, CB_INSERTSTRING, 0, (LPARAM)name);
SendDlgItemMessage(hwnd, IDC_CONTACTS, CB_SETITEMDATA, index, 0);
SendDlgItemMessage(hwnd, IDC_CONTACTS, CB_SETCURSEL, index, 0);
-
- SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
- TranslateDialogDefault(hwnd);
+ break;
}
- else if (msg == WM_COMMAND)
+ case WM_COMMAND:
{
+ ModuleAndContact *mac = (ModuleAndContact *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+
switch (LOWORD(wParam)) {
case CHK_COPY2ALL:
EnableWindow(GetDlgItem(hwnd, IDC_CONTACTS), BST_UNCHECKED == IsDlgButtonChecked(hwnd, CHK_COPY2ALL));
break;
case IDOK:
+
if (BST_UNCHECKED == IsDlgButtonChecked(hwnd, CHK_COPY2ALL)) {
MCONTACT hContact = (MCONTACT)SendDlgItemMessage(hwnd, IDC_CONTACTS, CB_GETITEMDATA, SendDlgItemMessage(hwnd, IDC_CONTACTS, CB_GETCURSEL, 0, 0), 0);
copyModule(mac->module, mac->hContact, hContact);
@@ -109,25 +69,47 @@ INT_PTR CALLBACK copyModDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
SetCursor(LoadCursor(NULL, IDC_ARROW));
}
- mir_free(mac);
refreshTree(1);
- DestroyWindow(hwnd);
- break;
-
+ // fall through
case IDCANCEL:
mir_free(mac);
DestroyWindow(hwnd);
break;
}
+ break;
}
+ } //switch
return 0;
}
-void copyModuleMenuItem(char* module, MCONTACT hContact)
+void copyModuleMenuItem(MCONTACT hContact, const char *module)
{
ModuleAndContact *mac = (ModuleAndContact *)mir_calloc(sizeof(ModuleAndContact));
mac->hContact = hContact;
- strncpy(mac->module, module, 255);
+ mir_strncpy(mac->module, module, sizeof(mac->module));
+
+ CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_COPY_MOD), hwnd2mainWindow, copyModDlgProc, (LPARAM)mac);
+}
+
- CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_COPY_MOD), 0, copyModDlgProc, (LPARAM)mac);
-} \ No newline at end of file
+int CloneContact(MCONTACT hContact)
+{
+ MCONTACT newContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
+ if (!newContact)
+ return 0;
+
+ // enum all the modules
+ ModuleSettingLL modlist;
+
+ if (!EnumModules(&modlist))
+ return 0;
+
+ ModSetLinkLinkItem *mod = modlist.first;
+ while (mod) {
+ copyModule(mod->name, hContact, newContact);
+ mod = (ModSetLinkLinkItem *)mod->next;
+ }
+
+ FreeModuleSettingLL(&modlist);
+ return 1;
+}
diff --git a/plugins/DbEditorPP/src/deletemodule.cpp b/plugins/DbEditorPP/src/deletemodule.cpp
index 7f94d13cd5..98d4075949 100644
--- a/plugins/DbEditorPP/src/deletemodule.cpp
+++ b/plugins/DbEditorPP/src/deletemodule.cpp
@@ -1,17 +1,17 @@
#include "headers.h"
-static int working;
+volatile BOOL working;
static HWND hwnd2Delete = NULL;
-int deleteModule(char *module, MCONTACT hContact, int fromMenu)
+int deleteModule(MCONTACT hContact, const char *module, int confirm)
{
- if (!module)
+ if (!module || IsModuleEmpty(hContact, module))
return 0;
- if (!fromMenu && db_get_b(NULL, modname, "WarnOnDelete", 1)) {
- char msg[1024];
- mir_snprintf(msg, SIZEOF(msg), Translate("Are you sure you want to delete module \"%s\"?"), module);
- if (MessageBox(0, msg, Translate("Confirm module deletion"), MB_YESNO | MB_ICONEXCLAMATION) == IDNO)
+ if (confirm && db_get_b(NULL, modname, "WarnOnDelete", 1)) {
+ TCHAR text[MSG_SIZE];
+ mir_sntprintf(text, TranslateT("Are you sure you want to delete module \"%s\"?"), _A2T(module));
+ if (dlg(text, MB_YESNO | MB_ICONEXCLAMATION) == IDNO)
return 0;
}
@@ -27,28 +27,29 @@ int deleteModule(char *module, MCONTACT hContact, int fromMenu)
return 1;
}
-void __cdecl PopulateModuleDropListThreadFunc(void *di)
+void __cdecl PopulateModuleDropListThreadFunc(void *param)
{
- HWND hwnd = (HWND)di;
+ HWND hwnd = (HWND)param;
ModuleSettingLL msll;
if (!EnumModules(&msll)) {
DestroyWindow(hwnd);
return;
}
+
int moduleEmpty;
ModSetLinkLinkItem *module = msll.first;
while (module && working) {
moduleEmpty = 1;
// check the null
if (!IsModuleEmpty(NULL, module->name)) {
- SendDlgItemMessage(hwnd, IDC_CONTACTS, CB_ADDSTRING, 0, (LPARAM)module->name);
+ SendDlgItemMessageA(hwnd, IDC_CONTACTS, CB_ADDSTRING, 0, (LPARAM)module->name);
moduleEmpty = 0;
module = module->next;
continue;
}
for (MCONTACT hContact = db_find_first(); moduleEmpty && hContact; hContact = db_find_next(hContact)) {
if (!IsModuleEmpty(hContact, module->name)) {
- SendDlgItemMessage(hwnd, IDC_CONTACTS, CB_ADDSTRING, 0, (LPARAM)module->name);
+ SendDlgItemMessageA(hwnd, IDC_CONTACTS, CB_ADDSTRING, 0, (LPARAM)module->name);
moduleEmpty = 0;
break;
}
@@ -59,7 +60,7 @@ void __cdecl PopulateModuleDropListThreadFunc(void *di)
}
SendDlgItemMessage(hwnd, IDC_CONTACTS, CB_SETCURSEL, 0, 0);
FreeModuleSettingLL(&msll);
- SetWindowText(hwnd, Translate("Delete module from database"));
+ SetWindowText(hwnd, TranslateT("Delete module from database"));
EnableWindow(GetDlgItem(hwnd, IDC_CONTACTS), 1);
EnableWindow(GetDlgItem(hwnd, IDOK), 1);
EnableWindow(GetDlgItem(hwnd, IDCANCEL), 1);
@@ -74,30 +75,30 @@ INT_PTR CALLBACK DeleteModuleDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM)
{
switch (msg) {
case WM_INITDIALOG:
- SetWindowText(hwnd, Translate("Delete module from database... Loading"));
+ SetWindowText(hwnd, LPGENT("Delete module from database... Loading"));
EnableWindow(GetDlgItem(hwnd, IDC_CONTACTS), 0);
EnableWindow(GetDlgItem(hwnd, IDOK), 0);
- SetDlgItemText(hwnd, IDC_INFOTEXT, Translate("Delete module from database"));
- SetDlgItemText(hwnd, CHK_COPY2ALL, Translate("Delete module from all contacts (including Setting)"));
+ SetDlgItemText(hwnd, IDC_INFOTEXT, LPGENT("Delete module from database"));
+ SetDlgItemText(hwnd, CHK_COPY2ALL, LPGENT("Delete module from all contacts (including Setting)"));
EnableWindow(GetDlgItem(hwnd, CHK_COPY2ALL), 0);
CheckDlgButton(hwnd, CHK_COPY2ALL, BST_CHECKED);
TranslateDialogDefault(hwnd);
working = 1;
- forkthread(PopulateModuleDropListThreadFunc, 0, hwnd);
+ mir_forkthread(PopulateModuleDropListThreadFunc, hwnd);
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
{
- char text[128];
- GetDlgItemText(hwnd, IDC_CONTACTS, text, SIZEOF(text));
+ char module[FLD_SIZE];
+ GetDlgItemTextA(hwnd, IDC_CONTACTS, module, SIZEOF(module));
SetCursor(LoadCursor(NULL, IDC_WAIT));
for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
- deleteModule(text, hContact, 1);
+ deleteModule(hContact, module, 0);
// do the null
- deleteModule(text, NULL, 1);
+ deleteModule(NULL, module, 0);
SetCursor(LoadCursor(NULL, IDC_ARROW));
refreshTree(1);
}
@@ -118,10 +119,10 @@ INT_PTR CALLBACK DeleteModuleDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM)
return 0;
}
-void deleteModuleGui()
+void deleteModuleDlg()
{
if (!hwnd2Delete)
- hwnd2Delete = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_COPY_MOD), hwnd2mainWindow, DeleteModuleDlgProc, 0);
+ hwnd2Delete = CreateDialog(hInst, MAKEINTRESOURCE(IDD_COPY_MOD), hwnd2mainWindow, DeleteModuleDlgProc);
else
SetForegroundWindow(hwnd2Delete);
-} \ No newline at end of file
+}
diff --git a/plugins/DbEditorPP/src/exportimport.cpp b/plugins/DbEditorPP/src/exportimport.cpp
index 25d1d4779a..61278154f4 100644
--- a/plugins/DbEditorPP/src/exportimport.cpp
+++ b/plugins/DbEditorPP/src/exportimport.cpp
@@ -1,140 +1,147 @@
#include "headers.h"
-int Mode;
-HWND hwnd2importWindow;
-static int Openfile(TCHAR *outputFile, const char *module)
+TCHAR *GetFilter()
+{
+ static TCHAR filter[MAX_PATH];
+ mir_sntprintf(filter, _T("%s%c*.ini%c%s%c*.*%c"), TranslateT("INI Files"), 0, 0, TranslateT("All Files"), 0, 0);
+ return filter;
+}
+
+
+int Openfile(TCHAR *outputFile, const char *module, int maxlen)
{
OPENFILENAME ofn = { 0 };
- char filename[MAX_PATH] = "";
- char filter[MAX_PATH];
- mir_snprintf(filter, SIZEOF(filter), "%s%c*.ini%c%s%c*.*%c", Translate("INI Files"), 0, 0, Translate("All Files"), 0, 0);
- char *title = Translate("Export to file");
+ TCHAR filename[MAX_PATH];
if (module) {
int n = 0;
- mir_strncpy(filename, module, SIZEOF(filename));
+ mir_tstrncpy(filename, _A2T(module), SIZEOF(filename));
while (filename[n]) {
switch (filename[n]) {
- case '*':
- case ':':
- case '/':
- case '?':
- case '|':
- case '\\':
- filename[n] = '_';
+ case _T('*'):
+ case _T(':'):
+ case _T('/'):
+ case _T('?'):
+ case _T('|'):
+ case _T('\\'):
+ filename[n] = _T('_');
break;
}
n++;
}
- }
+ }
+ else
+ filename[0] = 0;
+
ofn.lStructSize = sizeof(ofn);
ofn.lpstrFile = filename;
- ofn.lpstrFilter = filter;
+ ofn.lpstrFilter = GetFilter();
ofn.Flags = OFN_HIDEREADONLY | OFN_SHAREAWARE | OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT;
- ofn.lpstrTitle = title;
- ofn.nMaxFile = MAX_PATH;
- ofn.lpstrDefExt = "ini";
+ ofn.lpstrTitle = TranslateT("Export to file");
+ ofn.nMaxFile = maxlen;
+ ofn.lpstrDefExt = _T("ini");
if (!GetSaveFileName(&ofn))
return 0;
- _tcsncpy_s(outputFile, MAX_PATH, filename, _TRUNCATE);
+ mir_tstrncpy(outputFile, filename, maxlen);
return 1;
}
-void exportModule(MCONTACT hContact, char *module, FILE *file)
+void exportModule(MCONTACT hContact, const char *module, FILE *file)
{
char tmp[32];
ModuleSettingLL settinglist;
ModSetLinkLinkItem *setting;
- EnumSettings(hContact, module, &settinglist);
+ if (IsModuleEmpty(hContact, module) || !EnumSettings(hContact, module, &settinglist))
+ return;
// print the module header..
fprintf(file, "\n[%s]", module);
setting = settinglist.first;
while (setting) {
DBVARIANT dbv;
- if (!GetSetting(hContact, module, setting->name, &dbv)) {
+
+ if (!db_get_s(hContact, module, setting->name, &dbv, 0)) {
+
switch (dbv.type) {
case DBVT_BYTE:
- fprintf(file, "\n%s=b%s", setting->name, itoa(dbv.bVal, tmp, 10));
- db_free(&dbv);
+ fprintf(file, "\n%s=b%s", setting->name, _ultoa(dbv.bVal, tmp, 10));
break;
case DBVT_WORD:
- fprintf(file, "\n%s=w%s", setting->name, itoa(dbv.wVal, tmp, 10));
- db_free(&dbv);
+ fprintf(file, "\n%s=w%s", setting->name, _ultoa(dbv.wVal, tmp, 10));
break;
case DBVT_DWORD:
- fprintf(file, "\n%s=d%s", setting->name, itoa(dbv.dVal, tmp, 10));
- db_free(&dbv);
+ fprintf(file, "\n%s=d%s", setting->name, _ultoa(dbv.dVal, tmp, 10));
break;
+ case DBVT_BLOB:
+ {
+ ptrA data(StringFromBlob(dbv.pbVal, dbv.cpbVal));
+ fprintf(file, "\n%s=n%s", setting->name, data);
+ break;
+ }
+ case DBVT_WCHAR:
case DBVT_ASCIIZ:
case DBVT_UTF8:
- if (strchr(dbv.pszVal, '\r')) {
- CMStringA end = dbv.pszVal;
+ {
+ char *str = (dbv.type == DBVT_WCHAR) ? mir_utf8encodeW(dbv.pwszVal) : dbv.pszVal;
+
+ if (strchr(str, '\r')) {
+ CMStringA end = str;
end.Replace("\\", "\\\\");
end.Replace("\r", "\\r");
end.Replace("\n", "\\n");
fprintf(file, "\n%s=g%s", setting->name, end.c_str());
- break;
+ } else {
+ fprintf(file, "\n%s=%c", setting->name, (dbv.type == DBVT_ASCIIZ) ? 's' : 'u');
+ fputs(str, file);
}
- fprintf(file, "\n%s=%c", setting->name, (dbv.type == DBVT_UTF8) ? 'u' : 's');
- fputs(dbv.pszVal, file);
- db_free(&dbv);
- break;
-
- case DBVT_BLOB:
- char *data = (char*)mir_alloc(3 * (dbv.cpbVal + 1)*sizeof(char));
- data[0] = '\0';
- for (int j = 0; j < dbv.cpbVal; j++) {
- char tmp[16];
- mir_snprintf(tmp, "%02X ", (BYTE)dbv.pbVal[j]);
- mir_strcat(data, tmp);
- }
- fprintf(file, "\n%s=n%s", setting->name, data);
- mir_free(data);
- db_free(&dbv);
+ if (str != dbv.pszVal)
+ mir_free(str);
break;
}
+ } // switch
+ db_free(&dbv);
}
setting = (ModSetLinkLinkItem *)setting->next;
}
FreeModuleSettingLL(&settinglist);
}
+
char* NickFromHContact(MCONTACT hContact)
{
- static char nick[512] = "";
+ static char nick[NAME_SIZE] = "";
if (hContact) {
- char szProto[256];
+ char szProto[FLD_SIZE], name[NAME_SIZE];
int loaded = 0;
-
- if (GetValue(hContact, "Protocol", "p", szProto, SIZEOF(szProto)))
- loaded = IsProtocolLoaded(szProto);
-
- if (!szProto[0] || !loaded) {
- char name[256];
-
- if (szProto[0]) {
- if (GetValue(hContact, szProto, "Nick", name, SIZEOF(name)))
- mir_snprintf(nick, SIZEOF(nick), "%s (%s)", name, szProto);
- else
- mir_snprintf(nick, SIZEOF(nick), "(UNKNOWN) (%s)", szProto);
- }
- else mir_snprintf(nick, SIZEOF(nick), "(UNKNOWN)");
+ szProto[0] = 0;
+
+ if (!db_get_static(hContact, "Protocol", "p", szProto, SIZEOF(szProto)))
+ loaded = Proto_IsProtocolLoaded(szProto) ? 1 : 0;
+
+ if (!szProto[0] || db_get_static(hContact, szProto, "Nick", name, SIZEOF(name)))
+ mir_strncpy(name, "(UNKNOWN)", SIZEOF(name));
+
+ if (!loaded) {
+ if (szProto[0])
+ mir_snprintf(nick, SIZEOF(nick), "%s (%s)", name, szProto);
+ else
+ mir_strncpy(nick, name, SIZEOF(nick));
}
else {
char *uid = (char*)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0);
if ((INT_PTR)uid != CALLSERVICE_NOTFOUND && uid) {
- char szUID[256];
- GetValue(hContact, szProto, uid, szUID, SIZEOF(szUID));
- mir_snprintf(nick, SIZEOF(nick), "%s *(%s)*<%s>*{%s}*", (char*)GetContactName(hContact, szProto, 0), szProto, uid, szUID);
+ char szUID[FLD_SIZE];
+ GetValueA(hContact, szProto, uid, szUID, SIZEOF(szUID));
+ mir_snprintf(nick, SIZEOF(nick), "%s *(%s)*<%s>*{%s}*", name, szProto, uid, szUID);
}
- else mir_snprintf(nick, SIZEOF(nick), "%s (%s)", (char*)GetContactName(hContact, szProto, 0), szProto);
+ else
+ mir_snprintf(nick, SIZEOF(nick), "%s (%s)", name, szProto);
}
}
@@ -143,22 +150,21 @@ char* NickFromHContact(MCONTACT hContact)
// hContact == -1 export entire db. module == NULL export entire contact.
// hContact == -1, module == "" - all contacts
-void exportDB(MCONTACT hContact, char *module)
+void exportDB(MCONTACT hContact, const char *module)
{
ModSetLinkLinkItem *mod;
// enum all the modules
ModuleSettingLL modlist;
- if (!EnumModules(&modlist)) {
- msg(Translate("Error loading module list"), modFullname);
+ if (!EnumModules(&modlist))
return;
- }
TCHAR fileName[MAX_PATH];
- if (Openfile(fileName, (hContact == INVALID_CONTACT_ID) ? NULL : module)) {
+
+ if (Openfile(fileName, (hContact == INVALID_CONTACT_ID) ? NULL : module, MAX_PATH)) {
FILE *file = _tfopen(fileName, _T("wt"));
if (!file) {
- msg(Translate("Couldn't open file for writing"), modFullname);
+ msg(TranslateT("Couldn't open file for writing"));
return;
}
@@ -192,18 +198,10 @@ void exportDB(MCONTACT hContact, char *module)
fprintf(file, "\n\n");
while (hContact) {
- // filter
- if (Mode != MODE_ALL) {
- char szProto[256];
- int loaded = 0;
-
- if (GetValue(hContact, "Protocol", "p", szProto, SIZEOF(szProto)))
- loaded = IsProtocolLoaded(szProto);
-
- if ((loaded && Mode == MODE_UNLOADED) || (!loaded && Mode == MODE_LOADED)) {
- hContact = db_find_next(hContact);
- continue;
- }
+
+ if (ApplyProtoFilter(hContact)) {
+ hContact = db_find_next(hContact);
+ continue;
}
fprintf(file, "CONTACT: %s\n", NickFromHContact(hContact));
@@ -266,23 +264,27 @@ void exportDB(MCONTACT hContact, char *module)
FreeModuleSettingLL(&modlist);
}
-MCONTACT CheckNewContact(char *myProto, char *uid, char *myName)
+MCONTACT CheckNewContact(const char *myProto, const char *uid, const char *myName)
{
- char szProto[256], szName[256];
+ char szProto[FLD_SIZE], szName[NAME_SIZE];
for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
- if (DBGetContactSettingStringStatic(hContact, "Protocol", "p", szProto, 256))
+ if (!db_get_static(hContact, "Protocol", "p", szProto, SIZEOF(szProto)))
if (!mir_strcmp(szProto, myProto))
- if (GetValue(hContact, szProto, uid, szName, SIZEOF(szName)) && !mir_strcmp(szName, myName))
+ if (GetValueA(hContact, szProto, uid, szName, SIZEOF(szName)) && !mir_strcmp(szName, myName))
return hContact;
return INVALID_CONTACT_ID;
}
-void importSettings(MCONTACT hContact, char *importstring)
+
+void importSettings(MCONTACT hContact, char *utf8)
{
- char module[256] = "", setting[256] = "", *end;
+ char module[FLD_SIZE] = "", setting[FLD_SIZE] = "", *end;
int i = 0, value, type;
+ char *importstring = utf8;
+ char uid[FLD_SIZE], szUID[FLD_SIZE], szProto[FLD_SIZE];
+
importstring = strtok(importstring, "\n");
SetCursor(LoadCursor(NULL, IDC_WAIT));
@@ -307,11 +309,10 @@ void importSettings(MCONTACT hContact, char *importstring)
int len = (int)mir_strlen(&importstring[i]);
if (len > 10) {
- char uid[256] = "", szUID[256] = "", szProto[512] = "";
- char *p1, *p2;
+ uid[0] = 0; szUID[0] = 0, szProto[0] = 0;
- p1 = strrchr(&importstring[i], '>*{');
- p2 = strrchr(&importstring[i], '}*');
+ char *p1 = strrchr(&importstring[i], '>*{');
+ char *p2 = strrchr(&importstring[i], '}*');
if (p1 && p2 && p1 + 3 < p2 && p2 - p1 < SIZEOF(szUID)) {
strncpy(szUID, p1 + 1, p2 - p1 - 2);
@@ -355,7 +356,7 @@ void importSettings(MCONTACT hContact, char *importstring)
if (end = strpbrk(&importstring[i + 2], "]")) {
*end = '\0';
mir_strcpy(module, &importstring[i + 2]);
- deleteModule(module, hContact, 1);
+ deleteModule(hContact, module, 0);
}
}
else if (strstr(&importstring[i], "=") && module[0]) { // get the setting
@@ -365,8 +366,8 @@ void importSettings(MCONTACT hContact, char *importstring)
// get the type
type = *(end + 1);
- if (mir_tstrcmp(module, "CList") == 0 && mir_tstrcmp(setting, "Group") == 0) {
- ptrW GroupName(mir_utf8decodeW(end + 2));
+ if (mir_strcmp(module, "CList") == 0 && mir_strcmp(setting, "Group") == 0) {
+ ptrA GroupName(mir_utf8decodeA(end + 2));
if (!GroupName)
continue;
@@ -383,17 +384,17 @@ void importSettings(MCONTACT hContact, char *importstring)
switch (type) {
case 'b':
case 'B':
- if (sscanf((end + 2), "%d", &value) == 1)
+ if (sscanf((end + 2), "%u", &value) == 1)
db_set_b(hContact, module, setting, (BYTE)value);
break;
case 'w':
case 'W':
- if (sscanf((end + 2), "%d", &value) == 1)
+ if (sscanf((end + 2), "%u", &value) == 1)
db_set_w(hContact, module, setting, (WORD)value);
break;
case 'd':
case 'D':
- if (sscanf((end + 2), "%d", &value) == 1)
+ if (sscanf((end + 2), "%u", &value) == 1)
db_set_dw(hContact, module, setting, (DWORD)value);
break;
case 's':
@@ -434,70 +435,39 @@ void importSettings(MCONTACT hContact, char *importstring)
SetCursor(LoadCursor(NULL, IDC_ARROW));
}
+
INT_PTR CALLBACK ImportDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_INITDIALOG:
- hwnd2importWindow = hwnd;
SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
TranslateDialogDefault(hwnd);
- SendDlgItemMessage(hwnd, IDC_TEXT, EM_LIMITTEXT, (WPARAM)sizeof(TCHAR) * 0x7FFFFFFF, 0);
+ SendDlgItemMessage(hwnd, IDC_TEXT, EM_LIMITTEXT, (WPARAM)0x7FFFFFFF, 0);
+
+ TCHAR name[NAME_SIZE], msg[MSG_SIZE];
+
+ GetContactName((MCONTACT)lParam, NULL, name, SIZEOF(name));
+
+ mir_sntprintf(msg, TranslateT("Import to \"%s\""), name);
+ SetWindowText(hwnd, msg);
+
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
- case IDC_CRLF:
- {
- int length = GetWindowTextLength(GetDlgItem(hwnd, IDC_TEXT));
- char *string = (char*)_alloca(length + 3);
- int Pos = 2;
-
- if (length) {
- int Range = SendDlgItemMessage(hwnd, IDC_TEXT, EM_GETSEL, 0, 0);
- int Min = LOWORD(Range);
- int Max = HIWORD(Range);
-
- GetDlgItemText(hwnd, IDC_TEXT, string, length + 1);
-
- if (Min == -1)
- memcpy(string, crlf_string, sizeof(crlf_string));
- else if (Max == -1 || Max >= length)
- memcpy(&string[Min], crlf_string, sizeof(crlf_string));
- else if (Max - Min > 2) {
- memcpy(&string[Min], crlf_string, sizeof(crlf_string));
- memmove(&string[Min + 2], &string[Max], length - Max + 1);
- }
- else {
- memmove(&string[Min + 2], &string[Max], length - Max + 1);
- memcpy(&string[Min], crlf_string, sizeof(crlf_string));
- }
-
- if (Min) Pos += Min;
- }
- else memcpy(string, crlf_string, sizeof(crlf_string));
-
- SetDlgItemText(hwnd, IDC_TEXT, string);
- SendDlgItemMessage(hwnd, IDC_TEXT, EM_SETSEL, Pos, Pos);
- SetFocus(GetDlgItem(hwnd, IDC_TEXT));
- }
- break;
case IDCANCEL:
DestroyWindow(hwnd);
- hwnd2importWindow = 0;
break;
case IDOK:
MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hwnd, GWLP_USERDATA);
int length = GetWindowTextLength(GetDlgItem(hwnd, IDC_TEXT));
if (length) {
- char *string = (char*)_alloca(length + 1);
- if (!string) {
- msg(Translate("Couldn't allocate enough memory!"), modFullname);
- DestroyWindow(hwnd);
- }
- GetDlgItemText(hwnd, IDC_TEXT, string, length + 1);
- importSettings(hContact, string);
+ TCHAR *data = (TCHAR*)mir_alloc((length + 1)*sizeof(TCHAR));
+ GetDlgItemText(hwnd, IDC_TEXT, data, length + 1);
+ importSettings(hContact, T2Utf(data));
+ mir_free(data);
refreshTree(1);
}
}
@@ -506,27 +476,24 @@ INT_PTR CALLBACK ImportDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam
return 0;
}
+
void ImportSettingsMenuItem(MCONTACT hContact)
{
- if (hwnd2importWindow)
- DestroyWindow(hwnd2importWindow);
-
- CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_IMPORT), 0, ImportDlgProc, hContact);
+ CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_IMPORT), hwnd2mainWindow, ImportDlgProc, hContact);
}
-int Openfile2Import(char *outputFiles)
+
+int Openfile2Import(TCHAR *outputFiles, int maxlen)
{
- char filter[MAX_PATH];
- mir_snprintf(filter, SIZEOF(filter), "%s%c*.ini%c%s%c*.*%c", Translate("INI Files"), 0, 0, Translate("All Files"), 0, 0);
OPENFILENAME ofn = { 0 };
- ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
- ofn.lpstrFilter = filter;
+ ofn.lStructSize = sizeof(ofn);
+ ofn.lpstrFilter = GetFilter();
ofn.lpstrFile = outputFiles;
- ofn.nMaxFile = MAX_PATH * 10;
+ ofn.nMaxFile = maxlen;
ofn.nMaxFileTitle = MAX_PATH;
- ofn.Flags = OFN_HIDEREADONLY | OFN_SHAREAWARE | OFN_PATHMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_EXPLORER;
- ofn.lpstrTitle = Translate("Import from files");
+ ofn.Flags = OFN_SHAREAWARE | OFN_PATHMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_EXPLORER;
+ ofn.lpstrTitle = TranslateT("Import from files");
if (!GetOpenFileName(&ofn))
return 0;
@@ -538,43 +505,45 @@ BOOL Exists(LPCTSTR strName)
return GetFileAttributes(strName) != INVALID_FILE_ATTRIBUTES;
}
-void ImportSettingsFromFileMenuItem(MCONTACT hContact, char* FilePath)
+void ImportSettingsFromFileMenuItem(MCONTACT hContact, const char *FilePath)
{
- char szFileNames[MAX_PATH * 10] = { 0 };
- char szPath[MAX_PATH] = "";
- char szFile[MAX_PATH];
+ TCHAR szFileNames[MAX_PATH * 10];
+ TCHAR szPath[MAX_PATH] = { 0 };
+ TCHAR szFile[MAX_PATH];
DWORD offset = 0;
- if (mir_tstrcmp(FilePath, "") == 0)
- offset = Openfile2Import(szFileNames);
+
+ mir_tstrcpy(szFileNames, _T(""));
+
+ if (!FilePath)
+ offset = Openfile2Import(szFileNames, SIZEOF(szFileNames));
else {
- if (Exists(FilePath))
- mir_tstrcpy(szFileNames, FilePath);
- else
- mir_tstrcpy(szFileNames, "");
+ _A2T tmp(FilePath);
+ if (GetFileAttributes(tmp) != INVALID_FILE_ATTRIBUTES)
+ mir_tstrncpy(szFileNames, tmp, SIZEOF(szFileNames));
}
int index = 0;
- if (!mir_tstrcmp(szFileNames, "") == 0) {
- if ((DWORD)mir_strlen(szFileNames) < offset) {
+ if (mir_tstrcmp(szFileNames, _T(""))) {
+ if ((DWORD)mir_tstrlen(szFileNames) < offset) {
index += offset;
- strncpy(szPath, szFileNames, offset);
- mir_strcat(szPath, "\\");
+ mir_tstrncpy(szPath, szFileNames, offset);
+ mir_tstrcat(szPath, _T("\\"));
}
while (szFileNames[index]) {
- mir_strcpy(szFile, szPath);
- mir_strcat(szFile, &szFileNames[index]);
- index += (int)mir_strlen(&szFileNames[index]) + 1;
+ mir_tstrcpy(szFile, szPath);
+ mir_tstrcat(szFile, &szFileNames[index]);
+ index += (int)mir_tstrlen(&szFileNames[index]) + 1;
HANDLE hFile = CreateFile(szFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if (hFile != INVALID_HANDLE_VALUE) {
if (GetFileSize(hFile, NULL) > 0) {
HANDLE hMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
if (hMap) {
- PBYTE pFile = (PBYTE)MapViewOfFile(hMap, FILE_MAP_COPY, 0, 0, 0);
+ char *pFile = (char*)MapViewOfFile(hMap, FILE_MAP_COPY, 0, 0, 0);
if (pFile) {
- importSettings(hContact, (char*)pFile);
+ importSettings(hContact, pFile);
UnmapViewOfFile(pFile);
}
CloseHandle(hMap);
@@ -584,7 +553,7 @@ void ImportSettingsFromFileMenuItem(MCONTACT hContact, char* FilePath)
}
else break;
}
- if (mir_tstrcmp(FilePath, "") == 0)
+ if (mir_strcmp(FilePath, "") == 0)
refreshTree(1);
}
}
diff --git a/plugins/DbEditorPP/src/findwindow.cpp b/plugins/DbEditorPP/src/findwindow.cpp
index ee86cba930..3e65b5c02c 100644
--- a/plugins/DbEditorPP/src/findwindow.cpp
+++ b/plugins/DbEditorPP/src/findwindow.cpp
@@ -1,36 +1,61 @@
#include "headers.h"
-void __cdecl FindSettings(LPVOID di);
-static int working;
-static int replace;
-#define FW_CASE 1
-#define FW_EXACT 2
-#define FW_MODNAME 4
-#define FW_SETNAME 8
-#define FW_SETVAL 16
+#ifdef _UNICODE
+ #define FindMatchT(a,b,c) FindMatchW(a,b,c)
+#else
+ #define FindMatchT(a,b,c) FindMatchA(a,b,c)
+#endif
+
+
+#ifdef _UNICODE
+ #define multiReplaceT(a,b,c,d) multiReplaceW(a,b,c,d)
+#else
+ #define multiReplaceT(a,b,c,d) multiReplaceA(a,b,c,d)
+#endif
+
+
+static int lastColumn = -1;
-#define FW_REPLACED 0x100
-#define FW_DELETED 0x200
-#define RW_MODULE 1
-#define RW_SETNAME 2
-#define RW_SETVAL 4
-#define RW_FOUND 8
+#define F_CASE 1
+#define F_EXACT 2
+#define F_MODNAME 4
+#define F_SETNAME 8
+#define F_SETVAL 0x10
+
+#define F_ENTIRE 0x20
+
+#define F_NUMSRCH 0x40
+#define F_NUMREPL 0x80
+#define F_UNICODE 0x100
+
+#define F_REPLACED 0x200
+#define F_DELETED 0x400
-#define RW_FULL 0x100
-#define RW_CASE 0x200
typedef struct {
- HWND hwnd; // hwnd 2 item list
- char* text; // text to find
+ HWND hwnd; // hwnd to item list
+ TCHAR* search; // text to find
+ TCHAR* replace; // text to replace
int options; // or'd about items
- char* replace; // text to replace
- int mode; // replace mode
} FindInfo;
+ColumnsSettings csResultList[] = {
+ { LPGENT("Result"), 0, "Search0width", 100 },
+ { LPGENT("Contact"), 1, "Search1width", 100 },
+ { LPGENT("Module"), 2, "Search2width", 100 },
+ { LPGENT("Setting"), 3, "Search3width", 100 },
+ { LPGENT("Value"), 4, "Search4width", 150 },
+ {0}
+};
+
+
+void __cdecl FindSettings(LPVOID di);
+
+
int FindDialogResize(HWND, LPARAM, UTILRESIZECONTROL *urc)
{
switch (urc->wId) {
@@ -43,21 +68,12 @@ int FindDialogResize(HWND, LPARAM, UTILRESIZECONTROL *urc)
}
}
-void freeItems(HWND hwnd)
-{
- for (int i = 0; i < SendMessage(hwnd, LB_GETCOUNT, 0, 0); i++) {
- ItemInfo *ii = (ItemInfo*)SendMessage(hwnd, LB_GETITEMDATA, i, 0);
- if ((LRESULT)ii != LB_ERR)
- mir_free(ii);
- }
-}
INT_PTR CALLBACK FindWindowDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_INITDIALOG:
- TranslateDialogDefault(hwnd);
- SendDlgItemMessage(hwnd, IDC_SBAR, SB_SETTEXT, 0, (LPARAM)Translate("Enter a string to search the database for"));
+ SendDlgItemMessage(hwnd, IDC_SBAR, SB_SETTEXT, 0, (LPARAM)LPGENT("Enter a string to search the database for"));
CheckDlgButton(hwnd, IDC_MODNAME, BST_CHECKED);
CheckDlgButton(hwnd, IDC_SETTINGNAME, BST_CHECKED);
CheckDlgButton(hwnd, IDC_SETTINGVALUE, BST_CHECKED);
@@ -65,25 +81,29 @@ INT_PTR CALLBACK FindWindowDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(ICO_REGEDIT)));
SetWindowLongPtr(GetDlgItem(hwnd, IDC_REPLACE), GWLP_USERDATA, 0);
SetWindowLongPtr(GetDlgItem(hwnd, IDC_SEARCH), GWLP_USERDATA, 0);
+ SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_APPWINDOW); // taskbar icon
+ TranslateDialogDefault(hwnd);
+ ListView_SetExtendedListViewStyle(GetDlgItem(hwnd, IDC_LIST), 32 | LVS_EX_LABELTIP); // LVS_EX_GRIDLINES
+ loadListSettings(GetDlgItem(hwnd, IDC_LIST), csResultList);
+ Utils_RestoreWindowPositionNoMove(hwnd, NULL, modname, "Search_");
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
- SetWindowLongPtr(GetDlgItem(hwnd, IDC_REPLACE), GWLP_USERDATA, 1);
-
case IDC_SEARCH:
if (GetWindowLongPtr(GetDlgItem(hwnd, IDC_SEARCH), GWLP_USERDATA)) // stop the search
SetWindowLongPtr(GetDlgItem(hwnd, IDC_SEARCH), GWLP_USERDATA, 0);
else {
- char text[256];
- char replace[256] = "";
+ TCHAR text[FLD_SIZE];
+ TCHAR replace[FLD_SIZE] = {0};
- if (!GetDlgItemText(hwnd, IDC_TEXT, text, SIZEOF(text))) break;
+ if (!GetDlgItemText(hwnd, IDC_TEXT, text, SIZEOF(text)) && !IsDlgButtonChecked(hwnd, IDC_EXACT)) break;
- if (GetWindowLongPtr(GetDlgItem(hwnd, IDC_REPLACE), GWLP_USERDATA) &&
+ // empty replace is done only for exact match or entire replace
+ if (LOWORD(wParam) == IDOK &&
!GetDlgItemText(hwnd, IDC_REPLACE, replace, SIZEOF(replace)) &&
- BST_UNCHECKED == IsDlgButtonChecked(hwnd, IDC_ENTIRELY))
+ (!IsDlgButtonChecked(hwnd, IDC_ENTIRELY) && !IsDlgButtonChecked(hwnd, IDC_EXACT)))
break;
if (BST_UNCHECKED == IsDlgButtonChecked(hwnd, IDC_MODNAME) &&
@@ -96,65 +116,47 @@ INT_PTR CALLBACK FindWindowDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
break;
fi->hwnd = GetDlgItem(hwnd, IDC_LIST);
- fi->options = (IsDlgButtonChecked(hwnd, IDC_CASESENSITIVE) ? FW_CASE : 0) |
- (IsDlgButtonChecked(hwnd, IDC_EXACT) ? FW_EXACT : 0) |
- (IsDlgButtonChecked(hwnd, IDC_MODNAME) ? FW_MODNAME : 0) |
- (IsDlgButtonChecked(hwnd, IDC_SETTINGNAME) ? FW_SETNAME : 0) |
- (IsDlgButtonChecked(hwnd, IDC_SETTINGVALUE) ? FW_SETVAL : 0);
-
- if (GetWindowLongPtr(GetDlgItem(hwnd, IDC_REPLACE), GWLP_USERDATA)) {
- if (IsDlgButtonChecked(hwnd, IDC_FOUND))
- fi->mode = RW_FOUND;
- else if (IsDlgButtonChecked(hwnd, IDC_MODNAME2))
- fi->mode = RW_MODULE;
- else if (IsDlgButtonChecked(hwnd, IDC_SETTINGNAME2))
- fi->mode = RW_SETNAME;
- else if (IsDlgButtonChecked(hwnd, IDC_SETTINGVALUE2))
- fi->mode = RW_SETVAL;
+ fi->options = (IsDlgButtonChecked(hwnd, IDC_CASESENSITIVE) ? F_CASE : 0) |
+ (IsDlgButtonChecked(hwnd, IDC_EXACT) ? F_EXACT : 0) |
+ (IsDlgButtonChecked(hwnd, IDC_MODNAME) ? F_MODNAME : 0) |
+ (IsDlgButtonChecked(hwnd, IDC_SETTINGNAME) ? F_SETNAME : 0) |
+ (IsDlgButtonChecked(hwnd, IDC_SETTINGVALUE) ? F_SETVAL : 0);
+
+ if (LOWORD(wParam) == IDOK) {
if (IsDlgButtonChecked(hwnd, IDC_ENTIRELY))
- fi->mode |= RW_FULL;
+ fi->options |= F_ENTIRE;
fi->replace = mir_tstrdup(replace);
- SetDlgItemText(hwnd, IDOK, Translate("Stop"));
+ SetDlgItemText(hwnd, IDOK, TranslateT("Stop"));
EnableWindow(GetDlgItem(hwnd, IDC_SEARCH), 0);
- if (IsDlgButtonChecked(hwnd, IDC_CASESENSITIVE))
- fi->mode |= RW_CASE;
}
else {
- SetDlgItemText(hwnd, IDC_SEARCH, Translate("Stop"));
+ SetDlgItemText(hwnd, IDC_SEARCH, TranslateT("Stop"));
EnableWindow(GetDlgItem(hwnd, IDOK), 0);
}
- fi->text = mir_tstrdup(text);
+ fi->search = mir_tstrdup(text);
- SendDlgItemMessage(hwnd, IDC_LIST, LB_RESETCONTENT, 0, 0);
+ ListView_DeleteAllItems(fi->hwnd);
SetWindowLongPtr(GetDlgItem(hwnd, IDC_SEARCH), GWLP_USERDATA, 1);
EnableWindow(GetDlgItem(hwnd, IDCANCEL), 0);
- forkthread(FindSettings, 0, fi);
+ mir_forkthread(FindSettings, fi);
}
break;
case IDCANCEL:
DestroyWindow(hwnd);
break;
- case IDC_LIST:
- if (HIWORD(wParam) == LBN_DBLCLK) {
- int i = SendDlgItemMessage(hwnd, IDC_LIST, LB_GETCURSEL, 0, 0);
- ItemInfo *ii = (ItemInfo*)SendDlgItemMessage(hwnd, IDC_LIST, LB_GETITEMDATA, i, 0);
- if (!ii) break;
- SendMessage(GetParent(hwnd), WM_FINDITEM, (WPARAM)ii, 0);
- }
- break;
}
break;
case WM_GETMINMAXINFO:
{
MINMAXINFO *mmi = (MINMAXINFO*)lParam;
- mmi->ptMinTrackSize.x = 520;
+ mmi->ptMinTrackSize.x = 610;
mmi->ptMinTrackSize.y = 300;
}
return 0;
@@ -165,477 +167,430 @@ INT_PTR CALLBACK FindWindowDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
urd.cbSize = sizeof(urd);
urd.hInstance = hInst;
urd.hwndDlg = hwnd;
- urd.lpTemplate = MAKEINTRESOURCE(IDD_FIND);
+ urd.lpTemplate = MAKEINTRESOURCEA(IDD_FIND);
urd.pfnResizer = FindDialogResize;
CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd);
}
break;
+ case WM_NOTIFY:
+ if (LOWORD(wParam) != IDC_LIST) break;
+ switch (((NMHDR*)lParam)->code) {
+ case NM_DBLCLK:
+ {
+ LVHITTESTINFO hti;
+ LVITEM lvi;
+ HWND hwndResults = GetDlgItem(hwnd, IDC_LIST);
+ hti.pt = ((NMLISTVIEW*)lParam)->ptAction;
+ if (ListView_SubItemHitTest(hwndResults, &hti) > -1) {
+ if (hti.flags&LVHT_ONITEM)
+ {
+ lvi.mask = LVIF_PARAM;
+ lvi.iItem = hti.iItem;
+ lvi.iSubItem = 0;
+ if (ListView_GetItem(hwndResults, &lvi))
+ {
+ ItemInfo ii = {0};
+ ii.hContact = (MCONTACT)lvi.lParam;
+ ListView_GetItemTextA(hwndResults, hti.iItem, 2, ii.module, SIZEOF(ii.module));
+ ListView_GetItemTextA(hwndResults, hti.iItem, 3, ii.setting, SIZEOF(ii.setting));
+ if (ii.setting[0])
+ ii.type = FW_SETTINGNAME;
+ else if (ii.module[0])
+ ii.type = FW_MODULE;
+
+ SendMessage(hwnd2mainWindow, WM_FINDITEM, (WPARAM)&ii, 0);
+ }
+ }
+ }
+ break;
+ }
+
+ case LVN_COLUMNCLICK:
+ {
+ LPNMLISTVIEW lv = (LPNMLISTVIEW)lParam;
+ ColumnsSortParams params;
+ params.hList = GetDlgItem(hwnd, IDC_LIST);
+ params.column = lv->iSubItem;
+ params.last = lastColumn;
+ ListView_SortItemsEx(params.hList, ColumnsCompare, (LPARAM)&params);
+ lastColumn = (params.column == lastColumn) ? -1 : params.column;
+ break;
+ }
+ } // switch
+ break;
case WM_DESTROY:
- freeItems(hwnd);
+ ListView_DeleteAllItems(GetDlgItem(hwnd, IDC_LIST));
+ saveListSettings(GetDlgItem(hwnd, IDC_LIST), csResultList);
+ Utils_SaveWindowPosition(hwnd, NULL, modname, "Search_");
break;
}
return 0;
}
-void ItemFound(HWND hwnd, MCONTACT hContact, const char *module, const char *setting, const char* value, int type)
-{
- ItemInfo *ii = (ItemInfo*)mir_calloc(sizeof(ItemInfo));
- if (!ii) return;
-
- int index;
- char text[256] = "";
- char szValue[256];
- char *name, *mode;
-
- if (type & FW_REPLACED)
- mode = Translate("Replaced with");
- else
- if (type & FW_DELETED)
- mode = Translate("Deleted");
- else
- mode = Translate("Found");
-
- name = hContact ? (char*)GetContactName(hContact, NULL, 0) : Translate("Settings");
-
- switch (type & 0xFF) {
- case FW_MODULE:
- ii->type = FW_MODULE;
- mir_snprintf(text, SIZEOF(text), Translate("%s Module \"%s\" in contact \"%s\""), mode, module, name);
- break;
- case FW_SETTINGNAME:
- mir_strncpy(ii->setting, setting, SIZEOF(ii->setting));
- ii->type = FW_SETTINGNAME;
- if (GetValue(hContact, module, setting, szValue, SIZEOF(szValue)))
- mir_snprintf(text, SIZEOF(text), Translate("%s Setting \"%s\" in module \"%s\" in contact \"%s\" - \"%s\""), mode, setting, module, name, szValue);
- else
- mir_snprintf(text, SIZEOF(text), Translate("%s Setting \"%s\" in module \"%s\" in contact \"%s\""), mode, setting, module, name);
- break;
- case FW_SETTINGVALUE:
- mir_strncpy(ii->setting, setting, SIZEOF(ii->setting));
- ii->type = FW_SETTINGVALUE;
- mir_snprintf(text, SIZEOF(text), Translate("%s \"%s\" in Setting \"%s\" in module \"%s\" in contact \"%s\""), mode, value, setting, module, name);
- break;
- }
- index = SendMessage(hwnd, LB_ADDSTRING, 0, (LPARAM)text);
- if (type & FW_DELETED) {
- SendMessage(hwnd, LB_SETITEMDATA, index, 0);
- mir_free(ii);
- }
- else {
- ii->hContact = hContact;
- mir_strncpy(ii->module, module, SIZEOF(ii->module));
- SendMessage(hwnd, LB_SETITEMDATA, index, (LPARAM)ii);
- }
+void newFindWindow() {
+ CreateDialog(hInst, MAKEINTRESOURCE(IDD_FIND), hwnd2mainWindow, FindWindowDlgProc);
}
-char* multiReplace(const char* value, const char *find, const char *replace, int cs)
+void ItemFound(HWND hwnd, MCONTACT hContact, const char *module, const char *setting, TCHAR* value, int type)
{
- char *head, *temp, *string;
+ TCHAR name[NAME_SIZE];
+ TCHAR* mode;
- int len = (int)mir_strlen(find);
- int replen = (int)mir_strlen(replace);
+ if (type & F_REPLACED)
+ mode = TranslateT("Replaced");
+ else if (type & F_DELETED)
+ mode = TranslateT("Deleted");
+ else
+ mode = TranslateT("Found");
+
+ GetContactName(hContact, NULL, name, SIZEOF(name));
- // only should be 1 '=' sign there...
- if (head = (char*)(cs ? strstr(value, find) : StrStrI(value, find))) {
- string = (char*)value;
- temp = (char*)mir_alloc(1 * sizeof(char));
- temp[0] = '\0';
+ LVITEM lvi = {0};
+ lvi.mask = LVIF_PARAM;
+ lvi.lParam = (LPARAM)hContact;
- while (head) {
- temp = (char*)mir_realloc(temp, mir_strlen(temp) + mir_strlen(string) + replen + 1);
- if (!temp) mir_tstrdup(value);
+ int index = ListView_InsertItem(hwnd, &lvi);
+ ListView_SetItemText(hwnd, index, 0, mode);
+ ListView_SetItemText(hwnd, index, 1, name);
- mir_strncat(temp, string, (head - string));
- string = head + len;
- mir_strcat(temp, replace);
+ ListView_SetItemTextA(hwnd, index, 2, module);
- head = (cs ? strstr(string, find) : StrStrI(string, find));
- }
- mir_strcat(temp, string);
+ int F_type = type & 0xFF;
- return temp;
- }
+ if (F_type == F_SETNAME || F_type == F_SETVAL)
+ ListView_SetItemTextA(hwnd, index, 3, setting);
- return mir_tstrdup(value);
+ if (F_type == F_SETVAL && value)
+ ListView_SetItemText(hwnd, index, 4, value);
}
-int replaceValue(HWND hwnd, MCONTACT hContact, const char *module, const char *setting, DBVARIANT *dbv, const char *find, const char *replace, int mode)
-{
- int count = 0;
- DWORD num = 0;
- int isNumeric;
- char *myreplace = NULL;
- DBVARIANT val = { 0 };
-
- if (!dbv->type || dbv->type == DBVT_BLOB)
- return 0;
- if (!replace[0])
- isNumeric = 1;
- else
- isNumeric = sscanf(replace, "%d", &num);
-
- val.type = dbv->type;
-
- switch (dbv->type) {
- case DBVT_UTF8:
- case DBVT_ASCIIZ:
- if (mode & RW_FULL)
- val.pszVal = (char*)replace;
- else {
- myreplace = multiReplace(dbv->pszVal, find, replace, mode & RW_CASE);
- val.pszVal = myreplace;
- }
- break;
-
- case DBVT_BYTE:
- if (isNumeric && num < 0x100)
- val.bVal = (BYTE)num;
- else
- return 0;
- break;
-
- case DBVT_WORD:
- if (isNumeric && num < 0x10000)
- val.wVal = (WORD)num;
- else
- return 0;
- break;
-
- case DBVT_DWORD:
- if (isNumeric)
- val.dVal = num;
- else
- return 0;
- break;
-
- default:
- return 0;
- }
-
- if ((!val.pszVal && !replace[0]) || (val.pszVal && !val.pszVal[0])) {
- ItemFound(hwnd, hContact, module, setting, NULL, FW_SETTINGNAME | FW_DELETED);
- db_unset(hContact, module, setting);
- mir_free(myreplace);
- return 1;
- }
-
- if (!db_set(hContact, module, setting, &val)) {
- count++;
- ItemFound(hwnd, hContact, module, setting, myreplace ? myreplace : (char*)replace, FW_SETTINGVALUE | FW_REPLACED);
+char* multiReplaceA(const char *value, const char *search, const char *replace, int cs)
+{
+ int slen = (int)mir_strlen(search);
+ int rlen = (int)mir_strlen(replace);
+ int vlen = (int)mir_strlen(value);
+ int ci = slen ? cs : 1; // on empty string strstr() returns full string while StrStrI() returns NULL
+ // let's try to calculate maximum length for result string
+ int newlen = (!slen) ? rlen + 1 : ( ( rlen <= slen ) ? vlen + 1 : vlen * rlen / slen + 1 );
+
+ char *head;
+ char *in = (char*)value;
+ char *out = (char*)mir_alloc(newlen * sizeof(char));
+ out[0] = 0;
+
+ while (head = ci ? strstr(in, search) : StrStrIA(in, search)) {
+ if (head != in)
+ mir_strncat(out, in, head - in + 1);
+ in = head + slen;
+ mir_strcat(out, replace);
}
-
- mir_free(myreplace);
-
- return count;
+
+ mir_strcat(out, in);
+ return out;
}
-int replaceSetting(HWND hwnd, MCONTACT hContact, const char *module, const char *setting, DBVARIANT *dbv, const char *find, const char *replace, int mode)
+WCHAR* multiReplaceW(const WCHAR *value, const WCHAR *search, const WCHAR *replace, int cs)
{
- char *szSetting;
- ptrA myreplace;
- int count = 0;
- DBVARIANT dbv2;
-
- if (!dbv->type) return 0;
-
- if (mode & RW_FULL)
- szSetting = (char*)replace;
- else {
- myreplace = multiReplace(setting, find, replace, mode & RW_CASE);
- szSetting = myreplace;
+ int slen = (int)mir_wstrlen(search);
+ int rlen = (int)mir_wstrlen(replace);
+ int vlen = (int)mir_wstrlen(value);
+ int ci = slen ? cs : 1; // on empty string strstr() returns full string while StrStrI() returns NULL
+ // let's try to calculate maximum length for result string
+ int newlen = (!slen) ? rlen + 1 : ( ( rlen <= slen ) ? vlen + 1 : vlen * rlen / slen + 1 );
+
+ WCHAR *head;
+ WCHAR *in = (WCHAR*)value;
+ WCHAR *out = (WCHAR*)mir_alloc(newlen * sizeof(WCHAR));
+ out[0] = 0;
+
+ while (head = ci ? wcsstr(in, search) : StrStrIW(in, search)) {
+ if (head != in)
+ mir_wstrncat(out, in, head - in + 1);
+ in = head + slen;
+ mir_wstrcat(out, replace);
}
-
- if (szSetting[0] == 0) {
- ItemFound(hwnd, hContact, module, setting, NULL, FW_SETTINGNAME | FW_DELETED);
- db_unset(hContact, module, setting);
- return 1;
- }
-
- // check & write
- if (GetSetting(hContact, module, myreplace, &dbv2)) {
- if (!db_set(hContact, module, szSetting, &dbv2)) {
- count++;
- db_unset(hContact, module, setting);
- ItemFound(hwnd, hContact, module, szSetting, NULL, FW_SETTINGNAME | FW_REPLACED);
- }
- }
- else db_free(&dbv2);
-
- mir_free(myreplace);
-
- return count;
+
+ mir_wstrcat(out, in);
+ return out;
}
-int replaceModule(HWND hwnd, MCONTACT hContact, const char *module, const char *find, const char *replace, int mode)
+int FindMatchA(const char *text, char *search, int options)
{
- ModuleSettingLL msll;
- ModSetLinkLinkItem *setting;
- char *myreplace = NULL;
- char *newModule;
- int count = 0;
-
- if (mode & RW_FULL)
- newModule = (char*)replace;
- else {
- myreplace = multiReplace(module, find, replace, mode & RW_CASE);
- newModule = myreplace;
- }
-
- if (newModule[0] == 0) {
- ItemFound(hwnd, hContact, module, NULL, NULL, FW_MODULE | FW_DELETED);
- deleteModule((char*)module, hContact, 1);
- replaceTreeItem(GetDlgItem(hwnd2mainWindow, IDC_MODULES), hContact, module, NULL);
- mir_free(myreplace);
+ if (!search[0] && (!(options & F_EXACT) || !text[0]))
return 1;
- }
-
- if (!IsModuleEmpty(hContact, newModule))
- return 0;
- if (EnumSettings(hContact, (char*)module, &msll)) {
- setting = msll.first;
-
- while (setting) {
- DBVARIANT dbv;
-
- if (!GetSetting(hContact, module, setting->name, &dbv)) {
- switch (dbv.type) {
- case DBVT_BYTE:
- db_set_b(hContact, newModule, setting->name, dbv.bVal);
- break;
- case DBVT_WORD:
- db_set_w(hContact, newModule, setting->name, dbv.wVal);
- break;
- case DBVT_DWORD:
- db_set_dw(hContact, newModule, setting->name, dbv.dVal);
- break;
- case DBVT_ASCIIZ:
- db_set_s(hContact, newModule, setting->name, dbv.pszVal);
- break;
- case DBVT_UTF8:
- db_set_utf(hContact, newModule, setting->name, dbv.pszVal);
- break;
- case DBVT_BLOB:
- db_set_blob(hContact, newModule, setting->name, dbv.pbVal, dbv.cpbVal);
- break;
- }
+ if (options & F_EXACT)
+ return (options & F_CASE) ? !strcmp(text, search) : !stricmp(text, search);
+
+ // on empty string strstr() returns full string while StrStrI() returns NULL
+ return (options & F_CASE) ? (int)strstr(text, search) : (int)StrStrIA(text, search);
+}
- db_free(&dbv);
- db_unset(hContact, module, setting->name);
- }
- setting = setting->next;
- }
- FreeModuleSettingLL(&msll);
-
- replaceTreeItem(GetDlgItem(hwnd2mainWindow, IDC_MODULES), hContact, module, newModule);
+int FindMatchW(const WCHAR *text, WCHAR *search, int options)
+{
+ if (!search[0] && (!(options & F_EXACT) || !text[0]))
+ return 1;
- ItemFound(hwnd, hContact, newModule, NULL, NULL, FW_MODULE | FW_REPLACED);
- count++;
- }
+ if (options & F_EXACT)
+ return (options & F_CASE) ? !wcscmp(text, search) : !wcsicmp(text, search);
- mir_free(myreplace);
- return count;
+ // on empty string strstr() returns full string while StrStrI() returns NULL
+ return (options & F_CASE) ? (int)wcsstr(text, search) : (int)StrStrIW(text, search);
}
-char* stringToUpper(char* in, char* out, int maxlen)
-{
- int len;
- if (maxlen > 0)
- len = maxlen - 1;
- else
- len = 0x10000;
- int i;
- for (i = 0; in[i] && i < len; i++)
- out[i] = (in[i] >= 'a' && in[i] <= 'z') ? toupper(in[i]) : in[i];
- out[i] = '\0';
- return out;
+void fi_free(FindInfo* fi)
+{
+ mir_free(fi->search);
+ mir_free(fi->replace);
+ mir_free(fi);
}
-void __cdecl FindSettings(LPVOID di)
+void __cdecl FindSettings(LPVOID param)
{
- char* text = ((FindInfo*)di)->text;
- char* replace = ((FindInfo*)di)->replace;
- int mode = ((FindInfo*)di)->mode;
- HWND hwnd = ((FindInfo*)di)->hwnd;
- HWND prnthwnd = GetParent(hwnd);
- int options = ((FindInfo*)di)->options;
+ FindInfo* fi = (FindInfo*)param;
+ HWND hwndParent = GetParent(fi->hwnd);
+
ModuleSettingLL ModuleList, SettingList;
ModSetLinkLinkItem *module, *setting;
+
MCONTACT hContact;
DBVARIANT dbv = { 0 };
- int caseSensitive = options & FW_CASE;
- int exactMatch = options & FW_EXACT;
- int inModuleName = options & FW_MODNAME;
- int inSettingName = options & FW_SETNAME;
- int inSettingValue = options & FW_SETVAL;
- int foundCount = 0;
- int replaceCount = 0;
- char szTmp[128];
- int settingValue, isNumber, NULLContactDone = 0;
-
- freeItems(hwnd);
- if (!text)
- return;
- if (!EnumModules(&ModuleList)) {
- msg(Translate("Error loading module list"), modFullname);
- mir_free(di);
+ int foundCount = 0, replaceCount = 0, deleteCount = 0;
+
+ DWORD numsearch = 0, numreplace = 0;
+ int NULLContactDone = 0;
+
+ if (!fi->search || !EnumModules(&ModuleList)) {
+ fi_free(fi);
return;
}
- SendDlgItemMessage(GetParent(hwnd), IDC_SBAR, SB_SETTEXT, 0, (LPARAM)Translate("Searching..."));
+ _T2A search(fi->search);
+ _T2A replace(fi->replace);
+
+ // skip modules and setting names on unicode search or replace
+ if (IsRealUnicode(fi->search) || IsRealUnicode(fi->replace)) {
+ fi->options &= ~(F_SETNAME | F_MODNAME);
+ fi->options |= F_UNICODE;
+ }
+
+ if (!(fi->options & F_UNICODE) && (fi->options & F_SETVAL)) {
+ char val[16];
+ numsearch = strtoul(search, NULL, 10);
+ _ultoa(numsearch, val, 10);
+ if (!mir_strcmp(search, val)) {
+ fi->options |= F_NUMSRCH;
+ // replace numeric values only entirely
+ if (replace && (fi->options & F_ENTIRE)) {
+ numreplace = strtoul(replace, NULL, 10);
+ _ultoa(numreplace, val, 10);
+ if (!replace[0] || !mir_strcmp(replace, val))
+ fi->options |= F_NUMREPL;
+ }
+ }
+ }
+
+ SendDlgItemMessage(hwndParent, IDC_SBAR, SB_SETTEXT, 0, (LPARAM)TranslateT("Searching..."));
hContact = 0;
- isNumber = sscanf(text, "%d", &settingValue);
+ while (GetWindowLongPtr(GetDlgItem(hwndParent, IDC_SEARCH), GWLP_USERDATA)) {
- while (GetWindowLongPtr(GetDlgItem(prnthwnd, IDC_SEARCH), GWLP_USERDATA)) {
if (!hContact) {
- if (NULLContactDone) break;
+ if (NULLContactDone)
+ break;
else {
NULLContactDone = 1;
hContact = db_find_first();
}
}
- else hContact = db_find_next(hContact);
+ else
+ hContact = db_find_next(hContact);
+
+ for (module = ModuleList.first; module; module = module->next) {
- module = ModuleList.first;
- while (module) {
- if (IsModuleEmpty(hContact, module->name)) {
- module = module->next;
+ if (IsModuleEmpty(hContact, module->name))
continue;
- }
- if (!EnumSettings(hContact, module->name, &SettingList)) {
- msg(Translate("Error Loading Setting List"), modFullname);
- mir_free(text);
- mir_free(di);
- FreeModuleSettingLL(&ModuleList);
- return;
- }
- setting = SettingList.first;
+ if (fi->options & (F_SETVAL | F_SETNAME)) {
+
+ if (!EnumSettings(hContact, module->name, &SettingList)) {
+ fi_free(fi);
+ FreeModuleSettingLL(&ModuleList);
+ return;
+ }
+
+ for (setting = SettingList.first; setting; setting = setting->next) {
- // check in settings value
- while (setting) {
- if (inSettingValue) {
dbv.type = 0;
- // check the setting value
- if (!GetSetting(hContact, module->name, setting->name, &dbv)) {
- switch (dbv.type) {
- case DBVT_UTF8: // no conversion atm
- case DBVT_ASCIIZ:
- if ((exactMatch && !(caseSensitive ? mir_strcmp(dbv.pszVal, text) : strcmpi(dbv.pszVal, text))) || (!exactMatch && (caseSensitive ? strstr(dbv.pszVal, text) : StrStrI(dbv.pszVal, text)))) {
- if ((mode & RW_FOUND) || (mode & RW_SETVAL))
- replaceCount += replaceValue(hwnd, hContact, module->name, setting->name, &dbv, text, replace, mode);
- else
- ItemFound(hwnd, hContact, module->name, setting->name, dbv.pszVal, FW_SETTINGVALUE);
+ if (db_get_s(hContact, module->name, setting->name, &dbv, 0))
+ continue;
- foundCount++;
- }
- break;
+ // check in settings value
+ if (fi->options & F_SETVAL) {
- case DBVT_BYTE:
- if (isNumber && settingValue == dbv.bVal) {
- if ((mode & RW_FOUND) || (mode & RW_SETVAL))
- replaceCount += replaceValue(hwnd, hContact, module->name, setting->name, &dbv, NULL, replace, mode);
- else
- ItemFound(hwnd, hContact, module->name, setting->name, text, FW_SETTINGVALUE);
- foundCount++;
- }
- break;
+ TCHAR *value = NULL;
- case DBVT_WORD:
- if (isNumber && settingValue == dbv.wVal) {
- if ((mode & RW_FOUND) || (mode & RW_SETVAL))
- replaceCount += replaceValue(hwnd, hContact, module->name, setting->name, &dbv, NULL, replace, mode);
- else
- ItemFound(hwnd, hContact, module->name, setting->name, text, FW_SETTINGVALUE);
- foundCount++;
+ switch(dbv.type) {
+
+ case DBVT_BYTE:
+ case DBVT_WORD:
+ case DBVT_DWORD:
+ if ((fi->options & F_NUMSRCH) && numsearch == getNumericValue(&dbv)) {
+ TCHAR *val = fi->search;
+ int flag = F_SETVAL;
+
+ if (fi->options & F_NUMREPL) {
+ if (replace[0]) {
+ db_unset(hContact, module->name, setting->name);
+ flag |= F_DELETED;
+ deleteCount++;
+ }
+ else
+ if (setNumericValue(hContact, module->name, setting->name, numreplace, dbv.type)) {
+ val = fi->replace;
+ flag |= F_REPLACED;
+ replaceCount++;
+ }
+ }
+
+ ItemFound(fi->hwnd, hContact, module->name, setting->name, val, flag);
}
break;
- case DBVT_DWORD:
- if (isNumber && settingValue == (int)dbv.dVal) {
- if ((mode & RW_FOUND) || (mode & RW_SETVAL))
- replaceCount += replaceValue(hwnd, hContact, module->name, setting->name, &dbv, NULL, replace, mode);
- else
- ItemFound(hwnd, hContact, module->name, setting->name, text, FW_SETTINGVALUE);
+ case DBVT_WCHAR:
+ if (!value) value = mir_u2t(dbv.pwszVal);
+ case DBVT_UTF8:
+ if (!value) value = mir_utf8decodeT(dbv.pszVal);
+ case DBVT_ASCIIZ:
+ if (!value) value = mir_a2t(dbv.pszVal);
+
+ if (FindMatchT(value, fi->search, fi->options)) {
foundCount++;
+ ptrT ptr;
+ TCHAR *newValue = value;
+ int flag = F_SETVAL;
+
+ if (fi->replace) {
+ newValue = (fi->options & F_ENTIRE) ? fi->replace : ptr = multiReplaceT(value, fi->search, fi->replace, fi->options & F_CASE);
+ // !!!! delete or make empty ?
+ if (!newValue[0]) {
+ db_unset(hContact, module->name, setting->name);
+ flag |= F_DELETED;
+ newValue = value;
+ deleteCount++;
+ } else {
+#ifdef _UNICODE
+ // save as unicode if needed
+ if (dbv.type != DBVT_ASCIIZ || IsRealUnicode(newValue))
+ db_set_ws(hContact, module->name, setting->name, newValue);
+ else
+#endif
+ db_set_s(hContact, module->name, setting->name, _T2A(newValue));
+ flag |= F_REPLACED;
+ replaceCount++;
+ }
+ }
+
+ ItemFound(fi->hwnd, hContact, module->name, setting->name, newValue, flag);
}
+ mir_free(value);
break;
-
- }
- db_free(&dbv);
+ } // switch
}
- }
- // check in setting name
- if (inSettingName) {
- if ((exactMatch && !(caseSensitive ? mir_strcmp(setting->name, text) : strcmpi(setting->name, text))) || (!exactMatch && (caseSensitive ? StrStrI(setting->name, text) : StrStrI(setting->name, text)))) {
- if ((mode & RW_FOUND) || (mode & RW_SETNAME)) {
- if (!GetSetting(hContact, module->name, setting->name, &dbv)) {
- replaceCount += replaceSetting(hwnd, hContact, module->name, setting->name, &dbv, text, replace, mode);
- db_free(&dbv);
+ // check in setting name
+ if ((fi->options & F_SETNAME) && FindMatchA(setting->name, search, fi->options)) {
+ foundCount++;
+ ptrA ptr;
+ char *newSetting = setting->name;
+ int flag = F_SETNAME;
+
+ if (replace) {
+ newSetting = (fi->options & F_ENTIRE) ? replace : ptr = multiReplaceA(setting->name, search, replace, fi->options & F_CASE);
+
+ if (!newSetting[0]) {
+ db_unset(hContact, module->name, setting->name);
+ flag |= F_DELETED;
+ newSetting = setting->name;
+ deleteCount++;
+ } else {
+ DBVARIANT dbv2;
+ // skip if exist
+ if (!db_get_s(hContact, module->name, newSetting, &dbv2, 0))
+ db_free(&dbv2);
+ else if (!db_set(hContact, module->name, newSetting, &dbv)) {
+ db_unset(hContact, module->name, setting->name);
+ flag |= F_REPLACED;
+ replaceCount++;
+ }
}
}
- else
- ItemFound(hwnd, hContact, module->name, setting->name, NULL, FW_SETTINGNAME);
- foundCount++;
+
+ ItemFound(fi->hwnd, hContact, module->name, newSetting, NULL, flag);
}
- }
- setting = (ModSetLinkLinkItem *)setting->next;
+ db_free(&dbv);
+
+ } // for(setting)
+
+ FreeModuleSettingLL(&SettingList);
}
// check in module name
- if (inModuleName) {
- if ((exactMatch && !(caseSensitive ? mir_strcmp(module->name, text) : strcmpi(module->name, text))) || (!exactMatch && (caseSensitive ? strstr(module->name, text) : StrStrI(module->name, text)))) {
- if ((mode & RW_FOUND) || (mode & RW_MODULE))
- replaceCount += replaceModule(hwnd, hContact, module->name, text, replace, mode);
- else
- ItemFound(hwnd, hContact, module->name, 0, 0, FW_MODULE);
- foundCount++;
+ if ((fi->options & F_MODNAME) && FindMatchA(module->name, search, fi->options)) {
+ foundCount++;
+ char *newModule = module->name;
+ int flag = F_MODNAME;
+ ptrA ptr;
+
+ if (replace) {
+ newModule = (fi->options & F_ENTIRE) ? replace : ptr = multiReplaceA(module->name, search, replace, fi->options & F_CASE);
+
+ if (!newModule[0]) {
+ deleteModule(hContact, module->name, 0);
+ replaceTreeItem(hContact, module->name, NULL);
+ flag |= F_DELETED;
+ newModule = module->name;
+ deleteCount++;
+ }
+ else if (renameModule(hContact, module->name, newModule)) {
+ replaceTreeItem(hContact, module->name, NULL);
+ flag |= F_REPLACED;
+ replaceCount++;
+ }
}
- }
- FreeModuleSettingLL(&SettingList);
- module = (ModSetLinkLinkItem *)module->next;
- }
- }
+ ItemFound(fi->hwnd, hContact, newModule, 0, 0, flag);
+ }
- if (mode) {
- if (!replace[0])
- mir_snprintf(szTmp, Translate("Finished. %d items were found, %d items were deleted."), foundCount, replaceCount);
- else
- mir_snprintf(szTmp, Translate("Finished. %d items were found, %d items were replaced."), foundCount, replaceCount);
+ } // for(module)
}
- else mir_snprintf(szTmp, Translate("Finished. %d items were found."), foundCount);
-
- SendDlgItemMessage(prnthwnd, IDC_SBAR, SB_SETTEXT, 0, (LPARAM)szTmp);
- SetWindowLongPtr(GetDlgItem(prnthwnd, IDC_SEARCH), GWLP_USERDATA, 0);
+ TCHAR msg[MSG_SIZE];
+ mir_sntprintf(msg, TranslateT("Finished. Items found: %d / replaced: %d / deleted: %d"), foundCount, replaceCount, deleteCount);
+ SendDlgItemMessage(hwndParent, IDC_SBAR, SB_SETTEXT, 0, (LPARAM)msg);
- if (GetWindowLongPtr(GetDlgItem(prnthwnd, IDC_REPLACE), GWLP_USERDATA)) {
- SetWindowLongPtr(GetDlgItem(prnthwnd, IDC_REPLACE), GWLP_USERDATA, 0);
- EnableWindow(GetDlgItem(prnthwnd, IDC_SEARCH), 1);
- SetDlgItemText(prnthwnd, IDOK, Translate("&Replace"));
+ if (fi->replace) {
+ EnableWindow(GetDlgItem(hwndParent, IDC_SEARCH), 1);
+ SetDlgItemText(hwndParent, IDOK, TranslateT("&Replace"));
}
else {
- SetDlgItemText(prnthwnd, IDC_SEARCH, Translate("&Search"));
- EnableWindow(GetDlgItem(prnthwnd, IDOK), 1);
+ SetDlgItemText(hwndParent, IDC_SEARCH, TranslateT("&Search"));
+ EnableWindow(GetDlgItem(hwndParent, IDOK), 1);
}
- mir_free(replace);
- mir_free(text);
- mir_free(di);
+ fi_free(fi);
FreeModuleSettingLL(&ModuleList);
- EnableWindow(GetDlgItem(prnthwnd, IDCANCEL), 1);
+ SetWindowLongPtr(GetDlgItem(hwndParent, IDC_SEARCH), GWLP_USERDATA, 0);
+ EnableWindow(GetDlgItem(hwndParent, IDCANCEL), 1);
}
diff --git a/plugins/DbEditorPP/src/headers.h b/plugins/DbEditorPP/src/headers.h
index 425f14ec61..3f8c5b6c1a 100644
--- a/plugins/DbEditorPP/src/headers.h
+++ b/plugins/DbEditorPP/src/headers.h
@@ -39,98 +39,70 @@
#include <m_icolib.h>
#include <m_hotkeys.h>
#include <m_string.h>
+#include <m_metacontacts.h>
#include "m_toptoolbar.h"
#include "resource.h"
#include "Version.h"
-#include "modsettingenum.h"
-#define DEF_ICON 5
-#define crlf_string "\r\n\0"
-
-/////// icons support
-
-void addIcons();
-HICON LoadSkinnedDBEIcon(int icon);
-int AddIconToList(HIMAGELIST hil, HICON hIcon);
-void AddProtoIconsToList(HIMAGELIST hil, int newshift);
-int GetProtoIcon(char *szProto);
-extern MCONTACT hRestore;
-/////////////////////
-
-#ifndef NDEBUG
-#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
-#endif
//=======================================================
// Definitions
//=======================================================
#define modname "DBEditorpp"
#define modFullname "Database Editor++"
-#define msg(a,b) MessageBoxA(0,a,b,MB_OK)
-#define nick_unknown "(UNKNOWN)"
-#define nick_unknownW L"(UNKNOWN)"
+#define msg(a) MessageBox(hwnd2mainWindow,a,_A2T(modFullname),MB_OK)
+#define dlg(a,b) MessageBox(hwnd2mainWindow,a,_A2T(modFullname),b)
-#define WM_FINDITEM (WM_USER + 1) // onyl for the main window, wparam is ItemIfno* lparam is 0
-
-#define mir_strlen(ptr) ((ptr == NULL) ? 0 : (int)mir_strlen(ptr))
-#define mir_strncpy(dst, src, len) strncpy(dst, src, len)[len - 1] = 0;
-#define mir_strcmp(ptr1, ptr2) ((ptr1 && ptr2) ? mir_strcmp(ptr1, ptr2) : 1) // (ptr1||ptr2)
-
-#define ListView_SetItemTextW(hwndLV, i, iSubItem_, pszText_) \
-{ LV_ITEMW _ms_lvi;\
- _ms_lvi.iSubItem = iSubItem_;\
- _ms_lvi.pszText = pszText_;\
- SendMessageW((hwndLV), LVM_SETITEMTEXTW, (WPARAM)(i), (LPARAM)(LV_ITEMW *)&_ms_lvi);\
-}
-
-#define ListView_InsertItemW(hwnd, pitem) \
- SendMessageW((hwnd), LVM_INSERTITEMW, 0, (LPARAM)(const LV_ITEMW *)(pitem))
+#define FLD_SIZE 256
+#define MSG_SIZE 256
+#define NAME_SIZE 128
+#define WM_FINDITEM (WM_USER + 1) // onyl for the main window, wparam is ItemIfno* lparam is 0
-#define TreeView_InsertItemW(hwnd, lpis) \
- (HTREEITEM)SendMessageW((hwnd), TVM_INSERTITEMW, 0, (LPARAM)(LPTV_INSERTSTRUCTW)(lpis))
/***********************
ModuleTreeInfoStruct
this gets dumped as the lparam for each module tree item
************************/
+
// types
#define CONTACT_ROOT_ITEM 0
-#define CONTACT 1
-#define MODULE 0x2
-#define KNOWN_MODULE 2
-#define STUB 4
-#define EMPTY 8
+#define CONTACT 1
+#define MODULE 2
+#define STUB 4
+#define EMPTY 8
-typedef struct {
+
+struct ModuleTreeInfoStruct {
int type; // from above types
MCONTACT hContact;
-} ModuleTreeInfoStruct;
+};
-typedef struct {
+
+struct SettingListInfo {
MCONTACT hContact;
- char *module;
- HWND hwnd2Edit;
int selectedItem; // item that is currently selected
- int clicks; // set to 0 when selection changes, 1 after another click.. cant edit till this is 1
-} SettingListInfo;
+ char module[FLD_SIZE];
+ // for edit
+ HWND hwnd2Edit;
+ char setting[FLD_SIZE];
+ int subitem;
+};
-#define WATCH_MODULE 1
-#define WATCH_SETTING 0
struct DBsetting {
- DBVARIANT dbv;
MCONTACT hContact;
char *module;
char *setting;
- int WatchModule; // above defines
+ DBVARIANT dbv;
};
+
typedef struct {
- char module[256];
+ char module[FLD_SIZE];
MCONTACT hContact;
} ModuleAndContact;
@@ -142,31 +114,79 @@ typedef struct {
typedef struct {
int type; // above types
MCONTACT hContact;
- char module[256];
- char setting[256];
+ char module[FLD_SIZE];
+ char setting[FLD_SIZE];
} ItemInfo;
// watchwindow
-struct WatchListArrayStruct{
+struct WatchListArrayStruct {
struct DBsetting *item; // gotta malloc this
int count;
int size;
};
-extern WatchListArrayStruct WatchListArray;
+
+// module setting enum
+struct ModSetLinkLinkItem
+{
+ char *name;
+ ModSetLinkLinkItem *next;
+};
+
+struct ModuleSettingLL
+{
+ ModSetLinkLinkItem *first;
+ ModSetLinkLinkItem *last;
+};
+
+struct ColumnsSettings {
+ TCHAR *name;
+ int index;
+ char *dbname;
+ int defsize;
+};
+
+struct ColumnsSortParams {
+ HWND hList;
+ int column;
+ int last;
+};
+
+
+enum ICONS {
+ IMAGE_EMPTY,
+ IMAGE_BINARY,
+ IMAGE_BYTE,
+ IMAGE_WORD,
+ IMAGE_DWORD,
+ IMAGE_STRING,
+ IMAGE_UNICODE,
+ IMAGE_HANDLE,
+ IMAGE_SETTINGS,
+ IMAGE_CLOSED,
+ IMAGE_OPENED,
+ IMAGE_CONTACTS,
+ IMAGE_ONLINE,
+ IMAGE_OFFLINE
+};
+
//=======================================================
// Variables
//=======================================================
extern HINSTANCE hInst;
-extern HWND hwnd2mainWindow, hwnd2watchedVarsWindow, hwnd2importWindow;
-extern HIMAGELIST himl;
-extern HIMAGELIST himl2;
-extern int Mode;
-extern int Hex;
-extern int Order;
+
+extern HWND hwnd2mainWindow;
+
+extern int g_Mode;
+extern int g_Hex;
+extern int g_Order;
+extern int g_Inline;
+
+extern MCONTACT hRestore;
extern MIDatabase *g_db;
+extern BOOL bServiceMode;
extern BOOL usePopups;
#define NAMEORDERCOUNT 8
@@ -179,68 +199,104 @@ extern BOOL usePopups;
#define HEX_WORD 2
#define HEX_DWORD 4
-//main.c
-int DBGetContactSettingStringStatic(MCONTACT hContact, char *szModule, char *szSetting, char *value, int maxLength);
-int WriteBlobFromString(MCONTACT hContact, const char *szModule, const char *szSetting, const char *Value, int len);
-int GetSetting(MCONTACT hContact, const char *szModule, const char *szSetting, DBVARIANT *dbv);
-int GetValue(MCONTACT hContact, const char *szModule, const char *szSetting, char *Value, int length);
-int GetValueW(MCONTACT hContact, const char *szModule, const char *szSetting, WCHAR *Value, int length);
-char *u2a(wchar_t *src);
-wchar_t *a2u(char *src, wchar_t *buffer, int len);
-WCHAR *GetContactName(MCONTACT hContact, const char *szProto, int unicode);
-BOOL IsProtocolLoaded(char *pszProtocolName);
-
-// main_window.c
-INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
-
-// modules.c
-int deleteModule(char *module, MCONTACT hContact, int fromMenu);
-void deleteModuleGui();
-void renameModule(char *oldName, char *newName, MCONTACT hContact);
-INT_PTR CALLBACK AddModDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
-int CloneContact(MCONTACT hContact);
+#ifdef _UNICODE
+ #define GetValue(a,b,c,d,e) GetValueW(a,b,c,d,e)
+#else
+ #define GetValue(a,b,c,d,e) GetValueA(a,b,c,d,e)
+#endif
-// moduletree.c
-void replaceTreeItem(HWND hwnd, MCONTACT hContact, const char *module, const char *newModule);
+//main
+char *StringFromBlob(BYTE *blob, WORD len);
+int WriteBlobFromString(MCONTACT hContact, const char *module, const char *setting, const char *value, int len);
+TCHAR *DBVType(BYTE type);
+DWORD getNumericValue(DBVARIANT *dbv);
+int setNumericValue(MCONTACT hContact, const char *module, const char *setting, DWORD value, int type);
+int IsRealUnicode(TCHAR *value);
+int setTextValue(MCONTACT hContact, const char *module, const char *setting, TCHAR *value, int type);
+int GetValueA(MCONTACT hContact, const char *module, const char *setting, char *value, int length);
+int GetValueW(MCONTACT hContact, const char *module, const char *setting, WCHAR *value, int length);
+int GetContactName(MCONTACT hContact, const char *proto, TCHAR *value, int maxlen);
+int ApplyProtoFilter(MCONTACT hContact);
+void loadListSettings(HWND hwnd, ColumnsSettings *cs);
+void saveListSettings(HWND hwnd, ColumnsSettings *cs);
+INT_PTR CALLBACK ColumnsCompare(LPARAM lParam1, LPARAM lParam2, LPARAM myParam);
+
+// main_window
+void openMainWindow();
+
+// deletemodules
+int deleteModule(MCONTACT hContact, const char *module, int confirm);
+void deleteModuleDlg();
+
+// renamemodule
+int renameModule(MCONTACT hContact, const char *oldName, const char *newName);
+void renameModuleDlg();
+void addModuleDlg(MCONTACT hContact);
+
+// moduletree
+void insertItem(MCONTACT hContact, const char *module, HTREEITEM hParent);
+HTREEITEM findItemInTree(MCONTACT hContact, const char *module);
+void replaceTreeItem(MCONTACT hContact, const char *module, const char *newModule);
void refreshTree(BOOL restore);
-void __cdecl PopulateModuleTreeThreadFunc(LPVOID di);
-void freeTree(HWND hwnd2Tree, MCONTACT hContact);
-int findItemInTree(HWND hwnd2Tree, MCONTACT hContact, char *module);
-
-// settinglist.c
-void setupSettingsList(HWND hwnd2List);
-void saveListSettings(HWND hwnd2List);
-void ClearListview(HWND hwnd2Settings);
-void DeleteSettingsFromList(HWND hSettings, MCONTACT hContact, char *module, char *setting);
-void PopulateSettings(HWND hwnd2Settings, MCONTACT hContact, char *module);
-void SelectSetting(char *setting);
-
-// addeditsettingsdlg.c
-INT_PTR CALLBACK EditSettingDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
-void editSetting(MCONTACT hContact, char *module, char *setting);
-BOOL convertSetting(MCONTACT hContact, char *module, char *setting, int toType); // 0 = byte, 1 = word, 2 = dword, 3 = string
-
-// exportimport.c
-void exportDB(MCONTACT hContact, char *module); // hContact == -1 export entire db. module == NULL export entire contact
+void freeTree(MCONTACT hContact);
+
+// settinglist
+int ListView_GetItemTextA(HWND hwndLV, int i, int iSubItem, char *pszText, int cchTextMax);
+int ListView_SetItemTextA(HWND hwndLV, int i, int iSubItem, const char *pszText);
+void ClearListView();
+void DeleteSettingsFromList(MCONTACT hContact, const char *module, const char *setting);
+void addListHandle(MCONTACT hContact);
+void PopulateSettings(MCONTACT hContact, const char *module);
+void SelectSetting(const char *setting);
+void settingChanged(MCONTACT hContact, const char *module, const char *setting, DBVARIANT *dbv);
+
+// settingsdlg
+void editSetting(MCONTACT hContact, const char *module, const char *setting);
+void copySetting(MCONTACT hContact, const char *module, const char *setting);
+void newSetting(MCONTACT hContact, const char *module, int type);
+
+// exportimport
+void exportDB(MCONTACT hContact, const char *module); // hContact == -1 export entire db. module == NULL export entire contact
void ImportSettingsMenuItem(MCONTACT hContact);
-void ImportSettingsFromFileMenuItem(MCONTACT hContact, char *FilePath);
+void ImportSettingsFromFileMenuItem(MCONTACT hContact, const char *filePath); // ansi!
-// find window.c
-INT_PTR CALLBACK FindWindowDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
+// find window
+void newFindWindow();
-// copymodule.c
-void copyModuleMenuItem(char *module, MCONTACT hContact);
-void copyModule(char *module, MCONTACT hContactFrom, MCONTACT hContactTo);
+// copymodule
+void copyModuleMenuItem(MCONTACT hContact, const char *module);
+void copyModule(const char *module, MCONTACT hContactFrom, MCONTACT hContactTo);
+int CloneContact(MCONTACT hContact);
-// options.c
+// options
int OptInit(WPARAM wParam, LPARAM lParam);
-// watchlist
-int addSettingToWatchList(MCONTACT hContact, char *module, char *setting);
+// watchedvars
+int WatchedArrayIndex(MCONTACT hContact, const char *module, const char *setting, int strict);
+int addSettingToWatchList(MCONTACT hContact, const char *module, const char *setting);
void freeWatchListItem(int item);
-void PopulateWatchedWindow(HWND hwnd);
+void PopulateWatchedWindow();
void freeAllWatches();
-INT_PTR CALLBACK WatchDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
+void openWatchedVarWindow();
void popupWatchedVar(MCONTACT hContact, const char *module, const char *setting);
+// modsettingenum
+int EnumModules(ModuleSettingLL *msll);
+int EnumSettings(MCONTACT hContact, const char *module, ModuleSettingLL *msll);
+void FreeModuleSettingLL(ModuleSettingLL *msll);
+int IsModuleEmpty(MCONTACT hContact, const char *module);
+int LoadResidentSettings();
+void FreeResidentSettings();
+int IsResidentSetting(const char *module, const char *setting);
+int EnumResidentSettings(const char *module, ModuleSettingLL *msll);
+int EnumResidentModules(ModuleSettingLL *msll);
+int fixResidentSettings();
+
+// icons
+HANDLE GetIcoLibHandle(int icon);
+void IcoLibRegister();
+HICON LoadSkinnedDBEIcon(int icon);
+HIMAGELIST LoadIcons();
+int GetProtoIconIndex(const char *proto);
+
#endif //_COMMONHEADERS_H
diff --git a/plugins/DbEditorPP/src/icons.cpp b/plugins/DbEditorPP/src/icons.cpp
index 48d0f079fa..9492738125 100644
--- a/plugins/DbEditorPP/src/icons.cpp
+++ b/plugins/DbEditorPP/src/icons.cpp
@@ -1,27 +1,54 @@
#include "headers.h"
-HIMAGELIST himl;
+
+int dbeIcons[] = {
+ ICO_EMPTY,
+ ICO_BINARY,
+ ICO_BYTE,
+ ICO_WORD,
+ ICO_DWORD,
+ ICO_STRING,
+ ICO_UNICODE,
+ ICO_HANDLE,
+ ICO_SETTINGS,
+ ICO_CLOSED,
+ ICO_OPENED,
+ ICO_CONTACTS,
+ ICO_ONLINE,
+ ICO_OFFLINE
+};
+
IconItem iconList[] = {
- { LPGENT("Main icon"), "DBE++_0", ICO_DBE_BUTT },
- { LPGENT("Closed known module"), "DBE++_1", ICO_KNOWN },
- { LPGENT("Open known module"), "DBE++_2", ICO_KNOWNOPEN },
- { LPGENT("Settings"), "DBE++_5", ICO_SETTINGS },
- { LPGENT("Contacts group"), "DBE++_6", ICO_CONTACTS },
- { LPGENT("Unknown contact"), "DBE++_7", ICO_OFFLINE },
- { LPGENT("Known contact"), "DBE++_8", ICO_ONLINE },
- { LPGENT("Open user tree"), "DBE++_9", ICO_REGUSER },
-
- { LPGENT("BLOB setting"), "DBE++_BINARY", ICO_BINARY },
- { LPGENT("Byte setting"), "DBE++_BYTE", ICO_BYTE },
- { LPGENT("Word setting"), "DBE++_WORD", ICO_WORD },
- { LPGENT("Dword setting"), "DBE++_DWORD", ICO_DWORD },
- { LPGENT("String setting"), "DBE++_STRING", ICO_STRING },
- { LPGENT("Unicode setting"), "DBE++_UNICODE", ICO_UNICODE },
- { LPGENT("Handle"), "DBE++_HANDLE", ICO_HANDLE }
+ { LPGEN("Main icon"), "DBE++_0", ICO_DBE_BUTT },
+ { LPGEN("Closed module"), "DBE++_1", ICO_CLOSED },
+ { LPGEN("Open module"), "DBE++_2", ICO_OPENED },
+ { LPGEN("Settings"), "DBE++_5", ICO_SETTINGS },
+ { LPGEN("Contacts group"), "DBE++_6", ICO_CONTACTS },
+ { LPGEN("Unknown contact"), "DBE++_7", ICO_OFFLINE },
+ { LPGEN("Known contact"), "DBE++_8", ICO_ONLINE },
+ { LPGEN("Open user tree"), "DBE++_9", ICO_REGUSER },
+ { LPGEN("Empty setting"), "DBE++10", ICO_EMPTY },
+ { LPGEN("BLOB setting"), "DBE++_BINARY", ICO_BINARY },
+ { LPGEN("Byte setting"), "DBE++_BYTE", ICO_BYTE },
+ { LPGEN("Word setting"), "DBE++_WORD", ICO_WORD },
+ { LPGEN("Dword setting"), "DBE++_DWORD", ICO_DWORD },
+ { LPGEN("String setting"), "DBE++_STRING", ICO_STRING },
+ { LPGEN("Unicode setting"), "DBE++_UNICODE", ICO_UNICODE },
+ { LPGEN("Handle"), "DBE++_HANDLE", ICO_HANDLE }
};
-void addIcons(void)
+
+
+HANDLE GetIcoLibHandle(int icon)
+{
+ for (int i = 0; i < SIZEOF(iconList); i++)
+ if (iconList[i].defIconID == icon)
+ return iconList[i].hIcolib;
+ return INVALID_HANDLE_VALUE;
+}
+
+void IcoLibRegister(void)
{
Icon_Register(hInst, modFullname, iconList, SIZEOF(iconList));
}
@@ -35,57 +62,46 @@ HICON LoadSkinnedDBEIcon(int icon)
return LoadIcon(hInst, MAKEINTRESOURCE(icon));
}
-int AddIconToList(HIMAGELIST hil, HICON hIcon)
-{
- if (!hIcon || !hil)
- return 0;
-
- ImageList_AddIcon(hil, hIcon);
- return 1;
-}
-
static PROTOACCOUNT **protocols = NULL;
static int protoCount = 0;
-static int shift = 0;
-void AddProtoIconsToList(HIMAGELIST hil, int newshift)
+HIMAGELIST LoadIcons()
{
- shift = newshift;
+ HICON hIcon;
+ HIMAGELIST hil = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, SIZEOF(dbeIcons), 5);
+
+ if (!hil) return NULL;
+
+ for(int i = 0; i < SIZEOF(dbeIcons); i++)
+ ImageList_AddIcon(hil, LoadSkinnedDBEIcon(dbeIcons[i]));
ProtoEnumAccounts(&protoCount, &protocols);
for (int i = 0; i < protoCount; i++) {
- HICON hIcon;
+ if (!Proto_IsProtocolLoaded(protocols[i]->szModuleName))
+ ImageList_AddIcon(hil, LoadSkinnedDBEIcon(ICO_OFFLINE));
+ else
if (hIcon = Skin_LoadProtoIcon(protocols[i]->szModuleName, ID_STATUS_ONLINE))
- AddIconToList(hil, hIcon);
+ ImageList_AddIcon(hil, hIcon);
else
- AddIconToList(himl, LoadSkinnedDBEIcon(ICO_ONLINE));
- }
-}
-
-int GetProtoIcon(char *szProto)
-{
- if (!protoCount || !protocols || !szProto)
- return DEF_ICON;
-
- int n = 0;
-
- for (int i = 0; i < protoCount; i++) {
- if (!mir_strcmp(protocols[i]->szModuleName, szProto))
- return n + shift;
-
- n++;
+ ImageList_AddIcon(hil, LoadSkinnedDBEIcon(ICO_ONLINE));
}
- return DEF_ICON;
+ return hil;
}
-BOOL IsProtocolLoaded(char *pszProtocolName)
-{
- if (protoCount)
- for (int i = 0; i < protoCount; i++)
- if (!mir_strcmp(protocols[i]->szModuleName, pszProtocolName))
- return TRUE;
- return FALSE;
+int GetProtoIconIndex(const char *szProto)
+{
+ if (szProto && szProto[0]) {
+ if (protoCount && protocols) {
+ for (int i = 0; i < protoCount; i++) {
+ if (!mir_strcmp(protocols[i]->szModuleName, szProto))
+ return i + SIZEOF(dbeIcons);
+ }
+ if (Proto_IsProtocolLoaded(szProto))
+ return SIZEOF(dbeIcons) - 2; // ICO_ONLINE;
+ }
+ }
+ return SIZEOF(dbeIcons) - 1; // ICO_OFFLINE;
}
diff --git a/plugins/DbEditorPP/src/main.cpp b/plugins/DbEditorPP/src/main.cpp
index 3db3a53ab9..5a4e023bd8 100644
--- a/plugins/DbEditorPP/src/main.cpp
+++ b/plugins/DbEditorPP/src/main.cpp
@@ -3,16 +3,17 @@
HINSTANCE hInst = NULL;
MIDatabase *g_db;
+
HANDLE hTTBButt = NULL;
BOOL bServiceMode = FALSE;
BOOL usePopups;
-HWND hwnd2watchedVarsWindow;
+
int hLangpack;
BYTE nameOrder[NAMEORDERCOUNT];
HGENMENU hUserMenu;
-WatchListArrayStruct WatchListArray;
MCONTACT hRestore;
-IconItem iconList[];
+
+extern HWND hwnd2watchedVarsWindow;
//========================
// MirandaPluginInfo
@@ -50,54 +51,25 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD, LPVOID)
return TRUE;
}
-void settingChanged(HWND hwnd2Settings, MCONTACT hContact, char *module, char *setting);
int DBSettingChanged(WPARAM hContact, LPARAM lParam)
{
DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *)lParam;
- char *setting;
- SettingListInfo *info;
-
- if (hwnd2mainWindow) {
- HWND hwnd2Settings = GetDlgItem(hwnd2mainWindow, IDC_SETTINGS);
- if (info = (SettingListInfo *)GetWindowLongPtr(hwnd2Settings, GWLP_USERDATA)) {
- if ((hContact == info->hContact) && !mir_strcmp(info->module, cws->szModule)) {
- setting = mir_strdup(cws->szSetting);
- if (cws->value.type == DBVT_DELETED) {
- LVFINDINFO lvfi;
- int index;
- lvfi.flags = LVFI_STRING;
- lvfi.psz = setting;
- lvfi.vkDirection = VK_DOWN;
- index = ListView_FindItem(hwnd2Settings, -1, &lvfi);
- if (index > -1)
- ListView_DeleteItem(hwnd2Settings, index);
- mir_free(setting);
- return 0;
- }
- settingChanged(hwnd2Settings, hContact, info->module, setting);
- mir_free(setting);
- }
- }
- }
+ // setting list
+ if (hwnd2mainWindow)
+ settingChanged(hContact, cws->szModule, cws->szSetting, &(cws->value));
+
// watch list
if (!hwnd2watchedVarsWindow && !usePopups)
return 0;
- for (int i = 0; i < WatchListArray.count; i++) {
- if (WatchListArray.item[i].module && (hContact == WatchListArray.item[i].hContact)) {
- if (!mir_strcmp(cws->szModule, WatchListArray.item[i].module)) {
- if (!WatchListArray.item[i].setting || !mir_strcmp(cws->szSetting, WatchListArray.item[i].setting)) {
- if (usePopups)
- popupWatchedVar(hContact, cws->szModule, cws->szSetting);
- if (hwnd2watchedVarsWindow)
- PopulateWatchedWindow(GetDlgItem(hwnd2watchedVarsWindow, IDC_VARS));
- break;
- }
- }
- }
+ if (WatchedArrayIndex(hContact, cws->szModule, cws->szSetting, 0) >= 0)
+ {
+ if (usePopups) popupWatchedVar(hContact, cws->szModule, cws->szSetting);
+ PopulateWatchedWindow();
}
+
return 0;
}
@@ -105,8 +77,7 @@ INT_PTR DBEditorppMenuCommand(WPARAM wParam, LPARAM)
{
if (!hwnd2mainWindow) { // so only opens 1 at a time
hRestore = wParam;
- SetCursor(LoadCursor(NULL, IDC_WAIT));
- CreateDialog(hInst, MAKEINTRESOURCE(IDD_MAIN), 0, MainDlgProc);
+ openMainWindow();
}
else {
ShowWindow(hwnd2mainWindow, SW_RESTORE);
@@ -123,19 +94,13 @@ INT_PTR DBEditorppMenuCommand(WPARAM wParam, LPARAM)
return 0;
}
-BOOL IsCP_UTF8(void)
-{
- CPINFO CPInfo;
- return GetCPInfo(CP_UTF8, &CPInfo);
-}
-
static int OnTTBLoaded(WPARAM, LPARAM)
{
TTBButton ttb = { sizeof(ttb) };
ttb.dwFlags = TTBBF_VISIBLE | TTBBF_SHOWTOOLTIP;
ttb.pszService = "DBEditorpp/MenuCommand";
ttb.name = LPGEN("Database Editor++");
- ttb.hIconHandleUp = iconList[0].hIcolib;
+ ttb.hIconHandleUp = GetIcoLibHandle(ICO_DBE_BUTT);
ttb.pszTooltipUp = LPGEN("Open Database Editor");
hTTBButt = TopToolbar_AddButton(&ttb);
return 0;
@@ -143,12 +108,12 @@ static int OnTTBLoaded(WPARAM, LPARAM)
int ModulesLoaded(WPARAM, LPARAM)
{
- addIcons();
+ IcoLibRegister();
// Register menu item
CLISTMENUITEM mi = { sizeof(mi) };
mi.position = 1900000001;
- mi.icolibItem = iconList[0].hIcolib;
+ mi.icolibItem = GetIcoLibHandle(ICO_DBE_BUTT);
mi.pszPopupName = "Database";
mi.pszName = modFullname;
mi.pszService = "DBEditorpp/MenuCommand";
@@ -158,17 +123,18 @@ int ModulesLoaded(WPARAM, LPARAM)
mi.cbSize = sizeof(mi);
mi.position = 1900000001;
mi.flags = 0;
- mi.icolibItem = iconList[7].hIcolib;
+ mi.icolibItem = GetIcoLibHandle(ICO_REGUSER);
mi.pszName = LPGEN("Open user tree in DBE++");
mi.pszService = "DBEditorpp/MenuCommand";
hUserMenu = Menu_AddContactMenuItem(&mi);
// Register hotkeys
+ _A2T text(modFullname);
HOTKEYDESC hkd = { sizeof(hkd) };
hkd.pszName = "hk_dbepp_open";
hkd.pszService = "DBEditorpp/MenuCommand";
- hkd.ptszDescription = LPGEN("Open Database Editor");
- hkd.ptszSection = modFullname;
+ hkd.ptszDescription = LPGENT("Open Database Editor");
+ hkd.ptszSection = text;
hkd.DefHotKey = HOTKEYCODE(HOTKEYF_SHIFT | HOTKEYF_EXT, 'D');
Hotkey_Register(&hkd);
@@ -178,8 +144,8 @@ int ModulesLoaded(WPARAM, LPARAM)
for (int i = 0; i < NAMEORDERCOUNT; i++)
nameOrder[i] = i;
- DBVARIANT dbv;
- if (!db_get(NULL, "Contact", "NameOrder", &dbv)) {
+ DBVARIANT dbv = {0};
+ if (!db_get_s(NULL, "Contact", "NameOrder", &dbv, DBVT_BLOB)) {
memcpy(nameOrder, dbv.pbVal, dbv.cpbVal);
db_free(&dbv);
}
@@ -196,13 +162,12 @@ int PreShutdown(WPARAM, LPARAM)
{
if (hwnd2watchedVarsWindow) DestroyWindow(hwnd2watchedVarsWindow);
if (hwnd2mainWindow) DestroyWindow(hwnd2mainWindow);
- if (hwnd2importWindow) DestroyWindow(hwnd2importWindow);
return 0;
}
INT_PTR ServiceMode(WPARAM, LPARAM)
{
- addIcons();
+ IcoLibRegister();
bServiceMode = TRUE;
HookEvent(ME_DB_CONTACT_SETTINGCHANGED, DBSettingChanged);
@@ -220,7 +185,8 @@ extern "C" __declspec(dllexport) int Load(void)
{
mir_getLP(&pluginInfoEx);
- hwnd2mainWindow = hwnd2watchedVarsWindow = hwnd2importWindow = 0;
+ hwnd2mainWindow = NULL;
+
hRestore = NULL;
g_db = GetCurrentDatabase();
@@ -240,7 +206,6 @@ extern "C" __declspec(dllexport) int Load(void)
icex.dwICC = ICC_LISTVIEW_CLASSES;
InitCommonControlsEx(&icex);
- memset(&WatchListArray, 0, sizeof(WatchListArray));
return 0;
}
@@ -250,35 +215,35 @@ extern "C" __declspec(dllexport) int Unload(void)
return 0;
}
-//=======================================================
-// db_get_s (prob shouldnt use this unless u know how big the string is gonna be..)
-//=======================================================
-int DBGetContactSettingStringStatic(MCONTACT hContact, char *szModule, char *szSetting, char *value, int maxLength)
+// ======================================================================================================================
+
+char *StringFromBlob(BYTE *blob, WORD len)
{
- DBVARIANT dbv;
- if (!db_get(hContact, szModule, szSetting, &dbv)) {
- strncpy(value, dbv.pszVal, maxLength);
- db_free(&dbv);
- return 1;
- }
- else {
- db_free(&dbv);
- return 0;
+ int j;
+ char tmp[16];
+
+ char *data = (char*)mir_alloc(3 * (len + 2));
+ data[0] = 0;
+
+ for (j = 0; j < len; j++)
+ {
+ mir_snprintf(tmp, SIZEOF(tmp), "%02X ", blob[j]);
+ mir_strcat(data, tmp);
}
+ return data;
}
+
int WriteBlobFromString(MCONTACT hContact, const char *szModule, const char *szSetting, const char *szValue, int len)
{
int j = 0, i = 0;
- BYTE *data = NULL;
BYTE b;
- int tmp;
+ int tmp, res = 0;
+ BYTE *data = (BYTE*)mir_alloc(2 + len / 2);
- if (!(data = (BYTE *)_alloca(2 + len / 2))) {
- msg(Translate("Couldn't allocate enough memory!"), modFullname);
+ if (!data)
return 0;
- }
while (j < len) {
b = szValue[j];
@@ -288,221 +253,344 @@ int WriteBlobFromString(MCONTACT hContact, const char *szModule, const char *szS
(b >= 'a' && b <= 'f'))
{
if (sscanf(&szValue[j], "%02X", &tmp) == 1) {
- data[i++] = (BYTE)tmp;
+ data[i++] = (BYTE)(tmp&0xFF);
j++;
}
}
j++;
}
+
if (i)
- return db_set_blob(hContact, szModule, szSetting, data, (WORD)i);
+ res = !db_set_blob(hContact, szModule, szSetting, data, (WORD)i);
+
+ mir_free(data);
+ return res;
+}
+
+TCHAR *DBVType(BYTE type)
+{
+ switch (type) {
+ case DBVT_BYTE: return _T("BYTE");
+ case DBVT_WORD: return _T("WORD");
+ case DBVT_DWORD: return _T("DWORD");
+ case DBVT_ASCIIZ: return _T("STRING");
+ case DBVT_WCHAR:
+ case DBVT_UTF8: return _T("UNICODE");
+ case DBVT_BLOB: return _T("BLOB");
+ case DBVT_DELETED: return _T("DELETED");
+ }
+ return _T("");
+}
+
+
+DWORD getNumericValue(DBVARIANT *dbv) {
+ switch(dbv->type) {
+ case DBVT_DWORD:
+ return dbv->dVal;
+ case DBVT_WORD:
+ return dbv->wVal;
+ case DBVT_BYTE:
+ return dbv->bVal;
+ }
+ return 0;
+}
+
+int setNumericValue(MCONTACT hContact, const char *module, const char *setting, DWORD value, int type)
+{
+ switch(type) {
+ case DBVT_BYTE:
+ if (value <= 0xFF)
+ return !db_set_b(hContact, module, setting, (BYTE)value);
+ break;
+
+ case DBVT_WORD:
+ if (value <= 0xFFFF)
+ return !db_set_w(hContact, module, setting, (WORD)value);
+ break;
+
+ case DBVT_DWORD:
+ return !db_set_dw(hContact, module, setting, value);
+
+ }
return 0;
}
-int GetSetting(MCONTACT hContact, const char *szModule, const char *szSetting, DBVARIANT *dbv)
+
+int IsRealUnicode(TCHAR *value)
{
- return db_get_s(hContact, szModule, szSetting, dbv, 0);
+#ifdef _UNICODE
+ BOOL nonascii = 0;
+ WideCharToMultiByte(Langpack_GetDefaultCodePage(), WC_NO_BEST_FIT_CHARS, value, -1, NULL, 0, NULL, &nonascii);
+ return nonascii;
+#endif
+ return 0;
+}
+
+
+int setTextValue(MCONTACT hContact, const char *module, const char *setting, TCHAR *value, int type)
+{
+#ifdef _UNICODE
+ if (type == DBVT_UTF8 || type == DBVT_WCHAR)
+ return !db_set_ws(hContact, module, setting, value);
+
+ if (type == DBVT_ASCIIZ && IsRealUnicode(value))
+ return 0;
+#endif
+ return !db_set_s(hContact, module, setting, _T2A(value));
}
-int GetValue(MCONTACT hContact, const char *szModule, const char *szSetting, char *Value, int length)
+
+int GetValueA(MCONTACT hContact, const char *module, const char *setting, char *value, int length)
{
DBVARIANT dbv = { 0 };
- if (Value && length >= 10 && !GetSetting(hContact, szModule, szSetting, &dbv)) {
+ if (!module || !setting || !value)
+ return 0;
+
+ if (length >= 10 && !db_get_s(hContact, module, setting, &dbv, 0)) {
switch (dbv.type) {
+
case DBVT_ASCIIZ:
- strncpy(Value, dbv.pszVal, length);
+ mir_strncpy(value, dbv.pszVal, length);
break;
+
case DBVT_DWORD:
- _itoa(dbv.dVal, Value, 10);
- break;
+ case DBVT_WORD:
case DBVT_BYTE:
- _itoa(dbv.bVal, Value, 10);
+ _ultoa(getNumericValue(&dbv), value, 10);
break;
- case DBVT_WORD:
- _itoa(dbv.wVal, Value, 10);
+
+ case DBVT_WCHAR:
+ {
+ ptrA str(mir_u2a(dbv.pwszVal));
+ mir_strncpy(value, str, length);
break;
+
+ }
case DBVT_UTF8:
- int len = (int)mir_strlen(dbv.pszVal) + 1;
- char *sz = (char *)_alloca(len * 3);
- WCHAR *wc = (WCHAR *)_alloca(len * sizeof(WCHAR));
- MultiByteToWideChar(CP_UTF8, 0, dbv.pszVal, -1, wc, len);
- WideCharToMultiByte(CP_ACP, 0, wc, -1, sz, len, NULL, NULL);
- strncpy(Value, sz, length);
+ {
+ ptrA str(mir_utf8decodeA(dbv.pszVal));
+ mir_strncpy(value, str, length);
break;
}
+ case DBVT_DELETED:
+ value[0] = 0;
+ return 0;
+ }
+ int type = dbv.type;
db_free(&dbv);
-
- Value[length - 1] = 0;
- return 1;
+ return type;
}
- if (Value)
- Value[0] = 0;
-
+ value[0] = 0;
return 0;
}
-int GetValueW(MCONTACT hContact, const char *szModule, const char *szSetting, WCHAR *Value, int length)
+int GetValueW(MCONTACT hContact, const char *module, const char *setting, WCHAR *value, int length)
{
DBVARIANT dbv = { 0 };
- WCHAR *wc;
- int len;
- if (Value && length >= 10 && !GetSetting(hContact, szModule, szSetting, &dbv)) {
+ if (!module || !setting || !value)
+ return 0;
+
+ if (length >= 10 && !db_get_s(hContact, module, setting, &dbv, 0)) {
switch (dbv.type) {
- case DBVT_UTF8:
- len = (int)mir_strlen(dbv.pszVal) + 1;
- wc = (WCHAR *)_alloca(length * sizeof(WCHAR));
- MultiByteToWideChar(CP_UTF8, 0, dbv.pszVal, -1, wc, len);
- wcsncpy((WCHAR *)Value, wc, length);
- break;
case DBVT_ASCIIZ:
- len = (int)mir_strlen(dbv.pszVal) + 1;
- wc = (WCHAR *)_alloca(len * sizeof(WCHAR));
- MultiByteToWideChar(CP_ACP, 0, dbv.pszVal, -1, wc, len);
- wcsncpy((WCHAR *)Value, wc, length);
+ {
+ ptrW str(mir_a2u(dbv.pszVal));
+ mir_wstrncpy(value, str, length);
break;
-
+ }
case DBVT_DWORD:
- _itow(dbv.dVal, Value, 10);
+ case DBVT_WORD:
+ case DBVT_BYTE:
+ _ultow(getNumericValue(&dbv), value, 10);
break;
- case DBVT_BYTE:
- _itow(dbv.bVal, Value, 10);
+ case DBVT_WCHAR:
+ mir_wstrncpy(value, dbv.pwszVal, length);
break;
- case DBVT_WORD:
- _itow(dbv.wVal, Value, 10);
+ case DBVT_UTF8:
+ {
+ ptrW str(mir_utf8decodeW(dbv.pszVal));
+ mir_wstrncpy(value, str, length);
break;
}
+ case DBVT_DELETED:
+ value[0] = 0;
+ return 0;
+ }
+ int type = dbv.type;
db_free(&dbv);
-
- Value[length - 1] = 0;
- return 1;
+ return type;
}
- if (Value)
- Value[0] = 0;
-
+ value[0] = 0;
return 0;
}
-char *u2a(wchar_t *src)
+
+int GetContactName(MCONTACT hContact, const char *proto, TCHAR *value, int maxlen)
{
- if (!src)
- return NULL;
+ if (!value)
+ return 0;
+
+ if (!hContact) {
+ mir_tstrncpy(value, TranslateT("Settings"), maxlen);
+ return 1;
+ }
+
+ char *szProto = (char*)proto;
+ char tmp[FLD_SIZE];
+ TCHAR name[NAME_SIZE];
+ name[0] = 0;
+
+ if (hContact && (!proto || !proto[0])) {
+ if (!db_get_static(hContact, "Protocol", "p", tmp, SIZEOF(tmp)))
+ szProto = tmp;
+ }
+
+ for (int i = 0; i < NAMEORDERCOUNT - 1; i++) {
+ switch (nameOrder[i]) {
+ case 0: // custom name
+ GetValue(hContact, "CList", "MyHandle", name, SIZEOF(name));
+ break;
+
+ case 1: // nick
+ if (!szProto) break;
+ GetValue(hContact, szProto, "Nick", name, SIZEOF(name));
+ break;
+/*
+ case 2: // First Name
+ if (!szProto) break;
+ GetValue(hContact, szProto, "FirstName", name, SIZEOF(name));
+ break;
+*/
+ case 3: // E-mail
+ if (!szProto) break;
+ GetValue(hContact, szProto, "e-mail", name, SIZEOF(name));
+ break;
+/*
+ case 4: // Last Name
+ GetValue(hContact, szProto, "LastName", name, SIZEOF(name));
+ break;
+*/
+ case 5: // Unique id
+ {
+ if (!szProto) break;
+ // protocol must define a PFLAG_UNIQUEIDSETTING
+ char *uid = (char *)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0);
+ if ((INT_PTR)uid != CALLSERVICE_NOTFOUND && uid)
+ GetValue(hContact, szProto, uid, name, SIZEOF(name));
+ }
+ break;
+ case 6: // first + last name
+ {
+ if (!szProto) break;
+
+ GetValue(hContact, szProto, "FirstName", name, SIZEOF(name));
+
+ int len = mir_tstrlen(name);
+ if (len + 2 < SIZEOF(name)) {
+ if (len)
+ mir_tstrncat(name, _T(" "), SIZEOF(name));
+ len++;
+ GetValue(hContact, szProto, "LastName", &name[len], SIZEOF(name) - len);
+ }
+ }
+ break;
+ }
+
+ if (name[0])
+ break;
+ }
- int cbLen = WideCharToMultiByte(CP_ACP, 0, src, -1, NULL, 0, NULL, NULL);
- char *result = (char *)mir_calloc((cbLen + 1) * sizeof(char));
- if (result == NULL)
- return NULL;
+ if (!name[0])
+ mir_tstrncpy(name, TranslateT("<UNKNOWN>"), SIZEOF(name));
- WideCharToMultiByte(CP_ACP, 0, src, -1, result, cbLen, NULL, NULL);
- result[cbLen] = 0;
- return result;
+ if (szProto && szProto[0]) {
+ if (g_Order)
+ mir_sntprintf(value, maxlen, _T("(%s) %s"), _A2T(szProto), name);
+ else
+ mir_sntprintf(value, maxlen , _T("%s (%s)"), name, _A2T(szProto));
+ }
+ else
+ mir_tstrncpy(value, name, maxlen);
+
+ if (!szProto || !Proto_IsProtocolLoaded(szProto)) {
+ mir_tstrncat(value, _T(" "), maxlen);
+ mir_tstrncat(value, TranslateT("[UNLOADED]"), maxlen);
+ }
+
+ return 1;
}
-wchar_t *a2u(char *src, wchar_t *buffer, int len)
+
+int ApplyProtoFilter(MCONTACT hContact)
{
- wchar_t *result = buffer;
- if (result == NULL || len < 3)
- return NULL;
+ if (g_Mode == MODE_ALL) return 0;
- MultiByteToWideChar(CP_ACP, 0, src, -1, result, len - 1);
- result[len - 1] = 0;
+ int loaded = 0;
+ char szProto[FLD_SIZE];
- return result;
+ if (!db_get_static(hContact, "Protocol", "p", szProto, SIZEOF(szProto)))
+ loaded = Proto_IsProtocolLoaded(szProto) ? 1 : 0;
+
+ if ((loaded && g_Mode == MODE_UNLOADED) || (!loaded && g_Mode == MODE_LOADED))
+ return 1;
+
+ return 0;
}
-int GetDatabaseString(MCONTACT hContact, const char *szModule, const char *szSetting, WCHAR *Value, int length, BOOL unicode)
+
+void loadListSettings(HWND hwnd, ColumnsSettings *cs)
{
- if (unicode)
- return GetValueW(hContact, szModule, szSetting, Value, length);
- else
- return GetValue(hContact, szModule, szSetting, (char *)Value, length);
+ LVCOLUMN sLC = {0};
+ sLC.fmt = LVCFMT_LEFT;
+ sLC.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
+ int i = 0;
+ while (cs[i].name) {
+ sLC.pszText = TranslateTS(cs[i].name);
+ sLC.cx = db_get_w(NULL, modname, cs[i].dbname, cs[i].defsize);
+ ListView_InsertColumn(hwnd, cs[i].index, &sLC);
+ i++;
+ }
}
-WCHAR* GetContactName(MCONTACT hContact, const char *szProto, int unicode)
-{
- int i, r = 0;
- static WCHAR res[512];
- char *proto = (char *)szProto;
- char name[256];
-
- if (hContact && !proto)
- if (GetValue(hContact, "Protocol", "p", name, SIZEOF(name)))
- proto = name;
-
- if (proto) {
- for (i = 0; i < NAMEORDERCOUNT - 1; i++) {
- switch (nameOrder[i]) {
- case 0: // custom name
- r = GetDatabaseString(hContact, "CList", "MyHandle", res, SIZEOF(res), unicode);
- break;
-
- case 1: // nick
- r = GetDatabaseString(hContact, proto, "Nick", res, SIZEOF(res), unicode);
- break;
-
- case 2: // First Name
- r = GetDatabaseString(hContact, proto, "FirstName", res, SIZEOF(res), unicode);
- break;
-
- case 3: // E-mail
- r = GetDatabaseString(hContact, proto, "e-mail", res, SIZEOF(res), unicode);
- break;
-
- case 4: // Last Name
- if (GetDatabaseString(hContact, proto, "LastName", res, SIZEOF(res), unicode))
- break;
-
- case 5: // Unique id
- {
- // protocol must define a PFLAG_UNIQUEIDSETTING
- char *uid = (char *)CallProtoService(proto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0);
- if ((INT_PTR)uid != CALLSERVICE_NOTFOUND && uid)
- r = GetDatabaseString(hContact, proto, uid, res, SIZEOF(res), unicode);
- }
- break;
- case 6: // first + last name
- {
- int len = 0;
-
- if (r = GetDatabaseString(hContact, proto, "FirstName", res, SIZEOF(res), unicode)) {
- if (unicode)
- len = (int)mir_wstrlen(res);
- else
- len = (int)mir_strlen((char *)res);
- }
- else
- res[0] = 0;
-
- if (len && len < SIZEOF(res) - 2) {
- if (unicode)
- mir_wstrcat(res, L" ");
- else
- mir_strcat((char*)res, " ");
-
- len++;
- }
-
- if (SIZEOF(res) - len > 1)
- r |= GetDatabaseString(hContact, proto, "LastName", &res[len], SIZEOF(res) - len, unicode);
-
- break;
- }
- }
- if (r)
- return res;
+void saveListSettings(HWND hwnd, ColumnsSettings *cs)
+{
+ char tmp[FLD_SIZE];
+ LVCOLUMN sLC = {0};
+ sLC.mask = LVCF_WIDTH;
+ int i = 0;
+ while (cs[i].name) {
+ if (ListView_GetColumn(hwnd, cs[i].index, &sLC)) {
+ mir_snprintf(tmp, SIZEOF(tmp), cs[i].dbname, i);
+ db_set_w(NULL, modname, tmp, (WORD)sLC.cx);
}
+ i++;
}
+}
- return (unicode) ? nick_unknownW : (WCHAR *)nick_unknown;
+
+INT_PTR CALLBACK ColumnsCompare(LPARAM lParam1, LPARAM lParam2, LPARAM myParam)
+{
+ ColumnsSortParams params = *(ColumnsSortParams *)myParam;
+ const int maxSize = 1024;
+ TCHAR text1[maxSize];
+ TCHAR text2[maxSize];
+ ListView_GetItemText(params.hList, lParam1, params.column, text1, SIZEOF(text1));
+ ListView_GetItemText(params.hList, lParam2, params.column, text2, SIZEOF(text2));
+
+ int res = mir_tstrcmpi(text1, text2);
+ return (params.column == params.last) ? -res : res;
}
+
+
diff --git a/plugins/DbEditorPP/src/main_window.cpp b/plugins/DbEditorPP/src/main_window.cpp
index 7c74985b66..ea5f75dc60 100644
--- a/plugins/DbEditorPP/src/main_window.cpp
+++ b/plugins/DbEditorPP/src/main_window.cpp
@@ -1,13 +1,20 @@
#include "headers.h"
HWND hwnd2mainWindow;
-int Order;
-HIMAGELIST himl2;
-int Hex;
-#define GC_SPLITTERMOVED (WM_USER+101)
+static HIMAGELIST hImg = 0;
+
+int g_Hex;
+int g_Mode;
+int g_Order;
+int g_Inline;
+
+extern SettingListInfo info;
+extern struct ColumnsSettings csSettingList[];
+extern HWND hwnd2List;
+extern HWND hwnd2Tree;
-extern BOOL bServiceMode;
+#define GC_SPLITTERMOVED (WM_USER+101)
void moduleListWM_NOTIFY(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
void SettingsListWM_NOTIFY(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
@@ -99,36 +106,36 @@ LRESULT CALLBACK ModuleTreeSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPAR
case WM_CHAR:
if (GetKeyState(VK_CONTROL) & 0x8000 && wParam == 6)
- CreateDialog(hInst, MAKEINTRESOURCE(IDD_FIND), hwnd, FindWindowDlgProc);
+ newFindWindow();
break;
case WM_KEYUP:
if (wParam == VK_DELETE || wParam == VK_F2 || wParam == VK_F5 || wParam == VK_F3) {
TVITEM tvi;
- char module[256];
+ TCHAR text[FLD_SIZE];
tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT;
tvi.hItem = TreeView_GetSelection(hwnd);
- tvi.pszText = module;
- tvi.cchTextMax = SIZEOF(module);
+ tvi.pszText = text;
+ tvi.cchTextMax = SIZEOF(text);
if (TreeView_GetItem(hwnd, &tvi) && tvi.lParam) {
ModuleTreeInfoStruct *mtis = (ModuleTreeInfoStruct *)tvi.lParam;
MCONTACT hContact = mtis->hContact;
if (wParam == VK_DELETE) {
if ((mtis->type) & MODULE) {
- if (deleteModule(module, hContact, 0)) {
+ if (deleteModule(hContact,_T2A(text), 1)) {
mir_free(mtis);
TreeView_DeleteItem(hwnd, tvi.hItem);
}
}
else if ((mtis->type == CONTACT) && hContact) {
if (db_get_b(NULL, "CList", "ConfirmDelete", 1)) {
- char msg[1024];
- mir_snprintf(msg, SIZEOF(msg), Translate("Are you sure you want to delete contact \"%s\"?"), module);
- if (MessageBox(0, msg, Translate("Confirm contact delete"), MB_YESNO | MB_ICONEXCLAMATION) == IDNO)
+ TCHAR str[MSG_SIZE];
+ mir_sntprintf(text, TranslateT("Are you sure you want to delete contact \"%s\"?"), text);
+ if (dlg(str, MB_YESNO | MB_ICONEXCLAMATION) == IDNO)
break;
}
CallService(MS_DB_CONTACT_DELETE, hContact, 0);
- freeTree(hwnd, mtis->hContact);
+ freeTree(mtis->hContact);
TreeView_DeleteItem(hwnd, tvi.hItem);
}
}
@@ -139,7 +146,7 @@ LRESULT CALLBACK ModuleTreeSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPAR
break;
}
else if (wParam == VK_F3) {
- CreateDialog(hInst, MAKEINTRESOURCE(IDD_FIND), hwnd, FindWindowDlgProc);
+ newFindWindow();
break;
}
}
@@ -154,34 +161,31 @@ static LRESULT CALLBACK SettingListSubclassProc(HWND hwnd, UINT msg, WPARAM wPar
switch (msg) {
case WM_CHAR:
if (GetKeyState(VK_CONTROL) & 0x8000 && wParam == 6)
- CreateDialog(hInst, MAKEINTRESOURCE(IDD_FIND), hwnd, FindWindowDlgProc);
+ newFindWindow();
break;
case WM_KEYDOWN:
- if (wParam == VK_DELETE || wParam == VK_F5 || (wParam == VK_F2 && ListView_GetSelectedCount(hwnd) == 1)) {
- char *module, setting[256];
- MCONTACT hContact;
- SettingListInfo* sli = (SettingListInfo *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- if (!sli)
- break;
- hContact = sli->hContact;
- module = sli->module;
- ListView_GetItemText(hwnd, ListView_GetSelectionMark(hwnd), 0, setting, SIZEOF(setting));
+
+ if (wParam == VK_F5) {
+ PopulateSettings(info.hContact, info.module);
+ }
+ else if (wParam == VK_F3)
+ newFindWindow();
+ else
+ if (wParam == VK_DELETE || (wParam == VK_F2 && ListView_GetSelectedCount(hwnd) == 1)) {
+
+ char setting[FLD_SIZE];
+ int idx = ListView_GetSelectionMark(hwnd);
+ if (idx == -1 ) return 0;
+ ListView_GetItemTextA(hwnd, idx, 0, setting, SIZEOF(setting));
if (wParam == VK_F2)
- editSetting(hContact, module, setting);
- else if (wParam == VK_F5) {
- char *szModule = mir_tstrdup(module); // need to do this, otheriwse the setlist stays empty
- PopulateSettings(hwnd, hContact, szModule);
- mir_free(szModule);
- }
+ editSetting(info.hContact, info.module, setting);
else if (wParam == VK_DELETE)
- DeleteSettingsFromList(hwnd, hContact, module, setting);
+ DeleteSettingsFromList(info.hContact, info.module, setting);
return 0;
}
- else if (wParam == VK_F3)
- CreateDialog(hInst, MAKEINTRESOURCE(IDD_FIND), hwnd, FindWindowDlgProc);
break;
}
return mir_callNextSubclass(hwnd, SettingListSubclassProc, msg, wParam, lParam);
@@ -194,102 +198,57 @@ INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
TranslateDialogDefault(hwnd);
{
hwnd2mainWindow = hwnd;
+ hwnd2Tree = GetDlgItem(hwnd, IDC_MODULES);
+ hwnd2List = GetDlgItem(hwnd, IDC_SETTINGS);
+
+ LoadResidentSettings();
+
+ // image list
+ hImg = LoadIcons();
+
// do the icon
SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(ICO_REGEDIT)));
SetWindowText(hwnd, TranslateT("Database Editor++"));
// setup the splitter
- SetWindowLongPtr(GetDlgItem(hwnd, IDC_SPLITTER), GWLP_USERDATA, (LONG_PTR)db_get_w(NULL, modname, "Splitter", 300));
+ SetWindowLongPtr(GetDlgItem(hwnd, IDC_SPLITTER), GWLP_USERDATA, (LONG_PTR)db_get_w(NULL, modname, "Splitter", 200));
SendMessage(hwnd, GC_SPLITTERMOVED, 0, 0);
mir_subclassWindow(GetDlgItem(hwnd, IDC_SPLITTER), SplitterSubclassProc);
+
// module tree
- TreeView_SetUnicodeFormat(GetDlgItem(hwnd, IDC_MODULES), TRUE);
- mir_subclassWindow(GetDlgItem(hwnd, IDC_MODULES), ModuleTreeSubclassProc);
+ mir_subclassWindow(hwnd2Tree, ModuleTreeSubclassProc);
+ TreeView_SetImageList(hwnd2Tree, hImg, TVSIL_NORMAL);
+
//setting list
- setupSettingsList(GetDlgItem(hwnd, IDC_SETTINGS));
- mir_subclassWindow(GetDlgItem(hwnd, IDC_SETTINGS), SettingListSubclassProc);
+ mir_subclassWindow(hwnd2List, SettingListSubclassProc);
+ ListView_SetExtendedListViewStyle(hwnd2List, 32 | LVS_EX_SUBITEMIMAGES | LVS_EX_LABELTIP ); //LVS_EX_GRIDLINES
+ loadListSettings(hwnd2List, csSettingList);
+ ListView_SetImageList(hwnd2List, hImg, LVSIL_SMALL);
HMENU hMenu = GetMenu(hwnd);
TranslateMenu(hMenu);
for (int i = 0; i < 6; i++)
TranslateMenu(GetSubMenu(hMenu, i));
- // move the dialog to the users position
- MoveWindow(hwnd, db_get_dw(NULL, modname, "x", 0), db_get_dw(NULL, modname, "y", 0), db_get_dw(NULL, modname, "width", 500), db_get_dw(NULL, modname, "height", 250), 0);
- if (db_get_b(NULL, modname, "Maximised", 0)) {
- WINDOWPLACEMENT wp;
- wp.length = sizeof(WINDOWPLACEMENT);
- wp.flags = WPF_RESTORETOMAXIMIZED;
- wp.showCmd = SW_SHOWMAXIMIZED;
+ Utils_RestoreWindowPosition(hwnd, NULL, modname, "Main_");
+ if (db_get_b(NULL, modname, "Maximized", 0))
+ ShowWindow(hwnd,SW_SHOWMAXIMIZED);
- SetWindowPlacement(hwnd, &wp);
- }
- SetCursor(LoadCursor(NULL, IDC_ARROW));
+ g_Inline = !db_get_b(NULL, modname, "DontAllowInLineEdit", 1);
+ CheckMenuItem(GetSubMenu(hMenu, 5), MENU_INLINE_EDIT, MF_BYCOMMAND | (g_Inline ? MF_CHECKED: MF_UNCHECKED));
- Mode = MODE_ALL;
+ g_Mode = MODE_ALL;
CheckMenuItem(GetSubMenu(hMenu, 5), MENU_FILTER_ALL, MF_BYCOMMAND | MF_CHECKED);
- Hex = db_get_b(NULL, modname, "HexMode", 0);
- CheckMenuItem(GetSubMenu(hMenu, 5), MENU_BYTE_HEX, MF_BYCOMMAND | ((Hex & HEX_BYTE) ? MF_CHECKED : MF_UNCHECKED));
- CheckMenuItem(GetSubMenu(hMenu, 5), MENU_WORD_HEX, MF_BYCOMMAND | ((Hex & HEX_WORD) ? MF_CHECKED : MF_UNCHECKED));
- CheckMenuItem(GetSubMenu(hMenu, 5), MENU_DWORD_HEX, MF_BYCOMMAND | ((Hex & HEX_DWORD) ? MF_CHECKED : MF_UNCHECKED));
+ g_Hex = db_get_b(NULL, modname, "HexMode", 0);
+ CheckMenuItem(GetSubMenu(hMenu, 5), MENU_BYTE_HEX, MF_BYCOMMAND | ((g_Hex & HEX_BYTE) ? MF_CHECKED : MF_UNCHECKED));
+ CheckMenuItem(GetSubMenu(hMenu, 5), MENU_WORD_HEX, MF_BYCOMMAND | ((g_Hex & HEX_WORD) ? MF_CHECKED : MF_UNCHECKED));
+ CheckMenuItem(GetSubMenu(hMenu, 5), MENU_DWORD_HEX, MF_BYCOMMAND | ((g_Hex & HEX_DWORD) ? MF_CHECKED : MF_UNCHECKED));
CheckMenuItem(GetSubMenu(GetMenu(hwnd), 5), MENU_SAVE_POSITION, MF_BYCOMMAND | (db_get_b(NULL, modname, "RestoreOnOpen", 1) ? MF_CHECKED : MF_UNCHECKED));
- Order = db_get_b(NULL, modname, "SortMode", 1);
- CheckMenuItem(GetSubMenu(GetMenu(hwnd), 5), MENU_SORT_ORDER, MF_BYCOMMAND | (Order ? MF_CHECKED : MF_UNCHECKED));
-
- // image list
- int numberOfIcons = 0;
- himl = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 10, 0);
- if (himl != NULL) {
- if (AddIconToList(himl, LoadSkinnedDBEIcon(ICO_SETTINGS)))
- numberOfIcons++;
- if (AddIconToList(himl, LoadSkinnedDBEIcon(ICO_KNOWN)))
- numberOfIcons++;
- if (AddIconToList(himl, LoadSkinnedDBEIcon(ICO_KNOWNOPEN)))
- numberOfIcons++;
- if (AddIconToList(himl, LoadSkinnedDBEIcon(ICO_CONTACTS)))
- numberOfIcons++;
- if (AddIconToList(himl, LoadSkinnedDBEIcon(ICO_OFFLINE)))
- numberOfIcons++;
- if (AddIconToList(himl, LoadSkinnedDBEIcon(ICO_ONLINE)))
- numberOfIcons++;
-
- if (numberOfIcons < DEF_ICON + 1) {
- if (numberOfIcons)
- ImageList_Destroy(himl);
- himl = NULL;
- }
-
- AddProtoIconsToList(himl, numberOfIcons);
-
- himl2 = NULL;
- numberOfIcons = 0;
-
- if (himl2 = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 5, 0)) {
- if (AddIconToList(himl2, LoadSkinnedDBEIcon(ICO_BINARY)))
- numberOfIcons++;
- if (AddIconToList(himl2, LoadSkinnedDBEIcon(ICO_BYTE)))
- numberOfIcons++;
- if (AddIconToList(himl2, LoadSkinnedDBEIcon(ICO_WORD)))
- numberOfIcons++;
- if (AddIconToList(himl2, LoadSkinnedDBEIcon(ICO_DWORD)))
- numberOfIcons++;
- if (AddIconToList(himl2, LoadSkinnedDBEIcon(ICO_STRING)))
- numberOfIcons++;
- if (AddIconToList(himl2, LoadSkinnedDBEIcon(ICO_UNICODE)))
- numberOfIcons++;
- if (AddIconToList(himl2, LoadSkinnedDBEIcon(ICO_HANDLE)))
- numberOfIcons++;
-
- if (numberOfIcons < 7) {
- if (numberOfIcons)
- ImageList_Destroy(himl2);
- himl2 = NULL;
- }
- }
- }
+ g_Order = db_get_b(NULL, modname, "SortMode", 1);
+ CheckMenuItem(GetSubMenu(GetMenu(hwnd), 5), MENU_SORT_ORDER, MF_BYCOMMAND | (g_Order ? MF_CHECKED : MF_UNCHECKED));
int restore;
if (hRestore)
@@ -317,10 +276,10 @@ INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
ScreenToClient(hwnd, &pt);
splitterPos = rc.left + pt.x + 1;
- if (splitterPos < 65)
- splitterPos = 65;
- if (splitterPos > rc2.right - rc2.left - 65)
- splitterPos = rc2.right - rc2.left - 65;
+ if (splitterPos < 150)
+ splitterPos = 150;
+ if (splitterPos > rc2.right - rc2.left - 150)
+ splitterPos = rc2.right - rc2.left - 150;
SetWindowLongPtr(GetDlgItem(hwnd, IDC_SPLITTER), GWLP_USERDATA, splitterPos);
db_set_w(NULL, modname, "Splitter", (WORD)splitterPos);
}
@@ -332,12 +291,8 @@ INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
MINMAXINFO *mmi = (MINMAXINFO *)lParam;
int splitterPos = GetWindowLongPtr(GetDlgItem(hwnd, IDC_SPLITTER), GWLP_USERDATA);
-
- if (splitterPos + 40 > 200)
- mmi->ptMinTrackSize.x = splitterPos + 65;
- else
- mmi->ptMinTrackSize.x = 200;
- mmi->ptMinTrackSize.y = 150;
+ mmi->ptMinTrackSize.x = splitterPos + 150;
+ mmi->ptMinTrackSize.y = 300;
}
return 0;
@@ -351,29 +306,23 @@ INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
urd.hInstance = hInst;
urd.hwndDlg = hwnd;
urd.lParam = (LPARAM)GetWindowLongPtr(GetDlgItem(hwnd, IDC_SPLITTER), GWLP_USERDATA);
- urd.lpTemplate = MAKEINTRESOURCE(IDD_MAIN);
+ urd.lpTemplate = MAKEINTRESOURCEA(IDD_MAIN);
urd.pfnResizer = DialogResize;
CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd);
-
- if (msg == WM_SIZE && wParam == SIZE_MAXIMIZED || wParam == SIZE_MINIMIZED)
- db_set_b(NULL, modname, "Maximised", 1);
- else if (msg == WM_SIZE && wParam == SIZE_RESTORED)
- db_set_b(NULL, modname, "Maximised", 0);
}
break;
case WM_DESTROY: // free our shit!
if (db_get_b(NULL, modname, "RestoreOnOpen", 1)) {
HTREEITEM item;
- HWND hwnd2Tree = GetDlgItem(hwnd, IDC_MODULES);
- char module[256] = { 0 };
+
if (item = TreeView_GetSelection(hwnd2Tree)) {
int type = MODULE;
-
+ TCHAR text[FLD_SIZE];
TVITEM tvi = { 0 };
tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT;
- tvi.pszText = module;
- tvi.cchTextMax = SIZEOF(module);
+ tvi.pszText = text;
+ tvi.cchTextMax = SIZEOF(text);
tvi.hItem = item;
if (TreeView_GetItem(hwnd2Tree, &tvi)) {
MCONTACT hContact = 0;
@@ -388,50 +337,58 @@ INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
if (type == CONTACT)
db_set_s(NULL, modname, "LastModule", "");
else
- db_set_s(NULL, modname, "LastModule", module);
+ db_set_s(NULL, modname, "LastModule", _T2A(text));
}
else {
db_unset(NULL, modname, "LastContact");
db_unset(NULL, modname, "LastModule");
}
- HWND hwnd2Settings = GetDlgItem(hwnd, IDC_SETTINGS);
- int pos = ListView_GetSelectionMark(hwnd2Settings);
+ int pos = ListView_GetSelectionMark(hwnd2List);
if (pos != -1) {
- char text[256];
- ListView_GetItemText(hwnd2Settings, pos, 0, text, SIZEOF(text));
- db_set_s(NULL, modname, "LastSetting", text);
+ char data[FLD_SIZE];
+ ListView_GetItemTextA(hwnd2List, pos, 0, data, SIZEOF(data));
+ db_set_s(NULL, modname, "LastSetting", data);
}
else
db_unset(NULL, modname, "LastSetting");
}
}
- db_set_b(NULL, modname, "HexMode", (byte)Hex);
- db_set_b(NULL, modname, "SortMode", (byte)Order);
- saveListSettings(GetDlgItem(hwnd, IDC_SETTINGS));
- hwnd2mainWindow = 0;
- ClearListview(GetDlgItem(hwnd, IDC_SETTINGS));
- freeTree(GetDlgItem(hwnd, IDC_MODULES), 0);
- if (himl)
- ImageList_Destroy(himl);
- if (himl2)
- ImageList_Destroy(himl2);
-
- if (!db_get_b(NULL, modname, "Maximised", 0)) {
- RECT rc;
- GetWindowRect(hwnd, &rc);
- db_set_dw(NULL, modname, "x", rc.left);
- db_set_dw(NULL, modname, "y", rc.top);
- db_set_dw(NULL, modname, "width", rc.right - rc.left);
- db_set_dw(NULL, modname, "height", rc.bottom - rc.top);
- }
- if (hwnd2importWindow) {
- DestroyWindow(hwnd2importWindow);
- hwnd2importWindow = 0;
- }
+ db_set_b(NULL, modname, "HexMode", (byte)g_Hex);
+ db_set_b(NULL, modname, "SortMode", (byte)g_Order);
+ db_set_b(NULL, modname, "DontAllowInLineEdit", (byte)!g_Inline);
+ {
+ WINDOWPLACEMENT wp;
+ wp.length = sizeof(WINDOWPLACEMENT);
+ GetWindowPlacement(hwnd, &wp);
+ if (wp.flags == WPF_RESTORETOMAXIMIZED) {
+ db_set_b(NULL, modname, "Maximized", 1);
+ ShowWindow(hwnd, SW_SHOWNOACTIVATE);
+ } else
+ db_set_b(NULL, modname, "Maximized", 0);
+ Utils_SaveWindowPosition(hwnd, NULL, modname, "Main_");
+ ShowWindow(hwnd, SW_HIDE);
+ }
+
+ saveListSettings(hwnd2List, csSettingList);
+ ClearListView();
+
+ freeTree(0);
+
+ hwnd2mainWindow = NULL;
+ hwnd2Tree = NULL;
+ hwnd2List = NULL;
+
+ if (hImg) {
+ ImageList_Destroy(hImg);
+ hImg = NULL;
+ }
+
+ FreeResidentSettings();
+
if (bServiceMode)
PostQuitMessage(0);
return 0;
@@ -447,30 +404,23 @@ INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
case MENU_REFRESH_SETS:
{
TVITEM tvi;
- ModuleTreeInfoStruct *mtis;
- char module[256];
+
+ TCHAR text[FLD_SIZE];
tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT;
- tvi.hItem = TreeView_GetSelection(GetDlgItem(hwnd, IDC_MODULES));
- tvi.pszText = module;
- tvi.cchTextMax = SIZEOF(module);
- if (!TreeView_GetItem(GetDlgItem(hwnd, IDC_MODULES), &tvi)) break;
- if (tvi.lParam) {
- mtis = (ModuleTreeInfoStruct *)tvi.lParam;
- if (mtis->type == MODULE)
- PopulateSettings(GetDlgItem(hwnd, IDC_SETTINGS), mtis->hContact, module);
- else
- ClearListview(GetDlgItem(hwnd, IDC_SETTINGS));
- }
+ tvi.hItem = TreeView_GetSelection(hwnd2Tree);
+ tvi.pszText = text; // modulename
+ tvi.cchTextMax = SIZEOF(text);
+ if (!TreeView_GetItem(hwnd2Tree, &tvi)) break;
+ ModuleTreeInfoStruct *mtis = (ModuleTreeInfoStruct *)tvi.lParam;
+ if (mtis && (mtis->type == MODULE))
+ PopulateSettings(mtis->hContact, _T2A(text));
else
- ClearListview(GetDlgItem(hwnd, IDC_SETTINGS));
+ ClearListView();
}
break;
///////////////////////// // watches
case MENU_VIEW_WATCHES:
- if (!hwnd2watchedVarsWindow) // so only opens 1 at a time
- hwnd2watchedVarsWindow = CreateDialog(hInst, MAKEINTRESOURCE(IDD_WATCH_DIAG), 0, WatchDlgProc);
- else
- SetForegroundWindow(hwnd2watchedVarsWindow);
+ openWatchedVarWindow();
break;
case MENU_REMALL_WATCHES:
freeAllWatches();
@@ -485,7 +435,7 @@ INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
exportDB(NULL, 0);
break;
case MENU_IMPORTFROMFILE:
- ImportSettingsFromFileMenuItem(NULL, "");
+ ImportSettingsFromFileMenuItem(NULL, NULL);
break;
case MENU_IMPORTFROMTEXT:
ImportSettingsMenuItem(NULL);
@@ -495,52 +445,60 @@ INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
DestroyWindow(hwnd);
break;
case MENU_DELETE:
- deleteModuleGui();
+ deleteModuleDlg();
break;
case MENU_FINDANDREPLACE:
- CreateDialog(hInst, MAKEINTRESOURCE(IDD_FIND), hwnd, FindWindowDlgProc);
+ newFindWindow();
+ break;
+ case MENU_FIX_RESIDENT:
+ if (dlg(TranslateT("Fix resident setting deleting them from DB ?"), MB_YESNO | MB_ICONEXCLAMATION) == IDYES) {
+ int cnt = fixResidentSettings();
+ TCHAR text[MSG_SIZE];
+ mir_sntprintf(text, TranslateT("Deleted orphaned items: %d"), cnt);
+ msg(text);
+ }
break;
case MENU_FILTER_ALL:
- if (Mode != MODE_ALL) {
+ if (g_Mode != MODE_ALL) {
HMENU hMenu = GetMenu(hwnd);
CheckMenuItem(GetSubMenu(hMenu, 5), MENU_FILTER_ALL, MF_BYCOMMAND | MF_CHECKED);
CheckMenuItem(GetSubMenu(hMenu, 5), MENU_FILTER_LOADED, MF_BYCOMMAND | MF_UNCHECKED);
CheckMenuItem(GetSubMenu(hMenu, 5), MENU_FILTER_UNLOADED, MF_BYCOMMAND | MF_UNCHECKED);
- Mode = MODE_ALL;
+ g_Mode = MODE_ALL;
refreshTree(1);
}
break;
case MENU_FILTER_LOADED:
- if (Mode != MODE_LOADED) {
+ if (g_Mode != MODE_LOADED) {
HMENU hMenu = GetMenu(hwnd);
CheckMenuItem(GetSubMenu(hMenu, 5), MENU_FILTER_ALL, MF_BYCOMMAND | MF_UNCHECKED);
CheckMenuItem(GetSubMenu(hMenu, 5), MENU_FILTER_LOADED, MF_BYCOMMAND | MF_CHECKED);
CheckMenuItem(GetSubMenu(hMenu, 5), MENU_FILTER_UNLOADED, MF_BYCOMMAND | MF_UNCHECKED);
- Mode = MODE_LOADED;
+ g_Mode = MODE_LOADED;
refreshTree(1);
}
break;
case MENU_FILTER_UNLOADED:
- if (Mode != MODE_UNLOADED) {
+ if (g_Mode != MODE_UNLOADED) {
HMENU hMenu = GetMenu(hwnd);
CheckMenuItem(GetSubMenu(hMenu, 5), MENU_FILTER_ALL, MF_BYCOMMAND | MF_UNCHECKED);
CheckMenuItem(GetSubMenu(hMenu, 5), MENU_FILTER_LOADED, MF_BYCOMMAND | MF_UNCHECKED);
CheckMenuItem(GetSubMenu(hMenu, 5), MENU_FILTER_UNLOADED, MF_BYCOMMAND | MF_CHECKED);
- Mode = MODE_UNLOADED;
+ g_Mode = MODE_UNLOADED;
refreshTree(1);
}
break;
case MENU_BYTE_HEX:
- Hex ^= HEX_BYTE;
- CheckMenuItem(GetSubMenu(GetMenu(hwnd), 5), MENU_BYTE_HEX, MF_BYCOMMAND | ((Hex & HEX_BYTE) ? MF_CHECKED : MF_UNCHECKED));
+ g_Hex ^= HEX_BYTE;
+ CheckMenuItem(GetSubMenu(GetMenu(hwnd), 5), MENU_BYTE_HEX, MF_BYCOMMAND | ((g_Hex & HEX_BYTE) ? MF_CHECKED : MF_UNCHECKED));
break;
case MENU_WORD_HEX:
- Hex ^= HEX_WORD;
- CheckMenuItem(GetSubMenu(GetMenu(hwnd), 5), MENU_WORD_HEX, MF_BYCOMMAND | ((Hex & HEX_WORD) ? MF_CHECKED : MF_UNCHECKED));
+ g_Hex ^= HEX_WORD;
+ CheckMenuItem(GetSubMenu(GetMenu(hwnd), 5), MENU_WORD_HEX, MF_BYCOMMAND | ((g_Hex & HEX_WORD) ? MF_CHECKED : MF_UNCHECKED));
break;
case MENU_DWORD_HEX:
- Hex ^= HEX_DWORD;
- CheckMenuItem(GetSubMenu(GetMenu(hwnd), 5), MENU_DWORD_HEX, MF_BYCOMMAND | ((Hex & HEX_DWORD) ? MF_CHECKED : MF_UNCHECKED));
+ g_Hex ^= HEX_DWORD;
+ CheckMenuItem(GetSubMenu(GetMenu(hwnd), 5), MENU_DWORD_HEX, MF_BYCOMMAND | ((g_Hex & HEX_DWORD) ? MF_CHECKED : MF_UNCHECKED));
break;
case MENU_SAVE_POSITION:
{
@@ -549,9 +507,12 @@ INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
db_set_b(NULL, modname, "RestoreOnOpen", (byte)save);
}
break;
+ case MENU_INLINE_EDIT:
+ g_Inline = !g_Inline;
+ CheckMenuItem(GetSubMenu(GetMenu(hwnd), 5), MENU_INLINE_EDIT, MF_BYCOMMAND | (g_Inline ? MF_CHECKED: MF_UNCHECKED));
case MENU_SORT_ORDER:
- Order = !Order;
- CheckMenuItem(GetSubMenu(GetMenu(hwnd), 5), MENU_SORT_ORDER, MF_BYCOMMAND | (Order ? MF_CHECKED : MF_UNCHECKED));
+ g_Order = !g_Order;
+ CheckMenuItem(GetSubMenu(GetMenu(hwnd), 5), MENU_SORT_ORDER, MF_BYCOMMAND | (g_Order ? MF_CHECKED : MF_UNCHECKED));
refreshTree(1);
break;
case MENU_OPEN_OPTIONS:
@@ -578,26 +539,19 @@ INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_FINDITEM:
ItemInfo *ii = (ItemInfo *)wParam;
- HWND hwnd2Settings = GetDlgItem(hwnd, IDC_SETTINGS);
- int hItem = findItemInTree(GetDlgItem(hwnd, IDC_MODULES), ii->hContact, ii->module);
- if (hItem != -1) {
- TreeView_SelectItem(GetDlgItem(hwnd, IDC_MODULES), (HTREEITEM)hItem);
- if (ii->type != FW_MODULE) {
- LVITEM lvItem;
- LVFINDINFO lvfi;
-
- lvfi.flags = LVFI_STRING;
- lvfi.psz = ii->setting;
- lvfi.vkDirection = VK_DOWN;
-
- lvItem.mask = LVIF_TEXT | LVIF_IMAGE;
- lvItem.iItem = ListView_FindItem(hwnd2Settings, -1, &lvfi);
- lvItem.iSubItem = 0;
- if (lvItem.iItem >= 0)
- ListView_SetItemState(hwnd2Settings, lvItem.iItem, LVIS_SELECTED, LVIS_SELECTED);
- }
+ HTREEITEM hItem = findItemInTree(ii->hContact, ii->module);
+ if (hItem) {
+ TreeView_SelectItem(hwnd2Tree, hItem);
+ TreeView_Expand(hwnd2Tree, hItem, TVE_EXPAND);
+ if (ii->type != FW_MODULE)
+ SelectSetting(ii->setting);
}
break;
}
return 0;
}
+
+
+void openMainWindow() {
+ CreateDialog(hInst, MAKEINTRESOURCE(IDD_MAIN), 0, MainDlgProc);
+}
diff --git a/plugins/DbEditorPP/src/modsettingenum.cpp b/plugins/DbEditorPP/src/modsettingenum.cpp
index 00bac689c9..332df43032 100644
--- a/plugins/DbEditorPP/src/modsettingenum.cpp
+++ b/plugins/DbEditorPP/src/modsettingenum.cpp
@@ -1,6 +1,7 @@
#include "headers.h"
-void FreeModuleSettingLL(ModuleSettingLL* msll)
+
+void FreeModuleSettingLL(ModuleSettingLL *msll)
{
if (msll == NULL)
return;
@@ -19,7 +20,8 @@ void FreeModuleSettingLL(ModuleSettingLL* msll)
msll->last = 0;
}
-int enumModulesSettingsProc(const char *szName, DWORD, LPARAM lParam)
+
+int enumModulesSettingsProc(const char *setting, DWORD, LPARAM lParam)
{
ModuleSettingLL *msll = (ModuleSettingLL *)lParam;
if (!msll->first) {
@@ -27,7 +29,7 @@ int enumModulesSettingsProc(const char *szName, DWORD, LPARAM lParam)
if (!msll->first)
return 1;
- msll->first->name = mir_tstrdup(szName);
+ msll->first->name = mir_strdup(setting);
msll->first->next = 0;
msll->last = msll->first;
}
@@ -38,25 +40,32 @@ int enumModulesSettingsProc(const char *szName, DWORD, LPARAM lParam)
msll->last->next = item;
msll->last = item;
- item->name = mir_tstrdup(szName);
+ item->name = mir_strdup(setting);
item->next = 0;
}
return 0;
}
+
int EnumModules(ModuleSettingLL *msll) // 1 = success, 0 = fail
{
msll->first = 0;
msll->last = 0;
- return !CallService(MS_DB_MODULES_ENUM, (WPARAM)msll, (WPARAM)enumModulesSettingsProc);
+ if (CallService(MS_DB_MODULES_ENUM, (WPARAM)msll, (WPARAM)enumModulesSettingsProc)) {
+ msg(TranslateT("Error loading module list"));
+ return 0;
+ }
+ return 1;
}
-int enumSettingsProc(const char *szSetting, LPARAM lParam)
+
+int enumSettingsProc(const char *setting, LPARAM lParam)
{
- return enumModulesSettingsProc(szSetting, 0, lParam);
+ return enumModulesSettingsProc(setting, 0, lParam);
}
-int EnumSettings(MCONTACT hContact, char* module, ModuleSettingLL *msll)
+
+int EnumSettings(MCONTACT hContact, const char *module, ModuleSettingLL *msll)
{
DBCONTACTENUMSETTINGS dbces;
// enum all setting the contact has for the module
@@ -65,18 +74,200 @@ int EnumSettings(MCONTACT hContact, char* module, ModuleSettingLL *msll)
dbces.lParam = (LPARAM)msll;
msll->first = 0;
msll->last = 0;
- return !CallService(MS_DB_CONTACT_ENUMSETTINGS, hContact, (LPARAM)&dbces);
+ if (CallService(MS_DB_CONTACT_ENUMSETTINGS, hContact, (LPARAM)&dbces)) {
+ msg(TranslateT("Error loading setting list"));
+ return 0;
+ }
+ return 1;
}
+
int CheckIfModuleIsEmptyProc(const char *, LPARAM)
{
return 1;
}
-bool IsModuleEmpty(MCONTACT hContact, char* szModule)
+
+int IsModuleEmpty(MCONTACT hContact, const char *module)
{
DBCONTACTENUMSETTINGS dbces;
dbces.pfnEnumProc = CheckIfModuleIsEmptyProc;
- dbces.szModule = szModule;
+ dbces.szModule = module;
return 0 > CallService(MS_DB_CONTACT_ENUMSETTINGS, hContact, (LPARAM)&dbces);
}
+
+
+static int stringCompare(const char *p1, const char *p2)
+{
+ return mir_strcmp(p1, p2);
+}
+
+
+LIST<char> m_lResidentSettings(10, stringCompare);
+LIST<char> m_lResidentModules(5, stringCompare);
+
+
+int enumResidentProc(const char *setting, DWORD, LPARAM)
+{
+ m_lResidentSettings.insert(mir_strdup(setting));
+
+ char str[FLD_SIZE];
+ const char *end = strstr(setting, "/");
+ if (end && (end - setting) < SIZEOF(str)) {
+ mir_strncpy(str, setting, end - setting + 1);
+ if (m_lResidentModules.getIndex(str) == -1)
+ m_lResidentModules.insert(mir_strdup(str));
+ }
+ return 0;
+}
+
+
+int LoadResidentSettings()
+{
+ if (g_db)
+ return !g_db->EnumResidentSettings(enumResidentProc, 0);
+ return 0;
+}
+
+
+void FreeResidentSettings()
+{
+ for (int i = 0; i < m_lResidentSettings.getCount(); i++) {
+ mir_free(m_lResidentSettings[i]);
+ }
+ m_lResidentSettings.destroy();
+
+ for (int i = 0; i < m_lResidentModules.getCount(); i++) {
+ mir_free(m_lResidentModules[i]);
+ }
+ m_lResidentModules.destroy();
+}
+
+
+int IsResidentSetting(const char *module, const char *setting)
+{
+ if (!m_lResidentSettings.getCount()) return 0;
+
+ if (m_lResidentModules.getIndex((char*)module) == -1) return 0;
+ if (!setting) return 1;
+
+ char str[2*FLD_SIZE];
+ mir_strncpy(str, module, SIZEOF(str)-1);
+ mir_strcat(str, "/");
+ mir_strncat(str, setting, SIZEOF(str));
+ return m_lResidentSettings.getIndex(str) != -1;
+}
+
+
+int EnumResidentSettings(const char *module, ModuleSettingLL *msll)
+{
+ msll->first = 0;
+ msll->last = 0;
+
+ if (!module) return 0;
+ if (!m_lResidentSettings.getCount()) return 0;
+ if (m_lResidentModules.getIndex((char*)module) == -1) return 0;
+
+ int len = mir_strlen(module);
+ int cnt = 0;
+
+ for (int i = 0; i < m_lResidentSettings.getCount(); i++) {
+ if (strncmp(module, m_lResidentSettings[i], len))
+ continue;
+
+ if (m_lResidentSettings[i][len] != '/' || m_lResidentSettings[i][len+1] == 0) continue;
+
+ enumModulesSettingsProc(&m_lResidentSettings[i][len+1], 0, (LPARAM)msll);
+ cnt++;
+ }
+ return cnt;
+}
+
+
+int EnumResidentModules(ModuleSettingLL *msll)
+{
+ msll->first = 0;
+ msll->last = 0;
+
+ if (!m_lResidentModules.getCount()) return 0;
+
+ int cnt = 0;
+
+ for (int i = 0; i < m_lResidentModules.getCount(); i++) {
+ enumModulesSettingsProc(m_lResidentModules[i], 0, (LPARAM)msll);
+ cnt++;
+ }
+
+ return cnt;
+}
+
+
+static int fixing = 0;
+
+// previously saved in DB resident settings are unaccessible.
+// so let's find them and delete from DB
+int fixResidentSettings()
+{
+ if (!m_lResidentSettings.getCount() || fixing) return 0;
+
+ ModuleSettingLL ModuleList, SettingList;
+ ModSetLinkLinkItem *module, *setting;
+ MCONTACT hContact = 0;
+ int NULLContactDone = 0;
+ char str[2*FLD_SIZE];
+ int cnt = 0;
+
+ if (!EnumModules(&ModuleList)) return 0;
+
+ fixing = 1;
+
+ while (hwnd2mainWindow) {
+
+ if (!hContact) {
+ if (NULLContactDone)
+ break;
+ else {
+ NULLContactDone = 1;
+ hContact = db_find_first();
+ }
+ }
+ else
+ hContact = db_find_next(hContact);
+
+ for (module = ModuleList.first; module; module = module->next) {
+
+ if (IsModuleEmpty(hContact, module->name) || m_lResidentModules.getIndex(module->name) == -1)
+ continue;
+
+ if (!EnumSettings(hContact, module->name, &SettingList))
+ continue;
+
+ for (setting = SettingList.first; setting; setting = setting->next) {
+
+ mir_strncpy(str, module->name, SIZEOF(str)-1);
+ mir_strcat(str, "/");
+ mir_strncat(str, setting->name, SIZEOF(str));
+ int idx = m_lResidentSettings.getIndex(str);
+
+ if (idx == -1)
+ continue;
+
+ g_db->SetSettingResident(0, str);
+ db_unset(hContact, module->name, setting->name);
+ g_db->SetSettingResident(1, str);
+
+ cnt++;
+
+ } // for(setting)
+
+ FreeModuleSettingLL(&SettingList);
+
+ } // for(module)
+ }
+
+ FreeModuleSettingLL(&ModuleList);
+
+ fixing = 0;
+
+ return cnt;
+}
diff --git a/plugins/DbEditorPP/src/modsettingenum.h b/plugins/DbEditorPP/src/modsettingenum.h
deleted file mode 100644
index f46d991ac1..0000000000
--- a/plugins/DbEditorPP/src/modsettingenum.h
+++ /dev/null
@@ -1,18 +0,0 @@
-struct ModSetLinkLinkItem
-{
- char *name;
- ModSetLinkLinkItem *next;
-};
-
-struct ModuleSettingLL
-{
- ModSetLinkLinkItem *first;
- ModSetLinkLinkItem *last;
-};
-
-int EnumModules(ModuleSettingLL *msll);
-int EnumSettings(MCONTACT hContact, char *module, ModuleSettingLL *msll);
-
-void FreeModuleSettingLL(ModuleSettingLL *msll);
-
-bool IsModuleEmpty(MCONTACT hContact, char *szModule);
diff --git a/plugins/DbEditorPP/src/modules.cpp b/plugins/DbEditorPP/src/modules.cpp
deleted file mode 100644
index f0793a9853..0000000000
--- a/plugins/DbEditorPP/src/modules.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-#include "headers.h"
-
-void renameModule(char* oldName, char* newName, MCONTACT hContact)
-{
- DBVARIANT dbv;
- ModuleSettingLL settinglist;
- ModSetLinkLinkItem *setting;
-
- if (!EnumSettings(hContact, oldName, &settinglist)) { msg(Translate("Error Loading Setting List"), modFullname); return; }
-
- setting = settinglist.first;
- while (setting) {
- if (!GetSetting(hContact, oldName, setting->name, &dbv)) {
- switch (dbv.type) {
- case DBVT_BYTE:
- db_set_b(hContact, newName, setting->name, dbv.bVal);
- break;
- case DBVT_WORD:
- db_set_w(hContact, newName, setting->name, dbv.wVal);
- break;
- case DBVT_DWORD:
- db_set_dw(hContact, newName, setting->name, dbv.dVal);
- break;
- case DBVT_ASCIIZ:
- db_set_s(hContact, newName, setting->name, dbv.pszVal);
- break;
- case DBVT_UTF8:
- db_set_utf(hContact, newName, setting->name, dbv.pszVal);
- break;
- case DBVT_BLOB:
- db_set_blob(hContact, newName, setting->name, dbv.pbVal, dbv.cpbVal);
- break;
-
- }
- db_unset(hContact, oldName, setting->name);
- }
- db_free(&dbv);
- setting = (ModSetLinkLinkItem *)setting->next;
- }
- FreeModuleSettingLL(&settinglist);
-}
-
-INT_PTR CALLBACK AddModDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- if (msg == WM_INITDIALOG) {
- SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
- TranslateDialogDefault(hwnd);
- }
-
- if (msg == WM_COMMAND) {
- switch (LOWORD(wParam)) {
- case IDOK:
- if (GetWindowTextLength(GetDlgItem(hwnd, IDC_MODNAME))) {
- char modulename[256];
- GetDlgItemText(hwnd, IDC_MODNAME, modulename, SIZEOF(modulename));
- if (IsDlgButtonChecked(hwnd, CHK_ADD2ALL)) {
- // null contact
- db_set_b(NULL, modulename, "(Default)", 0);
- for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
- db_set_b(hContact, modulename, "(Default)", 0);
- }
- else db_set_b((MCONTACT)GetWindowLongPtr(hwnd, GWLP_USERDATA), modulename, "(Default)", 0);
-
- refreshTree(1);
- }
- // fall through
- case IDCANCEL:
- DestroyWindow(hwnd);
- break;
- }
- }
- return 0;
-}
-
-int CloneContact(MCONTACT hContact)
-{
- MCONTACT newContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
- if (!newContact)
- return 0;
-
- // enum all the modules
- ModuleSettingLL modlist;
- if (!EnumModules(&modlist)) {
- msg(Translate("Error loading module list"), modFullname);
- return 0;
- }
-
- ModSetLinkLinkItem *mod = modlist.first;
- while (mod) {
- copyModule(mod->name, hContact, newContact);
- mod = (ModSetLinkLinkItem *)mod->next;
- }
- FreeModuleSettingLL(&modlist);
- return 1;
-}
diff --git a/plugins/DbEditorPP/src/moduletree.cpp b/plugins/DbEditorPP/src/moduletree.cpp
index 151a081de3..5aaf0b7616 100644
--- a/plugins/DbEditorPP/src/moduletree.cpp
+++ b/plugins/DbEditorPP/src/moduletree.cpp
@@ -1,41 +1,56 @@
#include "headers.h"
-static BOOL populating = 0;
-int Select = 0;
+HWND hwnd2Tree = 0;
+
+volatile BOOL populating = 0;
+volatile int Select = 0;
+
static ModuleTreeInfoStruct contacts_mtis = { CONTACT_ROOT_ITEM, 0 };
static ModuleTreeInfoStruct settings_mtis = { CONTACT, 0 };
-int doContacts(HWND hwnd2Tree, HTREEITEM contactsRoot, ModuleSettingLL *modlist, MCONTACT hSelectedContact, char *SelectedModule, char *SelectedSetting)
+
+void insertItem(MCONTACT hContact, const char *module, HTREEITEM hParent)
+{
+ _A2T text(module);
+
+ TVINSERTSTRUCT tvi;
+ tvi.hParent = hParent;
+ tvi.hInsertAfter = TVI_SORT;
+ tvi.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
+ tvi.item.pszText = text;
+
+ ModuleTreeInfoStruct *lParam = (ModuleTreeInfoStruct *)mir_calloc(sizeof(ModuleTreeInfoStruct));
+ lParam->hContact = hContact;
+
+ tvi.item.iImage = IMAGE_CLOSED;
+ tvi.item.iSelectedImage = IMAGE_OPENED;
+ lParam->type = MODULE;
+
+ tvi.item.lParam = (LPARAM)lParam;
+ TreeView_InsertItem(hwnd2Tree, &tvi);
+}
+
+
+int doContacts(HTREEITEM contactsRoot, ModuleSettingLL *modlist, MCONTACT hSelectedContact, const char *selectedModule, const char *selectedSetting)
{
TVINSERTSTRUCT tvi;
HTREEITEM contact;
ModuleTreeInfoStruct *lParam;
- ModSetLinkLinkItem *module;
int itemscount = 0;
- int loaded, i = 0, icon = 0;
- int hItem = -1;
+ int i = 0, icon = 0;
+ HTREEITEM hItem = 0;
- SetWindowText(hwnd2mainWindow, Translate("Loading contacts..."));
+ SetWindowText(hwnd2mainWindow, TranslateT("Loading contacts..."));
tvi.hInsertAfter = TVI_SORT;
tvi.item.cChildren = 1;
+
+ char szProto[FLD_SIZE];
+ TCHAR name[NAME_SIZE];
for (MCONTACT hContact = db_find_first(); hContact && hwnd2mainWindow; hContact = db_find_next(hContact)) {
- char szProto[100];
- if (DBGetContactSettingStringStatic(hContact, "Protocol", "p", szProto, SIZEOF(szProto))) {
- icon = GetProtoIcon(szProto);
- loaded = (icon != DEF_ICON);
- }
- else {
- icon = DEF_ICON;
- loaded = 0;
- }
-
- i++;
-
- // filter
- if ((loaded && Mode == MODE_UNLOADED) || (!loaded && Mode == MODE_LOADED))
- continue;
+
+ if (ApplyProtoFilter(hContact)) continue;
// add the contact
lParam = (ModuleTreeInfoStruct *)mir_calloc(sizeof(ModuleTreeInfoStruct));
@@ -48,82 +63,50 @@ int doContacts(HWND hwnd2Tree, HTREEITEM contactsRoot, ModuleSettingLL *modlist,
if (hSelectedContact != hContact)
lParam->type |= EMPTY;
- // contacts name
- WCHAR nick[256];
- WCHAR protoW[256]; // unicode proto
+ if (db_get_static(hContact, "Protocol", "p", szProto, SIZEOF(szProto)))
+ szProto[0] = 0;
- if (szProto)
- a2u(szProto, protoW, SIZEOF(protoW));
- else
- protoW[0] = 0;
+ icon = GetProtoIconIndex(szProto);
- if (!szProto || !loaded) {
- tvi.item.iSelectedImage = (tvi.item.iImage = 4);
+ GetContactName(hContact, szProto, name, SIZEOF(name));
- if (protoW) {
- if (Order)
- mir_snwprintf(nick, SIZEOF(nick), L"(%s) %s %s", protoW, GetContactName(hContact, szProto, 1), L"(UNLOADED)");
- else
- mir_snwprintf(nick, SIZEOF(nick), L"%s (%s) %s", GetContactName(hContact, szProto, 1), protoW, L"(UNLOADED)");
- }
- else
- mir_wstrcpy(nick, nick_unknownW);
- }
- else {
- tvi.item.iSelectedImage = (tvi.item.iImage = icon); //GetProtoIcon(szProto, 7));
- if (Order)
- mir_snwprintf(nick, SIZEOF(nick), L"(%s) %s", protoW, GetContactName(hContact, szProto, 1));
- else
- mir_snwprintf(nick, SIZEOF(nick), L"%s (%s)", GetContactName(hContact, szProto, 1), protoW);
- }
+ tvi.item.pszText = name;
+ tvi.item.iImage = icon;
+ tvi.item.iSelectedImage = icon;
- tvi.item.pszText = (char *)nick;
- contact = TreeView_InsertItemW(hwnd2Tree, &tvi);
+ contact = TreeView_InsertItem(hwnd2Tree, &tvi);
itemscount++;
if (hSelectedContact == hContact) {
- module = modlist->first;
- while (module && hwnd2mainWindow) {
- if (module->name[0] && !IsModuleEmpty(hContact, module->name)) {
- tvi.hParent = contact;
- tvi.hInsertAfter = TVI_SORT;
- tvi.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
- tvi.item.pszText = module->name;
-
- lParam = (ModuleTreeInfoStruct *)mir_calloc(sizeof(ModuleTreeInfoStruct));
- lParam->hContact = hContact;
-
- tvi.item.iImage = 1;
- tvi.item.iSelectedImage = 2;
- lParam->type = KNOWN_MODULE;
-
- tvi.item.lParam = (LPARAM)lParam;
- TreeView_InsertItem(hwnd2Tree, &tvi);
- }
- module = (ModSetLinkLinkItem *)module->next;
+
+ for (ModSetLinkLinkItem *module = modlist->first; module && hwnd2mainWindow; module = module->next) {
+ if (!module->name[0] || IsModuleEmpty(hContact, module->name))
+ continue;
+ insertItem(hContact, module->name, contact);
}
- hItem = findItemInTree(hwnd2Tree, hSelectedContact, SelectedModule);
+ hItem = findItemInTree(hSelectedContact, selectedModule);
}
}
- if (hItem != -1) {
- TreeView_SelectItem(hwnd2Tree, (HTREEITEM)hItem);
+ if (hItem) {
+ TreeView_SelectItem(hwnd2Tree, hItem);
TreeView_Expand(hwnd2Tree, hItem, TVE_EXPAND);
- if (SelectedSetting[0])
- SelectSetting(SelectedSetting);
+ if (selectedSetting && selectedSetting[0])
+ SelectSetting(selectedSetting);
}
return itemscount;
}
-void doItems(HWND hwnd2Tree, ModuleSettingLL *modlist, int count)
+
+void doItems(ModuleSettingLL* modlist, int count)
{
- HWND hwnd = GetParent(hwnd2Tree);
+ HWND hwnd = GetParent(hwnd2Tree); //!!!
- char percent[96], title[64];
- mir_snprintf(title, SIZEOF(title), Translate("Loading modules..."));
+ TCHAR percent[128], title[96];
+ mir_sntprintf(title, TranslateT("Loading modules..."));
TVITEM item = { 0 };
item.mask = TVIF_STATE | TVIF_PARAM;
@@ -148,45 +131,34 @@ void doItems(HWND hwnd2Tree, ModuleSettingLL *modlist, int count)
continue;
// Caption
- mir_snprintf(percent, SIZEOF(percent), "%s %d%%", title, (int)(100 * i / count));
+ mir_sntprintf(percent, _T("%s %d%%"), title, (int)(100 * i / count));
SetWindowText(hwnd, percent);
for (ModSetLinkLinkItem *module = modlist->first; module && hwnd2mainWindow; module = module->next) {
if (!module->name[0] || IsModuleEmpty(hContact, module->name))
continue;
- TVINSERTSTRUCT tvi;
- tvi.hParent = item.hItem;
- tvi.hInsertAfter = TVI_SORT;
- tvi.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
- tvi.item.pszText = module->name;
-
- ModuleTreeInfoStruct *lParam = (ModuleTreeInfoStruct *)mir_calloc(sizeof(ModuleTreeInfoStruct));
- lParam->hContact = hContact;
-
- tvi.item.iImage = 1;
- tvi.item.iSelectedImage = 2;
- lParam->type = KNOWN_MODULE;
-
- tvi.item.lParam = (LPARAM)lParam;
- TreeView_InsertItem(hwnd2Tree, &tvi);
+ insertItem(hContact, module->name, item.hItem);
}
}
- SetWindowText(hwnd, TranslateT("Database Editor++"));
+ SetWindowText(hwnd2mainWindow, TranslateT("Database Editor++"));
}
// the following code to go through the whole tree is nicked from codeguru..
// http://www.codeguru.com/Cpp/controls/treeview/treetraversal/comments.php/c683/?thread=7680
-int findItemInTree(HWND hwnd2Tree, MCONTACT hContact, char *module)
+HTREEITEM findItemInTree(MCONTACT hContact, const char* module)
{
TVITEM item;
- char text[265];
HTREEITEM lastItem;
+ TCHAR text[FLD_SIZE];
+
if (!TreeView_GetCount(hwnd2Tree))
return 0;
+ _A2T szModule(module);
+
item.mask = TVIF_STATE | TVIF_PARAM | TVIF_TEXT;
item.hItem = TVI_ROOT;
item.pszText = text;
@@ -197,9 +169,9 @@ int findItemInTree(HWND hwnd2Tree, MCONTACT hContact, char *module)
if (lastItem != TVI_ROOT) {
/* these next 2 lines are not from code guru..... */
if (TreeView_GetItem(hwnd2Tree, &item) && item.lParam) {
- if ((hContact == ((ModuleTreeInfoStruct *)item.lParam)->hContact) && (!module[0] || !mir_strcmp(module, text))) {
- //TreeView_SelectItem(hwnd2Tree,item.hItem);
- return (int)item.hItem;
+ if ((hContact == ((ModuleTreeInfoStruct *)item.lParam)->hContact) && (!module || !module[0] || !mir_tstrcmp(szModule, text))) {
+ return item.hItem;
+
}
}
/* back to coduguru's code*/
@@ -209,13 +181,14 @@ int findItemInTree(HWND hwnd2Tree, MCONTACT hContact, char *module)
while ((!(item.hItem = TreeView_GetNextSibling(hwnd2Tree, lastItem))) && (lastItem = item.hItem = TreeView_GetParent(hwnd2Tree, lastItem)));
} while (item.hItem);
- return -1;
+
+ return 0;
}
// the following code to go through the whole tree is nicked from codeguru..
// http://www.codeguru.com/Cpp/controls/treeview/treetraversal/comments.php/c683/?thread=7680
-void freeTree(HWND hwnd2Tree, MCONTACT hContact)
+void freeTree(MCONTACT hContact)
{
TVITEM item;
HTREEITEM lastItem;
@@ -251,17 +224,20 @@ void freeTree(HWND hwnd2Tree, MCONTACT hContact)
} while (item.hItem);
}
-BOOL findAndRemoveDuplicates(HWND hwnd2Tree, MCONTACT hContact, char *module)
+BOOL findAndRemoveDuplicates(MCONTACT hContact, const char *module)
/* the following code to go through the whole tree is nicked from codeguru..
http://www.codeguru.com/Cpp/controls/treeview/treetraversal/comments.php/c683/?thread=7680 */
{
TVITEM item;
HTREEITEM lastItem, prelastItem;
BOOL Result = 0;
- char text[265];
+ TCHAR text[FLD_SIZE];
+
if (!TreeView_GetCount(hwnd2Tree))
return Result;
+ _A2T szModule(module);
+
item.mask = TVIF_STATE | TVIF_PARAM | TVIF_TEXT;
item.hItem = TVI_ROOT;
item.pszText = text;
@@ -276,7 +252,7 @@ http://www.codeguru.com/Cpp/controls/treeview/treetraversal/comments.php/c683/?t
/* these next lines are not from code guru..... */
if (item.lParam) {
ModuleTreeInfoStruct *mtis = (ModuleTreeInfoStruct *)item.lParam;
- if (hContact == mtis->hContact && !mir_strcmp(text, module)) {
+ if (hContact == mtis->hContact && !mir_tstrcmp(text, szModule)) {
mir_free(mtis);
TreeView_DeleteItem(hwnd2Tree, item.hItem);
lastItem = prelastItem;
@@ -298,89 +274,63 @@ http://www.codeguru.com/Cpp/controls/treeview/treetraversal/comments.php/c683/?t
}
-void replaceTreeItem(HWND hwnd, MCONTACT hContact, const char *module, const char *newModule)
+void replaceTreeItem(MCONTACT hContact, const char* module, const char* newModule)
{
- int hItem = findItemInTree(hwnd, hContact, (char *)module);
- HTREEITEM hParent;
+ HTREEITEM hItem = findItemInTree(hContact, module);
- if (hItem == -1)
+ if (!hItem)
return;
- hParent = TreeView_GetParent(hwnd, (HTREEITEM)hItem);
-
- {
- TVITEM item;
- item.mask = TVIF_PARAM;
- item.hItem = (HTREEITEM)hItem;
-
- if (TreeView_GetItem(hwnd, &item))
- mir_free((ModuleTreeInfoStruct *)item.lParam);
- TreeView_DeleteItem(hwnd, item.hItem);
- }
+ TVITEM item;
+ item.mask = TVIF_PARAM;
+ item.hItem = hItem;
- if (hParent && newModule) {
- TVINSERTSTRUCT tvi = { 0 };
- ModuleTreeInfoStruct *lParam;
+ HTREEITEM hParent = TreeView_GetParent(hwnd2Tree, hItem);
- tvi.hParent = hParent;
- tvi.hInsertAfter = TVI_SORT;
- tvi.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
- tvi.item.pszText = (char *)newModule;
+ if (TreeView_GetItem(hwnd2Tree, &item))
+ mir_free((ModuleTreeInfoStruct *)item.lParam);
- lParam = (ModuleTreeInfoStruct *)mir_calloc(sizeof(ModuleTreeInfoStruct));
- lParam->hContact = hContact;
- lParam->type = KNOWN_MODULE;
- tvi.item.iImage = 1;
- tvi.item.iSelectedImage = 2;
+ TreeView_DeleteItem(hwnd2Tree, item.hItem);
- tvi.item.lParam = (LPARAM)lParam;
+ if (!newModule)
+ return;
- TreeView_InsertItem(hwnd, &tvi);
+ if (hParent) {
+ replaceTreeItem(hContact, newModule, NULL);
+ insertItem(hContact, newModule, hParent);
}
}
-void refreshTree(int restore)
-{
- if (populating)
- return;
- populating = 1;
- forkthread(PopulateModuleTreeThreadFunc, 0, (HWND)restore);
-}
-void __cdecl PopulateModuleTreeThreadFunc(LPVOID di)
+void __cdecl PopulateModuleTreeThreadFunc(LPVOID param)
{
TVINSERTSTRUCT tvi;
- HWND hwnd2Tree = GetDlgItem(hwnd2mainWindow, IDC_MODULES);
- char SelectedModule[256] = { 0 };
- char SelectedSetting[256] = { 0 };
+ char SelectedModule[FLD_SIZE] = "";
+ char SelectedSetting[FLD_SIZE] = "";
+
MCONTACT hSelectedContact = hRestore;
MCONTACT hContact;
HTREEITEM contact, contactsRoot;
int count;
- // item lParams
- ModuleTreeInfoStruct *lParam;
-
// module list
- ModSetLinkLinkItem *module;
ModuleSettingLL modlist;
hRestore = NULL;
- if (!hwnd2Tree) {
- msg(Translate("Module tree not found"), modFullname);
+ if (!hwnd2Tree)
return;
- }
Select = 0;
- switch ((int)di) {
+ switch ((int)param) {
case 1: // restore after rebuild
if (HTREEITEM item = TreeView_GetSelection(hwnd2Tree)) {
+ TCHAR text[FLD_SIZE];
TVITEM tvi = { 0 };
tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT;
- tvi.pszText = SelectedModule;
- tvi.cchTextMax = SIZEOF(SelectedModule);
+ tvi.pszText = text;
+ tvi.cchTextMax = SIZEOF(text);
tvi.hItem = item;
TreeView_GetItem(hwnd2Tree, &tvi);
@@ -389,17 +339,19 @@ void __cdecl PopulateModuleTreeThreadFunc(LPVOID di)
hSelectedContact = mtis->hContact;
if (mtis->type == CONTACT)
SelectedModule[0] = 0;
+ else
+ mir_strncpy(SelectedModule, _T2A(text), SIZEOF(SelectedModule));
Select = 1;
}
}
break;
case 2: // restore saved
- if (GetValue(NULL, modname, "LastModule", SelectedModule, SIZEOF(SelectedModule))) {
+ if (GetValueA(NULL, modname, "LastModule", SelectedModule, SIZEOF(SelectedModule))) {
hSelectedContact = db_get_dw(NULL, modname, "LastContact", INVALID_CONTACT_ID);
if (hSelectedContact != INVALID_CONTACT_ID)
Select = 1;
- GetValue(NULL, modname, "LastSetting", SelectedSetting, SIZEOF(SelectedSetting));
+ GetValueA(NULL, modname, "LastSetting", SelectedSetting, SIZEOF(SelectedSetting));
}
break;
@@ -410,20 +362,15 @@ void __cdecl PopulateModuleTreeThreadFunc(LPVOID di)
break;
}
- if ((int)di != 4) { // do not rebuild on just going to another setting
- if (!EnumModules(&modlist)) {
- msg(Translate("Error loading module list"), modFullname);
+ if ((int)param != 4) { // do not rebuild on just going to another setting
+ if (!EnumModules(&modlist))
return;
- }
// remove all items (incase there are items there...
- freeTree(hwnd2Tree, 0);
+ freeTree(0);
TreeView_DeleteAllItems(hwnd2Tree);
TreeView_SelectItem(hwnd2Tree, 0);
- //image list
- TreeView_SetImageList(hwnd2Tree, himl, TVSIL_NORMAL);
-
/// contact root item
contacts_mtis.type = CONTACT_ROOT_ITEM;
tvi.item.lParam = (LPARAM)&contacts_mtis;
@@ -434,9 +381,9 @@ void __cdecl PopulateModuleTreeThreadFunc(LPVOID di)
tvi.item.cChildren = 1;
tvi.hInsertAfter = TVI_FIRST;
- tvi.item.pszText = Translate("Contacts");
- tvi.item.iImage = 3;
- tvi.item.iSelectedImage = 3;
+ tvi.item.pszText = TranslateT("Contacts");
+ tvi.item.iImage = IMAGE_CONTACTS;
+ tvi.item.iSelectedImage = IMAGE_CONTACTS;
contactsRoot = TreeView_InsertItem(hwnd2Tree, &tvi);
// add the settings item
@@ -446,9 +393,9 @@ void __cdecl PopulateModuleTreeThreadFunc(LPVOID di)
tvi.item.cChildren = 1;
tvi.hParent = NULL;
tvi.hInsertAfter = TVI_FIRST;
- tvi.item.pszText = Translate("Settings");
- tvi.item.iImage = 0;
- tvi.item.iSelectedImage = 0;
+ tvi.item.pszText = TranslateT("Settings");
+ tvi.item.iImage = IMAGE_SETTINGS;
+ tvi.item.iSelectedImage = IMAGE_SETTINGS;
contact = TreeView_InsertItem(hwnd2Tree, &tvi);
// to fix bug with CHANGE NOTIFY on window activation
@@ -456,34 +403,19 @@ void __cdecl PopulateModuleTreeThreadFunc(LPVOID di)
settings_mtis.type = CONTACT;
hContact = 0;
- module = modlist.first;
- while (module) {
- if (!IsModuleEmpty(hContact, module->name)) {
- tvi.hParent = contact;
- tvi.hInsertAfter = TVI_SORT;
- tvi.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
- tvi.item.pszText = module->name;
-
- lParam = (ModuleTreeInfoStruct *)mir_calloc(sizeof(ModuleTreeInfoStruct));
- lParam->hContact = hContact;
- tvi.item.iImage = 1;
- tvi.item.iSelectedImage = 2;
- lParam->type = KNOWN_MODULE;
-
- tvi.item.lParam = (LPARAM)lParam;
-
- TreeView_InsertItem(hwnd2Tree, &tvi);
- }
- module = (ModSetLinkLinkItem *)module->next;
+ for (ModSetLinkLinkItem *module = modlist.first; module && hwnd2mainWindow; module = module->next) {
+ if (!module->name[0] || IsModuleEmpty(hContact, module->name))
+ continue;
+ insertItem(hContact, module->name, contact);
}
if (db_get_b(NULL, modname, "ExpandSettingsOnOpen", 0))
TreeView_Expand(hwnd2Tree, contact, TVE_EXPAND);
if (Select && hSelectedContact == NULL) {
- int hItem = findItemInTree(hwnd2Tree, hSelectedContact, SelectedModule);
- if (hItem != -1) {
- TreeView_SelectItem(hwnd2Tree, (HTREEITEM)hItem);
+ HTREEITEM hItem = findItemInTree(hSelectedContact, SelectedModule);
+ if (hItem) {
+ TreeView_SelectItem(hwnd2Tree, hItem);
TreeView_Expand(hwnd2Tree, hItem, TVE_EXPAND);
if (SelectedSetting[0])
SelectSetting(SelectedSetting);
@@ -491,17 +423,17 @@ void __cdecl PopulateModuleTreeThreadFunc(LPVOID di)
Select = 0;
}
- count = doContacts(hwnd2Tree, contactsRoot, &modlist, Select ? hSelectedContact : NULL, SelectedModule, SelectedSetting);
+ count = doContacts(contactsRoot, &modlist, Select ? hSelectedContact : NULL, SelectedModule, SelectedSetting);
Select = 0;
- doItems(hwnd2Tree, &modlist, count);
+ doItems(&modlist, count);
FreeModuleSettingLL(&modlist);
}
if (Select) {
- int hItem = findItemInTree(hwnd2Tree, hSelectedContact, SelectedModule);
- if (hItem != -1) {
- TreeView_SelectItem(hwnd2Tree, (HTREEITEM)hItem);
+ HTREEITEM hItem = findItemInTree(hSelectedContact, SelectedModule);
+ if (hItem) {
+ TreeView_SelectItem(hwnd2Tree, hItem);
TreeView_Expand(hwnd2Tree, hItem, TVE_EXPAND);
if (SelectedSetting[0])
SelectSetting(SelectedSetting);
@@ -512,6 +444,15 @@ void __cdecl PopulateModuleTreeThreadFunc(LPVOID di)
}
+void refreshTree(int restore)
+{
+ if (populating)
+ return;
+ populating = 1;
+ mir_forkthread(PopulateModuleTreeThreadFunc, (HWND)restore);
+}
+
+
static LRESULT CALLBACK ModuleTreeLabelEditSubClassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
@@ -534,42 +475,21 @@ void moduleListRightClick(HWND hwnd, WPARAM wParam, LPARAM lParam);
void moduleListWM_NOTIFY(HWND hwnd, UINT, WPARAM wParam, LPARAM lParam)// hwnd here is to the main window, NOT the treview
{
switch (((NMHDR *)lParam)->code) {
- case TVN_ITEMEXPANDINGA:
- case TVN_ITEMEXPANDINGW:
+ case TVN_ITEMEXPANDING:
if (populating && ((LPNMTREEVIEW)lParam)->action == TVE_EXPAND) {
ModuleTreeInfoStruct *mtis = (ModuleTreeInfoStruct *)((LPNMTREEVIEW)lParam)->itemNew.lParam;
if (mtis && (mtis->type == (CONTACT | EMPTY))) {
- TVINSERTSTRUCT tvi;
- ModuleTreeInfoStruct *_lParam;
- HWND hwnd2Tree = GetDlgItem(hwnd2mainWindow, IDC_MODULES);
- ModSetLinkLinkItem *module;
- ModuleSettingLL modlist;
MCONTACT hContact = mtis->hContact;
-
mtis->type = CONTACT;
- if (!EnumModules(&modlist)) {
- msg(Translate("Error loading module list"), modFullname);
+ ModuleSettingLL modlist;
+ if (!EnumModules(&modlist))
break;
- }
- module = modlist.first;
+ ModSetLinkLinkItem *module = modlist.first;
while (module && hwnd2mainWindow) {
if (module->name[0] && !IsModuleEmpty(hContact, module->name)) {
- tvi.hParent = ((LPNMTREEVIEW)lParam)->itemNew.hItem;
- tvi.hInsertAfter = TVI_SORT;
- tvi.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
- tvi.item.pszText = module->name;
-
- _lParam = (ModuleTreeInfoStruct *)mir_calloc(sizeof(ModuleTreeInfoStruct));
- _lParam->hContact = hContact;
-
- tvi.item.iImage = 5;
- tvi.item.iSelectedImage = 6;
- _lParam->type = KNOWN_MODULE;
-
- tvi.item.lParam = (LPARAM)_lParam;
- TreeView_InsertItem(hwnd2Tree, &tvi);
+ insertItem(hContact, module->name, ((LPNMTREEVIEW)lParam)->itemNew.hItem);
}
module = (ModSetLinkLinkItem *)module->next;
}
@@ -579,23 +499,22 @@ void moduleListWM_NOTIFY(HWND hwnd, UINT, WPARAM wParam, LPARAM lParam)// hwnd h
}
break;
- case TVN_SELCHANGEDA:
- case TVN_SELCHANGEDW:
+ case TVN_SELCHANGED:
{
- ModuleTreeInfoStruct *mtis;
LPNMTREEVIEW pnmtv = (LPNMTREEVIEW)lParam;
TVITEM tvi = { 0 };
- char text[264];
+ TCHAR text[FLD_SIZE];
MCONTACT hContact;
- HWND hwnd2Settings = GetDlgItem(hwnd, IDC_SETTINGS);
tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT;
tvi.hItem = pnmtv->itemNew.hItem;
tvi.pszText = text;
tvi.cchTextMax = SIZEOF(text);
TreeView_GetItem(pnmtv->hdr.hwndFrom, &tvi);
+
+ ModuleTreeInfoStruct *mtis = (ModuleTreeInfoStruct *)tvi.lParam;
- if (tvi.lParam) {
- mtis = (ModuleTreeInfoStruct *)tvi.lParam;
+ if (mtis) {
+
hContact = mtis->hContact;
if (mtis->type == STUB)
@@ -605,28 +524,14 @@ void moduleListWM_NOTIFY(HWND hwnd, UINT, WPARAM wParam, LPARAM lParam)// hwnd h
Select = 0;
if (mtis->type == MODULE) {
- SettingListInfo *info = (SettingListInfo *)GetWindowLongPtr(hwnd2Settings, GWLP_USERDATA);
- BOOL refresh = 1;
-
- if (info) {
- if (info->hContact == hContact && !mir_strcmp(info->module, text))
- refresh = 0;
- }
-
- if (refresh)
- PopulateSettings(hwnd2Settings, hContact, text);
+ _T2A module(text);
+ PopulateSettings(hContact, module);
}
- else if (((mtis->type & CONTACT) == CONTACT && hContact) || (mtis->type == CONTACT_ROOT_ITEM && !hContact)) {
- char data[32], szProto[256];
- int index, loaded, multi = 0;
- LVITEM lvi = { 0 };
- lvi.mask = LVIF_IMAGE | LVIF_TEXT | LVIF_PARAM;
- lvi.iImage = 6;
-
- ClearListview(hwnd2Settings);
- SetWindowLongPtr(hwnd2Settings, GWLP_USERDATA, 0);
- if (himl2)
- ListView_SetImageList(hwnd2Settings, himl2, LVSIL_SMALL);
+ else
+ if (((mtis->type & CONTACT) == CONTACT && hContact) || (mtis->type == CONTACT_ROOT_ITEM && !hContact)) {
+ int multi = 0;
+
+ ClearListView();
if (mtis->type == CONTACT_ROOT_ITEM && !hContact) {
multi = 1;
@@ -634,41 +539,26 @@ void moduleListWM_NOTIFY(HWND hwnd, UINT, WPARAM wParam, LPARAM lParam)// hwnd h
}
while (hContact && hwnd2mainWindow) {
- if (multi) {
- // filter
- if (GetValue(hContact, "Protocol", "p", szProto, SIZEOF(szProto)))
- loaded = IsProtocolLoaded(szProto);
- else
- loaded = 0;
-
- if ((loaded && Mode == MODE_UNLOADED) || (!loaded && Mode == MODE_LOADED)) {
- hContact = db_find_next(hContact);
- continue;
- }
- }
-
- lvi.iItem = 0;
- lvi.pszText = (char *)GetContactName(hContact, NULL, FALSE);
-
- index = ListView_InsertItem(hwnd2Settings, &lvi);
- mir_snprintf(data, SIZEOF(data), "0x%08X (%ld)", hContact, hContact);
+ if (multi && ApplyProtoFilter(hContact)) {
+ hContact = db_find_next(hContact);
+ continue;
+ }
- ListView_SetItemText(hwnd2Settings, index, 1, data);
- ListView_SetItemText(hwnd2Settings, index, 2, Translate("HANDLE"));
- ListView_SetItemText(hwnd2Settings, index, 3, "0x0004 (4)");
+ addListHandle(hContact);
- if (!multi)
+ if (!multi) {
break;
+ }
hContact = db_find_next(hContact);
}
}
else
- ClearListview(hwnd2Settings);
+ ClearListView();
}
- else // clear any settings that may be there...
- ClearListview(hwnd2Settings);
+ else
+ ClearListView();
}
break; //TVN_SELCHANGED:
@@ -677,12 +567,11 @@ void moduleListWM_NOTIFY(HWND hwnd, UINT, WPARAM wParam, LPARAM lParam)// hwnd h
moduleListRightClick(hwnd, wParam, lParam);
break;
- case TVN_BEGINLABELEDITA: // subclass it..
- case TVN_BEGINLABELEDITW:
+ case TVN_BEGINLABELEDIT: // subclass it..
{
LPNMTVDISPINFO ptvdi = (LPNMTVDISPINFO)lParam;
ModuleTreeInfoStruct *mtis = (ModuleTreeInfoStruct *)ptvdi->item.lParam;
- HWND hwnd2Edit = TreeView_GetEditControl(GetDlgItem(hwnd, IDC_MODULES));
+ HWND hwnd2Edit = TreeView_GetEditControl(hwnd2Tree);
if (!mtis->type || (mtis->type == CONTACT)) {
SetWindowLongPtr(hwnd, DWLP_MSGRESULT, TRUE);
break;
@@ -692,12 +581,10 @@ void moduleListWM_NOTIFY(HWND hwnd, UINT, WPARAM wParam, LPARAM lParam)// hwnd h
}
break;
- case TVN_ENDLABELEDITA:
- case TVN_ENDLABELEDITW:
+ case TVN_ENDLABELEDIT:
LPNMTVDISPINFO ptvdi = (LPNMTVDISPINFO)lParam;
TVITEM tvi = { 0 };
- char text[264];
- char *newtext;
+ TCHAR text[FLD_SIZE];
ModuleTreeInfoStruct *mtis;
tvi.mask = TVIF_HANDLE | TVIF_TEXT | TVIF_PARAM;
tvi.hItem = ptvdi->item.hItem;
@@ -706,32 +593,23 @@ void moduleListWM_NOTIFY(HWND hwnd, UINT, WPARAM wParam, LPARAM lParam)// hwnd h
TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom, &tvi);
mtis = (ModuleTreeInfoStruct *)ptvdi->item.lParam;
- newtext = u2a((WCHAR *)ptvdi->item.pszText);
+ _T2A newtext(ptvdi->item.pszText);
+ _T2A oldtext(tvi.pszText);
if (!newtext // edit control failed
|| !mtis->type // its a root item
|| mtis->type == CONTACT // its a contact
- || *newtext == 0) // empty string
+ || newtext[0] == 0) // empty string
SetWindowLongPtr(hwnd, DWLP_MSGRESULT, FALSE);
else {
- if (mir_strcmp(tvi.pszText, newtext)) {
- renameModule(tvi.pszText, newtext, mtis->hContact);
-
- findAndRemoveDuplicates(((LPNMHDR)lParam)->hwndFrom, mtis->hContact, newtext);
-
- if (TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom, &tvi)) {
- tvi.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
- tvi.iImage = 1;
- tvi.iSelectedImage = 2;
- TreeView_SetItem(((LPNMHDR)lParam)->hwndFrom, &tvi);
-
- PopulateSettings(GetDlgItem(hwnd, IDC_SETTINGS), mtis->hContact, newtext);
- }
+ if (mir_strcmp(oldtext, newtext)) {
+ renameModule(mtis->hContact, oldtext, newtext);
+ findAndRemoveDuplicates(mtis->hContact, newtext);
+ if (TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom, &tvi))
+ PopulateSettings(mtis->hContact, newtext);
}
SetWindowLongPtr(hwnd, DWLP_MSGRESULT, TRUE);
}
-
- mir_free(newtext);
break;
}
}
@@ -743,177 +621,173 @@ void moduleListRightClick(HWND hwnd, WPARAM, LPARAM lParam) // hwnd here is to t
hti.pt.y = (short)HIWORD(GetMessagePos());
ScreenToClient(((LPNMHDR)lParam)->hwndFrom, &hti.pt);
- if (TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom, &hti)) {
- if (hti.flags & TVHT_ONITEM) {
- TVITEM tvi = { 0 };
- HMENU hMenu, hSubMenu;
- int menuNumber;
- char module[256];
- tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT;
- tvi.hItem = hti.hItem;
- tvi.pszText = module;
- tvi.cchTextMax = SIZEOF(module);
- TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom, &tvi);
- if (tvi.lParam) {
- ModuleTreeInfoStruct *mtis = (ModuleTreeInfoStruct *)tvi.lParam;
- MCONTACT hContact = mtis->hContact;
- GetCursorPos(&hti.pt);
- hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_CONTEXTMENU));
- TranslateMenu(hMenu);
- if (mtis->type == CONTACT && hContact)
- menuNumber = 2;
- else if ((mtis->type == MODULE) && !hContact)
- menuNumber = 1;
- else if (mtis->type == CONTACT && !hContact)
- menuNumber = 3;
- else if (mtis->type == CONTACT_ROOT_ITEM && !hContact)
- menuNumber = 4;
- else if ((mtis->type == MODULE) && hContact)
- menuNumber = 5;
- else return;
- hSubMenu = GetSubMenu(hMenu, menuNumber);
-
- TranslateMenu(hSubMenu);
- switch (menuNumber) {
- case 1: // null module
- case 5: // contact module
- {
- // check if we r already watching the module
- int i = 0, watching = 0;
- // check if the setting is being watched and if it is then check the menu item
- if (WatchListArray.item)
- for (i = 0; i < WatchListArray.count; i++)
- if (WatchListArray.item[i].module && (hContact == WatchListArray.item[i].hContact)) {
- if (!mir_strcmp(module, WatchListArray.item[i].module) && !WatchListArray.item[i].setting) {
- // yes so uncheck it
- CheckMenuItem(hSubMenu, MENU_WATCH_ITEM, MF_CHECKED | MF_BYCOMMAND);
- watching = 1;
- break;
- }
- }
-
- switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, hti.pt.x, hti.pt.y, 0, hwnd, NULL)) {
- case MENU_RENAME_MOD:
- TreeView_EditLabel(GetDlgItem(hwnd, IDC_MODULES), tvi.hItem);
- break;
-
- case MENU_DELETE_MOD:
- if (deleteModule(module, hContact, 0)) {
- TreeView_DeleteItem(((LPNMHDR)lParam)->hwndFrom, hti.hItem);
- mir_free(mtis);
- }
- break;
+ if (!TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom, &hti) || !(hti.flags & TVHT_ONITEM)) return;
- case MENU_COPY_MOD:
- copyModuleMenuItem(module, hContact);
- break;
+ TVITEM tvi = { 0 };
+ HMENU hMenu, hSubMenu;
+ int menuNumber;
+ TCHAR text[FLD_SIZE];
- ////////////////////////////////////////////////////////////////////// divider
- case MENU_WATCH_ITEM:
- if (!watching)
- addSettingToWatchList(hContact, module, 0);
- else
- freeWatchListItem(i);
- if (hwnd2watchedVarsWindow)
- PopulateWatchedWindow(GetDlgItem(hwnd2watchedVarsWindow, IDC_VARS));
- break;
-
- case MENU_EXPORTMODULE:
- exportDB(hContact, module);
- break;
-
- case MENU_EXPORTDB:
- exportDB(INVALID_CONTACT_ID, module);
- break;
- }
- }
- break;
+ tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT;
+ tvi.hItem = hti.hItem;
+ tvi.pszText = text;
+ tvi.cchTextMax = SIZEOF(text);
+ TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom, &tvi);
- case 2: // contact
- switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, hti.pt.x, hti.pt.y, 0, hwnd, NULL)) {
- case MENU_CLONE_CONTACT:
- if (CloneContact(hContact))
- refreshTree(1);
- break;
-
- case MENU_DELETE_CONTACT:
- if (db_get_b(NULL, "CList", "ConfirmDelete", 1)) {
- char msg[1024];
- mir_snprintf(msg, SIZEOF(msg), Translate("Are you sure you want to delete contact \"%s\"?"), module);
- if (MessageBox(0, msg, Translate("Confirm contact delete"), MB_YESNO | MB_ICONEXCLAMATION) == IDYES) {
- CallService(MS_DB_CONTACT_DELETE, hContact, 0);
- freeTree(((LPNMHDR)lParam)->hwndFrom, hContact);
- TreeView_DeleteItem(((LPNMHDR)lParam)->hwndFrom, tvi.hItem);
- }
- }
- else {
- CallService(MS_DB_CONTACT_DELETE, hContact, 0);
- freeTree(((LPNMHDR)lParam)->hwndFrom, hContact);
- TreeView_DeleteItem(((LPNMHDR)lParam)->hwndFrom, tvi.hItem);
- }
- break;
-
- ////////////////////////////////////////////////////////////////////// divider
- case MENU_EXPORTCONTACT:
- exportDB(hContact, 0);
- break;
- case MENU_IMPORTFROMTEXT:
- ImportSettingsMenuItem(hContact);
- break;
- case MENU_IMPORTFROMFILE:
- ImportSettingsFromFileMenuItem(hContact, "");
- break;
-
- ////////////////////////////////////////////////////////////////////// divider
- case MENU_ADD_MODULE:
- {
- HWND AddModhwnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_ADD_MODULE), hwnd, AddModDlgProc, hContact);
- char msg[1024];
- mir_snprintf(msg, SIZEOF(msg), Translate("Add module to contact \"%s\""), module);
- SetWindowText(AddModhwnd, module);
- }
- break;
- }
- break;
+ if (!tvi.lParam) return;
- case 3: // NULL contact
- switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, hti.pt.x, hti.pt.y, 0, hwnd, NULL)) {
- case MENU_ADD_MODULE:
- {
- HWND AddModhwnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_ADD_MODULE), hwnd, AddModDlgProc, hContact);
- char msg[1024];
- mir_snprintf(msg, SIZEOF(msg), Translate("Add module to contact \"%s\""), module);
- SetWindowText(AddModhwnd, module);
- }
- break;
- case MENU_EXPORTCONTACT:
- exportDB(NULL, 0);
- break;
- case MENU_IMPORTFROMTEXT:
- ImportSettingsMenuItem(NULL);
- break;
- case MENU_IMPORTFROMFILE:
- ImportSettingsFromFileMenuItem(NULL, "");
- break;
- }
- break;
+ _T2A module(text);
+ ModuleTreeInfoStruct *mtis = (ModuleTreeInfoStruct *)tvi.lParam;
- case 4: // Contacts root
- switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, hti.pt.x, hti.pt.y, 0, hwnd, NULL)) {
- case MENU_EXPORTCONTACT:
- exportDB(INVALID_CONTACT_ID, "");
- break;
- case MENU_IMPORTFROMTEXT:
- ImportSettingsMenuItem(NULL);
- break;
- case MENU_IMPORTFROMFILE:
- ImportSettingsFromFileMenuItem(NULL, "");
- break;
- }
+ MCONTACT hContact = mtis->hContact;
+ GetCursorPos(&hti.pt);
+
+ hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_CONTEXTMENU));
+ TranslateMenu(hMenu);
+
+ if (mtis->type == CONTACT && hContact)
+ menuNumber = 2;
+ else if ((mtis->type == MODULE) && !hContact)
+ menuNumber = 1;
+ else if (mtis->type == CONTACT && !hContact)
+ menuNumber = 3;
+ else if (mtis->type == CONTACT_ROOT_ITEM && !hContact)
+ menuNumber = 4;
+ else if ((mtis->type == MODULE) && hContact)
+ menuNumber = 5;
+ else return;
+
+ hSubMenu = GetSubMenu(hMenu, menuNumber);
+
+ TranslateMenu(hSubMenu);
+ switch (menuNumber) {
+ case 1: // null module
+ case 5: // contact module
+ {
+ // check if the setting is being watched and if it is then check the menu item
+ int watchIdx = WatchedArrayIndex(hContact, module, NULL, 1);
+ if (watchIdx >= 0)
+ CheckMenuItem(hSubMenu, MENU_WATCH_ITEM, MF_CHECKED | MF_BYCOMMAND);
+
+ switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, hti.pt.x, hti.pt.y, 0, hwnd, NULL)) {
+ case MENU_RENAME_MOD:
+ TreeView_EditLabel(hwnd2Tree, tvi.hItem);
+ break;
+
+ case MENU_DELETE_MOD:
+ if (deleteModule(hContact, module, 1)) {
+ TreeView_DeleteItem(((LPNMHDR)lParam)->hwndFrom, hti.hItem);
+ mir_free(mtis);
+ }
+ break;
+
+ case MENU_COPY_MOD:
+ copyModuleMenuItem(hContact, module);
+ break;
+
+ ////////////////////////////////////////////////////////////////////// divider
+ case MENU_WATCH_ITEM:
+ if (watchIdx < 0)
+ addSettingToWatchList(hContact, module, 0);
+ else
+ freeWatchListItem(watchIdx);
+ PopulateWatchedWindow();
+ break;
+
+ case MENU_REFRESH:
+ refreshTree(1);
+ break;
+
+ case MENU_EXPORTMODULE:
+ exportDB(hContact, module);
+ break;
+
+ case MENU_EXPORTDB:
+ exportDB(INVALID_CONTACT_ID, module);
+ break;
+ }
+ }
+ break;
+
+ case 2: // contact
+ switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, hti.pt.x, hti.pt.y, 0, hwnd, NULL)) {
+ case MENU_CLONE_CONTACT:
+ if (CloneContact(hContact))
+ refreshTree(1);
+ break;
+
+ case MENU_DELETE_CONTACT:
+ if (db_get_b(NULL, "CList", "ConfirmDelete", 1)) {
+ TCHAR str[MSG_SIZE];
+ mir_sntprintf(str, TranslateT("Are you sure you want to delete contact \"%s\"?"), text);
+ if (dlg(str, MB_YESNO | MB_ICONEXCLAMATION) == IDNO)
break;
- }
- DestroyMenu(hMenu);
}
+ CallService(MS_DB_CONTACT_DELETE, hContact, 0);
+ freeTree(hContact);
+ TreeView_DeleteItem(hwnd2Tree, tvi.hItem);
+ break;
+
+ ////////////////////////////////////////////////////////////////////// divider
+ case MENU_EXPORTCONTACT:
+ exportDB(hContact, 0);
+ break;
+ case MENU_IMPORTFROMTEXT:
+ ImportSettingsMenuItem(hContact);
+ break;
+ case MENU_IMPORTFROMFILE:
+ ImportSettingsFromFileMenuItem(hContact, NULL);
+ break;
+
+ ////////////////////////////////////////////////////////////////////// divider
+ case MENU_ADD_MODULE:
+ addModuleDlg(hContact);
+ break;
+
+ case MENU_REFRESH:
+ refreshTree(1);
+ break;
+
}
+ break;
+
+ case 3: // NULL contact
+ switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, hti.pt.x, hti.pt.y, 0, hwnd, NULL)) {
+ case MENU_ADD_MODULE:
+ addModuleDlg(hContact);
+ break;
+ case MENU_EXPORTCONTACT:
+ exportDB(NULL, 0);
+ break;
+ case MENU_IMPORTFROMTEXT:
+ ImportSettingsMenuItem(NULL);
+ break;
+ case MENU_IMPORTFROMFILE:
+ ImportSettingsFromFileMenuItem(NULL, NULL);
+ break;
+ case MENU_REFRESH:
+ refreshTree(1);
+ break;
+ }
+ break;
+
+ case 4: // Contacts root
+ switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, hti.pt.x, hti.pt.y, 0, hwnd, NULL)) {
+ case MENU_EXPORTCONTACT:
+ exportDB(INVALID_CONTACT_ID, 0);
+ break;
+ case MENU_IMPORTFROMTEXT:
+ ImportSettingsMenuItem(NULL);
+ break;
+ case MENU_IMPORTFROMFILE:
+ ImportSettingsFromFileMenuItem(NULL, NULL);
+ break;
+ case MENU_REFRESH:
+ refreshTree(1);
+ break;
+ }
+ break;
}
+ DestroyMenu(hMenu);
+
}
diff --git a/plugins/DbEditorPP/src/options.cpp b/plugins/DbEditorPP/src/options.cpp
index 2662c222a5..d53cd27050 100644
--- a/plugins/DbEditorPP/src/options.cpp
+++ b/plugins/DbEditorPP/src/options.cpp
@@ -63,11 +63,11 @@ INT OptInit(WPARAM wParam, LPARAM)
{
OPTIONSDIALOGPAGE odp = { 0 };
odp.hInstance = hInst;
- odp.pszTemplate = MAKEINTRESOURCE(IDD_OPTIONS);
+ odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS);
odp.pszGroup = LPGEN("Database");
odp.pszTitle = modFullname;
odp.pfnDlgProc = DlgProcOpts;
odp.flags = ODPF_BOLDGROUPS;
Options_AddPage(wParam, &odp);
return 0;
-} \ No newline at end of file
+}
diff --git a/plugins/DbEditorPP/src/renamemodule.cpp b/plugins/DbEditorPP/src/renamemodule.cpp
new file mode 100644
index 0000000000..fca6c7d3cc
--- /dev/null
+++ b/plugins/DbEditorPP/src/renamemodule.cpp
@@ -0,0 +1,70 @@
+#include "headers.h"
+
+
+int renameModule(MCONTACT hContact, const char *oldName, const char *newName)
+{
+ DBVARIANT dbv;
+ ModuleSettingLL settinglist;
+
+ if (IsModuleEmpty(hContact, oldName) || !EnumSettings(hContact, oldName, &settinglist))
+ return 0;
+
+ int cnt = 0;
+
+ for(ModSetLinkLinkItem *setting = settinglist.first; setting; setting = setting->next) {
+ if (!db_get_s(hContact, oldName, setting->name, &dbv, 0)) {
+ db_set(hContact, newName, setting->name, &dbv);
+ db_unset(hContact, oldName, setting->name);
+ db_free(&dbv);
+ cnt++;
+ }
+ }
+ FreeModuleSettingLL(&settinglist);
+ return cnt;
+}
+
+INT_PTR CALLBACK AddModDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch (msg) {
+ case WM_INITDIALOG:
+ SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
+ TranslateDialogDefault(hwnd);
+
+ TCHAR msg[MSG_SIZE], name[NAME_SIZE];
+ GetContactName((MCONTACT)lParam, NULL, name, SIZEOF(name));
+
+ mir_sntprintf(msg, TranslateT("Add module to \"%s\""), name);
+ SetWindowText(hwnd, msg);
+
+ break;
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDOK:
+ if (GetWindowTextLength(GetDlgItem(hwnd, IDC_MODNAME))) {
+ char modulename[FLD_SIZE];
+ GetDlgItemTextA(hwnd, IDC_MODNAME, modulename, SIZEOF(modulename));
+ if (IsDlgButtonChecked(hwnd, CHK_ADD2ALL)) {
+ // null contact
+ db_set_b(NULL, modulename, "(Default)", 0);
+ for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
+ db_set_b(hContact, modulename, "(Default)", 0);
+ }
+ else
+ db_set_b((MCONTACT)GetWindowLongPtr(hwnd, GWLP_USERDATA), modulename, "(Default)", 0);
+
+ refreshTree(1);
+ }
+ // fall through
+ case IDCANCEL:
+ DestroyWindow(hwnd);
+ break;
+ }
+ }
+ return 0;
+}
+
+
+void addModuleDlg(MCONTACT hContact)
+{
+ CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_ADD_MODULE), hwnd2mainWindow, AddModDlgProc, hContact);
+}
diff --git a/plugins/DbEditorPP/src/resource.h b/plugins/DbEditorPP/src/resource.h
index 6c2cafe832..f8e379b8c5 100644
--- a/plugins/DbEditorPP/src/resource.h
+++ b/plugins/DbEditorPP/src/resource.h
@@ -1,6 +1,6 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
-// Used by ..\res\resource.rc
+// Used by E:\Miranda\NG\plugins\DbeditorPP\res\resource.rc
//
#define ICO_REGEDIT 1
#define ICO_UNICODE 2
@@ -12,6 +12,7 @@
#define ICO_BYTE 8
#define ICO_WORD 9
#define ICO_HANDLE 10
+#define ICO_EMPTY 11
#define IDD_MAIN 101
#define IDR_MAINMENU 103
#define IDR_CONTEXTMENU 104
@@ -27,8 +28,8 @@
#define IDD_CHANGE_ARRAYSIZE 120
#define IDD_FIND 121
#define IDD_OPTIONS 122
-#define ICO_KNOWN 124
-#define ICO_KNOWNOPEN 125
+#define ICO_CLOSED 124
+#define ICO_OPENED 125
#define ICO_SETTINGS 128
#define ICO_ONLINE 129
#define IDC_MODULES 1000
@@ -69,6 +70,7 @@
#define IDC_SEARCH 1042
#define IDC_EXACT 1043
#define IDC_EXPANDSETTINGS 1044
+#define IDC_SEARCH2 1045
#define IDC_WARNONDEL 1047
#define IDC_POPUPS 1048
#define IDC_POPUPTIMEOUT 1049
@@ -92,6 +94,7 @@
#define MENU_DELETE_SET 40012
#define MENU_DELETE_MOD 40013
#define MENU_CREATE_MOD 40014
+#define MENU_COPY_SET 40015
#define MENU_VIEW_WATCHES 40016
#define MENU_REMALL_WATCHES 40017
#define MENU_ADD_WATCH 40018
@@ -106,6 +109,7 @@
#define MENU_ADD_DWORD 40026
#define MENU_ADD_STRING 40027
#define MENU_SAVE_WATCHES 40028
+#define MENU_INLINE_EDIT 40029
#define MENU_RENAME_MOD 40030
#define MENU_COPY_MOD 40032
#define MENU_USE_MODLIST 40033
@@ -120,10 +124,7 @@
#define MENU_WARNONDEL 40042
#define MENU_LOAD_WATCHES 40043
#define MENU_WORD_HEX 40044
-#define MENU_DECRYPT 40045
-#define MENU_ENCRYPT 40046
-#define MENU_VIEWDECRYPT 40047
-#define MENU_VIEWENCRYPT 40048
+#define MENU_FIX_RESIDENT 40045
#define MENU_LOGTODISK 40049
#define MENU_FINDANDREPLACE 40050
#define MENU_FINDMODSETTING 40051
diff --git a/plugins/DbEditorPP/src/settinglist.cpp b/plugins/DbEditorPP/src/settinglist.cpp
index 2f903bb431..f815ebbbbf 100644
--- a/plugins/DbEditorPP/src/settinglist.cpp
+++ b/plugins/DbEditorPP/src/settinglist.cpp
@@ -1,75 +1,151 @@
#include "headers.h"
-void setupSettingsList(HWND hwnd2List)
-{
- ListView_SetUnicodeFormat(hwnd2List, TRUE);
-
- LVCOLUMN sLC;
- sLC.fmt = LVCFMT_LEFT;
- ListView_SetExtendedListViewStyle(hwnd2List, 32 | LVS_EX_SUBITEMIMAGES); //LVS_EX_FULLROWSELECT
- sLC.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH;
-
- sLC.pszText = Translate("Name");
- sLC.cx = db_get_w(NULL, modname, "Column0width", 145);
- ListView_InsertColumn(hwnd2List, 0, &sLC);
- sLC.pszText = Translate("Data");
- sLC.cx = db_get_w(NULL, modname, "Column1width", 145);
- ListView_InsertColumn(hwnd2List, 1, &sLC);
- sLC.pszText = Translate("Type");
- sLC.cx = db_get_w(NULL, modname, "Column2width", 60);
- ListView_InsertColumn(hwnd2List, 2, &sLC);
- sLC.pszText = Translate("Size");
- sLC.cx = db_get_w(NULL, modname, "Column3width", 80);
- ListView_InsertColumn(hwnd2List, 3, &sLC);
+
+SettingListInfo info = {0};
+HWND hwnd2List = 0;
+
+
+static int lastColumn = -1;
+
+
+struct ColumnsSettings csSettingList[] = {
+ { LPGENT("Name"), 0, "Column0width", 180 },
+ { LPGENT("Value"), 1, "Column1width", 250 },
+ { LPGENT("Type"), 2, "Column2width", 60 },
+ { LPGENT("Size"), 3, "Column3width", 80 },
+ { LPGENT("#"), 4, "Column4width", 30 },
+ {0}
+};
+
+
+int ListView_GetItemTextA(HWND hwndLV, int i, int iSubItem, char *pszText, int cchTextMax)
+{
+ LV_ITEMA lvi;
+ lvi.iSubItem = iSubItem;
+ lvi.cchTextMax = cchTextMax;
+ lvi.pszText = pszText;
+ return SendMessageA((hwndLV), LVM_GETITEMTEXTA, (WPARAM)(i), (LPARAM)(LV_ITEMA *)&lvi);
+}
+
+
+int ListView_SetItemTextA(HWND hwndLV, int i, int iSubItem, const char *pszText)
+{
+ LV_ITEMA lvi;
+ lvi.iSubItem = iSubItem;
+ lvi.pszText = (char*)pszText;
+ return SendMessageA((hwndLV), LVM_SETITEMTEXTA, (WPARAM)(i), (LPARAM)(LV_ITEMA *)&lvi);
}
-void saveListSettings(HWND hwnd2List)
+
+int convertSetting(MCONTACT hContact, const char *module, const char *setting, int toType)
{
- LVCOLUMN sLC = { 0 };
- char tmp[33]; tmp[32] = 0;
+ DBVARIANT dbv = { 0 };
- sLC.mask = LVCF_WIDTH;
+ if (db_get_s(hContact, module, setting, &dbv, 0)) return 0;
- for (int i = 0; i <= 3; i++)
- if (ListView_GetColumn(hwnd2List, i, &sLC)) {
- mir_snprintf(tmp, "Column%dwidth", i);
- db_set_w(NULL, modname, tmp, (WORD)sLC.cx);
- }
+ if (dbv.type == toType) {
+ db_free(&dbv);
+ return 1;
+ }
+
+ int res = 0;
+ DWORD val = 0;
+ TCHAR tmp[16];
+ ptrT value;
+
+ switch (dbv.type) {
+
+ case DBVT_BYTE:
+ case DBVT_WORD:
+ case DBVT_DWORD:
+ val = getNumericValue(&dbv);
+ value = mir_tstrdup(_ultot(val, tmp, 10));
+ break;
+
+ case DBVT_WCHAR:
+ if (!value) value = mir_u2t(dbv.pwszVal);
+ case DBVT_UTF8:
+ if (!value) value = mir_utf8decodeT(dbv.pszVal);
+ case DBVT_ASCIIZ:
+ if (!value) value = mir_a2t(dbv.pszVal);
+
+ if (mir_tstrlen(value) < 11)
+ val = _tcstoul(value, NULL, NULL);
+ break;
+ }
+
+ switch (toType) {
+
+ case DBVT_BYTE:
+ case DBVT_WORD:
+ case DBVT_DWORD:
+ if (val != 0 || !mir_tstrcmp(value, _T("0")))
+ res = setNumericValue(hContact, module, setting, val, toType);
+ break;
+
+ case DBVT_ASCIIZ:
+ case DBVT_UTF8:
+ case DBVT_WCHAR:
+ if (value)
+ res = setTextValue(hContact, module, setting, value, toType);
+ break;
+
+ }
+
+ if (!res)
+ msg(TranslateT("Unable to store value in this data type!"));
+
+ db_free(&dbv);
+
+ return res;
}
-void ClearListview(HWND hwnd2Settings)
+void EditFinish(int selected)
{
- SettingListInfo *info = (SettingListInfo*)GetWindowLongPtr(hwnd2Settings, GWLP_USERDATA);
- if (info && ListView_GetItemCount(hwnd2Settings)) {
- mir_free(info->module);
- if (info->hwnd2Edit) {
- SendMessage(info->hwnd2Edit, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), 0);
- info->hwnd2Edit = NULL;
- }
- mir_free(info);
- SetWindowLongPtr(hwnd2Settings, GWLP_USERDATA, 0);
+ if (info.hwnd2Edit) {
+ SendMessage(info.hwnd2Edit, WM_COMMAND, MAKEWPARAM(IDOK, 0), 0);
+ info.hwnd2Edit = NULL;
}
- ListView_DeleteAllItems(hwnd2Settings);
+ info.selectedItem = selected;
}
-void DeleteSettingsFromList(HWND hSettings, MCONTACT hContact, char *module, char *setting)
+
+void ClearListView()
{
- int count = ListView_GetSelectedCount(hSettings);
+ EditFinish(0);
+ info.module[0] = 0;
+ info.setting[0] = 0;
+ info.hContact = 0;
+
+ ListView_DeleteAllItems(hwnd2List);
+}
+
+
+void DeleteSettingsFromList(MCONTACT hContact, const char *module, const char *setting)
+{
+ int count = ListView_GetSelectedCount(hwnd2List);
if (!count) return;
+ if (db_get_b(NULL, modname, "WarnOnDelete", 1)) {
+ TCHAR text[MSG_SIZE];
+ mir_sntprintf(text, TranslateT("Are you sure you want to delete setting(s): %d?"), count);
+ if (dlg(text, MB_YESNO | MB_ICONEXCLAMATION) == IDNO)
+ return;
+ }
+
if (count == 1)
db_unset(hContact, module, setting);
else {
- int items = ListView_GetItemCount(hSettings);
+ int items = ListView_GetItemCount(hwnd2List);
int i = 0;
- char text[256];
+ char text[FLD_SIZE];
while (i < items) {
- if (ListView_GetItemState(hSettings, i, LVIS_SELECTED)) {
- ListView_GetItemText(hSettings, i, 0, text, SIZEOF(text));
- db_unset(hContact, module, text);
+ if (ListView_GetItemState(hwnd2List, i, LVIS_SELECTED)) {
+ if (ListView_GetItemTextA(hwnd2List, i, 0, text, SIZEOF(text)))
+ db_unset(hContact, module, text);
items--;
}
else
@@ -77,246 +153,277 @@ void DeleteSettingsFromList(HWND hSettings, MCONTACT hContact, char *module, cha
}
}
- if (ListView_GetItemCount(hSettings) == 0) {
- HWND hModules = GetDlgItem(hwnd2mainWindow, IDC_MODULES);
- TVITEM item;
- char text[265];
- item.mask = TVIF_PARAM | TVIF_TEXT;
- item.pszText = text;
- item.cchTextMax = SIZEOF(text);
- item.hItem = (HTREEITEM)findItemInTree(hModules, hContact, module);
- if ((int)item.hItem != -1)
- if (TreeView_GetItem(hModules, &item) && item.lParam) {
- mir_free((char*)item.lParam);
- TreeView_DeleteItem(hModules, item.hItem);
- }
- }
+ if (ListView_GetItemCount(hwnd2List) == 0)
+ replaceTreeItem(hContact, module, 0);
}
-void additem(HWND hwnd2Settings, MCONTACT hContact, char* module, char* setting, int index)
+
+int findListItem(const char *setting)
{
- char *data = NULL;
- LVITEM lvi;
- lvi.mask = LVIF_IMAGE;
- lvi.iItem = index;
- lvi.iSubItem = 0;
+ if (!setting || !setting[0]) return -1;
- if (g_db && g_db->IsSettingEncrypted(module, setting)) {
- lvi.iImage = 5;
- ListView_SetItem(hwnd2Settings, &lvi);
+ LVFINDINFOA lvfi;
+ lvfi.flags = LVFI_STRING;
+ lvfi.psz = setting;
+ lvfi.vkDirection = VK_DOWN;
+ return SendMessageA(hwnd2List, LVM_FINDITEMA, -1, (LPARAM)&lvfi);
+}
- ListView_SetItemTextW(hwnd2Settings, index, 1, TranslateW(L"*** encrypted ***"));
- ListView_SetItemText(hwnd2Settings, index, 2, Translate("UNICODE"));
- ListView_SetItemText(hwnd2Settings, index, 3, "");
+void deleteListItem(const char *setting)
+{
+ int item = findListItem(setting);
+ if (item > -1)
+ ListView_DeleteItem(hwnd2List, item);
+}
+
+
+void updateListItem(int index, const char *setting, DBVARIANT *dbv, int resident)
+{
+ if (!dbv || !dbv->type) {
+ ListView_DeleteItem(hwnd2List, index);
return;
}
- DBVARIANT dbv = { 0 };
- if (!GetSetting(hContact, module, setting, &dbv)) {
- switch (dbv.type) {
- case DBVT_BLOB:
- if (!(data = (char*)mir_realloc(data, 3 * (dbv.cpbVal + 1) + 10))) {
- msg(Translate("Couldn't allocate enough memory!"), modFullname); return;
- }
- data[0] = '\0';
- for (int j = 0; j < dbv.cpbVal; j++) {
- char tmp[16];
- mir_snprintf(tmp, "%02X ", (BYTE)dbv.pbVal[j]);
- mir_strcat(data, tmp);
- }
- lvi.iImage = 0;
- ListView_SetItem(hwnd2Settings, &lvi);
- ListView_SetItemText(hwnd2Settings, index, 1, data);
- ListView_SetItemText(hwnd2Settings, index, 2, Translate("BLOB"));
- mir_snprintf(data, 3 * (dbv.cpbVal + 1) + 10, "0x%04X (%d)", dbv.cpbVal, dbv.cpbVal);
- ListView_SetItemText(hwnd2Settings, index, 3, data);
- break;
+ if (index < 0) return;
- case DBVT_BYTE:
- if (!(data = (char*)mir_realloc(data, 16))) // 0x00 (000)
- return;
- lvi.iImage = 1;
- ListView_SetItem(hwnd2Settings, &lvi);
- mir_snprintf(data, 16, "0x%02X (%d)", dbv.bVal, dbv.bVal);
- ListView_SetItemText(hwnd2Settings, index, 1, data);
- ListView_SetItemText(hwnd2Settings, index, 2, Translate("BYTE"));
- ListView_SetItemText(hwnd2Settings, index, 3, "0x0001 (1)");
- break;
+ LVITEM lvi = {0};
+ lvi.mask = LVIF_IMAGE;
+ lvi.iItem = index;
- case DBVT_WORD:
- if (!(data = (char*)mir_realloc(data, 16))) // 0x0000 (00000)
- return;
-
- lvi.iImage = 2;
- ListView_SetItem(hwnd2Settings, &lvi);
- mir_snprintf(data, 16, "0x%04X (%ld)", dbv.wVal, dbv.wVal);
- ListView_SetItemText(hwnd2Settings, index, 1, data);
- ListView_SetItemText(hwnd2Settings, index, 2, Translate("WORD"));
- ListView_SetItemText(hwnd2Settings, index, 3, "0x0002 (2)");
- break;
+ ListView_SetItemText(hwnd2List, index, 4, resident?_T("[R]"):_T(""));
- case DBVT_DWORD:
- if (!(data = (char*)mir_realloc(data, 32))) // 0x00000000 (0000000000)
- return;
-
- lvi.iImage = 3;
- ListView_SetItem(hwnd2Settings, &lvi);
- mir_snprintf(data, 32, "0x%08X (%ld)", dbv.dVal, dbv.dVal);
- ListView_SetItemText(hwnd2Settings, index, 1, data);
- ListView_SetItemText(hwnd2Settings, index, 2, Translate("DWORD"));
- ListView_SetItemText(hwnd2Settings, index, 3, "0x0004 (4)");
- break;
+ if (g_db && g_db->IsSettingEncrypted(info.module, setting)) {
+ lvi.iImage = IMAGE_UNICODE;
+ ListView_SetItem(hwnd2List, &lvi);
+ ListView_SetItemTextA(hwnd2List, index, 0, setting);
+ ListView_SetItemText(hwnd2List, index, 1, TranslateT("*** encrypted ***"));
+ ListView_SetItemText(hwnd2List, index, 2, _T("UNICODE"));
+ ListView_SetItemText(hwnd2List, index, 3, _T(""));
+ return;
+ }
- case DBVT_ASCIIZ:
- if ((data = (char*)mir_realloc(data, 512))) {
- lvi.iImage = 4;
- ListView_SetItem(hwnd2Settings, &lvi);
- ListView_SetItemText(hwnd2Settings, index, 1, dbv.pszVal);
- ListView_SetItemText(hwnd2Settings, index, 2, Translate("STRING"));
- int length = mir_strlen(dbv.pszVal) + 1;
- mir_snprintf(data, 512, "0x%04X (%d)", length, length);
- ListView_SetItemText(hwnd2Settings, index, 3, data);
- }
- break;
+ TCHAR data[32];
+ int length;
- case DBVT_UTF8:
- if ((data = (char*)mir_realloc(data, 512))) {
- lvi.iImage = 5;
- ListView_SetItem(hwnd2Settings, &lvi);
-
- int length = (int)mir_strlen(dbv.pszVal) + 1;
- WCHAR *wc = (WCHAR*)_alloca(length*sizeof(WCHAR));
- MultiByteToWideChar(CP_UTF8, 0, dbv.pszVal, -1, wc, length);
- ListView_SetItemTextW(hwnd2Settings, index, 1, wc);
-
- ListView_SetItemText(hwnd2Settings, index, 2, Translate("UNICODE"));
- mir_snprintf(data, 512, "0x%04X (%d)", length, length);
- ListView_SetItemText(hwnd2Settings, index, 3, data);
- }
- break;
+ switch (dbv->type) {
+ case DBVT_BLOB:
+ {
+ lvi.iImage = IMAGE_BINARY;
+ ListView_SetItem(hwnd2List, &lvi);
+ ptrA str(StringFromBlob(dbv->pbVal, dbv->cpbVal));
+ ListView_SetItemTextA(hwnd2List, index, 1, str);
+ mir_sntprintf(data, _T("0x%04X (%u)"), dbv->cpbVal, dbv->cpbVal);
+ ListView_SetItemText(hwnd2List, index, 3, data);
+ break;
+ }
+ case DBVT_BYTE:
+ lvi.iImage = IMAGE_BYTE;
+ ListView_SetItem(hwnd2List, &lvi);
+ mir_sntprintf(data, _T("0x%02X (%u)"), dbv->bVal, dbv->bVal);
+ ListView_SetItemText(hwnd2List, index, 1, data);
+ ListView_SetItemText(hwnd2List, index, 3, _T("0x0001 (1)"));
+ break;
- case DBVT_DELETED:
- return;
- }
+ case DBVT_WORD:
+ lvi.iImage = IMAGE_WORD;
+ ListView_SetItem(hwnd2List, &lvi);
+ mir_sntprintf(data, _T("0x%04X (%u)"), dbv->wVal, dbv->wVal);
+ ListView_SetItemText(hwnd2List, index, 1, data);
+ ListView_SetItemText(hwnd2List, index, 3, _T("0x0002 (2)"));
+ break;
+
+ case DBVT_DWORD:
+ lvi.iImage = IMAGE_DWORD;
+ ListView_SetItem(hwnd2List, &lvi);
+ mir_sntprintf(data, _T("0x%08X (%u)"), dbv->dVal, dbv->dVal);
+ ListView_SetItemText(hwnd2List, index, 1, data);
+ ListView_SetItemText(hwnd2List, index, 3, _T("0x0004 (4)"));
+ break;
+
+ case DBVT_ASCIIZ:
+ {
+ lvi.iImage = IMAGE_STRING;
+ ListView_SetItem(hwnd2List, &lvi);
+ ListView_SetItemTextA(hwnd2List, index, 1, dbv->pszVal);
+ length = mir_strlen(dbv->pszVal) + 1;
+ mir_sntprintf(data, _T("0x%04X (%u)"), length, length);
+ ListView_SetItemText(hwnd2List, index, 3, data);
+ break;
}
- else if (dbv.type == DBVT_UTF8) {
- lvi.iImage = 5;
- ListView_SetItem(hwnd2Settings, &lvi);
- ListView_SetItemText(hwnd2Settings, index, 1, Translate("<unsupported>"));
- ListView_SetItemText(hwnd2Settings, index, 2, Translate("UNICODE"));
- ListView_SetItemText(hwnd2Settings, index, 3, Translate("<unknown>"));
+ case DBVT_WCHAR:
+ {
+ lvi.iImage = IMAGE_UNICODE;
+ ListView_SetItem(hwnd2List, &lvi);
+ length = mir_wstrlen(dbv->pwszVal) + 1;
+ ptrT str(mir_u2t(dbv->pwszVal));
+ ListView_SetItemText(hwnd2List, index, 1, str);
+ mir_sntprintf(data, _T("0x%04X (%u)"), length, length);
+ ListView_SetItemText(hwnd2List, index, 3, data);
+ break;
+ }
+ case DBVT_UTF8:
+ {
+ lvi.iImage = IMAGE_UNICODE;
+ ListView_SetItem(hwnd2List, &lvi);
+ length = mir_strlen(dbv->pszVal) + 1;
+ ptrT str(mir_utf8decodeT(dbv->pszVal));
+ ListView_SetItemText(hwnd2List, index, 1, str);
+ mir_sntprintf(data, _T("0x%04X (%u)"), length, length);
+ ListView_SetItemText(hwnd2List, index, 3, data);
+ break;
+ }
+ case DBVT_DELETED:
+// ListView_DeleteItem(hwnd2List, index);
+ return;
}
- else ListView_DeleteItem(hwnd2Settings, index);
- db_free(&dbv);
- mir_free(data);
+ //ListView_SetItemTextA(hwnd2List, index, 0, setting);
+ ListView_SetItemText(hwnd2List, index, 2, DBVType(dbv->type));
}
-void PopulateSettings(HWND hwnd2Settings, MCONTACT hContact, char* module)
+
+void addListHandle(MCONTACT hContact)
{
- SettingListInfo* info = (SettingListInfo*)mir_calloc(sizeof(SettingListInfo));
- LVITEM lvItem;
+ TCHAR name[NAME_SIZE], data[32];
+ LVITEM lvi = { 0 };
+ lvi.mask = LVIF_IMAGE | LVIF_TEXT | LVIF_PARAM;
+ lvi.lParam = hContact;
+ lvi.iImage = IMAGE_HANDLE;
+
+ GetContactName(hContact, NULL, name, SIZEOF(name));
+ lvi.pszText = name;
+
+ int index = ListView_InsertItem(hwnd2List, &lvi);
+
+ mir_sntprintf(data, _T("0x%08X (%ld)"), hContact, hContact);
+
+ ListView_SetItemText(hwnd2List, index, 1, data);
+ ListView_SetItemText(hwnd2List, index, 2, _T("HANDLE"));
+ ListView_SetItemText(hwnd2List, index, 3, _T("0x0004 (4)"));
+ if (db_mc_isEnabled()) {
+ if (db_mc_isSub(hContact)) {
+ ListView_SetItemText(hwnd2List, index, 4, _T("[S]"));
+ } else
+ if (db_mc_isMeta(hContact)) {
+ ListView_SetItemText(hwnd2List, index, 4, _T("[M]"));
+ }
+ }
+}
- ModuleSettingLL setlist;
- if (!EnumSettings(hContact, module, &setlist)) {
- msg(Translate("Error Loading Setting List"), modFullname);
- mir_free(info);
+
+void addListItem(const char *setting, int resident)
+{
+ DBVARIANT dbv;
+ if (!db_get_s(info.hContact, info.module, setting, &dbv, 0)) {
+ LVITEMA lvi = { 0 };
+ lvi.mask = LVIF_TEXT;
+ lvi.pszText = (char*)setting;
+ int index = SendMessageA(hwnd2List, LVM_INSERTITEMA, 0, (LPARAM)&lvi);
+ updateListItem(index, setting, &dbv, resident);
+ db_free(&dbv);
+ }
+ else
+ if (!resident) {
+ LVITEMA lvi = { 0 };
+ lvi.mask = LVIF_TEXT;
+ lvi.pszText = (char*)setting;
+ int index = SendMessageA(hwnd2List, LVM_INSERTITEMA, 0, (LPARAM)&lvi);
+ ListView_SetItemText(hwnd2List, index, 1, TranslateT("*** buggy resident ***"));
return;
}
+}
+
+
+void PopulateSettings(MCONTACT hContact, const char *module)
+{
+ // save module as it can be erased by ClearListView()
+ char tmp[FLD_SIZE];
+ mir_strncpy(tmp, module, SIZEOF(tmp));
// clear any settings that may be there...
- ClearListview(hwnd2Settings);
+ ClearListView();
- info->hContact = hContact;
- info->module = mir_tstrdup(module);
- SetWindowLongPtr(hwnd2Settings, GWLP_USERDATA, (LONG_PTR)info);
+ info.hContact = hContact;
+ mir_strncpy(info.module, tmp, SIZEOF(info.module));
- // icons
- if (himl2)
- ListView_SetImageList(hwnd2Settings, himl2, LVSIL_SMALL);
+ ModuleSettingLL setlist;
- lvItem.mask = LVIF_TEXT;
- lvItem.iItem = 0;
- lvItem.iSubItem = 0;
+ if (IsModuleEmpty(info.hContact, info.module) || !EnumSettings(info.hContact, info.module, &setlist))
+ return;
- ModSetLinkLinkItem *setting = setlist.first;
- while (setting) {
- lvItem.pszText = setting->name;
- additem(hwnd2Settings, hContact, module, setting->name, ListView_InsertItem(hwnd2Settings, &lvItem));
- setting = (ModSetLinkLinkItem*)setting->next;
- }
+ for (ModSetLinkLinkItem *setting = setlist.first; setting; setting = setting->next)
+ addListItem(setting->name, 0);
FreeModuleSettingLL(&setlist);
-}
-void SelectSetting(char *setting)
-{
- LVITEM lvItem;
- LVFINDINFO lvfi;
- HWND hwnd2Settings = GetDlgItem(hwnd2mainWindow, IDC_SETTINGS);
-
- lvfi.flags = LVFI_STRING;
- lvfi.psz = setting;
- lvfi.vkDirection = VK_DOWN;
+ // Resident settings
+ if (!EnumResidentSettings(module, &setlist))
+ return;
- lvItem.mask = LVIF_TEXT;
- lvItem.iItem = ListView_FindItem(hwnd2Settings, -1, &lvfi);
- if (lvItem.iItem != -1) {
- lvItem.mask = LVIF_STATE;
- lvItem.state = LVIS_SELECTED | LVIS_FOCUSED;
- lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
- ListView_SetItem(hwnd2Settings, &lvItem);
- }
+ for (ModSetLinkLinkItem *setting = setlist.first; setting; setting = setting->next)
+ addListItem(setting->name, 1);
+
+ FreeModuleSettingLL(&setlist);
}
-void settingChanged(HWND hwnd2Settings, MCONTACT hContact, char* module, char* setting)
+
+void SelectSetting(const char *setting)
{
- LVITEM lvItem;
- LVFINDINFO lvfi;
+ LVITEM lvItem = {0};
- lvfi.flags = LVFI_STRING;
- lvfi.psz = setting;
- lvfi.vkDirection = VK_DOWN;
+ lvItem.mask = LVIF_STATE;
+ lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
+
+ int items = ListView_GetItemCount(hwnd2List);
+ for (int i = 0; i < items; i++) {
+ if (ListView_GetItemState(hwnd2List, i, lvItem.stateMask))
+ ListView_SetItemState(hwnd2List, i, 0, lvItem.stateMask);
+ }
- lvItem.mask = LVIF_TEXT | LVIF_IMAGE;
- lvItem.iItem = ListView_FindItem(hwnd2Settings, -1, &lvfi);
- lvItem.iSubItem = 0;
+ lvItem.iItem = findListItem(setting);
- if (lvItem.iItem == -1) {
- lvItem.iItem = 0;
- lvItem.pszText = setting;
- lvItem.iItem = ListView_InsertItem(hwnd2Settings, &lvItem);
+ if (lvItem.iItem != -1) {
+ EditFinish(lvItem.iItem);
+ lvItem.state = LVIS_SELECTED | LVIS_FOCUSED;
+ ListView_SetItem(hwnd2List, &lvItem);
}
- additem(hwnd2Settings, hContact, module, setting, lvItem.iItem);
}
-struct EditLabelInfoStruct
-{
- MCONTACT hContact;
- char module[256];
- char setting[256];
- int item;
- int subitem;
- HWND hwnd;
- int unicode;
-};
-void writeStandardTextfromLabel(EditLabelInfoStruct* info, char* value, WCHAR *wc, int type)
+void settingChanged(MCONTACT hContact, const char *module, const char *setting, DBVARIANT *dbv)
{
- if (type != DBVT_ASCIIZ && type != DBVT_UTF8)
- db_unset(info->hContact, info->module, info->setting);
+ // modules tree
+ if (dbv->type != DBVT_DELETED) {
+ HTREEITEM hItem = findItemInTree(hContact, module);
+ if (!hItem) {
+ HTREEITEM hParent = findItemInTree(hContact, NULL);
+ if (hParent)
+ insertItem(hContact, module, hParent);
+ }
+ }
- if (type == DBVT_UTF8 && wc) {
- db_set_ws(info->hContact, info->module, info->setting, wc);
- mir_free(wc);
+ // settings list
+ if (hContact != info.hContact || mir_strcmp(info.module, module)) return;
+
+ if (dbv->type == DBVT_DELETED) {
+ deleteListItem(setting);
+ } else {
+ LVITEMA lvi = {0};
+ lvi.iItem = findListItem(setting);
+ if (lvi.iItem == -1) {
+ lvi.iItem = 0;
+ lvi.mask = LVIF_TEXT;
+ lvi.pszText = (char*)setting;
+ lvi.iItem = SendMessageA(hwnd2List, LVM_INSERTITEMA, 0, (LPARAM)&lvi);
+ }
+ updateListItem(lvi.iItem, setting, dbv, IsResidentSetting(module, setting));
}
- else db_set_s(info->hContact, info->module, info->setting, value);
}
+
static LRESULT CALLBACK SettingLabelEditSubClassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
- EditLabelInfoStruct* info = (EditLabelInfoStruct*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
switch (msg) {
case WM_KEYDOWN:
switch (wParam) {
@@ -331,389 +438,287 @@ static LRESULT CALLBACK SettingLabelEditSubClassProc(HWND hwnd, UINT msg, WPARAM
}
break;
case WM_USER:
- SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
+ {
SetFocus(hwnd);
SendMessage(hwnd, WM_SETFONT, SendMessage(GetParent(hwnd), WM_GETFONT, 0, 0), 1);
- info = ((EditLabelInfoStruct*)lParam);
- if (info->subitem)
+ if (info.subitem)
SendMessage(hwnd, EM_LIMITTEXT, (WPARAM)65535, 0);
else
SendMessage(hwnd, EM_LIMITTEXT, (WPARAM)255, 0);
SendMessage(hwnd, EM_SETSEL, 0, -1);
break;
+ }
case WM_PAINT:
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
{
- int len = GetWindowTextLength(hwnd) + 1;
- char *value = (char*)_alloca(len);
- WCHAR *wc = NULL;
DBVARIANT dbv = { 0 };
+ int len = GetWindowTextLength(hwnd) + 1;
- GetWindowTextA(hwnd, value, len);
-
- if (info->unicode)
- wc = mir_a2u(value);
-
- if (len <= 1 || GetSetting(info->hContact, info->module, info->setting, &dbv)) {
+ if ((!info.subitem && len <= 1) || db_get_s(info.hContact, info.module, info.setting, &dbv, 0)) {
SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), 0);
return 0;
}
+
+ TCHAR *value = (TCHAR*)mir_alloc(len*sizeof(TCHAR));
+
+ GetWindowText(hwnd, value, len);
+
+ _T2A szValue(value);
- switch (info->subitem) {
+ int res = 0;
+
+ switch (info.subitem) {
case 0: // setting name
- if (!mir_strcmp(info->setting, value) || mir_strlen(value) > 255) {
+ if (!mir_strcmp(info.setting, szValue) || mir_strlen(szValue) > 0xFE) {
db_free(&dbv);
+ mir_free(value);
SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), 0);
return 0;
}
- db_set(info->hContact, info->module, value, &dbv);
- db_unset(info->hContact, info->module, info->setting);
- {
- LVFINDINFO lvfi;
- lvfi.flags = LVFI_STRING;
- lvfi.psz = info->setting;
- lvfi.vkDirection = VK_DOWN;
- int item = ListView_FindItem(info->hwnd, -1, &lvfi);
- ListView_DeleteItem(info->hwnd, item);
- }
+ if (db_set(info.hContact, info.module, szValue, &dbv))
+ break;
+ res = 1;
+ db_unset(info.hContact, info.module, info.setting);
+ deleteListItem(info.setting);
break;
case 1: // value
- int val;
+ DWORD val;
int i = 0;
if (dbv.type == DBVT_BLOB) {
- WriteBlobFromString(info->hContact, info->module, info->setting, value, len);
+ res = WriteBlobFromString(info.hContact, info.module, info.setting, szValue, mir_strlen(szValue));
break;
}
switch (value[0]) {
- case 'b':
- case 'B':
- if (value[1] == '0' && (value[2] == 'x' || value[2] == 'X'))
- sscanf(&value[3], "%x", &val);
- else if (value[1] >= '0' && value[1] <= '9') {
- val = atoi(&value[1]);
- if (dbv.type == DBVT_ASCIIZ || dbv.type == DBVT_UTF8)
- db_unset(info->hContact, info->module, info->setting);
-
- db_set_b(info->hContact, info->module, info->setting, (BYTE)val);
+ case _T('b'):
+ case _T('B'):
+ val = _tcstoul(&value[1], NULL, 0);
+ if (!val || value[1] == _T('0')) {
+ res = !db_set_b(info.hContact, info.module, info.setting, (BYTE)val);
}
- else writeStandardTextfromLabel(info, value, wc, dbv.type);
+ else
+ res = setTextValue(info.hContact, info.module, info.setting, value, dbv.type);
break;
- case 'w':
- case 'W':
- if (value[1] == '0' && (value[2] == 'x' || value[2] == 'X'))
- sscanf(&value[3], "%x", &val);
- else if (value[1] >= '0' && value[1] <= '9') {
- val = atoi(&value[1]);
- if (dbv.type == DBVT_ASCIIZ || dbv.type == DBVT_UTF8)
- db_unset(info->hContact, info->module, info->setting);
- db_set_w(info->hContact, info->module, info->setting, (WORD)val);
- }
- else writeStandardTextfromLabel(info, value, wc, dbv.type);
+ case _T('w'):
+ case _T('W'):
+ val = _tcstoul(&value[1], NULL, 0);
+ if (!val || value[1] == _T('0'))
+ res = !db_set_w(info.hContact, info.module, info.setting, (WORD)val);
+ else
+ res = setTextValue(info.hContact, info.module, info.setting, value, dbv.type);
break;
- case 'd':
- case 'D':
- if (value[1] == '0' && (value[2] == 'x' || value[2] == 'X'))
- sscanf(&value[3], "%x", &val);
- else if (value[1] >= '0' && value[1] <= '9') {
- val = atoi(&value[1]);
- if (dbv.type == DBVT_ASCIIZ || dbv.type == DBVT_UTF8)
- db_unset(info->hContact, info->module, info->setting);
- db_set_dw(info->hContact, info->module, info->setting, val);
- }
- else writeStandardTextfromLabel(info, value, wc, dbv.type);
+ case _T('d'):
+ case _T('D'):
+ val = _tcstoul(&value[1], NULL, 0);
+ if (!val || value[1] == _T('0'))
+ res = !db_set_dw(info.hContact, info.module, info.setting, val);
+ else
+ res = setTextValue(info.hContact, info.module, info.setting, value, dbv.type);
break;
- case '0':
+
+ case _T('0'):
i = 1;
- case 'x':
- case 'X':
- if (value[i] == 'x' || value[i] == 'X') {
- sscanf(&value[i + 1], "%x", &val);
- switch (dbv.type) {
- case DBVT_UTF8:
- case DBVT_ASCIIZ:
- writeStandardTextfromLabel(info, value, wc, dbv.type);
- break;
- case DBVT_BYTE:
- db_set_b(info->hContact, info->module, info->setting, (BYTE)val);
- break;
- case DBVT_WORD:
- db_set_w(info->hContact, info->module, info->setting, (WORD)val);
- break;
- case DBVT_DWORD:
- db_set_dw(info->hContact, info->module, info->setting, (DWORD)val);
- break;
- }
- }
- else {
- val = atoi(value);
- switch (dbv.type) {
- case DBVT_ASCIIZ:
- case DBVT_UTF8:
- writeStandardTextfromLabel(info, value, wc, dbv.type);
- break;
- case DBVT_BYTE:
- db_set_b(info->hContact, info->module, info->setting, (BYTE)val);
- break;
- case DBVT_WORD:
- db_set_w(info->hContact, info->module, info->setting, (WORD)val);
- break;
- case DBVT_DWORD:
- db_set_dw(info->hContact, info->module, info->setting, (DWORD)val);
- break;
- }
+ case _T('1'):
+ case _T('2'):
+ case _T('3'):
+ case _T('4'):
+ case _T('5'):
+ case _T('6'):
+ case _T('7'):
+ case _T('8'):
+ case _T('9'):
+ case _T('-'):
+ case _T('x'):
+ case _T('X'):
+ if (value[i] == _T('x') || value[i] == _T('X'))
+ val = _tcstoul(&value[i+1], NULL, 16);
+ else
+ val = _tcstoul(value, NULL, 10);
+
+ switch (dbv.type) {
+ case DBVT_BYTE:
+ case DBVT_WORD:
+ case DBVT_DWORD:
+ res = setNumericValue(info.hContact, info.module, info.setting, val, dbv.type);
+ break;
+ case DBVT_ASCIIZ:
+ case DBVT_WCHAR:
+ case DBVT_UTF8:
+ res = setTextValue(info.hContact, info.module, info.setting, value, dbv.type);
+ break;
}
break;
- case '\"':
- case '\'':
+ case _T('\"'):
+ case _T('\''):
{
- int nlen = mir_strlen(value);
+ int nlen = mir_tstrlen(value);
int sh = 0;
if (nlen > 3) {
if (value[nlen - 1] == value[0]) {
- value[nlen - 1] = '\0';
+ value[nlen - 1] = 0;
sh = 1;
}
}
- writeStandardTextfromLabel(info, &value[sh], wc, dbv.type);
+ res = setTextValue(info.hContact, info.module, info.setting, &value[sh], dbv.type);
}
break;
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- case '-':
- val = atoi(value);
- switch (dbv.type) {
- case DBVT_ASCIIZ:
- case DBVT_UTF8:
- writeStandardTextfromLabel(info, value, wc, dbv.type);
- break;
- case DBVT_BYTE:
- db_set_b(info->hContact, info->module, info->setting, (BYTE)val);
- break;
- case DBVT_WORD:
- db_set_w(info->hContact, info->module, info->setting, (WORD)val);
- break;
- case DBVT_DWORD:
- db_set_dw(info->hContact, info->module, info->setting, (DWORD)val);
- break;
- }
- break;
default:
- writeStandardTextfromLabel(info, value, wc, dbv.type);
+ res = setTextValue(info.hContact, info.module, info.setting, value, dbv.type);
break;
}
break;
}
+
+ mir_free(value);
db_free(&dbv);
+
+ if (!res) {
+ msg(TranslateT("Unable to store value in this data type!"));
+ break;
+ }
+
} // fall through
case IDCANCEL:
- SettingListInfo *sli = (SettingListInfo*)GetWindowLongPtr(info->hwnd, GWLP_USERDATA);
- if (sli && sli->hwnd2Edit == hwnd)
- sli->hwnd2Edit = NULL;
-
- mir_free(info);
+ {
DestroyWindow(hwnd);
return 0;
}
break; // wm_command
-
+ }
case WM_GETDLGCODE:
return DLGC_WANTALLKEYS;
+ case WM_DESTROY:
+ info.hwnd2Edit = NULL;
+ break;
}
return mir_callNextSubclass(hwnd, SettingLabelEditSubClassProc, msg, wParam, lParam);
}
-void EditLabel(HWND hwnd2List, int item, int subitem)
+void EditLabel(int item, int subitem)
{
RECT rc;
- char setting[256], value[16] = { 0 };
+ char setting[FLD_SIZE];
DBVARIANT dbv;
- SettingListInfo* info = (SettingListInfo*)GetWindowLongPtr(hwnd2List, GWLP_USERDATA);
- EditLabelInfoStruct *data = (EditLabelInfoStruct*)mir_calloc(sizeof(EditLabelInfoStruct));
- if (!data || !info)
- return;
- if (info->hwnd2Edit) {
- SendMessage(info->hwnd2Edit, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), 0); // ignore the new value of the last edit
- info->hwnd2Edit = NULL;
+ if (info.hwnd2Edit) {
+ SendMessage(info.hwnd2Edit, WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), 0); // ignore the new value of the last edit
+ info.hwnd2Edit = NULL;
}
-
- LVITEM lvi;
- lvi.mask = LVIF_TEXT;
- lvi.iItem = item;
- lvi.iSubItem = 0;
- lvi.pszText = setting;
- lvi.cchTextMax = SIZEOF(setting);
- if (!ListView_GetItem(hwnd2List, &lvi) ||
- !ListView_GetSubItemRect
- (hwnd2List, item, subitem, LVIR_LABEL, &rc) ||
- GetSetting(info->hContact, info->module, setting, &dbv)) {
- mir_free(data);
+
+ if (!ListView_GetItemTextA(hwnd2List, item, 0, setting, SIZEOF(setting))) return;
+ if (!setting[0] || !ListView_GetSubItemRect(hwnd2List, item, subitem, LVIR_LABEL, &rc))
+ return;
+
+ if (db_get_s(info.hContact, info.module, setting, &dbv, 0))
return;
- }
- data->hContact = info->hContact;
- mir_strcpy(data->module, info->module);
- mir_strcpy(data->setting, setting);
- data->item = item;
- data->subitem = subitem;
- data->hwnd = hwnd2List;
+ info.hContact = info.hContact;
+ mir_strcpy(info.setting, setting);
+ info.subitem = subitem;
- // fix size for long strings
+ if (!subitem)
+ info.hwnd2Edit = CreateWindow(_T("EDIT"), _A2T(setting), WS_BORDER | WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL, rc.left, rc.top, (rc.right - rc.left), (rc.bottom - rc.top), hwnd2List, 0, hInst, 0);
+ else {
+ TCHAR *str = NULL, value[16] = { 0 };
- switch (dbv.type) {
- case DBVT_UTF8:
- if (subitem) {
- int len = mir_strlen(dbv.pszVal) + 1;
- WCHAR *wc = (WCHAR*)_alloca(len*sizeof(WCHAR));
- MultiByteToWideChar(CP_UTF8, 0, dbv.pszVal, -1, wc, len);
- data->unicode = 1;
- info->hwnd2Edit = CreateWindowW(L"EDIT", wc, WS_BORDER | WS_VISIBLE | WS_CHILD | WS_VSCROLL | ES_MULTILINE | ES_AUTOHSCROLL, rc.left, rc.top, (int)((rc.right - rc.left)*1.5), (rc.bottom - rc.top) * 3, hwnd2List, 0, hInst, 0);
+ switch (dbv.type) {
+ case DBVT_ASCIIZ:
+ str = mir_a2t(dbv.pszVal);
+ break;
+ case DBVT_BYTE:
+ mir_sntprintf(value, (g_Hex & HEX_BYTE) ? _T("0x%02X") : _T("%u"), dbv.bVal);
+ break;
+ case DBVT_WORD:
+ mir_sntprintf(value, (g_Hex & HEX_WORD) ? _T("0x%04X") : _T("%u"), dbv.wVal);
+ break;
+ case DBVT_DWORD:
+ mir_sntprintf(value, (g_Hex & HEX_DWORD) ? _T("0x%08X") : _T("%u"), dbv.dVal);
+ break;
+ case DBVT_WCHAR:
+ str = mir_u2t(dbv.pwszVal);
+ break;
+ case DBVT_UTF8:
+ str = mir_utf8decodeT(dbv.pszVal);
+ break;
+ case DBVT_BLOB:
+ {
+ ptrA tmp(StringFromBlob(dbv.pbVal, dbv.cpbVal));
+ str = mir_a2t(tmp);
break;
}
- // fall through
- case DBVT_ASCIIZ:
- if (subitem) // convert from UTF8
- info->hwnd2Edit = CreateWindow("EDIT", dbv.pszVal, WS_BORDER | WS_VISIBLE | WS_CHILD | WS_VSCROLL | ES_MULTILINE | ES_AUTOHSCROLL, rc.left, rc.top, (int)((rc.right - rc.left)*1.5), (rc.bottom - rc.top) * 3, hwnd2List, 0, hInst, 0);
- else
- info->hwnd2Edit = CreateWindow("EDIT", setting, WS_BORDER | WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL, rc.left, rc.top, (rc.right - rc.left), (rc.bottom - rc.top), hwnd2List, 0, hInst, 0);
- break;
- case DBVT_BYTE:
- if (Hex & HEX_BYTE)
- mir_snprintf(value, SIZEOF(value), "0x%02X", dbv.bVal);
- else
- itoa(dbv.bVal, value, 10);
- info->hwnd2Edit = CreateWindow("EDIT", !subitem ? setting : value, WS_BORDER | WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL, rc.left, rc.top, (rc.right - rc.left), (rc.bottom - rc.top), hwnd2List, 0, hInst, 0);
- break;
- case DBVT_WORD:
- if (Hex & HEX_WORD)
- mir_snprintf(value, SIZEOF(value), "0x%04X", dbv.wVal);
- else
- itoa(dbv.wVal, value, 10);
- info->hwnd2Edit = CreateWindow("EDIT", !subitem ? setting : value, WS_BORDER | WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL, rc.left, rc.top, (rc.right - rc.left), (rc.bottom - rc.top), hwnd2List, 0, hInst, 0);
- break;
- case DBVT_DWORD:
- if (Hex & HEX_DWORD)
- mir_snprintf(value, SIZEOF(value), "0x%08X", dbv.dVal);
- else
- itoa(dbv.dVal, value, 10);
- info->hwnd2Edit = CreateWindow("EDIT", !subitem ? setting : value, WS_BORDER | WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL, rc.left, rc.top, (rc.right - rc.left), (rc.bottom - rc.top), hwnd2List, 0, hInst, 0);
- break;
- case DBVT_BLOB:
- if (!subitem)
- info->hwnd2Edit = CreateWindow("EDIT", setting, WS_BORDER | WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL, rc.left, rc.top, (rc.right - rc.left), (rc.bottom - rc.top), hwnd2List, 0, hInst, 0);
- else {
- int j;
- char tmp[16];
- char *data = (char*)_alloca(3 * (dbv.cpbVal + 1) + 10);
-
- if (!data) { msg(Translate("Couldn't allocate enough memory!"), modFullname); return; }
- data[0] = '\0';
-
- for (j = 0; j < dbv.cpbVal; j++) {
- mir_snprintf(tmp, "%02X ", (BYTE)dbv.pbVal[j]);
- mir_strcat(data, tmp);
- }
+ }
- info->hwnd2Edit = CreateWindow("EDIT", data, WS_BORDER | WS_VISIBLE | WS_CHILD | WS_VSCROLL | ES_MULTILINE, rc.left, rc.top, (int)((rc.right - rc.left)*1.5), (rc.bottom - rc.top) * 3, hwnd2List, 0, hInst, 0);
+ if (str)
+ {
+ int height = (rc.bottom - rc.top) * 4;
+ RECT rclist;
+ GetClientRect(hwnd2List, &rclist);
+ if (rc.top + height > rclist.bottom && rclist.bottom - rclist.top > height)
+ rc.top = rc.bottom - height;
+ info.hwnd2Edit = CreateWindow(_T("EDIT"), str, WS_BORDER | WS_VISIBLE | WS_CHILD | WS_VSCROLL | ES_MULTILINE | ES_AUTOHSCROLL, rc.left, rc.top, rc.right - rc.left, height, hwnd2List, 0, hInst, 0);
+ mir_free(str);
}
- break;
- default:
- return;
+ else
+ if (dbv.type == DBVT_BYTE || dbv.type == DBVT_WORD || dbv.type == DBVT_DWORD)
+ info.hwnd2Edit = CreateWindow(_T("EDIT"), value, WS_BORDER | WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL, rc.left, rc.top, (rc.right - rc.left), (rc.bottom - rc.top), hwnd2List, 0, hInst, 0);
+
}
db_free(&dbv);
- mir_subclassWindow(info->hwnd2Edit, SettingLabelEditSubClassProc);
-
- SendMessage(info->hwnd2Edit, WM_USER, 0, (LPARAM)data);
+ mir_subclassWindow(info.hwnd2Edit, SettingLabelEditSubClassProc);
+ SendMessage(info.hwnd2Edit, WM_USER, 0, 0);
}
-static int test;
+
void SettingsListRightClick(HWND hwnd, WPARAM wParam, LPARAM lParam);
-static int lastColumn = -1;
-struct SettingsSortParams
-{
- HWND hList;
- int column;
-};
-
-INT_PTR CALLBACK SettingsCompare(LPARAM lParam1, LPARAM lParam2, LPARAM myParam)
-{
- SettingsSortParams params = *(SettingsSortParams *)myParam;
- const int maxSize = 1024;
- TCHAR text1[maxSize];
- TCHAR text2[maxSize];
- ListView_GetItemText(params.hList, lParam1, params.column, text1, SIZEOF(text1));
- ListView_GetItemText(params.hList, lParam2, params.column, text2, SIZEOF(text2));
-
- int res = mir_tstrcmpi(text1, text2);
- res = (params.column == lastColumn) ? -res : res;
- return res;
-}
void SettingsListWM_NOTIFY(HWND hwnd, UINT, WPARAM wParam, LPARAM lParam)
{
- SettingListInfo* info = (SettingListInfo*)GetWindowLongPtr(GetDlgItem(hwnd, IDC_SETTINGS), GWLP_USERDATA);
LVHITTESTINFO hti;
switch (((NMHDR*)lParam)->code) {
case NM_CLICK:
-
hti.pt = ((NMLISTVIEW*)lParam)->ptAction;
- if (db_get_b(NULL, modname, "DontAllowInLineEdit", 0))
- break;
- if (info && ListView_SubItemHitTest(GetDlgItem(hwnd, IDC_SETTINGS), &hti) > -1) {
- if (hti.iSubItem < 2 && hti.flags != LVHT_ONITEMICON) {
- if (info->selectedItem == hti.iItem)
- EditLabel(GetDlgItem(hwnd, IDC_SETTINGS), hti.iItem, hti.iSubItem);
- else if (info->hwnd2Edit) {
- SendMessage(info->hwnd2Edit, WM_COMMAND, MAKEWPARAM(IDOK, 0), 0);
- info->hwnd2Edit = NULL;
- info->selectedItem = hti.iItem;
- }
- else info->selectedItem = hti.iItem;
- }
- else {
- if (info->hwnd2Edit) {
- SendMessage(info->hwnd2Edit, WM_COMMAND, MAKEWPARAM(IDOK, 0), 0);
- info->hwnd2Edit = NULL;
- }
- info->selectedItem = hti.iItem;
- }
- }
- else if (info && info->hwnd2Edit) {
- SendMessage(info->hwnd2Edit, WM_COMMAND, MAKEWPARAM(IDOK, 0), 0);
- info->hwnd2Edit = NULL;
- info->selectedItem = 0;
+ if (ListView_SubItemHitTest(hwnd2List, &hti) > -1) {
+ if (g_Inline && hti.iSubItem <= 1 && hti.flags != LVHT_ONITEMICON && info.selectedItem == hti.iItem)
+ EditLabel(hti.iItem, hti.iSubItem);
+ else
+ EditFinish(hti.iItem);
}
+ else
+ EditFinish(0);
break;
case NM_DBLCLK:
hti.pt = ((NMLISTVIEW*)lParam)->ptAction;
- if (info && ListView_SubItemHitTest(GetDlgItem(hwnd, IDC_SETTINGS), &hti) > -1) {
- if ((hti.iSubItem > 1 || hti.flags == LVHT_ONITEMICON) || (db_get_b(NULL, modname, "DontAllowInLineEdit", 0))) {
- char setting[256];
- SendMessage(info->hwnd2Edit, WM_COMMAND, MAKEWPARAM(IDOK, 0), 0);
- info->hwnd2Edit = NULL;
- ListView_GetItemText(GetDlgItem(hwnd, IDC_SETTINGS), hti.iItem, 0, setting, SIZEOF(setting));
- editSetting(info->hContact, info->module, setting);
+ if (ListView_SubItemHitTest(hwnd2List, &hti) > -1) {
+ if (!info.module[0]) { // contact
+ LVITEM lvi = { 0 };
+ lvi.mask = LVIF_PARAM;
+ lvi.iItem = hti.iItem;
+ if (!ListView_GetItem(hwnd2List, &lvi)) break;
+
+ ItemInfo ii = {0};
+ ii.hContact = (MCONTACT)lvi.lParam;
+ SendMessage(hwnd2mainWindow, WM_FINDITEM, (WPARAM)&ii, 0);
+ break;
}
- else EditLabel(GetDlgItem(hwnd, IDC_SETTINGS), hti.iItem, hti.iSubItem);
+ if (!g_Inline || hti.iSubItem > 1 || hti.flags == LVHT_ONITEMICON) {
+ char setting[FLD_SIZE];
+ EditFinish(hti.iItem);
+ if (ListView_GetItemTextA(hwnd2List, hti.iItem, 0, setting, SIZEOF(setting)))
+ editSetting(info.hContact, info.module, setting);
+ }
+ else
+ EditLabel(hti.iItem, hti.iSubItem);
}
break;
@@ -723,337 +728,203 @@ void SettingsListWM_NOTIFY(HWND hwnd, UINT, WPARAM wParam, LPARAM lParam)
case LVN_COLUMNCLICK:
LPNMLISTVIEW lv = (LPNMLISTVIEW)lParam;
- SettingsSortParams params = { 0 };
- params.hList = GetDlgItem(hwnd, IDC_SETTINGS);
+ ColumnsSortParams params = { 0 };
+ params.hList = hwnd2List;
params.column = lv->iSubItem;
- ListView_SortItemsEx(params.hList, SettingsCompare, (LPARAM)&params);
+ params.last = lastColumn;
+ ListView_SortItemsEx(params.hList, ColumnsCompare, (LPARAM)&params);
lastColumn = (params.column == lastColumn) ? -1 : params.column;
break;
}
}
+
void SettingsListRightClick(HWND hwnd, WPARAM, LPARAM lParam) // hwnd here is to the main window, NOT the listview
{
- HWND hSettings = GetDlgItem(hwnd, IDC_SETTINGS);
- SettingListInfo* info = (SettingListInfo*)GetWindowLongPtr(hSettings, GWLP_USERDATA);
- if (!info)
- return;
-
- char setting[256], *module;
- MCONTACT hContact;
LVHITTESTINFO hti;
POINT pt;
HMENU hMenu, hSubMenu;
- DBsetting *dbsetting;
- DBVARIANT dbv = { 0 }; // freed in the dialog
-
- module = info->module;
- hContact = info->hContact;
hti.pt = ((NMLISTVIEW*)lParam)->ptAction;
- if (ListView_SubItemHitTest(hSettings, &hti) == -1) {
+
+ if (ListView_SubItemHitTest(hwnd2List, &hti) == -1) {
// nowhere.. new item menu
GetCursorPos(&pt);
hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_CONTEXTMENU));
hSubMenu = GetSubMenu(hMenu, 6);
TranslateMenu(hSubMenu);
+ if (!info.module[0]) {
+ RemoveMenu(hSubMenu, 0, MF_BYPOSITION); // new
+ RemoveMenu(hSubMenu, 0, MF_BYPOSITION); // separator
+ }
+
switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hwnd, NULL)) {
case MENU_ADD_BYTE:
- dbsetting = (DBsetting*)mir_alloc(sizeof(DBsetting)); // gets safe_free()ed in the window proc
- dbv.type = DBVT_BYTE;
- dbsetting->dbv = dbv;
- dbsetting->hContact = hContact;
- dbsetting->module = mir_tstrdup(module);
- dbsetting->setting = mir_tstrdup("");
- CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd, EditSettingDlgProc, (LPARAM)dbsetting);
- break;
+ newSetting(info.hContact, info.module, DBVT_BYTE);
+ return;
case MENU_ADD_WORD:
- dbsetting = (DBsetting*)mir_alloc(sizeof(DBsetting)); // gets safe_free()ed in the window proc
- dbv.type = DBVT_WORD;
- dbsetting->dbv = dbv;
- dbsetting->hContact = hContact;
- dbsetting->module = mir_tstrdup(module);
- dbsetting->setting = mir_tstrdup("");
- CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd, EditSettingDlgProc, (LPARAM)dbsetting);
- break;
+ newSetting(info.hContact, info.module, DBVT_WORD);
+ return;
case MENU_ADD_DWORD:
- dbsetting = (DBsetting*)mir_alloc(sizeof(DBsetting)); // gets safe_free()ed in the window proc
- dbv.type = DBVT_DWORD;
- dbsetting->dbv = dbv;
- dbsetting->hContact = hContact;
- dbsetting->module = mir_tstrdup(module);
- dbsetting->setting = mir_tstrdup("");
- CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd, EditSettingDlgProc, (LPARAM)dbsetting);
- break;
+ newSetting(info.hContact, info.module, DBVT_DWORD);
+ return;
case MENU_ADD_STRING:
- dbsetting = (DBsetting*)mir_alloc(sizeof(DBsetting)); // gets safe_free()ed in the window proc
- dbv.type = DBVT_ASCIIZ;
- dbsetting->dbv = dbv;
- dbsetting->hContact = hContact;
- dbsetting->module = mir_tstrdup(module);
- dbsetting->setting = mir_tstrdup("");
- CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd, EditSettingDlgProc, (LPARAM)dbsetting);
- break;
+ newSetting(info.hContact, info.module, DBVT_ASCIIZ);
+ return;
case MENU_ADD_UNICODE:
- dbsetting = (DBsetting*)mir_alloc(sizeof(DBsetting)); // gets safe_free()ed in the window proc
- dbv.type = DBVT_UTF8;
- dbsetting->dbv = dbv;
- dbsetting->hContact = hContact;
- dbsetting->module = mir_tstrdup(module);
- dbsetting->setting = mir_tstrdup("");
- CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_EDIT_SETTING), hwnd, EditSettingDlgProc, (LPARAM)dbsetting);
- break;
+ newSetting(info.hContact, info.module, DBVT_WCHAR);
+ return;
case MENU_ADD_BLOB:
- dbsetting = (DBsetting*)mir_alloc(sizeof(DBsetting)); // gets safe_free()ed in the window proc
- dbv.type = DBVT_BLOB;
- dbsetting->dbv = dbv;
- dbsetting->hContact = hContact;
- dbsetting->module = mir_tstrdup(module);
- dbsetting->setting = mir_tstrdup("");
- CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd, EditSettingDlgProc, (LPARAM)dbsetting);
- break;
+ newSetting(info.hContact, info.module, DBVT_BLOB);
+ return;
+
+ case MENU_REFRESH:
+ PopulateSettings(info.hContact, info.module);
+ return;
}
return;
}
// on item
- char type[8];
- LVITEM lvi;
- int i;
- int watching = 0;
GetCursorPos(&pt);
hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_CONTEXTMENU));
hSubMenu = GetSubMenu(hMenu, 0);
TranslateMenu(hSubMenu);
- lvi.mask = LVIF_IMAGE | LVIF_TEXT;
+ LVITEM lvi = { 0 };
+
+ lvi.mask = LVIF_IMAGE;
lvi.iItem = hti.iItem;
lvi.iSubItem = 0;
- lvi.pszText = setting;
- lvi.cchTextMax = SIZEOF(setting);
-
- ListView_GetItem(hSettings, &lvi);
- ListView_GetItemText(hSettings, hti.iItem, 2, type, SIZEOF(type));
+ ListView_GetItem(hwnd2List, &lvi);
switch (lvi.iImage) {
- case 4: // STRING
+ case IMAGE_STRING:
RemoveMenu(hSubMenu, MENU_CHANGE2STRING, MF_BYCOMMAND);
break;
- case 1: // BYTE
- RemoveMenu(hSubMenu, 4, MF_BYPOSITION);
+ case IMAGE_BYTE:
RemoveMenu(hSubMenu, MENU_CHANGE2BYTE, MF_BYCOMMAND);
RemoveMenu(hSubMenu, MENU_CHANGE2UNICODE, MF_BYCOMMAND);
break;
- case 2: // WORD
- RemoveMenu(hSubMenu, 4, MF_BYPOSITION);
+ case IMAGE_WORD:
RemoveMenu(hSubMenu, MENU_CHANGE2WORD, MF_BYCOMMAND);
RemoveMenu(hSubMenu, MENU_CHANGE2UNICODE, MF_BYCOMMAND);
break;
- case 3: // DWORD
- RemoveMenu(hSubMenu, 4, MF_BYPOSITION);
+ case IMAGE_DWORD:
RemoveMenu(hSubMenu, MENU_CHANGE2DWORD, MF_BYCOMMAND);
RemoveMenu(hSubMenu, MENU_CHANGE2UNICODE, MF_BYCOMMAND);
break;
- case 0: // BLOB
- RemoveMenu(hSubMenu, 3, MF_BYPOSITION);
- RemoveMenu(hSubMenu, 1, MF_BYPOSITION);
- RemoveMenu(hSubMenu, 2, MF_BYPOSITION);
- RemoveMenu(hSubMenu, MENU_EDIT_SET, MF_BYCOMMAND);
+ case IMAGE_BINARY:
+ RemoveMenu(hSubMenu, 3, MF_BYPOSITION); // convert
break;
- case 5: // UTF8
- RemoveMenu(hSubMenu, 4, MF_BYPOSITION);
+ case IMAGE_UNICODE:
RemoveMenu(hSubMenu, MENU_CHANGE2DWORD, MF_BYCOMMAND);
RemoveMenu(hSubMenu, MENU_CHANGE2WORD, MF_BYCOMMAND);
RemoveMenu(hSubMenu, MENU_CHANGE2BYTE, MF_BYCOMMAND);
RemoveMenu(hSubMenu, MENU_CHANGE2UNICODE, MF_BYCOMMAND);
+ RemoveMenu(hSubMenu, MENU_CHANGE2BYTE, MF_BYCOMMAND);
+ break;
+ case IMAGE_EMPTY: // resident
+ RemoveMenu(hSubMenu, 3, MF_BYPOSITION); // convert
+ RemoveMenu(hSubMenu, MENU_COPY_SET, MF_BYCOMMAND);
+ RemoveMenu(hSubMenu, MENU_DELETE_SET, MF_BYCOMMAND);
break;
- }
-
- // watch list stuff
- if (ListView_GetSelectedCount(hSettings) > 1) {
- RemoveMenu(hSubMenu, 3, MF_BYPOSITION);
- RemoveMenu(hSubMenu, 1, MF_BYPOSITION);
- RemoveMenu(hSubMenu, 3, MF_BYPOSITION);
+ case IMAGE_HANDLE:
RemoveMenu(hSubMenu, MENU_EDIT_SET, MF_BYCOMMAND);
+ RemoveMenu(hSubMenu, MENU_COPY_SET, MF_BYCOMMAND);
+ RemoveMenu(hSubMenu, MENU_DELETE_SET, MF_BYCOMMAND);
+ RemoveMenu(hSubMenu, MENU_WATCH_ITEM, MF_BYCOMMAND);
+ RemoveMenu(hSubMenu, 0, MF_BYPOSITION); // convert
+ RemoveMenu(hSubMenu, 0, MF_BYPOSITION); // separator
+ RemoveMenu(hSubMenu, 0, MF_BYPOSITION); // new
+ break;
}
- // check if the setting is being watched and if it is then check the menu item
- for (i = 0; i < WatchListArray.count; i++) {
- if (WatchListArray.item[i].module && (hContact == WatchListArray.item[i].hContact)) {
- if (WatchListArray.item[i].WatchModule == WATCH_MODULE)
- continue;
-
- if (!mir_strcmp(module, WatchListArray.item[i].module) && WatchListArray.item[i].setting[0]) {
- if (!mir_strcmp(setting, WatchListArray.item[i].setting)) {
- // yes so uncheck it
- CheckMenuItem(hSubMenu, MENU_WATCH_ITEM, MF_CHECKED | MF_BYCOMMAND);
- watching = 1;
- break;
- }
- }
- }
+ if (ListView_GetSelectedCount(hwnd2List) > 1) {
+ RemoveMenu(hSubMenu, 3, MF_BYPOSITION); // convert
+ RemoveMenu(hSubMenu, MENU_EDIT_SET, MF_BYCOMMAND);
+ RemoveMenu(hSubMenu, MENU_COPY_SET, MF_BYCOMMAND);
+ RemoveMenu(hSubMenu, MENU_WATCH_ITEM, MF_BYCOMMAND);
}
+
+ char setting[FLD_SIZE];
+ if (!ListView_GetItemTextA(hwnd2List, hti.iItem, 0, setting, SIZEOF(setting))) return;
+ // check if the setting is being watched and if it is then check the menu item
+ int watchIdx = WatchedArrayIndex(info.hContact, info.module, setting, 1);
+ if (watchIdx >= 0)
+ CheckMenuItem(hSubMenu, MENU_WATCH_ITEM, MF_CHECKED | MF_BYCOMMAND);
+
switch (TrackPopupMenu(hSubMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hwnd, NULL)) {
case MENU_EDIT_SET:
- editSetting(info->hContact, info->module, setting);
+ editSetting(info.hContact, info.module, setting);
break;
- case MENU_ADD_BYTE:
- dbsetting = (DBsetting*)mir_alloc(sizeof(DBsetting)); // gets safe_free()ed in the window proc
- dbv.type = DBVT_BYTE;
- dbsetting->dbv = dbv;
- dbsetting->hContact = hContact;
- dbsetting->module = mir_tstrdup(module);
- dbsetting->setting = mir_tstrdup("");
- CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd, EditSettingDlgProc, (LPARAM)dbsetting);
+ case MENU_COPY_SET:
+ copySetting(info.hContact, info.module, setting);
break;
+ case MENU_ADD_BYTE:
+ newSetting(info.hContact, info.module, DBVT_BYTE);
+ return;
+
case MENU_ADD_WORD:
- dbsetting = (DBsetting*)mir_alloc(sizeof(DBsetting)); // gets safe_free()ed in the window proc
- dbv.type = DBVT_WORD;
- dbsetting->dbv = dbv;
- dbsetting->hContact = hContact;
- dbsetting->module = mir_tstrdup(module);
- dbsetting->setting = mir_tstrdup("");
- CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd, EditSettingDlgProc, (LPARAM)dbsetting);
- break;
+ newSetting(info.hContact, info.module, DBVT_WORD);
+ return;
case MENU_ADD_DWORD:
- dbsetting = (DBsetting*)mir_alloc(sizeof(DBsetting)); // gets safe_free()ed in the window proc
- dbv.type = DBVT_DWORD;
- dbsetting->dbv = dbv;
- dbsetting->hContact = hContact;
- dbsetting->module = mir_tstrdup(module);
- dbsetting->setting = mir_tstrdup("");
- CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd, EditSettingDlgProc, (LPARAM)dbsetting);
- break;
+ newSetting(info.hContact, info.module, DBVT_DWORD);
+ return;
case MENU_ADD_STRING:
- dbsetting = (DBsetting*)mir_alloc(sizeof(DBsetting)); // gets safe_free()ed in the window proc
- dbv.type = DBVT_ASCIIZ;
- dbsetting->dbv = dbv;
- dbsetting->hContact = hContact;
- dbsetting->module = mir_tstrdup(module);
- dbsetting->setting = mir_tstrdup("");
- CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd, EditSettingDlgProc, (LPARAM)dbsetting);
- break;
-
- case MENU_ADD_UNICODE:
- dbsetting = (DBsetting*)mir_alloc(sizeof(DBsetting)); // gets safe_free()ed in the window proc
- dbv.type = DBVT_UTF8;
- dbsetting->dbv = dbv;
- dbsetting->hContact = hContact;
- dbsetting->module = mir_tstrdup(module);
- dbsetting->setting = mir_tstrdup("");
- CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_EDIT_SETTING), hwnd, EditSettingDlgProc, (LPARAM)dbsetting);
- break;
+ newSetting(info.hContact, info.module, DBVT_ASCIIZ);
+ return;
case MENU_ADD_BLOB:
- dbsetting = (DBsetting*)mir_alloc(sizeof(DBsetting)); // gets safe_free()ed in the window proc
- dbv.type = DBVT_BLOB;
- dbsetting->dbv = dbv;
- dbsetting->hContact = hContact;
- dbsetting->module = mir_tstrdup(module);
- dbsetting->setting = mir_tstrdup("");
- CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd, EditSettingDlgProc, (LPARAM)dbsetting);
- break;
+ newSetting(info.hContact, info.module, DBVT_BLOB);
+ return;
- ///////////////////////// convert to submenu
case MENU_CHANGE2BYTE:
- if (convertSetting(hContact, module, setting, 0)) {
- lvi.iImage = 1;
- ListView_SetItem(hSettings, &lvi);
- }
+ convertSetting(info.hContact, info.module, setting, DBVT_BYTE);
break;
case MENU_CHANGE2WORD:
- if (convertSetting(hContact, module, setting, 1)) {
- lvi.iImage = 2;
- ListView_SetItem(hSettings, &lvi);
- }
+ convertSetting(info.hContact, info.module, setting, DBVT_WORD);
break;
case MENU_CHANGE2DWORD:
- if (convertSetting(hContact, module, setting, 2)) {
- lvi.iImage = 3;
- ListView_SetItem(hSettings, &lvi);
- }
+ convertSetting(info.hContact, info.module, setting, DBVT_DWORD);
break;
case MENU_CHANGE2STRING:
- if (convertSetting(hContact, module, setting, 3)) {
- lvi.iImage = 4;
- ListView_SetItem(hSettings, &lvi);
- }
+ convertSetting(info.hContact, info.module, setting, DBVT_ASCIIZ);
break;
case MENU_CHANGE2UNICODE:
- if (convertSetting(hContact, module, setting, 4)) {
- lvi.iImage = 5;
- ListView_SetItem(hSettings, &lvi);
- }
+ convertSetting(info.hContact, info.module, setting, DBVT_UTF8);
break;
- ///////////////////////// convert to submenu
- case MENU_VIEWDECRYPT:
- if (!db_get(hContact, module, setting, &dbv) && dbv.type == DBVT_ASCIIZ) {
- if (mir_strcmp(setting, "LoginPassword"))
- msg(dbv.pszVal, Translate("Decoded string.."));
- else {
- char *str = mir_strdup(dbv.pszVal);
- char *str1 = str;
- for (; *str1; ++str1) {
- const char c = *str1 ^ 0xc3;
- if (c) *str1 = c;
- }
-
- WCHAR *res = mir_utf8decodeW(str);
- MessageBoxW(0, res, TranslateW(L"Decoded string.."), MB_OK);
- mir_free(res);
- mir_free(str);
- }
- db_free(&dbv);
- }
- break;
-
- case MENU_VIEWENCRYPT:
- if (!db_get(hContact, module, setting, &dbv) && dbv.type == DBVT_ASCIIZ)
- msg(dbv.pszVal, Translate("Encoded string.."));
- db_free(&dbv);
- break;
-
- case MENU_DECRYPT:
- if (!db_get_s(hContact, module, setting, &dbv))
- db_set_s(hContact, module, setting, dbv.pszVal);
- db_free(&dbv);
- break;
-
- case MENU_ENCRYPT:
- if (!db_get_s(hContact, module, setting, &dbv))
- db_set_s(hContact, module, setting, dbv.pszVal);
- db_free(&dbv);
- break;
-
- ///////////////////////// divider
case MENU_WATCH_ITEM:
- if (!watching)
- addSettingToWatchList(hContact, module, setting);
+ if (watchIdx < 0)
+ addSettingToWatchList(info.hContact, info.module, setting);
else
- freeWatchListItem(i);
- if (hwnd2watchedVarsWindow)
- PopulateWatchedWindow(GetDlgItem(hwnd2watchedVarsWindow, IDC_VARS));
+ freeWatchListItem(watchIdx);
+ PopulateWatchedWindow();
break;
case MENU_DELETE_SET:
- DeleteSettingsFromList(hSettings, hContact, module, setting);
+ DeleteSettingsFromList(info.hContact, info.module, setting);
+ break;
+
+ case MENU_REFRESH:
+ PopulateSettings(info.hContact, info.module);
break;
}
}
diff --git a/plugins/DbEditorPP/src/settingsdlg.cpp b/plugins/DbEditorPP/src/settingsdlg.cpp
new file mode 100644
index 0000000000..334e1c8a80
--- /dev/null
+++ b/plugins/DbEditorPP/src/settingsdlg.cpp
@@ -0,0 +1,333 @@
+#include "headers.h"
+
+int saveAsType(HWND hwnd, int original)
+{
+ if (!IsWindowVisible(GetDlgItem(hwnd, GRP_TYPE)))
+ return original;
+
+ if (IsDlgButtonChecked(hwnd, CHK_BYTE))
+ return DBVT_BYTE;
+ else if (IsDlgButtonChecked(hwnd, CHK_WORD))
+ return DBVT_WORD;
+ else if (IsDlgButtonChecked(hwnd, CHK_DWORD))
+ return DBVT_DWORD;
+ else if (IsDlgButtonChecked(hwnd, CHK_STRING))
+ return DBVT_ASCIIZ;
+
+ return original;
+}
+
+
+INT_PTR CALLBACK EditSettingDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch (msg)
+ {
+ case WM_INITDIALOG:
+ {
+ SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)lParam);
+
+ struct DBsetting *dbsetting = (struct DBsetting*)lParam;
+
+ char val[16] = {0};
+ int convert = 0;
+
+ switch (dbsetting->dbv.type)
+ {
+ case DBVT_BYTE:
+ CheckRadioButton(hwnd, CHK_BYTE, CHK_STRING, CHK_BYTE);
+ ShowWindow(GetDlgItem(hwnd, IDC_STRING), SW_HIDE);
+ CheckRadioButton(hwnd, CHK_HEX, CHK_DECIMAL, (g_Hex & HEX_BYTE) ? CHK_HEX : CHK_DECIMAL);
+ if (dbsetting->setting) mir_snprintf(val, (g_Hex & HEX_BYTE) ? "0x%02X" : "%u", dbsetting->dbv.bVal);
+ break;
+ case DBVT_WORD:
+ CheckRadioButton(hwnd, CHK_BYTE, CHK_STRING, CHK_WORD);
+ ShowWindow(GetDlgItem(hwnd, IDC_STRING), SW_HIDE);
+ CheckRadioButton(hwnd, CHK_HEX, CHK_DECIMAL, (g_Hex & HEX_WORD) ? CHK_HEX : CHK_DECIMAL);
+ if (dbsetting->setting) mir_snprintf(val, (g_Hex & HEX_WORD) ? "0x%04X" : "%u", dbsetting->dbv.wVal);
+ break;
+ case DBVT_DWORD:
+ CheckRadioButton(hwnd, CHK_BYTE, CHK_STRING, CHK_DWORD);
+ ShowWindow(GetDlgItem(hwnd, IDC_STRING), SW_HIDE);
+ CheckRadioButton(hwnd, CHK_HEX, CHK_DECIMAL, (g_Hex & HEX_DWORD) ? CHK_HEX : CHK_DECIMAL);
+ if (dbsetting->setting) mir_snprintf(val, (g_Hex & HEX_DWORD) ? "0x%08X" : "%u", dbsetting->dbv.dVal);
+ break;
+
+ case DBVT_ASCIIZ:
+ case DBVT_UTF8:
+ case DBVT_WCHAR:
+ ShowWindow(GetDlgItem(hwnd, IDC_STRING), SW_SHOW);
+ ShowWindow(GetDlgItem(hwnd, IDC_SETTINGVALUE), SW_HIDE);
+ ShowWindow(GetDlgItem(hwnd, CHK_HEX), SW_HIDE);
+ ShowWindow(GetDlgItem(hwnd, CHK_DECIMAL), SW_HIDE);
+ ShowWindow(GetDlgItem(hwnd, GRP_BASE), SW_HIDE);
+ break;
+
+ case DBVT_BLOB:
+ ShowWindow(GetDlgItem(hwnd, IDC_STRING), SW_HIDE);
+ ShowWindow(GetDlgItem(hwnd, IDC_SETTINGVALUE), SW_HIDE);
+ ShowWindow(GetDlgItem(hwnd, IDC_BLOB), SW_SHOW);
+ ShowWindow(GetDlgItem(hwnd, CHK_HEX), SW_HIDE);
+ ShowWindow(GetDlgItem(hwnd, CHK_DECIMAL), SW_HIDE);
+ ShowWindow(GetDlgItem(hwnd, GRP_BASE), SW_HIDE);
+ break;
+
+ case DBVT_DELETED: // resident
+ CheckRadioButton(hwnd, CHK_BYTE, CHK_STRING, CHK_STRING);
+ CheckRadioButton(hwnd, CHK_HEX, CHK_DECIMAL, CHK_DECIMAL);
+ convert = 1;
+ break;
+
+ default:
+ msg(TranslateT("Unknown DBVariant type!"));
+ DestroyWindow(hwnd);
+ return TRUE;
+ }
+
+
+ if (dbsetting->setting) {
+ SetDlgItemTextA(hwnd, IDC_SETTINGNAME, dbsetting->setting);
+
+ switch (dbsetting->dbv.type)
+ {
+ case DBVT_BYTE:
+ case DBVT_WORD:
+ case DBVT_DWORD:
+ SetDlgItemTextA(hwnd, IDC_SETTINGVALUE, val);
+ convert = 1;
+ break;
+
+ case DBVT_ASCIIZ:
+ SetDlgItemTextA(hwnd, IDC_STRING, dbsetting->dbv.pszVal);
+ break;
+
+ case DBVT_WCHAR:
+ SetDlgItemTextW(hwnd, IDC_STRING, dbsetting->dbv.pwszVal);
+ break;
+
+ case DBVT_UTF8:
+ {
+ ptrW tmp(mir_utf8decodeW(dbsetting->dbv.pszVal));
+ SetDlgItemTextW(hwnd, IDC_STRING, tmp);
+ break;
+ }
+
+ case DBVT_BLOB:
+ {
+ ptrA tmp(StringFromBlob(dbsetting->dbv.pbVal, dbsetting->dbv.cpbVal));
+ SetDlgItemTextA(hwnd, IDC_BLOB, tmp);
+ break;
+ }
+ }
+ }
+
+ if (!convert) {
+ ShowWindow(GetDlgItem(hwnd, GRP_TYPE), SW_HIDE);
+ ShowWindow(GetDlgItem(hwnd, CHK_BYTE), SW_HIDE);
+ ShowWindow(GetDlgItem(hwnd, CHK_WORD), SW_HIDE);
+ ShowWindow(GetDlgItem(hwnd, CHK_DWORD), SW_HIDE);
+ ShowWindow(GetDlgItem(hwnd, CHK_STRING), SW_HIDE);
+ }
+
+ TranslateDialogDefault(hwnd);
+ {
+ TCHAR text[MSG_SIZE];
+ mir_sntprintf(text, dbsetting->setting?TranslateT("Edit setting (%s)"):TranslateT("New setting (%s)"), DBVType(dbsetting->dbv.type));
+ SetWindowText(hwnd, text);
+ }
+ }
+ return TRUE;
+
+ case WM_COMMAND:
+ switch (LOWORD(wParam))
+ {
+ case CHK_BYTE:
+ case CHK_WORD:
+ case CHK_DWORD:
+ EnableWindow(GetDlgItem(hwnd, CHK_HEX), 1);
+ EnableWindow(GetDlgItem(hwnd, CHK_DECIMAL), 1);
+ CheckRadioButton(hwnd, CHK_BYTE, CHK_STRING, LOWORD(wParam));
+ break;
+ case CHK_STRING:
+ EnableWindow(GetDlgItem(hwnd, CHK_HEX), 0);
+ EnableWindow(GetDlgItem(hwnd, CHK_DECIMAL), 0);
+ CheckRadioButton(hwnd, CHK_BYTE, CHK_STRING, LOWORD(wParam));
+ break;
+
+ case CHK_HEX:
+ case CHK_DECIMAL:
+ CheckRadioButton(hwnd, CHK_HEX, CHK_DECIMAL, LOWORD(wParam));
+ {
+ TCHAR *setting, text[32];
+ int settingLength, tmp;
+ settingLength = GetWindowTextLength(GetDlgItem(hwnd, IDC_SETTINGVALUE));
+ if (settingLength)
+ {
+ setting = (TCHAR*)mir_alloc((settingLength+1)*sizeof(TCHAR));
+ GetDlgItemText(hwnd, IDC_SETTINGVALUE, setting, settingLength + 1);
+ if (LOWORD(wParam) == CHK_DECIMAL && IsDlgButtonChecked(hwnd, CHK_DECIMAL))
+ {
+ _stscanf(setting, _T("%X"), &tmp);
+ mir_sntprintf(text, _T("%u"), tmp);
+ }
+ else
+ {
+ _stscanf(setting, _T("%u"), &tmp);
+ mir_sntprintf(text, _T("%X"), tmp);
+ }
+ SetDlgItemText(hwnd, IDC_SETTINGVALUE, text);
+ mir_free(setting);
+ }
+ }
+ break;
+
+ case IDC_SETTINGNAME:
+ EnableWindow(GetDlgItem(hwnd, IDOK), GetWindowTextLength(GetDlgItem(hwnd, IDC_SETTINGNAME)));
+ break;
+
+ case IDOK:
+ {
+ struct DBsetting *dbsetting = (struct DBsetting*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+
+ TCHAR settingname[FLD_SIZE];
+ GetDlgItemText(hwnd, IDC_SETTINGNAME, settingname, SIZEOF(settingname));
+
+ if (settingname[0])
+ {
+ int valueID = 0;
+
+ switch (dbsetting->dbv.type)
+ {
+ case DBVT_BYTE:
+ case DBVT_WORD:
+ case DBVT_DWORD:
+ case DBVT_DELETED:
+ valueID = IDC_SETTINGVALUE;
+ break;
+
+ case DBVT_ASCIIZ:
+ case DBVT_UTF8:
+ case DBVT_WCHAR:
+ valueID = IDC_STRING;
+ break;
+
+ case DBVT_BLOB:
+ valueID = IDC_BLOB;
+ break;
+ default:
+ break;
+ }
+
+ if (!valueID)
+ break;
+
+ int len = GetWindowTextLength(GetDlgItem(hwnd, valueID))+1;
+ TCHAR *value = (TCHAR*)mir_alloc(len*sizeof(TCHAR));
+
+ GetDlgItemText(hwnd, valueID, value, len);
+ _T2A setting(settingname);
+
+ int type = saveAsType(hwnd, dbsetting->dbv.type);
+ int res = 0;
+
+ // write the setting
+ switch (type)
+ {
+ case DBVT_BYTE:
+ case DBVT_WORD:
+ case DBVT_DWORD:
+ res = setNumericValue(dbsetting->hContact, dbsetting->module, setting, _tcstoul(value, NULL, IsDlgButtonChecked(hwnd, CHK_HEX)? 16 : 10), type);
+ break;
+ case DBVT_ASCIIZ:
+ case DBVT_UTF8:
+ case DBVT_WCHAR:
+ res = setTextValue(dbsetting->hContact, dbsetting->module, setting, value, type);
+ break;
+ case DBVT_BLOB:
+ res = WriteBlobFromString(dbsetting->hContact, dbsetting->module, setting, _T2A(value), len);
+ break;
+ }
+
+ mir_free(value);
+
+ if (!res) {
+ msg(TranslateT("Unable to store value in this data type!"));
+ break;
+ }
+
+ // delete old setting
+ if (dbsetting->setting && mir_strcmp(setting, dbsetting->setting))
+ db_unset(dbsetting->hContact, dbsetting->module, dbsetting->setting);
+ }
+
+ } // fall through
+ case IDCANCEL:
+ {
+ struct DBsetting *dbsetting = (struct DBsetting*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+ mir_free(dbsetting->module);
+ mir_free(dbsetting->setting);
+ db_free(&dbsetting->dbv);
+ mir_free(dbsetting);
+ DestroyWindow(hwnd);
+ }
+ break;
+ }
+ }
+ return 0;
+}
+
+
+void editSetting(MCONTACT hContact, const char *module, const char *setting)
+{
+ DBVARIANT dbv = { 0 };
+ if (!db_get_s(hContact, module, setting, &dbv, 0) || IsResidentSetting(module, setting))
+ {
+ // gets free()ed in the window proc
+ struct DBsetting *dbsetting = (struct DBsetting *)mir_calloc(sizeof(struct DBsetting));
+
+ dbsetting->dbv = dbv;
+ dbsetting->hContact = hContact;
+ dbsetting->module = mir_strdup(module);
+ dbsetting->setting = mir_strdup(setting);
+
+ CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd2mainWindow, EditSettingDlgProc, (LPARAM)dbsetting);
+ }
+}
+
+
+void copySetting(MCONTACT hContact, const char *module, const char *setting)
+{
+ DBVARIANT dbv = { 0 }, dbv2;
+ if (db_get_s(hContact, module, setting, &dbv, 0)) return;
+
+ char tmp[FLD_SIZE];
+
+ for (int i = 1; i < 10; i++) {
+ mir_snprintf(tmp, "%s (%d)", setting, i);
+ if (!db_get_s(hContact, module, tmp, &dbv2, 0))
+ db_free(&dbv2);
+ else {
+ // gets free()ed in the window proc
+ struct DBsetting *dbsetting = (struct DBsetting *)mir_calloc(sizeof(struct DBsetting));
+
+ dbsetting->dbv = dbv;
+ dbsetting->hContact = hContact;
+ dbsetting->module = mir_strdup(module);
+ dbsetting->setting = mir_strdup(tmp);
+ CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd2mainWindow, EditSettingDlgProc, (LPARAM)dbsetting);
+ return;
+ }
+ }
+ db_free(&dbv);
+}
+
+
+void newSetting(MCONTACT hContact, const char *module, int type)
+{
+ // gets safe_free()ed in the window proc
+ DBsetting *dbsetting = (DBsetting*)mir_calloc(sizeof(DBsetting));
+ dbsetting->dbv.type = type;
+ dbsetting->hContact = hContact;
+ dbsetting->module = mir_strdup(module);
+ dbsetting->setting = NULL;
+ CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_EDIT_SETTING), hwnd2mainWindow, EditSettingDlgProc, (LPARAM)dbsetting);
+}
diff --git a/plugins/DbEditorPP/src/threads.cpp b/plugins/DbEditorPP/src/threads.cpp
deleted file mode 100644
index 7ac144adc4..0000000000
--- a/plugins/DbEditorPP/src/threads.cpp
+++ /dev/null
@@ -1,48 +0,0 @@
-#include "headers.h"
-
-// thread stuff
-
-struct FORK_ARG {
- HANDLE hEvent;
- void (__cdecl *threadcode)(void*);
- unsigned (__stdcall *threadcodeex)(void*);
- void *arg;
-};
-
-void __cdecl forkthread_r(void *param)
-{
- struct FORK_ARG *fa=(struct FORK_ARG*)param;
- void (*callercode)(void*)=fa->threadcode;
- void *arg=fa->arg;
-
- CallService(MS_SYSTEM_THREAD_PUSH,0,0);
-
- SetEvent(fa->hEvent);
-
- __try {
- callercode(arg);
- } __finally {
- CallService(MS_SYSTEM_THREAD_POP,0,0);
- }
-
- return;
-}
-
-unsigned long forkthread ( void (__cdecl *threadcode)(void*),unsigned long stacksize,void *arg)
-{
- unsigned long rc;
- struct FORK_ARG fa;
-
- fa.hEvent=CreateEvent(NULL,FALSE,FALSE,NULL);
- fa.threadcode=threadcode;
- fa.arg=arg;
-
- rc=_beginthread(forkthread_r,stacksize,&fa);
-
- if ((unsigned long)-1L != rc) {
- WaitForSingleObject(fa.hEvent,INFINITE);
- }
- CloseHandle(fa.hEvent);
-
- return rc;
-}
diff --git a/plugins/DbEditorPP/src/watchedvars.cpp b/plugins/DbEditorPP/src/watchedvars.cpp
index 4059035738..3b4f9a3c9b 100644
--- a/plugins/DbEditorPP/src/watchedvars.cpp
+++ b/plugins/DbEditorPP/src/watchedvars.cpp
@@ -1,153 +1,203 @@
#include "headers.h"
-int addSettingToWatchList(MCONTACT hContact, char* module, char* setting)
+HWND hwnd2watchedVarsWindow = NULL;
+
+static WatchListArrayStruct WatchListArray = {0};
+
+static int lastColumn = -1;
+
+ColumnsSettings csWatchList[] = {
+ { LPGENT("Contact"), 0, "Watch0width", 100 },
+ { LPGENT("Module"), 1, "Watch1width", 100 },
+ { LPGENT("Setting"), 2, "Watch2width", 100 },
+ { LPGENT("Value"), 3, "Watch3width", 200 },
+ { LPGENT("Type"), 4, "Watch4width", 75 },
+ {0}
+};
+
+
+
+int WatchedArrayIndex(MCONTACT hContact, const char *module, const char *setting, int strict) {
+ for (int i = 0; i < WatchListArray.count; i++) {
+ if (hContact == WatchListArray.item[i].hContact)
+ if (!mir_strcmp(module, WatchListArray.item[i].module))
+ // empty setting = module watching
+ if ((!strict && !WatchListArray.item[i].setting) || !mir_strcmp(setting, WatchListArray.item[i].setting))
+ return i;
+ }
+ return -1;
+}
+
+
+int addSettingToWatchList(MCONTACT hContact, const char *module, const char *setting)
{
if (WatchListArray.count == WatchListArray.size)
{
WatchListArray.size += 32;
WatchListArray.item = (struct DBsetting*)mir_realloc(WatchListArray.item, sizeof(struct DBsetting)*WatchListArray.size);
}
- if (!WatchListArray.item) return 0;
- if (setting && db_get(hContact, module, setting, &(WatchListArray.item[WatchListArray.count].dbv))) return 0;
+ if (!WatchListArray.item)
+ return 0;
+
+ db_get_s(hContact, module, setting, &(WatchListArray.item[WatchListArray.count].dbv), 0);
+
WatchListArray.item[WatchListArray.count].hContact = hContact;
- WatchListArray.item[WatchListArray.count].module = mir_tstrdup(module);
- if (setting) WatchListArray.item[WatchListArray.count].setting = mir_tstrdup(setting);
- else WatchListArray.item[WatchListArray.count].setting = 0;
+ WatchListArray.item[WatchListArray.count].module = mir_strdup(module);
+
+ if (setting)
+ WatchListArray.item[WatchListArray.count].setting = mir_strdup(setting);
+ else
+ WatchListArray.item[WatchListArray.count].setting = 0;
- WatchListArray.item[WatchListArray.count].WatchModule = setting ? WATCH_SETTING : WATCH_MODULE;
WatchListArray.count++;
return 1;
}
+
void freeWatchListItem(int item)
{
- if (WatchListArray.item[item].module) mir_free(WatchListArray.item[item].module);
+ if (item < 0 || item >= WatchListArray.count) return;
+
+ if (WatchListArray.item[item].module)
+ mir_free(WatchListArray.item[item].module);
+
WatchListArray.item[item].module = 0;
- if (WatchListArray.item[item].setting) mir_free(WatchListArray.item[item].setting);
+
+ if (WatchListArray.item[item].setting)
+ mir_free(WatchListArray.item[item].setting);
+
WatchListArray.item[item].setting = 0;
db_free(&(WatchListArray.item[item].dbv));
WatchListArray.item[item].hContact = 0;
}
-void addwatchtolist(HWND hwnd2list, struct DBsetting *lParam)
+void addwatchtolist(HWND hwnd, struct DBsetting *lParam)
{
LVITEM lvItem;
int index;
- char data[32], tmp[32];
+
DBVARIANT *dbv = &(lParam->dbv);
MCONTACT hContact = lParam->hContact;
+
char *module = lParam->module;
char *setting = lParam->setting;
+
if (!module) return;
+
lvItem.lParam = (LPARAM)lParam->hContact;
lvItem.mask = LVIF_TEXT | LVIF_PARAM;
lvItem.iItem = 0;
lvItem.iSubItem = 0;
- if (!setting || (int)(lParam->setting) == WATCH_MODULE) // add every item in the module and return
+ if (!setting) // add every item in the module and return
{
ModuleSettingLL settinglist;
- struct DBsetting dummy;
+ struct DBsetting dummy = {0};
ModSetLinkLinkItem *setting;
- if (!EnumSettings(hContact, module, &settinglist)) return;
+ if (IsModuleEmpty(hContact, module) || !EnumSettings(hContact, module, &settinglist)) return;
+
dummy.hContact = hContact;
- dummy.module = mir_tstrdup(module);
+ dummy.module = module;
setting = settinglist.first;
while (setting)
{
dummy.setting = setting->name;
- addwatchtolist(hwnd2list, &dummy);
+ addwatchtolist(hwnd, &dummy);
setting = (ModSetLinkLinkItem *)setting->next;
}
- mir_free(dummy.module);
FreeModuleSettingLL(&settinglist);
return;
}
+
db_free(&(lParam->dbv));
- if (GetSetting(hContact, module, setting, &(lParam->dbv))) return;
- if (!hContact)
- lvItem.pszText = "NULL";
- else
- lvItem.pszText = (char*)GetContactName(hContact, NULL, 1);
+ db_get_s(hContact, module, setting, &(lParam->dbv), 0);
- index = ListView_InsertItem(hwnd2list, &lvItem);
+ TCHAR data[32], tmp[16], name[NAME_SIZE];
- WCHAR* ptszText = mir_a2u(lvItem.pszText);
- ListView_SetItemTextW(hwnd2list, index, 0, ptszText);
- mir_free(ptszText);
+ GetContactName(hContact, NULL, name, SIZEOF(name));
+ lvItem.pszText = name;
- ListView_SetItemText(hwnd2list, index, 1, module);
- ListView_SetItemText(hwnd2list, index, 2, setting);
+ index = ListView_InsertItem(hwnd, &lvItem);
+
+ ListView_SetItemText(hwnd, index, 0, lvItem.pszText);
+ ListView_SetItemTextA(hwnd, index, 1, module);
+ ListView_SetItemTextA(hwnd, index, 2, setting);
+ ListView_SetItemText(hwnd, index, 4, DBVType(dbv->type));
+
+ data[0] = 0;
switch (dbv->type) {
case DBVT_BLOB:
{
- int j;
- char *data = NULL;
- if (!(data = (char*)mir_realloc(data, 3 * (dbv->cpbVal + 1))))
- return;
- data[0] = '\0';
- for (j = 0; j < dbv->cpbVal; j++)
- {
- char tmp[16];
- mir_snprintf(tmp, "%02X ", (BYTE)dbv->pbVal[j]);
- mir_strcat(data, tmp);
- }
- ListView_SetItemText(hwnd2list, index, 4, data);
- ListView_SetItemText(hwnd2list, index, 3, "BLOB");
- mir_free(data);
+ ptrA str(StringFromBlob(dbv->pbVal, dbv->cpbVal));
+ ListView_SetItemTextA(hwnd, index, 3, str);
+ break;
}
- break;
-
case DBVT_BYTE:
- mir_snprintf(data, SIZEOF(data), "0x%02X (%s)", dbv->bVal, itoa(dbv->bVal, tmp, 10));
- ListView_SetItemText(hwnd2list, index, 4, data);
- ListView_SetItemText(hwnd2list, index, 3, "BYTE");
+ mir_sntprintf(data, _T("0x%02X (%s)"), dbv->bVal, _ultot(dbv->bVal, tmp, 10));
+ ListView_SetItemText(hwnd, index, 3, data);
break;
-
case DBVT_WORD:
- mir_snprintf(data, SIZEOF(data), "0x%04X (%s)", dbv->wVal, itoa(dbv->wVal, tmp, 10));
- ListView_SetItemText(hwnd2list, index, 4, data);
- ListView_SetItemText(hwnd2list, index, 3, "WORD");
+ mir_sntprintf(data, _T("0x%04X (%s)"), dbv->wVal, _ultot(dbv->wVal, tmp, 10));
+ ListView_SetItemText(hwnd, index, 3, data);
break;
case DBVT_DWORD:
- mir_snprintf(data, SIZEOF(data), "0x%08X (%s)", dbv->dVal, itoa(dbv->dVal, tmp, 10));
- ListView_SetItemText(hwnd2list, index, 4, data);
- ListView_SetItemText(hwnd2list, index, 3, "DWORD");
+ mir_sntprintf(data, _T("0x%08X (%s)"), dbv->dVal, _ultot(dbv->dVal, tmp, 10));
+ ListView_SetItemText(hwnd, index, 3, data);
break;
case DBVT_ASCIIZ:
- ListView_SetItemText(hwnd2list, index, 4, dbv->pszVal);
- ListView_SetItemText(hwnd2list, index, 3, "STRING");
+ ListView_SetItemTextA(hwnd, index, 3, dbv->pszVal);
break;
+ case DBVT_WCHAR:
+ {
+ ptrT str(mir_u2t(dbv->pwszVal));
+ ListView_SetItemText(hwnd, index, 3, str);
+ break;
+ }
+
case DBVT_UTF8:
- int length = (int)mir_strlen(dbv->pszVal) + 1;
- WCHAR *wc = (WCHAR*)_alloca(length*sizeof(WCHAR));
- MultiByteToWideChar(CP_UTF8, 0, dbv->pszVal, -1, wc, length);
- ListView_SetItemTextW(hwnd2list, index, 4, wc);
- ListView_SetItemText(hwnd2list, index, 3, "UNICODE");
+ {
+ ptrT str(mir_utf8decodeT(dbv->pszVal));
+ ListView_SetItemText(hwnd, index, 3, str);
break;
}
+ case DBVT_DELETED:
+ if (IsResidentSetting(module, setting))
+ ListView_SetItemText(hwnd, index, 3, TranslateT("*** resident ***"));
+ break;
+ } // switch
+
}
-void PopulateWatchedWindow(HWND hwnd)
+
+void PopulateWatchedWindow()
{
- int i;
+ if (!hwnd2watchedVarsWindow) return;
+ HWND hwnd = GetDlgItem(hwnd2watchedVarsWindow, IDC_VARS);
ListView_DeleteAllItems(hwnd);
- for (i = 0; i < WatchListArray.count; i++)
- {
+ for (int i = 0; i < WatchListArray.count; i++) {
addwatchtolist(hwnd, &(WatchListArray.item[i]));
}
+
+ if (lastColumn != -1) {
+ ColumnsSortParams params;
+ params.hList = hwnd;
+ params.column = lastColumn;
+ params.last = -1;
+ ListView_SortItemsEx(params.hList, ColumnsCompare, (LPARAM)&params);
+ }
}
+
void freeAllWatches()
{
- int i;
- for (i = 0; i < WatchListArray.count; i++)
+ ListView_DeleteAllItems(GetDlgItem(hwnd2watchedVarsWindow, IDC_VARS));
+ for (int i = 0; i < WatchListArray.count; i++)
{
freeWatchListItem(i);
}
@@ -156,6 +206,7 @@ void freeAllWatches()
WatchListArray.count = 0;
}
+
int WatchDialogResize(HWND, LPARAM, UTILRESIZECONTROL *urc)
{
switch (urc->wId)
@@ -170,45 +221,52 @@ int WatchDialogResize(HWND, LPARAM, UTILRESIZECONTROL *urc)
return RD_ANCHORX_LEFT | RD_ANCHORY_TOP;
}
+
+LRESULT CALLBACK WatchSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch (msg) {
+
+ case WM_KEYUP:
+ if (wParam == VK_F5) {
+ PopulateWatchedWindow();
+ }
+ break;
+ }
+ return mir_callNextSubclass(hwnd, WatchSubclassProc, msg, wParam, lParam);
+}
+
+
INT_PTR CALLBACK WatchDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_INITDIALOG:
{
- // setup the list...
- LVCOLUMN sLC;
-
- sLC.fmt = LVCFMT_LEFT;
- ListView_SetExtendedListViewStyle(GetDlgItem(hwnd, IDC_VARS), 32 | LVS_EX_SUBITEMIMAGES); //LVS_EX_FULLROWSELECT
- sLC.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH;
-
- sLC.pszText = Translate("Contact"); sLC.cx = 80;
- ListView_InsertColumn(GetDlgItem(hwnd, IDC_VARS), 0, &sLC);
- sLC.pszText = Translate("Module"); sLC.cx = 80;
- ListView_InsertColumn(GetDlgItem(hwnd, IDC_VARS), 1, &sLC);
- sLC.pszText = Translate("Setting"); sLC.cx = 80;
- ListView_InsertColumn(GetDlgItem(hwnd, IDC_VARS), 2, &sLC);
- sLC.pszText = Translate("Type"); sLC.cx = 60;
- ListView_InsertColumn(GetDlgItem(hwnd, IDC_VARS), 3, &sLC);
- sLC.pszText = Translate("Data"); sLC.cx = 300;
- ListView_InsertColumn(GetDlgItem(hwnd, IDC_VARS), 4, &sLC);
-
- PopulateWatchedWindow(GetDlgItem(hwnd, IDC_VARS));
-
+ hwnd2watchedVarsWindow = hwnd;
+ // do the icon
+ SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(ICO_REGEDIT)));
TranslateMenu(GetMenu(hwnd));
TranslateMenu(GetSubMenu(GetMenu(hwnd), 0));
TranslateDialogDefault(hwnd);
- // do the icon
- SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(ICO_REGEDIT)));
+
+ SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_APPWINDOW); // taskbar icon
+
+ ListView_SetExtendedListViewStyle(GetDlgItem(hwnd, IDC_VARS), 32 | LVS_EX_LABELTIP); // LVS_EX_GRIDLINES
+
+ loadListSettings(GetDlgItem(hwnd, IDC_VARS), csWatchList);
+ Utils_RestoreWindowPositionNoMove(hwnd, NULL, modname, "Watch_");
+
+ mir_subclassWindow(GetDlgItem(hwnd, IDC_VARS), WatchSubclassProc);
+
+ PopulateWatchedWindow();
}
return TRUE;
// for the resize
case WM_GETMINMAXINFO:
{
MINMAXINFO *mmi = (MINMAXINFO*)lParam;
- mmi->ptMinTrackSize.x = 200;
- mmi->ptMinTrackSize.y = 90;
+ mmi->ptMinTrackSize.x = 500;
+ mmi->ptMinTrackSize.y = 300;
return 0;
}
case WM_SIZE:
@@ -219,26 +277,25 @@ INT_PTR CALLBACK WatchDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
urd.hInstance = hInst;
urd.hwndDlg = hwnd;
urd.lParam = 0;
- urd.lpTemplate = MAKEINTRESOURCE(IDD_WATCH_DIAG);
+ urd.lpTemplate = MAKEINTRESOURCEA(IDD_WATCH_DIAG);
urd.pfnResizer = WatchDialogResize;
CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd);
break;
-
}
+
case WM_COMMAND:
switch (LOWORD(wParam))
{
case MENU_REMALL_WATCHES:
freeAllWatches();
- ListView_DeleteAllItems(GetDlgItem(hwnd, IDC_VARS));
break;
case MENU_EXIT:
case IDCANCEL:
- hwnd2watchedVarsWindow = 0;
+ hwnd2watchedVarsWindow = NULL;
DestroyWindow(hwnd);
break;
case MENU_REFRESH:
- PopulateWatchedWindow(GetDlgItem(hwnd, IDC_VARS));
+ PopulateWatchedWindow();
}
break;
@@ -246,95 +303,92 @@ INT_PTR CALLBACK WatchDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
switch (LOWORD(wParam))
{
case IDC_VARS:
- switch (((NMHDR*)lParam)->code)
- {
+ switch (((NMHDR*)lParam)->code) {
case NM_DBLCLK:
- {
- LVHITTESTINFO hti;
- LVITEM lvi;
- hti.pt = ((NMLISTVIEW*)lParam)->ptAction;
- if (ListView_SubItemHitTest(GetDlgItem(hwnd, IDC_VARS), &hti) > -1)
{
- if (hti.flags&LVHT_ONITEM)
+ LVHITTESTINFO hti;
+ LVITEM lvi;
+ HWND hwndVars = GetDlgItem(hwnd, IDC_VARS);
+ hti.pt = ((NMLISTVIEW*)lParam)->ptAction;
+ if (ListView_SubItemHitTest(hwndVars, &hti) > -1)
{
- lvi.mask = LVIF_PARAM;
- lvi.iItem = hti.iItem;
- lvi.iSubItem = 0;
- if (ListView_GetItem(GetDlgItem(hwnd, IDC_VARS), &lvi))
+ if (hti.flags&LVHT_ONITEM)
{
- ItemInfo ii;
- ii.hContact = (MCONTACT)lvi.lParam;
- ListView_GetItemText(GetDlgItem(hwnd, IDC_VARS), hti.iItem, 1, ii.module, SIZEOF(ii.module));
- ListView_GetItemText(GetDlgItem(hwnd, IDC_VARS), hti.iItem, 2, ii.setting, SIZEOF(ii.setting));
- ii.type = FW_SETTINGNAME;
- SendMessage(hwnd2mainWindow, WM_FINDITEM, (WPARAM)&ii, 0);
+ lvi.mask = LVIF_PARAM;
+ lvi.iItem = hti.iItem;
+ lvi.iSubItem = 0;
+ if (ListView_GetItem(hwndVars, &lvi))
+ {
+ ItemInfo ii;
+ ii.hContact = (MCONTACT)lvi.lParam;
+ ListView_GetItemTextA(hwndVars, hti.iItem, 1, ii.module, SIZEOF(ii.module));
+ ListView_GetItemTextA(hwndVars, hti.iItem, 2, ii.setting, SIZEOF(ii.setting));
+ ii.type = FW_SETTINGNAME;
+ SendMessage(hwnd2mainWindow, WM_FINDITEM, (WPARAM)&ii, 0);
+ }
}
}
}
- }
- break;
+ break;
+ case LVN_COLUMNCLICK:
+ {
+ LPNMLISTVIEW lv = (LPNMLISTVIEW)lParam;
+ ColumnsSortParams params;
+ params.hList = GetDlgItem(hwnd, IDC_VARS);
+ params.column = lv->iSubItem;
+ params.last = lastColumn;
+ ListView_SortItemsEx(params.hList, ColumnsCompare, (LPARAM)&params);
+ lastColumn = (params.column == lastColumn) ? -1 : params.column;
+ break;
+ }
}
break;
}
break;
+ case WM_DESTROY:
+ ListView_DeleteAllItems(GetDlgItem(hwnd, IDC_VARS));
+ saveListSettings(GetDlgItem(hwnd, IDC_VARS), csWatchList);
+ Utils_SaveWindowPosition(hwnd, NULL, modname, "Watch_");
+ hwnd2watchedVarsWindow = NULL;
+ break;
}
return 0;
}
-void popupWatchedVar(MCONTACT hContact, const char* module, const char* setting)
+void openWatchedVarWindow() {
+
+ if (!hwnd2watchedVarsWindow)
+ CreateDialog(hInst, MAKEINTRESOURCE(IDD_WATCH_DIAG), NULL, WatchDlgProc);
+ else
+ SetForegroundWindow(hwnd2watchedVarsWindow);
+}
+
+
+void popupWatchedVar(MCONTACT hContact, const char *module, const char *setting)
{
- HICON hIcon = LoadIcon(hInst, MAKEINTRESOURCE(ICO_REGEDIT));
- char lpzContactName[MAX_CONTACTNAME];
- char lpzText[MAX_SECONDLINE];
COLORREF colorBack = db_get_dw(NULL, modname, "PopupColour", RGB(255, 0, 0));
- COLORREF colorText = RGB(0, 0, 0);
+ COLORREF colorText = db_get_dw(NULL, modname, "PopupTextColour", RGB(0, 0, 0));
int timeout = db_get_b(NULL, modname, "PopupDelay", 3);
- if (hContact) {
- // contacts nick
- char szProto[256];
- if (GetValue(hContact, "Protocol", "p", szProto, SIZEOF(szProto)))
- mir_snprintf(lpzContactName, SIZEOF(lpzContactName), "%s (%s)", (char*)GetContactName(hContact, szProto, 0), szProto);
- else
- mir_snprintf(lpzContactName, SIZEOF(lpzContactName), nick_unknown);
- }
- else mir_strcpy(lpzContactName, Translate("Settings"));
+ TCHAR name[NAME_SIZE], text[MAX_SECONDLINE], value[MAX_SECONDLINE];
+ int res = 0;
- // 2nd line
- DBVARIANT dbv;
- if (GetSetting(hContact, module, setting, &dbv))
- return;
+ GetContactName(hContact, NULL, name, SIZEOF(name));
- switch (dbv.type) {
- case DBVT_BYTE:
- mir_snprintf(lpzText, SIZEOF(lpzText), Translate("Database Setting Changed: \nModule: \"%s\" , Setting: \"%s\"\nNew Value: (BYTE) %d"), module, setting, dbv.bVal);
- break;
- case DBVT_WORD:
- mir_snprintf(lpzText, SIZEOF(lpzText), Translate("Database Setting Changed: \nModule: \"%s\" , Setting: \"%s\"\nNew Value: (WORD) %d"), module, setting, dbv.wVal);
- break;
- case DBVT_DWORD:
- mir_snprintf(lpzText, SIZEOF(lpzText), Translate("Database Setting Changed: \nModule: \"%s\" , Setting: \"%s\"\nNew Value: (DWORD) 0x%X"), module, setting, dbv.dVal);
- break;
- case DBVT_ASCIIZ:
- mir_snprintf(lpzText, SIZEOF(lpzText), Translate("Database Setting Changed: \nModule: \"%s\" , Setting: \"%s\"\nNew Value: \"%s\""), module, setting, dbv.pszVal);
- break;
- case DBVT_UTF8:
- mir_snprintf(lpzText, SIZEOF(lpzText), Translate("Database Setting Changed: \nModule: \"%s\" , Setting: \"%s\"\nNew Value (UTF8): \"%s\""), module, setting, dbv.pszVal);
- break;
- default:
- return;
- }
+ // 2nd line
+ int type = GetValue(hContact, module, setting, value, SIZEOF(value));
+// if (!type) value = _T("NULL");
- db_free(&dbv);
+ mir_sntprintf(text, TranslateT("Database Setting Changed: \nModule: \"%s\", Setting: \"%s\"\nNew Value (%s): \"%s\""), _A2T(module), _A2T(setting), DBVType(type), value);
- POPUPDATA ppd = { 0 };
+ POPUPDATAT ppd = { 0 };
ppd.lchContact = (MCONTACT)hContact;
- ppd.lchIcon = hIcon;
- mir_tstrncpy(ppd.lpzContactName, lpzContactName, SIZEOF(ppd.lpzContactName));
- mir_tstrncpy(ppd.lpzText, lpzText, SIZEOF(ppd.lpzText));
+ ppd.lchIcon = LoadIcon(hInst, MAKEINTRESOURCE(ICO_REGEDIT));
+ mir_tstrncpy(ppd.lptzContactName, name, SIZEOF(ppd.lptzContactName));
+ mir_tstrncpy(ppd.lptzText, text, SIZEOF(ppd.lptzText));
ppd.colorBack = colorBack;
ppd.colorText = colorText;
ppd.iSeconds = timeout ? timeout : -1;
- PUAddPopup(&ppd);
+ PUAddPopupT(&ppd);
}