korganizer

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 Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
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   // paste is always possible
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     // Enable/Disabled menu items only valid for editable events.
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) emit showIncidenceSignal(mCurrentIncidence);
00129 }
00130 
00131 void KOEventPopupMenu::popupEdit()
00132 {
00133   if (mCurrentIncidence) emit editIncidenceSignal(mCurrentIncidence);
00134 }
00135 
00136 void KOEventPopupMenu::print()
00137 {
00138 #ifndef KORG_NOPRINTER
00139   KOCoreHelper helper;
00140   CalPrinter printer( this, mCalendar, &helper );
00141   connect( this, SIGNAL(configChanged()), &printer, SLOT(updateConfig()) );
00142 
00143   Incidence::List selectedIncidences;
00144   selectedIncidences.append( mCurrentIncidence );
00145 
00146   printer.print( KOrg::CalPrinterBase::Incidence,
00147                  mCurrentDate, mCurrentDate, selectedIncidences );
00148 #endif
00149 }
00150 
00151 void KOEventPopupMenu::popupDelete()
00152 {
00153   if (mCurrentIncidence) emit deleteIncidenceSignal(mCurrentIncidence);
00154 }
00155 
00156 void KOEventPopupMenu::popupCut()
00157 {
00158   if (mCurrentIncidence) emit cutIncidenceSignal(mCurrentIncidence);
00159 }
00160 
00161 void KOEventPopupMenu::popupCopy()
00162 {
00163   if (mCurrentIncidence) emit copyIncidenceSignal(mCurrentIncidence);
00164 }
00165 
00166 void KOEventPopupMenu::popupPaste()
00167 {
00168   emit pasteIncidenceSignal();
00169 }
00170 
00171 
00172 void KOEventPopupMenu::popupAlarm()
00173 {
00174   if (mCurrentIncidence) emit toggleAlarmSignal( mCurrentIncidence );
00175 }
00176 
00177 void KOEventPopupMenu::dissociateOccurrence()
00178 {
00179   if ( mCurrentIncidence )
00180     emit dissociateOccurrenceSignal( mCurrentIncidence, mCurrentDate );
00181 }
00182 
00183 void KOEventPopupMenu::dissociateFutureOccurrence()
00184 {
00185   if ( mCurrentIncidence )
00186     emit dissociateFutureOccurrenceSignal( mCurrentIncidence, mCurrentDate );
00187 }
00188 
00189 void KOEventPopupMenu::forward()
00190 {
00191   KOrg::MainWindow *w = ActionManager::findInstance( KURL() );
00192   if ( !w || !mCurrentIncidence )
00193     return;
00194   KActionCollection *ac = w->getActionCollection();
00195   KAction *action = ac->action( "schedule_forward" );
00196   action->activate();
00197 }
KDE Home | KDE Accessibility Home | Description of Access Keys