summaryrefslogtreecommitdiffabout
path: root/microkde
Unidiff
Diffstat (limited to 'microkde') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kapplication.cpp22
-rw-r--r--microkde/kapplication.h1
2 files changed, 23 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
13int KApplication::random() 13int KApplication::random()
14{ 14{
15 return rand(); 15 return rand();
16} 16}
17 17
18//US 18//US
19QString KApplication::randomString(int length) 19QString 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}
35int KApplication::execDialog( QDialog* d ) 35int 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}
41void KApplication::showLicence() 41void 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
46void KApplication::showFile(QString caption, QString fn) 46void 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
67bool 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}
67void KApplication::showText(QString caption, QString text) 89void 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}
diff --git a/microkde/kapplication.h b/microkde/kapplication.h
index 79cdb33..41546a0 100644
--- a/microkde/kapplication.h
+++ b/microkde/kapplication.h
@@ -1,26 +1,27 @@
1#ifndef MINIKDE_KAPPLICATION_H 1#ifndef MINIKDE_KAPPLICATION_H
2#define MINIKDE_KAPPLICATION_H 2#define MINIKDE_KAPPLICATION_H
3 3
4#include "qstring.h" 4#include "qstring.h"
5#include <qdialog.h> 5#include <qdialog.h>
6 6
7class KApplication 7class KApplication
8{ 8{
9 public: 9 public:
10 static int random(); 10 static int random();
11 11
12//US 12//US
13 /** 13 /**
14 * Generates a random string. It operates in the range [A-Za-z0-9] 14 * Generates a random string. It operates in the range [A-Za-z0-9]
15 * @param length Generate a string of this length. 15 * @param length Generate a string of this length.
16 * @return the random string 16 * @return the random string
17 */ 17 */
18 static QString randomString(int length); 18 static QString randomString(int length);
19 static int execDialog( QDialog* ); 19 static int execDialog( QDialog* );
20 static void showLicence(); 20 static void showLicence();
21 static void showFile(QString caption, QString file); 21 static void showFile(QString caption, QString file);
22 static void showText(QString caption, QString text); 22 static void showText(QString caption, QString text);
23 static bool convert2latin1(QString file);
23}; 24};
24 25
25 26
26#endif 27#endif