Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 42fa42e8 authored by Inge Wallin's avatar Inge Wallin

Implement a read-only option

parent d5a86c84
......@@ -73,6 +73,8 @@ public:
KAutoSaveFile *m_autosave;
bool m_dirty;
bool m_isReadOnly;
// save these to document
QList<KEduVocIdentifier> m_identifiers;
......@@ -110,7 +112,9 @@ public:
* @param flags Describes how to deal with locked file etc.
* @return ErrorCode where NoError is success
* */
KEduVocDocument::ErrorCode initializeKAutoSave(KAutoSaveFile &autosave, QString const &fpath, FileHandlingFlags flags) const;
KEduVocDocument::ErrorCode initializeKAutoSave(KAutoSaveFile &autosave,
QString const &fpath,
FileHandlingFlags flags) const;
};
KEduVocDocument::KEduVocDocumentPrivate::~KEduVocDocumentPrivate()
......@@ -139,6 +143,7 @@ void KEduVocDocument::KEduVocDocumentPrivate::init()
m_extraSizeHints.clear();
m_sizeHints.clear();
m_dirty = false;
m_isReadOnly = false;
m_queryorg = "";
m_querytrans = "";
m_autosave->setManagedFile( i18n( "Untitled" ) );
......@@ -298,9 +303,17 @@ KEduVocDocument::ErrorCode KEduVocDocument::open( const KUrl& url, FileHandling
return FileDoesNotExist;
}
ErrorCode autosaveError = d->initializeKAutoSave( *d->m_autosave, temporaryFile, flags );
if ( autosaveError != NoError) {
return autosaveError;
if (flags & FileOpenReadOnly) {
d->m_isReadOnly = true;
}
ErrorCode autosaveError = NoError;
if (!d->m_isReadOnly) {
autosaveError = d->initializeKAutoSave( *d->m_autosave, temporaryFile, flags );
if ( autosaveError != NoError) {
return autosaveError;
}
}
QIODevice * f = KFilterDev::deviceForFile( temporaryFile );
......@@ -330,8 +343,11 @@ KEduVocDocument::ErrorCode KEduVocDocument::open( const KUrl& url, FileHandling
return errStatus;
}
void KEduVocDocument::close() {
d->m_autosave->releaseLock();
void KEduVocDocument::close()
{
if (!d->m_isReadOnly) {
d->m_autosave->releaseLock();
}
}
/// @todo When the API major version number increments remove this function
......@@ -347,8 +363,12 @@ int KEduVocDocument::saveAs( const KUrl & url, FileType ft, const QString & gene
return err;
}
KEduVocDocument::ErrorCode KEduVocDocument::saveAs( const KUrl & url, FileType ft, FileHandlingFlags flags)
KEduVocDocument::ErrorCode KEduVocDocument::saveAs( const KUrl & url, FileType ft,
FileHandlingFlags flags)
{
if (!d->m_isReadOnly) {
return FileIsReadOnly;
}
KUrl tmp( url );
......
......@@ -71,14 +71,16 @@ public:
FileReaderFailed, //*< file reader failed
FileDoesNotExist, //*< unknown file type
FileLocked, //*< An autosave file exists for this document
FileCannotLock //*< Can't create an autosave file for this document
FileCannotLock, //*< Can't create an autosave file for this document
FileIsReadOnly //*< Can't save this file because it was opened read-only
};
/// indicates file open/save status locking or readonly
enum FileHandlingFlags
{
FileDefaultHandling = 0x0, //*< Default status
FileIgnoreLock = 0x1 //*< Ignore the file lock
FileIgnoreLock = 0x1, //*< Ignore the file lock
FileOpenReadOnly = 0x2 //*< Open without any intention to change and save back later.
};
/// used as parameter for pattern
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment