diff options
author | George Hazan <ghazan@miranda.im> | 2017-10-17 23:22:13 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-10-17 23:22:13 +0300 |
commit | dab14b038f1969182eaf5997c4c1e28166030f5e (patch) | |
tree | 548ed731e48c71b3102f36a01305fb375a4c899a /plugins/StatusManager | |
parent | 53ff16b147c30de05cd21e3f97b0ae0106dd9566 (diff) |
fixes #999 (global variable leads to duplicate profiles)
Diffstat (limited to 'plugins/StatusManager')
-rw-r--r-- | plugins/StatusManager/src/StartupStatus/ss_options.cpp | 635 | ||||
-rw-r--r-- | plugins/StatusManager/src/StartupStatus/startupstatus.h | 4 |
2 files changed, 318 insertions, 321 deletions
diff --git a/plugins/StatusManager/src/StartupStatus/ss_options.cpp b/plugins/StatusManager/src/StartupStatus/ss_options.cpp index 1f637a7c4d..3d734a7225 100644 --- a/plugins/StatusManager/src/StartupStatus/ss_options.cpp +++ b/plugins/StatusManager/src/StartupStatus/ss_options.cpp @@ -19,6 +19,13 @@ #include "..\stdafx.h" +char* OptName(int i, const char* setting) +{ + static char buf[100]; + mir_snprintf(buf, "%d_%s", i, setting); + return buf; +} + ///////////////////////////////////////////////////////////////////////////////////////// int SSCompareSettings(const TSSSetting *p1, const TSSSetting *p2) @@ -518,8 +525,6 @@ static int ClearDatabase(char* filter) } -static OBJLIST<PROFILEOPTIONS> arProfiles(5); - INT_PTR CALLBACK addProfileDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { static HWND hwndParent; @@ -555,358 +560,360 @@ INT_PTR CALLBACK addProfileDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM return 0; } -static INT_PTR CALLBACK StatusProfilesOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +class CSSAdvancedOptDlg : public CDlgBase { - static BOOL bNeedRebuildMenu = FALSE; - static BOOL bInitDone = FALSE; + bool bNeedRebuildMenu = false; - switch (msg) { - case WM_INITDIALOG: - bInitDone = false; + OBJLIST<PROFILEOPTIONS> arProfiles; - TranslateDialogDefault(hwndDlg); - SetDlgItemText(hwndDlg, IDC_CREATEMMI, TranslateT("Create a status menu item")); - { - int defProfile; - int profileCount = GetProfileCount((WPARAM)&defProfile, 0); - if (profileCount == 0) { - profileCount = 1; - defProfile = 0; - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - } + void ReinitProfiles() + { + // creates profile combo box according to 'dat' + cmbProfile.ResetContent(); + for (int i = 0; i < arProfiles.getCount(); i++) + cmbProfile.AddString(arProfiles[i].tszName, i); - for (int i = 0; i < profileCount; i++) { - PROFILEOPTIONS *ppo = new PROFILEOPTIONS; - ppo->ps = GetCurrentProtoSettings(); - TSettingsList& ar = *ppo->ps; + cmbProfile.SetCurSel(0); + SetProfile(); + } - if (GetProfile(i, ar) == -1) { - /* create an empty profile */ - if (i == defProfile) - ppo->tszName = mir_wstrdup(TranslateT("default")); - else - ppo->tszName = mir_wstrdup(TranslateT("unknown")); - } - else { - for (int j = 0; j < ar.getCount(); j++) - if (ar[j].m_szMsg != nullptr) - ar[j].m_szMsg = wcsdup(ar[j].m_szMsg); - - ppo->tszName = db_get_wsa(0, SSMODULENAME, OptName(i, SETTING_PROFILENAME)); - if (ppo->tszName == nullptr) { - if (i == defProfile) - ppo->tszName = mir_wstrdup(TranslateT("default")); - else - ppo->tszName = mir_wstrdup(TranslateT("unknown")); - } - ppo->createTtb = db_get_b(0, SSMODULENAME, OptName(i, SETTING_CREATETTBBUTTON), 0); - ppo->showDialog = db_get_b(0, SSMODULENAME, OptName(i, SETTING_SHOWCONFIRMDIALOG), 0); - ppo->createMmi = db_get_b(0, SSMODULENAME, OptName(i, SETTING_CREATEMMITEM), 0); - ppo->inSubMenu = db_get_b(0, SSMODULENAME, OptName(i, SETTING_INSUBMENU), 1); - ppo->regHotkey = db_get_b(0, SSMODULENAME, OptName(i, SETTING_REGHOTKEY), 0); - ppo->hotKey = db_get_w(0, SSMODULENAME, OptName(i, SETTING_HOTKEY), MAKEWORD((char)('0' + i), HOTKEYF_CONTROL | HOTKEYF_SHIFT)); + void SetProfile() + { + int sel = cmbProfile.GetItemData(cmbProfile.GetCurSel()); + chkCreateTTB.SetState(arProfiles[sel].createTtb); + chkShowDialog.SetState(arProfiles[sel].showDialog); + chkCreateMMI.SetState(arProfiles[sel].createMmi); + chkInSubmenu.SetState(arProfiles[sel].inSubMenu); + chkInSubmenu.Enable(arProfiles[sel].createMmi); + chkRegHotkey.SetState(arProfiles[sel].regHotkey); + edtHotkey.SendMsg(HKM_SETHOTKEY, arProfiles[sel].hotKey, 0); + edtHotkey.Enable(arProfiles[sel].regHotkey); + + // fill proto list + lstAccount.ResetContent(); + TSettingsList& ar = *arProfiles[sel].ps; + for (int i = 0; i < ar.getCount(); i++) + lstAccount.AddString(ar[i].m_tszAccName, (LPARAM)&ar[i]); + lstAccount.SetCurSel(0); + + SetProtocol(); + } + + void SetProtocol() + { + int idx = lstAccount.GetCurSel(); + if (idx != -1) { + // fill status box + TSSSetting* ps = (TSSSetting*)lstAccount.GetItemData(idx); + + int flags = (CallProtoService(ps->m_szName, PS_GETCAPS, PFLAGNUM_2, 0))&~(CallProtoService(ps->m_szName, PS_GETCAPS, PFLAGNUM_5, 0)); + lstStatus.ResetContent(); + for (int i = 0; i < _countof(statusModeList); i++) { + if ((flags & statusModePf2List[i]) || (statusModeList[i] == ID_STATUS_OFFLINE)) { + int item = lstStatus.AddString(pcli->pfnGetStatusModeDescription(statusModeList[i], 0), statusModeList[i]); + if (ps->m_status == statusModeList[i]) + lstStatus.SetCurSel(item); } - arProfiles.insert(ppo); } - if (hTTBModuleLoadedHook == nullptr) - EnableWindow(GetDlgItem(hwndDlg, IDC_CREATETTB), FALSE); - SendMessage(hwndDlg, UM_REINITPROFILES, 0, 0); - ShowWindow(GetDlgItem(hwndDlg, IDC_VARIABLESHELP), ServiceExists(MS_VARS_SHOWHELPEX) ? SW_SHOW : SW_HIDE); - bInitDone = true; - } - break; + int item = lstStatus.AddString(TranslateT("<current>"), ID_STATUS_CURRENT); + if (ps->m_status == ID_STATUS_CURRENT) + lstStatus.SetCurSel(item); - case UM_REINITPROFILES: - bInitDone = false; - { - // creates profile combo box according to 'dat' - SendDlgItemMessage(hwndDlg, IDC_PROFILE, CB_RESETCONTENT, 0, 0); - for (int i = 0; i < arProfiles.getCount(); i++) { - int item = SendDlgItemMessage(hwndDlg, IDC_PROFILE, CB_ADDSTRING, 0, (LPARAM)arProfiles[i].tszName); - SendDlgItemMessage(hwndDlg, IDC_PROFILE, CB_SETITEMDATA, (WPARAM)item, (LPARAM)i); - } - SendDlgItemMessage(hwndDlg, IDC_PROFILE, CB_SETCURSEL, 0, 0); - SendMessage(hwndDlg, UM_SETPROFILE, 0, 0); + item = lstStatus.AddString(TranslateT("<last>"), ID_STATUS_LAST); + if (ps->m_status == ID_STATUS_LAST) + lstStatus.SetCurSel(item); } - bInitDone = true; - break; - - case UM_SETPROFILE: - { - int sel = (int)SendDlgItemMessage(hwndDlg, IDC_PROFILE, CB_GETITEMDATA, - SendDlgItemMessage(hwndDlg, IDC_PROFILE, CB_GETCURSEL, 0, 0), 0); - CheckDlgButton(hwndDlg, IDC_CREATETTB, arProfiles[sel].createTtb ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_SHOWDIALOG, arProfiles[sel].showDialog ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_CREATEMMI, arProfiles[sel].createMmi ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_INSUBMENU, arProfiles[sel].inSubMenu ? BST_CHECKED : BST_UNCHECKED); - EnableWindow(GetDlgItem(hwndDlg, IDC_INSUBMENU), IsDlgButtonChecked(hwndDlg, IDC_CREATEMMI)); - CheckDlgButton(hwndDlg, IDC_REGHOTKEY, arProfiles[sel].regHotkey ? BST_CHECKED : BST_UNCHECKED); - SendDlgItemMessage(hwndDlg, IDC_HOTKEY, HKM_SETHOTKEY, arProfiles[sel].hotKey, 0); - EnableWindow(GetDlgItem(hwndDlg, IDC_HOTKEY), IsDlgButtonChecked(hwndDlg, IDC_REGHOTKEY)); - SendDlgItemMessage(hwndDlg, IDC_PROTOCOL, LB_RESETCONTENT, 0, 0); - - // fill proto list - TSettingsList& ar = *arProfiles[sel].ps; - for (int i = 0; i < ar.getCount(); i++) { - int item = SendDlgItemMessage(hwndDlg, IDC_PROTOCOL, LB_ADDSTRING, 0, (LPARAM)ar[i].m_tszAccName); - SendDlgItemMessage(hwndDlg, IDC_PROTOCOL, LB_SETITEMDATA, (WPARAM)item, (LPARAM)&ar[i]); - } - SendDlgItemMessage(hwndDlg, IDC_PROTOCOL, LB_SETCURSEL, 0, 0); - SendMessage(hwndDlg, UM_SETPROTOCOL, 0, 0); - } - break; - case UM_SETPROTOCOL: - { - int idx = SendDlgItemMessage(hwndDlg, IDC_PROTOCOL, LB_GETCURSEL, 0, 0); - if (idx != -1) { - // fill status box - TSSSetting* ps = (TSSSetting*)SendDlgItemMessage(hwndDlg, IDC_PROTOCOL, LB_GETITEMDATA, idx, 0); - - int flags = (CallProtoService(ps->m_szName, PS_GETCAPS, PFLAGNUM_2, 0))&~(CallProtoService(ps->m_szName, PS_GETCAPS, PFLAGNUM_5, 0)); - SendDlgItemMessage(hwndDlg, IDC_STATUS, LB_RESETCONTENT, 0, 0); - for (int i = 0; i < _countof(statusModeList); i++) { - if ((flags&statusModePf2List[i]) || (statusModeList[i] == ID_STATUS_OFFLINE)) { - int item = SendDlgItemMessage(hwndDlg, IDC_STATUS, LB_ADDSTRING, 0, (LPARAM)pcli->pfnGetStatusModeDescription(statusModeList[i], 0)); - SendDlgItemMessage(hwndDlg, IDC_STATUS, LB_SETITEMDATA, (WPARAM)item, (LPARAM)statusModeList[i]); - if (ps->m_status == statusModeList[i]) - SendDlgItemMessage(hwndDlg, IDC_STATUS, LB_SETCURSEL, (WPARAM)item, 0); - } - } - - int item = SendDlgItemMessage(hwndDlg, IDC_STATUS, LB_ADDSTRING, 0, (LPARAM)TranslateT("<current>")); - SendDlgItemMessage(hwndDlg, IDC_STATUS, LB_SETITEMDATA, (WPARAM)item, (LPARAM)ID_STATUS_CURRENT); - if (ps->m_status == ID_STATUS_CURRENT) - SendDlgItemMessage(hwndDlg, IDC_STATUS, LB_SETCURSEL, (WPARAM)item, 0); + SetStatusMsg(); + } - item = SendDlgItemMessage(hwndDlg, IDC_STATUS, LB_ADDSTRING, 0, (LPARAM)TranslateT("<last>")); - SendDlgItemMessage(hwndDlg, IDC_STATUS, LB_SETITEMDATA, (WPARAM)item, (LPARAM)ID_STATUS_LAST); - if (ps->m_status == ID_STATUS_LAST) - SendDlgItemMessage(hwndDlg, IDC_STATUS, LB_SETCURSEL, (WPARAM)item, 0); - } + // set status message + void SetStatusMsg() + { + bool bStatusMsg = false; + int idx = lstAccount.GetCurSel(); + if (idx != -1) { + TSSSetting *ps = (TSSSetting*)lstAccount.GetItemData(idx); - SendMessage(hwndDlg, UM_SETSTATUSMSG, 0, 0); - } - break; + CheckRadioButton(m_hwnd, IDC_MIRANDAMSG, IDC_CUSTOMMSG, ps->m_szMsg != nullptr ? IDC_CUSTOMMSG : IDC_MIRANDAMSG); + if (ps->m_szMsg != nullptr) + edtStatusMsg.SetText(ps->m_szMsg); - case UM_SETSTATUSMSG: - { - // set status message - BOOL bStatusMsg = FALSE; - int idx = SendDlgItemMessage(hwndDlg, IDC_PROTOCOL, LB_GETCURSEL, 0, 0); - if (idx != -1) { - TSSSetting* ps = (TSSSetting*)SendDlgItemMessage(hwndDlg, IDC_PROTOCOL, LB_GETITEMDATA, idx, 0); - - CheckRadioButton(hwndDlg, IDC_MIRANDAMSG, IDC_CUSTOMMSG, ps->m_szMsg != nullptr ? IDC_CUSTOMMSG : IDC_MIRANDAMSG); - if (ps->m_szMsg != nullptr) - SetDlgItemText(hwndDlg, IDC_STATUSMSG, ps->m_szMsg); - - bStatusMsg = ((((CallProtoService(ps->m_szName, PS_GETCAPS, PFLAGNUM_1, 0)&PF1_MODEMSGSEND&~PF1_INDIVMODEMSG)) && - (CallProtoService(ps->m_szName, PS_GETCAPS, PFLAGNUM_3, 0)&Proto_Status2Flag(ps->m_status))) || (ps->m_status == ID_STATUS_CURRENT) || (ps->m_status == ID_STATUS_LAST)); - } - EnableWindow(GetDlgItem(hwndDlg, IDC_MIRANDAMSG), bStatusMsg); - EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOMMSG), bStatusMsg); - EnableWindow(GetDlgItem(hwndDlg, IDC_STATUSMSG), bStatusMsg&&IsDlgButtonChecked(hwndDlg, IDC_CUSTOMMSG)); - EnableWindow(GetDlgItem(hwndDlg, IDC_VARIABLESHELP), bStatusMsg&&IsDlgButtonChecked(hwndDlg, IDC_CUSTOMMSG)); + bStatusMsg = ((((CallProtoService(ps->m_szName, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_MODEMSGSEND & ~PF1_INDIVMODEMSG)) && + (CallProtoService(ps->m_szName, PS_GETCAPS, PFLAGNUM_3, 0) & Proto_Status2Flag(ps->m_status))) || (ps->m_status == ID_STATUS_CURRENT) || (ps->m_status == ID_STATUS_LAST)); } - break; + chkMiranda.Enable(bStatusMsg); + chkCustom.Enable(bStatusMsg); + btnHelp.Enable(bStatusMsg && chkCustom.GetState()); + edtStatusMsg.Enable(bStatusMsg && chkCustom.GetState()); + } - case UM_ADDPROFILE: - { - wchar_t *tszName = (wchar_t*)lParam; - if (tszName == nullptr) - break; + CCtrlEdit edtStatusMsg, edtHotkey; + CCtrlCombo cmbProfile; + CCtrlCheck chkMiranda, chkCustom, chkCreateMMI, chkInSubmenu, chkRegHotkey, chkCreateTTB, chkShowDialog; + CCtrlButton btnAdd, btnDelete, btnHelp; + CCtrlListBox lstStatus, lstAccount; + +public: + CSSAdvancedOptDlg() : + CDlgBase(hInst, IDD_OPT_STATUSPROFILES), + cmbProfile(this, IDC_PROFILE), + btnAdd(this, IDC_ADDPROFILE), + btnHelp(this, IDC_VARIABLESHELP), + btnDelete(this, IDC_DELPROFILE), + chkCustom(this, IDC_CUSTOMMSG), + chkMiranda(this, IDC_MIRANDAMSG), + chkCreateMMI(this, IDC_CREATEMMI), + chkInSubmenu(this, IDC_INSUBMENU), + chkRegHotkey(this, IDC_REGHOTKEY), + chkCreateTTB(this, IDC_CREATETTB), + chkShowDialog(this, IDC_SHOWDIALOG), + edtHotkey(this, IDC_HOTKEY), + edtStatusMsg(this, IDC_STATUSMSG), + lstStatus(this, IDC_STATUS), + lstAccount(this, IDC_PROTOCOL), + arProfiles(5) + { + btnAdd.OnClick = Callback(this, &CSSAdvancedOptDlg::onClick_Add); + btnHelp.OnClick = Callback(this, &CSSAdvancedOptDlg::onClick_Help); + btnDelete.OnClick = Callback(this, &CSSAdvancedOptDlg::onClick_Delete); + + cmbProfile.OnChange = Callback(this, &CSSAdvancedOptDlg::onChange_Profile); + + chkCreateMMI.OnChange = Callback(this, &CSSAdvancedOptDlg::onChange_CreateMMI); + chkInSubmenu.OnChange = Callback(this, &CSSAdvancedOptDlg::onChange_InSubmenu); + chkCustom.OnChange = chkMiranda.OnChange = Callback(this, &CSSAdvancedOptDlg::onChange_StatusMsg); + chkRegHotkey.OnChange = chkCreateTTB.OnChange = chkShowDialog.OnChange = Callback(this, &CSSAdvancedOptDlg::onChange_Option); + + edtHotkey.OnChange = Callback(this, &CSSAdvancedOptDlg::onChange_Hotkey); + edtStatusMsg.OnChange = Callback(this, &CSSAdvancedOptDlg::onChange_EdtStatusMsg); + + lstStatus.OnSelChange = Callback(this, &CSSAdvancedOptDlg::onChange_Status); + lstAccount.OnSelChange = Callback(this, &CSSAdvancedOptDlg::onChange_Account); + } - PROFILEOPTIONS* ppo = new PROFILEOPTIONS; - ppo->tszName = mir_wstrdup(tszName); - ppo->ps = GetCurrentProtoSettings(); - arProfiles.insert(ppo); + virtual void OnInitDialog() override + { + chkCreateMMI.SetText(TranslateT("Create a status menu item")); - SendMessage(hwndDlg, UM_REINITPROFILES, 0, 0); + int defProfile; + int profileCount = GetProfileCount((WPARAM)&defProfile, 0); + if (profileCount == 0) { + profileCount = 1; + defProfile = 0; + NotifyChange(); } - break; - - case UM_DELPROFILE: { - // wparam == profile no - int i = (int)wParam; - if (arProfiles.getCount() == 1) { - MessageBox(nullptr, TranslateT("At least one profile must exist"), TranslateT("Status manager"), MB_OK); - break; + for (int i = 0; i < profileCount; i++) { + PROFILEOPTIONS *ppo = new PROFILEOPTIONS; + ppo->ps = GetCurrentProtoSettings(); + TSettingsList& ar = *ppo->ps; + + if (GetProfile(i, ar) == -1) { + /* create an empty profile */ + if (i == defProfile) + ppo->tszName = mir_wstrdup(TranslateT("default")); + else + ppo->tszName = mir_wstrdup(TranslateT("unknown")); } + else { + for (int j = 0; j < ar.getCount(); j++) + if (ar[j].m_szMsg != nullptr) + ar[j].m_szMsg = wcsdup(ar[j].m_szMsg); - arProfiles.remove(i); - - int defProfile; - GetProfileCount((WPARAM)&defProfile, 0); - if (i == defProfile) { - MessageBox(nullptr, TranslateT("Your default profile will be changed"), TranslateT("Status manager"), MB_OK); - db_set_w(0, SSMODULENAME, SETTING_DEFAULTPROFILE, 0); + ppo->tszName = db_get_wsa(0, SSMODULENAME, OptName(i, SETTING_PROFILENAME)); + if (ppo->tszName == nullptr) { + if (i == defProfile) + ppo->tszName = mir_wstrdup(TranslateT("default")); + else + ppo->tszName = mir_wstrdup(TranslateT("unknown")); + } + ppo->createTtb = db_get_b(0, SSMODULENAME, OptName(i, SETTING_CREATETTBBUTTON), 0); + ppo->showDialog = db_get_b(0, SSMODULENAME, OptName(i, SETTING_SHOWCONFIRMDIALOG), 0); + ppo->createMmi = db_get_b(0, SSMODULENAME, OptName(i, SETTING_CREATEMMITEM), 0); + ppo->inSubMenu = db_get_b(0, SSMODULENAME, OptName(i, SETTING_INSUBMENU), 1); + ppo->regHotkey = db_get_b(0, SSMODULENAME, OptName(i, SETTING_REGHOTKEY), 0); + ppo->hotKey = db_get_w(0, SSMODULENAME, OptName(i, SETTING_HOTKEY), MAKEWORD((char)('0' + i), HOTKEYF_CONTROL | HOTKEYF_SHIFT)); } - SendMessage(hwndDlg, UM_REINITPROFILES, 0, 0); - break; + arProfiles.insert(ppo); } + if (hTTBModuleLoadedHook == nullptr) + chkCreateTTB.Disable(); - case WM_COMMAND: - if (((HIWORD(wParam) == EN_CHANGE) || (HIWORD(wParam) == BN_CLICKED) || (HIWORD(wParam) == LBN_SELCHANGE)) && ((HWND)lParam == GetFocus())) - if (bInitDone) - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + ReinitProfiles(); + ShowWindow(GetDlgItem(m_hwnd, IDC_VARIABLESHELP), ServiceExists(MS_VARS_SHOWHELPEX) ? SW_SHOW : SW_HIDE); + } - switch (LOWORD(wParam)) { - case IDC_STATUS: - if (HIWORD(wParam) == LBN_SELCHANGE) { - int idx = SendDlgItemMessage(hwndDlg, IDC_PROTOCOL, LB_GETCURSEL, 0, 0); - if (idx != -1) { - TSSSetting* ps = (TSSSetting*)SendDlgItemMessage(hwndDlg, IDC_PROTOCOL, LB_GETITEMDATA, idx, 0); - ps->m_status = (int)SendDlgItemMessage(hwndDlg, IDC_STATUS, LB_GETITEMDATA, - SendDlgItemMessage(hwndDlg, IDC_STATUS, LB_GETCURSEL, 0, 0), 0); + virtual void OnApply() override + { + char setting[128]; + int oldCount = db_get_w(0, SSMODULENAME, SETTING_PROFILECOUNT, 0); + for (int i = 0; i < oldCount; i++) { + mir_snprintf(setting, "%d_", i); + ClearDatabase(setting); + } + for (int i = 0; i < arProfiles.getCount(); i++) { + PROFILEOPTIONS& po = arProfiles[i]; + db_set_b(0, SSMODULENAME, OptName(i, SETTING_SHOWCONFIRMDIALOG), po.showDialog); + db_set_b(0, SSMODULENAME, OptName(i, SETTING_CREATETTBBUTTON), po.createTtb); + db_set_b(0, SSMODULENAME, OptName(i, SETTING_CREATEMMITEM), po.createMmi); + db_set_b(0, SSMODULENAME, OptName(i, SETTING_INSUBMENU), po.inSubMenu); + db_set_b(0, SSMODULENAME, OptName(i, SETTING_REGHOTKEY), po.regHotkey); + db_set_w(0, SSMODULENAME, OptName(i, SETTING_HOTKEY), po.hotKey); + db_set_ws(0, SSMODULENAME, OptName(i, SETTING_PROFILENAME), po.tszName); + + TSettingsList& ar = *po.ps; + for (int j = 0; j < ar.getCount(); j++) { + if (ar[j].m_szMsg != nullptr) { + mir_snprintf(setting, "%s_%s", ar[j].m_szName, SETTING_PROFILE_STSMSG); + db_set_ws(0, SSMODULENAME, OptName(i, setting), ar[j].m_szMsg); } - SendMessage(hwndDlg, UM_SETSTATUSMSG, 0, 0); + db_set_w(0, SSMODULENAME, OptName(i, ar[j].m_szName), ar[j].m_status); } - break; + } + db_set_w(0, SSMODULENAME, SETTING_PROFILECOUNT, (WORD)arProfiles.getCount()); - case IDC_PROFILE: - if (HIWORD(wParam) != CBN_SELCHANGE) - break; + // Rebuild status menu + if (bNeedRebuildMenu) + pcli->pfnReloadProtoMenus(); - SendMessage(hwndDlg, UM_SETPROFILE, 0, 0); - break; + SSLoadMainOptions(); + } - case IDC_PROTOCOL: - if (HIWORD(wParam) != LBN_SELCHANGE) - break; + // add a profile + void onClick_Add(CCtrlButton*) + { + CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_ADDPROFILE), m_hwnd, addProfileDlgProc, (LPARAM)m_hwnd); + EnableWindow(m_hwnd, FALSE); + } - SendMessage(hwndDlg, UM_SETPROTOCOL, 0, 0); - break; + void onClick_Delete(CCtrlButton*) + { + // wparam == profile no + int sel = cmbProfile.GetItemData(cmbProfile.GetCurSel()); + if (arProfiles.getCount() == 1) { + MessageBox(nullptr, TranslateT("At least one profile must exist"), TranslateT("Status manager"), MB_OK); + return; + } - case IDC_MIRANDAMSG: - case IDC_CUSTOMMSG: - { - int len; - TSSSetting* ps = (TSSSetting*)SendDlgItemMessage(hwndDlg, IDC_PROTOCOL, LB_GETITEMDATA, - SendDlgItemMessage(hwndDlg, IDC_PROTOCOL, LB_GETCURSEL, 0, 0), 0); - if (ps->m_szMsg != nullptr) - free(ps->m_szMsg); - - ps->m_szMsg = nullptr; - if (IsDlgButtonChecked(hwndDlg, IDC_CUSTOMMSG)) { - len = SendDlgItemMessage(hwndDlg, IDC_STATUSMSG, WM_GETTEXTLENGTH, 0, 0); - ps->m_szMsg = (wchar_t*)calloc(sizeof(wchar_t), len + 1); - GetDlgItemText(hwndDlg, IDC_STATUSMSG, ps->m_szMsg, (len + 1)); - } - SendMessage(hwndDlg, UM_SETSTATUSMSG, 0, 0); - } - break; + arProfiles.remove(sel); - case IDC_STATUSMSG: - if (HIWORD(wParam) == EN_CHANGE) { - // update the status message in memory, this is done on each character tick, not nice - // but it works - TSSSetting* ps = (TSSSetting*)SendDlgItemMessage(hwndDlg, IDC_PROTOCOL, LB_GETITEMDATA, - SendDlgItemMessage(hwndDlg, IDC_PROTOCOL, LB_GETCURSEL, 0, 0), 0); - if (ps->m_szMsg != nullptr) { - if (*ps->m_szMsg) - free(ps->m_szMsg); - ps->m_szMsg = nullptr; - } - int len = SendDlgItemMessage(hwndDlg, IDC_STATUSMSG, WM_GETTEXTLENGTH, 0, 0); - ps->m_szMsg = (wchar_t*)calloc(sizeof(wchar_t), len + 1); - GetDlgItemText(hwndDlg, IDC_STATUSMSG, ps->m_szMsg, (len + 1)); - } - break; + int defProfile; + GetProfileCount((WPARAM)&defProfile, 0); + if (sel == defProfile) { + MessageBox(nullptr, TranslateT("Your default profile will be changed"), TranslateT("Status manager"), MB_OK); + db_set_w(0, SSMODULENAME, SETTING_DEFAULTPROFILE, 0); + } + ReinitProfiles();; + } - case IDC_CREATEMMI: - EnableWindow(GetDlgItem(hwndDlg, IDC_INSUBMENU), IsDlgButtonChecked(hwndDlg, IDC_CREATEMMI)); - case IDC_INSUBMENU: - bNeedRebuildMenu = TRUE; - case IDC_REGHOTKEY: - case IDC_CREATETTB: - case IDC_SHOWDIALOG: - { - int sel = (int)SendDlgItemMessage(hwndDlg, IDC_PROFILE, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_PROFILE, CB_GETCURSEL, 0, 0), 0); - PROFILEOPTIONS& po = arProfiles[sel]; - po.createMmi = IsDlgButtonChecked(hwndDlg, IDC_CREATEMMI); - po.inSubMenu = IsDlgButtonChecked(hwndDlg, IDC_INSUBMENU); - po.createTtb = IsDlgButtonChecked(hwndDlg, IDC_CREATETTB); - po.regHotkey = IsDlgButtonChecked(hwndDlg, IDC_REGHOTKEY); - po.showDialog = IsDlgButtonChecked(hwndDlg, IDC_SHOWDIALOG); - EnableWindow(GetDlgItem(hwndDlg, IDC_HOTKEY), IsDlgButtonChecked(hwndDlg, IDC_REGHOTKEY)); - } - break; + void onClick_Help(CCtrlButton*) + { + variables_showhelp(m_hwnd, IDC_STATUSMSG, VHF_INPUT | VHF_EXTRATEXT | VHF_HELP | VHF_FULLFILLSTRUCT | VHF_HIDESUBJECTTOKEN, nullptr, "Protocol ID"); + } - case IDC_HOTKEY: - if (HIWORD(wParam) == EN_CHANGE) { - int sel = (int)SendDlgItemMessage(hwndDlg, IDC_PROFILE, CB_GETITEMDATA, - SendDlgItemMessage(hwndDlg, IDC_PROFILE, CB_GETCURSEL, 0, 0), 0); - arProfiles[sel].hotKey = (WORD)SendDlgItemMessage(hwndDlg, IDC_HOTKEY, HKM_GETHOTKEY, 0, 0); - } - break; + void onChange_Status(CCtrlListBox*) + { + int idx = lstAccount.GetCurSel(); + if (idx != -1) { + TSSSetting* ps = (TSSSetting*)lstAccount.GetItemData(idx); + ps->m_status = lstStatus.GetItemData(lstStatus.GetCurSel()); + } + SetStatusMsg(); + } - case IDC_ADDPROFILE: - // add a profile - CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_ADDPROFILE), hwndDlg, addProfileDlgProc, (LPARAM)hwndDlg); - EnableWindow(hwndDlg, FALSE); - break; + void onChange_Account(CCtrlListBox*) + { + SetProtocol(); + } - case IDC_DELPROFILE: - { - int sel = (int)SendDlgItemMessage(hwndDlg, IDC_PROFILE, CB_GETITEMDATA, - SendDlgItemMessage(hwndDlg, IDC_PROFILE, CB_GETCURSEL, 0, 0), 0); - SendMessage(hwndDlg, UM_DELPROFILE, (WPARAM)sel, 0); - } - break; + void onChange_Profile(CCtrlCombo*) + { + SetProfile(); + } - case IDC_VARIABLESHELP: - variables_showhelp(hwndDlg, IDC_STATUSMSG, VHF_INPUT | VHF_EXTRATEXT | VHF_HELP | VHF_FULLFILLSTRUCT | VHF_HIDESUBJECTTOKEN, nullptr, "Protocol ID"); - break; + void onChange_StatusMsg(CCtrlCheck*) + { + int len; + TSSSetting* ps = (TSSSetting*)lstAccount.GetItemData(lstAccount.GetCurSel()); + if (ps->m_szMsg != nullptr) + free(ps->m_szMsg); + + ps->m_szMsg = nullptr; + if (chkCustom.GetState()) { + len = edtStatusMsg.SendMsg(WM_GETTEXTLENGTH, 0, 0); + ps->m_szMsg = (wchar_t*)calloc(sizeof(wchar_t), len + 1); + GetDlgItemText(m_hwnd, IDC_STATUSMSG, ps->m_szMsg, (len + 1)); } - break; - - case WM_NOTIFY: - if (((LPNMHDR)lParam)->code == PSN_APPLY) { - char setting[128]; - int oldCount = db_get_w(0, SSMODULENAME, SETTING_PROFILECOUNT, 0); - for (int i = 0; i < oldCount; i++) { - mir_snprintf(setting, "%d_", i); - ClearDatabase(setting); - } - for (int i = 0; i < arProfiles.getCount(); i++) { - PROFILEOPTIONS& po = arProfiles[i]; - db_set_b(0, SSMODULENAME, OptName(i, SETTING_SHOWCONFIRMDIALOG), po.showDialog); - db_set_b(0, SSMODULENAME, OptName(i, SETTING_CREATETTBBUTTON), po.createTtb); - db_set_b(0, SSMODULENAME, OptName(i, SETTING_CREATEMMITEM), po.createMmi); - db_set_b(0, SSMODULENAME, OptName(i, SETTING_INSUBMENU), po.inSubMenu); - db_set_b(0, SSMODULENAME, OptName(i, SETTING_REGHOTKEY), po.regHotkey); - db_set_w(0, SSMODULENAME, OptName(i, SETTING_HOTKEY), po.hotKey); - db_set_ws(0, SSMODULENAME, OptName(i, SETTING_PROFILENAME), po.tszName); - - TSettingsList& ar = *po.ps; - for (int j = 0; j < ar.getCount(); j++) { - if (ar[j].m_szMsg != nullptr) { - mir_snprintf(setting, "%s_%s", ar[j].m_szName, SETTING_PROFILE_STSMSG); - db_set_ws(0, SSMODULENAME, OptName(i, setting), ar[j].m_szMsg); - } - db_set_w(0, SSMODULENAME, OptName(i, ar[j].m_szName), ar[j].m_status); - } - } - db_set_w(0, SSMODULENAME, SETTING_PROFILECOUNT, (WORD)arProfiles.getCount()); + SetStatusMsg(); + } - // Rebuild status menu - if (bNeedRebuildMenu) - pcli->pfnReloadProtoMenus(); + void onChange_Hotkey(CCtrlEdit*) + { + int sel = cmbProfile.GetItemData(cmbProfile.GetCurSel()); + arProfiles[sel].hotKey = edtHotkey.SendMsg(HKM_GETHOTKEY, 0, 0); + } - SSLoadMainOptions(); + void onChange_EdtStatusMsg(CCtrlEdit*) + { + // update the status message in memory, this is done on each character tick, not nice + // but it works + TSSSetting* ps = (TSSSetting*)lstAccount.GetItemData(lstAccount.GetCurSel()); + if (ps->m_szMsg != nullptr) { + if (*ps->m_szMsg) + free(ps->m_szMsg); + ps->m_szMsg = nullptr; } - break; + int len = edtStatusMsg.SendMsg(WM_GETTEXTLENGTH, 0, 0); + ps->m_szMsg = (wchar_t*)calloc(sizeof(wchar_t), len + 1); + GetDlgItemText(m_hwnd, IDC_STATUSMSG, ps->m_szMsg, (len + 1)); + } - case WM_DESTROY: - arProfiles.destroy(); - break; + void onChange_CreateMMI(CCtrlCheck*) + { + chkInSubmenu.Enable(chkCreateMMI.GetState()); + onChange_InSubmenu(nullptr); } - return 0; -} + void onChange_InSubmenu(CCtrlCheck*) + { + bNeedRebuildMenu = TRUE; + onChange_Option(nullptr); + } + + void onChange_Option(CCtrlCheck*) + { + int sel = cmbProfile.GetItemData(cmbProfile.GetCurSel()); + PROFILEOPTIONS& po = arProfiles[sel]; + po.createMmi = chkCreateMMI.GetState(); + po.inSubMenu = chkInSubmenu.GetState(); + po.createTtb = chkCreateTTB.GetState(); + po.regHotkey = chkRegHotkey.GetState(); + po.showDialog = chkShowDialog.GetState(); + edtHotkey.Enable(chkRegHotkey.GetState()); + } + + virtual INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) override + { + switch (msg) { + case UM_ADDPROFILE: + wchar_t *tszName = (wchar_t*)lParam; + if (tszName == nullptr) + break; + + PROFILEOPTIONS* ppo = new PROFILEOPTIONS; + ppo->tszName = mir_wstrdup(tszName); + ppo->ps = GetCurrentProtoSettings(); + arProfiles.insert(ppo); + + ReinitProfiles();; + break; + } + + return CDlgBase::DlgProc(msg, wParam, lParam); + } +}; int StartupStatusOptionsInit(WPARAM wparam, LPARAM) { @@ -922,15 +929,9 @@ int StartupStatusOptionsInit(WPARAM wparam, LPARAM) Options_AddPage(wparam, &odp); odp.szTab.a = LPGEN("Status profiles"); - odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_STATUSPROFILES); - odp.pfnDlgProc = StatusProfilesOptDlgProc; + odp.pszTemplate = nullptr; + odp.pfnDlgProc = nullptr; + odp.pDialog = new CSSAdvancedOptDlg(); Options_AddPage(wparam, &odp); return 0; } - -char* OptName(int i, const char* setting) -{ - static char buf[100]; - mir_snprintf(buf, "%d_%s", i, setting); - return buf; -} diff --git a/plugins/StatusManager/src/StartupStatus/startupstatus.h b/plugins/StatusManager/src/StartupStatus/startupstatus.h index 79b82950cb..2c9f03b40e 100644 --- a/plugins/StatusManager/src/StartupStatus/startupstatus.h +++ b/plugins/StatusManager/src/StartupStatus/startupstatus.h @@ -63,11 +63,7 @@ typedef struct { } HKINFO; #define UM_REINITPROFILES WM_USER + 1 -#define UM_SETPROFILE WM_USER + 2 -#define UM_SETPROTOCOL WM_USER + 3 -#define UM_SETSTATUSMSG WM_USER + 4 #define UM_ADDPROFILE WM_USER + 5 -#define UM_DELPROFILE WM_USER + 6 #define UM_REINITDOCKED WM_USER + 7 #define UM_REINITWINSTATE WM_USER + 8 #define UM_REINITWINSIZE WM_USER + 9 |