summaryrefslogtreecommitdiff
path: root/plugins/Sessions
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Sessions')
-rw-r--r--plugins/Sessions/Sessions.vcxproj1
-rw-r--r--plugins/Sessions/Sessions.vcxproj.filters3
-rw-r--r--plugins/Sessions/Src/Import.cpp134
-rw-r--r--plugins/Sessions/Src/LoadSessions.cpp265
-rw-r--r--plugins/Sessions/Src/Main.cpp279
-rw-r--r--plugins/Sessions/Src/Options.cpp60
-rw-r--r--plugins/Sessions/Src/SaveSessions.cpp119
-rw-r--r--plugins/Sessions/Src/Utils.cpp261
-rw-r--r--plugins/Sessions/Src/Utils.h15
-rw-r--r--plugins/Sessions/Src/stdafx.h39
-rw-r--r--plugins/Sessions/Src/version.h4
11 files changed, 542 insertions, 638 deletions
diff --git a/plugins/Sessions/Sessions.vcxproj b/plugins/Sessions/Sessions.vcxproj
index b1a8b267f5..3fcccdfe5e 100644
--- a/plugins/Sessions/Sessions.vcxproj
+++ b/plugins/Sessions/Sessions.vcxproj
@@ -26,6 +26,7 @@
<Import Project="$(ProjectDir)..\..\build\vc.common\plugin.props" />
</ImportGroup>
<ItemGroup>
+ <ClCompile Include="Src\Import.cpp" />
<ClCompile Include="Src\LoadSessions.cpp" />
<ClCompile Include="src\Main.cpp" />
<ClCompile Include="src\Options.cpp" />
diff --git a/plugins/Sessions/Sessions.vcxproj.filters b/plugins/Sessions/Sessions.vcxproj.filters
index b3f50e8d3a..8d68b2540e 100644
--- a/plugins/Sessions/Sessions.vcxproj.filters
+++ b/plugins/Sessions/Sessions.vcxproj.filters
@@ -20,6 +20,9 @@
<ClCompile Include="Src\SaveSessions.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="Src\Import.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\Resource.h">
diff --git a/plugins/Sessions/Src/Import.cpp b/plugins/Sessions/Src/Import.cpp
new file mode 100644
index 0000000000..b7d6cda0ba
--- /dev/null
+++ b/plugins/Sessions/Src/Import.cpp
@@ -0,0 +1,134 @@
+/*
+Copyright (C) 2012-21 Miranda NG team (https://miranda-ng.org)
+
+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 version 2
+of the License.
+
+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, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "stdafx.h"
+
+bool LoadContactsFromMask(MCONTACT hContact, int mode, int count)
+{
+ CMStringA szValue;
+ if (mode == 0)
+ szValue = g_plugin.getMStringA(hContact, "LastSessionsMarks");
+ else if (mode == 1)
+ szValue = g_plugin.getMStringA(hContact, "UserSessionsMarks");
+
+ if (szValue.IsEmpty())
+ return false;
+
+ return szValue[count] == '1';
+}
+
+int GetInSessionOrder(MCONTACT hContact, int mode, int count)
+{
+ char szTemp[3] = { 0, 0, 0 };
+ count *= 2;
+
+ if (mode == 0) {
+ CMStringA szValue(g_plugin.getMStringA(hContact, "LastSessionsOrder"));
+ if (!szValue.IsEmpty() && count < szValue.GetLength()) {
+ memcpy(szTemp, szValue.c_str() + count, 2);
+ return atoi(szTemp);
+ }
+ }
+ else if (mode == 1) {
+ CMStringA szValue(g_plugin.getMStringA(hContact, "UserSessionsOrder"));
+ if (!szValue.IsEmpty() && count < szValue.GetLength()) {
+ memcpy(szTemp, szValue.c_str() + count, 2);
+ return atoi(szTemp);
+ }
+ }
+ return 0;
+}
+
+void CMPlugin::CheckImport()
+{
+ if (db_get_b(0, "Compatibility", MODULENAME) > 0)
+ return;
+
+ MCONTACT tmp[255];
+
+ for (int i = 0;; i++) {
+ char szSetting[100];
+ mir_snprintf(szSetting, "SessionDate_%d", i);
+ CMStringW wszName(getMStringW(szSetting));
+ if (wszName.IsEmpty())
+ break;
+
+ delSetting(szSetting);
+
+ memset(tmp, 0, sizeof(tmp));
+ for (auto &hContact : Contacts()) {
+ if (LoadContactsFromMask(hContact, 0, i)) {
+ int idx = GetInSessionOrder(hContact, 0, i);
+ if (idx < _countof(tmp))
+ tmp[idx] = hContact;
+ }
+ }
+ if (tmp[0] == 0)
+ continue;
+
+ CSession *pNew = new CSession();
+ pNew->id = 255 - i;
+ pNew->wszName = wszName;
+ for (int k = 0; tmp[k]; k++)
+ pNew->contacts.push_back(tmp[k]);
+
+ pNew->save();
+ }
+
+ for (int i = 0;; i++) {
+ char szSetting[100];
+ mir_snprintf(szSetting, "UserSessionDsc_%d", i);
+ CMStringW wszName(getMStringW(szSetting));
+ if (wszName.IsEmpty())
+ break;
+
+ delSetting(szSetting);
+
+ memset(tmp, 0, sizeof(tmp));
+ for (auto &hContact : Contacts()) {
+ if (LoadContactsFromMask(hContact, 1, i)) {
+ int idx = GetInSessionOrder(hContact, 1, i);
+ if (idx < _countof(tmp))
+ tmp[idx] = hContact;
+ }
+ }
+ if (tmp[0] == 0)
+ continue;
+
+ CSession *pNew = new CSession();
+ pNew->id = 255 - i;
+ pNew->bIsUser = true;
+ pNew->wszName = wszName;
+
+ mir_snprintf(szSetting, "FavUserSession_%d", i);
+ pNew->bIsFavorite = getBool(szSetting);
+ delSetting(szSetting);
+
+ for (int k = 0; tmp[k]; k++)
+ pNew->contacts.push_back(tmp[k]);
+
+ pNew->save();
+ }
+
+ delSetting("UserSessionsCount");
+
+ for (auto &hContact : Contacts())
+ db_delete_module(hContact, MODULENAME);
+
+ g_lastDateId = g_lastUserId = 256;
+ db_set_b(0, "Compatibility", MODULENAME, 1);
+}
diff --git a/plugins/Sessions/Src/LoadSessions.cpp b/plugins/Sessions/Src/LoadSessions.cpp
index dcc8e419a3..610a4a5ba4 100644
--- a/plugins/Sessions/Src/LoadSessions.cpp
+++ b/plugins/Sessions/Src/LoadSessions.cpp
@@ -17,154 +17,113 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
-bool g_hghostw, g_bStartup;
+static bool g_bDontShow, g_bStartup;
/////////////////////////////////////////////////////////////////////////////////////////
-INT_PTR CALLBACK LoadSessionDlgProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM)
+class CLoadSessionDlg : public CDlgBase
{
- static int ses_count;
-
- g_hDlg = hdlg;
- switch (msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hdlg);
- {
- int iDelay = g_plugin.getWord("StartupModeDelay", 1500);
- if (g_hghostw == TRUE)
- SetTimer(hdlg, TIMERID_LOAD, iDelay, nullptr);
- 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", g_ses_limit) == 0 && ses_count != 0)
- ses_count = 0;
-
- if (session_list_recovered[0])
- ses_count = 256;
-
- SendDlgItemMessage(hdlg, IDC_LIST, CB_SETCURSEL, 0, 0);
- LoadPosition(hdlg, "LoadDlg");
- if (g_bStartup)
- SetTimer(hdlg, TIMERID_SHOW, iDelay, nullptr);
- else
- ShowWindow(g_hDlg, SW_SHOW);
- }
- }
- break;
-
- case WM_TIMER:
- if (wparam == TIMERID_SHOW) {
- KillTimer(hdlg, TIMERID_SHOW);
- ShowWindow(hdlg, SW_SHOW);
- g_bStartup = FALSE;
- }
- else {
- KillTimer(hdlg, TIMERID_LOAD);
- LoadSession(0, g_bIncompletedSave ? 256 : 0);
- g_hghostw = g_bStartup = FALSE;
- DestroyWindow(hdlg);
- g_hDlg = nullptr;
- }
- break;
-
- case WM_CLOSE:
- SavePosition(hdlg, "LoadDlg");
- DestroyWindow(hdlg);
- g_hDlg = nullptr;
- 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 IDC_SESSDEL:
- if (session_list_recovered[0] && ses_count == 256) {
- for (int i = 0; session_list_recovered[i]; i++)
- g_plugin.setByte(session_list_recovered[i], "wasInLastSession", 0);
-
- memset(session_list_recovered, 0, sizeof(session_list_recovered));
- g_bIncompletedSave = 0;
-
- EnableWindow(GetDlgItem(hdlg, IDC_SESSDEL), FALSE);
- SendDlgItemMessage(hdlg, IDC_LIST, CB_RESETCONTENT, 0, 0);
+ CSession *pSession = nullptr;
+
+ CTimer timerShow, timerLoad;
+ CCtrlCombo m_list;
+ CCtrlButton btnDelete;
+
+public:
+ CLoadSessionDlg() :
+ CDlgBase(g_plugin, IDD_WLCMDIALOG),
+ m_list(this, IDC_LIST),
+ btnDelete(this, IDC_SESSDEL),
+ timerLoad(this, TIMERID_LOAD),
+ timerShow(this, TIMERID_SHOW)
+ {
+ btnDelete.OnClick = Callback(this, &CLoadSessionDlg::onClick_Delete);
+
+ m_list.OnSelChanged = Callback(this, &CLoadSessionDlg::onSelChange_List);
+
+ timerLoad.OnEvent = Callback(this, &CLoadSessionDlg::onTimer_Load);
+ timerShow.OnEvent = Callback(this, &CLoadSessionDlg::onTimer_Show);
+ }
- if ((ses_count = LoadSessionToCombobox(hdlg, 1, g_ses_limit, "SessionDate", 0)) == g_ses_limit)
- EnableWindow(GetDlgItem(hdlg, IDC_SESSDEL), TRUE);
+ bool OnInitDialog() override
+ {
+ g_hDlg = m_hwnd;
- if (LoadSessionToCombobox(hdlg, 1, 255, "UserSessionDsc", g_ses_limit) == 0 && ses_count != 0)
- ses_count = 0;
+ LoadSessionToCombobox(m_list, false);
+ LoadSessionToCombobox(m_list, true);
+ m_list.SetCurSel(0);
+ pSession = (CSession *)m_list.GetItemData(0);
- SendDlgItemMessage(hdlg, IDC_LIST, CB_SETCURSEL, 0, 0);
+ int iDelay = g_plugin.getWord("StartupModeDelay", 1500);
+ if (g_bDontShow == TRUE)
+ timerLoad.Start(iDelay);
+ else {
+ LoadPosition(m_hwnd, "LoadDlg");
+ if (g_bStartup)
+ timerShow.Start(iDelay);
+ else
+ Show();
+ }
- }
- 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);
+ return true;
+ }
- if ((ses_count = LoadSessionToCombobox(hdlg, 0, g_ses_limit, "SessionDate", 0)) == g_ses_limit)
- EnableWindow(GetDlgItem(hdlg, IDC_SESSDEL), TRUE);
+ bool OnApply() override
+ {
+ if (!LoadSession(pSession))
+ return true;
- if (LoadSessionToCombobox(hdlg, 0, 255, "UserSessionDsc", g_ses_limit) == 0 && ses_count != 0)
- ses_count = 0;
+ return false;
+ }
- if (session_list_recovered[0])
- ses_count = 256;
+ void OnDestroy() override
+ {
+ SavePosition(m_hwnd, "LoadDlg");
+ g_hDlg = nullptr;
+ }
- 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);
+ void onTimer_Load(CTimer *pTimer)
+ {
+ pTimer->Stop();
+ LoadSession(pSession);
+ g_bDontShow = g_bStartup = false;
+ Close();
+ }
- if (LoadSessionToCombobox(hdlg, 0, 255, "UserSessionDsc", g_ses_limit) == 0 && ses_count != 0)
- ses_count = 0;
+ void onTimer_Show(CTimer *pTimer)
+ {
+ pTimer->Stop();
+ Show();
+ g_bStartup = FALSE;
+ }
- if (session_list_recovered[0])
- ses_count = 256;
+ void onSelChange_List(CCtrlCombo *)
+ {
+ int index = m_list.GetCurSel();
+ if (index != CB_ERR)
+ pSession = (CSession*)m_list.GetItemData(index);
+ }
- 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 = nullptr;
+ void onClick_Delete(CCtrlButton *)
+ {
+ if (pSession == nullptr) {
+ if (session_list_recovered[0]) {
+ for (int i = 0; session_list_recovered[i]; i++)
+ g_plugin.setByte(session_list_recovered[i], "wasInLastSession", 0);
+ memset(session_list_recovered, 0, sizeof(session_list_recovered));
}
- break;
-
- case IDCANCEL:
- SavePosition(hdlg, "LoadDlg");
- DestroyWindow(hdlg);
- g_hDlg = nullptr;
- break;
+ g_bIncompletedSave = 0;
}
- break;
+ else pSession->remove();
- default:
- return FALSE;
+ m_list.ResetContent();
+ LoadSessionToCombobox(m_list, false);
+ LoadSessionToCombobox(m_list, true);
+
+ m_list.SetCurSel(0);
+ btnDelete.Enable(m_list.GetCount() != 0);
}
- return TRUE;
-}
+};
INT_PTR OpenSessionsManagerWindow(WPARAM, LPARAM)
{
@@ -173,9 +132,8 @@ INT_PTR OpenSessionsManagerWindow(WPARAM, LPARAM)
return 0;
}
- ptrW tszSession(g_plugin.getWStringA("SessionDate_0")), tszUserSession(g_plugin.getWStringA("UserSessionDsc_0"));
- if (g_bIncompletedSave || tszSession || tszUserSession) {
- g_hDlg = CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_WLCMDIALOG), nullptr, LoadSessionDlgProc);
+ if (g_bIncompletedSave || g_arDateSessions.getCount() || g_arUserSessions.getCount()) {
+ (new CLoadSessionDlg())->Create();
return 0;
}
@@ -187,22 +145,24 @@ INT_PTR OpenSessionsManagerWindow(WPARAM, LPARAM)
void CALLBACK LaunchSessions()
{
int startup = g_plugin.getByte("StartupMode", 3);
- if (startup == 1 || (startup == 3 && isLastTRUE == TRUE)) {
- g_bStartup = TRUE;
- g_hDlg = CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_WLCMDIALOG), nullptr, LoadSessionDlgProc);
+ if (startup == 1 || (startup == 3 && g_bLastSessionPresent)) {
+ g_bStartup = true;
+ (new CLoadSessionDlg())->Create();
}
- else if (startup == 2 && isLastTRUE == TRUE) {
- g_hghostw = TRUE;
- g_hDlg = CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_WLCMDIALOG), nullptr, LoadSessionDlgProc);
+ else if (startup == 2 && g_bLastSessionPresent) {
+ g_bDontShow = true;
+ (new CLoadSessionDlg())->Create();
}
}
/////////////////////////////////////////////////////////////////////////////////////////
-INT_PTR LoadLastSession(WPARAM wparam, LPARAM lparam)
+INT_PTR LoadLastSession(WPARAM, LPARAM)
{
- if (isLastTRUE)
- return LoadSession(wparam, lparam);
+ int cnt = g_arDateSessions.getCount();
+ if (g_bLastSessionPresent && cnt)
+ return LoadSession(&g_arDateSessions[cnt-1]);
+
if (g_bOtherWarnings)
MessageBox(nullptr, TranslateT("Last Sessions is empty"), TranslateT("Sessions Manager"), MB_OK);
return 0;
@@ -211,24 +171,19 @@ INT_PTR LoadLastSession(WPARAM wparam, LPARAM lparam)
/////////////////////////////////////////////////////////////////////////////////////////
// Load session dialog
-int LoadSession(WPARAM, LPARAM lparam)
+int LoadSession(CSession *pSession)
{
int dup = 0;
int hidden[255] = { '0' };
- MCONTACT session_list_t[255] = { 0 };
- 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)
+
+ MCONTACT session_list_t[255] = {};
+ if (session_list_recovered[0] && pSession == nullptr)
memcpy(session_list_t, session_list_recovered, sizeof(session_list_t));
- else
- for (auto &hContact : Contacts())
- if (LoadContactsFromMask(hContact, mode, lparam)) {
- int i = GetInSessionOrder(hContact, mode, lparam);
- session_list_t[i] = hContact;
- }
+ else {
+ int i = 0;
+ for (auto &cc : pSession->contacts)
+ session_list_t[i++] = cc;
+ }
int i = 0, j = 0;
// TODO: change to "switch"
diff --git a/plugins/Sessions/Src/Main.cpp b/plugins/Sessions/Src/Main.cpp
index eff26c0035..9bf7a0e20e 100644
--- a/plugins/Sessions/Src/Main.cpp
+++ b/plugins/Sessions/Src/Main.cpp
@@ -21,10 +21,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
HGENMENU hmSaveCurrentSession;
+OBJLIST<CSession> g_arUserSessions(1, NumericKeySortT), g_arDateSessions(1, NumericKeySortT);
+
HANDLE hmTBButton[2], hiTBbutton[2], iTBbutton[2];
int g_ses_limit;
-int g_ses_count;
+int g_lastUserId, g_lastDateId;
+
bool g_bExclHidden;
bool g_bWarnOnHidden;
bool g_bOtherWarnings;
@@ -33,7 +36,7 @@ bool g_bIncompletedSave;
HWND g_hDlg;
bool DONT = false;
-bool isLastTRUE = false;
+bool g_bLastSessionPresent = false;
MCONTACT session_list[255] = { 0 };
MCONTACT session_list_recovered[255];
@@ -59,54 +62,13 @@ PLUGININFOEX pluginInfoEx =
};
CMPlugin::CMPlugin() :
- PLUGIN<CMPlugin>(MODULENAME, pluginInfoEx)
+ PLUGIN<CMPlugin>(MODULENAME, pluginInfoEx),
+ g_lastUserId(MODULENAME, "LastUserId", 0),
+ g_lastDateId(MODULENAME, "LastDateId", 0)
{}
/////////////////////////////////////////////////////////////////////////////////////////
-INT_PTR CALLBACK ExitDlgProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM)
-{
- 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(session_list, false);
- g_plugin.setByte("lastempty", 0);
- DestroyWindow(hdlg);
- break;
-
- case IDCANCEL:
- SavePosition(hdlg, "ExitDlg");
- g_plugin.setByte("lastempty", 1);
- DestroyWindow(hdlg);
- break;
- }
- break;
-
- case WM_CLOSE:
- DestroyWindow(hdlg);
- break;
-
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
-
- default:
- return FALSE;
- }
- return TRUE;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
INT_PTR CloseCurrentSession(WPARAM, LPARAM)
{
while (session_list[0] != 0) {
@@ -119,107 +81,136 @@ INT_PTR CloseCurrentSession(WPARAM, LPARAM)
return 0;
}
-int DelUserDefSession(int ses_count)
+int SessionPreShutdown(WPARAM, LPARAM)
{
- for (auto &hContact : Contacts()) {
- RemoveSessionMark(hContact, 1, ses_count);
- SetInSessionOrder(hContact, 1, ses_count, 0);
- }
-
- char szSessionName[256];
- mir_snprintf(szSessionName, "%s_%u", "UserSessionDsc", ses_count);
- g_plugin.delSetting(szSessionName);
-
- mir_snprintf(szSessionName, "%s_%u", "FavUserSession", ses_count);
- g_plugin.delSetting(szSessionName);
-
- for (int i = ses_count + 1;; i++) {
- mir_snprintf(szSessionName, "%s_%u", "UserSessionDsc", i);
- ptrW szSessionNameBuf(g_plugin.getWStringA(szSessionName));
+ DONT = 1;
- mir_snprintf(szSessionName, "%s_%u", "UserSessionDsc", i - 1);
- if (szSessionNameBuf) {
- MarkUserDefSession(i - 1, IsMarkedUserDefSession(i));
- g_plugin.setWString(szSessionName, szSessionNameBuf);
- }
- else {
- g_plugin.delSetting(szSessionName);
+ if (g_hDlg) DestroyWindow(g_hDlg);
+ if (g_hSDlg) DestroyWindow(g_hSDlg);
- mir_snprintf(szSessionName, "%s_%u", "FavUserSession", i - 1);
- g_plugin.delSetting(szSessionName);
- break;
- }
- }
- g_ses_count--;
- g_plugin.setByte("UserSessionsCount", (BYTE)g_ses_count);
+ g_plugin.setByte("lastSaveCompleted", 1);
return 0;
}
-int DeleteAutoSession(int ses_count)
-{
- for (auto &hContact : Contacts()) {
- RemoveSessionMark(hContact, 0, ses_count);
- SetInSessionOrder(hContact, 0, ses_count, 0);
- }
-
- char szSessionName[256];
- mir_snprintf(szSessionName, "%s_%u", "SessionDate", ses_count);
- g_plugin.delSetting(szSessionName);
-
- for (int i = ses_count + 1;; i++) {
- mir_snprintf(szSessionName, "%s_%u", "SessionDate", i);
- ptrW szSessionNameBuf(g_plugin.getWStringA(szSessionName));
+/////////////////////////////////////////////////////////////////////////////////////////
- mir_snprintf(szSessionName, "%s_%u", "SessionDate", i - 1);
- if (szSessionNameBuf)
- g_plugin.setWString(szSessionName, szSessionNameBuf);
- else {
- g_plugin.delSetting(szSessionName);
- break;
+static void SaveDateSession()
+{
+ if (session_list[0] != 0) {
+ int TimeSize = GetTimeFormat(LOCALE_USER_DEFAULT, 0/*TIME_NOSECONDS*/, nullptr, nullptr, nullptr, 0);
+ ptrW szTimeBuf((wchar_t*)mir_alloc((TimeSize + 1)*sizeof(wchar_t)));
+ GetTimeFormat(LOCALE_USER_DEFAULT, 0/*TIME_NOSECONDS*/, nullptr, nullptr, szTimeBuf, TimeSize);
+
+ int DateSize = GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, nullptr, nullptr, nullptr, 0);
+ ptrW szDateBuf((wchar_t*)mir_alloc((DateSize + 1)*sizeof(wchar_t)));
+ GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, nullptr, nullptr, szDateBuf, DateSize);
+
+ g_plugin.g_lastDateId = g_plugin.g_lastDateId+1;
+
+ CSession data;
+ data.wszName.Format(L"%s - %s", szTimeBuf.get(), szDateBuf.get());
+ for (int i = 0; session_list[i]; i++)
+ data.contacts.push_back(session_list[i]);
+
+ char szSetting[256];
+ mir_snprintf(szSetting, "%s_%d", "SessionDate", int(g_plugin.g_lastDateId));
+ g_plugin.setUString(szSetting, data.toString().c_str());
+
+ while (g_arDateSessions.getCount() >= g_ses_limit) {
+ mir_snprintf(szSetting, "%s_%d", "SessionDate", g_arDateSessions[0].id);
+ g_plugin.delSetting(szSetting);
+ g_arDateSessions.remove(int(0));
}
}
- return 0;
+ if (g_bCrashRecovery)
+ g_plugin.setByte("lastSaveCompleted", 1);
}
-int SessionPreShutdown(WPARAM, LPARAM)
+/////////////////////////////////////////////////////////////////////////////////////////
+// Exit dialog
+
+class CExitDlg : public CDlgBase
{
- DONT = 1;
- if (g_hDlg) DestroyWindow(g_hDlg);
- if (g_hSDlg) DestroyWindow(g_hSDlg);
+public:
+ CExitDlg() :
+ CDlgBase(g_plugin, IDD_EXDIALOG)
+ {}
- g_plugin.setByte("lastSaveCompleted", 1);
- return 0;
-}
+ bool OnInitDialog() override
+ {
+ LoadPosition(m_hwnd, "ExitDlg");
+ return true;
+ }
+
+ bool OnApply() override
+ {
+ SaveDateSession();
+ return true;
+ }
+
+ void OnDestroy() override
+ {
+ SavePosition(m_hwnd, "ExitDlg");
+ g_plugin.setByte("lastempty", 1);
+ PostQuitMessage(0);
+ }
+};
int OkToExit(WPARAM, LPARAM)
{
int exitmode = g_plugin.getByte("ShutdownMode", 2);
DONT = 1;
if (exitmode == 2 && session_list[0] != 0) {
- SaveSessionDate();
- SaveSessionHandles(session_list, false);
+ SaveDateSession();
g_plugin.setByte("lastempty", 0);
}
else if (exitmode == 1 && session_list[0] != 0) {
- DialogBox(g_plugin.getInst(), MAKEINTRESOURCE(IDD_EXDIALOG), nullptr, ExitDlgProc);
+ CExitDlg().DoModal();
}
else g_plugin.setByte("lastempty", 1);
return 0;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
+static void AddToCurSession(MCONTACT hContact)
+{
+ if (CheckForDuplicate(session_list, hContact) == -1) {
+ for (int i = 0;; i++) {
+ if (session_list[i] == 0) {
+ session_list[i] = hContact;
+ break;
+ }
+ }
+ }
+}
+
+static void DelFromCurSession(MCONTACT hContact)
+{
+ for (int i = 0; session_list[i] != 0; i++) {
+ if (session_list[i] == hContact) {
+ while (session_list[i + 1] != 0) {
+ session_list[i] = session_list[i + 1];
+ i++;
+ }
+ session_list[i] = 0;
+ }
+ }
+}
+
static int OnSrmmWindowEvent(WPARAM, LPARAM lParam)
{
MessageWindowEventData *MWeventdata = (MessageWindowEventData*)lParam;
if (MWeventdata->uType == MSG_WINDOW_EVT_OPEN) {
- AddToCurSession(MWeventdata->hContact, 0);
+ AddToCurSession(MWeventdata->hContact);
if (g_bCrashRecovery)
g_plugin.setByte(MWeventdata->hContact, "wasInLastSession", 1);
}
else if (MWeventdata->uType == MSG_WINDOW_EVT_CLOSE) {
if (!DONT)
- DelFromCurSession(MWeventdata->hContact, 0);
+ DelFromCurSession(MWeventdata->hContact);
if (g_bCrashRecovery)
g_plugin.setByte(MWeventdata->hContact, "wasInLastSession", 0);
}
@@ -227,19 +218,36 @@ static int OnSrmmWindowEvent(WPARAM, LPARAM lParam)
return 0;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
INT_PTR BuildFavMenu(WPARAM, LPARAM)
{
POINT pt;
GetCursorPos(&pt);
HMENU hMenu = CreatePopupMenu();
- FillFavoritesMenu(hMenu, g_ses_count);
+ for (auto &it: g_arUserSessions)
+ if (it->bIsFavorite)
+ AppendMenu(hMenu, MF_STRING, it->id + 1, it->wszName);
+
+ if (GetMenuItemCount(hMenu) == 0) {
+ DestroyMenu(hMenu);
+ return 2;
+ }
+
int res = TrackPopupMenu(hMenu, TPM_RETURNCMD | TPM_NONOTIFY, pt.x, pt.y, 0, GetActiveWindow(), nullptr);
- if (res == 0) return 1;
- LoadSession(0, (res - 1) + g_ses_limit);
+ if (res == 0)
+ return 1;
+
+ res--;
+ if (auto *pSession = g_arUserSessions.find((CSession*)&res))
+ LoadSession(pSession);
return 0;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+// Toolbar initialization
+
static int CreateButtons(WPARAM, LPARAM)
{
TTBButton ttb = {};
@@ -267,7 +275,9 @@ static int CreateButtons(WPARAM, LPARAM)
return 0;
}
-static int PluginInit(WPARAM, LPARAM)
+/////////////////////////////////////////////////////////////////////////////////////////
+
+static int OnModulesLoaded(WPARAM, LPARAM)
{
HookEvent(ME_MSG_WINDOWEVENT, OnSrmmWindowEvent);
HookEvent(ME_TTB_MODULELOADED, CreateButtons);
@@ -340,23 +350,52 @@ static IconItem iconList[] =
{ LPGEN("Load last Session"), "SessionsLoadLast", IDD_SESSIONS_LOADLAST }
};
+int LoadSettings(const char *szSetting, void *)
+{
+ if (!memcmp(szSetting, "SessionUser_", 12)) {
+ auto *pSession = new CSession();
+ pSession->id = atoi(szSetting + 12);
+ pSession->fromString(ptrA(db_get_utfa(0, MODULENAME, szSetting)));
+ g_arUserSessions.insert(pSession);
+ }
+ else if (!memcmp(szSetting, "SessionDate_", 12)) {
+ auto *pSession = new CSession();
+ pSession->id = atoi(szSetting + 12);
+ pSession->fromString(ptrA(db_get_utfa(0, MODULENAME, szSetting)));
+ g_arDateSessions.insert(pSession);
+ }
+
+ return 0;
+}
+
int CMPlugin::Load()
{
+ // Icons
+ g_plugin.registerIcon(MODULENAME, iconList);
+
+ // Services
CreateServiceFunction(MS_SESSIONS_SHOWFAVORITESMENU, BuildFavMenu);
CreateServiceFunction(MS_SESSIONS_OPENMANAGER, OpenSessionsManagerWindow);
CreateServiceFunction(MS_SESSIONS_RESTORELASTSESSION, LoadLastSession);
CreateServiceFunction(MS_SESSIONS_SAVEUSERSESSION, SaveUserSessionHandles);
CreateServiceFunction(MS_SESSIONS_CLOSESESSION, CloseCurrentSession);
+ // Events
+ HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
+ HookEvent(ME_SYSTEM_OKTOEXIT, OkToExit);
+ HookEvent(ME_SYSTEM_PRESHUTDOWN, SessionPreShutdown);
+ HookEvent(ME_OPT_INITIALISE, OptionsInit);
+
Miranda_WaitOnHandle(LaunchSessions);
- g_ses_count = g_plugin.getByte("UserSessionsCount", 0);
+ // Settimgs
g_ses_limit = g_plugin.getByte("TrackCount", 10);
g_bExclHidden = g_plugin.getByte("ExclHidden", 0) != 0;
g_bWarnOnHidden = g_plugin.getByte("WarnOnHidden", 0) != 0;
g_bOtherWarnings = g_plugin.getByte("OtherWarnings", 1) != 0;
g_bCrashRecovery = g_plugin.getByte("CrashRecovery", 0) != 0;
+ // Crash recovery
if (g_bCrashRecovery)
g_bIncompletedSave = g_plugin.getByte("lastSaveCompleted", 0) == 0;
@@ -375,14 +414,12 @@ int CMPlugin::Load()
g_plugin.setByte("lastSaveCompleted", 0);
if (!g_plugin.getByte("lastempty", 1) || g_bIncompletedSave)
- isLastTRUE = true;
+ g_bLastSessionPresent = true;
- HookEvent(ME_SYSTEM_MODULESLOADED, PluginInit);
- HookEvent(ME_SYSTEM_OKTOEXIT, OkToExit);
- HookEvent(ME_SYSTEM_PRESHUTDOWN, SessionPreShutdown);
- HookEvent(ME_OPT_INITIALISE, OptionsInit);
+ // Check for old settings
+ CheckImport();
- // Icons
- g_plugin.registerIcon(MODULENAME, iconList);
+ // Load settings data
+ db_enum_settings(0, LoadSettings, MODULENAME);
return 0;
}
diff --git a/plugins/Sessions/Src/Options.cpp b/plugins/Sessions/Src/Options.cpp
index e9cd47ea53..9188c7e817 100644
--- a/plugins/Sessions/Src/Options.cpp
+++ b/plugins/Sessions/Src/Options.cpp
@@ -27,11 +27,9 @@ HWND hComboBoxEdit = nullptr;
HWND hOpClistControl = nullptr;
-int iSessionId;
+CSession *pSession = nullptr;
BOOL bSesssionNameChanged = 0;
-MCONTACT session_list_t[255] = { 0 };
-
BOOL bChecked = FALSE;
static LRESULT CALLBACK ComboBoxSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
@@ -71,17 +69,18 @@ static LRESULT CALLBACK ComboBoxSubclassProc(HWND hwnd, UINT msg, WPARAM wParam,
case WM_NCLBUTTONDBLCLK:
case WM_NCLBUTTONDOWN:
if (!bChecked) {
- MarkUserDefSession(iSessionId, 1);
+ pSession->bIsFavorite = true;
hIcon = hMarked;
bChecked = TRUE;
RedrawWindow(hwnd, nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW | RDW_FRAME);
}
else {
- MarkUserDefSession(iSessionId, 0);
+ pSession->bIsFavorite = false;
hIcon = hNotMarked;
bChecked = FALSE;
RedrawWindow(hwnd, nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW | RDW_FRAME);
}
+ pSession->save();
break;
case WM_MOUSEMOVE:
@@ -127,16 +126,9 @@ class COptionsDlg : public CDlgBase
{
memset(session_list_t, 0, sizeof(session_list_t));
- for (auto &hContact : Contacts()) {
- if (LoadContactsFromMask(hContact, 1, iSessionId)) {
- int i = GetInSessionOrder(hContact, 1, iSessionId);
- session_list_t[i] = hContact;
- }
- }
-
- int i;
- for (i = 0; session_list_t[i] != 0; i++)
- m_opclist.AddString(Clist_GetContactDisplayName(session_list_t[i]));
+ int i = 0;
+ for (auto &cc : pSession->contacts)
+ m_opclist.AddString(Clist_GetContactDisplayName(session_list_t[i++] = cc));
return i;
}
@@ -149,6 +141,8 @@ class COptionsDlg : public CDlgBase
CCtrlCheck chkExitAsk, chkExitSave, chkExitNothing;
CCtrlButton btnSave, btnEdit, btnDel;
+ MCONTACT session_list_t[255];
+
public:
COptionsDlg() :
CDlgBase(g_plugin, IDD_OPTIONS),
@@ -179,8 +173,11 @@ public:
chkExitNothing.OnChange = Callback(this, &COptionsDlg::onChange_ExNothing);
m_list.OnChange = Callback(this, &COptionsDlg::onEditChange_List);
+ m_list.OnSelChanged = Callback(this, &COptionsDlg::onSelChange_List);
m_clist.OnCheckChanged = Callback(this, &COptionsDlg::onCheckChanged_Clist);
+
+ memset(session_list_t, 0, sizeof(session_list_t));
}
bool OnInitDialog() override
@@ -188,7 +185,7 @@ public:
COMBOBOXINFO cbi = { 0 };
cbi.cbSize = sizeof(cbi);
- iSessionId = 0;
+ pSession = nullptr;
hMarked = g_plugin.getIcon(IDD_SESSION_CHECKED);
hNotMarked = g_plugin.getIcon(IDD_SESSION_UNCHECKED);
@@ -197,8 +194,6 @@ public:
m_clist.SetExStyle(CLS_EX_DISABLEDRAGDROP | CLS_EX_TRACKSELECT);
m_clist.AutoRebuild();
- hIcon = (bChecked = IsMarkedUserDefSession(iSessionId)) ? hMarked : hNotMarked;
-
SetDlgItemInt(m_hwnd, IDC_TRACK, g_ses_limit = g_plugin.getByte("TrackCount", 10), FALSE);
SendDlgItemMessage(m_hwnd, IDC_SPIN1, UDM_SETRANGE, 0, MAKELONG(10, 1));
SendDlgItemMessage(m_hwnd, IDC_SPIN1, UDM_SETPOS, 0, GetDlgItemInt(m_hwnd, IDC_TRACK, nullptr, FALSE));
@@ -236,10 +231,11 @@ public:
else if (exitmode == 2)
chkExitSave.SetState(true);
- LoadSessionToCombobox(m_hwnd, 1, 255, "UserSessionDsc", 0);
+ LoadSessionToCombobox(m_list, true);
if (m_list.GetCount()) {
btnEdit.Enable();
m_list.SetCurSel(0);
+ pSession = (CSession *)m_list.GetItemData(0);
if (!LoadSessionContacts())
btnDel.Disable();
}
@@ -328,9 +324,9 @@ public:
if (index == CB_ERR)
return;
- iSessionId = m_list.GetItemData(index);
+ pSession = (CSession*)m_list.GetItemData(index);
m_opclist.ResetContent();
- if (IsMarkedUserDefSession(iSessionId)) {
+ if (pSession->bIsFavorite) {
hIcon = hMarked;
bChecked = TRUE;
RedrawWindow(hComboBoxEdit, nullptr, nullptr, RDW_INVALIDATE | RDW_NOCHILDREN | RDW_UPDATENOW | RDW_FRAME);
@@ -379,26 +375,21 @@ public:
void onClick_Save(CCtrlButton *)
{
- int i = 0;
for (auto &hContact : Contacts()) {
BYTE res = m_clist.GetCheck(m_clist.FindContact(hContact));
if (res) {
- SetSessionMark(hContact, 1, '1', iSessionId);
- SetInSessionOrder(hContact, 1, iSessionId, i);
- i++;
- }
- else {
- SetSessionMark(hContact, 1, '0', iSessionId);
- SetInSessionOrder(hContact, 1, iSessionId, 0);
+ // !!!!!!!!!!!!!!!!!!!
}
}
if (bSesssionNameChanged) {
if (GetWindowTextLength(hComboBoxEdit)) {
wchar_t szUserSessionName[MAX_PATH] = { '\0' };
GetWindowText(hComboBoxEdit, szUserSessionName, _countof(szUserSessionName));
- RenameUserDefSession(iSessionId, szUserSessionName);
+ pSession->wszName = szUserSessionName;
+ pSession->save();
+
m_list.ResetContent();
- LoadSessionToCombobox(m_hwnd, 1, 255, "UserSessionDsc", 0);
+ LoadSessionToCombobox(m_list, true);
}
bSesssionNameChanged = FALSE;
}
@@ -408,14 +399,12 @@ public:
void onClick_Del(CCtrlButton *)
{
- DelUserDefSession(iSessionId);
+ pSession->remove();
m_opclist.ResetContent();
m_list.ResetContent();
- LoadSessionToCombobox(m_hwnd, 1, 255, "UserSessionDsc", 0);
-
- iSessionId = 0;
+ LoadSessionToCombobox(m_list, true);
if (m_list.GetCount()) {
btnEdit.Enable();
@@ -424,6 +413,7 @@ public:
btnDel.Disable();
}
else {
+ pSession = nullptr;
btnEdit.Disable();
btnDel.Disable();
}
diff --git a/plugins/Sessions/Src/SaveSessions.cpp b/plugins/Sessions/Src/SaveSessions.cpp
index 04f7bb155e..457b224c21 100644
--- a/plugins/Sessions/Src/SaveSessions.cpp
+++ b/plugins/Sessions/Src/SaveSessions.cpp
@@ -23,101 +23,36 @@ bool bSC = false;
/////////////////////////////////////////////////////////////////////////////////////////
-int SaveSessionDate()
+static int SaveUserSessionName(MCONTACT *contacts, wchar_t *szUSessionName)
{
- if (session_list[0] != 0) {
- int TimeSize = GetTimeFormat(LOCALE_USER_DEFAULT, 0/*TIME_NOSECONDS*/, nullptr, nullptr, nullptr, 0);
- wchar_t *szTimeBuf = (wchar_t*)mir_alloc((TimeSize + 1)*sizeof(wchar_t));
-
- GetTimeFormat(LOCALE_USER_DEFAULT, 0/*TIME_NOSECONDS*/, nullptr, nullptr, szTimeBuf, TimeSize);
-
- int DateSize = GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, nullptr, nullptr, nullptr, 0);
- wchar_t *szDateBuf = (wchar_t*)mir_alloc((DateSize + 1)*sizeof(wchar_t));
-
- GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, nullptr, nullptr, szDateBuf, DateSize);
- int lenn = (DateSize + TimeSize + 5);
- wchar_t *szSessionTime = (wchar_t*)mir_alloc(lenn*sizeof(wchar_t));
- mir_snwprintf(szSessionTime, lenn, L"%s - %s", szTimeBuf, szDateBuf);
-
- char szSetting[256];
- mir_snprintf(szSetting, "%s_%d", "SessionDate", 0);
- wchar_t *ptszSaveSessionDate = g_plugin.getWStringA(szSetting);
-
- g_plugin.setWString(szSetting, szSessionTime);
- mir_free(szSessionTime);
-
- if (ptszSaveSessionDate)
- ResaveSettings("SessionDate", 1, g_ses_limit, ptszSaveSessionDate);
-
- if (szTimeBuf)
- mir_free(szTimeBuf);
- if (szDateBuf)
- mir_free(szDateBuf);
- }
-
- if (g_bCrashRecovery)
- g_plugin.setByte("lastSaveCompleted", 1);
- return 0;
-}
-
-static int SaveUserSessionName(MCONTACT *pSession, wchar_t *szUSessionName)
-{
- if (pSession[0] == 0)
+ if (contacts[0] == 0)
return 1;
- char szSetting[256];
- mir_snprintf(szSetting, "%s_%u", "UserSessionDsc", 0);
- wchar_t *ptszUserSessionName = g_plugin.getWStringA(szSetting);
- if (ptszUserSessionName)
- ResaveSettings("UserSessionDsc", 1, 255, ptszUserSessionName);
-
- g_plugin.setWString(szSetting, szUSessionName);
- return 0;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
-static void AddInSessionOrder(MCONTACT hContact, int mode, int ordernum, int writemode)
-{
- char buf[100];
- mir_snprintf(buf, "%02u", ordernum);
-
- if (mode == 0) {
- CMStringA szValue(g_plugin.getMStringA(hContact, "LastSessionsOrder"));
- if (writemode == 0 && szValue.IsEmpty())
- return;
-
- szValue.Insert(0, buf);
- szValue.Truncate(g_ses_limit * 2);
- g_plugin.setString(hContact, "LastSessionsOrder", szValue);
+ CSession *pSession = nullptr;
+ for (auto &it : g_arUserSessions)
+ if (!it->wszName.CompareNoCase(szUSessionName))
+ pSession = it;
+
+ if (pSession)
+ pSession->contacts.clear();
+ else {
+ g_plugin.g_lastUserId = g_plugin.g_lastUserId + 1;
+
+ pSession = new CSession();
+ pSession->id = g_plugin.g_lastUserId;
+ pSession->bIsUser = true;
+ pSession->wszName = szUSessionName;
+ g_arUserSessions.insert(pSession);
}
- else if (mode == 1) {
- CMStringA szValue(g_plugin.getMStringA(hContact, "UserSessionsOrder"));
- szValue.Insert(0, buf);
- szValue.Truncate(g_ses_count * 2);
- g_plugin.setString(hContact, "UserSessionsOrder", szValue);
- }
-}
-int SaveSessionHandles(MCONTACT *pSession, bool bNewSession)
-{
- if (pSession[0] == 0)
- return 1;
+ for (int i = 0; contacts[i]; i++)
+ pSession->contacts.push_back(contacts[i]);
- int k = 0;
- for (auto &hContact : Contacts()) {
- if ((k = CheckForDuplicate(pSession, hContact)) != -1 && !(g_bExclHidden && !CheckContactVisibility(hContact))) {
- AddSessionMark(hContact, bNewSession, '1');
- AddInSessionOrder(hContact, bNewSession, k, 1);
- }
- else {
- AddSessionMark(hContact, bNewSession, '0');
- AddInSessionOrder(hContact, bNewSession, 0, 0);
- }
- }
- if (bNewSession) {
- g_ses_count++;
- g_plugin.setByte("UserSessionsCount", (BYTE)g_ses_count);
+ pSession->save();
+
+ while (g_arUserSessions.getCount() > g_ses_limit) {
+ g_arUserSessions[0].remove();
+ g_arUserSessions.remove(int(0));
}
return 0;
}
@@ -151,7 +86,7 @@ public:
bool OnInitDialog() override
{
g_hSDlg = m_hwnd;
- LoadSessionToCombobox(m_hwnd, 1, 5, "UserSessionDsc", 0);
+ LoadSessionToCombobox(m_sessions, true);
SetWindowLongPtr(m_clist.GetHwnd(), GWL_STYLE,
GetWindowLongPtr(m_clist.GetHwnd(), GWL_STYLE) | CLS_CHECKBOXES | CLS_HIDEEMPTYGROUPS | CLS_USEGROUPS | CLS_GREYALTERNATE | CLS_GROUPCHECKBOXES);
@@ -166,6 +101,7 @@ public:
{
wchar_t szUserSessionName[MAX_PATH];
m_sessions.GetText(szUserSessionName, _countof(szUserSessionName));
+ rtrimw(szUserSessionName);
if (szUserSessionName[0] == 0) {
MessageBox(nullptr, TranslateT("Session name is empty, enter the name and try again"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING);
return false;
@@ -181,14 +117,11 @@ public:
}
}
- SaveSessionHandles(user_session_list, true);
SaveUserSessionName(user_session_list, szUserSessionName);
return true;
}
if (!SaveUserSessionName(session_list, szUserSessionName)) {
- SaveSessionHandles(session_list, true);
-
if (chkSaveAndClose.IsChecked())
CloseCurrentSession(0, 0);
return true;
diff --git a/plugins/Sessions/Src/Utils.cpp b/plugins/Sessions/Src/Utils.cpp
index 54a3d90e08..13e980d770 100644
--- a/plugins/Sessions/Src/Utils.cpp
+++ b/plugins/Sessions/Src/Utils.cpp
@@ -19,235 +19,91 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
-void AddSessionMark(MCONTACT hContact, int mode, char bit)
+void CSession::fromString(const char *str)
{
- if (mode == 0) {
- CMStringA szValue(g_plugin.getMStringA(hContact, "LastSessionsMarks"));
- if (bit == '0' && szValue.IsEmpty())
- return;
+ JSONNode root = JSONNode::parse(str);
+ if (!root)
+ return;
- szValue.Insert(0, bit);
- szValue.Truncate(g_ses_limit);
- g_plugin.setString(hContact, "LastSessionsMarks", szValue);
- }
- else if (mode == 1) {
- CMStringA szValue(g_plugin.getMStringA(hContact, "UserSessionsMarks"));
- szValue.Insert(0, bit);
- szValue.Truncate((int)g_ses_count);
- g_plugin.setString(hContact, "UserSessionsMarks", szValue);
- }
-}
+ wszName = root["n"].as_mstring();
+ bIsUser = root["u"].as_int() != 0;
+ bIsFavorite = root["f"].as_int() != 0;
-void RemoveSessionMark(MCONTACT hContact, int mode, int marknum)
-{
- if (mode == 0) {
- CMStringA szValue(g_plugin.getMStringA(hContact, "LastSessionsMarks"));
- if (!szValue.IsEmpty() && marknum < szValue.GetLength()) {
- szValue.Delete(marknum, 1);
- g_plugin.setString(hContact, "LastSessionsMarks", szValue);
- }
- }
- else if (mode == 1) {
- CMStringA szValue(g_plugin.getMStringA(hContact, "UserSessionsMarks"));
- if (!szValue.IsEmpty() && marknum < szValue.GetLength()) {
- szValue.Delete(marknum, 1);
- g_plugin.setString(hContact, "UserSessionsMarks", szValue);
- }
- }
+ for (auto &mm : root["m"])
+ contacts.push_back(mm.as_int());
}
-void SetSessionMark(MCONTACT hContact, int mode, char bit, int marknum)
+CMStringA CSession::getSetting() const
{
- if (mode == 0) {
- CMStringA szValue(g_plugin.getMStringA(hContact, "LastSessionsMarks"));
- if (!szValue.IsEmpty() && marknum < szValue.GetLength()) {
- szValue.SetAt(marknum, bit);
- g_plugin.setString(hContact, "LastSessionsMarks", szValue);
- }
- }
- else if (mode == 1) {
- CMStringA szValue(g_plugin.getMStringA(hContact, "UserSessionsMarks"));
- if (!szValue.IsEmpty() && marknum < szValue.GetLength()) {
- szValue.SetAt(marknum, bit);
- g_plugin.setString(hContact, "UserSessionsMarks", szValue);
- }
- }
+ if (bIsUser)
+ return CMStringA(FORMAT, "SessionUser_%d", id);
+
+ return CMStringA(FORMAT, "SessionDate_%d", id);
}
-bool LoadContactsFromMask(MCONTACT hContact, int mode, int count)
+void CSession::remove()
{
- CMStringA szValue;
- if (mode == 0)
- szValue = g_plugin.getMStringA(hContact, "LastSessionsMarks");
- else if (mode == 1)
- szValue = g_plugin.getMStringA(hContact, "UserSessionsMarks");
-
- if (szValue.IsEmpty())
- return false;
+ g_plugin.delSetting(getSetting());
- return szValue[count] == '1';
+ if (bIsUser)
+ g_arUserSessions.remove(this);
+ else
+ g_arDateSessions.remove(this);
}
-int GetInSessionOrder(MCONTACT hContact, int mode, int count)
+void CSession::save()
{
- char szTemp[3] = { 0, 0, 0 };
- count *= 2;
-
- if (mode == 0) {
- CMStringA szValue(g_plugin.getMStringA(hContact, "LastSessionsOrder"));
- if (!szValue.IsEmpty() && count < szValue.GetLength()) {
- memcpy(szTemp, szValue.c_str() + count, 2);
- return atoi(szTemp);
- }
- }
- else if (mode == 1) {
- CMStringA szValue(g_plugin.getMStringA(hContact, "UserSessionsOrder"));
- if (!szValue.IsEmpty() && count < szValue.GetLength()) {
- memcpy(szTemp, szValue.c_str() + count, 2);
- return atoi(szTemp);
- }
- }
- return 0;
+ g_plugin.setUString(getSetting(), toString().c_str());
}
-void SetInSessionOrder(MCONTACT hContact, int mode, int count, int ordernum)
+std::string CSession::toString() const
{
- char szTemp[3];
- mir_snprintf(szTemp, "%02u", ordernum);
- count *= 2;
+ JSONNode members(JSON_ARRAY); members.set_name("m");
+ for (auto &cc : contacts)
+ members.push_back(JSONNode("", int(cc)));
- if (mode == 0) {
- CMStringA szValue(g_plugin.getMStringA(hContact, "LastSessionsOrder"));
- if (!szValue.IsEmpty() && count < szValue.GetLength()) {
- szValue.SetAt(count, szTemp[0]);
- szValue.SetAt(count + 1, szTemp[1]);
- g_plugin.setString(hContact, "LastSessionsOrder", szValue);
- }
- }
- else if (mode == 1) {
- CMStringA szValue(g_plugin.getMStringA(hContact, "UserSessionsOrder"));
- if (!szValue.IsEmpty() && count < szValue.GetLength()) {
- szValue.SetAt(count, szTemp[0]);
- szValue.SetAt(count + 1, szTemp[1]);
- g_plugin.setString(hContact, "UserSessionsOrder", szValue);
- }
- }
+ JSONNode root;
+ root << WCHAR_PARAM("n", wszName) << INT_PARAM("f", bIsFavorite) << INT_PARAM("u", bIsUser) << members;
+ return root.write();
}
-BOOL ResaveSettings(char *szName, int iFirst, int iLimit, wchar_t *szBuffer)
-{
- for (int i = iFirst; i < iLimit; i++) {
- if (szBuffer == nullptr)
- break;
-
- char szNameBuf[256];
- mir_snprintf(szNameBuf, "%s_%u", szName, i);
-
- wchar_t *ptszTemp = g_plugin.getWStringA(szNameBuf);
- g_plugin.setWString(szNameBuf, szBuffer);
- mir_free(szBuffer);
+/////////////////////////////////////////////////////////////////////////////////////////
- BYTE marked = IsMarkedUserDefSession(i);
- MarkUserDefSession(i, (BYTE)((i == iFirst) ? IsMarkedUserDefSession(iFirst - 1) : marked));
-
- if (ptszTemp == nullptr) // read failed
- return 0;
-
- szBuffer = ptszTemp;
- }
-
- mir_free(szBuffer);
- return 1;
-}
-
-int AddToCurSession(MCONTACT wparam, LPARAM)
+void DeleteAutoSession(CSession *pSession)
{
- if (CheckForDuplicate(session_list, wparam) == -1) {
- for (int i = 0;; i++) {
- if (session_list[i] == 0) {
- session_list[i] = wparam;
- break;
- }
- }
- }
- return 0;
-}
+ char szSessionName[256];
+ mir_snprintf(szSessionName, "%s_%u", "SessionDate", pSession->id);
+ g_plugin.delSetting(szSessionName);
-int DelFromCurSession(MCONTACT wparam, LPARAM)
-{
- 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;
- }
- }
- return 0;
+ g_arDateSessions.remove(pSession);
}
-int CheckForDuplicate(MCONTACT contact_list[], MCONTACT lparam)
+/////////////////////////////////////////////////////////////////////////////////////////
+
+int CheckForDuplicate(MCONTACT *contact_list, MCONTACT hContact)
{
- MCONTACT s_list[255] = { 0 };
- memcpy(s_list, contact_list, sizeof(s_list));
for (int i = 0;; i++) {
- if (s_list[i] == lparam)
+ if (contact_list[i] == hContact)
return i;
- if (s_list[i] == 0)
+ if (contact_list[i] == 0)
return -1;
}
}
-int LoadSessionToCombobox(HWND hdlg, BOOL mode, int iLimit, char* pszSetting, int iFirstNum)
-{
- 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, 256);
- }
-
- for (int i = 0; i < iLimit; i++) {
- mir_snprintf(szBuffer, "%s_%u", pszSetting, i);
- wchar_t *pszBuffer = g_plugin.getWStringA(szBuffer);
- if (pszBuffer) {
- 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);
- }
- else {
- SendDlgItemMessage(hdlg, IDC_LIST, CB_INSERTSTRING, 0, (LPARAM)pszBuffer);
- SendDlgItemMessage(hdlg, IDC_LIST, CB_SETITEMDATA, 0, i + iFirstNum);
- }
- mir_free(pszBuffer);
- }
- else {
- if (i == 0) ses_count = iLimit - iFirstNum;
- break;
- }
- }
+/////////////////////////////////////////////////////////////////////////////////////////
- return ses_count;
-}
-
-int FillFavoritesMenu(HMENU hMenu, int iLimit)
+void LoadSessionToCombobox(CCtrlCombo &combo, bool bUser)
{
- int iItems = 0;
+ if (session_list_recovered[0] && !bUser)
+ combo.AddString(TranslateT("Session Before Last Crash"), 0);
- for (int i = 0; i < iLimit; i++) {
- if (IsMarkedUserDefSession(i)) {
- char szBuffer[256];
- mir_snprintf(szBuffer, "%s_%u", "UserSessionDsc", i);
- wchar_t *pszBuffer = g_plugin.getWStringA(szBuffer);
- if (pszBuffer) {
- AppendMenu(hMenu, MF_STRING, i + 1, pszBuffer);
- iItems++;
- mir_free(pszBuffer);
- }
- }
+ auto &pList = (bUser) ? g_arUserSessions : g_arDateSessions;
+ for (auto &it : pList) {
+ if (it->bIsFavorite || bUser)
+ combo.AddString(it->wszName, LPARAM(it));
+ else
+ combo.InsertString(it->wszName, 0, LPARAM(it));
}
- return iItems;
}
void OffsetWindow(HWND parent, HWND hwnd, int dx, int dy)
@@ -273,25 +129,10 @@ int CheckContactVisibility(MCONTACT hContact)
void RenameUserDefSession(int ses_count, wchar_t* ptszNewName)
{
char szSession[256];
- mir_snprintf(szSession, "%s_%u", "UserSessionDsc", ses_count);
+ mir_snprintf(szSession, "%s_%u", "SessionUser", ses_count);
g_plugin.setWString(szSession, ptszNewName);
}
-int MarkUserDefSession(int ses_count, BYTE bCheck)
-{
- char szSessionName[256];
- mir_snprintf(szSessionName, "%s_%u", "FavUserSession", ses_count);
- g_plugin.setByte(szSessionName, bCheck);
- return 0;
-}
-
-BYTE IsMarkedUserDefSession(int ses_count)
-{
- char szSessionName[256];
- mir_snprintf(szSessionName, "%s_%u", "FavUserSession", ses_count);
- return g_plugin.getByte(szSessionName, 0);
-}
-
void SavePosition(HWND hwnd, char *wndName)
{
RECT rc;
diff --git a/plugins/Sessions/Src/Utils.h b/plugins/Sessions/Src/Utils.h
index 741dbf7e0b..6870de94bb 100644
--- a/plugins/Sessions/Src/Utils.h
+++ b/plugins/Sessions/Src/Utils.h
@@ -20,24 +20,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef __UTILS_H__
# define __UTILS_H__
-void SetInSessionOrder(MCONTACT hContact, int mode, int count, int ordernum);
-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, int marknum);
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);
-BOOL ResaveSettings(char *szName, int iFirst, int iLimit, wchar_t *pszPrevSetting);
+int CheckForDuplicate(MCONTACT *contact_list, MCONTACT lparam);
void OffsetWindow(HWND parent, HWND hwnd, int dx, int dy);
-int LoadSessionToCombobox(HWND hdlg, BOOL mode, int iLimit, char *pszSetting, int iFirstNum);
-int MarkUserDefSession(int ses_count, BYTE bCheck);
-BYTE IsMarkedUserDefSession(int ses_count);
+void LoadSessionToCombobox(CCtrlCombo &combo, bool bUser);
void SavePosition(HWND hWnd, char *wndName);
void LoadPosition(HWND hWnd, char *wndName);
int CheckContactVisibility(MCONTACT hContact);
void RenameUserDefSession(int ses_count, wchar_t *ptszNewName);
-int FillFavoritesMenu(HMENU hMenu, int iLimit);
#endif // __UTILS_H__ \ No newline at end of file
diff --git a/plugins/Sessions/Src/stdafx.h b/plugins/Sessions/Src/stdafx.h
index ed54517b8b..7271cd5f9e 100644
--- a/plugins/Sessions/Src/stdafx.h
+++ b/plugins/Sessions/Src/stdafx.h
@@ -25,6 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <commctrl.h>
#include <malloc.h>
+#include <vector>
#include <newpluginapi.h>
#include <m_clc.h>
@@ -32,6 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <m_contacts.h>
#include <m_hotkeys.h>
#include <m_icolib.h>
+#include <m_json.h>
#include <m_langpack.h>
#include <m_message.h>
#include <m_metacontacts.h>
@@ -50,18 +52,38 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
struct CMPlugin : public PLUGIN<CMPlugin>
{
+ CMOption<int> g_lastUserId, g_lastDateId;
+
CMPlugin();
+ void CheckImport();
+
int Load() override;
};
-#define MIIM_STRING 0x00000040
+/////////////////////////////////////////////////////////////////////////////////////////
+
+struct CSession
+{
+ int id;
+ CMStringW wszName;
+ std::vector<MCONTACT> contacts;
+ bool bIsFavorite = false, bIsUser = false;
+
+ void fromString(const char *str);
+ std::string toString() const;
+
+ CMStringA getSetting() const;
+ void remove();
+ void save();
+};
+
+extern OBJLIST<CSession> g_arUserSessions, g_arDateSessions;
+
+/////////////////////////////////////////////////////////////////////////////////////////
-int DelUserDefSession(int ses_count);
-int DeleteAutoSession(int ses_count);
-int LoadSession(WPARAM, LPARAM);
-int SaveSessionHandles(MCONTACT *pSession, bool bNewSession);
-int SaveSessionDate();
+int LoadSession(CSession *pSession);
+int SaveSessionHandles(MCONTACT *pSession, bool bNewSession);
void CALLBACK LaunchSessions();
@@ -74,9 +96,8 @@ extern MCONTACT session_list_recovered[255];
extern MCONTACT session_list[255];
extern HWND g_hDlg, g_hSDlg;
-extern int g_ses_limit;
-extern int g_ses_count;
-extern bool isLastTRUE;
+extern int g_ses_limit;
+extern bool g_bLastSessionPresent;
extern bool g_bExclHidden;
extern bool g_bWarnOnHidden;
extern bool g_bOtherWarnings;
diff --git a/plugins/Sessions/Src/version.h b/plugins/Sessions/Src/version.h
index 76ee24f1e2..0043e585bb 100644
--- a/plugins/Sessions/Src/version.h
+++ b/plugins/Sessions/Src/version.h
@@ -1,6 +1,6 @@
#define __MAJOR_VERSION 0
-#define __MINOR_VERSION 1
-#define __RELEASE_NUM 4
+#define __MINOR_VERSION 2
+#define __RELEASE_NUM 0
#define __BUILD_NUM 1
#include <stdver.h>