diff options
author | George Hazan <george.hazan@gmail.com> | 2014-11-03 16:10:07 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-11-03 16:10:07 +0000 |
commit | 415dcffc401ffdca1c0ccf94975c733b15d2e3c3 (patch) | |
tree | dca6756011ae055f2026393c6098052faef6ca48 /plugins/Sessions/Src | |
parent | 686b657701e50c3682045fdf4af9283e14087e04 (diff) |
massive code cleaning for Sessions
git-svn-id: http://svn.miranda-ng.org/main/trunk@10911 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Sessions/Src')
-rw-r--r-- | plugins/Sessions/Src/Main.cpp | 835 | ||||
-rw-r--r-- | plugins/Sessions/Src/Options.cpp | 4 | ||||
-rw-r--r-- | plugins/Sessions/Src/Sessions.h | 8 | ||||
-rw-r--r-- | plugins/Sessions/Src/Utils.cpp | 395 | ||||
-rw-r--r-- | plugins/Sessions/Src/Utils.h | 2 | ||||
-rw-r--r-- | plugins/Sessions/Src/Version.h | 20 |
6 files changed, 563 insertions, 701 deletions
diff --git a/plugins/Sessions/Src/Main.cpp b/plugins/Sessions/Src/Main.cpp index 85cf801d6a..32d0608052 100644 --- a/plugins/Sessions/Src/Main.cpp +++ b/plugins/Sessions/Src/Main.cpp @@ -31,8 +31,8 @@ BOOL g_hghostw; HWND hClistControl;
-unsigned int ses_limit;
-unsigned int g_ses_count;
+int g_ses_limit;
+int g_ses_count;
BOOL g_bExclHidden;
BOOL g_bWarnOnHidden;
BOOL g_bOtherWarnings;
@@ -49,7 +49,6 @@ MCONTACT user_session_list[255] = { 0 }; MCONTACT session_list_recovered[255];
int count = 0;
-unsigned int ses_count = 0;
int hLangpack;
@@ -79,35 +78,30 @@ IconItem iconList[] = { LPGEN("Load last Session"), "SessionsLoadLast", IDD_SESSIONS_LOADLAST }
};
-INT_PTR CALLBACK ExitDlgProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam)
+INT_PTR CALLBACK ExitDlgProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
{
- switch(msg)
- {
- case WM_INITDIALOG:
- {
- TranslateDialogDefault(hdlg);
- LoadPosition(hdlg, "ExitDlg");
- ShowWindow(hdlg,SW_SHOW);
- }break;
+ switch (msg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hdlg);
+ LoadPosition(hdlg, "ExitDlg");
+ ShowWindow(hdlg, SW_SHOW);
+ break;
case WM_COMMAND:
- switch(LOWORD(wparam))
- {
- case IDOK:
- {
- SavePosition(hdlg, "ExitDlg");
- SaveSessionDate();
- SaveSessionHandles(0,0);
- db_set_b(NULL, MODNAME, "lastempty", 0);
- DestroyWindow(hdlg);
- }break;
+ switch (LOWORD(wparam)) {
+ case IDOK:
+ SavePosition(hdlg, "ExitDlg");
+ SaveSessionDate();
+ SaveSessionHandles(0, 0);
+ db_set_b(NULL, MODNAME, "lastempty", 0);
+ DestroyWindow(hdlg);
+ break;
- case IDCANCEL:
- {
- SavePosition(hdlg, "ExitDlg");
- db_set_b(NULL, MODNAME, "lastempty", 1);
- DestroyWindow(hdlg);
- }break;
+ case IDCANCEL:
+ SavePosition(hdlg, "ExitDlg");
+ db_set_b(NULL, MODNAME, "lastempty", 1);
+ DestroyWindow(hdlg);
+ break;
}
case WM_CLOSE:
@@ -127,321 +121,292 @@ INT_PTR CALLBACK ExitDlgProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam) INT_PTR CALLBACK SaveSessionDlgProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam)
{
g_hSDlg = hdlg;
- switch(msg)
- {
- case WM_INITDIALOG:
+ switch (msg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hdlg);
{
- HWND hList;
- hList = GetDlgItem(hdlg, IDC_LIST);
- TranslateDialogDefault(hdlg);
+ HWND hList = GetDlgItem(hdlg, IDC_LIST);
LoadSessionToCombobox(hdlg, 1, 5, "UserSessionDsc", 0);
LoadPosition(hdlg, "SaveDlg");
ShowWindow(hdlg, SW_SHOW);
- }break;
-
- case WM_CLOSE:
- DestroyWindow(hdlg);
- g_hSDlg = 0;
- break;
+ }
+ break;
- case WM_NOTIFY:
- {
- switch (((LPNMHDR) lparam)->idFrom)
- {
- case IDC_CLIST:
- switch (((LPNMHDR)lparam)->code)
- {
- case CLN_CHECKCHANGED:
- {
- bSC = TRUE;
- memcpy(user_session_list, session_list, SIZEOF(user_session_list));
- }break;
+ case WM_CLOSE:
+ DestroyWindow(hdlg);
+ g_hSDlg = 0;
+ break;
- }
- }break;
- }break;
+ case WM_NOTIFY:
+ switch (((LPNMHDR)lparam)->idFrom) {
+ case IDC_CLIST:
+ switch (((LPNMHDR)lparam)->code) {
+ case CLN_CHECKCHANGED:
+ bSC = TRUE;
+ memcpy(user_session_list, session_list, SIZEOF(user_session_list));
+ break;
+ }
+ }
+ break;
- case WM_COMMAND:
- switch(LOWORD(wparam))
+ case WM_COMMAND:
+ switch (LOWORD(wparam)) {
+ case IDC_SELCONTACTS:
+ HANDLE hItem;
+ RECT rWnd;
{
- case IDC_SELCONTACTS:
- {
- HANDLE hItem;
- RECT rWnd;
- int i=0, x=0,y=0,dy=0,dx=0,dd=0;
-
- GetWindowRect(hdlg, &rWnd);
- x=rWnd.right-rWnd.left;
- y=rWnd.bottom-rWnd.top;
- if (IsDlgButtonChecked(hdlg,IDC_SELCONTACTS))
- {
- EnableWindow(GetDlgItem(hdlg,IDC_SANDCCHECK),FALSE);
- dy=20;
- dx=150;
- dd=5;
- hClistControl = CreateWindowEx(WS_EX_CLIENTEDGE, _T(CLISTCONTROL_CLASS), _T(""),
- WS_TABSTOP |WS_VISIBLE | WS_CHILD ,
+ int i = 0, x = 0, y = 0, dy = 0, dx = 0, dd = 0;
+
+ GetWindowRect(hdlg, &rWnd);
+ x = rWnd.right - rWnd.left;
+ y = rWnd.bottom - rWnd.top;
+ if (IsDlgButtonChecked(hdlg, IDC_SELCONTACTS)) {
+ EnableWindow(GetDlgItem(hdlg, IDC_SANDCCHECK), FALSE);
+ dy = 20;
+ dx = 150;
+ dd = 5;
+ hClistControl = CreateWindowEx(WS_EX_CLIENTEDGE, _T(CLISTCONTROL_CLASS), _T(""),
+ WS_TABSTOP | WS_VISIBLE | WS_CHILD,
x, y, dx, dy, hdlg, (HMENU)IDC_CLIST, hinstance, 0);
- SetWindowLongPtr(hClistControl, GWL_STYLE,
- GetWindowLongPtr(hClistControl, GWL_STYLE)|CLS_CHECKBOXES|CLS_HIDEEMPTYGROUPS|CLS_USEGROUPS|CLS_GREYALTERNATE|CLS_GROUPCHECKBOXES);
- SendMessage(hClistControl, CLM_SETEXSTYLE, CLS_EX_DISABLEDRAGDROP|CLS_EX_TRACKSELECT, 0);
- }
- else
- {
- EnableWindow(GetDlgItem(hdlg,IDC_SANDCCHECK),TRUE);
- dy=-20;
- dx=-150;
- dd=5;
- DestroyWindow(hClistControl);
- }
+ SetWindowLongPtr(hClistControl, GWL_STYLE,
+ GetWindowLongPtr(hClistControl, GWL_STYLE) | CLS_CHECKBOXES | CLS_HIDEEMPTYGROUPS | CLS_USEGROUPS | CLS_GREYALTERNATE | CLS_GROUPCHECKBOXES);
+ SendMessage(hClistControl, CLM_SETEXSTYLE, CLS_EX_DISABLEDRAGDROP | CLS_EX_TRACKSELECT, 0);
+ }
+ else {
+ EnableWindow(GetDlgItem(hdlg, IDC_SANDCCHECK), TRUE);
+ dy = -20;
+ dx = -150;
+ dd = 5;
+ DestroyWindow(hClistControl);
+ }
- SetWindowPos(hdlg, NULL, rWnd.left,rWnd.top, x+dx, y+(dx/3), SWP_NOZORDER | SWP_NOOWNERZORDER|SWP_NOMOVE);
+ SetWindowPos(hdlg, NULL, rWnd.left, rWnd.top, x + dx, y + (dx / 3), SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE);
- SetWindowPos(hClistControl,0,x-dd,dd,dx-dd,y+(dx/12),SWP_NOZORDER/*|SWP_NOSIZE|SWP_SHOWWINDOW*/);
- SendMessage(hClistControl,WM_TIMER,TIMERID_REBUILDAFTER,0);
+ SetWindowPos(hClistControl, 0, x - dd, dd, dx - dd, y + (dx / 12), SWP_NOZORDER/*|SWP_NOSIZE|SWP_SHOWWINDOW*/);
+ SendMessage(hClistControl, WM_TIMER, TIMERID_REBUILDAFTER, 0);
- for ( i = 0; session_list[i] > 0; i++)
- {
- hItem=(HANDLE)SendMessage(hClistControl,CLM_FINDCONTACT, (WPARAM)session_list[i], 0);
- SendMessage(hClistControl, CLM_SETCHECKMARK, (WPARAM)hItem,1);
- }
+ for (i = 0; session_list[i] > 0; i++) {
+ hItem = (HANDLE)SendMessage(hClistControl, CLM_FINDCONTACT, (WPARAM)session_list[i], 0);
+ SendMessage(hClistControl, CLM_SETCHECKMARK, (WPARAM)hItem, 1);
+ }
- OffsetWindow(hdlg, GetDlgItem(hdlg,IDC_LIST), 0, dy);
- OffsetWindow(hdlg, GetDlgItem(hdlg,IDC_STATIC), 0, dy);
- OffsetWindow(hdlg, GetDlgItem(hdlg,IDC_SANDCCHECK), 0, dy);
- OffsetWindow(hdlg, GetDlgItem(hdlg,IDOK), 0, dy);
- OffsetWindow(hdlg, GetDlgItem(hdlg,IDCANCEL), 0, dy);
-
- }break;
-
- case IDOK:
- {
- DWORD session_list_temp[255]={0};
- int lenght,i = 0;
- TCHAR szUserSessionName[MAX_PATH];
- lenght = GetWindowTextLength(GetDlgItem(hdlg, IDC_LIST));
- SavePosition(hdlg, "SaveDlg");
- if (lenght>0) {
- GetWindowText(GetDlgItem(hdlg, IDC_LIST), szUserSessionName, SIZEOF(szUserSessionName));
- szUserSessionName[lenght+1]='\0';
- if (IsDlgButtonChecked(hdlg,IDC_SELCONTACTS)&&bSC) {
- for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- BYTE res =(BYTE)SendMessage(hClistControl, CLM_GETCHECKMARK, SendMessage(hClistControl, CLM_FINDCONTACT, hContact, 0), 0);
- if (res) {
- user_session_list[i] = hContact;
- i++;
- }
+ OffsetWindow(hdlg, GetDlgItem(hdlg, IDC_LIST), 0, dy);
+ OffsetWindow(hdlg, GetDlgItem(hdlg, IDC_STATIC), 0, dy);
+ OffsetWindow(hdlg, GetDlgItem(hdlg, IDC_SANDCCHECK), 0, dy);
+ OffsetWindow(hdlg, GetDlgItem(hdlg, IDOK), 0, dy);
+ OffsetWindow(hdlg, GetDlgItem(hdlg, IDCANCEL), 0, dy);
+ }
+ break;
+
+ case IDOK:
+ TCHAR szUserSessionName[MAX_PATH];
+ {
+ DWORD session_list_temp[255] = { 0 };
+ int i = 0, length = GetWindowTextLength(GetDlgItem(hdlg, IDC_LIST));
+ SavePosition(hdlg, "SaveDlg");
+ if (length > 0) {
+ GetWindowText(GetDlgItem(hdlg, IDC_LIST), szUserSessionName, SIZEOF(szUserSessionName));
+ szUserSessionName[length + 1] = '\0';
+ if (IsDlgButtonChecked(hdlg, IDC_SELCONTACTS) && bSC) {
+ for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ BYTE res = (BYTE)SendMessage(hClistControl, CLM_GETCHECKMARK, SendMessage(hClistControl, CLM_FINDCONTACT, hContact, 0), 0);
+ if (res) {
+ user_session_list[i] = hContact;
+ i++;
}
- memcpy(session_list_temp,session_list,SIZEOF(session_list_temp));
- memcpy(session_list,user_session_list,SIZEOF(session_list));
- SaveSessionHandles(0,1);
- SaveUserSessionName(szUserSessionName);
- memcpy(session_list,session_list_temp,SIZEOF(session_list));
- DestroyWindow(hdlg);
- g_hSDlg=0;
- }
- else if (!SaveUserSessionName(szUserSessionName))
- {
- SaveSessionHandles(0,1);
-
- if (IsDlgButtonChecked(hdlg,IDC_SANDCCHECK))
- CloseCurrentSession(0,0);
- DestroyWindow(hdlg);
- g_hSDlg=0;
}
- else
- MessageBox(NULL,TranslateT("Current session is empty!"),TranslateT("Sessions Manager"),MB_OK|MB_ICONWARNING);
+ memcpy(session_list_temp, session_list, SIZEOF(session_list_temp));
+ memcpy(session_list, user_session_list, SIZEOF(session_list));
+ SaveSessionHandles(0, 1);
+ SaveUserSessionName(szUserSessionName);
+ memcpy(session_list, session_list_temp, SIZEOF(session_list));
+ DestroyWindow(hdlg);
+ g_hSDlg = 0;
+ }
+ else if (!SaveUserSessionName(szUserSessionName)) {
+ SaveSessionHandles(0, 1);
+
+ if (IsDlgButtonChecked(hdlg, IDC_SANDCCHECK))
+ CloseCurrentSession(0, 0);
+ DestroyWindow(hdlg);
+ g_hSDlg = 0;
}
else
- MessageBox(NULL,TranslateT("Session name is empty, enter the name and try again"),TranslateT("Sessions Manager"),MB_OK|MB_ICONWARNING);
- }break;
-
- case IDCANCEL:
- {
- SavePosition(hdlg, "SaveDlg");
- DestroyWindow(hdlg);
- g_hSDlg=0;
- }break;
+ MessageBox(NULL, TranslateT("Current session is empty!"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING);
+ }
+ else
+ MessageBox(NULL, TranslateT("Session name is empty, enter the name and try again"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING);
}
break;
- default:
- return FALSE;
+ case IDCANCEL:
+ SavePosition(hdlg, "SaveDlg");
+ DestroyWindow(hdlg);
+ g_hSDlg = 0;
+ }
+ break;
+
+ default:
+ return FALSE;
}
return TRUE;
}
-INT_PTR CALLBACK LoadSessionDlgProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam)
+INT_PTR CALLBACK LoadSessionDlgProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
{
- g_hDlg=hdlg;
- switch(msg)
- {
- case WM_INITDIALOG:
+ static int ses_count;
+
+ g_hDlg = hdlg;
+ switch (msg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hdlg);
{
- int iDelay=db_get_w(NULL, MODNAME, "StartupModeDelay", 1500);
+ int iDelay = db_get_w(NULL, MODNAME, "StartupModeDelay", 1500);
if (g_hghostw == TRUE)
SetTimer(hdlg, TIMERID_LOAD, iDelay, NULL);
- else
- {
- ses_count=0;
- TranslateDialogDefault(hdlg);
- if ((ses_count=LoadSessionToCombobox(hdlg,0,ses_limit,"SessionDate",0)) == ses_limit)
- EnableWindow(GetDlgItem(hdlg,IDC_SESSDEL),TRUE);
+ else {
+ if ((ses_count = LoadSessionToCombobox(hdlg, 0, g_ses_limit, "SessionDate", 0)) == g_ses_limit)
+ EnableWindow(GetDlgItem(hdlg, IDC_SESSDEL), TRUE);
- if (LoadSessionToCombobox(hdlg,0,255,"UserSessionDsc",ses_limit) == 0 && ses_count!=0)
- ses_count=0;
+ if (LoadSessionToCombobox(hdlg, 0, 255, "UserSessionDsc", g_ses_limit) == 0 && ses_count != 0)
+ ses_count = 0;
if (session_list_recovered[0])
- ses_count=256;
+ ses_count = 256;
SendDlgItemMessage(hdlg, IDC_LIST, CB_SETCURSEL, 0, 0);
LoadPosition(hdlg, "LoadDlg");
if (StartUp)
SetTimer(hdlg, TIMERID_SHOW, iDelay, NULL);
else
- ShowWindow(g_hDlg,SW_SHOW);
+ ShowWindow(g_hDlg, SW_SHOW);
}
- }break;
+ }
+ break;
- case WM_TIMER:
- if (wparam == TIMERID_SHOW)
- {
- KillTimer(hdlg, TIMERID_SHOW);
- ShowWindow(hdlg,SW_SHOW);
- StartUp=FALSE;
- }
- else
- {
- KillTimer(hdlg, TIMERID_LOAD);
- LoadSession(0,0);
- g_hghostw=StartUp=FALSE;
- DestroyWindow(hdlg);
- g_hDlg=0;
+ case WM_TIMER:
+ if (wparam == TIMERID_SHOW) {
+ KillTimer(hdlg, TIMERID_SHOW);
+ ShowWindow(hdlg, SW_SHOW);
+ StartUp = FALSE;
+ }
+ else {
+ KillTimer(hdlg, TIMERID_LOAD);
+ LoadSession(0, 0);
+ g_hghostw = StartUp = FALSE;
+ DestroyWindow(hdlg);
+ g_hDlg = 0;
+ }
+ break;
+
+ case WM_CLOSE:
+ SavePosition(hdlg, "LoadDlg");
+ DestroyWindow(hdlg);
+ g_hDlg = 0;
+ break;
+
+ case WM_COMMAND:
+ switch (LOWORD(wparam)) {
+ case IDC_LIST:
+ switch (HIWORD(wparam)) {
+ case CBN_SELCHANGE:
+ HWND hCombo = GetDlgItem(hdlg, IDC_LIST);
+ int index = SendMessage(hCombo, CB_GETCURSEL, 0, 0);
+ if (index != CB_ERR)
+ ses_count = SendMessage(hCombo, CB_GETITEMDATA, (WPARAM)index, 0);
}
break;
- case WM_CLOSE:
- SavePosition(hdlg, "LoadDlg");
- DestroyWindow(hdlg);
- g_hDlg=0;
- break;
+ case IDC_SESSDEL:
+ if (session_list_recovered[0] && ses_count == 256) {
+ int i = 0;
+ while (session_list_recovered[i]) {
+ db_set_b(session_list_recovered[i], MODNAME, "wasInLastSession", 0);
+ i++;
+ }
+ ZeroMemory(session_list_recovered, SIZEOF(session_list_recovered));
+ g_bIncompletedSave = 0;
- case WM_COMMAND:
- switch(LOWORD(wparam))
- {
- case IDC_LIST:
- {
- switch(HIWORD(wparam))
- {
- case CBN_SELCHANGE:
- {
- HWND hCombo = GetDlgItem(hdlg, IDC_LIST);
- int index = SendMessage(hCombo, CB_GETCURSEL, 0, 0);
- if (index != CB_ERR)
- ses_count = SendMessage(hCombo, CB_GETITEMDATA, (WPARAM)index, 0);
- }break;
- }break;
- }break;
-
- case IDC_SESSDEL:
- {
- if (session_list_recovered[0]&&ses_count == 256)
- {
- int i=0;
- while(session_list_recovered[i])
- {
- db_set_b(session_list_recovered[i], MODNAME, "wasInLastSession", 0);
- i++;
- }
- ZeroMemory(session_list_recovered,SIZEOF(session_list_recovered));
- g_bIncompletedSave=0;
+ EnableWindow(GetDlgItem(hdlg, IDC_SESSDEL), FALSE);
+ SendDlgItemMessage(hdlg, IDC_LIST, CB_RESETCONTENT, 0, 0);
- EnableWindow(GetDlgItem(hdlg,IDC_SESSDEL),FALSE);
- SendDlgItemMessage(hdlg, IDC_LIST, CB_RESETCONTENT, 0, 0);
+ if ((ses_count = LoadSessionToCombobox(hdlg, 1, g_ses_limit, "SessionDate", 0)) == g_ses_limit)
+ EnableWindow(GetDlgItem(hdlg, IDC_SESSDEL), TRUE);
- if ((ses_count=LoadSessionToCombobox(hdlg,1,ses_limit,"SessionDate",0)) == ses_limit)
- EnableWindow(GetDlgItem(hdlg,IDC_SESSDEL),TRUE);
+ if (LoadSessionToCombobox(hdlg, 1, 255, "UserSessionDsc", g_ses_limit) == 0 && ses_count != 0)
+ ses_count = 0;
- if (LoadSessionToCombobox(hdlg,1,255,"UserSessionDsc",ses_limit) == 0 && ses_count!=0)
- ses_count=0;
+ SendDlgItemMessage(hdlg, IDC_LIST, CB_SETCURSEL, 0, 0);
- SendDlgItemMessage(hdlg, IDC_LIST, CB_SETCURSEL, 0, 0);
+ }
+ else if (ses_count >= g_ses_limit) {
+ ses_count -= g_ses_limit;
+ DelUserDefSession(ses_count);
+ EnableWindow(GetDlgItem(hdlg, IDC_SESSDEL), FALSE);
+ SendDlgItemMessage(hdlg, IDC_LIST, CB_RESETCONTENT, 0, 0);
- }
- else if (ses_count>=ses_limit)
- {
- ses_count-=ses_limit;
- DelUserDefSession(ses_count);
- EnableWindow(GetDlgItem(hdlg,IDC_SESSDEL),FALSE);
- SendDlgItemMessage(hdlg, IDC_LIST, CB_RESETCONTENT, 0, 0);
+ if ((ses_count = LoadSessionToCombobox(hdlg, 0, g_ses_limit, "SessionDate", 0)) == g_ses_limit)
+ EnableWindow(GetDlgItem(hdlg, IDC_SESSDEL), TRUE);
- if ((ses_count=LoadSessionToCombobox(hdlg,0,ses_limit,"SessionDate",0)) == ses_limit)
- EnableWindow(GetDlgItem(hdlg,IDC_SESSDEL),TRUE);
+ if (LoadSessionToCombobox(hdlg, 0, 255, "UserSessionDsc", g_ses_limit) == 0 && ses_count != 0)
+ ses_count = 0;
- if (LoadSessionToCombobox(hdlg,0,255,"UserSessionDsc",ses_limit) == 0 && ses_count!=0)
- ses_count=0;
+ if (session_list_recovered[0]) ses_count = 256;
- if (session_list_recovered[0]) ses_count=256;
+ SendDlgItemMessage(hdlg, IDC_LIST, CB_SETCURSEL, 0, 0);
+ }
+ else {
+ DeleteAutoSession(ses_count);
+ EnableWindow(GetDlgItem(hdlg, IDC_SESSDEL), FALSE);
+ SendDlgItemMessage(hdlg, IDC_LIST, CB_RESETCONTENT, 0, 0);
+ if ((ses_count = LoadSessionToCombobox(hdlg, 0, g_ses_limit, "SessionDate", 0)) == g_ses_limit)
+ EnableWindow(GetDlgItem(hdlg, IDC_SESSDEL), TRUE);
- SendDlgItemMessage(hdlg, IDC_LIST, CB_SETCURSEL, 0, 0);
- }
- else
- {
- DeleteAutoSession(ses_count);
- EnableWindow(GetDlgItem(hdlg,IDC_SESSDEL),FALSE);
- SendDlgItemMessage(hdlg, IDC_LIST, CB_RESETCONTENT, 0, 0);
- if ((ses_count=LoadSessionToCombobox(hdlg,0,ses_limit,"SessionDate",0)) == ses_limit)
- EnableWindow(GetDlgItem(hdlg,IDC_SESSDEL),TRUE);
+ if (LoadSessionToCombobox(hdlg, 0, 255, "UserSessionDsc", g_ses_limit) == 0 && ses_count != 0)
+ ses_count = 0;
- if (LoadSessionToCombobox(hdlg,0,255,"UserSessionDsc",ses_limit) == 0 && ses_count!=0)
- ses_count=0;
+ if (session_list_recovered[0]) ses_count = 256;
- if (session_list_recovered[0]) ses_count=256;
+ SendDlgItemMessage(hdlg, IDC_LIST, CB_SETCURSEL, 0, 0);
+ }
+ if (SendDlgItemMessage(hdlg, IDC_LIST, CB_GETCOUNT, 0, 0))
+ EnableWindow(GetDlgItem(hdlg, IDC_SESSDEL), TRUE);
+ else
+ EnableWindow(GetDlgItem(hdlg, IDC_SESSDEL), FALSE);
+ break;
- SendDlgItemMessage(hdlg, IDC_LIST, CB_SETCURSEL, 0, 0);
- }
- if (SendDlgItemMessage(hdlg, IDC_LIST, CB_GETCOUNT, 0, 0))
- EnableWindow(GetDlgItem(hdlg,IDC_SESSDEL),TRUE);
- else
- EnableWindow(GetDlgItem(hdlg,IDC_SESSDEL),FALSE);
- }break;
-
- case IDOK:
- {
- if (!LoadSession(0,ses_count))
- {
- SavePosition(hdlg, "LoadDlg");
- DestroyWindow(hdlg);
- g_hDlg=0;
- }
- }break;
-
- case IDCANCEL:
- {
- SavePosition(hdlg, "LoadDlg");
- DestroyWindow(hdlg);
- g_hDlg=0;
- }break;
+ case IDOK:
+ if (!LoadSession(0, ses_count)) {
+ SavePosition(hdlg, "LoadDlg");
+ DestroyWindow(hdlg);
+ g_hDlg = 0;
}
break;
- default:
- return FALSE;
+ case IDCANCEL:
+ SavePosition(hdlg, "LoadDlg");
+ DestroyWindow(hdlg);
+ g_hDlg = 0;
+ break;
+ }
+ break;
+
+ default:
+ return FALSE;
}
return TRUE;
}
-INT_PTR CloseCurrentSession(WPARAM wparam,LPARAM lparam)
+INT_PTR CloseCurrentSession(WPARAM wparam, LPARAM lparam)
{
HWND hWnd;
- int i=0;
+ int i = 0;
MessageWindowInputData mwid;
MessageWindowData mwd;
- while(session_list[0]!=0)
- {
+ while (session_list[0] != 0) {
mwid.cbSize = sizeof(MessageWindowInputData);
mwid.hContact = session_list[i];
mwid.uFlags = MSG_WINDOW_UFLAG_MSG_BOTH;
@@ -451,31 +416,30 @@ INT_PTR CloseCurrentSession(WPARAM wparam,LPARAM lparam) mwd.uFlags = MSG_WINDOW_UFLAG_MSG_BOTH;
CallService(MS_MSG_GETWINDOWDATA, (WPARAM)&mwid, (LPARAM)&mwd);
- if (g_mode)
- {
- hWnd=GetAncestor(mwd.hwndWindow,GA_ROOT);
- SendMessage(hWnd,WM_CLOSE,0,1);
+ if (g_mode) {
+ hWnd = GetAncestor(mwd.hwndWindow, GA_ROOT);
+ SendMessage(hWnd, WM_CLOSE, 0, 1);
}
else SendMessage(mwd.hwndWindow, WM_CLOSE, 0, 0);
}
- ZeroMemory(session_list,SIZEOF(session_list));
+ ZeroMemory(session_list, SIZEOF(session_list));
return 0;
}
-int SaveSessionHandles(WPARAM wparam,LPARAM lparam)
+int SaveSessionHandles(WPARAM wparam, LPARAM lparam)
{
if (session_list[0] == 0)
return 1;
- int k=0;
+ int k = 0;
for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- if ((k=CheckForDuplicate(session_list,hContact)) != -1 && !(g_bExclHidden && !CheckContactVisibility(hContact))) {
- AddSessionMark(hContact,lparam,'1');
- AddInSessionOrder(hContact,lparam,k,1);
+ if ((k = CheckForDuplicate(session_list, hContact)) != -1 && !(g_bExclHidden && !CheckContactVisibility(hContact))) {
+ AddSessionMark(hContact, lparam, '1');
+ AddInSessionOrder(hContact, lparam, k, 1);
}
else {
- AddSessionMark(hContact,lparam,'0');
- AddInSessionOrder(hContact,lparam,0,0);
+ AddSessionMark(hContact, lparam, '0');
+ AddInSessionOrder(hContact, lparam, 0, 0);
}
}
if (lparam == 1) {
@@ -485,55 +449,54 @@ int SaveSessionHandles(WPARAM wparam,LPARAM lparam) return 0;
}
-INT_PTR SaveUserSessionHandles(WPARAM wparam,LPARAM lparam)
+INT_PTR SaveUserSessionHandles(WPARAM wparam, LPARAM lparam)
{
if (g_hSDlg) {
- ShowWindow(g_hSDlg,SW_SHOW);
+ ShowWindow(g_hSDlg, SW_SHOW);
return 1;
}
- g_hSDlg = CreateDialog(hinstance,MAKEINTRESOURCE(IDD_SAVEDIALOG), 0, SaveSessionDlgProc);
+ g_hSDlg = CreateDialog(hinstance, MAKEINTRESOURCE(IDD_SAVEDIALOG), 0, SaveSessionDlgProc);
return 0;
}
-INT_PTR OpenSessionsManagerWindow(WPARAM wparam,LPARAM lparam)
+INT_PTR OpenSessionsManagerWindow(WPARAM wparam, LPARAM lparam)
{
if (g_hDlg) {
- ShowWindow(g_hDlg,SW_SHOW);
+ ShowWindow(g_hDlg, SW_SHOW);
return 0;
}
-
- ptrT
+
+ ptrT
tszSession(db_get_tsa(NULL, MODNAME, "SessionDate_0")),
tszUserSession(db_get_tsa(NULL, MODNAME, "UserSessionDsc_0"));
if (g_bIncompletedSave || tszSession || tszUserSession) {
- g_hDlg = CreateDialog(hinstance,MAKEINTRESOURCE(IDD_WLCMDIALOG), 0, LoadSessionDlgProc);
+ g_hDlg = CreateDialog(hinstance, MAKEINTRESOURCE(IDD_WLCMDIALOG), 0, LoadSessionDlgProc);
return 0;
}
if (g_bOtherWarnings)
- MessageBox(NULL, TranslateT("No sessions to open"), TranslateT("Sessions Manager"), MB_OK|MB_ICONWARNING);
+ MessageBox(NULL, TranslateT("No sessions to open"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING);
return 1;
}
int SaveSessionDate()
{
- if (session_list[0]!=0)
- {
+ if (session_list[0] != 0) {
int TimeSize = GetTimeFormat(LOCALE_USER_DEFAULT, 0/*TIME_NOSECONDS*/, NULL, NULL, NULL, 0);
- TCHAR *szTimeBuf = (TCHAR*)mir_alloc((TimeSize+1)*sizeof(TCHAR));
+ TCHAR *szTimeBuf = (TCHAR*)mir_alloc((TimeSize + 1)*sizeof(TCHAR));
GetTimeFormat(LOCALE_USER_DEFAULT, 0/*TIME_NOSECONDS*/, NULL, NULL, szTimeBuf, TimeSize);
int DateSize = GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL, NULL, 0);
- TCHAR *szDateBuf = (TCHAR*)mir_alloc((DateSize+1)*sizeof(TCHAR));
+ TCHAR *szDateBuf = (TCHAR*)mir_alloc((DateSize + 1)*sizeof(TCHAR));
- GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL, szDateBuf, DateSize );
- int lenn = (DateSize+TimeSize+5);
+ GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL, szDateBuf, DateSize);
+ int lenn = (DateSize + TimeSize + 5);
TCHAR *szSessionTime = (TCHAR*)mir_alloc(lenn*sizeof(TCHAR));
mir_sntprintf(szSessionTime, lenn, _T("%s - %s"), szTimeBuf, szDateBuf);
char szSessionDate[256];
- DBVARIANT dbv = {0};
+ DBVARIANT dbv = { 0 };
mir_snprintf(szSessionDate, SIZEOF(szSessionDate), "%s_%d", "SessionDate", 0);
db_get_ts(NULL, MODNAME, szSessionDate, &dbv);
TCHAR *szSessionDateBuf_1 = mir_tstrdup(dbv.ptszVal);
@@ -541,7 +504,7 @@ int SaveSessionDate() db_set_ts(NULL, MODNAME, szSessionDate, szSessionTime);
mir_free(szSessionTime);
- ResaveSettings("SessionDate", 1, ses_limit, szSessionDateBuf_1);
+ ResaveSettings("SessionDate", 1, g_ses_limit, szSessionDateBuf_1);
if (szTimeBuf)
mir_free(szTimeBuf);
@@ -555,77 +518,56 @@ int SaveSessionDate() int SaveUserSessionName(TCHAR *szUSessionName)
{
- int i=0;
- DBVARIANT dbv={0};
- char szUserSessionNameBuf[256]={0};
- TCHAR *szUserSessionNameBuf_1=NULL;
- TCHAR *szUserSessionName=NULL;
- TCHAR *ptr=NULL;
-
- if (session_list[0]!=0)
- {
- szUserSessionName = mir_tstrdup(szUSessionName);
- mir_snprintf(szUserSessionNameBuf, SIZEOF(szUserSessionNameBuf), "%s_%u", "UserSessionDsc", 0);
- if (!db_get_ts(NULL, MODNAME, szUserSessionNameBuf, &dbv))
- {
- szUserSessionNameBuf_1 = mir_tstrdup(dbv.ptszVal);
- db_free(&dbv);
- ResaveSettings("UserSessionDsc",1,255,szUserSessionNameBuf_1);
- }
+ if (session_list[0] == 0)
+ return 1;
- db_set_ts(NULL, MODNAME, szUserSessionNameBuf, szUserSessionName);
+ char szUserSessionNameBuf[256];
+ mir_snprintf(szUserSessionNameBuf, SIZEOF(szUserSessionNameBuf), "%s_%u", "UserSessionDsc", 0);
+ ptrT szUserSessionName(db_get_tsa(NULL, MODNAME, szUserSessionNameBuf));
+ if (szUserSessionName)
+ ResaveSettings("UserSessionDsc", 1, 255, szUserSessionName);
- //free(szUserSessionNameBuf_1);
- mir_free(szUserSessionName);
- return 0;
- }
-
- return 1;
+ db_set_ts(NULL, MODNAME, szUserSessionNameBuf, szUSessionName);
+ return 0;
}
-INT_PTR LoadLastSession(WPARAM wparam,LPARAM lparam)
+INT_PTR LoadLastSession(WPARAM wparam, LPARAM lparam)
{
- int ret=0;
if (isLastTRUE)
- ret=LoadSession(wparam,lparam);
- else if (g_bOtherWarnings)
+ return LoadSession(wparam, lparam);
+ if (g_bOtherWarnings)
MessageBox(NULL, TranslateT("Last Sessions is empty"), TranslateT("Sessions Manager"), MB_OK);
- return ret;
+ return 0;
}
-int LoadSession(WPARAM wparam,LPARAM lparam)
+int LoadSession(WPARAM wparam, LPARAM lparam)
{
- int dup=0;
- int hidden[255]={'0'};
+ int dup = 0;
+ int hidden[255] = { '0' };
MCONTACT hContact;
MCONTACT session_list_t[255] = { 0 };
- int mode=0;
- int i=0,j=0;
- if ((UINT)lparam>=ses_limit&&lparam!=256)
- {
- mode=1;
- lparam-=ses_limit;
+ int mode = 0;
+ if ((int)lparam >= g_ses_limit&&lparam != 256) {
+ mode = 1;
+ lparam -= g_ses_limit;
}
- if (session_list_recovered[0]&&lparam == 256&&mode == 0)
- memcpy(session_list_t,session_list_recovered,SIZEOF(session_list_t));
+ if (session_list_recovered[0] && lparam == 256 && mode == 0)
+ memcpy(session_list_t, session_list_recovered, SIZEOF(session_list_t));
else
for (hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- if (LoadContactsFromMask(hContact,mode,lparam)) {
- i=GetInSessionOrder(hContact,mode, lparam);
+ if (LoadContactsFromMask(hContact, mode, lparam)) {
+ int i = GetInSessionOrder(hContact, mode, lparam);
session_list_t[i] = hContact;
}
}
- i=0;
+ int i = 0, j = 0;
//TODO: change to "switch"
- while(session_list_t[i]!=0)
- {
+ while (session_list_t[i] != 0) {
if (CheckForDuplicate(session_list, session_list_t[i]) == -1)
CallService(MS_CLIST_CONTACTDOUBLECLICKED, (WPARAM)session_list_t[i], 0);
- else if (g_bWarnOnHidden)
- {
- if (!CheckContactVisibility(session_list_t[i]))
- {
- hidden[j]=i+1;
+ else if (g_bWarnOnHidden) {
+ if (!CheckContactVisibility(session_list_t[i])) {
+ hidden[j] = i + 1;
j++;
}
dup++;
@@ -633,36 +575,26 @@ int LoadSession(WPARAM wparam,LPARAM lparam) i++;
}
- if (i == 0)
- {
+ if (i == 0) {
if (g_bOtherWarnings)
- MessageBox(NULL, TranslateT("No contacts to open"), TranslateT("Sessions Manager"), MB_OK|MB_ICONWARNING);
+ MessageBox(NULL, TranslateT("No contacts to open"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING);
return 1;
}
- else if (dup == i)
- {
- if (!hidden)
- {
+
+ if (dup == i) {
+ if (!hidden) {
if (g_bOtherWarnings)
- MessageBox(NULL, TranslateT("This Session already opened"), TranslateT("Sessions Manager"), MB_OK|MB_ICONWARNING);
+ MessageBox(NULL, TranslateT("This Session already opened"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING);
return 1;
}
- else if (!g_bWarnOnHidden&&g_bOtherWarnings)
- {
- MessageBox(NULL, TranslateT("This Session already opened"), TranslateT("Sessions Manager"), MB_OK|MB_ICONWARNING);
+ if (!g_bWarnOnHidden&&g_bOtherWarnings) {
+ MessageBox(NULL, TranslateT("This Session already opened"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING);
return 1;
}
- else if (g_bWarnOnHidden)
- {
- if (MessageBox(NULL, TranslateT("This Session already opened (but probably hidden).\nDo you want to show hidden contacts?"), TranslateT("Sessions Manager"), MB_YESNO|MB_ICONQUESTION) == IDYES)
- {
- j=0;
- while(hidden[j]!=0)
- {
- CallService(MS_CLIST_CONTACTDOUBLECLICKED, (WPARAM)session_list_t[hidden[j]-1], 0);
- j++;
- }
- }
+ if (g_bWarnOnHidden) {
+ if (IDYES == MessageBox(NULL, TranslateT("This Session already opened (but probably hidden).\nDo you want to show hidden contacts?"), TranslateT("Sessions Manager"), MB_YESNO | MB_ICONQUESTION))
+ for (j = 0; hidden[j] != 0; j++)
+ CallService(MS_CLIST_CONTACTDOUBLECLICKED, (WPARAM)session_list_t[hidden[j] - 1], 0);
}
}
@@ -671,36 +603,31 @@ int LoadSession(WPARAM wparam,LPARAM lparam) int DelUserDefSession(int ses_count)
{
- int i=0;
- MCONTACT hContact;
- char szSessionName[256]={0};
- TCHAR *szSessionNameBuf=NULL;
-
- for (hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- RemoveSessionMark(hContact,1,ses_count);
- SetInSessionOrder(hContact,1,ses_count,0);
+ for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ RemoveSessionMark(hContact, 1, ses_count);
+ SetInSessionOrder(hContact, 1, ses_count, 0);
}
+ char szSessionName[256];
mir_snprintf(szSessionName, SIZEOF(szSessionName), "%s_%u", "UserSessionDsc", ses_count);
db_unset(NULL, MODNAME, szSessionName);
mir_snprintf(szSessionName, SIZEOF(szSessionName), "%s_%u", "FavUserSession", ses_count);
db_unset(NULL, MODNAME, szSessionName);
- for (i=(ses_count+1);;i++) {
+ for (int i = ses_count + 1;; i++) {
mir_snprintf(szSessionName, SIZEOF(szSessionName), "%s_%u", "UserSessionDsc", i);
+ ptrT szSessionNameBuf(db_get_tsa(NULL, MODNAME, szSessionName));
- if (szSessionNameBuf = db_get_tsa(NULL, MODNAME, szSessionName)) {
- MarkUserDefSession(i-1,IsMarkedUserDefSession(i));
- mir_snprintf(szSessionName, SIZEOF(szSessionName), "%s_%u", "UserSessionDsc", i-1);
+ mir_snprintf(szSessionName, SIZEOF(szSessionName), "%s_%u", "UserSessionDsc", i - 1);
+ if (szSessionNameBuf) {
+ MarkUserDefSession(i-1, IsMarkedUserDefSession(i));
db_set_ts(NULL, MODNAME, szSessionName, szSessionNameBuf);
- mir_free(szSessionNameBuf);
}
else {
- mir_snprintf(szSessionName, SIZEOF(szSessionName), "%s_%u", "UserSessionDsc", i-1);
db_unset(NULL, MODNAME, szSessionName);
- mir_snprintf(szSessionName, SIZEOF(szSessionName), "%s_%u", "FavUserSession", i-1);
+ mir_snprintf(szSessionName, SIZEOF(szSessionName), "%s_%u", "FavUserSession", i - 1);
db_unset(NULL, MODNAME, szSessionName);
break;
}
@@ -712,30 +639,23 @@ int DelUserDefSession(int ses_count) int DeleteAutoSession(int ses_count)
{
- int i=0;
- MCONTACT hContact;
- char szSessionName[256]={0};
-
- TCHAR *szSessionNameBuf=NULL;
-
- for (hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
- RemoveSessionMark(hContact,0,ses_count);
- SetInSessionOrder(hContact,0,ses_count,0);
+ for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
+ RemoveSessionMark(hContact, 0, ses_count);
+ SetInSessionOrder(hContact, 0, ses_count, 0);
}
+ char szSessionName[256];
mir_snprintf(szSessionName, SIZEOF(szSessionName), "%s_%u", "SessionDate", ses_count);
db_unset(NULL, MODNAME, szSessionName);
- for (i=(ses_count+1);;i++) {
+ for (int i = ses_count+1;; i++) {
mir_snprintf(szSessionName, SIZEOF(szSessionName), "%s_%u", "SessionDate", i);
+ ptrT szSessionNameBuf(db_get_tsa(NULL, MODNAME, szSessionName));
- if (szSessionNameBuf = db_get_tsa(NULL, MODNAME, szSessionName)) {
- mir_snprintf(szSessionName, SIZEOF(szSessionName), "%s_%u", "SessionDate", i-1);
+ mir_snprintf(szSessionName, SIZEOF(szSessionName), "%s_%u", "SessionDate", i - 1);
+ if (szSessionNameBuf)
db_set_ts(NULL, MODNAME, szSessionName, szSessionNameBuf);
- mir_free(szSessionNameBuf);
- }
else {
- mir_snprintf(szSessionName, SIZEOF(szSessionName), "%s_%u", "SessionDate", i-1);
db_unset(NULL, MODNAME, szSessionName);
break;
}
@@ -744,75 +664,68 @@ int DeleteAutoSession(int ses_count) return 0;
}
-int SessionPreShutdown(WPARAM wparam,LPARAM lparam)
+int SessionPreShutdown(WPARAM wparam, LPARAM lparam)
{
- DONT=1;
+ DONT = 1;
if (g_hDlg) DestroyWindow(g_hDlg);
if (g_hSDlg) DestroyWindow(g_hSDlg);
- if (g_bIncompletedSave) {
- int i=0;
- while(session_list_recovered[i]) {
+ if (g_bIncompletedSave)
+ for (int i = 0; session_list_recovered[i]; i++)
db_set_b(session_list_recovered[i], MODNAME, "wasInLastSession", 0);
- i++;
- }
- }
db_set_b(NULL, MODNAME, "lastSaveCompleted", 1);
return 0;
}
-int OkToExit(WPARAM wparam,LPARAM lparam)
+int OkToExit(WPARAM wparam, LPARAM lparam)
{
- int exitmode=db_get_b(NULL, MODNAME, "ShutdownMode", 2);
- DONT=1;
- if (exitmode == 2&&session_list[0]!=0) {
+ int exitmode = db_get_b(NULL, MODNAME, "ShutdownMode", 2);
+ DONT = 1;
+ if (exitmode == 2 && session_list[0] != 0) {
SaveSessionDate();
- SaveSessionHandles(0,0);
+ SaveSessionHandles(0, 0);
db_set_b(NULL, MODNAME, "lastempty", 0);
}
- else if (exitmode == 1&&session_list[0]!=0)
- {
- DialogBox(hinstance,MAKEINTRESOURCE(IDD_EXDIALOG), 0, ExitDlgProc);
+ else if (exitmode == 1 && session_list[0] != 0) {
+ DialogBox(hinstance, MAKEINTRESOURCE(IDD_EXDIALOG), 0, ExitDlgProc);
}
else db_set_b(NULL, MODNAME, "lastempty", 1);
return 0;
}
-static int GetContactHandle(WPARAM wparam,LPARAM lParam)
+static int GetContactHandle(WPARAM wparam, LPARAM lParam)
{
MessageWindowEventData *MWeventdata = (MessageWindowEventData*)lParam;
-
if (MWeventdata->uType == MSG_WINDOW_EVT_OPEN) {
- if (strstr(MWeventdata->szModule,"tabSRMsg")) g_mode=1;
- AddToCurSession(MWeventdata->hContact,0);
+ if (strstr(MWeventdata->szModule, "tabSRMsg")) g_mode = 1;
+ AddToCurSession(MWeventdata->hContact, 0);
if (g_bCrashRecovery) db_set_b(MWeventdata->hContact, MODNAME, "wasInLastSession", 1);
}
else if (MWeventdata->uType == MSG_WINDOW_EVT_CLOSE) {
if (!DONT)
- DelFromCurSession(MWeventdata->hContact,0);
+ DelFromCurSession(MWeventdata->hContact, 0);
if (g_bCrashRecovery) db_set_b(MWeventdata->hContact, MODNAME, "wasInLastSession", 0);
}
return 0;
}
-INT_PTR BuildFavMenu(WPARAM wparam,LPARAM lparam)
+INT_PTR BuildFavMenu(WPARAM wparam, LPARAM lparam)
{
- HMENU hMenu=NULL;
POINT pt;
- int res=0;
- hMenu = CreatePopupMenu();
GetCursorPos(&pt);
- FillFavoritesMenu(hMenu,g_ses_count);
- res = TrackPopupMenu(hMenu, TPM_RETURNCMD|TPM_NONOTIFY, pt.x, pt.y, 0, GetActiveWindow(), NULL);
+
+ HMENU hMenu = CreatePopupMenu();
+ FillFavoritesMenu(hMenu, g_ses_count);
+ int res = TrackPopupMenu(hMenu, TPM_RETURNCMD | TPM_NONOTIFY, pt.x, pt.y, 0, GetActiveWindow(), NULL);
if (res == 0) return 1;
- LoadSession(0,(res-1)+ses_limit);
+ LoadSession(0, (res - 1) + g_ses_limit);
return 0;
}
-static int CreateButtons(WPARAM wparam,LPARAM lparam)
+static int CreateButtons(WPARAM wparam, LPARAM lparam)
{
TTBButton ttb = { sizeof(ttb) };
ttb.dwFlags = TTBBF_SHOWTOOLTIP | TTBBF_VISIBLE;
@@ -839,26 +752,28 @@ static int CreateButtons(WPARAM wparam,LPARAM lparam) return 0;
}
-static int PluginInit(WPARAM wparam,LPARAM lparam)
+static INT_PTR LaunchSessions(WPARAM wParam, LPARAM lParam)
{
- int startup=0;
-
- HookEvent(ME_MSG_WINDOWEVENT, GetContactHandle);
- HookEvent(ME_OPT_INITIALISE, OptionsInit);
- HookEvent(ME_TTB_MODULELOADED, CreateButtons);
-
- startup=db_get_b(NULL, MODNAME, "StartupMode", 3);
+ CallService(MS_SYSTEM_REMOVEWAIT, wParam, 0);
+ CloseHandle((HANDLE)wParam);
- if (startup == 1||(startup == 3&&isLastTRUE == TRUE))
- {
- StartUp=TRUE;
- g_hDlg=CreateDialog(hinstance,MAKEINTRESOURCE(IDD_WLCMDIALOG), 0, LoadSessionDlgProc);
+ int startup = db_get_b(NULL, MODNAME, "StartupMode", 3);
+ if (startup == 1 || (startup == 3 && isLastTRUE == TRUE)) {
+ StartUp = TRUE;
+ g_hDlg = CreateDialog(hinstance, MAKEINTRESOURCE(IDD_WLCMDIALOG), 0, LoadSessionDlgProc);
}
- else if (startup == 2&&isLastTRUE == TRUE)
- {
- g_hghostw=TRUE;
- g_hDlg=CreateDialog(hinstance,MAKEINTRESOURCE(IDD_WLCMDIALOG), 0, LoadSessionDlgProc);
+ else if (startup == 2 && isLastTRUE == TRUE) {
+ g_hghostw = TRUE;
+ g_hDlg = CreateDialog(hinstance, MAKEINTRESOURCE(IDD_WLCMDIALOG), 0, LoadSessionDlgProc);
}
+ return 0;
+}
+
+static int PluginInit(WPARAM wparam, LPARAM lparam)
+{
+ HookEvent(ME_MSG_WINDOWEVENT, GetContactHandle);
+ HookEvent(ME_OPT_INITIALISE, OptionsInit);
+ HookEvent(ME_TTB_MODULELOADED, CreateButtons);
// Hotkeys
HOTKEYDESC hkd = { sizeof(hkd) };
@@ -945,30 +860,39 @@ extern "C" __declspec(dllexport) int Load(void) CreateServiceFunction(MS_SESSIONS_SAVEUSERSESSION, SaveUserSessionHandles);
CreateServiceFunction(MS_SESSIONS_CLOSESESSION, CloseCurrentSession);
+ HANDLE hEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
+ if (hEvent != 0) {
+ CreateServiceFunction(MS_SESSIONS_LAUNCHME, LaunchSessions);
+ CallService(MS_SYSTEM_WAITONHANDLE, (WPARAM)hEvent, (LPARAM)MS_SESSIONS_LAUNCHME);
+ }
+
g_ses_count = db_get_b(0, MODNAME, "UserSessionsCount", 0);
if (!g_ses_count)
g_ses_count = db_get_b(0, "Sessions (Unicode)", "UserSessionsCount", 0);
- ses_limit = db_get_b(0, MODNAME, "TrackCount", 10);
+ g_ses_limit = db_get_b(0, MODNAME, "TrackCount", 10);
g_bExclHidden = db_get_b(NULL, MODNAME, "ExclHidden", 0);
g_bWarnOnHidden = db_get_b(NULL, MODNAME, "WarnOnHidden", 0);
g_bOtherWarnings = db_get_b(NULL, MODNAME, "OtherWarnings", 1);
g_bCrashRecovery = db_get_b(NULL, MODNAME, "CrashRecovery", 0);
if (g_bCrashRecovery)
- g_bIncompletedSave=!db_get_b(NULL, MODNAME, "lastSaveCompleted", 0);
+ g_bIncompletedSave = !db_get_b(NULL, MODNAME, "lastSaveCompleted", 0);
if (g_bIncompletedSave) {
- int i=0;
+ int i = 0;
ZeroMemory(session_list_recovered, sizeof(session_list_recovered));
for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
if (db_get_b(hContact, MODNAME, "wasInLastSession", 0))
session_list_recovered[i++] = hContact;
}
- if (!session_list_recovered[0]) g_bIncompletedSave=FALSE;
+
+ if (!session_list_recovered[0])
+ g_bIncompletedSave = FALSE;
+
db_set_b(NULL, MODNAME, "lastSaveCompleted", 0);
- if (!db_get_b(NULL, MODNAME, "lastempty", 1)||g_bIncompletedSave)
+ if (!db_get_b(NULL, MODNAME, "lastempty", 1) || g_bIncompletedSave)
isLastTRUE = TRUE;
HookEvent(ME_SYSTEM_MODULESLOADED, PluginInit);
@@ -977,6 +901,5 @@ extern "C" __declspec(dllexport) int Load(void) // Icons
Icon_Register(hinstance, MODNAME, iconList, SIZEOF(iconList));
-
return 0;
}
diff --git a/plugins/Sessions/Src/Options.cpp b/plugins/Sessions/Src/Options.cpp index 04ade10284..a6f4cde015 100644 --- a/plugins/Sessions/Src/Options.cpp +++ b/plugins/Sessions/Src/Options.cpp @@ -163,7 +163,7 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam) hIcon=(bChecked=IsMarkedUserDefSession(opses_count))?hMarked:hNotMarked;
- SetDlgItemInt(hdlg, IDC_TRACK,ses_limit=db_get_b(0, MODNAME, "TrackCount", 10), FALSE);
+ SetDlgItemInt(hdlg, IDC_TRACK,g_ses_limit=db_get_b(0, MODNAME, "TrackCount", 10), FALSE);
SendDlgItemMessage(hdlg, IDC_SPIN1, UDM_SETRANGE, 0, MAKELONG(10, 1));
SendDlgItemMessage(hdlg, IDC_SPIN1, UDM_SETPOS, 0, GetDlgItemInt(hdlg, IDC_TRACK, NULL, FALSE));
@@ -247,7 +247,7 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam) {
int iDelay=GetDlgItemInt(hdlg, IDC_STARTDELAY,NULL, FALSE);
db_set_w(0, MODNAME, "StartupModeDelay", (WORD)iDelay);
- db_set_b(0, MODNAME, "TrackCount", (BYTE)(ses_limit=GetDlgItemInt(hdlg, IDC_TRACK,NULL, FALSE)));
+ db_set_b(0, MODNAME, "TrackCount", (BYTE)(g_ses_limit=GetDlgItemInt(hdlg, IDC_TRACK,NULL, FALSE)));
if (IsDlgButtonChecked(hdlg, IDC_REXSAVE))
db_set_b(NULL, MODNAME, "ShutdownMode", 2);
else if (IsDlgButtonChecked(hdlg, IDC_REXDSAVE))
diff --git a/plugins/Sessions/Src/Sessions.h b/plugins/Sessions/Src/Sessions.h index 5cbfd65a4b..c053fde48d 100644 --- a/plugins/Sessions/Src/Sessions.h +++ b/plugins/Sessions/Src/Sessions.h @@ -24,6 +24,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include <windows.h>
#include <commctrl.h>
+#include <malloc.h>
+
#include <newpluginapi.h>
#include <m_options.h>
#include <m_clc.h>
@@ -44,6 +46,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define MODNAME "Sessions"
+#define MS_SESSIONS_LAUNCHME "Sessions/Service/LaunchMe"
+
extern IconItem iconList[];
#define MIIM_STRING 0x00000040
@@ -60,8 +64,8 @@ int SaveSessionDate(); extern HINSTANCE hinstance;
extern MCONTACT session_list_recovered[255];
extern MCONTACT session_list[255];
-extern unsigned int ses_limit;
-extern unsigned int g_ses_count;
+extern int g_ses_limit;
+extern int g_ses_count;
extern BOOL g_bExclHidden;
extern BOOL g_bWarnOnHidden;
extern BOOL g_bOtherWarnings;
diff --git a/plugins/Sessions/Src/Utils.cpp b/plugins/Sessions/Src/Utils.cpp index fd84a86f8b..3a4271d942 100644 --- a/plugins/Sessions/Src/Utils.cpp +++ b/plugins/Sessions/Src/Utils.cpp @@ -21,46 +21,43 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. void AddSessionMark(MCONTACT 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) {
- if (!db_get_s(hContact, MODNAME, "LastSessionsMarks", &dbv) && dbv.pszVal) {
- temp_1[0]=dbv.pszVal[0];
- 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];
+ if (mode == 0) {
+ ptrA szValue(db_get_sa(hContact, MODNAME, "LastSessionsMarks"));
+ if (szValue) {
+ char temp_1 = szValue[0];
+ for (int i = 0; i < g_ses_limit; i++) {
+ char temp_2 = szValue[i + 1];
+ szValue[i + 1] = temp_1;
+ temp_1 = temp_2;
}
- 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);
+ for (int i = g_ses_limit; i < 10; i++)
+ szValue[i] = '0';
+ szValue[0] = bit;
+ db_set_s(hContact, MODNAME, "LastSessionsMarks", szValue);
}
- else if (bit == '1') db_set_s(hContact, MODNAME, "LastSessionsMarks", "10000000000");
+ else if (bit == '1')
+ db_set_s(hContact, MODNAME, "LastSessionsMarks", "10000000000");
}
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);
+ ptrA szValue(db_get_sa(hContact, MODNAME, "UserSessionsMarks"));
+ if (szValue) {
+ char *pszBuffer;
+ if (strlen(szValue) < g_ses_count) {
+ pszBuffer = (char*)mir_alloc(g_ses_count + 1);
+ ZeroMemory(pszBuffer, g_ses_count + 1);
+ strcpy(pszBuffer, szValue);
}
- else pszBuffer = mir_strdup(dbv.pszVal);
- db_free(&dbv);
-
- temp_1[0]=pszBuffer[0];
- 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];
+ else pszBuffer = szValue.detouch();
+
+ char temp_1 = pszBuffer[0];
+ for (int i = 0; i < g_ses_count; i++) {
+ char temp_2 = pszBuffer[i+1];
+ pszBuffer[i+1] = temp_1;
+ temp_1 = temp_2;
}
- pszBuffer[0]=bit;
+ pszBuffer[0] = bit;
db_set_s(hContact, MODNAME, "UserSessionsMarks", pszBuffer);
-
+
mir_free(pszBuffer);
}
else if (bit == '1')
@@ -70,160 +67,112 @@ void AddSessionMark(MCONTACT hContact, int mode, char bit) }
}
-void RemoveSessionMark(MCONTACT hContact,int mode,int marknum)
+void RemoveSessionMark(MCONTACT hContact, int mode, int marknum)
{
- unsigned int i=1;
- char temp_1[1]={'\0'},temp_2[1]={'\0'};
- char szDst[256]={'\0'};
- 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];
+ ptrA szValue(db_get_sa(hContact, MODNAME, "LastSessionsMarks"));
+ if (szValue) {
+ for (int i = marknum; i < g_ses_limit; i++)
+ szValue[i] = szValue[i+1];
- for (i=ses_limit;i<10;i++)
- dbv.pszVal[i] = '0';
+ for (int i = g_ses_limit; i < 10; i++)
+ szValue[i] = '0';
- db_set_s(hContact, MODNAME, "LastSessionsMarks", dbv.pszVal);
- db_free(&dbv);
+ db_set_s(hContact, MODNAME, "LastSessionsMarks", szValue);
}
}
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];
+ ptrA szValue(db_get_sa(hContact, MODNAME, "UserSessionsMarks"));
+ if (szValue) {
+ for (int i = marknum; i < g_ses_limit; i++)
+ szValue[i] = szValue[i+1];
- db_set_s(hContact, MODNAME, "UserSessionsMarks", dbv.pszVal);
- db_free(&dbv);
+ db_set_s(hContact, MODNAME, "UserSessionsMarks", szValue);
}
}
}
-void SetSessionMark(MCONTACT hContact,int mode,char bit,unsigned int marknum)
+void SetSessionMark(MCONTACT hContact, int mode, char bit, unsigned int marknum)
{
- DBVARIANT dbv;
- char* pszBuffer=NULL;
-
- 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 == 0) {
+ ptrA szValue(db_get_sa(hContact, MODNAME, "LastSessionsMarks"));
+ if (szValue) {
+ szValue[marknum] = bit;
+ db_set_s(hContact, MODNAME, "LastSessionsMarks", szValue);
}
}
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);
- mir_free(pszBuffer);
- db_free(&dbv);
+ ptrA szValue(db_get_sa(hContact, MODNAME, "UserSessionsMarks"));
+ if (szValue) {
+ szValue[marknum] = bit;
+ db_set_s(hContact, MODNAME, "UserSessionsMarks", szValue);
}
}
}
-BOOL LoadContactsFromMask(MCONTACT hContact,int mode,int count)
-{
- DBVARIANT dbv;
- if (mode == 0) {
- if (db_get_s(hContact, MODNAME, "LastSessionsMarks", &dbv))
- return 0;
- }
- else if (mode == 1) {
- if (db_get_s(hContact, MODNAME, "UserSessionsMarks", &dbv))
- return 0;
- }
- else return 0;
+bool LoadContactsFromMask(MCONTACT hContact, int mode, int count)
+{
+ ptrA szValue;
+ if (mode == 0)
+ szValue = db_get_sa(hContact, MODNAME, "LastSessionsMarks");
+ else if (mode == 1)
+ szValue = db_get_sa(hContact, MODNAME, "UserSessionsMarks");
+
+ if (szValue == NULL)
+ return false;
- BOOL res = dbv.pszVal[count] == '1';
- db_free(&dbv);
- return res;
+ return szValue[count] == '1';
}
-void AddInSessionOrder(MCONTACT hContact,int mode,int ordernum,int writemode)
+void AddInSessionOrder(MCONTACT hContact, int mode, int ordernum, int writemode)
{
- int i;
- char temp_1[2]={'\0'},temp_2[2]={'\0'};
- char szDst[256]={'\0'};
- char* pszBuffer=NULL;
- char szFormNumBuf[255]={'\0'};
-
- if (ordernum<10)
- mir_snprintf(szFormNumBuf, SIZEOF(szFormNumBuf), "%u%u", 0, ordernum);
- else
- mir_snprintf(szFormNumBuf, SIZEOF(szFormNumBuf), "%u", ordernum);
-
+ char szDst[256] = { '\0' };
+
+ char szFormNumBuf[100];
+ mir_snprintf(szFormNumBuf, SIZEOF(szFormNumBuf), "%02u", ordernum);
+
if (mode == 0) {
- DBVARIANT dbv;
- if (!db_get_s(hContact, MODNAME, "LastSessionsOrder", &dbv)) {
- char* temp=NULL;
- char* temp2=NULL;
- int len= (int)strlen(dbv.pszVal);
+ ptrA szValue(db_get_sa(hContact, MODNAME, "LastSessionsMarks"));
+ if (szValue) {
+ int len = (int)strlen(szValue);
if (!len)
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) {
- 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);
+ char *temp2 = (char*)_alloca(len-1);
+ strncpy(temp2, szValue, len-2);
+ temp2[len-2]='\0';
+
+ char *temp = (char*)_alloca(len+1);
+ mir_snprintf(temp, len+1, "%02u%s", ordernum, temp2);
- for (i=(ses_limit*2);i<20;i++)
- temp[i]='0';
+ for (int i = (g_ses_limit * 2); i < 20; i++)
+ temp[i] = '0';
db_set_s(hContact, MODNAME, "LastSessionsOrder", temp);
- mir_free(temp);
- mir_free(temp2);
- db_free(&dbv);
}
else if (writemode == 1) {
- ZeroMemory(szFormNumBuf,SIZEOF(szFormNumBuf));
- if (ordernum<10)
- mir_snprintf(szFormNumBuf, SIZEOF(szFormNumBuf), "%u%u%s", 0, ordernum, "000000000000000000");
- else
- mir_snprintf(szFormNumBuf, SIZEOF(szFormNumBuf), "%u%s", ordernum, "000000000000000000");
-
+ mir_snprintf(szFormNumBuf, SIZEOF(szFormNumBuf), "%02u%s", ordernum, "000000000000000000");
db_set_s(hContact, MODNAME, "LastSessionsOrder", szFormNumBuf);
}
}
else if (mode == 1) {
- DBVARIANT dbv;
- int advlen=0;
- 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)) {
- pszBuffer = (char*)mir_alloc(g_ses_count*2+1);
- ZeroMemory(pszBuffer,g_ses_count*2+1);
- strcpy(pszBuffer,dbv.pszVal);
+ ptrA szValue(db_get_sa(hContact, MODNAME, "UserSessionsOrder"));
+ if (szValue) {
+ char *pszBuffer;
+ if (strlen(szValue) < (g_ses_count * 2)) {
+ pszBuffer = (char*)mir_alloc(g_ses_count * 2 + 1);
+ ZeroMemory(pszBuffer, g_ses_count * 2 + 1);
+ strcpy(pszBuffer, szValue);
}
- else pszBuffer = mir_strdup(dbv.pszVal);
-
- if (!(advlen=len= (int)strlen(pszBuffer)))
- advlen=len=20;
- else
- advlen=len+2;
-
- temp = (char*)mir_alloc(advlen+1);
- ZeroMemory(temp,advlen+1);
-
- if (ordernum<10)
- mir_snprintf(temp, advlen+1, "%u%u%s", 0, ordernum, dbv.pszVal);
- else
- mir_snprintf(temp, advlen+1, "%u%s", ordernum, dbv.pszVal);
-
- db_free(&dbv);
+ else pszBuffer = mir_strdup(szValue);
+
+ int len = (int)strlen(pszBuffer);
+ len = (len == 0) ? 20 : len + 2;
+ char *temp = (char*)_alloca(len+1);
+ ZeroMemory(temp, len+1);
+ mir_snprintf(temp, len + 1, "%02u%s", ordernum, szValue);
db_set_s(hContact, MODNAME, "UserSessionsOrder", temp);
- mir_free(temp);
mir_free(pszBuffer);
}
else if (writemode == 1)
@@ -233,86 +182,74 @@ void AddInSessionOrder(MCONTACT hContact,int mode,int ordernum,int writemode) }
}
-int GetInSessionOrder(MCONTACT hContact,int mode,int count)
+int GetInSessionOrder(MCONTACT hContact, int mode, int count)
{
- int iOrder = 0;
- char szTemp[3]={'\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);
- db_free(&dbv);
+ char szTemp[3];
+ if (mode == 0) {
+ ptrA szValue(db_get_sa(hContact, MODNAME, "LastSessionsOrder"));
+ if (szValue) {
+ strncpy_s(szTemp, &szValue[count*2], 2);
+ return atoi(szTemp);
}
}
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);
- db_free(&dbv);
+ ptrA szValue(db_get_sa(hContact, MODNAME, "UserSessionsOrder"));
+ if (szValue) {
+ strncpy_s(szTemp, &szValue[count*2], 2);
+ return atoi(szTemp);
}
}
- return iOrder;
+ return 0;
}
-void SetInSessionOrder(MCONTACT hContact,int mode,int count,unsigned int ordernum)
+void SetInSessionOrder(MCONTACT hContact, int mode, int count, unsigned int ordernum)
{
- int iOrder=0;
- char szTemp[3]={'\0'};
-
- if (ordernum < 10)
- mir_snprintf(szTemp, SIZEOF(szTemp), "%u%u", 0, ordernum);
- else
- mir_snprintf(szTemp, SIZEOF(szTemp), "%u", ordernum);
-
- if (mode == 0) {
- DBVARIANT dbv;
- 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);
+ int iOrder = 0;
+
+ char szTemp[3];
+ mir_snprintf(szTemp, SIZEOF(szTemp), "%02u", ordernum);
+
+ if (mode == 0) {
+ ptrA szValue(db_get_sa(hContact, MODNAME, "LastSessionsOrder"));
+ if (szValue) {
+ szValue[count*2] = szTemp[0];
+ szValue[count*2 + 1] = szTemp[1];
+ db_set_s(hContact, MODNAME, "LastSessionsOrder", szValue);
}
}
else if (mode == 1) {
- DBVARIANT dbv;
- 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);
- db_free(&dbv);
+ ptrA szValue(db_get_sa(hContact, MODNAME, "UserSessionsOrder"));
+ if (szValue) {
+ szValue[count*2] = szTemp[0];
+ szValue[count*2 + 1] = szTemp[1];
+ db_set_s(hContact, MODNAME, "UserSessionsOrder", szValue);
}
}
}
-BOOL ResaveSettings(char* szName,int iFirst,int iLimit,TCHAR* szBuffer)
+BOOL ResaveSettings(char* szName, int iFirst, int iLimit, TCHAR* szBuffer)
{
- BYTE marked,marked_t;
- char szNameBuf[256]={0};
+ BYTE marked, marked_t;
for (int i = iFirst; i < iLimit; i++) {
if (szBuffer == NULL)
break;
+ char szNameBuf[256];
mir_snprintf(szNameBuf, SIZEOF(szNameBuf), "%s_%u", szName, i);
- DBVARIANT dbv_temp;
- int res = db_get_ts(NULL, MODNAME, szNameBuf, &dbv_temp);
+ TCHAR *ptszTemp = db_get_tsa(NULL, MODNAME, szNameBuf);
db_set_ts(NULL, MODNAME, szNameBuf, 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
+ if (ptszTemp == NULL) // read failed
return 0;
-
- szBuffer = mir_tstrdup(dbv_temp.ptszVal);
- db_free(&dbv_temp);
+
+ szBuffer = ptszTemp;
}
mir_free(szBuffer);
@@ -332,12 +269,12 @@ int AddToCurSession(MCONTACT wparam, LPARAM lparam) return 0;
}
-int DelFromCurSession(MCONTACT wparam,LPARAM lparam)
+int DelFromCurSession(MCONTACT wparam, LPARAM lparam)
{
- for (int i=0; session_list[i] != 0; i++) {
+ 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];
+ while (session_list[i + 1] != 0) {
+ session_list[i] = session_list[i + 1];
i++;
}
session_list[i] = 0;
@@ -348,10 +285,9 @@ int DelFromCurSession(MCONTACT wparam,LPARAM lparam) int CheckForDuplicate(MCONTACT contact_list[], MCONTACT lparam)
{
- int i=0;
- MCONTACT s_list[255] = {0};
+ MCONTACT s_list[255] = { 0 };
memcpy(s_list, contact_list, SIZEOF(s_list));
- for (i=0;;i++) {
+ for (int i = 0;; i++) {
if (s_list[i] == lparam)
return i;
if (s_list[i] == 0)
@@ -360,30 +296,31 @@ int CheckForDuplicate(MCONTACT contact_list[], MCONTACT lparam) 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;
- char szBuffer[256]={0};
+ 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, index, 256);
}
- for(int i=0; i < iLimit; i++) {
+
+ 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, 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, 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;
}
}
@@ -391,17 +328,17 @@ int LoadSessionToCombobox(HWND hdlg,BOOL mode,int iLimit,char* pszSetting,int iF return ses_count;
}
-int FillFavoritesMenu (HMENU hMenu,int iLimit)
+int FillFavoritesMenu(HMENU hMenu, int iLimit)
{
- int iItems=0;
+ int iItems = 0;
- for(int i=0;i < iLimit; i++) {
+ for (int i = 0; i < iLimit; i++) {
if (IsMarkedUserDefSession(i)) {
char szBuffer[256];
mir_snprintf(szBuffer, SIZEOF(szBuffer), "%s_%u", "UserSessionDsc", i);
TCHAR *pszBuffer = db_get_tsa(NULL, MODNAME, szBuffer);
if (pszBuffer) {
- AppendMenu(hMenu,MF_STRING,i+1,pszBuffer);
+ AppendMenu(hMenu, MF_STRING, i + 1, pszBuffer);
iItems++;
mir_free(pszBuffer);
}
@@ -418,30 +355,28 @@ void OffsetWindow(HWND parent, HWND hwnd, int dx, int dy) pt.x = rc.left;
pt.y = rc.top;
ScreenToClient(parent, &pt);
- rc.left =pt.x ;
- rc.top =pt.y ;
+ rc.left = pt.x;
+ rc.top = pt.y;
OffsetRect(&rc, dx, dy);
- SetWindowPos(hwnd, NULL, rc.left, rc.top,0, 0, SWP_NOZORDER |SWP_NOSIZE);
+ SetWindowPos(hwnd, NULL, rc.left, rc.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
}
int CheckContactVisibility(MCONTACT hContact)
-{
- if (db_get_b(hContact, "CList", "Hidden", 0))
- return 0;
- return 1;
+{
+ return !db_get_b(hContact, "CList", "Hidden", 0);
}
-void RenameUserDefSession(int ses_count,TCHAR* ptszNewName)
+void RenameUserDefSession(int ses_count, TCHAR* ptszNewName)
{
- char szSession[256]={0};
+ char szSession[256];
mir_snprintf(szSession, SIZEOF(szSession), "%s_%u", "UserSessionDsc", ses_count);
db_set_ts(NULL, MODNAME, szSession, ptszNewName);
}
-int MarkUserDefSession(int ses_count,BYTE bCheck)
+int MarkUserDefSession(int ses_count, BYTE bCheck)
{
- char szSessionName[256]={0};
+ char szSessionName[256];
mir_snprintf(szSessionName, SIZEOF(szSessionName), "%s_%u", "FavUserSession", ses_count);
db_set_b(NULL, MODNAME, szSessionName, bCheck);
return 0;
@@ -449,8 +384,8 @@ int MarkUserDefSession(int ses_count,BYTE bCheck) BYTE IsMarkedUserDefSession(int ses_count)
{
- char szSessionName[256]={0};
- mir_snprintf(szSessionName, SIZEOF(szSessionName), "%s_%u","FavUserSession", ses_count);
+ char szSessionName[256];
+ mir_snprintf(szSessionName, SIZEOF(szSessionName), "%s_%u", "FavUserSession", ses_count);
return db_get_b(NULL, MODNAME, szSessionName, 0);
}
@@ -466,11 +401,11 @@ void SavePosition(HWND hwnd, char *wndName) }
void LoadPosition(HWND hWnd, char *wndName)
-{
+{
char buffer[512];
mir_snprintf(buffer, SIZEOF(buffer), "%sPosX", wndName);
- int 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);
- int 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);
}
diff --git a/plugins/Sessions/Src/Utils.h b/plugins/Sessions/Src/Utils.h index 72de9d3c54..ed1a8fd000 100644 --- a/plugins/Sessions/Src/Utils.h +++ b/plugins/Sessions/Src/Utils.h @@ -26,7 +26,7 @@ int GetInSessionOrder(MCONTACT hContact,int mode,int count); void AddSessionMark(MCONTACT hContact,int mode,char bit);
void RemoveSessionMark(MCONTACT hContact,int mode,int marknum);
void SetSessionMark(MCONTACT hContact,int mode,char bit,unsigned int marknum);
-BOOL LoadContactsFromMask(MCONTACT hContact,int mode,int count);
+bool LoadContactsFromMask(MCONTACT hContact, int mode, int count);
int AddToCurSession(MCONTACT hContact, LPARAM lparam);
int DelFromCurSession(MCONTACT hContact,LPARAM lparam);
int CheckForDuplicate(MCONTACT contact_list[], MCONTACT lparam);
diff --git a/plugins/Sessions/Src/Version.h b/plugins/Sessions/Src/Version.h index 8dca096602..6664b4d8e9 100644 --- a/plugins/Sessions/Src/Version.h +++ b/plugins/Sessions/Src/Version.h @@ -1,14 +1,14 @@ -#define __MAJOR_VERSION 0
-#define __MINOR_VERSION 1
+#define __MAJOR_VERSION 0
+#define __MINOR_VERSION 1
#define __RELEASE_NUM 3
-#define __BUILD_NUM 0
+#define __BUILD_NUM 1
#include <stdver.h>
-#define __PLUGIN_NAME "Sessions"
-#define __FILENAME "Sessions.dll"
-#define __DESCRIPTION "Sessions Manager for Miranda NG."
-#define __AUTHOR "MaD_CLuSTeR"
-#define __AUTHOREMAIL "daniok@yandex.ru"
-#define __AUTHORWEB "http://miranda-ng.org/p/Sessions/"
-#define __COPYRIGHT "© 2007-2008 Danil Mozhar"
+#define __PLUGIN_NAME "Sessions"
+#define __FILENAME "Sessions.dll"
+#define __DESCRIPTION "Sessions Manager for Miranda NG."
+#define __AUTHOR "MaD_CLuSTeR"
+#define __AUTHOREMAIL "daniok@yandex.ru"
+#define __AUTHORWEB "http://miranda-ng.org/p/Sessions/"
+#define __COPYRIGHT "© 2007-2008 Danil Mozhar"
|