summaryrefslogtreecommitdiff
path: root/plugins/Sessions/Src/Utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Sessions/Src/Utils.cpp')
-rw-r--r--plugins/Sessions/Src/Utils.cpp250
1 files changed, 96 insertions, 154 deletions
diff --git a/plugins/Sessions/Src/Utils.cpp b/plugins/Sessions/Src/Utils.cpp
index d2f5c58c12..480c8d3c0f 100644
--- a/plugins/Sessions/Src/Utils.cpp
+++ b/plugins/Sessions/Src/Utils.cpp
@@ -17,55 +17,43 @@ 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 "sessions.h"
-void AddSessionMark(HANDLE hContact,int mode,char bit)
+void AddSessionMark(HANDLE hContact, int mode, char bit)
{
+ DBVARIANT dbv;
unsigned int i;
char temp_1[1]={'\0'},temp_2[1]={'\0'};
char szDst[256]={'\0'};
char* pszBuffer=NULL;
- if (mode==0)
- {
- DBVARIANT dbv;
- if (!db_get_s(hContact, MODNAME, "LastSessionsMarks", &dbv) && dbv.pszVal)
- {
+ if (mode == 0) {
+ if (!db_get_s(hContact, MODNAME, "LastSessionsMarks", &dbv) && dbv.pszVal) {
temp_1[0]=dbv.pszVal[0];
- for (i=0;i<ses_limit;i++)
- {
+ for (i=0; i < ses_limit; i++) {
temp_2[0]=dbv.pszVal[i+1];
dbv.pszVal[i+1]=temp_1[0];
temp_1[0]=temp_2[0];
}
- for (i=ses_limit;i<10;i++)
+ for (i=ses_limit; i < 10; i++)
dbv.pszVal[i]='0';
dbv.pszVal[0]=bit;
db_set_s(hContact, MODNAME, "LastSessionsMarks", dbv.pszVal);
db_free(&dbv);
}
- else if (bit=='1') db_set_s(hContact, MODNAME, "LastSessionsMarks", "10000000000");
+ else if (bit == '1') db_set_s(hContact, MODNAME, "LastSessionsMarks", "10000000000");
}
-
- if (mode==1)
- {
- DBVARIANT dbv;
- if (!db_get_s(hContact, MODNAME, "UserSessionsMarks", &dbv) && dbv.pszVal)
- {
- if (strlen(dbv.pszVal)<g_ses_count)
- {
+ else if (mode == 1) {
+ if (!db_get_s(hContact, MODNAME, "UserSessionsMarks", &dbv) && dbv.pszVal) {
+ if (strlen(dbv.pszVal)<g_ses_count) {
pszBuffer = (char*)mir_alloc(g_ses_count+1);
ZeroMemory(pszBuffer,g_ses_count+1);
strcpy(pszBuffer,dbv.pszVal);
}
- else
- pszBuffer = mir_strdup(dbv.pszVal);
-
+ else pszBuffer = mir_strdup(dbv.pszVal);
db_free(&dbv);
temp_1[0]=pszBuffer[0];
- for (i=0;i<g_ses_count;i++)
- {
+ for (i=0;i<g_ses_count;i++) {
temp_2[0]=pszBuffer[i+1];
pszBuffer[i+1]=temp_1[0];
temp_1[0]=temp_2[0];
@@ -75,8 +63,10 @@ void AddSessionMark(HANDLE hContact,int mode,char bit)
mir_free(pszBuffer);
}
- else if (bit=='1')db_set_s(hContact, MODNAME, "UserSessionsMarks", "10000000000");
- else db_set_s(hContact, MODNAME, "UserSessionsMarks", "00000000000");
+ else if (bit == '1')
+ db_set_s(hContact, MODNAME, "UserSessionsMarks", "10000000000");
+ else
+ db_set_s(hContact, MODNAME, "UserSessionsMarks", "00000000000");
}
}
@@ -85,28 +75,24 @@ void RemoveSessionMark(HANDLE hContact,int mode,int marknum)
unsigned int i=1;
char temp_1[1]={'\0'},temp_2[1]={'\0'};
char szDst[256]={'\0'};
- if (mode==0)
- {
- DBVARIANT dbv;
- if (!db_get_s(hContact, MODNAME, "LastSessionsMarks", &dbv) && dbv.pszVal)
- {
+ DBVARIANT dbv;
+
+ if (mode == 0) {
+ if (!db_get_s(hContact, MODNAME, "LastSessionsMarks", &dbv) && dbv.pszVal) {
for (i=marknum;i<ses_limit;i++)
- dbv.pszVal[i]=dbv.pszVal[i+1];
+ dbv.pszVal[i] = dbv.pszVal[i+1];
for (i=ses_limit;i<10;i++)
- dbv.pszVal[i]='0';
+ dbv.pszVal[i] = '0';
db_set_s(hContact, MODNAME, "LastSessionsMarks", dbv.pszVal);
db_free(&dbv);
}
}
- if (mode==1)
- {
- DBVARIANT dbv;
- if (!db_get_s(hContact, MODNAME, "UserSessionsMarks", &dbv) && dbv.pszVal)
- {
- for (i=marknum;i<ses_limit;i++)
- dbv.pszVal[i]=dbv.pszVal[i+1];
+ else if (mode == 1) {
+ if (!db_get_s(hContact, MODNAME, "UserSessionsMarks", &dbv) && dbv.pszVal) {
+ for (i=marknum;i < ses_limit; i++)
+ dbv.pszVal[i] = dbv.pszVal[i+1];
db_set_s(hContact, MODNAME, "UserSessionsMarks", dbv.pszVal);
db_free(&dbv);
@@ -116,25 +102,19 @@ void RemoveSessionMark(HANDLE hContact,int mode,int marknum)
void SetSessionMark(HANDLE hContact,int mode,char bit,unsigned int marknum)
{
+ DBVARIANT dbv;
char* pszBuffer=NULL;
- if (mode==0)
- {
- DBVARIANT dbv;
- if (!db_get_s(hContact, MODNAME, "LastSessionsMarks", &dbv) && dbv.pszVal)
- {
+ if (mode == 0) {
+ if (!db_get_s(hContact, MODNAME, "LastSessionsMarks", &dbv)) {
dbv.pszVal[marknum]=bit;
db_set_s(hContact, MODNAME, "LastSessionsMarks", dbv.pszVal);
db_free(&dbv);
}
}
-
- if (mode==1)
- {
- DBVARIANT dbv;
- if (!db_get_s(hContact, MODNAME, "UserSessionsMarks", &dbv) && dbv.pszVal)
- {
+ else if (mode == 1) {
+ if (!db_get_s(hContact, MODNAME, "UserSessionsMarks", &dbv)) {
pszBuffer = mir_strdup(dbv.pszVal);
pszBuffer[marknum]=bit;
db_set_s(hContact, MODNAME, "UserSessionsMarks", pszBuffer);
@@ -146,26 +126,20 @@ void SetSessionMark(HANDLE hContact,int mode,char bit,unsigned int marknum)
BOOL LoadContactsFromMask(HANDLE hContact,int mode,int count)
{
+ DBVARIANT dbv;
if (mode == 0) {
- DBVARIANT dbv;
- if ( db_get_s(hContact, MODNAME, "LastSessionsMarks", &dbv))
+ if (db_get_s(hContact, MODNAME, "LastSessionsMarks", &dbv))
return 0;
-
- BOOL res = dbv.pszVal[count] == '1';
- db_free(&dbv);
- return res;
}
-
- if (mode == 1) {
- DBVARIANT dbv;
- if ( db_get_s(hContact, MODNAME, "UserSessionsMarks", &dbv))
+ else if (mode == 1) {
+ if (db_get_s(hContact, MODNAME, "UserSessionsMarks", &dbv))
return 0;
-
- BOOL res = dbv.pszVal[count] == '1';
- db_free(&dbv);
- return res;
}
- return 0;
+ else return 0;
+
+ BOOL res = dbv.pszVal[count] == '1';
+ db_free(&dbv);
+ return res;
}
void AddInSessionOrder(HANDLE hContact,int mode,int ordernum,int writemode)
@@ -181,29 +155,25 @@ void AddInSessionOrder(HANDLE hContact,int mode,int ordernum,int writemode)
else
mir_snprintf(szFormNumBuf, SIZEOF(szFormNumBuf), "%u", ordernum);
- if (mode==0)
- {
+ if (mode == 0) {
DBVARIANT dbv;
- if (!db_get_s(hContact, MODNAME, "LastSessionsOrder", &dbv))
- {
+ if (!db_get_s(hContact, MODNAME, "LastSessionsOrder", &dbv)) {
char* temp=NULL;
char* temp2=NULL;
int len= (int)strlen(dbv.pszVal);
if (!len)
- len=20;
+ len = 20;
temp2 = (char*)mir_alloc(len-1);
ZeroMemory(temp2,len-1);
temp = (char*)mir_alloc(len+1);
ZeroMemory(temp,len+1);
- if (ordernum<10)
- {
+ if (ordernum < 10) {
strncpy( temp2, dbv.pszVal, len-2 );
temp2[len-2]='\0';
mir_snprintf(temp, len+1, "%u%u%s", 0, ordernum, temp2);
}
- else
- mir_snprintf(temp, len+1, "%u%s", ordernum, temp2);
+ else mir_snprintf(temp, len+1, "%u%s", ordernum, temp2);
for (i=(ses_limit*2);i<20;i++)
temp[i]='0';
@@ -213,8 +183,7 @@ void AddInSessionOrder(HANDLE hContact,int mode,int ordernum,int writemode)
mir_free(temp2);
db_free(&dbv);
}
- else if (writemode==1)
- {
+ else if (writemode == 1) {
ZeroMemory(szFormNumBuf,SIZEOF(szFormNumBuf));
if (ordernum<10)
mir_snprintf(szFormNumBuf, SIZEOF(szFormNumBuf), "%u%u%s", 0, ordernum, "000000000000000000");
@@ -224,26 +193,20 @@ void AddInSessionOrder(HANDLE hContact,int mode,int ordernum,int writemode)
db_set_s(hContact, MODNAME, "LastSessionsOrder", szFormNumBuf);
}
}
-
- if (mode==1)
- {
+ else if (mode == 1) {
DBVARIANT dbv;
int advlen=0;
- if (!db_get_s(hContact, MODNAME, "UserSessionsOrder", &dbv) && dbv.pszVal)
- {
+ if (!db_get_s(hContact, MODNAME, "UserSessionsOrder", &dbv) && dbv.pszVal) {
char* temp=NULL;
char* temp2=NULL;
int len=0;
- if (strlen(dbv.pszVal)<(g_ses_count*2))
- {
+ if (strlen(dbv.pszVal)<(g_ses_count*2)) {
pszBuffer = (char*)mir_alloc(g_ses_count*2+1);
ZeroMemory(pszBuffer,g_ses_count*2+1);
strcpy(pszBuffer,dbv.pszVal);
}
- else
- {
- pszBuffer = mir_strdup(dbv.pszVal);
- }
+ else pszBuffer = mir_strdup(dbv.pszVal);
+
if (!(advlen=len= (int)strlen(pszBuffer)))
advlen=len=20;
else
@@ -263,7 +226,7 @@ void AddInSessionOrder(HANDLE hContact,int mode,int ordernum,int writemode)
mir_free(temp);
mir_free(pszBuffer);
}
- else if (writemode==1)
+ else if (writemode == 1)
db_set_s(hContact, MODNAME, "UserSessionsOrder", szFormNumBuf);
else
db_set_s(hContact, MODNAME, "UserSessionsOrder", "00");
@@ -272,27 +235,23 @@ void AddInSessionOrder(HANDLE hContact,int mode,int ordernum,int writemode)
int GetInSessionOrder(HANDLE hContact,int mode,int count)
{
- int iOrder=0;
+ int iOrder = 0;
char szTemp[3]={'\0'};
- if (mode==0)
- {
+ if (mode == 0) {
DBVARIANT dbv;
- if (!db_get_s(hContact, MODNAME, "LastSessionsOrder", &dbv) && dbv.pszVal)
- {
- szTemp[0]=dbv.pszVal[count*2];
- szTemp[1]=dbv.pszVal[count*2+1];
- iOrder=atoi(szTemp);
+ if (!db_get_s(hContact, MODNAME, "LastSessionsOrder", &dbv) && dbv.pszVal) {
+ szTemp[0] = dbv.pszVal[count*2];
+ szTemp[1] = dbv.pszVal[count*2+1];
+ iOrder = atoi(szTemp);
db_free(&dbv);
}
}
- if (mode==1)
- {
+ else if (mode == 1) {
DBVARIANT dbv;
- if (!db_get_s(hContact, MODNAME, "UserSessionsOrder", &dbv) && dbv.pszVal)
- {
- szTemp[0]=dbv.pszVal[count*2];
- szTemp[1]=dbv.pszVal[count*2+1];
- iOrder=atoi(szTemp);
+ if (!db_get_s(hContact, MODNAME, "UserSessionsOrder", &dbv) && dbv.pszVal) {
+ szTemp[0] = dbv.pszVal[count*2];
+ szTemp[1] = dbv.pszVal[count*2+1];
+ iOrder = atoi(szTemp);
db_free(&dbv);
}
}
@@ -304,28 +263,23 @@ void SetInSessionOrder(HANDLE hContact,int mode,int count,unsigned int ordernum)
int iOrder=0;
char szTemp[3]={'\0'};
- if (ordernum<10)
+ if (ordernum < 10)
mir_snprintf(szTemp, SIZEOF(szTemp), "%u%u", 0, ordernum);
else
mir_snprintf(szTemp, SIZEOF(szTemp), "%u", ordernum);
- if (mode==0)
- {
+ if (mode == 0) {
DBVARIANT dbv;
- if (!db_get_s(hContact, MODNAME, "LastSessionsOrder", &dbv) && dbv.pszVal)
- {
+ if (!db_get_s(hContact, MODNAME, "LastSessionsOrder", &dbv) && dbv.pszVal) {
dbv.pszVal[count*2]=szTemp[0];
dbv.pszVal[count*2+1]=szTemp[1];
db_set_s(hContact, MODNAME, "LastSessionsOrder", dbv.pszVal);
db_free(&dbv);
}
}
-
- if (mode==1)
- {
+ else if (mode == 1) {
DBVARIANT dbv;
- if (!db_get_s(hContact, MODNAME, "UserSessionsOrder", &dbv) && dbv.pszVal)
- {
+ if (!db_get_s(hContact, MODNAME, "UserSessionsOrder", &dbv) && dbv.pszVal) {
dbv.pszVal[count*2]=szTemp[0];
dbv.pszVal[count*2+1]=szTemp[1];
db_set_s(hContact, MODNAME, "UserSessionsOrder", dbv.pszVal);
@@ -339,8 +293,7 @@ BOOL ResaveSettings(char* szName,int iFirst,int iLimit,TCHAR* szBuffer)
BYTE marked,marked_t;
char szNameBuf[256]={0};
- for (int i = iFirst; i < iLimit; i++)
- {
+ for (int i = iFirst; i < iLimit; i++) {
if (szBuffer == NULL)
break;
@@ -352,7 +305,7 @@ BOOL ResaveSettings(char* szName,int iFirst,int iLimit,TCHAR* szBuffer)
mir_free(szBuffer);
marked = IsMarkedUserDefSession(i);
- MarkUserDefSession(i,(BYTE)((i==iFirst)?IsMarkedUserDefSession(iFirst-1):marked_t));
+ MarkUserDefSession(i,(BYTE)((i == iFirst)?IsMarkedUserDefSession(iFirst-1):marked_t));
marked_t = marked;
if (res) // read failed
@@ -366,16 +319,12 @@ BOOL ResaveSettings(char* szName,int iFirst,int iLimit,TCHAR* szBuffer)
return 1;
}
-int AddToCurSession (DWORD wparam,LPARAM lparam)
+int AddToCurSession (HANDLE wparam,LPARAM lparam)
{
- int i;
- if (CheckForDuplicate(session_list,wparam)==-1)
- {
- for (i=0;;i++)
- {
- if (session_list[i]==0)
- {
- session_list[i]=wparam;
+ if (CheckForDuplicate(session_list,wparam) == -1) {
+ for (int i=0;;i++) {
+ if (session_list[i] == 0) {
+ session_list[i] = wparam;
break;
}
}
@@ -383,64 +332,58 @@ int AddToCurSession (DWORD wparam,LPARAM lparam)
return 0;
}
-int DelFromCurSession(DWORD wparam,LPARAM lparam)
+int DelFromCurSession(HANDLE wparam,LPARAM lparam)
{
- int i=0;
- while(session_list[i]!=0)
- {
- if (session_list[i]==wparam)
- {
- while(session_list[i+1]!=0)
- {
+ for (int i=0; session_list[i] != 0; i++) {
+ if (session_list[i] == wparam) {
+ while(session_list[i+1]!=0) {
session_list[i]=session_list[i+1];
i++;
}
- session_list[i]=0;
+ session_list[i] = 0;
}
- i++;
}
return 0;
}
-int CheckForDuplicate(DWORD contact_list[],DWORD lparam)
+int CheckForDuplicate(HANDLE contact_list[], HANDLE lparam)
{
int i=0;
- DWORD s_list[255]={'0'};
+ HANDLE s_list[255] = {0};
memcpy(s_list, contact_list,SIZEOF(s_list));
- for (i=0;;i++)
- {
- if (s_list[i]==lparam)
+ for (i=0;;i++) {
+ if (s_list[i] == lparam)
return i;
- if (s_list[i]==0)
+ if (s_list[i] == 0)
return -1;
}
return 0;
}
-int LoadSessionToCombobox (HWND hdlg,BOOL mode,int iLimit,char* pszSetting,int iFirstNum)
+int LoadSessionToCombobox(HWND hdlg,BOOL mode,int iLimit,char* pszSetting,int iFirstNum)
{
- int ses_count=iFirstNum, index;
+ int ses_count = iFirstNum, index;
char szBuffer[256]={0};
if (session_list_recovered[0] && !iFirstNum && !mode) {
index = SendDlgItemMessage(hdlg, IDC_LIST, CB_ADDSTRING, 0, (LPARAM)TranslateT("Session Before Last Crash"));
- SendDlgItemMessage(hdlg, IDC_LIST, CB_SETITEMDATA, (WPARAM)index, (LPARAM) 256);
+ SendDlgItemMessage(hdlg, IDC_LIST, CB_SETITEMDATA, index, 256);
}
for(int i=0; i < iLimit; i++) {
mir_snprintf(szBuffer, SIZEOF(szBuffer), "%s_%u", pszSetting, i);
TCHAR *pszBuffer = db_get_tsa(NULL, MODNAME, szBuffer);
if (pszBuffer) {
- if (!IsMarkedUserDefSession(i+iFirstNum)||mode==1) {
+ if (!IsMarkedUserDefSession(i+iFirstNum)||mode == 1) {
index = SendDlgItemMessage(hdlg, IDC_LIST, CB_ADDSTRING, 0, (LPARAM)pszBuffer);
- SendDlgItemMessage(hdlg, IDC_LIST, CB_SETITEMDATA, (WPARAM)index, (LPARAM) (DWORD)i+iFirstNum);
+ SendDlgItemMessage(hdlg, IDC_LIST, CB_SETITEMDATA, (WPARAM)index, i+iFirstNum);
}
else {
SendDlgItemMessage(hdlg, IDC_LIST, CB_INSERTSTRING, 0, (LPARAM)pszBuffer);
- SendDlgItemMessage(hdlg, IDC_LIST, CB_SETITEMDATA, 0, (LPARAM) (DWORD)i+iFirstNum);
+ SendDlgItemMessage(hdlg, IDC_LIST, CB_SETITEMDATA, 0, i+iFirstNum);
}
mir_free(pszBuffer);
}
else {
- if (i==0) ses_count=iLimit-iFirstNum;
+ if (i == 0) ses_count=iLimit-iFirstNum;
break;
}
}
@@ -514,8 +457,8 @@ BYTE IsMarkedUserDefSession(int ses_count)
void SavePosition(HWND hwnd, char *wndName)
{
RECT rc;
- char buffer[512];
GetWindowRect(hwnd, &rc);
+ char buffer[512];
mir_snprintf(buffer, SIZEOF(buffer), "%sPosX", wndName);
db_set_dw(0, MODNAME, buffer, rc.left);
mir_snprintf(buffer, SIZEOF(buffer), "%sPosY", wndName);
@@ -525,10 +468,9 @@ void SavePosition(HWND hwnd, char *wndName)
void LoadPosition(HWND hWnd, char *wndName)
{
char buffer[512];
- int x,y ;
mir_snprintf(buffer, SIZEOF(buffer), "%sPosX", wndName);
- x = db_get_dw(0, MODNAME, buffer, ((GetSystemMetrics(SM_CXSCREEN)) / 2)-130);
+ int x = db_get_dw(0, MODNAME, buffer, ((GetSystemMetrics(SM_CXSCREEN)) / 2)-130);
mir_snprintf(buffer, SIZEOF(buffer), "%sPosY", wndName);
- y = db_get_dw(0, MODNAME, buffer, ((GetSystemMetrics(SM_CYSCREEN))/ 2)-80);
+ int y = db_get_dw(0, MODNAME, buffer, ((GetSystemMetrics(SM_CYSCREEN))/ 2)-80);
SetWindowPos(hWnd, NULL, x, y, 0, 0, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOSIZE);
-} \ No newline at end of file
+}