2010-06-25 21:04:10 +02:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-06-25 21:04:10 +02:00
|
|
|
|
|
|
|
Clementine 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, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-07-17 19:18:02 +02:00
|
|
|
#include "config.h"
|
2010-06-26 00:36:21 +02:00
|
|
|
#include "devicelister.h"
|
2010-06-25 21:04:10 +02:00
|
|
|
|
2010-09-09 23:49:51 +02:00
|
|
|
#include <QDir>
|
2010-07-17 19:18:02 +02:00
|
|
|
#include <QFile>
|
2010-07-25 02:20:18 +02:00
|
|
|
#include <QStringList>
|
2010-06-26 00:01:47 +02:00
|
|
|
#include <QThread>
|
|
|
|
#include <QtDebug>
|
|
|
|
|
2010-07-25 03:41:06 +02:00
|
|
|
#ifdef HAVE_LIBGPOD
|
2010-07-25 02:20:18 +02:00
|
|
|
#include <gpod/itdb.h>
|
2010-07-25 03:41:06 +02:00
|
|
|
#endif
|
2010-07-25 02:20:18 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
DeviceLister::DeviceLister() : thread_(nullptr) {}
|
2010-06-26 00:01:47 +02:00
|
|
|
|
2010-06-26 00:36:21 +02:00
|
|
|
DeviceLister::~DeviceLister() {
|
2010-06-26 00:01:47 +02:00
|
|
|
if (thread_) {
|
|
|
|
thread_->quit();
|
|
|
|
thread_->wait(1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-26 00:36:21 +02:00
|
|
|
void DeviceLister::Start() {
|
2010-06-26 00:01:47 +02:00
|
|
|
thread_ = new QThread;
|
|
|
|
connect(thread_, SIGNAL(started()), SLOT(ThreadStarted()));
|
|
|
|
|
|
|
|
moveToThread(thread_);
|
|
|
|
thread_->start();
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void DeviceLister::ThreadStarted() { Init(); }
|
2010-07-17 19:18:02 +02:00
|
|
|
|
2010-07-25 02:20:18 +02:00
|
|
|
namespace {
|
|
|
|
|
2010-07-25 02:43:41 +02:00
|
|
|
#ifdef HAVE_LIBGPOD
|
|
|
|
|
2010-07-25 02:20:18 +02:00
|
|
|
QString GetIpodColour(Itdb_IpodModel model) {
|
|
|
|
switch (model) {
|
|
|
|
case ITDB_IPOD_MODEL_MINI_GREEN:
|
|
|
|
case ITDB_IPOD_MODEL_NANO_GREEN:
|
|
|
|
case ITDB_IPOD_MODEL_SHUFFLE_GREEN:
|
|
|
|
return "green";
|
|
|
|
|
|
|
|
case ITDB_IPOD_MODEL_MINI_BLUE:
|
|
|
|
case ITDB_IPOD_MODEL_NANO_BLUE:
|
|
|
|
case ITDB_IPOD_MODEL_SHUFFLE_BLUE:
|
|
|
|
return "blue";
|
|
|
|
|
|
|
|
case ITDB_IPOD_MODEL_MINI_PINK:
|
|
|
|
case ITDB_IPOD_MODEL_NANO_PINK:
|
|
|
|
case ITDB_IPOD_MODEL_SHUFFLE_PINK:
|
|
|
|
return "pink";
|
|
|
|
|
|
|
|
case ITDB_IPOD_MODEL_MINI_GOLD:
|
|
|
|
return "gold";
|
|
|
|
|
|
|
|
case ITDB_IPOD_MODEL_NANO_WHITE:
|
|
|
|
case ITDB_IPOD_MODEL_VIDEO_WHITE:
|
|
|
|
return "white";
|
|
|
|
|
|
|
|
case ITDB_IPOD_MODEL_NANO_SILVER:
|
|
|
|
case ITDB_IPOD_MODEL_CLASSIC_SILVER:
|
|
|
|
return "silver";
|
|
|
|
|
|
|
|
case ITDB_IPOD_MODEL_NANO_RED:
|
|
|
|
case ITDB_IPOD_MODEL_SHUFFLE_RED:
|
|
|
|
return "red";
|
|
|
|
|
|
|
|
case ITDB_IPOD_MODEL_NANO_YELLOW:
|
|
|
|
return "yellow";
|
|
|
|
|
|
|
|
case ITDB_IPOD_MODEL_NANO_PURPLE:
|
|
|
|
case ITDB_IPOD_MODEL_SHUFFLE_PURPLE:
|
|
|
|
return "purple";
|
|
|
|
|
|
|
|
case ITDB_IPOD_MODEL_NANO_ORANGE:
|
|
|
|
case ITDB_IPOD_MODEL_SHUFFLE_ORANGE:
|
|
|
|
return "orange";
|
|
|
|
|
|
|
|
case ITDB_IPOD_MODEL_NANO_BLACK:
|
|
|
|
case ITDB_IPOD_MODEL_VIDEO_BLACK:
|
|
|
|
case ITDB_IPOD_MODEL_CLASSIC_BLACK:
|
|
|
|
return "black";
|
|
|
|
|
|
|
|
default:
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString GetIpodModel(Itdb_IpodModel model) {
|
|
|
|
switch (model) {
|
|
|
|
case ITDB_IPOD_MODEL_MINI:
|
|
|
|
case ITDB_IPOD_MODEL_MINI_BLUE:
|
|
|
|
case ITDB_IPOD_MODEL_MINI_PINK:
|
|
|
|
case ITDB_IPOD_MODEL_MINI_GREEN:
|
|
|
|
case ITDB_IPOD_MODEL_MINI_GOLD:
|
|
|
|
return "mini";
|
|
|
|
|
|
|
|
case ITDB_IPOD_MODEL_NANO_WHITE:
|
|
|
|
case ITDB_IPOD_MODEL_NANO_BLACK:
|
|
|
|
case ITDB_IPOD_MODEL_NANO_SILVER:
|
|
|
|
case ITDB_IPOD_MODEL_NANO_BLUE:
|
|
|
|
case ITDB_IPOD_MODEL_NANO_GREEN:
|
|
|
|
case ITDB_IPOD_MODEL_NANO_PINK:
|
|
|
|
case ITDB_IPOD_MODEL_NANO_RED:
|
|
|
|
case ITDB_IPOD_MODEL_NANO_YELLOW:
|
|
|
|
case ITDB_IPOD_MODEL_NANO_PURPLE:
|
|
|
|
case ITDB_IPOD_MODEL_NANO_ORANGE:
|
|
|
|
return "nano";
|
|
|
|
|
|
|
|
case ITDB_IPOD_MODEL_SHUFFLE:
|
|
|
|
case ITDB_IPOD_MODEL_SHUFFLE_SILVER:
|
|
|
|
case ITDB_IPOD_MODEL_SHUFFLE_PINK:
|
|
|
|
case ITDB_IPOD_MODEL_SHUFFLE_BLUE:
|
|
|
|
case ITDB_IPOD_MODEL_SHUFFLE_GREEN:
|
|
|
|
case ITDB_IPOD_MODEL_SHUFFLE_ORANGE:
|
|
|
|
case ITDB_IPOD_MODEL_SHUFFLE_RED:
|
|
|
|
return "shuffle";
|
|
|
|
|
|
|
|
case ITDB_IPOD_MODEL_COLOR:
|
|
|
|
case ITDB_IPOD_MODEL_REGULAR:
|
|
|
|
case ITDB_IPOD_MODEL_CLASSIC_SILVER:
|
|
|
|
case ITDB_IPOD_MODEL_CLASSIC_BLACK:
|
|
|
|
return "standard";
|
|
|
|
|
|
|
|
case ITDB_IPOD_MODEL_COLOR_U2:
|
|
|
|
case ITDB_IPOD_MODEL_REGULAR_U2:
|
|
|
|
return "U2";
|
|
|
|
|
|
|
|
default:
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-25 02:43:41 +02:00
|
|
|
#endif
|
2010-07-25 02:20:18 +02:00
|
|
|
}
|
|
|
|
|
2011-04-12 19:27:01 +02:00
|
|
|
QUrl DeviceLister::MakeUrlFromLocalPath(const QString& path) const {
|
2010-07-25 02:20:18 +02:00
|
|
|
if (IsIpod(path)) {
|
2010-09-09 23:49:51 +02:00
|
|
|
QUrl ret;
|
|
|
|
ret.setScheme("ipod");
|
|
|
|
ret.setPath(QDir::fromNativeSeparators(path));
|
|
|
|
return ret;
|
2010-07-17 19:18:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return QUrl::fromLocalFile(path);
|
|
|
|
}
|
2010-07-25 02:20:18 +02:00
|
|
|
|
2011-04-12 19:27:01 +02:00
|
|
|
bool DeviceLister::IsIpod(const QString& path) const {
|
|
|
|
return QFile::exists(path + "/iTunes_Control") ||
|
|
|
|
QFile::exists(path + "/iPod_Control") ||
|
|
|
|
QFile::exists(path + "/iTunes/iTunes_Control");
|
|
|
|
}
|
|
|
|
|
2010-07-25 02:20:18 +02:00
|
|
|
QStringList DeviceLister::GuessIconForPath(const QString& path) {
|
|
|
|
QStringList ret;
|
2010-07-25 02:43:41 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_LIBGPOD
|
2010-07-25 02:20:18 +02:00
|
|
|
if (IsIpod(path)) {
|
|
|
|
Itdb_Device* device = itdb_device_new();
|
|
|
|
itdb_device_set_mountpoint(device, path.toLocal8Bit().constData());
|
|
|
|
const Itdb_IpodInfo* info = itdb_device_get_ipod_info(device);
|
|
|
|
|
|
|
|
QString colour = GetIpodColour(info->ipod_model);
|
|
|
|
QString model = GetIpodModel(info->ipod_model);
|
|
|
|
|
|
|
|
itdb_device_free(device);
|
|
|
|
|
|
|
|
if (!colour.isEmpty()) {
|
2010-07-25 15:32:47 +02:00
|
|
|
QString colour_icon = "multimedia-player-ipod-%1-%2";
|
2010-08-09 22:06:53 +02:00
|
|
|
ret << colour_icon.arg(model, colour);
|
2010-07-25 02:20:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!model.isEmpty()) {
|
2010-07-25 15:32:47 +02:00
|
|
|
QString model_icon = "multimedia-player-ipod-%1";
|
2010-07-25 02:20:18 +02:00
|
|
|
ret << model_icon.arg(model);
|
|
|
|
}
|
|
|
|
}
|
2010-07-25 02:43:41 +02:00
|
|
|
#endif
|
2010-07-25 02:20:18 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2010-07-25 15:32:47 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
QStringList DeviceLister::GuessIconForModel(const QString& vendor,
|
|
|
|
const QString& model) {
|
2010-07-25 15:32:47 +02:00
|
|
|
QStringList ret;
|
|
|
|
if (vendor.startsWith("Google") && model.contains("Nexus")) {
|
|
|
|
ret << "phone-google-nexus-one";
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2010-09-11 14:29:44 +02:00
|
|
|
|
|
|
|
int DeviceLister::MountDevice(const QString& id) {
|
2014-02-07 16:34:20 +01:00
|
|
|
const int ret = next_mount_request_id_++;
|
2010-09-11 14:29:44 +02:00
|
|
|
emit DeviceMounted(id, ret, true);
|
|
|
|
return ret;
|
|
|
|
}
|