summaryrefslogtreecommitdiffabout
path: root/microkde/kapplication.cpp
Unidiff
Diffstat (limited to 'microkde/kapplication.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kapplication.cpp4
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,249 +1,251 @@
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
15int KApplication::random() 15int KApplication::random()
16{ 16{
17 return rand(); 17 return rand();
18} 18}
19 19
20//US 20//US
21QString KApplication::randomString(int length) 21QString 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}
37int KApplication::execDialog( QDialog* d ) 37int 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}
45void KApplication::showLicence() 45void 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
50void KApplication::testCoords( int* x, int* y, int* wid, int * hei ) 50void 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}
65void KApplication::showFile(QString caption, QString fn) 67void 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
86bool KApplication::convert2latin1(QString fileName) 88bool 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}
109void KApplication::showText(QString caption, QString text) 111void 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
125 dia.exec(); 127 dia.exec();
126 128
127} 129}
128 130
129#include <qlabel.h> 131#include <qlabel.h>
130#include <qpushbutton.h> 132#include <qpushbutton.h>
131#include <qlayout.h> 133#include <qlayout.h>
132#include <qdir.h> 134#include <qdir.h>
133#include <qradiobutton.h> 135#include <qradiobutton.h>
134#include <qbuttongroup.h> 136#include <qbuttongroup.h>
135#include "kglobal.h" 137#include "kglobal.h"
136#include "klocale.h" 138#include "klocale.h"
137 139
138class KBackupPrefs : public QDialog 140class KBackupPrefs : public QDialog
139{ 141{
140 public: 142 public:
141 KBackupPrefs( QString message , QWidget *parent=0, const char *name=0 ) : 143 KBackupPrefs( QString message , QWidget *parent=0, const char *name=0 ) :
142 QDialog( parent, name, true ) 144 QDialog( parent, name, true )
143 { 145 {
144 setCaption( i18n("Backup Failed!") ); 146 setCaption( i18n("Backup Failed!") );
145 QVBoxLayout* lay = new QVBoxLayout( this ); 147 QVBoxLayout* lay = new QVBoxLayout( this );
146 lay->setSpacing( 3 ); 148 lay->setSpacing( 3 );
147 lay->setMargin( 3 ); 149 lay->setMargin( 3 );
148 QLabel * lab = new QLabel( message, this ); 150 QLabel * lab = new QLabel( message, this );
149 lay->addWidget( lab ); 151 lay->addWidget( lab );
150 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("Choose action"), this ); 152 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("Choose action"), this );
151 lay->addWidget( format ); 153 lay->addWidget( format );
152 format->setExclusive ( true ) ; 154 format->setExclusive ( true ) ;
153 vcal = new QRadioButton(i18n("Try again now"), format ); 155 vcal = new QRadioButton(i18n("Try again now"), format );
154 tcal = new QRadioButton(i18n("Try again later"), format ); 156 tcal = new QRadioButton(i18n("Try again later"), format );
155 ical = new QRadioButton(i18n("Try again tomorrow"), format ); 157 ical = new QRadioButton(i18n("Try again tomorrow"), format );
156 ocal = new QRadioButton(i18n("Disable backup"), format ); 158 ocal = new QRadioButton(i18n("Disable backup"), format );
157 vcal->setChecked( true ); 159 vcal->setChecked( true );
158 QPushButton * ok = new QPushButton( i18n("OK"), this ); 160 QPushButton * ok = new QPushButton( i18n("OK"), this );
159 lay->addWidget(ok ); 161 lay->addWidget(ok );
160 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 162 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
161 } 163 }
162 164
163 bool again() { return vcal->isChecked(); } 165 bool again() { return vcal->isChecked(); }
164 bool later() { return tcal->isChecked(); } 166 bool later() { return tcal->isChecked(); }
165 bool againTomorrow() { return ical->isChecked(); } 167 bool againTomorrow() { return ical->isChecked(); }
166private: 168private:
167 QRadioButton* vcal, *ical, *ocal, *tcal; 169 QRadioButton* vcal, *ical, *ocal, *tcal;
168}; 170};
169int KApplication::createBackup( QString fn, QString dp, int numBup ) 171int KApplication::createBackup( QString fn, QString dp, int numBup )
170{ 172{
171 if ( numBup < 1) return 3; 173 if ( numBup < 1) return 3;
172 int ret = 3; 174 int ret = 3;
173 //qDebug("KApplication::createBackup %s --- %s --- %d", fn.latin1(), dp.latin1(), numBup); 175 //qDebug("KApplication::createBackup %s --- %s --- %d", fn.latin1(), dp.latin1(), numBup);
174 QDir bupDir ( dp ); 176 QDir bupDir ( dp );
175 bool tryAgain = true; 177 bool tryAgain = true;
176 while ( tryAgain ) { 178 while ( tryAgain ) {
177 if ( !bupDir.exists() ) { 179 if ( !bupDir.exists() ) {
178 QString bd = dp.right(25); 180 QString bd = dp.right(25);
179 if ( dp.length() > 25 ) 181 if ( dp.length() > 25 )
180 bd = "..." + bd; 182 bd = "..." + bd;
181 KBackupPrefs noDir( i18n("<b>Backup directory does not exist: </b>") + bd); 183 KBackupPrefs noDir( i18n("<b>Backup directory does not exist: </b>") + bd);
182 if ( !noDir.exec() ) return 3; 184 if ( !noDir.exec() ) return 3;
183 if ( noDir.againTomorrow() ) { 185 if ( noDir.againTomorrow() ) {
184 return 0; 186 return 0;
185 } else if ( noDir.later() ) { 187 } else if ( noDir.later() ) {
186 return 3; 188 return 3;
187 } else if ( !noDir.again() ) { 189 } else if ( !noDir.again() ) {
188 return 2; 190 return 2;
189 } 191 }
190 } else { 192 } else {
191 tryAgain = false; 193 tryAgain = false;
192 } 194 }
193 } 195 }
194 // we have a valid dir! 196 // we have a valid dir!
195 QStringList allFileList = bupDir.entryList(QDir::Files); 197 QStringList allFileList = bupDir.entryList(QDir::Files);
196 QFileInfo fileInfo ( fn ); 198 QFileInfo fileInfo ( fn );
197 QString fName = fileInfo.fileName (); 199 QString fName = fileInfo.fileName ();
198 QStringList fileList; 200 QStringList fileList;
199 201
200 int i; 202 int i;
201 for ( i = 0; i < allFileList.count(); ++i ) { 203 for ( i = 0; i < allFileList.count(); ++i ) {
202 QString fi = allFileList[i]; 204 QString fi = allFileList[i];
203 if ( fi. find( fName ) > -1 ) 205 if ( fi. find( fName ) > -1 )
204 fileList.append( fi ); 206 fileList.append( fi );
205 } 207 }
206 qDebug("KApp: %d backup files exist ", fileList.count()); 208 qDebug("KApp: %d backup files exist ", fileList.count());
207 int count = fileList.count(); 209 int count = fileList.count();
208 fileList.sort(); 210 fileList.sort();
209 int remCount = 0; 211 int remCount = 0;
210 while ( count >= numBup ) { 212 while ( count >= numBup ) {
211 QString fnr = dp + "/"+fileList[remCount]; 213 QString fnr = dp + "/"+fileList[remCount];
212 QFile::remove( fnr ); 214 QFile::remove( fnr );
213 --count; 215 --count;
214 ++remCount; 216 ++remCount;
215 } 217 }
216 QDateTime mRunStart = QDateTime::currentDateTime(); 218 QDateTime mRunStart = QDateTime::currentDateTime();
217 QString file = "%1%2%3-%4%5%6-"; 219 QString file = "%1%2%3-%4%5%6-";
218 file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 ); 220 file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 );
219 file.replace ( QRegExp (" "), "0" ); 221 file.replace ( QRegExp (" "), "0" );
220 file += fName ; 222 file += fName ;
221 file = dp + file; 223 file = dp + file;
222 QString command; 224 QString command;
223 int res = 0; 225 int res = 0;
224#ifdef _WIN32_ 226#ifdef _WIN32_
225 command = "copy \""+ QDir::convertSeparators( fn)+ "\" \""+QDir::convertSeparators(file)+ "\" "; 227 command = "copy \""+ QDir::convertSeparators( fn)+ "\" \""+QDir::convertSeparators(file)+ "\" ";
226#else 228#else
227 command = "cp "+ fn+ " "+file; 229 command = "cp "+ fn+ " "+file;
228#endif 230#endif
229 //qDebug("command %s ",command.latin1() ); 231 //qDebug("command %s ",command.latin1() );
230 tryAgain = true; 232 tryAgain = true;
231 while ( tryAgain ) { 233 while ( tryAgain ) {
232 res = system ( command.latin1() ); 234 res = system ( command.latin1() );
233 qDebug("KApp: Copy result %d ", res); 235 qDebug("KApp: Copy result %d ", res);
234 if ( res != 0 ) { 236 if ( res != 0 ) {
235 KBackupPrefs noDir( i18n("<b>The backup copy command failed!</b>")); 237 KBackupPrefs noDir( i18n("<b>The backup copy command failed!</b>"));
236 if ( !noDir.exec() ) return 3; 238 if ( !noDir.exec() ) return 3;
237 if ( noDir.againTomorrow() ) { 239 if ( noDir.againTomorrow() ) {
238 return 0; 240 return 0;
239 } else if ( noDir.later() ) { 241 } else if ( noDir.later() ) {
240 return 3; 242 return 3;
241 } else if ( !noDir.again() ) { 243 } else if ( !noDir.again() ) {
242 return 2; 244 return 2;
243 } 245 }
244 } else { 246 } else {
245 tryAgain = false; 247 tryAgain = false;
246 } 248 }
247 } 249 }
248 return 1; 250 return 1;
249} 251}