#include <QStandardItemModel>
#include <QStandardPaths>
#include <QStorageInfo>
+#include <QTableView>
#include <QTabWidget>
#include <QTextBrowser>
#include <QTextEdit>
connect(mPicture,SIGNAL(resized()),this,SLOT(reImage()),Qt::QueuedConnection);
connect(this,SIGNAL(updateImage()),this,SLOT(reImage()),Qt::QueuedConnection);
csplit->setStretchFactor(0,15);
- csplit->addWidget(mText=new QLabel("Description"));
+ csplit->addWidget(mText=new QTextBrowser);
mText->setFrameShape(QFrame::StyledPanel);
csplit->setStretchFactor(1,3);
split->setSizes(QList<int>()<<100<<500);
populate();
mrecent=set.value("recent").toStringList();
+ mhistory=set.value("history").value<QList<History_s>>();
redoRecent();
}
for(auto split:findChildren<QSplitter*>())
set.setValue("splitter/"+split->objectName(),split->saveState());
set.setValue("recent",QVariant::fromValue(mrecent));
+ set.setValue("history",QVariant::fromValue(mhistory));
}
void Kino::findRoot()
auto act=mGoto->addAction(ent.longLabel(),this,SLOT(gotoRecent()),QKeySequence(QString("Alt+%1").arg(i+1)));
act->setData(mrecent[i]);
act->setToolTip(QString("Video: %1\nVolume: %3\n\n%2").arg(ent.directory()).arg(ent.description()).arg(vol.label()));
+ act->setShortcutVisibleInContextMenu(true);
}
+ mGoto->addSeparator();
+ mGoto->addAction("&Show History...",this,SLOT(showHistory()),QKeySequence("Alt+S"))->setShortcutVisibleInContextMenu(true);
}
if(mrecent.contains(p))
mrecent.removeAll(p);
mrecent.prepend(p);
+ mhistory.prepend(p);
+ while(mhistory.size()>100)mhistory.removeLast();
sync();
redoRecent();
}
return QModelIndex();
}
-void Kino::gotoRecent()
+void Kino::gotoRecent(QString id)
{
- //get action
- QAction*act=qobject_cast<QAction*>(sender());
- if(act==nullptr){
- qDebug()<<"WARNING: gotoRecent called without back-link to action!";
- return;
- }
+ //get action (skip if id has been provided - see showHistory())
+ if(id.isEmpty()){
+ QAction*act=qobject_cast<QAction*>(sender());
+ if(act==nullptr){
+ qDebug()<<"WARNING: gotoRecent called without back-link to action!";
+ return;
+ }
+ id=act->data().toString();
+ }
//find entry in tree
- QModelIndex idx=findModelItem(mModel,act->data().toString());
+ QModelIndex idx=findModelItem(mModel,id);
if(idx.isValid()){
mTree->scrollTo(idx);
QItemSelectionModel* sel=mTree->selectionModel();
d.exec();
}
+void Kino::showHistory()
+{
+ //create GUI
+ QDialog d(this);
+ d.resize(800,600);
+ d.setSizeGripEnabled(true);
+ QVBoxLayout*vl;
+ d.setLayout(vl=new QVBoxLayout);
+ QTableView*tv;
+ QStandardItemModel*sm;
+ vl->addWidget(tv=new QTableView,1);
+ tv->setModel(sm=new QStandardItemModel(&d));
+ QHBoxLayout*hl;
+ vl->addLayout(hl=new QHBoxLayout,0);
+ hl->addStretch(1);
+ QPushButton*p;
+ hl->addWidget(p=new QPushButton("Goto..."));
+ connect(p,SIGNAL(clicked()),&d,SLOT(accept()));
+ hl->addWidget(p=new QPushButton("Close"));
+ connect(p,SIGNAL(clicked()),&d,SLOT(reject()));
+ //fill table
+ sm->setHorizontalHeaderLabels(QStringList()<<"Film"<<"Volume"<<"Time");
+ sm->insertRows(0,mhistory.size());
+ for(int i=0;i<mhistory.size();i++){
+ // find entry
+ auto &vol=getVolume(mhistory[i].id);
+ const auto &ent=getEntry(vol,mhistory[i].id);
+ //display
+ sm->setData(sm->index(i,0),ent.longLabel(),Qt::DisplayRole);
+ sm->setData(sm->index(i,0),mhistory[i].id,Qt::UserRole);
+ sm->setData(sm->index(i,1),vol.label(),Qt::DisplayRole);
+ sm->setData(sm->index(i,2),mhistory[i].when,Qt::DisplayRole);
+ }
+ tv->resizeColumnsToContents();
+ tv->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ tv->setSelectionBehavior(QAbstractItemView::SelectRows);
+ //wait for user
+ if(d.exec()==QDialog::Accepted){//Goto...
+ //get selection
+ auto smd=tv->selectionModel();
+ QModelIndexList idxl=smd->selectedIndexes();
+ QModelIndex idx;
+ if(idxl.size()>0)idx=idxl[0];
+ if(!idx.isValid())idx=smd->currentIndex();
+ if(!idx.isValid())return;
+ //get ID and goto
+ gotoRecent(sm->data(sm->index(idx.row(),0),Qt::UserRole).toString());
+ }//else Close...
+}
+
int main(int ac,char**av)
{
qRegisterMetaType<QPair<qint64,qint64>>();
qRegisterMetaTypeStreamOperators<QPair<qint64,qint64>>();
- QCoreApplication::setOrganizationName("Silmor");
+ qRegisterMetaType<History_s>();
+ qRegisterMetaType<QList<History_s>>();
+ qRegisterMetaTypeStreamOperators<History_s>();
+ qRegisterMetaTypeStreamOperators<QList<History_s>>();
+ QCoreApplication::setOrganizationName("Silmor");
QCoreApplication::setOrganizationDomain("silmor.de");
QCoreApplication::setApplicationName("Kino");
QApplication app(ac,av);
#include <QUuid>
#include <QList>
#include <QLabel>
+#include <QDateTime>
class QLabel;
class QStandardItemModel;
class QItemSelection;
class QTreeView;
class QMenu;
+class QTextBrowser;
#include "volume.h"
+///Helper structure for history storage
+struct History_s
+{
+ History_s()=default;
+ History_s(const QString&s):id(s),when(QDateTime::currentDateTime()){}
+ History_s(const History_s&)=default;
+ History_s(History_s&&)=default;
+ History_s& operator=(const History_s&)=default;
+ History_s& operator=(History_s&&)=default;
+ QString id;QDateTime when;
+};
+
///Main window
class Kino:public QWidget
{
///play media via play button
void playMedia(bool full=true);
///goto recently played disc
- void gotoRecent();
+ void gotoRecent(QString id=QString());
///called when selection changes
void select();
///repaints the current image, call updateImage instead
void findRoot();
///about dialog
void about();
+ ///history table
+ void showHistory();
signals:
///signals to repaint the image
void updateImage();
///reformats the Goto button menu
void redoRecent();
-
+
///synchronizes status data (geometry, list of recents plays,...)
void sync();
bool play(QString,bool);
QStandardItemModel *mModel=0;
- QLabel *mPicture=0,*mText=0;
+ QLabel *mPicture=0;
+ QTextBrowser*mText=0;
QTreeView*mTree=0;
QMenu*mGoto=0;
QList<Volume> mvolumes;
QSize mlastimagesize;
QString mlastimage;
QAction*mplayaction=0,*meditaction=0;
+ QList<History_s>mhistory;
};
+Q_DECLARE_METATYPE(History_s);
+Q_DECLARE_METATYPE(QList<History_s>);
+
+inline QDataStream& operator<<(QDataStream&strm,const History_s&h)
+{
+ strm<<h.id<<h.when;
+ return strm;
+}
+inline QDataStream& operator>>(QDataStream&strm,History_s&h)
+{
+ strm>>h.id>>h.when;
+ return strm;
+}
+
+inline QDataStream& operator<<(QDataStream&strm,const QList<History_s>&hl)
+{
+ strm<<hl.size();
+ for(const auto&h:hl)
+ strm<<h;
+ return strm;
+}
+inline QDataStream& operator>>(QDataStream&strm,QList<History_s>&hl)
+{
+ hl.clear();
+ int sz;
+ strm>>sz;
+ for(int i=0;i<sz;i++){
+ History_s h;
+ strm>>h;
+ hl.append(h);
+ }
+ return strm;
+}
+
#endif