dc53ec5e0b9b3e165bf7909f86f65c9d7381866b
[roobuilder] / src / Builder4 / ProjectSettings.vala
1 static Xcls_RooProjectSettings  _RooProjectSettings;
2
3 public class Xcls_RooProjectSettings : Object
4 {
5     public Gtk.Box el;
6     private Xcls_RooProjectSettings  _this;
7
8     public static Xcls_RooProjectSettings singleton()
9     {
10         if (_RooProjectSettings == null) {
11             _RooProjectSettings= new Xcls_RooProjectSettings();
12         }
13         return _RooProjectSettings;
14     }
15     public Xcls_label_global label_global;
16     public Xcls_label_database label_database;
17     public Xcls_path path;
18     public Xcls_base_template base_template;
19     public Xcls_rootURL rootURL;
20     public Xcls_view view;
21     public Xcls_database_DBTYPE database_DBTYPE;
22     public Xcls_database_DBNAME database_DBNAME;
23     public Xcls_database_DBUSERNAME database_DBUSERNAME;
24     public Xcls_database_DBPASSWORD database_DBPASSWORD;
25     public Xcls_database_ERROR database_ERROR;
26
27         // my vars (def)
28     public signal void buttonPressed (string btn);
29     public Project.Project project;
30
31     // ctor
32     public Xcls_RooProjectSettings()
33     {
34         _this = this;
35         this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
36
37         // my vars (dec)
38
39         // set gobject values
40         this.el.homogeneous = false;
41         this.el.border_width = 5;
42         var child_0 = new Xcls_Box2( _this );
43         child_0.ref();
44         this.el.pack_start (  child_0.el , false,false,0 );
45         var child_1 = new Xcls_Notebook5( _this );
46         child_1.ref();
47         this.el.pack_end (  child_1.el , true,true,0 );
48     }
49
50     // user defined functions
51     public void show (Project.Project project) {
52         _this.project = project;
53         _this.path.el.label = project.firstPath();
54         // get the active project.
55          var lm = Gtk.SourceLanguageManager.get_default();
56                     
57         ((Gtk.SourceBuffer)(_this.view.el.get_buffer())) .set_language(
58         
59             lm.get_language("html"));
60       
61         //print (project.fn);
62         //project.runhtml = project.runhtml || '';
63         _this.view.el.get_buffer().set_text(project.runhtml);
64         
65            
66         _this.rootURL.el.set_text( _this.project.rootURL );
67         _this.base_template.el.set_text(_this.project.base_template);    
68          var js = _this.project;
69         _this.database_DBTYPE.el.set_text(     js.get_string_member("DBTYPE") );
70         _this.database_DBNAME.el.set_text(    js.get_string_member("DBNAME") );
71         _this.database_DBUSERNAME.el.set_text(    js.get_string_member("DBUSERNAME") );
72         _this.database_DBPASSWORD.el.set_text(    js.get_string_member("DBPASSWORD") );
73         //this.el.show_all();
74     }
75     public void save ()
76     {
77        var buf =    _this.view.el.get_buffer();
78        Gtk.TextIter s;
79          Gtk.TextIter e;
80         buf.get_start_iter(out s);
81         buf.get_end_iter(out e);
82           _this.project.runhtml = buf.get_text(s,e,true);
83           
84         _this.project.rootURL = _this.rootURL.el.get_text();
85         _this.project.base_template = _this.base_template.el.get_text();    
86         
87         var js = _this.project.json_project_data;
88         js.set_string_member("DBTYPE", _this.database_DBTYPE.el.get_text());
89        js.set_string_member("DBNAME", _this.database_DBNAME.el.get_text());
90         js.set_string_member("DBUSERNAME", _this.database_DBUSERNAME.el.get_text());
91         js.set_string_member("DBPASSWORD", _this.database_DBPASSWORD.el.get_text());
92     //    _this.project.set_string_member("DBHOST", _this.DBTYPE.el.get_text());    
93         
94         // need to re-init the database 
95         
96         _this.project.initRooDatabase();
97           
98     }
99     public class Xcls_Box2 : Object
100     {
101         public Gtk.Box el;
102         private Xcls_RooProjectSettings  _this;
103
104
105             // my vars (def)
106
107         // ctor
108         public Xcls_Box2(Xcls_RooProjectSettings _owner )
109         {
110             _this = _owner;
111             this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
112
113             // my vars (dec)
114
115             // set gobject values
116             this.el.homogeneous = true;
117             this.el.expand = false;
118             this.el.vexpand = false;
119             var child_0 = new Xcls_Button3( _this );
120             child_0.ref();
121             this.el.add (  child_0.el  );
122             var child_1 = new Xcls_Button4( _this );
123             child_1.ref();
124             this.el.add (  child_1.el  );
125         }
126
127         // user defined functions
128     }
129     public class Xcls_Button3 : Object
130     {
131         public Gtk.Button el;
132         private Xcls_RooProjectSettings  _this;
133
134
135             // my vars (def)
136
137         // ctor
138         public Xcls_Button3(Xcls_RooProjectSettings _owner )
139         {
140             _this = _owner;
141             this.el = new Gtk.Button();
142
143             // my vars (dec)
144
145             // set gobject values
146             this.el.label = "Apply";
147
148             //listeners
149             this.el.button_press_event.connect( () => {
150                 _this.save();
151                       
152                 _this.buttonPressed("apply");
153                     return false;
154             });
155         }
156
157         // user defined functions
158     }
159
160     public class Xcls_Button4 : Object
161     {
162         public Gtk.Button el;
163         private Xcls_RooProjectSettings  _this;
164
165
166             // my vars (def)
167
168         // ctor
169         public Xcls_Button4(Xcls_RooProjectSettings _owner )
170         {
171             _this = _owner;
172             this.el = new Gtk.Button();
173
174             // my vars (dec)
175
176             // set gobject values
177             this.el.label = "Save";
178
179             //listeners
180             this.el.button_press_event.connect( () => {
181                    _this.save();
182                       
183                 _this.buttonPressed("save");
184                     return false;
185             });
186         }
187
188         // user defined functions
189     }
190
191
192     public class Xcls_Notebook5 : Object
193     {
194         public Gtk.Notebook el;
195         private Xcls_RooProjectSettings  _this;
196
197
198             // my vars (def)
199
200         // ctor
201         public Xcls_Notebook5(Xcls_RooProjectSettings _owner )
202         {
203             _this = _owner;
204             this.el = new Gtk.Notebook();
205
206             // my vars (dec)
207
208             // set gobject values
209             var child_0 = new Xcls_label_global( _this );
210             child_0.ref();
211             var child_1 = new Xcls_label_database( _this );
212             child_1.ref();
213             var child_2 = new Xcls_Box8( _this );
214             child_2.ref();
215             this.el.append_page (  child_2.el , _this.label_global.el );
216             var child_3 = new Xcls_Box19( _this );
217             child_3.ref();
218             this.el.append_page (  child_3.el , _this.label_database.el );
219         }
220
221         // user defined functions
222     }
223     public class Xcls_label_global : Object
224     {
225         public Gtk.Label el;
226         private Xcls_RooProjectSettings  _this;
227
228
229             // my vars (def)
230
231         // ctor
232         public Xcls_label_global(Xcls_RooProjectSettings _owner )
233         {
234             _this = _owner;
235             _this.label_global = this;
236             this.el = new Gtk.Label( "Global" );
237
238             // my vars (dec)
239
240             // set gobject values
241         }
242
243         // user defined functions
244     }
245
246     public class Xcls_label_database : Object
247     {
248         public Gtk.Label el;
249         private Xcls_RooProjectSettings  _this;
250
251
252             // my vars (def)
253
254         // ctor
255         public Xcls_label_database(Xcls_RooProjectSettings _owner )
256         {
257             _this = _owner;
258             _this.label_database = this;
259             this.el = new Gtk.Label( "Database" );
260
261             // my vars (dec)
262
263             // set gobject values
264         }
265
266         // user defined functions
267     }
268
269     public class Xcls_Box8 : Object
270     {
271         public Gtk.Box el;
272         private Xcls_RooProjectSettings  _this;
273
274
275             // my vars (def)
276
277         // ctor
278         public Xcls_Box8(Xcls_RooProjectSettings _owner )
279         {
280             _this = _owner;
281             this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
282
283             // my vars (dec)
284
285             // set gobject values
286             this.el.homogeneous = false;
287             var child_0 = new Xcls_path( _this );
288             child_0.ref();
289             this.el.pack_start (  child_0.el , false,false,0 );
290             var child_1 = new Xcls_Box10( _this );
291             child_1.ref();
292             this.el.pack_start (  child_1.el , false,false,0 );
293             var child_2 = new Xcls_Box13( _this );
294             child_2.ref();
295             this.el.pack_start (  child_2.el , false,false,0 );
296             var child_3 = new Xcls_Label16( _this );
297             child_3.ref();
298             this.el.pack_start (  child_3.el , false,false,0 );
299             var child_4 = new Xcls_ScrolledWindow17( _this );
300             child_4.ref();
301             this.el.pack_start (  child_4.el , true,true,0 );
302         }
303
304         // user defined functions
305     }
306     public class Xcls_path : Object
307     {
308         public Gtk.Label el;
309         private Xcls_RooProjectSettings  _this;
310
311
312             // my vars (def)
313
314         // ctor
315         public Xcls_path(Xcls_RooProjectSettings _owner )
316         {
317             _this = _owner;
318             _this.path = this;
319             this.el = new Gtk.Label( "filename" );
320
321             // my vars (dec)
322
323             // set gobject values
324             this.el.margin = 3;
325             this.el.xalign = 0f;
326         }
327
328         // user defined functions
329     }
330
331     public class Xcls_Box10 : Object
332     {
333         public Gtk.Box el;
334         private Xcls_RooProjectSettings  _this;
335
336
337             // my vars (def)
338
339         // ctor
340         public Xcls_Box10(Xcls_RooProjectSettings _owner )
341         {
342             _this = _owner;
343             this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
344
345             // my vars (dec)
346
347             // set gobject values
348             this.el.homogeneous = false;
349             this.el.expand = false;
350             var child_0 = new Xcls_Label11( _this );
351             child_0.ref();
352             this.el.pack_start (  child_0.el , false,false,0 );
353             var child_1 = new Xcls_base_template( _this );
354             child_1.ref();
355             this.el.add (  child_1.el  );
356         }
357
358         // user defined functions
359     }
360     public class Xcls_Label11 : Object
361     {
362         public Gtk.Label el;
363         private Xcls_RooProjectSettings  _this;
364
365
366             // my vars (def)
367
368         // ctor
369         public Xcls_Label11(Xcls_RooProjectSettings _owner )
370         {
371             _this = _owner;
372             this.el = new Gtk.Label( "HTML template file" );
373
374             // my vars (dec)
375
376             // set gobject values
377             this.el.margin = 3;
378         }
379
380         // user defined functions
381     }
382
383     public class Xcls_base_template : Object
384     {
385         public Gtk.Entry el;
386         private Xcls_RooProjectSettings  _this;
387
388
389             // my vars (def)
390
391         // ctor
392         public Xcls_base_template(Xcls_RooProjectSettings _owner )
393         {
394             _this = _owner;
395             _this.base_template = this;
396             this.el = new Gtk.Entry();
397
398             // my vars (dec)
399
400             // set gobject values
401         }
402
403         // user defined functions
404     }
405
406
407     public class Xcls_Box13 : Object
408     {
409         public Gtk.Box el;
410         private Xcls_RooProjectSettings  _this;
411
412
413             // my vars (def)
414
415         // ctor
416         public Xcls_Box13(Xcls_RooProjectSettings _owner )
417         {
418             _this = _owner;
419             this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
420
421             // my vars (dec)
422
423             // set gobject values
424             this.el.homogeneous = false;
425             this.el.expand = false;
426             var child_0 = new Xcls_Label14( _this );
427             child_0.ref();
428             this.el.pack_start (  child_0.el , false,false,0 );
429             var child_1 = new Xcls_rootURL( _this );
430             child_1.ref();
431             this.el.add (  child_1.el  );
432         }
433
434         // user defined functions
435     }
436     public class Xcls_Label14 : Object
437     {
438         public Gtk.Label el;
439         private Xcls_RooProjectSettings  _this;
440
441
442             // my vars (def)
443
444         // ctor
445         public Xcls_Label14(Xcls_RooProjectSettings _owner )
446         {
447             _this = _owner;
448             this.el = new Gtk.Label( "root URL" );
449
450             // my vars (dec)
451
452             // set gobject values
453             this.el.margin = 3;
454         }
455
456         // user defined functions
457     }
458
459     public class Xcls_rootURL : Object
460     {
461         public Gtk.Entry el;
462         private Xcls_RooProjectSettings  _this;
463
464
465             // my vars (def)
466
467         // ctor
468         public Xcls_rootURL(Xcls_RooProjectSettings _owner )
469         {
470             _this = _owner;
471             _this.rootURL = this;
472             this.el = new Gtk.Entry();
473
474             // my vars (dec)
475
476             // set gobject values
477         }
478
479         // user defined functions
480     }
481
482
483     public class Xcls_Label16 : Object
484     {
485         public Gtk.Label el;
486         private Xcls_RooProjectSettings  _this;
487
488
489             // my vars (def)
490
491         // ctor
492         public Xcls_Label16(Xcls_RooProjectSettings _owner )
493         {
494             _this = _owner;
495             this.el = new Gtk.Label( "HTML To insert at end of <HEAD>" );
496
497             // my vars (dec)
498
499             // set gobject values
500         }
501
502         // user defined functions
503     }
504
505     public class Xcls_ScrolledWindow17 : Object
506     {
507         public Gtk.ScrolledWindow el;
508         private Xcls_RooProjectSettings  _this;
509
510
511             // my vars (def)
512
513         // ctor
514         public Xcls_ScrolledWindow17(Xcls_RooProjectSettings _owner )
515         {
516             _this = _owner;
517             this.el = new Gtk.ScrolledWindow( null, null );
518
519             // my vars (dec)
520
521             // set gobject values
522             var child_0 = new Xcls_view( _this );
523             child_0.ref();
524             this.el.add (  child_0.el  );
525         }
526
527         // user defined functions
528     }
529     public class Xcls_view : Object
530     {
531         public Gtk.SourceView el;
532         private Xcls_RooProjectSettings  _this;
533
534
535             // my vars (def)
536
537         // ctor
538         public Xcls_view(Xcls_RooProjectSettings _owner )
539         {
540             _this = _owner;
541             _this.view = this;
542             this.el = new Gtk.SourceView();
543
544             // my vars (dec)
545
546             // init method
547
548             var description =   Pango.FontDescription.from_string("monospace");
549                 description.set_size(9000);
550                 this.el.override_font(description);
551
552             //listeners
553             this.el.key_release_event.connect( ( event) =>{
554                 if (event.keyval != 115) {
555                     return false;
556                      
557                 }
558                 if   ( (event.state & Gdk.ModifierType.CONTROL_MASK ) < 1 ) {
559                     return false;
560                 }
561                  var buf =    this.el.get_buffer();
562                 Gtk.TextIter s;
563                 Gtk.TextIter e;
564                 buf.get_start_iter(out s);
565                 buf.get_end_iter(out e);
566                 _this.project.runhtml = buf.get_text(s,e,true);
567                 
568                       
569                 _this.buttonPressed("save");
570                  
571                 return false;
572                      
573             });
574         }
575
576         // user defined functions
577     }
578
579
580
581     public class Xcls_Box19 : Object
582     {
583         public Gtk.Box el;
584         private Xcls_RooProjectSettings  _this;
585
586
587             // my vars (def)
588
589         // ctor
590         public Xcls_Box19(Xcls_RooProjectSettings _owner )
591         {
592             _this = _owner;
593             this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
594
595             // my vars (dec)
596
597             // set gobject values
598             this.el.homogeneous = false;
599             var child_0 = new Xcls_Label20( _this );
600             child_0.ref();
601             this.el.pack_start (  child_0.el , false,false,0 );
602             var child_1 = new Xcls_database_DBTYPE( _this );
603             child_1.ref();
604             this.el.pack_start (  child_1.el , false,false,0 );
605             var child_2 = new Xcls_Label22( _this );
606             child_2.ref();
607             this.el.pack_start (  child_2.el , false,false,0 );
608             var child_3 = new Xcls_database_DBNAME( _this );
609             child_3.ref();
610             this.el.pack_start (  child_3.el , false,false,0 );
611             var child_4 = new Xcls_Label24( _this );
612             child_4.ref();
613             this.el.pack_start (  child_4.el , false,false,0 );
614             var child_5 = new Xcls_database_DBUSERNAME( _this );
615             child_5.ref();
616             this.el.pack_start (  child_5.el , false,false,0 );
617             var child_6 = new Xcls_Label26( _this );
618             child_6.ref();
619             this.el.pack_start (  child_6.el , false,false,0 );
620             var child_7 = new Xcls_database_DBPASSWORD( _this );
621             child_7.ref();
622             this.el.pack_start (  child_7.el , false,false,0 );
623             var child_8 = new Xcls_Button28( _this );
624             child_8.ref();
625             this.el.pack_start (  child_8.el , false,false,0 );
626             var child_9 = new Xcls_database_ERROR( _this );
627             child_9.ref();
628             this.el.pack_start (  child_9.el , false,false,0 );
629         }
630
631         // user defined functions
632     }
633     public class Xcls_Label20 : Object
634     {
635         public Gtk.Label el;
636         private Xcls_RooProjectSettings  _this;
637
638
639             // my vars (def)
640
641         // ctor
642         public Xcls_Label20(Xcls_RooProjectSettings _owner )
643         {
644             _this = _owner;
645             this.el = new Gtk.Label( "Type (eg. MySQL or PostgreSQL)" );
646
647             // my vars (dec)
648
649             // set gobject values
650             this.el.xalign = 0f;
651         }
652
653         // user defined functions
654     }
655
656     public class Xcls_database_DBTYPE : Object
657     {
658         public Gtk.Entry el;
659         private Xcls_RooProjectSettings  _this;
660
661
662             // my vars (def)
663
664         // ctor
665         public Xcls_database_DBTYPE(Xcls_RooProjectSettings _owner )
666         {
667             _this = _owner;
668             _this.database_DBTYPE = this;
669             this.el = new Gtk.Entry();
670
671             // my vars (dec)
672
673             // set gobject values
674
675             //listeners
676             this.el.key_press_event.connect( (ev) => {
677             
678                 if (ev.keyval == Gdk.Key.Tab) {
679                     _this.database_DBNAME.el.grab_focus();
680                     return true;
681                 }
682             
683             
684                 return false;
685             });
686         }
687
688         // user defined functions
689     }
690
691     public class Xcls_Label22 : Object
692     {
693         public Gtk.Label el;
694         private Xcls_RooProjectSettings  _this;
695
696
697             // my vars (def)
698
699         // ctor
700         public Xcls_Label22(Xcls_RooProjectSettings _owner )
701         {
702             _this = _owner;
703             this.el = new Gtk.Label( "Name" );
704
705             // my vars (dec)
706
707             // set gobject values
708             this.el.xalign = 0f;
709         }
710
711         // user defined functions
712     }
713
714     public class Xcls_database_DBNAME : Object
715     {
716         public Gtk.Entry el;
717         private Xcls_RooProjectSettings  _this;
718
719
720             // my vars (def)
721
722         // ctor
723         public Xcls_database_DBNAME(Xcls_RooProjectSettings _owner )
724         {
725             _this = _owner;
726             _this.database_DBNAME = this;
727             this.el = new Gtk.Entry();
728
729             // my vars (dec)
730
731             // set gobject values
732
733             //listeners
734             this.el.key_press_event.connect( (ev) => {
735             
736                 if (ev.keyval == Gdk.Key.Tab) {
737                     _this.database_DBUSERNAME.el.grab_focus();
738                     return true;
739                 }
740             
741             
742                 return false;
743             });
744         }
745
746         // user defined functions
747     }
748
749     public class Xcls_Label24 : Object
750     {
751         public Gtk.Label el;
752         private Xcls_RooProjectSettings  _this;
753
754
755             // my vars (def)
756
757         // ctor
758         public Xcls_Label24(Xcls_RooProjectSettings _owner )
759         {
760             _this = _owner;
761             this.el = new Gtk.Label( "Username" );
762
763             // my vars (dec)
764
765             // set gobject values
766             this.el.xalign = 0f;
767         }
768
769         // user defined functions
770     }
771
772     public class Xcls_database_DBUSERNAME : Object
773     {
774         public Gtk.Entry el;
775         private Xcls_RooProjectSettings  _this;
776
777
778             // my vars (def)
779
780         // ctor
781         public Xcls_database_DBUSERNAME(Xcls_RooProjectSettings _owner )
782         {
783             _this = _owner;
784             _this.database_DBUSERNAME = this;
785             this.el = new Gtk.Entry();
786
787             // my vars (dec)
788
789             // set gobject values
790
791             //listeners
792             this.el.key_press_event.connect( (ev) => {
793             
794                 if (ev.keyval == Gdk.Key.Tab) {
795                     _this.database_DBPASSWORD.el.grab_focus();
796                     return true;
797                 }
798             
799             
800                 return false;
801             });
802         }
803
804         // user defined functions
805     }
806
807     public class Xcls_Label26 : Object
808     {
809         public Gtk.Label el;
810         private Xcls_RooProjectSettings  _this;
811
812
813             // my vars (def)
814
815         // ctor
816         public Xcls_Label26(Xcls_RooProjectSettings _owner )
817         {
818             _this = _owner;
819             this.el = new Gtk.Label( "Password" );
820
821             // my vars (dec)
822
823             // set gobject values
824             this.el.xalign = 0f;
825         }
826
827         // user defined functions
828     }
829
830     public class Xcls_database_DBPASSWORD : Object
831     {
832         public Gtk.Entry el;
833         private Xcls_RooProjectSettings  _this;
834
835
836             // my vars (def)
837
838         // ctor
839         public Xcls_database_DBPASSWORD(Xcls_RooProjectSettings _owner )
840         {
841             _this = _owner;
842             _this.database_DBPASSWORD = this;
843             this.el = new Gtk.Entry();
844
845             // my vars (dec)
846
847             // set gobject values
848         }
849
850         // user defined functions
851     }
852
853     public class Xcls_Button28 : Object
854     {
855         public Gtk.Button el;
856         private Xcls_RooProjectSettings  _this;
857
858
859             // my vars (def)
860
861         // ctor
862         public Xcls_Button28(Xcls_RooProjectSettings _owner )
863         {
864             _this = _owner;
865             this.el = new Gtk.Button();
866
867             // my vars (dec)
868
869             // set gobject values
870             this.el.label = "Check Connection";
871
872             //listeners
873             this.el.clicked.connect( () => {
874             
875             
876               _this.database_ERROR.el.label    = "";
877                 Gda.Connection cnc;
878                 try {
879                     // assumes localhost...
880                      cnc = Gda.Connection.open_from_string (
881                                 _this.database_DBTYPE.el.get_text(),
882                                 "DB_NAME=" + _this.database_DBNAME.el.get_text(), 
883                                 "USERNAME=" + _this.database_DBUSERNAME.el.get_text() + 
884                                 ";PASSWORD=" + _this.database_DBPASSWORD.el.get_text(),
885                                 Gda.ConnectionOptions.NONE
886                         );
887                //} catch (Gda.ConnectionError ce) { 
888                //   _this.database_ERROR.el.label = ce.message;        
889                } catch(Gda.ConnectionError ue) {
890                   _this.database_ERROR.el.label = ue.message;
891                     return;
892                }  catch(Gda.ConfigError ue) {
893                   _this.database_ERROR.el.label = ue.message;
894                     return;
895                }
896               _this.database_ERROR.el.label = "Connection Succeeded";
897                cnc.close();
898             });
899         }
900
901         // user defined functions
902     }
903
904     public class Xcls_database_ERROR : Object
905     {
906         public Gtk.Label el;
907         private Xcls_RooProjectSettings  _this;
908
909
910             // my vars (def)
911
912         // ctor
913         public Xcls_database_ERROR(Xcls_RooProjectSettings _owner )
914         {
915             _this = _owner;
916             _this.database_ERROR = this;
917             this.el = new Gtk.Label( " " );
918
919             // my vars (dec)
920
921             // set gobject values
922             this.el.margin = 3;
923             this.el.xalign = 0f;
924         }
925
926         // user defined functions
927     }
928
929
930
931 }