maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   SailfishOS (https://talk.maemo.org/forumdisplay.php?f=52)
-   -   Help me to code for Sailfish OS (https://talk.maemo.org/showthread.php?t=100817)

coderus 2020-09-03 00:07

Re: Help me to code for Sailfish OS
 
cool! [16 chars]

Markkyboy 2020-09-03 16:14

Re: Help me to code for Sailfish OS
 
The following code is a part of a Row, the Rectangle acts as a button and sends an IR command via WiFi to a Tasmotised Sonoff RF;

Code:

               
    Rectangle {
        id: mainLights1
        width: 80
        height: 80
        radius: 40
        color: "transparent"
        border.color: "yellow"
        border.width: mini1.pressed ? 4 : 2
        MouseArea {
            id: mini1
            anchors.fill: parent
            onClicked: {
                var xhttp = new XMLHttpRequest()
                xhttp.onreadystatechange = function() {
                    if (xhttp.readyState === 4 && xhttp.status === 200) {
                        led.opacity = 1.0
                        timer.start()
                        vibrate.start()
                        mainLights1.radius = 40

                        mainLights1.border.color = "green"  <-- ON, color is green

                        console.log("Main light1" + " " + xhttp.responseText)
                    }
                    else mainLights1.radius = 20
                }
                xhttp.open("POST", "http://192.168.0.230/cm?cmnd=cmnd/mini1/power toggle")
                xhttp.send()
            }
        }
        Label { text: "<b>PATIO</b>" ; anchors.centerIn: parent; color: "white"; font.pixelSize: Theme.fontSizeTiny }
    }

I'd like the following to happen when pressing the button;

Light ON = GREEN (mainLights1.border.color) - DONE
Light OFF = YELLOW (mainLights1.border.color) - ????

I've tried so many things, too many to list. Perhaps using 'if/else' is not the way to go?

coderus 2020-09-03 18:05

Re: Help me to code for Sailfish OS
 
i'm not sure what are you doing here, but probably you need to check result of network call, or perform additional call to get actual state of lights, and change color of button

Markkyboy 2020-09-03 18:37

Re: Help me to code for Sailfish OS
 
Well, it's a button made from a rectangle, when the button is pressed it turns a light on. When the light is on, the button should be green, when the light is turned off, the button should be yellow.

Sounds like you do understand my question, but how do I check the result of the network call?

In the code, there is console.log(), this outputs the xhttp.responseText, for example, the response looks like this;

Code:

mainLights1 "{"POWER":"ON"}"
Can I somehow use this output to change color of my button?

coderus 2020-09-03 21:07

Re: Help me to code for Sailfish OS
 
Code:

mainLights1.border.color = JSON.parse(xhttp.responseText).POWER == 'ON' ? "green" : "red"

Markkyboy 2020-09-04 21:50

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by coderus (Post 1569106)
Code:

mainLights1.border.color = JSON.parse(xhttp.responseText).POWER == 'ON' ? "green" : "red"

Perfect!, thanks.

rob_kouw 2020-09-06 16:11

Re: Help me to code for Sailfish OS
 
coderus, I read something about a FileModel. The post referred to your GitHub page, but the files have been removed from there. Is it possible to view them somewhere else?

coderus 2020-09-06 20:05

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by rob_kouw (Post 1569142)
coderus, I read something about a FileModel. The post referred to your GitHub page, but the files have been removed from there. Is it possible to view them somewhere else?

can you give more information what are you talking about? :D

rob_kouw 2020-09-07 07:06

Re: Help me to code for Sailfish OS
 
Sure. For my app (pure QML/JS now) I would like to have the possibility to select a file in Downloads, and the content into a variable.

coderus 2020-09-07 12:30

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by rob_kouw (Post 1569148)
Sure. For my app (pure QML/JS now) I would like to have the possibility to select a file in Downloads, and the content into a variable.

check https://github.com/CODeRUS/splashscr...SecondPage.qml

you can select file in QML, but you can't read it using qml only. You need Qt or python backend

Markkyboy 2020-09-08 11:26

Arranging numbers/letters/tickmarks in a circle
 
1 Attachment(s)
My application shows a dial with compass bearings (numbers) and tickmarks (asterisks).

I cannot use QML CircularGauge for my purpose because 'Controls.Styles' is not available in SFOS.

Currently, I am using this method for placing my text/numbers in a circular fashion;

Code:

    Rectangle {
            color: "#00000000"; width: 520; height: 520; radius: 260; anchors.centerIn: parent
            Repeater {
                id: tickmarks
                model: {
                    [
                    ' ', '*', '*', ' ', '*', '*', ' ', '*', '*', ' ', '*', '*',
                    ' ', '*', '*', ' ', '*', '*', ' ', '*', '*', ' ', '*', '*',
                    ' ', '*', '*', ' ', '*', '*', ' ', '*', '*', ' ', '*', '*'
                    ]
                }
                delegate: Rectangle {
                    height: 260
                    anchors.horizontalCenter: parent.horizontalCenter
                    transformOrigin: Rectangle.Bottom
                    rotation: 360 / tickmarks.model.length * index
                    Text {
                        text: modelData
                        color: Theme.secondaryHighlightColor
                        font {
                            bold: Font.Bold
                            pixelSize: 28
                        }
                        anchors.horizontalCenter: parent.horizontalCenter
                    }
                }
            }
        }

The above code is messy and clunky, among other things. How can I refine this code or is there a better way to achieve what is shown in the image?

thanks,

coderus 2020-09-08 11:32

Re: Help me to code for Sailfish OS
 
found this https://github.com/RSATom/Qt/blob/ma...GaugeStyle.qml
i think its easy to copy and implement as standalone item

Markkyboy 2020-09-08 12:42

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by coderus (Post 1569166)
found this https://github.com/RSATom/Qt/blob/ma...GaugeStyle.qml
i think its easy to copy and implement as standalone item

But that shows Controls.Styles as an import statement. I had already tried stripping down CircularGauge QML, but Controls.Styles is required.

/* I'll play anyway, its a huge file for what it does, amazing.*/
EDIT, I decided against playing with this file, it requires 4 import modules that are not available in SFOS.

thanks,

coderus 2020-09-08 14:29

Re: Help me to code for Sailfish OS
 
Grab minimal code, then go to styles if you really need it. For bare minimal code inside CircularGaugeStyle is enough to be copied to standalone item

Markkyboy 2020-09-08 16:33

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by coderus (Post 1569170)
Grab minimal code, then go to styles if you really need it. For bare minimal code inside CircularGaugeStyle is enough to be copied to standalone item

Okay, but I'm sure 'Styles' is also not available in SFOS. I have tried many import statements that are not available. I've looked through '/usr/lib/qt5/qml' on my device and didn't see 'controls' or 'styles'......?

coderus 2020-09-08 17:25

Re: Help me to code for Sailfish OS
 
you can't just copy and paste, you have to code the code! you can take idea from existing qtquick item and adapt to your project.

Maemish 2020-09-08 17:28

Re: Help me to code for Sailfish OS
 
Is this anyway related even though there is no ready answer?

https://talk.maemo.org/showthread.php?t=96839

coderus 2020-09-08 17:34

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by Maemish (Post 1569175)
Is this anyway related even though there is no ready answer?

https://talk.maemo.org/showthread.php?t=96839

dont miss %install step to actually copy files-to-be-packaged to %{buildroot}, then %files section can package it. files outside %{buildroot} can't be packaged.

Maemish 2020-09-08 19:22

Re: Help me to code for Sailfish OS
 
Would rinigus know answer to this? It seems he has done some stuff which may include something related.

rob_kouw 2020-09-09 20:27

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by coderus (Post 1568965)
i dont know a way to do this in pure qml without c++ code

So, the question was:
- There is a page with a ListView, with a model from database contents
- Tapping on an item opens a new Dialog, where the database item could change
- popping the dialog leaves an old listview that needs refreshing

Now, I found your GitHub page on callbacks: https://gist.github.com/CODeRUS/5235...bfaf0bafbeb7cd

Could I push the dialog with a callback to a function that would update the listview? Or is that not what the callback is for? Something like:
pageStack.push(Qt.resolvedUrl("DialogPage.qml"), {callback: updateListViewAfterDialog })

Update: yes, this seems to work!

rob_kouw 2020-09-14 09:34

Re: Help me to code for Sailfish OS
 
Codearus, maybe you know some way to manipulate the virtual keyboard from QML.

I noticed OKboard stops functioning frequently. The cause of it, I think, is my app GMFS. it seems every time I use a Dialog with numerical input, like
Code:

inputMethodHints: Qt.ImhFormattedNumbersOnly
OKboard stops working when the keyboard is back to QWERTY.

Do you know a command I can use in my app - QML/JS - to revive OKboard?

coderus 2020-09-14 10:15

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by rob_kouw (Post 1569264)
Codearus, maybe you know some way to manipulate the virtual keyboard from QML.

I noticed OKboard stops functioning frequently. The cause of it, I think, is my app GMFS. it seems every time I use a Dialog with numerical input, like
Code:

inputMethodHints: Qt.ImhFormattedNumbersOnly
OKboard stops working when the keyboard is back to QWERTY.

Do you know a command I can use in my app - QML/JS - to revive OKboard?

no, i never used okboard, sorry

Markkyboy 2020-09-20 09:54

Re: Help me to code for Sailfish OS
 
Currently, I have Eclipse MQTT 1.3.1 running flawlessly on my Jolla1.

I note there are 3 files for MQTT on my device, found in /usr/bin/; mosquitto_passwd, mosquitto_sub and mosquitto_pub

I also have a remote control app (as previously discussed with regard to changing button colours when lights are on/off). I would like to utilise MQTT to tell my Jolla1 when a light switch has been activated and change/update the button colour accordingly.

I am quite conversant with MQTT commands, but totally lack any ideas on how to implement/include MQTT in my remote control application.

Side note: MQTT for QML is not part of Qt, it is QtAutomotive, which requires licensing, so no good using official routes.

Any input appreciated, thanks

coderus 2020-09-20 22:15

Re: Help me to code for Sailfish OS
 
you can't implement it with given cli tools

Markkyboy 2020-09-29 09:59

Re: Help me to code for Sailfish OS
 
Hi coderus,

I have a small niggle with fetching an image from openweathermap.org. See the following code;

HTML Code:

        Image {
            id: icon
            source: "http://openweathermap.org/img/wn/" + label.text + "@2x.png"
            anchors.horizontalCenter: parent.horizontalCenter
        }
        Label {
            id: label
            text: {
                (wDataCntr.weatherData)
                ? String(wDataCntr.weatherData.weather[0].icon)
                : ""
            }
            visible: false
        }
    }


Yields the following error;

[W] unknown:13 - file:///usr/share/my-weather-landscape/qml/pages/WeatherIcon.qml:13:5: QML Image: Error transferring http://openweathermap.org/img/wn/@2x.png - server replied: Not Found

but the required/expected image is returned and displayed.

How can I prevent this error?, is there a better way to retrieve the required image?

Thanks,

coderus 2020-09-29 10:01

Re: Help me to code for Sailfish OS
 
do not load image if label text is empty?

Markkyboy 2020-09-29 11:09

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by coderus (Post 1569416)
do not load image if label text is empty?

Cool, but I wasn't quite sure how to implement your suggestion.

However, instead I added a Timer with no interval to be triggered upon the feed being updated or the app being started, the image is loaded successfully and I do not see any error in console log (thumbs up!)

I'm still open to any suggestions (preferably with an example) if someone knows a better way.

coderus 2020-09-29 12:43

Re: Help me to code for Sailfish OS
 
try adding
Code:

enabled: label.text
to Image

Markkyboy 2020-09-29 14:32

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by coderus (Post 1569418)
try adding
Code:

enabled: label.text
to Image

Okay, will try later. My OWM account just got suspended for making too many calls, Oops!

levone1 2020-11-06 21:40

Re: Help me to code for Sailfish OS
 
Quick question for anyone - how can I see all dconf keys? I can use dconf list command, but it seems like it doesn't show everything, since I am able to change certain values with write command that I don't see listed...
(sorry I can't remember the specifics atm - it's something I've been meaning to get around to posting for a while now, after messing around with it months ago - maybe someone knows about it... I'll try to pull it back up at some point and refresh my memory...)

peterleinchen 2020-11-06 22:03

Re: Help me to code for Sailfish OS
 
You mean like ?
Code:

dconf dump /

Markkyboy 2020-11-07 07:35

Re: Help me to code for Sailfish OS
 
as per the response from peterleinchen, you can also output to file;

Code:

dconf dump / > dconf-output.txt

aerique 2020-12-05 16:10

Re: Help me to code for Sailfish OS
 
What's the proper way to store an apps settings?

For my current (and first) app I'm for now just grabbing the `$HOME` environment variable and stuff a file in `$HOME/.config/app/settings`, but this is just for local dev and testing.

Once I'm distributing it through OpenRepos I'd like to do it the proper way (if there is one).

edit: Thanks for the hint, coderus. I've gone with:
Code:

QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)

coderus 2020-12-05 17:06

Re: Help me to code for Sailfish OS
 
Quote:

Originally Posted by aerique (Post 1570411)
What's the proper way to store an apps settings?

For my current (and first) app I'm for now just grabbing the `$HOME` environment variable and stuff a file in `$HOME/.config/app/settings`, but this is just for local dev and testing.

Once I'm distributing it through OpenRepos I'd like to do it the proper way (if there is one).

https://doc.qt.io/archives/qt-5.6/qstandardpaths.html

Code:

QStandardPaths::writableLocation(QStandardPaths::DataLocation)
If you use QSettings class it will automatically create file in correct location.


All times are GMT. The time now is 15:19.

vBulletin® Version 3.8.8