mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 23:34:06 +00:00
Merge branch 'staged' into dev
This commit is contained in:
commit
994a931eee
|
@ -3,7 +3,7 @@
|
|||
#if (QT_VERSION > QT_VERSION_CHECK(6,0,0))
|
||||
#include <QWebEngineContextMenuRequest>
|
||||
#endif
|
||||
ArticleInspector::ArticleInspector( QWidget * parent ) : QWidget( parent, Qt::WindowType::Window ),firstTimeOpened(false)
|
||||
ArticleInspector::ArticleInspector( QWidget * parent ) : QWidget( parent, Qt::WindowType::Window )
|
||||
{
|
||||
setWindowTitle(tr("Inspect"));
|
||||
setAttribute( Qt::WidgetAttribute::WA_DeleteOnClose, false );
|
||||
|
@ -22,14 +22,12 @@ void ArticleInspector::setInspectPage( QWebEngineView * view )
|
|||
viewContainer->page()->setInspectedPage(page);
|
||||
#if( QT_VERSION > QT_VERSION_CHECK( 6, 0, 0 ) )
|
||||
// without this line, application will crash on qt6.2 ,see https://bugreports.qt.io/browse/QTBUG-101724
|
||||
if( view->lastContextMenuRequest() && firstTimeOpened )
|
||||
{
|
||||
page->triggerAction( QWebEnginePage::InspectElement );
|
||||
}
|
||||
if( !firstTimeOpened )
|
||||
{
|
||||
firstTimeOpened = true;
|
||||
}
|
||||
// and seems to hangup forever on qt6.3 ,so the best solution for now is to comment out the following lines.
|
||||
|
||||
// if( view->lastContextMenuRequest())
|
||||
// {
|
||||
// page->triggerAction( QWebEnginePage::InspectElement );
|
||||
// }
|
||||
#else
|
||||
page->triggerAction( QWebEnginePage::InspectElement );
|
||||
#endif
|
||||
|
|
|
@ -15,9 +15,7 @@ public:
|
|||
|
||||
void setInspectPage( QWebEngineView * view);
|
||||
private:
|
||||
//used to record if the devtool was first time opened.
|
||||
//if right click on the webpage and open inspect page on the first time ,the application has great possiblity to hang forever.
|
||||
bool firstTimeOpened;
|
||||
|
||||
virtual void closeEvent( QCloseEvent * );
|
||||
};
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ extern "C" {
|
|||
|
||||
#include <vector>
|
||||
|
||||
#include "gddebug.hh"
|
||||
#include "utils.hh"
|
||||
|
||||
using std::vector;
|
||||
|
@ -140,7 +141,17 @@ DecoderContext::~DecoderContext()
|
|||
static int readAudioData( void * opaque, unsigned char * buffer, int bufferSize )
|
||||
{
|
||||
QDataStream * pStream = ( QDataStream * )opaque;
|
||||
return pStream->readRawData( ( char * )buffer, bufferSize );
|
||||
// This function is passed as the read_packet callback into avio_alloc_context().
|
||||
// The documentation for this callback parameter states:
|
||||
// For stream protocols, must never return 0 but rather a proper AVERROR code.
|
||||
if( pStream->atEnd() )
|
||||
return AVERROR_EOF;
|
||||
const int bytesRead = pStream->readRawData( ( char * )buffer, bufferSize );
|
||||
// QDataStream::readRawData() returns 0 at EOF => return AVERROR_EOF in this case.
|
||||
// An error is unlikely here, so just print a warning and return AVERROR_EOF too.
|
||||
if( bytesRead < 0 )
|
||||
gdWarning( "readAudioData: error while reading raw data." );
|
||||
return bytesRead > 0 ? bytesRead : AVERROR_EOF;
|
||||
}
|
||||
|
||||
bool DecoderContext::openCodec( QString & errorString )
|
||||
|
|
11
langcoder.cc
11
langcoder.cc
|
@ -207,17 +207,14 @@ static GDLangCode LangCodes[] = {
|
|||
{ "zh", "chi", 0, "Chinese" },
|
||||
{ "zu", "zul", -1, "Zulu" },
|
||||
{ "jb", "jbo", 0, "Lojban" },
|
||||
|
||||
{ "", "", 0, "" }
|
||||
};
|
||||
|
||||
LangCoder::LangCoder()
|
||||
{
|
||||
for (int i = 0; true; i++) {
|
||||
const GDLangCode &lc = LangCodes[i];
|
||||
if (lc.lang[0] == 0)
|
||||
break;
|
||||
codeMap[code2toInt(lc.code)] = i;
|
||||
int i = 0;
|
||||
for (const auto lc : LangCodes)
|
||||
{
|
||||
codeMap[ code2toInt( lc.code ) ] = i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -408,6 +408,11 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
connect( trayIconMenu.addAction( tr( "Show &Main Window" ) ), SIGNAL( triggered() ),
|
||||
this, SLOT( showMainWindow() ) );
|
||||
trayIconMenu.addAction( enableScanPopup );
|
||||
actTrackingClipboard = trayIconMenu.addAction( tr( "Tracking Clipboard" ) );
|
||||
actTrackingClipboard->setCheckable(true);
|
||||
actTrackingClipboard->setChecked(cfg.preferences.trackClipboardChanges);
|
||||
connect( actTrackingClipboard , SIGNAL( triggered(bool) ),
|
||||
this, SLOT( trackingClipboard(bool) ) );
|
||||
trayIconMenu.addSeparator();
|
||||
connect( trayIconMenu.addAction( tr( "&Quit" ) ), SIGNAL( triggered() ),
|
||||
this, SLOT( quitApp() ) );
|
||||
|
@ -995,12 +1000,10 @@ void MainWindow::mousePressEvent( QMouseEvent *event)
|
|||
// middle clicked
|
||||
QString subtype = "plain";
|
||||
|
||||
QString str = QApplication::clipboard()->text(subtype,
|
||||
QClipboard::Selection);
|
||||
QString str = QApplication::clipboard()->text( subtype, QClipboard::Selection );
|
||||
setTranslateBoxTextAndClearSuffix( str, EscapeWildcards, NoPopupChange );
|
||||
|
||||
QKeyEvent ev(QEvent::KeyPress, Qt::Key_Enter,
|
||||
Qt::NoModifier);
|
||||
QKeyEvent ev( QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier );
|
||||
QApplication::sendEvent( translateLine, &ev );
|
||||
}
|
||||
|
||||
|
@ -3192,6 +3195,11 @@ void MainWindow::showMainWindow()
|
|||
toggleMainWindow( true );
|
||||
}
|
||||
|
||||
void MainWindow::trackingClipboard( bool on )
|
||||
{
|
||||
cfg.preferences.trackClipboardChanges = on;
|
||||
}
|
||||
|
||||
void MainWindow::visitHomepage()
|
||||
{
|
||||
QDesktopServices::openUrl( QUrl( "http://goldendict.org/" ) );
|
||||
|
|
|
@ -117,6 +117,7 @@ private:
|
|||
QToolBar * navToolbar;
|
||||
MainStatusBar * mainStatusBar;
|
||||
QAction * navBack, * navForward, * navPronounce, * enableScanPopup;
|
||||
QAction * actTrackingClipboard;
|
||||
QAction * beforeScanPopupSeparator, * afterScanPopupSeparator, * beforeOptionsSeparator;
|
||||
QAction * zoomIn, * zoomOut, * zoomBase;
|
||||
QAction * wordsZoomIn, * wordsZoomOut, * wordsZoomBase;
|
||||
|
@ -415,6 +416,8 @@ private slots:
|
|||
|
||||
void showMainWindow();
|
||||
|
||||
void trackingClipboard(bool);
|
||||
|
||||
void visitHomepage();
|
||||
void visitForum();
|
||||
void openConfigFolder();
|
||||
|
|
|
@ -595,10 +595,12 @@ MdictParser::HeadWordIndex MdictParser::splitHeadWordBlock( QByteArray const & b
|
|||
}
|
||||
|
||||
bool MdictParser::readRecordBlock( MdictParser::HeadWordIndex & headWordIndex,
|
||||
MdictParser::RecordHandler & recordHandler )
|
||||
MdictParser::RecordHandler & recordHandler,
|
||||
bool cross_block_read )
|
||||
{
|
||||
// cache the index, the headWordIndex is already sorted
|
||||
size_t idx = 0;
|
||||
bool readNextBlock = false;
|
||||
|
||||
for ( HeadWordIndex::const_iterator i = headWordIndex.begin(); i != headWordIndex.end(); ++i )
|
||||
{
|
||||
|
@ -611,21 +613,41 @@ bool MdictParser::readRecordBlock( MdictParser::HeadWordIndex & headWordIndex,
|
|||
RecordIndex const & recordIndex = recordBlockInfos_[idx];
|
||||
HeadWordIndex::const_iterator iNext = i + 1;
|
||||
qint64 recordSize;
|
||||
auto current = *i;
|
||||
|
||||
if( iNext == headWordIndex.end() )
|
||||
recordSize = recordIndex.shadowEndPos - i->first;
|
||||
{
|
||||
qint64 lastWordSize = recordIndex.shadowEndPos - current.first;
|
||||
|
||||
readNextBlock = cross_block_read && readNextHeadWordIndex( headWordIndex );
|
||||
if(readNextBlock)
|
||||
{
|
||||
recordSize = qMin(lastWordSize, headWordIndex.begin()->first - current.first);
|
||||
}
|
||||
else
|
||||
recordSize = iNext->first - i->first;
|
||||
{
|
||||
recordSize = lastWordSize;
|
||||
}
|
||||
}
|
||||
else
|
||||
recordSize = iNext->first - current.first;
|
||||
|
||||
RecordInfo recordInfo;
|
||||
recordInfo.compressedBlockPos = recordPos_ + recordIndex.startPos;
|
||||
recordInfo.recordOffset = i->first - recordIndex.shadowStartPos;
|
||||
recordInfo.recordOffset = current.first - recordIndex.shadowStartPos;
|
||||
recordInfo.decompressedBlockSize = recordIndex.decompressedSize;
|
||||
recordInfo.compressedBlockSize = recordIndex.compressedSize;
|
||||
recordInfo.recordSize = recordSize;
|
||||
|
||||
recordHandler.handleRecord( i->second, recordInfo );
|
||||
recordHandler.handleRecord( current.second, recordInfo );
|
||||
|
||||
if( readNextBlock )
|
||||
break;
|
||||
}
|
||||
|
||||
if( readNextBlock )
|
||||
readRecordBlock( headWordIndex, recordHandler, cross_block_read );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -158,7 +158,7 @@ public:
|
|||
|
||||
bool open( const char * filename );
|
||||
bool readNextHeadWordIndex( HeadWordIndex & headWordIndex );
|
||||
bool readRecordBlock( HeadWordIndex & headWordIndex, RecordHandler & recordHandler );
|
||||
bool readRecordBlock( HeadWordIndex & headWordIndex, RecordHandler & recordHandler, bool cross_block_read=false );
|
||||
|
||||
// helpers
|
||||
static QString toUtf16( const char * fromCode, const char * from, size_t fromSize );
|
||||
|
|
4
mdx.cc
4
mdx.cc
|
@ -1440,9 +1440,9 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
|||
MdictParser::HeadWordIndex headWordIndex;
|
||||
|
||||
// enumerating word and its definition
|
||||
while ( parser.readNextHeadWordIndex( headWordIndex ) )
|
||||
if ( parser.readNextHeadWordIndex( headWordIndex ) )
|
||||
{
|
||||
parser.readRecordBlock( headWordIndex, articleHandler );
|
||||
parser.readRecordBlock( headWordIndex, articleHandler, true);
|
||||
}
|
||||
|
||||
// enumerating resources if there's any
|
||||
|
|
18
scanpopup.cc
18
scanpopup.cc
|
@ -270,14 +270,10 @@ ScanPopup::ScanPopup( QWidget * parent,
|
|||
connect( definition, SIGNAL( titleChanged( ArticleView *, QString const & ) ),
|
||||
this, SLOT( titleChanged( ArticleView *, QString const & ) ) );
|
||||
|
||||
#ifdef HAVE_X11
|
||||
connect( QApplication::clipboard(), SIGNAL( changed( QClipboard::Mode ) ),
|
||||
this, SLOT( clipboardChanged( QClipboard::Mode ) ) );
|
||||
#else
|
||||
if( cfg.preferences.trackClipboardChanges )
|
||||
connect( QApplication::clipboard(), SIGNAL( changed( QClipboard::Mode ) ),
|
||||
this, SLOT( clipboardChanged( QClipboard::Mode ) ) );
|
||||
#endif
|
||||
connect( QApplication::clipboard(),
|
||||
SIGNAL( changed( QClipboard::Mode ) ),
|
||||
this,
|
||||
SLOT( clipboardChanged( QClipboard::Mode ) ) );
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
connect( &MouseOver::instance(), SIGNAL( hovered( QString const &, bool ) ),
|
||||
|
@ -518,9 +514,13 @@ void ScanPopup::delayShow()
|
|||
|
||||
void ScanPopup::clipboardChanged( QClipboard::Mode m )
|
||||
{
|
||||
if( !cfg.preferences.trackClipboardChanges )
|
||||
return;
|
||||
|
||||
#ifdef HAVE_X11
|
||||
if ( !isScanningEnabled )
|
||||
return;
|
||||
#ifdef HAVE_X11
|
||||
|
||||
if( cfg.preferences.ignoreOwnClipboardChanges && ownsClipboardMode( m ) )
|
||||
return;
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue