forked from panyumin/task-list
/
mainwindow.cpp
423 lines (338 loc) · 13.5 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
#include "mainwindow.h"
#include "sync_widget.h"
#include "search_dial.h"
#include <QtGui>
#include <QWidget>
#include <QDebug>
#include <QtXml>
#include <QTimer>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
syncTimer = new QTimer(this);
my_task_list = new task_list;
my_sync_widget = new sync_widget(this, Qt::Popup | Qt::Dialog);
my_sync_widget->m_oauthHelper = new OAuth::Helper(this);
initial();
setWindowTitle("Task List");
search_gen = new search;
}
MainWindow::~MainWindow()
{
delete my_task_list;
}
void MainWindow::googleSendStatus(bool result){
if(result)
statusBar()->showMessage(tr("Current file successfully sent"));
else
statusBar()->showMessage(tr("Error: current file not fully synced (Google)"));
}
void MainWindow::googleRecvStatus(bool result){
if(result)
statusBar()->showMessage(tr("Current file updated with Google Tasks"));
else
statusBar()->showMessage(tr("Error: current file not fully synced (Google)"));
}
void MainWindow::dboxSendStatus(bool result){
if(result)
statusBar()->showMessage(tr("Current file sent to Dropbox"));
else
statusBar()->showMessage(tr("Error: current file not fully synced (Dropbox)"));
}
void MainWindow::dboxRecvStatus(bool result){
if(result)
statusBar()->showMessage(tr("Dropbox files successfully pulled down"));
else
statusBar()->showMessage(tr("Error: current file not fully synced (Dropbox)"));
}
void MainWindow::googleAuthStatus(bool result){
if(result)
statusBar()->showMessage(tr("Google Authentication complete"));
else
statusBar()->showMessage(tr("Error: Tasks not authenticated, try again..."));
}
void MainWindow::dboxAuthStatus(bool result){
if(result)
statusBar()->showMessage(tr("Dropbox Authentication complete"));
else
statusBar()->showMessage(tr("Error: Dropbox not authenticated, try again..."));
}
void MainWindow::newServiceClick(){
my_sync_widget->show();
}
void MainWindow::syncClick(){
//if(syncTimer == NULL)
if(!syncTimer->isActive()){
syncTimer->start(30000);
connect(syncTimer, SIGNAL(timeout()), this, SLOT(syncClick()));
sync_service_off->setEnabled(true);
}
emit syncClickEmit();
}
void MainWindow::syncClickOff(){
syncTimer->stop();
disconnect(syncTimer, SIGNAL(timeout()), this, SLOT(syncClick()));
sync_service_off->setDisabled(true);
}
void MainWindow::serviceAdded(QString &serviceType){
sync_service->setEnabled(true);
if(serviceType == "dbox"){
send_service->setEnabled(true);
get_service->setEnabled(true);
}
else if(serviceType == "google")
{
send_service_gtask->setEnabled(true);
get_service_gtask->setEnabled(true);
}
else{
qDebug() << "serviceAdded - error, service not recognized";
}
}
void MainWindow::openXmlRecv(QString &filename){
this->my_task_list->loadXml(filename);
}
void MainWindow::initial()
{
my_sync_widget->setWindowModality(Qt::WindowModal);
my_sync_widget->hide();
connect(my_sync_widget, SIGNAL(getSaveFile(QString&)), this, SLOT(syncSaveFile(QString&)));
connect(my_sync_widget, SIGNAL(enableServiceButton(QString&)), this, SLOT(serviceAdded(QString&)));
connect(this, SIGNAL(syncClickEmit()), my_sync_widget, SLOT(syncFiles()));
connect(my_sync_widget, SIGNAL(openXml(QString&)), this, SLOT(openXmlRecv(QString&)));
connect(my_sync_widget, SIGNAL(dboxAuthResult(bool)), this, SLOT(dboxAuthStatus(bool)));
connect(my_sync_widget, SIGNAL(dboxRecvResult(bool)), this, SLOT(dboxRecvStatus(bool)));
connect(my_sync_widget, SIGNAL(dboxSendResult(bool)), this, SLOT(dboxSendStatus(bool)));
connect(my_sync_widget, SIGNAL(googleAuthResult(bool)), this, SLOT(googleAuthStatus(bool)));
connect(my_sync_widget, SIGNAL(googleRecvResult(bool)), this, SLOT(googleRecvStatus(bool)));
connect(my_sync_widget, SIGNAL(googleSendResult(bool)), this, SLOT(googleSendStatus(bool)));
fileMenu = menuBar()->addMenu(tr("&File"));
newList = new QAction( tr("&New lists..."), this );
newList->setShortcuts(QKeySequence::New);
fileMenu->addAction(newList);
connect(newList, SIGNAL(triggered()),
this->my_task_list,SLOT(new_list()));
fileMenu->addSeparator();
loadAction = new QAction(tr("&Open XML..."), this);
loadAction->setShortcuts(QKeySequence::Open);
fileMenu->addAction(loadAction);
connect(loadAction, SIGNAL(triggered()),
this, SLOT(loadFile()));
saveAction = new QAction( tr("&Save..."), this );
saveAction->setShortcuts(QKeySequence::Save);
fileMenu->addAction(saveAction);
connect(saveAction, SIGNAL(triggered()),
this, SLOT(saveFile()));
saveAsAction = new QAction( tr("&Save as..."), this );
//saveAsAction->setShortcuts(QKeySequence::SaveAs);
fileMenu->addAction(saveAsAction);
connect(saveAsAction, SIGNAL(triggered()),
this, SLOT(saveasFile()));
fileMenu->addSeparator();
printAction = new QAction(tr("&Print"),this);
printAction->setShortcuts(QKeySequence::Print);
fileMenu->addAction(printAction);
connect(printAction, SIGNAL(triggered()),
this,SLOT(print()));
fileMenu->addSeparator();
exitAction = new QAction(tr("&Exit"), this);
fileMenu->addAction(exitAction);
connect(exitAction, SIGNAL(triggered()),
this, SLOT(close()));
OptMenu = menuBar()->addMenu(tr("&Options"));
change_font = new QAction(tr("&Change Font"),this);
OptMenu->addAction(change_font);
display_note = new QAction(tr("&Display/Hide Note"), this);
OptMenu->addAction(display_note);
search_for= new QAction(tr("&Search"),this);
search_for->setShortcut(QKeySequence::Find);
OptMenu->addAction(search_for);
connect(search_for,SIGNAL(triggered()),this,SLOT(search_start()));
Template = menuBar()->addMenu(tr("&Template"));
new_grocery = new QAction(tr("&Groceries"),this);
Template->addAction(new_grocery);
new_week_task = new QAction(tr("&Weekly Task"),this);
Template->addAction(new_week_task);
Sync = menuBar()->addMenu(tr("&Sync Menu"));
new_service = new QAction(tr("&Add Service"), this);
Sync->addAction(new_service);
sync_service = new QAction(tr("&Sync Services (On)"), this);
Sync->addAction(sync_service);
sync_service_off = new QAction(tr("&Sync Services Off"), this);
Sync->addAction(sync_service_off);
send_service = new QAction(tr("&Send Current File"), this);
Sync->addAction(send_service);
get_service = new QAction(tr("&Get Dropbox Files"), this);
Sync->addAction(get_service);
send_service_gtask = new QAction(tr("&Send Current File (GTask)"), this);
Sync->addAction(send_service_gtask);
get_service_gtask = new QAction(tr("&Get GTask Files"), this);
Sync->addAction(get_service_gtask);
sync_service->setDisabled(true);
send_service->setDisabled(true);
sync_service_off->setDisabled(true);
get_service->setDisabled(true);
send_service_gtask->setDisabled(true);
get_service_gtask->setDisabled(true);
addTask = new QPushButton( tr("Add Task") );
delTask = new QPushButton( tr("Delete") );
editTask = new QPushButton( tr("Edit Task") );
pop_up = new QPushButton(tr("Pop Task Up"));
move_down = new QPushButton(tr("Move Task Down"));
search_button = new QPushButton(tr("Search"));
QWidget *main_widget = new QWidget;
QVBoxLayout *main_layout = new QVBoxLayout;
QHBoxLayout *button_layout1 = new QHBoxLayout;
QHBoxLayout *button_layout2 = new QHBoxLayout;
//here is the list name area
//main_layout->addWidget( new QLabel(tr("Lists name")),0,Qt::AlignCenter );
//main_layout->addWidget(my_task_list->lists_name);
this->my_task_list->setColumnCount(5);
QStringList tmp_l;
tmp_l << "Name" << "Note" << "Tag" << "Due Date" << "Status";
this->my_task_list->setHeaderLabels(tmp_l );
this->my_task_list->setEditTriggers(QAbstractItemView::DoubleClicked);
this->my_task_list->setSelectionMode(QAbstractItemView::SingleSelection);
this->my_task_list->setSelectionBehavior(QAbstractItemView::SelectRows);
//here is the table content
/*QStandardItemModel *tmp_mod = my_task_list->mod;
tmp_mod->setColumnCount(4);
tmp_mod->setHeaderData(0, Qt::Horizontal, tr("Name"));
tmp_mod->setHeaderData(1,Qt::Horizontal, tr("Note"));
tmp_mod->setHeaderData(2,Qt::Horizontal, tr("Due date"));
tmp_mod->setHeaderData(3,Qt::Horizontal, tr("Status"));
my_task_list->table->setModel(tmp_mod);
my_task_list->table->setEditTriggers(QAbstractItemView::DoubleClicked);
my_task_list->table->setSelectionMode(QAbstractItemView::SingleSelection);
my_task_list->table->setSelectionBehavior(QAbstractItemView::SelectRows);*/
/*QTreeWidgetItem* task_child = new QTreeWidgetItem(this->my_task_list,0);
task_child->setText(0,"a");
this->my_task_list->addTopLevelItem(task_child);
QTreeWidgetItem* task_child1 = new QTreeWidgetItem(task_child,1);
task_child1->setText(0,"1");
QTreeWidgetItem* task_child2 = new QTreeWidgetItem(task_child,1);
task_child2->setText(0,"2");
QTreeWidgetItem* task_child3 = new QTreeWidgetItem(task_child,1);
task_child3->setText(0,"3");
task_child->addChild(task_child1);
task_child->addChild(task_child2);
task_child->addChild(task_child3);
QTreeWidgetItem* task_child4 = new QTreeWidgetItem(task_child,1);
task_child4->setText(0,"0");
task_child->insertChild(-2,task_child4);
*/
main_layout->addWidget( new QLabel(tr("Current Lists")),0,Qt::AlignCenter );
main_layout->addWidget(this->my_task_list);
button_layout1->addWidget(addTask);
button_layout1->addWidget(delTask);
button_layout1->addWidget(editTask);
button_layout2->addWidget(pop_up);
button_layout2->addWidget(move_down);
button_layout2->addWidget(search_button);
main_layout->addLayout(button_layout1);
main_layout->addLayout(button_layout2);
main_widget->setLayout(main_layout);
main_widget->setMinimumSize(520,500);
this->setCentralWidget(main_widget);
//connection
connect(addTask, SIGNAL(clicked()),
this->my_task_list,SLOT(addTask()));
connect(delTask, SIGNAL(clicked()),
this->my_task_list,SLOT(delTask()));
connect(editTask, SIGNAL(clicked()),
this->my_task_list, SLOT(editTask()));
connect(display_note, SIGNAL(triggered()),
this->my_task_list, SLOT(show_hide_Note()));//the action one in the menu
connect(change_font, SIGNAL(triggered()),
this->my_task_list, SLOT(changeFont()));
connect(pop_up, SIGNAL(clicked()),
this->my_task_list, SLOT(pop_up()));
connect(move_down, SIGNAL(clicked()),
this->my_task_list, SLOT(move_down()));
connect(new_grocery, SIGNAL(triggered()),
this->my_task_list, SLOT(grocery()));
connect(new_week_task, SIGNAL(triggered()),
this->my_task_list, SLOT(week_task()));
connect(new_service, SIGNAL(triggered()),
this, SLOT(newServiceClick()));
connect(sync_service, SIGNAL(triggered()),
this, SLOT(syncClick()));
connect(sync_service_off, SIGNAL(triggered()),
this, SLOT(syncClickOff()));
connect(send_service, SIGNAL(triggered()),
this->my_sync_widget, SLOT(sendFiles()));
connect(get_service, SIGNAL(triggered()),
this->my_sync_widget, SLOT(getFiles()));
connect(send_service_gtask, SIGNAL(triggered()),
this->my_sync_widget, SLOT(sendFilesGTask()));
connect(get_service_gtask, SIGNAL(triggered()),
this->my_sync_widget, SLOT(getFilesGTask()));
connect(search_button, SIGNAL(clicked()), this, SLOT(search_start()));
}
void MainWindow::loadFile()
{
QString fileName = QFileDialog::getOpenFileName(this);
if (!fileName.isEmpty())
{
this->my_task_list->loadXml(fileName);
}
}
void MainWindow::saveasFile()
{
QString fileName = QFileDialog::getSaveFileName(this);
if (!fileName.isEmpty())
{
this->my_task_list->writeXml(fileName);
}
}
void MainWindow::saveFile()
{
if(this->my_task_list->file_location!="")
{
this->my_task_list->writeXml(this->my_task_list->file_location);
}
else
{
QString fileName = QFileDialog::getSaveFileName(this);
if (!fileName.isEmpty())
{
this->my_task_list->writeXml(fileName);
}
}
}
void MainWindow::syncSaveFile(QString &syncPathName)
{
if(this->my_task_list->file_location!="")
{
this->my_task_list->writeXml(this->my_task_list->file_location);
}
else
{
QString fileName = QFileDialog::getSaveFileName(this);
if (!fileName.isEmpty())
{
this->my_task_list->writeXml(fileName);
}
}
syncPathName = this->my_task_list->file_location;
}
void MainWindow::print()
{
QPrinter *printer = new QPrinter;
QPrintDialog *printDialog = new QPrintDialog(printer, this);
if (printDialog->exec() == QDialog::Accepted)
{
QPainter temp_print(printer);
QPixmap p_map = QPixmap::grabWidget(this);
temp_print.drawPixmap(0, 0, p_map);
}
}
void MainWindow::search_start(){
my_search_dial = new search_dial;
if(my_search_dial->exec()){
connect(my_search_dial, SIGNAL(emitSearch(QString)), this, SLOT(searchRecv(QString)));
}
}
void MainWindow::searchRecv(QString searchText){
this->search_gen->start_search(searchText, this->my_task_list);
}