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