qbrowserlib::Executor as singleton; refs #167

master
Marc Wäckerlin 12 years ago
parent db352a329b
commit d191d8cc68
  1. 10
      src/browser.hxx
  2. 3
      src/designer/webviewwidgetifc.hxx
  3. 18
      src/qbrowserlib/executor.hxx
  4. 9
      src/qbrowserlib/pluginfactory.hxx
  5. 24
      src/qbrowserlib/qbrowserlib_de.ts
  6. 24
      src/qbrowserlib/qbrowserlib_en.ts
  7. 24
      src/qbrowserlib/qbrowserlib_fr.ts
  8. 24
      src/qbrowserlib/qbrowserlib_it.ts
  9. 28
      src/qbrowserlib/saveorrun.hxx
  10. 10
      src/qbrowserlib/swisswebpage.hxx
  11. 9
      src/qbrowserlib/swisswebview.hxx
  12. 63
      src/qbrowserlib/swisswebwidget.hxx

@ -75,9 +75,9 @@ class Browser: public QMainWindow, protected Ui::Browser {
_startUrl(urls.size()),
_quirks(quirks), _search(new qbrowserlib::ButtonLineEdit),
_searchEngines(new QComboBox),
_bookmarkfile(bookmarkfile),
_executor(&_settings) {
_bookmarkfile(bookmarkfile) {
TRC; LOG<<urls;
qbrowserlib::Executor::instance(&_settings);
_home = "about:blank";
if (urls.size()) _home = urls.at(0);
setupUi(this);
@ -248,7 +248,7 @@ class Browser: public QMainWindow, protected Ui::Browser {
//! Create new empty tab.
qbrowserlib::SwissWebView* newTab() {
qbrowserlib::SwissWebView* browser
(new qbrowserlib::SwissWebView(0, &_networkManager, &_executor));
(new qbrowserlib::SwissWebView(0, &_networkManager));
newTab(browser);
return browser;
}
@ -1391,8 +1391,7 @@ class Browser: public QMainWindow, protected Ui::Browser {
statusBar()->showMessage(tr("handling content ..."), 5000);
LOG<<"Show SaveOrRunDialog";
qbrowserlib::SaveOrRunDialog dlg
(reply, &_executor,
reply->header(QNetworkRequest::ContentTypeHeader).toString(),
(reply, reply->header(QNetworkRequest::ContentTypeHeader).toString(),
reply->url().host(), _kiosk, this);
if (!dlg.handlePreconfigured()) dlg.exec();
}
@ -1536,7 +1535,6 @@ class Browser: public QMainWindow, protected Ui::Browser {
qbrowserlib::ButtonLineEdit* _search;
QComboBox* _searchEngines;
FileStorage _bookmarkfile;
qbrowserlib::Executor _executor;
};
//! @}

@ -76,7 +76,7 @@ class SwissWebViewWidgetIfc: public QObject,
}
QWidget *createWidget(QWidget *parent) {
TRC;
return new qbrowserlib::SwissWebView(parent, &_net, &_executor);
return new qbrowserlib::SwissWebView(parent, &_net);
}
bool isInitialized() {
TRC;
@ -84,7 +84,6 @@ class SwissWebViewWidgetIfc: public QObject,
}
private:
QNetworkAccessManager _net;
qbrowserlib::Executor _executor;
};
//! @}

@ -17,7 +17,9 @@
#include <QtNetwork/QNetworkReply>
namespace qbrowserlib {
//! Execute external processes
/*! Implements a singleton pattern */
class Executor: public QObject {
Q_OBJECT;
@ -27,9 +29,17 @@ namespace qbrowserlib {
void applicationStarted();
void applicationFinished();
private:
Executor(Settings* settings=0): _settings(settings) {} // singleton
Executor(const Executor&); // singleton
public:
Executor(Settings* settings=0): _settings(settings) {}
static Executor& instance(Settings* settings=0) {
static Executor _instance(settings);
return _instance;
}
~Executor() {
TRC;
@ -102,9 +112,9 @@ namespace qbrowserlib {
_downloadProcesses.erase(qobject_cast<QProcess*>(sender()));
applicationFinished();
}
private:
private:
typedef std::map<QProcess*, TemporaryFile*> DownloadProcesses;
DownloadProcesses _downloadProcesses;
Settings* _settings;

@ -24,9 +24,8 @@ namespace qbrowserlib {
signals:
void done();
public:
PluginFactory(QNetworkAccessManager* net, Executor* executor,
QObject* p=0): QWebPluginFactory(p),
_net(net), _executor(executor) {
PluginFactory(QNetworkAccessManager* net, QObject* p=0):
QWebPluginFactory(p), _net(net) {
TRC;
// Plugin plugin;
// plugin.name = "Show PDF-Document";
@ -50,8 +49,7 @@ namespace qbrowserlib {
// }
QNetworkRequest req(url);
QNetworkReply* reply(_net->get(QNetworkRequest(url)));
SaveOrRunPlugin* p(new SaveOrRunPlugin(reply, _executor,
url, mimeType));
SaveOrRunPlugin* p(new SaveOrRunPlugin(reply, url, mimeType));
assert(connect(p, SIGNAL(accept()), SIGNAL(done())));
if (p->handlePreconfigured()) {
return p;
@ -69,7 +67,6 @@ namespace qbrowserlib {
private:
QList<Plugin> _plugins;
QNetworkAccessManager* _net;
Executor* _executor;
};
}

@ -632,14 +632,14 @@ p, li { white-space: pre-wrap; }
<context>
<name>qbrowserlib::SaveOrRun</name>
<message>
<location filename="saveorrun.hxx" line="144"/>
<location filename="saveorrun.hxx" line="156"/>
<location filename="saveorrun.hxx" line="146"/>
<location filename="saveorrun.hxx" line="158"/>
<source>File Exists</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="145"/>
<location filename="saveorrun.hxx" line="157"/>
<location filename="saveorrun.hxx" line="147"/>
<location filename="saveorrun.hxx" line="159"/>
<source>File already exists:
%1
@ -648,12 +648,12 @@ Overwrite?</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="169"/>
<location filename="saveorrun.hxx" line="171"/>
<source>No Program</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="170"/>
<location filename="saveorrun.hxx" line="172"/>
<source>Not an executable Program:
%1
@ -662,23 +662,23 @@ Specify full path to executable program</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="182"/>
<location filename="saveorrun.hxx" line="184"/>
<source>Save File As ...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="195"/>
<location filename="saveorrun.hxx" line="197"/>
<source>Open File With ...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="207"/>
<location filename="saveorrun.hxx" line="209"/>
<source>Dokumente</source>
<comment>Documents folder in local language</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="209"/>
<location filename="saveorrun.hxx" line="211"/>
<source>Arbeitsfläche</source>
<comment>Desktop folder in local language</comment>
<translation type="unfinished"></translation>
@ -687,7 +687,7 @@ Specify full path to executable program</source>
<context>
<name>qbrowserlib::SaveOrRunDialog</name>
<message>
<location filename="saveorrun.hxx" line="261"/>
<location filename="saveorrun.hxx" line="259"/>
<source>Unknown File Type</source>
<translation type="unfinished"></translation>
</message>
@ -695,7 +695,7 @@ Specify full path to executable program</source>
<context>
<name>qbrowserlib::SwissWebWidget</name>
<message>
<location filename="swisswebwidget.hxx" line="41"/>
<location filename="swisswebwidget.hxx" line="53"/>
<source>Browser Tools</source>
<comment>name of the browser&apos;s toolbar</comment>
<translation type="unfinished"></translation>

@ -632,14 +632,14 @@ p, li { white-space: pre-wrap; }
<context>
<name>qbrowserlib::SaveOrRun</name>
<message>
<location filename="saveorrun.hxx" line="144"/>
<location filename="saveorrun.hxx" line="156"/>
<location filename="saveorrun.hxx" line="146"/>
<location filename="saveorrun.hxx" line="158"/>
<source>File Exists</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="145"/>
<location filename="saveorrun.hxx" line="157"/>
<location filename="saveorrun.hxx" line="147"/>
<location filename="saveorrun.hxx" line="159"/>
<source>File already exists:
%1
@ -648,12 +648,12 @@ Overwrite?</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="169"/>
<location filename="saveorrun.hxx" line="171"/>
<source>No Program</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="170"/>
<location filename="saveorrun.hxx" line="172"/>
<source>Not an executable Program:
%1
@ -662,23 +662,23 @@ Specify full path to executable program</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="182"/>
<location filename="saveorrun.hxx" line="184"/>
<source>Save File As ...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="195"/>
<location filename="saveorrun.hxx" line="197"/>
<source>Open File With ...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="207"/>
<location filename="saveorrun.hxx" line="209"/>
<source>Dokumente</source>
<comment>Documents folder in local language</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="209"/>
<location filename="saveorrun.hxx" line="211"/>
<source>Arbeitsfläche</source>
<comment>Desktop folder in local language</comment>
<translation type="unfinished"></translation>
@ -687,7 +687,7 @@ Specify full path to executable program</source>
<context>
<name>qbrowserlib::SaveOrRunDialog</name>
<message>
<location filename="saveorrun.hxx" line="261"/>
<location filename="saveorrun.hxx" line="259"/>
<source>Unknown File Type</source>
<translation type="unfinished"></translation>
</message>
@ -695,7 +695,7 @@ Specify full path to executable program</source>
<context>
<name>qbrowserlib::SwissWebWidget</name>
<message>
<location filename="swisswebwidget.hxx" line="41"/>
<location filename="swisswebwidget.hxx" line="53"/>
<source>Browser Tools</source>
<comment>name of the browser&apos;s toolbar</comment>
<translation type="unfinished"></translation>

@ -632,14 +632,14 @@ p, li { white-space: pre-wrap; }
<context>
<name>qbrowserlib::SaveOrRun</name>
<message>
<location filename="saveorrun.hxx" line="144"/>
<location filename="saveorrun.hxx" line="156"/>
<location filename="saveorrun.hxx" line="146"/>
<location filename="saveorrun.hxx" line="158"/>
<source>File Exists</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="145"/>
<location filename="saveorrun.hxx" line="157"/>
<location filename="saveorrun.hxx" line="147"/>
<location filename="saveorrun.hxx" line="159"/>
<source>File already exists:
%1
@ -648,12 +648,12 @@ Overwrite?</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="169"/>
<location filename="saveorrun.hxx" line="171"/>
<source>No Program</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="170"/>
<location filename="saveorrun.hxx" line="172"/>
<source>Not an executable Program:
%1
@ -662,23 +662,23 @@ Specify full path to executable program</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="182"/>
<location filename="saveorrun.hxx" line="184"/>
<source>Save File As ...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="195"/>
<location filename="saveorrun.hxx" line="197"/>
<source>Open File With ...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="207"/>
<location filename="saveorrun.hxx" line="209"/>
<source>Dokumente</source>
<comment>Documents folder in local language</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="209"/>
<location filename="saveorrun.hxx" line="211"/>
<source>Arbeitsfläche</source>
<comment>Desktop folder in local language</comment>
<translation type="unfinished"></translation>
@ -687,7 +687,7 @@ Specify full path to executable program</source>
<context>
<name>qbrowserlib::SaveOrRunDialog</name>
<message>
<location filename="saveorrun.hxx" line="261"/>
<location filename="saveorrun.hxx" line="259"/>
<source>Unknown File Type</source>
<translation type="unfinished"></translation>
</message>
@ -695,7 +695,7 @@ Specify full path to executable program</source>
<context>
<name>qbrowserlib::SwissWebWidget</name>
<message>
<location filename="swisswebwidget.hxx" line="41"/>
<location filename="swisswebwidget.hxx" line="53"/>
<source>Browser Tools</source>
<comment>name of the browser&apos;s toolbar</comment>
<translation type="unfinished"></translation>

@ -632,14 +632,14 @@ p, li { white-space: pre-wrap; }
<context>
<name>qbrowserlib::SaveOrRun</name>
<message>
<location filename="saveorrun.hxx" line="144"/>
<location filename="saveorrun.hxx" line="156"/>
<location filename="saveorrun.hxx" line="146"/>
<location filename="saveorrun.hxx" line="158"/>
<source>File Exists</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="145"/>
<location filename="saveorrun.hxx" line="157"/>
<location filename="saveorrun.hxx" line="147"/>
<location filename="saveorrun.hxx" line="159"/>
<source>File already exists:
%1
@ -648,12 +648,12 @@ Overwrite?</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="169"/>
<location filename="saveorrun.hxx" line="171"/>
<source>No Program</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="170"/>
<location filename="saveorrun.hxx" line="172"/>
<source>Not an executable Program:
%1
@ -662,23 +662,23 @@ Specify full path to executable program</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="182"/>
<location filename="saveorrun.hxx" line="184"/>
<source>Save File As ...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="195"/>
<location filename="saveorrun.hxx" line="197"/>
<source>Open File With ...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="207"/>
<location filename="saveorrun.hxx" line="209"/>
<source>Dokumente</source>
<comment>Documents folder in local language</comment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="saveorrun.hxx" line="209"/>
<location filename="saveorrun.hxx" line="211"/>
<source>Arbeitsfläche</source>
<comment>Desktop folder in local language</comment>
<translation type="unfinished"></translation>
@ -687,7 +687,7 @@ Specify full path to executable program</source>
<context>
<name>qbrowserlib::SaveOrRunDialog</name>
<message>
<location filename="saveorrun.hxx" line="261"/>
<location filename="saveorrun.hxx" line="259"/>
<source>Unknown File Type</source>
<translation type="unfinished"></translation>
</message>
@ -695,7 +695,7 @@ Specify full path to executable program</source>
<context>
<name>qbrowserlib::SwissWebWidget</name>
<message>
<location filename="swisswebwidget.hxx" line="41"/>
<location filename="swisswebwidget.hxx" line="53"/>
<source>Browser Tools</source>
<comment>name of the browser&apos;s toolbar</comment>
<translation type="unfinished"></translation>

@ -39,9 +39,8 @@ namespace qbrowserlib {
public:
SaveOrRun(QNetworkReply* reply, Executor* executor,
QString type, QString src,
QWidget* p=0): QWidget(p), _reply(reply), _executor(executor) {
SaveOrRun(QNetworkReply* reply, QString type, QString src, QWidget* p=0):
QWidget(p), _reply(reply) {
TRC;
setupUi(this);
QString obj(remoteFilename());
@ -61,7 +60,7 @@ namespace qbrowserlib {
TRC;
QString filename(remoteFilename());
QStringList type
(_executor->settings()->mimetype
(qbrowserlib::Executor::instance().settings()->mimetype
(_reply->header(QNetworkRequest::ContentTypeHeader).toString(),
filename));
if (!type.isEmpty()) {
@ -69,9 +68,11 @@ namespace qbrowserlib {
hide();
filename.replace(QRegExp("^(.*)\\."+type.at(0)+"$"),
"\\1"); // remove extension
assert(connect(_executor, SIGNAL(applicationStarted()),
assert(connect(&qbrowserlib::Executor::instance(),
SIGNAL(applicationStarted()),
SIGNAL(accept())));
_executor->run(_reply, filename+"."+type.at(0), type.at(1));
qbrowserlib::Executor::instance().run
(_reply, filename+"."+type.at(0), type.at(1));
return true;
}
return false;
@ -132,7 +133,8 @@ namespace qbrowserlib {
void run() {
TRC; LOG<<program()<<filename();
_executor->run(_reply, filename(), program()+" %1");
qbrowserlib::Executor::instance().run
(_reply, filename(), program()+" %1");
accept();
}
@ -219,8 +221,6 @@ namespace qbrowserlib {
friend class SaveOrRunDialog;
QNetworkReply* _reply;
Executor* _executor;
};
class SaveOrRunPlugin: public SaveOrRun {
@ -228,11 +228,10 @@ namespace qbrowserlib {
public:
SaveOrRunPlugin(QNetworkReply* reply, Executor* executor,
SaveOrRunPlugin(QNetworkReply* reply,
const QUrl& url, const QString& mime,
bool kiosk=false, QWidget* p=0):
SaveOrRun(reply, executor,
mime, url.toString(), p) {
SaveOrRun(reply, mime, url.toString(), p) {
TRC;
setAutoFillBackground(true);
_type->setText(mime);
@ -253,10 +252,9 @@ namespace qbrowserlib {
public:
SaveOrRunDialog(QNetworkReply* reply, Executor* executor,
QString type, QString src,
SaveOrRunDialog(QNetworkReply* reply, QString type, QString src,
bool kiosk=false, QWidget* p=0):
QDialog(p), _sor(new SaveOrRun(reply, executor, type, src)) {
QDialog(p), _sor(new SaveOrRun(reply, type, src)) {
TRC;
setWindowTitle(tr("Unknown File Type"));
QVBoxLayout* l(new QVBoxLayout(this));

@ -34,11 +34,10 @@ namespace qbrowserlib {
signals:
void newPage(SwissWebPage*);
public:
SwissWebPage(QNetworkAccessManager* net,
Executor* executor, QObject *parent = 0):
QWebPage(parent), _net(net), _executor(executor) {
SwissWebPage(QNetworkAccessManager* net, QObject *parent = 0):
QWebPage(parent), _net(net) {
setNetworkAccessManager(_net);
PluginFactory* pf(new PluginFactory(_net, _executor, this));
PluginFactory* pf(new PluginFactory(_net, this));
assert(connect(pf, SIGNAL(done()), SLOT(back())));
setPluginFactory(pf);
setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
@ -53,7 +52,7 @@ namespace qbrowserlib {
switch (type) {
case QWebPage::WebBrowserWindow:
case QWebPage::WebModalDialog: {
SwissWebPage *page(new SwissWebPage(_net, _executor, parent()));
SwissWebPage *page(new SwissWebPage(_net, parent()));
newPage(page);
return page;
} break;
@ -76,7 +75,6 @@ namespace qbrowserlib {
}
private:
QNetworkAccessManager* _net;
Executor* _executor;
};
}

@ -38,16 +38,12 @@ namespace qbrowserlib {
public:
//! Default construction, creates new @ref SwissWebView
SwissWebView(QWidget *parent=0,
QNetworkAccessManager* net=0,
Executor* executor=0): QWebView(parent) {
QNetworkAccessManager* net=0): QWebView(parent) {
if (!net) net = (_fallbackNetworkAccessManager =
std::auto_ptr<QNetworkAccessManager>
(new QNetworkAccessManager)).get();
if (!executor) executor = (_fallbackExecutor =
std::auto_ptr<Executor>
(new Executor)).get();
//! @bugfix, gcc does not yet support constructor calling
x(new SwissWebPage(net, executor, this));
x(new SwissWebPage(net, this));
}
//! Construction with externally allocated @ref SwissWebPage
/*! SwissWebView takes ownership of SwissWebPage. */
@ -76,7 +72,6 @@ namespace qbrowserlib {
private:
std::auto_ptr<QNetworkAccessManager> _fallbackNetworkAccessManager;
std::auto_ptr<Executor> _fallbackExecutor;
};
}

@ -27,35 +27,52 @@ namespace qbrowserlib {
browser. To be used inside a QTabBar, as main window or as
docking widget. */
class SwissWebWidget: public QWidget, private Ui::SwissWebWidget {
Q_OBJECT;
public:
SwissWebWidget(QWidget* p=0): QWidget(p) {
setupUi(this);
QMainWindow* w(qobject_cast<QMainWindow*>(p?p->parentWidget():p));
qDebug()<<"Parent "<<p<<(w?"is":"is not")<<" a QMainWindow";
if (w) {
/*! Within a QMainWindow, the widget automatically reparents
the top buttons to the toolbar and the bottom status
line to the window's status bar. */
qDebug()<<"Rearranging";
QToolBar* t(w->addToolBar(trUtf8("Browser Tools",
"name of the browser's toolbar")));
while (_tools->count()) {
qDebug()<<"Rearranging tool item "<<(0)<<_tools->itemAt(0);
t->addWidget(_tools->itemAt(0)->widget());
}
delete _tools; _tools=0;
t->show();
_statusbar->removeWidget(_status);
delete _status; _status=0;
while (_statusbar->count()) {
qDebug()<<"Rearranging stat item "<<(0)<<_statusbar->itemAt(0);
w->statusBar()->addWidget(_statusbar->itemAt(0)->widget());
}
delete _statusbar; _statusbar=0;
}
/*! Within a QMainWindow, the widget automatically reparents
the top buttons to the toolbar and the bottom status
line to the window's status bar. */
moveToMain(qobject_cast<QMainWindow*>(p?p->parentWidget():p));
connects();
}
//! Moves status widgets to status bar, tool widgets to toolbar
/*! You can use this method to reparent the tools and the status
part of the widget into the toolbar and statusbar of your
main window.
@note If used as central widget of a QMainWindow, status and
tools are automatically reparented in the constructor. */
void moveToMain(QMainWindow* w) {
if (!w) return;
QToolBar* t(w->addToolBar(trUtf8("Browser Tools",
"name of the browser's toolbar")));
while (_tools->count())
t->addWidget(_tools->itemAt(0)->widget());
delete _tools; _tools=0;
_statusbar->removeWidget(_status); delete _status; _status=0;
while (_statusbar->count())
w->statusBar()->addWidget(_statusbar->itemAt(0)->widget());
delete _statusbar; _statusbar=0;
}
public Q_SLOTS:
void load() {
_webview->load(_url->text());
}
protected:
void connects() {
connect(_url, SIGNAL(returnPressed()), SLOT(load()));
}
};
}

Loading…
Cancel
Save