Skip to content

Commit

Permalink
Merge pull request #32 from francescmm/v1.0.0-rc
Browse files Browse the repository at this point in the history
Updating master to v1.0.0
  • Loading branch information
francescmm authored Dec 13, 2019
2 parents 609db29 + d20c3c6 commit e6104d7
Show file tree
Hide file tree
Showing 55 changed files with 995 additions and 2,140 deletions.
10 changes: 4 additions & 6 deletions GitQlient.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
CONFIG += qt warn_on c++17
QMAKE_CXXFLAGS += -Werror
TARGET = GitQlient
QT += widgets core gui
QT += widgets core
DEFINES += QT_DEPRECATED_WARNINGS
QMAKE_LFLAGS += -no-pie

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
Expand All @@ -14,13 +15,10 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
SOURCES += main.cpp

include(app/GitQlient.pri)
include($$PWD/qtsingleapplication/src/qtsingleapplication.pri)
include(QLogger/QLogger.pri)

INCLUDEPATH += QLogger \
app \
qtsingleapplication/src

include(QLogger/QLogger.pri)
app

OTHER_FILES += $$PWD/Tasks.txt \
$$PWD/LICENSE \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ GitQlient can be executed from command line with additional params. Please take

| Command | Desciption |
|---|---|
| -noLog | Disabled the log system for the current execution |
| -noLog | Disables the log system for the current execution |
| -repos | Provides a list separated with blank spaces for the different repositories that will be open at startup. <br> Ex: ```-repos /path/to/repo1 /path/to/repo2``` |

## Setup & Building the code
Expand Down
121 changes: 67 additions & 54 deletions app/CommitHistoryContextMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,61 +60,9 @@ void CommitHistoryContextMenu::createIndividualShaMenu()
const auto checkoutCommitAction = addAction("Checkout commit");
connect(checkoutCommitAction, &QAction::triggered, this, &CommitHistoryContextMenu::checkoutCommit);

QByteArray output;
auto ret = mGit->getBranchesOfCommit(sha);
const auto currentBranch = mGit->getCurrentBranchName();
addBranchActions(sha);

if (ret.success)
{
auto branches = ret.output.toString().split('\n');

for (auto &branch : branches)
{
if (branch.contains("*"))
branch.remove("*");

if (branch.contains("->"))
{
branch.clear();
continue;
}

branch.remove("remotes/");
branch = branch.trimmed();

if (!branch.isEmpty() && branch != currentBranch && branch != QString("origin/%1").arg(currentBranch))
{
const auto checkoutCommitAction = addAction(QString(tr("Checkout %1")).arg(branch));
checkoutCommitAction->setDisabled(true);
// connect(checkoutCommitAction, &QAction::triggered, this, &RepositoryView::executeAction);
}
}

for (auto branch : qAsConst(branches))
{
if (!branch.isEmpty() && branch != currentBranch && branch != QString("origin/%1").arg(currentBranch))
{
// If is the last commit of a branch
const auto mergeBranchAction = addAction(QString(tr("Merge %1")).arg(branch));
connect(mergeBranchAction, &QAction::triggered, this, [this, branch]() { merge(branch); });
}
}

addSeparator();

auto isCommitInCurrentBranch = false;

for (auto branch : qAsConst(branches))
isCommitInCurrentBranch |= branch == currentBranch;

if (!isCommitInCurrentBranch)
{
const auto cherryPickAction = addAction(tr("Cherry pick commit"));
connect(cherryPickAction, &QAction::triggered, this, &CommitHistoryContextMenu::cherryPickCommit);
}
}

ret = mGit->getLastCommitOfBranch(currentBranch);
const auto ret = mGit->getLastCommitOfBranch(mGit->getCurrentBranchName());

if (ret.success)
{
Expand Down Expand Up @@ -248,6 +196,14 @@ void CommitHistoryContextMenu::exportAsPatch()
}
}

void CommitHistoryContextMenu::checkoutBranch()
{
const auto branchName = qobject_cast<QAction *>(sender())->text();
mGit->checkoutRemoteBranch(branchName);

emit signalRepositoryUpdated();
}

void CommitHistoryContextMenu::checkoutCommit()
{
const auto sha = mShas.first();
Expand Down Expand Up @@ -362,3 +318,60 @@ void CommitHistoryContextMenu::merge(const QString &branchFrom)
else
QMessageBox::critical(parentWidget(), tr("Merge failed"), outputStr);
}

void CommitHistoryContextMenu::addBranchActions(const QString &sha)
{
auto isCommitInCurrentBranch = false;
const auto currentBranch = mGit->getCurrentBranchName();
const auto remoteBranches = mGit->getRefNames(sha, Git::RMT_BRANCH);
const auto localBranches = mGit->getRefNames(sha, Git::BRANCH);
auto branches = localBranches;

for (const auto &branch : remoteBranches)
{
auto localBranchEquivalent = branch;
if (!localBranches.contains(localBranchEquivalent.remove("origin/")))
branches.append(branch);
}

QList<QAction *> branchesToCheckout;

for (auto branch : qAsConst(branches))
{
isCommitInCurrentBranch |= branch == currentBranch;

if (!branch.isEmpty() && branch != currentBranch && branch != QString("origin/%1").arg(currentBranch))
{
const auto checkoutCommitAction = new QAction(QString(tr("%1")).arg(branch));
connect(checkoutCommitAction, &QAction::triggered, this, &CommitHistoryContextMenu::checkoutBranch);
branchesToCheckout.append(checkoutCommitAction);
}
}

if (!branchesToCheckout.isEmpty())
{
const auto branchMenu = addMenu("Checkout branch...");
branchMenu->addActions(branchesToCheckout);
}

if (!isCommitInCurrentBranch)
{
for (auto branch : qAsConst(branches))
{
if (!branch.isEmpty() && branch != currentBranch && branch != QString("origin/%1").arg(currentBranch))
{
// If is the last commit of a branch
const auto mergeBranchAction = addAction(QString(tr("Merge %1")).arg(branch));
connect(mergeBranchAction, &QAction::triggered, this, [this, branch]() { merge(branch); });
}
}
}

addSeparator();

if (!isCommitInCurrentBranch)
{
const auto cherryPickAction = addAction(tr("Cherry pick commit"));
connect(cherryPickAction, &QAction::triggered, this, &CommitHistoryContextMenu::cherryPickCommit);
}
}
2 changes: 2 additions & 0 deletions app/CommitHistoryContextMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class CommitHistoryContextMenu : public QMenu
void createBranch();
void createTag();
void exportAsPatch();
void checkoutBranch();
void checkoutCommit();
void cherryPickCommit();
void applyPatch();
Expand All @@ -62,4 +63,5 @@ class CommitHistoryContextMenu : public QMenu
void resetMixed();
void resetHard();
void merge(const QString &branchFrom);
void addBranchActions(const QString &sha);
};
2 changes: 1 addition & 1 deletion app/CommitHistoryModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ CommitHistoryModel::CommitHistoryModel(QSharedPointer<Git> git, QObject *p)
mColumns.insert(CommitHistoryColumns::AUTHOR, "Author");
mColumns.insert(CommitHistoryColumns::DATE, "Date");

connect(mGit.get(), &Git::signalNewRevisions, this, &CommitHistoryModel::onNewRevisions);
connect(mGit.get(), &Git::signalLoadingFinished, this, &CommitHistoryModel::onNewRevisions);
}

CommitHistoryModel::~CommitHistoryModel()
Expand Down
2 changes: 1 addition & 1 deletion app/CommitHistoryView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void CommitHistoryView::clear()

void CommitHistoryView::focusOnCommit(const QString &goToSha)
{
mCurrentSha = mGit->getRefSha(goToSha);
mCurrentSha = goToSha;

QLog_Info("UI", QString("Setting the focus on the commit {%1}").arg(mCurrentSha));

Expand Down
3 changes: 2 additions & 1 deletion app/CommitHistoryView.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class CommitHistoryView : public QTreeView
~CommitHistoryView() override;
QList<QString> getSelectedShaList() const;
void filterBySha(const QStringList &shaList);
bool hasActiveFiler() const { return mIsFiltering; }
void activateFilter(bool activate) { mIsFiltering = activate; }
bool hasActiveFilter() const { return mIsFiltering; }

void clear();
void focusOnCommit(const QString &goToSha);
Expand Down
2 changes: 1 addition & 1 deletion app/CommitInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ bool CommitInfo::operator==(const CommitInfo &commit) const
{
return mSha == commit.mSha && mParentsSha == commit.mParentsSha && mCommitter == commit.mCommitter
&& mAuthor == commit.mAuthor && mCommitDate == commit.mCommitDate && mShortLog == commit.mShortLog
&& mLongLog == commit.mLongLog && orderIdx == commit.orderIdx;
&& mLongLog == commit.mLongLog && orderIdx == commit.orderIdx && lanes == commit.lanes;
}

bool CommitInfo::operator!=(const CommitInfo &commit) const
Expand Down
21 changes: 10 additions & 11 deletions app/CommitInfoWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,14 @@ CommitInfoWidget::CommitInfoWidget(QSharedPointer<Git> git, QWidget *parent)
sizePolicy.setHeightForWidth(fileListWidget->sizePolicy().hasHeightForWidth());
fileListWidget->setSizePolicy(sizePolicy);

const auto gridLayout = new QGridLayout();
gridLayout->setHorizontalSpacing(10);
gridLayout->setVerticalSpacing(0);
gridLayout->setContentsMargins(0, 0, 0, 0);
gridLayout->addItem(new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 4, 1, 1);
gridLayout->addWidget(new QLabel(tr("Files")), 0, 2, 1, 1);
gridLayout->addWidget(labelIcon, 0, 1, 1, 1);
gridLayout->addItem(new QSpacerItem(10, 30, QSizePolicy::Fixed, QSizePolicy::Minimum), 0, 0, 1, 1);
gridLayout->addWidget(fileListWidget, 1, 0, 1, 5);
gridLayout->addWidget(labelModCount, 0, 3, 1, 1);
const auto headerLayout = new QHBoxLayout();
headerLayout->setContentsMargins(5, 0, 0, 0);
headerLayout->setSpacing(0);
headerLayout->addWidget(labelIcon);
headerLayout->addSpacerItem(new QSpacerItem(10, 1, QSizePolicy::Fixed, QSizePolicy::Fixed));
headerLayout->addWidget(new QLabel(tr("Files ")));
headerLayout->addWidget(labelModCount);
headerLayout->addStretch();

const auto verticalLayout = new QVBoxLayout(this);
verticalLayout->setSpacing(10);
Expand All @@ -78,7 +76,8 @@ CommitInfoWidget::CommitInfoWidget(QSharedPointer<Git> git, QWidget *parent)
verticalLayout->addWidget(labelTitle);
verticalLayout->addWidget(labelDescription);
verticalLayout->addWidget(commitInfoFrame);
verticalLayout->addLayout(gridLayout);
verticalLayout->addLayout(headerLayout);
verticalLayout->addWidget(fileListWidget);

connect(fileListWidget, &FileListWidget::itemDoubleClicked, this,
[this](QListWidgetItem *item) { emit signalOpenFileCommit(mCurrentSha, mParentSha, item->text()); });
Expand Down
66 changes: 46 additions & 20 deletions app/ConfigWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <CreateRepoDlg.h>
#include <git.h>
#include <ProgressDlg.h>
#include <GitQlientSettings.h>
#include <ClickableFrame.h>

#include <QPushButton>
#include <QGridLayout>
Expand All @@ -17,12 +19,15 @@

using namespace QLogger;

#include <QDebug>

ConfigWidget::ConfigWidget(QWidget *parent)
: QFrame(parent)
, mGit(new Git())
, mOpenRepo(new QPushButton(tr("Open existing repo")))
, mCloneRepo(new QPushButton(tr("Clone new repo")))
, mInitRepo(new QPushButton(tr("Init new repo")))
, mSettings(new GitQlientSettings())
{
mOpenRepo->setObjectName("bigButton");
mCloneRepo->setObjectName("bigButton");
Expand All @@ -44,18 +49,6 @@ ConfigWidget::ConfigWidget(QWidget *parent)
repoOptionsLayout->addWidget(mCloneRepo);
repoOptionsLayout->addWidget(mInitRepo);
repoOptionsLayout->addWidget(line);

QSettings s;
const auto mostUsedRepos = s.value("lastUsedRepos", QStringList()).toStringList();
for (const auto &repo : mostUsedRepos)
{
const auto usedRepo = new QPushButton(repo);
usedRepo->setToolTip(repo);
repoOptionsLayout->addWidget(usedRepo);
connect(usedRepo, &QPushButton::clicked, this,
[this]() { emit signalOpenRepo(dynamic_cast<QPushButton *>(sender())->toolTip()); });
}

repoOptionsLayout->addStretch();

const auto usedSubtitle = new QLabel(tr("Configuration"));
Expand Down Expand Up @@ -100,6 +93,11 @@ ConfigWidget::ConfigWidget(QWidget *parent)
connect(mGit.get(), &Git::signalCloningProgress, this, &ConfigWidget::updateProgressDialog, Qt::DirectConnection);
}

ConfigWidget::~ConfigWidget()
{
delete mSettings;
}

void ConfigWidget::openRepo()
{
const QString dirName(QFileDialog::getExistingDirectory(this, "Choose the directory of a Git project"));
Expand Down Expand Up @@ -134,9 +132,9 @@ QWidget *ConfigWidget::createConfigWidget()
{
mBtnGroup = new QButtonGroup();
mBtnGroup->addButton(new QPushButton(tr("General")), 0);
mBtnGroup->addButton(new QPushButton(tr("Git config")), 1);
mBtnGroup->addButton(new QPushButton(tr("Recent repos")), 1);

const auto firstBtn = mBtnGroup->button(0);
const auto firstBtn = mBtnGroup->button(1);
firstBtn->setProperty("selected", true);
firstBtn->style()->unpolish(firstBtn);
firstBtn->style()->polish(firstBtn);
Expand All @@ -161,11 +159,17 @@ QWidget *ConfigWidget::createConfigWidget()

buttonsLayout->addStretch();

const auto projectsFrame = new QFrame();

mRecentProjectsLayout = new QVBoxLayout(projectsFrame);
mRecentProjectsLayout->setContentsMargins(QMargins());
mRecentProjectsLayout->addWidget(createRecentProjectsPage());

const auto stackedWidget = new QStackedWidget();
stackedWidget->setMinimumHeight(300);
stackedWidget->addWidget(new GeneralConfigPage());
stackedWidget->addWidget(createConfigPage());
stackedWidget->setCurrentIndex(0);
stackedWidget->addWidget(projectsFrame);
stackedWidget->setCurrentIndex(1);

connect(mBtnGroup, qOverload<int>(&QButtonGroup::buttonClicked), this, [this, stackedWidget](int index) {
const auto selectedBtn = mBtnGroup->button(index);
Expand Down Expand Up @@ -193,12 +197,29 @@ QWidget *ConfigWidget::createConfigWidget()
return tabWidget;
}

QWidget *ConfigWidget::createConfigPage()
QWidget *ConfigWidget::createRecentProjectsPage()
{
const auto frame = new QFrame();
frame->setObjectName("configPage");
delete mInnerWidget;
mInnerWidget = new QFrame();
mInnerWidget->setObjectName("recentProjects");

return frame;
const auto innerLayout = new QVBoxLayout(mInnerWidget);
innerLayout->setSpacing(0);

const auto projects = mSettings->getRecentProjects();

for (auto project : projects)
{
const auto projectName = project.mid(project.lastIndexOf("/") + 1);
const auto labelText = QString("%1 <%2>").arg(projectName, project);
const auto clickableFrame = new ClickableFrame(labelText, Qt::AlignLeft);
connect(clickableFrame, &ClickableFrame::clicked, this, [this, project]() { emit signalOpenRepo(project); });
innerLayout->addWidget(clickableFrame);
}

innerLayout->addStretch();

return mInnerWidget;
}

void ConfigWidget::updateProgressDialog(QString stepDescription, int value)
Expand All @@ -219,3 +240,8 @@ void ConfigWidget::updateProgressDialog(QString stepDescription, int value)
mProgressDlg->setLabelText(stepDescription);
mProgressDlg->repaint();
}

void ConfigWidget::updateRecentProjectsList()
{
mRecentProjectsLayout->addWidget(createRecentProjectsPage());
}
Loading

0 comments on commit e6104d7

Please sign in to comment.