Unknown filetypes show a dialog where the user can choose between «save as» and «open with». If there is a plugin handler, we catch it and decide whether to pass to the plugin-handler or to handle it ourself (we do so, if the mime type is registered, otherwise we pass to the plugin handler). If the mimetype is known and registered, we launch the configured application, otherwise we show th edialog mentioned above.; refs #79
This commit is contained in:
129
src/browser.hxx
129
src/browser.hxx
@@ -13,9 +13,7 @@
|
||||
#include <errorlog.hxx>
|
||||
#include <downloadmanager.hxx>
|
||||
#include <authentication.hxx>
|
||||
#include <settings.hxx>
|
||||
#include <editbookmarks.hxx>
|
||||
#include <temporaryfile.hxx>
|
||||
#include <proxyface/proxy.hxx>
|
||||
#include <sslclientnetworkmanager.hxx>
|
||||
|
||||
@@ -24,6 +22,8 @@
|
||||
#include <qbrowserlib/buttonlineedit.hxx>
|
||||
#include <qbrowserlib/filestorage.hxx>
|
||||
#include <qbrowserlib/swisswebview.hxx>
|
||||
#include <qbrowserlib/settings.hxx>
|
||||
#include <qbrowserlib/executor.hxx>
|
||||
|
||||
#include <QtGui/QMainWindow>
|
||||
#include <QtGui/QProgressBar>
|
||||
@@ -38,7 +38,6 @@
|
||||
#include <QtNetwork/QNetworkReply>
|
||||
#include <QtNetwork/QSslError>
|
||||
#include <QtNetwork/QNetworkProxy>
|
||||
#include <QtCore/QProcess>
|
||||
#include <QtCore/QDir>
|
||||
#include <QtGui/QFileDialog>
|
||||
|
||||
@@ -79,7 +78,8 @@ class Browser: public QMainWindow, protected Ui::Browser {
|
||||
_startUrl(urls.size()),
|
||||
_quirks(quirks), _search(new ButtonLineEdit),
|
||||
_searchEngines(new QComboBox),
|
||||
_bookmarkfile(bookmarkfile) {
|
||||
_bookmarkfile(bookmarkfile),
|
||||
_executor(&_settings) {
|
||||
LOG<<urls;
|
||||
_home = "about:blank";
|
||||
if (urls.size()) _home = urls.at(0);
|
||||
@@ -240,18 +240,6 @@ class Browser: public QMainWindow, protected Ui::Browser {
|
||||
~Browser() {
|
||||
LOG;
|
||||
QWebSettings::clearIconDatabase();
|
||||
for (DownloadProcesses::iterator it(_downloadProcesses.begin());
|
||||
it!=_downloadProcesses.end(); ++it) {
|
||||
LOG<<"cleanup:"<<it->second->fileName();
|
||||
it->second->setAutoRemove(_settings.flag("CloseApps"));
|
||||
delete it->second;
|
||||
it->second = 0;
|
||||
if (_settings.flag("CloseApps")) {
|
||||
LOG<<"terminate process";
|
||||
it->first->terminate();
|
||||
delete it->first;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//! Whitelisting
|
||||
@@ -260,8 +248,9 @@ class Browser: public QMainWindow, protected Ui::Browser {
|
||||
}
|
||||
|
||||
//! Create new empty tab.
|
||||
SwissWebView* newTab() {
|
||||
SwissWebView* browser(new SwissWebView);
|
||||
qbrowserlib::SwissWebView* newTab() {
|
||||
qbrowserlib::SwissWebView* browser
|
||||
(new qbrowserlib::SwissWebView(&_networkManager, &_executor));
|
||||
newTab(browser);
|
||||
return browser;
|
||||
}
|
||||
@@ -330,12 +319,11 @@ class Browser: public QMainWindow, protected Ui::Browser {
|
||||
}
|
||||
|
||||
//! Slot that receives and initializes a new SwissWebView
|
||||
void newTab(SwissWebView* browser) {
|
||||
browser->page()->setNetworkAccessManager(&_networkManager);
|
||||
void newTab(qbrowserlib::SwissWebView* browser) {
|
||||
_url->setFocus();
|
||||
// SwissWebView
|
||||
assert(connect(browser, SIGNAL(newView(SwissWebView*)),
|
||||
SLOT(newTab(SwissWebView*))));
|
||||
assert(connect(browser, SIGNAL(newView(qbrowserlib::SwissWebView*)),
|
||||
SLOT(newTab(qbrowserlib::SwissWebView*))));
|
||||
// QWebView
|
||||
assert(connect(browser, SIGNAL(urlChanged(const QUrl&)),
|
||||
SLOT(urlChanged(const QUrl&))));
|
||||
@@ -1326,16 +1314,6 @@ class Browser: public QMainWindow, protected Ui::Browser {
|
||||
it!=rh.end(); ++it) {
|
||||
LOG<<"RawHeader:"<<it->first<<it->second;
|
||||
}
|
||||
if (reply->isFinished()) {
|
||||
handleContent(reply);
|
||||
} else {
|
||||
assert(connect(reply, SIGNAL(finished()), SLOT(downloadFinished())));
|
||||
}
|
||||
}
|
||||
|
||||
void downloadFinished() {
|
||||
LOG;
|
||||
QNetworkReply *reply(qobject_cast<QNetworkReply*>(sender()));
|
||||
handleContent(reply);
|
||||
}
|
||||
|
||||
@@ -1377,83 +1355,13 @@ class Browser: public QMainWindow, protected Ui::Browser {
|
||||
LOG<<"Error:"<<_downloadManager->networkError(reply->error());
|
||||
return;
|
||||
}
|
||||
QString filename
|
||||
(QString::fromUtf8(reply->rawHeader("Content-Disposition")));
|
||||
if (filename.contains
|
||||
(QRegExp("^\\s*attachment\\s*;\\s*filename\\s*=\\s*\"[^\"]+\""))) {
|
||||
LOG<<"From Content-Disposition";
|
||||
filename = filename.replace
|
||||
(QRegExp("^\\s*attachment\\s*;\\s*filename\\s*=\\s*\"([^\"]+)\".*"),
|
||||
"\\1");
|
||||
} else {
|
||||
LOG<<"From path";
|
||||
filename =
|
||||
QFileInfo(!reply->url().toLocalFile().isEmpty()
|
||||
?reply->url().toLocalFile()
|
||||
:reply->url().path()).fileName();
|
||||
}
|
||||
LOG<<"Filename:"<<filename;
|
||||
QStringList type
|
||||
(_settings.mimetype
|
||||
(reply->header(QNetworkRequest::ContentTypeHeader).toString(),
|
||||
filename));
|
||||
if (!type.isEmpty()) {
|
||||
LOG<<"Start Application";
|
||||
filename.replace(QRegExp("^(.*)\\."+type.at(0)+"$"),
|
||||
"\\1"); // remove extension
|
||||
run(reply, filename+"."+type.at(0), type.at(1));
|
||||
} else {
|
||||
LOG<<"Show SaveOrRunDialog";
|
||||
SaveOrRunDialog choice(_kiosk, this);
|
||||
choice.setup(filename,
|
||||
reply->header(QNetworkRequest::ContentTypeHeader)
|
||||
.toString(),
|
||||
reply->url().host());
|
||||
if (choice.exec()==QDialog::Accepted) {
|
||||
if (choice.save()) {
|
||||
QFile file(choice.sor()->filename());
|
||||
file.open(QIODevice::WriteOnly);
|
||||
file.write(reply->readAll());
|
||||
file.close();
|
||||
} else if (choice.run()) {
|
||||
run(reply, filename, choice.sor()->program()+" %1");
|
||||
} else {
|
||||
// ...
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void run(QNetworkReply* reply, QString filename, QString command) {
|
||||
TemporaryFile *file(new TemporaryFile
|
||||
(QDir::tempPath()+QDir::separator()
|
||||
+filename));
|
||||
file->open();
|
||||
reply->seek(0);
|
||||
file->write(reply->readAll());
|
||||
file->close();
|
||||
LOG<<"Stored as:"<<file->fileName();
|
||||
statusBar()->showMessage(tr("launching application ..."), 5000);
|
||||
QProcess* process(new QProcess);
|
||||
_downloadProcesses[process] = file;
|
||||
assert(connect(process, SIGNAL(finished(int, QProcess::ExitStatus)),
|
||||
SLOT(processFinished())));
|
||||
QStringList args(command.split(" ")
|
||||
.replaceInStrings("%1", file->fileName()));
|
||||
QString prg(args.takeFirst());
|
||||
LOG<<"Running:"<<prg<<args.join(" ");
|
||||
process->start(prg, args);
|
||||
}
|
||||
|
||||
void processFinished() {
|
||||
LOG;
|
||||
if (_downloadProcesses.find(qobject_cast<QProcess*>(sender()))
|
||||
== _downloadProcesses.end()) return;
|
||||
if (_downloadProcesses[qobject_cast<QProcess*>(sender())])
|
||||
_downloadProcesses[qobject_cast<QProcess*>(sender())]
|
||||
->setAutoRemove(_settings.flag("CloseApps"));
|
||||
delete _downloadProcesses[qobject_cast<QProcess*>(sender())];
|
||||
_downloadProcesses.erase(qobject_cast<QProcess*>(sender()));
|
||||
statusBar()->showMessage(tr("handling content ..."), 5000);
|
||||
LOG<<"Show SaveOrRunDialog";
|
||||
qbrowserlib::SaveOrRunDialog dlg
|
||||
(reply, &_executor,
|
||||
reply->header(QNetworkRequest::ContentTypeHeader).toString(),
|
||||
reply->url().host(), _kiosk, this);
|
||||
if (!dlg.handlePreconfigured()) dlg.exec();
|
||||
}
|
||||
|
||||
//@}
|
||||
@@ -1591,8 +1499,6 @@ class Browser: public QMainWindow, protected Ui::Browser {
|
||||
QPrinter _printer;
|
||||
SslClientAuthNetworkAccessManager _networkManager;
|
||||
QSharedPointer<DownloadManager> _downloadManager;
|
||||
typedef std::map<QProcess*, TemporaryFile*> DownloadProcesses;
|
||||
DownloadProcesses _downloadProcesses;
|
||||
Settings _settings;
|
||||
ErrorLog _errorLog;
|
||||
LoginCertificate _logincertificate;
|
||||
@@ -1604,6 +1510,7 @@ class Browser: public QMainWindow, protected Ui::Browser {
|
||||
ButtonLineEdit* _search;
|
||||
QComboBox* _searchEngines;
|
||||
FileStorage _bookmarkfile;
|
||||
qbrowserlib::Executor _executor;
|
||||
};
|
||||
|
||||
//! @}
|
||||
|
||||
Reference in New Issue
Block a user