Mercurial > projects > qtd
diff demos/browser/settings.d @ 73:7bfd46c330dc
more porting
author | mandel |
---|---|
date | Fri, 22 May 2009 10:59:00 +0000 |
parents | 71b382c10ef6 |
children | 37caa90ce503 |
line wrap: on
line diff
--- a/demos/browser/settings.d Wed May 20 22:44:31 2009 +0000 +++ b/demos/browser/settings.d Fri May 22 10:59:00 2009 +0000 @@ -41,11 +41,12 @@ module settings; -import QtGui.QDialog; -import ui_settings; +import qt.core.QSettings; +import qt.gui.qt.gui; +import qt.gui.QDialog; -import settings; +import QtWebKit.QtWebKit; import browserapplication; import browsermainwindow; @@ -53,287 +54,284 @@ import history; import networkaccessmanager; import webview; - -import QtCore.QSettings; -import QtGui.QtGui; -import QtWebKit.QtWebKit; +import ui_settings; class SettingsDialog : public QDialog, public Ui_Settings { - Q_OBJECT - public: - SettingsDialog(QWidget *parent = null); - : QDialog(parent) -{ - setupUi(this); - connect(exceptionsButton, SIGNAL(clicked()), this, SLOT(showExceptions())); - connect(setHomeToCurrentPageButton, SIGNAL(clicked()), this, SLOT(setHomeToCurrentPage())); - connect(cookiesButton, SIGNAL(clicked()), this, SLOT(showCookies())); - connect(standardFontButton, SIGNAL(clicked()), this, SLOT(chooseFont())); - connect(fixedFontButton, SIGNAL(clicked()), this, SLOT(chooseFixedFont())); - - loadDefaults(); - loadFromSettings(); -} - void accept(); -{ - saveToSettings(); - QDialog::accept(); -} - -private slots: - void loadDefaults() -{ - QWebSettings *defaultSettings = QWebSettings::globalSettings(); - QString standardFontFamily = defaultSettings.fontFamily(QWebSettings::StandardFont); - int standardFontSize = defaultSettings.fontSize(QWebSettings::DefaultFontSize); - standardFont = QFont(standardFontFamily, standardFontSize); - standardLabel.setText(QString(QLatin1String("%1 %2")).arg(standardFont.family()).arg(standardFont.pointSize())); - - QString fixedFontFamily = defaultSettings.fontFamily(QWebSettings::FixedFont); - int fixedFontSize = defaultSettings.fontSize(QWebSettings::DefaultFixedFontSize); - fixedFont = QFont(fixedFontFamily, fixedFontSize); - fixedLabel.setText(QString(QLatin1String("%1 %2")).arg(fixedFont.family()).arg(fixedFont.pointSize())); - - downloadsLocation.setText(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation)); - - enableJavascript.setChecked(defaultSettings.testAttribute(QWebSettings::JavascriptEnabled)); - enablePlugins.setChecked(defaultSettings.testAttribute(QWebSettings::PluginsEnabled)); -} - - void loadFromSettings() -{ - QSettings settings; - settings.beginGroup(QLatin1String("MainWindow")); - QString defaultHome = QLatin1String("http://qtsoftware.com"); - homeLineEdit.setText(settings.value(QLatin1String("home"), defaultHome).toString()); - settings.endGroup(); - - settings.beginGroup(QLatin1String("history")); - int historyExpire = settings.value(QLatin1String("historyExpire")).toInt(); - int idx = 0; - switch (historyExpire) { - case 1: idx = 0; break; - case 7: idx = 1; break; - case 14: idx = 2; break; - case 30: idx = 3; break; - case 365: idx = 4; break; - case -1: idx = 5; break; - default: - idx = 5; - } - expireHistory.setCurrentIndex(idx); - settings.endGroup(); - - settings.beginGroup(QLatin1String("downloadmanager")); - QString downloadDirectory = settings.value(QLatin1String("downloadDirectory"), downloadsLocation.text()).toString(); - downloadsLocation.setText(downloadDirectory); - settings.endGroup(); - - settings.beginGroup(QLatin1String("general")); - openLinksIn.setCurrentIndex(settings.value(QLatin1String("openLinksIn"), openLinksIn.currentIndex()).toInt()); - - settings.endGroup(); - - // Appearance - settings.beginGroup(QLatin1String("websettings")); - fixedFont = qVariantValue<QFont>(settings.value(QLatin1String("fixedFont"), fixedFont)); - standardFont = qVariantValue<QFont>(settings.value(QLatin1String("standardFont"), standardFont)); - - standardLabel.setText(QString(QLatin1String("%1 %2")).arg(standardFont.family()).arg(standardFont.pointSize())); - fixedLabel.setText(QString(QLatin1String("%1 %2")).arg(fixedFont.family()).arg(fixedFont.pointSize())); - - enableJavascript.setChecked(settings.value(QLatin1String("enableJavascript"), enableJavascript.isChecked()).toBool()); - enablePlugins.setChecked(settings.value(QLatin1String("enablePlugins"), enablePlugins.isChecked()).toBool()); - userStyleSheet.setText(settings.value(QLatin1String("userStyleSheet")).toUrl().toString()); - settings.endGroup(); - - // Privacy - settings.beginGroup(QLatin1String("cookies")); - - CookieJar *jar = BrowserApplication::cookieJar(); - QByteArray value = settings.value(QLatin1String("acceptCookies"), QLatin1String("AcceptOnlyFromSitesNavigatedTo")).toByteArray(); - QMetaEnum acceptPolicyEnum = jar.staticMetaObject.enumerator(jar.staticMetaObject.indexOfEnumerator("AcceptPolicy")); - CookieJar::AcceptPolicy acceptCookies = acceptPolicyEnum.keyToValue(value) == -1 ? - CookieJar::AcceptOnlyFromSitesNavigatedTo : - static_cast<CookieJar::AcceptPolicy>(acceptPolicyEnum.keyToValue(value)); - switch(acceptCookies) { - case CookieJar::AcceptAlways: - acceptCombo.setCurrentIndex(0); - break; - case CookieJar::AcceptNever: - acceptCombo.setCurrentIndex(1); - break; - case CookieJar::AcceptOnlyFromSitesNavigatedTo: - acceptCombo.setCurrentIndex(2); - break; - } - - value = settings.value(QLatin1String("keepCookiesUntil"), QLatin1String("Expire")).toByteArray(); - QMetaEnum keepPolicyEnum = jar.staticMetaObject.enumerator(jar.staticMetaObject.indexOfEnumerator("KeepPolicy")); - CookieJar::KeepPolicy keepCookies = keepPolicyEnum.keyToValue(value) == -1 ? - CookieJar::KeepUntilExpire : - static_cast<CookieJar::KeepPolicy>(keepPolicyEnum.keyToValue(value)); - switch(keepCookies) { - case CookieJar::KeepUntilExpire: - keepUntilCombo.setCurrentIndex(0); - break; - case CookieJar::KeepUntilExit: - keepUntilCombo.setCurrentIndex(1); - break; - case CookieJar::KeepUntilTimeLimit: - keepUntilCombo.setCurrentIndex(2); - break; - } - settings.endGroup(); - + + this(QWidget parent = null); + : QDialog(parent) + { + setupUi(this); + connect(exceptionsButton, SIGNAL(clicked()), this, SLOT(showExceptions())); + connect(setHomeToCurrentPageButton, SIGNAL(clicked()), this, SLOT(setHomeToCurrentPage())); + connect(cookiesButton, SIGNAL(clicked()), this, SLOT(showCookies())); + connect(standardFontButton, SIGNAL(clicked()), this, SLOT(chooseFont())); + connect(fixedFontButton, SIGNAL(clicked()), this, SLOT(chooseFixedFont())); - // Proxy - settings.beginGroup(QLatin1String("proxy")); - proxySupport.setChecked(settings.value(QLatin1String("enabled"), false).toBool()); - proxyType.setCurrentIndex(settings.value(QLatin1String("type"), 0).toInt()); - proxyHostName.setText(settings.value(QLatin1String("hostName")).toString()); - proxyPort.setValue(settings.value(QLatin1String("port"), 1080).toInt()); - proxyUserName.setText(settings.value(QLatin1String("userName")).toString()); - proxyPassword.setText(settings.value(QLatin1String("password")).toString()); - settings.endGroup(); -} - - void saveToSettings() -{ - QSettings settings; - settings.beginGroup(QLatin1String("MainWindow")); - settings.setValue(QLatin1String("home"), homeLineEdit.text()); - settings.endGroup(); - - settings.beginGroup(QLatin1String("general")); - settings.setValue(QLatin1String("openLinksIn"), openLinksIn.currentIndex()); - settings.endGroup(); - - settings.beginGroup(QLatin1String("history")); - int historyExpire = expireHistory.currentIndex(); - int idx = -1; - switch (historyExpire) { - case 0: idx = 1; break; - case 1: idx = 7; break; - case 2: idx = 14; break; - case 3: idx = 30; break; - case 4: idx = 365; break; - case 5: idx = -1; break; - } - settings.setValue(QLatin1String("historyExpire"), idx); - settings.endGroup(); - - // Appearance - settings.beginGroup(QLatin1String("websettings")); - settings.setValue(QLatin1String("fixedFont"), fixedFont); - settings.setValue(QLatin1String("standardFont"), standardFont); - settings.setValue(QLatin1String("enableJavascript"), enableJavascript.isChecked()); - settings.setValue(QLatin1String("enablePlugins"), enablePlugins.isChecked()); - QString userStyleSheetString = userStyleSheet.text(); - if (QFile::exists(userStyleSheetString)) - settings.setValue(QLatin1String("userStyleSheet"), QUrl::fromLocalFile(userStyleSheetString)); - else - settings.setValue(QLatin1String("userStyleSheet"), QUrl(userStyleSheetString)); - settings.endGroup(); - - //Privacy - settings.beginGroup(QLatin1String("cookies")); - - CookieJar::KeepPolicy keepCookies; - switch(acceptCombo.currentIndex()) { - default: - case 0: - keepCookies = CookieJar::KeepUntilExpire; - break; - case 1: - keepCookies = CookieJar::KeepUntilExit; - break; - case 2: - keepCookies = CookieJar::KeepUntilTimeLimit; - break; - } - CookieJar *jar = BrowserApplication::cookieJar(); - QMetaEnum acceptPolicyEnum = jar.staticMetaObject.enumerator(jar.staticMetaObject.indexOfEnumerator("AcceptPolicy")); - settings.setValue(QLatin1String("acceptCookies"), QLatin1String(acceptPolicyEnum.valueToKey(keepCookies))); - - CookieJar::KeepPolicy keepPolicy; - switch(keepUntilCombo.currentIndex()) { - default: - case 0: - keepPolicy = CookieJar::KeepUntilExpire; - break; - case 1: - keepPolicy = CookieJar::KeepUntilExit; - break; - case 2: - keepPolicy = CookieJar::KeepUntilTimeLimit; - break; - } - - QMetaEnum keepPolicyEnum = jar.staticMetaObject.enumerator(jar.staticMetaObject.indexOfEnumerator("KeepPolicy")); - settings.setValue(QLatin1String("keepCookiesUntil"), QLatin1String(keepPolicyEnum.valueToKey(keepPolicy))); - - settings.endGroup(); - - // proxy - settings.beginGroup(QLatin1String("proxy")); - settings.setValue(QLatin1String("enabled"), proxySupport.isChecked()); - settings.setValue(QLatin1String("type"), proxyType.currentIndex()); - settings.setValue(QLatin1String("hostName"), proxyHostName.text()); - settings.setValue(QLatin1String("port"), proxyPort.text()); - settings.setValue(QLatin1String("userName"), proxyUserName.text()); - settings.setValue(QLatin1String("password"), proxyPassword.text()); - settings.endGroup(); - - BrowserApplication::instance().loadSettings(); - BrowserApplication::networkAccessManager().loadSettings(); - BrowserApplication::cookieJar().loadSettings(); - BrowserApplication::historyManager().loadSettings(); -} - - void setHomeToCurrentPage() -{ - BrowserMainWindow *mw = static_cast<BrowserMainWindow*>(parent()); - WebView *webView = mw.currentTab(); - if (webView) - homeLineEdit.setText(webView.url().toString()); -} - - void showCookies() -{ - CookiesDialog *dialog = new CookiesDialog(BrowserApplication::cookieJar(), this); - dialog.exec(); -} - void showExceptions() -{ - CookiesExceptionsDialog *dialog = new CookiesExceptionsDialog(BrowserApplication::cookieJar(), this); - dialog.exec(); -} - - void chooseFont() -{ - bool ok; - QFont font = QFontDialog::getFont(&ok, standardFont, this); - if ( ok ) { - standardFont = font; - standardLabel.setText(QString(QLatin1String("%1 %2")).arg(font.family()).arg(font.pointSize())); - } -} - - void chooseFixedFont() -{ - bool ok; - QFont font = QFontDialog::getFont(&ok, fixedFont, this); - if ( ok ) { - fixedFont = font; - fixedLabel.setText(QString(QLatin1String("%1 %2")).arg(font.family()).arg(font.pointSize())); - } -} + loadDefaults(); + loadFromSettings(); + } + + void accept(); + { + saveToSettings(); + QDialog.accept(); + } private: - QFont standardFont; - QFont fixedFont; + + void loadDefaults() + { + QWebSettings defaultSettings = QWebSettings.globalSettings(); + QString standardFontFamily = defaultSettings.fontFamily(QWebSettings.StandardFont); + int standardFontSize = defaultSettings.fontSize(QWebSettings.DefaultFontSize); + standardFont = QFont(standardFontFamily, standardFontSize); + standardLabel.setText(QString(QLatin1String("%1 %2")).arg(standardFont.family()).arg(standardFont.pointSize())); + + QString fixedFontFamily = defaultSettings.fontFamily(QWebSettings.FixedFont); + int fixedFontSize = defaultSettings.fontSize(QWebSettings.DefaultFixedFontSize); + fixedFont = QFont(fixedFontFamily, fixedFontSize); + fixedLabel.setText(QString(QLatin1String("%1 %2")).arg(fixedFont.family()).arg(fixedFont.pointSize())); + + downloadsLocation.setText(QDesktopServices.storageLocation(QDesktopServices.DesktopLocation)); + + enableJavascript.setChecked(defaultSettings.testAttribute(QWebSettings.JavascriptEnabled)); + enablePlugins.setChecked(defaultSettings.testAttribute(QWebSettings.PluginsEnabled)); + } + + void loadFromSettings() + { + QSettings settings; + settings.beginGroup(QLatin1String("MainWindow")); + QString defaultHome = QLatin1String("http://qtsoftware.com"); + homeLineEdit.setText(settings.value(QLatin1String("home"), defaultHome).toString()); + settings.endGroup(); + + settings.beginGroup(QLatin1String("history")); + int historyExpire = settings.value(QLatin1String("historyExpire")).toInt(); + int idx = 0; + switch (historyExpire) { + case 1: idx = 0; break; + case 7: idx = 1; break; + case 14: idx = 2; break; + case 30: idx = 3; break; + case 365: idx = 4; break; + case -1: idx = 5; break; + default: + idx = 5; + } + expireHistory.setCurrentIndex(idx); + settings.endGroup(); + + settings.beginGroup(QLatin1String("downloadmanager")); + QString downloadDirectory = settings.value(QLatin1String("downloadDirectory"), downloadsLocation.text()).toString(); + downloadsLocation.setText(downloadDirectory); + settings.endGroup(); + + settings.beginGroup(QLatin1String("general")); + openLinksIn.setCurrentIndex(settings.value(QLatin1String("openLinksIn"), openLinksIn.currentIndex()).toInt()); + + settings.endGroup(); + + // Appearance + settings.beginGroup(QLatin1String("websettings")); + fixedFont = qVariantValue<QFont>(settings.value(QLatin1String("fixedFont"), fixedFont)); + standardFont = qVariantValue<QFont>(settings.value(QLatin1String("standardFont"), standardFont)); + + standardLabel.setText(QString(QLatin1String("%1 %2")).arg(standardFont.family()).arg(standardFont.pointSize())); + fixedLabel.setText(QString(QLatin1String("%1 %2")).arg(fixedFont.family()).arg(fixedFont.pointSize())); + + enableJavascript.setChecked(settings.value(QLatin1String("enableJavascript"), enableJavascript.isChecked()).toBool()); + enablePlugins.setChecked(settings.value(QLatin1String("enablePlugins"), enablePlugins.isChecked()).toBool()); + userStyleSheet.setText(settings.value(QLatin1String("userStyleSheet")).toUrl().toString()); + settings.endGroup(); + + // Privacy + settings.beginGroup(QLatin1String("cookies")); + + CookieJar jar = BrowserApplication.cookieJar(); + QByteArray value = settings.value(QLatin1String("acceptCookies"), QLatin1String("AcceptOnlyFromSitesNavigatedTo")).toByteArray(); + QMetaEnum acceptPolicyEnum = jar.staticMetaObject.enumerator(jar.staticMetaObject.indexOfEnumerator("AcceptPolicy")); + CookieJar.AcceptPolicy acceptCookies = acceptPolicyEnum.keyToValue(value) == -1 ? CookieJar.AcceptOnlyFromSitesNavigatedTo : + cast(CookieJar.AcceptPolicy) acceptPolicyEnum.keyToValue(value); + switch(acceptCookies) { + case CookieJar.AcceptAlways: + acceptCombo.setCurrentIndex(0); + break; + case CookieJar.AcceptNever: + acceptCombo.setCurrentIndex(1); + break; + case CookieJar.AcceptOnlyFromSitesNavigatedTo: + acceptCombo.setCurrentIndex(2); + break; + } + + value = settings.value(QLatin1String("keepCookiesUntil"), QLatin1String("Expire")).toByteArray(); + QMetaEnum keepPolicyEnum = jar.staticMetaObject.enumerator(jar.staticMetaObject.indexOfEnumerator("KeepPolicy")); + CookieJar.KeepPolicy keepCookies = keepPolicyEnum.keyToValue(value) == -1 ? CookieJar.KeepUntilExpire : + cast(CookieJar.KeepPolicy)(keepPolicyEnum.keyToValue(value)); + switch(keepCookies) { + case CookieJar.KeepUntilExpire: + keepUntilCombo.setCurrentIndex(0); + break; + case CookieJar.KeepUntilExit: + keepUntilCombo.setCurrentIndex(1); + break; + case CookieJar.KeepUntilTimeLimit: + keepUntilCombo.setCurrentIndex(2); + break; + } + settings.endGroup(); + + // Proxy + settings.beginGroup(QLatin1String("proxy")); + proxySupport.setChecked(settings.value(QLatin1String("enabled"), false).toBool()); + proxyType.setCurrentIndex(settings.value(QLatin1String("type"), 0).toInt()); + proxyHostName.setText(settings.value(QLatin1String("hostName")).toString()); + proxyPort.setValue(settings.value(QLatin1String("port"), 1080).toInt()); + proxyUserName.setText(settings.value(QLatin1String("userName")).toString()); + proxyPassword.setText(settings.value(QLatin1String("password")).toString()); + settings.endGroup(); + } + + void saveToSettings() + { + QSettings settings; + settings.beginGroup(QLatin1String("MainWindow")); + settings.setValue(QLatin1String("home"), homeLineEdit.text()); + settings.endGroup(); + + settings.beginGroup(QLatin1String("general")); + settings.setValue(QLatin1String("openLinksIn"), openLinksIn.currentIndex()); + settings.endGroup(); + + settings.beginGroup(QLatin1String("history")); + int historyExpire = expireHistory.currentIndex(); + int idx = -1; + switch (historyExpire) { + case 0: idx = 1; break; + case 1: idx = 7; break; + case 2: idx = 14; break; + case 3: idx = 30; break; + case 4: idx = 365; break; + case 5: idx = -1; break; + } + settings.setValue(QLatin1String("historyExpire"), idx); + settings.endGroup(); + + // Appearance + settings.beginGroup(QLatin1String("websettings")); + settings.setValue(QLatin1String("fixedFont"), fixedFont); + settings.setValue(QLatin1String("standardFont"), standardFont); + settings.setValue(QLatin1String("enableJavascript"), enableJavascript.isChecked()); + settings.setValue(QLatin1String("enablePlugins"), enablePlugins.isChecked()); + QString userStyleSheetString = userStyleSheet.text(); + if (QFile.exists(userStyleSheetString)) + settings.setValue(QLatin1String("userStyleSheet"), QUrl.fromLocalFile(userStyleSheetString)); + else + settings.setValue(QLatin1String("userStyleSheet"), QUrl(userStyleSheetString)); + settings.endGroup(); + + //Privacy + settings.beginGroup(QLatin1String("cookies")); + + CookieJar.KeepPolicy keepCookies; + switch(acceptCombo.currentIndex()) { + default: + case 0: + keepCookies = CookieJar.KeepUntilExpire; + break; + case 1: + keepCookies = CookieJar.KeepUntilExit; + break; + case 2: + keepCookies = CookieJar.KeepUntilTimeLimit; + break; + } + CookieJar jar = BrowserApplication.cookieJar(); + QMetaEnum acceptPolicyEnum = jar.staticMetaObject.enumerator(jar.staticMetaObject.indexOfEnumerator("AcceptPolicy")); + settings.setValue(QLatin1String("acceptCookies"), QLatin1String(acceptPolicyEnum.valueToKey(keepCookies))); + + CookieJar.KeepPolicy keepPolicy; + switch(keepUntilCombo.currentIndex()) { + default: + case 0: + keepPolicy = CookieJar.KeepUntilExpire; + break; + case 1: + keepPolicy = CookieJar.KeepUntilExit; + break; + case 2: + keepPolicy = CookieJar.KeepUntilTimeLimit; + break; + } + + QMetaEnum keepPolicyEnum = jar.staticMetaObject.enumerator(jar.staticMetaObject.indexOfEnumerator("KeepPolicy")); + settings.setValue(QLatin1String("keepCookiesUntil"), QLatin1String(keepPolicyEnum.valueToKey(keepPolicy))); + + settings.endGroup(); + + // proxy + settings.beginGroup(QLatin1String("proxy")); + settings.setValue(QLatin1String("enabled"), proxySupport.isChecked()); + settings.setValue(QLatin1String("type"), proxyType.currentIndex()); + settings.setValue(QLatin1String("hostName"), proxyHostName.text()); + settings.setValue(QLatin1String("port"), proxyPort.text()); + settings.setValue(QLatin1String("userName"), proxyUserName.text()); + settings.setValue(QLatin1String("password"), proxyPassword.text()); + settings.endGroup(); + + BrowserApplication.instance().loadSettings(); + BrowserApplication.networkAccessManager().loadSettings(); + BrowserApplication.cookieJar().loadSettings(); + BrowserApplication.historyManager().loadSettings(); + } + + void setHomeToCurrentPage() + { + BrowserMainWindow mw = cast(BrowserMainWindow) parent(); + WebView webView = mw.currentTab(); + if (webView) + homeLineEdit.setText(webView.url().toString()); + } + + void showCookies() + { + CookiesDialog dialog = new CookiesDialog(BrowserApplication.cookieJar(), this); + dialog.exec(); + } + + void showExceptions() + { + CookiesExceptionsDialog dialog = new CookiesExceptionsDialog(BrowserApplication.cookieJar(), this); + dialog.exec(); + } + + void chooseFont() + { + bool ok; + QFont font = QFontDialog.getFont(&ok, standardFont, this); + if ( ok ) { + standardFont = font; + standardLabel.setText(QString(QLatin1String("%1 %2")).arg(font.family()).arg(font.pointSize())); + } + } + + void chooseFixedFont() + { + bool ok; + QFont font = QFontDialog.getFont(&ok, fixedFont, this); + if ( ok ) { + fixedFont = font; + fixedLabel.setText(QString(QLatin1String("%1 %2")).arg(font.family()).arg(font.pointSize())); + } + } + +private: + + QFont standardFont; + QFont fixedFont; }