]> git.sven.stormbind.net Git - sven/vym.git/blob - src/export-orgmode.cpp
Replace Pierre as the maintainer
[sven/vym.git] / src / export-orgmode.cpp
1 #include "export-orgmode.h"
2
3 #include "mainwindow.h"
4 #include <QMessageBox>
5
6 extern Main *mainWindow;
7
8 ExportOrgMode::ExportOrgMode()
9 {
10     exportName = "OrgMode";
11     filter = "org-mode (*.org);;All (* *.*)";
12 }
13
14 void ExportOrgMode::doExport()
15 {
16     // Exports a map to an org-mode file.
17     // This file needs to be read
18     // by EMACS into an org mode buffer
19     QFile file(filePath);
20     if (!file.open(QIODevice::WriteOnly)) {
21         QMessageBox::critical(
22             0, QObject::tr("Critical Export Error"),
23             QObject::tr("Could not export as OrgMode to %1").arg(filePath));
24         mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
25         return;
26     }
27     QTextStream ts(&file);
28     ts.setCodec("UTF-8");
29
30     // Main loop over all branches
31     QString s;
32     int i;
33     BranchItem *cur = NULL;
34     BranchItem *prev = NULL;
35     model->nextBranch(cur, prev);
36     while (cur) {
37         if (!cur->hasHiddenExportParent()) {
38             for (i = 0; i <= cur->depth(); i++)
39                 ts << ("*");
40             ts << (" " + cur->getHeadingPlain() + "\n");
41             // If necessary, write note
42             if (!cur->isNoteEmpty()) {
43                 ts << (cur->getNoteASCII(0, 80));
44                 ts << ("\n");
45             }
46         }
47         model->nextBranch(cur, prev);
48     }
49     file.close();
50
51     result = ExportBase::Success;
52
53     displayedDestination = filePath;
54     completeExport();
55 }