File: freetuxtv-player-error-dialog.c

package info (click to toggle)
freetuxtv 0.6.8~dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, stretch
  • size: 4,236 kB
  • ctags: 1,486
  • sloc: ansic: 15,437; sh: 11,410; xml: 1,333; makefile: 678; sql: 135
file content (144 lines) | stat: -rw-r--r-- 4,359 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * freetuxtv
 * Copyright (C) Eric Beuque 2011 <eric.beuque@gmail.com>
 * 
freetuxtv is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * freetuxtv is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <string.h>
#include "freetuxtv-player-error-dialog.h"


typedef struct _FreetuxTVPlayerErrorDialogPrivate FreetuxTVPlayerErrorDialogPrivate;
struct _FreetuxTVPlayerErrorDialogPrivate
{
	FreetuxTVApp* app;
	GtkTextBuffer* pTextBuffer;
};

#define FREETUXTV_PLAYER_ERROR_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), FREETUXTV_TYPE_PLAYER_ERROR_DIALOG, FreetuxTVPlayerErrorDialogPrivate))

G_DEFINE_TYPE (FreetuxTVPlayerErrorDialog, freetuxtv_player_error_dialog, GTK_TYPE_DIALOG);

static void
on_response (GtkDialog *dialog, gint response_id, gpointer user_data)
{
	if(response_id == GTK_RESPONSE_CLOSE){
		gtk_widget_hide(GTK_WIDGET(dialog));
	}
}

static void
freetuxtv_player_error_dialog_init (FreetuxTVPlayerErrorDialog *object)
{
	FreetuxTVPlayerErrorDialogPrivate *priv;
	priv = FREETUXTV_PLAYER_ERROR_PRIVATE (object);

	priv->app = NULL;

	priv->pTextBuffer = gtk_text_buffer_new (NULL);

	GtkWidget* pTextView;
	pTextView = gtk_text_view_new_with_buffer (priv->pTextBuffer);
	gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW(pTextView), GTK_WRAP_WORD);

	GtkWidget* pScroll;
	pScroll = gtk_scrolled_window_new(NULL, NULL);
	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(pScroll), pTextView);
	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(pScroll), GTK_SHADOW_IN);
	//gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(pScroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

	GtkWidget* vbox;
#if GTK_API_VERSION == 3
	vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
#else
	vbox = gtk_vbox_new(FALSE, 5);
#endif
	gtk_box_pack_start (GTK_BOX (vbox),
	    GTK_WIDGET(pScroll), TRUE, TRUE, 5);

	GtkWidget* area;
	area = gtk_dialog_get_content_area (GTK_DIALOG(object));
	gtk_box_pack_start (GTK_BOX (area),
	    GTK_WIDGET(vbox), TRUE, TRUE, 5);

	gtk_widget_show_all(vbox);
	
	gtk_dialog_add_button (GTK_DIALOG(object), "gtk-close", GTK_RESPONSE_CLOSE);
	gtk_window_set_default_size (GTK_WINDOW(object), 400, 200);

	g_signal_connect(G_OBJECT(object), "response",
	    G_CALLBACK(on_response), NULL);
}

static void
freetuxtv_player_error_dialog_finalize (GObject *object)
{
	G_OBJECT_CLASS (freetuxtv_player_error_dialog_parent_class)->finalize (object);
}

static void
freetuxtv_player_error_dialog_class_init (FreetuxTVPlayerErrorDialogClass *klass)
{
	GObjectClass* object_class = G_OBJECT_CLASS (klass);
	
	g_type_class_add_private (klass, sizeof (FreetuxTVPlayerErrorDialogPrivate));

	object_class->finalize = freetuxtv_player_error_dialog_finalize;
}

GtkWidget*
freetuxtv_player_error_dialog_new (
    GtkWindow *parent, GtkDialogFlags flags, FreetuxTVApp* app)
{
	GtkWidget *widget;
	GtkDialog *dialog;

	g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);

	widget = g_object_new (FREETUXTV_TYPE_PLAYER_ERROR_DIALOG, NULL);
	dialog = GTK_DIALOG (widget);

	if (parent != NULL)
		gtk_window_set_transient_for (GTK_WINDOW (widget),
		    GTK_WINDOW (parent));

	if (flags & GTK_DIALOG_MODAL)
		gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);

	if (flags & GTK_DIALOG_DESTROY_WITH_PARENT)
		gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);

	/*
	if (flags & GTK_DIALOG_NO_SEPARATOR)
		gtk_dialog_set_has_separator (dialog, FALSE);*/

	

	return widget;
}

void
freetuxtv_player_error_dialog_set_message (
    FreetuxTVPlayerErrorDialog* pPlayerErrorDialog, const gchar *message)
{
	FreetuxTVPlayerErrorDialogPrivate *priv;
	priv = FREETUXTV_PLAYER_ERROR_PRIVATE (pPlayerErrorDialog);

	if (message)
	{
		gtk_text_buffer_set_text (priv->pTextBuffer, message, strlen(message));
	}
}