Qt4/Qt5 neutral changes:

+ remove class DownloadDialog
+ remove class HelpView
+ remove class DlgTipOfTheDay
This commit is contained in:
wmayer 2016-12-12 14:35:52 +01:00
parent 1cdee20953
commit 57e7d3ad61
12 changed files with 1 additions and 2668 deletions

View File

@ -163,7 +163,6 @@ set(Gui_MOC_HDRS
Control.h
Clipping.h
DemoMode.h
DownloadDialog.h
DownloadItem.h
DownloadManager.h
DlgActionsImp.h
@ -197,7 +196,6 @@ set(Gui_MOC_HDRS
DlgSettingsImageImp.h
DlgSettingsMacroImp.h
DlgSettingsUnitsImp.h
DlgTipOfTheDayImp.h
DlgCheckableMessageBox.h
DlgToolbarsImp.h
DlgWorkbenchesImp.h
@ -216,7 +214,6 @@ set(Gui_MOC_HDRS
GraphvizView.h
GuiApplication.h
GuiApplicationNativeEventAware.h
HelpView.h
InputVector.h
MainWindow.h
ManualAlignment.h
@ -309,7 +306,6 @@ SET(Gui_UIC_SRCS
DlgSettingsImage.ui
DlgSettingsMacro.ui
DlgCheckableMessageBox.ui
DlgTipOfTheDay.ui
DlgToolbars.ui
DlgWorkbenches.ui
DlgTreeWidget.ui
@ -377,7 +373,6 @@ SET(Dialog_CPP_SRCS
DlgProjectInformationImp.cpp
DlgProjectUtility.cpp
DlgPropertyLink.cpp
DlgTipOfTheDayImp.cpp
DlgExpressionInput.cpp
TaskDlgRelocation.cpp
DlgCheckableMessageBox.cpp
@ -389,7 +384,6 @@ SET(Dialog_CPP_SRCS
SceneInspector.cpp
TextureMapping.cpp
Transform.cpp
DownloadDialog.cpp
DownloadItem.cpp
DownloadManager.cpp
DocumentRecovery.cpp
@ -412,7 +406,6 @@ SET(Dialog_HPP_SRCS
DlgProjectUtility.h
DlgPropertyLink.h
DlgCheckableMessageBox.h
DlgTipOfTheDayImp.h
DlgExpressionInput.h
TaskDlgRelocation.h
TaskCSysDragger.h
@ -423,7 +416,6 @@ SET(Dialog_HPP_SRCS
SceneInspector.h
TextureMapping.h
Transform.h
DownloadDialog.h
DownloadItem.h
DownloadManager.h
DocumentRecovery.h
@ -450,7 +442,6 @@ SET(Dialog_SRCS
DlgProjectInformation.ui
DlgProjectUtility.ui
DlgPropertyLink.ui
DlgTipOfTheDay.ui
DlgCheckableMessageBox.ui
DlgTreeWidget.ui
DlgExpressionInput.ui
@ -552,7 +543,6 @@ SOURCE_GROUP("Dialog\\Settings" FILES ${Dialog_Settings_SRCS})
SET(Dock_Windows_CPP_SRCS
CombiView.cpp
DockWindow.cpp
HelpView.cpp
PropertyView.cpp
ReportView.cpp
SelectionView.cpp
@ -569,7 +559,6 @@ SET(Dock_Windows_CPP_SRCS
SET(Dock_Windows_HPP_SRCS
CombiView.h
DockWindow.h
HelpView.h
PropertyView.h
ReportView.h
SelectionView.h

View File

@ -39,7 +39,6 @@
#include "Application.h"
#include "Document.h"
#include "Selection.h"
#include "HelpView.h"
#include "Macro.h"
#include "MainWindow.h"
#include "DlgUndoRedo.h"

File diff suppressed because it is too large Load Diff

View File

@ -1,153 +0,0 @@
/***************************************************************************
* Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library 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. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
# include <qcheckbox.h>
# include <qfile.h>
# include <qlabel.h>
# include <qlayout.h>
# include <qtextstream.h>
# include <QHttp>
#endif
#include "DlgTipOfTheDayImp.h"
#include "Application.h"
#include "MainWindow.h"
#include <Base/Parameter.h>
#include <Base/Console.h>
using namespace Gui::Dialog;
/* TRANSLATOR Gui::Dialog::DlgTipOfTheDayImp */
/**
* Constructs a DlgTipOfTheDayImp which is a child of 'parent', with the
* name 'name' and widget flags set to 'f'
*
* The dialog will by default be modeless, unless you set 'modal' to
* true to construct a modal dialog.
*/
DlgTipOfTheDayImp::DlgTipOfTheDayImp( QWidget* parent, Qt::WindowFlags fl )
: QDialog( parent, fl | Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
WindowParameter("General")
{
setupUi(this);
_http = new QHttp;
connect(_http, SIGNAL(done(bool)), this, SLOT(onDone(bool)));
connect(_http, SIGNAL(stateChanged(int)), this, SLOT(onStateChanged(int)));
connect(_http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),
this, SLOT(onResponseHeaderReceived(const QHttpResponseHeader &)));
bool tips = getWindowParameter()->GetBool("Tipoftheday", true);
checkShowTips->setChecked(tips);
// Since the resize mode of DlgTipOfTheDayBase does not
// work properly so set this by hand
setMinimumSize(QSize(320, 250));
layout()->setSizeConstraint( QLayout::SetNoConstraint );
reload();
on_buttonNextTip_clicked();
}
/** Destroys the object and frees any allocated resources */
DlgTipOfTheDayImp::~DlgTipOfTheDayImp()
{
delete _http;
getWindowParameter()->SetBool("Tipoftheday", checkShowTips->isChecked());
}
/** Shows next tip taken from the Tip-of-the-day site. */
void DlgTipOfTheDayImp::on_buttonNextTip_clicked()
{
_iCurrentTip = (_iCurrentTip + 1) % _lTips.size();
textTip->setText(_lTips[_iCurrentTip]);
}
/** Reloads all tips from Tip-of-the-day site. */
void DlgTipOfTheDayImp::reload()
{
// set the host and start the download
_http->setHost(QLatin1String("www.freecadweb.org"));
_http->get(QLatin1String("/wiki/index.php?title=Tip_of_the_day"), 0);
_iCurrentTip = 0;
_lTips << tr("If you want to learn more about FreeCAD you must go to %1 or press the Help item in the Help menu.")
.arg(QLatin1String("<a href=\"http://www.freecadweb.org/wiki/\">"
"http://www.freecadweb.org/wiki/</a>"));
}
void DlgTipOfTheDayImp::onResponseHeaderReceived(const QHttpResponseHeader & responseHeader)
{
if (responseHeader.statusCode() != 200) {
QString msg = tr("Download failed: %1\n").arg(responseHeader.reasonPhrase());
Base::Console().Log(msg.toLatin1());
_http->abort();
}
}
void DlgTipOfTheDayImp::onDone(bool err)
{
if (err)
return;
// get the page and search for the tips section
QString text = QString::fromLatin1(_http->readAll());
QRegExp rx(QLatin1String("<p>You find the latest information.+<div class=\"printfooter\">"));
if (rx.indexIn(text) > -1) {
// the text of interest
text = rx.cap();
rx.setPattern(QLatin1String("<ul><li>.+</li></ul>\n"));
rx.setMinimal(true);
_lTips += text.split(rx, QString::SkipEmptyParts);
}
}
/**
* Prints some status information.
*/
void DlgTipOfTheDayImp::onStateChanged (int state)
{
switch (state) {
case QHttp::Connecting:
Base::Console().Log("Connecting to host...\n");
break;
case QHttp::Sending:
Base::Console().Log("Sending to host...\n");
break;
case QHttp::Reading:
Base::Console().Log("Reading from host...\n");
break;
case QHttp::Closing:
case QHttp::Unconnected:
Base::Console().Log("%s\n",(const char*)_http->errorString().toLatin1());
break;
default:
break;
}
}
#include "moc_DlgTipOfTheDayImp.cpp"

View File

@ -1,80 +0,0 @@
/***************************************************************************
* Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library 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. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef GUI_DIALOG_DLGTIPOFTHEDAY_IMP_H
#define GUI_DIALOG_DLGTIPOFTHEDAY_IMP_H
#include "ui_DlgTipOfTheDay.h"
#include "Window.h"
class QHttpResponseHeader;
class QHttp;
namespace Gui {
namespace Dialog {
/** Implementation of the well-known Tip-of-the-day dialog.
*
* All the tips are read from the Tip-of-the-day site located in the documentation
* directory of this installation.
*
* To download the latest online documentation you just have to press
* "Download online help" in the help menu. If you cannot compile these sources it is
* also possible to use the program \a wget specifying the options -r, -k, -E and the
* URL of the homepage of FreeCAD.
*
* For more details have a look at the FreeCAD homepage (http://www.freecadweb.org/wiki/).
*
* You can simply append a new tip by clicking the "EditText" hyperlink
* and writing a text, e.g: "** this is a new tip"
*
* \author Werner Mayer
*/
class DlgTipOfTheDayImp : public QDialog, public Ui_DlgTipOfTheDay, public WindowParameter
{
Q_OBJECT
public:
DlgTipOfTheDayImp( QWidget* parent = 0, Qt::WindowFlags fl = 0 );
~DlgTipOfTheDayImp();
void reload();
public Q_SLOTS:
void on_buttonNextTip_clicked();
protected Q_SLOTS:
void onDone(bool);
void onStateChanged (int state);
void onResponseHeaderReceived(const QHttpResponseHeader &);
private:
QStringList _lTips;
int _iCurrentTip;
QHttp* _http;
};
} // namespace Dialog
} // namespace Gui
#endif // GUI_DIALOG_DLGTIPOFTHEDAY_IMP_H

View File

@ -1,220 +0,0 @@
/***************************************************************************
* Copyright (c) 2002 Jürgen Riegel <juergen.riegel@web.de> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library 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. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QPushButton>
# include <QHBoxLayout>
#endif
#include <QAuthenticator>
#include "DownloadDialog.h"
#include "ui_DlgAuthorization.h"
using namespace Gui::Dialog;
DownloadDialog::DownloadDialog(const QUrl& url, QWidget *parent)
: QDialog(parent), url(url), file(0), httpGetId(0), httpRequestAborted(false)
{
statusLabel = new QLabel(url.toString());
progressBar = new QProgressBar(this);
downloadButton = new QPushButton(tr("Download"));
downloadButton->setDefault(true);
cancelButton = new QPushButton(tr("Cancel"));
closeButton = new QPushButton(tr("Close"));
closeButton->setAutoDefault(false);
buttonBox = new QDialogButtonBox;
buttonBox->addButton(downloadButton, QDialogButtonBox::ActionRole);
buttonBox->addButton(closeButton, QDialogButtonBox::RejectRole);
buttonBox->addButton(cancelButton, QDialogButtonBox::RejectRole);
cancelButton->hide();
http = new QHttp(this);
connect(http, SIGNAL(requestFinished(int, bool)),
this, SLOT(httpRequestFinished(int, bool)));
connect(http, SIGNAL(dataReadProgress(int, int)),
this, SLOT(updateDataReadProgress(int, int)));
connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),
this, SLOT(readResponseHeader(const QHttpResponseHeader &)));
connect(http, SIGNAL(authenticationRequired(const QString &, quint16, QAuthenticator *)),
this, SLOT(slotAuthenticationRequired(const QString &, quint16, QAuthenticator *)));
connect(downloadButton, SIGNAL(clicked()), this, SLOT(downloadFile()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelDownload()));
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
QHBoxLayout *topLayout = new QHBoxLayout;
topLayout->addWidget(statusLabel);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(topLayout);
mainLayout->addWidget(progressBar);
mainLayout->addWidget(buttonBox);
setLayout(mainLayout);
setWindowTitle(tr("Download"));
}
DownloadDialog::~DownloadDialog()
{
}
void DownloadDialog::downloadFile()
{
QFileInfo fileInfo(url.path());
QString fileName = fileInfo.fileName();
if (QFile::exists(fileName)) {
if (QMessageBox::question(this, tr("Download"),
tr("There already exists a file called %1 in "
"the current directory. Overwrite?").arg(fileName),
QMessageBox::Yes|QMessageBox::No, QMessageBox::No) == QMessageBox::No)
return;
QFile::remove(fileName);
}
file = new QFile(fileName);
if (!file->open(QIODevice::WriteOnly)) {
QMessageBox::information(this, tr("Download"),
tr("Unable to save the file %1: %2.")
.arg(fileName).arg(file->errorString()));
delete file;
file = 0;
return;
}
QHttp::ConnectionMode mode = url.scheme().toLower() == QLatin1String("https")
? QHttp::ConnectionModeHttps : QHttp::ConnectionModeHttp;
http->setHost(url.host(), mode, url.port() == -1 ? 80 : url.port());
if (!url.userName().isEmpty())
http->setUser(url.userName(), url.password());
httpRequestAborted = false;
QByteArray path = QUrl::toPercentEncoding(url.path(), "!$&'()*+,;=:@/");
if (path.isEmpty())
path = "/";
httpGetId = http->get(QString::fromLatin1(path), file);
statusLabel->setText(tr("Downloading %1.").arg(fileName));
downloadButton->setEnabled(false);
cancelButton->show();
closeButton->hide();
}
void DownloadDialog::cancelDownload()
{
statusLabel->setText(tr("Download canceled."));
httpRequestAborted = true;
http->abort();
close();
}
void DownloadDialog::httpRequestFinished(int requestId, bool error)
{
if (requestId != httpGetId)
return;
if (httpRequestAborted) {
if (file) {
file->close();
file->remove();
delete file;
file = 0;
}
progressBar->hide();
return;
}
if (requestId != httpGetId)
return;
progressBar->hide();
file->close();
if (error) {
file->remove();
QMessageBox::information(this, tr("Download"),
tr("Download failed: %1.")
.arg(http->errorString()));
}
else {
QString fileName = QFileInfo(url.path()).fileName();
statusLabel->setText(tr("Downloaded %1 to current directory.").arg(fileName));
}
downloadButton->setEnabled(true);
cancelButton->hide();
closeButton->show();
delete file;
file = 0;
}
void DownloadDialog::readResponseHeader(const QHttpResponseHeader &responseHeader)
{
switch (responseHeader.statusCode()) {
case 200: // Ok
case 301: // Moved Permanently
case 302: // Found
case 303: // See Other
case 307: // Temporary Redirect
// these are not error conditions
break;
default:
QMessageBox::information(this, tr("Download"),
tr("Download failed: %1.")
.arg(responseHeader.reasonPhrase()));
httpRequestAborted = true;
progressBar->hide();
http->abort();
}
}
void DownloadDialog::updateDataReadProgress(int bytesRead, int totalBytes)
{
if (httpRequestAborted)
return;
progressBar->setMaximum(totalBytes);
progressBar->setValue(bytesRead);
}
void DownloadDialog::slotAuthenticationRequired(const QString &hostName, quint16, QAuthenticator *authenticator)
{
QDialog dlg;
Ui_DlgAuthorization ui;
ui.setupUi(&dlg);
dlg.adjustSize();
ui.siteDescription->setText(tr("%1 at %2").arg(authenticator->realm()).arg(hostName));
if (dlg.exec() == QDialog::Accepted) {
authenticator->setUser(ui.username->text());
authenticator->setPassword(ui.password->text());
}
}
#include "moc_DownloadDialog.cpp"

View File

@ -1,84 +0,0 @@
/***************************************************************************
* Copyright (c) 2011 Jürgen Riegel <juergen.riegel@web.de> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library 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. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef GUI_DOWNLOADDIALOG_H
#define GUI_DOWNLOADDIALOG_H
#include <QtCore>
#include <QDialog>
#include <QUrl>
#include <QMessageBox>
#include <QBuffer>
#include <QLabel>
#include <QProgressBar>
#include <QHttp>
#include <QFileInfo>
#include <QCloseEvent>
#include <QDialogButtonBox>
class QFile;
class QHttpResponseHeader;
class QAuthenticator;
namespace Gui {
namespace Dialog {
/** Download a resource (file) from the web to a location on the disk
*
*/
class GuiExport DownloadDialog : public QDialog
{
Q_OBJECT
public:
DownloadDialog(const QUrl& url, QWidget *parent = 0);
~DownloadDialog();
private Q_SLOTS:
void downloadFile();
void cancelDownload();
void httpRequestFinished(int requestId, bool error);
void readResponseHeader(const QHttpResponseHeader &responseHeader);
void updateDataReadProgress(int bytesRead, int totalBytes);
void slotAuthenticationRequired(const QString &, quint16, QAuthenticator *);
private:
QLabel *statusLabel;
QProgressBar *progressBar;
QPushButton *downloadButton;
QPushButton *closeButton;
QPushButton *cancelButton;
QDialogButtonBox *buttonBox;
QUrl url;
QHttp *http;
QFile *file;
int httpGetId;
bool httpRequestAborted;
};
} // namespace Dialog
} // namespace Gui
#endif // GUI_DOWNLOADDIALOG_H

View File

@ -1,697 +0,0 @@
/***************************************************************************
* Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library 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. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QApplication>
# include <QContextMenuEvent>
# include <QDropEvent>
# include <QGroupBox>
# include <QHBoxLayout>
# include <QHttp>
# include <QLabel>
# include <QMenu>
# include <QMessageBox>
# include <QMimeData>
# include <QProcess>
# include <QTimerEvent>
# include <QToolButton>
# include <QToolTip>
# include <QWhatsThis>
#endif
#include "HelpView.h"
#include "Application.h"
#include "BitmapFactory.h"
#include "FileDialog.h"
#include "WhatsThis.h"
#include "Action.h"
#include "Command.h"
using namespace Gui;
using namespace Gui::DockWnd;
namespace Gui {
namespace DockWnd {
struct TextBrowserResources
{
QUrl url;
int type;
};
class TextBrowserPrivate
{
public:
bool bw, fw;
int toolTipId;
QString toolTip;
QHttp* http;
QUrl source;
QList<TextBrowserResources> resources;
TextBrowserPrivate() : bw(false), fw(false), toolTipId(0)
{
http = new QHttp;
}
~TextBrowserPrivate()
{
delete http;
}
};
} // namespace DockWnd
} // namespace Gui
/* TRANSLATOR Gui::DockWnd::TextBrowser */
TextBrowser::TextBrowser(QWidget * parent)
: QTextBrowser(parent)
{
d = new TextBrowserPrivate;
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setAcceptDrops( true );
viewport()->setAcceptDrops( true );
connect( d->http, SIGNAL(done(bool)), this, SLOT(done(bool)));
connect( d->http, SIGNAL(stateChanged(int)), this, SLOT(onStateChanged(int)));
connect( d->http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)), this, SLOT(onResponseHeaderReceived(const QHttpResponseHeader &)));
connect( this, SIGNAL(highlighted(const QString&)), this, SLOT(onHighlighted(const QString&)));
connect( this, SIGNAL(backwardAvailable(bool)), this, SLOT(setBackwardAvailable(bool)));
connect( this, SIGNAL(forwardAvailable (bool)), this, SLOT(setForwardAvailable (bool)));
}
TextBrowser::~TextBrowser()
{
delete d;
}
QString TextBrowser::findUrl(const QUrl &name) const
{
QString fileName = name.toLocalFile();
QFileInfo fi(fileName);
if (fi.isAbsolute())
return fileName;
QString slash(QLatin1String("/"));
QStringList spaths = searchPaths();
for (QStringList::ConstIterator it = spaths.begin(); it != spaths.end(); ++it) {
QString path = *it;
if (!path.endsWith(slash))
path.append(slash);
path.append(fileName);
fi.setFile(path);
if (fi.isReadable())
return path;
}
QUrl src = source();
if (src.isEmpty())
return fileName;
QFileInfo path(QFileInfo(src.toLocalFile()).absolutePath(), fileName);
return path.absoluteFilePath();
}
/**
* Checks whether the resource data must be downloaded via http or
* it is a file resource on the disk.
*/
QVariant TextBrowser::loadResource ( int type, const QUrl& url )
{
QString name = url.toString();
if (url.scheme() == QLatin1String("http") ||
d->source.scheme() == QLatin1String("http")) {
return loadHttpResource(type, url);
} else { // file scheme
return loadFileResource(type, url);
}
}
/**
* Supports only rendering of local files and resources that can be downloaded over
* the http protocol. In the latter case the download gets started.
*/
void TextBrowser::setSource (const QUrl& url)
{
bool relativeUrl = url.isRelative();
if (!relativeUrl)
d->source = url; // last set absolute url
QString name = url.toString();
if (url.scheme() == QLatin1String("http")) {
// start the download but do not call setSource() of the base
// class because we must wait until the data are available.
// The slot done() is invoked automatically then.
d->http->setHost(url.host());
d->http->get(url.path(), 0);
} else if (d->source.scheme() == QLatin1String("http")) {
// relative hyperlink in previously downloaded a HTML page
d->source = d->source.resolved(url);
d->http->get(url.path(), 0);
} else {
QUrl resolved = url;
#if defined (Q_OS_WIN)
if (url.scheme() == QLatin1String("file") && !url.isRelative()) {
QString auth = url.authority();
QString path = url.path();
//If we click on a hyperlink with a reference to an absolute file name
//then we get a string that cannot be used to open the file. So we try
//to reproduce the original url.
if (!auth.isEmpty() && !path.isEmpty()) {
QString fileName = auth + QLatin1Char(':') + path;
resolved = QUrl::fromLocalFile(fileName);
}
}
#endif
QTextBrowser::setSource(resolved);
}
}
/**
* The URL \a name must be a local file and its contents is returned to the caller. If the file doesn't exist
* an error message in HTML format or an empty image -- depending on \a type -- is returned to the caller.
*/
QVariant TextBrowser::loadFileResource(int type, const QUrl& name)
{
QVariant data;
QUrl resolved = name;
if (!QFileInfo(name.toLocalFile()).isAbsolute() && QFileInfo(d->source.toLocalFile()).isAbsolute())
resolved = d->source.resolved(name);
QString fileName = findUrl(resolved);
QFile file(fileName);
if (file.open(QFile::ReadOnly)) {
data = file.readAll();
file.close();
} else if (type == QTextDocument::HtmlResource) {
data = QString::fromLatin1(
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">"
"<html>"
"<head>"
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-16\">"
"<title>Error</title>"
"</head>"
"<body>"
"<h1>%1</h1>"
"<div><p><strong>%2</strong></p>"
"</div></body>"
"</html>").arg(tr("Could not open file.")).arg(tr("You tried to access the address %1 which is currently unavailable. "
"Please make sure that the URL exists and try reloading the page.").arg(name.toString()));
} else if (type == QTextDocument::ImageResource) {
static const char * empty_xpm[] = {
"24 24 1 1",
". c #C0C0C0",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................"};
QPixmap px(empty_xpm);
data.setValue<QPixmap>(px);
}
return data;
}
/**
* Returns the downloaded resource to the caller. In case the resource contains
* references to further resources (e.g. referenced images in HTML text) we store
* the URLs in a list and start the download afterwards.
*/
QVariant TextBrowser::loadHttpResource(int type, const QUrl& name)
{
QVariant data;
if (type == QTextDocument::ImageResource) {
TextBrowserResources res;
res.url = name;
res.type = type;
d->resources.push_back(res);
static const char * empty_xpm[] = {
"24 24 1 1",
". c #C0C0C0",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................",
"........................"};
QPixmap px(empty_xpm);
data.setValue<QPixmap>(px);
return data;
}
if (d->http->error() == QHttp::NoError) {
return d->http->readAll();
} else {
if (type == QTextDocument::HtmlResource) {
data = QString::fromLatin1(
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">"
"<html>"
"<head>"
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-16\">"
"<title>Error</title>"
"</head>"
"<body>"
"<h1>%1</h1>"
"<div><p><strong>%2</strong></p>"
"</div></body>"
"</html>").arg(d->http->errorString()).arg(tr("You tried to access the address %1 which is currently unavailable. "
"Please make sure that the URL exists and try reloading the page.").arg(name.toString()));
}
}
return data;
}
/**
* The download has finished. We add the resource to the document now.
*/
void TextBrowser::done( bool /*err*/ )
{
if (d->resources.isEmpty()/* && d->requestId == d->http->currentId()*/) {
// set the HTML text
QTextBrowser::setSource(d->source);
} else {
// add the referenced resource to the document
TextBrowserResources res = d->resources.front();
QVariant data(d->http->readAll());
document()->addResource(res.type, res.url, data);
viewport()->repaint();
d->resources.pop_front();
}
// if we need to download further resources start a http request
if (!d->resources.isEmpty()) {
TextBrowserResources res = d->resources.front();
d->http->get(res.url.toString());
} else {
stateChanged(d->source.toString());
}
}
/**
* Prints some status information.
*/
void TextBrowser::onStateChanged ( int state )
{
switch (state) {
case QHttp::Connecting:
stateChanged(tr("Connecting to %1").arg(d->source.host()));
break;
case QHttp::Sending:
stateChanged(tr("Sending to %1").arg(d->source.host()));
break;
case QHttp::Reading:
stateChanged(tr("Reading from %1").arg(d->source.host()));
break;
case QHttp::Closing:
case QHttp::Unconnected:
if (d->http->error() == QHttp::NoError)
stateChanged(d->source.toString());
else
stateChanged(d->http->errorString());
break;
default:
break;
}
}
/**
* Checks for the status code and aborts the request if needed.
*/
void TextBrowser::onResponseHeaderReceived(const QHttpResponseHeader &responseHeader)
{
if (responseHeader.statusCode() != 200) {
stateChanged(tr("Download failed: %1.").arg(responseHeader.reasonPhrase()));
d->http->abort();
}
}
void TextBrowser::onHighlighted(const QString& url)
{
if (url.isEmpty() && d->toolTipId != 0) {
killTimer(d->toolTipId);
d->toolTipId = 0;
} else if (!url.isEmpty()) {
d->toolTip = url;
d->toolTipId = startTimer(1000);
} else {
QToolTip::showText(QCursor::pos(), url, this);
}
}
void TextBrowser::backward()
{
QTextBrowser::backward();
reload();
}
void TextBrowser::forward()
{
QTextBrowser::forward();
reload();
}
void TextBrowser::setBackwardAvailable( bool b )
{
d->bw = b;
}
void TextBrowser::setForwardAvailable( bool b )
{
d->fw = b;
}
void TextBrowser::timerEvent ( QTimerEvent * e )
{
if (d->toolTipId == e->timerId()) {
QToolTip::showText(QCursor::pos(), d->toolTip, this);
killTimer(d->toolTipId);
d->toolTipId = 0;
}
}
void TextBrowser::contextMenuEvent ( QContextMenuEvent * e )
{
QMenu* menu = new QMenu(this);
QAction* prev = menu->addAction(Gui::BitmapFactory().pixmap("back_pixmap"), tr("Previous"), this, SLOT(backward()));
prev->setEnabled(d->bw);
QAction* next = menu->addAction(Gui::BitmapFactory().pixmap("forward_pixmap"), tr("Forward"), this, SLOT(forward()));
next->setEnabled(d->fw);
menu->addSeparator();
menu->addAction(Gui::BitmapFactory().pixmap("home_pixmap"), tr("Home"), this, SLOT(home()));
menu->addAction(tr("Refresh"), this, SLOT(reload()));
menu->addSeparator();
menu->addAction(tr("Copy"), this, SLOT(copy()));
menu->addAction(tr("Select all"), this, SLOT(selectAll()));
menu->exec(e->globalPos());
delete menu;
}
void TextBrowser::dropEvent(QDropEvent * e)
{
const QMimeData* mimeData = e->mimeData();
if ( mimeData->hasFormat(QLatin1String("text/x-action-items")) ) {
QByteArray itemData = mimeData->data(QLatin1String("text/x-action-items"));
QDataStream dataStream(&itemData, QIODevice::ReadOnly);
int ctActions; dataStream >> ctActions;
// handle the first item only
QString action;
dataStream >> action;
CommandManager& rclMan = Application::Instance->commandManager();
Command* pCmd = rclMan.getCommandByName(action.toLatin1());
if ( pCmd ) {
QString info = pCmd->getAction()->whatsThis();
if ( !info.isEmpty() ) {
// cannot show help to this command
info = QString::fromLatin1(
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">"
"<html>"
"<body bgcolor=white text=black alink=red link=darkblue vlink=darkmagenta>"
"%1"
"</body>"
"</html>" ).arg( info );
} else {
info = QString::fromLatin1(
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">"
"<html>"
"<body bgcolor=white text=black alink=red link=darkblue vlink=darkmagenta>"
"<h2>"
" %1 '%2'"
"</h2>"
"<hr>"
"</body>"
"</html>" ).arg(tr("No description for")).arg(action);
}
setHtml( info );
}
e->setDropAction(Qt::CopyAction);
e->accept();
} else if ( mimeData->hasUrls() ) {
QList<QUrl> uri = mimeData->urls();
QUrl url = uri.front();
setSource(url);
e->setDropAction(Qt::CopyAction);
e->accept();
} else {
e->ignore();
}
}
void TextBrowser::dragEnterEvent (QDragEnterEvent * e)
{
const QMimeData* mimeData = e->mimeData();
if ( mimeData->hasFormat(QLatin1String("text/x-action-items")) )
e->accept();
else if (mimeData->hasUrls())
e->accept();
else
e->ignore();
}
void TextBrowser::dragMoveEvent( QDragMoveEvent *e )
{
const QMimeData* mimeData = e->mimeData();
if ( mimeData->hasFormat(QLatin1String("text/x-action-items")) )
e->accept();
else if (mimeData->hasUrls())
e->accept();
else
e->ignore();
}
// --------------------------------------------------------------------
/* TRANSLATOR Gui::DockWnd::HelpView */
/**
* Constructs a HelpView which is a child of 'parent', with the
* name 'name' and widget flags set to 'f'. \a home is the start page to show.
*/
HelpView::HelpView( const QString& start, QWidget* parent )
: QWidget(parent)
{
TextBrowser* browser = new TextBrowser(this);
browser->setFrameStyle( QFrame::Panel | QFrame::Sunken );
// set the start page now
if (!start.isEmpty())
browser->setSource(QUrl::fromLocalFile(start));
QHBoxLayout* layout = new QHBoxLayout();
layout->setAlignment(Qt::AlignTop);
layout->setSpacing(1);
layout->setMargin (1);
// create the group box for the layout
QGroupBox* groupBox = new QGroupBox(this);
// the 'Backward' button
QToolButton* back = new QToolButton( groupBox );
back->setIcon( Gui::BitmapFactory().pixmap("back_pixmap") );
back->setAutoRaise(true);
back->setToolTip(tr("Previous"));
// the 'Forward' button
QToolButton* forward = new QToolButton( groupBox );
forward->setIcon( Gui::BitmapFactory().pixmap("forward_pixmap") );
forward->setAutoRaise(true);
forward->setToolTip(tr("Next"));
// the 'Home' button
QToolButton* home = new QToolButton( groupBox );
home->setIcon( Gui::BitmapFactory().pixmap("home_pixmap") );
home->setAutoRaise(true);
home->setToolTip(tr("Home"));
// the 'Open' button
QToolButton* open = new QToolButton( groupBox );
open->setIcon( Gui::BitmapFactory().pixmap("helpopen") );
open->setAutoRaise(true);
open->setToolTip(tr("Open"));
QGridLayout* formLayout = new QGridLayout( this );
formLayout->setSpacing( 1 );
formLayout->setMargin ( 1 );
// add the buttons and the space
layout->addWidget( back );
layout->addWidget( forward );
layout->addWidget( home );
layout->addWidget( open );
QSpacerItem* spacer = new QSpacerItem( 0, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
layout->addItem( spacer );
groupBox->setLayout(layout);
label = new QLabel(this);
label->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
label->setText(start);
// add the button group with its elements and the browser to the layout
formLayout->addWidget( groupBox, 0, 0 );
formLayout->addWidget( browser, 1, 0 );
formLayout->addWidget( label, 2, 0 );
connect( this, SIGNAL(setSource( const QUrl& )), browser, SLOT(setSource( const QUrl& )));
connect( browser, SIGNAL(stateChanged(const QString&)), this, SLOT(onStateChanged(const QString&)));
connect( browser, SIGNAL(backwardAvailable(bool)), back, SLOT(setEnabled(bool)));
connect( browser, SIGNAL(forwardAvailable (bool)), forward, SLOT(setEnabled(bool)));
connect( browser, SIGNAL(startExternalBrowser(const QString&)),
this, SLOT (startExternalBrowser(const QString&)));
connect( back, SIGNAL(clicked()), browser, SLOT(backward()));
connect( browser, SIGNAL(backwardAvailable(bool) ), back, SLOT(setEnabled(bool) ) );
connect( forward, SIGNAL(clicked()), browser, SLOT(forward()));
connect( browser, SIGNAL(forwardAvailable(bool) ), forward, SLOT(setEnabled(bool) ) );
connect( home, SIGNAL(clicked()), browser, SLOT(home()));
connect( open, SIGNAL(clicked()), this, SLOT(openHelpFile()));
forward->setEnabled( false );
back->setEnabled( false );
qApp->installEventFilter(this);
}
/**
* Destroys the object and frees any allocated resources
*/
HelpView::~HelpView()
{
// no need to delete child widgets, Qt does it all for us
qApp->removeEventFilter(this);
}
/**
* Sets the file source \a src to the help view's text browser.
*/
void HelpView::setFileSource( const QString& src )
{
setSource( src );
}
/**
* Opens a file dialog to specify a help page to open.
*/
void HelpView::openHelpFile()
{
QString fn = QFileDialog::getOpenFileName(this, tr("Open file"), QString(), tr("All HTML files (*.html *.htm)"));
if ( !fn.isEmpty() )
setSource( QUrl::fromLocalFile(fn) );
}
/**
* Looks up into preferences to start an external browser to render sites which this class cannot do
* right now. If now browser has been specified so far or the start fails an error message appears.
*/
void HelpView::startExternalBrowser( const QString& url )
{
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath
("User parameter:BaseApp/Preferences/OnlineHelp");
QString browser = QString::fromUtf8(hGrp->GetASCII( "ExternalBrowser", "" ).c_str());
if (browser.isEmpty())
{
QMessageBox::critical( this, tr("External browser"), tr("No external browser found. Specify in preferences, please") );
return;
}
// create the command to execute
QStringList arguments;
arguments << url;
if (!QProcess::startDetached(browser, arguments))
{
QMessageBox::critical( this, tr("External browser"), tr("Starting of %1 failed").arg( browser ) );
}
}
void HelpView::onStateChanged(const QString& state)
{
label->setText(state);
}
bool HelpView::eventFilter ( QObject* o, QEvent* e )
{
// Handles What's This click events
if (e->type() == QEvent::WhatsThisClicked) {
QString url = static_cast<QWhatsThisClickedEvent*>(e)->href();
setSource(QUrl::fromLocalFile(url));
QWhatsThis::hideText();
return true;
}
return QWidget::eventFilter( o, e );
}
#include "moc_HelpView.cpp"

View File

@ -1,121 +0,0 @@
/***************************************************************************
* Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library 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. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef GUI_DOCKWND_HELP_VIEW_H
#define GUI_DOCKWND_HELP_VIEW_H
#include <QTextBrowser>
#include "DockWindow.h"
#include "Window.h"
class QUrl;
class QLabel;
class QHttpResponseHeader;
namespace Gui {
namespace DockWnd {
/**
* The TextBrowser class is an extension of Qt's QTextBrowser providing
* a context menu and the possibility to render files via drag and drop.
* @author Werner Mayer
*/
class TextBrowserPrivate;
class TextBrowser : public QTextBrowser
{
Q_OBJECT
public:
TextBrowser(QWidget * parent=0);
virtual ~TextBrowser();
void setSource (const QUrl& url);
QVariant loadResource (int type, const QUrl& name);
void backward();
void forward();
Q_SIGNALS:
/// start an external browser to display complex web sites
void startExternalBrowser( const QString& );
void stateChanged(const QString&);
protected:
void dropEvent (QDropEvent * e);
void dragEnterEvent (QDragEnterEvent * e);
void dragMoveEvent (QDragMoveEvent * e );
void contextMenuEvent(QContextMenuEvent * );
void timerEvent (QTimerEvent * e );
private Q_SLOTS:
void setBackwardAvailable( bool b);
void setForwardAvailable( bool b);
void done( bool );
void onStateChanged ( int state );
void onResponseHeaderReceived(const QHttpResponseHeader &);
void onHighlighted(const QString&);
private:
QString findUrl(const QUrl &name) const;
QVariant loadFileResource(int type, const QUrl& name);
QVariant loadHttpResource(int type, const QUrl& name);
private:
TextBrowserPrivate* d;
};
/**
* The help viewer class embeds a textbrowser to render help files.
* @author Wenrer Mayer
*/
class HelpViewViewPrivate;
class GuiExport HelpView : public QWidget
{
Q_OBJECT
public:
HelpView( const QString& home_, QWidget* parent = 0 );
~HelpView();
void setFileSource( const QString& );
/**
* Filters events if this object has been installed as an event filter for the watched object.
*/
bool eventFilter ( QObject* o, QEvent* e );
Q_SIGNALS:
void setSource( const QUrl& );
private Q_SLOTS:
void openHelpFile();
void startExternalBrowser( const QString& );
void onStateChanged(const QString& state);
private:
QLabel* label;
};
} // namespace DockWnd
} // namespace Gui
#endif // GUI_DOCKWND_HELP_VIEW_H

View File

@ -67,7 +67,6 @@
#include "MainWindow.h"
#include "Application.h"
#include "Assistant.h"
#include "DownloadDialog.h"
#include "DownloadManager.h"
#include "WaitCursor.h"
@ -94,14 +93,12 @@
#include "SelectionView.h"
#include "MenuManager.h"
//#include "ToolBox.h"
#include "HelpView.h"
#include "ReportView.h"
#include "CombiView.h"
#include "PythonConsole.h"
#include "TaskView/TaskView.h"
#include "DAGView/DAGView.h"
#include "DlgTipOfTheDayImp.h"
#include "DlgUndoRedo.h"
#include "DlgOnlineHelpImp.h"
@ -1280,24 +1277,6 @@ QPixmap MainWindow::splashImage() const
return splash_image;
}
void MainWindow::showTipOfTheDay(bool force)
{
// tip of the day?
ParameterGrp::handle
hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->
GetGroup("Preferences")->GetGroup("General");
const std::map<std::string,std::string>& config = App::Application::Config();
std::map<std::string, std::string>::const_iterator tp = config.find("HideTipOfTheDay");
bool tip = (tp == config.end());
tip = hGrp->GetBool("Tipoftheday", tip);
if (tip || force) {
Gui::Dialog::DlgTipOfTheDayImp dlg(instance);
dlg.exec();
}
}
/**
* Drops the event \a e and tries to open the files.
*/

View File

@ -120,8 +120,6 @@ public:
void stopSplasher(void);
/* The image of the splash screen of the application. */
QPixmap splashImage() const;
/** Shows the Tip-of-the-day dialog after startup. */
void showTipOfTheDay(bool force=false);
/** Shows the online documentation. */
void showDocumentation(const QString& help);
//@}

View File

@ -50,6 +50,7 @@
# include <QDesktopServices>
# include <QMenu>
# include <QDesktopWidget>
# include <QSignalMapper>
#endif
#include "BrowserView.h"
@ -57,7 +58,6 @@
#include <Gui/Application.h>
#include <Gui/MainWindow.h>
#include <Gui/ProgressBar.h>
#include <Gui/DownloadDialog.h>
#include <Gui/Command.h>
#include <Gui/OnlineDocumentation.h>
#include <Gui/DownloadManager.h>