-rw-r--r-- | korganizer/kofilterview.cpp | 86 | ||||
-rw-r--r-- | korganizer/kofilterview.h | 59 |
2 files changed, 101 insertions, 44 deletions
diff --git a/korganizer/kofilterview.cpp b/korganizer/kofilterview.cpp index 105028a..36ee2eb 100644 --- a/korganizer/kofilterview.cpp +++ b/korganizer/kofilterview.cpp | |||
@@ -27,6 +27,8 @@ | |||
27 | #include <qlayout.h> | 27 | #include <qlayout.h> |
28 | #include <qlabel.h> | 28 | #include <qlabel.h> |
29 | #include <qdialog.h> | 29 | #include <qdialog.h> |
30 | #include <qtextstream.h> | ||
31 | #include <qtextcodec.h> | ||
30 | 32 | ||
31 | 33 | ||
32 | #include <libkcal/calfilter.h> | 34 | #include <libkcal/calfilter.h> |
@@ -39,43 +41,8 @@ | |||
39 | #include <kmessagebox.h> | 41 | #include <kmessagebox.h> |
40 | 42 | ||
41 | 43 | ||
42 | #include <kurlrequester.h> | ||
43 | #include <klineedit.h> | ||
44 | |||
45 | class KONewCalPrefs : public QDialog | ||
46 | { | ||
47 | public: | ||
48 | KONewCalPrefs( QWidget *parent=0, const char *name=0 ) : | ||
49 | QDialog( parent, name, true ) | ||
50 | { | ||
51 | setCaption( i18n("Add new Calendar") ); | ||
52 | QVBoxLayout* lay = new QVBoxLayout( this ); | ||
53 | lay->setSpacing( 3 ); | ||
54 | lay->setMargin( 3 ); | ||
55 | QLabel * lab = new QLabel( i18n("<b>Name of new calendar:</b>"), this ); | ||
56 | lay->addWidget( lab ); | ||
57 | nameE = new KLineEdit( this ); | ||
58 | lay->addWidget( nameE ); | ||
59 | lab = new QLabel( i18n("Local ical (*.ics) file:"), this ); | ||
60 | lay->addWidget( lab ); | ||
61 | url = new KURLRequester ( this ); | ||
62 | lay->addWidget( url ); | ||
63 | QPushButton * ok = new QPushButton( i18n("OK"), this ); | ||
64 | lay->addWidget( ok ); | ||
65 | QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); | ||
66 | lay->addWidget( cancel ); | ||
67 | connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) ); | ||
68 | connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); | ||
69 | //resize( 200, 200 ); | ||
70 | } | ||
71 | |||
72 | QString calName() { return nameE->text(); } | ||
73 | QString calFileName() { return url->url(); } | ||
74 | private: | ||
75 | KLineEdit* nameE; | ||
76 | KURLRequester *url; | ||
77 | }; | ||
78 | 44 | ||
45 | |||
79 | 46 | ||
80 | KOFilterView::KOFilterView(QPtrList<CalFilter> *filterList,QWidget* parent, | 47 | KOFilterView::KOFilterView(QPtrList<CalFilter> *filterList,QWidget* parent, |
81 | const char* name,WFlags fl ) | 48 | const char* name,WFlags fl ) |
@@ -242,7 +209,7 @@ void KOCalEditView::infoCal( int id ) | |||
242 | QString name = KOPrefs::instance()->getCalendar( id )->mName; | 209 | QString name = KOPrefs::instance()->getCalendar( id )->mName; |
243 | QString file = KOPrefs::instance()->getCalendar( id )->mFileName; | 210 | QString file = KOPrefs::instance()->getCalendar( id )->mFileName; |
244 | if ( KOPrefs::instance()->getCalendar( id )->mErrorOnLoad ) { | 211 | if ( KOPrefs::instance()->getCalendar( id )->mErrorOnLoad ) { |
245 | if ( KMessageBox::Yes == KMessageBox::questionYesNo( this, i18n("The calendar <tr><b>%1</b><tr> is not loaded! Loading of file <tr><b>%2</b><tr> failed! <tr><b>Try again to load the calendar?</b>").arg(name).arg(file) ) ) { | 212 | if ( KMessageBox::Yes == KMessageBox::questionYesNo( this, i18n("The calendar <tr><b>%1</b><tr> is not loaded! Loading of file <tr><b>%2</b><tr>failed!<tr><b>Try again to load the calendar?</b>").arg(name).arg(file) ) ) { |
246 | emit calendarAdded( id ); | 213 | emit calendarAdded( id ); |
247 | emit needsUpdate(); | 214 | emit needsUpdate(); |
248 | QTimer::singleShot( 0, this, SLOT ( readConfig() ) ); | 215 | QTimer::singleShot( 0, this, SLOT ( readConfig() ) ); |
@@ -373,15 +340,46 @@ void KOCalEditView::readConfig() | |||
373 | } | 340 | } |
374 | void KOCalEditView::addCal() | 341 | void KOCalEditView::addCal() |
375 | { | 342 | { |
376 | KONewCalPrefs prefs ( this ); | 343 | bool tryagain = true; |
377 | if ( ! prefs.exec() ) | 344 | QString name, file; |
378 | return; | 345 | while ( tryagain ) { |
379 | QString name = prefs.calName(); | 346 | KONewCalPrefs prefs ( this ); |
380 | QString file = prefs.calFileName(); | 347 | if ( !name.isEmpty() ) prefs.nameE->setText( name ); |
348 | if ( !file.isEmpty() ) prefs.url->setURL( file ); | ||
349 | if ( ! prefs.exec() ) | ||
350 | return; | ||
351 | name = prefs.calName(); | ||
352 | file = prefs.calFileName(); | ||
353 | tryagain = false; | ||
354 | KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first(); | ||
355 | while ( kkf ) { | ||
356 | if ( kkf->mName == name ) { | ||
357 | KMessageBox::information( this, i18n("Sorry, the calendar name already exists!\nPlease choose another name!") ); | ||
358 | name = ""; | ||
359 | break; | ||
360 | tryagain = true; | ||
361 | } | ||
362 | if ( kkf->mFileName == file ) { | ||
363 | |||
364 | break; | ||
365 | tryagain = true; | ||
366 | } | ||
367 | kkf = KOPrefs::instance()->mCalendars.next(); | ||
368 | } | ||
369 | } | ||
381 | QFileInfo fi ( file ); | 370 | QFileInfo fi ( file ); |
382 | if (!fi.exists() ) { | 371 | if (!fi.exists() ) { |
383 | KMessageBox::information( this, i18n("File does not exist!\nNo calendar added!")); | 372 | if ( KMessageBox::questionYesNo(this, i18n("The file does not exist!\nShall I create it for you?")) == KMessageBox::No ) |
384 | return; | 373 | return; |
374 | QFile fileIn( file ); | ||
375 | if (!fileIn.open( IO_WriteOnly ) ) { | ||
376 | KMessageBox::sorry( this, i18n("Sorry, cannot create the file!\nNo calendar added!") ); | ||
377 | return; | ||
378 | } | ||
379 | QTextStream tsIn( &fileIn ); | ||
380 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); | ||
381 | tsIn << "BEGIN:VCALENDAR\nPRODID:-//KDE-Pim//Platform-independent 2.1.0\nVERSION:2.0\nEND:VCALENDAR\n"; | ||
382 | fileIn.close(); | ||
385 | } | 383 | } |
386 | KopiCalendarFile * kkf = KOPrefs::instance()->getNewCalendar(); | 384 | KopiCalendarFile * kkf = KOPrefs::instance()->getNewCalendar(); |
387 | kkf->mName = name; | 385 | kkf->mName = name; |
diff --git a/korganizer/kofilterview.h b/korganizer/kofilterview.h index 3ab316f..945947a 100644 --- a/korganizer/kofilterview.h +++ b/korganizer/kofilterview.h | |||
@@ -25,6 +25,8 @@ | |||
25 | 25 | ||
26 | #include <qstring.h> | 26 | #include <qstring.h> |
27 | #include <qcheckbox.h> | 27 | #include <qcheckbox.h> |
28 | #include <qlayout.h> | ||
29 | #include <qlabel.h> | ||
28 | #include <qscrollview.h> | 30 | #include <qscrollview.h> |
29 | #include <qpushbutton.h> | 31 | #include <qpushbutton.h> |
30 | #include <kconfig.h> | 32 | #include <kconfig.h> |
@@ -32,9 +34,66 @@ | |||
32 | 34 | ||
33 | #include <libkcal/calfilter.h> | 35 | #include <libkcal/calfilter.h> |
34 | 36 | ||
37 | #include <kurlrequester.h> | ||
38 | #include <klineedit.h> | ||
39 | #include <kglobal.h> | ||
40 | #include <kmessagebox.h> | ||
41 | |||
35 | class QGridLayout; | 42 | class QGridLayout; |
36 | 43 | ||
37 | using namespace KCal; | 44 | using namespace KCal; |
45 | |||
46 | class KONewCalPrefs : public QDialog | ||
47 | { | ||
48 | Q_OBJECT | ||
49 | public: | ||
50 | KONewCalPrefs( QWidget *parent=0, const char *name=0 ) : | ||
51 | QDialog( parent, name, true ) | ||
52 | { | ||
53 | setCaption( i18n("Add new Calendar") ); | ||
54 | QVBoxLayout* lay = new QVBoxLayout( this ); | ||
55 | lay->setSpacing( 3 ); | ||
56 | lay->setMargin( 3 ); | ||
57 | QLabel * lab = new QLabel( i18n("<b>Name of new calendar:</b>"), this ); | ||
58 | lay->addWidget( lab ); | ||
59 | nameE = new KLineEdit( this ); | ||
60 | lay->addWidget( nameE ); | ||
61 | lab = new QLabel( i18n("<b>Local ical (*.ics) file:</b>"), this ); | ||
62 | lay->addWidget( lab ); | ||
63 | url = new KURLRequester ( this ); | ||
64 | lay->addWidget( url ); | ||
65 | QPushButton * ok = new QPushButton( i18n("OK"), this ); | ||
66 | lay->addWidget( ok ); | ||
67 | QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); | ||
68 | lay->addWidget( cancel ); | ||
69 | connect ( ok,SIGNAL(clicked() ),this , SLOT ( checkValid() ) ); | ||
70 | connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) ); | ||
71 | setMinimumWidth( 220 ); | ||
72 | resize(sizeHint() ); | ||
73 | } | ||
74 | |||
75 | QString calName() { return nameE->text(); } | ||
76 | QString calFileName() { return url->url(); } | ||
77 | |||
78 | public slots: | ||
79 | void checkValid() { | ||
80 | if ( nameE->text().isEmpty() ) { | ||
81 | KMessageBox::information( this, i18n("Sorry, the calendar name is empty!") ); | ||
82 | nameE->setText( "LPQJ_"+ QString::number( QTime::currentTime().msec () )); | ||
83 | return; | ||
84 | } | ||
85 | if ( url->url().isEmpty() ) { | ||
86 | KMessageBox::information( this, i18n("Sorry, the file name is empty!") ); | ||
87 | return; | ||
88 | } | ||
89 | accept(); | ||
90 | } | ||
91 | |||
92 | public: | ||
93 | KLineEdit* nameE; | ||
94 | KURLRequester *url; | ||
95 | }; | ||
96 | |||
38 | class KOCalButton : public QPushButton | 97 | class KOCalButton : public QPushButton |
39 | { | 98 | { |
40 | Q_OBJECT | 99 | Q_OBJECT |