304 lines
8.4 KiB
C++
304 lines
8.4 KiB
C++
#include "fm_datepicker.h"
|
|
#include "fm_layer.h"
|
|
#include "../data/rm_video_list_loader.h"
|
|
#include <QDir>
|
|
#if (RM_MODEL == RM_MODEL_TYPE_TB4000 && USE_DATE_FILTER)
|
|
FMDatePicker::FMDatePicker(QWidget *parent) : RMWidgetBase(parent,true)
|
|
{
|
|
//FMWidgetBorder(this,"border_frame",0x666666);
|
|
|
|
setFixedHeight(40);
|
|
|
|
layout = new QVBoxLayout(this);
|
|
#if (MODEL_WATEX)
|
|
layout->setMargin(0);
|
|
#else
|
|
layout->setMargin(1);
|
|
#endif
|
|
layout->setSpacing(0);
|
|
layout->setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
|
|
|
//FMWidgetBorder(this,"main_video_frame",0x666666);
|
|
QFont font("Monospace");
|
|
font.setPixelSize(12);
|
|
|
|
QWidget* p = new QWidget(this);
|
|
p->setStyleSheet("background-color: #616161;");
|
|
p->setFixedHeight(30);
|
|
p->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
|
|
layout->addWidget(p);
|
|
|
|
QHBoxLayout* yml = new QHBoxLayout(p);
|
|
yml->setMargin(2);
|
|
yml->setSpacing(2);
|
|
|
|
QLabel* label = new QLabel(p);
|
|
label->setText(FM_WSTR(L"년"));
|
|
label->setFont(font);
|
|
label->setStyleSheet("color : #F0F0F0;");
|
|
label->setFixedWidth(20);
|
|
|
|
_yearListCombo = new QComboBox(p);
|
|
_yearListCombo->setStyleSheet("font-family: Fixedsys;color : #DDDDDD;");
|
|
_yearListCombo->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
|
|
_yearListCombo->setMaxVisibleItems(100);
|
|
connect(_yearListCombo,SIGNAL(currentIndexChanged(int)),SLOT(onYearSelected(int)));
|
|
yml->addWidget(_yearListCombo);
|
|
yml->addWidget(label);
|
|
_yearListCombo->setFocusPolicy(Qt::NoFocus);
|
|
|
|
|
|
label = new QLabel(p);
|
|
label->setFont(font);
|
|
label->setText(FM_WSTR(L"월"));
|
|
label->setStyleSheet("color : #F0F0F0;");
|
|
label->setFixedWidth(20);
|
|
|
|
_monthListCombo = new QComboBox(p);
|
|
_monthListCombo->setStyleSheet("font-family: Fixedsys;color : #DDDDDD;");
|
|
_monthListCombo->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
|
|
_monthListCombo->setMaxVisibleItems(100);
|
|
_monthListCombo->setFocusPolicy(Qt::NoFocus);
|
|
|
|
connect(_monthListCombo,SIGNAL(currentIndexChanged(int)),SLOT(onMonthSelected(int)));
|
|
yml->addWidget(_monthListCombo);
|
|
yml->addWidget(label);
|
|
|
|
//#
|
|
label = new QLabel(p);
|
|
label->setText(FM_WSTR(L"일"));
|
|
label->setFont(font);
|
|
label->setStyleSheet("color : #F0F0F0;");
|
|
label->setFixedWidth(20);
|
|
|
|
_dayListCombo = new QComboBox(p);
|
|
_dayListCombo->setStyleSheet("font-family: Fixedsys;color : #DDDDDD;");
|
|
_dayListCombo->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
|
|
_dayListCombo->setMaxVisibleItems(100);
|
|
_dayListCombo->setFocusPolicy(Qt::NoFocus);
|
|
|
|
connect(_dayListCombo,SIGNAL(currentIndexChanged(int)),SLOT(onDaySelected(int)));
|
|
yml->addWidget(_dayListCombo);
|
|
yml->addWidget(label);
|
|
|
|
}
|
|
QString FMDatePicker::_videoFolder(bool bPhoto)
|
|
{
|
|
QString root = RMApp::currentRoot;
|
|
if(root.isEmpty()) {
|
|
return "";
|
|
}
|
|
|
|
// 영상폴더
|
|
return root + QDir::separator() + (bPhoto ? "Photo" : "Video");
|
|
}
|
|
|
|
void FMDatePicker::refreshYears()
|
|
{
|
|
// C:\stroage\testing\TELEBIT\TB4000_S01\20230904_TB4000_SAMPLE_SD\20230904_TB4000_SAMPLE_SD
|
|
QString folder = _videoFolder();
|
|
if(folder.isEmpty()) {
|
|
return;
|
|
}
|
|
QString selected = _yearListCombo->currentText();
|
|
_yearListCombo->clear();
|
|
QDir directory(folder);
|
|
// 2023_07, 2023_08
|
|
|
|
QStringList years = directory.entryList(QStringList() << "*",QDir::Dirs|QDir::NoDotAndDotDot|QDir::System|QDir::Hidden,QDir::Name);
|
|
_yearListCombo->blockSignals(true);
|
|
QSet<QString> yms;
|
|
|
|
foreach(QString year_month, years) {
|
|
|
|
QStringList ym = year_month.split("_");
|
|
if (ym.size() != 2) {
|
|
continue;
|
|
}
|
|
if (!yms.contains(ym.at(0))) {
|
|
yms.insert(ym.at(0));
|
|
_yearListCombo->addItem(ym.at(0));
|
|
}
|
|
}
|
|
_yearListCombo->blockSignals(false);
|
|
|
|
//QString last = selected;
|
|
if(!selected.isEmpty()) {
|
|
_yearListCombo->setCurrentText(selected);
|
|
} else if(_yearListCombo->count() > 0) {
|
|
|
|
// 가장 최근의 날짜로 변경
|
|
// 1개월만 존재할 경우 이벤트 발생하지 않음
|
|
_yearListCombo->setCurrentIndex(_yearListCombo->count()-1);
|
|
if(_yearListCombo->count() == 1) {
|
|
onYearSelected(0);
|
|
}
|
|
}
|
|
}
|
|
void FMDatePicker::refreshMonths()
|
|
{
|
|
QString folder = _videoFolder();
|
|
if(folder.isEmpty()) {
|
|
return;
|
|
}
|
|
|
|
QString year = _yearListCombo->currentText();
|
|
if(year.isEmpty()) {
|
|
return;
|
|
}
|
|
|
|
QString selected = _monthListCombo->currentText();
|
|
_monthListCombo->clear();
|
|
|
|
QDir directory(folder);
|
|
QStringList months = directory.entryList(QStringList() << "*",QDir::Dirs|QDir::NoDotAndDotDot|QDir::System|QDir::Hidden,QDir::Name);
|
|
|
|
_monthListCombo->blockSignals(true);
|
|
QSet<QString> yms;
|
|
foreach(QString year_month, months) {
|
|
|
|
if(!year_month.startsWith(year)) {
|
|
continue;
|
|
}
|
|
QStringList ym = year_month.split("_");
|
|
if (ym.size() != 2) {
|
|
continue;
|
|
}
|
|
if (!yms.contains(ym.at(1))) {
|
|
yms.insert(ym.at(1));
|
|
_monthListCombo->addItem(ym.at(1));
|
|
}
|
|
}
|
|
_monthListCombo->blockSignals(false);
|
|
|
|
QString last = selected;
|
|
if(!selected.isEmpty()) {
|
|
_monthListCombo->setCurrentText(selected);
|
|
} else if (_monthListCombo->count() > 0) {
|
|
_monthListCombo->setCurrentIndex(_monthListCombo->count()-1);
|
|
|
|
// 1개 개월만 존재할 경우 이벤트 발생하지 않아 강제 실행
|
|
if(_monthListCombo->count() == 1) {
|
|
onMonthSelected(0);
|
|
}
|
|
}
|
|
}
|
|
void FMDatePicker::refreshDays()
|
|
{
|
|
QString base = _videoFolder();
|
|
if(base.isEmpty()) {
|
|
return;
|
|
}
|
|
|
|
QString year = _yearListCombo->currentText();
|
|
if(year.isEmpty()) {
|
|
return;
|
|
}
|
|
|
|
QString month = _monthListCombo->currentText();
|
|
if(month.isEmpty()) {
|
|
return;
|
|
}
|
|
|
|
_dayListCombo->clear();
|
|
|
|
QString folder = base + QDir::separator() + year + "_" + month;
|
|
if(!QDir(folder).exists()) {
|
|
return;
|
|
}
|
|
|
|
QDir directory(folder);
|
|
QStringList days = directory.entryList(QStringList() << "*",QDir::Dirs|QDir::NoDotAndDotDot|QDir::System|QDir::Hidden,QDir::Name);
|
|
_dayListCombo->blockSignals(true);
|
|
foreach(QString day, days) {
|
|
_dayListCombo->addItem(day);
|
|
}
|
|
_dayListCombo->blockSignals(false);
|
|
if(days.size() > 0) {
|
|
onDaySelected(0);
|
|
}
|
|
}
|
|
QString FMDatePicker::_videoDayFolder(bool bPhoto)
|
|
{
|
|
QString base = _videoFolder(bPhoto);
|
|
if(base.isEmpty()) {
|
|
return "";
|
|
}
|
|
|
|
QString year = _yearListCombo->currentText();
|
|
QString month = _monthListCombo->currentText();
|
|
QString day = _dayListCombo->currentText();
|
|
if(year.isEmpty() || month.isEmpty() || day.isEmpty()) {
|
|
return "";
|
|
}
|
|
|
|
return QDir::cleanPath(base + QDir::separator() + year + "_" + month + QDir::separator() + day);
|
|
}
|
|
|
|
void FMDatePicker::onDaySelected(int index)
|
|
{
|
|
QString folder = _videoDayFolder();
|
|
if(folder.isEmpty()) {
|
|
return;
|
|
}
|
|
|
|
// 기타 폴더 가능, 전후방 동일 폴더 가능
|
|
QList<QUrl> list;
|
|
RMVideoFileList::appendFolderToList(folder,list);
|
|
|
|
RMVideoFileListLoader* loader = NULL;
|
|
loader = new RMVideoFileListLoader(list);
|
|
QThreadPool::globalInstance()->start(loader,5);
|
|
}
|
|
void FMDatePicker::onMonthSelected(int index)
|
|
{
|
|
Q_UNUSED(index)
|
|
|
|
QString base = _videoFolder();
|
|
if(base.isEmpty()) {
|
|
return;
|
|
}
|
|
|
|
QString year = _yearListCombo->currentText();
|
|
if(year.isEmpty()) {
|
|
return;
|
|
}
|
|
|
|
QString month = _monthListCombo->currentText();
|
|
if(month.isEmpty()) {
|
|
return;
|
|
}
|
|
|
|
QString folder = base + QDir::separator() + year + "_" + month;
|
|
if(!QDir(folder).exists()) {
|
|
return;
|
|
}
|
|
|
|
//qInfo() << _monthListCombo->currentText() << __FUNCTION__;
|
|
|
|
// 월 선택시 파일 항목 읽어서 '일'항목 생성해야함
|
|
refreshDays();
|
|
}
|
|
void FMDatePicker::onYearSelected(int index)
|
|
{
|
|
Q_UNUSED(index)
|
|
_monthListCombo->clear();
|
|
refreshMonths();
|
|
}
|
|
void FMDatePicker::onAppEvent(RMApp::Event event, int param)
|
|
{
|
|
Q_UNUSED(param)
|
|
if(event == RMApp::ROOT_FOLDER_OPEN) {
|
|
qInfo() << event << RMApp::currentRoot << __FUNCTION__;
|
|
refreshYears();
|
|
} else if(event == RMApp::NO_ROOT_FOLDER_OPEN) {
|
|
_yearListCombo->clear();
|
|
_monthListCombo->clear();
|
|
_dayListCombo->clear();
|
|
}
|
|
//Q_UNUSED(param);
|
|
//Q_UNUSED(event);
|
|
}
|
|
#endif
|
|
|