Initial work on multiple remotes
FossilOrigin-Name: 9674708cb5f2e8543e01d64211b6768d2cb726d6
This commit is contained in:
@@ -2,10 +2,15 @@
|
||||
#include <QCoreApplication>
|
||||
#include "Utils.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
Workspace::Workspace()
|
||||
{
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
Workspace::~Workspace()
|
||||
{
|
||||
clearState();
|
||||
remotes.clear();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -23,6 +28,80 @@ void Workspace::clearState()
|
||||
isIntegrated = false;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void Workspace::storeWorkspace(QSettings &store)
|
||||
{
|
||||
QString workspace = fossil().getCurrentWorkspace();
|
||||
if(workspace.isEmpty())
|
||||
return;
|
||||
|
||||
store.beginGroup("Remotes");
|
||||
store.beginWriteArray(QDir::toNativeSeparators(workspace));
|
||||
int index = 0;
|
||||
for(remote_map_t::iterator it=remotes.begin(); it!=remotes.end(); ++it, ++index)
|
||||
{
|
||||
store.setArrayIndex(index);
|
||||
store.setValue("Name", it->name);
|
||||
QUrl url = it->url;
|
||||
url.setPassword("");
|
||||
store.setValue("Url", url);
|
||||
if(it->isDefault)
|
||||
store.setValue("Default", it->isDefault);
|
||||
else
|
||||
store.remove("Default");
|
||||
}
|
||||
store.endArray();
|
||||
store.endGroup();
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool Workspace::switchWorkspace(const QString& workspace, QSettings &store)
|
||||
{
|
||||
// Save Remotes
|
||||
storeWorkspace(store);
|
||||
clearState();
|
||||
remotes.clear();
|
||||
|
||||
fossil().setCurrentWorkspace("");
|
||||
if(workspace.isEmpty())
|
||||
return true;
|
||||
|
||||
QString new_workspace = QFileInfo(workspace).absoluteFilePath();
|
||||
|
||||
if(!QDir::setCurrent(new_workspace))
|
||||
return false;
|
||||
|
||||
fossil().setCurrentWorkspace(new_workspace);
|
||||
|
||||
// Load Remotes
|
||||
store.beginGroup("Remotes");
|
||||
int num_remotes = store.beginReadArray(QDir::toNativeSeparators(new_workspace));
|
||||
for(int i=0; i<num_remotes; ++i)
|
||||
{
|
||||
store.setArrayIndex(i);
|
||||
|
||||
QString name = store.value("name").toString();
|
||||
QUrl url = store.value("Url").toUrl();
|
||||
bool def = store.value("Default", false).toBool();
|
||||
addRemote(url, name);
|
||||
if(def)
|
||||
setRemoteDefault(url);
|
||||
}
|
||||
store.endArray();
|
||||
store.endGroup();
|
||||
|
||||
// Add the default url from fossil
|
||||
QUrl default_remote;
|
||||
if(fossil().getRemoteUrl(default_remote) && default_remote.isValid() && !default_remote.isEmpty())
|
||||
{
|
||||
addRemote(default_remote, default_remote.toDisplayString());
|
||||
setRemoteDefault(default_remote);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool Workspace::scanDirectory(QFileInfoList &entries, const QString& dirPath, const QString &baseDir, const QString ignoreSpec, const bool &abort, UICallback &uiCallback)
|
||||
{
|
||||
@@ -216,3 +295,56 @@ _done:
|
||||
uiCallback.endProcess();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool Workspace::addRemote(const QUrl& url, const QString& name)
|
||||
{
|
||||
if(remotes.contains(url))
|
||||
return false;
|
||||
|
||||
Q_ASSERT(url.password().isEmpty());
|
||||
|
||||
Remote r(name, url);
|
||||
remotes.insert(r.name, r);
|
||||
return true;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool Workspace::removeRemote(const QUrl& url)
|
||||
{
|
||||
return remotes.remove(url) > 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool Workspace::setRemoteDefault(const QUrl& url)
|
||||
{
|
||||
Q_ASSERT(url.password().isEmpty());
|
||||
|
||||
bool found = false;
|
||||
for(remote_map_t::iterator it=remotes.begin(); it!=remotes.end(); ++it)
|
||||
{
|
||||
if(it->url == url)
|
||||
{
|
||||
it->isDefault = true;
|
||||
found = true;
|
||||
}
|
||||
else
|
||||
it->isDefault = false;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
const QUrl & Workspace::getRemoteDefault() const
|
||||
{
|
||||
return fossil().getDefaultRemoteUrl();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Remote * Workspace::findRemote(const QUrl& url)
|
||||
{
|
||||
remote_map_t::iterator it = remotes.find(url);
|
||||
if(it!=remotes.end())
|
||||
return &(*it);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user