forked from elha/CDex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCddbMatch.cpp
More file actions
185 lines (147 loc) · 4.36 KB
/
CddbMatch.cpp
File metadata and controls
185 lines (147 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
** CDex - Open Source Digital Audio CD Extractor
**
** Copyright (C) 2006 - 2007 Georgy Berdyshev
** Copyright (C) 1999 Albert L. Faber
**
** http://cdexos.sourceforge.net/
** http://sourceforge.net/projects/cdexos
**
** 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "Cdex.h"
#include "CddbMatch.h"
#include "Util.h"
#include "Config.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCddbMatch dialog
CCddbMatch::CCddbMatch(CWnd* pParent /*=NULL*/)
: CDialog(CCddbMatch::IDD, pParent)
{
m_nMatch = 0;
m_nMatches = 0;
//{{AFX_DATA_INIT(CCddbMatch)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CCddbMatch::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCddbMatch)
DDX_Control(pDX, IDOK, m_OK);
DDX_Control(pDX, IDC_MATCHLIST, m_List);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCddbMatch, CDialog)
//{{AFX_MSG_MAP(CCddbMatch)
ON_NOTIFY(NM_CLICK, IDC_MATCHLIST, OnClickMatchlist)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCddbMatch message handlers
void CCddbMatch::AddMatch(CUString strMatches)
{
int nPrevPos=0;
int nPos=0;
if ( m_nMatches < MAX_MATCHES )
{
m_strMatch[ m_nMatches ] = strMatches;
nPos=strMatches.Find( _T( ' ' ) );
if (nPos>=0)
{
m_strArrayCat[ m_nMatches ] = strMatches.Mid( nPrevPos, nPos-nPrevPos );
strMatches=strMatches.Right(strMatches.GetLength()-nPos-1);
nPos=strMatches.Find( _T( ' ' ) );
if (nPos>=0)
{
m_strArrayDid[ m_nMatches ]=strMatches.Mid(nPrevPos,nPos-nPrevPos);
m_strArrayTit[ m_nMatches ]=strMatches.Right(strMatches.GetLength()-nPos-1);
m_nMatches++;
}
}
}
}
BOOL CCddbMatch::OnInitDialog()
{
CUString strLang;
CRect rcList;
CDialog::OnInitDialog();
// translate dialog resources
g_language.InitDialogStrings( this, IDD );
// Get size position of Track List
m_List.GetWindowRect(rcList);
// Convert from screen to client (this parent window of course)
ScreenToClient(rcList);
int iWidth=rcList.Width();
CUStringConvert strCnv;
// Insert header columns
strLang = g_language.GetString(IDS_GENRE);
m_List.InsertColumn(0,strCnv.ToT( strLang ),LVCFMT_LEFT,iWidth/4);
strLang = g_language.GetString(IDS_ALBUM);
m_List.InsertColumn(1,strCnv.ToT( strLang ),LVCFMT_LEFT,iWidth/2);
strLang = g_language.GetString(IDS_CDDBID);
m_List.InsertColumn(2,strCnv.ToT( strLang ),LVCFMT_RIGHT,iWidth/5);
for (int i=0;i<m_nMatches;i++)
{
CUStringConvert strCnv;
// Add matches to the dialog
m_List.InsertItem( i, strCnv.ToT( m_strArrayCat[ i ] ) );
m_List.SetItemText( i, 1, strCnv.ToT( m_strArrayTit[ i ] ) );
m_List.SetItemText( i, 2, strCnv.ToT( m_strArrayDid[ i ] ) );
}
m_List.SetFocus();
// By default, select the first one
if ( m_nMatches > 0 )
{
// Enable the OK button
m_OK.EnableWindow( TRUE );
// Select first entry in list
m_List.SetCurSel( 0 );
}
else
{
// Do not enable the OK button, wait for User to select a match
m_OK.EnableWindow( FALSE );
}
return FALSE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CCddbMatch::OnOK()
{
// Get the item that's selected
m_nMatch = m_List.GetCurSel();
// Check range of selection to avoid GPF
if ( m_nMatch < 0 || m_nMatch > m_nMatches )
{
m_nMatch = 0;
}
CDialog::OnOK();
}
void CCddbMatch::OnCancel()
{
m_nMatch = 0;
CDialog::OnCancel();
}
void CCddbMatch::OnClickMatchlist(NMHDR* pNMHDR, LRESULT* pResult)
{
// User has selected a match, enable OK button
m_OK.EnableWindow(TRUE);
*pResult = 0;
}