Skip to content

Commit

Permalink
Add choice parameter to CServerParamsDlg (ComboBox) #366
Browse files Browse the repository at this point in the history
  • Loading branch information
zenden2k committed Oct 15, 2024
1 parent c9ac4a2 commit 3314ab2
Show file tree
Hide file tree
Showing 19 changed files with 388 additions and 45 deletions.
3 changes: 3 additions & 0 deletions Data/Scripts/Lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@
"text": "Пожалуйста, разрешите Image Uploader подключиться к вашему аккаунту Flickr (нажмите кнопку Allow в запущенном браузере), и после этого нажмите OK."
},
"verification": "Введите код подтверждения:"
},
"imgbb": {
"expiration": "Автоудаление (в минутах)"
}
}
111 changes: 110 additions & 1 deletion Data/Scripts/imgbb.nut
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,19 @@ function _UploadToAccount(FileName, options) {
if (apiKey == "") {
WriteLog("error", "[imgbb.com] Cannot upload to account without API key");
return 0;
}
local expiration = 0;
try {
expiration = 60 * ServerParams.getParam("uploadExpiration").tointeger();
} catch (ex) {

}
nm.addQueryParam("key", apiKey);
if (expiration) {
nm.addQueryParam("expiration", expiration);
}
nm.addQueryParamFile("image", FileName, ExtractFileName(FileName), "");
nm.setUrl("https://api.imgbb.com/1/upload");
nm.setUrl("https://api.imgbb.com/1/upload?expiration=" + expiration);
nm.doUploadMultipartData();
local t = ParseJSON(nm.responseBody());
if (nm.responseCode() == 200) {
Expand Down Expand Up @@ -89,4 +98,104 @@ function UploadFile(FileName, options) {
}
return 0;
}
}

function GetServerParamList() {
return {
uploadExpiration = tr("imgbb.expiration", "Expiration (in minutes)")
/*uploadExpiration = {
title = "Auto-delete after",
type = "choice",
items = [
{
id = "",
label = "Never"
},
{
id = "PT5M",
label = "15 minutes"
},
{
id = "PT30M",
label = "30 minutes"
},
{
id = "PT1H",
label = "1 hour"
},
{
id = "PT3H",
label = "3 hours"
},
{
id = "PT6H",
label = "6 hours"
},
{
id = "PT12H",
label = "12 hours"
},
{
id = "P1D",
label = "1 day"
},
{
id = "P2D",
label = "2 days"
},
{
id = "P3D",
label = "3 days"
},
{
id = "P4D",
label = "4 days"
},
{
id = "P5D",
label = "5 days"
},
{
id = "P6D",
label = "6 days"
},
{
id = "P1W",
label = "1 week"
},
{
id = "P2W",
label = "2 weeks"
},
{
id = "P3W",
label = "3 weeks"
},
{
id = "P1M",
label = "1 month"
},
{
id = "P2M",
label = "2 months"
},
{
id = "P3M",
label = "3 months"
},
{
id = "P4M",
label = "4 months"
},
{
id = "P5M",
label = "5 months"
},
{
id = "P6M",
label = "6 months"
}
]
}*/
};
}
6 changes: 6 additions & 0 deletions Source/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ set(SRC_LIST Network/NetworkClient.cpp
Upload/UploadManager.cpp
Upload/UploadSession.cpp
Upload/AdvancedUploadEngine.cpp
Upload/Parameters/AbstractParameter.cpp
Upload/Parameters/TextParameter.cpp
Upload/Parameters/ChoiceParameter.cpp
ServiceLocator.cpp
Settings/BasicSettings.cpp
Logging/MyLogSink.cpp
Expand Down Expand Up @@ -111,6 +114,9 @@ set(HEADER_LIST Network/NetworkClient.h
Upload/SearchByImageUrlTask.h
Upload/SearchByImageFileTask.h
Upload/TempImageUploadTask.h
Upload/Parameters/AbstractParameter.h
Upload/Parameters/TextParameter.h
Upload/Parameters/ChoiceParameter.h
Utils/CoreUtils.h
Utils/CryptoUtils.h
Utils/SimpleXml.h
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Upload/AdvancedUploadEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "Core/Utils/CoreTypes.h"
#include "Core/Upload/FolderList.h"
#include "Core/Network/NetworkClient.h"
#include "Parameters/AbstractParameter.h"

class CAdvancedUploadEngine : public CAbstractUploadEngine
{
Expand All @@ -43,7 +44,7 @@ class CAdvancedUploadEngine : public CAbstractUploadEngine
virtual int createFolder(const CFolderItem &parent, CFolderItem &folder)=0;
virtual int modifyFolder(CFolderItem &folder)=0;
virtual int getAccessTypeList(std::vector<std::string> &list)=0;
virtual int getServerParamList(std::map<std::string, std::string> &list)=0;
virtual int getServerParamList(ParameterList& list) = 0;
virtual int doLogin()=0;
virtual int doLogout()=0;
virtual bool isAuthenticated() = 0;
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Upload/MegaNzUploadEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ int CMegaNzUploadEngine::getAccessTypeList(std::vector<std::string>& list) {
return 1;
}

int CMegaNzUploadEngine::getServerParamList(std::map<std::string, std::string>& list) {
int CMegaNzUploadEngine::getServerParamList(ParameterList& list)
{
return 0;
}

Expand Down
5 changes: 3 additions & 2 deletions Source/Core/Upload/MegaNzUploadEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "Core/Upload/FolderList.h"
#include "AdvancedUploadEngine.h"
#include "FileUploadTask.h"
#include "Parameters/AbstractParameter.h"

class MyListener;
class MyGfxProcessor;
Expand All @@ -52,7 +53,7 @@ class CMegaNzUploadEngine : public CAdvancedUploadEngine {
int createFolder(const CFolderItem &parent, CFolderItem &folder) override;
int modifyFolder(CFolderItem &folder) override;
int getAccessTypeList(std::vector<std::string> &list) override;
int getServerParamList(std::map<std::string, std::string> &list) override;
int getServerParamList(ParameterList &list) override;
int doLogin() override;

bool supportsSettings() override;
Expand Down Expand Up @@ -83,4 +84,4 @@ class CMegaNzUploadEngine : public CAdvancedUploadEngine {

};

#endif
#endif
19 changes: 19 additions & 0 deletions Source/Core/Upload/Parameters/AbstractParameter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "AbstractParameter.h"

AbstractParameter::AbstractParameter(std::string name)
: name_(std::move(name))
{
}

std::string AbstractParameter::getName() const
{
return name_;
}

void AbstractParameter::setTitle(const std::string title) {
title_ = title;
}

std::string AbstractParameter::getTitle() const {
return title_;
}
24 changes: 24 additions & 0 deletions Source/Core/Upload/Parameters/AbstractParameter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include <string>
#include <memory>
#include <vector>

class AbstractParameter {
public:
AbstractParameter(std::string name);
virtual ~AbstractParameter() = default;

std::string getName() const;
void setTitle(const std::string title);
std::string getTitle() const;
virtual std::string getType() const = 0;

virtual void setValue(const std::string& val) = 0;
virtual std::string getValue() const = 0;

private:
std::string name_, title_;
};

using ParameterList = std::vector<std::unique_ptr<AbstractParameter>>;
30 changes: 30 additions & 0 deletions Source/Core/Upload/Parameters/ChoiceParameter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "ChoiceParameter.h"

ChoiceParameter::ChoiceParameter(std::string title)
: AbstractParameter(std::move(title))
{
}

std::string ChoiceParameter::getType() const {
return "choice";
}

std::string ChoiceParameter::getValue() const {
return value_;
}

void ChoiceParameter::setValue(const std::string& val) {
value_ = val;
}

void ChoiceParameter::addItem(const std::string& id, const std::string& value) {
items_.push_back({ id, value });
}

void ChoiceParameter::clearItems() {
items_.clear();
}

const std::vector<std::pair<std::string, std::string>>& ChoiceParameter::getItems() const{
return items_;
}
19 changes: 19 additions & 0 deletions Source/Core/Upload/Parameters/ChoiceParameter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include "AbstractParameter.h"

class ChoiceParameter: public AbstractParameter {
public:
explicit ChoiceParameter(std::string name);

std::string getType() const override;
std::string getValue() const override;
void setValue(const std::string& val) override;
void addItem(const std::string& id, const std::string& value);
void clearItems();
const std::vector<std::pair<std::string, std::string>>& getItems() const;

private:
std::string value_;
std::vector<std::pair<std::string, std::string>> items_;
};
18 changes: 18 additions & 0 deletions Source/Core/Upload/Parameters/TextParameter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "TextParameter.h"

TextParameter::TextParameter(std::string title)
: AbstractParameter(std::move(title))
{
}

std::string TextParameter::getType() const {
return "text";
}

std::string TextParameter::getValue() const {
return value_;
}

void TextParameter::setValue(const std::string& val) {
value_ = val;
}
15 changes: 15 additions & 0 deletions Source/Core/Upload/Parameters/TextParameter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include "AbstractParameter.h"

class TextParameter: public AbstractParameter {
public:
explicit TextParameter(std::string name);

std::string getType() const override;
std::string getValue() const override;
void setValue(const std::string& val) override;

private:
std::string value_;
};
Loading

0 comments on commit 3314ab2

Please sign in to comment.