Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // message.h
- /*
- * Copyright (C) Xabier Rodriguez Calvar <calvaris@igalia.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; version 3 of the
- * License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
- #ifndef MESSAGE_H
- #define MESSAGE_H
- #include <QDeclarativeItem>
- #include <QMessageService>
- #include <QMessage>
- QTM_USE_NAMESPACE
- class Message : public QDeclarativeItem
- {
- Q_OBJECT
- public:
- Q_PROPERTY(QStringList to
- READ to
- WRITE setTo)
- Q_PROPERTY(QString body
- READ body
- WRITE setBody)
- Q_PROPERTY(QString from
- READ from
- WRITE setFrom)
- Q_PROPERTY(QStringList attachments
- READ attachments
- WRITE setAttachments)
- Q_PROPERTY(QString subject
- READ subject
- WRITE setSubject)
- Message(QDeclarativeItem *parent = 0);
- virtual ~Message();
- Q_INVOKABLE bool send();
- Q_INVOKABLE bool compose();
- QStringList to() { return m_to; };
- QString body() { return m_body; };
- QString from() { return m_from; };
- QStringList attachments() { return m_attachments; };
- QString subject() { return m_subject; };
- public slots:
- void setTo(const QStringList& to) { m_to = to; };
- void setBody(const QString& body) { m_body = body; };
- void setFrom(const QString& from) { m_from = from; };
- void setAttachments(const QStringList& attachments) {
- m_attachments = attachments; };
- void setSubject(const QString& subject) { m_subject = subject; };
- private slots:
- void stateChanged (QMessageService::State newState);
- private:
- const QMessage createMessage();
- QStringList m_to;
- QString m_body;
- QString m_from;
- QStringList m_attachments;
- QString m_subject;
- QMessageService service;
- };
- #endif // MESSAGE_H
- // message.cpp
- /*
- * Copyright (C) Xabier Rodriguez Calvar <calvaris@igalia.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; version 3 of the
- * License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
- #include "message.h"
- Message::Message(QDeclarativeItem *parent) :
- QDeclarativeItem(parent)
- {
- connect(&service, SIGNAL(stateChanged (QMessageService::State)), this,
- SLOT(stateChanged (QMessageService::State)));
- }
- Message::~Message()
- {
- }
- const QMessage Message::createMessage()
- {
- QMessage message;
- message.setFrom(QMessageAddress(QMessageAddress::Email, m_from));
- QMessageAddressList toList;
- foreach (const QString &item, m_to) {
- toList.append(QMessageAddress(QMessageAddress::Email, item));
- }
- message.setTo(toList);
- message.setSubject(m_subject);
- message.setBody(m_body);
- message.appendAttachments(m_attachments);
- return message;
- }
- bool Message::send()
- {
- QMessage message = createMessage();
- qDebug("%s: from: <%s> to: <%s> body: \"%s\" attachment: %s", Q_FUNC_INFO,
- m_from.toUtf8().constData(), m_to[0].toUtf8().constData(),
- m_body.toUtf8().constData(), m_attachments[0].toUtf8().constData());
- service.send(message);
- return true;
- }
- bool Message::compose()
- {
- QMessage message = createMessage();
- qDebug("%s: from: <%s> to: <%s> body: \"%s\" attachment: %s", Q_FUNC_INFO,
- m_from.toUtf8().constData(), m_to[0].toUtf8().constData(),
- m_body.toUtf8().constData(), m_attachments[0].toUtf8().constData());
- service.compose(message);
- return true;
- }
- void Message::stateChanged (QMessageService::State newState)
- {
- qDebug() << "state changed to" << newState;
- if (newState == QMessageService::FinishedState) {
- QMessageManager::Error error = service.error();
- qDebug() << "error:" << error;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement