# HG changeset patch
# User mandel
# Date 1243172792 0
# Node ID 0654fc9bac95e5ca33d27910044336148d316a90
# Parent 454e4b4beb593538ccfd8b80897957daa56e8f29
more porting
diff -r 454e4b4beb59 -r 0654fc9bac95 demos/browser/TODO.txt
--- a/demos/browser/TODO.txt Sun May 24 11:24:57 2009 +0000
+++ b/demos/browser/TODO.txt Sun May 24 13:46:32 2009 +0000
@@ -1,14 +1,7 @@
This is a very coarse port of ./demos/browser from the QT 4.5.1 linux sources.
-Done:
-- *.cpp and *.h files have been merged into *.d files
-- C preprocessor include lines where replaced by import lines.
-- const from function headers were removed.
-- some '::' and most '->' have been replaced by '.'
-
Todo:
-- what about Q_PROPERTY/Q_UNUSED?
-- resolve multiple inheritance
-- QString -> char[]
-- QList -> []
-- everything else...
\ No newline at end of file
+- implement functionality from QList, QString and QStringList
+- resolve multiple inheritance, commented for now
+- fix segfaults due to not initialized variables
+- ...
\ No newline at end of file
diff -r 454e4b4beb59 -r 0654fc9bac95 demos/browser/bookmarks.d
--- a/demos/browser/bookmarks.d Sun May 24 11:24:57 2009 +0000
+++ b/demos/browser/bookmarks.d Sun May 24 13:46:32 2009 +0000
@@ -70,8 +70,8 @@
import xbel;
-const char[] BOOKMARKBAR = "Bookmarks Bar";
-const char[] BOOKMARKMENU = "Bookmarks Menu";
+const string BOOKMARKBAR = "Bookmarks Bar";
+const string BOOKMARKMENU = "Bookmarks Menu";
/*!
@@ -123,7 +123,7 @@
m_commands.push(command);
}
- void setTitle(BookmarkNode node, QString newTitle)
+ void setTitle(BookmarkNode node, string newTitle)
{
if (!m_loaded)
return;
@@ -133,7 +133,7 @@
m_commands.push(command);
}
- void setUrl(BookmarkNode node, QString newUrl)
+ void setUrl(BookmarkNode node, string newUrl)
{
if (!m_loaded)
return;
@@ -161,7 +161,7 @@
load();
for (int i = m_bookmarkRootNode.children().count() - 1; i >= 0; --i) {
- BookmarkNode node = m_bookmarkRootNode.children().at(i);
+ BookmarkNode node = m_bookmarkRootNode.children()[i];
if (node.title == tr(BOOKMARKMENU))
return node;
}
@@ -175,7 +175,7 @@
load();
for (int i = m_bookmarkRootNode.children().count() - 1; i >= 0; --i) {
- BookmarkNode node = m_bookmarkRootNode.children().at(i);
+ BookmarkNode node = m_bookmarkRootNode.children()[i];
if (node.title == tr(BOOKMARKBAR))
return node;
}
@@ -196,7 +196,7 @@
void importBookmarks()
{
- QString fileName = QFileDialog.getOpenFileName(0, tr("Open File"), QString(), tr("XBEL (*.xbel *.xml)"));
+ string fileName = QFileDialog.getOpenFileName(0, tr("Open File"), null, tr("XBEL (*.xbel *.xml)"));
if (fileName.isEmpty())
return;
@@ -216,7 +216,7 @@
void exportBookmarks()
{
- QString fileName = QFileDialog.getSaveFileName(0, tr("Save File"),
+ string fileName = QFileDialog.getSaveFileName(0, tr("Save File"),
tr("%1 Bookmarks.xbel").arg(QCoreApplication.applicationName()),
tr("XBEL (*.xbel *.xml)"));
if (fileName.isEmpty())
@@ -235,8 +235,8 @@
return;
XbelWriter writer;
- QString dir = QDesktopServices.storageLocation(QDesktopServices.DataLocation);
- QString bookmarkFile = dir + QLatin1String("/bookmarks.xbel");
+ string dir = QDesktopServices.storageLocation(QDesktopServices.DataLocation);
+ string bookmarkFile = dir + QLatin1String("/bookmarks.xbel");
if (!writer.write(bookmarkFile, m_bookmarkRootNode))
qWarning() << "BookmarkManager: error saving to" << bookmarkFile;
}
@@ -249,8 +249,8 @@
return;
m_loaded = true;
- QString dir = QDesktopServices.storageLocation(QDesktopServices.DataLocation);
- QString bookmarkFile = dir + QLatin1String("/bookmarks.xbel");
+ string dir = QDesktopServices.storageLocation(QDesktopServices.DataLocation);
+ string bookmarkFile = dir ~ QLatin1String("/bookmarks.xbel");
if (!QFile.exists(bookmarkFile))
bookmarkFile = QLatin1String(":defaultbookmarks.xbel");
@@ -266,7 +266,7 @@
BookmarkNode menu = null;
BookmarkNode[] others;
for (int i = m_bookmarkRootNode.children().count() - 1; i >= 0; --i) {
- BookmarkNode node = m_bookmarkRootNode.children().at(i);
+ BookmarkNode node = m_bookmarkRootNode.children()[i];
if (node.type() == BookmarkNode.Folder) {
// Automatically convert
if (node.title == tr("Toolbar Bookmarks") && !toolbar) {
@@ -284,7 +284,7 @@
menu = node;
}
} else {
- others.append(node);
+ others ~= node;
}
m_bookmarkRootNode.remove(node);
}
@@ -303,8 +303,8 @@
m_bookmarkRootNode.add(menu);
}
- for (int i = 0; i < others.count(); ++i)
- menu.add(others.at(i));
+ for (int i = 0; i < others.length; ++i)
+ menu.add(others[i]);
}
bool m_loaded;
@@ -377,7 +377,7 @@
{
public:
- this(BookmarksManager m_bookmarkManagaer, BookmarkNode node, QString newValue, bool title)
+ this(BookmarksManager m_bookmarkManagaer, BookmarkNode node, string newValue, bool title)
{
super();
m_bookmarkManagaer = m_bookmarkManagaer;
@@ -415,8 +415,8 @@
BookmarksManager m_bookmarkManagaer;
bool m_title;
- QString m_oldValue;
- QString m_newValue;
+ string m_oldValue;
+ string m_newValue;
BookmarkNode m_node;
}
@@ -494,7 +494,7 @@
QVariant data(QModelIndex index, int role = Qt.DisplayRole)
{
if (!index.isValid() || index.model() != this)
- return QVariant();
+ return QVariant();
BookmarkNode bookmarkNode = node(index);
switch (role) {
@@ -559,7 +559,7 @@
// get the parent node
BookmarkNode parentNode = node(parent);
- return createIndex(row, column, parentNode.children().at(row));
+ return createIndex(row, column, parentNode.children()[row]);
}
QModelIndex parent(QModelIndex index = QModelIndex())
@@ -610,7 +610,7 @@
BookmarkNode bookmarkNode = node(parent);
for (int i = row + count - 1; i >= row; --i) {
- BookmarkNode node = bookmarkNode.children().at(i);
+ BookmarkNode node = bookmarkNode.children()[i];
if (node == m_bookmarksManager.menu() || node == m_bookmarksManager.toolbar())
continue;
@@ -676,13 +676,11 @@
return mimeData;
}
- const char[] MIMETYPE = QLatin1String("application/bookmarks.xbel");
+ const string MIMETYPE = QLatin1String("application/bookmarks.xbel");
- QStringList mimeTypes()
+ string[] mimeTypes()
{
- QStringList types;
- types << MIMETYPE;
- return types;
+ return [ MIMETYPE ];
}
bool dropMimeData(QMimeData data, Qt.DropAction action, int row, int column, QModelIndex parent)
@@ -711,7 +709,7 @@
BookmarkNode rootNode = reader.read(&buffer);
BookmarkNode[] children = rootNode.children();
for (int i = 0; i < children.count(); ++i) {
- BookmarkNode bookmarkNode = children.at(i);
+ BookmarkNode bookmarkNode = children[i];
rootNode.remove(bookmarkNode);
row = qMax(0, row);
BookmarkNode parentNode = node(parent);
@@ -776,7 +774,7 @@
{
m_initialActions = actions;
for (int i = 0; i < m_initialActions.count(); ++i)
- addAction(m_initialActions.at(i));
+ addAction(m_initialActions[i]);
}
protected:
@@ -788,7 +786,7 @@
setRootIndex(m_bookmarksManager.bookmarksModel().index(1, 0));
// initial actions
for (int i = 0; i < m_initialActions.count(); ++i)
- addAction(m_initialActions.at(i));
+ addAction(m_initialActions[i]);
if (!m_initialActions.isEmpty())
addSeparator();
createMenu(model().index(0, 0), 1, this);
@@ -847,7 +845,7 @@
{
public:
- this(QString url, QString title, QWidget parent = null, BookmarksManager bookmarkManager = null)
+ this(string url, string title, QWidget parent = null, BookmarksManager bookmarkManager = null)
//: QDialog(parent)
{
m_url = url;
@@ -896,7 +894,7 @@
private:
- QString m_url;
+ string m_url;
BookmarksManager m_bookmarksManager;
AddBookmarkProxyModel m_proxyModel;
}
@@ -953,7 +951,7 @@
void customContextMenuRequested(QPoint pos)
{
- QMenu menu;
+ auto menu = new QMenu;
QModelIndex index = tree.indexAt(pos);
index = index.sibling(index.row(), 0);
if (index.isValid() && !tree.model().hasChildren(index)) {
@@ -1063,7 +1061,7 @@
void dragEnterEvent(QDragEnterEvent event)
{
- const QMimeData mimeData = event.mimeData();
+ QMimeData mimeData = event.mimeData();
if (mimeData.hasUrls())
event.acceptProposedAction();
QToolBar.dragEnterEvent(event);
@@ -1071,18 +1069,18 @@
void dropEvent(QDropEvent event)
{
- const QMimeData mimeData = event.mimeData();
+ QMimeData mimeData = event.mimeData();
if (mimeData.hasUrls() && mimeData.hasText()) {
QUrl[] urls = mimeData.urls();
QAction action = actionAt(event.pos());
- QString dropText;
+ string dropText;
if (action)
dropText = action.text();
int row = -1;
QModelIndex parentIndex = m_root;
for (int i = 0; i < m_bookmarksModel.rowCount(m_root); ++i) {
QModelIndex idx = m_bookmarksModel.index(i, 0, m_root);
- QString title = idx.data().toString();
+ string title = idx.data().toString();
if (title == dropText) {
row = i;
if (m_bookmarksModel.hasChildren(idx)) {
@@ -1093,7 +1091,7 @@
}
}
BookmarkNode bookmark = new BookmarkNode(BookmarkNode.Bookmark);
- bookmark.url = urls.at(0).toString();
+ bookmark.url = urls[0].toString();
bookmark.title = mimeData.text();
BookmarkNode parent = m_bookmarksModel.node(parentIndex);
diff -r 454e4b4beb59 -r 0654fc9bac95 demos/browser/browserapplication.d
--- a/demos/browser/browserapplication.d Sun May 24 11:24:57 2009 +0000
+++ b/demos/browser/browserapplication.d Sun May 24 13:46:32 2009 +0000
@@ -80,10 +80,10 @@
{
public:
- this(char[] args)
+ this(string[] args)
{
super(args);
- m_localServer = 0;
+ m_localServer = null;
QCoreApplication.setOrganizationName(QLatin1String("Trolltech"));
QCoreApplication.setApplicationName(QLatin1String("demobrowser"));
QCoreApplication.setApplicationVersion(QLatin1String("0.1"));
@@ -92,19 +92,19 @@
// Use a different server name for QWS so we can run an X11
// browser and a QWS browser in parallel on the same machine for
// debugging
- QString serverName = QCoreApplication.applicationName() + QLatin1String("_qws");
+ string serverName = QCoreApplication.applicationName() + QLatin1String("_qws");
} else {
- QString serverName = QCoreApplication.applicationName();
+ string serverName = QCoreApplication.applicationName();
}
- QLocalSocket socket;
+ auto socket = new QLocalSocket;
socket.connectToServer(serverName);
if (socket.waitForConnected(500)) {
auto stream = new QTextStream(&socket);
- QStringList args = QCoreApplication.arguments();
+ string[] args = QCoreApplication.arguments();
if (args.count() > 1)
stream << args.last();
else
- stream << QString();
+ stream << "";
stream.flush();
socket.waitForBytesWritten();
return;
@@ -134,7 +134,7 @@
}
QDesktopServices.setUrlHandler(QLatin1String("http"), this, "openUrl");
- QString localSysName = QLocale.system().name();
+ string localSysName = QLocale.system().name();
installTranslator(QLatin1String("qt_") + localSysName);
@@ -153,8 +153,8 @@
~this()
{
delete s_downloadManager;
- for (int i = 0; i < m_mainWindows.size(); ++i) {
- BrowserMainWindow window = m_mainWindows.at(i);
+ for (int i = 0; i < m_mainWindows.length; ++i) {
+ BrowserMainWindow window = m_mainWindows[i];
delete window;
}
delete s_networkAccessManager;
@@ -172,14 +172,14 @@
settings.beginGroup(QLatin1String("websettings"));
QWebSettings defaultSettings = QWebSettings.globalSettings();
- QString standardFontFamily = defaultSettings.fontFamily(QWebSettings.StandardFont);
+ string standardFontFamily = defaultSettings.fontFamily(QWebSettings.StandardFont);
int standardFontSize = defaultSettings.fontSize(QWebSettings.DefaultFontSize);
QFont standardFont = QFont(standardFontFamily, standardFontSize);
standardFont = qVariantValue!(QFont)(settings.value(QLatin1String("standardFont"), standardFont));
defaultSettings.setFontFamily(QWebSettings.StandardFont, standardFont.family());
defaultSettings.setFontSize(QWebSettings.DefaultFontSize, standardFont.pointSize());
- QString fixedFontFamily = defaultSettings.fontFamily(QWebSettings.FixedFont);
+ string fixedFontFamily = defaultSettings.fontFamily(QWebSettings.FixedFont);
int fixedFontSize = defaultSettings.fontSize(QWebSettings.DefaultFixedFontSize);
QFont fixedFont = QFont(fixedFontFamily, fixedFontSize);
fixedFont = qVariantValue!(QFont)(settings.value(QLatin1String("fixedFont"), fixedFont));
@@ -197,7 +197,7 @@
bool isTheOnlyBrowser()
{
- return (m_localServer != 0);
+ return (m_localServer != null);
}
BrowserMainWindow mainWindow()
@@ -212,8 +212,8 @@
{
clean();
BrowserMainWindow[] list;
- for (int i = 0; i < m_mainWindows.count(); ++i)
- list ~= m_mainWindows.at(i);
+ for (int i = 0; i < m_mainWindows.length; ++i)
+ list ~= m_mainWindows[i];
return list;
}
@@ -243,9 +243,9 @@
auto stream = new QDataStream(&buffer);
buffer.open(QIODevice.ReadWrite);
- stream << m_mainWindows.count();
- for (int i = 0; i < m_mainWindows.count(); ++i)
- stream << m_mainWindows.at(i).saveState();
+ stream << m_mainWindows.length;
+ for (int i = 0; i < m_mainWindows.length; ++i)
+ stream << m_mainWindows[i].saveState();
settings.setValue(QLatin1String("lastSession"), data);
settings.endGroup();
}
@@ -354,7 +354,7 @@
} else {
newWindow = newMainWindow();
}
- newWindow.restoreState(windows.at(i));
+ newWindow.restoreState(windows[i]);
}
}
@@ -367,12 +367,12 @@
{
clean();
int tabCount = 0;
- for (int i = 0; i < m_mainWindows.count(); ++i) {
- tabCount =+ m_mainWindows.at(i).tabWidget().count();
+ for (int i = 0; i < m_mainWindows.length; ++i) {
+ tabCount =+ m_mainWindows[i].tabWidget().count();
}
if (tabCount > 1) {
- int ret = QMessageBox.warning(mainWindow(), QString(),
+ int ret = QMessageBox.warning(mainWindow(), null,
tr("There are %1 windows and %2 tabs open\n"
"Do you want to quit anyway?").arg(m_mainWindows.count()).arg(tabCount),
QMessageBox.Yes | QMessageBox.No,
@@ -401,7 +401,7 @@
*/
void postLaunch()
{
- QString directory = QDesktopServices.storageLocation(QDesktopServices.DataLocation);
+ string directory = QDesktopServices.storageLocation(QDesktopServices.DataLocation);
if (directory.isEmpty())
directory = QDir.homePath() ~ QLatin1String("/.") ~ QCoreApplication.applicationName();
QWebSettings.setIconDatabasePath(directory);
@@ -412,7 +412,7 @@
// newMainWindow() needs to be called in main() for this to happen
if (m_mainWindows.count() > 0) {
- QStringList args = QCoreApplication.arguments();
+ string[] args = QCoreApplication.arguments();
if (args.count() > 1)
mainWindow().loadPage(args.last());
else
@@ -433,7 +433,7 @@
return;
socket.waitForReadyRead(1000);
QTextStream stream(socket);
- QString url;
+ string url;
stream >> url;
if (!url.isEmpty()) {
QSettings settings;
@@ -456,12 +456,12 @@
void clean()
{
// cleanup any deleted main windows first
- for (int i = m_mainWindows.count() - 1; i >= 0; --i)
- if (m_mainWindows.at(i).isNull())
+ for (int i = m_mainWindows.length - 1; i >= 0; --i)
+ if (m_mainWindows[i].isNull())
m_mainWindows.removeAt(i);
}
- void installTranslator(QString name)
+ void installTranslator(string name)
{
QTranslator translator = new QTranslator(this);
translator.load(name, QLibraryInfo.location(QLibraryInfo.TranslationsPath));
diff -r 454e4b4beb59 -r 0654fc9bac95 demos/browser/browsermainwindow.d
--- a/demos/browser/browsermainwindow.d Sun May 24 11:24:57 2009 +0000
+++ b/demos/browser/browsermainwindow.d Sun May 24 13:46:32 2009 +0000
@@ -83,7 +83,7 @@
class BrowserMainWindow : public QMainWindow
{
-static const qint32 BrowserMainWindowMagic = 0xba;
+static const int BrowserMainWindowMagic = 0xba;
public:
@@ -165,9 +165,9 @@
public:
- static QUrl guessUrlFromString(QString string)
+ static QUrl guessUrlFromString(string string)
{
- QString urlStr = string.trimmed();
+ string urlStr = string.trimmed();
auto test = new QRegExp(QLatin1String("^[a-zA-Z]+\\:.*"));
// Check if it looks like a qualified URL. Try parsing it and see.
@@ -188,7 +188,7 @@
if (!hasSchema) {
int dotIndex = urlStr.indexOf(QLatin1Char('.'));
if (dotIndex != -1) {
- QString prefix = urlStr.left(dotIndex).toLower();
+ string prefix = urlStr.left(dotIndex).toLower();
QByteArray schema = (prefix == QLatin1String("ftp")) ? prefix.toLatin1() : "http";
QUrl url =
QUrl.fromEncoded(schema + "://" + urlStr.toUtf8(), QUrl.TolerantMode);
@@ -222,8 +222,8 @@
QByteArray data;
auto stream = new QDataStream(&data, QIODevice.WriteOnly);
- stream << qint32(BrowserMainWindowMagic);
- stream << qint32(version_);
+ stream << cast(int) BrowserMainWindowMagic;
+ stream << cast(int) version_;
stream << size();
stream << !m_navigationBar.isHidden();
@@ -232,7 +232,7 @@
if (withTabs)
stream << tabWidget().saveState();
else
- stream << QByteArray();
+ stream << new QByteArray();
return data;
}
@@ -245,8 +245,8 @@
if (stream.atEnd())
return false;
- qint32 marker;
- qint32 v;
+ int marker;
+ int v;
stream >> marker;
stream >> v;
if (marker != BrowserMainWindowMagic || v != version_)
@@ -283,7 +283,7 @@
public:
- void loadPage(QString page)
+ void loadPage(string page)
{
QUrl url = guessUrlFromString(page);
loadUrl(url);
@@ -293,7 +293,7 @@
{
QSettings settings;
settings.beginGroup(QLatin1String("MainWindow"));
- QString home = settings.value(QLatin1String("home"), QLatin1String("http://qtsoftware.com/")).toString();
+ string home = settings.value(QLatin1String("home"), QLatin1String("http://qtsoftware.com/")).toString();
loadPage(home);
}
@@ -302,7 +302,7 @@
void closeEvent(QCloseEvent event)
{
if (m_tabWidget.count() > 1) {
- int ret = QMessageBox.warning(this, QString(),
+ int ret = QMessageBox.warning(this, null,
tr("Are you sure you want to close the window?"
" There are %1 tab open").arg(m_tabWidget.count()),
QMessageBox.Yes | QMessageBox.No,
@@ -348,12 +348,12 @@
}
}
- void slotUpdateStatusbar(QString string)
+ void slotUpdateStatusbar(string string)
{
statusBar().showMessage(string, 2000);
}
- void slotUpdateWindowTitle(QString title = QString())
+ void slotUpdateWindowTitle(string title = null)
{
if (title.isEmpty()) {
setWindowTitle(tr("Qt Demo Browser"));
@@ -391,7 +391,7 @@
void slotFileOpen()
{
- QString file = QFileDialog.getOpenFileName(this, tr("Open Web Resource"), QString(),
+ string file = QFileDialog.getOpenFileName(this, tr("Open Web Resource"), null,
tr("Web Resources (*.html *.htm *.svg *.png *.gif *.svgz);;All files (*.*)"));
if (file.isEmpty())
@@ -424,8 +424,8 @@
QWebSettings settings = QWebSettings.globalSettings();
bool pb = settings.testAttribute(QWebSettings.PrivateBrowsingEnabled);
if (!pb) {
- QString title = tr("Are you sure you want to turn on private browsing?");
- QString text = tr("%1
When private browsing in turned on,"
+ string title = tr("Are you sure you want to turn on private browsing?");
+ string text = tr("%1
When private browsing in turned on,"
" webpages are not added to the history,"
" items are automatically removed from the Downloads window,"
" new cookies are not stored, current cookies can't be accessed,"
@@ -434,7 +434,7 @@
" Until you close the window, you can still click the Back and Forward buttons"
" to return to the webpages you have opened.").arg(title);
- QMessageBox.StandardButton button = QMessageBox.question(this, QString(), text,
+ QMessageBox.StandardButton button = QMessageBox.question(this, null, text,
QMessageBox.Ok | QMessageBox.Cancel,
QMessageBox.Ok);
if (button == QMessageBox.Ok) {
@@ -444,8 +444,8 @@
settings.setAttribute(QWebSettings.PrivateBrowsingEnabled, false);
BrowserMainWindow[] windows = BrowserApplication.instance().mainWindows();
- for (int i = 0; i < windows.count(); ++i) {
- BrowserMainWindow window = windows.at(i);
+ for (int i = 0; i < windows.length; ++i) {
+ BrowserMainWindow window = windows[i];
window.m_lastSearch = null; //QString::null
window.tabWidget().clear();
}
@@ -462,7 +462,7 @@
if (!currentTab())
return;
bool ok;
- QString search = QInputDialog.getText(this, tr("Find"), tr("Text:"), QLineEdit.Normal, m_lastSearch, &ok);
+ string search = QInputDialog.getText(this, tr("Find"), tr("Text:"), QLineEdit.Normal, m_lastSearch, &ok);
if (ok && !search.isEmpty()) {
m_lastSearch = search;
if (!currentTab().findText(m_lastSearch))
@@ -494,8 +494,8 @@
void slotAddBookmark()
{
WebView webView = currentTab();
- QString url = webView.url().toString();
- QString title = webView.title();
+ string url = webView.url().toString();
+ string title = webView.title();
AddBookmarkDialog dialog(url, title);
dialog.exec();
}
@@ -570,7 +570,7 @@
if (!currentTab())
return;
- QString markup = currentTab().page().mainFrame().toHtml();
+ string markup = currentTab().page().mainFrame().toHtml();
QPlainTextEdit view = new QPlainTextEdit(markup);
view.setWindowTitle(tr("Page Source of %1").arg(currentTab().title()));
view.setMinimumWidth(640);
@@ -642,7 +642,7 @@
QWebHistory history = currentTab().history();
int historyCount = history.count();
for (int i = history.backItems(historyCount).count() - 1; i >= 0; --i) {
- QWebHistoryItem item = history.backItems(history.count()).at(i);
+ QWebHistoryItem item = history.backItems(history.count())[i];
QAction action = new QAction(this);
action.setData(-1*(historyCount-i-1));
QIcon icon = BrowserApplication.instance().icon(item.url());
@@ -660,7 +660,7 @@
QWebHistory history = currentTab().history();
int historyCount = history.count();
for (int i = 0; i < history.forwardItems(history.count()).count(); ++i) {
- QWebHistoryItem item = history.forwardItems(historyCount).at(i);
+ QWebHistoryItem item = history.forwardItems(historyCount)[i];
QAction action = new QAction(this);
action.setData(historyCount-i);
QIcon icon = BrowserApplication.instance().icon(item.url());
@@ -680,8 +680,8 @@
m_windowMenu.addSeparator();
BrowserMainWindow[] windows = BrowserApplication.instance().mainWindows();
- for (int i = 0; i < windows.count(); ++i) {
- BrowserMainWindow window = windows.at(i);
+ for (int i = 0; i < windows.length; ++i) {
+ BrowserMainWindow window = windows[i];
QAction action = m_windowMenu.addAction(window.windowTitle(), this, SLOT(slotShowWindow()));
action.setData(i);
action.setCheckable(true);
@@ -702,13 +702,13 @@
void slotShowWindow()
{
- if (QAction action = cast(QAction) sender()) {
+ if (QAction action = cast(QAction) signalSender()) {
QVariant v = action.data();
if (v.canConvert!(int)()) {
int offset = cast(int) v;
BrowserMainWindow[] windows = BrowserApplication.instance().mainWindows();
- windows.at(offset).activateWindow();
- windows.at(offset).currentTab().setFocus();
+ windows[offset].activateWindow();
+ windows[offset].currentTab().setFocus();
}
}
}
@@ -1016,5 +1016,5 @@
QIcon m_reloadIcon;
QIcon m_stopIcon;
- QString m_lastSearch;
+ string m_lastSearch;
}
diff -r 454e4b4beb59 -r 0654fc9bac95 demos/browser/chasewidget.d
--- a/demos/browser/chasewidget.d Sun May 24 11:24:57 2009 +0000
+++ b/demos/browser/chasewidget.d Sun May 24 13:46:32 2009 +0000
@@ -101,7 +101,6 @@
void paintEvent(QPaintEvent event)
{
- //Q_UNUSED(event);
auto p = new QPainter(this);
if (m_pixmapEnabled && !m_pixmap.isNull()) {
p.drawPixmap(0, 0, m_pixmap);
diff -r 454e4b4beb59 -r 0654fc9bac95 demos/browser/cookiejar.d
--- a/demos/browser/cookiejar.d Sun May 24 11:24:57 2009 +0000
+++ b/demos/browser/cookiejar.d Sun May 24 13:46:32 2009 +0000
@@ -44,7 +44,6 @@
import qt.core.QDebug;
import qt.core.QAbstractItemModel;
-import qt.core.QStringList;
import qt.core.QDateTime;
import qt.core.QDir;
import qt.core.QFile;
@@ -73,35 +72,35 @@
QDataStream operator<<(QDataStream stream, QNetworkCookie[] list)
{
stream << JAR_VERSION;
- stream << quint32(list.size());
- for (int i = 0; i < list.size(); ++i)
- stream << list.at(i).toRawForm();
+ stream << cast(uint) list.length;
+ for (int i = 0; i < list.length; ++i)
+ stream << list[i].toRawForm();
return stream;
}
-QDataStream operator>>(QDataStream stream, QNetworkCookie[] list)
+QDataStream operator>>(QDataStream stream, ref QNetworkCookie[] list)
{
list.clear();
- quint32 version_;
+ uint version_;
stream >> version_;
if (version != JAR_VERSION)
return stream;
- quint32 count;
+ uint count;
stream >> count;
- for(quint32 i = 0; i < count; ++i)
+ for(uint i = 0; i < count; ++i)
{
QByteArray value;
stream >> value;
QNetworkCookie[] newCookies = QNetworkCookie.parseCookies(value);
- if (newCookies.count() == 0 && value.length() != 0) {
+ if (newCookies.length == 0 && value.length() != 0) {
qWarning() << "CookieJar: Unable to parse saved cookie:" << value;
}
- for (int j = 0; j < newCookies.count(); ++j)
- list.append(newCookies.at(j));
+ for (int j = 0; j < newCookies.length; ++j)
+ list ~= newCookies[j];
if (stream.atEnd())
break;
@@ -144,7 +143,7 @@
QNetworkCookie[] cookiesForUrl(QUrl url)
{
- CookieJar that = const_cast(this);
+ CookieJar that = cast(CookieJar) this;
if (!m_loaded)
that.load();
@@ -166,7 +165,7 @@
if (globalSettings.testAttribute(QWebSettings.PrivateBrowsingEnabled))
return false;
- QString host = url.host();
+ string host = url.host();
bool eBlock = qBinaryFind(m_exceptions_block.begin(), m_exceptions_block.end(), host) != m_exceptions_block.end();
bool eAllow = qBinaryFind(m_exceptions_allow.begin(), m_exceptions_allow.end(), host) != m_exceptions_allow.end();
bool eAllowSession = qBinaryFind(m_exceptions_allowForSession.begin(), m_exceptions_allowForSession.end(), host) != m_exceptions_allowForSession.end();
@@ -178,7 +177,7 @@
// pass url domain == cookie domain
QDateTime soon = QDateTime.currentDateTime();
soon = soon.addDays(90);
- foreach(QNetworkCookie cookie, cookieList) {
+ foreach(QNetworkCookie cookie; cookieList) {
QNetworkCookie[] lst;
if (m_keepCookies == KeepUntilTimeLimit && !cookie.isSessionCookie() && cookie.expirationDate() > soon) {
cookie.setExpirationDate(soon);
@@ -204,7 +203,7 @@
if (addedCookies) {
m_saveTimer.changeOccurred();
- emit cookiesChanged();
+ cookiesChanged.emit();
}
return addedCookies;
}
@@ -212,7 +211,7 @@
AcceptPolicy acceptPolicy()
{
if (!m_loaded)
- (const_cast(this)).load();
+ (cast(CookieJar) this).load();
return m_acceptCookies;
}
@@ -229,7 +228,7 @@
KeepPolicy keepPolicy()
{
if (!m_loaded)
- (const_cast(this)).load();
+ (cast(CookieJar) this).load();
return m_keepCookies;
}
@@ -244,28 +243,28 @@
}
- QStringList blockedCookies()
+ string[] blockedCookies()
{
if (!m_loaded)
- (const_cast(this)).load();
+ (cast(CookieJar) this).load();
return m_exceptions_block;
}
- QStringList allowedCookies()
+ string[] allowedCookies()
{
if (!m_loaded)
- (const_cast(this)).load();
+ (cast(CookieJar) this).load();
return m_exceptions_allow;
}
- QStringList allowForSessionCookies()
+ string[] allowForSessionCookies()
{
if (!m_loaded)
- (const_cast(this)).load();
+ (cast(CookieJar) this).load();
return m_exceptions_allowForSession;
}
- void setBlockedCookies(QStringList list)
+ void setBlockedCookies(string[] list)
{
if (!m_loaded)
load();
@@ -274,7 +273,7 @@
m_saveTimer.changeOccurred();
}
- void setAllowedCookies(QStringList list)
+ void setAllowedCookies(string[] list)
{
if (!m_loaded)
load();
@@ -283,7 +282,7 @@
m_saveTimer.changeOccurred();
}
- void setAllowForSessionCookies(QStringList list)
+ void setAllowForSessionCookies(string[] list)
{
if (!m_loaded)
load();
@@ -298,7 +297,7 @@
{
setAllCookies(QNetworkCookie[]());
m_saveTimer.changeOccurred();
- emit cookiesChanged();
+ cookiesChanged.emit();
}
void loadSettings()
@@ -310,38 +309,39 @@
QMetaEnum acceptPolicyEnum = staticMetaObject.enumerator(staticMetaObject.indexOfEnumerator("AcceptPolicy"));
m_acceptCookies = acceptPolicyEnum.keyToValue(value) == -1 ?
AcceptOnlyFromSitesNavigatedTo :
- static_cast(acceptPolicyEnum.keyToValue(value));
+ cast(AcceptPolicy) acceptPolicyEnum.keyToValue(value);
value = settings.value(QLatin1String("keepCookiesUntil"), QLatin1String("KeepUntilExpire")).toByteArray();
QMetaEnum keepPolicyEnum = staticMetaObject.enumerator(staticMetaObject.indexOfEnumerator("KeepPolicy"));
m_keepCookies = keepPolicyEnum.keyToValue(value) == -1 ?
KeepUntilExpire :
- static_cast(keepPolicyEnum.keyToValue(value));
+ cast(KeepPolicy) keepPolicyEnum.keyToValue(value);
if (m_keepCookies == KeepUntilExit)
- setAllCookies(QNetworkCookie[]());
+ setAllCookies(null);
m_loaded = true;
- emit cookiesChanged();
+ cookiesChanged.emit();
}
private:
+
void save()
{
if (!m_loaded)
return;
purgeOldCookies();
- QString directory = QDesktopServices.storageLocation(QDesktopServices.DataLocation);
+ string directory = QDesktopServices.storageLocation(QDesktopServices.DataLocation);
if (directory.isEmpty())
directory = QDir.homePath() + QLatin1String("/.") + QCoreApplication.applicationName();
if (!QFile.exists(directory)) {
QDir dir;
dir.mkpath(directory);
}
- QSettings cookieSettings(directory + QLatin1String("/cookies.ini"), QSettings.IniFormat);
+ auto cookieSettings = new QSettings(directory + QLatin1String("/cookies.ini"), QSettings.IniFormat);
QNetworkCookie[] cookies = allCookies();
for (int i = cookies.count() - 1; i >= 0; --i) {
- if (cookies.at(i).isSessionCookie())
+ if (cookies[i].isSessionCookie())
cookies.removeAt(i);
}
cookieSettings.setValue(QLatin1String("cookies"), qVariantFromValue(cookies));
@@ -369,14 +369,14 @@
return;
int oldCount = cookies.count();
QDateTime now = QDateTime.currentDateTime();
- for (int i = cookies.count() - 1; i >= 0; --i) {
- if (!cookies.at(i).isSessionCookie() && cookies.at(i).expirationDate() < now)
+ for (int i = cookies.length - 1; i >= 0; --i) {
+ if (!cookies[i].isSessionCookie() && cookies[i].expirationDate() < now)
cookies.removeAt(i);
}
- if (oldCount == cookies.count())
+ if (oldCount == cookies.length)
return;
setAllCookies(cookies);
- emit cookiesChanged();
+ cookiesChanged.emit();
}
void load()
@@ -384,9 +384,9 @@
if (m_loaded)
return;
// load cookies and exceptions
- qRegisterMetaTypeStreamOperators("QNetworkCookie[]");
+ qRegisterMetaTypeStreamOperators!(QNetworkCookie[])("QNetworkCookie[]");
auto cookieSettings = new QSettings(QDesktopServices.storageLocation(QDesktopServices.DataLocation) + QLatin1String("/cookies.ini"), QSettings.IniFormat);
- setAllCookies(qvariant_cast(cookieSettings.value(QLatin1String("cookies"))));
+ setAllCookies(cast(QNetworkCookie[]) (cookieSettings.value(QLatin1String("cookies"))));
cookieSettings.beginGroup(QLatin1String("Exceptions"));
m_exceptions_block = cookieSettings.value(QLatin1String("block")).toStringList();
m_exceptions_allow = cookieSettings.value(QLatin1String("allow")).toStringList();
@@ -404,9 +404,9 @@
AcceptPolicy m_acceptCookies;
KeepPolicy m_keepCookies;
- QStringList m_exceptions_block;
- QStringList m_exceptions_allow;
- QStringList m_exceptions_allowForSession;
+ string[] m_exceptions_block;
+ string[] m_exceptions_allow;
+ string[] m_exceptions_allowForSession;
}
class CookieModel : public QAbstractTableModel
@@ -425,9 +425,9 @@
QVariant headerData(int section, Qt.Orientation orientation, int role)
{
if (role == Qt.SizeHintRole) {
- QFont font;
+ auto font = new QFont;
font.setPointSize(10);
- QFontMetrics fm(font);
+ auto fm = new QFontMetrics(font);
int height = fm.height() + fm.height()/3;
int width = fm.width(headerData(section, orientation, Qt.DisplayRole).toString());
return QSize(width, height);
@@ -451,7 +451,7 @@
case 5:
return tr("Contents");
default:
- return QVariant();
+ return new QVariant();
}
}
return QAbstractTableModel.headerData(section, orientation, role);
@@ -464,13 +464,13 @@
if (m_cookieJar)
lst = m_cookieJar.allCookies();
- if (index.row() < 0 || index.row() >= lst.size())
- return QVariant();
+ if (index.row() < 0 || index.row() >= lst.length)
+ return new QVariant();
switch (role) {
case Qt.DisplayRole:
case Qt.EditRole: {
- QNetworkCookie cookie = lst.at(index.row());
+ QNetworkCookie cookie = lst[index.row];
switch (index.column()) {
case 0:
return cookie.domain();
@@ -487,7 +487,7 @@
}
}
case Qt.FontRole:{
- QFont font;
+ auto font = new QFont;
font.setPointSize(10);
return font;
}
@@ -522,7 +522,7 @@
return true;
}
-private slots:
+private:
void cookiesChanged()
{
@@ -530,6 +530,7 @@
}
private:
+
CookieJar m_cookieJar;
}
@@ -542,7 +543,8 @@
{
public:
- this(CookieJar cookieJar, QWidget parent = this) : QDialog(parent)
+ this(CookieJar cookieJar, QWidget parent = this)
+ //: QDialog(parent)
{
setupUi(this);
setWindowFlags(Qt.Sheet);
@@ -606,9 +608,9 @@
QVariant headerData(int section, Qt.Orientation orientation, int role)
{
if (role == Qt.SizeHintRole) {
- QFont font;
+ auto font = new QFont;
font.setPointSize(10);
- QFontMetrics fm(font);
+ auto fm =new QFontMetrics(font);
int height = fm.height() + fm.height()/3;
int width = fm.width(headerData(section, orientation, Qt.DisplayRole).toString());
return QSize(width, height);
@@ -634,35 +636,35 @@
case Qt.DisplayRole:
case Qt.EditRole: {
int row = index.row();
- if (row < m_allowedCookies.count()) {
+ if (row < m_allowedCookies.length) {
switch (index.column()) {
case 0:
- return m_allowedCookies.at(row);
+ return m_allowedCookies[row];
case 1:
return tr("Allow");
}
}
- row = row - m_allowedCookies.count();
- if (row < m_blockedCookies.count()) {
+ row = row - m_allowedCookies.length;
+ if (row < m_blockedCookies.length) {
switch (index.column()) {
case 0:
- return m_blockedCookies.at(row);
+ return m_blockedCookies[row];
case 1:
return tr("Block");
}
}
- row = row - m_blockedCookies.count();
- if (row < m_sessionCookies.count()) {
+ row = row - m_blockedCookies.length;
+ if (row < m_sessionCookies.length) {
switch (index.column()) {
case 0:
- return m_sessionCookies.at(row);
+ return m_sessionCookies[row];
case 1:
return tr("Allow For Session");
}
}
}
case Qt.FontRole:{
- QFont font;
+ auto font = new QFont;
font.setPointSize(10);
return font;
}
@@ -677,7 +679,7 @@
int rowCount(QModelIndex parent = QModelIndex())
{
- return (parent.isValid() || !m_cookieJar) ? 0 : m_allowedCookies.count() + m_blockedCookies.count() + m_sessionCookies.count();
+ return (parent.isValid() || !m_cookieJar) ? 0 : m_allowedCookies.length + m_blockedCookies.length + m_sessionCookies.length;
}
bool removeRows(int row, int count, QModelIndex parent)
@@ -688,17 +690,17 @@
int lastRow = row + count - 1;
beginRemoveRows(parent, row, lastRow);
for (int i = lastRow; i >= row; --i) {
- if (i < m_allowedCookies.count()) {
+ if (i < m_allowedCookies.length) {
m_allowedCookies.removeAt(row);
continue;
}
- i = i - m_allowedCookies.count();
- if (i < m_blockedCookies.count()) {
+ i = i - m_allowedCookies.length;
+ if (i < m_blockedCookies.length) {
m_blockedCookies.removeAt(row);
continue;
}
- i = i - m_blockedCookies.count();
- if (i < m_sessionCookies.count()) {
+ i = i - m_blockedCookies.length;
+ if (i < m_sessionCookies.length) {
m_sessionCookies.removeAt(row);
continue;
}
@@ -716,9 +718,9 @@
CookieJar m_cookieJar;
// Domains we allow, Domains we block, Domains we allow for this session
- QStringList m_allowedCookies;
- QStringList m_blockedCookies;
- QStringList m_sessionCookies;
+ string[] m_allowedCookies;
+ string[] m_blockedCookies;
+ string[] m_sessionCookies;
}
@@ -728,7 +730,7 @@
public:
this(CookieJar cookieJar, QWidget parent = null)
- : QDialog(parent)
+ //: QDialog(parent)
{
m_cookieJar = cookieJar;
setupUi(this);
@@ -757,7 +759,7 @@
QFont f = font();
f.setPointSize(10);
- QFontMetrics fm(f);
+ auto fm = new QFontMetrics(f);
int height = fm.height() + fm.height()/3;
exceptionTable.verticalHeader().setDefaultSectionSize(height);
exceptionTable.verticalHeader().setMinimumSectionSize(-1);
@@ -783,7 +785,7 @@
{
if (domainLineEdit.text().isEmpty())
return;
- m_exceptionsModel.m_blockedCookies.append(domainLineEdit.text());
+ m_exceptionsModel.m_blockedCookies ~= domainLineEdit.text();
m_cookieJar.setBlockedCookies(m_exceptionsModel.m_blockedCookies);
m_exceptionsModel.reset();
}
@@ -792,7 +794,7 @@
{
if (domainLineEdit.text().isEmpty())
return;
- m_exceptionsModel.m_allowedCookies.append(domainLineEdit.text());
+ m_exceptionsModel.m_allowedCookies ~= domainLineEdit.text();
m_cookieJar.setAllowedCookies(m_exceptionsModel.m_allowedCookies);
m_exceptionsModel.reset();
}
@@ -800,12 +802,12 @@
{
if (domainLineEdit.text().isEmpty())
return;
- m_exceptionsModel.m_sessionCookies.append(domainLineEdit.text());
+ m_exceptionsModel.m_sessionCookie ~= domainLineEdit.text();
m_cookieJar.setAllowForSessionCookies(m_exceptionsModel.m_sessionCookies);
m_exceptionsModel.reset();
}
- void textChanged(QString text)
+ void textChanged(string text)
{
bool enabled = !text.isEmpty();
blockButton.setEnabled(enabled);
diff -r 454e4b4beb59 -r 0654fc9bac95 demos/browser/downloadmanager.d
--- a/demos/browser/downloadmanager.d Sun May 24 11:24:57 2009 +0000
+++ b/demos/browser/downloadmanager.d Sun May 24 13:46:32 2009 +0000
@@ -140,12 +140,12 @@
m_output.remove();
m_reply = r;
init();
- emit statusChanged();
+ statusChanged.emit();
}
void open()
{
- QFileInfo info(m_output);
+ auto info = new QFileInfo(m_output);
QUrl url = QUrl.fromLocalFile(info.absolutePath());
QDesktopServices.openUrl(url);
}
@@ -159,17 +159,15 @@
if (!m_requestFileName)
getFileName();
if (!m_output.open(QIODevice.WriteOnly)) {
- downloadInfoLabel.setText(tr("Error opening save file: %1")
- .arg(m_output.errorString()));
+ downloadInfoLabel.setText(Format(tr("Error opening save file: {}"), m_output.errorString()));
stopButton.click();
- emit statusChanged();
+ statusChanged.emit();
return;
}
- emit statusChanged();
+ statusChanged.emit();
}
if (-1 == m_output.write(m_reply.readAll())) {
- downloadInfoLabel.setText(tr("Error saving: %1")
- .arg(m_output.errorString()));
+ downloadInfoLabel.setText(Format(tr("Error saving: {}"), m_output.errorString()));
stopButton.click();
}
}
@@ -177,7 +175,7 @@
void error(QNetworkReply.NetworkError code)
{
qDebug() << "DownloadItem::error" << m_reply.errorString() << m_url;
- downloadInfoLabel.setText(tr("Network Error: %1").arg(m_reply.errorString()));
+ downloadInfoLabel.setText(Format(tr("Network Error: {}"), m_reply.errorString()));
tryAgainButton.setEnabled(true);
tryAgainButton.setVisible(true);
}
@@ -207,32 +205,32 @@
stopButton.hide();
m_output.close();
updateInfoLabel();
- emit statusChanged();
+ statusChanged.emit();
}
private:
void getFileName()
{
- QSettings settings;
+ auto settings = new QSettings;
settings.beginGroup(QLatin1String("downloadmanager"));
- QString defaultLocation = QDesktopServices.storageLocation(QDesktopServices.DesktopLocation);
- QString downloadDirectory = settings.value(QLatin1String("downloadDirectory"), defaultLocation).toString();
+ string defaultLocation = QDesktopServices.storageLocation(QDesktopServices.DesktopLocation);
+ string downloadDirectory = settings.value(QLatin1String("downloadDirectory"), defaultLocation).toString();
if (!downloadDirectory.isEmpty())
downloadDirectory += QLatin1Char('/');
- QString defaultFileName = saveFileName(downloadDirectory);
- QString fileName = defaultFileName;
+ string defaultFileName = saveFileName(downloadDirectory);
+ string fileName = defaultFileName;
if (m_requestFileName) {
fileName = QFileDialog.getSaveFileName(this, tr("Save File"), defaultFileName);
if (fileName.isEmpty()) {
m_reply.close();
- fileNameLabel.setText(tr("Download canceled: %1").arg(QFileInfo(defaultFileName).fileName()));
+ fileNameLabel.setText(Format(tr("Download canceled: {}"), (new QFileInfo(defaultFileName)).fileName()));
return;
}
}
m_output.setFileName(fileName);
- fileNameLabel.setText(QFileInfo(m_output.fileName()).fileName());
+ fileNameLabel.setText((new QFileInfo(m_output.fileName())).fileName());
if (m_requestFileName)
downloadReadyRead();
}
@@ -276,7 +274,7 @@
// update info label
double speed = m_bytesReceived * 1000.0 / m_downloadTime.elapsed();
double timeRemaining = (cast(double)(bytesTotal - m_bytesReceived)) / speed;
- QString timeRemainingString = tr("seconds");
+ string timeRemainingString = tr("seconds");
if (timeRemaining > 60) {
timeRemaining = timeRemaining / 60;
timeRemainingString = tr("minutes");
@@ -287,33 +285,31 @@
if (timeRemaining == 0)
timeRemaining = 1;
- QString info;
+ string info;
if (running) {
- QString remaining;
+ string remaining;
if (bytesTotal != 0)
- remaining = tr("- %4 %5 remaining")
- .arg(timeRemaining)
- .arg(timeRemainingString);
+ remaining = Format(tr("- {} {} remaining"), timeRemaining, timeRemainingString);
- info = QString(tr("%1 of %2 (%3/sec) %4"))
- .arg(dataString(m_bytesReceived))
- .arg(bytesTotal == 0 ? tr("?") : dataString(bytesTotal))
- .arg(dataString(cast(int) speed))
- .arg(remaining);
+ info = Format(tr("{} of {} ({}/sec) {}"),
+ dataString(m_bytesReceived),
+ bytesTotal == 0 ? tr("?") : dataString(bytesTotal),
+ dataString(cast(int) speed),
+ remaining);
} else {
if (m_bytesReceived == bytesTotal)
info = dataString(m_output.size());
else
- info = tr("%1 of %2 - Stopped")
- .arg(dataString(m_bytesReceived))
- .arg(dataString(bytesTotal));
+ info = Format(tr("{} of {} - Stopped"),
+ dataString(m_bytesReceived),
+ dataString(bytesTotal));
}
downloadInfoLabel.setText(info);
}
- QString dataString(int size)
+ string dataString(int size)
{
- QString unit;
+ string unit;
if (size < 1024) {
unit = tr("bytes");
} else if (size < 1024*1024) {
@@ -323,27 +319,27 @@
size /= 1024*1024;
unit = tr("MB");
}
- return QString(QLatin1String("%1 %2")).arg(size).arg(unit);
+ return Format(QLatin1String("{} {}"), size, unit);
}
- QString saveFileName(QString directory)
+ string saveFileName(string directory)
{
// Move this function into QNetworkReply to also get file name sent from the server
- QString path = m_url.path();
- QFileInfo info(path);
- QString baseName = info.completeBaseName();
- QString endName = info.suffix();
+ string path = m_url.path();
+ auto info = new QFileInfo(path);
+ string baseName = info.completeBaseName();
+ string endName = info.suffix();
if (baseName.isEmpty()) {
baseName = QLatin1String("unnamed_download");
qDebug() << "DownloadManager:: downloading unknown file:" << m_url;
}
- QString name = directory + baseName + QLatin1Char('.') + endName;
+ string name = directory ~ baseName ~ QLatin1Char('.') ~ endName;
if (QFile.exists(name)) {
// already exists, don't overwrite
int i = 1;
do {
- name = directory + baseName + QLatin1Char('-') + QString.number(i++) + QLatin1Char('.') + endName;
+ name = directory ~ baseName ~ QLatin1Char('-') ~ QString.number(i++) ~ QLatin1Char('.') ~ endName;
} while (QFile.exists(name));
}
return name;
@@ -403,8 +399,8 @@
int activeDownloads()
{
int count = 0;
- for (int i = 0; i < m_downloads.count(); ++i) {
- if (m_downloads.at(i).stopButton.isEnabled())
+ for (int i = 0; i < m_downloads.length; ++i) {
+ if (m_downloads[i].stopButton.isEnabled())
++count;
}
return count;
@@ -454,11 +450,11 @@
void cleanup()
{
- if (m_downloads.isEmpty())
+ if (m_downloads.length == 0)
return;
- m_model.removeRows(0, m_downloads.count());
+ m_model.removeRows(0, m_downloads.length);
updateItemCount();
- if (m_downloads.isEmpty() && m_iconProvider) {
+ if (m_downloads.length == 0 && m_iconProvider) {
delete m_iconProvider;
m_iconProvider = 0;
}
@@ -477,25 +473,25 @@
if (m_removePolicy == Exit)
return;
- for (int i = 0; i < m_downloads.count(); ++i) {
- QString key = QString(QLatin1String("download_%1_")).arg(i);
- settings.setValue(key + QLatin1String("url"), m_downloads[i].m_url);
- settings.setValue(key + QLatin1String("location"), QFileInfo(m_downloads[i].m_output).filePath());
- settings.setValue(key + QLatin1String("done"), m_downloads[i].downloadedSuccessfully());
+ for (int i = 0; i < m_downloads.length; ++i) {
+ string key = Format(QLatin1String("download_{}_"), i);
+ settings.setValue(key ~ QLatin1String("url"), m_downloads[i].m_url);
+ settings.setValue(key ~ QLatin1String("location"), (new QFileInfo(m_downloads[i].m_output)).filePath());
+ settings.setValue(key ~ QLatin1String("done"), m_downloads[i].downloadedSuccessfully());
}
- int i = m_downloads.count();
- QString key = QString(QLatin1String("download_%1_")).arg(i);
- while (settings.contains(key + QLatin1String("url"))) {
- settings.remove(key + QLatin1String("url"));
- settings.remove(key + QLatin1String("location"));
- settings.remove(key + QLatin1String("done"));
- key = QString(QLatin1String("download_%1_")).arg(++i);
+ int i = m_downloads.length;
+ string key = Format(QLatin1String("download_{}_"), i);
+ while (settings.contains(key ~ QLatin1String("url"))) {
+ settings.remove(key ~ QLatin1String("url"));
+ settings.remove(key ~ QLatin1String("location"));
+ settings.remove(key ~ QLatin1String("done"));
+ key = Format(QLatin1String("download_{}_"), ++i);
}
}
void updateRow()
{
- DownloadItem item = cast(DownloadItem) sender();
+ DownloadItem item = cast(DownloadItem) signalSender();
int row = m_downloads.indexOf(item);
if (-1 == row)
return;
@@ -518,7 +514,7 @@
if (remove)
m_model.removeRow(row);
- cleanupButton.setEnabled(m_downloads.count() - activeDownloads() > 0);
+ cleanupButton.setEnabled(m_downloads.length - activeDownloads() > 0);
}
private:
@@ -526,9 +522,9 @@
void addItem(DownloadItem item)
{
item.statusChanged.connect(&this.updateRow);
- int row = m_downloads.count();
+ int row = m_downloads.length;
m_model.beginInsertRows(QModelIndex(), row, row);
- m_downloads.append(item);
+ m_downloads ~= item;
m_model.endInsertRows();
updateItemCount();
if (row == 0)
@@ -542,8 +538,8 @@
void updateItemCount()
{
- int count = m_downloads.count();
- itemCount.setText(count == 1 ? tr("1 Download") : tr("%1 Downloads").arg(count));
+ int count = m_downloads.length;
+ itemCount.setText(count == 1 ? tr("1 Download") : tr("{} Downloads").arg(count));
}
void load()
@@ -559,15 +555,15 @@
cast(RemovePolicy) removePolicyEnum.keyToValue(value);
int i = 0;
- QString key = QString(QLatin1String("download_%1_")).arg(i);
+ string key = Format(QLatin1String("download_{}_"), i);
while (settings.contains(key + QLatin1String("url"))) {
QUrl url = settings.value(key + QLatin1String("url")).toUrl();
- QString fileName = settings.value(key + QLatin1String("location")).toString();
+ string fileName = settings.value(key + QLatin1String("location")).toString();
bool done = settings.value(key + QLatin1String("done"), true).toBool();
if (!url.isEmpty() && !fileName.isEmpty()) {
DownloadItem item = new DownloadItem(0, this);
item.m_output.setFileName(fileName);
- item.fileNameLabel.setText(QFileInfo(item.m_output.fileName()).fileName());
+ item.fileNameLabel.setText((new QFileInfo(item.m_output.fileName())).fileName());
item.m_url = url;
item.stopButton.setVisible(false);
item.stopButton.setEnabled(false);
@@ -576,9 +572,9 @@
item.progressBar.setVisible(!done);
addItem(item);
}
- key = QString(QLatin1String("download_%1_")).arg(++i);
+ key = Format(QLatin1String("download_{}_"), ++i);
}
- cleanupButton.setEnabled(m_downloads.count() - activeDownloads() > 0);
+ cleanupButton.setEnabled(m_downloads.length - activeDownloads() > 0);
}
AutoSaver m_autoSaver;
@@ -606,14 +602,14 @@
if (index.row() < 0 || index.row() >= rowCount(index.parent()))
return QVariant();
if (role == Qt.ToolTipRole)
- if (!m_downloadManager.m_downloads.at(index.row()).downloadedSuccessfully())
- return m_downloadManager.m_downloads.at(index.row()).downloadInfoLabel.text();
+ if (!m_downloadManager.m_downloads[index.row()].downloadedSuccessfully())
+ return m_downloadManager.m_downloads[index.row()].downloadInfoLabel.text();
return QVariant();
}
int rowCount(QModelIndex parent = QModelIndex())
{
- return (parent.isValid()) ? 0 : m_downloadManager.m_downloads.count();
+ return (parent.isValid()) ? 0 : m_downloadManager.m_downloads.length;
}
bool removeRows(int row, int count, QModelIndex parent = QModelIndex())
@@ -623,8 +619,8 @@
int lastRow = row + count - 1;
for (int i = lastRow; i >= row; --i) {
- if (m_downloadManager.m_downloads.at(i).downloadedSuccessfully()
- || m_downloadManager.m_downloads.at(i).tryAgainButton.isEnabled()) {
+ if (m_downloadManager.m_downloads[i].downloadedSuccessfully()
+ || m_downloadManager.m_downloads[i].tryAgainButton.isEnabled()) {
beginRemoveRows(parent, i, i);
m_downloadManager.m_downloads.takeAt(i).deleteLater();
endRemoveRows();
diff -r 454e4b4beb59 -r 0654fc9bac95 demos/browser/history.d
--- a/demos/browser/history.d Sun May 24 11:24:57 2009 +0000
+++ b/demos/browser/history.d Sun May 24 13:46:32 2009 +0000
@@ -82,7 +82,7 @@
this() {}
- this(QString u, QDateTime d = QDateTime(), QString t = QString())
+ this(string u, QDateTime d = QDateTime(), string t = null)
{
title = t;
url = u;
@@ -102,8 +102,8 @@
return cast(int) (dateTime > other.dateTime);
}
- QString title;
- QString url;
+ string title;
+ string url;
QDateTime dateTime;
}
@@ -147,29 +147,29 @@
m_saveTimer.saveIfNeccessary();
}
- bool historyContains(QString url)
+ bool historyContains(string url)
{
return m_historyFilterModel.historyContains(url);
}
- void addHistoryEntry(QString url)
+ void addHistoryEntry(string url)
{
QUrl cleanUrl(url);
- cleanUrl.setPassword(QString());
- cleanUrl.setHost(cleanUrl.host().toLower());
+ cleanUrl.setPassword(null);
+ cleanUrl.setHost(toLower(cleanUrl.host()));
auto item = new HistoryItem(cleanUrl.toString(), QDateTime.currentDateTime());
addHistoryItem(item);
}
- void updateHistoryItem(QUrl url, QString title)
+ void updateHistoryItem(QUrl url, string title)
{
- for (int i = 0; i < m_history.count(); ++i) {
- if (url == m_history.at(i).url) {
+ for (int i = 0; i < m_history.length; ++i) {
+ if (url == m_history[i].url) {
m_history[i].title = title;
m_saveTimer.changeOccurred();
if (m_lastSavedUrl.isEmpty())
- m_lastSavedUrl = m_history.at(i).url;
- emit entryUpdated(i);
+ m_lastSavedUrl = m_history[i].url;
+ entryUpdated.emit(i);
break;
}
}
@@ -207,10 +207,10 @@
if (loadedAndSorted) {
m_lastSavedUrl = m_history.value(0).url;
} else {
- m_lastSavedUrl = QString();
+ m_lastSavedUrl = null;
m_saveTimer.changeOccurred();
}
- emit historyReset();
+ historyReset.emit();
}
// History manager keeps around these models for use by the completer and other classes
@@ -233,8 +233,8 @@
void clear()
{
- m_history.clear();
- m_lastSavedUrl = QString();
+ m_history = null;
+ m_lastSavedUrl = null;
m_saveTimer.changeOccurred();
m_saveTimer.saveIfNeccessary();
historyReset();
@@ -257,21 +257,21 @@
settings.setValue(QLatin1String("historyLimit"), m_historyLimit);
bool saveAll = m_lastSavedUrl.isEmpty();
- int first = m_history.count() - 1;
+ int first = m_history.length - 1;
if (!saveAll) {
// find the first one to save
- for (int i = 0; i < m_history.count(); ++i) {
- if (m_history.at(i).url == m_lastSavedUrl) {
+ for (int i = 0; i < m_history.length; ++i) {
+ if (m_history[i].url == m_lastSavedUrl) {
first = i - 1;
break;
}
}
}
- if (first == m_history.count() - 1)
+ if (first == m_history.length - 1)
saveAll = true;
- QString directory = QDesktopServices.storageLocation(QDesktopServices.DataLocation);
+ string directory = QDesktopServices.storageLocation(QDesktopServices.DataLocation);
if (directory.isEmpty())
directory = QDir.homePath() + QLatin1String("/.") + QCoreApplication.applicationName();
if (!QFile.exists(directory)) {
@@ -300,7 +300,7 @@
for (int i = first; i >= 0; --i) {
QByteArray data;
auto stream = new QDataStream(data, QIODevice.WriteOnly);
- HistoryItem item = m_history.at(i);
+ HistoryItem item = m_history[i];
stream << HISTORY_VERSION << item.url << item.dateTime << item.title;
out_ << data;
}
@@ -317,13 +317,13 @@
void checkForExpired()
{
- if (m_historyLimit < 0 || m_history.isEmpty())
+ if (m_historyLimit < 0 || m_history.length == 0)
return;
QDateTime now = QDateTime.currentDateTime();
int nextTimeout = 0;
- while (!m_history.isEmpty()) {
+ while (m_history.length) {
QDateTime checkForExpired = m_history.last().dateTime;
checkForExpired.setDate(checkForExpired.date().addDays(m_historyLimit));
if (now.daysTo(checkForExpired) > 7) {
@@ -336,8 +336,8 @@
break;
HistoryItem item = m_history.takeLast();
// remove from saved file also
- m_lastSavedUrl = QString();
- emit entryRemoved(item);
+ m_lastSavedUrl = null;
+ entryRemoved.emit(item);
}
if (nextTimeout > 0)
@@ -352,9 +352,9 @@
if (globalSettings.testAttribute(QWebSettings.PrivateBrowsingEnabled))
return;
- m_history.prepend(item);
- emit entryAdded(item);
- if (m_history.count() == 1)
+ m_history = [item] ~ m_history;
+ entryAdded.emit(item);
+ if (m_history.length == 1)
checkForExpired();
}
@@ -364,7 +364,7 @@
{
loadSettings();
- historyFile = new QFile(QDesktopServices.storageLocation(QDesktopServices.DataLocation) + QLatin1String("/history"));
+ historyFile = new QFile(QDesktopServices.storageLocation(QDesktopServices.DataLocation) ~ QLatin1String("/history"));
if (!historyFile.exists())
return;
if (!historyFile.open(QFile.ReadOnly)) {
@@ -376,21 +376,21 @@
auto in_ = new QDataStream(&historyFile);
// Double check that the history file is sorted as it is read in
bool needToSort = false;
- HistoryItem lastInsertedItem;
- QByteArray data;
- QDataStream stream;
- QBuffer buffer;
+ auto lastInsertedItem = new HistoryItem;
+ auto data = new QByteArray;
+ auto stream = new QDataStream;
+ auto buffer = new QBuffer;
stream.setDevice(buffer);
while (!historyFile.atEnd()) {
in_ >> data;
buffer.close();
buffer.setBuffer(data);
buffer.open(QIODevice.ReadOnly);
- quint32 ver;
+ uint ver;
stream >> ver;
if (ver != HISTORY_VERSION)
continue;
- HistoryItem item;
+ auto item = new HistoryItem;
stream >> item.url;
stream >> item.dateTime;
stream >> item.title;
@@ -418,7 +418,7 @@
// If we had to sort re-write the whole history sorted
if (needToSort) {
- m_lastSavedUrl = QString();
+ m_lastSavedUrl = null;
m_saveTimer.changeOccurred();
}
}
@@ -427,7 +427,7 @@
int m_historyLimit;
QTimer m_expiredTimer;
HistoryItem[] m_history;
- QString m_lastSavedUrl;
+ string m_lastSavedUrl;
HistoryModel m_historyModel;
HistoryFilterModel m_historyFilterModel;
@@ -453,7 +453,7 @@
void entryUpdated(int offset)
{
QModelIndex idx = index(offset, 0);
- emit dataChanged(idx, idx);
+ dataChanged.emit(idx, idx);
}
public:
@@ -491,10 +491,10 @@
QVariant data(QModelIndex index, int role = Qt.DisplayRole)
{
HistoryItem[] lst = m_history.history();
- if (index.row() < 0 || index.row() >= lst.size())
+ if (index.row() < 0 || index.row() >= lst.length)
return QVariant();
- HistoryItem item = lst.at(index.row());
+ HistoryItem item = lst[index.row()];
switch (role) {
case DateTimeRole:
return item.dateTime;
@@ -510,7 +510,7 @@
case 0:
// when there is no title try to generate one from the url
if (item.title.isEmpty()) {
- QString page = QFileInfo(QUrl(item.url).path()).fileName();
+ string page = QFileInfo(QUrl(item.url).path()).fileName();
if (!page.isEmpty())
return page;
return item.url;
@@ -554,8 +554,8 @@
return true;
}
+private:
-private:
HistoryManager m_history;
}
@@ -579,16 +579,16 @@
setSourceModel(sourceModel);
}
- bool historyContains(QString url)
+ bool historyContains(string url)
{
load();
- return m_historyHash.contains(url);
+ return ((url in m_historyHash) != null);
}
- int historyLocation(QString url)
+ int historyLocation(string url)
{
load();
- if (!m_historyHash.contains(url))
+ if (!(url in m_historyHash))
return 0;
return sourceModel().rowCount() - m_historyHash.value(url);
}
@@ -596,8 +596,8 @@
QModelIndex mapFromSource(QModelIndex sourceIndex)
{
load();
- QString url = sourceIndex.data(HistoryModel.UrlStringRole).toString();
- if (!m_historyHash.contains(url))
+ string url = sourceIndex.data(HistoryModel.UrlStringRole).toString();
+ if (!(url in m_historyHash))
return QModelIndex();
// This can be done in a binary search, but we can't use qBinary find
@@ -608,7 +608,7 @@
int sourceModelRow = sourceModel().rowCount() - sourceIndex.row();
for (int i = 0; i < m_sourceRow.count(); ++i) {
- if (m_sourceRow.at(i) == sourceModelRow) {
+ if (m_sourceRow[i] == sourceModelRow) {
realRow = i;
break;
}
@@ -656,7 +656,7 @@
load();
if (parent.isValid())
return 0;
- return m_historyHash.count();
+ return m_historyHash.length;
}
int columnCount(QModelIndex parent = QModelIndex())
@@ -701,7 +701,6 @@
return true;
}
-
QVariant data(QModelIndex index, int role = Qt.DisplayRole)
{
return QAbstractProxyModel.data(index, role);
@@ -722,20 +721,18 @@
void sourceRowsRemoved(QModelIndex , int start, int end)
{
- //Q_UNUSED(start);
- //Q_UNUSED(end);
sourceReset();
}
void sourceRowsInserted(QModelIndex parent, int start, int end)
{
assert(start == end && start == 0);
- //Q_UNUSED(end);
+
if (!m_loaded)
return;
QModelIndex idx = sourceModel().index(start, 0, parent);
- QString url = idx.data(HistoryModel.UrlStringRole).toString();
- if (m_historyHash.contains(url)) {
+ string url = idx.data(HistoryModel.UrlStringRole).toString();
+ if (url in m_historyHash) {
int sourceRow = sourceModel().rowCount() - m_historyHash[url];
int realRow = mapFromSource(sourceModel().index(sourceRow, 0)).row();
beginRemoveRows(QModelIndex(), realRow, realRow);
@@ -744,7 +741,7 @@
endRemoveRows();
}
beginInsertRows(QModelIndex(), 0, 0);
- m_historyHash.insert(url, sourceModel().rowCount() - start);
+ m_historyHash[url] = (sourceModel().rowCount() - start);
m_sourceRow.insert(0, sourceModel().rowCount());
endInsertRows();
}
@@ -755,12 +752,13 @@
if (m_loaded)
return;
m_sourceRow.clear();
- m_historyHash.clear();
- m_historyHash.reserve(sourceModel().rowCount());
+ m_historyHash = null;
+ m_historyHash.length = sourceModel().rowCount();
+ m_historyHash.length = 0;
for (int i = 0; i < sourceModel().rowCount(); ++i) {
QModelIndex idx = sourceModel().index(i, 0);
- QString url = idx.data(HistoryModel.UrlStringRole).toString();
- if (!m_historyHash.contains(url)) {
+ string url = idx.data(HistoryModel.UrlStringRole).toString();
+ if (!(url in m_historyHash)) {
m_sourceRow.append(sourceModel().rowCount() - i);
m_historyHash[url] = sourceModel().rowCount() - i;
}
@@ -769,7 +767,7 @@
}
int[] m_sourceRow;
- int[QString] m_historyHash;
+ int[string] m_historyHash;
bool m_loaded;
}
@@ -923,8 +921,8 @@
void setInitialActions(QAction[] actions)
{
m_initialActions = actions;
- for (int i = 0; i < m_initialActions.count(); ++i)
- addAction(m_initialActions.at(i));
+ for (int i = 0; i < m_initialActions.length; ++i)
+ addAction(m_initialActions[i]);
}
protected:
@@ -937,9 +935,9 @@
setModel(m_historyMenuModel);
}
// initial actions
- for (int i = 0; i < m_initialActions.count(); ++i)
- addAction(m_initialActions.at(i));
- if (!m_initialActions.isEmpty())
+ for (int i = 0; i < m_initialActions.length; ++i)
+ addAction(m_initialActions[i]);
+ if (m_initialActions.length)
addSeparator();
setFirstSeparator(m_historyMenuModel.bumpedRows());
@@ -998,10 +996,10 @@
if (sourceModel() && (role == Qt.EditRole || role == Qt.DisplayRole) && index.isValid()) {
QModelIndex idx = mapToSource(index);
idx = idx.sibling(idx.row(), 1);
- QString urlString = idx.data(HistoryModel.UrlStringRole).toString();
+ string urlString = idx.data(HistoryModel.UrlStringRole).toString();
if (index.row() % 2) {
QUrl url = urlString;
- QString s = url.toString(QUrl.RemoveScheme | QUrl.RemoveUserInfo | QUrl.StripTrailingSlash);
+ string s = url.toString(QUrl.RemoveScheme | QUrl.RemoveUserInfo | QUrl.StripTrailingSlash);
return s.mid(2); // strip // from the front
}
return urlString;
@@ -1100,7 +1098,7 @@
return date.toString(QLatin1String("dddd, MMMM d, yyyy"));
}
if (index.column() == 1) {
- return tr("%1 items").arg(rowCount(index.sibling(index.row(), 0)));
+ return Format(tr("{} items"), rowCount(index.sibling(index.row(), 0)));
}
}
}
@@ -1127,8 +1125,8 @@
// row count OF dates
if (!parent.isValid()) {
- if (!m_sourceRowCache.isEmpty())
- return m_sourceRowCache.count();
+ if (m_sourceRowCache.length)
+ return m_sourceRowCache.length;
QDate currentDate;
int rows = 0;
int totalRows = sourceModel().rowCount();
@@ -1136,12 +1134,12 @@
for (int i = 0; i < totalRows; ++i) {
QDate rowDate = sourceModel().index(i, 0).data(HistoryModel.DateRole).toDate();
if (rowDate != currentDate) {
- m_sourceRowCache.append(i);
+ m_sourceRowCache ~= i;
currentDate = rowDate;
++rows;
}
}
- assert(m_sourceRowCache.count() == rows);
+ assert(m_sourceRowCache.length == rows);
return rows;
}
@@ -1156,7 +1154,7 @@
if (!sourceIndex.isValid())
return QModelIndex();
- if (m_sourceRowCache.isEmpty())
+ if (m_sourceRowCache.length == 0)
rowCount(QModelIndex());
int[].iterator it;
@@ -1164,7 +1162,7 @@
if (*it != sourceIndex.row())
--it;
int dateRow = qMax(0, it - m_sourceRowCache.begin());
- int row = sourceIndex.row() - m_sourceRowCache.at(dateRow);
+ int row = sourceIndex.row() - m_sourceRowCache[dateRow];
return createIndex(row, sourceIndex.column(), dateRow + 1);
}
@@ -1261,21 +1259,20 @@
void sourceReset()
{
- m_sourceRowCache.clear();
+ m_sourceRowCache.length = 0;
reset();
}
void sourceRowsInserted(QModelIndex parent, int start, int end)
{
- //Q_UNUSED(parent); // Avoid warnings when compiling release
assert(!parent.isValid());
if (start != 0 || start != end) {
- m_sourceRowCache.clear();
+ m_sourceRowCache.length = 0;
reset();
return;
}
- m_sourceRowCache.clear();
+ m_sourceRowCache.length = 0;
QModelIndex treeIndex = mapFromSource(sourceModel().index(start, 0));
QModelIndex treeParent = treeIndex.parent();
if (rowCount(treeParent) == 1) {
@@ -1287,18 +1284,17 @@
}
}
- void sourceRowsRemoved(QModelIndex parent, int start, int end);
+ void sourceRowsRemoved(QModelIndex parent, int start, int end)
{
- //Q_UNUSED(parent); // Avoid warnings when compiling release
assert(!parent.isValid());
- if (m_sourceRowCache.isEmpty())
+ if (m_sourceRowCache.length == 0)
return;
for (int i = end; i >= start;) {
int[]::iterator it;
it = qLowerBound(m_sourceRowCache.begin(), m_sourceRowCache.end(), i);
// playing it safe
if (it == m_sourceRowCache.end()) {
- m_sourceRowCache.clear();
+ m_sourceRowCache = null;
reset();
return;
}
@@ -1319,7 +1315,7 @@
++row;
--i;
}
- for (int j = row; j < m_sourceRowCache.count(); ++j)
+ for (int j = row; j < m_sourceRowCache.length; ++j)
--m_sourceRowCache[j];
endRemoveRows();
}
@@ -1333,15 +1329,15 @@
if (row <= 0)
return 0;
- if (m_sourceRowCache.isEmpty())
+ if (m_sourceRowCache.length == 0)
rowCount(QModelIndex());
- if (row >= m_sourceRowCache.count()) {
+ if (row >= m_sourceRowCache.length) {
if (!sourceModel())
return 0;
return sourceModel().rowCount();
}
- return m_sourceRowCache.at(row);
+ return m_sourceRowCache[row];
}
int[] m_sourceRowCache;
@@ -1362,7 +1358,8 @@
setFilterCaseSensitivity(Qt.CaseInsensitive);
}
- protected:
+protected:
+
bool filterAcceptsRow(int source_row, QModelIndex source_parent)
{
if (!source_parent.isValid())
@@ -1392,7 +1389,7 @@
tree.setTextElideMode(Qt.ElideMiddle);
auto model = history.historyTreeModel();
auto proxyModel = new TreeProxyModel(this);
- search.textChanged(QString).connect(&proxyModel.setFilterFixedString(QString));
+ search.textChanged.connect(&proxyModel.setFilterFixedString);
removeButton.clicked.connect(&tree.removeOne);
removeAllButton.clicked.connect(&history.clear);
proxyModel.setSourceModel(model);
@@ -1412,7 +1409,7 @@
void customContextMenuRequested(QPoint pos)
{
- QMenu menu;
+ auto menu = new QMenu;
QModelIndex index = tree.indexAt(pos);
index = index.sibling(index.row(), 0);
if (index.isValid() && !tree.model().hasChildren(index)) {
@@ -1429,7 +1426,7 @@
QModelIndex index = tree.currentIndex();
if (!index.parent().isValid())
return;
- emit openUrl(index.data(HistoryModel.UrlRole).toUrl());
+ openUrl.emit(index.data(HistoryModel.UrlRole).toUrl());
}
void copy()
@@ -1437,7 +1434,7 @@
QModelIndex index = tree.currentIndex();
if (!index.parent().isValid())
return;
- QString url = index.data(HistoryModel.UrlStringRole).toString();
+ string url = index.data(HistoryModel.UrlStringRole).toString();
QClipboard clipboard = QApplication.clipboard();
clipboard.setText(url);
diff -r 454e4b4beb59 -r 0654fc9bac95 demos/browser/main.d
--- a/demos/browser/main.d Sun May 24 11:24:57 2009 +0000
+++ b/demos/browser/main.d Sun May 24 13:46:32 2009 +0000
@@ -38,13 +38,14 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+
module main;
import browserapplication;
-int main(char[][] args)
+int main(string[] args)
{
//Q_INIT_RESOURCE(data);
scope application = new BrowserApplication(args);
diff -r 454e4b4beb59 -r 0654fc9bac95 demos/browser/modelmenu.d
--- a/demos/browser/modelmenu.d Sun May 24 11:24:57 2009 +0000
+++ b/demos/browser/modelmenu.d Sun May 24 13:46:32 2009 +0000
@@ -41,7 +41,7 @@
module modelmenu;
-import qt.gui.QMenu
+import qt.gui.QMenu;
import qt.core.QAbstractItemModel;
import qt.core.QAbstractItemModel;
@@ -51,9 +51,9 @@
// A QMenu that is dynamically populated from a QAbstractItemModel
class ModelMenu : public QMenu
{
-
+
mixin Signal!("activated", QModelIndex /*index*/);
-mixin Signal!("hovered", QString /*text*/);
+mixin Signal!("hovered", string /*text*/);
public:
@@ -129,12 +129,12 @@
return m_separatorRole;
}
- QAction makeAction(QIcon icon, QString text, QObject parent)
+ QAction makeAction(QIcon icon, string text, QObject parent)
{
auto fm = new QFontMetrics(font());
if (-1 == m_maxWidth)
m_maxWidth = fm.width(QLatin1Char('m')) * 30;
- QString smallText = fm.elidedText(text, Qt.ElideMiddle, m_maxWidth);
+ string smallText = fm.elidedText(text, Qt.ElideMiddle, m_maxWidth);
return new QAction(icon, smallText, parent);
}
@@ -155,9 +155,9 @@
void createMenu(QModelIndex parent, int max, QMenu parentMenu = null, QMenu menu = null)
{
if (!menu) {
- QString title = parent.data().toString();
+ string title = parent.data().toString();
menu = new QMenu(title, this);
- QIcon icon = qvariant_cast(parent.data(Qt.DecorationRole));
+ QIcon icon = cast(QIcon) parent.data(Qt.DecorationRole);
menu.setIcon(icon);
parentMenu.addMenu(menu);
QVariant v;
@@ -193,10 +193,10 @@
void aboutToShow()
{
- if (QMenu menu = qobject_cast(sender())) {
+ if (QMenu menu = cast(QMenu) signalSender()) {
QVariant v = menu.menuAction().data();
- if (v.canConvert()) {
- QModelIndex idx = qvariant_cast(v);
+ if (v.canConvert!(QModelIndex)()) {
+ QModelIndex idx = cast(QModelIndex) v;
createMenu(idx, -1, menu, menu);
menu.aboutToShow.disconnect(&this.aboutToShow);
return;
@@ -216,20 +216,20 @@
void triggered(QAction action)
{
QVariant v = action.data();
- if (v.canConvert()) {
- QModelIndex idx = qvariant_cast(v);
- emit activated(idx);
+ if (v.canConvert!(QModelIndex)()) {
+ QModelIndex idx = cast(QModelIndex) v;
+ activated.emit(idx);
}
}
void hovered(QAction action)
{
QVariant v = action.data();
- if (v.canConvert()) {
- QModelIndex idx = qvariant_cast(v);
- QString hoveredString = idx.data(m_hoverRole).toString();
+ if (v.canConvert!(QModelIndex)()) {
+ QModelIndex idx = cast(QModelIndex) v;
+ string hoveredString = idx.data(m_hoverRole).toString();
if (!hoveredString.isEmpty())
- emit hovered(hoveredString);
+ hovered.emit(hoveredString);
}
}
diff -r 454e4b4beb59 -r 0654fc9bac95 demos/browser/networkaccessmanager.d
--- a/demos/browser/networkaccessmanager.d Sun May 24 11:24:57 2009 +0000
+++ b/demos/browser/networkaccessmanager.d Sun May 24 13:46:32 2009 +0000
@@ -80,20 +80,20 @@
loadSettings();
QNetworkDiskCache diskCache = new QNetworkDiskCache(this);
- QString location = QDesktopServices.storageLocation(QDesktopServices.CacheLocation);
+ string location = QDesktopServices.storageLocation(QDesktopServices.CacheLocation);
diskCache.setCacheDirectory(location);
setCache(diskCache);
}
private:
- QString[] sslTrustedHostList;
+ string[] sslTrustedHostList;
public:
void loadSettings()
{
- QSettings settings;
+ auto settings = new QSettings;
settings.beginGroup(QLatin1String("proxy"));
QNetworkProxy proxy;
if (settings.value(QLatin1String("enabled"), false).toBool()) {
@@ -115,17 +115,16 @@
{
BrowserMainWindow mainWindow = BrowserApplication.instance().mainWindow();
- QDialog dialog(mainWindow);
+ auto dialog = new QDialog(mainWindow);
dialog.setWindowFlags(Qt.Sheet);
- Ui.PasswordDialog passwordDialog;
+ auto passwordDialog = new Ui.PasswordDialog;
passwordDialog.setupUi(&dialog);
- passwordDialog.iconLabel.setText(QString());
+ passwordDialog.iconLabel.setText(null);
passwordDialog.iconLabel.setPixmap(mainWindow.style().standardIcon(QStyle.SP_MessageBoxQuestion, 0, mainWindow).pixmap(32, 32));
- QString introMessage = tr("Enter username and password for \"%1\" at %2");
- introMessage = introMessage.arg(Qt.escape(reply.url().toString())).arg(Qt.escape(reply.url().toString()));
+ string introMessage = Format(tr("Enter username and password for \"{}\" at {}"), Qt.escape(reply.url().toString()), Qt.escape(reply.url().toString()));
passwordDialog.introLabel.setText(introMessage);
passwordDialog.introLabel.setWordWrap(true);
@@ -135,21 +134,20 @@
}
}
- void proxyAuthenticationRequired(const QNetworkProxy proxy, QAuthenticator auth)
+ void proxyAuthenticationRequired(QNetworkProxy proxy, QAuthenticator auth)
{
BrowserMainWindow mainWindow = BrowserApplication.instance().mainWindow();
- QDialog dialog(mainWindow);
+ auto dialog = new QDialog(mainWindow);
dialog.setWindowFlags(Qt.Sheet);
- Ui.ProxyDialog proxyDialog;
+ auto proxyDialog = new Ui.ProxyDialog;
proxyDialog.setupUi(&dialog);
- proxyDialog.iconLabel.setText(QString());
+ proxyDialog.iconLabel.setText(null);
proxyDialog.iconLabel.setPixmap(mainWindow.style().standardIcon(QStyle.SP_MessageBoxQuestion, 0, mainWindow).pixmap(32, 32));
- QString introMessage = tr("Connect to proxy \"%1\" using:");
- introMessage = introMessage.arg(Qt.escape(proxy.hostName()));
+ string introMessage = Format(tr("Connect to proxy \"{}\" using:"), Qt.escape(proxy.hostName()));
proxyDialog.introLabel.setText(introMessage);
proxyDialog.introLabel.setWordWrap(true);
@@ -164,17 +162,17 @@
void sslErrors(QNetworkReply reply, QSslError[] error)
{
// check if SSL certificate has been trusted already
- QString replyHost = reply.url().host() ~ ":" ~ reply.url().port();
+ string replyHost = reply.url().host() ~ ":" ~ reply.url().port();
if(! sslTrustedHostList.contains(replyHost)) {
BrowserMainWindow mainWindow = BrowserApplication.instance().mainWindow();
- QStringList errorStrings;
+ string[] errorStrings;
for (int i = 0; i < error.count(); ++i)
- errorStrings += error.at(i).errorString();
- QString errors = errorStrings.join(QLatin1String("\n"));
+ errorStrings += error[i].errorString();
+ string errors = errorStrings ~ QLatin1String("\n"));
int ret = QMessageBox.warning(mainWindow, QCoreApplication.applicationName(),
- tr("SSL Errors:\n\n%1\n\n%2\n\n"
- "Do you want to ignore these errors for this host?").arg(reply.url().toString()).arg(errors),
+ Format(tr("SSL Errors:\n\n{}\n\n{}\n\n"
+ "Do you want to ignore these errors for this host?"), reply.url().toString(), errors),
QMessageBox.Yes | QMessageBox.No, QMessageBox.No);
if (ret == QMessageBox.Yes) {
reply.ignoreSslErrors();
diff -r 454e4b4beb59 -r 0654fc9bac95 demos/browser/searchlineedit.d
--- a/demos/browser/searchlineedit.d Sun May 24 11:24:57 2009 +0000
+++ b/demos/browser/searchlineedit.d Sun May 24 13:46:32 2009 +0000
@@ -73,8 +73,7 @@
void paintEvent(QPaintEvent event)
{
- //Q_UNUSED(event);
- QPainter painter(this);
+ auto painter = new QPainter(this);
int height = this.height();
painter.setRenderHint(QPainter.Antialiasing, true);
@@ -92,7 +91,7 @@
painter.drawLine(border, height - border, width() - border, border);
}
- void textChanged(QString text)
+ void textChanged(string text)
{
setVisible(!text.isEmpty());
}
@@ -106,7 +105,7 @@
{
public:
- SearchButton(QWidget parent = null)
+ this(QWidget parent = null)
{
super(parent);
m_menu = 0;
@@ -117,19 +116,18 @@
void paintEvent(QPaintEvent event)
{
- //Q_UNUSED(event);
QPainterPath myPath;
int radius = (height() / 5) * 2;
- QRect circle(height() / 3 - 1, height() / 4, radius, radius);
+ QRect circle = QRect(height() / 3 - 1, height() / 4, radius, radius);
myPath.addEllipse(circle);
myPath.arcMoveTo(circle, 300);
QPointF c = myPath.currentPosition();
int diff = height() / 7;
- myPath.lineTo(qMin(width() - 2, (int)c.x() + diff), c.y() + diff);
+ myPath.lineTo(qMin(width() - 2, cast(int) c.x() + diff), c.y() + diff);
- QPainter painter(this);
+ auto painter = new QPainter(this);
painter.setRenderHint(QPainter.Antialiasing, true);
painter.setPen(QPen(Qt.darkGray, 2));
painter.drawPath(myPath);
@@ -171,7 +169,7 @@
class SearchLineEdit : public ExLineEdit
{
- mixin Signal!("textChanged", QString /*text*/);
+ mixin Signal!("textChanged", string /*text*/);
public:
@@ -193,12 +191,12 @@
setSizePolicy(QSizePolicy.Preferred, policy.verticalPolicy());
}
- QString inactiveText()
+ string inactiveText()
{
return m_inactiveText;
}
- void setInactiveText(QString text)
+ void setInactiveText(string text)
{
m_inactiveText = text;
}
@@ -208,7 +206,7 @@
if (!m_searchButton.m_menu) {
m_searchButton.m_menu = new QMenu(m_searchButton);
if (isVisible())
- (const_cast(this)).updateGeometries();
+ (cast(SearchLineEdit) this).updateGeometries();
}
return m_searchButton.m_menu;
}
@@ -238,8 +236,8 @@
QRect r = style().subElementRect(QStyle.SE_LineEditContents, &panel, this);
QFontMetrics fm = fontMetrics();
int horizontalMargin = lineEdit().x();
- QRect lineRect(horizontalMargin + r.x(), r.y() + (r.height() - fm.height() + 1) / 2, r.width() - 2 * horizontalMargin, fm.height());
- QPainter painter(this);
+ QRect lineRect = QRect(horizontalMargin + r.x(), r.y() + (r.height() - fm.height() + 1) / 2, r.width() - 2 * horizontalMargin, fm.height());
+ QPainter painter = new QPainter(this);
painter.setPen(palette().brush(QPalette.Disabled, QPalette.Text).color());
painter.drawText(lineRect, Qt.AlignLeft|Qt.AlignVCenter, m_inactiveText);
} else {
@@ -259,5 +257,5 @@
}
SearchButton m_searchButton;
- QString m_inactiveText;
+ string m_inactiveText;
}
diff -r 454e4b4beb59 -r 0654fc9bac95 demos/browser/settings.d
--- a/demos/browser/settings.d Sun May 24 11:24:57 2009 +0000
+++ b/demos/browser/settings.d Sun May 24 13:46:32 2009 +0000
@@ -67,7 +67,7 @@
setupUi(this);
exceptionsButton.clicked.connect(&this.showExceptions);
setHomeToCurrentPageButton.clicked.connect(&this.setHomeToCurrentPage);
- cookiesButton.clicked.connect(&this.showCookies()));
+ cookiesButton.clicked.connect(&this.showCookies());
standardFontButton.clicked.connect(this.chooseFont);
fixedFontButton.clicked.connect(&this.chooseFixedFont);
@@ -75,7 +75,7 @@
loadFromSettings();
}
- void accept();
+ void accept()
{
saveToSettings();
QDialog.accept();
@@ -86,15 +86,15 @@
void loadDefaults()
{
QWebSettings defaultSettings = QWebSettings.globalSettings();
- QString standardFontFamily = defaultSettings.fontFamily(QWebSettings.StandardFont);
+ string 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()));
+ standardLabel.setText(Format(QLatin1String("{} {}"), standardFont.family(), standardFont.pointSize()));
- QString fixedFontFamily = defaultSettings.fontFamily(QWebSettings.FixedFont);
+ string 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()));
+ fixedLabel.setText(Format(QLatin1String("{} {}"), fixedFont.family(), fixedFont.pointSize()));
downloadsLocation.setText(QDesktopServices.storageLocation(QDesktopServices.DesktopLocation));
@@ -104,9 +104,9 @@
void loadFromSettings()
{
- QSettings settings;
+ auto settings = new QSettings;
settings.beginGroup(QLatin1String("MainWindow"));
- QString defaultHome = QLatin1String("http://qtsoftware.com");
+ string defaultHome = QLatin1String("http://qtsoftware.com");
homeLineEdit.setText(settings.value(QLatin1String("home"), defaultHome).toString());
settings.endGroup();
@@ -127,7 +127,7 @@
settings.endGroup();
settings.beginGroup(QLatin1String("downloadmanager"));
- QString downloadDirectory = settings.value(QLatin1String("downloadDirectory"), downloadsLocation.text()).toString();
+ string downloadDirectory = settings.value(QLatin1String("downloadDirectory"), downloadsLocation.text()).toString();
downloadsLocation.setText(downloadDirectory);
settings.endGroup();
@@ -141,8 +141,8 @@
fixedFont = qVariantValue(settings.value(QLatin1String("fixedFont"), fixedFont));
standardFont = qVariantValue(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()));
+ standardLabel.setText(Format(QLatin1String("{} {}"), standardFont.family(), standardFont.pointSize()));
+ fixedLabel.setText(Format(QLatin1String("{} {}"), fixedFont.family(), fixedFont.pointSize()));
enableJavascript.setChecked(settings.value(QLatin1String("enableJavascript"), enableJavascript.isChecked()).toBool());
enablePlugins.setChecked(settings.value(QLatin1String("enablePlugins"), enablePlugins.isChecked()).toBool());
@@ -228,7 +228,7 @@
settings.setValue(QLatin1String("standardFont"), standardFont);
settings.setValue(QLatin1String("enableJavascript"), enableJavascript.isChecked());
settings.setValue(QLatin1String("enablePlugins"), enablePlugins.isChecked());
- QString userStyleSheetString = userStyleSheet.text();
+ string userStyleSheetString = userStyleSheet.text();
if (QFile.exists(userStyleSheetString))
settings.setValue(QLatin1String("userStyleSheet"), QUrl.fromLocalFile(userStyleSheetString));
else
@@ -316,7 +316,7 @@
QFont font = QFontDialog.getFont(&ok, standardFont, this);
if ( ok ) {
standardFont = font;
- standardLabel.setText(QString(QLatin1String("%1 %2")).arg(font.family()).arg(font.pointSize()));
+ standardLabel.setText(Format(QLatin1String("{} {}"), font.family(), font.pointSize()));
}
}
@@ -326,7 +326,7 @@
QFont font = QFontDialog.getFont(&ok, fixedFont, this);
if ( ok ) {
fixedFont = font;
- fixedLabel.setText(QString(QLatin1String("%1 %2")).arg(font.family()).arg(font.pointSize()));
+ fixedLabel.setText(Format(QLatin1String("{} {}"), font.family(), font.pointSize()));
}
}
diff -r 454e4b4beb59 -r 0654fc9bac95 demos/browser/squeezelabel.d
--- a/demos/browser/squeezelabel.d Sun May 24 11:24:57 2009 +0000
+++ b/demos/browser/squeezelabel.d Sun May 24 13:46:32 2009 +0000
@@ -59,8 +59,8 @@
{
QFontMetrics fm = fontMetrics();
if (fm.width(text()) > contentsRect().width()) {
- QString elided = fm.elidedText(text(), Qt.ElideMiddle, width());
- QString oldText = text();
+ string elided = fm.elidedText(text(), Qt.ElideMiddle, width());
+ string oldText = text();
setText(elided);
QLabel.paintEvent(event);
setText(oldText);
diff -r 454e4b4beb59 -r 0654fc9bac95 demos/browser/tabwidget.d
--- a/demos/browser/tabwidget.d Sun May 24 11:24:57 2009 +0000
+++ b/demos/browser/tabwidget.d Sun May 24 13:46:32 2009 +0000
@@ -83,13 +83,13 @@
setAcceptDrops(true);
this.customContextMenuRequested.connect(&this.contextMenuRequested);
- QString alt = QLatin1String("Alt+%1");
+ string alt = QLatin1String("Alt+%1");
for (int i = 1; i <= 10; ++i) {
int key = i;
if (key == 10)
key = 0;
QShortcut shortCut = new QShortcut(alt.arg(key), this);
- m_tabShortcuts.append(shortCut);
+ m_tabShortcuts ~= shortCut;
shortCut.activated.connect(&this.selectTabAction);
}
setTabsClosable(true);
@@ -115,10 +115,10 @@
if ((event.pos() - m_dragStartPos).manhattanLength() > QApplication.startDragDistance() && diffX < 3 && diffX > -3 && diffY < -10) {
QDrag drag = new QDrag(this);
QMimeData mimeData = new QMimeData;
- QList urls;
+ QUrl[] urls;
int index = tabAt(event.pos());
QUrl url = tabData(index).toUrl();
- urls.append(url);
+ urls ~= url;
mimeData.setUrls(urls);
mimeData.setText(tabText(index));
mimeData.setData(QLatin1String("action"), "tab-reordering");
@@ -133,7 +133,7 @@
void selectTabAction()
{
- if (QShortcut shortCut = qobject_cast(sender())) {
+ if (QShortcut shortCut = cast(QShortcut) signalSender()) {
int index = m_tabShortcuts.indexOf(shortCut);
if (index == 0)
index = 10;
@@ -143,33 +143,33 @@
void cloneTab()
{
- if (QAction action = qobject_cast(sender())) {
+ if (QAction action = cast(QAction) signalSender()) {
int index = action.data().toInt();
- emit cloneTab(index);
+ cloneTab.emit(index);
}
}
void closeTab()
{
- if (QAction action = qobject_cast(sender())) {
+ if (QAction action = cast(QAction) signalSender()) {
int index = action.data().toInt();
- emit closeTab(index);
+ closeTab.emit(index);
}
}
void closeOtherTabs()
{
- if (QAction action = qobject_cast(sender())) {
+ if (QAction action = cast(QAction) signalSender()) {
int index = action.data().toInt();
- emit closeOtherTabs(index);
+ closeOtherTabs.emit(index);
}
}
void reloadTab()
{
- if (QAction action = qobject_cast(sender())) {
+ if (QAction action = cast(QAction) signalSender()) {
int index = action.data().toInt();
- emit reloadTab(index);
+ reloadTab.emit(index);
}
}
@@ -278,7 +278,7 @@
void childChanged()
{
- if (QAction source = qobject_cast(sender())) {
+ if (QAction source = cast(QAction) signalSender()) {
if (m_root && m_currentParent && source.parent() == m_currentParent) {
m_root.setChecked(source.isChecked());
m_root.setEnabled(source.isEnabled());
@@ -317,14 +317,14 @@
class TabWidget : public QTabWidget
{
// tab widget signals
- mixin Singal!("loadPage", QString /*url*/);
+ mixin Singal!("loadPage", string /*url*/);
mixin Singal!("tabsChanged");
mixin Singal!("lastTabClosed");
// current tab signals
- mixin Singal!("setCurrentTitle", QString /*url*/);
- mixin Singal!("showStatusBarMessage", QString /*message*/);
- mixin Singal!("linkHovered", QString /*link*/);
+ mixin Singal!("setCurrentTitle", string /*url*/);
+ mixin Singal!("showStatusBarMessage", string /*message*/);
+ mixin Singal!("linkHovered", string /*link*/);
mixin Singal!("loadProgress", int /*progress*/);
mixin Singal!("geometryChangeRequested", QRect /*geometry*/);
mixin Singal!("menuBarVisibilityChangeRequested", bool /*visible*/);
@@ -336,7 +336,7 @@
this(QWidget parent = null)
{
- QTabWidget(parent)
+ super(parent);
m_recentlyClosedTabsAction = 0;
m_newTabAction = 0;
m_closeTabAction = 0;
@@ -350,12 +350,12 @@
setElideMode(Qt.ElideRight);
m_tabBar.newTab.connect(&this.newTab);
- m_tabBar.closeTab.connect(&this.closeTab(int)));
- m_tabBar.cloneTab.connect(&this.cloneTab(int)));
- m_tabBar.closeOtherTabs.connect(&this.closeOtherTabs(int)));
- m_tabBar.reloadTab.connect(&this.reloadTab(int)));
- m_tabBar.reloadAllTabs.connect(&this.reloadAllTabs()));
- m_tabBar.tabMoved.connect(&this.moveTab(int, int)));
+ m_tabBar.closeTab.connect(&this.closeTab);
+ m_tabBar.cloneTab.connect(&this.cloneTab);
+ m_tabBar.closeOtherTabs.connect(&this.closeOtherTabs);
+ m_tabBar.reloadTab.connect(&this.reloadTab);
+ m_tabBar.reloadAllTabs.connect(&this.reloadAllTabs);
+ m_tabBar.tabMoved.connect(&this.moveTab);
setTabBar(m_tabBar);
setDocumentMode(true);
@@ -371,20 +371,20 @@
m_closeTabAction.triggered.connect(&this.closeTab);
m_nextTabAction = new QAction(tr("Show Next Tab"), this);
- QList shortcuts;
- shortcuts.append(QKeySequence(Qt.CTRL | Qt.Key_BraceRight));
- shortcuts.append(QKeySequence(Qt.CTRL | Qt.Key_PageDown));
- shortcuts.append(QKeySequence(Qt.CTRL | Qt.Key_BracketRight));
- shortcuts.append(QKeySequence(Qt.CTRL | Qt.Key_Less));
+ QKeySequence[] shortcuts;
+ shortcuts ~= QKeySequence(Qt.CTRL | Qt.Key_BraceRight);
+ shortcuts ~= QKeySequence(Qt.CTRL | Qt.Key_PageDown);
+ shortcuts ~= QKeySequence(Qt.CTRL | Qt.Key_BracketRight);
+ shortcuts ~= QKeySequence(Qt.CTRL | Qt.Key_Less);
m_nextTabAction.setShortcuts(shortcuts);
m_nextTabAction.triggered.connect(&this.nextTab);
m_previousTabAction = new QAction(tr("Show Previous Tab"), this);
shortcuts.clear();
- shortcuts.append(QKeySequence(Qt.CTRL | Qt.Key_BraceLeft));
- shortcuts.append(QKeySequence(Qt.CTRL | Qt.Key_PageUp));
- shortcuts.append(QKeySequence(Qt.CTRL | Qt.Key_BracketLeft));
- shortcuts.append(QKeySequence(Qt.CTRL | Qt.Key_Greater));
+ shortcuts ~= QKeySequence(Qt.CTRL | Qt.Key_BraceLeft);
+ shortcuts ~= QKeySequence(Qt.CTRL | Qt.Key_PageUp);
+ shortcuts ~= QKeySequence(Qt.CTRL | Qt.Key_BracketLeft);
+ shortcuts ~= QKeySequence(Qt.CTRL | Qt.Key_Greater);
m_previousTabAction.setShortcuts(shortcuts);
m_previousTabAction.triggered.connect(&this.previousTab);
@@ -403,7 +403,7 @@
void clear()
{
// clear the recently closed tabs
- m_recentlyClosedTabs.clear();
+ m_recentlyClosedTabs.length = 0;
// clear the line edit history
for (int i = 0; i < m_lineEdits.count(); ++i) {
QLineEdit qLineEdit = lineEdit(i);
@@ -466,7 +466,7 @@
} else {
// optimization to delay creating the first webview
if (count() == 1) {
- TabWidget that = const_cast(this);
+ TabWidget that = cast(TabWidget) this;
that.setUpdatesEnabled(false);
that.newTab();
that.closeTab(0);
@@ -479,7 +479,7 @@
QLineEdit lineEdit(int index)
{
- UrlLineEdit urlLineEdit = qobject_cast(m_lineEdits.widget(index));
+ UrlLineEdit urlLineEdit = cast(UrlLineEdit) m_lineEdits.widget(index);
if (urlLineEdit)
return urlLineEdit.lineEdit();
return 0;
@@ -492,23 +492,23 @@
}
-static const qint32 TabWidgetMagic = 0xaa;
+static const int TabWidgetMagic = 0xaa;
QByteArray saveState()
{
- int version = 1;
+ int version_ = 1;
QByteArray data;
QDataStream stream(data, QIODevice.WriteOnly);
- stream << qint32(TabWidgetMagic);
- stream << qint32(version);
+ stream << cast(int) TabWidgetMagic;
+ stream << cast(int) version_;
- QStringList tabs;
+ string[] tabs;
for (int i = 0; i < count(); ++i) {
- if (WebView tab = cast(WebView) widget(i))) {
+ if (WebView tab = cast(WebView) widget(i)) {
tabs.append(tab.url().toString());
} else {
- tabs.append(QString.null);
+ tabs.append(null); //QString.null);
}
}
stream << tabs;
@@ -524,20 +524,20 @@
if (stream.atEnd())
return false;
- qint32 marker;
- qint32 v;
+ int marker;
+ int v;
stream >> marker;
stream >> v;
if (marker != TabWidgetMagic || v != version_)
return false;
- QStringList openTabs;
+ string[] openTabs;
stream >> openTabs;
- for (int i = 0; i < openTabs.count(); ++i) {
+ for (int i = 0; i < openTabs.length; ++i) {
if (i != 0)
newTab();
- loadPage(openTabs.at(i));
+ loadPage(openTabs[i]);
}
int currentTab;
@@ -575,7 +575,7 @@
if (event.button() == Qt.MidButton && !childAt(event.pos())
// Remove the line below when QTabWidget does not have a one pixel frame
&& event.pos().y() < (tabBar().y() + tabBar().height())) {
- QUrl url(QApplication.clipboard().text(QClipboard.Selection));
+ auto url = new QUrl(QApplication.clipboard().text(QClipboard.Selection));
if (!url.isEmpty() && url.isValid() && !url.scheme().isEmpty()) {
WebView webView = newTab();
webView.setUrl(url);
@@ -605,7 +605,7 @@
m_lineEditCompleter = new QCompleter(completionModel, this);
// Should this be in Qt by default?
QAbstractItemView popup = m_lineEditCompleter.popup();
- QListView listView = qobject_cast(popup);
+ QListView listView = cast(QListView) popup;
if (listView)
listView.setUniformItemSizes(true);
}
@@ -653,7 +653,7 @@
if (count() == 1)
currentChanged(currentIndex());
- emit tabsChanged();
+ tabsChanged.emit();
return webView;
}
@@ -694,8 +694,8 @@
hasFocus = tab.hasFocus();
m_recentlyClosedTabsAction.setEnabled(true);
- m_recentlyClosedTabs.prepend(tab.url());
- if (m_recentlyClosedTabs.size() >= TabWidget.m_recentlyClosedTabsSize)
+ m_recentlyClosedTabs = [tab.url()] ~ m_recentlyClosedTabs;
+ if (m_recentlyClosedTabs.length >= TabWidget.m_recentlyClosedTabsSize)
m_recentlyClosedTabs.removeLast();
}
QWidget lineEdit = m_lineEdits.widget(index);
@@ -704,11 +704,11 @@
QWidget webView = widget(index);
removeTab(index);
webView.deleteLater();
- emit tabsChanged();
+ tabsChanged.emit();
if (hasFocus && count() > 0)
currentWebView().setFocus();
if (count() == 0)
- emit lastTabClosed();
+ lastTabClosed.emit();
}
void closeOtherTabs(int index)
@@ -785,10 +785,10 @@
WebActionMapper mapper = m_actions[i];
mapper.updateCurrent(webView.page());
}
- emit setCurrentTitle(webView.title());
+ setCurrentTitle.emit(webView.title());
m_lineEdits.setCurrentIndex(index);
- emit loadProgress(webView.progress());
- emit showStatusBarMessage(webView.lastStatusBarText());
+ loadProgress.emit(webView.progress());
+ showStatusBarMessage.emit(webView.lastStatusBarText());
if (webView.url().isEmpty())
m_lineEdits.currentWidget().setFocus();
else
@@ -798,12 +798,12 @@
void aboutToShowRecentTabsMenu()
{
m_recentlyClosedTabsMenu.clear();
- for (int i = 0; i < m_recentlyClosedTabs.count(); ++i) {
+ for (int i = 0; i < m_recentlyClosedTabs.length; ++i) {
QAction action = new QAction(m_recentlyClosedTabsMenu);
- action.setData(m_recentlyClosedTabs.at(i));
- QIcon icon = BrowserApplication.instance().icon(m_recentlyClosedTabs.at(i));
+ action.setData(m_recentlyClosedTabs[i]);
+ QIcon icon = BrowserApplication.instance().icon(m_recentlyClosedTabs[i]);
action.setIcon(icon);
- action.setText(m_recentlyClosedTabs.at(i).toString());
+ action.setText(m_recentlyClosedTabs[i].toString());
m_recentlyClosedTabsMenu.addAction(action);
}
}
@@ -816,17 +816,17 @@
void webViewLoadStarted()
{
- WebView webView = cast(WebView) sender();
+ WebView webView = cast(WebView) signalSender();
int index = webViewIndex(webView);
if (-1 != index) {
- QIcon icon(QLatin1String(":loading.gif"));
+ auto icon = new QIcon(QLatin1String(":loading.gif"));
setTabIcon(index, icon);
}
}
void webViewIconChanged()
{
- WebView webView = cast(WebView) sender();
+ WebView webView = cast(WebView) signalSender();
int index = webViewIndex(webView);
if (-1 != index) {
QIcon icon = BrowserApplication.instance().icon(webView.url());
@@ -834,32 +834,32 @@
}
}
- void webViewTitleChanged(QString title)
+ void webViewTitleChanged(string title)
{
- WebView webView = cast(WebView) sender();
+ WebView webView = cast(WebView) signalSender();
int index = webViewIndex(webView);
if (-1 != index) {
setTabText(index, title);
}
if (currentIndex() == index)
- emit setCurrentTitle(title);
+ setCurrentTitle.emit(title);
BrowserApplication.historyManager().updateHistoryItem(webView.url(), title);
}
void webViewUrlChanged(QUrl url)
{
- WebView webView = cast(WebView) sender();
+ WebView webView = cast(WebView) signalSender();
int index = webViewIndex(webView);
if (-1 != index) {
m_tabBar.setTabData(index, url);
}
- emit tabsChanged();
+ tabsChanged.emit();
}
void lineEditReturnPressed()
{
- if (QLineEdit lineEdit = cast(QLineEdit) sender()) {
- emit loadPage(lineEdit.text());
+ if (QLineEdit lineEdit = cast(QLineEdit) signalSender()) {
+ loadPage.emit(lineEdit.text());
if (m_lineEdits.currentWidget() == lineEdit)
currentWebView().setFocus();
}
@@ -867,7 +867,7 @@
void windowCloseRequested()
{
- WebPage webPage = cast(WebPage) sender();
+ WebPage webPage = cast(WebPage) signalSender();
WebView webView = cast(WebView) webPage.view();
int index = webViewIndex(webView);
if (index >= 0) {
diff -r 454e4b4beb59 -r 0654fc9bac95 demos/browser/toolbarsearch.d
--- a/demos/browser/toolbarsearch.d Sun May 24 11:24:57 2009 +0000
+++ b/demos/browser/toolbarsearch.d Sun May 24 13:46:32 2009 +0000
@@ -56,7 +56,7 @@
class ToolbarSearch : public SearchLineEdit
{
- mixin Signal!("search", QUrl /*url*/)
+ mixin Signal!("search", QUrl /*url*/);
public:
@@ -66,7 +66,7 @@
*/
this(QWidget parent = null)
{
- super(parent)
+ super(parent);
m_autosaver = new AutoSaver(this);
m_maxSavedSearches = 10;
m_stringListModel = new QStringListModel(this);
@@ -76,7 +76,7 @@
m.triggered.connect(&this.triggeredMenuAction);
QCompleter completer = new QCompleter(m_stringListModel, this);
- completer.setCompletionMode(QCompleter::InlineCompletion);
+ completer.setCompletionMode(QCompleter.InlineCompletion);
lineEdit().setCompleter(completer);
lineEdit().returnPressed.connect(&searchNow);
@@ -93,32 +93,32 @@
void clear()
{
- m_stringListModel.setStringList(QStringList());
+ m_stringListModel.setStringList(string[]());
m_autosaver.changeOccurred();
}
void searchNow()
{
- QString searchText = lineEdit().text();
- QStringList newList = m_stringListModel.stringList();
+ string searchText = lineEdit().text();
+ string[] newList = m_stringListModel.stringList();
if (newList.contains(searchText))
newList.removeAt(newList.indexOf(searchText));
newList.prepend(searchText);
if (newList.size() >= m_maxSavedSearches)
newList.removeLast();
- QWebSettings globalSettings = QWebSettings::globalSettings();
- if (!globalSettings.testAttribute(QWebSettings::PrivateBrowsingEnabled)) {
+ QWebSettings globalSettings = QWebSettings.globalSettings();
+ if (!globalSettings.testAttribute(QWebSettings.PrivateBrowsingEnabled)) {
m_stringListModel.setStringList(newList);
m_autosaver.changeOccurred();
}
- QUrl url(QLatin1String("http://www.google.com/search"));
+ auto url = new QUrl(QLatin1String("http://www.google.com/search"));
url.addQueryItem(QLatin1String("q"), searchText);
url.addQueryItem(QLatin1String("ie"), QLatin1String("UTF-8"));
url.addQueryItem(QLatin1String("oe"), QLatin1String("UTF-8"));
url.addQueryItem(QLatin1String("client"), QLatin1String("qtdemobrowser"));
- emit search(url);
+ search.emit(url);
}
private:
@@ -138,7 +138,7 @@
lineEdit().selectAll();
QMenu m = menu();
m.clear();
- QStringList list = m_stringListModel.stringList();
+ string[] list = m_stringListModel.stringList();
if (list.isEmpty()) {
m.addAction(tr("No Recent Searches"));
return;
@@ -146,8 +146,8 @@
QAction recent = m.addAction(tr("Recent Searches"));
recent.setEnabled(false);
- for (int i = 0; i < list.count(); ++i) {
- QString text = list.at(i);
+ for (int i = 0; i < list.length; ++i) {
+ string text = list[i];
m.addAction(text).setData(text);
}
m.addSeparator();
@@ -157,8 +157,8 @@
void triggeredMenuAction(QAction action)
{
QVariant v = action.data();
- if (v.canConvert()) {
- QString text = v.toString();
+ if (v.canConvert!(string)()) {
+ string text = v.toString();
lineEdit().setText(text);
searchNow();
}
@@ -170,7 +170,7 @@
{
QSettings settings;
settings.beginGroup(QLatin1String("toolbarsearch"));
- QStringList list = settings.value(QLatin1String("recentSearches")).toStringList();
+ string[] list = settings.value(QLatin1String("recentSearches")).toStringList();
m_maxSavedSearches = settings.value(QLatin1String("maximumSaved"), m_maxSavedSearches).toInt();
m_stringListModel.setStringList(list);
settings.endGroup();
diff -r 454e4b4beb59 -r 0654fc9bac95 demos/browser/urllineedit.d
--- a/demos/browser/urllineedit.d Sun May 24 11:24:57 2009 +0000
+++ b/demos/browser/urllineedit.d Sun May 24 13:46:32 2009 +0000
@@ -254,8 +254,8 @@
QDrag drag = new QDrag(this);
QMimeData mimeData = new QMimeData;
mimeData.setText(QString.fromUtf8(m_webView.url().toEncoded()));
- QList urls;
- urls.append(m_webView.url());
+ QUrl[] urls;
+ urls ~= m_webView.url();
mimeData.setUrls(urls);
drag.setMimeData(mimeData);
drag.exec();
diff -r 454e4b4beb59 -r 0654fc9bac95 demos/browser/webview.d
--- a/demos/browser/webview.d Sun May 24 11:24:57 2009 +0000
+++ b/demos/browser/webview.d Sun May 24 13:46:32 2009 +0000
@@ -80,7 +80,7 @@
{
QObject w = this.parent();
while (w) {
- if (BrowserMainWindow mw = qobject_cast(w))
+ if (BrowserMainWindow mw = cast(BrowserMainWindow) w)
return mw;
w = w.parent();
}
@@ -117,14 +117,13 @@
}
if (frame == mainFrame()) {
m_loadingUrl = request.url();
- emit loadingUrl(m_loadingUrl);
+ loadingUrl.emit(m_loadingUrl);
}
return QWebPage.acceptNavigationRequest(frame, request, type);
}
QWebPage createWindow(QWebPage.WebWindowType type)
{
- //Q_UNUSED(type);
if (m_keyboardModifiers & Qt.ControlModifier || m_pressedButtons == Qt.MidButton)
m_openInNewTab = true;
if (m_openInNewTab) {
@@ -138,12 +137,9 @@
version(QT_NO_UITOOLS) {} else
{
- QObject createPlugin(QString classId, QUrl url, QStringList paramNames, QStringList paramValues);
+ QObject createPlugin(string classId, QUrl url, string[] paramNames, string[] paramValues);
{
- //Q_UNUSED(url);
- //Q_UNUSED(paramNames);
- //Q_UNUSED(paramValues);
- QUiLoader loader;
+ auto loader = new QUiLoader;
return loader.createWidget(classId, view());
}
}
@@ -157,14 +153,14 @@
return;
}
- QFile file(QLatin1String(":/notfound.html"));
+ auto file = new QFile(QLatin1String(":/notfound.html"));
bool isOpened = file.open(QIODevice.ReadOnly);
assert(isOpened);
- QString title = tr("Error loading page: %1").arg(reply.url().toString());
- QString html = QString(QLatin1String(file.readAll()))
- .arg(title)
- .arg(reply.errorString())
- .arg(reply.url().toString());
+ string title = Format(tr("Error loading page: {}"), reply.url().toString());
+ string html = Format(QLatin1String(file.readAll()),
+ title,
+ reply.errorString(),
+ reply.url().toString());
QBuffer imageBuffer;
imageBuffer.open(QBuffer.ReadWrite);
@@ -172,7 +168,7 @@
QPixmap pixmap = icon.pixmap(QSize(32,32));
if (pixmap.save(&imageBuffer, "PNG")) {
html.replace(QLatin1String("IMAGE_BINARY_DATA_HERE"),
- QString(QLatin1String(imageBuffer.buffer().toBase64())));
+ QLatin1String(imageBuffer.buffer().toBase64()));
}
QWebFrame[] frames;
@@ -235,7 +231,7 @@
return m_initialUrl;
}
- QString lastStatusBarText()
+ string lastStatusBarText()
{
return m_statusBarText;
}
@@ -310,9 +306,9 @@
m_progress = 0;
}
- void setStatusBarText(QString string)
+ void setStatusBarText(string str)
{
- m_statusBarText = string;
+ m_statusBarText = str;
}
void downloadRequested(QNetworkRequest request)
@@ -328,7 +324,7 @@
private:
- QString m_statusBarText;
+ string m_statusBarText;
QUrl m_initialUrl;
int m_progress;
WebPage m_page;
diff -r 454e4b4beb59 -r 0654fc9bac95 demos/browser/xbel.d
--- a/demos/browser/xbel.d Sun May 24 11:24:57 2009 +0000
+++ b/demos/browser/xbel.d Sun May 24 13:46:32 2009 +0000
@@ -80,10 +80,10 @@
bool operator==(BookmarkNode other)
{
if (url != other.url || title != other.title || desc != other.desc || expanded != other.expanded
- || m_type != other.m_type || m_children.count() != other.m_children.count())
+ || m_type != other.m_type || m_children.length != other.m_children.length)
return false;
- for (int i = 0; i < m_children.count(); ++i)
+ for (int i = 0; i < m_children.length; ++i)
if (!((*(m_children[i])) == (*(other.m_children[i]))))
return false;
return true;
@@ -104,8 +104,7 @@
return m_children;
}
-
- BookmarkNode parent() const
+ BookmarkNode parent()
{
return m_parent;
}
@@ -117,7 +116,7 @@
child.m_parent.remove(child);
child.m_parent = this;
if (-1 == offset)
- offset = m_children.size();
+ offset = m_children.length;
m_children.insert(offset, child);
}
@@ -127,9 +126,9 @@
m_children.removeAll(child);
}
- QString url;
- QString title;
- QString desc;
+ string url;
+ string title;
+ string desc;
bool expanded;
private:
@@ -147,7 +146,7 @@
{
}
- BookmarkNode read(QString fileName)
+ BookmarkNode read(string fileName)
{
auto file = new QFile(fileName);
if (!file.exists()) {
@@ -164,7 +163,7 @@
while (!atEnd()) {
readNext();
if (isStartElement()) {
- QString version_ = attributes().value(QLatin1String("version")).toString();
+ string version_ = attributes().value(QLatin1String("version")).toString();
if (name() == QLatin1String("xbel") && (version_.isEmpty() || version_ == QLatin1String("1.0"))) {
readXBEL(root);
} else {
@@ -299,9 +298,9 @@
setAutoFormatting(true);
}
- bool write(QString fileName, BookmarkNode root)
+ bool write(string fileName, BookmarkNode root)
{
- QFile file(fileName);
+ auto file = new QFile(fileName);
if (!root || !file.open(QFile.WriteOnly))
return false;
return write(&file, root);
@@ -316,8 +315,8 @@
writeStartElement(QLatin1String("xbel"));
writeAttribute(QLatin1String("version"), QLatin1String("1.0"));
if (root.type() == BookmarkNode.Root) {
- for (int i = 0; i < root.children().count(); ++i)
- writeItem(root.children().at(i));
+ for (int i = 0; i < root.children().length; ++i)
+ writeItem(root.children()[i]);
} else {
writeItem(root);
}
@@ -336,7 +335,7 @@
writeAttribute(QLatin1String("folded"), parent.expanded ? QLatin1String("no") : QLatin1String("yes"));
writeTextElement(QLatin1String("title"), parent.title);
for (int i = 0; i < parent.children().count(); ++i)
- writeItem(parent.children().at(i));
+ writeItem(parent.children()[i]);
writeEndElement();
break;
case BookmarkNode.Bookmark: