Re: [SailfishDevel] Saving state/config

2013-11-15 Thread Jonni Rainisto
Yes your .spec file should have following line if you want to use the plugin:

Requires:   nemo-qml-plugin-configuration-qt5


From: devel-boun...@lists.sailfishos.org [devel-boun...@lists.sailfishos.org] 
on behalf of Thomas Tanghus [tho...@tanghus.net]
Sent: Friday, November 15, 2013 4:24 PM
To: Sailfish OS Developers
Subject: Re: [SailfishDevel] Saving state/config

On Friday 15 November 2013 05:44 Jonni Rainisto wrote:
 import org.nemomobile.configuration 1.0

My n00bness shows again :P Will I have to add this module to my project? The
SailfishOS-i486-x86 target only comes with org.nemomobile.ngf

--
Med venlig hilsen / Best Regards

Thomas Tanghus
___
SailfishOS.org Devel mailing list
___
SailfishOS.org Devel mailing list


Re: [SailfishDevel] Saving state/config

2013-11-15 Thread Thomas Tanghus
On Friday 15 November 2013 20:26 Andrey Kozhevnikov wrote:
 use QSettings as Jonni said and register own component to use in qml, if
 need, or export single class instance via setContextProperty

The latter sounds like the easiest approach.

Thanks both for your good advice.

 On 15.11.2013 20:24, Thomas Tanghus wrote:
  On Friday 15 November 2013 05:44 Jonni Rainisto wrote:
  import org.nemomobile.configuration 1.0
  
  My n00bness shows again :P Will I have to add this module to my project?
  The SailfishOS-i486-x86 target only comes with org.nemomobile.ngf

-- 
Med venlig hilsen / Best Regards

Thomas Tanghus
___
SailfishOS.org Devel mailing list


Re: [SailfishDevel] Saving state/config

2013-11-15 Thread Andrey Kozhevnikov
both are easy. check Qt Assistant. examples and api reference are inside 
your Qt Creator ;)


On 15.11.2013 20:48, Thomas Tanghus wrote:

On Friday 15 November 2013 20:26 Andrey Kozhevnikov wrote:

use QSettings as Jonni said and register own component to use in qml, if
need, or export single class instance via setContextProperty

The latter sounds like the easiest approach.

Thanks both for your good advice.


On 15.11.2013 20:24, Thomas Tanghus wrote:

On Friday 15 November 2013 05:44 Jonni Rainisto wrote:

import org.nemomobile.configuration 1.0

My n00bness shows again :P Will I have to add this module to my project?
The SailfishOS-i486-x86 target only comes with org.nemomobile.ngf


___
SailfishOS.org Devel mailing list


Re: [SailfishDevel] Saving state/config

2013-11-15 Thread Marcin M.
The plugin uses gconf, doesn't it?
Can we use it to modify any gconf entry then?

--
Marcin


2013/11/15 Andrey Kozhevnikov coderusin...@gmail.com

 both are easy. check Qt Assistant. examples and api reference are inside
 your Qt Creator ;)


 On 15.11.2013 20:48, Thomas Tanghus wrote:

 On Friday 15 November 2013 20:26 Andrey Kozhevnikov wrote:

 use QSettings as Jonni said and register own component to use in qml, if
 need, or export single class instance via setContextProperty

 The latter sounds like the easiest approach.

 Thanks both for your good advice.

  On 15.11.2013 20:24, Thomas Tanghus wrote:

 On Friday 15 November 2013 05:44 Jonni Rainisto wrote:

 import org.nemomobile.configuration 1.0

 My n00bness shows again :P Will I have to add this module to my project?
 The SailfishOS-i486-x86 target only comes with org.nemomobile.ngf


 ___
 SailfishOS.org Devel mailing list

___
SailfishOS.org Devel mailing list

Re: [SailfishDevel] Saving state/config

2013-11-15 Thread Andrey Kozhevnikov

Sure. but you can make own classes for bth QSettings and GConfItem ;)

On 15.11.2013 21:00, Marcin M. wrote:

The plugin uses gconf, doesn't it?
Can we use it to modify any gconf entry then?

--
Marcin


2013/11/15 Andrey Kozhevnikov coderusin...@gmail.com 
mailto:coderusin...@gmail.com


both are easy. check Qt Assistant. examples and api reference are
inside your Qt Creator ;)


On 15.11.2013 20:48, Thomas Tanghus wrote:

On Friday 15 November 2013 20:26 Andrey Kozhevnikov wrote:

use QSettings as Jonni said and register own component to
use in qml, if
need, or export single class instance via setContextProperty

The latter sounds like the easiest approach.

Thanks both for your good advice.

On 15.11.2013 20:24, Thomas Tanghus wrote:

On Friday 15 November 2013 05:44 Jonni Rainisto wrote:

import org.nemomobile.configuration 1.0

My n00bness shows again :P Will I have to add this
module to my project?
The SailfishOS-i486-x86 target only comes with
org.nemomobile.ngf


___
SailfishOS.org Devel mailing list




___
SailfishOS.org Devel mailing list


___
SailfishOS.org Devel mailing list

Re: [SailfishDevel] Saving state/config

2013-11-15 Thread Thomas Tanghus
On Friday 15 November 2013 20:50 Andrey Kozhevnikov wrote:
 both are easy. check Qt Assistant. examples and api reference are inside
 your Qt Creator ;)

Forgive me for non-SailfishOS questions, but I must be doing something wrong, 
even if it's easy ;)

My main is now:

int main(int argc, char *argv[]) {
QGuiApplication *app = SailfishApp::application(argc, argv);
QQuickView *view = SailfishApp::createView();
QSettings *settings = new QSettings(Tanghus, 
net.tanghus.currencyconverter.sailfish);
view-rootContext()-setContextProperty(settings, settings);
view-
setSource(SailfishApp::pathTo(qml/net.tanghus.currencyconverter.sailfish.qml));
view-showFullScreen();
return app-exec();
}

And in ApplicationWindow I can see it's instantiated:

Component.onCompleted: {
console.log('Ready', settings);
}

Prints: Ready QSettings(0x70b633a0)

But if I use it like:

refreshInterval = settings.value('refreshInterval', 3600).toInt();

I get:

file:///opt/sdk/net.tanghus.currencyconverter.sailfish/usr/share/net.tanghus.currencyconverter.sailfish/qml/net.tanghus.currencyconverter.sailfish.qml:64:
 
TypeError: Object [object Object] has no method 'value'

I'm sure this is very trivial - but atm I'm stuck :P

 On 15.11.2013 20:48, Thomas Tanghus wrote:
  On Friday 15 November 2013 20:26 Andrey Kozhevnikov wrote:
  use QSettings as Jonni said and register own component to use in qml, if
  need, or export single class instance via setContextProperty
  
  The latter sounds like the easiest approach.
  

-- 
Med venlig hilsen / Best Regards

Thomas Tanghus
___
SailfishOS.org Devel mailing list


Re: [SailfishDevel] Saving state/config

2013-11-15 Thread Thomas Tanghus
Ah OK. I had missed that. It would also have been almost too easy ;)

Thanks a lot for your thorough help

On Friday 15 November 2013 23:39 Andrey Kozhevnikov wrote:
 unfortunately you cant use QSettings class this way. It have no public
 slots to be used from QML side. You need to write some QmlSettings class
 wrapper for QSettings:
 
 class QmlSettings: publicQObject
 ...
 public slots:
QVariant value(const QString key);
void setValue(const QString key, const QVariant value);
 
 ...
 private:
QSettings *_settings;
 
 ...
 
 in class constructor:
 
 _settings = new QSettings(Tanghus,
 net.tanghus.currencyconverter.sailfish);
 
 and
 
 QVariant QmlSettings::value(const QString key){
return _settings-value(key);
 }
 
 void QmlSettings::setValue(const QString key, const QVariant value){
_settings-setValue(key, value);
 }
 
 and then you can use QmlSettings class in QML
 
 On 15.11.2013 23:32, Thomas Tanghus wrote:
  On Friday 15 November 2013 20:50 Andrey Kozhevnikov wrote:
  both are easy. check Qt Assistant. examples and api reference are inside
  your Qt Creator ;)
  
  Forgive me for non-SailfishOS questions, but I must be doing something
  wrong, even if it's easy ;)
  
  My main is now:
  
  int main(int argc, char *argv[]) {
  
   QGuiApplication *app = SailfishApp::application(argc, argv);
   QQuickView *view = SailfishApp::createView();
   QSettings *settings = new QSettings(Tanghus,
  
  net.tanghus.currencyconverter.sailfish);
  
   view-rootContext()-setContextProperty(settings, settings);
   view-
  
  setSource(SailfishApp::pathTo(qml/net.tanghus.currencyconverter.sailfish
  .qml)); 
   view-showFullScreen();
   return app-exec();
  
  }
  
  And in ApplicationWindow I can see it's instantiated:
   Component.onCompleted: {
   
   console.log('Ready', settings);
   
   }
  
  Prints: Ready QSettings(0x70b633a0)
  
  But if I use it like:
   refreshInterval = settings.value('refreshInterval', 3600).toInt();
  
  I get:
  
  file:///opt/sdk/net.tanghus.currencyconverter.sailfish/usr/share/net.tangh
  us.currencyconverter.sailfish/qml/net.tanghus.currencyconverter.sailfish.q
  ml:64: TypeError: Object [object Object] has no method 'value'
  
  I'm sure this is very trivial - but atm I'm stuck :P
  
  On 15.11.2013 20:48, Thomas Tanghus wrote:
  On Friday 15 November 2013 20:26 Andrey Kozhevnikov wrote:
  use QSettings as Jonni said and register own component to use in qml,
  if
  need, or export single class instance via setContextProperty
  
  The latter sounds like the easiest approach.
 
 ___
 SailfishOS.org Devel mailing list

-- 
Med venlig hilsen / Best Regards

Thomas Tanghus
___
SailfishOS.org Devel mailing list


Re: [SailfishDevel] Saving state/config

2013-11-15 Thread Artem Marchenko
Thanks a lot, Jonni!

Discussion went further already, but I am just fascinated you guys have got
such a plugin ready! I used to implement GConf modification on my own or
create a Settings wrapper for the LocalStorage and now there's a ready made
plugin for GConf - great!

Best regards,
Artem.



On Fri, Nov 15, 2013 at 7:44 AM, Jonni Rainisto jonni.raini...@jolla.comwrote:

 Hi,

 Normal usage of QSettings which saves under /home/nemo/.config/app would
 be just fine for C++.
 If you just want to save few config values in QML, then you might want to
 use GConf by importing nemo-qml-plugin-configuration module (
 https://github.com/nemomobile/nemo-qml-plugin-configuration) and use
 config key like com/yourdomain/applicationname etc.

 For example:
 --
 import org.nemomobile.configuration 1.0

 Page {
 ConfigurationValue {
 id: your_foo_setting
 key: /com/super/superapplication/light_value
 defaultValue: -1
 }
 --
 re, Jonni
 
 From: devel-boun...@lists.sailfishos.org [
 devel-boun...@lists.sailfishos.org] on behalf of Thomas Tanghus [
 tho...@tanghus.net]
 Sent: Friday, November 15, 2013 3:13 AM
 To: Sailfish OS Developers
 Subject: [SailfishDevel] Saving state/config

 I couldn't find any standard way of saving an apps config. Is there such a
 standard, or is it up to the developer to choose format and location?

 I'm making a *very* simple app, so only using QML/JS, and only have to save
 3-4 values.

 As far as I could see the location should be
 /home/nemo/.config/appname[.ext]
 which could probably be accomplished better using
 QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) but is
 that
 possible in QML?
 And which format should it be in?

 --
 Med venlig hilsen / Best Regards

 Thomas Tanghus
 ___
 SailfishOS.org Devel mailing list
 ___
 SailfishOS.org Devel mailing list




-- 
Artem Marchenko
http://agilesoftwaredevelopment.com
http://twitter.com/AgileArtem
___
SailfishOS.org Devel mailing list

Re: [SailfishDevel] Saving state/config

2013-11-15 Thread Thomas Tanghus
On Friday 15 November 2013 14:27 Jonni Rainisto wrote:
 Yes your .spec file should have following line if you want to use the
 plugin:
 
 Requires:   nemo-qml-plugin-configuration-qt5

I went with the QSettings wrapper as proposed by Andrey, but this is certainly 
good to know for further development.
I've learned from the community a lot since I decided to awake my dormant 
Plasma widget Wednesday night :)

QML/Silica makes creating apps a breeze once you know your way around it :)

 From: devel-boun...@lists.sailfishos.org
 [devel-boun...@lists.sailfishos.org] on behalf of Thomas Tanghus
 [tho...@tanghus.net] Sent: Friday, November 15, 2013 4:24 PM
 To: Sailfish OS Developers
 Subject: Re: [SailfishDevel] Saving state/config
 
 On Friday 15 November 2013 05:44 Jonni Rainisto wrote:
  import org.nemomobile.configuration 1.0
 
 My n00bness shows again :P Will I have to add this module to my project? The
 SailfishOS-i486-x86 target only comes with org.nemomobile.ngf
-- 
Med venlig hilsen / Best Regards

Thomas Tanghus
___
SailfishOS.org Devel mailing list