Exemple #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;
}
bool
CollectionModel::id_list_get (Xmms::List<unsigned int> const &list)
{
	beginRemoveRows (QModelIndex (), 0, m_plist.size ());
	m_plist.clear ();
	endRemoveRows ();

	int i = 0;
	for (list.first (); list.isValid (); ++list) {
		i ++;
	}

	beginInsertRows (QModelIndex (), 0, i);
	for (list.first (); list.isValid (); ++list) {
		m_plist.append (*list);
	}
	endInsertRows ();
	
    emit searchDone ();

	return true;
}
bool
CollectionInfoModel::info_callback (const Xmms::List<Xmms::Dict> &list)
{
    /* convert the first entry in the list to get the headers */
	QList < QHash < QString, QVariant > > l;
	for (list.first (); list.isValid (); ++list) {
	    QHash<QString, QVariant> h = XClient::convert_dict (*list);
		l.append (h);
	}
	set_data (l);
	
	return true;
}
Exemple #4
0
bool
PlaylistModel::handle_list (const Xmms::List< unsigned int > &list)
#endif
{
	beginRemoveRows (QModelIndex (), 0, m_plist.size ());
	m_plist.clear ();
	endRemoveRows ();

	int i = 0;
#if HAVE_XMMSV
	for (Xmms::List< int >::const_iterator iter = list.begin();
	     iter != list.end(); ++iter) {
		i++;
	}
#else
	for (list.first (); list.isValid (); ++list) {
		i ++;
	}
#endif
	beginInsertRows (QModelIndex (), 0, i);
#if HAVE_XMMSV
	for (Xmms::List< int >::const_iterator iter = list.begin();
	     iter != list.end(); ++iter) {
		m_plist.append (*iter);
	}
#else
	for (list.first (); list.isValid (); ++list) {
		m_plist.append (*list);
	}
#endif

	endInsertRows ();

	emitTotalPlaytime  ();

	return true;
}
Exemple #5
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));
}