korganizer

publishdialog.cpp
1 /*
2  This file is part of KOrganizer.
3  Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 
19  As a special exception, permission is given to link this program
20  with any edition of TQt, and distribute the resulting executable,
21  without including the source code for TQt in the source distribution.
22 */
23 
24 #include <tqlineedit.h>
25 #include <tqpushbutton.h>
26 #include <kdebug.h>
27 #include <tqlistview.h>
28 
29 #include <tdeglobal.h>
30 #include <tdelocale.h>
31 #ifndef KORG_NOKABC
32 #include <tdeabc/addresseedialog.h>
33 #endif
34 #include <libkcal/attendee.h>
35 
36 #include "koprefs.h"
37 #include "publishdialog.h"
38 #include "publishdialog_base.h"
39 
40 PublishDialog::PublishDialog( TQWidget* parent, const char* name,
41  bool modal )
42  : KDialogBase( parent, name, modal,
43  i18n("Select Addresses"), Ok|Cancel|Help, Ok, true )
44 {
45  mWidget = new PublishDialog_base( this, "PublishFreeBusy" );
46  setMainWidget( mWidget );
47  mWidget->mNameLineEdit->setEnabled( false );
48  mWidget->mEmailLineEdit->setEnabled( false );
49  connect( mWidget->mAddressListView, TQ_SIGNAL( selectionChanged(TQListViewItem *) ),
50  TQ_SLOT(updateInput()));
51  connect( mWidget->mNew, TQ_SIGNAL( clicked() ),
52  TQ_SLOT( addItem() ) );
53  connect( mWidget->mRemove, TQ_SIGNAL( clicked() ),
54  TQ_SLOT( removeItem() ) );
55  connect( mWidget->mSelectAddressee, TQ_SIGNAL( clicked() ),
56  TQ_SLOT( openAddressbook() ) );
57  connect( mWidget->mNameLineEdit, TQ_SIGNAL( textChanged(const TQString&) ),
58  TQ_SLOT( updateItem() ) );
59  connect( mWidget->mEmailLineEdit, TQ_SIGNAL( textChanged(const TQString&) ),
60  TQ_SLOT( updateItem() ) );
61 }
62 
63 PublishDialog::~PublishDialog()
64 {
65 }
66 
67 void PublishDialog::addAttendee( Attendee *attendee )
68 {
69  mWidget->mNameLineEdit->setEnabled( true );
70  mWidget->mEmailLineEdit->setEnabled( true );
71  TQListViewItem *item = new TQListViewItem( mWidget->mAddressListView );
72  item->setText( 0, attendee->name() );
73  item->setText( 1, attendee->email() );
74  mWidget->mAddressListView->insertItem( item );
75 }
76 
77 TQString PublishDialog::addresses()
78 {
79  TQString to = "";
80  TQListViewItem *item;
81  int i, count;
82  count = mWidget->mAddressListView->childCount();
83  for ( i=0; i<count; i++ ) {
84  item = mWidget->mAddressListView->firstChild();
85  mWidget->mAddressListView->takeItem( item );
86  to += item->text( 1 );
87  if ( i < count-1 ) {
88  to += ", ";
89  }
90  }
91  return to;
92 }
93 
94 void PublishDialog::addItem()
95 {
96  mWidget->mNameLineEdit->setEnabled( true );
97  mWidget->mEmailLineEdit->setEnabled( true );
98  TQListViewItem *item = new TQListViewItem( mWidget->mAddressListView );
99  mWidget->mAddressListView->insertItem( item );
100  mWidget->mAddressListView->setSelected( item, true );
101  mWidget->mNameLineEdit->setText( i18n("(EmptyName)") );
102  mWidget->mEmailLineEdit->setText( i18n("(EmptyEmail)") );
103 }
104 
105 void PublishDialog::removeItem()
106 {
107  TQListViewItem *item;
108  item = mWidget->mAddressListView->selectedItem();
109  if (!item) return;
110  mWidget->mAddressListView->takeItem( item );
111  item = mWidget->mAddressListView->selectedItem();
112  if ( !item ) {
113  mWidget->mNameLineEdit->setText( "" );
114  mWidget->mEmailLineEdit->setText( "" );
115  mWidget->mNameLineEdit->setEnabled( false );
116  mWidget->mEmailLineEdit->setEnabled( false );
117  }
118  if ( mWidget->mAddressListView->childCount() == 0 ) {
119  mWidget->mNameLineEdit->setEnabled( false );
120  mWidget->mEmailLineEdit->setEnabled( false );
121  }
122 }
123 
124 void PublishDialog::openAddressbook()
125 {
126 #ifndef KORG_NOKABC
127  TDEABC::Addressee::List addressList;
128  addressList = TDEABC::AddresseeDialog::getAddressees( this );
129  //TDEABC::Addressee a = TDEABC::AddresseeDialog::getAddressee(this);
130  TDEABC::Addressee a = addressList.first();
131  if ( !a.isEmpty() ) {
132  uint i;
133  for ( i=0; i<addressList.size(); i++ ) {
134  a = addressList[i];
135  mWidget->mNameLineEdit->setEnabled( true );
136  mWidget->mEmailLineEdit->setEnabled( true );
137  TQListViewItem *item = new TQListViewItem( mWidget->mAddressListView );
138  mWidget->mAddressListView->setSelected( item, true );
139  mWidget->mNameLineEdit->setText( a.realName() );
140  mWidget->mEmailLineEdit->setText( a.preferredEmail() );
141  mWidget->mAddressListView->insertItem( item );
142  }
143  }
144 #endif
145 }
146 
147 void PublishDialog::updateItem()
148 {
149  TQListViewItem *item;
150  item = mWidget->mAddressListView->selectedItem();
151  if (!item) return;
152  item->setText( 0, mWidget->mNameLineEdit->text() );
153  item->setText( 1, mWidget->mEmailLineEdit->text() );
154 }
155 
156 void PublishDialog::updateInput()
157 {
158  TQListViewItem *item;
159  item = mWidget->mAddressListView->selectedItem();
160  if (!item) return;
161  mWidget->mNameLineEdit->setEnabled( true );
162  mWidget->mEmailLineEdit->setEnabled( true );
163  mWidget->mNameLineEdit->setText( item->text( 0 ) );
164  mWidget->mEmailLineEdit->setText( item->text( 1 ) );
165 }
166 
167 #include "publishdialog.moc"