真不好意思,刚整理出第一章的1.2节,似乎有点多
翻译真的不容易,各位老大辛苦了
page 18
这类应用程序的危险在于,它们很容易在网站中发生变化,但与强大的易用性所能节省的时间相比,这些变化就微不足道了。特别是当网站拥有大量用户时,这种程序更能发挥其效用。当然,我们可以控制这些改变,使其只影响后台使用的JavaScript而完全不会影响网站的源代码。
The danger of such applications is that they can be vulnerable to changes in the web site, but this may be outweighed by the time savings achieved by the greater convenience of use—particularly if the site has a large number of users. Also, we might be able to contain the effects of such changes so that they only affect the JavaScript we use behind the scenes without requiring source code changes
at all.
注:
* 1. 危险在于,面对网站发生的变化,应用程序很脆弱。
* 2. 我们“包容”而不是“控制”这些变化。所谓的包容是指:使变化只影响我们(应用程序)后台使用的JavaScript 而完全不需要修改我们的(C++)代码。
page 19
这两个对象会在后台建立QWebpage对象和再调用数据对象QWebage...
These objects create QWebPage objects behind the scenes—recall that QWebPages are data objects—and have their QWebPages download a pecified page.
注:recall 似乎应该翻译成 回想,记起
page 19
当在页面中建立这两个对象时,引入它们的JavaScript,这样做有助于提取相对链接。
They then inject the JavaScript they are given when they are constructed into the page, and this is used to extract relevant links.
注:
* 它们将该JavaScript注入到页面
* 该JavaScript是在它们自己被构造时传入的
* 这个JavaScript被用来提取相对链接。
page 20
如果文件系统中没有保存脚本,就直接返回,把嵌入到可执行文件目录中的脚本作为资源。
But if the script isn’t in the filesystem then we fall back to using
a script that has been embedded in the executable as a resource.
注:如果该脚本在文件系统中不存在,我们将使用一个已经作为资源被嵌入到可执行程序中的脚本。
page 25
第一个参数是JavaScript 可用对象的名称(在此例中,是linkFetcher),QObject的第二个参数是实际对象的一个引用。此时,它是LinkFetcher类的一个实例。
The string first argument is the name that the object will be accessible as in JavaScript (in this example, linkFetcher), and the QObject second argument is a reference to the actual object—in this case an instance of the LinkFetcher class itself.
注:这是在介绍 {{{void QWebFrame::addToJavaScriptWindowObject(const QString &, QObject *)}}} 这个函数。第一个String类型参数... 第二个QObject类型参数...
page 25
如果加载失败,那么通知所有连接对象。否则,检查QString scriptOrScriptName 私有成员变量是真的拥有一个脚本还是仅有脚本的名称;如果是后者,我们尝试写入脚本的文本。打开二进制模式的文件,并利用静态 QString::fromUtf8()方法把 QFile::readAll()方法返回的QByteArray转换成Unicode,而不是创建一个QTextStream。一旦脚本就绪,让QWebPage的主框架对它进行评估,然后通知所有连接对象转换已成功。
If the load failed we notify any connected objects. Otherwise we check to see if the QString scriptOrScriptName private member variable holds an actual script or only the name of a script; and in the latter case we attempt to read in the script’s text. Instead of creating a QTextStream, we open the file in binary mode and convert the QByteArray returned by the QFile::readAll() method into Unicode using the static QString::fromUtf8() method. Once the script is ready we tell the QWebPage’s main frame to evaluate it, and then we notify any connected objects that we have successfully finished.
注:
* read in the script's text ==> "写入"脚本的文本 ? (笔误)
* 打开二进制模式的文件 ==> 以二进制模式打开文件?
* evaluate ==> 用"评估"是否合适(其他地方也有出现)?
page 25
既然已经为链接检查器设定了一个引用,那么链接检查器本身就是可以被JavaScript脚本读取的,那么脚本就可以调用任何链接检查器的公共槽,并获取它的属性值。在这个示例中,为使用JavaScript脚本而使用了addUrlAndName槽。
Since we have set a reference to the link checker itself as an object accessible to the JavaScript script, that script can call any of the link checker’s public slots and access its properties. In this case we have provided the addUrlAndName() slot expressly for the use of JavaScript scripts.
注:
* 由于我们已经将链接检查器自身的引用设置为可被JavaScript脚本访问的对象...
* 在这种情况下,我们特意提供了 addUrlAndName() 槽...
page 26
图 1.11 显示了如何为一个网页添加应用程序的QObject,在网页上下文中执行的JavaScript可以同时获取页面的HTML元素(通过文档对象模型)和所有页面访问的应用程序的QObject。
Figure 1.11 illustrates how by adding an application QObject to a web page, JavaScript executed in the context of the web page can access both the page’s HTML elements (via the Document Object Model), and any application QObjects we give the page access to.
注:
* how by ... 这句如何翻译?
* 可访问的是: 所有我们给于该page访问权限的QObject
page 26
需要特别注意的是最后一个声明,这里参考了C++的链接获取器对象,用linkFetcher调用了LinkFetcher::addUrlAndName()。
The key point to notice is the last statement, where we call LinkFetcher::addUrlAndName() using the linkFetcher reference to the C++ link fetcher object.
注:
* 声明 ==> 语句
* 参考 ==> 引用
page 26
因为这样会妨碍GUI应用程序的时间循环。
since they block the GUI application’s event loop.
注:笔误?
page 27
讨论一下如何使用类似引入JavaScript来调试应用程序是非常值得的(它并不容易)!
it is worth discussing how to debug applications that use injected JavaScript like this—since it isn’t easy!
注:值得讨论的是如何调试使用了这种注入式JavaScript的应用程序。
page 27
这对哪些仍然稳定或我们已经拥有控制权的网站非常有用。
which is very convenient for web sites that we know will remain stable or that we have control over.
注:似乎应该翻译成,将会保持稳定
page 27
因此,在这种情况下,我们必须在简单和方便之间做出抉择,改变我们的JavaScript脚本,使其...
So, in each case, we must make the trade-off between the ease and convenience with which we can change our JavaScript scripts to keep up with web site changes, versus the power and asynchronicity of Qt’s networking and web classes which make it easy to present a responsive user interface and allow us to do all our web programming in pure C++.
注:似乎应该是在 “简单和方便” 与 "强大和异步" 之间做出抉择
page 28
我们把Qt的全局函数qsrand() 作为Qt的随机数发生器。
Qt’s global qsrand() function is used to seed Qt’s random number generator.
注:为Qt的随机数发生器提供种子。
page 29
调用 ctreatePlygin() 方法
the createPlugin() method is called.
注:排版错误。
page 30
执行过程返回的默认结果是0,在这种情况下,程序渲染的对象是<object>标志的文本(如果存在的话),而不是渲染预期目标。
The default implementation returns 0, and in such cases the <object> tag’s text (if any) is rendered rather than the intended object.
注:
* implementation ==> 执行 vs 实现
* object ==> 目标 vs 对象