Skip to content

Commit 3ccda05

Browse files
committed
javascript in one file
1 parent 6dcccd1 commit 3ccda05

File tree

7 files changed

+141
-87
lines changed

7 files changed

+141
-87
lines changed

.project

+1
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@
4040
<nature>com.qnx.tools.ide.bbt.core.bbtnature</nature>
4141
<nature>org.eclipse.cdt.core.ccnature</nature>
4242
<nature>com.rim.tad.tools.qml.core.qmlNature</nature>
43+
<nature>org.eclipse.cdt.qt.core.qtNature</nature>
4344
</natures>
4445
</projectDescription>

assets/.assets.index

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
1
2-
17
2+
18
33
About.qml
44
backgrounds/1.jpg
55
CamSettings.qml
@@ -13,6 +13,7 @@ images/dialogframe.png
1313
images/rec.png
1414
LivePreview.qml
1515
main.qml
16+
otherfunctions.js
1617
RetryConnectionDialog.qml
1718
Settings.qml
1819
Start.qml

assets/Start.qml

+11-77
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Network.GetterRequest 1.0
33
import CustomerTimer 1.0 //QTIMER TIMER class
44
import QTimerLibrary 1.0 //QTIMER class
55
import bb.system 1.2
6+
import "asset:///otherfunctions.js" as CamFunctions
67

78
Page {
89
id: startpage
@@ -23,18 +24,13 @@ Page {
2324

2425
onStatsReceived: {
2526
//reset NoStat counter
26-
Settings.setSettings("GetStats", 0)
27-
28-
buttonsContainer.enabled = true
29-
30-
responseArea.text = info
31-
batteryLabel.text = info2 + "%"
32-
camMode.text = info3
27+
CamFunctions.StatsReceived(response, batterypercent, mode)
3328
}
3429

3530
onPasswordReceived: {
3631
inProcess.stop()
3732
seTimer.start()
33+
sxTimer.Start()
3834
responseArea.text = "Connecting..."
3935
}
4036

@@ -44,45 +40,16 @@ Page {
4440
}
4541

4642
onSignalNotGetPassword: {
47-
var pcount = Settings.getSettings("GetPassword", 0)
48-
//console.debug("pcount:", pcount)
49-
pcount++
50-
Settings.setSettings("GetPassword", pcount)
51-
52-
if (pcount != 3) {
53-
//console.debug("pcount:", pcount)
54-
//console.debug("2nd or 3rd Getpassword")
55-
GetPassword()
56-
responseArea.text = "Attempt to get password..."
57-
}
58-
if (pcount == 3) {
59-
//console.debug("Start retryDialog and pcount=",pcount)
60-
inProcess.stop()
61-
retryDialog.open()
62-
responseArea.text = "Cannot connect to GoPro"
63-
}
43+
CamFunctions.NotGetPassword()
44+
6445
}
6546

6647
onSignalNotGetStats: {
67-
responseArea.text = "Problem with connection..."
68-
69-
var scount = Settings.getSettings("GetStats", 0)
70-
scount++
71-
console.debug("SCOUNT: ",scount)
72-
Settings.setSettings("GetStats", scount)
73-
74-
if (scount == 3) {
75-
deactAllButPower()
76-
resetNumbers()
77-
powerButton.setChecked(false)
78-
responseArea.text = "Disconnected!"
79-
seTimer.stop()
80-
getPasswordwithCounter()
81-
}
48+
CamFunctions.NotGetStats()
8249
}
8350

8451
},
85-
QTimer {
52+
Timer {
8653
id: sxTimer
8754
interval: 35000
8855
onTimeout: {
@@ -93,12 +60,12 @@ Page {
9360
RetryConnectionDialog {
9461
id: retryDialog
9562
onSendRestart: {
96-
getPasswordwithCounter()
63+
CamFunctions.getPasswordwithCounter()
9764
}
9865
onCancelRestart: {
9966
inProcess.stop()
100-
//deactAllButPower()
101-
deactAllbuttons()
67+
//CamFunctions.deactAllButPower()
68+
CamFunctions.deactAllbuttons()
10269
cancelledAlert.show()
10370
}
10471
}
@@ -373,40 +340,7 @@ Page {
373340

374341
onCreationCompleted: {
375342
//getThis.GetPassword()
376-
getPasswordwithCounter()
343+
CamFunctions.getPasswordwithCounter()
377344
}
378345

379-
//GetPassword with Counter up to 3 times
380-
function getPasswordwithCounter()
381-
{
382-
inProcess.start()
383-
Settings.setSettings("GetPassword", 0)
384-
var pcount = Settings.getSettings("GetPassword", 0)
385-
console.debug("pcount:", pcount)
386-
387-
console.debug("First Getpassword")
388-
389-
//reset failed stat counter
390-
Settings.setSettings("GetStats", 0)
391-
392-
getThis.GetPassword()
393-
}
394-
395-
function deactAllButPower()
396-
{
397-
batteryImage.imageSource = "asset:///images/battery-full-icon0.png"
398-
buttonsContainer.enabled = false
399-
responseArea.text = "Please restart DoIt GoPro to retry to connect..."
400-
}
401-
402-
function resetNumbers()
403-
{
404-
batteryLabel.text = "-%"
405-
camMode.text = "Unknown"
406-
}
407-
408-
function deactAllbuttons()
409-
{
410-
rootContainer.enabled = false
411-
}
412346
}

assets/otherfunctions.js

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/**
2+
* All functions from Start.qml
3+
*/
4+
5+
//When onStatsReceived emitted
6+
//
7+
function StatsReceived(info, info2, info3)
8+
{
9+
Settings.setSettings("GetStats", 0);
10+
11+
sxTimer.start();
12+
buttonsContainer.enabled = true;
13+
powerButton.setChecked(true);
14+
15+
responseArea.text = info;
16+
batteryLabel.text = info2 + "%";
17+
camMode.text = info3;
18+
}
19+
20+
//When the onSignalNotGetStats is emitted, it then calls this function
21+
//
22+
function NotGetStats()
23+
{
24+
responseArea.text = "Off or Problem with connection...";
25+
26+
var scount = Settings.getSettings("GetStats", 0);
27+
scount++;
28+
console.debug("SCOUNT: ",scount);
29+
Settings.setSettings("GetStats", scount);
30+
31+
if (scount == 3) {
32+
deactAllButPower();
33+
resetNumbers();
34+
powerButton.setChecked(false);
35+
responseArea.text = "Disconnected!";
36+
seTimer.stop();
37+
getPasswordwithCounter();
38+
sxTimer.stop();
39+
}
40+
}
41+
42+
//When the onSignalNotGetPassword is emitted, it then calls this function
43+
//
44+
function NoGetPassword()
45+
{
46+
var pcount = Settings.getSettings("GetPassword", 0);
47+
//console.debug("pcount:", pcount)
48+
pcount++;
49+
Settings.setSettings("GetPassword", pcount);
50+
51+
if (pcount != 3) {
52+
//console.debug("pcount:", pcount)
53+
//console.debug("2nd or 3rd Getpassword")
54+
GetPassword();
55+
responseArea.text = "Attempt to get password...";
56+
}
57+
if (pcount == 3) {
58+
//console.debug("Start retryDialog and pcount=",pcount)
59+
inProcess.stop();
60+
retryDialog.open();
61+
responseArea.text = "Cannot connect to GoPro";
62+
}
63+
}
64+
65+
//To make the stats labels to 0 / null / unknown
66+
//
67+
function resetNumbers()
68+
{
69+
batteryLabel.text = "-%";
70+
camMode.text = "Unknown";
71+
}
72+
73+
//GetPassword with Counter up to 3 times
74+
//
75+
function getPasswordwithCounter()
76+
{
77+
inProcess.start();
78+
Settings.setSettings("GetPassword", 0);
79+
var pcount = Settings.getSettings("GetPassword", 0);
80+
console.debug("pcount:", pcount);
81+
82+
console.debug("First Getpassword");
83+
84+
//reset failed stat counter
85+
Settings.setSettings("GetStats", 0);
86+
87+
getThis.GetPassword();
88+
}
89+
90+
91+
//to disable all buttons except the power one
92+
//
93+
function deactAllButPower()
94+
{
95+
batteryImage.imageSource = "asset:///images/battery-full-icon0.png";
96+
buttonsContainer.enabled = false;
97+
responseArea.text = "Please restart DoIt GoPro to retry to connect...";
98+
}
99+
100+
101+
//To disable all buttons
102+
//
103+
function deactAllbuttons()
104+
{
105+
rootContainer.enabled = false;
106+
}
107+
108+
function sxStatsTimer()
109+
{
110+
sxTimer.start();
111+
getThis.StatRequest(Settings.getSettings("password", ""),"sx");
112+
}

src/GetterRequest.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ void GetterRequest::onGetStats()
200200
const int available = reply->bytesAvailable();
201201

202202
if (available > 0) {
203+
qDebug() << "AVAILABLE";
204+
qDebug() << available;
205+
qDebug() << "AVAILABLE";
203206

204207
QByteArray buffer(reply->readAll());
205208

@@ -235,8 +238,11 @@ void GetterRequest::onGetStats()
235238
case 204:
236239
emit statsReceived(response, batteryLevel, camMode);
237240
break;
241+
case 401:
242+
emit signalNotGetStats(401);
243+
break;
238244
default:
239-
emit signalNotGetStats();
245+
emit signalNotGetStats(0);
240246
break;
241247
}
242248

@@ -402,7 +408,7 @@ void GetterRequest::stopReplyTimer()
402408

403409
else if (timer->objectName() == "StatRequest")
404410
{
405-
emit signalNotGetStats();
411+
emit signalNotGetStats(0);
406412
}
407413

408414
}

src/GetterRequest.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ public Q_SLOTS:
2727

2828
Q_SIGNALS:
2929
void responseReceived(const QString &info);
30-
void statsReceived(const QString &info, const int &info2, const QString &info3);
30+
void statsReceived(const QString &response, const int &batterypercent, const QString &mode);
3131
void passwordReceived(const QString &pass);
3232
void commandSent(const QUrl &commandSent);
3333
void timerTimesOut(const QString &requestName);
3434
void signalNotGetPassword();
35-
void signalNotGetStats();
35+
void signalNotGetStats(const int &code);
3636

3737

3838
private Q_SLOTS:

translations/DoIt.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@
1313
<name>GetterRequest</name>
1414
<message>
1515
<location filename="../src/GetterRequest.cpp" line="126"/>
16-
<location filename="../src/GetterRequest.cpp" line="219"/>
16+
<location filename="../src/GetterRequest.cpp" line="222"/>
1717
<source>Error: %1 status: %2</source>
1818
<translation type="unfinished"></translation>
1919
</message>
2020
<message>
2121
<location filename="../src/GetterRequest.cpp" line="134"/>
22-
<location filename="../src/GetterRequest.cpp" line="227"/>
22+
<location filename="../src/GetterRequest.cpp" line="230"/>
2323
<source>Unable to retrieve request headers</source>
2424
<translation type="unfinished"></translation>
2525
</message>
2626
<message>
27-
<location filename="../src/GetterRequest.cpp" line="369"/>
27+
<location filename="../src/GetterRequest.cpp" line="375"/>
2828
<source>Error: %1 Status: %2</source>
2929
<translation type="unfinished"></translation>
3030
</message>
@@ -60,12 +60,12 @@
6060
<context>
6161
<name>Start</name>
6262
<message>
63-
<location filename="../assets/Start.qml" line="149"/>
63+
<location filename="../assets/Start.qml" line="116"/>
6464
<source>DoIt GoPro</source>
6565
<translation type="unfinished"></translation>
6666
</message>
6767
<message>
68-
<location filename="../assets/Start.qml" line="356"/>
68+
<location filename="../assets/Start.qml" line="323"/>
6969
<source>Not Connected</source>
7070
<translation type="unfinished"></translation>
7171
</message>

0 commit comments

Comments
 (0)