diff options
author | George Hazan <ghazan@miranda.im> | 2019-04-25 12:54:22 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2019-04-25 12:54:22 +0300 |
commit | 462deb27452322b8540f6d31230e766760b817bb (patch) | |
tree | 3b65a39d7089730a444205cb1d0f9ccad6db302c /plugins/Import/src/ui.cpp | |
parent | 644e81723335e445a7e53c6d858867ba416b31cd (diff) |
first version of pattern import that could be compiled
Diffstat (limited to 'plugins/Import/src/ui.cpp')
-rw-r--r-- | plugins/Import/src/ui.cpp | 143 |
1 files changed, 98 insertions, 45 deletions
diff --git a/plugins/Import/src/ui.cpp b/plugins/Import/src/ui.cpp index b5cb46a5ff..18bfe73a10 100644 --- a/plugins/Import/src/ui.cpp +++ b/plugins/Import/src/ui.cpp @@ -22,56 +22,109 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" -CContactImportDlg::CContactImportDlg(MCONTACT hContact) : - CDlgBase(g_plugin, IDD_IMPORT_CONTACT), - m_hContact(hContact), - edtFileName(this, IDC_FILENAME), - m_btnOk(this, IDOK), - m_btnOpenFile(this, IDC_OPEN_FILE) +class CContactImportDlg : public CDlgBase { - m_btnOk.OnClick = Callback(this, &CContactImportDlg::onClick_Ok); - m_btnOpenFile.OnClick = Callback(this, &CContactImportDlg::onClick_OpenFile); -} + MCONTACT m_hContact; + int m_flags = 0; -bool CContactImportDlg::OnInitDialog() -{ - CMStringW wszTitle(FORMAT, TranslateT("Import history for %s"), Clist_GetContactDisplayName(m_hContact)); - SetWindowTextW(m_hwnd, wszTitle); - return true; -} + CCtrlButton m_btnOpenFile, m_btnOk; + CCtrlCombo m_cmbFileType; + CCtrlEdit edtFileName; -bool CContactImportDlg::OnApply() -{ - edtFileName.GetText(importFile, _countof(importFile)); - if (importFile[0] == 0) - return false; +public: + CContactImportDlg(MCONTACT hContact) : + CDlgBase(g_plugin, IDD_IMPORT_CONTACT), + m_hContact(hContact), + edtFileName(this, IDC_FILENAME), + m_cmbFileType(this, IDC_FILETYPE), + m_btnOk(this, IDOK), + m_btnOpenFile(this, IDC_OPEN_FILE) + { + m_btnOk.OnClick = Callback(this, &CContactImportDlg::onClick_Ok); + m_btnOpenFile.OnClick = Callback(this, &CContactImportDlg::onClick_OpenFile); + } - if (IsDlgButtonChecked(m_hwnd, IDC_CHECK_DUPS)) - m_flags = IOPT_CHECKDUPS; - return true; -} + int getFlags() const { return m_flags; } -void CContactImportDlg::onClick_Ok(CCtrlButton*) -{ - EndModal(1); -} + bool OnInitDialog() override + { + CMStringW wszTitle(FORMAT, TranslateT("Import history for %s"), Clist_GetContactDisplayName(m_hContact)); + SetWindowTextW(m_hwnd, wszTitle); + + m_cmbFileType.AddString(TranslateT("Miranda NG database"), -1); + m_cmbFileType.AddString(TranslateT("JSON file"), -2); + + int iType = 1; + for (auto &it : g_plugin.m_patterns) + m_cmbFileType.AddString(it->wszName, iType++); + + return true; + } -void CContactImportDlg::onClick_OpenFile(CCtrlButton*) + bool OnApply() override + { + edtFileName.GetText(g_wszImportFile, _countof(g_wszImportFile)); + if (g_wszImportFile[0] == 0) + return false; + + if (IsDlgButtonChecked(m_hwnd, IDC_CHECK_DUPS)) + m_flags = IOPT_CHECKDUPS; + return true; + } + + void onClick_Ok(CCtrlButton*) + { + EndModal(1); + } + + void onClick_OpenFile(CCtrlButton*) + { + int iCur = m_cmbFileType.GetCurSel(); + if (iCur == -1) + return; + + CMStringW text, cmbText(ptrW(m_cmbFileType.GetText())); + switch(int idx = m_cmbFileType.GetItemData(iCur)) { + case -1: + text.AppendFormat(L"%s (*.dat,*.bak)%c*.dat;*.bak%c", cmbText.c_str(), 0, 0); + g_pActivePattern = nullptr; + break; + + case -2: + text.AppendFormat(L"%s (*.json)%c*.json%c", cmbText.c_str(), 0, 0); + g_pActivePattern = nullptr; + break; + + default: + auto &p = g_plugin.m_patterns[idx-1]; + text.AppendFormat(L"%s (*.%s)%c*.%s%c", cmbText.c_str(), p.wszExt.c_str(), 0, p.wszExt.c_str(), 0); + g_pActivePattern = &p; + break; + } + text.AppendFormat(L"%s (*.*)%c*.*%c%c", TranslateT("All Files"), 0, 0, 0); + + OPENFILENAME ofn = { 0 }; + ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; + ofn.lpstrFilter = text; + ofn.lpstrDefExt = L"dat"; + ofn.Flags = OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_DONTADDTORECENT; + ofn.lpstrFile = g_wszImportFile; + ofn.nMaxFile = _countof(g_wszImportFile); + if (!GetOpenFileNameW(&ofn)) { + g_wszImportFile[0] = 0; + g_pActivePattern = nullptr; + } + else edtFileName.SetText(g_wszImportFile); + } +}; + +INT_PTR ImportContact(WPARAM hContact, LPARAM) { - CMStringW text; - text.AppendFormat(L"%s (*.dat,*.bak)%c*.dat;*.bak%c", TranslateT("Miranda NG database"), 0, 0); - text.AppendFormat(L"%s (*.json)%c*.json%c", TranslateT("JSON file"), 0, 0); - text.AppendFormat(L"%s (*.*)%c*.*%c%c", TranslateT("All Files"), 0, 0, 0); - - OPENFILENAME ofn = { 0 }; - ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; - ofn.lpstrFilter = text; - ofn.lpstrDefExt = L"dat"; - ofn.Flags = OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_DONTADDTORECENT; - ofn.lpstrFile = importFile; - ofn.nMaxFile = _countof(importFile); - if (!GetOpenFileName(&ofn)) - importFile[0] = 0; - else - edtFileName.SetText(importFile); + CContactImportDlg dlg(hContact); + if (!dlg.DoModal()) + return 0; + + g_hImportContact = hContact; + g_iImportOptions = IOPT_HISTORY + dlg.getFlags(); + return RunWizard(new CProgressPageDlg(), true); } |