Call template using explict types

master
JuanJakobo 2022-09-08 14:23:51 +02:00
parent fc030fa284
commit f8c628105d
4 changed files with 27 additions and 20 deletions

View File

@ -57,16 +57,16 @@ std::vector<WebDAVItem> WebDAV::login(const string &Url, const string &Username,
uuid = Username;
}
auto tempPath = NEXTCLOUD_ROOT_PATH + uuid + "/";
Util::accessConfig( Action::IWriteString, "storageLocation", "/mnt/ext1/nextcloud");
Util::accessConfig<string>( Action::IWriteString, "storageLocation", "/mnt/ext1/nextcloud");
std::vector<WebDAVItem> tempItems = getDataStructure(tempPath);
if (!tempItems.empty())
{
if (iv_access(CONFIG_PATH.c_str(), W_OK) != 0)
iv_buildpath(CONFIG_PATH.c_str());
Util::accessConfig( Action::IWriteString, "url", _url);
Util::accessConfig( Action::IWriteString, "username", _username);
Util::accessConfig( Action::IWriteString, "UUID", uuid);
Util::accessConfig( Action::IWriteSecret, "password", _password);
Util::accessConfig<string>( Action::IWriteString, "url", _url);
Util::accessConfig<string>( Action::IWriteString, "username", _username);
Util::accessConfig<string>( Action::IWriteString, "UUID", uuid);
Util::accessConfig<string>( Action::IWriteSecret, "password", _password);
}
else
{

View File

@ -36,11 +36,12 @@ EventHandler::EventHandler()
if (iv_access(CONFIG_PATH.c_str(), W_OK) == 0)
{
//for backwards compatibilty
if (Util::accessConfig<string>(Action::IReadString, "storageLocation",{}).empty())
Util::accessConfig(Action::IWriteString, "storageLocation", "/mnt/ext1/nextcloud");
if (Util::accessConfig<string>(Action::IReadString, "storageLocation",{}).compare("error") == 0)
Util::accessConfig<string>(Action::IWriteString, "storageLocation", "/mnt/ext1/nextcloud");
if (iv_access(Util::accessConfig<string>(Action::IReadString, "storageLocation",{}).c_str(), W_OK) != 0)
iv_mkdir(Util::accessConfig<string>(Action::IReadString, "storageLocation",{}).c_str(), 0777);
std::vector<WebDAVItem> currentWebDAVItems;
string path = NEXTCLOUD_ROOT_PATH + Util::accessConfig<string>(Action::IReadString,"UUID",{}) + '/';
@ -188,10 +189,10 @@ void EventHandler::mainMenuHandler(const int index)
switch (dialogResult)
{
case 1:
Util::accessConfig(Action::IWriteInt, "sortBy", 1);
Util::accessConfig<int>(Action::IWriteInt, "sortBy", 1);
break;
case 2:
Util::accessConfig(Action::IWriteInt, "sortBy", 2);
Util::accessConfig<int>(Action::IWriteInt, "sortBy", 2);
break;
default:
return;
@ -203,13 +204,16 @@ void EventHandler::mainMenuHandler(const int index)
case 104:
{
_currentPath =+ (_currentPath.back() != '/') ? "/nextcloud" : "nextcloud";
_currentPath = _currentPath + ((_currentPath.back() != '/') ? "/nextcloud" : "nextcloud");
if (iv_mkdir(_currentPath.c_str(), 0777) != 0)
{
Log::writeErrorLog("choosen part " + _currentPath + " could not be created as permission are not sufficient.");
Message(ICON_ERROR, "Error", "The permissions are not sufficient.", 1000);
}
else
{
Util::accessConfig(Action::IWriteString, "storageLocation", _currentPath);
Util::accessConfig<string>(Action::IWriteString, "storageLocation", _currentPath);
std::vector<WebDAVItem> currentWebDAVItems = _webDAV.getDataStructure(NEXTCLOUD_ROOT_PATH + Util::accessConfig<string>(Action::IReadString,"UUID",{}) + '/');
if (currentWebDAVItems.empty())
{
@ -377,11 +381,11 @@ int EventHandler::pointerHandler(const int type, const int par1, const int par2)
else
{
int dialogResult = DialogSynchro(ICON_QUESTION, "Action", "Do you want to choose your own storage path or use the default one. \n (/mnt/ext1/nextcloud/)", "Choose my own path", "Choose standard path", NULL);
auto path = "/mnt/ext1";
switch (dialogResult)
{
case 1:
{
auto path = "/mnt/ext1";
FileBrowser fileBrowser = FileBrowser(false);
vector<FileItem> currentFolder = fileBrowser.getFileStructure(path);
_currentPath = path;
@ -390,7 +394,10 @@ int EventHandler::pointerHandler(const int type, const int par1, const int par2)
_fileView = std::unique_ptr<FileView>(new FileView(_menu->getContentRect(), currentFolder,1));
}
break;
case 2:
default:
if (iv_access(Util::accessConfig<string>(Action::IReadString, "storageLocation",{}).c_str(), W_OK) != 0)
iv_mkdir(Util::accessConfig<string>(Action::IReadString, "storageLocation",{}).c_str(), 0777);
updateItems(currentWebDAVItems);
drawWebDAVItems(currentWebDAVItems);
break;
@ -549,6 +556,7 @@ int EventHandler::keyHandler(const int type, const int par1, const int par2)
}
//TODO use Filebrowser
void EventHandler::getLocalFileStructure(vector<WebDAVItem> &items)
{
//get local files, https://stackoverflow.com/questions/306533/how-do-i-get-a-list-of-files-in-a-directory-in-c
@ -694,6 +702,7 @@ void EventHandler::updateItems(vector<WebDAVItem> &items)
{
for(auto &item : items)
{
//ICloud if is not found
item.state = _sqllite.getState(item.path);
if (item.type == Itemtype::IFILE)

View File

@ -47,7 +47,7 @@ WebDAVView::WebDAVView(const irect &contentRect, vector<WebDAVItem> &items, int
sort(begin, items.end(), []( WebDAVItem &w1, WebDAVItem &w2) -> bool
{
if(Util::accessConfig(Action::IReadInt, "sortBy", 0) == 2)
if(Util::accessConfig<int>(Action::IReadInt, "sortBy", 0) == 2)
{
//sort by lastmodified
time_t t1 = mktime(&w1.lastEditDate);

View File

@ -12,6 +12,7 @@
#include "inkview.h"
#include "eventHandler.h"
#include "log.h"
#include <string>
enum class Action
@ -65,9 +66,6 @@ public:
iconfig *config = OpenConfig(CONFIG_PATH.c_str(), temp);
T returnValue;
if constexpr(std::is_same<T, Entry>::value)
{
}
if constexpr(std::is_same<T, std::string>::value)
{
switch (action)
@ -77,14 +75,14 @@ public:
returnValue = {};
break;
case Action::IReadSecret:
returnValue = ReadSecret(config, name.c_str(), "");
returnValue = ReadSecret(config, name.c_str(), "error");
break;
case Action::IWriteString:
WriteString(config, name.c_str(), value.c_str());
returnValue = {};
break;
case Action::IReadString:
returnValue = ReadString(config, name.c_str(), "");
returnValue = ReadString(config, name.c_str(), "error");
break;
default:
break;