Const orgies.

This commit is contained in:
Martin Rotter 2016-01-14 13:17:49 +01:00
parent 42b44043df
commit e3c28f4681
21 changed files with 191 additions and 131 deletions

View file

@ -38,7 +38,7 @@ FormDatabaseCleanup::FormDatabaseCleanup(QWidget *parent) : QDialog(parent), m_u
} }
FormDatabaseCleanup::~FormDatabaseCleanup() { FormDatabaseCleanup::~FormDatabaseCleanup() {
qDebug("Destroying FormDatabaseCleanup instance."); qDebug("Destroying FormDatabaseCleanup instance.");
} }
void FormDatabaseCleanup::setCleaner(DatabaseCleaner *cleaner) { void FormDatabaseCleanup::setCleaner(DatabaseCleaner *cleaner) {
@ -119,15 +119,13 @@ void FormDatabaseCleanup::onPurgeFinished(bool finished) {
} }
void FormDatabaseCleanup::loadDatabaseInfo() { void FormDatabaseCleanup::loadDatabaseInfo() {
qint64 db_size = qApp->database()->getDatabaseSize(); qint64 file_size = qApp->database()->getDatabaseFileSize();
qint64 data_size = qApp->database()->getDatabaseDataSize();
if (db_size > 0) { QString file_size_str = file_size > 0 ? QString::number(file_size / 1000000.0) + QL1S(" MB") : tr("unknown");
m_ui->m_txtFileSize->setText(QString::number(db_size / 1000000.0) + QL1S(" MB")); QString data_size_str = data_size > 0 ? QString::number(data_size / 1000000.0) + QL1S(" MB") : tr("unknown");
}
else {
m_ui->m_txtFileSize->setText(QSL("-"));
}
m_ui->m_txtFileSize->setText(tr("file: %1, data: %2").arg(file_size_str, data_size_str));
m_ui->m_txtDatabaseType->setText(qApp->database()->humanDriverName(qApp->database()->activeDatabaseDriver())); m_ui->m_txtDatabaseType->setText(qApp->database()->humanDriverName(qApp->database()->activeDatabaseDriver()));
m_ui->m_checkShrink->setEnabled(qApp->database()->activeDatabaseDriver() == DatabaseFactory::SQLITE || m_ui->m_checkShrink->setEnabled(qApp->database()->activeDatabaseDriver() == DatabaseFactory::SQLITE ||
qApp->database()->activeDatabaseDriver() == DatabaseFactory::SQLITE_MEMORY); qApp->database()->activeDatabaseDriver() == DatabaseFactory::SQLITE_MEMORY);

View file

@ -50,7 +50,7 @@ Application::Application(const QString &id, int &argc, char **argv)
} }
Application::~Application() { Application::~Application() {
delete m_updateFeedsLock; qDebug("Destroying Application instance.");
qDeleteAll(m_feedServices); qDeleteAll(m_feedServices);
} }
@ -108,11 +108,13 @@ DownloadManager *Application::downloadManager() {
} }
Mutex *Application::feedUpdateLock() { Mutex *Application::feedUpdateLock() {
if (m_updateFeedsLock == NULL) { if (m_updateFeedsLock.isNull()) {
m_updateFeedsLock = new Mutex(); // NOTE: Cannot use parent hierarchy because this method can be usually called
// from any thread.
m_updateFeedsLock.reset(new Mutex());
} }
return m_updateFeedsLock; return m_updateFeedsLock.data();
} }
void Application::backupDatabaseSettings(bool backup_database, bool backup_settings, void Application::backupDatabaseSettings(bool backup_database, bool backup_settings,
@ -261,7 +263,7 @@ void Application::onAboutToQuit() {
eliminateFirstRun(APP_VERSION); eliminateFirstRun(APP_VERSION);
// Make sure that we obtain close lock BEFORE even trying to quit the application. // Make sure that we obtain close lock BEFORE even trying to quit the application.
bool locked_safely = feedUpdateLock()->tryLock(4 * CLOSE_LOCK_TIMEOUT); const bool locked_safely = feedUpdateLock()->tryLock(4 * CLOSE_LOCK_TIMEOUT);
processEvents(); processEvents();

View file

@ -195,7 +195,7 @@ class Application : public QtSingleApplication {
// But of user decides to close the application (in other words, // But of user decides to close the application (in other words,
// tries to lock the lock for writing), then no other // tries to lock the lock for writing), then no other
// action will be allowed to lock for reading. // action will be allowed to lock for reading.
Mutex *m_updateFeedsLock; QScopedPointer<Mutex> m_updateFeedsLock;
QList<ServiceEntryPoint*> m_feedServices; QList<ServiceEntryPoint*> m_feedServices;
QList<QAction*> m_userActions; QList<QAction*> m_userActions;
FormMain *m_mainForm; FormMain *m_mainForm;

View file

@ -24,7 +24,6 @@
class AutoSaver : public QObject{ class AutoSaver : public QObject{
Q_OBJECT Q_OBJECT
public: public:

View file

@ -39,7 +39,7 @@ void DatabaseCleaner::purgeDatabaseData(const CleanerOrders &which_data) {
emit purgeStarted(); emit purgeStarted();
bool result = true; bool result = true;
int difference = 99 / 8; const int difference = 99 / 8;
int progress = 0; int progress = 0;
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
@ -118,7 +118,7 @@ bool DatabaseCleaner::purgeReadMessages(const QSqlDatabase &database) {
bool DatabaseCleaner::purgeOldMessages(const QSqlDatabase &database, int days) { bool DatabaseCleaner::purgeOldMessages(const QSqlDatabase &database, int days) {
QSqlQuery query = QSqlQuery(database); QSqlQuery query = QSqlQuery(database);
qint64 since_epoch = QDateTime::currentDateTimeUtc().addDays(-days).toMSecsSinceEpoch(); const qint64 since_epoch = QDateTime::currentDateTimeUtc().addDays(-days).toMSecsSinceEpoch();
query.setForwardOnly(true); query.setForwardOnly(true);
query.prepare(QSL("DELETE FROM Messages WHERE is_important = :is_important AND date_created < :date_created;")); query.prepare(QSL("DELETE FROM Messages WHERE is_important = :is_important AND date_created < :date_created;"));

View file

@ -39,7 +39,7 @@ DatabaseFactory::DatabaseFactory(QObject *parent)
DatabaseFactory::~DatabaseFactory() { DatabaseFactory::~DatabaseFactory() {
} }
qint64 DatabaseFactory::getDatabaseSize() { qint64 DatabaseFactory::getDatabaseFileSize() const {
if (m_activeDatabaseDriver == SQLITE || m_activeDatabaseDriver == SQLITE_MEMORY) { if (m_activeDatabaseDriver == SQLITE || m_activeDatabaseDriver == SQLITE_MEMORY) {
return QFileInfo(sqliteDatabaseFilePath()).size(); return QFileInfo(sqliteDatabaseFilePath()).size();
} }
@ -48,6 +48,53 @@ qint64 DatabaseFactory::getDatabaseSize() {
} }
} }
qint64 DatabaseFactory::getDatabaseDataSize() const {
if (m_activeDatabaseDriver == SQLITE || m_activeDatabaseDriver == SQLITE_MEMORY) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
qint64 result = 1;
QSqlQuery query(database);
if (query.exec(QSL("PRAGMA page_count;"))) {
query.next();
result *= query.value(0).value<qint64>();
}
else {
return 0;
}
if (query.exec(QSL("PRAGMA page_size;"))) {
query.next();
result *= query.value(0).value<qint64>();
}
else {
return 0;
}
return result;
}
else if (m_activeDatabaseDriver == MYSQL) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
qint64 result = 1;
QSqlQuery query(database);
if (query.exec("SELECT Round(Sum(data_length + index_length), 1) "
"FROM information_schema.tables "
"GROUP BY table_schema;")) {
while (query.next()) {
result *= query.value(0).value<qint64>();
}
return result;
}
else {
return 0;
}
}
else {
return 0;
}
}
DatabaseFactory::MySQLError DatabaseFactory::mysqlTestConnection(const QString &hostname, int port, const QString &w_database, DatabaseFactory::MySQLError DatabaseFactory::mysqlTestConnection(const QString &hostname, int port, const QString &w_database,
const QString &username, const QString &password) { const QString &username, const QString &password) {
QSqlDatabase database = QSqlDatabase::addDatabase(APP_DB_MYSQL_DRIVER, APP_DB_MYSQL_TEST); QSqlDatabase database = QSqlDatabase::addDatabase(APP_DB_MYSQL_DRIVER, APP_DB_MYSQL_TEST);
@ -64,14 +111,12 @@ DatabaseFactory::MySQLError DatabaseFactory::mysqlTestConnection(const QString &
return MySQLOk; return MySQLOk;
} }
else { else {
// Connection failed, do cleanup and return specific // Connection failed, do cleanup and return specific error code.
// error code. return static_cast<MySQLError>(database.lastError().number());
MySQLError error_code = static_cast<MySQLError>(database.lastError().number());
return error_code;
} }
} }
QString DatabaseFactory::mysqlInterpretErrorCode(MySQLError error_code) { QString DatabaseFactory::mysqlInterpretErrorCode(MySQLError error_code) const {
switch (error_code) { switch (error_code) {
case MySQLOk: case MySQLOk:
return tr("MySQL server works as expected."); return tr("MySQL server works as expected.");
@ -112,7 +157,7 @@ void DatabaseFactory::finishRestoration() {
return; return;
} }
QString backup_database_file = m_sqliteDatabaseFilePath + QDir::separator() + BACKUP_NAME_DATABASE + BACKUP_SUFFIX_DATABASE; const QString backup_database_file = m_sqliteDatabaseFilePath + QDir::separator() + BACKUP_NAME_DATABASE + BACKUP_SUFFIX_DATABASE;
if (QFile::exists(backup_database_file)) { if (QFile::exists(backup_database_file)) {
qWarning("Backup database file '%s' was detected. Restoring it.", qPrintable(QDir::toNativeSeparators(backup_database_file))); qWarning("Backup database file '%s' was detected. Restoring it.", qPrintable(QDir::toNativeSeparators(backup_database_file)));
@ -173,7 +218,7 @@ QSqlDatabase DatabaseFactory::sqliteInitializeInMemoryDatabase() {
qPrintable(APP_MISC_PATH)); qPrintable(APP_MISC_PATH));
} }
QStringList statements = QString(file_init.readAll()).split(APP_DB_COMMENT_SPLIT, QString::SkipEmptyParts); const QStringList statements = QString(file_init.readAll()).split(APP_DB_COMMENT_SPLIT, QString::SkipEmptyParts);
database.transaction(); database.transaction();
foreach(const QString &statement, statements) { foreach(const QString &statement, statements) {
@ -203,8 +248,16 @@ QSqlDatabase DatabaseFactory::sqliteInitializeInMemoryDatabase() {
// Copy all stuff. // Copy all stuff.
// WARNING: All tables belong here. // WARNING: All tables belong here.
QStringList tables; tables << QSL("Information") << QSL("Categories") << QSL("Feeds") << QStringList tables;
QSL("Accounts") << QSL("TtRssAccounts") << QSL("Messages");
if (copy_contents.exec(QSL("SELECT name FROM storage.sqlite_master WHERE type='table';"))) {
while (copy_contents.next()) {
tables.append(copy_contents.value(0).toString());
}
}
else {
qFatal("Cannot obtain list of table names from file-base SQLite database.");
}
foreach (const QString &table, tables) { foreach (const QString &table, tables) {
copy_contents.exec(QString("INSERT INTO main.%1 SELECT * FROM storage.%1;").arg(table)); copy_contents.exec(QString("INSERT INTO main.%1 SELECT * FROM storage.%1;").arg(table));
@ -229,7 +282,7 @@ QSqlDatabase DatabaseFactory::sqliteInitializeFileBasedDatabase(const QString &c
finishRestoration(); finishRestoration();
// Prepare file paths. // Prepare file paths.
QDir db_path(m_sqliteDatabaseFilePath); const QDir db_path(m_sqliteDatabaseFilePath);
QFile db_file(db_path.absoluteFilePath(APP_DB_SQLITE_FILE)); QFile db_file(db_path.absoluteFilePath(APP_DB_SQLITE_FILE));
// Check if database directory exists. // Check if database directory exists.
@ -278,7 +331,7 @@ QSqlDatabase DatabaseFactory::sqliteInitializeFileBasedDatabase(const QString &c
qPrintable(APP_MISC_PATH)); qPrintable(APP_MISC_PATH));
} }
QStringList statements = QString(file_init.readAll()).split(APP_DB_COMMENT_SPLIT, QString::SkipEmptyParts); const QStringList statements = QString(file_init.readAll()).split(APP_DB_COMMENT_SPLIT, QString::SkipEmptyParts);
database.transaction(); database.transaction();
foreach(const QString &statement, statements) { foreach(const QString &statement, statements) {
@ -296,7 +349,7 @@ QSqlDatabase DatabaseFactory::sqliteInitializeFileBasedDatabase(const QString &c
} }
else { else {
query_db.next(); query_db.next();
QString installed_db_schema = query_db.value(0).toString(); const QString installed_db_schema = query_db.value(0).toString();
query_db.finish(); query_db.finish();
if (installed_db_schema < APP_DB_SCHEMA_VERSION) { if (installed_db_schema < APP_DB_SCHEMA_VERSION) {
@ -331,7 +384,7 @@ QString DatabaseFactory::sqliteDatabaseFilePath() const {
bool DatabaseFactory::sqliteUpdateDatabaseSchema(QSqlDatabase database, const QString &source_db_schema_version) { bool DatabaseFactory::sqliteUpdateDatabaseSchema(QSqlDatabase database, const QString &source_db_schema_version) {
int working_version = QString(source_db_schema_version).remove('.').toInt(); int working_version = QString(source_db_schema_version).remove('.').toInt();
int current_version = QString(APP_DB_SCHEMA_VERSION).remove('.').toInt(); const int current_version = QString(APP_DB_SCHEMA_VERSION).remove('.').toInt();
// Now, it would be good to create backup of SQLite DB file. // Now, it would be good to create backup of SQLite DB file.
if (IOFactory::copyFile(sqliteDatabaseFilePath(), sqliteDatabaseFilePath() + ".bak")) { if (IOFactory::copyFile(sqliteDatabaseFilePath(), sqliteDatabaseFilePath() + ".bak")) {
@ -342,10 +395,10 @@ bool DatabaseFactory::sqliteUpdateDatabaseSchema(QSqlDatabase database, const QS
} }
while (working_version != current_version) { while (working_version != current_version) {
QString update_file_name = QString(APP_MISC_PATH) + QDir::separator() + const QString update_file_name = QString(APP_MISC_PATH) + QDir::separator() +
QString(APP_DB_UPDATE_FILE_PATTERN).arg(QSL("sqlite"), QString(APP_DB_UPDATE_FILE_PATTERN).arg(QSL("sqlite"),
QString::number(working_version), QString::number(working_version),
QString::number(working_version + 1)); QString::number(working_version + 1));
if (!QFile::exists(update_file_name)) { if (!QFile::exists(update_file_name)) {
qFatal("Updating of database schema failed. File '%s' does not exist.", qPrintable(QDir::toNativeSeparators(update_file_name))); qFatal("Updating of database schema failed. File '%s' does not exist.", qPrintable(QDir::toNativeSeparators(update_file_name)));
@ -357,7 +410,7 @@ bool DatabaseFactory::sqliteUpdateDatabaseSchema(QSqlDatabase database, const QS
qFatal("Updating of database schema failed. File '%s' cannot be opened.", qPrintable(QDir::toNativeSeparators(update_file_name))); qFatal("Updating of database schema failed. File '%s' cannot be opened.", qPrintable(QDir::toNativeSeparators(update_file_name)));
} }
QStringList statements = QString(update_file_handle.readAll()).split(APP_DB_COMMENT_SPLIT, QString::SkipEmptyParts); const QStringList statements = QString(update_file_handle.readAll()).split(APP_DB_COMMENT_SPLIT, QString::SkipEmptyParts);
foreach (const QString &statement, statements) { foreach (const QString &statement, statements) {
QSqlQuery query = database.exec(statement); QSqlQuery query = database.exec(statement);
@ -377,13 +430,13 @@ bool DatabaseFactory::sqliteUpdateDatabaseSchema(QSqlDatabase database, const QS
bool DatabaseFactory::mysqlUpdateDatabaseSchema(QSqlDatabase database, const QString &source_db_schema_version) { bool DatabaseFactory::mysqlUpdateDatabaseSchema(QSqlDatabase database, const QString &source_db_schema_version) {
int working_version = QString(source_db_schema_version).remove('.').toInt(); int working_version = QString(source_db_schema_version).remove('.').toInt();
int current_version = QString(APP_DB_SCHEMA_VERSION).remove('.').toInt(); const int current_version = QString(APP_DB_SCHEMA_VERSION).remove('.').toInt();
while (working_version != current_version) { while (working_version != current_version) {
QString update_file_name = QString(APP_MISC_PATH) + QDir::separator() + const QString update_file_name = QString(APP_MISC_PATH) + QDir::separator() +
QString(APP_DB_UPDATE_FILE_PATTERN).arg(QSL("mysql"), QString(APP_DB_UPDATE_FILE_PATTERN).arg(QSL("mysql"),
QString::number(working_version), QString::number(working_version),
QString::number(working_version + 1)); QString::number(working_version + 1));
if (!QFile::exists(update_file_name)) { if (!QFile::exists(update_file_name)) {
qFatal("Updating of database schema failed. File '%s' does not exist.", qPrintable(QDir::toNativeSeparators(update_file_name))); qFatal("Updating of database schema failed. File '%s' does not exist.", qPrintable(QDir::toNativeSeparators(update_file_name)));
@ -425,7 +478,7 @@ QSqlDatabase DatabaseFactory::connection(const QString &connection_name, Desired
} }
} }
QString DatabaseFactory::humanDriverName(DatabaseFactory::UsedDriver driver) { QString DatabaseFactory::humanDriverName(DatabaseFactory::UsedDriver driver) const {
switch (driver) { switch (driver) {
case MYSQL: case MYSQL:
return tr("MySQL/MariaDB (dedicated database)"); return tr("MySQL/MariaDB (dedicated database)");
@ -437,7 +490,7 @@ QString DatabaseFactory::humanDriverName(DatabaseFactory::UsedDriver driver) {
} }
} }
QString DatabaseFactory::humanDriverName(const QString &driver_code) { QString DatabaseFactory::humanDriverName(const QString &driver_code) const {
if (driver_code == APP_DB_SQLITE_DRIVER) { if (driver_code == APP_DB_SQLITE_DRIVER) {
return humanDriverName(SQLITE); return humanDriverName(SQLITE);
} }
@ -466,8 +519,16 @@ void DatabaseFactory::sqliteSaveMemoryDatabase() {
// Copy all stuff. // Copy all stuff.
// WARNING: All tables belong here. // WARNING: All tables belong here.
QStringList tables; tables << QSL("Information") << QSL("Categories") << QSL("Feeds") << QStringList tables;
QSL("Accounts") << QSL("TtRssAccounts") << QSL("Messages");
if (copy_contents.exec(QSL("SELECT name FROM storage.sqlite_master WHERE type='table';"))) {
while (copy_contents.next()) {
tables.append(copy_contents.value(0).toString());
}
}
else {
qFatal("Cannot obtain list of table names from file-base SQLite database.");
}
foreach (const QString &table, tables) { foreach (const QString &table, tables) {
copy_contents.exec(QString(QSL("DELETE FROM storage.%1;")).arg(table)); copy_contents.exec(QString(QSL("DELETE FROM storage.%1;")).arg(table));
@ -480,7 +541,7 @@ void DatabaseFactory::sqliteSaveMemoryDatabase() {
} }
void DatabaseFactory::determineDriver() { void DatabaseFactory::determineDriver() {
QString db_driver = qApp->settings()->value(GROUP(Database), SETTING(Database::ActiveDriver)).toString(); const QString db_driver = qApp->settings()->value(GROUP(Database), SETTING(Database::ActiveDriver)).toString();
if (db_driver == APP_DB_MYSQL_DRIVER && QSqlDatabase::isDriverAvailable(APP_DB_SQLITE_DRIVER)) { if (db_driver == APP_DB_MYSQL_DRIVER && QSqlDatabase::isDriverAvailable(APP_DB_SQLITE_DRIVER)) {
// User wants to use MySQL and MySQL is actually available. Use it. // User wants to use MySQL and MySQL is actually available. Use it.
@ -556,7 +617,7 @@ QSqlDatabase DatabaseFactory::mysqlConnection(const QString &connection_name) {
QSqlDatabase DatabaseFactory::mysqlInitializeDatabase(const QString &connection_name) { QSqlDatabase DatabaseFactory::mysqlInitializeDatabase(const QString &connection_name) {
// Folders are created. Create new QSQLDatabase object. // Folders are created. Create new QSQLDatabase object.
QSqlDatabase database = QSqlDatabase::addDatabase(APP_DB_MYSQL_DRIVER, connection_name); QSqlDatabase database = QSqlDatabase::addDatabase(APP_DB_MYSQL_DRIVER, connection_name);
QString database_name = qApp->settings()->value(GROUP(Database), SETTING(Database::MySQLDatabase)).toString(); const QString database_name = qApp->settings()->value(GROUP(Database), SETTING(Database::MySQLDatabase)).toString();
database.setHostName(qApp->settings()->value(GROUP(Database), SETTING(Database::MySQLHostname)).toString()); database.setHostName(qApp->settings()->value(GROUP(Database), SETTING(Database::MySQLHostname)).toString());
database.setPort(qApp->settings()->value(GROUP(Database), SETTING(Database::MySQLPort)).toInt()); database.setPort(qApp->settings()->value(GROUP(Database), SETTING(Database::MySQLPort)).toInt());
@ -584,7 +645,7 @@ QSqlDatabase DatabaseFactory::mysqlInitializeDatabase(const QString &connection_
qPrintable(APP_MISC_PATH)); qPrintable(APP_MISC_PATH));
} }
QStringList statements = QString(file_init.readAll()).split(APP_DB_COMMENT_SPLIT, QString::SkipEmptyParts); const QStringList statements = QString(file_init.readAll()).split(APP_DB_COMMENT_SPLIT, QString::SkipEmptyParts);
database.transaction(); database.transaction();
foreach(QString statement, statements) { foreach(QString statement, statements) {
@ -604,7 +665,7 @@ QSqlDatabase DatabaseFactory::mysqlInitializeDatabase(const QString &connection_
// Database was previously initialized. Now just check the schema version. // Database was previously initialized. Now just check the schema version.
query_db.next(); query_db.next();
QString installed_db_schema = query_db.value(0).toString(); const QString installed_db_schema = query_db.value(0).toString();
if (installed_db_schema < APP_DB_SCHEMA_VERSION) { if (installed_db_schema < APP_DB_SCHEMA_VERSION) {
if (mysqlUpdateDatabaseSchema(database, installed_db_schema)) { if (mysqlUpdateDatabaseSchema(database, installed_db_schema)) {
@ -683,7 +744,7 @@ QSqlDatabase DatabaseFactory::sqliteConnection(const QString &connection_name, D
// yet, add it and set it up. // yet, add it and set it up.
database = QSqlDatabase::addDatabase(APP_DB_SQLITE_DRIVER, connection_name); database = QSqlDatabase::addDatabase(APP_DB_SQLITE_DRIVER, connection_name);
QDir db_path(m_sqliteDatabaseFilePath); const QDir db_path(m_sqliteDatabaseFilePath);
QFile db_file(db_path.absoluteFilePath(APP_DB_SQLITE_FILE)); QFile db_file(db_path.absoluteFilePath(APP_DB_SQLITE_FILE));
// Setup database file path. // Setup database file path.

View file

@ -61,15 +61,18 @@ class DatabaseFactory : public QObject {
virtual ~DatabaseFactory(); virtual ~DatabaseFactory();
// Returns size of DB file. // Returns size of DB file.
qint64 getDatabaseSize(); qint64 getDatabaseFileSize() const;
// Returns size of data contained in the DB file.
qint64 getDatabaseDataSize() const;
// If in-memory is true, then :memory: database is returned // If in-memory is true, then :memory: database is returned
// In-memory database is DEFAULT database. // In-memory database is DEFAULT database.
// NOTE: This always returns OPENED database. // NOTE: This always returns OPENED database.
QSqlDatabase connection(const QString &connection_name, DesiredType desired_type = FromSettings); QSqlDatabase connection(const QString &connection_name, DesiredType desired_type = FromSettings);
QString humanDriverName(UsedDriver driver); QString humanDriverName(UsedDriver driver) const;
QString humanDriverName(const QString &driver_code); QString humanDriverName(const QString &driver_code) const;
// Removes connection. // Removes connection.
void removeConnection(const QString &connection_name = QString()); void removeConnection(const QString &connection_name = QString());
@ -106,7 +109,7 @@ class DatabaseFactory : public QObject {
const QString &username, const QString &password); const QString &username, const QString &password);
// Interprets MySQL error code. // Interprets MySQL error code.
QString mysqlInterpretErrorCode(MySQLError error_code); QString mysqlInterpretErrorCode(MySQLError error_code) const;
private: private:
// //

View file

@ -74,8 +74,8 @@ void IconFactory::setCurrentIconTheme(const QString &theme_name) {
} }
void IconFactory::loadCurrentIconTheme() { void IconFactory::loadCurrentIconTheme() {
QStringList installed_themes = installedIconThemes(); const QStringList installed_themes = installedIconThemes();
QString theme_name_from_settings = qApp->settings()->value(GROUP(GUI), SETTING(GUI::IconTheme)).toString(); const QString theme_name_from_settings = qApp->settings()->value(GROUP(GUI), SETTING(GUI::IconTheme)).toString();
if (m_currentIconTheme == theme_name_from_settings) { if (m_currentIconTheme == theme_name_from_settings) {
qDebug("Icon theme '%s' already loaded.", qPrintable(theme_name_from_settings)); qDebug("Icon theme '%s' already loaded.", qPrintable(theme_name_from_settings));
@ -108,7 +108,7 @@ QStringList IconFactory::installedIconThemes() const {
icon_themes_paths.removeDuplicates(); icon_themes_paths.removeDuplicates();
foreach (const QString &icon_path, icon_themes_paths) { foreach (const QString &icon_path, icon_themes_paths) {
QDir icon_dir(icon_path); const QDir icon_dir(icon_path);
// Iterate all icon themes in this directory. // Iterate all icon themes in this directory.
foreach (const QString &icon_theme_path, icon_dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot | foreach (const QString &icon_theme_path, icon_dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot |

View file

@ -39,10 +39,10 @@ class IconFactory : public QObject {
// Destructor. // Destructor.
virtual ~IconFactory(); virtual ~IconFactory();
// Used to store/retrieve QIcons from/to database via Base64-encoded // Used to store/retrieve QIcons from/to Base64-encoded
// byte array. // byte array.
QIcon fromByteArray(QByteArray array); static QIcon fromByteArray(QByteArray array);
QByteArray toByteArray(const QIcon &icon); static QByteArray toByteArray(const QIcon &icon);
void clearCache(); void clearCache();

View file

@ -48,8 +48,8 @@ QString IOFactory::ensureUniqueFilename(const QString &name, const QString &appe
while (QFile::exists(tmp_filename)) { while (QFile::exists(tmp_filename)) {
tmp_filename = name; tmp_filename = name;
int index = tmp_filename.lastIndexOf(QL1C('.')); const int index = tmp_filename.lastIndexOf(QL1C('.'));
QString append_string = append_format.arg(i++); const QString append_string = append_format.arg(i++);
if (index < 0) { if (index < 0) {
tmp_filename.append(append_string); tmp_filename.append(append_string);

View file

@ -32,7 +32,7 @@ Localization::Localization(QObject *parent)
Localization::~Localization() { Localization::~Localization() {
} }
QString Localization::desiredLanguage() { QString Localization::desiredLanguage() const {
return qApp->settings()->value(GROUP(General), SETTING(General::Language)).toString(); return qApp->settings()->value(GROUP(General), SETTING(General::Language)).toString();
} }
@ -63,9 +63,9 @@ void Localization::loadActiveLanguage() {
QLocale::setDefault(m_loadedLocale); QLocale::setDefault(m_loadedLocale);
} }
QList<Language> Localization::installedLanguages() { QList<Language> Localization::installedLanguages() const {
QList<Language> languages; QList<Language> languages;
QDir file_dir(APP_LANG_PATH); const QDir file_dir(APP_LANG_PATH);
QTranslator translator; QTranslator translator;
// Iterate all found language files. // Iterate all found language files.

View file

@ -44,14 +44,14 @@ class Localization : public QObject {
// Returns code of language that should // Returns code of language that should
// be loaded according to settings. // be loaded according to settings.
QString desiredLanguage(); QString desiredLanguage() const;
// Loads currently active language. // Loads currently active language.
void loadActiveLanguage(); void loadActiveLanguage();
// Returns list of installed application localizations. // Returns list of installed application localizations.
// This list is used ie. in settings dialog. // This list is used ie. in settings dialog.
QList<Language> installedLanguages(); QList<Language> installedLanguages() const;
// Returns empty string or loaded language // Returns empty string or loaded language
// name if it is really loaded. // name if it is really loaded.

View file

@ -23,7 +23,6 @@ Mutex::Mutex(QMutex::RecursionMode mode, QObject *parent) : QObject(parent), m_m
Mutex::~Mutex() { Mutex::~Mutex() {
qDebug("Destroying Mutex instance."); qDebug("Destroying Mutex instance.");
delete m_mutex;
} }
void Mutex::lock() { void Mutex::lock() {

View file

@ -49,7 +49,7 @@ class Mutex : public QObject {
void unlocked(); void unlocked();
private: private:
QMutex *m_mutex; QScopedPointer<QMutex> m_mutex;
bool m_isLocked; bool m_isLocked;
}; };

View file

@ -319,8 +319,8 @@ bool Settings::initiateRestoration(const QString &settings_backup_file_path) {
} }
void Settings::finishRestoration(const QString &desired_settings_file_path) { void Settings::finishRestoration(const QString &desired_settings_file_path) {
QString backup_settings_file = QFileInfo(desired_settings_file_path).absolutePath() + QDir::separator() + const QString backup_settings_file = QFileInfo(desired_settings_file_path).absolutePath() + QDir::separator() +
BACKUP_NAME_SETTINGS + BACKUP_SUFFIX_SETTINGS; BACKUP_NAME_SETTINGS + BACKUP_SUFFIX_SETTINGS;
if (QFile::exists(backup_settings_file)) { if (QFile::exists(backup_settings_file)) {
qWarning("Backup settings file '%s' was detected. Restoring it.", qPrintable(QDir::toNativeSeparators(backup_settings_file))); qWarning("Backup settings file '%s' was detected. Restoring it.", qPrintable(QDir::toNativeSeparators(backup_settings_file)));
@ -341,7 +341,7 @@ Settings *Settings::setupSettings(QObject *parent) {
// If settings file exists (and is writable) in executable file working directory // If settings file exists (and is writable) in executable file working directory
// (in subdirectory APP_CFG_PATH), then use it (portable settings). // (in subdirectory APP_CFG_PATH), then use it (portable settings).
// Otherwise use settings file stored in home path. // Otherwise use settings file stored in home path.
SettingsProperties properties = determineProperties(); const SettingsProperties properties = determineProperties();
finishRestoration(properties.m_absoluteSettingsFileName); finishRestoration(properties.m_absoluteSettingsFileName);
@ -349,7 +349,7 @@ Settings *Settings::setupSettings(QObject *parent) {
new_settings = new Settings(properties.m_absoluteSettingsFileName, QSettings::IniFormat, properties.m_type, parent); new_settings = new Settings(properties.m_absoluteSettingsFileName, QSettings::IniFormat, properties.m_type, parent);
// Construct icon cache in the same path. // Construct icon cache in the same path.
QString web_path = properties.m_baseDirectory + QDir::separator() + QString(APP_DB_WEB_PATH); const QString web_path = properties.m_baseDirectory + QDir::separator() + QString(APP_DB_WEB_PATH);
QDir(web_path).mkpath(web_path); QDir(web_path).mkpath(web_path);
QWebSettings::setIconDatabasePath(web_path); QWebSettings::setIconDatabasePath(web_path);
@ -369,16 +369,16 @@ SettingsProperties Settings::determineProperties() {
properties.m_settingsSuffix = QDir::separator() + QString(APP_CFG_PATH) + QDir::separator() + QString(APP_CFG_FILE); properties.m_settingsSuffix = QDir::separator() + QString(APP_CFG_PATH) + QDir::separator() + QString(APP_CFG_FILE);
QString app_path = qApp->applicationDirPath(); const QString app_path = qApp->applicationDirPath();
QString home_path = qApp->homeFolderPath() + QDir::separator() + QString(APP_LOW_H_NAME); const QString home_path = qApp->homeFolderPath() + QDir::separator() + QString(APP_LOW_H_NAME);
QString home_path_file = home_path + properties.m_settingsSuffix; const QString home_path_file = home_path + properties.m_settingsSuffix;
bool portable_settings_available = QFileInfo(app_path).isWritable(); const bool portable_settings_available = QFileInfo(app_path).isWritable();
bool non_portable_settings_exist = QFile::exists(home_path_file); const bool non_portable_settings_exist = QFile::exists(home_path_file);
// We will use PORTABLE settings only and only if it is available and NON-PORTABLE // We will use PORTABLE settings only and only if it is available and NON-PORTABLE
// settings was not initialized before. // settings was not initialized before.
bool will_we_use_portable_settings = portable_settings_available && !non_portable_settings_exist; const bool will_we_use_portable_settings = portable_settings_available && !non_portable_settings_exist;
if (will_we_use_portable_settings) { if (will_we_use_portable_settings) {
properties.m_type = SettingsProperties::Portable; properties.m_type = SettingsProperties::Portable;

View file

@ -32,9 +32,9 @@ SkinFactory::~SkinFactory() {
} }
void SkinFactory::loadCurrentSkin() { void SkinFactory::loadCurrentSkin() {
QString skin_name_from_settings = selectedSkinName(); const QString skin_name_from_settings = selectedSkinName();
bool skin_parsed; bool skin_parsed;
Skin skin_data = skinInfo(skin_name_from_settings, &skin_parsed); const Skin skin_data = skinInfo(skin_name_from_settings, &skin_parsed);
if (skin_parsed) { if (skin_parsed) {
loadSkinFromData(skin_data); loadSkinFromData(skin_data);
@ -50,7 +50,7 @@ void SkinFactory::loadCurrentSkin() {
} }
bool SkinFactory::loadSkinFromData(const Skin &skin) { bool SkinFactory::loadSkinFromData(const Skin &skin) {
QStringList skin_parts = skin.m_baseName.split(QL1C('/'), QString::SkipEmptyParts); const QStringList skin_parts = skin.m_baseName.split(QL1C('/'), QString::SkipEmptyParts);
// Skin does not contain leading folder name or the actual skin file name. // Skin does not contain leading folder name or the actual skin file name.
if (skin_parts.size() != 2) { if (skin_parts.size() != 2) {
@ -64,7 +64,7 @@ bool SkinFactory::loadSkinFromData(const Skin &skin) {
} }
// Create needed variables and create QFile object representing skin contents. // Create needed variables and create QFile object representing skin contents.
QString skin_folder = skin_parts.at(0); const QString skin_folder = skin_parts.at(0);
// Here we use "/" instead of QDir::separator() because CSS2.1 url field // Here we use "/" instead of QDir::separator() because CSS2.1 url field
// accepts '/' as path elements separator. // accepts '/' as path elements separator.
@ -85,7 +85,7 @@ bool SkinFactory::loadSkinFromData(const Skin &skin) {
} }
if (!raw_data.isEmpty()) { if (!raw_data.isEmpty()) {
QString parsed_data = raw_data.replace(QSL("##"), APP_SKIN_PATH + QL1S("/") + skin_folder); const QString parsed_data = raw_data.replace(QSL("##"), APP_SKIN_PATH + QL1S("/") + skin_folder);
qApp->setStyleSheet(parsed_data); qApp->setStyleSheet(parsed_data);
} }
@ -96,11 +96,11 @@ void SkinFactory::setCurrentSkinName(const QString &skin_name) {
qApp->settings()->setValue(GROUP(GUI), GUI::Skin, skin_name); qApp->settings()->setValue(GROUP(GUI), GUI::Skin, skin_name);
} }
QString SkinFactory::selectedSkinName() { QString SkinFactory::selectedSkinName() const {
return qApp->settings()->value(GROUP(GUI), SETTING(GUI::Skin)).toString(); return qApp->settings()->value(GROUP(GUI), SETTING(GUI::Skin)).toString();
} }
Skin SkinFactory::skinInfo(const QString &skin_name, bool *ok) { Skin SkinFactory::skinInfo(const QString &skin_name, bool *ok) const {
Skin skin; Skin skin;
QString styles; QString styles;
QFile skin_file(APP_SKIN_PATH + QDir::separator() + skin_name); QFile skin_file(APP_SKIN_PATH + QDir::separator() + skin_name);
@ -114,7 +114,7 @@ Skin SkinFactory::skinInfo(const QString &skin_name, bool *ok) {
return skin; return skin;
} }
QDomNode skin_node = dokument.namedItem(QSL("skin")); const QDomNode skin_node = dokument.namedItem(QSL("skin"));
// Obtain visible skin name. // Obtain visible skin name.
skin.m_visibleName = skin_node.namedItem(QSL("name")).toElement().text(); skin.m_visibleName = skin_node.namedItem(QSL("name")).toElement().text();
@ -155,7 +155,7 @@ Skin SkinFactory::skinInfo(const QString &skin_name, bool *ok) {
skin_file.close(); skin_file.close();
skin_file.deleteLater(); skin_file.deleteLater();
if (ok) { if (ok != NULL) {
*ok = !skin.m_author.isEmpty() && !skin.m_version.isEmpty() && *ok = !skin.m_author.isEmpty() && !skin.m_version.isEmpty() &&
!skin.m_baseName.isEmpty() && !skin.m_email.isEmpty() && !skin.m_baseName.isEmpty() && !skin.m_email.isEmpty() &&
!skin.m_layoutMarkup.isEmpty(); !skin.m_layoutMarkup.isEmpty();
@ -164,23 +164,22 @@ Skin SkinFactory::skinInfo(const QString &skin_name, bool *ok) {
return skin; return skin;
} }
QList<Skin> SkinFactory::installedSkins() { QList<Skin> SkinFactory::installedSkins() const {
QList<Skin> skins; QList<Skin> skins;
bool skin_load_ok; bool skin_load_ok;
QStringList skin_directories = QDir(APP_SKIN_PATH).entryList(QDir::Dirs | const QStringList skin_directories = QDir(APP_SKIN_PATH).entryList(QDir::Dirs |
QDir::NoDotAndDotDot | QDir::NoDotAndDotDot |
QDir::NoSymLinks | QDir::NoSymLinks |
QDir::Readable); QDir::Readable);
foreach (const QString &base_directory, skin_directories) { foreach (const QString &base_directory, skin_directories) {
// Check skins installed in this base directory. // Check skins installed in this base directory.
QStringList skin_files = QDir(APP_SKIN_PATH + QDir::separator() + base_directory).entryList(QStringList() << QSL("*.xml"), const QStringList skin_files = QDir(APP_SKIN_PATH + QDir::separator() + base_directory).entryList(QStringList() << QSL("*.xml"),
QDir::Files | QDir::Readable | QDir::NoDotAndDotDot | QDir::NoSymLinks); QDir::Files | QDir::Readable | QDir::NoDotAndDotDot | QDir::NoSymLinks);
foreach (const QString &skin_file, skin_files) { foreach (const QString &skin_file, skin_files) {
// Check if skin file is valid and add it if it is valid. // Check if skin file is valid and add it if it is valid.
Skin skin_info = skinInfo(base_directory + QDir::separator() + skin_file, const Skin skin_info = skinInfo(base_directory + QDir::separator() + skin_file, &skin_load_ok);
&skin_load_ok);
if (skin_load_ok) { if (skin_load_ok) {
skins.append(skin_info); skins.append(skin_info);

View file

@ -58,13 +58,13 @@ class SkinFactory : public QObject {
// Returns the name of the skin, that should be activated // Returns the name of the skin, that should be activated
// after application restart. // after application restart.
QString selectedSkinName(); QString selectedSkinName() const;
// Gets skin about a particular skin. // Gets skin about a particular skin.
Skin skinInfo(const QString &skin_name, bool *ok = NULL); Skin skinInfo(const QString &skin_name, bool *ok = NULL) const;
// Returns list of installed skins. // Returns list of installed skins.
QList<Skin> installedSkins(); QList<Skin> installedSkins() const;
// Sets the desired skin as the active one if it exists. // Sets the desired skin as the active one if it exists.
void setCurrentSkinName(const QString &skin_name); void setCurrentSkinName(const QString &skin_name);

View file

@ -49,15 +49,15 @@ SystemFactory::SystemFactory(QObject *parent) : QObject(parent) {
SystemFactory::~SystemFactory() { SystemFactory::~SystemFactory() {
} }
SystemFactory::AutoStartStatus SystemFactory::getAutoStartStatus() { SystemFactory::AutoStartStatus SystemFactory::getAutoStartStatus() const {
// User registry way to auto-start the application on Windows. // User registry way to auto-start the application on Windows.
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
QSettings registry_key(QSL("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"), QSettings registry_key(QSL("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"),
QSettings::NativeFormat); QSettings::NativeFormat);
bool autostart_enabled = registry_key.value(QSL(APP_LOW_NAME), const bool autostart_enabled = registry_key.value(QSL(APP_LOW_NAME),
QString()).toString().replace(QL1C('\\'), QString()).toString().replace(QL1C('\\'),
QL1C('/')) == QL1C('/')) ==
Application::applicationFilePath(); Application::applicationFilePath();
if (autostart_enabled) { if (autostart_enabled) {
return SystemFactory::Enabled; return SystemFactory::Enabled;
@ -69,7 +69,7 @@ SystemFactory::AutoStartStatus SystemFactory::getAutoStartStatus() {
// Use proper freedesktop.org way to auto-start the application on Linux. // Use proper freedesktop.org way to auto-start the application on Linux.
// INFO: http://standards.freedesktop.org/autostart-spec/latest/ // INFO: http://standards.freedesktop.org/autostart-spec/latest/
#elif defined(Q_OS_LINUX) #elif defined(Q_OS_LINUX)
QString desktop_file_location = SystemFactory::getAutostartDesktopFileLocation(); const QString desktop_file_location = SystemFactory::getAutostartDesktopFileLocation();
// No correct path was found. // No correct path was found.
if (desktop_file_location.isEmpty()) { if (desktop_file_location.isEmpty()) {
@ -93,7 +93,7 @@ SystemFactory::AutoStartStatus SystemFactory::getAutoStartStatus() {
#if defined(Q_OS_LINUX) #if defined(Q_OS_LINUX)
QString SystemFactory::getAutostartDesktopFileLocation() { QString SystemFactory::getAutostartDesktopFileLocation() {
QString xdg_config_path(qgetenv("XDG_CONFIG_HOME")); const QString xdg_config_path(qgetenv("XDG_CONFIG_HOME"));
QString desktop_file_location; QString desktop_file_location;
if (!xdg_config_path.isEmpty()) { if (!xdg_config_path.isEmpty()) {
@ -103,7 +103,8 @@ QString SystemFactory::getAutostartDesktopFileLocation() {
} }
else { else {
// Desired variable is not set, look for the default 'autostart' subdirectory. // Desired variable is not set, look for the default 'autostart' subdirectory.
QString home_directory(qgetenv("HOME")); const QString home_directory(qgetenv("HOME"));
if (!home_directory.isEmpty()) { if (!home_directory.isEmpty()) {
// Home directory exists. Check if target .desktop file exists and // Home directory exists. Check if target .desktop file exists and
// return according status. // return according status.
@ -117,7 +118,7 @@ QString SystemFactory::getAutostartDesktopFileLocation() {
#endif #endif
bool SystemFactory::setAutoStartStatus(const AutoStartStatus &new_status) { bool SystemFactory::setAutoStartStatus(const AutoStartStatus &new_status) {
SystemFactory::AutoStartStatus current_status = SystemFactory::getAutoStartStatus(); const SystemFactory::AutoStartStatus current_status = SystemFactory::getAutoStartStatus();
// Auto-start feature is not even available, exit. // Auto-start feature is not even available, exit.
if (current_status == SystemFactory::Unavailable) { if (current_status == SystemFactory::Unavailable) {
@ -126,14 +127,17 @@ bool SystemFactory::setAutoStartStatus(const AutoStartStatus &new_status) {
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
QSettings registry_key(QSL("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"), QSettings::NativeFormat); QSettings registry_key(QSL("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"), QSettings::NativeFormat);
switch (new_status) { switch (new_status) {
case SystemFactory::Enabled: case SystemFactory::Enabled:
registry_key.setValue(APP_LOW_NAME, registry_key.setValue(APP_LOW_NAME,
Application::applicationFilePath().replace(QL1C('/'), QL1C('\\'))); Application::applicationFilePath().replace(QL1C('/'), QL1C('\\')));
return true; return true;
case SystemFactory::Disabled: case SystemFactory::Disabled:
registry_key.remove(APP_LOW_NAME); registry_key.remove(APP_LOW_NAME);
return true; return true;
default: default:
return false; return false;
} }
@ -142,12 +146,13 @@ bool SystemFactory::setAutoStartStatus(const AutoStartStatus &new_status) {
// "rssguard.desktop" desktop file. // "rssguard.desktop" desktop file.
switch (new_status) { switch (new_status) {
case SystemFactory::Enabled: case SystemFactory::Enabled:
QFile::link(QString(APP_DESKTOP_ENTRY_PATH) + '/' + APP_DESKTOP_ENTRY_FILE, QFile::link(QString(APP_DESKTOP_ENTRY_PATH) + '/' + APP_DESKTOP_ENTRY_FILE, getAutostartDesktopFileLocation());
getAutostartDesktopFileLocation());
return true; return true;
case SystemFactory::Disabled: case SystemFactory::Disabled:
QFile::remove(getAutostartDesktopFileLocation()); QFile::remove(getAutostartDesktopFileLocation());
return true; return true;
default: default:
return false; return false;
} }
@ -186,7 +191,7 @@ QString SystemFactory::getUsername() const {
return name; return name;
} }
QPair<UpdateInfo, QNetworkReply::NetworkError> SystemFactory::checkForUpdates() { QPair<UpdateInfo, QNetworkReply::NetworkError> SystemFactory::checkForUpdates() const {
QPair<UpdateInfo, QNetworkReply::NetworkError> result; QPair<UpdateInfo, QNetworkReply::NetworkError> result;
QByteArray releases_xml; QByteArray releases_xml;
QByteArray changelog; QByteArray changelog;
@ -206,8 +211,8 @@ bool SystemFactory::isUpdateNewer(const QString &update_version) {
QStringList new_version_tkn = update_version.split(QL1C('.')); QStringList new_version_tkn = update_version.split(QL1C('.'));
while (!current_version_tkn.isEmpty() && !new_version_tkn.isEmpty()) { while (!current_version_tkn.isEmpty() && !new_version_tkn.isEmpty()) {
int current_number = current_version_tkn.takeFirst().toInt(); const int current_number = current_version_tkn.takeFirst().toInt();
int new_number = new_version_tkn.takeFirst().toInt(); const int new_number = new_version_tkn.takeFirst().toInt();
if (new_number > current_number) { if (new_number > current_number) {
// New version is indeed higher thatn current version. // New version is indeed higher thatn current version.
@ -233,10 +238,10 @@ bool SystemFactory::isUpdateNewer(const QString &update_version) {
} }
} }
UpdateInfo SystemFactory::parseUpdatesFile(const QByteArray &updates_file, const QByteArray &changelog) { UpdateInfo SystemFactory::parseUpdatesFile(const QByteArray &updates_file, const QByteArray &changelog) const {
UpdateInfo update; UpdateInfo update;
QDomDocument document; document.setContent(updates_file, false); QDomDocument document; document.setContent(updates_file, false);
QDomNodeList releases = document.elementsByTagName(QSL("release")); const QDomNodeList releases = document.elementsByTagName(QSL("release"));
if (releases.size() == 1) { if (releases.size() == 1) {
QDomElement rel_elem = releases.at(0).toElement(); QDomElement rel_elem = releases.at(0).toElement();
@ -266,7 +271,7 @@ UpdateInfo SystemFactory::parseUpdatesFile(const QByteArray &updates_file, const
} }
void SystemFactory::checkForUpdatesOnStartup() { void SystemFactory::checkForUpdatesOnStartup() {
UpdateCheck updates = checkForUpdates(); const UpdateCheck updates = checkForUpdates();
if (updates.second == QNetworkReply::NoError && isUpdateNewer(updates.first.m_availableVersion)) { if (updates.second == QNetworkReply::NoError && isUpdateNewer(updates.first.m_availableVersion)) {
qApp->showGuiMessage(tr("New version available"), qApp->showGuiMessage(tr("New version available"),

View file

@ -63,7 +63,7 @@ class SystemFactory : public QObject {
virtual ~SystemFactory(); virtual ~SystemFactory();
// Returns current status of auto-start function. // Returns current status of auto-start function.
SystemFactory::AutoStartStatus getAutoStartStatus(); SystemFactory::AutoStartStatus getAutoStartStatus() const;
// Sets new status for auto-start function. // Sets new status for auto-start function.
// Function returns false if setting of // Function returns false if setting of
@ -84,13 +84,7 @@ class SystemFactory : public QObject {
QString getUsername() const; QString getUsername() const;
// Tries to download list with new updates. // Tries to download list with new updates.
QPair<UpdateInfo, QNetworkReply::NetworkError> checkForUpdates(); QPair<UpdateInfo, QNetworkReply::NetworkError> checkForUpdates() const;
// Check whether given pointer belongs to instance of given class or not.
template<typename Base, typename T>
static bool isInstanceOf(T *ptr) {
return dynamic_cast<Base*>(ptr) != NULL;
}
// Checks if update is newer than current application version. // Checks if update is newer than current application version.
static bool isUpdateNewer(const QString &update_version); static bool isUpdateNewer(const QString &update_version);
@ -100,7 +94,7 @@ class SystemFactory : public QObject {
private: private:
// Performs parsing of downloaded file with list of updates. // Performs parsing of downloaded file with list of updates.
UpdateInfo parseUpdatesFile(const QByteArray &updates_file, const QByteArray &changelog); UpdateInfo parseUpdatesFile(const QByteArray &updates_file, const QByteArray &changelog) const;
}; };
#endif // SYSTEMFACTORY_H #endif // SYSTEMFACTORY_H

View file

@ -35,12 +35,12 @@ TextFactory::TextFactory() {
} }
int TextFactory::stringHeight(const QString &string, const QFontMetrics &metrics) { int TextFactory::stringHeight(const QString &string, const QFontMetrics &metrics) {
int count_lines = string.split(QL1C('\n')).size(); const int count_lines = string.split(QL1C('\n')).size();
return metrics.height() * count_lines; return metrics.height() * count_lines;
} }
int TextFactory::stringWidth(const QString &string, const QFontMetrics &metrics) { int TextFactory::stringWidth(const QString &string, const QFontMetrics &metrics) {
QStringList lines = string.split(QL1C('\n')); const QStringList lines = string.split(QL1C('\n'));
int width = 0; int width = 0;
foreach (const QString &line, lines) { foreach (const QString &line, lines) {
@ -55,10 +55,10 @@ int TextFactory::stringWidth(const QString &string, const QFontMetrics &metrics)
} }
QDateTime TextFactory::parseDateTime(const QString &date_time) { QDateTime TextFactory::parseDateTime(const QString &date_time) {
QString input_date = date_time.simplified(); const QString input_date = date_time.simplified();
QDateTime dt; QDateTime dt;
QTime time_zone_offset; QTime time_zone_offset;
QLocale locale(QLocale::C); const QLocale locale(QLocale::C);
bool positive_time_zone_offset = false; bool positive_time_zone_offset = false;
QStringList date_patterns; date_patterns << QSL("yyyy-MM-ddTHH:mm:ss") << QSL("MMM dd yyyy hh:mm:ss") << QStringList date_patterns; date_patterns << QSL("yyyy-MM-ddTHH:mm:ss") << QSL("MMM dd yyyy hh:mm:ss") <<

View file

@ -27,7 +27,7 @@
class TextFactory { class TextFactory {
private: private:
// Constructors and destructors. // Constructors and destructors.
explicit TextFactory(); TextFactory();
public: public:
// Returns true if lhs is smaller than rhs if case-insensitive string comparison is used. // Returns true if lhs is smaller than rhs if case-insensitive string comparison is used.