1
0
Fork 0
mirror of https://github.com/marty-oehme/scripts.git synced 2024-11-14 22:08:08 +00:00
qownnotes-scripts/inbox/inbox.qml

140 lines
5.6 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 checkPyCommand() {
if (script.startSynchronousProcess('pythonw', '-V', '').toString().indexOf('Python 3') != '-1') {return 'pythonw'}
if (script.startSynchronousProcess('python3', '-V', '').toString().indexOf('Python 3') != '-1') {return 'python3'}
if (script.startSynchronousProcess('python', '-V', '').toString().indexOf('Python 3') != '-1') {return 'python'}
return ''
}
function setDefaultPyCommand() {
if (script.getPersistentVariable('MdNT/pyCommand', '') == '') {
script.setPersistentVariable('MdNT/pyCommand', checkPyCommand())
}
return script.getPersistentVariable('MdNT/pyCommand', '')
}
2017-08-14 15:37:23 +00:00
property string scriptDirPath
property string inboxFolder
2017-09-03 16:29:59 +00:00
property bool scanFolder
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
2017-08-14 15:37:23 +00:00
2017-09-03 16:29:59 +00:00
property string pandocVersion
2017-08-14 15:37:23 +00:00
property variant settingsVariables: [
{
'identifier': 'inboxFolder',
'name': 'Inbox folder name',
'description': 'Name of inbox folder located in the root of note folder. It is single for all note folders\n' +
'An empty inbox folder will be created if no exists.',
'type': 'string',
'default': 'Inbox',
},
2017-09-03 16:29:59 +00:00
{
'identifier': 'scanFolder',
'name': 'Scan whole folder rather than only Inbox folder',
'description': 'If true the script will convert any non-".md" file in folder to note. \n' +
'"Sub-folder to single note" and modification times in note titles will still be only for Inbox.',
'type': 'boolean',
'default': 'false',
},
2017-08-14 15:37:23 +00:00
{
'identifier': 'tagMarker',
'name': 'Tag word marker',
2017-09-03 16:29:59 +00:00
'description': 'A symbol or group of symbols which start a "topic" word for ".txt" notes. \n' +
2017-08-14 15:37:23 +00:00
'For example a txt note with "@tag" word will go to "tag.md" note',
'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-03 16:29:59 +00:00
2017-08-14 15:37:23 +00:00
function init() {
2017-09-03 16:29:59 +00:00
pandocVersion = script.getPersistentVariable('MdNT/pandocVersion', '')
/// 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]
if (pandocCheck.indexOf('pandoc') != '-1') {
script.setPersistentVariable('MdNT/pandocCommand', pandocCommand)
script.setPersistentVariable('MdNT/pandocVersion', pandocCheck.slice(7))
pandocVersion = pandocCheck.slice(7)
}
else {
script.setPersistentVariable('MdNT/pandocCommand', '')
}
}
/// Issues alerts
if (script.getPersistentVariable('MdNT/pandocCommand', '') == '') {
script.informationMessageBox('The command/path for pandoc in the script settings is not valid\n' +
'Converting web pages will be disabled.',
'Script')
script.setPersistentVariable('MdNT/pandocCommand', pandocCommand)
script.setPersistentVariable('MdNT/pandocVersion', '')
pandocVersion = ''
}
if (script.getPersistentVariable('MdNT/pyCommand', '') == '') {
script.informationMessageBox('The command/path for Python 3 interpreter in the script settings is not valid\n' +
'Please set the correct command/path.',
'Script')
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') {
var pyScriptPath = scriptDirPath + script.dirSeparator() + 'inbox.py'
var inboxPath = script.currentNoteFolderPath() + script.dirSeparator() + inboxFolder
2017-09-03 16:29:59 +00:00
var args = [pyScriptPath,
'--inbox', inboxPath,
'--folder', script.currentNoteFolderPath(),
'--marker', tagMarker]
if (scanFolder == true) {
args.push('--scan-folder')
}
if (pandocVersion != '') {
args.push('--pandoc-bin', pandocCommand,
'--pandoc-ver', pandocVersion)
}
script.startDetachedProcess(pyCommand, args)
2017-08-14 15:37:23 +00:00
script.log('Processing inbox...')
}
}
2017-09-03 16:29:59 +00:00
}