From 8110cdf241107506a921b2be53996e32d971c7e2 Mon Sep 17 00:00:00 2001 From: Alan Briolat Date: Mon, 5 Dec 2011 23:10:25 +0000 Subject: [PATCH] Minimal SubsonicService and SubsonicSettingsPage to show up in UI --- data/data.qrc | 1 + data/providers/subsonic.png | Bin 0 -> 734 bytes src/CMakeLists.txt | 5 ++ src/internet/internetmodel.cpp | 2 + src/internet/subsonicservice.cpp | 47 ++++++++++++ src/internet/subsonicservice.h | 39 ++++++++++ src/internet/subsonicsettingspage.cpp | 39 ++++++++++ src/internet/subsonicsettingspage.h | 25 +++++++ src/internet/subsonicsettingspage.ui | 101 ++++++++++++++++++++++++++ src/ui/settingsdialog.cpp | 2 + src/ui/settingsdialog.h | 1 + 11 files changed, 262 insertions(+) create mode 100644 data/providers/subsonic.png create mode 100644 src/internet/subsonicservice.cpp create mode 100644 src/internet/subsonicservice.h create mode 100644 src/internet/subsonicsettingspage.cpp create mode 100644 src/internet/subsonicsettingspage.h create mode 100644 src/internet/subsonicsettingspage.ui diff --git a/data/data.qrc b/data/data.qrc index 1fc89205b..f3a51c48b 100644 --- a/data/data.qrc +++ b/data/data.qrc @@ -337,5 +337,6 @@ schema/schema-35.sql schema/schema-36.sql grooveshark-valicert-ca.pem + providers/subsonic.png diff --git a/data/providers/subsonic.png b/data/providers/subsonic.png new file mode 100644 index 0000000000000000000000000000000000000000..d2d8647872fbfadcbb15d33abf7e61ec59b69b9c GIT binary patch literal 734 zcmV<40wMj0P)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2ipt< z78)(9S|Sqw00Le~L_t(I%WacEYZE~jhM%3?gv3o_H`x@SJ(L8j=}A2FQVPBJ158_y zUX`Bw0UpgQ(33(B4T!hi>L2i?JxKK?N^&qoCS8_fDao>N&AQq3V73(559aXAyzlc3 z?=Z^p@-j(HCKD!;32_{gR*Isa>pHrwU+-x*1wsgbbzldm0f}+~`~Xgc5Z`Zlv`i** z-T1!0rR(}m6h-f%D0&qHfeVn$W{X0I`$C8V;53uTe7pvfN+kfUuC5k~#p0tVie6{4 z*`96NHwU>(OG_VuAm|Gro&#S?rP2sMGfguQ-2*O6)9e9MDiwOY9st#9m4$@`fS%(x z7r;H!G(Q1o<#IUz7=V@Z<#L(T)z!2tEx<^0nqe5p!4P<07zXF(=c%u-v9SSA27V?! z&9-fX5ae>XFDol6PfkuwkW!`s27>|n`}=qM{eF8e7!XAfYQ0`ZQIyr%?&X0y2q?4?{_ui0$wN-2-0 z(`h{jg3T}t5su^FIL>;j)jH~QI*djmfLsb7HyVxTbUL(Jts}>A)*Z+BmjSTY?Ork- zkFhKZpqK(ET9(D-)7}8x*=+Vcj$>N^)VbgmkOAVkDV(o({%f_lRssG1zkuI=0hm$t^>k8U Qg8%>k07*qoM6N<$f_Wr5e*gdg literal 0 HcmV?d00001 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 54a53f28e..a265e0bef 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -169,6 +169,8 @@ set(SOURCES internet/savedradio.cpp internet/somafmservice.cpp internet/somafmurlhandler.cpp + internet/subsonicservice.cpp + internet/subsonicsettingspage.cpp library/groupbydialog.cpp library/library.cpp @@ -411,6 +413,8 @@ set(HEADERS internet/savedradio.h internet/somafmservice.h internet/somafmurlhandler.h + internet/subsonicservice.h + internet/subsonicsettingspage.h library/groupbydialog.h library/library.h @@ -559,6 +563,7 @@ set(UI internet/magnatunedownloaddialog.ui internet/magnatunesettingspage.ui internet/spotifysettingspage.ui + internet/subsonicsettingspage.ui library/groupbydialog.ui library/libraryfilterwidget.ui diff --git a/src/internet/internetmodel.cpp b/src/internet/internetmodel.cpp index f26ab7d97..8786d36f3 100644 --- a/src/internet/internetmodel.cpp +++ b/src/internet/internetmodel.cpp @@ -25,6 +25,7 @@ #include "savedradio.h" #include "somafmservice.h" #include "groovesharkservice.h" +#include "subsonicservice.h" #include "core/logging.h" #include "core/mergedproxymodel.h" #include "smartplaylists/generatormimedata.h" @@ -78,6 +79,7 @@ InternetModel::InternetModel(BackgroundThread* db_thread, #ifdef HAVE_SPOTIFY AddService(new SpotifyService(this)); #endif + AddService(new SubsonicService(this)); } void InternetModel::AddService(InternetService *service) { diff --git a/src/internet/subsonicservice.cpp b/src/internet/subsonicservice.cpp new file mode 100644 index 000000000..bf8a6e5fe --- /dev/null +++ b/src/internet/subsonicservice.cpp @@ -0,0 +1,47 @@ +#include "subsonicservice.h" +#include "internetmodel.h" + +const char* SubsonicService::kServiceName = "Subsonic"; +const char* SubsonicService::kSettingsGroup = "Subsonic"; +const char* SubsonicService::kApiVersion = "1.6.0"; +const char* SubsonicService::kApiClientName = "Clementine"; + +SubsonicService::SubsonicService(InternetModel *parent) + : InternetService(kServiceName, parent, parent) +{ +} + +SubsonicService::~SubsonicService() +{ +} + +QStandardItem* SubsonicService::CreateRootItem() +{ + root_ = new QStandardItem(QIcon(":providers/subsonic.png"), kServiceName); + root_->setData(true, InternetModel::Role_CanLazyLoad); + return root_; +} + +void SubsonicService::LazyPopulate(QStandardItem *item) +{ + +} + +QModelIndex SubsonicService::GetCurrentIndex() +{ + return context_item_; +} + +QUrl SubsonicService::BuildRequestUrl(const QString &view, const RequestOptions &options) +{ + QUrl url(server_url_ + "rest/" + view + ".view"); + url.addQueryItem("v", kApiVersion); + url.addQueryItem("c", kApiClientName); + url.addQueryItem("u", username_); + url.addQueryItem("p", password_); + for (RequestOptions::const_iterator i = options.begin(); i != options.end(); ++i) + { + url.addQueryItem(i.key(), i.value()); + } + return url; +} diff --git a/src/internet/subsonicservice.h b/src/internet/subsonicservice.h new file mode 100644 index 000000000..f574f7741 --- /dev/null +++ b/src/internet/subsonicservice.h @@ -0,0 +1,39 @@ +#ifndef SUBSONICSERVICE_H +#define SUBSONICSERVICE_H + +#include "internetservice.h" + +class SubsonicService : public InternetService +{ + Q_OBJECT + public: + SubsonicService(InternetModel *parent); + ~SubsonicService(); + + typedef QMap RequestOptions; + + QStandardItem* CreateRootItem(); + void LazyPopulate(QStandardItem *item); + + static const char* kServiceName; + static const char* kSettingsGroup; + static const char* kApiVersion; + static const char* kApiClientName; + + protected: + QModelIndex GetCurrentIndex(); + + private: + QUrl BuildRequestUrl(const QString &view, const RequestOptions &options); + + QModelIndex context_item_; + QStandardItem* root_; + + // Configuration + QString server_url_; + QString username_; + QString password_; + +}; + +#endif // SUBSONICSERVICE_H diff --git a/src/internet/subsonicsettingspage.cpp b/src/internet/subsonicsettingspage.cpp new file mode 100644 index 000000000..d669f0df2 --- /dev/null +++ b/src/internet/subsonicsettingspage.cpp @@ -0,0 +1,39 @@ +#include "subsonicsettingspage.h" +#include "ui_subsonicsettingspage.h" +#include "subsonicservice.h" + +#include + +SubsonicSettingsPage::SubsonicSettingsPage(SettingsDialog *dialog) + : SettingsPage(dialog), + ui_(new Ui_SubsonicSettingsPage) +{ + ui_->setupUi(this); + + setWindowIcon(QIcon(":/providers/subsonic.png")); +} + +SubsonicSettingsPage::~SubsonicSettingsPage() +{ + delete ui_; +} + +void SubsonicSettingsPage::Load() +{ + QSettings s; + s.beginGroup(SubsonicService::kSettingsGroup); + + ui_->server->setText(s.value("server").toString()); + ui_->username->setText(s.value("username").toString()); + ui_->password->setText(s.value("password").toString()); +} + +void SubsonicSettingsPage::Save() +{ + QSettings s; + s.beginGroup(SubsonicService::kSettingsGroup); + + s.setValue("server", ui_->server->text()); + s.setValue("username", ui_->username->text()); + s.setValue("password", ui_->password->text()); +} diff --git a/src/internet/subsonicsettingspage.h b/src/internet/subsonicsettingspage.h new file mode 100644 index 000000000..acc4f021c --- /dev/null +++ b/src/internet/subsonicsettingspage.h @@ -0,0 +1,25 @@ +#ifndef SUBSONICSETTINGSPAGE_H +#define SUBSONICSETTINGSPAGE_H + +#include "ui/settingspage.h" + +class Ui_SubsonicSettingsPage; +class SubsonicService; + +class SubsonicSettingsPage : public SettingsPage +{ + Q_OBJECT + + public: + SubsonicSettingsPage(SettingsDialog *dialog); + ~SubsonicSettingsPage(); + + void Load(); + void Save(); + + private: + Ui_SubsonicSettingsPage* ui_; + SubsonicService* service_; +}; + +#endif // SUBSONICSETTINGSPAGE_H diff --git a/src/internet/subsonicsettingspage.ui b/src/internet/subsonicsettingspage.ui new file mode 100644 index 000000000..da5706c73 --- /dev/null +++ b/src/internet/subsonicsettingspage.ui @@ -0,0 +1,101 @@ + + + SubsonicSettingsPage + + + + 0 + 0 + 505 + 219 + + + + Subsonic + + + + + + + + + Server details + + + + + + Server + + + + + + + Username + + + + + + + Password + + + + + + + QLineEdit::Password + + + + + + + + + + + + + Login + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + LoginStateWidget + QWidget +
widgets/loginstatewidget.h
+ 1 +
+
+ + server + username + password + login + + + +
diff --git a/src/ui/settingsdialog.cpp b/src/ui/settingsdialog.cpp index 0e01a16a5..e5026b1f3 100644 --- a/src/ui/settingsdialog.cpp +++ b/src/ui/settingsdialog.cpp @@ -35,6 +35,7 @@ #include "internet/digitallyimportedsettingspage.h" #include "internet/groovesharksettingspage.h" #include "internet/magnatunesettingspage.h" +#include "internet/subsonicsettingspage.h" #include "library/librarysettingspage.h" #include "playlist/playlistview.h" #include "songinfo/songinfosettingspage.h" @@ -149,6 +150,7 @@ SettingsDialog::SettingsDialog(BackgroundStreams* streams, QWidget* parent) AddPage(Page_Magnatune, new MagnatuneSettingsPage(this), providers); AddPage(Page_DigitallyImported, new DigitallyImportedSettingsPage(this), providers); AddPage(Page_BackgroundStreams, new BackgroundStreamsSettingsPage(this), providers); + AddPage(Page_Subsonic, new SubsonicSettingsPage(this), providers); // List box connect(ui_->list, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), diff --git a/src/ui/settingsdialog.h b/src/ui/settingsdialog.h index 237c5cbb9..f2b1947d8 100644 --- a/src/ui/settingsdialog.h +++ b/src/ui/settingsdialog.h @@ -75,6 +75,7 @@ public: Page_Transcoding, Page_Remote, Page_Wiimotedev, + Page_Subsonic, }; enum Role {