Debian Codegraph @

src/av-cp/gui.c

raw
1 /*
2 * Copyright (C) 2007 Zeeshan Ali (Khattak) <[email protected]>
3 *
4 * Authors: Zeeshan Ali (Khattak) <[email protected]>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20
21 #include <config.h>
22
23 #include <gmodule.h>
24 #include <stdlib.h>
25 #include <string.h>
26
27 #include "gui.h"
28 #include "playlist-treeview.h"
29 #include "renderer-combo.h"
30 #include "renderer-controls.h"
31 #include "main.h"
32 #include "icons.h"
33
34 #define UI_FILE "/org/gupnp/Tools/AV-CP/gupnp-av-cp.ui"
35 #define ICON_FILE "pixmaps/av-cp.png"
36
37 static GtkBuilder *builder;
38 static GtkWidget *main_window;
39 static GtkWidget *about_dialog;
40 static GtkButton *rescan_button;
41
42 gboolean
43 on_delete_event (GtkWidget *widget,
44 GdkEvent *event,
45 gpointer user_data);
46
47 G_MODULE_EXPORT
48 gboolean
49 on_delete_event (GtkWidget *widget,
50 GdkEvent *event,
51 gpointer user_data)
52 {
53 application_exit ();
54
55 return TRUE;
56 }
57
58 static void
59 setup_icons (GtkBuilder *object)
60 {
61 GdkPixbuf *icon_pixbuf;
62
63 init_icons ();
64
65 icon_pixbuf = load_pixbuf_file (ICON_FILE);
66 g_assert (icon_pixbuf != NULL);
67
68 gtk_window_set_icon (GTK_WINDOW (main_window), icon_pixbuf);
69 gtk_window_set_icon (GTK_WINDOW (about_dialog), icon_pixbuf);
70 gtk_about_dialog_set_logo (GTK_ABOUT_DIALOG (about_dialog),
71 icon_pixbuf);
72 g_object_unref (icon_pixbuf);
73 }
74
75 gboolean
76 init_ui (void)
77 {
78 gint window_width, window_height;
79 GError *error = NULL;
80 double w = 0.0;
81 double h = 0.0;
82
83 builder = gtk_builder_new ();
84 g_assert (builder != NULL);
85 gtk_builder_set_translation_domain (builder, GETTEXT_PACKAGE);
86
87 if (!gtk_builder_add_from_resource (builder, UI_FILE, &error)) {
88 g_critical ("Unable to load the GUI file %s: %s",
89 UI_FILE,
90 error->message);
91
92 g_error_free (error);
93 return FALSE;
94 }
95
96 main_window = GTK_WIDGET (gtk_builder_get_object (builder,
97 "main-window"));
98 g_assert (main_window != NULL);
99 about_dialog = GTK_WIDGET (gtk_builder_get_object (builder,
100 "about-dialog"));
101 g_assert (about_dialog != NULL);
102 rescan_button = GTK_BUTTON (gtk_builder_get_object (builder,
103 "rescan-button"));
104 g_assert (rescan_button != NULL);
105
106
107 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG (about_dialog),
108 VERSION);
109
110 gtk_widget_realize (main_window);
111 /* 40% of the screen but don't get bigger than 1000x800 */
112 #if GTK_CHECK_VERSION(3,22,0)
113 {
114 GdkWindow *window = gtk_widget_get_window (main_window);
115 GdkDisplay *display = gdk_display_get_default ();
116 GdkMonitor *monitor = gdk_display_get_monitor_at_window (display,
117 window);
118 GdkRectangle rectangle;
119
120 gdk_monitor_get_geometry (monitor, &rectangle);
121 w = rectangle.width * 0.4;
122 h = rectangle.height * 0.4;
123 }
124
125 #else
126 w = gdk_screen_width () * 0.4;
127 h = gdk_screen_height () * 0.4;
128 #endif
129
130 /* Keep 5/4 aspect */
131 if (w/h > 1.25) {
132 h = w / 1.25;
133 } else {
134 w = h * 1.25;
135 }
136
137 window_width = CLAMP ((int) w, 10, 1000);
138 window_height = CLAMP ((int) h, 10, 800);
139 gtk_window_set_default_size (GTK_WINDOW (main_window),
140 window_width,
141 window_height);
142
143 gtk_builder_connect_signals (builder, NULL);
144
145 setup_icons (builder);
146 setup_playlist_treeview (builder);
147 setup_renderer_controls (builder);
148 setup_renderer_combo (builder);
149
150
151 gtk_widget_show_all (main_window);
152
153 return TRUE;
154 }
155
156 GtkButton *
157 get_rescan_button (void)
158 {
159 return rescan_button;
160 }
161
162 void
163 deinit_ui (void)
164 {
165 g_object_unref (builder);
166 gtk_widget_destroy (main_window);
167 gtk_widget_destroy (about_dialog);
168 deinit_icons ();
169 }
170