Ejemplo n.º 1
0
bool
BrowseModel::list_cb (const Xmms::List< Xmms::Dict > &res)
{
	while (!m_list.isEmpty ()) {
		delete m_list.takeFirst ();
	}

	for (res.first (); res.isValid (); ++res) {
		Xmms::Dict d = *res;

		if (!d.contains ("path"))
			continue;

		QString path = QString::fromStdString (d.get<std::string> ("path"));

		QString name;
		if (d.contains ("name")) {
			name = QString::fromStdString (d.get<std::string> ("name"));
		} else {
			if (d.contains ("title")) {
				if (d.contains ("artist")) {
					name += QString::fromStdString (d.get<std::string> ("artist"));
					name += " - ";
				}
				if (d.contains ("album")) {
					name += QString::fromStdString (d.get<std::string> ("album"));
					name += " - ";
				}
				if (d.contains ("tracknr")) {
					name += QString::number (d.get<uint32_t>
											 ("tracknr")).rightJustified(2, '0');
					name += " - ";
				}
				name += QString::fromStdString (d.get<std::string> ("title"));
			} else {
				std::string tmp;
				QString tmp2 = path.mid (path.lastIndexOf ("/")+1);
				tmp = Xmms::decodeUrl (tmp2.toAscii ());
				name = QString::fromUtf8 (tmp.c_str ());
			}
		}

		bool isdir = d.get<int32_t> ("isdir");

		if (m_filter_dot && name.startsWith ("."))
			// skip these files 
			continue;

		m_list.append (new BrowseModelItem (path, name, isdir));
	}

	qSort (m_list.begin (), m_list.end (), BrowseModelItem::itemCompare);

	reset ();

	emit dirChanged (m_current_dir);

	return true;
}
Ejemplo n.º 2
0
bool
PlaylistModel::handle_change (const Xmms::Dict &chg)
{
	int32_t change = chg.get<int32_t> ("type");
	int32_t pos = 0, npos = 0;
	int32_t id = 0;
	QString s;

	if (chg.contains ("position")) {
		pos = chg.get<int32_t> ("position");
	}

	if (chg.contains ("id")) {
#if HAVE_XMMSV
		id = chg.get<int32_t> ("id");
#else
		id = chg.get<uint32_t> ("id");
#endif
	}

	if (chg.contains ("name")) {
		s = XClient::stdToQ (chg.get<std::string> ("name"));
	}

	if (s != m_name) {
		return true;
	}

	QModelIndex idx = QModelIndex ();

	switch (change) {
		case XMMS_PLAYLIST_CHANGED_ADD:
			beginInsertRows (idx, pos, pos);
			m_plist.append (id);
			endInsertRows ();
			break;
		case XMMS_PLAYLIST_CHANGED_INSERT:
			beginInsertRows (idx, pos, pos);
			m_plist.insert (pos, id);
			endInsertRows ();
			break;
		case XMMS_PLAYLIST_CHANGED_MOVE:
			npos = chg.get<int32_t> ("newposition");

			beginRemoveRows (idx, pos, pos);
			m_plist.removeAt (pos);
			endRemoveRows ();

			beginInsertRows (idx, npos, npos);
			m_plist.insert (npos, id);
			endInsertRows ();

			if (pos < npos && pos)
				pos --;

			emit entryMoved (index (pos, 0), index (npos, 0));

			break;
		case XMMS_PLAYLIST_CHANGED_REMOVE:
            m_client->cache ()->invalidate (m_plist[pos]);
			beginRemoveRows (idx, pos, pos);
			m_plist.removeAt (pos);
			endRemoveRows ();
			break;
		default:
            m_client->cache ()->invalidate_all ();
			m_client->playlist ()->listEntries () (Xmms::bind (&PlaylistModel::handle_list, this));
			break;
	}

	/* TODO: call this only for the necessary methods */
	emitTotalPlaytime ();

	return true;
}
Ejemplo n.º 3
0
bool
BrowseModel::list_cb (const Xmms::List< Xmms::Dict > &res)
{
	while (!m_list.isEmpty ()) {
		delete m_list.takeFirst ();
	}

#if HAVE_XMMSV
	for (Xmms::List< Xmms::Dict >::const_iterator iter = res.begin();
	     iter != res.end(); ++iter) {
		Xmms::Dict d = *iter;
#else
	for (res.first (); res.isValid (); ++res) {
		Xmms::Dict d = *res;
#endif

		if (!d.contains ("path"))
			continue;

		QString path = QString::fromStdString (d.get<std::string> ("path"));

		QString name;
		if (d.contains ("name")) {
			name = QString::fromStdString (d.get<std::string> ("name"));
		} else {
			if (d.contains ("title")) {
				if (d.contains ("artist")) {
					name += QString::fromStdString (d.get<std::string> ("artist"));
					name += " - ";
				}
				if (d.contains ("album")) {
					name += QString::fromStdString (d.get<std::string> ("album"));
					name += " - ";
				}
				if (d.contains ("tracknr")) {
					name += QString::number (d.get<int32_t>
											 ("tracknr")).rightJustified(2, '0');
					name += " - ";
				}
				name += QString::fromStdString (d.get<std::string> ("title"));
			} else {
				QString tmp2 = path.mid (path.lastIndexOf ("/")+1);
				name = decodeXmmsUrl (tmp2);
			}
		}

		bool isdir = d.get<int32_t> ("isdir");

		if (m_filter_dot && name.startsWith ("."))
			// skip these files 
			continue;

		m_list.append (new BrowseModelItem (path, name, isdir));
	}

	qSort (m_list.begin (), m_list.end (), BrowseModelItem::itemCompare);

	//qDebug ("%s", m_list.size() > 0 ? qPrintable(m_list.at(0)->data("name")) : "none");

	reset ();

	emit dirChanged (m_current_dir);

	return true;
}

/* QModel overrides */
int
BrowseModel::rowCount (const QModelIndex &parent) const
{
	if (parent.isValid())
		return 0;

	return m_list.size ();
}

int
BrowseModel::columnCount (const QModelIndex &parent) const
{
	return m_columns.size ();
}

QVariant
BrowseModel::data (const QModelIndex &index,
						 int role) const
{
	if (!index.isValid ())
		return QVariant ();

	if (index.column () == 0 && role == Qt::DecorationRole)
		return fileIcon(index);

	if (role != Qt::DisplayRole)
		return QVariant ();

	QString h = m_columns[index.column ()].toLower ();

	return QVariant (m_list.at (index.row ())->data (h));
}

QVariant
BrowseModel::headerData (int section,
						 Qt::Orientation orientation,
						 int role) const
{
	if (role == Qt::DisplayRole)
		return QVariant (m_columns[section]);
	return QVariant ();
}

QIcon
BrowseModel::fileIcon (const QModelIndex &index) const
{
    if (!index.isValid())
		return QIcon ();

	BrowseModelItem *item = m_list.at (index.row ());
	if (item && item->isDir ())
    	return QIcon (m_style->standardPixmap (QStyle::SP_DirClosedIcon));

	return QIcon (m_style->standardPixmap (QStyle::SP_FileIcon));
}
Ejemplo n.º 4
0
bool
PlaylistModel::handle_change (const Xmms::Dict &chg)
{
	int32_t change = chg.get<int32_t> ("type");
	int32_t pos = 0, npos = 0;
	uint32_t id = 0;
	QString s;

	if (chg.contains ("position")) {
		pos = chg.get<int32_t> ("position");
	}

	if (chg.contains ("id")) {
		id = chg.get<int32_t> ("id");
	}

	if (chg.contains ("name")) {
		s = XClient::stdToQ (chg.get<std::string> ("name"));
	}
	
	if (s != m_name) {
		return true;
	}

	QModelIndex idx = QModelIndex ();

	switch (change) {
	case XMMS_PLAYLIST_CHANGED_ADD:
		beginInsertRows (idx, pos, pos);
		m_plist.append (id);
		endInsertRows ();
		emit this->entryAdded();
		break;
	case XMMS_PLAYLIST_CHANGED_INSERT:
		beginInsertRows (idx, pos, pos);
		m_plist.insert (pos, id);
		endInsertRows ();
		emit this->entryAdded();
		break;
	case XMMS_PLAYLIST_CHANGED_MOVE:
		npos = chg.get<int32_t> ("newposition");
		
		beginRemoveRows (idx, pos, pos);
		m_plist.removeAt (pos);
		endRemoveRows ();

		beginInsertRows (idx, npos, npos);
		m_plist.insert (npos, id);
		endInsertRows ();

		if (pos < npos && pos)
			pos --;

		emit entryMoved (index (pos, 0), index (npos, 0));

		break;
	case XMMS_PLAYLIST_CHANGED_REMOVE:
		m_client->cache ()->invalidate (m_plist[pos]);
		beginRemoveRows (idx, pos, pos);
		m_plist.removeAt (pos);
		endRemoveRows ();			
		break;
		case XMMS_PLAYLIST_CHANGED_SHUFFLE:
		case XMMS_PLAYLIST_CHANGED_SORT:
		case XMMS_PLAYLIST_CHANGED_CLEAR:
		m_client->cache ()->invalidate_all ();
		m_client->playlist ()->listEntries () (Xmms::bind (&PlaylistModel::handle_list, this));
		break;
	}

	return true;
}