#212: Scratch, currently works under windows, for both Qt4 and Qt5

This commit is contained in:
Timon Wong 2013-05-30 21:24:21 +08:00
parent d6b832dc6a
commit 1d85f1b359
28 changed files with 332 additions and 116 deletions

View file

@ -29,6 +29,7 @@
#include "ufile.hh"
#include "wstring_qt.hh"
#include "qt4x5.hh"
namespace Aard {
@ -594,7 +595,7 @@ void AardArticleRequestRunnable::run()
void AardArticleRequest::run()
{
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;
@ -621,7 +622,7 @@ void AardArticleRequest::run()
for( unsigned x = 0; x < chain.size(); ++x )
{
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;

View file

@ -4,6 +4,8 @@
#include "about.hh"
#include <QtGui>
#include "qt4x5.hh"
About::About( QWidget * parent ): QDialog( parent )
{
ui.setupUi( this );
@ -39,7 +41,7 @@ About::About( QWidget * parent ): QDialog( parent )
str.replace( "\\", "@" );
str = Qt::escape( str );
str = Qt4x5::escape( str );
int colon = str.indexOf( ":" );

View file

@ -10,6 +10,8 @@
#include "article_netmgr.hh"
#include "wstring_qt.hh"
#include "dprintf.hh"
#include "qt4x5.hh"
using std::string;
namespace
@ -134,24 +136,24 @@ sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource(
{
contentType = "text/html";
if ( url.queryItemValue( "blank" ) == "1" )
if ( Qt4x5::Url::queryItemValue( url, "blank" ) == "1" )
return articleMaker.makeEmptyPage();
bool groupIsValid = false;
QString word = url.queryItemValue( "word" );
unsigned group = url.queryItemValue( "group" ).toUInt( &groupIsValid );
QString word = Qt4x5::Url::queryItemValue( url, "word" );
unsigned group = Qt4x5::Url::queryItemValue( url, "group" ).toUInt( &groupIsValid );
// See if we have some dictionaries muted
QSet< QString > mutedDicts =
QSet< QString >::fromList( url.queryItemValue( "muted" ).split( ',' ) );
QSet< QString >::fromList( Qt4x5::Url::queryItemValue( url, "muted" ).split( ',' ) );
// Unpack contexts
QMap< QString, QString > contexts;
QString contextsEncoded = url.queryItemValue( "contexts" );
QString contextsEncoded = Qt4x5::Url::queryItemValue( url, "contexts" );
if ( contextsEncoded.size() )
{

View file

@ -12,15 +12,16 @@
#include <QClipboard>
#include <QKeyEvent>
#include <QFileDialog>
#include <QDebug>
#include <QWebElement>
#include <QCryptographicHash>
#include "folding.hh"
#include "wstring_qt.hh"
#include "webmultimediadownload.hh"
#include "programs.hh"
#include "dprintf.hh"
#include "ffmpegaudio.hh"
#include <QDebug>
#include <QWebElement>
#include <QCryptographicHash>
#include "qt4x5.hh"
#include <assert.h>
@ -200,11 +201,11 @@ void ArticleView::showDefinition( QString const & word, unsigned group,
req.setScheme( "gdlookup" );
req.setHost( "localhost" );
req.addQueryItem( "word", word );
req.addQueryItem( "group", QString::number( group ) );
Qt4x5::Url::addQueryItem( req, "word", word );
Qt4x5::Url::addQueryItem( req, "group", QString::number( group ) );
if ( scrollTo.size() )
req.addQueryItem( "scrollto", scrollTo );
Qt4x5::Url::addQueryItem( req, "scrollto", scrollTo );
if ( contexts.size() )
{
@ -218,13 +219,13 @@ void ArticleView::showDefinition( QString const & word, unsigned group,
buf.close();
req.addQueryItem( "contexts", QString::fromLatin1( buf.buffer().toBase64() ) );
Qt4x5::Url::addQueryItem( req, "contexts", QString::fromLatin1( buf.buffer().toBase64() ) );
}
QString mutedDicts = getMutedForGroup( group );
if ( mutedDicts.size() )
req.addQueryItem( "muted", mutedDicts );
Qt4x5::Url::addQueryItem( req, "muted", mutedDicts );
// Update both histories (pages history and headwords history)
saveHistoryUserData();
@ -325,11 +326,11 @@ void ArticleView::loadFinished( bool )
}
}
else
if ( url.queryItemValue( "scrollto" ).startsWith( "gdfrom-" ) )
if ( Qt4x5::Url::queryItemValue( url, "scrollto" ).startsWith( "gdfrom-" ) )
{
// There is no active article saved in history, but we have it as a parameter.
// setCurrentArticle will save it and scroll there.
setCurrentArticle( url.queryItemValue( "scrollto" ), true );
setCurrentArticle( Qt4x5::Url::queryItemValue( url, "scrollto" ), true );
}
@ -375,8 +376,8 @@ void ArticleView::handleUrlChanged( QUrl const & url )
unsigned ArticleView::getGroup( QUrl const & url )
{
if ( url.scheme() == "gdlookup" && url.hasQueryItem( "group" ) )
return url.queryItemValue( "group" ).toUInt();
if ( url.scheme() == "gdlookup" && Qt4x5::Url::hasQueryItem( url, "group" ) )
return Qt4x5::Url::queryItemValue( url, "group" ).toUInt();
return 0;
}
@ -693,10 +694,10 @@ void ArticleView::linkHovered ( const QString & link, const QString & , const QS
def = def.mid( 1 );
}
if( url.hasQueryItem( "dict" ) )
if( Qt4x5::Url::hasQueryItem( url, "dict" ) )
{
// Link to other dictionary
QString dictName( url.queryItemValue( "dict" ) );
QString dictName( Qt4x5::Url::queryItemValue( url, "dict" ) );
if( !dictName.isEmpty() )
msg = tr( "Definition from dictionary \"%1\": %2" ).arg( dictName ).arg( def );
}
@ -763,10 +764,10 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref,
else
{
QString newScrollTo( scrollTo );
if( url.hasQueryItem( "dict" ) )
if( Qt4x5::Url::hasQueryItem( url, "dict" ) )
{
// Link to other dictionary
QString dictName( url.queryItemValue( "dict" ) );
QString dictName( Qt4x5::Url::queryItemValue( url, "dict" ) );
for( unsigned i = 0; i < allDictionaries.size(); i++ )
{
if( dictName.compare( QString::fromUtf8( allDictionaries[ i ]->getName().c_str() ) ) == 0 )
@ -938,7 +939,7 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref,
// TODO: Port TTS
#if defined( Q_OS_WIN32 ) || defined( Q_OS_MACX )
// Text to speech
QString md5Id = url.queryItemValue( "engine" );
QString md5Id = Qt4x5::Url::queryItemValue( url, "engine" );
QString text( url.path().mid( 1 ) );
for ( Config::VoiceEngines::const_iterator i = cfg.voiceEngines.begin();
@ -1054,14 +1055,14 @@ void ArticleView::updateMutedContents()
QString mutedDicts = getMutedForGroup( group );
if ( currentUrl.queryItemValue( "muted" ) != mutedDicts )
if ( Qt4x5::Url::queryItemValue( currentUrl, "muted" ) != mutedDicts )
{
// The list has changed -- update the url
currentUrl.removeQueryItem( "muted" );
Qt4x5::Url::removeQueryItem( currentUrl, "muted" );
if ( mutedDicts.size() )
currentUrl.addQueryItem( "muted", mutedDicts );
Qt4x5::Url::addQueryItem( currentUrl, "muted", mutedDicts );
saveHistoryUserData();

14
bgl.cc
View file

@ -31,6 +31,8 @@
#include <QRegExp>
#include "qt4x5.hh"
namespace Bgl {
using std::map;
@ -472,7 +474,7 @@ void BglHeadwordsRequestRunnable::run()
void BglHeadwordsRequest::run()
{
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;
@ -484,7 +486,7 @@ void BglHeadwordsRequest::run()
for( unsigned x = 0; x < chain.size(); ++x )
{
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;
@ -657,7 +659,7 @@ void BglArticleRequest::fixHebArticle(string & hebArticle) // Hebrew support - r
void BglArticleRequest::run()
{
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;
@ -689,7 +691,7 @@ void BglArticleRequest::run()
for( unsigned x = 0; x < chain.size(); ++x )
{
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;
@ -909,7 +911,7 @@ void BglResourceRequestRunnable::run()
void BglResourceRequest::run()
{
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;
@ -927,7 +929,7 @@ void BglResourceRequest::run()
for( size_t count = resourcesCount; count--; )
{
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
break;
vector< char > nameData( idx.read< uint32_t >() );

View file

@ -11,6 +11,7 @@
#include <string.h>
#include <stdlib.h>
#include "dprintf.hh"
#include "qt4x5.hh"
//#define __BTREE_USE_LZO
// LZO mode is experimental and unsupported. Tests didn't show any substantial
@ -178,7 +179,7 @@ void BtreeWordSearchRunnable::run()
void BtreeWordSearchRequest::run()
{
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;
@ -225,7 +226,7 @@ void BtreeWordSearchRequest::run()
if ( chainOffset )
for( ; ; )
{
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
break;
//DPRINTF( "offset = %u, size = %u\n", chainOffset - &leaf.front(), leaf.size() );
@ -296,7 +297,7 @@ void BtreeWordSearchRequest::run()
}
}
if ( charsLeftToChop && !isCancelled )
if ( charsLeftToChop && !Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
--charsLeftToChop;
folded.resize( folded.size() - 1 );

View file

@ -23,22 +23,24 @@
#include <QPainter>
#include <QRegExp>
#include "qt4x5.hh"
namespace Dictionary {
bool Request::isFinished()
{
return (int)isFinishedFlag;
return Qt4x5::AtomicInt::loadAcquire( isFinishedFlag );
}
void Request::update()
{
if ( !isFinishedFlag )
if ( !Qt4x5::AtomicInt::loadAcquire( isFinishedFlag ) )
emit updated();
}
void Request::finish()
{
if ( !isFinishedFlag )
if ( !Qt4x5::AtomicInt::loadAcquire( isFinishedFlag ) )
{
isFinishedFlag.ref();

18
dsl.cc
View file

@ -48,6 +48,8 @@
// For SVG handling
#include <QtSvg/QSvgRenderer>
#include "qt4x5.hh"
namespace Dsl {
using namespace Details;
@ -301,11 +303,11 @@ public:
void DslDictionary::deferredInit()
{
if ( !deferredInitDone )
if ( !Qt4x5::AtomicInt::loadAcquire( deferredInitDone ) )
{
Mutex::Lock _( deferredInitMutex );
if ( deferredInitDone )
if ( Qt4x5::AtomicInt::loadAcquire( deferredInitDone ) )
return;
if ( !deferredInitRunnableStarted )
@ -329,11 +331,11 @@ string const & DslDictionary::ensureInitDone()
void DslDictionary::doDeferredInit()
{
if ( !deferredInitDone )
if ( !Qt4x5::AtomicInt::loadAcquire( deferredInitDone ) )
{
Mutex::Lock _( deferredInitMutex );
if ( deferredInitDone )
if ( Qt4x5::AtomicInt::loadAcquire( deferredInitDone ) )
return;
// Do deferred init
@ -950,7 +952,7 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node )
{
QList< QPair< QString, QString > > query;
query.append( QPair< QString, QString >( attr.left( n ), attr.mid( n + 1 ) ) );
url.setQueryItems( query );
Qt4x5::Url::setQueryItems( url, query );
}
}
@ -1162,7 +1164,7 @@ void DslArticleRequestRunnable::run()
void DslArticleRequest::run()
{
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;
@ -1197,7 +1199,7 @@ void DslArticleRequest::run()
for( unsigned x = 0; x < chain.size(); ++x )
{
// Check if we're cancelled occasionally
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;
@ -1347,7 +1349,7 @@ void DslResourceRequestRunnable::run()
void DslResourceRequest::run()
{
// Some runnables linger enough that they are cancelled before they start
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;

View file

@ -24,6 +24,8 @@ extern "C" {
#include <vector>
#include "qt4x5.hh"
using std::vector;
namespace Ffmpeg
@ -336,13 +338,14 @@ bool DecoderContext::play( QString & errorString )
AVPacket packet;
av_init_packet( &packet );
while ( !isCancelled_ && av_read_frame( formatContext_, &packet ) >= 0 )
while ( !Qt4x5::AtomicInt::loadAcquire( isCancelled_ ) &&
av_read_frame( formatContext_, &packet ) >= 0 )
{
if ( packet.stream_index == audioStream_->index )
{
int gotFrame = 0;
avcodec_decode_audio4( codecContext_, frame, &gotFrame, &packet );
if ( !isCancelled_ && gotFrame )
if ( !Qt4x5::AtomicInt::loadAcquire( isCancelled_ ) && gotFrame )
{
playFrame( frame );
}
@ -351,13 +354,14 @@ bool DecoderContext::play( QString & errorString )
av_free_packet( &packet );
}
if ( !isCancelled_ && codecContext_->codec->capabilities & CODEC_CAP_DELAY )
if ( !Qt4x5::AtomicInt::loadAcquire( isCancelled_ ) &&
codecContext_->codec->capabilities & CODEC_CAP_DELAY )
{
av_init_packet( &packet );
int gotFrame = 0;
while ( avcodec_decode_audio4( codecContext_, frame, &gotFrame, &packet ) >= 0 && gotFrame )
{
if ( isCancelled_ )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled_ ) )
break;
playFrame( frame );
}
@ -536,7 +540,7 @@ void DecoderThread::run()
while ( !deviceMutex_.tryLock( 100 ) )
{
if ( isCancelled_ )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled_ ) )
return;
}

View file

@ -19,10 +19,21 @@ isEmpty( hasGit ) {
# DEPENDPATH += . generators
INCLUDEPATH += .
QT += webkit
QT += xml
QT += network
QT += svg
QT += core \
gui \
xml \
network \
svg
greaterThan(QT_MAJOR_VERSION, 4) {
QT += widgets \
webkitwidgets \
printsupport
} else {
QT += webkit
}
CONFIG += exceptions \
rtti \
stl
@ -46,11 +57,17 @@ win32 {
LIBS += -lvorbisfile \
-lvorbis \
-logg \
-lhunspell-1.3.2 \
-lao \
-lavutil-gd \
-lavformat-gd \
-lavcodec-gd
greaterThan(QT_MAJOR_VERSION, 4) {
LIBS += -lhunspell-1.3
} else {
LIBS += -lhunspell-1.3.2
}
RC_FILE = goldendict.rc
INCLUDEPATH += winlibs/include
LIBS += -L$${PWD}/winlibs/lib
@ -236,7 +253,8 @@ HEADERS += folding.hh \
mdx.hh \
voiceengines.hh \
ffmpegaudio.hh \
articleinspector.hh
articleinspector.hh \
qt4x5.hh
FORMS += groups.ui \
dictgroupwidget.ui \
@ -411,12 +429,13 @@ TRANSLATIONS += locale/ru_RU.ts \
QMAKE_EXTRA_TARGETS += revtarget
PRE_TARGETDEPS += $$PWD/version.txt
revtarget.target = $$PWD/version.txt
!win32 {
revtarget.commands = cd $$PWD; git describe --tags --always --dirty > $$revtarget.target
}
win32 {
revtarget.commands = git --git-dir=\"$$PWD/.git\" describe --tags --always --dirty > $$revtarget.target
}
!win32 {
revtarget.commands = cd $$PWD; git describe --tags --always --dirty > $$revtarget.target
} else {
revtarget.commands = git --git-dir=\"$$PWD/.git\" describe --tags --always --dirty > $$revtarget.target
}
ALL_SOURCES = $$SOURCES $$HEADERS $$FORMS
for(src, ALL_SOURCES) {
QUALIFIED_SOURCES += $${PWD}/$${src}

View file

@ -17,6 +17,8 @@
#include <QMap>
#include <QVector>
#include <QFileInfo>
#include <QFileDialog>
#include <QMessageBox>
using std::vector;
@ -164,14 +166,16 @@ void DictListModel::populate(
dictionaries = active;
allDicts = &available;
reset();
beginResetModel();
endResetModel();
}
void DictListModel::populate(
std::vector< sptr< Dictionary::Class > > const & active )
{
dictionaries = active;
reset();
beginResetModel();
endResetModel();
}
void DictListModel::setAsSource()
@ -356,7 +360,8 @@ void DictListModel::removeSelectedRows( QItemSelectionModel * source )
dictionaries.erase( dictionaries.begin() + rows.at( i ).row() );
}
reset();
beginResetModel();
endResetModel();
emit contentChanged();
}
@ -413,7 +418,8 @@ void DictListModel::addSelectedUniqueFromModel( QItemSelectionModel * source )
list.remove( j );
if ( list.isEmpty() )
{
reset();
beginResetModel();
endResetModel();
emit contentChanged();
return;
}
@ -422,7 +428,8 @@ void DictListModel::addSelectedUniqueFromModel( QItemSelectionModel * source )
}
}
reset();
beginResetModel();
endResetModel();
emit contentChanged();
}
@ -447,7 +454,8 @@ void DictListModel::filterDuplicates()
if ( doReset )
{
reset();
beginResetModel();
endResetModel();
emit contentChanged();
}
}

View file

@ -254,5 +254,6 @@ void HistoryModel::historyChanged()
{
// qDebug() << "History Changed!!";
reset();
beginResetModel();
endResetModel();
}

View file

@ -4,6 +4,10 @@
#endif
#include "hotkeywrapper.hh"
#include <QWidget>
#include <QMainWindow>
#include "dprintf.hh"
#ifdef Q_WS_X11
@ -15,6 +19,9 @@
QHotkeyApplication::QHotkeyApplication( int & argc, char ** argv ):
QtSingleApplication( argc, argv )
{
#if defined( Q_OS_WIN ) && IS_QT_5
installNativeEventFilter( this );
#endif
}
QHotkeyApplication::QHotkeyApplication( QString const & id,
@ -201,7 +208,7 @@ bool HotkeyWrapper::checkState(quint32 vk, quint32 mod)
//////////////////////////////////////////////////////////////////////////
#ifdef Q_WS_WIN
#ifdef Q_OS_WIN
void HotkeyWrapper::init()
{
@ -332,6 +339,25 @@ void HotkeyWrapper::unregister()
}
#if IS_QT_5
bool QHotkeyApplication::nativeEventFilter( const QByteArray & /*eventType*/, void * message, long * result )
{
MSG * msg = reinterpret_cast< MSG * >( message );
if ( msg->message == WM_HOTKEY )
{
for (int i = 0; i < hotkeyWrappers.size(); i++)
{
if ( hotkeyWrappers.at(i)->winEvent( msg, result ) )
return true;
}
}
return false;
}
#else // IS_QT_5
bool QHotkeyApplication::winEventFilter ( MSG * message, long * result )
{
@ -347,6 +373,8 @@ bool QHotkeyApplication::winEventFilter ( MSG * message, long * result )
return QApplication::winEventFilter( message, result );
}
#endif
//////////////////////////////////////////////////////////////////////////
#else

View file

@ -20,12 +20,13 @@
#include "ex.hh"
#include "qtsingleapplication.h"
#include "qt4x5.hh"
//////////////////////////////////////////////////////////////////////////
struct HotkeyStruct
{
HotkeyStruct() {};
HotkeyStruct() {}
HotkeyStruct( quint32 key, quint32 key2, quint32 modifier, int handle, int id );
quint32 key, key2;
@ -187,6 +188,9 @@ public:
};
class QHotkeyApplication : public QtSingleApplication
#if defined( Q_OS_WIN ) && IS_QT_5
, public QAbstractNativeEventFilter
#endif
{
friend class HotkeyWrapper;
@ -207,8 +211,12 @@ protected:
void unregisterWrapper(HotkeyWrapper *wrapper);
#ifdef Q_OS_WIN32
# if IS_QT_5
virtual bool nativeEventFilter( const QByteArray & eventType, void * message, long * result );
# else // IS_QT_5
virtual bool winEventFilter ( MSG * message, long * result );
#endif
#endif // Q_OS_WIN32
QList<HotkeyWrapper*> hotkeyWrappers;
};

View file

@ -9,17 +9,21 @@
#include "wstring_qt.hh"
#include "language.hh"
#include "langcoder.hh"
#include <QRunnable>
#include <QThreadPool>
#include <QSemaphore>
#include <QRegExp>
#include <QDir>
#include <QCoreApplication>
#include <QFileInfo>
#include <set>
#include <hunspell/hunspell.hxx>
#include "dprintf.hh"
#include "fsencoding.hh"
#include <QFileInfo>
#include "qt4x5.hh"
namespace HunspellMorpho {
@ -197,7 +201,7 @@ void HunspellArticleRequestRunnable::run()
void HunspellArticleRequest::run()
{
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;
@ -373,7 +377,7 @@ void HunspellHeadwordsRequestRunnable::run()
void HunspellHeadwordsRequest::run()
{
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;
@ -597,7 +601,7 @@ void HunspellPrefixMatchRequestRunnable::run()
void HunspellPrefixMatchRequest::run()
{
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;

View file

@ -7,7 +7,9 @@
#include "preferences.hh"
#include "about.hh"
#include "mruqmenu.hh"
#include <limits.h>
#include <QDebug>
#include <QTextStream>
#include <QDir>
#include <QMessageBox>
#include <QIcon>
@ -15,16 +17,22 @@
#include <QToolBar>
#include <QCloseEvent>
#include <QDesktopServices>
#include <QProcess>
#include <QCryptographicHash>
#include <QFileDialog>
#include <QPrinter>
#include <QPageSetupDialog>
#include <QPrintPreviewDialog>
#include <QPrintDialog>
#include <limits.h>
#include <set>
#include <map>
#include "dprintf.hh"
#include <QDebug>
#include <QTextStream>
#include "dictinfo.hh"
#include "fsencoding.hh"
#include <QProcess>
#include "historypanewidget.hh"
#include <QCryptographicHash>
#ifdef Q_OS_MAC
#include "lionsupport.h"

18
mdx.cc
View file

@ -35,6 +35,8 @@
#include <QTextDocument>
#include <QCryptographicHash>
#include "qt4x5.hh"
namespace Mdx
{
@ -324,11 +326,11 @@ public:
void MdxDictionary::deferredInit()
{
if ( !deferredInitDone )
if ( !Qt4x5::AtomicInt::loadAcquire( deferredInitDone ) )
{
Mutex::Lock _( deferredInitMutex );
if ( deferredInitDone )
if ( Qt4x5::AtomicInt::loadAcquire( deferredInitDone ) )
return;
if ( !deferredInitRunnableStarted )
@ -349,11 +351,11 @@ string const & MdxDictionary::ensureInitDone()
void MdxDictionary::doDeferredInit()
{
if ( !deferredInitDone )
if ( !Qt4x5::AtomicInt::loadAcquire( deferredInitDone ) )
{
Mutex::Lock _( deferredInitMutex );
if ( deferredInitDone )
if ( Qt4x5::AtomicInt::loadAcquire( deferredInitDone ) )
return;
// Do deferred init
@ -493,7 +495,7 @@ void MdxArticleRequestRunnable::run()
void MdxArticleRequest::run()
{
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;
@ -525,7 +527,7 @@ void MdxArticleRequest::run()
for ( unsigned x = 0; x < chain.size(); ++x )
{
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;
@ -671,7 +673,7 @@ void MddResourceRequestRunnable::run()
void MddResourceRequest::run()
{
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;
@ -690,7 +692,7 @@ void MddResourceRequest::run()
for ( ;; )
{
// Some runnables linger enough that they are cancelled before they start
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;

View file

@ -10,6 +10,7 @@
#include <list>
#include "dprintf.hh"
#include "audiolink.hh"
#include "qt4x5.hh"
namespace MediaWiki {
@ -112,7 +113,7 @@ MediaWikiWordSearchRequest::MediaWikiWordSearchRequest( wstring const & str,
DPRINTF( "request begin\n" );
QUrl reqUrl( url + "/api.php?action=query&list=allpages&aplimit=40&format=xml" );
reqUrl.addQueryItem( "apfrom", gd::toQString( str ) );
Qt4x5::Url::addQueryItem( reqUrl, "apfrom", gd::toQString( str ) );
netReply = mgr.get( QNetworkRequest( reqUrl ) );
@ -252,7 +253,7 @@ void MediaWikiArticleRequest::addQuery( QNetworkAccessManager & mgr,
QUrl reqUrl( url + "/api.php?action=parse&prop=text|revid&format=xml&redirects" );
reqUrl.addQueryItem( "page", gd::toQString( str ) );
Qt4x5::Url::addQueryItem( reqUrl, "page", gd::toQString( str ) );
sptr< QNetworkReply > netReply = mgr.get( QNetworkRequest( reqUrl ) );

View file

@ -7,6 +7,8 @@
#include "language.hh"
#include "fsencoding.hh"
#include <algorithm>
#include <QMenu>
#include <QPair>
using std::vector;

106
qt4x5.hh Normal file
View file

@ -0,0 +1,106 @@
/* Thin wrappers for retaining compatibility for both Qt4.x and Qt5.x */
#ifndef QT4X5_HH
#define QT4X5_HH
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
# define IS_QT_5 0
#else
# define IS_QT_5 1
#endif
#include <QString>
#include <QAtomicInt>
#include <QTextDocument>
#include <QUrl>
#if IS_QT_5
#include <QUrlQuery>
#endif
namespace Qt4x5
{
inline QString escape( QString const & plain )
{
#if IS_QT_5
return plain.toHtmlEscaped();
#else
return Qt::escape( plain );
#endif
}
namespace AtomicInt
{
inline int loadAcquire( QAtomicInt const & ref )
{
#if IS_QT_5
return ref.loadAcquire();
#else
return ( int )ref;
#endif
}
}
namespace Url
{
inline bool hasQueryItem( QUrl const & url, QString const & key )
{
#if IS_QT_5
return QUrlQuery( url ).hasQueryItem( key );
#else
return url.hasQueryItem( key );
#endif
}
inline QString queryItemValue( QUrl const & url, QString const & item )
{
#if IS_QT_5
return QUrlQuery( url ).queryItemValue( item );
#else
return url.queryItemValue( item );
#endif
}
inline void addQueryItem( QUrl & url, QString const & key, QString const & value )
{
#if IS_QT_5
QUrlQuery urlQuery( url );
urlQuery.addQueryItem( key, value );
url.setQuery( urlQuery );
#else
url.addQueryItem( key, value );
#endif
}
inline void removeQueryItem( QUrl & url, QString const & key )
{
#if IS_QT_5
QUrlQuery urlQuery( url );
urlQuery.removeQueryItem( key );
url.setQuery( urlQuery );
#else
url.removeQueryItem( key );
#endif
}
inline void setQueryItems( QUrl & url, QList< QPair< QString, QString > > const & query )
{
#if IS_QT_5
QUrlQuery urlQuery( url );
urlQuery.setQueryItems( query );
url.setQuery( urlQuery );
#else
url.setQueryItems( query );
#endif
}
}
}
#endif // QT4X5_HH

View file

@ -26,6 +26,7 @@
#include <QDomDocument>
#include "ufile.hh"
#include "qt4x5.hh"
namespace Sdict {
@ -406,7 +407,7 @@ void SdictArticleRequestRunnable::run()
void SdictArticleRequest::run()
{
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;
@ -433,7 +434,7 @@ void SdictArticleRequest::run()
for( unsigned x = 0; x < chain.size(); ++x )
{
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;

View file

@ -367,7 +367,7 @@ void MediaWikisModel::addNewWiki()
QModelIndex MediaWikisModel::index( int row, int column, QModelIndex const & /*parent*/ ) const
{
return createIndex( row, column, 0 );
return createIndex( row, column );
}
QModelIndex MediaWikisModel::parent( QModelIndex const & /*parent*/ ) const
@ -524,7 +524,7 @@ void WebSitesModel::addNewSite()
QModelIndex WebSitesModel::index( int row, int column, QModelIndex const & /*parent*/ ) const
{
return createIndex( row, column, 0 );
return createIndex( row, column );
}
QModelIndex WebSitesModel::parent( QModelIndex const & /*parent*/ ) const
@ -681,7 +681,7 @@ void ProgramsModel::addNewProgram()
QModelIndex ProgramsModel::index( int row, int column, QModelIndex const & /*parent*/ ) const
{
return createIndex( row, column, 0 );
return createIndex( row, column );
}
QModelIndex ProgramsModel::parent( QModelIndex const & /*parent*/ ) const
@ -870,7 +870,7 @@ void PathsModel::addNewPath( QString const & path )
QModelIndex PathsModel::index( int row, int column, QModelIndex const & /*parent*/ ) const
{
return createIndex( row, column, 0 );
return createIndex( row, column );
}
QModelIndex PathsModel::parent( QModelIndex const & /*parent*/ ) const
@ -976,7 +976,7 @@ void SoundDirsModel::addNewSoundDir( QString const & path, QString const & name
QModelIndex SoundDirsModel::index( int row, int column, QModelIndex const & /*parent*/ ) const
{
return createIndex( row, column, 0 );
return createIndex( row, column );
}
QModelIndex SoundDirsModel::parent( QModelIndex const & /*parent*/ ) const
@ -1080,12 +1080,13 @@ HunspellDictsModel::HunspellDictsModel( QWidget * parent,
void HunspellDictsModel::changePath( QString const & newPath )
{
dataFiles = HunspellMorpho::findDataFiles( newPath );
reset();
beginResetModel();
endResetModel();
}
QModelIndex HunspellDictsModel::index( int row, int column, QModelIndex const & /*parent*/ ) const
{
return createIndex( row, column, 0 );
return createIndex( row, column );
}
QModelIndex HunspellDictsModel::parent( QModelIndex const & /*parent*/ ) const

View file

@ -36,6 +36,7 @@
#include <QAtomicInt>
#include "ufile.hh"
#include "qt4x5.hh"
namespace Stardict {
@ -613,7 +614,7 @@ void StardictHeadwordsRequestRunnable::run()
void StardictHeadwordsRequest::run()
{
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;
@ -627,7 +628,7 @@ void StardictHeadwordsRequest::run()
for( unsigned x = 0; x < chain.size(); ++x )
{
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;
@ -733,7 +734,7 @@ void StardictArticleRequestRunnable::run()
void StardictArticleRequest::run()
{
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;
@ -762,7 +763,7 @@ void StardictArticleRequest::run()
for( unsigned x = 0; x < chain.size(); ++x )
{
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;
@ -1011,7 +1012,7 @@ void StardictResourceRequestRunnable::run()
void StardictResourceRequest::run()
{
// Some runnables linger enough that they are cancelled before they start
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;

View file

@ -180,7 +180,7 @@ void VoiceEnginesModel::addNewVoiceEngine( QString const & id, QString const & n
QModelIndex VoiceEnginesModel::index( int row, int column, QModelIndex const & /*parent*/ ) const
{
return createIndex( row, column, 0 );
return createIndex( row, column );
}
QModelIndex VoiceEnginesModel::parent( QModelIndex const & /*parent*/ ) const

View file

@ -15,6 +15,8 @@
#include <QFileInfo>
#include <QCryptographicHash>
#include "qt4x5.hh"
namespace VoiceEngines
{
@ -93,7 +95,7 @@ sptr< Dictionary::DataRequest > VoiceEnginesDictionary::getArticle(
url.setPath( QString::fromUtf8( wordUtf8.c_str() ) );
QList< QPair<QString, QString> > query;
query.push_back( QPair<QString, QString>( "engine", QString::fromStdString( getId() ) ) );
url.setQueryItems( query );
Qt4x5::Url::setQueryItems( url, query );
string encodedUrl = url.toEncoded().data();
string ref = string( "\"" ) + encodedUrl + "\"";

View file

@ -6,6 +6,10 @@
#include "w_char.hxx"
#ifdef near
# undef near
#endif
class LIBHUNSPELL_DLL_EXPORTED RepList
{
protected:
@ -24,4 +28,5 @@ public:
int match(const char * word, int n);
int conv(const char * word, char * dest);
};
#endif

Binary file not shown.

16
xdxf.cc
View file

@ -36,6 +36,8 @@
#include <QThreadPool>
#include <QAtomicInt>
#include "qt4x5.hh"
namespace Xdxf {
using std::map;
@ -393,7 +395,7 @@ void XdxfArticleRequestRunnable::run()
void XdxfArticleRequest::run()
{
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;
@ -420,7 +422,7 @@ void XdxfArticleRequest::run()
for( unsigned x = 0; x < chain.size(); ++x )
{
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;
@ -648,21 +650,21 @@ QString readXhtmlData( QXmlStreamReader & stream )
{
QString name = stream.name().toString();
result += "<" + Qt::escape( name ) + " ";
result += "<" + Qt4x5::escape( name ) + " ";
QXmlStreamAttributes attrs = stream.attributes();
for( int x = 0; x < attrs.size(); ++x )
{
result += Qt::escape( attrs[ x ].name().toString() );
result += "=\"" + Qt::escape( attrs[ x ].value().toString() ) + "\"";
result += Qt4x5::escape( attrs[ x ].name().toString() );
result += "=\"" + Qt4x5::escape( attrs[ x ].value().toString() ) + "\"";
}
result += ">";
result += readXhtmlData( stream );
result += "</" + Qt::escape( name ) + ">";
result += "</" + Qt4x5::escape( name ) + ">";
}
else
if ( stream.isCharacters() || stream.isWhitespace() || stream.isCDATA() )
@ -862,7 +864,7 @@ void XdxfResourceRequestRunnable::run()
void XdxfResourceRequest::run()
{
// Some runnables linger enough that they are cancelled before they start
if ( isCancelled )
if ( Qt4x5::AtomicInt::loadAcquire( isCancelled ) )
{
finish();
return;