make format

This commit is contained in:
Vlad Maltsev 2014-08-03 19:40:06 +07:00
parent bff79664bc
commit e65596cba6
8 changed files with 117 additions and 127 deletions

View File

@ -30,33 +30,31 @@
static const QUrl kVkOAuthEndpoint("https://oauth.vk.com/authorize");
static const QUrl kVkOAuthTokenEndpoint("https://oauth.vk.com/access_token");
static const QUrl kApiUrl("https://api.vk.com/method/");
static const char *kScopeNames[] = { "notify", "friends", "photos", "audio",
"video", "docs", "notes", "pages", "status", "offers", "questions", "wall",
"groups", "messages", "notifications", "stats", "ads", "offline" };
static const char* kScopeNames[] = {
"notify", "friends", "photos", "audio", "video", "docs",
"notes", "pages", "status", "offers", "questions", "wall",
"groups", "messages", "notifications", "stats", "ads", "offline"};
static const QString kAppID = "3421812";
static const QString kAppSecret = "cY7KMyX46Fq3nscZlbdo";
static const VkConnection::Scopes kScopes =
VkConnection::Offline |
VkConnection::Audio |
VkConnection::Friends |
VkConnection::Groups |
VkConnection::Status;
VkConnection::Offline | VkConnection::Audio | VkConnection::Friends |
VkConnection::Groups | VkConnection::Status;
static const char* kSettingsGroup = "Vk.com/oauth";
VkConnection::VkConnection(QObject* parent)
: Connection(parent),
state_(Vreen::Client::StateOffline),
expires_in_(0),
uid_(0) {
: Connection(parent),
state_(Vreen::Client::StateOffline),
expires_in_(0),
uid_(0) {
loadToken();
}
VkConnection::~VkConnection() {
}
VkConnection::~VkConnection() {}
void VkConnection::connectToHost(const QString& login, const QString& password) {
void VkConnection::connectToHost(const QString& login,
const QString& password) {
Q_UNUSED(login)
Q_UNUSED(password)
if (hasAccount()) {
@ -85,16 +83,17 @@ void VkConnection::clear() {
}
bool VkConnection::hasAccount() {
return !access_token_.isNull()
&& (expires_in_ > static_cast<time_t>(QDateTime::currentDateTime().toTime_t()));
return !access_token_.isNull() &&
(expires_in_ >
static_cast<time_t>(QDateTime::currentDateTime().toTime_t()));
}
QNetworkRequest VkConnection::makeRequest(const QString& method, const QVariantMap& args) {
QNetworkRequest VkConnection::makeRequest(const QString& method,
const QVariantMap& args) {
QUrl url = kApiUrl;
url.setPath(url.path() % QLatin1Literal("/") % method);
for (auto it = args.constBegin(); it != args.constEnd(); ++it) {
url.addQueryItem(it.key(),
it.value().toString());
url.addQueryItem(it.key(), it.value().toString());
}
url.addEncodedQueryItem("access_token", access_token_);
return QNetworkRequest(url);
@ -119,9 +118,9 @@ void VkConnection::requestAccessToken() {
qLog(Debug) << "Try to login to Vk.com" << url;
NewClosure(server, SIGNAL(Finished()),
this, SLOT(codeRecived(LocalRedirectServer*, QUrl)),
server, server->url());
NewClosure(server, SIGNAL(Finished()), this,
SLOT(codeRecived(LocalRedirectServer*, QUrl)), server,
server->url());
QDesktopServices::openUrl(url);
}

View File

@ -25,17 +25,16 @@
#include "core/taskmanager.h"
VkMusicCache::VkMusicCache(Application* app, VkService* service)
: QObject(service),
app_(app),
service_(service),
current_song_index(0),
is_downloading(false),
is_aborted(false),
task_id(0),
file_(NULL),
network_manager_(new QNetworkAccessManager),
reply_(NULL) {
}
: QObject(service),
app_(app),
service_(service),
current_song_index(0),
is_downloading(false),
is_aborted(false),
task_id(0),
file_(NULL),
network_manager_(new QNetworkAccessManager),
reply_(NULL) {}
QUrl VkMusicCache::Get(const QUrl& url) {
QUrl result;
@ -47,7 +46,8 @@ QUrl VkMusicCache::Get(const QUrl& url) {
return result;
}
void VkMusicCache::AddToCache(const QUrl& url, const QUrl&media_url, bool force) {
void VkMusicCache::AddToCache(const QUrl& url, const QUrl& media_url,
bool force) {
AddToQueue(CachedFilename(url), media_url);
if (!force) {
current_song_index = queue_.size();
@ -71,7 +71,8 @@ void VkMusicCache::BreakCurrentCaching() {
* Queue operations
*/
void VkMusicCache::AddToQueue(const QString& filename, const QUrl& download_url) {
void VkMusicCache::AddToQueue(const QString& filename,
const QUrl& download_url) {
DownloadItem item;
item.filename = filename;
item.url = download_url;
@ -93,7 +94,8 @@ void VkMusicCache::DownloadNext() {
// Check file path and file existance first
if (QFile::exists(current_download.filename)) {
qLog(Warning) << "Tried to overwrite already cached file" << current_download.filename;
qLog(Warning) << "Tried to overwrite already cached file"
<< current_download.filename;
return;
}
@ -113,14 +115,15 @@ void VkMusicCache::DownloadNext() {
// Start downloading
is_aborted = false;
is_downloading = true;
task_id = app_->task_manager()->
StartTask(tr("Caching %1")
.arg(QFileInfo(current_download.filename).baseName()));
task_id = app_->task_manager()->StartTask(
tr("Caching %1").arg(QFileInfo(current_download.filename).baseName()));
reply_ = network_manager_->get(QNetworkRequest(current_download.url));
connect(reply_, SIGNAL(finished()), SLOT(Downloaded()));
connect(reply_, SIGNAL(readyRead()), SLOT(DownloadReadyToRead()));
connect(reply_, SIGNAL(downloadProgress(qint64, qint64)), SLOT(DownloadProgress(qint64, qint64)));
qLog(Info)<< "Start cashing" << current_download.filename << "from" << current_download.url;
connect(reply_, SIGNAL(downloadProgress(qint64, qint64)),
SLOT(DownloadProgress(qint64, qint64)));
qLog(Info) << "Start cashing" << current_download.filename << "from"
<< current_download.url;
}
}
@ -150,13 +153,13 @@ void VkMusicCache::Downloaded() {
QString path = service_->cacheDir();
if (file_->size() > 0) {
if (file_->size() > 0) {
QDir(path).mkpath(QFileInfo(current_download.filename).path());
if (file_->copy(current_download.filename)) {
qLog(Info) << "Cached" << current_download.filename;
} else {
qLog(Error) << "Unable to save" << current_download.filename
<< ":" << file_->errorString();
qLog(Error) << "Unable to save" << current_download.filename << ":"
<< file_->errorString();
}
} else {
qLog(Error) << "File" << current_download.filename << "is empty";
@ -190,7 +193,8 @@ QString VkMusicCache::CachedFilename(const QUrl& url) {
cache_filename.replace("%artist", args[2]);
cache_filename.replace("%title", args[3]);
} else {
qLog(Warning) << "Song url with args" << args << "does not contain artist and title"
qLog(Warning) << "Song url with args" << args
<< "does not contain artist and title"
<< "use id as file name for cache.";
cache_filename = args[1];
}
@ -201,5 +205,5 @@ QString VkMusicCache::CachedFilename(const QUrl& url) {
return "";
}
// TODO(Vk): Maybe use extenstion from link? Seems it's always mp3.
return cache_dir+QDir::separator()+cache_filename+".mp3";
return cache_dir + QDir::separator() + cache_filename + ".mp3";
}

View File

@ -30,7 +30,7 @@ class Application;
class VkMusicCache : public QObject {
Q_OBJECT
public:
public:
explicit VkMusicCache(Application* app, VkService* service);
~VkMusicCache() {}
// Return file path if file in cache otherwise
@ -40,19 +40,19 @@ public:
void BreakCurrentCaching();
bool InCache(const QUrl& url);
private slots:
private slots:
void AddToQueue(const QString& filename, const QUrl& download_url);
void DownloadNext();
void DownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
void DownloadReadyToRead();
void Downloaded();
private:
private:
struct DownloadItem {
QString filename;
QUrl url;
bool operator ==(const DownloadItem& rhv) {
bool operator==(const DownloadItem& rhv) {
return filename == rhv.filename;
}
};

View File

@ -1026,7 +1026,7 @@ Vreen::AudioItem VkService::GetAudioItemFromUrl(const QUrl& url) {
return Vreen::AudioItem();
}
UrlHandler::LoadResult VkService::GetSongResult(const QUrl&url) {
UrlHandler::LoadResult VkService::GetSongResult(const QUrl& url) {
// Try get from cache
QUrl media_url = cache_->Get(url);
if (media_url.isValid()) {
@ -1093,13 +1093,13 @@ void VkService::SongStarting(const QUrl& url) {
SongStarting(SongFromUrl(url));
}
void VkService::SongStarting(const Song &song)
{
void VkService::SongStarting(const Song& song) {
current_song_ = song;
if (isBroadcasting() && HasAccount()) {
auto id = ExtractIds(song.url());
auto reply = audio_provider_->setBroadcast(id.audio_id, id.owner_id, IdList());
auto reply =
audio_provider_->setBroadcast(id.audio_id, id.owner_id, IdList());
NewClosure(reply, SIGNAL(resultReady(QVariant)), this,
SLOT(BroadcastChangeReceived(Vreen::IntReply*)), reply);
connect(app_->player(), SIGNAL(Stopped()), this, SLOT(SongStoped()),
@ -1113,8 +1113,7 @@ void VkService::SongSkiped() {
cache_->BreakCurrentCaching();
}
void VkService::SongStoped()
{
void VkService::SongStoped() {
current_song_.set_valid(false);
if (isBroadcasting() && HasAccount()) {
@ -1126,8 +1125,7 @@ void VkService::SongStoped()
}
}
void VkService::BroadcastChangeReceived(Vreen::IntReply *reply)
{
void VkService::BroadcastChangeReceived(Vreen::IntReply* reply) {
qLog(Debug) << "Broadcast changed for " << reply->result();
}
@ -1298,8 +1296,8 @@ void VkService::ReloadSettings() {
groups_in_global_search_ = s.value("groups_in_global_search", false).toBool();
if (!s.contains("enable_broadcast")) {
// Need to update premissions
Logout();
// Need to update premissions
Logout();
}
enable_broadcast_ = s.value("enable_broadcast", false).toBool();
}

View File

@ -44,11 +44,8 @@ class VkSearchDialog;
* using in bookmarks.
*/
class MusicOwner {
public:
MusicOwner() :
songs_count_(0),
id_(0)
{}
public:
MusicOwner() : songs_count_(0), id_(0) {}
explicit MusicOwner(const QUrl& group_url);
Song toOwnerRadio() const;
@ -58,7 +55,7 @@ public:
int song_count() const { return songs_count_; }
static QList<MusicOwner> parseMusicOwnerList(const QVariant& request_result);
private:
private:
friend QDataStream& operator<<(QDataStream& stream, const MusicOwner& val);
friend QDataStream& operator>>(QDataStream& stream, MusicOwner& val);
friend QDebug operator<<(QDebug d, const MusicOwner& owner);
@ -66,7 +63,8 @@ private:
int songs_count_;
int id_; // if id > 0 is user otherwise id group
QString name_;
// name used in url http://vk.com/<screen_name> for example: http://vk.com/shedward
// name used in url http://vk.com/<screen_name> for example:
// http://vk.com/shedward
QString screen_name_;
QUrl photo_;
};
@ -84,20 +82,13 @@ QDebug operator<<(QDebug d, const MusicOwner& owner);
* how to react to the received request or quickly skip unwanted.
*/
struct SearchID {
enum Type {
GlobalSearch,
LocalSearch,
MoreLocalSearch,
UserOrGroup
};
enum Type { GlobalSearch, LocalSearch, MoreLocalSearch, UserOrGroup };
explicit SearchID(Type type)
: type_(type) {
id_= last_id_++;
}
explicit SearchID(Type type) : type_(type) { id_ = last_id_++; }
int id() const { return id_; }
Type type() const { return type_; }
private:
private:
static uint last_id_;
int id_;
Type type_;
@ -109,7 +100,7 @@ private:
class VkService : public InternetService {
Q_OBJECT
public:
public:
explicit VkService(Application* app, InternetModel* parent);
~VkService();
@ -133,8 +124,10 @@ public:
Type_Search
};
enum Role { Role_MusicOwnerMetadata = InternetModel::RoleCount,
Role_AlbumMetadata };
enum Role {
Role_MusicOwnerMetadata = InternetModel::RoleCount,
Role_AlbumMetadata
};
Application* app() const { return app_; }
@ -165,7 +158,8 @@ public:
// Return random song result from group playlist.
UrlHandler::LoadResult GetGroupNextSongUrl(const QUrl& url);
void SongSearch(SearchID id, const QString& query, int count = 50, int offset = 0);
void SongSearch(SearchID id, const QString& query, int count = 50,
int offset = 0);
void GroupSearch(SearchID id, const QString& query);
/* Settings */
@ -184,15 +178,16 @@ signals:
void LoginSuccess(bool success);
void SongSearchResult(const SearchID& id, const SongList& songs);
void GroupSearchResult(const SearchID& id, const MusicOwnerList& groups);
void UserOrGroupSearchResult(const SearchID& id, const MusicOwnerList& owners);
void UserOrGroupSearchResult(const SearchID& id,
const MusicOwnerList& owners);
void StopWaiting();
public slots:
public slots:
void UpdateRoot();
void ShowConfig();
void FindUserOrGroup(const QString& q);
private slots:
private slots:
/* Interface */
void UpdateItem();
@ -231,9 +226,10 @@ private slots:
void RecommendationsLoaded(Vreen::AudioItemListReply* reply);
void SearchResultLoaded(const SearchID& id, const SongList& songs);
private:
private:
/* Interface */
QStandardItem* CreateAndAppendRow(QStandardItem* parent, VkService::ItemType type);
QStandardItem* CreateAndAppendRow(QStandardItem* parent,
VkService::ItemType type);
void ClearStandardItem(QStandardItem* item);
QStandardItem* GetBookmarkItemById(int id);
void EnsureMenuCreated();
@ -286,7 +282,7 @@ private:
uint last_search_id_;
QString last_query_;
Song selected_song_; // Store for context menu actions.
Song current_song_; // Store for actions with now playing song.
Song current_song_; // Store for actions with now playing song.
// Store current group url for actions with it.
QUrl current_group_url_;

View File

@ -25,22 +25,17 @@
#include "core/logging.h"
#include "internet/vkservice.h"
VkSettingsPage::VkSettingsPage(SettingsDialog *parent)
: SettingsPage(parent),
ui_(new Ui::VkSettingsPage),
service_(dialog()->app()->internet_model()->Service<VkService>()) {
VkSettingsPage::VkSettingsPage(SettingsDialog* parent)
: SettingsPage(parent),
ui_(new Ui::VkSettingsPage),
service_(dialog()->app()->internet_model()->Service<VkService>()) {
ui_->setupUi(this);
connect(service_, SIGNAL(LoginSuccess(bool)),
SLOT(LoginSuccess(bool)));
connect(ui_->choose_path, SIGNAL(clicked()),
SLOT(CacheDirBrowse()));
connect(ui_->reset, SIGNAL(clicked()),
SLOT(ResetCasheFilenames()));
connect(service_, SIGNAL(LoginSuccess(bool)), SLOT(LoginSuccess(bool)));
connect(ui_->choose_path, SIGNAL(clicked()), SLOT(CacheDirBrowse()));
connect(ui_->reset, SIGNAL(clicked()), SLOT(ResetCasheFilenames()));
}
VkSettingsPage::~VkSettingsPage() {
delete ui_;
}
VkSettingsPage::~VkSettingsPage() { delete ui_; }
void VkSettingsPage::Load() {
service_->ReloadSettings();
@ -49,7 +44,8 @@ void VkSettingsPage::Load() {
ui_->enable_caching->setChecked(service_->isCachingEnabled());
ui_->cache_dir->setText(service_->cacheDir());
ui_->cache_filename->setText(service_->cacheFilename());
ui_->love_button_is_add_to_mymusic->setChecked(service_->isLoveAddToMyMusic());
ui_->love_button_is_add_to_mymusic->setChecked(
service_->isLoveAddToMyMusic());
ui_->groups_in_global_search->setChecked(service_->isGroupsInGlobalSearch());
ui_->enable_broadcast->setChecked(service_->isBroadcasting());
@ -68,8 +64,10 @@ void VkSettingsPage::Save() {
s.setValue("cache_enabled", ui_->enable_caching->isChecked());
s.setValue("cache_dir", ui_->cache_dir->text());
s.setValue("cache_filename", ui_->cache_filename->text());
s.setValue("love_is_add_to_my_music", ui_->love_button_is_add_to_mymusic->isChecked());
s.setValue("groups_in_global_search", ui_->groups_in_global_search->isChecked());
s.setValue("love_is_add_to_my_music",
ui_->love_button_is_add_to_mymusic->isChecked());
s.setValue("groups_in_global_search",
ui_->groups_in_global_search->isChecked());
s.setValue("enable_broadcast", ui_->enable_broadcast->isChecked());
service_->ReloadSettings();
@ -96,7 +94,7 @@ void VkSettingsPage::Logout() {
void VkSettingsPage::CacheDirBrowse() {
QString directory = QFileDialog::getExistingDirectory(
this, tr("Choose Vk.com cache directory"), ui_->cache_dir->text());
this, tr("Choose Vk.com cache directory"), ui_->cache_dir->text());
if (directory.isEmpty()) {
return;
}
@ -113,10 +111,9 @@ void VkSettingsPage::LoginWidgets() {
ui_->name->setText("");
ui_->login_button->setEnabled(true);
connect(ui_->login_button, SIGNAL(clicked()),
SLOT(Login()), Qt::UniqueConnection);
disconnect(ui_->login_button, SIGNAL(clicked()),
this, SLOT(Logout()));
connect(ui_->login_button, SIGNAL(clicked()), SLOT(Login()),
Qt::UniqueConnection);
disconnect(ui_->login_button, SIGNAL(clicked()), this, SLOT(Logout()));
}
void VkSettingsPage::LogoutWidgets() {
@ -124,12 +121,11 @@ void VkSettingsPage::LogoutWidgets() {
ui_->name->setText(tr("Loading..."));
ui_->login_button->setEnabled(true);
connect(service_, SIGNAL(NameUpdated(QString)),
ui_->name, SLOT(setText(QString)), Qt::UniqueConnection);
connect(service_, SIGNAL(NameUpdated(QString)), ui_->name,
SLOT(setText(QString)), Qt::UniqueConnection);
service_->RequestUserProfile();
connect(ui_->login_button, SIGNAL(clicked()),
SLOT(Logout()), Qt::UniqueConnection);
disconnect(ui_->login_button, SIGNAL(clicked()),
this, SLOT(Login()));
connect(ui_->login_button, SIGNAL(clicked()), SLOT(Logout()),
Qt::UniqueConnection);
disconnect(ui_->login_button, SIGNAL(clicked()), this, SLOT(Login()));
}

View File

@ -25,18 +25,17 @@
#include "vkmusiccache.h"
VkUrlHandler::VkUrlHandler(VkService* service, QObject* parent)
: UrlHandler(parent),
service_(service) {
}
: UrlHandler(parent), service_(service) {}
UrlHandler::LoadResult VkUrlHandler::StartLoading(const QUrl& url) {
QStringList args = url.path().split("/");
LoadResult result;
if (args.size() < 2) {
qLog(Error) << "Invalid Vk.com URL: " << url
<< "Url format should be vk://<source>/<id>."
<< "For example vk://song/61145020_166946521/Daughtry/Gone Too Soon";
qLog(Error)
<< "Invalid Vk.com URL: " << url
<< "Url format should be vk://<source>/<id>."
<< "For example vk://song/61145020_166946521/Daughtry/Gone Too Soon";
} else {
QString action = url.host();
@ -52,9 +51,7 @@ UrlHandler::LoadResult VkUrlHandler::StartLoading(const QUrl& url) {
return result;
}
void VkUrlHandler::TrackSkipped() {
service_->SongSkiped();
}
void VkUrlHandler::TrackSkipped() { service_->SongSkiped(); }
UrlHandler::LoadResult VkUrlHandler::LoadNext(const QUrl& url) {
if (url.host() == "group") {

View File

@ -28,7 +28,7 @@ class VkMusicCache;
class VkUrlHandler : public UrlHandler {
Q_OBJECT
public:
public:
VkUrlHandler(VkService* service, QObject* parent);
QString scheme() const { return "vk"; }
QIcon icon() const { return QIcon(":providers/vk.png"); }
@ -36,7 +36,7 @@ public:
void TrackSkipped();
LoadResult LoadNext(const QUrl& url);
private:
private:
VkService* service_;
};