📄 browserlist.cpp
字号:
delete [] filereturn;
char *url;
uint32 length;
vector<string>::iterator i;
url = new char[_MAX_PATH + 7];
for (i = oFileList.begin(); i != oFileList.end(); i++) {
char *ext = NULL;
struct stat st;
stat((*i).c_str(), &st);
if (st.st_mode & S_IFDIR) {
vector<string> oList, oQuery;
oQuery.push_back(string("*.mp1"));
oQuery.push_back(string("*.mp2"));
oQuery.push_back(string("*.mp3"));
FindMusicFiles((*i).c_str(), oList, oQuery);
if (oList.size() > 0) {
vector<string>::iterator j = oList.begin();
for (; j != oList.end(); j++) {
PlaylistItem *newitem = new PlaylistItem((*j).c_str());
itemList->push_back(newitem);
}
}
}
else {
ext = p->GetContext()->player->GetExtension((*i).c_str());
FilePathToURL((*i).c_str(), url, &length);
if (ext) {
PlaylistManager *plm = p->GetContext()->plm;
if (plm->IsSupportedPlaylistFormat(ext))
plm->ReadPlaylist(url, itemList);
else if (p->GetContext()->player->IsSupportedExtension(ext))
{
PlaylistItem *newitem = new PlaylistItem(url);
itemList->push_back(newitem);
}
delete [] ext;
}
}
}
delete [] url;
GtkCListDestInfo dest_info;
drag_dest_cell(GTK_CLIST(widget), x, y, &dest_info);
if (dest_info.insert_pos == GTK_CLIST_DRAG_AFTER)
dest_info.cell.row++;
p->m_lastindex = dest_info.cell.row;
p->AddTracksPlaylistEvent(itemList);
delete itemList;
p->SetClickState(kContextPlaylist);
g_dataset_remove_data(context, "gtk-clist-drag-dest");
gtk_drag_finish(context, TRUE, FALSE, time);
}
}
gtk_drag_finish(context, FALSE, FALSE, time);
}
static void list_drag_leave_internal(GtkWidget *widget, GdkDragContext *context,
guint time, GTKMusicBrowser *p)
{
if (widget == gtk_drag_get_source_widget(context))
return;
GtkCList *clist = GTK_CLIST(widget);
GtkCListDestInfo *dest_info;
dest_info = (GtkCListDestInfo *)g_dataset_get_data(context,
"gtk-clist-drag-dest");
if (dest_info) {
if (dest_info->cell.row >= 0) {
GList *list = context->targets;
GdkAtom tree = gdk_atom_intern("tree-drag", FALSE);
GdkAtom plain = gdk_atom_intern("text/plain", FALSE);
GdkAtom html = gdk_atom_intern("text/html", FALSE);
while (list) {
if (((int)tree == GPOINTER_TO_INT(list->data)) ||
((int)plain == GPOINTER_TO_INT(list->data)) ||
((int)html == GPOINTER_TO_INT(list->data))) {
GTK_CLIST_CLASS_FW(clist)->draw_drag_highlight(clist,
(GtkCListRow *)g_list_nth(clist->row_list,
dest_info->cell.row)->data,
dest_info->cell.row, dest_info->insert_pos);
break;
}
list = list->next;
}
}
g_dataset_remove_data(context, "gtk-clist-drag-dest");
}
}
static GdkAtom i_drag_dest_find_target(GtkWidget *widget,
GtkDragDestSite *site,
GdkDragContext *context)
{
GList *tmp_target;
GList *tmp_source = NULL;
GtkWidget *source_widget = gtk_drag_get_source_widget (context);
tmp_target = site->target_list->list;
while (tmp_target)
{
GtkTargetPair *pair = (GtkTargetPair *)(tmp_target->data);
tmp_source = context->targets;
while (tmp_source)
{
if (tmp_source->data == GUINT_TO_POINTER (pair->target))
{
if ((!(pair->flags & GTK_TARGET_SAME_APP) || source_widget) &&
(!(pair->flags & GTK_TARGET_SAME_WIDGET) || (source_widget == widget)))
return pair->target;
else
break;
}
tmp_source = tmp_source->next;
}
tmp_target = tmp_target->next;
}
return GDK_NONE;
}
static gint list_drag_motion_internal(GtkWidget *widget,
GdkDragContext *context,
gint x, gint y, guint time,
GTKMusicBrowser *p)
{
GtkDragDestSite *site;
GdkDragAction action = (GdkDragAction)0;
site = (GtkDragDestSite *)gtk_object_get_data(GTK_OBJECT(widget), "gtk-drag-dest");
if (context->suggested_action & site->actions)
action = context->suggested_action;
else {
gint i;
for (i = 0; i < 8; i++) {
if ((site->actions & (1 << i)) && (context->actions & (1 << i))) {
action = (GdkDragAction)(1 << i);
break;
}
}
}
if (action && i_drag_dest_find_target(widget, site, context)) {
if (!site->have_drag)
site->have_drag = TRUE;
gdk_drag_status(context, action, time);
}
GtkCList *clist = GTK_CLIST(widget);
GtkCListDestInfo new_info;
GtkCListDestInfo *dest_info;
dest_info = (GtkCListDestInfo *)g_dataset_get_data(context,
"gtk-clist-drag-dest");
if (!dest_info) {
dest_info = (GtkCListDestInfo *)malloc(sizeof(GtkCListDestInfo));
dest_info->insert_pos = GTK_CLIST_DRAG_NONE;
dest_info->cell.row = -1;
dest_info->cell.column = -1;
g_dataset_set_data_full(context, "gtk-clist-drag-dest", dest_info,
drag_dest_info_destroy);
}
drag_dest_cell(clist, x, y, &new_info);
GList *list = context->targets;
GdkAtom atom = gdk_atom_intern("gtk-clist-drag-reorder", FALSE);
GdkAtom tree = gdk_atom_intern("tree-drag", FALSE);
GdkAtom plain = gdk_atom_intern("text/plain", FALSE);
GdkAtom html = gdk_atom_intern("text/html", FALSE);
list = context->targets;
while (list) {
if ((int)tree == GPOINTER_TO_INT(list->data))
break;
else if ((int)plain == GPOINTER_TO_INT(list->data))
break;
else if ((int)html == GPOINTER_TO_INT(list->data))
break;
else if ((int)atom == GPOINTER_TO_INT(list->data))
break;
list = list->next;
}
if (list) {
site->have_drag = TRUE;
if (new_info.cell.row != dest_info->cell.row ||
(new_info.cell.row == dest_info->cell.row &&
dest_info->insert_pos != new_info.insert_pos)) {
if (dest_info->cell.row >= 0 && dest_info->cell.column != -1)
GTK_CLIST_CLASS_FW(clist)->draw_drag_highlight(clist,
(GtkCListRow *)g_list_nth(clist->row_list,
dest_info->cell.row)->data,
dest_info->cell.row, dest_info->insert_pos);
dest_info->insert_pos = new_info.insert_pos;
dest_info->cell.row = new_info.cell.row;
dest_info->cell.column = new_info.cell.column;
if (dest_info->cell.column != -1)
GTK_CLIST_CLASS_FW(clist)->draw_drag_highlight(clist,
(GtkCListRow *)g_list_nth(clist->row_list,
dest_info->cell.row)->data,
dest_info->cell.row, dest_info->insert_pos);
gdk_drag_status(context, context->suggested_action, time);
}
return TRUE;
}
dest_info->insert_pos = new_info.insert_pos;
dest_info->cell.row = new_info.cell.row;
dest_info->cell.column = new_info.cell.column;
return TRUE;
}
static void play_now_pop(GTKMusicBrowser *p, guint action, GtkWidget *w)
{
p->PlayEvent();
}
static void move_up_pop(GTKMusicBrowser *p, guint action, GtkWidget *w)
{
p->MoveUpEvent();
}
static void move_down_pop(GTKMusicBrowser *p, guint action, GtkWidget *w)
{
p->MoveDownEvent();
}
static void delete_pop(GTKMusicBrowser *p, guint action, GtkWidget *w)
{
p->DeleteEvent();
}
static void edit_pop(GTKMusicBrowser *p, guint action, GtkWidget *w)
{
p->PopUpInfoEditor();
}
static void add_fav_pop(GTKMusicBrowser *p, guint action, GtkWidget *w)
{
p->AddPLStreamToFavs();
}
static void tip_pop(GTKMusicBrowser *p, guint action, GtkWidget *w)
{
p->TipArtist();
}
void GTKMusicBrowser::PlaylistRightClick(int x, int y, uint32 time)
{
if (m_lastindex == kInvalidIndex)
return;
PlaylistItem *sel = m_plm->ItemAt(m_lastindex);
if (!sel)
return;
string url = sel->URL();
if (url.find("http://") < url.length() || url.find("rtp://") < url.length())
gtk_item_factory_popup(playlist2Popup, x, y, 3, time);
else
gtk_item_factory_popup(playlistPopup, x, y, 3, time);
}
static void list_clicked(GtkWidget *w, GdkEventButton *event,
GTKMusicBrowser *p)
{
if (!event)
return;
g_return_if_fail(w != NULL);
g_return_if_fail(GTK_IS_CLIST(w));
g_return_if_fail(event != NULL);
GtkCList *clist = GTK_CLIST(w);
if (event->window != clist->clist_window)
return;
p->SetClickState(kContextPlaylist);
if (event->button == 3) {
int row;
gtk_clist_get_selection_info(clist, (int)event->x,
(int)event->y, &row, NULL);
p->m_lastindex = row;
gtk_clist_select_row(clist, row, 0);
p->PlaylistRightClick((int)event->x_root,
(int)event->y_root,
event->time);
}
}
void GTKMusicBrowser::CreatePlaylistList(GtkWidget *box)
{
GtkItemFactoryEntry popup_items[] = {
{"/Play Now", NULL, (GtkItemFactoryCallback)play_now_pop, 0, 0 },
{"/Move Up", NULL, (GtkItemFactoryCallback)move_up_pop, 0, 0 },
{"/Move Down", NULL, (GtkItemFactoryCallback)move_down_pop, 0, 0 },
{"/sep1", NULL, 0, 0, "<Separator>" },
{"/Remove", NULL, (GtkItemFactoryCallback)delete_pop, 0, 0 },
{"/sep2", NULL, 0, 0, "<Separator>" },
{"/Edit Info", NULL, (GtkItemFactoryCallback)edit_pop, 0, 0 },
{"/sep3", NULL, 0, 0, "<Separator>" },
{"/Tip This Artist", NULL, (GtkItemFactoryCallback)tip_pop, 0, 0 }
};
int nmenu_items = sizeof(popup_items) / sizeof(popup_items[0]);
GtkItemFactoryEntry popup2_items[] = {
{"/Play Now", NULL, (GtkItemFactoryCallback)play_now_pop, 0, 0 },
{"/Move Up", NULL, (GtkItemFactoryCallback)move_up_pop, 0, 0 },
{"/Move Down", NULL, (GtkItemFactoryCallback)move_down_pop, 0, 0 },
{"/sep1", NULL, 0, 0, "<Separator>" },
{"/Remove", NULL, (GtkItemFactoryCallback)delete_pop, 0, 0 },
{"/sep2", NULL, 0, 0, "<Separator>" },
{"/Edit Info", NULL, (GtkItemFactoryCallback)edit_pop, 0, 0 },
{"/sep3", NULL, 0, 0, "<Separator>" },
{"/Add Stream to Favorites", NULL, (GtkItemFactoryCallback)add_fav_pop, 0, 0 }
};
int nmenu2_items = sizeof(popup2_items) / sizeof(popup2_items[0]);
playlistList = gtk_clist_new(9);
gtk_container_add(GTK_CONTAINER(box), playlistList);
gtk_signal_connect(GTK_OBJECT(playlistList), "row_move",
GTK_SIGNAL_FUNC(playlist_row_move_internal), this);
gtk_signal_connect(GTK_OBJECT(playlistList), "select_row",
GTK_SIGNAL_FUNC(set_current_index_internal), this);
gtk_signal_connect(GTK_OBJECT(playlistList), "unselect_row",
GTK_SIGNAL_FUNC(unset_current_index_internal), this);
gtk_clist_set_selection_mode(GTK_CLIST(playlistList),
GTK_SELECTION_EXTENDED);
GtkTargetEntry new_clist_target_table[4] = {
{"gtk-clist-drag-reorder", 0, 0},
{"tree-drag", 0, TARGET_TREE},
{"text/plain", 0, TARGET_STRING},
{"text/html", 0, TARGET_URL},
};
GTK_CLIST_SET_FLAG(GTK_CLIST(playlistList), CLIST_REORDERABLE);
gtk_drag_dest_set(playlistList, (GtkDestDefaults)0,
(GtkTargetEntry *)&new_clist_target_table, 4,
GDK_ACTION_MOVE);
gtk_signal_connect(GTK_OBJECT(playlistList), "drag_leave",
GTK_SIGNAL_FUNC(list_drag_leave_internal), this);
gtk_signal_connect(GTK_OBJECT(playlistList), "drag_drop",
GTK_SIGNAL_FUNC(list_drag_drop_internal), this);
gtk_signal_connect(GTK_OBJECT(playlistList), "drag_data_received",
GTK_SIGNAL_FUNC(list_drag_rec_internal), this);
gtk_signal_connect(GTK_OBJECT(playlistList), "drag_motion",
GTK_SIGNAL_FUNC(list_drag_motion_internal), this);
gtk_signal_connect(GTK_OBJECT(playlistList), "key_press_event",
GTK_SIGNAL_FUNC(list_keypress), this);
gtk_signal_connect(GTK_OBJECT(playlistList), "button_press_event",
GTK_SIGNAL_FUNC(list_clicked), this);
playlistPopup = gtk_item_factory_new(GTK_TYPE_MENU, "<plist_popup>",
NULL);
gtk_item_factory_create_items(playlistPopup, nmenu_items, popup_items,
(void *)this);
playlist2Popup = gtk_item_factory_new(GTK_TYPE_MENU, "<plist2_popup>",
NULL);
gtk_item_factory_create_items(playlist2Popup, nmenu2_items,
popup2_items, (void *)this);
gtk_clist_columns_autosize(GTK_CLIST(playlistList));
gtk_widget_show(playlistList);
m_lastindex = m_plm->GetCurrentIndex();
UpdatePlaylistList();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -