/gpump/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/gpump/trunk

« back to all changes in this revision

Viewing changes to src/settings_data.js

  • Committer: Gustav Hartvigsson
  • Date: 2014-06-09 12:46:36 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20140609124636-swulk259dubsefgt
* finnished the getter and setter for the settings. Still untested.

Show diffs side-by-side

added added

removed removed

Lines of Context:
102
102
   */
103
103
  set_setting: function (setting, value) {
104
104
    if (typeof setting != "string") {
105
 
      print ("ERROR: The \"setting\" paramenter must be a string... Exiting.");
 
105
      print ("ERROR: The \"setting\" parameter must be a string.");
106
106
      return false;
107
107
    }
 
108
    switch (setting) {
 
109
      case "ui.x":
 
110
        if (typeof value == "number") {
 
111
          this._settings.ui.x = value;
 
112
        } else {
 
113
          print ("The setting \"ui.x\" must be a number.");
 
114
        }
 
115
        break;
 
116
      case "ui.y":
 
117
        if (typeof value == "number") {
 
118
          this._settings.ui.y = value;
 
119
        } else {
 
120
          print ("The setting \"ui.y\" must be a number.");
 
121
        }
 
122
        break;
 
123
      case "ui.h":
 
124
        if (typeof value == "number") {
 
125
          this._settings.ui.h = value;
 
126
        } else {
 
127
          print ("The setting \"ui.h\" must be a number.");
 
128
        }
 
129
        break;
 
130
      case "ui.w":
 
131
        if (typeof value == "number") {
 
132
          this._settings.ui.w = value;
 
133
        } else {
 
134
          print ("The setting \"ui.w\" must be a number.");
 
135
        }
 
136
        break;
 
137
      case "main.use_dark":
 
138
        if (typeof value == "boolean") {
 
139
          this._settings.main.use_dark = value;
 
140
        } else {
 
141
          print ("The setting \"main.use_dark\" must be a boolean.");
 
142
        }
 
143
        break;
 
144
      case "main.first_run":
 
145
        if (typeof value == "boolean") {
 
146
          this._settings.main.first_run = value;
 
147
        } else {
 
148
          print ("The setting \"main.first_run\" must be a boolean.");
 
149
        }
 
150
        break;
 
151
      case "main.privacy.show_full_name":
 
152
        if (typeof value == "boolean") {
 
153
          this._settings.main.privacy.show_full_name = value;
 
154
        } else {
 
155
          print (
 
156
          "The setting \"main.privacy.show_full_name\" must be a boolean.");
 
157
        }
 
158
        break;
 
159
      case "main.privacy.only_show_avatar":
 
160
        if (typeof value == "boolean") {
 
161
          this._settings.main.privacy.only_show_avatar = value;
 
162
        } else {
 
163
          print (
 
164
          "The setting \"main.privacy.only_show_avatar\" must be a boolean.");
 
165
        }
 
166
        break;
 
167
      default:
 
168
        
 
169
        print ("ERROR: The setting \"" + setting + "\" does not exist.");
 
170
        return false;
 
171
        break;
 
172
    }
108
173
    
 
174
    return true;
109
175
  },
110
176
  
111
177
  /**
112
178
   * Gets a value from the settings object.
113
179
   *
114
 
   * returns a complex object with two fealds: ok and data.
115
 
   *
116
 
   * If ok is false something went wrong and the data feald will be undefined.
117
 
   *
118
 
   * If ok is true everything is ok and the data feald will be set to the value.
 
180
   * returns a complex object with two field: ok and data.
 
181
   *
 
182
   * If ok is false something went wrong and the data field will be undefined.
 
183
   *
 
184
   * If ok is true everything is ok and the data field will be set to the value.
119
185
   */
120
186
  get_setting: function (setting) {
121
187
    let ret_data = {
123
189
      data: undefined
124
190
    };
125
191
    
 
192
    if (typeof setting != "string") {
 
193
      print ("ERROR: The \"setting\" parameter must be a string.");
 
194
      ret_data.ok = false;
 
195
      return ret_data.ok;
 
196
    }
 
197
    
 
198
    switch (setting) {
 
199
      case "ui.x":
 
200
        ret_data.data = this._settings.ui.x;
 
201
        break;
 
202
      case "ui.y":
 
203
        ret_data.data = this._settings.ui.y;
 
204
        break;
 
205
      case "ui.h":
 
206
        ret_data.data = this._settings.ui.h;
 
207
        break;
 
208
      case "ui.w":
 
209
        ret_data.data = this._settings.ui.w;
 
210
        break;
 
211
      case "main.use_dark":
 
212
        ret_data.data = this._settings.main.use_dark;
 
213
        break;
 
214
      case "main.first_run":
 
215
        ret_data.data = this._settings.main.first_run;
 
216
        break;
 
217
      case "main.privacy.show_full_name":
 
218
        ret_data.data = this._settings.main.privacy.show_full_name;
 
219
        break;
 
220
      case "main.privacy.only_show_avatar":
 
221
        ret_data.data = this._settings.main.privacy.only_show_avatar;
 
222
        break;
 
223
      default:
 
224
        ret_data.ok = false;
 
225
        print ("ERROR: The setting \"" + setting + "\" does not exist.");
 
226
        break;
 
227
    }
 
228
    
126
229
    return ret_data;
127
230
  },
128
231