Skip to content

Commit

Permalink
updated variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzhaninan committed Mar 8, 2018
1 parent 11e9004 commit 482a8cc
Show file tree
Hide file tree
Showing 56 changed files with 548 additions and 562 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ set(PROJECT_ROOT "${CMAKE_CURRENT_SOURCE_DIR}")

# Activating MOC and searching for the Qt5 dependencies
set(CMAKE_AUTOMOC ON)
find_package(Qt5 COMPONENTS Core Gui Widgets Charts Svg Concurrent REQUIRED)
find_package(Qt5 COMPONENTS Core Gui Widgets Charts Svg Concurrent REQUIRED)

# Setting the minimum C++ standard and passing the Qt-specific define
set(CMAKE_CXX_STANDARD 11)
Expand Down
4 changes: 3 additions & 1 deletion stacer-core/Info/cpu_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ quint8 CpuInfo::getCpuCoreCount() const

QList<double> CpuInfo::getLoadAvgs() const
{
QList<double> avgs;
QList<double> avgs = {0, 0, 0};

QStringList strListAvgs = FileUtil::readStringFromFile(PROC_LOADAVG).split(QRegExp("\\s+"));

if (strListAvgs.count() > 2) {
avgs.clear();
avgs << strListAvgs.takeFirst().toDouble();
avgs << strListAvgs.takeFirst().toDouble();
avgs << strListAvgs.takeFirst().toDouble();
Expand Down
2 changes: 1 addition & 1 deletion stacer-core/Info/network_info.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef NETWORK_INFO_H
#define NETWORK_INFO_H

#include <QtNetwork/QNetworkInterface>
#include "Utils/file_util.h"
#include "Utils/command_util.h"
#include <QtNetwork/QNetworkInterface>

#include "stacer-core_global.h"

Expand Down
5 changes: 0 additions & 5 deletions stacer-core/Info/process.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#include "process.h"

Process::Process()
{

}

pid_t Process::getPid() const
{
return pid;
Expand Down
6 changes: 0 additions & 6 deletions stacer-core/Info/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@

#include "Utils/file_util.h"

// defines
#define PROC_PID_CMD "/proc/%1/comm"
#define PROC_PID_STATUS "/proc/%1/comm"

#include "stacer-core_global.h"

class STACERCORESHARED_EXPORT Process {

public:
Process();

pid_t getPid() const;
void setPid(const pid_t &value);

Expand Down
2 changes: 1 addition & 1 deletion stacer-core/Info/system_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ SystemInfo::SystemInfo()
try {
if (name.isEmpty())
name = CommandUtil::exec("whoami").trimmed();
} catch (QString &ex) {
} catch (const QString &ex) {
qCritical() << ex;
}

Expand Down
5 changes: 2 additions & 3 deletions stacer-core/Info/system_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define PROC_CPUINFO "/proc/cpuinfo"

#include "stacer-core_global.h"

class STACERCORESHARED_EXPORT SystemInfo
{
public:
Expand All @@ -21,18 +22,16 @@ class STACERCORESHARED_EXPORT SystemInfo
QString getCpuModel() const;
QString getCpuSpeed() const;
QString getCpuCore() const;
QString getUsername() const;

QFileInfoList getCrashReports() const;
QFileInfoList getAppLogs() const;
QFileInfoList getAppCaches() const;

QString getUsername() const;

private:
QString cpuCore;
QString cpuModel;
QString cpuSpeed;

QString username;
};

Expand Down
87 changes: 46 additions & 41 deletions stacer-core/Tools/apt_source_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ void AptSourceTool::removeAPTSource(const APTSourcePtr aptSource)
changeSource(aptSource, "");
}

void AptSourceTool::addRepository(const QString &repository, const bool isSource)
{
if (! repository.isEmpty()) {
QStringList args = { "-y", repository };
if (isSource) {
args << "-s";
}

CommandUtil::sudoExec("add-apt-repository", args);
}
}

void AptSourceTool::changeSource(const APTSourcePtr aptSource, const QString newSource)
{
QStringList sourceFileContent = FileUtil::readListFromFile(aptSource->filePath);
Expand All @@ -32,14 +44,18 @@ void AptSourceTool::changeSource(const APTSourcePtr aptSource, const QString new
}

if (pos != -1) {
sourceFileContent.replace(pos, newSource);
}
if (newSource.isEmpty()) {
sourceFileContent.removeAt(pos);
} else {
sourceFileContent.replace(pos, newSource);
}

QStringList args = { aptSource->filePath };
QStringList args = { aptSource->filePath };

QByteArray data = sourceFileContent.join('\n').append('\n').toUtf8();
QByteArray data = sourceFileContent.join('\n').append('\n').toUtf8();

CommandUtil::sudoExec("tee", args, data);
CommandUtil::sudoExec("tee", args, data);
}
}

void AptSourceTool::changeStatus(const APTSourcePtr aptSource, const bool status)
Expand All @@ -59,57 +75,46 @@ QList<APTSourcePtr> AptSourceTool::getSourceList()
{
QList<APTSourcePtr> aptSourceList;

QDir aptSourceListDir(APT_SOURCES_LIST_D_PATH);

QFileInfoList infoList = aptSourceListDir.entryInfoList({ "*.list"/*, "*.save"*/ },
QDir::Files, QDir::Time);
QFileInfoList infoList = QDir(APT_SOURCES_LIST_D_PATH).entryInfoList({"*.list"}, QDir::Files, QDir::Time);
infoList.append(QFileInfo(APT_SOURCES_LIST_PATH)); // sources.list

// example "deb [arch=amd64] http://packages.microsoft.com/repos/vscode stable main"
for (const QFileInfo &info : infoList) {

QStringList fileContent = FileUtil::readListFromFile(info.absoluteFilePath());
QStringList fileContent = FileUtil::readListFromFile(info.absoluteFilePath()).filter(QRegExp("^\\s{0,}#{0,}\\s{0,}deb"));

for (const QString &line : fileContent) {
QString _line = line.trimmed();

if (! _line.isEmpty()) {

APTSourcePtr aptSource(new APTSource);
aptSource->filePath = info.absoluteFilePath();
APTSourcePtr aptSource(new APTSource);
aptSource->filePath = info.absoluteFilePath();

if (_line.startsWith(QChar('#'))) { // is deactive
aptSource->isActive = false;
_line.replace("#", ""); // remove comment
} else {
aptSource->isActive = true;
}
aptSource->isActive = ! _line.startsWith(QChar('#'));

// if has options
if (_line.contains(" [")) {
int pos1 = _line.indexOf('['), pos2 = _line.indexOf(']');
_line.remove('#'); // remove comment

if (pos1 != -1 && pos2 != -1) {
aptSource->options = _line.mid(pos1, pos2-pos1+1);
_line.replace(aptSource->options, ""); // delete options section
}
}
// if has options
QRegExp regexOption("(\\s[\\[]+.*[\\]]+)");
regexOption.indexIn(_line);
if (regexOption.matchedLength() > 0) {
aptSource->options = regexOption.cap().trimmed();
}
// remove options
_line.remove(regexOption);

QStringList sourceColumns = _line.trimmed().split(QRegExp("\\s+"));
bool isBinary = sourceColumns.first() == "deb";
bool isSource = sourceColumns.first() == "deb-src";
QStringList sourceColumns = _line.trimmed().split(QRegExp("\\s+"));
bool isBinary = sourceColumns.first() == "deb";
bool isSource = sourceColumns.first() == "deb-src";

// example "deb http://packages.microsoft.com/repos/vscode stable main"
if (isBinary || isSource) {
aptSource->isSource = isSource;
aptSource->uri = sourceColumns.at(1);
aptSource->distribution = sourceColumns.at(2);
aptSource->components = sourceColumns.mid(3).join(' ');
if ((isBinary || isSource) && sourceColumns.count() > 2) {
aptSource->isSource = isSource;
aptSource->uri = sourceColumns.at(1);
aptSource->distribution = sourceColumns.at(2);
aptSource->components = sourceColumns.mid(3).join(' ');

aptSource->source = line.trimmed().replace("#", "").trimmed();
// qDebug() << aptSource->source;
aptSource->source = line.trimmed().remove('#').trimmed();

aptSourceList.append(aptSource);
}
aptSourceList.append(aptSource);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions stacer-core/Tools/apt_source_tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class AptSourceTool
static void removeAPTSource(const APTSourcePtr aptSource);
static void changeStatus(const APTSourcePtr aptSource, const bool status);
static void changeSource(const APTSourcePtr aptSource, const QString newSource);
static void addRepository(const QString &repository, const bool isSource);
};

#endif // AptSourceTool_H
1 change: 0 additions & 1 deletion stacer-core/Utils/format_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ QString FormatUtil::formatBytes(const quint64 &bytes)
return formatUnit(bytes, GIBI, "GiB");
else // TiB
return formatUnit(bytes, TEBI, "TiB");

#undef formatUnit
}
11 changes: 5 additions & 6 deletions stacer-core/Utils/format_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ class STACERCORESHARED_EXPORT FormatUtil
public:
static QString formatBytes(const quint64 &bytes);

private:
static const quint64 KIBI = 1UL << 10UL;
static const quint64 MEBI = 1UL << 20UL;
static const quint64 GIBI = 1UL << 30UL;
static const quint64 TEBI = 1UL << 40UL;

public:
static const quint64 KIBI = 1024;
static const quint64 MEBI = 1048576;
static const quint64 GIBI = 1073741824;
static const quint64 TEBI = 1099511627776;
};

#endif // FORMAT_UTIL_H
4 changes: 4 additions & 0 deletions stacer-core/stacer-core.pro
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

QT -= gui

QT += core network

CONFIG += c++11

TARGET = stacer-core
TEMPLATE = lib

Expand Down
28 changes: 14 additions & 14 deletions stacer/Managers/app_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ AppManager::AppManager()

loadThemeList();

if (translator.load(QString("stacer_%1").arg(mSettingManager->getLanguage()), qApp->applicationDirPath() + "/translations")) {
qApp->installTranslator(&translator);
if (mTranslator.load(QString("stacer_%1").arg(mSettingManager->getLanguage()), qApp->applicationDirPath() + "/translations")) {
qApp->installTranslator(&mTranslator);
(mSettingManager->getLanguage() == "ar") ? qApp->setLayoutDirection(Qt::RightToLeft) : qApp->setLayoutDirection(Qt::LeftToRight);
} else {
qCritical() << "Translator could not load.";
Expand All @@ -37,7 +37,7 @@ QSystemTrayIcon *AppManager::getTrayIcon()

QSettings *AppManager::getStyleValues() const
{
return styleValues;
return mStyleValues;
}

void AppManager::loadLanguageList()
Expand All @@ -49,13 +49,13 @@ void AppManager::loadLanguageList()

QJsonObject ob = lanuages.at(i).toObject();

languageList.insert(ob["value"].toString(), ob["text"].toString());
mLanguageList.insert(ob["value"].toString(), ob["text"].toString());
}
}

QMap<QString, QString> AppManager::getLanguageList() const
{
return languageList;
return mLanguageList;
}

void AppManager::loadThemeList()
Expand All @@ -67,33 +67,33 @@ void AppManager::loadThemeList()

QJsonObject ob = themes.at(i).toObject();

themeList.insert(ob["value"].toString(), ob["text"].toString());
mThemeList.insert(ob["value"].toString(), ob["text"].toString());
}
}

QMap<QString, QString> AppManager::getThemeList() const
{
return themeList;
return mThemeList;
}

void AppManager::updateStylesheet()
{
QString appThemePath = QString(":/static/themes/%1/style").arg(mSettingManager->getThemeName());
styleValues = new QSettings(QString("%1/values.ini").arg(appThemePath), QSettings::IniFormat);
mStyleValues = new QSettings(QString("%1/values.ini").arg(appThemePath), QSettings::IniFormat);

stylesheetFileContent = FileUtil::readStringFromFile(QString("%1/style.qss").arg(appThemePath));
mStylesheetFileContent = FileUtil::readStringFromFile(QString("%1/style.qss").arg(appThemePath));

// set values example: @color01 => #fff
for (const QString &key : styleValues->allKeys()) {
stylesheetFileContent.replace(key, styleValues->value(key).toString());
for (const QString &key : mStyleValues->allKeys()) {
mStylesheetFileContent.replace(key, mStyleValues->value(key).toString());
}

qApp->setStyleSheet(stylesheetFileContent);
qApp->setStyleSheet(mStylesheetFileContent);

emit SignalMapper::ins()->changedAppTheme();
emit SignalMapper::ins()->sigChangedAppTheme();
}

QString AppManager::getStylesheetFileContent() const
{
return stylesheetFileContent;
return mStylesheetFileContent;
}
11 changes: 5 additions & 6 deletions stacer/Managers/app_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <QApplication>
#include <QMap>
#include <QStandardPaths>
#include <QSettings>
#include <QJsonDocument>
#include <QJsonArray>
Expand Down Expand Up @@ -39,14 +38,14 @@ class AppManager
AppManager();

private:
QTranslator translator;
QTranslator mTranslator;
QSystemTrayIcon *mTrayIcon;

QSettings *styleValues;
QSettings *mStyleValues;

QMap<QString, QString> languageList;
QMap<QString, QString> themeList;
QString stylesheetFileContent;
QMap<QString, QString> mLanguageList;
QMap<QString, QString> mThemeList;
QString mStylesheetFileContent;

SettingManager *mSettingManager;
};
Expand Down
Loading

0 comments on commit 482a8cc

Please sign in to comment.