Skip to content

Commit

Permalink
resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
coder3101 committed Jan 25, 2020
2 parents 967114c + 1a49958 commit 99a18da
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.5)

project(CPEditor LANGUAGES CXX VERSION 5.3.2)
project(CPEditor LANGUAGES CXX VERSION 5.4.0)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

Expand Down
5 changes: 5 additions & 0 deletions include/SettingsManager.hpp
Expand Up @@ -89,6 +89,8 @@ struct SettingsData

ViewMode viewMode;
QByteArray splitterSizes;

QString cfPath;
};

class SettingManager
Expand Down Expand Up @@ -225,6 +227,9 @@ class SettingManager
QMap<QString, QVariant> getEditorStatus(int index);
void setEditorStatus(int index, const QMap<QString, QVariant> &status);

QString getCFPath();
void setCFPath(QString path);

void resetSettings();

SettingsData toData();
Expand Down
8 changes: 5 additions & 3 deletions include/cftools.hpp
Expand Up @@ -29,17 +29,19 @@ class CFTools : public QObject
Q_OBJECT

public:
CFTools(MessageLogger *logger);
CFTools(QString path, MessageLogger *logger);
~CFTools();
void submit(const QString &filePath, const QString &url, const QString &lang);
static bool check();
static bool check(QString path);

private slots:
void updatePath(QString p);
private slots:
void onReadReady();

private:
QProcess *CFToolProcess = nullptr;
MessageLogger *log;
QString path;
};
} // namespace Network

Expand Down
1 change: 1 addition & 0 deletions include/mainwindow.hpp
Expand Up @@ -176,6 +176,7 @@ class MainWindow : public QMainWindow
QString problemURL;
QString filePath;
QString savedText;
QString cftoolPath;
QFileSystemWatcher *fileWatcher;

QVector<QPlainTextEdit *> input = QVector<QPlainTextEdit *>(3, nullptr);
Expand Down
3 changes: 3 additions & 0 deletions include/preferencewindow.hpp
Expand Up @@ -79,6 +79,9 @@ class PreferenceWindow : public QMainWindow
void on_transparency_slider_valueChanged(int value);

private:
void on_cfpath_button_clicked();

private:
Ui::PreferenceWindow *ui;
QFont currentFont;
QString cppTemplatePath, pythonTemplatePath, javaTemplatePath;
Expand Down
11 changes: 11 additions & 0 deletions src/SettingsManager.cpp
Expand Up @@ -465,6 +465,16 @@ void SettingManager::setTransparency(int val)
mSettings->setValue("transparency", val);
}

QString SettingManager::getCFPath()
{
return mSettings->value("cf_path", "cf").toString();
}

void SettingManager::setCFPath(QString path)
{
mSettings->setValue("cf_path", path);
}

void SettingManager::setHotkeyViewModeToggler(QKeySequence sequence)
{
mSettings->setValue("hotkey_mode_toggle", sequence.toString());
Expand Down Expand Up @@ -576,6 +586,7 @@ SettingsData SettingManager::toData()
data.hotkeySnippets = getHotkeySnippets();
data.viewMode = getViewMode();
data.splitterSizes = getSplitterSizes();
data.cfPath = getCFPath();

return data;
}
Expand Down
37 changes: 32 additions & 5 deletions src/cftools.cpp
Expand Up @@ -16,12 +16,13 @@
*/

#include "cftools.hpp"
#include <QFileInfo>
#include <QUrl>

namespace Network
{

CFTools::CFTools(MessageLogger *logger)
CFTools::CFTools(QString path, MessageLogger *logger) : path(path)
{
log = logger;
CFToolProcess = new QProcess();
Expand Down Expand Up @@ -62,19 +63,45 @@ void CFTools::submit(const QString &filePath, const QString &url, const QString
return;
}
}

CFToolProcess->setProgram("cf");
if(path != "cf")
{
QFileInfo fileInfo(path);
CFToolProcess->setProgram(fileInfo.canonicalFilePath());
}
else
{
CFToolProcess->setProgram("cf");
}
CFToolProcess->setArguments({"submit", problemContestId, problemCode, filePath});
connect(CFToolProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(onReadReady()));
CFToolProcess->start();
}

bool CFTools::check()
bool CFTools::check(QString path)
{
QProcess checkProcess;
checkProcess.start("cf --version");

if(path != "cf")
{
QFileInfo pathInfo(path);
checkProcess.setProgram(pathInfo.canonicalFilePath());
checkProcess.setArguments({"--version"});
checkProcess.start();
}
else
{
checkProcess.start("cf", {"--version"});
}

bool finished = checkProcess.waitForFinished(2000);
return finished && checkProcess.exitCode() == 0;


}

void CFTools::updatePath(QString p)
{
path = p;
}

void CFTools::onReadReady()
Expand Down
16 changes: 13 additions & 3 deletions src/mainwindow.cc
Expand Up @@ -280,7 +280,7 @@ void MainWindow::setCFToolsUI()
if (submitToCodeforces == nullptr)
{
submitToCodeforces = new QPushButton("Submit Solution", this);
cftools = new Network::CFTools(&log);
cftools = new Network::CFTools(cftoolPath, &log);
ui->horizontalLayout_9->addWidget(submitToCodeforces);
connect(submitToCodeforces, &QPushButton::clicked, this, [this] {
auto response = QMessageBox::warning(
Expand All @@ -296,12 +296,13 @@ void MainWindow::setCFToolsUI()
}
});
}
if (!Network::CFTools::check())
if (!Network::CFTools::check(cftoolPath))
{
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");
"not on SYSTEM PATH. You can set it manually in settings.");
}

}

int MainWindow::getUntitledIndex() const
Expand Down Expand Up @@ -502,6 +503,15 @@ void MainWindow::setSettingsData(const Settings::SettingsData &data, bool should
formatter->updateBinary(data.clangFormatBinary);
formatter->updateStyle(data.clangFormatStyle);

cftoolPath = data.cfPath;

if(cftools != nullptr && Network::CFTools::check(cftoolPath))
{
cftools->updatePath(cftoolPath);
if(submitToCodeforces != nullptr)
submitToCodeforces->setEnabled(true);
}

editor->setTabReplace(data.isTabsReplaced);
editor->setTabReplaceSize(data.tabStop);
editor->setAutoIndentation(data.isAutoIndent);
Expand Down
24 changes: 24 additions & 0 deletions src/preferencewindow.cpp
Expand Up @@ -151,6 +151,11 @@ void PreferenceWindow::applySettingsToui()
if (lang_index != -1)
ui->snippets_lang->setCurrentIndex(lang_index);
onSnippetsLangChanged(lang);

if(manager->getCFPath() == "cf")
ui->cfpath_button->setText("<Search on System Environment>");
else
ui->cfpath_button->setText(manager->getCFPath());
}

void PreferenceWindow::extractSettingsFromUi()
Expand Down Expand Up @@ -204,6 +209,8 @@ void PreferenceWindow::extractSettingsFromUi()
manager->setHotkeyCompileRun(ui->compileRun_hotkey->keySequence());
manager->setHotkeyViewModeToggler(ui->toggle_hotkey->keySequence());
manager->setHotkeySnippets(ui->snippets_hotkey->keySequence());

manager->setCFPath(ui->cfpath_button->text());
}

void PreferenceWindow::updateShow()
Expand Down Expand Up @@ -515,3 +522,20 @@ QString PreferenceWindow::getNewSnippetName(const QString &lang, const QString &
else
return getNewSnippetName(lang, name);
}

void PreferenceWindow::on_cfpath_button_clicked()
{
#if defined (_WIN32)
auto filename = QFileDialog::getOpenFileName(this, tr("Choose CF tools"), "",
"Executable File (*.exe)");
if (filename.isEmpty())
return;
#else
auto filename = QFileDialog::getOpenFileName(this, tr("Choose CF tools"), "",
"Executable File (*.*)");
if (filename.isEmpty())
return;
#endif
ui->cfpath_button->setText(filename);

}
14 changes: 14 additions & 0 deletions ui/preferencewindow.ui
Expand Up @@ -964,6 +964,20 @@ p, li { white-space: pre-wrap; }
<item row="0" column="1">
<widget class="QSpinBox" name="time_limit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_49">
<property name="text">
<string>Codeforces Tools Path</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="cfpath_button">
<property name="text">
<string>&lt;Not Selected&gt;</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down
2 changes: 1 addition & 1 deletion win-setup.iss
Expand Up @@ -2,7 +2,7 @@
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "CP Editor"
#define MyAppVersion "5.3.2"
#define MyAppVersion "5.4.0"
#define MyAppPublisher "Ashar Khan <coder3101>"
#define MyAppURL "https://github.com/coder3101/cp-editor"
#define MyAppExeName "CPEditor.exe"
Expand Down

0 comments on commit 99a18da

Please sign in to comment.