Skip to content

Commit

Permalink
qimageuploader: save selected servers
Browse files Browse the repository at this point in the history
Refactor CommonGuiSettings and WtlGuiSettings
  • Loading branch information
zenden2k committed Apr 30, 2024
1 parent 1895e38 commit 2a235b7
Show file tree
Hide file tree
Showing 17 changed files with 254 additions and 192 deletions.
2 changes: 1 addition & 1 deletion Data/Scripts/yandexdisk.nut
Expand Up @@ -266,7 +266,7 @@ function Authenticate() {

ShellOpenUrl("https://oauth.yandex.ru/authorize?response_type=code&client_id=a49c34035aa8418d9a77ff24e0660719");

local confirmCode = InputDialog(tr("yandexdisk.confirmation.text", "You need to need to sign in to your Yandex.Disk account in web browser which just have opened and then copy confirmation code into the text field below. Please enter confirmation code:"), "");
local confirmCode = InputDialog(tr("yandexdisk.confirmation.text", "You need to need to sign in to your Yandex.Disk account\r\nin web browser which just have opened and then copy\r\nconfirmation code into the text field below.\r\n\r\nPlease enter confirmation code:"), "");
if ( confirmCode != "" ) {
nm.setUrl("https://oauth.yandex.ru/token");
nm.addQueryParam("grant_type", "authorization_code");
Expand Down
5 changes: 2 additions & 3 deletions Source/Core/Settings/BasicSettings.cpp
Expand Up @@ -152,8 +152,7 @@ void BasicSettings::BindToManager()
upload.n_bind(MaxUploadSpeed);
}

bool BasicSettings::PostLoadSettings(SimpleXml &xml)
{
bool BasicSettings::PostLoadSettings(SimpleXml &xml) {
return true;
}

Expand Down Expand Up @@ -212,4 +211,4 @@ ServerSettingsStruct* BasicSettings::getServerSettings(const ServerProfile& prof
}
}
return nullptr;
}
}
2 changes: 1 addition & 1 deletion Source/Core/Settings/BasicSettings.h
Expand Up @@ -63,4 +63,4 @@ class BasicSettings {
virtual bool PostLoadSettings(SimpleXml &xml);
virtual bool PostSaveSettings(SimpleXml &xml);
};
#endif
#endif
154 changes: 150 additions & 4 deletions Source/Core/Settings/CommonGuiSettings.cpp
Expand Up @@ -20,7 +20,9 @@ limitations under the License.

#include "CommonGuiSettings.h"

#ifndef IU_QT
#include "Func/WinUtils.h"
#endif

const TCHAR CommonGuiSettings::VideoEngineDirectshow[] = _T("Directshow");
const TCHAR CommonGuiSettings::VideoEngineDirectshow2[] = _T("Directshow_2");
Expand All @@ -30,14 +32,12 @@ const TCHAR CommonGuiSettings::VideoEngineAuto[] = _T("Auto");
CommonGuiSettings::CommonGuiSettings() : BasicSettings()
{
// Default values of settings

ShowTrayIcon = false;
ShowTrayIcon_changed = false;
MaxThreads = 3;
DeveloperMode = false;
//temporaryServer.UseDefaultSettings = false;
#ifndef IU_QT
HistorySettings.EnableDownloading = true;
HistorySettings.HistoryConverted = false;
#endif
}

CommonGuiSettings::~CommonGuiSettings() {
Expand All @@ -55,3 +55,149 @@ bool CommonGuiSettings::IsFFmpegAvailable() {
#endif
#endif
}

bool CommonGuiSettings::LoadServerProfiles(SimpleXmlNode root)
{
std::vector<SimpleXmlNode> servers;
root.GetChilds("ServerProfile", servers);

for (size_t i = 0; i < servers.size(); i++) {
SimpleXmlNode serverProfileNode = servers[i];
std::string profileName = serverProfileNode.Attribute("ServerProfileId");
ServerProfile sp;
SettingsManager mgr;
sp.bind(mgr.root());

mgr.loadFromXmlNode(serverProfileNode);
ServerProfiles[Utf8ToSettingsString(profileName)] = sp;
}
return true;
}

bool CommonGuiSettings::SaveServerProfiles(SimpleXmlNode root)
{
for (ServerProfilesMap::iterator it = ServerProfiles.begin(); it != ServerProfiles.end(); ++it) {
SimpleXmlNode serverProfileNode = root.CreateChild("ServerProfile");

std::string profileName = SettingsStringToUtf8(it->first);

//ServerProfile sp = ;
SettingsManager mgr;
it->second.bind(mgr.root());
mgr["@ServerProfileId"].bind(profileName);

mgr.saveToXmlNode(serverProfileNode);
}
return true;
}

void CommonGuiSettings::LoadServerProfile(SimpleXmlNode root, ServerProfile& profile) {
SettingsManager mgr;
profile.bind(mgr.root());
mgr.loadFromXmlNode(root);
}

bool CommonGuiSettings::LoadServerProfileGroup(SimpleXmlNode root, ServerProfileGroup& group) {
std::vector<SimpleXmlNode> servers;
root.GetChilds("ServerProfileItem", servers);
if (!servers.empty()) {
group.getItems().clear();
for (size_t i = 0; i < servers.size(); i++) {
SimpleXmlNode serverProfileNode = servers[i];
/*std::string profileName = serverProfileNode.Attribute("ServerProfileId");*/
ServerProfile sp;
SettingsManager mgr;
sp.bind(mgr.root());

mgr.loadFromXmlNode(serverProfileNode);
group.addItem(sp);
}
}
return true;
}
bool CommonGuiSettings::SaveServerProfileGroup(SimpleXmlNode root, ServerProfileGroup& group) {
for (auto& item: group.getItems()) {
SimpleXmlNode serverProfileNode = root.CreateChild("ServerProfileItem");
SettingsManager mgr;
SettingsNode& image = mgr.root();
item.bind(image);

mgr.saveToXmlNode(serverProfileNode);
}
return true;
}

bool CommonGuiSettings::PostLoadSettings(SimpleXml &xml)
{
BasicSettings::PostLoadSettings(xml);
SimpleXmlNode settingsNode = xml.getRoot(rootName_).GetChild("Settings");
LoadServerProfiles(settingsNode.GetChild("Uploading").GetChild("ServerProfiles"));

auto uploading = settingsNode.GetChild("Uploading");

ServerProfile oldImageServer, oldFileServer, oldQuickScreenshotServer, oldContextMenuServer;
// Load the old format of chosen servers (just reading)
LoadServerProfile(uploading.GetChild("Server"), oldImageServer);
LoadServerProfile(uploading.GetChild("FileServer"), oldFileServer);
LoadServerProfile(uploading.GetChild("QuickScreenshotServer"), oldQuickScreenshotServer);
LoadServerProfile(uploading.GetChild("ContextMenuServer"), oldContextMenuServer);
/*LoadServerProfile(uploading.GetChild("UrlShorteningServer"), oldUrlShorteningServer);
LoadServerProfile(uploading.GetChild("TemporaryServer"), oldTemporaryServer);*/

imageServer = oldImageServer;
fileServer = oldFileServer;
quickScreenshotServer = oldQuickScreenshotServer;
/*urlShorteningServer = oldUrlShorteningServer;
temporaryServer = oldTemporaryServer;*/

// Load the new format of chosen servers
LoadServerProfileGroup(uploading.GetChild("ServerGroup"), imageServer);
LoadServerProfileGroup(uploading.GetChild("FileServerGroup"), fileServer);
LoadServerProfileGroup(uploading.GetChild("QuickScreenshotServerGroup"), quickScreenshotServer);
LoadServerProfileGroup(uploading.GetChild("ContextMenuServerGroup"), contextMenuServer);


PostLoadServerProfileGroup(imageServer);
PostLoadServerProfileGroup(fileServer);
PostLoadServerProfileGroup(contextMenuServer);
PostLoadServerProfileGroup(quickScreenshotServer);
PostLoadServerProfile(urlShorteningServer);
PostLoadServerProfile(temporaryServer);

return true;
}

void CommonGuiSettings::PostLoadServerProfileGroup(ServerProfileGroup& profileGroup) {
for(auto& item: profileGroup.getItems()) {
PostLoadServerProfile(item);
}
}

void CommonGuiSettings::PostLoadServerProfile(ServerProfile& profile) {
if (!profile.profileName().empty() && ServersSettings[profile.serverName()].find(profile.profileName()) == ServersSettings[profile.serverName()].end()) {
profile.setProfileName("");
}
}

void CommonGuiSettings::BindToManager() {
BasicSettings::BindToManager();
SettingsNode& upload = mgr_["Uploading"];
urlShorteningServer.bind(upload["UrlShorteningServer"]);
temporaryServer.bind(upload["TemporaryServer"]);
}

bool CommonGuiSettings::PostSaveSettings(SimpleXml &xml) {
BasicSettings::PostSaveSettings(xml);
SaveServerProfiles(xml.getRoot(rootName_).GetChild("Settings").GetChild("Uploading").GetChild("ServerProfiles"));

SimpleXmlNode uploading = xml.getRoot(rootName_).GetChild("Settings").GetChild("Uploading");
SaveServerProfileGroup(uploading.GetChild("ServerGroup"), imageServer);
SaveServerProfileGroup(uploading.GetChild("FileServerGroup"), fileServer);
SaveServerProfileGroup(uploading.GetChild("QuickScreenshotServerGroup"), quickScreenshotServer);
SaveServerProfileGroup(uploading.GetChild("ContextMenuServerGroup"), contextMenuServer);
return true;
}




60 changes: 30 additions & 30 deletions Source/Core/Settings/CommonGuiSettings.h
Expand Up @@ -14,34 +14,23 @@
#ifdef IU_QT
#include <QString>
typedef QString SettingsString;
#define Utf8ToSettingsString(s) QString::fromStdString(s)
#define SettingsStringToUtf8(s) s.toStdString()

#else
#include "atlheaders.h"
typedef CString SettingsString;
#define Utf8ToSettingsString(s) Utf8ToWCstring(s)
#define SettingsStringToUtf8(s) WCstringToUtf8(s)
#endif

#include "EncodedPassword.h"

#include "Core/Images/ImageConverter.h"

struct UploadProfileStruct {
bool GenThumb;
bool KeepAsIs;
int ServerID, QuickServerID;
};

typedef std::map<CString, ServerProfile> ServerProfilesMap;

struct FullUploadProfile {
ServerProfile upload_profile;
ImageConvertingParams convert_profile;
};

/*struct ThumbSettingsStruct : public ThumbCreatingParams {
TCHAR FontName[256];
BOOL UseServerThumbs;
bool CreateThumbs;
};*/
typedef std::map<SettingsString, ServerProfile> ServerProfilesMap;

#ifndef IU_QT
struct VideoSettingsStruct {
int Columns;
int TileWidth;
Expand All @@ -66,29 +55,31 @@ struct HistorySettingsStruct {
bool EnableDownloading;
bool HistoryConverted;
};

#endif

class CommonGuiSettings : public BasicSettings {
public:
CommonGuiSettings();
~CommonGuiSettings();

UploadProfileStruct UploadProfile;
bool UseDirectLinks;

ServerProfile urlShorteningServer, temporaryServer;
ServerProfileGroup imageServer, fileServer, quickScreenshotServer, contextMenuServer;
ServerProfilesMap ServerProfiles;
#ifndef IU_QT
CString Language;
CString DataFolder;
CString m_SettingsDir;
CString Language;

#ifndef IU_SERVERLISTTOOL
bool ShowTrayIcon;
bool ShowTrayIcon_changed;
bool ShowTrayIcon = false;
bool ShowTrayIcon_changed = false;
bool AutoStartup;
bool AutoStartup_changed;
int ThumbsPerLine;
TCHAR m_szLang[64];
VideoSettingsStruct VideoSettings;
MediaInfoSettingsStruct MediaInfoSettings;
ServerProfile urlShorteningServer, temporaryServer;
ServerProfileGroup imageServer, fileServer, quickScreenshotServer, contextMenuServer;

HistorySettingsStruct HistorySettings;

int CodeLang;
Expand All @@ -100,12 +91,21 @@ class CommonGuiSettings : public BasicSettings {
CString VideoFolder, ImagesFolder;

std::map<CString, ImageConvertingParams> ConvertProfiles;
ServerProfilesMap ServerProfiles;

protected:
CString CurrentConvertProfileName;
public:

#endif
protected:
void BindToManager();
bool PostSaveSettings(SimpleXml &xml) override;
bool PostLoadSettings(SimpleXml &xml) override;
bool LoadServerProfiles(SimpleXmlNode root);
bool SaveServerProfiles(SimpleXmlNode root);
void LoadServerProfile(SimpleXmlNode root, ServerProfile& profile);
bool LoadServerProfileGroup(SimpleXmlNode root, ServerProfileGroup& group);
bool SaveServerProfileGroup(SimpleXmlNode root, ServerProfileGroup& group);
void PostLoadServerProfileGroup(ServerProfileGroup& profile);
virtual void PostLoadServerProfile(ServerProfile& profile);
public:
static const TCHAR VideoEngineDirectshow[];
static const TCHAR VideoEngineDirectshow2[];
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Settings/QtGuiSettings.cpp
@@ -1,6 +1,6 @@
#include "QtGuiSettings.h"

QtGuiSettings::QtGuiSettings() : BasicSettings() {
QtGuiSettings::QtGuiSettings() : CommonGuiSettings() {
BindToManager();
}

Expand Down
6 changes: 3 additions & 3 deletions Source/Core/Settings/QtGuiSettings.h
Expand Up @@ -2,11 +2,11 @@
#define IU_CORE_SETTINGS_QTGUISETTINGS_H

#pragma once
#include "BasicSettings.h"
#include "CommonGuiSettings.h"

class QtGuiSettings : public BasicSettings {
class QtGuiSettings : public CommonGuiSettings {
public:
QtGuiSettings();
};

#endif
#endif

0 comments on commit 2a235b7

Please sign in to comment.