diff --git a/scripts/6.py b/scripts/24hourWallpaper.py similarity index 98% rename from scripts/6.py rename to scripts/24hourWallpaper.py index bc3e2d9..d5f33fc 100644 --- a/scripts/6.py +++ b/scripts/24hourWallpaper.py @@ -1,3 +1,5 @@ +# source: 24h壁纸 +# updateTime wallpaperFile import os import sys import json @@ -6,7 +8,7 @@ from sunCalculator import SunCalculator, DateTime import requests -file = sys.argv[1] +file = sys.argv[5] unpackDir = "/tmp/" + file.split("/")[-1].split(".")[0] diff --git a/scripts/2.py b/scripts/Bing-rand.py similarity index 93% rename from scripts/2.py rename to scripts/Bing-rand.py index 8e98773..87dd2d0 100644 --- a/scripts/2.py +++ b/scripts/Bing-rand.py @@ -1,3 +1,5 @@ +# source: 必应壁纸(随机) +# updateTime from setWallpaper import set_wallpaper from checkWakkpaperDir import check import requests diff --git a/scripts/3.py b/scripts/Bing-tody.py similarity index 80% rename from scripts/3.py rename to scripts/Bing-tody.py index f413058..131048e 100644 --- a/scripts/3.py +++ b/scripts/Bing-tody.py @@ -1,3 +1,5 @@ +# source: 必应壁纸(今日) +# updateTime from setWallpaper import set_wallpaper from checkWakkpaperDir import check import requests @@ -9,7 +11,7 @@ def download(path): headers = { "user-agent": - "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0" + "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0" } img = requests.get(api_url, headers=headers) diff --git a/scripts/1.py b/scripts/FY-4.py similarity index 98% rename from scripts/1.py rename to scripts/FY-4.py index 488b18c..afe5515 100644 --- a/scripts/1.py +++ b/scripts/FY-4.py @@ -1,3 +1,5 @@ +# source: 风云四号 +# updateTime earthSize from PIL import Image from setWallpaper import set_wallpaper from checkWakkpaperDir import check diff --git a/scripts/0.py b/scripts/Himawari-8.py similarity index 96% rename from scripts/0.py rename to scripts/Himawari-8.py index 26d2770..0f5eab8 100644 --- a/scripts/0.py +++ b/scripts/Himawari-8.py @@ -1,3 +1,6 @@ +# source: 向日葵八号 +# updateTime earthSize + from PIL import Image from setWallpaper import set_wallpaper from checkWakkpaperDir import check diff --git a/scripts/5.py b/scripts/LocalWallpaper.py similarity index 93% rename from scripts/5.py rename to scripts/LocalWallpaper.py index 1dee3be..4bcd7b8 100644 --- a/scripts/5.py +++ b/scripts/LocalWallpaper.py @@ -1,8 +1,10 @@ +# source: 本地壁纸 +# updateTime wallpaperDir import sys import os from setWallpaper import set_wallpaper -wallpaperDir = sys.argv[1] +wallpaperDir = sys.argv[4] currentFile = wallpaperDir + "/current.txt" currentWallpaper = "None" diff --git a/scripts/4.py b/scripts/wifu.py similarity index 95% rename from scripts/4.py rename to scripts/wifu.py index 8cc9797..7324036 100644 --- a/scripts/4.py +++ b/scripts/wifu.py @@ -1,3 +1,5 @@ +# source: 动漫壁纸 +# updateTime from setWallpaper import set_wallpaper from checkWakkpaperDir import check import requests diff --git a/src/config.cpp b/src/config.cpp index c51297c..b962ef7 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -3,10 +3,10 @@ #include #include #include +#include #include #include #include -#include Config::Config(QWidget *parent) : QWidget(parent), ui(new Ui::Config) { @@ -32,7 +32,7 @@ Config::Config(QWidget *parent) : QWidget(parent), ui(new Ui::Config) initUI(); initConnect(); readConfig(); - controlOption(); + controlOption(ui->earthSource->currentText()); } Config::~Config() @@ -44,19 +44,28 @@ Config::~Config() void Config::initUI() { this->setWindowIcon(QIcon(":/img/cn.huguoyang.earthwallpaper.png")); - ui->earthSource->addItem("向日葵八号"); - ui->earthSource->addItem("风云四号"); - ui->earthSource->addItem("必应壁纸(随机)"); - ui->earthSource->addItem("必应壁纸(每日)"); - ui->earthSource->addItem("动漫壁纸"); - ui->earthSource->addItem("本地壁纸"); - ui->earthSource->addItem("24h壁纸"); ui->updateTime->addItem("10"); ui->updateTime->addItem("30"); ui->updateTime->addItem("60"); ui->updateTime->addItem("120"); ui->updateTime->addItem("180"); ui->updateTime->addItem("720"); + QString exePath = QCoreApplication::applicationDirPath(); + QDir scriptsDir(exePath + "/scripts"); + QStringList nameFilters; + nameFilters << "*.py"; + scriptsDir.setNameFilters(nameFilters); + QStringList files = scriptsDir.entryList(QDir::Files, QDir::Name); + foreach (QString file, files) + { + QFile scriptFile(exePath + "/scripts/" + file); + scriptFile.open(QIODevice::ReadOnly); + QString info = scriptFile.readLine(); + if (info.split(" ")[1] == "source:") + { + ui->earthSource->addItem(info.split(" ")[2].remove("\n")); + } + } } void Config::initConnect() @@ -72,7 +81,7 @@ void Config::readConfig() this->settings = new QSettings(configPath + "/config", QSettings::IniFormat); settings->setIniCodec("UTF8"); settings->beginGroup("APP"); - ui->earthSource->setCurrentIndex(settings->value("earthSource").toInt()); + ui->earthSource->setCurrentText(settings->value("earthSource").toString()); ui->updateTime->setCurrentText(settings->value("updateTime").toString()); ui->earthSize->setValue(settings->value("earthSize").toInt()); ui->wallpaperDir->setText(settings->value("wallpaperDir").toString()); @@ -82,7 +91,8 @@ void Config::readConfig() void Config::writeConfig() { settings->beginGroup("APP"); - settings->setValue("earthSource", ui->earthSource->currentIndex()); + settings->setIniCodec("UTF8"); + settings->setValue("earthSource", ui->earthSource->currentText()); settings->setValue("updateTime", ui->updateTime->currentText()); settings->setValue("earthSize", ui->earthSize->value()); settings->setValue("wallpaperDir", ui->wallpaperDir->text()); @@ -91,45 +101,71 @@ void Config::writeConfig() QMessageBox::information(this, tr("设置"), tr("设置保存成功!")); emit configChanged(); } -void Config::controlOption() +void Config::controlOption(QString source) { - if (ui->earthSource->currentIndex() == 0 || ui->earthSource->currentIndex() == 1) - { - ui->label_3->show(); - ui->earthSize->show(); - } - else - { - ui->label_3->hide(); - ui->earthSize->hide(); - } - if (ui->earthSource->currentIndex() == 5) + QString exePath = QCoreApplication::applicationDirPath(); + QDir scriptsDir(exePath + "/scripts"); + QStringList nameFilters; + nameFilters << "*.py"; + scriptsDir.setNameFilters(nameFilters); + QStringList files = scriptsDir.entryList(QDir::Files, QDir::Name); + foreach (QString file, files) { - ui->label_4->show(); - ui->wallpaperDir->show(); - ui->select->show(); - } - else - { - ui->label_4->hide(); - ui->wallpaperDir->hide(); - ui->select->hide(); - } - if (ui->earthSource->currentIndex() == 6) - { - ui->label_5->show(); - ui->wallpaperFile->show(); - ui->selectFile->show(); - ui->updateTime->hide(); - ui->label_2->hide(); - } - else - { - ui->label_5->hide(); - ui->wallpaperFile->hide(); - ui->selectFile->hide(); - ui->updateTime->show(); - ui->label_2->show(); + QFile scriptFile(exePath + "/scripts/" + file); + scriptFile.open(QIODevice::ReadOnly); + QString info = scriptFile.readLine(); + if (info.split(" ")[1] == "source:") + { + if (info.split(" ")[2].remove("\n") == source) + { + QString itemInfo = scriptFile.readLine(); + if (itemInfo.contains("updateTime")) + { + ui->label_2->show(); + ui->updateTime->show(); + } + else + { + settings->setValue("APP/updateTime", "10"); + ui->label_2->hide(); + ui->updateTime->hide(); + } + if (itemInfo.contains("earthSize")) + { + ui->label_3->show(); + ui->earthSize->show(); + } + else + { + ui->label_3->hide(); + ui->earthSize->hide(); + } + if (itemInfo.contains("wallpaperDir")) + { + ui->label_4->show(); + ui->wallpaperDir->show(); + ui->select->show(); + } + else + { + ui->label_4->hide(); + ui->wallpaperDir->hide(); + ui->select->hide(); + } + if (itemInfo.contains("wallpaperFile")) + { + ui->label_5->show(); + ui->wallpaperFile->show(); + ui->selectFile->show(); + } + else + { + ui->label_5->hide(); + ui->wallpaperFile->hide(); + ui->selectFile->hide(); + } + } + } } } void Config::selectDir() diff --git a/src/config.h b/src/config.h index ff9c0db..18300ba 100644 --- a/src/config.h +++ b/src/config.h @@ -26,7 +26,7 @@ class Config : public QWidget void initConnect(); void readConfig(); void writeConfig(); - void controlOption(); + void controlOption(QString source); void selectDir(); void selectFile(); diff --git a/src/trayicon.cpp b/src/trayicon.cpp index b8ea7a0..cff2ae3 100644 --- a/src/trayicon.cpp +++ b/src/trayicon.cpp @@ -116,38 +116,40 @@ void TrayIcon::reloadSettings() void TrayIcon::handle() { qDebug() << "handling..."; - int earthSource = settings->value("APP/earthSource").toInt(); - QString earthSize = settings->value("APP/earthSize").toString(); - QString wallpaperDir = settings->value("APP/wallpaperDir").toString(); - QString wallpaperFile = settings->value("APP/wallpaperFile").toString(); - QString exePath = QCoreApplication::applicationDirPath(); + settings->beginGroup("APP"); + settings->setIniCodec("UTF8"); + QString earthSource = settings->value("earthSource").toString(); + QString earthSize = settings->value("earthSize").toString(); + QString wallpaperDir = settings->value("wallpaperDir").toString(); + QString wallpaperFile = settings->value("wallpaperFile").toString(); + settings->endGroup(); QString command = ""; - switch (earthSource) + QString exePath = QCoreApplication::applicationDirPath(); + QDir scriptsDir(exePath + "/scripts"); + QStringList nameFilters; + nameFilters << "*.py"; + scriptsDir.setNameFilters(nameFilters); + QStringList files = scriptsDir.entryList(QDir::Files, QDir::Name); + qDebug() << earthSource; + foreach (QString file, files) { - case 0: - command = "python3 " + exePath + "/scripts/" + "0.py " + QString::number(this->height) + " " + - QString::number(this->width) + " " + earthSize; - break; - case 1: - command = "python3 " + exePath + "/scripts/" + "1.py " + QString::number(this->height) + " " + - QString::number(this->width) + " " + earthSize; - break; - case 2: - command = "python3 " + exePath + "/scripts/" + "2.py"; - break; - case 3: - command = "python3 " + exePath + "/scripts/" + "3.py"; - break; - case 4: - command = "python3 " + exePath + "/scripts/" + "4.py"; - break; - case 5: - command = "python3 " + exePath + "/scripts/" + "5.py " + wallpaperDir; - break; - case 6: - settings->setValue("APP/updateTime", "10"); - command = "python3 " + exePath + "/scripts/" + "6.py " + wallpaperFile; - break; + QFile scriptFile(exePath + "/scripts/" + file); + scriptFile.open(QIODevice::ReadOnly); + QString info = scriptFile.readLine(); + if (info.split(" ")[1] == "source:") + { + + qDebug() << info.split(" ")[2].remove("\n"); + if (info.split(" ")[2].remove("\n") == earthSource) + { + command = "python3 " + exePath + "/scripts/" + file + " " + QString::number(this->height) + " " + + QString::number(this->width) + " " + earthSize + " " + wallpaperDir + " " + wallpaperFile; + if (file == "24h.py") + { + settings->setValue("APP/updateTime", "10"); + } + } + } } // 根据设置下载、更新壁纸 diff --git a/template/config b/template/config index 5b2ade8..dd2479c 100644 --- a/template/config +++ b/template/config @@ -1,6 +1,6 @@ [APP] -earthSource=0 +earthSource=风云四号 updateTime=30 earthSize=60 -wallpaperDir="" -wallpaperFile="" \ No newline at end of file +wallpaperDir="/" +wallpaperFile="/" \ No newline at end of file