author | zecke <zecke> | 2003-08-31 20:14:53 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-08-31 20:14:53 (UTC) |
commit | 2fb39071c9880b462acd6fa7314d99a032a9df47 (patch) (unidiff) | |
tree | c21ba18503b4a1613692f2114809a00c696e9d02 /core/launcher/launcherglobal.cpp | |
parent | 2696413e75a401899764f244c8c24026999fdb9d (diff) | |
download | opie-2fb39071c9880b462acd6fa7314d99a032a9df47.zip opie-2fb39071c9880b462acd6fa7314d99a032a9df47.tar.gz opie-2fb39071c9880b462acd6fa7314d99a032a9df47.tar.bz2 |
thanks mickeyl
Diffstat (limited to 'core/launcher/launcherglobal.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/launcher/launcherglobal.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/core/launcher/launcherglobal.cpp b/core/launcher/launcherglobal.cpp new file mode 100644 index 0000000..84caa93 --- a/dev/null +++ b/core/launcher/launcherglobal.cpp | |||
@@ -0,0 +1,83 @@ | |||
1 | /* | ||
2 | * GPLv2 only | ||
3 | * | ||
4 | * TT 2002-2002,2003 | ||
5 | */ | ||
6 | #include <qstring.h> | ||
7 | #include <qcstring.h> | ||
8 | #include <qwidget.h> | ||
9 | #include <qguardedptr.h> | ||
10 | #include <qfile.h> | ||
11 | #include <qtextstream.h> | ||
12 | |||
13 | #include <qtopia/mimetype.h> | ||
14 | |||
15 | #include "launcherglobal.h" | ||
16 | |||
17 | bool Opie::Global::isAppLnkFileName( const QString& file ) { | ||
18 | if ( file.right(1) == "/" ) | ||
19 | return FALSE; | ||
20 | |||
21 | return file.find(MimeType::appsFolderName()+"/")==0; | ||
22 | } | ||
23 | |||
24 | QString Opie::Global::tempDir() { | ||
25 | return QString::fromLatin1("/tmp/"); | ||
26 | } | ||
27 | |||
28 | Global::Command* Opie::Global::builtinCommands() { | ||
29 | return builtin; | ||
30 | } | ||
31 | |||
32 | QGuardedPtr<QWidget>* Opie::Global::builtinRunning() { | ||
33 | return running; | ||
34 | } | ||
35 | |||
36 | QString Opie::Global::uuid() { | ||
37 | QFile file( "/proc/sys/kernel/random/uuid" ); | ||
38 | if (!file.open(IO_ReadOnly ) ) | ||
39 | return QString::null; | ||
40 | |||
41 | QTextStream stream(&file); | ||
42 | |||
43 | return "{" + stream.read().stripWhiteSpace() + "}"; | ||
44 | } | ||
45 | |||
46 | QByteArray Opie::Global::encodeBase64(const QByteArray& origData ) { | ||
47 | // follows simple algorithm from rsync code | ||
48 | uchar *in = (uchar*)origData.data(); | ||
49 | |||
50 | int inbytes = origData.size(); | ||
51 | int outbytes = ((inbytes * 8) + 5) / 6; | ||
52 | int padding = 4-outbytes%4; if ( padding == 4 ) padding = 0; | ||
53 | |||
54 | QByteArray outbuf(outbytes+padding); | ||
55 | uchar* out = (uchar*)outbuf.data(); | ||
56 | |||
57 | const char *b64 = | ||
58 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | ||
59 | |||
60 | for (int i = 0; i < outbytes; i++) { | ||
61 | int byte = (i * 6) / 8; | ||
62 | int bit = (i * 6) % 8; | ||
63 | if (bit < 3) { | ||
64 | if (byte < inbytes) | ||
65 | *out = (b64[(in[byte] >> (2 - bit)) & 0x3F]); | ||
66 | } else { | ||
67 | if (byte + 1 == inbytes) { | ||
68 | *out = (b64[(in[byte] << (bit - 2)) & 0x3F]); | ||
69 | } else { | ||
70 | *out = (b64[(in[byte] << (bit - 2) | | ||
71 | in[byte + 1] >> (10 - bit)) & 0x3F]); | ||
72 | } | ||
73 | } | ||
74 | ++out; | ||
75 | } | ||
76 | ASSERT(out == (uchar*)outbuf.data() + outbuf.size() - padding); | ||
77 | while ( padding-- ) | ||
78 | *out++='='; | ||
79 | |||
80 | return outbuf; | ||
81 | } | ||
82 | |||
83 | |||