1 /*
2     mp3curs.c - curses/ncurses interface for mp3info
3 
4     Copyright (C) 2000-2006 Cedric Tefft <cedric@phreaker.net>
5 
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10 
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 
20   ***************************************************************************
21 
22   This program is based in part on MP3Info 0.5 by Ricardo Cerqueira <rmc@rccn.net>
23 
24 */
25 
26 
27 #include "mp3info.h"
28 
29 
30 /*
31  * Check if Break is given, and if so, clean term and exit, else pad the input.
32  */
33 
checkinput(int c,char * string,int length)34 char *checkinput(int c, char *string, int length) {
35         if (c == CTRL_C) { endwin(); exit(0); }
36         return string;
37 }
38 
39 /*
40  * Get the cursor to the right place, and get input
41  */
42 
curs_addparam(WINDOW * win,int line,int length,char * buf)43 char *curs_addparam(WINDOW *win, int line, int length, char *buf) {
44         int c;
45         char string[TEXT_FIELD_LEN];
46 
47         wmove(win,line,16);
48         c = wgetnstr(win,string,length);
49         strcpy(buf,checkinput(c,string,length));
50         return buf;
51 }
52 
53 /*
54  * Bring up the curses window, then get and parse input, and build the tag.
55  */
56 
tagedit_curs(char * filename,int filenum,int fileoutof,id3tag * tag)57 void tagedit_curs(char *filename, int filenum, int fileoutof, id3tag *tag) {
58 WINDOW *mainwin;
59    char line[50], track_text[4], *genre, genre_text[30];
60    unsigned int track_num, genre_num;
61    line[0]='\0';
62 
63    initscr(); cbreak(); noecho();
64    nonl();
65    mainwin = newwin(9,COLS,5,0);
66    intrflush(mainwin, FALSE);
67    keypad(mainwin, TRUE);
68    CenterText(1,VERSION);
69 /*   CenterText(2,"by Ricardo Cerqueira (C)2000"); */
70 #ifdef HAVE_TOUCHWIN
71    touchwin(mainwin);
72 #endif
73    box(mainwin, 0, 0);
74    wmove(mainwin,1,1);
75    wprintw(mainwin,"Song Title:    %s",tag->title);
76    wmove(mainwin,2,1);
77    wprintw(mainwin,"Artist Name:   %s",tag->artist);
78    wmove(mainwin,3,1);
79    wprintw(mainwin,"Album Name:    %s",tag->album);
80    wmove(mainwin,4,1);
81    wprintw(mainwin,"Year:          %s",tag->year);
82    wmove(mainwin,5,1);
83    wprintw(mainwin,"Comment:       %s",tag->comment);
84    wmove(mainwin,6,1);
85    if(tag->track[0] != '\0') {
86 	sprintf(track_text,"%d",tag->track[0]);
87    } else {
88 	track_text[0]='\0';
89    }
90    wprintw(mainwin,"Track:         %s",track_text);
91    wmove(mainwin,7,1);
92    if(tag->genre[0] < 127) {
93 	genre=typegenre[tag->genre[0]];
94    } else {
95 	genre="";
96    }
97    strcpy(genre_text,genre);
98    wprintw(mainwin,"Genre:         %s",genre);
99    wmove(mainwin,8,4);
100    wprintw(mainwin," (%d/%d) %s ",filenum,fileoutof,filename);
101 #ifdef __WIN32__
102    wmove(mainwin,8,COLS-23);
103    wprintw(mainwin," Press ^BREAK to quit ");
104 #else
105    wmove(mainwin,8,COLS-22);
106    wprintw(mainwin," Press ^C to quit ");
107 #endif
108    refresh();
109    echo();
110    curs_addparam(mainwin,1,30,line);
111    strncpy(tag->title,line,strlen(line));
112    curs_addparam(mainwin,2,30,line);
113    strncpy(tag->artist,line,strlen(line));
114    curs_addparam(mainwin,3,30,line);
115    strncpy(tag->album,line,strlen(line));
116    curs_addparam(mainwin,4,4,line);
117    strncpy(tag->year,line,strlen(line));
118    curs_addparam(mainwin,5,30,line);
119    strncpy(tag->comment,line,strlen(line));
120    curs_addparam(mainwin,6,30,line);
121    strncpy(track_text,line,strlen(line) + (strlen(line) < strlen (track_text) ? 0 : 1));
122 /*   strncpy(track_text,line,3); */
123    curs_addparam(mainwin,7,30,line);
124    strncpy(genre_text,line,strlen(line) + (strlen(line) < strlen (genre_text) ? 0 : 1));
125 
126    endwin();
127    if((track_num=atoi(track_text)) < 256) {
128 	tag->track[0] = (unsigned char) track_num;
129    } else {
130 	printf("ERROR - '%s' is not a valid track number.\n",track_text);
131    }
132    unpad(genre_text);
133    if((genre_num=get_genre(genre_text)) < 256) {
134 	tag->genre[0] = (unsigned char) genre_num;
135    } else {
136 	printf("ERROR - '%s' is not a valid genre name or number.\nUse '-G' for a list of valid genres.\n",genre_text);
137    }
138 
139 }
140 
141