mailtransport
transportlistview.cpp
00001 /* 00002 Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com> 00003 00004 Based on KMail code by: 00005 Copyright (c) 2002 Marc Mutz <mutz@kde.org> 00006 2007 Mathias Soeken <msoeken@tzi.de> 00007 00008 This library is free software; you can redistribute it and/or modify it 00009 under the terms of the GNU Library General Public License as published by 00010 the Free Software Foundation; either version 2 of the License, or (at your 00011 option) any later version. 00012 00013 This library is distributed in the hope that it will be useful, but WITHOUT 00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00015 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00016 License for more details. 00017 00018 You should have received a copy of the GNU Library General Public License 00019 along with this library; see the file COPYING.LIB. If not, write to the 00020 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00021 02110-1301, USA. 00022 */ 00023 00024 #include "transportlistview.h" 00025 #include "transport.h" 00026 #include "transportmanager.h" 00027 #include "transporttype.h" 00028 00029 #include <QHeaderView> 00030 #include <QLineEdit> 00031 00032 #include <KDebug> 00033 #include <KLocalizedString> 00034 00035 using namespace MailTransport; 00036 00037 TransportListView::TransportListView( QWidget *parent ) 00038 : QTreeWidget( parent ) 00039 { 00040 setHeaderLabels( QStringList() 00041 << i18nc( "@title:column email transport name", "Name" ) 00042 << i18nc( "@title:column email transport type", "Type" ) ); 00043 setRootIsDecorated( false ); 00044 header()->setMovable( false ); 00045 setAllColumnsShowFocus( true ); 00046 setAlternatingRowColors( true ); 00047 setSortingEnabled( true ); 00048 sortByColumn( 0, Qt::AscendingOrder ); 00049 setSelectionMode( SingleSelection ); 00050 00051 fillTransportList(); 00052 connect( TransportManager::self(), SIGNAL(transportsChanged()), 00053 this, SLOT(fillTransportList()) ); 00054 } 00055 00056 void TransportListView::editItem( QTreeWidgetItem *item, int column ) 00057 { 00058 // TODO: is there a nicer way to make only the 'name' column editable? 00059 if ( column == 0 && item ) { 00060 Qt::ItemFlags oldFlags = item->flags(); 00061 item->setFlags( oldFlags | Qt::ItemIsEditable ); 00062 QTreeWidget::editItem( item, 0 ); 00063 item->setFlags( oldFlags ); 00064 } 00065 } 00066 00067 void TransportListView::commitData( QWidget *editor ) 00068 { 00069 if( selectedItems().size() < 1 ) { 00070 // transport was deleted by someone else??? 00071 kDebug() << "No selected item."; 00072 return; 00073 } 00074 QTreeWidgetItem *item = selectedItems()[0]; 00075 QLineEdit *edit = dynamic_cast<QLineEdit*>( editor ); // krazy:exclude=qclasses 00076 Q_ASSERT( edit ); // original code had if 00077 00078 int id = item->data( 0, Qt::UserRole ).toInt(); 00079 Transport *t = TransportManager::self()->transportById( id ); 00080 if( !t ) { 00081 kWarning() << "Transport" << id << "not known by manager."; 00082 return; 00083 } 00084 kDebug() << "Renaming transport" << id << "to" << edit->text(); 00085 t->setName( edit->text() ); 00086 t->forceUniqueName(); 00087 t->writeConfig(); 00088 } 00089 00090 void TransportListView::fillTransportList() 00091 { 00092 // try to preserve the selection 00093 int selected = -1; 00094 if ( currentItem() ) { 00095 selected = currentItem()->data( 0, Qt::UserRole ).toInt(); 00096 } 00097 00098 clear(); 00099 foreach ( Transport *t, TransportManager::self()->transports() ) { 00100 QTreeWidgetItem *item = new QTreeWidgetItem( this ); 00101 item->setData( 0, Qt::UserRole, t->id() ); 00102 item->setText( 0, t->name() ); 00103 QString type = t->transportType().name(); 00104 if ( TransportManager::self()->defaultTransportId() == t->id() ) { 00105 type += i18nc( "@label the default mail transport", " (Default)" ); 00106 } 00107 item->setText( 1, type ); 00108 if ( t->id() == selected ) { 00109 setCurrentItem( item ); 00110 } 00111 } 00112 } 00113 00114 #include "transportlistview.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu Aug 2 2012 15:25:02 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu Aug 2 2012 15:25:02 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.