00001
00002
00003
00004
00005
#ifdef HAVE_CONFIG_H
00006
#include <config.h>
00007
#endif
00008
00009
#include "kmfawidgets.h"
00010
00011
#include <kabc/addresseedialog.h>
00012
#include <kiconloader.h>
00013
#include <klocale.h>
00014
#include <kaudioplayer.h>
00015
#include <kurlrequester.h>
00016
#include <kfiledialog.h>
00017
#include <kstandarddirs.h>
00018
00019
#include <qlayout.h>
00020
00021
00022
00023
00024
00025
00026
00027 KMFilterActionWithAddressWidget::KMFilterActionWithAddressWidget(
QWidget* parent,
const char* name )
00028 :
QWidget( parent, name )
00029 {
00030
QHBoxLayout *hbl =
new QHBoxLayout(
this);
00031 hbl->setSpacing(4);
00032 mLineEdit =
new KLineEdit(
this);
00033 hbl->addWidget( mLineEdit, 1 );
00034 mBtn =
new QPushButton( QString::null ,
this );
00035 mBtn->setPixmap( BarIcon(
"contents", KIcon::SizeSmall ) );
00036 mBtn->setFixedHeight( mLineEdit->sizeHint().height() );
00037 hbl->addWidget( mBtn );
00038
00039 connect( mBtn, SIGNAL(clicked()),
00040
this, SLOT(slotAddrBook()) );
00041 }
00042
00043
void KMFilterActionWithAddressWidget::slotAddrBook()
00044 {
00045 KABC::Addressee::List lst = KABC::AddresseeDialog::getAddressees(
this );
00046
00047
if ( lst.empty() )
00048
return;
00049
00050
QStringList addrList;
00051
00052
for( KABC::Addressee::List::const_iterator it = lst.begin(); it != lst.end(); ++it )
00053 addrList << (*it).fullEmail();
00054
00055
QString txt = mLineEdit->text().stripWhiteSpace();
00056
00057
if ( !txt.isEmpty() ) {
00058
if ( !txt.endsWith(
"," ) )
00059 txt +=
", ";
00060
else
00061 txt +=
' ';
00062 }
00063
00064 mLineEdit->setText( txt + addrList.join(
",") );
00065 }
00066
00067 KMSoundTestWidget::KMSoundTestWidget(
QWidget *parent,
const char *name)
00068 :
QWidget( parent, name)
00069 {
00070
QHBoxLayout *lay1 =
new QHBoxLayout(
this );
00071 m_playButton =
new QPushButton(
this,
"m_playButton" );
00072 m_playButton->setPixmap( SmallIcon(
"1rightarrow" ) );
00073 connect( m_playButton, SIGNAL( clicked() ), SLOT( playSound() ));
00074 lay1->addWidget( m_playButton );
00075
00076 m_urlRequester =
new KURLRequester(
this );
00077 lay1->addWidget( m_urlRequester );
00078 connect( m_urlRequester, SIGNAL( openFileDialog( KURLRequester * )),
00079 SLOT( openSoundDialog( KURLRequester * )));
00080 connect( m_urlRequester->lineEdit(), SIGNAL( textChanged (
const QString & )), SLOT( slotUrlChanged(
const QString & )));
00081 slotUrlChanged(m_urlRequester->lineEdit()->text() );
00082 }
00083
00084 KMSoundTestWidget::~KMSoundTestWidget()
00085 {
00086 }
00087
00088
void KMSoundTestWidget::slotUrlChanged(
const QString &_text )
00089 {
00090 m_playButton->setEnabled( !_text.isEmpty());
00091 }
00092
00093
void KMSoundTestWidget::openSoundDialog( KURLRequester * )
00094 {
00095
static bool init =
true;
00096
if ( !init )
00097
return;
00098
00099 init =
false;
00100
00101 KFileDialog *fileDialog = m_urlRequester->fileDialog();
00102 fileDialog->setCaption( i18n(
"Select Sound File") );
00103
QStringList filters;
00104 filters <<
"audio/x-wav" <<
"audio/x-mp3" <<
"application/x-ogg"
00105 <<
"audio/x-adpcm";
00106 fileDialog->setMimeFilter( filters );
00107
00108
QStringList soundDirs = KGlobal::dirs()->resourceDirs(
"sound" );
00109
00110
if ( !soundDirs.isEmpty() ) {
00111 KURL soundURL;
00112
QDir dir;
00113 dir.setFilter( QDir::Files | QDir::Readable );
00114 QStringList::ConstIterator it = soundDirs.begin();
00115
while ( it != soundDirs.end() ) {
00116 dir = *it;
00117
if ( dir.isReadable() && dir.count() > 2 ) {
00118 soundURL.setPath( *it );
00119 fileDialog->setURL( soundURL );
00120
break;
00121 }
00122 ++it;
00123 }
00124 }
00125
00126 }
00127
00128
void KMSoundTestWidget::playSound()
00129 {
00130
QString parameter= m_urlRequester->lineEdit()->text();
00131
if ( parameter.isEmpty() )
00132
return ;
00133
QString play = parameter;
00134
QString file = QString::fromLatin1(
"file:");
00135
if (parameter.startsWith(file))
00136 play = parameter.mid(file.length());
00137 KAudioPlayer::play(QFile::encodeName(play));
00138 }
00139
00140
00141
QString KMSoundTestWidget::url()
const
00142
{
00143
return m_urlRequester->lineEdit()->text();
00144 }
00145
00146
void KMSoundTestWidget::setUrl(
const QString & url)
00147 {
00148 m_urlRequester->lineEdit()->setText(url);
00149 }
00150
00151
void KMSoundTestWidget::clear()
00152 {
00153 m_urlRequester->lineEdit()->clear();
00154 }
00155
00156
00157
#include "kmfawidgets.moc"