Implement "goldendict://nice" url scheme handler for windows and linux (#227)

* windows: add url scheme goldendict://

* linux: add url scheme goldendict:// handler
This commit is contained in:
shenlebantongying 2022-11-27 20:24:49 -05:00 committed by GitHub
parent 53d443357b
commit 5a284d5c66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 1 deletions

View file

@ -183,6 +183,14 @@ logFile( false )
}
else
word = arguments[ i ];
#if defined(Q_OS_LINUX) || defined (Q_OS_WIN)
// handle url scheme like "goldendict://" on windows
word.remove("goldendict://");
// In microsoft Words, the / will be automatically appended
if(word.endsWith("/")){
word.chop(1);
}
#endif
}
}
}

View file

@ -912,6 +912,21 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
inspector.reset( new ArticleInspector( this ));
connect( QApplication::clipboard(), &QClipboard::changed, this, &MainWindow::clipboardChange );
#ifdef Q_OS_WIN
// Regiser and update URL Scheme for windows
// https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa767914(v=vs.85)
// Windows will automatically map registry key to Computer\HKEY_CLASSES_ROOT\ */
QSettings urlRegistry(R"(HKEY_CURRENT_USER\Software\Classes)", QSettings::NativeFormat);
urlRegistry.beginGroup("goldendict");
urlRegistry.setValue("Default", "URL: goldendict Protocol");
urlRegistry.setValue("URL Protocol", "");
urlRegistry.setValue("shell/open/command/Default",
QString("\"%1\"").arg( QDir::toNativeSeparators(QApplication::applicationFilePath())) + " \"%1\"");
urlRegistry.endGroup();
#endif
}
void MainWindow::clipboardChange( QClipboard::Mode m)

View file

@ -6,4 +6,5 @@ Name=GoldenDict
GenericName=Multiformat Dictionary
Comment=A feature-rich dictionary lookup program
Icon=goldendict
Exec=goldendict
Exec=goldendict %u
MimeType=x-scheme-handler/goldendict