/* $Id$ */ /* * Cantus Tag Editor * Copyright © 2002-2004 by Samuel Abels * Copyright © 2007 by Tim Huetz * * 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 3 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, see **/ #ifdef HAVE_CONFIG_H # include #endif #include /****************************************************************************** * Constructor/Destructor ******************************************************************************/ Displayarea::Displayarea(CantusHash *pplugindata) { plugindata = pplugindata; CantusAddListenerSigCFunc addlistener = (CantusAddListenerSigCFunc) cantushash_get_pointer(plugindata, "Cantus:AddListenerSigC"); g_return_if_fail(addlistener != NULL); listenerids.push_back( addlistener("Filelist:Read:Start", sigc::mem_fun(*this, &Displayarea::on_selection_changed_event))); listenerids.push_back( addlistener("File:Read:Finished", sigc::mem_fun(*this, &Displayarea::on_file_read_finished_event))); listenerids.push_back( addlistener("GUI:PluginWidget:Destroyed", sigc::mem_fun(*this, &Displayarea::on_uiwidget_destroyed_event))); } Displayarea::~Displayarea(void) { #ifdef _DEBUG_ printf("mpegheader(): Displayarea::~Displayarea(): Called.\n"); #endif CantusRemoveListenerFunc removelistener = (CantusRemoveListenerFunc) cantushash_get_pointer(plugindata, "Cantus:RemoveListener"); g_return_if_fail(removelistener != NULL); std::list::iterator iter = listenerids.begin(); while (iter != listenerids.end()) { removelistener(*iter); iter++; } } /****************************************************************************** * Public ******************************************************************************/ GtkWidget *Displayarea::build(bool vertical) { Gtk::Table *table = new Gtk::Table(2, 7); Gtk::Label *label = NULL; Gtk::Fixed *fixed = NULL; Gtk::AttachOptions yfill = vertical ? Gtk::FILL : Gtk::FILL; table->set_border_width(5); table->set_col_spacings(3); // Labels label = new Gtk::Label("", 0, 0.5); widgets["info"] = label; table->attach(*label, 0, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, yfill); label = new Gtk::Label(_("Version:"), 0, 0.5); table->attach(*label, 0, 1, 1, 2, Gtk::FILL, yfill); label = new Gtk::Label("", 0, 0.5); widgets["version"] = label; table->attach(*label, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, yfill); label = new Gtk::Label(_("Sample Rate:"), 0, 0.5); table->attach(*label, 0, 1, 2, 3, Gtk::FILL, yfill); label = new Gtk::Label("", 0, 0.5); widgets["samplerate"] = label; table->attach(*label, 1, 2, 2, 3, Gtk::FILL|Gtk::EXPAND, yfill); label = new Gtk::Label(_("Bitrate:"), 0, 0.5); table->attach(*label, 0, 1, 3, 4, Gtk::FILL, yfill); label = new Gtk::Label("", 0, 0.5); widgets["bitrate"] = label; table->attach(*label, 1, 2, 3, 4, Gtk::FILL|Gtk::EXPAND, yfill); label = new Gtk::Label(_("Mode:"), 0, 0.5); table->attach(*label, 0, 1, 4, 5, Gtk::FILL, yfill); label = new Gtk::Label("", 0, 0.5); widgets["mode"] = label; table->attach(*label, 1, 2, 4, 5, Gtk::FILL|Gtk::EXPAND, yfill); label = new Gtk::Label(_("Time:"), 0, 0.5); table->attach(*label, 0, 1, 6, 7, Gtk::FILL, yfill); label = new Gtk::Label("", 0, 0.5); widgets["time"] = label; table->attach(*label, 1, 2, 6, 7, Gtk::FILL|Gtk::EXPAND, yfill); // Some distance at the lower edge of the display. fixed = new Gtk::Fixed; fixed->set_size_request(0, -1); table->attach(*fixed, 0, 2, 7, 8, Gtk::FILL, Gtk::FILL|Gtk::EXPAND); table->show_all(); return (GtkWidget*)Glib::unwrap(table); } /****************************************************************************** * Private ******************************************************************************/ /* The selection changed, but the selected files have not yet been read. */ void Displayarea::on_selection_changed_event(void *pselected) { #ifdef _DEBUG_ std::cout << "mpegheader(): Displayarea::on_selection_changed_event(): " << "Called.\n"; #endif gint numitems = pselected ? g_list_length((GList*)pselected) : 0; gchar *text = NULL; update = FALSE; // Clear all fields. std::map::iterator iter = widgets.begin(); while (iter != widgets.end()) { iter->second->set_text(""); iter++; } // Update the "info" field. switch (numitems) { case 0: widgets["info"]->set_text(_("None selected.")); // Update the GUI. break; case 1: update = TRUE; default: text = g_strdup_printf(ngettext("%i File selected.", "%i Files selected.", numitems), numitems); widgets["info"]->set_text(text); g_free(text); break; } } /* A file has been read successfully. */ void Displayarea::on_file_read_finished_event(void *pinfo) { #ifdef _DEBUG_ std::cout << "mpegheader(): Displayarea::on_file_read_finished_event(): " << "Called.\n"; #endif if (!update) return; update = FALSE; CantusHash *info = (CantusHash*)pinfo; gchar *text = NULL; const gchar *mode = NULL; gint seconds, mins, secs; gint mode_int; text = g_strdup_printf(_("MPEG V%s, Layer %i"), cantushash_get_char(info, "MPEGHeader:Version"), cantushash_get_int(info, "MPEGHeader:Layer")); widgets["version"]->set_text(text); g_free(text); text = g_strdup_printf("%i", cantushash_get_int(info, "MPEGHeader:Samplerate")); widgets["samplerate"]->set_text(text); g_free(text); text = g_strdup_printf("%i", cantushash_get_int(info, "MPEGHeader:Bitrate")); widgets["bitrate"]->set_text(text); g_free(text); // Mode. mode_int = cantushash_get_int(info, "MPEGHeader:Mode"); switch (mode_int) { case 0: mode = _("Stereo"); break; case 1: mode = _("Joint Stereo"); break; case 2: mode = _("2 Channel"); break; case 3: mode = _("Mono"); break; default: g_assert_not_reached(); } widgets["mode"]->set_text(mode); // Time. seconds = cantushash_get_int(info, "MPEGHeader:Seconds"); mins = seconds / 60; secs = seconds % 60; text = g_strdup_printf("%i:%02i", mins, secs); widgets["time"]->set_text(text); g_free(text); } void Displayarea::on_uiwidget_destroyed_event(void *name) { #ifdef _DEBUG_ printf("id3v2(): Displayarea::on_uiwidget_destroyed_event(): Called.\n"); #endif if (strcmp((gchar*)name, cantushash_get_char(plugindata, "Plugin:Name")) == 0) delete this; }