diff options
author | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2013-08-19 15:17:56 +0200 |
---|---|---|
committer | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2013-08-20 18:15:57 +0200 |
commit | c1c7c3cfa9d8c3e6f05095d0880a84a13a0d9e01 (patch) | |
tree | 1a77807a994125236fc6631e84cdad83d9e3897e /lib/type_conversion.h | |
parent | abd17e1583e8e13b1a46d599fb695c1189550226 (diff) |
Centralize type conversion functions.
This adds the common GURL->QUrl and string16->QString conversions
into a common header and use those functions throughout the code.
Move the qStringToStringType into the same header and rename it
to a name consistent with the others.
This also cleans up shared_globals.h by moving content:: forward
declarations in the cpp, where they are used.
Change-Id: I19527ea7de1f6047aae8b44c97eb4d7c3e5a0e54
Reviewed-by: Andras Becsi <andras.becsi@digia.com>
Diffstat (limited to 'lib/type_conversion.h')
-rw-r--r-- | lib/type_conversion.h | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/lib/type_conversion.h b/lib/type_conversion.h new file mode 100644 index 000000000..51a543f73 --- /dev/null +++ b/lib/type_conversion.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TYPE_CONVERSION_H +#define TYPE_CONVERSION_H + +#include <QString> +#include <QUrl> +#include "base/files/file_path.h" +#include "url/gurl.h" + +inline QString toQt(const string16 &string) +{ + return QString::fromUtf16(string.data()); +} + +inline QUrl toQt(const GURL &url) +{ + return QUrl(QString::fromStdString(url.spec())); +} + +inline GURL toGurl(const QUrl& url) +{ + return GURL(url.toString().toStdString()); +} + +inline base::FilePath::StringType toFilePathString(const QString &str) +{ +#if defined(OS_POSIX) + return str.toStdString(); +#elif defined(OS_WIN) + return str.toStdWString(); +#endif +} + +#endif // TYPE_CONVERSION_H |