-
Notifications
You must be signed in to change notification settings - Fork 0
/
GooDer.cpp
2135 lines (1778 loc) · 71.7 KB
/
GooDer.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
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "GooDer.h"
#include "ui_GooDer.h"
#include "entry.h"
#include "addFeedDialog.h"
#include "removeFeedDialog.h"
#include "settingsDialog.h"
#include "labelNameDialog.h"
#include <QDebug>
#include <QtNetwork/QNetworkCookie>
#include <QFile>
#include <QtGui>
#include <QFont>
#include <QXmlStreamWriter>
#include <QShortcut>
#include <QSettings>
/*!
\brief Vychozi konstruktor
*/
GooDer::GooDer(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
/*!
\brief Vychozi destruktor
*/
GooDer::~GooDer()
{
qDebug() << "Exiting";
qDebug() << "";
delete ui;
}
void GooDer::changeEvent(QEvent *e) {
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
case QEvent::WindowStateChange:
if (this->isMinimized()) {
this->hide();
if (_flashEnabled) {
this->setFlash(false);
ui->browser->reload();
}
}
else {
if (_flashEnabled) {
this->setFlash(_flashEnabled);
ui->browser->reload();
}
}
break;
default:
break;
}
}
void GooDer::iconActivated(QSystemTrayIcon::ActivationReason reason) {
switch (reason) {
case QSystemTrayIcon::Trigger:
case QSystemTrayIcon::DoubleClick:
this->show();
break;
case QSystemTrayIcon::MiddleClick:
this->checkFeeds();
break;
default:
break;
}
}
/*!
\brief Inicializace prvku mimo konstruktor
*/
void GooDer::initialize() {
_settings = new QSettings("GooDer", "GooDer");
_googleReaderController = new GoogleReaderController();
_crypt = new SimpleCrypt(Q_UINT64_C(0x0c2ac1a5cea3fe23));
_timerRefreshFeeds = new QTimer(this);
_checkFeedTime = 0;
_commandHistoryCounter = -1;
_feedAdded = false;
_firstRun = true;
_fetchingEntriesFromHistory = false;
_fetchingEntriesFromHistoryActivated = true;
//vytvori polozku v systemove liste
createTray();
//nastavi ikonu v systemove liste
setIcon();
//zobrazi polozku v systemove liste
_trayIcon->show();
//skryje listu s tlacitkem pro zobrazeni seznamu zdroju
ui->frameShowFeedListButton->hide();
//nastavime pocet sloupcu v panelech se zdroji a polozkami
ui->entriesTreeWidget->sortByColumn(2);
//nastavime jmena sloupcu v panelu s polozkami
setEntriesWidget();
//vytvorime kontextove menu v seznamu zdroju
createFeedsContextMenu();
createEntriesContextMenu();
connect(_googleReaderController, SIGNAL(signalConnected(bool)),
this, SLOT(onlineState(bool)));
//nastavi pismo a pocitadlo pro rozlisovani radku
_fontNormal.setWeight(QFont::Normal);
_fontBold.setWeight(QFont::Bold);
_lineColor = QColor(220, 220, 220);
_labelColor = QColor(187, 201, 255);
_unreadColor = QColor(248, 0, 18, 50);
this->setStatusbarWidgets();
//napoji signaly
this->connectSignals();
this->loadSettings();
}
void GooDer::setStatusbarWidgets() {
_commandsLine = new QLineEdit();
_loadProgress = new QLineEdit();
QFontMetrics metrics(QApplication::font());
QPalette palette = _commandsLine->palette();
palette.setColor(QPalette::Base, Qt::transparent);
_commandsLine->setPalette(palette);
_loadProgress->setPalette(palette);
_commandsLine->setFrame(false);
_loadProgress->setFrame(false);
_loadProgress->setReadOnly(true);
_loadProgress->setFixedWidth(metrics.width("10000%"));
_loadProgress->setAlignment(Qt::AlignRight);
ui->statusbar->addPermanentWidget(_commandsLine);
ui->statusbar->addPermanentWidget(_loadProgress);
//nainstalujeme filtr pro odchytavani klaves nahoru a dolu v radce s prikazy
_commandsLine->installEventFilter(this);
}
void GooDer::setFlash(bool enable) {
QWebSettings *defaultSettings = QWebSettings::globalSettings();
defaultSettings->setAttribute(QWebSettings::JavascriptEnabled, true);
if (enable) {
defaultSettings->setAttribute(QWebSettings::PluginsEnabled, true);
qDebug() << "flash is ON";
}
else {
defaultSettings->setAttribute(QWebSettings::PluginsEnabled, false);
qDebug() << "flash is OFF";
}
}
void GooDer::loadSettings() {
if (!_settings->value("username").toString().isNull()) {
_shortcutNextEntry = (_settings->value("shortcutNextEntry", "Meta+.").toString());
_shortcutPrevEntry = (_settings->value("shortcutPrevEntry", "Meta+,").toString());
_shortcutNextFeed = (_settings->value("shortcutNextFeed", "Meta+'").toString());
_shortcutPrevFeed = (_settings->value("shortcutPrevFeed", "Meta+;").toString());
_shortcutNextLabel = (_settings->value("shortcutNextLabel", "Meta+]").toString());
_shortcutPrevLabel = (_settings->value("shortcutPrevLabel", "Meta+[").toString());
_shortcutToggleFeedPanel = (_settings->value("shortcutToggleFeedPanel", "Meta+\\").toString());
_flashEnabled = _settings->value("flash", false).toBool();
_showSummary = _settings->value("showSummary", false).toBool();
_checkFeedTime = _settings->value("checkFeedTime", 300000).toInt();
_autoHideFeedPanel = _settings->value("autoHideFeedPanel", true).toBool();
_showAllFeeds = _settings->value("showAllFeeds", true).toBool();
_showLabels = _settings->value("showLabels", true).toBool();
QString history = _settings->value("commandHistory").toString();
foreach (QString command, history.split(";", QString::SkipEmptyParts))
_commandHistory.append(command);
(_settings->value("toolbar", true).toBool()) ? ui->toolBar->show() : ui->toolBar->hide();
(_settings->value("menuVisibility", true).toBool()) ? ui->menubar->show() : ui->menubar->hide();
_timerRefreshFeeds->start(_checkFeedTime);
setShortcuts();
emit signalLogin();
}
else {
showHelp();
emit this->showSettingsDialog();
}
}
void GooDer::saveSettings() {
_settings->setValue("username", _settings->value("username"));
_settings->setValue("password", _settings->value("password"));
_settings->setValue("checkFeedTime", _checkFeedTime);
_settings->setValue("toolbar", ui->toolBar->isVisible());
_settings->setValue("autoHideFeedPanel", _autoHideFeedPanel);
_settings->setValue("menuVisibility", ui->menubar->isVisible());
_settings->setValue("flash", _flashEnabled);
_settings->setValue("showSummary", _showSummary);
_settings->setValue("showAllFeeds", _showAllFeeds);
_settings->setValue("showLabels", _showLabels);
_settings->setValue("shortcutNextEntry", _shortcutNextEntry);
_settings->setValue("shortcutPrevEntry", _shortcutPrevEntry);
_settings->setValue("shortcutNextFeed", _shortcutNextFeed);
_settings->setValue("shortcutPrevFeed", _shortcutPrevFeed);
_settings->setValue("shortcutNextLabel", _shortcutNextLabel);
_settings->setValue("shortcutPrevLabel", _shortcutPrevLabel);
_settings->setValue("shortcutToggleFeedPanel", _shortcutToggleFeedPanel);
QString history = "";
foreach (QString command, _commandHistory)
history += command + ";";
_settings->setValue("commandHistory", history);
}
/*!
\brief Ulozi veci potrebne k odesilani pozadavku
*/
void GooDer::loginSuccessfull(bool status) {
if (status) {
qDebug() << "Login was successfull -> checking feeds";
emit checkFeeds();
}
else
qDebug() << "Login was unsuccessfull";
}
/*!
\brief
*/
void GooDer::onlineState(bool online) {
_online = online;
if (!_online) {
this->setStatusBarMessage(trUtf8("Can't login to server. Please check internet connection."));
}
}
/*!
\brief Instalace filtru pro odchytaveni klaves nahoru a dolu v radku pro zadavani prikazu
*/
bool GooDer::eventFilter(QObject* obj, QEvent *event)
{
if (obj == _commandsLine) {
if (event->type() == QEvent::KeyPress) {
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
//stisknuta klavesa nahoru
if (keyEvent->key() == Qt::Key_Up) {
if (!_commandHistory.isEmpty() && _commandHistoryCounter < _commandHistory.count() -1) {
_commandHistoryCounter++;
_commandsLine->setText(_commandHistory.at(_commandHistoryCounter));
}
return true;
}
//stisknuta klavesa dolu
else if(keyEvent->key() == Qt::Key_Down) {
if (!_commandHistory.isEmpty() && _commandHistoryCounter != -1) {
_commandHistoryCounter--;
if (_commandHistoryCounter != -1)
_commandsLine->setText(_commandHistory.at(_commandHistoryCounter));
return true;
}
else {
_commandsLine->setText(":");
return true;
}
}
else if (keyEvent->key() == Qt::Key_Escape)
hideCommandLine();
}
return false;
}
return QMainWindow::eventFilter(obj, event);
}
/*!
\brief Vytvori kontextove menu pro vytvoreni slozky
*/
void GooDer::createFeedsContextMenu() {
//v seznamu zdroju
ui->feedTreeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
_feedContextMenu = new QMenu(ui->feedTreeWidget);
_actionCreateNewLabel = new QAction(trUtf8("Add label"),_feedContextMenu);
ui->feedTreeWidget->addAction(_actionCreateNewLabel);
_actionRemoveLabel = new QAction(trUtf8("Remove label"),_feedContextMenu);
ui->feedTreeWidget->addAction(_actionRemoveLabel);
_actionRemoveFeed = new QAction(trUtf8("Remove feed"),_feedContextMenu);
ui->feedTreeWidget->addAction(_actionRemoveFeed);
}
/*!
\brief Vytvori kontextove menu pro vytvoreni slozky
*/
void GooDer::createEntriesContextMenu() {
//v seznamu polozek
ui->entriesTreeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
_entryContextMenu = new QMenu(ui->entriesTreeWidget);
_actionOpenInExternBrowser = new QAction(trUtf8("Open in external browser"), _entryContextMenu);
ui->entriesTreeWidget->addAction(_actionOpenInExternBrowser);
}
/*!
\brief Nastavi klavesove zkratky pouzivane v programu
*/
void GooDer::setShortcuts() {
//odchytava dvojtecku a vola zadany slot
new QShortcut(QKeySequence(Qt::Key_Colon), this, SLOT(showCommandLine()));
//po stisknuti ZZ nebo Ctrl + Q ukonci aplikaci
new QShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Z, Qt::SHIFT + Qt::Key_Z), this, SLOT(close()));
new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this, SLOT(close()));
//po stisknuti / se zobrazi pole pro vyhledavani
new QShortcut(QKeySequence(Qt::Key_Escape), this, SLOT(hideCommandLine()));
new QShortcut(QKeySequence(Qt::Key_Slash), this, SLOT(showSearchLine()));
new QShortcut(QKeySequence::fromString(_shortcutNextEntry, QKeySequence::PortableText), this, SLOT(readNextEntry()));
new QShortcut(QKeySequence::fromString(_shortcutPrevEntry, QKeySequence::PortableText), this, SLOT(readPreviousEntry()));
new QShortcut(QKeySequence::fromString(_shortcutNextFeed, QKeySequence::PortableText), this, SLOT(readNextFeed()));
new QShortcut(QKeySequence::fromString(_shortcutPrevFeed, QKeySequence::PortableText), this, SLOT(readPreviousFeed()));
new QShortcut(QKeySequence::fromString(_shortcutPrevLabel, QKeySequence::PortableText), this, SLOT(readPreviousLabel()));
new QShortcut(QKeySequence::fromString(_shortcutNextLabel, QKeySequence::PortableText), this, SLOT(readNextLabel()));
//po stisknuti CTRL + N zobrazi dialog pro pridani zroje
new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_N), this, SLOT(showAddFeedDialog()));
//po stisknuti CTRL + R zobrazi dialog pro odebrani zdroje
new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_R), this, SLOT(showRemoveFeedDialog()));
//po stisknuti CTRL + M oznaci polozky jako prectene
new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_M), this, SLOT(markAsRead()));
//po stisknuti CTRL + P zobrazi nastaveni
new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_P), this, SLOT(showSettingsDialog()));
//po stisknuti F5 aktualizuje zdroje
new QShortcut(QKeySequence(Qt::Key_F5), this, SLOT(callCheckFeeds()));
//po stisknuti F1 zobrazi napovedu
new QShortcut(QKeySequence(Qt::Key_F1), this, SLOT(showHelp()));
//po stisknuti META + \ zobrazi/skryje seznam zdroju
new QShortcut(QKeySequence::fromString(_shortcutToggleFeedPanel, QKeySequence::PortableText), this, SLOT(showHideFeedList()));
new QShortcut(QKeySequence(Qt::META + Qt::CTRL + Qt::Key_Apostrophe), this, SLOT(readNextUnreadFeed()));
new QShortcut(QKeySequence(Qt::META + Qt::CTRL + Qt::Key_Semicolon), this, SLOT(readPrevUnreadFeed()));
}
/*!
\brief Rozpoznava prikazy a vola jednotlive ukony
*/
void GooDer::parseCommands() {
//ulozim si pozadavek
QString command = _commandsLine->text().mid(1);
if (_commandsLine->text().left(1) == "/") {
searchEntry(command);
_commandsLine->clear();
this->setFocus();
return;
}
//vlozim jej do historie
_commandHistory.append(_commandsLine->text());
_commandsLine->clear();
//pokud chci zkontrolovat zdroje
if (command == "c" || command == "check") emit checkFeeds();
//pokud chci zobrazit okno pro pridani noveho zdroje
else if ((command == "a" || command == "add") && command.length() == 1) emit signalShowAddFeedDialog();
//pokud chci pridat novy zdroj prikazem
//pokud chceme pridal label aktualni polozce
else if (command.left(7) == "a label") { emit signalAddLabel(command.mid(8)); return; }
else if (command.left(9) == "add label") { emit signalAddLabel(command.mid(10)); return; }
else if (command.left(2) == "a " && command.length() > 1) {
QStringList feedData = command.split(" ");
if (feedData.count() == 4)
emit signalAddFeed(feedData.at(1), feedData.at(2), feedData.at(3));
else
showStatusBarMessage("Enter all required informations!");
}
//pokud chci odebrat zdroj
else if (command == "rm" || command == "remove") emit signalShowRemoveFeedDialog();
else if ((command == "remove this" || command == "rm this") && command.length() >= 7 ) {
if (ui->feedTreeWidget->topLevelItemCount() > 0)
_googleReaderController->removeFeed(ui->feedTreeWidget->currentItem()->text(2));
}
//pokud chceme odebrat stitek
else if (command == "rm label" || command == "remove label") emit signalRemoveLabel();
//pokud chci zobrazit nastaveni
else if (command == "o" || command == "options") emit signalShowSettingsDialog();
//pokud chceme aplikaci ukoncit
else if (command == "wq" || command == "q" || command == "quit") qApp->quit();
//pokud chceme aplikaci minimalizovat
else if (command == "mi" || command == "minimize") this->showMinimized();
//pokud chceme oznacit polozky jako prectene
else if (command == "m" || command == "mark") this->markAsRead();
else if (command == "m all" || command == "mark all") this->markAllAsRead();
//pokud chceme prejit na dalsi polozku
else if (command == "n" || command == "next") emit signalReadNextEntry();
//pokud chceme prejit na nasledujici zdroj
else if (command == "nf") emit signalReadNextFeed();
//pokud chceme zobrazit ci skyt menu
else if (command == "tm") emit signalShowHideMenu();
//pokud chceme prejit na nasledujici stitek
else if (command == "nl") emit signalReadNextLabel();
//pokud chceme prejit na prechozi polozku
else if (command == "p" || command == "prev") emit signalReadPreviousEntry();
//pokud chceme prejit na predchozi zdroj
else if (command == "pf") emit signalReadPreviousFeed();
//pokud chceme prejit na predchozi stitek
else if (command == "pl") emit signalReadPreviousLabel();
//zobrazi/skryje nastrojovou listu
else if (command == "tt") emit signalShowHideToolbar();
//pokud chci nastavit nejakou polozku
else if (command.left(3) == "set") {
//pokud chceme nastavit cas automaticke aktualizace zdroju
if (command.mid(4,4) == "time")
_checkFeedTime = command.mid(9).toInt();
//pokud chceme nastavit viditelnost listy nastroju
else if (command.mid(4,7) == "toolbar") {
if (command.right(2) == "on")
ui->toolBar->show();
if (command.right(3) == "off")
ui->toolBar->hide();
}
//pokud chceme nastavit viditelnost menu
else if (command.mid(4,4) == "menu") {
if (command.right(2) == "on")
ui->menubar->show();
if (command.right(3) == "off")
ui->menubar->hide();
}
else if (command.mid(4,7) == "summary") {
if (command.right(2) == "on")
_showSummary = true;
if (command.right(3) == "off")
_showSummary = false;
}
else if (command.mid(4,5) == "flash") {
if (command.right(2) == "on") {
this->setFlash(true);
ui->browser->reload();
_flashEnabled = true;
this->setStatusBarMessage("Flash is enabled");
}
if (command.right(3) == "off") {
this->setFlash(false);
ui->browser->reload();
_flashEnabled = false;
this->setStatusBarMessage("Flash is disabled");
}
}
else if (command.mid(4,8) == "show all") {
if (command.right(2) == "on") {
_showAllFeeds = true;
ui->feedTreeWidget->topLevelItem(0)->setHidden(false);
}
if (command.right(3) == "off") {
_showAllFeeds = false;
ui->feedTreeWidget->topLevelItem(0)->setHidden(true);
}
}
else if (command.mid(4,11) == "show labels") {
if (command.right(2) == "on")
_showLabels = true;
if (command.right(3) == "off")
_showLabels = false;
toggleLabelsVisibility(_showLabels);
}
//pokud chceme nastavit automaticke skryvani panelu se zdroji
else if (command.mid(4,8) == "autohide") {
if (command.right(2) == "on")
_autoHideFeedPanel = true;
if (command.right(3) == "off") {
_autoHideFeedPanel = false;
ui->frameShowFeedListButton->hide();
ui->feedTreeWidget->show();
}
}
else {
showStatusBarMessage("Unknown command: " + command);
return;
}
saveSettings();
}
else if (command.left(4) == "info") {
if (command.mid(5,4) == "time")
_commandsLine->setText(command.mid(5,4) + " " + QString::number(_checkFeedTime/60000));
else if (command.mid(5,7) == "toolbar") {
if (ui->toolBar->isHidden())
_commandsLine->setText(command.mid(5,7) + " " + "off");
else
_commandsLine->setText(command.mid(5,7) + " " + "on");
}
else if (command.mid(5,4) == "menu") {
if (ui->menubar->isHidden())
_commandsLine->setText(command.mid(5,4) + " " + "off");
else
_commandsLine->setText(command.mid(5,4) + " " + "on");
}
else if (command.mid(5,5) == "flash") {
if (_flashEnabled)
_commandsLine->setText(command.mid(5,5) + " " + "on");
else
_commandsLine->setText(command.mid(5,5) + " " + "off");
}
else if (command.mid(5,8) == "username") {
_commandsLine->setText(_settings->value("username").toString());
}
else if (command.mid(5,8) == "autohide") {
if (_autoHideFeedPanel)
_commandsLine->setText(command.mid(5,8) + " " + "on");
else
_commandsLine->setText(command.mid(5,8) + " " + "off");
}
else
showStatusBarMessage("Unknown command: " + command);
}
else if (command == "") this->setFocus();
else {
bool ok = false;
command.toInt(&ok);
if (ok) {
int index = command.toInt();
if (index < 1 || index > ui->entriesTreeWidget->topLevelItemCount()-1) {
showStatusBarMessage("Index out of range");
return;
}
ui->entriesTreeWidget->setCurrentItem(ui->entriesTreeWidget->topLevelItem(index-1));
emit signalReadNextEntry(ui->entriesTreeWidget->currentIndex());
}
else
showStatusBarMessage("Unknown command: " + command);
}
this->setFocus();
}
void GooDer::newFeedAdded() {
_feedAdded = true;
callCheckFeeds();
}
/*!
\brief Zavola metodu pro ziskani seznamu neprectenych polozek
*/
void GooDer::callCheckFeeds() {
if (!_online) {
showStatusBarMessage("Please connect to internet!");
emit signalLogin();
}
qDebug() << "fetching feeds" << "in GooDer::callCheckFeeds";
if (_googleReaderController->getFeedsDB().isEmpty())
_googleReaderController->getFeeds();
else {
_googleReaderController->getUnreadFeeds();
_timerRefreshFeeds->start();
}
}
/*!
\brief Porovna dve ruzna data publikovani
*/
bool isLess(Entry* entry1, Entry* entry2) {
return (entry1->getPublishedDate() <= entry2->getPublishedDate()) ? false : true;
}
void GooDer::setEntriesWidget() {
int width = this->width();
ui->entriesTreeWidget->setColumnWidth(0, width/1.8);
ui->entriesTreeWidget->setColumnWidth(1, width/4);
ui->entriesTreeWidget->setColumnWidth(2, width/4);
ui->entriesTreeWidget->setColumnWidth(3, width/4);
}
void GooDer::s_refreshAfterFeedDeleted() {
this->readNextEntry();
refreshFeedWidget();
}
void GooDer::s_refreshFeedWidget() {
refreshFeedWidget();
}
void GooDer::toggleLabelsVisibility(bool visibility) {
for (int i = 0; i < ui->feedTreeWidget->topLevelItemCount(); i++)
if (ui->feedTreeWidget->topLevelItem(i)->text(2) == "label")
ui->feedTreeWidget->topLevelItem(i)->setHidden(!visibility);
if (visibility)
ui->feedTreeWidget->expandAll();
}
void GooDer::refreshFeedWidget() {
ui->feedTreeWidget->clear();
bool notFound = true;
QTreeWidgetItem* treeWidgetItem = new QTreeWidgetItem((QTreeWidget*)0, QStringList(trUtf8("All feeds")));
treeWidgetItem->setText(2, "allfeeds");
ui->feedTreeWidget->addTopLevelItem(treeWidgetItem);
foreach (Feed* feed, _googleReaderController->getFeedsDB()) {
//a pridavam je do leveho sloupce se zdroji
QTreeWidgetItem *newItem = new QTreeWidgetItem;
newItem->setText(0, feed->getTitle());
newItem->setText(2, feed->getId());
treeWidgetItem->addChild(newItem);
if (feed->getLabel().isEmpty()) {
_feedAdded = false;
continue;
}
//seznam vsech stitku prirazenych zdroji
QList<QString> labelList = feed->getLabel();
foreach (QString label, labelList) {
if (label.isEmpty())
continue;
//a pokousim se najit zda je jiz v levem sloupci se zdroji uveden
QList<QTreeWidgetItem*> itemsFound = ui->feedTreeWidget->findItems(label, Qt::MatchExactly, 0);
if (itemsFound.isEmpty()) {
QTreeWidgetItem* labelItem = new QTreeWidgetItem((QTreeWidget*)0, QStringList(label));
labelItem->setText(2, "label");
ui->feedTreeWidget->addTopLevelItem(labelItem);
}
QList<QTreeWidgetItem*> labels = ui->feedTreeWidget->findItems(label, Qt::MatchExactly, 0);
for (int i = 0; i < labels.at(0)->childCount(); i++) {
if (labels.at(0)->child(i)->text(0) == feed->getTitle()) {
notFound = false;
break;
}
}
if (notFound) {
newItem = new QTreeWidgetItem;
newItem->setText(0, feed->getTitle());
newItem->setText(2, feed->getId());
labels.at(0)->addChild(newItem);
}
notFound = true;
}
_feedAdded = false;
}
toggleLabelsVisibility(_showLabels);
differentiateFeedsLines();
checkEntriesFeedsNumbers();
//rozbali vsechny polozky
ui->feedTreeWidget->expandAll();
//prizpusobim velikost bunek obsahu
ui->feedTreeWidget->resizeColumnToContents(0);
ui->feedTreeWidget->resizeColumnToContents(1);
ui->feedTreeWidget->setWordWrap(true);
setFeedListWidth();
ui->entriesTreeWidget->setRootIsDecorated(false);
}
/*!
\brief Po spusteni programu, pokud neni zvolen zadny zdroj, zobrazim vsechy polozky serazene podle data
*/
void GooDer::getEntriesReady() {
if (_fetchingEntriesFromHistory) {
getEntriesFromFeed(_fetchingEntriesFromHistoryActivated);
return;
}
this->showNotification();
ui->statusbar->clearMessage();
if (_firstRun || _feedAdded)
refreshFeedWidget();
if (!_firstRun) {
checkEntriesFeedsNumbers();
if (ui->feedTreeWidget->currentItem() == NULL)
return;
QString feedId = ui->feedTreeWidget->currentItem()->text(2);
if (feedId == "allfeeds" || feedId == "label")
return;
ui->entriesTreeWidget->clear();
addFeedEntriesToEntriesList(_googleReaderController->getFeedDB(feedId));
}
else {
ui->entriesTreeWidget->clear();
//a vypisi jej do praveho sloupce s polozkami
foreach (Feed* feed, _googleReaderController->getFeedsDB())
addFeedEntriesToEntriesList(feed);
if (!_showAllFeeds)
ui->feedTreeWidget->topLevelItem(0)->setHidden(true);
_firstRun = false;
}
differentiateEntriesLines();
}
/*!
\brief Zobrazi pole pro zadavani prikazu
*/
void GooDer::showCommandLine() {
_commandsLine->setText(":");
_commandsLine->setFocus();
}
/*!
\brief Zobrazi pole pro zadavani prikazu
*/
void GooDer::hideCommandLine() {
_commandsLine->clear();
this->setFocus();
}
/*!
\brief Zobrazi pole pro vyhledavani
*/
void GooDer::showSearchLine() {
_commandsLine->setText("/");
_commandsLine->setFocus();
}
/*!
\brief Zobrazi dialog s nastavenim
*/
void GooDer::showSettingsDialog() {
_settingsDialogInstance = new SettingsDialog(this);
connect(_settingsDialogInstance, SIGNAL(settingsData()),
this, SLOT(showSettingsDialogSuccess()));
_settingsDialogInstance->exec();
}
void GooDer::showSettingsDialogSuccess() {
loadSettings();
}
/*!
\brief Vola funkci pro prihlaseni programu
*/
void GooDer::login() {
_googleReaderController->login(_settings->value("username").toString(),
_crypt->decryptToString(_settings->value("password").toString()));
}
/*!
\brief Nastavi ikonu programu a ikonu v systemove liste
*/
void GooDer::setIcon() {
QIcon icon = QIcon(":/icons/icons/GooDer.svgz");
_trayIcon->setIcon(icon);
GooDer::setWindowIcon(icon);
}
void GooDer::trayMarkAllAsRead() {
this->markAllAsRead();
}
/*!
\brief Vytvori ikonu v systemove liste
*/
void GooDer::createTray() {
_trayIcon = new QSystemTrayIcon(this);
_trayMenu = new QMenu(this);
QAction* trayCheckFeeds = new QAction(trUtf8("Check feeds"), this);
connect(trayCheckFeeds, SIGNAL(triggered()),
this, SLOT(callCheckFeeds()));
_trayMenu->addAction(trayCheckFeeds);
_trayMenu->addSeparator();
QAction* trayMarkAllAsRead = new QAction(trUtf8("Mark all as read"), this);
connect(trayMarkAllAsRead, SIGNAL(triggered()),
this, SLOT(trayMarkAllAsRead()));
_trayMenu->addAction(trayMarkAllAsRead);
_trayMenu->addSeparator();
QAction* trayExit = new QAction(trUtf8("Quit"), this);
connect(trayExit, SIGNAL(triggered()),
this, SLOT(close()));
_trayMenu->addAction(trayExit);
_trayIcon->setContextMenu(_trayMenu);
connect(_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason)));
}
/*!
\brief Zobrazi dialog O aplikaci
*/
void GooDer::showAbout() {
QMessageBox::information(0, trUtf8("About GooDer"), trUtf8("Based on my bachelors thesis. Author: Tomas Popela, [email protected]"));
}
/*!
\brief Zobrazi dialog O aplikaci
*/
void GooDer::showHelp() {
ui->browser->load(QUrl("qrc:/help/help.html"));
}
void GooDer::connectSignalsUI() {
//pokud chceme zobrazit napovedu
connect(ui->actionHelp, SIGNAL(triggered()),
this, SLOT(showHelp()));
//pokud chceme zobrazit okno O aplikaci
connect(ui->actionAbout, SIGNAL(triggered()),
this, SLOT(showAbout()));
//pokud je v menu zvolena moznost pridat zdroj
connect(ui->actionAddFeed, SIGNAL(triggered()),
this, SLOT(showAddFeedDialog()));
//pokud je zvolena moznost ukoncit program
connect(ui->actionQuit, SIGNAL(triggered()),
this, SLOT(close()));
//pokud je zvolena moznost aktualizovat zdroje
connect(ui->actionCheckFeeds, SIGNAL(triggered()),
this, SLOT(callCheckFeeds()));
//pokud je zvolena moznost oznacit vsechny polozky jako prectene
connect(ui->actionMarkedAllAsRead, SIGNAL(triggered()),
this, SLOT(markAsRead()));
//pokud je zvolena moznost odstranit zdroj
connect(ui->actionRemoveFeed, SIGNAL(triggered()),
this, SLOT(showRemoveFeedDialog()));
//pokud je zvolena moznost zobrazit nastaven*/i
connect(ui->actionSettings, SIGNAL(triggered()),
this, SLOT(showSettingsDialog()));
//pokud je stisknuto tlacitko pro zobrazeni seznamu zdroju
connect(ui->showFeedList, SIGNAL(clicked()),
this, SLOT(showFeedTreeWidget()));
//zobrazi seznam polozek po jednom kliknuti (Mac, Win)
connect(ui->feedTreeWidget, SIGNAL(clicked(QModelIndex)),
this, SLOT(showEntriesOnSelectedFeed(QModelIndex)));
//zobrazi polozku po jednom kliknuti (Mac, Win)
connect(ui->entriesTreeWidget, SIGNAL(clicked(QModelIndex)),
this, SLOT(showSelectedEntry(QModelIndex)));
connect(_trayIcon, SIGNAL(messageClicked()),
this, SLOT(show()));
connect(_trayIcon,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
connect(ui->browser, SIGNAL(loadProgress(int)),
this, SLOT(showLoadProgress(int)));
connect(ui->entriesTreeWidget->header(), SIGNAL(sectionClicked(int)),
this, SLOT(changeSortingUIChanges(int)));
connect(_commandsLine, SIGNAL(returnPressed()),
this, SLOT(parseCommands()));
}
void GooDer::connectSignalsControl() {
//zobrazi zpravu v informacni liste
connect(this, SIGNAL(setStatusBarMessage(QString)),
this, SLOT(showStatusBarMessage(QString)));
//zkontroluje zdroje
connect(this, SIGNAL(checkFeeds()),
this, SLOT(callCheckFeeds()));
//volani pro zobrazeni polozky v externim prohlizeci
connect(this->_actionOpenInExternBrowser, SIGNAL(triggered()),
this, SLOT(openEntryInExternalBrowser()));
//prechod na nasledujici polozku
connect(this, SIGNAL(signalReadNextEntry(QModelIndex)),
this, SLOT(showSelectedEntry(QModelIndex)));
//prechod na predchozi polozku
connect(this, SIGNAL(signalReadPreviousEntry(QModelIndex)),
this, SLOT(showSelectedEntry(QModelIndex)));
//prechod na nasledujici polozku
connect(this, SIGNAL(signalReadNextEntry()),
this, SLOT(readNextEntry()));
//prechod na predchozi polozku
connect(this, SIGNAL(signalReadPreviousEntry()),
this, SLOT(readPreviousEntry()));
//prechod na nasledujici zdroj
connect(this, SIGNAL(signalReadNextFeed(QModelIndex)),
this, SLOT(showEntriesOnSelectedFeed(QModelIndex)));
//prechod na predchozi zdroj
connect(this, SIGNAL(signalReadPreviousFeed(QModelIndex)),
this, SLOT(showEntriesOnSelectedFeed(QModelIndex)));
//prechod na nasledujici zdroj
connect(this, SIGNAL(signalReadNextFeed()),
this, SLOT(readNextFeed()));
//prechod na predchozi zdroj
connect(this, SIGNAL(signalReadPreviousFeed()),
this, SLOT(readPreviousFeed()));
//prechod na nasledujici stitek
connect(this, SIGNAL(signalReadNextLabel()),
this, SLOT(readNextLabel()));
//prechod na predchozi stitek
connect(this, SIGNAL(signalReadPreviousLabel()),
this, SLOT(readPreviousLabel()));
//zobrazi/skryje nastrojovou listu
connect(this, SIGNAL(signalShowHideToolbar()),
this, SLOT(showHideToolbar()));
//pokud je stisknuto tlacitko pro zobrazeni nastaveni
connect(this, SIGNAL(signalShowSettingsDialog()),
this, SLOT(showSettingsDialog()));
//volani prihlaseni
connect(this, SIGNAL(signalLogin()),
this, SLOT(login()));
//pokud je zvolena moznost vytvorit novou slozku
connect(this->_actionCreateNewLabel, SIGNAL(triggered()),
this, SLOT(showCreateNewLabelDialog()));
//pokud je zvolena moznost odebrani stitku
connect(this->_actionRemoveLabel, SIGNAL(triggered()),
this, SLOT(removeLabel()));
//pokud je zvolena moznost odebrani stitku
connect(this->_actionRemoveFeed, SIGNAL(triggered()),
this, SLOT(removeFeed()));
//zobrazi dialog pro pridani noveho zdroje
connect(this, SIGNAL(signalShowAddFeedDialog()),
this, SLOT(showAddFeedDialog()));
//zobrazi dialog pro odebrani zdroje
connect(this, SIGNAL(signalShowRemoveFeedDialog()),
this, SLOT(showRemoveFeedDialog()));
//pokud chci pridat novy zdroj
connect(this, SIGNAL(signalAddFeed(QString, QString, QString)),
this, SLOT(addNewFeed(QString,QString, QString)));
//pokud chceme zobrazit/skryt menu
connect(this, SIGNAL(signalShowHideMenu()),
this, SLOT(showHideMenu()));
//pokud chceme odebrat stitek
connect(this, SIGNAL(signalRemoveLabel()),
this, SLOT(removeLabel()));
//pokud chceme pridat stitek
connect(this, SIGNAL(signalAddLabel(QString)),
this, SLOT(createNewLabel(QString)));
}
void GooDer::connectSignalsAccount() {
connect(_googleReaderController, SIGNAL(signalLoginStatus(bool)),
this, SLOT(loginSuccessfull(bool)));
}
void GooDer::connectSignalsNetwork() {
connect(_googleReaderController, SIGNAL(signalStatusLogin(bool)),
this, SLOT(statusLogin(bool)));
connect(_googleReaderController, SIGNAL(signalStatusMarkEntryAsRead(bool)),
this, SLOT(statusMarkEntryAsRead(bool)));
connect(_googleReaderController, SIGNAL(signalStatusMarkFeedAsRead(bool)),
this, SLOT(statusMarkFeedAsRead(bool)));
connect(_googleReaderController, SIGNAL(signalStatusAddFeedLabel(bool)),
this, SLOT(statusAddFeedLabel(bool)));
connect(_googleReaderController, SIGNAL(signalStatusRemoveFeedLabel(bool)),
this, SLOT(statusRemoveFeedLabel(bool)));
connect(_googleReaderController, SIGNAL(signalStatusAddFeed(bool)),
this, SLOT(statusAddFeedLabel(bool)));
connect(_googleReaderController, SIGNAL(signalStatusRemoveFeed(bool)),
this, SLOT(statusRemoveFeedLabel(bool)));
connect(_googleReaderController, SIGNAL(signalStatusGetEntries(bool)),
this, SLOT(statusGetEntries(bool)));