mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-14 19:18:55 -07:00
Major Directory Refactoring (#5118)
* refactored cardzone.cpp, added doc and changed if to switch case * started moving every files into different folders * remove undercase to match with other files naming convention * refactored dialog files * ran format.sh * refactored client/tabs folder * refactored client/tabs folder * refactored client/tabs folder * refactored client folder * refactored carddbparser * refactored dialogs * Create sonar-project.properties temporary file for lint * Create build.yml temporary file for lint * removed all files from root directory * removed all files from root directory * added current branch to workflow * fixed most broken import * fixed issues while renaming files * fixed oracle importer * fixed dbconverter * updated translations * made sub-folders for client * removed linter * removed linter folder * fixed oracle import * revert card_zone documentation * renamed db parser files name and deck_view imports * fixed dlg file issue * ran format file and fixed test file * fixed carddb test files * moved player folder in game * updated translations and format files * fixed peglib import * format cmake files * removing vcpkg to try to add it back later * tried fixing vcpkg file * renamed filter to filters and moved database parser to cards folder * reverted translation files * reverted oracle translated * Update cockatrice/src/dialogs/dlg_register.cpp Co-authored-by: tooomm <tooomm@users.noreply.github.com> * Update cockatrice/src/client/ui/window_main.cpp Co-authored-by: tooomm <tooomm@users.noreply.github.com> * removed empty line at file start * removed useless include from tab_supervisor.cpp * refactored cardzone.cpp, added doc and changed if to switch case * started moving every files into different folders * remove undercase to match with other files naming convention * refactored dialog files * ran format.sh * refactored client/tabs folder * refactored client folder * refactored carddbparser * refactored dialogs * removed all files from root directory * Create sonar-project.properties temporary file for lint * Create build.yml temporary file for lint * added current branch to workflow * fixed most broken import * fixed issues while renaming files * fixed oracle importer * fixed dbconverter * updated translations * made sub-folders for client * removed linter * removed linter folder * fixed oracle import * revert card_zone documentation * renamed db parser files name and deck_view imports * fixed dlg file issue * ran format file and fixed test file * fixed carddb test files * moved player folder in game * updated translations and format files * fixed peglib import * reverted translation files * format cmake files * removing vcpkg to try to add it back later * tried fixing vcpkg file * pre-updating of cockatrice changes * removed empty line at file start * reverted oracle translated * Update cockatrice/src/dialogs/dlg_register.cpp Co-authored-by: tooomm <tooomm@users.noreply.github.com> * Update cockatrice/src/client/ui/window_main.cpp Co-authored-by: tooomm <tooomm@users.noreply.github.com> * removed useless include from tab_supervisor.cpp --------- Co-authored-by: tooomm <tooomm@users.noreply.github.com>
This commit is contained in:
parent
d1e0f9dfc5
commit
fa999880ee
261 changed files with 735 additions and 729 deletions
142
cockatrice/src/utility/logger.cpp
Normal file
142
cockatrice/src/utility/logger.cpp
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
#include "logger.h"
|
||||
|
||||
#include "version_string.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDateTime>
|
||||
#include <QLocale>
|
||||
#include <QSysInfo>
|
||||
#include <iostream>
|
||||
|
||||
#define LOGGER_MAX_ENTRIES 128
|
||||
#define LOGGER_FILENAME "qdebug.txt"
|
||||
|
||||
Logger::Logger() : logToFileEnabled(false)
|
||||
{
|
||||
logBuffer.append(getClientVersion());
|
||||
logBuffer.append(getSystemArchitecture());
|
||||
logBuffer.append(getSystemLocale());
|
||||
logBuffer.append(getClientInstallInfo());
|
||||
logBuffer.append(QString("-").repeated(75));
|
||||
std::cerr << getClientVersion().toStdString() << std::endl;
|
||||
std::cerr << getSystemArchitecture().toStdString() << std::endl;
|
||||
std::cerr << getSystemLocale().toStdString() << std::endl;
|
||||
std::cerr << getClientInstallInfo().toStdString() << std::endl;
|
||||
}
|
||||
|
||||
Logger::~Logger()
|
||||
{
|
||||
closeLogfileSession();
|
||||
logBuffer.clear();
|
||||
}
|
||||
|
||||
void Logger::logToFile(bool enabled)
|
||||
{
|
||||
if (enabled) {
|
||||
openLogfileSession();
|
||||
} else {
|
||||
closeLogfileSession();
|
||||
}
|
||||
}
|
||||
|
||||
QString Logger::getClientVersion()
|
||||
{
|
||||
return "Client Version: " + QString::fromStdString(VERSION_STRING);
|
||||
}
|
||||
|
||||
void Logger::openLogfileSession()
|
||||
{
|
||||
if (logToFileEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
fileHandle.setFileName(LOGGER_FILENAME);
|
||||
fileHandle.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
|
||||
fileStream.setDevice(&fileHandle);
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
fileStream << "Log session started at " << QDateTime::currentDateTime().toString() << Qt::endl;
|
||||
fileStream << getClientVersion() << Qt::endl;
|
||||
fileStream << getSystemArchitecture() << Qt::endl;
|
||||
fileStream << getClientInstallInfo() << Qt::endl;
|
||||
#else
|
||||
fileStream << "Log session started at " << QDateTime::currentDateTime().toString() << endl;
|
||||
fileStream << getClientVersion() << endl;
|
||||
fileStream << getSystemArchitecture() << endl;
|
||||
fileStream << getClientInstallInfo() << endl;
|
||||
#endif
|
||||
logToFileEnabled = true;
|
||||
}
|
||||
|
||||
void Logger::closeLogfileSession()
|
||||
{
|
||||
if (!logToFileEnabled)
|
||||
return;
|
||||
|
||||
logToFileEnabled = false;
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
fileStream << "Log session closed at " << QDateTime::currentDateTime().toString() << Qt::endl;
|
||||
#else
|
||||
fileStream << "Log session closed at " << QDateTime::currentDateTime().toString() << endl;
|
||||
#endif
|
||||
fileHandle.close();
|
||||
}
|
||||
|
||||
void Logger::log(QtMsgType /* type */, const QMessageLogContext & /* ctx */, const QString message)
|
||||
{
|
||||
QMetaObject::invokeMethod(this, "internalLog", Qt::QueuedConnection, Q_ARG(const QString &, message));
|
||||
}
|
||||
|
||||
void Logger::internalLog(QString message)
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
|
||||
logBuffer.append(message);
|
||||
if (logBuffer.size() > LOGGER_MAX_ENTRIES) {
|
||||
logBuffer.removeAt(1);
|
||||
}
|
||||
|
||||
emit logEntryAdded(message);
|
||||
std::cerr << message.toStdString() << std::endl; // Print to stdout
|
||||
|
||||
if (logToFileEnabled) {
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||
fileStream << message << Qt::endl; // Print to fileStream
|
||||
#else
|
||||
fileStream << message << endl; // Print to fileStream
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
QString Logger::getSystemArchitecture()
|
||||
{
|
||||
QString result;
|
||||
|
||||
if (!getClientOperatingSystem().isEmpty()) {
|
||||
// We don't want translatable strings in the 'Debug Log' for easier troubleshooting
|
||||
result.append(QString("Client Operating System: ") + getClientOperatingSystem() + "\n");
|
||||
}
|
||||
|
||||
result.append(QString("Build Architecture: ") + QString::fromStdString(BUILD_ARCHITECTURE) + "\n");
|
||||
result.append(QString("Qt Version: ") + QT_VERSION_STR);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QString Logger::getClientOperatingSystem()
|
||||
{
|
||||
return QSysInfo::prettyProductName();
|
||||
}
|
||||
|
||||
QString Logger::getSystemLocale()
|
||||
{
|
||||
QString result(QString("System Locale: ") + QLocale().name());
|
||||
return result;
|
||||
}
|
||||
|
||||
QString Logger::getClientInstallInfo()
|
||||
{
|
||||
// don't rely on settingsCache->getIsPortableBuild() since the logger is initialized earlier
|
||||
bool isPortable = QFile::exists(qApp->applicationDirPath() + "/portable.dat");
|
||||
QString result(QString("Install Mode: ") + (isPortable ? "Portable" : "Standard"));
|
||||
return result;
|
||||
}
|
||||
66
cockatrice/src/utility/logger.h
Normal file
66
cockatrice/src/utility/logger.h
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
#ifndef LOGGER_H
|
||||
#define LOGGER_H
|
||||
|
||||
#include <QFile>
|
||||
#include <QMutex>
|
||||
#include <QString>
|
||||
#include <QTextStream>
|
||||
#include <QVector>
|
||||
|
||||
#if defined(Q_PROCESSOR_X86_32)
|
||||
#define BUILD_ARCHITECTURE "32-bit"
|
||||
#elif defined(Q_PROCESSOR_X86_64)
|
||||
#define BUILD_ARCHITECTURE "64-bit"
|
||||
#elif defined(Q_PROCESSOR_ARM)
|
||||
#define BUILD_ARCHITECTURE "ARM"
|
||||
#else
|
||||
#define BUILD_ARCHITECTURE "unknown"
|
||||
#endif
|
||||
|
||||
class Logger : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static Logger &getInstance()
|
||||
{
|
||||
static Logger instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void logToFile(bool enabled);
|
||||
void log(QtMsgType type, const QMessageLogContext &ctx, QString message);
|
||||
QString getClientVersion();
|
||||
QString getClientOperatingSystem();
|
||||
QString getSystemArchitecture();
|
||||
QString getSystemLocale();
|
||||
QString getClientInstallInfo();
|
||||
QList<QString> getLogBuffer()
|
||||
{
|
||||
return logBuffer;
|
||||
}
|
||||
|
||||
private:
|
||||
Logger();
|
||||
~Logger() override;
|
||||
// Singleton - Don't implement copy constructor and assign operator
|
||||
Logger(Logger const &);
|
||||
void operator=(Logger const &);
|
||||
|
||||
bool logToFileEnabled;
|
||||
QTextStream fileStream;
|
||||
QFile fileHandle;
|
||||
QList<QString> logBuffer;
|
||||
QMutex mutex;
|
||||
|
||||
protected:
|
||||
void openLogfileSession();
|
||||
void closeLogfileSession();
|
||||
|
||||
protected slots:
|
||||
void internalLog(QString message);
|
||||
|
||||
signals:
|
||||
void logEntryAdded(QString message);
|
||||
};
|
||||
|
||||
#endif
|
||||
195
cockatrice/src/utility/sequence_edit.cpp
Normal file
195
cockatrice/src/utility/sequence_edit.cpp
Normal file
|
|
@ -0,0 +1,195 @@
|
|||
#include "sequence_edit.h"
|
||||
|
||||
#include "../settings/cache_settings.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QKeyEvent>
|
||||
#include <QToolTip>
|
||||
#include <utility>
|
||||
|
||||
SequenceEdit::SequenceEdit(const QString &_shortcutName, QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
lineEdit = new QLineEdit(this);
|
||||
clearButton = new QPushButton("", this);
|
||||
defaultButton = new QPushButton("", this);
|
||||
|
||||
lineEdit->setMinimumWidth(70);
|
||||
clearButton->setIcon(QPixmap("theme:icons/clearsearch"));
|
||||
defaultButton->setIcon(QPixmap("theme:icons/update"));
|
||||
|
||||
auto *layout = new QHBoxLayout(this);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setSpacing(1);
|
||||
layout->addWidget(lineEdit);
|
||||
layout->addWidget(clearButton);
|
||||
layout->addWidget(defaultButton);
|
||||
|
||||
connect(clearButton, SIGNAL(clicked()), this, SLOT(removeLastShortcut()));
|
||||
connect(defaultButton, SIGNAL(clicked()), this, SLOT(restoreDefault()));
|
||||
lineEdit->installEventFilter(this);
|
||||
|
||||
setShortcutName(_shortcutName);
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void SequenceEdit::setShortcutName(const QString &_shortcutName)
|
||||
{
|
||||
shortcutName = _shortcutName;
|
||||
if (shortcutName.isEmpty()) {
|
||||
clearButton->setEnabled(false);
|
||||
defaultButton->setEnabled(false);
|
||||
lineEdit->setEnabled(false);
|
||||
lineEdit->setText("");
|
||||
lineEdit->setPlaceholderText(tr("Choose an action from the table"));
|
||||
} else {
|
||||
clearButton->setEnabled(true);
|
||||
defaultButton->setEnabled(true);
|
||||
lineEdit->setEnabled(true);
|
||||
lineEdit->setText(SettingsCache::instance().shortcuts().getShortcutString(shortcutName));
|
||||
lineEdit->setPlaceholderText(tr("Hit the key/combination of keys you want to set for this action"));
|
||||
}
|
||||
}
|
||||
|
||||
QString SequenceEdit::getSequence()
|
||||
{
|
||||
return lineEdit->text();
|
||||
}
|
||||
|
||||
void SequenceEdit::removeLastShortcut()
|
||||
{
|
||||
QString sequences = lineEdit->text();
|
||||
if (!sequences.isEmpty()) {
|
||||
if (sequences.lastIndexOf(";") > 0) {
|
||||
QString validText = sequences.left(sequences.lastIndexOf(";"));
|
||||
lineEdit->setText(validText);
|
||||
} else {
|
||||
lineEdit->clear();
|
||||
}
|
||||
|
||||
updateSettings();
|
||||
}
|
||||
}
|
||||
|
||||
void SequenceEdit::restoreDefault()
|
||||
{
|
||||
lineEdit->setText(SettingsCache::instance().shortcuts().getDefaultShortcutString(shortcutName));
|
||||
updateSettings();
|
||||
}
|
||||
|
||||
void SequenceEdit::refreshShortcut()
|
||||
{
|
||||
lineEdit->setText(SettingsCache::instance().shortcuts().getShortcutString(shortcutName));
|
||||
}
|
||||
|
||||
void SequenceEdit::clear()
|
||||
{
|
||||
lineEdit->setText("");
|
||||
}
|
||||
|
||||
bool SequenceEdit::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
|
||||
auto *keyEvent = reinterpret_cast<QKeyEvent *>(event);
|
||||
|
||||
// don't filter outside arrow key events
|
||||
if (obj != lineEdit) {
|
||||
switch (keyEvent->key()) {
|
||||
case Qt::Key_Up:
|
||||
case Qt::Key_Down:
|
||||
case Qt::Key_Left:
|
||||
case Qt::Key_Right:
|
||||
return false;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (event->type() == QEvent::KeyPress && !keyEvent->isAutoRepeat()) {
|
||||
processKey(keyEvent);
|
||||
} else if (event->type() == QEvent::KeyRelease && !keyEvent->isAutoRepeat()) {
|
||||
finishShortcut();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void SequenceEdit::processKey(QKeyEvent *e)
|
||||
{
|
||||
int key = e->key();
|
||||
if (key != Qt::Key_Control && key != Qt::Key_Shift && key != Qt::Key_Meta && key != Qt::Key_Alt) {
|
||||
valid = true;
|
||||
key |= translateModifiers(e->modifiers(), e->text());
|
||||
}
|
||||
|
||||
keys = key;
|
||||
currentKey++;
|
||||
if (currentKey >= key) {
|
||||
finishShortcut();
|
||||
}
|
||||
}
|
||||
|
||||
int SequenceEdit::translateModifiers(Qt::KeyboardModifiers state, const QString &text)
|
||||
{
|
||||
int result = 0;
|
||||
// The shift modifier only counts when it is not used to type a symbol
|
||||
// that is only reachable using the shift key anyway
|
||||
if ((state & Qt::ShiftModifier) &&
|
||||
(text.isEmpty() || !text.at(0).isPrint() || text.at(0).isLetterOrNumber() || text.at(0).isSpace())) {
|
||||
result |= Qt::SHIFT;
|
||||
}
|
||||
|
||||
if (state & Qt::ControlModifier) {
|
||||
result |= Qt::CTRL;
|
||||
}
|
||||
|
||||
if (state & Qt::MetaModifier) {
|
||||
result |= Qt::META;
|
||||
}
|
||||
|
||||
if (state & Qt::AltModifier) {
|
||||
result |= Qt::ALT;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void SequenceEdit::finishShortcut()
|
||||
{
|
||||
QKeySequence sequence(keys);
|
||||
if (!sequence.isEmpty() && valid) {
|
||||
QString sequenceString = sequence.toString();
|
||||
if (SettingsCache::instance().shortcuts().isKeyAllowed(shortcutName, sequenceString)) {
|
||||
if (SettingsCache::instance().shortcuts().isValid(shortcutName, sequenceString)) {
|
||||
if (!lineEdit->text().isEmpty()) {
|
||||
if (lineEdit->text().contains(sequenceString)) {
|
||||
return;
|
||||
}
|
||||
lineEdit->setText(lineEdit->text() + ";");
|
||||
}
|
||||
lineEdit->setText(lineEdit->text() + sequenceString);
|
||||
} else {
|
||||
QToolTip::showText(lineEdit->mapToGlobal(QPoint()), tr("Shortcut already in use"));
|
||||
}
|
||||
} else {
|
||||
QToolTip::showText(lineEdit->mapToGlobal(QPoint()), tr("Invalid key"));
|
||||
}
|
||||
}
|
||||
|
||||
currentKey = 0;
|
||||
keys = 0;
|
||||
valid = false;
|
||||
updateSettings();
|
||||
}
|
||||
|
||||
void SequenceEdit::updateSettings()
|
||||
{
|
||||
SettingsCache::instance().shortcuts().setShortcuts(shortcutName, lineEdit->text());
|
||||
}
|
||||
|
||||
void SequenceEdit::retranslateUi()
|
||||
{
|
||||
clearButton->setText(tr("Clear"));
|
||||
defaultButton->setText(tr("Restore default"));
|
||||
setShortcutName(shortcutName);
|
||||
}
|
||||
43
cockatrice/src/utility/sequence_edit.h
Normal file
43
cockatrice/src/utility/sequence_edit.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#ifndef SEQUENCEEDIT_H
|
||||
#define SEQUENCEEDIT_H
|
||||
|
||||
#include <QEvent>
|
||||
#include <QKeySequence>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QWidget>
|
||||
|
||||
class SequenceEdit : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SequenceEdit(const QString &_shortcutName, QWidget *parent = nullptr);
|
||||
QString getSequence();
|
||||
void setShortcutName(const QString &_shortcutName);
|
||||
void refreshShortcut();
|
||||
void clear();
|
||||
void retranslateUi();
|
||||
|
||||
private slots:
|
||||
void removeLastShortcut();
|
||||
void restoreDefault();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *, QEvent *event);
|
||||
|
||||
private:
|
||||
QString shortcutName;
|
||||
QLineEdit *lineEdit;
|
||||
QPushButton *clearButton;
|
||||
QPushButton *defaultButton;
|
||||
int keys = 0;
|
||||
int currentKey = 0;
|
||||
bool valid = false;
|
||||
|
||||
void processKey(QKeyEvent *e);
|
||||
int translateModifiers(Qt::KeyboardModifiers state, const QString &text);
|
||||
void finishShortcut();
|
||||
void updateSettings();
|
||||
};
|
||||
|
||||
#endif // SEQUENCEEDIT_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue