~bobo-324/dekko/customScheme

« back to all changes in this revision

Viewing changes to src/app/PartWidget/NewPartWidget.cpp

  • Committer: Dan Chapman
  • Date: 2014-11-07 19:41:38 UTC
  • mfrom: (148.1.15 removeQtWebkit)
  • Revision ID: dpniel@ubuntu.com-20141107194138-n95ozzhrcu2rg5ib
Finally webkit has been nuked from dekko!! Thanks for your work on this boren

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
#include "app/Utils/Path.h"
12
12
#include "app/PartWidget/LoadablePartWidget.h"
13
13
#include "app/PartWidget/AttachmentView.h"
 
14
#include "app/PartWidget/SectionType.h"
14
15
 
15
16
extern QQuickView *qQuickViewer;
16
17
 
151
152
        QModelIndex anotherPart = partIndex.child(i, 0);
152
153
        Q_ASSERT(anotherPart.isValid()); // guaranteed by the MVC
153
154
        QObject *res = factory->create(anotherPart, messageView, recursionDepth + 1, filteredForEmbedding(options));
154
 
        if (res != NULL)
155
 
            qobject_cast<QQuickItem *>(res)->setParentItem(columnItem);
 
155
        if (res != NULL) {
 
156
            if (res->property("isAttachmentView").toBool()) {
 
157
                QMetaObject::invokeMethod(messageView, "addAttachmentItem", Q_ARG(QVariant, QVariant::fromValue(qobject_cast<QQuickItem *>(res))));
 
158
            } else {
 
159
                qobject_cast<QQuickItem *>(res)->setParentItem(columnItem);
 
160
            }
 
161
        }
156
162
    }
157
163
    return columnItem;
158
164
}
165
171
}
166
172
 
167
173
QObject *PartWidgetFactory::newSimplePartWidget(QObject *parent, Imap::Network::MsgPartNetAccessManager *manager,
168
 
                             const QModelIndex &partIndex, QObject *messageView)
 
174
                             const QModelIndex &partIndex, QObject *messageView, bool dontRegisterAsSection)
169
175
{
170
176
    qDebug() << "newSimplePartWidget";
171
177
    QQmlEngine *engine = qQuickViewer->engine();
172
178
    bool isPlainText = false;
 
179
    bool isHtml = false;
173
180
    QQmlComponent *component;
174
181
    if (partIndex.data(Imap::Mailbox::RolePartMimeType).toString() == QLatin1String("text/html")){
175
182
        component = new QQmlComponent(engine, Dekko::findQmlFile("qml/MessageView/HtmlPart.qml"));
 
183
        isHtml = true;
176
184
    } else if (partIndex.data(Imap::Mailbox::RolePartMimeType).toString().startsWith(QLatin1String("image"))) {
177
185
        component = new QQmlComponent(engine, Dekko::findQmlFile("qml/MessageView/ImagePart.qml"));
178
186
    } else {
187
195
    QQuickItem *item = qobject_cast<QQuickItem*>(component->create(engine->contextForObject(messageView)));
188
196
 
189
197
    item->setParent(messageView);
190
 
    delete component;
 
198
    component->deleteLater();
191
199
 
192
200
    if (partIndex.data(Imap::Mailbox::RolePartMimeType).toString() == QLatin1String("text/html"))
193
201
        connect(item, SIGNAL(linkClicked(QVariant)), messageView, SLOT(openUrlExternally(QVariant)));
194
202
 
195
 
    if (isPlainText) {
 
203
    if (isPlainText || isHtml) {
196
204
        item->setProperty("msgPartIndex", partIndex);
197
205
    } else {
198
 
        item->setProperty("messageUrl", url);
 
206
        item->setProperty("source", url);
 
207
    }
 
208
 
 
209
    if ((isHtml || isPlainText) && !dontRegisterAsSection) {
 
210
        if (isHtml) {
 
211
            QMetaObject::invokeMethod(messageView, "addSection",
 
212
                Q_ARG(QVariant, QVariant::fromValue(item)),
 
213
                Q_ARG(QVariant, QVariant::fromValue((int)Dekko::PartWidget::SectionType::HTML)));
 
214
        } else {
 
215
            //plainText
 
216
            QMetaObject::invokeMethod(messageView, "addSection",
 
217
                Q_ARG(QVariant, QVariant::fromValue(item)),
 
218
                Q_ARG(QVariant, QVariant::fromValue((int)Dekko::PartWidget::SectionType::PLAIN_TEXT)));
 
219
        }
199
220
    }
200
221
 
201
222
    return item;