diff --git a/FileOperator.cpp b/FileOperator.cpp new file mode 100644 index 0000000..5e05f0d --- /dev/null +++ b/FileOperator.cpp @@ -0,0 +1,123 @@ +#include "FileOperator.h" +#include "commonHeaders.h" + +bool isFolder(const QString& pathName) +{ + // File do not exist or FileName is Empty + if (pathName.isEmpty() || !QDir().exists(pathName)) + { + qDebug()<<"isEmpty OR do not exist => "<< pathName; + return false; + } + + QFileInfo FileInfo(pathName); + + if(FileInfo.isDir()) + { + qDebug()<<"Folder Exist"<<" => "<< pathName; + return true; + } + + qDebug()<<"is not Folder"<<" => "<< pathName; + return false; +} + +bool isFile(const QString& pathName) +{ + // File do not exist or FileName is Empty + if (pathName.isEmpty() || !QDir().exists(pathName)) + { + qDebug()<<"isEmpty OR do not exist => "<< pathName; + return false; + } + + QFileInfo FileInfo(pathName); + + if(FileInfo.isFile()) + { + qDebug()<<"File Exist"<<" => "<< pathName; + return true; + } + + qDebug()<<"is not File"<<" => "<< pathName; + return false; +} + + +bool FileCopy(QString _res, QString _target) +{ + QFile qfile; + if(qfile.copy(_res, _target)) + { + qDebug()<<"FileCopy Success => "<< _target; + return true; + } + else + { + qDebug()<<"FileCopy Fail => "<< _target; + return false; + } +} + +bool copyPic(QString resFile,const QString& targetDir,QString num) +{ + if(!FileCopy(resFile,targetDir+"\\"+num+".jpg")) + { + qDebug()<<"pic copy OK!"; + return false; + } + return true; +} + +bool storeIni(const QStringList &fileNameList,QString& targetDir) +{ + QString IniName = "picname.ini"; + QFile file(IniName); + if(!isFile(IniName)) + { + file.open(QIODevice::ReadWrite|QIODevice::Text); + } + QStringList existNames; + QTextStream _ini(&file); + while(!_ini.atEnd()) + { + QString str=_ini.readLine(); + qDebug()<"< "< + +bool isFolder(const QString& pathName); +bool isFile(const QString& pathName); +bool fileCopy(const QString _res, const QString _target); +bool copyPic(QString resFile, const QString& targetDir,QString num); +bool storeIni(const QStringList &fileNameList, QString& targetDir); +bool createFile(const QString& fileName); + +#endif // FILEOPERATOR_H diff --git a/WinFocus.pro b/WinFocus.pro new file mode 100644 index 0000000..ebda0f9 --- /dev/null +++ b/WinFocus.pro @@ -0,0 +1,50 @@ +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 + +# You can make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + FileOperator.cpp \ + aboutwindow.cpp \ + commonHeaders.cpp \ + config.cpp \ + configwindow.cpp \ + main.cpp \ + mainwindow.cpp \ + pathOperator.cpp \ + picOperator.cpp + +HEADERS += \ + FileOperator.h \ + aboutwindow.h \ + commonHeaders.h \ + config.h \ + configwindow.h \ + mainwindow.h \ + pathOperator.h \ + picOperator.h + +FORMS += \ + aboutwindow.ui \ + configwindow.ui \ + mainwindow.ui + +TRANSLATIONS += \ + WinFocus_zh_CN.ts +CONFIG += lrelease +CONFIG += embed_translations + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target + +RESOURCES += \ + res/res.qrc + +RC_ICONS = $$PWD/res/icon.ico diff --git a/WinFocus_zh_CN.ts b/WinFocus_zh_CN.ts new file mode 100644 index 0000000..0dc27ed --- /dev/null +++ b/WinFocus_zh_CN.ts @@ -0,0 +1,3 @@ + + + diff --git a/aboutwindow.cpp b/aboutwindow.cpp new file mode 100644 index 0000000..6fbc7e5 --- /dev/null +++ b/aboutwindow.cpp @@ -0,0 +1,48 @@ +#include "aboutwindow.h" +#include "ui_aboutwindow.h" +#include +#include + +aboutWindow::aboutWindow(QWidget *parent) : + QWidget(parent), + ui(new Ui::aboutWindow) +{ + ui->setupUi(this); + setWindowIcon(QIcon(":/icon.ico")); + setWindowTitle("关于"); + setFixedSize(300,200); + + setWindowFlags(windowFlags()&~Qt::WindowMinMaxButtonsHint); + + ui->name->setText(tr("WinFocus (x64)")); + + ui->version->setText(tr("版本: 1.0")); + ui->builtdate->setText(tr("Built on Mar 22 2022")); + ui->author->setText(tr("Built by 代码之火")); + ui->blog->setText(tr("Blog@https://cosyspark.space

")); + ui->github->setText(tr("Github@https://github.com/Albreskyblog,&QLabel::linkActivated,this,&aboutWindow::blog_linkActivated); + connect(ui->github,&QLabel::linkActivated,this,&aboutWindow::github_linkActivated); +} + +aboutWindow::~aboutWindow() +{ + delete ui; +} + + + +void aboutWindow::blog_linkActivated() +{ + QDesktopServices::openUrl(QUrl(QLatin1String("https://cosyspark.space"))); + qDebug()<<"blog hyperLink triggered"; +} + + +void aboutWindow::github_linkActivated() +{ + QDesktopServices::openUrl(QUrl(QLatin1String("https://github.com/Albresky"))); + qDebug()<<"blog hyperLink triggered"; +} + diff --git a/aboutwindow.h b/aboutwindow.h new file mode 100644 index 0000000..24c4967 --- /dev/null +++ b/aboutwindow.h @@ -0,0 +1,27 @@ +#ifndef ABOUTWINDOW_H +#define ABOUTWINDOW_H + +#include + +namespace Ui { +class aboutWindow; +} + +class aboutWindow : public QWidget +{ + Q_OBJECT + +public: + explicit aboutWindow(QWidget *parent = nullptr); + ~aboutWindow(); + +private slots: + void blog_linkActivated(); + + void github_linkActivated(); + +private: + Ui::aboutWindow *ui; +}; + +#endif // ABOUTWINDOW_H diff --git a/aboutwindow.ui b/aboutwindow.ui new file mode 100644 index 0000000..1545032 --- /dev/null +++ b/aboutwindow.ui @@ -0,0 +1,122 @@ + + + aboutWindow + + + true + + + + 0 + 0 + 300 + 200 + + + + Form + + + + + 30 + 150 + 251 + 20 + + + + Blog + + + Qt::RichText + + + + + + 150 + 10 + 121 + 41 + + + + Name + + + + + + 180 + 50 + 81 + 31 + + + + Version + + + + + + 130 + 80 + 141 + 31 + + + + BuiltDate + + + + + + 150 + 110 + 121 + 31 + + + + Author + + + + + + 30 + 170 + 251 + 20 + + + + Github + + + + + + 10 + 10 + 91 + 91 + + + + image: url(:/logo.png); + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + diff --git a/commonHeaders.cpp b/commonHeaders.cpp new file mode 100644 index 0000000..d335955 --- /dev/null +++ b/commonHeaders.cpp @@ -0,0 +1,3 @@ +#include "commonHeaders.h" + +QString prefix=""; diff --git a/commonHeaders.h b/commonHeaders.h new file mode 100644 index 0000000..8689e10 --- /dev/null +++ b/commonHeaders.h @@ -0,0 +1,17 @@ +#ifndef COMMONHEADERS_H +#define COMMONHEADERS_H + +#include +#include +#include +#include +#include +#include +#include + + +extern QString prefix; + +void updateGlobalVar(QString str); + +#endif // COMMONHEADERS_H diff --git a/config.cpp b/config.cpp new file mode 100644 index 0000000..2432e7c --- /dev/null +++ b/config.cpp @@ -0,0 +1,33 @@ +#include "config.h" +#include "FileOperator.h" + +Config::Config(QString cfgFile) +{ + if(!isFile(cfgFile)&&createFile(cfgFile)) + { + pri_cfgFile=QCoreApplication::applicationDirPath()+cfgFile; + } + else + { + pri_cfgFile=cfgFile; + qDebug()<setValue(QString("/%1/%2").arg(nodeName).arg(keyName),value); +} + +QVariant Config::Get(QString nodeName, QString keyName) +{ + QVariant qvar=pri_pSettings->value(QString("/%1/%2").arg(nodeName).arg(keyName)); + return qvar; +} diff --git a/config.h b/config.h new file mode 100644 index 0000000..11a2bcf --- /dev/null +++ b/config.h @@ -0,0 +1,20 @@ +#ifndef CONFIG_H +#define CONFIG_H + +#include +#include +#include + +class Config +{ +public: + Config(QString cfgFile=""); + virtual ~Config(void); + void Set(QString,QString,QVariant); + QVariant Get(QString,QString); +private: + QString pri_cfgFile; + QSettings *pri_pSettings; +}; + +#endif // CONFIG_H diff --git a/configwindow.cpp b/configwindow.cpp new file mode 100644 index 0000000..b73546a --- /dev/null +++ b/configwindow.cpp @@ -0,0 +1,107 @@ +#include "configwindow.h" +#include "config.h" +#include "commonHeaders.h" +#include "ui_configwindow.h" +#include + +configWindow::configWindow(QWidget *parent) : + QWidget(parent), + ui(new Ui::configWindow) +{ + ui->setupUi(this); + + setWindowFlags(windowFlags()|Qt::Dialog); + setWindowModality(Qt::ApplicationModal); + setWindowFlags(windowFlags()&~Qt::WindowMinMaxButtonsHint); + + setWindowIcon(QIcon(":/icon.ico")); + setWindowTitle("配置"); + setFixedSize(370,160); + + setWindowFlags(windowFlags()&~Qt::WindowMinMaxButtonsHint); + + ui->lang->setText("界面语言"); + ui->outputPath->setText("图片保存位置"); + ui->pathLabel->setText("路径"); + ui->enter->setText("确定"); + ui->cancel->setText("取消"); + ui->openFolder->setText("打开文件路径"); + + //Load Config File + Config loadConfig=Config("Config.ini"); + + //Load language + QStringList langList={"zh-CN","English","Japanese"}; + for(int i=0;ilangBox->addItem("简体中文"); + continue; + } + ui->langBox->addItem(langList[i]); + } + + QVariant lang = loadConfig.Get("Config","Language"); + QString langShow=lang.value(); + langShow =(langShow=="zh-CN")?"简体中文":langShow; + ui->langBox->setCurrentText(langShow); + + + // if(ui->langBox->findText(langShow)==-1) + // ui->langBox->addItem("English"); + qDebug()<<"load language => "<locationLabel->setText(location.value()); + ui->locationLabel->setStyleSheet("Font-size:14px"); + qDebug()<<"load picture store path => "<locationLabel->setText(ManualSelectDir); + ui->locationLabel->setStyleSheet("Font-size:8px"); + ui->locationLabel->setStyleSheet("font-style:italic"); + } +} + + +void configWindow::on_enter_clicked() +{ + Config loadConfig=Config("Config.ini"); + loadConfig.Set("Config","Language",QVariant(ui->langBox->currentText())); + loadConfig.Set("Config","Location",QVariant(ui->locationLabel->text())); + this->close(); +} + + +void configWindow::on_openFolder_clicked() +{ + QDesktopServices::openUrl(QUrl::fromLocalFile(ui->locationLabel->text())); +} + + +void configWindow::on_cancel_clicked() +{ + this->close(); +} + diff --git a/configwindow.h b/configwindow.h new file mode 100644 index 0000000..0c11aaa --- /dev/null +++ b/configwindow.h @@ -0,0 +1,35 @@ +#ifndef CONFIGWINDOW_H +#define CONFIGWINDOW_H + +#include +#include + +namespace Ui { +class configWindow; +} + +class configWindow : public QWidget +{ + Q_OBJECT + +public: + explicit configWindow(QWidget *parent = nullptr); + ~configWindow(); + +private slots: + void on_langBox_activated(int index); + + void on_choosePath_clicked(); + + void on_enter_clicked(); + + void on_openFolder_clicked(); + + void on_cancel_clicked(); + +private: + Ui::configWindow *ui; +// Config loadConfig; +}; + +#endif // CONFIGWINDOW_H diff --git a/configwindow.ui b/configwindow.ui new file mode 100644 index 0000000..009756b --- /dev/null +++ b/configwindow.ui @@ -0,0 +1,130 @@ + + + configWindow + + + + 0 + 0 + 370 + 160 + + + + Form + + + + + 10 + 10 + 51 + 21 + + + + Language + + + + + + 60 + 10 + 121 + 22 + + + + + + + 10 + 40 + 111 + 21 + + + + Config + + + + + + 20 + 60 + 41 + 41 + + + + Path + + + + + + 50 + 70 + 261 + 21 + + + + + + + 320 + 70 + 22 + 20 + + + + ... + + + + + + 10 + 120 + 141 + 21 + + + + Open Folder + + + + + + 180 + 120 + 80 + 20 + + + + Enter + + + + + + 280 + 120 + 80 + 20 + + + + Cancel + + + + + + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..8613368 --- /dev/null +++ b/main.cpp @@ -0,0 +1,24 @@ +#include "mainwindow.h" +#include "commonHeaders.h" +#include "config.h" +#include +#include +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + QTranslator translator; + const QStringList uiLanguages = QLocale::system().uiLanguages(); + for (const QString &locale : uiLanguages) { + const QString baseName = "WinFocus_" + QLocale(locale).name(); + if (translator.load(":/i18n/" + baseName)) { + a.installTranslator(&translator); + break; + } + } + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..6927d78 --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,152 @@ +#include "mainwindow.h" +#include "aboutwindow.h" +#include "configwindow.h" +#include "ui_mainwindow.h" +#include "pathOperator.h" +#include "FileOperator.h" +#include "commonHeaders.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::MainWindow) +{ + ui->setupUi(this); + setWindowTitle("WinFocus"); + setWindowIcon(QIcon(":/icon.ico")); + setFixedSize(320,180); + + QMediaPlayer* player = new QMediaPlayer(); + QAudioOutput* audioOp= new QAudioOutput(); + connect(player,SIGNAL(positionChanged(qint64)),this,SLOT(positionChanged(qint64))); + player->setAudioOutput(audioOp); + player->setSource(QUrl::fromLocalFile(":/bgm.m4a")); + audioOp->setVolume(60); + player->play(); + + this->qGif_pressed=new QMovie(":/myBtn_light.gif"); + this->qGif_pressed->setScaledSize(QSize(60,60)); + this->qGif_released=new QMovie(":/myBtn_dark.gif"); + this->qGif_released->setScaledSize(QSize(60,60)); + + + ui->apply_btn->setStyleSheet("border-image: url(:/myBtn.png)"); + ui->apply_btn->setWindowFlags(Qt::WindowStaysOnTopHint); + ui->apply_lbl->close(); + + + btn_list={"border-image: url(:/btn/btn_1.png)","border-image: url(:/btn/btn_2.png)","border-image: url(:/btn/btn_3.png)", + "border-image: url(:/btn/btn_3.png)","border-image: url(:/btn/btn_4.png)","border-image: url(:/btn/btn_6.png)", + "border-image: url(:/btn/btn_5.png)","border-image: url(:/btn/btn_6.png)","border-image: url(:/btn/btn_9.png)"}; + + QObject::connect(ui->actionAbout,&QAction::triggered,this,&MainWindow::about_clicked); + QObject::connect(ui->actionConfig,&QAction::triggered,this,&MainWindow::config_clicked); + + cfg=new Config("Config.ini"); + ui->apply_btn->setEnabled(false); + loct=new QString(); + while(!loct->length()) + { + ui->statusbar->setStyleSheet("font-size:10px;color:red"); + ui->statusbar->showMessage(tr("路径未配置"),30000); + *loct=cfg->Get("Config","Location").value(); + } + qDebug()<<*loct; + ui->statusbar->setStyleSheet("font-size:10px;color:black"); + ui->statusbar->showMessage(tr("路径已配置"),200000); + ui->apply_btn->setEnabled(true); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + + +void MainWindow::about_clicked() +{ + aboutWindow *aboutWin =new aboutWindow(); + qDebug()<<"about Menubar-menu clicked"; + aboutWin->show(); +} + + +void MainWindow::config_clicked() +{ + configWindow *configWin =new configWindow(); + qDebug()<<"config Menubar-menu clicked"; + configWin->show(); +} + + + +void MainWindow::on_apply_btn_pressed() +{ + qDebug()<<"pushBtn pressed"; + ui->apply_lbl->show(); + for(int i=0;i<=8;i++) + { + ui->apply_lbl->setStyleSheet(this->btn_list[i]); + QThread::msleep(125); + } + getPicPath(); + QStringList filenamelist; + if(getPicName(prefix,filenamelist)) + { + qDebug()<<"getPicNameList success!"; + } + qDebug()<<"++++++++++++++++picNames+++++++++++++++++"; + for(int i=0;istatusbar->setStyleSheet("font-size:10px;color:green"); + if(storeIni(filenamelist,*loct)) + { + ui->statusbar->showMessage(tr("锁屏壁纸提取成功!"),200000); + qDebug()<<"store FileName Success!"; + } + ui->statusbar->showMessage(tr("锁屏壁纸提取失败!"),200000); +} + + +void MainWindow::on_apply_btn_released() +{ + // qDebug()<<"pushBtn released"; + // ui->apply_lbl->setMovie(this->qGif_released); + // ui->apply_lbl->show(); + // this->qGif_released->start(); + // ui->apply_btn->setEnabled(true); + // ui->apply_btn->setCheckable(true); +} + + +//void MainWindow::on_apply_btn_clicked() +//{ +// qDebug()<<"pushBtn clicked"; +// ui->apply_lbl->setMovie(this->qGif_pressed); +// ui->apply_lbl->show(); +// this->qGif_pressed->start(); +// ui->apply_btn->setCheckable(true); +//} + + +void MainWindow::on_pushButton_clicked() +{ + //Load FileStoreLocation + qDebug()<<"Open Folder clicked"; + QDesktopServices::openUrl(QUrl::fromLocalFile(*loct)); +} + diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..5dc9a70 --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,42 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include "picOperator.h" +#include "commonHeaders.h" +#include "config.h" + +QT_BEGIN_NAMESPACE +namespace Ui { class MainWindow; } +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + +private slots: + void about_clicked(); + + void config_clicked(); + + void on_apply_btn_pressed(); + + void on_apply_btn_released(); + +// void on_apply_btn_clicked(); + + void on_pushButton_clicked(); + +private: + Ui::MainWindow *ui; + QMovie* qGif_pressed; + QMovie* qGif_released; + QStringList btn_list; + Config* cfg; + QString* loct; +}; +#endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui new file mode 100644 index 0000000..88231e3 --- /dev/null +++ b/mainwindow.ui @@ -0,0 +1,114 @@ + + + MainWindow + + + + 0 + 0 + 320 + 180 + + + + MainWindow + + + + + 0 + 0 + + + + + + + + + 40 + 40 + 61 + 61 + + + + + + + + + + + + + 40 + 40 + 61 + 61 + + + + + + + + + + 200 + 40 + 51 + 51 + + + + border-image: url(:/folder.png); + + + + + + + + + + 0 + 0 + 320 + 18 + + + + + 首选项 + + + + + + 帮助 + + + + + + + + + false + + + + + 关于 + + + + + 配置 + + + + + + diff --git a/pathOperator.cpp b/pathOperator.cpp new file mode 100644 index 0000000..af10fce --- /dev/null +++ b/pathOperator.cpp @@ -0,0 +1,51 @@ +#include "pathOperator.h" +#include "commonHeaders.h" + +bool getUserName(QString *str) +{ + const int MAX_LENGTH=256; + wchar_t buffer[MAX_LENGTH]; + DWORD len=MAX_LENGTH; + if(GetUserName(buffer, &len)) + { + *str=QString::fromWCharArray(buffer,-1); + qDebug()<<"Username:"<<*str; + return true; + } + return false; +} + +bool getWinPath(QString* str) +{ + const int MAX_LENGTH=256; + wchar_t buffer[MAX_LENGTH]; + if(GetWindowsDirectory(buffer, MAX_PATH)) + { + *str=QString::fromWCharArray(buffer,-1); + qDebug()<<"SysDir:"<<*str; + return true; + } + return false; +} + +void getPicPath() +{ + QString *SysDir = new QString; + QString *UserName = new QString; + QString *PicPath= new QString; + static QString strAppend="AppData\\Local\\Packages\\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\\LocalState\\Assets"; + if(getWinPath(SysDir)&&getUserName(UserName)) + { + QStringList list=SysDir->split(":"); + QString WinLetter=list[0]; + *PicPath=WinLetter+":\\Users\\"+*UserName+"\\"+strAppend; + qDebug()<<*PicPath; + } + delete SysDir; + delete UserName; + prefix=*PicPath; + qDebug()<<"getPicPath()|prefix=>"< + + icon.ico + logo.png + apply.gif + myBtn_light.gif + myBtn_dark.gif + myBtn.png + btn/btn_1.png + btn/btn_2.png + btn/btn_3.png + btn/btn_4.png + btn/btn_5.png + btn/btn_6.png + btn/btn_7.png + btn/btn_8.png + btn/btn_9.png + folder.png + bgm.m4a + +