mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
opt: add translation windows when invoked from console (#1173)
* opt: add an extra console argument to specify the translation windows * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes (attempt 2/3) --------- Co-authored-by: YiFang Xiao <yifang.xiao@noreply.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
3b70c29f01
commit
ef6e878a31
24
src/main.cc
24
src/main.cc
|
@ -148,6 +148,7 @@ struct GDOptions
|
|||
bool logFile = false;
|
||||
bool togglePopup = false;
|
||||
QString word, groupName, popupGroupName;
|
||||
QString window;
|
||||
|
||||
inline bool needSetGroup() const
|
||||
{
|
||||
|
@ -220,6 +221,14 @@ void processCommandLine( QCoreApplication * app, GDOptions * result )
|
|||
QObject::tr( "Change the group of popup." ),
|
||||
"popupGroupName" );
|
||||
|
||||
QCommandLineOption window_popupOption( QStringList() << "s"
|
||||
<< "scanpopup",
|
||||
QObject::tr( "Force the word to be translated in scanpopup" ) );
|
||||
|
||||
QCommandLineOption window_mainWindowOption( QStringList() << "m"
|
||||
<< "main-window",
|
||||
QObject::tr( "Force the word to be translated in the mainwindow" ) );
|
||||
|
||||
QCommandLineOption togglePopupOption( QStringList() << "t"
|
||||
<< "toggle-scan-popup",
|
||||
QObject::tr( "Toggle scan popup." ) );
|
||||
|
@ -231,6 +240,8 @@ void processCommandLine( QCoreApplication * app, GDOptions * result )
|
|||
qcmd.addOption( logFileOption );
|
||||
qcmd.addOption( groupNameOption );
|
||||
qcmd.addOption( popupGroupNameOption );
|
||||
qcmd.addOption( window_popupOption );
|
||||
qcmd.addOption( window_mainWindowOption );
|
||||
qcmd.addOption( togglePopupOption );
|
||||
qcmd.addOption( notts );
|
||||
qcmd.addOption( resetState );
|
||||
|
@ -253,7 +264,12 @@ void processCommandLine( QCoreApplication * app, GDOptions * result )
|
|||
if ( qcmd.isSet( popupGroupNameOption ) ) {
|
||||
result->popupGroupName = qcmd.value( popupGroupNameOption );
|
||||
}
|
||||
|
||||
if ( qcmd.isSet( window_popupOption ) ) {
|
||||
result->window = "popup";
|
||||
}
|
||||
if ( qcmd.isSet( window_mainWindowOption ) ) {
|
||||
result->window = "main";
|
||||
}
|
||||
if ( qcmd.isSet( togglePopupOption ) ) {
|
||||
result->togglePopup = true;
|
||||
}
|
||||
|
@ -414,6 +430,7 @@ int main( int argc, char ** argv )
|
|||
if ( app.isRunning() ) {
|
||||
bool wasMessage = false;
|
||||
|
||||
//TODO .all the following messages can be combined into one.
|
||||
if ( gdcl.needSetGroup() ) {
|
||||
app.sendMessage( QString( "setGroup: " ) + gdcl.getGroupName() );
|
||||
wasMessage = true;
|
||||
|
@ -424,6 +441,11 @@ int main( int argc, char ** argv )
|
|||
wasMessage = true;
|
||||
}
|
||||
|
||||
if ( !gdcl.window.isEmpty() ) {
|
||||
app.sendMessage( QString( "window:" ) + gdcl.window );
|
||||
wasMessage = true;
|
||||
}
|
||||
|
||||
if ( gdcl.needTranslateWord() ) {
|
||||
app.sendMessage( QString( "translateWord: " ) + gdcl.wordToTranslate() );
|
||||
wasMessage = true;
|
||||
|
|
|
@ -3548,11 +3548,28 @@ void MainWindow::messageFromAnotherInstanceReceived( QString const & message )
|
|||
return;
|
||||
}
|
||||
|
||||
QString prefix = "window:";
|
||||
if ( message.left( prefix.size() ) == prefix ) {
|
||||
consoleWindowOnce = message.mid( prefix.size() );
|
||||
}
|
||||
|
||||
if ( message.left( 15 ) == "translateWord: " ) {
|
||||
if ( scanPopup )
|
||||
scanPopup->translateWord( message.mid( 15 ) );
|
||||
else
|
||||
wordReceived( message.mid( 15 ) );
|
||||
auto word = message.mid( 15 );
|
||||
if ( ( consoleWindowOnce == "popup" ) && scanPopup ) {
|
||||
scanPopup->translateWord( word );
|
||||
}
|
||||
else if ( consoleWindowOnce == "main" ) {
|
||||
wordReceived( word );
|
||||
}
|
||||
else {
|
||||
//default logic
|
||||
if ( scanPopup && enableScanningAction->isChecked() )
|
||||
scanPopup->translateWord( word );
|
||||
else
|
||||
wordReceived( word );
|
||||
}
|
||||
|
||||
consoleWindowOnce.clear();
|
||||
}
|
||||
else if ( message.left( 10 ) == "setGroup: " ) {
|
||||
setGroupByName( message.mid( 10 ), true );
|
||||
|
|
|
@ -149,6 +149,9 @@ private:
|
|||
|
||||
ScanPopup * scanPopup = nullptr;
|
||||
|
||||
//only used once, when used ,reset to empty.
|
||||
QString consoleWindowOnce;
|
||||
|
||||
sptr< HotkeyWrapper > hotkeyWrapper;
|
||||
|
||||
sptr< QPrinter > printer; // The printer we use for all printing operations
|
||||
|
|
Loading…
Reference in a new issue