Upload files to "/"
This commit is contained in:
parent
b0e5395d42
commit
742c7be190
5 changed files with 253 additions and 0 deletions
88
autostart.h
Normal file
88
autostart.h
Normal file
|
@ -0,0 +1,88 @@
|
|||
#ifndef AUTOSTART_H
|
||||
#define AUTOSTART_H
|
||||
|
||||
#include <qglobal.h>
|
||||
#include <QDir>
|
||||
#include <QCoreApplication>
|
||||
|
||||
#define MY_APP_NAME "NumLockManager"
|
||||
#define MY_APP_PATH QDir::toNativeSeparators(QCoreApplication::applicationFilePath())
|
||||
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <QSettings>
|
||||
|
||||
class Autostart{
|
||||
public:
|
||||
Autostart (){}
|
||||
~Autostart(){delete settings;}
|
||||
|
||||
bool status(){
|
||||
return !settings->value(MY_APP_NAME).toString().isEmpty();
|
||||
}
|
||||
|
||||
void set(bool s){
|
||||
s ? settings->setValue(MY_APP_NAME, MY_APP_PATH) : settings->remove(MY_APP_NAME);
|
||||
settings->sync();
|
||||
}
|
||||
|
||||
void switch_(){
|
||||
status() ? settings->remove(MY_APP_NAME) : settings->setValue(MY_APP_NAME, MY_APP_PATH);
|
||||
settings->sync();
|
||||
}
|
||||
private:
|
||||
QSettings * settings = new QSettings("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
#include <QFile>
|
||||
#include <QStandardPaths>
|
||||
|
||||
class Autostart{
|
||||
public:
|
||||
Autostart (){
|
||||
file_data = file_data.replace("$", MY_APP_PATH);
|
||||
}
|
||||
|
||||
bool status(){
|
||||
return QFile::exists(file_path);
|
||||
}
|
||||
|
||||
void set(bool s){
|
||||
s ? make_file() : (void)QFile::remove(file_path);
|
||||
}
|
||||
|
||||
void switch_(){
|
||||
status() ? (void)QFile::remove(file_path) : make_file();
|
||||
}
|
||||
|
||||
private:
|
||||
QString file_path = QStandardPaths::standardLocations(QStandardPaths::ConfigLocation)[0] + "/autostart/NumLockManager.desktop";
|
||||
QString file_data = QString("[Desktop Entry]\n"
|
||||
"Encoding=UTF-8\n"
|
||||
"Version=1.2\n"
|
||||
"Type=Application\n"
|
||||
"Name=NumLockManager\n"
|
||||
"Comment=\n"
|
||||
"Exec=$\n"
|
||||
"RunHook=0\n"
|
||||
"StartupNotify=false\n"
|
||||
"Terminal=false\n"
|
||||
"Hidden=false\n");
|
||||
|
||||
|
||||
|
||||
void make_file(){
|
||||
QFile file(file_path);
|
||||
file.open(QIODevice::WriteOnly | QIODevice::Text);
|
||||
file.write(file_data.toUtf8());
|
||||
file.close();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#endif // AUTOSTART_H
|
35
config.h
Normal file
35
config.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#include <QFile>
|
||||
#include <QCoreApplication>
|
||||
|
||||
class Config{
|
||||
public:
|
||||
Config(){ file->exists() ? load() : setMode(0);}
|
||||
~Config(){
|
||||
file->close();
|
||||
delete file;
|
||||
}
|
||||
void setMode(int m) { mode = m; save(); }
|
||||
int getMode() {return mode;}
|
||||
|
||||
private:
|
||||
int mode = 0;
|
||||
QFile * file = new QFile(QCoreApplication::applicationDirPath() + "/src/config.ini");
|
||||
|
||||
void load(){
|
||||
file->open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
mode = file->readAll().toInt();
|
||||
file->close();
|
||||
}
|
||||
|
||||
void save(){
|
||||
file->open(QIODevice::WriteOnly | QIODevice::Text);
|
||||
QString a;
|
||||
a.setNum(mode);
|
||||
file->write(a.toUtf8());
|
||||
file->close();
|
||||
}
|
||||
};
|
||||
#endif // CONFIG_H
|
32
modethread.h
Normal file
32
modethread.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
#ifndef MODETHREAD_H
|
||||
#define MODETHREAD_H
|
||||
|
||||
#include <QThread>
|
||||
|
||||
#include "wl_numlock.h"
|
||||
|
||||
class ModeThread : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ModeThread(){}
|
||||
~ModeThread(){ delete key_manager; }
|
||||
|
||||
void setMode(int m){ mode = m; }
|
||||
|
||||
private:
|
||||
int mode = 0; // 0 - on/off, 1 - on, 2 - off
|
||||
WLKeyManager * key_manager = new WLKeyManager();
|
||||
|
||||
protected:
|
||||
void run() override{
|
||||
forever{
|
||||
if (mode == 0) return;
|
||||
msleep(50);
|
||||
if ((mode == 1 && !key_manager->getNumLockState()) || (mode == 2 && key_manager->getNumLockState()))
|
||||
key_manager->pressNumLock();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif // MODETHREAD_H
|
69
numlockmanager.h
Normal file
69
numlockmanager.h
Normal file
|
@ -0,0 +1,69 @@
|
|||
#ifndef NUMLOCKMANAGER_H
|
||||
#define NUMLOCKMANAGER_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QMenu>
|
||||
#include <QAction>
|
||||
#include <QSettings>
|
||||
#include <QThread>
|
||||
#include <QDir>
|
||||
#include <QCloseEvent>
|
||||
|
||||
#include "statusshow.h"
|
||||
#include "modethread.h"
|
||||
#include "config.h"
|
||||
#include "ui_numlockmanager.h"
|
||||
#include "autostart.h"
|
||||
|
||||
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class NumLockManager; }
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class NumLockManager : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
NumLockManager(QWidget *parent = nullptr);
|
||||
~NumLockManager() { delete ui; }
|
||||
|
||||
private:
|
||||
Ui::NumLockManager *ui;
|
||||
|
||||
StatusShow * ss = new StatusShow();
|
||||
ModeThread * mode = new ModeThread();
|
||||
Config config;
|
||||
Autostart * autostart = new Autostart();
|
||||
|
||||
QSystemTrayIcon * tray_icon = new QSystemTrayIcon(this);
|
||||
QIcon tray_icon_off = QIcon(QCoreApplication::applicationDirPath() + "/src/icons/num_lock_icon_off.png");
|
||||
QIcon tray_icon_on = QIcon(QCoreApplication::applicationDirPath() + "/src/icons/num_lock_icon_on.png");
|
||||
QIcon icon_check_false = QIcon(QCoreApplication::applicationDirPath() + "/src/icons/check_radio_c_0.png");
|
||||
QIcon icon_check_true = QIcon(QCoreApplication::applicationDirPath() + "/src/icons/check_radio_c_1.png");
|
||||
QIcon icon_radio_false = QIcon(QCoreApplication::applicationDirPath() + "/src/icons/check_radio_r_0.png");
|
||||
QIcon icon_radio_true = QIcon(QCoreApplication::applicationDirPath() + "/src/icons/check_radio_r_1.png");
|
||||
|
||||
QMenu * menu = new QMenu();
|
||||
QAction * action_autostart = new QAction();
|
||||
QAction * action_mode_0 = new QAction();
|
||||
QAction * action_mode_1 = new QAction();
|
||||
QAction * action_mode_2 = new QAction();
|
||||
QAction * action_about = new QAction();
|
||||
QAction * action_exit = new QAction();
|
||||
QAction * actions[6] = {action_autostart, action_mode_0, action_mode_1, action_mode_2, action_about ,action_exit};
|
||||
QAction * actions_mode[3] = {action_mode_0, action_mode_1, action_mode_2};
|
||||
|
||||
void set_mode(int index);
|
||||
|
||||
public slots:
|
||||
void icon_activated(QSystemTrayIcon::ActivationReason reason) {Q_UNUSED(reason); menu->exec(QCursor::pos()); }
|
||||
void getStatus(bool status);
|
||||
void set_menu_hz(QAction * action);
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event) override{ event->ignore(); hide(); }
|
||||
};
|
||||
#endif // NUMLOCKMANAGER_H
|
29
statusshow.h
Normal file
29
statusshow.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
#ifndef STATUSSHOW_H
|
||||
#define STATUSSHOW_H
|
||||
|
||||
#include <QThread>
|
||||
|
||||
#include "wl_numlock.h"
|
||||
|
||||
class StatusShow : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
StatusShow(){}
|
||||
~StatusShow(){ delete key_manager; }
|
||||
|
||||
private:
|
||||
WLKeyManager * key_manager;
|
||||
|
||||
signals:
|
||||
void status(bool);
|
||||
protected:
|
||||
void run() override {
|
||||
forever{
|
||||
emit status(key_manager->getNumLockState());
|
||||
msleep(500);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif // STATUSSHOW_H
|
Loading…
Reference in a new issue