diff --git a/aard.cc b/aard.cc index 2505aeaa..ac1963f6 100644 --- a/aard.cc +++ b/aard.cc @@ -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; diff --git a/about.cc b/about.cc index e784ed82..800c7b12 100644 --- a/about.cc +++ b/about.cc @@ -4,6 +4,8 @@ #include "about.hh" #include +#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( ":" ); diff --git a/article_netmgr.cc b/article_netmgr.cc index 9902c818..7fab6e49 100644 --- a/article_netmgr.cc +++ b/article_netmgr.cc @@ -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() ) { diff --git a/articleview.cc b/articleview.cc index 93e77009..59ec808e 100644 --- a/articleview.cc +++ b/articleview.cc @@ -12,15 +12,16 @@ #include #include #include +#include +#include +#include #include "folding.hh" #include "wstring_qt.hh" #include "webmultimediadownload.hh" #include "programs.hh" #include "dprintf.hh" #include "ffmpegaudio.hh" -#include -#include -#include +#include "qt4x5.hh" #include @@ -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(); diff --git a/bgl.cc b/bgl.cc index 00acb070..54ea9b37 100644 --- a/bgl.cc +++ b/bgl.cc @@ -31,6 +31,8 @@ #include +#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 >() ); diff --git a/btreeidx.cc b/btreeidx.cc index 5806ba20..edfbb40b 100644 --- a/btreeidx.cc +++ b/btreeidx.cc @@ -11,6 +11,7 @@ #include #include #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 ); diff --git a/dictionary.cc b/dictionary.cc index f5f3b94c..3446065d 100644 --- a/dictionary.cc +++ b/dictionary.cc @@ -23,22 +23,24 @@ #include #include +#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(); diff --git a/dsl.cc b/dsl.cc index a7a9b7c6..36af633b 100644 --- a/dsl.cc +++ b/dsl.cc @@ -48,6 +48,8 @@ // For SVG handling #include +#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; diff --git a/ffmpegaudio.cc b/ffmpegaudio.cc index ca0bb195..3ddb7164 100644 --- a/ffmpegaudio.cc +++ b/ffmpegaudio.cc @@ -24,6 +24,8 @@ extern "C" { #include +#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; } diff --git a/goldendict.pro b/goldendict.pro index 8653a234..6871b9a6 100644 --- a/goldendict.pro +++ b/goldendict.pro @@ -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} diff --git a/groups_widgets.cc b/groups_widgets.cc index 0548de06..8932e606 100644 --- a/groups_widgets.cc +++ b/groups_widgets.cc @@ -17,6 +17,8 @@ #include #include #include +#include +#include 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(); } } diff --git a/historypanewidget.cc b/historypanewidget.cc index 68687362..46f52001 100644 --- a/historypanewidget.cc +++ b/historypanewidget.cc @@ -254,5 +254,6 @@ void HistoryModel::historyChanged() { // qDebug() << "History Changed!!"; - reset(); + beginResetModel(); + endResetModel(); } diff --git a/hotkeywrapper.cc b/hotkeywrapper.cc index 73404ff0..28939b0b 100644 --- a/hotkeywrapper.cc +++ b/hotkeywrapper.cc @@ -4,6 +4,10 @@ #endif #include "hotkeywrapper.hh" + +#include +#include + #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 diff --git a/hotkeywrapper.hh b/hotkeywrapper.hh index 1e5a2669..8d3b112e 100644 --- a/hotkeywrapper.hh +++ b/hotkeywrapper.hh @@ -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 hotkeyWrappers; }; diff --git a/hunspell.cc b/hunspell.cc index 149483ee..34ad9fa6 100644 --- a/hunspell.cc +++ b/hunspell.cc @@ -9,17 +9,21 @@ #include "wstring_qt.hh" #include "language.hh" #include "langcoder.hh" + #include #include #include #include #include #include +#include + #include #include + #include "dprintf.hh" #include "fsencoding.hh" -#include +#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; diff --git a/mainwindow.cc b/mainwindow.cc index 79619247..12fedc60 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -7,7 +7,9 @@ #include "preferences.hh" #include "about.hh" #include "mruqmenu.hh" -#include + +#include +#include #include #include #include @@ -15,16 +17,22 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include + +#include #include #include #include "dprintf.hh" -#include -#include + #include "dictinfo.hh" #include "fsencoding.hh" -#include #include "historypanewidget.hh" -#include #ifdef Q_OS_MAC #include "lionsupport.h" diff --git a/mdx.cc b/mdx.cc index a70fd0dc..5a597b6e 100644 --- a/mdx.cc +++ b/mdx.cc @@ -35,6 +35,8 @@ #include #include +#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; diff --git a/mediawiki.cc b/mediawiki.cc index c563826f..5dc43a2e 100644 --- a/mediawiki.cc +++ b/mediawiki.cc @@ -10,6 +10,7 @@ #include #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 ) ); diff --git a/orderandprops.cc b/orderandprops.cc index af8f0631..ecc458b6 100644 --- a/orderandprops.cc +++ b/orderandprops.cc @@ -7,6 +7,8 @@ #include "language.hh" #include "fsencoding.hh" #include + +#include #include using std::vector; diff --git a/qt4x5.hh b/qt4x5.hh new file mode 100644 index 00000000..60b616aa --- /dev/null +++ b/qt4x5.hh @@ -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 +#include +#include + +#include +#if IS_QT_5 +#include +#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 diff --git a/sdict.cc b/sdict.cc index 7a158593..022d9435 100644 --- a/sdict.cc +++ b/sdict.cc @@ -26,6 +26,7 @@ #include #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; diff --git a/sources.cc b/sources.cc index bf7c5fda..538478f2 100644 --- a/sources.cc +++ b/sources.cc @@ -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 diff --git a/stardict.cc b/stardict.cc index eead0451..4d5116e5 100644 --- a/stardict.cc +++ b/stardict.cc @@ -36,6 +36,7 @@ #include #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; diff --git a/texttospeechsource.cc b/texttospeechsource.cc index edc2199c..21500658 100644 --- a/texttospeechsource.cc +++ b/texttospeechsource.cc @@ -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 diff --git a/voiceengines.cc b/voiceengines.cc index e12adb3a..d9b7eaa2 100644 --- a/voiceengines.cc +++ b/voiceengines.cc @@ -15,6 +15,8 @@ #include #include +#include "qt4x5.hh" + namespace VoiceEngines { @@ -93,7 +95,7 @@ sptr< Dictionary::DataRequest > VoiceEnginesDictionary::getArticle( url.setPath( QString::fromUtf8( wordUtf8.c_str() ) ); QList< QPair > query; query.push_back( QPair( "engine", QString::fromStdString( getId() ) ) ); - url.setQueryItems( query ); + Qt4x5::Url::setQueryItems( url, query ); string encodedUrl = url.toEncoded().data(); string ref = string( "\"" ) + encodedUrl + "\""; diff --git a/winlibs/include/hunspell/replist.hxx b/winlibs/include/hunspell/replist.hxx index 9c37e29b..ea3ed52e 100644 --- a/winlibs/include/hunspell/replist.hxx +++ b/winlibs/include/hunspell/replist.hxx @@ -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 diff --git a/winlibs/lib/libhunspell-1.3.a b/winlibs/lib/libhunspell-1.3.a new file mode 100644 index 00000000..4214b0fb Binary files /dev/null and b/winlibs/lib/libhunspell-1.3.a differ diff --git a/xdxf.cc b/xdxf.cc index a40a56ae..0e8add48 100644 --- a/xdxf.cc +++ b/xdxf.cc @@ -36,6 +36,8 @@ #include #include +#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 += ""; + result += ""; } 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;