| 105 | } |
| 106 | |
| 107 | static QString generatePathOrUrl(bool onlyPath, bool isLocalFile, const QVector<QString>& data) |
| 108 | { |
| 109 | // more or less a copy of QtPrivate::QStringList_join |
| 110 | const int size = data.size(); |
| 111 | |
| 112 | if (size == 0) { |
| 113 | return QString(); |
| 114 | } |
| 115 | |
| 116 | int totalLength = 0; |
| 117 | // separators: '/' |
| 118 | totalLength += size; |
| 119 | |
| 120 | // skip Path segment if we only want the path |
| 121 | int start = (onlyPath && !isLocalFile) ? 1 : 0; |
| 122 | |
| 123 | // path and url prefix |
| 124 | for (int i = start; i < size; ++i) { |
| 125 | totalLength += data.at(i).size(); |
| 126 | } |
| 127 | |
| 128 | // build string representation |
| 129 | QString res; |
| 130 | res.reserve(totalLength); |
| 131 | |
| 132 | #ifdef Q_OS_WIN |
| 133 | if (start == 0 && isLocalFile) { |
| 134 | if(!data.at(0).endsWith(QLatin1Char(':'))) { |
| 135 | qCWarning(UTIL) << "Path::generatePathOrUrl: Invalid Windows drive encountered (expected C: or similar), got: " << |
| 136 | qPrintable(data.at(0)); |
| 137 | } |
| 138 | Q_ASSERT(data.at(0).endsWith(QLatin1Char(':'))); // assume something along "C:" |
| 139 | res += data.at(0); |
| 140 | start++; |
| 141 | } |
| 142 | #endif |
| 143 | |
| 144 | for (int i = start; i < size; ++i) { |
| 145 | if (i || isLocalFile) { |
| 146 | res += QLatin1Char('/'); |
| 147 | } |
| 148 | |
| 149 | res += data.at(i); |
| 150 | } |
| 151 | |
| 152 | return res; |
| 153 | } |
| 154 | |
| 155 | QString Path::pathOrUrl() const |
| 156 | { |