summaryrefslogtreecommitdiffstats
path: root/renamedlgplugins/audio/audiopreview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'renamedlgplugins/audio/audiopreview.cpp')
-rw-r--r--renamedlgplugins/audio/audiopreview.cpp135
1 files changed, 135 insertions, 0 deletions
diff --git a/renamedlgplugins/audio/audiopreview.cpp b/renamedlgplugins/audio/audiopreview.cpp
new file mode 100644
index 0000000..e9c6f26
--- /dev/null
+++ b/renamedlgplugins/audio/audiopreview.cpp
@@ -0,0 +1,135 @@
+/* This file is part of the KDE project
+ Copyright (C) 2003 Fabian Wolf <fabianw@gmx.net>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public
+ License as published by the Free Software Foundation; version 2
+ of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <kfilemetainfo.h>
+#include <klocale.h>
+#include <kmimetype.h>
+#include <kurl.h>
+#include <qvbox.h>
+#include <qlabel.h>
+#include <qpixmap.h>
+#include <kio/netaccess.h>
+#include <kurllabel.h>
+#include <kmimetype.h>
+#include <kmediaplayer/player.h>
+#include <kparts/componentfactory.h>
+#include <ksqueezedtextlabel.h>
+
+#include "audiopreview.h"
+
+AudioPreview::AudioPreview( QWidget *parent, const char *name, const QString &fileName, const QString &mimeType)
+ : QVBox( parent, name )
+{
+ m_isTempFile = false;
+ pic = 0;
+ m_player = 0L;
+ description = 0;
+ // fileName is created by KUrl::prettyURL()
+ KURL url( fileName );
+ setSpacing( 0 );
+ if( url.isValid() && url.isLocalFile() ) {
+ m_localFile = url.path();
+ pic = new QLabel(this);
+ pic->setPixmap(KMimeType::pixmapForURL( url ));
+ pic->adjustSize();
+ initView( mimeType );
+ } else if( !url.isLocalFile() ) {
+ KURLLabel *label = new KURLLabel( this );
+ label->setText(i18n("This audio file isn't stored\non the local host.\nClick on this label to load it.\n" ) );
+ label->setURL( url.prettyURL() );
+ connect(label, SIGNAL(leftClickedURL(const QString&)), SLOT(downloadFile(const QString&)));
+ pic = label;
+ } else {
+ description = new QLabel(this );
+ description->setText(i18n("Unable to load audio file") );
+ }
+}
+
+AudioPreview::~AudioPreview()
+{
+ if ( m_isTempFile )
+ KIO::NetAccess::removeTempFile( m_localFile );
+
+ delete m_player;
+}
+
+void AudioPreview::initView( const QString& mimeType )
+{
+ KURL url = KURL::fromPathOrURL( m_localFile );
+ pic->setText( QString::null );
+ pic->setPixmap(KMimeType::pixmapForURL( url ));
+ pic->adjustSize();
+
+ KFileMetaInfo info(m_localFile);
+ KMimeType::Ptr mimeptr = KMimeType::mimeType(mimeType);
+
+ QString desc;
+ if (info.isValid())
+ {
+ if (mimeptr->is("audio/x-mp3") || mimeptr->is("application/ogg"))
+ {
+ // following 3 infos might be very long; make sure they get squeezed
+ // TODO: when string-freeze is over, eliminate trailing '\n' as it's no longer needed
+ KSqueezedTextLabel *sl;
+
+ sl = new KSqueezedTextLabel(this);
+ sl->setText(i18n("Artist: %1\n").arg(info.item("Artist").value().toString()));
+
+ sl = new KSqueezedTextLabel(this);
+ sl->setText(i18n("Title: %1\n").arg(info.item("Title").value().toString()));
+
+ sl = new KSqueezedTextLabel(this);
+ sl->setText(i18n("Comment: %1\n").arg(info.item("Comment").value().toString()));
+
+ desc.append(i18n("Biterate: 160 kbits/s", "Bitrate: %1 %2\n").arg( info.item("Bitrate").value().toString() ).arg( info.item("Bitrate").suffix() ));
+ }
+ desc.append(i18n("Sample rate: %1 %2\n").arg( info.item("Sample Rate").value().toString() ).arg( info.item("Sample Rate").suffix() ));
+ desc.append(i18n("Length: "));
+
+ /* Calculate length in mm:ss format */
+ int length = info.item("Length").value().toInt();
+ if (length/60 < 10)
+ desc.append("0");
+ desc.append(QString("%1:").arg(length/60, 0, 10));
+ if (length%60 < 10)
+ desc.append("0");
+ desc.append(QString("%1\n").arg(length%60, 0, 10));
+ }
+
+ description = new QLabel(this);
+ description->setText( desc );
+ description->adjustSize();
+ m_player = KParts::ComponentFactory::createInstanceFromQuery<KMediaPlayer::Player>( "KMediaPlayer/Player", QString::null, this );
+ if ( m_player )
+ {
+ static_cast<KParts::ReadOnlyPart*>(m_player)->openURL( url );
+ m_player->widget()->show();
+ }
+}
+
+void AudioPreview::downloadFile( const QString& url )
+{
+ if( KIO::NetAccess::download( KURL::fromPathOrURL( url ), m_localFile , topLevelWidget()) )
+ {
+ m_isTempFile = true;
+ initView( KMimeType::findByPath( m_localFile )->name() );
+ }
+}
+
+#include <audiopreview.moc>