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

mailtransport

  • 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 
31 using namespace MailTransport;
32 
33 class TransportManagementWidget::Private
34 {
35  public:
36 
37  Private( TransportManagementWidget *parent );
38 
39  Ui::TransportManagementWidget ui;
40  TransportManagementWidget *q;
41 
42  // Slots
43  void defaultClicked();
44  void removeClicked();
45  void renameClicked();
46  void editClicked();
47  void addClicked();
48  void updateButtonState();
49  void slotCustomContextMenuRequested( const QPoint & );
50 };
51 
52 TransportManagementWidget::Private::Private( TransportManagementWidget *parent )
53  : q( parent )
54 {
55 }
56 
57 TransportManagementWidget::TransportManagementWidget( QWidget *parent )
58  : QWidget( parent ), d( new Private( this ) )
59 {
60  KGlobal::locale()->insertCatalog( QString::fromLatin1( "libmailtransport" ) );
61  d->ui.setupUi( this );
62  d->updateButtonState();
63 
64  d->ui.transportList->setContextMenuPolicy( Qt::CustomContextMenu );
65  connect( d->ui.transportList, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
66  SLOT(updateButtonState()) );
67  connect( d->ui.transportList, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),
68  SLOT(editClicked()) );
69  connect( d->ui.addButton, SIGNAL(clicked()), SLOT(addClicked()) );
70  connect( d->ui.editButton, SIGNAL(clicked()), SLOT(editClicked()) );
71  connect( d->ui.renameButton, SIGNAL(clicked()), SLOT(renameClicked()) );
72  connect( d->ui.removeButton, SIGNAL(clicked()), SLOT(removeClicked()) );
73  connect( d->ui.defaultButton, SIGNAL(clicked()), SLOT(defaultClicked()) );
74  connect( d->ui.transportList, SIGNAL(customContextMenuRequested(QPoint)),
75  SLOT(slotCustomContextMenuRequested(QPoint)) );
76 }
77 
78 TransportManagementWidget::~TransportManagementWidget()
79 {
80  delete d;
81 }
82 
83 void TransportManagementWidget::Private::updateButtonState()
84 {
85  // TODO figure out current item vs. selected item (in almost every function)
86  if ( !ui.transportList->currentItem() ) {
87  ui.editButton->setEnabled( false );
88  ui.renameButton->setEnabled( false );
89  ui.removeButton->setEnabled( false );
90  ui.defaultButton->setEnabled( false );
91  } else {
92  ui.editButton->setEnabled( true );
93  ui.renameButton->setEnabled( true );
94  ui.removeButton->setEnabled( true );
95  if ( ui.transportList->currentItem()->data( 0, Qt::UserRole ) ==
96  TransportManager::self()->defaultTransportId() ) {
97  ui.defaultButton->setEnabled( false );
98  } else {
99  ui.defaultButton->setEnabled( true );
100  }
101  }
102 }
103 
104 void TransportManagementWidget::Private::addClicked()
105 {
106  TransportManager::self()->showTransportCreationDialog( q );
107 }
108 
109 void TransportManagementWidget::Private::editClicked()
110 {
111  if ( !ui.transportList->currentItem() ) {
112  return;
113  }
114 
115  const int currentId = ui.transportList->currentItem()->data( 0, Qt::UserRole ).toInt();
116  Transport *transport = TransportManager::self()->transportById( currentId );
117  TransportManager::self()->configureTransport( transport, q );
118 }
119 
120 void TransportManagementWidget::Private::renameClicked()
121 {
122  if ( !ui.transportList->currentItem() ) {
123  return;
124  }
125 
126  ui.transportList->editItem( ui.transportList->currentItem(), 0 );
127 }
128 
129 void TransportManagementWidget::Private::removeClicked()
130 {
131  if ( !ui.transportList->currentItem() ) {
132  return;
133  }
134  const int rc =
135  KMessageBox::questionYesNo(
136  q,
137  i18n( "Do you want to remove outgoing account '%1'?",
138  ui.transportList->currentItem()->text( 0 ) ),
139  i18n( "Remove outgoing account?" ) );
140  if ( rc == KMessageBox::No ) {
141  return;
142  }
143 
144  TransportManager::self()->removeTransport(
145  ui.transportList->currentItem()->data( 0, Qt::UserRole ).toInt() );
146 }
147 
148 void TransportManagementWidget::Private::defaultClicked()
149 {
150  if ( !ui.transportList->currentItem() ) {
151  return;
152  }
153 
154  TransportManager::self()->setDefaultTransport(
155  ui.transportList->currentItem()->data( 0, Qt::UserRole ).toInt() );
156 }
157 
158 void TransportManagementWidget::Private::slotCustomContextMenuRequested( const QPoint &pos )
159 {
160  KMenu *menu = new KMenu( q );
161  menu->addAction( i18n( "Add..." ), q, SLOT(addClicked()) );
162  QTreeWidgetItem *item = ui.transportList->itemAt( pos );
163  if ( item ) {
164  menu->addAction( i18n( "Edit..." ), q, SLOT(editClicked()) );
165  menu->addAction( i18n( "Rename" ), q, SLOT(renameClicked()) );
166  menu->addAction( i18n( "Remove" ), q, SLOT(removeClicked()) );
167  if ( item->data( 0, Qt::UserRole ) != TransportManager::self()->defaultTransportId() ) {
168  menu->addSeparator();
169  menu->addAction( i18n( "Set as Default" ), q, SLOT(defaultClicked()) );
170  }
171  }
172  menu->exec( ui.transportList->viewport()->mapToGlobal( pos ) );
173  delete menu;
174 }
175 
176 #include "moc_transportmanagementwidget.cpp"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:26:53 by doxygen 1.8.3.1 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-4.10.5 API Reference

Skip menu "kdepimlibs-4.10.5 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
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