void XClient::propDictToQHash (const std::string &key, const Xmms::Dict::Variant &value, const std::string &source, #ifdef SOURCEPREF_HACK const QList<QRegExp> &prio_list, QHash<QString, int> &curr_prio, #endif QHash<QString, QVariant> &hash) { #ifdef SOURCEPREF_HACK // braces because of tmp_prio definition { int tmp_prio = getPriority (QString::fromStdString (source), prio_list); QString tmp_key = QString::fromStdString (key); // Don't add a new value if the priority of it isn't better than the // priority already present in hash. If there is no "*" source // preference, this also get's rid of values we don't want at all if (tmp_prio >= curr_prio.value (tmp_key, prio_list.size ())) return; // Set the priority of the current source-key combination for the key, so // that we do not overwrite our value with a worse source for this key. // (higher priority values are worse) curr_prio[tmp_key] = tmp_prio; } #endif if (value.type () == typeid (int32_t)) { hash.insert (QString::fromLatin1 (key.c_str ()), QVariant (boost::get< int32_t > (value))); } else if (value.type () == typeid (uint32_t)) { hash.insert (QString::fromLatin1 (key.c_str ()), QVariant (boost::get< int32_t > (value))); } else { QString val; if (key == "url") { QString tmp = QString::fromUtf8 (boost::get< std::string >(value).c_str ()); #if 0 val = decodeXmmsUrl (tmp); #else tmp = decodeXmmsUrl (tmp); val = tmp.mid (tmp.lastIndexOf ("/") + 1); if (val.isEmpty ()) { val = tmp; } #endif } else { val = QString::fromUtf8 (boost::get< std::string > (value).c_str ()); } hash.insert (stdToQ (key), QVariant (val)); } }
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)); }