2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-12-08 14:30:47 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2009-12-08 14:30:47 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-12-08 14:30:47 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
2014-10-01 13:21:18 +02:00
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2009-12-08 14:30:47 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-12-08 14:30:47 +01:00
|
|
|
|
|
|
|
|
#include "vcsplugin.h"
|
2014-02-24 12:36:47 +01:00
|
|
|
|
|
|
|
|
#include "vcsbaseconstants.h"
|
|
|
|
|
|
2010-04-12 16:34:21 +02:00
|
|
|
#include "commonsettingspage.h"
|
2009-12-08 14:30:47 +01:00
|
|
|
#include "nicknamedialog.h"
|
|
|
|
|
#include "vcsbaseoutputwindow.h"
|
|
|
|
|
#include "corelistener.h"
|
|
|
|
|
|
2014-02-24 12:36:47 +01:00
|
|
|
#include <coreplugin/iversioncontrol.h>
|
2009-12-08 14:30:47 +01:00
|
|
|
#include <coreplugin/mimedatabase.h>
|
2014-02-24 12:36:47 +01:00
|
|
|
#include <coreplugin/variablemanager.h>
|
|
|
|
|
#include <coreplugin/vcsmanager.h>
|
|
|
|
|
#include <projectexplorer/project.h>
|
|
|
|
|
#include <projectexplorer/projectexplorer.h>
|
2009-12-08 14:30:47 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QtPlugin>
|
|
|
|
|
#include <QDebug>
|
2009-12-08 14:30:47 +01:00
|
|
|
|
2014-06-23 16:57:56 +02:00
|
|
|
using namespace Core;
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
namespace VcsBase {
|
2009-12-08 14:30:47 +01:00
|
|
|
namespace Internal {
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsPlugin *VcsPlugin::m_instance = 0;
|
2009-12-08 14:30:47 +01:00
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsPlugin::VcsPlugin() :
|
2009-12-08 14:30:47 +01:00
|
|
|
m_settingsPage(0),
|
|
|
|
|
m_nickNameModel(0),
|
|
|
|
|
m_coreListener(0)
|
|
|
|
|
{
|
|
|
|
|
m_instance = this;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsPlugin::~VcsPlugin()
|
2009-12-08 14:30:47 +01:00
|
|
|
{
|
|
|
|
|
m_instance = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
bool VcsPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
2009-12-08 14:30:47 +01:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(arguments)
|
|
|
|
|
|
2013-08-30 16:38:57 +02:00
|
|
|
if (!Core::MimeDatabase::addMimeTypes(QLatin1String(":/vcsbase/VcsBase.mimetypes.xml"), errorMessage))
|
2009-12-08 14:30:47 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
m_coreListener = new CoreListener;
|
|
|
|
|
addAutoReleasedObject(m_coreListener);
|
|
|
|
|
|
2010-04-12 16:34:21 +02:00
|
|
|
m_settingsPage = new CommonOptionsPage;
|
2009-12-08 14:30:47 +01:00
|
|
|
addAutoReleasedObject(m_settingsPage);
|
2012-01-07 12:31:48 +01:00
|
|
|
addAutoReleasedObject(VcsBaseOutputWindow::instance());
|
|
|
|
|
connect(m_settingsPage, SIGNAL(settingsChanged(VcsBase::Internal::CommonVcsSettings)),
|
|
|
|
|
this, SIGNAL(settingsChanged(VcsBase::Internal::CommonVcsSettings)));
|
|
|
|
|
connect(m_settingsPage, SIGNAL(settingsChanged(VcsBase::Internal::CommonVcsSettings)),
|
2009-12-08 14:30:47 +01:00
|
|
|
this, SLOT(slotSettingsChanged()));
|
|
|
|
|
slotSettingsChanged();
|
2014-02-24 12:36:47 +01:00
|
|
|
|
2014-06-23 16:57:56 +02:00
|
|
|
VariableManager::registerVariable(Constants::VAR_VCS_NAME,
|
|
|
|
|
tr("Name of the version control system in use by the current project."),
|
|
|
|
|
[]() -> QString {
|
|
|
|
|
IVersionControl *vc = 0;
|
|
|
|
|
if (Project *project = ProjectExplorerPlugin::currentProject())
|
|
|
|
|
vc = VcsManager::findVersionControlForDirectory(project->projectDirectory().toString());
|
|
|
|
|
return vc ? vc->displayName() : QString();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
VariableManager::registerVariable(Constants::VAR_VCS_TOPIC,
|
|
|
|
|
tr("The current version control topic (branch or tag) identification of the current project."),
|
|
|
|
|
[]() -> QString {
|
|
|
|
|
IVersionControl *vc = 0;
|
|
|
|
|
QString topLevel;
|
|
|
|
|
if (Project *project = ProjectExplorerPlugin::currentProject())
|
|
|
|
|
vc = VcsManager::findVersionControlForDirectory(project->projectDirectory().toString(), &topLevel);
|
|
|
|
|
return vc ? vc->vcsTopic(topLevel) : QString();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
VariableManager::registerVariable(Constants::VAR_VCS_TOPLEVELPATH,
|
|
|
|
|
tr("The top level path to the repository the current project is in."),
|
|
|
|
|
[]() -> QString {
|
|
|
|
|
if (Project *project = ProjectExplorerPlugin::currentProject())
|
2014-07-02 22:52:53 +03:00
|
|
|
return VcsManager::findTopLevelForDirectory(project->projectDirectory().toString());
|
|
|
|
|
return QString();
|
2014-06-23 16:57:56 +02:00
|
|
|
});
|
2014-02-24 12:36:47 +01:00
|
|
|
|
2009-12-08 14:30:47 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
void VcsPlugin::extensionsInitialized()
|
2009-12-08 14:30:47 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsPlugin *VcsPlugin::instance()
|
2009-12-08 14:30:47 +01:00
|
|
|
{
|
|
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
CoreListener *VcsPlugin::coreListener() const
|
2009-12-08 14:30:47 +01:00
|
|
|
{
|
|
|
|
|
return m_coreListener;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
CommonVcsSettings VcsPlugin::settings() const
|
2009-12-08 14:30:47 +01:00
|
|
|
{
|
|
|
|
|
return m_settingsPage->settings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Delayed creation/update of the nick name model. */
|
2012-01-07 12:31:48 +01:00
|
|
|
QStandardItemModel *VcsPlugin::nickNameModel()
|
2009-12-08 14:30:47 +01:00
|
|
|
{
|
|
|
|
|
if (!m_nickNameModel) {
|
|
|
|
|
m_nickNameModel = NickNameDialog::createModel(this);
|
|
|
|
|
populateNickNameModel();
|
|
|
|
|
}
|
|
|
|
|
return m_nickNameModel;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
void VcsPlugin::populateNickNameModel()
|
2009-12-08 14:30:47 +01:00
|
|
|
{
|
|
|
|
|
QString errorMessage;
|
|
|
|
|
if (!NickNameDialog::populateModelFromMailCapFile(settings().nickNameMailMap,
|
|
|
|
|
m_nickNameModel,
|
|
|
|
|
&errorMessage)) {
|
2010-04-12 16:34:21 +02:00
|
|
|
qWarning("%s", qPrintable(errorMessage));
|
|
|
|
|
}
|
2009-12-08 14:30:47 +01:00
|
|
|
}
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
void VcsPlugin::slotSettingsChanged()
|
2009-12-08 14:30:47 +01:00
|
|
|
{
|
|
|
|
|
if (m_nickNameModel)
|
|
|
|
|
populateNickNameModel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
2012-01-07 12:31:48 +01:00
|
|
|
} // namespace VcsBase
|
2009-12-08 14:30:47 +01:00
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
Q_EXPORT_PLUGIN(VcsBase::Internal::VcsPlugin)
|