author | zautrix <zautrix> | 2005-02-05 14:31:01 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-02-05 14:31:01 (UTC) |
commit | 231a90376b096687770b2b029d4a3d2efa232b2e (patch) (unidiff) | |
tree | 609a9b8434fe28eab8ea9a1a7e4441a37be0b246 /korganizer | |
parent | 7be6218eaf6bd29d4bc09d0bb79bb0dec6da9ae5 (diff) | |
download | kdepimpi-231a90376b096687770b2b029d4a3d2efa232b2e.zip kdepimpi-231a90376b096687770b2b029d4a3d2efa232b2e.tar.gz kdepimpi-231a90376b096687770b2b029d4a3d2efa232b2e.tar.bz2 |
many fixes
-rw-r--r-- | korganizer/journalentry.cpp | 83 | ||||
-rw-r--r-- | korganizer/journalentry.h | 2 | ||||
-rw-r--r-- | korganizer/koeventeditor.cpp | 4 |
3 files changed, 85 insertions, 4 deletions
diff --git a/korganizer/journalentry.cpp b/korganizer/journalentry.cpp index 7af5cf4..dca42e0 100644 --- a/korganizer/journalentry.cpp +++ b/korganizer/journalentry.cpp | |||
@@ -1,170 +1,249 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | // | 24 | // |
25 | // Journal Entry | 25 | // Journal Entry |
26 | 26 | ||
27 | #include <qlabel.h> | 27 | #include <qlabel.h> |
28 | #include <qlayout.h> | 28 | #include <qlayout.h> |
29 | #include <qvbox.h> | ||
30 | #include <qfile.h> | ||
31 | #include <qdir.h> | ||
32 | #include <qtextstream.h> | ||
33 | #include <qtextcodec.h> | ||
34 | #include <qpixmap.h> | ||
35 | #include <qpushbutton.h> | ||
29 | 36 | ||
30 | #include <kdebug.h> | 37 | #include <kdebug.h> |
31 | #include <kglobal.h> | 38 | #include <kglobal.h> |
32 | #include <klocale.h> | 39 | #include <klocale.h> |
33 | #include <ktextedit.h> | 40 | #include <ktextedit.h> |
41 | #include <kfiledialog.h> | ||
42 | #include <kmessagebox.h> | ||
34 | #include "koprefs.h" | 43 | #include "koprefs.h" |
35 | 44 | ||
36 | #include <libkcal/journal.h> | 45 | #include <libkcal/journal.h> |
37 | #include <libkcal/calendarresources.h> | 46 | #include <libkcal/calendarresources.h> |
38 | #include <libkcal/resourcecalendar.h> | 47 | #include <libkcal/resourcecalendar.h> |
39 | #include <kresources/resourceselectdialog.h> | 48 | #include <kresources/resourceselectdialog.h> |
40 | 49 | ||
41 | #include "journalentry.h" | 50 | #include "journalentry.h" |
42 | //#include "journalentry.moc" | 51 | //#include "journalentry.moc" |
43 | #ifndef DESKTOP_VERSION | 52 | #ifndef DESKTOP_VERSION |
44 | #include <qpe/qpeapplication.h> | 53 | #include <qpe/qpeapplication.h> |
45 | #endif | 54 | #endif |
46 | JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : | 55 | JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : |
47 | QFrame(parent) | 56 | QFrame(parent) |
48 | { | 57 | { |
49 | mCalendar = calendar; | 58 | mCalendar = calendar; |
50 | mJournal = 0; | 59 | mJournal = 0; |
51 | mDirty = false; | 60 | mDirty = false; |
52 | 61 | ||
53 | mTitleLabel = new QLabel(i18n("Title"),this); | 62 | QHBox * vb = new QHBox ( this ); |
63 | QPushButton * loadTemplate = new QPushButton( vb ); | ||
64 | QPushButton * saveTemplate = new QPushButton( vb ); | ||
65 | QIconSet icon; | ||
66 | if ( QApplication::desktop()->width() < 321 ) | ||
67 | icon = SmallIcon("fileexport16"); | ||
68 | else | ||
69 | icon = SmallIcon("fileexport"); | ||
70 | saveTemplate->setIconSet (icon ) ; | ||
71 | int size = saveTemplate->sizeHint().height(); | ||
72 | saveTemplate->setFixedSize( size, size ); | ||
73 | if ( QApplication::desktop()->width() < 321 ) | ||
74 | icon = SmallIcon("fileimport16"); | ||
75 | else | ||
76 | icon = SmallIcon("fileimport"); | ||
77 | loadTemplate->setIconSet (icon ) ; | ||
78 | loadTemplate->setFixedSize( size, size ); | ||
79 | |||
80 | mTitleLabel = new QLabel(i18n("Title"),vb); | ||
54 | mTitleLabel->setMargin(2); | 81 | mTitleLabel->setMargin(2); |
55 | mTitleLabel->setAlignment(AlignCenter); | 82 | mTitleLabel->setAlignment(AlignCenter); |
56 | 83 | ||
57 | mEditor = new KTextEdit(this); | 84 | mEditor = new KTextEdit(this); |
58 | connect(mEditor,SIGNAL(textChanged()),SLOT(setDirty())); | 85 | connect(mEditor,SIGNAL(textChanged()),SLOT(setDirty())); |
59 | #ifndef DESKTOP_VERSION | 86 | #ifndef DESKTOP_VERSION |
60 | QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold ); | 87 | QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold ); |
61 | #endif | 88 | #endif |
62 | mEditor->setWordWrap( KTextEdit::WidgetWidth ); | 89 | mEditor->setWordWrap( KTextEdit::WidgetWidth ); |
63 | QBoxLayout *topLayout = new QVBoxLayout(this); | 90 | QBoxLayout *topLayout = new QVBoxLayout(this); |
64 | topLayout->addWidget(mTitleLabel); | 91 | topLayout->addWidget(vb); |
65 | topLayout->addWidget(mEditor); | 92 | topLayout->addWidget(mEditor); |
66 | mEditor->installEventFilter(this); | 93 | mEditor->installEventFilter(this); |
94 | connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) ); | ||
95 | connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) ); | ||
67 | } | 96 | } |
68 | 97 | ||
69 | JournalEntry::~JournalEntry() | 98 | JournalEntry::~JournalEntry() |
70 | { | 99 | { |
71 | } | 100 | } |
72 | 101 | ||
102 | void JournalEntry::slotSaveTemplate() | ||
103 | { | ||
104 | QString fileName =locateLocal( "templates", "journals" ); | ||
105 | QDir t_dir; | ||
106 | if ( !t_dir.exists(fileName) ) | ||
107 | t_dir.mkdir ( fileName ); | ||
108 | fileName += "/journal"; | ||
109 | fileName = KFileDialog::getSaveFileName( fileName , i18n("Save as Journal template"), this ); | ||
110 | if ( fileName.length() == 0 ) | ||
111 | return; | ||
112 | |||
113 | QFile fileIn( fileName ); | ||
114 | if (!fileIn.open( IO_WriteOnly ) ) { | ||
115 | KMessageBox::error( this, i18n("Error saving template file\n '%1'.") | ||
116 | .arg( fileName ) ); | ||
117 | return; | ||
118 | } | ||
119 | // QString text; | ||
120 | QTextStream tsIn( &fileIn ); | ||
121 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); | ||
122 | tsIn << mEditor->text(); | ||
123 | fileIn.close(); | ||
124 | } | ||
125 | void JournalEntry::slotLoadTemplate() | ||
126 | { | ||
127 | QString fileName =locateLocal( "templates", "journals" ); | ||
128 | QDir t_dir; | ||
129 | if ( !t_dir.exists(fileName) ) | ||
130 | t_dir.mkdir ( fileName ); | ||
131 | fileName += "/journal"; | ||
132 | fileName = KFileDialog::getOpenFileName( fileName , i18n("Insert Journal template"), this ); | ||
133 | if ( fileName.length() == 0 ) | ||
134 | return; | ||
135 | QFile fileIn( fileName ); | ||
136 | if (!fileIn.open( IO_ReadOnly ) ) { | ||
137 | KMessageBox::error( this, i18n("Error loading template file\n '%1'.") | ||
138 | .arg( fileName ) ); | ||
139 | return; | ||
140 | } | ||
141 | QTextStream tsIn( &fileIn ); | ||
142 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); | ||
143 | QString text = tsIn.read(); | ||
144 | fileIn.close(); | ||
145 | int line, col; | ||
146 | mEditor->getCursorPosition (& line, & col ); | ||
147 | mEditor-> insertAt ( text, line, col, true ); | ||
148 | //mEditor->setIgnoreMark( true ); | ||
149 | setDirty(); | ||
150 | } | ||
73 | void JournalEntry::setDate(const QDate &date) | 151 | void JournalEntry::setDate(const QDate &date) |
74 | { | 152 | { |
75 | writeJournal(); | 153 | writeJournal(); |
76 | 154 | ||
77 | mTitleLabel->setText(KGlobal::locale()->formatDate(date)); | 155 | mTitleLabel->setText(KGlobal::locale()->formatDate(date)); |
78 | 156 | ||
79 | 157 | ||
80 | mDate = date; | 158 | mDate = date; |
81 | } | 159 | } |
82 | 160 | ||
83 | void JournalEntry::setJournal(Journal *journal) | 161 | void JournalEntry::setJournal(Journal *journal) |
84 | { | 162 | { |
85 | writeJournal(); | 163 | writeJournal(); |
86 | 164 | ||
87 | mJournal = journal; | 165 | mJournal = journal; |
88 | 166 | ||
89 | mEditor->setText(mJournal->description()); | 167 | mEditor->setText(mJournal->description()); |
90 | 168 | ||
91 | mDirty = false; | 169 | mDirty = false; |
92 | } | 170 | } |
93 | 171 | ||
94 | Journal *JournalEntry::journal() const | 172 | Journal *JournalEntry::journal() const |
95 | { | 173 | { |
96 | return mJournal; | 174 | return mJournal; |
97 | } | 175 | } |
98 | 176 | ||
99 | void JournalEntry::setDirty() | 177 | void JournalEntry::setDirty() |
100 | { | 178 | { |
101 | mDirty = true; | 179 | mDirty = true; |
102 | 180 | ||
103 | // kdDebug() << "JournalEntry::setDirty()" << endl; | 181 | // kdDebug() << "JournalEntry::setDirty()" << endl; |
104 | } | 182 | } |
105 | 183 | ||
106 | void JournalEntry::clear() | 184 | void JournalEntry::clear() |
107 | { | 185 | { |
108 | mJournal = 0; | 186 | mJournal = 0; |
109 | mEditor->setText(""); | 187 | mEditor->setText(""); |
110 | } | 188 | } |
111 | 189 | ||
112 | bool JournalEntry::eventFilter( QObject *o, QEvent *e ) | 190 | bool JournalEntry::eventFilter( QObject *o, QEvent *e ) |
113 | { | 191 | { |
114 | // kdDebug() << "JournalEntry::event received " << e->type() << endl; | 192 | // kdDebug() << "JournalEntry::event received " << e->type() << endl; |
115 | 193 | ||
116 | if ( e->type() == QEvent::FocusOut ) { | 194 | if ( e->type() == QEvent::FocusOut ) { |
117 | writeJournal(); | 195 | writeJournal(); |
118 | } | 196 | } |
119 | if ( e->type() == QEvent::KeyPress ) { | 197 | if ( e->type() == QEvent::KeyPress ) { |
120 | QKeyEvent * k = (QKeyEvent *) e; | 198 | QKeyEvent * k = (QKeyEvent *) e; |
121 | if ( k->state() == Qt::ControlButton ) { | 199 | if ( k->state() == Qt::ControlButton ) { |
122 | k->ignore(); | 200 | k->ignore(); |
123 | //return true; | 201 | //return true; |
124 | } | 202 | } |
125 | } | 203 | } |
126 | 204 | ||
127 | return QFrame::eventFilter( o, e ); // standard event processing | 205 | return QFrame::eventFilter( o, e ); // standard event processing |
128 | } | 206 | } |
129 | 207 | ||
130 | void JournalEntry::writeJournal() | 208 | void JournalEntry::writeJournal() |
131 | { | 209 | { |
132 | // kdDebug() << "JournalEntry::writeJournal()" << endl; | 210 | // kdDebug() << "JournalEntry::writeJournal()" << endl; |
133 | if (!mDirty) return; | 211 | if (!mDirty) return; |
134 | 212 | ||
135 | if (mEditor->text().isEmpty()) { | 213 | if (mEditor->text().isEmpty()) { |
136 | if ( mJournal ) { | 214 | if ( mJournal ) { |
137 | mDirty = false; | 215 | mDirty = false; |
138 | bool conf = KOPrefs::instance()->mConfirm; | 216 | bool conf = KOPrefs::instance()->mConfirm; |
139 | KOPrefs::instance()->mConfirm = false; | 217 | KOPrefs::instance()->mConfirm = false; |
140 | emit deleteJournal(mJournal); | 218 | emit deleteJournal(mJournal); |
141 | KOPrefs::instance()->mConfirm = conf; | 219 | KOPrefs::instance()->mConfirm = conf; |
142 | mJournal = 0; | 220 | mJournal = 0; |
143 | } | 221 | } |
144 | return; | 222 | return; |
145 | } | 223 | } |
146 | 224 | ||
147 | // kdDebug() << "JournalEntry::writeJournal()..." << endl; | 225 | // kdDebug() << "JournalEntry::writeJournal()..." << endl; |
148 | 226 | ||
149 | if (!mJournal) { | 227 | if (!mJournal) { |
150 | mJournal = new Journal; | 228 | mJournal = new Journal; |
151 | mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0))); | 229 | mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0))); |
152 | mCalendar->addJournal(mJournal); | 230 | mCalendar->addJournal(mJournal); |
153 | } | 231 | } |
154 | 232 | ||
155 | mJournal->setDescription(mEditor->text()); | 233 | mJournal->setDescription(mEditor->text()); |
234 | //qDebug("tttt%s ", mEditor->text().latin1()); | ||
156 | 235 | ||
157 | mDirty = false; | 236 | mDirty = false; |
158 | } | 237 | } |
159 | 238 | ||
160 | void JournalEntry::flushEntry() | 239 | void JournalEntry::flushEntry() |
161 | { | 240 | { |
162 | if (!mDirty) return; | 241 | if (!mDirty) return; |
163 | 242 | ||
164 | writeJournal(); | 243 | writeJournal(); |
165 | } | 244 | } |
166 | void JournalEntry::keyPressEvent ( QKeyEvent * e ) | 245 | void JournalEntry::keyPressEvent ( QKeyEvent * e ) |
167 | { | 246 | { |
168 | e->ignore(); | 247 | e->ignore(); |
169 | 248 | ||
170 | } | 249 | } |
diff --git a/korganizer/journalentry.h b/korganizer/journalentry.h index 1f784f4..f1a1fef 100644 --- a/korganizer/journalentry.h +++ b/korganizer/journalentry.h | |||
@@ -1,73 +1,75 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | #ifndef JOURNALENTRY_H | 23 | #ifndef JOURNALENTRY_H |
24 | #define JOURNALENTRY_H | 24 | #define JOURNALENTRY_H |
25 | // | 25 | // |
26 | // Widget showing one Journal entry | 26 | // Widget showing one Journal entry |
27 | 27 | ||
28 | #include <qframe.h> | 28 | #include <qframe.h> |
29 | 29 | ||
30 | #include <libkcal/calendar.h> | 30 | #include <libkcal/calendar.h> |
31 | 31 | ||
32 | class QLabel; | 32 | class QLabel; |
33 | class KTextEdit; | 33 | class KTextEdit; |
34 | 34 | ||
35 | using namespace KCal; | 35 | using namespace KCal; |
36 | 36 | ||
37 | class JournalEntry : public QFrame { | 37 | class JournalEntry : public QFrame { |
38 | Q_OBJECT | 38 | Q_OBJECT |
39 | public: | 39 | public: |
40 | JournalEntry(Calendar *,QWidget *parent); | 40 | JournalEntry(Calendar *,QWidget *parent); |
41 | virtual ~JournalEntry(); | 41 | virtual ~JournalEntry(); |
42 | 42 | ||
43 | void setJournal(Journal *); | 43 | void setJournal(Journal *); |
44 | Journal *journal() const; | 44 | Journal *journal() const; |
45 | 45 | ||
46 | void setDate(const QDate &); | 46 | void setDate(const QDate &); |
47 | 47 | ||
48 | void clear(); | 48 | void clear(); |
49 | 49 | ||
50 | void flushEntry(); | 50 | void flushEntry(); |
51 | 51 | ||
52 | protected slots: | 52 | protected slots: |
53 | void slotSaveTemplate(); | ||
54 | void slotLoadTemplate(); | ||
53 | void setDirty(); | 55 | void setDirty(); |
54 | signals: | 56 | signals: |
55 | void deleteJournal(Journal *); | 57 | void deleteJournal(Journal *); |
56 | 58 | ||
57 | protected: | 59 | protected: |
58 | bool eventFilter( QObject *o, QEvent *e ); | 60 | bool eventFilter( QObject *o, QEvent *e ); |
59 | 61 | ||
60 | void writeJournal(); | 62 | void writeJournal(); |
61 | 63 | ||
62 | private: | 64 | private: |
63 | Calendar *mCalendar; | 65 | Calendar *mCalendar; |
64 | Journal *mJournal; | 66 | Journal *mJournal; |
65 | QDate mDate; | 67 | QDate mDate; |
66 | void keyPressEvent ( QKeyEvent * ) ; | 68 | void keyPressEvent ( QKeyEvent * ) ; |
67 | QLabel *mTitleLabel; | 69 | QLabel *mTitleLabel; |
68 | KTextEdit *mEditor; | 70 | KTextEdit *mEditor; |
69 | 71 | ||
70 | bool mDirty; | 72 | bool mDirty; |
71 | }; | 73 | }; |
72 | 74 | ||
73 | #endif | 75 | #endif |
diff --git a/korganizer/koeventeditor.cpp b/korganizer/koeventeditor.cpp index 0ff99a4..337db9b 100644 --- a/korganizer/koeventeditor.cpp +++ b/korganizer/koeventeditor.cpp | |||
@@ -1,377 +1,377 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | Copyright (c) 2001,2002 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001,2002 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <qtooltip.h> | 24 | #include <qtooltip.h> |
25 | #include <qframe.h> | 25 | #include <qframe.h> |
26 | #include <qpixmap.h> | 26 | #include <qpixmap.h> |
27 | #include <qhbox.h> | 27 | #include <qhbox.h> |
28 | #include <qdir.h> | 28 | #include <qdir.h> |
29 | #include <qlayout.h> | 29 | #include <qlayout.h> |
30 | #include <qwidgetstack.h> | 30 | #include <qwidgetstack.h> |
31 | #include <qapplication.h> | 31 | #include <qapplication.h> |
32 | 32 | ||
33 | #include <kiconloader.h> | 33 | #include <kiconloader.h> |
34 | #include <kstandarddirs.h> | 34 | #include <kstandarddirs.h> |
35 | #include <kdebug.h> | 35 | #include <kdebug.h> |
36 | #include <klocale.h> | 36 | #include <klocale.h> |
37 | #include <kfiledialog.h> | 37 | #include <kfiledialog.h> |
38 | #include <kmessagebox.h> | 38 | #include <kmessagebox.h> |
39 | #include <libkcal/calendarresources.h> | 39 | #include <libkcal/calendarresources.h> |
40 | #include <libkcal/resourcecalendar.h> | 40 | #include <libkcal/resourcecalendar.h> |
41 | #include <kresources/resourceselectdialog.h> | 41 | #include <kresources/resourceselectdialog.h> |
42 | 42 | ||
43 | #include <libkdepim/categoryselectdialog.h> | 43 | #include <libkdepim/categoryselectdialog.h> |
44 | #include <libkcal/calendarlocal.h> | 44 | #include <libkcal/calendarlocal.h> |
45 | #include <libkcal/icalformat.h> | 45 | #include <libkcal/icalformat.h> |
46 | 46 | ||
47 | #include "koprefs.h" | 47 | #include "koprefs.h" |
48 | 48 | ||
49 | #include "koeventeditor.h" | 49 | #include "koeventeditor.h" |
50 | extern int globalFlagBlockAgenda; | 50 | extern int globalFlagBlockAgenda; |
51 | 51 | ||
52 | KOEventEditor::KOEventEditor( Calendar *calendar, QWidget *parent ) : | 52 | KOEventEditor::KOEventEditor( Calendar *calendar, QWidget *parent ) : |
53 | KOIncidenceEditor( i18n("Edit Event"), calendar, parent ) | 53 | KOIncidenceEditor( i18n("Edit Event"), calendar, parent ) |
54 | { | 54 | { |
55 | mEvent = 0; | 55 | mEvent = 0; |
56 | init(); | 56 | init(); |
57 | } | 57 | } |
58 | 58 | ||
59 | KOEventEditor::~KOEventEditor() | 59 | KOEventEditor::~KOEventEditor() |
60 | { | 60 | { |
61 | //emit dialogClose( mEvent ); | 61 | //emit dialogClose( mEvent ); |
62 | } | 62 | } |
63 | 63 | ||
64 | void KOEventEditor::init() | 64 | void KOEventEditor::init() |
65 | { | 65 | { |
66 | 66 | ||
67 | setupGeneral(); | 67 | setupGeneral(); |
68 | setupAttendeesTab(); | 68 | setupAttendeesTab(); |
69 | setupRecurrence(); | 69 | setupRecurrence(); |
70 | 70 | ||
71 | // Propagate date time settings to recurrence tab | 71 | // Propagate date time settings to recurrence tab |
72 | connect(mGeneral,SIGNAL(dateTimesChanged(QDateTime,QDateTime)), | 72 | connect(mGeneral,SIGNAL(dateTimesChanged(QDateTime,QDateTime)), |
73 | mRecurrence,SLOT(setDateTimes(QDateTime,QDateTime))); | 73 | mRecurrence,SLOT(setDateTimes(QDateTime,QDateTime))); |
74 | connect(mGeneral,SIGNAL(dateTimeStrChanged(const QString &)), | 74 | connect(mGeneral,SIGNAL(dateTimeStrChanged(const QString &)), |
75 | mRecurrence,SLOT(setDateTimeStr(const QString &))); | 75 | mRecurrence,SLOT(setDateTimeStr(const QString &))); |
76 | 76 | ||
77 | // Category dialog | 77 | // Category dialog |
78 | // connect(mGeneral,SIGNAL(openCategoryDialog()),mCategoryDialog,SLOT(show())); | 78 | // connect(mGeneral,SIGNAL(openCategoryDialog()),mCategoryDialog,SLOT(show())); |
79 | //connect(mCategoryDialog,SIGNAL(categoriesSelected(const QString &)), | 79 | //connect(mCategoryDialog,SIGNAL(categoriesSelected(const QString &)), |
80 | // mGeneral,SLOT(setCategories(const QString &))); | 80 | // mGeneral,SLOT(setCategories(const QString &))); |
81 | 81 | ||
82 | 82 | ||
83 | } | 83 | } |
84 | 84 | ||
85 | void KOEventEditor::reload() | 85 | void KOEventEditor::reload() |
86 | { | 86 | { |
87 | if ( mEvent ) readEvent( mEvent ); | 87 | if ( mEvent ) readEvent( mEvent ); |
88 | } | 88 | } |
89 | 89 | ||
90 | void KOEventEditor::setSecrecy( int sec ) | 90 | void KOEventEditor::setSecrecy( int sec ) |
91 | { | 91 | { |
92 | mGeneral->setSecrecy( sec ); | 92 | mGeneral->setSecrecy( sec ); |
93 | } | 93 | } |
94 | void KOEventEditor::setCategories( QString s ) | 94 | void KOEventEditor::setCategories( QString s ) |
95 | { | 95 | { |
96 | mGeneral->setCategories(s); | 96 | mGeneral->setCategories(s); |
97 | 97 | ||
98 | } | 98 | } |
99 | void KOEventEditor::setupGeneral() | 99 | void KOEventEditor::setupGeneral() |
100 | { | 100 | { |
101 | mGeneral = new KOEditorGeneralEvent( this, "KOEditorGeneralEvent" ); | 101 | mGeneral = new KOEditorGeneralEvent( this, "KOEditorGeneralEvent" ); |
102 | connect ( mGeneral, SIGNAL ( allAccepted() ), this, SLOT ( slotOk () ) ); | 102 | connect ( mGeneral, SIGNAL ( allAccepted() ), this, SLOT ( slotOk () ) ); |
103 | 103 | ||
104 | if( KOPrefs::instance()->mCompactDialogs ) { | 104 | if( KOPrefs::instance()->mCompactDialogs ) { |
105 | QFrame *topFrame = addPage(i18n("General")); | 105 | QFrame *topFrame = addPage(i18n("General")); |
106 | QBoxLayout *topLayout = new QVBoxLayout(topFrame); | 106 | QBoxLayout *topLayout = new QVBoxLayout(topFrame); |
107 | topLayout->setSpacing(spacingHint()-1); | 107 | topLayout->setSpacing(spacingHint()-1); |
108 | topLayout->setMargin(marginHint()-1); | 108 | topLayout->setMargin(marginHint()-1); |
109 | mGeneral->initHeader(topFrame,topLayout); | 109 | mGeneral->initHeader(topFrame,topLayout); |
110 | mGeneral->initTime(topFrame,topLayout); | 110 | mGeneral->initTime(topFrame,topLayout); |
111 | // QBoxLayout *alarmLineLayout = new QHBoxLayout(topLayout); | 111 | // QBoxLayout *alarmLineLayout = new QHBoxLayout(topLayout); |
112 | mGeneral->initAlarm(topFrame,topLayout); | 112 | mGeneral->initAlarm(topFrame,topLayout); |
113 | mGeneral->enableAlarm( false ); | 113 | mGeneral->enableAlarm( false ); |
114 | 114 | ||
115 | QBoxLayout *buttonLayout; | 115 | QBoxLayout *buttonLayout; |
116 | if ( QApplication::desktop()->width() < 500 ) | 116 | if ( QApplication::desktop()->width() < 500 ) |
117 | buttonLayout = new QVBoxLayout( topLayout ); | 117 | buttonLayout = new QVBoxLayout( topLayout ); |
118 | else | 118 | else |
119 | buttonLayout = new QHBoxLayout( topLayout ); | 119 | buttonLayout = new QHBoxLayout( topLayout ); |
120 | QHBox* buttonWidget = new QHBox (topFrame); | 120 | QHBox* buttonWidget = new QHBox (topFrame); |
121 | QIconSet icon; | 121 | QIconSet icon; |
122 | if ( QApplication::desktop()->width() < 321 ) | 122 | if ( QApplication::desktop()->width() < 321 ) |
123 | icon = SmallIcon("fileexport16"); | 123 | icon = SmallIcon("fileexport16"); |
124 | else | 124 | else |
125 | icon = SmallIcon("fileexport"); | 125 | icon = SmallIcon("fileexport"); |
126 | QPushButton * loadTemplate = new QPushButton( buttonWidget); | 126 | QPushButton * loadTemplate = new QPushButton( buttonWidget); |
127 | QPushButton * saveTemplate = new QPushButton( buttonWidget); | 127 | QPushButton * saveTemplate = new QPushButton( buttonWidget); |
128 | saveTemplate->setIconSet (icon ) ; | 128 | saveTemplate->setIconSet (icon ) ; |
129 | int size = saveTemplate->sizeHint().height(); | 129 | int size = saveTemplate->sizeHint().height(); |
130 | saveTemplate->setFixedSize( size, size ); | 130 | saveTemplate->setFixedSize( size, size ); |
131 | if ( QApplication::desktop()->width() < 321 ) | 131 | if ( QApplication::desktop()->width() < 321 ) |
132 | icon = SmallIcon("fileimport16"); | 132 | icon = SmallIcon("fileimport16"); |
133 | else | 133 | else |
134 | icon = SmallIcon("fileimport"); | 134 | icon = SmallIcon("fileimport"); |
135 | loadTemplate->setIconSet (icon ) ; | 135 | loadTemplate->setIconSet (icon ) ; |
136 | loadTemplate->setFixedSize( size, size ); | 136 | loadTemplate->setFixedSize( size, size ); |
137 | buttonLayout->addWidget( buttonWidget ); | 137 | buttonLayout->addWidget( buttonWidget ); |
138 | mGeneral->initCategories( topFrame, buttonLayout ); | 138 | mGeneral->initCategories( topFrame, buttonLayout ); |
139 | 139 | ||
140 | topLayout->addStretch( 1 ); | 140 | topLayout->addStretch( 1 ); |
141 | 141 | ||
142 | QFrame *topFrame2 = addPage(i18n("Details")); | 142 | QFrame *topFrame2 = addPage(i18n("Details")); |
143 | 143 | ||
144 | QBoxLayout *topLayout2 = new QVBoxLayout(topFrame2); | 144 | QBoxLayout *topLayout2 = new QVBoxLayout(topFrame2); |
145 | topLayout2->setSpacing(spacingHint()); | 145 | topLayout2->setSpacing(spacingHint()); |
146 | 146 | ||
147 | mGeneral->initClass(topFrame2,topLayout2); | 147 | mGeneral->initClass(topFrame2,topLayout2); |
148 | mGeneral->initSecrecy( topFrame2, topLayout2 ); | 148 | mGeneral->initSecrecy( topFrame2, topLayout2 ); |
149 | mGeneral->initDescription(topFrame2,topLayout2); | 149 | mGeneral->initDescription(topFrame2,topLayout2); |
150 | 150 | ||
151 | connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) ); | 151 | connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) ); |
152 | connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) ); | 152 | connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) ); |
153 | } else { | 153 | } else { |
154 | QFrame *topFrame = addPage(i18n("General")); | 154 | QFrame *topFrame = addPage(i18n("General")); |
155 | 155 | ||
156 | QBoxLayout *topLayout = new QVBoxLayout(topFrame); | 156 | QBoxLayout *topLayout = new QVBoxLayout(topFrame); |
157 | topLayout->setSpacing(spacingHint()); | 157 | topLayout->setSpacing(spacingHint()); |
158 | 158 | ||
159 | mGeneral->initHeader(topFrame,topLayout); | 159 | mGeneral->initHeader(topFrame,topLayout); |
160 | mGeneral->initTime(topFrame,topLayout); | 160 | mGeneral->initTime(topFrame,topLayout); |
161 | QBoxLayout *alarmLineLayout = new QHBoxLayout(topLayout); | 161 | QBoxLayout *alarmLineLayout = new QHBoxLayout(topLayout); |
162 | mGeneral->initAlarm(topFrame,alarmLineLayout); | 162 | mGeneral->initAlarm(topFrame,alarmLineLayout); |
163 | mGeneral->initClass(topFrame,alarmLineLayout); | 163 | mGeneral->initClass(topFrame,alarmLineLayout); |
164 | mGeneral->initDescription(topFrame,topLayout); | 164 | mGeneral->initDescription(topFrame,topLayout); |
165 | QBoxLayout *detailsLayout = new QHBoxLayout(topLayout); | 165 | QBoxLayout *detailsLayout = new QHBoxLayout(topLayout); |
166 | mGeneral->initCategories( topFrame, detailsLayout ); | 166 | mGeneral->initCategories( topFrame, detailsLayout ); |
167 | mGeneral->initSecrecy( topFrame, detailsLayout ); | 167 | mGeneral->initSecrecy( topFrame, detailsLayout ); |
168 | } | 168 | } |
169 | 169 | ||
170 | mGeneral->finishSetup(); | 170 | mGeneral->finishSetup(); |
171 | 171 | ||
172 | } | 172 | } |
173 | 173 | ||
174 | void KOEventEditor::setupRecurrence() | 174 | void KOEventEditor::setupRecurrence() |
175 | { | 175 | { |
176 | QFrame *topFrame = addPage( i18n("Recurrence") ); | 176 | QFrame *topFrame = addPage( i18n("Recurrence") ); |
177 | QBoxLayout *topLayout = new QVBoxLayout( topFrame ); | 177 | QBoxLayout *topLayout = new QVBoxLayout( topFrame ); |
178 | 178 | ||
179 | mRecurrence = new KOEditorRecurrence( topFrame ); | 179 | mRecurrence = new KOEditorRecurrence( topFrame ); |
180 | topLayout->addWidget( mRecurrence ); | 180 | topLayout->addWidget( mRecurrence ); |
181 | } | 181 | } |
182 | 182 | ||
183 | void KOEventEditor::editEvent(Event *event, bool showDescription) | 183 | void KOEventEditor::editEvent(Event *event, bool showDescription) |
184 | { | 184 | { |
185 | // init(); | 185 | // init(); |
186 | 186 | ||
187 | mEvent = event; | 187 | mEvent = event; |
188 | readEvent(mEvent); | 188 | readEvent(mEvent); |
189 | qApp->processEvents(); | 189 | qApp->processEvents(); |
190 | if ( showDescription ) { | 190 | if ( showDescription ) { |
191 | showPage( 1 ); | 191 | showPage( 1 ); |
192 | mGeneral->setFocusOn( 1 ); | 192 | mGeneral->setFocusOn( 1 ); |
193 | } else { | 193 | } else { |
194 | showPage( 0 ); | 194 | showPage( 0 ); |
195 | mGeneral->setFocusOn( 2 ); | 195 | mGeneral->setFocusOn( 2 ); |
196 | } | 196 | } |
197 | } | 197 | } |
198 | 198 | ||
199 | void KOEventEditor::newEvent( QDateTime from, QDateTime to, bool allDay ) | 199 | void KOEventEditor::newEvent( QDateTime from, QDateTime to, bool allDay ) |
200 | { | 200 | { |
201 | // init(); | 201 | // init(); |
202 | 202 | ||
203 | mEvent = 0; | 203 | mEvent = 0; |
204 | setDefaults(from,to,allDay); | 204 | setDefaults(from,to,allDay); |
205 | } | 205 | } |
206 | 206 | ||
207 | void KOEventEditor::loadDefaults() | 207 | void KOEventEditor::loadDefaults() |
208 | { | 208 | { |
209 | int fmt = KOPrefs::instance()->mStartTime; | 209 | int fmt = KOPrefs::instance()->mStartTime; |
210 | 210 | ||
211 | QDateTime from(QDate::currentDate(), QTime(fmt,0,0)); | 211 | QDateTime from(QDate::currentDate(), QTime(fmt,0,0)); |
212 | QDateTime to(QDate::currentDate(), | 212 | QDateTime to(QDate::currentDate(), |
213 | QTime(fmt+KOPrefs::instance()->mDefaultDuration,0,0)); | 213 | QTime(fmt+KOPrefs::instance()->mDefaultDuration,0,0)); |
214 | 214 | ||
215 | setDefaults(from,to,false); | 215 | setDefaults(from,to,false); |
216 | } | 216 | } |
217 | 217 | ||
218 | bool KOEventEditor::processInput( bool emitTime ) | 218 | bool KOEventEditor::processInput( bool emitTime ) |
219 | { | 219 | { |
220 | if (!validateInput()) return false; | 220 | if (!validateInput()) return false; |
221 | 221 | ||
222 | Event *event = 0; | 222 | Event *event = 0; |
223 | 223 | ||
224 | if (mEvent) event = mEvent; | 224 | if (mEvent) event = mEvent; |
225 | else { | 225 | else { |
226 | event = new Event; | 226 | event = new Event; |
227 | event->setOrganizer(KOPrefs::instance()->email()); | 227 | event->setOrganizer(KOPrefs::instance()->email()); |
228 | } | 228 | } |
229 | 229 | ||
230 | writeEvent(event); | 230 | writeEvent(event); |
231 | if ( emitTime ) { | 231 | if ( emitTime ) { |
232 | globalFlagBlockAgenda = 1; | 232 | globalFlagBlockAgenda = 1; |
233 | emit showAgendaView( false ); | 233 | emit showAgendaView( false ); |
234 | emit jumpToTime( event->dtStart().date() ); | 234 | emit jumpToTime( event->dtStart().date() ); |
235 | globalFlagBlockAgenda = 2; | 235 | globalFlagBlockAgenda = 2; |
236 | 236 | ||
237 | } | 237 | } |
238 | if (mEvent) { | 238 | if (mEvent) { |
239 | event->setRevision(event->revision()+1); | 239 | event->setRevision(event->revision()+1); |
240 | emit eventChanged(event); | 240 | emit eventChanged(event); |
241 | } else { | 241 | } else { |
242 | mCalendar->addEvent(event); | 242 | mCalendar->addEvent(event); |
243 | mEvent = event; | 243 | mEvent = event; |
244 | emit eventAdded(event); | 244 | emit eventAdded(event); |
245 | } | 245 | } |
246 | 246 | ||
247 | return true; | 247 | return true; |
248 | } | 248 | } |
249 | 249 | ||
250 | void KOEventEditor::deleteEvent() | 250 | void KOEventEditor::deleteEvent() |
251 | { | 251 | { |
252 | kdDebug() << "Delete event" << endl; | 252 | kdDebug() << "Delete event" << endl; |
253 | 253 | ||
254 | if (mEvent) { | 254 | if (mEvent) { |
255 | if (KOPrefs::instance()->mConfirm) { | 255 | if (KOPrefs::instance()->mConfirm) { |
256 | switch (msgItemDelete()) { | 256 | switch (msgItemDelete()) { |
257 | case KMessageBox::Continue: // OK | 257 | case KMessageBox::Continue: // OK |
258 | emit eventToBeDeleted(mEvent); | 258 | emit eventToBeDeleted(mEvent); |
259 | emit dialogClose(mEvent); | 259 | emit dialogClose(mEvent); |
260 | mCalendar->deleteEvent(mEvent); | 260 | mCalendar->deleteEvent(mEvent); |
261 | emit eventDeleted(); | 261 | emit eventDeleted(); |
262 | reject(); | 262 | reject(); |
263 | break; | 263 | break; |
264 | } | 264 | } |
265 | } | 265 | } |
266 | else { | 266 | else { |
267 | emit eventToBeDeleted(mEvent); | 267 | emit eventToBeDeleted(mEvent); |
268 | emit dialogClose(mEvent); | 268 | emit dialogClose(mEvent); |
269 | mCalendar->deleteEvent(mEvent); | 269 | mCalendar->deleteEvent(mEvent); |
270 | emit eventDeleted(); | 270 | emit eventDeleted(); |
271 | reject(); | 271 | reject(); |
272 | } | 272 | } |
273 | } else { | 273 | } else { |
274 | reject(); | 274 | reject(); |
275 | } | 275 | } |
276 | } | 276 | } |
277 | 277 | ||
278 | void KOEventEditor::setDefaults(QDateTime from, QDateTime to, bool allDay) | 278 | void KOEventEditor::setDefaults(QDateTime from, QDateTime to, bool allDay) |
279 | { | 279 | { |
280 | mGeneral->setDefaults(from,to,allDay); | 280 | mGeneral->setDefaults(from,to,allDay); |
281 | mDetails->setDefaults(); | 281 | mDetails->setDefaults(); |
282 | mRecurrence->setDefaults(from,to,allDay); | 282 | mRecurrence->setDefaults(from,to,allDay); |
283 | showPage( 0 ); | 283 | showPage( 0 ); |
284 | mGeneral->setFocusOn( 2 ); | 284 | mGeneral->setFocusOn( 2 ); |
285 | } | 285 | } |
286 | 286 | ||
287 | void KOEventEditor::readEvent( Event *event, bool tmpl ) | 287 | void KOEventEditor::readEvent( Event *event, bool tmpl ) |
288 | { | 288 | { |
289 | mGeneral->readEvent( event, tmpl ); | 289 | mGeneral->readEvent( event, tmpl ); |
290 | mDetails->readEvent( event ); | 290 | mDetails->readEvent( event ); |
291 | mRecurrence->readEvent( event ); | 291 | mRecurrence->readEvent( event ); |
292 | 292 | ||
293 | // categories | 293 | // categories |
294 | //mCategoryDialog->setSelected( event->categories() ); | 294 | //mCategoryDialog->setSelected( event->categories() ); |
295 | } | 295 | } |
296 | 296 | ||
297 | void KOEventEditor::writeEvent(Event *event) | 297 | void KOEventEditor::writeEvent(Event *event) |
298 | { | 298 | { |
299 | mGeneral->writeEvent( event ); | 299 | mGeneral->writeEvent( event ); |
300 | mDetails->writeEvent( event ); | 300 | mDetails->writeEvent( event ); |
301 | 301 | ||
302 | if ( event->organizer() == KOPrefs::instance()->email() ) { | 302 | if ( event->organizer() == KOPrefs::instance()->email() ) { |
303 | Event *ev = new Event( *event ); | 303 | Event *ev = new Event( *event ); |
304 | ev->registerObserver(0); | 304 | ev->registerObserver(0); |
305 | mDetails->cancelAttendeeEvent( ev ); | 305 | mDetails->cancelAttendeeEvent( ev ); |
306 | if ( ev->attendeeCount() > 0 ) { | 306 | if ( ev->attendeeCount() > 0 ) { |
307 | emit deleteAttendee( ev ); | 307 | emit deleteAttendee( ev ); |
308 | } | 308 | } |
309 | delete(ev); | 309 | delete(ev); |
310 | } | 310 | } |
311 | 311 | ||
312 | mRecurrence->writeEvent(event); | 312 | mRecurrence->writeEvent(event); |
313 | } | 313 | } |
314 | 314 | ||
315 | bool KOEventEditor::validateInput() | 315 | bool KOEventEditor::validateInput() |
316 | { | 316 | { |
317 | if (!mGeneral->validateInput()) return false; | 317 | if (!mGeneral->validateInput()) return false; |
318 | if (!mDetails->validateInput()) return false; | 318 | if (!mDetails->validateInput()) return false; |
319 | if (!mRecurrence->validateInput()) return false; | 319 | if (!mRecurrence->validateInput()) return false; |
320 | return true; | 320 | return true; |
321 | } | 321 | } |
322 | 322 | ||
323 | int KOEventEditor::msgItemDelete() | 323 | int KOEventEditor::msgItemDelete() |
324 | { | 324 | { |
325 | return KMessageBox::warningContinueCancel(this, | 325 | return KMessageBox::warningContinueCancel(this, |
326 | i18n("This item will be permanently deleted."), | 326 | i18n("This item will be permanently deleted."), |
327 | i18n("KOrganizer Confirmation"),i18n("Delete")); | 327 | i18n("KOrganizer Confirmation"),i18n("Delete")); |
328 | } | 328 | } |
329 | 329 | ||
330 | void KOEventEditor::slotLoadTemplate() | 330 | void KOEventEditor::slotLoadTemplate() |
331 | { | 331 | { |
332 | 332 | ||
333 | QString fileName =locateLocal( "templates", "events" ); | 333 | QString fileName =locateLocal( "templates", "events" ); |
334 | QDir t_dir; | 334 | QDir t_dir; |
335 | if ( !t_dir.exists(fileName) ) | 335 | if ( !t_dir.exists(fileName) ) |
336 | t_dir.mkdir ( fileName ); | 336 | t_dir.mkdir ( fileName ); |
337 | fileName += "/event"; | 337 | fileName += "/event"; |
338 | fileName = KFileDialog::getSaveFileName( fileName , "Load Event template", this ); | 338 | fileName = KFileDialog::getOpenFileName( fileName , i18n("Load Event template"), this ); |
339 | if ( fileName.length() == 0 ) | 339 | if ( fileName.length() == 0 ) |
340 | return; | 340 | return; |
341 | CalendarLocal cal; | 341 | CalendarLocal cal; |
342 | ICalFormat format; | 342 | ICalFormat format; |
343 | if ( !format.load( &cal, fileName ) ) { | 343 | if ( !format.load( &cal, fileName ) ) { |
344 | KMessageBox::error( this, i18n("Error loading template file\n '%1'.") | 344 | KMessageBox::error( this, i18n("Error loading template file\n '%1'.") |
345 | .arg( fileName ) ); | 345 | .arg( fileName ) ); |
346 | return ; | 346 | return ; |
347 | } | 347 | } |
348 | QPtrList<Event> events = cal.events(); | 348 | QPtrList<Event> events = cal.events(); |
349 | Event* event = events.first(); | 349 | Event* event = events.first(); |
350 | if ( !event ) { | 350 | if ( !event ) { |
351 | KMessageBox::error( this, | 351 | KMessageBox::error( this, |
352 | i18n("Template does not contain\na valid Event.")); | 352 | i18n("Template does not contain\na valid Event.")); |
353 | } else { | 353 | } else { |
354 | kdDebug() << "KOEventEditor::slotLoadTemplate(): readTemplate" << endl; | 354 | kdDebug() << "KOEventEditor::slotLoadTemplate(): readTemplate" << endl; |
355 | readEvent( event, true ); | 355 | readEvent( event, true ); |
356 | } | 356 | } |
357 | } | 357 | } |
358 | 358 | ||
359 | 359 | ||
360 | void KOEventEditor::slotSaveTemplate() | 360 | void KOEventEditor::slotSaveTemplate() |
361 | { | 361 | { |
362 | QString fileName =locateLocal( "templates", "events" ); | 362 | QString fileName =locateLocal( "templates", "events" ); |
363 | QDir t_dir; | 363 | QDir t_dir; |
364 | if ( !t_dir.exists(fileName) ) | 364 | if ( !t_dir.exists(fileName) ) |
365 | t_dir.mkdir ( fileName ); | 365 | t_dir.mkdir ( fileName ); |
366 | fileName += "/event"; | 366 | fileName += "/event"; |
367 | fileName = KFileDialog::getSaveFileName( fileName , "Save as Event template", this ); | 367 | fileName = KFileDialog::getSaveFileName( fileName , i18n("Save as Event template"), this ); |
368 | if ( fileName.length() > 0 ) | 368 | if ( fileName.length() > 0 ) |
369 | saveTemplate( fileName ); | 369 | saveTemplate( fileName ); |
370 | } | 370 | } |
371 | 371 | ||
372 | void KOEventEditor::saveTemplate( const QString &templateName ) | 372 | void KOEventEditor::saveTemplate( const QString &templateName ) |
373 | { | 373 | { |
374 | Event *event = new Event; | 374 | Event *event = new Event; |
375 | writeEvent( event ); | 375 | writeEvent( event ); |
376 | saveAsTemplate( event, templateName ); | 376 | saveAsTemplate( event, templateName ); |
377 | } | 377 | } |