This repository was archived by the owner on Dec 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.cpp
More file actions
268 lines (225 loc) · 7.94 KB
/
Copy pathMainWindow.cpp
File metadata and controls
268 lines (225 loc) · 7.94 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#include "MainWindow.h"
#include "EditWindow.h"
#include "CatDialog.h"
#include "CatConfig.h"
#include "Links.h"
//============================================================================
MainWindowWidget::MainWindowWidget(QWidget *parent, const char *name)
{
setCaption("sMemo");
setIcon(QPixmap::QPixmap("sMemo.png"));
setIconText("sMemo");
CategoryConfig *catConfig = new CategoryConfig();
QVBox *center = new QVBox(this, 0, 0, FALSE);
listMemos = new QListBox(center, "listMemos");
QHBox *buttons = new QHBox(center, 0, 0, FALSE);
QPushButton *btnNew = new QPushButton("New", buttons, "btnNew");
QPushButton *btnViewEdit = new QPushButton("View/Edit", buttons, "btnViewEdit");
QPushButton *btnDelete = new QPushButton("Delete", buttons, "btnDelete");
comboCategories = new QComboBox(buttons, "comboCategories");
catConfig->BuildCategoryCombo(comboCategories, TRUE);
setCentralWidget(center);
this->selected = -1;
RefreshList(listMemos);
QObject::connect(btnNew, SIGNAL(clicked()), this, SLOT(NewMemo()));
QObject::connect(btnViewEdit, SIGNAL(clicked()), this, SLOT(OpenMemo()));
QObject::connect(btnDelete, SIGNAL(clicked()), this, SLOT(DeleteMemo()));
QObject::connect(listMemos, SIGNAL(returnPressed(QListBoxItem*)), this, SLOT(OpenMemo()));
QObject::connect(listMemos, SIGNAL(doubleClicked(QListBoxItem*)), this, SLOT(OpenMemo()));
QObject::connect(comboCategories, SIGNAL(activated(int)), this, SLOT(ChangeCategory()));
QPopupMenu *menuMemo = new QPopupMenu(this);
menuMemo->insertItem("&New", this, SLOT(MenuMemoNew()));
menuMemo->insertItem("&Open", this, SLOT(MenuMemoOpen()));
menuMemo->insertItem("&Delete", this, SLOT(MenuMemoDelete()));
QPopupMenu *menuOptions = new QPopupMenu(this);
menuOptions->insertItem("&Settings", this, SLOT(MenuOptionsSettings()));
menuOptions->insertItem("&Categories", this, SLOT(MenuOptionsCategories()));
QPopupMenu *menuHelp = new QPopupMenu(this);
menuHelp->insertItem("&About", this, SLOT(MenuHelpAbout()));
menuHelp->insertItem("About &Qt", this, SLOT(MenuHelpAboutQt()));
QPEMenuBar *menu = new QPEMenuBar(this);
menu->setMargin(0);
menu->insertItem("&Memo", menuMemo);
menu->insertItem("&Options", menuOptions);
menu->insertItem("&Help", menuHelp);
delete(catConfig);
}
//============================================================================
void MainWindowWidget::NewMemo()
{
unsigned int catIndex = 0;
QDate today(QDate::currentDate());
QTime now(QTime::currentTime());
QString name;
CategoryConfig *catConfig = new CategoryConfig();
catIndex = comboCategories->currentItem();
if (catIndex==0)
catIndex++;
this->EditMemo(name.sprintf(QDir::homeDirPath()+"/sMemo/"+catConfig->folders[catIndex]+"/%4i-%02i-%02i-%02i-%02i-%02i.smemo", today.year(), today.month(), today.day(), now.hour(), now.minute(), now.second()), true);
delete(catConfig);
}
//============================================================================
void MainWindowWidget::EditMemo(QString filename, int create)
{
EditWindowWidget *editWindow = new EditWindowWidget(0, "editWindow", true, 0);
editWindow->fileName = filename;
editWindow->LoadMemo();
editWindow->catIndex = comboCategories->currentItem();
if (editWindow->catIndex>0)
editWindow->catIndex--;
editWindow->RefreshWindow();
QDialog::DialogCode retval = (QDialog::DialogCode)editWindow->exec();
if (retval==QDialog::Accepted)
{
editWindow->SaveMemo();
if (create)
{
Links *links = new Links();
links->MakeLinkInAll(filename, editWindow->catIndex+1);
delete(links);
this->selected = listMemos->count();
}
// Here must be memo category renaming if the category was changed!!!
comboCategories->setCurrentItem(editWindow->catIndex+1);
editWindow->catIndex = 0;
}
RefreshList(listMemos);
}
//============================================================================
void MainWindowWidget::RefreshList(QListBox *list)
{
unsigned int item;
QString row;
CategoryConfig *catConfig = new CategoryConfig();
list->clear();
fileList.setPath(QDir::homeDirPath()+"/sMemo/"+catConfig->folders[comboCategories->currentItem()]);
fileList.setFilter(QDir::Files);
fileList.setSorting(QDir::Name);
fileList.setNameFilter("*.smemo");
for (item=0; item<fileList.count(); item++)
{
QFile file(QDir::homeDirPath()+"/sMemo/"+catConfig->folders[comboCategories->currentItem()]+"/"+fileList[item]);
if (!file.open(IO_ReadOnly))
{
QString message = "Could not read item '" + fileList[item] + "'";
QMessageBox::warning(0, "File i/o error", message);
}
else
{
QTextStream inStream(&file);
if (!inStream.atEnd())
{
row = QString::fromUtf8(inStream.readLine());
}
else
{
row = "<empty memo>";
}
if (row.length()<1)
row = "<no caption>";
file.close();
list->insertItem(row);
}
}
if (listMemos->count()>0)
{
if (this->selected==-1)
{
listMemos->setCurrentItem(0);
}
else
{
if (listMemos->count()>this->selected)
{
listMemos->setCurrentItem(this->selected);
}
else
{
listMemos->setCurrentItem(listMemos->count()-1);
}
}
}
else
{
this->selected = -1;
}
delete(catConfig);
}
//============================================================================
void MainWindowWidget::OpenMemo()
{
int number = listMemos->currentItem();
CategoryConfig *catConfig = new CategoryConfig();
if (listMemos->count()>0)
{
this->selected = number;
this->EditMemo(QDir::homeDirPath()+"/sMemo/"+catConfig->folders[comboCategories->currentItem()]+"/"+fileList[number], false);
}
delete(catConfig);
}
//============================================================================
void MainWindowWidget::DeleteMemo()
{
CategoryConfig *catConfig = new CategoryConfig();
if (listMemos->count()>0)
{
switch (QMessageBox::warning(0, "Delete Memo", "Really delete\n'"+listMemos->currentText()+"'?", QMessageBox::Yes, QMessageBox::No))
{
case QMessageBox::Yes:
this->selected = listMemos->currentItem();
QFile::remove(QDir::homeDirPath()+"/sMemo/"+catConfig->folders[comboCategories->currentItem()]+"/"+fileList[listMemos->currentItem()]);
// Delete link!!!
RefreshList(listMemos);
break;
case QMessageBox::No:
break;
}
}
delete(catConfig);
}
//============================================================================
void MainWindowWidget::ChangeCategory()
{
RefreshList(listMemos);
}
//============================================================================
void MainWindowWidget::MenuMemoNew()
{
NewMemo();
}
//============================================================================
void MainWindowWidget::MenuMemoOpen()
{
OpenMemo();
}
//============================================================================
void MainWindowWidget::MenuMemoDelete()
{
DeleteMemo();
}
//============================================================================
void MainWindowWidget::MenuHelpAbout()
{
QString aboutText;
aboutText = "<b>sMemo 1.1</b><br>Based on noteZ<br>Written by Alexander Cheryomukhin aka SolarWind<br>solarwind.palm@gmail.com<br>Distributed under GPL";
QMessageBox::about(this, "About", aboutText);
}
//============================================================================
void MainWindowWidget::MenuHelpAboutQt()
{
QMessageBox::aboutQt(0, "About Qt");
}
//============================================================================
void MainWindowWidget::MenuOptionsSettings()
{
}
//============================================================================
void MainWindowWidget::MenuOptionsCategories()
{
CategoriesDialog *categories = new CategoriesDialog(0, "", true, 0);
categories->exec();
CategoryConfig *catConfig = new CategoryConfig();
catConfig->BuildCategoryCombo(comboCategories, TRUE);
delete(catConfig);
RefreshList(listMemos);
}