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

kmail

  • sources
  • kde-4.12
  • kdepim
  • kmail
kmail_part.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-file-style: "gnu" -*-
2 
3  This file is part of KMail.
4  Copyright (c) 2002-2003 Don Sanders <sanders@kde.org>,
5  Copyright (c) 2003 Zack Rusin <zack@kde.org>,
6  Based on the work of Cornelius Schumacher <schumacher@kde.org>
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 
22  As a special exception, permission is given to link this program
23  with any edition of Qt, and distribute the resulting executable,
24  without including the source code for Qt in the source distribution.
25 */
26 
27 #include "kmail_part.h"
28 
29 #include "kmmainwin.h"
30 #include "kmmainwidget.h"
31 #include "kmstartup.h"
32 #include "aboutdata.h"
33 
34 #include <QVBoxLayout>
35 #include <QLabel>
36 
37 #include <kparts/statusbarextension.h>
38 #include <kparts/mainwindow.h>
39 #include <kpluginfactory.h>
40 #include <kpluginloader.h>
41 #include <kiconloader.h>
42 #include <kdebug.h>
43 #include <ksettings/dispatcher.h>
44 #include <kmailpartadaptor.h>
45 #include <kicon.h>
46 #include <akonadi/collection.h>
47 #include <akonadi/entitydisplayattribute.h>
48 #include <akonadi/changerecorder.h>
49 #include "foldertreeview.h"
50 #include "tag/tagactionmanager.h"
51 #include "foldershortcutactionmanager.h"
52 
53 #include <kglobal.h>
54 
55 K_PLUGIN_FACTORY( KMailFactory, registerPlugin<KMailPart>(); )
56 K_EXPORT_PLUGIN( KMailFactory( KMail::AboutData() ) )
57 
58 using namespace KMail;
59 
60 KMailPart::KMailPart(QWidget *parentWidget, QObject *parent, const QVariantList &) :
61  KParts::ReadOnlyPart( parent ),
62  mParentWidget( parentWidget )
63 {
64  kDebug() << "InstanceName:" << KGlobal::mainComponent().componentName();
65  setComponentData(KMailFactory::componentData());
66  kDebug() << "InstanceName:" << KGlobal::mainComponent().componentName();
67 
68  // import i18n data and icons from libraries:
69  KMail::insertLibraryCataloguesAndIcons();
70 
71 
72  //local, do the init
73  KMKernel *mKMailKernel = new KMKernel();
74  mKMailKernel->init();
75  mKMailKernel->setXmlGuiInstance( KMailFactory::componentData() );
76 
77  // and session management
78  mKMailKernel->doSessionManagement();
79 
80  // any dead letters?
81  mKMailKernel->recoverDeadLetters();
82 
83  kmkernel->setupDBus(); // Ok. We are ready for D-Bus requests.
84  (void) new KmailpartAdaptor( this );
85  QDBusConnection::sessionBus().registerObject( QLatin1String("/KMailPart"), this );
86 
87  // create a canvas to insert our widget
88  QWidget *canvas = new QWidget( parentWidget );
89  canvas->setFocusPolicy(Qt::ClickFocus);
90  canvas->setObjectName( QLatin1String("canvas") );
91  setWidget(canvas);
92  KIconLoader::global()->addAppDir( QLatin1String("libkdepim") );
93  mainWidget = new KMMainWidget( canvas, this, actionCollection(),
94  KGlobal::config() );
95  mainWidget->setObjectName( QLatin1String("partmainwidget") );
96  QVBoxLayout *topLayout = new QVBoxLayout(canvas);
97  topLayout->addWidget(mainWidget);
98  topLayout->setMargin(0);
99  mainWidget->setFocusPolicy(Qt::ClickFocus);
100  KParts::StatusBarExtension *statusBar = new KParts::StatusBarExtension(this);
101  statusBar->addStatusBarItem( mainWidget->vacationScriptIndicator(), 2, false );
102 
103  // Get to know when the user clicked on a folder in the KMail part and update the headerWidget of Kontact
104  connect( mainWidget->folderTreeView(), SIGNAL(currentChanged(Akonadi::Collection)),
105  this, SLOT(slotFolderChanged(Akonadi::Collection)) );
106  connect( kmkernel->folderCollectionMonitor(), SIGNAL(collectionChanged(Akonadi::Collection,QSet<QByteArray>)),
107  this, SLOT(slotCollectionChanged(Akonadi::Collection,QSet<QByteArray>)));
108  setXMLFile( QLatin1String("kmail_part.rc"), true );
109 
110  KSettings::Dispatcher::registerComponent( KMailFactory::componentData(), mKMailKernel, "slotConfigChanged" );
111 }
112 
113 KMailPart::~KMailPart()
114 {
115  kDebug() << "Closing last KMMainWin: stopping mail check";
116  // Running KIO jobs prevent kapp from exiting, so we need to kill them
117  // if they are only about checking mail (not important stuff like moving messages)
118  mainWidget->destruct();
119  kmkernel->cleanup();
120  delete kmkernel;
121 }
122 
123 bool KMailPart::openFile()
124 {
125  kDebug();
126 
127  mainWidget->show();
128  return true;
129 }
130 
131 void KMailPart::slotFolderChanged( const Akonadi::Collection &col )
132 {
133  //Don't know which code use it
134  if ( col.isValid() ) {
135  emit textChanged( col.name() );
136  if ( col.hasAttribute<Akonadi::EntityDisplayAttribute>() &&
137  !col.attribute<Akonadi::EntityDisplayAttribute>()->iconName().isEmpty() ) {
138  emit iconChanged( col.attribute<Akonadi::EntityDisplayAttribute>()->icon().pixmap( 22, 22 ) );
139  }
140  }
141 }
142 void KMailPart::slotCollectionChanged( const Akonadi::Collection &collection, const QSet<QByteArray> &attributeNames )
143 {
144  if( attributeNames.contains("ENTITYDISPLAY")|| attributeNames.contains( "NAME" ) )
145  slotFolderChanged(collection);
146 }
147 
148 //-----------------------------------------------------------------------------
149 
150 void KMailPart::guiActivateEvent(KParts::GUIActivateEvent *e)
151 {
152  kDebug();
153  KParts::ReadOnlyPart::guiActivateEvent(e);
154  mainWidget->initializeFilterActions();
155  mainWidget->tagActionManager()->createActions();
156  mainWidget->folderShortcutActionManager()->createActions();
157  mainWidget->updateVacationScriptStatus();
158 }
159 
160 void KMailPart::exit()
161 {
162  delete this;
163 }
164 
165 QWidget* KMailPart::parentWidget() const
166 {
167  return mParentWidget;
168 }
169 #include "kmail_part.moc"
170 
KMailPart::iconChanged
void iconChanged(const QPixmap &)
KMKernel::init
void init()
Definition: kmkernel.cpp:1152
KMail::AboutData
Definition: aboutdata.h:40
kmmainwidget.h
KMailPart::~KMailPart
virtual ~KMailPart()
Definition: kmail_part.cpp:113
KMKernel
Central point of coordination in KMail.
Definition: kmkernel.h:103
tagactionmanager.h
QWidget
KMMainWidget::tagActionManager
KMail::TagActionManager * tagActionManager() const
Definition: kmmainwidget.h:147
KMailPart::exit
Q_SCRIPTABLE void exit()
Definition: kmail_part.cpp:160
KMMainWidget::folderShortcutActionManager
KMail::FolderShortcutActionManager * folderShortcutActionManager() const
Definition: kmmainwidget.h:151
kmmainwin.h
KMailPart
Definition: kmail_part.h:39
QObject
KMMainWidget::destruct
void destruct()
Definition: kmmainwidget.cpp:385
K_EXPORT_PLUGIN
K_EXPORT_PLUGIN(KMailFactory(KMail::AboutData())) using namespace KMail
aboutdata.h
KMailPart::openFile
virtual bool openFile()
Definition: kmail_part.cpp:123
KMailPart::guiActivateEvent
virtual void guiActivateEvent(KParts::GUIActivateEvent *e)
Definition: kmail_part.cpp:150
KMKernel::recoverDeadLetters
void recoverDeadLetters()
Definition: kmkernel.cpp:1094
KMMainWidget
Definition: kmmainwidget.h:83
kmkernel
#define kmkernel
Definition: kmkernel.h:22
KMMainWidget::initializeFilterActions
void initializeFilterActions()
Definition: kmmainwidget.cpp:4286
KMailPart::textChanged
void textChanged(const QString &)
KMailPart::slotFolderChanged
void slotFolderChanged(const Akonadi::Collection &)
Definition: kmail_part.cpp:131
KMailPart::parentWidget
QWidget * parentWidget() const
Definition: kmail_part.cpp:165
KMailPart::slotCollectionChanged
void slotCollectionChanged(const Akonadi::Collection &collection, const QSet< QByteArray > &attributeNames)
Definition: kmail_part.cpp:142
KMKernel::setXmlGuiInstance
void setXmlGuiInstance(const KComponentData &instance)
Definition: kmkernel.h:348
foldershortcutactionmanager.h
kmstartup.h
KMMainWidget::updateVacationScriptStatus
void updateVacationScriptStatus()
Definition: kmmainwidget.h:138
KMail::FolderShortcutActionManager::createActions
void createActions()
Definition: foldershortcutactionmanager.cpp:75
KMKernel::doSessionManagement
bool doSessionManagement()
Definition: kmkernel.cpp:1201
KMail::TagActionManager::createActions
void createActions()
Creates and plugs all tag actions.
Definition: tagactionmanager.cpp:160
kmail_part.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmail

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal