comparison demos/browser/webview.d @ 77:0654fc9bac95

more porting
author mandel
date Sun, 24 May 2009 13:46:32 +0000
parents 37caa90ce503
children 85c59c4e5f19
comparison
equal deleted inserted replaced
76:454e4b4beb59 77:0654fc9bac95
78 78
79 BrowserMainWindow mainWindow() 79 BrowserMainWindow mainWindow()
80 { 80 {
81 QObject w = this.parent(); 81 QObject w = this.parent();
82 while (w) { 82 while (w) {
83 if (BrowserMainWindow mw = qobject_cast<BrowserMainWindow>(w)) 83 if (BrowserMainWindow mw = cast(BrowserMainWindow) w)
84 return mw; 84 return mw;
85 w = w.parent(); 85 w = w.parent();
86 } 86 }
87 return BrowserApplication.instance().mainWindow(); 87 return BrowserApplication.instance().mainWindow();
88 } 88 }
115 m_pressedButtons = Qt.NoButton; 115 m_pressedButtons = Qt.NoButton;
116 return false; 116 return false;
117 } 117 }
118 if (frame == mainFrame()) { 118 if (frame == mainFrame()) {
119 m_loadingUrl = request.url(); 119 m_loadingUrl = request.url();
120 emit loadingUrl(m_loadingUrl); 120 loadingUrl.emit(m_loadingUrl);
121 } 121 }
122 return QWebPage.acceptNavigationRequest(frame, request, type); 122 return QWebPage.acceptNavigationRequest(frame, request, type);
123 } 123 }
124 124
125 QWebPage createWindow(QWebPage.WebWindowType type) 125 QWebPage createWindow(QWebPage.WebWindowType type)
126 { 126 {
127 //Q_UNUSED(type);
128 if (m_keyboardModifiers & Qt.ControlModifier || m_pressedButtons == Qt.MidButton) 127 if (m_keyboardModifiers & Qt.ControlModifier || m_pressedButtons == Qt.MidButton)
129 m_openInNewTab = true; 128 m_openInNewTab = true;
130 if (m_openInNewTab) { 129 if (m_openInNewTab) {
131 m_openInNewTab = false; 130 m_openInNewTab = false;
132 return mainWindow().tabWidget().newTab().page(); 131 return mainWindow().tabWidget().newTab().page();
136 return mainWindow.currentTab().page(); 135 return mainWindow.currentTab().page();
137 } 136 }
138 137
139 version(QT_NO_UITOOLS) {} else 138 version(QT_NO_UITOOLS) {} else
140 { 139 {
141 QObject createPlugin(QString classId, QUrl url, QStringList paramNames, QStringList paramValues); 140 QObject createPlugin(string classId, QUrl url, string[] paramNames, string[] paramValues);
142 { 141 {
143 //Q_UNUSED(url); 142 auto loader = new QUiLoader;
144 //Q_UNUSED(paramNames);
145 //Q_UNUSED(paramValues);
146 QUiLoader loader;
147 return loader.createWidget(classId, view()); 143 return loader.createWidget(classId, view());
148 } 144 }
149 } 145 }
150 146
151 private: 147 private:
155 if (reply.error() == QNetworkReply.NoError) { 151 if (reply.error() == QNetworkReply.NoError) {
156 BrowserApplication.downloadManager().handleUnsupportedContent(reply); 152 BrowserApplication.downloadManager().handleUnsupportedContent(reply);
157 return; 153 return;
158 } 154 }
159 155
160 QFile file(QLatin1String(":/notfound.html")); 156 auto file = new QFile(QLatin1String(":/notfound.html"));
161 bool isOpened = file.open(QIODevice.ReadOnly); 157 bool isOpened = file.open(QIODevice.ReadOnly);
162 assert(isOpened); 158 assert(isOpened);
163 QString title = tr("Error loading page: %1").arg(reply.url().toString()); 159 string title = Format(tr("Error loading page: {}"), reply.url().toString());
164 QString html = QString(QLatin1String(file.readAll())) 160 string html = Format(QLatin1String(file.readAll()),
165 .arg(title) 161 title,
166 .arg(reply.errorString()) 162 reply.errorString(),
167 .arg(reply.url().toString()); 163 reply.url().toString());
168 164
169 QBuffer imageBuffer; 165 QBuffer imageBuffer;
170 imageBuffer.open(QBuffer.ReadWrite); 166 imageBuffer.open(QBuffer.ReadWrite);
171 QIcon icon = view().style().standardIcon(QStyle.SP_MessageBoxWarning, 0, view()); 167 QIcon icon = view().style().standardIcon(QStyle.SP_MessageBoxWarning, 0, view());
172 QPixmap pixmap = icon.pixmap(QSize(32,32)); 168 QPixmap pixmap = icon.pixmap(QSize(32,32));
173 if (pixmap.save(&imageBuffer, "PNG")) { 169 if (pixmap.save(&imageBuffer, "PNG")) {
174 html.replace(QLatin1String("IMAGE_BINARY_DATA_HERE"), 170 html.replace(QLatin1String("IMAGE_BINARY_DATA_HERE"),
175 QString(QLatin1String(imageBuffer.buffer().toBase64()))); 171 QLatin1String(imageBuffer.buffer().toBase64()));
176 } 172 }
177 173
178 QWebFrame[] frames; 174 QWebFrame[] frames;
179 frames.append(mainFrame()); 175 frames.append(mainFrame());
180 while (!frames.isEmpty()) { 176 while (!frames.isEmpty()) {
233 if (!url.isEmpty()) 229 if (!url.isEmpty())
234 return url; 230 return url;
235 return m_initialUrl; 231 return m_initialUrl;
236 } 232 }
237 233
238 QString lastStatusBarText() 234 string lastStatusBarText()
239 { 235 {
240 return m_statusBarText; 236 return m_statusBarText;
241 } 237 }
242 238
243 int progress() const { return m_progress; } 239 int progress() const { return m_progress; }
308 qWarning() << "Received finished signal while progress is still:" << progress() << "Url:" << url(); 304 qWarning() << "Received finished signal while progress is still:" << progress() << "Url:" << url();
309 } 305 }
310 m_progress = 0; 306 m_progress = 0;
311 } 307 }
312 308
313 void setStatusBarText(QString string) 309 void setStatusBarText(string str)
314 { 310 {
315 m_statusBarText = string; 311 m_statusBarText = str;
316 } 312 }
317 313
318 void downloadRequested(QNetworkRequest request) 314 void downloadRequested(QNetworkRequest request)
319 { 315 {
320 BrowserApplication.downloadManager().download(request); 316 BrowserApplication.downloadManager().download(request);
326 pageAction(QWebPage.OpenLinkInNewWindow).trigger(); 322 pageAction(QWebPage.OpenLinkInNewWindow).trigger();
327 } 323 }
328 324
329 private: 325 private:
330 326
331 QString m_statusBarText; 327 string m_statusBarText;
332 QUrl m_initialUrl; 328 QUrl m_initialUrl;
333 int m_progress; 329 int m_progress;
334 WebPage m_page; 330 WebPage m_page;
335 } 331 }