mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 00:14:06 +00:00
Merge pull request #108 from vtliem/WikiFix20120621
Wiki images fix @https://github.com/goldendict/goldendict/issues/102
This commit is contained in:
commit
1f67465870
21
config.cc
21
config.cc
|
@ -167,14 +167,14 @@ MediaWikis makeDefaultMediaWikis( bool enable )
|
|||
{
|
||||
MediaWikis mw;
|
||||
|
||||
mw.push_back( MediaWiki( "ae6f89aac7151829681b85f035d54e48", "English Wikipedia", "http://en.wikipedia.org/w", enable ) );
|
||||
mw.push_back( MediaWiki( "affcf9678e7bfe701c9b071f97eccba3", "English Wiktionary", "http://en.wiktionary.org/w", false ) );
|
||||
mw.push_back( MediaWiki( "8e0c1c2b6821dab8bdba8eb869ca7176", "Russian Wikipedia", "http://ru.wikipedia.org/w", false ) );
|
||||
mw.push_back( MediaWiki( "b09947600ae3902654f8ad4567ae8567", "Russian Wiktionary", "http://ru.wiktionary.org/w", false ) );
|
||||
mw.push_back( MediaWiki( "a8a66331a1242ca2aeb0b4aed361c41d", "German Wikipedia", "http://de.wikipedia.org/w", false ) );
|
||||
mw.push_back( MediaWiki( "21c64bca5ec10ba17ff19f3066bc962a", "German Wiktionary", "http://de.wiktionary.org/w", false ) );
|
||||
mw.push_back( MediaWiki( "96957cb2ad73a20c7a1d561fc83c253a", "Portuguese Wikipedia", "http://pt.wikipedia.org/w", false ) );
|
||||
mw.push_back( MediaWiki( "ed4c3929196afdd93cc08b9a903aad6a", "Portuguese Wiktionary", "http://pt.wiktionary.org/w", false ) );
|
||||
mw.push_back( MediaWiki( "ae6f89aac7151829681b85f035d54e48", "English Wikipedia", "http://en.wikipedia.org/w", enable, "" ) );
|
||||
mw.push_back( MediaWiki( "affcf9678e7bfe701c9b071f97eccba3", "English Wiktionary", "http://en.wiktionary.org/w", false, "" ) );
|
||||
mw.push_back( MediaWiki( "8e0c1c2b6821dab8bdba8eb869ca7176", "Russian Wikipedia", "http://ru.wikipedia.org/w", false, "" ) );
|
||||
mw.push_back( MediaWiki( "b09947600ae3902654f8ad4567ae8567", "Russian Wiktionary", "http://ru.wiktionary.org/w", false, "" ) );
|
||||
mw.push_back( MediaWiki( "a8a66331a1242ca2aeb0b4aed361c41d", "German Wikipedia", "http://de.wikipedia.org/w", false, "" ) );
|
||||
mw.push_back( MediaWiki( "21c64bca5ec10ba17ff19f3066bc962a", "German Wiktionary", "http://de.wiktionary.org/w", false, "" ) );
|
||||
mw.push_back( MediaWiki( "96957cb2ad73a20c7a1d561fc83c253a", "Portuguese Wikipedia", "http://pt.wikipedia.org/w", false, "" ) );
|
||||
mw.push_back( MediaWiki( "ed4c3929196afdd93cc08b9a903aad6a", "Portuguese Wiktionary", "http://pt.wiktionary.org/w", false, "" ) );
|
||||
|
||||
return mw;
|
||||
}
|
||||
|
@ -552,6 +552,7 @@ Class load() throw( exError )
|
|||
w.name = mw.attribute( "name" );
|
||||
w.url = mw.attribute( "url" );
|
||||
w.enabled = ( mw.attribute( "enabled" ) == "1" );
|
||||
w.icon = mw.attribute( "icon" );
|
||||
|
||||
c.mediawikis.push_back( w );
|
||||
}
|
||||
|
@ -1016,6 +1017,10 @@ void save( Class const & c ) throw( exError )
|
|||
QDomAttr enabled = dd.createAttribute( "enabled" );
|
||||
enabled.setValue( i->enabled ? "1" : "0" );
|
||||
mw.setAttributeNode( enabled );
|
||||
|
||||
QDomAttr icon = dd.createAttribute( "icon" );
|
||||
icon.setValue( i->icon );
|
||||
mw.setAttributeNode( icon );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -198,19 +198,19 @@ struct Preferences
|
|||
/// A MediaWiki network dictionary definition
|
||||
struct MediaWiki
|
||||
{
|
||||
QString id, name, url;
|
||||
QString id, name, url, icon;
|
||||
bool enabled;
|
||||
|
||||
MediaWiki(): enabled( false )
|
||||
{}
|
||||
|
||||
MediaWiki( QString const & id_, QString const & name_, QString const & url_,
|
||||
bool enabled_ ):
|
||||
id( id_ ), name( name_ ), url( url_ ), enabled( enabled_ ) {}
|
||||
bool enabled_, QString icon_ ):
|
||||
id( id_ ), name( name_ ), url( url_ ), enabled( enabled_ ), icon( icon_ ) {}
|
||||
|
||||
bool operator == ( MediaWiki const & other ) const
|
||||
{ return id == other.id && name == other.name && url == other.url &&
|
||||
enabled == other.enabled; }
|
||||
enabled == other.enabled && icon == other.icon ; }
|
||||
};
|
||||
|
||||
/// Any website which can be queried though a simple template substitution
|
||||
|
|
17
mediawiki.cc
17
mediawiki.cc
|
@ -20,17 +20,19 @@ namespace {
|
|||
class MediaWikiDictionary: public Dictionary::Class
|
||||
{
|
||||
string name;
|
||||
QString url;
|
||||
QString url, icon;
|
||||
QNetworkAccessManager & netMgr;
|
||||
|
||||
public:
|
||||
|
||||
MediaWikiDictionary( string const & id, string const & name_,
|
||||
QString const & url_,
|
||||
QString const & icon_,
|
||||
QNetworkAccessManager & netMgr_ ):
|
||||
Dictionary::Class( id, vector< string >() ),
|
||||
name( name_ ),
|
||||
url( url_ ),
|
||||
icon( icon_ ),
|
||||
netMgr( netMgr_ )
|
||||
{
|
||||
}
|
||||
|
@ -48,7 +50,15 @@ public:
|
|||
{ return 0; }
|
||||
|
||||
virtual QIcon getIcon() throw()
|
||||
{ return QIcon(":/icons/icon32_wiki.png"); }
|
||||
{
|
||||
if( !icon.isNull() && !icon.isEmpty() )
|
||||
{
|
||||
QFileInfo fInfo( QDir( Config::getConfigDir() ), icon );
|
||||
if( fInfo.isFile() )
|
||||
return QIcon( fInfo.absoluteFilePath() );
|
||||
}
|
||||
return QIcon(":/icons/icon32_wiki.png");
|
||||
}
|
||||
|
||||
virtual sptr< WordSearchRequest > prefixMatch( wstring const &,
|
||||
unsigned long maxResults ) throw( std::exception );
|
||||
|
@ -307,6 +317,8 @@ void MediaWikiArticleRequest::requestFinished( QNetworkReply * r )
|
|||
|
||||
// Add "http:" to image source urls
|
||||
articleString.replace( " src=\"//", " src=\"http://" );
|
||||
//fix src="/foo/bar/Baz.png"
|
||||
articleString.replace( "src=\"/", "src=\"" + url +"/" );
|
||||
|
||||
// Replace the href="/foo/bar/Baz" to just href="Baz".
|
||||
articleString.replace( QRegExp( "<a\\shref=\"/([\\w\\.]*/)*" ), "<a href=\"" );
|
||||
|
@ -409,6 +421,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
|
|||
result.push_back( new MediaWikiDictionary( wikis[ x ].id.toStdString(),
|
||||
wikis[ x ].name.toUtf8().data(),
|
||||
wikis[ x ].url,
|
||||
wikis[ x ].icon,
|
||||
mgr ) );
|
||||
}
|
||||
|
||||
|
|
11
sources.cc
11
sources.cc
|
@ -40,6 +40,7 @@ Sources::Sources( QWidget * parent, Config::Paths const & paths,
|
|||
ui.mediaWikis->resizeColumnToContents( 0 );
|
||||
ui.mediaWikis->resizeColumnToContents( 1 );
|
||||
ui.mediaWikis->resizeColumnToContents( 2 );
|
||||
ui.mediaWikis->resizeColumnToContents( 3 );
|
||||
|
||||
ui.webSites->setTabKeyNavigation( true );
|
||||
ui.webSites->setModel( &webSitesModel );
|
||||
|
@ -378,7 +379,7 @@ int MediaWikisModel::columnCount( QModelIndex const & parent ) const
|
|||
if ( parent.isValid() )
|
||||
return 0;
|
||||
else
|
||||
return 3;
|
||||
return 4;
|
||||
}
|
||||
|
||||
QVariant MediaWikisModel::headerData( int section, Qt::Orientation /*orientation*/, int role ) const
|
||||
|
@ -392,6 +393,8 @@ QVariant MediaWikisModel::headerData( int section, Qt::Orientation /*orientation
|
|||
return tr( "Name" );
|
||||
case 2:
|
||||
return tr( "Address" );
|
||||
case 3:
|
||||
return tr( "Icon" );
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
@ -412,6 +415,8 @@ QVariant MediaWikisModel::data( QModelIndex const & index, int role ) const
|
|||
return mediawikis[ index.row() ].name;
|
||||
case 2:
|
||||
return mediawikis[ index.row() ].url;
|
||||
case 3:
|
||||
return mediawikis[ index.row() ].icon;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
@ -452,6 +457,10 @@ bool MediaWikisModel::setData( QModelIndex const & index, const QVariant & value
|
|||
mediawikis[ index.row() ].url = value.toString();
|
||||
dataChanged( index, index );
|
||||
return true;
|
||||
case 3:
|
||||
mediawikis[ index.row() ].icon = value.toString();
|
||||
dataChanged( index, index );
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue