summaryrefslogtreecommitdiffabout
path: root/microkde
authorzautrix <zautrix>2005-04-22 09:02:00 (UTC)
committer zautrix <zautrix>2005-04-22 09:02:00 (UTC)
commit86518702ea6efc14992580a7fc6c089905cfb716 (patch) (unidiff)
tree29ba7c61bd1948a0eb1155d1f4f06f48aeaadd9f /microkde
parentabf935a18e55fcbe221d5a7c652840af279e2e3f (diff)
downloadkdepimpi-86518702ea6efc14992580a7fc6c089905cfb716.zip
kdepimpi-86518702ea6efc14992580a7fc6c089905cfb716.tar.gz
kdepimpi-86518702ea6efc14992580a7fc6c089905cfb716.tar.bz2
fixes
Diffstat (limited to 'microkde') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kapplication.cpp13
1 files changed, 6 insertions, 7 deletions
diff --git a/microkde/kapplication.cpp b/microkde/kapplication.cpp
index 566bb41..2c9e3b6 100644
--- a/microkde/kapplication.cpp
+++ b/microkde/kapplication.cpp
@@ -45,203 +45,202 @@ int KApplication::execDialog( QDialog* d )
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 + *wid > dWid ) { 54 if ( *x + *wid > dWid ) {
55 *x = 0; 55 *x = 0;
56 if ( *wid > dWid ) 56 if ( *wid > dWid )
57 *wid = dWid; 57 *wid = dWid;
58 } 58 }
59 if ( *y + *hei > dHei ) { 59 if ( *y + *hei > dHei ) {
60 *y = 0; 60 *y = 0;
61 if ( *hei > dHei ) 61 if ( *hei > dHei )
62 *hei = dHei; 62 *hei = dHei;
63 } 63 }
64} 64}
65void KApplication::showFile(QString caption, QString fn) 65void KApplication::showFile(QString caption, QString fn)
66{ 66{
67 QString text; 67 QString text;
68 QString fileName; 68 QString fileName;
69#ifndef DESKTOP_VERSION 69#ifndef DESKTOP_VERSION
70 fileName = getenv("QPEDIR"); 70 fileName = getenv("QPEDIR");
71 fileName += "/pics/" + fn ; 71 fileName += "/pics/" + fn ;
72#else 72#else
73 fileName = qApp->applicationDirPath () + "/" + fn; 73 fileName = qApp->applicationDirPath () + "/" + fn;
74#endif 74#endif
75 QFile file( fileName ); 75 QFile file( fileName );
76 if (!file.open( IO_ReadOnly ) ) { 76 if (!file.open( IO_ReadOnly ) ) {
77 return ; 77 return ;
78 } 78 }
79 QTextStream ts( &file ); 79 QTextStream ts( &file );
80 text = ts.read(); 80 text = ts.read();
81 file.close(); 81 file.close();
82 KApplication::showText( caption, text ); 82 KApplication::showText( caption, text );
83 83
84} 84}
85 85
86bool KApplication::convert2latin1(QString fileName) 86bool KApplication::convert2latin1(QString fileName)
87{ 87{
88 QString text; 88 QString text;
89 QFile file( fileName ); 89 QFile file( fileName );
90 if (!file.open( IO_ReadOnly ) ) { 90 if (!file.open( IO_ReadOnly ) ) {
91 return false; 91 return false;
92 92
93 } 93 }
94 QTextStream ts( &file ); 94 QTextStream ts( &file );
95 ts.setEncoding( QTextStream::UnicodeUTF8 ); 95 ts.setEncoding( QTextStream::UnicodeUTF8 );
96 text = ts.read(); 96 text = ts.read();
97 file.close(); 97 file.close();
98 if (!file.open( IO_WriteOnly ) ) { 98 if (!file.open( IO_WriteOnly ) ) {
99 return false; 99 return false;
100 } 100 }
101 QTextStream tsIn( &file ); 101 QTextStream tsIn( &file );
102 tsIn.setEncoding( QTextStream::Latin1 ); 102 tsIn.setEncoding( QTextStream::Latin1 );
103 tsIn << text.latin1(); 103 tsIn << text.latin1();
104 file.close(); 104 file.close();
105 return true; 105 return true;
106 106
107 107
108} 108}
109void KApplication::showText(QString caption, QString text) 109void KApplication::showText(QString caption, QString text)
110{ 110{
111 QDialog dia( 0, "name", true ); ; 111 QDialog dia( 0, "name", true ); ;
112 dia.setCaption( caption ); 112 dia.setCaption( caption );
113 QVBoxLayout* lay = new QVBoxLayout( &dia ); 113 QVBoxLayout* lay = new QVBoxLayout( &dia );
114 lay->setSpacing( 3 ); 114 lay->setSpacing( 3 );
115 lay->setMargin( 3 ); 115 lay->setMargin( 3 );
116 KTextEdit tb ( &dia ); 116 KTextEdit tb ( &dia );
117 tb.setWordWrap( QMultiLineEdit::WidgetWidth ); 117 tb.setWordWrap( QMultiLineEdit::WidgetWidth );
118 lay->addWidget( &tb ); 118 lay->addWidget( &tb );
119 tb.setText( text ); 119 tb.setText( text );
120#ifdef DESKTOP_VERSION 120#ifdef DESKTOP_VERSION
121 dia.resize( 640, 480); 121 dia.resize( 640, 480);
122#else 122#else
123 dia.showMaximized(); 123 dia.showMaximized();
124#endif 124#endif
125 dia.exec(); 125 dia.exec();
126 126
127} 127}
128 128
129#include <qlabel.h> 129#include <qlabel.h>
130#include <qpushbutton.h> 130#include <qpushbutton.h>
131#include <qlayout.h> 131#include <qlayout.h>
132#include <qdir.h> 132#include <qdir.h>
133#include <qradiobutton.h> 133#include <qradiobutton.h>
134#include <qbuttongroup.h> 134#include <qbuttongroup.h>
135#include "kglobal.h" 135#include "kglobal.h"
136#include "klocale.h" 136#include "klocale.h"
137 137
138class KBackupPrefs : public QDialog 138class KBackupPrefs : public QDialog
139{ 139{
140 public: 140 public:
141 KBackupPrefs( QString message , QWidget *parent=0, const char *name=0 ) : 141 KBackupPrefs( QString message , QWidget *parent=0, const char *name=0 ) :
142 QDialog( parent, name, true ) 142 QDialog( parent, name, true )
143 { 143 {
144 setCaption( i18n("Backup Failed!") ); 144 setCaption( i18n("Backup Failed!") );
145 QVBoxLayout* lay = new QVBoxLayout( this ); 145 QVBoxLayout* lay = new QVBoxLayout( this );
146 lay->setSpacing( 3 ); 146 lay->setSpacing( 3 );
147 lay->setMargin( 3 ); 147 lay->setMargin( 3 );
148 QLabel * lab = new QLabel( message, this ); 148 QLabel * lab = new QLabel( message, this );
149 lay->addWidget( lab ); 149 lay->addWidget( lab );
150 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("Choose action"), this ); 150 QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("Choose action"), this );
151 lay->addWidget( format ); 151 lay->addWidget( format );
152 format->setExclusive ( true ) ; 152 format->setExclusive ( true ) ;
153 vcal = new QRadioButton(i18n("Try again now"), format ); 153 vcal = new QRadioButton(i18n("Try again now"), format );
154 tcal = new QRadioButton(i18n("Try again later"), format ); 154 tcal = new QRadioButton(i18n("Try again later"), format );
155 ical = new QRadioButton(i18n("Try again tomorrow"), format ); 155 ical = new QRadioButton(i18n("Try again tomorrow"), format );
156 ocal = new QRadioButton(i18n("Disable backup"), format ); 156 ocal = new QRadioButton(i18n("Disable backup"), format );
157 vcal->setChecked( true ); 157 vcal->setChecked( true );
158 QPushButton * ok = new QPushButton( i18n("OK"), this ); 158 QPushButton * ok = new QPushButton( i18n("OK"), this );
159 lay->addWidget(ok ); 159 lay->addWidget(ok );
160 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); 160 connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
161 } 161 }
162 162
163 bool again() { return vcal->isChecked(); } 163 bool again() { return vcal->isChecked(); }
164 bool later() { return tcal->isChecked(); } 164 bool later() { return tcal->isChecked(); }
165 bool againTomorrow() { return ical->isChecked(); } 165 bool againTomorrow() { return ical->isChecked(); }
166private: 166private:
167 QRadioButton* vcal, *ical, *ocal, *tcal; 167 QRadioButton* vcal, *ical, *ocal, *tcal;
168}; 168};
169int KApplication::createBackup( QString fn, QString dp, int numBup ) 169int KApplication::createBackup( QString fn, QString dp, int numBup )
170{ 170{
171 if ( numBup < 1) return 3; 171 if ( numBup < 1) return 3;
172 int ret = 3; 172 int ret = 3;
173 qDebug("KApplication::createBackup %s --- %s --- %d", fn.latin1(), dp.latin1(), numBup); 173 //qDebug("KApplication::createBackup %s --- %s --- %d", fn.latin1(), dp.latin1(), numBup);
174 QDir bupDir ( dp ); 174 QDir bupDir ( dp );
175 bool tryAgain = true; 175 bool tryAgain = true;
176 while ( tryAgain ) { 176 while ( tryAgain ) {
177 if ( !bupDir.exists() ) { 177 if ( !bupDir.exists() ) {
178 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));
179 if ( !noDir.exec() ) return 3; 179 if ( !noDir.exec() ) return 3;
180 if ( noDir.againTomorrow() ) { 180 if ( noDir.againTomorrow() ) {
181 return 0; 181 return 0;
182 } else if ( noDir.later() ) { 182 } else if ( noDir.later() ) {
183 return 3; 183 return 3;
184 } else if ( !noDir.again() ) { 184 } else if ( !noDir.again() ) {
185 return 2; 185 return 2;
186 } 186 }
187 } else { 187 } else {
188 tryAgain = false; 188 tryAgain = false;
189 } 189 }
190 } 190 }
191 // we have a valid dir! 191 // we have a valid dir!
192 QStringList allFileList = bupDir.entryList(QDir::Files); 192 QStringList allFileList = bupDir.entryList(QDir::Files);
193 QFileInfo fileInfo ( fn ); 193 QFileInfo fileInfo ( fn );
194 QString fName = fileInfo.fileName (); 194 QString fName = fileInfo.fileName ();
195 QStringList fileList; 195 QStringList fileList;
196 196
197 int i; 197 int i;
198 for ( i = 0; i < allFileList.count(); ++i ) { 198 for ( i = 0; i < allFileList.count(); ++i ) {
199 QString fi = allFileList[i]; 199 QString fi = allFileList[i];
200 if ( fi. find( fName ) > -1 ) 200 if ( fi. find( fName ) > -1 )
201 fileList.append( fi ); 201 fileList.append( fi );
202 } 202 }
203 qDebug("%d backup files exist ", fileList.count()); 203 qDebug("KApp: %d backup files exist ", fileList.count());
204 int count = fileList.count(); 204 int count = fileList.count();
205 fileList.sort(); 205 fileList.sort();
206 int remCount = 0; 206 int remCount = 0;
207 while ( count >= numBup ) { 207 while ( count >= numBup ) {
208 QString fnr = dp + "/"+fileList[remCount]; 208 QString fnr = dp + "/"+fileList[remCount];
209 QFile::remove( fnr ); 209 QFile::remove( fnr );
210 --count; 210 --count;
211 ++remCount; 211 ++remCount;
212 } 212 }
213 QDateTime mRunStart = QDateTime::currentDateTime(); 213 QDateTime mRunStart = QDateTime::currentDateTime();
214 QString file = "%1%2%3-%4%5%6-"; 214 QString file = "%1%2%3-%4%5%6-";
215 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 ); 215 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 );
216 file.replace ( QRegExp (" "), "0" ); 216 file.replace ( QRegExp (" "), "0" );
217 file += fName ; 217 file += fName ;
218 file = dp + "/"+file; 218 file = dp + file;
219 QString command; 219 QString command;
220 int res = 0; 220 int res = 0;
221#ifdef _WIN32_ 221#ifdef _WIN32_
222 command = "xcopy "+ fn+ " "+file; 222 command = "copy \""+ QDir::convertSeparators( fn)+ "\" \""+QDir::convertSeparators(file)+ "\" ";
223 command = QDir::convertSeparators( command );
224#else 223#else
225 command = "cp "+ fn+ " "+file; 224 command = "cp "+ fn+ " "+file;
226#endif 225#endif
227 qDebug("command %s ",command.latin1() ); 226 //qDebug("command %s ",command.latin1() );
228 tryAgain = true; 227 tryAgain = true;
229 while ( tryAgain ) { 228 while ( tryAgain ) {
230 res = system ( command.latin1() ); 229 res = system ( command.latin1() );
231 qDebug("copy result %d ", res); 230 qDebug("KApp: Copy result %d ", res);
232 if ( res != 0 ) { 231 if ( res != 0 ) {
233 KBackupPrefs noDir( i18n("<b>The backup copy command failed!</b>")); 232 KBackupPrefs noDir( i18n("<b>The backup copy command failed!</b>"));
234 if ( !noDir.exec() ) return 3; 233 if ( !noDir.exec() ) return 3;
235 if ( noDir.againTomorrow() ) { 234 if ( noDir.againTomorrow() ) {
236 return 0; 235 return 0;
237 } else if ( noDir.later() ) { 236 } else if ( noDir.later() ) {
238 return 3; 237 return 3;
239 } else if ( !noDir.again() ) { 238 } else if ( !noDir.again() ) {
240 return 2; 239 return 2;
241 } 240 }
242 } else { 241 } else {
243 tryAgain = false; 242 tryAgain = false;
244 } 243 }
245 } 244 }
246 return 1; 245 return 1;
247} 246}