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,18 +30,16 @@
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",
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";
@ -53,10 +51,10 @@ VkConnection::VkConnection(QObject* parent)
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

@ -34,8 +34,7 @@ VkMusicCache::VkMusicCache(Application* app, VkService* service)
task_id(0),
file_(NULL),
network_manager_(new QNetworkAccessManager),
reply_(NULL) {
}
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;
}
}
@ -155,8 +158,8 @@ void VkMusicCache::Downloaded() {
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];
}

View File

@ -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();
}

View File

@ -45,10 +45,7 @@ class VkSearchDialog;
*/
class MusicOwner {
public:
MusicOwner() :
songs_count_(0),
id_(0)
{}
MusicOwner() : songs_count_(0), id_(0) {}
explicit MusicOwner(const QUrl& group_url);
Song toOwnerRadio() const;
@ -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,19 +82,12 @@ 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:
static uint last_id_;
int id_;
@ -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,7 +178,8 @@ 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:
@ -233,7 +228,8 @@ private slots:
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();

View File

@ -30,17 +30,12 @@ VkSettingsPage::VkSettingsPage(SettingsDialog *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();
@ -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,16 +25,15 @@
#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
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 {
@ -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") {