-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
125 lines (82 loc) · 2.72 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "QPushButton"
#include "QFileDialog"
#include "QInputDialog"
#include "includes/Repository.h"
#include <filesystem>
using namespace std;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
MainWindow::repo = nullptr;
ui->setupUi(this);
ui->stackedWidget->setCurrentIndex(0);
}
MainWindow::~MainWindow()
{
delete ui;
delete repo;
}
void MainWindow::on_browseBtn1_clicked()
{
QString selectedFolder = QFileDialog::getExistingDirectory(this, tr("Select Folder"), QDir::homePath());
if (! selectedFolder.isEmpty()) {
this->selectedFolder = selectedFolder;
}
ui->lineEdit->setText(selectedFolder);
}
void MainWindow::on_browseBtn2_clicked()
{
QString selectedFile = QFileDialog::getOpenFileName(this, tr("Select File"), QDir::homePath());
if (! selectedFile.isEmpty()) {
this->fileToAdd = selectedFile;
}
ui->lineEdit_2->setText(selectedFile);
}
void MainWindow::on_enterToRepo_clicked()
{
if (selectedFolder != nullptr) {
this->repo = new Repository(selectedFolder.toStdString());
std::string msg = repo->init();
ui->repoInitMessage->setText(QString::fromStdString(msg));
ui->stackedWidget->setCurrentIndex(1);
}
}
void MainWindow::on_addBtn_clicked()
{
if (this->fileToAdd != nullptr) {
std::string filename = std::filesystem::path(this->fileToAdd.toStdString()).filename().generic_string();
std::string msg = this->repo->add(filename);
std::vector<std::string> statuses = this->repo->status();
ui->statusTextbox->clear();
for (auto it: statuses) {
ui->statusTextbox->append(QString::fromStdString(it));
}
ui->commitSuccessLabel->setText(QString::fromStdString(msg));
}
}
void MainWindow::on_commitBtn_clicked()
{
if (this->fileToAdd != nullptr) {
std::string filename = std::filesystem::path(this->fileToAdd.toStdString()).filename().generic_string();
bool ok;
QString userInput = QInputDialog::getText(this, "Input Dialog", "Enter the commit message:", QLineEdit::Normal, "", &ok);
if (ok && !userInput.isEmpty()) {
std::string msgToShow = this->repo->commit(filename, userInput.toStdString());
ui->commitSuccessLabel->setText(QString::fromStdString(msgToShow));
}
}
}
void MainWindow::on_changeRepoBtn_clicked()
{
this->selectedFolder = nullptr;
this->repo = nullptr;
this->fileToAdd = nullptr;
ui->commitSuccessLabel->clear();
ui->statusTextbox->clear();
ui->lineEdit->clear();
ui->lineEdit_2->clear();
ui->stackedWidget->setCurrentIndex(0);
}