mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
feat: add -v --version flag to CLI
* also abstract version info into a standalone namespace
This commit is contained in:
parent
85caaffd8e
commit
9d19ea1ebc
|
@ -290,16 +290,17 @@ HEADERS += \
|
|||
src/ankiconnector.hh \
|
||||
src/article_maker.hh \
|
||||
src/article_netmgr.hh \
|
||||
src/common/atomic_rename.hh \
|
||||
src/audiolink.hh \
|
||||
src/audioplayerfactory.hh \
|
||||
src/audioplayerinterface.hh \
|
||||
src/btreeidx.hh \
|
||||
src/chunkedstorage.hh \
|
||||
src/common/atomic_rename.hh \
|
||||
src/common/base_type.hh \
|
||||
src/common/ex.hh \
|
||||
src/common/file.hh \
|
||||
src/common/filetype.hh \
|
||||
src/common/folding.hh \
|
||||
src/common/gddebug.hh \
|
||||
src/common/globalbroadcaster.hh \
|
||||
src/common/globalregex.hh \
|
||||
|
@ -358,7 +359,6 @@ HEADERS += \
|
|||
src/externalviewer.hh \
|
||||
src/ffmpegaudio.hh \
|
||||
src/ffmpegaudioplayer.hh \
|
||||
src/common/folding.hh \
|
||||
src/ftshelpers.hh \
|
||||
src/fulltextsearch.hh \
|
||||
src/gestures.hh \
|
||||
|
@ -406,6 +406,7 @@ HEADERS += \
|
|||
src/ui/searchpanewidget.hh \
|
||||
src/ui/stylescombobox.hh \
|
||||
src/ui/translatebox.hh \
|
||||
src/version.hh \
|
||||
src/webmultimediadownload.hh \
|
||||
src/weburlrequestinterceptor.hh \
|
||||
src/wordfinder.hh \
|
||||
|
@ -418,13 +419,14 @@ SOURCES += \
|
|||
src/ankiconnector.cc \
|
||||
src/article_maker.cc \
|
||||
src/article_netmgr.cc \
|
||||
src/common/atomic_rename.cc \
|
||||
src/audiolink.cc \
|
||||
src/audioplayerfactory.cc \
|
||||
src/btreeidx.cc \
|
||||
src/chunkedstorage.cc \
|
||||
src/common/atomic_rename.cc \
|
||||
src/common/file.cc \
|
||||
src/common/filetype.cc \
|
||||
src/common/folding.cc \
|
||||
src/common/gddebug.cc \
|
||||
src/common/globalbroadcaster.cc \
|
||||
src/common/globalregex.cc \
|
||||
|
@ -479,7 +481,6 @@ SOURCES += \
|
|||
src/externalaudioplayer.cc \
|
||||
src/externalviewer.cc \
|
||||
src/ffmpegaudio.cc \
|
||||
src/common/folding.cc \
|
||||
src/ftshelpers.cc \
|
||||
src/fulltextsearch.cc \
|
||||
src/gestures.cc \
|
||||
|
@ -526,6 +527,7 @@ SOURCES += \
|
|||
src/ui/searchpanel.cc \
|
||||
src/ui/stylescombobox.cc \
|
||||
src/ui/translatebox.cc \
|
||||
src/version.cc \
|
||||
src/webmultimediadownload.cc \
|
||||
src/weburlrequestinterceptor.cc \
|
||||
src/wordfinder.cc \
|
||||
|
|
11
src/main.cc
11
src/main.cc
|
@ -7,6 +7,7 @@
|
|||
#include "config.hh"
|
||||
#include <QWebEngineProfile>
|
||||
#include "hotkeywrapper.hh"
|
||||
#include "version.hh"
|
||||
#ifdef HAVE_X11
|
||||
#include <fixx11h.h>
|
||||
#endif
|
||||
|
@ -173,12 +174,17 @@ void processCommandLine( QCoreApplication * app, GDOptions * result)
|
|||
<< "toggle-scan-popup",
|
||||
QObject::tr( "Toggle scan popup." ) );
|
||||
|
||||
QCommandLineOption printVersion( QStringList() << "v"
|
||||
<< "version",
|
||||
QObject::tr( "Print version and diagnosis info." ) );
|
||||
|
||||
qcmd.addOption( logFileOption );
|
||||
qcmd.addOption( groupNameOption );
|
||||
qcmd.addOption( popupGroupNameOption );
|
||||
qcmd.addOption( togglePopupOption );
|
||||
qcmd.addOption( notts );
|
||||
qcmd.addOption( resetState );
|
||||
qcmd.addOption( printVersion );
|
||||
|
||||
QCommandLineOption doNothingOption( "disable-web-security" ); // ignore the --disable-web-security
|
||||
doNothingOption.setFlags( QCommandLineOption::HiddenFromHelp );
|
||||
|
@ -210,6 +216,11 @@ void processCommandLine( QCoreApplication * app, GDOptions * result)
|
|||
result->resetState = true;
|
||||
}
|
||||
|
||||
if ( qcmd.isSet( printVersion ) ) {
|
||||
qInfo() << qPrintable( Version::everything() );
|
||||
std::exit( 0 );
|
||||
}
|
||||
|
||||
const QStringList posArgs = qcmd.positionalArguments();
|
||||
if ( !posArgs.empty() ) {
|
||||
result->word = posArgs.at( 0 );
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "about.hh"
|
||||
#include "utils.hh"
|
||||
#include "version.hh"
|
||||
|
||||
#include <QClipboard>
|
||||
#include <QFile>
|
||||
|
@ -13,61 +14,15 @@ About::About( QWidget * parent, std::vector< sptr< Dictionary::Class > > * dicto
|
|||
{
|
||||
ui.setupUi( this );
|
||||
|
||||
QFile versionFile( ":/version.txt" );
|
||||
ui.version->setText( Version::version() );
|
||||
|
||||
QString version;
|
||||
ui.qtVersion->setText( tr( "Based on Qt %1 (%2, %3)" )
|
||||
.arg( QLatin1String( qVersion() ), Version::compiler, QSysInfo::currentCpuArchitecture() )
|
||||
+ " (Xapian inside)" );
|
||||
|
||||
if ( !versionFile.open( QFile::ReadOnly ) )
|
||||
version = tr( "[Unknown]" );
|
||||
else
|
||||
version = QString::fromLatin1( versionFile.readAll() ).trimmed();
|
||||
|
||||
ui.version->setText( version );
|
||||
|
||||
#if defined (_MSC_VER)
|
||||
QString compilerVersion = QString( "Visual C++ Compiler: %1" )
|
||||
.arg( _MSC_FULL_VER );
|
||||
#elif defined (__clang__) && defined (__clang_version__)
|
||||
QString compilerVersion = QLatin1String( "Clang " ) + QLatin1String( __clang_version__ );
|
||||
#else
|
||||
QString compilerVersion = QLatin1String( "GCC " ) + QLatin1String( __VERSION__ );
|
||||
#endif
|
||||
|
||||
ui.qtVersion->setText( tr( "Based on Qt %1 (%2, %3 bit)" ).arg(
|
||||
QLatin1String( qVersion() ),
|
||||
compilerVersion,
|
||||
QString::number( QSysInfo::WordSize ) )
|
||||
+" (Xapian inside)"
|
||||
);
|
||||
|
||||
// copy basic debug info to clipboard
|
||||
connect(ui.copyInfoBtn, &QPushButton::clicked, [=]{
|
||||
QGuiApplication::clipboard()->setText(
|
||||
"Goldendict " + version + "\n" +
|
||||
QSysInfo::productType() + " " + QSysInfo::kernelType() + " " + QSysInfo::kernelVersion() + " " +
|
||||
"Qt " + QLatin1String(qVersion()) + " " +
|
||||
QSysInfo::buildAbi() + "\n" +
|
||||
compilerVersion + "\n"
|
||||
+ "Flags:"
|
||||
+" USE_XAPIAN "
|
||||
|
||||
#ifdef MAKE_ZIM_SUPPORT
|
||||
+" MAKE_ZIM_SUPPORT"
|
||||
#endif
|
||||
|
||||
#ifdef NO_EPWING_SUPPORT
|
||||
+" NO_EPWING_SUPPORT"
|
||||
#endif
|
||||
|
||||
#ifdef USE_ICONV
|
||||
+" USE_ICONV"
|
||||
#endif
|
||||
|
||||
#ifdef MAKE_CHINESE_CONVERSION_SUPPORT
|
||||
+" MAKE_CHINESE_CONVERSION_SUPPORT"
|
||||
#endif
|
||||
);
|
||||
});
|
||||
connect( ui.copyInfoBtn, &QPushButton::clicked, [] {
|
||||
QGuiApplication::clipboard()->setText( Version::everything() );
|
||||
} );
|
||||
|
||||
connect(ui.copyDictListBtn, &QPushButton::clicked, [=]{
|
||||
QString tempDictList{};
|
||||
|
|
24
src/version.cc
Normal file
24
src/version.cc
Normal file
|
@ -0,0 +1,24 @@
|
|||
#include "version.hh"
|
||||
#include <QFile>
|
||||
|
||||
namespace Version {
|
||||
QString version()
|
||||
{
|
||||
QFile versionFile( ":/version.txt" );
|
||||
|
||||
if ( !versionFile.open( QFile::ReadOnly ) ) {
|
||||
return QStringLiteral( "[Unknown Version]" );
|
||||
}
|
||||
else {
|
||||
return versionFile.readAll().trimmed();
|
||||
}
|
||||
}
|
||||
|
||||
QString everything()
|
||||
{
|
||||
return QStringLiteral( "Goldendict-ng " ) + Version::version() + "\n" + "Qt " + QLatin1String( qVersion() ) + " "
|
||||
+ Version::compiler + QSysInfo::productType() + " " + QSysInfo::kernelType() + " " + QSysInfo::kernelVersion() + " "
|
||||
+ QSysInfo::buildAbi() + "\n" + "Flags:" + flags;
|
||||
}
|
||||
|
||||
} // namespace Version
|
40
src/version.hh
Normal file
40
src/version.hh
Normal file
|
@ -0,0 +1,40 @@
|
|||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace Version {
|
||||
|
||||
const QLatin1String flags = QLatin1String(
|
||||
"USE_XAPIAN"
|
||||
#ifdef MAKE_ZIM_SUPPORT
|
||||
" MAKE_ZIM_SUPPORT"
|
||||
#endif
|
||||
#ifdef NO_EPWING_SUPPORT
|
||||
" NO_EPWING_SUPPORT"
|
||||
#endif
|
||||
#ifdef USE_ICONV
|
||||
" USE_ICONV"
|
||||
#endif
|
||||
#ifdef MAKE_CHINESE_CONVERSION_SUPPORT
|
||||
" MAKE_CHINESE_CONVERSION_SUPPORT"
|
||||
#endif
|
||||
);
|
||||
|
||||
const QLatin1String compiler = QLatin1String(
|
||||
#if defined( Q_CC_MSVC )
|
||||
"Visual C++ Compiler " QT_STRINGIFY( _MSC_FULL_VER )
|
||||
#elif defined( Q_CC_CLANG )
|
||||
"Clang " __clang_version__
|
||||
#elif defined( Q_CC_GNU )
|
||||
"GCC " __VERSION__
|
||||
#else
|
||||
"Unknown complier"
|
||||
#endif
|
||||
);
|
||||
/// Version string from the version.txt
|
||||
QString version();
|
||||
|
||||
/// Full report of version & various information
|
||||
QString everything();
|
||||
|
||||
} // namespace Version
|
Loading…
Reference in a new issue