diff --git a/src/filmslist/filmslistloader.cpp b/src/filmslist/filmslistloader.cpp index 9f3cf81..ff88b45 100644 --- a/src/filmslist/filmslistloader.cpp +++ b/src/filmslist/filmslistloader.cpp @@ -69,7 +69,7 @@ bool FilmsListLoader::Populate( FilmItem* rootItem, QString fileName ) } -bool FilmsListLoader::Save( FilmItem* rootItem, QString fileName ) +bool FilmsListLoader::Save( FilmItem* rootItem, QString fileName, QString* errorString ) { DebugPrintFunc( "FilmsListLoader::Save", fileName ); @@ -93,18 +93,25 @@ bool FilmsListLoader::Save( FilmItem* rootItem, QString fileName ) QFile file( fileName ); - if( file.open( QIODevice::WriteOnly ) || file.write(data) == -1 ) + if( file.open( QIODevice::WriteOnly ) ) { QDataStream stream( &file ); stream.setVersion( QDataStream::Qt_5_3 ); stream << Alexandra::databaseHeader; stream << Alexandra::databaseVersion; stream << data; + file.close(); } else { DebugPrint( "Saving failed!" ); DebugPrintFuncDone( "FilmsListLoader::Save" ); + + if (errorString != nullptr) + { + *errorString = file.errorString(); + } + return( false ); } diff --git a/src/filmslist/filmslistloader.h b/src/filmslist/filmslistloader.h index a6a14e3..fca9082 100644 --- a/src/filmslist/filmslistloader.h +++ b/src/filmslist/filmslistloader.h @@ -33,7 +33,7 @@ class FilmsListLoader { public: static bool Populate( FilmItem* rootItem, QString fileName ); - static bool Save( FilmItem* rootItem, QString fileName ); + static bool Save( FilmItem* rootItem, QString fileName, QString* errorString = nullptr ); static bool CreateEmptyDatabase( QString fileName ); diff --git a/src/filmslist/filmslistmodel.cpp b/src/filmslist/filmslistmodel.cpp index 8d2a503..7996c92 100644 --- a/src/filmslist/filmslistmodel.cpp +++ b/src/filmslist/filmslistmodel.cpp @@ -543,14 +543,15 @@ QModelIndex FilmsListModel::GetFilmIndex( QString title ) const void FilmsListModel::SaveToFileSync( QString fileName ) { - if( isDatabaseChanged ) + if( isDatabaseChanged && !isReadonly ) { QMutexLocker locker( &mutexDataEdit ); isDatabaseChanged = false; + QString errorString; - if( !FilmsListLoader::Save( rootItem, fileName ) ) + if( !FilmsListLoader::Save( rootItem, fileName, &errorString ) ) { - emit DatabaseWriteError(); + emit DatabaseWriteError( errorString ); } } } diff --git a/src/filmslist/filmslistmodel.h b/src/filmslist/filmslistmodel.h index 07586bb..24874c7 100644 --- a/src/filmslist/filmslistmodel.h +++ b/src/filmslist/filmslistmodel.h @@ -87,7 +87,7 @@ class FilmsListModel : public QAbstractItemModel signals: void DatabaseConvertOld(); void DatabaseReadError( QString ); - void DatabaseWriteError(); + void DatabaseWriteError( QString ); void DatabaseIsEmpty(); void DatabaseIsReadonly(); diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index d31f0b6..e191201 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -226,6 +226,12 @@ void MainWindow::DatabaseReadError( const QString& message ) } +void MainWindow::DatabaseWriteError( const QString& message ) +{ + QMessageBox::critical( this, tr("Database write error"), message ); +} + + void MainWindow::DatabaseIsEmpty() { ClearTextFields(); @@ -876,6 +882,7 @@ void MainWindow::SetupWindows() connect( filmsListModel, &FilmsListModel::DatabaseLoaded, this, &MainWindow::DatabaseIsLoaded ); connect( filmsListModel, &FilmsListModel::DatabaseReadError, this, &MainWindow::DatabaseReadError ); + connect( filmsListModel, &FilmsListModel::DatabaseWriteError, this, &MainWindow::DatabaseWriteError ); connect( filmsListModel, &FilmsListModel::DatabaseIsReadonly, this, &MainWindow::DatabaseIsReadonly ); connect( filmsListModel, &FilmsListModel::DatabaseIsEmpty, this, &MainWindow::DatabaseIsEmpty ); connect( filmsListModel, &FilmsListModel::DatabaseChanged, this, &MainWindow::DatabaseChanged ); diff --git a/src/mainwindow/mainwindow.h b/src/mainwindow/mainwindow.h index adfaeae..2d4b9ad 100644 --- a/src/mainwindow/mainwindow.h +++ b/src/mainwindow/mainwindow.h @@ -69,6 +69,7 @@ class MainWindow : public QMainWindow, protected Ui::MainWindow void DatabaseIsLoaded() { SetAllFunctionsEnabled( true ); } void DatabaseReadError( const QString& message ); + void DatabaseWriteError( const QString& message ); void DatabaseIsEmpty(); void DatabaseIsReadonly(); diff --git a/src/src.pro b/src/src.pro index b40aca8..86d8f19 100644 --- a/src/src.pro +++ b/src/src.pro @@ -11,7 +11,7 @@ TARGET = alexandra TEMPLATE = app -#CONFIG += release +CONFIG += release #CONFIG += debug console QT = core gui widgets network