Skip to content

Commit fafed1d

Browse files
committed
Implement ability to collect extended logs
+ changed default logs location to Documents -> starc -> logs
1 parent a6f0b86 commit fafed1d

File tree

9 files changed

+161
-22
lines changed

9 files changed

+161
-22
lines changed

src/core/management_layer/application_manager.cpp

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ class ApplicationManager::Implementation
114114
explicit Implementation(ApplicationManager* _q);
115115
~Implementation();
116116

117+
/**
118+
* @brief Настроить логгирование
119+
*/
120+
void initLogging();
121+
117122
/**
118123
* @brief Настроить док-меню
119124
*/
@@ -447,6 +452,33 @@ ApplicationManager::Implementation::~Implementation()
447452
}
448453
}
449454

455+
void ApplicationManager::Implementation::initLogging()
456+
{
457+
const auto logFilePath
458+
= QString("%1/starc/logs/%2.log")
459+
.arg(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation),
460+
PlatformHelper::systemSavebleFileName(
461+
QDateTime::currentDateTime().toString(Qt::ISODateWithMs)));
462+
const auto loggingLevel =
463+
#if defined(QT_DEBUG) || (defined(DEV_BUILD) && DEV_BUILD > 0)
464+
Log::Level::Trace;
465+
#else
466+
static_cast<Log::Level>(
467+
settingsValue(DataStorageLayer::kApplicationLoggingLevelKey).toInt());
468+
#endif
469+
Log::init(loggingLevel, logFilePath);
470+
471+
QString applicationVersion = "0.8.1";
472+
#if defined(DEV_BUILD) && DEV_BUILD > 0
473+
applicationVersion += QString(" dev %1").arg(DEV_BUILD);
474+
#endif
475+
QApplication::setApplicationVersion(applicationVersion);
476+
477+
Log::info("%1 version %2, %3, %4", QApplication::applicationName(),
478+
QApplication::applicationVersion(), QSysInfo().prettyProductName(),
479+
QSysInfo().currentCpuArchitecture());
480+
}
481+
450482
void ApplicationManager::Implementation::initDockMenu()
451483
{
452484
#ifdef Q_OS_MAC
@@ -2312,28 +2344,7 @@ ApplicationManager::ApplicationManager(QObject* _parent)
23122344
//
23132345
// Первым делом настраиваем сбор логов
23142346
//
2315-
const auto logFilePath
2316-
= QString("%1/logs/%2.log")
2317-
.arg(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation),
2318-
PlatformHelper::systemSavebleFileName(
2319-
QDateTime::currentDateTime().toString(Qt::ISODateWithMs)));
2320-
const auto loggingLevel =
2321-
#if defined(QT_DEBUG) || (defined(DEV_BUILD) && DEV_BUILD > 0)
2322-
Log::Level::Trace;
2323-
#else
2324-
Log::Level::Debug;
2325-
#endif
2326-
Log::init(loggingLevel, logFilePath);
2327-
2328-
QString applicationVersion = "0.8.1";
2329-
#if defined(DEV_BUILD) && DEV_BUILD > 0
2330-
applicationVersion += QString(" dev %1").arg(DEV_BUILD);
2331-
#endif
2332-
QApplication::setApplicationVersion(applicationVersion);
2333-
2334-
Log::info("%1 version %2, %3, %4", QApplication::applicationName(),
2335-
QApplication::applicationVersion(), QSysInfo().prettyProductName(),
2336-
QSysInfo().currentCpuArchitecture());
2347+
d->initLogging();
23372348

23382349
QApplication::setStyle(new ApplicationStyle(QStyleFactory::create("Fusion")));
23392350

@@ -3022,6 +3033,9 @@ void ApplicationManager::initConnections()
30223033
connect(d->settingsManager.data(), &SettingsManager::novelNavigatorChanged, this,
30233034
[this] { d->projectManager->reconfigureNovelNavigator(); });
30243035
//
3036+
connect(d->settingsManager.data(), &SettingsManager::advancedUseExtendingLoggingChanged, this,
3037+
[this] { d->initLogging(); });
3038+
//
30253039
connect(d->settingsManager.data(), &SettingsManager::resetToDefaultsRequested, this, [this] {
30263040
//
30273041
// Если пользователь хочет сбросить все настройки, закроем текущий проект

src/core/management_layer/content/settings/settings_manager.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <utils/helpers/dialog_helper.h>
2727
#include <utils/helpers/extension_helper.h>
2828
#include <utils/helpers/shortcuts_helper.h>
29+
#include <utils/logging.h>
2930

3031
#include <QApplication>
3132
#include <QDir>
@@ -82,6 +83,14 @@ class SettingsManager::Implementation
8283
void loadShortcutsForStageplaySettings();
8384
void loadShortcutsForNovelSettings();
8485

86+
/**
87+
* @brief Загрузить дополнительные параметры
88+
*/
89+
void loadAdvancedSettings();
90+
91+
/**
92+
* @brief Перезагрузкить все настройки
93+
*/
8594
void reloadSettings();
8695

8796

@@ -877,11 +886,19 @@ void SettingsManager::Implementation::loadShortcutsForNovelSettings()
877886
view->setShortcutsForNovelModel(model);
878887
}
879888

889+
void SettingsManager::Implementation::loadAdvancedSettings()
890+
{
891+
view->setAdvancedUseExtendedLogging(
892+
settingsValue(DataStorageLayer::kApplicationLoggingLevelKey).toInt()
893+
== static_cast<int>(Log::Level::Trace));
894+
}
895+
880896
void SettingsManager::Implementation::reloadSettings()
881897
{
882898
loadApplicationSettings();
883899
loadComponentsSettings();
884900
loadShortcutsSettings();
901+
loadAdvancedSettings();
885902
}
886903

887904

@@ -926,6 +943,8 @@ SettingsManager::SettingsManager(QObject* _parent, QWidget* _parentWidget,
926943
&Ui::SettingsView::showComponentsNovel);
927944
connect(d->navigator, &Ui::SettingsNavigator::shortcutsPressed, d->view,
928945
&Ui::SettingsView::showShortcuts);
946+
connect(d->navigator, &Ui::SettingsNavigator::advancedPressed, d->view,
947+
&Ui::SettingsView::showAdvanced);
929948
connect(d->navigator, &Ui::SettingsNavigator::resetToDefaultsPressed, this, [this] {
930949
auto dialog = new Dialog(d->view->topLevelWidget());
931950
const int kCancelButtonId = 0;
@@ -1643,6 +1662,12 @@ SettingsManager::SettingsManager(QObject* _parent, QWidget* _parentWidget,
16431662
&SettingsManager::setShortcutsForStageplayEdit);
16441663
connect(d->view, &Ui::SettingsView::shortcutsForNovelEditorChanged, this,
16451664
&SettingsManager::setShortcutsForNovelEdit);
1665+
1666+
//
1667+
// Дополнительные параметры
1668+
//
1669+
connect(d->view, &Ui::SettingsView::advancedUseExtendedLoggingChanged, this,
1670+
&SettingsManager::setAdvancedUseExtendedLogging);
16461671
}
16471672

16481673
SettingsManager::~SettingsManager() = default;
@@ -2637,4 +2662,11 @@ void SettingsManager::setShortcutsForNovelEdit(const QString& _blockType, const
26372662
emit novelEditorChanged({ DataStorageLayer::kComponentsNovelEditorShortcutsKey });
26382663
}
26392664

2665+
void SettingsManager::setAdvancedUseExtendedLogging(bool _use)
2666+
{
2667+
setSettingsValue(DataStorageLayer::kApplicationLoggingLevelKey,
2668+
static_cast<int>(_use ? Log::Level::Trace : Log::Level::Debug));
2669+
emit advancedUseExtendingLoggingChanged(_use);
2670+
}
2671+
26402672
} // namespace ManagementLayer

src/core/management_layer/content/settings/settings_manager.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ class SettingsManager : public QObject
9090
void novelEditorChanged(const QStringList& _changedSettingsKeys);
9191
void novelNavigatorChanged();
9292

93+
/**
94+
* @brief Изменились расширенные параметры приложения
95+
*/
96+
void advancedUseExtendingLoggingChanged(bool _use);
97+
9398
/**
9499
* @brief Пользователь хочет сбросить настройки к заводским
95100
*/
@@ -250,6 +255,11 @@ class SettingsManager : public QObject
250255
const QString& _jumpByTab, const QString& _jumpByEnter,
251256
const QString& _changeByTab, const QString& _changeByEnter);
252257

258+
//
259+
// Сохранение расширенных параметров
260+
//
261+
void setAdvancedUseExtendedLogging(bool _use);
262+
253263
private:
254264
class Implementation;
255265
QScopedPointer<Implementation> d;

src/core/ui/settings/settings_navigator.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ constexpr int kComponentsAudioplayIndex = 3;
2525
constexpr int kComponentsStageplayIndex = 4;
2626
constexpr int kComponentsNovelIndex = 5;
2727
constexpr int kShortcutsIndex = 2;
28+
constexpr int kAdvancedIndex = 3;
2829
} // namespace
2930

3031

@@ -65,6 +66,7 @@ SettingsNavigator::Implementation::Implementation(QWidget* _parent)
6566
componentsItem->appendRow(createItem(u8"\U000F05DA"));
6667
model->appendRow(componentsItem);
6768
model->appendRow(createItem(u8"\U000f030c"));
69+
model->appendRow(createItem(u8"\U000F066A"));
6870
tree->setModel(model);
6971
tree->setCurrentIndex(model->index(0, 0));
7072
tree->expandAll();
@@ -166,6 +168,10 @@ SettingsNavigator::SettingsNavigator(QWidget* _parent)
166168
emit shortcutsPressed();
167169
break;
168170
}
171+
case kAdvancedIndex: {
172+
emit advancedPressed();
173+
break;
174+
}
169175
default: {
170176
break;
171177
}
@@ -208,6 +214,7 @@ void SettingsNavigator::updateTranslations()
208214
model->item(kComponentsIndex)->child(kComponentsStageplayIndex)->setText(tr("Stageplay"));
209215
model->item(kComponentsIndex)->child(kComponentsNovelIndex)->setText(tr("Novel"));
210216
model->item(kShortcutsIndex)->setText(tr("Shortcuts"));
217+
model->item(kAdvancedIndex)->setText(tr("Advanced"));
211218

212219
d->resetToDefaults->setText(tr("Reset to defaults"));
213220
}

src/core/ui/settings/settings_navigator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class SettingsNavigator : public StackWidget
3838
void componentsStageplayPressed();
3939
void componentsNovelPressed();
4040
void shortcutsPressed();
41+
void advancedPressed();
4142

4243
/**
4344
* @brief Пользователь хочет сбросить настройки до заводских

src/core/ui/settings/settings_view.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ class SettingsView::Implementation
255255
*/
256256
void initShortcutsCard();
257257

258+
/**
259+
* @brief Настроить карточку экспериментальных опций
260+
*/
261+
void initAdvancedCard();
262+
258263
/**
259264
* @brief Проскролить представление до заданного виджета
260265
*/
@@ -635,6 +640,14 @@ class SettingsView::Implementation
635640
ComboBoxItemDelegate* novelParagraphChangeTypeDelegate = nullptr;
636641
//
637642
int shortcutsCardBottomSpacerIndex = 0;
643+
644+
//
645+
// Advanced options
646+
//
647+
Card* advancedCard = nullptr;
648+
QGridLayout* advancedCardLayout = nullptr;
649+
H5Label* advancedTitle = nullptr;
650+
CheckBox* advancedUseExtendedLogging = nullptr;
638651
};
639652

640653
SettingsView::Implementation::Implementation(QWidget* _parent)
@@ -897,6 +910,11 @@ SettingsView::Implementation::Implementation(QWidget* _parent)
897910
new ComboBoxItemDelegate(shortcutsForNovel, novelParagraphTypesModel))
898911
, novelParagraphChangeTypeDelegate(
899912
new ComboBoxItemDelegate(shortcutsForNovel, novelParagraphTypesModel))
913+
//
914+
, advancedCard(new Card(content))
915+
, advancedCardLayout(new QGridLayout)
916+
, advancedTitle(new H5Label(advancedCard))
917+
, advancedUseExtendedLogging(new CheckBox(advancedCard))
900918
{
901919
scrollAnimation.setEasingCurve(QEasingCurve::OutQuad);
902920
scrollAnimation.setDuration(180);
@@ -911,6 +929,7 @@ SettingsView::Implementation::Implementation(QWidget* _parent)
911929
initStageplayCard();
912930
initNovelCard();
913931
initShortcutsCard();
932+
initAdvancedCard();
914933

915934
auto layout = qobject_cast<QVBoxLayout*>(content->widget()->layout());
916935
layout->addWidget(applicationCard);
@@ -922,6 +941,7 @@ SettingsView::Implementation::Implementation(QWidget* _parent)
922941
layout->addWidget(stageplayCard);
923942
layout->addWidget(novelCard);
924943
layout->addWidget(shortcutsCard);
944+
layout->addWidget(advancedCard);
925945
layout->addStretch();
926946
}
927947

@@ -1660,6 +1680,20 @@ void SettingsView::Implementation::initShortcutsCard()
16601680
shortcutsCard->setContentLayout(shortcutsCardLayout);
16611681
}
16621682

1683+
void SettingsView::Implementation::initAdvancedCard()
1684+
{
1685+
//
1686+
// Компоновка
1687+
//
1688+
applicationCardLayout->setContentsMargins({});
1689+
applicationCardLayout->setSpacing(0);
1690+
int itemIndex = 0;
1691+
advancedCardLayout->addWidget(advancedTitle, itemIndex++, 0);
1692+
advancedCardLayout->addWidget(advancedUseExtendedLogging, itemIndex++, 0);
1693+
//
1694+
advancedCard->setContentLayout(advancedCardLayout);
1695+
}
1696+
16631697
void SettingsView::Implementation::scrollToTitle(AbstractLabel* title)
16641698
{
16651699
const QRect microFocus = title->inputMethodQuery(Qt::ImCursorRectangle).toRect();
@@ -2978,6 +3012,12 @@ SettingsView::SettingsView(QWidget* _parent)
29783012
//
29793013
// Соединения шорткатов настраиваются в момент установки моделей с данными о них в представление
29803014
//
3015+
3016+
//
3017+
// Соединения дополнительных параметров
3018+
//
3019+
connect(d->advancedUseExtendedLogging, &CheckBox::checkedChanged, this,
3020+
&SettingsView::advancedUseExtendedLoggingChanged);
29813021
}
29823022

29833023
void SettingsView::showDefaultPage()
@@ -3050,6 +3090,11 @@ void SettingsView::showShortcuts()
30503090
d->scrollToTitle(d->shortcutsTitle);
30513091
}
30523092

3093+
void SettingsView::showAdvanced()
3094+
{
3095+
d->scrollToTitle(d->advancedTitle);
3096+
}
3097+
30533098
void SettingsView::setApplicationLanguage(int _language)
30543099
{
30553100
auto languageString = [_language]() -> QString {
@@ -4018,6 +4063,11 @@ void SettingsView::setShortcutsForNovelModel(HierarchicalModel* _model)
40184063
});
40194064
}
40204065

4066+
void SettingsView::setAdvancedUseExtendedLogging(bool _use)
4067+
{
4068+
d->advancedUseExtendedLogging->setChecked(_use);
4069+
}
4070+
40214071
void SettingsView::resizeEvent(QResizeEvent* _event)
40224072
{
40234073
StackWidget::resizeEvent(_event);
@@ -4447,6 +4497,9 @@ void SettingsView::updateTranslations()
44474497
buildNovelParagraphTypesModel(d->shortcutsForNovel, d->novelParagraphTypesModel);
44484498
d->novelParagraphAddTypeDelegate->setLabel(tr("Add paragraph"));
44494499
d->novelParagraphChangeTypeDelegate->setLabel(tr("Change to"));
4500+
//
4501+
d->advancedTitle->setText(tr("Advanced settings"));
4502+
d->advancedUseExtendedLogging->setText(tr("Collect extended logs"));
44504503
}
44514504

44524505
SettingsView::~SettingsView() = default;
@@ -4478,6 +4531,7 @@ void SettingsView::designSystemChangeEvent(DesignSystemChangeEvent* _event)
44784531
d->stageplayCard,
44794532
d->novelCard,
44804533
d->shortcutsCard,
4534+
d->advancedCard,
44814535
}) {
44824536
card->setBackgroundColor(DesignSystem::color().background());
44834537
}
@@ -4521,6 +4575,7 @@ void SettingsView::designSystemChangeEvent(DesignSystemChangeEvent* _event)
45214575
d->shortcutsForAudioplayTitle,
45224576
d->shortcutsForStageplayTitle,
45234577
d->shortcutsForNovelTitle,
4578+
d->advancedTitle,
45244579
}) {
45254580
cardTitle->setBackgroundColor(DesignSystem::color().background());
45264581
cardTitle->setTextColor(titleColor);
@@ -4658,6 +4713,8 @@ void SettingsView::designSystemChangeEvent(DesignSystemChangeEvent* _event)
46584713
//
46594714
d->novelNavigatorShowSceneText,
46604715
d->novelNavigatorCounterType,
4716+
//
4717+
d->advancedUseExtendedLogging,
46614718
}) {
46624719
checkBox->setBackgroundColor(DesignSystem::color().background());
46634720
checkBox->setTextColor(DesignSystem::color().onBackground());

0 commit comments

Comments
 (0)