// rddropboxlistmodel.cpp // // Data model for Rivendell dropboxes // // (C) Copyright 2021 Fred Gleason // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // 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. // #include "rdapplication.h" #include "rdescape_string.h" #include "rddropboxlistmodel.h" RDDropboxListModel::RDDropboxListModel(const QString &hostname,QObject *parent) : QAbstractTableModel(parent) { d_hostname=hostname; // // Column Attributes // unsigned left=Qt::AlignLeft|Qt::AlignVCenter; unsigned center=Qt::AlignCenter; unsigned right=Qt::AlignRight|Qt::AlignVCenter; d_headers.push_back(tr("ID")); // 00 d_alignments.push_back(right); d_headers.push_back(tr("Group")); // 01 d_alignments.push_back(left); d_headers.push_back(tr("Path")); // 02 d_alignments.push_back(left); d_headers.push_back(tr("Norm. Level")); // 03 d_alignments.push_back(right); d_headers.push_back(tr("Autotrim Level")); // 04 d_alignments.push_back(right); d_headers.push_back(tr("To Cart")); // 05 d_alignments.push_back(right); d_headers.push_back(tr("Force Mono")); // 06 d_alignments.push_back(center); d_headers.push_back(tr("Use CC ID")); // 07 d_alignments.push_back(center); d_headers.push_back(tr("Delete Cuts")); // 08 d_alignments.push_back(center); d_headers.push_back(tr("Metadata Pattern")); // 09 d_alignments.push_back(center); d_headers.push_back(tr("User Defined")); // 10 d_alignments.push_back(center); updateModel(); } RDDropboxListModel::~RDDropboxListModel() { } QPalette RDDropboxListModel::palette() { return d_palette; } void RDDropboxListModel::setPalette(const QPalette &pal) { d_palette=pal; } void RDDropboxListModel::setFont(const QFont &font) { d_font=font; d_bold_font=font; d_bold_font.setWeight(QFont::Bold); } int RDDropboxListModel::columnCount(const QModelIndex &parent) const { return d_headers.size(); } int RDDropboxListModel::rowCount(const QModelIndex &parent) const { return d_texts.size(); } QVariant RDDropboxListModel::headerData(int section,Qt::Orientation orient, int role) const { if((orient==Qt::Horizontal)&&(role==Qt::DisplayRole)) { return d_headers.at(section); } return QVariant(); } QVariant RDDropboxListModel::data(const QModelIndex &index,int role) const { QString str; int col=index.column(); int row=index.row(); if(row list; for(int i=0;ifirst()) { updateRow(row.row(),q); emit dataChanged(createIndex(row.row(),0), createIndex(row.row(),columnCount())); } delete q; } } void RDDropboxListModel::refresh(int box_id) { for(int i=0;i texts; RDSqlQuery *q=NULL; QString sql=sqlFields()+ "where `DROPBOXES`.`STATION_NAME`='"+RDEscapeString(d_hostname)+"' "+ "order by `DROPBOXES`.`ID` "; beginResetModel(); d_box_ids.clear(); d_group_colors.clear(); d_texts.clear(); q=new RDSqlQuery(sql); while(q->next()) { d_box_ids.push_back(-1); d_group_colors.push_back(QVariant()); d_texts.push_back(texts); updateRow(d_texts.size()-1,q); } delete q; endResetModel(); } void RDDropboxListModel::updateRowLine(int line) { if(linefirst()) { updateRow(line,q); } delete q; } } void RDDropboxListModel::updateRow(int row,RDSqlQuery *q) { QList texts; // ID d_box_ids[row]=q->value(0).toInt(); texts.push_back(q->value(0)); // Group texts.push_back(q->value(1)); d_group_colors[row]=QColor(q->value(2).toString()); // Path texts.push_back(q->value(3)); // Norm. Level if(q->value(4).toInt()==0) { texts.push_back(tr("[off]")); } else { texts.push_back(QString::asprintf("%d dBFS",q->value(4).toInt()/100)); } // Autotrim Level if(q->value(5).toInt()==0) { texts.push_back(tr("[off]")); } else { texts.push_back(QString::asprintf("%d dBFS",q->value(5).toInt()/100)); } // To Cart if(q->value(6).toUInt()==0) { texts.push_back(tr("[auto]")); } else { texts.push_back(QString::asprintf("%06u",q->value(6).toUInt())); } // Force to Mono texts.push_back(q->value(7)); // Use CC ID texts.push_back(q->value(8)); // Delete Cuts texts.push_back(q->value(9)); // Metadata Pattern texts.push_back(q->value(10)); // User Defined texts.push_back(q->value(11)); d_texts[row]=texts; } QString RDDropboxListModel::sqlFields() const { QString sql=QString("select ")+ "`DROPBOXES`.`ID`,"+ // 00 "`DROPBOXES`.`GROUP_NAME`,"+ // 01 "`GROUPS`.`COLOR`,"+ // 02 "`DROPBOXES`.`PATH`,"+ // 03 "`DROPBOXES`.`NORMALIZATION_LEVEL`,"+ // 04 "`DROPBOXES`.`AUTOTRIM_LEVEL`,"+ // 05 "`DROPBOXES`.`TO_CART`,"+ // 06 "`DROPBOXES`.`FORCE_TO_MONO`,"+ // 07 "`DROPBOXES`.`USE_CARTCHUNK_ID`,"+ // 08 "`DROPBOXES`.`DELETE_CUTS`,"+ // 09 "`DROPBOXES`.`METADATA_PATTERN`,"+ // 10 "`DROPBOXES`.`SET_USER_DEFINED` "+ // 11 "from `DROPBOXES` left join `GROUPS` "+ "on `DROPBOXES`.`GROUP_NAME`=`GROUPS`.`NAME` "; return sql; }