Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:add an option to enable log through the preference #2097

Merged
merged 9 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 4 additions & 41 deletions locale/crowdin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,25 +345,6 @@ between classic and school orthography in cyrillic)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Dialog</name>
<message>
<source>Proxy authentication required</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>You need to supply a Username and a Password to access via proxy</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Username:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Password:</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DictGroupWidget</name>
<message>
Expand Down Expand Up @@ -3525,6 +3506,10 @@ from Stardict, Babylon and GLS dictionaries</source>
<source>Automatic</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enable application log</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ProgramTypeEditor</name>
Expand Down Expand Up @@ -3998,28 +3983,6 @@ based on English phonology</source>
<source>Hepburn</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>The most regular system, having a one-to-one relation to the
kana writing systems. Standardized as ISO 3602

Not implemented yet in GoldenDict.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Nihon-shiki</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Based on Nihon-shiki system, but modified for modern standard Japanese.
Standardized as ISO 3602

Not implemented yet in GoldenDict.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Kunrei-shiki</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Syllabaries:</source>
<translation type="unfinished"></translation>
Expand Down
9 changes: 9 additions & 0 deletions src/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,11 @@ Class load()
( preferences.namedItem( "removeInvalidIndexOnExit" ).toElement().text() == "1" );
}

if ( !preferences.namedItem( "enableApplicationLog" ).isNull() ) {
c.preferences.enableApplicationLog =
( preferences.namedItem( "enableApplicationLog" ).toElement().text() == "1" );
}

if ( !preferences.namedItem( "maxStringsInHistory" ).isNull() ) {
c.preferences.maxStringsInHistory = preferences.namedItem( "maxStringsInHistory" ).toElement().text().toUInt();
}
Expand Down Expand Up @@ -2021,6 +2026,10 @@ void save( Class const & c )
opt.appendChild( dd.createTextNode( c.preferences.removeInvalidIndexOnExit ? "1" : "0" ) );
preferences.appendChild( opt );

opt = dd.createElement( "enableApplicationLog" );
opt.appendChild( dd.createTextNode( c.preferences.enableApplicationLog ? "1" : "0" ) );
preferences.appendChild( opt );

opt = dd.createElement( "maxStringsInHistory" );
opt.appendChild( dd.createTextNode( QString::number( c.preferences.maxStringsInHistory ) ) );
preferences.appendChild( opt );
Expand Down
1 change: 1 addition & 0 deletions src/config.hh
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ struct Preferences
int maxNetworkCacheSize;
bool clearNetworkCacheOnExit;
bool removeInvalidIndexOnExit = false;
bool enableApplicationLog = false;

qreal zoomFactor;
qreal helpZoomFactor;
Expand Down
29 changes: 17 additions & 12 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ QMutex logMutex;

void gdMessageHandler( QtMsgType type, const QMessageLogContext & context, const QString & mess )
{
if ( GlobalBroadcaster::instance()->getPreference() == nullptr
|| !GlobalBroadcaster::instance()->getPreference()->enableApplicationLog ) {
return;
}
QString strTime = QDateTime::currentDateTime().toString( "MM-dd hh:mm:ss" );
QString message = QString( "%1 %2\r\n" ).arg( strTime, mess );

Expand Down Expand Up @@ -488,6 +492,9 @@ int main( int argc, char ** argv )
for ( ;; ) {
try {
cfg = Config::load();

//enabled through command line or preference
gdcl.logFile = gdcl.logFile || cfg.preferences.enableApplicationLog;
}
catch ( Config::exError & ) {
QMessageBox mb(
Expand Down Expand Up @@ -519,20 +526,18 @@ int main( int argc, char ** argv )

cfg.resetState = gdcl.resetState;

if ( gdcl.needLogFile() ) {
// Open log file
logFilePtr->setFileName( Config::getConfigDir() + "gd_log.txt" );
logFilePtr->remove();
logFilePtr->open( QFile::ReadWrite );
// Open log file
logFilePtr->setFileName( Config::getConfigDir() + "gd_log.txt" );
logFilePtr->remove();
logFilePtr->open( QFile::ReadWrite );
xiaoyifang marked this conversation as resolved.
Show resolved Hide resolved

// Write UTF-8 BOM
QByteArray line;
line.append( 0xEF ).append( 0xBB ).append( 0xBF );
logFilePtr->write( line );
// Write UTF-8 BOM
QByteArray line;
line.append( 0xEF ).append( 0xBB ).append( 0xBF );
logFilePtr->write( line );
xiaoyifang marked this conversation as resolved.
Show resolved Hide resolved

// Install message handler
qInstallMessageHandler( gdMessageHandler );
}
// Install message handler
qInstallMessageHandler( gdMessageHandler );

// Reload translations for user selected locale is nesessary
QTranslator qtTranslator;
Expand Down
2 changes: 2 additions & 0 deletions src/ui/preferences.cc
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):

//Misc
ui.removeInvalidIndexOnExit->setChecked( p.removeInvalidIndexOnExit );
ui.enableApplicationLog->setChecked( p.enableApplicationLog );

// Add-on styles
ui.addonStylesLabel->setVisible( ui.addonStyles->count() > 1 );
Expand Down Expand Up @@ -526,6 +527,7 @@ Config::Preferences Preferences::getPreferences()
p.clearNetworkCacheOnExit = ui.clearNetworkCacheOnExit->isChecked();

p.removeInvalidIndexOnExit = ui.removeInvalidIndexOnExit->isChecked();
p.enableApplicationLog = ui.enableApplicationLog->isChecked();

p.addonStyle = ui.addonStyles->getCurrentStyle();

Expand Down
7 changes: 7 additions & 0 deletions src/ui/preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1935,6 +1935,13 @@ from Stardict, Babylon and GLS dictionaries</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="enableApplicationLog">
<property name="text">
<string>Enable application log</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
Loading