1
0
Fork 0
mirror of https://github.com/marty-oehme/scripts.git synced 2024-10-31 23:38:08 +00:00
qownnotes-scripts/inbox/inbox.qml

184 lines
6.8 KiB
QML
Raw Normal View History

2017-08-14 15:37:23 +00:00
import QtQml 2.2
import QOwnNotesTypes 1.0
Script {
2017-09-03 16:29:59 +00:00
function setDefaultPyCommand() {
2017-09-16 14:37:25 +00:00
2017-09-03 16:29:59 +00:00
if (script.getPersistentVariable('MdNT/pyCommand', '') == '') {
2017-09-16 14:37:25 +00:00
if (script.platformIsWindows()) {
var defaultPyCommand = 'pythonw'
}
else {
var defaultPyCommand = 'python3'
}
if (script.startSynchronousProcess(defaultPyCommand, '-V', '').toString().indexOf('Python 3') != '-1') {
script.setPersistentVariable('MdNT/pyCommand', checkPyCommand())
}
2017-09-03 16:29:59 +00:00
}
2017-09-16 14:37:25 +00:00
2017-09-03 16:29:59 +00:00
return script.getPersistentVariable('MdNT/pyCommand', '')
}
2017-08-14 15:37:23 +00:00
property string scriptDirPath
property string noteFolder
2017-08-14 15:37:23 +00:00
property string inboxFolder
2017-09-03 16:29:59 +00:00
property bool scanFolder
2017-09-13 18:10:38 +00:00
property bool watchFS
2017-08-14 15:37:23 +00:00
property string tagMarker
2017-09-03 16:29:59 +00:00
property string pyCommand
property string pandocCommand
property string pandocVersion
2017-08-14 15:37:23 +00:00
property variant settingsVariables: [
{
'identifier': 'noteFolder',
'name': 'Note folder path',
'description': 'Full absolute path to note folder to process. You can select "notes.sqlite" file or type the path in.\n' +
"Leave empty for current note folder. Continuous watch mode won't work if empty.",
'type': 'file',
'default': '',
},
2017-08-14 15:37:23 +00:00
{
'identifier': 'inboxFolder',
'name': 'Inbox folder name',
2017-09-16 14:37:25 +00:00
'description': 'Name of inbox folder located in the root of note folder. An new inbox folder will be created if no exists.',
2017-08-14 15:37:23 +00:00
'type': 'string',
'default': 'Inbox',
},
2017-09-03 16:29:59 +00:00
{
'identifier': 'scanFolder',
'name': 'Scan whole folder rather than only Inbox folder',
2017-09-13 18:10:38 +00:00
'description': 'If true the script will convert any non-".md" file in folder to note.\n' +
2017-09-16 14:37:25 +00:00
'"Sub-folder to single note" and modification times in note titles features will still work only for Inbox.',
2017-09-03 16:29:59 +00:00
'type': 'boolean',
'default': 'false',
},
2017-09-13 18:10:38 +00:00
{
'identifier': 'watchFS',
'name': 'Continuously watch for new files and process them as they appear',
'description': 'If true the script will continuously watch inbox/folder (depending on above setting)\n' +
'for new files and process them as soon as they appear.\n' +
'The script will start working on load, no toolbar button will appear.',
'type': 'boolean',
'default': 'false',
},
2017-08-14 15:37:23 +00:00
{
'identifier': 'tagMarker',
'name': 'Tag word marker',
2017-09-13 18:10:38 +00:00
'description': 'A symbol or string of symbols which start a "topic" word for ".txt" notes. \n' +
'For example, if set to "@", a ".txt" file with "@tag" word will go to "tag.md" note',
2017-08-14 15:37:23 +00:00
'type': 'string',
'default': '@',
},
{
2017-09-03 16:29:59 +00:00
'identifier': 'pyCommand',
2017-08-14 15:37:23 +00:00
'name': 'Command/path to run Python 3 Interpreter',
2017-09-03 16:29:59 +00:00
'description': "Put a command or path to run Python 3 interpreter.",
2017-08-14 15:37:23 +00:00
'type': 'file',
2017-09-03 16:29:59 +00:00
'default': setDefaultPyCommand(),
},
{
'identifier': 'pandocCommand',
'name': 'Command/path to run Pandoc',
'description': "Put a command or path to run Pandoc.",
'type': 'file',
'default': 'pandoc',
},
2017-08-14 15:37:23 +00:00
]
2017-09-13 18:10:38 +00:00
function runInbox() {
2017-09-13 18:10:38 +00:00
var pyScriptPath = scriptDirPath + script.dirSeparator() + 'inbox.py'
var inboxPath = noteFolder + script.dirSeparator() + inboxFolder
2017-09-03 16:29:59 +00:00
2017-09-13 18:10:38 +00:00
var args = [pyScriptPath,
'--inbox', inboxPath,
2017-09-17 08:18:25 +00:00
'--folder', noteFolder,
2017-09-13 18:10:38 +00:00
'--marker', tagMarker]
2017-09-03 16:29:59 +00:00
2017-09-13 18:10:38 +00:00
if (scanFolder == true) {
args.push('--scan-folder')
}
if (watchFS == true) {
args.push('--watch')
}
if (pandocVersion != '') {
args.push('--pandoc-bin', pandocCommand,
'--pandoc-ver', pandocVersion)
}
script.startDetachedProcess(pyCommand, args)
script.log('Processing inbox...')
}
function init() {
if (noteFolder == '') {
noteFolder = script.currentNoteFolderPath()
watchFS = false
}
else {
noteFolder = noteFolder.replace(script.dirSeparator() + 'notes.sqlite', '')
}
2017-09-03 16:29:59 +00:00
/// Check if set pyCommand can run Python 3
if (script.getPersistentVariable('MdNT/pyCommand', '') != pyCommand) {
if (script.startSynchronousProcess(pyCommand, '-V', '').toString().indexOf('Python 3') != '-1') {
script.setPersistentVariable('MdNT/pyCommand', pyCommand)
}
else {
script.setPersistentVariable('MdNT/pyCommand', '')
}
}
/// Get the version of pandoc
if (script.getPersistentVariable('MdNT/pandocCommand', '') != pandocCommand) {
var pandocCheck = script.startSynchronousProcess(pandocCommand, '-v', '').toString().split('\n')[0]
2017-09-13 18:10:38 +00:00
2017-09-03 16:29:59 +00:00
if (pandocCheck.indexOf('pandoc') != '-1') {
script.setPersistentVariable('MdNT/pandocCommand', pandocCommand)
script.setPersistentVariable('MdNT/pandocVersion', pandocCheck.slice(7))
}
else {
2017-09-13 18:10:38 +00:00
script.setPersistentVariable('MdNT/pandocCommand', '')
2017-09-03 16:29:59 +00:00
}
}
/// Issues alerts
if (script.getPersistentVariable('MdNT/pandocCommand', '') == '') {
2017-09-13 18:10:38 +00:00
script.informationMessageBox('The command/path for pandoc in the script settings is not valid.\n' +
'Converting web pages to notes will be disabled.',
'Inbox script')
2017-09-03 16:29:59 +00:00
script.setPersistentVariable('MdNT/pandocCommand', pandocCommand)
script.setPersistentVariable('MdNT/pandocVersion', '')
pandocVersion = ''
}
2017-09-13 18:10:38 +00:00
else {
pandocVersion = script.getPersistentVariable('MdNT/pandocVersion', '')
}
2017-09-03 16:29:59 +00:00
if (script.getPersistentVariable('MdNT/pyCommand', '') == '') {
2017-09-13 18:10:38 +00:00
script.informationMessageBox('The command/path for Python 3 interpreter in the script settings is not valid.\n' +
2017-09-03 16:29:59 +00:00
'Please set the correct command/path.',
2017-09-13 18:10:38 +00:00
'Inbox script')
}
else if (watchFS == true) {
runInbox()
2017-08-14 15:37:23 +00:00
}
else {
script.registerCustomAction('inbox', 'Process inbox folder', 'Inbox', 'mail-receive.svg')
}
}
function customActionInvoked(action) {
if (action == 'inbox') {
2017-09-13 18:10:38 +00:00
runInbox()
2017-08-14 15:37:23 +00:00
}
}
}