1 static NewBranch _NewBranch;
3 public class NewBranch : Object
6 private NewBranch _this;
8 public static NewBranch singleton()
10 if (_NewBranch == null) {
11 _NewBranch= new NewBranch();
15 public Xcls_projectsel projectsel;
16 public Xcls_prcellrenderer prcellrenderer;
17 public Xcls_prmodel prmodel;
18 public Xcls_ticketsel ticketsel;
19 public Xcls_dbcellrenderer dbcellrenderer;
20 public Xcls_dbmodel dbmodel;
21 public Xcls_name name;
22 public Xcls_btn_not_me btn_not_me;
23 public Xcls_btn_closed btn_closed;
24 public Xcls_scrolled_window scrolled_window;
25 public Xcls_view view;
30 public Gee.ArrayList<GitMonitorQueue> queue;
36 this.el = new Gtk.Dialog();
44 this.el.title = "Create a working branch ";
45 this.el.default_height = 200;
46 this.el.default_width = 500;
47 this.el.deletable = true;
49 var child_0 = new Xcls_Box2( _this );
51 this.el.get_content_area().add ( child_0.el );
54 this.el.delete_event.connect( (self, event) => {
59 this.el.response.connect( (self, response_id) => {
61 GLib.debug("got %d", (int) response_id);
62 if (response_id < 1) {
68 // have they selected a ticket..
69 // make that the current active ticket?
70 // we really need to store locally what ticket is being worked on..
71 // in theory we could be working on multiple project and not merging..
72 // -- each repo would have their active ticket (only one per repo)
73 // -- so we could just store that in there
74 // -- initial load can check the contents of the ticket files on first scan.
75 var ticket_id = _this.ticketsel.selectedTicketId();
77 if (this.repo != null) {
78 var bn = _this.name.el.get_text();
80 var res = this.repo.setActiveTicket(
81 RooTicket.singleton().getById(ticket_id != "" ? ticket_id : "-1"), bn
84 // start the monitoring..
85 GitMonitor.gitmonitor.start();
101 // user defined functions
102 public void show ( GitRepo repo, Gee.ArrayList<GitMonitorQueue> queue, string tid = "" )
104 // this.el.set_gravity(Gdk.Gravity.NORTH);
105 if (this.running) { // should not happen!!
106 GLib.error("new branch show called, when already being displayed?");
111 GitMonitor.gitmonitor.stop();
117 this.el.move((Gdk.Screen.width() / 2)- 250 ,0);
118 this.el.set_default_size( 500,200); // not sure why it grows..
119 GLib.debug("Loading tickets");
123 this.el.set_keep_above(true);
126 var curproj = RooTicket.singleton().getProjectByRepo(this.repo);
127 _this.prmodel.loadProjects(curproj == null ? "" : curproj.id);
129 _this.dbmodel.loadTickets(curproj == null ? "": curproj.id, tid);
131 var name = RooTicket.singleton().usernameLocal();
132 var ticket = RooTicket.singleton().getById(tid);
133 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
139 public class Xcls_Box2 : Object
142 private NewBranch _this;
148 public Xcls_Box2(NewBranch _owner )
151 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
155 // set gobject values
156 var child_0 = new Xcls_Table3( _this );
158 this.el.pack_start ( child_0.el , false,false,0 );
159 var child_1 = new Xcls_scrolled_window( _this );
161 this.el.add ( child_1.el );
164 // user defined functions
166 public class Xcls_Table3 : Object
169 private NewBranch _this;
175 public Xcls_Table3(NewBranch _owner )
178 this.el = new Gtk.Table( 5, 5, true );
182 // set gobject values
183 this.el.expand = false;
185 this.el.column_spacing = 4;
186 this.el.vexpand = false;
187 var child_0 = new Xcls_Label4( _this );
189 this.el.attach_defaults ( child_0.el , 0,1,0,1 );
190 var child_1 = new Xcls_Label5( _this );
192 this.el.attach_defaults ( child_1.el , 1,2,0,1 );
193 var child_2 = new Xcls_projectsel( _this );
195 this.el.attach_defaults ( child_2.el , 0,1,1,2 );
196 var child_3 = new Xcls_ticketsel( _this );
198 this.el.attach_defaults ( child_3.el , 1,4,1,2 );
199 var child_4 = new Xcls_Button12( _this );
201 this.el.attach_defaults ( child_4.el , 4,5,1,2 );
202 var child_5 = new Xcls_Label13( _this );
204 this.el.attach_defaults ( child_5.el , 0,1,3,4 );
205 var child_6 = new Xcls_name( _this );
207 this.el.attach_defaults ( child_6.el , 0,4,4,5 );
208 var child_7 = new Xcls_Button15( _this );
210 this.el.attach_defaults ( child_7.el , 4,5,4,5 );
211 var child_8 = new Xcls_Box16( _this );
213 this.el.attach_defaults ( child_8.el , 0,5,2,3 );
216 // user defined functions
218 public class Xcls_Label4 : Object
221 private NewBranch _this;
227 public Xcls_Label4(NewBranch _owner )
230 this.el = new Gtk.Label( "Project" );
234 // set gobject values
235 this.el.halign = Gtk.Align.START;
236 this.el.justify = Gtk.Justification.RIGHT;
237 this.el.visible = true;
240 // user defined functions
243 public class Xcls_Label5 : Object
246 private NewBranch _this;
252 public Xcls_Label5(NewBranch _owner )
255 this.el = new Gtk.Label( "Ticket" );
259 // set gobject values
260 this.el.halign = Gtk.Align.START;
261 this.el.visible = true;
264 // user defined functions
267 public class Xcls_projectsel : Object
269 public Gtk.ComboBox el;
270 private NewBranch _this;
277 public Xcls_projectsel(NewBranch _owner )
280 _this.projectsel = this;
281 this.el = new Gtk.ComboBox.with_entry();
284 this.loading = false;
286 // set gobject values
287 var child_0 = new Xcls_prcellrenderer( _this );
289 this.el.pack_start ( child_0.el , true );
290 var child_1 = new Xcls_prmodel( _this );
292 this.el.set_model ( child_1.el );
296 this.el.set_entry_text_column(1);
299 this.el.changed.connect( () => {
303 var project_id = this.selectedProjectId();
304 _this.dbmodel.loadTickets(project_id);
307 /*if (this.loading) {
310 var ticket_id = this.selectedTicketId();
312 var name = RooTicket.singleton().usernameLocal();
314 if (ticket_id == "" || ticket_id == null) {
316 var dt = new DateTime.now_local();
317 _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
322 var ticket = RooTicket.singleton().getById(ticket_id);
324 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
326 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
331 // user defined functions
332 public string selectedProjectId () {
337 this.el.get_active_iter (out iter);
338 _this.prmodel.el.get_value (iter, 0, out val1);
341 return (string) val1;
348 public class Xcls_prcellrenderer : Object
350 public Gtk.CellRendererText el;
351 private NewBranch _this;
357 public Xcls_prcellrenderer(NewBranch _owner )
360 _this.prcellrenderer = this;
361 this.el = new Gtk.CellRendererText();
365 // set gobject values
368 // user defined functions
371 public class Xcls_prmodel : Object
373 public Gtk.ListStore el;
374 private NewBranch _this;
380 public Xcls_prmodel(NewBranch _owner )
383 _this.prmodel = this;
384 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
388 // set gobject values
391 // user defined functions
392 public void loadProjects (string id) {
394 var rt = RooTicket.singleton();
397 _this.projectsel.loading = true;
406 el.set_value(iter, 0, "");
407 el.set_value(iter, 1, "-- select a project --");
409 _this.projectsel.el.set_active_iter(iter);
411 var projects = rt.projects;
412 foreach(var project in projects) {
416 el.set_value(iter, 0, project.id);
417 el.set_value(iter, 1, project.name );
418 if (id == project.id) {
419 _this.projectsel.el.set_active_iter(iter);
424 _this.projectsel.loading = false;
425 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
431 public class Xcls_ticketsel : Object
433 public Gtk.ComboBox el;
434 private NewBranch _this;
441 public Xcls_ticketsel(NewBranch _owner )
444 _this.ticketsel = this;
445 this.el = new Gtk.ComboBox.with_entry();
448 this.loading = false;
450 // set gobject values
451 var child_0 = new Xcls_dbcellrenderer( _this );
453 this.el.pack_start ( child_0.el , true );
454 var child_1 = new Xcls_dbmodel( _this );
456 this.el.set_model ( child_1.el );
460 //this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
461 this.el.set_entry_text_column(1);
464 this.el.changed.connect( () => {
468 var ticket_id = this.selectedTicketId();
470 var name = RooTicket.singleton().usernameLocal();
472 if (ticket_id == "" || ticket_id == null) {
474 var dt = new DateTime.now_local();
475 _this.name.el.set_text("wip_%s_%s".printf(name,dt.format("%Y_%b_%d")));
480 var ticket = RooTicket.singleton().getById(ticket_id);
482 _this.name.el.set_text("wip_%s_T%s_%s".printf(name,ticket.id, ticket.summaryToBranchName()));
484 //GLib.debug (//"Selection: %s, %s\n", (string) val1, (string) val2);
488 // user defined functions
489 public string selectedTicketId () {
494 this.el.get_active_iter (out iter);
495 _this.dbmodel.el.get_value (iter, 0, out val1);
498 return (string) val1;
505 public class Xcls_dbcellrenderer : Object
507 public Gtk.CellRendererText el;
508 private NewBranch _this;
514 public Xcls_dbcellrenderer(NewBranch _owner )
517 _this.dbcellrenderer = this;
518 this.el = new Gtk.CellRendererText();
522 // set gobject values
525 // user defined functions
528 public class Xcls_dbmodel : Object
530 public Gtk.ListStore el;
531 private NewBranch _this;
537 public Xcls_dbmodel(NewBranch _owner )
540 _this.dbmodel = this;
541 this.el = new Gtk.ListStore( 2, typeof(string),typeof(string) );
545 // set gobject values
548 // user defined functions
549 public void loadTickets (string project_id , string tid = "") {
553 // fixme .. get project id from selection..
555 RooTicket.singleton().loadTickets(
557 _this.btn_not_me.el.active ? RooTicket.Who.ANYBODY : RooTicket.Who.ME,
558 _this.btn_closed.el.active ? RooTicket.Status.ALL : RooTicket.Status.ACTIVE
561 _this.ticketsel.loading = true;
570 el.set_value(iter, 0, "");
571 el.set_value(iter, 1, "-- select a ticket --");
573 _this.ticketsel.el.set_active_iter(iter);
574 var tickets = RooTicket.singleton().tickets;
575 foreach(var ticket in tickets) {
579 el.set_value(iter, 0, ticket.id);
580 el.set_value(iter, 1, "#%s [%s] %s".printf( ticket.id, ticket.project_id_name , ticket.summary));
582 if (ticket.id == tid) {
583 _this.ticketsel.el.set_active_iter(iter);
588 _this.ticketsel.loading = false;
589 //this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);
595 public class Xcls_Button12 : Object
597 public Gtk.Button el;
598 private NewBranch _this;
604 public Xcls_Button12(NewBranch _owner )
607 this.el = new Gtk.Button();
611 // set gobject values
612 this.el.expand = false;
613 this.el.label = "New Ticket";
616 this.el.clicked.connect( () => {
617 _this.el.response(-1);
618 Ticket.singleton().show(_this.repo);
623 // user defined functions
626 public class Xcls_Label13 : Object
629 private NewBranch _this;
635 public Xcls_Label13(NewBranch _owner )
638 this.el = new Gtk.Label( "Use this as branch name" );
642 // set gobject values
643 this.el.halign = Gtk.Align.START;
644 this.el.justify = Gtk.Justification.RIGHT;
645 this.el.xalign = 0.900000f;
648 // user defined functions
651 public class Xcls_name : Object
654 private NewBranch _this;
660 public Xcls_name(NewBranch _owner )
664 this.el = new Gtk.Entry();
668 // set gobject values
669 this.el.visible = true;
672 // user defined functions
675 public class Xcls_Button15 : Object
677 public Gtk.Button el;
678 private NewBranch _this;
684 public Xcls_Button15(NewBranch _owner )
687 this.el = new Gtk.Button();
691 // set gobject values
692 this.el.label = "Create Branch";
697 this.el.get_style_context().add_class("suggested-action");
701 this.el.clicked.connect( () => {
702 GLib.debug("fire response = 1");
703 _this.el.response(1);
707 // user defined functions
710 public class Xcls_Box16 : Object
713 private NewBranch _this;
719 public Xcls_Box16(NewBranch _owner )
722 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
726 // set gobject values
727 var child_0 = new Xcls_btn_not_me( _this );
729 this.el.add ( child_0.el );
730 var child_1 = new Xcls_btn_closed( _this );
732 this.el.add ( child_1.el );
733 var child_2 = new Xcls_Label19( _this );
735 this.el.add ( child_2.el );
738 // user defined functions
740 public class Xcls_btn_not_me : Object
742 public Gtk.CheckButton el;
743 private NewBranch _this;
749 public Xcls_btn_not_me(NewBranch _owner )
752 _this.btn_not_me = this;
753 this.el = new Gtk.CheckButton();
757 // set gobject values
758 this.el.label = "Show tickets not assigned to me";
761 this.el.toggled.connect( () => {
762 var project_id = _this.projectsel.selectedProjectId();
763 _this.dbmodel.loadTickets(project_id);
767 // user defined functions
770 public class Xcls_btn_closed : Object
772 public Gtk.CheckButton el;
773 private NewBranch _this;
779 public Xcls_btn_closed(NewBranch _owner )
782 _this.btn_closed = this;
783 this.el = new Gtk.CheckButton();
787 // set gobject values
788 this.el.label = "Show closed Tickets";
791 this.el.toggled.connect( () => {
792 var project_id = _this.projectsel.selectedProjectId();
793 _this.dbmodel.loadTickets(project_id);
798 // user defined functions
801 public class Xcls_Label19 : Object
804 private NewBranch _this;
810 public Xcls_Label19(NewBranch _owner )
813 this.el = new Gtk.Label( "<a href=\"refresh\">Refresh Ticket list</a>" );
817 // set gobject values
818 this.el.halign = Gtk.Align.END;
819 this.el.hexpand = true;
820 this.el.use_markup = true;
823 this.el.activate_link.connect( (uri) => {
824 if (uri == "refresh") {
825 var curproj = RooTicket.singleton().getProjectByRepo(_this.repo);
826 _this.prmodel.loadProjects(curproj == null ? "": curproj.id);
828 _this.dbmodel.loadTickets(curproj == null ? "": curproj.id);
834 // user defined functions
839 public class Xcls_scrolled_window : Object
841 public Gtk.ScrolledWindow el;
842 private NewBranch _this;
848 public Xcls_scrolled_window(NewBranch _owner )
851 _this.scrolled_window = this;
852 this.el = new Gtk.ScrolledWindow( null, null );
856 // set gobject values
857 var child_0 = new Xcls_view( _this );
859 this.el.add ( child_0.el );
864 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
868 // user defined functions
870 public class Xcls_view : Object
872 public WebKit.WebView el;
873 private NewBranch _this;
879 public Xcls_view(NewBranch _owner )
883 this.el = new WebKit.WebView();
893 this.el.load_changed.connect( (ev ) => {
894 if (ev != WebKit.LoadEvent.FINISHED) {
903 this.el.resource_load_started.connect( (resource, request) => {
904 print("Adding referrer header %s\n" , request.get_uri());
906 if (request.get_http_headers() != null) {
907 request.get_http_headers().remove("Referer");
908 request.get_http_headers().append("Referer", request.get_uri());
911 var settings = this.el.get_settings();
912 settings.set_user_agent( "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36" );
917 // this.el.resource_request_starting.connect( (p0, webres, netreq ) => {
918 // print("resource req. started %s\n", netreq.uri);
922 this.el.load_finished.connect( ( ) => {
928 WebKit.get_default_session().request_started.connect((message, socket) => {
929 Soup.URI uri = message.get_uri();
931 var host = uri.get_host ();
933 print("Adding header http://%s/\n", host);
934 message.request_headers.remove("Referer");
935 message.request_headers.append("Referer", "http://"+host+"/");
939 var sess = WebKit.get_default_session();
940 sess.user_agent= "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36";
945 this.cookie_file = "";
946 if (webkitpdf.opt_cookies != null) {
947 print("setting cookie %s\n",webkitpdf.opt_cookies);
949 var uri = new Soup.URI (webkitpdf.opt_url);
951 string[] cookies = webkitpdf.opt_cookies.split ("=", 2);
953 if(cookies.length > 1 ) {
956 var context = WebKit.WebContext.get_default();
957 var cookie_manager = context.get_cookie_manager();
958 cookie_manager.set_accept_policy(WebKit.CookieAcceptPolicy.NEVER);
959 string scheme = uri.get_scheme ();
962 FileIOStream iostream;
963 File file = File.new_tmp ("cookie-XXXXXX.txt", out iostream);
964 this.cookie_file = file.get_path ();
965 print("cookie tmp file name: %s\n", file.get_path ());
967 OutputStream ostream = iostream.output_stream;
968 DataOutputStream dostream = new DataOutputStream (ostream);
969 dostream.put_string ("%s\tTRUE\t/\t%s\t2147483647\t%s\t%s".printf(uri.get_host(),scheme == "http" ? "FALSE" : "TRUE",cookies[0],cookies[1]));
970 cookie_manager.set_persistent_storage(file.get_path(), WebKit.CookiePersistentStorage.TEXT);
972 stdout.printf ("Error: %s\n", e.message);
975 var cookie_jar = new Soup.CookieJar();
976 var cookie = new Soup.Cookie (cookies[0], cookies[1], uri.get_host(), "/", -1);
977 if(uri.get_scheme() =="https") {
978 cookie.set_secure(true);
980 cookie_jar.set_accept_policy(Soup.CookieJarAcceptPolicy.NEVER);
981 cookie_jar.add_cookie(cookie);
982 WebKit.get_default_session().add_feature(cookie_jar);
991 // user defined functions
992 public void printit () {
993 print("load_finsihed\n");
995 if (this.print_started) {
996 print("load_finsihed - already printing..%d %s\n", this.load_try, this.el.uri);
1005 this.print_started = true; // flag to stop double call.
1008 // inject any javascript if needed..
1009 if (webkitpdf.opt_inject_js != null) {
1011 print("injecting javascript files \n");
1012 foreach(var inject_js in webkitpdf.opt_inject_js) {
1013 print("inject? %s\n", inject_js);
1016 FileUtils.get_contents( inject_js, out str);
1017 } catch(FileError e) {
1018 print("Failed to inject %s\n", inject_js);
1022 GLib.MainLoop mainloop = new GLib.MainLoop();
1023 this.el.run_javascript.begin(str, null, (obj,res) => {
1029 this.el.execute_script(str);
1034 print("calling print in %d seconds\n", (int)webkitpdf.opt_delay);
1035 if (webkitpdf.opt_target_pdf != null) {
1036 GLib.Timeout.add_seconds(webkitpdf.opt_delay, () => {
1037 print("delay done URL: %s\n", this.el.uri);
1042 }, GLib.Priority.DEFAULT);
1048 print("PNG not supported in webkit2\n");
1052 GLib.Timeout.add_seconds(webkitpdf.opt_delay, () => {
1055 // ----------------- JPEG
1056 // resize the window...
1057 // window.document.documentElement.scrollHeight
1058 var scroll_height = (int) _this.view.el.get_dom_document().document_element.scroll_height;
1059 print("Scroll height %d\n", scroll_height);
1060 if (scroll_height> 1024 || webkitpdf.opt_width > 0 || webkitpdf.opt_height > 0 ) {
1061 var w = webkitpdf.opt_width > 0 ? webkitpdf.opt_width : 1200;
1062 var h = int.min(scroll_height, 6000);
1063 _this.scrolled_window.el.set_size_request( w, h);
1064 _this.el.resize (w+50, h+50);
1065 print("Resize to %d, %d\n", w,h);
1066 GLib.Timeout.add_seconds(webkitpdf.opt_delay > 0 ? webkitpdf.opt_delay : 1 , () => {
1069 }, GLib.Priority.DEFAULT);
1074 }, GLib.Priority.DEFAULT);
1080 public bool printpdf () {
1084 var list = Gtk.PaperSize.get_paper_sizes(false);
1085 var psetup = new Gtk.PageSetup();
1086 for(var i = 0; i < list.length(); i++ ) {
1087 var entry = list.nth_data(i).copy();
1088 if (entry.get_name() == "iso_a2") {
1089 psetup.set_paper_size(entry);
1096 var pe = new WebKit.PrintOperation(this.el);
1097 pe.set_page_setup(psetup);
1098 pe.finished.connect( () => {
1099 print("print completed\n");
1100 this.delete_cookiefile();
1105 var ps = new Gtk.PrintSettings();
1106 ps.set_printer("Print to File");
1107 ps.set("output-file-format", "pdf");
1108 ps.set("output-uri", "file://" + webkitpdf.opt_target_pdf);
1111 pe.set_print_settings(ps);
1118 var pe = new Gtk.PrintOperation();
1119 pe.export_filename = webkitpdf.opt_target_pdf;
1120 print("got callback for print\n");
1122 /*pe.failed.connect(() => {
1123 print("print failed\n");
1128 pe.done.connect(() => {
1129 print("print completed\n");
1130 this.delete_cookiefile();
1135 //pe.run_dialog(_this.el);
1141 pe.set_default_page_setup(psetup);
1142 print("Calling Print?\n");
1143 //pe.run_dialog(_this.el);
1150 this.el.get_main_frame().print_full(pe,Gtk.PrintOperationAction.EXPORT);
1159 public void printpng () {
1160 //var filename = "/tmp/test.pdf";
1161 //print("load_changed %d ?= %d\n", le, LoadEvent.FINISHED);
1163 //if (le != LoadEvent.FINISHED) {
1167 // what size is the documet.
1169 print("making screenshot\n");
1173 // fix vapi - get_snapshot add '?' to all null.
1174 var pixmap = _this.view.el.get_snapshot( null );
1180 // add out to gdkpixmap.get_size
1181 pixmap.get_size( out w , out h);
1182 var pixbuf = Gdk.pixbuf_get_from_drawable(null, pixmap, null , 0, 0, 0, 0, w, h);
1183 print("pixbuf size: %d x %d\n ", w,h);
1187 pixbuf.save(webkitpdf.opt_target_png, "png");
1188 print("Saved to %s\n", webkitpdf.opt_target_png);
1189 //view.get_snapshot.begin(WebKit.SnapshotRegion.FULL_DOCUMENT, WebKit.SnapshotOptions.NONE, null, (obj, res) => {
1190 // var sf = view.get_snapshot.end(res);
1192 // sf.write_to_png(Browser.opt_target_png);
1194 this.delete_cookiefile();
1202 public void delete_cookiefile () {
1203 if(this.cookie_file.length < 1 ){
1206 print("deleting tmp file %s\n",this.cookie_file);
1207 File file = File.new_for_path (this.cookie_file);
1209 if (file.query_exists () == true) {
1213 stdout.printf ("Error: %s\n", e.message);