Skip to content

Commit

Permalink
Next part of class "profileimporter"
Browse files Browse the repository at this point in the history
  • Loading branch information
juliagoda committed Jul 21, 2018
1 parent cd420d1 commit 8ba2f4c
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 70 deletions.
214 changes: 151 additions & 63 deletions src/profileimporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <QMessageBox>
#include <QFileDialog>
#include <QFileInfo>
#include <QSettings>

#include <iostream>
#include <fstream>
Expand Down Expand Up @@ -84,7 +85,7 @@ char ProfileImporter::convertHexToString_char(string const & hexValue)

void ProfileImporter::putGamecontrMapping()
{
/* QString mappingString = generateSDLMappingString();
/* QString mappingString = generateSDLMappingString();
settings->getLock()->lock();
Expand All @@ -101,7 +102,7 @@ void ProfileImporter::putGamecontrMapping()
out << generateSDLMappingString();
}
emit mappingUpdate(mappingString, device);*/
emit mappingUpdate(mappingString, device); */
}


Expand Down Expand Up @@ -163,28 +164,24 @@ void ProfileImporter::putSettingsToApp()
*/

bool ProfileImporter::allFilled()
{
return ((!ui->profileLineEdit->text().isEmpty()) && (radioBtnProfiles.checkedButton() != nullptr));
}


void ProfileImporter::on_AcceptBtn_clicked()
bool ProfileImporter::allFilled()
{
if (!allFilled())
if ((!ui->profileLineEdit->text().isEmpty()) && (radioBtnProfiles.checkedButton() != nullptr))
{
QMessageBox box;
box.setText(trUtf8("Could not import profile. Choose profile type and profile's file."));
box.setWindowTitle(trUtf8("Insufficient data"));
box.setStandardButtons(QMessageBox::Close);
box.raise();
box.exec();

if (ui->fullSettCheckBox->isChecked())
{
if (ui->configLineEdit->text().isEmpty()) return false;
else return true;
}
else
{
return true;
}
}
else
{


return false;
}
}

Expand All @@ -194,8 +191,8 @@ void ProfileImporter::changeExtensionFile(QString filePath)
QFileInfo info(filePath);
if (properExtension(filePath))
{
if ((radioBtnProfiles.checkedButton()->text().remove('&') == "JoyToKey")) {

if ((radioBtnProfiles.checkedButton()->text().remove('&') == "JoyToKey"))
{
QString strNewName = info.path() + "/" + info.completeBaseName() + ".ini";
QFile renamed(filePath);
renamed.rename(filePath, strNewName);
Expand All @@ -220,7 +217,6 @@ void ProfileImporter::backExtensionFile(QString filePath)
QString strNewName = info.path() + "/" + info.completeBaseName() + "." + extensionProfile();
QFile renamed(filePath);
renamed.rename(filePath, strNewName);

}


Expand All @@ -234,9 +230,8 @@ QString ProfileImporter::extensionProfile()
}


bool ProfileImporter::properExtension(QString profilePath)
bool ProfileImporter::properExtension(const QString& profilePath)
{

QFileInfo info(profilePath);

if ((radioBtnProfiles.checkedButton()->text().remove('&') == "JoyToKey") && (info.completeSuffix() == "cfg"))
Expand All @@ -256,63 +251,41 @@ bool ProfileImporter::properExtension(QString profilePath)
}


void ProfileImporter::openFile(QString profilePath)
bool ProfileImporter::properExtensionSett(const QString & settfilePath)
{
QFileInfo info(settfilePath);

if (info.completeSuffix() == "ini") return true;

return false;
}


void ProfileImporter::readSettGroups()
void ProfileImporter::openFile(QString importedFilePath)
{
QSettings settings(importedFilePath, QSettings::NativeFormat);



}


QString ProfileImporter::displayModeJoyToKey()
void ProfileImporter::readSettGroups()
{
return "";
}


void ProfileImporter::on_cancelBtn_clicked()
{
close();
}


void ProfileImporter::on_findProfileBtn_clicked()
const QString ProfileImporter::displayModeJoyToKey()
{
if (radioBtnProfiles.checkedButton() == nullptr) {

QMessageBox box;
box.setText(trUtf8("Could not define file's extension. Choose profile's type first above."));
box.setWindowTitle(trUtf8("Insufficient data"));
box.setStandardButtons(QMessageBox::Close);
box.raise();
box.exec();

} else {

QString profile = profilePath();
if (!properExtension(profile)) {

QMessageBox box;
box.setText(trUtf8("Could not choose a file. Find a file with proper extension."));
box.setWindowTitle(trUtf8("Incorrect filename"));
box.setStandardButtons(QMessageBox::Close);
box.raise();
box.exec();

} else {
return displayedModeJoyToKey;
}

ui->profileLineEdit->setText(profilePath());

QFileInfo info(profile);
chosenFile = info.completeBaseName();
}
}
void ProfileImporter::setDisplayModeJoyToKey(QString const & displayMode)
{
displayedModeJoyToKey = displayMode;
}


Expand All @@ -326,21 +299,20 @@ QString ProfileImporter::filedialogDescExt()
}


QString ProfileImporter::profilePath()
const QString ProfileImporter::importedFilePath(QString title, QString extensionFile)
{
QString fileName = QFileDialog::getOpenFileName(
this, trUtf8("Choose game profile"),
this, title,
QFileDialog::getExistingDirectory(this, trUtf8("Find"),
QDir::currentPath()),
filedialogDescExt());
extensionFile);

return fileName;
}


void ProfileImporter::rewriteButtonGroup()
{

QList<QRadioButton *> allButtons = ui->groupBox->findChildren<QRadioButton *>();

qDebug() << allButtons.size();
Expand All @@ -355,6 +327,27 @@ void ProfileImporter::rewriteButtonGroup()
}


void ProfileImporter::putSettingsFromJoyToKey()
{

}


void ProfileImporter::putSettingsFromXPadder()
{

}


void ProfileImporter::putSettingsFromPinnacle()
{

}


// ----------------------------- SLOTS ------------------------------------- //


// 0 - unchecked
// 2 - checked
void ProfileImporter::on_fullSettCheckBox_stateChanged(int state)
Expand Down Expand Up @@ -388,3 +381,98 @@ void ProfileImporter::on_fullSettCheckBox_stateChanged(int state)
break;
}
}


void ProfileImporter::on_AcceptBtn_clicked()
{
if (!allFilled())
{
QMessageBox box;
box.setText(trUtf8("Could not import profile. Choose profile type and profile's file."));
box.setWindowTitle(trUtf8("Insufficient data"));
box.setStandardButtons(QMessageBox::Close);
box.raise();
box.exec();
}
else
{


}
}


void ProfileImporter::on_cancelBtn_clicked()
{
close();
}


void ProfileImporter::on_findProfileBtn_clicked()
{
if (radioBtnProfiles.checkedButton() == nullptr) {

QMessageBox box;
box.setText(trUtf8("Could not define file's extension. Choose profile's type first above."));
box.setWindowTitle(trUtf8("Insufficient data"));
box.setStandardButtons(QMessageBox::Close);
box.raise();
box.exec();

} else {

QString profile = importedFilePath(trUtf8("Choose game profile"), filedialogDescExt());

if (!properExtension(profile))
{
QMessageBox box;
box.setText(trUtf8("Could not choose a file. Find a file with proper extension."));
box.setWindowTitle(trUtf8("Incorrect filename"));
box.setStandardButtons(QMessageBox::Close);
box.raise();
box.exec();

} else {

ui->profileLineEdit->setText(profile);

QFileInfo info(profile);
chosenFile = info.completeBaseName();
}
}
}


void ProfileImporter::on_findConfigBtn_clicked()
{
if (radioBtnProfiles.checkedButton() == nullptr)
{
QMessageBox box;
box.setText(trUtf8("Could not define file's extension. Choose profile's type first above."));
box.setWindowTitle(trUtf8("Insufficient data"));
box.setStandardButtons(QMessageBox::Close);
box.raise();
box.exec();

} else {

QString settingsFile = importedFilePath(trUtf8("Choose app settings file"), trUtf8("Settings file (*.ini)"));

if (!properExtensionSett(settingsFile))
{
QMessageBox box;
box.setText(trUtf8("Could not choose a file. Find a file with proper extension."));
box.setWindowTitle(trUtf8("Incorrect filename"));
box.setStandardButtons(QMessageBox::Close);
box.raise();
box.exec();

} else {

ui->configLineEdit->setText(settingsFile);

QFileInfo info(settingsFile);
chosenFileSett = info.completeBaseName();
}
}
}
20 changes: 14 additions & 6 deletions src/profileimporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,20 @@ class ProfileImporter : public QWidget

void changeExtensionFile(QString filePath);
void backExtensionFile(QString filePath);
QString profilePath();
void openFile(QString profilePath);
void openFile(QString importedFilePath);
void readSettGroups();
int convertStringToQtKey(QString const & keyString);
const QString importedFilePath(QString title, QString extensionFile);
const QString displayModeJoyToKey();
QChar convertHexToString_QChar(QString const & hexValue);
char convertHexToString_char(std::string const & hexValue);
int convertStringToQtKey(QString const & keyString);


protected:
bool allFilled();
bool properExtension(QString profilePath);
bool properExtension(const QString& profilePath);
bool properExtensionSett(const QString& settfilePath);
void setDisplayModeJoyToKey(QString const & displayMode);
QString extensionProfile();


Expand All @@ -152,6 +155,7 @@ private slots:
void on_cancelBtn_clicked();
void on_findProfileBtn_clicked();
void on_fullSettCheckBox_stateChanged(int state);
void on_findConfigBtn_clicked();


private:
Expand All @@ -160,15 +164,19 @@ private slots:
QHash<QString, QString> antToCurrGamepads;

AntiMicroSettings *settings;
QString chosenFile;
QButtonGroup radioBtnProfiles;
QString chosenFile;
QString chosenFileSett;
QString displayedModeJoyToKey;
QString buttonMode;

void putSettingsToApp();
void putGamecontrMapping();
QString displayModeJoyToKey();
void rewriteButtonGroup();
void putSettingsFromJoyToKey();
void putSettingsFromXPadder();
void putSettingsFromPinnacle();

QString filedialogDescExt();

};
Expand Down
2 changes: 1 addition & 1 deletion src/profileimporter.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>457</width>
<height>459</height>
<height>555</height>
</rect>
</property>
<property name="windowTitle">
Expand Down

0 comments on commit 8ba2f4c

Please sign in to comment.