Skip to content

Commit

Permalink
Attempt to fix singletons
Browse files Browse the repository at this point in the history
  • Loading branch information
km2442 committed May 19, 2019
1 parent 6730911 commit 8de7c23
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 146 deletions.
8 changes: 7 additions & 1 deletion Windows/AutoSwitch/Source/Dialogs/passwordconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "Source/Main/functions.h"

PasswordConfig PasswordConfig::passwordConfigInstance;
Q_GLOBAL_STATIC(PasswordConfig, passwordConfigInstance);

PasswordConfig::PasswordConfig(QWidget *parent) :
QDialog(parent),
Expand Down Expand Up @@ -227,6 +227,12 @@ void PasswordConfig::loadFromReg()
pwSettings_changed = 0;
}

PasswordConfig *PasswordConfig::getInstance()
{
//return passwordConfigInstance;
return nullptr;
}

bool PasswordConfig::saveToRegistry(QString pw, bool pwr_run, bool pwr_settings, bool pwr_autorun, bool pwr_show)
{
QString param = "password enable " + pw;
Expand Down
3 changes: 1 addition & 2 deletions Windows/AutoSwitch/Source/Dialogs/passwordconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PasswordConfig : public QDialog

public:
void loadFromReg();
static PasswordConfig* getInstance() { return &passwordConfigInstance; }
static PasswordConfig *getInstance();
bool saveToRegistry(QString pw, bool pwr_run, bool pwr_settings, bool pwr_autorun, bool pwr_show);
explicit PasswordConfig(QWidget *parent = 0);
~PasswordConfig();
Expand Down Expand Up @@ -57,7 +57,6 @@ private slots:
private:
bool cleanPassConf();
void comparePass();
static PasswordConfig passwordConfigInstance;
Ui::PasswordConfig *ui;

bool password_enable = 0;
Expand Down
2 changes: 1 addition & 1 deletion Windows/AutoSwitch/Source/Main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "QtSingleApplication"

QString appData, PrgrData, appVersion = "1.0.1.1";
QString appData, PrgrData, appVersion = "1.0.2.0";
bool autoRunned = 0;

int main(int argc, char *argv[])
Expand Down
200 changes: 100 additions & 100 deletions Windows/AutoSwitch/Source/Main/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,40 @@ MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
// ui->setupUi(this);
// ui->Tasks_Table->setColumnWidth(0, 200);
// ui->Tasks_Table->setColumnWidth(1, 100);
// ui->Tasks_Table->setColumnWidth(2, 100);
// ui->Tasks_Table->setColumnWidth(3, 100);
// ui->Tasks_Table->setColumnWidth(4, 100);
ui->setupUi(this);
ui->Tasks_Table->setColumnWidth(0, 200);
ui->Tasks_Table->setColumnWidth(1, 100);
ui->Tasks_Table->setColumnWidth(2, 100);
ui->Tasks_Table->setColumnWidth(3, 100);
ui->Tasks_Table->setColumnWidth(4, 100);

// qApp->setStyle("fusion");
// MainWindow::tray();
qApp->setStyle("fusion");
MainWindow::tray();

// QTimer *timer = new QTimer(this);
// connect(timer,SIGNAL(timeout()), this, SLOT(show_time()));
// timer->start(950);
QTimer *timer = new QTimer(this);
connect(timer,SIGNAL(timeout()), this, SLOT(show_time()));
timer->start(950);

// ui->Info_BuildDate_Date->setText(__DATE__);
// ui->Info_BuildDate_Time->setText(__TIME__);
// ui->About_Version->setText(ui->About_Version->text() + appVersion);
ui->Info_BuildDate_Date->setText(__DATE__);
ui->Info_BuildDate_Time->setText(__TIME__);
ui->About_Version->setText(ui->About_Version->text() + appVersion);

// if (isHibernateAvailable() == 0) ui->Main_Task_Hibernate->setEnabled(0);
if (isHibernateAvailable() == 0) ui->Main_Task_Hibernate->setEnabled(0);

// PasswordConfig *pc = PasswordConfig::getInstance();
// if (pc->getPasswordrules_run())
// {
// if (authorize() == false) exit(10);
// }

// Autorun AR;
// AR.autorunLoad(1);
// AR.close();
Autorun AR;
AR.autorunLoad(1);
AR.close();

// isUserRegistered();
// ui->retranslateUi(this);
isUserRegistered();
ui->retranslateUi(this);

// setAlignedIcons();
setAlignedIcons();

// SocketCommunicator server(nullptr, this);
// server.StartServer();
Expand Down Expand Up @@ -85,8 +85,8 @@ void MainWindow::tray()
trayIcon = trayIcon;

Settings *s = Settings::getInstance();
s->settingsLoad();
s->close();
// s->settingsLoad();
// s->close();
tasklist = ui->Tasks_Table;
TraySubmenu tsm;

Expand All @@ -99,89 +99,89 @@ void MainWindow::tray()

tsm.mainMenu = trayIconMenu;

if (s->getTraySettings_Shutdown())
{
tsm.actionSingle = ShutdownAction;
memcpy(MShutdown, tsm.action, sizeof(MShutdown));
tsm.actionText = tr("Wyłącz Komputer");
tsm.iconPath = ":/icons/Resources/Icons/shutdown.png";
tsm.mode = 'w';
tsm.subMenu = subMenu_Shutdown;
if (s->getTraySettings_Shutdown()) trayBuilder(tsm, 1);
else trayBuilder(tsm, 0);
}
// if (s->getTraySettings_Shutdown())
// {
// tsm.actionSingle = ShutdownAction;
// memcpy(MShutdown, tsm.action, sizeof(MShutdown));
// tsm.actionText = tr("Wyłącz Komputer");
// tsm.iconPath = ":/icons/Resources/Icons/shutdown.png";
// tsm.mode = 'w';
// tsm.subMenu = subMenu_Shutdown;
// if (s->getTraySettings_Shutdown()) trayBuilder(tsm, 1);
// else trayBuilder(tsm, 0);
// }

if (s->getTraySettings_Reboot())
{
tsm.actionSingle = RebootAction;
memcpy(MReboot, tsm.action, sizeof(MReboot));
tsm.actionText = tr("Uruchom ponownie Komputer");
tsm.iconPath = ":/icons/Resources/Icons/reboot.png";
tsm.mode = 'r';
tsm.subMenu = subMenu_Reboot;
if (s->getTraySettings_Reboot()) trayBuilder(tsm, 1);
else trayBuilder(tsm, 0);
}
// if (s->getTraySettings_Reboot())
// {
// tsm.actionSingle = RebootAction;
// memcpy(MReboot, tsm.action, sizeof(MReboot));
// tsm.actionText = tr("Uruchom ponownie Komputer");
// tsm.iconPath = ":/icons/Resources/Icons/reboot.png";
// tsm.mode = 'r';
// tsm.subMenu = subMenu_Reboot;
// if (s->getTraySettings_Reboot()) trayBuilder(tsm, 1);
// else trayBuilder(tsm, 0);
// }

if (s->getTraySettings_Sleep())
{
tsm.actionSingle = SleepAction;
memcpy(MSleep, tsm.action, sizeof(MSleep));
tsm.actionText = tr("Uśpij Komputer");
tsm.iconPath = ":/icons/Resources/Icons/hibernate.png";
tsm.mode = 'u';
tsm.subMenu = subMenu_Sleep;
if (s->getTraySettings_Sleep()) trayBuilder(tsm, 1);
else trayBuilder(tsm, 0);
}
// if (s->getTraySettings_Sleep())
// {
// tsm.actionSingle = SleepAction;
// memcpy(MSleep, tsm.action, sizeof(MSleep));
// tsm.actionText = tr("Uśpij Komputer");
// tsm.iconPath = ":/icons/Resources/Icons/hibernate.png";
// tsm.mode = 'u';
// tsm.subMenu = subMenu_Sleep;
// if (s->getTraySettings_Sleep()) trayBuilder(tsm, 1);
// else trayBuilder(tsm, 0);
// }

if (s->getTraySettings_Hibernate())
{
tsm.actionSingle = HibernateAction;
memcpy(MHibernate, tsm.action, sizeof(MHibernate));
tsm.actionText = tr("Hibernuj Komputer");
tsm.iconPath = ":/icons/Resources/Icons/hibernate.png";
tsm.mode = 'h';
tsm.subMenu = subMenu_Hibernate;
if (s->getTraySettings_Hibernate()) trayBuilder(tsm, 1);
else trayBuilder(tsm, 0);
}
// if (s->getTraySettings_Hibernate())
// {
// tsm.actionSingle = HibernateAction;
// memcpy(MHibernate, tsm.action, sizeof(MHibernate));
// tsm.actionText = tr("Hibernuj Komputer");
// tsm.iconPath = ":/icons/Resources/Icons/hibernate.png";
// tsm.mode = 'h';
// tsm.subMenu = subMenu_Hibernate;
// if (s->getTraySettings_Hibernate()) trayBuilder(tsm, 1);
// else trayBuilder(tsm, 0);
// }

if (s->getTraySettings_Logoff())
{
tsm.actionSingle = LogoffAction;
memcpy(MLogoff, tsm.action, sizeof(MLogoff));
tsm.actionText = tr("Wyloguj się");
tsm.iconPath = ":/icons/Resources/Icons/logout.png";
tsm.mode = 'l';
tsm.subMenu = subMenu_Logoff;
if (s->getTraySettings_Logoff()) trayBuilder(tsm, 1);
else trayBuilder(tsm, 0);
}
// if (s->getTraySettings_Logoff())
// {
// tsm.actionSingle = LogoffAction;
// memcpy(MLogoff, tsm.action, sizeof(MLogoff));
// tsm.actionText = tr("Wyloguj się");
// tsm.iconPath = ":/icons/Resources/Icons/logout.png";
// tsm.mode = 'l';
// tsm.subMenu = subMenu_Logoff;
// if (s->getTraySettings_Logoff()) trayBuilder(tsm, 1);
// else trayBuilder(tsm, 0);
// }

if (s->getTraySettings_Lock())
{
tsm.actionSingle = LockAction;
memcpy(MLock, tsm.action, sizeof(MLock));
tsm.actionText = tr("Zablokuj Komputer");
tsm.iconPath = ":/icons/Resources/Icons/lock.png";
tsm.mode = 'b';
tsm.subMenu = subMenu_Lock;
if (s->getTraySettings_Lock()) trayBuilder(tsm, 1);
else trayBuilder(tsm, 0);
}
// if (s->getTraySettings_Lock())
// {
// tsm.actionSingle = LockAction;
// memcpy(MLock, tsm.action, sizeof(MLock));
// tsm.actionText = tr("Zablokuj Komputer");
// tsm.iconPath = ":/icons/Resources/Icons/lock.png";
// tsm.mode = 'b';
// tsm.subMenu = subMenu_Lock;
// if (s->getTraySettings_Lock()) trayBuilder(tsm, 1);
// else trayBuilder(tsm, 0);
// }

if (s->getTraySettings_Monitor())
{
tsm.actionSingle = MonitoroffAction;
memcpy(MMonitoroff, tsm.action, sizeof(MMonitoroff));
tsm.actionText = tr("Wyłącz Monitor");
tsm.iconPath = ":/icons/Resources/Icons/monitor_off.png";
tsm.mode = 'm';
tsm.subMenu = subMenu_MonitorOff;
if (s->getTraySettings_Monitor()) trayBuilder(tsm, 1);
else trayBuilder(tsm, 0);
}
// if (s->getTraySettings_Monitor())
// {
// tsm.actionSingle = MonitoroffAction;
// memcpy(MMonitoroff, tsm.action, sizeof(MMonitoroff));
// tsm.actionText = tr("Wyłącz Monitor");
// tsm.iconPath = ":/icons/Resources/Icons/monitor_off.png";
// tsm.mode = 'm';
// tsm.subMenu = subMenu_MonitorOff;
// if (s->getTraySettings_Monitor()) trayBuilder(tsm, 1);
// else trayBuilder(tsm, 0);
// }

trayIconMenu->addSeparator();
WyjdzAction = new QAction(tr("Wyjdź z programu"), this);
Expand Down
86 changes: 46 additions & 40 deletions Windows/AutoSwitch/Source/Main/settings.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "settings.h"
#include "ui_settings.h"

Settings Settings::settingsInstance;
Q_GLOBAL_STATIC(Settings, settingsInstance);

Settings::Settings(QWidget *parent) :
QDialog(parent),
Expand Down Expand Up @@ -32,6 +32,12 @@ Settings::Settings(QWidget *parent) :
fexec = 0;
}

Settings *Settings::getInstance()
{
//return settingsInstance;
return nullptr;
}

Settings::~Settings()
{
delete ui;
Expand All @@ -57,45 +63,45 @@ void Settings::settingsLoad()
QSettings setting(appData + "/config/settings.ini", QSettings::IniFormat);
setting.beginGroup("Settings");
ui->Settings_Theme_Choose->setCurrentIndex(setting.value("WindowStyle").toInt());
ui->Settings_LanguageSelect->setCurrentIndex(setting.value("Language").toInt() - 1);
ui->Settings_Log->setCurrentIndex(setting.value("LogActions").toInt());
ui->Settings_Statistics->setCurrentIndex(setting.value("SendStatistics").toInt());
ui->Settings_MultiInstance->setCurrentIndex(setting.value("AllowMultiInstance").toInt());
ui->Settings_DeveloperMode->setCurrentIndex(setting.value("DeveloperOptions").toInt());
ui->Settings_HideDialogWarning->setCurrentIndex(setting.value("HideDialogWarning").toInt());
setting.endGroup();

setting.beginGroup("TraySettings");
ui->Settings_Tray_Switch->setCurrentIndex(setting.value("TrayActive").toInt());
if (setting.value("ShutdownActive").toBool()) ui->Settings_Tray_Shutdown->setChecked(2);
else ui->Settings_Tray_Shutdown->setChecked(0);
if (setting.value("RebootActive").toBool()) ui->Settings_Tray_Reboot->setChecked(2);
else ui->Settings_Tray_Reboot->setChecked(0);
if (setting.value("SleepActive").toBool()) ui->Settings_Tray_Sleep->setChecked(2);
else ui->Settings_Tray_Sleep->setChecked(0);
if (setting.value("HibernateActive").toBool()) ui->Settings_Tray_Hibernate->setChecked(2);
else ui->Settings_Tray_Hibernate->setChecked(0);
if (setting.value("LogoffActive").toBool()) ui->Settings_Tray_Logoff->setChecked(2);
else ui->Settings_Tray_Logoff->setChecked(0);
if (setting.value("LockActive").toBool()) ui->Settings_Tray_Lock->setChecked(2);
else ui->Settings_Tray_Lock->setChecked(0);
if (setting.value("MonitorActive").toBool()) ui->Settings_Tray_Monitor->setChecked(2);
else ui->Settings_Tray_Monitor->setChecked(0);
setting.endGroup();

setting.beginGroup("TraySettingsTime");
ui->Settings_Tray_ShutdownTime->setCurrentIndex(setting.value("ShutdownTime").toInt());
ui->Settings_Tray_RebootTime->setCurrentIndex(setting.value("RebootTime").toInt());
ui->Settings_Tray_SleepTime->setCurrentIndex(setting.value("SleepTime").toInt());
ui->Settings_Tray_HibernateTime->setCurrentIndex(setting.value("HibernateTime").toInt());
ui->Settings_Tray_LogoffTime->setCurrentIndex(setting.value("LogoffTime").toInt());
ui->Settings_Tray_LockTime->setCurrentIndex(setting.value("LockTime").toInt());
ui->Settings_Tray_MonitorTime->setCurrentIndex(setting.value("MonitorTime").toInt());
setting.endGroup();

settings_changed = 0;
tray_changed = 0;
user_changed = 0;
// ui->Settings_LanguageSelect->setCurrentIndex(setting.value("Language").toInt() - 1);
// ui->Settings_Log->setCurrentIndex(setting.value("LogActions").toInt());
// ui->Settings_Statistics->setCurrentIndex(setting.value("SendStatistics").toInt());
// ui->Settings_MultiInstance->setCurrentIndex(setting.value("AllowMultiInstance").toInt());
// ui->Settings_DeveloperMode->setCurrentIndex(setting.value("DeveloperOptions").toInt());
// ui->Settings_HideDialogWarning->setCurrentIndex(setting.value("HideDialogWarning").toInt());
// setting.endGroup();

// setting.beginGroup("TraySettings");
// ui->Settings_Tray_Switch->setCurrentIndex(setting.value("TrayActive").toInt());
// if (setting.value("ShutdownActive").toBool()) ui->Settings_Tray_Shutdown->setChecked(2);
// else ui->Settings_Tray_Shutdown->setChecked(0);
// if (setting.value("RebootActive").toBool()) ui->Settings_Tray_Reboot->setChecked(2);
// else ui->Settings_Tray_Reboot->setChecked(0);
// if (setting.value("SleepActive").toBool()) ui->Settings_Tray_Sleep->setChecked(2);
// else ui->Settings_Tray_Sleep->setChecked(0);
// if (setting.value("HibernateActive").toBool()) ui->Settings_Tray_Hibernate->setChecked(2);
// else ui->Settings_Tray_Hibernate->setChecked(0);
// if (setting.value("LogoffActive").toBool()) ui->Settings_Tray_Logoff->setChecked(2);
// else ui->Settings_Tray_Logoff->setChecked(0);
// if (setting.value("LockActive").toBool()) ui->Settings_Tray_Lock->setChecked(2);
// else ui->Settings_Tray_Lock->setChecked(0);
// if (setting.value("MonitorActive").toBool()) ui->Settings_Tray_Monitor->setChecked(2);
// else ui->Settings_Tray_Monitor->setChecked(0);
// setting.endGroup();

// setting.beginGroup("TraySettingsTime");
// ui->Settings_Tray_ShutdownTime->setCurrentIndex(setting.value("ShutdownTime").toInt());
// ui->Settings_Tray_RebootTime->setCurrentIndex(setting.value("RebootTime").toInt());
// ui->Settings_Tray_SleepTime->setCurrentIndex(setting.value("SleepTime").toInt());
// ui->Settings_Tray_HibernateTime->setCurrentIndex(setting.value("HibernateTime").toInt());
// ui->Settings_Tray_LogoffTime->setCurrentIndex(setting.value("LogoffTime").toInt());
// ui->Settings_Tray_LockTime->setCurrentIndex(setting.value("LockTime").toInt());
// ui->Settings_Tray_MonitorTime->setCurrentIndex(setting.value("MonitorTime").toInt());
// setting.endGroup();

// settings_changed = 0;
// tray_changed = 0;
// user_changed = 0;
}

void Settings::settingsSave(bool p, QString path)
Expand Down
Loading

0 comments on commit 8de7c23

Please sign in to comment.