diff options
author | George Hazan <george.hazan@gmail.com> | 2015-05-20 18:21:33 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-05-20 18:21:33 +0000 |
commit | 80ecc6b2862c5de44432f930190ecfebb3030a30 (patch) | |
tree | 1d4411fc4b09fabc91be0d05eba802811c901be6 /src | |
parent | b5bb7bfe0a4da1fb1e9664da06ec708c809dbe6d (diff) |
Profile Manager -> CCtrlPages
git-svn-id: http://svn.miranda-ng.org/main/trunk@13720 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/database/profilemanager.cpp | 1188 | ||||
-rw-r--r-- | src/resource.rc | 7 |
2 files changed, 480 insertions, 715 deletions
diff --git a/src/modules/database/profilemanager.cpp b/src/modules/database/profilemanager.cpp index b562089040..4228af9aa3 100644 --- a/src/modules/database/profilemanager.cpp +++ b/src/modules/database/profilemanager.cpp @@ -35,53 +35,8 @@ void EnsureCheckerLoaded(bool); typedef BOOL (__cdecl *ENUMPROFILECALLBACK) (TCHAR *tszFullPath, TCHAR *profile, LPARAM lParam); -struct DetailsPageInit -{ - int pageCount; - OPTIONSDIALOGPAGE *odp; -}; - -struct DetailsPageData -{ - DLGTEMPLATE *pTemplate; - HINSTANCE hInst; - DLGPROC dlgProc; - HWND hwnd; - int changed; -}; - -struct DlgProfData -{ - PROPSHEETHEADER *psh; - HWND hwndOK; - PROFILEMANAGERDATA *pd; - HANDLE hFileNotify; -}; - -struct DetailsData -{ - HINSTANCE hInstIcmp; - HFONT hBoldFont; - int pageCount; - int currentPage; - DetailsPageData *opd; - RECT rcDisplay; - DlgProfData *prof; -}; - -struct ProfileEnumData -{ - HWND hwnd; - TCHAR* szProfile; -}; - void SetServiceModePlugin(pluginEntry *p); -static void ThemeDialogBackground(HWND hwnd) -{ - EnableThemeDialogTexture(hwnd, ETDT_ENABLETAB); -} - ///////////////////////////////////////////////////////////////////////////////////////// // Profile creator @@ -114,47 +69,6 @@ static int findProfiles(TCHAR *szProfileDir, ENUMPROFILECALLBACK callback, LPARA return 1; } -static int CreateProfile(TCHAR *profile, DATABASELINK *link, HWND hwndDlg) -{ - TCHAR buf[256]; - int err = 0; - // check if the file already exists - TCHAR *file = _tcsrchr(profile, '\\'); - if (file) file++; - if (_taccess(profile, 0) == 0) { - // file already exists! - mir_sntprintf(buf, SIZEOF(buf), - TranslateT("The profile '%s' already exists. Do you want to move it to the Recycle Bin?\n\nWARNING: The profile will be deleted if Recycle Bin is disabled.\nWARNING: A profile may contain confidential information and should be properly deleted."), - file); - if (MessageBox(hwndDlg, buf, TranslateT("The profile already exists"), MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2) != IDYES) - return 0; - - // move the file - SHFILEOPSTRUCT sf = {0}; - sf.wFunc = FO_DELETE; - sf.pFrom = buf; - sf.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT | FOF_ALLOWUNDO; - mir_sntprintf(buf, SIZEOF(buf), _T("%s\0"), profile); - if (SHFileOperation(&sf) != 0) { - mir_sntprintf(buf, SIZEOF(buf), TranslateT("Couldn't move '%s' to the Recycle Bin. Please select another profile name."), file); - MessageBox(0, buf, TranslateT("Problem moving profile"), MB_ICONINFORMATION|MB_OK); - return 0; - } - // now the file should be gone! - } - // ask the database to create the profile - CreatePathToFileT(profile); - if ((err = link->makeDatabase(profile)) != ERROR_SUCCESS) { - mir_sntprintf(buf, SIZEOF(buf), TranslateT("Unable to create the profile '%s', the error was %x"), file, err); - MessageBox(hwndDlg, buf, TranslateT("Problem creating profile"), MB_ICONERROR|MB_OK); - return 0; - } - - // the profile has been created! - g_bDbCreated = true; - return 1; -} - static LRESULT CALLBACK ProfileNameValidate(HWND edit, UINT msg, WPARAM wParam, LPARAM lParam) { if (msg == WM_CHAR) { @@ -165,726 +79,578 @@ static LRESULT CALLBACK ProfileNameValidate(HWND edit, UINT msg, WPARAM wParam, return mir_callNextSubclass(edit, ProfileNameValidate, msg, wParam, lParam); } -static INT_PTR CALLBACK DlgProfileNew(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +class CCreateProfileDlg : public CDlgBase { - DlgProfData *dat = (DlgProfData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - switch (msg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); - dat = (DlgProfData*)lParam; - { - HWND hwndCombo = GetDlgItem(hwndDlg, IDC_PROFILEDRIVERS); - - // what, no plugins?! - if (arDbPlugins.getCount() == 0) { - EnableWindow(hwndCombo, FALSE); - EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILENAME), FALSE); - ShowWindow(GetDlgItem(hwndDlg, IDC_NODBDRIVERS), TRUE); - } - else { - for (int i = 0; i < arDbPlugins.getCount(); i++) { - DATABASELINK *p = arDbPlugins[i]; - LRESULT index = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)TranslateTS(p->szFullName)); - SendMessage(hwndCombo, CB_SETITEMDATA, index, (LPARAM)p); - } + CCtrlButton &m_btnOk; + PROFILEMANAGERDATA *m_pd; + + int CreateProfile(TCHAR *profile, DATABASELINK *link) + { + TCHAR buf[256]; + int err = 0; + // check if the file already exists + TCHAR *file = _tcsrchr(profile, '\\'); + if (file) file++; + if (_taccess(profile, 0) == 0) { + // file already exists! + mir_sntprintf(buf, SIZEOF(buf), + TranslateT("The profile '%s' already exists. Do you want to move it to the Recycle Bin?\n\nWARNING: The profile will be deleted if Recycle Bin is disabled.\nWARNING: A profile may contain confidential information and should be properly deleted."), + file); + if (MessageBox(m_hwnd, buf, TranslateT("The profile already exists"), MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2) != IDYES) + return 0; + + // move the file + SHFILEOPSTRUCT sf = { 0 }; + sf.wFunc = FO_DELETE; + sf.pFrom = buf; + sf.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT | FOF_ALLOWUNDO; + mir_sntprintf(buf, SIZEOF(buf), _T("%s\0"), profile); + if (SHFileOperation(&sf) != 0) { + mir_sntprintf(buf, SIZEOF(buf), TranslateT("Couldn't move '%s' to the Recycle Bin. Please select another profile name."), file); + MessageBox(m_hwnd, buf, TranslateT("Problem moving profile"), MB_ICONINFORMATION | MB_OK); + return 0; } + // now the file should be gone! + } + // ask the database to create the profile + CreatePathToFileT(profile); + if ((err = link->makeDatabase(profile)) != ERROR_SUCCESS) { + mir_sntprintf(buf, SIZEOF(buf), TranslateT("Unable to create the profile '%s', the error was %x"), file, err); + MessageBox(m_hwnd, buf, TranslateT("Problem creating profile"), MB_ICONERROR | MB_OK); + return 0; + } - // default item - SendMessage(hwndCombo, CB_SETCURSEL, 0, 0); + // the profile has been created! + g_bDbCreated = true; + return 1; + } - // subclass the profile name box - mir_subclassWindow(GetDlgItem(hwndDlg, IDC_PROFILENAME), ProfileNameValidate); + CCtrlCombo m_driverList; + CCtrlEdit m_profileName; + CCtrlBase m_warning; + +public: + CCreateProfileDlg(CCtrlButton &_btn, PROFILEMANAGERDATA *_pd) : + CDlgBase(hInst, IDD_PROFILE_NEW), + m_btnOk(_btn), + m_pd(_pd), + m_driverList(this, IDC_PROFILEDRIVERS), + m_profileName(this, IDC_PROFILENAME), + m_warning(this, IDC_NODBDRIVERS) + {} + + virtual void OnInitDialog() + { + // what, no plugins?! + if (arDbPlugins.getCount() == 0) { + m_driverList.Enable(false); + m_profileName.Enable(false); + ShowWindow(m_warning.GetHwnd(), TRUE); + } + else { + for (int i = 0; i < arDbPlugins.getCount(); i++) { + DATABASELINK *p = arDbPlugins[i]; + m_driverList.AddString(TranslateTS(p->szFullName), (LPARAM)p); + } } + // default item + m_driverList.SetCurSel(0); + + // subclass the profile name box + mir_subclassWindow(m_profileName.GetHwnd(), ProfileNameValidate); + // decide if there is a default profile name given in the INI and if it should be used - if (dat->pd->noProfiles || (shouldAutoCreate(dat->pd->ptszProfile) && _taccess(dat->pd->ptszProfile, 0))) { - TCHAR *profile = _tcsrchr(dat->pd->ptszProfile, '\\'); + if (m_pd->noProfiles || (shouldAutoCreate(m_pd->ptszProfile) && _taccess(m_pd->ptszProfile, 0))) { + TCHAR *profile = _tcsrchr(m_pd->ptszProfile, '\\'); if (profile) ++profile; - else profile = dat->pd->ptszProfile; + else profile = m_pd->ptszProfile; TCHAR *p = _tcsrchr(profile, '.'); TCHAR c = 0; if (p) { c = *p; *p = 0; } - SetDlgItemText(hwndDlg, IDC_PROFILENAME, profile); + m_profileName.SetText(profile); if (c) *p = c; } // focus on the textbox - PostMessage(hwndDlg, WM_FOCUSTEXTBOX, 0, 0); - return TRUE; + PostMessage(m_hwnd, WM_FOCUSTEXTBOX, 0, 0); + } - case WM_FOCUSTEXTBOX: - SetFocus(GetDlgItem(hwndDlg, IDC_PROFILENAME)); - break; + virtual INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
+ {
+ switch (msg) {
+ case WM_FOCUSTEXTBOX: + SetFocus(m_profileName.GetHwnd()); + break; - case WM_INPUTCHANGED: // when input in the edit box changes - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - EnableWindow(dat->hwndOK, GetWindowTextLength(GetDlgItem(hwndDlg, IDC_PROFILENAME)) > 0); - break; + case WM_INPUTCHANGED: // when input in the edit box changes + NotifyChange(); + m_btnOk.Enable(GetWindowTextLength(m_profileName.GetHwnd()) > 0); + break; - case WM_SHOWWINDOW: - if (wParam) { - SetWindowText(dat->hwndOK, TranslateT("&Create")); - SendMessage(hwndDlg, WM_INPUTCHANGED, 0, 0); + case WM_SHOWWINDOW: + if (wParam) { + m_btnOk.SetText(TranslateT("&Create")); + SendMessage(m_hwnd, WM_INPUTCHANGED, 0, 0); + } + break; } - break; - - case WM_NOTIFY: - NMHDR *hdr = (NMHDR*)lParam; - if (hdr && hdr->code == PSN_APPLY && dat && IsWindowVisible(hwndDlg)) { - TCHAR szName[MAX_PATH]; - LRESULT curSel = SendDlgItemMessage(hwndDlg, IDC_PROFILEDRIVERS, CB_GETCURSEL, 0, 0); - if (curSel == CB_ERR) - break; // should never happen - - GetDlgItemText(hwndDlg, IDC_PROFILENAME, szName, SIZEOF(szName)); - if (szName[0] == 0) - break; + return CDlgBase::DlgProc(msg, wParam, lParam); + } - // profile placed in "profile_name" subfolder - mir_sntprintf(dat->pd->ptszProfile, MAX_PATH, _T("%s\\%s\\%s.dat"), dat->pd->ptszProfileDir, szName, szName); - dat->pd->newProfile = 1; - dat->pd->dblink = (DATABASELINK *)SendDlgItemMessage(hwndDlg, IDC_PROFILEDRIVERS, CB_GETITEMDATA, (WPARAM)curSel, 0); + virtual void OnApply() + { + LRESULT curSel = m_driverList.GetCurSel(); + if (curSel == -1) + return; // should never happen - if (CreateProfile(dat->pd->ptszProfile, dat->pd->dblink, hwndDlg) == 0) - SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE); - else - dat->pd->bRun = true; - } - break; - } + ptrT szName(m_profileName.GetText()); + if (szName == 0) + return; - return FALSE; -} + // profile placed in "profile_name" subfolder + mir_sntprintf(m_pd->ptszProfile, MAX_PATH, _T("%s\\%s\\%s.dat"), m_pd->ptszProfileDir, szName, szName); + m_pd->newProfile = 1; + m_pd->dblink = (DATABASELINK *)m_driverList.GetItemData(curSel); + + if (CreateProfile(m_pd->ptszProfile, m_pd->dblink) == 0) + SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE); + else + m_pd->bRun = true; + } +}; ///////////////////////////////////////////////////////////////////////////////////////// // Profile selector -BOOL EnumProfilesForList(TCHAR *tszFullPath, TCHAR *profile, LPARAM lParam) +class CChooseProfileDlg : public CDlgBase { - ProfileEnumData *ped = (ProfileEnumData*)lParam; - HWND hwndList = GetDlgItem(ped->hwnd, IDC_PROFILELIST); - - TCHAR sizeBuf[64]; - bool bFileLocked = true; - - TCHAR *p = _tcsrchr(profile, '.'); - _tcscpy(sizeBuf, _T("0 KB")); - if (p != NULL) *p = 0; - - LVITEM item = { 0 }; - item.mask = LVIF_TEXT | LVIF_IMAGE; - item.pszText = profile; - item.iItem = 0; - - struct _stat statbuf; - if (_tstat(tszFullPath, &statbuf) == 0) { - if (statbuf.st_size > 1000000) { - mir_sntprintf(sizeBuf, SIZEOF(sizeBuf), _T("%.3lf"), (double)statbuf.st_size / 1048576.0); - _tcscpy(sizeBuf + 5, _T(" MB")); + CCtrlButton &m_btnOk; + PROFILEMANAGERDATA *m_pd; + HANDLE m_hFileNotify; + + struct ProfileEnumData + { + CCtrlListView &list; + TCHAR* szProfile; + }; + + static BOOL EnumProfilesForList(TCHAR *tszFullPath, TCHAR *profile, LPARAM lParam) + { + ProfileEnumData *ped = (ProfileEnumData*)lParam; + CCtrlListView &list = ped->list; + + TCHAR sizeBuf[64]; + bool bFileLocked = true; + + TCHAR *p = _tcsrchr(profile, '.'); + _tcscpy(sizeBuf, _T("0 KB")); + if (p != NULL) *p = 0; + + LVITEM item = { 0 }; + item.mask = LVIF_TEXT | LVIF_IMAGE; + item.pszText = profile; + item.iItem = 0; + + struct _stat statbuf; + if (_tstat(tszFullPath, &statbuf) == 0) { + if (statbuf.st_size > 1000000) { + mir_sntprintf(sizeBuf, SIZEOF(sizeBuf), _T("%.3lf"), (double)statbuf.st_size / 1048576.0); + _tcscpy(sizeBuf + 5, _T(" MB")); + } + else { + mir_sntprintf(sizeBuf, SIZEOF(sizeBuf), _T("%.3lf"), (double)statbuf.st_size / 1024.0); + _tcscpy(sizeBuf + 5, _T(" KB")); + } + bFileLocked = !fileExist(tszFullPath); } - else { - mir_sntprintf(sizeBuf, SIZEOF(sizeBuf), _T("%.3lf"), (double)statbuf.st_size / 1024.0); - _tcscpy(sizeBuf + 5, _T(" KB")); + + DATABASELINK *dblink; + switch (touchDatabase(tszFullPath, &dblink)) { + case ERROR_SUCCESS: + item.iImage = bFileLocked; + break; + + case EGROKPRF_OBSOLETE: + item.iImage = 2; + break; + + default: + item.iImage = 3; } - bFileLocked = !fileExist(tszFullPath); - } - DATABASELINK *dblink; - switch (touchDatabase(tszFullPath, &dblink)) { - case ERROR_SUCCESS: - item.iImage = bFileLocked; - break; + int iItem = list.InsertItem(&item); + if (mir_tstrcmpi(ped->szProfile, tszFullPath) == 0) + list.SetItemState(iItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); + + list.SetItemText(iItem, 2, sizeBuf); - case EGROKPRF_OBSOLETE: - item.iImage = 2; - break; + if (dblink != NULL) { + if (bFileLocked) // file locked + list.SetItemText(iItem, 1, TranslateT("<In use>")); + else + list.SetItemText(iItem, 1, TranslateTS(dblink->szFullName)); + } + else list.SetItemText(iItem, 1, TranslateT("<Unknown format>")); - default: - item.iImage = 3; + return TRUE; } - int iItem = SendMessage(hwndList, LVM_INSERTITEM, 0, (LPARAM)&item); - if (mir_tstrcmpi(ped->szProfile, tszFullPath) == 0) - ListView_SetItemState(hwndList, iItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); + void CheckProfile(int iItem) + { + if (iItem < 0) + return; + + TCHAR profile[MAX_PATH], fullName[MAX_PATH]; + LVITEM item = { 0 }; + item.mask = LVIF_TEXT | LVIF_IMAGE; + item.iItem = iItem; + item.pszText = profile; + item.cchTextMax = SIZEOF(profile); + if (!m_profileList.GetItem(&item)) + return; + + mir_sntprintf(fullName, SIZEOF(fullName), _T("%s\\%s\\%s.dat"), m_pd->ptszProfileDir, profile, profile); + CallService(MS_DB_CHECKPROFILE, (WPARAM)fullName, item.iImage == 2); + } - item.iItem = iItem; - item.iSubItem = 2; - item.pszText = sizeBuf; - SendMessage(hwndList, LVM_SETITEMTEXT, iItem, (LPARAM)&item); + void DeleteProfile(int iItem) + { + if (iItem < 0) + return; - if (dblink != NULL) { - if (bFileLocked) // file locked - item.pszText = TranslateT("<In use>"); - else - item.pszText = TranslateTS(dblink->szFullName); - } - else item.pszText = TranslateT("<Unknown format>"); + TCHAR profile[MAX_PATH], profilef[MAX_PATH * 2]; - item.iSubItem = 1; - SendMessage(hwndList, LVM_SETITEMTEXT, iItem, (LPARAM)&item); - return TRUE; -} + LVITEM item = { 0 }; + item.mask = LVIF_TEXT; + item.iItem = iItem; + item.pszText = profile; + item.cchTextMax = SIZEOF(profile); + if (!m_profileList.GetItem(&item)) + return; -void CheckProfile(HWND hwndList, int iItem, DlgProfData *dat) -{ - if (iItem < 0) - return; - - TCHAR profile[MAX_PATH], fullName[MAX_PATH]; - LVITEM item = { 0 }; - item.mask = LVIF_TEXT | LVIF_IMAGE; - item.iItem = iItem; - item.pszText = profile; - item.cchTextMax = SIZEOF(profile); - if (!ListView_GetItem(hwndList, &item)) - return; - - mir_sntprintf(fullName, SIZEOF(fullName), _T("%s\\%s\\%s.dat"), dat->pd->ptszProfileDir, profile, profile); - CallService(MS_DB_CHECKPROFILE, (WPARAM)fullName, item.iImage == 2); -} + mir_sntprintf(profilef, SIZEOF(profilef), TranslateT("Are you sure you want to remove profile \"%s\"?"), profile); + if (IDYES != MessageBox(NULL, profilef, _T("Miranda NG"), MB_YESNO | MB_TASKMODAL | MB_ICONWARNING)) + return; -void DeleteProfile(HWND hwndList, int iItem, DlgProfData *dat) -{ - if (iItem < 0) - return; - - TCHAR profile[MAX_PATH], profilef[MAX_PATH * 2]; - - LVITEM item = { 0 }; - item.mask = LVIF_TEXT; - item.iItem = iItem; - item.pszText = profile; - item.cchTextMax = SIZEOF(profile); - if (!ListView_GetItem(hwndList, &item)) - return; - - mir_sntprintf(profilef, SIZEOF(profilef), TranslateT("Are you sure you want to remove profile \"%s\"?"), profile); - if (IDYES != MessageBox(NULL, profilef, _T("Miranda NG"), MB_YESNO | MB_TASKMODAL | MB_ICONWARNING)) - return; - - mir_sntprintf(profilef, SIZEOF(profilef), _T("%s\\%s%c"), dat->pd->ptszProfileDir, profile, 0); - - SHFILEOPSTRUCT sf = { 0 }; - sf.wFunc = FO_DELETE; - sf.pFrom = profilef; - sf.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_ALLOWUNDO; - SHFileOperation(&sf); - ListView_DeleteItem(hwndList, item.iItem); -} + mir_sntprintf(profilef, SIZEOF(profilef), _T("%s\\%s%c"), m_pd->ptszProfileDir, profile, 0); -static void CheckRun(HWND hwndDlg, int uMsg) -{ - DlgProfData *dat = (DlgProfData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - if (dat == NULL) - return; - - HWND hwndList = GetDlgItem(hwndDlg, IDC_PROFILELIST); - EnableWindow(dat->hwndOK, ListView_GetSelectedCount(hwndList) == 1); - - TCHAR profile[MAX_PATH]; - LVITEM item = { 0 }; - item.mask = LVIF_TEXT | LVIF_IMAGE; - item.iItem = ListView_GetNextItem(hwndList, -1, LVNI_SELECTED | LVNI_ALL); - item.pszText = profile; - item.cchTextMax = SIZEOF(profile); - if (!ListView_GetItem(hwndList, &item)) - return; - - switch(item.iImage) { - case 3: - EnableWindow(dat->hwndOK, false); - return; - - case 2: - SetWindowText(dat->hwndOK, TranslateT("&Convert")); - dat->pd->bRun = false; - break; - - default: - SetWindowText(dat->hwndOK, TranslateT("&Run")); - dat->pd->bRun = true; + SHFILEOPSTRUCT sf = { 0 }; + sf.wFunc = FO_DELETE; + sf.pFrom = profilef; + sf.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_ALLOWUNDO; + SHFileOperation(&sf); + m_profileList.DeleteItem(item.iItem); } - // profile is placed in "profile_name" subfolder + void CheckRun(int uMsg) + { + m_btnOk.Enable(m_profileList.GetSelectedCount() == 1); + + TCHAR profile[MAX_PATH]; + LVITEM item = { 0 }; + item.mask = LVIF_TEXT | LVIF_IMAGE; + item.iItem = m_profileList.GetNextItem(-1, LVNI_SELECTED | LVNI_ALL); + item.pszText = profile; + item.cchTextMax = SIZEOF(profile); + if (!m_profileList.GetItem(&item)) + return; + + switch(item.iImage) { + case 3: + m_btnOk.Enable(false); + return; + + case 2: + m_btnOk.SetText(TranslateT("&Convert")); + m_pd->bRun = false; + break; - TCHAR tmpPath[MAX_PATH]; - mir_sntprintf(tmpPath, SIZEOF(tmpPath), _T("%s\\%s.dat"), dat->pd->ptszProfileDir, profile); - if (_taccess(tmpPath, 2)) - mir_sntprintf(dat->pd->ptszProfile, MAX_PATH, _T("%s\\%s\\%s.dat"), dat->pd->ptszProfileDir, profile, profile); - else - _tcsncpy_s(dat->pd->ptszProfile, MAX_PATH, tmpPath, _TRUNCATE); + default: + m_btnOk.SetText(TranslateT("&Run")); + m_pd->bRun = true; + } - if (uMsg == NM_DBLCLK) - EndDialog(GetParent(hwndDlg), 1); -} + // profile is placed in "profile_name" subfolder -static void ExecuteMenu(HWND hwndDlg, LPARAM lParam) -{ - HWND hwndList = GetDlgItem(hwndDlg, IDC_PROFILELIST); - DlgProfData *dat = (DlgProfData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + TCHAR tmpPath[MAX_PATH]; + mir_sntprintf(tmpPath, SIZEOF(tmpPath), _T("%s\\%s.dat"), m_pd->ptszProfileDir, profile); + if (_taccess(tmpPath, 2)) + mir_sntprintf(m_pd->ptszProfile, MAX_PATH, _T("%s\\%s\\%s.dat"), m_pd->ptszProfileDir, profile, profile); + else + _tcsncpy_s(m_pd->ptszProfile, MAX_PATH, tmpPath, _TRUNCATE); - LVHITTESTINFO lvht = { 0 }; - lvht.pt.x = GET_X_LPARAM(lParam); - lvht.pt.y = GET_Y_LPARAM(lParam); - ScreenToClient(hwndList, &lvht.pt); + if (uMsg == NM_DBLCLK) + EndDialog(GetParent(m_hwnd), 1); + } + + void ExecuteMenu(LPARAM lParam) + { + LVHITTESTINFO lvht = { 0 }; + lvht.pt.x = GET_X_LPARAM(lParam); + lvht.pt.y = GET_Y_LPARAM(lParam); + ScreenToClient(m_profileList.GetHwnd(), &lvht.pt); - if (ListView_HitTest(hwndList, &lvht) == -1) - return; + if (m_profileList.HitTest(&lvht) == -1) + return; - if (lvht.iItem == -1) - return; + if (lvht.iItem == -1) + return; - LVITEM tvi = { 0 }; - tvi.mask = LVIF_IMAGE; - tvi.iItem = lvht.iItem; - if (!ListView_GetItem(hwndList, &tvi)) - return; + LVITEM tvi = { 0 }; + tvi.mask = LVIF_IMAGE; + tvi.iItem = lvht.iItem; + if (!m_profileList.GetItem(&tvi)) + return; - bool bConvert = (tvi.iImage == 2); + bool bConvert = (tvi.iImage == 2); - lvht.pt.x = GET_X_LPARAM(lParam); - lvht.pt.y = GET_Y_LPARAM(lParam); + lvht.pt.x = GET_X_LPARAM(lParam); + lvht.pt.y = GET_Y_LPARAM(lParam); - HMENU hMenu = CreatePopupMenu(); - if (tvi.iImage < 2) { - AppendMenu(hMenu, MF_STRING, 1, TranslateT("Run")); - AppendMenu(hMenu, MF_SEPARATOR, 0, NULL); + HMENU hMenu = CreatePopupMenu(); + if (tvi.iImage < 2) { + AppendMenu(hMenu, MF_STRING, 1, TranslateT("Run")); + AppendMenu(hMenu, MF_SEPARATOR, 0, NULL); + } + if (tvi.iImage != 3 && ServiceExists(MS_DB_CHECKPROFILE)) { + if (bConvert) + AppendMenu(hMenu, MF_STRING, 2, TranslateT("Convert database")); + else + AppendMenu(hMenu, MF_STRING, 2, TranslateT("Check database")); + AppendMenu(hMenu, MF_SEPARATOR, 0, NULL); + } + AppendMenu(hMenu, MF_STRING, 3, TranslateT("Delete")); + int index = TrackPopupMenu(hMenu, TPM_RETURNCMD, lvht.pt.x, lvht.pt.y, 0, m_hwnd, NULL); + switch (index) { + case 1: + SendMessage(GetParent(m_hwnd), WM_COMMAND, IDOK, 0); + break; + + case 2: + CheckProfile(lvht.iItem); + break; + + case 3: + DeleteProfile(lvht.iItem); + break; + } + DestroyMenu(hMenu); } - if (tvi.iImage != 3 && ServiceExists(MS_DB_CHECKPROFILE)) { - if (bConvert) - AppendMenu(hMenu, MF_STRING, 2, TranslateT("Convert database")); - else - AppendMenu(hMenu, MF_STRING, 2, TranslateT("Check database")); - AppendMenu(hMenu, MF_SEPARATOR, 0, NULL); + + CCtrlListView m_profileList; + +public: + CChooseProfileDlg(CCtrlButton &_btn, PROFILEMANAGERDATA *_pd) : + CDlgBase(hInst, IDD_PROFILE_SELECTION), + m_btnOk(_btn), + m_pd(_pd), + m_profileList(this, IDC_PROFILELIST) + {} + + virtual void OnInitDialog() + { + // set columns + LVCOLUMN col; + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.pszText = TranslateT("Profile"); + col.cx = 100; + m_profileList.InsertColumn(0, &col); + + col.pszText = TranslateT("Driver"); + col.cx = 150 - GetSystemMetrics(SM_CXVSCROLL); + m_profileList.InsertColumn(1, &col); + + col.pszText = TranslateT("Size"); + col.cx = 60; + m_profileList.InsertColumn(2, &col); + + // icons + HIMAGELIST hImgList = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 2, 1); + ImageList_AddIcon_NotShared(hImgList, MAKEINTRESOURCE(IDI_USERDETAILS)); + ImageList_AddIcon_NotShared(hImgList, MAKEINTRESOURCE(IDI_DELETE)); + ImageList_AddIcon_NotShared(hImgList, MAKEINTRESOURCE(IDI_MWARNING)); + ImageList_AddIcon_NotShared(hImgList, MAKEINTRESOURCE(IDI_MFATAL)); + + // LV will destroy the image list + m_profileList.SetImageList(hImgList, LVSIL_SMALL); + m_profileList.SetExtendedListViewStyle(m_profileList.GetExtendedListViewStyle() | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_LABELTIP | LVS_EX_FULLROWSELECT); + + // find all the profiles + ProfileEnumData ped = { m_profileList, m_pd->ptszProfile }; + findProfiles(m_pd->ptszProfileDir, EnumProfilesForList, (LPARAM)&ped); + PostMessage(m_hwnd, WM_FOCUSTEXTBOX, 0, 0); + + m_hFileNotify = FindFirstChangeNotification(m_pd->ptszProfileDir, TRUE, FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE); + if (m_hFileNotify != INVALID_HANDLE_VALUE) + SetTimer(m_hwnd, 0, 1200, NULL); } - AppendMenu(hMenu, MF_STRING, 3, TranslateT("Delete")); - int index = TrackPopupMenu(hMenu, TPM_RETURNCMD, lvht.pt.x, lvht.pt.y, 0, hwndDlg, NULL); - switch (index) { - case 1: - SendMessage(GetParent(hwndDlg), WM_COMMAND, IDOK, 0); - break; - - case 2: - CheckProfile(hwndList, lvht.iItem, dat); - break; - - case 3: - DeleteProfile(hwndList, lvht.iItem, dat); - break; + + virtual void OnDestroy() + { + KillTimer(m_hwnd, 0); + FindCloseChangeNotification(m_hFileNotify); } - DestroyMenu(hMenu); -} -static INT_PTR CALLBACK DlgProfileSelect(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - DlgProfData *dat = (DlgProfData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - HWND hwndList = GetDlgItem(hwndDlg, IDC_PROFILELIST); - - switch (msg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - { - dat = (DlgProfData*)lParam; - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); - - // set columns - LVCOLUMN col; - col.mask = LVCF_TEXT | LVCF_WIDTH; - col.pszText = TranslateT("Profile"); - col.cx = 100; - ListView_InsertColumn(hwndList, 0, &col); - - col.pszText = TranslateT("Driver"); - col.cx = 150 - GetSystemMetrics(SM_CXVSCROLL); - ListView_InsertColumn(hwndList, 1, &col); - - col.pszText = TranslateT("Size"); - col.cx = 60; - ListView_InsertColumn(hwndList, 2, &col); - - // icons - HIMAGELIST hImgList = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 2, 1); - ImageList_AddIcon_NotShared(hImgList, MAKEINTRESOURCE(IDI_USERDETAILS)); - ImageList_AddIcon_NotShared(hImgList, MAKEINTRESOURCE(IDI_DELETE)); - ImageList_AddIcon_NotShared(hImgList, MAKEINTRESOURCE(IDI_MWARNING)); - ImageList_AddIcon_NotShared(hImgList, MAKEINTRESOURCE(IDI_MFATAL)); - - // LV will destroy the image list - SetWindowLongPtr(hwndList, GWL_STYLE, GetWindowLongPtr(hwndList, GWL_STYLE) | LVS_SORTASCENDING); - ListView_SetImageList(hwndList, hImgList, LVSIL_SMALL); - ListView_SetExtendedListViewStyle(hwndList, - ListView_GetExtendedListViewStyle(hwndList) | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_LABELTIP | LVS_EX_FULLROWSELECT); - - // find all the profiles - ProfileEnumData ped = { hwndDlg, dat->pd->ptszProfile }; - findProfiles(dat->pd->ptszProfileDir, EnumProfilesForList, (LPARAM)&ped); - PostMessage(hwndDlg, WM_FOCUSTEXTBOX, 0, 0); - - dat->hFileNotify = FindFirstChangeNotification(dat->pd->ptszProfileDir, TRUE, FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE); - if (dat->hFileNotify != INVALID_HANDLE_VALUE) - SetTimer(hwndDlg, 0, 1200, NULL); - return TRUE; - } + virtual INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
+ {
+ switch (msg) {
+ case WM_TIMER: + if (WaitForSingleObject(m_hFileNotify, 0) == WAIT_OBJECT_0) { + m_profileList.DeleteAllItems(); + ProfileEnumData ped = { m_profileList, m_pd->ptszProfile }; + findProfiles(m_pd->ptszProfileDir, EnumProfilesForList, (LPARAM)&ped); + FindNextChangeNotification(m_hFileNotify); + } + break; - case WM_DESTROY: - KillTimer(hwndDlg, 0); - FindCloseChangeNotification(dat->hFileNotify); - break; - - case WM_TIMER: - if (WaitForSingleObject(dat->hFileNotify, 0) == WAIT_OBJECT_0) { - ListView_DeleteAllItems(hwndList); - ProfileEnumData ped = { hwndDlg, dat->pd->ptszProfile }; - findProfiles(dat->pd->ptszProfileDir, EnumProfilesForList, (LPARAM)&ped); - FindNextChangeNotification(dat->hFileNotify); - } - break; - - case WM_FOCUSTEXTBOX: - SetFocus(hwndList); - if (dat->pd->ptszProfile[0] == 0 || ListView_GetSelectedCount(hwndList) == 0) - ListView_SetItemState(hwndList, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); - break; - - case WM_SHOWWINDOW: - if (wParam) - CheckRun(hwndDlg, 0); - break; - - case WM_CONTEXTMENU: - ExecuteMenu(hwndDlg, lParam); - break; - - case WM_NOTIFY: - LPNMHDR hdr = (LPNMHDR)lParam; - if (hdr == NULL) + case WM_FOCUSTEXTBOX: + SetFocus(m_profileList.GetHwnd()); + if (m_pd->ptszProfile[0] == 0 || m_profileList.GetSelectedCount() == 0) + m_profileList.SetItemState(0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); break; - if (hdr->idFrom == 0) { - CheckRun(hwndDlg, 0); + case WM_SHOWWINDOW: + if (wParam) + CheckRun(0); break; - } - if (hdr->idFrom == IDC_PROFILELIST) { - switch (hdr->code) { - case LVN_ITEMCHANGED: - case NM_DBLCLK: - CheckRun(hwndDlg, hdr->code); - return TRUE; + case WM_CONTEXTMENU: + ExecuteMenu(lParam); + break; - case LVN_KEYDOWN: - if (((LPNMLVKEYDOWN)lParam)->wVKey == VK_DELETE) - DeleteProfile(hwndList, ListView_GetNextItem(hwndList, -1, LVNI_SELECTED | LVNI_ALL), dat); + case WM_NOTIFY: + LPNMHDR hdr = (LPNMHDR)lParam; + if (hdr == NULL) break; - case LVN_GETINFOTIP: - NMLVGETINFOTIP *pInfoTip = (NMLVGETINFOTIP *)lParam; - if (pInfoTip != NULL) { - TCHAR profilename[MAX_PATH], tszFullPath[MAX_PATH]; - struct _stat statbuf; - ListView_GetItemText(hwndList, pInfoTip->iItem, 0, profilename, SIZEOF(profilename)); - mir_sntprintf(tszFullPath, SIZEOF(tszFullPath), _T("%s\\%s\\%s.dat"), dat->pd->ptszProfileDir, profilename, profilename); - _tstat(tszFullPath, &statbuf); - mir_sntprintf(pInfoTip->pszText, pInfoTip->cchTextMax, _T("%s\n%s: %s\n%s: %s"), tszFullPath, TranslateT("Created"), rtrimt(NEWTSTR_ALLOCA(_tctime(&statbuf.st_ctime))), TranslateT("Modified"), rtrimt(NEWTSTR_ALLOCA(_tctime(&statbuf.st_mtime)))); + if (hdr->idFrom == 0) { + CheckRun(0); + break; + } + + if (hdr->idFrom == IDC_PROFILELIST) { + switch (hdr->code) { + case LVN_ITEMCHANGED: + case NM_DBLCLK: + CheckRun(hdr->code); + return TRUE; + + case LVN_KEYDOWN: + if (((LPNMLVKEYDOWN)lParam)->wVKey == VK_DELETE) + DeleteProfile(m_profileList.GetNextItem(-1, LVNI_SELECTED | LVNI_ALL)); + break; + + case LVN_GETINFOTIP: + NMLVGETINFOTIP *pInfoTip = (NMLVGETINFOTIP *)lParam; + if (pInfoTip != NULL) { + TCHAR profilename[MAX_PATH], tszFullPath[MAX_PATH]; + struct _stat statbuf; + m_profileList.GetItemText(pInfoTip->iItem, 0, profilename, SIZEOF(profilename)); + mir_sntprintf(tszFullPath, SIZEOF(tszFullPath), _T("%s\\%s\\%s.dat"), m_pd->ptszProfileDir, profilename, profilename); + _tstat(tszFullPath, &statbuf); + mir_sntprintf(pInfoTip->pszText, pInfoTip->cchTextMax, _T("%s\n%s: %s\n%s: %s"), tszFullPath, TranslateT("Created"), rtrimt(NEWTSTR_ALLOCA(_tctime(&statbuf.st_ctime))), TranslateT("Modified"), rtrimt(NEWTSTR_ALLOCA(_tctime(&statbuf.st_mtime)))); + } } } + break; } - break; - } - return FALSE; -} + return CDlgBase::DlgProc(msg, wParam, lParam); + } +}; ///////////////////////////////////////////////////////////////////////////////////////// // Tab manager + its envelope -static INT_PTR CALLBACK DlgProfileManager(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +class CProfileManager : public CDlgBase { - DetailsData *dat = (DetailsData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - - switch (msg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - { - DlgProfData *prof = (DlgProfData*)lParam; - PROPSHEETHEADER *psh = prof->psh; - SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadImage(hInst, MAKEINTRESOURCE(IDI_DETAILSLOGO), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0)); - SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadImage(hInst, MAKEINTRESOURCE(IDI_DETAILSLOGO), IMAGE_ICON, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 0)); - dat = (DetailsData*)mir_alloc(sizeof(DetailsData)); - dat->prof = prof; - prof->hwndOK = GetDlgItem(hwndDlg, IDOK); - EnableWindow(prof->hwndOK, FALSE); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); - - SetDlgItemText(hwndDlg, IDC_NAME, TranslateT("Manage your Miranda NG profile")); - - dat->currentPage = 0; - dat->pageCount = psh->nPages; - dat->opd = (DetailsPageData*)mir_calloc(sizeof(DetailsPageData)*dat->pageCount); - OPTIONSDIALOGPAGE *odp = (OPTIONSDIALOGPAGE*)psh->ppsp; - - TCITEM tci; - tci.mask = TCIF_TEXT; - for (int i = 0; i < dat->pageCount; i++) { - dat->opd[i].pTemplate = (DLGTEMPLATE*)LockResource(LoadResource(odp[i].hInstance, FindResourceA(odp[i].hInstance, odp[i].pszTemplate, MAKEINTRESOURCEA(5)))); - dat->opd[i].dlgProc = odp[i].pfnDlgProc; - dat->opd[i].hInst = odp[i].hInstance; - dat->opd[i].hwnd = NULL; - dat->opd[i].changed = 0; - tci.pszText = (TCHAR*)odp[i].ptszTitle; - if (dat->prof->pd->noProfiles || shouldAutoCreate(dat->prof->pd->ptszProfile)) - dat->currentPage = 1; - TabCtrl_InsertItem(GetDlgItem(hwndDlg, IDC_TABS), i, &tci); - } - - GetWindowRect(GetDlgItem(hwndDlg, IDC_TABS), &dat->rcDisplay); - TabCtrl_AdjustRect(GetDlgItem(hwndDlg, IDC_TABS), FALSE, &dat->rcDisplay); - - POINT pt = { 0, 0 }; - ClientToScreen(hwndDlg, &pt); - OffsetRect(&dat->rcDisplay, -pt.x, -pt.y); - - TabCtrl_SetCurSel(GetDlgItem(hwndDlg, IDC_TABS), dat->currentPage); - dat->opd[dat->currentPage].hwnd = CreateDialogIndirectParam(dat->opd[dat->currentPage].hInst, dat->opd[dat->currentPage].pTemplate, hwndDlg, dat->opd[dat->currentPage].dlgProc, (LPARAM)dat->prof); - ThemeDialogBackground(dat->opd[dat->currentPage].hwnd); - SetWindowPos(dat->opd[dat->currentPage].hwnd, HWND_TOP, dat->rcDisplay.left, dat->rcDisplay.top, 0, 0, SWP_NOSIZE); - - PSHNOTIFY pshn; - pshn.hdr.code = PSN_INFOCHANGED; - pshn.hdr.hwndFrom = dat->opd[dat->currentPage].hwnd; - pshn.hdr.idFrom = 0; - pshn.lParam = 0; - SendMessage(dat->opd[dat->currentPage].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn); - - // service mode combobox - if (servicePlugins.getCount() == 0) { - ShowWindow(GetDlgItem(hwndDlg, IDC_SM_LABEL), FALSE); - ShowWindow(GetDlgItem(hwndDlg, IDC_SM_COMBO), FALSE); - } - else { - HWND hwndCombo = GetDlgItem(hwndDlg, IDC_SM_COMBO); - LRESULT index = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)_T("")); - SendMessage(hwndCombo, CB_SETITEMDATA, index, (LPARAM)-1); - SendMessage(hwndCombo, CB_SETCURSEL, 0, 0); - for (int i = 0; i < servicePlugins.getCount(); i++) { - pluginEntry *p = servicePlugins[i]; - index = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)TranslateTS(p->pluginname)); - SendMessage(hwndCombo, CB_SETITEMDATA, index, (LPARAM)i); - } - } - ShowWindow(dat->opd[dat->currentPage].hwnd, SW_SHOW); - } - return TRUE; + PROFILEMANAGERDATA *m_pd; + + CCtrlPages m_tab; + CCtrlButton m_btnOk; + CCtrlCombo m_servicePlugs; + CCtrlBase m_warning; + +public: + CProfileManager(PROFILEMANAGERDATA *_pd) : + CDlgBase(hInst, IDD_PROFILEMANAGER), + m_btnOk(this, IDOK), + m_pd(_pd), + m_tab(this, IDC_TABS), + m_servicePlugs(this, IDC_SM_COMBO), + m_warning(this, IDC_SM_LABEL) + { + m_btnOk.OnClick = Callback(this, &CProfileManager::onOk); + + m_tab.AddPage(LPGENT("My profiles"), NULL, new CChooseProfileDlg(m_btnOk, m_pd)); + m_tab.AddPage(LPGENT("New profile"), NULL, new CCreateProfileDlg(m_btnOk, m_pd)); + } + + virtual void OnInitDialog() + { + SendMessage(m_hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadImage(hInst, MAKEINTRESOURCE(IDI_DETAILSLOGO), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0)); + SendMessage(m_hwnd, WM_SETICON, ICON_BIG, (LPARAM)LoadImage(hInst, MAKEINTRESOURCE(IDI_DETAILSLOGO), IMAGE_ICON, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 0)); - case WM_CTLCOLORSTATIC: - switch (GetDlgCtrlID((HWND)lParam)) { - case IDC_WHITERECT: - SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW)); - return (INT_PTR)GetSysColorBrush(COLOR_WINDOW); - } - break; + if (m_pd->noProfiles || shouldAutoCreate(m_pd->ptszProfile)) + m_tab.ActivatePage(1); - case PSM_CHANGED: - dat->opd[dat->currentPage].changed = 1; - return TRUE; + m_btnOk.Enable(false); - case PSM_FORCECHANGED: - { - PSHNOTIFY pshn; - pshn.hdr.code = PSN_INFOCHANGED; - pshn.hdr.idFrom = 0; - pshn.lParam = 0; - for (int i = 0; i < dat->pageCount; i++) { - pshn.hdr.hwndFrom = dat->opd[i].hwnd; - if (dat->opd[i].hwnd != NULL) - SendMessage(dat->opd[i].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn); - } + // service mode combobox + if (servicePlugins.getCount() == 0) { + ShowWindow(m_warning.GetHwnd(), FALSE); + ShowWindow(m_servicePlugs.GetHwnd(), FALSE); } - break; - - case WM_NOTIFY: - switch (wParam) { - case IDC_TABS: - switch (((LPNMHDR)lParam)->code) { - case TCN_SELCHANGING: - if (dat->currentPage != -1 && dat->opd[dat->currentPage].hwnd != NULL) { - PSHNOTIFY pshn; - pshn.hdr.code = PSN_KILLACTIVE; - pshn.hdr.hwndFrom = dat->opd[dat->currentPage].hwnd; - pshn.hdr.idFrom = 0; - pshn.lParam = 0; - if (SendMessage(dat->opd[dat->currentPage].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn)) { - SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE); - return TRUE; - } - } - break; + else { + m_servicePlugs.AddStringA("", -1); + m_servicePlugs.SetCurSel(0); - case TCN_SELCHANGE: - if (dat->currentPage != -1 && dat->opd[dat->currentPage].hwnd != NULL) - ShowWindow(dat->opd[dat->currentPage].hwnd, SW_HIDE); - - dat->currentPage = TabCtrl_GetCurSel(GetDlgItem(hwndDlg, IDC_TABS)); - if (dat->currentPage != -1) { - if (dat->opd[dat->currentPage].hwnd == NULL) { - PSHNOTIFY pshn; - dat->opd[dat->currentPage].hwnd = CreateDialogIndirectParam(dat->opd[dat->currentPage].hInst, dat->opd[dat->currentPage].pTemplate, hwndDlg, dat->opd[dat->currentPage].dlgProc, (LPARAM)dat->prof); - ThemeDialogBackground(dat->opd[dat->currentPage].hwnd); - SetWindowPos(dat->opd[dat->currentPage].hwnd, HWND_TOP, dat->rcDisplay.left, dat->rcDisplay.top, 0, 0, SWP_NOSIZE); - pshn.hdr.code = PSN_INFOCHANGED; - pshn.hdr.hwndFrom = dat->opd[dat->currentPage].hwnd; - pshn.hdr.idFrom = 0; - pshn.lParam = 0; - SendMessage(dat->opd[dat->currentPage].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn); - } - ShowWindow(dat->opd[dat->currentPage].hwnd, SW_SHOW); - } - break; + for (int i = 0; i < servicePlugins.getCount(); i++) { + pluginEntry *p = servicePlugins[i]; + m_servicePlugs.AddString(TranslateTS(p->pluginname), i); } - break; } - break; - - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDCANCEL: - { - PSHNOTIFY pshn; - pshn.hdr.idFrom = 0; - pshn.lParam = 0; - pshn.hdr.code = PSN_RESET; - for (int i = 0; i < dat->pageCount; i++) { - if (dat->opd[i].hwnd == NULL || !dat->opd[i].changed) - continue; - - pshn.hdr.hwndFrom = dat->opd[i].hwnd; - SendMessage(dat->opd[i].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn); - } - EndDialog(hwndDlg, 0); - } - break; + } - case IDC_REMOVE: - if (!dat->prof->pd->noProfiles) { - HWND hwndList = GetDlgItem(dat->opd[0].hwnd, IDC_PROFILELIST); - DeleteProfile(hwndList, ListView_GetNextItem(hwndList, -1, LVNI_SELECTED | LVNI_ALL), dat->prof); + virtual INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
+ {
+ switch (msg) {
+ case WM_CTLCOLORSTATIC: + switch (GetDlgCtrlID((HWND)lParam)) { + case IDC_WHITERECT: + SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW)); + return (INT_PTR)GetSysColorBrush(COLOR_WINDOW); } break; - - case IDOK: - PSHNOTIFY pshn; - pshn.hdr.idFrom = 0; - pshn.lParam = 0; - if (dat->currentPage != -1) { - pshn.hdr.code = PSN_KILLACTIVE; - pshn.hdr.hwndFrom = dat->opd[dat->currentPage].hwnd; - if (SendMessage(dat->opd[dat->currentPage].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn)) - break; - } - - pshn.hdr.code = PSN_APPLY; - for (int i = 0; i < dat->pageCount; i++) { - if (dat->opd[i].hwnd == NULL || !dat->opd[i].changed) - continue; - - pshn.hdr.hwndFrom = dat->opd[i].hwnd; - SendMessage(dat->opd[i].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn); - if (GetWindowLongPtr(dat->opd[i].hwnd, DWLP_MSGRESULT) == PSNRET_INVALID_NOCHANGEPAGE) { - TabCtrl_SetCurSel(GetDlgItem(hwndDlg, IDC_TABS), i); - if (dat->currentPage != -1) - ShowWindow(dat->opd[dat->currentPage].hwnd, SW_HIDE); - dat->currentPage = i; - ShowWindow(dat->opd[dat->currentPage].hwnd, SW_SHOW); - return 0; - } - } - EndDialog(hwndDlg, 1); } - break; + return CDlgBase::DlgProc(msg, wParam, lParam); + } - case WM_DESTROY: - LRESULT curSel = SendDlgItemMessage(hwndDlg, IDC_SM_COMBO, CB_GETCURSEL, 0, 0); - if (curSel != CB_ERR) { - int idx = SendDlgItemMessage(hwndDlg, IDC_SM_COMBO, CB_GETITEMDATA, (WPARAM)curSel, 0); - if (idx != CB_ERR) + virtual void OnDestroy() + { + LRESULT curSel = m_servicePlugs.GetCurSel(); + if (curSel != -1) { + int idx = m_servicePlugs.GetItemData(curSel); + if (idx != -1) SetServiceModePlugin(servicePlugins[idx]); } - DestroyIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, 0)); - DestroyIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0)); - DeleteObject(dat->hBoldFont); - - for (int i = 0; i < dat->pageCount; i++) - if (dat->opd[i].hwnd != NULL) - DestroyWindow(dat->opd[i].hwnd); - - mir_free(dat->opd); - mir_free(dat); - break; + DestroyIcon((HICON)SendMessage(m_hwnd, WM_SETICON, ICON_SMALL, 0)); + DestroyIcon((HICON)SendMessage(m_hwnd, WM_SETICON, ICON_BIG, 0)); } - return FALSE; -} -static int AddProfileManagerPage(struct DetailsPageInit *opi, OPTIONSDIALOGPAGE *odp) -{ - opi->odp = (OPTIONSDIALOGPAGE*)mir_realloc(opi->odp, sizeof(OPTIONSDIALOGPAGE)*(opi->pageCount + 1)); - - OPTIONSDIALOGPAGE *p = opi->odp + opi->pageCount++; - p->hInstance = odp->hInstance; - p->pfnDlgProc = odp->pfnDlgProc; - p->position = odp->position; - p->ptszTitle = Langpack_PcharToTchar(odp->pszTitle); - p->pszGroup = NULL; - p->groupPosition = odp->groupPosition; - p->hGroupIcon = odp->hGroupIcon; - p->hIcon = odp->hIcon; - if ((DWORD_PTR)odp->pszTemplate & 0xFFFF0000) - p->pszTemplate = mir_strdup(odp->pszTemplate); - else - p->pszTemplate = odp->pszTemplate; - return 0; -} + void onOk(CCtrlButton*) + { + EndDialog(m_hwnd, 1); + } +}; int getProfileManager(PROFILEMANAGERDATA *pd) { EnsureCheckerLoaded(true); - DetailsPageInit opi = { 0 }; - - OPTIONSDIALOGPAGE odp = { 0 }; - odp.pszTitle = LPGEN("My profiles"); - odp.pfnDlgProc = DlgProfileSelect; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_PROFILE_SELECTION); - odp.hInstance = hInst; - AddProfileManagerPage(&opi, &odp); - - odp.pszTitle = LPGEN("New profile"); - odp.pszTemplate = MAKEINTRESOURCEA(IDD_PROFILE_NEW); - odp.pfnDlgProc = DlgProfileNew; - AddProfileManagerPage(&opi, &odp); - - PROPSHEETHEADER psh = { 0 }; - psh.dwSize = sizeof(psh); - psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW; - psh.nPages = opi.pageCount; - psh.ppsp = (PROPSHEETPAGE*)opi.odp; - - DlgProfData prof; - prof.pd = pd; - prof.psh = &psh; - int rc = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_PROFILEMANAGER), NULL, DlgProfileManager, (LPARAM)&prof); - if (rc != -1) { - for (int i = 0; i < opi.pageCount; i++) { - mir_free(opi.odp[i].pszTitle); - mir_free(opi.odp[i].pszGroup); - if ((DWORD_PTR)opi.odp[i].pszTemplate & 0xFFFF0000) - mir_free((char*)opi.odp[i].pszTemplate); - } - } - mir_free(opi.odp); - - return rc; + return CProfileManager(pd).DoModal(); } diff --git a/src/resource.rc b/src/resource.rc index 11bb217691..31ab3dab7b 100644 --- a/src/resource.rc +++ b/src/resource.rc @@ -91,7 +91,7 @@ CAPTION "Miranda NG profile manager" FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
CONTROL "Manage your Miranda NG profile",IDC_NAME,"MHeaderbarCtrl",0x0,0,0,220,25
- CONTROL "Tab1",IDC_TABS,"SysTabControl32",TCS_HOTTRACK | WS_TABSTOP,2,31,215,137
+ CONTROL "Tab1",IDC_TABS,"SysTabControl32",TCS_HOTTRACK,2,31,215,137
PUSHBUTTON "&Run",IDOK,169,195,48,14
PUSHBUTTON "&Exit",IDCANCEL,112,195,48,14
RTEXT "Start in service mode with",IDC_SM_LABEL,10,178,106,10
@@ -387,7 +387,7 @@ BEGIN END
IDD_PROFILE_SELECTION DIALOGEX 0, 0, 208, 122
-STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | DS_CONTROL
EXSTYLE WS_EX_CONTROLPARENT
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
@@ -395,8 +395,7 @@ BEGIN END
IDD_PROFILE_NEW DIALOGEX 0, 0, 208, 122
-STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN
-EXSTYLE WS_EX_CONTROLPARENT
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | DS_CONTROL
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
LTEXT "Please complete the following form to create a new user profile",IDC_STATIC,4,3,205,16
|