-rw-r--r-- | korganizer/journalentry.cpp | 61 |
1 files changed, 49 insertions, 12 deletions
diff --git a/korganizer/journalentry.cpp b/korganizer/journalentry.cpp index c19a5ca..7274849 100644 --- a/korganizer/journalentry.cpp +++ b/korganizer/journalentry.cpp | |||
@@ -11,207 +11,244 @@ | |||
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 | 45 | ||
46 | #include <libkcal/journal.h> | 46 | #include <libkcal/journal.h> |
47 | #include <libkcal/calendarresources.h> | 47 | #include <libkcal/calendarresources.h> |
48 | #include <libkcal/resourcecalendar.h> | 48 | #include <libkcal/resourcecalendar.h> |
49 | #include <kresources/resourceselectdialog.h> | 49 | #include <kresources/resourceselectdialog.h> |
50 | 50 | ||
51 | #include "journalentry.h" | 51 | #include "journalentry.h" |
52 | //#include "journalentry.moc" | 52 | //#include "journalentry.moc" |
53 | #ifndef DESKTOP_VERSION | 53 | #ifndef DESKTOP_VERSION |
54 | #include <qpe/qpeapplication.h> | 54 | #include <qpe/qpeapplication.h> |
55 | #endif | 55 | #endif |
56 | JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : | 56 | JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : |
57 | QFrame(parent) | 57 | QFrame(parent) |
58 | { | 58 | { |
59 | showOnlyMode = false; | ||
59 | mCalendar = calendar; | 60 | mCalendar = calendar; |
60 | mJournal = 0; | 61 | mJournal = 0; |
61 | mDirty = false; | 62 | mDirty = false; |
62 | 63 | ||
63 | QHBox * vb = new QHBox ( this ); | 64 | QHBox * vb = new QHBox ( this ); |
65 | QPushButton * newJournal = new QPushButton( vb ); | ||
66 | QIconSet icon; | ||
67 | if ( QApplication::desktop()->width() < 321 ) | ||
68 | icon = SmallIcon("ko16old"); | ||
69 | else | ||
70 | icon = SmallIcon("ko24old"); | ||
71 | newJournal->setIconSet (icon ) ; | ||
72 | int size = newJournal->sizeHint().height(); | ||
73 | newJournal->setFixedSize( size, size ); | ||
74 | |||
75 | |||
76 | QPushButton * toggleJournal = new QPushButton( vb ); | ||
77 | icon = SmallIcon("1updownarrow"); | ||
78 | toggleJournal->setIconSet (icon ) ; | ||
79 | //int size = toggleJournal->sizeHint().height(); | ||
80 | toggleJournal->setFixedSize( size * 2 /3 , size ); | ||
81 | |||
82 | |||
83 | |||
84 | mTitleLabel = new QLabel(i18n("Title"),vb); | ||
85 | mTitleLabel->setMargin(2); | ||
86 | mTitleLabel->setAlignment(AlignCenter); | ||
64 | QPushButton * loadTemplate = new QPushButton( vb ); | 87 | QPushButton * loadTemplate = new QPushButton( vb ); |
65 | QPushButton * saveTemplate = new QPushButton( vb ); | 88 | QPushButton * saveTemplate = new QPushButton( vb ); |
66 | QIconSet icon; | ||
67 | if ( QApplication::desktop()->width() < 321 ) | 89 | if ( QApplication::desktop()->width() < 321 ) |
68 | icon = SmallIcon("fileexport16"); | 90 | icon = SmallIcon("fileexport16"); |
69 | else | 91 | else |
70 | icon = SmallIcon("fileexport"); | 92 | icon = SmallIcon("fileexport"); |
71 | saveTemplate->setIconSet (icon ) ; | 93 | saveTemplate->setIconSet (icon ) ; |
72 | int size = saveTemplate->sizeHint().height(); | 94 | //size = saveTemplate->sizeHint().height(); |
73 | saveTemplate->setFixedSize( size, size ); | 95 | saveTemplate->setFixedSize( size, size ); |
74 | if ( QApplication::desktop()->width() < 321 ) | 96 | if ( QApplication::desktop()->width() < 321 ) |
75 | icon = SmallIcon("fileimport16"); | 97 | icon = SmallIcon("fileimport16"); |
76 | else | 98 | else |
77 | icon = SmallIcon("fileimport"); | 99 | icon = SmallIcon("fileimport"); |
78 | loadTemplate->setIconSet (icon ) ; | 100 | loadTemplate->setIconSet (icon ) ; |
79 | loadTemplate->setFixedSize( size, size ); | 101 | loadTemplate->setFixedSize( size, size ); |
80 | |||
81 | mTitleLabel = new QLabel(i18n("Title"),vb); | ||
82 | mTitleLabel->setMargin(2); | ||
83 | mTitleLabel->setAlignment(AlignCenter); | ||
84 | |||
85 | mEditor = new KTextEdit(this); | 102 | mEditor = new KTextEdit(this); |
86 | connect(mEditor,SIGNAL(textChanged()),SLOT(setDirty())); | 103 | connect(mEditor,SIGNAL(textChanged()),SLOT(setDirty())); |
87 | #ifndef DESKTOP_VERSION | 104 | #ifndef DESKTOP_VERSION |
88 | QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold ); | 105 | QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold ); |
89 | #endif | 106 | #endif |
90 | mEditor->setWordWrap( KTextEdit::WidgetWidth ); | 107 | mEditor->setWordWrap( KTextEdit::WidgetWidth ); |
91 | QBoxLayout *topLayout = new QVBoxLayout(this); | 108 | QBoxLayout *topLayout = new QVBoxLayout(this); |
92 | topLayout->addWidget(vb); | 109 | topLayout->addWidget(vb); |
93 | topLayout->addWidget(mEditor); | 110 | topLayout->addWidget(mEditor); |
94 | mEditor->installEventFilter(this); | 111 | mEditor->installEventFilter(this); |
95 | connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) ); | 112 | connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) ); |
96 | connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) ); | 113 | connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) ); |
114 | connect( newJournal, SIGNAL( clicked() ), this , SIGNAL( newJournal() ) ); | ||
115 | connect( toggleJournal, SIGNAL( clicked() ), this , SLOT( toggleShowJournal() ) ); | ||
97 | } | 116 | } |
98 | 117 | ||
99 | JournalEntry::~JournalEntry() | 118 | JournalEntry::~JournalEntry() |
100 | { | 119 | { |
101 | } | 120 | } |
102 | 121 | ||
103 | void JournalEntry::slotSaveTemplate() | 122 | void JournalEntry::slotSaveTemplate() |
104 | { | 123 | { |
105 | QString fileName =locateLocal( "templates", "journals" ); | 124 | QString fileName =locateLocal( "templates", "journals" ); |
106 | QDir t_dir; | 125 | QDir t_dir; |
107 | if ( !t_dir.exists(fileName) ) | 126 | if ( !t_dir.exists(fileName) ) |
108 | t_dir.mkdir ( fileName ); | 127 | t_dir.mkdir ( fileName ); |
109 | fileName += "/journal"; | 128 | fileName += "/journal"; |
110 | fileName = KFileDialog::getSaveFileName( fileName , i18n("Save as Journal template"), this ); | 129 | fileName = KFileDialog::getSaveFileName( fileName , i18n("Save as Journal template"), this ); |
111 | if ( fileName.length() == 0 ) | 130 | if ( fileName.length() == 0 ) |
112 | return; | 131 | return; |
113 | 132 | ||
114 | QFile fileIn( fileName ); | 133 | QFile fileIn( fileName ); |
115 | if (!fileIn.open( IO_WriteOnly ) ) { | 134 | if (!fileIn.open( IO_WriteOnly ) ) { |
116 | KMessageBox::error( this, i18n("Error saving template file\n '%1'.") | 135 | KMessageBox::error( this, i18n("Error saving template file\n '%1'.") |
117 | .arg( fileName ) ); | 136 | .arg( fileName ) ); |
118 | return; | 137 | return; |
119 | } | 138 | } |
120 | // QString text; | 139 | // QString text; |
121 | QTextStream tsIn( &fileIn ); | 140 | QTextStream tsIn( &fileIn ); |
122 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); | 141 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); |
123 | tsIn << mEditor->text(); | 142 | tsIn << mEditor->text(); |
124 | fileIn.close(); | 143 | fileIn.close(); |
125 | } | 144 | } |
126 | void JournalEntry::slotLoadTemplate() | 145 | void JournalEntry::slotLoadTemplate() |
127 | { | 146 | { |
128 | QString fileName =locateLocal( "templates", "journals" ); | 147 | QString fileName =locateLocal( "templates", "journals" ); |
129 | QDir t_dir; | 148 | QDir t_dir; |
130 | if ( !t_dir.exists(fileName) ) | 149 | if ( !t_dir.exists(fileName) ) |
131 | t_dir.mkdir ( fileName ); | 150 | t_dir.mkdir ( fileName ); |
132 | fileName += "/journal"; | 151 | fileName += "/journal"; |
133 | fileName = KFileDialog::getOpenFileName( fileName , i18n("Insert Journal template"), this ); | 152 | fileName = KFileDialog::getOpenFileName( fileName , i18n("Insert Journal template"), this ); |
134 | if ( fileName.length() == 0 ) | 153 | if ( fileName.length() == 0 ) |
135 | return; | 154 | return; |
136 | QFile fileIn( fileName ); | 155 | QFile fileIn( fileName ); |
137 | if (!fileIn.open( IO_ReadOnly ) ) { | 156 | if (!fileIn.open( IO_ReadOnly ) ) { |
138 | KMessageBox::error( this, i18n("Error loading template file\n '%1'.") | 157 | KMessageBox::error( this, i18n("Error loading template file\n '%1'.") |
139 | .arg( fileName ) ); | 158 | .arg( fileName ) ); |
140 | return; | 159 | return; |
141 | } | 160 | } |
142 | QTextStream tsIn( &fileIn ); | 161 | QTextStream tsIn( &fileIn ); |
143 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); | 162 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); |
144 | QString text = tsIn.read(); | 163 | QString text = tsIn.read(); |
145 | fileIn.close(); | 164 | fileIn.close(); |
146 | int line, col; | 165 | int line, col; |
147 | mEditor->getCursorPosition (& line, & col ); | 166 | mEditor->getCursorPosition (& line, & col ); |
148 | mEditor-> insertAt ( text, line, col, true ); | 167 | mEditor-> insertAt ( text, line, col, true ); |
149 | //mEditor->setIgnoreMark( true ); | 168 | //mEditor->setIgnoreMark( true ); |
150 | setDirty(); | 169 | setDirty(); |
151 | } | 170 | } |
152 | void JournalEntry::setDate(const QDate &date) | 171 | void JournalEntry::setDate(const QDate &date) |
153 | { | 172 | { |
173 | showOnlyMode = false; | ||
174 | mDate = date; | ||
154 | writeJournal(); | 175 | writeJournal(); |
176 | int id = mCalendar->defaultCalendar(); | ||
177 | if ( id == 1 ) { | ||
178 | mTitleLabel->setText(KGlobal::locale()->formatDate(date)); | ||
179 | } else { | ||
180 | QString calname = KOPrefs::instance()->getCalendar( id )->mName; | ||
181 | mTitleLabel->setText( KGlobal::locale()->formatDate(mDate,true) + " (" + calname +")"); | ||
182 | } | ||
183 | } | ||
155 | 184 | ||
156 | mTitleLabel->setText(KGlobal::locale()->formatDate(date)); | 185 | void JournalEntry::toggleShowJournal() |
157 | 186 | { | |
158 | 187 | if ( showOnlyMode ) | |
159 | mDate = date; | 188 | emit showJournalOnly( 0 ); |
189 | else | ||
190 | emit showJournalOnly( mJournal ); | ||
160 | } | 191 | } |
161 | 192 | ||
162 | void JournalEntry::setJournal(Journal *journal) | 193 | void JournalEntry::setJournal(Journal *journal) |
163 | { | 194 | { |
164 | writeJournal(); | 195 | writeJournal(); |
165 | 196 | ||
166 | mJournal = journal; | 197 | mJournal = journal; |
167 | 198 | ||
168 | mEditor->setText(mJournal->description()); | 199 | mEditor->setText(mJournal->description()); |
169 | 200 | int id = mJournal->calID(); | |
201 | if ( id > 1 ) { | ||
202 | QString calname = KOPrefs::instance()->getCalendar( id )->mName; | ||
203 | mTitleLabel->setText( KGlobal::locale()->formatDate(mDate,true) + " (" + calname +")"); | ||
204 | } else { | ||
205 | mTitleLabel->setText(KGlobal::locale()->formatDate(mDate)); | ||
206 | } | ||
170 | mDirty = false; | 207 | mDirty = false; |
171 | } | 208 | } |
172 | 209 | ||
173 | Journal *JournalEntry::journal() const | 210 | Journal *JournalEntry::journal() const |
174 | { | 211 | { |
175 | return mJournal; | 212 | return mJournal; |
176 | } | 213 | } |
177 | 214 | ||
178 | void JournalEntry::setDirty() | 215 | void JournalEntry::setDirty() |
179 | { | 216 | { |
180 | mDirty = true; | 217 | mDirty = true; |
181 | 218 | ||
182 | // kdDebug() << "JournalEntry::setDirty()" << endl; | 219 | // kdDebug() << "JournalEntry::setDirty()" << endl; |
183 | } | 220 | } |
184 | 221 | ||
185 | void JournalEntry::clear() | 222 | void JournalEntry::clear() |
186 | { | 223 | { |
187 | mJournal = 0; | 224 | mJournal = 0; |
188 | mEditor->setText(""); | 225 | mEditor->setText(""); |
189 | } | 226 | } |
190 | 227 | ||
191 | bool JournalEntry::eventFilter( QObject *o, QEvent *e ) | 228 | bool JournalEntry::eventFilter( QObject *o, QEvent *e ) |
192 | { | 229 | { |
193 | // kdDebug() << "JournalEntry::event received " << e->type() << endl; | 230 | // kdDebug() << "JournalEntry::event received " << e->type() << endl; |
194 | 231 | ||
195 | if ( e->type() == QEvent::FocusOut ) { | 232 | if ( e->type() == QEvent::FocusOut ) { |
196 | writeJournal(); | 233 | writeJournal(); |
197 | } | 234 | } |
198 | if ( e->type() == QEvent::KeyPress ) { | 235 | if ( e->type() == QEvent::KeyPress ) { |
199 | QKeyEvent * k = (QKeyEvent *) e; | 236 | QKeyEvent * k = (QKeyEvent *) e; |
200 | if ( k->state() == Qt::ControlButton ) { | 237 | if ( k->state() == Qt::ControlButton ) { |
201 | k->ignore(); | 238 | k->ignore(); |
202 | //return true; | 239 | //return true; |
203 | } | 240 | } |
204 | } | 241 | } |
205 | 242 | ||
206 | return QFrame::eventFilter( o, e ); // standard event processing | 243 | return QFrame::eventFilter( o, e ); // standard event processing |
207 | } | 244 | } |
208 | 245 | ||
209 | void JournalEntry::writeJournal() | 246 | void JournalEntry::writeJournal() |
210 | { | 247 | { |
211 | // kdDebug() << "JournalEntry::writeJournal()" << endl; | 248 | // kdDebug() << "JournalEntry::writeJournal()" << endl; |
212 | if (!mDirty) return; | 249 | if (!mDirty) return; |
213 | 250 | ||
214 | if (mEditor->text().isEmpty()) { | 251 | if (mEditor->text().isEmpty()) { |
215 | if ( mJournal ) { | 252 | if ( mJournal ) { |
216 | mDirty = false; | 253 | mDirty = false; |
217 | bool conf = KOPrefs::instance()->mConfirm; | 254 | bool conf = KOPrefs::instance()->mConfirm; |