841b2a34a2ed04f2dc089852834cf6cc87b0ecb4
[tilda-gobject.git] / tilda-terminal.c
1 #include "tilda.h"
2 #include "tilda-terminal.h"
3 #include "tilda-terminal-dbus-glue.h"
4
5 // FIXME: temporary helpers for gettext
6 // TODO:  remove these
7 #define _(X) X
8 #define N_(X) X
9
10 static void
11 tilda_terminal_dbus_register_object (TildaTerminal *tt)
12 {
13         gchar *object_path;
14
15         // Register this object with DBus
16         object_path = g_strdup_printf ("/net/sourceforge/Tilda/Window%d/Terminal%d",
17                                                                    tt->window_number, tt->number);
18         dbus_g_connection_register_g_object (dbus_connection, object_path, G_OBJECT(tt));
19         g_free (object_path);
20 }
21
22 /**
23  * Start the current tt->shell in the given TildaTerminal
24  * NOTE: this will kill whatever is running in the terminal,
25  * NOTE: and run the current tt->shell instead :)
26  * Return: TRUE if ok, FALSE otherwise
27  */
28 static gboolean
29 tilda_terminal_start_shell (TildaTerminal *tt)
30 {
31         gint ret;
32         gint argc;
33         gchar **argv;
34         GError *error = NULL;
35
36         /* Launch a custom command if tt->shell is set (not NULL) */
37         if (tt->shell)
38         {
39                 /* Try to parse the user's custom command */
40                 ret = g_shell_parse_argv (tt->shell, &argc, &argv, &error);
41
42                 if (ret == FALSE)
43                 {
44                         g_printerr (_("Problem parsing custom command: %s\n"), error->message);
45                         g_printerr (_("Launching default shell instead\n"));
46
47                         g_error_free (error);
48                         goto launch_default_shell;
49                 }
50
51                 /* Try to start the user's custom command */
52                 ret = vte_terminal_fork_command (VTE_TERMINAL(tt->vte_term),
53                                                                                  argv[0], /* Command */
54                                                                                  argv,    /* Arg Vector */
55                                                                                  NULL,    /* Env Vector */
56                                                                                  tt->working_directory, /* Start directory */
57                                                                                  TRUE,    /* Add to lastlog */
58                                                                                  TRUE,    /* Add to utmp */
59                                                                                  TRUE);   /* Add to wtmp */
60
61                 g_strfreev (argv);
62
63                 /* Check for error */
64                 if (ret == -1)
65                 {
66                         g_printerr (_("Unable to launch custom command: %s\n"), tt->shell);
67                         g_printerr (_("Launching default shell instead\n"));
68
69                         goto launch_default_shell;
70                 }
71
72                 return TRUE; /* SUCCESS: the early way out */
73         }
74
75 launch_default_shell:
76
77     ret = vte_terminal_fork_command (VTE_TERMINAL(tt->vte_term),
78                                                                          NULL, /* Command -- VTE will figure it out */
79                                                                          NULL, /* Arg Vector */
80                                                                          NULL, /* Env Vector */
81                                                                          tt->working_directory, /* Start Directory */
82                                                                          TRUE, /* Add to lastlog */
83                                                                          TRUE, /* Add to utmp */
84                                                                          TRUE);/* Add to wtmp */
85
86         if (ret == -1)
87         {
88                 g_printerr (_("Unable to launch default shell\n"));
89                 return FALSE;
90         }
91
92         return TRUE;
93 }
94
95 /*******************************************************************************
96  * All GObject stuff is below. You probably don't need to change this...
97  ******************************************************************************/
98
99 static GObjectClass *parent_class = NULL;
100
101 enum tilda_terminal_properties {
102         TILDA_TERMINAL_NUMBER = 1,
103         TILDA_TERMINAL_WINDOW_NUMBER,
104         TILDA_TERMINAL_TW,
105
106         /* All non-constructor-only properties */
107         TILDA_TERMINAL_BACKGROUND_IMAGE,
108         TILDA_TERMINAL_SHELL,
109         TILDA_TERMINAL_FONT,
110         TILDA_TERMINAL_TITLE,
111         TILDA_TERMINAL_WORKING_DIRECTORY,
112
113         TILDA_TERMINAL_SCROLLBACK_LINES,
114         TILDA_TERMINAL_TRANSPARENCY_PERCENT,
115
116         TILDA_TERMINAL_BACKSPACE_BINDING,
117         TILDA_TERMINAL_DELETE_BINDING,
118         TILDA_TERMINAL_DYNAMIC_TITLE,
119         TILDA_TERMINAL_EXIT_ACTION,
120
121         TILDA_TERMINAL_SCROLL_BACKGROUND,
122         TILDA_TERMINAL_SCROLL_ON_OUTPUT,
123         TILDA_TERMINAL_SCROLL_ON_KEYSTROKE,
124         TILDA_TERMINAL_ANTIALIASED,
125         TILDA_TERMINAL_ALLOW_BOLD_TEXT,
126         TILDA_TERMINAL_CURSOR_BLINKS,
127         TILDA_TERMINAL_AUDIBLE_BELL,
128         TILDA_TERMINAL_VISIBLE_BELL,
129         TILDA_TERMINAL_DOUBLE_BUFFERED,
130         TILDA_TERMINAL_MOUSE_AUTOHIDE,
131 };
132
133 static void
134 tilda_terminal_instance_init (GTypeInstance *instance,
135                                                           gpointer       g_class)
136 {
137         TildaTerminal *self = (TildaTerminal *) instance;
138
139         /* Initialize instance members and allocate any necessary memory here.
140          * NOTE: any constructor-time values will be set later. */
141         self->dispose_has_run = FALSE;
142         self->number = 0;
143
144         self->vte_term = vte_terminal_new ();
145         self->scrollbar = gtk_vscrollbar_new (VTE_TERMINAL(self->vte_term)->adjustment);
146         self->hbox = gtk_hbox_new (FALSE, 0);
147 }
148
149 static void
150 tilda_terminal_set_property (GObject      *object,
151                                                          guint         property_id,
152                                                          const GValue *value,
153                                                          GParamSpec   *pspec)
154 {
155         TildaTerminal *self = (TildaTerminal *) object;
156
157         switch (property_id) {
158
159                 case TILDA_TERMINAL_NUMBER:
160                         self->number = g_value_get_int (value);
161                         g_print ("terminal number: %d\n", self->number);
162                         break;
163
164                 case TILDA_TERMINAL_WINDOW_NUMBER:
165                         self->window_number = g_value_get_int (value);
166                         g_print ("terminal parent window number: %d\n", self->window_number);
167                         break;
168
169                 case TILDA_TERMINAL_TW:
170                         self->parent_window = g_value_get_pointer (value);
171                         g_print ("terminal parent window: 0x%x\n", self->parent_window);
172                         g_print ("terminal parent window number (direct): %d\n", TILDA_WINDOW(self->parent_window)->number);
173                         break;
174
175                 case TILDA_TERMINAL_BACKGROUND_IMAGE:
176                         g_free (self->background_image);
177                         self->background_image = g_value_dup_string (value);
178                         vte_terminal_set_background_image_file (VTE_TERMINAL(self->vte_term), self->background_image);
179                         g_print ("terminal back img: %s\n", self->background_image);
180                         break;
181
182                 case TILDA_TERMINAL_SHELL:
183                         g_free (self->shell);
184                         self->shell = g_value_dup_string (value);
185                         tilda_terminal_start_shell (self);
186                         g_print ("terminal shell: %s\n", self->shell);
187                         break;
188
189                 case TILDA_TERMINAL_FONT:
190                         g_free (self->font);
191                         self->font = g_value_dup_string (value);
192                         vte_terminal_set_font_from_string_full (VTE_TERMINAL(self->vte_term),
193                                                                                                         self->font,
194                                                                                                         self->antialiased);
195                         g_print ("terminal font: %s\n", self->font);
196                         break;
197
198                 case TILDA_TERMINAL_TITLE:
199                         g_free (self->title);
200                         self->title = g_value_dup_string (value);
201                         g_print ("terminal title: %s\n", self->title);
202                         break;
203
204                 case TILDA_TERMINAL_WORKING_DIRECTORY:
205                         g_free (self->working_directory);
206                         self->working_directory = g_value_dup_string (value);
207                         g_print ("terminal wrk dir: %s\n", self->working_directory);
208                         break;
209
210                 case TILDA_TERMINAL_SCROLLBACK_LINES:
211                         self->scrollback_lines = g_value_get_int (value);
212                         vte_terminal_set_scrollback_lines (VTE_TERMINAL(self->vte_term), self->scrollback_lines);
213                         g_print ("terminal scrollback lines: %d\n", self->scrollback_lines);
214                         break;
215
216                 case TILDA_TERMINAL_TRANSPARENCY_PERCENT:
217                         self->transparency_percent = g_value_get_int (value);
218                         g_print ("terminal transp percent: %d\n", self->transparency_percent);
219                         break;
220
221                 case TILDA_TERMINAL_BACKSPACE_BINDING:
222                         self->backspace_binding = g_value_get_int (value);
223                         vte_terminal_set_backspace_binding (VTE_TERMINAL(self->vte_term), self->backspace_binding);
224                         g_print ("terminal backspace key: %d\n", self->backspace_binding);
225                         break;
226
227                 case TILDA_TERMINAL_DELETE_BINDING:
228                         self->delete_binding = g_value_get_int (value);
229                         vte_terminal_set_delete_binding (VTE_TERMINAL(self->vte_term), self->delete_binding);
230                         g_print ("terminal delete key: %d\n", self->delete_binding);
231                         break;
232
233                 case TILDA_TERMINAL_DYNAMIC_TITLE:
234                         self->dynamic_title = g_value_get_int (value);
235                         g_print ("terminal dynamic title: %d\n", self->dynamic_title);
236                         break;
237
238                 case TILDA_TERMINAL_EXIT_ACTION:
239                         self->exit_action = g_value_get_int (value);
240                         g_print ("terminal exit action: %d\n", self->exit_action);
241                         break;
242
243                 case TILDA_TERMINAL_SCROLL_BACKGROUND:
244                         self->scroll_background = g_value_get_boolean (value);
245                         vte_terminal_set_scroll_background (VTE_TERMINAL(self->vte_term), self->scroll_background);
246                         g_print ("terminal scroll background: %d\n", self->scroll_background);
247                         break;
248
249                 case TILDA_TERMINAL_SCROLL_ON_OUTPUT:
250                         self->scroll_on_output = g_value_get_boolean (value);
251                         vte_terminal_set_scroll_on_output (VTE_TERMINAL(self->vte_term), self->scroll_on_output);
252                         g_print ("terminal scroll on output: %d\n", self->scroll_on_output);
253                         break;
254
255                 case TILDA_TERMINAL_SCROLL_ON_KEYSTROKE:
256                         self->scroll_on_keystroke = g_value_get_boolean (value);
257                         vte_terminal_set_scroll_on_keystroke (VTE_TERMINAL(self->vte_term), self->scroll_on_keystroke);
258                         g_print ("terminal scroll on keystroke: %d\n", self->scroll_on_keystroke);
259                         break;
260
261                 case TILDA_TERMINAL_ANTIALIASED:
262                         self->antialiased = g_value_get_boolean (value);
263                         vte_terminal_set_font_from_string_full (VTE_TERMINAL(self->vte_term),
264                                                                                                         self->font,
265                                                                                                         self->antialiased);
266                         g_print ("terminal antialiased: %d\n", self->antialiased);
267                         break;
268
269                 case TILDA_TERMINAL_ALLOW_BOLD_TEXT:
270                         self->allow_bold_text = g_value_get_boolean (value);
271                         vte_terminal_set_allow_bold (VTE_TERMINAL(self->vte_term), self->allow_bold_text);
272                         g_print ("terminal allow bold text: %d\n", self->allow_bold_text);
273                         break;
274
275                 case TILDA_TERMINAL_CURSOR_BLINKS:
276                         self->cursor_blinks = g_value_get_boolean (value);
277                         vte_terminal_set_cursor_blinks (VTE_TERMINAL(self->vte_term), self->cursor_blinks);
278                         g_print ("terminal cursor blinks: %d\n", self->cursor_blinks);
279                         break;
280
281                 case TILDA_TERMINAL_AUDIBLE_BELL:
282                         self->audible_bell = g_value_get_boolean (value);
283                         vte_terminal_set_audible_bell (VTE_TERMINAL(self->vte_term), self->audible_bell);
284                         g_print ("terminal audible bell: %d\n", self->audible_bell);
285                         break;
286
287                 case TILDA_TERMINAL_VISIBLE_BELL:
288                         self->visible_bell = g_value_get_boolean (value);
289                         vte_terminal_set_visible_bell (VTE_TERMINAL(self->vte_term), self->visible_bell);
290                         g_print ("terminal visible bell: %d\n", self->visible_bell);
291                         break;
292
293                 case TILDA_TERMINAL_DOUBLE_BUFFERED:
294                         self->double_buffered = g_value_get_boolean (value);
295                         gtk_widget_set_double_buffered (GTK_WIDGET(self->vte_term), self->double_buffered);
296                         g_print ("terminal double buffered: %d\n", self->double_buffered);
297                         break;
298
299                 case TILDA_TERMINAL_MOUSE_AUTOHIDE:
300                         self->mouse_autohide = g_value_get_boolean (value);
301                         vte_terminal_set_mouse_autohide (VTE_TERMINAL(self->vte_term), self->mouse_autohide);
302                         g_print ("terminal mouse autohide: %d\n", self->mouse_autohide);
303                         break;
304
305                 default:
306                         /* We don't have this property... */
307                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
308                         break;
309         }
310 }
311
312 static void
313 tilda_terminal_get_property (GObject    *object,
314                                                          guint       property_id,
315                                                          GValue     *value,
316                                                          GParamSpec *pspec)
317 {
318         TildaTerminal *self = (TildaTerminal *) object;
319
320         switch (property_id) {
321
322                 case TILDA_TERMINAL_NUMBER:
323                         g_value_set_int (value, self->number);
324                         break;
325
326                 case TILDA_TERMINAL_WINDOW_NUMBER:
327                         g_value_set_int (value, self->window_number);
328                         break;
329
330                 case TILDA_TERMINAL_TW:
331                         g_value_set_pointer (value, self->parent_window);
332                         break;
333
334                 case TILDA_TERMINAL_BACKGROUND_IMAGE:
335                         g_value_set_string (value, self->background_image);
336                         break;
337
338                 case TILDA_TERMINAL_SHELL:
339                         g_value_set_string (value, self->shell);
340                         break;
341
342                 case TILDA_TERMINAL_FONT:
343                         g_value_set_string (value, self->font);
344                         break;
345
346                 case TILDA_TERMINAL_TITLE:
347                         g_value_set_string (value, self->title);
348                         break;
349
350                 case TILDA_TERMINAL_WORKING_DIRECTORY:
351                         g_value_set_string (value, self->working_directory);
352                         break;
353
354                 case TILDA_TERMINAL_SCROLLBACK_LINES:
355                         g_value_set_int (value, self->scrollback_lines);
356                         break;
357
358                 case TILDA_TERMINAL_TRANSPARENCY_PERCENT:
359                         g_value_set_int (value, self->transparency_percent);
360                         break;
361
362                 case TILDA_TERMINAL_BACKSPACE_BINDING:
363                         g_value_set_int (value, self->backspace_binding);
364                         break;
365
366                 case TILDA_TERMINAL_DELETE_BINDING:
367                         g_value_set_int (value, self->delete_binding);
368                         break;
369
370                 case TILDA_TERMINAL_DYNAMIC_TITLE:
371                         g_value_set_int (value, self->dynamic_title);
372                         break;
373
374                 case TILDA_TERMINAL_EXIT_ACTION:
375                         g_value_set_int (value, self->exit_action);
376                         break;
377
378                 case TILDA_TERMINAL_SCROLL_BACKGROUND:
379                         g_value_set_boolean (value, self->scroll_background);
380                         break;
381
382                 case TILDA_TERMINAL_SCROLL_ON_OUTPUT:
383                         g_value_set_boolean (value, self->scroll_on_output);
384                         break;
385
386                 case TILDA_TERMINAL_SCROLL_ON_KEYSTROKE:
387                         g_value_set_boolean (value, self->scroll_on_keystroke);
388                         break;
389
390                 case TILDA_TERMINAL_ANTIALIASED:
391                         g_value_set_boolean (value, self->antialiased);
392                         break;
393
394                 case TILDA_TERMINAL_ALLOW_BOLD_TEXT:
395                         g_value_set_boolean (value, self->allow_bold_text);
396                         break;
397
398                 case TILDA_TERMINAL_CURSOR_BLINKS:
399                         g_value_set_boolean (value, self->cursor_blinks);
400                         break;
401
402                 case TILDA_TERMINAL_AUDIBLE_BELL:
403                         g_value_set_boolean (value, self->audible_bell);
404                         break;
405
406                 case TILDA_TERMINAL_VISIBLE_BELL:
407                         g_value_set_boolean (value, self->visible_bell);
408                         break;
409
410                 case TILDA_TERMINAL_DOUBLE_BUFFERED:
411                         g_value_set_boolean (value, self->double_buffered);
412                         break;
413
414                 case TILDA_TERMINAL_MOUSE_AUTOHIDE:
415                         g_value_set_boolean (value, self->mouse_autohide);
416                         break;
417
418                 default:
419                         /* We don't have this property... */
420                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
421                         break;
422         }
423 }
424
425 static GObject *
426 tilda_terminal_constructor (GType                  type,
427                                                         guint                  n_construct_properties,
428                                                         GObjectConstructParam *construct_properties)
429 {
430         GObject *obj;
431         TildaTerminal *self;
432
433         /* Invoke parent constructor */
434         TildaTerminalClass *klass;
435         klass = TILDA_TERMINAL_CLASS (g_type_class_peek (TILDA_TYPE_TERMINAL));
436         obj = parent_class->constructor (type,
437                                                                          n_construct_properties,
438                                                                          construct_properties);
439
440         /* Do other stuff here. The object is ready to go now, and all
441          * ctor properties have been set.
442          *
443          * TODO: This is the place to do DBus-init */
444         self = TILDA_TERMINAL(obj);
445
446         /* Pack into the hbox */
447         gtk_box_pack_end (GTK_BOX(self->hbox), self->scrollbar, FALSE, FALSE, 0);
448         gtk_box_pack_end (GTK_BOX(self->hbox), self->vte_term, TRUE, TRUE, 0);
449         gtk_widget_show (self->scrollbar);
450
451
452         g_signal_connect (G_OBJECT(self->vte_term), "child-exited",
453                                           G_CALLBACK(gtk_main_quit), self);
454
455         tilda_terminal_start_shell (self);
456         tilda_terminal_dbus_register_object (self);
457
458         return obj;
459 }
460
461 static void
462 tilda_terminal_dispose (GObject *obj)
463 {
464         TildaTerminal *self = (TildaTerminal *) obj;
465
466         /* We don't want to run dispose twice, so just return immediately */
467         if (self->dispose_has_run)
468                 return;
469
470         self->dispose_has_run = TRUE;
471
472         /*
473          * In dispose, you are supposed to free all types referenced from this
474          * object which might themselves hold a reference to self. Generally,
475          * the most simple solution is to unref all members on which you own a
476          * reference.
477          */
478
479         /* Chain up to the parent class */
480         G_OBJECT_CLASS (parent_class)->dispose (obj);
481 }
482
483 static void
484 tilda_terminal_finalize (GObject *obj)
485 {
486         TildaTerminal *self = (TildaTerminal *) obj;
487
488         /*
489          * Here, complete object destruction.
490          * You might not need to do much...
491          */
492
493         // TODO: g_free() any primitives here
494         g_free (self->background_image);
495         g_free (self->shell);
496         g_free (self->font);
497         g_free (self->title);
498         g_free (self->working_directory);
499
500
501         /* Chain up to the parent class */
502         G_OBJECT_CLASS (parent_class)->finalize (obj);
503 }
504
505 static void
506 tilda_terminal_class_init (gpointer g_class,
507                                                    gpointer g_class_data)
508 {
509         GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
510         TildaTerminalClass *klass = TILDA_TERMINAL_CLASS (g_class);
511         GParamSpec *pspec;
512
513         /* Hook our functions to this type */
514         gobject_class->set_property = tilda_terminal_set_property;
515         gobject_class->get_property = tilda_terminal_get_property;
516         gobject_class->dispose = tilda_terminal_dispose;
517         gobject_class->finalize = tilda_terminal_finalize;
518         gobject_class->constructor = tilda_terminal_constructor;
519
520         parent_class = g_type_class_peek_parent (klass);
521
522         /* Hook the TildaTerminal type into DBus */
523         dbus_g_object_type_install_info (tilda_terminal_get_type(), &dbus_glib_tilda_terminal_object_info);
524
525         /* Install all of the properties */
526         pspec = g_param_spec_int ("number",
527                                                           "Terminal number",
528                                                           "Set terminal's number",
529                                                           0,            // min value
530                                                           INT_MAX,      // max value
531                                                           0,            // def value
532                                                           G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
533
534         g_object_class_install_property (gobject_class,
535                                                                          TILDA_TERMINAL_NUMBER,
536                                                                          pspec);
537
538         pspec = g_param_spec_int ("window-number",
539                                                           "Number of the window to which this terminal belongs",
540                                                           "Set the number of the parent window",
541                                                           0,
542                                                           INT_MAX,
543                                                           0x0000beef,
544                                                           G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
545
546         g_object_class_install_property (gobject_class,
547                                                                          TILDA_TERMINAL_WINDOW_NUMBER,
548                                                                          pspec);
549
550         pspec = g_param_spec_pointer ("parent-window",
551                                                                   "Pointer to terminal's parent TildaWindow",
552                                                                   "Set the pointer to the terminal's parent TildaWindow",
553                                                                   G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
554
555         g_object_class_install_property (gobject_class,
556                                                                          TILDA_TERMINAL_TW,
557                                                                          pspec);
558
559         pspec = g_param_spec_string ("background-image",
560                                                                  "Terminal's background image",
561                                                                  "Get/Set terminal's background image",
562                                                                  NULL,
563                                                                  G_PARAM_READWRITE);
564
565         g_object_class_install_property (gobject_class,
566                                                                          TILDA_TERMINAL_BACKGROUND_IMAGE,
567                                                                          pspec);
568
569         pspec = g_param_spec_string ("shell",
570                                                                  "Terminal's shell",
571                                                                  "Get/Set terminal's shell",
572                                                                  NULL,
573                                                                  G_PARAM_READWRITE);
574
575         g_object_class_install_property (gobject_class,
576                                                                          TILDA_TERMINAL_SHELL,
577                                                                          pspec);
578
579         pspec = g_param_spec_string ("font",
580                                                                  "Terminal's font",
581                                                                  "Get/Set terminal's font",
582                                                                  NULL,
583                                                                  G_PARAM_READWRITE);
584
585         g_object_class_install_property (gobject_class,
586                                                                          TILDA_TERMINAL_FONT,
587                                                                          pspec);
588
589         pspec = g_param_spec_string ("title",
590                                                                  "Terminal's title",
591                                                                  "Get/Set terminal's title",
592                                                                  NULL,
593                                                                  G_PARAM_READWRITE);
594
595         g_object_class_install_property (gobject_class,
596                                                                          TILDA_TERMINAL_TITLE,
597                                                                          pspec);
598
599         pspec = g_param_spec_string ("working-directory",
600                                                                  "Terminal's initial working directory",
601                                                                  "Get/Set terminal's initial working directory",
602                                                                  NULL,
603                                                                  G_PARAM_READWRITE);
604
605         g_object_class_install_property (gobject_class,
606                                                                          TILDA_TERMINAL_WORKING_DIRECTORY,
607                                                                          pspec);
608
609         pspec = g_param_spec_int ("scrollback-lines",
610                                                           "Terminal's scrollback amount (lines)",
611                                                           "Get/Set terminal's scrollback amount",
612                                                           0,
613                                                           INT_MAX, // TODO: artificially limit this?
614                                                           1000,
615                                                           G_PARAM_READWRITE);
616
617         g_object_class_install_property (gobject_class,
618                                                                          TILDA_TERMINAL_SCROLLBACK_LINES,
619                                                                          pspec);
620
621         pspec = g_param_spec_int ("transparency-percent",
622                                                           "Terminal's transparency (percent)",
623                                                           "Get/Set terminal's transparency",
624                                                           0,
625                                                           100,
626                                                           0,
627                                                           G_PARAM_READWRITE);
628
629         g_object_class_install_property (gobject_class,
630                                                                          TILDA_TERMINAL_TRANSPARENCY_PERCENT,
631                                                                          pspec);
632
633         pspec = g_param_spec_int ("backspace-binding",
634                                                           "Terminal's backspace binding",
635                                                           "Get/Set terminal's backspace key binding",
636                                                           VTE_ERASE_AUTO,
637                                                           VTE_ERASE_DELETE_SEQUENCE,
638                                                           VTE_ERASE_AUTO,
639                                                           G_PARAM_READWRITE);
640
641         g_object_class_install_property (gobject_class,
642                                                                          TILDA_TERMINAL_BACKSPACE_BINDING,
643                                                                          pspec);
644
645         pspec = g_param_spec_int ("delete-binding",
646                                                           "Terminal's delete binding",
647                                                           "Get/Set terminal's delete key binding",
648                                                           VTE_ERASE_AUTO,
649                                                           VTE_ERASE_DELETE_SEQUENCE,
650                                                           VTE_ERASE_AUTO,
651                                                           G_PARAM_READWRITE);
652
653         g_object_class_install_property (gobject_class,
654                                                                          TILDA_TERMINAL_DELETE_BINDING,
655                                                                          pspec);
656
657         pspec = g_param_spec_int ("dynamic-title",
658                                                           "Terminal's dynamic title generation method",
659                                                           "Get/Set terminal's dynamic title generation method",
660                                                           0,
661                                                           INT_MAX,
662                                                           0,
663                                                           G_PARAM_READWRITE);
664
665         g_object_class_install_property (gobject_class,
666                                                                          TILDA_TERMINAL_DYNAMIC_TITLE,
667                                                                          pspec);
668
669         pspec = g_param_spec_int ("exit-action",
670                                                           "Terminal's action upon child exit",
671                                                           "Get/Set terminal's action upon child exit",
672                                                           0,
673                                                           INT_MAX,
674                                                           0,
675                                                           G_PARAM_READWRITE);
676
677         g_object_class_install_property (gobject_class,
678                                                                          TILDA_TERMINAL_EXIT_ACTION,
679                                                                          pspec);
680
681         pspec = g_param_spec_boolean ("scroll-background",
682                                                                   "Controls terminal's scrolling behavior",
683                                                                   "Get/Set terminal's scrolling behavior",
684                                                                   FALSE,
685                                                                   G_PARAM_READWRITE);
686
687         g_object_class_install_property (gobject_class,
688                                                                          TILDA_TERMINAL_SCROLL_BACKGROUND,
689                                                                          pspec);
690
691         pspec = g_param_spec_boolean ("scroll-on-output",
692                                                                   "Controls terminal's scrolling behavior on output",
693                                                                   "Get/Set terminal's scrolling behavior on output",
694                                                                   FALSE,
695                                                                   G_PARAM_READWRITE);
696
697         g_object_class_install_property (gobject_class,
698                                                                          TILDA_TERMINAL_SCROLL_ON_OUTPUT,
699                                                                          pspec);
700
701         pspec = g_param_spec_boolean ("scroll-on-keystroke",
702                                                                   "Controls the terminal's scrolling behavior on keystroke",
703                                                                   NULL, FALSE, G_PARAM_READWRITE);
704
705         g_object_class_install_property (gobject_class,
706                                                                          TILDA_TERMINAL_SCROLL_ON_KEYSTROKE,
707                                                                          pspec);
708
709         pspec = g_param_spec_boolean ("antialiased",
710                                                                   "Attempt to antialias fonts",
711                                                                   NULL, FALSE, G_PARAM_READWRITE);
712
713         g_object_class_install_property (gobject_class,
714                                                                          TILDA_TERMINAL_ANTIALIASED,
715                                                                          pspec);
716
717         pspec = g_param_spec_boolean ("allow-bold-text",
718                                                                   "Allow bold text",
719                                                                   NULL, FALSE, G_PARAM_READWRITE);
720
721         g_object_class_install_property (gobject_class,
722                                                                          TILDA_TERMINAL_ALLOW_BOLD_TEXT,
723                                                                          pspec);
724
725         pspec = g_param_spec_boolean ("cursor-blinks",
726                                                                   NULL, NULL, FALSE, G_PARAM_READWRITE);
727
728         g_object_class_install_property (gobject_class,
729                                                                          TILDA_TERMINAL_CURSOR_BLINKS,
730                                                                          pspec);
731
732         pspec = g_param_spec_boolean ("audible-bell",
733                                                                   NULL, NULL, FALSE, G_PARAM_READWRITE);
734
735         g_object_class_install_property (gobject_class,
736                                                                          TILDA_TERMINAL_AUDIBLE_BELL,
737                                                                          pspec);
738
739         pspec = g_param_spec_boolean ("visible-bell",
740                                                                   NULL, NULL, FALSE, G_PARAM_READWRITE);
741
742         g_object_class_install_property (gobject_class,
743                                                                          TILDA_TERMINAL_VISIBLE_BELL,
744                                                                          pspec);
745
746         pspec = g_param_spec_boolean ("double-buffered",
747                                                                   NULL, NULL, FALSE, G_PARAM_READWRITE);
748
749         g_object_class_install_property (gobject_class,
750                                                                          TILDA_TERMINAL_DOUBLE_BUFFERED,
751                                                                          pspec);
752
753         pspec = g_param_spec_boolean ("mouse-autohide",
754                                                                   NULL, NULL, FALSE, G_PARAM_READWRITE);
755
756         g_object_class_install_property (gobject_class,
757                                                                          TILDA_TERMINAL_MOUSE_AUTOHIDE,
758                                                                          pspec);
759 }
760
761 GType
762 tilda_terminal_get_type (void)
763 {
764         static GType type = 0;
765
766         if (type == 0)
767         {
768                 static const GTypeInfo info = {
769                         sizeof (TildaTerminalClass),
770                         NULL,   /* base_init */
771                         NULL,   /* base_finalize */
772                         tilda_terminal_class_init,      /* class_init */
773                         NULL,   /* class_finalize */
774                         NULL,   /* class_data */
775                         sizeof (TildaTerminal),
776                         0,              /* n_preallocs */
777                         tilda_terminal_instance_init,   /* instance_init */
778                 };
779
780                 type = g_type_register_static (G_TYPE_OBJECT,
781                                                                            "TildaTerminalType",
782                                                                            &info,
783                                                                            0);
784         }
785
786         return type;
787 }
788
789 #if 0
790
791 int main (int argc, char *argv[])
792 {
793         GObject *tt;
794         gint test_number = INT_MIN;
795         gchar *test_string = NULL;
796
797         /* Initialize the GObject type system */
798         g_type_init ();
799         gtk_init (&argc, &argv);
800
801         tt = g_object_new (TILDA_TYPE_TERMINAL, "number", 10, NULL);
802         g_object_get (G_OBJECT (tt), "number", &test_number, NULL);
803         g_assert (test_number == 10);
804
805         g_object_unref (G_OBJECT (tt));
806
807         tt = g_object_new (TILDA_TYPE_TERMINAL, "number", 22, NULL);
808         g_object_get (G_OBJECT (tt), "number", &test_number, NULL);
809         g_assert (test_number == 22);
810
811         g_object_set (G_OBJECT (tt), "font", "hello I'm a font");
812         g_object_set (G_OBJECT (tt), "font", "Bitstream Vera Sans Mono 13");
813
814         g_object_get (G_OBJECT (tt), "font", &test_string, NULL);
815         g_print ("Read Font: %s\n", test_string);
816         // NOTE: you MUST free the string!!!!
817         g_free (test_string);
818
819         g_object_set (G_OBJECT (tt), "transparency-percent", 50);
820
821         g_object_unref (G_OBJECT (tt));
822
823         return 0;
824 }
825
826 #endif
827
828 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */