00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <qcursor.h>
00026
00027 #include <kactioncollection.h>
00028 #include <klocale.h>
00029 #include <kdebug.h>
00030 #include <kiconloader.h>
00031 #include <kurl.h>
00032
00033 #include <libkcal/event.h>
00034
00035 #include "koglobals.h"
00036
00037 #include <korganizer/baseview.h>
00038 #include "koeventpopupmenu.h"
00039 #include "koeventpopupmenu.moc"
00040 #include "kocorehelper.h"
00041 #include "actionmanager.h"
00042 #ifndef KORG_NOPRINTER
00043 #include "calprinter.h"
00044 #endif
00045
00046 KOEventPopupMenu::KOEventPopupMenu()
00047 {
00048 mCurrentIncidence = 0;
00049 mCurrentDate = QDate();
00050 mHasAdditionalItems = false;
00051
00052 insertItem( i18n("&Show"), this, SLOT( popupShow() ) );
00053 mEditOnlyItems.append(
00054 insertItem(i18n("&Edit..."), this, SLOT( popupEdit() ) ) );
00055 #ifndef KORG_NOPRINTER
00056 insertItem( KOGlobals::self()->smallIcon("printer1"), i18n("&Print..."),
00057 this, SLOT( print() ) );
00058 #endif
00059
00060 mEditOnlyItems.append( insertSeparator() );
00061 mEditOnlyItems.append(
00062 insertItem( KOGlobals::self()->smallIcon("editcut"), i18n("&Cut"),
00063 this, SLOT( popupCut() ) ) );
00064 mEditOnlyItems.append(
00065 insertItem( KOGlobals::self()->smallIcon("editcopy"), i18n("&Copy"),
00066 this, SLOT( popupCopy() ) ) );
00067 mEditOnlyItems.append(
00068 insertItem( KOGlobals::self()->smallIcon("editdelete"), i18n("&Delete"),
00069 this, SLOT( popupDelete() ) ) );
00070
00071 mEditOnlyItems.append( insertSeparator() );
00072 mEditOnlyItems.append(
00073 insertItem( KOGlobals::self()->smallIcon("bell"), i18n("&Toggle Reminder"),
00074 this, SLOT( popupAlarm() ) ) );
00075
00076 mRecurrenceItems.append( insertSeparator() );
00077 mRecurrenceItems.append(
00078 insertItem( i18n("&Dissociate This Occurrence"),
00079 this, SLOT( dissociateOccurrence() ) ) );
00080 mRecurrenceItems.append(
00081 insertItem( i18n("&Dissociate Future Occurrences"),
00082 this, SLOT( dissociateFutureOccurrence() ) ) );
00083
00084 insertSeparator();
00085 insertItem( KOGlobals::self()->smallIcon("mail_forward"), i18n( "Send as iCalendar..."),
00086 this, SLOT(forward()) );
00087 }
00088
00089 void KOEventPopupMenu::showIncidencePopup( Incidence *incidence, const QDate &qd )
00090 {
00091 mCurrentIncidence = incidence;
00092 mCurrentDate = qd;
00093
00094 if (mCurrentIncidence) {
00095
00096 QValueList<int>::Iterator it;
00097 for( it = mEditOnlyItems.begin(); it != mEditOnlyItems.end(); ++it ) {
00098 setItemEnabled(*it,!mCurrentIncidence->isReadOnly());
00099 }
00100 for ( it = mRecurrenceItems.begin(); it != mRecurrenceItems.end(); ++it ) {
00101 setItemVisible( *it, mCurrentIncidence->doesRecur() );
00102 }
00103 popup(QCursor::pos());
00104 } else {
00105 kdDebug(5850) << "KOEventPopupMenu::showEventPopup(): No event selected" << endl;
00106 }
00107 }
00108
00109 void KOEventPopupMenu::addAdditionalItem(const QIconSet &icon,const QString &text,
00110 const QObject *receiver, const char *member,
00111 bool editOnly)
00112 {
00113 if (!mHasAdditionalItems) {
00114 mHasAdditionalItems = true;
00115 insertSeparator();
00116 }
00117 int id = insertItem(icon,text,receiver,member);
00118 if (editOnly) mEditOnlyItems.append(id);
00119 }
00120
00121 void KOEventPopupMenu::popupShow()
00122 {
00123 if (mCurrentIncidence) emit showIncidenceSignal(mCurrentIncidence);
00124 }
00125
00126 void KOEventPopupMenu::popupEdit()
00127 {
00128 if (mCurrentIncidence) emit editIncidenceSignal(mCurrentIncidence);
00129 }
00130
00131 void KOEventPopupMenu::print()
00132 {
00133 #ifndef KORG_NOPRINTER
00134 KOCoreHelper helper;
00135 CalPrinter printer( this, 0, &helper );
00136 connect( this, SIGNAL(configChanged()), &printer, SLOT(updateConfig()) );
00137
00138 Incidence::List selectedIncidences;
00139 selectedIncidences.append( mCurrentIncidence );
00140
00141 printer.print( KOrg::CalPrinterBase::Incidence,
00142 mCurrentDate, mCurrentDate, selectedIncidences );
00143 #endif
00144 }
00145
00146 void KOEventPopupMenu::popupDelete()
00147 {
00148 if (mCurrentIncidence) emit deleteIncidenceSignal(mCurrentIncidence);
00149 }
00150
00151 void KOEventPopupMenu::popupCut()
00152 {
00153 if (mCurrentIncidence) emit cutIncidenceSignal(mCurrentIncidence);
00154 }
00155
00156 void KOEventPopupMenu::popupCopy()
00157 {
00158 if (mCurrentIncidence) emit copyIncidenceSignal(mCurrentIncidence);
00159 }
00160
00161
00162 void KOEventPopupMenu::popupAlarm()
00163 {
00164 if (mCurrentIncidence) emit toggleAlarmSignal( mCurrentIncidence );
00165 }
00166
00167 void KOEventPopupMenu::dissociateOccurrence()
00168 {
00169 if ( mCurrentIncidence )
00170 emit dissociateOccurrenceSignal( mCurrentIncidence, mCurrentDate );
00171 }
00172
00173 void KOEventPopupMenu::dissociateFutureOccurrence()
00174 {
00175 if ( mCurrentIncidence )
00176 emit dissociateFutureOccurrenceSignal( mCurrentIncidence, mCurrentDate );
00177 }
00178
00179 void KOEventPopupMenu::forward()
00180 {
00181 KOrg::MainWindow *w = ActionManager::findInstance( KURL() );
00182 if ( !w || !mCurrentIncidence )
00183 return;
00184 KActionCollection *ac = w->getActionCollection();
00185 KAction *action = ac->action( "schedule_forward" );
00186 action->activate();
00187 }