summaryrefslogtreecommitdiffabout
path: root/microkde
Unidiff
Diffstat (limited to 'microkde') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kapplication.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/microkde/kapplication.cpp b/microkde/kapplication.cpp
index 539397b..566bb41 100644
--- a/microkde/kapplication.cpp
+++ b/microkde/kapplication.cpp
@@ -1,204 +1,205 @@
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 14
14int KApplication::random() 15int KApplication::random()
15{ 16{
16 return rand(); 17 return rand();
17} 18}
18 19
19//US 20//US
20QString KApplication::randomString(int length) 21QString KApplication::randomString(int length)
21{ 22{
22 if (length <=0 ) return QString::null; 23 if (length <=0 ) return QString::null;
23 24
24 QString str; 25 QString str;
25 while (length--) 26 while (length--)
26 { 27 {
27 int r=random() % 62; 28 int r=random() % 62;
28 r+=48; 29 r+=48;
29 if (r>57) r+=7; 30 if (r>57) r+=7;
30 if (r>90) r+=6; 31 if (r>90) r+=6;
31 str += char(r); 32 str += char(r);
32 // so what if I work backwards? 33 // so what if I work backwards?
33 } 34 }
34 return str; 35 return str;
35} 36}
36int KApplication::execDialog( QDialog* d ) 37int KApplication::execDialog( QDialog* d )
37{ 38{
38 if (QApplication::desktop()->width() <= 640 ) 39 if (QApplication::desktop()->width() <= 640 )
39 d->showMaximized(); 40 d->showMaximized();
40 else 41 else
41 ;//d->resize( 800, 600 ); 42 ;//d->resize( 800, 600 );
42 return d->exec(); 43 return d->exec();
43} 44}
44void KApplication::showLicence() 45void KApplication::showLicence()
45{ 46{
46 KApplication::showFile( "KDE-Pim/Pi licence", "kdepim/licence.txt" ); 47 KApplication::showFile( "KDE-Pim/Pi licence", "kdepim/licence.txt" );
47} 48}
48 49
49void KApplication::testCoords( int* x, int* y, int* wid, int * hei ) 50void KApplication::testCoords( int* x, int* y, int* wid, int * hei )
50{ 51{
51 int dWid = QApplication::desktop()->width() ; 52 int dWid = QApplication::desktop()->width() ;
52 int dHei = QApplication::desktop()->height(); 53 int dHei = QApplication::desktop()->height();
53 if ( *x + *wid > dWid ) { 54 if ( *x + *wid > dWid ) {
54 *x = 0; 55 *x = 0;
55 if ( *wid > dWid ) 56 if ( *wid > dWid )
56 *wid = dWid; 57 *wid = dWid;
57 } 58 }
58 if ( *y + *hei > dHei ) { 59 if ( *y + *hei > dHei ) {
59 *y = 0; 60 *y = 0;
60 if ( *hei > dHei ) 61 if ( *hei > dHei )
61 *hei = dHei; 62 *hei = dHei;
62 } 63 }
63} 64}
64void KApplication::showFile(QString caption, QString fn) 65void KApplication::showFile(QString caption, QString fn)
65{ 66{
66 QString text; 67 QString text;
67 QString fileName; 68 QString fileName;
68#ifndef DESKTOP_VERSION 69#ifndef DESKTOP_VERSION
69 fileName = getenv("QPEDIR"); 70 fileName = getenv("QPEDIR");
70 fileName += "/pics/" + fn ; 71 fileName += "/pics/" + fn ;
71#else 72#else
72 fileName = qApp->applicationDirPath () + "/" + fn; 73 fileName = qApp->applicationDirPath () + "/" + fn;
73#endif 74#endif
74 QFile file( fileName ); 75 QFile file( fileName );
75 if (!file.open( IO_ReadOnly ) ) { 76 if (!file.open( IO_ReadOnly ) ) {
76 return ; 77 return ;
77 } 78 }
78 QTextStream ts( &file ); 79 QTextStream ts( &file );
79 text = ts.read(); 80 text = ts.read();
80 file.close(); 81 file.close();
81 KApplication::showText( caption, text ); 82 KApplication::showText( caption, text );
82 83
83} 84}
84 85
85bool KApplication::convert2latin1(QString fileName) 86bool KApplication::convert2latin1(QString fileName)
86{ 87{
87 QString text; 88 QString text;
88 QFile file( fileName ); 89 QFile file( fileName );
89 if (!file.open( IO_ReadOnly ) ) { 90 if (!file.open( IO_ReadOnly ) ) {
90 return false; 91 return false;
91 92
92 } 93 }
93 QTextStream ts( &file ); 94 QTextStream ts( &file );
94 ts.setEncoding( QTextStream::UnicodeUTF8 ); 95 ts.setEncoding( QTextStream::UnicodeUTF8 );
95 text = ts.read(); 96 text = ts.read();
96 file.close(); 97 file.close();
97 if (!file.open( IO_WriteOnly ) ) { 98 if (!file.open( IO_WriteOnly ) ) {
98 return false; 99 return false;
99 } 100 }
100 QTextStream tsIn( &file ); 101 QTextStream tsIn( &file );
101 tsIn.setEncoding( QTextStream::Latin1 ); 102 tsIn.setEncoding( QTextStream::Latin1 );
102 tsIn << text.latin1(); 103 tsIn << text.latin1();
103 file.close(); 104 file.close();
104 return true; 105 return true;
105 106
106 107
107} 108}
108void KApplication::showText(QString caption, QString text) 109void KApplication::showText(QString caption, QString text)
109{ 110{
110 QDialog dia( 0, "name", true ); ; 111 QDialog dia( 0, "name", true ); ;
111 dia.setCaption( caption ); 112 dia.setCaption( caption );
112 QVBoxLayout* lay = new QVBoxLayout( &dia ); 113 QVBoxLayout* lay = new QVBoxLayout( &dia );
113 lay->setSpacing( 3 ); 114 lay->setSpacing( 3 );
114 lay->setMargin( 3 ); 115 lay->setMargin( 3 );
115 KTextEdit tb ( &dia ); 116 KTextEdit tb ( &dia );
116 tb.setWordWrap( QMultiLineEdit::WidgetWidth ); 117 tb.setWordWrap( QMultiLineEdit::WidgetWidth );
117 lay->addWidget( &tb ); 118 lay->addWidget( &tb );
118 tb.setText( text ); 119 tb.setText( text );
119#ifdef DESKTOP_VERSION 120#ifdef DESKTOP_VERSION
120 dia.resize( 640, 480); 121 dia.resize( 640, 480);
121#else 122#else
122 dia.showMaximized(); 123 dia.showMaximized();
123#endif 124#endif
124 dia.exec(); 125 dia.exec();
125 126
126} 127}
127 128
128#include <qlabel.h> 129#include <qlabel.h>
129#include <qpushbutton.h> 130#include <qpushbutton.h>
130#include <qlayout.h> 131#include <qlayout.h>
131#include <qdir.h> 132#include <qdir.h>
132#include <qradiobutton.h> 133#include <qradiobutton.h>
133#include <qbuttongroup.h> 134#include <qbuttongroup.h>
134#include "kglobal.h" 135#include "kglobal.h"
135#include "klocale.h" 136#include "klocale.h"
136 137
137class KBackupPrefs : public QDialog 138class KBackupPrefs : public QDialog
138{ 139{
139 public: 140 public:
140 KBackupPrefs( QString message , QWidget *parent=0, const char *name=0 ) : 141 KBackupPrefs( QString message , QWidget *parent=0, const char *name=0 ) :
141 QDialog( parent, name, true ) 142 QDialog( parent, name, true )
142 { 143 {
143 setCaption( i18n("Backup Failed!") ); 144 setCaption( i18n("Backup Failed!") );
144 QVBoxLayout* lay = new QVBoxLayout( this ); 145 QVBoxLayout* lay = new QVBoxLayout( this );
145 lay->setSpacing( 3 ); 146 lay->setSpacing( 3 );
146 lay->setMargin( 3 ); 147 lay->setMargin( 3 );
147 QLabel * lab = new QLabel( message, this ); 148 QLabel * lab = new QLabel( message, this );
148 lay->addWidget( lab ); 149 lay->addWidget( lab );
149 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("Choose action"), this ); 150 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("Choose action"), this );
150 lay->addWidget( format ); 151 lay->addWidget( format );
151 format->setExclusive ( true ) ; 152 format->setExclusive ( true ) ;
152 vcal = new QRadioButton(i18n("Try again now"), format ); 153 vcal = new QRadioButton(i18n("Try again now"), format );
153 tcal = new QRadioButton(i18n("Try again later"), format ); 154 tcal = new QRadioButton(i18n("Try again later"), format );
154 ical = new QRadioButton(i18n("Try again tomorrow"), format ); 155 ical = new QRadioButton(i18n("Try again tomorrow"), format );
155 ocal = new QRadioButton(i18n("Disable backup"), format ); 156 ocal = new QRadioButton(i18n("Disable backup"), format );
156 vcal->setChecked( true ); 157 vcal->setChecked( true );
157 QPushButton * ok = new QPushButton( i18n("OK"), this ); 158 QPushButton * ok = new QPushButton( i18n("OK"), this );
158 lay->addWidget(ok ); 159 lay->addWidget(ok );
159 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 160 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
160 } 161 }
161 162
162 bool again() { return vcal->isChecked(); } 163 bool again() { return vcal->isChecked(); }
163 bool later() { return tcal->isChecked(); } 164 bool later() { return tcal->isChecked(); }
164 bool againTomorrow() { return ical->isChecked(); } 165 bool againTomorrow() { return ical->isChecked(); }
165private: 166private:
166 QRadioButton* vcal, *ical, *ocal, *tcal; 167 QRadioButton* vcal, *ical, *ocal, *tcal;
167}; 168};
168int KApplication::createBackup( QString fn, QString dp, int numBup ) 169int KApplication::createBackup( QString fn, QString dp, int numBup )
169{ 170{
170 if ( numBup < 1) return 3; 171 if ( numBup < 1) return 3;
171 int ret = 3; 172 int ret = 3;
172 qDebug("KApplication::createBackup %s --- %s --- %d", fn.latin1(), dp.latin1(), numBup); 173 qDebug("KApplication::createBackup %s --- %s --- %d", fn.latin1(), dp.latin1(), numBup);
173 QDir bupDir ( dp ); 174 QDir bupDir ( dp );
174 bool tryAgain = true; 175 bool tryAgain = true;
175 while ( tryAgain ) { 176 while ( tryAgain ) {
176 if ( !bupDir.exists() ) { 177 if ( !bupDir.exists() ) {
177 KBackupPrefs noDir( i18n("<b>Backup directory does not exist: </b>") + dp.right(30)); 178 KBackupPrefs noDir( i18n("<b>Backup directory does not exist: </b>") + dp.right(30));
178 if ( !noDir.exec() ) return 3; 179 if ( !noDir.exec() ) return 3;
179 if ( noDir.againTomorrow() ) { 180 if ( noDir.againTomorrow() ) {
180 return 0; 181 return 0;
181 } else if ( noDir.later() ) { 182 } else if ( noDir.later() ) {
182 return 3; 183 return 3;
183 } else if ( !noDir.again() ) { 184 } else if ( !noDir.again() ) {
184 return 2; 185 return 2;
185 } 186 }
186 } else { 187 } else {
187 tryAgain = false; 188 tryAgain = false;
188 } 189 }
189 } 190 }
190 // we have a valid dir! 191 // we have a valid dir!
191 QStringList allFileList = bupDir.entryList(QDir::Files); 192 QStringList allFileList = bupDir.entryList(QDir::Files);
192 QFileInfo fileInfo ( fn ); 193 QFileInfo fileInfo ( fn );
193 QString fName = fileInfo.fileName (); 194 QString fName = fileInfo.fileName ();
194 QStringList fileList; 195 QStringList fileList;
195 196
196 int i; 197 int i;
197 for ( i = 0; i < allFileList.count(); ++i ) { 198 for ( i = 0; i < allFileList.count(); ++i ) {
198 QString fi = allFileList[i]; 199 QString fi = allFileList[i];
199 if ( fi. find( fName ) > -1 ) 200 if ( fi. find( fName ) > -1 )
200 fileList.append( fi ); 201 fileList.append( fi );
201 } 202 }
202 qDebug("%d backup files exist ", fileList.count()); 203 qDebug("%d backup files exist ", fileList.count());
203 int count = fileList.count(); 204 int count = fileList.count();
204 fileList.sort(); 205 fileList.sort();