Skip to content
Browse files

Make DanceTag code compliant to Clementine's coding-style

  • Loading branch information...
1 parent 6fc6e33 commit e6ed5e1352ac8b0ed7813390146fe61c932fb873 @ximion committed Sep 24, 2011
View
10 src/CMakeLists.txt
@@ -126,6 +126,8 @@ set(SOURCES
globalsearch/tooltipactionwidget.cpp
globalsearch/tooltipresultwidget.cpp
+ internet/dancetagprovider.cpp
+ internet/dancetagsettingspage.cpp
internet/digitallyimportedservice.cpp
internet/digitallyimportedservicebase.cpp
internet/digitallyimportedsettingspage.cpp
@@ -151,8 +153,6 @@ set(SOURCES
internet/skyfmservice.cpp
internet/somafmservice.cpp
internet/somafmurlhandler.cpp
- internet/dancetagprovider.cpp
- internet/dancetagsettingspage.cpp
library/groupbydialog.cpp
library/library.cpp
@@ -369,6 +369,8 @@ set(HEADERS
globalsearch/tooltipactionwidget.h
globalsearch/tooltipresultwidget.h
+ internet/dancetagprovider.h
+ internet/dancetagsettingspage.h
internet/digitallyimportedservicebase.h
internet/digitallyimportedsettingspage.h
internet/icecastbackend.h
@@ -389,8 +391,6 @@ set(HEADERS
internet/skyfmservice.h
internet/somafmservice.h
internet/somafmurlhandler.h
- internet/dancetagprovider.h
- internet/dancetagsettingspage.h
library/groupbydialog.h
library/library.h
@@ -535,13 +535,13 @@ set(UI
globalsearch/globalsearchpopup.ui
globalsearch/globalsearchwidget.ui
+ internet/dancetagsettingspage.ui
internet/digitallyimportedsettingspage.ui
internet/icecastfilterwidget.ui
internet/internetviewcontainer.ui
internet/magnatunedownloaddialog.ui
internet/magnatunesettingspage.ui
internet/spotifysettingspage.ui
- internet/dancetagsettingspage.ui
library/groupbydialog.ui
library/libraryfilterwidget.ui
View
85 src/internet/dancetagprovider.cpp
@@ -22,66 +22,65 @@
#include <QUrl>
#include "core/logging.h"
+#include "core/scopedgobject.h"
#include "core/song.h"
-#define DANCETAG_API_VERSION 0
-
const char* DanceTagProvider::kSettingsGroup = "DanceTag";
DanceTagProvider::DanceTagProvider(QObject* parent)
: QObject(parent)
{
// Search for the dancetag library
- m_libdt = new QLibrary("dancetag", DANCETAG_API_VERSION, this);
- dt_available = m_libdt->load();
- apikey = "";
- apikey = "toapi11";
- data_provider = new_dataprovider();
+ libdt_ = new QLibrary("dancetag", DanceTagProvider::DANCETAG_API_VERSION, this);
+ available_ = libdt_->load();
+ // For testing
+ apikey_ = "toapi11";
+ data_provider_.reset_without_add(new_dataprovider());
}
-void* DanceTagProvider::getFunc(QString name)
+void* DanceTagProvider::getFunc(const QString& name)
{
void* res;
QString nfo = "dancetag_" + name;
- res = m_libdt->resolve(nfo.toLatin1());
+ res = libdt_->resolve(nfo.toLatin1());
return res;
}
-void* DanceTagProvider::new_dataprovider ()
+GObject* DanceTagProvider::new_dataprovider ()
{
- typedef void* (*NewDataProvider)();
+ typedef GObject* (*NewDataProvider)();
NewDataProvider _new_dt = (NewDataProvider) getFunc("data_provider_new");
- typedef void* (*DataProviderSetKey)(void*, const gchar*);
+ typedef GObject* (*DataProviderSetKey)(void*, const gchar*);
DataProviderSetKey _dt_set_key = (DataProviderSetKey) getFunc("data_provider_set_api_key");
- void* dt = _new_dt();
- _dt_set_key(dt, apikey.toLatin1());
+ GObject* dt = _new_dt();
+ _dt_set_key(dt, apikey_.toLatin1());
return dt;
}
bool DanceTagProvider::available() const
{
- return dt_available;
+ return available_;
}
bool DanceTagProvider::ready() const
{
- if ((available()) && (apikey != "")
- && (data_provider))
+ if ((available()) && (!apikey_.isEmpty())
+ && (data_provider_.get()))
return true;
else
return false;
}
-void* DanceTagProvider::new_dtsongfile(const gchar* fname)
+GObject* DanceTagProvider::new_dtsongfile(const gchar* fname)
{
- typedef void* (*NewSongFile)(const gchar*, void*);
+ typedef GObject* (*NewSongFile)(const gchar*, GObject*);
NewSongFile _new_dtsong = (NewSongFile) getFunc("song_file_new");
- if (QString::fromLatin1(fname) == "")
+ if (QString::fromUtf8(fname).isEmpty())
return NULL;
- return _new_dtsong (fname, data_provider);
+ return _new_dtsong (fname, data_provider_.get());
}
void DanceTagProvider::reloadSettings()
@@ -92,52 +91,55 @@ void DanceTagProvider::reloadSettings()
QString DanceTagProvider::dancesFromFile(const char* fname, bool allowWebDB)
{
if (!available())
- return "";
+ return QString();
- void* dtSong = new_dtsongfile(fname);
- if (!dtSong)
- return "";
+ ScopedGObject<GObject> dtSong;
+ dtSong.reset_without_add(new_dtsongfile(fname));
+ if (!dtSong.get())
+ return QString();
if (allowWebDB) {
- qDebug() << "Searching the web for dances...";
+ qLog(Debug) << "Searching the web for dances...";
// Search the web for dances which match this song
- typedef bool (*UpdateDancesFromWeb)(void*);
+ typedef bool (*UpdateDancesFromWeb)(GObject*);
UpdateDancesFromWeb _dt_file_update_dances = (UpdateDancesFromWeb) getFunc("song_file_update_dance_information_from_web");
- bool success = _dt_file_update_dances(dtSong);
+ bool success = _dt_file_update_dances(dtSong.get());
if (!success)
qLog(Debug) << "Unable to fetch dance tag for" << fname << "from web.";
}
- typedef GPtrArray* (*GetDances)(void*);
+ typedef GPtrArray* (*GetDances)(GObject*);
GetDances _dt_get_dances = (GetDances) getFunc("song_file_get_dances");
- GPtrArray* danceList = _dt_get_dances (dtSong);
+ GPtrArray* danceList = _dt_get_dances (dtSong.get());
- QString dances = "";
+ QString dances;
if (danceList) {
for (uint i = 0; i < danceList->len; i++) {
const gchar* dance = (const gchar*) g_ptr_array_index(danceList, i);
- if ((dance == NULL) || (QString(dance) == ""))
+ if ((dance == NULL) || (!dance[0]))
continue;
- qDebug() << dance;
- if (dances != "")
+ qLog(Debug) << dance;
+ if (!dances.isEmpty())
dances += " / ";
- dances += QString::fromLatin1(dance);
+ dances += QString::fromUtf8(dance);
}
g_ptr_array_unref(danceList);
}
- g_object_unref(dtSong);
return dances;
}
void DanceTagProvider::fetchDanceTag(const Song& song, bool allowWebDB)
{
- QString dances = dancesFromFile(song.url().toString(QUrl::RemoveScheme).toLatin1(), allowWebDB);
+ if (song.url().scheme() != "file")
+ return;
+
+ QString dances = dancesFromFile(song.url().toLocalFile().toLocal8Bit().constData(), allowWebDB);
SongList songs;
Song newSong = song;
- qDebug() << "!!!!!!!!!!!!!! " << dances;
+ qLog(Debug) << "!DanceList: " << dances;
newSong.set_dances (dances);
songs.append(newSong);
@@ -161,20 +163,21 @@ void DanceTagProvider::_test()
typedef GPtrArray* (*SearchSongs)(void*, const gchar*, const gchar*, GError**);
SearchSongs _dt_search = (SearchSongs) getFunc("data_provider_search_songs");
// Search the dance DB for a song
- GPtrArray* songList = _dt_search (data_provider, "Robbie Williams", "Feel", NULL);
+ GPtrArray* songList = _dt_search (data_provider_.get(), "Robbie Williams", "Feel", NULL);
typedef gchar* (*SongToStr)(void*, bool);
SongToStr _song_tostr = (SongToStr) getFunc("song_to_string");
if (!songList) {
- qDebug() << "ERROR!";
+ // TODO
+ qLog(Debug) << "ERROR!";
return;
}
for (uint i = 0; i < songList->len; i++) {
void* item = g_ptr_array_index(songList, i);
- qDebug() << _song_tostr (item, true);
+ qLog(Debug) << _song_tostr (item, true);
}
g_ptr_array_unref(songList);
View
21 src/internet/dancetagprovider.h
@@ -23,6 +23,7 @@
#include <QObject>
#include <QLibrary>
+#include "core/scopedgobject.h"
#include "core/song.h"
class MimeData;
@@ -38,8 +39,8 @@ class DanceTagProvider : public QObject {
bool ready() const;
bool available() const;
- void setApiKey(QString key) { apikey = key; }
- QString apiKey() const { return apikey; }
+ void setApiKey(const QString& key) { apikey_ = key; }
+ QString apiKey() const { return apikey_; }
QString dancesFromFile(const char* fname, bool allowWebDB = false);
@@ -57,15 +58,17 @@ public slots:
void songMetadataChanged(const Song& song);
private:
- QString apikey;
- QLibrary *m_libdt;
- void* data_provider;
+ const static int DANCETAG_API_VERSION = 0;
+
+ QString apikey_;
+ QLibrary *libdt_;
+ ScopedGObject<GObject> data_provider_;
- bool dt_available;
+ bool available_;
- void* getFunc(QString name);
- void* new_dataprovider();
- void* new_dtsongfile(const gchar* fname);
+ void* getFunc(const QString& name);
+ GObject* new_dataprovider();
+ GObject* new_dtsongfile(const gchar* fname);
};
Q_GLOBAL_STATIC(DanceTagProvider, get_dtProvider);
View
4 src/internet/dancetagsettingspage.cpp
@@ -59,7 +59,7 @@ void DanceTagSettingsPage::Save() {
get_dtProvider()->reloadSettings();
}
-void DanceTagSettingsPage::enableDanceTag(bool en)
+void DanceTagSettingsPage::enableDanceTag(bool enabled)
{
- ui_->login_container->setEnabled(en);
+ ui_->login_container->setEnabled(enabled);
}
View
2 src/internet/dancetagsettingspage.h
@@ -32,7 +32,7 @@ class DanceTagSettingsPage : public SettingsPage {
void Save();
private slots:
- void enableDanceTag(bool en);
+ void enableDanceTag(bool enabled);
private:
View
5 src/playlist/playlist.cpp
@@ -276,7 +276,7 @@ QVariant Playlist::data(const QModelIndex& index, int role) const {
case Column_Score: return song.score();
case Column_BPM: return song.bpm();
- case Column_Dances: return song.dances();
+ case Column_Dances: return song.dances();
case Column_Bitrate: return song.bitrate();
case Column_Samplerate: return song.samplerate();
case Column_Filename: return song.url();
@@ -1403,7 +1403,8 @@ void Playlist::SetStreamMetadata(const QUrl& url, const Song& song) {
// Don't update the metadata if it's only a minor change from before
if (current_item_->Metadata().artist() == song.artist() &&
- current_item_->Metadata().title() == song.title())
+ current_item_->Metadata().title() == song.title() &&
+ current_item_->Metadata().dances() == song.dances())
return;
current_item_->SetTemporaryMetadata(song);
View
2 src/ui/mainwindow.cpp
@@ -443,7 +443,7 @@ MainWindow::MainWindow(
connect(playlists_, SIGNAL(CurrentSongChanged(Song)), player_, SLOT(CurrentMetadataChanged(Song)));
if (get_dtProvider()->available()) {
connect(playlists_, SIGNAL(CurrentSongChanged(Song)), get_dtProvider(), SLOT(fetchDanceTagAllowWeb(Song)));
- connect(get_dtProvider(), SIGNAL(songsMetadataChanged(SongList)), playlists_->library_backend(), SLOT(AddOrUpdateSongs(SongList)));
+ connect(get_dtProvider(), SIGNAL(songsMetadataChanged(SongList)), library_->backend(), SLOT(AddOrUpdateSongs(SongList)));
connect(get_dtProvider(), SIGNAL(songMetadataChanged(Song)), playlists_, SLOT(CurrentSongChanged(Song)));
}
connect(playlists_, SIGNAL(EditingFinished(QModelIndex)), SLOT(PlaylistEditFinished(QModelIndex)));

0 comments on commit e6ed5e1

Please sign in to comment.
Something went wrong with that request. Please try again.