-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 | |||
@@ -28,2 +28,9 @@ | |||
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 | ||
@@ -33,2 +40,4 @@ | |||
33 | #include <ktextedit.h> | 40 | #include <ktextedit.h> |
41 | #include <kfiledialog.h> | ||
42 | #include <kmessagebox.h> | ||
34 | #include "koprefs.h" | 43 | #include "koprefs.h" |
@@ -52,3 +61,21 @@ JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : | |||
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); |
@@ -63,5 +90,7 @@ JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : | |||
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 | } |
@@ -72,2 +101,51 @@ JournalEntry::~JournalEntry() | |||
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) |
@@ -155,2 +233,3 @@ void JournalEntry::writeJournal() | |||
155 | mJournal->setDescription(mEditor->text()); | 233 | mJournal->setDescription(mEditor->text()); |
234 | //qDebug("tttt%s ", mEditor->text().latin1()); | ||
156 | 235 | ||
diff --git a/korganizer/journalentry.h b/korganizer/journalentry.h index 1f784f4..f1a1fef 100644 --- a/korganizer/journalentry.h +++ b/korganizer/journalentry.h | |||
@@ -52,2 +52,4 @@ class JournalEntry : public QFrame { | |||
52 | protected slots: | 52 | protected slots: |
53 | void slotSaveTemplate(); | ||
54 | void slotLoadTemplate(); | ||
53 | void setDirty(); | 55 | void setDirty(); |
diff --git a/korganizer/koeventeditor.cpp b/korganizer/koeventeditor.cpp index 0ff99a4..337db9b 100644 --- a/korganizer/koeventeditor.cpp +++ b/korganizer/koeventeditor.cpp | |||
@@ -337,3 +337,3 @@ void KOEventEditor::slotLoadTemplate() | |||
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 ) |
@@ -366,3 +366,3 @@ void KOEventEditor::slotSaveTemplate() | |||
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 ) |