Skip to content

Commit

Permalink
Merge pull request #93 from DXS-SQUAD/InDev
Browse files Browse the repository at this point in the history
Fix requests
  • Loading branch information
Nighty3098 authored Jun 8, 2024
2 parents f4b36ed + 1406c1d commit cc887a0
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 76 deletions.
177 changes: 108 additions & 69 deletions src/CodeKeeper/keeperFunc/getProjectInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,49 +132,44 @@ QString MainWindow::getRepositoryData(QString git_url, QTableWidget *table)

name = obj["name"].toString();

if (isCreated) {
createdAt = obj["created_at"].toString();
QDateTime createdDate = QDateTime::fromString(createdAt, Qt::ISODate);
createdAt = createdDate.toString("dd MMM yyyy hh:mm");
}
if (isIssue) {
openIssues = QString::number(obj["open_issues"].toInt());
}
createdAt = obj["created_at"].toString();
QDateTime createdDate = QDateTime::fromString(createdAt, Qt::ISODate);
createdAt = createdDate.toString("dd MMM yyyy hh:mm");

openIssues = QString::number(obj["open_issues"].toInt());

// repoData += " \n Watchers: " + QString::number(obj["watchers"].toInt()) + " ";
if (isForks) {
forks = QString::number(obj["forks"].toInt());
}
if (isLang) {
lang = obj["language"].toString();
}
if (isStars) {
stars = QString::number(obj["stargazers_count"].toInt());
}
if (isRepoSize) {
qint64 size = obj["size"].toDouble();
forks = QString::number(obj["forks"].toInt());
lang = obj["language"].toString();


stars = QString::number(obj["stargazers_count"].toInt());

qint64 size = obj["size"].toDouble();
repoSize = formatFileSize(size);

repoSize = formatFileSize(size);
}

if (obj.contains("license")) {
QJsonObject licenseObj = obj["license"].toObject();
if (licenseObj.contains("name")) {
if (isLicense) {
license = licenseObj["name"].toString() + " ";
}
} else {
if (isLicense) {
qDebug() << "License not found";
}
}
} else {
if (isLicense) {
qDebug() << "License not found";
}
}

QUrl commitUrl("https://api.github.com/repos/" + repo + "/commits");
QNetworkReply *commitReply = manager->get(QNetworkRequest(commitUrl));
commitUrl.setQuery(query);

QNetworkRequest commitUrlRequest(commitUrl);
commitUrlRequest.setHeader(QNetworkRequest::UserAgentHeader, "CodeKeeper");
commitUrlRequest.setRawHeader("Authorization", ("Bearer " + git_token).toUtf8());
commitUrlRequest.setRawHeader("X-GitHub-Api-Version", "2022-11-28");
commitUrlRequest.setRawHeader("Accept", "application/vnd.github.v3+json");

QNetworkReply *commitReply = manager->get(commitUrlRequest);
QObject::connect(commitReply, &QNetworkReply::finished, &loop, &QEventLoop::quit);

loop.exec();
Expand All @@ -190,22 +185,26 @@ QString MainWindow::getRepositoryData(QString git_url, QTableWidget *table)
qDebug() << commitDoc;

if (commits.isEmpty()) {
if (isLastCommit) {
qDebug() << "No commits found";
}
qDebug() << "No commits found";
}

QJsonObject lastCommit = commits.first().toObject();
QString dateStr = lastCommit["commit"].toObject()["author"].toObject()["date"].toString();

QDateTime lastCommitDate = QDateTime::fromString(dateStr, Qt::ISODate);

if (isLastCommit) {
QString lastCommitS = lastCommitDate.toString("dd MMM yyyy hh:mm");
}
lastCommitS = lastCommitDate.toString("dd MMM yyyy hh:mm");

QUrl releaseUrl("https://api.github.com/repos/" + repo + "/releases");
QNetworkReply *releaseReply = manager->get(QNetworkRequest(releaseUrl));
releaseUrl.setQuery(query);

QNetworkRequest releaseUrlRequest(releaseUrl);
releaseUrlRequest.setHeader(QNetworkRequest::UserAgentHeader, "CodeKeeper");
releaseUrlRequest.setRawHeader("Authorization", ("Bearer " + git_token).toUtf8());
releaseUrlRequest.setRawHeader("X-GitHub-Api-Version", "2022-11-28");
releaseUrlRequest.setRawHeader("Accept", "application/vnd.github.v3+json");

QNetworkReply *releaseReply = manager->get(releaseUrlRequest);
QObject::connect(releaseReply, &QNetworkReply::finished, &loop, &QEventLoop::quit);

loop.exec();
Expand All @@ -226,13 +225,20 @@ QString MainWindow::getRepositoryData(QString git_url, QTableWidget *table)
iTotalDownloads += downloads;
}

if (isDownloads) {
totalDownloads = QString::number(iTotalDownloads);
}
totalDownloads = QString::number(iTotalDownloads);


// Release info
QUrl releasesUrl("https://api.github.com/repos/" + repo + "/releases/latest");
QNetworkReply *releasesReply = manager->get(QNetworkRequest(releasesUrl));
releasesUrl.setQuery(query);

QNetworkRequest releasesRequest(releasesUrl);
releasesRequest.setHeader(QNetworkRequest::UserAgentHeader, "CodeKeeper");
releasesRequest.setRawHeader("Authorization", ("Bearer " + git_token).toUtf8());
releasesRequest.setRawHeader("X-GitHub-Api-Version", "2022-11-28");
releasesRequest.setRawHeader("Accept", "application/vnd.github.v3+json");

QNetworkReply *releasesReply = manager->get(releasesRequest);
QObject::connect(releasesReply, &QNetworkReply::finished, &loop, &QEventLoop::quit);

loop.exec(); // Block until the lambda function has finished
Expand All @@ -246,16 +252,13 @@ QString MainWindow::getRepositoryData(QString git_url, QTableWidget *table)
QJsonObject releasesObj = releasesDoc.object();
qDebug() << releasesDoc;

if (isRelease) {
release = releasesObj["name"].toString();
}

release = releasesObj["name"].toString();

if (isReleaseDate) {
QString dateStr = releasesObj["published_at"].toString();
dateStr = releasesObj["published_at"].toString();

QDateTime releaseDateT = QDateTime::fromString(dateStr, Qt::ISODate);
releaseDate = releaseDateT.toString("dd MMM yyyy hh:mm");
}
QDateTime releaseDateT = QDateTime::fromString(dateStr, Qt::ISODate);
releaseDate = releaseDateT.toString("dd MMM yyyy hh:mm");

releasesReply->deleteLater();
reply->deleteLater();
Expand Down Expand Up @@ -284,39 +287,75 @@ QString MainWindow::getRepositoryData(QString git_url, QTableWidget *table)

table->setItem(0, 0, new QTableWidgetItem("Repo"));
table->setItem(0, 1, new QTableWidgetItem(name));
table->item(0, 0)->setTextAlignment(Qt::AlignCenter);

QStringList dataList, textList;

dataList << name;
textList << "Repo";

table->setItem(1, 0, new QTableWidgetItem("Created at"));
table->setItem(1, 1, new QTableWidgetItem(createdAt));
if (isCreated) {
textList << "Created at";
dataList << createdAt;
}

if (isIssue) {
dataList << openIssues;
textList << "Open issues";
}

if (isForks) {
dataList << forks;
textList << "Forks";
}

if (isLang) {
dataList << lang;
textList << "Lang";
}

table->setItem(2, 0, new QTableWidgetItem("Open issues"));
table->setItem(2, 1, new QTableWidgetItem(openIssues));
if (isStars) {
dataList << stars;
textList << "Stars";
}

table->setItem(3, 0, new QTableWidgetItem("Forks"));
table->setItem(3, 1, new QTableWidgetItem(forks));
if (isRepoSize) {
dataList << repoSize;
textList << "Repo size";
}

table->setItem(4, 0, new QTableWidgetItem("Lang"));
table->setItem(4, 1, new QTableWidgetItem(lang));
if (isLicense) {
dataList << license;
textList << "License";
}

table->setItem(5, 0, new QTableWidgetItem("Stars"));
table->setItem(5, 1, new QTableWidgetItem(stars));
if (isLastCommit) {
dataList << lastCommitS;
textList << "Last commit";
}

table->setItem(6, 0, new QTableWidgetItem("Repo size"));
table->setItem(6, 1, new QTableWidgetItem(repoSize));
if (isDownloads) {
dataList << totalDownloads;
textList << "Downloads";
}

table->setItem(7, 0, new QTableWidgetItem("License"));
table->setItem(7, 1, new QTableWidgetItem(license));
if (isRelease) {
dataList << release;
textList << "Release";
}

table->setItem(8, 0, new QTableWidgetItem("Last commit"));
table->setItem(8, 1, new QTableWidgetItem(lastCommitS));
if (isReleaseDate) {
dataList << releaseDate;
textList << "Release at";
}

table->setItem(9, 0, new QTableWidgetItem("Downloads"));
table->setItem(9, 1, new QTableWidgetItem(totalDownloads));
for (int i = 0; i < dataList.count(); i++) {
table->setItem(i, 0, new QTableWidgetItem(textList[i]));
table->setItem(i, 1, new QTableWidgetItem(dataList[i]));
table->item(i, 0)->setTextAlignment(Qt::AlignCenter);
}

table->setItem(10, 0, new QTableWidgetItem("Release"));
table->setItem(10, 1, new QTableWidgetItem(release));

table->setItem(11, 0, new QTableWidgetItem("Release at"));
table->setItem(11, 1, new QTableWidgetItem(releaseDate));

for (int row = 0; row < table->rowCount(); ++row) {
for (int col = 0; col < table->columnCount(); ++col) {
Expand Down
10 changes: 5 additions & 5 deletions src/CodeKeeper/keeperFunc/projectsFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void MainWindow::openProject(QListWidget *listWidget, QListWidgetItem *item)
{
if (item) {
QDialog dialog(this);
dialog.setFixedSize(400, 650);
dialog.setFixedSize(400, 550);
dialog.setWindowTitle(tr("Edit project"));
dialog.setWindowFlags(windowFlags() | Qt::FramelessWindowHint);

Expand Down Expand Up @@ -170,7 +170,7 @@ void MainWindow::openProject(QListWidget *listWidget, QListWidgetItem *item)
git_stats->setStyleSheet(
"QTableWidget{ background-color: #0d1117; alternate-background-color: #171b22; "
"selection-background-color: #336fc9; show-decoration-selected: 1; font-size: "
+ font_size + "pt; }");
+ font_size + "pt; border: 0px;}");

/*QWebEngineView *git_stats = new QWebEngineView();
git_stats->page()->setBackgroundColor(Qt::transparent);
Expand Down Expand Up @@ -216,9 +216,9 @@ void MainWindow::openProject(QListWidget *listWidget, QListWidgetItem *item)
mainLayout.addWidget(documentation, 2, 0);
mainLayout.addWidget(openButton, 2, 1);
mainLayout.addWidget(git_stats, 4, 0, 1, 2);
mainLayout.addWidget(lastMod, 7, 0, 1, 2);
mainLayout.addWidget(saveDataBtn, 5, 0, 1, 2, Qt::AlignCenter);
mainLayout.addWidget(cancelBtn, 6, 0, 1, 2, Qt::AlignCenter);
mainLayout.addWidget(saveDataBtn, 6, 0, 1, 2, Qt::AlignCenter);
mainLayout.addWidget(cancelBtn, 7, 0, 1, 2, Qt::AlignCenter);
mainLayout.addWidget(lastMod, 5, 0, 1, 2, Qt::AlignCenter);

QThread *thread = new QThread;
QObject::connect(thread, &QThread::started, this, [this, projectData, git_stats]() {
Expand Down
4 changes: 2 additions & 2 deletions src/CodeKeeper/settingswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ SettingsWindow::SettingsWindow(QWidget *parent) : QMainWindow{ parent }
connect(repoTimer, &QTimer::timeout, [=]() { checkRepo(); });
repoTimer->start(100);

qDebug() << "\033[0m\033[32mrepoTimerThread started";
qDebug() << "repoTimerThread started";
});
repoTimerThread->start();

Expand All @@ -369,7 +369,7 @@ SettingsWindow::SettingsWindow(QWidget *parent) : QMainWindow{ parent }
int font_size_int = font_size.toInt();
setFontPr2(&selectedFont, &font_size_int);

qDebug() << "\033[0m\033[32mstyleThread started";
qDebug() << "styleThread started";
});
styleThread->start();
}
Expand Down

0 comments on commit cc887a0

Please sign in to comment.