├── .gitignore
├── .travis.yml
├── CMakeLists.txt
├── LICENSE
├── README.md
├── bin
└── .gitignore
├── build
└── .gitignore
├── doc
├── Doxyfile
├── html.zip
└── images
│ ├── about.png
│ ├── add-book.png
│ ├── administer.png
│ ├── book.png
│ ├── borrow-book.png
│ ├── borrow-record.png
│ ├── login.png
│ ├── newest-book.png
│ ├── record.png
│ ├── search.png
│ ├── setting.png
│ ├── sign-up.png
│ ├── star.png
│ ├── top.png
│ ├── 切换语言.gif
│ ├── 刷新缓存(更新排行榜).gif
│ ├── 收藏和借阅.gif
│ ├── 收藏夹.gif
│ ├── 查看书籍.gif
│ ├── 添加书籍.png
│ ├── 编辑书籍.gif
│ ├── 编辑用户信息及注销.gif
│ ├── 记录.gif
│ ├── 设置权限.png
│ └── 还书.png
└── src
├── CMakeLists.txt
├── README.md
├── client
├── CMakeLists.txt
├── README.md
├── core
│ ├── Book.cpp
│ ├── Book.h
│ ├── BookBrief.cpp
│ ├── BookBrief.h
│ ├── BorrowRecord.cpp
│ ├── BorrowRecord.h
│ ├── BrowseRecord.cpp
│ ├── BrowseRecord.h
│ ├── KeepRecord.cpp
│ ├── KeepRecord.h
│ ├── LoginRecord.cpp
│ ├── LoginRecord.h
│ ├── StarRecord.cpp
│ ├── StarRecord.h
│ ├── User.cpp
│ └── User.h
├── dialog
│ ├── DialogBook.cpp
│ ├── DialogBook.h
│ ├── DialogChooseTime.cpp
│ ├── DialogChooseTime.h
│ ├── DialogLogin.cpp
│ ├── DialogLogin.h
│ ├── DialogModifyBook.cpp
│ ├── DialogModifyBook.h
│ ├── DialogModifyUser.cpp
│ ├── DialogModifyUser.h
│ ├── DialogRefresh.cpp
│ ├── DialogRefresh.h
│ ├── DialogSignUp.cpp
│ └── DialogSignUp.h
├── listwidget
│ ├── ListWidgetBorrowRecord.cpp
│ ├── ListWidgetBorrowRecord.h
│ ├── ListWidgetBrowseBook.cpp
│ ├── ListWidgetBrowseBook.h
│ ├── ListWidgetBrowseRecord.cpp
│ ├── ListWidgetBrowseRecord.h
│ ├── ListWidgetKeepRecord.cpp
│ ├── ListWidgetKeepRecord.h
│ ├── ListWidgetLoginRecord.cpp
│ ├── ListWidgetLoginRecord.h
│ ├── ListWidgetStarRecord.cpp
│ └── ListWidgetStarRecord.h
├── main.cpp
├── mainwindow
│ ├── MainWindow.cpp
│ └── MainWindow.h
├── manager
│ ├── BookManager.cpp
│ ├── BookManager.h
│ ├── UserManager.cpp
│ └── UserManager.h
├── object
│ ├── GetRecords.cpp
│ └── GetRecords.h
├── page
│ ├── PageAbout.cpp
│ ├── PageAbout.h
│ ├── PageAddBook.cpp
│ ├── PageAddBook.h
│ ├── PageAdminister.cpp
│ ├── PageAdminister.h
│ ├── PageBrowse.cpp
│ ├── PageBrowse.h
│ ├── PageFavorite.cpp
│ ├── PageFavorite.h
│ ├── PageRecord.cpp
│ ├── PageRecord.h
│ ├── PageSetting.cpp
│ └── PageSetting.h
├── resource
│ ├── i18n
│ │ ├── qt_zh_CN.qm
│ │ ├── zh_CN.qm
│ │ └── zh_CN.ts
│ ├── images
│ │ └── WidgetLogin
│ │ │ ├── close.png
│ │ │ ├── drop_down_button.png
│ │ │ ├── head.jpg
│ │ │ └── min.png
│ ├── resource.qrc
│ └── style
│ │ ├── DialogBook
│ │ └── style.css
│ │ ├── DialogSignUp
│ │ └── style.css
│ │ ├── ListWidgetNavigation
│ │ └── style.css
│ │ ├── WidgetLogin
│ │ ├── style.css
│ │ └── title.css
│ │ └── WidgetMain
│ │ └── style.css
├── thread
│ ├── ThreadBorrowBook.cpp
│ ├── ThreadBorrowBook.h
│ ├── ThreadGetBook.cpp
│ ├── ThreadGetBook.h
│ ├── ThreadGetNewBookList.cpp
│ ├── ThreadGetNewBookList.h
│ ├── ThreadGetRecord.cpp
│ ├── ThreadGetRecord.h
│ ├── ThreadGetSearchBookList.cpp
│ ├── ThreadGetSearchBookList.h
│ ├── ThreadGetTopBookList.cpp
│ ├── ThreadGetTopBookList.h
│ ├── ThreadLogin.cpp
│ ├── ThreadLogin.h
│ ├── ThreadLogout.cpp
│ ├── ThreadLogout.h
│ ├── ThreadModifyUser.cpp
│ ├── ThreadModifyUser.h
│ ├── ThreadNetwork.cpp
│ ├── ThreadNetwork.h
│ ├── ThreadReturnBook.cpp
│ ├── ThreadReturnBook.h
│ ├── ThreadSetBook.cpp
│ ├── ThreadSetBook.h
│ ├── ThreadSetPriority.cpp
│ ├── ThreadSetPriority.h
│ ├── ThreadSignUp.cpp
│ ├── ThreadSignUp.h
│ ├── ThreadStarBook.cpp
│ ├── ThreadStarBook.h
│ ├── ThreadUnStarBook.cpp
│ └── ThreadUnStarBook.h
├── utils.cpp
├── utils.h
├── values.cpp
├── values.h
└── widget
│ ├── WidgetHead.cpp
│ ├── WidgetHead.h
│ ├── WidgetLogin.cpp
│ ├── WidgetLogin.h
│ ├── WidgetLogin.ui
│ ├── WidgetLoginTitle.cpp
│ ├── WidgetLoginTitle.h
│ ├── WidgetMain.cpp
│ ├── WidgetMain.h
│ ├── WidgetSearchBook.cpp
│ ├── WidgetSearchBook.h
│ ├── WidgetSetBook.cpp
│ └── WidgetSetBook.h
├── core
├── CMakeLists.txt
├── README.md
├── Resource.cpp
├── Resource.h
├── SocketInfo.cpp
├── SocketInfo.h
├── types.h
├── utils.cpp
├── utils.h
├── values.cpp
└── values.h
├── server
├── CMakeLists.txt
├── README.md
├── core
│ ├── Server.cpp
│ ├── Server.h
│ ├── Session.cpp
│ └── Session.h
├── main.cpp
├── manager
│ ├── SessionManager.cpp
│ ├── SessionManager.h
│ ├── SocketManager.cpp
│ ├── SocketManager.h
│ ├── UserManager.cpp
│ └── UserManager.h
├── utils.cpp
├── utils.h
├── values.cpp
└── values.h
└── test
├── CMakeLists.txt
├── book
├── 1
│ └── cover.jpg
├── 2
│ └── cover.jpg
├── 3
│ └── cover.jpg
├── 4
│ └── cover.jpg
├── 5
│ └── cover.jpg
├── 6
│ └── cover.jpg
├── 7
│ └── cover.jpg
├── 8
│ └── cover.jpg
├── 9
│ └── cover.jpg
├── 10
│ └── cover.jpg
├── 11
│ └── cover.jpg
├── 12
│ └── cover.jpg
├── 13
│ └── cover.jpg
├── 14
│ └── cover.jpg
├── 15
│ └── cover.jpg
├── 16
│ └── cover.jpg
├── 17
│ └── cover.jpg
├── 18
│ └── cover.jpg
├── 19
│ └── cover.jpg
├── 20
│ └── cover.jpg
├── 21
│ └── cover.jpg
└── 22
│ └── cover.jpg
├── testServer1.cpp
├── testServer2.cpp
├── testServer3.cpp
└── testServer4.cpp
/.gitignore:
--------------------------------------------------------------------------------
1 | /tmp
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: cpp
2 |
3 | compiler:
4 | - gcc
5 | - clang
6 |
7 | branches:
8 | only:
9 | - master
10 |
11 | env:
12 | global:
13 | - DEPS_DIR=deps
14 | - CMAKE_VERSION=v3.11
15 | - CMAKE_FILE=cmake-3.11.2-Linux-x86_64.tar.gz
16 | matrix:
17 | - CONFIG=Release
18 | - CONFIG=Debug
19 |
20 | addons:
21 | apt:
22 | sources:
23 | - ubuntu-toolchain-r-test
24 | - llvm-toolchain-precise-3.7
25 |
26 | packages:
27 | - mongodb-org-server
28 | - g++-5
29 | - clang-3.8
30 |
31 | install:
32 | # GCC
33 | - if [ "$CXX" = "g++" ]; then export CXX="g++-5"; export CC="gcc-5"; fi
34 |
35 | # Clang
36 | - if [ "$CXX" == "clang++" ]; then export CXX="clang++-3.8"; export CC="clang-3.8"; fi
37 |
38 | # Install dependencies
39 | - curl -O https://cmake.org/files/${CMAKE_VERSION}/${CMAKE_FILE}
40 | - tar -zxf ${CMAKE_FILE} -C ${DEPS_DIR}/cmake
41 | - export PATH=${DEPS_DIR}/cmake/bin:${PATH}
42 |
43 | before_script:
44 | - $CC --version
45 | - $CXX --version
46 | - cmake --version
47 |
48 | - cd build
49 | # - cmake -DCMAKE_BUILD_TYPE=$CONFIG -DBUILD_ALL=ON -DBUILD_STATIC=ON ..
50 |
51 | script:
52 | # - make
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.2)
2 |
3 | message(STATUS "========================================")
4 | message(STATUS "========================================")
5 | message(STATUS "Building PiLibrary v1.0.0 PI!pi!Pi!pI!")
6 | message(STATUS "Author: xalanq, chang-ran")
7 | message(STATUS "License: LGPL v3.0")
8 | message(STATUS "========================================")
9 | message(STATUS "========================================")
10 |
11 | project(PiLibrary LANGUAGES CXX)
12 |
13 | if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
14 | if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.8.2")
15 | message(FATAL_ERROR "Insufficient GCC version - GCC 4.8.2+ required")
16 | endif()
17 | elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
18 | if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "19.0.23506")
19 | message(FATAL_ERROR "Insufficient Microsoft Visual C++ version - MSVC 2015 Update 1+ required")
20 | endif()
21 | elseif (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
22 | if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.1")
23 | message(FATAL_ERROR "Insufficient Apple clang version - XCode 5.1+ required")
24 | endif()
25 | elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
26 | if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.5")
27 | message(FATAL_ERROR "Insufficient clang version - clang 3.5+ required")
28 | endif()
29 | else()
30 | message(WARNING "Unknown compiler... recklessly proceeding without a version check")
31 | endif()
32 |
33 | set(CMAKE_CXX_STANDARD 11)
34 | set(CMAKE_CXX_STANDARD_REQUIRED ON)
35 | set(CMAKE_CXX_EXTENSIONS OFF)
36 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
37 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_SOURCE_DIR}/bin)
38 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_SOURCE_DIR}/bin)
39 |
40 | if (NOT CMAKE_BUILD_TYPE)
41 | message(STATUS "No build type selected, default is Release")
42 | set(CMAKE_BUILD_TYPE "Release")
43 | endif()
44 |
45 | if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
46 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
47 | if (CMAKE_BUILD_TYPE STREQUAL "Release")
48 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
49 | endif()
50 | endif()
51 |
52 | add_subdirectory(src)
--------------------------------------------------------------------------------
/bin/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
3 |
--------------------------------------------------------------------------------
/build/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
3 |
--------------------------------------------------------------------------------
/doc/html.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/doc/html.zip
--------------------------------------------------------------------------------
/doc/images/about.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/doc/images/about.png
--------------------------------------------------------------------------------
/doc/images/add-book.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/doc/images/add-book.png
--------------------------------------------------------------------------------
/doc/images/administer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/doc/images/administer.png
--------------------------------------------------------------------------------
/doc/images/book.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/doc/images/book.png
--------------------------------------------------------------------------------
/doc/images/borrow-book.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/doc/images/borrow-book.png
--------------------------------------------------------------------------------
/doc/images/borrow-record.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/doc/images/borrow-record.png
--------------------------------------------------------------------------------
/doc/images/login.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/doc/images/login.png
--------------------------------------------------------------------------------
/doc/images/newest-book.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/doc/images/newest-book.png
--------------------------------------------------------------------------------
/doc/images/record.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/doc/images/record.png
--------------------------------------------------------------------------------
/doc/images/search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/doc/images/search.png
--------------------------------------------------------------------------------
/doc/images/setting.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/doc/images/setting.png
--------------------------------------------------------------------------------
/doc/images/sign-up.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/doc/images/sign-up.png
--------------------------------------------------------------------------------
/doc/images/star.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/doc/images/star.png
--------------------------------------------------------------------------------
/doc/images/top.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/doc/images/top.png
--------------------------------------------------------------------------------
/doc/images/切换语言.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/doc/images/切换语言.gif
--------------------------------------------------------------------------------
/doc/images/刷新缓存(更新排行榜).gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/doc/images/刷新缓存(更新排行榜).gif
--------------------------------------------------------------------------------
/doc/images/收藏和借阅.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/doc/images/收藏和借阅.gif
--------------------------------------------------------------------------------
/doc/images/收藏夹.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/doc/images/收藏夹.gif
--------------------------------------------------------------------------------
/doc/images/查看书籍.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/doc/images/查看书籍.gif
--------------------------------------------------------------------------------
/doc/images/添加书籍.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/doc/images/添加书籍.png
--------------------------------------------------------------------------------
/doc/images/编辑书籍.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/doc/images/编辑书籍.gif
--------------------------------------------------------------------------------
/doc/images/编辑用户信息及注销.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/doc/images/编辑用户信息及注销.gif
--------------------------------------------------------------------------------
/doc/images/记录.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/doc/images/记录.gif
--------------------------------------------------------------------------------
/doc/images/设置权限.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/doc/images/设置权限.png
--------------------------------------------------------------------------------
/doc/images/还书.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/doc/images/还书.png
--------------------------------------------------------------------------------
/src/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | option(BUILD_STATIC_X "Build static version" OFF)
2 | option(BUILD_CLIENT_X "Build client" OFF)
3 | option(BUILD_SERVER_X "Build server" OFF)
4 | option(BUILD_BOTH_X "Build server, client" OFF)
5 | option(BUILD_ALL_X "Build server, client, test" OFF)
6 |
7 | if (NOT BUILD_CLIENT_X AND NOT BUILD_SERVER_X AND NOT BUILD_BOTH_X AND NOT BUILD_ALL_X)
8 | message(STATUS "=========Use BUILD_BOTH_X(default)========")
9 | set(BUILD_BOTH_X ON)
10 | endif()
11 |
12 | if (BUILD_STATIC_X)
13 | message(STATUS "==========Build Static Version==========")
14 | else()
15 | message(STATUS "==========Build Dynamic Version=========")
16 | endif()
17 |
18 | if (CMAKE_BUILD_TYPE STREQUAL "Release")
19 | message(STATUS "==========Build Release Version==========")
20 | else()
21 | message(STATUS "==========Build Debug Version===========")
22 | endif()
23 |
24 | message(STATUS "===============Build Core===============")
25 | add_subdirectory(core)
26 |
27 | if (BUILD_CLIENT_X OR BUILD_BOTH_X OR BUILD_ALL_X)
28 | message(STATUS "==============Build Client==============")
29 | add_subdirectory(client)
30 | endif()
31 |
32 | if (BUILD_SERVER_X OR BUILD_BOTH_X OR BUILD_ALL_X)
33 | message(STATUS "==============Build Server==============")
34 | add_subdirectory(server)
35 | endif()
36 |
37 | if (BUILD_SERVER_X_TEST OR BUILD_ALL_X)
38 | message(STATUS "===============Build Test===============")
39 | add_subdirectory(test)
40 | endif()
--------------------------------------------------------------------------------
/src/README.md:
--------------------------------------------------------------------------------
1 | ## PiLibrary 源码
2 |
3 | * [client](./client):客户端
4 | * [core](./core):核心接口
5 | * [server](./server):服务端
6 | * [test](./test):单元测试
--------------------------------------------------------------------------------
/src/client/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | project(client)
2 |
3 | set(Boost_USE_STATIC_LIBS ON)
4 | set(Boost_USE_MULTITHREADED ON)
5 | set(Boost_USE_STATIC_RUNTIME OFF)
6 |
7 | if (CMAKE_BUILD_TYPE STREQUAL "Release")
8 | set(Boost_USE_RELEASE_LIBS ON)
9 | set(Boost_USE_DEBUG_LIBS OFF)
10 | set(Boost_USE_DEBUG_RUNTIME OFF)
11 | else()
12 | set(Boost_USE_RELEASE_LIBS OFF)
13 | set(Boost_USE_DEBUG_LIBS ON)
14 | set(Boost_USE_DEBUG_RUNTIME ON)
15 | endif()
16 |
17 | set(CMAKE_AUTOMOC ON)
18 | set(CMAKE_AUTOUIC ON)
19 | set(CMAKE_AUTORCC ON)
20 |
21 | find_package(Boost 1.56.0 REQUIRED COMPONENTS regex date_time system thread)
22 | find_package(Qt5Widgets)
23 | find_package(Qt5Core)
24 | find_package(Qt5Gui)
25 |
26 | include_directories(${CMAKE_SOURCE_DIR}/src)
27 | include_directories(${Boost_INCLUDE_DIRS})
28 |
29 | file(GLOB_RECURSE client_sources *.cpp *h *.qrc)
30 | add_executable(client WIN32 ${client_sources})
31 |
32 | target_link_libraries(client core ${Boost_LIBRARIES} Qt5::Widgets Qt5::Core Qt5::Gui)
--------------------------------------------------------------------------------
/src/client/README.md:
--------------------------------------------------------------------------------
1 | # 客户端
2 |
3 | Qt5 + Boost.Asio
--------------------------------------------------------------------------------
/src/client/core/Book.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 |
6 | Book::xint Book::getAmount() const {
7 | return amount;
8 | }
9 |
10 | Book& Book::setAmount(const xint &value) {
11 | amount = value;
12 | return *this;
13 | }
14 |
15 | Book::xstring Book::getPosition() const {
16 | return position;
17 | }
18 |
19 | Book& Book::setPosition(const xstring &value) {
20 | position = value;
21 | return *this;
22 | }
23 |
24 | Book& Book::setFromPtree(const ptree &pt) {
25 | BookBrief::setFromPtree(pt);
26 | setAmount(pt.get("amount", 0));
27 | setPosition(pt.get("position", ""));
28 | return *this;
29 | }
30 |
31 | Book Book::fromPtree(const ptree &pt) {
32 | Book book;
33 | book.setFromPtree(pt);
34 | return std::move(book);
35 | }
36 |
37 | Book& Book::updateFromPtree(const ptree &pt) {
38 | BookBrief::updateFromPtree(pt);
39 | auto amount = pt.get_optional("amount");
40 | auto position = pt.get_optional("position");
41 | if (amount)
42 | setAmount(*amount);
43 | if (position)
44 | setPosition(*position);
45 | return *this;
46 | }
47 |
48 | Book& Book::cleanCover() {
49 | BookBrief::cleanCover();
50 | return *this;
51 | }
52 |
53 | const Book& Book::unknown() {
54 | static Book book;
55 | static bool init {false};
56 | if (!init) {
57 | book.setTitle("Unknown");
58 | init = true;
59 | }
60 | return book;
61 | }
62 |
--------------------------------------------------------------------------------
/src/client/core/Book.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
\
45 | Copyright © 2018 by %3.
\
46 | Email: %4
\
47 | Website: %6
\
48 | Github: %8
\
49 | Lisence: LGPL v3.0
").
50 | arg(QString::fromStdString(X::APP_NAME).toHtmlEscaped()).
51 | arg(QString::fromStdString(X::VERSION).toHtmlEscaped()).
52 | arg(QString::fromStdString(X::AUTHOR[0] + ", " + X::AUTHOR[1]).toHtmlEscaped()).
53 | arg(QString::fromStdString(X::EMAIL[0] + ", " + X::EMAIL[1]).toHtmlEscaped()).
54 | arg(QString::fromStdString(X::WEBSITE).toHtmlEscaped()).
55 | arg(QString::fromStdString(X::WEBSITE).toHtmlEscaped()).
56 | arg(QString::fromStdString(X::GITHUB).toHtmlEscaped()).
57 | arg(QString::fromStdString(X::GITHUB).toHtmlEscaped())
58 | );
59 | label->setOpenExternalLinks(true);
60 | label->setWordWrap(true);
61 | label->setFixedWidth(600);
62 |
63 | btnUpdate->setText(tr("Check update"));
64 | }
65 |
--------------------------------------------------------------------------------
/src/client/page/PageAbout.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 | #include
8 | #include
9 |
10 | class PageAbout : public QWidget {
11 | Q_OBJECT
12 |
13 | public:
14 | PageAbout(QWidget *parent = Q_NULLPTR);
15 |
16 | private:
17 | void setUI();
18 | void setConnection();
19 |
20 | private:
21 | QLabel *label;
22 | QPushButton *btnUpdate;
23 | };
24 |
--------------------------------------------------------------------------------
/src/client/page/PageAddBook.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 |
6 | #include
7 | #include
8 |
9 | PageAddBook::PageAddBook(UserManager &userManager, BookManager &bookManager, QWidget *parent) :
10 | WidgetSetBook(userManager, bookManager, parent) {
11 |
12 | setUI();
13 | setConnection();
14 | }
15 |
16 | void PageAddBook::slotAdd() {
17 | WidgetSetBook::getData();
18 | bookManager.addBook(pt, cover, std::bind(&PageAddBook::slotAddEnd, this, std::placeholders::_1));
19 | }
20 |
21 | void PageAddBook::slotAddEnd(const X::ErrorCode &ec) {
22 | if (ec == X::NoError) {
23 | QMessageBox::information(this, tr("Add result"), tr("Successfully!"));
24 | } else {
25 | lblMessage->setText(X::what(ec));
26 | lblMessage->show();
27 | }
28 | }
29 |
30 | void PageAddBook::setUI() {
31 | lblBookid->hide();
32 | editBookid->setDisabled(true);
33 | editBookid->hide();
34 | }
35 |
36 | void PageAddBook::setConnection() {
37 | connect(btnAdd, &QPushButton::clicked, this, &PageAddBook::slotAdd);
38 | }
39 |
--------------------------------------------------------------------------------
/src/client/page/PageAddBook.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 |
8 | #include
9 | #include
10 | #include
11 |
12 | class PageAddBook : public WidgetSetBook {
13 | Q_OBJECT
14 |
15 | public:
16 | PageAddBook(UserManager &userManager, BookManager &bookManager, QWidget *parent = Q_NULLPTR);
17 |
18 | public slots:
19 | void slotAdd();
20 | void slotAddEnd(const X::ErrorCode &ec);
21 |
22 | private:
23 | void setUI();
24 | void setConnection();
25 | };
26 |
--------------------------------------------------------------------------------
/src/client/page/PageAdminister.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | #include
14 | #include
15 |
16 | class PageAdminister : public QWidget {
17 | Q_OBJECT
18 |
19 | public:
20 | PageAdminister(UserManager &userManager, BookManager &bookManager, QWidget *parent = Q_NULLPTR);
21 |
22 | signals:
23 | void signalReady();
24 |
25 | public slots:
26 | void slotReturn();
27 | void slotSetPriority();
28 |
29 | private:
30 | void setUI();
31 | void setConnection();
32 |
33 | private:
34 | UserManager &userManager;
35 | BookManager &bookManager;
36 |
37 | QLabel *lblReturnUserid;
38 | QLabel *lblReturnBookid;
39 | QLineEdit *editReturnUserid;
40 | QLineEdit *editReturnBookid;
41 | QPushButton *btnReturn;
42 |
43 | QLabel *lblSetPriorityUserid;
44 | QLabel *lblSetPriority;
45 | QLineEdit *editSetPriorityUserid;
46 | QComboBox *cbboxSetPriority;
47 | QPushButton *btnSetPriority;
48 |
49 | QStringList priorityList;
50 | std::vector priorityInfo;
51 | };
52 |
--------------------------------------------------------------------------------
/src/client/page/PageBrowse.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | PageBrowse::PageBrowse(UserManager &userManager, BookManager &bookManager, QWidget *parent) :
13 | QWidget(parent),
14 | userManager(userManager),
15 | bookManager(bookManager) {
16 |
17 | tabWidget = new QTabWidget(this);
18 |
19 | listWidgetNewBook = new ListWidgetBrowseBook(userManager, bookManager, this);
20 |
21 | listWidgetTopBook = new ListWidgetBrowseBook(userManager, bookManager, this);
22 |
23 | widgetSearchBook = new WidgetSearchBook(this);
24 | listWidgetSearchBook = new ListWidgetBrowseBook(userManager, bookManager, this);
25 |
26 | setUI();
27 | setConnection();
28 | }
29 |
30 | void PageBrowse::updateStar(const X::xint &bookid, bool star) {
31 | listWidgetNewBook->updateStar(bookid, star);
32 | listWidgetTopBook->updateStar(bookid, star);
33 | listWidgetSearchBook->updateStar(bookid, star);
34 | }
35 |
36 | void PageBrowse::slotReady() {
37 | if (++readyCount == 2) {
38 | emit signalReady();
39 | }
40 | }
41 |
42 | void PageBrowse::refresh() {
43 | readyCount = 0;
44 | {
45 | listWidgetNewBook->clear();
46 | auto thread = new ThreadGetNewBookList(userManager.getToken(), 15, this);
47 | connect(thread, &ThreadGetNewBookList::done, listWidgetNewBook, std::bind(&ListWidgetBrowseBook::slotGetBookList, listWidgetNewBook, std::placeholders::_1, std::placeholders::_2, false));
48 | connect(thread, &ThreadGetNewBookList::finished, thread, &QObject::deleteLater);
49 | thread->start();
50 | }
51 | {
52 | listWidgetTopBook->clear();
53 | auto thread = new ThreadGetTopBookList(userManager.getToken(), 15, this);
54 | connect(thread, &ThreadGetTopBookList::done, listWidgetTopBook, std::bind(&ListWidgetBrowseBook::slotGetBookList, listWidgetTopBook, std::placeholders::_1, std::placeholders::_2, true));
55 | connect(thread, &ThreadGetTopBookList::finished, thread, &QObject::deleteLater);
56 | thread->start();
57 | }
58 | }
59 |
60 | void PageBrowse::slotSearch(const X::ptree &pt) {
61 | listWidgetSearchBook->clear();
62 | auto thread = new ThreadGetSearchBookList(userManager.getToken(), pt, this);
63 | connect(thread, &ThreadGetSearchBookList::done, listWidgetSearchBook, std::bind(&ListWidgetBrowseBook::slotGetBookList, listWidgetSearchBook, std::placeholders::_1, std::placeholders::_2, false));
64 | connect(thread, &ThreadGetSearchBookList::finished, thread, &QObject::deleteLater);
65 | thread->start();
66 | }
67 |
68 | void PageBrowse::setUI() {
69 | listWidgetNewBook->setFrameStyle(QFrame::NoFrame);
70 | listWidgetTopBook->setFrameStyle(QFrame::NoFrame);
71 | listWidgetSearchBook->setFrameStyle(QFrame::NoFrame);
72 |
73 | tabWidget->addTab(listWidgetNewBook, tr("Newest Book"));
74 | tabWidget->addTab(listWidgetTopBook, tr("Top Book"));
75 |
76 | QWidget *w = new QWidget(this);
77 | auto layoutSearch = new QVBoxLayout;
78 | layoutSearch->addWidget(widgetSearchBook);
79 | layoutSearch->addWidget(listWidgetSearchBook);
80 | w->setLayout(layoutSearch);
81 | w->setContentsMargins(0, 0, 0, 0);
82 |
83 | tabWidget->addTab(w, tr("Search Book"));
84 | tabWidget->setContentsMargins(0, 0, 0, 0);
85 | layoutSearch->setContentsMargins(0, 0, 0, 0);
86 |
87 | auto layout = new QVBoxLayout;
88 | layout->addWidget(tabWidget);
89 | setLayout(layout);
90 |
91 | layout->setContentsMargins(0, 10, 0, 0);
92 | }
93 |
94 | void PageBrowse::setConnection() {
95 | connect(listWidgetNewBook,
96 | SIGNAL(signalModify()),
97 | this,
98 | SIGNAL(signalModify()));
99 | connect(listWidgetTopBook,
100 | SIGNAL(signalModify()),
101 | this,
102 | SIGNAL(signalModify()));
103 | connect(listWidgetSearchBook,
104 | SIGNAL(signalModify()),
105 | this,
106 | SIGNAL(signalModify()));
107 | connect(listWidgetNewBook,
108 | SIGNAL(signalReady()),
109 | this,
110 | SLOT(slotReady()));
111 | connect(listWidgetTopBook,
112 | SIGNAL(signalReady()),
113 | this,
114 | SLOT(slotReady()));
115 | connect(widgetSearchBook,
116 | &WidgetSearchBook::searchInfo,
117 | this,
118 | &PageBrowse::slotSearch);
119 | }
120 |
--------------------------------------------------------------------------------
/src/client/page/PageBrowse.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 | #include
8 |
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 |
15 | class PageBrowse : public QWidget {
16 | Q_OBJECT
17 |
18 | public:
19 | PageBrowse(UserManager &userManager, BookManager &bookManager, QWidget *parent = Q_NULLPTR);
20 | void updateStar(const X::xint &bookid, bool star);
21 |
22 | signals:
23 | void signalReady();
24 | void signalModify();
25 |
26 | public slots:
27 | void slotReady();
28 | void refresh();
29 | void slotSearch(const X::ptree &pt);
30 |
31 | private:
32 | void setUI();
33 | void setConnection();
34 |
35 | private:
36 | UserManager &userManager;
37 | BookManager &bookManager;
38 |
39 | QTabWidget *tabWidget;
40 |
41 | ListWidgetBrowseBook *listWidgetNewBook;
42 |
43 | ListWidgetBrowseBook *listWidgetTopBook;
44 |
45 | WidgetSearchBook *widgetSearchBook;
46 | ListWidgetBrowseBook *listWidgetSearchBook;
47 |
48 | int readyCount;
49 | };
50 |
--------------------------------------------------------------------------------
/src/client/page/PageFavorite.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 | #include
6 |
7 | #include
8 |
9 | #include
10 | #include
11 | #include
12 |
13 | PageFavorite::PageFavorite(UserManager &userManager, BookManager &bookManager, QWidget *parent) :
14 | QWidget(parent),
15 | userManager(userManager),
16 | bookManager(bookManager) {
17 |
18 | listWidgetStarRecord = new ListWidgetStarRecord(this);
19 |
20 | setUI();
21 | setConnection();
22 | }
23 |
24 | void PageFavorite::updateStar(const X::xint &bookid, bool star) {
25 | if (!star) {
26 | for (int i = 0; i < listWidgetStarRecord->count(); ++i) {
27 | auto item = dynamic_cast (listWidgetStarRecord->item(i));
28 | if (item->getBook().getBookid() == bookid) {
29 | listWidgetStarRecord->takeItem(i);
30 | break;
31 | }
32 | }
33 | } else {
34 | StarRecord record;
35 | record.setBookid(bookid);
36 | record.setTime(time(0));
37 | bookManager.getBookBrief(bookid, std::bind(&ListWidgetStarRecord::add, listWidgetStarRecord, std::placeholders::_1, record, 0));
38 | }
39 | }
40 |
41 | void PageFavorite::slotGetStarRecord(const std::vector &records) {
42 | int tot = int(records.size());
43 | for (int i = 0; i < tot; ++i) {
44 | listWidgetStarRecord->add(BookBrief::unknown(), records[i]);
45 | userManager.starBook(records[i].getBookid());
46 | }
47 | for (int i = 0; i < tot; ++i)
48 | bookManager.getBookBrief(records[i].getBookid(), std::bind(&ListWidgetStarRecord::update, listWidgetStarRecord, std::placeholders::_1, records[i], tot - 1 - i));
49 | emit signalReady();
50 | }
51 |
52 | void PageFavorite::slotItemClicked(QListWidgetItem *item) {
53 | auto x = dynamic_cast (item);
54 | auto dialog = new DialogBook(userManager, bookManager, x->getBook().getBookid(), this);
55 | connect(dialog, SIGNAL(signalModify()), this, SIGNAL(signalModify()));
56 | dialog->show();
57 | }
58 |
59 | void PageFavorite::refresh() {
60 | userManager.clearStar();
61 | listWidgetStarRecord->clear();
62 | auto obj = new GetStarRecords(userManager.getToken(), bookManager, 2147483647, 0);
63 | connect(obj, &GetStarRecords::done, this, &PageFavorite::slotGetStarRecord);
64 | obj->start();
65 | }
66 |
67 | void PageFavorite::setUI() {
68 | listWidgetStarRecord->setFrameStyle(QFrame::NoFrame);
69 |
70 | auto layout = new QVBoxLayout;
71 | layout->addWidget(listWidgetStarRecord);
72 | setLayout(layout);
73 |
74 | layout->setContentsMargins(0, 0, 0, 0);
75 | }
76 |
77 | void PageFavorite::setConnection() {
78 | connect(listWidgetStarRecord,
79 | &ListWidgetStarRecord::itemDoubleClicked,
80 | this,
81 | &PageFavorite::slotItemClicked);
82 | }
83 |
84 |
--------------------------------------------------------------------------------
/src/client/page/PageFavorite.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 |
8 | #include
9 | #include
10 | #include
11 |
12 | class PageFavorite : public QWidget {
13 | Q_OBJECT
14 |
15 | public:
16 | PageFavorite(UserManager &userManager, BookManager &bookManager, QWidget *parent = Q_NULLPTR);
17 | void updateStar(const X::xint &bookid, bool star);
18 |
19 | signals:
20 | void signalReady();
21 | void signalModify();
22 |
23 | public slots:
24 | void slotGetStarRecord(const std::vector &records);
25 | void slotItemClicked(QListWidgetItem *item);
26 |
27 | void refresh();
28 |
29 | private:
30 | void setUI();
31 | void setConnection();
32 |
33 | private:
34 | UserManager &userManager;
35 | BookManager &bookManager;
36 |
37 | ListWidgetStarRecord *listWidgetStarRecord;
38 | };
39 |
--------------------------------------------------------------------------------
/src/client/page/PageRecord.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 |
8 | #include
9 | #include
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 |
19 | class PageRecord : public QWidget {
20 | Q_OBJECT
21 |
22 | public:
23 | PageRecord(UserManager &userManager, BookManager &bookManager, QWidget *parent = Q_NULLPTR);
24 | void updateBorrow(const X::xint &bookid, const X::xll &beginTime, const X::xll &endTime);
25 | void updateBrowse(const X::xint &bookid);
26 |
27 | signals:
28 | void signalReady();
29 | void signalModify();
30 |
31 | public slots:
32 | void slotGetBrowseRecord(const std::vector &records);
33 | void slotGetKeepRecord(const std::vector &records);
34 | void slotGetBorrowRecord(const std::vector &records);
35 | void slotGetLoginRecord(const X::ErrorCode &ec, const X::ptree &pt);
36 |
37 | void slotBrowseRecordItemClicked(QListWidgetItem *item);
38 | void slotKeepRecordItemClicked(QListWidgetItem *item);
39 | void slotBorrowRecordItemClicked(QListWidgetItem *item);
40 |
41 | void refresh();
42 | void refreshBrowseRecord();
43 | void refreshKeepRecord();
44 | void refreshBorrowRecord();
45 | void refreshLoginRecord();
46 |
47 | private:
48 | void setUI();
49 | void setConnection();
50 |
51 | private:
52 | UserManager &userManager;
53 | BookManager &bookManager;
54 |
55 | QTabWidget *tabWidget;
56 | ListWidgetBrowseRecord *listWidgetBrowseRecord;
57 | ListWidgetKeepRecord *listWidgetKeepRecord;
58 | ListWidgetBorrowRecord *listWidgetBorrowRecord;
59 | ListWidgetLoginRecord *listWidgetLoginRecord;
60 | };
61 |
--------------------------------------------------------------------------------
/src/client/page/PageSetting.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/src/client/page/PageSetting.cpp
--------------------------------------------------------------------------------
/src/client/page/PageSetting.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | #include
14 |
15 | class PageSetting : public QWidget {
16 | Q_OBJECT
17 |
18 | public:
19 | PageSetting(UserManager &userManager, QWidget *parent = Q_NULLPTR);
20 |
21 | signals:
22 | void signalRefresh();
23 | void signalModifyUser();
24 | void signalLogout();
25 |
26 | public slots:
27 | void slotModify();
28 | void slotLogout();
29 | void slotChangeLanguage(int index);
30 |
31 | private:
32 | void setUI();
33 | void setConnection();
34 |
35 | private:
36 | UserManager &userManager;
37 |
38 | QPushButton *btnModify;
39 | QPushButton *btnLogout;
40 |
41 | QPushButton *btnRefresh;
42 |
43 | QComboBox *cbboxLanguage;
44 | QLabel *lblLanguage;
45 |
46 | QStringList languageList;
47 | QStringList languageFileName;
48 | };
49 |
--------------------------------------------------------------------------------
/src/client/resource/i18n/qt_zh_CN.qm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/src/client/resource/i18n/qt_zh_CN.qm
--------------------------------------------------------------------------------
/src/client/resource/i18n/zh_CN.qm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/src/client/resource/i18n/zh_CN.qm
--------------------------------------------------------------------------------
/src/client/resource/images/WidgetLogin/close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/src/client/resource/images/WidgetLogin/close.png
--------------------------------------------------------------------------------
/src/client/resource/images/WidgetLogin/drop_down_button.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/src/client/resource/images/WidgetLogin/drop_down_button.png
--------------------------------------------------------------------------------
/src/client/resource/images/WidgetLogin/head.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/src/client/resource/images/WidgetLogin/head.jpg
--------------------------------------------------------------------------------
/src/client/resource/images/WidgetLogin/min.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/src/client/resource/images/WidgetLogin/min.png
--------------------------------------------------------------------------------
/src/client/resource/resource.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | images/WidgetLogin/drop_down_button.png
4 | images/WidgetLogin/head.jpg
5 | i18n/zh_CN.qm
6 | i18n/qt_zh_CN.qm
7 | style/WidgetLogin/style.css
8 | style/WidgetLogin/title.css
9 | images/WidgetLogin/close.png
10 | images/WidgetLogin/min.png
11 | style/DialogSignUp/style.css
12 | style/ListWidgetNavigation/style.css
13 | style/WidgetMain/style.css
14 | style/DialogBook/style.css
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/client/resource/style/DialogBook/style.css:
--------------------------------------------------------------------------------
1 | * { font-family: Microsoft YaHei; }
2 |
3 | QDialog {
4 | background: white;
5 | }
6 |
7 | QPushButton#btnMore {
8 | text-align:left;
9 | color: rgb(38, 133, 227);
10 | background-color: transparent;
11 | }
12 |
13 | QPushButton#btnMore:hover {
14 | color: rgb(97, 179, 246);
15 | }
16 |
17 | QPushButton#btnMore:pressed {
18 | color: rgb(0, 109, 176);
19 | }
--------------------------------------------------------------------------------
/src/client/resource/style/DialogSignUp/style.css:
--------------------------------------------------------------------------------
1 | * { font-family: Microsoft YaHei; }
2 |
3 | QLineEdit {
4 | background: white;
5 | padding-left: 5px;
6 | padding-top: 1px;
7 | border-radius: 3px;
8 | border: 1px solid rgb(209, 209, 209);
9 | }
10 |
11 | QLineEdit:hover {
12 | border: 1px solid rgb(21, 131, 221);
13 | }
14 |
15 | DialogSignUp {
16 | background: white;
17 | }
18 |
19 | QPushButton {
20 | color: white;
21 | background-color: rgb(14, 150, 254);
22 | border-radius: 5px;
23 | }
24 |
25 | QPushButton:hover {
26 | color: white;
27 | background-color: rgb(44, 137, 255);
28 | }
29 |
30 | QPushButton:pressed {
31 | color: white;
32 | background-color: rgb(14, 135, 228);
33 | padding-left: 3px;
34 | padding-top: 3px;
35 | }
36 |
--------------------------------------------------------------------------------
/src/client/resource/style/ListWidgetNavigation/style.css:
--------------------------------------------------------------------------------
1 | * { font-family: Microsoft YaHei; }
2 |
3 | QListWidget::item {
4 | padding: 20px;
5 | }
6 |
--------------------------------------------------------------------------------
/src/client/resource/style/WidgetLogin/style.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xalanq/PiLibrary/5d2a9614ab109a475b4499ebcfe3c60ec804445e/src/client/resource/style/WidgetLogin/style.css
--------------------------------------------------------------------------------
/src/client/resource/style/WidgetLogin/title.css:
--------------------------------------------------------------------------------
1 | /* Reference: https://blog.csdn.net/goforwardtostep/article/details/53792702 */
2 |
3 | * { font-family: Microsoft YaHei; }
4 |
5 | /* 最小化按钮 */
6 | QPushButton#btnMin {
7 | border-image: url(:/images/WidgetLogin/min.png) 0 60 0 0;
8 | }
9 |
10 | QPushButton#btnMin:hover {
11 | border-image: url(:/images/WidgetLogin/min.png) 0 30 0 30;
12 | }
13 |
14 | QPushButton#btnMin:pressed {
15 | border-image: url(:/images/WidgetLogin/min.png) 0 0 0 60;
16 | }
17 |
18 | /* 关闭按钮 */
19 | QPushButton#btnClose {
20 | border-image: url(:/images/WidgetLogin/close.png) 0 60 0 0;
21 | border-top-right-radius: 3;
22 | }
23 |
24 | QPushButton#btnClose:hover {
25 | border-image: url(:/images/WidgetLogin/close.png) 0 30 0 30;
26 | border-top-right-radius: 3;
27 | }
28 |
29 | QPushButton#btnClose:pressed {
30 | border-image: url(:/images/WidgetLogin/close.png) 0 0 0 60;
31 | border-top-right-radius: 3;
32 | }
--------------------------------------------------------------------------------
/src/client/resource/style/WidgetMain/style.css:
--------------------------------------------------------------------------------
1 | QTabWidget::pane { /* The tab widget frame */
2 | border-top: 1px solid #C2C7CB;
3 | }
4 |
5 | QTabWidget::tab-bar {
6 | left: 5px; /* move to the right by 5px */
7 | }
8 |
9 | /* Style the tab using the tab sub-control. Note that
10 | it reads QTabBar _not_ QTabWidget */
11 | QTabBar::tab {
12 | border: 1px solid #C4C4C3;
13 | border-bottom-color: #C2C7CB; /* same as the pane color */
14 | border-top-left-radius: 4px;
15 | border-top-right-radius: 4px;
16 | min-width: 8ex;
17 | padding: 10px;
18 | }
19 |
20 | QTabBar::tab:selected, QTabBar::tab:hover {
21 | background: white;
22 | }
23 |
24 | QTabBar::tab:selected {
25 | border-color: #9B9B9B;
26 | border-bottom-color: #C2C7CB; /* same as pane color */
27 | }
28 |
29 | QTabBar::tab:!selected {
30 | margin-top: 2px; /* make non-selected tabs look smaller */
31 | }
--------------------------------------------------------------------------------
/src/client/thread/ThreadBorrowBook.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 | #include
6 |
7 | ThreadBorrowBook::ThreadBorrowBook(const xll &token, const xint &bookid, const xll &keepTime, QObject *parent) :
8 | ThreadNetwork(parent),
9 | token(token),
10 | bookid(bookid),
11 | keepTime(keepTime) {
12 | }
13 |
14 | void ThreadBorrowBook::run() {
15 | xll token = this->token;
16 | ptree pt;
17 | ActionCode ac = X::NoAction;
18 | ErrorCode ec = X::NoError;
19 |
20 | pt.put("bookid", this->bookid);
21 | pt.put("keepTime", this->keepTime);
22 |
23 | try {
24 | auto socket = newSocket();
25 | X::tcp_sync_write(socket, token, X::BorrowBook, pt);
26 | pt = ptree();
27 | X::tcp_sync_read(socket, token, ac, pt);
28 | socket.close();
29 | ec = static_cast (pt.get("error_code"));
30 | } catch (std::exception &) {
31 | ec = X::UnknownError;
32 | }
33 |
34 | emit done(ec);
35 | }
--------------------------------------------------------------------------------
/src/client/thread/ThreadBorrowBook.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 |
8 | class ThreadBorrowBook : public ThreadNetwork {
9 | Q_OBJECT
10 |
11 | public:
12 | ThreadBorrowBook(const xll &token, const xint &bookid, const xll &keepTime, QObject *parent = Q_NULLPTR);
13 |
14 | signals:
15 | void done(const ErrorCode &ec);
16 |
17 | private:
18 | void run() override;
19 |
20 | private:
21 | xll token;
22 | xint bookid;
23 | xll keepTime;
24 | };
--------------------------------------------------------------------------------
/src/client/thread/ThreadGetBook.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 | #include
6 |
7 | ThreadGetBook::ThreadGetBook(const xll &token, const xint &bookid, bool brief, QObject *parent) :
8 | ThreadNetwork(parent),
9 | token(token),
10 | bookid(bookid),
11 | brief(brief) {
12 |
13 | qRegisterMetaType("Resource");
14 | }
15 |
16 | void ThreadGetBook::run() {
17 | xll token = this->token;
18 | ptree pt;
19 | ActionCode ac = X::NoAction;
20 | ErrorCode ec = X::NoError;
21 | Resource cover;
22 |
23 | pt.put("bookid", this->bookid);
24 |
25 | try {
26 | auto socket = newSocket();
27 | X::tcp_sync_write(socket, token, brief ? X::GetBookBrief : X::GetBook, pt);
28 | pt = ptree();
29 | X::tcp_sync_read(socket, token, ac, pt);
30 | ec = static_cast (pt.get("error_code"));
31 | if (ec == X::NoError) {
32 | ptree p;
33 | p.put("bookid", this->bookid);
34 | ActionCode a;
35 | X::tcp_sync_write(socket, token, X::GetBookCover, p);
36 | p = ptree();
37 | cover = X::tcp_sync_read_with_file(socket, token, a, p);
38 | }
39 | socket.close();
40 | } catch (std::exception &) {
41 | ec = X::InvalidBook;
42 | pt = ptree();
43 | cover.clean();
44 | }
45 |
46 | emit done(ec, pt, cover);
47 | }
--------------------------------------------------------------------------------
/src/client/thread/ThreadGetBook.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 | #include
8 |
9 | class ThreadGetBook : public ThreadNetwork {
10 | Q_OBJECT
11 |
12 | public:
13 | ThreadGetBook(const xll &token, const xint &bookid, bool brief, QObject *parent = Q_NULLPTR);
14 |
15 | signals:
16 | void done(const ErrorCode &ec, const ptree &pt, const Resource &cover);
17 |
18 | private:
19 | void run() override;
20 |
21 | private:
22 | xll token;
23 | xint bookid;
24 | bool brief;
25 | };
--------------------------------------------------------------------------------
/src/client/thread/ThreadGetNewBookList.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 | #include
6 |
7 | ThreadGetNewBookList::ThreadGetNewBookList(const xll &token, const xint &number, QObject *parent) :
8 | ThreadNetwork(parent),
9 | token(token),
10 | number(number) {
11 | }
12 |
13 | void ThreadGetNewBookList::run() {
14 | xll token = this->token;
15 | ptree pt;
16 | ActionCode ac = X::NoAction;
17 | ErrorCode ec = X::NoError;
18 |
19 | pt.put("number", this->number);
20 |
21 | try {
22 | auto socket = newSocket();
23 | X::tcp_sync_write(socket, token, X::GetNewBookList, pt);
24 | pt = ptree();
25 | X::tcp_sync_read(socket, token, ac, pt);
26 | socket.close();
27 | ec = static_cast (pt.get("error_code"));
28 | } catch (std::exception &) {
29 | ec = X::UnknownError;
30 | pt = ptree();
31 | }
32 |
33 | emit done(ec, pt);
34 | }
--------------------------------------------------------------------------------
/src/client/thread/ThreadGetNewBookList.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 |
8 | class ThreadGetNewBookList : public ThreadNetwork {
9 | Q_OBJECT
10 |
11 | public:
12 | ThreadGetNewBookList(const xll &token, const xint &number, QObject *parent = Q_NULLPTR);
13 |
14 | signals:
15 | void done(const ErrorCode &ec, const ptree &pt);
16 |
17 | private:
18 | void run() override;
19 |
20 | private:
21 | xll token;
22 | xint number;
23 | };
--------------------------------------------------------------------------------
/src/client/thread/ThreadGetRecord.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 | #include
6 |
7 | ThreadGetRecord::ThreadGetRecord(const xll &token, const ActionCode &type, const xint &number, const xint &begin, QObject *parent) :
8 | ThreadNetwork(parent),
9 | token(token),
10 | type(type),
11 | number(number),
12 | begin(begin) {
13 | }
14 |
15 | void ThreadGetRecord::run() {
16 | xll token = this->token;
17 | ptree pt;
18 | ActionCode ac = X::NoAction;
19 | ErrorCode ec = X::NoError;
20 |
21 | pt.put("number", this->number);
22 | pt.put("begin", this->begin);
23 |
24 | try {
25 | auto socket = newSocket();
26 | X::tcp_sync_write(socket, token, this->type, pt);
27 | pt = ptree();
28 | X::tcp_sync_read(socket, token, ac, pt);
29 | socket.close();
30 | ec = static_cast (pt.get("error_code"));
31 | } catch (std::exception &) {
32 | ec = X::UnknownError;
33 | pt = ptree();
34 | }
35 |
36 | emit done(ec, pt);
37 | }
--------------------------------------------------------------------------------
/src/client/thread/ThreadGetRecord.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 |
8 | class ThreadGetRecord : public ThreadNetwork {
9 | Q_OBJECT
10 |
11 | public:
12 | ThreadGetRecord(const xll &token, const ActionCode &type, const xint &number, const xint& begin = 0, QObject *parent = Q_NULLPTR);
13 |
14 | signals:
15 | void done(const ErrorCode &ec, const ptree &pt);
16 |
17 | private:
18 | void run() override;
19 |
20 | private:
21 | xll token;
22 | ActionCode type;
23 | xint number;
24 | xint begin;
25 | };
--------------------------------------------------------------------------------
/src/client/thread/ThreadGetSearchBookList.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 | #include
6 |
7 | ThreadGetSearchBookList::ThreadGetSearchBookList(const xll &token, const ptree &pt, QObject *parent) :
8 | ThreadNetwork(parent),
9 | token(token),
10 | pt(pt) {
11 | }
12 |
13 | void ThreadGetSearchBookList::run() {
14 | xll token = this->token;
15 | ActionCode ac = X::NoAction;
16 | ErrorCode ec = X::NoError;
17 |
18 | try {
19 | auto socket = newSocket();
20 | X::tcp_sync_write(socket, token, X::GetSearchBookList, pt);
21 | pt = ptree();
22 | X::tcp_sync_read(socket, token, ac, pt);
23 | socket.close();
24 | ec = static_cast (pt.get("error_code"));
25 | } catch (std::exception &) {
26 | ec = X::UnknownError;
27 | pt = ptree();
28 | }
29 |
30 | emit done(ec, pt);
31 | }
--------------------------------------------------------------------------------
/src/client/thread/ThreadGetSearchBookList.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 |
8 | class ThreadGetSearchBookList : public ThreadNetwork {
9 | Q_OBJECT
10 |
11 | public:
12 | ThreadGetSearchBookList(const xll &token, const ptree &pt, QObject *parent = Q_NULLPTR);
13 |
14 | signals:
15 | void done(const ErrorCode &ec, const ptree &pt);
16 |
17 | private:
18 | void run() override;
19 |
20 | private:
21 | xll token;
22 | ptree pt;
23 | };
--------------------------------------------------------------------------------
/src/client/thread/ThreadGetTopBookList.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 | #include
6 |
7 | ThreadGetTopBookList::ThreadGetTopBookList(const xll &token, const xint &number, QObject *parent) :
8 | ThreadNetwork(parent),
9 | token(token),
10 | number(number) {
11 | }
12 |
13 | void ThreadGetTopBookList::run() {
14 | xll token = this->token;
15 | ptree pt;
16 | ActionCode ac = X::NoAction;
17 | ErrorCode ec = X::NoError;
18 |
19 | pt.put("number", this->number);
20 |
21 | try {
22 | auto socket = newSocket();
23 | X::tcp_sync_write(socket, token, X::GetTopBookList, pt);
24 | pt = ptree();
25 | X::tcp_sync_read(socket, token, ac, pt);
26 | socket.close();
27 | ec = static_cast (pt.get("error_code"));
28 | } catch (std::exception &) {
29 | ec = X::UnknownError;
30 | pt = ptree();
31 | }
32 |
33 | emit done(ec, pt);
34 | }
--------------------------------------------------------------------------------
/src/client/thread/ThreadGetTopBookList.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 |
8 | class ThreadGetTopBookList : public ThreadNetwork {
9 | Q_OBJECT
10 |
11 | public:
12 | ThreadGetTopBookList(const xll &token, const xint &number, QObject *parent = Q_NULLPTR);
13 |
14 | signals:
15 | void done(const ErrorCode &ec, const ptree &pt);
16 |
17 | private:
18 | void run() override;
19 |
20 | private:
21 | xll token;
22 | xint number;
23 | };
--------------------------------------------------------------------------------
/src/client/thread/ThreadLogin.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 | #include
6 |
7 | ThreadLogin::ThreadLogin(const QString &username, const QString &password, QObject *parent) :
8 | ThreadNetwork(parent),
9 | username(username.toStdString()),
10 | password(password.toStdString()) {
11 | }
12 |
13 | void ThreadLogin::run() {
14 | xll token = 0;
15 | ptree pt;
16 | ActionCode ac = X::NoAction;
17 | ErrorCode ec = X::NoError;
18 |
19 | pt.put("username", username);
20 | pt.put("password", password);
21 |
22 | try {
23 | auto socket = newSocket();
24 | X::tcp_sync_write(socket, token, X::Login, pt);
25 | pt = ptree();
26 | X::tcp_sync_read(socket, token, ac, pt);
27 | socket.close();
28 | ec = static_cast (pt.get("error_code"));
29 | } catch (std::exception &) {
30 | ec = X::LoginFailed;
31 | token = 0;
32 | pt = ptree();
33 | }
34 |
35 | emit done(ec, token, pt);
36 | }
37 |
--------------------------------------------------------------------------------
/src/client/thread/ThreadLogin.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 |
8 | #include
9 |
10 | class ThreadLogin : public ThreadNetwork {
11 | Q_OBJECT
12 |
13 | public:
14 | ThreadLogin(const QString &username, const QString &password, QObject *parent = Q_NULLPTR);
15 |
16 | signals:
17 | void done(const ErrorCode &ec, const xll &token, const ptree &pt);
18 |
19 | private:
20 | void run() override;
21 |
22 | private:
23 | xstring username;
24 | xstring password;
25 | };
--------------------------------------------------------------------------------
/src/client/thread/ThreadLogout.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 | #include
6 |
7 | ThreadLogout::ThreadLogout(const xll &token, QObject *parent) :
8 | ThreadNetwork(parent),
9 | token(token) {
10 | }
11 |
12 | void ThreadLogout::run() {
13 | xll token = this->token;
14 | ptree pt;
15 | ActionCode ac = X::NoAction;
16 | ErrorCode ec = X::NoError;
17 |
18 | try {
19 | auto socket = newSocket();
20 | X::tcp_sync_write(socket, token, X::Logout, pt);
21 | pt = ptree();
22 | X::tcp_sync_read(socket, token, ac, pt);
23 | socket.close();
24 | ec = static_cast (pt.get("error_code"));
25 | } catch (std::exception &) {
26 | ec = X::UnknownError;
27 | }
28 |
29 | emit done(ec);
30 | }
31 |
--------------------------------------------------------------------------------
/src/client/thread/ThreadLogout.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 |
8 | #include
9 |
10 | class ThreadLogout : public ThreadNetwork {
11 | Q_OBJECT
12 |
13 | public:
14 | ThreadLogout(const xll &token, QObject *parent = Q_NULLPTR);
15 |
16 | signals:
17 | void done(const ErrorCode &ec);
18 |
19 | private:
20 | void run() override;
21 |
22 | private:
23 | xll token;
24 | };
--------------------------------------------------------------------------------
/src/client/thread/ThreadModifyUser.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 | #include
6 |
7 | ThreadModifyUser::ThreadModifyUser(const xll &token, const QString &nickname, const QString &email, const QString &passwordOld, const QString &passwordNew, QObject *parent) :
8 | ThreadNetwork(parent),
9 | token(token),
10 | nickname(nickname.toStdString()),
11 | email(email.toStdString()),
12 | passwordOld(passwordOld.toStdString()),
13 | passwordNew(passwordNew.toStdString()) {
14 |
15 | }
16 |
17 | void ThreadModifyUser::run() {
18 | xll token = this->token;
19 | ptree pt;
20 | ActionCode ac = X::NoAction;
21 | ErrorCode ec = X::NoError;
22 |
23 | pt.put("nickname", nickname);
24 | pt.put("email", email);
25 | pt.put("passwordOld", passwordOld);
26 | if (passwordNew.size() > 0)
27 | pt.put("passwordNew", passwordNew);
28 |
29 | try {
30 | auto socket = newSocket();
31 | X::tcp_sync_write(socket, token, X::Modify, pt);
32 | pt = ptree();
33 | X::tcp_sync_read(socket, token, ac, pt);
34 | socket.close();
35 | ec = static_cast (pt.get("error_code"));
36 | } catch (std::exception &) {
37 | ec = X::ModifyFailed;
38 | }
39 |
40 | emit done(ec);
41 | }
--------------------------------------------------------------------------------
/src/client/thread/ThreadModifyUser.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 |
8 | #include
9 |
10 | class ThreadModifyUser : public ThreadNetwork {
11 | Q_OBJECT
12 |
13 | public:
14 | ThreadModifyUser(const xll &token, const QString &nickname, const QString &email, const QString &passwordOld, const QString &passwordNew, QObject *parent = Q_NULLPTR);
15 |
16 | signals:
17 | void done(const ErrorCode &ec);
18 |
19 | private:
20 | void run() override;
21 |
22 | private:
23 | xll token;
24 | xstring nickname;
25 | xstring email;
26 | xstring passwordOld;
27 | xstring passwordNew;
28 | };
--------------------------------------------------------------------------------
/src/client/thread/ThreadNetwork.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 |
6 | #include
7 |
8 | ThreadNetwork::ThreadNetwork(QObject *parent) :
9 | QThread(parent),
10 | io_service(),
11 | ep(boost::asio::ip::address::from_string(
12 | QSettings().value("Network/server_url", "127.0.0.1").toString().toStdString()),
13 | QSettings().value("Network/server_port", 2333).toInt()) {
14 | qRegisterMetaType("xll");
15 | qRegisterMetaType("xint");
16 | qRegisterMetaType("ptree");
17 | qRegisterMetaType("xstring");
18 | qRegisterMetaType("ErrorCode");
19 | qRegisterMetaType("ActionCode");
20 | }
21 |
22 | boost::asio::ip::tcp::socket ThreadNetwork::newSocket() {
23 | boost::asio::ip::tcp::socket socket(io_service);
24 | socket.connect(ep);
25 | return std::move(socket);
26 | }
27 |
--------------------------------------------------------------------------------
/src/client/thread/ThreadNetwork.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 |
8 | #include
9 |
10 | #include
11 |
12 | class ThreadNetwork : public QThread {
13 | Q_OBJECT
14 |
15 | public:
16 | typedef X::xll xll;
17 | typedef X::xint xint;
18 | typedef X::ptree ptree;
19 | typedef X::xstring xstring;
20 | typedef X::ErrorCode ErrorCode;
21 | typedef X::ActionCode ActionCode;
22 |
23 | ThreadNetwork(QObject *parent = Q_NULLPTR);
24 | virtual ~ThreadNetwork() = default;
25 |
26 | boost::asio::ip::tcp::socket newSocket();
27 |
28 | private:
29 | boost::asio::io_service io_service;
30 | boost::asio::ip::tcp::endpoint ep;
31 | };
32 |
--------------------------------------------------------------------------------
/src/client/thread/ThreadReturnBook.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 | #include
6 |
7 | ThreadReturnBook::ThreadReturnBook(const xll &token, const xint &userid, const xint &bookid, QObject *parent) :
8 | ThreadNetwork(parent),
9 | token(token),
10 | userid(userid),
11 | bookid(bookid) {
12 | }
13 |
14 | void ThreadReturnBook::run() {
15 | xll token = this->token;
16 | ptree pt;
17 | ActionCode ac = X::NoAction;
18 | ErrorCode ec = X::NoError;
19 |
20 | pt.put("userid", this->userid);
21 | pt.put("bookid", this->bookid);
22 |
23 | try {
24 | auto socket = newSocket();
25 | X::tcp_sync_write(socket, token, X::ReturnBook, pt);
26 | pt = ptree();
27 | X::tcp_sync_read(socket, token, ac, pt);
28 | socket.close();
29 | ec = static_cast (pt.get("error_code"));
30 | } catch (std::exception &) {
31 | ec = X::UnknownError;
32 | }
33 |
34 | emit done(ec);
35 | }
--------------------------------------------------------------------------------
/src/client/thread/ThreadReturnBook.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 |
8 | class ThreadReturnBook : public ThreadNetwork {
9 | Q_OBJECT
10 |
11 | public:
12 | ThreadReturnBook(const xll &token, const xint &userid, const xint &bookid, QObject *parent = Q_NULLPTR);
13 |
14 | signals:
15 | void done(const ErrorCode &ec);
16 |
17 | private:
18 | void run() override;
19 |
20 | private:
21 | xll token;
22 | xint userid;
23 | xint bookid;
24 | };
--------------------------------------------------------------------------------
/src/client/thread/ThreadSetBook.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 | #include
6 |
7 | ThreadSetBook::ThreadSetBook(const xll &token, const ptree &pt, const Resource &cover, QObject *parent) :
8 | ThreadNetwork(parent),
9 | token(token),
10 | pt(pt),
11 | cover(cover) {
12 | }
13 |
14 | void ThreadSetBook::run() {
15 | ActionCode ac = X::NoAction;
16 | ErrorCode ec = X::NoError;
17 |
18 | auto bookid = pt.get("bookid");
19 | try {
20 | auto socket = newSocket();
21 | X::tcp_sync_write(socket, token, X::SetBook, pt);
22 | pt = ptree();
23 | X::tcp_sync_read(socket, token, ac, pt);
24 | ec = static_cast (pt.get("error_code"));
25 |
26 | if (ec == X::NoError && cover.getSize()) {
27 | pt = ptree();
28 | pt.put("bookid", bookid);
29 | pt.put("fileSize", cover.getSize());
30 | X::tcp_sync_write_with_file(socket, token, X::SetBookCover, pt, cover);
31 | pt = ptree();
32 | X::tcp_sync_read(socket, token, ac, pt);
33 | ec = static_cast (pt.get("error_code"));
34 | }
35 | socket.close();
36 | } catch (std::exception &) {
37 | ec = X::UnknownError;
38 | }
39 |
40 | emit done(ec);
41 | }
42 |
--------------------------------------------------------------------------------
/src/client/thread/ThreadSetBook.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 | #include
8 |
9 | class ThreadSetBook : public ThreadNetwork {
10 | Q_OBJECT
11 |
12 | public:
13 | ThreadSetBook(const xll &token, const ptree &pt, const Resource &cover, QObject *parent = Q_NULLPTR);
14 |
15 | signals:
16 | void done(const ErrorCode &ec);
17 |
18 | private:
19 | void run() override;
20 |
21 | private:
22 | xll token;
23 | ptree pt;
24 | Resource cover;
25 | };
26 |
--------------------------------------------------------------------------------
/src/client/thread/ThreadSetPriority.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 | #include
6 |
7 | ThreadSetPriority::ThreadSetPriority(const xll &token, const xint &userid, const xint &priority, QObject *parent) :
8 | ThreadNetwork(parent),
9 | token(token),
10 | userid(userid),
11 | priority(priority) {
12 | }
13 |
14 | void ThreadSetPriority::run() {
15 | xll token = this->token;
16 | ptree pt;
17 | ActionCode ac = X::NoAction;
18 | ErrorCode ec = X::NoError;
19 |
20 | pt.put("userid", this->userid);
21 | pt.put("priority", this->priority);
22 |
23 | try {
24 | auto socket = newSocket();
25 | X::tcp_sync_write(socket, token, X::SetPriority, pt);
26 | pt = ptree();
27 | X::tcp_sync_read(socket, token, ac, pt);
28 | socket.close();
29 | ec = static_cast (pt.get("error_code"));
30 | } catch (std::exception &) {
31 | ec = X::UnknownError;
32 | }
33 |
34 | emit done(ec);
35 | }
36 |
--------------------------------------------------------------------------------
/src/client/thread/ThreadSetPriority.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 |
8 | #include
9 |
10 | class ThreadSetPriority : public ThreadNetwork {
11 | Q_OBJECT
12 |
13 | public:
14 | ThreadSetPriority(const xll &token, const xint &userid, const xint &priority, QObject *parent = Q_NULLPTR);
15 |
16 | signals:
17 | void done(const ErrorCode &ec);
18 |
19 | private:
20 | void run() override;
21 |
22 | private:
23 | xll token;
24 | xint userid;
25 | xint priority;
26 | };
--------------------------------------------------------------------------------
/src/client/thread/ThreadSignUp.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 | #include
6 |
7 | ThreadSignUp::ThreadSignUp(const QString &username, const QString &nickname, const QString &password, const QString &email, QObject *parent) :
8 | ThreadNetwork(parent),
9 | username(username.toStdString()),
10 | nickname(nickname.toStdString()),
11 | password(password.toStdString()),
12 | email(email.toStdString()) {
13 | }
14 |
15 | void ThreadSignUp::run() {
16 | xll token = 0;
17 | ptree pt;
18 | ActionCode ac = X::NoAction;
19 | ErrorCode ec = X::NoError;
20 |
21 | pt.put("username", username);
22 | pt.put("nickname", nickname);
23 | pt.put("password", password);
24 | pt.put("email", email);
25 |
26 | try {
27 | auto socket = newSocket();
28 | X::tcp_sync_write(socket, token, X::Register, pt);
29 | pt = ptree();
30 | X::tcp_sync_read(socket, token, ac, pt);
31 | socket.close();
32 | ec = static_cast (pt.get("error_code"));
33 | } catch (std::exception &) {
34 | ec = X::RegisterFailed;
35 | }
36 |
37 | emit done(ec);
38 | }
--------------------------------------------------------------------------------
/src/client/thread/ThreadSignUp.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 |
8 | #include
9 |
10 | class ThreadSignUp : public ThreadNetwork {
11 | Q_OBJECT
12 |
13 | public:
14 | ThreadSignUp(const QString &username, const QString &nickname, const QString &password, const QString &email, QObject *parent = Q_NULLPTR);
15 |
16 | signals:
17 | void done(const ErrorCode &ec);
18 |
19 | private:
20 | void run() override;
21 |
22 | private:
23 | xstring username;
24 | xstring nickname;
25 | xstring password;
26 | xstring email;
27 | };
--------------------------------------------------------------------------------
/src/client/thread/ThreadStarBook.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 | #include
6 |
7 | ThreadStarBook::ThreadStarBook(const xll &token, const xint &bookid, QObject *parent) :
8 | ThreadNetwork(parent),
9 | token(token),
10 | bookid(bookid) {
11 | }
12 |
13 | void ThreadStarBook::run() {
14 | xll token = this->token;
15 | ptree pt;
16 | ActionCode ac = X::NoAction;
17 | ErrorCode ec = X::NoError;
18 |
19 | pt.put("bookid", this->bookid);
20 |
21 | try {
22 | auto socket = newSocket();
23 | X::tcp_sync_write(socket, token, X::StarBook, pt);
24 | pt = ptree();
25 | X::tcp_sync_read(socket, token, ac, pt);
26 | socket.close();
27 | ec = static_cast (pt.get("error_code"));
28 | } catch (std::exception &) {
29 | ec = X::UnknownError;
30 | }
31 |
32 | emit done(ec);
33 | }
--------------------------------------------------------------------------------
/src/client/thread/ThreadStarBook.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 |
8 | class ThreadStarBook : public ThreadNetwork {
9 | Q_OBJECT
10 |
11 | public:
12 | ThreadStarBook(const xll &token, const xint &bookid, QObject *parent = Q_NULLPTR);
13 |
14 | signals:
15 | void done(const ErrorCode &ec);
16 |
17 | private:
18 | void run() override;
19 |
20 | private:
21 | xll token;
22 | xint bookid;
23 | };
--------------------------------------------------------------------------------
/src/client/thread/ThreadUnStarBook.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 | #include
6 |
7 | ThreadUnStarBook::ThreadUnStarBook(const xll &token, const xint &bookid, QObject *parent) :
8 | ThreadNetwork(parent),
9 | token(token),
10 | bookid(bookid) {
11 | }
12 |
13 | void ThreadUnStarBook::run() {
14 | xll token = this->token;
15 | ptree pt;
16 | ActionCode ac = X::NoAction;
17 | ErrorCode ec = X::NoError;
18 |
19 | pt.put("bookid", this->bookid);
20 |
21 | try {
22 | auto socket = newSocket();
23 | X::tcp_sync_write(socket, token, X::UnStarBook, pt);
24 | pt = ptree();
25 | X::tcp_sync_read(socket, token, ac, pt);
26 | socket.close();
27 | ec = static_cast (pt.get("error_code"));
28 | } catch (std::exception &) {
29 | ec = X::UnknownError;
30 | }
31 |
32 | emit done(ec);
33 | }
--------------------------------------------------------------------------------
/src/client/thread/ThreadUnStarBook.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 |
8 | class ThreadUnStarBook : public ThreadNetwork {
9 | Q_OBJECT
10 |
11 | public:
12 | ThreadUnStarBook(const xll &token, const xint &bookid, QObject *parent = Q_NULLPTR);
13 |
14 | signals:
15 | void done(const ErrorCode &ec);
16 |
17 | private:
18 | void run() override;
19 |
20 | private:
21 | xll token;
22 | xint bookid;
23 | };
--------------------------------------------------------------------------------
/src/client/utils.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 | #include
6 |
7 | #include
8 |
9 | namespace X {
10 | QString what(const ErrorCode &ec) {
11 | switch (ec) {
12 | case NoError:
13 | return QObject::tr("No Error");
14 | case UnknownError:
15 | return QObject::tr("Unknown Error");
16 | case InvalidBody:
17 | return QObject::tr("Invalid Body");
18 | case LoginFailed:
19 | return QObject::tr("Login Failed");
20 | case NoSuchUser:
21 | return QObject::tr("No Such User");
22 | case AlreadyLogin:
23 | return QObject::tr("Already Login");
24 | case RegisterFailed:
25 | return QObject::tr("Register Failed");
26 | case InvalidUsername:
27 | return QObject::tr("Invalid Username");
28 | case InvalidNickname:
29 | return QObject::tr("Invalid Nickname");
30 | case InvalidPassword:
31 | return QObject::tr("Invalid Password");
32 | case InvalidEmail:
33 | return QObject::tr("Invalid Email");
34 | case AlreadyRegister:
35 | return QObject::tr("Already Register");
36 | case ModifyFailed:
37 | return QObject::tr("Modify Failed");
38 | case InvalidNewPassword:
39 | return QObject::tr("Invalid New Password");
40 | case NotLogin:
41 | return QObject::tr("No Login");
42 | case InvalidToken:
43 | return QObject::tr("Invalid Token");
44 | case InvalidBook:
45 | return QObject::tr("Invalid Book");
46 | case NoSuchBook:
47 | return QObject::tr("No Such Book");
48 | case NoRestBook:
49 | return QObject::tr("No Rest Book");
50 | case AlreadyHave:
51 | return QObject::tr("Already Have");
52 | case NoHave:
53 | return QObject::tr("No Have");
54 | case InvalidTime:
55 | return QObject::tr("Invalid Time");
56 | case AlreadyStar:
57 | return QObject::tr("Already Star");
58 | case NoSuchStar:
59 | return QObject::tr("No Such Star");
60 | case NoPermission:
61 | return QObject::tr("No Permission");
62 | case InvalidResource:
63 | return QObject::tr("Invalid Resource");
64 | case NoSuchResource:
65 | return QObject::tr("No Such Resource");
66 | default:
67 | return QObject::tr("No Such Error");
68 | }
69 | }
70 |
71 | bool loadStyleSheet(QWidget *w, const QString &filename) {
72 | QFile f(filename);
73 | f.open(QFile::ReadOnly);
74 | if (f.isOpen()) {
75 | w->setStyleSheet(f.readAll());
76 | return true;
77 | }
78 | return false;
79 | }
80 |
81 | }
--------------------------------------------------------------------------------
/src/client/utils.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 | #include
8 |
9 | #include
10 |
11 | namespace X {
12 | extern QString what(const ErrorCode &ec);
13 | extern bool loadStyleSheet(QWidget *w, const QString &filename);
14 | }
--------------------------------------------------------------------------------
/src/client/values.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 |
6 | namespace X {
7 | const xstring &ORG_NAME = "Pi";
8 | const xstring &APP_NAME = "PiLibrary";
9 | const xstring &VERSION = "1.0.0";
10 | const xstring &saltBegin = "Ht1*dvj+W";
11 | const xstring &saltEnd = "zs-8Oh_wqn";
12 | }
13 |
--------------------------------------------------------------------------------
/src/client/values.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 |
8 | namespace X {
9 | extern const xstring &ORG_NAME;
10 | extern const xstring &APP_NAME;
11 | extern const xstring &VERSION;
12 | extern const xstring &saltBegin;
13 | extern const xstring &saltEnd;
14 | }
15 |
--------------------------------------------------------------------------------
/src/client/widget/WidgetHead.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 | #include
6 |
7 | #include
8 |
9 | WidgetHead::WidgetHead(UserManager &userManager, QWidget *parent) :
10 | QWidget(parent),
11 | userManager(userManager) {
12 |
13 | lblNickname = new QLabel(this);
14 |
15 | setUI();
16 | }
17 |
18 | void WidgetHead::slotModify() {
19 | lblNickname->setText(tr("Hello\n") + QString::fromStdString(userManager.getUser().getNickname()));
20 | }
21 |
22 | void WidgetHead::setUI() {
23 | lblNickname->setWordWrap(true);
24 | lblNickname->setAlignment(Qt::AlignCenter);
25 | lblNickname->setFixedHeight(100);
26 |
27 | auto layout = new QHBoxLayout;
28 | layout->addWidget(lblNickname, Qt::AlignCenter);
29 |
30 | setLayout(layout);
31 | slotModify();
32 | }
33 |
--------------------------------------------------------------------------------
/src/client/widget/WidgetHead.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 | #include
8 |
9 | #include
10 |
11 | class WidgetHead : public QWidget {
12 | Q_OBJECT
13 |
14 | public:
15 | WidgetHead(UserManager &userManager, QWidget *parent = Q_NULLPTR);
16 |
17 | public slots:
18 | void slotModify();
19 |
20 | private:
21 | void setUI();
22 |
23 | private:
24 | UserManager &userManager;
25 |
26 | QLabel *lblNickname;
27 | };
--------------------------------------------------------------------------------
/src/client/widget/WidgetLogin.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 | #include
15 | #include
16 | #include
17 |
18 | #include "ui_WidgetLogin.h"
19 |
20 | class WidgetLogin : public QWidget, private Ui::WidgetLogin {
21 | Q_OBJECT
22 |
23 | public:
24 | WidgetLogin(UserManager &userManager, QWidget *parent = Q_NULLPTR);
25 | ~WidgetLogin();
26 | void loadSetting();
27 | void saveSetting();
28 |
29 | signals:
30 | void signalAccept();
31 |
32 | public slots:
33 | void slotLoginBegin();
34 | void slotLoginEnd(const X::ErrorCode &ec, const X::xll &token, const X::ptree &pt);
35 | void slotRegister();
36 |
37 | private:
38 | void setUI();
39 | void setConnection();
40 |
41 | private:
42 | UserManager &userManager;
43 |
44 | WidgetLoginTitle *title;
45 | };
46 |
47 |
--------------------------------------------------------------------------------
/src/client/widget/WidgetLoginTitle.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | #include
9 | #include
10 |
11 | WidgetLoginTitle::WidgetLoginTitle(QWidget *moveWidget, QWidget *parent) :
12 | QWidget(parent) {
13 |
14 | btnMin = new QPushButton(this);
15 | btnMin->setObjectName("btnMin");
16 | btnClose = new QPushButton(this);
17 | btnClose->setObjectName("btnClose");
18 | this->moveWidget = moveWidget;
19 |
20 | setUI();
21 | setConnection();
22 | }
23 |
24 | void WidgetLoginTitle::setUI() {
25 | static const int W = 50;
26 | static const int H = 50;
27 |
28 | X::loadStyleSheet(this, ":/style/WidgetLogin/title.css");
29 |
30 | btnMin->setFixedSize(QSize(W, H));
31 | btnMin->setFocusPolicy(Qt::NoFocus);
32 | btnClose->setFixedSize(QSize(W, H));
33 | btnClose->setFocusPolicy(Qt::NoFocus);
34 |
35 | QHBoxLayout *layout = new QHBoxLayout(this);
36 |
37 | layout->addStretch();
38 | layout->addWidget(btnMin);
39 | layout->addWidget(btnClose);
40 | layout->setContentsMargins(0, 0, 0, 0);
41 | layout->setSpacing(0);
42 |
43 | setFixedHeight(H);
44 | setWindowFlags(Qt::FramelessWindowHint);
45 | }
46 |
47 | void WidgetLoginTitle::setConnection() {
48 | connect(btnMin, &QPushButton::clicked, this, &WidgetLoginTitle::slotMin);
49 | connect(btnClose, &QPushButton::clicked, this, &WidgetLoginTitle::slotClose);
50 | }
51 |
52 | void WidgetLoginTitle::mousePressEvent(QMouseEvent *event) {
53 | isPressed = true;
54 | startPoint = event->globalPos();
55 | QWidget::mousePressEvent(event);
56 | }
57 |
58 | void WidgetLoginTitle::mouseMoveEvent(QMouseEvent *event) {
59 | if (isPressed) {
60 | auto now = event->globalPos();
61 | auto moveDelta = now - startPoint;
62 | startPoint = now;
63 | moveWidget->move(moveWidget->pos() + moveDelta);
64 | }
65 | QWidget::mouseMoveEvent(event);
66 | }
67 |
68 | void WidgetLoginTitle::mouseReleaseEvent(QMouseEvent *event) {
69 | isPressed = false;
70 | QWidget::mouseReleaseEvent(event);
71 | }
72 |
73 | void WidgetLoginTitle::slotMin() {
74 | emit signalMin();
75 | }
76 |
77 | void WidgetLoginTitle::slotClose() {
78 | emit signalClose();
79 | }
80 |
--------------------------------------------------------------------------------
/src/client/widget/WidgetLoginTitle.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 | #include
8 | #include
9 |
10 | #include
11 |
12 | class WidgetLoginTitle : public QWidget {
13 | Q_OBJECT
14 |
15 | public:
16 | WidgetLoginTitle(QWidget *moveWidget, QWidget *parent = Q_NULLPTR);
17 |
18 | signals:
19 | void signalMin();
20 | void signalClose();
21 |
22 | private slots:
23 | void slotMin();
24 | void slotClose();
25 |
26 | private:
27 | void setUI();
28 | void setConnection();
29 |
30 | protected:
31 | void mousePressEvent(QMouseEvent *event) override;
32 | void mouseMoveEvent(QMouseEvent *event) override;
33 | void mouseReleaseEvent(QMouseEvent *event) override;
34 |
35 | private:
36 | QPushButton *btnMin;
37 | QPushButton *btnClose;
38 | QWidget *moveWidget;
39 |
40 | QPoint startPoint;
41 | bool isPressed {false};
42 | };
--------------------------------------------------------------------------------
/src/client/widget/WidgetMain.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 |
24 | class WidgetMain : public QWidget {
25 | Q_OBJECT
26 |
27 | public:
28 | WidgetMain(UserManager &userManager, BookManager &bookManager, QWidget *parent = Q_NULLPTR);
29 | void loadSetting();
30 | void saveSetting();
31 |
32 | signals:
33 | void signalLogout();
34 |
35 | public slots:
36 | void setEvents();
37 | void refresh(bool force = true);
38 |
39 | private:
40 | void setUI();
41 | void setConnection();
42 | void initListWidget();
43 | void initPageWidget();
44 |
45 | private:
46 | UserManager &userManager;
47 | BookManager &bookManager;
48 |
49 | QSettings setting;
50 |
51 | WidgetHead *widgetHead;
52 | QListWidget *listWidget;
53 | QStackedWidget *pageWidget;
54 | QScrollArea *scrollArea;
55 |
56 | PageAbout *pageAbout;
57 | PageAddBook *pageAddBook;
58 | PageBrowse *pageBrowse;
59 | PageFavorite *pageFavorite;
60 | PageRecord *pageRecord;
61 | PageAdminister *pageAdminister;
62 | PageSetting *pageSetting;
63 |
64 | DialogRefresh *dialogRefresh;
65 |
66 | int eventCount;
67 | };
68 |
--------------------------------------------------------------------------------
/src/client/widget/WidgetSearchBook.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 |
6 | #include
7 | #include
8 |
9 | #include
10 | #include
11 |
12 | WidgetSearchBook::WidgetSearchBook(QWidget *parent) :
13 | QWidget(parent) {
14 |
15 | #define XNEW(name) \
16 | lbl##name = new QLabel(this); \
17 | edit##name = new QLineEdit(this); \
18 | regex##name = new QCheckBox(this);
19 |
20 | XNEW(Title)
21 | XNEW(Author)
22 | XNEW(Introduction)
23 | XNEW(Position)
24 | XNEW(Bookid)
25 | XNEW(Publisher)
26 | XNEW(ISBN)
27 |
28 | btnSearch = new QPushButton(this);
29 | btnMore = new QPushButton(this);
30 |
31 | setUI();
32 | setConnection();
33 | }
34 |
35 | void WidgetSearchBook::slotSearch() {
36 | X::ptree pt;
37 |
38 | #define XPUT(low, big) \
39 | auto low = edit##big->text(); \
40 | if (low.size()) { \
41 | if (regex##big->isChecked()) \
42 | pt.put(#low, low.toStdString()); \
43 | else \
44 | pt.put(#low, X::escape(low.toStdString())); \
45 | }
46 |
47 | XPUT(title, Title)
48 | XPUT(author, Author)
49 | XPUT(introduction, Introduction)
50 | XPUT(position, Position)
51 | XPUT(bookid, Bookid)
52 | XPUT(publisher, Publisher)
53 | XPUT(ISBN, ISBN)
54 |
55 | emit searchInfo(pt);
56 | }
57 |
58 | void WidgetSearchBook::slotMore() {
59 | if (lblAuthor->isHidden()) {
60 | #define XSHOW(name) \
61 | lbl##name->show(); \
62 | edit##name->show(); \
63 | regex##name->show();
64 |
65 | regexTitle->show();
66 | XSHOW(Author)
67 | XSHOW(Introduction)
68 | XSHOW(Position)
69 | XSHOW(Publisher)
70 | XSHOW(Bookid)
71 | XSHOW(ISBN)
72 | } else {
73 | #define XHIDE(name) \
74 | lbl##name->hide(); \
75 | edit##name->hide(); \
76 | regex##name->hide();
77 |
78 | regexTitle->hide();
79 | XHIDE(Author)
80 | XHIDE(Introduction)
81 | XHIDE(Position)
82 | XHIDE(Publisher)
83 | XHIDE(Bookid)
84 | XHIDE(ISBN)
85 | }
86 | }
87 |
88 | void WidgetSearchBook::setUI() {
89 | int maxWidth = 130;
90 |
91 | auto layout = new QVBoxLayout;
92 |
93 | auto layoutTitle = new QHBoxLayout;
94 | lblTitle->setFixedWidth(maxWidth);
95 | lblTitle->setBuddy(editTitle);
96 | btnSearch->setText(tr("&Search"));
97 | btnMore->setText(tr("&More"));
98 | regexTitle->setText(tr("&Regex"));
99 | regexTitle->hide();
100 | layoutTitle->addWidget(lblTitle);
101 | layoutTitle->addWidget(editTitle);
102 | layoutTitle->addWidget(btnSearch);
103 | layoutTitle->addWidget(btnMore);
104 | layoutTitle->addWidget(regexTitle);
105 | layout->addLayout(layoutTitle);
106 |
107 | #define XSETUI(name) \
108 | auto layout##name = new QHBoxLayout; \
109 | lbl##name->setBuddy(edit##name); \
110 | lbl##name->setFixedWidth(maxWidth); \
111 | lbl##name->hide(); \
112 | edit##name->hide(); \
113 | regex##name->setText(tr("&Regex")); \
114 | regex##name->hide(); \
115 | layout##name->addWidget(lbl##name); \
116 | layout##name->addWidget(edit##name); \
117 | layout##name->addWidget(regex##name); \
118 | layout->addLayout(layout##name);
119 |
120 | XSETUI(Author)
121 | XSETUI(Introduction)
122 | XSETUI(Position)
123 | XSETUI(Bookid)
124 | XSETUI(Publisher)
125 | XSETUI(ISBN)
126 |
127 | lblTitle->setText(tr("Title: "));
128 | lblAuthor->setText(tr("&Author: "));
129 | lblIntroduction->setText(tr("&Introduction: "));
130 | lblPosition->setText(tr("&Position: "));
131 | lblBookid->setText(tr("&Bookid: "));
132 | lblPublisher->setText(tr("&Publisher: "));
133 | lblISBN->setText(tr("&ISBN: "));
134 |
135 | btnSearch->setDefault(true);
136 |
137 | setLayout(layout);
138 | }
139 |
140 | void WidgetSearchBook::setConnection() {
141 | connect(btnSearch, &QPushButton::clicked, this, &WidgetSearchBook::slotSearch);
142 | connect(btnMore, &QPushButton::clicked, this, &WidgetSearchBook::slotMore);
143 |
144 | #define XENTER(name) \
145 | connect(name, &QLineEdit::returnPressed, btnSearch, std::bind(&QPushButton::clicked, btnSearch, true));
146 |
147 | XENTER(editTitle)
148 | XENTER(editAuthor)
149 | XENTER(editIntroduction)
150 | XENTER(editPosition)
151 | XENTER(editBookid)
152 | XENTER(editPublisher)
153 | XENTER(editISBN)
154 | }
155 |
--------------------------------------------------------------------------------
/src/client/widget/WidgetSearchBook.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include
13 |
14 | class WidgetSearchBook : public QWidget {
15 | Q_OBJECT
16 |
17 | public:
18 | WidgetSearchBook(QWidget *parent);
19 |
20 | signals:
21 | void searchInfo(const X::ptree &pt);
22 |
23 | public slots:
24 | void slotSearch();
25 | void slotMore();
26 |
27 | private:
28 | void setUI();
29 | void setConnection();
30 |
31 | private:
32 | QLabel *lblTitle;
33 | QLabel *lblAuthor;
34 | QLabel *lblIntroduction;
35 | QLabel *lblPosition;
36 | QLabel *lblBookid;
37 | QLabel *lblPublisher;
38 | QLabel *lblISBN;
39 |
40 | QLineEdit *editTitle;
41 | QLineEdit *editAuthor;
42 | QLineEdit *editIntroduction;
43 | QLineEdit *editPosition;
44 | QLineEdit *editBookid;
45 | QLineEdit *editPublisher;
46 | QLineEdit *editISBN;
47 |
48 | QCheckBox *regexTitle;
49 | QCheckBox *regexAuthor;
50 | QCheckBox *regexIntroduction;
51 | QCheckBox *regexPosition;
52 | QCheckBox *regexBookid;
53 | QCheckBox *regexPublisher;
54 | QCheckBox *regexISBN;
55 |
56 | QPushButton *btnSearch;
57 | QPushButton *btnMore;
58 | };
59 |
--------------------------------------------------------------------------------
/src/client/widget/WidgetSetBook.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 |
18 | #include
19 | #include
20 | #include
21 | #include
22 |
23 | class WidgetSetBook : public QWidget {
24 | Q_OBJECT
25 |
26 | public:
27 | WidgetSetBook(UserManager &userManager, BookManager &bookManager, QWidget *parent = Q_NULLPTR);
28 | void getData();
29 |
30 | public slots:
31 | void slotUpload();
32 |
33 | private:
34 | void setUI();
35 | void setConnection();
36 |
37 | protected:
38 | UserManager &userManager;
39 | BookManager &bookManager;
40 |
41 | QLabel *lblCover;
42 | QLabel *lblBookid;
43 | QLabel *lblTitle;
44 | QLabel *lblAuthor;
45 | QLabel *lblISBN;
46 | QLabel *lblPublisher;
47 | QLabel *lblIntroduction;
48 | QLabel *lblPriority;
49 | QLabel *lblPosition;
50 | QLabel *lblAmount;
51 | QLabel *lblKeepTime;
52 | QLabel *lblDay;
53 | QLabel *lblHour;
54 | QLabel *lblMinute;
55 | QLabel *lblMessage;
56 |
57 | QLineEdit *editBookid;
58 | QLineEdit *editTitle;
59 | QLineEdit *editAuthor;
60 | QLineEdit *editISBN;
61 | QLineEdit *editPublisher;
62 | QPlainTextEdit *editIntroduction;
63 | QComboBox *cbboxPriority;
64 | QLineEdit *editPosition;
65 | QLineEdit *editAmount;
66 |
67 | QPushButton *btnUploadCover;
68 | QPushButton *btnAdd;
69 |
70 | QSpinBox *spinDay;
71 | QSpinBox *spinHour;
72 | QSpinBox *spinMinute;
73 |
74 | QStringList priorityList;
75 | std::vector priorityInfo;
76 |
77 | X::ptree pt;
78 | Resource cover;
79 | X::xll beforeKeepTime;
80 | };
81 |
--------------------------------------------------------------------------------
/src/core/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | project(core)
2 |
3 | set(Boost_USE_STATIC_LIBS ON)
4 | set(Boost_USE_MULTITHREADED ON)
5 | set(Boost_USE_STATIC_RUNTIME OFF)
6 |
7 | if (CMAKE_BUILD_TYPE STREQUAL "Release")
8 | set(Boost_USE_RELEASE_LIBS ON)
9 | set(Boost_USE_DEBUG_LIBS OFF)
10 | set(Boost_USE_DEBUG_RUNTIME OFF)
11 | else()
12 | set(Boost_USE_RELEASE_LIBS OFF)
13 | set(Boost_USE_DEBUG_LIBS ON)
14 | set(Boost_USE_DEBUG_RUNTIME ON)
15 | endif()
16 |
17 | find_package(Boost 1.56.0 REQUIRED COMPONENTS system filesystem)
18 |
19 | include_directories(${CMAKE_SOURCE_DIR}/src)
20 | include_directories(${Boost_INCLUDE_DIRS})
21 |
22 | file(GLOB core_sources *.cpp)
23 | add_library(core ${core_sources})
24 |
25 | target_link_libraries(core PUBLIC ${Boost_LIBRARIES})
26 |
--------------------------------------------------------------------------------
/src/core/README.md:
--------------------------------------------------------------------------------
1 | # 核心接口
2 |
--------------------------------------------------------------------------------
/src/core/Resource.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 | #include
6 |
7 | #include
8 |
9 | #include
10 |
11 | Resource::Resource(char *data, const size_t &size) :
12 | data(data),
13 | size(size) { }
14 |
15 | Resource::Resource(const Resource &r) :
16 | data(r.data),
17 | size(r.size) { }
18 |
19 | Resource::Resource(Resource &&r) :
20 | data(std::move(r.data)),
21 | size(std::move(r.size)) {
22 | r.data = nullptr;
23 | r.size = 0;
24 | }
25 |
26 | Resource& Resource::operator = (const Resource &r) {
27 | data = r.data;
28 | size = r.size;
29 | return *this;
30 | }
31 |
32 | Resource& Resource::operator = (Resource &&r) {
33 | data = std::move(r.data);
34 | size = std::move(r.size);
35 | r.data = nullptr;
36 | r.size = 0;
37 | return *this;
38 | }
39 |
40 | char* Resource::getData() {
41 | return data;
42 | }
43 |
44 | const char* Resource::getData() const {
45 | return data;
46 | }
47 |
48 | Resource& Resource::setData(char *data) {
49 | this->data = data;
50 | return *this;
51 | }
52 |
53 | size_t Resource::getSize() const {
54 | return size;
55 | }
56 |
57 | Resource& Resource::setSize(const size_t &size) {
58 | this->size = size;
59 | return *this;
60 | }
61 |
62 | void Resource::clean() {
63 | if (data) {
64 | size = 0;
65 | delete[] data;
66 | }
67 | }
68 |
69 | std::map Resource::resourceTemp {};
70 |
71 | size_t Resource::fileSize(const xstring &path) {
72 | struct stat statbuff;
73 | if (stat(path.c_str(), &statbuff) >= 0)
74 | return statbuff.st_size;
75 | return 0;
76 | }
77 |
78 | bool Resource::add(const xstring &path, const Resource &file) {
79 | auto f = Resource::copy(file);
80 | boost::filesystem::path p(path);
81 | boost::filesystem::create_directories(p.parent_path());
82 | FILE *fio = fopen(path.c_str(), "wb");
83 | if (fio == NULL)
84 | return false;
85 | if (fwrite(f.getData(), f.getSize(), 1, fio) != 1)
86 | return false;
87 | fclose(fio);
88 | auto &t = resourceTemp[path];
89 | t.clean();
90 | t = f;
91 | return true;
92 | }
93 |
94 | Resource Resource::get(const xstring &path) {
95 | auto &t = resourceTemp[path];
96 | FILE *fio = fopen(path.c_str(), "rb");
97 | if (fio == NULL) {
98 | t.clean();
99 | return nullptr;
100 | }
101 | if (t.getSize())
102 | return t;
103 | Resource file;
104 | auto size = fileSize(path);
105 | file.setSize(size)
106 | .setData(new char[size]);
107 | if (fread(file.getData(), size, 1, fio) != 1)
108 | file.clean();
109 | fclose(fio);
110 | return file;
111 | }
112 |
113 | Resource Resource::copy(const Resource &file) {
114 | char *s = new char[file.size];
115 | memcpy(s, file.data, file.size);
116 | return Resource(s, file.size);
117 | }
118 |
--------------------------------------------------------------------------------
/src/core/Resource.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include
7 |
8 | #include
9 |
10 | class Resource {
11 | public:
12 | typedef X::xll xll;
13 | typedef X::xint xint;
14 | typedef X::xstring xstring;
15 |
16 | Resource(char *data = nullptr, const size_t &size = 0);
17 | Resource(const Resource &r);
18 | Resource(Resource &&r);
19 | Resource& operator = (const Resource &r);
20 | Resource& operator = (Resource &&r);
21 |
22 | char* getData();
23 | const char* getData() const;
24 | Resource& setData(char *data);
25 |
26 | size_t getSize() const;
27 | Resource& setSize(const size_t &size);
28 |
29 | void clean();
30 |
31 | static std::map resourceTemp;
32 |
33 | static size_t fileSize(const xstring &path);
34 | static bool add(const xstring &path, const Resource &file);
35 | static Resource get(const xstring &path);
36 | static Resource copy(const Resource &file);
37 |
38 | private:
39 | char *data {};
40 | size_t size {};
41 | };
42 |
--------------------------------------------------------------------------------
/src/core/SocketInfo.cpp:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #include
5 | #include
6 |
7 | #include
8 |
9 | #include
10 |
11 | const char SocketInfo::IDENTIFIER = -101;
12 |
13 | SocketInfo::SocketInfo() {
14 | size = 0;
15 | buffer = 0;
16 | }
17 |
18 | SocketInfo::~SocketInfo() {
19 | if (buffer)
20 | delete[] buffer;
21 | }
22 |
23 | void SocketInfo::setSize(const size_t &size) {
24 | if (this->size < size) {
25 | if (buffer)
26 | delete[] buffer;
27 | buffer = new char[size];
28 | this->size = size;
29 | }
30 | }
31 |
32 | size_t SocketInfo::getSize() const {
33 | return size;
34 | }
35 |
36 | SocketInfo::xll SocketInfo::decodeHeaderToken() const {
37 | return *static_cast ((const void *)(buffer));
38 | }
39 |
40 | SocketInfo::xint SocketInfo::decodeHeaderLength() const {
41 | return *static_cast ((const void *)(buffer + sizeof(xll)));
42 | }
43 |
44 | SocketInfo::ActionCode SocketInfo::decodeHeaderActionCode() const {
45 | return *static_cast ((const void *)(buffer + sizeof(xll) + sizeof(xint)));
46 | }
47 |
48 | void SocketInfo::decodeBody(const xint &length, ptree &pt) const {
49 | std::stringstream ss;
50 | const xstring str(buffer, length);
51 | ss << str;
52 | boost::property_tree::read_json(ss, pt);
53 | }
54 |
55 | void SocketInfo::encodeIndentifier() {
56 | buffer[0] = IDENTIFIER;
57 | }
58 |
59 | void SocketInfo::encodeHeaderToken(const xll &token) {
60 | memcpy(buffer + 1, (const void *)(&token), sizeof(xll));
61 | }
62 |
63 | void SocketInfo::encodeHeaderLength(const xint &length) {
64 | memcpy(buffer + 1 + sizeof(xll), (const void *)(&length), sizeof(xint));
65 | }
66 |
67 | void SocketInfo::encodeHeaderActionCode(const ActionCode &ac) {
68 | memcpy(buffer + 1 + sizeof(xll) + sizeof(xint), (const void *)(&ac), sizeof(ActionCode));
69 | }
70 |
71 | void SocketInfo::encodeBody(const char *data, const size_t &length) {
72 | memcpy(buffer + 1 + sizeof(xll) + sizeof(xint) + sizeof(ActionCode), data, length);
73 | }
74 |
75 | void SocketInfo::encodeFile(const xint &mainLength, const char *data, const size_t &length) {
76 | memcpy(buffer + mainLength, data, length);
77 | }
78 |
79 | void SocketInfo::encodeMain(const xll &token, const xint &bodyLength, const ActionCode &ac, const char *data, const size_t &length) {
80 | encodeIndentifier();
81 | encodeHeaderToken(token);
82 | encodeHeaderLength(bodyLength);
83 | encodeHeaderActionCode(ac);
84 | encodeBody(data, length);
85 | }
86 |
87 | void SocketInfo::encodeMain(const xll &token, const xint &bodyLength, const ActionCode &ac, const xstring &str) {
88 | encodeMain(token, bodyLength, ac, str.c_str(), str.size());
89 | }
90 |
91 | void SocketInfo::encodeMain(const xll &token, const xint &bodyLength, const ActionCode &ac, const ptree &pt) {
92 | encodeMain(token, bodyLength, ac, encodePtree(pt));
93 | }
94 |
95 | SocketInfo::xstring SocketInfo::encodePtree(const ptree &pt, bool pretty) {
96 | std::stringstream ss;
97 | boost::property_tree::write_json(ss, pt, pretty);
98 | return std::move(ss.str());
99 | }
100 |
101 | void SocketInfo::decodePtree(const xstring &str, ptree &pt) {
102 | std::stringstream ss;
103 | ss << str;
104 | boost::property_tree::read_json(ss, pt);
105 | }
106 |
107 | const char *SocketInfo::getBuffer() const {
108 | return buffer;
109 | }
110 |
111 | char *SocketInfo::getBuffer() {
112 | return buffer;
113 | }
114 |
115 | void SocketInfo::setBuffer(char *buffer) {
116 | this->buffer = buffer;
117 | }
118 |
--------------------------------------------------------------------------------
/src/core/SocketInfo.h:
--------------------------------------------------------------------------------
1 | // Copyright 2018 xalanq, chang-ran
2 | // License: LGPL v3.0
3 |
4 | #pragma once
5 |
6 | #include