All: Reformat according to new standard

This commit is contained in:
pre-commit-ci[bot]
2025-11-11 13:49:01 +01:00
committed by Kacper Donat
parent eafd18dac0
commit 25c3ba7338
2390 changed files with 154630 additions and 115818 deletions

View File

@@ -21,13 +21,11 @@
***************************************************************************/
# include <QApplication>
# include <QDir>
# include <QFileInfo>
# include <QMessageBox>
# include <QTimer>
#include <QApplication>
#include <QDir>
#include <QFileInfo>
#include <QMessageBox>
#include <QTimer>
#include <FCConfig.h>
@@ -45,7 +43,8 @@
using namespace Gui;
using namespace Gui::Dialog;
namespace Gui {
namespace Gui
{
struct NetworkRetrieverP
{
@@ -70,12 +69,12 @@ struct NetworkRetrieverP
bool fail;
};
} // namespace Gui
} // namespace Gui
/* TRANSLATOR Gui::NetworkRetriever */
NetworkRetriever::NetworkRetriever( QObject * parent )
: QObject( parent )
NetworkRetriever::NetworkRetriever(QObject* parent)
: QObject(parent)
{
d = new NetworkRetrieverP;
d->tries = 3;
@@ -91,8 +90,12 @@ NetworkRetriever::NetworkRetriever( QObject * parent )
wget = new QProcess(this);
// if wgets exits emit signal
connect(wget, qOverload<int, QProcess::ExitStatus>(&QProcess::finished),
this, &NetworkRetriever::wgetFinished);
connect(
wget,
qOverload<int, QProcess::ExitStatus>(&QProcess::finished),
this,
&NetworkRetriever::wgetFinished
);
// if application quits kill wget immediately to avoid dangling processes
connect(qApp, &QApplication::lastWindowClosed, wget, &QProcess::kill);
@@ -105,18 +108,17 @@ NetworkRetriever::~NetworkRetriever()
}
/**
* This method is connected to QTimer::singleShot() and executed after 5 seconds. If wget then is still running
* we can assume that everything is fine.
* \note This test is necessary since \a wget writes all its output on stderr and we cannot determine surely
* if an error occurred or not.
* This method is connected to QTimer::singleShot() and executed after 5 seconds. If wget then is
* still running we can assume that everything is fine.
* \note This test is necessary since \a wget writes all its output on stderr and we cannot
* determine surely if an error occurred or not.
*
* There is still a problem that is not solved so far. If wget requires the proxy settings and if these
* are not set, wget could take more than 5 seconds without downloading anything.
* There is still a problem that is not solved so far. If wget requires the proxy settings and if
* these are not set, wget could take more than 5 seconds without downloading anything.
*/
void NetworkRetriever::testFailure()
{
if ( wget->state() == QProcess::Running )
{
if (wget->state() == QProcess::Running) {
d->fail = false;
QString msg = tr("Download started…");
Base::Console().message("%s\n", msg.toUtf8().constData());
@@ -127,7 +129,7 @@ void NetworkRetriever::testFailure()
* Sets the number of retries to \a tries. If \a tries is 0 the number of tries
* is unlimited. The default value of the tries property is set to 3.
*/
void NetworkRetriever::setNumberOfTries( int tries )
void NetworkRetriever::setNumberOfTries(int tries)
{
d->tries = tries;
}
@@ -135,7 +137,7 @@ void NetworkRetriever::setNumberOfTries( int tries )
/**
* Sets output file to \a out where documents are written to.
*/
void NetworkRetriever::setOutputFile( const QString& out )
void NetworkRetriever::setOutputFile(const QString& out)
{
d->outputFile = out;
}
@@ -155,7 +157,7 @@ void NetworkRetriever::setEnableTimestamp(bool ts)
* Moreover, if the proxy requires user authentication then you can specify the username
* with \a user and the password with \a passwd.
*/
void NetworkRetriever::setProxy( const QString& proxy, const QString& user, const QString& passwd )
void NetworkRetriever::setProxy(const QString& proxy, const QString& user, const QString& passwd)
{
d->proxy = proxy;
d->user = user;
@@ -169,7 +171,7 @@ void NetworkRetriever::setProxy( const QString& proxy, const QString& user, cons
* property is 1.
* \note: Use this with care!
*/
void NetworkRetriever::setEnableRecursive( bool recursive, int level )
void NetworkRetriever::setEnableRecursive(bool recursive, int level)
{
d->recurse = recursive;
d->level = level;
@@ -179,7 +181,7 @@ void NetworkRetriever::setEnableRecursive( bool recursive, int level )
* If \a folRel is true wget follows relative links only. As default
* the follows relative property is false.
*/
void NetworkRetriever::setFollowRelative( bool folRel )
void NetworkRetriever::setFollowRelative(bool folRel)
{
d->folRel = folRel;
}
@@ -188,7 +190,7 @@ void NetworkRetriever::setFollowRelative( bool folRel )
* If \a convert is true all non-relative links are converted to
* relative links. As default the convert property is true.
*/
void NetworkRetriever::setEnableConvert( bool convert )
void NetworkRetriever::setEnableConvert(bool convert)
{
d->convert = convert;
}
@@ -197,7 +199,7 @@ void NetworkRetriever::setEnableConvert( bool convert )
* If \a img is true wget tries to get all needed image files
* to display the HTML page. As default this behaviour is disabled..
*/
void NetworkRetriever::setFetchImages( bool img )
void NetworkRetriever::setFetchImages(bool img)
{
d->img = img;
}
@@ -206,7 +208,7 @@ void NetworkRetriever::setFetchImages( bool img )
* Saves all text/html documents with .html extionsion if \a html is true.
* As default the html property is false.
*/
void NetworkRetriever::setEnableHTMLExtension( bool html )
void NetworkRetriever::setEnableHTMLExtension(bool html)
{
d->html = html;
}
@@ -214,7 +216,7 @@ void NetworkRetriever::setEnableHTMLExtension( bool html )
/**
* Do not ever ascend to the parent directory when retrieving recursively.
*/
void NetworkRetriever::setNoParent( bool nop )
void NetworkRetriever::setNoParent(bool nop)
{
d->nop = nop;
}
@@ -222,7 +224,7 @@ void NetworkRetriever::setNoParent( bool nop )
/**
* Sets the output directory to \a dir where all downloaded are written into.
*/
void NetworkRetriever::setOutputDirectory( const QString& dir )
void NetworkRetriever::setOutputDirectory(const QString& dir)
{
d->dir = dir;
}
@@ -230,23 +232,22 @@ void NetworkRetriever::setOutputDirectory( const QString& dir )
/**
* wget starts to download \a startUrl and all referenced pages.
*/
bool NetworkRetriever::startDownload( const QString& startUrl )
bool NetworkRetriever::startDownload(const QString& startUrl)
{
if ( !testWget() )
if (!testWget()) {
return false;
}
d->startUrl = startUrl;
// proxy as environment variable
if ( !d->proxy.isEmpty() )
{
if (!d->proxy.isEmpty()) {
QStringList env = wget->environment();
env << QStringLiteral("http_proxy=%1").arg(d->proxy);
env << QStringLiteral("ftp_proxy=%1").arg(d->proxy);
wget->setEnvironment(env);
}
else
{
else {
QStringList env = wget->environment();
env.removeAll(QStringLiteral("http_proxy=%1").arg(d->proxy));
env.removeAll(QStringLiteral("ftp_proxy=%1").arg(d->proxy));
@@ -258,77 +259,79 @@ bool NetworkRetriever::startDownload( const QString& startUrl )
// since the wget option '--directory-prefix' seems not to work as expected
// and QProcess::setWorkingDirectory() fails if the 'doc' directory doesn't
// exist we must check for this and create it if needed.
if ( !d->dir.isEmpty() )
{
if (!d->dir.isEmpty()) {
QDir dir(d->dir);
if (!dir.exists(d->dir))
{
if (!dir.mkdir(d->dir))
{
Base::Console().error("Directory '%s' could not be created.", (const char*)d->dir.toLatin1());
return true; // please, no error message
if (!dir.exists(d->dir)) {
if (!dir.mkdir(d->dir)) {
Base::Console().error(
"Directory '%s' could not be created.",
(const char*)d->dir.toLatin1()
);
return true; // please, no error message
}
}
wget->setWorkingDirectory( dir.path() );
wget->setWorkingDirectory(dir.path());
}
// user authentication
if ( !d->proxy.isEmpty() )
{
if ( !d->user.isEmpty() )
{
wgetArguments << QStringLiteral("--proxy-user=%1").arg( d->user );
if ( !d->passwd.isEmpty() )
{
wgetArguments << QStringLiteral("--proxy-passwd=%1").arg( d->passwd );
if (!d->proxy.isEmpty()) {
if (!d->user.isEmpty()) {
wgetArguments << QStringLiteral("--proxy-user=%1").arg(d->user);
if (!d->passwd.isEmpty()) {
wgetArguments << QStringLiteral("--proxy-passwd=%1").arg(d->passwd);
}
}
}
// output file
if ( !d->outputFile.isEmpty() )
wgetArguments << QStringLiteral("--output-document=%1").arg( d->outputFile );
if (!d->outputFile.isEmpty()) {
wgetArguments << QStringLiteral("--output-document=%1").arg(d->outputFile);
}
// timestamping enabled -> update newer files only
if ( d->timeStamp )
if (d->timeStamp) {
wgetArguments << QStringLiteral("-N");
}
// get all needed image files
if ( d->img )
if (d->img) {
wgetArguments << QStringLiteral("-p");
}
// follow relative links only
if ( d->folRel )
wgetArguments<< QStringLiteral("-L");
if ( d->recurse )
{
if (d->folRel) {
wgetArguments << QStringLiteral("-L");
}
if (d->recurse) {
wgetArguments << QStringLiteral("-r");
wgetArguments << QStringLiteral("--level=%1").arg( d->level );
wgetArguments << QStringLiteral("--level=%1").arg(d->level);
}
if ( d->nop )
if (d->nop) {
wgetArguments << QStringLiteral("-np");
}
// convert absolute links in to relative
if ( d->convert )
if (d->convert) {
wgetArguments << QStringLiteral("-k");
}
// number of tries
wgetArguments << QStringLiteral("--tries=%1").arg( d->tries );
wgetArguments << QStringLiteral("--tries=%1").arg(d->tries);
// use HTML file extension
if ( d->html )
if (d->html) {
wgetArguments << QStringLiteral("-E");
}
// start URL
wgetArguments << startUrl;
#ifdef FC_OS_LINUX
// on Linux it seems that we have to change cwd
QString cwd = QDir::currentPath ();
if ( !d->dir.isEmpty() )
{
QString cwd = QDir::currentPath();
if (!d->dir.isEmpty()) {
QDir::setCurrent(d->dir);
}
wget->start(QStringLiteral("wget"), wgetArguments);
QDir::setCurrent( cwd );
QDir::setCurrent(cwd);
#else
wget->start(QStringLiteral("wget"), wgetArguments);
#endif
@@ -349,9 +352,8 @@ bool NetworkRetriever::isDownloading() const
*/
void NetworkRetriever::abort()
{
if ( wget->state() == QProcess::Running)
{
QTimer::singleShot( 2000, wget, &QProcess::kill);
if (wget->state() == QProcess::Running) {
QTimer::singleShot(2000, wget, &QProcess::kill);
}
}
@@ -384,27 +386,28 @@ bool NetworkRetriever::testWget()
// --------------------------------------------------------------------
StdCmdDownloadOnlineHelp::StdCmdDownloadOnlineHelp( QObject * parent)
: QObject(parent), Command("Std_DownloadOnlineHelp")
StdCmdDownloadOnlineHelp::StdCmdDownloadOnlineHelp(QObject* parent)
: QObject(parent)
, Command("Std_DownloadOnlineHelp")
{
sGroup ="Help";
sMenuText = QT_TR_NOOP("Download Online Help");
sToolTipText = QT_TR_NOOP("Downloads %1's online help");
sWhatsThis = "Std_DownloadOnlineHelp";
sStatusTip = sToolTipText;
sPixmap = "help";
sGroup = "Help";
sMenuText = QT_TR_NOOP("Download Online Help");
sToolTipText = QT_TR_NOOP("Downloads %1's online help");
sWhatsThis = "Std_DownloadOnlineHelp";
sStatusTip = sToolTipText;
sPixmap = "help";
wget = new NetworkRetriever( this );
wget = new NetworkRetriever(this);
// downloading recursively and depth 5
wget->setEnableRecursive( true, 5 );
wget->setNumberOfTries( 3 );
wget->setEnableHTMLExtension( true );
wget->setEnableConvert( true );
wget->setEnableRecursive(true, 5);
wget->setNumberOfTries(3);
wget->setEnableHTMLExtension(true);
wget->setEnableConvert(true);
wget->setEnableTimestamp( true );
wget->setFetchImages( true );
wget->setFollowRelative( false );
wget->setNoParent( true );
wget->setEnableTimestamp(true);
wget->setFetchImages(true);
wget->setFollowRelative(false);
wget->setNoParent(true);
connect(wget, &NetworkRetriever::wgetExited, this, &StdCmdDownloadOnlineHelp::wgetFinished);
}
@@ -414,20 +417,16 @@ StdCmdDownloadOnlineHelp::~StdCmdDownloadOnlineHelp()
delete wget;
}
Action * StdCmdDownloadOnlineHelp::createAction()
Action* StdCmdDownloadOnlineHelp::createAction()
{
Action *pcAction;
Action* pcAction;
QString exe = QString::fromStdString(App::Application::getExecutableName());
pcAction = new Action(this,getMainWindow());
pcAction->setText(QCoreApplication::translate(
this->className(), getMenuText()));
pcAction->setToolTip(QCoreApplication::translate(
this->className(), getToolTipText()).arg(exe));
pcAction->setStatusTip(QCoreApplication::translate(
this->className(), getStatusTip()).arg(exe));
pcAction->setWhatsThis(QCoreApplication::translate(
this->className(), getWhatsThis()).arg(exe));
pcAction = new Action(this, getMainWindow());
pcAction->setText(QCoreApplication::translate(this->className(), getMenuText()));
pcAction->setToolTip(QCoreApplication::translate(this->className(), getToolTipText()).arg(exe));
pcAction->setStatusTip(QCoreApplication::translate(this->className(), getStatusTip()).arg(exe));
pcAction->setWhatsThis(QCoreApplication::translate(this->className(), getWhatsThis()).arg(exe));
pcAction->setIcon(Gui::BitmapFactory().pixmap(getPixmap()));
pcAction->setShortcut(QString::fromLatin1(getAccel()));
@@ -438,14 +437,16 @@ void StdCmdDownloadOnlineHelp::languageChange()
{
if (_pcAction) {
QString exe = QString::fromStdString(App::Application::getExecutableName());
_pcAction->setText(QCoreApplication::translate(
this->className(), getMenuText()));
_pcAction->setToolTip(QCoreApplication::translate(
this->className(), getToolTipText()).arg(exe));
_pcAction->setStatusTip(QCoreApplication::translate(
this->className(), getStatusTip()).arg(exe));
_pcAction->setWhatsThis(QCoreApplication::translate(
this->className(), getWhatsThis()).arg(exe));
_pcAction->setText(QCoreApplication::translate(this->className(), getMenuText()));
_pcAction->setToolTip(
QCoreApplication::translate(this->className(), getToolTipText()).arg(exe)
);
_pcAction->setStatusTip(
QCoreApplication::translate(this->className(), getStatusTip()).arg(exe)
);
_pcAction->setWhatsThis(
QCoreApplication::translate(this->className(), getWhatsThis()).arg(exe)
);
}
}
@@ -457,8 +458,8 @@ void StdCmdDownloadOnlineHelp::activated(int iMsg)
hGrp = hGrp->GetGroup("Preferences")->GetGroup("OnlineHelp");
std::string url = hGrp->GetASCII("DownloadURL", "www.freecad.org/wiki/");
std::string prx = hGrp->GetASCII("ProxyText", "");
bool bUseProxy = hGrp->GetBool ("UseProxy", false);
bool bAuthor = hGrp->GetBool ("Authorize", false);
bool bUseProxy = hGrp->GetBool("UseProxy", false);
bool bAuthor = hGrp->GetBool("Authorize", false);
if (bUseProxy) {
QString username;
@@ -479,54 +480,63 @@ void StdCmdDownloadOnlineHelp::activated(int iMsg)
wget->setProxy(QString::fromLatin1(prx.c_str()), username, password);
}
int loop=3;
int loop = 3;
bool canStart = false;
// set output directory
QString path = QString::fromStdString(App::Application::getHomePath());
path += QStringLiteral("/doc/");
ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/OnlineHelp");
path = QString::fromUtf8(hURLGrp->GetASCII( "DownloadLocation", path.toLatin1() ).c_str());
ParameterGrp::handle hURLGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/OnlineHelp"
);
path = QString::fromUtf8(hURLGrp->GetASCII("DownloadLocation", path.toLatin1()).c_str());
while (loop > 0) {
loop--;
QFileInfo fi( path);
QFileInfo fi(path);
if (!fi.exists()) {
if (QMessageBox::critical(getMainWindow(), tr("Non-existing directory"),
tr("The directory '%1' does not exist.\n\n"
"Specify an existing directory?").arg(fi.filePath()),
QMessageBox::Yes | QMessageBox::No) !=
QMessageBox::Yes)
{
// exit the command
return;
}
else
{
path = FileDialog::getExistingDirectory();
if ( path.isEmpty() )
return;
}
}
if (!fi.permission( QFile::WriteUser)) {
if (QMessageBox::critical(getMainWindow(), tr("Missing permission"),
tr("You don't have write permission to '%1'\n\n"
"Specify another directory?").arg(fi.filePath()),
QMessageBox::Yes | QMessageBox::No) !=
QMessageBox::Yes)
{
if (QMessageBox::critical(
getMainWindow(),
tr("Non-existing directory"),
tr("The directory '%1' does not exist.\n\n"
"Specify an existing directory?")
.arg(fi.filePath()),
QMessageBox::Yes | QMessageBox::No
)
!= QMessageBox::Yes) {
// exit the command
return;
}
else {
path = FileDialog::getExistingDirectory();
if ( path.isEmpty() )
if (path.isEmpty()) {
return;
}
}
}
if (!fi.permission(QFile::WriteUser)) {
if (QMessageBox::critical(
getMainWindow(),
tr("Missing permission"),
tr("You don't have write permission to '%1'\n\n"
"Specify another directory?")
.arg(fi.filePath()),
QMessageBox::Yes | QMessageBox::No
)
!= QMessageBox::Yes) {
// exit the command
return;
}
else {
path = FileDialog::getExistingDirectory();
if (path.isEmpty()) {
return;
}
}
}
else {
wget->setOutputDirectory( path );
wget->setOutputDirectory(path);
canStart = true;
break;
}
@@ -534,13 +544,15 @@ void StdCmdDownloadOnlineHelp::activated(int iMsg)
if (canStart) {
bool ok = wget->startDownload(QString::fromLatin1(url.c_str()));
if (!ok)
if (!ok) {
Base::Console().error("The tool 'wget' could not be found. Check the installation.");
else if ( wget->isDownloading() && _pcAction )
}
else if (wget->isDownloading() && _pcAction) {
_pcAction->setText(tr("Stop downloading"));
}
}
}
else // kill the process now
else // kill the process now
{
wget->abort();
}
@@ -548,10 +560,9 @@ void StdCmdDownloadOnlineHelp::activated(int iMsg)
void StdCmdDownloadOnlineHelp::wgetFinished()
{
if (_pcAction)
_pcAction->setText(QCoreApplication::translate(
this->className(), getMenuText()));
if (_pcAction) {
_pcAction->setText(QCoreApplication::translate(this->className(), getMenuText()));
}
}
#include "moc_NetworkRetriever.cpp"