fix warnings, update clang file

This commit is contained in:
Martin Rotter 2022-04-09 09:35:55 +02:00
parent 3beb4a6c08
commit ad4ffddf8d
5 changed files with 195 additions and 209 deletions

View file

@ -16,8 +16,8 @@ AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortFunctionsOnASingleLine: Empty
AllowShortLambdasOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
@ -40,16 +40,16 @@ BraceWrapping:
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeElse: true
BeforeLambdaBody: false
BeforeWhile: false
BeforeWhile: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: true
BreakBeforeBraces: Attach
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
@ -59,7 +59,7 @@ BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
QualifierAlignment: Leave
QualifierAlignment: Left
CompactNamespaces: false
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
@ -97,7 +97,7 @@ IncludeCategories:
CaseSensitive: false
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentAccessModifiers: true
IndentCaseLabels: false
IndentCaseBlocks: false
IndentGotoLabels: true
@ -114,7 +114,7 @@ LambdaBodyIndentation: Signature
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
NamespaceIndentation: All
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
@ -130,7 +130,7 @@ PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PenaltyIndentedWhitespace: 0
PointerAlignment: Right
PointerAlignment: Left
PPIndentWidth: -1
ReferenceAlignment: Pointer
ReflowComments: true

View file

@ -24,13 +24,11 @@
using RootItemPtr = RootItem*;
FeedsModel::FeedsModel(QObject* parent) : QAbstractItemModel(parent), m_rootItem(new RootItem())
{
FeedsModel::FeedsModel(QObject* parent) : QAbstractItemModel(parent), m_rootItem(new RootItem()) {
setObjectName(QSL("FeedsModel"));
// Create root item.
// : Name of root item of feed list which can be seen in feed add/edit dialog.
m_rootItem->setTitle(tr("Root"));
m_rootItem->setIcon(qApp->icons()->fromTheme(QSL("folder")));
@ -40,8 +38,7 @@ FeedsModel::FeedsModel(QObject* parent) : QAbstractItemModel(parent), m_rootItem
// : Title text in the feed list header.
m_headerData << tr("Title");
m_tooltipData
<< /*: Feed list header "titles" column tooltip.*/ tr("Titles of feeds/categories.")
m_tooltipData << /*: Feed list header "titles" column tooltip.*/ tr("Titles of feeds/categories.")
<< /*: Feed list header "counts" column tooltip.*/ tr("Counts of unread/all mesages.");
setupFonts();
@ -78,8 +75,8 @@ QStringList FeedsModel::mimeTypes() const {
return QStringList() << QSL(MIME_TYPE_ITEM_POINTER);
}
bool FeedsModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row,
int column, const QModelIndex& parent) {
bool FeedsModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column,
const QModelIndex& parent) {
Q_UNUSED(row)
Q_UNUSED(column)
@ -99,7 +96,8 @@ bool FeedsModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int
QDataStream stream(&dragged_items_data, QIODevice::OpenModeFlag::ReadOnly);
while (!stream.atEnd()) {
quintptr pointer_to_item; stream >> pointer_to_item;
quintptr pointer_to_item;
stream >> pointer_to_item;
// We have item we want to drag, we also determine the target item.
auto* dragged_item = RootItemPtr(pointer_to_item);
@ -108,14 +106,15 @@ bool FeedsModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int
ServiceRoot* target_item_root = target_item->getParentServiceRoot();
if (dragged_item == target_item || dragged_item->parent() == target_item) {
qDebug("Dragged item is equal to target item or its parent is equal to target item. Cancelling drag-drop action.");
qDebug(
"Dragged item is equal to target item or its parent is equal to target item. Cancelling drag-drop action.");
return false;
}
if (dragged_item_root != target_item_root) {
// Transferring of items between different accounts is not possible.
qApp->showGuiMessage(Notification::Event::GeneralEvent, {
tr("Cannot perform drag & drop operation"),
qApp->showGuiMessage(Notification::Event::GeneralEvent,
{tr("Cannot perform drag & drop operation"),
tr("You can't transfer dragged item into different account, this is not supported."),
QSystemTrayIcon::MessageIcon::Critical});
qDebugNN << LOGSEC_FEEDMODEL
@ -385,9 +384,8 @@ QModelIndex FeedsModel::indexForItem(const RootItem* item) const {
while (!chain.isEmpty()) {
const RootItem* parent_item = chain.pop();
target_index = index(parent_item->parent()->childItems().indexOf(const_cast<RootItem* const>(parent_item)),
0,
target_index);
target_index =
index(parent_item->parent()->childItems().indexOf(const_cast<RootItem* const>(parent_item)), 0, target_index);
}
return target_index;
@ -428,16 +426,12 @@ void FeedsModel::notifyWithCounts() {
void FeedsModel::onItemDataChanged(const QList<RootItem*>& items) {
if (items.size() > RELOAD_MODEL_BORDER_NUM) {
qDebugNN << LOGSEC_FEEDMODEL
<< "There is request to reload feed model for more than "
<< RELOAD_MODEL_BORDER_NUM
qDebugNN << LOGSEC_FEEDMODEL << "There is request to reload feed model for more than " << RELOAD_MODEL_BORDER_NUM
<< " items, reloading model fully.";
reloadWholeLayout();
}
else {
qDebugNN << LOGSEC_FEEDMODEL
<< "There is request to reload feed model, reloading the "
<< items.size()
qDebugNN << LOGSEC_FEEDMODEL << "There is request to reload feed model, reloading the " << items.size()
<< " items individually.";
for (RootItem* item : items) {
@ -451,7 +445,8 @@ void FeedsModel::onItemDataChanged(const QList<RootItem*>& items) {
void FeedsModel::setupFonts() {
QFont fon;
fon.fromString(qApp->settings()->value(GROUP(Feeds), Feeds::ListFont, Application::font("FeedsView").toString()).toString());
fon.fromString(
qApp->settings()->value(GROUP(Feeds), Feeds::ListFont, Application::font("FeedsView").toString()).toString());
m_normalFont = fon;
@ -478,7 +473,8 @@ bool FeedsModel::addServiceAccount(ServiceRoot* root, bool freshly_activated) {
endInsertRows();
// Connect.
connect(root, &ServiceRoot::itemRemovalRequested, this, static_cast<void (FeedsModel::*)(RootItem*)>(&FeedsModel::removeItem));
connect(root, &ServiceRoot::itemRemovalRequested, this,
static_cast<void (FeedsModel::*)(RootItem*)>(&FeedsModel::removeItem));
connect(root, &ServiceRoot::itemReassignmentRequested, this, &FeedsModel::reassignNodeToNewParent);
connect(root, &ServiceRoot::dataChanged, this, &FeedsModel::onItemDataChanged);
connect(root, &ServiceRoot::reloadMessageListRequested, this, &FeedsModel::reloadMessageListRequested);
@ -579,9 +575,7 @@ QVariant FeedsModel::data(const QModelIndex& index, int role) const {
case Qt::ItemDataRole::FontRole: {
RootItem* it = itemForIndex(index);
bool is_bold = it->countOfUnreadMessages() > 0;
bool is_striked = it->kind() == RootItem::Kind::Feed
? qobject_cast<Feed*>(it)->isSwitchedOff()
: false;
bool is_striked = it->kind() == RootItem::Kind::Feed ? qobject_cast<Feed*>(it)->isSwitchedOff() : false;
if (is_bold) {
return is_striked ? m_boldStrikedFont : m_boldFont;
@ -597,6 +591,7 @@ QVariant FeedsModel::data(const QModelIndex& index, int role) const {
}
default:
return itemForIndex(index)->data(index.column(), role);;
return itemForIndex(index)->data(index.column(), role);
;
}
}

View file

@ -883,8 +883,7 @@ void Application::parseCmdArgumentsFromMyInstance(const QStringList &raw_cli_arg
QCommandLineOption version({QSL(CLI_VER_SHORT), QSL(CLI_VER_LONG)}, QSL("Displays version of the application."));
QCommandLineOption log_file(
{QSL(CLI_LOG_SHORT), QSL(CLI_LOG_LONG)},
QSL("Write application debug log to file. Note that logging to file may slow application down."),
QSL("log-file"));
QSL("Write application debug log to file. Note that logging to file may slow application down."), QSL("log-file"));
QCommandLineOption custom_data_folder(
{QSL(CLI_DAT_SHORT), QSL(CLI_DAT_LONG)},
QSL("Use custom folder for user data and disable single instance application mode."), QSL("user-data-folder"));

View file

@ -18,11 +18,11 @@
#include "miscellaneous/systemfactory.h"
#include "network-web/downloadmanager.h"
#include <functional>
#include <QCommandLineParser>
#include <QList>
#include <functional>
#if defined(qApp)
#undef qApp
#endif
@ -144,8 +144,8 @@ class RSSGUARD_DLLSPEC Application : public SingleApplication {
void setMainForm(FormMain* main_form);
void backupDatabaseSettings(bool backup_database, bool backup_settings,
const QString& target_path, const QString& backup_name);
void backupDatabaseSettings(bool backup_database, bool backup_settings, const QString& target_path,
const QString& backup_name);
void restoreDatabaseSettings(bool restore_database, bool restore_settings,
const QString& source_database_file_path = QString(),
const QString& source_settings_file_path = QString());
@ -155,11 +155,8 @@ class RSSGUARD_DLLSPEC Application : public SingleApplication {
// Displays given simple message in tray icon bubble or OSD
// or in message box if tray icon is disabled.
void showGuiMessage(Notification::Event event,
const GuiMessage& msg,
const GuiMessageDestination& dest = {},
const GuiAction& action = {},
QWidget* parent = nullptr);
void showGuiMessage(Notification::Event event, const GuiMessage& msg, const GuiMessageDestination& dest = {},
const GuiAction& action = {}, QWidget* parent = nullptr);
WebViewer* createWebView();
@ -174,7 +171,6 @@ class RSSGUARD_DLLSPEC Application : public SingleApplication {
static void performLogging(QtMsgType type, const QMessageLogContext& context, const QString& msg);
public slots:
// Restarts the application.
void restart();
@ -199,15 +195,15 @@ class RSSGUARD_DLLSPEC Application : public SingleApplication {
#endif
#endif
#if defined(Q_OS_WIN)
QImage generateOverlayIcon(int number) const;
#endif
void onFeedUpdatesStarted();
void onFeedUpdatesProgress(const Feed* feed, int current, int total);
void onFeedUpdatesFinished(const FeedDownloadResults& results);
private:
#if defined(Q_OS_WIN)
QImage generateOverlayIcon(int number) const;
#endif
void setupCustomDataFolder(const QString& data_folder);
void determineFirstRuns();
void eliminateFirstRuns();
@ -260,8 +256,6 @@ class RSSGUARD_DLLSPEC Application : public SingleApplication {
#endif
};
inline Application* Application::instance() {
return static_cast<Application*>(QCoreApplication::instance());
}
inline Application* Application::instance() { return static_cast<Application*>(QCoreApplication::instance()); }
#endif // APPLICATION_H

View file

@ -23,11 +23,9 @@
#include <QMimeData>
#include <QSettings>
DownloadItem::DownloadItem(QNetworkReply* reply,
const QString& preferred_file_name,
const std::function<void (DownloadItem*)>& run_on_finish,
QWidget* parent) : QWidget(parent),
m_ui(new Ui::DownloadItem), m_reply(reply), m_preferredFileName(preferred_file_name),
DownloadItem::DownloadItem(QNetworkReply* reply, const QString& preferred_file_name,
const std::function<void(DownloadItem*)>& run_on_finish, QWidget* parent)
: QWidget(parent), m_ui(new Ui::DownloadItem), m_reply(reply), m_preferredFileName(preferred_file_name),
m_runOnFinish(run_on_finish), m_bytesReceived(0), m_requestFileName(false), m_startedSaving(false),
m_finishedDownloading(false), m_gettingFileName(false), m_canceledFileSelect(false) {
m_ui->setupUi(this);
@ -68,7 +66,8 @@ void DownloadItem::init() {
#if QT_VERSION >= 0x050F00 // Qt >= 5.15.0
connect(m_reply, &QNetworkReply::errorOccurred, this, &DownloadItem::error);
#else
connect(m_reply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error), this, &DownloadItem::error);
connect(m_reply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error), this,
&DownloadItem::error);
#endif
connect(m_reply, &QNetworkReply::downloadProgress, this, &DownloadItem::downloadProgress);
@ -96,14 +95,15 @@ void DownloadItem::getFileName() {
const QString download_directory = qApp->downloadManager()->downloadDirectory();
QString chosen_filename = saveFileName(download_directory);
const QString filename_for_prompt = qApp->settings()->value(GROUP(Downloads), SETTING(Downloads::TargetExplicitDirectory)).toString() +
QDir::separator() +
QFileInfo(chosen_filename).fileName();
const QString filename_for_prompt =
qApp->settings()->value(GROUP(Downloads), SETTING(Downloads::TargetExplicitDirectory)).toString() +
QDir::separator() + QFileInfo(chosen_filename).fileName();
if (m_requestFileName) {
// User must provide the path where he wants to save downloaded file in.
m_gettingFileName = true;
chosen_filename = QFileDialog::getSaveFileName(this, tr("Select destination for downloaded file"), filename_for_prompt);
chosen_filename =
QFileDialog::getSaveFileName(this, tr("Select destination for downloaded file"), filename_for_prompt);
m_gettingFileName = false;
if (chosen_filename.isEmpty()) {
@ -166,7 +166,9 @@ QString DownloadItem::saveFileName(const QString& directory) const {
QString base_name = info.completeBaseName();
QString end_name = info.suffix();
if (base_name.isEmpty() || base_name.contains(QRegularExpression(QSL("\\/|<|\\?")))) {
static QRegularExpression reg(QSL("\\/|<|\\?"));
if (base_name.isEmpty() || base_name.contains(reg)) {
base_name = QSL("unnamed_download");
}
@ -188,8 +190,7 @@ QString DownloadItem::saveFileName(const QString& directory) const {
return name;
}
const QFile& DownloadItem::output() const
{
const QFile& DownloadItem::output() const {
return m_output;
}
@ -201,14 +202,14 @@ void DownloadItem::stop() {
m_ui->m_btnTryAgain->show();
setUpdatesEnabled(true);
m_reply->abort();
emit downloadFinished();
}
void DownloadItem::openFile() {
if (!QDesktopServices::openUrl(QUrl::fromLocalFile(m_output.fileName()))) {
qApp->showGuiMessage(Notification::Event::GeneralEvent, {
tr("Cannot open file"),
tr("Cannot open output file. Open it manually."),
qApp->showGuiMessage(Notification::Event::GeneralEvent,
{tr("Cannot open file"), tr("Cannot open output file. Open it manually."),
QSystemTrayIcon::MessageIcon::Warning});
}
}
@ -216,12 +217,8 @@ void DownloadItem::openFile() {
void DownloadItem::openFolder() {
if (m_output.exists()) {
if (!SystemFactory::openFolderFile(m_output.fileName())) {
MsgBox::show(this,
QMessageBox::Icon::Warning,
tr("Cannot open directory"),
tr("Cannot open output directory. Open it manually."),
QString(),
m_output.fileName());
MsgBox::show(this, QMessageBox::Icon::Warning, tr("Cannot open directory"),
tr("Cannot open output directory. Open it manually."), QString(), m_output.fileName());
}
}
}
@ -380,18 +377,18 @@ void DownloadItem::updateDownloadInfoLabel() {
remaining = DownloadManager::timeString(time_remaining);
}
info = QString(tr("%1 of %2 (%3 per second) - %4")).arg(DownloadManager::dataString(m_bytesReceived),
info = QString(tr("%1 of %2 (%3 per second) - %4"))
.arg(DownloadManager::dataString(m_bytesReceived),
bytes_total == 0 ? QSL("?") : DownloadManager::dataString(bytes_total),
DownloadManager::dataString((int)speed),
remaining);
DownloadManager::dataString((int)speed), remaining);
}
else {
if (m_bytesReceived == bytes_total) {
info = DownloadManager::dataString(m_output.size());
}
else {
info = tr("%1 of %2 - download completed").arg(DownloadManager::dataString(m_bytesReceived),
DownloadManager::dataString(m_bytesReceived));
info = tr("%1 of %2 - download completed")
.arg(DownloadManager::dataString(m_bytesReceived), DownloadManager::dataString(m_bytesReceived));
}
}
@ -430,14 +427,12 @@ void DownloadItem::finished() {
}
if (downloadedSuccessfully()) {
qApp->showGuiMessage(Notification::Event::GeneralEvent, {
tr("Download finished"),
tr("File '%1' is downloaded.\nClick here to open parent directory.").arg(QDir::toNativeSeparators(
m_output.fileName())),
qApp->showGuiMessage(Notification::Event::GeneralEvent,
{tr("Download finished"),
tr("File '%1' is downloaded.\nClick here to open parent directory.")
.arg(QDir::toNativeSeparators(m_output.fileName())),
QSystemTrayIcon::MessageIcon::Information},
{}, {
tr("Open folder"),
[this] {
{}, {tr("Open folder"), [this] {
openFolder();
}});
}
@ -448,9 +443,10 @@ void DownloadItem::updateInfoAndUrlLabel() {
m_ui->m_lblLocalFilename->setText(tr("Local file: %1").arg(QDir::toNativeSeparators(m_output.fileName())));
}
DownloadManager::DownloadManager(QWidget* parent) : TabContent(parent), m_ui(new Ui::DownloadManager),
m_autoSaver(new AutoSaver(this)), m_model(new DownloadModel(this)),
m_networkManager(new SilentNetworkAccessManager(this)), m_iconProvider(nullptr), m_removePolicy(RemovePolicy::Never) {
DownloadManager::DownloadManager(QWidget* parent)
: TabContent(parent), m_ui(new Ui::DownloadManager), m_autoSaver(new AutoSaver(this)),
m_model(new DownloadModel(this)), m_networkManager(new SilentNetworkAccessManager(this)), m_iconProvider(nullptr),
m_removePolicy(RemovePolicy::Never) {
m_ui->setupUi(this);
m_ui->m_viewDownloads->setShowGrid(false);
m_ui->m_viewDownloads->verticalHeader()->hide();
@ -503,8 +499,7 @@ int DownloadManager::downloadProgress() const {
}
}
void DownloadManager::download(const QNetworkRequest& request,
const QString& preferred_file_name,
void DownloadManager::download(const QNetworkRequest& request, const QString& preferred_file_name,
const std::function<void(DownloadItem*)>& run_on_finish) {
if (!request.url().isEmpty()) {
handleUnsupportedContent(m_networkManager->get(request), preferred_file_name, run_on_finish);
@ -515,8 +510,7 @@ void DownloadManager::download(const QUrl& url) {
download(QNetworkRequest(url));
}
void DownloadManager::handleUnsupportedContent(QNetworkReply* reply,
const QString& preferred_file_name,
void DownloadManager::handleUnsupportedContent(QNetworkReply* reply, const QString& preferred_file_name,
const std::function<void(DownloadItem*)>& run_on_finish) {
if (reply == nullptr || reply->url().isEmpty()) {
return;
@ -534,14 +528,15 @@ void DownloadManager::handleUnsupportedContent(QNetworkReply* reply,
addItem(item);
if (!item->m_canceledFileSelect && qApp->settings()->value(GROUP(Downloads),
SETTING(Downloads::ShowDownloadsWhenNewDownloadStarts)).toBool()) {
if (!item->m_canceledFileSelect &&
qApp->settings()->value(GROUP(Downloads), SETTING(Downloads::ShowDownloadsWhenNewDownloadStarts)).toBool()) {
qApp->mainForm()->tabWidget()->showDownloadManager();
}
}
void DownloadManager::addItem(DownloadItem* item) {
connect(item, &DownloadItem::statusChanged, this, static_cast<void (DownloadManager::*)()>(&DownloadManager::updateRow));
connect(item, &DownloadItem::statusChanged, this,
static_cast<void (DownloadManager::*)()>(&DownloadManager::updateRow));
connect(item, &DownloadItem::progress, this, &DownloadManager::itemProgress);
connect(item, &DownloadItem::downloadFinished, this, &DownloadManager::itemFinished);
@ -651,7 +646,8 @@ void DownloadManager::save() const {
// Save all download items.
for (int i = 0; i < m_downloads.count(); i++) {
settings->setValue(GROUP(Downloads), QString(Downloads::ItemUrl).arg(i), m_downloads[i]->m_url);
settings->setValue(GROUP(Downloads), QString(Downloads::ItemLocation).arg(i), QFileInfo(m_downloads[i]->m_output).filePath());
settings->setValue(GROUP(Downloads), QString(Downloads::ItemLocation).arg(i),
QFileInfo(m_downloads[i]->m_output).filePath());
settings->setValue(GROUP(Downloads), QString(Downloads::ItemDone).arg(i), m_downloads[i]->downloadedSuccessfully());
}
@ -671,7 +667,8 @@ void DownloadManager::load() {
int i = 0;
// Restore the policy.
m_removePolicy = static_cast<RemovePolicy>(settings->value(GROUP(Downloads), SETTING(Downloads::RemovePolicy)).toInt());
m_removePolicy =
static_cast<RemovePolicy>(settings->value(GROUP(Downloads), SETTING(Downloads::RemovePolicy)).toInt());
// Restore downloads.
while (settings->contains(GROUP(Downloads), QString(Downloads::ItemUrl).arg(i))) {
@ -829,7 +826,8 @@ QMimeData* DownloadModel::mimeData(const QModelIndexList& indexes) const {
continue;
}
urls.append(QUrl::fromLocalFile(QFileInfo(m_downloadManager->m_downloads.at(index.row())->m_output).absoluteFilePath()));
urls.append(
QUrl::fromLocalFile(QFileInfo(m_downloadManager->m_downloads.at(index.row())->m_output).absoluteFilePath()));
}
mimeData->setUrls(urls);