Initial work on multiple remotes
FossilOrigin-Name: 9674708cb5f2e8543e01d64211b6768d2cb726d6
This commit is contained in:
@@ -285,6 +285,7 @@ MainWindow::MainWindow(Settings &_settings, QWidget *parent, QString *workspaceP
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
stopUI();
|
||||
getWorkspace().storeWorkspace(*settings.GetStore());
|
||||
updateSettings();
|
||||
|
||||
delete ui;
|
||||
@@ -299,24 +300,14 @@ const QString &MainWindow::getCurrentWorkspace()
|
||||
//-----------------------------------------------------------------------------
|
||||
void MainWindow::setCurrentWorkspace(const QString &workspace)
|
||||
{
|
||||
if(workspace.isEmpty())
|
||||
{
|
||||
fossil().setCurrentWorkspace("");
|
||||
return;
|
||||
}
|
||||
|
||||
QString new_workspace = QFileInfo(workspace).absoluteFilePath();
|
||||
|
||||
fossil().setCurrentWorkspace(new_workspace);
|
||||
|
||||
addWorkspace(new_workspace);
|
||||
|
||||
if(!QDir::setCurrent(new_workspace))
|
||||
QMessageBox::critical(this, tr("Error"), tr("Could not change current directory to '%0'").arg(new_workspace), QMessageBox::Ok );
|
||||
if(!getWorkspace().switchWorkspace(workspace, *settings.GetStore()))
|
||||
QMessageBox::critical(this, tr("Error"), tr("Could not change current directory to '%0'").arg(workspace), QMessageBox::Ok );
|
||||
else
|
||||
addWorkspaceHistory(fossil().getCurrentWorkspace());
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void MainWindow::addWorkspace(const QString &dir)
|
||||
void MainWindow::addWorkspaceHistory(const QString &dir)
|
||||
{
|
||||
if(dir.isEmpty())
|
||||
return;
|
||||
@@ -794,7 +785,6 @@ void MainWindow::updateWorkspaceView()
|
||||
tags->appendRow(tag);
|
||||
}
|
||||
|
||||
// FIXME: Unique Icon name
|
||||
// Stashes
|
||||
QStandardItem *stashes = new QStandardItem(getInternalIcon(":icons/icon-action-repo-open"), tr("Stashes"));
|
||||
stashes->setData(WorkspaceItem(WorkspaceItem::TYPE_STASHES, ""), ROLE_WORKSPACE_ITEM);
|
||||
@@ -812,15 +802,20 @@ void MainWindow::updateWorkspaceView()
|
||||
remotes->setData(WorkspaceItem(WorkspaceItem::TYPE_REMOTES, ""), ROLE_WORKSPACE_ITEM);
|
||||
remotes->setEditable(false);
|
||||
getWorkspace().getTreeModel().appendRow(remotes);
|
||||
for(remote_map_t::const_iterator it=getWorkspace().getRemotes().begin(); it!=getWorkspace().getRemotes().end(); ++it)
|
||||
{
|
||||
QUrl default_url = fossil().getDefaultRemoteUrl();
|
||||
if(!default_url.isEmpty())
|
||||
QStandardItem *remote_item = new QStandardItem(getInternalIcon(":icons/icon-item-remote"), it->name);
|
||||
remote_item->setData(WorkspaceItem(WorkspaceItem::TYPE_REMOTE, it->url.toString()), ROLE_WORKSPACE_ITEM);
|
||||
remote_item->setToolTip(it->url.toDisplayString());
|
||||
|
||||
// Mark the default url as bold
|
||||
if(it->isDefault)
|
||||
{
|
||||
QUrl url = default_url;
|
||||
QStandardItem *remote_item = new QStandardItem(getInternalIcon(":icons/icon-item-remote"), url.toDisplayString());
|
||||
remote_item->setData(WorkspaceItem(WorkspaceItem::TYPE_REMOTE, default_url.toString()), ROLE_WORKSPACE_ITEM);
|
||||
remotes->appendRow(remote_item);
|
||||
QFont font = remote_item->font();
|
||||
font.setBold(true);
|
||||
remote_item->setFont(font);
|
||||
}
|
||||
remotes->appendRow(remote_item);
|
||||
}
|
||||
|
||||
// Expand previously selected nodes
|
||||
@@ -974,7 +969,7 @@ void MainWindow::applySettings()
|
||||
if(wk.isEmpty() || !QDir(wk).exists())
|
||||
continue;
|
||||
|
||||
addWorkspace(wk);
|
||||
addWorkspaceHistory(wk);
|
||||
|
||||
if(store->contains("Active") && store->value("Active").toBool())
|
||||
setCurrentWorkspace(wk);
|
||||
@@ -2463,20 +2458,41 @@ void MainWindow::on_actionEditRemote_triggered()
|
||||
if(remotes.empty())
|
||||
return;
|
||||
|
||||
QUrl url(remotes.first());
|
||||
bool exists = KeychainGet(this, url);
|
||||
QUrl old_url(remotes.first());
|
||||
|
||||
if(!RemoteDialog::run(this, url))
|
||||
QString name;
|
||||
Remote *remote = getWorkspace().findRemote(old_url);
|
||||
if(remote)
|
||||
name = remote->name;
|
||||
|
||||
bool exists = KeychainGet(this, old_url);
|
||||
|
||||
QUrl new_url = old_url;
|
||||
if(!RemoteDialog::run(this, new_url, name))
|
||||
return;
|
||||
|
||||
if(!url.isLocalFile())
|
||||
if(!new_url.isLocalFile())
|
||||
{
|
||||
if(exists)
|
||||
KeychainDelete(this, url);
|
||||
KeychainDelete(this, new_url);
|
||||
|
||||
if(!KeychainSet(this, url))
|
||||
if(!KeychainSet(this, new_url))
|
||||
QMessageBox::critical(this, tr("Error"), tr("Could not store information to keychain."), QMessageBox::Ok );
|
||||
}
|
||||
|
||||
// Remove password
|
||||
new_url.setPassword("");
|
||||
old_url.setPassword("");
|
||||
// Url changed?
|
||||
if(new_url != old_url)
|
||||
{
|
||||
getWorkspace().removeRemote(old_url);
|
||||
getWorkspace().addRemote(new_url, name);
|
||||
}
|
||||
else // Just data changed
|
||||
remote->name = name;
|
||||
|
||||
updateWorkspaceView();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -2516,7 +2532,7 @@ void MainWindow::on_actionPullRemote_triggered()
|
||||
//------------------------------------------------------------------------------
|
||||
void MainWindow::on_actionPush_triggered()
|
||||
{
|
||||
QUrl url = fossil().getDefaultRemoteUrl();
|
||||
QUrl url = getWorkspace().getRemoteDefault();
|
||||
|
||||
if(url.isEmpty())
|
||||
{
|
||||
@@ -2528,14 +2544,13 @@ void MainWindow::on_actionPush_triggered()
|
||||
if(!url.isLocalFile())
|
||||
KeychainGet(this, url);
|
||||
|
||||
|
||||
fossil().pushRepository(url);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void MainWindow::on_actionPull_triggered()
|
||||
{
|
||||
QUrl url = fossil().getDefaultRemoteUrl();
|
||||
QUrl url = getWorkspace().getRemoteDefault();
|
||||
|
||||
if(url.isEmpty())
|
||||
{
|
||||
@@ -2560,11 +2575,7 @@ void MainWindow::on_actionSetDefaultRemote_triggered()
|
||||
|
||||
QUrl url(remotes.first());
|
||||
|
||||
// Retrieve password from keychain
|
||||
if(!url.isLocalFile())
|
||||
KeychainGet(this, url);
|
||||
|
||||
fossil().setRemoteUrl(url);
|
||||
getWorkspace().setRemoteDefault(url);
|
||||
updateWorkspaceView();
|
||||
}
|
||||
|
||||
@@ -2572,7 +2583,8 @@ void MainWindow::on_actionSetDefaultRemote_triggered()
|
||||
void MainWindow::on_actionAddRemote_triggered()
|
||||
{
|
||||
QUrl url;
|
||||
if(!RemoteDialog::run(this, url))
|
||||
QString name;
|
||||
if(!RemoteDialog::run(this, url, name))
|
||||
return;
|
||||
|
||||
if(!url.isLocalFile())
|
||||
@@ -2583,6 +2595,7 @@ void MainWindow::on_actionAddRemote_triggered()
|
||||
QMessageBox::critical(this, tr("Error"), tr("Could not store information to keychain."), QMessageBox::Ok );
|
||||
}
|
||||
|
||||
fossil().setRemoteUrl(url);
|
||||
getWorkspace().addRemote(url, name);
|
||||
updateWorkspaceView();
|
||||
}
|
||||
|
||||
|
@@ -45,7 +45,7 @@ private:
|
||||
bool startUI();
|
||||
void stopUI();
|
||||
void enableActions(bool on);
|
||||
void addWorkspace(const QString &dir);
|
||||
void addWorkspaceHistory(const QString &dir);
|
||||
void rebuildRecent();
|
||||
bool openWorkspace(const QString &path);
|
||||
void loadFossilSettings();
|
||||
|
@@ -22,7 +22,7 @@ RemoteDialog::~RemoteDialog()
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool RemoteDialog::run(QWidget *parent, QUrl &url)
|
||||
bool RemoteDialog::run(QWidget *parent, QUrl &url, QString &name)
|
||||
{
|
||||
RemoteDialog dlg(parent);
|
||||
|
||||
@@ -33,6 +33,7 @@ bool RemoteDialog::run(QWidget *parent, QUrl &url)
|
||||
dlg.ui->lineURL->setText(url_no_credentials);
|
||||
dlg.ui->lineUserName->setText(url.userName());
|
||||
dlg.ui->linePassword->setText(url.password());
|
||||
dlg.ui->lineName->setText(name);
|
||||
}
|
||||
|
||||
if(dlg.exec() != QDialog::Accepted)
|
||||
@@ -53,6 +54,10 @@ bool RemoteDialog::run(QWidget *parent, QUrl &url)
|
||||
if(!dlg.ui->linePassword->text().trimmed().isEmpty())
|
||||
url.setPassword(dlg.ui->linePassword->text());
|
||||
|
||||
name =dlg.ui->lineName->text().trimmed();
|
||||
if(name.isEmpty())
|
||||
name = url.toString(QUrl::PrettyDecoded|QUrl::RemoveUserInfo);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -15,7 +15,7 @@ public:
|
||||
explicit RemoteDialog(QWidget *parent = 0);
|
||||
~RemoteDialog();
|
||||
|
||||
static bool run(QWidget *parent, class QUrl &url);
|
||||
static bool run(QWidget *parent, class QUrl &url, QString &name);
|
||||
|
||||
private slots:
|
||||
void on_btnSelectSourceRepo_clicked();
|
||||
|
@@ -34,8 +34,7 @@ struct Settings
|
||||
enum SettingType
|
||||
{
|
||||
TYPE_FOSSIL_GLOBAL,
|
||||
TYPE_FOSSIL_LOCAL,
|
||||
TYPE_FOSSIL_COMMAND
|
||||
TYPE_FOSSIL_LOCAL
|
||||
};
|
||||
|
||||
Setting(QVariant value, SettingType type) : Value(value), Type(type)
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -6,6 +6,7 @@
|
||||
#include <QDir>
|
||||
#include <QSet>
|
||||
#include <QMap>
|
||||
#include <QSettings>
|
||||
#include "Utils.h"
|
||||
#include "Fossil.h"
|
||||
|
||||
@@ -99,13 +100,31 @@ private:
|
||||
|
||||
typedef QSet<QString> stringset_t;
|
||||
|
||||
class Remote
|
||||
{
|
||||
public:
|
||||
Remote(const QString &_name, const QUrl &_url, bool _isDefault=false)
|
||||
: name(_name), url(_url), isDefault(_isDefault)
|
||||
{
|
||||
}
|
||||
|
||||
QString name;
|
||||
QUrl url;
|
||||
bool isDefault;
|
||||
|
||||
};
|
||||
|
||||
typedef QMap<QUrl, Remote> remote_map_t;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Workspace
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Workspace
|
||||
{
|
||||
public:
|
||||
Workspace();
|
||||
|
||||
~Workspace();
|
||||
|
||||
typedef QList<WorkspaceFile*> filelist_t;
|
||||
@@ -116,7 +135,7 @@ public:
|
||||
Fossil & fossil() { return bridge; }
|
||||
const Fossil & fossil() const { return bridge; }
|
||||
|
||||
static bool scanDirectory(QFileInfoList &entries, const QString& dirPath, const QString &baseDir, const QString ignoreSpec, const bool& abort, UICallback &uiCallback);
|
||||
bool switchWorkspace(const QString &workspace, QSettings &store);
|
||||
void scanWorkspace(bool scanLocal, bool scanIgnored, bool scanModified, bool scanUnchanged, const QString &ignoreGlob, UICallback &uiCallback, bool &operationAborted);
|
||||
|
||||
QStandardItemModel &getFileModel() { return repoFileModel; }
|
||||
@@ -129,6 +148,19 @@ public:
|
||||
QStringList &getBranches() { return branchList; }
|
||||
bool otherChanges() const { return isIntegrated; }
|
||||
|
||||
// Remotes
|
||||
const remote_map_t &getRemotes() const { return remotes; }
|
||||
bool addRemote(const QUrl &url, const QString &name);
|
||||
bool removeRemote(const QUrl &url);
|
||||
bool setRemoteDefault(const QUrl& url);
|
||||
const QUrl &getRemoteDefault() const;
|
||||
Remote * findRemote(const QUrl& url);
|
||||
|
||||
|
||||
void storeWorkspace(QSettings &store);
|
||||
private:
|
||||
static bool scanDirectory(QFileInfoList &entries, const QString& dirPath, const QString &baseDir, const QString ignoreSpec, const bool& abort, UICallback &uiCallback);
|
||||
|
||||
private:
|
||||
Fossil bridge;
|
||||
filemap_t workspaceFiles;
|
||||
@@ -136,6 +168,7 @@ private:
|
||||
stashmap_t stashMap;
|
||||
QStringList branchList;
|
||||
QStringMap tags;
|
||||
remote_map_t remotes;
|
||||
bool isIntegrated;
|
||||
|
||||
QStandardItemModel repoFileModel;
|
||||
|
Reference in New Issue
Block a user