summaryrefslogtreecommitdiff
path: root/plugins/NewXstatusNotify/src/utils.cpp
blob: 7e1f988ab1a84169ce4301d48c3a5a999f772aa4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
	NewXstatusNotify YM - Plugin for Miranda IM
	Copyright (c) 2001-2004 Luca Santarelli
	Copyright (c) 2005-2007 Vasilich
	Copyright (c) 2007-2011 yaho

	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; either version 2 of the License, or
	(at your option) any later version.

	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, write to the Free Software
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include "common.h"

TCHAR *db2t(DBVARIANT *dbv)
{
	TCHAR *buff;
	switch (dbv->type) {
		case DBVT_ASCIIZ: buff = mir_a2t(dbv->pszVal); break;
		case DBVT_WCHAR: buff = mir_tstrdup(dbv->ptszVal); break;
		case DBVT_UTF8: buff = mir_utf8decodeT(dbv->pszVal); break;
		default: return NULL;
	}

	if (buff[0] == 0) {
		mir_free(buff);
		buff = NULL;
	}
		
	return buff;
}

int DBGetStringDefault(HCONTACT hContact, const char *szModule, const char *szSetting, TCHAR *setting, int size, const TCHAR *defaultValue)
{
	DBVARIANT dbv;
	if ( !db_get_ts(hContact, szModule, szSetting, &dbv)) {
		_tcsncpy(setting, dbv.ptszVal, size);
		db_free(&dbv);
		return 0;
	} 

	_tcsncpy(setting, defaultValue, size);
	return 1;
}

void HigherLower(int maxValue, int minValue) 
{
	TCHAR str[64] = { 0 };
	mir_sntprintf(str, SIZEOF(str), TranslateT("You cannot specify a value lower than %d and higher than %d."), minValue, maxValue);
}

void ShowLog(TCHAR *file)
{
	int res = (int)ShellExecute(NULL, _T("open"), file, NULL, NULL, SW_SHOW);
	if (res <= 32) // error
		MessageBox(0, TranslateT("Can't open the log file!"), TranslateT("NewXstatusNotify"), MB_OK | MB_ICONERROR);
}

BOOL StatusHasAwayMessage(char *szProto, int status) 
{
	if (szProto != NULL) {
		unsigned long iSupportsSM = (unsigned long)CallProtoService(szProto, PS_GETCAPS, (WPARAM)PFLAGNUM_3, 0);
		return (iSupportsSM & Proto_Status2Flag(status)) ? TRUE : FALSE;
	}

	switch (status) {
	case ID_STATUS_AWAY:
	case ID_STATUS_NA:
	case ID_STATUS_OCCUPIED:
	case ID_STATUS_DND:
	case ID_STATUS_FREECHAT:
	case ID_STATUS_ONTHEPHONE:
	case ID_STATUS_OUTTOLUNCH:
		return TRUE;

	default:
		return FALSE;
	}
}

void LogToFile(TCHAR *stzText)
{	
	FILE *fp = _tfopen(opt.LogFilePath, _T("a+b, ccs=UTF-8"));
	if (fp) { 
		char *encodedText = mir_utf8encodeT(stzText);
		if (encodedText) {
			fprintf(fp, encodedText);
			mir_free(encodedText);
		}
		fclose(fp);
	}
}