1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
/*
* Copyright (C) 2023, KylinSoft Co., Ltd.
*
* This program 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 3, or (at your option)
* any later version.
*
* This program 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 this program; if not, see <http://www.gnu.org/licenses/>.
*
**/
#include "update.h"
#include "ui_update.h"
#include <QMovie>
#include <QDebug>
Update::Update()
{
ui = new Ui::Update;
pluginWidget = new QWidget;
pluginWidget->setAttribute(Qt::WA_DeleteOnClose);
ui->setupUi(pluginWidget);
pluginName = tr("Update");
pluginType = UPDATE;
ui_init();
connect(ui->checkBtn, SIGNAL(clicked()), this, SLOT(update_btn_clicked()));
}
Update::~Update()
{
delete ui;
ui = nullptr;
}
QString Update::plugini18nName(){
return pluginName;
}
int Update::pluginTypes(){
return pluginType;
}
QWidget *Update::pluginUi(){
return pluginWidget;
}
const QString Update::name() const {
return QStringLiteral("Update");
}
bool Update::isShowOnHomePage() const
{
return false;
}
QIcon Update::icon() const
{
return QIcon();
}
bool Update::isEnable() const
{
return false;
}
void Update::ui_init(){
//~ contents_path /Update/System Update
ui->titleLabel->setText(tr("System Update"));
ui->titleLabel->setStyleSheet("QLabel{color: palette(windowText);}");
QString filename = QDir::homePath() + "/.config/ukccUpdate.conf";
syncSettings = new QSettings(filename, QSettings::IniFormat);
syncSettings->beginGroup("updateTime");
QString time = syncSettings->value("time", "").toString();
if (time.isEmpty()) {
QDateTime current =QDateTime::currentDateTime();
QString current_date_time =current.toString(QString("yyyy-MM-dd hh:mm:ss"));
time = current_date_time;
}
ui->updatetimeLabel->setText(time);
syncSettings->endGroup();
ui->logoLabel->setPixmap(QPixmap(":/img/plugins/update/update.svg"));
}
QStringList Update::readFile(QString filepath)
{
QStringList fileCont;
QFile file(filepath);
if(file.exists()) {
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qWarning() << "ReadFile() failed to open" << filepath;
return QStringList();
}
QTextStream textStream(&file);
while(!textStream.atEnd()) {
QString line= textStream.readLine();
line.remove('\n');
fileCont<<line;
}
file.close();
return fileCont;
} else {
qWarning() << filepath << " not found"<<endl;
return QStringList();
}
}
void Update::update_btn_clicked(){
QString cmd = "/usr/bin/update-manager";
QString versionPath = "/etc/os-release";
QStringList osRes = readFile(versionPath);
QString version;
for (QString str : osRes) {
if (str.contains("PRETTY_NAME=")) {
int index = str.indexOf("PRETTY_NAME=");
int startIndex = index + 13;
int length = str.length() - startIndex - 1;
version = str.mid(startIndex, length);
}
}
if (version == "Kylin V10" || version == "Kylin V10.1") {
cmd = "/usr/bin/kylin-update-manager";
}
QProcess process(this);
process.startDetached(cmd);
QDateTime current =QDateTime::currentDateTime();
QString current_date_time =current.toString(QString("yyyy-MM-dd hh:mm:ss"));
syncSettings->beginGroup("updateTime");
syncSettings->setValue("time", current_date_time);
syncSettings->endGroup();
syncSettings->sync();
}
|