commit 3ec1dd4f9420f9e508bcb49ba28dcd17c1ba4ebb
parent 455ac85cceb49e603cd6c572041aad4e0775d92f
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sun, 4 Jun 2017 04:11:18 -0400
api: add GetRepository function
Diffstat:
3 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/src/api.cpp b/src/api.cpp
@@ -185,11 +185,8 @@ DEFINE_API(bool, EnumOwnedFiles, ((PackageEntry*, entry))((int, index))
});
DEFINE_API(bool, EnumRepositories, ((int, index))
- ((char*, nameOut))((int, nameOut_sz))((char*, urlOut))((int, urlOut_sz))
- ((bool*, enabledOut))((int*, autoInstallOut)), R"(
+ ((char*, nameOut))((int, nameOut_sz)), 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;
@@ -204,12 +201,6 @@ DEFINE_API(bool, EnumRepositories, ((int, index))
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;
});
@@ -296,12 +287,34 @@ DEFINE_API(PackageEntry*, GetOwner, ((const char*, fn))((char*, errorOut))((int,
}
});
+DEFINE_API(bool, GetRepository, ((const char*, name))
+ ((char*, urlOut))((int, urlOut_sz))
+ ((bool*, enabledOut))((int*, autoInstallOut)), R"(
+ Get the infos of the given repository.
+
+ autoInstall: 0=manual, 1=when sychronizing, 2=obey user setting
+)", {
+ const Remote &remote = reapack->remote(name);
+
+ if(!remote)
+ return false;
+
+ 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 true;
+});
+
DEFINE_API(bool, SetRepository, ((const char*, name))((const char*, url))
((bool, enabled))((int, autoInstall))((bool, commit))
((char*, errorOut))((int, errorOut_sz)), R"(
- Add the given repository name and URL to the list. Set commit to true on the last call to this function.
+ Add or modify a repository. Set commit to true for the last call to save the new list and update the GUI.
- autoInstall: default is 2 (use global setting).
+ autoInstall: default is 2 (obey user setting).
)", {
try {
if(reapack->remote(name).isProtected()) {
diff --git a/src/api.hpp b/src/api.hpp
@@ -53,6 +53,7 @@ namespace API {
extern APIFunc FreeEntry;
extern APIFunc GetEntryInfo;
extern APIFunc GetOwner;
+ extern APIFunc GetRepository;
extern APIFunc SetRepository;
};
diff --git a/src/main.cpp b/src/main.cpp
@@ -168,6 +168,7 @@ static void setupAPI()
reapack->setupAPI(&API::FreeEntry);
reapack->setupAPI(&API::GetEntryInfo);
reapack->setupAPI(&API::GetOwner);
+ reapack->setupAPI(&API::GetRepository);
reapack->setupAPI(&API::SetRepository);
}