gui/window: Add a function for getting the window
This is cleaner and easier than calling into the gtk builder directly. I bumped up the window layer so other gui components can use it. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
85bb67feed
commit
133efc0515
|
@ -2,7 +2,7 @@
|
|||
* Copyright 2016 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/audio.h>
|
||||
#include <gui/builder.h>
|
||||
#include <gui/window.h>
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#define ARTWORK_PREVIEW_SIZE 150
|
||||
|
@ -124,8 +124,7 @@ void __artwork_select_cover(GtkButton *button)
|
|||
|
||||
filter = gtk_file_filter_new();
|
||||
preview = gtk_image_new_from_icon_name("", GTK_ICON_SIZE_DIALOG);
|
||||
dialog = gtk_file_chooser_dialog_new("Choose an image",
|
||||
GTK_WINDOW(gui_builder_widget("o_window")),
|
||||
dialog = gtk_file_chooser_dialog_new("Choose an image", gui_window(),
|
||||
GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
||||
_("_Open"), GTK_RESPONSE_ACCEPT,
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
#include <core/string.h>
|
||||
#include <gui/artwork.h>
|
||||
#include <gui/audio.h>
|
||||
#include <gui/builder.h>
|
||||
#include <gui/idle.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/window.h>
|
||||
|
||||
static inline void __audio_set_label(const gchar *label, const gchar *size,
|
||||
const gchar *text)
|
||||
|
@ -105,9 +105,8 @@ static int __audio_timeout(gpointer data)
|
|||
|
||||
gboolean __audio_can_accel(GtkWidget *widget, guint signal_id)
|
||||
{
|
||||
GtkWindow *window = GTK_WINDOW(gui_builder_widget("o_window"));
|
||||
g_signal_stop_emission_by_name(widget, "can-activate-accel");
|
||||
return !GTK_IS_ENTRY(gtk_window_get_focus(window)) &&
|
||||
return !GTK_IS_ENTRY(gtk_window_get_focus(gui_window())) &&
|
||||
gtk_widget_is_visible(widget) &&
|
||||
gtk_widget_is_sensitive(widget);
|
||||
}
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
*/
|
||||
#include <core/idle.h>
|
||||
#include <core/playlist.h>
|
||||
#include <gui/builder.h>
|
||||
#include <gui/idle.h>
|
||||
#include <gui/playlist.h>
|
||||
#include <gui/window.h>
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
static void __collection_add(GtkFileChooser *chooser)
|
||||
|
@ -29,8 +29,7 @@ void __collection_choose(GtkButton *button, gpointer data)
|
|||
filter = gtk_file_filter_new();
|
||||
gtk_file_filter_add_mime_type(filter, "inode/directory");
|
||||
|
||||
dialog = gtk_file_chooser_dialog_new("Add Music",
|
||||
GTK_WINDOW(gui_builder_widget("o_window")),
|
||||
dialog = gtk_file_chooser_dialog_new("Add Music", gui_window(),
|
||||
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
|
||||
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
||||
_("_Open"), GTK_RESPONSE_ACCEPT,
|
||||
|
|
|
@ -53,8 +53,7 @@ static gchar *find_file_path(const gchar *file)
|
|||
|
||||
static void __ocarina_activate(GApplication *application, gpointer data)
|
||||
{
|
||||
gtk_application_add_window(GTK_APPLICATION(application),
|
||||
GTK_WINDOW(gui_builder_widget("o_window")));
|
||||
gtk_application_add_window(GTK_APPLICATION(application), gui_window());
|
||||
}
|
||||
|
||||
static int __ocarina_local_options(GApplication *application,
|
||||
|
@ -102,10 +101,10 @@ static void __ocarina_startup(GApplication *application, gpointer data)
|
|||
|
||||
gui_builder_init(ui);
|
||||
core_init(&startup_argc, &startup_argv, &init_data);
|
||||
gui_window_init(icon);
|
||||
gui_queue_model_init();
|
||||
gui_view_init();
|
||||
gui_queue_init();
|
||||
gui_window_init(icon);
|
||||
gui_sidebar_init();
|
||||
gui_collection_init();
|
||||
gui_playlist_init();
|
||||
|
@ -122,8 +121,8 @@ static void __ocarina_shutdown(GApplication *application, gpointer data)
|
|||
gui_idle_disable();
|
||||
core_deinit();
|
||||
|
||||
gui_window_deinit();
|
||||
gui_queue_model_deinit();
|
||||
gui_window_deinit();
|
||||
gui_builder_deinit();
|
||||
}
|
||||
|
||||
|
|
16
gui/view.c
16
gui/view.c
|
@ -8,6 +8,7 @@
|
|||
#include <gui/model.h>
|
||||
#include <gui/queue.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/window.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -69,6 +70,9 @@ static unsigned int __view_get_column_index(GtkTreeViewColumn *col)
|
|||
{
|
||||
unsigned int i;
|
||||
|
||||
if (!view_treeview)
|
||||
return Q_MODEL_N_COLUMNS;
|
||||
|
||||
for (i = 0; i < Q_MODEL_N_COLUMNS; i++) {
|
||||
if (col == gtk_tree_view_get_column(view_treeview, i))
|
||||
return i;
|
||||
|
@ -203,15 +207,17 @@ static void __view_delete_selection(GtkTreeSelection *selection)
|
|||
|
||||
static gchar *__view_get_new_playlist_name(void)
|
||||
{
|
||||
unsigned int flags = GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL;
|
||||
GtkWidget *entry, *dialog, *content;
|
||||
gchar *text = NULL;
|
||||
GtkWidget *entry = gtk_entry_new();
|
||||
GtkWidget *dialog = gtk_dialog_new_with_buttons("New Playlist Name?",
|
||||
GTK_WINDOW(gui_builder_widget("o_window")),
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
|
||||
|
||||
entry = gtk_entry_new();
|
||||
dialog = gtk_dialog_new_with_buttons("New Playlist Name?",
|
||||
gui_window(), flags,
|
||||
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
||||
_("_OK"), GTK_RESPONSE_ACCEPT,
|
||||
NULL);
|
||||
GtkWidget *content = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
|
||||
content = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
|
||||
|
||||
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
|
||||
gtk_entry_set_activates_default(GTK_ENTRY(entry), true);
|
||||
|
|
11
gui/window.c
11
gui/window.c
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
#include <core/settings.h>
|
||||
#include <core/version.h>
|
||||
#include <gui/builder.h>
|
||||
#include <gui/window.h>
|
||||
|
||||
static const gchar *SETTINGS_WIDTH = "gui.window.width";
|
||||
static const gchar *SETTINGS_HEIGHT = "gui.window.height";
|
||||
|
@ -46,21 +46,20 @@ gboolean __window_state(GtkWindow *window, GdkEventWindowState *event,
|
|||
|
||||
void gui_window_init(const gchar *icon)
|
||||
{
|
||||
GtkWindow *window = GTK_WINDOW(gui_builder_widget("o_window"));
|
||||
gchar *title = g_strdup_printf("Ocarina %s", get_version());
|
||||
|
||||
gtk_window_set_title(window, title);
|
||||
gtk_window_set_icon_from_file(window, icon, NULL);
|
||||
gtk_window_set_title(gui_window(), title);
|
||||
gtk_window_set_icon_from_file(gui_window(), icon, NULL);
|
||||
|
||||
saved_width = settings_get(SETTINGS_WIDTH);
|
||||
saved_height = settings_get(SETTINGS_HEIGHT);
|
||||
if (saved_width > 0 && saved_height > 0)
|
||||
gtk_window_resize(window, saved_width, saved_height);
|
||||
gtk_window_resize(gui_window(), saved_width, saved_height);
|
||||
|
||||
g_free(title);
|
||||
}
|
||||
|
||||
void gui_window_deinit()
|
||||
{
|
||||
gtk_widget_destroy(gui_builder_widget("o_window"));
|
||||
gtk_widget_destroy(GTK_WIDGET(gui_window()));
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
#ifndef OCARINA_GUI_VIEW_H
|
||||
#define OCARINA_GUI_VIEW_H
|
||||
|
||||
#include <gui/builder.h>
|
||||
#include <core/queue.h>
|
||||
|
||||
/* Called to initialize structures needed by the treeview. */
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
#ifndef OCARINA_GUI_WINDOW_H
|
||||
#define OCARINA_GUI_WINDOW_H
|
||||
#include <gui/builder.h>
|
||||
|
||||
/* Called to initialize the main window. */
|
||||
void gui_window_init(const gchar *);
|
||||
|
@ -10,4 +11,10 @@ void gui_window_init(const gchar *);
|
|||
/* Called to deinitialize the main window. */
|
||||
void gui_window_deinit();
|
||||
|
||||
/* Called to get a pointer to the main window. */
|
||||
static inline GtkWindow *gui_window()
|
||||
{
|
||||
return GTK_WINDOW(gui_builder_widget("o_window"));
|
||||
}
|
||||
|
||||
#endif /* OCARINA_GUI_WINDOW_H */
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
builder
|
||||
window
|
||||
model
|
||||
view
|
||||
queue
|
||||
window
|
||||
idle
|
||||
sidebar
|
||||
playlist
|
||||
|
|
|
@ -5,10 +5,10 @@ function(gui_unit_test name)
|
|||
endfunction()
|
||||
|
||||
gui_unit_test(Builder)
|
||||
gui_unit_test(Window)
|
||||
gui_unit_test(Model)
|
||||
gui_unit_test(View)
|
||||
gui_unit_test(Queue)
|
||||
gui_unit_test(Window)
|
||||
gui_unit_test(Idle)
|
||||
gui_unit_test(Sidebar)
|
||||
gui_unit_test(Playlist)
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <gui/builder.h>
|
||||
#include <gui/idle.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/window.h>
|
||||
#include <tests/test.h>
|
||||
|
||||
static const unsigned int N = 100;
|
||||
|
@ -30,13 +31,11 @@ static int test_on_idle()
|
|||
static void test_idle()
|
||||
{
|
||||
GtkProgressBar *progress;
|
||||
GtkWindow *window;
|
||||
unsigned int i;
|
||||
float fraction;
|
||||
|
||||
main_loop = g_main_loop_new(NULL, FALSE);
|
||||
window = GTK_WINDOW(gui_builder_widget("o_window"));
|
||||
g_idle_add(test_on_idle, window);
|
||||
g_idle_add(test_on_idle, gui_window());
|
||||
|
||||
progress = GTK_PROGRESS_BAR(gui_builder_widget("o_idle_progress"));
|
||||
g_assert_false(gtk_widget_is_visible(GTK_WIDGET(progress)));
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <gui/model.h>
|
||||
#include <gui/playlist.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/window.h>
|
||||
#include <tests/test.h>
|
||||
|
||||
struct core_init_data init_data = {
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
* Copyright 2015 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/settings.h>
|
||||
#include <gui/builder.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/window.h>
|
||||
#include <tests/test.h>
|
||||
|
||||
|
@ -20,7 +18,7 @@ static void test_window()
|
|||
GtkWindow *window;
|
||||
|
||||
main_loop = g_main_loop_new(NULL, FALSE);
|
||||
window = GTK_WINDOW(gui_builder_widget("o_window"));
|
||||
window = gui_window();
|
||||
g_idle_add(test_on_idle, window);
|
||||
|
||||
g_assert_false(settings_has("gui.window.width"));
|
||||
|
@ -46,10 +44,9 @@ int main(int argc, char **argv)
|
|||
{
|
||||
int ret;
|
||||
|
||||
gtk_init(&argc, NULL);
|
||||
settings_init();
|
||||
gtk_init(&argc, NULL);
|
||||
gui_builder_init("share/ocarina/ocarina.ui");
|
||||
gui_view_init();
|
||||
gui_window_init("share/ocarina/ocarina.png");
|
||||
|
||||
g_test_init(&argc, &argv, NULL);
|
||||
|
|
Loading…
Reference in New Issue