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,188 +1,190 @@
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;