-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
198 lines (168 loc) · 5.88 KB
/
Copy pathMain.cpp
File metadata and controls
198 lines (168 loc) · 5.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include <vcl.h>
#include <windows.h>
#pragma hdrstop
#include <ShlObj.h>
#include <string>
#include <filesystem>
#include <iostream>
#include <fstream>
#include <ctime>
#include <cmath>
#include <vector>
#include <exception>
#include "bass/bass.h"
#pragma comment (lib,"bassx.lib")
#include "Main.h"
#include "Logs.h"
#include "UserData.h"
#include "UserControls.h"
#include "Edit.h"
#include "Chart.h"
#include "AudioStream.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "AdvSmoothProgressBar"
#pragma link "AdvSmoothTabPager"
#pragma link "AdvSmoothSlider"
#pragma link "AdvSmoothSlider"
#pragma link "AdvSmoothTabPager"
#pragma resource "*.dfm"
#pragma comment(lib, "shell32.lib")
using namespace std;
namespace fs = std::filesystem;
const string mainFolder = "readerdata";
const string logFilePath = "logs.readerdata";
const string userDataPath = "userdata.readerdata";
const string audioStreamsPath = "streampath.readerdata";
const string appVersion = "0.9";
int rowId;
vector<userBook> userBooks;
//Logs.cpp
void createLogFile();
void addLogLine(string exception);
//UserData.cpp
bool genreIsAlreadyAdded();
string getNext(string currLine, int *index);
void rewriteFileData();
void distributeString(string currLine);
void getUserData();
void __fastcall AddNewButton1Click(TObject *Sender);
//UserControls.cpp
void setAddNewComboBox(TComboBox *comboBox, string selected);
void fillComboBox(TComboBox *comboBox);
void setProgress(TAdvSmoothProgressBar *progressBar, TLabel *reportLabel);
void setLogEdit(TEdit *edit);
void setStringGrid(TStringGrid *grid, int clWIdth, int gridWidth, int height);
void drawFixedRows(TStringGrid *grid);
void clearStringGrid(TStringGrid *grid);
void updateStringGrid(TStringGrid *grid);
void clearAllInputs(TEdit *BookNameEdit1, TEdit *BookAuthorEdit1, TEdit *CustomBookGenre, TComboBox *BookGenreComboBox, TEdit *BookLenghtEdit1);
void __fastcall BookListChange(TObject *Sender);
void __fastcall LogUpButtonClick(TObject *Sender);
void __fastcall LogDownButtonClick(TObject *Sender);
void deleteRow(TStringGrid *grid);
void setReadingStat(TMemo *memo);
void printReadingStat(TLabel *label);
//Edit.cpp
void fillForm(TEdit *bookName, TEdit *authorName, TEdit *customGenre, TComboBox *genre);
//AudioStream.cpp
void __fastcall PlayButtonClick(TObject *Sender);
void __fastcall PauseButtonClick(TObject *Sender);
void getStreamHistory();
void setStreamComboBox(TComboBox *comboBox);
TMainForm *MainForm;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
bool checkFirstLaunch() {
bool isFirstLaunch;
fs::path filepath = string(mainFolder + "\\" + logFilePath);
bool filepathExists = fs::is_directory(filepath.parent_path());
if (filepathExists) {
isFirstLaunch = false;
}
else {
isFirstLaunch = true;
fs::create_directory(mainFolder);
ofstream streamDataFile(mainFolder + "\\" + audioStreamsPath);
streamDataFile.close();
}
createLogFile();
return isFirstLaunch;
}
void updateDisplays(TComboBox *genreComboBox, TComboBox *booksComboBox, TStringGrid *historyGrid, TMemo *statMemo, TLabel *label) {
string tempBlankLine = "";
setAddNewComboBox(genreComboBox, tempBlankLine);
fillComboBox(booksComboBox);
updateStringGrid(historyGrid);
setReadingStat(statMemo);
printReadingStat(label);
}
void setTabsLenght(TPageControl *pControl, int clWidth, int clHeight) {
pControl->Width = clWidth;
pControl->Height = clHeight;
}
void __fastcall TMainForm::FormCreate(TObject *Sender)
{
bool isFirstLaunch = checkFirstLaunch();
getStreamHistory();
setStreamComboBox(RadioEdit);
getUserData();
setStringGrid(HistoryGrid, HistorySheet->ClientWidth, HistoryGrid->ClientWidth, HistorySheet->Height);
setLogEdit(LogEdit);
updateDisplays(BookGenreComboBox, BookList, HistoryGrid, ReadStatMemo, ReportLabel5);
}
string returnStr(AnsiString output) {
const size_t len = (output.Length() + 1) * sizeof(System::AnsiChar);
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, len);
if (hMem) {
memcpy(GlobalLock(hMem), output.c_str(), len);
}
return output.c_str();
}
void __fastcall TMainForm::MainApplicationEventsException(TObject *Sender, Exception *E)
{
addLogLine(returnStr(E->Message));
}
void __fastcall TMainForm::HistoryGridDblClick(TObject *Sender)
{
if ((HistoryGrid->Row != 0) && (HistoryGrid->Row != HistoryGrid->RowCount - 1)) {
rowId = HistoryGrid->Row;
TEditForm *Form = new TEditForm(this);
Form->ShowModal();
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::aDeleteItemExecute(TObject *Sender)
{
deleteRow(HistoryGrid);
updateDisplays(BookGenreComboBox, BookList, HistoryGrid, ReadStatMemo, ReportLabel5);
rewriteFileData();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::aEditItemExecute(TObject *Sender)
{
updateDisplays(BookGenreComboBox, BookList, HistoryGrid, ReadStatMemo, ReportLabel5);
rewriteFileData();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ProgressButton1Click(TObject *Sender)
{
ChartForm->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ThemeButtonClick(TObject *Sender)
{
if (ThemeButton->Caption == "Disabled") {
TStyleManager::TrySetStyle("Tablet Dark");
ThemeButton->Caption = "Enabled";
}
else {
TStyleManager::TrySetStyle("Tablet Light");
ThemeButton->Caption = "Disabled";
}
}
//---------------------------------------------------------------------------