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