25 #include <tqtooltip.h>
27 #include <tqguardedptr.h>
30 #include <tqwidgetstack.h>
31 #include <tqdatetime.h>
32 #include <tqwhatsthis.h>
35 #include <tdelocale.h>
36 #include <kstandarddirs.h>
37 #include <tdemessagebox.h>
38 #include <kinputdialog.h>
39 #include <tdeio/netaccess.h>
40 #include <tdeabc/addressee.h>
42 #include <libtdepim/designerfields.h>
43 #include <libtdepim/embeddedurlpage.h>
45 #include <libkcal/calendarlocal.h>
46 #include <libkcal/incidence.h>
47 #include <libkcal/icalformat.h>
48 #include <libkcal/resourcecalendar.h>
51 #include "koglobals.h"
52 #include "koeditordetails.h"
53 #include "koeditoralarms.h"
54 #include "urihandler.h"
55 #include "koincidenceeditor.h"
56 #include "templatemanagementdialog.h"
59 Calendar *calendar, TQWidget *parent )
60 : KDialogBase( Tabbed, caption, Ok | Apply | Cancel | Default, Ok,
61 parent, 0, false, false ),
62 mAttendeeEditor( 0 ), mResource( 0 ), mIsCounter( false ), mIsCreateTask( false ),
63 mRecurIncidence( 0 ), mRecurIncidenceAfterDissoc( 0 )
67 setWFlags( getWFlags() | WGroupLeader );
71 if ( KOPrefs::instance()->mCompactDialogs ) {
72 showButton( Apply,
false );
73 showButton( Default,
false );
75 setButtonText( Default, i18n(
"&Templates...") );
78 connect(
this, TQ_SIGNAL( defaultClicked() ), TQ_SLOT( slotManageTemplates() ) );
79 connect(
this, TQ_SIGNAL( finished() ), TQ_SLOT( delayedDestruct() ) );
82 KOIncidenceEditor::~KOIncidenceEditor()
86 void KOIncidenceEditor::setupAttendeesTab()
88 TQFrame *topFrame = addPage( i18n(
"Atte&ndees") );
89 TQWhatsThis::add( topFrame,
90 i18n(
"The Attendees tab allows you to Add or Remove "
91 "Attendees to/from this event or to-do.") );
93 TQBoxLayout *topLayout =
new TQVBoxLayout( topFrame );
95 mAttendeeEditor = mDetails =
new KOEditorDetails( spacingHint(), topFrame );
96 topLayout->addWidget( mDetails );
99 void KOIncidenceEditor::slotApply()
104 void KOIncidenceEditor::slotOk()
109 TQGuardedPtr<TQWidget> ptr(
this );
113 void KOIncidenceEditor::slotCancel()
119 void KOIncidenceEditor::cancelRemovedAttendees(
Incidence *incidence )
121 if ( !incidence )
return;
125 if ( KOPrefs::instance()->thatIsMe( incidence->organizer().email() ) ) {
130 emit deleteAttendee( ev );
137 void KOIncidenceEditor::slotManageTemplates()
139 kdDebug(5850) <<
"KOIncidenceEditor::manageTemplates()" << endl;
141 TemplateManagementDialog *
const d =
new TemplateManagementDialog(
this, templates() );
142 connect( d, TQ_SIGNAL( loadTemplate(
const TQString& ) ),
143 this, TQ_SLOT( slotLoadTemplate(
const TQString& ) ) );
144 connect( d, TQ_SIGNAL( templatesChanged(
const TQStringList& ) ),
145 this, TQ_SLOT( slotTemplatesChanged(
const TQStringList& ) ) );
146 connect( d, TQ_SIGNAL( saveTemplate(
const TQString& ) ),
147 this, TQ_SLOT( slotSaveTemplate(
const TQString& ) ) );
152 void KOIncidenceEditor::saveAsTemplate(
Incidence *incidence,
153 const TQString &templateName )
155 if ( !incidence || templateName.isEmpty() )
return;
157 TQString fileName =
"templates/" + incidence->type();
158 fileName.append(
"/" + templateName );
159 fileName = locateLocal(
"data",
"korganizer/" + fileName );
162 cal.addIncidence( incidence );
164 format.
save( &cal, fileName );
167 void KOIncidenceEditor::slotLoadTemplate(
const TQString& templateName )
170 TQString fileName = locateLocal(
"data",
"korganizer/templates/" + type() +
"/" +
173 if ( fileName.isEmpty() ) {
174 KMessageBox::error(
this, i18n(
"Unable to find template '%1'.")
178 if ( !format.
load( &cal, fileName ) ) {
179 KMessageBox::error(
this, i18n(
"Error loading template file '%1'.")
187 void KOIncidenceEditor::slotTemplatesChanged(
const TQStringList& newTemplates )
189 templates() = newTemplates;
192 void KOIncidenceEditor::setupDesignerTabs(
const TQString &type )
194 TQStringList activePages = KOPrefs::instance()->activeDesignerFields();
196 TQStringList list = TDEGlobal::dirs()->findAllResources(
"data",
197 "korganizer/designer/" + type +
"/*.ui",
true,
true );
198 for ( TQStringList::iterator it = list.begin(); it != list.end(); ++it ) {
199 const TQString &fn = (*it).mid( (*it).findRev(
'/') + 1 );
200 if ( activePages.find( fn ) != activePages.end() ) {
201 addDesignerTab( *it );
206 TQWidget *KOIncidenceEditor::addDesignerTab(
const TQString &uifile )
208 kdDebug(5850) <<
"Designer tab: " << uifile << endl;
210 KPIM::DesignerFields *wid =
new KPIM::DesignerFields( uifile, 0 );
211 mDesignerFields.append( wid );
213 TQFrame *topFrame = addPage( wid->title() );
215 TQBoxLayout *topLayout =
new TQVBoxLayout( topFrame );
217 wid->reparent( topFrame, 0, TQPoint() );
218 topLayout->addWidget( wid );
219 mDesignerFieldForWidget[ topFrame ] = wid;
224 class KCalStorage :
public KPIM::DesignerFields::Storage
228 : mIncidence( incidence )
236 TQMap<TQCString, TQString> props = mIncidence->customProperties();
237 TQMap<TQCString, TQString>::ConstIterator it;
238 for( it = props.begin(); it != props.end(); ++it ) {
239 TQString customKey = it.key();
240 TQStringList parts = TQStringList::split(
"-", customKey );
241 if ( parts.count() != 4 )
continue;
242 if ( parts[ 2 ] !=
"KORGANIZER" )
continue;
243 keys.append( parts[ 3 ] );
249 TQString read(
const TQString &key )
251 return mIncidence->customProperty(
"KORGANIZER", key.utf8() );
254 void write(
const TQString &key,
const TQString &value )
256 mIncidence->setCustomProperty(
"KORGANIZER", key.utf8(), value );
263 void KOIncidenceEditor::readDesignerFields(
Incidence *i )
265 KCalStorage storage( i );
266 KPIM::DesignerFields *fields;
267 for( fields = mDesignerFields.first(); fields;
268 fields = mDesignerFields.next() ) {
269 fields->load( &storage );
273 void KOIncidenceEditor::writeDesignerFields(
Incidence *i )
275 kdDebug(5850) <<
"KOIncidenceEditor::writeDesignerFields()" << endl;
277 KCalStorage storage( i );
278 KPIM::DesignerFields *fields;
279 for( fields = mDesignerFields.first(); fields;
280 fields = mDesignerFields.next() ) {
281 kdDebug(5850) <<
"Write Field " << fields->title() << endl;
282 fields->save( &storage );
287 void KOIncidenceEditor::setupEmbeddedURLPage(
const TQString &label,
288 const TQString &url,
const TQString &mimetype )
290 kdDebug(5850) <<
"KOIncidenceEditor::setupEmbeddedURLPage()" << endl;
291 kdDebug(5850) <<
"label=" << label <<
", url=" << url <<
", mimetype=" << mimetype << endl;
292 TQFrame *topFrame = addPage( label );
293 TQBoxLayout *topLayout =
new TQVBoxLayout( topFrame );
295 KPIM::EmbeddedURLPage *wid =
new KPIM::EmbeddedURLPage( url, mimetype,
297 topLayout->addWidget( wid );
298 mEmbeddedURLPages.append( topFrame );
299 connect( wid, TQ_SIGNAL( openURL(
const KURL & ) ) ,
300 this, TQ_SLOT( openURL(
const KURL & ) ) );
305 void KOIncidenceEditor::createEmbeddedURLPages(
Incidence *i )
307 kdDebug(5850) <<
"KOIncidenceEditor::createEmbeddedURLPages()" << endl;
310 if ( !mEmbeddedURLPages.isEmpty() ) {
311 kdDebug(5850) <<
"mEmbeddedURLPages are not empty, clearing it!" << endl;
312 mEmbeddedURLPages.setAutoDelete(
true );
313 mEmbeddedURLPages.clear();
314 mEmbeddedURLPages.setAutoDelete(
false );
316 if ( !mAttachedDesignerFields.isEmpty() ) {
317 for ( TQPtrList<TQWidget>::Iterator it = mAttachedDesignerFields.begin();
318 it != mAttachedDesignerFields.end(); ++it ) {
319 if ( mDesignerFieldForWidget.contains( *it ) ) {
320 mDesignerFields.remove( mDesignerFieldForWidget[ *it ] );
323 mAttachedDesignerFields.setAutoDelete(
true );
324 mAttachedDesignerFields.clear();
325 mAttachedDesignerFields.setAutoDelete(
false );
329 for ( Attachment::List::Iterator it = att.begin(); it != att.end(); ++it ) {
331 kdDebug(5850) <<
"Iterating over the attachments " << endl;
332 kdDebug(5850) <<
"label=" << a->label() <<
", url=" << a->uri() <<
", mimetype=" << a->mimeType() << endl;
333 if ( a && a->showInline() && a->isUri() ) {
343 if ( a->mimeType() ==
"text/html" )
345 setupEmbeddedURLPage( a->label(), a->uri(), a->mimeType() );
351 void KOIncidenceEditor::openURL(
const KURL &url )
353 TQString uri = url.url();
354 UriHandler::process(
this, uri );
358 const TQStringList &mimeTypes,
359 bool inlineAttachments )
361 emit signalAddAttachments( attachments, mimeTypes, inlineAttachments );
366 TQStringList::ConstIterator it;
367 for ( it = attendees.begin(); it != attendees.end(); ++it ) {
368 TQString name, email;
369 TDEABC::Addressee::parseEmailAddress( *it, name, email );
370 mAttendeeEditor->insertAttendee(
new Attendee( name, email,
true, Attendee::NeedsAction ) );
374 void KOIncidenceEditor::setResource(
ResourceCalendar *res,
const TQString &subRes )
378 if ( !res->
subresources().isEmpty() && !subRes.isEmpty() ) {
381 label = res->resourceName();
386 mSubResource = subRes;
390 void KOIncidenceEditor::selectCreateTask(
bool enable )
392 mIsCreateTask = enable;
393 if ( mIsCreateTask ) {
394 setCaption( i18n(
"Create to-do" ) );
395 setButtonOK( i18n(
"Create to-do" ) );
396 showButtonApply(
false );
400 void KOIncidenceEditor::selectInvitationCounterProposal(
bool enable)
404 setCaption( i18n(
"Counter proposal" ) );
405 setButtonOK( i18n(
"Counter proposal" ) );
406 showButtonApply(
false );
413 mRecurIncidence = originalIncidence;
414 mRecurIncidenceAfterDissoc = incAfterDissociation;
418 #include "koincidenceeditor.moc"
int attendeeCount() const
void registerObserver(Observer *)
virtual Incidence * clone()=0
Attachment::List attachments() const
virtual TQStringList subresources() const
virtual const TQString labelForSubresource(const TQString &resource) const
void cancelAttendeeEvent(KCal::Incidence *incidence)
return a clone of the event with attendees to be canceld
KOIncidenceEditor(const TQString &caption, Calendar *calendar, TQWidget *parent)
Construct new IncidenceEditor.
void setRecurringIncidence(Incidence *originalIncidence, Incidence *incAfterDissociation)
This should be called when editing only one occurrence of a recurring incidence, before showing the e...
void addAttendees(const TQStringList &attendees)
Adds attendees to the editor.
void addAttachments(const TQStringList &attachments, const TQStringList &mimeTypes=TQStringList(), bool inlineAttachment=false)
Adds attachments to the editor.
virtual bool processInput()
Process user input and create or update event.