Androids like kittens, too

This commit is contained in:
Andreas 2013-12-22 15:16:42 +01:00
parent fde4586773
commit 00fd9b4724
6 changed files with 51 additions and 13 deletions

View File

@ -217,3 +217,13 @@ void NetworkRemote::CreateRemoteClient(QTcpSocket* client_socket) {
incoming_data_parser_.get(), SLOT(Parse(pb::remote::Message)));
}
}
void NetworkRemote::EnableKittens(bool aww) {
if (outgoing_data_creator_.get())
outgoing_data_creator_->EnableKittens(aww);
}
void NetworkRemote::SendKitten(quint64 id, const QImage &kitten) {
if (outgoing_data_creator_.get())
outgoing_data_creator_->SendKitten(kitten);
}

View File

@ -26,6 +26,8 @@ public slots:
void StartServer();
void ReloadSettings();
void AcceptConnection();
void EnableKittens(bool aww);
void SendKitten(quint64 id, const QImage& kitten);
private:
boost::scoped_ptr<QTcpServer> server_;

View File

@ -33,6 +33,7 @@ const quint32 OutgoingDataCreator::kFileChunkSize = 100000; // in Bytes
OutgoingDataCreator::OutgoingDataCreator(Application* app)
: app_(app),
aww_(false),
ultimate_reader_(new UltimateLyricsReader(this)),
fetcher_(new SongInfoFetcher(this))
{
@ -314,21 +315,26 @@ void OutgoingDataCreator::SendFirstData(bool send_playlist_songs) {
void OutgoingDataCreator::CurrentSongChanged(const Song& song, const QString& uri, const QImage& img) {
current_song_ = song;
current_uri_ = uri;
current_image_ = img;
if (!clients_->empty()) {
// Create the message
pb::remote::Message msg;
msg.set_type(pb::remote::CURRENT_METAINFO);
// If there is no song, create an empty node, otherwise fill it with data
int i = app_->playlist_manager()->active()->current_row();
CreateSong(
current_song_, img, i,
msg.mutable_response_current_metadata()->mutable_song_metadata());
SendDataToClients(&msg);
if (!aww_) {
current_image_ = img;
}
SendSongMetadata();
}
void OutgoingDataCreator::SendSongMetadata() {
// Create the message
pb::remote::Message msg;
msg.set_type(pb::remote::CURRENT_METAINFO);
// If there is no song, create an empty node, otherwise fill it with data
int i = app_->playlist_manager()->active()->current_row();
CreateSong(
current_song_, current_image_, i,
msg.mutable_response_current_metadata()->mutable_song_metadata());
SendDataToClients(&msg);
}
void OutgoingDataCreator::CreateSong(
@ -774,3 +780,15 @@ void OutgoingDataCreator::SendLibrary(RemoteClient *client) {
// Remove temporary file
file.remove();
}
void OutgoingDataCreator::EnableKittens(bool aww) {
aww_ = aww;
}
void OutgoingDataCreator::SendKitten(const QImage& kitten) {
if (aww_) {
current_image_ = kitten;
SendSongMetadata();
}
}

View File

@ -62,6 +62,7 @@ public slots:
void PlaylistRenamed(int id, const QString& new_name);
void ActiveChanged(Playlist*);
void CurrentSongChanged(const Song& song, const QString& uri, const QImage& img);
void SendSongMetadata();
void StateChanged(Engine::State);
void SendKeepAlive();
void SendRepeatMode(PlaylistSequence::RepeatMode mode);
@ -73,6 +74,8 @@ public slots:
void SendSongs(const pb::remote::RequestDownloadSongs& request, RemoteClient* client);
void ResponseSongOffer(RemoteClient* client, bool accepted);
void SendLibrary(RemoteClient* client);
void EnableKittens(bool aww);
void SendKitten(const QImage& kitten);
private:
Application* app_;
@ -86,6 +89,7 @@ private:
int keep_alive_timeout_;
QMap<RemoteClient*, QQueue<DownloadItem> > download_queue_;
int last_track_position_;
bool aww_;
boost::scoped_ptr<UltimateLyricsReader> ultimate_reader_;
ProviderList provider_list_;

View File

@ -58,6 +58,7 @@
#include "library/libraryfilterwidget.h"
#include "library/libraryviewcontainer.h"
#include "musicbrainz/tagfetcher.h"
#include "networkremote/networkremote.h"
#include "playlist/playlistbackend.h"
#include "playlist/playlist.h"
#include "playlist/playlistlistcontainer.h"
@ -670,6 +671,7 @@ MainWindow::MainWindow(Application* app,
SLOT(NowPlayingWidgetPositionChanged(bool)));
connect(ui_->action_hypnotoad, SIGNAL(toggled(bool)), ui_->now_playing, SLOT(AllHail(bool)));
connect(ui_->action_kittens, SIGNAL(toggled(bool)), ui_->now_playing, SLOT(EnableKittens(bool)));
connect(ui_->action_kittens, SIGNAL(toggled(bool)), app_->network_remote(), SLOT(EnableKittens(bool)));
// Hide the console
//connect(ui_->action_console, SIGNAL(triggered()), SLOT(ShowConsole()));
NowPlayingWidgetPositionChanged(ui_->now_playing->show_above_status_bar());

View File

@ -23,6 +23,7 @@
#include "covers/currentartloader.h"
#include "covers/kittenloader.h"
#include "library/librarybackend.h"
#include "networkremote/networkremote.h"
#include "ui/albumcoverchoicecontroller.h"
#include "ui/iconloader.h"
@ -423,6 +424,7 @@ void NowPlayingWidget::EnableKittens(bool aww) {
kittens_ = new KittenLoader(this);
app_->MoveToNewThread(kittens_);
connect(kittens_, SIGNAL(ImageLoaded(quint64,QImage)), SLOT(KittenLoaded(quint64,QImage)));
connect(kittens_, SIGNAL(ImageLoaded(quint64,QImage)), app_->network_remote(), SLOT(SendKitten(quint64,QImage)));
}
aww_ = aww;