-rw-r--r-- | microkde/kapplication.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/microkde/kapplication.cpp b/microkde/kapplication.cpp index 98ef2f2..56c01af 100644 --- a/microkde/kapplication.cpp +++ b/microkde/kapplication.cpp | |||
@@ -1,84 +1,106 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <stdio.h> | 2 | #include <stdio.h> |
3 | 3 | ||
4 | #include "kapplication.h" | 4 | #include "kapplication.h" |
5 | #include <qapplication.h> | 5 | #include <qapplication.h> |
6 | #include <qstring.h> | 6 | #include <qstring.h> |
7 | #include <qfile.h> | 7 | #include <qfile.h> |
8 | #include <qtextstream.h> | 8 | #include <qtextstream.h> |
9 | #include <qdialog.h> | 9 | #include <qdialog.h> |
10 | #include <qlayout.h> | 10 | #include <qlayout.h> |
11 | #include <qtextbrowser.h> | 11 | #include <qtextbrowser.h> |
12 | 12 | ||
13 | int KApplication::random() | 13 | int KApplication::random() |
14 | { | 14 | { |
15 | return rand(); | 15 | return rand(); |
16 | } | 16 | } |
17 | 17 | ||
18 | //US | 18 | //US |
19 | QString KApplication::randomString(int length) | 19 | QString KApplication::randomString(int length) |
20 | { | 20 | { |
21 | if (length <=0 ) return QString::null; | 21 | if (length <=0 ) return QString::null; |
22 | 22 | ||
23 | QString str; | 23 | QString str; |
24 | while (length--) | 24 | while (length--) |
25 | { | 25 | { |
26 | int r=random() % 62; | 26 | int r=random() % 62; |
27 | r+=48; | 27 | r+=48; |
28 | if (r>57) r+=7; | 28 | if (r>57) r+=7; |
29 | if (r>90) r+=6; | 29 | if (r>90) r+=6; |
30 | str += char(r); | 30 | str += char(r); |
31 | // so what if I work backwards? | 31 | // so what if I work backwards? |
32 | } | 32 | } |
33 | return str; | 33 | return str; |
34 | } | 34 | } |
35 | int KApplication::execDialog( QDialog* d ) | 35 | int KApplication::execDialog( QDialog* d ) |
36 | { | 36 | { |
37 | if (QApplication::desktop()->width() <= 640 ) | 37 | if (QApplication::desktop()->width() <= 640 ) |
38 | d->showMaximized(); | 38 | d->showMaximized(); |
39 | return d->exec(); | 39 | return d->exec(); |
40 | } | 40 | } |
41 | void KApplication::showLicence() | 41 | void KApplication::showLicence() |
42 | { | 42 | { |
43 | KApplication::showFile( "KDE-Pim/Pi licence", "kdepim/LICENCE.TXT" ); | 43 | KApplication::showFile( "KDE-Pim/Pi licence", "kdepim/LICENCE.TXT" ); |
44 | } | 44 | } |
45 | 45 | ||
46 | void KApplication::showFile(QString caption, QString fn) | 46 | void KApplication::showFile(QString caption, QString fn) |
47 | { | 47 | { |
48 | QString text; | 48 | QString text; |
49 | QString fileName; | 49 | QString fileName; |
50 | #ifndef DESKTOP_VERSION | 50 | #ifndef DESKTOP_VERSION |
51 | fileName = getenv("QPEDIR"); | 51 | fileName = getenv("QPEDIR"); |
52 | fileName += "/pics/" + fn ; | 52 | fileName += "/pics/" + fn ; |
53 | #else | 53 | #else |
54 | fileName = qApp->applicationDirPath () + "/" + fn; | 54 | fileName = qApp->applicationDirPath () + "/" + fn; |
55 | #endif | 55 | #endif |
56 | QFile file( fileName ); | 56 | QFile file( fileName ); |
57 | if (!file.open( IO_ReadOnly ) ) { | 57 | if (!file.open( IO_ReadOnly ) ) { |
58 | return ; | 58 | return ; |
59 | } | 59 | } |
60 | QTextStream ts( &file ); | 60 | QTextStream ts( &file ); |
61 | text = ts.read(); | 61 | text = ts.read(); |
62 | file.close(); | 62 | file.close(); |
63 | KApplication::showText( caption, text ); | 63 | KApplication::showText( caption, text ); |
64 | 64 | ||
65 | } | 65 | } |
66 | 66 | ||
67 | bool KApplication::convert2latin1(QString fileName) | ||
68 | { | ||
69 | QString text; | ||
70 | QFile file( fileName ); | ||
71 | if (!file.open( IO_ReadOnly ) ) { | ||
72 | return false; | ||
73 | |||
74 | } | ||
75 | QTextStream ts( &file ); | ||
76 | ts.setEncoding( QTextStream::UnicodeUTF8 ); | ||
77 | text = ts.read(); | ||
78 | file.close(); | ||
79 | if (!file.open( IO_WriteOnly ) ) { | ||
80 | return false; | ||
81 | } | ||
82 | QTextStream tsIn( &file ); | ||
83 | tsIn.setEncoding( QTextStream::Latin1 ); | ||
84 | tsIn << text.latin1(); | ||
85 | file.close(); | ||
86 | |||
87 | |||
88 | } | ||
67 | void KApplication::showText(QString caption, QString text) | 89 | void KApplication::showText(QString caption, QString text) |
68 | { | 90 | { |
69 | QDialog dia( 0, "name", true ); ; | 91 | QDialog dia( 0, "name", true ); ; |
70 | dia.setCaption( caption ); | 92 | dia.setCaption( caption ); |
71 | QVBoxLayout* lay = new QVBoxLayout( &dia ); | 93 | QVBoxLayout* lay = new QVBoxLayout( &dia ); |
72 | lay->setSpacing( 3 ); | 94 | lay->setSpacing( 3 ); |
73 | lay->setMargin( 3 ); | 95 | lay->setMargin( 3 ); |
74 | QTextBrowser tb ( &dia ); | 96 | QTextBrowser tb ( &dia ); |
75 | lay->addWidget( &tb ); | 97 | lay->addWidget( &tb ); |
76 | tb.setText( text ); | 98 | tb.setText( text ); |
77 | #ifdef DESKTOP_VERSION | 99 | #ifdef DESKTOP_VERSION |
78 | dia.resize( 640, 480); | 100 | dia.resize( 640, 480); |
79 | #else | 101 | #else |
80 | dia.showMaximized(); | 102 | dia.showMaximized(); |
81 | #endif | 103 | #endif |
82 | dia.exec(); | 104 | dia.exec(); |
83 | 105 | ||
84 | } | 106 | } |