Skip to content

Commit

Permalink
WIP : CF tools intergration in progress(1/3)
Browse files Browse the repository at this point in the history
  • Loading branch information
coder3101 committed Jan 9, 2020
1 parent 73d67fc commit a9aaf62
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 8 deletions.
8 changes: 5 additions & 3 deletions include/cftools.hpp
Expand Up @@ -2,21 +2,23 @@
#define CFTOOLS_HPP

#include <QProcess>
#include <BaseFiles.hpp>
namespace Network
{
class CFTools
class CFTools : private Core::Base::Files
{
public:
CFTools();
CFTools(int index);

void submit();
void submit(QString url, QString lang);
void killProcess();

static bool check();
~CFTools();

private:
QProcess *cftool = nullptr;
int index;
};
} // namespace Network
#endif // CFTOOLS_HPP
3 changes: 3 additions & 0 deletions include/mainwindow.hpp
Expand Up @@ -26,6 +26,7 @@
#include <QFile>
#include <QLabel>
#include <QMainWindow>
#include <QPushButton>
#include <QShortcut>
#include <QSplitter>
#include <Runner.hpp>
Expand Down Expand Up @@ -121,6 +122,8 @@ class MainWindow : public QMainWindow
QVector<QLabel *> verdict = QVector<QLabel *>(3, nullptr);
QVector<QString *> expected = QVector<QString *>(3, nullptr);
Network::CompanionData companionData;
QPushButton *submitToCodeforces = nullptr;
Network::CFTools *cftools = nullptr;

void setEditor();
void setupCore();
Expand Down
26 changes: 22 additions & 4 deletions src/cftools.cpp
@@ -1,26 +1,44 @@
#include "cftools.hpp"

#include <QDebug>
namespace Network
{

CFTools::CFTools()
CFTools::CFTools(int index) : Core::Base::Files(index)
{
}

void CFTools::killProcess()
{
}

void CFTools::submit()
void CFTools::submit(QString url, QString language)
{
QString filePath;
if (language == "Cpp")
{
filePath = getProgramFile();
}
else if (language == "Java")
{
filePath = getProgramFile(".java");
}
else if (language == "Python")
{
filePath = getProgramFile(".py");
}
else
{
return;
}
// Todo : Invoke cf-tools here.
}

bool CFTools::check()
{
QProcess program;
QString commandToStart = "cf";
QStringList environment = program.systemEnvironment();
program.start(commandToStart + " --version");
program.start(commandToStart);
bool started = program.waitForStarted();
if (started) // 10 Second timeout
program.kill();
Expand Down
25 changes: 24 additions & 1 deletion src/mainwindow.cc
Expand Up @@ -112,6 +112,7 @@ void MainWindow::setEditor()
expected[i] = new QString;
input[i]->setWordWrapMode(QTextOption::NoWrap);
output[i]->setWordWrapMode(QTextOption::NoWrap);
input[i]->setAcceptDrops(false);
}

QObject::connect(editor, SIGNAL(textChanged()), this, SLOT(onTextChangedTriggered()));
Expand Down Expand Up @@ -278,7 +279,29 @@ void MainWindow::saveTests()

void MainWindow::setCFToolsUI()
{
ui->horizontalLayout_9->addWidget(new QPushButton("Submit on Codeforces", this));
if (submitToCodeforces == nullptr)
{
submitToCodeforces = new QPushButton("Submit Solution", this);
cftools = new Network::CFTools(windowIndex);
ui->horizontalLayout_9->addWidget(submitToCodeforces);
connect(submitToCodeforces, &QPushButton::clicked, this, [this] {
auto response = QMessageBox::warning(
this, "Sure to submit",
"Are you sure you want to submit this solution to codeforces?\nContest URL: " + companionData.url +
"\n Language : " + language,
QMessageBox::Yes | QMessageBox::No);

if (response == QMessageBox::Yes)
cftools->submit(companionData.url, language);
});

}
if (!Network::CFTools::check())
{
submitToCodeforces->setEnabled(false);
log.error("CFTools",
"You will not be able to submit code to codeforces because CFTools is not installed or is not on SYSTEM PATH");
}
}

QString MainWindow::fileName() const
Expand Down

0 comments on commit a9aaf62

Please sign in to comment.