summaryrefslogtreecommitdiffstats
path: root/src/core/type_conversion.h
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2021-01-22 10:55:57 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2021-01-25 15:41:53 +0100
commitcde72003881c6b5680ac8ac0fe6d6971bb43e0d5 (patch)
treefcb50002765c1cb179dd6f62054380c3fed85e80 /src/core/type_conversion.h
parent3fb215dab139fd7b61473ce3fe1058b87a6b4fe3 (diff)
parent75d061bbc68875c08b3dc243e464e32a80da71df (diff)
Merge remote-tracking branch 'origin/5.15' into dev
Including update to 87-based Change-Id: I36b6054e00de97ab055d0bc800cff08d0408fac6
Diffstat (limited to 'src/core/type_conversion.h')
-rw-r--r--src/core/type_conversion.h56
1 files changed, 18 insertions, 38 deletions
diff --git a/src/core/type_conversion.h b/src/core/type_conversion.h
index 565d8330a..85fd763b4 100644
--- a/src/core/type_conversion.h
+++ b/src/core/type_conversion.h
@@ -52,7 +52,6 @@
#include <base/strings/nullable_string16.h>
#include "base/files/file_path.h"
#include "base/time/time.h"
-#include "content/public/common/file_chooser_file_info.h"
#include "favicon_manager.h"
#include "net/cookies/canonical_cookie.h"
#include "third_party/blink/public/mojom/favicon/favicon_url.mojom-forward.h"
@@ -87,6 +86,17 @@ inline QString toQt(const base::string16 &string)
#endif
}
+inline QString toQt(const base::Optional<base::string16> &string)
+{
+ if (!string.has_value())
+ return QString();
+#if defined(OS_WIN)
+ return QString::fromStdWString(string->data());
+#else
+ return QString::fromUtf16(string->data());
+#endif
+}
+
inline QString toQString(const std::string &string)
{
return QString::fromStdString(string);
@@ -117,6 +127,13 @@ inline base::NullableString16 toNullableString16(const QString &qString)
return base::NullableString16(toString16(qString), qString.isNull());
}
+inline base::Optional<base::string16> toOptionalString16(const QString &qString)
+{
+ if (qString.isNull())
+ return base::nullopt;
+ return base::make_optional(toString16(qString));
+}
+
inline QUrl toQt(const GURL &url)
{
if (url.is_valid())
@@ -244,43 +261,6 @@ inline base::FilePath toFilePath(const QString &str)
return base::FilePath(toFilePathString(str));
}
-template <typename T>
-inline T fileListingHelper(const QString &)
-// Clang is still picky about this though it should be supported eventually.
-// See http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#941
-#ifndef Q_CC_CLANG
-= delete;
-#else
-{ return T(); }
-#endif
-
-template <>
-inline content::FileChooserFileInfo fileListingHelper<content::FileChooserFileInfo>(const QString &file)
-{
- content::FileChooserFileInfo choose_file;
- base::FilePath fp(toFilePath(file));
- choose_file.file_path = fp;
- choose_file.display_name = fp.BaseName().value();
- return choose_file;
-}
-
-template <>
-inline base::FilePath fileListingHelper<base::FilePath>(const QString &file)
-{
- return base::FilePath(toFilePathString(file));
-}
-
-
-template <typename T>
-inline std::vector<T> toVector(const QStringList &fileList)
-{
- std::vector<T> selectedFiles;
- selectedFiles.reserve(fileList.size());
- for (const QString &file : fileList)
- selectedFiles.push_back(fileListingHelper<T>(file));
- return selectedFiles;
-}
-
int flagsFromModifiers(Qt::KeyboardModifiers modifiers);
inline QStringList fromVector(const std::vector<base::string16> &vector)