Compare commits

..

1 commit

Author SHA1 Message Date
xiaoyifang 4631a59d6f
Merge 15b918eb6a into dcc4579544 2024-11-09 01:36:09 +08:00
28 changed files with 136 additions and 147 deletions

View file

@ -26,7 +26,6 @@ Checks: >
-google-default-arguments,
-google-readability-casting,
-hicpp-deprecated-headers,
-hicpp-no-array-decay,
-misc-const-correctness,
-misc-include-cleaner,
-misc-non-private-member-variables-in-classes,

View file

@ -1,79 +1,79 @@
issue: https://github.com/goldendict/goldendict/issues/1441
http://tango.freedesktop.org/Tango_Desktop_Project GPLv3
list:
internet.svg
home.svg
configure.svg
fileopen.svg
addtab.svg
wizard.svg
fulltext
text2speech
reload
icons/print.svg
icons/programs.svg
error
star.svg
star_blue.svg
network.svg
hotkeys
previous
next
advanced
windows-list
filesave
playsound_color
interface
webdict
transliteration
closetab
folder
reload
menu.svg
https://packages.debian.org/bullseye/gnome-icon-theme GPLv3
lists:
clear
https://commons.wikimedia.org/wiki/File:Accessories-dictionary.svg
lists:
icon32_sdict.svg
https://freesvg.org/pushpin-vector-image public domain
lists:
pushbin
https://commons.wikimedia.org/wiki/File:Arrow_bottom_svg.svg license:public domain
lists:
1downarrow
these two icons from sertoli @ https://forum.freemdict.com/u/sertoli/summary
playsound.png
playsound_full.png
LGPL
icon32_zoombase.png https://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/128/Actions-page-zoom-icon.png
icon32_zoomout.png https://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/128/Actions-zoom-out-icon.png
icon32_zoomin.png https://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/128/Actions-zoom-in-icon.png
reload.png https://iconarchive.com/show/oxygen-icons-by-oxygen-icons.org/Actions-edit-redo-icon.html
advanced.png https://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/128/Actions-system-run-icon.png
sources.png https://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/128/Apps-plasma-icon.png
book.svg https://github.com/johnfactotum/foliate
lingualibre.svg https://en.m.wikipedia.org/wiki/File:Lingualibre-logo-no-text.svg
Apache License Version 2.0
1downarrow.svg
system-search.svg
Modified from https://github.com/google/material-design-icons
add-anki-icon.svg MIT license
issue: https://github.com/goldendict/goldendict/issues/1441
http://tango.freedesktop.org/Tango_Desktop_Project GPLv3
list:
internet.svg
home.svg
configure.svg
fileopen.svg
addtab.svg
wizard.svg
fulltext
text2speech
reload
icons/print.svg
icons/programs.svg
error
star.svg
star_blue.svg
network.svg
hotkeys
previous
next
advanced
windows-list
filesave
playsound_color
interface
webdict
transliteration
closetab
folder
reload
menu.svg
https://packages.debian.org/bullseye/gnome-icon-theme GPLv3
lists:
clear
https://commons.wikimedia.org/wiki/File:Accessories-dictionary.svg
lists:
icon32_sdict.svg
https://freesvg.org/pushpin-vector-image public domain
lists:
pushbin
https://commons.wikimedia.org/wiki/File:Arrow_bottom_svg.svg license:public domain
lists:
1downarrow
these two icons from sertoli @ https://forum.freemdict.com/u/sertoli/summary
playsound.png
playsound_full.png
LGPL
icon32_zoombase.png https://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/128/Actions-page-zoom-icon.png
icon32_zoomout.png https://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/128/Actions-zoom-out-icon.png
icon32_zoomin.png https://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/128/Actions-zoom-in-icon.png
reload.png https://iconarchive.com/show/oxygen-icons-by-oxygen-icons.org/Actions-edit-redo-icon.html
advanced.png https://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/128/Actions-system-run-icon.png
sources.png https://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/128/Apps-plasma-icon.png
book.svg https://github.com/johnfactotum/foliate
lingualibre.svg https://en.m.wikipedia.org/wiki/File:Lingualibre-logo-no-text.svg
Apache License Version 2.0
1downarrow.svg
system-search.svg
Modified from https://github.com/google/material-design-icons
add-anki-icon.svg MIT license
https://www.svgrepo.com/svg/435992/add-card

View file

@ -1,3 +0,0 @@
Code to support GD's internal/external audio players.
Only `audioplayerinterface.hh` is supposed to be used outside this folder.

View file

@ -197,6 +197,9 @@ Preferences::Preferences():
hideSingleTab( false ),
mruTabOrder( false ),
hideMenubar( false ),
enableTrayIcon( true ),
startToTray( false ),
closeToTray( true ),
autoStart( false ),
doubleClickTranslates( true ),
selectWordBySingleClick( false ),
@ -901,11 +904,10 @@ Class load()
c.preferences.hideSingleTab = ( preferences.namedItem( "hideSingleTab" ).toElement().text() == "1" );
c.preferences.mruTabOrder = ( preferences.namedItem( "mruTabOrder" ).toElement().text() == "1" );
c.preferences.hideMenubar = ( preferences.namedItem( "hideMenubar" ).toElement().text() == "1" );
#ifndef Q_OS_MACOS // // macOS uses the dock menu instead of the tray icon
c.preferences.enableTrayIcon = ( preferences.namedItem( "enableTrayIcon" ).toElement().text() == "1" );
c.preferences.startToTray = ( preferences.namedItem( "startToTray" ).toElement().text() == "1" );
c.preferences.closeToTray = ( preferences.namedItem( "closeToTray" ).toElement().text() == "1" );
#endif
c.preferences.autoStart = ( preferences.namedItem( "autoStart" ).toElement().text() == "1" );
c.preferences.alwaysOnTop = ( preferences.namedItem( "alwaysOnTop" ).toElement().text() == "1" );
c.preferences.searchInDock = ( preferences.namedItem( "searchInDock" ).toElement().text() == "1" );

View file

@ -341,17 +341,9 @@ struct Preferences
bool hideSingleTab;
bool mruTabOrder;
bool hideMenubar;
#ifdef Q_OS_MACOS // macOS uses the dock menu instead of the tray icon
bool closeToTray = false;
bool enableTrayIcon = false;
bool startToTray = false;
#else
bool enableTrayIcon = true;
bool closeToTray = true;
bool startToTray = false;
#endif
bool enableTrayIcon;
bool startToTray;
bool closeToTray;
bool autoStart;
bool doubleClickTranslates;
bool selectWordBySingleClick;

View file

@ -264,12 +264,14 @@ bool MdictParser::parseCompressedBlock( qint64 compressedBlockSize,
case 0x02000000:
// zlib compression
decompressedBlock = zlibDecompress( buf, size, checksum );
if ( decompressedBlock.isEmpty() ) {
gdWarning( "MDict: parseCompressedBlock: zlib: failed to decompress or checksum does not match" );
decompressedBlock = zlibDecompress( buf, size );
if ( !checkAdler32( decompressedBlock.constData(), decompressedBlock.size(), checksum ) ) {
gdWarning( "MDict: parseCompressedBlock: zlib: checksum does not match" );
return false;
}
break;
default:
gdWarning( "MDict: parseCompressedBlock: unknown type" );
return false;

View file

@ -3,21 +3,20 @@
#include <bzlib.h>
#include <lzma.h>
using std::string;
#define CHUNK_SIZE 2048
static constexpr qsizetype CHUNK_SIZE = 2048;
QByteArray zlibDecompress( const char * bufptr, unsigned length, uLong adler32_checksum )
QByteArray zlibDecompress( const char * bufptr, unsigned length )
{
z_stream zs{};
z_stream zs;
char buf[ CHUNK_SIZE ];
QByteArray str;
int res = Z_OK;
int res;
memset( &zs, 0, sizeof( zs ) );
zs.next_in = (Bytef *)bufptr;
zs.avail_in = length;
res = inflateInit( &zs );
if ( res == Z_OK ) {
char buf[ CHUNK_SIZE ];
while ( res != Z_STREAM_END ) {
zs.next_out = (Bytef *)buf;
zs.avail_out = CHUNK_SIZE;
@ -28,7 +27,9 @@ QByteArray zlibDecompress( const char * bufptr, unsigned length, uLong adler32_c
}
}
}
if ( inflateEnd( &zs ) != Z_OK || res != Z_STREAM_END || ( adler32_checksum != 0 && zs.adler != adler32_checksum ) ) {
inflateEnd( &zs );
if ( res != Z_STREAM_END ) {
str.clear();
}
return str;
@ -36,7 +37,7 @@ QByteArray zlibDecompress( const char * bufptr, unsigned length, uLong adler32_c
string decompressZlib( const char * bufptr, unsigned length )
{
QByteArray b = zlibDecompress( bufptr, length, 0 );
QByteArray b = zlibDecompress( bufptr, length );
return string( b.constData(), b.size() );
}

View file

@ -3,11 +3,12 @@
#include <QByteArray>
#include <string>
/// @param adler32_checksum 0 to skip checksum
QByteArray zlibDecompress( const char * bufptr, unsigned length, unsigned long adler32_checksum );
using std::string;
std::string decompressZlib( const char * bufptr, unsigned length );
QByteArray zlibDecompress( const char * bufptr, unsigned length );
std::string decompressBzip2( const char * bufptr, unsigned length );
string decompressZlib( const char * bufptr, unsigned length );
std::string decompressLzma2( const char * bufptr, unsigned length, bool raw_decoder = false );
string decompressBzip2( const char * bufptr, unsigned length );
string decompressLzma2( const char * bufptr, unsigned length, bool raw_decoder = false );

View file

@ -10,7 +10,7 @@
#include <QWebEngineView>
#include <list>
#include "article_netmgr.hh"
#include "audio/audioplayerinterface.hh"
#include "audioplayerinterface.hh"
#include "instances.hh"
#include "groupcombobox.hh"
#include "globalbroadcaster.hh"

View file

@ -401,18 +401,15 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
connect( wordsZoomOut, &QAction::triggered, this, &MainWindow::doWordsZoomOut );
connect( wordsZoomBase, &QAction::triggered, this, &MainWindow::doWordsZoomBase );
// tray icon
#ifndef Q_OS_MACOS // macOS uses the dock menu instead of the tray icon
connect( trayIconMenu.addAction( tr( "Show &Main Window" ) ), &QAction::triggered, this, [ this ] {
this->toggleMainWindow( true );
} );
#endif
// tray icon
connect( trayIconMenu.addAction( tr( "Show &Main Window" ) ),
&QAction::triggered,
this,
&MainWindow::showMainWindow );
trayIconMenu.addAction( enableScanningAction );
#ifndef Q_OS_MACOS // macOS uses the dock menu instead of the tray icon
trayIconMenu.addSeparator();
connect( trayIconMenu.addAction( tr( "&Quit" ) ), &QAction::triggered, this, &MainWindow::quitApp );
#endif
addGlobalAction( &escAction, [ this ]() {
handleEsc();
@ -1424,11 +1421,6 @@ void MainWindow::updateAppearances( QString const & addonStyle,
void MainWindow::trayIconUpdateOrInit()
{
#ifdef Q_OS_MACOS
trayIconMenu.setAsDockMenu();
ui.actionCloseToTray->setVisible( false );
#else
if ( !cfg.preferences.enableTrayIcon ) {
if ( trayIcon ) {
delete trayIcon;
@ -1452,7 +1444,6 @@ void MainWindow::trayIconUpdateOrInit()
// The 'Close to tray' action is associated with the tray icon, so we hide
// or show it here.
ui.actionCloseToTray->setVisible( cfg.preferences.enableTrayIcon );
#endif
}
void MainWindow::wheelEvent( QWheelEvent * ev )
@ -2541,7 +2532,7 @@ void MainWindow::handleEsc()
}
if ( cfg.preferences.escKeyHidesMainWindow ) {
toggleMainWindow( false );
toggleMainWindow();
}
else {
focusTranslateLine();
@ -2882,7 +2873,7 @@ void MainWindow::showTranslationForDicts( QString const & inWord,
ignoreDiacritics );
}
void MainWindow::toggleMainWindow( bool ensureShow )
void MainWindow::toggleMainWindow( bool onlyShow )
{
bool shown = false;
@ -2915,7 +2906,7 @@ void MainWindow::toggleMainWindow( bool ensureShow )
}
shown = true;
}
else if ( !ensureShow ) {
else if ( !onlyShow ) {
// On Windows and Linux, a hidden window won't show a task bar icon
// When trayicon is enabled, the duplication is unneeded
@ -2999,7 +2990,7 @@ void MainWindow::installHotKeys()
void MainWindow::hotKeyActivated( int hk )
{
if ( !hk ) {
toggleMainWindow( false );
toggleMainWindow();
}
else if ( scanPopup ) {
#ifdef HAVE_X11
@ -3084,7 +3075,7 @@ void MainWindow::trayIconActivated( QSystemTrayIcon::ActivationReason r )
switch ( r ) {
case QSystemTrayIcon::Trigger:
// Left click toggles the visibility of main window
toggleMainWindow( false );
toggleMainWindow();
break;
case QSystemTrayIcon::MiddleClick:
@ -3097,6 +3088,10 @@ void MainWindow::trayIconActivated( QSystemTrayIcon::ActivationReason r )
}
}
void MainWindow::showMainWindow()
{
toggleMainWindow( true );
}
void MainWindow::visitHomepage()
{
@ -3735,6 +3730,13 @@ void MainWindow::wordReceived( const QString & word )
respondToTranslationRequest( word, false );
}
void MainWindow::headwordReceived( const QString & word, const QString & ID )
{
toggleMainWindow( true );
setInputLineText( word, WildcardPolicy::EscapeWildcards, NoPopupChange );
respondToTranslationRequest( word, false, ArticleView::scrollToFromDictionaryId( ID ), false );
}
void MainWindow::updateFavoritesMenu()
{
if ( ui.favoritesPane->isVisible() ) {
@ -4139,13 +4141,7 @@ void MainWindow::showDictionaryHeadwords( Dictionary::Class * dict )
headwordsDlg = new DictHeadwords( this, cfg, dict );
addGlobalActionsToDialog( headwordsDlg );
addGroupComboBoxActionsToDialog( headwordsDlg, groupList );
connect( headwordsDlg,
&DictHeadwords::headwordSelected,
this,
[ this ]( QString const & headword, QString const & dictID ) {
setInputLineText( headword, WildcardPolicy::EscapeWildcards, NoPopupChange );
respondToTranslationRequest( headword, false, ArticleView::scrollToFromDictionaryId( dictID ), false );
} );
connect( headwordsDlg, &DictHeadwords::headwordSelected, this, &MainWindow::headwordReceived );
connect( headwordsDlg,
&DictHeadwords::closeDialog,
this,

View file

@ -14,7 +14,7 @@
#include "config.hh"
#include "dict/dictionary.hh"
#include "article_netmgr.hh"
#include "audio/audioplayerfactory.hh"
#include "audioplayerfactory.hh"
#include "instances.hh"
#include "article_maker.hh"
#include "scanpopup.hh"
@ -67,6 +67,7 @@ public slots:
void messageFromAnotherInstanceReceived( QString const & );
void showStatusBarMessage( QString const &, int, QPixmap const & );
void wordReceived( QString const & );
void headwordReceived( QString const &, QString const & );
void headwordFromFavorites( QString const &, QString const & );
void quitApp();
@ -225,8 +226,9 @@ private:
/// group, or to all dictionaries if there are no groups.
vector< sptr< Dictionary::Class > > const & getActiveDicts();
/// @param ensureShow only ensure the window will be shown and no "toggling"
void toggleMainWindow( bool ensureShow );
/// Brings the main window to front if it's not currently, or hides it
/// otherwise. The hiding part is omitted if onlyShow is true.
void toggleMainWindow( bool onlyShow = false );
/// Creates hotkeyWrapper and hooks the currently set keys for it
void installHotKeys();
@ -396,6 +398,8 @@ private slots:
void setAutostart( bool );
void showMainWindow();
void visitHomepage();
void visitForum();
void openConfigFolder();

View file

@ -174,11 +174,6 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
ui.hideSingleTab->setChecked( p.hideSingleTab );
ui.mruTabOrder->setChecked( p.mruTabOrder );
ui.enableTrayIcon->setChecked( p.enableTrayIcon );
#ifdef Q_OS_MACOS // macOS uses the dock menu instead of the tray icon
ui.enableTrayIcon->hide();
#endif
ui.startToTray->setChecked( p.startToTray );
ui.closeToTray->setChecked( p.closeToTray );
ui.cbAutostart->setChecked( p.autoStart );