📄 infoeditor.cpp
字号:
/*____________________________________________________________________________
FreeAmp - The Free MP3 Player
Portions Copyright (C) 1999 EMusic.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: infoeditor.cpp,v 1.17 2000/09/21 20:43:38 ijr Exp $
____________________________________________________________________________*/
#include "config.h"
#include <set>
using namespace std;
#include "utility.h"
#include "infoeditor.h"
#include "metadata.h"
#include "musiccatalog.h"
#include "uuid.h"
#include "gtkmessagedialog.h"
infoeditorUI::infoeditorUI(FAContext *context, PlaylistManager *plm,
vector<PlaylistItem *> *itemlist)
{
m_context = context;
m_itemlist = itemlist;
m_plm = plm;
title_change = false;
artist_change = false;
album_change = false;
genre_change = false;
year_change = false;
comment_change = false;
track_change = false;
count_change = false;
gartistlist = NULL;
galbumlist = NULL;
ggenrelist = NULL;
}
infoeditorUI::~infoeditorUI()
{
gtk_widget_destroy(m_window);
delete m_itemlist;
if (gartistlist)
g_list_free(gartistlist);
if (galbumlist)
g_list_free(galbumlist);
if (ggenrelist)
g_list_free(ggenrelist);
}
void infoeditorUI::DoApplyInfoEdit(void)
{
if (!changed)
return;
gtk_widget_set_sensitive(m_okButton, FALSE);
gtk_widget_set_sensitive(m_applyButton, FALSE);
vector<PlaylistItem *>::iterator i = m_itemlist->begin();
for (; i != m_itemlist->end(); i++) {
MetaData oldmeta, newmeta;
gchar *text;
oldmeta = newmeta = (*i)->GetMetaData();
if (title_change) {
text = gtk_entry_get_text(GTK_ENTRY(m_titleEntry));
newmeta.SetTitle(text);
}
if (artist_change) {
text = gtk_entry_get_text(GTK_ENTRY(m_artistEntry));
newmeta.SetArtist(text);
}
if (album_change) {
text = gtk_entry_get_text(GTK_ENTRY(m_albumEntry));
newmeta.SetAlbum(text);
}
if (year_change) {
text = gtk_entry_get_text(GTK_ENTRY(m_yearEntry));
newmeta.SetYear(atoi(text));
}
if (comment_change) {
text = gtk_entry_get_text(GTK_ENTRY(m_commentEntry));
newmeta.SetComment(text);
}
if (genre_change) {
text = gtk_entry_get_text(GTK_ENTRY(m_genreEntry));
newmeta.SetGenre(text);
}
if (track_change) {
text = gtk_entry_get_text(GTK_ENTRY(m_trackEntry));
newmeta.SetTrack(atoi(text));
}
if (count_change) {
text = gtk_entry_get_text(GTK_ENTRY(m_countEntry));
newmeta.SetPlayCount(atoi(text));
}
newmeta.SetTime(oldmeta.Time());
newmeta.SetSize(oldmeta.Size());
newmeta.SetGUID(oldmeta.GUID().c_str());
if (newmeta != oldmeta) {
(*i)->SetMetaData(&newmeta);
if (m_plm)
m_plm->UpdateTrackMetaData(*i, true);
m_context->catalog->UpdateSong(*i);
}
}
}
gint info_delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
{
return FALSE;
}
void info_ok_button_event(GtkWidget *widget, infoeditorUI *p)
{
p->DoApplyInfoEdit();
delete p;
}
void info_close_button_event(GtkWidget *widget, infoeditorUI *p)
{
delete p;
}
void info_apply_button_event(GtkWidget * widget, infoeditorUI *p)
{
p->DoApplyInfoEdit();
}
void text_changed_event(GtkWidget *widget, infoeditorUI *p)
{
gtk_widget_set_sensitive(p->m_okButton, TRUE);
gtk_widget_set_sensitive(p->m_applyButton, TRUE);
p->changed = true;
p->CheckWidget(widget);
}
void infoeditorUI::MBClick(void)
{
MetaData firstdata = (*(m_itemlist->begin()))->GetMetaData();
if (firstdata.GUID() == "") {
string caption = "No Signature Found";
string message = "This track does not have a Relatable Signature "
"associated with it. To look up this track on the "
"MusicBrainz server, you need to enable a Relatable "
"Profile and signature your music collection.";
GTKMessageDialog *dialog = new GTKMessageDialog();
dialog->Show(message.c_str(), caption.c_str(), kMessageOk, true);
delete dialog;
}
else {
string url = "http://www.musicbrainz.org/showguid.html?guid=";
char ascii_uuid[37];
uuid_t1 uu;
memset(uu, '\0', 17 * sizeof(unsigned char));
strncpy((char *)uu, firstdata.GUID().c_str(), 16);
uuid_ascii(uu, ascii_uuid);
url += ascii_uuid;
LaunchBrowser((char *)url.c_str());
}
}
void mb_button_click(GtkWidget *w, infoeditorUI *p)
{
p->MBClick();
}
void infoeditorUI::CheckWidget(GtkWidget *widget)
{
if (widget == m_titleEntry)
title_change = true;
else if (widget == m_artistEntry)
artist_change = true;
else if (widget == m_albumEntry)
album_change = true;
else if (widget == m_yearEntry)
year_change = true;
else if (widget == m_genreEntry)
genre_change = true;
else if (widget == m_trackEntry)
track_change = true;
else if (widget == m_commentEntry)
comment_change = true;
else if (widget == m_countEntry)
count_change = true;
}
void infoeditorUI::DisplayInfo(void)
{
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *table;
GtkWidget *label;
GtkWidget *separator;
GtkWidget *close_button;
if (!m_itemlist || m_itemlist->size() == 0)
return;
BuildLists();
m_listsize = m_itemlist->size();
m_artists = true;
m_albums = true;
m_years = true;
m_genres = true;
m_counts = true;
MetaData firstdata = (*(m_itemlist->begin()))->GetMetaData();
vector<PlaylistItem *>::iterator i = m_itemlist->begin();
i++;
for (; i != m_itemlist->end(); i++) {
MetaData compare = (*i)->GetMetaData();
if (firstdata.Artist() != compare.Artist())
m_artists = false;
if (firstdata.Album() != compare.Album())
m_albums = false;
if (firstdata.Year() != compare.Year())
m_years = false;
if (firstdata.Genre() != compare.Genre())
m_genres = false;
if (firstdata.PlayCount() != compare.PlayCount())
m_counts = false;
}
m_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(m_window), BRANDING" - Edit Track Info");
gtk_signal_connect(GTK_OBJECT(m_window), "delete_event",
GTK_SIGNAL_FUNC(info_delete_event), this);
gtk_container_set_border_width(GTK_CONTAINER(m_window), 5);
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(m_window), vbox);
gtk_widget_show(vbox);
label = gtk_label_new("Use the fields below to change the information associated with your selected\ntrack(s).");
gtk_label_set_line_wrap(GTK_LABEL(label), FALSE);
gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 5);
gtk_widget_show(label);
if (m_listsize == 1) {
GtkWidget *mb_button = gtk_button_new_with_label("Look up track on MusicBrainz");
gtk_box_pack_start(GTK_BOX(vbox), mb_button, FALSE, FALSE, 5);
gtk_signal_connect(GTK_OBJECT(mb_button), "clicked",
GTK_SIGNAL_FUNC(mb_button_click), this);
gtk_widget_show(mb_button);
}
table = gtk_table_new(6, 5, FALSE);
gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 5);
gtk_widget_show(table);
/* Song title entry */
label = gtk_label_new("Title:");
gtk_misc_set_alignment(GTK_MISC(label), (gfloat)1.0, (gfloat)0.5);
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL,
10, 1);
gtk_widget_show(label);
m_titleEntry = gtk_entry_new();
if (m_listsize > 1)
gtk_entry_set_text(GTK_ENTRY(m_titleEntry), "<Multiple Tracks Selected>");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -