⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cover.c

📁 Aqualung is an advanced music player primarily targeted for the GNU/Linux operating system, but als
💻 C
📖 第 1 页 / 共 2 页
字号:
/*                                                     -*- linux-c -*-    Copyright (C) 2004 Tom Szilagyi              (C) 2006 Tomasz Maka    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: cover.c,v 1.7 2006/09/23 17:32:18 pasp Exp $*/#include <config.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <dirent.h>#include <gtk/gtk.h>#include <gdk/gdkcursor.h>#include <gdk/gdkkeysyms.h>#include "common.h"#include "cover.h"#include "gui_main.h"#include "music_browser.h"#include "i18n.h"#include "options.h"extern options_t options;extern gint cover_show_flag;extern gint browser_size_x;extern GtkWidget * comment_view;extern GtkWidget * main_window;extern GtkTreeSelection * music_select;/* maximum 4 chars per extension */gchar *cover_extensions[] = {        "jpg", "jpeg", "png", "gif", "bmp", "tif", "tiff"};gint n_extensions = sizeof(cover_extensions) / sizeof(gchar*);GtkWidget *cover_window;gchar temp_filename[PATH_MAX];gint ext_flag;gint calculated_width, calculated_height;gint cover_widths[N_COVER_WIDTHS] = { 50, 100, 200, 300, -1 };       /* widths in pixels */gchar *get_song_path(gchar *song_filename) {        static gchar song_path[PATH_MAX];        gint i = 0;        gchar *pos;                if ((pos = strrchr(song_filename, '/'))) {                for (i=0; song_filename <= pos; i++) {                        song_path[i] = *song_filename++;                }        }        song_path[i] = '\0';        return song_path;}static gintentry_filter(const struct dirent *entry) {        gint i, len;        gchar *ext, *str1, *str2;        len = strlen (entry->d_name);        if (len < 5)                    /* 5 => a.abc */                return FALSE;        if ((ext = strrchr(entry->d_name, '.'))) {                 ext++;                 /* filter candidates for cover */                str1 = g_utf8_casefold(ext, -1);                for (i = 0; i < n_extensions; i++) {                        str2 = g_utf8_casefold(cover_extensions[i], -1);                                                if (!g_utf8_collate(str1, str2)) {                                g_free(str1);                                g_free(str2);                                ext_flag = TRUE;                                strncpy(temp_filename, entry->d_name, PATH_MAX-1);                                return TRUE;                        }                                        g_free (str2);                }                g_free (str1);        }	return FALSE;}gchar *find_cover_filename(gchar *song_filename) {        gchar *cover_filenames[] = {                "cover", ".cover",                 "folder", ".folder",                "front", ".front"        };        gint n_files, i, j, n;        gchar base_path[PATH_MAX], current_filename[PATH_MAX];        static gchar cover_filename[PATH_MAX];	struct dirent ** d_entry;        gchar *str1, *str2;        n_files = sizeof(cover_filenames) / sizeof(gchar*);        strcpy(base_path, get_song_path(song_filename));        cover_filename[0] = temp_filename[0] = '\0';        for (i = 0; i < n_files; i++) {                for (j = 0; j < n_extensions; j++) {                        strcpy (current_filename, cover_filenames[i]);                        strcat (current_filename, ".");                        strcat (current_filename, cover_extensions[j]);                        ext_flag = FALSE;                        str1 = g_utf8_casefold (current_filename, -1);	                for (n = 0; n < scandir(base_path, &d_entry, entry_filter, alphasort); n++) {                                str2 = g_utf8_casefold(d_entry[n]->d_name, -1);                                if (!g_utf8_collate(str1, str2)) {                                        strcpy (cover_filename, base_path);                                        strcat (cover_filename, d_entry[n]->d_name);                                        if (g_file_test (cover_filename, G_FILE_TEST_IS_REGULAR) == TRUE) {                                                g_free (str1);                                                g_free (str2);                                                return cover_filename;                                        }                                }                                g_free (str2);                        }                        g_free (str1);                }        }        if (ext_flag == TRUE) {                strcpy (cover_filename, base_path);                strcat (cover_filename, temp_filename);        }        return cover_filename;}voiddraw_cover_frame(GdkPixbuf *pixbuf, gint width, gint height, gboolean bevel) {        gint rowstride, channels;        gint i, bc1, bc2, bc3, bc4;        guchar *pixels, *p;        bc1 = bc2 = bc3 = bc4 = 0;      /* black edges */        if (bevel == TRUE) {                bc2 = bc4 = 255;        /* white edges */        }        /* draw frame */        channels = gdk_pixbuf_get_n_channels (pixbuf);        rowstride = gdk_pixbuf_get_rowstride (pixbuf);        pixels = gdk_pixbuf_get_pixels (pixbuf);        /* horizontal lines */        for(i=0; i < width; i++) {                p = pixels + i * channels;                p[0] = p[1] = p[2] = bc1;                p = pixels + (height-1) * rowstride + i * channels;                p[0] = p[1] = p[2] = bc2;        }        /* vertical lines */        for(i=0; i < height; i++) {                p = pixels + i * rowstride;                p[0] = p[1] = p[2] = bc3;                p = pixels + i * rowstride + (width-1) * channels;                p[0] = p[1] = p[2] = bc4;        }}gbooleancover_window_close_cb(GtkWidget * widget, GdkEvent * event, gpointer data) {        gtk_widget_destroy(widget);	return TRUE;}gintcover_window_key_pressed(GtkWidget * widget, GdkEventKey * kevent) {	if (kevent->keyval == GDK_Escape) {                cover_window_close_cb(widget, NULL, NULL);		return TRUE;        }	return FALSE;}void 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -