1 /* -*- mode: C++; c-file-style: "gnu" -*-
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>
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.
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.
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.
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.
27 #include "kmail_part.h"
29 #include "kmmainwin.h"
30 #include "kmmainwidget.h"
31 #include "kmstartup.h"
32 #include "aboutdata.h"
34 #include <QVBoxLayout>
36 #include <kparts/mainwindow.h>
37 #include <kpluginfactory.h>
38 #include <kpluginloader.h>
39 #include <kiconloader.h>
41 #include <ksettings/dispatcher.h>
42 #include <kmailpartadaptor.h>
44 #include <akonadi/collection.h>
45 #include <akonadi/entitydisplayattribute.h>
46 #include <akonadi/changerecorder.h>
47 #include "foldertreeview.h"
48 #include "tagactionmanager.h"
49 #include "foldershortcutactionmanager.h"
53 K_PLUGIN_FACTORY( KMailFactory
, registerPlugin
<KMailPart
>(); )
54 K_EXPORT_PLUGIN( KMailFactory( KMail::AboutData() ) )
56 using namespace KMail
;
58 KMailPart::KMailPart(QWidget
*parentWidget
, QObject
*parent
, const QVariantList
&) :
59 KParts::ReadOnlyPart( parent
),
60 mParentWidget( parentWidget
)
62 kDebug() << "InstanceName:" << KGlobal::mainComponent().componentName();
63 setComponentData(KMailFactory::componentData());
64 kDebug() << "InstanceName:" << KGlobal::mainComponent().componentName();
66 // import i18n data and icons from libraries:
67 KMail::insertLibraryCataloguesAndIcons();
73 KMKernel
*mKMailKernel
= new KMKernel();
75 mKMailKernel
->setXmlGuiInstance( KMailFactory::componentData() );
77 // and session management
78 mKMailKernel
->doSessionManagement();
81 mKMailKernel
->recoverDeadLetters();
83 kmkernel
->setupDBus(); // Ok. We are ready for D-Bus requests.
84 (void) new KmailpartAdaptor( this );
85 QDBusConnection::sessionBus().registerObject( "/KMailPart", this );
87 // create a canvas to insert our widget
88 QWidget
*canvas
= new QWidget( parentWidget
);
89 canvas
->setFocusPolicy(Qt::ClickFocus
);
90 canvas
->setObjectName( "canvas" );
92 KIconLoader::global()->addAppDir( "libkdepim" );
94 //It's also possible to make a part out of a readerWin
95 KMReaderWin
*mReaderWin
= new KMReaderWin( canvas
, canvas
, actionCollection() );
96 connect(mReaderWin
, SIGNAL(urlClicked(KUrl
,int)),
97 mReaderWin
, SLOT(slotUrlClicked()));
98 QVBoxLayout
*topLayout
= new QVBoxLayout(canvas
);
99 topLayout
->addWidget(mReaderWin
);
100 mReaderWin
->setAutoDelete( true );
101 kmkernel
->inboxFolder()->open();
102 KMMessage
*msg
= kmkernel
->inboxFolder()->getMsg(0);
103 mReaderWin
->setMsg( msg
, true );
104 mReaderWin
->setFocusPolicy(Qt::ClickFocus
);
105 mStatusBar
= new KMailStatusBarExtension(this);
106 //new KParts::SideBarExtension( kmkernel->mainWin()-mainKMWidget()->leftFrame(), this );
107 setXMLFile( "kmail_part.rc" );
108 kmkernel
->inboxFolder()->close();
110 mainWidget
= new KMMainWidget( canvas
, this, actionCollection(),
112 mainWidget
->setObjectName( "partmainwidget" );
113 QVBoxLayout
*topLayout
= new QVBoxLayout(canvas
);
114 topLayout
->addWidget(mainWidget
);
115 topLayout
->setMargin(0);
116 mainWidget
->setFocusPolicy(Qt::ClickFocus
);
117 mStatusBar
= new KMailStatusBarExtension(this);
118 mStatusBar
->addStatusBarItem( mainWidget
->vacationScriptIndicator(), 2, false );
120 // Get to know when the user clicked on a folder in the KMail part and update the headerWidget of Kontact
121 connect( mainWidget
->folderTreeView(), SIGNAL(currentChanged(Akonadi::Collection
)),
122 this, SLOT(slotFolderChanged(Akonadi::Collection
)) );
123 connect( kmkernel
->folderCollectionMonitor(), SIGNAL(collectionChanged(Akonadi::Collection
,QSet
<QByteArray
>)),
124 this, SLOT(slotCollectionChanged(Akonadi::Collection
,QSet
<QByteArray
>)));
125 setXMLFile( "kmail_part.rc", true );
128 KSettings::Dispatcher::registerComponent( KMailFactory::componentData(), mKMailKernel
, "slotConfigChanged" );
131 KMailPart::~KMailPart()
133 kDebug() << "Closing last KMMainWin: stopping mail check";
134 // Running KIO jobs prevent kapp from exiting, so we need to kill them
135 // if they are only about checking mail (not important stuff like moving messages)
136 mainWidget
->destruct();
139 KMail::cleanup(); // pid file (see kmstartup.cpp)
142 bool KMailPart::openFile()
150 void KMailPart::slotFolderChanged( const Akonadi::Collection
&col
)
152 if ( col
.isValid() ) {
153 emit
textChanged( col
.name() );
154 if ( col
.hasAttribute
<Akonadi::EntityDisplayAttribute
>() &&
155 !col
.attribute
<Akonadi::EntityDisplayAttribute
>()->iconName().isEmpty() ) {
156 emit
iconChanged( col
.attribute
<Akonadi::EntityDisplayAttribute
>()->icon().pixmap( 22, 22 ) );
160 void KMailPart::slotCollectionChanged( const Akonadi::Collection
&collection
, const QSet
<QByteArray
> &attributeNames
)
162 if( !attributeNames
.contains("ENTITYDISPLAY"))
164 slotFolderChanged(collection
);
167 //-----------------------------------------------------------------------------
169 void KMailPart::guiActivateEvent(KParts::GUIActivateEvent
*e
)
172 KParts::ReadOnlyPart::guiActivateEvent(e
);
173 mainWidget
->initializeFilterActions();
174 mainWidget
->tagActionManager()->createActions();
175 mainWidget
->folderShortcutActionManager()->createActions();
176 mainWidget
->updateVacationScriptStatus();
179 void KMailPart::exit()
184 QWidget
* KMailPart::parentWidget() const
186 return mParentWidget
;
190 KMailStatusBarExtension::KMailStatusBarExtension( KMailPart
*parent
)
191 : KParts::StatusBarExtension( parent
), mParent( parent
)
195 KMainWindow
* KMailStatusBarExtension::mainWindow() const
197 return static_cast<KMainWindow
*>( mParent
->parentWidget() );
200 #include "kmail_part.moc"