added change apt source status

This commit is contained in:
Oguzhan INAN
2018-02-21 22:24:23 +03:00
parent 010e928ad5
commit c7d98ea7d4
6 changed files with 33 additions and 3 deletions

View File

@@ -13,7 +13,7 @@ void DiskInfo::updateDiskInfo()
{
disks.clear();
try {
QStringList result = CommandUtil::exec("df -Pl").split(QChar('\n'));
QStringList result = CommandUtil::exec("df", { "-Pl" }).split(QChar('\n'));
QRegExp sep("\\s+");
for (const QString &line : result.filter(QRegExp("^/")))

View File

@@ -22,6 +22,31 @@ void AptSourceTool::removeAPTSource(const QString source)
}
}
void AptSourceTool::changeStatus(const APTSourcePtr aptSource, const bool status)
{
QStringList sourceFileContent = FileUtil::readListFromFile(aptSource->filePath);
int pos = sourceFileContent.indexOf(aptSource->source);
if (pos != -1) {
QString line = sourceFileContent.at(pos);
line.replace("#", "").trimmed();
if (status) {
sourceFileContent.replace(pos, line);
} else {
sourceFileContent.replace(pos, "# " + line);
}
}
QStringList args = { aptSource->filePath };
QByteArray data = sourceFileContent.join('\n').toUtf8();
CommandUtil::sudoExec("tee", args, data);
}
QList<APTSourcePtr> AptSourceTool::getSourceList()
{
QList<APTSourcePtr> aptSourceList;

View File

@@ -24,6 +24,7 @@ public:
static bool checkSourceRepository();
static QList<APTSourcePtr> getSourceList();
static void removeAPTSource(const QString source);
static void changeStatus(const APTSourcePtr aptSource, const bool status);
};
#endif // AptSourceTool_H

View File

@@ -122,5 +122,8 @@ void ToolManager::removeAPTSource(const QString source)
AptSourceTool::removeAPTSource(source);
}
void ToolManager::changeStatus(const APTSourcePtr aptSource, const bool status)
{
AptSourceTool::changeStatus(aptSource, status);
}

View File

@@ -31,6 +31,7 @@ public slots:
bool checkSourceRepository() const;
QList<APTSourcePtr> getSourceList() const;
void removeAPTSource(const QString source);
void changeStatus(const APTSourcePtr aptSource, const bool status);
signals:
void uninstallFinished();

View File

@@ -52,5 +52,5 @@ void APTSourceRepositoryItem::on_deleteAptSourceBtn_clicked()
void APTSourceRepositoryItem::on_aptSourceCheck_clicked(bool checked)
{
ToolManager::ins()->changeStatus(mAptSource, checked);
}