commit cde3c683eb8e313ad6d31ab2aa6ddfebe52d70e0
parent 4b5d1fb9a0f9170abc0df49c110615eb59daecf5
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sat, 3 Jun 2017 19:46:09 -0400
api: create EnumRepositories function
Diffstat:
3 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/src/api.cpp b/src/api.cpp
@@ -17,12 +17,15 @@
#include "api.hpp"
+#include <boost/lexical_cast.hpp>
+#include <boost/logic/tribool_io.hpp> // required to get correct tribool casts
#include <boost/mpl/aux_/preprocessor/token_equal.hpp>
#include <boost/preprocessor.hpp>
#include <reaper_plugin_functions.h>
#include "about.hpp"
+#include "config.hpp"
#include "errors.hpp"
#include "index.hpp"
#include "reapack.hpp"
@@ -181,6 +184,36 @@ DEFINE_API(bool, EnumOwnedFiles, ((PackageEntry*, entry))((int, index))
return entry->files.size() > i + 1;
});
+DEFINE_API(bool, EnumRepositories, ((int, index))
+ ((char*, nameOut))((int, nameOut_sz))((char*, urlOut))((int, urlOut_sz))
+ ((bool*, enabledOut))((int*, autoInstallOut)), R"(
+ Enumerate the repository list. Returns false once the end of the list is reached.
+
+ autoInstall: 0=manual, 1=when sychronizing, 2=use global setting
+)", {
+ const size_t i = index;
+ const RemoteList &list = reapack->config()->remotes;
+
+ if(i >= list.size())
+ return false;
+
+ auto it = list.begin();
+ advance(it, i);
+
+ const Remote &remote = *it;
+
+ if(nameOut)
+ snprintf(nameOut, nameOut_sz, "%s", remote.name().c_str());
+ if(urlOut)
+ snprintf(urlOut, urlOut_sz, "%s", remote.url().c_str());
+ if(enabledOut)
+ *enabledOut = remote.isEnabled();
+ if(autoInstallOut)
+ *autoInstallOut = boost::lexical_cast<int>(remote.autoInstall());
+
+ return list.size() > i + 1;
+});
+
DEFINE_API(bool, FreeEntry, ((PackageEntry*, entry)), R"(
Free resources allocated for the given package entry.
)", {
diff --git a/src/api.hpp b/src/api.hpp
@@ -49,6 +49,7 @@ namespace API {
extern APIFunc AboutRepository;
extern APIFunc CompareVersions;
extern APIFunc EnumOwnedFiles;
+ extern APIFunc EnumRepositories;
extern APIFunc FreeEntry;
extern APIFunc GetEntryInfo;
extern APIFunc GetOwner;
diff --git a/src/main.cpp b/src/main.cpp
@@ -164,6 +164,7 @@ static void setupAPI()
reapack->setupAPI(&API::AboutRepository);
reapack->setupAPI(&API::CompareVersions);
reapack->setupAPI(&API::EnumOwnedFiles);
+ reapack->setupAPI(&API::EnumRepositories);
reapack->setupAPI(&API::FreeEntry);
reapack->setupAPI(&API::GetEntryInfo);
reapack->setupAPI(&API::GetOwner);