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

kmail

  • sources
  • kde-4.14
  • kdepim
  • kmail
  • widgets
kactionmenuaccount.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2015 Montel Laurent <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "kactionmenuaccount.h"
19 #include <Akonadi/AgentInstance>
20 #include <Akonadi/AgentManager>
21 #include "mailcommon/util/mailutil.h"
22 #include <KDebug>
23 #include <KMenu>
24 
25 KActionMenuAccount::KActionMenuAccount(QObject *parent)
26  : KActionMenu(parent),
27  mInitialized(false)
28 {
29  setDelayed(true);
30  connect( menu(),SIGNAL(aboutToShow()),SLOT(slotCheckTransportMenu()));
31  connect( menu(), SIGNAL(triggered(QAction*)), this, SLOT(slotSelectAccount(QAction*)) );
32  connect( Akonadi::AgentManager::self(), SIGNAL(instanceNameChanged(Akonadi::AgentInstance)), this, SLOT(updateAccountMenu()));
33  connect( Akonadi::AgentManager::self(), SIGNAL(instanceRemoved(Akonadi::AgentInstance)), this, SLOT(updateAccountMenu()));
34  connect( Akonadi::AgentManager::self(), SIGNAL(instanceAdded(Akonadi::AgentInstance)), this, SLOT(updateAccountMenu()));
35 }
36 
37 KActionMenuAccount::~KActionMenuAccount()
38 {
39 
40 }
41 
42 void KActionMenuAccount::slotSelectAccount(QAction *act)
43 {
44  if ( !act ) {
45  return;
46  }
47 
48  Akonadi::AgentInstance agent = Akonadi::AgentManager::self()->instance( act->data().toString() );
49  if ( agent.isValid() ) {
50  if ( !agent.isOnline() ) {
51  agent.setIsOnline( true );
52  }
53  agent.synchronize();
54  } else {
55  kDebug() << "account with identifier" << act->data().toString() << "not found";
56  }
57 }
58 
59 void KActionMenuAccount::slotCheckTransportMenu()
60 {
61  if (!mInitialized) {
62  mInitialized = true;
63  updateAccountMenu();
64  }
65 }
66 
67 
68 void KActionMenuAccount::updateAccountMenu()
69 {
70  if (mInitialized) {
71  menu()->clear();
72  const Akonadi::AgentInstance::List lst = MailCommon::Util::agentInstances();
73  Q_FOREACH ( const Akonadi::AgentInstance& type, lst ) {
74  // Explicitly make a copy, as we're not changing values of the list but only
75  // the local copy which is passed to action.
76  QAction* action = menu()->addAction( QString( type.name() ).replace(QLatin1Char('&'), QLatin1String("&&")) );
77  action->setData( type.identifier() );
78  }
79  }
80 }
kactionmenuaccount.h
QAction::data
QVariant data() const
KActionMenuAccount::KActionMenuAccount
KActionMenuAccount(QObject *parent=0)
Definition: kactionmenuaccount.cpp:25
QObject
QString
QAction::setData
void setData(const QVariant &userData)
QLatin1Char
KActionMenu
QLatin1String
QAction
KActionMenuAccount::~KActionMenuAccount
~KActionMenuAccount()
Definition: kactionmenuaccount.cpp:37
QVariant::toString
QString toString() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:33 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
  • pimprint

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