diff options
author | George Hazan <ghazan@miranda.im> | 2018-05-17 16:47:04 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-05-17 16:47:04 +0300 |
commit | ba1083b4da33ca44a5ae7d90eabbe3d6d340a81e (patch) | |
tree | ff215cbcb7d606f9898dbb0f038e850540f52e75 /plugins/ZeroNotification | |
parent | 3c641c02b973483e86b9562088719396bbdbe412 (diff) |
XSoundNotify, YAPP, YaRelay, ZeroSwitch, ZeroNotify -> CMPlugin
Diffstat (limited to 'plugins/ZeroNotification')
-rw-r--r-- | plugins/ZeroNotification/src/main.cpp | 143 | ||||
-rw-r--r-- | plugins/ZeroNotification/src/options.cpp | 143 | ||||
-rw-r--r-- | plugins/ZeroNotification/src/stdafx.h | 11 |
3 files changed, 162 insertions, 135 deletions
diff --git a/plugins/ZeroNotification/src/main.cpp b/plugins/ZeroNotification/src/main.cpp index b92f20bc6a..cb6bafbf0b 100644 --- a/plugins/ZeroNotification/src/main.cpp +++ b/plugins/ZeroNotification/src/main.cpp @@ -8,27 +8,13 @@ https://miranda-ng.org/ #include "stdafx.h"
-HINSTANCE hInst;
+CMPlugin g_plugin;
HGENMENU noSoundMenu;
int hLangpack;
-struct CheckBoxValues_t
-{
- DWORD style;
- wchar_t *szDescr;
-};
+int OptionsInitialize(WPARAM, LPARAM);
-static const struct CheckBoxValues_t statusValues[] = {
- { PF2_ONLINE, TEXT("Online") },
- { PF2_SHORTAWAY, TEXT("Away") },
- { PF2_LONGAWAY, TEXT("Not available") },
- { PF2_LIGHTDND, TEXT("Occupied") },
- { PF2_HEAVYDND, TEXT("Do not disturb") },
- { PF2_FREECHAT, TEXT("Free for chat") },
- { PF2_INVISIBLE, TEXT("Invisible") },
- { PF2_OUTTOLUNCH, TEXT("Out to lunch") },
- { PF2_ONTHEPHONE, TEXT("On the phone") }
-};
+/////////////////////////////////////////////////////////////////////////////////////////
PLUGININFOEX pluginInfoEx = {
sizeof(PLUGININFOEX),
@@ -48,50 +34,15 @@ extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) return &pluginInfoEx;
}
-BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD, LPVOID)
-{
- hInst = hinstDLL;
- return TRUE;
-}
-
-static void FillCheckBoxTree(HWND hwndTree, const struct CheckBoxValues_t *values, int nValues, DWORD style)
-{
- TVINSERTSTRUCT tvis;
- tvis.hParent = nullptr;
- tvis.hInsertAfter = TVI_LAST;
- tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_STATE;
- for (int i = 0; i < nValues; i++) {
- tvis.item.lParam = values[i].style;
- tvis.item.pszText = TranslateW(values[i].szDescr);
- tvis.item.stateMask = TVIS_STATEIMAGEMASK;
- tvis.item.state = INDEXTOSTATEIMAGEMASK((style&tvis.item.lParam) != 0 ? 2 : 1);
- TreeView_InsertItem(hwndTree, &tvis);
- }
-}
-
-static DWORD MakeCheckBoxTreeFlags(HWND hwndTree)
-{
- DWORD flags = 0;
-
- TVITEM tvi;
- tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_STATE;
- tvi.hItem = TreeView_GetRoot(hwndTree);
- while (tvi.hItem) {
- TreeView_GetItem(hwndTree, &tvi);
- if (((tvi.state & TVIS_STATEIMAGEMASK) >> 12 == 2))
- flags |= tvi.lParam;
- tvi.hItem = TreeView_GetNextSibling(hwndTree, tvi.hItem);
- }
- return flags;
-}
+/////////////////////////////////////////////////////////////////////////////////////////
+// Update the name on the menu
-//Update the name on the menu
static void UpdateMenuItem()
{
Menu_ModifyItem(noSoundMenu, db_get_b(NULL, "Skin", "UseSound", 1) ? DISABLE_SOUND : ENABLE_SOUND);
}
-//Called when the sound setting in the database is changed
+// Called when the sound setting in the database is changed
static int SoundSettingChanged(WPARAM, LPARAM lParam)
{
DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING*)lParam;
@@ -100,7 +51,7 @@ static int SoundSettingChanged(WPARAM, LPARAM lParam) return 0;
}
-static int SetNotify(const long status)
+int SetNotify(const long status)
{
db_set_b(NULL, "Skin", "UseSound", (BYTE)!(db_get_dw(NULL, MODNAME, "NoSound", DEFAULT_NOSOUND) & status));
db_set_b(NULL, "CList", "DisableTrayFlash", (BYTE)(db_get_dw(NULL, MODNAME, "NoBlink", DEFAULT_NOBLINK) & status));
@@ -110,7 +61,7 @@ static int SetNotify(const long status) return 0;
}
-//Called whenever a change in status is detected
+// Called whenever a change in status is detected
static int ProtoAck(WPARAM, LPARAM lParam)
{
// quit if not status event
@@ -126,82 +77,6 @@ static int ProtoAck(WPARAM, LPARAM lParam) return 0;
}
-static INT_PTR CALLBACK DlgProcNoSoundOpts(HWND hwndDlg, UINT msg, WPARAM, LPARAM lParam)
-{
- DWORD test;
- switch (msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
- SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_NOSOUND), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_NOSOUND), GWL_STYLE) | TVS_NOHSCROLL | TVS_CHECKBOXES);
- SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_NOBLINK), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_NOBLINK), GWL_STYLE) | TVS_NOHSCROLL | TVS_CHECKBOXES);
- SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_NOCLCBLINK), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_NOCLCBLINK), GWL_STYLE) | TVS_NOHSCROLL | TVS_CHECKBOXES);
- CheckDlgButton(hwndDlg, IDC_HIDEMENU, db_get_b(NULL, MODNAME, "HideMenu", 1) ? BST_CHECKED : BST_UNCHECKED);
-
- FillCheckBoxTree(GetDlgItem(hwndDlg, IDC_NOSOUND), statusValues, sizeof(statusValues) / sizeof(statusValues[0]), db_get_dw(NULL, MODNAME, "NoSound", DEFAULT_NOSOUND));
- FillCheckBoxTree(GetDlgItem(hwndDlg, IDC_NOBLINK), statusValues, sizeof(statusValues) / sizeof(statusValues[0]), db_get_dw(NULL, MODNAME, "NoBlink", DEFAULT_NOBLINK));
- FillCheckBoxTree(GetDlgItem(hwndDlg, IDC_NOCLCBLINK), statusValues, sizeof(statusValues) / sizeof(statusValues[0]), db_get_dw(NULL, MODNAME, "NoCLCBlink", DEFAULT_NOCLCBLINK));
- return TRUE;
-
- case WM_COMMAND:
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- break;
-
- case WM_NOTIFY:
- switch (((LPNMHDR)lParam)->idFrom) {
- case IDC_NOSOUND:
- case IDC_NOBLINK:
- case IDC_NOCLCBLINK:
- if (((LPNMHDR)lParam)->code == NM_CLICK) {
- TVHITTESTINFO hti;
- hti.pt.x = (short)LOWORD(GetMessagePos());
- hti.pt.y = (short)HIWORD(GetMessagePos());
- ScreenToClient(((LPNMHDR)lParam)->hwndFrom, &hti.pt);
- if (TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom, &hti)) {
- if (hti.flags & TVHT_ONITEMSTATEICON) {
- TVITEM tvi;
- tvi.mask = TVIF_HANDLE | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
- tvi.hItem = hti.hItem;
- TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom, &tvi);
- tvi.iImage = tvi.iSelectedImage = tvi.iImage == 1 ? 2 : 1;
- TreeView_SetItem(((LPNMHDR)lParam)->hwndFrom, &tvi);
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
- }
- }
- }
- break;
- case 0:
- switch (((LPNMHDR)lParam)->code) {
- case PSN_APPLY:
- db_set_b(NULL, MODNAME, "HideMenu", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_HIDEMENU));
-
- db_set_dw(NULL, MODNAME, "NoSound", MakeCheckBoxTreeFlags(GetDlgItem(hwndDlg, IDC_NOSOUND)));
- db_set_dw(NULL, MODNAME, "NoBlink", MakeCheckBoxTreeFlags(GetDlgItem(hwndDlg, IDC_NOBLINK)));
- db_set_dw(NULL, MODNAME, "NoCLCBlink", MakeCheckBoxTreeFlags(GetDlgItem(hwndDlg, IDC_NOCLCBLINK)));
-
- test = db_get_w(NULL, "CList", "Status", 0);
- SetNotify(Proto_Status2Flag(db_get_w(NULL, "CList", "Status", 0)));
- return TRUE;
- }
- break;
- }
- }
- return FALSE;
-}
-
-static int OptionsInitialize(WPARAM wParam, LPARAM)
-{
- OPTIONSDIALOGPAGE odp = { 0 };
- odp.position = 100000000;
- odp.hInstance = hInst;
- odp.flags = ODPF_UNICODE;
- odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_NOSOUND);
- odp.szTitle.w = LPGENW("Zero Notifications");
- odp.szGroup.w = LPGENW("Plugins");
- odp.pfnDlgProc = DlgProcNoSoundOpts;
- Options_AddPage(wParam, &odp);
- return 0;
-}
-
static INT_PTR NoSoundMenuCommand(WPARAM, LPARAM)
{
bool useSound = db_get_b(0, "Skin", "UseSound", true);
@@ -234,6 +109,8 @@ extern "C" __declspec(dllexport) int Load(void) return 0;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
extern "C" __declspec(dllexport) int Unload(void)
{
return 0;
diff --git a/plugins/ZeroNotification/src/options.cpp b/plugins/ZeroNotification/src/options.cpp new file mode 100644 index 0000000000..9daa6886f2 --- /dev/null +++ b/plugins/ZeroNotification/src/options.cpp @@ -0,0 +1,143 @@ +/* +Copyright (C) 2012-18 Miranda NG team (https://miranda-ng.org) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation version 2 +of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "stdafx.h" + +struct CheckBoxValues_t +{ + DWORD style; + wchar_t *szDescr; +} +static const statusValues[] = +{ + { PF2_ONLINE, TEXT("Online") }, + { PF2_SHORTAWAY, TEXT("Away") }, + { PF2_LONGAWAY, TEXT("Not available") }, + { PF2_LIGHTDND, TEXT("Occupied") }, + { PF2_HEAVYDND, TEXT("Do not disturb") }, + { PF2_FREECHAT, TEXT("Free for chat") }, + { PF2_INVISIBLE, TEXT("Invisible") }, + { PF2_OUTTOLUNCH, TEXT("Out to lunch") }, + { PF2_ONTHEPHONE, TEXT("On the phone") } +}; + +static void FillCheckBoxTree(HWND hwndTree, const struct CheckBoxValues_t *values, int nValues, DWORD style) +{ + TVINSERTSTRUCT tvis; + tvis.hParent = nullptr; + tvis.hInsertAfter = TVI_LAST; + tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_STATE; + for (int i = 0; i < nValues; i++) { + tvis.item.lParam = values[i].style; + tvis.item.pszText = TranslateW(values[i].szDescr); + tvis.item.stateMask = TVIS_STATEIMAGEMASK; + tvis.item.state = INDEXTOSTATEIMAGEMASK((style & tvis.item.lParam) != 0 ? 2 : 1); + TreeView_InsertItem(hwndTree, &tvis); + } +} + +static DWORD MakeCheckBoxTreeFlags(HWND hwndTree) +{ + DWORD flags = 0; + + TVITEM tvi; + tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_STATE; + tvi.hItem = TreeView_GetRoot(hwndTree); + while (tvi.hItem) { + TreeView_GetItem(hwndTree, &tvi); + if (((tvi.state & TVIS_STATEIMAGEMASK) >> 12 == 2)) + flags |= tvi.lParam; + tvi.hItem = TreeView_GetNextSibling(hwndTree, tvi.hItem); + } + return flags; +} + +static INT_PTR CALLBACK DlgProcNoSoundOpts(HWND hwndDlg, UINT msg, WPARAM, LPARAM lParam) +{ + DWORD test; + switch (msg) { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_NOSOUND), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_NOSOUND), GWL_STYLE) | TVS_NOHSCROLL | TVS_CHECKBOXES); + SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_NOBLINK), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_NOBLINK), GWL_STYLE) | TVS_NOHSCROLL | TVS_CHECKBOXES); + SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_NOCLCBLINK), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_NOCLCBLINK), GWL_STYLE) | TVS_NOHSCROLL | TVS_CHECKBOXES); + CheckDlgButton(hwndDlg, IDC_HIDEMENU, db_get_b(NULL, MODNAME, "HideMenu", 1) ? BST_CHECKED : BST_UNCHECKED); + + FillCheckBoxTree(GetDlgItem(hwndDlg, IDC_NOSOUND), statusValues, sizeof(statusValues) / sizeof(statusValues[0]), db_get_dw(NULL, MODNAME, "NoSound", DEFAULT_NOSOUND)); + FillCheckBoxTree(GetDlgItem(hwndDlg, IDC_NOBLINK), statusValues, sizeof(statusValues) / sizeof(statusValues[0]), db_get_dw(NULL, MODNAME, "NoBlink", DEFAULT_NOBLINK)); + FillCheckBoxTree(GetDlgItem(hwndDlg, IDC_NOCLCBLINK), statusValues, sizeof(statusValues) / sizeof(statusValues[0]), db_get_dw(NULL, MODNAME, "NoCLCBlink", DEFAULT_NOCLCBLINK)); + return TRUE; + + case WM_COMMAND: + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + + case WM_NOTIFY: + switch (((LPNMHDR)lParam)->idFrom) { + case IDC_NOSOUND: + case IDC_NOBLINK: + case IDC_NOCLCBLINK: + if (((LPNMHDR)lParam)->code == NM_CLICK) { + TVHITTESTINFO hti; + hti.pt.x = (short)LOWORD(GetMessagePos()); + hti.pt.y = (short)HIWORD(GetMessagePos()); + ScreenToClient(((LPNMHDR)lParam)->hwndFrom, &hti.pt); + if (TreeView_HitTest(((LPNMHDR)lParam)->hwndFrom, &hti)) { + if (hti.flags & TVHT_ONITEMSTATEICON) { + TVITEM tvi; + tvi.mask = TVIF_HANDLE | TVIF_IMAGE | TVIF_SELECTEDIMAGE; + tvi.hItem = hti.hItem; + TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom, &tvi); + tvi.iImage = tvi.iSelectedImage = tvi.iImage == 1 ? 2 : 1; + TreeView_SetItem(((LPNMHDR)lParam)->hwndFrom, &tvi); + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + } + } + } + break; + case 0: + switch (((LPNMHDR)lParam)->code) { + case PSN_APPLY: + db_set_b(NULL, MODNAME, "HideMenu", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_HIDEMENU)); + + db_set_dw(NULL, MODNAME, "NoSound", MakeCheckBoxTreeFlags(GetDlgItem(hwndDlg, IDC_NOSOUND))); + db_set_dw(NULL, MODNAME, "NoBlink", MakeCheckBoxTreeFlags(GetDlgItem(hwndDlg, IDC_NOBLINK))); + db_set_dw(NULL, MODNAME, "NoCLCBlink", MakeCheckBoxTreeFlags(GetDlgItem(hwndDlg, IDC_NOCLCBLINK))); + + test = db_get_w(NULL, "CList", "Status", 0); + SetNotify(Proto_Status2Flag(db_get_w(NULL, "CList", "Status", 0))); + return TRUE; + } + break; + } + } + return FALSE; +} + +int OptionsInitialize(WPARAM wParam, LPARAM) +{ + OPTIONSDIALOGPAGE odp = { 0 }; + odp.position = 100000000; + odp.hInstance = g_plugin.getInst(); + odp.flags = ODPF_UNICODE; + odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_NOSOUND); + odp.szTitle.w = LPGENW("Zero Notifications"); + odp.szGroup.w = LPGENW("Plugins"); + odp.pfnDlgProc = DlgProcNoSoundOpts; + Options_AddPage(wParam, &odp); + return 0; +} diff --git a/plugins/ZeroNotification/src/stdafx.h b/plugins/ZeroNotification/src/stdafx.h index fa2de8828f..c9b6406e2b 100644 --- a/plugins/ZeroNotification/src/stdafx.h +++ b/plugins/ZeroNotification/src/stdafx.h @@ -3,7 +3,6 @@ #include <windows.h>
#include <commctrl.h>
-#define __NO_CMPLUGIN_NEEDED
#include <newpluginapi.h>
#include <m_options.h>
#include <m_database.h>
@@ -14,7 +13,14 @@ #include "version.h"
#include "resource.h"
-#define MODNAME "ZeroNotify"
+#define MODNAME "ZeroNotify"
+
+struct CMPlugin : public PLUGIN<CMPlugin>
+{
+ CMPlugin() :
+ PLUGIN<CMPlugin>(MODNAME)
+ {}
+};
#define DEFAULT_NOSOUND 0x00000000
#define DEFAULT_NOBLINK 0x00000000
@@ -23,3 +29,4 @@ #define DISABLE_SOUND LPGENW("Disable &Sounds")
#define ENABLE_SOUND LPGENW("Enable &Sounds")
+int SetNotify(const long status);
|