kmail_part.cpp 5.15 KB
Newer Older
Laurent Montel's avatar
Laurent Montel committed
1
/*
2

Stephan Kulow's avatar
Stephan Kulow committed
3
    This file is part of KMail.
4 5
    Copyright (c) 2002-2003 Don Sanders <sanders@kde.org>,
    Copyright (c) 2003      Zack Rusin  <zack@kde.org>,
Stephan Kulow's avatar
Stephan Kulow committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19
    Based on the work of Cornelius Schumacher <schumacher@kde.org>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Stephan Kulow's avatar
Stephan Kulow committed
21 22 23 24 25 26

    As a special exception, permission is given to link this program
    with any edition of Qt, and distribute the resulting executable,
    without including the source code for Qt in the source distribution.
*/

27
#include "kmail_part.h"
Stephan Kulow's avatar
Stephan Kulow committed
28 29 30

#include "kmmainwin.h"
#include "kmmainwidget.h"
Laurent Montel's avatar
Laurent Montel committed
31

Laurent Montel's avatar
Laurent Montel committed
32
#include <QVBoxLayout>
33

David Faure's avatar
David Faure committed
34
#include <KParts/GUIActivateEvent>
Laurent Montel's avatar
Laurent Montel committed
35
#include <kparts/statusbarextension.h>
36
#include <kparts/mainwindow.h>
37
#include <KPluginFactory>
Laurent Montel's avatar
Laurent Montel committed
38
#include "kmail_debug.h"
Till Adam's avatar
Till Adam committed
39
#include <ksettings/dispatcher.h>
Laurent Montel's avatar
Laurent Montel committed
40
#include <kmailpartadaptor.h>
Laurent Montel's avatar
Laurent Montel committed
41 42 43
#include <AkonadiCore/collection.h>
#include <AkonadiCore/entitydisplayattribute.h>
#include <AkonadiCore/changerecorder.h>
Laurent Montel's avatar
Laurent Montel committed
44
#include "MailCommon/FolderTreeView"
Laurent Montel's avatar
Laurent Montel committed
45
#include "tag/tagactionmanager.h"
46
#include "foldershortcutactionmanager.h"
47
#include "kmmigrateapplication.h"
Laurent Montel's avatar
Laurent Montel committed
48
#include <KLocalizedString>
Laurent Montel's avatar
Laurent Montel committed
49
#include "messageviewer/config-messageviewer.h"
50
#include <KSharedConfig>
51

Laurent Montel's avatar
Laurent Montel committed
52 53
K_PLUGIN_FACTORY(KMailFactory, registerPlugin<KMailPart>();
                 )
54

55 56
using namespace KMail;

Laurent Montel's avatar
Laurent Montel committed
57 58 59
KMailPart::KMailPart(QWidget *parentWidget, QObject *parent, const QVariantList &)
    : KParts::ReadOnlyPart(parent)
    , mParentWidget(parentWidget)
Stephan Kulow's avatar
Stephan Kulow committed
60
{
Laurent Montel's avatar
Laurent Montel committed
61
    setComponentName(QStringLiteral("kmail2"), i18n("KMail2"));
Laurent Montel's avatar
Laurent Montel committed
62

63 64
    KMMigrateApplication migrate;
    migrate.migrate();
Laurent Montel's avatar
Laurent Montel committed
65

Laurent Montel's avatar
Laurent Montel committed
66 67 68
    //local, do the init
    KMKernel *mKMailKernel = new KMKernel();
    mKMailKernel->init();
Laurent Montel's avatar
Laurent Montel committed
69
    mKMailKernel->setXmlGuiInstanceName(QStringLiteral("kmail2"));
Laurent Montel's avatar
Laurent Montel committed
70 71 72 73 74 75 76 77

    // and session management
    mKMailKernel->doSessionManagement();

    // any dead letters?
    mKMailKernel->recoverDeadLetters();

    kmkernel->setupDBus(); // Ok. We are ready for D-Bus requests.
Laurent Montel's avatar
Laurent Montel committed
78
    (void)new KmailpartAdaptor(this);
Laurent Montel's avatar
Laurent Montel committed
79
    QDBusConnection::sessionBus().registerObject(QStringLiteral("/KMailPart"), this);
Laurent Montel's avatar
Laurent Montel committed
80 81

    // create a canvas to insert our widget
Laurent Montel's avatar
Laurent Montel committed
82
    QWidget *canvas = new QWidget(parentWidget);
Laurent Montel's avatar
Laurent Montel committed
83
    canvas->setFocusPolicy(Qt::ClickFocus);
Laurent Montel's avatar
Laurent Montel committed
84
    canvas->setObjectName(QStringLiteral("canvas"));
Laurent Montel's avatar
Laurent Montel committed
85
    setWidget(canvas);
Laurent Montel's avatar
Laurent Montel committed
86 87
    mainWidget = new KMMainWidget(canvas, this, actionCollection(),
                                  KSharedConfig::openConfig());
Laurent Montel's avatar
Laurent Montel committed
88
    mainWidget->setObjectName(QStringLiteral("partmainwidget"));
Laurent Montel's avatar
Laurent Montel committed
89 90
    QVBoxLayout *topLayout = new QVBoxLayout(canvas);
    topLayout->addWidget(mainWidget);
91
    topLayout->setContentsMargins(0, 0, 0, 0);
Laurent Montel's avatar
Laurent Montel committed
92
    mainWidget->setFocusPolicy(Qt::ClickFocus);
Laurent Montel's avatar
Laurent Montel committed
93
    KParts::StatusBarExtension *statusBar = new KParts::StatusBarExtension(this);
Laurent Montel's avatar
Laurent Montel committed
94
    statusBar->addStatusBarItem(mainWidget->vacationScriptIndicator(), 2, false);
Laurent Montel's avatar
Laurent Montel committed
95
    statusBar->addStatusBarItem(mainWidget->zoomLabelIndicator(), 3, false);
Laurent Montel's avatar
Laurent Montel committed
96 97 98
#ifdef USE_DKIM_CHECKER
    statusBar->addStatusBarItem(mainWidget->dkimWidgetInfo(), 4, false);
#endif
Laurent Montel's avatar
Laurent Montel committed
99

Laurent Montel's avatar
Laurent Montel committed
100 101
    setXMLFile(QStringLiteral("kmail_part.rc"), true);
    KSettings::Dispatcher::registerComponent(QStringLiteral("kmail2"), mKMailKernel, "slotConfigChanged");
102
    connect(mainWidget, &KMMainWidget::captionChangeRequest, this, &KMailPart::setWindowCaption);
Stephan Kulow's avatar
Stephan Kulow committed
103 104 105 106
}

KMailPart::~KMailPart()
{
Laurent Montel's avatar
Laurent Montel committed
107
    qCDebug(KMAIL_LOG) << "Closing last KMMainWin: stopping mail check";
Laurent Montel's avatar
Laurent Montel committed
108 109 110 111 112
    // Running KIO jobs prevent kapp from exiting, so we need to kill them
    // if they are only about checking mail (not important stuff like moving messages)
    mainWidget->destruct();
    kmkernel->cleanup();
    delete kmkernel;
Stephan Kulow's avatar
Stephan Kulow committed
113 114
}

Laurent Montel's avatar
Laurent Montel committed
115 116 117 118 119
void KMailPart::updateQuickSearchText()
{
    mainWidget->updateQuickSearchLineText();
}

Stephan Kulow's avatar
Stephan Kulow committed
120 121
bool KMailPart::openFile()
{
Laurent Montel's avatar
Laurent Montel committed
122 123
    mainWidget->show();
    return true;
Stephan Kulow's avatar
Stephan Kulow committed
124 125
}

126 127
//-----------------------------------------------------------------------------

Stephan Kulow's avatar
Stephan Kulow committed
128 129
void KMailPart::guiActivateEvent(KParts::GUIActivateEvent *e)
{
Laurent Montel's avatar
Laurent Montel committed
130
    KParts::ReadOnlyPart::guiActivateEvent(e);
David Faure's avatar
David Faure committed
131
    if (e->activated()) {
Laurent Montel's avatar
Laurent Montel committed
132
        mainWidget->initializeFilterActions(true);
David Faure's avatar
David Faure committed
133 134 135 136 137 138 139 140 141
        mainWidget->tagActionManager()->createActions();
        mainWidget->folderShortcutActionManager()->createActions();
        mainWidget->populateMessageListStatusFilterCombo();
        mainWidget->initializePluginActions();

        const QString title = mainWidget->fullCollectionPath();
        if (!title.isEmpty()) {
            Q_EMIT setWindowCaption(title);
        }
142
    }
Stephan Kulow's avatar
Stephan Kulow committed
143 144 145 146
}

void KMailPart::exit()
{
Laurent Montel's avatar
Laurent Montel committed
147
    delete this;
Stephan Kulow's avatar
Stephan Kulow committed
148 149
}

Laurent Montel's avatar
Laurent Montel committed
150
QWidget *KMailPart::parentWidget() const
151
{
Laurent Montel's avatar
Laurent Montel committed
152
    return mParentWidget;
153
}
Laurent Montel's avatar
Laurent Montel committed
154 155 156 157 158

void KMailPart::save()
{
    /*TODO*/
}
Laurent Montel's avatar
Laurent Montel committed
159

160
#include "kmail_part.moc"