Commit f919f02f authored by Evgeniy Ivanov's avatar Evgeniy Ivanov
Browse files

Added gitplugin with basic functionality. It can be used to create git-based...

Added gitplugin with basic functionality. It can be used to create git-based projects ('git init' and 'git add' would be used) and it can d
o 'git add/commit/remove' inside Projects View. Aslo there are some little tests and another code whish is not used now. Somewhere the code needs cleanup, but it's ok.
parents
add_subdirectory(tests)
include_directories( ${KDE4_INCLUDES}
${CMAKE_SOURCE_DIR}/util
${CMAKE_SOURCE_DIR}/interfaces
${CMAKE_SOURCE_DIR}/project
${CMAKE_SOURCE_DIR}/vcs
${CMAKE_SOURCE_DIR}/vcs/interfaces
${CMAKE_SOURCE_DIR}/vcs/models
)
########### next target ###############
set(kdevgit_PART_SRCS
gitplugin.cpp
gitjob.cpp
gitproxy.cpp
commitdialog.cpp
gitmainview.cpp
gitgenericoutputview.cpp
importdialog.cpp
importmetadatawidget.cpp
)
set(kdevgit_PART_UI
commitdialog.ui
cvsgenericoutputview.ui
cvsmainview.ui
importmetadatawidget.ui
)
kde4_add_ui_files(kdevgit_PART_SRCS ${kdevgit_PART_UI})
kde4_add_plugin(kdevgit ${kdevgit_PART_SRCS})
target_link_libraries(kdevgit
${KDE4_KDECORE_LIBS}
kdevplatformutil
kdevplatforminterfaces
kdevplatformvcs
kdevplatformproject
)
install(TARGETS kdevgit DESTINATION ${PLUGIN_INSTALL_DIR} )
########### install files ###############
install( FILES kdevgit.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
install( FILES kdevgit.rc DESTINATION ${DATA_INSTALL_DIR}/kdevgit )
/***************************************************************************
* Copyright 2007 Robert Gruber <rgruber@users.sourceforge.net> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "commitdialog.h"
CommitDialog::CommitDialog(QDialog *parent)
: QDialog(parent), Ui::CommitDialogBase()
{
Ui::CommitDialogBase::setupUi(this);
}
CommitDialog::~CommitDialog()
{
}
#include "commitdialog.moc"
/***************************************************************************
* Copyright 2007 Robert Gruber <rgruber@users.sourceforge.net> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License or (at your option) version 3 or any later version *
* accepted by the membership of KDE e.V. (or its successor approved *
* by the membership of KDE e.V.), which shall act as a proxy *
* defined in Section 14 of version 3 of the license. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef COMMITDIALOG_H
#define COMMITDIALOG_H
#include <QDialog>
#include <KTextEdit>
#include "ui_commitdialog.h"
/**
* Allows to enter text which can them be used as
* parameter for @code cvs commit @endcode
* @author Robert Gruber <rgruber@users.sourceforge.net>
*/
class CommitDialog : public QDialog, private Ui::CommitDialogBase
{
Q_OBJECT
public:
CommitDialog(QDialog *parent = 0);
virtual ~CommitDialog();
/**
* @return The text entered by the user
*/
QString message() { return textedit->toPlainText(); }
};
#endif
<ui version="4.0" >
<class>CommitDialogBase</class>
<widget class="QDialog" name="CommitDialogBase" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>387</width>
<height>269</height>
</rect>
</property>
<property name="windowTitle" >
<string>Commit to Repository</string>
</property>
<layout class="QVBoxLayout" >
<item>
<widget class="QGroupBox" name="groupBox" >
<property name="title" >
<string>Message</string>
</property>
<layout class="QGridLayout" >
<item row="0" column="0" >
<widget class="KTextEdit" name="textedit" />
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons" >
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KTextEdit</class>
<extends>QTextEdit</extends>
<header>ktextedit.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>CommitDialogBase</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel" >
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel" >
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>CommitDialogBase</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel" >
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel" >
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
<ui version="4.0" >
<class>CvsGenericOutputViewBase</class>
<widget class="QWidget" name="CvsGenericOutputViewBase" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>112</height>
</rect>
</property>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>0</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<item>
<widget class="QTextEdit" name="textArea" >
<property name="frameShape" >
<enum>QFrame::NoFrame</enum>
</property>
<property name="lineWrapMode" >
<enum>QTextEdit::NoWrap</enum>
</property>
<property name="readOnly" >
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
<ui version="4.0" >
<class>CvsMainViewBase</class>
<widget class="QWidget" name="CvsMainViewBase" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<layout class="QGridLayout" >
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<item row="0" column="0" >
<widget class="KTabWidget" name="tabwidget" />
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KTabWidget</class>
<extends>QTabWidget</extends>
<header>ktabwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
/***************************************************************************
* Copyright 2007 Robert Gruber <rgruber@users.sourceforge.net> *
* *
* Adapted for Git *
* Copyright 2008 Evgeniy Ivanov <powerfox@kde.ru> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License or (at your option) version 3 or any later version *
* accepted by the membership of KDE e.V. (or its successor approved *
* by the membership of KDE e.V.), which shall act as a proxy *
* defined in Section 14 of version 3 of the license. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "gitgenericoutputview.h"
#include "gitjob.h"
GitGenericOutputView::GitGenericOutputView(GitPlugin *plugin, GitJob* job, QWidget* parent)
: QWidget(parent), Ui::CvsGenericOutputViewBase(), m_plugin(plugin)
{
Ui::CvsGenericOutputViewBase::setupUi(this);
if (job) {
connect(job, SIGNAL( result(KJob*) ),
this, SLOT( slotJobFinished(KJob*) ));
}
}
GitGenericOutputView::~GitGenericOutputView()
{
}
void GitGenericOutputView::appendText(const QString& text)
{
textArea->append(text);
}
void GitGenericOutputView::slotJobFinished(KJob * job)
{
GitJob * gitjob = dynamic_cast<GitJob*>(job);
if (gitjob) {
appendText( gitjob->gitCommand() );
appendText( gitjob->output() );
if (job->error() == 0) {
appendText( i18n("Job exited normally") );
} else {
appendText( job->errorText() );
}
}
}
// #include "cvsgenericoutputview.moc"
/***************************************************************************
* Copyright 2007 Robert Gruber <rgruber@users.sourceforge.net> *
* *
* Adapted for Git *
* Copyright 2008 Evgeniy Ivanov <powerfox@kde.ru> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License or (at your option) version 3 or any later version *
* accepted by the membership of KDE e.V. (or its successor approved *
* by the membership of KDE e.V.), which shall act as a proxy *
* defined in Section 14 of version 3 of the license. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef GITGENERICOUTPUTVIEW_H
#define GITGENERICOUTPUTVIEW_H
#include <QWidget>
#include <KJob>
#include "ui_cvsgenericoutputview.h"
class GitPlugin;
class GitJob;
/**
* Shows plain text.
*
* Text can either be added directly by calling appendText().
*
* Or by connecting a job's result() signal to slotJobFinished().
*
* @author Robert Gruber <rgruber@users.sourceforge.net>
*/
class GitGenericOutputView : public QWidget, private Ui::CvsGenericOutputViewBase {
Q_OBJECT
public:
explicit GitGenericOutputView(GitPlugin *plugin, GitJob* job=0, QWidget* parent=0);
virtual ~GitGenericOutputView();
public slots:
void appendText(const QString& text);
void slotJobFinished(KJob* job);
private:
GitPlugin* m_plugin;
};
#endif
/***************************************************************************
* This file was partly taken from KDevelop's cvs plugin *
* Copyright 2002-2003 Christian Loose <christian.loose@hamburg.de> *
* Copyright 2007 Robert Gruber <rgruber@users.sourceforge.net> *
* *
* Adapted for Git *
* Copyright 2008 Evgeniy Ivanov <powerfox@kde.ru> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License or (at your option) version 3 or any later version *
* accepted by the membership of KDE e.V. (or its successor approved *
* by the membership of KDE e.V.), which shall act as a proxy *
* defined in Section 14 of version 3 of the license. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "gitjob.h"
#include <QFile>
#include <QList>
#include <QStringList>
#include <KDebug>
#include <KLocale>
#include "processlinemaker.h"
#include <iplugin.h>
struct GitJob::Private
{
Private() : isRunning(false), commMode(KProcess::SeparateChannels), vcsplugin(0)
{
childproc = new KProcess;
lineMaker = new KDevelop::ProcessLineMaker( childproc );
}
~Private() {
if (lineMaker) delete lineMaker;
if (childproc) delete childproc;
}
KDevelop::ProcessLineMaker* lineMaker;
KProcess* childproc;
QStringList command;
QString server;
QString directory;
bool isRunning;
QStringList outputLines;
KProcess::OutputChannelMode commMode;
KDevelop::IPlugin* vcsplugin;
};
GitJob::GitJob(KDevelop::IPlugin* parent)
: VcsJob(parent), d(new Private)
{
d->vcsplugin = parent;
}
GitJob::~GitJob()
{
delete d;
}
void GitJob::clear()
{
d->childproc->clearEnvironment();
d->command.clear();
d->outputLines.clear();
}
void GitJob::setServer(const QString& server)
{
d->server = server;
}
void GitJob::setDirectory(const QString& directory)
{
d->directory = directory;
}
QString GitJob::getDirectory()
{
return d->directory;
}
bool GitJob::isRunning() const
{
return d->isRunning;
}
GitJob& GitJob::operator<<(const QString& arg)
{
d->command.append( arg );
return *this;
}
GitJob& GitJob::operator<<(const char* arg)
{
d->command.append( arg );
return *this;
}
GitJob& GitJob::operator<<(const QStringList& args)
{
d->command.append( args.join(" ") );
return *this;
}
QString GitJob::gitCommand() const
{
return d->command.join(" ");
}
QString GitJob::output() const
{
return d->outputLines.join("\n");
}
void GitJob::start()
{
if( !d->directory.isEmpty() ) {
kDebug(9500) << "Working directory:" << d->directory;
d->childproc->setWorkingDirectory(d->directory);
}
connect(d->childproc, SIGNAL(finished(int, QProcess::ExitStatus)),
SLOT(slotProcessExited(int, QProcess::ExitStatus)));
connect(d->lineMaker, SIGNAL(receivedStdoutLines(const QStringList&)),
SLOT(slotReceivedStdout(const QStringList&)));
connect(d->lineMaker, SIGNAL(receivedStderrLines(const QStringList&)),
SLOT(slotReceivedStderr(const QStringList&)) );
kDebug(9500) << "Execute git command:" << gitCommand();
d->outputLines.clear();
d->isRunning = true;
d->childproc->setOutputChannelMode( d->commMode );
d->childproc->setProgram( d->command );
d->childproc->start();
}
void GitJob::setCommunicationMode(KProcess::OutputChannelMode comm)
{
d->commMode = comm;
}
void GitJob::cancel()
{
d->childproc->kill();
}
void GitJob::slotProcessExited(int exitCode, QProcess::ExitStatus exitStatus)
{
// disconnect all connections to childproc's signals; they are no longer needed
d->childproc->disconnect();
d->isRunning = false;
if (exitStatus != QProcess::NormalExit || exitCode != 0) {
setError( exitCode );
setErrorText( i18n("Process exited with status %1", exitCode) );
}
emitResult(); //KJob
emit resultsReady(this); //VcsJob
}
void GitJob::slotReceivedStdout(const QStringList& output)
{
// accumulate output
d->outputLines += output;
kDebug(9500)<<"received output:";
kDebug(9500)<<output.join("\n");
}
void GitJob::slotReceivedStderr(const QStringList& output)
{
// accumulate output
d->outputLines += output;
kDebug(9500)<<"received error:";
kDebug(9500)<<output.join("\n");
}
QVariant GitJob::fetchResults()
{
return output();
}
KDevelop::VcsJob::JobStatus GitJob::status() const
{
if (d->isRunning)
return KDevelop::VcsJob::JobRunning;
if (d->childproc->exitCode() != 0)
return KDevelop::VcsJob::JobFailed;
return KDevelop::VcsJob::JobSucceeded;
}
KDevelop::IPlugin* GitJob::vcsPlugin() const
{
return d->vcsplugin;
}