kmail

kmfawidgets.cpp
1 // kmfawidgets.h - KMFilterAction parameter widgets
2 // Copyright: (c) 2001 Marc Mutz <mutz@kde.org>
3 // License: GNU Genaral Public License
4 
5 #ifdef HAVE_CONFIG_H
6 #include <config.h>
7 #endif
8 
9 #include "kmfawidgets.h"
10 
11 #include <tdeabc/addresseedialog.h> // for the button in KMFilterActionWithAddress
12 #include <kiconloader.h>
13 #include <tdelocale.h>
14 #include <kaudioplayer.h>
15 #include <kurlrequester.h>
16 #include <tdefiledialog.h>
17 #include <kstandarddirs.h>
18 
19 #include <tqlayout.h>
20 #include <tqtooltip.h>
21 
22 //=============================================================================
23 //
24 // class KMFilterActionWithAddressWidget
25 //
26 //=============================================================================
27 
28 KMFilterActionWithAddressWidget::KMFilterActionWithAddressWidget( TQWidget* parent, const char* name )
29  : TQWidget( parent, name )
30 {
31  TQHBoxLayout *hbl = new TQHBoxLayout(this);
32  hbl->setSpacing(4);
33  mLineEdit = new KLineEdit(this);
34  mLineEdit->setName( "addressEdit" );
35  hbl->addWidget( mLineEdit, 1 /*stretch*/ );
36  mBtn = new TQPushButton( TQString() ,this );
37  mBtn->setPixmap( BarIcon( "contents", TDEIcon::SizeSmall ) );
38  mBtn->setFixedHeight( mLineEdit->sizeHint().height() );
39  TQToolTip::add( mBtn, i18n( "Open Address Book" ) );
40  hbl->addWidget( mBtn );
41 
42  connect( mBtn, TQ_SIGNAL(clicked()),
43  this, TQ_SLOT(slotAddrBook()) );
44  connect( mLineEdit, TQ_SIGNAL( textChanged(const TQString&) ),
45  this, TQ_SIGNAL( textChanged(const TQString&) ) );
46 }
47 
48 void KMFilterActionWithAddressWidget::slotAddrBook()
49 {
50  TDEABC::Addressee::List lst = TDEABC::AddresseeDialog::getAddressees( this );
51 
52  if ( lst.empty() )
53  return;
54 
55  TQStringList addrList;
56 
57  for( TDEABC::Addressee::List::const_iterator it = lst.begin(); it != lst.end(); ++it )
58  addrList << (*it).fullEmail();
59 
60  TQString txt = mLineEdit->text().stripWhiteSpace();
61 
62  if ( !txt.isEmpty() ) {
63  if ( !txt.endsWith( "," ) )
64  txt += ", ";
65  else
66  txt += ' ';
67  }
68 
69  mLineEdit->setText( txt + addrList.join(",") );
70 }
71 
72 KMSoundTestWidget::KMSoundTestWidget(TQWidget *parent, const char *name)
73  : TQWidget( parent, name)
74 {
75  TQHBoxLayout *lay1 = new TQHBoxLayout( this );
76  m_playButton = new TQPushButton( this, "m_playButton" );
77  m_playButton->setPixmap( SmallIcon( "1rightarrow" ) );
78  connect( m_playButton, TQ_SIGNAL( clicked() ), TQ_SLOT( playSound() ));
79  lay1->addWidget( m_playButton );
80 
81  m_urlRequester = new KURLRequester( this );
82  lay1->addWidget( m_urlRequester );
83  connect( m_urlRequester, TQ_SIGNAL( openFileDialog( KURLRequester * )),
84  TQ_SLOT( openSoundDialog( KURLRequester * )));
85  connect( m_urlRequester->lineEdit(), TQ_SIGNAL( textChanged ( const TQString & )), TQ_SLOT( slotUrlChanged(const TQString & )));
86  slotUrlChanged(m_urlRequester->lineEdit()->text() );
87 }
88 
89 KMSoundTestWidget::~KMSoundTestWidget()
90 {
91 }
92 
93 void KMSoundTestWidget::slotUrlChanged(const TQString &_text )
94 {
95  m_playButton->setEnabled( !_text.isEmpty());
96 }
97 
98 void KMSoundTestWidget::openSoundDialog( KURLRequester * )
99 {
100  static bool init = true;
101  if ( !init )
102  return;
103 
104  init = false;
105 
106  KFileDialog *fileDialog = m_urlRequester->fileDialog();
107  fileDialog->setCaption( i18n("Select Sound File") );
108  TQStringList filters;
109  filters << "audio/x-wav" << "audio/x-mp3" << "application/x-ogg"
110  << "audio/x-adpcm";
111  fileDialog->setMimeFilter( filters );
112 
113  TQStringList soundDirs = TDEGlobal::dirs()->resourceDirs( "sound" );
114 
115  if ( !soundDirs.isEmpty() ) {
116  KURL soundURL;
117  TQDir dir;
118  dir.setFilter( TQDir::Files | TQDir::Readable );
119  TQStringList::ConstIterator it = soundDirs.begin();
120  while ( it != soundDirs.end() ) {
121  dir = *it;
122  if ( dir.isReadable() && dir.count() > 2 ) {
123  soundURL.setPath( *it );
124  fileDialog->setURL( soundURL );
125  break;
126  }
127  ++it;
128  }
129  }
130 
131 }
132 
133 void KMSoundTestWidget::playSound()
134 {
135  TQString parameter= m_urlRequester->lineEdit()->text();
136  if ( parameter.isEmpty() )
137  return ;
138  TQString play = parameter;
139  TQString file = TQString::fromLatin1("file:");
140  if (parameter.startsWith(file))
141  play = parameter.mid(file.length());
142  KAudioPlayer::play(TQFile::encodeName(play));
143 }
144 
145 
146 TQString KMSoundTestWidget::url() const
147 {
148  return m_urlRequester->lineEdit()->text();
149 }
150 
151 void KMSoundTestWidget::setUrl(const TQString & url)
152 {
153  m_urlRequester->lineEdit()->setText(url);
154 }
155 
156 void KMSoundTestWidget::clear()
157 {
158  m_urlRequester->lineEdit()->clear();
159 }
160 
161 //--------------------------------------------
162 #include "kmfawidgets.moc"