-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathmain.qml
1339 lines (1256 loc) · 60.8 KB
/
main.qml
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
import QtQuick 2.12
import QtQuick.Controls 2.5
import QtQuick.Window 2.2
import QtQuick.Controls.Universal 2.12
import QtQuick.Controls.Styles 1.4
import QtGraphicalEffects 1.12
import AndroidNative 1.0 as AN
import Qt.labs.settings 1.0
import QtQml 2.12
import FileIO 1.0
ApplicationWindow {
id: appWindow
visible: true
title: qsTr("Volla")
property ApplicationWindow mainWindow : appWindow
property bool isActive: false
onClosing: close.accepted = false
Connections {
target: Qt.application
// @disable-check M16
onStateChanged: {
if (Qt.application.state === Qt.ApplicationActive) {
if (isActive) return
isActive = true
// Application go in active state
console.log("MainView | Application became active")
if (Qt.fontFamilies().indexOf("Noto Sans") > -1) {
console.debug("APP: Use smaller font size")
mainView.headerFontSize = 34.0
mainView.largeFontSize = 18.0
mainView.mediumFontSize = 16.0
mainView.smallFontSize = 14.0
}
settings.sync()
if (!appGridLoader.active) appGridLoader.active = true
if (!springboardLoader.active) springboardLoader.active = true
if (!settingsPageLoader.active) settingsPageLoader.active = true
if (mainView.keepLastIndex) {
if (mainView.currentIndex === mainView.swipeIndex.ConversationOrNewsOrDetails) {
console.log("MainView | Switch to conversation page")
mainView.currentIndex = mainView.swipeIndex.ConversationOrNewsOrDetails
}
mainView.keepLastIndex = false
} else {
if (settings.showAppsAtStartup && mainView.currentIndex === mainView.swipeIndex.Apps)
appGrid.children[0].item.updateNotifications()
mainView.currentIndex = settings.showAppsAtStartup ? mainView.swipeIndex.Apps : mainView.swipeIndex.Springboard
}
// Check runnung apps
if (mainView.isTablet) AN.SystemDispatcher.dispatch("volla.launcher.runningAppsAction", {})
// Start onboarding for the first start of the app
console.log("MainView | First start: " + settings.firstStart)
// Check new pinned shortcut
AN.SystemDispatcher.dispatch("volla.launcher.checkNewShortcut", {})
// Update app grid
AN.SystemDispatcher.dispatch("volla.launcher.appCountAction", {})
// Load wallpaper
AN.SystemDispatcher.dispatch("volla.launcher.wallpaperAction", {"wallpaperId": mainView.wallpaperId})
// Load contacts
AN.SystemDispatcher.dispatch("volla.launcher.checkContactAction", {"timestamp": settings.lastContactsCheck})
} else if (Qt.application.state === Qt.ApplicationInactive) {
// Application go in suspend state
console.log("MainView | Application became inactive")
isActive = false
appGridLoader.active = false
springboardLoader.active = false
settingsPageLoader.active = false
}
}
}
SwipeView {
id: mainView
anchors.fill: parent
currentIndex: 2
interactive: true
background: Item {
id: background
anchors.fill: parent
Image {
id: backgroundImage
anchors.fill: parent
fillMode: Image.PreserveAspectCrop
source: mainView.wallpaper
}
FastBlur {
id: fastBlur
anchors.fill: backgroundImage
source: backgroundImage
radius: settings.blurEffect
}
Rectangle {
anchors.fill: parent
color: Universal.background
opacity: mainView.backgroundOpacity
Behavior on opacity {
NumberAnimation {
duration: 300
}
}
}
}
property real outerSpacing: Screen.desktopAvailableWidth > 520 ? 100 : 0
property real innerSpacing : Screen.desktopAvailableWidth > 520 ? 22 : 22 // 22.0
property real componentSpacing: Screen.desktopAvailableWidth > 520 ? 32 : 22
property real headerFontSize: 36.0
property real largeFontSize: 20.0
property real mediumFontSize: 18.0
property real smallFontSize: 16.0
property var collectionMode : {
'People' : 0,
'Threads' : 1,
'News' : 2,
'Notes' : 3
}
property var conversationMode: {
'Person' : 0,
'Thread' : 1
}
property var feedMode: {
'RSS' : 0,
'Atom' : 1,
'Twitter': 2
}
property var detailMode: {
'Web' : 0,
'Twitter' : 1,
'MMS' : 2,
'Mail' : 3,
'Note' : 4
}
property var searchMode: {
'Duck' : 0,
'StartPage' : 1,
'MetaGer' : 2
}
property var theme: {
'Light': 0,
'Dark': 1,
'Translucent': 2
}
property var actionType: {
'SuggestContact': 0,
'SuggestPluginEntity' : 1,
'MakeCall': 20000,
'SendEmail': 20001,
'SendSMS': 20002,
'OpenURL': 20003,
'SearchWeb': 20004,
'CreateNote': 20005,
'ShowGroup': 20006,
'ShowDetails': 20007,
'ShowGallery': 20008,
'ShowContacts': 20009,
'ShowCalendar' : 20010,
'ShowThreads': 20011,
'ShowNews': 20012,
'OpenCam': 20013,
'ShowNotes': 20014,
'ShowDialer': 20015,
'CreateEvent': 20016,
'AddFeed': 20017,
'MakeCallToMobile': 20018,
'MakeCallToWork': 20019,
'MakeCallToHome': 20020,
'MakeCallToOther': 20021,
'SendEmailToHome': 20022,
'SendEmailToWork': 20023,
'SendEmailToOther': 20024,
'OpenContact' : 20025,
'OpenApp' : 20026,
'SendSignal' : 20027,
'OpenSignalContact' : 20028,
'ExecutePlugin': 20029,
'LiveContentPlugin': 20030
}
property var actionName: {"SendSMS": qsTr("Send message"), "SendEmail": qsTr("Send email"),
"SendEmailToHome": qsTr("Send home email"), "SendEmailToWork": qsTr("Send work email"),
"SendEmailToOther": qsTr("Send other email"), "MakeCall": qsTr("Call"),
"MakeCallToMobile": qsTr("Call on cell phone"), "MakeCallToHome": qsTr("Call at home"),
"MakeCallToWork": qsTr("Call at work"), "MakeCallToOther": qsTr("Call other phone"),
"CreateNote": qsTr("Create note"), "SearchWeb": qsTr("Search web"),
"OpenURL": qsTr("Open in browser"), "AddFeed": qsTr("Add feed to collection"),
"OpenContact" : qsTr("Open Contact"), "ShowNotes": qsTr("Show Notes"), "SendSignal" : qsTr("Send Signal message"),
"CreateEvent" : qsTr("Add to Calender"), "OpenSignalContact": qsTr("Show in Signal")
}
property var swipeIndex: {
'Preferences' : 0,
'Apps' : 1,
'Springboard' : 2,
'Collections' : 3,
'ConversationOrNewsOrDetails' : 4,
'Details' : 5
}
property var settingsAction: {
'CREATE': 0,
'UPDATE': 1,
'REMOVE': 2
}
property var notifications: { "MissingText": qsTr("Missing message text"),
"MessageSent": qsTr("Message sent"),
"GenericFailure": qsTr("Generic failure"),
"NoService": qsTr("No service"),
"NullPdu": qsTr("Null PDU"),
"RadioOff": qsTr("Radio off"),
"MessageDelivered": qsTr("Message delivered"),
"MessageNotDelivered": qsTr("Message not delivered")}
property var contacts: new Array
property var notes: new Array
property var loadingContacts: new Array
property bool isLoadingContacts: false
property var wallpaper: ""
property var wallpaperId: ""
property var backgroundOpacity: 1.0
property var backgroundColor: Universal.background
property var accentColor: Universal.accent
property var fontColor: Universal.foreground
property var vibrationDuration: 50
property bool useVibration: settings.useHapticMenus
property bool useColoredIcons: settings.useColoredIcons
property string city: settings.city
property double longitude: settings.longitude
property double latitude: settings.latitude
property bool isTablet: Screen.desktopAvailableWidth > 520
property int maxTitleLength: 120
property string galleryApp: "org.fossify.gallery"
property string calendarApp: "org.fossify.calendar"
property string cameraApp: "com.mediatek.camera"
property string phoneApp: "com.android.dialer"
property string notesApp: "org.fossify.notes"
property var messageApp: ["com.android.mms", "org.fossify.messages", "com.android.messaging"];
property var iconMap: {
"com.simplemobiletools.dialer": "/icons/[email protected]",
"com.simplemobiletools.smsmessenger": "/icons/[email protected]",
"com.simplemobiletools.gallery.pro": "/icons/[email protected]",
"com.simplemobiletools.contacts.pro": "/icons/[email protected]",
"com.simplemobiletools.clock": "/icons/[email protected]",
"com.simplemobiletools.calendar.pro": "/icons/[email protected]",
"com.simplemobiletools.filemanager.pro": "/icons/[email protected]",
"com.simplemobiletools.notes.pro": "/icons/[email protected]",
"com.simplemobiletools.calculator": "/icons/calculator@4x_104x104px.png",
"org.fossify.phone": "/icons/[email protected]",
"org.fossify.smsmessenger": "/icons/[email protected]",
"org.fossify.gallery": "/icons/[email protected]",
"org.fossify.contacts": "/icons/[email protected]",
"org.fossify.clock": "/icons/[email protected]",
"org.fossify.calendar": "/icons/[email protected]",
"org.fossify.filemanager": "/icons/[email protected]",
"org.fossify.notes": "/icons/[email protected]",
"org.fossify.calculator": "/icons/calculator@4x_104x104px.png",
"org.fossify.musicplayer": "/icons/[email protected]",
"com.volla.messages": "/icons/[email protected]",
"com.contactoffice.mailfence": "/icons/[email protected]",
"com.emclient.mailclient": "/icons/[email protected]",
"net.thunderbird.android": "/icons/[email protected]",
"be.engie.smart": "/icons/[email protected]",
"be.bmid.itsme": "/icons/[email protected]",
"com.facebook.lite": "/icons/[email protected]",
"nl.apcreation.woolsocks": "/icons/[email protected]",
"com.zhiliaoapp.musically": "/icons/[email protected]",
"com.proximus.proximusplus": "/icons/[email protected]",
"mobi.inthepocket.bcmc.bancontact": "/icons/[email protected]",
"com.symantec.mobilesecurity": "/icons/[email protected]",
"be.nexuzhealth.mobile.mynexuz": "/icons/[email protected]",
"com.bookmark.money": "/icons/[email protected]",
"be.bpost.mybpost": "/icons/[email protected]",
"be.ixor.doccle.android": "/icons/[email protected]",
"com.themobilecompany.delijn": "/icons/[email protected]",
"com.x8bit.bitwarden": "/icons/[email protected]",
"com.beeper.android": "/icons/[email protected]",
"be.argenta.bankieren": "/icons/[email protected]",
"com.android.dialer": "/icons/[email protected]",
"com.android.mms" : "/icons/[email protected]",
"com.android.messaging": "/icons/[email protected]",
"com.google.android.apps.messaging" : "/icons/[email protected]",
"net.osmand.plus": "/icons/[email protected]",
"com.mediatek.camera": "/icons/[email protected]",
"com.android.camera2": "/icons/[email protected]",
"com.android.gallery3d": "/icons/[email protected]",
"com.android.deskclock": "/icons/[email protected]",
"com.android.settings": "/icons/[email protected]",
"com.android.documentsui": "/icons/[email protected]",
"org.telegram.messenger": "/icons/[email protected]",
"com.android.email": "/icons/[email protected]",
"com.fsck.k9": "/icons/[email protected]",
"com.google.android.gm": "/icons/[email protected]",
"com.Slack": "/icons/[email protected]",
"org.mozilla.fennec_fdroid": "/icons/[email protected]",
"com.maxfour.music": "/icons/[email protected]",
"com.instagram.android": "/icons/[email protected]",
"com.github.yeriomin.yalpstore": "/icons/[email protected]",
"com.aurora.store": "/icons/[email protected]",
"com.amazon.mShop.android.shopping": "/icons/[email protected]",
"de.hafas.android.db": "/icons/[email protected]",
"com.dropbox.android": "/icons/[email protected]",
"org.fdroid.fdroid": "/icons/[email protected]",
"com.facebook.katana": "/icons/[email protected]",
"de.gmx.mobile.android.mail": "/icons/[email protected]",
"hideme.android.vpn.noPlayStore": "/icons/[email protected]",
"com.linkedin.android": "/icons/[email protected]",
"com.nextcloud.client": "/icons/[email protected]",
"com.paypal.android.p2pmobile": "/icons/[email protected]",
"com.skype.raider": "/icons/[email protected]",
"com.spotify.music": "/icons/[email protected]",
"de.tutao.tutanota": "/icons/[email protected]",
"com.volla.launcher": "/icons/[email protected]",
"de.web.mobile.android.mail": "/icons/[email protected]",
"com.wetter.androidclient": "/icons/[email protected]",
"com.whatsapp": "/icons/[email protected]",
"com.android.fmradio": "/icons/radio@4x_104x104px.png",
"at.bitfire.davdroid": "/icons/sync@4x_104x104px.png",
"org.thoughtcrime.securesms": "/icons/signal@4x_104x104px.png",
"de.baumann.weather": "/icons/weather@4x_104x104px.png",
"com.android.calculator2": "/icons/calculator@4x_104x104px.png",
"eu.siacs.conversations": "/icons/xmpp@4x_104x104px.png",
"one.socializer.android": "/icons/[email protected]",
"im.status.ethereum": "/icons/[email protected]",
"org.liberty.android.freeotpplus": "/icons/[email protected]",
"com.kickstarter.kickstarter": "/icons/[email protected]",
"com.ebay.kleinanzeigen": "/icons/[email protected]",
"com.secuso.privacyFriendlyCodeScanner": "/icons/[email protected]",
"com.twitter.android": "/icons/[email protected]",
"com.commerzbank.photoTAN": "/icons/[email protected]",
"com.volla.messages": "/icons/[email protected]"
}
property var labelMap: {
"com.simplemobiletools.filemanager.pro": qsTr("Files"),
"com.simplemobiletools.smsmessenger": qsTr("Messages"),
"org.fossify.filemanager": qsTr("Files"),
"org.fossify.smsmessenger": qsTr("Messages"),
"org.fossify.musicplayer": qsTr("Music"),
"mobi.inthepocket.bcmc.bancontact": qsTr("Bancontact"),
"be.sncbnmbs.b2cmobapp": qsTr("De Trein"),
"be.nexuzhealth.mobile.mynexuz": qsTr("Mynexuzhealth"),
"com.codesynd.cashfree": qsTr("Bonsai"),
"be.introlution.myonlinecalendar": qsTr("MijnOnlineAgenda"),
"com.facebook.lite": qsTr("Facebook"),
"org.mozilla.fennec_fdroid": qsTr("Browser"),
"com.google.android.gm" : qsTr("Mail"),
"eu.faircode.email" : qsTr("Mail"),
"com.emclient.mailclient" : qsTr("Mail"),
"net.thunderbird.android" : qsTr("Mail"),
"com.fsck.k9": qsTr("Mail"),
"at.bitfire.davdroid": qsTr("Sync"),
"hideme.android.vpn.noPlayStore": qsTr("VPN"),
"com.aurora.store": qsTr("Store"),
"com.aurora.adroid": qsTr("A-Droid"),
"net.osmand.plus": qsTr("Maps"),
"com.volla.launcher": qsTr("Settings"),
"com.android.fmradio" : qsTr("Radio"),
"de.baumann.weather": qsTr("Weather")
}
property string cacheName: "VollaCacheDB"
property string cacheDescription: "Messages cache"
property real cacheVersion: 1.0
property int cacheSize: 1000
property var defaultFeeds: [{"id" : "https://www.nzz.ch/recent.rss", "name" : "NZZ", "activated" : true, "icon": "https://assets.static-nzz.ch/nzz/app/static/favicon/favicon-128.png?v=3"},
{"id" : "https://www.chip.de/rss/rss_topnews.xml", "name": "Chip Online", "activated" : true, "icon": "https://www.chip.de/fec/assets/favicon/apple-touch-icon.png?v=01"},
{"id" : "https://www.theguardian.com/world/rss", "name": "The Guardian", "activated" : true, "icon": "https://assets.guim.co.uk/images/favicons/6a2aa0ea5b4b6183e92d0eac49e2f58b/57x57.png"}]
property var defaultActions: [{"id" : actionType.ShowDialer, "name" : qsTr("Show Dialer"), "activated" : true},
{"id" : actionType.OpenCam, "name": qsTr("Camera"), "activated" : true},
{"id" : actionType.ShowGallery, "name": qsTr("Gallery"), "activated" : true},
{"id" : actionType.ShowCalendar, "name": qsTr("Agenda"), "activated" : true},
{"id" : actionType.CreateEvent, "name": qsTr("Create Event"), "activated" : false},
{"id" : actionType.ShowNotes, "name": qsTr("Show Notes"), "activated" : true},
{"id" : actionType.ShowNews, "name": qsTr("Recent News"), "activated" : true},
{"id" : actionType.ShowThreads, "name": qsTr("Recent Threads"), "activated" : true},
{"id" : actionType.ShowContacts, "name": qsTr("Recent People"), "activated" : true}]
property var timeStamp: 0
property var lastCheckOfThreads: 0
property var lastCheckOfCalls: 0
property var redirectCount: 0
property var maxRedirectCount: 1
property bool keepLastIndex: false
onCurrentIndexChanged: {
console.debug("MainView | Index changed to " + currentIndex)
switch (currentIndex) {
case swipeIndex.Apps:
appGrid.children[0].item.updateNotifications()
break
case swipeIndex.Preferences:
settingsPage.children[0].item.updateAvailablePlugins()
AN.SystemDispatcher.dispatch("volla.launcher.securityStateAction", {})
break
default:
// Nothing to do
}
}
onBackgroundOpacityChanged: {
updateGridView("backgroundOpacity", backgroundOpacity)
}
Item {
id: settingsPage
Loader {
id: settingsPageLoader
anchors.fill: parent
sourceComponent: Qt.createComponent("/Settings.qml", mainView)
}
}
Item {
id: appGrid
Loader {
id: appGridLoader
anchors.fill: parent
sourceComponent: Qt.createComponent("/AppGrid.qml", mainView)
}
}
Item {
id: springboard
Loader {
id: springboardLoader
anchors.fill: parent
sourceComponent: Qt.createComponent("/Springboard.qml", mainView)
}
}
function updateSpringboard(text, selectedObj) {
console.log("MainView | Uodate springboar with text '" + text + "'")
currentIndex = swipeIndex.Springboard
var item = itemAt(swipeIndex.Springboard)
if (selectedObj !== undefined) {
item.children[0].item.selectedObj = selectedObj
}
item.children[0].item.textInputArea.text = text
}
function updateShortcutMenuState(opened) {
console.log("MainView | Update shortcut menu state: '" + opened + "'")
currentIndex = swipeIndex.Springboard
var item = itemAt(swipeIndex.Springboard)
item.children[0].item.updateShortcutMenuState(opened)
}
function updateCollectionPage(mode) {
console.log("MainView | New collection mode: " + mode)
if (count === swipeIndex.Springboard + 1) {
var item = Qt.createQmlObject('import QtQuick 2.12; Item {Loader {anchors.fill: parent}}', mainView, "dynamicQml")
item.children[0].sourceComponent = Qt.createComponent("/Collections.qml", mainView)
addItem(item)
} else {
while (count > swipeIndex.Collections + 1) {
removeItem(swipeIndex.Collections + 1)
}
item = itemAt(swipeIndex.Collections)
}
currentIndex = swipeIndex.Collections
item.children[0].item.updateCollectionPage(mode)
}
function updateConversationPage(mode, id, name) {
console.log("MainView | Will update conversation page")
if (count === swipeIndex.Collections + 1) {
var item = Qt.createQmlObject('import QtQuick 2.12; Item {Loader {anchors.fill: parent}}', mainView, "dynamicQml")
addItem(item)
} else {
while (count > swipeIndex.ConversationOrNewsOrDetails + 1) {
removeItem(swipeIndex.ConversationOrNewsOrDetails + 1)
}
item = itemAt(swipeIndex.ConversationOrNewsOrDetails)
}
item.children[0].sourceComponent = Qt.createComponent("/Conversation.qml", mainView)
currentIndex++
updateSpinner(true)
item.children[0].item.updateConversationPage(mode, id, name)
}
function updateDetailPage(mode, id, author, date, title, hasBadge) {
console.log("MainView | Will update detail page")
switch (currentIndex) {
case swipeIndex.Collections:
console.log("MainView | Current page is a collection")
if (count > swipeIndex.Collections + 1) {
var item = itemAt(swipeIndex.ConversationOrNewsOrDetails)
if (item.children[0].item.objectName !== "detailPage") {
console.log("MainView | Create detail page")
item.children[0].sourceComponent = Qt.createComponent("/Details.qml", mainView)
while (count > swipeIndex.ConversationOrNewsOrDetails + 1) {
removeItem(swipeIndex.ConversationOrNewsOrDetails + 1)
}
} else {
console.log("MainView | Re-use existing detail page")
}
} else {
item = Qt.createQmlObject('import QtQuick 2.12; Item {Loader {anchors.fill: parent}}', mainView, "dynamicQml")
item.children[0].sourceComponent = Qt.createComponent("/Details.qml", mainView)
addItem(item)
}
break
case swipeIndex.ConversationOrNewsOrDetails:
console.log("MainView | Current page is a news or detail view")
if (count > swipeIndex.ConversationOrNewsOrDetails + 1) {
item = itemAt(swipeIndex.Details)
if (item.children[0].item.objectName !== "detailPage") {
console.log("MainView | Create detail page")
item.children[0].sourceComponent = Qt.createComponent("/Details.qml", mainView)
while (count > swipeIndex.Details + 1) {
removeItem(swipeIndex.Details + 1)
}
} else {
console.log("MainView | Re-use existing detail page")
}
} else {
item = Qt.createQmlObject('import QtQuick 2.12; Item {Loader {anchors.fill: parent}}', mainView, "dynamicQml")
item.children[0].sourceComponent = Qt.createComponent("/Details.qml", mainView)
addItem(item)
}
break
default:
console.log("MainView | Unexpected state for detail view request")
}
currentIndex++
item.children[0].item.updateDetailPage(mode, id, author, date, title, hasBadge)
}
function updateNewsPage(mode, id, name, icon) {
console.log("MainView | Will update news page")
if (count === swipeIndex.Collections + 1) {
var item = Qt.createQmlObject('import QtQuick 2.12; Item {Loader {anchors.fill: parent}}', mainView, "dynamicQml")
addItem(item)
} else {
while (count > swipeIndex.ConversationOrNewsOrDetails + 1) {
removeItem(swipeIndex.ConversationOrNewsOrDetails + 1)
}
item = itemAt(swipeIndex.ConversationOrNewsOrDetails)
}
item.children[0].sourceComponent = Qt.createComponent("/Feed.qml", mainView)
currentIndex++
item.children[0].item.updateFeedPage(mode, id, name, icon)
}
function showToast(message) {
toast.text = message
toast.show()
}
function switchTheme(theme, updateLockScreen) {
if (settings.sync) {
settings.sync()
}
console.log("MainView | Swith theme to " + theme + ", " + settings.theme)
switch (theme) {
case mainView.theme.Dark:
Universal.theme = Universal.Dark
mainView.backgroundOpacity = 1.0
mainView.backgroundColor = "black"
mainView.fontColor = "white"
break
case mainView.theme.Light:
Universal.theme = Universal.Light
mainView.backgroundOpacity = 1.0
mainView.backgroundColor = "white"
mainView.fontColor = "black"
break
case mainView.theme.Translucent:
Universal.theme = Universal.Dark
mainView.backgroundOpacity = 0.3
mainView.backgroundColor = "transparent"
mainView.fontColor = "white"
break
default:
console.log("MainView | Not supported theme: " + theme)
break
}
var item = itemAt(swipeIndex.Springboard)
item.children[0].item.updateHeadlineColor()
AN.SystemDispatcher.dispatch("volla.launcher.colorAction", { "value": theme, "updateLockScreen": updateLockScreen})
}
// todo: Improve display date and time with third party library
function parseTime(timeInMillis) {
var now = new Date()
var date = new Date(timeInMillis)
var today = new Date()
today.setHours(0)
today.setMinutes(0)
today.setMilliseconds(0)
var yesterday = new Date()
yesterday.setHours(0)
yesterday.setMinutes(0)
yesterday.setMilliseconds(0)
yesterday = new Date(yesterday.valueOf() - 84000 * 1000)
var timeDelta = (now.valueOf() - timeInMillis) / 1000 / 60
if (timeDelta < 1) {
return qsTr("Just now")
} else if (timeDelta < 60) {
return Math.floor(timeDelta) + " " + qsTr("minutes ago")
} else if (date.valueOf() > today.valueOf()) {
if (date.getMinutes() < 10) {
return qsTr("Today") + " " + date.getHours() + ":0" + date.getMinutes()
} else {
return qsTr("Today") + " " + date.getHours() + ":" + date.getMinutes()
}
} else if (date.valueOf() > yesterday.valueOf()) {
if (date.getMinutes() < 10) {
return qsTr("Yesterday") + " " + date.getHours() + ":0" + date.getMinutes()
} else {
return qsTr("Yesterday") + " " + date.getHours() + ":" + date.getMinutes()
}
} else if (date.getMinutes() < 10) {
return date.toDateString() + " " + date.getHours() + ":0" + date.getMinutes()
} else {
return date.toDateString() + " " + date.getHours() + ":" + date.getMinutes()
}
}
function getContacts() {
if (mainView.contacts === undefined) {
var contactsStr = contactsCache.readPrivate()
mainView.contacts = contactsStr.length === 0 ? new Array : JSON.parse(contactsStr)
}
return mainView.contacts
}
function getApps() {
return appGrid.children[0].item.getAllApps()
}
function getFeeds() {
var channels = feeds.read()
console.log("MainView | Retrieved feeds: " + channels.lenth)
return channels.length > 0 ? JSON.parse(channels) : mainView.defaultFeeds
}
function updateFeed(channelId, isActive, sAction, newChannel) {
console.log("MainView | Will update channel: " + channelId + " with properties " + newChannel)
var channels = getFeeds()
var channel
var matched = false
var i
for (i = 0; i < channels.length; i++) {
channel = channels[i]
if (channel["id"] === channelId) {
matched = true
channel["activated"] = isActive
break
}
}
switch (sAction) {
case mainView.settingsAction.CREATE:
if (matched === false) {
channels.push(newChannel)
console.log("MainView | Did store feeds: " + feeds.write(JSON.stringify(channels)))
showToast(qsTr("New Subscrption") + ": " + newChannel.name)
} else {
showToast(qsTr("You have already subscribed the feed"))
}
break
case mainView.settingsAction.UPDATE:
if (matched === true) {
channels[i] = channel
console.log("MainView | Did store feeds: " + feeds.write(JSON.stringify(channels)))
}
break
case mainView.settingsAction.REMOVE:
if (matched === true) {
channels.splice(i, 1)
console.log("MainView | Did store feeds: " + feeds.write(JSON.stringify(channels)))
}
break
default:
break
}
}
function updateRecentNews(channelId, newsId) {
console.log("MainView | Will update recent news : " + channelId + " with newa " + newsId)
if (channelId === undefined || newsId === undefined) {
mainView.showToast(qsTr("Invalid news ID"))
}
var channels = getFeeds()
var channel
var matched = false
var i
for (i = 0; i < channels.length; i++) {
channel = channels[i]
if (channel["id"] === channelId) {
matched = true
channel["recent"] = newsId
console.log("MainView | Did store feeds: " + feeds.write(JSON.stringify(channels)))
break
}
}
}
function checkAndAddFeed(url) {
console.log("MainView | Will check and update feeds")
var doc = new XMLHttpRequest();
doc.onreadystatechange = function() {
if (doc.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
console.log("MainView | Received header status feed url: " + doc.status);
if (doc.status === 301) {
var redirectUrl = doc.getResponseHeader("Location")
console.log("MainView | Redirect to " + redirectUrl)
if (maxRedirectCount - redirectCount > 0) {
redirectCount = redirectCount + 1
//checkAndAddFeed(redirectUrl)
} else {
redirectCount = 0
mainView.showToast(qsTr("Error because of too much redirects"))
doc.abort()
}
}
else if (doc.status >= 400) {
redirectCount = 0
mainView.showToast(qsTr("Could not load feed: " + doc.statusText))
doc.abort()
}
} else if (doc.readyState === XMLHttpRequest.DONE) {
if (doc.responseXML === null) {
console.log("MainView | No valid XML for feed: " + doc.responseText)
mainView.showToast(qsTr("Could not load a valid feed"))
doc.abort()
} else {
var rss = doc.responseXML.documentElement
var channel
if (rss.nodeName === "feed") {
channel = rss
} else {
for (var i = 0; i < rss.childNodes.length; ++i) {
if (rss.childNodes[i].nodeName === "channel" || rss.childNodes[i].nodeName === "feed") {
channel = rss.childNodes[i]
break
}
}
}
if (channel === undefined) {
console.log("MainView | Missing rss channel")
mainView.showToast(qsTr("Invalid RSS feed: ") + url)
return
}
var feed = new Object
feed.id = url
feed.activated = true
for (i = 0; i < channel.childNodes.length; ++i) {
if (channel.childNodes[i].nodeName === "title") {
var childNode = channel.childNodes[i]
var textNode = childNode.firstChild
feed.name = textNode.nodeValue
} else if (channel.childNodes[i].nodeName === "logo") {
childNode = channel.childNodes[i]
textNode = childNode.firstChild
feed.icon = textNode.nodeValue
}
}
if (feed.icon !== undefined) {
mainView.updateFeed(feed.id, true, mainView.settingsAction.CREATE, feed)
return
}
var baseUrl = getBaseUrl(url)
var htmlRequest = new XMLHttpRequest();
htmlRequest.onreadystatechange = function() {
if (htmlRequest.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
console.log("MainView | Received header status for news homepage: " + htmlRequest.status);
if (htmlRequest.status !== 200) {
console.log("MainView | Couldn't load feed homepage. Will take fallback for icon")
// todo: solution for fallback. ico not supported.
feed.icon = baseUrl + "/favicon.ico"
mainView.updateFeed(feed.id, true, mainView.settingsAction.CREATE, feed)
return
}
} else if (htmlRequest.readyState === XMLHttpRequest.DONE) {
var html = htmlRequest.responseText
feed.icon = getFavicon(baseUrl, html)
mainView.updateFeed(feed.id, true, mainView.settingsAction.CREATE, feed)
return
}
}
htmlRequest.open("GET", baseUrl)
htmlRequest.send()
}
}
}
doc.open("GET", url)
doc.send()
}
function getBaseUrl(url) {
var urlPattern = /(.+:\/\/)?([^\/]+)(\/.*)*/i
var urlArr = urlPattern.exec(url)
urlArr = urlArr[2].split(".")
var baseUrl = "https://www." + urlArr[urlArr.length - 2] + "." + urlArr[urlArr.length - 1]
console.log("MainView | base url for icon is " + baseUrl)
return baseUrl
}
function getFavicon(baseUrl, pageSource) {
var pattern = /<link\n?.+\n?.*rel="((apple-touch-)|(shortcut\s))?icon"\n?.+\n?.*>/i
var link = pattern.exec(pageSource)
if (link !== undefined && link !== null) {
pattern = /href="\S+"/i
link = pattern.exec(link).toString()
var length = link.length - 1
link = link.slice(6, length)
if (!link.startsWith("http")) {
link = baseUrl + link
}
console.log("MainView | Identified feed icon: " + link)
return link
} else {
console.log("MainView | Missing header of feed homepage. Will take fallback for icon")
return baseUrl + "/favicon.ico"
}
}
function getActions() {
var actions = shortcuts.read()
console.log("MainView | Retrieved shortcuts: " + actions)
return actions.length > 0 ? JSON.parse(actions) : mainView.defaultActions
}
function updateAction(actionId, isActive, sAction, newAction) {
console.log("MainView | Will update shortcut: " + actionId + " with properties " + newAction)
var actions = getActions()
var action
var matched = false
var i
var stored = false
for (i = 0; i < actions.length; i++) {
action = actions[i]
if (action["id"] === actionId) {
matched = true
action["activated"] = isActive
break
}
}
switch (sAction) {
case mainView.settingsAction.CREATE:
if (matched === false) {
actions.push(newAction)
stored = shortcuts.write(JSON.stringify(actions))
console.log("MainView | Did store Shortcut: " + stored)
showToast(qsTr("New shortcut") + ": " + newAction.name)
} else {
showToast(qsTr("You have alresdy added the shortcut"))
}
break
case mainView.settingsAction.UPDATE:
if (matched === true) {
actions[i] = action
stored = shortcuts.write(JSON.stringify(actions))
console.log("MainView | Did store shortcuts: " + stored)
}
break
case mainView.settingsAction.REMOVE:
if (matched === true) {
actions.splice(i, 1)
stored = shortcuts.write(JSON.stringify(actions))
console.log("MainView | Did store shortcuts: " + stored)
}
break
default:
break
}
springboard.children[0].item.updateShortcuts(actions)
return stored
}
function getSearchMode() {
return settings.searchMode
}
function updateSearchMode(searchMode) {
settings.searchMode = searchMode
if (settings.sync) {
settings.sync()
}
}
function getNotes() {
if (notes.length === 0) var noteStr = notesStore.read()
return noteStr !== undefined && noteStr.length > 0 ? JSON.parse(noteStr) : notes
}
function updateNote(noteId, content, pinned) {
//console.debug("MainView | Update Note: " + noteId + ", " + content + ", " + pinned)
var notesArr = mainView.getNotes()
var note
var i = 0
while (noteId !== undefined && i < notesArr.length && note === undefined) {
if (notesArr[i]["id"] === noteId) note = notesArr[i]
i++
}
if (note !== undefined) {
console.log("MainView | Existing note: " + note)
note["content"] = content
note["date"] = new Date().valueOf()
note["pinned"] = pinned
notesArr[i-1] = note
} else {
console.log("MainView | Create note")
note = new Object
note["id"] = noteId === undefined ? new Date().valueOf() : noteId
note["content"] = content
note["date"] = new Date().valueOf()
note["pinned"] = false
notesArr.push(note)
}
console.debug("MainView | New JSON: " + JSON.stringify(notesArr))
notesStore.write(JSON.stringify(notesArr))
notes = notesArr
if (mainView.count > mainView.swipeIndex.Collections) {
var item = itemAt(swipeIndex.Collections)
item.children[0].item.updateCollectionPage(mainView.collectionMode.Notes)
}
}
function removeNote(id) {
console.log("MainView | Remove note " + id)
var notesArr = mainView.getNotes()
var index = notesArr.findIndex( element => {
if (element.id === id) {
return true;
}
})
if (index > -1) {
notesArr.splice(index, 1)
notesStore.write(JSON.stringify(notesArr))
notes = notesArr
}
updateCollectionPage(mainView.collectionMode.Notes)
}
function updateSpinner(shouldRun) {
if (!(isLoadingContacts && !shouldRun)) {
spinner.running = shouldRun
}
}
function updateGridView(key, value) {
var item = itemAt(swipeIndex.Apps)
item.children[0].item.updateAppLauncher(key, value)
}
function updateSettings(key, value) {
if (key === "blurEffect") {
settings.blurEffect = value
fastBlur.radius = value
} else if (key === "fullscreen") {
settings.fullscreen = value
if (value) {
appWindow.visibility = 5
} else {
appWindow.visibility = 2
}
} else if (key === "useHapticMenus") {
settings.useHapticMenus = value
mainView.useVibration = value
} else if (key === "showAppsAtStartup") {
settings.showAppsAtStartup = value
} else if (key === "activateSignal") {
settings.signalIsActivated = value
}
if (settings.sync) {
settings.sync()
}
}
function resetActions() {
shortcuts.write(JSON.stringify(defaultActions))
showToast(qsTr("Reset successful"))
}
function resetFeeds() {
feeds.write(JSON.stringify(defaultFeeds))
showToast(qsTr("Reset successful"))
}
function resetLauncher() {
AN.SystemDispatcher.dispatch("volla.launcher.resetAction", {})
}
function resetContacts() {
console.debug("MainView | Reset contacts")
settings.lastContactsCheck = 0.0