summaryrefslogtreecommitdiff
path: root/core/launcher/launcherglobal.cpp
blob: 9abcae9a5532f1f4113f70db0190e2ac5addbc6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * GPLv2 only
 *
 * TT 2002-2002,2003
 */
#include <qfile.h>
#include <qtextstream.h>

#include <qtopia/mimetype.h>

#include "launcherglobal.h"

bool Opie::Global::isAppLnkFileName( const QString& file ) {
    if ( file.right(1) == "/" )
	return FALSE;

    return file.find(MimeType::appsFolderName()+"/")==0;
}

QString Opie::Global::tempDir() {
    return QString::fromLatin1("/tmp/");
}

Global::Command* Opie::Global::builtinCommands() {
    return builtin;
}

QGuardedPtr<QWidget>* Opie::Global::builtinRunning() {
    return running;
}

QString Opie::Global::uuid() {
    QFile file( "/proc/sys/kernel/random/uuid" );
    if (!file.open(IO_ReadOnly ) )
        return QString::null;

    QTextStream stream(&file);

    return "{" + stream.read().stripWhiteSpace() + "}";
}

QByteArray Opie::Global::encodeBase64(const QByteArray& origData ) {
// follows simple algorithm from rsync code
    uchar *in = (uchar*)origData.data();

    int inbytes = origData.size();
    int outbytes = ((inbytes * 8) + 5) / 6;
    int padding = 4-outbytes%4; if ( padding == 4 ) padding = 0;

    QByteArray outbuf(outbytes+padding);
    uchar* out = (uchar*)outbuf.data();

    const char *b64 =
        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

    for (int i = 0; i < outbytes; i++) {
        int byte = (i * 6) / 8;
        int bit = (i * 6) % 8;
        if (bit < 3) {
            if (byte < inbytes)
	        *out = (b64[(in[byte] >> (2 - bit)) & 0x3F]);
        } else {
            if (byte + 1 == inbytes) {
	        *out = (b64[(in[byte] << (bit - 2)) & 0x3F]);
            } else {
	        *out = (b64[(in[byte] << (bit - 2) |
		     in[byte + 1] >> (10 - bit)) & 0x3F]);
            }
        }
        ++out;
    }
    ASSERT(out == (uchar*)outbuf.data() + outbuf.size() - padding);
    while ( padding-- )
        *out++='=';

    return outbuf;
}