1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 
3 /*
4  *  Goo
5  *
6  *  Copyright (C) 2004-2009 Free Software Foundation, Inc.
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either arg_version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include <config.h>
23 #include <stdlib.h>
24 #include <brasero3/brasero-medium-monitor.h>
25 #include <gst/gst.h>
26 #include <glib.h>
27 #include <glib/gprintf.h>
28 #include <gtk/gtk.h>
29 #include "glib-utils.h"
30 #include "goo-application.h"
31 #include "goo-player-info.h"
32 #include "goo-window.h"
33 #include "gtk-utils.h"
34 #include "main.h"
35 #include "preferences.h"
36 #include "typedefs.h"
37 
38 
39 GtkApplication *Main_Application = NULL;
40 int	        arg_auto_play = FALSE;
41 int	        arg_toggle_visibility = FALSE;
42 
43 
44 int
main(int argc,char * argv[])45 main (int argc, char *argv[])
46 {
47 	int status;
48 
49 	/* text domain */
50 
51 	bindtextdomain (GETTEXT_PACKAGE, GOO_LOCALEDIR);
52 	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
53 	textdomain (GETTEXT_PACKAGE);
54 
55 	/* run the main application */
56 
57 	Main_Application = goo_application_new ();
58 	status = g_application_run (G_APPLICATION (Main_Application), argc, argv);
59 
60 	g_object_unref (Main_Application);
61 
62 	return status;
63 }
64 
65 
66 /* -- utilities -- */
67 
68 
69 GtkWidget *
main_get_window_from_device(const char * device)70 main_get_window_from_device (const char *device)
71 {
72 	GList *scan;
73 
74 	if (device == NULL)
75 		return NULL;
76 
77 	for (scan = gtk_application_get_windows (GTK_APPLICATION (g_application_get_default ())); scan; scan = scan->next) {
78 		GooWindow *window = scan->data;
79 
80 		if (g_strcmp0 (goo_player_get_device (goo_window_get_player (window)), device) == 0)
81 			return (GtkWidget *) window;
82 	}
83 
84 	return NULL;
85 }
86 
87 
88 BraseroDrive *
main_get_most_likely_drive(void)89 main_get_most_likely_drive (void)
90 {
91 	BraseroDrive         *result;
92 	BraseroMediumMonitor *monitor;
93 	GSList               *drivers;
94 
95 	monitor = brasero_medium_monitor_get_default ();
96 	drivers = brasero_medium_monitor_get_drives (monitor, BRASERO_MEDIA_TYPE_AUDIO | BRASERO_MEDIA_TYPE_CD);
97 	if (drivers != NULL)
98 		result = g_object_ref ((BraseroDrive *) drivers->data);
99 	else
100 		result = NULL;
101 
102 	g_slist_foreach (drivers, (GFunc) g_object_unref, NULL);
103 	g_slist_free (drivers);
104 	g_object_unref (monitor);
105 
106 	return result;
107 }
108 
109 
110 BraseroDrive *
main_get_drive_for_device(const char * device)111 main_get_drive_for_device (const char *device)
112 {
113 	BraseroDrive         *result = NULL;
114 	BraseroMediumMonitor *monitor;
115 
116 	monitor = brasero_medium_monitor_get_default ();
117 	result = brasero_medium_monitor_get_drive (monitor, device);
118 	g_object_unref (monitor);
119 
120 	return result;
121 }
122 
123 
124 void
system_notify(GooWindow * window,const char * id,const char * summary,const char * body)125 system_notify (GooWindow       *window,
126 	       const char      *id,
127 	       const char      *summary,
128 	       const char      *body)
129 {
130 	GNotification *notification;
131 	const char    *cover_path;
132 
133 	notification = g_notification_new (summary);
134 	g_notification_set_priority (notification, G_NOTIFICATION_PRIORITY_LOW);
135 	if (body != NULL)
136 		g_notification_set_body (G_NOTIFICATION (notification), body);
137 
138 	/* cover */
139 
140 	cover_path = goo_player_info_get_cover_file (GOO_PLAYER_INFO (goo_window_get_player_info (window)));
141 	if (cover_path != NULL) {
142 		GFile *cover_file;
143 		GIcon *cover_icon;
144 
145 		cover_file = g_file_new_for_path (cover_path);
146 		cover_icon = g_file_icon_new (cover_file);
147 		g_notification_set_icon (G_NOTIFICATION (notification), cover_icon);
148 
149 		g_object_unref (cover_icon);
150 		g_object_unref (cover_file);
151 	}
152 
153 	/* actions */
154 
155 	if (g_strcmp0 (id, "new-track") == 0) {
156 		const char *device_id;
157 
158 		device_id = goo_player_get_device (goo_window_get_player (window));
159 		if (goo_player_get_state (goo_window_get_player (window)) == GOO_PLAYER_STATE_PLAYING)
160 			g_notification_add_button_with_target (G_NOTIFICATION (notification), _("Pause"), "app.pause", "s", device_id);
161 		else
162 			g_notification_add_button_with_target (G_NOTIFICATION (notification), _("Play"), "app.play", "s", device_id);
163 		g_notification_add_button_with_target (G_NOTIFICATION (notification), _("Next"), "app.play-next", "s", device_id);
164 	}
165 	else if (g_strcmp0 (id, "new-album") == 0) {
166 		const char *device_id;
167 
168 		device_id = goo_player_get_device (goo_window_get_player (window));
169 		g_notification_add_button_with_target (G_NOTIFICATION (notification), _("Play"), "app.play-next", "s", device_id);
170 	}
171 
172 	/* send */
173 
174 	g_application_send_notification (G_APPLICATION (gtk_window_get_application (GTK_WINDOW (window))), "cd-info", notification);
175 
176 	g_object_unref (notification);
177 }
178