-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainform.cpp
174 lines (152 loc) · 4.96 KB
/
mainform.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include "mainform.h"
#include "ui_mainform.h"
MainForm::MainForm(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainForm)
{
ui->setupUi(this);
about_form = new About(this);
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(onTimerCopy()));
flag_copy = false;
time_update = 0;
path_src = path_dest = "";
ReadIni(time_update, path_src, path_dest);
if (time_update<0 || time_update>1 || path_src=="" || path_dest=="")
{
QMessageBox::about(0, "Не верные настройки", "Не верные настройки программы!\nНастройте пути копирования и перезапустите программу.");
}else
{
ui->comboBox->setCurrentIndex(time_update);
ui->lineEdit->setText(path_src);
ui->lineEdit_2->setText(path_dest);
timer->start(60000);
}
tray = new QSystemTrayIcon(this);
tray->setContextMenu(ui->menu);
tray->setIcon(QIcon("://icon.png"));
connect(tray,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),this,SLOT(trayIconActivated(QSystemTrayIcon::ActivationReason)));
tray->show();
thread_copy = new ThreadCopy();
thread_copy->SetTray(tray);
}
MainForm::~MainForm()
{
delete thread_copy;
delete ui;
}
void MainForm::trayIconActivated(QSystemTrayIcon::ActivationReason reason)
{
switch (reason)
{
case QSystemTrayIcon::Trigger:
case QSystemTrayIcon::DoubleClick:
this->show();
break;
default:
break;
}
}
void MainForm::closeEvent(QCloseEvent* event)
{
this->hide();
event->ignore();
}
void MainForm::onTimerCopy()
{
QDate last_date = LogFile::GetLastDate();
//qDebug()<<last_date.toString("dd.MM.yyyy");
if (time_update==0)
{
if (last_date<QDate::currentDate())
flag_copy = true;
}
if (time_update==1)
{
last_date = last_date.addMonths(1);
if (last_date<QDate::currentDate())
flag_copy = true;
}
//qDebug()<<"Flag="<<flag_copy;
if (flag_copy)
{
QString new_path_src = path_src;
QString new_path_dest = path_dest
+"/"+QString::number(QDate::currentDate().day())
+"_"+QString::number(QDate::currentDate().month())
+"_"+QString::number(QDate::currentDate().year());
//qDebug()<<new_path_dest;
new_path_src.replace("/", "\\");
new_path_dest.replace("/", "\\");
if (!thread_copy->isRunning())
{
thread_copy->setProperty("path_src", new_path_src);
thread_copy->setProperty("path_dest", new_path_dest);
thread_copy->start();
flag_copy = false;
}
}
}
void MainForm::ReadIni(int& time_update, QString& path_src, QString& path_dest)
{
QSettings setting("setting.ini", QSettings::IniFormat);
time_update = setting.value("time_update").toInt();
path_src = setting.value("path_src").toString();
path_dest = setting.value("path_dest").toString();
}
void MainForm::WriteIni(int time_update, QString path_src, QString path_dest)
{
QSettings setting("setting.ini", QSettings::IniFormat);
setting.setValue("time_update", time_update);
setting.setValue("path_src", path_src);
setting.setValue("path_dest", path_dest);
}
void MainForm::on_pushButton_clicked()
{
time_update = ui->comboBox->currentIndex();
path_src = ui->lineEdit->text();
path_dest = ui->lineEdit_2->text();
WriteIni(time_update, path_src, path_dest);
}
void MainForm::on_pushButton_2_clicked()
{
QString new_path_src = QFileDialog::getExistingDirectory(this, "Выбор директории", "", QFileDialog::ShowDirsOnly|QFileDialog::DontResolveSymlinks);
if (new_path_src!="" && new_path_src!=path_src)
{
path_src = new_path_src;
ui->lineEdit->setText(path_src);
}
}
void MainForm::on_pushButton_3_clicked()
{
QString new_path_dest = QFileDialog::getExistingDirectory(this, "Выбор директории", "", QFileDialog::ShowDirsOnly|QFileDialog::DontResolveSymlinks);
if (new_path_dest!="" && new_path_dest!=path_dest)
{
path_dest = new_path_dest;
ui->lineEdit_2->setText(path_dest);
}
}
void MainForm::on_action_3_triggered()
{
QApplication::exit();
}
void MainForm::on_pushButton_4_clicked()
{
if (!thread_copy->isRunning())
{
QString new_path_src = path_src;
QString new_path_dest = path_dest
+"/"+QString::number(QDate::currentDate().day())
+"_"+QString::number(QDate::currentDate().month())
+"_"+QString::number(QDate::currentDate().year());
new_path_src.replace("/", "\\");
new_path_dest.replace("/", "\\");
thread_copy->setProperty("path_src", new_path_src);
thread_copy->setProperty("path_dest", new_path_dest);
thread_copy->start();
}
}
void MainForm::on_action_triggered()
{
about_form->show();
}