-
Notifications
You must be signed in to change notification settings - Fork 7
/
PlayListAdapter.h
135 lines (122 loc) · 3.35 KB
/
PlayListAdapter.h
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
#pragma once
#include "stdafx.h"
#include <helper/SAdapterBase.h>
#include "FilesHelp.h"
#include <algorithm>
#include <helper/SCriticalSection.h>
class CPlayListWnd : public SMcAdapterBase
{
public:
CPlayListWnd(HWND _hwnd):_m_hwnd(_hwnd),m_Play_index(-1)
{
}
virtual int getCount()
{
SAutoLock lock(m_cs);
return m_db.GetCount();
}
virtual void getView(int position, SWindow * pItem, pugi::xml_node xmlTemplate)
{
if (pItem->GetChildrenCount() == 0)
{
pItem->InitFromXml(xmlTemplate);
}
m_cs.Enter();
PlaylistInfo info = m_db[position];
m_cs.Leave();
SStatic *pBtnsave = pItem->FindChildByName2<SStatic>(L"filename");
pBtnsave->SetWindowTextW(SStringT().Format(L"【%02d】%s", position+1,info.m_name));
pBtnsave->SetAttribute(L"tip", S_CT2W(info.m_name));
pItem->SetUserData(position);
pItem->GetEventSet()->subscribeEvent(EventItemPanelDbclick::EventID, Subscriber(&CPlayListWnd::OnButtonDbclick, this));
}
bool OnButtonDbclick(EventArgs *pEvt)//播放文件
{
SAutoLock lock(m_cs);
SWindow *btn = sobj_cast<SWindow>(pEvt->sender);
SStringT _pathname = m_db[btn->GetUserData()].m_FULL_Path;
m_Play_index=btn->GetUserData();
::SendMessageW(_m_hwnd, MS_PLAYING_PATHNAME, 0, (LPARAM)(LPCTSTR)_pathname);
return true;
}
void ADD_files(SStringT m_path)
{
SAutoLock lock(m_cs);
PlaylistInfo info;
info.m_FULL_Path = m_path;
info.m_file_size = CFileHelp::FileSizeToString(CFileHelp::GetFileSize(m_path));
CFileHelp::SplitPathFileName(m_path, info.m_name, info.m_ext);
m_db.Add(info);
}
void Del_File(int _items)
{
SAutoLock lock(m_cs);
m_db.RemoveAt(_items);
if(m_Play_index> (int)m_db.GetCount()-1)
m_Play_index=m_db.GetCount()-1;
notifyDataSetChanged();
}
void DELL_ALL()
{
SAutoLock lock(m_cs);
m_db.RemoveAll();
m_Play_index=-1;
notifyDataSetChanged();
}
int Get_Play_index()
{
return m_Play_index;
}
void Set_Play_index(int items)
{
m_Play_index=items;
}
SStringT Get_index_Path(int items)
{
SAutoLock lock(m_cs);
return m_db[items].m_FULL_Path;
}
struct SORTCTX
{
int iCol;
};
void Sort_Play_list(int id)//排序
{
SAutoLock lock(m_cs);
SORTCTX ctx = { 1 };
if(id==1)
qsort_s(m_db.GetData(), m_db.GetCount(), sizeof(m_db), SortCmp_name, &ctx);
else qsort_s(m_db.GetData(), m_db.GetCount(), sizeof(m_db), SortCmp_ext, &ctx);
notifyDataSetChanged();
}
SStringW GetColumnName(int iCol) const {
return SStringW().Format(L"col%d", iCol + 1);
}
private:
HWND _m_hwnd;
struct PlaylistInfo
{
SStringT m_FULL_Path, m_name, m_ext, m_file_size;
};
static int __cdecl SortCmp_name(void *context, const void * p1, const void * p2)
{
SORTCTX *pctx = (SORTCTX*)context;
const PlaylistInfo *pSI1 = (const PlaylistInfo*)p1;
const PlaylistInfo *pSI2 = (const PlaylistInfo*)p2;
int nRet = 0;
nRet = wcscmp(pSI1->m_name, pSI2->m_name);
return nRet;
}
static int __cdecl SortCmp_ext(void *context, const void * p1, const void * p2)
{
SORTCTX *pctx = (SORTCTX*)context;
const PlaylistInfo *pSI1 = (const PlaylistInfo*)p1;
const PlaylistInfo *pSI2 = (const PlaylistInfo*)p2;
int nRet = 0;
nRet = wcscmp(pSI1->m_ext, pSI2->m_ext);
return nRet;
}
SArray<PlaylistInfo> m_db;
int m_Play_index;
SCriticalSection m_cs;
};