• 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
transportlistview.cpp
1 /*
2  Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
3 
4  Based on KMail code by:
5  Copyright (c) 2002 Marc Mutz <mutz@kde.org>
6  Copyright (c) 2007 Mathias Soeken <msoeken@tzi.de>
7 
8  This library is free software; you can redistribute it and/or modify it
9  under the terms of the GNU Library General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or (at your
11  option) any later version.
12 
13  This library is distributed in the hope that it will be useful, but WITHOUT
14  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
16  License for more details.
17 
18  You should have received a copy of the GNU Library General Public License
19  along with this library; see the file COPYING.LIB. If not, write to the
20  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 */
23 
24 #include "transportlistview.h"
25 #include "transport.h"
26 #include "transportmanager.h"
27 #include "transporttype.h"
28 
29 #include <QHeaderView>
30 #include <QLineEdit>
31 
32 #include <KDebug>
33 #include <KLocalizedString>
34 
35 using namespace MailTransport;
36 
37 TransportListView::TransportListView( QWidget *parent )
38  : QTreeWidget( parent )
39 {
40  setHeaderLabels( QStringList()
41  << i18nc( "@title:column email transport name", "Name" )
42  << i18nc( "@title:column email transport type", "Type" ) );
43  setRootIsDecorated( false );
44  header()->setMovable( false );
45  header()->setResizeMode( QHeaderView::ResizeToContents );
46  setAllColumnsShowFocus( true );
47  setAlternatingRowColors( true );
48  setSortingEnabled( true );
49  sortByColumn( 0, Qt::AscendingOrder );
50  setSelectionMode( SingleSelection );
51 
52  fillTransportList();
53  connect( TransportManager::self(), SIGNAL(transportsChanged()),
54  this, SLOT(fillTransportList()) );
55 }
56 
57 void TransportListView::editItem( QTreeWidgetItem *item, int column )
58 {
59  // TODO: is there a nicer way to make only the 'name' column editable?
60  if ( column == 0 && item ) {
61  Qt::ItemFlags oldFlags = item->flags();
62  item->setFlags( oldFlags | Qt::ItemIsEditable );
63  QTreeWidget::editItem( item, 0 );
64  item->setFlags( oldFlags );
65  const int id = item->data( 0, Qt::UserRole ).toInt();
66  Transport *t = TransportManager::self()->transportById( id );
67  if ( !t ) {
68  kWarning() << "Transport" << id << "not known by manager.";
69  return;
70  }
71  if ( TransportManager::self()->defaultTransportId() == t->id() ) {
72  item->setText( 0, t->name() );
73  }
74  }
75 }
76 
77 void TransportListView::commitData( QWidget *editor )
78 {
79  if ( selectedItems().isEmpty() ) {
80  // transport was deleted by someone else???
81  kDebug() << "No selected item.";
82  return;
83  }
84  QTreeWidgetItem *item = selectedItems().first();
85  QLineEdit *edit = dynamic_cast<QLineEdit*>( editor ); // krazy:exclude=qclasses
86  Q_ASSERT( edit ); // original code had if
87 
88  const int id = item->data( 0, Qt::UserRole ).toInt();
89  Transport *t = TransportManager::self()->transportById( id );
90  if ( !t ) {
91  kWarning() << "Transport" << id << "not known by manager.";
92  return;
93  }
94  kDebug() << "Renaming transport" << id << "to" << edit->text();
95  t->setName( edit->text() );
96  t->forceUniqueName();
97  t->writeConfig();
98 }
99 
100 void TransportListView::fillTransportList()
101 {
102  // try to preserve the selection
103  int selected = -1;
104  if ( currentItem() ) {
105  selected = currentItem()->data( 0, Qt::UserRole ).toInt();
106  }
107 
108  clear();
109  foreach ( Transport *t, TransportManager::self()->transports() ) {
110  QTreeWidgetItem *item = new QTreeWidgetItem( this );
111  item->setData( 0, Qt::UserRole, t->id() );
112  QString name = t->name();
113  if ( TransportManager::self()->defaultTransportId() == t->id() ) {
114  name += i18nc( "@label the default mail transport", " (Default)" );
115  QFont font( item->font(0) );
116  font.setBold( true );
117  item->setFont( 0, font );
118  }
119  item->setText( 0, name );
120  item->setText( 1, t->transportType().name() );
121  if ( t->id() == selected ) {
122  setCurrentItem( item );
123  }
124  }
125 }
MailTransport::TransportType::name
QString name() const
Returns the i18n'ed name of the transport type.
Definition: transporttype.cpp:76
QWidget
QLineEdit::text
text
QTreeWidgetItem::setFont
void setFont(int column, const QFont &font)
MailTransport::TransportManager::self
static TransportManager * self()
Returns the TransportManager instance.
Definition: transportmanager.cpp:162
QFont
QTreeWidgetItem::setData
virtual void setData(int column, int role, const QVariant &value)
QTreeWidgetItem::data
virtual QVariant data(int column, int role) const
QTreeWidget::clear
void clear()
QFont::setBold
void setBold(bool enable)
QTreeWidgetItem::setFlags
void setFlags(QFlags< Qt::ItemFlag > flags)
QTreeWidget
QObject::name
const char * name() const
QVariant::toInt
int toInt(bool *ok) const
QTreeWidgetItem::font
QFont font(int column) const
QTreeWidget::currentItem
QTreeWidgetItem * currentItem() const
QString
QStringList
QWidget::font
const QFont & font() const
QTreeWidget::selectedItems
QList< QTreeWidgetItem * > selectedItems() const
QTreeWidget::setCurrentItem
void setCurrentItem(QTreeWidgetItem *item)
QTreeWidgetItem::flags
Qt::ItemFlags flags() const
QTreeWidgetItem
MailTransport::Transport::forceUniqueName
void forceUniqueName()
Makes sure the transport has a unique name.
Definition: transport.cpp:83
QTreeWidgetItem::setText
void setText(int column, const QString &text)
QAbstractItemView::edit
void edit(const QModelIndex &index)
QLineEdit
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
QTreeWidget::editItem
void editItem(QTreeWidgetItem *item, int column)
MailTransport::Transport::transportType
TransportType transportType() const
Returns the type of this transport.
Definition: transport.cpp:342
Qt::ItemFlags
typedef ItemFlags
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