-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
99 lines (89 loc) · 3.02 KB
/
Copy pathmain.cpp
File metadata and controls
99 lines (89 loc) · 3.02 KB
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
/*******************************************************************************************************/
/* 注意事项
/* 1.代码中全部变量名均以小写字母开头,类名均以大写字母开头
/*
/*******************************************************************************************************/
#include "widget.h"
#include <QApplication>
#include <QDebug>
#include <QDir>
#include <QString>
#include <QString>
#include <QtXml>
#include <QFile>
#include <QDate>
#include <QScreen>
#include "reader_mgmt.h"
#include <QStyleFactory>
QString dataDir; //数据所在目录
QString bookInfoPath; //图书信息文件路径
QString readerInfoPath; //读者信息文件路径
QString coverDir; //图书封面所在目录,用于存储图书封面
QDate systemDate; //程序当前日期
qreal dpi;
Reader* activereader=Q_NULLPTR;
bool userMessageChanged=false;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
//计算DPI
QScreen* screen=a.primaryScreen();
dpi=screen->logicalDotsPerInch()/96;
//创建Data文件夹
QDir dir;
dataDir=dir.currentPath()+"/Data";
coverDir=dataDir+"/Covers";
bookInfoPath=dataDir+"/BookInfo.xml";
readerInfoPath=dataDir+"/ReaderInfo.xml";
if(!dir.exists(dataDir)) //在当前目录下创建Data文件夹,将读者与图书的相关信息存入Data文件夹
dir.mkdir(dataDir);
if(!dir.exists(coverDir)) //在Data目录下创建Cover文件夹
dir.mkdir(coverDir);
//创建xml文件
systemDate=getDate();
//建立图书的xml文件
QFile bookInfo(bookInfoPath);
QDomProcessingInstruction instruction;
if(!bookInfo.exists())
{
QDomDocument bookInfoDom;
//写文件头
instruction=bookInfoDom.createProcessingInstruction("xml","version=\"1.0\" encoding=\"UTF-8\"" );
//写根元素
bookInfoDom.appendChild(instruction);
QDomElement root=bookInfoDom.createElement(QString("Library"));
bookInfoDom.appendChild(root);
if(!bookInfo.open(QIODevice::WriteOnly|QIODevice::Truncate))
{
return 0;
}
QTextStream out_1(&bookInfo);
bookInfoDom.save(out_1,4);
bookInfo.close();
}
//读者xml文件
QFile readerInfo(readerInfoPath);
if(!readerInfo.exists())
{
QDomDocument readerInfoDom;
//写文件头
instruction=readerInfoDom.createProcessingInstruction("xml","version=\"1.0\" encoding=\"UTF-8\"" );
//写根元素
readerInfoDom.appendChild(instruction);
QDomElement root=readerInfoDom.createElement(QString("readerlist"));
readerInfoDom.appendChild(root);
if(!readerInfo.open(QIODevice::WriteOnly|QIODevice::Truncate))
{
return 0;
}
QTextStream out_1(&readerInfo);
readerInfoDom.save(out_1,4);
readerInfo.close();
}
getXml();
getXml2();
log_print("initial","","","");
Widget w;
w.show();
return a.exec();
}