Permalink
Browse files

Add first parts of LibDanceTag support

  • Loading branch information...
ximion committed Sep 18, 2011
1 parent 58dae53 commit ecd6639c5b63f6fe3ad630c3e55352532f835889
View
@@ -33,6 +33,7 @@
<file>last.fm/my_friends.png</file>
<file>last.fm/my_neighbours.png</file>
<file>last.fm/user_purple.png</file>
+ <file>providers/dancetag.png</file>
<file>providers/somafm.png</file>
<file>schema/schema-1.sql</file>
<file>schema/schema-2.sql</file>
@@ -314,6 +315,7 @@
<file>schema/schema-30.sql</file>
<file>schema/schema-31.sql</file>
<file>schema/schema-32.sql</file>
+ <file>schema/schema-35.sql</file>
<file>icons/22x22/edit-find.png</file>
<file>icons/32x32/edit-find.png</file>
<file>icons/48x48/edit-find.png</file>
View
Binary file not shown.
@@ -0,0 +1,4 @@
+ALTER TABLE %allsongstables ADD COLUMN dances TEXT DEFAULT "";
+ALTER TABLE playlist_items ADD COLUMN dances TEXT DEFAULT "";
+
+UPDATE schema_version SET version=35;
View
@@ -148,6 +148,8 @@ set(SOURCES
internet/skyfmservice.cpp
internet/somafmservice.cpp
internet/somafmurlhandler.cpp
+ internet/dancetagprovider.cpp

This comment has been minimized.

Show comment Hide comment
@davidsansome

davidsansome Sep 24, 2011

Contributor

Please sort these alphabetically

@davidsansome

davidsansome Sep 24, 2011

Contributor

Please sort these alphabetically

+ internet/dancetagsettingspage.cpp
library/groupbydialog.cpp
library/library.cpp
@@ -366,7 +368,7 @@ set(HEADERS
internet/icecastbackend.h
internet/icecastfilterwidget.h
internet/icecastmodel.h
- internet/icecastservice.h
+ internet/icecastservice.h
internet/internetmimedata.h
internet/internetmodel.h
internet/internetservice.h
@@ -381,6 +383,8 @@ set(HEADERS
internet/skyfmservice.h
internet/somafmservice.h
internet/somafmurlhandler.h
+ internet/dancetagprovider.h
+ internet/dancetagsettingspage.h
library/groupbydialog.h
library/library.h
@@ -531,6 +535,7 @@ set(UI
internet/magnatunedownloaddialog.ui
internet/magnatunesettingspage.ui
internet/spotifysettingspage.ui
+ internet/dancetagsettingspage.ui
library/groupbydialog.ui
library/libraryfilterwidget.ui
View
@@ -33,7 +33,7 @@
#include <QVariant>
const char* Database::kDatabaseFilename = "clementine.db";
-const int Database::kSchemaVersion = 34;
+const int Database::kSchemaVersion = 35;
const char* Database::kMagicAllSongsTables = "%allsongstables";
int Database::sNextConnectionId = 1;
View
@@ -573,6 +573,7 @@ void Song::InitFromQuery(const SqlRow& q, bool reliable_metadata, int col) {
d->cue_path_ = tostr(col + 34);
d->unavailable_ = q.value(col + 35).toBool();
+ d->dances_ = tostr(col + 36);
#undef tostr
#undef toint
@@ -1055,6 +1056,8 @@ void Song::BindToQuery(QSqlQuery *query) const {
query->bindValue(":cue_path", d->cue_path_);
query->bindValue(":unavailable", d->unavailable_ ? 1 : 0);
+
+ query->bindValue(":dances", strval(d->dances_));
#undef intval
#undef notnullintval
View
@@ -176,6 +176,7 @@ class Song {
int disc() const { return d->disc_; }
float bpm() const { return d->bpm_; }
int year() const { return d->year_; }
+ const QString& dances() const { return d->dances_; }
const QString& genre() const { return d->genre_; }
const QString& comment() const { return d->comment_; }
bool is_compilation() const {
@@ -250,6 +251,7 @@ class Song {
void set_track(int v) { d->track_ = v; }
void set_disc(int v) { d->disc_ = v; }
void set_bpm(float v) { d->bpm_ = v; }
+ void set_dances(const QString& v) { d->dances_ = v; }
void set_year(int v) { d->year_ = v; }
void set_genre(const QString& v) { d->genre_ = v; }
void set_genre_id3(int id);
@@ -310,6 +312,7 @@ class Song {
QString artist_;
QString albumartist_;
QString composer_;
+ QString dances_;
int track_;
int disc_;
float bpm_;
@@ -0,0 +1,154 @@
+/* This file is part of Clementine.
+ Copyright 2011, Matthias Klumpp <matthias@tenstral.net>
+
+ Clementine is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Clementine is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Clementine. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "dancetagprovider.h"
+
+#include <glib.h>
+#include <glib-object.h>
+
+#define DANCETAG_API_VERSION 0

This comment has been minimized.

Show comment Hide comment
@davidsansome

davidsansome Sep 24, 2011

Contributor

Can this be a static const int member variable of DanceTagProvider instead?

@davidsansome

davidsansome Sep 24, 2011

Contributor

Can this be a static const int member variable of DanceTagProvider instead?

+
+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 = "";

This comment has been minimized.

Show comment Hide comment
@davidsansome

davidsansome Sep 24, 2011

Contributor

Remove this one if you're going to overwrite it after

@davidsansome

davidsansome Sep 24, 2011

Contributor

Remove this one if you're going to overwrite it after

This comment has been minimized.

Show comment Hide comment
@ximion

ximion Sep 24, 2011

Owner

This one was just for testing... (Users can't set an own API-key at time)

@ximion

ximion Sep 24, 2011

Owner

This one was just for testing... (Users can't set an own API-key at time)

+ apikey = "toapi11";
+ data_provider = new_dataprovider();
+}
+
+void* DanceTagProvider::getFunc(QString name)
+{
+ void* res;
+ QString nfo = "dancetag_" + name;
+ res = m_libdt->resolve(nfo.toLatin1());
+ return res;
+}
+
+void* DanceTagProvider::new_dataprovider ()
+{
+ typedef void* (*NewDataProvider)();
+ NewDataProvider _new_dt = (NewDataProvider) getFunc("data_provider_new");
+
+ typedef void* (*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());
+
+ return dt;
+}
+
+bool DanceTagProvider::available() const
+{
+ return dt_available;
+}
+
+bool DanceTagProvider::ready() const
+{
+ if ((available()) && (apikey != "")

This comment has been minimized.

Show comment Hide comment
@davidsansome

davidsansome Sep 24, 2011

Contributor

!apikey.isEmpty()

@davidsansome

davidsansome Sep 24, 2011

Contributor

!apikey.isEmpty()

+ && (data_provider))
+ return true;
+ else
+ return false;
+}
+
+void* DanceTagProvider::new_dtsongfile(const Song& song)
+{
+ typedef void* (*NewSongFile)(const gchar*, void*);
+ NewSongFile _new_dtsong = (NewSongFile) getFunc("song_file_new");
+ const gchar* fname = song.url().encodedPath().data();

This comment has been minimized.

Show comment Hide comment
@davidsansome

davidsansome Sep 24, 2011

Contributor

I'd check if song.url().scheme() == "file", and then use song.url().toLocalFile().toLocal8Bit().constData()

@davidsansome

davidsansome Sep 24, 2011

Contributor

I'd check if song.url().scheme() == "file", and then use song.url().toLocalFile().toLocal8Bit().constData()

+ if (QString::fromLatin1(fname) == "")
+ return NULL;
+ return _new_dtsong (song.url().encodedPath().data(), data_provider);
+}
+
+void var_unused(void* param) {
+ // FIXME
+}
+
+void DanceTagProvider::fetchDanceTag(const Song& song, bool fromFileOnly)
+{
+ void* dtSong = new_dtsongfile(song);
+ if (!dtSong)
+ return;
+
+ if (!fromFileOnly) {
+ qDebug() << "::TODO";

This comment has been minimized.

Show comment Hide comment
@davidsansome

davidsansome Sep 24, 2011

Contributor

I wrote a nicer logging framework, #include "core/logging.h" then use qLog(Debug) << instead.

@davidsansome

davidsansome Sep 24, 2011

Contributor

I wrote a nicer logging framework, #include "core/logging.h" then use qLog(Debug) << instead.

This comment has been minimized.

Show comment Hide comment
@ximion

ximion Sep 24, 2011

Owner

I already do that :) (See some of the following commits)

@ximion

ximion Sep 24, 2011

Owner

I already do that :) (See some of the following commits)

This comment has been minimized.

Show comment Hide comment
@davidsansome

davidsansome Sep 24, 2011

Contributor

Cool :)

@davidsansome

davidsansome Sep 24, 2011

Contributor

Cool :)

+ }
+
+ qDebug() << "A";
+ typedef GPtrArray* (*GetDances)(void*);
+ GetDances _dt_get_dances = (GetDances) getFunc("song_file_get_dances");
+ GPtrArray* danceList = _dt_get_dances (dtSong);
+ qDebug() << "b";
+
+ if (danceList) {
+ QString dances = "";

This comment has been minimized.

Show comment Hide comment
@davidsansome

davidsansome Sep 24, 2011

Contributor

You don't need to initialise QStrings - they'll be initialised to a null string by default.

@davidsansome

davidsansome Sep 24, 2011

Contributor

You don't need to initialise QStrings - they'll be initialised to a null string by default.

+ qDebug() << "HERE!!";
+ for (uint i = 0; i < danceList->len; i++) {
+ qDebug() << "Alpha";

This comment has been minimized.

Show comment Hide comment
@davidsansome

davidsansome Sep 24, 2011

Contributor

Some tab weirdness going on here :p

@davidsansome

davidsansome Sep 24, 2011

Contributor

Some tab weirdness going on here :p

+ const gchar* dance = (const gchar*) g_ptr_array_index(danceList, i);
+ qDebug() << dance;
+ if (dances != "")

This comment has been minimized.

Show comment Hide comment
@davidsansome

davidsansome Sep 24, 2011

Contributor

if (!dances.isEmpty())

@davidsansome

davidsansome Sep 24, 2011

Contributor

if (!dances.isEmpty())

+ dances += " / ";
+ dances += QString::fromLatin1(dance);

This comment has been minimized.

Show comment Hide comment
@davidsansome

davidsansome Sep 24, 2011

Contributor

May as well use QString::fromUtf8, just in case

@davidsansome

davidsansome Sep 24, 2011

Contributor

May as well use QString::fromUtf8, just in case

+ }
+ qDebug() << "!!!!!!!!!!!!!! " << dances;
+ //song.set_dances (dances);
+ g_ptr_array_unref(danceList);
+ }
+ g_object_unref(dtSong);

This comment has been minimized.

Show comment Hide comment
@davidsansome

davidsansome Sep 24, 2011

Contributor

Make dtSong a ScopedGObject, from core/scopedgobject.h, then it'll get unreffed automatically

@davidsansome

davidsansome Sep 24, 2011

Contributor

Make dtSong a ScopedGObject, from core/scopedgobject.h, then it'll get unreffed automatically

This comment has been minimized.

Show comment Hide comment
@ximion

ximion Sep 24, 2011

Owner

Wow, this is a great hint! Makes life a lot easier!

@ximion

ximion Sep 24, 2011

Owner

Wow, this is a great hint! Makes life a lot easier!

+}
+
+void DanceTagProvider::fetchDanceTags(const SongList& songs)
+{
+ foreach (const Song& song, songs) {
+ fetchDanceTag(song);
+ }
+}
+
+void DanceTagProvider::_test()
+{
+ if (!ready())
+ return;
+
+
+ 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);
+
+
+ typedef gchar* (*SongToStr)(void*, bool);
+ SongToStr _song_tostr = (SongToStr) getFunc("song_to_string");
+
+ if (!songList) {
+ qDebug() << "ERROR!";
+ return;
+ }
+
+ for (uint i = 0; i < songList->len; i++) {
+ void* item = g_ptr_array_index(songList, i);
+ qDebug() << _song_tostr (item, true);
+ }
+
+ g_ptr_array_unref(songList);
+ //g_object_unref (data_provider);
+}
@@ -0,0 +1,61 @@
+/* This file is part of Clementine.
+ Copyright 2011, Matthias Klumpp <matthias@tenstral.net>
+
+ Clementine is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Clementine is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Clementine. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef DANCETAGPROVIDER_H
+#define DANCETAGPROVIDER_H
+
+#include <QIcon>
+#include <QMetaType>
+#include <QObject>
+#include <QLibrary>
+
+#include "core/song.h"
+
+class MimeData;
+
+class DanceTagProvider : public QObject {
+ Q_OBJECT
+
+public:
+ DanceTagProvider(QObject* parent = 0);
+
+ bool ready() const;
+ bool available() const;
+
+ void setApiKey(QString key) { apikey = key; }

This comment has been minimized.

Show comment Hide comment
@davidsansome

davidsansome Sep 24, 2011

Contributor

const QString&

@davidsansome

davidsansome Sep 24, 2011

Contributor

const QString&

+ QString apiKey() const { return apikey; }
+
+ void _test();
+
+public slots:
+ void fetchDanceTag(const Song& song, bool fromFileOnly = true);
+ void fetchDanceTags(const SongList& songs);
+ void fetchDanceTagFromWeb(const Song& song) { fetchDanceTag(song, false); }
+
+private:
+ QString apikey;

This comment has been minimized.

Show comment Hide comment
@davidsansome

davidsansome Sep 24, 2011

Contributor

We use the google C++ coding style, see http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml , member variables should be in unix_hacker_style and end with another underscore. So this would be apikey_

@davidsansome

davidsansome Sep 24, 2011

Contributor

We use the google C++ coding style, see http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml , member variables should be in unix_hacker_style and end with another underscore. So this would be apikey_

+ QLibrary *m_libdt;
+ void* data_provider;
+
+ bool dt_available;
+
+ void* getFunc(QString name);

This comment has been minimized.

Show comment Hide comment
@davidsansome

davidsansome Sep 24, 2011

Contributor

const QString&

@davidsansome

davidsansome Sep 24, 2011

Contributor

const QString&

+ void* new_dataprovider();
+ void* new_dtsongfile(const Song& song);
+};
+
+#endif // DANCETAGPROVIDER_H
Oops, something went wrong.

0 comments on commit ecd6639

Please sign in to comment.