doc fixes found while translating
[kdepim.git] / kmail / collectiontemplatespage.cpp
blob16bcb6cb3dd0778d0750018467f10d7ac0dc88fc
1 /* -*- mode: C++; c-file-style: "gnu" -*-
2 This file is part of KMail, the KDE mail client.
3 Copyright (c) 2009 Montel Laurent <montel@kde.org>
5 KMail is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License, version 2, as
7 published by the Free Software Foundation.
9 KMail is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "collectiontemplatespage.h"
21 #include "kmkernel.h"
22 #include "mailkernel.h"
23 #include "foldercollection.h"
24 #include "templateparser/templatesconfiguration.h"
25 #include "templateparser/templatesconfiguration_kfg.h"
27 #include <akonadi/collection.h>
29 #include <KLocale>
30 #include <KPushButton>
31 #include <QCheckBox>
33 using namespace Akonadi;
34 using namespace MailCommon;
36 CollectionTemplatesPage::CollectionTemplatesPage(QWidget * parent) :
37 CollectionPropertiesPage( parent ), mFolderCollection( 0 )
39 setObjectName( QLatin1String( "KMail::CollectionTemplatesPage" ) );
40 setPageTitle( i18n( "Templates" ) );
41 init();
44 CollectionTemplatesPage::~CollectionTemplatesPage()
48 bool CollectionTemplatesPage::canHandle( const Collection &collection ) const
51 return ( !CommonKernel->isSystemFolderCollection( collection ) || CommonKernel->isMainFolderCollection( collection ) );
54 void CollectionTemplatesPage::init()
56 QVBoxLayout *topLayout = new QVBoxLayout( this );
57 topLayout->setMargin( KDialog::marginHint() );
58 topLayout->setSpacing( KDialog::spacingHint() );
60 QHBoxLayout *topItems = new QHBoxLayout;
61 topLayout->addLayout( topItems );
63 mCustom = new QCheckBox( i18n("&Use custom message templates in this folder"), this );
64 topItems->addWidget( mCustom, Qt::AlignLeft );
66 mWidget = new TemplatesConfiguration( this, "folder-templates" );
67 mWidget->setEnabled( false );
69 // Move the help label outside of the templates configuration widget,
70 // so that the help can be read even if the widget is not enabled.
71 topItems->addStretch( 9 );
72 topItems->addWidget( mWidget->helpLabel(), Qt::AlignRight );
74 topLayout->addWidget( mWidget );
76 QHBoxLayout *btns = new QHBoxLayout();
77 btns->setSpacing( KDialog::spacingHint() );
78 mCopyGlobal = new KPushButton( i18n("&Copy Global Templates"), this );
79 mCopyGlobal->setEnabled( false );
80 btns->addWidget( mCopyGlobal );
81 topLayout->addLayout( btns );
83 connect( mCustom, SIGNAL(toggled(bool)),
84 mWidget, SLOT(setEnabled(bool)) );
85 connect( mCustom, SIGNAL(toggled(bool)),
86 mCopyGlobal, SLOT(setEnabled(bool)) );
88 connect( mCopyGlobal, SIGNAL(clicked()),
89 this, SLOT(slotCopyGlobal()) );
93 void CollectionTemplatesPage::load(const Collection & col)
95 mFolderCollection = FolderCollection::forCollection( col );
96 if ( !mFolderCollection )
97 return;
99 const QString fid = mFolderCollection->idString();
101 Templates t( fid );
103 mCustom->setChecked(t.useCustomTemplates());
105 mIdentity = mFolderCollection->identity();
107 mWidget->loadFromFolder( fid, mIdentity );
110 void CollectionTemplatesPage::save(Collection &)
112 if ( mFolderCollection ) {
113 const QString fid = mFolderCollection->idString();
114 Templates t(fid);
116 //kDebug() << "use custom templates for folder" << fid <<":" << mCustom->isChecked();
117 t.setUseCustomTemplates(mCustom->isChecked());
118 t.writeConfig();
120 mWidget->saveToFolder(fid);
124 void CollectionTemplatesPage::slotCopyGlobal() {
125 if ( mIdentity ) {
126 mWidget->loadFromIdentity( mIdentity );
128 else {
129 mWidget->loadFromGlobal();
133 #include "collectiontemplatespage.moc"