mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-28 03:44:07 +00:00
Merge pull request #873 from shenlebantongying/zim_icon
feat: load and display ZIM dictionary icon
This commit is contained in:
commit
7fa6d42c3b
|
@ -41,6 +41,8 @@
|
||||||
#include <zim/archive.h>
|
#include <zim/archive.h>
|
||||||
#include <zim/entry.h>
|
#include <zim/entry.h>
|
||||||
#include <zim/item.h>
|
#include <zim/item.h>
|
||||||
|
#include <zim/error.h>
|
||||||
|
|
||||||
namespace Zim {
|
namespace Zim {
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
@ -275,17 +277,31 @@ void ZimDictionary::loadIcon() noexcept
|
||||||
if ( dictionaryIconLoaded )
|
if ( dictionaryIconLoaded )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Try to load Original GD's user provided icon
|
||||||
QString fileName = QDir::fromNativeSeparators( getDictionaryFilenames()[ 0 ].c_str() );
|
QString fileName = QDir::fromNativeSeparators( getDictionaryFilenames()[ 0 ].c_str() );
|
||||||
|
|
||||||
// Remove the extension
|
// Remove the extension
|
||||||
fileName.chop( 3 );
|
fileName.chop( 3 );
|
||||||
|
if ( loadIconFromFile( fileName ) ) {
|
||||||
if( !loadIconFromFile( fileName ) )
|
dictionaryIconLoaded = true;
|
||||||
{
|
return;
|
||||||
// Load failed -- use default icons
|
|
||||||
dictionaryNativeIcon = dictionaryIcon = QIcon(":/icons/icon32_zim.png");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try to load zim's illustration, which is usually 48x48 png
|
||||||
|
try {
|
||||||
|
auto illustration = df.getIllustrationItem( 48 ).getData();
|
||||||
|
QImage img = QImage::fromData( reinterpret_cast< const uchar * >( illustration.data() ), illustration.size() );
|
||||||
|
dictionaryNativeIcon = dictionaryIcon = QIcon( QPixmap::fromImage( img ) );
|
||||||
|
|
||||||
|
dictionaryIconLoaded = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch ( zim::EntryNotFound & e ) {
|
||||||
|
gdDebug( "ZIM icon not loaded for: %s", dictionaryName.c_str() );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback to default icon
|
||||||
|
dictionaryNativeIcon = dictionaryIcon = QIcon( ":/icons/icon32_zim.png" );
|
||||||
|
|
||||||
dictionaryIconLoaded = true;
|
dictionaryIconLoaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue