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

korganizer

  • sources
  • kde-4.12
  • kdepim
  • korganizer
publishdialog.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KOrganizer.
3  Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4  Copyright (c) 2009 Allen Winter <winter@kde.org>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License along
17  with this program; if not, write to the Free Software Foundation, Inc.,
18  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of Qt, and distribute the resulting executable,
22  without including the source code for Qt in the source distribution.
23 */
24 
25 // TODO: validate hand-entered email addresses
26 // TODO: don't allow duplicates; at least remove dupes when passing back
27 // TODO: the list in PublishDialog::addresses()
28 
29 #include "publishdialog.h"
30 
31 #include <Akonadi/Contact/EmailAddressSelectionDialog>
32 
33 #include <KCalCore/Attendee>
34 #include <KCalCore/Person>
35 
36 #include <KPIMUtils/Email>
37 
38 PublishDialog::PublishDialog( QWidget *parent )
39  : KDialog( parent )
40 {
41  setCaption( i18n( "Select Addresses" ) );
42  setButtons( Ok|Cancel|Help );
43  setHelp( QLatin1String("group-scheduling"), QLatin1String("korganizer") );
44  QWidget *widget = new QWidget( this );
45  widget->setObjectName( QLatin1String("PublishFreeBusy") );
46  mUI.setupUi( widget );
47  setMainWidget( widget );
48  mUI.mListWidget->setSelectionMode( QAbstractItemView::SingleSelection );
49  mUI.mNameLineEdit->setEnabled( false );
50  mUI.mEmailLineEdit->setEnabled( false );
51 
52  setButtonToolTip( Ok, i18n( "Send email to these recipients" ) );
53  setButtonWhatsThis( Ok, i18n( "Clicking the <b>Ok</b> button will cause "
54  "an email to be sent to the recipients you "
55  "have entered." ) );
56  setButtonToolTip( Cancel, i18n( "Cancel recipient selection and the email" ) );
57  setButtonWhatsThis( Cancel, i18n( "Clicking the <b>Cancel</b> button will "
58  "cause the email operation to be terminated." ) );
59 
60  setButtonWhatsThis( Help, i18n( "Click the <b>Help</b> button to read "
61  "more information about Group Scheduling." ) );
62 
63  mUI.mAdd->setIcon( KIcon( QLatin1String("list-add") ) );
64  mUI.mRemove->setIcon( KIcon( QLatin1String("list-remove") ) );
65  mUI.mRemove->setEnabled( false );
66  mUI.mSelectAddressee->setIcon( KIcon( QLatin1String("view-pim-contacts") ) );
67 
68  connect( mUI.mListWidget, SIGNAL(itemSelectionChanged()),
69  SLOT(updateInput()) );
70  connect( mUI.mAdd, SIGNAL(clicked()),
71  SLOT(addItem()) );
72  connect( mUI.mRemove, SIGNAL(clicked()),
73  SLOT(removeItem()) );
74  connect( mUI.mSelectAddressee, SIGNAL(clicked()),
75  SLOT(openAddressbook()) );
76  connect( mUI.mNameLineEdit, SIGNAL(textChanged(QString)),
77  SLOT(updateItem()) );
78  connect( mUI.mEmailLineEdit, SIGNAL(textChanged(QString)),
79  SLOT(updateItem()) );
80 }
81 
82 PublishDialog::~PublishDialog()
83 {
84 }
85 
86 void PublishDialog::addAttendee( const KCalCore::Attendee::Ptr &attendee )
87 {
88  mUI.mNameLineEdit->setEnabled( true );
89  mUI.mEmailLineEdit->setEnabled( true );
90  QListWidgetItem *item = new QListWidgetItem( mUI.mListWidget );
91  KCalCore::Person person( attendee->name(), attendee->email() );
92  item->setText( person.fullName() );
93  mUI.mListWidget->addItem( item );
94  mUI.mRemove->setEnabled( !mUI.mListWidget->selectedItems().isEmpty() );
95 }
96 
97 QString PublishDialog::addresses()
98 {
99  QString to;
100  const int count = mUI.mListWidget->count();
101  for ( int i=0; i<count; ++i ) {
102  const QListWidgetItem *item = mUI.mListWidget->item( i );
103  if( !item->text().isEmpty() ) {
104  to += item->text();
105  if ( i < count-1 ) {
106  to += QLatin1String(", ");
107  }
108  }
109  }
110  return to;
111 }
112 
113 void PublishDialog::addItem()
114 {
115  mUI.mNameLineEdit->setEnabled( true );
116  mUI.mEmailLineEdit->setEnabled( true );
117  QListWidgetItem *item = new QListWidgetItem( mUI.mListWidget );
118  mUI.mListWidget->addItem( item );
119  mUI.mListWidget->setItemSelected( item, true );
120  mUI.mNameLineEdit->setText( i18n( "(EmptyName)" ) );
121  mUI.mEmailLineEdit->setText( i18n( "(EmptyEmail)" ) );
122 
123  mUI.mRemove->setEnabled( true );
124 }
125 
126 void PublishDialog::removeItem()
127 {
128  if ( mUI.mListWidget->selectedItems().isEmpty() ) {
129  return;
130  }
131  QListWidgetItem *item;
132  item = mUI.mListWidget->selectedItems().first();
133 
134  int row = mUI.mListWidget->row( item );
135  delete mUI.mListWidget->takeItem( row );
136 
137  if ( !mUI.mListWidget->count() ) {
138  mUI.mNameLineEdit->setText( QString() );
139  mUI.mNameLineEdit->setEnabled( false );
140  mUI.mEmailLineEdit->setText( QString() );
141  mUI.mEmailLineEdit->setEnabled( false );
142  mUI.mRemove->setEnabled( false );
143  return;
144  }
145  if ( row > 0 ) {
146  row--;
147  }
148 
149  mUI.mListWidget->setCurrentRow( row );
150 }
151 
152 void PublishDialog::openAddressbook()
153 {
154  Akonadi::EmailAddressSelectionDialog dlg( this );
155  if ( !dlg.exec() ) {
156  return;
157  }
158 
159  const Akonadi::EmailAddressSelection::List selections = dlg.selectedAddresses();
160  if ( !selections.isEmpty() ) {
161  foreach ( const Akonadi::EmailAddressSelection &selection, selections ) {
162  mUI.mNameLineEdit->setEnabled( true );
163  mUI.mEmailLineEdit->setEnabled( true );
164  QListWidgetItem *item = new QListWidgetItem( mUI.mListWidget );
165  mUI.mListWidget->setItemSelected( item, true );
166  mUI.mNameLineEdit->setText( selection.name() );
167  mUI.mEmailLineEdit->setText( selection.email() );
168  mUI.mListWidget->addItem( item );
169  }
170 
171  mUI.mRemove->setEnabled( true );
172  }
173 }
174 
175 void PublishDialog::updateItem()
176 {
177  if ( !mUI.mListWidget->selectedItems().count() ) {
178  return;
179  }
180 
181  KCalCore::Person person( mUI.mNameLineEdit->text(), mUI.mEmailLineEdit->text() );
182  QListWidgetItem *item = mUI.mListWidget->selectedItems().first();
183  item->setText( person.fullName() );
184 }
185 
186 void PublishDialog::updateInput()
187 {
188  if ( !mUI.mListWidget->selectedItems().count() ) {
189  return;
190  }
191 
192  mUI.mNameLineEdit->setEnabled( true );
193  mUI.mEmailLineEdit->setEnabled( true );
194 
195  QListWidgetItem *item = mUI.mListWidget->selectedItems().first();
196  QString mail, name;
197  KPIMUtils::extractEmailAddressAndName( item->text(), mail, name );
198  mUI.mNameLineEdit->setText( name );
199  mUI.mEmailLineEdit->setText( mail );
200 }
201 
202 #include "publishdialog.moc"
PublishDialog::updateInput
void updateInput()
Definition: publishdialog.cpp:186
QWidget
PublishDialog::openAddressbook
void openAddressbook()
Definition: publishdialog.cpp:152
KDialog
PublishDialog::removeItem
void removeItem()
Definition: publishdialog.cpp:126
PublishDialog::mUI
Ui::PublishDialog_base mUI
Definition: publishdialog.h:56
PublishDialog::updateItem
void updateItem()
Definition: publishdialog.cpp:175
PublishDialog::addAttendee
void addAttendee(const KCalCore::Attendee::Ptr &attendee)
Definition: publishdialog.cpp:86
PublishDialog::addresses
QString addresses()
Definition: publishdialog.cpp:97
PublishDialog::addItem
void addItem()
Definition: publishdialog.cpp:113
publishdialog.h
PublishDialog::PublishDialog
PublishDialog(QWidget *parent=0)
Definition: publishdialog.cpp:38
PublishDialog::~PublishDialog
~PublishDialog()
Definition: publishdialog.cpp:82
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

korganizer

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

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

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