Compare commits

..

No commits in common. "5b70a7e081b655f3d7a90d1aa2fc0a65c16daff0" and "0680edd1e98ce015909df92acfe9bb261b18d9b2" have entirely different histories.

55 changed files with 879 additions and 746 deletions

View file

@ -17,7 +17,4 @@ a11c9e3aeca4329e1982d8fe26bacbb21ab50ddf
d15081e723756eef053550dc9e06e31d7828dec3 d15081e723756eef053550dc9e06e31d7828dec3
# remove gd::toWString # remove gd::toWString
c8af0450f1f7f8188004db96e3f53e7e33e2ccad c8af0450f1f7f8188004db96e3f53e7e33e2ccad
# remove gddebug.hh and associated functions
76aaed116bdc3aeb53fd61553aedb877baf9b510

View file

@ -4,6 +4,7 @@
#include "article_maker.hh" #include "article_maker.hh"
#include "config.hh" #include "config.hh"
#include "folding.hh" #include "folding.hh"
#include "gddebug.hh"
#include "globalbroadcaster.hh" #include "globalbroadcaster.hh"
#include "globalregex.hh" #include "globalregex.hh"
#include "htmlescape.hh" #include "htmlescape.hh"
@ -539,7 +540,7 @@ void ArticleRequest::altSearchFinished()
bodyRequests.push_back( r ); bodyRequests.push_back( r );
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "getArticle request error (%s) in \"%s\"", e.what(), activeDict->getName().c_str() ); gdWarning( "getArticle request error (%s) in \"%s\"\n", e.what(), activeDict->getName().c_str() );
} }
} }
@ -617,7 +618,7 @@ void ArticleRequest::bodyFinished()
return; return;
} }
qDebug( "some body finished" ); GD_DPRINTF( "some body finished" );
bool wasUpdated = false; bool wasUpdated = false;
@ -627,7 +628,7 @@ void ArticleRequest::bodyFinished()
if ( bodyRequests.front()->isFinished() ) { if ( bodyRequests.front()->isFinished() ) {
// Good // Good
qDebug( "one finished." ); GD_DPRINTF( "one finished." );
Dictionary::DataRequest & req = *bodyRequests.front(); Dictionary::DataRequest & req = *bodyRequests.front();
@ -717,7 +718,7 @@ void ArticleRequest::bodyFinished()
} }
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "getDataSlice error: %s", e.what() ); gdWarning( "getDataSlice error: %s\n", e.what() );
} }
wasUpdated = true; wasUpdated = true;
@ -727,12 +728,12 @@ void ArticleRequest::bodyFinished()
//signal finished dictionary for pronounciation //signal finished dictionary for pronounciation
GlobalBroadcaster::instance()->pronounce_engine.finishDictionary( dictId ); GlobalBroadcaster::instance()->pronounce_engine.finishDictionary( dictId );
} }
qDebug( "erasing.." ); GD_DPRINTF( "erasing.." );
bodyRequests.pop_front(); bodyRequests.pop_front();
qDebug( "erase done.." ); GD_DPRINTF( "erase done.." );
} }
else { else {
qDebug( "one not finished." ); GD_DPRINTF( "one not finished." );
break; break;
} }
} }
@ -975,7 +976,7 @@ void ArticleRequest::compoundSearchNextStep( bool lastSearchSucceeded )
// Look it up // Look it up
// qDebug( "Looking up %s", qPrintable( currentSplittedWordCompound ) ); // GD_DPRINTF( "Looking up %s\n", qPrintable( currentSplittedWordCompound ) );
stemmedWordFinder->expressionMatch( currentSplittedWordCompound, stemmedWordFinder->expressionMatch( currentSplittedWordCompound,
activeDicts, activeDicts,

View file

@ -4,6 +4,7 @@
#include <stdint.h> #include <stdint.h>
#include <QUrl> #include <QUrl>
#include "article_netmgr.hh" #include "article_netmgr.hh"
#include "gddebug.hh"
#include "utils.hh" #include "utils.hh"
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include "globalbroadcaster.hh" #include "globalbroadcaster.hh"
@ -92,7 +93,7 @@ QNetworkReply * ArticleNetworkAccessManager::getArticleReply( QNetworkRequest co
//if not external url,can be blocked from here. no need to continue execute the following code. //if not external url,can be blocked from here. no need to continue execute the following code.
//such as bres://upload.wikimedia.... etc . //such as bres://upload.wikimedia.... etc .
if ( !Utils::isExternalLink( url ) ) { if ( !Utils::isExternalLink( url ) ) {
qWarning( R"(Blocking element "%s" as built-in link )", req.url().toEncoded().data() ); gdWarning( R"(Blocking element "%s" as built-in link )", req.url().toEncoded().data() );
return new BlockedNetworkReply( this ); return new BlockedNetworkReply( this );
} }
@ -107,7 +108,7 @@ QNetworkReply * ArticleNetworkAccessManager::getArticleReply( QNetworkRequest co
if ( !url.host().endsWith( refererUrl.host() ) if ( !url.host().endsWith( refererUrl.host() )
&& Utils::Url::getHostBaseFromUrl( url ) != Utils::Url::getHostBaseFromUrl( refererUrl ) && Utils::Url::getHostBaseFromUrl( url ) != Utils::Url::getHostBaseFromUrl( refererUrl )
&& !url.scheme().startsWith( "data" ) ) { && !url.scheme().startsWith( "data" ) ) {
qWarning( R"(Blocking element "%s" due to not same domain)", url.toEncoded().data() ); gdWarning( R"(Blocking element "%s" due to not same domain)", url.toEncoded().data() );
return new BlockedNetworkReply( this ); return new BlockedNetworkReply( this );
} }
@ -237,7 +238,7 @@ sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource( QUrl c
return dictionary->getResource( Utils::Url::path( url ).mid( 1 ).toUtf8().data() ); return dictionary->getResource( Utils::Url::path( url ).mid( 1 ).toUtf8().data() );
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "getResource request error (%s) in \"%s\"", e.what(), dictionary->getName().c_str() ); gdWarning( "getResource request error (%s) in \"%s\"\n", e.what(), dictionary->getName().c_str() );
return {}; return {};
} }
} }
@ -283,7 +284,7 @@ ArticleResourceReply::ArticleResourceReply( QObject * parent,
if ( req->isFinished() ) { if ( req->isFinished() ) {
emit finishedSignal(); emit finishedSignal();
qDebug( "In-place finish." ); GD_DPRINTF( "In-place finish.\n" );
} }
} }
} }
@ -352,11 +353,11 @@ qint64 ArticleResourceReply::readData( char * out, qint64 maxSize )
return 0; return 0;
} }
qDebug( "====reading %lld of (%lld) bytes, %lld bytes readed . Finish status: %d", GD_DPRINTF( "====reading %lld of (%lld) bytes, %lld bytes readed . Finish status: %d",
toRead, toRead,
avail, avail,
alreadyRead, alreadyRead,
finished ); finished );
try { try {
req->getDataSlice( alreadyRead, toRead, out ); req->getDataSlice( alreadyRead, toRead, out );

View file

@ -8,6 +8,7 @@
#include "ffmpegaudioplayer.hh" #include "ffmpegaudioplayer.hh"
#include "multimediaaudioplayer.hh" #include "multimediaaudioplayer.hh"
#include "externalaudioplayer.hh" #include "externalaudioplayer.hh"
#include "gddebug.hh"
AudioPlayerFactory::AudioPlayerFactory( bool useInternalPlayer, AudioPlayerFactory::AudioPlayerFactory( bool useInternalPlayer,
InternalPlayerBackend internalPlayerBackend, InternalPlayerBackend internalPlayerBackend,
@ -40,7 +41,7 @@ void AudioPlayerFactory::setPreferences( bool new_useInternalPlayer,
setAudioPlaybackProgram( *externalPlayer ); setAudioPlaybackProgram( *externalPlayer );
} }
else { else {
qWarning( "External player was expected, but it does not exist." ); gdWarning( "External player was expected, but it does not exist.\n" );
} }
} }
} }

View file

@ -2,6 +2,7 @@
#include "audiooutput.hh" #include "audiooutput.hh"
#include "ffmpegaudio.hh" #include "ffmpegaudio.hh"
#include "gddebug.hh"
#include "utils.hh" #include "utils.hh"
#include <QAudioDevice> #include <QAudioDevice>
#include <QDataStream> #include <QDataStream>
@ -87,7 +88,7 @@ static int readAudioData( void * opaque, unsigned char * buffer, int bufferSize
// QDataStream::readRawData() returns 0 at EOF => return AVERROR_EOF in this case. // 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. // An error is unlikely here, so just print a warning and return AVERROR_EOF too.
if ( bytesRead < 0 ) { if ( bytesRead < 0 ) {
qWarning( "readAudioData: error while reading raw data." ); gdWarning( "readAudioData: error while reading raw data." );
} }
return bytesRead > 0 ? bytesRead : AVERROR_EOF; return bytesRead > 0 ? bytesRead : AVERROR_EOF;
} }
@ -169,11 +170,11 @@ bool DecoderContext::openCodec( QString & errorString )
// 61 = FFmpeg 7.0 -> https://github.com/FFmpeg/FFmpeg/blob/release/7.0/libavcodec/version_major.h // 61 = FFmpeg 7.0 -> https://github.com/FFmpeg/FFmpeg/blob/release/7.0/libavcodec/version_major.h
#if LIBAVCODEC_VERSION_MAJOR >= 61 #if LIBAVCODEC_VERSION_MAJOR >= 61
qDebug( "Codec open: %s: channels: %d, rate: %d, format: %s", gdDebug( "Codec open: %s: channels: %d, rate: %d, format: %s\n",
codec_->long_name, codec_->long_name,
codecContext_->ch_layout.nb_channels, codecContext_->ch_layout.nb_channels,
codecContext_->sample_rate, codecContext_->sample_rate,
av_get_sample_fmt_name( codecContext_->sample_fmt ) ); av_get_sample_fmt_name( codecContext_->sample_fmt ) );
if ( !av_channel_layout_check( &codecContext_->ch_layout ) ) { if ( !av_channel_layout_check( &codecContext_->ch_layout ) ) {
av_channel_layout_default( &codecContext_->ch_layout, codecContext_->ch_layout.nb_channels ); av_channel_layout_default( &codecContext_->ch_layout, codecContext_->ch_layout.nb_channels );
@ -192,11 +193,11 @@ bool DecoderContext::openCodec( QString & errorString )
qDebug() << "swr_alloc_set_opts2 failed."; qDebug() << "swr_alloc_set_opts2 failed.";
} }
#else #else
qDebug( "Codec open: %s: channels: %d, rate: %d, format: %s", gdDebug( "Codec open: %s: channels: %d, rate: %d, format: %s\n",
codec_->long_name, codec_->long_name,
codecContext_->channels, codecContext_->channels,
codecContext_->sample_rate, codecContext_->sample_rate,
av_get_sample_fmt_name( codecContext_->sample_fmt ) ); av_get_sample_fmt_name( codecContext_->sample_fmt ) );
auto layout = codecContext_->channel_layout; auto layout = codecContext_->channel_layout;
if ( !layout ) { if ( !layout ) {
@ -366,7 +367,7 @@ bool DecoderContext::normalizeAudio( AVFrame * frame, vector< uint8_t > & sample
return false; return false;
} }
else { else {
// qDebug( "out_count:%d, out_nb_samples:%d, frame->nb_samples:%d ", out_count, out_nb_samples, frame->nb_samples ); // qDebug( "out_count:%d, out_nb_samples:%d, frame->nb_samples:%d \n", out_count, out_nb_samples, frame->nb_samples );
} }
int actual_size = av_samples_get_buffer_size( nullptr, dst_channels, out_nb_samples, AV_SAMPLE_FMT_S16, 1 ); int actual_size = av_samples_get_buffer_size( nullptr, dst_channels, out_nb_samples, AV_SAMPLE_FMT_S16, 1 );

29
src/common/gddebug.cc Normal file
View file

@ -0,0 +1,29 @@
/* This file is (c) 2013 Abs62
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
#include "gddebug.hh"
#include <QDebug>
#include <QString>
#include <QtCore5Compat/QTextCodec>
QFile * logFilePtr;
void gdWarning( const char * msg, ... )
{
va_list ap;
va_start( ap, msg );
qWarning() << QString().vasprintf( msg, ap );
va_end( ap );
}
void gdDebug( const char * msg, ... )
{
va_list ap;
va_start( ap, msg );
qDebug().noquote() << QString().vasprintf( msg, ap );
va_end( ap );
}

29
src/common/gddebug.hh Normal file
View file

@ -0,0 +1,29 @@
#pragma once
#include <QFile>
#ifdef NO_CONSOLE
#define GD_DPRINTF( ... ) \
do { \
} while ( 0 )
#define GD_FDPRINTF( ... ) \
do { \
} while ( 0 )
#else
#define GD_DPRINTF( ... ) gdDebug( __VA_ARGS__ )
#define GD_FDPRINTF( ... ) fprintf( __VA_ARGS__ )
#endif
void gdWarning( const char *, ... ) /* print warning message */
#if defined( Q_CC_GNU ) && !defined( __INSURE__ )
__attribute__( ( format( printf, 1, 2 ) ) )
#endif
;
void gdDebug( const char *, ... )
#if defined( Q_CC_GNU ) && !defined( __INSURE__ )
__attribute__( ( format( printf, 1, 2 ) ) )
#endif
;
extern QFile * logFilePtr;

View file

@ -1,2 +0,0 @@
#include "logfileptr.hh"
QFile * logFilePtr;

View file

@ -1,3 +0,0 @@
#pragma once
#include <QFile>
extern QFile * logFilePtr;

View file

@ -8,6 +8,7 @@
#include <QtXml> #include <QtXml>
#include <QApplication> #include <QApplication>
#include <QStyle> #include <QStyle>
#include "gddebug.hh"
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
//this is a windows header file. //this is a windows header file.
@ -129,9 +130,9 @@ QString Preferences::sanitizeInputPhrase( QString const & inputWord ) const
} }
if ( limitInputPhraseLength && result.size() > inputPhraseLengthLimit ) { if ( limitInputPhraseLength && result.size() > inputPhraseLengthLimit ) {
qDebug( "Ignoring an input phrase %lld symbols long. The configured maximum input phrase length is %d symbols.", gdDebug( "Ignoring an input phrase %lld symbols long. The configured maximum input phrase length is %d symbols.",
result.size(), result.size(),
inputPhraseLengthLimit ); inputPhraseLengthLimit );
return {}; return {};
} }
@ -540,7 +541,7 @@ Class load()
if ( !loadFromTemplate ) { if ( !loadFromTemplate ) {
// Load the config as usual // Load the config as usual
if ( !dd.setContent( &configFile, false, &errorStr, &errorLine, &errorColumn ) ) { if ( !dd.setContent( &configFile, false, &errorStr, &errorLine, &errorColumn ) ) {
qDebug( "Error: %s at %d,%d", errorStr.toLocal8Bit().constData(), errorLine, errorColumn ); GD_DPRINTF( "Error: %s at %d,%d\n", errorStr.toLocal8Bit().constData(), errorLine, errorColumn );
throw exMalformedConfigFile(); throw exMalformedConfigFile();
} }
} }
@ -553,7 +554,7 @@ Class load()
QBuffer bufferedData( &data ); QBuffer bufferedData( &data );
if ( !dd.setContent( &bufferedData, false, &errorStr, &errorLine, &errorColumn ) ) { if ( !dd.setContent( &bufferedData, false, &errorStr, &errorLine, &errorColumn ) ) {
qDebug( "Error: %s at %d,%d", errorStr.toLocal8Bit().constData(), errorLine, errorColumn ); GD_DPRINTF( "Error: %s at %d,%d\n", errorStr.toLocal8Bit().constData(), errorLine, errorColumn );
throw exMalformedConfigFile(); throw exMalformedConfigFile();
} }
} }

View file

@ -8,6 +8,7 @@
#include "chunkedstorage.hh" #include "chunkedstorage.hh"
#include "langcoder.hh" #include "langcoder.hh"
#include "decompress.hh" #include "decompress.hh"
#include "gddebug.hh"
#include "ftshelpers.hh" #include "ftshelpers.hh"
#include "htmlescape.hh" #include "htmlescape.hh"
@ -405,7 +406,7 @@ void AardDictionary::loadArticle( quint32 address, string & articleText, bool ra
df.read( &articleBody.front(), articleSize ); df.read( &articleBody.front(), articleSize );
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "AARD: Failed loading article from \"%s\", reason: %s", getName().c_str(), ex.what() ); gdWarning( "AARD: Failed loading article from \"%s\", reason: %s\n", getName().c_str(), ex.what() );
break; break;
} }
catch ( ... ) { catch ( ... ) {
@ -565,14 +566,14 @@ void AardDictionary::makeFTSIndex( QAtomicInt & isCancelled )
} }
qDebug( "Aard: Building the full-text index for dictionary: %s", getName().c_str() ); gdDebug( "Aard: Building the full-text index for dictionary: %s\n", getName().c_str() );
try { try {
FtsHelpers::makeFTSIndex( this, isCancelled ); FtsHelpers::makeFTSIndex( this, isCancelled );
FTS_index_completed.ref(); FTS_index_completed.ref();
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "Aard: Failed building full-text search index for \"%s\", reason: %s", getName().c_str(), ex.what() ); gdWarning( "Aard: Failed building full-text search index for \"%s\", reason: %s\n", getName().c_str(), ex.what() );
QFile::remove( QString::fromStdString( ftsIdxName ) ); QFile::remove( QString::fromStdString( ftsIdxName ) );
} }
} }
@ -588,7 +589,7 @@ void AardDictionary::getArticleText( uint32_t articleAddress, QString & headword
text = Html::unescape( QString::fromUtf8( articleText.data(), articleText.size() ) ); text = Html::unescape( QString::fromUtf8( articleText.data(), articleText.size() ) );
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "Aard: Failed retrieving article from \"%s\", reason: %s", getName().c_str(), ex.what() ); gdWarning( "Aard: Failed retrieving article from \"%s\", reason: %s\n", getName().c_str(), ex.what() );
} }
} }
@ -779,12 +780,12 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) || indexIsOldOrBad( indexFile ) ) { if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) || indexIsOldOrBad( indexFile ) ) {
try { try {
qDebug( "Aard: Building the index for dictionary: %s", fileName.c_str() ); gdDebug( "Aard: Building the index for dictionary: %s\n", fileName.c_str() );
{ {
QFileInfo info( QString::fromUtf8( fileName.c_str() ) ); QFileInfo info( QString::fromUtf8( fileName.c_str() ) );
if ( static_cast< quint64 >( info.size() ) > ULONG_MAX ) { if ( static_cast< quint64 >( info.size() ) > ULONG_MAX ) {
qWarning( "File %s is too large", fileName.c_str() ); gdWarning( "File %s is too large\n", fileName.c_str() );
continue; continue;
} }
} }
@ -798,7 +799,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
if ( strncmp( dictHeader.signature, "aard", 4 ) if ( strncmp( dictHeader.signature, "aard", 4 )
|| ( !has64bitIndex && strncmp( dictHeader.indexItemFormat, ">LL", 4 ) ) || ( !has64bitIndex && strncmp( dictHeader.indexItemFormat, ">LL", 4 ) )
|| strncmp( dictHeader.keyLengthFormat, ">H", 2 ) || strncmp( dictHeader.articleLengthFormat, ">L", 2 ) ) { || strncmp( dictHeader.keyLengthFormat, ">H", 2 ) || strncmp( dictHeader.articleLengthFormat, ">L", 2 ) ) {
qWarning( "File %s is not in supported aard format", fileName.c_str() ); gdWarning( "File %s is not in supported aard format\n", fileName.c_str() );
continue; continue;
} }
@ -806,7 +807,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
quint32 size = qFromBigEndian( dictHeader.metaLength ); quint32 size = qFromBigEndian( dictHeader.metaLength );
if ( size == 0 ) { if ( size == 0 ) {
qWarning( "File %s has invalid metadata", fileName.c_str() ); gdWarning( "File %s has invalid metadata", fileName.c_str() );
continue; continue;
} }
@ -820,7 +821,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
map< string, string > meta = parseMetaData( metaStr ); map< string, string > meta = parseMetaData( metaStr );
if ( meta.empty() ) { if ( meta.empty() ) {
qWarning( "File %s has invalid metadata", fileName.c_str() ); gdWarning( "File %s has invalid metadata", fileName.c_str() );
continue; continue;
} }
@ -974,11 +975,11 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
idx.write( &idxHeader, sizeof( idxHeader ) ); idx.write( &idxHeader, sizeof( idxHeader ) );
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "Aard dictionary indexing failed: %s, error: %s", fileName.c_str(), e.what() ); gdWarning( "Aard dictionary indexing failed: %s, error: %s\n", fileName.c_str(), e.what() );
continue; continue;
} }
catch ( ... ) { catch ( ... ) {
qWarning( "Aard dictionary indexing failed" ); gdWarning( "Aard dictionary indexing failed\n" );
continue; continue;
} }
} // if need to rebuild } // if need to rebuild
@ -986,7 +987,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
dictionaries.push_back( std::make_shared< AardDictionary >( dictId, indexFile, dictFiles ) ); dictionaries.push_back( std::make_shared< AardDictionary >( dictId, indexFile, dictFiles ) );
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "Aard dictionary initializing failed: %s, error: %s", fileName.c_str(), e.what() ); gdWarning( "Aard dictionary initializing failed: %s, error: %s\n", fileName.c_str(), e.what() );
continue; continue;
} }
} }

View file

@ -8,6 +8,7 @@
#include "dictfile.hh" #include "dictfile.hh"
#include "folding.hh" #include "folding.hh"
#include "ftshelpers.hh" #include "ftshelpers.hh"
#include "gddebug.hh"
#include "htmlescape.hh" #include "htmlescape.hh"
#include "langcoder.hh" #include "langcoder.hh"
#include "language.hh" #include "language.hh"
@ -409,7 +410,7 @@ void BglDictionary::getArticleText( uint32_t articleAddress, QString & headword,
text = Html::unescape( QString::fromStdU32String( wstr ) ); text = Html::unescape( QString::fromStdU32String( wstr ) );
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "BGL: Failed retrieving article from \"%s\", reason: %s", getName().c_str(), ex.what() ); gdWarning( "BGL: Failed retrieving article from \"%s\", reason: %s\n", getName().c_str(), ex.what() );
} }
} }
@ -425,14 +426,14 @@ void BglDictionary::makeFTSIndex( QAtomicInt & isCancelled )
} }
qDebug( "Bgl: Building the full-text index for dictionary: %s", getName().c_str() ); gdDebug( "Bgl: Building the full-text index for dictionary: %s\n", getName().c_str() );
try { try {
FtsHelpers::makeFTSIndex( this, isCancelled ); FtsHelpers::makeFTSIndex( this, isCancelled );
FTS_index_completed.ref(); FTS_index_completed.ref();
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "Bgl: Failed building full-text search index for \"%s\", reason: %s", getName().c_str(), ex.what() ); gdWarning( "Bgl: Failed building full-text search index for \"%s\", reason: %s\n", getName().c_str(), ex.what() );
QFile::remove( QString::fromStdString( ftsIdxName ) ); QFile::remove( QString::fromStdString( ftsIdxName ) );
} }
} }
@ -718,7 +719,7 @@ void BglArticleRequest::run()
} // try } // try
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "BGL: Failed loading article from \"%s\", reason: %s", dict.getName().c_str(), ex.what() ); gdWarning( "BGL: Failed loading article from \"%s\", reason: %s\n", dict.getName().c_str(), ex.what() );
} }
} }
@ -914,7 +915,7 @@ void BglResourceRequest::run()
compressedData.size() ) compressedData.size() )
!= Z_OK != Z_OK
|| decompressedLength != data.size() ) { || decompressedLength != data.size() ) {
qWarning( "Failed to decompress resource \"%s\", ignoring it.", name.c_str() ); gdWarning( "Failed to decompress resource \"%s\", ignoring it.\n", name.c_str() );
} }
else { else {
hasAnyData = true; hasAnyData = true;
@ -992,14 +993,14 @@ protected:
void ResourceHandler::handleBabylonResource( string const & filename, char const * data, size_t size ) void ResourceHandler::handleBabylonResource( string const & filename, char const * data, size_t size )
{ {
//qDebug( "Handling resource file %s (%u bytes)", filename.c_str(), size ); //GD_DPRINTF( "Handling resource file %s (%u bytes)\n", filename.c_str(), size );
vector< unsigned char > compressedData( compressBound( size ) ); vector< unsigned char > compressedData( compressBound( size ) );
unsigned long compressedSize = compressedData.size(); unsigned long compressedSize = compressedData.size();
if ( compress( &compressedData.front(), &compressedSize, (unsigned char const *)data, size ) != Z_OK ) { if ( compress( &compressedData.front(), &compressedSize, (unsigned char const *)data, size ) != Z_OK ) {
qWarning( "Failed to compress the body of resource \"%s\", dropping it.", filename.c_str() ); gdWarning( "Failed to compress the body of resource \"%s\", dropping it.\n", filename.c_str() );
return; return;
} }
@ -1050,7 +1051,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) || indexIsOldOrBad( indexFile ) ) { if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) || indexIsOldOrBad( indexFile ) ) {
// Building the index // Building the index
qDebug( "Bgl: Building the index for dictionary: %s", fileName.c_str() ); gdDebug( "Bgl: Building the index for dictionary: %s\n", fileName.c_str() );
try { try {
Babylon b( fileName ); Babylon b( fileName );
@ -1062,7 +1063,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
std::string sourceCharset, targetCharset; std::string sourceCharset, targetCharset;
if ( !b.read( sourceCharset, targetCharset ) ) { if ( !b.read( sourceCharset, targetCharset ) ) {
qWarning( "Failed to start reading from %s, skipping it", fileName.c_str() ); gdWarning( "Failed to start reading from %s, skipping it\n", fileName.c_str() );
continue; continue;
} }
@ -1154,7 +1155,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
idxHeader.chunksOffset = chunks.finish(); idxHeader.chunksOffset = chunks.finish();
qDebug( "Writing index..." ); GD_DPRINTF( "Writing index...\n" );
// Good. Now build the index // Good. Now build the index
@ -1190,7 +1191,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
idx.write( &idxHeader, sizeof( idxHeader ) ); idx.write( &idxHeader, sizeof( idxHeader ) );
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "BGL dictionary indexing failed: %s, error: %s", fileName.c_str(), e.what() ); gdWarning( "BGL dictionary indexing failed: %s, error: %s\n", fileName.c_str(), e.what() );
} }
} }
@ -1198,7 +1199,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
dictionaries.push_back( std::make_shared< BglDictionary >( dictId, indexFile, fileName ) ); dictionaries.push_back( std::make_shared< BglDictionary >( dictId, indexFile, fileName ) );
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "BGL dictionary initializing failed: %s, error: %s", fileName.c_str(), e.what() ); gdWarning( "BGL dictionary initializing failed: %s, error: %s\n", fileName.c_str(), e.what() );
} }
} }

View file

@ -23,6 +23,7 @@
#include "bgl_babylon.hh" #include "bgl_babylon.hh"
#include "dictionary.hh" #include "dictionary.hh"
#include "gddebug.hh"
#include "globalregex.hh" #include "globalregex.hh"
#include "htmlescape.hh" #include "htmlescape.hh"
#include "iconv.hh" #include "iconv.hh"
@ -332,10 +333,10 @@ bool Babylon::read( const std::string & source_charset, const std::string & targ
convertToUtf8( m_email, BGL_TARGET_CHARSET ); convertToUtf8( m_email, BGL_TARGET_CHARSET );
convertToUtf8( m_copyright, BGL_TARGET_CHARSET ); convertToUtf8( m_copyright, BGL_TARGET_CHARSET );
convertToUtf8( m_description, BGL_TARGET_CHARSET ); convertToUtf8( m_description, BGL_TARGET_CHARSET );
qDebug( "Default charset: %s\nSource Charset: %s\nTargetCharset: %s", GD_DPRINTF( "Default charset: %s\nSource Charset: %s\nTargetCharset: %s\n",
m_defaultCharset.c_str(), m_defaultCharset.c_str(),
m_sourceCharset.c_str(), m_sourceCharset.c_str(),
m_targetCharset.c_str() ); m_targetCharset.c_str() );
return true; return true;
} }
@ -497,7 +498,7 @@ bgl_entry Babylon::readEntry( ResourceHandler * resourceHandler )
unsigned length = (unsigned char)block.data[ pos ] - 0x3F; unsigned length = (unsigned char)block.data[ pos ] - 0x3F;
if ( length > len - a - 2 ) { if ( length > len - a - 2 ) {
qWarning( "Hidden displayed headword is too large %s", headword.c_str() ); GD_FDPRINTF( stderr, "Hidden displayed headword is too large %s\n", headword.c_str() );
pos += len - a; pos += len - a;
break; break;
} }
@ -510,7 +511,7 @@ bgl_entry Babylon::readEntry( ResourceHandler * resourceHandler )
unsigned length = (unsigned char)block.data[ pos + 1 ]; unsigned length = (unsigned char)block.data[ pos + 1 ];
if ( length > len - a - 2 ) { if ( length > len - a - 2 ) {
qWarning( "Displayed headword's length is too large for headword %s", headword.c_str() ); GD_FDPRINTF( stderr, "Displayed headword's length is too large for headword %s\n", headword.c_str() );
pos += len - a; pos += len - a;
break; break;
} }
@ -524,7 +525,7 @@ bgl_entry Babylon::readEntry( ResourceHandler * resourceHandler )
unsigned length = qFromBigEndian( *reinterpret_cast< quint16 * >( block.data + pos + 1 ) ); unsigned length = qFromBigEndian( *reinterpret_cast< quint16 * >( block.data + pos + 1 ) );
if ( length > len - a - 3 ) { if ( length > len - a - 3 ) {
qWarning( "2-byte sized displayed headword for %s is too large", headword.c_str() ); GD_FDPRINTF( stderr, "2-byte sized displayed headword for %s is too large\n", headword.c_str() );
pos += len - a; pos += len - a;
break; break;
} }
@ -540,7 +541,9 @@ bgl_entry Babylon::readEntry( ResourceHandler * resourceHandler )
unsigned length = (unsigned char)block.data[ pos + 2 ]; unsigned length = (unsigned char)block.data[ pos + 2 ];
if ( length > len - a - 3 ) { if ( length > len - a - 3 ) {
qWarning( "1-byte-sized transcription's length is too large for headword %s\n", headword.c_str() ); GD_FDPRINTF( stderr,
"1-byte-sized transcription's length is too large for headword %s\n",
headword.c_str() );
pos += len - a; pos += len - a;
break; break;
} }
@ -550,7 +553,7 @@ bgl_entry Babylon::readEntry( ResourceHandler * resourceHandler )
transcription = Iconv::toUtf8( "Windows-1252", block.data + pos + 3, length ); transcription = Iconv::toUtf8( "Windows-1252", block.data + pos + 3, length );
} }
catch ( Iconv::Ex & e ) { catch ( Iconv::Ex & e ) {
qWarning( "Bgl: charset conversion error, no trancription processing's done: %s", e.what() ); qWarning( "Bgl: charset conversion error, no trancription processing's done: %s\n", e.what() );
transcription = std::string( block.data + pos + 3, length ); transcription = std::string( block.data + pos + 3, length );
} }
} }
@ -567,7 +570,9 @@ bgl_entry Babylon::readEntry( ResourceHandler * resourceHandler )
unsigned length = qFromBigEndian( *reinterpret_cast< quint16 * >( block.data + pos + 2 ) ); unsigned length = qFromBigEndian( *reinterpret_cast< quint16 * >( block.data + pos + 2 ) );
if ( length > len - a - 4 ) { if ( length > len - a - 4 ) {
qWarning( "2-byte-sized transcription's length is too large for headword %s\n", headword.c_str() ); GD_FDPRINTF( stderr,
"2-byte-sized transcription's length is too large for headword %s\n",
headword.c_str() );
pos += len - a; pos += len - a;
break; break;
} }
@ -577,7 +582,7 @@ bgl_entry Babylon::readEntry( ResourceHandler * resourceHandler )
transcription = Iconv::toUtf8( "Windows-1252", block.data + pos + 4, length ); transcription = Iconv::toUtf8( "Windows-1252", block.data + pos + 4, length );
} }
catch ( Iconv::Ex & e ) { catch ( Iconv::Ex & e ) {
qWarning( "Bgl: charset conversion error, no transcription processing's done: %s", e.what() ); qWarning( "Bgl: charset conversion error, no transcription processing's done: %s\n", e.what() );
transcription = std::string( block.data + pos + 4, length ); transcription = std::string( block.data + pos + 4, length );
} }
} }
@ -595,7 +600,7 @@ bgl_entry Babylon::readEntry( ResourceHandler * resourceHandler )
unsigned length = (unsigned char)block.data[ pos ] - 0x3F; unsigned length = (unsigned char)block.data[ pos ] - 0x3F;
if ( length > len - a - 2 ) { if ( length > len - a - 2 ) {
qWarning( "Hidden transcription is too large %s", headword.c_str() ); GD_FDPRINTF( stderr, "Hidden transcription is too large %s\n", headword.c_str() );
pos += len - a; pos += len - a;
break; break;
} }

View file

@ -7,6 +7,7 @@
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "gddebug.hh"
#include "wstring_qt.hh" #include "wstring_qt.hh"
#include "utils.hh" #include "utils.hh"
@ -87,11 +88,11 @@ BtreeIndex::findArticles( wstring const & search_word, bool ignoreDiacritics, ui
} }
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "Articles searching failed, error: %s", e.what() ); gdWarning( "Articles searching failed, error: %s\n", e.what() );
result.clear(); result.clear();
} }
catch ( ... ) { catch ( ... ) {
qWarning( "Articles searching failed" ); qWarning( "Articles searching failed\n" );
result.clear(); result.clear();
} }
@ -264,7 +265,7 @@ void BtreeWordSearchRequest::findMatches()
break; break;
} }
//qDebug( "offset = %u, size = %u", chainOffset - &leaf.front(), leaf.size() ); //GD_DPRINTF( "offset = %u, size = %u\n", chainOffset - &leaf.front(), leaf.size() );
vector< WordArticleLink > chain = dict.readChain( chainOffset ); vector< WordArticleLink > chain = dict.readChain( chainOffset );
@ -327,7 +328,7 @@ void BtreeWordSearchRequest::findMatches()
if ( chainOffset >= leafEnd ) { if ( chainOffset >= leafEnd ) {
// We're past the current leaf, fetch the next one // We're past the current leaf, fetch the next one
//qDebug( "advancing" ); //GD_DPRINTF( "advancing\n" );
if ( nextLeaf ) { if ( nextLeaf ) {
QMutexLocker _( dict.idxFileMutex ); QMutexLocker _( dict.idxFileMutex );
@ -341,7 +342,7 @@ void BtreeWordSearchRequest::findMatches()
uint32_t leafEntries = *(uint32_t *)&leaf.front(); uint32_t leafEntries = *(uint32_t *)&leaf.front();
if ( leafEntries == 0xffffFFFF ) { if ( leafEntries == 0xffffFFFF ) {
//qDebug( "bah!" ); //GD_DPRINTF( "bah!\n" );
exit( 1 ); exit( 1 );
} }
} }
@ -362,10 +363,10 @@ void BtreeWordSearchRequest::findMatches()
} }
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "Index searching failed: \"%s\", error: %s", dict.getName().c_str(), e.what() ); qWarning( "Index searching failed: \"%s\", error: %s\n", dict.getName().c_str(), e.what() );
} }
catch ( ... ) { catch ( ... ) {
qWarning( "Index searching failed: \"%s\"", dict.getName().c_str() ); gdWarning( "Index searching failed: \"%s\"\n", dict.getName().c_str() );
} }
} }
@ -420,7 +421,7 @@ void BtreeIndex::readNode( uint32_t offset, vector< char > & out )
uint32_t uncompressedSize = idxFile->read< uint32_t >(); uint32_t uncompressedSize = idxFile->read< uint32_t >();
uint32_t compressedSize = idxFile->read< uint32_t >(); uint32_t compressedSize = idxFile->read< uint32_t >();
//qDebug( "%x,%x", uncompressedSize, compressedSize ); //GD_DPRINTF( "%x,%x\n", uncompressedSize, compressedSize );
out.resize( uncompressedSize ); out.resize( uncompressedSize );
@ -501,7 +502,7 @@ char const * BtreeIndex::findChainOffsetExactOrPrefix(
if ( leafEntries == 0xffffFFFF ) { if ( leafEntries == 0xffffFFFF ) {
// A node // A node
//qDebug( "=>a node" ); //GD_DPRINTF( "=>a node\n" );
uint32_t const * offsets = (uint32_t *)leaf + 1; uint32_t const * offsets = (uint32_t *)leaf + 1;
@ -587,13 +588,13 @@ char const * BtreeIndex::findChainOffsetExactOrPrefix(
currentNodeOffset = offsets[ entry + 1 ]; currentNodeOffset = offsets[ entry + 1 ];
} }
//qDebug( "reading node at %x", currentNodeOffset ); //GD_DPRINTF( "reading node at %x\n", currentNodeOffset );
readNode( currentNodeOffset, extLeaf ); readNode( currentNodeOffset, extLeaf );
leaf = &extLeaf.front(); leaf = &extLeaf.front();
leafEnd = leaf + extLeaf.size(); leafEnd = leaf + extLeaf.size();
} }
else { else {
//qDebug( "=>a leaf" ); //GD_DPRINTF( "=>a leaf\n" );
// A leaf // A leaf
// If this leaf is the root, there's no next leaf, it just can't be. // If this leaf is the root, there's no next leaf, it just can't be.
@ -626,7 +627,7 @@ char const * BtreeIndex::findChainOffsetExactOrPrefix(
memcpy( &chainSize, ptr, sizeof( uint32_t ) ); memcpy( &chainSize, ptr, sizeof( uint32_t ) );
//qDebug( "%s + %s", ptr + sizeof( uint32_t ), ptr + sizeof( uint32_t ) + strlen( ptr + sizeof( uint32_t ) ) + 1 ); //GD_DPRINTF( "%s + %s\n", ptr + sizeof( uint32_t ), ptr + sizeof( uint32_t ) + strlen( ptr + sizeof( uint32_t ) ) + 1 );
ptr += sizeof( uint32_t ) + chainSize; ptr += sizeof( uint32_t ) + chainSize;
} }
@ -639,7 +640,7 @@ char const * BtreeIndex::findChainOffsetExactOrPrefix(
unsigned windowSize = chainOffsets.size(); unsigned windowSize = chainOffsets.size();
for ( ;; ) { for ( ;; ) {
//qDebug( "window = %u, ws = %u", window - &chainOffsets.front(), windowSize ); //GD_DPRINTF( "window = %u, ws = %u\n", window - &chainOffsets.front(), windowSize );
char const ** chainToCheck = window + windowSize / 2; char const ** chainToCheck = window + windowSize / 2;
ptr = *chainToCheck; ptr = *chainToCheck;
@ -1055,7 +1056,7 @@ IndexInfo buildIndex( IndexedWords const & indexedWords, File::Index & file )
btreeMaxElements = BtreeMaxElements; btreeMaxElements = BtreeMaxElements;
} }
qDebug( "Building a tree of %u elements", (unsigned)btreeMaxElements ); GD_DPRINTF( "Building a tree of %u elements\n", (unsigned)btreeMaxElements );
uint32_t lastLeafOffset = 0; uint32_t lastLeafOffset = 0;
@ -1415,7 +1416,7 @@ bool BtreeDictionary::getHeadwords( QStringList & headwords )
} }
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "Failed headwords retrieving for \"%s\", reason: %s", getName().c_str(), ex.what() ); gdWarning( "Failed headwords retrieving for \"%s\", reason: %s\n", getName().c_str(), ex.what() );
} }
return headwords.size() > 0; return headwords.size() > 0;

View file

@ -15,6 +15,7 @@
#include <list> #include <list>
#include <wctype.h> #include <wctype.h>
#include <stdlib.h> #include <stdlib.h>
#include "gddebug.hh"
#include "ftshelpers.hh" #include "ftshelpers.hh"
#include <QDir> #include <QDir>
#include <QUrl> #include <QUrl>
@ -455,14 +456,14 @@ void DictdDictionary::makeFTSIndex( QAtomicInt & isCancelled )
} }
qDebug( "DictD: Building the full-text index for dictionary: %s", getName().c_str() ); gdDebug( "DictD: Building the full-text index for dictionary: %s\n", getName().c_str() );
try { try {
FtsHelpers::makeFTSIndex( this, isCancelled ); FtsHelpers::makeFTSIndex( this, isCancelled );
FTS_index_completed.ref(); FTS_index_completed.ref();
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "DictD: Failed building full-text search index for \"%s\", reason: %s", getName().c_str(), ex.what() ); gdWarning( "DictD: Failed building full-text search index for \"%s\", reason: %s\n", getName().c_str(), ex.what() );
QFile::remove( QString::fromStdString( ftsIdxName ) ); QFile::remove( QString::fromStdString( ftsIdxName ) );
} }
} }
@ -536,7 +537,7 @@ void DictdDictionary::getArticleText( uint32_t articleAddress, QString & headwor
} }
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "DictD: Failed retrieving article from \"%s\", reason: %s", getName().c_str(), ex.what() ); gdWarning( "DictD: Failed retrieving article from \"%s\", reason: %s\n", getName().c_str(), ex.what() );
} }
} }
@ -588,7 +589,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
// Building the index // Building the index
string dictionaryName = nameFromFileName( dictFiles[ 0 ] ); string dictionaryName = nameFromFileName( dictFiles[ 0 ] );
qDebug( "DictD: Building the index for dictionary: %s", dictionaryName.c_str() ); gdDebug( "DictD: Building the index for dictionary: %s\n", dictionaryName.c_str() );
initializing.indexingDictionary( dictionaryName ); initializing.indexingDictionary( dictionaryName );
@ -627,7 +628,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
if ( tab3 ) { if ( tab3 ) {
char * tab4 = strchr( tab3 + 1, '\t' ); char * tab4 = strchr( tab3 + 1, '\t' );
if ( tab4 ) { if ( tab4 ) {
qDebug( "Warning: too many tabs present, skipping: %s", buf ); GD_DPRINTF( "Warning: too many tabs present, skipping: %s\n", buf );
continue; continue;
} }
@ -672,7 +673,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
*endEol = 0; *endEol = 0;
} }
qDebug( "DICT NAME: '%s'", eol ); GD_DPRINTF( "DICT NAME: '%s'\n", eol );
dictionaryName = eol; dictionaryName = eol;
} }
} }
@ -684,12 +685,12 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
} }
} }
else { else {
qDebug( "Warning: only a single tab present, skipping: %s", buf ); GD_DPRINTF( "Warning: only a single tab present, skipping: %s\n", buf );
continue; continue;
} }
} }
else { else {
qDebug( "Warning: no tabs present, skipping: %s", buf ); GD_DPRINTF( "Warning: no tabs present, skipping: %s\n", buf );
continue; continue;
} }
@ -733,7 +734,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
dictionaries.push_back( std::make_shared< DictdDictionary >( dictId, indexFile, dictFiles ) ); dictionaries.push_back( std::make_shared< DictdDictionary >( dictId, indexFile, dictFiles ) );
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "Dictd dictionary \"%s\" reading failed, error: %s", fileName.c_str(), e.what() ); gdWarning( "Dictd dictionary \"%s\" reading failed, error: %s\n", fileName.c_str(), e.what() );
} }
} }

View file

@ -15,6 +15,7 @@
#include "langcoder.hh" #include "langcoder.hh"
#include "wstring_qt.hh" #include "wstring_qt.hh"
#include "indexedzip.hh" #include "indexedzip.hh"
#include "gddebug.hh"
#include "tiff.hh" #include "tiff.hh"
#include "ftshelpers.hh" #include "ftshelpers.hh"
#include <map> #include <map>
@ -374,7 +375,7 @@ void DslDictionary::doDeferredInit()
memcpy( &total, abrvBlock, sizeof( uint32_t ) ); memcpy( &total, abrvBlock, sizeof( uint32_t ) );
abrvBlock += sizeof( uint32_t ); abrvBlock += sizeof( uint32_t );
qDebug( "Loading %u abbrv", total ); GD_DPRINTF( "Loading %u abbrv\n", total );
while ( total-- ) { while ( total-- ) {
uint32_t keySz; uint32_t keySz;
@ -494,7 +495,7 @@ void DslDictionary::loadArticle( uint32_t address,
memcpy( &articleOffset, articleProps, sizeof( articleOffset ) ); memcpy( &articleOffset, articleProps, sizeof( articleOffset ) );
memcpy( &articleSize, articleProps + sizeof( articleOffset ), sizeof( articleSize ) ); memcpy( &articleSize, articleProps + sizeof( articleOffset ), sizeof( articleSize ) );
qDebug( "offset = %x", articleOffset ); GD_DPRINTF( "offset = %x\n", articleOffset );
char * articleBody; char * articleBody;
@ -993,11 +994,11 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node )
result += "<br />"; result += "<br />";
} }
else { else {
qWarning( R"(DSL: Unknown tag "%s" with attributes "%s" found in "%s", article "%s".)", gdWarning( R"(DSL: Unknown tag "%s" with attributes "%s" found in "%s", article "%s".)",
QString::fromStdU32String( node.tagName ).toUtf8().data(), QString::fromStdU32String( node.tagName ).toUtf8().data(),
QString::fromStdU32String( node.tagAttrs ).toUtf8().data(), QString::fromStdU32String( node.tagAttrs ).toUtf8().data(),
getName().c_str(), getName().c_str(),
QString::fromStdU32String( currentHeadword ).toUtf8().data() ); QString::fromStdU32String( currentHeadword ).toUtf8().data() );
result += "<span class=\"dsl_unknown\">[" + string( QString::fromStdU32String( node.tagName ).toUtf8().data() ); result += "<span class=\"dsl_unknown\">[" + string( QString::fromStdU32String( node.tagName ).toUtf8().data() );
if ( !node.tagAttrs.empty() ) { if ( !node.tagAttrs.empty() ) {
@ -1105,14 +1106,14 @@ void DslDictionary::makeFTSIndex( QAtomicInt & isCancelled )
} }
qDebug( "Dsl: Building the full-text index for dictionary: %s", getName().c_str() ); gdDebug( "Dsl: Building the full-text index for dictionary: %s\n", getName().c_str() );
try { try {
FtsHelpers::makeFTSIndex( this, isCancelled ); FtsHelpers::makeFTSIndex( this, isCancelled );
FTS_index_completed.ref(); FTS_index_completed.ref();
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "DSL: Failed building full-text search index for \"%s\", reason: %s", getName().c_str(), ex.what() ); gdWarning( "DSL: Failed building full-text search index for \"%s\", reason: %s\n", getName().c_str(), ex.what() );
QFile::remove( ftsIdxName.c_str() ); QFile::remove( ftsIdxName.c_str() );
} }
} }
@ -1533,7 +1534,7 @@ void DslArticleRequest::run()
articleText += articleAfter; articleText += articleAfter;
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "DSL: Failed loading article from \"%s\", reason: %s", dict.getName().c_str(), ex.what() ); gdWarning( "DSL: Failed loading article from \"%s\", reason: %s\n", dict.getName().c_str(), ex.what() );
articleText = articleText =
string( "<span class=\"dsl_article\">" ) + QObject::tr( "Article loading error" ).toStdString() + "</span>"; string( "<span class=\"dsl_article\">" ) + QObject::tr( "Article loading error" ).toStdString() + "</span>";
} }
@ -1608,7 +1609,7 @@ void DslResourceRequest::run()
string n = dict.getContainingFolder().toStdString() + Utils::Fs::separator() + resourceName; string n = dict.getContainingFolder().toStdString() + Utils::Fs::separator() + resourceName;
qDebug( "dsl resource name is %s", n.c_str() ); GD_DPRINTF( "dsl resource name is %s\n", n.c_str() );
try { try {
try { try {
@ -1660,10 +1661,10 @@ void DslResourceRequest::run()
hasAnyData = true; hasAnyData = true;
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "DSL: Failed loading resource \"%s\" for \"%s\", reason: %s", gdWarning( "DSL: Failed loading resource \"%s\" for \"%s\", reason: %s\n",
resourceName.c_str(), resourceName.c_str(),
dict.getName().c_str(), dict.getName().c_str(),
ex.what() ); ex.what() );
// Resource not loaded -- we don't set the hasAnyData flag then // Resource not loaded -- we don't set the hasAnyData flag then
} }
@ -1768,8 +1769,8 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
// Building the index // Building the index
initializing.indexingDictionary( Utf8::encode( scanner.getDictionaryName() ) ); initializing.indexingDictionary( Utf8::encode( scanner.getDictionaryName() ) );
qDebug( "Dsl: Building the index for dictionary: %s", gdDebug( "Dsl: Building the index for dictionary: %s\n",
QString::fromStdU32String( scanner.getDictionaryName() ).toUtf8().data() ); QString::fromStdU32String( scanner.getDictionaryName() ).toUtf8().data() );
File::Index idx( indexFile, QIODevice::WriteOnly ); File::Index idx( indexFile, QIODevice::WriteOnly );
@ -1835,7 +1836,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
expandOptionalParts( curString, &keys ); expandOptionalParts( curString, &keys );
if ( !abrvScanner.readNextLineWithoutComments( curString, curOffset ) || curString.empty() ) { if ( !abrvScanner.readNextLineWithoutComments( curString, curOffset ) || curString.empty() ) {
qWarning( "Premature end of file %s", abrvFileName.c_str() ); gdWarning( "Premature end of file %s\n", abrvFileName.c_str() );
eof = true; eof = true;
break; break;
} }
@ -1874,7 +1875,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
chunks.addToBlock( &sz, sizeof( uint32_t ) ); chunks.addToBlock( &sz, sizeof( uint32_t ) );
for ( const auto & i : abrv ) { for ( const auto & i : abrv ) {
// qDebug( "%s:%s", i->first.c_str(), i->second.c_str() ); // GD_DPRINTF( "%s:%s\n", i->first.c_str(), i->second.c_str() );
sz = i.first.size(); sz = i.first.size();
chunks.addToBlock( &sz, sizeof( uint32_t ) ); chunks.addToBlock( &sz, sizeof( uint32_t ) );
@ -1885,7 +1886,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
} }
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "Error reading abrv file \"%s\", error: %s. Skipping it.", abrvFileName.c_str(), e.what() ); gdWarning( "Error reading abrv file \"%s\", error: %s. Skipping it.\n", abrvFileName.c_str(), e.what() );
} }
} }
@ -1915,7 +1916,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
// characters are blank, too. // characters are blank, too.
for ( size_t x = 1; x < curString.size(); ++x ) { for ( size_t x = 1; x < curString.size(); ++x ) {
if ( !isDslWs( curString[ x ] ) ) { if ( !isDslWs( curString[ x ] ) ) {
qWarning( "Garbage string in %s at offset 0x%lX", fileName.c_str(), curOffset ); gdWarning( "Garbage string in %s at offset 0x%lX\n", fileName.c_str(), curOffset );
break; break;
} }
} }
@ -1931,13 +1932,13 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
uint32_t articleOffset = curOffset; uint32_t articleOffset = curOffset;
//qDebug( "Headword: %ls", curString.c_str() ); //GD_DPRINTF( "Headword: %ls\n", curString.c_str() );
// More headwords may follow // More headwords may follow
for ( ;; ) { for ( ;; ) {
if ( !( hasString = scanner.readNextLineWithoutComments( curString, curOffset ) ) ) { if ( !( hasString = scanner.readNextLineWithoutComments( curString, curOffset ) ) ) {
qWarning( "Premature end of file %s", fileName.c_str() ); gdWarning( "Premature end of file %s\n", fileName.c_str() );
break; break;
} }
@ -1995,11 +1996,11 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
if ( !hasString || ( curString.size() && !isDslWs( curString[ 0 ] ) ) ) { if ( !hasString || ( curString.size() && !isDslWs( curString[ 0 ] ) ) ) {
if ( insideInsided ) { if ( insideInsided ) {
qWarning( "Unclosed tag '@' at line %i", dogLine ); gdWarning( "Unclosed tag '@' at line %i", dogLine );
insidedCards.append( InsidedCard( offset, curOffset - offset, insidedHeadwords ) ); insidedCards.append( InsidedCard( offset, curOffset - offset, insidedHeadwords ) );
} }
if ( noSignificantLines ) { if ( noSignificantLines ) {
qWarning( "Orphan headword at line %i", headwordLine ); gdWarning( "Orphan headword at line %i", headwordLine );
} }
break; break;
@ -2013,7 +2014,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
} }
else { else {
if ( wasEmptyLine && !Folding::applyWhitespaceOnly( curString ).empty() ) { if ( wasEmptyLine && !Folding::applyWhitespaceOnly( curString ).empty() ) {
qWarning( "Orphan string at line %i", scanner.getLinesRead() - 1 ); gdWarning( "Orphan string at line %i", scanner.getLinesRead() - 1 );
} }
} }
@ -2034,7 +2035,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
else { else {
// Embedded card tag must be placed at first position in line after spaces // Embedded card tag must be placed at first position in line after spaces
if ( !isAtSignFirst( curString ) ) { if ( !isAtSignFirst( curString ) ) {
qWarning( "Unescaped '@' symbol at line %i", scanner.getLinesRead() - 1 ); gdWarning( "Unescaped '@' symbol at line %i", scanner.getLinesRead() - 1 );
if ( insideInsided ) { if ( insideInsided ) {
linesInsideCard++; linesInsideCard++;
@ -2124,7 +2125,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
// If there was a zip file, index it too // If there was a zip file, index it too
if ( zipFileName.size() ) { if ( zipFileName.size() ) {
qDebug( "Indexing zip file" ); GD_DPRINTF( "Indexing zip file\n" );
idxHeader.hasZipFile = 1; idxHeader.hasZipFile = 1;
@ -2180,7 +2181,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
dictionaries.push_back( std::make_shared< DslDictionary >( dictId, indexFile, dictFiles ) ); dictionaries.push_back( std::make_shared< DslDictionary >( dictId, indexFile, dictFiles ) );
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "DSL dictionary reading failed: %s:%u, error: %s", fileName.c_str(), atLine, e.what() ); gdWarning( "DSL dictionary reading failed: %s:%u, error: %s\n", fileName.c_str(), atLine, e.what() );
} }
} }

View file

@ -5,6 +5,7 @@
#include "folding.hh" #include "folding.hh"
#include "langcoder.hh" #include "langcoder.hh"
#include "gddebug.hh"
#include "ufile.hh" #include "ufile.hh"
#include "utf8.hh" #include "utf8.hh"
@ -118,10 +119,10 @@ ArticleDom::ArticleDom( wstring const & str, string const & dictName, wstring co
if ( !atSignFirstInLine() ) { if ( !atSignFirstInLine() ) {
// Not insided card // Not insided card
if ( dictName.empty() ) { if ( dictName.empty() ) {
qWarning( "Unescaped '@' symbol found" ); gdWarning( "Unescaped '@' symbol found" );
} }
else { else {
qWarning( "Unescaped '@' symbol found in \"%s\"", dictName.c_str() ); gdWarning( "Unescaped '@' symbol found in \"%s\"", dictName.c_str() );
} }
} }
else { else {
@ -245,16 +246,16 @@ ArticleDom::ArticleDom( wstring const & str, string const & dictName, wstring co
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
if ( !dictionaryName.empty() ) { if ( !dictionaryName.empty() ) {
qWarning( R"(DSL: Unfinished tag "%s" with attributes "%s" found in "%s", article "%s".)", gdWarning( R"(DSL: Unfinished tag "%s" with attributes "%s" found in "%s", article "%s".)",
QString::fromStdU32String( name ).toUtf8().data(), QString::fromStdU32String( name ).toUtf8().data(),
QString::fromStdU32String( attrs ).toUtf8().data(), QString::fromStdU32String( attrs ).toUtf8().data(),
dictionaryName.c_str(), dictionaryName.c_str(),
QString::fromStdU32String( headword ).toUtf8().data() ); QString::fromStdU32String( headword ).toUtf8().data() );
} }
else { else {
qWarning( R"(DSL: Unfinished tag "%s" with attributes "%s" found)", gdWarning( R"(DSL: Unfinished tag "%s" with attributes "%s" found)",
QString::fromStdU32String( name ).toUtf8().data(), QString::fromStdU32String( name ).toUtf8().data(),
QString::fromStdU32String( attrs ).toUtf8().data() ); QString::fromStdU32String( attrs ).toUtf8().data() );
} }
throw ex; throw ex;
@ -677,16 +678,16 @@ ArticleDom::ArticleDom( wstring const & str, string const & dictName, wstring co
unsigned const unclosedTagCount = 1 + std::count_if( it, stack.end(), MustTagBeClosed() ); unsigned const unclosedTagCount = 1 + std::count_if( it, stack.end(), MustTagBeClosed() );
if ( dictName.empty() ) { if ( dictName.empty() ) {
qWarning( "Warning: %u tag(s) were unclosed, first tag name \"%s\".", gdWarning( "Warning: %u tag(s) were unclosed, first tag name \"%s\".\n",
unclosedTagCount, unclosedTagCount,
firstTagName.constData() ); firstTagName.constData() );
} }
else { else {
qWarning( "Warning: %u tag(s) were unclosed in \"%s\", article \"%s\", first tag name \"%s\".", gdWarning( "Warning: %u tag(s) were unclosed in \"%s\", article \"%s\", first tag name \"%s\".\n",
unclosedTagCount, unclosedTagCount,
dictName.c_str(), dictName.c_str(),
QString::fromStdU32String( headword ).toUtf8().constData(), QString::fromStdU32String( headword ).toUtf8().constData(),
firstTagName.constData() ); firstTagName.constData() );
} }
} }
} }
@ -786,14 +787,14 @@ void ArticleDom::closeTag( wstring const & name, list< Node * > & stack, bool wa
} }
else if ( warn ) { else if ( warn ) {
if ( !dictionaryName.empty() ) { if ( !dictionaryName.empty() ) {
qWarning( R"(No corresponding opening tag for closing tag "%s" found in "%s", article "%s".)", gdWarning( R"(No corresponding opening tag for closing tag "%s" found in "%s", article "%s".)",
QString::fromStdU32String( name ).toUtf8().data(), QString::fromStdU32String( name ).toUtf8().data(),
dictionaryName.c_str(), dictionaryName.c_str(),
QString::fromStdU32String( headword ).toUtf8().data() ); QString::fromStdU32String( headword ).toUtf8().data() );
} }
else { else {
qWarning( "No corresponding opening tag for closing tag \"%s\" found.", gdWarning( "No corresponding opening tag for closing tag \"%s\" found.",
QString::fromStdU32String( name ).toUtf8().data() ); QString::fromStdU32String( name ).toUtf8().data() );
} }
} }
} }
@ -974,7 +975,7 @@ DslScanner::DslScanner( string const & fileName ):
// The encoding // The encoding
if ( !needExactEncoding ) { if ( !needExactEncoding ) {
// We don't need that! // We don't need that!
qWarning( "Warning: encoding was specified in a Unicode file, ignoring." ); GD_FDPRINTF( stderr, "Warning: encoding was specified in a Unicode file, ignoring.\n" );
} }
else if ( !arg.compare( U"Latin" ) ) { else if ( !arg.compare( U"Latin" ) ) {
encoding = Utf8::Windows1252; encoding = Utf8::Windows1252;
@ -1120,7 +1121,7 @@ void processUnsortedParts( wstring & str, bool strip )
--refCount; --refCount;
if ( refCount < 0 ) { if ( refCount < 0 ) {
qWarning( "Warning: an unmatched closing brace was encountered." ); GD_FDPRINTF( stderr, "Warning: an unmatched closing brace was encountered.\n" );
refCount = 0; refCount = 0;
// But we remove that thing either way // But we remove that thing either way
str.erase( x, 1 ); str.erase( x, 1 );
@ -1145,7 +1146,7 @@ void processUnsortedParts( wstring & str, bool strip )
} }
if ( strip && refCount ) { if ( strip && refCount ) {
qWarning( "Warning: unclosed brace(s) encountered." ); GD_FDPRINTF( stderr, "Warning: unclosed brace(s) encountered.\n" );
str.erase( startPos ); str.erase( startPos );
} }
} }

View file

@ -12,6 +12,7 @@
#include <string> #include <string>
#include "btreeidx.hh" #include "btreeidx.hh"
#include "folding.hh" #include "folding.hh"
#include "gddebug.hh"
#include "chunkedstorage.hh" #include "chunkedstorage.hh"
#include "filetype.hh" #include "filetype.hh"
#include "ftshelpers.hh" #include "ftshelpers.hh"
@ -413,14 +414,16 @@ void EpwingDictionary::makeFTSIndex( QAtomicInt & isCancelled )
return; return;
qDebug( "Epwing: Building the full-text index for dictionary: %s", getName().c_str() ); gdDebug( "Epwing: Building the full-text index for dictionary: %s\n", getName().c_str() );
try { try {
FtsHelpers::makeFTSIndex( this, isCancelled ); FtsHelpers::makeFTSIndex( this, isCancelled );
FTS_index_completed.ref(); FTS_index_completed.ref();
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "Epwing: Failed building full-text search index for \"%s\", reason: %s", getName().c_str(), ex.what() ); gdWarning( "Epwing: Failed building full-text search index for \"%s\", reason: %s\n",
getName().c_str(),
ex.what() );
QFile::remove( QString::fromStdString( ftsIdxName ) ); QFile::remove( QString::fromStdString( ftsIdxName ) );
} }
} }
@ -859,10 +862,10 @@ void EpwingResourceRequest::run()
} }
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "Epwing: Failed loading resource \"%s\" for \"%s\", reason: %s", gdWarning( "Epwing: Failed loading resource \"%s\" for \"%s\", reason: %s\n",
resourceName.c_str(), resourceName.c_str(),
dict.getName().c_str(), dict.getName().c_str(),
ex.what() ); ex.what() );
// Resource not loaded -- we don't set the hasAnyData flag then // Resource not loaded -- we don't set the hasAnyData flag then
} }
@ -1136,7 +1139,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
subBooksNumber = dict.setBook( mainDirectory ); subBooksNumber = dict.setBook( mainDirectory );
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "Epwing dictionary initializing failed: %s, error: %s", mainDirectory.c_str(), e.what() ); gdWarning( "Epwing dictionary initializing failed: %s, error: %s\n", mainDirectory.c_str(), e.what() );
continue; continue;
} }
@ -1171,7 +1174,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
string indexFile = indicesDir + dictId; string indexFile = indicesDir + dictId;
if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) || indexIsOldOrBad( indexFile ) ) { if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) || indexIsOldOrBad( indexFile ) ) {
qDebug( "Epwing: Building the index for dictionary in directory %s", dir.toUtf8().data() ); gdDebug( "Epwing: Building the index for dictionary in directory %s\n", dir.toUtf8().data() );
QString str = dict.title(); QString str = dict.title();
QByteArray nameData = str.toUtf8(); QByteArray nameData = str.toUtf8();
@ -1251,7 +1254,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
dictionaries.push_back( std::make_shared< EpwingDictionary >( dictId, indexFile, dictFiles, sb ) ); dictionaries.push_back( std::make_shared< EpwingDictionary >( dictId, indexFile, dictFiles, sb ) );
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "Epwing dictionary initializing failed: %s, error: %s", dir.toUtf8().data(), e.what() ); gdWarning( "Epwing dictionary initializing failed: %s, error: %s\n", dir.toUtf8().data(), e.what() );
continue; continue;
} }
} }

View file

@ -9,6 +9,8 @@
#include <QTextStream> #include <QTextStream>
#include <QTextDocumentFragment> #include <QTextDocumentFragment>
#include <QHash> #include <QHash>
#include "gddebug.hh"
#include "audiolink.hh" #include "audiolink.hh"
#include "wstring.hh" #include "wstring.hh"
#include "wstring_qt.hh" #include "wstring_qt.hh"
@ -575,7 +577,7 @@ QString EpwingBook::createCacheDir( QString const & dirName )
QFileInfo info( mainCacheDir ); QFileInfo info( mainCacheDir );
if ( !info.exists() || !info.isDir() ) { if ( !info.exists() || !info.isDir() ) {
if ( !dir.mkdir( mainCacheDir ) ) { if ( !dir.mkdir( mainCacheDir ) ) {
qWarning( "Epwing: can't create cache directory \"%s\"", mainCacheDir.toUtf8().data() ); gdWarning( "Epwing: can't create cache directory \"%s\"", mainCacheDir.toUtf8().data() );
return {}; return {};
} }
} }
@ -584,7 +586,7 @@ QString EpwingBook::createCacheDir( QString const & dirName )
info = QFileInfo( cacheDir ); info = QFileInfo( cacheDir );
if ( !info.exists() || !info.isDir() ) { if ( !info.exists() || !info.isDir() ) {
if ( !dir.mkdir( cacheDir ) ) { if ( !dir.mkdir( cacheDir ) ) {
qWarning( "Epwing: can't create cache directory \"%s\"", cacheDir.toUtf8().data() ); gdWarning( "Epwing: can't create cache directory \"%s\"", cacheDir.toUtf8().data() );
return {}; return {};
} }
} }
@ -1261,7 +1263,7 @@ const char * EpwingBook::beginDecoration( unsigned int code )
str = "<sup>"; str = "<sup>";
break; break;
default: default:
qWarning( "Epwing: Unknown decoration code %i", code ); gdWarning( "Epwing: Unknown decoration code %i", code );
code = UNKNOWN; code = UNKNOWN;
break; break;
} }
@ -1283,7 +1285,7 @@ const char * EpwingBook::endDecoration( unsigned int code )
storedCode = decorationStack.pop(); storedCode = decorationStack.pop();
if ( storedCode != code ) { if ( storedCode != code ) {
qWarning( "Epwing: tags mismatch detected" ); gdWarning( "Epwing: tags mismatch detected" );
if ( storedCode == UNKNOWN ) if ( storedCode == UNKNOWN )
storedCode = code; storedCode = code;
} }
@ -1403,7 +1405,7 @@ QByteArray EpwingBook::handleColorImage( EB_Hook_Code code, const unsigned int *
EB_Error_Code ret = eb_set_binary_color_graphic( &book, &pos ); EB_Error_Code ret = eb_set_binary_color_graphic( &book, &pos );
if ( ret != EB_SUCCESS ) { if ( ret != EB_SUCCESS ) {
setErrorString( "eb_set_binary_color_graphic", ret ); setErrorString( "eb_set_binary_color_graphic", ret );
qWarning( "Epwing image retrieve error: %s", error_string.toUtf8().data() ); gdWarning( "Epwing image retrieve error: %s", error_string.toUtf8().data() );
return QByteArray(); return QByteArray();
} }
@ -1441,7 +1443,7 @@ QByteArray EpwingBook::handleColorImage( EB_Hook_Code code, const unsigned int *
ret = eb_read_binary( &book, BinaryBufferSize, buffer.data(), &length ); ret = eb_read_binary( &book, BinaryBufferSize, buffer.data(), &length );
if ( ret != EB_SUCCESS ) { if ( ret != EB_SUCCESS ) {
setErrorString( "eb_read_binary", ret ); setErrorString( "eb_read_binary", ret );
qWarning( "Epwing image retrieve error: %s", error_string.toUtf8().data() ); gdWarning( "Epwing image retrieve error: %s", error_string.toUtf8().data() );
break; break;
} }
@ -1478,7 +1480,7 @@ QByteArray EpwingBook::handleMonoImage( EB_Hook_Code code, const unsigned int *
EB_Error_Code ret = eb_set_binary_mono_graphic( &book, &pos, monoWidth, monoHeight ); EB_Error_Code ret = eb_set_binary_mono_graphic( &book, &pos, monoWidth, monoHeight );
if ( ret != EB_SUCCESS ) { if ( ret != EB_SUCCESS ) {
setErrorString( "eb_set_binary_mono_graphic", ret ); setErrorString( "eb_set_binary_mono_graphic", ret );
qWarning( "Epwing image retrieve error: %s", error_string.toUtf8().data() ); gdWarning( "Epwing image retrieve error: %s", error_string.toUtf8().data() );
return QByteArray(); return QByteArray();
} }
@ -1513,7 +1515,7 @@ QByteArray EpwingBook::handleMonoImage( EB_Hook_Code code, const unsigned int *
ret = eb_read_binary( &book, BinaryBufferSize, buffer.data(), &length ); ret = eb_read_binary( &book, BinaryBufferSize, buffer.data(), &length );
if ( ret != EB_SUCCESS ) { if ( ret != EB_SUCCESS ) {
setErrorString( "eb_read_binary", ret ); setErrorString( "eb_read_binary", ret );
qWarning( "Epwing image retrieve error: %s", error_string.toUtf8().data() ); gdWarning( "Epwing image retrieve error: %s", error_string.toUtf8().data() );
break; break;
} }
@ -1583,7 +1585,7 @@ QByteArray EpwingBook::handleWave( EB_Hook_Code code, const unsigned int * argv
EB_Error_Code ret = eb_read_binary( &book, BinaryBufferSize, buffer.data(), &length ); EB_Error_Code ret = eb_read_binary( &book, BinaryBufferSize, buffer.data(), &length );
if ( ret != EB_SUCCESS ) { if ( ret != EB_SUCCESS ) {
setErrorString( "eb_read_binary", ret ); setErrorString( "eb_read_binary", ret );
qWarning( "Epwing sound retrieve error: %s", error_string.toUtf8().data() ); gdWarning( "Epwing sound retrieve error: %s", error_string.toUtf8().data() );
break; break;
} }
@ -1650,7 +1652,7 @@ QByteArray EpwingBook::handleMpeg( EB_Hook_Code code, const unsigned int * argv
EB_Error_Code ret = eb_read_binary( &book, BinaryBufferSize, buffer.data(), &length ); EB_Error_Code ret = eb_read_binary( &book, BinaryBufferSize, buffer.data(), &length );
if ( ret != EB_SUCCESS ) { if ( ret != EB_SUCCESS ) {
setErrorString( "eb_read_binary", ret ); setErrorString( "eb_read_binary", ret );
qWarning( "Epwing movie retrieve error: %s", error_string.toUtf8().data() ); gdWarning( "Epwing movie retrieve error: %s", error_string.toUtf8().data() );
break; break;
} }
@ -1718,7 +1720,7 @@ QByteArray EpwingBook::handleNarrowFont( const unsigned int * argv, bool text_on
EB_Error_Code ret = eb_narrow_font_character_bitmap( &book, *argv, bitmap ); EB_Error_Code ret = eb_narrow_font_character_bitmap( &book, *argv, bitmap );
if ( ret != EB_SUCCESS ) { if ( ret != EB_SUCCESS ) {
setErrorString( "eb_narrow_font_character_bitmap", ret ); setErrorString( "eb_narrow_font_character_bitmap", ret );
qWarning( "Epwing: Font retrieve error: %s", error_string.toUtf8().data() ); gdWarning( "Epwing: Font retrieve error: %s", error_string.toUtf8().data() );
return QByteArray( "?" ); return QByteArray( "?" );
} }
@ -1727,7 +1729,7 @@ QByteArray EpwingBook::handleNarrowFont( const unsigned int * argv, bool text_on
ret = eb_bitmap_to_png( bitmap, 8, 16, buff, &nlen ); ret = eb_bitmap_to_png( bitmap, 8, 16, buff, &nlen );
if ( ret != EB_SUCCESS ) { if ( ret != EB_SUCCESS ) {
setErrorString( "eb_bitmap_to_png", ret ); setErrorString( "eb_bitmap_to_png", ret );
qWarning( "Epwing: Font retrieve error: %s", error_string.toUtf8().data() ); gdWarning( "Epwing: Font retrieve error: %s", error_string.toUtf8().data() );
return QByteArray( "?" ); return QByteArray( "?" );
} }
@ -1782,7 +1784,7 @@ QByteArray EpwingBook::handleWideFont( const unsigned int * argv, bool text_only
EB_Error_Code ret = eb_wide_font_character_bitmap( &book, *argv, bitmap ); EB_Error_Code ret = eb_wide_font_character_bitmap( &book, *argv, bitmap );
if ( ret != EB_SUCCESS ) { if ( ret != EB_SUCCESS ) {
setErrorString( "eb_wide_font_character_bitmap", ret ); setErrorString( "eb_wide_font_character_bitmap", ret );
qWarning( "Epwing: Font retrieve error: %s", error_string.toUtf8().data() ); gdWarning( "Epwing: Font retrieve error: %s", error_string.toUtf8().data() );
return QByteArray( "?" ); return QByteArray( "?" );
} }
@ -1791,7 +1793,7 @@ QByteArray EpwingBook::handleWideFont( const unsigned int * argv, bool text_only
ret = eb_bitmap_to_png( bitmap, 16, 16, buff, &wlen ); ret = eb_bitmap_to_png( bitmap, 16, 16, buff, &wlen );
if ( ret != EB_SUCCESS ) { if ( ret != EB_SUCCESS ) {
setErrorString( "eb_bitmap_to_png", ret ); setErrorString( "eb_bitmap_to_png", ret );
qWarning( "Epwing: Font retrieve error: %s", error_string.toUtf8().data() ); gdWarning( "Epwing: Font retrieve error: %s", error_string.toUtf8().data() );
return QByteArray( "?" ); return QByteArray( "?" );
} }
@ -1871,14 +1873,14 @@ bool EpwingBook::getMatches( QString word, QList< QString > & matches )
EB_Error_Code ret = eb_search_word( &book, bword.data() ); EB_Error_Code ret = eb_search_word( &book, bword.data() );
if ( ret != EB_SUCCESS ) { if ( ret != EB_SUCCESS ) {
setErrorString( "eb_search_word", ret ); setErrorString( "eb_search_word", ret );
qWarning( "Epwing word search error: %s", error_string.toUtf8().data() ); gdWarning( "Epwing word search error: %s", error_string.toUtf8().data() );
return false; return false;
} }
ret = eb_hit_list( &book, 10, hits, &hitCount ); ret = eb_hit_list( &book, 10, hits, &hitCount );
if ( ret != EB_SUCCESS ) { if ( ret != EB_SUCCESS ) {
setErrorString( "eb_hit_list", ret ); setErrorString( "eb_hit_list", ret );
qWarning( "Epwing word search error: %s", error_string.toUtf8().data() ); gdWarning( "Epwing word search error: %s", error_string.toUtf8().data() );
return false; return false;
} }
} }
@ -1887,14 +1889,14 @@ bool EpwingBook::getMatches( QString word, QList< QString > & matches )
EB_Error_Code ret = eb_search_word( &book, bword2.data() ); EB_Error_Code ret = eb_search_word( &book, bword2.data() );
if ( ret != EB_SUCCESS ) { if ( ret != EB_SUCCESS ) {
setErrorString( "eb_search_word", ret ); setErrorString( "eb_search_word", ret );
qWarning( "Epwing word search error: %s", error_string.toUtf8().data() ); gdWarning( "Epwing word search error: %s", error_string.toUtf8().data() );
return false; return false;
} }
ret = eb_hit_list( &book, 10, hits, &hitCount ); ret = eb_hit_list( &book, 10, hits, &hitCount );
if ( ret != EB_SUCCESS ) { if ( ret != EB_SUCCESS ) {
setErrorString( "eb_hit_list", ret ); setErrorString( "eb_hit_list", ret );
qWarning( "Epwing word search error: %s", error_string.toUtf8().data() ); gdWarning( "Epwing word search error: %s", error_string.toUtf8().data() );
return false; return false;
} }
} }
@ -1942,14 +1944,14 @@ bool EpwingBook::getArticlePos( QString word, QList< int > & pages, QList< int >
EB_Error_Code ret = eb_search_exactword( &book, bword.data() ); EB_Error_Code ret = eb_search_exactword( &book, bword.data() );
if ( ret != EB_SUCCESS ) { if ( ret != EB_SUCCESS ) {
setErrorString( "eb_search_word", ret ); setErrorString( "eb_search_word", ret );
qWarning( "Epwing word search error: %s", error_string.toUtf8().data() ); gdWarning( "Epwing word search error: %s", error_string.toUtf8().data() );
return false; return false;
} }
ret = eb_hit_list( &book, HitsBufferSize, hits, &hitCount ); ret = eb_hit_list( &book, HitsBufferSize, hits, &hitCount );
if ( ret != EB_SUCCESS ) { if ( ret != EB_SUCCESS ) {
setErrorString( "eb_hit_list", ret ); setErrorString( "eb_hit_list", ret );
qWarning( "Epwing word search error: %s", error_string.toUtf8().data() ); gdWarning( "Epwing word search error: %s", error_string.toUtf8().data() );
return false; return false;
} }
} }
@ -1958,14 +1960,14 @@ bool EpwingBook::getArticlePos( QString word, QList< int > & pages, QList< int >
EB_Error_Code ret = eb_search_exactword( &book, bword2.data() ); EB_Error_Code ret = eb_search_exactword( &book, bword2.data() );
if ( ret != EB_SUCCESS ) { if ( ret != EB_SUCCESS ) {
setErrorString( "eb_search_word", ret ); setErrorString( "eb_search_word", ret );
qWarning( "Epwing word search error: %s", error_string.toUtf8().data() ); gdWarning( "Epwing word search error: %s", error_string.toUtf8().data() );
return false; return false;
} }
ret = eb_hit_list( &book, HitsBufferSize, hits, &hitCount ); ret = eb_hit_list( &book, HitsBufferSize, hits, &hitCount );
if ( ret != EB_SUCCESS ) { if ( ret != EB_SUCCESS ) {
setErrorString( "eb_hit_list", ret ); setErrorString( "eb_hit_list", ret );
qWarning( "Epwing word search error: %s", error_string.toUtf8().data() ); gdWarning( "Epwing word search error: %s", error_string.toUtf8().data() );
return false; return false;
} }
} }

View file

@ -10,6 +10,7 @@
#include "audiolink.hh" #include "audiolink.hh"
#include "htmlescape.hh" #include "htmlescape.hh"
#include "utf8.hh" #include "utf8.hh"
#include "gddebug.hh"
namespace Forvo { namespace Forvo {
@ -163,7 +164,7 @@ ForvoArticleRequest::ForvoArticleRequest( wstring const & str,
void ForvoArticleRequest::addQuery( QNetworkAccessManager & mgr, wstring const & str ) void ForvoArticleRequest::addQuery( QNetworkAccessManager & mgr, wstring const & str )
{ {
qDebug( "Forvo: requesting article %s", QString::fromStdU32String( str ).toUtf8().data() ); gdDebug( "Forvo: requesting article %s\n", QString::fromStdU32String( str ).toUtf8().data() );
QString key = apiKey; QString key = apiKey;
@ -178,7 +179,7 @@ void ForvoArticleRequest::addQuery( QNetworkAccessManager & mgr, wstring const &
+ "/language/" + languageCode + "/order/rate-desc" ) + "/language/" + languageCode + "/order/rate-desc" )
.toUtf8() ); .toUtf8() );
// qDebug( "req: %s", reqUrl.toEncoded().data() ); // GD_DPRINTF( "req: %s\n", reqUrl.toEncoded().data() );
sptr< QNetworkReply > netReply = std::shared_ptr< QNetworkReply >( mgr.get( QNetworkRequest( reqUrl ) ) ); sptr< QNetworkReply > netReply = std::shared_ptr< QNetworkReply >( mgr.get( QNetworkRequest( reqUrl ) ) );
@ -187,7 +188,7 @@ void ForvoArticleRequest::addQuery( QNetworkAccessManager & mgr, wstring const &
void ForvoArticleRequest::requestFinished( QNetworkReply * r ) void ForvoArticleRequest::requestFinished( QNetworkReply * r )
{ {
qDebug( "Finished." ); GD_DPRINTF( "Finished.\n" );
if ( isFinished() ) { // Was cancelled if ( isFinished() ) { // Was cancelled
return; return;
@ -226,7 +227,7 @@ void ForvoArticleRequest::requestFinished( QNetworkReply * r )
QString( tr( "XML parse error: %1 at %2,%3" ).arg( errorStr ).arg( errorLine ).arg( errorColumn ) ) ); QString( tr( "XML parse error: %1 at %2,%3" ).arg( errorStr ).arg( errorLine ).arg( errorColumn ) ) );
} }
else { else {
// qDebug( "%s", dd.toByteArray().data() ); // GD_DPRINTF( "%s\n", dd.toByteArray().data() );
QDomNode items = dd.namedItem( "items" ); QDomNode items = dd.namedItem( "items" );
@ -329,7 +330,7 @@ void ForvoArticleRequest::requestFinished( QNetworkReply * r )
setErrorString( text ); setErrorString( text );
} }
} }
qDebug( "done." ); GD_DPRINTF( "done.\n" );
} }
else { else {
setErrorString( netReply->errorString() ); setErrorString( netReply->errorString() );

View file

@ -8,6 +8,7 @@
#include "ufile.hh" #include "ufile.hh"
#include "btreeidx.hh" #include "btreeidx.hh"
#include "folding.hh" #include "folding.hh"
#include "gddebug.hh"
#include "utf8.hh" #include "utf8.hh"
#include "wstring_qt.hh" #include "wstring_qt.hh"
#include "chunkedstorage.hh" #include "chunkedstorage.hh"
@ -522,7 +523,7 @@ QString const & GlsDictionary::getDescription()
} }
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "GLS dictionary description reading failed: %s, error: %s", getName().c_str(), e.what() ); gdWarning( "GLS dictionary description reading failed: %s, error: %s\n", getName().c_str(), e.what() );
} }
if ( dictionaryDescription.isEmpty() ) { if ( dictionaryDescription.isEmpty() ) {
@ -553,14 +554,14 @@ void GlsDictionary::makeFTSIndex( QAtomicInt & isCancelled )
} }
qDebug( "Gls: Building the full-text index for dictionary: %s", getName().c_str() ); gdDebug( "Gls: Building the full-text index for dictionary: %s\n", getName().c_str() );
try { try {
FtsHelpers::makeFTSIndex( this, isCancelled ); FtsHelpers::makeFTSIndex( this, isCancelled );
FTS_index_completed.ref(); FTS_index_completed.ref();
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "Gls: Failed building full-text search index for \"%s\", reason: %s", getName().c_str(), ex.what() ); gdWarning( "Gls: Failed building full-text search index for \"%s\", reason: %s\n", getName().c_str(), ex.what() );
QFile::remove( ftsIdxName.c_str() ); QFile::remove( ftsIdxName.c_str() );
} }
} }
@ -801,7 +802,7 @@ void GlsDictionary::getArticleText( uint32_t articleAddress, QString & headword,
text = Html::unescape( QString::fromStdString( articleStr ) ); text = Html::unescape( QString::fromStdString( articleStr ) );
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "Gls: Failed retrieving article from \"%s\", reason: %s", getName().c_str(), ex.what() ); gdWarning( "Gls: Failed retrieving article from \"%s\", reason: %s\n", getName().c_str(), ex.what() );
} }
} }
@ -1081,7 +1082,7 @@ void GlsResourceRequest::run()
try { try {
string n = dict.getContainingFolder().toStdString() + Utils::Fs::separator() + resourceName; string n = dict.getContainingFolder().toStdString() + Utils::Fs::separator() + resourceName;
qDebug( "gls resource name is %s", n.c_str() ); GD_DPRINTF( "gls resource name is %s\n", n.c_str() );
try { try {
QMutexLocker _( &dataMutex ); QMutexLocker _( &dataMutex );
@ -1166,10 +1167,10 @@ void GlsResourceRequest::run()
hasAnyData = true; hasAnyData = true;
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "GLS: Failed loading resource \"%s\" for \"%s\", reason: %s", gdWarning( "GLS: Failed loading resource \"%s\" for \"%s\", reason: %s\n",
resourceName.c_str(), resourceName.c_str(),
dict.getName().c_str(), dict.getName().c_str(),
ex.what() ); ex.what() );
// Resource not loaded -- we don't set the hasAnyData flag then // Resource not loaded -- we don't set the hasAnyData flag then
} }
@ -1246,8 +1247,8 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
// Building the index // Building the index
initializing.indexingDictionary( Utf8::encode( scanner.getDictionaryName() ) ); initializing.indexingDictionary( Utf8::encode( scanner.getDictionaryName() ) );
qDebug( "Gls: Building the index for dictionary: %s", gdDebug( "Gls: Building the index for dictionary: %s\n",
QString::fromStdU32String( scanner.getDictionaryName() ).toUtf8().data() ); QString::fromStdU32String( scanner.getDictionaryName() ).toUtf8().data() );
File::Index idx( indexFile, QIODevice::WriteOnly ); File::Index idx( indexFile, QIODevice::WriteOnly );
@ -1349,7 +1350,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
// If there was a zip file, index it too // If there was a zip file, index it too
if ( zipFileName.size() ) { if ( zipFileName.size() ) {
qDebug( "Indexing zip file" ); GD_DPRINTF( "Indexing zip file\n" );
idxHeader.hasZipFile = 1; idxHeader.hasZipFile = 1;
@ -1414,7 +1415,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
dictionaries.push_back( std::make_shared< GlsDictionary >( dictId, indexFile, dictFiles ) ); dictionaries.push_back( std::make_shared< GlsDictionary >( dictId, indexFile, dictFiles ) );
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "GLS dictionary reading failed: %s:%u, error: %s", fileName.c_str(), atLine, e.what() ); gdWarning( "GLS dictionary reading failed: %s:%u, error: %s\n", fileName.c_str(), atLine, e.what() );
} }
} }

View file

@ -13,6 +13,7 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <QFileInfo> #include <QFileInfo>
#include <set> #include <set>
#include "gddebug.hh"
#include "utils.hh" #include "utils.hh"
#include <QtConcurrentRun> #include <QtConcurrentRun>
@ -270,10 +271,10 @@ void HunspellArticleRequest::run()
} }
} }
catch ( Iconv::Ex & e ) { catch ( Iconv::Ex & e ) {
qWarning( "Hunspell: charset conversion error, no processing's done: %s", e.what() ); gdWarning( "Hunspell: charset conversion error, no processing's done: %s\n", e.what() );
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "Hunspell: error: %s", e.what() ); gdWarning( "Hunspell: error: %s\n", e.what() );
} }
finish(); finish();
@ -395,7 +396,7 @@ QList< wstring > suggest( wstring & word, QMutex & hunspellMutex, Hunspell & hun
suggestion.chop( suggestion.length() - n ); suggestion.chop( suggestion.length() - n );
} }
qDebug( ">>>Sugg: %s", suggestion.toLocal8Bit().data() ); GD_DPRINTF( ">>>Sugg: %s\n", suggestion.toLocal8Bit().data() );
auto match = cutStem.match( suggestion.trimmed() ); auto match = cutStem.match( suggestion.trimmed() );
if ( match.hasMatch() ) { if ( match.hasMatch() ) {
@ -410,7 +411,7 @@ QList< wstring > suggest( wstring & word, QMutex & hunspellMutex, Hunspell & hun
} }
} }
catch ( Iconv::Ex & e ) { catch ( Iconv::Ex & e ) {
qWarning( "Hunspell: charset conversion error, no processing's done: %s", e.what() ); gdWarning( "Hunspell: charset conversion error, no processing's done: %s\n", e.what() );
} }
return result; return result;
@ -492,7 +493,7 @@ void HunspellPrefixMatchRequest::run()
} }
} }
catch ( Iconv::Ex & e ) { catch ( Iconv::Ex & e ) {
qWarning( "Hunspell: charset conversion error, no processing's done: %s", e.what() ); gdWarning( "Hunspell: charset conversion error, no processing's done: %s\n", e.what() );
} }
finish(); finish();

View file

@ -15,6 +15,7 @@
#include "dict/forvo.hh" #include "dict/forvo.hh"
#include "dict/programs.hh" #include "dict/programs.hh"
#include "dict/voiceengines.hh" #include "dict/voiceengines.hh"
#include "gddebug.hh"
#include "dict/xdxf.hh" #include "dict/xdxf.hh"
#include "dict/sdict.hh" #include "dict/sdict.hh"
#include "dict/aard.hh" #include "dict/aard.hh"
@ -280,7 +281,7 @@ void loadDictionaries( QWidget * parent,
addDicts( DictServer::makeDictionaries( cfg.dictServers ) ); addDicts( DictServer::makeDictionaries( cfg.dictServers ) );
qDebug( "Load done" ); GD_DPRINTF( "Load done\n" );
// Remove any stale index files // Remove any stale index files
@ -290,12 +291,12 @@ void loadDictionaries( QWidget * parent,
for ( unsigned x = dictionaries.size(); x--; ) { for ( unsigned x = dictionaries.size(); x--; ) {
ret = ids.insert( dictionaries[ x ]->getId() ); ret = ids.insert( dictionaries[ x ]->getId() );
if ( !ret.second ) { if ( !ret.second ) {
qWarning( R"(Duplicate dictionary ID found: ID=%s, name="%s", path="%s")", gdWarning( R"(Duplicate dictionary ID found: ID=%s, name="%s", path="%s")",
dictionaries[ x ]->getId().c_str(), dictionaries[ x ]->getId().c_str(),
dictionaries[ x ]->getName().c_str(), dictionaries[ x ]->getName().c_str(),
dictionaries[ x ]->getDictionaryFilenames().empty() ? dictionaries[ x ]->getDictionaryFilenames().empty() ?
"" : "" :
dictionaries[ x ]->getDictionaryFilenames()[ 0 ].c_str() ); dictionaries[ x ]->getDictionaryFilenames()[ 0 ].c_str() );
} }
} }

View file

@ -9,6 +9,7 @@
#include "btreeidx.hh" #include "btreeidx.hh"
#include "audiolink.hh" #include "audiolink.hh"
#include "gddebug.hh"
#include <set> #include <set>
#include <string> #include <string>
@ -463,13 +464,13 @@ sptr< Dictionary::DataRequest > LsaDictionary::getResource( string const & name
long result = ov_read( &vf, ptr, left, 0, 2, 1, &bitstream ); long result = ov_read( &vf, ptr, left, 0, 2, 1, &bitstream );
if ( result <= 0 ) { if ( result <= 0 ) {
qWarning( "Failed to read Vorbis data (code = %ld)", result ); gdWarning( "Failed to read Vorbis data (code = %ld)\n", result );
memset( ptr, 0, left ); memset( ptr, 0, left );
break; break;
} }
if ( result > left ) { if ( result > left ) {
qWarning( "Warning: Vorbis decode returned more data than requested." ); GD_FDPRINTF( stderr, "Warning: Vorbis decode returned more data than requested.\n" );
result = left; result = left;
} }
@ -538,7 +539,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) || indexIsOldOrBad( indexFile ) ) { if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) || indexIsOldOrBad( indexFile ) ) {
// Building the index // Building the index
qDebug( "Lsa: Building the index for dictionary: %s", i->c_str() ); gdDebug( "Lsa: Building the index for dictionary: %s\n", i->c_str() );
initializing.indexingDictionary( Utils::Fs::basename( *i ) ); initializing.indexingDictionary( Utils::Fs::basename( *i ) );
@ -558,7 +559,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
/// XXX handle big-endian machines here! /// XXX handle big-endian machines here!
auto entriesCount = f.read< uint32_t >(); auto entriesCount = f.read< uint32_t >();
qDebug( "%s: %u entries", i->c_str(), entriesCount ); GD_DPRINTF( "%s: %u entries\n", i->c_str(), entriesCount );
idxHeader.soundsCount = entriesCount; idxHeader.soundsCount = entriesCount;
@ -573,7 +574,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
// Remove the extension, no need for that in the index // Remove the extension, no need for that in the index
e.name = stripExtension( e.name ); e.name = stripExtension( e.name );
qDebug( "Read filename %s (%u at %u)<", e.name.c_str(), e.samplesLength, e.samplesOffset ); GD_DPRINTF( "Read filename %s (%u at %u)<\n", e.name.c_str(), e.samplesLength, e.samplesOffset );
// Insert new entry into an index // Insert new entry into an index
@ -612,7 +613,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
dictionaries.push_back( std::make_shared< LsaDictionary >( dictId, indexFile, dictFiles ) ); dictionaries.push_back( std::make_shared< LsaDictionary >( dictId, indexFile, dictFiles ) );
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "Lingvo's LSA reading failed: %s, error: %s", i->c_str(), e.what() ); gdWarning( "Lingvo's LSA reading failed: %s, error: %s\n", i->c_str(), e.what() );
} }
} }

View file

@ -35,6 +35,7 @@
#include <QtCore5Compat/QTextCodec> #include <QtCore5Compat/QTextCodec>
#include "decompress.hh" #include "decompress.hh"
#include "gddebug.hh"
#include "ripemd.hh" #include "ripemd.hh"
#include "utils.hh" #include "utils.hh"
#include "htmlescape.hh" #include "htmlescape.hh"
@ -117,7 +118,7 @@ bool MdictParser::open( const char * filename )
filename_ = QString::fromUtf8( filename ); filename_ = QString::fromUtf8( filename );
file_ = new QFile( filename_ ); file_ = new QFile( filename_ );
qDebug( "MdictParser: open %s", filename ); gdDebug( "MdictParser: open %s", filename );
if ( file_.isNull() || !file_->exists() ) { if ( file_.isNull() || !file_->exists() ) {
return false; return false;
@ -232,7 +233,7 @@ bool MdictParser::parseCompressedBlock( qint64 compressedBlockSize,
case 0x00000000: case 0x00000000:
// No compression // No compression
if ( !checkAdler32( buf, size, checksum ) ) { if ( !checkAdler32( buf, size, checksum ) ) {
qWarning( "MDict: parseCompressedBlock: plain: checksum not match" ); gdWarning( "MDict: parseCompressedBlock: plain: checksum not match" );
return false; return false;
} }
@ -247,13 +248,13 @@ bool MdictParser::parseCompressedBlock( qint64 compressedBlockSize,
result = lzo1x_decompress_safe( (const uchar *)buf, size, (uchar *)decompressedBlock.data(), &blockSize, NULL ); result = lzo1x_decompress_safe( (const uchar *)buf, size, (uchar *)decompressedBlock.data(), &blockSize, NULL );
if ( result != LZO_E_OK || blockSize != (lzo_uint)decompressedBlockSize ) { if ( result != LZO_E_OK || blockSize != (lzo_uint)decompressedBlockSize ) {
qWarning( "MDict: parseCompressedBlock: decompression failed" ); gdWarning( "MDict: parseCompressedBlock: decompression failed" );
return false; return false;
} }
if ( checksum if ( checksum
!= lzo_adler32( lzo_adler32( 0, NULL, 0 ), (const uchar *)decompressedBlock.constData(), blockSize ) ) { != lzo_adler32( lzo_adler32( 0, NULL, 0 ), (const uchar *)decompressedBlock.constData(), blockSize ) ) {
qWarning( "MDict: parseCompressedBlock: lzo: checksum does not match" ); gdWarning( "MDict: parseCompressedBlock: lzo: checksum does not match" );
return false; return false;
} }
} break; } break;
@ -262,12 +263,12 @@ bool MdictParser::parseCompressedBlock( qint64 compressedBlockSize,
// zlib compression // zlib compression
decompressedBlock = zlibDecompress( buf, size, checksum ); decompressedBlock = zlibDecompress( buf, size, checksum );
if ( decompressedBlock.isEmpty() ) { if ( decompressedBlock.isEmpty() ) {
qWarning( "MDict: parseCompressedBlock: zlib: failed to decompress or checksum does not match" ); gdWarning( "MDict: parseCompressedBlock: zlib: failed to decompress or checksum does not match" );
return false; return false;
} }
break; break;
default: default:
qWarning( "MDict: parseCompressedBlock: unknown type" ); gdWarning( "MDict: parseCompressedBlock: unknown type" );
return false; return false;
} }
@ -319,7 +320,7 @@ bool MdictParser::readHeader( QDataStream & in )
in.setByteOrder( QDataStream::LittleEndian ); in.setByteOrder( QDataStream::LittleEndian );
in >> checksum; in >> checksum;
if ( !checkAdler32( headerTextUtf16.constData(), headerTextUtf16.size(), checksum ) ) { if ( !checkAdler32( headerTextUtf16.constData(), headerTextUtf16.size(), checksum ) ) {
qWarning( "MDict: readHeader: checksum does not match" ); gdWarning( "MDict: readHeader: checksum does not match" );
return false; return false;
} }
headerTextUtf16.clear(); headerTextUtf16.clear();

View file

@ -9,6 +9,7 @@
#include "wstring.hh" #include "wstring.hh"
#include "wstring_qt.hh" #include "wstring_qt.hh"
#include "chunkedstorage.hh" #include "chunkedstorage.hh"
#include "gddebug.hh"
#include "langcoder.hh" #include "langcoder.hh"
#include "audiolink.hh" #include "audiolink.hh"
#include "ex.hh" #include "ex.hh"
@ -447,7 +448,7 @@ void MdxDictionary::makeFTSIndex( QAtomicInt & isCancelled )
// return; // return;
qDebug( "MDict: Building the full-text index for dictionary: %s", getName().c_str() ); gdDebug( "MDict: Building the full-text index for dictionary: %s", getName().c_str() );
try { try {
auto _dict = std::make_shared< MdxDictionary >( this->getId(), idxFileName, this->getDictionaryFilenames() ); auto _dict = std::make_shared< MdxDictionary >( this->getId(), idxFileName, this->getDictionaryFilenames() );
@ -458,7 +459,7 @@ void MdxDictionary::makeFTSIndex( QAtomicInt & isCancelled )
FTS_index_completed.ref(); FTS_index_completed.ref();
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "MDict: Failed building full-text search index for \"%s\", reason: %s", getName().c_str(), ex.what() ); gdWarning( "MDict: Failed building full-text search index for \"%s\", reason: %s", getName().c_str(), ex.what() );
QFile::remove( ftsIdxName.c_str() ); QFile::remove( ftsIdxName.c_str() );
} }
} }
@ -473,7 +474,7 @@ void MdxDictionary::getArticleText( uint32_t articleAddress, QString & headword,
text = Html::unescape( QString::fromUtf8( articleText.data(), articleText.size() ) ); text = Html::unescape( QString::fromUtf8( articleText.data(), articleText.size() ) );
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "MDict: Failed retrieving article from \"%s\", reason: %s", getName().c_str(), ex.what() ); gdWarning( "MDict: Failed retrieving article from \"%s\", reason: %s", getName().c_str(), ex.what() );
} }
} }
@ -1121,7 +1122,7 @@ QString MdxDictionary::getCachedFileName( QString filename )
QFileInfo info( cacheDirName ); QFileInfo info( cacheDirName );
if ( !info.exists() || !info.isDir() ) { if ( !info.exists() || !info.isDir() ) {
if ( !dir.mkdir( cacheDirName ) ) { if ( !dir.mkdir( cacheDirName ) ) {
qWarning( "Mdx: can't create cache directory \"%s\"", cacheDirName.toUtf8().data() ); gdWarning( "Mdx: can't create cache directory \"%s\"", cacheDirName.toUtf8().data() );
return QString(); return QString();
} }
} }
@ -1139,7 +1140,7 @@ QString MdxDictionary::getCachedFileName( QString filename )
QFileInfo dirInfo( dirName ); QFileInfo dirInfo( dirName );
if ( !dirInfo.exists() ) { if ( !dirInfo.exists() ) {
if ( !dir.mkdir( dirName ) ) { if ( !dir.mkdir( dirName ) ) {
qWarning( "Mdx: can't create cache directory \"%s\"", dirName.toUtf8().data() ); gdWarning( "Mdx: can't create cache directory \"%s\"", dirName.toUtf8().data() );
return QString(); return QString();
} }
} }
@ -1154,7 +1155,7 @@ QString MdxDictionary::getCachedFileName( QString filename )
} }
QFile f( fullName ); QFile f( fullName );
if ( !f.open( QFile::WriteOnly ) ) { if ( !f.open( QFile::WriteOnly ) ) {
qWarning( R"(Mdx: file "%s" creating error: "%s")", fullName.toUtf8().data(), f.errorString().toUtf8().data() ); gdWarning( R"(Mdx: file "%s" creating error: "%s")", fullName.toUtf8().data(), f.errorString().toUtf8().data() );
return QString(); return QString();
} }
gd::wstring resourceName = filename.toStdU32String(); gd::wstring resourceName = filename.toStdU32String();
@ -1194,7 +1195,7 @@ QString MdxDictionary::getCachedFileName( QString filename )
f.close(); f.close();
if ( n < (qint64)data.size() ) { if ( n < (qint64)data.size() ) {
qWarning( R"(Mdx: file "%s" writing error: "%s")", fullName.toUtf8().data(), f.errorString().toUtf8().data() ); gdWarning( R"(Mdx: file "%s" writing error: "%s")", fullName.toUtf8().data(), f.errorString().toUtf8().data() );
return QString(); return QString();
} }
return fullName; return fullName;
@ -1342,7 +1343,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) || indexIsOldOrBad( dictFiles, indexFile ) ) { if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) || indexIsOldOrBad( dictFiles, indexFile ) ) {
// Building the index // Building the index
qDebug( "MDict: Building the index for dictionary: %s", fileName.c_str() ); gdDebug( "MDict: Building the index for dictionary: %s\n", fileName.c_str() );
MdictParser parser; MdictParser parser;
list< sptr< MdictParser > > mddParsers; list< sptr< MdictParser > > mddParsers;
@ -1358,7 +1359,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
if ( File::exists( *mddIter ) ) { if ( File::exists( *mddIter ) ) {
sptr< MdictParser > mddParser = std::make_shared< MdictParser >(); sptr< MdictParser > mddParser = std::make_shared< MdictParser >();
if ( !mddParser->open( mddIter->c_str() ) ) { if ( !mddParser->open( mddIter->c_str() ) ) {
qWarning( "Broken mdd (resource) file: %s", mddIter->c_str() ); gdWarning( "Broken mdd (resource) file: %s\n", mddIter->c_str() );
continue; continue;
} }
mddParsers.push_back( mddParser ); mddParsers.push_back( mddParser );
@ -1433,7 +1434,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
// Finish with the chunks // Finish with the chunks
idxHeader.chunksOffset = chunks.finish(); idxHeader.chunksOffset = chunks.finish();
qDebug( "Writing index..." ); GD_DPRINTF( "Writing index...\n" );
// Good. Now build the index // Good. Now build the index
IndexInfo idxInfo = BtreeIndexing::buildIndex( indexedWords, idx ); IndexInfo idxInfo = BtreeIndexing::buildIndex( indexedWords, idx );

View file

@ -9,6 +9,7 @@
#include <QtXml> #include <QtXml>
#include <algorithm> #include <algorithm>
#include <list> #include <list>
#include "gddebug.hh"
#include "audiolink.hh" #include "audiolink.hh"
#include "langcoder.hh" #include "langcoder.hh"
#include "utils.hh" #include "utils.hh"
@ -155,7 +156,7 @@ MediaWikiWordSearchRequest::MediaWikiWordSearchRequest( wstring const & str,
QNetworkAccessManager & mgr ): QNetworkAccessManager & mgr ):
isCancelling( false ) isCancelling( false )
{ {
qDebug( "wiki request begin" ); GD_DPRINTF( "wiki request begin\n" );
QUrl reqUrl( url + "/api.php?action=query&list=allpages&aplimit=40&format=xml" ); QUrl reqUrl( url + "/api.php?action=query&list=allpages&aplimit=40&format=xml" );
GlobalBroadcaster::instance()->addWhitelist( reqUrl.host() ); GlobalBroadcaster::instance()->addWhitelist( reqUrl.host() );
@ -179,7 +180,7 @@ MediaWikiWordSearchRequest::MediaWikiWordSearchRequest( wstring const & str,
MediaWikiWordSearchRequest::~MediaWikiWordSearchRequest() MediaWikiWordSearchRequest::~MediaWikiWordSearchRequest()
{ {
qDebug( "request end" ); GD_DPRINTF( "request end\n" );
} }
void MediaWikiWordSearchRequest::cancel() void MediaWikiWordSearchRequest::cancel()
@ -193,7 +194,7 @@ void MediaWikiWordSearchRequest::cancel()
finish(); finish();
qDebug( "cancel the request" ); GD_DPRINTF( "cancel the request" );
} }
void MediaWikiWordSearchRequest::downloadFinished() void MediaWikiWordSearchRequest::downloadFinished()
@ -226,7 +227,7 @@ void MediaWikiWordSearchRequest::downloadFinished()
} }
} }
} }
qDebug( "done." ); GD_DPRINTF( "done.\n" );
} }
else { else {
setErrorString( netReply->errorString() ); setErrorString( netReply->errorString() );
@ -257,11 +258,11 @@ public:
QDomElement const sectionsElement = parseNode.firstChildElement( "sections" ); QDomElement const sectionsElement = parseNode.firstChildElement( "sections" );
if ( sectionsElement.isNull() ) { if ( sectionsElement.isNull() ) {
qWarning( "MediaWiki: empty table of contents and missing sections element." ); gdWarning( "MediaWiki: empty table of contents and missing sections element." );
return; return;
} }
qDebug( "MediaWiki: generating table of contents from the sections element." ); gdDebug( "MediaWiki: generating table of contents from the sections element." );
MediaWikiSectionsParser parser; MediaWikiSectionsParser parser;
parser.generateTableOfContents( sectionsElement ); parser.generateTableOfContents( sectionsElement );
articleString.replace( emptyTocPos, emptyTocIndicator.size(), parser.tableOfContents ); articleString.replace( emptyTocPos, emptyTocIndicator.size(), parser.tableOfContents );
@ -342,17 +343,17 @@ bool MediaWikiSectionsParser::addListLevel( QString const & levelString )
int const level = levelString.toInt( &convertedToInt ); int const level = levelString.toInt( &convertedToInt );
if ( !convertedToInt ) { if ( !convertedToInt ) {
qWarning( "MediaWiki: sections level is not an integer: %s", levelString.toUtf8().constData() ); gdWarning( "MediaWiki: sections level is not an integer: %s", levelString.toUtf8().constData() );
return false; return false;
} }
if ( level <= 0 ) { if ( level <= 0 ) {
qWarning( "MediaWiki: unsupported nonpositive sections level: %s", levelString.toUtf8().constData() ); gdWarning( "MediaWiki: unsupported nonpositive sections level: %s", levelString.toUtf8().constData() );
return false; return false;
} }
if ( level > previousLevel + 1 ) { if ( level > previousLevel + 1 ) {
qWarning( "MediaWiki: unsupported sections level increase by more than one: from %d to %s", gdWarning( "MediaWiki: unsupported sections level increase by more than one: from %d to %s",
previousLevel, previousLevel,
levelString.toUtf8().constData() ); levelString.toUtf8().constData() );
return false; return false;
} }
@ -465,7 +466,7 @@ MediaWikiArticleRequest::MediaWikiArticleRequest( wstring const & str,
void MediaWikiArticleRequest::addQuery( QNetworkAccessManager & mgr, wstring const & str ) void MediaWikiArticleRequest::addQuery( QNetworkAccessManager & mgr, wstring const & str )
{ {
qDebug( "MediaWiki: requesting article %s", QString::fromStdU32String( str ).toUtf8().data() ); gdDebug( "MediaWiki: requesting article %s\n", QString::fromStdU32String( str ).toUtf8().data() );
QUrl reqUrl( url + "/api.php?action=parse&prop=text|revid|sections&format=xml&redirects" ); QUrl reqUrl( url + "/api.php?action=parse&prop=text|revid|sections&format=xml&redirects" );
@ -489,7 +490,7 @@ void MediaWikiArticleRequest::addQuery( QNetworkAccessManager & mgr, wstring con
void MediaWikiArticleRequest::requestFinished( QNetworkReply * r ) void MediaWikiArticleRequest::requestFinished( QNetworkReply * r )
{ {
qDebug( "Finished." ); GD_DPRINTF( "Finished.\n" );
if ( isFinished() ) { // Was cancelled if ( isFinished() ) { // Was cancelled
return; return;
@ -692,7 +693,7 @@ void MediaWikiArticleRequest::requestFinished( QNetworkReply * r )
} }
} }
} }
qDebug( "done." ); GD_DPRINTF( "done.\n" );
} }
else { else {
setErrorString( netReply->errorString() ); setErrorString( netReply->errorString() );

View file

@ -6,6 +6,7 @@
#include "decompress.hh" #include "decompress.hh"
#include "folding.hh" #include "folding.hh"
#include "ftshelpers.hh" #include "ftshelpers.hh"
#include "gddebug.hh"
#include "htmlescape.hh" #include "htmlescape.hh"
#include "langcoder.hh" #include "langcoder.hh"
#include "sdict.hh" #include "sdict.hh"
@ -222,7 +223,7 @@ void SdictDictionary::loadIcon() noexcept
string SdictDictionary::convert( string const & in ) string SdictDictionary::convert( string const & in )
{ {
// qDebug( "Source>>>>>>>>>>: %s\n\n", in.c_str() ); // GD_DPRINTF( "Source>>>>>>>>>>: %s\n\n\n", in.c_str() );
string inConverted; string inConverted;
@ -373,14 +374,14 @@ void SdictDictionary::makeFTSIndex( QAtomicInt & isCancelled )
} }
qDebug( "SDict: Building the full-text index for dictionary: %s", getName().c_str() ); gdDebug( "SDict: Building the full-text index for dictionary: %s\n", getName().c_str() );
try { try {
FtsHelpers::makeFTSIndex( this, isCancelled ); FtsHelpers::makeFTSIndex( this, isCancelled );
FTS_index_completed.ref(); FTS_index_completed.ref();
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "SDict: Failed building full-text search index for \"%s\", reason: %s", getName().c_str(), ex.what() ); gdWarning( "SDict: Failed building full-text search index for \"%s\", reason: %s\n", getName().c_str(), ex.what() );
QFile::remove( ftsIdxName.c_str() ); QFile::remove( ftsIdxName.c_str() );
} }
} }
@ -401,7 +402,7 @@ void SdictDictionary::getArticleText( uint32_t articleAddress, QString & headwor
} }
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "SDict: Failed retrieving article from \"%s\", reason: %s", getName().c_str(), ex.what() ); gdWarning( "SDict: Failed retrieving article from \"%s\", reason: %s\n", getName().c_str(), ex.what() );
} }
} }
@ -525,7 +526,7 @@ void SdictArticleRequest::run()
articlesIncluded.insert( x.articleOffset ); articlesIncluded.insert( x.articleOffset );
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "SDict: Failed loading article from \"%s\", reason: %s", dict.getName().c_str(), ex.what() ); gdWarning( "SDict: Failed loading article from \"%s\", reason: %s\n", dict.getName().c_str(), ex.what() );
} }
} }
@ -636,7 +637,7 @@ QString const & SdictDictionary::getDescription()
QObject::tr( "Version: %1%2" ).arg( QString::fromUtf8( str.c_str(), str.size() ) ).arg( "\n\n" ); QObject::tr( "Version: %1%2" ).arg( QString::fromUtf8( str.c_str(), str.size() ) ).arg( "\n\n" );
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "SDict: Failed description reading for \"%s\", reason: %s", getName().c_str(), ex.what() ); gdWarning( "SDict: Failed description reading for \"%s\", reason: %s\n", getName().c_str(), ex.what() );
} }
if ( dictionaryDescription.isEmpty() ) { if ( dictionaryDescription.isEmpty() ) {
@ -672,7 +673,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) || indexIsOldOrBad( indexFile ) ) { if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) || indexIsOldOrBad( indexFile ) ) {
try { try {
qDebug( "SDict: Building the index for dictionary: %s", fileName.c_str() ); gdDebug( "SDict: Building the index for dictionary: %s\n", fileName.c_str() );
File::Index df( fileName, QIODevice::ReadOnly ); File::Index df( fileName, QIODevice::ReadOnly );
@ -680,7 +681,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
df.read( &dictHeader, sizeof( dictHeader ) ); df.read( &dictHeader, sizeof( dictHeader ) );
if ( strncmp( dictHeader.signature, "sdct", 4 ) ) { if ( strncmp( dictHeader.signature, "sdct", 4 ) ) {
qWarning( "File \"%s\" is not valid SDictionary file", fileName.c_str() ); gdWarning( "File \"%s\" is not valid SDictionary file", fileName.c_str() );
continue; continue;
} }
int compression = dictHeader.compression & 0x0F; int compression = dictHeader.compression & 0x0F;
@ -780,11 +781,11 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
idx.write( &idxHeader, sizeof( idxHeader ) ); idx.write( &idxHeader, sizeof( idxHeader ) );
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "Sdictionary dictionary indexing failed: %s, error: %s", fileName.c_str(), e.what() ); gdWarning( "Sdictionary dictionary indexing failed: %s, error: %s\n", fileName.c_str(), e.what() );
continue; continue;
} }
catch ( ... ) { catch ( ... ) {
qWarning( "Sdictionary dictionary indexing failed" ); qWarning( "Sdictionary dictionary indexing failed\n" );
continue; continue;
} }
} // if need to rebuild } // if need to rebuild
@ -792,7 +793,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
dictionaries.push_back( std::make_shared< SdictDictionary >( dictId, indexFile, dictFiles ) ); dictionaries.push_back( std::make_shared< SdictDictionary >( dictId, indexFile, dictFiles ) );
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "Sdictionary dictionary initializing failed: %s, error: %s", fileName.c_str(), e.what() ); gdWarning( "Sdictionary dictionary initializing failed: %s, error: %s\n", fileName.c_str(), e.what() );
} }
} }
return dictionaries; return dictionaries;

View file

@ -6,6 +6,7 @@
#include "btreeidx.hh" #include "btreeidx.hh"
#include "folding.hh" #include "folding.hh"
#include "gddebug.hh"
#include "utf8.hh" #include "utf8.hh"
#include "decompress.hh" #include "decompress.hh"
#include "langcoder.hh" #include "langcoder.hh"
@ -935,7 +936,7 @@ void SlobDictionary::makeFTSIndex( QAtomicInt & isCancelled )
} }
qDebug( "Slob: Building the full-text index for dictionary: %s", getName().c_str() ); gdDebug( "Slob: Building the full-text index for dictionary: %s\n", getName().c_str() );
try { try {
const auto slob_dic = std::make_unique< SlobDictionary >( getId(), idxFileName, getDictionaryFilenames() ); const auto slob_dic = std::make_unique< SlobDictionary >( getId(), idxFileName, getDictionaryFilenames() );
@ -943,7 +944,7 @@ void SlobDictionary::makeFTSIndex( QAtomicInt & isCancelled )
FTS_index_completed.ref(); FTS_index_completed.ref();
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "Slob: Failed building full-text search index for \"%s\", reason: %s", getName().c_str(), ex.what() ); gdWarning( "Slob: Failed building full-text search index for \"%s\", reason: %s\n", getName().c_str(), ex.what() );
QFile::remove( ftsIdxName.c_str() ); QFile::remove( ftsIdxName.c_str() );
} }
} }
@ -973,7 +974,7 @@ void SlobDictionary::getArticleText( uint32_t articleAddress, QString & headword
} }
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "Slob: Failed retrieving article from \"%s\", reason: %s", getName().c_str(), ex.what() ); gdWarning( "Slob: Failed retrieving article from \"%s\", reason: %s\n", getName().c_str(), ex.what() );
} }
} }
@ -1221,10 +1222,10 @@ void SlobResourceRequest::run()
hasAnyData = true; hasAnyData = true;
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "SLOB: Failed loading resource \"%s\" from \"%s\", reason: %s", gdWarning( "SLOB: Failed loading resource \"%s\" from \"%s\", reason: %s\n",
resourceName.c_str(), resourceName.c_str(),
dict.getName().c_str(), dict.getName().c_str(),
ex.what() ); ex.what() );
// Resource not loaded -- we don't set the hasAnyData flag then // Resource not loaded -- we don't set the hasAnyData flag then
} }
@ -1267,7 +1268,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) || indexIsOldOrBad( indexFile ) ) { if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) || indexIsOldOrBad( indexFile ) ) {
SlobFile sf; SlobFile sf;
qDebug( "Slob: Building the index for dictionary: %s", fileName.c_str() ); gdDebug( "Slob: Building the index for dictionary: %s\n", fileName.c_str() );
sf.open( firstName ); sf.open( firstName );
@ -1361,11 +1362,11 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
dictionaries.push_back( std::make_shared< SlobDictionary >( dictId, indexFile, dictFiles ) ); dictionaries.push_back( std::make_shared< SlobDictionary >( dictId, indexFile, dictFiles ) );
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "Slob dictionary initializing failed: %s, error: %s", fileName.c_str(), e.what() ); gdWarning( "Slob dictionary initializing failed: %s, error: %s\n", fileName.c_str(), e.what() );
continue; continue;
} }
catch ( ... ) { catch ( ... ) {
qWarning( "Slob dictionary initializing failed" ); qWarning( "Slob dictionary initializing failed\n" );
continue; continue;
} }
} }

View file

@ -524,8 +524,8 @@ bool MediaWikisModel::setData( QModelIndex const & index, const QVariant & value
} }
if ( role == Qt::CheckStateRole && !index.column() ) { if ( role == Qt::CheckStateRole && !index.column() ) {
//qDebug( "type = %d", (int)value.type() ); //GD_DPRINTF( "type = %d\n", (int)value.type() );
//qDebug( "value = %d", (int)value.toInt() ); //GD_DPRINTF( "value = %d\n", (int)value.toInt() );
// XXX it seems to be always passing Int( 2 ) as a value, so we just toggle // XXX it seems to be always passing Int( 2 ) as a value, so we just toggle
mediawikis[ index.row() ].enabled = !mediawikis[ index.row() ].enabled; mediawikis[ index.row() ].enabled = !mediawikis[ index.row() ].enabled;
@ -713,8 +713,8 @@ bool WebSitesModel::setData( QModelIndex const & index, const QVariant & value,
} }
if ( role == Qt::CheckStateRole && !index.column() ) { if ( role == Qt::CheckStateRole && !index.column() ) {
//qDebug( "type = %d", (int)value.type() ); //GD_DPRINTF( "type = %d\n", (int)value.type() );
//qDebug( "value = %d", (int)value.toInt() ); //GD_DPRINTF( "value = %d\n", (int)value.toInt() );
// XXX it seems to be always passing Int( 2 ) as a value, so we just toggle // XXX it seems to be always passing Int( 2 ) as a value, so we just toggle
webSites[ index.row() ].enabled = !webSites[ index.row() ].enabled; webSites[ index.row() ].enabled = !webSites[ index.row() ].enabled;

View file

@ -10,6 +10,7 @@
#include "xdxf2html.hh" #include "xdxf2html.hh"
#include "htmlescape.hh" #include "htmlescape.hh"
#include "langcoder.hh" #include "langcoder.hh"
#include "gddebug.hh"
#include "filetype.hh" #include "filetype.hh"
#include "indexedzip.hh" #include "indexedzip.hh"
#include "tiff.hh" #include "tiff.hh"
@ -930,7 +931,9 @@ void StardictDictionary::loadArticle( uint32_t address, string & headword, strin
entrySize = size; entrySize = size;
} }
else if ( !size ) { else if ( !size ) {
qWarning( "Stardict: short entry for the word %s encountered in \"%s\".", headword.c_str(), getName().c_str() ); gdWarning( "Stardict: short entry for the word %s encountered in \"%s\".\n",
headword.c_str(),
getName().c_str() );
break; break;
} }
@ -943,9 +946,9 @@ void StardictDictionary::loadArticle( uint32_t address, string & headword, strin
} }
if ( size < entrySize ) { if ( size < entrySize ) {
qWarning( "Stardict: malformed entry for the word %s encountered in \"%s\".", gdWarning( "Stardict: malformed entry for the word %s encountered in \"%s\".\n",
headword.c_str(), headword.c_str(),
getName().c_str() ); getName().c_str() );
break; break;
} }
@ -963,9 +966,9 @@ void StardictDictionary::loadArticle( uint32_t address, string & headword, strin
if ( !entrySizeKnown ) { if ( !entrySizeKnown ) {
if ( size < sizeof( uint32_t ) ) { if ( size < sizeof( uint32_t ) ) {
qWarning( "Stardict: malformed entry for the word %s encountered in \"%s\".", gdWarning( "Stardict: malformed entry for the word %s encountered in \"%s\".\n",
headword.c_str(), headword.c_str(),
getName().c_str() ); getName().c_str() );
break; break;
} }
@ -978,9 +981,9 @@ void StardictDictionary::loadArticle( uint32_t address, string & headword, strin
} }
if ( size < entrySize ) { if ( size < entrySize ) {
qWarning( "Stardict: malformed entry for the word %s encountered in \"%s\".", gdWarning( "Stardict: malformed entry for the word %s encountered in \"%s\".\n",
headword.c_str(), headword.c_str(),
getName().c_str() ); getName().c_str() );
break; break;
} }
@ -990,10 +993,10 @@ void StardictDictionary::loadArticle( uint32_t address, string & headword, strin
size -= entrySize; size -= entrySize;
} }
else { else {
qWarning( "Stardict: non-alpha entry type 0x%x for the word %s encountered in \"%s\".", gdWarning( "Stardict: non-alpha entry type 0x%x for the word %s encountered in \"%s\".\n",
type, type,
headword.c_str(), headword.c_str(),
getName().c_str() ); getName().c_str() );
break; break;
} }
} }
@ -1006,9 +1009,9 @@ void StardictDictionary::loadArticle( uint32_t address, string & headword, strin
size_t len = strlen( ptr + 1 ); size_t len = strlen( ptr + 1 );
if ( size < len + 2 ) { if ( size < len + 2 ) {
qWarning( "Stardict: malformed entry for the word %s encountered in \"%s\".", gdWarning( "Stardict: malformed entry for the word %s encountered in \"%s\".\n",
headword.c_str(), headword.c_str(),
getName().c_str() ); getName().c_str() );
break; break;
} }
@ -1020,9 +1023,9 @@ void StardictDictionary::loadArticle( uint32_t address, string & headword, strin
else if ( isupper( *ptr ) ) { else if ( isupper( *ptr ) ) {
// An entry which havs its size before contents // An entry which havs its size before contents
if ( size < sizeof( uint32_t ) + 1 ) { if ( size < sizeof( uint32_t ) + 1 ) {
qWarning( "Stardict: malformed entry for the word %s encountered in \"%s\".", gdWarning( "Stardict: malformed entry for the word %s encountered in \"%s\".\n",
headword.c_str(), headword.c_str(),
getName().c_str() ); getName().c_str() );
break; break;
} }
@ -1033,9 +1036,9 @@ void StardictDictionary::loadArticle( uint32_t address, string & headword, strin
entrySize = ntohl( entrySize ); entrySize = ntohl( entrySize );
if ( size < sizeof( uint32_t ) + 1 + entrySize ) { if ( size < sizeof( uint32_t ) + 1 + entrySize ) {
qWarning( "Stardict: malformed entry for the word %s encountered in \"%s\".", gdWarning( "Stardict: malformed entry for the word %s encountered in \"%s\".\n",
headword.c_str(), headword.c_str(),
getName().c_str() ); getName().c_str() );
break; break;
} }
@ -1045,10 +1048,10 @@ void StardictDictionary::loadArticle( uint32_t address, string & headword, strin
size -= sizeof( uint32_t ) + 1 + entrySize; size -= sizeof( uint32_t ) + 1 + entrySize;
} }
else { else {
qWarning( "Stardict: non-alpha entry type 0x%x for the word %s encountered in \"%s\".", gdWarning( "Stardict: non-alpha entry type 0x%x for the word %s encountered in \"%s\".\n",
(unsigned)*ptr, (unsigned)*ptr,
headword.c_str(), headword.c_str(),
getName().c_str() ); getName().c_str() );
break; break;
} }
} }
@ -1123,14 +1126,16 @@ void StardictDictionary::makeFTSIndex( QAtomicInt & isCancelled )
} }
qDebug( "Stardict: Building the full-text index for dictionary: %s", getName().c_str() ); gdDebug( "Stardict: Building the full-text index for dictionary: %s\n", getName().c_str() );
try { try {
FtsHelpers::makeFTSIndex( this, isCancelled ); FtsHelpers::makeFTSIndex( this, isCancelled );
FTS_index_completed.ref(); FTS_index_completed.ref();
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "Stardict: Failed building full-text search index for \"%s\", reason: %s", getName().c_str(), ex.what() ); gdWarning( "Stardict: Failed building full-text search index for \"%s\", reason: %s\n",
getName().c_str(),
ex.what() );
QFile::remove( ftsIdxName.c_str() ); QFile::remove( ftsIdxName.c_str() );
} }
} }
@ -1146,7 +1151,7 @@ void StardictDictionary::getArticleText( uint32_t articleAddress, QString & head
text = Html::unescape( QString::fromStdString( articleStr ) ); text = Html::unescape( QString::fromStdString( articleStr ) );
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "Stardict: Failed retrieving article from \"%s\", reason: %s", getName().c_str(), ex.what() ); gdWarning( "Stardict: Failed retrieving article from \"%s\", reason: %s\n", getName().c_str(), ex.what() );
} }
} }
@ -1559,7 +1564,7 @@ void StardictResourceRequest::run()
string n = string n =
dict.getContainingFolder().toStdString() + Utils::Fs::separator() + "res" + Utils::Fs::separator() + resourceName; dict.getContainingFolder().toStdString() + Utils::Fs::separator() + "res" + Utils::Fs::separator() + resourceName;
qDebug( "startdict resource name is %s", n.c_str() ); GD_DPRINTF( "startdict resource name is %s\n", n.c_str() );
try { try {
QMutexLocker _( &dataMutex ); QMutexLocker _( &dataMutex );
@ -1636,10 +1641,10 @@ void StardictResourceRequest::run()
hasAnyData = true; hasAnyData = true;
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "Stardict: Failed loading resource \"%s\" for \"%s\", reason: %s", gdWarning( "Stardict: Failed loading resource \"%s\" for \"%s\", reason: %s\n",
resourceName.c_str(), resourceName.c_str(),
dict.getName().c_str(), dict.getName().c_str(),
ex.what() ); ex.what() );
// Resource not loaded -- we don't set the hasAnyData flag then // Resource not loaded -- we don't set the hasAnyData flag then
} }
catch ( ... ) { catch ( ... ) {
@ -1721,7 +1726,7 @@ static void handleIdxSynFile( string const & fileName,
size_t wordLen = strlen( ptr ); size_t wordLen = strlen( ptr );
if ( ptr + wordLen + 1 + ( isSynFile ? sizeof( uint32_t ) : sizeof( uint32_t ) * 2 ) > &image.back() ) { if ( ptr + wordLen + 1 + ( isSynFile ? sizeof( uint32_t ) : sizeof( uint32_t ) * 2 ) > &image.back() ) {
qWarning( "Warning: sudden end of file %s", fileName.c_str() ); GD_FDPRINTF( stderr, "Warning: sudden end of file %s\n", fileName.c_str() );
break; break;
} }
@ -1811,7 +1816,7 @@ static void handleIdxSynFile( string const & fileName,
} }
} }
qDebug( "%u entires made", (unsigned)indexedWords.size() ); GD_DPRINTF( "%u entires made\n", (unsigned)indexedWords.size() );
} }
@ -1863,7 +1868,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
Ifo ifo( QString::fromStdString( fileName ) ); Ifo ifo( QString::fromStdString( fileName ) );
qDebug( "Stardict: Building the index for dictionary: %s", ifo.bookname.c_str() ); gdDebug( "Stardict: Building the index for dictionary: %s\n", ifo.bookname.c_str() );
if ( ifo.idxoffsetbits == 64 ) { if ( ifo.idxoffsetbits == 64 ) {
throw ex64BitsNotSupported(); throw ex64BitsNotSupported();
@ -1875,20 +1880,20 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
if ( synFileName.empty() ) { if ( synFileName.empty() ) {
if ( ifo.synwordcount ) { if ( ifo.synwordcount ) {
qDebug( GD_DPRINTF(
"Warning: dictionary has synwordcount specified, but no " "Warning: dictionary has synwordcount specified, but no "
"corresponding .syn file was found\n" ); "corresponding .syn file was found\n" );
ifo.synwordcount = 0; // Pretend it wasn't there ifo.synwordcount = 0; // Pretend it wasn't there
} }
} }
else if ( !ifo.synwordcount ) { else if ( !ifo.synwordcount ) {
qDebug( "Warning: ignoring .syn file %s, since there's no synwordcount in .ifo specified", GD_DPRINTF( "Warning: ignoring .syn file %s, since there's no synwordcount in .ifo specified\n",
synFileName.c_str() ); synFileName.c_str() );
} }
qDebug( "bookname = %s", ifo.bookname.c_str() ); GD_DPRINTF( "bookname = %s\n", ifo.bookname.c_str() );
qDebug( "wordcount = %u", ifo.wordcount ); GD_DPRINTF( "wordcount = %u\n", ifo.wordcount );
initializing.indexingDictionary( ifo.bookname ); initializing.indexingDictionary( ifo.bookname );
@ -1973,7 +1978,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
// If there was a zip file, index it too // If there was a zip file, index it too
if ( zipFileName.size() ) { if ( zipFileName.size() ) {
qDebug( "Indexing zip file" ); GD_DPRINTF( "Indexing zip file\n" );
idxHeader.hasZipFile = 1; idxHeader.hasZipFile = 1;
@ -2012,7 +2017,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
dictionaries.push_back( std::make_shared< StardictDictionary >( dictId, indexFile, dictFiles ) ); dictionaries.push_back( std::make_shared< StardictDictionary >( dictId, indexFile, dictFiles ) );
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "Stardict dictionary initializing failed: %s, error: %s", fileName.c_str(), e.what() ); gdWarning( "Stardict dictionary initializing failed: %s, error: %s\n", fileName.c_str(), e.what() );
} }
} }

View file

@ -6,6 +6,7 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <opencc/opencc.h> #include <opencc/opencc.h>
#include "folding.hh" #include "folding.hh"
#include "gddebug.hh"
#include "transliteration.hh" #include "transliteration.hh"
#include "utf8.hh" #include "utf8.hh"
@ -41,18 +42,18 @@ CharacterConversionDictionary::CharacterConversionDictionary( std::string const
// #ifdef Q_OS_MAC // #ifdef Q_OS_MAC
converter = opencc_open( openccConfig.toLocal8Bit().constData() ); converter = opencc_open( openccConfig.toLocal8Bit().constData() );
if ( converter == reinterpret_cast< opencc_t >( -1 ) ) { if ( converter == reinterpret_cast< opencc_t >( -1 ) ) {
qWarning( "CharacterConversionDictionary: failed to initialize OpenCC from config %s: %s", gdWarning( "CharacterConversionDictionary: failed to initialize OpenCC from config %s: %s\n",
openccConfig.toLocal8Bit().constData(), openccConfig.toLocal8Bit().constData(),
opencc_error() ); opencc_error() );
} }
// #else // #else
// converter = new opencc::SimpleConverter( openccConfig.toLocal8Bit().constData() ); // converter = new opencc::SimpleConverter( openccConfig.toLocal8Bit().constData() );
// #endif // #endif
} }
catch ( std::runtime_error & e ) { catch ( std::runtime_error & e ) {
qWarning( "CharacterConversionDictionary: failed to initialize OpenCC from config %s: %s", gdWarning( "CharacterConversionDictionary: failed to initialize OpenCC from config %s: %s\n",
openccConfig.toLocal8Bit().constData(), openccConfig.toLocal8Bit().constData(),
e.what() ); e.what() );
} }
} }
@ -87,7 +88,7 @@ std::vector< gd::wstring > CharacterConversionDictionary::getAlternateWritings(
opencc_convert_utf8_free( tmp ); opencc_convert_utf8_free( tmp );
} }
else { else {
qWarning( "OpenCC: conversion failed %s", opencc_error() ); gdWarning( "OpenCC: conversion failed %s\n", opencc_error() );
} }
} }
// #else // #else
@ -96,7 +97,7 @@ std::vector< gd::wstring > CharacterConversionDictionary::getAlternateWritings(
result = Utf8::decode( output ); result = Utf8::decode( output );
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "OpenCC: conversion failed %s", ex.what() ); gdWarning( "OpenCC: conversion failed %s\n", ex.what() );
} }
if ( !result.empty() && result != folded ) { if ( !result.empty() && result != folded ) {

View file

@ -4,6 +4,7 @@
#include "transliteration.hh" #include "transliteration.hh"
#include "utf8.hh" #include "utf8.hh"
#include "folding.hh" #include "folding.hh"
#include "gddebug.hh"
namespace Transliteration { namespace Transliteration {
@ -60,7 +61,7 @@ sptr< Dictionary::WordSearchRequest > BaseTransliterationDictionary::findHeadwor
vector< wstring > alts = getAlternateWritings( str ); vector< wstring > alts = getAlternateWritings( str );
qDebug( "alts = %u", (unsigned)alts.size() ); GD_DPRINTF( "alts = %u\n", (unsigned)alts.size() );
for ( const auto & alt : alts ) { for ( const auto & alt : alts ) {
result->getMatches().push_back( alt ); result->getMatches().push_back( alt );

View file

@ -4,6 +4,7 @@
#include "indexedzip.hh" #include "indexedzip.hh"
#include "zipfile.hh" #include "zipfile.hh"
#include <zlib.h> #include <zlib.h>
#include "gddebug.hh"
#include "utf8.hh" #include "utf8.hh"
#include "iconv.hh" #include "iconv.hh"
#include "wstring_qt.hh" #include "wstring_qt.hh"
@ -66,7 +67,7 @@ bool IndexedZip::loadFile( uint32_t offset, vector< char > & data )
if ( !ZipFile::readLocalHeader( zip, header ) ) { if ( !ZipFile::readLocalHeader( zip, header ) ) {
vector< string > zipFileNames; vector< string > zipFileNames;
zip.getFilenames( zipFileNames ); zip.getFilenames( zipFileNames );
qDebug( "Failed to load header" ); GD_DPRINTF( "Failed to load header" );
string filename; string filename;
if ( zip.getCurrentFile() < zipFileNames.size() ) { if ( zip.getCurrentFile() < zipFileNames.size() ) {
filename = zipFileNames.at( zip.getCurrentFile() ); filename = zipFileNames.at( zip.getCurrentFile() );
@ -80,7 +81,7 @@ bool IndexedZip::loadFile( uint32_t offset, vector< char > & data )
switch ( header.compressionMethod ) { switch ( header.compressionMethod ) {
case ZipFile::Uncompressed: case ZipFile::Uncompressed:
qDebug( "Uncompressed" ); GD_DPRINTF( "Uncompressed" );
data.resize( header.uncompressedSize ); data.resize( header.uncompressedSize );
return (size_t)zip.read( &data.front(), data.size() ) == data.size(); return (size_t)zip.read( &data.front(), data.size() ) == data.size();
@ -110,7 +111,7 @@ bool IndexedZip::loadFile( uint32_t offset, vector< char > & data )
} }
if ( inflate( &stream, Z_FINISH ) != Z_STREAM_END ) { if ( inflate( &stream, Z_FINISH ) != Z_STREAM_END ) {
qDebug( "Not zstream end!" ); GD_DPRINTF( "Not zstream end!" );
data.clear(); data.clear();
@ -155,7 +156,7 @@ bool IndexedZip::indexFile( BtreeIndexing::IndexedWords & zipFileNames, quint32
while ( ZipFile::readNextEntry( zip, entry ) ) { while ( ZipFile::readNextEntry( zip, entry ) ) {
if ( entry.compressionMethod == ZipFile::Unsupported ) { if ( entry.compressionMethod == ZipFile::Unsupported ) {
qWarning( "Zip warning: compression method unsupported -- skipping file \"%s\"", entry.fileName.data() ); qWarning( "Zip warning: compression method unsupported -- skipping file \"%s\"\n", entry.fileName.data() );
continue; continue;
} }

View file

@ -8,6 +8,7 @@
#include <QTextCodec> #include <QTextCodec>
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include "gddebug.hh"
#include "globalbroadcaster.hh" #include "globalbroadcaster.hh"
#include "fmt/compile.h" #include "fmt/compile.h"
@ -299,9 +300,9 @@ void WebSiteArticleRequest::requestFinished( QNetworkReply * r )
} }
else { else {
if ( netReply->url().scheme() == "file" ) { if ( netReply->url().scheme() == "file" ) {
qWarning( "WebSites: Failed loading article from \"%s\", reason: %s", gdWarning( "WebSites: Failed loading article from \"%s\", reason: %s\n",
dictPtr->getName().c_str(), dictPtr->getName().c_str(),
netReply->errorString().toUtf8().data() ); netReply->errorString().toUtf8().data() );
} }
else { else {
setErrorString( netReply->errorString() ); setErrorString( netReply->errorString() );

View file

@ -15,6 +15,7 @@
#include <list> #include <list>
#include <wctype.h> #include <wctype.h>
#include <stdlib.h> #include <stdlib.h>
#include "gddebug.hh"
#include "xdxf2html.hh" #include "xdxf2html.hh"
#include "ufile.hh" #include "ufile.hh"
#include "langcoder.hh" #include "langcoder.hh"
@ -376,14 +377,14 @@ void XdxfDictionary::makeFTSIndex( QAtomicInt & isCancelled )
} }
qDebug( "Xdxf: Building the full-text index for dictionary: %s", getName().c_str() ); gdDebug( "Xdxf: Building the full-text index for dictionary: %s\n", getName().c_str() );
try { try {
FtsHelpers::makeFTSIndex( this, isCancelled ); FtsHelpers::makeFTSIndex( this, isCancelled );
FTS_index_completed.ref(); FTS_index_completed.ref();
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "Xdxf: Failed building full-text search index for \"%s\", reason: %s", getName().c_str(), ex.what() ); gdWarning( "Xdxf: Failed building full-text search index for \"%s\", reason: %s\n", getName().c_str(), ex.what() );
QFile::remove( ftsIdxName.c_str() ); QFile::remove( ftsIdxName.c_str() );
} }
} }
@ -397,7 +398,7 @@ void XdxfDictionary::getArticleText( uint32_t articleAddress, QString & headword
text = Html::unescape( QString::fromStdString( articleStr ) ); text = Html::unescape( QString::fromStdString( articleStr ) );
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "Xdxf: Failed retrieving article from \"%s\", reason: %s", getName().c_str(), ex.what() ); gdWarning( "Xdxf: Failed retrieving article from \"%s\", reason: %s\n", getName().c_str(), ex.what() );
} }
} }
@ -521,7 +522,7 @@ void XdxfArticleRequest::run()
articlesIncluded.insert( x.articleOffset ); articlesIncluded.insert( x.articleOffset );
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "XDXF: Failed loading article from \"%s\", reason: %s", dict.getName().c_str(), ex.what() ); gdWarning( "XDXF: Failed loading article from \"%s\", reason: %s\n", dict.getName().c_str(), ex.what() );
} }
} }
@ -862,7 +863,7 @@ void indexArticle( GzippedFile & gzFile,
if ( words.empty() ) { if ( words.empty() ) {
// Nothing to index, this article didn't have any tags // Nothing to index, this article didn't have any tags
qWarning( "No <k> tags found in an article at offset 0x%x, article skipped.", (unsigned)articleOffset ); gdWarning( "No <k> tags found in an article at offset 0x%x, article skipped.\n", (unsigned)articleOffset );
} }
else { else {
// Add an entry // Add an entry
@ -882,7 +883,7 @@ void indexArticle( GzippedFile & gzFile,
// Add also first header - it's needed for full-text search // Add also first header - it's needed for full-text search
chunks.addToBlock( words.begin()->toUtf8().data(), words.begin()->toUtf8().length() + 1 ); chunks.addToBlock( words.begin()->toUtf8().data(), words.begin()->toUtf8().length() + 1 );
// qDebug( "%x: %s", articleOffset, words.begin()->toUtf8().data() ); // GD_DPRINTF( "%x: %s\n", articleOffset, words.begin()->toUtf8().data() );
// Add words to index // Add words to index
@ -957,7 +958,7 @@ void XdxfResourceRequest::run()
string n = dict.getContainingFolder().toStdString() + Utils::Fs::separator() + resourceName; string n = dict.getContainingFolder().toStdString() + Utils::Fs::separator() + resourceName;
qDebug( "xdxf resource name is %s", n.c_str() ); GD_DPRINTF( "xdxf resource name is %s\n", n.c_str() );
try { try {
try { try {
@ -1000,10 +1001,10 @@ void XdxfResourceRequest::run()
hasAnyData = true; hasAnyData = true;
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "XDXF: Failed loading resource \"%s\" for \"%s\", reason: %s", gdWarning( "XDXF: Failed loading resource \"%s\" for \"%s\", reason: %s\n",
resourceName.c_str(), resourceName.c_str(),
dict.getName().c_str(), dict.getName().c_str(),
ex.what() ); ex.what() );
// Resource not loaded -- we don't set the hasAnyData flag then // Resource not loaded -- we don't set the hasAnyData flag then
} }
@ -1057,7 +1058,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) || indexIsOldOrBad( indexFile ) ) { if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) || indexIsOldOrBad( indexFile ) ) {
// Building the index // Building the index
qDebug( "Xdxf: Building the index for dictionary: %s", fileName.c_str() ); gdDebug( "Xdxf: Building the index for dictionary: %s\n", fileName.c_str() );
//initializing.indexingDictionary( nameFromFileName( dictFiles[ 0 ] ) ); //initializing.indexingDictionary( nameFromFileName( dictFiles[ 0 ] ) );
@ -1146,7 +1147,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
chunks.addToBlock( n.data(), n.size() ); chunks.addToBlock( n.data(), n.size() );
} }
else { else {
qDebug( "Warning: duplicate full_name in %s", dictFiles[ 0 ].c_str() ); GD_DPRINTF( "Warning: duplicate full_name in %s\n", dictFiles[ 0 ].c_str() );
} }
} }
else if ( stream.name() == u"description" ) { else if ( stream.name() == u"description" ) {
@ -1170,7 +1171,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
chunks.addToBlock( n.data(), n.size() ); chunks.addToBlock( n.data(), n.size() );
} }
else { else {
qDebug( "Warning: duplicate description in %s", dictFiles[ 0 ].c_str() ); GD_DPRINTF( "Warning: duplicate description in %s\n", dictFiles[ 0 ].c_str() );
} }
} }
else if ( stream.name() == u"languages" ) { else if ( stream.name() == u"languages" ) {
@ -1296,7 +1297,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
// If there was a zip file, index it too // If there was a zip file, index it too
if ( zipFileName.size() ) { if ( zipFileName.size() ) {
qDebug( "Indexing zip file" ); GD_DPRINTF( "Indexing zip file\n" );
idxHeader.hasZipFile = 1; idxHeader.hasZipFile = 1;
@ -1347,17 +1348,17 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
} }
if ( stream.hasError() ) { if ( stream.hasError() ) {
qWarning( "%s had a parse error %s at line %lu, and therefore was indexed only up to the point of error.", gdWarning( "%s had a parse error %s at line %lu, and therefore was indexed only up to the point of error.",
dictFiles[ 0 ].c_str(), dictFiles[ 0 ].c_str(),
stream.errorString().toUtf8().data(), stream.errorString().toUtf8().data(),
(unsigned long)stream.lineNumber() ); (unsigned long)stream.lineNumber() );
} }
} }
dictionaries.push_back( std::make_shared< XdxfDictionary >( dictId, indexFile, dictFiles ) ); dictionaries.push_back( std::make_shared< XdxfDictionary >( dictId, indexFile, dictFiles ) );
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "Xdxf dictionary initializing failed: %s, error: %s", fileName.c_str(), e.what() ); gdWarning( "Xdxf dictionary initializing failed: %s, error: %s\n", fileName.c_str(), e.what() );
} }
} }

View file

@ -3,6 +3,7 @@
#include "xdxf2html.hh" #include "xdxf2html.hh"
#include <QtXml> #include <QtXml>
#include "gddebug.hh"
#include "utf8.hh" #include "utf8.hh"
#include "wstring_qt.hh" #include "wstring_qt.hh"
#include "folding.hh" #include "folding.hh"
@ -130,21 +131,21 @@ string convert( string const & in,
#if ( QT_VERSION < QT_VERSION_CHECK( 6, 5, 0 ) ) #if ( QT_VERSION < QT_VERSION_CHECK( 6, 5, 0 ) )
if ( !dd.setContent( QByteArray( in_data.c_str() ), false, &errorStr, &errorLine, &errorColumn ) ) { if ( !dd.setContent( QByteArray( in_data.c_str() ), false, &errorStr, &errorLine, &errorColumn ) ) {
qWarning( "Xdxf2html error, xml parse failed: %s at %d,%d", qWarning( "Xdxf2html error, xml parse failed: %s at %d,%d\n",
errorStr.toLocal8Bit().constData(), errorStr.toLocal8Bit().constData(),
errorLine, errorLine,
errorColumn ); errorColumn );
qWarning( "The input was: %s", in_data.c_str() ); gdWarning( "The input was: %s\n", in_data.c_str() );
return in; return in;
} }
#else #else
auto setContentResult = dd.setContent( QByteArray::fromStdString( in_data ) ); auto setContentResult = dd.setContent( QByteArray::fromStdString( in_data ) );
if ( !setContentResult ) { if ( !setContentResult ) {
qWarning( "Xdxf2html error, xml parse failed: %s at %lld,%lld", qWarning( "Xdxf2html error, xml parse failed: %s at %lld,%lld\n",
setContentResult.errorMessage.toStdString().c_str(), setContentResult.errorMessage.toStdString().c_str(),
setContentResult.errorLine, setContentResult.errorLine,
setContentResult.errorColumn ); setContentResult.errorColumn );
qWarning( "The input was: %s", in_data.c_str() ); gdWarning( "The input was: %s\n", in_data.c_str() );
return in; return in;
} }
#endif #endif

View file

@ -6,6 +6,7 @@
#include "zim.hh" #include "zim.hh"
#include "btreeidx.hh" #include "btreeidx.hh"
#include "folding.hh" #include "folding.hh"
#include "gddebug.hh"
#include "utf8.hh" #include "utf8.hh"
#include "langcoder.hh" #include "langcoder.hh"
#include "filetype.hh" #include "filetype.hh"
@ -283,7 +284,7 @@ void ZimDictionary::loadIcon() noexcept
return; return;
} }
catch ( zim::EntryNotFound & e ) { catch ( zim::EntryNotFound & e ) {
qDebug( "ZIM icon not loaded for: %s", dictionaryName.c_str() ); gdDebug( "ZIM icon not loaded for: %s", dictionaryName.c_str() );
} }
} }
@ -485,13 +486,13 @@ void ZimDictionary::makeFTSIndex( QAtomicInt & isCancelled )
return; return;
} }
qDebug( "Zim: Building the full-text index for dictionary: %s", getName().c_str() ); gdDebug( "Zim: Building the full-text index for dictionary: %s\n", getName().c_str() );
try { try {
FtsHelpers::makeFTSIndex( this, isCancelled ); FtsHelpers::makeFTSIndex( this, isCancelled );
FTS_index_completed.ref(); FTS_index_completed.ref();
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "Zim: Failed building full-text search index for \"%s\", reason: %s", getName().c_str(), ex.what() ); gdWarning( "Zim: Failed building full-text search index for \"%s\", reason: %s\n", getName().c_str(), ex.what() );
QFile::remove( ftsIdxName.c_str() ); QFile::remove( ftsIdxName.c_str() );
} }
} }
@ -506,7 +507,7 @@ void ZimDictionary::getArticleText( uint32_t articleAddress, QString & headword,
text = Html::unescape( QString::fromUtf8( articleText.data(), articleText.size() ) ); text = Html::unescape( QString::fromUtf8( articleText.data(), articleText.size() ) );
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "Zim: Failed retrieving article from \"%s\", reason: %s", getName().c_str(), ex.what() ); gdWarning( "Zim: Failed retrieving article from \"%s\", reason: %s\n", getName().c_str(), ex.what() );
} }
} }
@ -755,10 +756,10 @@ void ZimResourceRequest::run()
hasAnyData = true; hasAnyData = true;
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "ZIM: Failed loading resource \"%s\" from \"%s\", reason: %s", gdWarning( "ZIM: Failed loading resource \"%s\" from \"%s\", reason: %s\n",
resourceName.c_str(), resourceName.c_str(),
dict.getName().c_str(), dict.getName().c_str(),
ex.what() ); ex.what() );
// Resource not loaded -- we don't set the hasAnyData flag then // Resource not loaded -- we don't set the hasAnyData flag then
} }
@ -810,7 +811,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
try { try {
//only check zim file. //only check zim file.
if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) || indexIsOldOrBad( indexFile ) ) { if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) || indexIsOldOrBad( indexFile ) ) {
qDebug( "Zim: Building the index for dictionary: %s", fileName.c_str() ); gdDebug( "Zim: Building the index for dictionary: %s\n", fileName.c_str() );
unsigned articleCount = df.getArticleCount(); unsigned articleCount = df.getArticleCount();
unsigned wordCount = 0; unsigned wordCount = 0;
@ -898,11 +899,11 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
dictionaries.push_back( std::make_shared< ZimDictionary >( dictId, indexFile, dictFiles ) ); dictionaries.push_back( std::make_shared< ZimDictionary >( dictId, indexFile, dictFiles ) );
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "Zim dictionary initializing failed: %s, error: %s", fileName.c_str(), e.what() ); gdWarning( "Zim dictionary initializing failed: %s, error: %s\n", fileName.c_str(), e.what() );
continue; continue;
} }
catch ( ... ) { catch ( ... ) {
qWarning( "Zim dictionary initializing failed" ); qWarning( "Zim dictionary initializing failed\n" );
continue; continue;
} }
} }

View file

@ -10,6 +10,7 @@
#include "audiolink.hh" #include "audiolink.hh"
#include "indexedzip.hh" #include "indexedzip.hh"
#include "filetype.hh" #include "filetype.hh"
#include "gddebug.hh"
#include "chunkedstorage.hh" #include "chunkedstorage.hh"
#include "htmlescape.hh" #include "htmlescape.hh"
@ -399,7 +400,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
string indexFile = indicesDir + dictId; string indexFile = indicesDir + dictId;
if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) || indexIsOldOrBad( indexFile ) ) { if ( Dictionary::needToRebuildIndex( dictFiles, indexFile ) || indexIsOldOrBad( indexFile ) ) {
qDebug( "Zips: Building the index for dictionary: %s", fileName.c_str() ); gdDebug( "Zips: Building the index for dictionary: %s\n", fileName.c_str() );
File::Index idx( indexFile, QIODevice::WriteOnly ); File::Index idx( indexFile, QIODevice::WriteOnly );
IdxHeader idxHeader; IdxHeader idxHeader;
@ -473,7 +474,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
dictionaries.push_back( std::make_shared< ZipSoundsDictionary >( dictId, indexFile, dictFiles ) ); dictionaries.push_back( std::make_shared< ZipSoundsDictionary >( dictId, indexFile, dictFiles ) );
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "Zipped sounds pack reading failed: %s, error: %s", fileName.c_str(), e.what() ); gdWarning( "Zipped sounds pack reading failed: %s, error: %s\n", fileName.c_str(), e.what() );
} }
} }

View file

@ -4,6 +4,7 @@
#include <QDir> #include <QDir>
#include <QTimer> #include <QTimer>
#include "externalviewer.hh" #include "externalviewer.hh"
#include "gddebug.hh"
ExternalViewer::ExternalViewer( ExternalViewer::ExternalViewer(
const char * data, int size, QString const & extension, QString const & viewerCmdLine_, QObject * parent ): const char * data, int size, QString const & extension, QString const & viewerCmdLine_, QObject * parent ):
@ -25,7 +26,7 @@ ExternalViewer::ExternalViewer(
tempFile.close(); tempFile.close();
qDebug( "%s", tempFile.fileName().toLocal8Bit().data() ); GD_DPRINTF( "%s\n", tempFile.fileName().toLocal8Bit().data() );
} }
void ExternalViewer::start() void ExternalViewer::start()

View file

@ -7,6 +7,7 @@
#include "ftshelpers.hh" #include "ftshelpers.hh"
#include "wstring_qt.hh" #include "wstring_qt.hh"
#include "dictfile.hh" #include "dictfile.hh"
#include "gddebug.hh"
#include "folding.hh" #include "folding.hh"
#include "utils.hh" #include "utils.hh"
@ -252,7 +253,7 @@ void FTSResultsRequest::run()
qWarning() << e.get_description().c_str(); qWarning() << e.get_description().c_str();
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "FTS: Failed full-text search for \"%s\", reason: %s", dict.getName().c_str(), ex.what() ); gdWarning( "FTS: Failed full-text search for \"%s\", reason: %s\n", dict.getName().c_str(), ex.what() );
// Results not loaded -- we don't set the hasAnyData flag then // Results not loaded -- we don't set the hasAnyData flag then
} }

View file

@ -3,6 +3,7 @@
#include "ftshelpers.hh" #include "ftshelpers.hh"
#include "fulltextsearch.hh" #include "fulltextsearch.hh"
#include "gddebug.hh"
#include "globalregex.hh" #include "globalregex.hh"
#include "help.hh" #include "help.hh"
#include <QFutureSynchronizer> #include <QFutureSynchronizer>
@ -45,7 +46,7 @@ void Indexing::run()
timerThread->wait(); timerThread->wait();
} }
catch ( std::exception & ex ) { catch ( std::exception & ex ) {
qWarning( "Exception occurred while full-text search: %s", ex.what() ); gdWarning( "Exception occurred while full-text search: %s", ex.what() );
} }
emit sendNowIndexingName( QString() ); emit sendNowIndexingName( QString() );
} }
@ -388,7 +389,7 @@ void FullTextSearchDialog::searchReqFinished()
std::list< sptr< Dictionary::DataRequest > >::iterator it; std::list< sptr< Dictionary::DataRequest > >::iterator it;
for ( it = searchReqs.begin(); it != searchReqs.end(); ++it ) { for ( it = searchReqs.begin(); it != searchReqs.end(); ++it ) {
if ( ( *it )->isFinished() ) { if ( ( *it )->isFinished() ) {
qDebug( "one finished." ); GD_DPRINTF( "one finished.\n" );
QString errorString = ( *it )->getErrorString(); QString errorString = ( *it )->getErrorString();
@ -404,7 +405,7 @@ void FullTextSearchDialog::searchReqFinished()
addSortedHeadwords( allHeadwords, hws ); addSortedHeadwords( allHeadwords, hws );
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "getDataSlice error: %s", e.what() ); gdWarning( "getDataSlice error: %s\n", e.what() );
} }
} }
} }
@ -412,9 +413,9 @@ void FullTextSearchDialog::searchReqFinished()
} }
} }
if ( it != searchReqs.end() ) { if ( it != searchReqs.end() ) {
qDebug( "erasing.." ); GD_DPRINTF( "erasing..\n" );
searchReqs.erase( it ); searchReqs.erase( it );
qDebug( "erase done.." ); GD_DPRINTF( "erase done..\n" );
continue; continue;
} }
else { else {

View file

@ -1,4 +1,5 @@
#include "hotkeywrapper.hh" #include "hotkeywrapper.hh"
#include "gddebug.hh"
#include <QTimer> #include <QTimer>
#include <QSessionManager> #include <QSessionManager>
#include <QWidget> #include <QWidget>
@ -250,4 +251,329 @@ bool HotkeyWrapper::checkState( quint32 vk, quint32 mod )
state2 = false; state2 = false;
return false; return false;
} }
#ifndef Q_OS_WIN
//////////////////////////////////////////////////////////////////////////
#include <X11/keysym.h>
void HotkeyWrapper::init()
{
keyToUngrab = grabbedKeys.end();
#if QT_VERSION < 0x060000
Display * displayID = QX11Info::display();
#else
QNativeInterface::QX11Application * x11AppInfo = qApp->nativeInterface< QNativeInterface::QX11Application >();
Display * displayID = x11AppInfo->display();
#endif
// We use RECORD extension instead of XGrabKey. That's because XGrabKey
// prevents other clients from getting their input if it's grabbed.
Display * display = displayID;
lShiftCode = XKeysymToKeycode( display, XK_Shift_L );
rShiftCode = XKeysymToKeycode( display, XK_Shift_R );
lCtrlCode = XKeysymToKeycode( display, XK_Control_L );
rCtrlCode = XKeysymToKeycode( display, XK_Control_R );
lAltCode = XKeysymToKeycode( display, XK_Alt_L );
rAltCode = XKeysymToKeycode( display, XK_Alt_R );
lMetaCode = XKeysymToKeycode( display, XK_Super_L );
rMetaCode = XKeysymToKeycode( display, XK_Super_R );
cCode = XKeysymToKeycode( display, XK_c );
insertCode = XKeysymToKeycode( display, XK_Insert );
kpInsertCode = XKeysymToKeycode( display, XK_KP_Insert );
currentModifiers = 0;
// This one will be used to read the recorded content
dataDisplay = XOpenDisplay( 0 );
if ( !dataDisplay )
throw exInit();
recordRange = XRecordAllocRange();
if ( !recordRange ) {
XCloseDisplay( dataDisplay );
throw exInit();
}
recordRange->device_events.first = KeyPress;
recordRange->device_events.last = KeyRelease;
recordClientSpec = XRecordAllClients;
recordContext = XRecordCreateContext( display, 0, &recordClientSpec, 1, &recordRange, 1 );
if ( !recordContext ) {
XFree( recordRange );
XCloseDisplay( dataDisplay );
throw exInit();
}
// This is required to ensure context was indeed created
XSync( display, False );
connect( this, &HotkeyWrapper::keyRecorded, this, &HotkeyWrapper::checkState, Qt::QueuedConnection );
start();
}
void HotkeyWrapper::run() // Runs in a separate thread
{
if ( !XRecordEnableContext( dataDisplay, recordContext, recordEventCallback, (XPointer)this ) )
GD_DPRINTF( "Failed to enable record context\n" );
}
void HotkeyWrapper::recordEventCallback( XPointer ptr, XRecordInterceptData * data )
{
( (HotkeyWrapper *)ptr )->handleRecordEvent( data );
}
void HotkeyWrapper::handleRecordEvent( XRecordInterceptData * data )
{
if ( data->category == XRecordFromServer ) {
xEvent * event = (xEvent *)data->data;
if ( event->u.u.type == KeyPress ) {
KeyCode key = event->u.u.detail;
if ( key == lShiftCode || key == rShiftCode )
currentModifiers |= ShiftMask;
else if ( key == lCtrlCode || key == rCtrlCode )
currentModifiers |= ControlMask;
else if ( key == lAltCode || key == rAltCode )
currentModifiers |= Mod1Mask;
else if ( key == lMetaCode || key == rMetaCode )
currentModifiers |= Mod4Mask;
else {
// Here we employ a kind of hack translating KP_Insert key
// to just Insert. This allows reacting to both Insert keys.
if ( key == kpInsertCode )
key = insertCode;
emit keyRecorded( key, currentModifiers );
}
}
else if ( event->u.u.type == KeyRelease ) {
KeyCode key = event->u.u.detail;
if ( key == lShiftCode || key == rShiftCode )
currentModifiers &= ~ShiftMask;
else if ( key == lCtrlCode || key == rCtrlCode )
currentModifiers &= ~ControlMask;
else if ( key == lAltCode || key == rAltCode )
currentModifiers &= ~Mod1Mask;
else if ( key == lMetaCode || key == rMetaCode )
currentModifiers &= ~Mod4Mask;
}
}
XRecordFreeData( data );
}
bool HotkeyWrapper::setGlobalKey( QKeySequence const & seq, int handle )
{
Config::HotKey hk( seq );
return setGlobalKey( hk.key1, hk.key2, hk.modifiers, handle );
}
bool HotkeyWrapper::setGlobalKey( int key, int key2, Qt::KeyboardModifiers modifier, int handle )
{
if ( !key )
return false; // We don't monitor empty combinations
int vk = nativeKey( key );
int vk2 = key2 ? nativeKey( key2 ) : 0;
quint32 mod = 0;
if ( modifier & Qt::ShiftModifier )
mod |= ShiftMask;
if ( modifier & Qt::ControlModifier )
mod |= ControlMask;
if ( modifier & Qt::AltModifier )
mod |= Mod1Mask;
if ( modifier & Qt::MetaModifier )
mod |= Mod4Mask;
hotkeys.append( HotkeyStruct( vk, vk2, mod, handle, 0 ) );
if ( !isCopyToClipboardKey( vk, mod ) )
grabKey( vk, mod ); // Make sure it doesn't get caught by other apps
return true;
}
bool HotkeyWrapper::isCopyToClipboardKey( quint32 keyCode, quint32 modifiers ) const
{
return modifiers == ControlMask && ( keyCode == cCode || keyCode == insertCode || keyCode == kpInsertCode );
}
bool HotkeyWrapper::isKeyGrabbed( quint32 keyCode, quint32 modifiers ) const
{
GrabbedKeys::const_iterator i = grabbedKeys.find( std::make_pair( keyCode, modifiers ) );
return i != grabbedKeys.end();
}
namespace {
using X11ErrorHandler = int ( * )( Display * display, XErrorEvent * event );
class X11GrabUngrabErrorHandler
{
public:
static bool error;
static int grab_ungrab_error_handler( Display *, XErrorEvent * event )
{
qDebug() << "grab_ungrab_error_handler is invoked";
switch ( event->error_code ) {
case BadAccess:
case BadValue:
case BadWindow:
if ( event->request_code == 33 /* X_GrabKey */ || event->request_code == 34 /* X_UngrabKey */ ) {
error = true;
}
}
return 0;
}
X11GrabUngrabErrorHandler()
{
error = false;
previousErrorHandler_ = XSetErrorHandler( grab_ungrab_error_handler );
}
~X11GrabUngrabErrorHandler()
{
#if QT_VERSION < 0x060000
Display * displayID = QX11Info::display();
#else
QNativeInterface::QX11Application * x11AppInfo = qApp->nativeInterface< QNativeInterface::QX11Application >();
Display * displayID = x11AppInfo->display();
#endif
XFlush( displayID );
(void)XSetErrorHandler( previousErrorHandler_ );
}
bool isError() const
{
#if QT_VERSION < 0x060000
Display * displayID = QX11Info::display();
#else
QNativeInterface::QX11Application * x11AppInfo = qApp->nativeInterface< QNativeInterface::QX11Application >();
Display * displayID = x11AppInfo->display();
#endif
XFlush( displayID );
return error;
}
private:
X11ErrorHandler previousErrorHandler_;
};
bool X11GrabUngrabErrorHandler::error = false;
} // anonymous namespace
HotkeyWrapper::GrabbedKeys::iterator HotkeyWrapper::grabKey( quint32 keyCode, quint32 modifiers )
{
std::pair< GrabbedKeys::iterator, bool > result = grabbedKeys.insert( std::make_pair( keyCode, modifiers ) );
if ( result.second ) {
#if QT_VERSION < 0x060000
Display * displayID = QX11Info::display();
#else
QNativeInterface::QX11Application * x11AppInfo = qApp->nativeInterface< QNativeInterface::QX11Application >();
Display * displayID = x11AppInfo->display();
#endif
X11GrabUngrabErrorHandler errorHandler;
XGrabKey( displayID, keyCode, modifiers, DefaultRootWindow( displayID ), True, GrabModeAsync, GrabModeAsync );
if ( errorHandler.isError() ) {
gdWarning( "Possible hotkeys conflict. Check your hotkeys options." );
ungrabKey( result.first );
}
}
return result.first;
}
void HotkeyWrapper::ungrabKey( GrabbedKeys::iterator i )
{
#if QT_VERSION < 0x060000
Display * displayID = QX11Info::display();
#else
QNativeInterface::QX11Application * x11AppInfo = qApp->nativeInterface< QNativeInterface::QX11Application >();
Display * displayID = x11AppInfo->display();
#endif
X11GrabUngrabErrorHandler errorHandler;
XUngrabKey( displayID, i->first, i->second, XDefaultRootWindow( displayID ) );
grabbedKeys.erase( i );
if ( errorHandler.isError() ) {
gdWarning( "Cannot ungrab the hotkey" );
}
}
quint32 HotkeyWrapper::nativeKey( int key )
{
QString keySymName;
switch ( key ) {
case Qt::Key_Insert:
keySymName = "Insert";
break;
default:
keySymName = QKeySequence( key ).toString();
break;
}
#if QT_VERSION < 0x060000
Display * displayID = QX11Info::display();
#else
QNativeInterface::QX11Application * x11AppInfo = qApp->nativeInterface< QNativeInterface::QX11Application >();
Display * displayID = x11AppInfo->display();
#endif
Display * display = displayID;
return XKeysymToKeycode( display, XStringToKeysym( keySymName.toLatin1().data() ) );
}
void HotkeyWrapper::unregister()
{
#if QT_VERSION < 0x060000
Display * displayID = QX11Info::display();
#else
QNativeInterface::QX11Application * x11AppInfo = qApp->nativeInterface< QNativeInterface::QX11Application >();
Display * displayID = x11AppInfo->display();
#endif
Display * display = displayID;
XRecordDisableContext( display, recordContext );
XSync( display, False );
wait();
XRecordFreeContext( display, recordContext );
XFree( recordRange );
XCloseDisplay( dataDisplay );
while ( grabbedKeys.size() )
ungrabKey( grabbedKeys.begin() );
( static_cast< QHotkeyApplication * >( qApp ) )->unregisterWrapper( this );
}
#endif
#endif #endif

View file

@ -1,28 +1,35 @@
#pragma once #pragma once
/// @file /// @file
/// Handling global hotkeys and some trick /// Handling global hotkeys and some tricks
/// Part of this header is implemented in /// Part of this header are implmented in
/// + `winhotkeywrapper` /// + `winhotkeywrapper.cc`
/// + `machotkeywrapper` /// + `machotkeywrapper.hh`
/// + `x11hotkeywrapper` ///
#include <QGuiApplication> #include <QGuiApplication>
#include <QThread> #include <QThread>
#include "config.hh" #include "config.hh"
#include "ex.hh" #include "ex.hh"
#include "qtsingleapplication.h" #include "qtsingleapplication.h"
#include "utils.hh" #include "utils.hh"
#ifdef HAVE_X11 #ifdef HAVE_X11
#include <fixx11h.h>
#include <set> #include <set>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/extensions/record.h> #include <X11/extensions/record.h>
#if ( QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) )
#include <QX11Info>
#endif
#include <X11/Xlibint.h> #include <X11/Xlibint.h>
#undef Bool #undef Bool
#undef min #undef min
#undef max #undef max
#endif #endif
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
@ -123,7 +130,7 @@ private:
/// Called by recordEventCallback() /// Called by recordEventCallback()
void handleRecordEvent( XRecordInterceptData * ); void handleRecordEvent( XRecordInterceptData * );
void run() override; // QThread void run(); // QThread
// We do one-time init of those, translating keysyms to keycodes // We do one-time init of those, translating keysyms to keycodes
KeyCode lShiftCode, rShiftCode, lCtrlCode, rCtrlCode, lAltCode, rAltCode, cCode, insertCode, kpInsertCode, lMetaCode, KeyCode lShiftCode, rShiftCode, lCtrlCode, rCtrlCode, lAltCode, rAltCode, cCode, insertCode, kpInsertCode, lMetaCode,

View file

@ -1,24 +1,16 @@
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org> /* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */ * Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
#include "config.hh"
#include "logfileptr.hh"
#include "mainwindow.hh"
#include "termination.hh"
#include "version.hh"
#include <QByteArray>
#include <QCommandLineParser>
#include <QFile>
#include <QIcon>
#include <QMessageBox>
#include <QMutex>
#include <QString>
#include <QStringBuilder>
#include <QtWebEngineCore/QWebEngineUrlScheme>
#include <stdio.h> #include <stdio.h>
#include <QStyleFactory> #include <QIcon>
#include "mainwindow.hh"
#include "hotkeywrapper.hh" // X11 headers & fixer causes this file must be included last #include "config.hh"
#include <QWebEngineProfile>
#include "hotkeywrapper.hh"
#include "version.hh"
#ifdef HAVE_X11
#include <fixx11h.h>
#endif
#if defined( Q_OS_UNIX ) #if defined( Q_OS_UNIX )
#include <clocale> #include <clocale>
@ -29,6 +21,19 @@
#include <windows.h> #include <windows.h>
#endif #endif
#include "termination.hh"
#include <QByteArray>
#include <QCommandLineParser>
#include <QFile>
#include <QMessageBox>
#include <QString>
#include <QStringBuilder>
#include <QtWebEngineCore/QWebEngineUrlScheme>
#include "gddebug.hh"
#include <QMutex>
#include <QStyleFactory>
#if defined( USE_BREAKPAD ) #if defined( USE_BREAKPAD )
#if defined( Q_OS_MAC ) #if defined( Q_OS_MAC )
#include "client/mac/handler/exception_handler.h" #include "client/mac/handler/exception_handler.h"

View file

@ -2,10 +2,10 @@
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org> /* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */ * Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
#include "logfileptr.hh"
#include "termination.hh" #include "termination.hh"
#include <QDebug>
#include <exception> #include <exception>
#include <QtCore>
static void termHandler() static void termHandler()
{ {

View file

@ -3,6 +3,10 @@
#pragma once #pragma once
#include <QFile>
extern QFile * logFilePtr;
// Installs the termination handler which attempts to pop Qt's dialog showing // Installs the termination handler which attempts to pop Qt's dialog showing
// the exception and backtrace, and then aborts. // the exception and backtrace, and then aborts.
void installTerminationHandler(); void installTerminationHandler();

View file

@ -4,6 +4,7 @@
#include "articleview.hh" #include "articleview.hh"
#include "dict/programs.hh" #include "dict/programs.hh"
#include "folding.hh" #include "folding.hh"
#include "gddebug.hh"
#include "gestures.hh" #include "gestures.hh"
#include "globalbroadcaster.hh" #include "globalbroadcaster.hh"
#include "speechclient.hh" #include "speechclient.hh"

View file

@ -2,6 +2,7 @@
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */ * Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
#include "dictheadwords.hh" #include "dictheadwords.hh"
#include "gddebug.hh"
#include "headwordsmodel.hh" #include "headwordsmodel.hh"
#include <QDir> #include <QDir>
#include <QFileDialog> #include <QFileDialog>
@ -254,7 +255,7 @@ QRegularExpression DictHeadwords::getFilterRegex() const
QRegularExpression regExp = QRegularExpression( pattern, options ); QRegularExpression regExp = QRegularExpression( pattern, options );
if ( !regExp.isValid() ) { if ( !regExp.isValid() ) {
qWarning( "Invalid regexp pattern: %s", pattern.toUtf8().data() ); gdWarning( "Invalid regexp pattern: %s\n", pattern.toUtf8().data() );
} }
return regExp; return regExp;
} }
@ -427,7 +428,7 @@ void DictHeadwords::saveHeadersToFile()
progress.setValue( progress.maximum() ); progress.setValue( progress.maximum() );
if ( progress.wasCanceled() ) { if ( progress.wasCanceled() ) {
QMessageBox::warning( this, "GoldenDict", tr( "Export process is interrupted" ) ); QMessageBox::warning( this, "GoldenDict", tr( "Export process is interrupted" ) );
qWarning( "Headers export error: %s", file.errorString().toUtf8().data() ); gdWarning( "Headers export error: %s", file.errorString().toUtf8().data() );
} }
else { else {
//completed. //completed.

View file

@ -210,7 +210,7 @@ void DictionaryBar::showContextMenu( QContextMenuEvent * event, bool extended )
void DictionaryBar::mutedDictionariesChanged() void DictionaryBar::mutedDictionariesChanged()
{ {
//qDebug( "Muted dictionaries changed" ); //GD_DPRINTF( "Muted dictionaries changed\n" );
if ( !mutedDictionaries ) { if ( !mutedDictionaries ) {
return; return;

View file

@ -17,10 +17,9 @@
#include <functional> #include <functional>
#include "favoritespanewidget.hh" #include "favoritespanewidget.hh"
#include "gddebug.hh"
#include "globalbroadcaster.hh" #include "globalbroadcaster.hh"
#include <QFile>
/************************************************** FavoritesPaneWidget *********************************************/ /************************************************** FavoritesPaneWidget *********************************************/
void FavoritesPaneWidget::setUp( Config::Class * cfg, QMenu * menu ) void FavoritesPaneWidget::setUp( Config::Class * cfg, QMenu * menu )
@ -645,7 +644,7 @@ void FavoritesModel::readData()
QFile favoritesFile( m_favoritesFilename ); QFile favoritesFile( m_favoritesFilename );
if ( !favoritesFile.open( QFile::ReadOnly ) ) { if ( !favoritesFile.open( QFile::ReadOnly ) ) {
qDebug( "No favorites file found" ); gdDebug( "No favorites file found" );
return; return;
} }
@ -655,7 +654,7 @@ void FavoritesModel::readData()
if ( !dom.setContent( &favoritesFile, false, &errorStr, &errorLine, &errorColumn ) ) { if ( !dom.setContent( &favoritesFile, false, &errorStr, &errorLine, &errorColumn ) ) {
// Mailformed file // Mailformed file
qWarning( "Favorites file parsing error: %s at %d,%d", errorStr.toUtf8().data(), errorLine, errorColumn ); gdWarning( "Favorites file parsing error: %s at %d,%d\n", errorStr.toUtf8().data(), errorLine, errorColumn );
QMessageBox mb( QMessageBox::Warning, "GoldenDict", tr( "Error in favorities file" ), QMessageBox::Ok ); QMessageBox mb( QMessageBox::Warning, "GoldenDict", tr( "Error in favorities file" ), QMessageBox::Ok );
mb.exec(); mb.exec();
@ -687,7 +686,7 @@ void FavoritesModel::saveData()
QSaveFile tmpFile( m_favoritesFilename ); QSaveFile tmpFile( m_favoritesFilename );
if ( !tmpFile.open( QFile::WriteOnly ) ) { if ( !tmpFile.open( QFile::WriteOnly ) ) {
qWarning( "Can't write favorites file, error: %s", tmpFile.errorString().toUtf8().data() ); gdWarning( "Can't write favorites file, error: %s", tmpFile.errorString().toUtf8().data() );
return; return;
} }
@ -700,7 +699,7 @@ void FavoritesModel::saveData()
QByteArray result( dom.toByteArray() ); QByteArray result( dom.toByteArray() );
if ( tmpFile.write( result ) != result.size() ) { if ( tmpFile.write( result ) != result.size() ) {
qWarning( "Can't write favorites file, error: %s", tmpFile.errorString().toUtf8().data() ); gdWarning( "Can't write favorites file, error: %s", tmpFile.errorString().toUtf8().data() );
return; return;
} }
@ -1146,7 +1145,7 @@ bool FavoritesModel::setDataFromXml( QString const & dataStr )
if ( !dom.setContent( dataStr, false, &errorStr, &errorLine, &errorColumn ) ) { if ( !dom.setContent( dataStr, false, &errorStr, &errorLine, &errorColumn ) ) {
// Mailformed data // Mailformed data
qWarning( "XML parsing error: %s at %d,%d", errorStr.toUtf8().data(), errorLine, errorColumn ); gdWarning( "XML parsing error: %s at %d,%d\n", errorStr.toUtf8().data(), errorLine, errorColumn );
dom.clear(); dom.clear();
return false; return false;
} }

View file

@ -43,6 +43,7 @@
#include <set> #include <set>
#include <map> #include <map>
#include "gddebug.hh"
#include "dictinfo.hh" #include "dictinfo.hh"
#include "historypanewidget.hh" #include "historypanewidget.hh"
@ -1293,7 +1294,7 @@ void MainWindow::commitData()
Config::save( cfg ); Config::save( cfg );
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "Configuration saving failed, error: %s", e.what() ); gdWarning( "Configuration saving failed, error: %s\n", e.what() );
} }
// Save history // Save history
@ -1303,7 +1304,7 @@ void MainWindow::commitData()
ui.favoritesPaneWidget->saveData(); ui.favoritesPaneWidget->saveData();
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "Commit data failed, error: %s", e.what() ); gdWarning( "Commit data failed, error: %s\n", e.what() );
} }
} }
@ -1576,7 +1577,7 @@ void MainWindow::setupNetworkCache( int maxSize )
QString cacheDirectory = Config::getCacheDir(); QString cacheDirectory = Config::getCacheDir();
if ( !QDir().mkpath( cacheDirectory ) ) { if ( !QDir().mkpath( cacheDirectory ) ) {
cacheDirectory = QStandardPaths::writableLocation( QStandardPaths::CacheLocation ); cacheDirectory = QStandardPaths::writableLocation( QStandardPaths::CacheLocation );
qWarning( "Cannot create a cache directory %s. use default cache path.", cacheDirectory.toUtf8().constData() ); gdWarning( "Cannot create a cache directory %s. use default cache path.", cacheDirectory.toUtf8().constData() );
} }
QNetworkDiskCache * const diskCache = new QNetworkDiskCache( this ); QNetworkDiskCache * const diskCache = new QNetworkDiskCache( this );
@ -4492,7 +4493,7 @@ void MainWindow::setGroupByName( QString const & name, bool main_window )
} }
} }
if ( i >= groupList->count() ) { if ( i >= groupList->count() ) {
qWarning( "Group \"%s\" for main window is not found", name.toUtf8().data() ); gdWarning( "Group \"%s\" for main window is not found\n", name.toUtf8().data() );
} }
} }
else { else {

View file

@ -8,6 +8,7 @@
#include <QBitmap> #include <QBitmap>
#include <QMenu> #include <QMenu>
#include <QMouseEvent> #include <QMouseEvent>
#include "gddebug.hh"
#include "gestures.hh" #include "gestures.hh"
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
@ -50,7 +51,7 @@ static bool ownsClipboardMode( QClipboard::Mode mode )
return clipboard.ownsFindBuffer(); return clipboard.ownsFindBuffer();
} }
qWarning( "Unknown clipboard mode: %d", static_cast< int >( mode ) ); gdWarning( "Unknown clipboard mode: %d\n", static_cast< int >( mode ) );
return false; return false;
} }
#endif #endif
@ -748,14 +749,14 @@ bool ScanPopup::eventFilter( QObject * watched, QEvent * event )
void ScanPopup::reactOnMouseMove( QPointF const & p ) void ScanPopup::reactOnMouseMove( QPointF const & p )
{ {
if ( geometry().contains( p.toPoint() ) ) { if ( geometry().contains( p.toPoint() ) ) {
// qDebug( "got inside" ); // GD_DPRINTF( "got inside\n" );
hideTimer.stop(); hideTimer.stop();
mouseEnteredOnce = true; mouseEnteredOnce = true;
uninterceptMouse(); uninterceptMouse();
} }
else { else {
// qDebug( "outside" ); // GD_DPRINTF( "outside\n" );
// We're in grab mode and outside the window - calculate the // We're in grab mode and outside the window - calculate the
// distance from it. We might want to hide it. // distance from it. We might want to hide it.
@ -1164,7 +1165,7 @@ void ScanPopup::setGroupByName( QString const & name ) const
} }
} }
if ( i >= ui.groupList->count() ) { if ( i >= ui.groupList->count() ) {
qWarning( "Group \"%s\" for popup window is not found", name.toUtf8().data() ); gdWarning( "Group \"%s\" for popup window is not found\n", name.toUtf8().data() );
} }
} }

View file

@ -1,309 +0,0 @@
#ifdef HAVE_X11
#include "hotkeywrapper.hh"
#include <X11/keysym.h>
//
/// Previously impletended with XGrabKey
/// Then reimplemented with X Record Extension Library
///
void HotkeyWrapper::init()
{
keyToUngrab = grabbedKeys.end();
QNativeInterface::QX11Application * x11AppInfo = qApp->nativeInterface< QNativeInterface::QX11Application >();
Display * displayID = x11AppInfo->display();
// We use RECORD extension instead of XGrabKey. That's because XGrabKey
// prevents other clients from getting their input if it's grabbed.
Display * display = displayID;
lShiftCode = XKeysymToKeycode( display, XK_Shift_L );
rShiftCode = XKeysymToKeycode( display, XK_Shift_R );
lCtrlCode = XKeysymToKeycode( display, XK_Control_L );
rCtrlCode = XKeysymToKeycode( display, XK_Control_R );
lAltCode = XKeysymToKeycode( display, XK_Alt_L );
rAltCode = XKeysymToKeycode( display, XK_Alt_R );
lMetaCode = XKeysymToKeycode( display, XK_Super_L );
rMetaCode = XKeysymToKeycode( display, XK_Super_R );
cCode = XKeysymToKeycode( display, XK_c );
insertCode = XKeysymToKeycode( display, XK_Insert );
kpInsertCode = XKeysymToKeycode( display, XK_KP_Insert );
currentModifiers = 0;
// This one will be used to read the recorded content
dataDisplay = XOpenDisplay( 0 );
if ( !dataDisplay )
throw exInit();
recordRange = XRecordAllocRange();
if ( !recordRange ) {
XCloseDisplay( dataDisplay );
throw exInit();
}
recordRange->device_events.first = KeyPress;
recordRange->device_events.last = KeyRelease;
recordClientSpec = XRecordAllClients;
recordContext = XRecordCreateContext( display, 0, &recordClientSpec, 1, &recordRange, 1 );
if ( !recordContext ) {
XFree( recordRange );
XCloseDisplay( dataDisplay );
throw exInit();
}
// This is required to ensure context was indeed created
XSync( display, False );
connect( this, &HotkeyWrapper::keyRecorded, this, &HotkeyWrapper::checkState, Qt::QueuedConnection );
start();
}
void HotkeyWrapper::run() // Runs in a separate thread
{
if ( !XRecordEnableContext( dataDisplay, recordContext, recordEventCallback, (XPointer)this ) )
qDebug( "Failed to enable record context" );
}
void HotkeyWrapper::recordEventCallback( XPointer ptr, XRecordInterceptData * data )
{
( (HotkeyWrapper *)ptr )->handleRecordEvent( data );
}
void HotkeyWrapper::handleRecordEvent( XRecordInterceptData * data )
{
if ( data->category == XRecordFromServer ) {
xEvent * event = (xEvent *)data->data;
if ( event->u.u.type == KeyPress ) {
KeyCode key = event->u.u.detail;
if ( key == lShiftCode || key == rShiftCode )
currentModifiers |= ShiftMask;
else if ( key == lCtrlCode || key == rCtrlCode )
currentModifiers |= ControlMask;
else if ( key == lAltCode || key == rAltCode )
currentModifiers |= Mod1Mask;
else if ( key == lMetaCode || key == rMetaCode )
currentModifiers |= Mod4Mask;
else {
// Here we employ a kind of hack translating KP_Insert key
// to just Insert. This allows reacting to both Insert keys.
if ( key == kpInsertCode )
key = insertCode;
emit keyRecorded( key, currentModifiers );
}
}
else if ( event->u.u.type == KeyRelease ) {
KeyCode key = event->u.u.detail;
if ( key == lShiftCode || key == rShiftCode )
currentModifiers &= ~ShiftMask;
else if ( key == lCtrlCode || key == rCtrlCode )
currentModifiers &= ~ControlMask;
else if ( key == lAltCode || key == rAltCode )
currentModifiers &= ~Mod1Mask;
else if ( key == lMetaCode || key == rMetaCode )
currentModifiers &= ~Mod4Mask;
}
}
XRecordFreeData( data );
}
bool HotkeyWrapper::setGlobalKey( QKeySequence const & seq, int handle )
{
Config::HotKey hk( seq );
return setGlobalKey( hk.key1, hk.key2, hk.modifiers, handle );
}
bool HotkeyWrapper::setGlobalKey( int key, int key2, Qt::KeyboardModifiers modifier, int handle )
{
if ( !key )
return false; // We don't monitor empty combinations
int vk = nativeKey( key );
int vk2 = key2 ? nativeKey( key2 ) : 0;
quint32 mod = 0;
if ( modifier & Qt::ShiftModifier )
mod |= ShiftMask;
if ( modifier & Qt::ControlModifier )
mod |= ControlMask;
if ( modifier & Qt::AltModifier )
mod |= Mod1Mask;
if ( modifier & Qt::MetaModifier )
mod |= Mod4Mask;
hotkeys.append( HotkeyStruct( vk, vk2, mod, handle, 0 ) );
if ( !isCopyToClipboardKey( vk, mod ) )
grabKey( vk, mod ); // Make sure it doesn't get caught by other apps
return true;
}
bool HotkeyWrapper::isCopyToClipboardKey( quint32 keyCode, quint32 modifiers ) const
{
return modifiers == ControlMask && ( keyCode == cCode || keyCode == insertCode || keyCode == kpInsertCode );
}
bool HotkeyWrapper::isKeyGrabbed( quint32 keyCode, quint32 modifiers ) const
{
GrabbedKeys::const_iterator i = grabbedKeys.find( std::make_pair( keyCode, modifiers ) );
return i != grabbedKeys.end();
}
namespace {
using X11ErrorHandler = int ( * )( Display * display, XErrorEvent * event );
class X11GrabUngrabErrorHandler
{
public:
static bool error;
static int grab_ungrab_error_handler( Display *, XErrorEvent * event )
{
qDebug() << "grab_ungrab_error_handler is invoked";
switch ( event->error_code ) {
case BadAccess:
case BadValue:
case BadWindow:
if ( event->request_code == 33 /* X_GrabKey */ || event->request_code == 34 /* X_UngrabKey */ ) {
error = true;
}
}
return 0;
}
X11GrabUngrabErrorHandler()
{
error = false;
previousErrorHandler_ = XSetErrorHandler( grab_ungrab_error_handler );
}
~X11GrabUngrabErrorHandler()
{
QNativeInterface::QX11Application * x11AppInfo = qApp->nativeInterface< QNativeInterface::QX11Application >();
Display * displayID = x11AppInfo->display();
XFlush( displayID );
(void)XSetErrorHandler( previousErrorHandler_ );
}
bool isError() const
{
QNativeInterface::QX11Application * x11AppInfo = qApp->nativeInterface< QNativeInterface::QX11Application >();
Display * displayID = x11AppInfo->display();
XFlush( displayID );
return error;
}
private:
X11ErrorHandler previousErrorHandler_;
};
bool X11GrabUngrabErrorHandler::error = false;
} // anonymous namespace
HotkeyWrapper::GrabbedKeys::iterator HotkeyWrapper::grabKey( quint32 keyCode, quint32 modifiers )
{
std::pair< GrabbedKeys::iterator, bool > result = grabbedKeys.insert( std::make_pair( keyCode, modifiers ) );
if ( result.second ) {
QNativeInterface::QX11Application * x11AppInfo = qApp->nativeInterface< QNativeInterface::QX11Application >();
Display * displayID = x11AppInfo->display();
X11GrabUngrabErrorHandler errorHandler;
XGrabKey( displayID, keyCode, modifiers, DefaultRootWindow( displayID ), True, GrabModeAsync, GrabModeAsync );
if ( errorHandler.isError() ) {
qWarning( "Possible hotkeys conflict. Check your hotkeys options." );
ungrabKey( result.first );
}
}
return result.first;
}
void HotkeyWrapper::ungrabKey( GrabbedKeys::iterator i )
{
QNativeInterface::QX11Application * x11AppInfo = qApp->nativeInterface< QNativeInterface::QX11Application >();
Display * displayID = x11AppInfo->display();
X11GrabUngrabErrorHandler errorHandler;
XUngrabKey( displayID, i->first, i->second, XDefaultRootWindow( displayID ) );
grabbedKeys.erase( i );
if ( errorHandler.isError() ) {
qWarning( "Cannot ungrab the hotkey" );
}
}
quint32 HotkeyWrapper::nativeKey( int key )
{
QString keySymName;
switch ( key ) {
case Qt::Key_Insert:
keySymName = "Insert";
break;
default:
keySymName = QKeySequence( key ).toString();
break;
}
QNativeInterface::QX11Application * x11AppInfo = qApp->nativeInterface< QNativeInterface::QX11Application >();
Display * display = x11AppInfo->display();
return XKeysymToKeycode( display, XStringToKeysym( keySymName.toLatin1().data() ) );
}
void HotkeyWrapper::unregister()
{
QNativeInterface::QX11Application * x11AppInfo = qApp->nativeInterface< QNativeInterface::QX11Application >();
Display * display = x11AppInfo->display();
XRecordDisableContext( display, recordContext );
XSync( display, False );
wait();
XRecordFreeContext( display, recordContext );
XFree( recordRange );
XCloseDisplay( dataDisplay );
while ( grabbedKeys.size() )
ungrabKey( grabbedKeys.begin() );
( static_cast< QHotkeyApplication * >( qApp ) )->unregisterWrapper( this );
}
#endif

View file

@ -5,7 +5,7 @@
#include "folding.hh" #include "folding.hh"
#include "wstring_qt.hh" #include "wstring_qt.hh"
#include <map> #include <map>
#include "gddebug.hh"
using std::vector; using std::vector;
using std::list; using std::list;
@ -157,10 +157,10 @@ void WordFinder::startSearch()
queuedRequests.push_back( sr ); queuedRequests.push_back( sr );
} }
catch ( std::exception & e ) { catch ( std::exception & e ) {
qWarning( "Word \"%s\" search error (%s) in \"%s\"", gdWarning( "Word \"%s\" search error (%s) in \"%s\"\n",
inputWord.toUtf8().data(), inputWord.toUtf8().data(),
e.what(), e.what(),
inputDict->getName().c_str() ); inputDict->getName().c_str() );
} }
} }
} }