Click here to Skip to main content
15,885,767 members
Articles / Desktop Programming / MFC

Exile 1.8 - The Password Manager

Rate me:
Please Sign up or sign in to vote.
4.57/5 (51 votes)
6 Mar 20058 min read 255.2K   7.4K   111  
Yet another password manager.
// ExportToXmlDialog.cpp : implementation file
//

#include "stdafx.h"
#include "exile.h"
#include "ExportToXmlDialog.h"
#include "predefined.h"
#include "registry.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CExportToXmlDialog dialog


CExportToXmlDialog::CExportToXmlDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CExportToXmlDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CExportToXmlDialog)
	m_strFileName = _T("");
	//}}AFX_DATA_INIT
}


void CExportToXmlDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CExportToXmlDialog)
	DDX_Control(pDX, IDOK, m_ctrlOK);
	DDX_Control(pDX, IDC_BROWSE, m_ctrlBrowse);
	DDX_Control(pDX, IDC_ENTITIESLIST, m_ctrlEntitiesList);
	DDX_Text(pDX, IDC_FILENAME, m_strFileName);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CExportToXmlDialog, CDialog)
	//{{AFX_MSG_MAP(CExportToXmlDialog)
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
	ON_NOTIFY(NM_CLICK, IDC_ENTITIESLIST, OnClickEntitieslist)
	ON_EN_CHANGE(IDC_FILENAME, OnChangeFilename)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CExportToXmlDialog message handlers

BOOL CExportToXmlDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();

	// Loading settings
	CRegistry reg;
	CString strKey;

	reg.SetRootKey(HKEY_CURRENT_USER);
	strKey.LoadString(IDS_REGKEY);
	strKey += _T("\\Export To XML");

	BOOL bKey = reg.SetKey(strKey, FALSE);

	if(bKey)
		m_strFileName = reg.ReadString("Recent File");
	
	// Adding columns
	CString strText;

	strText.LoadString(IDS_COLUMN_ENTITY);
	m_ctrlEntitiesList.InsertColumn(0, strText, LVCFMT_LEFT, bKey ? reg.ReadInt("Column 0", 130) : 130);

	strText.LoadString(IDS_COLUMN_ENTITYDESCRIPTION);
	m_ctrlEntitiesList.InsertColumn(1, strText, LVCFMT_LEFT, bKey ? reg.ReadInt("Column 1", 230) : 230);

	m_ctrlEntitiesList.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_LABELTIP);

	// Adding list contents
	LVITEM lvi;

	for(size_t i = 0; i < sizeof(g_aEntities) / sizeof(g_aEntities[0]); ++i)
	{
		lvi.mask = LVIF_TEXT | LVIF_PARAM;
		lvi.iItem = i;
		lvi.iSubItem = 0; // Item itself
		lvi.pszText = (TCHAR *)g_aEntities[i].szName;
		lvi.lParam = g_aEntities[i].nFlag; // Flags to be ORed
		lvi.cchTextMax = nNameLength;

		m_ctrlEntitiesList.InsertItem(&lvi);

		m_ctrlEntitiesList.SetItemText(i, 1, g_aEntities[i].szDescription); // Simple solution
	} // for

	UpdateData(FALSE);

	SwitchControls();	
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CExportToXmlDialog::OnDestroy() 
{
	BeginWaitCursor();

	UpdateData();

	// Saving settings
	BeginWaitCursor();
	CRegistry reg;
	CString strKey;

	reg.SetRootKey(HKEY_CURRENT_USER);
	strKey.LoadString(IDS_REGKEY);

	strKey += _T("\\Export To XML");

	if(reg.CreateKey(strKey))
	{		
		for(int n = 0; n < m_ctrlEntitiesList.GetHeaderCtrl()->GetItemCount(); ++n)
		{
			strKey.Format("Column %d", n);
			reg.WriteInt(strKey, m_ctrlEntitiesList.GetColumnWidth(n));
		} // for

		reg.WriteString(_T("Recent File"), m_strFileName);
	} // if

	EndWaitCursor();

	CDialog::OnDestroy();	
}

void CExportToXmlDialog::OnBrowse() 
{
	CString strFilter, strExt;
	strFilter.LoadString(IDS_XMLEXPORTFILTER);
	strExt.LoadString(IDS_XMLEXTENSION);

	CFileDialog dlgSave(FALSE, strExt, 0, OFN_HIDEREADONLY | OFN_NONETWORKBUTTON, strFilter, this);

	if(IDCANCEL == dlgSave.DoModal()) 
		return;

	m_strFileName = dlgSave.GetPathName();

	SwitchControls();

	UpdateData(FALSE);
}

void CExportToXmlDialog::OnClickEntitieslist(NMHDR* pNMHDR, LRESULT* pResult) 
{
	UpdateData();

	SwitchControls();

	*pResult = 0;
}

void CExportToXmlDialog::SwitchControls()
{
	m_ctrlOK.EnableWindow(!m_strFileName.IsEmpty() && m_ctrlEntitiesList.GetSelectedCount());
}

void CExportToXmlDialog::OnChangeFilename() 
{	
	UpdateData();

	SwitchControls();
}

void CExportToXmlDialog::OnOK() 
{
	// Saving export flags
	m_nExportFlags = 0;
	POSITION pos = m_ctrlEntitiesList.GetFirstSelectedItemPosition();

	while(pos)
	{
		m_nExportFlags |= m_ctrlEntitiesList.GetItemData(m_ctrlEntitiesList.GetNextSelectedItem(pos));
	} // while

	CDialog::OnOK();
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Russian Federation Russian Federation
I'll think about it later on...

Comments and Discussions