--- /dev/null
+//
+// C++ Implementation: user
+//
+// Description:
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#include "user.h"
+#include "webrequest.h"
+
+#include <QRegExp>
+#include <QDomElement>
+
+MUser::MUser(MWebRequest*r,QDomElement&e)
+{
+ req=r;
+ m_userid=e.attribute("name").trimmed();
+ m_descr=e.text().trimmed();
+}
+
+MUser::MUser(MWebRequest*r,QString n)
+{
+ req=r;
+ m_userid=n;
+}
+
+MUser::MUser()
+{
+ req=0;
+}
+
+MUser::MUser(const MUser&u)
+{
+ req=u.req;
+ m_userid=u.m_userid;
+ m_descr=u.m_descr;
+}
+
+QString MUser::userId()
+{
+ return m_userid;
+}
+
+QString MUser::description()
+{
+ return m_descr;
+}
+
+bool MUser::isValid()
+{
+ return QRegExp("[A-Za-z0-9_]+").exactMatch(m_userid);
+}
+
+bool MUser::create()
+{
+ //do not attempt to save invalid or incomplete data
+ if(!isValid())return false;
+ //create XML
+ QDomDocument doc;
+ QDomElement root=doc.createElement("Users");
+ QDomElement el=doc.createElement("User");
+ el.setAttribute("name",m_userid);
+ el.appendChild(doc.createTextNode(m_descr));
+ root.appendChild(el);
+ doc.appendChild(root);
+ //call
+ req->request("adduser",doc.toByteArray());
+ //check success
+ if(req->responseStatus()==MWebRequest::Ok){
+ //TODO: check response content for myself, return false if not found
+ return true;
+ }else{
+ return false;
+ }
+}
+
+bool MUser::setDescription(QString d)
+{
+ m_descr=d;
+ //do not attempt to save invalid or incomplete data
+ if(!isValid())return false;
+ //create XML
+ QDomDocument doc;
+ QDomElement root=doc.createElement("Users");
+ QDomElement el=doc.createElement("User");
+ el.setAttribute("name",m_userid);
+ el.appendChild(doc.createTextNode(m_descr));
+ root.appendChild(el);
+ doc.appendChild(root);
+ //call
+ req->request("setuserdescription",doc.toByteArray());
+ //check success
+ if(req->responseStatus()==MWebRequest::Ok){
+ return true;
+ }else{
+ return false;
+ }
+}
--- /dev/null
+//
+// C++ Interface: user
+//
+// Description:
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#ifndef MAGICSMOKE_USER_H
+#define MAGICSMOKE_USER_H
+
+#include <QString>
+
+class MWebRequest;
+class QDomElement;
+
+class MUser
+{
+ public:
+ /**create invalid user*/
+ MUser();
+ /**create user by name*/
+ MUser(MWebRequest*,QString);
+ /**create user from XML element*/
+ MUser(MWebRequest*,QDomElement&);
+ /**copy user*/
+ MUser(const MUser&);
+
+ /**returns user name*/
+ QString userId();
+ /**returns user description*/
+ QString description();
+
+ /**checks user name*/
+ bool isValid();
+
+ /**creates user in database; returns true on success*/
+ bool create();
+
+ /**sets new description, both locally and on server*/
+ bool setDescription(QString);
+
+ private:
+ MWebRequest*req;
+ QString m_userid,m_descr;
+};
+
+
+#endif