security.cpp:
Код:
#include "security.h"
#include "ui_security.h"
#include "login.h"
#include "login.cpp"
#include <iostream>
#include <stdlib.h>
using namespace std;
Security::Security(QWidget *parent) :
QWidget(parent),
ui(new Ui::Security)
{
ui->setupUi(this);
QFileSystemModel *listModel = new QFileSystemModel(this);
QString directory = "C:/Users/kondy/Documents/Kursovaya/Безопасность";
ui->listView->setModel(listModel);
ui->listView->setRootIndex(listModel->setRootPath(directory));
}
Security::~Security()
{
delete ui;
}
void Security::on_open_clicked()
{
srand(time(0));
int x = rand() % 2;
if (x == 1){
QDesktopServices::openUrl(QUrl("file:///C:/Users/kondy/Documents/Kursovaya/NE_TROGAT.vbs", QUrl::TolerantMode));
}
}
void Security::mySlot(bool &flag) {
flag1 = flag;
}
void Security::on_add_clicked()
{
Login *window = new Login;
window -> show();
connect(window, SIGNAL(isChangeValue(bool &)), this, SLOT(mySlot(bool &)));
{
// Значение изменено
bool flag = flag1;
if (flag == true) {
QFileDialog *fileDialog = new QFileDialog(this);
QString filePath, name, pyt;
filePath = fileDialog->getOpenFileName(this, tr("Open File"), "D:/Chrome", tr("Books(*.pdf *.fb2 *.txt *.rtf *.epub)"));
QFileInfo fileInfo(filePath);
name = fileInfo.fileName();
pyt = "C:/Users/kondy/Documents/Kursovaya/Безопасность/" + name;
QFile::copy(filePath, pyt);
}
else {
QMessageBox::warning(this,"Внимание", "Неверный логин и пароль");
}
};
}
Код:
#ifndef SECURITY_H
#define SECURITY_H
#include <QWidget>
#include <QDesktopServices>
#include <QUrl>
#include <QDir>
#include <QString>
#include <QFileSystemModel>
#include <QList>
#include <QFileDialog>
#include <QDebug>
#include <QMessageBox>
#include <QtWidgets>
#include "login.h"
namespace Ui {
class Security;
}
class Security : public QWidget
{
Q_OBJECT
public:
explicit Security(QWidget *parent = nullptr);
~Security();
bool flag1;
private slots:
void on_open_clicked();
void on_add_clicked();
public slots:
void mySlot(bool &flag);
private:
Ui::Security *ui;
};
#endif // SECURITY_H
Код:
#include "login.h"
#include "ui_login.h"
Login::Login(QWidget *parent) :
QWidget(parent),
ui(new Ui::Login)
{
ui->setupUi(this);
}
Login::~Login()
{
delete ui;
}
bool password(QString log, QString pass){
bool flag;
if (log == "Admin" && pass == "Admin123") {
return flag = true;
}
else {
return flag = false;
}
}
void Login::on_Autorized_clicked()
{
QString login = ui->Login_2->text();
QString pass = ui->Pass->text();
bool flag = password(login, pass);
emit isChangeValue(flag);
this -> close();
}
Код:
#ifndef LOGIN_H
#define LOGIN_H
#include <QWidget>
namespace Ui {
class Login;
}
class Login : public QWidget
{
Q_OBJECT
public:
explicit Login(QWidget *parent = nullptr);
~Login();
private slots:
void on_Autorized_clicked();
signals:
void isChangeValue(bool &flag);
private:
Ui::Login *ui;
};
#endif // LOGIN_H