Skip to content

Commit cfcfd5b

Browse files
committed
Show message body instead of raw.
mimetic is used which is likely to be substituted with something more flexible soon
1 parent 89250f4 commit cfcfd5b

File tree

10 files changed

+115
-28
lines changed

10 files changed

+115
-28
lines changed

MessageViewer.qml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import QtQuick 2.0
22
import QtQuick.Controls 1.2
3+
import Notquick 1.0
34

45
Rectangle {
56
id: root
67
property var message
8+
property var entity: message.createMimeEntity()
79

810
color: "red"
911

1012
TextArea {
1113
readOnly: true
1214
anchors.fill: parent
13-
text: message.raw
15+
text: entity.body
1416
}
1517

1618
}

main.qml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import QtQuick 2.0
2-
import Notmuch 1.0
2+
import Notquick 1.0
33
import QtQuick.Controls 1.0
44

55
ApplicationWindow {
@@ -33,7 +33,6 @@ ApplicationWindow {
3333
function updateThreads() { // this is done to implement refreshing on 'Go' click
3434
threadList.model = 0
3535
threadList.model = NotmuchDatabase.queryThreads(queryString)
36-
threadList.updateMessages()
3736
}
3837
}
3938

notquick.pro

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ SOURCES += \
1111
src/disposable.cpp \
1212
src/notmuch/tags.cpp \
1313
src/notmuch/messages.cpp \
14-
src/notmuch/message.cpp
14+
src/notmuch/message.cpp \
15+
src/mime/fileentity.cpp \
16+
src/mime/mytest.cpp
1517

1618
RESOURCES += qml.qrc
1719

@@ -23,10 +25,12 @@ HEADERS += \
2325
src/disposable.h \
2426
src/notmuch/tags.h \
2527
src/notmuch/messages.h \
26-
src/notmuch/message.h
28+
src/notmuch/message.h \
29+
src/mime/fileentity.h \
30+
src/mime/mytest.h
2731

2832
INCLUDEPATH += src/
2933

30-
LIBS += -lnotmuch
34+
LIBS += -lnotmuch -lmimetic
3135

3236
OTHER_FILES +=

src/main.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
#include <QQmlApplicationEngine>
66
#include <QQmlContext>
77

8-
#include "src/notmuch/thread.h"
9-
#include "src/notmuch/threads.h"
10-
#include "src/notmuch/database.h"
11-
#include "src/notmuch/tags.h"
8+
9+
#include "notmuch/database.h"
10+
#include "mime/fileentity.h"
11+
#include "mime/mytest.h"
1212

1313
notmuch::DatabaseProxy *proxy = 0;
1414

@@ -24,12 +24,13 @@ int main(int argc, char *argv[])
2424
db.open();
2525
proxy = new notmuch::DatabaseProxy(&db); // owned by QML, so GC-ed later
2626

27-
qmlRegisterSingletonType<notmuch::Database>("Notmuch", 1, 0, "NotmuchDatabase", databaseSingleton);
28-
//qmlRegisterType<notmuch::Threads>("Notmuch", 1, 0, "NotmuchThreads");
29-
//qmlRegisterType<notmuch::Tags>("Notmuch", 1, 0, "NotmuchTags");
27+
qmlRegisterSingletonType<notmuch::Database>("Notquick", 1, 0, "NotmuchDatabase", databaseSingleton);
28+
qmlRegisterType<mime::FileEntity>("Notquick", 1, 0, "MimeFileEntity");
29+
30+
qmlRegisterType<MyTest>("Notquick", 1, 0, "NQTest");
3031

31-
QApplication app(argc, argv);
32-
QQmlApplicationEngine engine;
32+
QApplication app(argc, argv); // TODO maybe switch to QGuiApplication
33+
QQmlApplicationEngine engine; // TODO maybe switch to QQmlEngine
3334

3435
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
3536

src/mime/fileentity.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "fileentity.h"
2+
#include <QFile>
3+
#include <QDebug>
4+
5+
#include <fstream>
6+
7+
namespace mime {
8+
9+
QString FileEntity::body() const
10+
{
11+
if(!mimeticEntity)
12+
return QString();
13+
return QString(mimeticEntity->body().c_str());
14+
}
15+
16+
FileEntity::FileEntity(QString filename, QObject *parent) :
17+
QObject(parent)
18+
{
19+
qDebug() << "opening " << filename;
20+
// TODO error messages to qCritical()
21+
std::ifstream f(filename.toLocal8Bit().data());
22+
mimeticEntity = new mimetic::MimeEntity();
23+
mimeticEntity->load(f, mimetic::imChildParts | mimetic::imEpilogue | mimetic::imPreamble);
24+
}
25+
26+
FileEntity::~FileEntity()
27+
{
28+
if(mimeticEntity)
29+
delete mimeticEntity;
30+
}
31+
32+
} // namespace mail

src/mime/fileentity.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef MAIL_ENTITY_H
2+
#define MAIL_ENTITY_H
3+
4+
#include <QObject>
5+
#include <QFile>
6+
#include <mimetic/mimeentity.h>
7+
8+
namespace mime {
9+
10+
class FileEntity : public QObject
11+
{
12+
Q_OBJECT
13+
Q_PROPERTY(QString body READ body CONSTANT)
14+
15+
QString body() const;
16+
public:
17+
explicit FileEntity(QString filename = QString(), QObject *parent = 0);
18+
virtual ~FileEntity();
19+
20+
private:
21+
mimetic::MimeEntity* mimeticEntity;
22+
23+
24+
25+
26+
};
27+
28+
} // namespace mail
29+
30+
#endif // MAIL_ENTITY_H

src/mime/mytest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "mytest.h"
2+
3+
MyTest::MyTest(QObject *parent) :
4+
QObject(parent)
5+
{
6+
}

src/mime/mytest.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef MYTEST_H
2+
#define MYTEST_H
3+
4+
#include <QObject>
5+
6+
class MyTest : public QObject
7+
{
8+
Q_OBJECT
9+
public:
10+
explicit MyTest(QObject *parent = 0);
11+
12+
signals:
13+
14+
public slots:
15+
16+
};
17+
18+
#endif // MYTEST_H

src/notmuch/message.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <QTextStream>
44
#include <QDebug>
55
#include "log.h"
6+
#include "mime/fileentity.h"
67

78
namespace notmuch {
89

@@ -27,6 +28,11 @@ bool Message::dropTag(QString name)
2728
return true;
2829
}
2930

31+
QObject *Message::createMimeEntity() const
32+
{
33+
return new mime::FileEntity(filename(), 0);
34+
}
35+
3036
QString Message::filename() const
3137
{
3238
if(!libnotmuch_message)
@@ -42,16 +48,6 @@ QDateTime Message::date() const
4248
return datetime;
4349
}
4450

45-
QString Message::raw() const
46-
{
47-
QFile f(filename());
48-
if(!f.open(QFile::ReadOnly|QFile::Text)) {
49-
// TODO error message
50-
}
51-
QTextStream in(&f);
52-
return filename() + "\n\n" + in.readAll();
53-
}
54-
5551
QString Message::id() const
5652
{
5753
if(!libnotmuch_message)

src/notmuch/message.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class Message : public QObject, protected Disposable
1717
QString id() const;
1818
QString filename() const;
1919
QDateTime date() const;
20-
QString raw() const;
2120
Tags* tags();
2221

2322
public:
@@ -38,10 +37,10 @@ class Message : public QObject, protected Disposable
3837
Q_PROPERTY(QString from READ from CONSTANT)*/
3938
Q_PROPERTY(QObject* tags READ tags CONSTANT)
4039

41-
Q_PROPERTY(QString raw READ raw CONSTANT)
42-
4340
Q_INVOKABLE bool dropTag(QString name);
4441

42+
Q_INVOKABLE QObject* createMimeEntity() const; // TODO call MimeEntity const. directly from qml
43+
4544
private:
4645
Message(notmuch_message_t* libnotmuch_message, QObject* parent);
4746
notmuch_message_t* libnotmuch_message;

0 commit comments

Comments
 (0)