From 4f6d07882e5c7b5056a498eb0f512b9b250e6fc8 Mon Sep 17 00:00:00 2001 From: Brian Pepple Date: Thu, 22 Oct 2009 22:30:24 -0400 Subject: Add code for app window. --- Makefile.am | 2 +- data/Makefile.am | 6 +- data/sonancy.ui | 48 +++++------ po/POTFILES.in | 1 - src/Makefile.am | 23 +++-- src/sonancy-app.c | 4 +- src/sonancy-window.c | 237 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/sonancy-window.h | 57 +++++++++++++ 8 files changed, 333 insertions(+), 45 deletions(-) create mode 100644 src/sonancy-window.c create mode 100644 src/sonancy-window.h diff --git a/Makefile.am b/Makefile.am index 8af9fe5..ec116f7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = src po +SUBDIRS = data src po ACLOCAL_AMFLAGS = -I m4 diff --git a/data/Makefile.am b/data/Makefile.am index 3b4a476..84ca091 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -1,5 +1,5 @@ -builderdir = $(datadir)/sonancy -builder_DATA = \ +builderuidir = $(datadir)/sonancy +builderui_DATA = \ sonancy.ui -EXTRA_DIST = $(builder_DATA) \ No newline at end of file +EXTRA_DIST = $(builderui_DATA) diff --git a/data/sonancy.ui b/data/sonancy.ui index 7f90ece..55d18e9 100644 --- a/data/sonancy.ui +++ b/data/sonancy.ui @@ -1,29 +1,19 @@ - - - - - - - - True - vertical - - - - - - - - - True - 2 - - - False - 2 - - - - - - + + + + + + + + + + + + + + diff --git a/po/POTFILES.in b/po/POTFILES.in index 018b797..fd5b7ba 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,4 +1,3 @@ # List of source files containing translatable strings. # Please keep this list in alphabetic order. [encoding: UTF-8] -[type: gettext/glade]data/sonancy.ui \ No newline at end of file diff --git a/src/Makefile.am b/src/Makefile.am index 31ea7a8..ab88c40 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,12 +1,16 @@ -AM_CPPFLAGS = \ - -DG_LOG_DOMAIN=\"Sonacy\" \ - -DPREFIX="\"$(prefix)"\" \ - -DSYSCONFDIR=\""$(sysconfdir)"\" \ - -DDATADIR=\""$(datadir)"\" \ - -DLIBDIR=\""$(libdir)"\" \ - -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \ - -I$(top_srcdir) \ - -I$(top_builddir) \ +AM_CPPFLAGS = \ + -DPREFIX=\""$(prefix)"\" \ + -DLIBDIR=\""$(libdir)"\" \ + -DDATADIR=\""$(datadir)"\" \ + -DPKGDATADIR=\""$(datadir)/sonancy"\" \ + -DUIDATADIR=\""$(datadir)/gnome-2.0/ui"\" \ + -DGNOMELOCALEDIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \ + -DG_DISABLE_DEPRECATED \ + -DGDK_DISABLE_DEPRECATED \ + -DGDK_PIXBUF_DISABLE_DEPRECATED \ + -DGTK_DISABLE_DEPRECATED \ + -I$(top_srcdir) \ + -I$(top_builddir) \ $(SONANCY_CFLAGS) bin_PROGRAMS = sonancy @@ -14,6 +18,7 @@ bin_PROGRAMS = sonancy sonancy_SOURCES = \ sonancy-app.c sonancy-app.h \ sonancy-main.c \ + sonancy-window.c sonancy-window.h \ sonancy-xml.c sonancy-xml.h sonancy_LDADD= \ diff --git a/src/sonancy-app.c b/src/sonancy-app.c index 895b472..ec548fe 100644 --- a/src/sonancy-app.c +++ b/src/sonancy-app.c @@ -81,12 +81,12 @@ sonancy_app_run (SonancyApp *app) { g_return_val_if_fail (SONANCY_IS_APP (app), EXIT_FAILURE); g_return_val_if_fail (!sonancy_app_is_running (app), EXIT_SUCCESS); -/* + app->main_window = sonancy_window_new (); g_signal_connect (app->main_window, "destroy", G_CALLBACK (on_window_destroy), app); -*/ + gtk_main (); return EXIT_SUCCESS; diff --git a/src/sonancy-window.c b/src/sonancy-window.c new file mode 100644 index 0000000..b7a16e6 --- /dev/null +++ b/src/sonancy-window.c @@ -0,0 +1,237 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2009 Brian Pepple + * + * This program 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 2 of the + * License, or (at your option) any later version. + * + * This program 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, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include + +#include + +#include + +#include "sonancy-window.h" + +#define SONANCY_WINDOW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), SONANCY_TYPE_WINDOW, SonancyWindowPrivate)) + +struct _SonancyWindowPrivate { + GtkWidget *vbox; + GtkWidget *menubar; + + GtkUIManager *manager; + GtkActionGroup *action_group; +}; + +G_DEFINE_TYPE (SonancyWindow, sonancy_window, GTK_TYPE_WINDOW); + +static void +sonancy_window_dispose (GObject *gobject) +{ + SonancyWindowPrivate *priv = SONANCY_WINDOW (gobject)->priv; + + if (priv->manager) { + g_object_unref (priv->manager); + priv->manager = NULL; + } + + if (priv->action_group) { + g_object_unref (priv->action_group); + priv->action_group = NULL; + } + + G_OBJECT_CLASS (sonancy_window_parent_class)->dispose (gobject); +} + +static void +sonancy_window_constructed (GObject *gobject) +{ + SonancyWindow *window = SONANCY_WINDOW (gobject); + SonancyWindowPrivate *priv = window->priv; + + gtk_widget_show_all (GTK_WIDGET (window)); +} + +static void +sonancy_window_cmd_quit (GtkAction *action, + SonancyWindow *window) +{ + gtk_widget_destroy (GTK_WIDGET (window)); +} + +static void +sonancy_window_cmd_preferences (GtkAction *action, + SonancyWindow *window) +{ + +} + +static void +about_url_hook (GtkAboutDialog *dialog, + const gchar *link_, + gpointer user_data) +{ + GdkScreen *screen; + gint pid; + GError *error; + gchar **argv; + + if (gtk_widget_has_screen (GTK_WIDGET (dialog))) + screen = gtk_widget_get_screen (GTK_WIDGET (dialog)); + else + screen = gdk_screen_get_default (); + + argv = g_new (gchar*, 3); + argv[0] = g_strdup ("gnome-open"); + argv[1] = g_strdup (link_); + argv[2] = NULL; + + error = NULL; + gdk_spawn_on_screen (screen, + NULL, + argv, NULL, + G_SPAWN_SEARCH_PATH, + NULL, NULL, + &pid, &error); + + if (error) { + g_warning ("Unable to launch gnome-open: %s", error->message); + g_error_free (error); + } + + g_strfreev (argv); +} + +static void +sonancy_window_cmd_help_about (GtkAction *action, + SonancyWindow *window) +{ + const gchar *authors[] = { + "Brian Pepple ", + NULL + }; + + const gchar *translator_credits = _("translator-credits"); + const gchar *copyright = "Copyright \xc2\xa9 2009 Brian Pepple"; + + gtk_about_dialog_set_url_hook (about_url_hook, NULL, NULL); + + gtk_show_about_dialog (GTK_WINDOW (window), + "program-name", PACKAGE_NAME, + "title",_("About Sonancy"), + "comments", _("Audio Tagging Tool"), + "version", VERSION, + "copyright", copyright, + "authors", authors, + "translator-credits", translator_credits, + NULL); +} + +static void +sonancy_window_class_init (SonancyWindowClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + g_type_class_add_private (klass, sizeof (SonancyWindowPrivate)); + + gobject_class->dispose = sonancy_window_dispose; + gobject_class->constructed = sonancy_window_constructed; +} + +static const GtkActionEntry action_entries[] = { + { "SonancyFileAction", NULL, N_("_File") }, + { + "SonancyQuit", GTK_STOCK_QUIT, NULL, "Q", + N_("Quit Sonancy"), + G_CALLBACK (sonancy_window_cmd_quit) + }, + + { "SonancyEditAction", NULL, N_("_Edit") }, + { + "SonancyPreferences", GTK_STOCK_PREFERENCES, NULL, NULL, + N_("Edit Sonancy Preferences"), + G_CALLBACK (sonancy_window_cmd_preferences) + }, + + { "SonancyHelpAction", NULL, N_("_Help") }, + { + "SonancyAbout", GTK_STOCK_ABOUT, N_("_About"), NULL, NULL, + G_CALLBACK (sonancy_window_cmd_help_about) + } +}; + +static void +sonancy_window_init (SonancyWindow *window) +{ + SonancyWindowPrivate *priv; + GtkAccelGroup *accel_group; + GError *error; + + GTK_WINDOW (window)->type = GTK_WINDOW_TOPLEVEL; + gtk_window_set_resizable (GTK_WINDOW (window), TRUE); + gtk_window_set_default_size (GTK_WINDOW (window), 362, 600); + gtk_window_set_title (GTK_WINDOW (window), "Sonancy"); + + window->priv = priv = SONANCY_WINDOW_GET_PRIVATE (window); + + priv->vbox = gtk_vbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (window), priv->vbox); + gtk_widget_show (priv->vbox); + + priv->action_group = gtk_action_group_new ("SonancyActions"); + gtk_action_group_set_translation_domain (priv->action_group, NULL); + gtk_action_group_add_actions (priv->action_group, + action_entries, + G_N_ELEMENTS (action_entries), + window); + + priv->manager = gtk_ui_manager_new (); + gtk_ui_manager_insert_action_group (priv->manager, + priv->action_group, + 0); + + accel_group = gtk_ui_manager_get_accel_group (priv->manager); + gtk_window_add_accel_group (GTK_WINDOW (window), accel_group); + + error = NULL; + if (!gtk_ui_manager_add_ui_from_file (priv->manager, + PKGDATADIR G_DIR_SEPARATOR_S "sonancy.ui", + &error)) + { + g_critical ("Building menus failed: %s", + error->message); + g_error_free (error); + } else { + priv->menubar = gtk_ui_manager_get_widget (priv->manager, "/SonancyMenubar"); + gtk_box_pack_start (GTK_BOX (priv->vbox), priv->menubar, FALSE, FALSE, 0); + gtk_widget_show (priv->menubar); + } +} + +GtkWidget * +sonancy_window_new (void) +{ + return g_object_new (SONANCY_TYPE_WINDOW, NULL); +} diff --git a/src/sonancy-window.h b/src/sonancy-window.h new file mode 100644 index 0000000..2a89ea6 --- /dev/null +++ b/src/sonancy-window.h @@ -0,0 +1,57 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2009 Brian Pepple + * + * This program 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 2 of the + * License, or (at your option) any later version. + * + * This program 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, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + */ + +#ifndef __SONANCY_WINDOW_H__ +#define __SONANCY_WINDOW_H__ + +#include + +G_BEGIN_DECLS + +#define SONANCY_TYPE_WINDOW (sonancy_window_get_type ()) +#define SONANCY_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SONANCY_TYPE_WINDOW, SonancyWindow)) +#define SONANCY_IS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SONANCY_TYPE_WINDOW)) +#define SONANCY_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SONANCY_TYPE_WINDOW, SonancyWindowClass)) +#define SONANCY_IS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SONANCY_TYPE_WINDOW)) +#define SONANCY_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SONANCY_TYPE_WINDOW, SonancyWindowClass)) + +typedef struct _SonancyWindow SonancyWindow; +typedef struct _SonancyWindowPrivate SonancyWindowPrivate; +typedef struct _SonancyWindowClass SonancyWindowClass; + +struct _SonancyWindow +{ + GtkWindow parent_instance; + + SonancyWindowPrivate *priv; +}; + +struct _SonancyWindowClass +{ + GtkWindowClass parent_class; +}; + +GType sonancy_window_get_type (void) G_GNUC_CONST; +GtkWidget *sonancy_window_new (void); + +G_END_DECLS + +#endif /* __SONANCY_WINDOW_H__ */ -- cgit