-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_manager.cpp
42 lines (39 loc) · 1.5 KB
/
user_manager.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
#include "user_manager.h"
user_manager::user_manager(QObject *parent) : QObject(parent){}
QStringList user_manager::to_user_name_list(){return user_name_list;}
void user_manager::add_user(QString user_name, QString user_password, QString logging_method){
user_name_list.append(user_name);
user_password_list.append(user_password);
user_logging_method_list.append(logging_method);
fresh_file();
emit user_name_list_Changed();
}
void user_manager::delete_user(int i){
user_name_list.removeAt(i);
user_password_list.removeAt(i);
user_logging_method_list.removeAt(i);
fresh_file();
emit user_name_list_Changed();
}
void user_manager::fresh_file(){
user_config.seek(0);
user_config.resize(0);
for (int i=0;i<user_name_list.count();i++){
user_config.write(user_name_list[i].toUtf8()+'\n'+user_password_list[i].toUtf8()+'\n'+user_logging_method_list[i].toUtf8()+'\n');
}
user_config.resize(user_config.size()-1);//delete the last '\n'.if not,it will read_file wrongly
}
void user_manager::read_file(){
user_config.setFileName("./user.conf");
user_config.open(QIODevice::ReadWrite);
if (user_config.readAll()!=""){
user_config.seek(0);
tmp_text = user_config.readAll();
tmp_list = tmp_text.split('\n');
for (int i=0;i<tmp_list.count();i++) {
user_name_list.append(tmp_list[i]); i++;
user_password_list.append(tmp_list[i]); i++;
user_logging_method_list.append(tmp_list[i]);
}
}
}