Click here to Skip to main content
15,887,214 members
Articles / Desktop Programming / MFC

A reminder tool for .dan.g's ToDoList

Rate me:
Please Sign up or sign in to vote.
3.60/5 (14 votes)
25 Feb 2004 152.8K   3.4K   61  
A simple reminder tool to remind you of your overdue tasks in ToDoList throughout the day
// ToDoListReaderWriter.cpp: implementation of the CToDoListReaderWriter class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "TDLReminderTool.h"
#include "ToDoListReaderWriter.h"
#include "Task.h"

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

#define TODOLIST		"TODOLIST"
#define TASK			"TASK"
#define STARTDATESTRING "STARTDATESTRING"
#define PRIORITY		"PRIORITY"
#define DUEDATESTRING	"DUEDATESTRING"
#define TITLE			"TITLE"
#define PERSON			"PERSON"
#define TIMEESTIMATE	"TIMEESTIMATE"
#define FILEREFPATH		"FILEREFPATH"
#define ID				"ID"
#define DUEDATE			"DUEDATE"
#define PERCENTDONE		"PERCENTDONE"
#define STARTDATE		"STARTDATE"
#define POS				"POS"
#define COMMENTS		"COMMENTS"
#define DONEDATESTRING	"DONEDATESTRING"
#define DONEDATE		"DONEDATE"
#define WEBCOLOR		"WEBCOLOR"
#define COLOR			"COLOR"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CToDoListReaderWriter::CToDoListReaderWriter()
{

}

CToDoListReaderWriter::~CToDoListReaderWriter()
{

}

CTODOList* CToDoListReaderWriter::ReadXML(CString filePath)
{
	CTODOList* pTdl = NULL;
	xmlDocPtr doc;
    xmlNodePtr cur;
	CTask CurTask;
	doc = xmlParseFile(filePath);
    if (doc == NULL)
		return NULL ;

    cur = xmlDocGetRootElement(doc);
   // print_element_names(cur);

    if (cur == NULL)
	{
        
		xmlFreeDoc(doc);
		return NULL ;
    }
    
    if (xmlStrcmp(cur->name, (const xmlChar *) TODOLIST))
	{
		xmlFreeDoc(doc);
		return NULL ;
    }

	pTdl = new CTODOList();

	cur = cur->xmlChildrenNode;
    while (cur && xmlIsBlankNode (cur))
    {
		cur = cur -> next;
    }
    
	if (cur == 0)
      return  NULL;

    while (cur != NULL)
	{
		if ((!xmlStrcmp(cur->name, (const xmlChar *)TASK)))
		{
			BOOL bRet = parseTask(doc,cur,CurTask);
			if(bRet)
				pTdl->addTask(CurTask);	
		}	
		
		cur = cur->next;
    }

	xmlFreeDoc(doc);
	xmlCleanupParser();
	return pTdl;

}

void CToDoListReaderWriter::WriteXML(CTODOList tdl)
{

}

//Recursive function
BOOL CToDoListReaderWriter::parseTask(xmlDocPtr doc, xmlNodePtr cur, CTask& Task)
{
	
	CString s = "";

	_xmlAttr* p = cur->properties;
	if(p==NULL)
		return FALSE;

	while(p!=NULL)
	{
		s = p->name;
		if(s==PRIORITY)
		{
			Task.setPriority((char*)p->children->content);
		}
		else if(s==STARTDATESTRING)
		{
			Task.setStartDateString((char*)p->children->content);
		}
		else if(s==DUEDATESTRING) 
		{
			Task.setDueDateString((char*)p->children->content);
		}
		else if(s==TITLE) 
		{
			Task.setTitle((char*)p->children->content);
		}
		else if(s==PERSON) 
		{
			Task.setPerson((char*)p->children->content);
		}
		else if(s==TIMEESTIMATE)
		{
			Task.setTimeEstimate((char*)p->children->content);
		}
		else if(s==FILEREFPATH) 
		{
			Task.setFileRefPath((char*)p->children->content);
		}
		else if(s==ID) 
		{
			Task.setID((char*)p->children->content);
		}
		else if(s==DUEDATE) 
		{
			Task.setDueDate((char*)p->children->content);
		}
		else if(s==PERCENTDONE) 
		{
			Task.setPercentDone((char*)p->children->content);
		}
		else if(s==STARTDATE) 
		{
			Task.setStartDate((char*)p->children->content);
		}
		else if(s==POS) 
		{
			Task.setPOS((char*)p->children->content);
		}
		else if(s==DONEDATESTRING)
		{
			Task.setDoneDateString((char*)p->children->content);
		}
		else if(s==DONEDATE)
		{
			Task.setDoneDate((char*)p->children->content);
		}
		else if(s==WEBCOLOR)
		{
			Task.setWebColor((char*)p->children->content);
		}
		else if(s==COLOR)
		{
			Task.setColor((char*)p->children->content);
		}

		p = p->next;
	}

	xmlNodePtr child = cur->xmlChildrenNode;
    while (child && xmlIsBlankNode (child))
    {
		child = child -> next;
    }

	while (child != NULL)
	{

		if ((!xmlStrcmp(child->name, (const xmlChar *)COMMENTS)))
		{
			Task.setComment((char*)child->children->content);
		}
		else
		{	
			if ((!xmlStrcmp(child->name, (const xmlChar *)TASK)))
			{
				CTask CurTask;
				BOOL bRet = parseTask(doc,child,CurTask);
				if(bRet)
				{
					Task.addSubTask(CurTask);
				}
			}
		}
		child = child->next;
	}

	return TRUE;
}

void CToDoListReaderWriter::print_element_names(xmlNode * a_node)
{
    xmlNode *cur_node = NULL;

    for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
        if (cur_node->type == XML_ELEMENT_NODE)
		{
			CString s = "";
			s.Format("node type: Element, name: %s\n", cur_node->name);
            TRACE(s);
        }

        print_element_names(cur_node->children);
    }
}

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
Team Leader www.unitronics.com
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions