summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/launcherglobal.cpp83
-rw-r--r--core/launcher/launcherglobal.h19
2 files changed, 102 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
17bool Opie::Global::isAppLnkFileName( const QString& file ) {
18 if ( file.right(1) == "/" )
19 return FALSE;
20
21 return file.find(MimeType::appsFolderName()+"/")==0;
22}
23
24QString Opie::Global::tempDir() {
25 return QString::fromLatin1("/tmp/");
26}
27
28Global::Command* Opie::Global::builtinCommands() {
29 return builtin;
30}
31
32QGuardedPtr<QWidget>* Opie::Global::builtinRunning() {
33 return running;
34}
35
36QString 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
46QByteArray 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
diff --git a/core/launcher/launcherglobal.h b/core/launcher/launcherglobal.h
new file mode 100644
index 0000000..e8829c5
--- a/dev/null
+++ b/core/launcher/launcherglobal.h
@@ -0,0 +1,19 @@
1/*
2 * original code from global1.cpp Copyright by trolltech
3 * GPLv2 only zecke@handhelds.org
4 *
5 */
6#define private protected
7#include <qtopia/global.h>
8#undef private
9
10namespace Opie {
11 struct Global : public ::Global{
12 static bool isAppLnkFileName( const QString& str );
13 static QString tempDir();
14 static Command* builtinCommands();
15 static QGuardedPtr<QWidget>* builtinRunning();
16 static QString uuid();
17 static QByteArray encodeBase64(const QByteArray& data );
18 };
19}