1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-23 08:20:01 +01:00

Fix some problems

This commit is contained in:
Krzysztof Sobiecki 2014-11-02 19:32:48 +01:00
parent 011155a751
commit a85728dfb3
13 changed files with 2215 additions and 673 deletions

148
dist/copyright.py vendored Executable file
View File

@ -0,0 +1,148 @@
#!/usr/bin/python
from subprocess import *
from sys import *
from os import rename, remove
from datetime import *
def pretty_years(s):
l = list(s)
l.sort()
start = None
prev = None
r = []
for x in l:
if prev is None:
start = x
prev = x
continue
if x == prev + 1:
prev = x
continue
if prev == start:
r.append("%i" % prev)
else:
r.append("%i-%i" % (start, prev))
start = x
prev = x
if not prev is None:
if prev == start:
r.append("%i" % prev)
else:
r.append("%i-%i" % (start, prev))
return ", ".join(r)
def order_by_year(a, b):
la = list(a[2])
la.sort()
lb = list(b[2])
lb.sort()
if la[0] < lb[0]:
return -1
elif la[0] > lb[0]:
return 1
else:
return 0
def gen_copyrights(f):
commits = []
data = {}
copyrights = []
for ln in Popen(["git", "blame", "--incremental", f], stdout=PIPE).stdout:
if ln.startswith("filename "):
if len(data) > 0:
commits.append(data)
data = {}
elif ln.startswith("author "):
data["author"] = ln[7:].strip()
elif ln.startswith("author-mail <"):
data["author-mail"] = ln[12:].strip()
elif ln.startswith("author-time "):
data["author-time"] = ln[11:].strip()
elif ln.startswith("author-tz "):
data["author-tz"] = ln[9:].strip()
by_author = {}
for c in commits:
try:
n = by_author[c["author"]]
except KeyError:
n = (c["author"], c["author-mail"], set())
by_author[c["author"]] = n
# FIXME: Handle time zones properly
year = datetime.fromtimestamp(int(c["author-time"])).year
n[2].add(year)
for an, a in list(by_author.iteritems()):
for bn, b in list(by_author.iteritems()):
if a is b:
continue
if a[1] == b[1]:
a[2].update(b[2])
if by_author.has_key(an) and by_author.has_key(bn):
del by_author[bn]
copyright = list(by_author.itervalues())
copyright.sort(order_by_year)
for name, mail, years in copyright:
copyrights.append(" Copyright %s, %s %s\n" % (pretty_years(years), name, mail))
return copyrights
def change_file(filename):
content=[]
out=[]
extended=0
ends=0
with open(filename, "r") as fi:
content=fi.readlines()
copyrights=gen_copyrights(filename)
if -1 == content[0].find("/* This file is part of Clementine."):
return 0
for i in content:
if i.find("*/") != -1:
ends = 1
if i.find("Copyright ") != -1:
if not extended:
out.extend(copyrights)
extended = 1
if not ends:
continue
else:
out.append(i)
with open(filename+'_tmp', "w") as fi:
fi.writelines(out)
rename(filename+'_tmp', filename)
if __name__ == "__main__":
for files in argv[1:]:
change_file(files)

2684
dist/cpplint.py vendored

File diff suppressed because it is too large Load Diff

View File

@ -33,7 +33,7 @@ class BackgroundStreams : public QObject {
Q_OBJECT
public:
BackgroundStreams(EngineBase* engine, QObject* parent = nullptr);
explicit BackgroundStreams(EngineBase* engine, QObject* parent = nullptr);
~BackgroundStreams();
void LoadStreams();

View File

@ -26,7 +26,7 @@
template <typename T, typename D>
class BoundFutureWatcher : public QFutureWatcher<T>, boost::noncopyable {
public:
BoundFutureWatcher(const D& data, QObject* parent = nullptr)
explicit BoundFutureWatcher(const D& data, QObject* parent = nullptr)
: QFutureWatcher<T>(parent), data_(data) {}
~BoundFutureWatcher() {}

View File

@ -33,7 +33,7 @@ class CommandlineOptions {
friend QDataStream& operator>>(QDataStream& s, CommandlineOptions& a);
public:
CommandlineOptions(int argc = 0, char* *argv = nullptr);
explicit CommandlineOptions(int argc = 0, char* *argv = nullptr);
static const char* kHelpText;
static const char* kVersionText;

View File

@ -387,7 +387,7 @@ void Database::AttachDatabase(const QString& database_name,
void Database::AttachDatabaseOnDbConnection(const QString& database_name,
const AttachedDatabase& database,
const QSqlDatabase& db) {
QSqlDatabase& db) {
AttachDatabase(database_name, database);
// Attach the db
@ -416,7 +416,7 @@ void Database::DetachDatabase(const QString& database_name) {
attached_databases_.remove(database_name);
}
void Database::UpdateDatabaseSchema(int version, const QSqlDatabase& db) {
void Database::UpdateDatabaseSchema(int version, QSqlDatabase& db) {
QString filename;
if (version == 0)
filename = ":/schema/schema.sql";
@ -447,7 +447,7 @@ void Database::UpdateDatabaseSchema(int version, const QSqlDatabase& db) {
}
}
void Database::UrlEncodeFilenameColumn(const QString& table, const QSqlDatabase& db) {
void Database::UrlEncodeFilenameColumn(const QString& table, QSqlDatabase& db) {
QSqlQuery select(QString("SELECT ROWID, filename FROM %1").arg(table), db);
QSqlQuery update(
QString("UPDATE %1 SET filename=:filename WHERE ROWID=:id").arg(table),
@ -471,7 +471,7 @@ void Database::UrlEncodeFilenameColumn(const QString& table, const QSqlDatabase&
}
}
void Database::ExecSchemaCommandsFromFile(const QSqlDatabase& db,
void Database::ExecSchemaCommandsFromFile(QSqlDatabase& db,
const QString& filename,
int schema_version,
bool in_transaction) {
@ -483,7 +483,7 @@ void Database::ExecSchemaCommandsFromFile(const QSqlDatabase& db,
schema_version, in_transaction);
}
void Database::ExecSchemaCommands(const QSqlDatabase& db, const QString& schema,
void Database::ExecSchemaCommands(QSqlDatabase& db, const QString& schema,
int schema_version, bool in_transaction) {
// Run each command
const QStringList commands(schema.split(QRegExp("; *\n\n")));
@ -505,7 +505,7 @@ void Database::ExecSchemaCommands(const QSqlDatabase& db, const QString& schema,
}
}
void Database::ExecSongTablesCommands(const QSqlDatabase& db,
void Database::ExecSongTablesCommands(QSqlDatabase& db,
const QStringList& song_tables,
const QStringList& commands) {
for (const QString& command : commands) {
@ -535,7 +535,7 @@ void Database::ExecSongTablesCommands(const QSqlDatabase& db,
}
}
QStringList Database::SongsTables(const QSqlDatabase& db, int schema_version) const {
QStringList Database::SongsTables(QSqlDatabase& db, int schema_version) const {
QStringList ret;
// look for the tables in the main db

View File

@ -70,7 +70,7 @@ class Database : public QObject {
QMutex* Mutex() { return &mutex_; }
void RecreateAttachedDb(const QString& database_name);
void ExecSchemaCommands(const QSqlDatabase& db, const QString& schema,
void ExecSchemaCommands(QSqlDatabase& db, const QString& schema,
int schema_version, bool in_transaction = false);
int startup_schema_version() const { return startup_schema_version_; }
@ -80,7 +80,7 @@ class Database : public QObject {
const AttachedDatabase& database);
void AttachDatabaseOnDbConnection(const QString& database_name,
const AttachedDatabase& database,
const QSqlDatabase& db);
QSqlDatabase& db);
void DetachDatabase(const QString& database_name);
signals:
@ -92,16 +92,16 @@ class Database : public QObject {
private:
void UpdateMainSchema(QSqlDatabase* db);
void ExecSchemaCommandsFromFile(const QSqlDatabase& db, const QString& filename,
void ExecSchemaCommandsFromFile(QSqlDatabase& db, const QString& filename,
int schema_version,
bool in_transaction = false);
void ExecSongTablesCommands(const QSqlDatabase& db, const QStringList& song_tables,
void ExecSongTablesCommands(QSqlDatabase& db, const QStringList& song_tables,
const QStringList& commands);
void UpdateDatabaseSchema(int version, const QSqlDatabase& db);
void UrlEncodeFilenameColumn(const QString& table, const QSqlDatabase& db);
QStringList SongsTables(const QSqlDatabase& db, int schema_version) const;
bool IntegrityCheck(const QSqlDatabase db);
void UpdateDatabaseSchema(int version, QSqlDatabase& db);
void UrlEncodeFilenameColumn(const QString& table, QSqlDatabase& db);
QStringList SongsTables(QSqlDatabase& db, int schema_version) const;
bool IntegrityCheck(QSqlDatabase db);
void BackupFile(const QString& filename);
bool OpenDatabase(const QString& filename, sqlite3** connection) const;

View File

@ -108,7 +108,8 @@ void FHT::semiLogSpectrum(float* p) {
void FHT::spectrum(float* p) {
power2(p);
for (int i = 0; i < (m_num / 2); i++, p++) *p = static_cast<float>(sqrt(*p * .5));
for (int i = 0; i < (m_num / 2); i++, p++)
*p = static_cast<float>(sqrt(*p * .5));
}
void FHT::power(float* p) {

View File

@ -232,7 +232,7 @@ QString OrganiseFormat::TagValue(const QString& tag, const Song& song) const {
OrganiseFormat::Validator::Validator(QObject* parent) : QValidator(parent) {}
QValidator::State OrganiseFormat::Validator::validate(const QString& input,
QValidator::State OrganiseFormat::Validator::validate(QString& input,
int&) const {
QRegExp tag_regexp(kTagPattern);

View File

@ -51,7 +51,7 @@ class OrganiseFormat {
class Validator : public QValidator {
public:
explicit Validator(QObject* parent = nullptr);
QValidator::State validate(const QString& format, const int& pos) const;
QValidator::State validate(QString& format, int& pos) const;
};
class SyntaxHighlighter : public QSyntaxHighlighter {

View File

@ -614,9 +614,9 @@ void Song::InitFromQuery(const SqlRow& q, bool reliable_metadata, int col) {
void Song::InitFromFilePartial(const QString& filename) {
set_url(QUrl::fromLocalFile(filename));
// We currently rely on filename suffix to know if it's a music file or not.
// TODO(Arnaud Bienner): I know this is not satisfying, but currently, we rely on TagLib
// which seems to have the behavior (filename checks). Someday, it would be
// nice to perform some magic tests everywhere.
// TODO(Arnaud Bienner): I know this is not satisfying, but currently,
// we rely on TagLib which seems to have the behavior (filename checks).
// Someday, it would be nice to perform some magic tests everywhere.
QFileInfo info(filename);
d->basefilename_ = info.fileName();
QString suffix = info.suffix().toLower();
@ -888,7 +888,8 @@ void Song::BindToQuery(QSqlQuery* query) const {
if (Application::kIsPortable &&
Utilities::UrlOnSameDriveAsClementine(d->url_)) {
query->bindValue(":filename",
Utilities::GetRelativePathToClementineBin(d->url_).toEncoded());
Utilities::
GetRelativePathToClementineBin(d->url_).toEncoded());
} else {
query->bindValue(":filename", d->url_.toEncoded());
}

View File

@ -475,7 +475,7 @@ QByteArray Sha256(const QByteArray& data) {
}
// File must not be open and will be closed afterwards!
QByteArray Sha1File(const QFile& file) {
QByteArray Sha1File(QFile& file) {
file.open(QIODevice::ReadOnly);
QCryptographicHash hash(QCryptographicHash::Sha1);
QByteArray data;

View File

@ -64,7 +64,7 @@ QByteArray HmacMd5(const QByteArray& key, const QByteArray& data);
QByteArray HmacSha256(const QByteArray& key, const QByteArray& data);
QByteArray HmacSha1(const QByteArray& key, const QByteArray& data);
QByteArray Sha256(const QByteArray& data);
QByteArray Sha1File(const QFile& file);
QByteArray Sha1File(QFile& file);
QByteArray Sha1CoverHash(const QString& artist, const QString& album);
// Picks an unused ephemeral port number. Doesn't hold the port open so