diff options
author | dartraiden <wowemuh@gmail.com> | 2023-01-02 21:10:29 +0300 |
---|---|---|
committer | dartraiden <wowemuh@gmail.com> | 2023-01-02 21:10:29 +0300 |
commit | 1979fd80424d16b2e489f9b57d01d9c7811d25a2 (patch) | |
tree | 960d42c5fe4a51f0fe2850bea91256e226bce221 /plugins/Sessions | |
parent | adfbbb217d4f4a05acf198755f219a5223d31c27 (diff) |
Update copyrights
Diffstat (limited to 'plugins/Sessions')
-rw-r--r-- | plugins/Sessions/Src/Import.cpp | 268 | ||||
-rw-r--r-- | plugins/Sessions/Src/LoadSessions.cpp | 454 | ||||
-rw-r--r-- | plugins/Sessions/Src/SaveSessions.cpp | 388 | ||||
-rw-r--r-- | plugins/Sessions/Src/stdafx.cxx | 2 |
4 files changed, 556 insertions, 556 deletions
diff --git a/plugins/Sessions/Src/Import.cpp b/plugins/Sessions/Src/Import.cpp index 47b2d80159..6eac8c639e 100644 --- a/plugins/Sessions/Src/Import.cpp +++ b/plugins/Sessions/Src/Import.cpp @@ -1,134 +1,134 @@ -/* -Copyright (C) 2012-22 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); -} +/*
+Copyright (C) 2012-23 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 de9e428d0a..690ff664d2 100644 --- a/plugins/Sessions/Src/LoadSessions.cpp +++ b/plugins/Sessions/Src/LoadSessions.cpp @@ -1,227 +1,227 @@ -/* -Copyright (C) 2012-22 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" - -static bool g_bDontShow, g_bStartup; - -///////////////////////////////////////////////////////////////////////////////////////// - -class CLoadSessionDlg : public CDlgBase -{ - 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); - } - - bool OnInitDialog() override - { - g_hDlg = m_hwnd; - - LoadSessionToCombobox(m_list, false); - LoadSessionToCombobox(m_list, true); - m_list.SetCurSel(0); - pSession = (CSession *)m_list.GetItemData(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(); - } - - return true; - } - - bool OnApply() override - { - if (!LoadSession(pSession)) - return true; - - return false; - } - - void OnDestroy() override - { - SavePosition(m_hwnd, "LoadDlg"); - g_hDlg = nullptr; - } - - void onTimer_Load(CTimer *pTimer) - { - pTimer->Stop(); - LoadSession(pSession); - g_bDontShow = g_bStartup = false; - Close(); - } - - void onTimer_Show(CTimer *pTimer) - { - pTimer->Stop(); - Show(); - g_bStartup = FALSE; - } - - void onSelChange_List(CCtrlCombo *) - { - int index = m_list.GetCurSel(); - if (index != CB_ERR) - pSession = (CSession*)m_list.GetItemData(index); - } - - 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)); - } - g_bIncompletedSave = 0; - } - else pSession->remove(); - - m_list.ResetContent(); - LoadSessionToCombobox(m_list, false); - LoadSessionToCombobox(m_list, true); - - m_list.SetCurSel(0); - btnDelete.Enable(m_list.GetCount() != 0); - } -}; - -INT_PTR OpenSessionsManagerWindow(WPARAM, LPARAM) -{ - if (g_hDlg) { - ShowWindow(g_hDlg, SW_SHOW); - return 0; - } - - if (g_bIncompletedSave || g_arDateSessions.getCount() || g_arUserSessions.getCount()) { - (new CLoadSessionDlg())->Create(); - return 0; - } - - if (g_bOtherWarnings) - MessageBox(nullptr, TranslateT("No sessions to open"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING); - return 1; -} - -void CALLBACK LaunchSessions() -{ - int startup = g_plugin.getByte("StartupMode", 3); - if (startup == 1 || (startup == 3 && g_bLastSessionPresent)) { - g_bStartup = true; - (new CLoadSessionDlg())->Create(); - } - else if (startup == 2 && g_bLastSessionPresent) { - g_bDontShow = true; - (new CLoadSessionDlg())->Create(); - } -} - -///////////////////////////////////////////////////////////////////////////////////////// - -INT_PTR LoadLastSession(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; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// Load session dialog - -int LoadSession(CSession *pSession) -{ - int dup = 0; - int hidden[255] = { '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 { - int i = 0; - for (auto &cc : pSession->contacts) - session_list_t[i++] = cc; - } - - int i = 0, j = 0; - // TODO: change to "switch" - while (session_list_t[i] != 0) { - if (CheckForDuplicate(session_list, session_list_t[i]) == -1) - Clist_ContactDoubleClicked(session_list_t[i]); - else if (g_bWarnOnHidden) { - if (!CheckContactVisibility(session_list_t[i])) { - hidden[j] = i + 1; - j++; - } - dup++; - } - i++; - } - - if (i == 0) { - if (g_bOtherWarnings) - MessageBox(nullptr, TranslateT("No contacts to open"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING); - return 1; - } - - if (dup == i) { - if (!hidden[i]) { - if (g_bOtherWarnings) - MessageBox(nullptr, TranslateT("This Session already opened"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING); - return 1; - } - if (!g_bWarnOnHidden && g_bOtherWarnings) { - MessageBox(nullptr, TranslateT("This Session already opened"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING); - return 1; - } - if (g_bWarnOnHidden) { - if (IDYES == MessageBox(nullptr, 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++) - Clist_ContactDoubleClicked(session_list_t[hidden[j] - 1]); - } - } - - return 0; -} +/*
+Copyright (C) 2012-23 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"
+
+static bool g_bDontShow, g_bStartup;
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+class CLoadSessionDlg : public CDlgBase
+{
+ 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);
+ }
+
+ bool OnInitDialog() override
+ {
+ g_hDlg = m_hwnd;
+
+ LoadSessionToCombobox(m_list, false);
+ LoadSessionToCombobox(m_list, true);
+ m_list.SetCurSel(0);
+ pSession = (CSession *)m_list.GetItemData(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();
+ }
+
+ return true;
+ }
+
+ bool OnApply() override
+ {
+ if (!LoadSession(pSession))
+ return true;
+
+ return false;
+ }
+
+ void OnDestroy() override
+ {
+ SavePosition(m_hwnd, "LoadDlg");
+ g_hDlg = nullptr;
+ }
+
+ void onTimer_Load(CTimer *pTimer)
+ {
+ pTimer->Stop();
+ LoadSession(pSession);
+ g_bDontShow = g_bStartup = false;
+ Close();
+ }
+
+ void onTimer_Show(CTimer *pTimer)
+ {
+ pTimer->Stop();
+ Show();
+ g_bStartup = FALSE;
+ }
+
+ void onSelChange_List(CCtrlCombo *)
+ {
+ int index = m_list.GetCurSel();
+ if (index != CB_ERR)
+ pSession = (CSession*)m_list.GetItemData(index);
+ }
+
+ 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));
+ }
+ g_bIncompletedSave = 0;
+ }
+ else pSession->remove();
+
+ m_list.ResetContent();
+ LoadSessionToCombobox(m_list, false);
+ LoadSessionToCombobox(m_list, true);
+
+ m_list.SetCurSel(0);
+ btnDelete.Enable(m_list.GetCount() != 0);
+ }
+};
+
+INT_PTR OpenSessionsManagerWindow(WPARAM, LPARAM)
+{
+ if (g_hDlg) {
+ ShowWindow(g_hDlg, SW_SHOW);
+ return 0;
+ }
+
+ if (g_bIncompletedSave || g_arDateSessions.getCount() || g_arUserSessions.getCount()) {
+ (new CLoadSessionDlg())->Create();
+ return 0;
+ }
+
+ if (g_bOtherWarnings)
+ MessageBox(nullptr, TranslateT("No sessions to open"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING);
+ return 1;
+}
+
+void CALLBACK LaunchSessions()
+{
+ int startup = g_plugin.getByte("StartupMode", 3);
+ if (startup == 1 || (startup == 3 && g_bLastSessionPresent)) {
+ g_bStartup = true;
+ (new CLoadSessionDlg())->Create();
+ }
+ else if (startup == 2 && g_bLastSessionPresent) {
+ g_bDontShow = true;
+ (new CLoadSessionDlg())->Create();
+ }
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+INT_PTR LoadLastSession(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;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Load session dialog
+
+int LoadSession(CSession *pSession)
+{
+ int dup = 0;
+ int hidden[255] = { '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 {
+ int i = 0;
+ for (auto &cc : pSession->contacts)
+ session_list_t[i++] = cc;
+ }
+
+ int i = 0, j = 0;
+ // TODO: change to "switch"
+ while (session_list_t[i] != 0) {
+ if (CheckForDuplicate(session_list, session_list_t[i]) == -1)
+ Clist_ContactDoubleClicked(session_list_t[i]);
+ else if (g_bWarnOnHidden) {
+ if (!CheckContactVisibility(session_list_t[i])) {
+ hidden[j] = i + 1;
+ j++;
+ }
+ dup++;
+ }
+ i++;
+ }
+
+ if (i == 0) {
+ if (g_bOtherWarnings)
+ MessageBox(nullptr, TranslateT("No contacts to open"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING);
+ return 1;
+ }
+
+ if (dup == i) {
+ if (!hidden[i]) {
+ if (g_bOtherWarnings)
+ MessageBox(nullptr, TranslateT("This Session already opened"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING);
+ return 1;
+ }
+ if (!g_bWarnOnHidden && g_bOtherWarnings) {
+ MessageBox(nullptr, TranslateT("This Session already opened"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING);
+ return 1;
+ }
+ if (g_bWarnOnHidden) {
+ if (IDYES == MessageBox(nullptr, 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++)
+ Clist_ContactDoubleClicked(session_list_t[hidden[j] - 1]);
+ }
+ }
+
+ return 0;
+}
diff --git a/plugins/Sessions/Src/SaveSessions.cpp b/plugins/Sessions/Src/SaveSessions.cpp index 4d195b4c83..c9792d8ee2 100644 --- a/plugins/Sessions/Src/SaveSessions.cpp +++ b/plugins/Sessions/Src/SaveSessions.cpp @@ -1,194 +1,194 @@ -/* -Copyright (C) 2012-22 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" - -HWND g_hSDlg; - -bool bSC = false; - -///////////////////////////////////////////////////////////////////////////////////////// - -static int SaveUserSessionName(MCONTACT *contacts, wchar_t *szUSessionName) -{ - if (contacts[0] == 0) - return 1; - - 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); - } - - for (int i = 0; contacts[i]; i++) - pSession->contacts.push_back(contacts[i]); - - pSession->save(); - - while (g_arUserSessions.getCount() > g_ses_limit) { - g_arUserSessions[0].remove(); - g_arUserSessions.remove(int(0)); - } - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// Save session dialog - -class CSessionDlg : public CDlgBase -{ - CCtrlClc m_clist; - CCtrlCombo m_sessions; - CCtrlCheck chkSelContacts, chkSaveAndClose; - - MCONTACT user_session_list[255]; - -public: - CSessionDlg() : - CDlgBase(g_plugin, IDD_SAVEDIALOG), - m_clist(this, IDC_CLIST), - m_sessions(this, IDC_LIST), - chkSelContacts(this, IDC_SELCONTACTS), - chkSaveAndClose(this, IDC_SANDCCHECK) - { - memset(user_session_list, 0, sizeof(user_session_list)); - - chkSelContacts.OnChange = Callback(this, &CSessionDlg::onChange_SelContacts); - - m_clist.OnCheckChanged = Callback(this, &CSessionDlg::onCheckChanged_Clist); - } - - bool OnInitDialog() override - { - g_hSDlg = m_hwnd; - 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); - m_clist.SetExStyle(CLS_EX_DISABLEDRAGDROP | CLS_EX_TRACKSELECT); - m_clist.AutoRebuild(); - - LoadPosition(m_hwnd, "SaveDlg"); - return true; - } - - bool OnApply() override - { - 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; - } - - if (chkSelContacts.IsChecked() && bSC) { - int i = 0; - for (auto &hContact : Contacts()) { - uint8_t res = m_clist.GetCheck(m_clist.FindContact(hContact)); - if (res) { - user_session_list[i] = hContact; - i++; - } - } - - SaveUserSessionName(user_session_list, szUserSessionName); - return true; - } - - if (!SaveUserSessionName(session_list, szUserSessionName)) { - if (chkSaveAndClose.IsChecked()) - CloseCurrentSession(0, 0); - return true; - } - - MessageBox(nullptr, TranslateT("Current session is empty!"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING); - return false; - } - - void OnDestroy() override - { - SavePosition(m_hwnd, "SaveDlg"); - g_hSDlg = nullptr; - } - - void onCheckChanged_Clist(CCtrlClc*) - { - bSC = TRUE; - memcpy(user_session_list, session_list, sizeof(user_session_list)); - } - - void onChange_SelContacts(CCtrlCheck *) - { - if (!m_bInitialized) - return; - - RECT rWnd; - GetWindowRect(m_hwnd, &rWnd); - - int x = rWnd.right - rWnd.left, y = rWnd.bottom - rWnd.top, dy, dx, dd; - - if (chkSelContacts.IsChecked()) { - chkSaveAndClose.Disable(); - dy = 20; - dx = 150; - dd = 5; - m_clist.Show(); - } - else { - chkSaveAndClose.Enable(); - dy = -20; - dx = -150; - dd = 5; - m_clist.Hide(); - } - - SetWindowPos(m_hwnd, nullptr, rWnd.left, rWnd.top, x + dx, y + (dx / 3), SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE); - SetWindowPos(m_clist.GetHwnd(), nullptr, x - dd, dd, dx - dd, y + (dx / 12), SWP_NOZORDER); - - for (int i = 0; session_list[i] > 0; i++) - m_clist.SetCheck(m_clist.FindContact(session_list[i]), 1); - - OffsetWindow(m_hwnd, GetDlgItem(m_hwnd, IDC_LIST), 0, dy); - OffsetWindow(m_hwnd, GetDlgItem(m_hwnd, IDC_STATIC), 0, dy); - OffsetWindow(m_hwnd, GetDlgItem(m_hwnd, IDC_SANDCCHECK), 0, dy); - OffsetWindow(m_hwnd, GetDlgItem(m_hwnd, IDOK), 0, dy); - OffsetWindow(m_hwnd, GetDlgItem(m_hwnd, IDCANCEL), 0, dy); - } -}; - -INT_PTR SaveUserSessionHandles(WPARAM, LPARAM) -{ - if (g_hSDlg) { - ShowWindow(g_hSDlg, SW_SHOW); - return 1; - } - - (new CSessionDlg())->Show(); - return 0; -} +/*
+Copyright (C) 2012-23 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"
+
+HWND g_hSDlg;
+
+bool bSC = false;
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+static int SaveUserSessionName(MCONTACT *contacts, wchar_t *szUSessionName)
+{
+ if (contacts[0] == 0)
+ return 1;
+
+ 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);
+ }
+
+ for (int i = 0; contacts[i]; i++)
+ pSession->contacts.push_back(contacts[i]);
+
+ pSession->save();
+
+ while (g_arUserSessions.getCount() > g_ses_limit) {
+ g_arUserSessions[0].remove();
+ g_arUserSessions.remove(int(0));
+ }
+ return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Save session dialog
+
+class CSessionDlg : public CDlgBase
+{
+ CCtrlClc m_clist;
+ CCtrlCombo m_sessions;
+ CCtrlCheck chkSelContacts, chkSaveAndClose;
+
+ MCONTACT user_session_list[255];
+
+public:
+ CSessionDlg() :
+ CDlgBase(g_plugin, IDD_SAVEDIALOG),
+ m_clist(this, IDC_CLIST),
+ m_sessions(this, IDC_LIST),
+ chkSelContacts(this, IDC_SELCONTACTS),
+ chkSaveAndClose(this, IDC_SANDCCHECK)
+ {
+ memset(user_session_list, 0, sizeof(user_session_list));
+
+ chkSelContacts.OnChange = Callback(this, &CSessionDlg::onChange_SelContacts);
+
+ m_clist.OnCheckChanged = Callback(this, &CSessionDlg::onCheckChanged_Clist);
+ }
+
+ bool OnInitDialog() override
+ {
+ g_hSDlg = m_hwnd;
+ 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);
+ m_clist.SetExStyle(CLS_EX_DISABLEDRAGDROP | CLS_EX_TRACKSELECT);
+ m_clist.AutoRebuild();
+
+ LoadPosition(m_hwnd, "SaveDlg");
+ return true;
+ }
+
+ bool OnApply() override
+ {
+ 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;
+ }
+
+ if (chkSelContacts.IsChecked() && bSC) {
+ int i = 0;
+ for (auto &hContact : Contacts()) {
+ uint8_t res = m_clist.GetCheck(m_clist.FindContact(hContact));
+ if (res) {
+ user_session_list[i] = hContact;
+ i++;
+ }
+ }
+
+ SaveUserSessionName(user_session_list, szUserSessionName);
+ return true;
+ }
+
+ if (!SaveUserSessionName(session_list, szUserSessionName)) {
+ if (chkSaveAndClose.IsChecked())
+ CloseCurrentSession(0, 0);
+ return true;
+ }
+
+ MessageBox(nullptr, TranslateT("Current session is empty!"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING);
+ return false;
+ }
+
+ void OnDestroy() override
+ {
+ SavePosition(m_hwnd, "SaveDlg");
+ g_hSDlg = nullptr;
+ }
+
+ void onCheckChanged_Clist(CCtrlClc*)
+ {
+ bSC = TRUE;
+ memcpy(user_session_list, session_list, sizeof(user_session_list));
+ }
+
+ void onChange_SelContacts(CCtrlCheck *)
+ {
+ if (!m_bInitialized)
+ return;
+
+ RECT rWnd;
+ GetWindowRect(m_hwnd, &rWnd);
+
+ int x = rWnd.right - rWnd.left, y = rWnd.bottom - rWnd.top, dy, dx, dd;
+
+ if (chkSelContacts.IsChecked()) {
+ chkSaveAndClose.Disable();
+ dy = 20;
+ dx = 150;
+ dd = 5;
+ m_clist.Show();
+ }
+ else {
+ chkSaveAndClose.Enable();
+ dy = -20;
+ dx = -150;
+ dd = 5;
+ m_clist.Hide();
+ }
+
+ SetWindowPos(m_hwnd, nullptr, rWnd.left, rWnd.top, x + dx, y + (dx / 3), SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOMOVE);
+ SetWindowPos(m_clist.GetHwnd(), nullptr, x - dd, dd, dx - dd, y + (dx / 12), SWP_NOZORDER);
+
+ for (int i = 0; session_list[i] > 0; i++)
+ m_clist.SetCheck(m_clist.FindContact(session_list[i]), 1);
+
+ OffsetWindow(m_hwnd, GetDlgItem(m_hwnd, IDC_LIST), 0, dy);
+ OffsetWindow(m_hwnd, GetDlgItem(m_hwnd, IDC_STATIC), 0, dy);
+ OffsetWindow(m_hwnd, GetDlgItem(m_hwnd, IDC_SANDCCHECK), 0, dy);
+ OffsetWindow(m_hwnd, GetDlgItem(m_hwnd, IDOK), 0, dy);
+ OffsetWindow(m_hwnd, GetDlgItem(m_hwnd, IDCANCEL), 0, dy);
+ }
+};
+
+INT_PTR SaveUserSessionHandles(WPARAM, LPARAM)
+{
+ if (g_hSDlg) {
+ ShowWindow(g_hSDlg, SW_SHOW);
+ return 1;
+ }
+
+ (new CSessionDlg())->Show();
+ return 0;
+}
diff --git a/plugins/Sessions/Src/stdafx.cxx b/plugins/Sessions/Src/stdafx.cxx index f64d25234b..ebbde0ade1 100644 --- a/plugins/Sessions/Src/stdafx.cxx +++ b/plugins/Sessions/Src/stdafx.cxx @@ -1,5 +1,5 @@ /*
-Copyright (C) 2012-22 Miranda NG team (https://miranda-ng.org)
+Copyright (C) 2012-23 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
|