summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/journalentry.cpp39
-rw-r--r--korganizer/journalentry.h3
-rw-r--r--korganizer/kojournalview.cpp6
3 files changed, 15 insertions, 33 deletions
diff --git a/korganizer/journalentry.cpp b/korganizer/journalentry.cpp
index 58863fe..add874f 100644
--- a/korganizer/journalentry.cpp
+++ b/korganizer/journalentry.cpp
@@ -16,270 +16,253 @@
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 46
47#include <libkcal/journal.h> 47#include <libkcal/journal.h>
48#include <libkcal/calendarresources.h> 48#include <libkcal/calendarresources.h>
49#include <libkcal/resourcecalendar.h> 49#include <libkcal/resourcecalendar.h>
50#include <kresources/resourceselectdialog.h> 50#include <kresources/resourceselectdialog.h>
51 51
52#include "journalentry.h" 52#include "journalentry.h"
53//#include "journalentry.moc" 53//#include "journalentry.moc"
54#ifndef DESKTOP_VERSION 54#ifndef DESKTOP_VERSION
55#include <qpe/qpeapplication.h> 55#include <qpe/qpeapplication.h>
56#endif 56#endif
57JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : 57JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) :
58 QFrame(parent) 58 QFrame(parent)
59{ 59{
60 heiHint = QApplication::desktop()->height() / 5 ; 60 heiHint = QApplication::desktop()->height() / 5 ;
61 showOnlyMode = false; 61 showOnlyMode = false;
62 mCalendar = calendar; 62 mCalendar = calendar;
63 mJournal = 0; 63 mJournal = 0;
64 mDirty = false;
65 64
66 QHBox * vb = new QHBox ( this ); 65 QHBox * vb = new QHBox ( this );
67 QIconSet icon; 66 QPixmap iconp;
68 67
69 QPushButton * toggleJournal = new QPushButton( vb ); 68 QPushButton * toggleJournal = new QPushButton( vb );
70 icon = SmallIcon("1updownarrow"); 69 iconp = SmallIcon("1updownarrow");
71 toggleJournal->setIconSet (icon ) ; 70 toggleJournal->setPixmap (iconp ) ;
72 new QLabel(i18n(" Title: "),vb); 71 new QLabel(i18n(" Title: "),vb);
73 mTitle = new KLineEdit ( vb ); 72 mTitle = new KLineEdit ( vb );
74 mTitleLabel = new QLabel(i18n("Title"),vb); 73 mTitleLabel = new QLabel(i18n("Title"),vb);
75 mTitleLabel->setMargin(0); 74 mTitleLabel->setMargin(0);
76 mTitleLabel->setAlignment(AlignCenter); 75 mTitleLabel->setAlignment(AlignCenter);
77 QPushButton * loadTemplate = new QPushButton( vb ); 76 QPushButton * loadTemplate = new QPushButton( vb );
78 QPushButton * saveTemplate = new QPushButton( vb ); 77 QPushButton * saveTemplate = new QPushButton( vb );
79 if ( QApplication::desktop()->width() < 321 ) 78 if ( QApplication::desktop()->width() < 321 )
80 icon = SmallIcon("fileexport16"); 79 iconp = SmallIcon("fileexport16");
81 else 80 else
82 icon = SmallIcon("fileexport"); 81 iconp = SmallIcon("fileexport");
83 saveTemplate->setIconSet (icon ) ; 82 saveTemplate->setPixmap (iconp ) ;
84 int size = saveTemplate->sizeHint().height(); 83 int size = saveTemplate->sizeHint().height();
85 if ( QApplication::desktop()->width() < 321 ) 84 if ( QApplication::desktop()->width() < 321 )
86 icon = SmallIcon("fileimport16"); 85 iconp = SmallIcon("fileimport16");
87 else 86 else
88 icon = SmallIcon("fileimport"); 87 iconp = SmallIcon("fileimport");
89 loadTemplate->setIconSet (icon ) ; 88 loadTemplate->setPixmap (iconp ) ;
90 loadTemplate->setFixedSize( size, size ); 89 loadTemplate->setFixedSize( size, size );
91 saveTemplate->setFixedSize( size, size ); 90 saveTemplate->setFixedSize( size, size );
92 toggleJournal->setFixedSize( size , size ); 91 toggleJournal->setFixedSize( size , size );
93 mEditor = new KTextEdit(this); 92 mEditor = new KTextEdit(this);
94 connect(mEditor,SIGNAL(textChanged()),SLOT(setDirty()));
95#ifndef DESKTOP_VERSION 93#ifndef DESKTOP_VERSION
96 QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold ); 94 QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold );
97#endif 95#endif
98 mEditor->setWordWrap( KTextEdit::WidgetWidth ); 96 mEditor->setWordWrap( KTextEdit::WidgetWidth );
99 QBoxLayout *topLayout = new QVBoxLayout(this); 97 QBoxLayout *topLayout = new QVBoxLayout(this);
100 topLayout->addWidget(vb); 98 topLayout->addWidget(vb);
101 topLayout->addWidget(mEditor); 99 topLayout->addWidget(mEditor);
102 mEditor->installEventFilter(this); 100 mEditor->installEventFilter(this);
103 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) ); 101 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) );
104 connect( mTitle, SIGNAL( textChanged ( const QString & ) ), this , SLOT( setDirty() ) );
105 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) ); 102 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) );
106 connect( toggleJournal, SIGNAL( clicked() ), this , SLOT( toggleShowJournal() ) ); 103 connect( toggleJournal, SIGNAL( clicked() ), this , SLOT( toggleShowJournal() ) );
107} 104}
108 105
109JournalEntry::~JournalEntry() 106JournalEntry::~JournalEntry()
110{ 107{
111 //qDebug("JournalEntry::~JournalEntry() "); 108 //qDebug("JournalEntry::~JournalEntry() ");
112} 109}
113QSize JournalEntry::sizeHint() const 110QSize JournalEntry::sizeHint() const
114{ 111{
115 return QSize ( 240, heiHint ); 112 return QSize ( 240, heiHint );
116} 113}
117void JournalEntry::slotSaveTemplate() 114void JournalEntry::slotSaveTemplate()
118{ 115{
119 QString fileName =locateLocal( "templates", "journals" ); 116 QString fileName =locateLocal( "templates", "journals" );
120 QDir t_dir; 117 QDir t_dir;
121 if ( !t_dir.exists(fileName) ) 118 if ( !t_dir.exists(fileName) )
122 t_dir.mkdir ( fileName ); 119 t_dir.mkdir ( fileName );
123 fileName += "/journal"; 120 fileName += "/journal";
124 fileName = KFileDialog::getSaveFileName( fileName , i18n("Save as Journal template"), this ); 121 fileName = KFileDialog::getSaveFileName( fileName , i18n("Save as Journal template"), this );
125 if ( fileName.length() == 0 ) 122 if ( fileName.length() == 0 )
126 return; 123 return;
127 124
128 QFile fileIn( fileName ); 125 QFile fileIn( fileName );
129 if (!fileIn.open( IO_WriteOnly ) ) { 126 if (!fileIn.open( IO_WriteOnly ) ) {
130 KMessageBox::error( this, i18n("Error saving template file\n '%1'.") 127 KMessageBox::error( this, i18n("Error saving template file\n '%1'.")
131 .arg( fileName ) ); 128 .arg( fileName ) );
132 return; 129 return;
133 } 130 }
134 // QString text; 131 // QString text;
135 QTextStream tsIn( &fileIn ); 132 QTextStream tsIn( &fileIn );
136 tsIn.setCodec( QTextCodec::codecForName("utf8") ); 133 tsIn.setCodec( QTextCodec::codecForName("utf8") );
137 tsIn << mEditor->text(); 134 tsIn << mEditor->text();
138 fileIn.close(); 135 fileIn.close();
139} 136}
140void JournalEntry::slotLoadTemplate() 137void JournalEntry::slotLoadTemplate()
141{ 138{
142 QString fileName =locateLocal( "templates", "journals" ); 139 QString fileName =locateLocal( "templates", "journals" );
143 QDir t_dir; 140 QDir t_dir;
144 if ( !t_dir.exists(fileName) ) 141 if ( !t_dir.exists(fileName) )
145 t_dir.mkdir ( fileName ); 142 t_dir.mkdir ( fileName );
146 fileName += "/journal"; 143 fileName += "/journal";
147 fileName = KFileDialog::getOpenFileName( fileName , i18n("Insert Journal template"), this ); 144 fileName = KFileDialog::getOpenFileName( fileName , i18n("Insert Journal template"), this );
148 if ( fileName.length() == 0 ) 145 if ( fileName.length() == 0 )
149 return; 146 return;
150 QFile fileIn( fileName ); 147 QFile fileIn( fileName );
151 if (!fileIn.open( IO_ReadOnly ) ) { 148 if (!fileIn.open( IO_ReadOnly ) ) {
152 KMessageBox::error( this, i18n("Error loading template file\n '%1'.") 149 KMessageBox::error( this, i18n("Error loading template file\n '%1'.")
153 .arg( fileName ) ); 150 .arg( fileName ) );
154 return; 151 return;
155 } 152 }
156 QTextStream tsIn( &fileIn ); 153 QTextStream tsIn( &fileIn );
157 tsIn.setCodec( QTextCodec::codecForName("utf8") ); 154 tsIn.setCodec( QTextCodec::codecForName("utf8") );
158 QString text = tsIn.read(); 155 QString text = tsIn.read();
159 fileIn.close(); 156 fileIn.close();
160 int line, col; 157 int line, col;
161 mEditor->getCursorPosition (& line, & col ); 158 mEditor->getCursorPosition (& line, & col );
162 mEditor-> insertAt ( text, line, col, true ); 159 mEditor-> insertAt ( text, line, col, true );
163 //mEditor->setIgnoreMark( true ); 160 //mEditor->setIgnoreMark( true );
164 setDirty();
165} 161}
166void JournalEntry::setDate(const QDate &date) 162void JournalEntry::setDate(const QDate &date)
167{ 163{
168 showOnlyMode = false; 164 showOnlyMode = false;
169 mDate = date; 165 mDate = date;
170 writeJournal(); 166 writeJournal();
171 int id = mCalendar->defaultCalendar(); 167 int id = mCalendar->defaultCalendar();
172 QString calname = KOPrefs::instance()->getCalendar( id )->mName; 168 QString calname = KOPrefs::instance()->getCalendar( id )->mName;
173 mTitleLabel->setText( " (" + calname +")"); 169 mTitleLabel->setText( " (" + calname +")");
174} 170}
175 171
176void JournalEntry::toggleShowJournal() 172void JournalEntry::toggleShowJournal()
177{ 173{
178 flushEntry(); 174 flushEntry();
179 if ( showOnlyMode ) 175 if ( showOnlyMode )
180 emit showJournalOnly( 0 ); 176 emit showJournalOnly( 0 );
181 else 177 else
182 emit showJournalOnly( mJournal ); 178 emit showJournalOnly( mJournal );
183} 179}
184void JournalEntry::setShowOnly() 180void JournalEntry::setShowOnly()
185{ 181{
186 showOnlyMode = true; 182 showOnlyMode = true;
187 mEditor->setFocus(); 183 mEditor->setFocus();
188} 184}
189void JournalEntry::setJournal(Journal *journal) 185void JournalEntry::setJournal(Journal *journal)
190{ 186{
191 writeJournal(); 187 writeJournal();
192 188
193 mJournal = journal; 189 mJournal = journal;
194 if ( journal->isReadOnly() ) 190 if ( journal->isReadOnly() )
195 mTitle->setText(mJournal->summary()+" ("+i18n("readonly")+")"); 191 mTitle->setText(mJournal->summary()+" ("+i18n("readonly")+")");
196 else 192 else
197 mTitle->setText(mJournal->summary()); 193 mTitle->setText(mJournal->summary());
198 mEditor->setText(mJournal->description()); 194 mEditor->setText(mJournal->description());
199 mTitle->setReadOnly (journal->isReadOnly() ); 195 mTitle->setReadOnly (journal->isReadOnly() );
200 mEditor->setReadOnly ( journal->isReadOnly() ); 196 mEditor->setReadOnly ( journal->isReadOnly() );
201 int id = mJournal->calID(); 197 int id = mJournal->calID();
202 198
203 QString calname = KOPrefs::instance()->getCalendar( id )->mName; 199 QString calname = KOPrefs::instance()->getCalendar( id )->mName;
204 mTitleLabel->setText( " (" + calname +")"); 200 mTitleLabel->setText( " (" + calname +")");
205 201
206 mDirty = false;
207} 202}
208 203
209Journal *JournalEntry::journal() const 204Journal *JournalEntry::journal() const
210{ 205{
211 return mJournal; 206 return mJournal;
212} 207}
213 208
214void JournalEntry::setDirty()
215{
216 mDirty = true;
217
218// kdDebug() << "JournalEntry::setDirty()" << endl;
219}
220 209
221void JournalEntry::clear() 210void JournalEntry::clear()
222{ 211{
223 mJournal = 0; 212 mJournal = 0;
224 mEditor->setText(""); 213 mEditor->setText("");
225} 214}
226 215
227bool JournalEntry::eventFilter( QObject *o, QEvent *e ) 216bool JournalEntry::eventFilter( QObject *o, QEvent *e )
228{ 217{
229// kdDebug() << "JournalEntry::event received " << e->type() << endl; 218// kdDebug() << "JournalEntry::event received " << e->type() << endl;
230 219
231 if ( e->type() == QEvent::FocusOut ) { 220 if ( e->type() == QEvent::FocusOut ) {
232 writeJournal(); 221 writeJournal();
233 } 222 }
234 if ( e->type() == QEvent::KeyPress ) { 223 if ( e->type() == QEvent::KeyPress ) {
235 QKeyEvent * k = (QKeyEvent *) e; 224 QKeyEvent * k = (QKeyEvent *) e;
236 if ( k->state() == Qt::ControlButton ) { 225 if ( k->state() == Qt::ControlButton ) {
237 k->ignore(); 226 k->ignore();
238 //return true; 227 //return true;
239 } 228 }
240 } 229 }
241 230
242 return QFrame::eventFilter( o, e ); // standard event processing 231 return QFrame::eventFilter( o, e ); // standard event processing
243} 232}
244 233
245void JournalEntry::writeJournal() 234void JournalEntry::writeJournal()
246{ 235{
247// kdDebug() << "JournalEntry::writeJournal()" << endl;
248 if (!mDirty) return;
249 236
250 if (mEditor->text().isEmpty()) { 237 if (mEditor->text().isEmpty() && mTitle->text().isEmpty()) {
251 if ( mJournal ) { 238 if ( mJournal ) {
252 mDirty = false;
253 bool conf = KOPrefs::instance()->mConfirm; 239 bool conf = KOPrefs::instance()->mConfirm;
254 KOPrefs::instance()->mConfirm = false; 240 KOPrefs::instance()->mConfirm = false;
255 emit deleteJournal(mJournal); 241 emit deleteJournal(mJournal);
256 KOPrefs::instance()->mConfirm = conf; 242 KOPrefs::instance()->mConfirm = conf;
257 mJournal = 0; 243 mJournal = 0;
258 } 244 }
259 return; 245 return;
260 } 246 }
261 247
262// kdDebug() << "JournalEntry::writeJournal()..." << endl; 248// kdDebug() << "JournalEntry::writeJournal()..." << endl;
263 249
264 if (!mJournal) { 250 if (!mJournal) {
265 mJournal = new Journal; 251 mJournal = new Journal;
266 mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0))); 252 mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0)));
267 mCalendar->addJournal(mJournal); 253 mCalendar->addJournal(mJournal);
268 } 254 }
269 255
270 mJournal->setDescription(mEditor->text()); 256 mJournal->setDescription(mEditor->text());
271 mJournal->setSummary(mTitle->text()); 257 mJournal->setSummary(mTitle->text());
272 mDirty = false;
273} 258}
274 259
275void JournalEntry::flushEntry() 260void JournalEntry::flushEntry()
276{ 261{
277 if (!mDirty) return; 262 writeJournal();
278
279 writeJournal();
280} 263}
281void JournalEntry::keyPressEvent ( QKeyEvent * e ) 264void JournalEntry::keyPressEvent ( QKeyEvent * e )
282{ 265{
283 e->ignore(); 266 e->ignore();
284 267
285} 268}
diff --git a/korganizer/journalentry.h b/korganizer/journalentry.h
index b37cabd..f2db785 100644
--- a/korganizer/journalentry.h
+++ b/korganizer/journalentry.h
@@ -10,75 +10,72 @@
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
32class QLabel; 32class QLabel;
33class KTextEdit; 33class KTextEdit;
34class KLineEdit; 34class KLineEdit;
35 35
36using namespace KCal; 36using namespace KCal;
37 37
38class JournalEntry : public QFrame { 38class JournalEntry : public QFrame {
39 Q_OBJECT 39 Q_OBJECT
40 public: 40 public:
41 JournalEntry(Calendar *,QWidget *parent); 41 JournalEntry(Calendar *,QWidget *parent);
42 virtual ~JournalEntry(); 42 virtual ~JournalEntry();
43 43
44 void setJournal(Journal *); 44 void setJournal(Journal *);
45 Journal *journal() const; 45 Journal *journal() const;
46 46
47 void setDate(const QDate &); 47 void setDate(const QDate &);
48 48
49 void clear(); 49 void clear();
50 50
51 void flushEntry(); 51 void flushEntry();
52 void setShowOnly(); 52 void setShowOnly();
53 QSize sizeHint() const; 53 QSize sizeHint() const;
54 54
55 protected slots: 55 protected slots:
56 void slotSaveTemplate(); 56 void slotSaveTemplate();
57 void slotLoadTemplate(); 57 void slotLoadTemplate();
58 void setDirty();
59 void toggleShowJournal(); 58 void toggleShowJournal();
60 signals: 59 signals:
61 void deleteJournal(Journal *); 60 void deleteJournal(Journal *);
62 void newJournal(); 61 void newJournal();
63 void showJournalOnly( Journal * ); 62 void showJournalOnly( Journal * );
64 63
65 protected: 64 protected:
66 bool eventFilter( QObject *o, QEvent *e ); 65 bool eventFilter( QObject *o, QEvent *e );
67 66
68 void writeJournal(); 67 void writeJournal();
69 68
70 private: 69 private:
71 bool showOnlyMode; 70 bool showOnlyMode;
72 Calendar *mCalendar; 71 Calendar *mCalendar;
73 Journal *mJournal; 72 Journal *mJournal;
74 QDate mDate; 73 QDate mDate;
75 void keyPressEvent ( QKeyEvent * ) ; 74 void keyPressEvent ( QKeyEvent * ) ;
76 QLabel *mTitleLabel; 75 QLabel *mTitleLabel;
77 KLineEdit * mTitle; 76 KLineEdit * mTitle;
78 KTextEdit *mEditor; 77 KTextEdit *mEditor;
79 int heiHint; 78 int heiHint;
80
81 bool mDirty;
82}; 79};
83 80
84#endif 81#endif
diff --git a/korganizer/kojournalview.cpp b/korganizer/kojournalview.cpp
index ff87ef4..cb9a2c0 100644
--- a/korganizer/kojournalview.cpp
+++ b/korganizer/kojournalview.cpp
@@ -14,183 +14,185 @@
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// View of Journal entries 25// View of Journal entries
26 26
27#include <qlayout.h> 27#include <qlayout.h>
28#include <qscrollview.h> 28#include <qscrollview.h>
29#include <qpopupmenu.h> 29#include <qpopupmenu.h>
30#include <qhbox.h> 30#include <qhbox.h>
31#include <qpushbutton.h> 31#include <qpushbutton.h>
32#include <qlabel.h> 32#include <qlabel.h>
33#include <qpushbutton.h> 33#include <qpushbutton.h>
34#include <qapplication.h> 34#include <qapplication.h>
35 35
36#include <klocale.h> 36#include <klocale.h>
37#include <kdebug.h> 37#include <kdebug.h>
38#include "koprefs.h" 38#include "koprefs.h"
39#include <kglobal.h> 39#include <kglobal.h>
40 40
41#include <libkcal/calendar.h> 41#include <libkcal/calendar.h>
42 42
43#include "journalentry.h" 43#include "journalentry.h"
44 44
45#include "kojournalview.h" 45#include "kojournalview.h"
46using namespace KOrg; 46using namespace KOrg;
47 47
48KOJournalView::KOJournalView(Calendar *calendar, QWidget *parent, 48KOJournalView::KOJournalView(Calendar *calendar, QWidget *parent,
49 const char *name) 49 const char *name)
50 : KOrg::BaseView(calendar, parent, name) 50 : KOrg::BaseView(calendar, parent, name)
51{ 51{
52 mCalendar = calendar; 52 mCalendar = calendar;
53 QScrollView * sv = new QScrollView( this ); 53 QScrollView * sv = new QScrollView( this );
54 QHBoxLayout * hbl = new QHBoxLayout( this ); 54 QHBoxLayout * hbl = new QHBoxLayout( this );
55 hbl->addWidget( sv ); 55 hbl->addWidget( sv );
56 parWid = new QWidget( sv->viewport() ); 56 parWid = new QWidget( sv->viewport() );
57 sv->addChild(parWid); 57 sv->addChild(parWid);
58 sv->setResizePolicy( QScrollView:: AutoOneFit ); 58 sv->setResizePolicy( QScrollView:: AutoOneFit );
59 mTopLayout = new QVBoxLayout(parWid); 59 mTopLayout = new QVBoxLayout(parWid);
60 QHBox * vb = new QHBox ( parWid ); 60 QHBox * vb = new QHBox ( parWid );
61 QPushButton * newJournal = new QPushButton( vb ); 61 QPushButton * newJournal = new QPushButton( vb );
62 QIconSet icon; 62 QPixmap icon;
63 if ( QApplication::desktop()->width() < 321 ) 63 if ( QApplication::desktop()->width() < 321 )
64 icon = SmallIcon("ko16old"); 64 icon = SmallIcon("ko16old");
65 else 65 else
66 icon = SmallIcon("ko24old"); 66 icon = SmallIcon("ko24old");
67 newJournal->setIconSet (icon ) ; 67 newJournal->setPixmap (icon ) ;
68 int size = newJournal->sizeHint().height(); 68 int size = newJournal->sizeHint().height();
69 newJournal->setFixedSize( size, size ); 69 newJournal->setFixedSize( size, size );
70 mDateLabel = new QLabel ( vb ); 70 mDateLabel = new QLabel ( vb );
71 mTopLayout->addWidget( vb ); 71 mTopLayout->addWidget( vb );
72 mDateLabel->setMargin(1); 72 mDateLabel->setMargin(1);
73 mDateLabel->setAlignment(AlignCenter); 73 mDateLabel->setAlignment(AlignCenter);
74 connect( newJournal, SIGNAL( clicked() ), this , SLOT( newJournal() ) ); 74 connect( newJournal, SIGNAL( clicked() ), this , SLOT( newJournal() ) );
75 getNewEntry(); 75 getNewEntry();
76} 76}
77 77
78KOJournalView::~KOJournalView() 78KOJournalView::~KOJournalView()
79{ 79{
80} 80}
81 81
82int KOJournalView::currentDateCount() 82int KOJournalView::currentDateCount()
83{ 83{
84 return 0; 84 return 0;
85} 85}
86JournalEntry* KOJournalView::getNewEntry() 86JournalEntry* KOJournalView::getNewEntry()
87{ 87{
88 JournalEntry* Entry = new JournalEntry(mCalendar,parWid); 88 JournalEntry* Entry = new JournalEntry(mCalendar,parWid);
89 jEntries.append( Entry ); 89 jEntries.append( Entry );
90 mTopLayout->addWidget(Entry); 90 mTopLayout->addWidget(Entry);
91 Entry->setFont ( KOPrefs::instance()->mJornalViewFont ); 91 Entry->setFont ( KOPrefs::instance()->mJornalViewFont );
92 connect ( Entry,SIGNAL(deleteJournal(Journal *) ),this ,SIGNAL(deleteJournal(Journal *) ) ) ; 92 connect ( Entry,SIGNAL(deleteJournal(Journal *) ),this ,SIGNAL(deleteJournal(Journal *) ) ) ;
93 connect ( Entry,SIGNAL(newJournal() ),this ,SLOT(newJournal() ) ) ; 93 connect ( Entry,SIGNAL(newJournal() ),this ,SLOT(newJournal() ) ) ;
94 connect ( Entry,SIGNAL(showJournalOnly( Journal * ) ),this ,SLOT(showOnly ( Journal* ) ) ) ; 94 connect ( Entry,SIGNAL(showJournalOnly( Journal * ) ),this ,SLOT(showOnly ( Journal* ) ) ) ;
95 return Entry; 95 return Entry;
96} 96}
97 97
98QPtrList<Incidence> KOJournalView::selectedIncidences() 98QPtrList<Incidence> KOJournalView::selectedIncidences()
99{ 99{
100 QPtrList<Incidence> eventList; 100 QPtrList<Incidence> eventList;
101 101
102 return eventList; 102 return eventList;
103} 103}
104void KOJournalView::updateConfig() 104void KOJournalView::updateConfig()
105{ 105{
106 JournalEntry* mEntry = jEntries.first(); 106 JournalEntry* mEntry = jEntries.first();
107 while ( mEntry ) { 107 while ( mEntry ) {
108 mEntry->setFont ( KOPrefs::instance()->mJornalViewFont ); 108 mEntry->setFont ( KOPrefs::instance()->mJornalViewFont );
109 mEntry = jEntries.next(); 109 mEntry = jEntries.next();
110 } 110 }
111} 111}
112void KOJournalView::updateView() 112void KOJournalView::updateView()
113{ 113{
114 JournalEntry* mEntry = jEntries.first(); 114 JournalEntry* mEntry = jEntries.first();
115 while ( mEntry ) { 115 while ( mEntry ) {
116 mEntry->setFont ( KOPrefs::instance()->mJornalViewFont ); 116 mEntry->setFont ( KOPrefs::instance()->mJornalViewFont );
117 mEntry = jEntries.next(); 117 mEntry = jEntries.next();
118 } 118 }
119 showDates( mDate, QDate() ); 119 showDates( mDate, QDate() );
120} 120}
121 121
122void KOJournalView::flushView() 122void KOJournalView::flushView()
123{ 123{
124 JournalEntry* mEntry = jEntries.first(); 124 JournalEntry* mEntry = jEntries.first();
125 while ( mEntry ) { 125 while ( mEntry ) {
126 mEntry->flushEntry(); 126 mEntry->flushEntry();
127 mEntry = jEntries.next(); 127 mEntry = jEntries.next();
128 } 128 }
129} 129}
130 130
131void KOJournalView::clearList() 131void KOJournalView::clearList()
132{ 132{
133 JournalEntry* mEntry = jEntries.first(); 133 JournalEntry* mEntry = jEntries.first();
134 while ( mEntry ) { 134 while ( mEntry ) {
135 mEntry->clear(); 135 mEntry->clear();
136 mEntry = jEntries.next(); 136 mEntry = jEntries.next();
137 } 137 }
138} 138}
139void KOJournalView::newJournal() 139void KOJournalView::newJournal()
140{ 140{
141 flushView();
141 Journal* mJournal = new Journal; 142 Journal* mJournal = new Journal;
142 mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0))); 143 mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0)));
143 mCalendar->addJournal(mJournal); 144 mCalendar->addJournal(mJournal);
144 showDates( mDate, QDate() ); 145 showDates( mDate, QDate() );
145} 146}
146 147
147void KOJournalView::showOnly ( Journal* j ) 148void KOJournalView::showOnly ( Journal* j )
148{ 149{
150 flushView();
149 if ( j == 0 ) { 151 if ( j == 0 ) {
150 showDates( mDate, QDate() ); 152 showDates( mDate, QDate() );
151 return; 153 return;
152 } 154 }
153 QPtrList<Journal> jl; 155 QPtrList<Journal> jl;
154 jl.append ( j ); 156 jl.append ( j );
155 showList( jl ); 157 showList( jl );
156 JournalEntry* mEntry = jEntries.first(); 158 JournalEntry* mEntry = jEntries.first();
157 mEntry->setShowOnly(); 159 mEntry->setShowOnly();
158} 160}
159void KOJournalView::showList(QPtrList<Journal> jl) 161void KOJournalView::showList(QPtrList<Journal> jl)
160{ 162{
161 JournalEntry* mEntry = jEntries.first(); 163 JournalEntry* mEntry = jEntries.first();
162 JournalEntry* firstEntry = mEntry; 164 JournalEntry* firstEntry = mEntry;
163 int count = jl.count(); 165 int count = jl.count();
164 int iii = 0; 166 int iii = 0;
165 while ( iii < count ) { 167 while ( iii < count ) {
166 if ( !mEntry ) { 168 if ( !mEntry ) {
167 mEntry = getNewEntry(); 169 mEntry = getNewEntry();
168 mEntry->show(); 170 mEntry->show();
169 mEntry->setDate(mDate); 171 mEntry->setDate(mDate);
170 mEntry->setJournal(jl.at(iii)); 172 mEntry->setJournal(jl.at(iii));
171 mEntry = 0; 173 mEntry = 0;
172 } else { 174 } else {
173 mEntry->setDate(mDate); 175 mEntry->setDate(mDate);
174 mEntry->setJournal(jl.at(iii)); 176 mEntry->setJournal(jl.at(iii));
175 mEntry->show(); 177 mEntry->show();
176 mEntry = jEntries.next(); 178 mEntry = jEntries.next();
177 } 179 }
178 ++iii; 180 ++iii;
179 } 181 }
180 while ( mEntry ) { 182 while ( mEntry ) {
181 mEntry->setDate(mDate); 183 mEntry->setDate(mDate);
182 mEntry->clear(); 184 mEntry->clear();
183 if ( mEntry != firstEntry ) 185 if ( mEntry != firstEntry )
184 mEntry->hide(); 186 mEntry->hide();
185 else 187 else
186 mEntry->show(); 188 mEntry->show();
187 mEntry = jEntries.next(); 189 mEntry = jEntries.next();
188 } 190 }
189} 191}
190 192
191void KOJournalView::showDates(const QDate &start, const QDate &) 193void KOJournalView::showDates(const QDate &start, const QDate &)
192{ 194{
193 mDate = start; 195 mDate = start;
194 mDateLabel-> setText(KGlobal::locale()->formatDate(mDate)); 196 mDateLabel-> setText(KGlobal::locale()->formatDate(mDate));
195 QPtrList<Journal> jl = calendar()->journals4Date( start ); 197 QPtrList<Journal> jl = calendar()->journals4Date( start );
196 showList( jl ); 198 showList( jl );