Commit 564bccf2 authored by Alexander Lohnau's avatar Alexander Lohnau 💬

Improve code quality and fix deprecation warnings

Discussion: !40
parents 6216091a fe971b9e
......@@ -51,7 +51,6 @@ private:
char m_algo[2], m_parms[2];
long long m_realsize;
int m_adate, m_cdate;
long long m_curpos;
};
#endif
......@@ -485,7 +485,7 @@ void kio_krarcProtocol::get(const QUrl &url, int tries)
QMimeDatabase db;
QMimeType mt = db.mimeTypeForFile(arcTempDir + file);
if (mt.isValid())
emit mimeType(mt.name());
mimeType(mt.name());
QString escapedFilename = file;
if(arcType == "zip") // left bracket needs to be escaped
......@@ -517,7 +517,7 @@ void kio_krarcProtocol::get(const QUrl &url, int tries)
return;
}
} else {
if (proc.exitStatus() != QProcess::NormalExit || !checkStatus(proc.exitCode()) || !QFileInfo(arcTempDir + file).exists()) {
if (proc.exitStatus() != QProcess::NormalExit || !checkStatus(proc.exitCode()) || !QFileInfo::exists(arcTempDir + file)) {
if (decompressToFile)
QFile(arcTempDir + file).remove();
if (encrypted && tries) {
......@@ -557,7 +557,7 @@ void kio_krarcProtocol::get(const QUrl &url, int tries)
QMimeDatabase db;
QMimeType mt = db.mimeTypeForFile(arcTempDir + file);
if (mt.isValid())
emit mimeType(mt.name());
mimeType(mt.name());
KIO::filesize_t processed_size = 0;
......@@ -688,7 +688,7 @@ void kio_krarcProtocol::stat(const QUrl &url)
path = getPath(newUrl);
}
// we might be stating a real file
if (QFileInfo(path).exists()) {
if (QFileInfo::exists(path)) {
QT_STATBUF buff;
QT_STAT(path.toLocal8Bit(), &buff);
QString mime;
......@@ -775,7 +775,7 @@ void kio_krarcProtocol::copy(const QUrl &url, const QUrl &dest, int, KIO::JobFla
error(KIO::ERR_CANNOT_WRITE, getPath(dest, QUrl::StripTrailingSlash) + "\n\n" + proc.getErrorMsg());
return;
}
if (!QFileInfo(getPath(dest, QUrl::StripTrailingSlash)).exists()) {
if (!QFileInfo::exists(getPath(dest, QUrl::StripTrailingSlash))) {
error(KIO::ERR_CANNOT_WRITE, getPath(dest, QUrl::StripTrailingSlash));
return;
}
......@@ -845,7 +845,7 @@ void kio_krarcProtocol::listDir(const QUrl &url)
if (path.right(1) != DIR_SEPARATOR) path = path + DIR_SEPARATOR;
// it might be a real dir !
if (QFileInfo(path).exists()) {
if (QFileInfo::exists(path)) {
if (QFileInfo(path).isDir()) {
QUrl redir;
redir.setPath(getPath(url));
......
......@@ -170,7 +170,7 @@ void UserActionListView::slotCurrentItemChanged(QTreeWidgetItem* item)
QDomDocument UserActionListView::dumpSelectedActions(QDomDocument* mergeDoc) const
{
QList<QTreeWidgetItem*> list = selectedItems();
const QList<QTreeWidgetItem*> list = selectedItems();
QDomDocument doc;
if (mergeDoc)
doc = *mergeDoc;
......@@ -188,7 +188,7 @@ QDomDocument UserActionListView::dumpSelectedActions(QDomDocument* mergeDoc) con
void UserActionListView::removeSelectedActions()
{
QList<QTreeWidgetItem*> list = selectedItems();
const QList<QTreeWidgetItem*> list = selectedItems();
for (auto item : list) {
if (auto* actionItem = dynamic_cast<UserActionListViewItem*>(item)) {
......
......@@ -487,13 +487,10 @@ void countFiles(const QString &path, unsigned long &totalFiles, bool &stop)
return;
}
for (const QString& name : dir.entryList()) {
for (const QString& name : dir.entryList(QDir::NoDotAndDotDot)) {
if (stop)
return;
if (name == QStringLiteral(".") || name == QStringLiteral(".."))
continue;
countFiles(dir.absoluteFilePath(name), totalFiles, stop);
}
}
......@@ -510,7 +507,7 @@ void AbstractJobThread::countLocalFiles(const QUrl &baseUrl, const QStringList &
return;
const QString path = calcSpaceFileSystem->getUrl(name).toLocalFile();
if (!QFileInfo(path).exists())
if (!QFileInfo::exists(path))
return;
countFiles(path, totalFiles, _exited);
......
......@@ -56,7 +56,7 @@ void Kr7zEncryptionChecker::receivedOutput()
if ((line.contains("password") && line.contains("enter")) ||
line == QStringLiteral("encrypted = +")) {
encrypted = true;
::kill(- pid(), SIGKILL); // kill the whole process group by giving the negative PID
::kill(- processId(), SIGKILL); // kill the whole process group by giving the negative PID
break;
}
}
......
......@@ -28,7 +28,6 @@
// QtWidgets
#include <QApplication>
#include <KArchive/KTar>
#include <KConfigCore/KSharedConfig>
#include <KI18n/KLocalizedString>
#include <KIO/Global>
......@@ -45,44 +44,6 @@
#include "../Dialogs/krpleasewait.h"
#include "../../krArc/krlinecountingprocess.h"
#if 0
class DefaultKrArcObserver : public KrArcObserver
{
public:
DefaultKrArcObserver() {}
virtual ~DefaultKrArcObserver() {}
virtual void processEvents() override {
usleep(1000);
qApp->processEvents();
}
virtual void subJobStarted(const QString & jobTitle, qulonglong count) override {
krApp->startWaiting(jobTitle, count, true);
}
virtual void subJobStopped() override {
krApp->stopWait();
}
virtual bool wasCancelled() override {
return krApp->wasWaitingCancelled();
}
virtual void error(const QString & error) override {
KMessageBox::error(krApp, error, i18n("Error"));
}
virtual void detailedError(const QString & error, const QString & details) override {
KMessageBox::detailedError(krApp, error, details, i18n("Error"));
}
virtual void incrementProgress(int c) override {
krApp->plzWait->incProgress(c);
}
};
#endif
static QStringList arcProtocols = QString("tar;bzip;bzip2;lzma;xz;gzip;krarc;zip").split(';');
QMap<QString, QString>* KrArcHandler::slaveMap = nullptr;
......@@ -124,7 +85,7 @@ KrArcHandler::KrArcHandler(QObject *parent) : QObject(parent)
QStringLiteral("application/vnd.rar") };
#ifdef KRARC_QUERY_ENABLED
auto mimetypes = KProtocolInfo::archiveMimetypes("krarc");
const auto mimetypes = KProtocolInfo::archiveMimetypes("krarc");
for (const auto &mimetype : mimetypes)
krarcArchiveMimetypes.insert(mimetype);
#endif
......
......@@ -599,7 +599,7 @@ bool KrBookmarkHandler::eventFilter(QObject *obj, QEvent *ev)
// such as Ctrl+W and accelerator keys
if (eventType == QEvent::KeyPress && menu) {
auto *kev = dynamic_cast<QKeyEvent *>(ev);
QList<QAction *> acts = menu->actions();
const QList<QAction *> acts = menu->actions();
bool quickSearchStarted = false;
bool searchInSpecialItems = KConfigGroup(krConfig, "Look&Feel").readEntry("Search in special items", false);
......
......@@ -568,7 +568,7 @@ void VerifyWizard::onResultPage()
bool VerifyWizard::isSupported(const QString &path)
{
const QFileInfo fileInfo(path);
return fileInfo.isFile() && m_checksumTools.keys().contains(fileInfo.suffix());
return fileInfo.isFile() && m_checksumTools.contains(fileInfo.suffix());
}
} // NAMESPACE CHECKSUM_
......@@ -124,7 +124,7 @@ void KURLListRequester::keyPressEvent(QKeyEvent *e)
void KURLListRequester::deleteSelectedItems()
{
QList<QListWidgetItem *> selectedItems = urlListBox->selectedItems();
const QList<QListWidgetItem *> selectedItems = urlListBox->selectedItems();
for (QListWidgetItem *item : selectedItems)
delete item;
emit changed();
......
......@@ -125,18 +125,17 @@ public:
class DULinesItem : public QTreeWidgetItem
{
public:
DULinesItem(DiskUsage *diskUsageIn, File *fileItem, QTreeWidget * parent, const QString& label1,
DULinesItem(File *fileItem, QTreeWidget * parent, const QString& label1,
const QString& label2, const QString& label3) : QTreeWidgetItem(parent),
diskUsage(diskUsageIn), file(fileItem) {
file(fileItem) {
setText(0, label1);
setText(1, label2);
setText(2, label3);
setTextAlignment(1, Qt::AlignRight);
}
DULinesItem(DiskUsage *diskUsageIn, File *fileItem, QTreeWidget * parent, QTreeWidgetItem * after,
const QString& label1, const QString& label2, const QString& label3) : QTreeWidgetItem(parent, after),
diskUsage(diskUsageIn), file(fileItem) {
DULinesItem(File *fileItem, QTreeWidget * parent, QTreeWidgetItem * after,
const QString& label1, const QString& label2, const QString& label3) : QTreeWidgetItem(parent, after), file(fileItem) {
setText(0, label1);
setText(1, label2);
setText(2, label3);
......@@ -168,7 +167,6 @@ public:
}
private:
DiskUsage *diskUsage;
File *file;
};
......@@ -209,8 +207,6 @@ DULines::DULines(DiskUsage *usage)
header()->setSortIndicatorShown(true);
sortItems(1, Qt::AscendingOrder);
// toolTip = new DULinesToolTip( diskUsage, viewport(), this );
connect(diskUsage, &DiskUsage::enteringDirectory, this, &DULines::slotDirChanged);
connect(diskUsage, &DiskUsage::clearing, this, &DULines::clear);
......@@ -284,9 +280,9 @@ void DULines::slotDirChanged(Directory *dirEntry)
QString fileName = item->name();
if (lastItem == nullptr)
lastItem = new DULinesItem(diskUsage, item, this, "", item->percent() + " ", fileName);
lastItem = new DULinesItem(item, this, "", item->percent() + " ", fileName);
else
lastItem = new DULinesItem(diskUsage, item, this, lastItem, "", item->percent() + " ", fileName);
lastItem = new DULinesItem(item, this, lastItem, "", item->percent() + " ", fileName);
if (item->isExcluded())
lastItem->setHidden(true);
......
......@@ -30,7 +30,7 @@
#include "Config.h"
#include "fileTree.h"
#include "radialMap.h"
#include "sincos.h"
#include <cmath>
#include "widget.h"
#include "../compat.h"
......@@ -253,9 +253,6 @@ RadialMap::Widget::paintExplodedLabels(QPainter &paint) const
rightSide = ((*it)->a < 1440 || (*it)->a > 4320);
ra = M_PI / 2880 * (*it)->a; //convert to radians
#if 0
sincos(ra, &sinra, &cosra);
#endif
sinra = sin(ra); cosra = cos(ra);
spacer = preSpacer + m_map.m_ringBreadth * (*it)->lvl;
......
......@@ -34,7 +34,7 @@
#include "builder.h"
#include "Config.h"
#include "fileTree.h"
#include "sincos.h"
#include <cmath>
#include "widget.h"
#define COLOR_GREY QColor::fromHsv( 0, 0, 140 )
......@@ -320,9 +320,6 @@ RadialMap::Map::paint(unsigned int scaleFactor)
if (i == 2)
radius += 5 * scaleFactor;
#if 0
sincos(ra, &sinra, &cosra);
#endif
sinra = sin(ra); cosra = cos(ra);
pos.rx() = cpos.x() + static_cast<int>(cosra * radius);
pos.ry() = cpos.y() - static_cast<int>(sinra * radius);
......@@ -393,15 +390,3 @@ RadialMap::Map::paint(unsigned int scaleFactor)
paint.end();
}
#if 0
#if __GLIBC__ < 2 || __GLIBC__ == 2 && __GLIBC_MINOR__ < 1
void
sincos(double angleRadians, double *Sin, double *Cos)
{
*Sin = sin(angleRadians);
*Cos = cos(angleRadians);
}
#endif
#endif
/*****************************************************************************
* Copyright (C) 2003-2004 Max Howell <max.howell@methylblue.com> *
* Copyright (C) 2004-2020 Krusader Krew [https://krusader.org] *
* *
* This file is part of Krusader [https://krusader.org]. *
* *
* Krusader is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 2 of the License, or *
* (at your option) any later version. *
* *
* Krusader is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with Krusader. If not, see [http://www.gnu.org/licenses/]. *
*****************************************************************************/
#ifndef SINCOS_H
#define SINCOS_H
#include <math.h>
#if 0
#if __GLIBC__ < 2 || __GLIBC__ == 2 && __GLIBC_MINOR__ < 1
void
sincos(double angleRadians, double *Sin, double *Cos);
#endif
#endif
#endif
......@@ -32,8 +32,6 @@
// QtWidgets
#include <QApplication> //sendEvent
#include <KWidgetsAddons/KCursor> //ctor
#include "fileTree.h"
#include "Config.h"
#include "radialMap.h" //constants
......
......@@ -28,21 +28,18 @@
// QtCore
#include <QTimer> //::resizeEvent()
// QtGui
#include <QMouseEvent>
#include <QPainter>
#include <QPaintEvent>
#include <QResizeEvent>
// QtWidgets
#include <QApplication> //QApplication::setOverrideCursor()
#include <QMenu>
#include <KI18n/KLocalizedString>
#include <KIconThemes/KIconEffect>
#include <KIO/DeleteJob>
#include <KIO/JobUiDelegate>
#include <KIOWidgets/KRun>
#include <KWidgetsAddons/KCursor>
#include <KWidgetsAddons/KMessageBox>
#include <KToolInvocation>
void
......@@ -195,7 +192,7 @@ RadialMap::Widget::mousePressEvent(QMouseEvent *e)
//KRun::runCommand will show an error message if there was trouble
KRun::runCommand(QString("kfmclient openURL '%1'").arg(url.url()), this);
else if (result == actKonsole)
KRun::runCommand(QString("konsole --workdir '%1'").arg(url.url()), this);
KToolInvocation::invokeTerminal(QString(), url.url());
else if (result == actViewMag || result == actFileOpen)
goto sectionTwo;
else if (result == actEditDel) {
......@@ -225,14 +222,8 @@ RadialMap::Widget::mousePressEvent(QMouseEvent *e)
m_tip.hide(); //user expects this
if (!isDir || e->button() == Qt::MidButton) {
#if 0 // TODO: PORTME
KIconEffect::visualActivate(this, rect);
#endif
new KRun(url, this, true); //FIXME see above
} else if (m_focus->file() != m_tree) { //is left mouse button
#if 0 // TODO: PORTME
KIconEffect::visualActivate(this, rect);
#endif
emit activated(url); //activate first, this will cause UI to prepare itself
if (m_focus)
createFromCache(dynamic_cast<const Directory*>(m_focus->file()));
......
......@@ -103,7 +103,8 @@ void SizeCalculator::nextUrl()
nextUrl();
return;
}
for (FileItem *file : fs->fileItems())
const QList<FileItem *> fileItems = fs->fileItems();
for (FileItem *file : fileItems)
m_nextSubUrls << file->getUrl();
delete fs;
} else {
......
......@@ -51,7 +51,7 @@ KFnKeys::KFnKeys(QWidget *parent, KrMainWindow *mainWindow) :
layout->setSpacing(0);
int pos = 0;
for(QPair<QPushButton *, QPair<QAction *, const QString&>> entry : buttonList) {
for(QPair<QPushButton *, QPair<QAction *, const QString&>> entry : qAsConst(buttonList)) {
layout->addWidget(entry.first, 0, pos++);
}
layout->activate();
......
......@@ -144,7 +144,6 @@ void MediaButton::createMediaList()
for (auto & it : possibleMountList) {
if (krMtMan.networkFilesystem(it->mountType())) {
QString path = it->mountPoint();
bool mounted = false;
for (auto & it2 : currentMountList) {
......@@ -175,7 +174,6 @@ bool MediaButton::getNameAndIcon(Solid::Device & device, QString &name, QIcon &i
if (access == nullptr)
return false;
QString udi = device.udi();
QString label = i18nc("Unknown label", "Unknown");
bool mounted = access->isAccessible();
QString path = access->filePath();
......
......@@ -248,7 +248,7 @@ bool JobMan::waitForJobs(bool waitForUserInput)
m_messageBox->addButton(QMessageBox::Abort);
m_messageBox->addButton(QMessageBox::Cancel);
m_messageBox->setDefaultButton(QMessageBox::Cancel);
for (KrJob *job: m_jobs)
for (KrJob *job: qAsConst(m_jobs))
connect(job, &KrJob::terminated, this, &JobMan::slotUpdateMessageBox);
slotUpdateMessageBox();
......@@ -258,7 +258,7 @@ bool JobMan::waitForJobs(bool waitForUserInput)
// accepted -> cancel all jobs
if (result == QMessageBox::Abort) {
for (KrJob *job: m_jobs) {
for (KrJob *job: qAsConst(m_jobs)) {
job->cancel();
}
return true;
......@@ -314,7 +314,7 @@ void JobMan::slotControlActionTriggered()
if (!anyRunning && m_queueMode) {
m_jobs.first()->start();
} else {
for (KrJob *job : m_jobs) {
for (KrJob *job : qAsConst(m_jobs)) {
if (anyRunning)
job->pause();
else
......@@ -426,7 +426,7 @@ void JobMan::cleanupMenu() {
void JobMan::updateUI()
{
int totalPercent = 0;
for (KrJob *job: m_jobs) {
for (KrJob *job: qAsConst(m_jobs)) {
totalPercent += job->percent();
}
const bool hasJobs = !m_jobs.isEmpty();
......@@ -451,9 +451,5 @@ void JobMan::updateUI()
bool JobMan::jobsAreRunning()
{
for (KrJob *job: m_jobs)
if (job->isRunning())
return true;
return false;
return std::any_of(m_jobs.cbegin(), m_jobs.cend(), [](KrJob *job) {return job->isRunning();});
}
......@@ -227,7 +227,6 @@ void KrViewer::createGUI(KParts::Part* part)
}
// and "fix" the menubar
QList<QAction *> actList = menuBar()->actions();
viewerMenu->setTitle(i18n("&KrViewer"));
QAction * act = menuBar() ->addMenu(viewerMenu);
act->setData(QVariant(70));
......
......@@ -397,37 +397,7 @@ bool KrInterBriefView::isIndexHidden(const QModelIndex&ndx) const
{
return ndx.column() != 0;
}
#if 0
QRegion KrInterBriefView::visualRegionForSelection(const QItemSelection &selection) const
{
if (selection.isEmpty())
return QRegion();
QRegion selectionRegion;
for (int i = 0; i < selection.count(); ++i) {
QItemSelectionRange range = selection.at(i);
if (!range.isValid())
continue;
QModelIndex leftIndex = range.topLeft();
if (!leftIndex.isValid())
continue;
const QRect leftRect = visualRect(leftIndex);
int top = leftRect.top();
QModelIndex rightIndex = range.bottomRight();
if (!rightIndex.isValid())
continue;
const QRect rightRect = visualRect(rightIndex);
int bottom = rightRect.bottom();
if (top > bottom)
qSwap<int>(top, bottom);
int height = bottom - top + 1;
QRect combined = leftRect | rightRect;
combined.setX(range.left());
selectionRegion += combined;
}
return selectionRegion;
}
#endif
void KrInterBriefView::paintEvent(QPaintEvent *e)
{
QStyleOptionViewItem option = viewOptions();
......
......@@ -952,8 +952,6 @@ void KrView::sortModeUpdated(KrViewProperties::ColumnType sortColumn, bool desce
options &= ~KrViewProperties::Descending;
_properties->sortColumn = sortColumn;
_properties->sortOptions = static_cast<KrViewProperties::SortOptions>(options);
// op()->settingsChanged(KrViewProperties::PropSortMode);
}
bool KrView::drawCurrent() const
......
......@@ -107,16 +107,6 @@ QString KrViewItem::description() const
QPixmap KrViewItem::icon()
{
#if 0
QPixmap *p;
// This is bad - very bad. the function must return a valid reference,
// This is an interface flow - shie please fix it with a function that return QPixmap*
// this way we can return 0 - and do our error checking...
// shie answers: why? what's the difference? if we return an empty pixmap, others can use it as it
// is, without worrying or needing to do error checking. empty pixmap displays nothing
#endif
if (dummyFileItem || !_viewProperties->displayIcons)
return QPixmap();
else return KrView::getIcon(_fileitem, true);
......
......@@ -237,7 +237,7 @@ void KrViewItemDelegate::cycleEditorSelection()
EditorSelection currentSelection(editor->selectionStart(), editor->QLINEEDIT_SELECTIONLENGTH);
auto text = editor->text();
auto selections = generateFileNameSelections(text);
const auto selections = generateFileNameSelections(text);
// try to find current selection in the list
int currentIndex = 0;
......
......@@ -750,7 +750,7 @@ void KrColorCache::refreshColors()
m_impl->m_cachedColors.clear();
m_impl->m_colorSettings = KrColorSettings();
QPixmapCache::clear(); // dimmed icons are cached
colorsRefreshed();
emit colorsRefreshed();
}
void KrColorCache::setColors(const KrColorSettings & colorSettings)
......@@ -758,6 +758,6 @@ void KrColorCache::setColors(const KrColorSettings & colorSettings)
m_impl->m_cachedColors.clear();
m_impl->m_colorSettings = colorSettings;
QPixmapCache::clear(); // dimmed icons are cached
colorsRefreshed();
emit colorsRefreshed();
}
......@@ -54,7 +54,7 @@
class KrDirModel : public KDirModel
{
public:
KrDirModel(QWidget *parent, KrFileTreeView *ftv) : KDirModel(parent), fileTreeView(ftv) {}
KrDirModel(QWidget *parent) : KDirModel(parent) {}
protected:
Qt::ItemFlags flags(const QModelIndex &index) const override
......@@ -64,9 +64,6 @@ protected:
itflags &= ~Qt::ItemIsDropEnabled;
return itflags;
}