summaryrefslogtreecommitdiff
path: root/plugins/StopSpamPlus/src/opt_proto.cpp
diff options
context:
space:
mode:
authorVadim Dashevskiy <watcherhd@gmail.com>2012-05-15 10:38:20 +0000
committerVadim Dashevskiy <watcherhd@gmail.com>2012-05-15 10:38:20 +0000
commit48540940b6c28bb4378abfeb500ec45a625b37b6 (patch)
tree2ef294c0763e802f91d868bdef4229b6868527de /plugins/StopSpamPlus/src/opt_proto.cpp
parent5c350913f011e119127baeb32a6aedeb4f0d33bc (diff)
initial commit
git-svn-id: http://svn.miranda-ng.org/main/trunk@2 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/StopSpamPlus/src/opt_proto.cpp')
-rw-r--r--plugins/StopSpamPlus/src/opt_proto.cpp137
1 files changed, 137 insertions, 0 deletions
diff --git a/plugins/StopSpamPlus/src/opt_proto.cpp b/plugins/StopSpamPlus/src/opt_proto.cpp
new file mode 100644
index 0000000000..201fba693d
--- /dev/null
+++ b/plugins/StopSpamPlus/src/opt_proto.cpp
@@ -0,0 +1,137 @@
+#include "../headers.h"
+
+struct ProtocolData
+{
+ char *RealName;
+ int show,enabled;
+};
+
+int IsProtoIM(const PROTOACCOUNT* pa)
+{
+ return (CallProtoService(pa->szModuleName, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IM);
+}
+
+int FillTree(HWND hwnd)
+{
+ ProtocolData *PD;
+ int i,n;
+ PROTOACCOUNT** pa;
+
+ TVINSERTSTRUCT tvis;
+ tvis.hParent = NULL;
+ tvis.hInsertAfter = TVI_LAST;
+ tvis.item.mask = TVIF_PARAM|TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
+
+ TreeView_DeleteAllItems(hwnd);
+
+ if(CallService(MS_PROTO_ENUMACCOUNTS, (LPARAM)&n, (WPARAM)&pa))
+ return FALSE;
+
+ for ( i = 0; i < n; i++ ) {
+ if(IsAccountEnabled( pa[i] )){
+ PD = ( ProtocolData* )mir_alloc( sizeof( ProtocolData ));
+ PD->RealName = pa[i]->szModuleName;
+ PD->enabled = IsProtoIM( pa[i]);
+ PD->show = PD->enabled ? (plSets->ProtoDisabled(PD->RealName)?1:0) : 100;
+
+ tvis.item.lParam = ( LPARAM )PD;
+ tvis.item.pszText = pa[i]->tszAccountName;
+ tvis.item.iImage = tvis.item.iSelectedImage = PD->show;
+ TreeView_InsertItem( hwnd, &tvis );
+ }
+ }
+
+ return 0;
+}
+
+INT_PTR CALLBACK ProtoDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ HWND hwndProto = GetDlgItem(hwnd, IDC_PROTO);
+
+ switch (msg)
+ {
+
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hwnd);
+
+ SetWindowLong(hwndProto, GWL_STYLE, GetWindowLong(hwndProto, GWL_STYLE) | TVS_NOHSCROLL);
+ {
+ HIMAGELIST himlCheckBoxes = ImageList_Create( GetSystemMetrics( SM_CXSMICON ), GetSystemMetrics( SM_CYSMICON ), ILC_COLOR32|ILC_MASK, 2, 2 );
+ HICON Icon;
+ Icon=(HICON)LoadSkinnedIcon(SKINICON_OTHER_NOTICK);
+ ImageList_AddIcon(himlCheckBoxes, Icon);
+ CallService(MS_SKIN2_RELEASEICON, (WPARAM)Icon, 0);
+ Icon=(HICON)LoadSkinnedIcon(SKINICON_OTHER_TICK);
+ ImageList_AddIcon(himlCheckBoxes, Icon);
+ CallService(MS_SKIN2_RELEASEICON, (WPARAM)Icon, 0);
+
+ TreeView_SetImageList(hwndProto, himlCheckBoxes, TVSIL_NORMAL);
+ }
+
+ FillTree(hwndProto);
+ return TRUE;
+
+ case WM_NOTIFY:
+ switch(((LPNMHDR)lParam)->idFrom) {
+ case 0:
+ if (((LPNMHDR)lParam)->code == PSN_APPLY ) {
+
+ std::ostringstream out;
+
+ TVITEM tvi;
+ tvi.hItem = TreeView_GetRoot(hwndProto);
+ tvi.cchTextMax = 32;
+ tvi.mask = TVIF_PARAM | TVIF_HANDLE;
+
+ while ( tvi.hItem != NULL ) {
+ TreeView_GetItem(hwndProto, &tvi);
+
+ if (tvi.lParam!=0) {
+ ProtocolData* ppd = ( ProtocolData* )tvi.lParam;
+ if(ppd->enabled && ppd->show)
+ out << ppd->RealName << " ";
+ }
+
+ tvi.hItem = TreeView_GetNextSibling(hwndProto, tvi.hItem );
+ }
+
+ plSets->DisabledProtoList=out.str();
+ }
+ break;
+
+ case IDC_PROTO:
+ switch (((LPNMHDR)lParam)->code) {
+ case TVN_DELETEITEMA:
+ {
+ NMTREEVIEWA * pnmtv = (NMTREEVIEWA *) lParam;
+ if (pnmtv && pnmtv->itemOld.lParam)
+ mir_free((ProtocolData*)pnmtv->itemOld.lParam);
+ }
+ break;
+
+ case 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_ONITEMICON ) {
+ TVITEMA tvi;
+ tvi.mask = TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
+ tvi.hItem = hti.hItem;
+ TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom,&tvi);
+
+ ProtocolData *pData = ( ProtocolData* )tvi.lParam;
+ if ( pData->enabled ) {
+ tvi.iImage = tvi.iSelectedImage = !tvi.iImage;
+ pData->show = tvi.iImage;
+ TreeView_SetItem(((LPNMHDR)lParam)->hwndFrom,&tvi);
+ SendMessage(GetParent(hwnd), PSM_CHANGED, (WPARAM)hwnd, 0);
+ } } } } }
+ break;
+ }
+ break;
+ }
+ return FALSE;
+}