Add Supported Types functionality to Generic MediaDevices.
Roel Meeuws
r.j.meeuws at gmail.com
Mon Jun 26 16:56:11 UTC 2006
Hi you guys,
Here is an updated genericmediadevice patch it has the supported filetypes
patch AND a patch adding the possibility to specify tree structure of the
files on the device in a somewhat more sophisticated way then the standard
three sorting levels. It is now a bit more comparable to Amarok's organize
collection dialog. Furthermore, I removed the transfer dialog, because it
makes less sense now. Tell me what you think, please!
greetz,
Roel
2006/6/24, Roel Meeuws <r.j.meeuws at gmail.com>:
>
> And now without the changes to amarok.kdevelop
>
>
> 2006/6/24, Roel Meeuws <r.j.meeuws at gmail.com>:
> >
> > Ouch.... attaching the patch would be nice...
> >
> > gr,
> >
> > roel
> >
> > 2006/6/24, Roel Meeuws < r.j.meeuws at gmail.com>:
> >
> > > Okay. I converted the GUI code to use an .ui file. And I reordered the
> > > layouts a little better. Let me know what you think.
> > >
> > > btw, how could I get this committed? First a review process or
> > > something?
> > >
> > > 2006/6/23, Ian Monroe <ian at monroe.nu>:
> > >
> > > > Just construct the class created by UIC and pass the QWidget* parent
> > > >
> > > > as the parent.
> > > >
> > > > You'll also want to set the border of the .ui's dialog to zero. But
> > > > I
> > > > can help with this if you can't find it.
> > > >
> > > > Ian Monroe (eean)
> > > >
> > > > On 6/23/06, Roel Meeuws < r.j.meeuws at gmail.com> wrote:
> > > > > Hi Ian,
> > > > >
> > > > > thanks for the reply. I did copy it from uic code. The problem
> > > > for me was I
> > > > > don't know how to extend a parent dialog passed to
> > > > addConfigElements with an
> > > > > external ui file. So I just copied the code. I'd like to note that
> > > > this
> > > > > mechanism of extending the configDialog was not invented by me, so
> > > > we should
> > > > > probably keep using this mechanism.
> > > > >
> > > > > So... anybody any idea on how to extend a dialog with a ui file?
> > > > or any
> > > > > other cleaner options?
> > > > >
> > > > > greetz,
> > > > >
> > > > > Roel
> > > >
> > >
> > >
> > >
> > > --
> > > Roel Meeuws
> > >
> > > Delft University of Technology
> > > Faculty of Electrical Engineering Mathematics and Computer Science
> > > Computer Engineering Laboratory
> > > Mekelweg 4, 2628 CD Delft, The Netherlands
> > > --------------------------------------------
> > > Email:r.j.meeuws at ewi.tudelft.nl
> > > Office phone: +31 (0)6 10 82 44 01
> > > --------------------------------------------
> > >
> >
> >
> >
> > --
> > Roel Meeuws
> >
> > Delft University of Technology
> > Faculty of Electrical Engineering Mathematics and Computer Science
> > Computer Engineering Laboratory
> > Mekelweg 4, 2628 CD Delft, The Netherlands
> > --------------------------------------------
> > Email:r.j.meeuws at ewi.tudelft.nl
> > Office phone: +31 (0)6 10 82 44 01
> > --------------------------------------------
> >
> >
>
>
> --
> Roel Meeuws
>
> Delft University of Technology
> Faculty of Electrical Engineering Mathematics and Computer Science
> Computer Engineering Laboratory
> Mekelweg 4, 2628 CD Delft, The Netherlands
> --------------------------------------------
> Email:r.j.meeuws at ewi.tudelft.nl
> Office phone: +31 (0)6 10 82 44 01
> --------------------------------------------
>
>
--
Roel Meeuws
Delft University of Technology
Faculty of Electrical Engineering Mathematics and Computer Science
Computer Engineering Laboratory
Mekelweg 4, 2628 CD Delft, The Netherlands
--------------------------------------------
Email:r.j.meeuws at ewi.tudelft.nl
Office phone: +31 (0)6 10 82 44 01
--------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/amarok/attachments/20060626/8b649585/attachment.html>
-------------- next part --------------
Index: amarok/src/mediadevice/generic/genericmediadevice.h
===================================================================
--- amarok/src/mediadevice/generic/genericmediadevice.h (revision 554563)
+++ amarok/src/mediadevice/generic/genericmediadevice.h (working copy)
@@ -29,7 +29,10 @@
class GenericMediaItem;
class GenericMediaFile;
+class GenericMediaDeviceConfigDialog;
+class QStringList;
+
typedef QMap<QString, GenericMediaFile*> MediaFileMap;
typedef QMap<GenericMediaItem*, GenericMediaFile*> MediaItemMap;
@@ -37,6 +40,8 @@
{
Q_OBJECT
+ friend class GenericMediaDeviceConfigDialog;
+
public:
GenericMediaDevice();
void init( MediaBrowser* parent );
@@ -46,11 +51,15 @@
void rmbPressed( QListViewItem* qitem, const QPoint& point, int );
- bool hasTransferDialog() { return true; }
- void runTransferDialog();
- TransferDialog *getTransferDialog() { return m_td; }
+ QStringList supportedFiletypes() { return m_supportedFileTypes; }
+ bool isPlayable( const MetaBundle& bundle );
+ bool isPreferredFormat( const MetaBundle &bundle );
bool needsManualConfig() { return false; }
+ void addConfigElements( QWidget * parent );
+ void removeConfigElements( QWidget * /* parent */);
+
+ void applyConfig();
void loadConfig();
MediaFileMap &getFileMap() { return m_mfm; }
@@ -99,6 +108,9 @@
MediaItem *trackExists( const MetaBundle& );
+ QString buildDestination( const QString &format, const MetaBundle &mb );
+ void checkAndBuildLocation( const QString& location );
+
KURL::List getSelectedItems();
void downloadSelectedItems();
void copyTrackSortHelper( const MetaBundle& bundle, QString& sort, QString& base );
@@ -115,14 +127,20 @@
KDirLister *m_dirLister;
- TransferDialog *m_td;
bool m_actuallyVfat;
bool m_dirListerComplete;
bool m_connected;
KURL::List m_downloadList;
MediaFileMap m_mfm;
MediaItemMap m_mim;
+
+ QStringList m_supportedFileTypes;
+ QString m_songLocation;
+ QString m_podcastLocation;
+ bool m_asciiTextOnly;
+ bool m_ignoreThePrefix;
+
+ GenericMediaDeviceConfigDialog *m_configDialog;
};
#endif /*AMAROK_GENERICMEDIADEVICE_H*/
-
Index: amarok/src/mediadevice/generic/genericmediadeviceconfigdialog.ui.h
===================================================================
--- amarok/src/mediadevice/generic/genericmediadeviceconfigdialog.ui.h (revision 0)
+++ amarok/src/mediadevice/generic/genericmediadeviceconfigdialog.ui.h (revision 0)
@@ -0,0 +1,269 @@
+/// Configuration Dialog Extension slots
+
+void
+GenericMediaDeviceConfigDialog::addSupportedButtonClicked()
+{
+ if( m_unsupportedComboBox->currentItem() < 0 )
+ return;
+
+ QComboBox *unsupported = m_unsupportedComboBox;
+ QComboBox *convert = m_convertComboBox;
+ QListBox *supported = m_supportedListBox;
+
+ supported->insertItem( unsupported->currentText() );
+
+ QString temp = convert->currentText();
+ convert->insertItem( unsupported->currentText() );
+
+ unsupported->removeItem( unsupported->currentItem() );
+
+ supported->sort();
+ convert->listBox()->sort();
+
+ convert->setCurrentText( temp );
+}
+
+
+void
+GenericMediaDeviceConfigDialog::removeSupportedButtonClicked()
+{
+ QComboBox *unsupported = m_unsupportedComboBox;
+ QComboBox *convert = m_convertComboBox;
+ QListBox *supported = m_supportedListBox;
+
+ for( uint i = 0; i < supported->count() ; /* nothing */)
+ {
+ QListBoxItem *item = supported->item( i );
+
+ if( item->isSelected() )
+ {
+ QString temp;
+
+ unsupported->insertItem( item->text() );
+
+ temp = convert->currentText();
+
+ convert->setCurrentText( item->text() );
+ convert->removeItem( convert->currentItem() );
+
+ if( temp == item->text() )
+ convert->setCurrentItem( 0 );
+ else
+ convert->setCurrentText( temp );
+
+ item = 0;
+ supported->removeItem( i );
+
+ continue;
+ }
+
+ i++;
+ }
+
+ // at least support mp3 format.
+ if( supported->count() <= 0 )
+ {
+ supported->insertItem( "mp3" );
+ convert->insertItem( "mp3" );
+ convert->setCurrentItem( 0 );
+ unsupported->setCurrentText( "mp3" );
+ unsupported->removeItem( convert->currentItem() );
+ }
+
+ unsupported->listBox()->sort();
+}
+
+
+void
+GenericMediaDeviceConfigDialog::supportedListBoxDoubleClicked( QListBoxItem* item )
+{
+ m_convertComboBox->setCurrentText( item->text() );
+}
+
+
+
+
+void
+GenericMediaDeviceConfigDialog::updateConfigDialogLists( const QStringList & supportedFileTypes )
+{
+ QStringList allTypes;
+ allTypes << "mp3" << "ogg" << "wma" << "mp4" << "aac" << "m4a" << "ac3";
+ allTypes << "wav" << "flac" << "asf" << "asx" << "mpg" << "mp4v" << "mpeg";
+ allTypes << "aa" << "3gp" << "mp2";
+
+ QComboBox *unsupported = m_unsupportedComboBox;
+ QComboBox *convert = m_convertComboBox;
+ QListBox *supported = m_supportedListBox;
+
+
+ for( QStringList::Iterator it = allTypes.begin(); it != allTypes.end(); it++ )
+ {
+ if( supportedFileTypes.contains( *it ) )
+ {
+ supported->insertItem( *it );
+ convert->insertItem( *it );
+ }
+ else
+ {
+ unsupported->insertItem( *it );
+ }
+ }
+
+ supported->sort();
+ unsupported->listBox()->sort();
+ convert->listBox()->sort();
+ convert->setCurrentText( supportedFileTypes.first() );
+}
+
+QString
+GenericMediaDeviceConfigDialog::buildDestination( const QString &format, const MetaBundle &mb ) const
+{
+ bool isCompilation = mb.compilation() > 0;
+ QMap<QString, QString> args;
+ QString artist = mb.artist();
+ QString albumartist = artist;
+ if( isCompilation )
+ albumartist = i18n( "Various Artists" );
+ args["theartist"] = cleanPath( artist );
+ args["thealbumartist"] = cleanPath( albumartist );
+ if( m_ignoreTheCheck->isChecked() && artist.startsWith( "The " ) )
+ CollectionView::instance()->manipulateThe( artist, true );
+ artist = cleanPath( artist );
+ if( m_ignoreTheCheck->isChecked() && albumartist.startsWith( "The " ) )
+ CollectionView::instance()->manipulateThe( albumartist, true );
+
+ albumartist = cleanPath( albumartist );
+ for( int i = 0; i < MetaBundle::NUM_COLUMNS; i++ )
+ {
+ if( i == MetaBundle::Score || i == MetaBundle::PlayCount || i == MetaBundle::LastPlayed )
+ continue;
+ args[mb.exactColumnName( i ).lower()] = cleanPath( mb.prettyText( i ) );
+ }
+ args["artist"] = artist;
+ args["albumartist"] = albumartist;
+ args["initial"] = albumartist.mid( 0, 1 ).upper();
+ args["filetype"] = mb.url().path().section( ".", -1 ).lower();
+ QString track;
+ if ( mb.track() )
+ track.sprintf( "%02d", mb.track() );
+ args["track"] = track;
+
+ amaroK::QStringx formatx( format );
+ QString result = m_device->mountPoint().append( formatx.namedOptArgs( args ) );
+ QString tail = result.mid( m_device->mountPoint().length() );
+ if( !tail.startsWith( "/" ) )
+ tail.prepend( "/" );
+
+ return m_device->mountPoint() + tail.replace( QRegExp( "/\\.*" ), "/" );
+}
+
+QString GenericMediaDeviceConfigDialog::cleanPath( const QString &component ) const
+{
+ QString result = component;
+
+ if( m_asciiCheck->isChecked() )
+ {
+ result = amaroK::cleanPath(result, true /* replaces weird stuff by '_' */);
+ }
+
+ result.simplifyWhiteSpace();
+ if( m_spaceCheck->isChecked() )
+ result.replace( QRegExp( "\\s" ), "_" );
+ if( m_device->m_actuallyVfat )
+ result = amaroK::vfatPath( result );
+
+ result.replace( "/", "-" );
+
+ return result;
+}
+
+
+void
+GenericMediaDeviceConfigDialog::updatePreviewLabel()
+{
+ m_previewLabel->setText( buildDestination( m_songLocationBox->text(), *m_previewBundle ) );
+}
+
+void
+GenericMediaDeviceConfigDialog::updatePreviewLabel( const QString& format)
+{
+ m_previewLabel->setText( buildDestination( format , *m_previewBundle ) );
+}
+
+void
+GenericMediaDeviceConfigDialog::setDevice( GenericMediaDevice* device )
+{
+ m_device = device;
+ m_songLocationBox->setText( m_device->m_songLocation );
+ m_podcastLocationBox->setText( m_device->m_podcastLocation );
+
+ updatePreviewLabel( m_device->m_songLocation );
+
+ updateConfigDialogLists( m_device->m_supportedFileTypes );
+ m_asciiCheck->setChecked( m_device->m_asciiTextOnly );
+ m_spaceCheck->setChecked( m_device->m_spacesToUnderscores );
+ m_ignoreTheCheck->setChecked( m_device->m_ignoreThePrefix );
+}
+
+QString
+GenericMediaDeviceConfigDialog::buildFormatTip() const
+{
+ QMap<QString, QString> args;
+ for( int i = 0; i < MetaBundle::NUM_COLUMNS; i++ )
+ {
+ if( i == MetaBundle::Score || i == MetaBundle::PlayCount || i == MetaBundle::LastPlayed )
+ continue;
+ args[MetaBundle::exactColumnName( i ).lower()] = MetaBundle::prettyColumnName( i );
+ }
+ args["albumartist"] = i18n( "%1 or %2" ).arg( "Album Artist, The" , "The Album Artist" );
+ args["thealbumartist"] = "The Album Artist";
+ args["theartist"] = "The Artist";
+ args["artist"] = i18n( "%1 or %2" ).arg( "Artist, The" , "The Artist" );
+ args["initial"] = i18n( "Artist's Initial" );
+ args["filetype"] = i18n( "File Extension of Source" );
+ args["track"] = i18n( "Track Number" );
+
+ QString tooltip = i18n( "<h3>Custom Format String</h3>" );
+ tooltip += i18n( "You can use the following tokens:" );
+ tooltip += "<ul>";
+ for( QMap<QString, QString>::iterator it = args.begin();
+ it != args.end();
+ ++it )
+ {
+ tooltip += QString( "<li>%1 - %2" ).arg( it.data(), "%" + it.key() );
+ }
+ tooltip += "</ul>";
+
+ tooltip += i18n( "If you surround sections of text that contain a token with curly-braces, "
+ "that section will be hidden if the token is empty." );
+
+ return tooltip;
+}
+
+void
+GenericMediaDeviceConfigDialog::init()
+{
+ m_previewBundle = new MetaBundle();
+ m_previewBundle->setAlbum( AtomicString( "Some Album" ) );
+ m_previewBundle->setArtist( AtomicString( "The One Artist" ) );
+ m_previewBundle->setBitrate( 128 );
+ m_previewBundle->setComment( AtomicString( "Some Comment" ) );
+ m_previewBundle->setCompilation( 0 );
+ m_previewBundle->setComposer( AtomicString( "The One Composer" ) );
+ m_previewBundle->setDiscNumber( 1 );
+ m_previewBundle->setFileType( 2 );
+ m_previewBundle->setFilesize( 1003264 );
+ m_previewBundle->setGenre( AtomicString( "Some Genre" ) );
+ m_previewBundle->setLength( 193 );
+ m_previewBundle->setPlayCount( 2 );
+ m_previewBundle->setRating( 3 );
+ m_previewBundle->setSampleRate( 44100 );
+ m_previewBundle->setScore( 3 );
+ m_previewBundle->setTitle( AtomicString( "Some Title" ) );
+ m_previewBundle->setTrack( 7 );
+ m_previewBundle->setUrl( "/some%20directory/some%20file.mp3" );
+ m_previewBundle->setYear( 2006 );
+
+ m_formatHelp->setText( QString( "<a href='whatsthis:%1'>%2</a>" ).
+ arg( amaroK::escapeHTMLAttr( buildFormatTip() ), i18n( "(Help)" ) ) );
+}
Index: amarok/src/mediadevice/generic/Makefile.am
===================================================================
--- amarok/src/mediadevice/generic/Makefile.am (revision 554563)
+++ amarok/src/mediadevice/generic/Makefile.am (working copy)
@@ -23,8 +23,10 @@
$(all_libraries)
libamarok_generic_mediadevice_la_SOURCES = \
+ genericmediadeviceconfigdialog.ui\
genericmediadevice.cpp
noinst_HEADERS = \
+ genericmediadeviceconfigdialog.ui.h\
genericmediadevice.h
Index: amarok/src/mediadevice/generic/genericmediadevice.cpp
===================================================================
--- amarok/src/mediadevice/generic/genericmediadevice.cpp (revision 554563)
+++ amarok/src/mediadevice/generic/genericmediadevice.cpp (working copy)
@@ -31,6 +31,7 @@
#include "playlist.h"
#include "statusbar/statusbar.h"
#include "transferdialog.h"
+#include "genericmediadeviceconfigdialog.h"
#include <kapplication.h>
#include <kconfig.h> //download saveLocation
@@ -51,7 +52,12 @@
#include <qcstring.h>
#include <qfile.h>
#include <qstringx.h>
+#include <qstringlist.h>
+#include <qcombobox.h>
+#include <qlistbox.h>
+#include <qlineedit.h>
+
typedef QPtrList<GenericMediaFile> MediaFileList;
typedef QPtrListIterator<GenericMediaFile> MediaFileListIterator;
@@ -304,14 +310,22 @@
{
DEBUG_BLOCK
m_name = "Generic Audio Player";
- m_td = 0;
m_dirLister = new KDirLister();
- m_dirLister->setNameFilter( "*.mp3 *.wav *.asf *.flac *.wma *.ogg *.aac *.m4a" );
+ m_dirLister->setNameFilter( "*.mp3 *.wav *.asf *.flac *.wma *.ogg *.aac *.m4a *.mp4 *.mp2 *.ac3" );
m_dirLister->setAutoUpdate( false );
+
m_spacesToUnderscores = false;
- m_firstSort = "None";
- m_secondSort = "None";
- m_thirdSort = "None";
+ m_ignoreThePrefix = false;
+ m_asciiTextOnly = false;
+
+ m_songLocation = "";
+ m_podcastLocation = "";
+
+ m_supportedFileTypes.empty();
+
+ m_configDialog = 0;
+
+
connect( m_dirLister, SIGNAL( newItems(const KFileItemList &) ), this, SLOT( newItems(const KFileItemList &) ) );
connect( m_dirLister, SIGNAL( completed() ), this, SLOT( dirListerCompleted() ) );
connect( m_dirLister, SIGNAL( clear() ), this, SLOT( dirListerClear() ) );
@@ -327,23 +341,58 @@
GenericMediaDevice::~GenericMediaDevice()
{
- setConfigString( "firstGrouping" , m_firstSort );
- setConfigString( "secondGrouping" , m_secondSort );
- setConfigString( "thirdGrouping" , m_thirdSort );
- setConfigBool( "spacesToUnderscores", m_spacesToUnderscores );
+ applyConfig();
closeDevice();
}
void
+GenericMediaDevice::applyConfig()
+{
+ if( m_configDialog != 0)
+ {
+ m_supportedFileTypes.clear();
+ for( uint i = 0; i < m_configDialog->m_supportedListBox->count(); i++ )
+ {
+ QString currentText = m_configDialog->m_supportedListBox->item( i )->text();
+
+ if( currentText == m_configDialog->m_convertComboBox->currentText() )
+ m_supportedFileTypes.prepend( currentText );
+ else
+ m_supportedFileTypes.append( currentText );
+ }
+
+ m_spacesToUnderscores = m_configDialog->m_spaceCheck->isChecked();
+ m_asciiTextOnly = m_configDialog->m_asciiCheck->isChecked();
+ m_ignoreThePrefix = m_configDialog->m_ignoreTheCheck->isChecked();
+
+ m_songLocation = m_configDialog->m_songLocationBox->text();
+ m_podcastLocation = m_configDialog->m_podcastLocationBox->text();
+ }
+
+
+ setConfigString( "songLocation" , m_songLocation );
+ setConfigString( "podcastLocation" , m_podcastLocation );
+ setConfigBool( "spacesToUnderscores", m_spacesToUnderscores );
+ setConfigBool( "ignoreThePrefix" , m_ignoreThePrefix );
+ setConfigBool( "asciiTextOnly" , m_asciiTextOnly );
+ setConfigString( "supportedFiletypes" , m_supportedFileTypes.join( ", " ) );
+}
+
+
+void
GenericMediaDevice::loadConfig()
{
MediaDevice::loadConfig();
- m_spacesToUnderscores = configBool("spacesToUnderscores");
- m_firstSort = configString( "firstGrouping", "None" );
- m_secondSort = configString( "secondGrouping", "None" );
- m_thirdSort = configString( "thirdGrouping", "None" );
+ m_spacesToUnderscores = configBool( "spacesToUnderscores", false );
+ m_ignoreThePrefix = configBool( "ignoreThePrefix", false);
+ m_asciiTextOnly = configBool( "asciiTextOnly", false );
+
+ m_songLocation = configString( "songLocation", "/%artist/%album/%title.%filetype" );
+ m_podcastLocation = configString( "podcastLocation", "/podcasts/" );
+
+ m_supportedFileTypes = QStringList::split( ", ", configString( "supportedFiletypes", "mp3"), true);
}
bool
@@ -382,13 +431,6 @@
return true;
}
-void
-GenericMediaDevice::runTransferDialog()
-{
- m_td = new TransferDialog( this );
- m_td->exec();
-}
-
/// Renaming
void
@@ -491,44 +533,79 @@
/// Uploading
+QString
+GenericMediaDevice::buildDestination( const QString &format, const MetaBundle &mb )
+{
+ bool isCompilation = mb.compilation() > 0;
+ QMap<QString, QString> args;
+ QString artist = mb.artist();
+ QString albumartist = artist;
+ if( isCompilation )
+ albumartist = i18n( "Various Artists" );
+ args["theartist"] = cleanPath( artist );
+ args["thealbumartist"] = cleanPath( albumartist );
+ if( m_ignoreThePrefix && artist.startsWith( "The " ) )
+ CollectionView::instance()->manipulateThe( artist, true );
+ artist = cleanPath( artist );
+ if( m_ignoreThePrefix && albumartist.startsWith( "The " ) )
+ CollectionView::instance()->manipulateThe( albumartist, true );
+
+ albumartist = cleanPath( albumartist );
+ for( int i = 0; i < MetaBundle::NUM_COLUMNS; i++ )
+ {
+ if( i == MetaBundle::Score || i == MetaBundle::PlayCount || i == MetaBundle::LastPlayed )
+ continue;
+ args[mb.exactColumnName( i ).lower()] = cleanPath( mb.prettyText( i ) );
+ }
+ args["artist"] = artist;
+ args["albumartist"] = albumartist;
+ args["initial"] = albumartist.mid( 0, 1 ).upper();
+ args["filetype"] = mb.url().path().section( ".", -1 ).lower();
+ QString track;
+ if ( mb.track() )
+ track.sprintf( "%02d", mb.track() );
+ args["track"] = track;
+
+ amaroK::QStringx formatx( format );
+ QString result = formatx.namedOptArgs( args );
+ if( !result.startsWith( "/" ) )
+ result.prepend( "/" );
+
+ return result.replace( QRegExp( "/\\.*" ), "/" );
+}
+
void
-GenericMediaDevice::copyTrackSortHelper( const MetaBundle& bundle, QString& sort, QString& base )
+GenericMediaDevice::checkAndBuildLocation( const QString& location )
{
- if( sort != "None" )
+ for( int i = m_medium.mountPoint().contains( '/', false );
+ i < location.contains( '/', false );
+ i++ )
{
- QString temp = bundle.prettyText( bundle.columnIndex(sort) );
- temp = ( temp == QString::null ? "Unknown" : cleanPath(temp) );
- QString newBase = base + '/' + temp;
+ QString path = location.section( '/', 0, i );
+ KURL url( path );
- if( !KIO::NetAccess::exists( KURL( newBase ), false, m_parent ) )
+ if( !KIO::NetAccess::exists( url, false, m_parent ) )
{
debug() << "directory does not exist, creating..." << endl;
- if( !KIO::NetAccess::mkdir( KURL( QFile::encodeName( newBase ) ), m_view ) ) //failed
+ if( !KIO::NetAccess::mkdir(url, m_view ) ) //failed
{
- debug() << "Failed to create directory " << temp << endl;
+ debug() << "Failed to create directory " << url << endl;
return;
}
}
- base = newBase;
}
}
-
MediaItem *
GenericMediaDevice::copyTrackToDevice( const MetaBundle& bundle )
{
if( !m_connected ) return 0;
- QString newFilenameSansBaseDir = fileName( bundle );
- QString base = m_transferDir;
+ QString path = m_transferDir + buildDestination( m_songLocation, bundle);
- copyTrackSortHelper( bundle, m_firstSort, base);
- copyTrackSortHelper( bundle, m_secondSort, base);
- copyTrackSortHelper( bundle, m_thirdSort, base);
+ checkAndBuildLocation( path );
- QString newFilename = base + '/' + newFilenameSansBaseDir;
-
- const QCString dest = QFile::encodeName( newFilename );
+ const QCString dest = QFile::encodeName( path );
const KURL desturl = KURL::fromPathOrURL( dest );
//kapp->processEvents( 100 );
@@ -552,49 +629,28 @@
GenericMediaDevice::trackExists( const MetaBundle& bundle )
{
QString key;
+ QString path = buildDestination( m_songLocation, bundle);
+ KURL url( path );
+ QStringList directories = QStringList::split( "/", url.directory(1,1), false );
+
QListViewItem *it = view()->firstChild();
- if( m_firstSort != "None")
+ for( QStringList::Iterator directory = directories.begin();
+ directory != directories.end();
+ directory++ )
{
- key = bundle.prettyText( bundle.columnIndex( m_firstSort ) );
- key = cleanPath( ( key.isEmpty() ? "Unknown" : key ) );
+ key = *directory;
while( it && it->text( 0 ) != key )
it = it->nextSibling();
if( !it )
return 0;
if( !it->childCount() )
- expandItem( it );
+ expandItem( it );
it = it->firstChild();
}
- if( m_secondSort != "None")
- {
- key = bundle.prettyText( bundle.columnIndex( m_secondSort ) );
- key = cleanPath( ( key.isEmpty() ? "Unknown" : key ) );
- while( it && it->text( 0 ) != key )
- {
- it = it->nextSibling();
- }
- if( !it )
- return 0;
- if( !it->childCount() )
- expandItem( it );
- it = it->firstChild();
- }
+ key = url.fileName( true );
+ key = key.isEmpty() ? fileName( bundle ) : key;
- if( m_thirdSort != "None")
- {
- key = bundle.prettyText( bundle.columnIndex( m_thirdSort ) );
- key = cleanPath( ( key.isEmpty() ? "Unknown" : key ) );
- while( it && it->text( 0 ) != key )
- it = it->nextSibling();
- if( !it )
- return 0;
- if( !it->childCount() )
- expandItem( it );
- it = it->firstChild();
- }
-
- key = fileName( bundle );
while( it && it->text( 0 ) != key )
it = it->nextSibling();
@@ -947,4 +1003,43 @@
return result;
}
+/// File Information functions
+
+bool GenericMediaDevice::isPlayable( const MetaBundle& bundle )
+{
+ for( QStringList::Iterator it = m_supportedFileTypes.begin(); it != m_supportedFileTypes.end() ; it++ )
+ {
+ if( bundle.type() == *it )
+ return true;
+ }
+
+ return false;
+}
+
+
+bool GenericMediaDevice::isPreferredFormat( const MetaBundle &bundle )
+{
+ return m_supportedFileTypes.first() == bundle.type();
+}
+
+/// Configuration Dialog Extension
+
+void GenericMediaDevice::addConfigElements( QWidget * parent )
+{
+ m_configDialog = new GenericMediaDeviceConfigDialog( parent );
+
+ m_configDialog->setDevice( this );
+}
+
+
+void GenericMediaDevice::removeConfigElements( QWidget * /* parent */ )
+{
+ if( m_configDialog != 0 )
+ delete m_configDialog;
+
+ m_configDialog = 0;
+
+}
+
+
#include "genericmediadevice.moc"
Index: amarok/src/mediadevice/generic/genericmediadeviceconfigdialog.ui
===================================================================
--- amarok/src/mediadevice/generic/genericmediadeviceconfigdialog.ui (revision 0)
+++ amarok/src/mediadevice/generic/genericmediadeviceconfigdialog.ui (revision 0)
@@ -0,0 +1,466 @@
+<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
+<class>GenericMediaDeviceConfigDialog</class>
+<widget class="QWidget">
+ <property name="name">
+ <cstring>GenericMediaDeviceConfigDialog</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>486</width>
+ <height>577</height>
+ </rect>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>7</hsizetype>
+ <vsizetype>7</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="caption">
+ <string>GenericMediaDeviceConfigDialog1</string>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <property name="spacing">
+ <number>0</number>
+ </property>
+ <widget class="QLayoutWidget" row="0" column="0">
+ <property name="name">
+ <cstring>layout88</cstring>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <widget class="QGroupBox">
+ <property name="name">
+ <cstring>groupBox1</cstring>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>7</hsizetype>
+ <vsizetype>3</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="frameShape">
+ <enum>GroupBoxPanel</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>Sunken</enum>
+ </property>
+ <property name="title">
+ <string>Transferring files to media device</string>
+ </property>
+ <property name="flat">
+ <bool>false</bool>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLabel" row="0" column="0">
+ <property name="name">
+ <cstring>textLabel2</cstring>
+ </property>
+ <property name="text">
+ <string>The following formats will be transferred directly:</string>
+ </property>
+ </widget>
+ <widget class="QLayoutWidget" row="1" column="0">
+ <property name="name">
+ <cstring>layout24</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLayoutWidget">
+ <property name="name">
+ <cstring>layout23</cstring>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QListBox">
+ <property name="name">
+ <cstring>m_supportedListBox</cstring>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>The formats supported by the generic media device.</string>
+ </property>
+ </widget>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>textLabel1</cstring>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>7</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Other formats will be converted to:</string>
+ </property>
+ </widget>
+ </vbox>
+ </widget>
+ <widget class="QLayoutWidget">
+ <property name="name">
+ <cstring>layout19</cstring>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QComboBox">
+ <property name="name">
+ <cstring>m_unsupportedComboBox</cstring>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>The format to add/remove, only unsupported formats are listed here.</string>
+ </property>
+ </widget>
+ <widget class="QPushButton">
+ <property name="name">
+ <cstring>m_addSupportedButton</cstring>
+ </property>
+ <property name="text">
+ <string>&Add format...</string>
+ </property>
+ <property name="accel">
+ <string>Alt+A</string>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>Add the above format to the list.</string>
+ </property>
+ </widget>
+ <widget class="QPushButton">
+ <property name="name">
+ <cstring>m_removeSupportedButton</cstring>
+ </property>
+ <property name="text">
+ <string>Remove selected</string>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>Remove the selected formats from the list.</string>
+ </property>
+ </widget>
+ <spacer>
+ <property name="name">
+ <cstring>spacer1</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Vertical</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Expanding</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>20</width>
+ <height>93</height>
+ </size>
+ </property>
+ </spacer>
+ <widget class="QComboBox">
+ <property name="name">
+ <cstring>m_convertComboBox</cstring>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>1</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>The preferred format for transcoding files.</string>
+ </property>
+ </widget>
+ </vbox>
+ </widget>
+ </hbox>
+ </widget>
+ </grid>
+ </widget>
+ <widget class="QGroupBox">
+ <property name="name">
+ <cstring>groupBox2</cstring>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>7</hsizetype>
+ <vsizetype>0</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="title">
+ <string>Transfered files locations</string>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLayoutWidget" row="0" column="0">
+ <property name="name">
+ <cstring>layout120</cstring>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLayoutWidget">
+ <property name="name">
+ <cstring>layout119</cstring>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QCheckBox" row="0" column="2">
+ <property name="name">
+ <cstring>m_ignoreTheCheck</cstring>
+ </property>
+ <property name="text">
+ <string>Ignore "The"</string>
+ </property>
+ <property name="accel">
+ <string></string>
+ </property>
+ </widget>
+ <widget class="QCheckBox" row="0" column="1">
+ <property name="name">
+ <cstring>m_spaceCheck</cstring>
+ </property>
+ <property name="text">
+ <string>Convert spaces</string>
+ </property>
+ <property name="accel">
+ <string></string>
+ </property>
+ </widget>
+ <widget class="QCheckBox" row="0" column="0">
+ <property name="name">
+ <cstring>m_asciiCheck</cstring>
+ </property>
+ <property name="text">
+ <string>ASCII te&xt</string>
+ </property>
+ <property name="accel">
+ <string>Alt+X</string>
+ </property>
+ </widget>
+ </grid>
+ </widget>
+ <widget class="QLayoutWidget">
+ <property name="name">
+ <cstring>layout96</cstring>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>textLabel1_2_2</cstring>
+ </property>
+ <property name="text">
+ <string>Song location:</string>
+ </property>
+ </widget>
+ <widget class="QLayoutWidget">
+ <property name="name">
+ <cstring>layout86</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLineEdit">
+ <property name="name">
+ <cstring>m_songLocationBox</cstring>
+ </property>
+ <property name="text">
+ <string></string>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>The location of the transfered songs relative to the device mount point.</string>
+ </property>
+ </widget>
+ <widget class="KActiveLabel">
+ <property name="name">
+ <cstring>m_formatHelp</cstring>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>1</hsizetype>
+ <vsizetype>7</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string><p align="center">(help)</p></string>
+ </property>
+ <property name="autoFormatting">
+ <set>AutoAll</set>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>textLabel2_2</cstring>
+ </property>
+ <property name="text">
+ <string>Example song location:</string>
+ </property>
+ </widget>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>m_previewLabel</cstring>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy>
+ <hsizetype>7</hsizetype>
+ <vsizetype>5</vsizetype>
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="frameShape">
+ <enum>StyledPanel</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>Plain</enum>
+ </property>
+ <property name="margin">
+ <number>2</number>
+ </property>
+ <property name="text">
+ <string></string>
+ </property>
+ </widget>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>textLabel2_2_2</cstring>
+ </property>
+ <property name="text">
+ <string>Podcast location:</string>
+ </property>
+ </widget>
+ <widget class="QLineEdit">
+ <property name="name">
+ <cstring>m_podcastLocationBox</cstring>
+ </property>
+ <property name="text">
+ <string></string>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>The location of the transfered podcasts relative to the device mount point.</string>
+ </property>
+ </widget>
+ </vbox>
+ </widget>
+ </vbox>
+ </widget>
+ </grid>
+ </widget>
+ </vbox>
+ </widget>
+ </grid>
+</widget>
+<connections>
+ <connection>
+ <sender>m_addSupportedButton</sender>
+ <signal>clicked()</signal>
+ <receiver>GenericMediaDeviceConfigDialog</receiver>
+ <slot>addSupportedButtonClicked()</slot>
+ </connection>
+ <connection>
+ <sender>m_removeSupportedButton</sender>
+ <signal>clicked()</signal>
+ <receiver>GenericMediaDeviceConfigDialog</receiver>
+ <slot>removeSupportedButtonClicked()</slot>
+ </connection>
+ <connection>
+ <sender>m_supportedListBox</sender>
+ <signal>doubleClicked(QListBoxItem*)</signal>
+ <receiver>GenericMediaDeviceConfigDialog</receiver>
+ <slot>supportedListBoxDoubleClicked(QListBoxItem*)</slot>
+ </connection>
+ <connection>
+ <sender>m_songLocationBox</sender>
+ <signal>textChanged(const QString&)</signal>
+ <receiver>GenericMediaDeviceConfigDialog</receiver>
+ <slot>updatePreviewLabel(const QString&)</slot>
+ </connection>
+ <connection>
+ <sender>m_asciiCheck</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>GenericMediaDeviceConfigDialog</receiver>
+ <slot>updatePreviewLabel()</slot>
+ </connection>
+ <connection>
+ <sender>m_spaceCheck</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>GenericMediaDeviceConfigDialog</receiver>
+ <slot>updatePreviewLabel()</slot>
+ </connection>
+ <connection>
+ <sender>m_ignoreTheCheck</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>GenericMediaDeviceConfigDialog</receiver>
+ <slot>updatePreviewLabel()</slot>
+ </connection>
+</connections>
+<includes>
+ <include location="local" impldecl="in declaration">genericmediadevice.h</include>
+ <include location="global" impldecl="in implementation">metabundle.h</include>
+ <include location="global" impldecl="in implementation">qstringx.h</include>
+ <include location="global" impldecl="in implementation">collectionbrowser.h</include>
+</includes>
+<variables>
+ <variable access="private">GenericMediaDevice *m_device;</variable>
+ <variable access="private">MetaBundle *m_previewBundle;</variable>
+</variables>
+<slots>
+ <slot specifier="non virtual">addSupportedButtonClicked()</slot>
+ <slot specifier="non virtual">removeSupportedButtonClicked()</slot>
+ <slot specifier="non virtual">supportedListBoxDoubleClicked( QListBoxItem * item )</slot>
+ <slot>updatePreviewLabel()</slot>
+ <slot>updatePreviewLabel( const QString & format )</slot>
+</slots>
+<functions>
+ <function access="private" specifier="non virtual">updateConfigDialogLists( const QStringList & supportedFileTypes )</function>
+ <function access="private" specifier="non virtual" returnType="QString">buildDestination( const QString & format, const MetaBundle & mb ) const</function>
+ <function access="private" specifier="non virtual" returnType="QString">cleanPath( const QString & component ) const</function>
+ <function specifier="non virtual">setDevice( GenericMediaDevice * device )</function>
+ <function access="private" specifier="non virtual" returnType="QString">buildFormatTip() const</function>
+ <function access="private" specifier="non virtual">init()</function>
+</functions>
+<layoutdefaults spacing="6" margin="11"/>
+<includehints>
+ <includehint>kactivelabel.h</includehint>
+</includehints>
+</UI>
More information about the Amarok
mailing list