koeventpopupmenu.cpp
00001 /* 00002 This file is part of KOrganizer. 00003 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 00004 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of TQt, and distribute the resulting executable, 00022 without including the source code for TQt in the source distribution. 00023 */ 00024 00025 #include <tqcursor.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 = TQDate(); 00051 mHasAdditionalItems = false; 00052 00053 insertItem( i18n("&Show"), this, TQT_SLOT( popupShow() ) ); 00054 mEditOnlyItems.append( 00055 insertItem(i18n("&Edit..."), this, TQT_SLOT( popupEdit() ) ) ); 00056 #ifndef KORG_NOPRINTER 00057 insertItem( KOGlobals::self()->smallIcon("printer1"), i18n("&Print..."), 00058 this, TQT_SLOT( print() ) ); 00059 #endif 00060 //------------------------------------------------------------------------ 00061 mEditOnlyItems.append( insertSeparator() ); 00062 mEditOnlyItems.append( 00063 insertItem( KOGlobals::self()->smallIcon("editcut"), i18n("&Cut"), 00064 this, TQT_SLOT( popupCut() ) ) ); 00065 mEditOnlyItems.append( 00066 insertItem( KOGlobals::self()->smallIcon("editcopy"), i18n("&Copy"), 00067 this, TQT_SLOT( popupCopy() ) ) ); 00068 // paste is always possible 00069 insertItem( KOGlobals::self()->smallIcon("editpaste"), i18n("&Paste"), 00070 this, TQT_SLOT( popupPaste() ) ); 00071 mEditOnlyItems.append( 00072 insertItem( KOGlobals::self()->smallIcon("editdelete"), i18n("&Delete"), 00073 this, TQT_SLOT( popupDelete() ) ) ); 00074 //------------------------------------------------------------------------ 00075 mEditOnlyItems.append( insertSeparator() ); 00076 mEditOnlyItems.append( 00077 insertItem( KOGlobals::self()->smallIcon("bell"), i18n("&Toggle Reminder"), 00078 this, TQT_SLOT( popupAlarm() ) ) ); 00079 //------------------------------------------------------------------------ 00080 mRecurrenceItems.append( insertSeparator() ); 00081 mRecurrenceItems.append( 00082 insertItem( i18n("&Dissociate This Occurrence"), 00083 this, TQT_SLOT( dissociateOccurrence() ) ) ); 00084 mRecurrenceItems.append( 00085 insertItem( i18n("&Dissociate Future Occurrences"), 00086 this, TQT_SLOT( dissociateFutureOccurrence() ) ) ); 00087 00088 insertSeparator(); 00089 insertItem( KOGlobals::self()->smallIcon("mail_forward"), i18n( "Send as iCalendar..."), 00090 this, TQT_SLOT(forward()) ); 00091 } 00092 00093 void KOEventPopupMenu::showIncidencePopup( Calendar *cal, Incidence *incidence, const TQDate &qd ) 00094 { 00095 mCalendar = cal; 00096 mCurrentIncidence = incidence; 00097 mCurrentDate = qd; 00098 00099 if (mCurrentIncidence) { 00100 // Enable/Disabled menu items only valid for editable events. 00101 TQValueList<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(TQCursor::pos()); 00109 } else { 00110 kdDebug(5850) << "KOEventPopupMenu::showEventPopup(): No event selected" << endl; 00111 } 00112 } 00113 00114 void KOEventPopupMenu::addAdditionalItem(const TQIconSet &icon,const TQString &text, 00115 const TQObject *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, TQT_SIGNAL(configChanged()), &printer, TQT_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 }