commit 0021e7d8dbabe8982c8a495682e425fc1bba2451
parent 33b2afc330ba7dfd858efd4915ad04df5ccc653f
Author: cfillion <cfillion@users.noreply.github.com>
Date: Thu, 24 Aug 2017 16:31:18 -0400
api: merge part of AddSetRepository codebase with GUI import logic
(It now synchronizes the repo on enable and, when autoInstall is on, upon insertion)
Diffstat:
6 files changed, 40 insertions(+), 35 deletions(-)
diff --git a/src/about.cpp b/src/about.cpp
@@ -507,7 +507,7 @@ void AboutIndexDelegate::install()
if(!tx)
return;
- reapack->enable(remote);
+ reapack->setRemoteEnabled(remote);
tx->synchronize(remote, choice == INSTALL_ALL);
tx->runTasks();
diff --git a/src/api.cpp b/src/api.cpp
@@ -325,18 +325,13 @@ autoInstall: usually set to 2 (obey user setting).)",
return false;
}
- Remote remote(name, url, enable, boost::lexical_cast<tribool>(autoInstall));
+ Remote remote = reapack->remote(name);
+ remote.setName(name);
+ remote.setUrl(url);
+ remote.setAutoInstall(boost::lexical_cast<tribool>(autoInstall));
- if(existing && enable != existing.isEnabled()) {
- Transaction *tx = reapack->setupTransaction();
-
- if(!tx)
- return false;
-
- reapack->setRemoteEnabled(enable, remote);
- }
- else
- reapack->config()->remotes.add(remote);
+ if(!reapack->addSetRemote(remote, enable))
+ return false;
}
catch(const reapack_error &e) {
if(errorOut)
diff --git a/src/import.cpp b/src/import.cpp
@@ -231,25 +231,8 @@ void Import::processQueue()
bool Import::import(const ImportData &data)
{
- if(!data.remote.isEnabled()) {
- if(Transaction *tx = m_reapack->setupTransaction()) {
- m_reapack->enable(data.remote);
- tx->synchronize(data.remote);
- return true;
- }
- else
- return false;
- }
-
- Config *config = m_reapack->config();
- config->remotes.add(data.remote);
-
- if(config->install.autoInstall) {
- if(Transaction *tx = m_reapack->setupTransaction()) {
- tx->synchronize(data.remote);
- return true;
- }
- }
+ if(!m_reapack->addSetRemote(data.remote))
+ return false;
FS::write(Index::pathFor(data.remote.name()), data.contents);
diff --git a/src/manager.cpp b/src/manager.cpp
@@ -690,7 +690,7 @@ bool Manager::apply()
continue;
if(mods.enable) {
- m_reapack->setRemoteEnabled(*mods.enable, remote);
+ m_reapack->setRemoteEnabled(remote, *mods.enable);
if(*mods.enable)
syncList.insert(remote);
diff --git a/src/reapack.cpp b/src/reapack.cpp
@@ -165,7 +165,34 @@ void ReaPack::synchronizeAll()
tx->runTasks();
}
-void ReaPack::setRemoteEnabled(const bool enable, const Remote &remote)
+bool ReaPack::addSetRemote(const Remote &remote, const bool enable)
+{
+ if(remote.isEnabled() != enable) {
+ if(Transaction *tx = setupTransaction()) {
+ setRemoteEnabled(remote, enable); // adds the new remote to the list
+
+ if(enable)
+ tx->synchronize(remote);
+
+ return true;
+ }
+ else
+ return false;
+ }
+
+ m_config->remotes.add(remote);
+
+ if(m_config->install.autoInstall) {
+ if(Transaction *tx = setupTransaction()) {
+ tx->synchronize(remote);
+ return true;
+ }
+ }
+
+ return true;
+}
+
+void ReaPack::setRemoteEnabled(const Remote &remote, const bool enable)
{
assert(m_tx);
diff --git a/src/reapack.hpp b/src/reapack.hpp
@@ -62,8 +62,8 @@ public:
void setupAPI(const APIFunc *func);
void synchronizeAll();
- void setRemoteEnabled(bool enable, const Remote &);
- void enable(const Remote &r) { setRemoteEnabled(true, r); }
+ bool addSetRemote(const Remote &, bool enable = true);
+ void setRemoteEnabled(const Remote &, bool enable = true);
void uninstall(const Remote &);
void importRemote();