• 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
  • collectionpage
collectiontemplatespage.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-file-style: "gnu" -*-
2  This file is part of KMail, the KDE mail client.
3  Copyright (c) 2009, 2011 Montel Laurent <montel@kde.org>
4 
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.
8 
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.
13 
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
17 */
18 
19 #include "collectiontemplatespage.h"
20 
21 #include "kmkernel.h"
22 #include "kernel/mailkernel.h"
23 #include "foldercollection.h"
24 #include "templateparser/templatesconfiguration.h"
25 #include "templateparser/templatesconfiguration_kfg.h"
26 #include <akonadi/collection.h>
27 
28 #include <KLocale>
29 #include <KPushButton>
30 #include <QCheckBox>
31 
32 using namespace Akonadi;
33 using namespace MailCommon;
34 
35 CollectionTemplatesPage::CollectionTemplatesPage(QWidget * parent) :
36  CollectionPropertiesPage( parent ), mChanged(false)
37 {
38  setObjectName( QLatin1String( "KMail::CollectionTemplatesPage" ) );
39  setPageTitle( i18n( "Templates" ) );
40  init();
41 }
42 
43 CollectionTemplatesPage::~CollectionTemplatesPage()
44 {
45 }
46 
47 bool CollectionTemplatesPage::canHandle( const Collection &collection ) const
48 {
49  return ( !CommonKernel->isSystemFolderCollection( collection ) ||
50  CommonKernel->isMainFolderCollection( collection ) );
51 }
52 
53 void CollectionTemplatesPage::init()
54 {
55  QVBoxLayout *topLayout = new QVBoxLayout( this );
56  topLayout->setMargin( KDialog::marginHint() );
57  topLayout->setSpacing( KDialog::spacingHint() );
58 
59  QHBoxLayout *topItems = new QHBoxLayout;
60  topLayout->addLayout( topItems );
61 
62  mCustom = new QCheckBox( i18n("&Use custom message templates in this folder"), this );
63  connect(mCustom, SIGNAL(clicked(bool)), this, SLOT(slotChanged()));
64  topItems->addWidget( mCustom, Qt::AlignLeft );
65 
66  mWidget = new TemplateParser::TemplatesConfiguration( this, QLatin1String("folder-templates") );
67  connect(mWidget, SIGNAL(changed()), this, SLOT(slotChanged()));
68  mWidget->setEnabled( false );
69 
70  // Move the help label outside of the templates configuration widget,
71  // so that the help can be read even if the widget is not enabled.
72  topItems->addStretch( 9 );
73  topItems->addWidget( mWidget->helpLabel(), Qt::AlignRight );
74 
75  topLayout->addWidget( mWidget );
76 
77  QHBoxLayout *btns = new QHBoxLayout();
78  btns->setSpacing( KDialog::spacingHint() );
79  KPushButton *copyGlobal = new KPushButton( i18n("&Copy Global Templates"), this );
80  copyGlobal->setEnabled( false );
81  btns->addWidget( copyGlobal );
82  topLayout->addLayout( btns );
83 
84  connect( mCustom, SIGNAL(toggled(bool)),
85  mWidget, SLOT(setEnabled(bool)) );
86  connect( mCustom, SIGNAL(toggled(bool)),
87  copyGlobal, SLOT(setEnabled(bool)) );
88 
89  connect( copyGlobal, SIGNAL(clicked()),
90  this, SLOT(slotCopyGlobal()) );
91 }
92 
93 
94 void CollectionTemplatesPage::load(const Collection & col)
95 {
96  const QSharedPointer<FolderCollection> fd = FolderCollection::forCollection( col, false );
97  if ( !fd )
98  return;
99 
100  mCollectionId = QString::number( col.id() );
101 
102  TemplateParser::Templates t( mCollectionId );
103 
104  mCustom->setChecked(t.useCustomTemplates());
105 
106  mIdentity = fd->identity();
107 
108  mWidget->loadFromFolder( mCollectionId, mIdentity );
109  mChanged = false;
110 }
111 
112 void CollectionTemplatesPage::save(Collection &)
113 {
114  if ( mChanged && !mCollectionId.isEmpty() ) {
115  TemplateParser::Templates t(mCollectionId);
116  //kDebug() << "use custom templates for folder" << fid <<":" << mCustom->isChecked();
117  t.setUseCustomTemplates(mCustom->isChecked());
118  t.writeConfig();
119 
120  mWidget->saveToFolder(mCollectionId);
121  }
122 }
123 
124 void CollectionTemplatesPage::slotCopyGlobal() {
125  if ( mIdentity ) {
126  mWidget->loadFromIdentity( mIdentity );
127  } else {
128  mWidget->loadFromGlobal();
129  }
130 }
131 
132 void CollectionTemplatesPage::slotChanged()
133 {
134  mChanged = true;
135 }
136 
137 #include "collectiontemplatespage.moc"
QSharedPointer
Definition: collectionmailinglistpage.h:34
CollectionTemplatesPage::canHandle
bool canHandle(const Akonadi::Collection &collection) const
Definition: collectiontemplatespage.cpp:47
QWidget
CollectionTemplatesPage::slotCopyGlobal
void slotCopyGlobal()
Definition: collectiontemplatespage.cpp:124
CollectionTemplatesPage::CollectionTemplatesPage
CollectionTemplatesPage(QWidget *parent=0)
Definition: collectiontemplatespage.cpp:35
CollectionTemplatesPage::~CollectionTemplatesPage
~CollectionTemplatesPage()
Definition: collectiontemplatespage.cpp:43
kmkernel.h
CollectionTemplatesPage::save
void save(Akonadi::Collection &col)
Definition: collectiontemplatespage.cpp:112
CollectionTemplatesPage::load
void load(const Akonadi::Collection &col)
Definition: collectiontemplatespage.cpp:94
collectiontemplatespage.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