📄 gtkmusicbrowser.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: gtkmusicbrowser.cpp,v 1.53 2000/01/18 20:40:40 ijr Exp $
____________________________________________________________________________*/
#include "config.h"
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <sys/stat.h>
#include <unistd.h>
#include <iostream>
#include "utility.h"
#include "gtkmusicbrowser.h"
#include "infoeditor.h"
#include "fileselector.h"
#include "browsermenu.h"
#include "eventdata.h"
#include "player.h"
#include "musicbrowserui.h"
#include "gtkmessagedialog.h"
#include "help.h"
#include "../res/down_pic.xpm"
#include "../res/edit_pic.xpm"
#include "../res/new_pic.xpm"
#include "../res/import_pic.xpm"
#include "../res/add_file.xpm"
#include "../res/add_track.xpm"
#include "../res/save_pic.xpm"
#include "../res/trash_pic.xpm"
#include "../res/up_pic.xpm"
#include "../res/album_pix.xpm"
#include "../res/all_pix.xpm"
#include "../res/artist_pix.xpm"
#include "../res/catalog_pix.xpm"
#include "../res/playlist_pix.xpm"
#include "../res/track_pix.xpm"
#include "../res/uncatagorized_pix.xpm"
extern "C" {
void new_plist(GTKMusicBrowser *p, guint action, GtkWidget *w);
void open_list(GTKMusicBrowser *p, guint action, GtkWidget *w);
void save_list(GTKMusicBrowser *p, guint action, GtkWidget *w);
void saveas_list(GTKMusicBrowser *p, guint action, GtkWidget *w);
void export_list(GTKMusicBrowser *p, guint action, GtkWidget *w);
void import_list(GTKMusicBrowser *p, guint action, GtkWidget *w);
void music_search(GTKMusicBrowser *p, guint action, GtkWidget *w);
void quit_menu(GTKMusicBrowser *p, guint action, GtkWidget *w);
void add_track_mb(GTKMusicBrowser *p, guint action, GtkWidget *w);
void add_track(GTKMusicBrowser *p, guint action, GtkWidget *w);
void infoedit(GTKMusicBrowser *p, guint action, GtkWidget *w);
void delete_sel(GTKMusicBrowser *p, guint action, GtkWidget *w);
void move_up(GTKMusicBrowser *p, guint action, GtkWidget *w);
void move_down(GTKMusicBrowser *p, guint action, GtkWidget *w);
void clear_list(GTKMusicBrowser *p, guint action, GtkWidget *w);
void catalog_tog(GTKMusicBrowser *p, guint action, GtkWidget *w);
void sort_normal(GTKMusicBrowser *p, guint action, GtkWidget *w);
void sort_random(GTKMusicBrowser *p, guint action, GtkWidget *w);
void sort_random2(GTKMusicBrowser *p, guint action, GtkWidget *w);
void sort_location(GTKMusicBrowser *p, guint action, GtkWidget *w);
void sort_time(GTKMusicBrowser *p, guint action, GtkWidget *w);
void sort_genre(GTKMusicBrowser *p, guint action, GtkWidget *w);
void sort_track(GTKMusicBrowser *p, guint action, GtkWidget *w);
void sort_year(GTKMusicBrowser *p, guint action, GtkWidget *w);
void sort_title(GTKMusicBrowser *p, guint action, GtkWidget *w);
void sort_album(GTKMusicBrowser *p, guint action, GtkWidget *w);
void sort_artist(GTKMusicBrowser *p, guint action, GtkWidget *w);
void options_show(GTKMusicBrowser *p, guint action, GtkWidget *w);
void stop_menu(GTKMusicBrowser *p, guint action, GtkWidget *w);
void play_menu(GTKMusicBrowser *p, guint action, GtkWidget *w);
void next_menu(GTKMusicBrowser *p, guint action, GtkWidget *w);
void prev_menu(GTKMusicBrowser *p, guint action, GtkWidget *w);
void repeat_none(GTKMusicBrowser *p, guint action, GtkWidget *w);
void repeat_one(GTKMusicBrowser *p, guint action, GtkWidget *w);
void repeat_all(GTKMusicBrowser *p, guint action, GtkWidget *w);
void show_help(GTKMusicBrowser *p, guint action, GtkWidget *w);
void freeamp_web(GTKMusicBrowser *p, guint action, GtkWidget *w);
void emusic_web(GTKMusicBrowser *p, guint action, GtkWidget *w);
void show_about(GTKMusicBrowser *p, guint action, GtkWidget *w);
}
FAContext *BADContext = NULL;
void repeat_none(GTKMusicBrowser *p, guint action, GtkWidget *w)
{
p->SetRepeat(0);
}
void repeat_one(GTKMusicBrowser *p, guint action, GtkWidget *w)
{
p->SetRepeat(1);
}
void repeat_all(GTKMusicBrowser *p, guint action, GtkWidget *w)
{
p->SetRepeat(2);
}
void GTKMusicBrowser::SetRepeat(int numrepeat)
{
iSetRepeatMode = true;
switch(numrepeat) {
case 0: {
m_plm->SetRepeatMode(kPlaylistMode_RepeatNone);
break; }
case 1: {
m_plm->SetRepeatMode(kPlaylistMode_RepeatOne);
break; }
case 2: {
m_plm->SetRepeatMode(kPlaylistMode_RepeatAll);
break; }
}
}
void set_active(GtkWidget *w, gpointer data)
{
if (GTK_IS_CHECK_MENU_ITEM(GTK_OBJECT(w))) {
gtk_check_menu_item_set_show_toggle(GTK_CHECK_MENU_ITEM(w), TRUE);
}
}
void GTKMusicBrowser::SetRepeatType(RepeatMode mode)
{
GtkWidget *w;
if (mode == kPlaylistMode_RepeatNone)
w = gtk_item_factory_get_widget(menuFactory,
"/Controls/Repeat No Tracks");
else if (mode == kPlaylistMode_RepeatOne)
w = gtk_item_factory_get_widget(menuFactory,
"/Controls/Repeat One Track");
else
w = gtk_item_factory_get_widget(menuFactory,
"/Controls/Repeat All Tracks");
if (GTK_IS_CHECK_MENU_ITEM(GTK_OBJECT(w)))
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), TRUE);
}
void GTKMusicBrowser::SetShuffleType(bool shuffled)
{
iSetShuffleMode = false;
GtkWidget *w;
if (shuffled)
w = gtk_item_factory_get_widget(menuFactory,
"/Controls/Play Tracks in Random Order");
else
w = gtk_item_factory_get_widget(menuFactory,
"/Controls/Play Tracks in Normal Order");
if (GTK_IS_CHECK_MENU_ITEM(GTK_OBJECT(w)))
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), TRUE);
}
void show_help(GTKMusicBrowser *p, guint action, GtkWidget *w)
{
string oHelpFile;
char dir[_MAX_PATH];
uint32 len = _MAX_PATH;
p->GetContext()->prefs->GetInstallDirectory(dir, &len);
oHelpFile = string(dir) + string(DIR_MARKER_STR) + string("../share/");
oHelpFile += string(HELP_FILE);
struct stat st;
if (stat(oHelpFile.c_str(), &st) == 0 && st.st_mode & S_IFREG)
LaunchBrowser((char *)oHelpFile.c_str());
else {
GTKMessageDialog oBox;
string oMessage("Cannot find the help files. Please make sure that the help files are properly installed, and you are not running "the_BRANDING" from the build directory.");
oBox.Show(oMessage.c_str(), string(BRANDING), kMessageOk, true);
}
}
void freeamp_web(GTKMusicBrowser *p, guint action, GtkWidget *w)
{
LaunchBrowser("http://www.freeamp.org/");
}
void emusic_web(GTKMusicBrowser *p, guint action, GtkWidget *w)
{
LaunchBrowser("http://www.emusic.com/");
}
void show_about(GTKMusicBrowser *p, guint action, GtkWidget *w)
{
p->ShowOptions(5);
}
void stop_menu(GTKMusicBrowser *p, guint action, GtkWidget *w)
{
p->StopMenu();
}
void GTKMusicBrowser::StopMenu()
{
m_context->target->AcceptEvent(new Event(CMD_Stop));
}
void play_menu(GTKMusicBrowser *p, guint action, GtkWidget *w)
{
p->PlayMenu();
}
void GTKMusicBrowser::PlayMenu()
{
if (pauseState)
m_context->target->AcceptEvent(new Event(CMD_Play));
else
m_context->target->AcceptEvent(new Event(CMD_Pause));
}
void next_menu(GTKMusicBrowser *p, guint action, GtkWidget *w)
{
p->NextMenu();
}
void GTKMusicBrowser::NextMenu(void)
{
m_context->target->AcceptEvent(new Event(CMD_NextMediaPiece));
}
void prev_menu(GTKMusicBrowser *p, guint action, GtkWidget *w)
{
p->PrevMenu();
}
void GTKMusicBrowser::PrevMenu(void)
{
m_context->target->AcceptEvent(new Event(CMD_PrevMediaPiece));
}
void options_show(GTKMusicBrowser *p, guint action, GtkWidget *w)
{
p->ShowOptions();
}
void GTKMusicBrowser::ShowOptions(int page)
{
m_context->target->AcceptEvent(new ShowPreferencesEvent(page));
}
TreeData *GTKMusicBrowser::NewTreeData(int type, MusicCatalog *cat,
ArtistList *art, AlbumList *alb,
PlaylistItem *tr, char *pname,
char *message)
{
TreeData *data = new TreeData;
data->type = type;
data->catalog = cat;
data->artist = art;
data->album = alb;
data->track = tr;
if (pname)
data->playlistname = pname;
else
data->playlistname = "";
if (message)
data->message = message;
else
data->message = "";
return data;
}
static vector<PlaylistItem *> *getTreeSelection(GtkCTree *tree)
{
vector<PlaylistItem *> *newlist = new vector<PlaylistItem *>;
GtkCList *clist = GTK_CLIST(tree);
GList *selection = clist->selection;
while (selection) {
GtkCTreeNode *node = (GtkCTreeNode *)selection->data;
TreeData *data = (TreeData *)gtk_ctree_node_get_row_data(tree, node);
if (!data)
return newlist;
switch (data->type) {
case kTreeAll: {
MusicCatalog *cat = data->catalog;
if (!cat)
return newlist;
vector<ArtistList *> *artistList =
(vector<ArtistList *>*)cat->GetMusicList();
vector<PlaylistItem *> *unsorted =
(vector<PlaylistItem *>*)cat->GetUnsortedMusic();
vector<ArtistList *>::iterator h = artistList->begin();
for (; h != artistList->end(); h++) {
vector<AlbumList *>::iterator i = (*h)->m_albumList->begin();
for (; i != (*h)->m_albumList->end(); i++) {
vector<PlaylistItem *>::iterator j = (*i)->m_trackList->begin();
for (; j != (*i)->m_trackList->end(); j++) {
PlaylistItem *item = new PlaylistItem(*(PlaylistItem *)*j);
newlist->push_back(item);
}
}
}
vector<PlaylistItem *>::iterator k = unsorted->begin();
for (; k != unsorted->end(); k++) {
PlaylistItem *item = new PlaylistItem(*(PlaylistItem *)*k);
newlist->push_back(item);
}
break; }
case kTreeArtist: {
ArtistList *list = data->artist;
vector<AlbumList *>::iterator i = list->m_albumList->begin();
for (; i != list->m_albumList->end(); i++) {
vector<PlaylistItem *>::iterator j = (*i)->m_trackList->begin();
for (; j != (*i)->m_trackList->end(); j++) {
PlaylistItem *item = new PlaylistItem(*(PlaylistItem *)*j);
newlist->push_back(item);
}
}
break; }
case kTreeAlbum: {
AlbumList *list = data->album;
vector<PlaylistItem *>::iterator j = list->m_trackList->begin();
for (; j != list->m_trackList->end(); j++) {
PlaylistItem *item = new PlaylistItem(*(PlaylistItem *)*j);
newlist->push_back(item);
}
break; }
case kTreeTrack: {
PlaylistItem *i = new PlaylistItem(*(data->track));
newlist->push_back(i);
break; }
case kTreePlaylist: {
char *fname = (char *)data->playlistname.c_str();
BADContext->plm->ReadPlaylist(fname, newlist);
break; }
case kTreeUncat: {
MusicCatalog *cat = data->catalog;
vector<PlaylistItem *> *unsorted =
(vector<PlaylistItem *>*)cat->GetUnsortedMusic();
vector<PlaylistItem *>::iterator k = unsorted->begin();
for (; k != unsorted->end(); k++) {
PlaylistItem *item = new PlaylistItem(*(PlaylistItem *)*k);
newlist->push_back(item);
}
break; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -