1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 09:32:12 +01:00

WebPage: Implement chooseFiles

This commit is contained in:
David Rosca 2015-06-09 18:01:17 +02:00
parent 2d6ba21c03
commit b30b25b254
2 changed files with 50 additions and 68 deletions

View File

@ -697,6 +697,35 @@ bool WebPage::event(QEvent* event)
return QWebEnginePage::event(event); return QWebEnginePage::event(event);
} }
QStringList WebPage::chooseFiles(QWebEnginePage::FileSelectionMode mode, const QStringList &oldFiles, const QStringList &acceptedMimeTypes)
{
Q_UNUSED(acceptedMimeTypes);
QStringList files;
QString suggestedFileName = s_lastUploadLocation;
if (!oldFiles.isEmpty())
suggestedFileName = oldFiles.first();
switch (mode) {
case FileSelectOpen:
files = QStringList(QzTools::getOpenFileName("WebPage-ChooseFile", view(), tr("Choose file..."), suggestedFileName));
break;
case FileSelectOpenMultiple:
files = QzTools::getOpenFileNames("WebPage-ChooseFile", view(), tr("Choose files..."), suggestedFileName);
break;
default:
files = QWebEnginePage::chooseFiles(mode, oldFiles, acceptedMimeTypes);
break;
}
if (!files.isEmpty())
s_lastUploadLocation = files.first();
return files;
}
void WebPage::setSSLCertificate(const QSslCertificate &cert) void WebPage::setSSLCertificate(const QSslCertificate &cert)
{ {
// if (cert != m_SslCert) // if (cert != m_SslCert)
@ -729,48 +758,6 @@ void WebPage::populateNetworkRequest(QNetworkRequest &request)
#endif #endif
} }
QWebEnginePage* WebPage::createWindow(QWebEnginePage::WebWindowType type)
{
switch (type) {
case QWebEnginePage::WebBrowserWindow: // TODO
case QWebEnginePage::WebBrowserTab: {
int index = m_view->browserWindow()->tabWidget()->addView(QUrl(), Qz::NT_CleanSelectedTab);
TabbedWebView* view = m_view->browserWindow()->weView(index);
view->setPage(new WebPage);
return view->page();
}
case QWebEnginePage::WebDialog: {
PopupWebView* view = new PopupWebView;
view->setPage(new WebPage);
PopupWindow* popup = new PopupWindow(view);
popup->show();
m_view->browserWindow()->addDeleteOnCloseWidget(popup);
return view->page();
}
default:
return 0;
}
}
QObject* WebPage::createPlugin(const QString &classid, const QUrl &url,
const QStringList &paramNames, const QStringList &paramValues)
{
Q_UNUSED(url)
Q_UNUSED(paramNames)
Q_UNUSED(paramValues)
if (classid == QLatin1String("RecoveryWidget") && mApp->restoreManager() && m_view) {
return new RecoveryWidget(m_view, m_view->browserWindow());
}
else {
load(QUrl("qupzilla:start"));
}
return 0;
}
bool WebPage::acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame) bool WebPage::acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame)
{ {
m_lastRequestUrl = url; m_lastRequestUrl = url;
@ -1221,35 +1208,30 @@ void WebPage::setJavaScriptEnabled(bool enabled)
#endif #endif
} }
#if QTWEBENGINE_DISABLED QWebEnginePage* WebPage::createWindow(QWebEnginePage::WebWindowType type)
QString WebPage::chooseFile(QWebEngineFrame* originatingFrame, const QString &oldFile)
{ {
QString suggFileName; switch (type) {
case QWebEnginePage::WebBrowserWindow: // TODO
if (oldFile.isEmpty()) { case QWebEnginePage::WebBrowserTab: {
suggFileName = s_lastUploadLocation; int index = m_view->browserWindow()->tabWidget()->addView(QUrl(), Qz::NT_CleanSelectedTab);
} TabbedWebView* view = m_view->browserWindow()->weView(index);
else { view->setPage(new WebPage);
suggFileName = oldFile; return view->page();
} }
const QString fileName = QzTools::getOpenFileName("WebPage-ChooseFile", view(), tr("Choose file..."), suggFileName); case QWebEnginePage::WebDialog: {
PopupWebView* view = new PopupWebView;
if (!fileName.isEmpty()) { view->setPage(new WebPage);
s_lastUploadLocation = fileName; PopupWindow* popup = new PopupWindow(view);
popup->show();
// Check if we can read from file m_view->browserWindow()->addDeleteOnCloseWidget(popup);
QFile file(fileName); return view->page();
if (!file.open(QFile::ReadOnly)) {
const QString msg = tr("Cannot read data from <b>%1</b>. Upload was cancelled!").arg(fileName);
QMessageBox::critical(view(), tr("Cannot read file!"), msg);
return QString();
}
} }
return fileName; default:
return 0;
}
} }
#endif
bool WebPage::isPointerSafeToUse(WebPage* page) bool WebPage::isPointerSafeToUse(WebPage* page)
{ {

View File

@ -120,14 +120,14 @@ private slots:
protected: protected:
bool event(QEvent* event); bool event(QEvent* event);
QWebEnginePage* createWindow(QWebEnginePage::WebWindowType type);
QObject* createPlugin(const QString &classid, const QUrl &url, const QStringList &paramNames, const QStringList &paramValues);
private: private:
QStringList chooseFiles(FileSelectionMode mode, const QStringList &oldFiles, const QStringList &acceptedMimeTypes) Q_DECL_OVERRIDE;
QWebEnginePage* createWindow(QWebEnginePage::WebWindowType type) Q_DECL_OVERRIDE;
#if QTWEBENGINE_DISABLED #if QTWEBENGINE_DISABLED
bool supportsExtension(Extension extension) const; bool supportsExtension(Extension extension) const;
bool extension(Extension extension, const ExtensionOption* option, ExtensionReturn* output = 0); bool extension(Extension extension, const ExtensionOption* option, ExtensionReturn* output = 0);
QString chooseFile(QWebFrame* originatingFrame, const QString &oldFile);
#endif #endif
bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame) Q_DECL_OVERRIDE; bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame) Q_DECL_OVERRIDE;