summaryrefslogtreecommitdiffabout
path: root/korganizer/journalentry.cpp
Unidiff
Diffstat (limited to 'korganizer/journalentry.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/journalentry.cpp83
1 files changed, 81 insertions, 2 deletions
diff --git a/korganizer/journalentry.cpp b/korganizer/journalentry.cpp
index 7af5cf4..dca42e0 100644
--- a/korganizer/journalentry.cpp
+++ b/korganizer/journalentry.cpp
@@ -17,68 +17,146 @@
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
46JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : 55JournalEntry::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
69JournalEntry::~JournalEntry() 98JournalEntry::~JournalEntry()
70{ 99{
71} 100}
72 101
102void 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}
125void 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}
73void JournalEntry::setDate(const QDate &date) 151void 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
83void JournalEntry::setJournal(Journal *journal) 161void JournalEntry::setJournal(Journal *journal)
84{ 162{
@@ -144,24 +222,25 @@ void JournalEntry::writeJournal()
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
160void JournalEntry::flushEntry() 239void JournalEntry::flushEntry()
161{ 240{
162 if (!mDirty) return; 241 if (!mDirty) return;
163 242
164 writeJournal(); 243 writeJournal();
165} 244}
166void JournalEntry::keyPressEvent ( QKeyEvent * e ) 245void JournalEntry::keyPressEvent ( QKeyEvent * e )
167{ 246{