- Add support for user-installable stream providers. Need to copy name.xml.gz, and name.svg/name.png to ~/.config/cantata/streams - or PREFIX/share/cantata/streams
- Use thi snew mechanism to install 1.fm provider
This commit is contained in:
@@ -354,6 +354,7 @@ endif (MSVC)
|
||||
add_subdirectory(po)
|
||||
add_subdirectory(support)
|
||||
add_subdirectory(streams/icons)
|
||||
add_subdirectory(streams/providers)
|
||||
|
||||
if (ENABLE_PROXY_CONFIG)
|
||||
set(CANTATA_SRCS ${CANTATA_SRCS} network/proxysettings.cpp)
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
-----
|
||||
1. Add support for opus audio format - AudioCD encoding, transcoding, HTTP
|
||||
server, etc.
|
||||
2. Add support for user-installable stream providers. Need to copy
|
||||
name.xml.gz, and name.svg/name.png to ~/.config/cantata/streams - or
|
||||
PREFIX/share/cantata/streams
|
||||
|
||||
1.1.1
|
||||
-----
|
||||
|
||||
@@ -38,12 +38,14 @@
|
||||
#include "digitallyimported.h"
|
||||
#include "qjson/parser.h"
|
||||
#include "qtiocompressor/qtiocompressor.h"
|
||||
#include "utils.h"
|
||||
#include <QModelIndex>
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
#include <QMimeData>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QTimer>
|
||||
#include <QLocale>
|
||||
@@ -54,6 +56,9 @@
|
||||
#include <KDE/KGlobal>
|
||||
K_GLOBAL_STATIC(StreamsModel, instance)
|
||||
#endif
|
||||
#if defined Q_OS_WIN
|
||||
#include <QDesktopServices>
|
||||
#endif
|
||||
|
||||
StreamsModel * StreamsModel::self()
|
||||
{
|
||||
@@ -116,6 +121,25 @@ static QIcon getIcon(const QString &name)
|
||||
return icon.isNull() ? Icons::self()->streamCategoryIcon : icon;
|
||||
}
|
||||
|
||||
static QIcon getExternalIcon(const QString &xmlFile)
|
||||
{
|
||||
QIcon icon;
|
||||
QString iconFile=xmlFile;
|
||||
iconFile.replace(".xml.gz", ".svg");
|
||||
|
||||
if (QFile::exists(iconFile)) {
|
||||
icon.addFile(iconFile);
|
||||
} else {
|
||||
iconFile=xmlFile;
|
||||
iconFile.replace(".xml.gz", ".png");
|
||||
if (QFile::exists(iconFile)) {
|
||||
icon.addFile(iconFile);
|
||||
}
|
||||
}
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
static QString categoryCacheName(const QString &name, bool createDir=false)
|
||||
{
|
||||
return Utils::cacheDir(StreamsModel::constCacheDir, createDir)+name+StreamsModel::constCacheExt;
|
||||
@@ -264,7 +288,16 @@ QList<StreamsModel::Item *> StreamsModel::CategoryItem::loadCache()
|
||||
}
|
||||
}
|
||||
|
||||
return newItems;
|
||||
return QList<Item *>();
|
||||
}
|
||||
|
||||
QList<StreamsModel::Item *> StreamsModel::XmlCategoryItem::loadCache()
|
||||
{
|
||||
if (QFile::exists(cacheName)) {
|
||||
return loadXml(cacheName);
|
||||
}
|
||||
|
||||
return QList<Item *>();
|
||||
}
|
||||
|
||||
bool StreamsModel::CategoryItem::saveXml(const QString &fileName, bool format) const
|
||||
@@ -460,6 +493,7 @@ StreamsModel::StreamsModel(QObject *parent)
|
||||
favourites=new FavouritesCategoryItem(constFavouritesUrl, i18n("Favorites"), root, getIcon("favourites"));
|
||||
root->children.append(favourites);
|
||||
buildListenLive();
|
||||
buildXml();
|
||||
addBookmarkAction = ActionCollection::get()->createAction("bookmarkcategory", i18n("Bookmark Category"), Icon("bookmark-new"));
|
||||
addToFavouritesAction = ActionCollection::get()->createAction("addtofavourites", i18n("Add Stream To Favorites"), favouritesIcon());
|
||||
configureAction = ActionCollection::get()->createAction("configurestreams", i18n("Configure Streams"), Icons::self()->configureIcon);
|
||||
@@ -1668,3 +1702,29 @@ void StreamsModel::buildListenLive()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StreamsModel::buildXml()
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
QStringList dirs=QStringList() << QCoreApplication::applicationDirPath()+"/streams/";
|
||||
#else
|
||||
QStringList dirs=QStringList() << INSTALL_PREFIX "/share/cantata/streams/"
|
||||
<< Utils::configDir("streams");
|
||||
#endif
|
||||
QSet<QString> added;
|
||||
|
||||
foreach (const QString &dir, dirs) {
|
||||
if (dir.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
QDir d(dir);
|
||||
QStringList files=d.entryList(QStringList() << "*.xml.gz", QDir::Files|QDir::Readable);
|
||||
foreach (const QString &file, files) {
|
||||
if (!added.contains(file)) {
|
||||
CategoryItem *cat=new XmlCategoryItem(Utils::getFile(file).remove(".xml.gz"), root, getExternalIcon(dir+file), dir+file);
|
||||
added.insert(file);
|
||||
root->children.append(cat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public:
|
||||
CategoryItem * getBookmarksCategory();
|
||||
CategoryItem * createBookmarksCategory();
|
||||
void saveCache() const;
|
||||
QList<Item *> loadCache();
|
||||
virtual QList<Item *> loadCache();
|
||||
bool saveXml(const QString &fileName, bool format=false) const;
|
||||
bool saveXml(QIODevice *dev, bool format=false) const;
|
||||
QList<Item *> loadXml(const QString &fileName, bool importing=false);
|
||||
@@ -119,6 +119,13 @@ public:
|
||||
bool canConfigure() const { return true; }
|
||||
};
|
||||
|
||||
struct XmlCategoryItem : public CategoryItem
|
||||
{
|
||||
XmlCategoryItem(const QString &n, CategoryItem *p, const QIcon &i, const QString &cn)
|
||||
: CategoryItem("-", n, p, i, cn) { }
|
||||
QList<Item *> loadCache();
|
||||
};
|
||||
|
||||
static const QString constPrefix;
|
||||
static const QString constCacheDir;
|
||||
static const QString constCacheExt;
|
||||
@@ -198,6 +205,7 @@ private:
|
||||
Item * toItem(const QModelIndex &index) const { return index.isValid() ? static_cast<Item*>(index.internalPointer()) : root; }
|
||||
bool loadFavourites(const QString &fileName, const QModelIndex &index, bool importing=false);
|
||||
void buildListenLive();
|
||||
void buildXml();
|
||||
|
||||
private:
|
||||
QMap<QNetworkReply *, CategoryItem *> jobs;
|
||||
|
||||
BIN
streams/providers/1.fm.png
Normal file
BIN
streams/providers/1.fm.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.3 KiB |
BIN
streams/providers/1.fm.xml.gz
Normal file
BIN
streams/providers/1.fm.xml.gz
Normal file
Binary file not shown.
6
streams/providers/CMakeLists.txt
Normal file
6
streams/providers/CMakeLists.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
file(GLOB provider_files *.xml.gz *.png *.svg)
|
||||
if (WIN32)
|
||||
install(FILES ${provider_files} DESTINATION ${CMAKE_INSTALL_PREFIX}/streams/)
|
||||
else (WIN32)
|
||||
install(FILES ${provider_files} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/${CMAKE_PROJECT_NAME}/streams/)
|
||||
endif (WIN32)
|
||||
Reference in New Issue
Block a user