2 #include "tilda-terminal.h"
3 #include "tilda-terminal-dbus-glue.h"
5 #define DINGUS1 "(((news|telnet|nttp|file|http|ftp|https)://)|(www|ftp)[-A-Za-z0-9]*\\.)[-A-Za-z0-9\\.]+(:[0-9]*)?"
6 #define DINGUS2 "(((news|telnet|nttp|file|http|ftp|https)://)|(www|ftp)[-A-Za-z0-9]*\\.)[-A-Za-z0-9\\.]+(:[0-9]*)?/[-A-Za-z0-9_\\$\\.\\+\\!\\*\\(\\),;:@&=\\?/~\\#\\%]*[^]'\\.}>\\) ,\\\"]"
10 tilda_terminal_dbus_register_object (TildaTerminal *tt)
13 debug_assert (TILDA_IS_TERMINAL(tt));
17 // Register this object with DBus
18 object_path = g_strdup_printf ("/net/sourceforge/Tilda/Window%d/Terminal%d",
19 tt->window_number, tt->number);
20 dbus_g_connection_register_g_object (dbus_connection, object_path, G_OBJECT(tt));
25 * Start the current tt->shell in the given TildaTerminal
26 * NOTE: this will kill whatever is running in the terminal,
27 * NOTE: and run the current tt->shell instead :)
28 * Return: TRUE if ok, FALSE otherwise
31 tilda_terminal_start_shell (TildaTerminal *tt)
34 debug_assert (TILDA_IS_TERMINAL(tt));
41 /* Launch a custom command if tt->shell is set (not NULL) */
44 /* Try to parse the user's custom command */
45 ret = g_shell_parse_argv (tt->shell, &argc, &argv, &error);
49 g_printerr (_("Problem parsing custom command: %s\n"), error->message);
50 g_printerr (_("Launching default shell instead\n"));
53 goto launch_default_shell;
56 /* Try to start the user's custom command */
57 ret = vte_terminal_fork_command (VTE_TERMINAL(tt->vte_term),
58 argv[0], /* Command */
59 argv, /* Arg Vector */
60 NULL, /* Env Vector */
61 tt->working_directory, /* Start directory */
62 TRUE, /* Add to lastlog */
63 TRUE, /* Add to utmp */
64 TRUE); /* Add to wtmp */
71 g_printerr (_("Unable to launch custom command: %s\n"), tt->shell);
72 g_printerr (_("Launching default shell instead\n"));
74 goto launch_default_shell;
77 return TRUE; /* SUCCESS: the early way out */
82 ret = vte_terminal_fork_command (VTE_TERMINAL(tt->vte_term),
83 NULL, /* Command -- VTE will figure it out */
84 NULL, /* Arg Vector */
85 NULL, /* Env Vector */
86 tt->working_directory, /* Start Directory */
87 TRUE, /* Add to lastlog */
88 TRUE, /* Add to utmp */
89 TRUE);/* Add to wtmp */
93 g_printerr (_("Unable to launch default shell\n"));
101 * Called when the child process running in the VteTerminal exits.
104 tilda_terminal_child_exited_cb (GtkWidget *widget, gpointer data)
107 debug_assert (GTK_IS_WIDGET(widget));
108 debug_assert (TILDA_IS_TERMINAL(data));
110 TildaTerminal *self = TILDA_TERMINAL(data);
112 /* These can stay here. They don't need to go into a header because
113 * they are only used at this point in the code. */
114 enum exit_actions { HOLD_TERMINAL_OPEN, RESTART_COMMAND, EXIT_TERMINAL };
116 /* Check the user's preference for what to do when the child terminal
117 * is closed. Take the appropriate action */
118 switch (self->exit_action)
121 tilda_window_remove_term (TILDA_WINDOW(self->parent_window), self->number);
123 case RESTART_COMMAND:
124 vte_terminal_feed (VTE_TERMINAL(self->vte_term), "\r\n\r\n", 4);
125 tilda_terminal_start_shell (self);
127 case HOLD_TERMINAL_OPEN:
135 * Called when the child window title changes. Determines if a new
136 * title needs to be put into the notebook's tab label.
139 tilda_terminal_window_title_changed_cb (GtkWidget *widget, gpointer data)
142 debug_assert (GTK_IS_WIDGET(widget));
143 debug_assert (TILDA_IS_TERMINAL(data));
145 TildaTerminal *self = TILDA_TERMINAL(data);
146 TildaWindow *parent_window = TILDA_WINDOW(self->parent_window);
148 const gchar *vte_title;
151 enum dynamic_titles { NOT_DISPLAYED, AFTER_INITIAL, BEFORE_INITIAL, REPLACE_INITIAL };
152 label = gtk_notebook_get_tab_label (GTK_NOTEBOOK(parent_window->notebook), self->hbox);
154 /* If we aren't using a dynamic title -- NOT_DISPLAYED -- then just
155 * set it to the static title and exit */
156 if (!self->dynamic_title)
158 gtk_label_set_text (GTK_LABEL(label), self->title);
162 /* Get the title from VTE */
163 vte_title = vte_terminal_get_window_title (VTE_TERMINAL (widget));
165 /* Take the appropriate action */
166 switch (self->dynamic_title)
168 case REPLACE_INITIAL:
169 new_title = g_strdup (vte_title);
173 new_title = g_strdup_printf ("%s - %s", vte_title, self->title);
177 new_title = g_strdup_printf ("%s - %s", self->title, vte_title);
181 debug_printf ("ERROR: Bad value of self->dynamic_title\n");
183 new_title = g_strdup(self->title);
187 gtk_label_set_text (GTK_LABEL(label), new_title);
192 * Gets called whenever there is a button-press event in the VteTerminal. It
193 * is used to open the user's web browser, for example.
196 tilda_terminal_button_press_cb (GtkWidget *widget,
197 GdkEventButton *event,
201 debug_assert (GTK_IS_WIDGET(widget));
202 debug_assert (TILDA_IS_TERMINAL(data));
203 debug_printf ("event->button = %d\n", event->button);
205 GError *error = NULL;
206 TildaTerminal *self = TILDA_TERMINAL(data);
207 VteTerminal *terminal = VTE_TERMINAL(self->vte_term);
208 gint tag, xpad, ypad;
209 gchar *match, *cmd, *web_browser_cmd;
210 gboolean ret = FALSE;
212 switch (event->button)
214 case 3: /* Right Click */
215 // FIXME: need to add this
216 //popup_menu (tt->tw, tt);
217 g_print ("FIXME: popup_menu() here\n");
220 case 2: /* Middle Click */
223 case 1: /* Left Click */
224 vte_terminal_get_padding (terminal, &xpad, &ypad);
225 match = vte_terminal_match_check (terminal,
226 (event->x - ypad) / terminal->char_width,
227 (event->y - ypad) / terminal->char_height,
230 /* Check if we can launch a web browser, and do so if possible */
231 if ((event->state & GDK_CONTROL_MASK) && match != NULL)
233 web_browser_cmd = g_strescape (self->web_browser, NULL);
234 cmd = g_strdup_printf ("%s %s", web_browser_cmd, match);
236 debug_printf ("Got a Ctrl+Left-Click -- match: '%s' tag: %d\n", match, tag);
237 debug_printf ("Launching command: '%s'\n", cmd);
239 ret = g_spawn_command_line_async(cmd, &error);
241 /* Check that the command launched */
244 g_printerr (_("Failed to launch web browser command: `%s'\n"), cmd);
245 g_printerr (_("Error message: %s\n"), error->message);
248 /* Free allocated memory */
249 g_free (web_browser_cmd);
253 /* Always free match if it is non NULL */
265 * Set the given TildaTerminal to the appropriate transparency level
266 * based on the self->transparency_percent member. */
268 tilda_terminal_set_transparent (TildaTerminal *self)
271 debug_assert (TILDA_IS_TERMINAL(self));
273 TildaWindow *parent_window = TILDA_WINDOW(self->parent_window);
276 /* Convert the transparency to VTE's format */
277 temp = ((gdouble) self->transparency_percent) / 100.0;
279 if (self->transparency_percent > 0)
281 vte_terminal_set_background_saturation (VTE_TERMINAL(self->vte_term), temp);
282 vte_terminal_set_opacity (VTE_TERMINAL(self->vte_term), (1.0 - temp) * 0xffff);
284 /* Use fake transparency if necessary */
285 vte_terminal_set_background_transparent (VTE_TERMINAL(self->vte_term),
286 !parent_window->have_real_transparency);
290 /* Turn off transparency */
291 vte_terminal_set_background_saturation (VTE_TERMINAL(self->vte_term), 0);
292 vte_terminal_set_opacity (VTE_TERMINAL(self->vte_term), 0xffff);
293 vte_terminal_set_background_transparent (VTE_TERMINAL(self->vte_term), FALSE);
297 * Set the scrollbar position of the given TildaTerminal to
298 * the value in self->scrollbar_position.
301 tilda_terminal_set_scrollbar_position (TildaTerminal *self)
304 debug_assert (TILDA_IS_TERMINAL(self));
306 enum scrollbar_positions { DISABLED, LEFT, RIGHT };
307 switch (self->scrollbar_position)
310 gtk_box_reorder_child (GTK_BOX(self->hbox), self->scrollbar, 0);
311 gtk_widget_show (self->scrollbar);
315 gtk_box_reorder_child (GTK_BOX(self->hbox), self->scrollbar, 1);
316 gtk_widget_show (self->scrollbar);
320 debug_printf ("ERROR: Bad scrollbar position\n");
322 gtk_widget_hide (self->scrollbar);
327 /*******************************************************************************
328 * All GObject stuff is below. You probably don't need to change this...
329 ******************************************************************************/
331 static GObjectClass *parent_class = NULL;
333 enum tilda_terminal_properties {
334 TILDA_TERMINAL_NUMBER = 1,
335 TILDA_TERMINAL_WINDOW_NUMBER,
338 /* All non-constructor-only properties */
339 TILDA_TERMINAL_BACKGROUND_IMAGE,
340 TILDA_TERMINAL_SHELL,
342 TILDA_TERMINAL_TITLE,
343 TILDA_TERMINAL_WORKING_DIRECTORY,
344 TILDA_TERMINAL_WEB_BROWSER,
346 TILDA_TERMINAL_SCROLLBACK_LINES,
347 TILDA_TERMINAL_TRANSPARENCY_PERCENT,
349 TILDA_TERMINAL_BACKSPACE_BINDING,
350 TILDA_TERMINAL_DELETE_BINDING,
351 TILDA_TERMINAL_DYNAMIC_TITLE,
352 TILDA_TERMINAL_EXIT_ACTION,
353 TILDA_TERMINAL_SCROLLBAR_POSITION,
355 TILDA_TERMINAL_SCROLL_BACKGROUND,
356 TILDA_TERMINAL_SCROLL_ON_OUTPUT,
357 TILDA_TERMINAL_SCROLL_ON_KEYSTROKE,
358 TILDA_TERMINAL_ANTIALIASED,
359 TILDA_TERMINAL_ALLOW_BOLD_TEXT,
360 TILDA_TERMINAL_CURSOR_BLINKS,
361 TILDA_TERMINAL_AUDIBLE_BELL,
362 TILDA_TERMINAL_VISIBLE_BELL,
363 TILDA_TERMINAL_DOUBLE_BUFFERED,
364 TILDA_TERMINAL_MOUSE_AUTOHIDE,
368 tilda_terminal_instance_init (GTypeInstance *instance,
373 TildaTerminal *self = (TildaTerminal *) instance;
375 /* Initialize instance members and allocate any necessary memory here.
376 * NOTE: any constructor-time values will be set later. */
377 self->dispose_has_run = FALSE;
380 self->vte_term = vte_terminal_new ();
381 self->scrollbar = gtk_vscrollbar_new (VTE_TERMINAL(self->vte_term)->adjustment);
382 self->hbox = gtk_hbox_new (FALSE, 0);
386 tilda_terminal_set_property (GObject *object,
391 TildaTerminal *self = (TildaTerminal *) object;
393 switch (property_id) {
395 case TILDA_TERMINAL_NUMBER:
396 self->number = g_value_get_int (value);
397 debug_printf ("terminal number: %d\n", self->number);
400 case TILDA_TERMINAL_WINDOW_NUMBER:
401 self->window_number = g_value_get_int (value);
402 debug_printf ("terminal parent window number: %d\n", self->window_number);
405 case TILDA_TERMINAL_TW:
406 self->parent_window = g_value_get_pointer (value);
407 debug_printf ("terminal parent window: 0x%x\n", self->parent_window);
410 case TILDA_TERMINAL_BACKGROUND_IMAGE:
411 g_free (self->background_image);
412 self->background_image = g_value_dup_string (value);
413 vte_terminal_set_background_image_file (VTE_TERMINAL(self->vte_term), self->background_image);
414 debug_printf ("terminal back img: %s\n", self->background_image);
417 case TILDA_TERMINAL_SHELL:
418 g_free (self->shell);
419 self->shell = g_value_dup_string (value);
420 tilda_terminal_start_shell (self);
421 debug_printf ("terminal shell: %s\n", self->shell);
424 case TILDA_TERMINAL_FONT:
426 self->font = g_value_dup_string (value);
427 vte_terminal_set_font_from_string_full (VTE_TERMINAL(self->vte_term),
430 debug_printf ("terminal font: %s\n", self->font);
433 case TILDA_TERMINAL_TITLE:
434 g_free (self->title);
435 self->title = g_value_dup_string (value);
436 debug_printf ("terminal title: %s\n", self->title);
439 case TILDA_TERMINAL_WORKING_DIRECTORY:
440 g_free (self->working_directory);
441 self->working_directory = g_value_dup_string (value);
442 debug_printf ("terminal wrk dir: %s\n", self->working_directory);
445 case TILDA_TERMINAL_WEB_BROWSER:
446 g_free (self->web_browser);
447 self->web_browser = g_value_dup_string (value);
448 debug_printf ("terminal web browser: %s\n", self->web_browser);
451 case TILDA_TERMINAL_SCROLLBACK_LINES:
452 self->scrollback_lines = g_value_get_int (value);
453 vte_terminal_set_scrollback_lines (VTE_TERMINAL(self->vte_term), self->scrollback_lines);
454 debug_printf ("terminal scrollback lines: %d\n", self->scrollback_lines);
457 case TILDA_TERMINAL_TRANSPARENCY_PERCENT:
458 self->transparency_percent = g_value_get_int (value);
459 tilda_terminal_set_transparent (self);
460 debug_printf ("terminal transp percent: %d\n", self->transparency_percent);
463 case TILDA_TERMINAL_BACKSPACE_BINDING:
464 self->backspace_binding = g_value_get_int (value);
465 vte_terminal_set_backspace_binding (VTE_TERMINAL(self->vte_term), self->backspace_binding);
466 debug_printf ("terminal backspace key: %d\n", self->backspace_binding);
469 case TILDA_TERMINAL_DELETE_BINDING:
470 self->delete_binding = g_value_get_int (value);
471 vte_terminal_set_delete_binding (VTE_TERMINAL(self->vte_term), self->delete_binding);
472 debug_printf ("terminal delete key: %d\n", self->delete_binding);
475 case TILDA_TERMINAL_DYNAMIC_TITLE:
476 self->dynamic_title = g_value_get_int (value);
477 debug_printf ("terminal dynamic title: %d\n", self->dynamic_title);
480 case TILDA_TERMINAL_EXIT_ACTION:
481 self->exit_action = g_value_get_int (value);
482 debug_printf ("terminal exit action: %d\n", self->exit_action);
485 case TILDA_TERMINAL_SCROLLBAR_POSITION:
486 self->scrollbar_position = g_value_get_int (value);
487 tilda_terminal_set_scrollbar_position (self);
488 debug_printf ("terminal scrollbar position: %d\n", self->scrollbar_position);
491 case TILDA_TERMINAL_SCROLL_BACKGROUND:
492 self->scroll_background = g_value_get_boolean (value);
493 vte_terminal_set_scroll_background (VTE_TERMINAL(self->vte_term), self->scroll_background);
494 debug_printf ("terminal scroll background: %d\n", self->scroll_background);
497 case TILDA_TERMINAL_SCROLL_ON_OUTPUT:
498 self->scroll_on_output = g_value_get_boolean (value);
499 vte_terminal_set_scroll_on_output (VTE_TERMINAL(self->vte_term), self->scroll_on_output);
500 debug_printf ("terminal scroll on output: %d\n", self->scroll_on_output);
503 case TILDA_TERMINAL_SCROLL_ON_KEYSTROKE:
504 self->scroll_on_keystroke = g_value_get_boolean (value);
505 vte_terminal_set_scroll_on_keystroke (VTE_TERMINAL(self->vte_term), self->scroll_on_keystroke);
506 debug_printf ("terminal scroll on keystroke: %d\n", self->scroll_on_keystroke);
509 case TILDA_TERMINAL_ANTIALIASED:
510 self->antialiased = g_value_get_boolean (value);
511 vte_terminal_set_font_from_string_full (VTE_TERMINAL(self->vte_term),
514 debug_printf ("terminal antialiased: %d\n", self->antialiased);
517 case TILDA_TERMINAL_ALLOW_BOLD_TEXT:
518 self->allow_bold_text = g_value_get_boolean (value);
519 vte_terminal_set_allow_bold (VTE_TERMINAL(self->vte_term), self->allow_bold_text);
520 debug_printf ("terminal allow bold text: %d\n", self->allow_bold_text);
523 case TILDA_TERMINAL_CURSOR_BLINKS:
524 self->cursor_blinks = g_value_get_boolean (value);
525 vte_terminal_set_cursor_blinks (VTE_TERMINAL(self->vte_term), self->cursor_blinks);
526 debug_printf ("terminal cursor blinks: %d\n", self->cursor_blinks);
529 case TILDA_TERMINAL_AUDIBLE_BELL:
530 self->audible_bell = g_value_get_boolean (value);
531 vte_terminal_set_audible_bell (VTE_TERMINAL(self->vte_term), self->audible_bell);
532 debug_printf ("terminal audible bell: %d\n", self->audible_bell);
535 case TILDA_TERMINAL_VISIBLE_BELL:
536 self->visible_bell = g_value_get_boolean (value);
537 vte_terminal_set_visible_bell (VTE_TERMINAL(self->vte_term), self->visible_bell);
538 debug_printf ("terminal visible bell: %d\n", self->visible_bell);
541 case TILDA_TERMINAL_DOUBLE_BUFFERED:
542 self->double_buffered = g_value_get_boolean (value);
543 gtk_widget_set_double_buffered (GTK_WIDGET(self->vte_term), self->double_buffered);
544 debug_printf ("terminal double buffered: %d\n", self->double_buffered);
547 case TILDA_TERMINAL_MOUSE_AUTOHIDE:
548 self->mouse_autohide = g_value_get_boolean (value);
549 vte_terminal_set_mouse_autohide (VTE_TERMINAL(self->vte_term), self->mouse_autohide);
550 debug_printf ("terminal mouse autohide: %d\n", self->mouse_autohide);
554 /* We don't have this property... */
555 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
561 tilda_terminal_get_property (GObject *object,
566 TildaTerminal *self = (TildaTerminal *) object;
568 switch (property_id) {
570 case TILDA_TERMINAL_NUMBER:
571 g_value_set_int (value, self->number);
574 case TILDA_TERMINAL_WINDOW_NUMBER:
575 g_value_set_int (value, self->window_number);
578 case TILDA_TERMINAL_TW:
579 g_value_set_pointer (value, self->parent_window);
582 case TILDA_TERMINAL_BACKGROUND_IMAGE:
583 g_value_set_string (value, self->background_image);
586 case TILDA_TERMINAL_SHELL:
587 g_value_set_string (value, self->shell);
590 case TILDA_TERMINAL_FONT:
591 g_value_set_string (value, self->font);
594 case TILDA_TERMINAL_TITLE:
595 g_value_set_string (value, self->title);
598 case TILDA_TERMINAL_WORKING_DIRECTORY:
599 g_value_set_string (value, self->working_directory);
602 case TILDA_TERMINAL_WEB_BROWSER:
603 g_value_set_string (value, self->web_browser);
606 case TILDA_TERMINAL_SCROLLBACK_LINES:
607 g_value_set_int (value, self->scrollback_lines);
610 case TILDA_TERMINAL_TRANSPARENCY_PERCENT:
611 g_value_set_int (value, self->transparency_percent);
614 case TILDA_TERMINAL_BACKSPACE_BINDING:
615 g_value_set_int (value, self->backspace_binding);
618 case TILDA_TERMINAL_DELETE_BINDING:
619 g_value_set_int (value, self->delete_binding);
622 case TILDA_TERMINAL_DYNAMIC_TITLE:
623 g_value_set_int (value, self->dynamic_title);
626 case TILDA_TERMINAL_EXIT_ACTION:
627 g_value_set_int (value, self->exit_action);
630 case TILDA_TERMINAL_SCROLLBAR_POSITION:
631 g_value_set_int (value, self->scrollbar_position);
634 case TILDA_TERMINAL_SCROLL_BACKGROUND:
635 g_value_set_boolean (value, self->scroll_background);
638 case TILDA_TERMINAL_SCROLL_ON_OUTPUT:
639 g_value_set_boolean (value, self->scroll_on_output);
642 case TILDA_TERMINAL_SCROLL_ON_KEYSTROKE:
643 g_value_set_boolean (value, self->scroll_on_keystroke);
646 case TILDA_TERMINAL_ANTIALIASED:
647 g_value_set_boolean (value, self->antialiased);
650 case TILDA_TERMINAL_ALLOW_BOLD_TEXT:
651 g_value_set_boolean (value, self->allow_bold_text);
654 case TILDA_TERMINAL_CURSOR_BLINKS:
655 g_value_set_boolean (value, self->cursor_blinks);
658 case TILDA_TERMINAL_AUDIBLE_BELL:
659 g_value_set_boolean (value, self->audible_bell);
662 case TILDA_TERMINAL_VISIBLE_BELL:
663 g_value_set_boolean (value, self->visible_bell);
666 case TILDA_TERMINAL_DOUBLE_BUFFERED:
667 g_value_set_boolean (value, self->double_buffered);
670 case TILDA_TERMINAL_MOUSE_AUTOHIDE:
671 g_value_set_boolean (value, self->mouse_autohide);
674 /* We don't have this property... */
675 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
681 tilda_terminal_constructor (GType type,
682 guint n_construct_properties,
683 GObjectConstructParam *construct_properties)
691 /* Invoke parent constructor */
692 TildaTerminalClass *klass;
693 klass = TILDA_TERMINAL_CLASS (g_type_class_peek (TILDA_TYPE_TERMINAL));
694 obj = parent_class->constructor (type,
695 n_construct_properties,
696 construct_properties);
698 /* Do other stuff here. The object is ready to go now, and all
699 * ctor properties have been set.
701 * TODO: This is the place to do DBus-init */
702 self = TILDA_TERMINAL(obj);
704 /* Pack into the hbox */
705 gtk_box_pack_end (GTK_BOX(self->hbox), self->scrollbar, FALSE, FALSE, 0);
706 gtk_box_pack_end (GTK_BOX(self->hbox), self->vte_term, TRUE, TRUE, 0);
707 gtk_widget_show (self->scrollbar);
708 gtk_widget_show (self->vte_term);
709 gtk_widget_show (self->hbox);
711 /* Match URL's, etc */
712 ret = vte_terminal_match_add (VTE_TERMINAL(self->vte_term), DINGUS1);
713 vte_terminal_match_set_cursor_type (VTE_TERMINAL(self->vte_term), ret, GDK_HAND2);
714 ret = vte_terminal_match_add(VTE_TERMINAL(self->vte_term), DINGUS2);
715 vte_terminal_match_set_cursor_type (VTE_TERMINAL(self->vte_term), ret, GDK_HAND2);
717 /* Connect Signals */
718 g_signal_connect (G_OBJECT(self->vte_term), "child-exited",
719 G_CALLBACK(tilda_terminal_child_exited_cb), self);
720 g_signal_connect (G_OBJECT(self->vte_term), "eof",
721 G_CALLBACK(tilda_terminal_child_exited_cb), self);
722 g_signal_connect (G_OBJECT(self->vte_term), "window-title-changed",
723 G_CALLBACK(tilda_terminal_window_title_changed_cb), self);
724 g_signal_connect (G_OBJECT(self->vte_term), "button-press-event",
725 G_CALLBACK(tilda_terminal_button_press_cb), self);
727 tilda_terminal_start_shell (self);
728 tilda_terminal_dbus_register_object (self);
734 tilda_terminal_dispose (GObject *obj)
738 TildaTerminal *self = (TildaTerminal *) obj;
740 /* We don't want to run dispose twice, so just return immediately */
741 if (self->dispose_has_run)
744 self->dispose_has_run = TRUE;
747 * In dispose, you are supposed to free all types referenced from this
748 * object which might themselves hold a reference to self. Generally,
749 * the most simple solution is to unref all members on which you own a
753 /* Chain up to the parent class */
754 G_OBJECT_CLASS (parent_class)->dispose (obj);
758 tilda_terminal_finalize (GObject *obj)
762 TildaTerminal *self = (TildaTerminal *) obj;
765 * Here, complete object destruction.
766 * You might not need to do much...
769 // TODO: g_free() any primitives here
770 g_free (self->background_image);
771 g_free (self->shell);
773 g_free (self->title);
774 g_free (self->working_directory);
777 /* Chain up to the parent class */
778 G_OBJECT_CLASS (parent_class)->finalize (obj);
782 tilda_terminal_class_init (gpointer g_class,
783 gpointer g_class_data)
787 GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
788 TildaTerminalClass *klass = TILDA_TERMINAL_CLASS (g_class);
791 /* Hook our functions to this type */
792 gobject_class->set_property = tilda_terminal_set_property;
793 gobject_class->get_property = tilda_terminal_get_property;
794 gobject_class->dispose = tilda_terminal_dispose;
795 gobject_class->finalize = tilda_terminal_finalize;
796 gobject_class->constructor = tilda_terminal_constructor;
798 parent_class = g_type_class_peek_parent (klass);
800 /* Hook the TildaTerminal type into DBus */
801 dbus_g_object_type_install_info (tilda_terminal_get_type(), &dbus_glib_tilda_terminal_object_info);
803 /* Install all of the properties */
804 pspec = g_param_spec_int ("number",
806 "Set terminal's number",
808 INT_MAX, // max value
810 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
812 g_object_class_install_property (gobject_class,
813 TILDA_TERMINAL_NUMBER,
816 pspec = g_param_spec_int ("window-number",
817 "Number of the window to which this terminal belongs",
818 "Set the number of the parent window",
822 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
824 g_object_class_install_property (gobject_class,
825 TILDA_TERMINAL_WINDOW_NUMBER,
828 pspec = g_param_spec_pointer ("parent-window",
829 "Pointer to terminal's parent TildaWindow",
830 "Set the pointer to the terminal's parent TildaWindow",
831 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
833 g_object_class_install_property (gobject_class,
837 pspec = g_param_spec_string ("background-image",
838 "Terminal's background image",
839 "Get/Set terminal's background image",
843 g_object_class_install_property (gobject_class,
844 TILDA_TERMINAL_BACKGROUND_IMAGE,
847 pspec = g_param_spec_string ("shell",
849 "Get/Set terminal's shell",
853 g_object_class_install_property (gobject_class,
854 TILDA_TERMINAL_SHELL,
857 pspec = g_param_spec_string ("font",
859 "Get/Set terminal's font",
863 g_object_class_install_property (gobject_class,
867 pspec = g_param_spec_string ("title",
869 "Get/Set terminal's title",
873 g_object_class_install_property (gobject_class,
874 TILDA_TERMINAL_TITLE,
877 pspec = g_param_spec_string ("working-directory",
878 "Terminal's initial working directory",
879 "Get/Set terminal's initial working directory",
883 g_object_class_install_property (gobject_class,
884 TILDA_TERMINAL_WORKING_DIRECTORY,
887 pspec = g_param_spec_string ("web-browser",
888 "Terminal's web browser command",
893 g_object_class_install_property (gobject_class,
894 TILDA_TERMINAL_WEB_BROWSER,
897 pspec = g_param_spec_int ("scrollback-lines",
898 "Terminal's scrollback amount (lines)",
899 "Get/Set terminal's scrollback amount",
901 INT_MAX, // TODO: artificially limit this?
905 g_object_class_install_property (gobject_class,
906 TILDA_TERMINAL_SCROLLBACK_LINES,
909 pspec = g_param_spec_int ("transparency-percent",
910 "Terminal's transparency (percent)",
911 "Get/Set terminal's transparency",
917 g_object_class_install_property (gobject_class,
918 TILDA_TERMINAL_TRANSPARENCY_PERCENT,
921 pspec = g_param_spec_int ("backspace-binding",
922 "Terminal's backspace binding",
923 "Get/Set terminal's backspace key binding",
925 VTE_ERASE_DELETE_SEQUENCE,
929 g_object_class_install_property (gobject_class,
930 TILDA_TERMINAL_BACKSPACE_BINDING,
933 pspec = g_param_spec_int ("delete-binding",
934 "Terminal's delete binding",
935 "Get/Set terminal's delete key binding",
937 VTE_ERASE_DELETE_SEQUENCE,
941 g_object_class_install_property (gobject_class,
942 TILDA_TERMINAL_DELETE_BINDING,
945 pspec = g_param_spec_int ("dynamic-title",
946 "Terminal's dynamic title generation method",
947 "Get/Set terminal's dynamic title generation method",
953 g_object_class_install_property (gobject_class,
954 TILDA_TERMINAL_DYNAMIC_TITLE,
957 pspec = g_param_spec_int ("exit-action",
958 "Terminal's action upon child exit",
959 "Get/Set terminal's action upon child exit",
965 g_object_class_install_property (gobject_class,
966 TILDA_TERMINAL_EXIT_ACTION,
969 pspec = g_param_spec_int ("scrollbar-position",
970 "Terminal's scrollbar position",
977 g_object_class_install_property (gobject_class,
978 TILDA_TERMINAL_SCROLLBAR_POSITION,
981 pspec = g_param_spec_boolean ("scroll-background",
982 "Controls terminal's scrolling behavior",
983 "Get/Set terminal's scrolling behavior",
987 g_object_class_install_property (gobject_class,
988 TILDA_TERMINAL_SCROLL_BACKGROUND,
991 pspec = g_param_spec_boolean ("scroll-on-output",
992 "Controls terminal's scrolling behavior on output",
993 "Get/Set terminal's scrolling behavior on output",
997 g_object_class_install_property (gobject_class,
998 TILDA_TERMINAL_SCROLL_ON_OUTPUT,
1001 pspec = g_param_spec_boolean ("scroll-on-keystroke",
1002 "Controls the terminal's scrolling behavior on keystroke",
1003 NULL, FALSE, G_PARAM_READWRITE);
1005 g_object_class_install_property (gobject_class,
1006 TILDA_TERMINAL_SCROLL_ON_KEYSTROKE,
1009 pspec = g_param_spec_boolean ("antialiased",
1010 "Attempt to antialias fonts",
1011 NULL, FALSE, G_PARAM_READWRITE);
1013 g_object_class_install_property (gobject_class,
1014 TILDA_TERMINAL_ANTIALIASED,
1017 pspec = g_param_spec_boolean ("allow-bold-text",
1019 NULL, FALSE, G_PARAM_READWRITE);
1021 g_object_class_install_property (gobject_class,
1022 TILDA_TERMINAL_ALLOW_BOLD_TEXT,
1025 pspec = g_param_spec_boolean ("cursor-blinks",
1026 NULL, NULL, FALSE, G_PARAM_READWRITE);
1028 g_object_class_install_property (gobject_class,
1029 TILDA_TERMINAL_CURSOR_BLINKS,
1032 pspec = g_param_spec_boolean ("audible-bell",
1033 NULL, NULL, FALSE, G_PARAM_READWRITE);
1035 g_object_class_install_property (gobject_class,
1036 TILDA_TERMINAL_AUDIBLE_BELL,
1039 pspec = g_param_spec_boolean ("visible-bell",
1040 NULL, NULL, FALSE, G_PARAM_READWRITE);
1042 g_object_class_install_property (gobject_class,
1043 TILDA_TERMINAL_VISIBLE_BELL,
1046 pspec = g_param_spec_boolean ("double-buffered",
1047 NULL, NULL, FALSE, G_PARAM_READWRITE);
1049 g_object_class_install_property (gobject_class,
1050 TILDA_TERMINAL_DOUBLE_BUFFERED,
1053 pspec = g_param_spec_boolean ("mouse-autohide",
1054 NULL, NULL, FALSE, G_PARAM_READWRITE);
1056 g_object_class_install_property (gobject_class,
1057 TILDA_TERMINAL_MOUSE_AUTOHIDE,
1062 tilda_terminal_get_type (void)
1064 static GType type = 0;
1068 static const GTypeInfo info = {
1069 sizeof (TildaTerminalClass),
1070 NULL, /* base_init */
1071 NULL, /* base_finalize */
1072 tilda_terminal_class_init, /* class_init */
1073 NULL, /* class_finalize */
1074 NULL, /* class_data */
1075 sizeof (TildaTerminal),
1076 0, /* n_preallocs */
1077 tilda_terminal_instance_init, /* instance_init */
1080 type = g_type_register_static (G_TYPE_OBJECT,
1081 "TildaTerminalType",
1089 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */