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