189
197
QDir dir(source);
190
198
foreach (const QString& child, dir.entryList(QDir::NoDotAndDotDot | QDir::Dirs)) {
191
199
if (!CopyRecursive(source + "/" + child, dest_path)) {
192
qWarning() << "Failed to copy dir" << source + "/" + child << "to" << dest_path;
200
qLog(Warning) << "Failed to copy dir" << source + "/" + child << "to" << dest_path;
197
205
foreach (const QString& child, dir.entryList(QDir::NoDotAndDotDot | QDir::Files)) {
198
206
if (!QFile::copy(source + "/" + child, dest_path + "/" + child)) {
199
qWarning() << "Failed to copy file" << source + "/" + child << "to" << dest_path;
207
qLog(Warning) << "Failed to copy file" << source + "/" + child << "to" << dest_path;
272
277
return QDir::homePath();
280
case Path_LocalSpotifyBlob:
281
return GetConfigPath(Path_Root) + "/spotifyblob";
276
284
qFatal("%s", Q_FUNC_INFO);
277
285
return QString::null;
281
void OpenInFileBrowser(const QStringList& filenames) {
290
qint32 GetMacVersion() {
291
SInt32 minor_version;
292
Gestalt(gestaltSystemVersionMinor, &minor_version);
293
return minor_version;
295
#endif // Q_OS_DARWIN
297
void OpenInFileBrowser(const QList<QUrl>& urls) {
282
298
QSet<QString> dirs;
284
foreach (const QString& filename, filenames) {
285
// Ignore things that look like URLs
286
if (filename.contains("://"))
289
if (!QFile::exists(filename))
292
const QString directory = QFileInfo(filename).dir().path();
300
foreach (const QUrl& url, urls) {
301
if (url.scheme() != "file") {
304
QString path = url.toLocalFile();
306
if (!QFile::exists(path))
309
const QString directory = QFileInfo(path).dir().path();
294
311
if (dirs.contains(directory))
319
QByteArray Hmac(const QByteArray& key, const QByteArray& data, HashFunction method) {
320
const int kBlockSize = 64; // bytes
321
Q_ASSERT(key.length() <= kBlockSize);
323
QByteArray inner_padding(kBlockSize, char(0x36));
324
QByteArray outer_padding(kBlockSize, char(0x5c));
326
for (int i=0 ; i<key.length() ; ++i) {
327
inner_padding[i] = inner_padding[i] ^ key[i];
328
outer_padding[i] = outer_padding[i] ^ key[i];
330
if (Md5_Algo == method) {
331
return QCryptographicHash::hash(outer_padding +
332
QCryptographicHash::hash(inner_padding + data,
333
QCryptographicHash::Md5),
334
QCryptographicHash::Md5);
335
} else { // Sha256_Algo, currently default
336
return Sha256(outer_padding + Sha256(inner_padding + data));
340
QByteArray HmacSha256(const QByteArray& key, const QByteArray& data) {
341
return Hmac(key, data, Sha256_Algo);
344
QByteArray HmacMd5(const QByteArray& key, const QByteArray& data) {
345
return Hmac(key, data, Md5_Algo);
348
QByteArray Sha256(const QByteArray& data) {
350
SHA256_Init(&context);
351
SHA256_Update(&context, reinterpret_cast<const u_int8_t*>(data.constData()),
354
QByteArray ret(SHA256_DIGEST_LENGTH, '\0');
355
SHA256_Final(reinterpret_cast<u_int8_t*>(ret.data()), &context);
360
QString PrettySize(const QSize& size) {
361
return QString::number(size.width()) + "x" +
362
QString::number(size.height());
365
void ForwardMouseEvent(const QMouseEvent* e, QWidget* target) {
366
QMouseEvent c(e->type(), target->mapFromGlobal(e->globalPos()),
367
e->globalPos(), e->button(), e->buttons(), e->modifiers());
369
QApplication::sendEvent(target, &c);
372
bool IsMouseEventInWidget(const QMouseEvent* e, const QWidget* widget) {
373
return widget->rect().contains(widget->mapFromGlobal(e->globalPos()));
376
quint16 PickUnusedPort() {
378
const quint16 port = 49152 + qrand() % 16384;
381
if (server.listen(QHostAddress::Any, port)) {
387
void ConsumeCurrentElement(QXmlStreamReader* reader) {
389
while (level != 0 && !reader->atEnd()) {
390
switch (reader->readNext()) {
391
case QXmlStreamReader::StartElement: ++level; break;
392
case QXmlStreamReader::EndElement: --level; break;
302
398
} // namespace Utilities