2021-01-25 Fred Gleason <fredg@paravelsystems.com>

* Added 'RDFeedListModel' class
	* Refactored the top-level window in rdcastmanager(1) to use the
	model-based API.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason 2021-01-25 09:28:43 -05:00
parent be3fcfd4ef
commit 9d5d446c2a
24 changed files with 945 additions and 278 deletions

View File

@ -20891,3 +20891,7 @@
model-based API.
2021-01-24 Fred Gleason <fredg@paravelsystems.com>
* Added a 'RDIconEngine::applicationIcon()' method.
2021-01-25 Fred Gleason <fredg@paravelsystems.com>
* Added 'RDFeedListModel' class
* Refactored the top-level window in rdcastmanager(1) to use the
model-based API.

View File

@ -133,6 +133,7 @@ dist_librd_la_SOURCES = dbversion.h\
rdeventimportlist.cpp rdeventimportlist.h\
rdexport_settings_dialog.cpp rdexport_settings_dialog.h\
rdfeed.cpp rdfeed.h\
rdfeedlistmodel.cpp rdfeedlistmodel.h\
rdfontengine.cpp rdfontengine.h\
rdformpost.cpp rdformpost.h\
rdflacdecode.cpp rdflacdecode.h\
@ -307,6 +308,7 @@ nodist_librd_la_SOURCES = moc_rdadd_cart.cpp\
moc_rdevent_player.cpp\
moc_rdexport_settings_dialog.cpp\
moc_rdfeed.cpp\
moc_rdfeedlistmodel.cpp\
moc_rdframe.cpp\
moc_rdget_ath.cpp\
moc_rdgetpasswd.cpp\

View File

@ -99,8 +99,9 @@ SOURCES += rdevent.cpp
SOURCES += rdevent_line.cpp
SOURCES += rdeventimportlist.cpp
SOURCES += rdexport_settings_dialog.cpp
SOURCES += rdframe.cpp
SOURCES += rdfeedlistmodel.cpp
SOURCES += rdfontengine.cpp
SOURCES += rdframe.cpp
SOURCES += rdget_ath.cpp
SOURCES += rdgetpasswd.cpp
SOURCES += rdgpioselector.cpp
@ -253,8 +254,9 @@ HEADERS += rdevent.h
HEADERS += rdevent_line.h
HEADERS += rdeventimportlist.h
HEADERS += rdexport_settings_dialog.h
HEADERS += rdframe.h
HEADERS += rdfeedlistmodel.h
HEADERS += rdfontengine.h
HEADERS += rdframe.h
HEADERS += rdget_ath.h
HEADERS += rdgetpasswd.h
HEADERS += rdgpioselector.h

View File

@ -2384,6 +2384,10 @@ Přepsat?</translation>
<source>Creation Date</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[superfeed]</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDGetAth</name>

View File

@ -2361,6 +2361,10 @@ Overwrite?</source>
<source>Creation Date</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[superfeed]</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDGetAth</name>

View File

@ -2356,6 +2356,10 @@ Overwrite?</source>
<source>Creation Date</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[superfeed]</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDGetAth</name>

View File

@ -2009,6 +2009,10 @@ Are you sure you want to save?</source>
<source>Creation Date</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[superfeed]</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDGetAth</name>

View File

@ -2342,6 +2342,10 @@ Skriv over?</translation>
<source>Creation Date</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[superfeed]</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDGetAth</name>

View File

@ -2342,6 +2342,10 @@ Skriv over?</translation>
<source>Creation Date</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[superfeed]</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDGetAth</name>

View File

@ -2349,6 +2349,10 @@ Sobreescrever?</translation>
<source>Creation Date</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[superfeed]</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDGetAth</name>

642
lib/rdfeedlistmodel.cpp Normal file
View File

@ -0,0 +1,642 @@
// rdfeedlistmodel.cpp
//
// Data model for Rivendell RSS feeds
//
// (C) Copyright 2021 Fred Gleason <fredg@paravelsystems.com>
//
// 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 "rdconf.h"
#include "rdescape_string.h"
#include "rdfeed.h"
#include "rdfeedlistmodel.h"
#include "rdpodcast.h"
RDFeedListModel::RDFeedListModel(QObject *parent)
: QAbstractItemModel(parent)
{
d_font_metrics=NULL;
d_bold_font_metrics=NULL;
//
// Column Attributes
//
unsigned left=Qt::AlignLeft|Qt::AlignVCenter;
unsigned center=Qt::AlignCenter;
unsigned right=Qt::AlignRight|Qt::AlignVCenter;
d_headers.push_back(tr("Key Name")); // 00
d_alignments.push_back(left);
d_headers.push_back(tr("Feed Title")); // 01
d_alignments.push_back(left);
d_headers.push_back(tr("Casts")); // 02
d_alignments.push_back(center);
d_headers.push_back(tr("Creation Date")); // 03
d_alignments.push_back(center);
d_headers.push_back(tr("Auto Post")); // 04
d_alignments.push_back(right);
d_headers.push_back(tr("Superfeed")); // 05
d_alignments.push_back(center);
d_headers.push_back(tr("Public URL")); // 06
d_alignments.push_back(left);
}
RDFeedListModel::~RDFeedListModel()
{
}
QPalette RDFeedListModel::palette()
{
return d_palette;
}
void RDFeedListModel::setPalette(const QPalette &pal)
{
d_palette=pal;
}
void RDFeedListModel::setFont(const QFont &font)
{
d_font=font;
if(d_font_metrics!=NULL) {
delete d_font_metrics;
}
d_font_metrics=new QFontMetrics(d_font);
d_bold_font=font;
d_bold_font.setWeight(QFont::Bold);
if(d_bold_font_metrics!=NULL) {
delete d_bold_font_metrics;
}
d_bold_font_metrics=new QFontMetrics(d_bold_font);
}
QModelIndex RDFeedListModel::index(int row,int col,
const QModelIndex &parent) const
{
if(!parent.isValid()) {
return createIndex(row,col,(quint32)0);
}
if((parent.column()==0)&&(parent.internalId()==0)) {
return createIndex(row,col,(quint32)(1+parent.row()));
}
return QModelIndex();
}
QModelIndex RDFeedListModel::parent(const QModelIndex &index) const
{
if(index.isValid()&&(index.internalId()>0)) {
return createIndex(index.internalId()-1,0,(quint32)0);
}
return QModelIndex();
}
int RDFeedListModel::columnCount(const QModelIndex &parent) const
{
return d_headers.size();
}
int RDFeedListModel::rowCount(const QModelIndex &parent) const
{
if(parent.isValid()) {
if(parent.internalId()==0) {
return d_cast_texts.at(parent.row()).size();
}
return d_cast_texts.at(parent.internalId()-1).size();
}
return d_texts.size();
}
bool RDFeedListModel::hasChildren(const QModelIndex &parent) const
{
if(parent.isValid()) {
if((parent.internalId()==0)&&(parent.column()==0)) {
return d_cast_texts.at(parent.row()).size()>0;
}
return false;
}
return true;
}
Qt::ItemFlags RDFeedListModel::flags(const QModelIndex &index) const
{
return Qt::ItemIsSelectable|Qt::ItemIsEnabled;
}
QVariant RDFeedListModel::headerData(int section,Qt::Orientation orient,
int role) const
{
if((orient==Qt::Horizontal)&&(role==Qt::DisplayRole)) {
return d_headers.at(section);
}
return QVariant();
}
QVariant RDFeedListModel::data(const QModelIndex &index,int role) const
{
QString str;
int col=index.column();
int row=index.row();
QPixmap pix;
if(!index.isValid()) {
return QVariant();
}
if(index.internalId()>0) { // Casts
if(row<d_cast_texts.at(index.internalId()-1).size()) {
switch((Qt::ItemDataRole)role) {
case Qt::DisplayRole:
return d_cast_texts.at(index.internalId()-1).at(row).at(col);
case Qt::DecorationRole:
if(col==0) {
return d_cast_icons.at(index.internalId()-1).at(row);
}
break;
case Qt::TextAlignmentRole:
return d_alignments.at(col);
case Qt::SizeHintRole:
return QSize(RD_LISTWIDGET_ITEM_WIDTH_PADDING+
d_font_metrics->width(d_cast_texts.
at(index.internalId()-1).at(row).at(col).toString()),
24);
default:
break;
}
}
}
else { // Feeds
if(row<d_texts.size()) {
switch((Qt::ItemDataRole)role) {
case Qt::DisplayRole:
return d_texts.at(row).at(col);
case Qt::DecorationRole:
return d_icons.at(row).at(col);
case Qt::TextAlignmentRole:
return d_alignments.at(col);
case Qt::FontRole:
if(col==0) { // Key Name
return d_bold_font;
}
return d_font;
case Qt::TextColorRole:
// Nothing to do here!
break;
case Qt::BackgroundRole:
// Nothing to do here!
break;
case Qt::SizeHintRole:
return QSize(RD_LISTWIDGET_ITEM_WIDTH_PADDING+
(d_icons.at(row).at(col).value<QPixmap>().width())+
d_font_metrics->width(d_texts.at(row).at(col).toString()),
40);
default:
break;
}
}
}
return QVariant();
}
bool RDFeedListModel::isFeed(const QModelIndex &index) const
{
return index.internalId()==0;
}
bool RDFeedListModel::isCast(const QModelIndex &index) const
{
return index.internalId()>0;
}
QString RDFeedListModel::keyName(const QModelIndex &index) const
{
if(index.isValid()) {
if(isFeed(index)) {
return d_key_names.at(index.row());
}
return d_key_names.at(index.internalId()-1);
}
return QString();
}
unsigned RDFeedListModel::feedId(const QModelIndex &index) const
{
if(index.isValid()) {
if(isFeed(index)) {
return d_feed_ids.at(index.row());
}
return d_feed_ids.at(index.internalId()-1);
}
return 0;
}
QString RDFeedListModel::publicUrl(const QModelIndex &index) const
{
if(index.isValid()) {
if(isFeed(index)) {
return d_texts.at(index.row()).at(6).toString();
}
return d_texts.at(index.internalId()-1).at(6).toString();
}
return QString();
}
unsigned RDFeedListModel::castId(const QModelIndex &index) const
{
if(index.isValid()) {
if(isCast(index)) {
return d_cast_ids.at(index.internalId()-1).at(index.row());
}
}
return 0;
}
QModelIndex RDFeedListModel::feedRow(const QString &keyname) const
{
int pos=d_key_names.indexOf(keyname);
if(pos<0) {
return QModelIndex();
}
return createIndex(pos,0,(quint32)0);
}
QModelIndex RDFeedListModel::castRow(unsigned cast_id) const
{
for(int i=0;i<d_cast_ids.size();i++) {
for(int j=0;j<d_cast_ids.at(i).size();j++) {
if(d_cast_ids.at(i).at(j)==cast_id) {
return createIndex(j,0,i+1);
}
}
}
return QModelIndex();
}
QModelIndex RDFeedListModel::addFeed(const QString &keyname)
{
//
// Find the insertion offset
//
int offset=d_key_names.size();
for(int i=0;i<d_key_names.size();i++) {
if(keyname.toLower()<d_key_names.at(i).toLower()) {
offset=i;
break;
}
}
beginInsertRows(QModelIndex(),offset,offset);
QList<QVariant> list;
for(int i=0;i<columnCount();i++) {
list.push_back(QVariant());
}
QList<QList<QVariant> > list_list;
QList<unsigned> ids_list;
list_list.push_back(list);
d_icons.insert(offset,list);
d_texts.insert(offset,list);
d_key_names.insert(offset,keyname);
d_feed_ids.insert(offset,0);
d_cast_ids.insert(offset,ids_list);
d_cast_icons.insert(offset,list);
QString sql=sqlFields()+
"where "+
"FEEDS.KEY_NAME=\""+RDEscapeString(keyname)+"\" ";
RDSqlQuery *q=new RDSqlQuery(sql);
if(q->first()) {
updateRow(offset,q);
}
delete q;
endInsertRows();
emit rowCountChanged(d_texts.size());
return createIndex(offset,0,0);
}
void RDFeedListModel::removeFeed(const QString &keyname)
{
for(int i=0;i<d_key_names.size();i++) {
if(d_key_names.at(i)==keyname) {
beginRemoveRows(QModelIndex(),i,i);
d_key_names.removeAt(i);
d_feed_ids.removeAt(i);
d_texts.removeAt(i);
d_cast_ids.removeAt(i);
d_cast_icons.removeAt(i);
d_icons.removeAt(i);
endRemoveRows();
emit rowCountChanged(d_texts.size());
return;
}
}
}
void RDFeedListModel::refreshRow(const QModelIndex &index)
{
if(isFeed(index)) {
updateRowLine(index.row());
emit dataChanged(index,createIndex(index.row(),columnCount(),0));
}
}
void RDFeedListModel::refreshFeed(const QString &keyname)
{
for(int i=0;i<d_texts.size();i++) {
if(d_key_names.at(i)==keyname) {
updateRowLine(i);
emit dataChanged(createIndex(i,0,0),createIndex(i,columnCount(),0));
}
}
}
void RDFeedListModel::changeUser()
{
QString sql;
RDSqlQuery *q=NULL;
QString filter_sql="where ";
sql=QString("select ")+
"KEY_NAME "+ // 00
"from FEED_PERMS where "+
"USER_NAME=\""+RDEscapeString(rda->user()->name())+"\"";
q=new RDSqlQuery(sql);
while(q->next()) {
filter_sql+="(KEY_NAME=\""+RDEscapeString(q->value(0).toString())+"\")||";
}
delete q;
filter_sql=filter_sql.left(filter_sql.length()-2);
updateModel(filter_sql);
}
void RDFeedListModel::processNotification(RDNotification *notify)
{
QString keyname;
if(notify->type()==RDNotification::FeedType) {
keyname=notify->id().toString();
switch(notify->action()) {
case RDNotification::ModifyAction:
refreshFeed(keyname);
break;
case RDNotification::NoAction:
case RDNotification::AddAction:
case RDNotification::DeleteAction:
case RDNotification::LastAction:
break;
}
}
}
void RDFeedListModel::updateModel(const QString &filter_sql)
{
QString sql;
RDSqlQuery *q=NULL;
//
// Placeholder values
//
QList<QVariant> list;
QList<QVariant> icons;
for(int i=0;i<columnCount();i++) {
list.push_back(QVariant());
icons.push_back(QVariant());
}
QList<QList<QVariant> > list_list;
list_list.push_back(list);
sql=sqlFields()+
filter_sql+
"order by FEEDS.KEY_NAME asc, PODCASTS.ORIGIN_DATETIME desc";
// printf("SQL: %s\n",sql.toUtf8().constData());
beginResetModel();
d_texts.clear();
d_key_names.clear();
d_feed_ids.clear();
d_cast_ids.clear();
d_cast_icons.clear();
d_icons.clear();
QString prev_keyname;
QList<unsigned> ids;
q=new RDSqlQuery(sql);
while(q->next()) {
if(q->value(0).toString()!=prev_keyname) {
d_texts.push_back(list);
d_key_names.push_back(QString());
d_feed_ids.push_back(0);
d_cast_texts.push_back(list_list);
d_cast_ids.push_back(ids);
d_cast_icons.push_back(list);
d_icons.push_back(icons);
updateRow(d_texts.size()-1,q);
prev_keyname=q->value(0).toString();
}
}
delete q;
endResetModel();
emit rowCountChanged(d_texts.size());
}
void RDFeedListModel::updateRowLine(int line)
{
QString sql=sqlFields()+
"where "+
"FEEDS.KEY_NAME=\""+RDEscapeString(d_key_names.at(line).at(0))+"\"";
RDSqlQuery *q=new RDSqlQuery(sql);
if(q->first()) {
updateRow(line,q);
emit dataChanged(createIndex(line,0,0),
createIndex(line,columnCount(),(quint32)0));
}
delete q;
}
void RDFeedListModel::updateRow(int row,RDSqlQuery *q)
{
int active_casts=0;
int total_casts=0;
QString keyname=q->value(1).toString();
//
// Feed Attributes
//
d_feed_ids[row]=q->value(0).toUInt();
d_key_names[row]=q->value(1).toString();
d_texts[row][0]=keyname; // Key Name
if(q->value(11).isNull()) {
d_icons[row][0]=rda->iconEngine()->
applicationIcon(RDIconEngine::RdCastManager,32);
}
else {
d_icons[row][0]=QImage::fromData(q->value(11).toByteArray());
}
d_texts[row][1]=q->value(2); // Title
if(q->value(3).toString()=="Y") {
d_texts[row][2]=tr("[superfeed]");
}
else {
d_texts[row][2]="0 / 0"; // Casts
}
d_texts[row][3]=q->value(6).toDate().toString("MM/dd/yyyy"); // Creation Date
d_texts[row][4]=q->value(3).toString(); // Superfeed
d_texts[row][5]=q->value(4).toString(); // Autopost
d_texts[row][6]=RDFeed::publicUrl(q->value(5).toString(),keyname);
//
// Cast Attributes
//
d_cast_texts[row].clear();
d_cast_ids[row].clear();
d_cast_icons[row].clear();
QList<QVariant> list;
for(int i=0;i<columnCount();i++) {
list.push_back(QVariant());
}
do {
if(q->value(7).isNull()) {
return; // No casts!
}
// Process
total_casts++;
d_cast_ids[row].push_back(q->value(7).toUInt());
switch((RDPodcast::Status)q->value(9).toUInt()) {
case RDPodcast::StatusPending:
d_cast_icons[row].push_back(rda->iconEngine()->
listIcon(RDIconEngine::BlueBall));
break;
case RDPodcast::StatusActive:
d_cast_icons[row].push_back(rda->iconEngine()->
listIcon(RDIconEngine::GreenBall));
active_casts++;
break;
case RDPodcast::StatusExpired:
d_cast_icons[row].push_back(rda->iconEngine()->
listIcon(RDIconEngine::WhiteBall));
break;
}
d_cast_texts[row].push_back(list);
d_cast_texts[row].back()[1]=q->value(8); // Item Title
d_cast_texts[row].back()[3]=
q->value(10).toDateTime().toString("MM/dd/yyyy");
} while(q->next()&&(q->value(1).toString()==keyname));
q->previous();
if(q->value(3).toString()=="Y") {
d_texts[row][2]=tr("[superfeed]");
}
else {
d_texts[row][2]=
QString().sprintf("%d / %d",active_casts,total_casts); // Casts
}
}
QString RDFeedListModel::sqlFields() const
{
QString sql=QString("select ")+
"FEEDS.ID,"+ // 00
"FEEDS.KEY_NAME,"+ // 01
"FEEDS.CHANNEL_TITLE,"+ // 02
"FEEDS.IS_SUPERFEED,"+ // 03
"FEEDS.ID,"+ // 04
"FEEDS.BASE_URL,"+ // 05
"FEEDS.ORIGIN_DATETIME,"+ // 06
"PODCASTS.ID,"+ // 07
"PODCASTS.ITEM_TITLE,"+ // 08
"PODCASTS.STATUS,"+ // 09
"PODCASTS.ORIGIN_DATETIME,"+ // 10
"FEED_IMAGES.DATA "+ // 11
"from FEEDS left join FEED_IMAGES "+
"on FEEDS.CHANNEL_IMAGE_ID=FEED_IMAGES.ID left join PODCASTS "+
"on FEEDS.ID=PODCASTS.FEED_ID ";
return sql;
}
QByteArray RDFeedListModel::DumpIndex(const QModelIndex &index,const QString &caption) const
{
QByteArray ret;
if(!caption.isEmpty()) {
ret+=(caption+": ").toUtf8();
}
if(index.isValid()) {
ret+=QString().sprintf("QModelIndex(%d,%d,%llu)",
index.row(),index.column(),index.internalId()).
toUtf8();
}
else {
ret+=QString("QModelIndex()").toUtf8();
}
return ret;
}

101
lib/rdfeedlistmodel.h Normal file
View File

@ -0,0 +1,101 @@
// rdfeedlistmodel.h
//
// Data model for Rivendell RSS feeds
//
// (C) Copyright 2021 Fred Gleason <fredg@paravelsystems.com>
//
// 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.
//
#ifndef RDFEEDLISTMODEL_H
#define RDFEEDLISTMODEL_H
#include <QAbstractItemModel>
#include <QFont>
#include <QFontMetrics>
#include <QList>
#include <QMap>
#include <QPalette>
#include <rdcart.h>
#include <rddb.h>
#include <rdnotification.h>
class RDFeedListModel : public QAbstractItemModel
{
Q_OBJECT
public:
RDFeedListModel(QObject *parent=0);
~RDFeedListModel();
QPalette palette();
void setPalette(const QPalette &pal);
void setFont(const QFont &font);
QModelIndex index(int row,int col,
const QModelIndex &parent=QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const;
int columnCount(const QModelIndex &parent=QModelIndex()) const;
int rowCount(const QModelIndex &parent=QModelIndex()) const;
bool hasChildren(const QModelIndex &parent=QModelIndex()) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
QVariant headerData(int section,Qt::Orientation orient,
int role=Qt::DisplayRole) const;
QVariant data(const QModelIndex &index,int role=Qt::DisplayRole) const;
bool isFeed(const QModelIndex &index) const;
bool isCast(const QModelIndex &index) const;
QString keyName(const QModelIndex &index) const;
unsigned feedId(const QModelIndex &index) const;
QString publicUrl(const QModelIndex &index) const;
QModelIndex feedRow(const QString &keyname) const;
QModelIndex castRow(unsigned cast_id) const;
unsigned castId(const QModelIndex &index) const;
QString castOwnedBy(const QModelIndex &index);
QModelIndex addFeed(const QString &keyname);
void removeFeed(const QString &keyname);
void refreshRow(const QModelIndex &index);
void refreshFeed(const QString &keyname);
signals:
void rowCountChanged(int rows);
public slots:
void changeUser();
void processNotification(RDNotification *notify);
protected:
void updateModel(const QString &filter_sql);
void updateRowLine(int line);
void updateRow(int row,RDSqlQuery *q);
QString sqlFields() const;
private:
QByteArray DumpIndex(const QModelIndex &index,const QString &caption="") const;
QPalette d_palette;
QFont d_font;
QFontMetrics *d_font_metrics;
QFont d_bold_font;
QFontMetrics *d_bold_font_metrics;
QList<QVariant> d_headers;
QList<QList<QVariant> > d_texts;
QList<QList<QVariant> > d_icons;
QList<QList<QList<QVariant> > > d_cast_texts;
QList<QList<unsigned> > d_cast_ids;
QList<QList<QVariant> > d_cast_icons;
QList<QVariant> d_alignments;
QList<QVariant> d_background_colors;
QStringList d_key_names;
QList<unsigned> d_feed_ids;
};
#endif // RDFEEDLISTMODEL_H

View File

@ -384,13 +384,13 @@ void EditCast::okData()
return;
}
done(0);
done(true);
}
void EditCast::cancelData()
{
done(-1);
done(false);
}

View File

@ -41,11 +41,10 @@
#include "../icons/whiteball.xpm"
#include "../icons/rdcastmanager-32x32.xpm"
ListCasts::ListCasts(unsigned feed_id,bool is_super,QWidget *parent)
ListCasts::ListCasts(unsigned feed_id,QWidget *parent)
: RDDialog(parent)
{
list_feed_id=feed_id;
list_is_superfeed=is_super;
setWindowTitle("RDCastManager - "+tr("Podcast Item List")+
" [Feed ID: "+QString().sprintf("%u",feed_id)+"]");
@ -486,7 +485,7 @@ void ListCasts::postProgressChangedData(int step)
void ListCasts::closeData()
{
done(0);
done(true);
}
@ -566,7 +565,7 @@ void ListCasts::RefreshList()
list_casts_view->clear();
sql=QString("select ID from PODCASTS ")+
RDCastSearch(list_feed->keyName(),list_is_superfeed,
RDCastSearch(list_feed->keyName(),false,
list_filter_edit->text(),
list_active_check->isChecked())+
" order by ORIGIN_DATETIME";

View File

@ -35,7 +35,7 @@ class ListCasts : public RDDialog
{
Q_OBJECT
public:
ListCasts(unsigned feed_id,bool is_super,QWidget *parent=0);
ListCasts(unsigned feed_id,QWidget *parent=0);
~ListCasts();
QSize sizeHint() const;
QSizePolicy sizePolicy() const;
@ -84,7 +84,6 @@ class ListCasts : public RDDialog
QProgressDialog *list_progress_dialog;
RenderDialog *list_render_dialog;
RDFeed *list_feed;
bool list_is_superfeed;
};

View File

@ -2,7 +2,7 @@
//
// A PodCast Management Utility for Rivendell.
//
// (C) Copyright 2002-2020 Fred Gleason <fredg@paravelsystems.com>
// (C) Copyright 2002-2021 Fred Gleason <fredg@paravelsystems.com>
//
// 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
@ -18,26 +18,20 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#include <qapplication.h>
#include <qclipboard.h>
#include <qtranslator.h>
#include <qmessagebox.h>
#include <QApplication>
#include <QClipboard>
#include <QTranslator>
#include <QMessageBox>
#include <rdconf.h>
#include <rdescape_string.h>
#include <rdpodcast.h>
#include "edit_cast.h"
#include "globals.h"
#include "list_casts.h"
#include "rdcastmanager.h"
//
// Icons
//
#include "../icons/greencheckmark.xpm"
#include "../icons/redx.xpm"
#include "../icons/rdcastmanager-32x32.xpm"
//
// Global Resources
//
@ -68,6 +62,8 @@ MainWidget::MainWidget(RDConfig *c,QWidget *parent)
QMessageBox::critical(this,"RDCastManager - "+tr("Error"),err_msg);
exit(1);
}
setWindowIcon(rda->iconEngine()->
applicationIcon(RDIconEngine::RdCastManager,22));
//
// Read Command Options
@ -92,15 +88,6 @@ MainWidget::MainWidget(RDConfig *c,QWidget *parent)
rda->ripc()->
connectHost("localhost",RIPCD_TCP_PORT,rda->config()->password());
//
// Create Icons
//
setWindowIcon(rda->iconEngine()->
applicationIcon(RDIconEngine::RdCastManager,22));
cast_greencheckmark_map=new QPixmap(greencheckmark_xpm);
cast_redx_map=new QPixmap(redx_xpm);
cast_rdcastmanager_32x32_map=new QPixmap(rdcastmanager_32x32_xpm);
//
// Notifications
//
@ -110,29 +97,24 @@ MainWidget::MainWidget(RDConfig *c,QWidget *parent)
//
// Feed List
//
cast_feed_list=new RDListView(this);
cast_feed_list->setAllColumnsShowFocus(true);
cast_feed_list->setItemMargin(5);
connect(cast_feed_list,SIGNAL(clicked(Q3ListViewItem *)),
this,SLOT(feedClickedData(Q3ListViewItem *)));
connect(cast_feed_list,
SIGNAL(doubleClicked(Q3ListViewItem *,const QPoint &,int)),
this,
SLOT(feedDoubleclickedData(Q3ListViewItem *,const QPoint &,int)));
cast_feed_list->addColumn("");
cast_feed_list->setColumnAlignment(0,Qt::AlignCenter);
cast_feed_list->addColumn(tr("Key Name"));
cast_feed_list->setColumnAlignment(1,Qt::AlignLeft);
cast_feed_list->addColumn(tr("Feed Name"));
cast_feed_list->setColumnAlignment(2,Qt::AlignLeft);
cast_feed_list->addColumn(tr("Casts"));
cast_feed_list->setColumnAlignment(3,Qt::AlignCenter);
cast_feed_list->addColumn(tr("Public URL"));
cast_feed_list->setColumnAlignment(4,Qt::AlignLeft);
cast_feed_view=new QTreeView(this);
cast_feed_view->setSelectionBehavior(QAbstractItemView::SelectRows);
cast_feed_view->setSortingEnabled(false);
cast_feed_view->setWordWrap(false);
cast_feed_model=new RDFeedListModel(this);
cast_feed_model->setFont(font());
cast_feed_model->setPalette(palette());
cast_feed_view->setModel(cast_feed_model);
connect(cast_feed_model,SIGNAL(modelReset()),this,SLOT(modelResetData()));
connect(rda->ripc(),SIGNAL(notificationReceived(RDNotification *)),
cast_feed_model,SLOT(processNotification(RDNotification *)));
connect(cast_feed_view,SIGNAL(doubleClicked(const QModelIndex &)),
this,SLOT(feedDoubleClickedData(const QModelIndex &)));
connect(cast_feed_view->selectionModel(),
SIGNAL(selectionChanged(const QItemSelection &,const QItemSelection &)),
this,
SLOT(selectionChangedData(const QItemSelection &,
const QItemSelection &)));
//
// Open Button
@ -183,8 +165,33 @@ void MainWidget::userChangedData()
str1=QString("RDCastManager")+" v"+VERSION+" - "+tr("Host");
str2=QString(tr("User"));
setCaption(str1+": "+rda->config()->stationName()+" "+str2+" "+rda->ripc()->user());
RefreshList();
setWindowTitle(str1+": "+rda->config()->stationName()+" "+str2+" "+rda->ripc()->user());
cast_feed_model->changeUser();
}
void MainWidget::modelResetData()
{
for(int i=0;i<cast_feed_model->columnCount();i++) {
cast_feed_view->resizeColumnToContents(i);
}
}
void MainWidget::selectionChangedData(const QItemSelection &before,
const QItemSelection &after)
{
QModelIndexList rows=cast_feed_view->selectionModel()->selectedRows();
cast_open_button->setEnabled(rows.size()==1);
cast_copy_button->setEnabled(rows.size()==1);
if(cast_feed_model->isFeed(rows.first())) {
cast_open_button->setText(tr("View\nFeed"));
}
if(cast_feed_model->isCast(rows.first())) {
cast_open_button->setText(tr("Edit"));
}
}
@ -197,62 +204,47 @@ void MainWidget::feedClickedData(Q3ListViewItem *item)
void MainWidget::openData()
{
RDListViewItem *item=(RDListViewItem *)cast_feed_list->selectedItem();
if(item==NULL) {
QModelIndexList rows=cast_feed_view->selectionModel()->selectedRows();
if(rows.size()!=1) {
return;
}
ListCasts *casts=
new ListCasts(item->id(),item->text(3)==tr("[superfeed]"),this);
casts->exec();
RefreshItem(item);
delete casts;
if(cast_feed_model->isFeed(rows.first())) {
ListCasts *d=new ListCasts(cast_feed_model->feedId(rows.first()),this);
if(d->exec()) {
cast_feed_model->refreshRow(rows.first());
}
delete d;
}
if(cast_feed_model->isCast(rows.first())) {
EditCast *d=new EditCast(cast_feed_model->castId(rows.first()),this);
if(d->exec()) {
cast_feed_model->refreshRow(rows.first());
}
delete d;
}
}
void MainWidget::copyData()
{
RDListViewItem *item=(RDListViewItem *)cast_feed_list->selectedItem();
if(item==NULL) {
QModelIndexList rows=cast_feed_view->selectionModel()->selectedRows();
if(rows.size()!=1) {
return;
}
QApplication::clipboard()->setText(item->text(4));
QApplication::clipboard()->setText(cast_feed_model->publicUrl(rows.first()));
}
void MainWidget::feedDoubleclickedData(Q3ListViewItem *,const QPoint &,int)
void MainWidget::feedDoubleClickedData(const QModelIndex &index)
{
openData();
}
void MainWidget::notificationReceivedData(RDNotification *notify)
{
QString keyname;
RDListViewItem *item=NULL;
if(notify->type()==RDNotification::FeedType) {
keyname=notify->id().toString();
switch(notify->action()) {
case RDNotification::ModifyAction:
item=(RDListViewItem *)cast_feed_list->firstChild();
while(item!=NULL) {
if(item->text(1)==keyname) {
RefreshItem(item);
}
item=(RDListViewItem *)item->nextSibling();
}
break;
case RDNotification::NoAction:
case RDNotification::AddAction:
case RDNotification::DeleteAction:
case RDNotification::LastAction:
break;
}
}
}
void MainWidget::quitMainWidget()
{
exit(0);
@ -262,7 +254,7 @@ void MainWidget::quitMainWidget()
void MainWidget::resizeEvent(QResizeEvent *e)
{
if(cast_resize) {
cast_feed_list->setGeometry(10,10,size().width()-20,size().height()-70);
cast_feed_view->setGeometry(10,10,size().width()-20,size().height()-70);
cast_open_button->setGeometry(10,size().height()-55,80,50);
cast_copy_button->setGeometry(120,size().height()-55,100,50);
cast_close_button->setGeometry(size().width()-90,size().height()-55,80,50);
@ -270,103 +262,6 @@ void MainWidget::resizeEvent(QResizeEvent *e)
}
void MainWidget::RefreshItem(RDListViewItem *item)
{
RDSqlQuery *q;
RDSqlQuery *q1;
QString sql;
int active=0;
int total=0;
sql=QString("select ")+
"FEEDS.CHANNEL_TITLE,"+ // 00
"FEEDS.IS_SUPERFEED,"+ // 01
"FEEDS.ID,"+ // 02
"FEEDS.BASE_URL,"+ // 03
"FEED_IMAGES.DATA "+ // 04
"from FEEDS left join FEED_IMAGES "+
"on FEEDS.CHANNEL_IMAGE_ID=FEED_IMAGES.ID where "+
"FEEDS.KEY_NAME=\""+RDEscapeString(item->text(1))+"\"";
q=new RDSqlQuery(sql);
while(q->next()) {
sql=QString().sprintf("select STATUS from PODCASTS where FEED_ID=%u",
q->value(2).toUInt());
q1=new RDSqlQuery(sql);
while(q1->next()) {
total++;
switch((RDPodcast::Status)q1->value(0).toUInt()) {
case RDPodcast::StatusActive:
case RDPodcast::StatusExpired:
active++;
break;
case RDPodcast::StatusPending:
break;
}
}
delete q1;
if(q->value(4).isNull()) {
item->setPixmap(0,*cast_rdcastmanager_32x32_map);
}
else {
QImage img=QImage::fromData(q->value(4).toByteArray());
item->setPixmap(0,QPixmap::fromImage(img.scaled(32,32)));
}
item->setText(2,q->value(0).toString());
if(RDBool(q->value(1).toString())) {
item->setText(3,tr("[superfeed]"));
}
else {
item->setText(3,QString().sprintf("%d / %d",active,total));
}
item->setText(4,RDFeed::publicUrl(q->value(3).toString(),item->text(1)));
}
delete q;
}
void MainWidget::RefreshList()
{
RDSqlQuery *q;
QString sql;
int id=-1;
RDListViewItem *selected_item=NULL;
RDListViewItem *item=(RDListViewItem *)cast_feed_list->selectedItem();
if(item!=NULL) {
id=item->id();
}
cast_feed_list->clear();
sql=QString("select KEY_NAME from FEED_PERMS where ")+
"USER_NAME=\""+RDEscapeString(rda->user()->name())+"\"";
q=new RDSqlQuery(sql);
if(q->size()<=0) { // No valid feeds!
delete q;
return;
}
sql="select ID,KEY_NAME from FEEDS where ";
while(q->next()) {
sql+=QString("(KEY_NAME=\"")+RDEscapeString(q->value(0).toString())+"\")||";
}
delete q;
sql=sql.left(sql.length()-2);
q=new RDSqlQuery(sql);
while(q->next()) {
item=new RDListViewItem(cast_feed_list);
item->setId(q->value(0).toInt());
item->setText(1,q->value(1).toString());
RefreshItem(item);
if(item->id()==id) {
selected_item=item;
}
}
delete q;
if(selected_item!=NULL) {
cast_feed_list->setSelected(selected_item,true);
cast_feed_list->ensureItemVisible(item);
}
}
int main(int argc,char *argv[])
{
QApplication::setStyle(RD_GUI_STYLE);

View File

@ -2,7 +2,7 @@
//
// A RSS Feed Management Utility for Rivendell.
//
// (C) Copyright 2002-2020 Fred Gleason <fredg@paravelsystems.com>
// (C) Copyright 2002-2021 Fred Gleason <fredg@paravelsystems.com>
//
// 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
@ -21,9 +21,11 @@
#ifndef RDCASTMANAGER_H
#define RDCASTMANAGER_H
#include <qpushbutton.h>
#include <QPushButton>
#include <QTreeView>
#include <rdconfig.h>
#include <rdfeedlistmodel.h>
#include <rdlog_line.h>
#include <rdwidget.h>
@ -41,21 +43,19 @@ class MainWidget : public RDWidget
void openData();
void copyData();
void userChangedData();
void modelResetData();
void selectionChangedData(const QItemSelection &before,
const QItemSelection &after);
void feedClickedData(Q3ListViewItem *item);
void feedDoubleclickedData(Q3ListViewItem *item,const QPoint &pt,int col);
void notificationReceivedData(RDNotification *notify);
void feedDoubleClickedData(const QModelIndex &index);
void quitMainWidget();
protected:
void resizeEvent(QResizeEvent *e);
private:
void RefreshItem(RDListViewItem *item);
void RefreshList();
RDListView *cast_feed_list;
QPixmap *cast_greencheckmark_map;
QPixmap *cast_redx_map;
QPixmap *cast_rdcastmanager_32x32_map;
QTreeView *cast_feed_view;
RDFeedListModel *cast_feed_model;
QPushButton *cast_open_button;
QPushButton *cast_copy_button;
QPushButton *cast_close_button;

View File

@ -473,11 +473,11 @@ Log</source>
</message>
<message>
<source>Key Name</source>
<translation>Název klíče</translation>
<translation type="obsolete">Název klíče</translation>
</message>
<message>
<source>Feed Name</source>
<translation>Název přívodu</translation>
<translation type="obsolete">Název přívodu</translation>
</message>
<message>
<source>Description</source>
@ -485,7 +485,7 @@ Log</source>
</message>
<message>
<source>Casts</source>
<translation>Podcasty</translation>
<translation type="obsolete">Podcasty</translation>
</message>
<message>
<source>&amp;View
@ -499,7 +499,7 @@ přívod</translation>
</message>
<message>
<source>User</source>
<translation>Uživatel</translation>
<translation type="unfinished">Uživatel</translation>
</message>
<message>
<source>Host</source>
@ -513,17 +513,18 @@ přívod</translation>
<source>Unknown command option</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Public URL</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Copy URL to
Clipboard</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[superfeed]</source>
<source>View
Feed</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Edit</source>
<translation type="unfinished"></translation>
</message>
</context>

View File

@ -458,11 +458,11 @@ Log</source>
</message>
<message>
<source>Key Name</source>
<translation>Schlüsselname</translation>
<translation type="obsolete">Schlüsselname</translation>
</message>
<message>
<source>Feed Name</source>
<translation>Feedname</translation>
<translation type="obsolete">Feedname</translation>
</message>
<message>
<source>Description</source>
@ -470,7 +470,7 @@ Log</source>
</message>
<message>
<source>Casts</source>
<translation>Casts</translation>
<translation type="obsolete">Casts</translation>
</message>
<message>
<source>&amp;View
@ -484,7 +484,7 @@ Feed</translation>
</message>
<message>
<source>User</source>
<translation>Benutzer</translation>
<translation type="unfinished">Benutzer</translation>
</message>
<message>
<source>Host</source>
@ -498,17 +498,18 @@ Feed</translation>
<source>Unknown command option</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Public URL</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Copy URL to
Clipboard</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[superfeed]</source>
<source>View
Feed</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Edit</source>
<translation type="unfinished"></translation>
</message>
</context>

View File

@ -413,11 +413,11 @@ Log</source>
</message>
<message>
<source>Key Name</source>
<translation>Nombre Clave</translation>
<translation type="obsolete">Nombre Clave</translation>
</message>
<message>
<source>Feed Name</source>
<translation>Nombre del Feed</translation>
<translation type="obsolete">Nombre del Feed</translation>
</message>
<message>
<source>Description</source>
@ -425,7 +425,7 @@ Log</source>
</message>
<message>
<source>Casts</source>
<translation>Podcasts</translation>
<translation type="obsolete">Podcasts</translation>
</message>
<message>
<source>&amp;Close</source>
@ -433,7 +433,7 @@ Log</source>
</message>
<message>
<source>User</source>
<translation>Usuario</translation>
<translation type="unfinished">Usuario</translation>
</message>
<message>
<source>&amp;View
@ -452,17 +452,18 @@ Feed</source>
<source>Unknown command option</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Public URL</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Copy URL to
Clipboard</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[superfeed]</source>
<source>View
Feed</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Edit</source>
<translation type="unfinished"></translation>
</message>
</context>

View File

@ -288,18 +288,6 @@ Log</source>
<source>User: [Unknown]</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Key Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Feed Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Casts</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&amp;View
Feed</source>
@ -309,10 +297,6 @@ Feed</source>
<source>&amp;Close</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>User</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Host</source>
<translation type="unfinished"></translation>
@ -325,17 +309,22 @@ Feed</source>
<source>Unknown command option</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Public URL</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Copy URL to
Clipboard</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[superfeed]</source>
<source>User</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>View
Feed</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Edit</source>
<translation type="unfinished"></translation>
</message>
</context>

View File

@ -440,11 +440,11 @@ Log</source>
</message>
<message>
<source>Key Name</source>
<translation>Lykjelnamn</translation>
<translation type="obsolete">Lykjelnamn</translation>
</message>
<message>
<source>Feed Name</source>
<translation>Straumnamn</translation>
<translation type="obsolete">Straumnamn</translation>
</message>
<message>
<source>Description</source>
@ -452,7 +452,7 @@ Log</source>
</message>
<message>
<source>Casts</source>
<translation>Kastar</translation>
<translation type="obsolete">Kastar</translation>
</message>
<message>
<source>&amp;View
@ -466,7 +466,7 @@ straum</translation>
</message>
<message>
<source>User</source>
<translation>Brukar</translation>
<translation type="unfinished">Brukar</translation>
</message>
<message>
<source>Host</source>
@ -480,17 +480,18 @@ straum</translation>
<source>Unknown command option</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Public URL</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Copy URL to
Clipboard</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[superfeed]</source>
<source>View
Feed</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Edit</source>
<translation type="unfinished"></translation>
</message>
</context>

View File

@ -440,11 +440,11 @@ Log</source>
</message>
<message>
<source>Key Name</source>
<translation>Lykjelnamn</translation>
<translation type="obsolete">Lykjelnamn</translation>
</message>
<message>
<source>Feed Name</source>
<translation>Straumnamn</translation>
<translation type="obsolete">Straumnamn</translation>
</message>
<message>
<source>Description</source>
@ -452,7 +452,7 @@ Log</source>
</message>
<message>
<source>Casts</source>
<translation>Kastar</translation>
<translation type="obsolete">Kastar</translation>
</message>
<message>
<source>&amp;View
@ -466,7 +466,7 @@ straum</translation>
</message>
<message>
<source>User</source>
<translation>Brukar</translation>
<translation type="unfinished">Brukar</translation>
</message>
<message>
<source>Host</source>
@ -480,17 +480,18 @@ straum</translation>
<source>Unknown command option</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Public URL</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Copy URL to
Clipboard</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[superfeed]</source>
<source>View
Feed</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Edit</source>
<translation type="unfinished"></translation>
</message>
</context>

View File

@ -418,11 +418,11 @@ Log</source>
</message>
<message>
<source>Key Name</source>
<translation>Nome chave</translation>
<translation type="obsolete">Nome chave</translation>
</message>
<message>
<source>Feed Name</source>
<translation>Nome do Feed</translation>
<translation type="obsolete">Nome do Feed</translation>
</message>
<message>
<source>Description</source>
@ -430,7 +430,7 @@ Log</source>
</message>
<message>
<source>Casts</source>
<translation>Casts</translation>
<translation type="obsolete">Casts</translation>
</message>
<message>
<source>&amp;View
@ -444,7 +444,7 @@ Feed</translation>
</message>
<message>
<source>User</source>
<translation>Usuário</translation>
<translation type="unfinished">Usuário</translation>
</message>
<message>
<source>Host</source>
@ -458,17 +458,18 @@ Feed</translation>
<source>Unknown command option</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Public URL</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Copy URL to
Clipboard</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[superfeed]</source>
<source>View
Feed</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Edit</source>
<translation type="unfinished"></translation>
</message>
</context>