• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kontact

knotes_plugin.cpp

Go to the documentation of this file.
00001 /*
00002   This file is part of Kontact
00003   Copyright (c) 2002 Daniel Molkentin <molkentin@kde.org>
00004 
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Library General Public
00007   License as published by the Free Software Foundation; either
00008   version 2 of the License, or (at your option) any later version.
00009 
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Library General Public License for more details.
00014 
00015   You should have received a copy of the GNU Library General Public License
00016   along with this library; see the file COPYING.LIB.  If not, write to
00017   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018   Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "knotes_plugin.h"
00022 #include "knotes_part.h"
00023 #include "summarywidget.h"
00024 
00025 #include <kontactinterfaces/core.h>
00026 #include <kontactinterfaces/plugin.h>
00027 
00028 #include <libkdepim/maillistdrag.h>
00029 #include <libkdepim/kdepimprotocols.h>
00030 #include <libkdepim/kvcarddrag.h>
00031 #include <libkdepim/kpimprefs.h>
00032 
00033 #include <kcal/calendarlocal.h>
00034 #include <kcal/icaldrag.h>
00035 
00036 #include <kaboutdata.h>
00037 #include <kaction.h>
00038 #include <kdebug.h>
00039 #include <kgenericfactory.h>
00040 #include <kactioncollection.h>
00041 #include <kiconloader.h>
00042 #include <kstatusbar.h>
00043 #include <kicon.h>
00044 #include <kmessagebox.h>
00045 
00046 #include <QtDBus/QtDBus>
00047 #include <QtGui/QDropEvent>
00048 
00049 EXPORT_KONTACT_PLUGIN( KNotesPlugin, knotes )
00050 
00051 KNotesPlugin::KNotesPlugin( Kontact::Core *core, const QVariantList & )
00052   : Kontact::Plugin( core, core, "knotes" ), mAboutData( 0 )
00053 {
00054   setComponentData( KontactPluginFactory::componentData() );
00055 
00056   KAction *action = new KAction( KIcon( "knotes" ), i18n( "New Popup Note..." ), this );
00057   actionCollection()->addAction( "new_note", action );
00058   connect( action, SIGNAL(triggered(bool)), SLOT(slotNewNote()) );
00059   action->setShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_N ) );
00060   insertNewAction( action );
00061 
00062   KAction *syncAction = new KAction( KIcon( "view-refresh" ), i18n( "Synchronize Popup Notes" ), this );
00063   actionCollection()->addAction( "knotes_sync", syncAction );
00064   connect( action, SIGNAL(triggered(bool)), SLOT(slotSyncNotes()) );
00065   insertSyncAction( syncAction );
00066 }
00067 
00068 KNotesPlugin::~KNotesPlugin()
00069 {
00070 }
00071 
00072 QString KNotesPlugin::tipFile() const
00073 {
00074   // TODO: tips file
00075   //QString file = KStandardDirs::locate("data", "knotes/tips");
00076   QString file;
00077   return file;
00078 }
00079 
00080 KParts::ReadOnlyPart *KNotesPlugin::createPart()
00081 {
00082   return new KNotesPart( this );
00083 }
00084 
00085 Kontact::Summary *KNotesPlugin::createSummaryWidget( QWidget *parentWidget )
00086 {
00087   return new KNotesSummaryWidget( this, parentWidget );
00088 }
00089 
00090 const KAboutData *KNotesPlugin::aboutData()
00091 {
00092   if ( !mAboutData ) {
00093     mAboutData = new KAboutData( "knotes", 0, ki18n( "KNotes" ),
00094                                  "0.5", ki18n( "Popup Notes" ),
00095                                  KAboutData::License_GPL_V2,
00096                                  ki18n( "(c) 2003-2004 The Kontact developers" ) );
00097     mAboutData->addAuthor( ki18n( "Michael Brade" ),
00098                            ki18n( "Current Maintainer" ), "brade@kde.org" );
00099     mAboutData->addAuthor( ki18n( "Tobias Koenig" ),
00100                            KLocalizedString(), "tokoe@kde.org" );
00101   }
00102 
00103   return mAboutData;
00104 }
00105 
00106 bool KNotesPlugin::canDecodeMimeData( const QMimeData *mimeData )
00107 {
00108   return mimeData->hasText() || KPIM::MailList::canDecode( mimeData ) ||
00109          KPIM::KVCardDrag::canDecode( mimeData ) || KCal::ICalDrag::canDecode( mimeData );
00110 }
00111 
00112 void KNotesPlugin::processDropEvent( QDropEvent *event )
00113 {
00114   const QMimeData *md = event->mimeData();
00115 
00116   if ( KPIM::KVCardDrag::canDecode( md ) ) {
00117     KABC::Addressee::List contacts;
00118 
00119     KPIM::KVCardDrag::fromMimeData( md, contacts );
00120 
00121     KABC::Addressee::List::Iterator it;
00122 
00123     QStringList attendees;
00124     for ( it = contacts.begin(); it != contacts.end(); ++it ) {
00125       QString email = (*it).fullEmail();
00126       if ( email.isEmpty() ) {
00127         attendees.append( (*it).realName() + "<>" );
00128       } else {
00129         attendees.append( email );
00130       }
00131     }
00132 
00133     static_cast<KNotesPart *>( part() )->newNote( i18n( "Meeting" ), attendees.join(", ") );
00134     return;
00135   }
00136 
00137   if ( KCal::ICalDrag::canDecode( event->mimeData() ) ) {
00138     KCal::CalendarLocal cal( KPIM::KPimPrefs::timeSpec() );
00139     if ( KCal::ICalDrag::fromMimeData( event->mimeData(), &cal ) ) {
00140       KCal::Journal::List journals = cal.journals();
00141       if ( !journals.isEmpty() ) {
00142         event->accept();
00143         KCal::Journal *j = journals.first();
00144         static_cast<KNotesPart *>( part() )->newNote( i18n( "Note: %1", j->summary() ), j->description() );
00145         return;
00146       }
00147       // else fall through to text decoding
00148     }
00149   }
00150 
00151   if ( md->hasText() ) {
00152     static_cast<KNotesPart *>( part() )->newNote( i18n( "New Note" ), md->text() );
00153     return;
00154   }
00155 
00156   if ( KPIM::MailList::canDecode( md ) ) {
00157     KPIM::MailList mails = KPIM::MailList::fromMimeData( md );
00158     event->accept();
00159     if ( mails.count() != 1 ) {
00160       KMessageBox::sorry( core(),
00161                           i18n( "Dropping multiple mails is not supported." ) );
00162     } else {
00163       KPIM::MailSummary mail = mails.first();
00164       QString txt = i18n( "From: %1\nTo: %2\nSubject: %3", mail.from(), mail.to(), mail.subject() );
00165       static_cast<KNotesPart *>( part() )->newNote( i18n( "Mail: %1", mail.subject() ), txt );
00166     }
00167     return;
00168   }
00169 
00170   kWarning() << QString( "Cannot handle drop events of type '%1'." ).arg( event->format() );
00171 }
00172 
00173 // private slots
00174 
00175 void KNotesPlugin::slotNewNote()
00176 {
00177   if ( part() ) {
00178     static_cast<KNotesPart *>( part() )->newNote();
00179   }
00180 }
00181 
00182 void KNotesPlugin::slotSyncNotes()
00183 {
00184   QDBusMessage message = QDBusMessage::createMethodCall(
00185     "org.kde.kmail", "/Groupware", "org.kde.kmail.groupware", "triggerSync" );
00186   message << QString( "Popup Note" );
00187   QDBusConnection::sessionBus().send( message );
00188 }
00189 
00190 #include "knotes_plugin.moc"

kontact

Skip menu "kontact"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal