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 Calendar *cal;
00135 KOCoreHelper helper;
00136 CalPrinter printer( this, cal, &helper );
00137 connect( this, SIGNAL(configChanged()), &printer, SLOT(updateConfig()) );
00138
00139 Incidence::List selectedIncidences;
00140 selectedIncidences.append( mCurrentIncidence );
00141
00142 printer.print( KOrg::CalPrinterBase::Incidence,
00143 mCurrentDate, mCurrentDate, selectedIncidences );
00144 #endif
00145 }
00146
00147 void KOEventPopupMenu::popupDelete()
00148 {
00149 if (mCurrentIncidence) emit deleteIncidenceSignal(mCurrentIncidence);
00150 }
00151
00152 void KOEventPopupMenu::popupCut()
00153 {
00154 if (mCurrentIncidence) emit cutIncidenceSignal(mCurrentIncidence);
00155 }
00156
00157 void KOEventPopupMenu::popupCopy()
00158 {
00159 if (mCurrentIncidence) emit copyIncidenceSignal(mCurrentIncidence);
00160 }
00161
00162
00163 void KOEventPopupMenu::popupAlarm()
00164 {
00165 if (mCurrentIncidence) emit toggleAlarmSignal( mCurrentIncidence );
00166 }
00167
00168 void KOEventPopupMenu::dissociateOccurrence()
00169 {
00170 if ( mCurrentIncidence )
00171 emit dissociateOccurrenceSignal( mCurrentIncidence, mCurrentDate );
00172 }
00173
00174 void KOEventPopupMenu::dissociateFutureOccurrence()
00175 {
00176 if ( mCurrentIncidence )
00177 emit dissociateFutureOccurrenceSignal( mCurrentIncidence, mCurrentDate );
00178 }
00179
00180 void KOEventPopupMenu::forward()
00181 {
00182 KOrg::MainWindow *w = ActionManager::findInstance( KURL() );
00183 if ( !w || !mCurrentIncidence )
00184 return;
00185 KActionCollection *ac = w->getActionCollection();
00186 KAction *action = ac->action( "schedule_forward" );
00187 action->activate();
00188 }