PhoneBookServlet.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "PhoneBookServlet.h"
  2. #include "HttpRequest.h"
  3. #include "HttpResponse.h"
  4. #include <QXmlStreamWriter>
  5. #include <QContactPhoneNumber>
  6. #include <QContactName>
  7. #include <QSystemDeviceInfo>
  8. PhoneBookServlet::PhoneBookServlet(HttpServer *parent)
  9. : AbstractServlet(parent)
  10. , m_contactManager(new QContactManager())
  11. {
  12. }
  13. PhoneBookServlet::~PhoneBookServlet()
  14. {
  15. delete m_contactManager;
  16. }
  17. void PhoneBookServlet::request(HttpRequest *request, HttpResponse *response)
  18. {
  19. QSystemDeviceInfo info;
  20. response->setStatusCode(HttpResponse::HttpOK);
  21. response->setMimeType("text/xml");
  22. response->sendHeader();
  23. QXmlStreamWriter stream(response->outputDevice());
  24. stream.setAutoFormatting(true);
  25. stream.writeStartDocument();
  26. stream.writeStartElement("SnomIPPhoneDirectory");
  27. stream.writeTextElement("Title", QString("%1 %2").arg(info.manufacturer()).arg(info.model()));
  28. /* Probaly add later:
  29. <Title>Menu</Title>
  30. <Prompt>Prompt</Prompt>
  31. */
  32. QList<QContact> contacts(m_contactManager->contacts());
  33. foreach (QContact contact, contacts) {
  34. stream.writeStartElement("DirectoryEntry");
  35. QContactName name(contact.detail<QContactName>());
  36. stream.writeTextElement("Name", QString("%1 %2").arg(name.firstName()).arg(name.lastName()));
  37. stream.writeTextElement("Telephone", contact.detail<QContactPhoneNumber>().number());
  38. stream.writeEndElement(); // DirectoryEntry
  39. }
  40. stream.writeEndElement(); // SnomIPPhoneDirectory
  41. stream.writeEndDocument();
  42. }