OK - I finally got back to working on this, had some other stuff come up!
I've made a plugin that makes the interface below available to the QScriptEngine.
A map of fileNames to QLockFile is maintained.
#include <QObject>
#include <QDebug>
#include <QLockFile>
class FileLocker : public QObject
{
Q_OBJECT
public:
FileLocker() : QObject() {}
~FileLocker();
bool lock(QString fName);
bool unlock(QString fName);
QString toString();
QString lockToString(QString fName);
QString errorToString(QLockFile* lck);
QString convertFileNameToLockName(QString fName);
private:
QMap<QString, QLockFile*> lockFiles;
};
Q_DECLARE_METATYPE(FileLocker*)
Using this, I can create a lock file when opening a file (example shown below).
A second user attempting to open the same file will throw a READ-ONLY error.
I currently have Lock/Unlock set up as actions in their own script files.
I added the LockFile Action to NewFile.postOpenActions[], and the Unlock occurs under NewFile.closeRequested.
Similar action calls are my the Save.js file to account for:
- untitled drawings being saved for the first time
- a drawing being "Saved As" a different file name
I would prefer to not edit the standard scripts - is there a better way to catch the opening/closing/renaming of files?
I'm investigating the Transaction Listeners now.
Thanks -- let me know what you think!!
Connor