Ability to lock switching between s3 and imgur and use s3 only

This commit is contained in:
Yuriy Puchkov
2020-10-06 15:57:45 +03:00
parent 79ededbd99
commit 7d0d51efb5
5 changed files with 45 additions and 2 deletions

View File

@@ -17,6 +17,7 @@
#include "uploadstorageconfig.h"
#include "src/tools/storage/imgstorages.h"
#include "src/tools/storage/storagemanager.h"
#include "src/utils/confighandler.h"
#include <QCheckBox>
@@ -46,6 +47,13 @@ UploadStorageConfig::UploadStorageConfig(QWidget* parent)
ConfigHandler().setUploadStorage(SCREENSHOT_STORAGE_TYPE_S3);
});
StorageManager storageManager;
if (storageManager.storageLocked()) {
ConfigHandler().setUploadStorage(storageManager.storageDefault());
storageImgUr->setDisabled(true);
storageImgS3->setDisabled(true);
}
// set current storage radiobutton active
if (ConfigHandler().uploadStorage() == SCREENSHOT_STORAGE_TYPE_IMGUR) {
storageImgUr->setChecked(true);

View File

@@ -1,4 +1,9 @@
[General]
; Lock storage selection for the enterprise users
; (it will lock to the default storage)
STORAGE_LOCK=true
; PROXY SETTINGS
;HTTP_PROXY_HOST=0.0.0.0
;HTTP_PROXY_PORT=3128
@@ -6,7 +11,7 @@
;HTTP_PROXY_USER=
;HTTP_PROXY_PASSWORD=
HTTP_PROXY_TYPE=3
;HTTP_PROXY_TYPE=3
; Proxy Types (3 is default):
; 0 Proxy is determined based on the application proxy set using setApplicationProxy()
; 1 Socks5 proxying is used

View File

@@ -4,6 +4,8 @@
#include "s3/imgs3settings.h"
#include "s3/imgs3uploadertool.h"
#include "src/tools/capturetool.h"
#include <QSettings>
#include <QStringLiteral>
StorageManager::StorageManager() {}
@@ -38,4 +40,18 @@ const QString& StorageManager::storageDefault()
m_qstr = SCREENSHOT_STORAGE_TYPE_IMGUR;
}
return m_qstr;
}
bool StorageManager::storageLocked()
{
// TODO - move this to some common config file, not a storage specific
// configuration file
bool res = false;
ImgS3Settings imgS3Settings;
if (imgS3Settings.settings()->contains("STORAGE_LOCK")) {
res = imgS3Settings.settings()
->value(QStringLiteral("STORAGE_LOCK"))
.toBool();
}
return res;
}

View File

@@ -17,6 +17,7 @@ public:
QObject* parent = nullptr);
const QString& storageUrl(const QString& imgUploaderType);
const QString& storageDefault();
bool storageLocked();
private:
// class members

View File

@@ -464,11 +464,24 @@ void ConfigHandler::setCopyPathAfterSaveEnabled(const bool value)
void ConfigHandler::setUploadStorage(const QString& uploadStorage)
{
m_settings.setValue(QStringLiteral("uploadStorage"), uploadStorage);
StorageManager storageManager;
if (storageManager.storageLocked()) {
m_settings.setValue(QStringLiteral("uploadStorage"),
storageManager.storageDefault());
} else {
m_settings.setValue(QStringLiteral("uploadStorage"), uploadStorage);
}
}
const QString& ConfigHandler::uploadStorage()
{
StorageManager storageManager;
// check for storage lock
if (storageManager.storageLocked()) {
setUploadStorage(storageManager.storageDefault());
}
// get storage
m_strRes = m_settings.value(QStringLiteral("uploadStorage")).toString();
if (m_strRes.isEmpty()) {
StorageManager storageManager;