TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicurlutils.cpp
Go to the documentation of this file.
1 #include "musicurlutils.h"
2 #include "ttkplatformsystem.h"
3 
4 #include <QUrl>
5 #include <QProcess>
6 #include <QDesktopServices>
7 #ifdef Q_OS_WIN
8 # define WIN32_LEAN_AND_MEAN
9 # include <qt_windows.h>
10 # include <shellapi.h>
11 #endif
12 
13 bool TTK::Url::execute(const QString &path)
14 {
15 #ifdef Q_OS_WIN
16  ShellExecuteW(0, L"open", path.toStdWString().c_str(), nullptr, nullptr, SW_SHOWNORMAL);
17  return true;
18 #else
19  return QProcess::startDetached(path, {});
20 #endif
21 }
22 
23 bool TTK::Url::openUrl(const QString &path, bool local)
24 {
25  if(path.isEmpty())
26  {
27  return false;
28  }
29 
30  if(local)
31  {
32 #ifdef Q_OS_WIN
33  QString p = path;
34  p.replace(TTK_SEPARATOR, "\\");
35  p = "/select," + p;
36  ShellExecuteW(0, L"open", L"explorer.exe", p.toStdWString().c_str(), nullptr, SW_SHOWNORMAL);
37  return true;
38 #elif defined Q_OS_UNIX
39  TTKPlatformSystem platform;
41  {
42  return QProcess::startDetached("nautilus", {path});
43  }
44 #endif
45  }
46  return QDesktopServices::openUrl(local ? QUrl::fromLocalFile(path) : QUrl(path, QUrl::TolerantMode));
47 }
48 
49 QString TTK::Url::urlEncode(QString &data)
50 {
51  data.replace("+", "%2B");
52  data.replace("/", "%2F");
53  data.replace("=", "%3D");
54  return data;
55 }
56 
57 QString TTK::Url::urlDecode(QString &data)
58 {
59  data.replace("%2B", "+");
60  data.replace("%2F", "/");
61  data.replace("%3D", "=");
62  return data;
63 }
64 
65 QByteArray TTK::Url::urlEncode(QByteArray &data)
66 {
67  data.replace("+", "%2B");
68  data.replace("/", "%2F");
69  data.replace("=", "%3D");
70  return data;
71 }
72 
73 QByteArray TTK::Url::urlDecode(QByteArray &data)
74 {
75  data.replace("%2B", "+");
76  data.replace("%2F", "/");
77  data.replace("%3D", "=");
78  return data;
79 }
80 
81 QString TTK::Url::urlPrettyEncode(QString &data)
82 {
83 #if TTK_QT_VERSION_CHECK(5,0,0)
84  data = QUrl(data).toString(QUrl::FullyEncoded);
85 #else
86  data = QUrl(data).toEncoded();
87 #endif
88  return data;
89 }
90 
91 QString TTK::Url::urlPrettyDecode(QString &data)
92 {
93 #if TTK_QT_VERSION_CHECK(5,0,0)
94  data = QUrl(data).toString();
95 #else
96  data = QByteArray::fromPercentEncoding(data.toUtf8());
97 #endif
98  return data;
99 }
100 
101 QByteArray TTK::Url::urlPrettyEncode(QByteArray &data)
102 {
103 #if TTK_QT_VERSION_CHECK(5,0,0)
104  data = QUrl(data).toString(QUrl::FullyEncoded).toUtf8();
105 #else
106  data = QUrl(data).toEncoded();
107 #endif
108  return data;
109 }
110 
111 QByteArray TTK::Url::urlPrettyDecode(QByteArray &data)
112 {
113 #if TTK_QT_VERSION_CHECK(5,0,0)
114  data = QUrl::fromEncoded(data).toString(QUrl::FullyDecoded).toUtf8();
115 #else
116  data = QByteArray::fromPercentEncoding(data);
117 #endif
118  return data;
119 }
TTK_MODULE_EXPORT QString urlEncode(QString &data)
TTK_MODULE_EXPORT bool execute(const QString &path)
TTK_MODULE_EXPORT QString urlPrettyEncode(QString &data)
TTK_MODULE_EXPORT QString urlDecode(QString &data)
System systemName() const
The class of the platform system.
#define TTK_SEPARATOR
Definition: ttkglobal.h:195
#define local
Definition: unzip.c:91
TTK_MODULE_EXPORT bool openUrl(const QString &path, bool local=true)
TTK_MODULE_EXPORT QString urlPrettyDecode(QString &data)