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