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