Skip to content

Commit

Permalink
Merge pull request #138 from fxdeniz/issue_137
Browse files Browse the repository at this point in the history
Issue 137
  • Loading branch information
fxdeniz authored May 11, 2023
2 parents ef0f8c2 + 3b94de8 commit 98b6eb9
Show file tree
Hide file tree
Showing 23 changed files with 655 additions and 141 deletions.
29 changes: 13 additions & 16 deletions Backend/FileStorageSubSystem/FileStorageManager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "FileStorageManager.h"

#include "Utility/AppConfig.h"
#include "Utility/JsonDtoFormat.h"
#include "Utility/DatabaseRegistry.h"

Expand All @@ -11,7 +12,7 @@

FileStorageManager::FileStorageManager(const QSqlDatabase &db, const QString &backupFolderPath)
{
setBackupFolderPath(backupFolderPath);
setStorageFolderPath(backupFolderPath);
database = db;

if(!database.isOpen())
Expand All @@ -24,14 +25,10 @@ FileStorageManager::FileStorageManager(const QSqlDatabase &db, const QString &ba

QSharedPointer<FileStorageManager> FileStorageManager::instance()
{
QString tempPath = QStandardPaths::writableLocation(QStandardPaths::StandardLocation::TempLocation);
tempPath = QDir::toNativeSeparators(tempPath) + QDir::separator();
QString folderName = "backup_2";
QDir(tempPath).mkdir(folderName);

AppConfig config;
QSqlDatabase storageDb = DatabaseRegistry::fileStorageDatabase();

auto *rawPtr = new FileStorageManager(storageDb, tempPath + folderName);
auto *rawPtr = new FileStorageManager(storageDb, config.getStorageFolderPath());
auto result = QSharedPointer<FileStorageManager>(rawPtr);

return result;
Expand Down Expand Up @@ -176,7 +173,7 @@ bool FileStorageManager::appendVersion(const QString &symbolFilePath, const QStr

QFile file(pathToFile);
QString internalFileName = generateRandomFileName();
QString generatedFilePath = getBackupFolderPath() + internalFileName;
QString generatedFilePath = getStorageFolderPath() + internalFileName;
bool isCopied = file.copy(generatedFilePath);

if(!isCopied)
Expand Down Expand Up @@ -238,7 +235,7 @@ bool FileStorageManager::deleteFile(const QString &symbolFilePath)
QStringList internalPathList;

for(const FileVersionEntity &version : fileVersionList)
internalPathList.append(getBackupFolderPath() + version.internalFileName);
internalPathList.append(getStorageFolderPath() + version.internalFileName);

result = fileRepository->deleteEntity(entity);

Expand Down Expand Up @@ -267,7 +264,7 @@ bool FileStorageManager::deleteFileVersion(const QString &symbolFilePath, qlongl

if(result == true)
{
QString internalFilePath = getBackupFolderPath() + entity.internalFileName;
QString internalFilePath = getStorageFolderPath() + entity.internalFileName;
QFile::remove(internalFilePath);

FileEntity parentEntity = fileRepository->findBySymbolPath(symbolFilePath, true);
Expand Down Expand Up @@ -467,17 +464,17 @@ QJsonArray FileStorageManager::getActiveFileList() const
return result;
}

QString FileStorageManager::getBackupFolderPath() const
QString FileStorageManager::getStorageFolderPath() const
{
return backupFolderPath;
return storageFolderPath;
}

void FileStorageManager::setBackupFolderPath(const QString &newBackupFolderPath)
void FileStorageManager::setStorageFolderPath(const QString &newStorageFolderPath)
{
backupFolderPath = QDir::toNativeSeparators(newBackupFolderPath);
storageFolderPath = QDir::toNativeSeparators(newStorageFolderPath);

if(!backupFolderPath.endsWith(QDir::separator()))
backupFolderPath.append(QDir::separator());
if(!storageFolderPath.endsWith(QDir::separator()))
storageFolderPath.append(QDir::separator());
}

QString FileStorageManager::generateRandomFileName()
Expand Down
6 changes: 3 additions & 3 deletions Backend/FileStorageSubSystem/FileStorageManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class FileStorageManager
QJsonArray getActiveFolderList() const;
QJsonArray getActiveFileList() const;

QString getBackupFolderPath() const;
void setBackupFolderPath(const QString &newBackupFolderPath);
QString getStorageFolderPath() const;
void setStorageFolderPath(const QString &newStorageFolderPath);

private:
QString generateRandomFileName();
Expand All @@ -60,7 +60,7 @@ class FileStorageManager
bool sortFileVersionEntities(const FileEntity &parentEntity);

private:
QString backupFolderPath;
QString storageFolderPath;
QSqlDatabase database;
FolderRepository *folderRepository;
FileRepository *fileRepository;
Expand Down
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ set(PROJECT_SOURCES
Gui/DataModels/DialogImport/ItemDelegateAction.h
Gui/DataModels/DialogImport/ItemDelegateAction.cpp
#

# DialogSettings
Gui/Dialogs/DialogSettings.h
Gui/Dialogs/DialogSettings.cpp
Gui/Dialogs/DialogSettings.ui
#

# TabFileExplorer
Gui/Tabs/TabFileExplorer.h
Expand Down Expand Up @@ -119,9 +125,12 @@ set(PROJECT_SOURCES
#

main.cpp
resources.qrc

Utility/DatabaseRegistry.h
Utility/DatabaseRegistry.cpp
Utility/AppConfig.h
Utility/AppConfig.cpp
Utility/JsonDtoFormat.h

Backend/FileStorageSubSystem/FileStorageManager.h
Expand Down
2 changes: 1 addition & 1 deletion Gui/Dialogs/DialogAddNewFolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void DialogAddNewFolder::on_buttonSelectFolder_clicked()
auto fsm = FileStorageManager::instance();
QString selectedFolderPath = QDir::toNativeSeparators(dialog.selectedFiles().at(0)).append(QDir::separator());

QStorageInfo storageInfo(fsm->getBackupFolderPath());
QStorageInfo storageInfo(fsm->getStorageFolderPath());
qint64 folderSize = getFolderSize(selectedFolderPath);
qint64 availableSize = storageInfo.bytesFree();

Expand Down
2 changes: 1 addition & 1 deletion Gui/Dialogs/DialogCreateCopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void DialogCreateCopy::on_buttonCreateCopy_clicked()
auto fsm = FileStorageManager::instance();
QJsonObject fileJson = fsm->getFileVersionJson(currentFileSymbolPath, ui->comboBox->currentText().toInt());

QString internalFilePath = fsm->getBackupFolderPath();
QString internalFilePath = fsm->getStorageFolderPath();
internalFilePath += fileJson[JsonKeys::FileVersion::InternalFileName].toString();

QFile::remove(userFilePath);
Expand Down
2 changes: 1 addition & 1 deletion Gui/Dialogs/DialogExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void DialogExport::on_buttonExport_clicked()
{
QJsonObject versionJson = currentFileVersion.toObject();
QString internalFileName = versionJson[JsonKeys::FileVersion::InternalFileName].toString();
QString internalFilePath = fsm->getBackupFolderPath() + internalFileName;
QString internalFilePath = fsm->getStorageFolderPath() + internalFileName;

QFile rawFile(internalFilePath);
bool isReadable = rawFile.open(QFile::OpenModeFlag::ReadOnly);
Expand Down
72 changes: 72 additions & 0 deletions Gui/Dialogs/DialogSettings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "DialogSettings.h"
#include "ui_DialogSettings.h"

#include "Utility/AppConfig.h"

#include <QFileDialog>
#include <QStandardPaths>

DialogSettings::DialogSettings(QWidget *parent) :
QDialog(parent),
ui(new Ui::DialogSettings)
{
ui->setupUi(this);
}

DialogSettings::~DialogSettings()
{
delete ui;
}

void DialogSettings::show()
{
AppConfig config;
ui->lineEdit->setText(config.getStorageFolderPath());
showStatusInfo(tr("No changes made made to settings yet."), ui->labelStatus);
ui->buttonSave->setDisabled(true);

QWidget::show();
}

void DialogSettings::on_buttonSelectStorageFolder_clicked()
{
QString desktopPath = QStandardPaths::writableLocation(QStandardPaths::StandardLocation::DesktopLocation);
desktopPath = QDir::toNativeSeparators(desktopPath);
desktopPath += QDir::separator();

QString folderPath = QFileDialog::getExistingDirectory(this, tr("Select a profile folder"), desktopPath);

if(folderPath.isEmpty())
return;

folderPath = QDir::toNativeSeparators(folderPath) + QDir::separator();
ui->lineEdit->setText(folderPath);

bool isExist = QFile::exists(folderPath + "ns_database.db3");

if(isExist)
{
QString message = tr("Existing profile found at selected location.<br>"
"After saving, selected profile will be loaded. <b>NOTE:</b> Saving requires restard.");

showStatusSuccess(message, ui->labelStatus);
}
else
{
QString message = tr("No profile found at selected location. New profile will be created.<br>"
"After saving, new and empty profile will be loaded. <b>NOTE:</b> Saving requires restard.");

showStatusWarning(message, ui->labelStatus);
}

ui->buttonSave->setEnabled(true);
}


void DialogSettings::on_buttonSave_clicked()
{
AppConfig config;
config.setStorageFolderPath(ui->lineEdit->text());
qApp->exit(0);
}

31 changes: 31 additions & 0 deletions Gui/Dialogs/DialogSettings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef DIALOGSETTINGS_H
#define DIALOGSETTINGS_H

#include "BaseDialog.h"

#include <QDialog>

namespace Ui {
class DialogSettings;
}

class DialogSettings : public QDialog, public BaseDialog
{
Q_OBJECT

public:
explicit DialogSettings(QWidget *parent = nullptr);
~DialogSettings();

void show();

private slots:
void on_buttonSelectStorageFolder_clicked();

void on_buttonSave_clicked();

private:
Ui::DialogSettings *ui;
};

#endif // DIALOGSETTINGS_H
Loading

0 comments on commit 98b6eb9

Please sign in to comment.