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 mCalendar = 0;
00049 mCurrentIncidence = 0;
00050 mCurrentDate = QDate();
00051 mHasAdditionalItems = false;
00052
00053 insertItem( i18n("&Show"), this, SLOT( popupShow() ) );
00054 mEditOnlyItems.append(
00055 insertItem(i18n("&Edit..."), this, SLOT( popupEdit() ) ) );
00056 #ifndef KORG_NOPRINTER
00057 insertItem( KOGlobals::self()->smallIcon("printer1"), i18n("&Print..."),
00058 this, SLOT( print() ) );
00059 #endif
00060
00061 mEditOnlyItems.append( insertSeparator() );
00062 mEditOnlyItems.append(
00063 insertItem( KOGlobals::self()->smallIcon("editcut"), i18n("&Cut"),
00064 this, SLOT( popupCut() ) ) );
00065 mEditOnlyItems.append(
00066 insertItem( KOGlobals::self()->smallIcon("editcopy"), i18n("&Copy"),
00067 this, SLOT( popupCopy() ) ) );
00068
00069 insertItem( KOGlobals::self()->smallIcon("editpaste"), i18n("&Paste"),
00070 this, SLOT( popupPaste() ) );
00071 mEditOnlyItems.append(
00072 insertItem( KOGlobals::self()->smallIcon("editdelete"), i18n("&Delete"),
00073 this, SLOT( popupDelete() ) ) );
00074
00075 mEditOnlyItems.append( insertSeparator() );
00076 mEditOnlyItems.append(
00077 insertItem( KOGlobals::self()->smallIcon("bell"), i18n("&Toggle Reminder"),
00078 this, SLOT( popupAlarm() ) ) );
00079
00080 mRecurrenceItems.append( insertSeparator() );
00081 mRecurrenceItems.append(
00082 insertItem( i18n("&Dissociate This Occurrence"),
00083 this, SLOT( dissociateOccurrence() ) ) );
00084 mRecurrenceItems.append(
00085 insertItem( i18n("&Dissociate Future Occurrences"),
00086 this, SLOT( dissociateFutureOccurrence() ) ) );
00087
00088 insertSeparator();
00089 insertItem( KOGlobals::self()->smallIcon("mail_forward"), i18n( "Send as iCalendar..."),
00090 this, SLOT(forward()) );
00091 }
00092
00093 void KOEventPopupMenu::showIncidencePopup( Calendar *cal, Incidence *incidence, const QDate &qd )
00094 {
00095 mCalendar = cal;
00096 mCurrentIncidence = incidence;
00097 mCurrentDate = qd;
00098
00099 if (mCurrentIncidence) {
00100
00101 QValueList<int>::Iterator it;
00102 for( it = mEditOnlyItems.begin(); it != mEditOnlyItems.end(); ++it ) {
00103 setItemEnabled(*it,!mCurrentIncidence->isReadOnly());
00104 }
00105 for ( it = mRecurrenceItems.begin(); it != mRecurrenceItems.end(); ++it ) {
00106 setItemVisible( *it, mCurrentIncidence->doesRecur() );
00107 }
00108 popup(QCursor::pos());
00109 } else {
00110 kdDebug(5850) << "KOEventPopupMenu::showEventPopup(): No event selected" << endl;
00111 }
00112 }
00113
00114 void KOEventPopupMenu::addAdditionalItem(const QIconSet &icon,const QString &text,
00115 const QObject *receiver, const char *member,
00116 bool editOnly)
00117 {
00118 if (!mHasAdditionalItems) {
00119 mHasAdditionalItems = true;
00120 insertSeparator();
00121 }
00122 int id = insertItem(icon,text,receiver,member);
00123 if (editOnly) mEditOnlyItems.append(id);
00124 }
00125
00126 void KOEventPopupMenu::popupShow()
00127 {
00128 if ( mCurrentIncidence ) {
00129 emit showIncidenceSignal( mCurrentIncidence, mCurrentDate );
00130 }
00131 }
00132
00133 void KOEventPopupMenu::popupEdit()
00134 {
00135 if ( mCurrentIncidence ) {
00136 emit editIncidenceSignal( mCurrentIncidence, mCurrentDate );
00137 }
00138 }
00139
00140 void KOEventPopupMenu::print()
00141 {
00142 #ifndef KORG_NOPRINTER
00143 KOCoreHelper helper;
00144 CalPrinter printer( this, mCalendar, &helper );
00145 connect( this, SIGNAL(configChanged()), &printer, SLOT(updateConfig()) );
00146
00147 Incidence::List selectedIncidences;
00148 selectedIncidences.append( mCurrentIncidence );
00149
00150 printer.print( KOrg::CalPrinterBase::Incidence,
00151 mCurrentDate, mCurrentDate, selectedIncidences );
00152 #endif
00153 }
00154
00155 void KOEventPopupMenu::popupDelete()
00156 {
00157 if (mCurrentIncidence) emit deleteIncidenceSignal(mCurrentIncidence);
00158 }
00159
00160 void KOEventPopupMenu::popupCut()
00161 {
00162 if (mCurrentIncidence) emit cutIncidenceSignal(mCurrentIncidence);
00163 }
00164
00165 void KOEventPopupMenu::popupCopy()
00166 {
00167 if (mCurrentIncidence) emit copyIncidenceSignal(mCurrentIncidence);
00168 }
00169
00170 void KOEventPopupMenu::popupPaste()
00171 {
00172 emit pasteIncidenceSignal();
00173 }
00174
00175
00176 void KOEventPopupMenu::popupAlarm()
00177 {
00178 if (mCurrentIncidence) emit toggleAlarmSignal( mCurrentIncidence );
00179 }
00180
00181 void KOEventPopupMenu::dissociateOccurrence()
00182 {
00183 if ( mCurrentIncidence )
00184 emit dissociateOccurrenceSignal( mCurrentIncidence, mCurrentDate );
00185 }
00186
00187 void KOEventPopupMenu::dissociateFutureOccurrence()
00188 {
00189 if ( mCurrentIncidence )
00190 emit dissociateFutureOccurrenceSignal( mCurrentIncidence, mCurrentDate );
00191 }
00192
00193 void KOEventPopupMenu::forward()
00194 {
00195 KOrg::MainWindow *w = ActionManager::findInstance( KURL() );
00196 if ( !w || !mCurrentIncidence )
00197 return;
00198 KActionCollection *ac = w->getActionCollection();
00199 KAction *action = ac->action( "schedule_forward" );
00200 action->activate();
00201 }