Commit 2db387ac authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Make it compile with strict compile flags.

Fix mem leak.
Initialize pointer
parent 8175df47
......@@ -74,6 +74,13 @@ set(HAVE_XRES ${X11_XRes_FOUND})
set(HAVE_QTWEBKITWIDGETS ${Qt5WebKitWidgets_FOUND})
configure_file(config-ksysguard.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-ksysguard.h )
add_definitions(-DQT_NO_URL_CAST_FROM_STRING)
add_definitions(-DQT_USE_QSTRINGBUILDER)
add_definitions(-DQT_NO_CAST_FROM_ASCII)
add_definitions(-DQT_NO_CAST_TO_ASCII)
add_definitions(-DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT)
#add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000)
add_subdirectory( lsofui )
add_subdirectory( processcore )
add_subdirectory( processui )
......
......@@ -129,7 +129,7 @@ class SensorRequest
private:
QString mRequest;
SensorClient *mClient;
SensorClient *mClient = nullptr;
int mId;
};
......
......@@ -54,7 +54,7 @@ class SensorShellAgent : public SensorAgent
~SensorShellAgent() override;
bool start( const QString &host, const QString &shell,
const QString &command = QLatin1String(QLatin1String("")), int port = -1 ) override;
const QString &command = QLatin1String(""), int port = -1 ) override;
void hostInfo( QString &shell, QString &command, int &port) const override;
......
......@@ -53,3 +53,8 @@ LsofSearchWidget::LsofSearchWidget(QWidget* parent, int pid )
ktreewidgetsearchline
}
LsofSearchWidget::~LsofSearchWidget()
{
delete ui;
}
......@@ -36,7 +36,8 @@ class LsofSearchWidget : public QDialog
Q_OBJECT
public:
LsofSearchWidget(QWidget *parent);
explicit LsofSearchWidget(QWidget *parent);
~LsofSearchWidget();
private:
Ui_LsofSearchWidget *ui;
......
......@@ -45,7 +45,7 @@ bool KLsofWidget::update()
d->process->waitForFinished();
args << QStringLiteral("-Fftn");
if(d->pid > 0)
args << ("-p" + QString::number(d->pid));
args << (QStringLiteral("-p") + QString::number(d->pid));
d->process->start(QStringLiteral("lsof"), args);
return true;
}
......
......@@ -560,7 +560,7 @@ void Process::setTracerpid(qlonglong tracerpid)
d->changes |= Process::Tracerpid;
}
void Process::setTty(QByteArray tty)
void Process::setTty(const QByteArray &tty)
{
if(d->tty == tty) return;
d->tty = tty;
......@@ -654,13 +654,13 @@ void Process::setVmURSS(qlonglong _vmURSS) {
d->changes |= Process::VmURSS;
}
void Process::setName(QString _name) {
void Process::setName(const QString &_name) {
if(d->name == _name) return;
d->name = _name;
d->changes |= Process::Name;
}
void Process::setCommand(QString _command) {
void Process::setCommand(const QString &_command) {
if(d->command == _command) return;
d->command = _command;
d->changes |= Process::Command;
......@@ -765,4 +765,4 @@ void Process::setChanges(KSysGuard::Process::Change changes)
d->changes = changes;
}
}
\ No newline at end of file
}
......@@ -89,7 +89,7 @@ public:
void setTracerpid(qlonglong tracerpid); ///< If this is being debugged, this is the process that is debugging it, or 0 otherwise
QByteArray tty() const;
void setTty(QByteArray tty); ///< The name of the tty the process owns
void setTty(const QByteArray &tty); ///< The name of the tty the process owns
qlonglong userTime() const;
void setUserTime(qlonglong userTime); ///< The time, in 100ths of a second, spent in total on user calls. -1 if not known
......@@ -137,10 +137,10 @@ public:
void setVmURSS(qlonglong vmURSS); ///< Physical memory used only by the process, and not counting the code for shared libraries. Set to -1 if unknown
QString name() const;
void setName(QString name); ///< The name (e.g. "ksysguard", "konversation", "init")
void setName(const QString &name); ///< The name (e.g. "ksysguard", "konversation", "init")
QString& command() const; // REF, make non-ref later!
void setCommand(QString command); ///< The command the process was launched with
void setCommand(const QString &command); ///< The command the process was launched with
ProcessStatus status() const;
void setStatus( ProcessStatus status); ///< Whether the process is running/sleeping/etc
......
......@@ -519,7 +519,7 @@ bool Processes::loadHistoryFile(const QString &filename)
QString Processes::historyFileName() const
{
if(!d->mIsLocalHost || !d->mHistoricProcesses)
return QString::null;
return QString();
return d->mHistoricProcesses->historyFileName();
}
QDateTime Processes::viewingTime() const
......
......@@ -58,7 +58,7 @@ namespace KSysGuard
public:
Processes(const QString &hostname = QString::null, QObject * parent = nullptr);
Processes(const QString &hostname = QString(), QObject * parent = nullptr);
~Processes() override;
enum UpdateFlag {
StandardInformation = 1,
......
......@@ -44,7 +44,7 @@ namespace KSysGuard
tracerPidColumn = ttyColumn = ioprioClassColumn = ioprioColumn =
vmURSSColumn = -1;
usedMemory = freeMemory;}
~Private() {;}
~Private() {}
QString host;
QList<QByteArray> lastAnswer;
QSet<long> pids;
......
......@@ -59,23 +59,23 @@ void KTextEditVT::insertVTChar(const QChar & c) {
escape_number2 = escape_number2*10 + c.digitValue();
}
} else if(c == ';') {
} else if(c == QLatin1Char(';')) {
escape_number_seperator = true;
} else if(escape_OSC && c==7) { //Throw away any letters that are not OSC
escape_code = c;
} else if(escape_CSI)
escape_code = c;
} else if(c=='[') {
} else if(c==QLatin1Char('[')) {
escape_CSI = true;
} else if(c==']') {
} else if(c==QLatin1Char(']')) {
escape_OSC = true;
}
else if(c=='(' || c==')') {}
else if(c==QLatin1Char('(') || c==QLatin1Char(')')) {}
else
escape_code = c;
if(!escape_code.isNull()) {
//We've read in the whole escape sequence. Now parse it
if(escape_code == 'm') { // change color
if(escape_code == QLatin1Char('m')) { // change color
switch(escape_number2){
case 0: //all off
setFontWeight(QFont::Normal);
......@@ -119,9 +119,9 @@ void KTextEditVT::insertVTChar(const QChar & c) {
escape_number_seperator = false;
}
} else if(c == 0x0d) {
insertPlainText(QChar('\n'));
} else if(c.isPrint() || c == '\n') {
insertPlainText(QChar(c));
insertPlainText(QStringLiteral("\n"));
} else if(c.isPrint() || c == QLatin1Char('\n')) {
insertPlainText(c);
} else if(mParseAnsi) {
if(c == 127 || c == 8) { // delete or backspace, respectively
textCursor().deletePreviousChar();
......@@ -137,8 +137,8 @@ void KTextEditVT::insertVTChar(const QChar & c) {
} else if(!c.isNull()) {
insertPlainText(QStringLiteral("["));
QByteArray num;
num.setNum(c.toLatin1());
QString num;
num = c;
insertPlainText(num);
insertPlainText(QStringLiteral("]"));
}
......@@ -148,7 +148,7 @@ void KTextEditVT::insertVTText(const QByteArray & string)
{
int size= string.size();
for(int i =0; i < size; i++)
insertVTChar(QChar(string.at(i)));
insertVTChar(QLatin1Char(string.at(i)));
}
void KTextEditVT::insertVTText(const QString & string)
......
......@@ -57,7 +57,7 @@ class Q_DECL_EXPORT KTextEditVT : public QTextEdit
Q_PROPERTY( bool parseAnsiEscapeCodes READ parseAnsiEscapeCodes WRITE setParseAnsiEscapeCodes )
public:
KTextEditVT(QWidget* parent);
explicit KTextEditVT(QWidget* parent);
/** Whether to parse ANSI display code. If turned off the escape sequence will be shown literally. */
bool parseAnsiEscapeCodes() const;
......
......@@ -94,7 +94,7 @@ bool ProcessFilter::filterAcceptsRow( int source_row, const QModelIndex & source
} else {
// login and getty kinda _are_ the tty, so I do not really count them as 'programs'. So make a special case and hide them
// Their ppid are 1 (init) so by checking we try to avoid false matches, and speed up checking overall
QString name = process->name().section(' ', 0,0);
QString name = process->name().section(QLatin1Char(' '), 0,0);
if(process->parentPid() == 1 && (name == QLatin1String("login") || name.endsWith(QLatin1String("getty"))))
accepted = false;
}
......
......@@ -44,7 +44,7 @@ class KSYSGUARD_EXPORT ProcessFilter : public QSortFilterProxyModel
public:
enum State {AllProcesses=0,AllProcessesInTreeForm, SystemProcesses, UserProcesses, OwnProcesses, ProgramsOnly};
ProcessFilter(QObject *parent=nullptr) : QSortFilterProxyModel(parent) {mFilter = AllProcesses;}
explicit ProcessFilter(QObject *parent=nullptr) : QSortFilterProxyModel(parent) {mFilter = AllProcesses;}
~ProcessFilter() override {}
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
State filter() const {return mFilter; }
......
......@@ -302,7 +302,7 @@ bool ProcessModel::lessThan(const QModelIndex &left, const QModelIndex &right) c
//and sort by the string first, then sort by the number
QRegExp regexpLeft(QStringLiteral("^(\\D*)(\\d*)$"));
QRegExp regexpRight(regexpLeft);
if(regexpLeft.indexIn(processLeft->tty()) == -1 || regexpRight.indexIn(processRight->tty()) == -1)
if(regexpLeft.indexIn(QString::fromUtf8(processLeft->tty())) == -1 || regexpRight.indexIn(QString::fromUtf8(processRight->tty())) == -1)
return processLeft->tty() < processRight->tty();
int nameMatch = regexpLeft.cap(1).compare(regexpRight.cap(1));
if(nameMatch < 0)
......@@ -1240,7 +1240,7 @@ QVariant ProcessModel::data(const QModelIndex &index, int role) const
if(d->mShowCommandLineOptions)
return process->name();
else
return process->name().section(' ', 0,0);
return process->name().section(QLatin1Char(' '), 0,0);
case HeadingPid:
return (qlonglong)process->pid();
case HeadingUser:
......@@ -1248,7 +1248,7 @@ QVariant ProcessModel::data(const QModelIndex &index, int role) const
if(process->uid() == process->euid())
return d->getUsernameForUser(process->uid(), false);
else
return QString(d->getUsernameForUser(process->uid(), false) + ", " + d->getUsernameForUser(process->euid(), false));
return QString(d->getUsernameForUser(process->uid(), false) + QStringLiteral(", ") + d->getUsernameForUser(process->euid(), false));
case HeadingNiceness:
switch(process->scheduler()) {
case KSysGuard::Process::Other:
......@@ -1280,9 +1280,9 @@ QVariant ProcessModel::data(const QModelIndex &index, int role) const
if(total < 1 && process->status() != KSysGuard::Process::Sleeping && process->status() != KSysGuard::Process::Running && process->status() != KSysGuard::Process::Ended)
return process->translatedStatus(); //tell the user when the process is a zombie or stopped
if(total < 0.5)
return "";
return QString();
return QString(QString::number((int)(total+0.5)) + '%');
return QString(QString::number((int)(total+0.5)) + QLatin1Char('%'));
}
case HeadingCPUTime: {
qlonglong seconds = (process->userTime() + process->sysTime())/100;
......@@ -1313,7 +1313,7 @@ QVariant ProcessModel::data(const QModelIndex &index, int role) const
}
case HeadingCommand:
{
return process->command().replace('\n',' ');
return process->command().replace(QLatin1Char('\n'),QLatin1Char(' '));
// It would be nice to embolden the process name in command, but this requires that the itemdelegate to support html text
// QString command = process->command;
// command.replace(process->name, "<b>" + process->name + "</b>");
......@@ -1450,7 +1450,7 @@ QVariant ProcessModel::data(const QModelIndex &index, int role) const
tooltip += xi18nc("@info:tooltip", "<para><emphasis strong='true'>Command:</emphasis> %1</para>", process->command());
}
if(!process->tty().isEmpty())
tooltip += xi18nc("@info:tooltip", "<para><emphasis strong='true'>Running on:</emphasis> %1</para>", QString(process->tty()));
tooltip += xi18nc("@info:tooltip", "<para><emphasis strong='true'>Running on:</emphasis> %1</para>", QString::fromUtf8(process->tty()));
if(!tracer.isEmpty())
return QStringLiteral("%1<br />%2").arg(tooltip).arg(tracer);
......@@ -1479,7 +1479,7 @@ QVariant ProcessModel::data(const QModelIndex &index, int role) const
xi18nc("@info:tooltip", "<para><emphasis strong='true'>This process was run with the following command:</emphasis></para>"
"<para>%1</para>", process->command());
if(!process->tty().isEmpty())
tooltip += xi18nc("@info:tooltip", "<para><emphasis strong='true'>Running on:</emphasis> %1</para>", QString(process->tty()));
tooltip += xi18nc("@info:tooltip", "<para><emphasis strong='true'>Running on:</emphasis> %1</para>", QString::fromUtf8(process->tty()));
if (!tracer.isEmpty()) {
return QStringLiteral("%1<br/>%2").arg(tooltip).arg(tracer);
}
......@@ -1491,7 +1491,7 @@ QVariant ProcessModel::data(const QModelIndex &index, int role) const
return tooltip;
}
return tooltip + "<br/>" + tracer;
return QString(tooltip + QStringLiteral("<br/>") + tracer);
}
case HeadingNiceness: {
QString tooltip;
......@@ -1518,7 +1518,7 @@ QVariant ProcessModel::data(const QModelIndex &index, int role) const
tooltip += xi18nc("@info:tooltip", "<para><emphasis strong='true'>I/O Class:</emphasis> %1</para>", process->ioPriorityClassAsString());
}
if(tracer.isEmpty()) return tooltip;
return QString(tooltip + "<br/>" + tracer);
return QString(tooltip + QStringLiteral("<br/>") + tracer);
}
case HeadingCPUUsage:
case HeadingCPUTime: {
......@@ -1560,7 +1560,7 @@ QVariant ProcessModel::data(const QModelIndex &index, int role) const
}
if(!tracer.isEmpty())
return QString(tooltip + "<br/>" + tracer);
return QString(tooltip + QStringLiteral("<br/>") + tracer);
return tooltip;
}
case HeadingVmSize: {
......@@ -1628,10 +1628,10 @@ QVariant ProcessModel::data(const QModelIndex &index, int role) const
if(values.isEmpty()) return QVariant(QVariant::String);
for(int i = 0; i < values.size(); i++) {
if(!values.at(i)->name.isEmpty())
tooltip += "<li>" + values.at(i)->name + "</li>";
tooltip += QStringLiteral("<li>") + values.at(i)->name + QStringLiteral("</li>");
}
if(!tooltip.isEmpty())
return QString("<qt><p style='white-space:pre'><ul>" + tooltip + "</ul>");
return QString(QStringLiteral("<qt><p style='white-space:pre'><ul>") + tooltip + QStringLiteral("</ul>"));
#endif
return QVariant(QVariant::String);
}
......@@ -1677,7 +1677,7 @@ QVariant ProcessModel::data(const QModelIndex &index, int role) const
if(process->uid() == process->euid())
return d->getUsernameForUser(process->uid(), false);
else
return QString(d->getUsernameForUser(process->uid(), false) + ", " + d->getUsernameForUser(process->euid(), false));
return QString(d->getUsernameForUser(process->uid(), false) + QStringLiteral(", ") + d->getUsernameForUser(process->euid(), false));
case HeadingNiceness:
return process->niceLevel();
case HeadingTty:
......@@ -2103,39 +2103,39 @@ QMimeData *ProcessModel::mimeData(const QModelIndexList &indexes) const
else if(firstColumn != index.column())
continue;
else {
textCsv += '\n';
textPlain += '\n';
textCsv += QLatin1Char('\n');
textPlain += QLatin1Char('\n');
textHtml += QLatin1String("</tr><tr>");
firstrow = false;
}
for(int i = 0; i < d->mHeadings.size(); i++) {
if(firstrow) {
QString heading = d->mHeadings[i];
textHtmlHeaders += "<th>" + heading + "</th>";
textHtmlHeaders += QStringLiteral("<th>") + heading + QStringLiteral("</th>");
if(i) {
textCsvHeaders += ',';
textCsvHeaders += QLatin1Char(',');
textPlainHeaders += QLatin1String(", ");
}
textPlainHeaders += heading;
heading.replace('"', QLatin1String("\"\""));
textCsvHeaders += '"' + heading + '"';
heading.replace(QLatin1Char('"'), QLatin1String("\"\""));
textCsvHeaders += QLatin1Char('"') + heading + QLatin1Char('"');
}
QModelIndex index2 = createIndex(index.row(), i, reinterpret_cast< KSysGuard::Process * > (index.internalPointer()));
QString display = data(index2, PlainValueRole).toString();
if(i) {
textCsv += ',';
textCsv += QLatin1Char(',');
textPlain += QLatin1String(", ");
}
textHtml += "<td>" + QString(display).toHtmlEscaped() + "</td>";
textHtml += QStringLiteral("<td>") + display.toHtmlEscaped() + QStringLiteral("</td>");
textPlain += display;
display.replace('"',QLatin1String("\"\""));
textCsv += '"' + display + '"';
display.replace(QLatin1Char('"'),QLatin1String("\"\""));
textCsv += QLatin1Char('"') + display + QLatin1Char('"');
}
}
}
textHtml = "<html><table><tr>" + textHtmlHeaders + "</tr><tr>" + textHtml + "</tr></table>";
textCsv = textCsvHeaders + '\n' + textCsv;
textPlain = textPlainHeaders + '\n' + textPlain;
textHtml = QStringLiteral("<html><table><tr>") + textHtmlHeaders + QStringLiteral("</tr><tr>") + textHtml + QStringLiteral("</tr></table>");
textCsv = textCsvHeaders + QLatin1Char('\n') + textCsv;
textPlain = textPlainHeaders + QLatin1Char('\n') + textPlain;
mimeData->setText(textPlain);
mimeData->setHtml(textHtml);
......
......@@ -55,7 +55,7 @@ class KSYSGUARD_EXPORT ProcessModel : public QAbstractItemModel
float value;
};
ProcessModel(QObject* parent = nullptr, const QString &host = QString() );
explicit ProcessModel(QObject* parent = nullptr, const QString &host = QString() );
~ProcessModel() override;
/* Functions for our Model for QAbstractItemModel*/
......
......@@ -120,7 +120,12 @@ ReniceDlg::ReniceDlg(QWidget* parent, const QStringList& processes, int currentC
updateUi();
mainLayout->addWidget(buttonBox);
mainLayout->addWidget(buttonBox);
}
ReniceDlg::~ReniceDlg()
{
delete ui;
}
void ReniceDlg::ioSliderChanged(int value) {
......
......@@ -41,7 +41,8 @@ public:
* @p currentCpuSched The current Cpu Scheduler of the processes. Set to -1 to they have different schedulers
* @p currentIoSched The current I/O Scheduler of the processes. Set to -1 to they have different schedulers. Leave as the default -2 if not supported
*/
ReniceDlg(QWidget* parent, const QStringList& processes, int currentCpuPrio, int currentCpuSched, int currentIoPrio=-2, int currentIoSched=-2);
explicit ReniceDlg(QWidget* parent, const QStringList& processes, int currentCpuPrio, int currentCpuSched, int currentIoPrio=-2, int currentIoSched=-2);
~ReniceDlg();
int newCPUPriority;
int newIOPriority;
int newCPUSched;
......
......@@ -59,7 +59,7 @@ class Q_DECL_EXPORT KSysGuardProcessList : public QWidget
Q_ENUMS( ProcessModel::Units )
public:
KSysGuardProcessList(QWidget* parent = nullptr, const QString &hostName = QString());
explicit KSysGuardProcessList(QWidget* parent = nullptr, const QString &hostName = QString());
~KSysGuardProcessList() override;
QLineEdit *filterLineEdit() const;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment