2006-03-05 17:24:44 +00:00
/**
2007-08-31 05:53:55 +00:00
* \ file GuiAbout . cpp
2006-03-05 17:24:44 +00:00
* This file is part of LyX , the document processor .
* Licence details can be found in the file COPYING .
*
* \ author Kalle Dalheimer
*
* Full author contact details are available in file CREDITS .
*/
# include <config.h>
2007-08-31 05:53:55 +00:00
# include "GuiAbout.h"
2020-08-12 14:24:40 -04:00
# include "GuiApplication.h"
2007-09-05 22:54:47 +00:00
2010-01-23 20:29:00 +00:00
# include "ui_AboutUi.h"
2006-03-05 17:24:44 +00:00
# include "qt_helpers.h"
2007-09-05 22:54:47 +00:00
# include "version.h"
2006-03-05 17:24:44 +00:00
2007-09-05 22:54:47 +00:00
# include "support/filetools.h"
2009-01-15 13:31:05 +00:00
# include "support/gettext.h"
# include "support/lstrings.h"
2007-09-05 22:54:47 +00:00
# include "support/Package.h"
2006-03-05 17:24:44 +00:00
2020-08-12 14:24:40 -04:00
# include <QClipboard>
2009-01-15 13:31:05 +00:00
# include <QDate>
2013-05-15 07:47:02 +02:00
# include <QFile>
2013-05-12 12:27:16 +02:00
# include <QTextStream>
2006-03-05 17:24:44 +00:00
2009-01-15 13:31:05 +00:00
using namespace lyx : : support ;
2007-09-05 22:54:47 +00:00
using lyx : : support : : package ;
using lyx : : support : : makeDisplayPath ;
2006-03-05 17:24:44 +00:00
2007-09-05 20:33:29 +00:00
2006-03-05 17:24:44 +00:00
namespace lyx {
namespace frontend {
2009-01-15 13:31:05 +00:00
static QDate release_date ( )
{
return QDate : : fromString ( QString ( lyx_release_date ) , Qt : : ISODate ) ;
}
2007-09-05 22:54:47 +00:00
static QString credits ( )
2006-03-05 17:24:44 +00:00
{
2007-09-05 22:54:47 +00:00
QString res ;
2010-04-21 01:19:09 +00:00
QFile file ( toqstr ( package ( ) . system_support ( ) . absFileName ( ) ) + " /CREDITS " ) ;
2007-09-05 22:54:47 +00:00
QTextStream out ( & res ) ;
2015-05-18 11:15:11 +02:00
if ( ! file . exists ( ) ) {
out < < qt_ ( " ERROR: LyX wasn't able to find the CREDITS file \n " ) ;
2018-02-22 20:55:35 +01:00
out < < qt_ ( " Please install correctly to estimate the great \n amount of work other people have done for the LyX project. " ) ;
2007-09-05 22:54:47 +00:00
} else {
file . open ( QIODevice : : ReadOnly ) ;
2015-05-18 11:15:11 +02:00
if ( ! file . isReadable ( ) ) {
out < < qt_ ( " ERROR: LyX wasn't able to read the CREDITS file \n " ) ;
2018-02-22 20:55:35 +01:00
out < < qt_ ( " Please install correctly to estimate the great \n amount of work other people have done for the LyX project. " ) ;
2015-05-18 11:15:11 +02:00
} else {
QTextStream ts ( & file ) ;
ts . setCodec ( " UTF-8 " ) ;
QString line ;
do {
line = ts . readLine ( ) ;
2019-08-14 21:23:48 -04:00
if ( line . startsWith ( " # " ) )
continue ;
2015-05-18 11:15:11 +02:00
if ( line . startsWith ( " @b " ) )
out < < " <b> " < < line . mid ( 2 ) < < " </b> " ;
else if ( line . startsWith ( " @i " ) ) {
if ( line . startsWith ( " @iE-mail " ) ) {
// unmask email
line . replace ( QString ( " () " ) , QString ( " @ " ) ) ;
line . replace ( QString ( " ! " ) , QString ( " . " ) ) ;
}
out < < " <i> " < < line . mid ( 2 ) < < " </i> " ;
} else
out < < line ;
out < < " <br> " ;
} while ( ! line . isNull ( ) ) ;
}
2007-09-05 22:54:47 +00:00
}
out . flush ( ) ;
return res ;
}
2006-03-05 17:24:44 +00:00
2015-05-19 09:57:52 +02:00
static QString release_notes ( )
{
QString res ;
QFile file ( toqstr ( package ( ) . system_support ( ) . absFileName ( ) ) + " /RELEASE-NOTES " ) ;
QTextStream out ( & res ) ;
if ( ! file . exists ( ) ) {
out < < qt_ ( " ERROR: LyX wasn't able to find the RELEASE-NOTES file \n " ) ;
2018-02-22 20:55:35 +01:00
out < < qt_ ( " Please install correctly to see what has changed \n for this version of LyX. " ) ;
2015-05-19 09:57:52 +02:00
} else {
file . open ( QIODevice : : ReadOnly ) ;
if ( ! file . isReadable ( ) ) {
out < < qt_ ( " ERROR: LyX wasn't able to read the RELEASE-NOTES file \n " ) ;
2018-02-22 20:55:35 +01:00
out < < qt_ ( " Please install correctly to see what has changed \n for this version of LyX. " ) ;
2015-05-19 09:57:52 +02:00
} else {
QTextStream ts ( & file ) ;
ts . setCodec ( " UTF-8 " ) ;
QString line ;
bool incomment = false ;
bool inlist = false ;
do {
// a simple markdown parser
line = ts . readLine ( ) ;
// skipe empty lines
if ( line . isEmpty ( ) )
continue ;
// parse (:comments:)
if ( line . startsWith ( " (: " ) ) {
if ( ! line . endsWith ( " :) " ) )
incomment = true ;
continue ;
} if ( line . endsWith ( " :) " ) & & incomment ) {
incomment = false ;
continue ;
} if ( incomment )
continue ;
2015-05-24 14:51:47 +02:00
// detect links to the tracker
line . replace ( QRegExp ( " (bug )( \\ #)( \\ d+)* " ) ,
" <a href= \" http://www.lyx.org/trac/ticket/ \\ 3 \" > \\ 1 \\ 3</a> " ) ;
2015-05-19 09:57:52 +02:00
// headings
if ( line . startsWith ( " !!! " ) ) {
if ( inlist ) {
out < < " </li> " ;
out < < " </ul><br> " ;
inlist = false ;
}
out < < " <h4> " < < line . mid ( 3 ) < < " </h4> " ;
}
else if ( line . startsWith ( " !! " ) ) {
if ( inlist ) {
out < < " </li> " ;
out < < " </ul><br> " ;
inlist = false ;
}
out < < " <h3> " < < line . mid ( 2 ) < < " </h3> " ;
} else if ( line . startsWith ( " ! " ) ) {
if ( inlist ) {
out < < " </li> " ;
out < < " </ul><br> " ;
inlist = false ;
}
out < < " <h2> " < < line . mid ( 1 ) < < " </h2> " ;
// lists
} else if ( line . startsWith ( " * " ) ) {
if ( inlist )
out < < " </li> " ;
else
out < < " <ul> " ;
inlist = true ;
out < < " <li> " < < line . mid ( 2 ) ;
} else if ( inlist & & line . startsWith ( " " ) ) {
out < < line . mid ( 2 ) ;
} else if ( inlist ) {
inlist = false ;
out < < " </li> " ;
out < < " </ul><br> " ;
out < < line ;
} else
out < < line ;
out < < " " ;
} while ( ! line . isNull ( ) ) ;
}
}
out . flush ( ) ;
return res ;
}
2007-09-05 22:54:47 +00:00
static QString copyright ( )
{
2009-01-15 13:31:05 +00:00
QString release_year = release_date ( ) . toString ( " yyyy " ) ;
docstring copy_message =
bformat ( _ ( " LyX is Copyright (C) 1995 by Matthias Ettrich, \n 1995--%1$s LyX Team " ) ,
qstring_to_ucs4 ( release_year ) ) ;
return toqstr ( copy_message ) ;
2007-09-05 22:54:47 +00:00
}
2007-09-05 20:33:29 +00:00
2006-03-05 17:24:44 +00:00
2007-09-05 22:54:47 +00:00
static QString license ( )
{
2008-02-05 12:43:19 +00:00
return qt_ ( " This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. " ) ;
2007-09-05 22:54:47 +00:00
}
2006-03-05 17:24:44 +00:00
2007-09-05 22:54:47 +00:00
static QString disclaimer ( )
{
2008-02-05 12:43:19 +00:00
return qt_ ( " LyX is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. \n See the GNU General Public License for more details. \n You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. " ) ;
2007-09-05 22:54:47 +00:00
}
2006-03-05 17:24:44 +00:00
2020-08-12 14:24:40 -04:00
static QString buildinfo ( )
{
QString res ;
QTextStream out ( & res ) ;
out < < " LyX " < < lyx_version
2020-08-15 16:06:56 +02:00
< < " ( " < < lyx_release_date < < " ) "
# if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
< < Qt : : endl ;
# else
< < endl ;
# endif
2020-08-12 14:24:40 -04:00
if ( std : : string ( lyx_git_commit_hash ) ! = " none " )
out < < qt_ ( " Git commit hash " )
2020-08-15 16:06:56 +02:00
< < QString ( lyx_git_commit_hash ) . left ( 8 )
# if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
< < Qt : : endl ;
# else
< < endl ;
# endif
out < < lyx_version_info
# if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
< < Qt : : endl ;
# else
< < endl ;
# endif
2020-08-12 14:24:40 -04:00
return res ;
}
static QString dirLibrary ( )
{
return toqstr ( makeDisplayPath ( package ( ) . system_support ( ) . absFileName ( ) ) ) ;
}
static QString dirUser ( )
{
return toqstr ( makeDisplayPath ( package ( ) . user_support ( ) . absFileName ( ) ) ) ;
}
2007-09-05 22:54:47 +00:00
static QString version ( )
{
2009-03-18 23:17:33 +00:00
QString loc_release_date ;
QDate date = release_date ( ) ;
if ( date . isValid ( ) ) {
QLocale loc ;
loc_release_date = loc . toString ( date , QLocale : : LongFormat ) ;
} else {
2009-02-16 10:06:24 +00:00
if ( QString ( lyx_release_date ) = = " not released yet " )
2009-01-15 13:56:40 +00:00
loc_release_date = qt_ ( " not released yet " ) ;
else
loc_release_date = toqstr ( lyx_release_date ) ;
}
2009-01-15 13:31:05 +00:00
docstring version_date =
2020-08-16 11:31:56 +02:00
bformat ( _ ( " Version %1$s \n (%2$s) " ) ,
2009-01-15 13:31:05 +00:00
from_ascii ( lyx_version ) ,
2014-10-10 12:12:17 +02:00
qstring_to_ucs4 ( loc_release_date ) ) + " \n " ;
if ( std : : string ( lyx_git_commit_hash ) ! = " none " )
2020-08-15 16:07:12 +02:00
version_date + = from_ascii ( " </p><p> " ) + _ ( " Built from git commit hash " )
2014-10-10 12:12:17 +02:00
+ from_utf8 ( lyx_git_commit_hash ) . substr ( 0 , 8 ) ;
2007-09-05 22:54:47 +00:00
QString res ;
QTextStream out ( & res ) ;
2020-08-15 16:07:12 +02:00
out < < toqstr ( " <html><head/><body><p><span style= \" font-weight:600; \" > " ) ;
out < < toqstr ( version_date ) < < " </span></p><p> " ;
out < < toqstr ( bformat ( _ ( " Qt Version (run-time): %1$s " ) , from_ascii ( qVersion ( ) ) ) ) < < " </p><p> " ;
2020-08-12 14:24:40 -04:00
out < < toqstr ( bformat ( _ ( " Qt Version (compile-time): %1$s " ) , from_ascii ( QT_VERSION_STR ) ) ) ;
2020-08-15 16:07:12 +02:00
out < < toqstr ( " </p></body></html> " ) ;
2007-09-05 22:54:47 +00:00
return res ;
}
2006-03-05 17:24:44 +00:00
2020-08-12 14:24:40 -04:00
struct GuiAbout : : Private
2012-10-07 11:27:07 -04:00
{
2020-08-12 14:24:40 -04:00
Ui : : AboutUi ui ;
} ;
2012-10-07 11:27:07 -04:00
2020-08-12 14:24:40 -04:00
void GuiAbout : : on_showDirLibraryPB_clicked ( )
{
showDirectory ( package ( ) . system_support ( ) ) ;
2012-10-07 11:27:07 -04:00
}
2006-03-05 17:24:44 +00:00
2020-08-12 14:24:40 -04:00
void GuiAbout : : on_showDirUserPB_clicked ( )
2010-01-23 20:29:00 +00:00
{
2020-08-12 14:24:40 -04:00
showDirectory ( package ( ) . user_support ( ) ) ;
}
void GuiAbout : : on_versionCopyPB_clicked ( )
{
2020-08-13 08:12:56 +02:00
qApp - > clipboard ( ) - > setText ( version ( ) ) ;
2020-08-12 14:24:40 -04:00
}
2010-01-23 20:29:00 +00:00
2007-11-23 09:44:02 +00:00
GuiAbout : : GuiAbout ( GuiView & lv )
2010-01-23 20:29:00 +00:00
: DialogView ( lv , " aboutlyx " , qt_ ( " About LyX " ) ) ,
d ( new GuiAbout : : Private )
2007-09-05 22:54:47 +00:00
{
2010-01-23 20:29:00 +00:00
d - > ui . setupUi ( this ) ;
2006-03-05 17:24:44 +00:00
2010-01-23 20:29:00 +00:00
d - > ui . copyrightTB - > setPlainText ( copyright ( ) ) ;
d - > ui . copyrightTB - > append ( QString ( ) ) ;
d - > ui . copyrightTB - > append ( license ( ) ) ;
d - > ui . copyrightTB - > append ( QString ( ) ) ;
d - > ui . copyrightTB - > append ( disclaimer ( ) ) ;
d - > ui . versionLA - > setText ( version ( ) ) ;
2020-08-15 16:07:12 +02:00
QPixmap icon = getPixmap ( " images/ " , " lyx " , " svg,png " ) ;
int const iconsize = d - > ui . versionLA - > height ( ) * 1.5 ;
d - > ui . iconLA - > setPixmap ( icon . scaled ( iconsize , iconsize ,
Qt : : IgnoreAspectRatio ,
Qt : : SmoothTransformation ) ) ;
2020-08-12 14:24:40 -04:00
d - > ui . dirLibraryLA - > setText ( dirLibrary ( ) ) ;
d - > ui . dirUserLA - > setText ( dirUser ( ) ) ;
2012-10-07 11:27:07 -04:00
d - > ui . buildinfoTB - > setText ( buildinfo ( ) ) ;
2015-05-19 09:57:52 +02:00
d - > ui . releasenotesTB - > setHtml ( release_notes ( ) ) ;
2015-05-24 14:51:47 +02:00
d - > ui . releasenotesTB - > setOpenExternalLinks ( true ) ;
2010-01-23 20:29:00 +00:00
d - > ui . creditsTB - > setHtml ( credits ( ) ) ;
2015-05-19 15:08:59 +02:00
d - > ui . tab - > setUsesScrollButtons ( false ) ;
2020-08-15 16:07:12 +02:00
// fix height to minimum
setFixedHeight ( sizeHint ( ) . height ( ) ) ;
2010-01-23 20:29:00 +00:00
}
2007-09-05 20:33:29 +00:00
2018-07-08 16:35:38 +02:00
void GuiAbout : : on_buttonBox_rejected ( )
2010-01-23 20:29:00 +00:00
{
close ( ) ;
2006-03-05 17:24:44 +00:00
}
2007-10-06 09:55:21 +00:00
2007-11-23 09:44:02 +00:00
Dialog * createGuiAbout ( GuiView & lv ) { return new GuiAbout ( lv ) ; }
2007-10-06 09:55:21 +00:00
2006-03-05 17:24:44 +00:00
} // namespace frontend
} // namespace lyx
2007-04-24 11:32:09 +00:00
2008-11-14 14:28:50 +00:00
# include "moc_GuiAbout.cpp"