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

mailtransport

  • sources
  • kde-4.14
  • kdepimlibs
  • mailtransport
transportmanagementwidget.cpp
1 /*
2  Copyright (c) 2006 - 2007 Volker Krause <vkrause@kde.org>
3 
4  Based on KMail code by:
5  Copyright (C) 2001-2003 Marc Mutz <mutz@kde.org>
6 
7  This library is free software; you can redistribute it and/or modify it
8  under the terms of the GNU Library General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version.
11 
12  This library is distributed in the hope that it will be useful, but WITHOUT
13  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15  License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to the
19  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  02110-1301, USA.
21 */
22 
23 #include "transportmanagementwidget.h"
24 #include "ui_transportmanagementwidget.h"
25 #include "transportmanager.h"
26 #include "transport.h"
27 
28 #include <KMessageBox>
29 #include <KMenu>
30 #include <KGlobal>
31 
32 using namespace MailTransport;
33 
34 class TransportManagementWidget::Private
35 {
36  public:
37 
38  Private( TransportManagementWidget *parent );
39 
40  Ui::TransportManagementWidget ui;
41  TransportManagementWidget *q;
42 
43  // Slots
44  void defaultClicked();
45  void removeClicked();
46  void renameClicked();
47  void editClicked();
48  void addClicked();
49  void updateButtonState();
50  void slotCustomContextMenuRequested( const QPoint & );
51 };
52 
53 TransportManagementWidget::Private::Private( TransportManagementWidget *parent )
54  : q( parent )
55 {
56 }
57 
58 TransportManagementWidget::TransportManagementWidget( QWidget *parent )
59  : QWidget( parent ), d( new Private( this ) )
60 {
61  KGlobal::locale()->insertCatalog( QString::fromLatin1( "libmailtransport" ) );
62  d->ui.setupUi( this );
63  d->updateButtonState();
64 
65  d->ui.transportList->setContextMenuPolicy( Qt::CustomContextMenu );
66  connect( d->ui.transportList, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
67  SLOT(updateButtonState()) );
68  connect( d->ui.transportList, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),
69  SLOT(editClicked()) );
70  connect( d->ui.addButton, SIGNAL(clicked()), SLOT(addClicked()) );
71  connect( d->ui.editButton, SIGNAL(clicked()), SLOT(editClicked()) );
72  connect( d->ui.renameButton, SIGNAL(clicked()), SLOT(renameClicked()) );
73  connect( d->ui.removeButton, SIGNAL(clicked()), SLOT(removeClicked()) );
74  connect( d->ui.defaultButton, SIGNAL(clicked()), SLOT(defaultClicked()) );
75  connect( d->ui.transportList, SIGNAL(customContextMenuRequested(QPoint)),
76  SLOT(slotCustomContextMenuRequested(QPoint)) );
77 }
78 
79 TransportManagementWidget::~TransportManagementWidget()
80 {
81  delete d;
82 }
83 
84 void TransportManagementWidget::Private::updateButtonState()
85 {
86  // TODO figure out current item vs. selected item (in almost every function)
87  if ( !ui.transportList->currentItem() ) {
88  ui.editButton->setEnabled( false );
89  ui.renameButton->setEnabled( false );
90  ui.removeButton->setEnabled( false );
91  ui.defaultButton->setEnabled( false );
92  } else {
93  ui.editButton->setEnabled( true );
94  ui.renameButton->setEnabled( true );
95  ui.removeButton->setEnabled( true );
96  if ( ui.transportList->currentItem()->data( 0, Qt::UserRole ) ==
97  TransportManager::self()->defaultTransportId() ) {
98  ui.defaultButton->setEnabled( false );
99  } else {
100  ui.defaultButton->setEnabled( true );
101  }
102  }
103 }
104 
105 void TransportManagementWidget::Private::addClicked()
106 {
107  TransportManager::self()->showTransportCreationDialog( q );
108 }
109 
110 void TransportManagementWidget::Private::editClicked()
111 {
112  if ( !ui.transportList->currentItem() ) {
113  return;
114  }
115 
116  const int currentId = ui.transportList->currentItem()->data( 0, Qt::UserRole ).toInt();
117  Transport *transport = TransportManager::self()->transportById( currentId );
118  TransportManager::self()->configureTransport( transport, q );
119 }
120 
121 void TransportManagementWidget::Private::renameClicked()
122 {
123  if ( !ui.transportList->currentItem() ) {
124  return;
125  }
126 
127  ui.transportList->editItem( ui.transportList->currentItem(), 0 );
128 }
129 
130 void TransportManagementWidget::Private::removeClicked()
131 {
132  if ( !ui.transportList->currentItem() ) {
133  return;
134  }
135  const int rc =
136  KMessageBox::questionYesNo(
137  q,
138  i18n( "Do you want to remove outgoing account '%1'?",
139  ui.transportList->currentItem()->text( 0 ) ),
140  i18n( "Remove outgoing account?" ) );
141  if ( rc == KMessageBox::No ) {
142  return;
143  }
144 
145  TransportManager::self()->removeTransport(
146  ui.transportList->currentItem()->data( 0, Qt::UserRole ).toInt() );
147 }
148 
149 void TransportManagementWidget::Private::defaultClicked()
150 {
151  if ( !ui.transportList->currentItem() ) {
152  return;
153  }
154 
155  TransportManager::self()->setDefaultTransport(
156  ui.transportList->currentItem()->data( 0, Qt::UserRole ).toInt() );
157 }
158 
159 void TransportManagementWidget::Private::slotCustomContextMenuRequested( const QPoint &pos )
160 {
161  KMenu *menu = new KMenu( q );
162  menu->addAction( i18n( "Add..." ), q, SLOT(addClicked()) );
163  QTreeWidgetItem *item = ui.transportList->itemAt( pos );
164  if ( item ) {
165  menu->addAction( i18n( "Modify..." ), q, SLOT(editClicked()) );
166  menu->addAction( i18n( "Rename" ), q, SLOT(renameClicked()) );
167  menu->addAction( i18n( "Remove" ), q, SLOT(removeClicked()) );
168  if ( item->data( 0, Qt::UserRole ) != TransportManager::self()->defaultTransportId() ) {
169  menu->addSeparator();
170  menu->addAction( i18n( "Set as Default" ), q, SLOT(defaultClicked()) );
171  }
172  }
173  menu->exec( ui.transportList->viewport()->mapToGlobal( pos ) );
174  delete menu;
175 }
176 
177 #include "moc_transportmanagementwidget.cpp"
QWidget::customContextMenuRequested
void customContextMenuRequested(const QPoint &pos)
QWidget
MailTransport::TransportManager::setDefaultTransport
Q_SCRIPTABLE void setDefaultTransport(int id)
Sets the default transport.
Definition: transportmanager.cpp:381
MailTransport::TransportManager::self
static TransportManager * self()
Returns the TransportManager instance.
Definition: transportmanager.cpp:162
MailTransport::TransportManager::defaultTransportId
Q_SCRIPTABLE int defaultTransportId() const
Returns the default transport identifier.
Definition: transportmanager.cpp:376
QPoint
QTreeWidgetItem::data
virtual QVariant data(int column, int role) const
MailTransport::TransportManager::configureTransport
bool configureTransport(Transport *transport, QWidget *parent)
Open a configuration dialog for an existing transport.
Definition: transportmanager.cpp:282
MailTransport::TransportManager::showTransportCreationDialog
bool showTransportCreationDialog(QWidget *parent, ShowCondition showCondition=Always)
Shows a dialog for creating and configuring a new transport.
Definition: transportmanager.cpp:258
MailTransport::TransportManagementWidget
A widget to manage mail transports.
Definition: transportmanagementwidget.h:35
MailTransport::TransportManagementWidget::~TransportManagementWidget
virtual ~TransportManagementWidget()
Destroys the widget.
Definition: transportmanagementwidget.cpp:79
MailTransport::TransportManagementWidget::TransportManagementWidget
TransportManagementWidget(QWidget *parent=0)
Creates a new TransportManagementWidget.
Definition: transportmanagementwidget.cpp:58
QTreeWidgetItem
QString::fromLatin1
QString fromLatin1(const char *str, int size)
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject::parent
QObject * parent() const
MailTransport::Transport
Represents the settings of a specific mail transport.
Definition: transport.h:50
MailTransport::TransportManager::transportById
Transport * transportById(int id, bool def=true) const
Returns the Transport object with the given id.
Definition: transportmanager.cpp:171
MailTransport::TransportManager::removeTransport
Q_SCRIPTABLE void removeTransport(int id)
Deletes the specified transport.
Definition: transportmanager.cpp:390
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:37:49 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

mailtransport

Skip menu "mailtransport"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

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