1 /***************************************************************************
2 * Copyright (C) 2008 by RafaĆ Rzepecki *
3 * divided.mind@gmail.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #define DEBUG_PREFIX "SonyNWMediaDevice"
23 #include "plugin_amarok_sonynw.h"
24 #include "trackmediaitem.h"
30 #include <qtextcodec.h>
33 // we are not reentrant
36 AMAROK_EXPORT_PLUGIN( SonyNWMediaDevice
)
39 using namespace SonyNW
;
42 static Value
v(const T
&val
) { return Value(val
); }
45 static Value
v(const QString
&str
) { return Value(str
.utf8()); }
47 SonyNWMediaDevice::SonyNWMediaDevice() : MediaDevice(), m_db( 0 )
49 QMutexLocker
lock(&mutex
);
54 QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
57 SonyNWMediaDevice::~SonyNWMediaDevice()
61 bool SonyNWMediaDevice::isConnected()
66 QStringList
SonyNWMediaDevice::supportedFiletypes()
68 return QStringList("mp3");
71 MediaItem
*SonyNWMediaDevice::trackExists( const MetaBundle
& bundle
)
73 // FIXME really search
77 bool SonyNWMediaDevice::lockDevice( bool /*tryOnly*/ )
79 // unsure if that is really possible
83 void SonyNWMediaDevice::unlockDevice()
87 bool SonyNWMediaDevice::openDevice( bool silent
)
89 QMutexLocker
lock(&mutex
);
90 m_db
= new Ruby::Value(klass("NetworkWalkman::Db").send("new", v(mountPoint())));
91 if (m_db
->isNil()) return false;
93 Ruby::Value songs
= m_db
->send("songs");
94 for (int i
= 0; i
< RARRAY(VALUE(songs
))->len
; i
++) {
95 Ruby::Value song
= rb_ary_entry(songs
, i
);
96 if (VALUE(m_db
->const_send("really_exists", song
)) == Qfalse
)
98 TrackMediaItem
* item
= new TrackMediaItem(m_view
);
99 item
->setSong(new Value(song
));
104 bool SonyNWMediaDevice::closeDevice()
106 QMutexLocker
lock(&mutex
);
113 void SonyNWMediaDevice::synchronizeDevice()
115 QMutexLocker
lock(&mutex
);
119 MediaItem
*SonyNWMediaDevice::copyTrackToDevice( const MetaBundle
& bundle
)
121 QMutexLocker
lock(&mutex
);
122 // FIXME check if it's a file url
123 Value mp3
= klass("NetworkWalkman::AudioFile::Mp3").send("new", v(bundle
.url().path()));
124 mp3
.send("putOnDevice", v(mountPoint()));
125 m_db
->send("add", mp3
);
126 TrackMediaItem
* item
= new TrackMediaItem(m_view
);
127 item
->setSong(new Value(mp3
));
131 int SonyNWMediaDevice::deleteItemFromDevice( MediaItem
*it
, int flags
)
133 QMutexLocker
lock(&mutex
);
134 TrackMediaItem
* item
= dynamic_cast<TrackMediaItem
*>(it
);
137 Value song
= *(item
->song());
138 m_db
->send("remove", song
);
139 /* debug() << "would remove: " << "\n";
140 debug() << "\t" << song.inspect() << "\n";
141 debug() << "item is: " << item << " == " << it << "\n";*/
143 // debug() << "and deleted\n";
147 #include "plugin_amarok_sonynw.moc"