From ab06f83a076ece3aba4a47a107203829b11974db Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Robert=20P=C3=B6sel?= <robyer@seznam.cz>
Date: Fri, 13 Dec 2013 13:35:19 +0000
Subject: Tipper: new option for items to show only for particular type of
 contacts (all, contacts, chatrooms); version bump

Useful for not showing last seen or status fields for chatrooms.

git-svn-id: http://svn.miranda-ng.org/main/trunk@7174 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
---
 plugins/TipperYM/res/resource.rc      | 17 +++++++++--------
 plugins/TipperYM/src/options.cpp      | 22 +++++++++++++++++++++-
 plugins/TipperYM/src/options.h        | 12 ++++++++++++
 plugins/TipperYM/src/popwin.cpp       |  2 +-
 plugins/TipperYM/src/preset_items.cpp |  1 +
 plugins/TipperYM/src/resource.h       |  1 +
 plugins/TipperYM/src/subst.cpp        | 16 ++++++++++++++++
 plugins/TipperYM/src/subst.h          |  2 ++
 plugins/TipperYM/src/version.h        |  2 +-
 9 files changed, 64 insertions(+), 11 deletions(-)

(limited to 'plugins/TipperYM')

diff --git a/plugins/TipperYM/res/resource.rc b/plugins/TipperYM/res/resource.rc
index 2bf964ce0e..b4f4fd43ea 100644
--- a/plugins/TipperYM/res/resource.rc
+++ b/plugins/TipperYM/res/resource.rc
@@ -109,24 +109,25 @@ BEGIN
     PUSHBUTTON      "Cancel",IDCANCEL,117,172,50,14
 END
 
-IDD_ITEM DIALOGEX 0, 0, 225, 207
+IDD_ITEM DIALOGEX 0, 0, 225, 225
 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
 CAPTION "Item"
 FONT 8, "MS Shell Dlg", 400, 0, 0x1
 BEGIN
     LTEXT           "Label:",IDC_STATIC,14,10,195,8
-    LTEXT           "Value:",IDC_STATIC,14,47,198,8
     EDITTEXT        IDC_ED_LABEL,13,23,198,13,ES_AUTOHSCROLL
+    LTEXT           "Value:",IDC_STATIC,14,47,198,8
     EDITTEXT        IDC_ED_VALUE,13,58,198,45,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN
+    CONTROL         "Variables",IDC_BTN_VARIABLE,"MButtonClass",WS_TABSTOP,194,108,16,14
     CONTROL         "Draw a line above",IDC_CHK_LINEABOVE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,110,173,10
     CONTROL         "Value on a new line",IDC_CHK_VALNEWLINE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,122,198,10
-    DEFPUSHBUTTON   "OK",IDOK,58,185,50,14
-    PUSHBUTTON      "Cancel",IDCANCEL,116,185,50,14
-    COMBOBOX        IDC_CMB_PRESETITEMS,13,161,198,30,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
-    LTEXT           "Preset items:",IDC_STATIC,14,151,198,8
-    CONTROL         "Variables",IDC_BTN_VARIABLE,"MButtonClass",WS_TABSTOP,194,108,16,14
     CONTROL         "Parse Tipper variables first",IDC_CHK_PARSETIPPERFIRST,
                     "Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,134,198,10
+    COMBOBOX        IDC_CMB_TYPE,13,150,198,30,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
+    LTEXT           "Preset items:",IDC_STATIC,14,170,198,8
+    COMBOBOX        IDC_CMB_PRESETITEMS,13,180,198,30,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
+    DEFPUSHBUTTON   "OK",IDOK,58,201,50,14
+    PUSHBUTTON      "Cancel",IDCANCEL,116,201,50,14
 END
 
 IDD_OPT_CONTENT DIALOGEX 0, 0, 300, 230
@@ -273,7 +274,7 @@ BEGIN
         LEFTMARGIN, 7
         RIGHTMARGIN, 218
         TOPMARGIN, 7
-        BOTTOMMARGIN, 200
+        BOTTOMMARGIN, 218
     END
 
     IDD_OPT_CONTENT, DIALOG
diff --git a/plugins/TipperYM/src/options.cpp b/plugins/TipperYM/src/options.cpp
index 6a8ee4e2c9..2d9c01ed4d 100644
--- a/plugins/TipperYM/src/options.cpp
+++ b/plugins/TipperYM/src/options.cpp
@@ -187,6 +187,8 @@ bool LoadDI(DISPLAYITEM *di, int index)
 		db_free(&dbv);
 	}
 
+	mir_snprintf(setting, SIZEOF(setting), "DIType%d", index);
+	di->type = (DisplayItemType)db_get_b(0, MODULE_ITEMS, setting, DIT_ALL);
 	mir_snprintf(setting, SIZEOF(setting), "DILineAbove%d", index);
 	di->bLineAbove = (db_get_b(0, MODULE_ITEMS, setting, 0) == 1);
 	mir_snprintf(setting, SIZEOF(setting), "DIValNewline%d", index);
@@ -219,6 +221,8 @@ void SaveDI(DISPLAYITEM *di, int index)
 		db_set_s(0, MODULE_ITEMS, setting, buff);
 	}
 
+	mir_snprintf(setting, SIZEOF(setting), "DIType%d", index);
+	db_set_b(0, MODULE_ITEMS, setting, (BYTE)di->type);
 	mir_snprintf(setting, SIZEOF(setting), "DILineAbove%d", index);
 	db_set_b(0, MODULE_ITEMS, setting, di->bLineAbove ? 1 : 0);
 	mir_snprintf(setting, SIZEOF(setting), "DIValNewline%d", index);
@@ -580,6 +584,14 @@ INT_PTR CALLBACK DlgProcAddItem(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
 			SetDlgItemText(hwndDlg, IDC_ED_LABEL, di->swzLabel);
 			SetDlgItemText(hwndDlg, IDC_ED_VALUE, di->swzValue);
 
+			for (int i = 0; i < SIZEOF(displayItemTypes); i++)
+			{
+				int index = SendDlgItemMessage(hwndDlg, IDC_CMB_TYPE, CB_ADDSTRING, (WPARAM)-1, (LPARAM)TranslateTS(displayItemTypes[i].title));
+				SendDlgItemMessage(hwndDlg, IDC_CMB_TYPE, CB_SETITEMDATA, index, (LPARAM)displayItemTypes[i].type);
+				if (displayItemTypes[i].type == di->type)
+					SendDlgItemMessage(hwndDlg, IDC_CMB_TYPE, CB_SETCURSEL, index, 0);
+			}
+
 			CheckDlgButton(hwndDlg, IDC_CHK_LINEABOVE, di->bLineAbove ? TRUE : FALSE);
 			CheckDlgButton(hwndDlg, IDC_CHK_VALNEWLINE, di->bValueNewline ? TRUE : FALSE);
 			CheckDlgButton(hwndDlg, IDC_CHK_PARSETIPPERFIRST, di->bParseTipperVarsFirst ? TRUE : FALSE);
@@ -603,11 +615,19 @@ INT_PTR CALLBACK DlgProcAddItem(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
 						GetDlgItemText(hwndDlg, IDC_ED_LABEL, di->swzLabel, LABEL_LEN);
 						GetDlgItemText(hwndDlg, IDC_ED_VALUE, di->swzValue, VALUE_LEN);
 
+						int sel = SendDlgItemMessage(hwndDlg, IDC_CMB_TYPE, CB_GETCURSEL, 0, 0);
+						int type = SendDlgItemMessage(hwndDlg, IDC_CMB_TYPE, CB_GETITEMDATA, sel, 0);
+						for (int i = 0; i < SIZEOF(displayItemTypes); i++)
+						{
+							if (displayItemTypes[i].type == type)
+								di->type = displayItemTypes[i].type;
+						}
+
 						di->bLineAbove = (IsDlgButtonChecked(hwndDlg, IDC_CHK_LINEABOVE) ? true : false);
 						di->bValueNewline = (IsDlgButtonChecked(hwndDlg, IDC_CHK_VALNEWLINE) ? true : false);
 						di->bParseTipperVarsFirst = (IsDlgButtonChecked(hwndDlg, IDC_CHK_PARSETIPPERFIRST) ? true : false);
 
-						int sel = SendDlgItemMessage(hwndDlg, IDC_CMB_PRESETITEMS, CB_GETCURSEL, 0, 0);
+						sel = SendDlgItemMessage(hwndDlg, IDC_CMB_PRESETITEMS, CB_GETCURSEL, 0, 0);
 						if (sel != CB_ERR)
 						{
 							TCHAR buff[256];
diff --git a/plugins/TipperYM/src/options.h b/plugins/TipperYM/src/options.h
index 32c2009b8a..c3c649ded5 100644
--- a/plugins/TipperYM/src/options.h
+++ b/plugins/TipperYM/src/options.h
@@ -41,14 +41,26 @@ typedef struct {
 	TCHAR *swzTooltip;
 } OPTBUTTON;
 
+typedef enum { DIT_ALL = 0, DIT_CONTACTS = 1, DIT_CHATS = 2 } DisplayItemType;
 typedef struct {
 	TCHAR swzLabel[LABEL_LEN];
 	TCHAR swzValue[VALUE_LEN];
+	DisplayItemType type;
 	bool bLineAbove, bValueNewline;
 	bool bIsVisible;
 	bool bParseTipperVarsFirst;
 } DISPLAYITEM;
 
+// display item types
+static struct {
+	DisplayItemType type;
+	TCHAR* title;
+} displayItemTypes[] = {
+	{ DIT_ALL, LPGENT("Show for all contact types") },
+	{ DIT_CONTACTS, LPGENT("Show only for contacts") },
+	{ DIT_CHATS, LPGENT("Show only for chatrooms") }
+};
+
 typedef enum {DVT_DB = 0, DVT_PROTODB = 1} DisplaySubstType;
 typedef struct {
 	TCHAR swzName[LABEL_LEN];
diff --git a/plugins/TipperYM/src/popwin.cpp b/plugins/TipperYM/src/popwin.cpp
index 441db0effa..c2b01d3bf8 100644
--- a/plugins/TipperYM/src/popwin.cpp
+++ b/plugins/TipperYM/src/popwin.cpp
@@ -1054,7 +1054,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa
 				DIListNode *node = opt.diList;
 				TCHAR buff_label[LABEL_LEN], buff[VALUE_LEN];
 				while (node) {
-					if (node->di.bIsVisible) {
+					if (node->di.bIsVisible && CheckContactType(pwd->hContact, node->di)) {
 						if (GetLabelText(pwd->hContact, node->di, buff_label, LABEL_LEN) && GetValueText(pwd->hContact, node->di, buff, VALUE_LEN)) {
 							if (node->di.bLineAbove // we have a line above
 								&& pwd->iRowCount > 0 // and we're not the first row
diff --git a/plugins/TipperYM/src/preset_items.cpp b/plugins/TipperYM/src/preset_items.cpp
index 373911704f..e6e5cce468 100644
--- a/plugins/TipperYM/src/preset_items.cpp
+++ b/plugins/TipperYM/src/preset_items.cpp
@@ -22,6 +22,7 @@ Boston, MA 02111-1307, USA.
 
 PRESETITEM presetItems[] = 
 {
+	"account", LPGENT("Account"), LPGENT("Account:"), _T("%sys:account%"), 0, 0, 0,
 	"birth", LPGENT("Birthday"), LPGENT("Birthday:"), _T("%birthday_date% (%birthday_age%) @ Next: %birthday_next%"), "birthdate", "birthage", "birthnext",
 	"client", LPGENT("Client"), LPGENT("Client:"), _T("%raw:/MirVer%"), 0, 0, 0,
 	"email", LPGENT("Email"), LPGENT("Email:"), _T("%raw:/e-mail%"), 0, 0, 0,
diff --git a/plugins/TipperYM/src/resource.h b/plugins/TipperYM/src/resource.h
index 0e850b25ea..5f14e5a4b2 100644
--- a/plugins/TipperYM/src/resource.h
+++ b/plugins/TipperYM/src/resource.h
@@ -111,6 +111,7 @@
 #define IDC_CHK_USEPROTOSMILEYS         1106
 #define IDC_CHK_ONLYISOLATED            1107
 #define IDC_CMB_PRESETITEMS             1111
+#define IDC_CMB_TYPE                    1112
 #define IDC_CHK_LIMITMSG                1113
 #define IDC_ED_CHARCOUNT                1114
 #define IDC_SPIN_CHARCOUNT              1115
diff --git a/plugins/TipperYM/src/subst.cpp b/plugins/TipperYM/src/subst.cpp
index 36dadd8b6d..6fdf551015 100644
--- a/plugins/TipperYM/src/subst.cpp
+++ b/plugins/TipperYM/src/subst.cpp
@@ -63,6 +63,22 @@ bool DBGetContactSettingAsString(HANDLE hContact, const char *szModuleName, cons
 	return buff[0] ? true : false;
 }
 
+bool CheckContactType(HANDLE hContact, const DISPLAYITEM &di)
+{
+	if (di.type == DIT_ALL)
+		return true;
+
+	char *szProto = GetContactProto(hContact);	
+	if (szProto) {
+		if (db_get_b(hContact, szProto, "ChatRoom", 0) != 0)
+			return di.type == DIT_CHATS;
+		else
+			return di.type == DIT_CONTACTS;
+	}
+
+	return false;
+}
+
 void StripBBCodesInPlace(TCHAR *swzText)
 {
 	if (!db_get_b(0, MODULE, "StripBBCodes", 1))
diff --git a/plugins/TipperYM/src/subst.h b/plugins/TipperYM/src/subst.h
index d8cbf39d45..7df4a13cca 100644
--- a/plugins/TipperYM/src/subst.h
+++ b/plugins/TipperYM/src/subst.h
@@ -24,6 +24,8 @@ Boston, MA 02111-1307, USA.
 bool GetLabelText(HANDLE hContact, const DISPLAYITEM &di, TCHAR *buff, int iBufflen);
 bool GetValueText(HANDLE hContact, const DISPLAYITEM &di, TCHAR *buff, int iBufflen);
 
+bool CheckContactType(HANDLE hContact, const DISPLAYITEM &di);
+
 void StripBBCodesInPlace(TCHAR *text);
 
 // can be used with hContact == 0 to get uid for a given proto
diff --git a/plugins/TipperYM/src/version.h b/plugins/TipperYM/src/version.h
index 1fca504129..3493167c92 100644
--- a/plugins/TipperYM/src/version.h
+++ b/plugins/TipperYM/src/version.h
@@ -1,7 +1,7 @@
 #define __MAJOR_VERSION				2
 #define __MINOR_VERSION				1
 #define __RELEASE_NUM				0
-#define __BUILD_NUM					4
+#define __BUILD_NUM					5
 
 #define __FILEVERSION_STRING		__MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM
 
-- 
cgit v1.2.3