int main(int argc, char *argv[]) { signal_user_data_t *ud; GError *error = NULL; GOptionContext *context; hb_global_init(); #ifdef ENABLE_NLS bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); #endif context = g_option_context_new(_("- Transcode media formats")); g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE); g_option_context_add_group(context, gtk_get_option_group(TRUE)); #if defined(_ENABLE_GST) g_option_context_add_group(context, gst_init_get_option_group()); #endif g_option_context_parse(context, &argc, &argv, &error); if (error != NULL) { g_warning("%s: %s", G_STRFUNC, error->message); g_clear_error(&error); } g_option_context_free(context); #if defined(_WIN32) if (win32_console) { // Enable console logging if(AttachConsole(ATTACH_PARENT_PROCESS) || AllocConsole()){ close(STDOUT_FILENO); freopen("CONOUT$", "w", stdout); close(STDERR_FILENO); freopen("CONOUT$", "w", stderr); } } else { // Non-console windows apps do not have a stderr->_file // assigned properly stderr->_file = STDERR_FILENO; stdout->_file = STDOUT_FILENO; } #endif if (argc > 1 && dvd_device == NULL && argv[1][0] != '-') { dvd_device = argv[1]; } gtk_init(&argc, &argv); GtkCssProvider *css = gtk_css_provider_new(); error = NULL; gtk_css_provider_load_from_data(css, MyCSS, -1, &error); if (error == NULL) { GdkScreen *ss = gdk_screen_get_default(); gtk_style_context_add_provider_for_screen(ss, GTK_STYLE_PROVIDER(css), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); } else { g_warning("%s: %s", G_STRFUNC, error->message); g_clear_error(&error); } #if !defined(_WIN32) notify_init("HandBrake"); #endif ghb_resource_init(); ghb_load_icons(); #if !defined(_WIN32) dbus_g_thread_init(); #endif ghb_udev_init(); ghb_write_pid_file(); ud = g_malloc0(sizeof(signal_user_data_t)); ud->debug = ghb_debug; g_log_set_handler(NULL, G_LOG_LEVEL_DEBUG, debug_log_handler, ud); g_log_set_handler("Gtk", G_LOG_LEVEL_WARNING, warn_log_handler, ud); //g_log_set_handler("Gtk", G_LOG_LEVEL_CRITICAL, warn_log_handler, ud); ud->globals = ghb_dict_new(); ud->prefs = ghb_dict_new(); ud->settings_array = ghb_array_new(); ud->settings = ghb_dict_new(); ghb_array_append(ud->settings_array, ud->settings); ud->builder = create_builder_or_die(BUILDER_NAME); // Enable events that alert us to media change events watch_volumes(ud); //GtkWidget *widget = GHB_WIDGET(ud->builder, "PictureDetelecineCustom"); //gtk_entry_set_inner_border(widget, 2); // Since GtkBuilder no longer assigns object ids to widget names // Assign a few that are necessary for style overrides to work GtkWidget *widget; #if defined(_NO_UPDATE_CHECK) widget = GHB_WIDGET(ud->builder, "check_updates_box"); gtk_widget_hide(widget); #endif // Must set the names of the widgets that I want to modify // style for. gtk_widget_set_name(GHB_WIDGET(ud->builder, "preview_hud"), "preview_hud"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "preview_frame"), "preview_frame"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "live_preview_play"), "live_preview_play"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "live_preview_progress"), "live_preview_progress"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "live_encode_progress"), "live_encode_progress"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "live_duration"), "live_duration"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "preview_show_crop"), "preview_show_crop"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "preview_fullscreen"), "preview_fullscreen"); widget = GHB_WIDGET(ud->builder, "preview_hud"); gtk_widget_set_name(widget, "preview_hud"); widget = GHB_WIDGET(ud->builder, "preview_window"); gtk_widget_set_name(widget, "preview_window"); // Set up the "hud" control overlay for the preview window GtkWidget *preview_box, *draw, *hud, *blender; preview_box = GHB_WIDGET(ud->builder, "preview_window_box"); draw = GHB_WIDGET(ud->builder, "preview_image"); hud = GHB_WIDGET(ud->builder, "preview_hud"); #if 0 // GTK_CHECK_VERSION(3, 0, 0) // This uses the new GtkOverlay widget. // // Unfortunately, GtkOverlay is broken in a couple of ways. // // First, it doesn't respect gtk_widget_shape_combine_region() // on it's child overlays. It appears to just ignore the clip // mask of the child. // // Second, it doesn't respect window opacity. // // So for now, I'll just continue using my home-grown overlay // widget (GhbCompositor). blender = gtk_overlay_new(); gtk_container_add(GTK_CONTAINER(preview_box), blender); gtk_container_add(GTK_CONTAINER(blender), draw); gtk_widget_set_valign (hud, GTK_ALIGN_END); gtk_widget_set_halign (hud, GTK_ALIGN_CENTER); gtk_overlay_add_overlay(GTK_OVERLAY(blender), hud); g_signal_connect(G_OBJECT(blender), "get-child-position", G_CALLBACK(position_overlay_cb), ud); gtk_widget_show(blender); #else // Set up compositing for hud blender = ghb_compositor_new(); gtk_container_add(GTK_CONTAINER(preview_box), blender); ghb_compositor_zlist_insert(GHB_COMPOSITOR(blender), draw, 1, 1); ghb_compositor_zlist_insert(GHB_COMPOSITOR(blender), hud, 2, .85); gtk_widget_show(blender); #endif // Redirect stderr to the activity window ghb_preview_init(ud); IoRedirect(ud); ghb_log( "%s - %s - %s", HB_PROJECT_TITLE, HB_PROJECT_BUILD_TITLE, HB_PROJECT_URL_WEBSITE ); ghb_init_dep_map(); // Need to connect x264_options textview buffer to the changed signal // since it can't be done automatically GtkTextView *textview; GtkTextBuffer *buffer; textview = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "x264Option")); buffer = gtk_text_view_get_buffer(textview); g_signal_connect(buffer, "changed", (GCallback)x264_entry_changed_cb, ud); textview = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "VideoOptionExtra")); buffer = gtk_text_view_get_buffer(textview); g_signal_connect(buffer, "changed", (GCallback)video_option_changed_cb, ud); textview = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "MetaLongDescription")); buffer = gtk_text_view_get_buffer(textview); g_signal_connect(buffer, "changed", (GCallback)plot_changed_cb, ud); ghb_combo_init(ud); g_debug("ud %p\n", ud); g_debug("ud->builder %p\n", ud->builder); bind_audio_tree_model(ud); bind_subtitle_tree_model(ud); bind_presets_tree_model(ud); bind_queue_tree_model(ud); bind_chapter_tree_model(ud); // Connect up the signals to their callbacks // I wrote my own connector so that I could pass user data // to the callbacks. Builder's standard autoconnect doesn't all this. gtk_builder_connect_signals_full(ud->builder, MyConnect, ud); ghb_init_audio_defaults_ui(ud); ghb_init_subtitle_defaults_ui(ud); // Parsing x264 options "" initializes x264 widgets to proper defaults ghb_x264_init(ud); // Load prefs before presets. Some preset defaults may depend // on preference settings. // First load default values ghb_settings_init(ud->prefs, "Preferences"); ghb_settings_init(ud->globals, "Globals"); ghb_settings_init(ud->settings, "Initialization"); ghb_settings_init(ud->settings, "OneTimeInitialization"); // Load user preferences file ghb_prefs_load(ud); // Store user preferences into ud->prefs ghb_prefs_to_settings(ud->prefs); int logLevel = ghb_dict_get_int(ud->prefs, "LoggingLevel"); ghb_backend_init(logLevel); // Load the presets files ghb_presets_load(ud); // Note that ghb_preset_to_settings(ud->settings) is called when // the default preset is selected. ghb_settings_to_ui(ud, ud->globals); ghb_settings_to_ui(ud, ud->prefs); // Note that ghb_settings_to_ui(ud->settings) happens when initial // empty title is initialized. if (ghb_dict_get_bool(ud->prefs, "hbfd")) { ghb_hbfd(ud, TRUE); } const gchar *source = ghb_dict_get_string(ud->prefs, "default_source"); ghb_dvd_set_current(source, ud); // Populate the presets tree view ghb_presets_list_init(ud, NULL); // Get the first preset name if (arg_preset != NULL) { ghb_select_preset(ud->builder, arg_preset); } else { ghb_select_default_preset(ud->builder); } // Grey out widgets that are dependent on a disabled feature ghb_check_all_depencencies(ud); if (dvd_device != NULL) { // Source overridden from command line option ghb_dict_set_string(ud->globals, "scan_source", dvd_device); g_idle_add((GSourceFunc)ghb_idle_scan, ud); } else { GhbValue *gval = ghb_dict_get_value(ud->prefs, "default_source"); ghb_dict_set(ud->globals, "scan_source", ghb_value_dup(gval)); } // Reload and check status of the last saved queue g_idle_add((GSourceFunc)ghb_reload_queue, ud); // Start timer for monitoring libhb status, 500ms g_timeout_add(200, ghb_timer_cb, (gpointer)ud); // Add dvd devices to File menu ghb_volname_cache_init(); GHB_THREAD_NEW("Cache Volume Names", (GThreadFunc)ghb_cache_volnames, ud); GtkWidget *ghb_window = GHB_WIDGET(ud->builder, "hb_window"); gint window_width, window_height; GdkGeometry geo = { -1, -1, 1920, 768, -1, -1, 10, 10, 0, 0, GDK_GRAVITY_NORTH_WEST }; GdkWindowHints geo_mask; geo_mask = GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE | GDK_HINT_BASE_SIZE; gtk_window_set_geometry_hints(GTK_WINDOW(ghb_window), ghb_window, &geo, geo_mask); window_width = ghb_dict_get_int(ud->prefs, "window_width"); window_height = ghb_dict_get_int(ud->prefs, "window_height"); /* * Filter objects in GtkBuilder xml * Unfortunately, GtkFilter is poorly supported by GtkBuilder, * so a lot of the setup must happen in code. SourceFilterAll SourceFilterVideo SourceFilterTS SourceFilterMPG SourceFilterEVO SourceFilterVOB SourceFilterMKV SourceFilterMP4 SourceFilterAVI SourceFilterMOV SourceFilterOGG SourceFilterFLV SourceFilterWMV */ // Add filters to source chooser GtkFileFilter *filter; GtkFileChooser *chooser; chooser = GTK_FILE_CHOOSER(GHB_WIDGET(ud->builder, "source_dialog")); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterAll")); gtk_file_filter_set_name(filter, _("All")); gtk_file_filter_add_pattern(filter, "*"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterVideo")); gtk_file_filter_set_name(filter, _("Video")); gtk_file_filter_add_mime_type(filter, "video/*"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterTS")); gtk_file_filter_set_name(filter, "TS"); gtk_file_filter_add_pattern(filter, "*.ts"); gtk_file_filter_add_pattern(filter, "*.TS"); gtk_file_filter_add_pattern(filter, "*.m2ts"); gtk_file_filter_add_pattern(filter, "*.M2TS"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMPG")); gtk_file_filter_set_name(filter, "MPG"); gtk_file_filter_add_pattern(filter, "*.mpg"); gtk_file_filter_add_pattern(filter, "*.MPG"); gtk_file_filter_add_pattern(filter, "*.mepg"); gtk_file_filter_add_pattern(filter, "*.MEPG"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterEVO")); gtk_file_filter_set_name(filter, "EVO"); gtk_file_filter_add_pattern(filter, "*.evo"); gtk_file_filter_add_pattern(filter, "*.EVO"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterVOB")); gtk_file_filter_set_name(filter, "VOB"); gtk_file_filter_add_pattern(filter, "*.vob"); gtk_file_filter_add_pattern(filter, "*.VOB"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMKV")); gtk_file_filter_set_name(filter, "MKV"); gtk_file_filter_add_pattern(filter, "*.mkv"); gtk_file_filter_add_pattern(filter, "*.MKV"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMP4")); gtk_file_filter_set_name(filter, "MP4"); gtk_file_filter_add_pattern(filter, "*.mp4"); gtk_file_filter_add_pattern(filter, "*.MP4"); gtk_file_filter_add_pattern(filter, "*.m4v"); gtk_file_filter_add_pattern(filter, "*.M4V"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMOV")); gtk_file_filter_set_name(filter, "MOV"); gtk_file_filter_add_pattern(filter, "*.mov"); gtk_file_filter_add_pattern(filter, "*.MOV"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterAVI")); gtk_file_filter_set_name(filter, "AVI"); gtk_file_filter_add_pattern(filter, "*.avi"); gtk_file_filter_add_pattern(filter, "*.AVI"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterOGG")); gtk_file_filter_set_name(filter, "OGG"); gtk_file_filter_add_pattern(filter, "*.ogg"); gtk_file_filter_add_pattern(filter, "*.OGG"); gtk_file_filter_add_pattern(filter, "*.ogv"); gtk_file_filter_add_pattern(filter, "*.OGV"); gtk_file_filter_add_pattern(filter, "*.ogm"); gtk_file_filter_add_pattern(filter, "*.OGM"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterFLV")); gtk_file_filter_set_name(filter, "FLV"); gtk_file_filter_add_pattern(filter, "*.flv"); gtk_file_filter_add_pattern(filter, "*.FLV"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterWMV")); gtk_file_filter_set_name(filter, "WMV"); gtk_file_filter_add_pattern(filter, "*.wmv"); gtk_file_filter_add_pattern(filter, "*.WMV"); gtk_file_chooser_add_filter(chooser, filter); // Gtk has a really stupid bug. If the file chooser is showing // hidden files AND there is no filter set, it will not select // the filename when gtk_file_chooser_set_filename is called. // So add a completely unnessary filter to prevent this behavior. filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterAll")); gtk_file_chooser_set_filter(chooser, filter); PangoFontDescription *font_desc; font_desc = pango_font_description_from_string("monospace 10"); textview = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "activity_view")); gtk_widget_override_font(GTK_WIDGET(textview), font_desc); pango_font_description_free(font_desc); // Grrrr! Gtk developers !!!hard coded!!! the width of the // radio buttons in GtkStackSwitcher to 100!!! // // Thankfully, GtkStackSwitcher is a regular container object // and we can access the buttons to change their width. GList *stack_switcher_children, *link; GtkContainer * stack_switcher = GTK_CONTAINER( GHB_WIDGET(ud->builder, "SettingsStackSwitcher")); link = stack_switcher_children = gtk_container_get_children(stack_switcher); while (link != NULL) { GtkWidget *widget = link->data; gtk_widget_set_size_request(widget, -1, -1); gtk_widget_set_hexpand(widget, TRUE); gtk_widget_set_halign(widget, GTK_ALIGN_FILL); link = link->next; } g_list_free(stack_switcher_children); gtk_window_resize(GTK_WINDOW(ghb_window), window_width, window_height); gtk_widget_show(ghb_window); // Everything should be go-to-go. Lets rock! gtk_main(); ghb_backend_close(); ghb_value_free(&ud->queue); ghb_value_free(&ud->settings_array); ghb_value_free(&ud->prefs); ghb_value_free(&ud->globals); ghb_value_free(&ud->x264_priv); g_io_channel_unref(ud->activity_log); ghb_settings_close(); ghb_resource_free(); #if !defined(_WIN32) notify_uninit(); #endif g_object_unref(ud->builder); g_free(ud->current_dvd_device); g_free(ud); return 0; }
void daemon_main(FILE *logging_file) { pid_t daemon_sid; NotifyNotification *newconn_notification; struct addrinfo *servinfo; struct sockaddr_storage peer_addr; struct sigaction sa; long long sockfd, new_fd, nread, nwrote; socklen_t sin_size, peer_addr_len; char s[INET6_ADDRSTRLEN]; char tolog[255]; char notify_string[128]; char recv_buf[RECEPTION_BUFFER_SIZE]; memset(recv_buf, 0, sizeof(recv_buf)); logfile = logging_file; /* Set new sid to daemon */ if((daemon_sid = setsid()) < 0) { log_error(logfile, "Initialization", strerror(errno)); fclose(logfile); exit(EXIT_FAILURE); } /* Set up signal handler */ if(signal(SIGTERM, signal_handler) == SIG_ERR) { log_error(logfile, "Initialization", "Failed to register TERM signal handler\n"); fclose(logfile); exit(EXIT_FAILURE); } if((servinfo = get_local_addrinfo(PORT)) == NULL) { log_error(logfile, "Initialisation", "Failed to get local address info\n"); fclose(logfile); exit(EXIT_FAILURE); } if((sockfd = find_n_bind(servinfo)) < 0) { log_error(logfile, "Initialization", "Failed to get a writable socket\n"); fclose(logfile); exit(EXIT_FAILURE); } freeaddrinfo(servinfo); if (listen(sockfd, BACKLOG) < 0) { log_error(logfile, "Initialization", "Failed to setup listenning\n"); exit(EXIT_FAILURE); } sa.sa_handler = sigchld_handler; sigemptyset(&sa.sa_mask); sa.sa_flags = SA_RESTART; if (sigaction(SIGCHLD, &sa, NULL) < 0) { log_error(logfile, "Initialization", "Failed to setup sigaction\n"); exit(EXIT_FAILURE); } /* Daemon initialisation complete */ log_event(logfile, "Initialization", "Startup complete"); fflush(logfile); /* Do daemon job until stop signal received */ while(1) { sin_size = sizeof(peer_addr); if((new_fd = accept(sockfd, (struct sockaddr*)&peer_addr, &sin_size)) < 0) { log_error(logfile, "Runtime", "Failed to accept new connection, retrying\n"); continue; } inet_ntop(peer_addr.ss_family, get_in_addr((struct sockaddr*)&peer_addr), s, sizeof(s)); sprintf(tolog, "Got connection from %s", s); log_event(logfile, "Runtime", tolog); if(fork() == 0) { FILE *destfile = fopen(DESTFILEPATH, "w"); close(sockfd); notify_init ("Sfttd listening now"); sprintf(notify_string, "New data from %s", s); newconn_notification = notify_notification_new(notify_string, "Run 'sisefit list' for more details", PIXFILEPATH); notify_notification_show(newconn_notification, NULL); notify_uninit (); peer_addr_len = sizeof(peer_addr); while((nread = recvfrom(new_fd, recv_buf, RECEPTION_BUFFER_SIZE, 0, (struct sockaddr *) &peer_addr, &peer_addr_len)) > 0) { nwrote = fwrite(&recv_buf, sizeof(char), nread, destfile); if(ferror(destfile) != 0){ log_error(logfile, "New connection", "Failed to write to file"); clearerr(destfile); break; } memset(recv_buf, 0, sizeof(recv_buf)); } if(nread == -1) log_error(logfile, "New connection", "Failed to receive data"); else if(HASHOK){ sprintf(tolog, "Data successfully wrote in file"); log_event(logfile, "New conection", tolog); } close(new_fd); fclose(destfile); fclose(logfile); exit(EXIT_SUCCESS); } } /* Close logging file and return */ fclose(logfile); return; }
int main(int argc, char *argv[]) { signal_user_data_t *ud; GValue *preset; GError *error = NULL; GOptionContext *context; #ifdef ENABLE_NLS bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); #endif context = g_option_context_new("- Transcode media formats"); g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE); g_option_context_add_group(context, gtk_get_option_group(TRUE)); #if defined(_ENABLE_GST) g_option_context_add_group(context, gst_init_get_option_group()); #endif g_option_context_parse(context, &argc, &argv, &error); if (error != NULL) { g_warning("%s: %s", G_STRFUNC, error->message); g_clear_error(&error); } g_option_context_free(context); if (argc > 1 && dvd_device == NULL && argv[1][0] != '-') { dvd_device = argv[1]; } gtk_init(&argc, &argv); #if GTK_CHECK_VERSION(3, 0, 0) GtkCssProvider *css = gtk_css_provider_new(); error = NULL; gtk_css_provider_load_from_data(css, MyCSS, -1, &error); if (error == NULL) { GdkScreen *ss = gdk_screen_get_default(); gtk_style_context_add_provider_for_screen(ss, GTK_STYLE_PROVIDER(css), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); } else { g_warning("%s: %s", G_STRFUNC, error->message); g_clear_error(&error); } #else gtk_rc_parse_string(hud_rcstyle); #endif g_type_class_unref(g_type_class_ref(GTK_TYPE_BUTTON)); g_object_set(gtk_settings_get_default(), "gtk-button-images", TRUE, NULL); #if !defined(_WIN32) notify_init("HandBrake"); #endif ghb_register_transforms(); ghb_resource_init(); ghb_load_icons(); #if !defined(_WIN32) dbus_g_thread_init(); #endif ghb_udev_init(); ghb_write_pid_file(); ud = g_malloc0(sizeof(signal_user_data_t)); ud->debug = ghb_debug; g_log_set_handler(NULL, G_LOG_LEVEL_DEBUG, debug_log_handler, ud); g_log_set_handler("Gtk", G_LOG_LEVEL_WARNING, warn_log_handler, ud); //g_log_set_handler("Gtk", G_LOG_LEVEL_CRITICAL, warn_log_handler, ud); ud->settings = ghb_settings_new(); ud->builder = create_builder_or_die(BUILDER_NAME); // Enable events that alert us to media change events watch_volumes(ud); //GtkWidget *widget = GHB_WIDGET(ud->builder, "PictureDetelecineCustom"); //gtk_entry_set_inner_border(widget, 2); // Since GtkBuilder no longer assigns object ids to widget names // Assign a few that are necessary for style overrides to work GtkWidget *widget; #if defined(_NO_UPDATE_CHECK) widget = GHB_WIDGET(ud->builder, "check_updates_box"); gtk_widget_hide(widget); #endif // Must set the names of the widgets that I want to modify // style for. gtk_widget_set_name(GHB_WIDGET(ud->builder, "preview_event_box"), "preview_event_box"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "preview_frame"), "preview_frame"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "live_preview_play"), "live_preview_play"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "live_preview_progress"), "live_preview_progress"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "live_encode_progress"), "live_encode_progress"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "live_duration"), "live_duration"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "preview_show_crop"), "preview_show_crop"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "preview_fullscreen"), "preview_fullscreen"); gtk_widget_set_name(GHB_WIDGET(ud->builder, "hide_settings"), "hide_settings"); widget = GHB_WIDGET(ud->builder, "preview_hud"); gtk_widget_set_name(widget, "preview_hud"); widget = GHB_WIDGET(ud->builder, "preview_window"); gtk_widget_set_name(widget, "preview_window"); // Set up the "hud" control overlay for the preview window GtkWidget *align, *draw, *hud, *blender; align = GHB_WIDGET(ud->builder, "preview_window_alignment"); draw = GHB_WIDGET(ud->builder, "preview_image_align"); hud = GHB_WIDGET(ud->builder, "preview_hud"); #if 0 // wGTK_CHECK_VERSION(3, 0, 0) // This uses the new GtkOverlay widget. // // Unfortunately, GtkOverlay is broken in a couple of ways. // // First, it doesn't respect gtk_widget_shape_combine_region() // on it's child overlays. It appears to just ignore the clip // mask of the child. // // Second, it doesn't respect window opacity. // // So for now, I'll just continue using my home-grown overlay // widget (GhbCompositor). blender = gtk_overlay_new(); gtk_container_add(GTK_CONTAINER(align), blender); gtk_container_add(GTK_CONTAINER(blender), draw); gtk_widget_set_valign (hud, GTK_ALIGN_END); gtk_widget_set_halign (hud, GTK_ALIGN_CENTER); gtk_overlay_add_overlay(GTK_OVERLAY(blender), hud); g_signal_connect(G_OBJECT(blender), "get-child-position", G_CALLBACK(position_overlay_cb), ud); gtk_widget_show(blender); #else // Set up compositing for hud blender = ghb_compositor_new(); gtk_container_add(GTK_CONTAINER(align), blender); ghb_compositor_zlist_insert(GHB_COMPOSITOR(blender), draw, 1, 1); ghb_compositor_zlist_insert(GHB_COMPOSITOR(blender), hud, 2, .85); gtk_widget_show(blender); #endif // Redirect stderr to the activity window ghb_preview_init(ud); IoRedirect(ud); ghb_log( "%s - %s - %s", HB_PROJECT_TITLE, HB_PROJECT_BUILD_TITLE, HB_PROJECT_URL_WEBSITE ); ghb_init_dep_map(); // Need to connect x264_options textview buffer to the changed signal // since it can't be done automatically GtkTextView *textview; GtkTextBuffer *buffer; textview = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "x264Option")); buffer = gtk_text_view_get_buffer(textview); g_signal_connect(buffer, "changed", (GCallback)x264_entry_changed_cb, ud); textview = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "x264OptionExtra")); buffer = gtk_text_view_get_buffer(textview); g_signal_connect(buffer, "changed", (GCallback)x264_option_changed_cb, ud); ghb_combo_init(ud); g_debug("ud %p\n", ud); g_debug("ud->builder %p\n", ud->builder); bind_audio_tree_model(ud); bind_subtitle_tree_model(ud); bind_presets_tree_model(ud); bind_queue_tree_model(ud); bind_chapter_tree_model(ud); // Connect up the signals to their callbacks // I wrote my own connector so that I could pass user data // to the callbacks. Builder's standard autoconnect doesn't all this. gtk_builder_connect_signals_full(ud->builder, MyConnect, ud); GtkWidget *presetSlider = GHB_WIDGET(ud->builder, "x264PresetSlider"); const char * const *x264_presets; int count = 0; x264_presets = hb_x264_presets(); while (x264_presets && x264_presets[count]) count++; gtk_range_set_range(GTK_RANGE(presetSlider), 0, count-1); // Load all internal settings ghb_settings_init(ud); // Load the presets files ghb_presets_load(ud); ghb_prefs_load(ud); ghb_prefs_to_ui(ud); gint logLevel; logLevel = ghb_settings_get_int(ud->settings, "LoggingLevel"); ghb_backend_init(logLevel); if (ghb_settings_get_boolean(ud->settings, "hbfd")) { ghb_hbfd(ud, TRUE); } gchar *source = ghb_settings_get_string(ud->settings, "default_source"); ghb_dvd_set_current(source, ud); g_free(source); // Parsing x264 options "" initializes x264 widgets to proper defaults ghb_x264_parse_options(ud, ""); // Populate the presets tree view ghb_presets_list_init(ud, NULL, 0); // Get the first preset name if (arg_preset != NULL) { preset = ghb_parse_preset_path(arg_preset); if (preset) { ghb_select_preset(ud->builder, preset); ghb_value_free(preset); } } else { ghb_select_default_preset(ud->builder); } // Grey out widgets that are dependent on a disabled feature ghb_check_all_depencencies(ud); if (dvd_device != NULL) { // Source overridden from command line option ghb_settings_set_string(ud->settings, "scan_source", dvd_device); g_idle_add((GSourceFunc)ghb_idle_scan, ud); } // Reload and check status of the last saved queue g_idle_add((GSourceFunc)ghb_reload_queue, ud); // Start timer for monitoring libhb status, 500ms g_timeout_add(500, ghb_timer_cb, (gpointer)ud); // Add dvd devices to File menu ghb_volname_cache_init(); GHB_THREAD_NEW("Cache Volume Names", (GThreadFunc)ghb_cache_volnames, ud); #if defined(_USE_APP_IND) GtkUIManager * uim = GTK_UI_MANAGER(GHB_OBJECT(ud->builder, "uimanager1")); GtkMenu *ai_menu = GTK_MENU(gtk_ui_manager_get_widget(uim, "/ui/tray_menu")); ud->ai = app_indicator_new("HandBrake", "hb-icon", APP_INDICATOR_CATEGORY_APPLICATION_STATUS); app_indicator_set_menu( ud->ai, ai_menu ); app_indicator_set_label( ud->ai, "", "99.99%"); if (ghb_settings_get_boolean(ud->settings, "show_status")) { app_indicator_set_status( ud->ai, APP_INDICATOR_STATUS_ACTIVE ); } else { app_indicator_set_status( ud->ai, APP_INDICATOR_STATUS_PASSIVE ); } GtkStatusIcon *si; si = GTK_STATUS_ICON(GHB_OBJECT(ud->builder, "hb_status")); gtk_status_icon_set_visible(si, FALSE ); #else GtkStatusIcon *si; si = GTK_STATUS_ICON(GHB_OBJECT(ud->builder, "hb_status")); gtk_status_icon_set_visible(si, ghb_settings_get_boolean(ud->settings, "show_status")); #if GTK_CHECK_VERSION(2, 16, 0) gtk_status_icon_set_has_tooltip(si, TRUE); g_signal_connect(si, "query-tooltip", status_icon_query_tooltip_cb, ud); #else gtk_status_icon_set_tooltip(si, "HandBrake"); #endif #endif // Ugly hack to keep subtitle table from bouncing around as I change // which set of controls are visible gint width, height; #if GTK_CHECK_VERSION(3, 0, 0) GtkRequisition min_size, size; widget = GHB_WIDGET(ud->builder, "SrtCodeset"); gtk_widget_get_preferred_size( widget, &min_size, &size ); height = MAX(min_size.height, size.height); widget = GHB_WIDGET(ud->builder, "srt_code_label"); gtk_widget_get_preferred_size( widget, &min_size, &size ); height += MAX(min_size.height, size.height); widget = GHB_WIDGET(ud->builder, "subtitle_table"); gtk_widget_set_size_request(widget, -1, height); #else GtkRequisition size; widget = GHB_WIDGET(ud->builder, "SrtCodeset"); gtk_widget_size_request( widget, &size ); height = size.height; widget = GHB_WIDGET(ud->builder, "srt_code_label"); gtk_widget_size_request( widget, &size ); height += size.height; widget = GHB_WIDGET(ud->builder, "subtitle_table"); gtk_widget_set_size_request(widget, -1, height); #endif widget = GHB_WIDGET(ud->builder, "hb_window"); GdkGeometry geo = { -1, -1, 1024, 768, -1, -1, 10, 10, 0, 0, GDK_GRAVITY_NORTH_WEST }; GdkWindowHints geo_mask; geo_mask = GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE | GDK_HINT_BASE_SIZE; gtk_window_set_geometry_hints( GTK_WINDOW(widget), widget, &geo, geo_mask); width = ghb_settings_get_int(ud->settings, "window_width"); height = ghb_settings_get_int(ud->settings, "window_height"); gtk_window_resize(GTK_WINDOW(widget), width, height); gtk_widget_show(widget); /* * Filter objects in GtkBuilder xml * Unfortunately, GtkFilter is poorly supported by GtkBuilder, * so a lot of the setup must happen in code. SourceFilterAll SourceFilterVideo SourceFilterTS SourceFilterMPG SourceFilterEVO SourceFilterVOB SourceFilterMKV SourceFilterMP4 SourceFilterAVI SourceFilterMOV SourceFilterOGG SourceFilterFLV SourceFilterWMV */ // Add filters to source chooser GtkFileFilter *filter; GtkFileChooser *chooser; chooser = GTK_FILE_CHOOSER(GHB_WIDGET(ud->builder, "source_dialog")); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterAll")); gtk_file_filter_set_name(filter, "All"); gtk_file_filter_add_pattern(filter, "*"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterVideo")); gtk_file_filter_set_name(filter, "Video"); gtk_file_filter_add_mime_type(filter, "video/*"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterTS")); gtk_file_filter_set_name(filter, "TS"); gtk_file_filter_add_pattern(filter, "*.ts"); gtk_file_filter_add_pattern(filter, "*.TS"); gtk_file_filter_add_pattern(filter, "*.m2ts"); gtk_file_filter_add_pattern(filter, "*.M2TS"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMPG")); gtk_file_filter_set_name(filter, "MPG"); gtk_file_filter_add_pattern(filter, "*.mpg"); gtk_file_filter_add_pattern(filter, "*.MPG"); gtk_file_filter_add_pattern(filter, "*.mepg"); gtk_file_filter_add_pattern(filter, "*.MEPG"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterEVO")); gtk_file_filter_set_name(filter, "EVO"); gtk_file_filter_add_pattern(filter, "*.evo"); gtk_file_filter_add_pattern(filter, "*.EVO"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterVOB")); gtk_file_filter_set_name(filter, "VOB"); gtk_file_filter_add_pattern(filter, "*.vob"); gtk_file_filter_add_pattern(filter, "*.VOB"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMKV")); gtk_file_filter_set_name(filter, "MKV"); gtk_file_filter_add_pattern(filter, "*.mkv"); gtk_file_filter_add_pattern(filter, "*.MKV"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMP4")); gtk_file_filter_set_name(filter, "MP4"); gtk_file_filter_add_pattern(filter, "*.mp4"); gtk_file_filter_add_pattern(filter, "*.MP4"); gtk_file_filter_add_pattern(filter, "*.m4v"); gtk_file_filter_add_pattern(filter, "*.M4V"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterMOV")); gtk_file_filter_set_name(filter, "MOV"); gtk_file_filter_add_pattern(filter, "*.mov"); gtk_file_filter_add_pattern(filter, "*.MOV"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterAVI")); gtk_file_filter_set_name(filter, "AVI"); gtk_file_filter_add_pattern(filter, "*.avi"); gtk_file_filter_add_pattern(filter, "*.AVI"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterOGG")); gtk_file_filter_set_name(filter, "OGG"); gtk_file_filter_add_pattern(filter, "*.ogg"); gtk_file_filter_add_pattern(filter, "*.OGG"); gtk_file_filter_add_pattern(filter, "*.ogv"); gtk_file_filter_add_pattern(filter, "*.OGV"); gtk_file_filter_add_pattern(filter, "*.ogm"); gtk_file_filter_add_pattern(filter, "*.OGM"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterFLV")); gtk_file_filter_set_name(filter, "FLV"); gtk_file_filter_add_pattern(filter, "*.flv"); gtk_file_filter_add_pattern(filter, "*.FLV"); gtk_file_chooser_add_filter(chooser, filter); filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterWMV")); gtk_file_filter_set_name(filter, "WMV"); gtk_file_filter_add_pattern(filter, "*.wmv"); gtk_file_filter_add_pattern(filter, "*.WMV"); gtk_file_chooser_add_filter(chooser, filter); // Gtk has a really stupid bug. If the file chooser is showing // hidden files AND there is no filter set, it will not select // the filename when gtk_file_chooser_set_filename is called. // So add a completely unnessary filter to prevent this behavior. filter = GTK_FILE_FILTER(GHB_OBJECT(ud->builder, "SourceFilterAll")); gtk_file_chooser_set_filter(chooser, filter); PangoFontDescription *font_desc; font_desc = pango_font_description_from_string("monospace 10"); textview = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "activity_view")); gtk_widget_modify_font(GTK_WIDGET(textview), font_desc); pango_font_description_free(font_desc); // Everything should be go-to-go. Lets rock! gtk_main(); gtk_status_icon_set_visible(si, FALSE); ghb_backend_close(); if (ud->queue) ghb_value_free(ud->queue); ghb_value_free(ud->settings); g_io_channel_unref(ud->activity_log); ghb_settings_close(); #if !defined(_WIN32) notify_uninit(); #endif g_free(ud); return 0; }
static void _notify(const char * const message, int timeout, const char * const category) { #ifdef HAVE_LIBNOTIFY log_debug("Attempting notification: %s", message); if (notify_is_initted()) { log_debug("Reinitialising libnotify"); notify_uninit(); notify_init("Profanity"); } else { log_debug("Initialising libnotify"); notify_init("Profanity"); } if (notify_is_initted()) { NotifyNotification *notification; notification = notify_notification_new("Profanity", message, NULL); notify_notification_set_timeout(notification, timeout); notify_notification_set_category(notification, category); notify_notification_set_urgency(notification, NOTIFY_URGENCY_NORMAL); GError *error = NULL; gboolean notify_success = notify_notification_show(notification, &error); if (!notify_success) { log_error("Error sending desktop notification:"); log_error(" -> Message : %s", message); log_error(" -> Error : %s", error->message); } else { log_debug("Notification sent."); } } else { log_error("Libnotify not initialised."); } #endif #ifdef PLATFORM_CYGWIN NOTIFYICONDATA nid; nid.cbSize = sizeof(NOTIFYICONDATA); //nid.hWnd = hWnd; nid.uID = 100; nid.uVersion = NOTIFYICON_VERSION; //nid.uCallbackMessage = WM_MYMESSAGE; nid.hIcon = LoadIcon(NULL, IDI_APPLICATION); strncpy(nid.szTip, "Tray Icon", 10); nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; Shell_NotifyIcon(NIM_ADD, &nid); // For a Ballon Tip nid.uFlags = NIF_INFO; strncpy(nid.szInfoTitle, "Profanity", 10); // Title strncpy(nid.szInfo, message, 256); // Copy Tip nid.uTimeout = timeout; // 3 Seconds nid.dwInfoFlags = NIIF_INFO; Shell_NotifyIcon(NIM_MODIFY, &nid); #endif #ifdef HAVE_OSXNOTIFY GString *notify_command = g_string_new("terminal-notifier -title \"Profanity\" -message \""); char *escaped_double = str_replace(message, "\"", "\\\""); char *escaped_single = str_replace(escaped_double, "`", "\\`"); if (escaped_single[0] == '<') { g_string_append(notify_command, "\\<"); g_string_append(notify_command, &escaped_single[1]); } else if (escaped_single[0] == '[') { g_string_append(notify_command, "\\["); g_string_append(notify_command, &escaped_single[1]); } else if (escaped_single[0] == '(') { g_string_append(notify_command, "\\("); g_string_append(notify_command, &escaped_single[1]); } else if (escaped_single[0] == '{') { g_string_append(notify_command, "\\{"); g_string_append(notify_command, &escaped_single[1]); } else { g_string_append(notify_command, escaped_single); } g_string_append(notify_command, "\""); free(escaped_double); free(escaped_single); char *term_name = getenv("TERM_PROGRAM"); char *app_id = NULL; if (g_strcmp0(term_name, "Apple_Terminal") == 0) { app_id = "com.apple.Terminal"; } else if (g_strcmp0(term_name, "iTerm.app") == 0) { app_id = "com.googlecode.iterm2"; } if (app_id != NULL) { g_string_append(notify_command, " -sender "); g_string_append(notify_command, app_id); } int res = system(notify_command->str); if (res == -1) { log_error("Could not send desktop notificaion."); } g_string_free(notify_command, TRUE); #endif }
static gboolean plugin_unload(PurplePlugin *plugin) { gpointer handle; handle = purple_plugins_find_with_id(purple_events_get_plugin_id()); g_return_val_if_fail(handle != NULL, FALSE); purple_signal_disconnect( handle, "user_presence-online", plugin, (PurpleCallback)_purple_notify_plus_signed_on ); purple_signal_disconnect( handle, "user_presence-offline", plugin, (PurpleCallback)_purple_notify_plus_signed_off ); purple_signal_disconnect( handle, "user_presence-away", plugin, (PurpleCallback)_purple_notify_plus_away ); purple_signal_disconnect( handle, "user_presence-back", plugin, (PurpleCallback)_purple_notify_plus_back ); purple_signal_disconnect( handle, "user_presence-idle", plugin, (PurpleCallback)_purple_notify_plus_idle ); purple_signal_disconnect( handle, "user_presence-idle-back", plugin, (PurpleCallback)_purple_notify_plus_idle_back ); purple_signal_disconnect( handle, "user_presence-message", plugin, (PurpleCallback)_purple_notify_plus_status ); purple_signal_disconnect( handle, "user_im-received", plugin, (PurpleCallback)_purple_notify_plus_im_message ); purple_signal_disconnect( handle, "user_im-highlight", plugin, (PurpleCallback)_purple_notify_plus_im_highlight ); purple_signal_disconnect( handle, "user_chat-received", plugin, (PurpleCallback)_purple_notify_plus_chat_message ); purple_signal_disconnect( handle, "user_chat-highlight", plugin, (PurpleCallback)_purple_notify_plus_chat_highlight ); purple_signal_disconnect( handle, "user_email-arrived", plugin, (PurpleCallback)_purple_notify_plus_email ); notify_uninit(); return TRUE; }
/* FIXME: Cleanup track refs */ void common_cleanup(struct con_win *cwin) { CDEBUG(DBG_INFO, "Cleaning up"); if ((cwin->cstate->state == ST_STOPPED) && (cwin->cstate->curr_mobj_clear)) delete_musicobject(cwin->cstate->curr_mobj); if ((cwin->cstate->state == ST_PLAYING) || (cwin->cstate->state == ST_PAUSED)) stop_playback(cwin); save_preferences(cwin); g_object_unref(cwin->library_store); g_object_unref(cwin->pixbuf->image_play); g_object_unref(cwin->pixbuf->image_pause); if (cwin->pixbuf->pixbuf_app) g_object_unref(cwin->pixbuf->pixbuf_app); if (cwin->pixbuf->pixbuf_dir) g_object_unref(cwin->pixbuf->pixbuf_dir); if (cwin->pixbuf->pixbuf_artist) g_object_unref(cwin->pixbuf->pixbuf_artist); if (cwin->pixbuf->pixbuf_album) g_object_unref(cwin->pixbuf->pixbuf_album); if (cwin->pixbuf->pixbuf_track) g_object_unref(cwin->pixbuf->pixbuf_track); if (cwin->pixbuf->pixbuf_genre) g_object_unref(cwin->pixbuf->pixbuf_genre); g_slice_free(struct pixbuf, cwin->pixbuf); if (cwin->album_art) gtk_widget_destroy(cwin->album_art); if (cwin->cstate->cdda_drive) cdio_cddap_close(cwin->cstate->cdda_drive); if (cwin->cstate->cddb_disc) cddb_disc_destroy(cwin->cstate->cddb_disc); if (cwin->cstate->cddb_conn) { cddb_destroy(cwin->cstate->cddb_conn); libcddb_shutdown(); } g_free(cwin->cpref->lw.lastfm_user); g_free(cwin->cpref->lw.lastfm_pass); #ifdef HAVE_LIBGLYR g_free(cwin->cpref->cache_folder); #endif g_free(cwin->cpref->configrc_file); g_free(cwin->cpref->installed_version); g_free(cwin->cpref->audio_sink); g_free(cwin->cpref->audio_alsa_device); g_free(cwin->cpref->audio_oss_device); g_free(cwin->cpref->album_art_pattern); g_free(cwin->cpref->audio_cd_device); g_free(cwin->cpref->start_mode); g_free(cwin->cpref->sidebar_pane); g_key_file_free(cwin->cpref->configrc_keyfile); free_str_list(cwin->cpref->library_dir); free_str_list(cwin->cpref->lib_add); free_str_list(cwin->cpref->lib_delete); free_str_list(cwin->cpref->library_tree_nodes); free_str_list(cwin->cpref->playlist_columns); g_slist_free(cwin->cpref->playlist_column_widths); g_slice_free(struct con_pref, cwin->cpref); g_rand_free(cwin->cstate->rand); g_free(cwin->cstate->last_folder); g_mutex_free(cwin->cstate->c_mutex); /* Hack, hack */ if (g_mutex_trylock(cwin->cstate->l_mutex) == TRUE) { g_mutex_unlock(cwin->cstate->l_mutex); g_mutex_free(cwin->cstate->l_mutex); } g_cond_free(cwin->cstate->c_cond); g_slice_free(struct con_state, cwin->cstate); #ifdef HAVE_LIBGLYR uninit_glyr_related (cwin); #endif g_free(cwin->cdbase->db_file); sqlite3_close(cwin->cdbase->db); g_slice_free(struct con_dbase, cwin->cdbase); if (cwin->cstate->audio_init && cwin->cmixer) cwin->cmixer->deinit_mixer(cwin); if (cwin->clibao->ao_dev) { CDEBUG(DBG_INFO, "Freeing ao dev"); ao_close(cwin->clibao->ao_dev); } ao_shutdown(); g_slice_free(struct con_mixer, cwin->cmixer); g_slice_free(struct con_libao, cwin->clibao); g_free(cwin->clastfm->session_id); g_free(cwin->clastfm->submission_url); if (cwin->clastfm->curl_handle) curl_easy_cleanup(cwin->clastfm->curl_handle); curl_global_cleanup(); g_slice_free(struct con_lastfm, cwin->clastfm); dbus_connection_remove_filter(cwin->con_dbus, dbus_filter_handler, cwin); dbus_bus_remove_match(cwin->con_dbus, "type='signal',path='/org/pragha/DBus'", NULL); dbus_connection_unref(cwin->con_dbus); #if HAVE_GLIB_2_26 mpris_cleanup(cwin); #endif if (notify_is_initted()) notify_uninit(); #ifdef HAVE_LIBKEYBINDER keybinder_unbind("XF86AudioPlay", (KeybinderHandler) keybind_play_handler); keybinder_unbind("XF86AudioStop", (KeybinderHandler) keybind_stop_handler); keybinder_unbind("XF86AudioPrev", (KeybinderHandler) keybind_prev_handler); keybinder_unbind("XF86AudioNext", (KeybinderHandler) keybind_next_handler); keybinder_unbind("XF86AudioMedia", (KeybinderHandler) keybind_media_handler); #endif g_option_context_free(cwin->cmd_context); g_slice_free(struct con_win, cwin); }
int main (int argc, char *argv[]) { signal_user_data_t *ud; GValue *preset; GError *error = NULL; GOptionContext *context; #ifdef ENABLE_NLS bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif if (!g_thread_supported()) g_thread_init(NULL); context = g_option_context_new ("- Rip and encode DVD or MPEG file"); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); #if !defined(_WIN32) g_option_context_add_group (context, gst_init_get_option_group ()); #endif g_option_context_parse (context, &argc, &argv, &error); g_option_context_free(context); if (argc > 1 && dvd_device == NULL && argv[1][0] != '-') { dvd_device = argv[1]; } gtk_set_locale (); gtk_init (&argc, &argv); gtk_rc_parse_string(hud_rcstyle); g_type_class_unref(g_type_class_ref(GTK_TYPE_BUTTON)); g_object_set(gtk_settings_get_default(), "gtk-button-images", TRUE, NULL); #if !defined(_WIN32) notify_init("HandBrake"); #endif ghb_register_transforms(); ghb_resource_init(); ghb_load_icons(); #if !defined(_WIN32) dbus_g_thread_init(); #endif ghb_udev_init(); ghb_write_pid_file(); ud = g_malloc0(sizeof(signal_user_data_t)); ud->debug = ghb_debug; g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, debug_log_handler, ud); g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, warn_log_handler, ud); //g_log_set_handler ("Gtk", G_LOG_LEVEL_CRITICAL, warn_log_handler, ud); ud->settings = ghb_settings_new(); ud->builder = create_builder_or_die (BUILDER_NAME); // Enable events that alert us to media change events watch_volumes (ud); //GtkWidget *widget = GHB_WIDGET(ud->builder, "PictureDetelecineCustom"); //gtk_entry_set_inner_border(widget, 2); // Since GtkBuilder no longer assigns object ids to widget names // Assign a few that are necessary for style overrides to work GtkWidget *widget; #if defined(_NO_UPDATE_CHECK) widget = GHB_WIDGET(ud->builder, "check_updates_box"); gtk_widget_hide(widget); #endif widget = GHB_WIDGET(ud->builder, "preview_hud"); gtk_widget_set_name(widget, "preview_hud"); widget = GHB_WIDGET(ud->builder, "preview_window"); gtk_widget_set_name(widget, "preview_window"); // Set up the "hud" control overlay for the preview window GtkWidget *draw, *hud, *blender, *align; align = GHB_WIDGET(ud->builder, "preview_window_alignment"); draw = GHB_WIDGET(ud->builder, "preview_image_align"); hud = GHB_WIDGET(ud->builder, "preview_hud"); // Set up compositing for hud blender = ghb_compositor_new(); gtk_container_add(GTK_CONTAINER(align), blender); ghb_compositor_zlist_insert(GHB_COMPOSITOR(blender), draw, 1, 1); ghb_compositor_zlist_insert(GHB_COMPOSITOR(blender), hud, 2, .85); gtk_widget_show(blender); // Redirect stderr to the activity window ghb_preview_init(ud); IoRedirect(ud); ghb_log( "%s - %s - %s", HB_PROJECT_TITLE, HB_PROJECT_BUILD_TITLE, HB_PROJECT_URL_WEBSITE ); ghb_init_dep_map(); // Need to connect x264_options textview buffer to the changed signal // since it can't be done automatically GtkTextView *textview; GtkTextBuffer *buffer; textview = GTK_TEXT_VIEW(GHB_WIDGET (ud->builder, "x264Option")); buffer = gtk_text_view_get_buffer (textview); g_signal_connect(buffer, "changed", (GCallback)x264_entry_changed_cb, ud); ghb_combo_init(ud); g_debug("ud %p\n", ud); g_debug("ud->builder %p\n", ud->builder); bind_audio_tree_model(ud); bind_subtitle_tree_model(ud); bind_presets_tree_model(ud); bind_queue_tree_model(ud); bind_chapter_tree_model(ud); // Connect up the signals to their callbacks // I wrote my own connector so that I could pass user data // to the callbacks. Builder's standard autoconnect doesn't all this. gtk_builder_connect_signals_full (ud->builder, MyConnect, ud); // Load all internal settings ghb_settings_init(ud); // Load the presets files ghb_presets_load(ud); ghb_prefs_load(ud); ghb_prefs_to_ui(ud); gint logLevel; logLevel = ghb_settings_get_int(ud->settings, "LoggingLevel"); ghb_backend_init(logLevel); if (ghb_settings_get_boolean(ud->settings, "hbfd")) { ghb_hbfd(ud, TRUE); } gchar *source = ghb_settings_get_string(ud->settings, "default_source"); ghb_dvd_set_current(source, ud); g_free(source); // Parsing x264 options "" initializes x264 widgets to proper defaults ghb_x264_parse_options(ud, ""); // Populate the presets tree view ghb_presets_list_init(ud, NULL, 0); // Get the first preset name if (arg_preset != NULL) { preset = ghb_parse_preset_path(arg_preset); if (preset) { ghb_select_preset(ud->builder, preset); ghb_value_free(preset); } } else { ghb_select_default_preset(ud->builder); } // Grey out widgets that are dependent on a disabled feature ghb_check_all_depencencies (ud); if (dvd_device != NULL) { // Source overridden from command line option ghb_settings_set_string(ud->settings, "scan_source", dvd_device); g_idle_add((GSourceFunc)ghb_idle_scan, ud); } // Reload and check status of the last saved queue g_idle_add((GSourceFunc)ghb_reload_queue, ud); // Start timer for monitoring libhb status, 500ms g_timeout_add (500, ghb_timer_cb, (gpointer)ud); // Add dvd devices to File menu ghb_volname_cache_init(); g_thread_create((GThreadFunc)ghb_cache_volnames, ud, FALSE, NULL); GtkStatusIcon *si; si = GTK_STATUS_ICON(GHB_OBJECT(ud->builder, "hb_status")); gtk_status_icon_set_visible(si, ghb_settings_get_boolean(ud->settings, "show_status")); #if GTK_CHECK_VERSION(2, 16, 0) gtk_status_icon_set_has_tooltip(si, TRUE); g_signal_connect(si, "query-tooltip", status_icon_query_tooltip_cb, ud); #else gtk_status_icon_set_tooltip(si, "HandBrake"); #endif // Ugly hack to keep subtitle table from bouncing around as I change // which set of controls are visible GtkRequisition req; gint height; widget = GHB_WIDGET(ud->builder, "SrtCodeset"); gtk_widget_size_request( widget, &req ); height = req.height; widget = GHB_WIDGET(ud->builder, "srt_code_label"); gtk_widget_size_request( widget, &req ); height += req.height; widget = GHB_WIDGET(ud->builder, "subtitle_table"); gtk_widget_set_size_request(widget, -1, height); // Everything should be go-to-go. Lets rock! gtk_main (); gtk_status_icon_set_visible(si, FALSE); ghb_backend_close(); if (ud->queue) ghb_value_free(ud->queue); ghb_value_free(ud->settings); g_io_channel_unref(ud->activity_log); ghb_settings_close(); #if !defined(_WIN32) notify_uninit(); #endif g_free(ud); return 0; }
void unload(ErlNifEnv *env, void *priv_data) { notify_uninit(); }
int main (int argc, char *argv[]) { MateSettingsManager *manager; DBusGConnection *bus; gboolean res; GError *error; GSettings *debug_settings = NULL; manager = NULL; mate_settings_profile_start (NULL); bindtextdomain (GETTEXT_PACKAGE, MATE_SETTINGS_LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); setlocale (LC_ALL, ""); parse_args (&argc, &argv); /* Allows to enable/disable debug from GSettings only if it is not set from argument */ if (mate_gsettings_schema_exists (DEBUG_SCHEMA)) { debug_settings = g_settings_new (DEBUG_SCHEMA); debug = g_settings_get_boolean (debug_settings, DEBUG_KEY); g_signal_connect (debug_settings, "changed::" DEBUG_KEY, G_CALLBACK (debug_changed), NULL); if (debug) { g_setenv ("G_MESSAGES_DEBUG", "all", FALSE); } } mate_settings_profile_start ("opening gtk display"); if (! gtk_init_check (NULL, NULL)) { g_warning ("Unable to initialize GTK+"); exit (EXIT_FAILURE); } mate_settings_profile_end ("opening gtk display"); g_log_set_default_handler (msd_log_default_handler, NULL); bus = get_session_bus (); if (bus == NULL) { g_warning ("Could not get a connection to the bus"); goto out; } if (! bus_register (bus)) { goto out; } #ifdef HAVE_LIBNOTIFY notify_init ("mate-settings-daemon"); #endif /* HAVE_LIBNOTIFY */ mate_settings_profile_start ("mate_settings_manager_new"); manager = mate_settings_manager_new (); mate_settings_profile_end ("mate_settings_manager_new"); if (manager == NULL) { g_warning ("Unable to register object"); goto out; } set_session_over_handler (bus, manager); /* If we aren't started by dbus then load the plugins automatically. Otherwise, wait for an Awake etc. */ if (g_getenv ("DBUS_STARTER_BUS_TYPE") == NULL) { error = NULL; res = mate_settings_manager_start (manager, &error); if (! res) { g_warning ("Unable to start: %s", error->message); g_error_free (error); goto out; } } if (do_timed_exit) { g_timeout_add_seconds (30, (GSourceFunc) timed_exit_cb, NULL); } gtk_main (); out: if (bus != NULL) { dbus_g_connection_unref (bus); } if (manager != NULL) { g_object_unref (manager); } if (debug_settings != NULL) { g_object_unref (debug_settings); } #ifdef HAVE_LIBNOTIFY if (notify_is_initted ()) notify_uninit (); #endif /* HAVE_LIBNOTIFY */ g_debug ("SettingsDaemon finished"); mate_settings_profile_end (NULL); return 0; }
static int data_cb(const struct nlmsghdr * nlh, void * data) { struct nlattr * tb[IFLA_MAX + 1] = {}; struct ifinfomsg * ifm = mnl_nlmsg_get_payload(nlh); char * notification = NULL; const char * interface = NULL; NotifyNotification * netlink = NULL; unsigned int errcount = 0; gboolean res = FALSE; GError * error = NULL; mnl_attr_parse(nlh, sizeof(* ifm), data_attr_cb, tb); interface = mnl_attr_get_str(tb[IFLA_IFNAME]); notification = malloc(strlen(interface) + strlen(NOTIFICATION_TEXT) + 1); // 2* %s is enough for "down", but we need an additional byte for \n sprintf(notification, NOTIFICATION_TEXT, interface, (ifm->ifi_flags & IFF_RUNNING ? "up" : "down")); printf(NOTIFICATION_TEXT_DEBUG, program, interface, ifm->ifi_index, (ifm->ifi_flags & IFF_RUNNING ? "up" : "down")); if (netlinksize < ifm->ifi_index) { netlinkref = realloc(netlinkref, (ifm->ifi_index + 1) * sizeof(size_t)); while(netlinksize < ifm->ifi_index) netlinkref[++netlinksize] = 0; } if (netlinkref[ifm->ifi_index] == 0) { netlink = notify_notification_new("Netlink", notification, (ifm->ifi_flags & IFF_RUNNING ? "network-transmit-receive" : "network-error")); netlinkref[ifm->ifi_index] = (size_t)netlink; } else { netlink = (NotifyNotification *)netlinkref[ifm->ifi_index]; notify_notification_update(netlink, "Netlink", notification, (ifm->ifi_flags & IFF_RUNNING ? "network-transmit-receive" : "network-error")); } notify_notification_set_timeout(netlink, NOTIFICATION_TIMEOUT); notify_notification_set_category(netlink, "Netlink"); notify_notification_set_urgency (netlink, NOTIFY_URGENCY_NORMAL); while(!notify_notification_show(netlink, &error)) { if (errcount > 1) { fprintf(stderr, "%s: Looks like we can not reconnect to notification daemon... Exiting.\n", program); exit(EXIT_FAILURE); } else { g_printerr("%s: Error \"%s\" while trying to show notification. Trying to reconnect.\n", program, error->message); errcount++; g_error_free(error); error = NULL; notify_uninit(); usleep(500 * 1000); if(!notify_init("Udev-Net-Notification")) { fprintf(stderr, "%s: Can't create notify.\n", program); exit(EXIT_FAILURE); } } } errcount = 0; free(notification); return MNL_CB_OK; }
/** * @mainpage PCManX GTK+ Documentation * * @section intro_sec Introduction * * PCManX is a newly developed GPL'd version of PCMan, a full-featured famous BBS client. * It aimed to be an easy-to-use yet full-featured telnet client facilitating BBS browsing with the ability to process double-byte characters. * Some handy functions like tabbed-browsing, auto-login and a built-in ANSI editor enabling colored text editing are also provided. * * - Website * - http://code.google.com/p/pcmanx-gtk2/ * - Mailing List & Forum * - http://groups.google.com/group/PCManX * - Repository * - http://code.google.com/p/pcmanx-gtk2/source/ * */ int main(int argc, char *argv[]) { lt_dlinit(); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); #ifdef USE_DEBUG /* glib introduces its own memory management mechanism, which * confuses memory debuggers such as valgrind and disable their * malloc/free wrapper against the applications. * * Here, we enforce glib to use malloc instead of original ones * for debugging need. */ #if !defined(GLIB_VERSION_2_34) if (getenv("BYPASS_GLIB_POOLS") != NULL) { g_slice_set_config(G_SLICE_CONFIG_ALWAYS_MALLOC, TRUE); } #endif #endif #if !defined(GLIB_VERSION_2_32) if (!g_thread_supported ()) g_thread_init (NULL); #endif gdk_threads_init(); /*--- Initialize Gtk+ ---*/ { /* GTK requires a program's argc and argv variables, and * requires that they be valid. Set it up. */ int fake_argc = 1; char *_fake_argv[] = { (char *) "pcmanx", NULL }; char **fake_argv = _fake_argv; gtk_init (&fake_argc, &fake_argv); } /*--- Initialize Runtime options ---*/ { GError *error = NULL; GOptionContext *context; context = g_option_context_new ("Runtime options"); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_parse (context, &argc, &argv, &error); } /*--- prevent GTK+ from catching F10 ---*/ GtkSettings *gtk_settings; gtk_settings = gtk_settings_get_for_screen(gdk_screen_get_default()); g_object_set(gtk_settings, "gtk-menu-bar-accel", NULL, NULL); /*--- Check if multiple-instance is allowed. ---*/ if (!multiple_instance) { #ifdef USE_DOCKLET /* if we are already running, silently exit */ if (! detect_get_clipboard()) { #ifndef USE_DEBUG return 1; #endif /* USE_DEBUG */ } #endif /* USE_DOCKLET */ } AppConfig.SetToDefault(); AppConfig.Load(); AppConfig.LoadFavorites(); if (AppConfig.RowsPerPage < 24) AppConfig.RowsPerPage = 24; if (AppConfig.ColsPerPage < 80) AppConfig.ColsPerPage = 80; CTelnetCon::Init(); CTelnetCon::SetSocketTimeout( AppConfig.SocketTimeout ); CMainFrame* main_frm = new CMainFrame; gtk_window_move(GTK_WINDOW(main_frm->m_Widget), AppConfig.MainWndX, AppConfig.MainWndY); gtk_window_resize(GTK_WINDOW(main_frm->m_Widget), AppConfig.MainWndW, AppConfig.MainWndH); main_frm->Show(); #ifdef USE_DOCKLET if( AppConfig.ShowTrayIcon ) main_frm->ShowTrayIcon(); else main_frm->HideTrayIcon(); #endif #ifdef USE_NOTIFIER #ifdef USE_LIBNOTIFY if (!notify_is_initted()) { notify_init("pcmanx"); } #else popup_notifier_init(main_frm->GetMainIcon()); popup_notifier_set_timeout( AppConfig.PopupTimeout ); #endif #endif #ifdef USE_SCRIPT InitScriptInterface("."); #endif gdk_threads_enter(); gtk_main (); gdk_threads_leave(); #ifdef USE_LIBNOTIFY notify_uninit(); #endif CTelnetCon::Cleanup(); AppConfig.SaveFavorites(); AppConfig.Save(); lt_dlexit(); return 0; }
void snotify_finalize(){ notify_uninit(); }
void notification_backend_deinit (void) { notify_uninit (); }
int main (int argc, char ** argv) { struct udev * udev; struct udev_device * dev; char * device = NULL; struct udev_monitor * mon = NULL; fd_set readfds; int fdcount, devnum, errcount = 0; unsigned short int i, major, minor; short int * maxminor; char * notification = NULL; char * icon = NULL; NotifyNotification * netlink; NotifyNotification *** netlinkref; blkid_cache cache = NULL; char *read = NULL; blkid_tag_iterate iter; const char *type, *value, *devname; blkid_dev blkdev; GError * error = NULL; printf("%s: %s v%s (compiled: %s)\n", argv[0], PROGNAME, VERSION, DATE); if(!notify_init("Udev-Block-Notification")) { fprintf(stderr, "%s: Can't create notify.\n", argv[0]); exit(EXIT_FAILURE); } udev = udev_new(); if(!udev) { fprintf(stderr, "%s: Can't create udev.\n", argv[0]); exit(EXIT_FAILURE); } mon = udev_monitor_new_from_netlink(udev, "udev"); udev_monitor_filter_add_match_subsystem_devtype(mon, "block", NULL); udev_monitor_enable_receiving(mon); netlinkref = malloc(256 * sizeof(size_t)); for(i = 0; i < 256; i++) netlinkref[i] = NULL; maxminor = malloc(256 * sizeof(short int)); for(i = 0; i < 256; i++) maxminor[i] = -1; while (1) { FD_ZERO(&readfds); if (mon != NULL) FD_SET(udev_monitor_get_fd(mon), &readfds); fdcount = select(udev_monitor_get_fd(mon) + 1, &readfds, NULL, NULL, NULL); if ((mon != NULL) && FD_ISSET(udev_monitor_get_fd(mon), &readfds)) { dev = udev_monitor_receive_device(mon); if(dev) { device = (char *) udev_device_get_sysname(dev); devnum = udev_device_get_devnum(dev); major = devnum / 256; minor = devnum - (major * 256); switch(udev_device_get_action(dev)[0]) { case 'a': // a: add notification = (char *) malloc(strlen(TEXT_ADD) + strlen(device)); sprintf(notification, TEXT_ADD, device, major, minor); icon = ICON_ADD; break; case 'r': // r: remove notification = (char *) malloc(strlen(TEXT_REMOVE) + strlen(device)); sprintf(notification, TEXT_REMOVE, device, major, minor); icon = ICON_REMOVE; break; case 'm': // m: move notification = (char *) malloc(strlen(TEXT_MOVE) + strlen(device)); sprintf(notification, TEXT_MOVE, device, major, minor); icon = ICON_MOVE; break; case 'c': // c: change notification = (char *) malloc(strlen(TEXT_CHANGE) + strlen(device)); sprintf(notification, TEXT_CHANGE, device, major, minor); icon = ICON_CHANGE; break; default: // we should never get here I think... notification = (char *) malloc(strlen(TEXT_DEFAULT) + strlen(device)); sprintf(notification, TEXT_CHANGE, device, major, minor); icon = ICON_DEFAULT; } blkid_get_cache(&cache, read); blkdev = blkid_get_dev(cache, udev_device_get_devnode(dev), BLKID_DEV_NORMAL); if (blkdev) { iter = blkid_tag_iterate_begin(blkdev); while (blkid_tag_next(iter, &type, &value) == 0) { notification = (char *) realloc(notification, strlen(TEXT_TAG) + strlen(notification) + strlen(type) + strlen(value)); sprintf(notification, TEXT_TAG, notification, type, value); } blkid_tag_iterate_end(iter); blkid_put_cache(cache); } printf("%s: %s\n", argv[0], notification); if (maxminor[major] < minor) { netlinkref[major] = realloc(netlinkref[major], (minor + 1) * sizeof(size_t)); while(maxminor[major] < minor) netlinkref[major][++maxminor[major]] = NULL; } if (netlinkref[major][minor] == NULL) { netlink = notify_notification_new("Udev-Block", notification, icon); netlinkref[major][minor] = netlink; } else { netlink = netlinkref[major][minor]; notify_notification_update(netlink, "Udev-Block", notification, icon); } notify_notification_set_timeout(netlink, NOTIFICATION_TIMEOUT); notify_notification_set_category(netlink, "Udev-Block"); notify_notification_set_urgency (netlink, NOTIFY_URGENCY_NORMAL); while(!notify_notification_show(netlink, &error)) { if (errcount > 1) { fprintf(stderr, "%s: Looks like we can not reconnect to notification daemon... Exiting.\n", argv[0]); exit(EXIT_FAILURE); } else { g_printerr("%s: Error \"%s\" while trying to show notification. Trying to reconnect.\n", argv[0], error->message); errcount++; g_error_free(error); error = NULL; notify_uninit(); usleep(500 * 1000); if(!notify_init("Udev-Block-Notification")) { fprintf(stderr, "%s: Can't create notify.\n", argv[0]); exit(EXIT_FAILURE); } } } errcount = 0; free(notification); udev_device_unref(dev); } // This is not really needed... But we want to make shure not to eat 100% CPU if anything breaks. ;) usleep(500 * 1000); } } udev_unref(udev); return EXIT_SUCCESS; }
virtual void OnExit() { if ( notify_is_initted() ) notify_uninit(); }
int main(int argc, char **argv) { pa_glib_mainloop *mainloop; pa_mainloop_api *mainloop_api; pa_context *context; GdkWindow *root; int status = EXIT_SUCCESS; int i; gtk_init(&argc, &argv); mainloop = pa_glib_mainloop_new(NULL); if (!mainloop) { fprintf(stderr, "pa_glib_mainloop_new() failed\n"); status = EXIT_FAILURE; goto out; } mainloop_api = pa_glib_mainloop_get_api(mainloop); if (pa_signal_init(mainloop_api) < 0) { fprintf(stderr, "pa_signal_init() failed\n"); status = EXIT_FAILURE; goto mainloop_free; } pa_signal_new(SIGINT, exit_signal_callback, NULL); pa_signal_new(SIGTERM, exit_signal_callback, NULL); context = pa_context_new(mainloop_api, NULL); if (!context) { fprintf(stderr, "pa_context_new() failed\n"); status = EXIT_FAILURE; goto mainloop_free; } pa_context_set_state_callback(context, context_state_callback, NULL); if (pa_context_connect(context, NULL, 0, NULL) < 0) { fprintf(stderr, "pa_context_connect() failed: %s\n", pa_strerror(pa_context_errno(context))); status = EXIT_FAILURE; goto context_unref; } if (!notify_init(APP_NAME)) { fprintf(stderr, "Could not initialize libnotify\n"); status = EXIT_FAILURE; goto context_unref; } notification = notify_notification_new(APP_NAME, NULL, NULL); if (!notification) { fprintf(stderr, "notify_notification_new() failed\n"); status = EXIT_FAILURE; goto notify_uninit; } notify_notification_set_timeout(notification, NOTIFY_EXPIRES_DEFAULT); notify_notification_set_hint_string(notification, "synchronous", "volume"); root = gdk_get_default_root_window(); gdk_window_set_events(root, GDK_KEY_PRESS_MASK); gdk_window_add_filter(root, filter, context); for (i = 0; i < sizeof(keysyms) / sizeof(keysyms[0]); i++) { keycodes[i] = XKeysymToKeycode(GDK_WINDOW_XDISPLAY(root), keysyms[i]); if (!keycodes[i]) { fprintf(stderr, "%s is not mapped on this keyboard\n", XKeysymToString(keysyms[i])); continue; } XGrabKey(GDK_WINDOW_XDISPLAY(root), keycodes[i], AnyModifier, GDK_WINDOW_XID(root), False, GrabModeAsync, GrabModeAsync); } gtk_main(); g_object_unref(G_OBJECT(notification)); notify_uninit: notify_uninit(); context_unref: pa_context_unref(context); mainloop_free: pa_glib_mainloop_free(mainloop); out: return status; }
static void sigterm_cb(int sig) { RimeFinalize(); notify_uninit(); exit(EXIT_FAILURE); }
/** * Uninitializes libnotify if it is initialized. */ void uninit_libnotify() { if (notify_is_initted()) notify_uninit(); }
int main (int argc, char *argv[]) { GError *error_parsearg = NULL; GOptionContext *context; GtkWidget *window, *vbox, *hbox1, *hbox2; GtkAdjustment *sadj, *madj, *hadj; #ifdef ENABLE_NLS bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif gtk_init (&argc, &argv); notify_init ("Gtimer"); ca_context_create (&sound); context = g_option_context_new (_("- a simple countdown timer")); g_option_context_add_main_entries (context, entries, NULL); #ifdef ENABLE_NLS g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); #endif if (!g_option_context_parse (context, &argc, &argv, &error_parsearg)) { g_fprintf (stderr, "%s\n", error_parsearg->message); exit(1); } vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); hbox1 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_set_spacing (GTK_BOX (hbox2), 5); gtk_container_set_border_width (GTK_CONTAINER (vbox), 5); gui_elem.timer_display = gtk_label_new (NULL); reset_display(); sadj = gtk_adjustment_new (0, 0, 60, 1, 1, 0); madj = gtk_adjustment_new (0, 0, 60, 1, 1, 0); hadj = gtk_adjustment_new (0, 0, 24, 1, 1, 0); gui_time_elem.spin_seconds = gtk_spin_button_new (sadj, 1, 0); gui_time_elem.spin_minutes = gtk_spin_button_new (madj, 1, 0); gui_time_elem.spin_hours = gtk_spin_button_new (hadj, 1, 0); gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (gui_time_elem.spin_seconds), TRUE); gtk_spin_button_set_value (GTK_SPIN_BUTTON (gui_time_elem.spin_seconds), time_elem.seconds); g_object_set (gui_time_elem.spin_seconds, "shadow-type", GTK_SHADOW_IN, NULL); gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (gui_time_elem.spin_minutes), TRUE); gtk_spin_button_set_value (GTK_SPIN_BUTTON (gui_time_elem.spin_minutes), time_elem.minutes); g_object_set (gui_time_elem.spin_minutes, "shadow-type", GTK_SHADOW_IN, NULL); gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (gui_time_elem.spin_hours), TRUE); gtk_spin_button_set_value (GTK_SPIN_BUTTON (gui_time_elem.spin_hours), time_elem.hours); g_object_set (gui_time_elem.spin_hours, "shadow-type", GTK_SHADOW_IN, NULL); gui_elem.entry = gtk_entry_new(); gtk_entry_set_text (GTK_ENTRY (gui_elem.entry), entry_text); gui_elem.button_timer = gtk_button_new(); gtk_button_set_label (GTK_BUTTON (gui_elem.button_timer), _("Start")); gui_elem.button_reset = gtk_button_new_with_label (_("Reset")); gtk_widget_set_sensitive (gui_elem.button_reset, FALSE); gtk_box_pack_start (GTK_BOX (hbox1), gui_time_elem.spin_hours, TRUE, FALSE, 5); gtk_box_pack_start (GTK_BOX (hbox1), gui_time_elem.spin_minutes, TRUE, FALSE, 5); gtk_box_pack_start (GTK_BOX (hbox1), gui_time_elem.spin_seconds, TRUE, FALSE, 5); gtk_box_pack_start (GTK_BOX (vbox), gui_elem.timer_display, FALSE, TRUE, 5); gtk_box_pack_start (GTK_BOX (hbox2), gui_elem.button_timer, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (hbox2), gui_elem.button_reset, TRUE, TRUE, 0); gtk_container_add (GTK_CONTAINER (vbox), hbox1); gtk_box_pack_start (GTK_BOX (vbox), gui_elem.entry, FALSE, TRUE, 5); gtk_container_add (GTK_CONTAINER (vbox), hbox2); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window), "Gtimer"); gtk_container_add (GTK_CONTAINER (window), vbox); gtk_widget_show_all (window); g_timeout_add_seconds (1, (GSourceFunc) timer_function, NULL); g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); g_signal_connect (gui_elem.button_timer, "clicked", G_CALLBACK (on_timer_button_clicked), NULL); g_signal_connect (gui_elem.button_reset, "clicked", G_CALLBACK (on_reset_button_clicked), NULL); gtk_main(); notify_uninit(); ca_context_destroy (sound); g_option_context_free (context); return 0; }