summaryrefslogtreecommitdiffabout
path: root/korganizer/journalentry.cpp
Unidiff
Diffstat (limited to 'korganizer/journalentry.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/journalentry.cpp36
1 files changed, 23 insertions, 13 deletions
diff --git a/korganizer/journalentry.cpp b/korganizer/journalentry.cpp
index 3c38f34..4751d40 100644
--- a/korganizer/journalentry.cpp
+++ b/korganizer/journalentry.cpp
@@ -1,289 +1,299 @@
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> 29#include <qvbox.h>
30#include <qfile.h> 30#include <qfile.h>
31#include <qdir.h> 31#include <qdir.h>
32#include <qtextstream.h> 32#include <qtextstream.h>
33#include <qtextcodec.h> 33#include <qtextcodec.h>
34#include <qpixmap.h> 34#include <qpixmap.h>
35#include <qpushbutton.h> 35#include <qpushbutton.h>
36#include <qapplication.h> 36#include <qapplication.h>
37 37
38#include <kdebug.h> 38#include <kdebug.h>
39#include <kglobal.h> 39#include <kglobal.h>
40#include <klocale.h> 40#include <klocale.h>
41#include <ktextedit.h> 41#include <ktextedit.h>
42#include <kfiledialog.h> 42#include <kfiledialog.h>
43#include <kmessagebox.h> 43#include <kmessagebox.h>
44#include "koprefs.h" 44#include "koprefs.h"
45#include <klineedit.h> 45#include <klineedit.h>
46#include <kdialog.h>
47#include "kolocationbox.h"
46 48
47#include <libkcal/journal.h> 49#include <libkcal/journal.h>
48#include <libkcal/calendarresources.h> 50#include <libkcal/calendarresources.h>
49#include <libkcal/resourcecalendar.h> 51#include <libkcal/resourcecalendar.h>
50#include <kresources/resourceselectdialog.h> 52#include <kresources/resourceselectdialog.h>
51 53
52#include "journalentry.h" 54#include "journalentry.h"
53//#include "journalentry.moc" 55//#include "journalentry.moc"
54#ifndef DESKTOP_VERSION 56#ifndef DESKTOP_VERSION
55#include <qpe/qpeapplication.h> 57#include <qpe/qpeapplication.h>
56#endif 58#endif
57JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : 59JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) :
58 QFrame(parent) 60 QFrame(parent)
59{ 61{
60 62
61 int fac = 5; 63 int fac = 5;
62 heiHint = QApplication::desktop()->height(); 64 heiHint = QApplication::desktop()->height();
63 if ( heiHint > 800 ) 65 if ( heiHint > 800 )
64 fac += 2; 66 fac += 2;
65 heiHint = heiHint / fac; 67 heiHint = heiHint / fac;
66 68
67 showOnlyMode = false; 69 showOnlyMode = false;
68 mCalendar = calendar; 70 mCalendar = calendar;
69 mJournal = 0; 71 mJournal = 0;
70 visibleMode = true; 72 visibleMode = true;
71 QHBox * vb = new QHBox ( this ); 73 QHBox * vb = new QHBox ( this );
72 QPixmap iconp; 74 QPixmap iconp;
73 75 vb->setMargin ( KDialog::marginHint()-1 );
74 QPushButton * toggleJournal = new QPushButton( vb ); 76 QPushButton * toggleJournal = new QPushButton( vb );
75 iconp = SmallIcon("1updownarrow"); 77 iconp = SmallIcon("1updownarrow");
76 toggleJournal->setPixmap (iconp ) ; 78 toggleJournal->setPixmap (iconp ) ;
77 new QLabel(" "+i18n("Title: "),vb); 79 new QLabel(" "+i18n("Title: "),vb);
78 mTitle = new KLineEdit ( vb ); 80 mTitle = new KOLocationBox(TRUE, vb, 30);
81 mTitle->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding ,QSizePolicy::Fixed ,FALSE) );
79 mTitleLabel = new QLabel(i18n("Title"),vb); 82 mTitleLabel = new QLabel(i18n("Title"),vb);
80 mTitleLabel->setMargin(0); 83 mTitleLabel->setMargin(0);
81 mTitleLabel->setAlignment(AlignCenter); 84 mTitleLabel->setAlignment(AlignCenter);
82 QPushButton * loadTemplate = new QPushButton( vb ); 85 QPushButton * loadTemplate = new QPushButton( vb );
83 QPushButton * saveTemplate = new QPushButton( vb ); 86 QPushButton * saveTemplate = new QPushButton( vb );
84 if ( QApplication::desktop()->width() < 321 ) 87 if ( QApplication::desktop()->width() < 321 )
85 iconp = SmallIcon("fileexport16"); 88 iconp = SmallIcon("fileexport16");
86 else 89 else
87 iconp = SmallIcon("fileexport"); 90 iconp = SmallIcon("fileexport");
88 saveTemplate->setPixmap (iconp ) ; 91 saveTemplate->setPixmap (iconp ) ;
89 int size = saveTemplate->sizeHint().height(); 92 int size = saveTemplate->sizeHint().height();
90 if ( QApplication::desktop()->width() < 321 ) 93 if ( QApplication::desktop()->width() < 321 )
91 iconp = SmallIcon("fileimport16"); 94 iconp = SmallIcon("fileimport16");
92 else 95 else
93 iconp = SmallIcon("fileimport"); 96 iconp = SmallIcon("fileimport");
94 loadTemplate->setPixmap (iconp ) ; 97 loadTemplate->setPixmap (iconp ) ;
95 loadTemplate->setFixedSize( size, size ); 98 loadTemplate->setFixedSize( size, size );
96 saveTemplate->setFixedSize( size, size ); 99 saveTemplate->setFixedSize( size, size );
97 toggleJournal->setFixedSize( size , size ); 100 toggleJournal->setFixedSize( size , size );
101 mTitle->setMaximumHeight( size+4);
98 mEditor = new KTextEdit(this); 102 mEditor = new KTextEdit(this);
99#ifndef DESKTOP_VERSION 103#ifndef DESKTOP_VERSION
100 QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold ); 104 QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold );
101#endif 105#endif
102 mEditor->setWordWrap( KTextEdit::WidgetWidth ); 106 mEditor->setWordWrap( KTextEdit::WidgetWidth );
103 QBoxLayout *topLayout = new QVBoxLayout(this); 107 QBoxLayout *topLayout = new QVBoxLayout(this);
104 topLayout->addWidget(vb); 108 topLayout->addWidget(vb);
105 topLayout->addWidget(mEditor); 109 topLayout->addWidget(mEditor);
106 mEditor->installEventFilter(this); 110 mEditor->installEventFilter(this);
107 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) ); 111 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) );
108 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) ); 112 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) );
109 connect( toggleJournal, SIGNAL( clicked() ), this , SLOT( toggleShowJournal() ) ); 113 connect( toggleJournal, SIGNAL( clicked() ), this , SLOT( toggleShowJournal() ) );
114 mTitle->load( KOLocationBox::SUMMARYJOURNAL );
115 mTitle->lineEdit ()->setText("");
110} 116}
111 117
112JournalEntry::~JournalEntry() 118JournalEntry::~JournalEntry()
113{ 119{
114 //qDebug("JournalEntry::~JournalEntry() "); 120 //qDebug("JournalEntry::~JournalEntry() ");
115} 121}
116QSize JournalEntry::sizeHint() const 122QSize JournalEntry::sizeHint() const
117{ 123{
118 return QSize ( 240, heiHint ); 124 return QSize ( 240, heiHint );
119} 125}
120void JournalEntry::slotSaveTemplate() 126void JournalEntry::slotSaveTemplate()
121{ 127{
122 QString fileName =locateLocal( "templates", "journals" ); 128 QString fileName =locateLocal( "templates", "journals" );
123 QDir t_dir; 129 QDir t_dir;
124 if ( !t_dir.exists(fileName) ) 130 if ( !t_dir.exists(fileName) )
125 t_dir.mkdir ( fileName ); 131 t_dir.mkdir ( fileName );
126 fileName += "/journal"; 132 fileName += "/journal";
127 fileName = KFileDialog::getSaveFileName( fileName , i18n("Save as Journal template"), this ); 133 fileName = KFileDialog::getSaveFileName( fileName , i18n("Save as Journal template"), this );
128 if ( fileName.length() == 0 ) 134 if ( fileName.length() == 0 )
129 return; 135 return;
130 136
131 QFile fileIn( fileName ); 137 QFile fileIn( fileName );
132 if (!fileIn.open( IO_WriteOnly ) ) { 138 if (!fileIn.open( IO_WriteOnly ) ) {
133 KMessageBox::error( this, i18n("Error saving template file\n '%1'.") 139 KMessageBox::error( this, i18n("Error saving template file\n '%1'.")
134 .arg( fileName ) ); 140 .arg( fileName ) );
135 return; 141 return;
136 } 142 }
137 // QString text; 143 // QString text;
138 QTextStream tsIn( &fileIn ); 144 QTextStream tsIn( &fileIn );
139 tsIn.setCodec( QTextCodec::codecForName("utf8") ); 145 tsIn.setCodec( QTextCodec::codecForName("utf8") );
140 tsIn << mEditor->text(); 146 tsIn << mEditor->text();
141 fileIn.close(); 147 fileIn.close();
142} 148}
143void JournalEntry::slotLoadTemplate() 149void JournalEntry::slotLoadTemplate()
144{ 150{
145 QString fileName =locateLocal( "templates", "journals" ); 151 QString fileName =locateLocal( "templates", "journals" );
146 QDir t_dir; 152 QDir t_dir;
147 if ( !t_dir.exists(fileName) ) 153 if ( !t_dir.exists(fileName) )
148 t_dir.mkdir ( fileName ); 154 t_dir.mkdir ( fileName );
149 fileName += "/journal"; 155 fileName += "/journal";
150 fileName = KFileDialog::getOpenFileName( fileName , i18n("Insert Journal template"), this ); 156 fileName = KFileDialog::getOpenFileName( fileName , i18n("Insert Journal template"), this );
151 if ( fileName.length() == 0 ) 157 if ( fileName.length() == 0 )
152 return; 158 return;
153 QFile fileIn( fileName ); 159 QFile fileIn( fileName );
154 if (!fileIn.open( IO_ReadOnly ) ) { 160 if (!fileIn.open( IO_ReadOnly ) ) {
155 KMessageBox::error( this, i18n("Error loading template file\n '%1'.") 161 KMessageBox::error( this, i18n("Error loading template file\n '%1'.")
156 .arg( fileName ) ); 162 .arg( fileName ) );
157 return; 163 return;
158 } 164 }
159 QTextStream tsIn( &fileIn ); 165 QTextStream tsIn( &fileIn );
160 tsIn.setCodec( QTextCodec::codecForName("utf8") ); 166 tsIn.setCodec( QTextCodec::codecForName("utf8") );
161 QString text = tsIn.read(); 167 QString text = tsIn.read();
162 fileIn.close(); 168 fileIn.close();
163 int line, col; 169 int line, col;
164 mEditor->getCursorPosition (& line, & col ); 170 mEditor->getCursorPosition (& line, & col );
165 mEditor-> insertAt ( text, line, col, true ); 171 mEditor-> insertAt ( text, line, col, true );
166 //mEditor->setIgnoreMark( true ); 172 //mEditor->setIgnoreMark( true );
167} 173}
168void JournalEntry::setDate(const QDate &date) 174void JournalEntry::setDate(const QDate &date)
169{ 175{
170 showOnlyMode = false; 176 showOnlyMode = false;
171 writeJournal(); 177 writeJournal();
172 mDate = date; 178 mDate = date;
173 int id = mCalendar->defaultCalendar(); 179 int id = mCalendar->defaultCalendar();
174 QString calname = KOPrefs::instance()->getCalendar( id )->mName; 180 QString calname = KOPrefs::instance()->getCalendar( id )->mName;
175 mTitleLabel->setText( " (" + calname +")"); 181 mTitleLabel->setText( " (" + calname +")");
176} 182}
177 183
178void JournalEntry::toggleShowJournal() 184void JournalEntry::toggleShowJournal()
179{ 185{
180 if (!mEditor->text().isEmpty() || !mTitle->text().isEmpty()) 186 if (!mEditor->text().isEmpty() || !mTitle->currentText ().isEmpty())
181 flushEntry(); 187 flushEntry();
182 if ( showOnlyMode ) 188 if ( showOnlyMode )
183 emit showJournalOnly( 0 ); 189 emit showJournalOnly( 0 );
184 else { 190 else {
185 // we have to protect mJournal from deleting if mJournal has empty text 191 // we have to protect mJournal from deleting if mJournal has empty text
186 visibleMode = false; // set to true via :setShowOnly() 192 visibleMode = false; // set to true via :setShowOnly()
187 emit showJournalOnly( mJournal ); 193 emit showJournalOnly( mJournal );
188 //QTimer::singleShot( 0, this, SLOT( setVisibleOn() ) ); 194 //QTimer::singleShot( 0, this, SLOT( setVisibleOn() ) );
189 } 195 }
190} 196}
191void JournalEntry::setVisibleOn() 197void JournalEntry::setVisibleOn()
192{ 198{
193 visibleMode = true; 199 visibleMode = true;
194} 200}
195void JournalEntry::setShowOnly() 201void JournalEntry::setShowOnly()
196{ 202{
197 showOnlyMode = true; 203 showOnlyMode = true;
198 if ( mTitle->text().isEmpty() ) 204 if ( mTitle->currentText().isEmpty() )
199 mTitle->setFocus(); 205 mTitle->setFocus();
200 else 206 else
201 mEditor->setFocus(); 207 mEditor->setFocus();
202} 208}
203void JournalEntry::setJournal(Journal *journal) 209void JournalEntry::setJournal(Journal *journal)
204{ 210{
205 writeJournal(); 211 writeJournal();
212 mTitle->load( KOLocationBox::SUMMARYJOURNAL );
206 213
207 mJournal = journal; 214 mJournal = journal;
208 if ( journal->isReadOnly() ) 215 if ( journal->isReadOnly() )
209 mTitle->setText(mJournal->summary()+" ("+i18n("readonly")+")"); 216 mTitle->lineEdit ()->setText(mJournal->summary()+" ("+i18n("readonly")+")");
210 else 217 else
211 mTitle->setText(mJournal->summary()); 218 mTitle->lineEdit ()->setText(mJournal->summary());
212 mEditor->setText(mJournal->description()); 219 mEditor->setText(mJournal->description());
213 mTitle->setReadOnly (journal->isReadOnly() ); 220 mTitle->setEnabled (!journal->isReadOnly() );
214 mEditor->setReadOnly ( journal->isReadOnly() ); 221 mEditor->setReadOnly ( journal->isReadOnly() );
215 int id = mJournal->calID(); 222 int id = mJournal->calID();
216 223
217 QString calname = KOPrefs::instance()->getCalendar( id )->mName; 224 QString calname = KOPrefs::instance()->getCalendar( id )->mName;
218 mTitleLabel->setText( " (" + calname +")"); 225 mTitleLabel->setText( " (" + calname +")");
219
220} 226}
221 227
222Journal *JournalEntry::journal() const 228Journal *JournalEntry::journal() const
223{ 229{
224 return mJournal; 230 return mJournal;
225} 231}
226 232
227 233
228void JournalEntry::clear() 234void JournalEntry::clear()
229{ 235{
230 mJournal = 0; 236 mJournal = 0;
231 mEditor->setText(""); 237 mEditor->setText("");
232 mTitle->setText(""); 238 mTitle->load( KOLocationBox::SUMMARYJOURNAL );
239 mTitle->lineEdit ()->setText("");
233} 240}
234 241
235bool JournalEntry::eventFilter( QObject *o, QEvent *e ) 242bool JournalEntry::eventFilter( QObject *o, QEvent *e )
236{ 243{
237// kdDebug() << "JournalEntry::event received " << e->type() << endl; 244// kdDebug() << "JournalEntry::event received " << e->type() << endl;
238 245
239 if ( e->type() == QEvent::FocusOut ) { 246 if ( e->type() == QEvent::FocusOut ) {
240 writeJournal(); 247 writeJournal();
241 } 248 }
242 if ( e->type() == QEvent::KeyPress ) { 249 if ( e->type() == QEvent::KeyPress ) {
243 QKeyEvent * k = (QKeyEvent *) e; 250 QKeyEvent * k = (QKeyEvent *) e;
244 if ( k->state() == Qt::ControlButton ) { 251 if ( k->state() == Qt::ControlButton ) {
245 k->ignore(); 252 k->ignore();
246 //return true; 253 //return true;
247 } 254 }
248 } 255 }
249 256
250 return QFrame::eventFilter( o, e ); // standard event processing 257 return QFrame::eventFilter( o, e ); // standard event processing
251} 258}
252 259
253void JournalEntry::writeJournal() 260void JournalEntry::writeJournal()
254{ 261{
255 if ( !visibleMode ) return; 262 if ( !visibleMode ) return;
256 if (mEditor->text().isEmpty() && mTitle->text().isEmpty()) { 263 if (mEditor->text().isEmpty() && mTitle->currentText().isEmpty()) {
257 if ( mJournal ) { 264 if ( mJournal ) {
258 Journal* j = mJournal; 265 Journal* j = mJournal;
259 mJournal = 0; 266 mJournal = 0;
260 bool conf = KOPrefs::instance()->mConfirm; 267 bool conf = KOPrefs::instance()->mConfirm;
261 KOPrefs::instance()->mConfirm = false; 268 KOPrefs::instance()->mConfirm = false;
262 emit deleteJournal(j); 269 emit deleteJournal(j);
263 KOPrefs::instance()->mConfirm = conf; 270 KOPrefs::instance()->mConfirm = conf;
264 } 271 }
265 return; 272 return;
266 } 273 }
267 274
268// kdDebug() << "JournalEntry::writeJournal()..." << endl; 275// kdDebug() << "JournalEntry::writeJournal()..." << endl;
269 276
270 if (!mJournal) { 277 if (!mJournal) {
271 mJournal = new Journal; 278 mJournal = new Journal;
272 mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0))); 279 mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0)));
273 mCalendar->addJournal(mJournal); 280 mCalendar->addJournal(mJournal);
274 } 281 }
275 if ( mJournal->description() != mEditor->text() ) 282 if ( mJournal->description() != mEditor->text() ) {
276 mJournal->setDescription(mEditor->text()); 283 mJournal->setDescription(mEditor->text());
277 if ( mJournal->summary() != mTitle->text() ) 284 }
278 mJournal->setSummary(mTitle->text()); 285 if ( mJournal->summary() != mTitle->currentText() ) {
286 mJournal->setSummary(mTitle->currentText());
287 mTitle->save(KOLocationBox::SUMMARYJOURNAL);
288 }
279} 289}
280 290
281void JournalEntry::flushEntry() 291void JournalEntry::flushEntry()
282{ 292{
283 writeJournal(); 293 writeJournal();
284} 294}
285void JournalEntry::keyPressEvent ( QKeyEvent * e ) 295void JournalEntry::keyPressEvent ( QKeyEvent * e )
286{ 296{
287 e->ignore(); 297 e->ignore();
288 298
289} 299}