-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenexport.cpp
91 lines (73 loc) · 2.19 KB
/
enexport.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "enexport.h"
#include "enexportparser.h"
#include "ennote.h"
#include "endisplay.h"
EnExport::EnExport(QObject* parent) :
QThread(parent),
mEnProcess(0)
{
QSettings settings("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths", QSettings::NativeFormat);
mEnScriptPath = settings.value("ENScript.exe/Default", "").toString();
mEvernotePath = settings.value("Evernote.exe/Default", "").toString();
Q_ASSERT(mEnScriptPath != "" && mEvernotePath != "");
mEnProcess = new QProcess;
//connect(mEnProcess, SIGNAL(finished(int)), SLOT(readExport()));
}
EnExport::~EnExport(){
delete mEnProcess;
foreach(EnNote* note, mEnNotes){
delete note;
}
}
void EnExport::run(){
loadNotes(mQuery);
}
bool EnExport::loadNotes(const QString& query){
mTimer.start();
if(query.isEmpty())
return false;
// ïðîâåðÿåì çàïóùåí ëè ïðîöåññ
if(mEnProcess->isOpen()){
mEnProcess->close();
qDebug() << "forced closing";
return false;
}
// àðãóìåíòû äëÿ çàïóñêà ïðîöåññà
QStringList arguments;
arguments << "exportNotes" << "/q" << query;
mEnProcess->start(mEnScriptPath, arguments);
mEnProcess->waitForFinished();
readExport();
return true;
}
void EnExport::readExport(){
foreach(EnNote* note, mEnNotes){
delete note;
}
mEnNotes = EnExportParser::readFromIO(mEnProcess);
emit exported();
foreach(EnNote* note, mEnNotes){
//qDebug() << note->toString();
}
qDebug() << "total " + QString::number(mEnNotes.count());
qDebug("timer: export %d ms", mTimer.elapsed());
}
void EnExport::setNotesToView(QWebView* view){
EnDisplay disp;
view->setHtml(disp.display(mEnNotes));
}
QList<EnNote*> EnExport::getNotes() const{
return mEnNotes;
}
void EnExport::setQuery(const QString& query){
mQuery = query;
}
bool EnExport::isExportAvaliable() const{
return mEnScriptPath != ""/* && mEvernotePath != ""*/;
}
void EnExport::openNote(const QString& title){
// àðãóìåíòû äëÿ çàïóñêà ïðîöåññà
QStringList arguments;
arguments << "showNotes" << "/q" << '"' + title + '"';
mEnProcess->start(mEnScriptPath, arguments);
}