📄 gtk_gui.cpp
字号:
// This file is part of Ambulant Player, www.ambulantplayer.org.//// Copyright (C) 2003-2007 Stichting CWI, // Kruislaan 413, 1098 SJ Amsterdam, The Netherlands.//// Ambulant Player is free software; you can redistribute it and/or modify// it under the terms of the GNU Lesser General Public License as published by// the Free Software Foundation; either version 2.1 of the License, or// (at your option) any later version.//// Ambulant Player 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 Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public License// along with Ambulant Player; if not, write to the Free Software// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA/* gtk_gui.cpp - GTK GUI for Ambulant * */#include <pthread.h>#include <libgen.h>#include <stdlib.h>#include <fcntl.h>#include "gtk_gui.h"#include "gtk_mainloop.h"#include "gtk_logger.h"#include "gtk_renderer.h"#ifdef WITH_GSTREAMER#include "ambulant/gui/gstreamer/gstreamer_renderer_factory.h"#endif/*WITH_GSTREAMER*/#if 1#include "ambulant/config/config.h"#include "ambulant/lib/logger.h"#include "ambulant/version.h"#endif//#define AM_DBG#ifndef AM_DBG#define AM_DBG if(0)#endif#define WITH_GTK_LOGGER//KB XXXX FIXME #ifdef WITH_NOKIA770#ifdef AMBULANT_DATADIR //KB XXXX#undef AMBULANT_DATADIR#define AMBULANT_DATADIR "/usr/share/ambulant"#endif/*AMBULANT_DATADIR*/#define UI_FILENAME AMBULANT_DATADIR "/ui_manager.xml"#include <hildon-widgets/hildon-program.h>#include <glib-object.h>#else /*WITH_NOKIA770*/#define UI_FILENAME "ui_manager.xml"#endif/*WITH_NOKIA770*/const char *ui_description = "<ui> \n" "<menubar name=\"MenuBar\"> \n" "<menu action=\"FileMenu\"> \n" "<menuitem action=\"open\"/> \n" "<menuitem action=\"openurl\"/> \n" "<menuitem action=\"reload\"/> \n" "<separator/> \n" "<menuitem action=\"preferences\"/> \n" "<menuitem action=\"loadsettings\"/> \n" "<separator/> \n" "<menuitem action=\"quit\"/> \n" "</menu> \n" "<menu action=\"PlayMenu\"> \n" "<menuitem action=\"play\"/> \n" "<menuitem action=\"pause\"/> \n" "<menuitem action=\"stop\"/> \n" "</menu> \n" "<menu action=\"ViewMenu\"> \n" "<menuitem action=\"fullscreen\"/> \n" "<menuitem action=\"window\"/> \n" "<separator/> \n" "<menuitem action=\"logwindow\"/> \n" "</menu> \n" "<menu action=\"HelpMenu\"> \n" "<menuitem action=\"about\"/> \n" "<menuitem action=\"help\"/> \n" "<separator/> \n" "<menuitem action=\"website\"/> \n" "<separator/> \n" "<menuitem action=\"welcome\"/> \n" "</menu> \n" "</menubar> \n" "</ui> \n" "\0";const char *about_text = "Ambulant SMIL 2.1 player.\n" "Version: %s\n" "Copyright Stichting CWI, 2003-2007.\n\n" "License: LGPL";// Places where to look for the Welcome documentconst char *welcome_locations[] = { "Welcome/Welcome.smil", "../Welcome/Welcome.smil", "Extras/Welcome/Welcome.smil", "../Extras/Welcome/Welcome.smil",#ifdef AMBULANT_DATADIR AMBULANT_DATADIR "/Welcome/Welcome.smil",#else "/usr/local/share/ambulant/Welcome/Welcome.smil",#endif#ifdef GTK_NO_FILEDIALOG /* Assume embedded Qt */ "/home/zaurus/Documents/Ambulant/Extras/Welcome/Welcome.smil",#endif/*QT_NO_FILEDIALOG*/ NULL};// Places where to look for the helpfileconst char *helpfile_locations[] = { "Documentation/user/index.html", "../Documentation/user/index.html",#ifdef AMBULANT_DATADIR AMBULANT_DATADIR "/AmbulantPlayerHelp/index.html",#else "/usr/local/share/ambulant/AmbulantPlayerHelp/index.html",#endif NULL};static GdkPixmap *pixmap = NULL;// callbacks for C++/* File */extern "C" {gboolean gtk_C_callback_timer(void *userdata){// AM_DBG lib::logger::get_logger()->debug("gtk_C_callback_timer called"); return TRUE;}}extern "C" {void gtk_C_callback_resize(void *userdata, GdkEventConfigure *event, GtkWidget *widget){ ((gtk_gui*) userdata)->do_resize(event);}}extern "C" {void gtk_C_callback_open(void *userdata){ ((gtk_gui*) userdata)->do_open();}}extern "C" {void gtk_C_callback_open_url(void *userdata){ ((gtk_gui*) userdata)->do_open_url();}void gtk_C_callback_reload(void *userdata){ ((gtk_gui*) userdata)->do_reload();}void gtk_C_callback_settings_select(void *userdata){ ((gtk_gui*) userdata)->do_settings_select();}void gtk_C_callback_quit(void *userdata){ ((gtk_gui*) userdata)->do_quit();}/* Play */void gtk_C_callback_play(void *userdata){ ((gtk_gui*) userdata)->do_play();}void gtk_C_callback_pause(void *userdata){ ((gtk_gui*) userdata)->do_pause();}void gtk_C_callback_stop(void *userdata){ ((gtk_gui*) userdata)->do_stop();}/* View */void gtk_C_callback_full_screen(void *userdata){ gtk_window_fullscreen(((gtk_gui*) userdata)->get_toplevel_container());}void gtk_C_callback_normal_screen(void *userdata){ gtk_window_unfullscreen(((gtk_gui*) userdata)->get_toplevel_container());}void gtk_C_callback_load_settings(void *userdata){ ((gtk_gui*) userdata)->do_load_settings();}void gtk_C_callback_logger_window(void *userdata){ ((gtk_gui*) userdata)->do_logger_window();}/* Help */void gtk_C_callback_about(void *userdata){ ((gtk_gui*) userdata)->do_about();}void gtk_C_callback_help(void *userdata){ ((gtk_gui*) userdata)->do_help();}void gtk_C_callback_homepage(void *userdata){ ((gtk_gui*) userdata)->do_homepage();}void gtk_C_callback_welcome(void *userdata){ ((gtk_gui*) userdata)->do_welcome();}}extern "C" {void gtk_C_callback_do_player_done(void *userdata){ ((gtk_gui*) userdata)->do_player_done();}void gtk_C_callback_do_need_redraw(void *userdata, void* r_call, void* w_call, void* pt_call){ const void* r = r_call; void* w = w_call; const void* pt = pt_call;// ((gtk_gui*) userdata)->(r, w, pt);}void gtk_C_callback_do_internal_message(void *userdata, void* e){ gtk_message_event* event = (gtk_message_event*) e; ((gtk_gui*) userdata)->do_internal_message(event);}}static const char * find_datafile(const char **locations){ const char **p; for(p = locations; *p; p++) { if (access(*p, 0) >= 0) return *p; } return NULL;}gtk_gui::gtk_gui(const char* title, const char* initfile) :// initialize all dynamic data pointers in the same order as they are declared m_programfilename(NULL), m_smilfilename(NULL), m_settings(NULL), m_toplevelcontainer(NULL), menubar(NULL), m_guicontainer(NULL), m_documentcontainer(NULL), m_actions(NULL),#ifdef LOCK_MESSAGE m_gui_thread(0),#endif/*LOCK_MESSAGE*/ m_file_chooser(NULL), m_settings_chooser(NULL), m_url_text_entry(NULL), m_mainloop(NULL){ GError *error = NULL; // Initialization of the Menu Bar Items // There is a problem in here because the callbacks in Actions go like g_signal_connect (but, we need g_sginal_connect_swapped) static GtkActionEntry entries[] = { { "FileMenu", NULL, gettext_noop("_File")}, { "open", GTK_STOCK_OPEN, gettext_noop("_Open..."), "<Control>O", gettext_noop("Open a document from local disk"), NULL}, { "openurl", NULL, gettext_noop("Open _URL..."), "<Control>L", gettext_noop("Open a document from the network"), NULL}, { "reload", GTK_STOCK_REFRESH, gettext_noop("_Reload"), NULL, gettext_noop("Reload current document"), NULL}, { "preferences", GTK_STOCK_PREFERENCES , gettext_noop("_Preferences"), NULL, gettext_noop("Change application preferences"), NULL}, { "loadsettings", GTK_STOCK_PROPERTIES, gettext_noop("_Load Settings..."), NULL, gettext_noop("Open SMIL playback settings document"), NULL}, { "quit", GTK_STOCK_QUIT, gettext_noop("_Quit"), "<Control>Q", gettext_noop("Quit Ambulant Player"), NULL}, // Play Menu { "PlayMenu", NULL, gettext_noop("Pla_y")}, { "play", GTK_STOCK_MEDIA_PLAY, gettext_noop("Pla_y"), "<Control>P", gettext_noop("Start document playback"), NULL}, { "pause", GTK_STOCK_MEDIA_PAUSE, gettext_noop("_Pause"), "<Control><Shift>P", gettext_noop("Pause document playback"), NULL}, { "stop", GTK_STOCK_MEDIA_STOP, gettext_noop("_Stop"), "<Control>S", gettext_noop("Stop document playback"), NULL}, // View Menu { "ViewMenu", NULL, gettext_noop("_View")}, { "fullscreen", NULL, gettext_noop("_Full Screen"), "<Control>F", gettext_noop("Full Screen"), NULL}, { "window", NULL, gettext_noop("_Window"), "<Control><Alt>F", gettext_noop("Normal Screen"), NULL}, { "logwindow", NULL, gettext_noop("_Log Window..."), "<Control>L", gettext_noop("Show status output window"), NULL}, // Help Menu { "HelpMenu", NULL, gettext_noop("_Help")}, { "about", GTK_STOCK_ABOUT, gettext_noop("_About AmbulantPlayer"), NULL, gettext_noop("Information about Ambulant"), NULL}, { "help", GTK_STOCK_HELP, gettext_noop("AmbulantPlayer _Help..."), NULL, gettext_noop("Help in AmbulantPlayer Webpage"), NULL}, { "website", NULL, gettext_noop("AmbulantPlayer _Website..."), NULL, gettext_noop("Open the Ambulant Webpage"), NULL}, { "welcome", GTK_STOCK_HOME, gettext_noop("_Play Welcome Document"), "<Control><shift>H", gettext_noop("Plays a simple SMIL file"), NULL} }; int n_entries = G_N_ELEMENTS(entries); m_programfilename = title;#ifdef LOCK_MESSAGE pthread_cond_init(&m_cond_message, NULL); pthread_mutex_init(&m_lock_message, NULL); m_gui_thread = pthread_self();#endif/*LOCK_MESSAGE*/ if (initfile != NULL && initfile != "") m_smilfilename = strdup(initfile); /*Initialization of the Main Window */ m_toplevelcontainer = GTK_WINDOW (gtk_window_new (GTK_WINDOW_TOPLEVEL)); gtk_window_set_title(m_toplevelcontainer, initfile); gtk_window_set_resizable(m_toplevelcontainer, true); gtk_widget_set_size_request(GTK_WIDGET (m_toplevelcontainer), 150, 150); gtk_widget_set_uposition(GTK_WIDGET (m_toplevelcontainer), 240, 320); g_signal_connect_swapped (GTK_OBJECT (m_toplevelcontainer), "delete-event", G_CALLBACK (gtk_C_callback_quit), (void *) this); // Callback for the resize events g_signal_connect_swapped (GTK_OBJECT (m_toplevelcontainer), "expose-event", G_CALLBACK (gtk_C_callback_resize), (void *) this); /* Initialization of the signals */ signal_player_done_id = g_signal_new ("signal-player-done", gtk_window_get_type(), G_SIGNAL_RUN_LAST, 0, 0, 0, g_cclosure_marshal_VOID__VOID,GTK_TYPE_NONE, 0, NULL); signal_need_redraw_id = g_signal_new ("signal-need-redraw", gtk_window_get_type(), G_SIGNAL_RUN_LAST, 0, 0, 0, gtk_marshal_NONE__POINTER_POINTER_POINTER,GTK_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER); signal_internal_message_id = g_signal_new ("signal-internal-message", gtk_window_get_type(), G_SIGNAL_RUN_LAST, 0, 0, 0, gtk_marshal_NONE__POINTER, GTK_TYPE_NONE, 1, G_TYPE_POINTER); // Signal connections g_signal_connect_swapped (GTK_OBJECT (m_toplevelcontainer), "signal-player-done", G_CALLBACK (gtk_C_callback_do_player_done), (void*)this); g_signal_connect_swapped (GTK_OBJECT (m_toplevelcontainer), "signal-need-redraw", G_CALLBACK (gtk_C_callback_do_player_done), (void*)this); g_signal_connect_swapped (GTK_OBJECT (m_toplevelcontainer), "signal-internal-message", G_CALLBACK (gtk_C_callback_do_internal_message), (void*)this); /* VBox (m_guicontainer) to place the Menu bar in the correct place */ m_guicontainer = gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(m_toplevelcontainer), GTK_WIDGET (m_guicontainer)); /* The Action Group that includes the menu bar */ m_actions = gtk_action_group_new("Actions"); AM_DBG printf("%s0x%X\n", "gtk_gui::gtk_gui(), PACKAGE=", PACKAGE); gtk_action_group_set_translation_domain(m_actions, PACKAGE); gtk_action_group_add_actions(m_actions, entries, n_entries, (void*)this); /* The Gtk UI Manager */ GtkUIManager *ui = gtk_ui_manager_new();// if (!gtk_ui_manager_add_ui_from_file(ui, UI_FILENAME, &error)) if (!gtk_ui_manager_add_ui_from_string(ui, ui_description, -1, &error)) g_error("Could not merge UI, error was: %s\n", error->message); gtk_ui_manager_insert_action_group(ui, m_actions, 0); gtk_window_add_accel_group(m_toplevelcontainer, gtk_ui_manager_get_accel_group(ui)); /* Disable and make invisible menus and menu items */#ifdef GTK_NO_FILEDIALOG gtk_action_set_sensitive(gtk_action_group_get_action(m_actions, "open"), true); gtk_action_set_sensitive(gtk_action_group_get_action(m_actions, "openurl"), false);#endif // The actual activation calls g_signal_connect_swapped (gtk_action_group_get_action (m_actions, "open"), "activate", G_CALLBACK (gtk_C_callback_open), (void *) this );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -